Re: [PATCH v4 01/16] add util/search-path.{c, h} to test for executables in $PATH
[notmuch-archives.git] / 1d / 217b6068bd8602bbb5cac2565085132ea8be2c
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 7CF61429E26\r
6         for <notmuch@notmuchmail.org>; Tue,  6 Dec 2011 12:48:56 -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 Hsr6cDFTbWNv for <notmuch@notmuchmail.org>;\r
16         Tue,  6 Dec 2011 12:48:56 -0800 (PST)\r
17 Received: from mail-bw0-f53.google.com (mail-bw0-f53.google.com\r
18         [209.85.214.53]) (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 AB3A6429E21\r
21         for <notmuch@notmuchmail.org>; Tue,  6 Dec 2011 12:48:55 -0800 (PST)\r
22 Received: by bkbzu5 with SMTP id zu5so7894031bkb.26\r
23         for <notmuch@notmuchmail.org>; Tue, 06 Dec 2011 12:48:54 -0800 (PST)\r
24 Received: by 10.180.18.165 with SMTP id x5mr19448364wid.24.1323204534003;\r
25         Tue, 06 Dec 2011 12:48:54 -0800 (PST)\r
26 Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.\r
27         [80.220.92.23])\r
28         by mx.google.com with ESMTPS id hi3sm3591213wib.0.2011.12.06.12.48.52\r
29         (version=SSLv3 cipher=OTHER); Tue, 06 Dec 2011 12:48:53 -0800 (PST)\r
30 From: Jani Nikula <jani@nikula.org>\r
31 To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org\r
32 Subject: Re: [PATCH 3/4] notmuch-restore: convert to notmuch-opts argument\r
33         handling.\r
34 In-Reply-To: <1323013675-6929-4-git-send-email-david@tethera.net>\r
35 References: <1323013675-6929-1-git-send-email-david@tethera.net>\r
36         <1323013675-6929-4-git-send-email-david@tethera.net>\r
37 User-Agent: Notmuch/0.10.1+59~ga1814f2 (http://notmuchmail.org) Emacs/23.3.1\r
38         (i686-pc-linux-gnu)\r
39 Date: Tue, 06 Dec 2011 22:48:50 +0200\r
40 Message-ID: <87ty5dxw7h.fsf@nikula.org>\r
41 MIME-Version: 1.0\r
42 Content-Type: text/plain; charset=us-ascii\r
43 Cc: David Bremner <bremner@debian.org>\r
44 X-BeenThere: notmuch@notmuchmail.org\r
45 X-Mailman-Version: 2.1.13\r
46 Precedence: list\r
47 List-Id: "Use and development of the notmuch mail system."\r
48         <notmuch.notmuchmail.org>\r
49 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
50         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
51 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
52 List-Post: <mailto:notmuch@notmuchmail.org>\r
53 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
54 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
55         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
56 X-List-Received-Date: Tue, 06 Dec 2011 20:48:56 -0000\r
57 \r
58 On Sun,  4 Dec 2011 11:47:54 -0400, David Bremner <david@tethera.net> wrote:\r
59 > From: David Bremner <bremner@debian.org>\r
60\r
61 > The new argument handling is a bit more concise, and bit more\r
62 > flexible.  It allows the input file name to go before the --accumulate\r
63 > option.\r
64 > ---\r
65 >  notmuch-restore.c |   38 ++++++++++++++++----------------------\r
66 >  1 files changed, 16 insertions(+), 22 deletions(-)\r
67\r
68 > diff --git a/notmuch-restore.c b/notmuch-restore.c\r
69 > index 13b4325..d0aa7a8 100644\r
70 > --- a/notmuch-restore.c\r
71 > +++ b/notmuch-restore.c\r
72 > @@ -18,9 +18,8 @@\r
73 >   * Author: Carl Worth <cworth@cworth.org>\r
74 >   */\r
75 >  \r
76 > -#include <getopt.h>\r
77 > -\r
78 >  #include "notmuch-client.h"\r
79 > +#include "notmuch-opts.h"\r
80 \r
81 I guess this will eventually be included almost everywhere, so in that\r
82 sense could be put in notmuch-client.h too.\r
83 \r
84 >  \r
85 >  int\r
86 >  notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
87 > @@ -29,12 +28,14 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
88 >      notmuch_database_t *notmuch;\r
89 >      notmuch_bool_t synchronize_flags;\r
90 >      notmuch_bool_t accumulate = FALSE;\r
91 > +    char *input_file_name = NULL;\r
92 >      FILE *input = stdin;\r
93 >      char *line = NULL;\r
94 >      size_t line_size;\r
95 >      ssize_t line_len;\r
96 >      regex_t regex;\r
97 >      int rerr;\r
98 > +    int opt_index;\r
99 >  \r
100 >      config = notmuch_config_open (ctx, NULL, NULL);\r
101 >      if (config == NULL)\r
102 > @@ -47,37 +48,30 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
103 >  \r
104 >      synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
105 >  \r
106 > -    struct option options[] = {\r
107 > -     { "accumulate",   no_argument,       0, 'a' },\r
108 > -     { 0, 0, 0, 0}\r
109 > +    notmuch_opt_desc_t options[] = {\r
110 > +     { "in-file", 'i', NOTMUCH_OPT_POSITION, 0, &input_file_name },\r
111 \r
112 Unless I'm mistaken in review of patch 1, specifying the input file\r
113 using --in-file=file doesn't work; it only works as a positional\r
114 argument.\r
115 \r
116 > +     { "accumulate", 'a',  NOTMUCH_OPT_BOOLEAN, 0, &accumulate },\r
117 > +     { 0, 0, 0, 0, 0 }\r
118 >      };\r
119 >  \r
120 > -    int opt;\r
121 > -    do {\r
122 > -     opt = getopt_long (argc, argv, "", options, NULL);\r
123 > +    opt_index = notmuch_parse_args (argc, argv, options, 1);\r
124 >  \r
125 > -     switch (opt) {\r
126 > -     case 'a':\r
127 > -         accumulate = 1;\r
128 > -         break;\r
129 > -     case '?':\r
130 > -         return 1;\r
131 > -         break;\r
132 > -     }\r
133 > -\r
134 > -    } while (opt != -1);\r
135 > +    if (opt_index < 0) {\r
136 > +     /* diagnostics already printed */\r
137 > +     exit(1);\r
138 \r
139 return 1 rather than exit(1)?\r
140 \r
141 BR,\r
142 Jani.\r
143 \r
144 > +    }\r
145 >  \r
146 > -    if (optind < argc) {\r
147 > -     input = fopen (argv[optind], "r");\r
148 > +    if (input_file_name) {\r
149 > +     input = fopen (input_file_name, "r");\r
150 >       if (input == NULL) {\r
151 >           fprintf (stderr, "Error opening %s for reading: %s\n",\r
152 > -                  argv[optind], strerror (errno));\r
153 > +                  input_file_name, strerror (errno));\r
154 >           return 1;\r
155 >       }\r
156 >       optind++;\r
157 >      }\r
158 >  \r
159 > -    if (optind < argc) {\r
160 > +    if (opt_index < argc) {\r
161 >       fprintf (stderr,\r
162 >        "Cannot read dump from more than one file: %s\n",\r
163 >                argv[optind]);\r
164 > -- \r
165 > 1.7.7.3\r
166\r
167 > _______________________________________________\r
168 > notmuch mailing list\r
169 > notmuch@notmuchmail.org\r
170 > http://notmuchmail.org/mailman/listinfo/notmuch\r