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/source/idlcmain.cxx | 14 +- idlc/source/options.cxx | 526 ++++++++++++++++++++++++----------------------- 2 files changed, 282 insertions(+), 258 deletions(-) (limited to 'idlc/source') 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) + { + // "-