Commit a5dc11a8 authored by Pankaj Yadav's avatar Pankaj Yadav Committed by Rémi Denis-Courmont

Some platforms may have macros optind optarg and optopt so we don't...

... use them as names of our variables
Signed-off-by: default avatarRémi Denis-Courmont <remi@remlab.net>
parent f2e9e149
...@@ -200,7 +200,7 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc, ...@@ -200,7 +200,7 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc,
* Parse the command line options * Parse the command line options
*/ */
vlc_getopt_t state; 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, while( ( i_cmd = vlc_getopt_long( i_argc, (char **)ppsz_argv,
psz_shortopts, psz_shortopts,
p_longopts, &i_index, &state ) ) != -1 ) p_longopts, &i_index, &state ) ) != -1 )
...@@ -252,21 +252,21 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc, ...@@ -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_LIST_CAT:
case CONFIG_ITEM_MODULE_CAT: case CONFIG_ITEM_MODULE_CAT:
var_Create( p_this, psz_name, VLC_VAR_STRING ); 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; break;
case CONFIG_ITEM_INTEGER: case CONFIG_ITEM_INTEGER:
var_Create( p_this, psz_name, VLC_VAR_INTEGER ); var_Create( p_this, psz_name, VLC_VAR_INTEGER );
var_SetInteger( p_this, psz_name, var_SetInteger( p_this, psz_name,
strtoll(state.optarg, NULL, 0)); strtoll(state.arg, NULL, 0));
break; break;
case CONFIG_ITEM_FLOAT: case CONFIG_ITEM_FLOAT:
var_Create( p_this, psz_name, VLC_VAR_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; break;
case CONFIG_ITEM_KEY: case CONFIG_ITEM_KEY:
var_Create( p_this, psz_name, VLC_VAR_INTEGER ); var_Create( p_this, psz_name, VLC_VAR_INTEGER );
var_SetInteger( p_this, psz_name, var_SetInteger( p_this, psz_name,
ConfigStringToKey( state.optarg ) ); ConfigStringToKey( state.arg ) );
break; break;
case CONFIG_ITEM_BOOL: case CONFIG_ITEM_BOOL:
var_Create( p_this, psz_name, VLC_VAR_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, ...@@ -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:
case CONFIG_ITEM_MODULE_LIST_CAT: case CONFIG_ITEM_MODULE_LIST_CAT:
var_Create( p_this, name, VLC_VAR_STRING ); var_Create( p_this, name, VLC_VAR_STRING );
var_SetString( p_this, name, state.optarg ); var_SetString( p_this, name, state.arg );
break; break;
case CONFIG_ITEM_INTEGER: case CONFIG_ITEM_INTEGER:
var_Create( p_this, name, VLC_VAR_INTEGER ); var_Create( p_this, name, VLC_VAR_INTEGER );
...@@ -304,7 +304,7 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc, ...@@ -304,7 +304,7 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc,
else else
{ {
var_SetInteger( p_this, name, var_SetInteger( p_this, name,
strtoll(state.optarg, NULL, 0) ); strtoll(state.arg, NULL, 0) );
} }
break; break;
case CONFIG_ITEM_BOOL: case CONFIG_ITEM_BOOL:
...@@ -321,13 +321,13 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc, ...@@ -321,13 +321,13 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc,
{ {
fputs( "vlc: unknown option" fputs( "vlc: unknown option"
" or missing mandatory argument ", stderr ); " or missing mandatory argument ", stderr );
if( state.optopt ) if( state.opt )
{ {
fprintf( stderr, "`-%c'\n", state.optopt ); fprintf( stderr, "`-%c'\n", state.opt );
} }
else 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 ); fputs( "Try `vlc --help' for more information.\n", stderr );
goto out; goto out;
...@@ -336,7 +336,7 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc, ...@@ -336,7 +336,7 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc,
ret = 0; ret = 0;
if( pindex != NULL ) if( pindex != NULL )
*pindex = state.optind; *pindex = state.ind;
out: out:
/* Free allocated resources */ /* Free allocated resources */
for( i_index = 0; p_longopts[i_index].name; i_index++ ) for( i_index = 0; p_longopts[i_index].name; i_index++ )
......
...@@ -42,7 +42,7 @@ static void exchange(char **argv, vlc_getopt_t *restrict state) ...@@ -42,7 +42,7 @@ static void exchange(char **argv, vlc_getopt_t *restrict state)
{ {
int bottom = state->first_nonopt; int bottom = state->first_nonopt;
int middle = state->last_nonopt; int middle = state->last_nonopt;
int top = state->optind; int top = state->ind;
char *tem; char *tem;
/* Exchange the shorter segment with the far end of the longer segment. /* 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) ...@@ -88,8 +88,8 @@ static void exchange(char **argv, vlc_getopt_t *restrict state)
/* Update records for the slots the non-options now occupy. */ /* Update records for the slots the non-options now occupy. */
state->first_nonopt += (state->optind - state->last_nonopt); state->first_nonopt += (state->ind - state->last_nonopt);
state->last_nonopt = state->optind; state->last_nonopt = state->ind;
} }
...@@ -148,19 +148,19 @@ int vlc_getopt_long(int argc, char *const *argv, ...@@ -148,19 +148,19 @@ int vlc_getopt_long(int argc, char *const *argv,
const struct vlc_option *restrict longopts, int *longind, const struct vlc_option *restrict longopts, int *longind,
vlc_getopt_t *restrict state) 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. */ /* Initialize the internal data when the first call is made. */
/* Start processing options with ARGV-element 1 (since ARGV-element 0 /* Start processing options with ARGV-element 1 (since ARGV-element 0
is the program name); the sequence of previously skipped is the program name); the sequence of previously skipped
non-option ARGV-elements is empty. */ 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; 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') if (state->nextchar == NULL || *state->nextchar == '\0')
{ {
...@@ -168,55 +168,55 @@ int vlc_getopt_long(int argc, char *const *argv, ...@@ -168,55 +168,55 @@ int vlc_getopt_long(int argc, char *const *argv,
/* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
moved back by the user (who may also have changed the arguments). */ moved back by the user (who may also have changed the arguments). */
if (state->last_nonopt > state->optind) if (state->last_nonopt > state->ind)
state->last_nonopt = state->optind; state->last_nonopt = state->ind;
if (state->first_nonopt > state->optind) if (state->first_nonopt > state->ind)
state->first_nonopt = state->optind; state->first_nonopt = state->ind;
/* If we have just processed some options following some non-options, /* If we have just processed some options following some non-options,
exchange them so that the options come first. */ exchange them so that the options come first. */
if (state->first_nonopt != state->last_nonopt if (state->first_nonopt != state->last_nonopt
&& state->last_nonopt != state->optind) && state->last_nonopt != state->ind)
exchange((char **) argv, state); exchange((char **) argv, state);
else if (state->last_nonopt != state->optind) else if (state->last_nonopt != state->ind)
state->first_nonopt = state->optind; state->first_nonopt = state->ind;
/* Skip any additional non-options /* Skip any additional non-options
and extend the range of non-options previously skipped. */ and extend the range of non-options previously skipped. */
while (state->optind < argc && NONOPTION_P) while (state->ind < argc && NONOPTION_P)
state->optind++; state->ind++;
state->last_nonopt = state->optind; state->last_nonopt = state->ind;
/* The special ARGV-element `--' means premature end of options. /* The special ARGV-element `--' means premature end of options.
Skip it like a null option, Skip it like a null option,
then exchange with previous non-options as if it were an option, then exchange with previous non-options as if it were an option,
then skip everything else like a non-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 if (state->first_nonopt != state->last_nonopt
&& state->last_nonopt != state->optind) && state->last_nonopt != state->ind)
exchange((char **) argv, state); exchange((char **) argv, state);
else if (state->first_nonopt == state->last_nonopt) else if (state->first_nonopt == state->last_nonopt)
state->first_nonopt = state->optind; state->first_nonopt = state->ind;
state->last_nonopt = argc; state->last_nonopt = argc;
state->optind = argc; state->ind = argc;
} }
/* If we have done all the ARGV-elements, stop the scan /* If we have done all the ARGV-elements, stop the scan
and back over any non-options that we skipped and permuted. */ 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 /* Set the next-arg-index to point at the non-options
that we previously skipped, so the caller will digest them. */ that we previously skipped, so the caller will digest them. */
if (state->first_nonopt != state->last_nonopt) if (state->first_nonopt != state->last_nonopt)
state->optind = state->first_nonopt; state->ind = state->first_nonopt;
return -1; return -1;
} }
...@@ -225,22 +225,22 @@ int vlc_getopt_long(int argc, char *const *argv, ...@@ -225,22 +225,22 @@ int vlc_getopt_long(int argc, char *const *argv,
if (NONOPTION_P) if (NONOPTION_P)
{ {
state->optarg = argv[state->optind++]; state->arg = argv[state->ind++];
return 1; return 1;
} }
/* We have found another option-ARGV-element. /* We have found another option-ARGV-element.
Skip the initial punctuation. */ Skip the initial punctuation. */
state->nextchar = (argv[state->optind] + 1 state->nextchar = (argv[state->ind] + 1
+ (argv[state->optind][1] == '-')); + (argv[state->ind][1] == '-'));
} }
/* Decode the current option-ARGV-element. */ /* Decode the current option-ARGV-element. */
/* Check whether the ARGV-element is a long option. */ /* Check whether the ARGV-element is a long option. */
if (argv[state->optind][1] == '-') if (argv[state->ind][1] == '-')
{ {
char *nameend; char *nameend;
const struct vlc_option *p; const struct vlc_option *p;
...@@ -281,35 +281,35 @@ int vlc_getopt_long(int argc, char *const *argv, ...@@ -281,35 +281,35 @@ int vlc_getopt_long(int argc, char *const *argv,
if (ambig && !exact) if (ambig && !exact)
{ {
state->nextchar += strlen(state->nextchar); state->nextchar += strlen(state->nextchar);
state->optind++; state->ind++;
state->optopt = 0; state->opt = 0;
return '?'; return '?';
} }
if (pfound != NULL) if (pfound != NULL)
{ {
option_index = indfound; option_index = indfound;
state->optind++; state->ind++;
if (*nameend) if (*nameend)
{ {
if (pfound->has_arg) if (pfound->has_arg)
state->optarg = nameend + 1; state->arg = nameend + 1;
else else
{ {
state->nextchar += strlen(state->nextchar); state->nextchar += strlen(state->nextchar);
state->optopt = pfound->val; state->opt = pfound->val;
return '?'; return '?';
} }
} }
else if (pfound->has_arg) else if (pfound->has_arg)
{ {
if (state->optind < argc) if (state->ind < argc)
state->optarg = argv[state->optind++]; state->arg = argv[state->ind++];
else else
{ {
state->nextchar += strlen(state->nextchar); state->nextchar += strlen(state->nextchar);
state->optopt = pfound->val; state->opt = pfound->val;
return optstring[0] == ':' ? ':' : '?'; return optstring[0] == ':' ? ':' : '?';
} }
} }
...@@ -325,8 +325,8 @@ int vlc_getopt_long(int argc, char *const *argv, ...@@ -325,8 +325,8 @@ int vlc_getopt_long(int argc, char *const *argv,
} }
state->nextchar = (char *) ""; state->nextchar = (char *) "";
state->optind++; state->ind++;
state->optopt = 0; state->opt = 0;
return '?'; return '?';
} }
...@@ -338,11 +338,11 @@ int vlc_getopt_long(int argc, char *const *argv, ...@@ -338,11 +338,11 @@ int vlc_getopt_long(int argc, char *const *argv,
/* Increment `optind' when we start to process its last character. */ /* Increment `optind' when we start to process its last character. */
if (*state->nextchar == '\0') if (*state->nextchar == '\0')
++state->optind; ++state->ind;
if (temp == NULL || c == ':') if (temp == NULL || c == ':')
{ {
state->optopt = c; state->opt = c;
return '?'; return '?';
} }
/* Convenience. Treat POSIX -W foo same as long option --foo */ /* Convenience. Treat POSIX -W foo same as long option --foo */
...@@ -359,14 +359,14 @@ int vlc_getopt_long(int argc, char *const *argv, ...@@ -359,14 +359,14 @@ int vlc_getopt_long(int argc, char *const *argv,
/* This is an option that requires an argument. */ /* This is an option that requires an argument. */
if (*state->nextchar != '\0') 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, /* If we end this ARGV-element by taking the rest as an arg,
we must advance to the next element now. */ 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] == ':') if (optstring[0] == ':')
c = ':'; c = ':';
else else
...@@ -376,12 +376,12 @@ int vlc_getopt_long(int argc, char *const *argv, ...@@ -376,12 +376,12 @@ int vlc_getopt_long(int argc, char *const *argv,
else else
/* We already incremented `optind' once; /* We already incremented `optind' once;
increment it again when taking next ARGV-elt as argument. */ 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 /* optarg is now the argument, see if it's in the
table of longopts. */ table of longopts. */
for (state->nextchar = nameend = state->optarg; *nameend && *nameend != '='; nameend++) for (state->nextchar = nameend = state->arg; *nameend && *nameend != '='; nameend++)
/* Do nothing. */ ; /* Do nothing. */ ;
/* Test all long options for either exact match /* Test all long options for either exact match
...@@ -411,7 +411,7 @@ int vlc_getopt_long(int argc, char *const *argv, ...@@ -411,7 +411,7 @@ int vlc_getopt_long(int argc, char *const *argv,
if (ambig && !exact) if (ambig && !exact)
{ {
state->nextchar += strlen(state->nextchar); state->nextchar += strlen(state->nextchar);
state->optind++; state->ind++;
return '?'; return '?';
} }
if (pfound != NULL) if (pfound != NULL)
...@@ -420,7 +420,7 @@ int vlc_getopt_long(int argc, char *const *argv, ...@@ -420,7 +420,7 @@ int vlc_getopt_long(int argc, char *const *argv,
if (*nameend) if (*nameend)
{ {
if (pfound->has_arg) if (pfound->has_arg)
state->optarg = nameend + 1; state->arg = nameend + 1;
else else
{ {
state->nextchar += strlen(state->nextchar); state->nextchar += strlen(state->nextchar);
...@@ -429,8 +429,8 @@ int vlc_getopt_long(int argc, char *const *argv, ...@@ -429,8 +429,8 @@ int vlc_getopt_long(int argc, char *const *argv,
} }
else if (pfound->has_arg) else if (pfound->has_arg)
{ {
if (state->optind < argc) if (state->ind < argc)
state->optarg = argv[state->optind++]; state->arg = argv[state->ind++];
else else
{ {
state->nextchar += strlen(state->nextchar); state->nextchar += strlen(state->nextchar);
...@@ -455,14 +455,14 @@ int vlc_getopt_long(int argc, char *const *argv, ...@@ -455,14 +455,14 @@ int vlc_getopt_long(int argc, char *const *argv,
/* This is an option that requires an argument. */ /* This is an option that requires an argument. */
if (*state->nextchar != '\0') 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, /* If we end this ARGV-element by taking the rest as an arg,
we must advance to the next element now. */ 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] == ':') if (optstring[0] == ':')
c = ':'; c = ':';
else else
...@@ -471,7 +471,7 @@ int vlc_getopt_long(int argc, char *const *argv, ...@@ -471,7 +471,7 @@ int vlc_getopt_long(int argc, char *const *argv,
else else
/* We already incremented `optind' once; /* We already incremented `optind' once;
increment it again when taking next ARGV-elt as argument. */ increment it again when taking next ARGV-elt as argument. */
state->optarg = argv[state->optind++]; state->arg = argv[state->ind++];
state->nextchar = NULL; state->nextchar = NULL;
} }
return c; return c;
......
...@@ -28,7 +28,7 @@ typedef struct vlc_getopt_s ...@@ -28,7 +28,7 @@ typedef struct vlc_getopt_s
When `getopt' finds an option that takes an argument, When `getopt' finds an option that takes an argument,
the argument value is returned here. */ the argument value is returned here. */
char *optarg; char *arg;
/* Index in ARGV of the next element to be scanned. /* Index in ARGV of the next element to be scanned.
This is used for communication to and from the caller This is used for communication to and from the caller
...@@ -42,11 +42,11 @@ typedef struct vlc_getopt_s ...@@ -42,11 +42,11 @@ typedef struct vlc_getopt_s
Otherwise, `optind' communicates from one call to the next Otherwise, `optind' communicates from one call to the next
how much of ARGV has been scanned so far. */ how much of ARGV has been scanned so far. */
int optind; int ind;
/* Set to an option character which was unrecognized. */ /* Set to an option character which was unrecognized. */
int optopt; int opt;
/* The next char to be scanned in the option-element /* The next char to be scanned in the option-element
in which the last option character we returned was found. in which the last option character we returned was found.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment