diff options
Diffstat (limited to 'cpp/src/slice2rb/Main.cpp')
-rw-r--r-- | cpp/src/slice2rb/Main.cpp | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/cpp/src/slice2rb/Main.cpp b/cpp/src/slice2rb/Main.cpp index 2e91d3c1d8a..b52f8f0d1cd 100644 --- a/cpp/src/slice2rb/Main.cpp +++ b/cpp/src/slice2rb/Main.cpp @@ -9,6 +9,7 @@ #include <IceUtil/DisableWarnings.h> #include <IceUtil/Options.h> +#include <IceUtil/CtrlCHandler.h> #include <Slice/Preprocessor.h> #include <Slice/RubyUtil.h> #include <Slice/SignalHandler.h> @@ -30,6 +31,16 @@ using namespace std; using namespace Slice; using namespace Slice::Ruby; +// +// Callback for Crtl-C signal handling +// +static IceUtilInternal::Output _out; + +static void closeCallback() +{ + _out.close(); +} + void usage(const char* n) { @@ -138,7 +149,9 @@ main(int argc, char* argv[]) for(i = args.begin(); i != args.end(); ++i) { - SignalHandler sigHandler; + SignalHandler::clearCleanupFileList(); + IceUtil::CtrlCHandler ctrlCHandler; + ctrlCHandler.setCallback(SignalHandler::removeFilesOnInterrupt); Preprocessor icecpp(argv[0], *i, cppArgs); FILE* cppHandle = icecpp.preprocess(false); @@ -192,26 +205,28 @@ main(int argc, char* argv[]) { file = output + '/' + file; } - SignalHandler::addFile(file); - IceUtilInternal::Output out; - out.open(file.c_str()); - if(!out) + SignalHandler::setCloseCallback(closeCallback); + + SignalHandler::addFileForCleanup(file); + _out.open(file.c_str()); + if(!_out) { cerr << argv[0] << ": can't open `" << file << "' for writing" << endl; u->destroy(); return EXIT_FAILURE; } - printHeader(out); - out << "\n# Generated from file `" << base << ".ice'\n"; + printHeader(_out); + _out << "\n# Generated from file `" << base << ".ice'\n"; // // Generate the Ruby mapping. // - generate(u, all, checksum, includePaths, out); + generate(u, all, checksum, includePaths, _out); - out.close(); + _out.close(); + SignalHandler::setCloseCallback(0); } u->destroy(); |