diff options
author | Daniel Baumann <mail@daniel-baumann.ch> | 2015-11-06 11:29:58 +0000 |
---|---|---|
committer | Daniel Baumann <mail@daniel-baumann.ch> | 2015-11-06 11:29:58 +0000 |
commit | 72be44917bc19be536d1413c0f122cf5f2414263 (patch) | |
tree | de59e3cdd43e922654d43b2bbcb60e7e5936ed2c /carg_parser.c | |
parent | Adding debian version 1.0-1. (diff) | |
download | clzip-72be44917bc19be536d1413c0f122cf5f2414263.tar.xz clzip-72be44917bc19be536d1413c0f122cf5f2414263.zip |
Merging upstream version 1.1~rc2.
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'carg_parser.c')
-rw-r--r-- | carg_parser.c | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/carg_parser.c b/carg_parser.c index fe3228c..ff14a87 100644 --- a/carg_parser.c +++ b/carg_parser.c @@ -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; |