From f3de0f63df974b9ca01817d46d5fc8c831f72918 Mon Sep 17 00:00:00 2001 From: Juergen Schmidt Date: Fri, 1 Oct 2010 14:20:45 +0200 Subject: jsc340: i14847: clean up cmdline help fo devtools --- idlc/source/options.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'idlc') diff --git a/idlc/source/options.cxx b/idlc/source/options.cxx index c90bce43b3bc..a115a2262fe1 100644 --- a/idlc/source/options.cxx +++ b/idlc/source/options.cxx @@ -343,8 +343,8 @@ OString Options::prepareHelp() OString Options::prepareVersion() { - OString version("\nSun Microsystems (R) "); - version += m_program + " Version 1.1\n\n"; + OString version(m_program); + version += " Version 1.1\n\n"; return version; } -- cgit From 1bd0f73be5802157f5ccd3ba4b79ce76150d0114 Mon Sep 17 00:00:00 2001 From: "Matthias Huetsch [mhu]" Date: Thu, 25 Nov 2010 14:24:19 +0100 Subject: #i115784# idlc: fix memory errors uncovered by valgrind and other tools. --- idlc/source/astexpression.cxx | 21 +++++------ idlc/source/options.cxx | 81 +++++++++++++++++++++---------------------- idlc/source/preproc/eval.c | 15 ++++---- idlc/source/preproc/lex.c | 10 ++++-- idlc/source/preproc/unix.c | 1 + 5 files changed, 64 insertions(+), 64 deletions(-) (limited to 'idlc') diff --git a/idlc/source/astexpression.cxx b/idlc/source/astexpression.cxx index a93c13ecf8ba..357da1ab362e 100644 --- a/idlc/source/astexpression.cxx +++ b/idlc/source/astexpression.cxx @@ -27,6 +27,7 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_idlc.hxx" + #include #include #include @@ -34,6 +35,7 @@ #include #include +#include // auto_ptr<> #undef MAXCHAR #define MAXCHAR 127 @@ -927,7 +929,6 @@ AstExprValue* AstExpression::eval_internal(EvalKind ek) AstExprValue* AstExpression::eval_bin_op(EvalKind ek) { - AstExprValue *retval = NULL; ExprType eType = ET_double; if ( m_combOperator == EC_mod ) @@ -950,7 +951,7 @@ AstExprValue* AstExpression::eval_bin_op(EvalKind ek) if (m_subExpr2->getExprValue() == NULL) return NULL; - retval = new AstExprValue(); + std::auto_ptr< AstExprValue > retval(new AstExprValue()); retval->et = eType; switch (m_combOperator) @@ -971,20 +972,18 @@ AstExprValue* AstExpression::eval_bin_op(EvalKind ek) break; case EC_div: if (m_subExpr2->getExprValue()->u.dval == 0.0) - return NULL; + return NULL; retval->u.dval = m_subExpr1->getExprValue()->u.dval / m_subExpr2->getExprValue()->u.dval; break; default: return NULL; } - return retval; + return retval.release(); } AstExprValue* AstExpression::eval_bit_op(EvalKind ek) { - AstExprValue *retval = NULL; - if (ek != EK_const && ek != EK_positive_int) return NULL; if (m_subExpr1 == NULL || m_subExpr2 == NULL) @@ -1002,7 +1001,7 @@ AstExprValue* AstExpression::eval_bit_op(EvalKind ek) if (m_subExpr2->getExprValue() == NULL) return NULL; - retval = new AstExprValue; + std::auto_ptr< AstExprValue > retval(new AstExprValue()); retval->et = ET_long; switch (m_combOperator) @@ -1026,13 +1025,11 @@ AstExprValue* AstExpression::eval_bit_op(EvalKind ek) return NULL; } - return retval; + return retval.release(); } AstExprValue* AstExpression::eval_un_op(EvalKind ek) { - AstExprValue *retval = NULL; - if (m_exprValue != NULL) return m_exprValue; @@ -1047,7 +1044,7 @@ AstExprValue* AstExpression::eval_un_op(EvalKind ek) if (m_subExpr1->getExprValue() == NULL) return NULL; - retval = new AstExprValue(); + std::auto_ptr< AstExprValue > retval(new AstExprValue()); retval->et = ET_double; switch (m_combOperator) @@ -1068,7 +1065,7 @@ AstExprValue* AstExpression::eval_un_op(EvalKind ek) return NULL; } - return retval; + return retval.release(); } AstExprValue* AstExpression::eval_symbol(EvalKind ek) diff --git a/idlc/source/options.cxx b/idlc/source/options.cxx index c90bce43b3bc..0c6da3bb8ec0 100644 --- a/idlc/source/options.cxx +++ b/idlc/source/options.cxx @@ -28,9 +28,10 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_idlc.hxx" +#include "idlc/options.hxx" + #include -#include /*MSVC trouble: */ -#include +#include using namespace rtl; @@ -226,7 +227,7 @@ sal_Bool Options::initOptions(int ac, char* av[], sal_Bool bCmdFile) exit(0); } case 's': - if (/*MSVC trouble: std::*/strcmp(&av[j][2], "tdin") == 0) + if (strcmp(&av[j][2], "tdin") == 0) { m_stdin = true; break; @@ -246,53 +247,49 @@ sal_Bool Options::initOptions(int ac, char* av[], sal_Bool bCmdFile) ret = sal_False; } else { - int rargc=0; - char* rargv[512]; - char buffer[512]=""; + std::vector< std::string > args; + + std::string buffer; + buffer.reserve(256); - int i=0; - int found = 0; - char c; - while ( fscanf(cmdFile, "%c", &c) != EOF ) + bool quoted = false; + int c = EOF; + while ((c = fgetc(cmdFile)) != EOF) { - if (c=='\"') { - if (found) { - found=0; - } else { - found=1; - continue; - } - } else { - if (c!=13 && c!=10) { - if (found || c!=' ') { - buffer[i++]=c; - continue; + switch(c) + { + case '\"': + quoted = !quoted; + break; + case ' ': + case '\t': + case '\r': + case '\n': + if (!quoted) + { + if (!buffer.empty()) + { + // append current argument. + args.push_back(buffer); + buffer.clear(); } + break; } - if (i==0) - continue; + default: + // quoted white-space fall through + buffer.push_back(sal::static_int_cast(c)); + break; } - buffer[i]='\0'; - found=0; - i=0; - rargv[rargc]= strdup(buffer); - rargc++; - buffer[0]='\0'; } - if (buffer[0] != '\0') { - buffer[i]='\0'; - rargv[rargc]= strdup(buffer); - rargc++; - } - fclose(cmdFile); - - ret = initOptions(rargc, rargv, bCmdFile); - - long ii = 0; - for (ii=0; ii < rargc; ii++) + if (!buffer.empty()) { - free(rargv[ii]); + // append unterminated argument. + args.push_back(buffer); + buffer.clear(); } + (void) fclose(cmdFile); + + ret = initOptions(args.size(), args.data(), bCmdFile); } } else { diff --git a/idlc/source/preproc/eval.c b/idlc/source/preproc/eval.c index cd3adc2204c7..bed61eb95f00 100644 --- a/idlc/source/preproc/eval.c +++ b/idlc/source/preproc/eval.c @@ -24,9 +24,11 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ + +#include "cpp.h" + #include #include -#include "cpp.h" #define NSTAK 32 #define SGN 0 @@ -736,10 +738,10 @@ struct value } else { - static char cvcon[] - = "b\bf\fn\nr\rt\tv\v''\"\"??\\\\"; + static char cvcon[] = "b\bf\fn\nr\rt\tv\v''\"\"??\\\\"; + static int cvlen = sizeof(cvcon) - 1; - for (i = 0; i < (int)sizeof(cvcon); i += 2) + for (i = 0; i < cvlen; i += 2) { if (*p == cvcon[i]) { @@ -748,9 +750,8 @@ struct value } } p += 1; - if (i >= (int)sizeof(cvcon)) - error(WARNING, - "Undefined escape in character constant"); + if (i >= cvlen) + error(WARNING,"Undefined escape in character constant"); } } else diff --git a/idlc/source/preproc/lex.c b/idlc/source/preproc/lex.c index fd6d00792984..856ee72bfc53 100644 --- a/idlc/source/preproc/lex.c +++ b/idlc/source/preproc/lex.c @@ -290,7 +290,7 @@ void bigfsm[j][fp->state] = (short) nstate; continue; case C_ALPH: - for (j = 0; j <= 256; j++) + for (j = 0; j < 256; j++) if (('a' <= j && j <= 'z') || ('A' <= j && j <= 'Z') || j == '_') bigfsm[j][fp->state] = (short) nstate; @@ -687,9 +687,13 @@ void if (s->fd >= 0) { - close(s->fd); - dofree(s->inb); + (void) close(s->fd); + dofree(s->filename); } + + if (s->inb) + dofree(s->inb); + cursource = s->next; dofree(s); } diff --git a/idlc/source/preproc/unix.c b/idlc/source/preproc/unix.c index a1b52ce72f06..2d37fa1eef95 100644 --- a/idlc/source/preproc/unix.c +++ b/idlc/source/preproc/unix.c @@ -92,6 +92,7 @@ void maketokenrow(3, &tr); gettokens(&tr, 1); doadefine(&tr, c); + dofree(tr.bp); tr.bp = 0; unsetsource(); break; -- cgit 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) + { + // "-