From 0897bd94a7d430a3d14a2de01a109191bb89c86e Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 8 Mar 2012 11:20:20 +0200 Subject: Print usage/version information to STDOUT instead of STDERR --- examples/cxx/tree/embedded/xsdbin.cxx | 40 +++---- xsd/cxx/parser/generator.cxx | 129 +++++++++++----------- xsd/cxx/tree/generator.cxx | 201 +++++++++++++++++----------------- xsd/xsd.cxx | 63 ++++++----- 4 files changed, 221 insertions(+), 212 deletions(-) diff --git a/examples/cxx/tree/embedded/xsdbin.cxx b/examples/cxx/tree/embedded/xsdbin.cxx index 53e2533..0da307b 100644 --- a/examples/cxx/tree/embedded/xsdbin.cxx +++ b/examples/cxx/tree/embedded/xsdbin.cxx @@ -88,10 +88,13 @@ main (int argc, char* argv[]) string base; string outdir; - class usage {}; + struct usage + { + usage (bool e = true): error (e) {} + bool error; + }; int argi (1); - bool help (false); bool multi_import (true); bool verbose (false); @@ -102,10 +105,7 @@ main (int argc, char* argv[]) string a (argv[argi]); if (a == "--help") - { - help = true; - throw usage (); - } + throw usage (false); else if (a == "--verbose") { verbose = true; @@ -154,20 +154,22 @@ main (int argc, char* argv[]) base = argv[argi]; } - catch (usage const&) + catch (usage const& e) { - cerr << "Usage: " << argv[0] << " [options] " << endl - << "Options:" << endl - << " --help Print usage information and exit." << endl - << " --verbose Print progress information." << endl - << " --output-dir Write generated files to ." << endl - << " --hxx-suffix Header file suffix instead of '-schema.hxx'." << endl - << " --cxx-suffix Source file suffix instead of '-schema.cxx'." << endl - << " --array-name Binary data array name." << endl - << " --disable-multi-import Disable multiple import support." << endl - << endl; - - return help ? 0 : 1; + ostream& o (e.error ? cerr : cout); + + o << "Usage: " << argv[0] << " [options] " << endl + << "Options:" << endl + << " --help Print usage information and exit." << endl + << " --verbose Print progress information." << endl + << " --output-dir Write generated files to ." << endl + << " --hxx-suffix Header file suffix instead of '-schema.hxx'." << endl + << " --cxx-suffix Source file suffix instead of '-schema.cxx'." << endl + << " --array-name Binary data array name." << endl + << " --disable-multi-import Disable multiple import support." << endl + << endl; + + return e.error ? 0 : 1; } XMLPlatformUtils::Initialize (); diff --git a/xsd/cxx/parser/generator.cxx b/xsd/cxx/parser/generator.cxx index 4e067d8..8723940 100644 --- a/xsd/cxx/parser/generator.cxx +++ b/xsd/cxx/parser/generator.cxx @@ -48,6 +48,7 @@ using std::endl; using std::wcerr; +using std::wcout; using namespace XSDFrontend::SemanticGraph; @@ -191,22 +192,22 @@ namespace CXX Void Parser::Generator:: usage () { - std::wostream& e (wcerr); - ::CLI::Indent::Clip< ::CLI::OptionsUsage, WideChar> clip (e); + std::wostream& o (wcout); + ::CLI::Indent::Clip< ::CLI::OptionsUsage, WideChar> clip (o); - e << "--type-map " << endl + o << "--type-map " << endl << " Read XML Schema to C++ type mapping information\n" << " from . Repeat this option to specify\n" << " several type maps. Type maps are considered in\n" << " order of appearance and the first match is used." << endl; - e << "--char-type " << endl + o << "--char-type " << endl << " Use as the base character type. Valid\n" << " values are 'char' (default) and 'wchar_t'." << endl; - e << "--char-encoding " << endl + o << "--char-encoding " << endl << " Specify the character encoding that should be used\n" << " in the object model. Valid values for the 'char'\n" << " character type are 'utf8' (default), 'iso8859-1',\n" @@ -214,176 +215,176 @@ namespace CXX << " type the only valid value is 'auto'." << endl; - e << "--output-dir " << endl + o << "--output-dir " << endl << " Write generated files to instead of current\n" << " directory." << endl; - e << "--xml-parser " << endl + o << "--xml-parser " << endl << " Use as the underlying XML parser. Valid\n" << " values are 'xerces' (default) and 'expat'." << endl; - e << "--generate-inline" << endl + o << "--generate-inline" << endl << " Generate certain functions inline." << endl; - e << "--generate-validation" << endl + o << "--generate-validation" << endl << " Generate validation code." << endl; - e << "--suppress-validation" << endl + o << "--suppress-validation" << endl << " Suppress the generation of validation code." << endl; - e << "--generate-polymorphic" << endl + o << "--generate-polymorphic" << endl << " Generate polymorphism-aware code. Specify this\n" << " option if you use substitution groups or xsi:type." << endl; - e << "--generate-noop-impl" << endl + o << "--generate-noop-impl" << endl << " Generate a sample parser implementation that\n" << " does nothing (no operation)." << endl; - e << "--generate-print-impl" << endl + o << "--generate-print-impl" << endl << " Generate a sample parser implementation that\n" << " prints the XML data to STDOUT." << endl; - e << "--generate-test-driver" << endl + o << "--generate-test-driver" << endl << " Generate a test driver for the sample parser\n" << " implementation." << endl; - e << "--force-overwrite" << endl + o << "--force-overwrite" << endl << " Force overwriting of the existing implementation\n" << " and test driver files." << endl; - e << "--root-element-first" << endl + o << "--root-element-first" << endl << " Indicate that the first global element is the\n" << " document root." << endl; - e << "--root-element-last" << endl + o << "--root-element-last" << endl << " Indicate that the last global element is the\n" << " document root." << endl; - e << "--root-element " << endl + o << "--root-element " << endl << " Indicate that is the document root." << endl; - e << "--generate-xml-schema" << endl + o << "--generate-xml-schema" << endl << " Generate a C++ header file as if the schema being\n" << " compiled defines the XML Schema namespace." << endl; - e << "--extern-xml-schema " << endl + o << "--extern-xml-schema " << endl << " Generate code as if the XML Schema namespace was\n" << " defined in and xsd:included in the schema\n" << " being compiled." << endl; - e << "--skel-type-suffix " << endl + o << "--skel-type-suffix " << endl << " Use instead of the default '_pskel' to\n" << " construct the names of generated parser skeletons." << endl; - e << "--skel-file-suffix " << endl + o << "--skel-file-suffix " << endl << " Use instead of the default '-pskel' to\n" << " construct the names of generated parser skeleton\n" << " files." << endl; - e << "--impl-type-suffix " << endl + o << "--impl-type-suffix " << endl << " Use instead of the default '_pimpl' to\n" << " construct the names of parser implementations for\n" << " the built-in XML Schema types and sample parser\n" << " implementations." << endl; - e << "--impl-file-suffix " << endl + o << "--impl-file-suffix " << endl << " Use instead of the default '-pimpl' to\n" << " construct the names of generated sample parser\n" << " implementation files." << endl; - e << "--namespace-map =" << endl + o << "--namespace-map =" << endl << " Map XML Schema namespace to C++ namespace\n" << " . Repeat this option to specify mapping for\n" << " more than one XML Schema namespace." << endl; - e << "--namespace-regex " << endl + o << "--namespace-regex " << endl << " Add to the list of regular expressions\n" << " used to translate XML Schema namespace names to\n" << " C++ namespace names." << endl; - e << "--namespace-regex-trace" << endl + o << "--namespace-regex-trace" << endl << " Trace the process of applying regular expressions\n" << " specified with the --namespace-regex option." << endl; - e << "--reserved-name " << endl + o << "--reserved-name " << endl << " Add to the list of names that should not\n" << " be used as identifiers. The name can optionally\n" << " be followed by '=' and the replacement name that\n" << " should be used instead." << endl; - e << "--include-with-brackets" << endl + o << "--include-with-brackets" << endl << " Use angle brackets (<>) instead of quotes (\"\") in\n" << " generated #include directives." << endl; - e << "--include-prefix " << endl + o << "--include-prefix " << endl << " Add to generated #include directive\n" << " paths." << endl; - e << "--include-regex " << endl + o << "--include-regex " << endl << " Add to the list of regular expressions\n" << " used to transform #include directive paths." << endl; - e << "--include-regex-trace" << endl + o << "--include-regex-trace" << endl << " Trace the process of applying regular expressions\n" << " specified with the --include-regex option." << endl; - e << "--guard-prefix " << endl + o << "--guard-prefix " << endl << " Add to generated header inclusion guards." << endl; - e << "--hxx-suffix " << endl + o << "--hxx-suffix " << endl << " Use instead of the default '.hxx' to\n" << " construct the name of the header file." << endl; - e << "--ixx-suffix " << endl + o << "--ixx-suffix " << endl << " Use instead of the default '.ixx' to\n" << " construct the name of the inline file." << endl; - e << "--cxx-suffix " << endl + o << "--cxx-suffix " << endl << " Use instead of the default '.cxx' to\n" << " construct the name of the source file." << endl; - e << "--hxx-regex " << endl + o << "--hxx-regex " << endl << " Use to construct the name of the header\n" << " file." << endl; - e << "--ixx-regex " << endl + o << "--ixx-regex " << endl << " Use to construct the name of the inline\n" << " file." << endl; - e << "--cxx-regex " << endl + o << "--cxx-regex " << endl << " Use to construct the name of the source\n" << " file." << endl; @@ -391,19 +392,19 @@ namespace CXX // Prologues. // - e << "--hxx-prologue " << endl + o << "--hxx-prologue " << endl << " Insert at the beginning of the header file." << endl; - e << "--ixx-prologue " << endl + o << "--ixx-prologue " << endl << " Insert at the beginning of the inline file." << endl; - e << "--cxx-prologue " << endl + o << "--cxx-prologue " << endl << " Insert at the beginning of the source file." << endl; - e << "--prologue " << endl + o << "--prologue " << endl << " Insert at the beginning of each generated\n" << " file for which there is no file-specific prologue." << endl; @@ -411,19 +412,19 @@ namespace CXX // Epilogues. // - e << "--hxx-epilogue " << endl + o << "--hxx-epilogue " << endl << " Insert at the end of the header file." << endl; - e << "--ixx-epilogue " << endl + o << "--ixx-epilogue " << endl << " Insert at the end of the inline file." << endl; - e << "--cxx-epilogue " << endl + o << "--cxx-epilogue " << endl << " Insert at the end of the source file." << endl; - e << "--epilogue " << endl + o << "--epilogue " << endl << " Insert at the end of each generated file\n" << " for which there is no file-specific epilogue." << endl; @@ -431,22 +432,22 @@ namespace CXX // Prologue files. // - e << "--hxx-prologue-file " << endl + o << "--hxx-prologue-file " << endl << " Insert the content of the at the beginning\n" << " of the header file." << endl; - e << "--ixx-prologue-file " << endl + o << "--ixx-prologue-file " << endl << " Insert the content of the at the beginning\n" << " of the inline file." << endl; - e << "--cxx-prologue-file " << endl + o << "--cxx-prologue-file " << endl << " Insert the content of the at the beginning\n" << " of the source file." << endl; - e << "--prologue-file " << endl + o << "--prologue-file " << endl << " Insert the content of the at the beginning\n" << " of each generated file for which there is no file-\n" << " specific prologue file." @@ -455,22 +456,22 @@ namespace CXX // Epilogue files. // - e << "--hxx-epilogue-file " << endl + o << "--hxx-epilogue-file " << endl << " Insert the content of the at the end of\n" << " the header file." << endl; - e << "--ixx-epilogue-file " << endl + o << "--ixx-epilogue-file " << endl << " Insert the content of the at the end of\n" << " the inline file." << endl; - e << "--cxx-epilogue-file " << endl + o << "--cxx-epilogue-file " << endl << " Insert the content of the at the end of\n" << " the source file." << endl; - e << "--epilogue-file " << endl + o << "--epilogue-file " << endl << " Insert the content of the at the end of\n" << " each generated file for which there is no file-\n" << " specific epilogue file." @@ -479,45 +480,45 @@ namespace CXX // Misc. // - e << "--custom-literals " << endl + o << "--custom-literals " << endl << " Load custom XML string to C++ literal mappings\n" << " from ." << endl; - e << "--export-symbol " << endl + o << "--export-symbol " << endl << " Export symbol for Win32 DLL export/import control." << endl; - e << "--export-maps" << endl + o << "--export-maps" << endl << " Export polymorphism support maps from Win32 DLL." << endl; - e << "--import-maps" << endl + o << "--import-maps" << endl << " Import polymorphism support maps from Win32 DLL." << endl; - e << "--show-anonymous" << endl + o << "--show-anonymous" << endl << " Show elements and attributes that are of anonymous\n" << " types." << endl; - e << "--show-sloc" << endl + o << "--show-sloc" << endl << " Show the number of generated physical source lines\n" << " of code (SLOC)." << endl; - e << "--sloc-limit " << endl + o << "--sloc-limit " << endl << " Check that the number of generated physical source\n" << " lines of code (SLOC) does not exceed ." << endl; - e << "--options-file " << endl + o << "--options-file " << endl << " Read additional options from . Each option\n" << " should appear on a separate line optionally\n" << " followed by space and an argument." << endl; - e << "--proprietary-license" << endl + o << "--proprietary-license" << endl << " Indicate that the generated code is licensed under\n" << " a proprietary license instead of the GPL." << endl; diff --git a/xsd/cxx/tree/generator.cxx b/xsd/cxx/tree/generator.cxx index 006a666..19cdd0e 100644 --- a/xsd/cxx/tree/generator.cxx +++ b/xsd/cxx/tree/generator.cxx @@ -50,6 +50,7 @@ using std::endl; using std::wcerr; +using std::wcout; using namespace XSDFrontend::SemanticGraph; @@ -218,15 +219,15 @@ namespace CXX Void Tree::Generator:: usage () { - std::wostream& e (wcerr); - ::CLI::Indent::Clip< ::CLI::OptionsUsage, WideChar> clip (e); + std::wostream& o (wcout); + ::CLI::Indent::Clip< ::CLI::OptionsUsage, WideChar> clip (o); - e << "--char-type " << endl + o << "--char-type " << endl << " Use as the base character type. Valid\n" << " values are 'char' (default) and 'wchar_t'." << endl; - e << "--char-encoding " << endl + o << "--char-encoding " << endl << " Specify the character encoding that should be used\n" << " in the object model. Valid values for the 'char'\n" << " character type are 'utf8' (default), 'iso8859-1',\n" @@ -234,293 +235,293 @@ namespace CXX << " type the only valid value is 'auto'." << endl; - e << "--output-dir " << endl + o << "--output-dir " << endl << " Write generated files to instead of current\n" << " directory." << endl; - e << "--generate-polymorphic" << endl + o << "--generate-polymorphic" << endl << " Generate polymorphism-aware code. Specify this\n" << " option if you use substitution groups or xsi:type." << endl; - e << "--polymorphic-type " << endl + o << "--polymorphic-type " << endl << " Indicate that is a root of a polymorphic\n" << " type hierarchy." << endl; - e << "--polymorphic-type-all" << endl + o << "--polymorphic-type-all" << endl << " Indicate that all types should be treated as\n" << " polymorphic." << endl; - e << "--generate-serialization" << endl + o << "--generate-serialization" << endl << " Generate serialization functions. They convert an\n" << " in-memory representation back to XML." << endl; - e << "--generate-inline" << endl + o << "--generate-inline" << endl << " Generate certain functions inline." << endl; - e << "--generate-ostream" << endl + o << "--generate-ostream" << endl << " Generate ostream insertion operators." << endl; - e << "--generate-doxygen" << endl + o << "--generate-doxygen" << endl << " Generate documentation comments in the Doxygen\n" << " format." << endl; - e << "--generate-comparison" << endl + o << "--generate-comparison" << endl << " Generate comparison operators." << endl; - e << "--generate-default-ctor" << endl + o << "--generate-default-ctor" << endl << " Generate default constructors even for types that\n" << " have required members." << endl; - e << "--generate-from-base-ctor" << endl + o << "--generate-from-base-ctor" << endl << " Generate from-base constructors." << endl; - e << "--suppress-assignment" << endl + o << "--suppress-assignment" << endl << " Suppress the generation of copy assignment\n" << " operators for complex types." << endl; - e << "--generate-detach" << endl + o << "--generate-detach" << endl << " Generate detach functions for required members." << endl; - e << "--generate-wildcard" << endl + o << "--generate-wildcard" << endl << " Generate accessors/modifiers as well as parsing\n" << " and serialization code for XML Schema wildcards." << endl; - e << "--generate-insertion " << endl + o << "--generate-insertion " << endl << " Generate data representation stream insertion\n" << " operators for the output stream type." << endl; - e << "--generate-extraction " << endl + o << "--generate-extraction " << endl << " Generate data representation stream extraction\n" << " constructors for the input stream type." << endl; - e << "--generate-forward" << endl + o << "--generate-forward" << endl << " Generate forward declaration file." << endl; - e << "--generate-xml-schema" << endl + o << "--generate-xml-schema" << endl << " Generate a C++ header file as if the schema being\n" << " compiled defines the XML Schema namespace." << endl; - e << "--extern-xml-schema " << endl + o << "--extern-xml-schema " << endl << " Generate code as if the XML Schema namespace was\n" << " defined in and xsd:included in the schema\n" << " being compiled." << endl; - e << "--suppress-parsing" << endl + o << "--suppress-parsing" << endl << " Suppress the generation of parsing functions." << endl; - e << "--generate-element-type" << endl + o << "--generate-element-type" << endl << " Generate types instead of parsing/serialization\n" << " functions for root elements." << endl; - e << "--generate-element-map" << endl + o << "--generate-element-map" << endl << " Generate a root element map that allows uniform\n" << " parsing/serialization of multiple root elements.\n" << endl; - e << "--generate-intellisense" << endl + o << "--generate-intellisense" << endl << " Generate workarounds for IntelliSense bugs in\n" << " Visual Studio 2005 (8.0)." << endl; - e << "--omit-default-attributes" << endl + o << "--omit-default-attributes" << endl << " Omit attributes with default and fixed values\n" << " from serialized XML documents." << endl; - e << "--namespace-map =" << endl + o << "--namespace-map =" << endl << " Map XML Schema namespace to C++ namespace\n" << " . Repeat this option to specify mapping for\n" << " more than one XML Schema namespace." << endl; - e << "--namespace-regex " << endl + o << "--namespace-regex " << endl << " Add to the list of regular expressions\n" << " used to translate XML Schema namespace names to\n" << " C++ namespace names." << endl; - e << "--namespace-regex-trace" << endl + o << "--namespace-regex-trace" << endl << " Trace the process of applying regular expressions\n" << " specified with the --namespace-regex option." << endl; - e << "--reserved-name " << endl + o << "--reserved-name " << endl << " Add to the list of names that should not\n" << " be used as identifiers. The name can optionally\n" << " be followed by '=' and the replacement name that\n" << " should be used instead." << endl; - e << "--type-naming