1 Return-Path: <jani@nikula.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 E85CA431FC0
\r
6 for <notmuch@notmuchmail.org>; Tue, 29 Jan 2013 13:46:51 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"
\r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
13 tests=[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 4MM6nB70lV-X for <notmuch@notmuchmail.org>;
\r
17 Tue, 29 Jan 2013 13:46:51 -0800 (PST)
\r
18 Received: from mail-la0-f45.google.com (mail-la0-f45.google.com
\r
19 [209.85.215.45]) (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 43325431FC7
\r
22 for <notmuch@notmuchmail.org>; Tue, 29 Jan 2013 13:46:50 -0800 (PST)
\r
23 Received: by mail-la0-f45.google.com with SMTP id er20so647502lab.18
\r
24 for <notmuch@notmuchmail.org>; Tue, 29 Jan 2013 13:46:48 -0800 (PST)
\r
25 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
26 d=google.com; s=20120113;
\r
27 h=x-received:from:to:subject:date:message-id:x-mailer:in-reply-to
\r
28 :references:in-reply-to:references:x-gm-message-state;
\r
29 bh=4qDQAjZfBxw+vY+TowfikkHP/5T9Zn3JBgUl8IWByd0=;
\r
30 b=LxS8Q186Dv8+exSpgYvTTIxH9pHaTGgrhm3X6ltjeOlbcc2KKkcynb4f4suhIaLnNm
\r
31 CZvf1twbcaXWQjN4tYe84xdwN7GrfraJWEvLnyZ9FFBS0ek7P0gGChbCl1Ajqh1EPNac
\r
32 GuPoUSLJeCnaQhfCvifYVj6HSd/ghQ194qZzKJ9Uqix5azNf1dWCw2xRo9hraiSkDK9z
\r
33 o3p0imkotHoNmEMjQ/fMDeIVsSbkThlXmwCLQqx5AEfnBvwVp52fRqKOhNnA0NQx7i2Z
\r
34 +0gNjHKQRiMB4QPfO4zoq5R6YMUfMQq3FYJKr5OiW7NR2uRLJHqZgWMuFqUBEtCaHRm6
\r
36 X-Received: by 10.112.38.164 with SMTP id h4mr1031947lbk.123.1359496008558;
\r
37 Tue, 29 Jan 2013 13:46:48 -0800 (PST)
\r
38 Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi.
\r
40 by mx.google.com with ESMTPS id q4sm5590461lbj.15.2013.01.29.13.46.46
\r
41 (version=TLSv1.2 cipher=RC4-SHA bits=128/128);
\r
42 Tue, 29 Jan 2013 13:46:47 -0800 (PST)
\r
43 From: Jani Nikula <jani@nikula.org>
\r
44 To: notmuch@notmuchmail.org
\r
45 Subject: [PATCH 3/6] cli: abstract subcommand finding into a new function
\r
46 Date: Tue, 29 Jan 2013 23:46:21 +0200
\r
48 <4fa07d936647d316f642c8f30b763d316604ea5f.1359495450.git.jani@nikula.org>
\r
49 X-Mailer: git-send-email 1.7.10.4
\r
50 In-Reply-To: <cover.1359495450.git.jani@nikula.org>
\r
51 References: <cover.1359495450.git.jani@nikula.org>
\r
52 In-Reply-To: <cover.1359495450.git.jani@nikula.org>
\r
53 References: <cover.1359495450.git.jani@nikula.org>
\r
55 ALoCoQkR3nDUsllGMSZG26Z6cqxy+Q2aboFlmB/+qbEGMNWhm6WpjHM3+3qDTMGsni0AeoOoK5c0
\r
56 X-BeenThere: notmuch@notmuchmail.org
\r
57 X-Mailman-Version: 2.1.13
\r
59 List-Id: "Use and development of the notmuch mail system."
\r
60 <notmuch.notmuchmail.org>
\r
61 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
62 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
63 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
64 List-Post: <mailto:notmuch@notmuchmail.org>
\r
65 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
66 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
67 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
68 X-List-Received-Date: Tue, 29 Jan 2013 21:46:52 -0000
\r
72 notmuch.c | 68 +++++++++++++++++++++++++++++++------------------------------
\r
73 1 file changed, 35 insertions(+), 33 deletions(-)
\r
75 diff --git a/notmuch.c b/notmuch.c
\r
76 index b413b53..c47b998 100644
\r
79 @@ -70,6 +70,18 @@ static command_t commands[] = {
\r
80 "This message, or more detailed help for the named command." }
\r
84 +find_command (const char *name)
\r
88 + for (i = 0; i < ARRAY_SIZE (commands); i++)
\r
89 + if (strcmp (name, commands[i].name) == 0)
\r
90 + return &commands[i];
\r
95 int notmuch_format_version;
\r
98 @@ -139,7 +151,6 @@ static int
\r
99 notmuch_help_command (void *ctx, int argc, char *argv[])
\r
101 command_t *command;
\r
104 argc--; argv++; /* Ignore "help" */
\r
106 @@ -158,13 +169,10 @@ notmuch_help_command (void *ctx, int argc, char *argv[])
\r
110 - for (i = 0; i < ARRAY_SIZE (commands); i++) {
\r
111 - command = &commands[i];
\r
113 - if (strcmp (argv[0], command->name) == 0) {
\r
114 - char *page = talloc_asprintf (ctx, "notmuch-%s", command->name);
\r
117 + command = find_command (argv[0]);
\r
119 + char *page = talloc_asprintf (ctx, "notmuch-%s", command->name);
\r
123 if (strcmp (argv[0], "search-terms") == 0) {
\r
124 @@ -246,10 +254,11 @@ int
\r
125 main (int argc, char *argv[])
\r
128 + char *talloc_report;
\r
129 command_t *command;
\r
131 notmuch_bool_t print_help=FALSE, print_version=FALSE;
\r
135 notmuch_opt_desc_t options[] = {
\r
136 { NOTMUCH_OPT_BOOLEAN, &print_help, "help", 'h', 0 },
\r
137 @@ -284,37 +293,30 @@ main (int argc, char *argv[])
\r
141 - for (i = 0; i < ARRAY_SIZE (commands); i++) {
\r
142 - command = &commands[i];
\r
144 - if (strcmp (argv[opt_index], command->name) == 0) {
\r
146 - char *talloc_report;
\r
148 - ret = (command->function)(local, argc - opt_index, argv + opt_index);
\r
149 + command = find_command (argv[opt_index]);
\r
151 + fprintf (stderr, "Error: Unknown command '%s' (see \"notmuch help\")\n",
\r
152 + argv[opt_index]);
\r
156 - /* in the future support for this environment variable may
\r
157 - * be supplemented or replaced by command line arguments
\r
158 - * --leak-report and/or --leak-report-full */
\r
159 + ret = (command->function)(local, argc - opt_index, argv + opt_index);
\r
161 - talloc_report = getenv ("NOTMUCH_TALLOC_REPORT");
\r
162 + /* in the future support for this environment variable may
\r
163 + * be supplemented or replaced by command line arguments
\r
164 + * --leak-report and/or --leak-report-full */
\r
166 - /* this relies on the previous call to
\r
167 - * talloc_enable_null_tracking */
\r
168 + talloc_report = getenv ("NOTMUCH_TALLOC_REPORT");
\r
170 - if (talloc_report && strcmp (talloc_report, "") != 0) {
\r
171 - FILE *report = fopen (talloc_report, "w");
\r
172 - talloc_report_full (NULL, report);
\r
174 + /* this relies on the previous call to
\r
175 + * talloc_enable_null_tracking */
\r
179 + if (talloc_report && strcmp (talloc_report, "") != 0) {
\r
180 + FILE *report = fopen (talloc_report, "w");
\r
181 + talloc_report_full (NULL, report);
\r
184 - fprintf (stderr, "Error: Unknown command '%s' (see \"notmuch help\")\n",
\r
187 talloc_free (local);
\r