diff options
author | Bernard Normier <bernard@zeroc.com> | 2009-01-23 17:07:21 -0500 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2009-01-23 17:07:21 -0500 |
commit | 2380e089401d048490da23bc6d71e5687bafbe47 (patch) | |
tree | 6d97052d1f93bc2bafcd7fd1a9ebe103544b6cad /cpp/src/slice2rb/Main.cpp | |
parent | Fixed permissions (diff) | |
parent | 3.3.1 third-party updates (diff) | |
download | ice-2380e089401d048490da23bc6d71e5687bafbe47.tar.bz2 ice-2380e089401d048490da23bc6d71e5687bafbe47.tar.xz ice-2380e089401d048490da23bc6d71e5687bafbe47.zip |
Merge branch 'R3_3_branch' of cvs:/home/git/ice into R3_3_branch
Conflicts:
java/resources/IceGridAdmin/icegridadmin_content_dyn.html
java/resources/IceGridAdmin/icegridadmin_content_static.html
Diffstat (limited to 'cpp/src/slice2rb/Main.cpp')
-rw-r--r-- | cpp/src/slice2rb/Main.cpp | 79 |
1 files changed, 53 insertions, 26 deletions
diff --git a/cpp/src/slice2rb/Main.cpp b/cpp/src/slice2rb/Main.cpp index da01726693a..2cdd6ec4982 100644 --- a/cpp/src/slice2rb/Main.cpp +++ b/cpp/src/slice2rb/Main.cpp @@ -1,6 +1,6 @@ // ********************************************************************** // -// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. // // This copy of Ice is licensed to you under the terms described in the // ICE_LICENSE file included in this distribution. @@ -9,9 +9,11 @@ #include <IceUtil/DisableWarnings.h> #include <IceUtil/Options.h> +#include <IceUtil/CtrlCHandler.h> +#include <IceUtil/StaticMutex.h> #include <Slice/Preprocessor.h> +#include <Slice/FileTracker.h> #include <Slice/RubyUtil.h> -#include <Slice/SignalHandler.h> #include <fstream> @@ -26,18 +28,21 @@ #include <unistd.h> #endif +#include <string.h> + using namespace std; using namespace Slice; using namespace Slice::Ruby; -// -// Callback for Crtl-C signal handling -// -static IceUtilInternal::Output _out; +static IceUtil::StaticMutex _mutex = ICE_STATIC_MUTEX_INITIALIZER; +static bool _interrupted = false; -static void closeCallback() +void +interruptedCallback(int signal) { - _out.close(); + IceUtil::StaticMutex::Lock lock(_mutex); + + _interrupted = true; } void @@ -99,7 +104,7 @@ main(int argc, char* argv[]) if(opts.isSet("version")) { - cout << ICE_STRING_VERSION << endl; + cerr << ICE_STRING_VERSION << endl; return EXIT_SUCCESS; } @@ -146,9 +151,11 @@ main(int argc, char* argv[]) int status = EXIT_SUCCESS; + IceUtil::CtrlCHandler ctrlCHandler; + ctrlCHandler.setCallback(interruptedCallback); + for(i = args.begin(); i != args.end(); ++i) { - SignalHandler sigHandler; Preprocessor icecpp(argv[0], *i, cppArgs); FILE* cppHandle = icecpp.preprocess(false); @@ -202,31 +209,51 @@ main(int argc, char* argv[]) { file = output + '/' + file; } - SignalHandler::addFile(file); - - SignalHandler::setCallback(closeCallback); - _out.open(file.c_str()); - if(!_out) + try + { + IceUtilInternal::Output out; + out.open(file.c_str()); + if(!out) + { + ostringstream os; + os << "cannot open`" << file << "': " << strerror(errno); + throw FileException(__FILE__, __LINE__, os.str()); + } + FileTracker::instance()->addFile(file); + + printHeader(out); + out << "\n# Generated from file `" << base << ".ice'\n"; + + // + // Generate the Ruby mapping. + // + generate(u, all, checksum, includePaths, out); + + out.close(); + } + catch(const Slice::FileException& ex) { - cerr << argv[0] << ": can't open `" << file << "' for writing" << endl; + // If a file could not be created, then cleanup + // any created files. + FileTracker::instance()->cleanup(); u->destroy(); + cerr << argv[0] << ": " << ex.reason() << endl; return EXIT_FAILURE; } + } - printHeader(_out); - _out << "\n# Generated from file `" << base << ".ice'\n"; + u->destroy(); + } - // - // Generate the Ruby mapping. - // - generate(u, all, checksum, includePaths, _out); + { + IceUtil::StaticMutex::Lock lock(_mutex); - _out.close(); - SignalHandler::setCallback(0); + if(_interrupted) + { + FileTracker::instance()->cleanup(); + return EXIT_FAILURE; } - - u->destroy(); } } |