[PATCH] bitmap:improve memory usage using CHAR_BITS and unsigned CHAR
[notmuch-archives.git] / 56 / 99318aa15dc556f3405449c7837ebaef43ffc1
1 Return-Path: <amdragon@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 7E023431FC0\r
6         for <notmuch@notmuchmail.org>; Fri, 28 Dec 2012 10:26:49 -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.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 H2azlYEVBf24 for <notmuch@notmuchmail.org>;\r
16         Fri, 28 Dec 2012 10:26:48 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-7.mit.edu (DMZ-MAILSEC-SCANNER-7.MIT.EDU\r
18         [18.7.68.36])\r
19         by olra.theworths.org (Postfix) with ESMTP id 9A148431FB6\r
20         for <notmuch@notmuchmail.org>; Fri, 28 Dec 2012 10:26:48 -0800 (PST)\r
21 X-AuditID: 12074424-b7f4e6d0000004ca-30-50dde4677ac2\r
22 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
23         by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 5F.44.01226.764EDD05; Fri, 28 Dec 2012 13:26:47 -0500 (EST)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id qBSIQk1U001811; \r
27         Fri, 28 Dec 2012 13:26:46 -0500\r
28 Received: from drake.dyndns.org (c-76-21-105-205.hsd1.ca.comcast.net\r
29         [76.21.105.205]) (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 qBSIQf4O012712\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Fri, 28 Dec 2012 13:26:43 -0500 (EST)\r
34 Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
35         (envelope-from <amdragon@mit.edu>)\r
36         id 1Toedj-0000sS-Rn; Fri, 28 Dec 2012 13:26:39 -0500\r
37 From: Austin Clements <amdragon@MIT.EDU>\r
38 To: notmuch@notmuchmail.org\r
39 Subject: [PATCH v3 2/5] util: Function to parse boolean term queries\r
40 Date: Fri, 28 Dec 2012 13:26:26 -0500\r
41 Message-Id: <1356719189-2837-3-git-send-email-amdragon@mit.edu>\r
42 X-Mailer: git-send-email 1.7.10.4\r
43 In-Reply-To: <1356719189-2837-1-git-send-email-amdragon@mit.edu>\r
44 References: <1356719189-2837-1-git-send-email-amdragon@mit.edu>\r
45 X-Brightmail-Tracker:\r
46  H4sIAAAAAAAAA+NgFjrPIsWRmVeSWpSXmKPExsUixCmqrZv+5G6AwYtPhhY3WrsZLZqmO1us\r
47         nstjcf3mTGYHFo+ds+6ye9y6/5rd49mqW8weWw69Zw5gieKySUnNySxLLdK3S+DKmPTgC1vB\r
48         V9GKzreXGBsYrwl0MXJySAiYSDy+eZkJwhaTuHBvPVsXIxeHkMA+RonGaXOZIJwNjBKd57tY\r
49         IJyLTBL31j5kB2kREpjLKHFouhOIzSagIbFt/3JGEFtEQFpi593ZrCA2s0CexMNHW8HqhQVc\r
50         JP7M/AFWwyKgKvF8wUkWEJtXwF5i7rUvbBBnKEp0P5sAZnMKOEi8mnKODWKXvcSpGctZJzDy\r
51         L2BkWMUom5JbpZubmJlTnJqsW5ycmJeXWqRrrpebWaKXmlK6iREUbuwuKjsYmw8pHWIU4GBU\r
52         4uE9cftugBBrYllxZe4hRkkOJiVR3uUPgEJ8SfkplRmJxRnxRaU5qcWHGCU4mJVEePuagXK8\r
53         KYmVValF+TApaQ4WJXHe6yk3/YUE0hNLUrNTUwtSi2CyMhwcShK87o+BGgWLUtNTK9Iyc0oQ\r
54         0kwcnCDDeYCGR4DU8BYXJOYWZ6ZD5E8xKkqJ80aCJARAEhmleXC9sHTwilEc6BVhXjWQKh5g\r
55         KoHrfgU0mAlosDXPHZDBJYkIKakGRrUMryVHLRI3uRfVtfLNvK27I4TdXKFyg/a74MBpl38G\r
56         lO0vSln2hf+F68/8TS8LagLipCrPH17SytwstN7z47dfr45k2TJs3bHAlufW58itIt9TV33a\r
57         liTIu8dnSYRiboHPv+CmjTlTZhiqHGh7y6P43eSBut8lFS3JVMlpfdcKeX3PX0+vVGIpzkg0\r
58         1GIuKk4EAJN2+KfiAgAA\r
59 X-BeenThere: notmuch@notmuchmail.org\r
60 X-Mailman-Version: 2.1.13\r
61 Precedence: list\r
62 List-Id: "Use and development of the notmuch mail system."\r
63         <notmuch.notmuchmail.org>\r
64 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
65         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
66 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
67 List-Post: <mailto:notmuch@notmuchmail.org>\r
68 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
69 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
70         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
71 X-List-Received-Date: Fri, 28 Dec 2012 18:26:49 -0000\r
72 \r
73 This parses the subset of Xapian's boolean term quoting rules that are\r
74 used by make_boolean_term.  This is provided as a generic string\r
75 utility, but will be used shortly in notmuch restore to parse and\r
76 optimize for ID queries.\r
77 ---\r
78  util/string-util.c |   55 ++++++++++++++++++++++++++++++++++++++++++++++++++++\r
79  util/string-util.h |   11 +++++++++++\r
80  2 files changed, 66 insertions(+)\r
81 \r
82 diff --git a/util/string-util.c b/util/string-util.c\r
83 index e4bea21..83b4953 100644\r
84 --- a/util/string-util.c\r
85 +++ b/util/string-util.c\r
86 @@ -96,3 +96,58 @@ make_boolean_term (void *ctx, const char *prefix, const char *term,\r
87  \r
88      return 0;\r
89  }\r
90 +\r
91 +int\r
92 +parse_boolean_term (void *ctx, const char *str,\r
93 +                   char **prefix_out, char **term_out)\r
94 +{\r
95 +    *prefix_out = *term_out = NULL;\r
96 +\r
97 +    /* Parse prefix */\r
98 +    const char *pos = strchr (str, ':');\r
99 +    if (! pos)\r
100 +       goto FAIL;\r
101 +    *prefix_out = talloc_strndup (ctx, str, pos - str);\r
102 +    ++pos;\r
103 +\r
104 +    /* Implement de-quoting compatible with make_boolean_term. */\r
105 +    if (*pos == '"') {\r
106 +       char *out = talloc_array (ctx, char, strlen (pos));\r
107 +       int closed = 0;\r
108 +       *term_out = out;\r
109 +       /* Skip the opening quote, find the closing quote, and\r
110 +        * un-double doubled internal quotes. */\r
111 +       for (++pos; *pos; ) {\r
112 +           if (*pos == '"') {\r
113 +               ++pos;\r
114 +               if (*pos != '"') {\r
115 +                   /* Found the closing quote. */\r
116 +                   closed = 1;\r
117 +                   break;\r
118 +               }\r
119 +           }\r
120 +           *out++ = *pos++;\r
121 +       }\r
122 +       /* Did the term terminate without a closing quote or is there\r
123 +        * trailing text after the closing quote? */\r
124 +       if (!closed || *pos)\r
125 +           goto FAIL;\r
126 +       *out = '\0';\r
127 +    } else {\r
128 +       const char *start = pos;\r
129 +       /* Check for text after the boolean term. */\r
130 +       while (*pos > ' ' && *pos != ')')\r
131 +           ++pos;\r
132 +       if (*pos)\r
133 +           goto FAIL;\r
134 +       /* No trailing text; dup the string so the caller can free\r
135 +        * it. */\r
136 +       *term_out = talloc_strdup (ctx, start);\r
137 +    }\r
138 +    return 0;\r
139 +\r
140 + FAIL:\r
141 +    talloc_free (*prefix_out);\r
142 +    talloc_free (*term_out);\r
143 +    return 1;\r
144 +}\r
145 diff --git a/util/string-util.h b/util/string-util.h\r
146 index b8844a3..43d49d0 100644\r
147 --- a/util/string-util.h\r
148 +++ b/util/string-util.h\r
149 @@ -33,4 +33,15 @@ char *strtok_len (char *s, const char *delim, size_t *len);\r
150  int make_boolean_term (void *talloc_ctx, const char *prefix, const char *term,\r
151                        char **buf, size_t *len);\r
152  \r
153 +/* Parse a boolean term query produced by make_boolean_term, returning\r
154 + * the prefix in *prefix_out and the term in *term_out.  *prefix_out\r
155 + * and *term_out will be talloc'd with context ctx.\r
156 + *\r
157 + * Return: 0 on success, non-zero on parse error (including trailing\r
158 + * data in str).\r
159 + */\r
160 +int\r
161 +parse_boolean_term (void *ctx, const char *str,\r
162 +                   char **prefix_out, char **term_out);\r
163 +\r
164  #endif\r
165 -- \r
166 1.7.10.4\r
167 \r