Re: [PATCH 0/4] Allow specifying alternate names for addresses in other_email
[notmuch-archives.git] / a1 / 374bc52b437a57c68c9534d583d7009b4c4e7c
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 AEC35429E31\r
6         for <notmuch@notmuchmail.org>; Sun,  4 Dec 2011 07:48:22 -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: -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 UJ-mObW90xh7 for <notmuch@notmuchmail.org>;\r
16         Sun,  4 Dec 2011 07:48:21 -0800 (PST)\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 9485B429E32\r
21         for <notmuch@notmuchmail.org>; Sun,  4 Dec 2011 07:48:15 -0800 (PST)\r
22 Received: from zancas.localnet\r
23         (fctnnbsc36w-156034079193.pppoe-dynamic.High-Speed.nb.bellaliant.net\r
24         [156.34.79.193]) (authenticated bits=0)\r
25         by tempo.its.unb.ca (8.13.8/8.13.8) with ESMTP id pB4Fm8g1005364\r
26         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO);\r
27         Sun, 4 Dec 2011 11:48:11 -0400\r
28 Received: from bremner by zancas.localnet with local (Exim 4.77)\r
29         (envelope-from <bremner@tethera.net>)\r
30         id 1RXEIS-0001oq-BK; Sun, 04 Dec 2011 11:48:08 -0400\r
31 From: David Bremner <david@tethera.net>\r
32 To: notmuch@notmuchmail.org\r
33 Subject: [PATCH 3/4] notmuch-restore: convert to notmuch-opts argument\r
34         handling.\r
35 Date: Sun,  4 Dec 2011 11:47:54 -0400\r
36 Message-Id: <1323013675-6929-4-git-send-email-david@tethera.net>\r
37 X-Mailer: git-send-email 1.7.7.3\r
38 In-Reply-To: <1323013675-6929-1-git-send-email-david@tethera.net>\r
39 References: <1323013675-6929-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: Sun, 04 Dec 2011 15:48:23 -0000\r
54 \r
55 From: David Bremner <bremner@debian.org>\r
56 \r
57 The new argument handling is a bit more concise, and bit more\r
58 flexible.  It allows the input file name to go before the --accumulate\r
59 option.\r
60 ---\r
61  notmuch-restore.c |   38 ++++++++++++++++----------------------\r
62  1 files changed, 16 insertions(+), 22 deletions(-)\r
63 \r
64 diff --git a/notmuch-restore.c b/notmuch-restore.c\r
65 index 13b4325..d0aa7a8 100644\r
66 --- a/notmuch-restore.c\r
67 +++ b/notmuch-restore.c\r
68 @@ -18,9 +18,8 @@\r
69   * Author: Carl Worth <cworth@cworth.org>\r
70   */\r
71  \r
72 -#include <getopt.h>\r
73 -\r
74  #include "notmuch-client.h"\r
75 +#include "notmuch-opts.h"\r
76  \r
77  int\r
78  notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
79 @@ -29,12 +28,14 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
80      notmuch_database_t *notmuch;\r
81      notmuch_bool_t synchronize_flags;\r
82      notmuch_bool_t accumulate = FALSE;\r
83 +    char *input_file_name = NULL;\r
84      FILE *input = stdin;\r
85      char *line = NULL;\r
86      size_t line_size;\r
87      ssize_t line_len;\r
88      regex_t regex;\r
89      int rerr;\r
90 +    int opt_index;\r
91  \r
92      config = notmuch_config_open (ctx, NULL, NULL);\r
93      if (config == NULL)\r
94 @@ -47,37 +48,30 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
95  \r
96      synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
97  \r
98 -    struct option options[] = {\r
99 -       { "accumulate",   no_argument,       0, 'a' },\r
100 -       { 0, 0, 0, 0}\r
101 +    notmuch_opt_desc_t options[] = {\r
102 +       { "in-file", 'i', NOTMUCH_OPT_POSITION, 0, &input_file_name },\r
103 +       { "accumulate", 'a',  NOTMUCH_OPT_BOOLEAN, 0, &accumulate },\r
104 +       { 0, 0, 0, 0, 0 }\r
105      };\r
106  \r
107 -    int opt;\r
108 -    do {\r
109 -       opt = getopt_long (argc, argv, "", options, NULL);\r
110 +    opt_index = notmuch_parse_args (argc, argv, options, 1);\r
111  \r
112 -       switch (opt) {\r
113 -       case 'a':\r
114 -           accumulate = 1;\r
115 -           break;\r
116 -       case '?':\r
117 -           return 1;\r
118 -           break;\r
119 -       }\r
120 -\r
121 -    } while (opt != -1);\r
122 +    if (opt_index < 0) {\r
123 +       /* diagnostics already printed */\r
124 +       exit(1);\r
125 +    }\r
126  \r
127 -    if (optind < argc) {\r
128 -       input = fopen (argv[optind], "r");\r
129 +    if (input_file_name) {\r
130 +       input = fopen (input_file_name, "r");\r
131         if (input == NULL) {\r
132             fprintf (stderr, "Error opening %s for reading: %s\n",\r
133 -                    argv[optind], strerror (errno));\r
134 +                    input_file_name, strerror (errno));\r
135             return 1;\r
136         }\r
137         optind++;\r
138      }\r
139  \r
140 -    if (optind < argc) {\r
141 +    if (opt_index < argc) {\r
142         fprintf (stderr,\r
143          "Cannot read dump from more than one file: %s\n",\r
144                  argv[optind]);\r
145 -- \r
146 1.7.7.3\r
147 \r