[PATCH v2 02/20] tag: make tag operation parser public
authorPeter Wang <novalazy@gmail.com>
Sun, 25 Nov 2012 01:16:28 +0000 (12:16 +1100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:50:53 +0000 (09:50 -0800)
95/25757a09920b262ef0f1b468ceddfabb02fb58 [new file with mode: 0644]

diff --git a/95/25757a09920b262ef0f1b468ceddfabb02fb58 b/95/25757a09920b262ef0f1b468ceddfabb02fb58
new file mode 100644 (file)
index 0000000..e85cf3e
--- /dev/null
@@ -0,0 +1,158 @@
+Return-Path: <novalazy@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id C3259431FAE\r
+       for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 17:17:16 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id 9hR5Ew+RisLC for <notmuch@notmuchmail.org>;\r
+       Sat, 24 Nov 2012 17:17:16 -0800 (PST)\r
+Received: from mail-pb0-f53.google.com (mail-pb0-f53.google.com\r
+       [209.85.160.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 392ED431FBD\r
+       for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 17:17:16 -0800 (PST)\r
+Received: by mail-pb0-f53.google.com with SMTP id jt11so7944513pbb.26\r
+       for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 17:17:15 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+       h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
+       bh=VlIljfmxJjPfuWpmcWLotjw/BjiP2vefwPdyBkrjMgU=;\r
+       b=n9tFiGmSrm0vDb2++99f4yhBOjREUxG/bLPTO4feSMov8T3A6FGx7fQcOA9Ryy5wSk\r
+       +aP/CkJApkOAmdKNuJ/xdHtcjmQCeOhlWNOt1Rq1U+MZ2yc24zOrY+m/9JzWIvJ3wAZE\r
+       uuksT7BV0K3maIPDOJEjg2rzj2lP4B8xo3pE3b22Atb23PSRdfFlxF16q0IWBwREWBNw\r
+       UWNWVFg+7wDQKpv2HQz4rhd3cS3uFZ9fEHrWuTDVQ5ofR46zLHWL3fz5XpHYojGNF96X\r
+       cyDdMhLySH3J2bptY4oU3L207XLBkkoMXWVxJjdgFtfjty+FAxBFPYnJ50G2PT5Sgxel\r
+       ZFBA==\r
+Received: by 10.66.72.71 with SMTP id b7mr21677109pav.28.1353806235475;\r
+       Sat, 24 Nov 2012 17:17:15 -0800 (PST)\r
+Received: from localhost (215.42.233.220.static.exetel.com.au.\r
+       [220.233.42.215])\r
+       by mx.google.com with ESMTPS id ok8sm6224085pbb.42.2012.11.24.17.17.12\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Sat, 24 Nov 2012 17:17:14 -0800 (PST)\r
+From: Peter Wang <novalazy@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 02/20] tag: make tag operation parser public\r
+Date: Sun, 25 Nov 2012 12:16:28 +1100\r
+Message-Id: <1353806206-29133-3-git-send-email-novalazy@gmail.com>\r
+X-Mailer: git-send-email 1.7.12.1\r
+In-Reply-To: <1353806206-29133-1-git-send-email-novalazy@gmail.com>\r
+References: <1353806206-29133-1-git-send-email-novalazy@gmail.com>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 25 Nov 2012 01:17:16 -0000\r
+\r
+Make the tag operation parser accessible outside notmuch-tag.c\r
+so it can be reused by the upcoming insert command.\r
+---\r
+ notmuch-client.h |  9 +++++++++\r
+ notmuch-tag.c    | 17 ++++++-----------\r
+ 2 files changed, 15 insertions(+), 11 deletions(-)\r
+\r
+diff --git a/notmuch-client.h b/notmuch-client.h\r
+index ae9344b..a7c3df2 100644\r
+--- a/notmuch-client.h\r
++++ b/notmuch-client.h\r
+@@ -65,6 +65,11 @@ typedef GMimeCipherContext notmuch_crypto_context_t;\r
+ #define STRINGIFY(s) STRINGIFY_(s)\r
+ #define STRINGIFY_(s) #s\r
\r
++typedef struct {\r
++    const char *tag;\r
++    notmuch_bool_t remove;\r
++} notmuch_tag_operation_t;\r
++\r
+ typedef struct mime_node mime_node_t;\r
+ struct sprinter;\r
+ struct notmuch_show_params;\r
+@@ -159,6 +164,10 @@ notmuch_cat_command (void *ctx, int argc, char *argv[]);\r
+ int\r
+ notmuch_config_command (void *ctx, int argc, char *argv[]);\r
\r
++int\r
++parse_tag_operations (int i, int argc, char *argv[],\r
++                    notmuch_tag_operation_t *tag_ops, int *tag_ops_count);\r
++\r
+ const char *\r
+ notmuch_time_relative_date (const void *ctx, time_t then);\r
\r
+diff --git a/notmuch-tag.c b/notmuch-tag.c\r
+index 35a76db..831a0e4 100644\r
+--- a/notmuch-tag.c\r
++++ b/notmuch-tag.c\r
+@@ -54,14 +54,9 @@ _escape_tag (char *buf, const char *tag)\r
+     return buf;\r
+ }\r
\r
+-typedef struct {\r
+-    const char *tag;\r
+-    notmuch_bool_t remove;\r
+-} tag_operation_t;\r
+-\r
+ static char *\r
+ _optimize_tag_query (void *ctx, const char *orig_query_string,\r
+-                   const tag_operation_t *tag_ops)\r
++                   const notmuch_tag_operation_t *tag_ops)\r
+ {\r
+     /* This is subtler than it looks.  Xapian ignores the '-' operator\r
+      * at the beginning both queries and parenthesized groups and,\r
+@@ -116,7 +111,7 @@ _optimize_tag_query (void *ctx, const char *orig_query_string,\r
+  * element. */\r
+ static int\r
+ tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,\r
+-         tag_operation_t *tag_ops, notmuch_bool_t synchronize_flags)\r
++         notmuch_tag_operation_t *tag_ops, notmuch_bool_t synchronize_flags)\r
+ {\r
+     notmuch_query_t *query;\r
+     notmuch_messages_t *messages;\r
+@@ -170,9 +165,9 @@ tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,\r
+ /* Parse +tag and -tag operations between argv[i] and argv[argc-1].\r
+  * The array tag_ops must be at least argc - i elements long.\r
+  * Returns the index into argv where parsing stopped, or -1 on error. */\r
+-static int\r
++int\r
+ parse_tag_operations (int i, int argc, char *argv[],\r
+-                    tag_operation_t *tag_ops, int *tag_ops_count)\r
++                    notmuch_tag_operation_t *tag_ops, int *tag_ops_count)\r
+ {\r
+     *tag_ops_count = 0;\r
\r
+@@ -207,7 +202,7 @@ parse_tag_operations (int i, int argc, char *argv[],\r
+ int\r
+ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
+ {\r
+-    tag_operation_t *tag_ops;\r
++    notmuch_tag_operation_t *tag_ops;\r
+     int tag_ops_count;\r
+     char *query_string;\r
+     notmuch_config_t *config;\r
+@@ -228,7 +223,7 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
\r
+     /* Array of tagging operations (add or remove), terminated with an\r
+      * empty element. */\r
+-    tag_ops = talloc_array (ctx, tag_operation_t, argc + 1);\r
++    tag_ops = talloc_array (ctx, notmuch_tag_operation_t, argc + 1);\r
+     if (tag_ops == NULL) {\r
+       fprintf (stderr, "Out of memory.\n");\r
+       return 1;\r
+-- \r
+1.7.12.1\r
+\r