diff options
Diffstat (limited to 'cpp/src/slice2js/Main.cpp')
-rw-r--r-- | cpp/src/slice2js/Main.cpp | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/cpp/src/slice2js/Main.cpp b/cpp/src/slice2js/Main.cpp index fe5986e2f45..d135fbaec2c 100644 --- a/cpp/src/slice2js/Main.cpp +++ b/cpp/src/slice2js/Main.cpp @@ -11,6 +11,7 @@ #include <IceUtil/CtrlCHandler.h> #include <IceUtil/Mutex.h> #include <IceUtil/MutexPtrLock.h> +#include <IceUtil/ConsoleUtil.h> #include <Slice/Preprocessor.h> #include <Slice/FileTracker.h> #include <Slice/Util.h> @@ -18,6 +19,7 @@ using namespace std; using namespace Slice; +using namespace IceUtilInternal; namespace { @@ -56,8 +58,8 @@ interruptedCallback(int /*signal*/) void usage(const string& n) { - getErrorStream() << "Usage: " << n << " [options] slice-files...\n"; - getErrorStream() << + consoleErr << "Usage: " << n << " [options] slice-files...\n"; + consoleErr << "Options:\n" "-h, --help Show this message.\n" "-v, --version Display the Ice version.\n" @@ -74,8 +76,10 @@ usage(const string& n) "--depend-xml Generate dependencies in XML format.\n" "--depend-file FILE Write dependencies to FILE instead of standard output.\n" "-d, --debug Print debug messages.\n" - "--ice Allow reserved Ice prefix in Slice identifiers.\n" - "--underscore Allow underscores in Slice identifiers.\n" + "--ice Allow reserved Ice prefix in Slice identifiers\n" + " deprecated: use instead [[\"ice-prefix\"]] metadata.\n" + "--underscore Allow underscores in Slice identifiers\n" + " deprecated: use instead [[\"underscore\"]] metadata.\n" ; } @@ -109,7 +113,7 @@ compile(const vector<string>& argv) } catch(const IceUtilInternal::BadOptException& e) { - getErrorStream() << argv[0] << ": error: " << e.reason << endl; + consoleErr << argv[0] << ": error: " << e.reason << endl; if(!validate) { usage(argv[0]); @@ -125,7 +129,7 @@ compile(const vector<string>& argv) if(opts.isSet("version")) { - getErrorStream() << ICE_STRING_VERSION << endl; + consoleErr << ICE_STRING_VERSION << endl; return EXIT_SUCCESS; } @@ -170,7 +174,7 @@ compile(const vector<string>& argv) if(args.empty()) { - getErrorStream() << argv[0] << ": error: no input file" << endl; + consoleErr << argv[0] << ": error: no input file" << endl; if(!validate) { usage(argv[0]); @@ -180,7 +184,7 @@ compile(const vector<string>& argv) if(depend && dependJSON) { - getErrorStream() << argv[0] << ": error: cannot specify both --depend and --depend-json" << endl; + consoleErr << argv[0] << ": error: cannot specify both --depend and --depend-json" << endl; if(!validate) { usage(argv[0]); @@ -190,7 +194,7 @@ compile(const vector<string>& argv) if(depend && dependxml) { - getErrorStream() << argv[0] << ": error: cannot specify both --depend and --depend-xml" << endl; + consoleErr << argv[0] << ": error: cannot specify both --depend and --depend-xml" << endl; if(!validate) { usage(argv[0]); @@ -200,7 +204,7 @@ compile(const vector<string>& argv) if(dependxml && dependJSON) { - getErrorStream() << argv[0] << ": error: cannot specify both --depend-xml and --depend-json" << endl; + consoleErr << argv[0] << ": error: cannot specify both --depend-xml and --depend-json" << endl; if(!validate) { usage(argv[0]); @@ -218,14 +222,14 @@ compile(const vector<string>& argv) IceUtil::CtrlCHandler ctrlCHandler; ctrlCHandler.setCallback(interruptedCallback); - DependOutputUtil out(dependFile); + ostringstream os; if(dependJSON) { - out.os() << "{" << endl; + os << "{" << endl; } else if(dependxml) { - out.os() << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<dependencies>" << endl; + os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<dependencies>" << endl; } // @@ -250,7 +254,6 @@ compile(const vector<string>& argv) if(cppHandle == 0) { - out.cleanup(); return EXIT_FAILURE; } @@ -260,24 +263,21 @@ compile(const vector<string>& argv) if(parseStatus == EXIT_FAILURE) { - out.cleanup(); return EXIT_FAILURE; } bool last = (++i == sources.end()); - if(!icecpp->printMakefileDependencies(out.os(), + if(!icecpp->printMakefileDependencies(os, depend ? Preprocessor::JavaScript : (dependJSON ? Preprocessor::JavaScriptJSON : Preprocessor::SliceXML), includePaths, "-D__SLICE2JS__")) { - out.cleanup(); return EXIT_FAILURE; } if(!icecpp->close()) { - out.cleanup(); return EXIT_FAILURE; } @@ -285,9 +285,9 @@ compile(const vector<string>& argv) { if(!last) { - out.os() << ","; + os << ","; } - out.os() << "\n"; + os << "\n"; } } else @@ -302,7 +302,7 @@ compile(const vector<string>& argv) if(preprocess) { char buf[4096]; - while(fgets(buf, static_cast<int>(sizeof(buf)), cppHandle) != NULL) + while(fgets(buf, static_cast<int>(sizeof(buf)), cppHandle) != ICE_NULLPTR) { if(fputs(buf, stdout) == EOF) { @@ -351,7 +351,7 @@ compile(const vector<string>& argv) // FileTracker::instance()->cleanup(); p->destroy(); - getErrorStream() << argv[0] << ": error: " << ex.reason() << endl; + consoleErr << argv[0] << ": error: " << ex.reason() << endl; return EXIT_FAILURE; } } @@ -366,7 +366,6 @@ compile(const vector<string>& argv) if(interrupted) { - out.cleanup(); FileTracker::instance()->cleanup(); return EXIT_FAILURE; } @@ -375,11 +374,16 @@ compile(const vector<string>& argv) if(dependJSON) { - out.os() << "}" << endl; + os << "}\n"; } else if(dependxml) { - out.os() << "</dependencies>\n"; + os << "</dependencies>\n"; + } + + if(depend || dependJSON || dependxml) + { + writeDependencies(os.str(), dependFile); } return status; @@ -398,22 +402,22 @@ int main(int argc, char* argv[]) } catch(const std::exception& ex) { - getErrorStream() << args[0] << ": error:" << ex.what() << endl; + consoleErr << args[0] << ": error:" << ex.what() << endl; return EXIT_FAILURE; } catch(const std::string& msg) { - getErrorStream() << args[0] << ": error:" << msg << endl; + consoleErr << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(const char* msg) { - getErrorStream() << args[0] << ": error:" << msg << endl; + consoleErr << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(...) { - getErrorStream() << args[0] << ": error:" << "unknown exception" << endl; + consoleErr << args[0] << ": error:" << "unknown exception" << endl; return EXIT_FAILURE; } } |