Re: Possible addtions to notmuch new ?
[notmuch-archives.git] / 4f / 391d0ed24e2545f1c7551c5f3126c29aaf337c
1 Return-Path: <markwalters1009@gmail.com>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 9F4F4431FB6\r
6         for <notmuch@notmuchmail.org>; Sat,  7 Jul 2012 08:13:12 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0.201\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13         FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
14         RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
15 Received: from olra.theworths.org ([127.0.0.1])\r
16         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
17         with ESMTP id sk0idobAiMYi for <notmuch@notmuchmail.org>;\r
18         Sat,  7 Jul 2012 08:13:12 -0700 (PDT)\r
19 Received: from mail-we0-f181.google.com (mail-we0-f181.google.com\r
20         [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
21         (No client certificate requested)\r
22         by olra.theworths.org (Postfix) with ESMTPS id E815F431FAF\r
23         for <notmuch@notmuchmail.org>; Sat,  7 Jul 2012 08:13:11 -0700 (PDT)\r
24 Received: by weyt57 with SMTP id t57so3271720wey.26\r
25         for <notmuch@notmuchmail.org>; Sat, 07 Jul 2012 08:13:10 -0700 (PDT)\r
26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
27         h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
28         bh=wcGuI4HoTnkGRYn5J/S1+eE1wgU18tizzkvfe5CI4ZA=;\r
29         b=K5ZjloGRVZEKLA4cPgud+aRJJYdWFW6VW7mYBzL3NTmt2g0Czqub5pyMyHTz9JDYFG\r
30         ed75NYtsznJyfhqnhfFJ+824nAcY+FMisGWEHY9DpUxKUe6ZYWNEMM7//PboJiRDDNTs\r
31         RocR6G5wW/AJcBlQ3g/r90bV4SdNNUY2yiOkBr67NpfxxmIycEhXIRs32pjQHC4hdVQ6\r
32         KHfKVqnPKdryS+P4IdACFZok/EVOraUVt8ua8j6KWNoNFrSWgrhMeJkQ9TUkN7Zl2hR/\r
33         sgefq7nuc17oavy+OrvOB5rpm8olqZ2rX6tYJbI6qu+ZpMRRmRLK9OYcpDs6DVmU2Cz8\r
34         8cbQ==\r
35 Received: by 10.216.216.95 with SMTP id f73mr5164590wep.149.1341673990702;\r
36         Sat, 07 Jul 2012 08:13:10 -0700 (PDT)\r
37 Received: from localhost (94-192-233-223.zone6.bethere.co.uk.\r
38  [94.192.233.223])      by mx.google.com with ESMTPS id\r
39  bc2sm18280270wib.0.2012.07.07.08.13.09 (version=TLSv1/SSLv3 cipher=OTHER);\r
40         Sat, 07 Jul 2012 08:13:10 -0700 (PDT)\r
41 From: Mark Walters <markwalters1009@gmail.com>\r
42 To: notmuch@notmuchmail.org\r
43 Subject: [PATCH 1/3] cli: allow keyword lists in argument parser.\r
44 Date: Sat,  7 Jul 2012 16:12:56 +0100\r
45 Message-Id: <1341673978-6094-2-git-send-email-markwalters1009@gmail.com>\r
46 X-Mailer: git-send-email 1.7.9.1\r
47 In-Reply-To: <1341673978-6094-1-git-send-email-markwalters1009@gmail.com>\r
48 References: <1341673978-6094-1-git-send-email-markwalters1009@gmail.com>\r
49 X-BeenThere: notmuch@notmuchmail.org\r
50 X-Mailman-Version: 2.1.13\r
51 Precedence: list\r
52 List-Id: "Use and development of the notmuch mail system."\r
53         <notmuch.notmuchmail.org>\r
54 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
55         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
56 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
57 List-Post: <mailto:notmuch@notmuchmail.org>\r
58 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
59 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
60         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
61 X-List-Received-Date: Sat, 07 Jul 2012 15:13:12 -0000\r
62 \r
63 We allow keyword lists in the argument parser. The parser returns a\r
64 bitfield of the arguments present which is the union of the specified\r
65 bitfields for each option. Since it is the union the parser could\r
66 allow things like\r
67 \r
68 --output-headers=default,reply-to\r
69 \r
70 to get the default headers with reply-to added.\r
71 ---\r
72  command-line-arguments.c |   47 ++++++++++++++++++++++++++++++++++++++++++++++\r
73  command-line-arguments.h |    3 +-\r
74  2 files changed, 49 insertions(+), 1 deletions(-)\r
75 \r
76 diff --git a/command-line-arguments.c b/command-line-arguments.c\r
77 index b0a0dab..d322f9e 100644\r
78 --- a/command-line-arguments.c\r
79 +++ b/command-line-arguments.c\r
80 @@ -37,6 +37,50 @@ _process_keyword_arg (const notmuch_opt_desc_t *arg_desc, char next, const char\r
81  }\r
82  \r
83  static notmuch_bool_t\r
84 +_process_keyword_list (const notmuch_opt_desc_t *arg_desc, const char *arg_str) {\r
85 +\r
86 +    char *key_str, *final;\r
87 +    unsigned int matched_keys = 0;\r
88 +    notmuch_bool_t matched;\r
89 +    const notmuch_keyword_t *keywords;\r
90 +\r
91 +    key_str = strdup (arg_str);\r
92 +\r
93 +    do {\r
94 +       keywords = arg_desc->keywords;\r
95 +       matched = FALSE;\r
96 +\r
97 +       final = strrchr (key_str, ',');\r
98 +\r
99 +       if (final) {\r
100 +           *final = '\0';\r
101 +           final++;\r
102 +       } else {\r
103 +           final = key_str;\r
104 +       }\r
105 +\r
106 +       while (keywords->name && !matched) {\r
107 +           if (strcmp (final, keywords->name) == 0) {\r
108 +               matched_keys |= keywords->value;\r
109 +               matched = TRUE;\r
110 +           }\r
111 +           keywords++;\r
112 +       }\r
113 +       if (!matched) {\r
114 +           fprintf (stderr, "unknown keyword: \'%s\' in list %s\n", final, arg_str);\r
115 +           goto DONE;\r
116 +       }\r
117 +    } while (final != key_str);\r
118 +\r
119 +    if (arg_desc->output_var) {\r
120 +       *((unsigned int *)arg_desc->output_var) = matched_keys;\r
121 +    }\r
122 +DONE:\r
123 +    free (key_str);\r
124 +    return matched;\r
125 +}\r
126 +\r
127 +static notmuch_bool_t\r
128  _process_boolean_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) {\r
129  \r
130      if (next == 0) {\r
131 @@ -121,6 +165,9 @@ parse_option (const char *arg,\r
132             case NOTMUCH_OPT_KEYWORD:\r
133                 return _process_keyword_arg (try, next, value);\r
134                 break;\r
135 +           case NOTMUCH_OPT_KEYWORD_LIST:\r
136 +               return _process_keyword_list (try, value);\r
137 +               break;\r
138             case NOTMUCH_OPT_BOOLEAN:\r
139                 return _process_boolean_arg (try, next, value);\r
140                 break;\r
141 diff --git a/command-line-arguments.h b/command-line-arguments.h\r
142 index de1734a..f2b2275 100644\r
143 --- a/command-line-arguments.h\r
144 +++ b/command-line-arguments.h\r
145 @@ -9,7 +9,8 @@ enum notmuch_opt_type {\r
146      NOTMUCH_OPT_INT,           /* --frob=8               */\r
147      NOTMUCH_OPT_KEYWORD,       /* --format=raw|json|text */\r
148      NOTMUCH_OPT_STRING,                /* --file=/tmp/gnarf.txt  */\r
149 -    NOTMUCH_OPT_POSITION       /* notmuch dump pos_arg   */\r
150 +    NOTMUCH_OPT_POSITION,      /* notmuch dump pos_arg   */\r
151 +    NOTMUCH_OPT_KEYWORD_LIST   /* --output=header,body   */\r
152  };\r
153  \r
154  /*\r
155 -- \r
156 1.7.9.1\r
157 \r