... use them as names of our variables
Signed-off-by: Rémi Denis-Courmont <remi@remlab.net>
* Parse the command line options
*/
vlc_getopt_t state;
* 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 )
while( ( i_cmd = vlc_getopt_long( i_argc, (char **)ppsz_argv,
psz_shortopts,
p_longopts, &i_index, &state ) ) != -1 )
case CONFIG_ITEM_MODULE_LIST_CAT:
case CONFIG_ITEM_MODULE_CAT:
var_Create( p_this, psz_name, VLC_VAR_STRING );
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,
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 );
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,
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 );
break;
case CONFIG_ITEM_BOOL:
var_Create( p_this, psz_name, VLC_VAR_BOOL );
case CONFIG_ITEM_MODULE_LIST:
case CONFIG_ITEM_MODULE_LIST_CAT:
var_Create( p_this, name, VLC_VAR_STRING );
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 );
break;
case CONFIG_ITEM_INTEGER:
var_Create( p_this, name, VLC_VAR_INTEGER );
else
{
var_SetInteger( p_this, name,
else
{
var_SetInteger( p_this, name,
- strtoll(state.optarg, NULL, 0) );
+ strtoll(state.arg, NULL, 0) );
}
break;
case CONFIG_ITEM_BOOL:
}
break;
case CONFIG_ITEM_BOOL:
{
fputs( "vlc: unknown option"
" or missing mandatory argument ", stderr );
{
fputs( "vlc: unknown option"
" or missing mandatory argument ", stderr );
- fprintf( stderr, "`-%c'\n", state.optopt );
+ fprintf( stderr, "`-%c'\n", state.opt );
- 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;
}
fputs( "Try `vlc --help' for more information.\n", stderr );
goto out;
ret = 0;
if( pindex != NULL )
ret = 0;
if( pindex != NULL )
- *pindex = state.optind;
out:
/* Free allocated resources */
for( i_index = 0; p_longopts[i_index].name; i_index++ )
out:
/* Free allocated resources */
for( i_index = 0; p_longopts[i_index].name; i_index++ )
{
int bottom = state->first_nonopt;
int middle = state->last_nonopt;
{
int bottom = state->first_nonopt;
int middle = state->last_nonopt;
- int top = state->optind;
char *tem;
/* Exchange the shorter segment with the far end of the longer segment.
char *tem;
/* Exchange the shorter segment with the far end of the longer segment.
/* 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->last_nonopt = state->optind;
+ state->first_nonopt += (state->ind - state->last_nonopt);
+ state->last_nonopt = state->ind;
const struct vlc_option *restrict longopts, int *longind,
vlc_getopt_t *restrict state)
{
const struct vlc_option *restrict longopts, int *longind,
vlc_getopt_t *restrict state)
{
- if (state->optind == 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. */
{
/* 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;
}
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')
{
/* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
moved back by the user (who may also have changed the arguments). */
/* 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
/* 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);
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. */
/* 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. */
/* 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], "--"))
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);
else if (state->first_nonopt == state->last_nonopt)
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->last_nonopt = argc;
}
/* If we have done all the ARGV-elements, stop the scan
and back over any non-options that we skipped and permuted. */
}
/* 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)
{
/* 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;
- state->optarg = argv[state->optind++];
+ state->arg = argv[state->ind++];
return 1;
}
/* We have found another option-ARGV-element.
Skip the initial punctuation. */
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. */
}
/* 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;
{
char *nameend;
const struct vlc_option *p;
if (ambig && !exact)
{
state->nextchar += strlen(state->nextchar);
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;
return '?';
}
if (pfound != NULL)
{
option_index = indfound;
if (*nameend)
{
if (pfound->has_arg)
if (*nameend)
{
if (pfound->has_arg)
- state->optarg = nameend + 1;
+ state->arg = nameend + 1;
else
{
state->nextchar += strlen(state->nextchar);
else
{
state->nextchar += strlen(state->nextchar);
- state->optopt = pfound->val;
+ state->opt = pfound->val;
return '?';
}
}
else if (pfound->has_arg)
{
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);
else
{
state->nextchar += strlen(state->nextchar);
- state->optopt = pfound->val;
+ state->opt = pfound->val;
return optstring[0] == ':' ? ':' : '?';
}
}
return optstring[0] == ':' ? ':' : '?';
}
}
}
state->nextchar = (char *) "";
}
state->nextchar = (char *) "";
- state->optind++;
- state->optopt = 0;
+ state->ind++;
+ state->opt = 0;
/* Increment `optind' when we start to process its last character. */
if (*state->nextchar == '\0')
/* Increment `optind' when we start to process its last character. */
if (*state->nextchar == '\0')
if (temp == NULL || c == ':')
{
if (temp == NULL || c == ':')
{
return '?';
}
/* Convenience. Treat POSIX -W foo same as long option --foo */
return '?';
}
/* Convenience. Treat POSIX -W foo same as long option --foo */
/* This is an option that requires an argument. */
if (*state->nextchar != '\0')
{
/* 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. */
/* If we end this ARGV-element by taking the rest as an arg,
we must advance to the next element now. */
- else if (state->optind == argc)
+ else if (state->ind == argc)
if (optstring[0] == ':')
c = ':';
else
if (optstring[0] == ':')
c = ':';
else
else
/* We already incremented `optind' once;
increment it again when taking next ARGV-elt as argument. */
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. */
/* 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
/* Do nothing. */ ;
/* Test all long options for either exact match
if (ambig && !exact)
{
state->nextchar += strlen(state->nextchar);
if (ambig && !exact)
{
state->nextchar += strlen(state->nextchar);
return '?';
}
if (pfound != NULL)
return '?';
}
if (pfound != NULL)
if (*nameend)
{
if (pfound->has_arg)
if (*nameend)
{
if (pfound->has_arg)
- state->optarg = nameend + 1;
+ state->arg = nameend + 1;
else
{
state->nextchar += strlen(state->nextchar);
else
{
state->nextchar += strlen(state->nextchar);
}
else if (pfound->has_arg)
{
}
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);
else
{
state->nextchar += strlen(state->nextchar);
/* This is an option that requires an argument. */
if (*state->nextchar != '\0')
{
/* 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. */
/* If we end this ARGV-element by taking the rest as an arg,
we must advance to the next element now. */
- else if (state->optind == argc)
+ else if (state->ind == argc)
if (optstring[0] == ':')
c = ':';
else
if (optstring[0] == ':')
c = ':';
else
else
/* We already incremented `optind' once;
increment it again when taking next ARGV-elt as argument. */
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;
state->nextchar = NULL;
}
return c;
When `getopt' finds an option that takes an argument,
the argument value is returned here. */
When `getopt' finds an option that takes an argument,
the argument value is returned here. */
/* Index in ARGV of the next element to be scanned.
This is used for communication to and from the caller
/* Index in ARGV of the next element to be scanned.
This is used for communication to and from the caller
Otherwise, `optind' communicates from one call to the next
how much of ARGV has been scanned so far. */
Otherwise, `optind' communicates from one call to the next
how much of ARGV has been scanned so far. */
/* Set to an option character which was unrecognized. */
/* Set to an option character which was unrecognized. */
/* The next char to be scanned in the option-element
in which the last option character we returned was found.
/* The next char to be scanned in the option-element
in which the last option character we returned was found.