diff options
Diffstat (limited to 'cpp/src/slice2freeze/Main.cpp')
-rw-r--r-- | cpp/src/slice2freeze/Main.cpp | 111 |
1 files changed, 65 insertions, 46 deletions
diff --git a/cpp/src/slice2freeze/Main.cpp b/cpp/src/slice2freeze/Main.cpp index d89b03670eb..762f3338b5b 100644 --- a/cpp/src/slice2freeze/Main.cpp +++ b/cpp/src/slice2freeze/Main.cpp @@ -9,12 +9,13 @@ #include <IceUtil/DisableWarnings.h> #include <IceUtil/Options.h> +#include <IceUtil/CtrlCHandler.h> +#include <IceUtil/StaticMutex.h> #include <Slice/Preprocessor.h> #include <Slice/Util.h> #include <Slice/CPlusPlusUtil.h> #include <IceUtil/OutputUtil.h> #include <IceUtil/StringUtil.h> -#include <Slice/SignalHandler.h> #include <cstring> using namespace std; @@ -22,16 +23,15 @@ using namespace IceUtil; using namespace IceUtilInternal; using namespace Slice; -static ::IceUtilInternal::Output _H; -static ::IceUtilInternal::Output _CPP; +static IceUtil::StaticMutex _mutex = ICE_STATIC_MUTEX_INITIALIZER; +static bool _interrupted = false; -// -// Callback for Crtl-C signal handling -// -static void closeCallback() +void +interruptedCallback(int signal) { - _H.close(); - _CPP.close(); + IceUtil::StaticMutex::Lock lock(_mutex); + + _interrupted = true; } static string ICE_ENCODING_COMPARE = "Freeze::IceEncodingCompare"; @@ -1792,7 +1792,8 @@ main(int argc, char* argv[]) int status = EXIT_SUCCESS; - SignalHandler sigHandler; + IceUtil::CtrlCHandler ctrlCHandler; + ctrlCHandler.setCallback(interruptedCallback); for(vector<string>::size_type idx = 1; idx < args.size(); ++idx) { @@ -1837,6 +1838,15 @@ main(int argc, char* argv[]) u->destroy(); return EXIT_FAILURE; } + + { + IceUtil::StaticMutex::Lock lock(_mutex); + + if(_interrupted) + { + return EXIT_FAILURE; + } + } } if(status == EXIT_SUCCESS && !preprocess) @@ -1851,30 +1861,27 @@ main(int argc, char* argv[]) } } - SignalHandler::addFile(fileH); - SignalHandler::addFile(fileC); - - SignalHandler::setCallback(closeCallback); - - _H.open(fileH.c_str()); - if(!_H) + IceUtilInternal::Output H; + H.open(fileH.c_str()); + if(!H) { cerr << argv[0] << ": can't open `" << fileH << "' for writing: " << strerror(errno) << endl; u->destroy(); return EXIT_FAILURE; } - printHeader(_H); - printFreezeTypes(_H, dicts, indices); + printHeader(H); + printFreezeTypes(H, dicts, indices); - _CPP.open(fileC.c_str()); - if(!_CPP) + IceUtilInternal::Output CPP; + CPP.open(fileC.c_str()); + if(!CPP) { cerr << argv[0] << ": can't open `" << fileC << "' for writing: " << strerror(errno) << endl; u->destroy(); return EXIT_FAILURE; } - printHeader(_CPP); - printFreezeTypes(_CPP, dicts, indices); + printHeader(CPP); + printFreezeTypes(CPP, dicts, indices); for(vector<string>::const_iterator i = extraHeaders.begin(); i != extraHeaders.end(); ++i) { @@ -1888,57 +1895,57 @@ main(int argc, char* argv[]) } if(!guard.empty()) { - _CPP << "\n#ifndef " << guard; - _CPP << "\n#define " << guard; + CPP << "\n#ifndef " << guard; + CPP << "\n#define " << guard; } - _CPP << "\n#include <"; + CPP << "\n#include <"; if(!include.empty()) { - _CPP << include << '/'; + CPP << include << '/'; } - _CPP << hdr << '>'; + CPP << hdr << '>'; if(!guard.empty()) { - _CPP << "\n#endif"; + CPP << "\n#endif"; } } string s = fileH; transform(s.begin(), s.end(), s.begin(), ToIfdef()); - _H << "\n#ifndef __" << s << "__"; - _H << "\n#define __" << s << "__"; - _H << '\n'; + H << "\n#ifndef __" << s << "__"; + H << "\n#define __" << s << "__"; + H << '\n'; if(dicts.size() > 0) { - _H << "\n#include <Freeze/Map.h>"; + H << "\n#include <Freeze/Map.h>"; } if(indices.size() > 0) { - _H << "\n#include <Freeze/Index.h>"; + H << "\n#include <Freeze/Index.h>"; } { for(StringList::const_iterator p = includes.begin(); p != includes.end(); ++p) { - _H << "\n#include <" << changeInclude(*p, includePaths) << "." + headerExtension + ">"; + H << "\n#include <" << changeInclude(*p, includePaths) << "." + headerExtension + ">"; } } - _CPP << "\n#include <Ice/BasicStream.h>"; - _CPP << "\n#include <"; + CPP << "\n#include <Ice/BasicStream.h>"; + CPP << "\n#include <"; if(include.size()) { - _CPP << include << '/'; + CPP << include << '/'; } - _CPP << includeH << '>'; + CPP << includeH << '>'; - printVersionCheck(_H); - printVersionCheck(_CPP); + printVersionCheck(H); + printVersionCheck(CPP); - printDllExportStuff(_H, dllExport); + printDllExportStuff(H, dllExport); if(dllExport.size()) { dllExport += " "; @@ -1949,7 +1956,7 @@ main(int argc, char* argv[]) { try { - if(!writeDict(argv[0], u, *p, _H, _CPP, dllExport)) + if(!writeDict(argv[0], u, *p, H, CPP, dllExport)) { u->destroy(); return EXIT_FAILURE; @@ -1968,7 +1975,7 @@ main(int argc, char* argv[]) { try { - if(!writeIndex(argv[0], u, *q, _H, _CPP, dllExport)) + if(!writeIndex(argv[0], u, *q, H, CPP, dllExport)) { u->destroy(); return EXIT_FAILURE; @@ -1984,12 +1991,24 @@ main(int argc, char* argv[]) } - _H << "\n\n#endif\n"; - _CPP << '\n'; + H << "\n\n#endif\n"; + CPP << '\n'; + H.close(); + CPP.close(); } u->destroy(); + { + IceUtil::StaticMutex::Lock lock(_mutex); + + if(_interrupted) + { + return EXIT_FAILURE; + } + } + + return status; } |