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