[PATCH v3 4/6] setup: Create functions for tag list printing and parsing
[notmuch-archives.git] / 6a / c7ca4ab2385d51012c5305cc1608be221078ad
1 Return-Path: <pieter@praet.org>\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 A6281429E54\r
6         for <notmuch@notmuchmail.org>; Sun, 22 Jan 2012 21:52:42 -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.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 8sfMgQMHKzbh for <notmuch@notmuchmail.org>;\r
16         Sun, 22 Jan 2012 21:52:42 -0800 (PST)\r
17 Received: from mail-we0-f181.google.com (mail-we0-f181.google.com\r
18         [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 05B72429E40\r
21         for <notmuch@notmuchmail.org>; Sun, 22 Jan 2012 21:52:41 -0800 (PST)\r
22 Received: by werb10 with SMTP id b10so2146731wer.26\r
23         for <notmuch@notmuchmail.org>; Sun, 22 Jan 2012 21:52:40 -0800 (PST)\r
24 MIME-Version: 1.0\r
25 Received: by 10.180.86.105 with SMTP id o9mr4177839wiz.4.1327297960837;\r
26         Sun, 22 Jan 2012 21:52:40 -0800 (PST)\r
27 Received: from localhost ([109.131.95.182])\r
28         by mx.google.com with ESMTPS id hc10sm7780443wib.8.2012.01.22.21.52.40\r
29         (version=TLSv1/SSLv3 cipher=OTHER);\r
30         Sun, 22 Jan 2012 21:52:40 -0800 (PST)\r
31 From: Pieter Praet <pieter@praet.org>\r
32 To: Austin Clements <amdragon@MIT.EDU>\r
33 Subject: [PATCH v3 4/6] setup: Create functions for tag list printing and\r
34         parsing\r
35 Date: Mon, 23 Jan 2012 06:50:45 +0100\r
36 Message-Id: <1327297845-16438-1-git-send-email-pieter@praet.org>\r
37 X-Mailer: git-send-email 1.7.8.1\r
38 In-Reply-To: <20120123050737.GT16740@mit.edu>\r
39 References: <20120123050737.GT16740@mit.edu>\r
40 X-Gm-Message-State:\r
41  ALoCoQkrorl97QSMdRsCoFliTmjVHgBTShvwRKiHyttvg3i71w+t4HmiKFsl7sxPEuxXPpV8rVu+\r
42 Cc: Notmuch Mail <notmuch@notmuchmail.org>\r
43 X-BeenThere: notmuch@notmuchmail.org\r
44 X-Mailman-Version: 2.1.13\r
45 Precedence: list\r
46 List-Id: "Use and development of the notmuch mail system."\r
47         <notmuch.notmuchmail.org>\r
48 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
50 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
51 List-Post: <mailto:notmuch@notmuchmail.org>\r
52 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
53 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
54         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
55 X-List-Received-Date: Mon, 23 Jan 2012 05:52:42 -0000\r
56 \r
57 From: Austin Clements <amdragon@MIT.EDU>\r
58 \r
59 This refactors the tag list printing and parsing currently used for\r
60 new.tags so that both can be reused for the new search.exclude_tags\r
61 option.\r
62 \r
63 ---\r
64  notmuch-setup.c |   55 ++++++++++++++++++++++++++++++++++---------------------\r
65  1 files changed, 34 insertions(+), 21 deletions(-)\r
66 \r
67 diff --git a/notmuch-setup.c b/notmuch-setup.c\r
68 index c3ea937..f85e0eb 100644\r
69 --- a/notmuch-setup.c\r
70 +++ b/notmuch-setup.c\r
71 @@ -87,6 +87,38 @@ welcome_message_post_setup (void)\r
72  "have sufficient storage space available now.\n\n");\r
73  }\r
74  \r
75 +static void\r
76 +print_tag_list (const char **tags, size_t tags_len)\r
77 +{\r
78 +    unsigned int i;\r
79 +    for (i = 0; i < tags_len; i++) {\r
80 +       if (i != 0)\r
81 +           printf (" ");\r
82 +       printf ("%s", tags[i]);\r
83 +    }\r
84 +}\r
85 +\r
86 +static GPtrArray *\r
87 +parse_tag_list (void *ctx, char *response)\r
88 +{\r
89 +    GPtrArray *tags = g_ptr_array_new ();\r
90 +    char *tag = response;\r
91 +    char *space;\r
92 +\r
93 +    while (tag && *tag) {\r
94 +       space = strchr (tag, ' ');\r
95 +       if (space)\r
96 +           g_ptr_array_add (tags, talloc_strndup (ctx, tag, space - tag));\r
97 +       else\r
98 +           g_ptr_array_add (tags, talloc_strdup (ctx, tag));\r
99 +       tag = space;\r
100 +       while (tag && *tag == ' ')\r
101 +           tag++;\r
102 +    }\r
103 +\r
104 +    return tags;\r
105 +}\r
106 +\r
107  int\r
108  notmuch_setup_command (unused (void *ctx),\r
109                        unused (int argc), unused (char *argv[]))\r
110 @@ -164,30 +196,11 @@ notmuch_setup_command (unused (void *ctx),\r
111      new_tags = notmuch_config_get_new_tags (config, &new_tags_len);\r
112  \r
113      printf ("Tags to apply to all new messages (separated by spaces) [");\r
114 -\r
115 -    for (i = 0; i < new_tags_len; i++) {\r
116 -       if (i != 0)\r
117 -           printf (" ");\r
118 -       printf ("%s", new_tags[i]);\r
119 -    }\r
120 -\r
121 +    print_tag_list (new_tags, new_tags_len);\r
122      prompt ("]: ");\r
123  \r
124      if (strlen (response)) {\r
125 -       GPtrArray *tags = g_ptr_array_new ();\r
126 -       char *tag = response;\r
127 -       char *space;\r
128 -\r
129 -       while (tag && *tag) {\r
130 -           space = strchr (tag, ' ');\r
131 -           if (space)\r
132 -               g_ptr_array_add (tags, talloc_strndup (ctx, tag, space - tag));\r
133 -           else\r
134 -               g_ptr_array_add (tags, talloc_strdup (ctx, tag));\r
135 -           tag = space;\r
136 -           while (tag && *tag == ' ')\r
137 -               tag++;\r
138 -       }\r
139 +       GPtrArray *tags = parse_tag_list (ctx, response);\r
140  \r
141         notmuch_config_set_new_tags (config, (const char **) tags->pdata,\r
142                                      tags->len);\r
143 -- \r
144 1.7.8.1\r
145 \r