From 6e28aeaf5536d0286476c71e5f7c7e20cbc17036 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 7 Nov 2015 15:25:10 +0100 Subject: Merging upstream version 1.1. Signed-off-by: Daniel Baumann --- carg_parser.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'carg_parser.c') diff --git a/carg_parser.c b/carg_parser.c index 793907b..f797b75 100644 --- a/carg_parser.c +++ b/carg_parser.c @@ -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] ) // `--=' syntax + if( opt[len+2] ) /* `--=' 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; -- cgit v1.2.3