Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / f3 / 0a3edc117500ca1c3b7efda55a08da7f7f3b1c
1 Return-Path: <tomi.ollila@iki.fi>\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 D2178431FB6\r
6         for <notmuch@notmuchmail.org>; Sat, 29 Dec 2012 13:58:32 -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 KXkyali8N-EF for <notmuch@notmuchmail.org>;\r
16         Sat, 29 Dec 2012 13:58:31 -0800 (PST)\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
18         by olra.theworths.org (Postfix) with ESMTP id AEDA6431FAF\r
19         for <notmuch@notmuchmail.org>; Sat, 29 Dec 2012 13:58:30 -0800 (PST)\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
21         by guru.guru-group.fi (Postfix) with ESMTP id 114601000CA;\r
22         Sat, 29 Dec 2012 23:58:22 +0200 (EET)\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>\r
24 To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org\r
25 Subject: Re: [PATCH v3 2/5] util: Function to parse boolean term queries\r
26 In-Reply-To: <1356719189-2837-3-git-send-email-amdragon@mit.edu>\r
27 References: <1356719189-2837-1-git-send-email-amdragon@mit.edu>\r
28         <1356719189-2837-3-git-send-email-amdragon@mit.edu>\r
29 User-Agent: Notmuch/0.14+216~gd58661f (http://notmuchmail.org) Emacs/24.2.1\r
30         (x86_64-unknown-linux-gnu)\r
31 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
32         $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
33         !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
34 Date: Sat, 29 Dec 2012 23:58:21 +0200\r
35 Message-ID: <m2han4sepu.fsf@guru.guru-group.fi>\r
36 MIME-Version: 1.0\r
37 Content-Type: text/plain\r
38 X-BeenThere: notmuch@notmuchmail.org\r
39 X-Mailman-Version: 2.1.13\r
40 Precedence: list\r
41 List-Id: "Use and development of the notmuch mail system."\r
42         <notmuch.notmuchmail.org>\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
44         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
46 List-Post: <mailto:notmuch@notmuchmail.org>\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
50 X-List-Received-Date: Sat, 29 Dec 2012 21:58:33 -0000\r
51 \r
52 On Fri, Dec 28 2012, Austin Clements <amdragon@MIT.EDU> wrote:\r
53 \r
54 > This parses the subset of Xapian's boolean term quoting rules that are\r
55 > used by make_boolean_term.  This is provided as a generic string\r
56 > utility, but will be used shortly in notmuch restore to parse and\r
57 > optimize for ID queries.\r
58 > ---\r
59 >  util/string-util.c |   55 ++++++++++++++++++++++++++++++++++++++++++++++++++++\r
60 >  util/string-util.h |   11 +++++++++++\r
61 >  2 files changed, 66 insertions(+)\r
62 >\r
63 > diff --git a/util/string-util.c b/util/string-util.c\r
64 > index e4bea21..83b4953 100644\r
65 > --- a/util/string-util.c\r
66 > +++ b/util/string-util.c\r
67 > @@ -96,3 +96,58 @@ make_boolean_term (void *ctx, const char *prefix, const char *term,\r
68 >  \r
69 >      return 0;\r
70 >  }\r
71 > +\r
72 > +int\r
73 > +parse_boolean_term (void *ctx, const char *str,\r
74 > +                 char **prefix_out, char **term_out)\r
75 > +{\r
76 > +    *prefix_out = *term_out = NULL;\r
77 > +\r
78 > +    /* Parse prefix */\r
79 > +    const char *pos = strchr (str, ':');\r
80 > +    if (! pos)\r
81 > +     goto FAIL;\r
82 > +    *prefix_out = talloc_strndup (ctx, str, pos - str);\r
83 > +    ++pos;\r
84 > +\r
85 > +    /* Implement de-quoting compatible with make_boolean_term. */\r
86 > +    if (*pos == '"') {\r
87 > +     char *out = talloc_array (ctx, char, strlen (pos));\r
88 > +     int closed = 0;\r
89 > +     *term_out = out;\r
90 > +     /* Skip the opening quote, find the closing quote, and\r
91 > +      * un-double doubled internal quotes. */\r
92 > +     for (++pos; *pos; ) {\r
93 > +         if (*pos == '"') {\r
94 > +             ++pos;\r
95 > +             if (*pos != '"') {\r
96 > +                 /* Found the closing quote. */\r
97 > +                 closed = 1;\r
98 > +                 break;\r
99 > +             }\r
100 > +         }\r
101 > +         *out++ = *pos++;\r
102 > +     }\r
103 > +     /* Did the term terminate without a closing quote or is there\r
104 > +      * trailing text after the closing quote? */\r
105 > +     if (!closed || *pos)\r
106 > +         goto FAIL;\r
107 > +     *out = '\0';\r
108 > +    } else {\r
109 > +     const char *start = pos;\r
110 > +     /* Check for text after the boolean term. */\r
111 > +     while (*pos > ' ' && *pos != ')')\r
112 > +         ++pos;\r
113 > +     if (*pos)\r
114 > +         goto FAIL;\r
115 \r
116 Mark pointed out a good case about trailing whitespace -- It would be nice\r
117 if the core were lenient for such cases. I personally remember once wasting\r
118 hours of work by just failing to notice trailing whitespace in one system\r
119 so this subject is sensitive to me...\r
120 \r
121 Another thing I saw earlyer today: make_boolean_term() checks\r
122 \r
123    if (*in <= ' ' || *in == ')' || *in == '"' || (unsigned char)*in > 127)\r
124 \r
125 but here the check is only\r
126 \r
127    while (*pos > ' ' && *pos != ')')\r
128 \r
129 I wonder whether it matters...\r
130 \r
131 Everyting else looks good to me.\r
132 \r
133 \r
134 Tomi\r
135 \r
136 > +     /* No trailing text; dup the string so the caller can free\r
137 > +      * it. */\r
138 > +     *term_out = talloc_strdup (ctx, start);\r
139 > +    }\r
140 > +    return 0;\r
141 > +\r
142 > + FAIL:\r
143 > +    talloc_free (*prefix_out);\r
144 > +    talloc_free (*term_out);\r
145 > +    return 1;\r
146 > +}\r
147 > diff --git a/util/string-util.h b/util/string-util.h\r
148 > index b8844a3..43d49d0 100644\r
149 > --- a/util/string-util.h\r
150 > +++ b/util/string-util.h\r
151 > @@ -33,4 +33,15 @@ char *strtok_len (char *s, const char *delim, size_t *len);\r
152 >  int make_boolean_term (void *talloc_ctx, const char *prefix, const char *term,\r
153 >                      char **buf, size_t *len);\r
154 >  \r
155 > +/* Parse a boolean term query produced by make_boolean_term, returning\r
156 > + * the prefix in *prefix_out and the term in *term_out.  *prefix_out\r
157 > + * and *term_out will be talloc'd with context ctx.\r
158 > + *\r
159 > + * Return: 0 on success, non-zero on parse error (including trailing\r
160 > + * data in str).\r
161 > + */\r
162 > +int\r
163 > +parse_boolean_term (void *ctx, const char *str,\r
164 > +                 char **prefix_out, char **term_out);\r
165 > +\r
166 >  #endif\r
167 > -- \r
168 > 1.7.10.4\r
169 >\r
170 > _______________________________________________\r
171 > notmuch mailing list\r
172 > notmuch@notmuchmail.org\r
173 > http://notmuchmail.org/mailman/listinfo/notmuch\r