]> granicus.if.org Git - icu/commitdiff
ICU-11831 u_parseArgs() reset option->doesOccur in case of error
authorMarkus Scherer <markus.icu@gmail.com>
Fri, 4 Sep 2015 18:38:25 +0000 (18:38 +0000)
committerMarkus Scherer <markus.icu@gmail.com>
Fri, 4 Sep 2015 18:38:25 +0000 (18:38 +0000)
X-SVN-Rev: 37882

icu4c/source/tools/genrb/genrb.cpp
icu4c/source/tools/toolutil/uoptions.c

index 154aa62e3fcb3eccd493de921f7b2003cbcb6d94..20ac5908beb8f6cf6d927950749ef539784040ec 100644 (file)
@@ -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
index 05efc170cbdf7513dd57ebf7779b982e97a21d94..291e2fce4e7fb88cebfb0375901bc691c8742a76 100644 (file)
@@ -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 {