1
0
Fork 0

Merging upstream version 1.1.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-23 19:12:39 +01:00
parent 992afe8498
commit 0c0a7befad
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
16 changed files with 414 additions and 235 deletions

View file

@ -77,16 +77,16 @@ static char parse_long_option( struct Arg_parser * const ap,
for( len = 0; opt[len+2] && opt[len+2] != '='; ++len ) ;
// Test all long options for either exact match or abbreviated matches.
/* Test all long options for either exact match or abbreviated matches. */
for( i = 0; options[i].code != 0; ++i )
if( options[i].name && !strncmp( options[i].name, &opt[2], len ) )
{
if( strlen( options[i].name ) == len ) // Exact match found
if( strlen( options[i].name ) == len ) /* Exact match found */
{ index = i; exact = 1; break; }
else if( index < 0 ) index = i; // First nonexact match found
else if( index < 0 ) index = i; /* First nonexact match found */
else if( options[index].code != options[i].code ||
options[index].has_arg != options[i].has_arg )
ambig = 1; // Second or later nonexact match found
ambig = 1; /* Second or later nonexact match found */
}
if( ambig && !exact )
@ -96,7 +96,7 @@ static char parse_long_option( struct Arg_parser * const ap,
return 1;
}
if( index < 0 ) // nothing found
if( index < 0 ) /* nothing found */
{
add_error( ap, "unrecognized option `" ); add_error( ap, opt );
add_error( ap, "'" );
@ -105,7 +105,7 @@ static char parse_long_option( struct Arg_parser * const ap,
++*argindp;
if( opt[len+2] ) // `--<long_option>=<argument>' syntax
if( opt[len+2] ) /* `--<long_option>=<argument>' syntax */
{
if( options[index].has_arg == ap_no )
{
@ -143,14 +143,15 @@ static char parse_short_option( struct Arg_parser * const ap,
const struct ap_Option options[],
int * const argindp )
{
int cind = 1; // character index in opt
int cind = 1; /* character index in opt */
while( cind > 0 )
{
int index = -1;
int i;
const unsigned char code = opt[cind];
const char code_str[2] = { code, 0 };
char code_str[2];
code_str[0] = code; code_str[1] = 0;
if( code != 0 )
for( i = 0; options[i].code; ++i )
@ -163,7 +164,7 @@ static char parse_short_option( struct Arg_parser * const ap,
return 1;
}
if( opt[++cind] == 0 ) { ++*argindp; cind = 0; } // opt finished
if( opt[++cind] == 0 ) { ++*argindp; cind = 0; } /* opt finished */
if( options[index].has_arg != ap_no && cind > 0 && opt[cind] )
{
@ -191,9 +192,9 @@ char ap_init( struct Arg_parser * const ap,
const int argc, const char * const argv[],
const struct ap_Option options[], const char in_order )
{
const char ** non_options = 0; // skipped non-options
int non_options_size = 0; // number of skipped non-options
int argind = 1; // index in argv
const char ** non_options = 0; /* skipped non-options */
int non_options_size = 0; /* number of skipped non-options */
int argind = 1; /* index in argv */
int i;
ap->data = 0;
@ -207,13 +208,13 @@ char ap_init( struct Arg_parser * const ap,
const unsigned char ch1 = argv[argind][0];
const unsigned char ch2 = ( ch1 ? argv[argind][1] : 0 );
if( ch1 == '-' && ch2 ) // we found an option
if( ch1 == '-' && ch2 ) /* we found an option */
{
const char * const opt = argv[argind];
const char * const arg = (argind + 1 < argc) ? argv[argind+1] : 0;
if( ch2 == '-' )
{
if( !argv[argind][2] ) { ++argind; break; } // we found "--"
if( !argv[argind][2] ) { ++argind; break; } /* we found "--" */
else if( !parse_long_option( ap, opt, arg, options, &argind ) ) return 0;
}
else if( !parse_short_option( ap, opt, arg, options, &argind ) ) return 0;