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 08154429E21 for ; Sun, 13 Nov 2011 14:47:36 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" 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 ybjKceXU+GKr for ; Sun, 13 Nov 2011 14:47:35 -0800 (PST) Received: from mail-bw0-f53.google.com (mail-bw0-f53.google.com [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 4278D431FB6 for ; Sun, 13 Nov 2011 14:47:35 -0800 (PST) Received: by mail-bw0-f53.google.com with SMTP id q10so6354254bka.26 for ; Sun, 13 Nov 2011 14:47:34 -0800 (PST) Received: by 10.205.138.140 with SMTP id is12mr8846828bkc.139.1321224454791; Sun, 13 Nov 2011 14:47:34 -0800 (PST) Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi. [80.220.92.23]) by mx.google.com with ESMTPS id q6sm28076066bka.6.2011.11.13.14.47.32 (version=SSLv3 cipher=OTHER); Sun, 13 Nov 2011 14:47:33 -0800 (PST) From: Jani Nikula To: notmuch@notmuchmail.org, david@tethera.net Subject: [PATCH 1/6] cli: notmuch new: use getopt_long for parsing command line options Date: Mon, 14 Nov 2011 00:47:21 +0200 Message-Id: <828501bd94ae962dda51fd470cb248921e1c6b79.1321223343.git.jani@nikula.org> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: References: In-Reply-To: References: 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, 13 Nov 2011 22:47:36 -0000 Signed-off-by: Jani Nikula --- notmuch-client.h | 1 + notmuch-new.c | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/notmuch-client.h b/notmuch-client.h index b50cb38..eb16f0d 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include diff --git a/notmuch-new.c b/notmuch-new.c index 81a9350..145aa64 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -815,16 +815,26 @@ notmuch_new_command (void *ctx, int argc, char *argv[]) add_files_state.verbose = 0; add_files_state.output_is_a_tty = isatty (fileno (stdout)); - argc--; argv++; /* skip subcommand argument */ + while (1) { + int opt; + static struct option options[] = { + { "verbose", no_argument, NULL, 0 }, + { NULL, 0, NULL, 0 }, + }; + + opt = getopt_long (argc, argv, "", options, NULL); + if (opt == -1) + break; - for (i = 0; i < argc && argv[i][0] == '-'; i++) { - if (STRNCMP_LITERAL (argv[i], "--verbose") == 0) { + switch (opt) { + case 0: add_files_state.verbose = 1; - } else { - fprintf (stderr, "Unrecognized option: %s\n", argv[i]); + break; + case '?': return 1; } } + config = notmuch_config_open (ctx, NULL, NULL); if (config == NULL) return 1; -- 1.7.5.4