diff options
Diffstat (limited to 'cpp/src/slice2rb/Main.cpp')
-rw-r--r-- | cpp/src/slice2rb/Main.cpp | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/cpp/src/slice2rb/Main.cpp b/cpp/src/slice2rb/Main.cpp index 0d6856a2123..2cdd6ec4982 100644 --- a/cpp/src/slice2rb/Main.cpp +++ b/cpp/src/slice2rb/Main.cpp @@ -12,6 +12,7 @@ #include <IceUtil/CtrlCHandler.h> #include <IceUtil/StaticMutex.h> #include <Slice/Preprocessor.h> +#include <Slice/FileTracker.h> #include <Slice/RubyUtil.h> #include <fstream> @@ -27,6 +28,8 @@ #include <unistd.h> #endif +#include <string.h> + using namespace std; using namespace Slice; using namespace Slice::Ruby; @@ -101,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; } @@ -207,24 +210,37 @@ main(int argc, char* argv[]) file = output + '/' + file; } - IceUtilInternal::Output out; - 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"; - - // - // Generate the Ruby mapping. - // - generate(u, all, checksum, includePaths, out); - - out.close(); } u->destroy(); @@ -235,6 +251,7 @@ main(int argc, char* argv[]) if(_interrupted) { + FileTracker::instance()->cleanup(); return EXIT_FAILURE; } } |