Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id D7208429E2F for ; Wed, 7 Dec 2011 11:26:55 -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 edrw6pvPP8sx for ; Wed, 7 Dec 2011 11:26:54 -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 ED73F429E37 for ; Wed, 7 Dec 2011 11:26:49 -0800 (PST) Received: from convex-new.cs.unb.ca ([131.202.13.154]) by tempo.its.unb.ca (8.13.8/8.13.8) with ESMTP id pB7JQhNn021341; Wed, 7 Dec 2011 15:26:46 -0400 Received: from bremner by convex-new.cs.unb.ca with local (Exim 4.72) (envelope-from ) id 1RYN8d-0004Pp-UW; Wed, 07 Dec 2011 15:26:43 -0400 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH v4 4/5] notmuch-restore: convert to command-line-arguments Date: Wed, 7 Dec 2011 15:26:38 -0400 Message-Id: <1323285999-16870-5-git-send-email-david@tethera.net> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1323285999-16870-1-git-send-email-david@tethera.net> References: <87iplso9c9.fsf@zancas.localnet> <1323285999-16870-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: Wed, 07 Dec 2011 19:26:56 -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 | 37 +++++++++++++++---------------------- 1 files changed, 15 insertions(+), 22 deletions(-) diff --git a/notmuch-restore.c b/notmuch-restore.c index 13b4325..87d9772 100644 --- a/notmuch-restore.c +++ b/notmuch-restore.c @@ -18,8 +18,6 @@ * Author: Carl Worth */ -#include - #include "notmuch-client.h" int @@ -29,12 +27,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 +47,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[] = { + { NOTMUCH_OPT_POSITION, &input_file_name, 0, 0, 0 }, + { NOTMUCH_OPT_BOOLEAN, &accumulate, "accumulate", 'a', 0 }, + { 0, 0, 0, 0, 0 } }; - int opt; - do { - opt = getopt_long (argc, argv, "", options, NULL); - - switch (opt) { - case 'a': - accumulate = 1; - break; - case '?': - return 1; - break; - } + opt_index = parse_arguments (argc, argv, options, 1); - } while (opt != -1); + if (opt_index < 0) { + /* diagnostics already printed */ + return 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.5.4