X-Git-Url: http://git.efficios.com/?p=argpar.git;a=blobdiff_plain;f=argpar%2Fargpar.c;h=58cbc2b9d917203be676d58e7259bb8518cf0529;hp=5a8a302de8d063dc7ef6426f2be1eb4dfca39793;hb=dd757a651292048da829dd6fa085c1f107569bcc;hpb=2af370d0a1dd610f66232e2bacc75e4b40ffca0d diff --git a/argpar/argpar.c b/argpar/argpar.c index 5a8a302..58cbc2b 100644 --- a/argpar/argpar.c +++ b/argpar/argpar.c @@ -418,11 +418,7 @@ enum parse_orig_arg_opt_ret parse_short_opts(const char * const short_opts, const struct argpar_opt_descr *descr; struct argpar_item_opt *opt_item; - if (strlen(short_opts) == 0) { - try_append_string_printf(error, "Invalid argument"); - ret = PARSE_ORIG_ARG_OPT_RET_ERROR_INVALID_ARG; - goto error; - } + ARGPAR_ASSERT(strlen(short_opts) != 0); if (!iter->short_opt_ch) { iter->short_opt_ch = short_opts; @@ -517,11 +513,7 @@ enum parse_orig_arg_opt_ret parse_long_opt(const char * const long_opt_arg, /* Option name */ const char *long_opt_name = long_opt_arg; - if (strlen(long_opt_arg) == 0) { - try_append_string_printf(error, "Invalid argument"); - ret = PARSE_ORIG_ARG_OPT_RET_ERROR_INVALID_ARG; - goto error; - } + ARGPAR_ASSERT(strlen(long_opt_arg) != 0); /* Find the first `=` in original argument */ eq_pos = strchr(long_opt_arg, '='); @@ -703,9 +695,10 @@ enum argpar_iter_next_status argpar_iter_next( next_orig_arg = iter->i < (iter->argc - 1) ? iter->argv[iter->i + 1] : NULL; - if (orig_arg[0] != '-') { + if (strcmp(orig_arg, "-") == 0 || strcmp(orig_arg, "--") == 0 || + orig_arg[0] != '-') { /* Non-option argument */ - struct argpar_item_non_opt * const non_opt_item = + const struct argpar_item_non_opt * const non_opt_item = create_non_opt_item(orig_arg, iter->i, iter->non_opt_index); @@ -766,7 +759,7 @@ end: } ARGPAR_HIDDEN -unsigned int argpar_iter_get_ingested_orig_args( +unsigned int argpar_iter_ingested_orig_args( const struct argpar_iter * const iter) { return iter->i; @@ -809,7 +802,7 @@ struct argpar_parse_ret argpar_parse(const unsigned int argc, case ARGPAR_ITER_NEXT_STATUS_ERROR_UNKNOWN_OPT: if (fail_on_unknown_opt) { parse_ret.ingested_orig_args = - argpar_iter_get_ingested_orig_args(iter); + argpar_iter_ingested_orig_args(iter); goto error; } @@ -832,7 +825,7 @@ struct argpar_parse_ret argpar_parse(const unsigned int argc, success: ARGPAR_ASSERT(!parse_ret.error); - parse_ret.ingested_orig_args = argpar_iter_get_ingested_orig_args(iter); + parse_ret.ingested_orig_args = argpar_iter_ingested_orig_args(iter); goto end; error: