[PATCH v4 1/5] command-line-arguments.[ch]: new argument parsing framework for notmuch.
[notmuch-archives.git] / 69 / 868da69f83bcd9bf7bd0cc71248e4eb85e74fd
1 Return-Path: <amthrax@drake.mit.edu>\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 8CD18429E2F\r
6         for <notmuch@notmuchmail.org>; Sun, 16 Jan 2011 00:11:37 -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\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id GjxYcuRLpr0m for <notmuch@notmuchmail.org>;\r
16         Sun, 16 Jan 2011 00:11:35 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-1.mit.edu (DMZ-MAILSEC-SCANNER-1.MIT.EDU\r
18         [18.9.25.12])\r
19         by olra.theworths.org (Postfix) with ESMTP id 5C77B42D299\r
20         for <notmuch@notmuchmail.org>; Sun, 16 Jan 2011 00:11:24 -0800 (PST)\r
21 X-AuditID: 1209190c-b7ba9ae0000009f8-bc-4d32a82c0e73\r
22 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
23         by dmz-mailsec-scanner-1.mit.edu (Symantec Brightmail Gateway) with\r
24         SMTP id AB.ED.02552.C28A23D4; Sun, 16 Jan 2011 03:11:24 -0500 (EST)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id p0G8BNhu004721; \r
27         Sun, 16 Jan 2011 03:11:23 -0500\r
28 Received: from drake.mit.edu (a074.catapulsion.net [70.36.81.74])\r
29         (authenticated bits=0)\r
30         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
31         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id p0G8BMTW010524\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Sun, 16 Jan 2011 03:11:23 -0500 (EST)\r
34 Received: from amthrax by drake.mit.edu with local (Exim 4.72)\r
35         (envelope-from <amthrax@drake.mit.edu>)\r
36         id 1PeNhp-0002Xa-Tq; Sun, 16 Jan 2011 03:11:21 -0500\r
37 From: Austin Clements <amdragon@MIT.EDU>\r
38 To: notmuch@notmuchmail.org\r
39 Subject: [PATCH 5/8] Support "tag:*" as well as "NOT tag:*" queries.\r
40 Date: Sun, 16 Jan 2011 03:10:55 -0500\r
41 Message-Id: <1295165458-9573-6-git-send-email-amdragon@mit.edu>\r
42 X-Mailer: git-send-email 1.7.2.3\r
43 In-Reply-To: <1295165458-9573-1-git-send-email-amdragon@mit.edu>\r
44 References: <1295165458-9573-1-git-send-email-amdragon@mit.edu>\r
45 X-Brightmail-Tracker: AAAAAA==\r
46 Cc: amdragon@mit.edu\r
47 X-BeenThere: notmuch@notmuchmail.org\r
48 X-Mailman-Version: 2.1.13\r
49 Precedence: list\r
50 List-Id: "Use and development of the notmuch mail system."\r
51         <notmuch.notmuchmail.org>\r
52 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
53         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
54 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
55 List-Post: <mailto:notmuch@notmuchmail.org>\r
56 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
57 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
58         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
59 X-List-Received-Date: Sun, 16 Jan 2011 08:11:37 -0000\r
60 \r
61 This extends the syntactic-to-database prefix query transform to\r
62 optionally expand wildcards for boolean prefixes.  Support of "NOT\r
63 tag:*" queries to find all untagged messages falls out as a convenient\r
64 side-effect.\r
65 ---\r
66  TODO                  |    2 --\r
67  lib/database.cc       |    4 ++--\r
68  lib/notmuch-private.h |   10 ++++++----\r
69  lib/qparser.cc        |   12 +++++++++++-\r
70  4 files changed, 19 insertions(+), 9 deletions(-)\r
71 \r
72 diff --git a/TODO b/TODO\r
73 index 10c8c12..15606d1 100644\r
74 --- a/TODO\r
75 +++ b/TODO\r
76 @@ -220,8 +220,6 @@ Fix the "count" functionality to be exact as Olly explained in IRC:\r
77  \r
78  Search syntax\r
79  -------------\r
80 -Implement support for "tag:*" to expand to all tags.\r
81 -\r
82  Fix "notmuch search to:" to be less confusing. Many users expect this\r
83  to search for all messages with a To: header, but it instead searches\r
84  for all messages with the word "to". If we don't provide the first\r
85 diff --git a/lib/database.cc b/lib/database.cc\r
86 index a3df0ae..3af82b0 100644\r
87 --- a/lib/database.cc\r
88 +++ b/lib/database.cc\r
89 @@ -679,13 +679,13 @@ notmuch_database_open (const char *path,\r
90         for (i = 0; i < ARRAY_SIZE (BOOLEAN_PREFIX_EXTERNAL); i++) {\r
91             prefix_t *prefix = &BOOLEAN_PREFIX_EXTERNAL[i];\r
92             _notmuch_qparser_add_db_prefix (notmuch->query_parser, prefix->name,\r
93 -                                           prefix->prefix, TRUE);\r
94 +                                           prefix->prefix, TRUE, TRUE);\r
95         }\r
96  \r
97         for (i = 0; i < ARRAY_SIZE (PROBABILISTIC_PREFIX); i++) {\r
98             prefix_t *prefix = &PROBABILISTIC_PREFIX[i];\r
99             _notmuch_qparser_add_db_prefix (notmuch->query_parser, prefix->name,\r
100 -                                           prefix->prefix, FALSE);\r
101 +                                           prefix->prefix, FALSE, FALSE);\r
102         }\r
103  \r
104         _notmuch_qparser_add_transform (notmuch->query_parser,\r
105 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
106 index eb346ea..5fc54de 100644\r
107 --- a/lib/notmuch-private.h\r
108 +++ b/lib/notmuch-private.h\r
109 @@ -631,13 +631,15 @@ _notmuch_qparser_add_transform (_notmuch_qparser_t *qparser,\r
110                                 void *opaque);\r
111  \r
112  /* Add a syntactic prefix (field) and a transform pass to transform\r
113 - * that syntactic prefix into a database prefix (prefix).  This\r
114 - * corresponds to Xapian's add_prefix and add_boolean_prefix\r
115 - * functions. */\r
116 + * that syntactic prefix into a database prefix (prefix).  For boolean\r
117 + * prefixes, wildcard indicates whether the term should allow wildcard\r
118 + * expansion.  This corresponds to Xapian's add_prefix and\r
119 + * add_boolean_prefix functions. */\r
120  void\r
121  _notmuch_qparser_add_db_prefix (_notmuch_qparser_t *qparser,\r
122                                 const char *field, const char *prefix,\r
123 -                               notmuch_bool_t boolean);\r
124 +                               notmuch_bool_t boolean,\r
125 +                               notmuch_bool_t wildcard);\r
126  \r
127  /* Lex a query string, returning the first token in the token list.\r
128   * This is only meant for testing. */\r
129 diff --git a/lib/qparser.cc b/lib/qparser.cc\r
130 index bd0296a..0ff240c 100644\r
131 --- a/lib/qparser.cc\r
132 +++ b/lib/qparser.cc\r
133 @@ -974,6 +974,7 @@ _notmuch_qparser_add_transform (_notmuch_qparser_t *qparser,\r
134  \r
135  struct _notmuch_transform_prefix_info {\r
136      char *field, *prefix;\r
137 +    notmuch_bool_t wildcard;\r
138  };\r
139  \r
140  static _notmuch_token_t *\r
141 @@ -986,6 +987,13 @@ transform_prefix_rec (struct _notmuch_transform_prefix_info *info,\r
142         active = (strcmp (info->field, root->text) == 0);\r
143      } else if (active && (root->type == TOK_TERMS || root->type == TOK_LIT)) {\r
144         root->prefix = info->prefix;\r
145 +       if (info->wildcard) {\r
146 +           int n = strlen (root->text);\r
147 +           if (n && root->text[n - 1] == '*') {\r
148 +               root->text = talloc_strndup (root, root->text, n - 1);\r
149 +               root->wildcard = TRUE;\r
150 +           }\r
151 +       }\r
152      }\r
153      transform_prefix_rec (info, root->left, active);\r
154      transform_prefix_rec (info, root->right, active);\r
155 @@ -1003,12 +1011,14 @@ transform_prefix (_notmuch_token_t *root, void *opaque)\r
156  void\r
157  _notmuch_qparser_add_db_prefix (_notmuch_qparser_t *qparser,\r
158                                 const char *field, const char *prefix,\r
159 -                               notmuch_bool_t boolean)\r
160 +                               notmuch_bool_t boolean,\r
161 +                               notmuch_bool_t wildcard)\r
162  {\r
163      struct _notmuch_transform_prefix_info *info;\r
164      info = talloc (qparser, struct _notmuch_transform_prefix_info);\r
165      info->field = talloc_strdup (info, field);\r
166      info->prefix = talloc_strdup (info, prefix);\r
167 +    info->wildcard = boolean && wildcard;\r
168      _notmuch_qparser_add_prefix (qparser, field, boolean, boolean);\r
169      _notmuch_qparser_add_transform (qparser, transform_prefix, info);\r
170  }\r
171 -- \r
172 1.7.2.3\r
173 \r