diff options
Diffstat (limited to 'cpp/src/slice2objc/Main.cpp')
-rw-r--r-- | cpp/src/slice2objc/Main.cpp | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/cpp/src/slice2objc/Main.cpp b/cpp/src/slice2objc/Main.cpp index 607e6aabf7f..86ceba8dcf6 100644 --- a/cpp/src/slice2objc/Main.cpp +++ b/cpp/src/slice2objc/Main.cpp @@ -13,11 +13,13 @@ #include <IceUtil/CtrlCHandler.h> #include <IceUtil/Mutex.h> #include <IceUtil/MutexPtrLock.h> +#include <IceUtil/ConsoleUtil.h> #include <Slice/Util.h> #include "Gen.h" using namespace std; using namespace Slice; +using namespace IceUtilInternal; namespace { @@ -55,8 +57,8 @@ interruptedCallback(int signal) void usage(const string& n) { - cerr << "Usage: " << n << " [options] slice-files...\n"; - cerr << + consoleErr << "Usage: " << n << " [options] slice-files...\n"; + consoleErr << "Options:\n" "-h, --help Show this message.\n" "-v, --version Display the Ice version.\n" @@ -68,13 +70,16 @@ usage(const string& n) "-E Print preprocessor output on stdout.\n" "--include-dir DIR Use DIR as the header include directory in source files.\n" "--output-dir DIR Create files in the directory DIR.\n" - "--dll-export SYMBOL Use SYMBOL for DLL exports.\n" "--depend Generate Makefile dependencies.\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" + "--dll-export SYMBOL Use SYMBOL for DLL exports\n" + " deprecated: use instead [[\"objc:dll-export:SYMBOL\"]] metadata.\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" ; // Note: --case-sensitive is intentionally not shown here! } @@ -110,7 +115,7 @@ compile(const vector<string>& argv) } catch(const IceUtilInternal::BadOptException& e) { - cerr << argv[0] << ": " << e.reason << endl; + consoleErr << argv[0] << ": " << e.reason << endl; if(!validate) { usage(argv[0]); @@ -126,7 +131,7 @@ compile(const vector<string>& argv) if(opts.isSet("version")) { - cout << ICE_STRING_VERSION << endl; + consoleErr << ICE_STRING_VERSION << endl; return EXIT_SUCCESS; } @@ -170,7 +175,7 @@ compile(const vector<string>& argv) if(args.empty()) { - getErrorStream() << argv[0] << ": no input file" << endl; + consoleErr << argv[0] << ": no input file" << endl; if(!validate) { usage(argv[0]); @@ -180,7 +185,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]); @@ -195,10 +200,10 @@ compile(const vector<string>& argv) int status = EXIT_SUCCESS; - DependOutputUtil out(dependFile); + ostringstream os; 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; } IceUtil::CtrlCHandler ctrlCHandler; @@ -213,7 +218,6 @@ compile(const vector<string>& argv) if(cppHandle == 0) { - out.cleanup(); return EXIT_FAILURE; } @@ -223,20 +227,17 @@ compile(const vector<string>& argv) if(parseStatus == EXIT_FAILURE) { - out.cleanup(); return EXIT_FAILURE; } - if(!icecpp->printMakefileDependencies(out.os(), depend ? Preprocessor::ObjC : Preprocessor::SliceXML, + if(!icecpp->printMakefileDependencies(os, depend ? Preprocessor::ObjC : Preprocessor::SliceXML, includePaths, "-D__SLICE2OBJC__")) { - out.cleanup(); return EXIT_FAILURE; } if(!icecpp->close()) { - out.cleanup(); return EXIT_FAILURE; } } @@ -253,7 +254,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) { @@ -298,7 +299,7 @@ compile(const vector<string>& argv) // cleanup any created files. FileTracker::instance()->cleanup(); u->destroy(); - getErrorStream() << argv[0] << ": error: " << ex.reason() << endl; + consoleErr << argv[0] << ": error: " << ex.reason() << endl; return EXIT_FAILURE; } } @@ -312,7 +313,6 @@ compile(const vector<string>& argv) if(interrupted) { - out.cleanup(); FileTracker::instance()->cleanup(); return EXIT_FAILURE; } @@ -321,7 +321,12 @@ compile(const vector<string>& argv) if(dependxml) { - out.os() << "</dependencies>\n"; + os << "</dependencies>\n"; + } + + if(depend || dependxml) + { + writeDependencies(os.str(), dependFile); } return status; @@ -340,22 +345,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; } } |