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 81B08429E25
\r
6 for <notmuch@notmuchmail.org>; Thu, 8 Mar 2012 14:16:12 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\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 Cd8ez-OCKQWr for <notmuch@notmuchmail.org>;
\r
18 Thu, 8 Mar 2012 14:16:12 -0800 (PST)
\r
19 Received: from mail-ww0-f45.google.com (mail-ww0-f45.google.com
\r
20 [74.125.82.45]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client
\r
21 certificate requested) by olra.theworths.org (Postfix) with ESMTPS id
\r
22 CEEC8431FAE for <notmuch@notmuchmail.org>; Thu, 8 Mar 2012 14:16:11 -0800
\r
24 Received: by mail-ww0-f45.google.com with SMTP id ds10so878463wgb.2
\r
25 for <notmuch@notmuchmail.org>; Thu, 08 Mar 2012 14:16:11 -0800 (PST)
\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=UvY+VtrS18qmXIzo8Z6w8CC6EqsYraJnjzcaJkKkMoI=;
\r
29 b=Yu/b4aTB/6TkxVXo4OTvVTZvY/tDDEhwsDQi9o9Y7sz4zeorXTSS45QVOY/Vur2wXy
\r
30 sKsT4hmeKLIftlvGKwARFkGDGQlfadU36rJ79owAOvA2PCF9ivO/COcV9FiseGiw7hX4
\r
31 8mT20dg5S45UigL/u9njgtdiLygKabfho9/OqkUDrMr8I9pO6hmjcygcyhBTetx8z8GY
\r
32 p0Ue2CIRwly52jh/eGnd3mYqMacPznNI1TsPiOMGWIMATpeKvgE7J0tcNdpDn476wVRY
\r
33 hpND6JSSfagQskTQQfFoOExEvA4jmPImm8WoVOcghPpawEv5gk3+MQiGdB6Pgbq9xOO1
\r
35 Received: by 10.216.132.98 with SMTP id n76mr4124246wei.101.1331244971342;
\r
36 Thu, 08 Mar 2012 14:16:11 -0800 (PST)
\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 fl2sm14898801wib.4.2012.03.08.14.16.10 (version=TLSv1/SSLv3 cipher=OTHER);
\r
40 Thu, 08 Mar 2012 14:16:10 -0800 (PST)
\r
41 From: Mark Walters <markwalters1009@gmail.com>
\r
42 To: notmuch@notmuchmail.org
\r
43 Subject: [PATCH 1/2] cli: Parsing. Add option NOTMUCH_OPT_INT_OR_BOOLEAN
\r
44 Date: Thu, 8 Mar 2012 22:15:43 +0000
\r
45 Message-Id: <1331244944-7960-2-git-send-email-markwalters1009@gmail.com>
\r
46 X-Mailer: git-send-email 1.7.9.1
\r
47 In-Reply-To: <1331244944-7960-1-git-send-email-markwalters1009@gmail.com>
\r
48 References: <1331244944-7960-1-git-send-email-markwalters1009@gmail.com>
\r
49 X-BeenThere: notmuch@notmuchmail.org
\r
50 X-Mailman-Version: 2.1.13
\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: Thu, 08 Mar 2012 22:16:12 -0000
\r
63 Allow the option NOTMUCH_OPT_INT_OR_BOOLEAN for command line parsing
\r
64 which accepts --verbose=3 and --verbose with the latter setting
\r
65 verbose to 1. It also allows --verbose=0 so (with a little caller
\r
66 support) user can turn off boolean options.
\r
68 This means that extra options can be added to the command line
\r
69 programs in a backwards compatible manner.
\r
71 command-line-arguments.c | 29 +++++++++++++++++++++++++++--
\r
72 command-line-arguments.h | 3 +++
\r
73 2 files changed, 30 insertions(+), 2 deletions(-)
\r
75 diff --git a/command-line-arguments.c b/command-line-arguments.c
\r
76 index e711414..99e13c6 100644
\r
77 --- a/command-line-arguments.c
\r
78 +++ b/command-line-arguments.c
\r
80 #include "error_util.h"
\r
81 #include "command-line-arguments.h"
\r
83 +/* A helper for parsing an int to a boolean */
\r
85 +notmuch_int_to_boolean (int i)
\r
93 + INTERNAL_ERROR ("Non-boolean value %d", i);
\r
100 Search the array of keywords for a given argument, assigning the
\r
101 output variable to the corresponding value. Return FALSE if nothing
\r
102 @@ -72,6 +88,7 @@ parse_option (const char *arg,
\r
103 if (try->name && strncmp (arg, try->name, strlen (try->name)) == 0) {
\r
104 char next = arg[strlen (try->name)];
\r
105 const char *value= arg+strlen(try->name)+1;
\r
106 + enum notmuch_opt_type opt_type = try->opt_type;
\r
110 @@ -79,7 +96,14 @@ parse_option (const char *arg,
\r
111 * delimiter, and a non-zero length value
\r
114 - if (try->opt_type != NOTMUCH_OPT_BOOLEAN) {
\r
115 + if (opt_type == NOTMUCH_OPT_INT_OR_BOOLEAN) {
\r
117 + opt_type = NOTMUCH_OPT_INT;
\r
119 + opt_type = NOTMUCH_OPT_BOOLEAN;
\r
122 + if (opt_type != NOTMUCH_OPT_BOOLEAN) {
\r
123 if (next != '=' && next != ':') return FALSE;
\r
124 if (value[0] == 0) return FALSE;
\r
126 @@ -89,7 +113,7 @@ parse_option (const char *arg,
\r
127 if (try->output_var == NULL)
\r
128 INTERNAL_ERROR ("output pointer NULL for option %s", try->name);
\r
130 - switch (try->opt_type) {
\r
131 + switch (opt_type) {
\r
132 case NOTMUCH_OPT_KEYWORD:
\r
133 return _process_keyword_arg (try, value);
\r
135 @@ -107,6 +131,7 @@ parse_option (const char *arg,
\r
137 case NOTMUCH_OPT_POSITION:
\r
138 case NOTMUCH_OPT_END:
\r
139 + case NOTMUCH_OPT_INT_OR_BOOLEAN: /* should be dealt with above */
\r
141 INTERNAL_ERROR ("unknown or unhandled option type %d", try->opt_type);
\r
143 diff --git a/command-line-arguments.h b/command-line-arguments.h
\r
144 index de1734a..a2fc545 100644
\r
145 --- a/command-line-arguments.h
\r
146 +++ b/command-line-arguments.h
\r
148 enum notmuch_opt_type {
\r
149 NOTMUCH_OPT_END = 0,
\r
150 NOTMUCH_OPT_BOOLEAN, /* --verbose */
\r
151 + NOTMUCH_OPT_INT_OR_BOOLEAN, /* --verbose or --verbose=1 */
\r
152 NOTMUCH_OPT_INT, /* --frob=8 */
\r
153 NOTMUCH_OPT_KEYWORD, /* --format=raw|json|text */
\r
154 NOTMUCH_OPT_STRING, /* --file=/tmp/gnarf.txt */
\r
155 @@ -76,5 +77,7 @@ parse_position_arg (const char *arg,
\r
156 int position_arg_index,
\r
157 const notmuch_opt_desc_t* options);
\r
160 +notmuch_int_to_boolean (int i);
\r