Re: [PATCH 9/9] add has: query prefix to search for specific properties
[notmuch-archives.git] / af / b8edbef842b9aab5a4f4739d04b12d0920c8fc
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 89B12431FBC\r
6         for <notmuch@notmuchmail.org>; Sat, 10 Mar 2012 03:05:43 -0800 (PST)\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 kK3QfH+kCvEL for <notmuch@notmuchmail.org>;\r
18         Sat, 10 Mar 2012 03:05:43 -0800 (PST)\r
19 Received: from mail-wi0-f179.google.com (mail-wi0-f179.google.com\r
20         [209.85.212.179]) (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 E3AC7431FAE\r
23         for <notmuch@notmuchmail.org>; Sat, 10 Mar 2012 03:05:42 -0800 (PST)\r
24 Received: by wibhn6 with SMTP id hn6so1267357wib.2\r
25         for <notmuch@notmuchmail.org>; Sat, 10 Mar 2012 03:05:41 -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=abGHG+cDQHnRjuF49w/IsNTgJrmXXA/0Vjxm5mnfdW0=;\r
29         b=IIfrRK0Nq5+8MWTNiudgQcDjbSfztgj/MTRq9hy1T09AQedXEFaTugISIJmvDr4nMP\r
30         HSiWpkfi+MSCkLOu9Cq+4gkBoaKagVNMhWNmONYEuwZyPSll8pLYIynSkPThoeh9HIuC\r
31         itMqOBrT+XVikrBDRv2ww499MnfWXKrsdlUNk/AO7BSibZVUHE3qXx3rsC0zfe/RT2xw\r
32         tUcgpB+bk0BbQRmUOjYVQ5tBaNEXI7//1wP3KQVey+J5FoMTtkL81sCY0DS2e31VNoW7\r
33         r8b4dMvjwHi+J08kLvrFn0pxzoq2RFrJdLIq0i4S8joslRSah5yVyLjeY/qTvCtWmGwK\r
34         HPcQ==\r
35 Received: by 10.216.139.129 with SMTP id c1mr3347361wej.48.1331377541532;\r
36         Sat, 10 Mar 2012 03:05:41 -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  be4sm24537464wib.8.2012.03.10.03.05.40 (version=TLSv1/SSLv3 cipher=OTHER);\r
40         Sat, 10 Mar 2012 03:05:40 -0800 (PST)\r
41 From: Mark Walters <markwalters1009@gmail.com>\r
42 To: notmuch@notmuchmail.org\r
43 Subject: [PATCH 1/2] cli: Parsing. Allow true/false parameter for boolean\r
44         options.\r
45 Date: Sat, 10 Mar 2012 11:05:32 +0000\r
46 Message-Id: <1331377533-30262-2-git-send-email-markwalters1009@gmail.com>\r
47 X-Mailer: git-send-email 1.7.9.1\r
48 In-Reply-To: <1331377533-30262-1-git-send-email-markwalters1009@gmail.com>\r
49 References: <1331377533-30262-1-git-send-email-markwalters1009@gmail.com>\r
50 X-BeenThere: notmuch@notmuchmail.org\r
51 X-Mailman-Version: 2.1.13\r
52 Precedence: list\r
53 List-Id: "Use and development of the notmuch mail system."\r
54         <notmuch.notmuchmail.org>\r
55 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
56         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
57 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
58 List-Post: <mailto:notmuch@notmuchmail.org>\r
59 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
60 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
61         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
62 X-List-Received-Date: Sat, 10 Mar 2012 11:05:43 -0000\r
63 \r
64 Allow NOTMUCH_OPT_BOOLEAN to take a true or false parameter.  In\r
65 particular it allows the user to turn off a boolean option with\r
66 --option=false.\r
67 ---\r
68  command-line-arguments.c |   34 ++++++++++++++++++++++++++--------\r
69  1 files changed, 26 insertions(+), 8 deletions(-)\r
70 \r
71 diff --git a/command-line-arguments.c b/command-line-arguments.c\r
72 index e711414..76b185f 100644\r
73 --- a/command-line-arguments.c\r
74 +++ b/command-line-arguments.c\r
75 @@ -28,6 +28,24 @@ _process_keyword_arg (const notmuch_opt_desc_t *arg_desc, const char *arg_str) {\r
76      return FALSE;\r
77  }\r
78  \r
79 +static notmuch_bool_t\r
80 +_process_boolean_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) {\r
81 +\r
82 +    if (next == 0) {\r
83 +       *((notmuch_bool_t *)arg_desc->output_var) = TRUE;\r
84 +       return TRUE;\r
85 +    }\r
86 +    if (strcmp (arg_str, "false") == 0) {\r
87 +       *((notmuch_bool_t *)arg_desc->output_var) = FALSE;\r
88 +       return TRUE;\r
89 +    }\r
90 +    if (strcmp (arg_str, "true") == 0) {\r
91 +       *((notmuch_bool_t *)arg_desc->output_var) = TRUE;\r
92 +       return TRUE;\r
93 +    }\r
94 +    return FALSE;\r
95 +}\r
96 +\r
97  /*\r
98     Search for the {pos_arg_index}th position argument, return FALSE if\r
99     that does not exist.\r
100 @@ -76,14 +94,15 @@ parse_option (const char *arg,\r
101             char *endptr;\r
102  \r
103             /* Everything but boolean arguments (switches) needs a\r
104 -            * delimiter, and a non-zero length value\r
105 +            * delimiter, and a non-zero length value. Boolean\r
106 +            * arguments may take an optional =true or =false value.\r
107              */\r
108 -\r
109 -           if (try->opt_type != NOTMUCH_OPT_BOOLEAN) {\r
110 -               if (next != '=' && next != ':') return FALSE;\r
111 -               if (value[0] == 0) return FALSE;\r
112 +           if (next != '=' && next != ':' && next != 0) return FALSE;\r
113 +           if (next == 0) {\r
114 +               if (try->opt_type != NOTMUCH_OPT_BOOLEAN)\r
115 +                   return FALSE;\r
116             } else {\r
117 -               if (next != 0) return FALSE;\r
118 +               if (value[0] == 0) return FALSE;\r
119             }\r
120  \r
121             if (try->output_var == NULL)\r
122 @@ -94,8 +113,7 @@ parse_option (const char *arg,\r
123                 return _process_keyword_arg (try, value);\r
124                 break;\r
125             case NOTMUCH_OPT_BOOLEAN:\r
126 -               *((notmuch_bool_t *)try->output_var) = TRUE;\r
127 -               return TRUE;\r
128 +               return _process_boolean_arg (try, next, value);\r
129                 break;\r
130             case NOTMUCH_OPT_INT:\r
131                 *((int *)try->output_var) = strtol (value, &endptr, 10);\r
132 -- \r
133 1.7.9.1\r
134 \r