diff options
author | Jose <jose@zeroc.com> | 2017-01-09 17:01:31 +0100 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2017-01-09 17:01:31 +0100 |
commit | d4ed7973f1824478477be29989fc125b04207494 (patch) | |
tree | ec488f46a0ee15f987a0a24c87d1fe0a999cc168 /cpp/src/slice2java/Main.cpp | |
parent | IceSSL C#/Java test fixes to sync with C++ changes (diff) | |
download | ice-d4ed7973f1824478477be29989fc125b04207494.tar.bz2 ice-d4ed7973f1824478477be29989fc125b04207494.tar.xz ice-d4ed7973f1824478477be29989fc125b04207494.zip |
Fixed (ICE-6694) - Unicode output in command line tools
Diffstat (limited to 'cpp/src/slice2java/Main.cpp')
-rw-r--r-- | cpp/src/slice2java/Main.cpp | 67 |
1 files changed, 26 insertions, 41 deletions
diff --git a/cpp/src/slice2java/Main.cpp b/cpp/src/slice2java/Main.cpp index 198fda6b838..27845a76994 100644 --- a/cpp/src/slice2java/Main.cpp +++ b/cpp/src/slice2java/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> @@ -20,6 +21,7 @@ using namespace std; using namespace Slice; +using namespace IceUtilInternal; namespace { @@ -58,8 +60,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" @@ -122,7 +124,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]); @@ -138,7 +140,7 @@ compile(const vector<string>& argv) if(opts.isSet("version")) { - getErrorStream() << ICE_STRING_VERSION << endl; + consoleErr << ICE_STRING_VERSION << endl; return EXIT_SUCCESS; } @@ -193,7 +195,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]); @@ -203,7 +205,7 @@ compile(const vector<string>& argv) if(impl && implTie) { - getErrorStream() << argv[0] << ": error: cannot specify both --impl and --impl-tie" << endl; + consoleErr << argv[0] << ": error: cannot specify both --impl and --impl-tie" << endl; if(!validate) { usage(argv[0]); @@ -213,7 +215,7 @@ compile(const vector<string>& argv) if(!compat && (tie || implTie)) { - getErrorStream() << argv[0] << ": error: TIE classes are only supported with the Java-Compat mapping" << endl; + consoleErr << argv[0] << ": error: TIE classes are only supported with the Java-Compat mapping" << endl; if(!validate) { usage(argv[0]); @@ -223,7 +225,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]); @@ -243,10 +245,10 @@ compile(const vector<string>& argv) IceUtil::CtrlCHandler ctrlCHandler; ctrlCHandler.setCallback(interruptedCallback); - 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; } vector<string> cppOpts; @@ -274,7 +276,6 @@ compile(const vector<string>& argv) if(cppHandle == 0) { - out.cleanup(); return EXIT_FAILURE; } @@ -284,31 +285,23 @@ compile(const vector<string>& argv) if(parseStatus == EXIT_FAILURE) { - out.cleanup(); return EXIT_FAILURE; } - if(!icecpp->printMakefileDependencies(out.os(), depend ? Preprocessor::Java : Preprocessor::SliceXML, + if(!icecpp->printMakefileDependencies(os, depend ? Preprocessor::Java : Preprocessor::SliceXML, includePaths, cppOpts)) { - out.cleanup(); return EXIT_FAILURE; } if(!icecpp->close()) { - out.cleanup(); return EXIT_FAILURE; } } else { ostringstream os; - if(listGenerated) - { - Slice::setErrorStream(os); - } - FileTracker::instance()->setSource(*i); PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs); @@ -316,10 +309,6 @@ compile(const vector<string>& argv) if(cppHandle == 0) { - if(listGenerated) - { - FileTracker::instance()->setOutput(os.str(), true); - } status = EXIT_FAILURE; break; } @@ -353,10 +342,6 @@ compile(const vector<string>& argv) if(parseStatus == EXIT_FAILURE) { p->destroy(); - if(listGenerated) - { - FileTracker::instance()->setOutput(os.str(), true); - } status = EXIT_FAILURE; } else @@ -417,11 +402,7 @@ compile(const vector<string>& argv) // FileTracker::instance()->cleanup(); p->destroy(); - getErrorStream() << argv[0] << ": error: " << ex.reason() << endl; - if(listGenerated) - { - FileTracker::instance()->setOutput(os.str(), true); - } + consoleErr << argv[0] << ": error: " << ex.reason() << endl; status = EXIT_FAILURE; break; } @@ -435,7 +416,6 @@ compile(const vector<string>& argv) if(interrupted) { - out.cleanup(); // // If the translator was interrupted then cleanup any files we've already created. // @@ -447,7 +427,12 @@ compile(const vector<string>& argv) if(dependxml) { - out.os() << "</dependencies>\n"; + os << "</dependencies>\n"; + } + + if(depend || dependxml) + { + writeDependencies(os.str(), dependFile); } if(status == EXIT_SUCCESS && !checksumClass.empty() && !dependxml) @@ -462,12 +447,12 @@ compile(const vector<string>& argv) // If a file could not be created, then cleanup any created files. // FileTracker::instance()->cleanup(); - getErrorStream() << argv[0] << ": error: " << ex.reason() << endl; + consoleErr << argv[0] << ": error: " << ex.reason() << endl; return EXIT_FAILURE; } } - if(listGenerated) + if(listGenerated && status == EXIT_SUCCESS) { FileTracker::instance()->dumpxml(); } @@ -488,22 +473,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; } } |