From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id AEC35429E31 for ; Sun, 4 Dec 2011 07:48:22 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -2.3 X-Spam-Level: X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UJ-mObW90xh7 for ; Sun, 4 Dec 2011 07:48:21 -0800 (PST) Received: from tempo.its.unb.ca (tempo.its.unb.ca [131.202.1.21]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 9485B429E32 for ; Sun, 4 Dec 2011 07:48:15 -0800 (PST) Received: from zancas.localnet (fctnnbsc36w-156034079193.pppoe-dynamic.High-Speed.nb.bellaliant.net [156.34.79.193]) (authenticated bits=0) by tempo.its.unb.ca (8.13.8/8.13.8) with ESMTP id pB4Fm8g1005364 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO); Sun, 4 Dec 2011 11:48:11 -0400 Received: from bremner by zancas.localnet with local (Exim 4.77) (envelope-from ) id 1RXEIS-0001oq-BK; Sun, 04 Dec 2011 11:48:08 -0400 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 3/4] notmuch-restore: convert to notmuch-opts argument handling. Date: Sun, 4 Dec 2011 11:47:54 -0400 Message-Id: <1323013675-6929-4-git-send-email-david@tethera.net> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1323013675-6929-1-git-send-email-david@tethera.net> References: <1323013675-6929-1-git-send-email-david@tethera.net> Cc: David Bremner X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 04 Dec 2011 15:48:23 -0000 From: David Bremner The new argument handling is a bit more concise, and bit more flexible. It allows the input file name to go before the --accumulate option. --- notmuch-restore.c | 38 ++++++++++++++++---------------------- 1 files changed, 16 insertions(+), 22 deletions(-) diff --git a/notmuch-restore.c b/notmuch-restore.c index 13b4325..d0aa7a8 100644 --- a/notmuch-restore.c +++ b/notmuch-restore.c @@ -18,9 +18,8 @@ * Author: Carl Worth */ -#include - #include "notmuch-client.h" +#include "notmuch-opts.h" int notmuch_restore_command (unused (void *ctx), int argc, char *argv[]) @@ -29,12 +28,14 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[]) notmuch_database_t *notmuch; notmuch_bool_t synchronize_flags; notmuch_bool_t accumulate = FALSE; + char *input_file_name = NULL; FILE *input = stdin; char *line = NULL; size_t line_size; ssize_t line_len; regex_t regex; int rerr; + int opt_index; config = notmuch_config_open (ctx, NULL, NULL); if (config == NULL) @@ -47,37 +48,30 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[]) synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config); - struct option options[] = { - { "accumulate", no_argument, 0, 'a' }, - { 0, 0, 0, 0} + notmuch_opt_desc_t options[] = { + { "in-file", 'i', NOTMUCH_OPT_POSITION, 0, &input_file_name }, + { "accumulate", 'a', NOTMUCH_OPT_BOOLEAN, 0, &accumulate }, + { 0, 0, 0, 0, 0 } }; - int opt; - do { - opt = getopt_long (argc, argv, "", options, NULL); + opt_index = notmuch_parse_args (argc, argv, options, 1); - switch (opt) { - case 'a': - accumulate = 1; - break; - case '?': - return 1; - break; - } - - } while (opt != -1); + if (opt_index < 0) { + /* diagnostics already printed */ + exit(1); + } - if (optind < argc) { - input = fopen (argv[optind], "r"); + if (input_file_name) { + input = fopen (input_file_name, "r"); if (input == NULL) { fprintf (stderr, "Error opening %s for reading: %s\n", - argv[optind], strerror (errno)); + input_file_name, strerror (errno)); return 1; } optind++; } - if (optind < argc) { + if (opt_index < argc) { fprintf (stderr, "Cannot read dump from more than one file: %s\n", argv[optind]); -- 1.7.7.3