From a5dc11a80916461de6e279143db532d7782cfea2 Mon Sep 17 00:00:00 2001 From: Pankaj Yadav Date: Sun, 18 Jul 2010 09:32:37 +0530 Subject: [PATCH] Some platforms may have macros optind optarg and optopt so we don't... MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit ... use them as names of our variables Signed-off-by: Rémi Denis-Courmont --- src/config/cmdline.c | 22 ++++---- src/config/getopt.c | 110 ++++++++++++++++++++-------------------- src/config/vlc_getopt.h | 6 +-- 3 files changed, 69 insertions(+), 69 deletions(-) diff --git a/src/config/cmdline.c b/src/config/cmdline.c index d01c133734..015ffcdb5a 100644 --- a/src/config/cmdline.c +++ b/src/config/cmdline.c @@ -200,7 +200,7 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc, * Parse the command line options */ vlc_getopt_t state; - state.optind = 0 ; /* set to 0 to tell GNU getopt to reinitialize */ + state.ind = 0 ; /* set to 0 to tell GNU getopt to reinitialize */ while( ( i_cmd = vlc_getopt_long( i_argc, (char **)ppsz_argv, psz_shortopts, p_longopts, &i_index, &state ) ) != -1 ) @@ -252,21 +252,21 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc, case CONFIG_ITEM_MODULE_LIST_CAT: case CONFIG_ITEM_MODULE_CAT: var_Create( p_this, psz_name, VLC_VAR_STRING ); - var_SetString( p_this, psz_name, state.optarg ); + var_SetString( p_this, psz_name, state.arg ); break; case CONFIG_ITEM_INTEGER: var_Create( p_this, psz_name, VLC_VAR_INTEGER ); var_SetInteger( p_this, psz_name, - strtoll(state.optarg, NULL, 0)); + strtoll(state.arg, NULL, 0)); break; case CONFIG_ITEM_FLOAT: var_Create( p_this, psz_name, VLC_VAR_FLOAT ); - var_SetFloat( p_this, psz_name, us_atof(state.optarg) ); + var_SetFloat( p_this, psz_name, us_atof(state.arg) ); break; case CONFIG_ITEM_KEY: var_Create( p_this, psz_name, VLC_VAR_INTEGER ); var_SetInteger( p_this, psz_name, - ConfigStringToKey( state.optarg ) ); + ConfigStringToKey( state.arg ) ); break; case CONFIG_ITEM_BOOL: var_Create( p_this, psz_name, VLC_VAR_BOOL ); @@ -292,7 +292,7 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc, case CONFIG_ITEM_MODULE_LIST: case CONFIG_ITEM_MODULE_LIST_CAT: var_Create( p_this, name, VLC_VAR_STRING ); - var_SetString( p_this, name, state.optarg ); + var_SetString( p_this, name, state.arg ); break; case CONFIG_ITEM_INTEGER: var_Create( p_this, name, VLC_VAR_INTEGER ); @@ -304,7 +304,7 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc, else { var_SetInteger( p_this, name, - strtoll(state.optarg, NULL, 0) ); + strtoll(state.arg, NULL, 0) ); } break; case CONFIG_ITEM_BOOL: @@ -321,13 +321,13 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc, { fputs( "vlc: unknown option" " or missing mandatory argument ", stderr ); - if( state.optopt ) + if( state.opt ) { - fprintf( stderr, "`-%c'\n", state.optopt ); + fprintf( stderr, "`-%c'\n", state.opt ); } else { - fprintf( stderr, "`%s'\n", ppsz_argv[state.optind-1] ); + fprintf( stderr, "`%s'\n", ppsz_argv[state.ind-1] ); } fputs( "Try `vlc --help' for more information.\n", stderr ); goto out; @@ -336,7 +336,7 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc, ret = 0; if( pindex != NULL ) - *pindex = state.optind; + *pindex = state.ind; out: /* Free allocated resources */ for( i_index = 0; p_longopts[i_index].name; i_index++ ) diff --git a/src/config/getopt.c b/src/config/getopt.c index 75eb5c95c3..9b1b1aa0fd 100644 --- a/src/config/getopt.c +++ b/src/config/getopt.c @@ -42,7 +42,7 @@ static void exchange(char **argv, vlc_getopt_t *restrict state) { int bottom = state->first_nonopt; int middle = state->last_nonopt; - int top = state->optind; + int top = state->ind; char *tem; /* Exchange the shorter segment with the far end of the longer segment. @@ -88,8 +88,8 @@ static void exchange(char **argv, vlc_getopt_t *restrict state) /* Update records for the slots the non-options now occupy. */ - state->first_nonopt += (state->optind - state->last_nonopt); - state->last_nonopt = state->optind; + state->first_nonopt += (state->ind - state->last_nonopt); + state->last_nonopt = state->ind; } @@ -148,19 +148,19 @@ int vlc_getopt_long(int argc, char *const *argv, const struct vlc_option *restrict longopts, int *longind, vlc_getopt_t *restrict state) { - state->optarg = NULL; + state->arg = NULL; - if (state->optind == 0) + if (state->ind == 0) { /* Initialize the internal data when the first call is made. */ /* Start processing options with ARGV-element 1 (since ARGV-element 0 is the program name); the sequence of previously skipped non-option ARGV-elements is empty. */ - state->first_nonopt = state->last_nonopt = state->optind = 1; + state->first_nonopt = state->last_nonopt = state->ind = 1; state->nextchar = NULL; } -#define NONOPTION_P (argv[state->optind][0] != '-' || argv[state->optind][1] == '\0') +#define NONOPTION_P (argv[state->ind][0] != '-' || argv[state->ind][1] == '\0') if (state->nextchar == NULL || *state->nextchar == '\0') { @@ -168,55 +168,55 @@ int vlc_getopt_long(int argc, char *const *argv, /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been moved back by the user (who may also have changed the arguments). */ - if (state->last_nonopt > state->optind) - state->last_nonopt = state->optind; - if (state->first_nonopt > state->optind) - state->first_nonopt = state->optind; + if (state->last_nonopt > state->ind) + state->last_nonopt = state->ind; + if (state->first_nonopt > state->ind) + state->first_nonopt = state->ind; /* If we have just processed some options following some non-options, exchange them so that the options come first. */ if (state->first_nonopt != state->last_nonopt - && state->last_nonopt != state->optind) + && state->last_nonopt != state->ind) exchange((char **) argv, state); - else if (state->last_nonopt != state->optind) - state->first_nonopt = state->optind; + else if (state->last_nonopt != state->ind) + state->first_nonopt = state->ind; /* Skip any additional non-options and extend the range of non-options previously skipped. */ - while (state->optind < argc && NONOPTION_P) - state->optind++; - state->last_nonopt = state->optind; + while (state->ind < argc && NONOPTION_P) + state->ind++; + state->last_nonopt = state->ind; /* The special ARGV-element `--' means premature end of options. Skip it like a null option, then exchange with previous non-options as if it were an option, then skip everything else like a non-option. */ - if (state->optind != argc && !strcmp(argv[state->optind], "--")) + if (state->ind != argc && !strcmp(argv[state->ind], "--")) { - state->optind++; + state->ind++; if (state->first_nonopt != state->last_nonopt - && state->last_nonopt != state->optind) + && state->last_nonopt != state->ind) exchange((char **) argv, state); else if (state->first_nonopt == state->last_nonopt) - state->first_nonopt = state->optind; + state->first_nonopt = state->ind; state->last_nonopt = argc; - state->optind = argc; + state->ind = argc; } /* If we have done all the ARGV-elements, stop the scan and back over any non-options that we skipped and permuted. */ - if (state->optind == argc) + if (state->ind == argc) { /* Set the next-arg-index to point at the non-options that we previously skipped, so the caller will digest them. */ if (state->first_nonopt != state->last_nonopt) - state->optind = state->first_nonopt; + state->ind = state->first_nonopt; return -1; } @@ -225,22 +225,22 @@ int vlc_getopt_long(int argc, char *const *argv, if (NONOPTION_P) { - state->optarg = argv[state->optind++]; + state->arg = argv[state->ind++]; return 1; } /* We have found another option-ARGV-element. Skip the initial punctuation. */ - state->nextchar = (argv[state->optind] + 1 - + (argv[state->optind][1] == '-')); + state->nextchar = (argv[state->ind] + 1 + + (argv[state->ind][1] == '-')); } /* Decode the current option-ARGV-element. */ /* Check whether the ARGV-element is a long option. */ - if (argv[state->optind][1] == '-') + if (argv[state->ind][1] == '-') { char *nameend; const struct vlc_option *p; @@ -281,35 +281,35 @@ int vlc_getopt_long(int argc, char *const *argv, if (ambig && !exact) { state->nextchar += strlen(state->nextchar); - state->optind++; - state->optopt = 0; + state->ind++; + state->opt = 0; return '?'; } if (pfound != NULL) { option_index = indfound; - state->optind++; + state->ind++; if (*nameend) { if (pfound->has_arg) - state->optarg = nameend + 1; + state->arg = nameend + 1; else { state->nextchar += strlen(state->nextchar); - state->optopt = pfound->val; + state->opt = pfound->val; return '?'; } } else if (pfound->has_arg) { - if (state->optind < argc) - state->optarg = argv[state->optind++]; + if (state->ind < argc) + state->arg = argv[state->ind++]; else { state->nextchar += strlen(state->nextchar); - state->optopt = pfound->val; + state->opt = pfound->val; return optstring[0] == ':' ? ':' : '?'; } } @@ -325,8 +325,8 @@ int vlc_getopt_long(int argc, char *const *argv, } state->nextchar = (char *) ""; - state->optind++; - state->optopt = 0; + state->ind++; + state->opt = 0; return '?'; } @@ -338,11 +338,11 @@ int vlc_getopt_long(int argc, char *const *argv, /* Increment `optind' when we start to process its last character. */ if (*state->nextchar == '\0') - ++state->optind; + ++state->ind; if (temp == NULL || c == ':') { - state->optopt = c; + state->opt = c; return '?'; } /* Convenience. Treat POSIX -W foo same as long option --foo */ @@ -359,14 +359,14 @@ int vlc_getopt_long(int argc, char *const *argv, /* This is an option that requires an argument. */ if (*state->nextchar != '\0') { - state->optarg = state->nextchar; + state->arg = state->nextchar; /* If we end this ARGV-element by taking the rest as an arg, we must advance to the next element now. */ - state->optind++; + state->ind++; } - else if (state->optind == argc) + else if (state->ind == argc) { - state->optopt = c; + state->opt = c; if (optstring[0] == ':') c = ':'; else @@ -376,12 +376,12 @@ int vlc_getopt_long(int argc, char *const *argv, else /* We already incremented `optind' once; increment it again when taking next ARGV-elt as argument. */ - state->optarg = argv[state->optind++]; + state->arg = argv[state->ind++]; /* optarg is now the argument, see if it's in the table of longopts. */ - for (state->nextchar = nameend = state->optarg; *nameend && *nameend != '='; nameend++) + for (state->nextchar = nameend = state->arg; *nameend && *nameend != '='; nameend++) /* Do nothing. */ ; /* Test all long options for either exact match @@ -411,7 +411,7 @@ int vlc_getopt_long(int argc, char *const *argv, if (ambig && !exact) { state->nextchar += strlen(state->nextchar); - state->optind++; + state->ind++; return '?'; } if (pfound != NULL) @@ -420,7 +420,7 @@ int vlc_getopt_long(int argc, char *const *argv, if (*nameend) { if (pfound->has_arg) - state->optarg = nameend + 1; + state->arg = nameend + 1; else { state->nextchar += strlen(state->nextchar); @@ -429,8 +429,8 @@ int vlc_getopt_long(int argc, char *const *argv, } else if (pfound->has_arg) { - if (state->optind < argc) - state->optarg = argv[state->optind++]; + if (state->ind < argc) + state->arg = argv[state->ind++]; else { state->nextchar += strlen(state->nextchar); @@ -455,14 +455,14 @@ int vlc_getopt_long(int argc, char *const *argv, /* This is an option that requires an argument. */ if (*state->nextchar != '\0') { - state->optarg = state->nextchar; + state->arg = state->nextchar; /* If we end this ARGV-element by taking the rest as an arg, we must advance to the next element now. */ - state->optind++; + state->ind++; } - else if (state->optind == argc) + else if (state->ind == argc) { - state->optopt = c; + state->opt = c; if (optstring[0] == ':') c = ':'; else @@ -471,7 +471,7 @@ int vlc_getopt_long(int argc, char *const *argv, else /* We already incremented `optind' once; increment it again when taking next ARGV-elt as argument. */ - state->optarg = argv[state->optind++]; + state->arg = argv[state->ind++]; state->nextchar = NULL; } return c; diff --git a/src/config/vlc_getopt.h b/src/config/vlc_getopt.h index 2a798767a9..751f762319 100644 --- a/src/config/vlc_getopt.h +++ b/src/config/vlc_getopt.h @@ -28,7 +28,7 @@ typedef struct vlc_getopt_s When `getopt' finds an option that takes an argument, the argument value is returned here. */ - char *optarg; + char *arg; /* Index in ARGV of the next element to be scanned. This is used for communication to and from the caller @@ -42,11 +42,11 @@ typedef struct vlc_getopt_s Otherwise, `optind' communicates from one call to the next how much of ARGV has been scanned so far. */ - int optind; + int ind; /* Set to an option character which was unrecognized. */ - int optopt; + int opt; /* The next char to be scanned in the option-element in which the last option character we returned was found. -- 2.39.2