From: Markus Scherer Date: Fri, 4 Sep 2015 18:38:25 +0000 (+0000) Subject: ICU-11831 u_parseArgs() reset option->doesOccur in case of error X-Git-Tag: milestone-59-0-1~934 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b4b5fc8392ec8bd637bae93dffc4810b1d261536;p=icu ICU-11831 u_parseArgs() reset option->doesOccur in case of error X-SVN-Rev: 37882 --- diff --git a/icu4c/source/tools/genrb/genrb.cpp b/icu4c/source/tools/genrb/genrb.cpp index 154aa62e3fc..20ac5908beb 100644 --- a/icu4c/source/tools/genrb/genrb.cpp +++ b/icu4c/source/tools/genrb/genrb.cpp @@ -131,40 +131,31 @@ main(int argc, /* error handling, printing usage message */ if(argc<0) { fprintf(stderr, "%s: error in command line argument \"%s\"\n", argv[0], argv[-argc]); + illegalArg = TRUE; } else if(argc<2) { - argc = -1; + illegalArg = TRUE; } if(options[WRITE_POOL_BUNDLE].doesOccur && options[USE_POOL_BUNDLE].doesOccur) { fprintf(stderr, "%s: cannot combine --writePoolBundle and --usePoolBundle\n", argv[0]); - argc = -1; + illegalArg = TRUE; } if(options[FORMAT_VERSION].doesOccur) { const char *s = options[FORMAT_VERSION].value; if(uprv_strlen(s) != 1 || (s[0] < '1' && '3' < s[0])) { fprintf(stderr, "%s: unsupported --formatVersion %s\n", argv[0], s); - argc = -1; + illegalArg = TRUE; } else if(s[0] == '1' && (options[WRITE_POOL_BUNDLE].doesOccur || options[USE_POOL_BUNDLE].doesOccur) ) { fprintf(stderr, "%s: cannot combine --formatVersion 1 with --writePoolBundle or --usePoolBundle\n", argv[0]); - argc = -1; + illegalArg = TRUE; } else { setFormatVersion(s[0] - '0'); } } - if(options[VERSION].doesOccur) { - fprintf(stderr, - "%s version %s (ICU version %s).\n" - "%s\n", - argv[0], GENRB_VERSION, U_ICU_VERSION, U_COPYRIGHT_STRING); - return U_ZERO_ERROR; - } - - if(argc<0) { - illegalArg = TRUE; - } else if((options[JAVA_PACKAGE].doesOccur || options[BUNDLE_NAME].doesOccur) && - !options[WRITE_JAVA].doesOccur) { + if((options[JAVA_PACKAGE].doesOccur || options[BUNDLE_NAME].doesOccur) && + !options[WRITE_JAVA].doesOccur) { fprintf(stderr, "%s error: command line argument --java-package or --bundle-name " "without --write-java\n", @@ -172,6 +163,16 @@ main(int argc, illegalArg = TRUE; } + if(options[VERSION].doesOccur) { + fprintf(stderr, + "%s version %s (ICU version %s).\n" + "%s\n", + argv[0], GENRB_VERSION, U_ICU_VERSION, U_COPYRIGHT_STRING); + if(!illegalArg) { + return U_ZERO_ERROR; + } + } + if(illegalArg || options[HELP1].doesOccur || options[HELP2].doesOccur) { /* * Broken into chunks because the C89 standard says the minimum diff --git a/icu4c/source/tools/toolutil/uoptions.c b/icu4c/source/tools/toolutil/uoptions.c index 05efc170cbd..291e2fce4e7 100644 --- a/icu4c/source/tools/toolutil/uoptions.c +++ b/icu4c/source/tools/toolutil/uoptions.c @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 2000, International Business Machines +* Copyright (C) 2000-2015, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -60,9 +60,16 @@ u_parseArgs(int argc, char* argv[], option->value=argv[++i]; } else if(option->hasArg==UOPT_REQUIRES_ARG) { /* there is no argument, but one is required: return with error */ + option->doesOccur=0; return -i; } } + + if(option->optionFn!=NULL && option->optionFn(option->context, option)<0) { + /* the option function was called and returned an error */ + option->doesOccur=0; + return -i; + } } } else { /* process one or more short options */ @@ -95,21 +102,23 @@ u_parseArgs(int argc, char* argv[], break; } else if(option->hasArg==UOPT_REQUIRES_ARG) { /* there is no argument, but one is required: return with error */ + option->doesOccur=0; return -i; } } + if(option->optionFn!=NULL && option->optionFn(option->context, option)<0) { + /* the option function was called and returned an error */ + option->doesOccur=0; + return -i; + } + /* get the next option letter */ option=NULL; c=*arg++; } while(c!=0); } - if(option!=0 && option->optionFn!=0 && option->optionFn(option->context, option)<0) { - /* the option function was called and returned an error */ - return -i; - } - /* go to next argv[] */ ++i; } else {