X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=command-line-arguments.c;h=c591dcbec7cc3e7f92b4043828b2a950f1215737;hb=4dc3291199055c076b89267c8bf2bdb366c6e635;hp=f1a5b2324337fb2ceb78f6fcde64133f8f12454c;hpb=4a6721970a42a9f86149fb5d395d1001fed2d305;p=notmuch diff --git a/command-line-arguments.c b/command-line-arguments.c index f1a5b232..c591dcbe 100644 --- a/command-line-arguments.c +++ b/command-line-arguments.c @@ -13,14 +13,14 @@ static notmuch_bool_t _process_keyword_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) { - const notmuch_keyword_t *keywords = arg_desc->keywords; + const notmuch_keyword_t *keywords; if (next == '\0') { /* No keyword given */ arg_str = ""; } - while (keywords->name) { + for (keywords = arg_desc->keywords; keywords->name; keywords++) { if (strcmp (arg_str, keywords->name) == 0) { if (arg_desc->opt_flags) *arg_desc->opt_flags |= keywords->value; @@ -28,7 +28,6 @@ _process_keyword_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_desc->opt_keyword = keywords->value; return TRUE; } - keywords++; } if (next != '\0') fprintf (stderr, "Unknown keyword argument \"%s\" for option \"%s\".\n", arg_str, arg_desc->name); @@ -39,21 +38,20 @@ _process_keyword_arg (const notmuch_opt_desc_t *arg_desc, char next, const char static notmuch_bool_t _process_boolean_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) { - - if (next == '\0') { - *arg_desc->opt_bool = TRUE; - return TRUE; - } - if (strcmp (arg_str, "false") == 0) { - *arg_desc->opt_bool = FALSE; - return TRUE; - } - if (strcmp (arg_str, "true") == 0) { - *arg_desc->opt_bool = TRUE; - return TRUE; + notmuch_bool_t value; + + if (next == '\0' || strcmp (arg_str, "true") == 0) { + value = TRUE; + } else if (strcmp (arg_str, "false") == 0) { + value = FALSE; + } else { + fprintf (stderr, "Unknown argument \"%s\" for (boolean) option \"%s\".\n", arg_str, arg_desc->name); + return FALSE; } - fprintf (stderr, "Unknown argument \"%s\" for (boolean) option \"%s\".\n", arg_str, arg_desc->name); - return FALSE; + + *arg_desc->opt_bool = value; + + return TRUE; } static notmuch_bool_t @@ -128,6 +126,8 @@ parse_position_arg (const char *arg_str, int pos_arg_index, if (arg_desc->opt_position) { if (pos_arg_counter == pos_arg_index) { *arg_desc->opt_position = arg_str; + if (arg_desc->present) + *arg_desc->present = TRUE; return TRUE; } pos_arg_counter++; @@ -202,10 +202,13 @@ parse_option (int argc, char **argv, const notmuch_opt_desc_t *options, int opt_ else INTERNAL_ERROR ("unknown or unhandled option \"%s\"", try->name); - if (opt_status) - return opt_index+1; - else + if (! opt_status) return -1; + + if (try->present) + *try->present = TRUE; + + return opt_index+1; } return -1; }