From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <amdragon@mit.edu>
Received: from localhost (localhost [127.0.0.1])
	by olra.theworths.org (Postfix) with ESMTP id A56B4431FBD
	for <notmuch@notmuchmail.org>; Sun, 30 Dec 2012 22:42:52 -0800 (PST)
X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
X-Spam-Flag: NO
X-Spam-Score: -0.7
X-Spam-Level: 
X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
	tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
Received: from olra.theworths.org ([127.0.0.1])
	by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id jg16oMcRxCXj for <notmuch@notmuchmail.org>;
	Sun, 30 Dec 2012 22:42:52 -0800 (PST)
Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU
	[18.9.25.15])
	by olra.theworths.org (Postfix) with ESMTP id DD7EA431FAF
	for <notmuch@notmuchmail.org>; Sun, 30 Dec 2012 22:42:51 -0800 (PST)
X-AuditID: 1209190f-b7f016d000000e07-ae-50e133eb6114
Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])
	by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP
	id 9B.5C.03591.BE331E05; Mon, 31 Dec 2012 01:42:51 -0500 (EST)
Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])
	by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id qBV6goqc026112; 
	Mon, 31 Dec 2012 01:42:50 -0500
Received: from drake.dyndns.org (c-76-21-105-205.hsd1.ca.comcast.net
	[76.21.105.205]) (authenticated bits=0)
	(User authenticated as amdragon@ATHENA.MIT.EDU)
	by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id qBV6gkKq009878
	(version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
	Mon, 31 Dec 2012 01:42:48 -0500 (EST)
Received: from amthrax by drake.dyndns.org with local (Exim 4.77)
	(envelope-from <amdragon@mit.edu>)
	id 1TpZ5B-0000id-Ou; Mon, 31 Dec 2012 01:42:45 -0500
From: Austin Clements <amdragon@MIT.EDU>
To: notmuch@notmuchmail.org
Subject: [PATCH v4 0/5] Use Xapian query syntax for batch-tag dump/restore
Date: Mon, 31 Dec 2012 01:42:37 -0500
Message-Id: <1356936162-2589-1-git-send-email-amdragon@mit.edu>
X-Mailer: git-send-email 1.7.10.4
X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrPIsWRmVeSWpSXmKPExsUixG6nrvva+GGAwZw54hY3WrsZLZqmO1us
	nstjcf3mTGaLNyvnsTqweuycdZfd4/DXhSwet+6/Zvd4tuoWs8eWQ++ZA1ijuGxSUnMyy1KL
	9O0SuDI6vu5jKjgvUXF391fWBsb/Ql2MnBwSAiYSm9dOZIawxSQu3FvP1sXIwSEksI9RYrlB
	FyMXkLmBUeJ0z01GkBohgYtMEje31kAk5jJK3Fx6jg0kwSagIbFt/3KwIhEBaYmdd2ezgtjM
	AnESKy8tZgexhQW8JG59nwq2jEVAVWLJyZ1MIDavgL3E7IeHmSCOUJTofjaBbQIj7wJGhlWM
	sim5Vbq5iZk5xanJusXJiXl5qUW6Jnq5mSV6qSmlmxhB4cQpyb+D8dtBpUOMAhyMSjy8HEwP
	A4RYE8uKK3MPMUpyMCmJ8j40AgrxJeWnVGYkFmfEF5XmpBYfYpTgYFYS4X2rBZTjTUmsrEot
	yodJSXOwKInzXk256S8kkJ5YkpqdmlqQWgSTleHgUJLgLQYZKliUmp5akZaZU4KQZuLgBBnO
	AzS8GqSGt7ggMbc4Mx0if4pRUUqcNxEkIQCSyCjNg+uFxfsrRnGgV4R5p4NU8QBTBVz3K6DB
	TECDtRgegAwuSURISTUwSoumpRU8al7W9vaYf3LZqq83p1gYOiY9bzvl/VZCqz1Ea17w+k1X
	y2o6JH49ezf326/tXUoaMqd7nNdv+f76t+eTZgNN1V6HX4qWWyY8eXfDuW1PKuspswtP4781
	7E/LslPkk9n110U59mvCkgcfPp28X7le+LyIbGk8l5Bm1yvfnDtMU+e9UWIpzkg01GIuKk4E
	AJrCHQrSAgAA
Cc: tomi.ollila@iki.fi
X-BeenThere: notmuch@notmuchmail.org
X-Mailman-Version: 2.1.13
Precedence: list
List-Id: "Use and development of the notmuch mail system."
	<notmuch.notmuchmail.org>
List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
	<mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
List-Archive: <http://notmuchmail.org/pipermail/notmuch>
List-Post: <mailto:notmuch@notmuchmail.org>
List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
	<mailto:notmuch-request@notmuchmail.org?subject=subscribe>
X-List-Received-Date: Mon, 31 Dec 2012 06:42:52 -0000

This obsoletes

  id:1356719189-2837-1-git-send-email-amdragon@mit.edu

This version accepts whitespace before and after boolean terms in
parse_boolean_term and expands its documentation comment to describe
what it accepts and how that relates to Xapian and make_boolean_term.

The diff from v3 is below.

diff --git a/util/string-util.c b/util/string-util.c
index 83b4953..52c7781 100644
--- a/util/string-util.c
+++ b/util/string-util.c
@@ -22,6 +22,8 @@
 #include "string-util.h"
 #include "talloc.h"
 
+#include <ctype.h>
+
 char *
 strtok_len (char *s, const char *delim, size_t *len)
 {
@@ -97,6 +99,14 @@ make_boolean_term (void *ctx, const char *prefix, const char *term,
     return 0;
 }
 
+static const char*
+skip_space (const char *str)
+{
+    while (*str && isspace (*str))
+	++str;
+    return str;
+}
+
 int
 parse_boolean_term (void *ctx, const char *str,
 		    char **prefix_out, char **term_out)
@@ -104,6 +114,7 @@ parse_boolean_term (void *ctx, const char *str,
     *prefix_out = *term_out = NULL;
 
     /* Parse prefix */
+    str = skip_space (str);
     const char *pos = strchr (str, ':');
     if (! pos)
 	goto FAIL;
@@ -123,6 +134,7 @@ parse_boolean_term (void *ctx, const char *str,
 		if (*pos != '"') {
 		    /* Found the closing quote. */
 		    closed = 1;
+		    pos = skip_space (pos);
 		    break;
 		}
 	    }
@@ -138,11 +150,11 @@ parse_boolean_term (void *ctx, const char *str,
 	/* Check for text after the boolean term. */
 	while (*pos > ' ' && *pos != ')')
 	    ++pos;
-	if (*pos)
+	if (*skip_space (pos))
 	    goto FAIL;
 	/* No trailing text; dup the string so the caller can free
 	 * it. */
-	*term_out = talloc_strdup (ctx, start);
+	*term_out = talloc_strndup (ctx, start, pos - start);
     }
     return 0;
 
diff --git a/util/string-util.h b/util/string-util.h
index 43d49d0..8b9fe50 100644
--- a/util/string-util.h
+++ b/util/string-util.h
@@ -33,12 +33,16 @@ char *strtok_len (char *s, const char *delim, size_t *len);
 int make_boolean_term (void *talloc_ctx, const char *prefix, const char *term,
 		       char **buf, size_t *len);
 
-/* Parse a boolean term query produced by make_boolean_term, returning
- * the prefix in *prefix_out and the term in *term_out.  *prefix_out
- * and *term_out will be talloc'd with context ctx.
+/* Parse a boolean term query consisting of a prefix, a colon, and a
+ * term that may be quoted as described for make_boolean_term.  If the
+ * term is not quoted, then it ends at the first whitespace or close
+ * parenthesis.  str may containing leading or trailing whitespace,
+ * but anything else is considered a parse error.  This is compatible
+ * with anything produced by make_boolean_term, and supports a subset
+ * of the quoting styles supported by Xapian (and hence notmuch).
+ * *prefix_out and *term_out will be talloc'd with context ctx.
  *
- * Return: 0 on success, non-zero on parse error (including trailing
- * data in str).
+ * Return: 0 on success, non-zero on parse error.
  */
 int
 parse_boolean_term (void *ctx, const char *str,