Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 2f / f9cfdd042f7b8bd09dafc1af23f53e6287a658
1 Return-Path: <bremner@tethera.net>\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 4BC64429E2E\r
6         for <notmuch@notmuchmail.org>; Fri, 28 Oct 2011 20:05:11 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -2.3\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_MED=-2.3] 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 0W-1LZ-wD-9C for <notmuch@notmuchmail.org>;\r
16         Fri, 28 Oct 2011 20:05:10 -0700 (PDT)\r
17 Received: from tempo.its.unb.ca (tempo.its.unb.ca [131.202.1.21])\r
18         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 06728429E31\r
21         for <notmuch@notmuchmail.org>; Fri, 28 Oct 2011 20:05:03 -0700 (PDT)\r
22 Received: from zancas.localnet\r
23         (fctnnbsc36w-156034064058.pppoe-dynamic.High-Speed.nb.bellaliant.net\r
24         [156.34.64.58]) (authenticated bits=0)\r
25         by tempo.its.unb.ca (8.13.8/8.13.8) with ESMTP id p9T34xWM016363\r
26         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO);\r
27         Sat, 29 Oct 2011 00:04:59 -0300\r
28 Received: from bremner by zancas.localnet with local (Exim 4.76)\r
29         (envelope-from <bremner@tethera.net>)\r
30         id 1RJzEB-0003DD-2I; Sat, 29 Oct 2011 00:04:59 -0300\r
31 From: David Bremner <david@tethera.net>\r
32 To: notmuch@notmuchmail.org\r
33 Subject: [PATCH 2/4] notmuch-restore: implement argument parsing for --match\r
34 Date: Sat, 29 Oct 2011 00:04:49 -0300\r
35 Message-Id: <1319857491-12298-3-git-send-email-david@tethera.net>\r
36 X-Mailer: git-send-email 1.7.6.3\r
37 In-Reply-To: <1319857491-12298-1-git-send-email-david@tethera.net>\r
38 References: <1319406673-7208-1-git-send-email-david@tethera.net>\r
39         <1319857491-12298-1-git-send-email-david@tethera.net>\r
40 Cc: David Bremner <bremner@debian.org>\r
41 X-BeenThere: notmuch@notmuchmail.org\r
42 X-Mailman-Version: 2.1.13\r
43 Precedence: list\r
44 List-Id: "Use and development of the notmuch mail system."\r
45         <notmuch.notmuchmail.org>\r
46 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
47         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
48 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
49 List-Post: <mailto:notmuch@notmuchmail.org>\r
50 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
51 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
52         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
53 X-List-Received-Date: Sat, 29 Oct 2011 03:05:11 -0000\r
54 \r
55 From: David Bremner <bremner@debian.org>\r
56 \r
57 - recognize the --match option\r
58 - require an argument\r
59 - check the argument is a correct regex.\r
60 \r
61 Currently the arguments are ignored after parsing. Note that we have\r
62 to be a bit careful to avoid creating a resource leak here by error\r
63 returning before calling regfree. On the other hand, notmuch is\r
64 probably shutting down at that point, so it may not matter much.\r
65 ---\r
66  notmuch-restore.c |   18 ++++++++++++++----\r
67  test/dump-restore |    3 ---\r
68  2 files changed, 14 insertions(+), 7 deletions(-)\r
69 \r
70 diff --git a/notmuch-restore.c b/notmuch-restore.c\r
71 index 13b4325..e5ac162 100644\r
72 --- a/notmuch-restore.c\r
73 +++ b/notmuch-restore.c\r
74 @@ -29,11 +29,12 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
75      notmuch_database_t *notmuch;\r
76      notmuch_bool_t synchronize_flags;\r
77      notmuch_bool_t accumulate = FALSE;\r
78 +    notmuch_bool_t match_enabled = FALSE;\r
79      FILE *input = stdin;\r
80      char *line = NULL;\r
81      size_t line_size;\r
82      ssize_t line_len;\r
83 -    regex_t regex;\r
84 +    regex_t input_regex, match_regex;\r
85      int rerr;\r
86  \r
87      config = notmuch_config_open (ctx, NULL, NULL);\r
88 @@ -49,6 +50,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
89  \r
90      struct option options[] = {\r
91         { "accumulate",   no_argument,       0, 'a' },\r
92 +       { "match",        required_argument, 0, 'm' },\r
93         { 0, 0, 0, 0}\r
94      };\r
95  \r
96 @@ -60,6 +62,11 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
97         case 'a':\r
98             accumulate = 1;\r
99             break;\r
100 +       case 'm':\r
101 +           match_enabled = TRUE;\r
102 +           if ( xregcomp (&match_regex, optarg, REG_EXTENDED) )\r
103 +               return 1;\r
104 +           break;\r
105         case '?':\r
106             return 1;\r
107             break;\r
108 @@ -88,7 +95,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
109       * non-space characters for the message-id, then one or more\r
110       * spaces, then a list of space-separated tags as a sequence of\r
111       * characters within literal '(' and ')'. */\r
112 -    if ( xregcomp (&regex,\r
113 +    if ( xregcomp (&input_regex,\r
114                    "^([^ ]+) \\(([^)]*)\\)$",\r
115                    REG_EXTENDED) )\r
116         INTERNAL_ERROR("compile time constant regex failed.");\r
117 @@ -103,7 +110,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
118  \r
119         chomp_newline (line);\r
120  \r
121 -       rerr = xregexec (&regex, line, 3, match, 0);\r
122 +       rerr = xregexec (&input_regex, line, 3, match, 0);\r
123         if (rerr == REG_NOMATCH)\r
124         {\r
125             fprintf (stderr, "Warning: Ignoring invalid input line: %s\n",\r
126 @@ -186,7 +193,10 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
127         free (file_tags);\r
128      }\r
129  \r
130 -    regfree (&regex);\r
131 +    regfree (&input_regex);\r
132 +\r
133 +    if (match_enabled)\r
134 +       regfree (&match_regex);\r
135  \r
136      if (line)\r
137         free (line);\r
138 diff --git a/test/dump-restore b/test/dump-restore\r
139 index c176b52..c6089f9 100755\r
140 --- a/test/dump-restore\r
141 +++ b/test/dump-restore\r
142 @@ -55,16 +55,13 @@ test_expect_success 'restore extra argument' \\r
143  \r
144  \r
145  test_begin_subtest 'restore --match #missing arg'\r
146 -test_subtest_known_broken\r
147  test_expect_equal "restore: option '--match' requires an argument"\\r
148    "$(notmuch restore --match 2>&1)"\r
149  \r
150  test_begin_subtest 'restore --match=<bad regex>'\r
151 -test_subtest_known_broken\r
152  test_expect_equal 'compiling regex notmuch.*[: Invalid regular expression'\\r
153    "$(notmuch restore --match='notmuch.*[' 2>&1)"\r
154  \r
155 -test_subtest_known_broken\r
156  test_expect_success 'restore --match=<good regex>' \\r
157      'notmuch restore --match="notmuch.*" < /dev/null > /dev/null 2>&1'\r
158  \r
159 -- \r
160 1.7.6.3\r
161 \r