From d4ed7973f1824478477be29989fc125b04207494 Mon Sep 17 00:00:00 2001 From: Jose Date: Mon, 9 Jan 2017 17:01:31 +0100 Subject: Fixed (ICE-6694) - Unicode output in command line tools --- cpp/src/slice2js/Main.cpp | 54 ++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 26 deletions(-) (limited to 'cpp/src/slice2js/Main.cpp') diff --git a/cpp/src/slice2js/Main.cpp b/cpp/src/slice2js/Main.cpp index a4d9023395c..158e31efd00 100644 --- a/cpp/src/slice2js/Main.cpp +++ b/cpp/src/slice2js/Main.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -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" @@ -111,7 +113,7 @@ compile(const vector& 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]); @@ -127,7 +129,7 @@ compile(const vector& argv) if(opts.isSet("version")) { - getErrorStream() << ICE_STRING_VERSION << endl; + consoleErr << ICE_STRING_VERSION << endl; return EXIT_SUCCESS; } @@ -172,7 +174,7 @@ compile(const vector& 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]); @@ -182,7 +184,7 @@ compile(const vector& 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]); @@ -192,7 +194,7 @@ compile(const vector& 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]); @@ -202,7 +204,7 @@ compile(const vector& 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]); @@ -220,14 +222,14 @@ compile(const vector& argv) IceUtil::CtrlCHandler ctrlCHandler; ctrlCHandler.setCallback(interruptedCallback); - DependOutputUtil out(dependFile); + ostringstream os; if(dependJSON) { - out.os() << "{" << endl; + os << "{" << endl; } else if(dependxml) { - out.os() << "\n" << endl; + os << "\n" << endl; } // @@ -252,7 +254,6 @@ compile(const vector& argv) if(cppHandle == 0) { - out.cleanup(); return EXIT_FAILURE; } @@ -262,24 +263,21 @@ compile(const vector& 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; } @@ -287,9 +285,9 @@ compile(const vector& argv) { if(!last) { - out.os() << ","; + os << ","; } - out.os() << "\n"; + os << "\n"; } } else @@ -353,7 +351,7 @@ compile(const vector& argv) // FileTracker::instance()->cleanup(); p->destroy(); - getErrorStream() << argv[0] << ": error: " << ex.reason() << endl; + consoleErr << argv[0] << ": error: " << ex.reason() << endl; return EXIT_FAILURE; } } @@ -368,7 +366,6 @@ compile(const vector& argv) if(interrupted) { - out.cleanup(); FileTracker::instance()->cleanup(); return EXIT_FAILURE; } @@ -377,11 +374,16 @@ compile(const vector& argv) if(dependJSON) { - out.os() << "}" << endl; + os << "}\n"; } else if(dependxml) { - out.os() << "\n"; + os << "\n"; + } + + if(depend || dependJSON || dependxml) + { + writeDependencies(os.str(), dependFile); } return status; @@ -400,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; } } -- cgit v1.2.3