Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 7b / 95bbeedd173834786f771f70428a9dfb6212a3
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 F2618431FB6\r
6         for <notmuch@notmuchmail.org>; Sun, 13 Nov 2011 14:48:05 -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
9 X-Spam-Flag: NO\r
10 X-Spam-Score: -0.7\r
11 X-Spam-Level: \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 twPdfRYHl7Km for <notmuch@notmuchmail.org>;\r
17         Sun, 13 Nov 2011 14:48:03 -0800 (PST)\r
18 Received: from mail-bw0-f53.google.com (mail-bw0-f53.google.com\r
19         [209.85.214.53]) (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 9DA5B429E44\r
22         for <notmuch@notmuchmail.org>; Sun, 13 Nov 2011 14:47:49 -0800 (PST)\r
23 Received: by mail-bw0-f53.google.com with SMTP id q10so6354254bka.26\r
24         for <notmuch@notmuchmail.org>; Sun, 13 Nov 2011 14:47:49 -0800 (PST)\r
25 Received: by 10.204.41.66 with SMTP id n2mr16693030bke.77.1321224469198;\r
26         Sun, 13 Nov 2011 14:47:49 -0800 (PST)\r
27 Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.\r
28         [80.220.92.23])\r
29         by mx.google.com with ESMTPS id z7sm28089278bka.1.2011.11.13.14.47.47\r
30         (version=SSLv3 cipher=OTHER); Sun, 13 Nov 2011 14:47:48 -0800 (PST)\r
31 From: Jani Nikula <jani@nikula.org>\r
32 To: notmuch@notmuchmail.org,\r
33         david@tethera.net\r
34 Subject: [PATCH 5/6] cli: notmuch reply: use getopt_long for parsing command\r
35         line options\r
36 Date: Mon, 14 Nov 2011 00:47:25 +0200\r
37 Message-Id:\r
38  <77019f4b2cd807d61f92360ff9e6f106ecd6ce35.1321223343.git.jani@nikula.org>\r
39 X-Mailer: git-send-email 1.7.5.4\r
40 In-Reply-To: <cover.1321223343.git.jani@nikula.org>\r
41 References: <cover.1321223343.git.jani@nikula.org>\r
42 In-Reply-To: <cover.1321223343.git.jani@nikula.org>\r
43 References: <cover.1321223343.git.jani@nikula.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: Sun, 13 Nov 2011 22:48:06 -0000\r
57 \r
58 Signed-off-by: Jani Nikula <jani@nikula.org>\r
59 ---\r
60  notmuch-reply.c |   40 +++++++++++++++++++++++-----------------\r
61  1 files changed, 23 insertions(+), 17 deletions(-)\r
62 \r
63 diff --git a/notmuch-reply.c b/notmuch-reply.c\r
64 index 7ac879f..45b9fe9 100644\r
65 --- a/notmuch-reply.c\r
66 +++ b/notmuch-reply.c\r
67 @@ -619,8 +619,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
68      notmuch_config_t *config;\r
69      notmuch_database_t *notmuch;\r
70      notmuch_query_t *query;\r
71 -    char *opt, *query_string;\r
72 -    int i, ret = 0;\r
73 +    char *query_string;\r
74 +    int ret = 0;\r
75      int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params);\r
76      notmuch_show_params_t params;\r
77  \r
78 @@ -628,24 +628,30 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
79      params.part = -1;\r
80      params.cryptoctx = NULL;\r
81  \r
82 -    argc--; argv++; /* skip subcommand argument */\r
83 +    while (1) {\r
84 +       int opt;\r
85 +       static struct option options[] = {\r
86 +           { "format", required_argument, NULL, 0 },\r
87 +           { "decrypt", no_argument, NULL, 1 },\r
88 +           { NULL, 0, NULL, 0 },\r
89 +       };\r
90  \r
91 -    for (i = 0; i < argc && argv[i][0] == '-'; i++) {\r
92 -       if (strcmp (argv[i], "--") == 0) {\r
93 -           i++;\r
94 +       opt = getopt_long (argc, argv, "", options, NULL);\r
95 +       if (opt == -1)\r
96             break;\r
97 -       }\r
98 -        if (STRNCMP_LITERAL (argv[i], "--format=") == 0) {\r
99 -           opt = argv[i] + sizeof ("--format=") - 1;\r
100 -           if (strcmp (opt, "default") == 0) {\r
101 +\r
102 +       switch (opt) {\r
103 +       case 0:\r
104 +           if (strcmp (optarg, "default") == 0) {\r
105                 reply_format_func = notmuch_reply_format_default;\r
106 -           } else if (strcmp (opt, "headers-only") == 0) {\r
107 +           } else if (strcmp (optarg, "headers-only") == 0) {\r
108                 reply_format_func = notmuch_reply_format_headers_only;\r
109             } else {\r
110 -               fprintf (stderr, "Invalid value for --format: %s\n", opt);\r
111 +               fprintf (stderr, "Invalid value for --format: %s\n", optarg);\r
112                 return 1;\r
113             }\r
114 -       } else if ((STRNCMP_LITERAL (argv[i], "--decrypt") == 0)) {\r
115 +           break;\r
116 +       case 1:\r
117             if (params.cryptoctx == NULL) {\r
118                 GMimeSession* session = g_object_new(g_mime_session_get_type(), NULL);\r
119                 if (NULL == (params.cryptoctx = g_mime_gpg_context_new(session, "gpg")))\r
120 @@ -655,14 +661,14 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
121                 g_object_unref (session);\r
122                 session = NULL;\r
123             }\r
124 -       } else {\r
125 -           fprintf (stderr, "Unrecognized option: %s\n", argv[i]);\r
126 +           break;\r
127 +       case '?':\r
128             return 1;\r
129         }\r
130      }\r
131  \r
132 -    argc -= i;\r
133 -    argv += i;\r
134 +    argc -= optind;\r
135 +    argv += optind;\r
136  \r
137      config = notmuch_config_open (ctx, NULL, NULL);\r
138      if (config == NULL)\r
139 -- \r
140 1.7.5.4\r
141 \r