From 7f24f7fd2361ff5d43775e4523bc78ffdb108306 Mon Sep 17 00:00:00 2001 From: Dwayne Boone Date: Wed, 19 Nov 2008 11:06:31 -0330 Subject: Added use of CtrlChandler to slice compilers --- cpp/src/slice2py/Main.cpp | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'cpp/src/slice2py/Main.cpp') diff --git a/cpp/src/slice2py/Main.cpp b/cpp/src/slice2py/Main.cpp index 7951141b1b3..fcae12e5e5e 100644 --- a/cpp/src/slice2py/Main.cpp +++ b/cpp/src/slice2py/Main.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -33,6 +34,16 @@ using namespace std; using namespace Slice; using namespace Slice::Python; +// +// Callback for Crtl-C signal handling +// +static IceUtilInternal::Output _out; + +static void closeCallback() +{ + _out.close(); +} + // // For each Slice file Foo.ice we generate Foo_ice.py containing the Python // mappings. Furthermore, for each Slice module M in Foo.ice, we create a @@ -477,7 +488,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); @@ -537,26 +550,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 Python mapping. // - generate(u, all, checksum, includePaths, out); + generate(u, all, checksum, includePaths, _out); - out.close(); + _out.close(); + SignalHandler::setCloseCallback(0); // // Create or update the Python package hierarchy. -- cgit v1.2.3