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 5D181429E27 for ; Wed, 30 Nov 2011 17:15:54 -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 02hxuyNPe0xe for ; Wed, 30 Nov 2011 17:15:53 -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 AA7ED431FD0 for ; Wed, 30 Nov 2011 17:15:53 -0800 (PST) Received: from rocinante.cs.unb.ca (m3.kereda.com [207.194.238.3] (may be forged)) (authenticated bits=0) by tempo.its.unb.ca (8.13.8/8.13.8) with ESMTP id pB11FnmK008709 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO); Wed, 30 Nov 2011 21:15:50 -0400 Received: from bremner by rocinante.cs.unb.ca with local (Exim 4.76) (envelope-from ) id 1RVvFd-0006qU-9e; Wed, 30 Nov 2011 17:15:49 -0800 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 2/3] notmuch-dump: convert to notmuch-opts option-parsing. Date: Wed, 30 Nov 2011 17:15:29 -0800 Message-Id: <1322702130-26068-2-git-send-email-bremner@debian.org> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1322702130-26068-1-git-send-email-bremner@debian.org> References: <7574621578db9bbfc88348c87e2f5431f4cb2296.1321223343.git.jani@nikula.org> <1322702130-26068-1-git-send-email-bremner@debian.org> 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: Thu, 01 Dec 2011 01:15:54 -0000 This is actually a bit of a tricky case because of the treating of the first non-option as a filename. On the other hand, we don't do any "normal" argument parsing yet. --- notmuch-dump.c | 46 +++++++++++++++++++++++++++++++--------------- 1 files changed, 31 insertions(+), 15 deletions(-) diff --git a/notmuch-dump.c b/notmuch-dump.c index 0475eb9..8a8d6ec 100644 --- a/notmuch-dump.c +++ b/notmuch-dump.c @@ -19,6 +19,7 @@ */ #include "notmuch-client.h" +#include "notmuch-opts.h" int notmuch_dump_command (unused (void *ctx), int argc, char *argv[]) @@ -41,27 +42,42 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[]) if (notmuch == NULL) return 1; - argc--; argv++; /* skip subcommand argument */ + notmuch_opt_desc_t options[] = { + { 0, 0, 0, 0 } + }; - if (argc && strcmp (argv[0], "--") != 0) { - fprintf (stderr, "Warning: the output file argument of dump is deprecated.\n"); - output = fopen (argv[0], "w"); - if (output == NULL) { - fprintf (stderr, "Error opening %s for writing: %s\n", - argv[0], strerror (errno)); + notmuch_opt_t result; + int opt_index; + notmuch_bool_t more_args=TRUE; + + for (opt_index = 1; more_args && opt_index < argc; opt_index++) { + + more_args=parse_argument (argv[0], argv[opt_index], options, &result); + + switch (result.arg_id) { + case '?': return 1; + break; + case '*': + fprintf (stderr, "Warning: the output file argument of dump is deprecated.\n"); + output = fopen (result.string, "w"); + if (output == NULL) { + fprintf (stderr, "Error opening %s for writing: %s\n", + result.string, strerror (errno)); + return 1; + } + case '-': + /* fall through */ + more_args=FALSE; + break; } - argc--; - argv++; } - if (argc && strcmp (argv[0], "--") == 0){ - argc--; - argv++; - } + if (opt_index < argc && strcmp(argv[opt_index],"--") == 0) + opt_index++; - if (argc) { - query_str = query_string_from_args (notmuch, argc, argv); + if (opt_index < argc) { + query_str = query_string_from_args (notmuch, argc-opt_index, argv+opt_index); if (query_str == NULL) { fprintf (stderr, "Out of memory.\n"); return 1; -- 1.7.5.4