1
0
Fork 0

Merging upstream version 1.1~rc2.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-17 19:14:54 +01:00
parent a8d17e4a46
commit 950a431716
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
22 changed files with 1309 additions and 1071 deletions

View file

@ -93,16 +93,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 )
@ -112,7 +112,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, "'" );
@ -121,7 +121,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 )
{
@ -159,14 +159,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 )
@ -179,7 +180,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] )
{
@ -207,9 +208,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;
@ -223,13 +224,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;