ICU-11831 u_parseArgs() reset option->doesOccur in case of error

X-SVN-Rev: 37882
This commit is contained in:
Markus Scherer 2015-09-04 18:38:25 +00:00
parent 1310bace9c
commit b4b5fc8392
2 changed files with 32 additions and 22 deletions

View File

@ -131,45 +131,46 @@ 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[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",
argv[0]);
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);
return U_ZERO_ERROR;
}
if(argc<0) {
illegalArg = TRUE;
} else 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",
argv[0]);
illegalArg = TRUE;
if(!illegalArg) {
return U_ZERO_ERROR;
}
}
if(illegalArg || options[HELP1].doesOccur || options[HELP2].doesOccur) {

View 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 {