argument parsing refactoring, round 2
David Bremner
david at tethera.net
Mon Apr 6 05:22:34 PDT 2015
Thanks to Mark for pointing out on IRC that the previous version had problems linking the test suite helpers. That's fixed here by adding a couple stubs.
Here's the diff, roughly with the previous version (actually the first
hunk is with a slightly later version, where I fixed one bug and
introduced another).
diff --git a/notmuch-config.c b/notmuch-config.c
index 568b3dc..f2cd6a8 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -885,9 +885,9 @@ notmuch_config_command (notmuch_config_t *config, int argc, char *argv[])
notmuch_process_shared_options (argv[0]);
- /* skip subcommand argument */
- argc-= opt_index+1;
- argv+= opt_index+1;
+ /* skip at least subcommand argument */
+ argc-= opt_index;
+ argv+= opt_index;
if (argc < 1) {
fprintf (stderr, "Error: notmuch config requires at least one argument.\n");
diff --git a/notmuch-setup.c b/notmuch-setup.c
index 5fc6e25..6a020dc 100644
--- a/notmuch-setup.c
+++ b/notmuch-setup.c
@@ -155,7 +155,7 @@ notmuch_setup_command (notmuch_config_t *config,
if (opt_index < 0)
return EXIT_FAILURE;
- notmuch_process_shared_options (argv[0]);
+ notmuch_process_shared_options ("setup");
if (notmuch_config_is_new (config))
welcome_message_pre_setup ();
diff --git a/test/random-corpus.c b/test/random-corpus.c
index 790193d..6c467bb 100644
--- a/test/random-corpus.c
+++ b/test/random-corpus.c
@@ -114,6 +114,15 @@ random_utf8_string (void *ctx, size_t char_count)
return buf;
}
+/* stubs since we cannot link with notmuch.o */
+const notmuch_opt_desc_t notmuch_shared_options[] = {
+ { 0, 0, 0, 0, 0 }
+};
+
+void
+notmuch_process_shared_options (unused (const char *dummy))
+{
+}
int
main (int argc, char **argv)
More information about the notmuch
mailing list