From 232c0fb700efd31eff8cfee896437c481582ed0f Mon Sep 17 00:00:00 2001 From: "Matthias Huetsch [mhu]" Date: Fri, 10 Dec 2010 08:38:05 +0100 Subject: #115784# idlc: fixed commandline option processing. --- idlc/inc/idlc/options.hxx | 17 +- idlc/source/idlcmain.cxx | 14 +- idlc/source/options.cxx | 526 ++++++++++++++++++++++++---------------------- 3 files changed, 296 insertions(+), 261 deletions(-) (limited to 'idlc') diff --git a/idlc/inc/idlc/options.hxx b/idlc/inc/idlc/options.hxx index 7eba788a4ea9..383150bd4b40 100644 --- a/idlc/inc/idlc/options.hxx +++ b/idlc/inc/idlc/options.hxx @@ -50,18 +50,29 @@ public: class Options { public: - Options(); + explicit Options(char const * progname); ~Options(); + static bool checkArgument(std::vector< std::string > & rArgs, char const * arg, size_t len); + static bool checkCommandFile(std::vector< std::string > & rArgs, char const * filename); + + bool initOptions(std::vector< std::string > & rArgs) + throw(IllegalArgument); + bool badOption(char const * reason, std::string const & rArg) + throw(IllegalArgument); + bool setOption(char const * option, std::string const & rArg); + +#if 0 /* @@@ */ sal_Bool initOptions(int ac, char* av[], sal_Bool bCmdFile=sal_False) throw( IllegalArgument ); +#endif /* @@@ */ ::rtl::OString prepareHelp(); ::rtl::OString prepareVersion(); const ::rtl::OString& getProgramName() const; - sal_Bool isValid(const ::rtl::OString& option); - const ::rtl::OString getOption(const ::rtl::OString& option) + bool isValid(const ::rtl::OString& option); + const ::rtl::OString& getOption(const ::rtl::OString& option) throw( IllegalArgument ); const StringVector& getInputFiles() const { return m_inputFiles; } diff --git a/idlc/source/idlcmain.cxx b/idlc/source/idlcmain.cxx index 006131f727df..6e3af1baca73 100644 --- a/idlc/source/idlcmain.cxx +++ b/idlc/source/idlcmain.cxx @@ -34,19 +34,25 @@ using namespace ::rtl; SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) { - Options options; + std::vector< std::string > args; + for (int i = 1; i < argc; i++) + { + if (!Options::checkArgument (args, argv[i], strlen(argv[i]))) + return (1); + } + Options options(argv[0]); try { - if (!options.initOptions(argc, argv)) - exit(1); + if (!options.initOptions(args)) + return (0); } catch( IllegalArgument& e) { fprintf(stderr, "Illegal argument: %s\n%s", e.m_message.getStr(), options.prepareVersion().getStr()); - exit(99); + return (99); } setIdlc(&options); diff --git a/idlc/source/options.cxx b/idlc/source/options.cxx index 0c6da3bb8ec0..42b97237e34f 100644 --- a/idlc/source/options.cxx +++ b/idlc/source/options.cxx @@ -30,12 +30,18 @@ #include "idlc/options.hxx" +#include "osl/diagnose.h" +#include "rtl/string.hxx" +#include "rtl/strbuf.hxx" + #include #include -using namespace rtl; +using rtl::OString; +using rtl::OStringBuffer; -Options::Options(): m_stdin(false), m_verbose(false), m_quiet(false) +Options::Options(char const * progname) + : m_program(progname), m_stdin(false), m_verbose(false), m_quiet(false) { } @@ -43,269 +49,282 @@ Options::~Options() { } -sal_Bool Options::initOptions(int ac, char* av[], sal_Bool bCmdFile) - throw( IllegalArgument ) +// static +bool Options::checkArgument (std::vector< std::string > & rArgs, char const * arg, size_t len) { - sal_Bool ret = sal_True; - sal_uInt16 j=0; - - if (!bCmdFile) + bool result = ((arg != 0) && (len > 0)); + OSL_PRECOND(result, "idlc::Options::checkArgument(): invalid arguments"); + if (result) + { + switch(arg[0]) { - bCmdFile = sal_True; - - m_program = av[0]; - - if (ac < 2) + case '@': + if ((result = (len > 1)) == true) + { + // "@" + result = Options::checkCommandFile (rArgs, &(arg[1])); + } + break; + case '-': + if ((result = (len > 1)) == true) + { + // "-