1 Return-Path: <novalazy@gmail.com>
\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 C8495431FBD
\r
6 for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 17:17:10 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5
\r
12 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
\r
13 FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id FvIGBmFpKB+q for <notmuch@notmuchmail.org>;
\r
17 Sat, 24 Nov 2012 17:17:10 -0800 (PST)
\r
18 Received: from mail-da0-f53.google.com (mail-da0-f53.google.com
\r
19 [209.85.210.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id D0B36431FCB
\r
22 for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 17:17:09 -0800 (PST)
\r
23 Received: by mail-da0-f53.google.com with SMTP id x6so2305618dac.26
\r
24 for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 17:17:09 -0800 (PST)
\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
\r
26 h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;
\r
27 bh=PHYy4HmuoDFHpFufvJXb0a38WQiJAMf1vpNxzYtVRzQ=;
\r
28 b=aFLkwOcYdoayx6xo+dD8Ky6tgn8c+WBQrn8FG6fMtMaG6SxoTqakGKWnX7KOVSBrHs
\r
29 ktRBJTbdDewlNQRopBagqcp3gCEkmm+k1gQ4x1Bpnz1BAm6+3hT9AH+QVuiDviUhr0/8
\r
30 4mHKJycdK5NXpYUZhDOr0hc0ElNSXbcg9/wzU/Pls8lJy2k13wKuNozp0P+rsk2BPlqN
\r
31 VjIA/d2UrkpOVqGVxNG6J3UT799Z3C74yLciLVn3djirrZa1JFY1matVdoSVpyruiELu
\r
32 ay6XG1UKtbfssr0y/gexIPc2rYxc15Yz65WXWf5Mdo2KH0Kol1sTqrh4DcrROVj0XpaW
\r
34 Received: by 10.66.78.169 with SMTP id c9mr22193987pax.30.1353806229604;
\r
35 Sat, 24 Nov 2012 17:17:09 -0800 (PST)
\r
36 Received: from localhost (215.42.233.220.static.exetel.com.au.
\r
38 by mx.google.com with ESMTPS id gl9sm6222142pbc.51.2012.11.24.17.17.06
\r
39 (version=TLSv1/SSLv3 cipher=OTHER);
\r
40 Sat, 24 Nov 2012 17:17:08 -0800 (PST)
\r
41 From: Peter Wang <novalazy@gmail.com>
\r
42 To: notmuch@notmuchmail.org
\r
43 Subject: [PATCH v2 01/20] tag: factor out tag operation parsing
\r
44 Date: Sun, 25 Nov 2012 12:16:27 +1100
\r
45 Message-Id: <1353806206-29133-2-git-send-email-novalazy@gmail.com>
\r
46 X-Mailer: git-send-email 1.7.12.1
\r
47 In-Reply-To: <1353806206-29133-1-git-send-email-novalazy@gmail.com>
\r
48 References: <1353806206-29133-1-git-send-email-novalazy@gmail.com>
\r
49 X-BeenThere: notmuch@notmuchmail.org
\r
50 X-Mailman-Version: 2.1.13
\r
52 List-Id: "Use and development of the notmuch mail system."
\r
53 <notmuch.notmuchmail.org>
\r
54 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
55 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
56 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
57 List-Post: <mailto:notmuch@notmuchmail.org>
\r
58 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
59 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
60 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
61 X-List-Received-Date: Sun, 25 Nov 2012 01:17:11 -0000
\r
63 Factor out parsing of +tag, -tag operations from argv
\r
64 into a separate function.
\r
66 notmuch-tag.c | 66 +++++++++++++++++++++++++++++++++++++----------------------
\r
67 1 file changed, 41 insertions(+), 25 deletions(-)
\r
69 diff --git a/notmuch-tag.c b/notmuch-tag.c
\r
70 index 88d559b..35a76db 100644
\r
73 @@ -167,11 +167,48 @@ tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,
\r
77 +/* Parse +tag and -tag operations between argv[i] and argv[argc-1].
\r
78 + * The array tag_ops must be at least argc - i elements long.
\r
79 + * Returns the index into argv where parsing stopped, or -1 on error. */
\r
81 +parse_tag_operations (int i, int argc, char *argv[],
\r
82 + tag_operation_t *tag_ops, int *tag_ops_count)
\r
84 + *tag_ops_count = 0;
\r
86 + for (; i < argc; i++) {
\r
87 + if (strcmp (argv[i], "--") == 0) {
\r
91 + if (argv[i][0] == '+' || argv[i][0] == '-') {
\r
92 + if (argv[i][0] == '+' && argv[i][1] == '\0') {
\r
93 + fprintf (stderr, "Error: tag names cannot be empty.\n");
\r
96 + if (argv[i][0] == '+' && argv[i][1] == '-') {
\r
97 + /* This disallows adding the non-removable tag "-" and
\r
98 + * enables notmuch tag to take long options in the
\r
100 + fprintf (stderr, "Error: tag names must not start with '-'.\n");
\r
103 + tag_ops[*tag_ops_count].tag = argv[i] + 1;
\r
104 + tag_ops[*tag_ops_count].remove = (argv[i][0] == '-');
\r
105 + (*tag_ops_count)++;
\r
115 notmuch_tag_command (void *ctx, int argc, char *argv[])
\r
117 tag_operation_t *tag_ops;
\r
118 - int tag_ops_count = 0;
\r
119 + int tag_ops_count;
\r
120 char *query_string;
\r
121 notmuch_config_t *config;
\r
122 notmuch_database_t *notmuch;
\r
123 @@ -197,30 +234,9 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
\r
127 - for (i = 0; i < argc; i++) {
\r
128 - if (strcmp (argv[i], "--") == 0) {
\r
132 - if (argv[i][0] == '+' || argv[i][0] == '-') {
\r
133 - if (argv[i][0] == '+' && argv[i][1] == '\0') {
\r
134 - fprintf (stderr, "Error: tag names cannot be empty.\n");
\r
137 - if (argv[i][0] == '+' && argv[i][1] == '-') {
\r
138 - /* This disallows adding the non-removable tag "-" and
\r
139 - * enables notmuch tag to take long options in the
\r
141 - fprintf (stderr, "Error: tag names must not start with '-'.\n");
\r
144 - tag_ops[tag_ops_count].tag = argv[i] + 1;
\r
145 - tag_ops[tag_ops_count].remove = (argv[i][0] == '-');
\r
151 + i = parse_tag_operations (0, argc, argv, tag_ops, &tag_ops_count);
\r
155 tag_ops[tag_ops_count].tag = NULL;
\r