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 26CDA429E26 for ; Tue, 6 Dec 2011 12:43:44 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 eVeaDB0OvMFF for ; Tue, 6 Dec 2011 12:43:43 -0800 (PST) Received: from mail-ww0-f45.google.com (mail-ww0-f45.google.com [74.125.82.45]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 64406429E21 for ; Tue, 6 Dec 2011 12:43:43 -0800 (PST) Received: by wgbds13 with SMTP id ds13so5706407wgb.2 for ; Tue, 06 Dec 2011 12:43:42 -0800 (PST) Received: by 10.227.203.10 with SMTP id fg10mr12462465wbb.1.1323204222061; Tue, 06 Dec 2011 12:43:42 -0800 (PST) Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi. [80.220.92.23]) by mx.google.com with ESMTPS id b5sm35340022wbh.4.2011.12.06.12.43.40 (version=SSLv3 cipher=OTHER); Tue, 06 Dec 2011 12:43:40 -0800 (PST) From: Jani Nikula To: David Bremner , notmuch@notmuchmail.org Subject: Re: [PATCH 2/4] notmuch-dump: convert to notmuch-opts argument handling. In-Reply-To: <1323013675-6929-3-git-send-email-david@tethera.net> References: <1323013675-6929-1-git-send-email-david@tethera.net> <1323013675-6929-3-git-send-email-david@tethera.net> User-Agent: Notmuch/0.10.1+59~ga1814f2 (http://notmuchmail.org) Emacs/23.3.1 (i686-pc-linux-gnu) Date: Tue, 06 Dec 2011 22:43:38 +0200 Message-ID: <87wra9xwg5.fsf@nikula.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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: Tue, 06 Dec 2011 20:43:44 -0000 On Sun, 4 Dec 2011 11:47:53 -0400, David Bremner wrote: > From: David Bremner > > The output file is handled via positional arguments. There are > currently no "normal" options. > --- > notmuch-dump.c | 32 ++++++++++++++++++++------------ > 1 files changed, 20 insertions(+), 12 deletions(-) > > diff --git a/notmuch-dump.c b/notmuch-dump.c > index a490917..6fbdc81 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,34 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[]) > if (notmuch == NULL) > return 1; > > - argc--; argv++; /* skip subcommand argument */ > + char *output_file_name = NULL; > + int opt_index; > > - if (argc && strcmp (argv[0], "--") != 0) { > + notmuch_opt_desc_t options[] = { > + { "out-file", 'o', NOTMUCH_OPT_POSITION, 0, &output_file_name }, > + { 0, 0, 0, 0, 0 } > + }; > + > + opt_index = notmuch_parse_args (argc, argv, options, 1); > + > + if (opt_index < 0) { > + /* diagnostics already printed */ > + exit(1); return 1 rather than exit(1)? BR, Jani. > + } > + > + if (output_file_name) { > fprintf (stderr, "Warning: the output file argument of dump is deprecated.\n"); > - output = fopen (argv[0], "w"); > + output = fopen (output_file_name, "w"); > if (output == NULL) { > fprintf (stderr, "Error opening %s for writing: %s\n", > - argv[0], strerror (errno)); > + output_file_name, strerror (errno)); > return 1; > } > - argc--; > - argv++; > } > > - if (argc && strcmp (argv[0], "--") == 0){ > - argc--; > - argv++; > - } > > - 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.7.3 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch