From: Mark Walters Date: Sat, 7 Jul 2012 15:12:56 +0000 (+0100) Subject: [PATCH 1/3] cli: allow keyword lists in argument parser. X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=70f38e8831a4a3d356afd44e9e12692070388382;p=notmuch-archives.git [PATCH 1/3] cli: allow keyword lists in argument parser. --- diff --git a/4f/391d0ed24e2545f1c7551c5f3126c29aaf337c b/4f/391d0ed24e2545f1c7551c5f3126c29aaf337c new file mode 100644 index 000000000..2ff556de5 --- /dev/null +++ b/4f/391d0ed24e2545f1c7551c5f3126c29aaf337c @@ -0,0 +1,157 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 9F4F4431FB6 + for ; Sat, 7 Jul 2012 08:13:12 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0.201 +X-Spam-Level: +X-Spam-Status: No, score=0.201 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001, + RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id sk0idobAiMYi for ; + Sat, 7 Jul 2012 08:13:12 -0700 (PDT) +Received: from mail-we0-f181.google.com (mail-we0-f181.google.com + [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id E815F431FAF + for ; Sat, 7 Jul 2012 08:13:11 -0700 (PDT) +Received: by weyt57 with SMTP id t57so3271720wey.26 + for ; Sat, 07 Jul 2012 08:13:10 -0700 (PDT) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; + h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; + bh=wcGuI4HoTnkGRYn5J/S1+eE1wgU18tizzkvfe5CI4ZA=; + b=K5ZjloGRVZEKLA4cPgud+aRJJYdWFW6VW7mYBzL3NTmt2g0Czqub5pyMyHTz9JDYFG + ed75NYtsznJyfhqnhfFJ+824nAcY+FMisGWEHY9DpUxKUe6ZYWNEMM7//PboJiRDDNTs + RocR6G5wW/AJcBlQ3g/r90bV4SdNNUY2yiOkBr67NpfxxmIycEhXIRs32pjQHC4hdVQ6 + KHfKVqnPKdryS+P4IdACFZok/EVOraUVt8ua8j6KWNoNFrSWgrhMeJkQ9TUkN7Zl2hR/ + sgefq7nuc17oavy+OrvOB5rpm8olqZ2rX6tYJbI6qu+ZpMRRmRLK9OYcpDs6DVmU2Cz8 + 8cbQ== +Received: by 10.216.216.95 with SMTP id f73mr5164590wep.149.1341673990702; + Sat, 07 Jul 2012 08:13:10 -0700 (PDT) +Received: from localhost (94-192-233-223.zone6.bethere.co.uk. + [94.192.233.223]) by mx.google.com with ESMTPS id + bc2sm18280270wib.0.2012.07.07.08.13.09 (version=TLSv1/SSLv3 cipher=OTHER); + Sat, 07 Jul 2012 08:13:10 -0700 (PDT) +From: Mark Walters +To: notmuch@notmuchmail.org +Subject: [PATCH 1/3] cli: allow keyword lists in argument parser. +Date: Sat, 7 Jul 2012 16:12:56 +0100 +Message-Id: <1341673978-6094-2-git-send-email-markwalters1009@gmail.com> +X-Mailer: git-send-email 1.7.9.1 +In-Reply-To: <1341673978-6094-1-git-send-email-markwalters1009@gmail.com> +References: <1341673978-6094-1-git-send-email-markwalters1009@gmail.com> +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sat, 07 Jul 2012 15:13:12 -0000 + +We allow keyword lists in the argument parser. The parser returns a +bitfield of the arguments present which is the union of the specified +bitfields for each option. Since it is the union the parser could +allow things like + +--output-headers=default,reply-to + +to get the default headers with reply-to added. +--- + command-line-arguments.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++ + command-line-arguments.h | 3 +- + 2 files changed, 49 insertions(+), 1 deletions(-) + +diff --git a/command-line-arguments.c b/command-line-arguments.c +index b0a0dab..d322f9e 100644 +--- a/command-line-arguments.c ++++ b/command-line-arguments.c +@@ -37,6 +37,50 @@ _process_keyword_arg (const notmuch_opt_desc_t *arg_desc, char next, const char + } + + static notmuch_bool_t ++_process_keyword_list (const notmuch_opt_desc_t *arg_desc, const char *arg_str) { ++ ++ char *key_str, *final; ++ unsigned int matched_keys = 0; ++ notmuch_bool_t matched; ++ const notmuch_keyword_t *keywords; ++ ++ key_str = strdup (arg_str); ++ ++ do { ++ keywords = arg_desc->keywords; ++ matched = FALSE; ++ ++ final = strrchr (key_str, ','); ++ ++ if (final) { ++ *final = '\0'; ++ final++; ++ } else { ++ final = key_str; ++ } ++ ++ while (keywords->name && !matched) { ++ if (strcmp (final, keywords->name) == 0) { ++ matched_keys |= keywords->value; ++ matched = TRUE; ++ } ++ keywords++; ++ } ++ if (!matched) { ++ fprintf (stderr, "unknown keyword: \'%s\' in list %s\n", final, arg_str); ++ goto DONE; ++ } ++ } while (final != key_str); ++ ++ if (arg_desc->output_var) { ++ *((unsigned int *)arg_desc->output_var) = matched_keys; ++ } ++DONE: ++ free (key_str); ++ return matched; ++} ++ ++static notmuch_bool_t + _process_boolean_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) { + + if (next == 0) { +@@ -121,6 +165,9 @@ parse_option (const char *arg, + case NOTMUCH_OPT_KEYWORD: + return _process_keyword_arg (try, next, value); + break; ++ case NOTMUCH_OPT_KEYWORD_LIST: ++ return _process_keyword_list (try, value); ++ break; + case NOTMUCH_OPT_BOOLEAN: + return _process_boolean_arg (try, next, value); + break; +diff --git a/command-line-arguments.h b/command-line-arguments.h +index de1734a..f2b2275 100644 +--- a/command-line-arguments.h ++++ b/command-line-arguments.h +@@ -9,7 +9,8 @@ enum notmuch_opt_type { + NOTMUCH_OPT_INT, /* --frob=8 */ + NOTMUCH_OPT_KEYWORD, /* --format=raw|json|text */ + NOTMUCH_OPT_STRING, /* --file=/tmp/gnarf.txt */ +- NOTMUCH_OPT_POSITION /* notmuch dump pos_arg */ ++ NOTMUCH_OPT_POSITION, /* notmuch dump pos_arg */ ++ NOTMUCH_OPT_KEYWORD_LIST /* --output=header,body */ + }; + + /* +-- +1.7.9.1 +