while (keywords->name) {
if (strcmp (arg_str, keywords->name) == 0) {
- if (arg_desc->output_var) {
- if (arg_desc->opt_type == NOTMUCH_OPT_KEYWORD_FLAGS)
- *((int *)arg_desc->output_var) |= keywords->value;
- else
- *((int *)arg_desc->output_var) = keywords->value;
- }
+ if (arg_desc->opt_flags)
+ *arg_desc->opt_flags |= keywords->value;
+ else
+ *arg_desc->opt_keyword = keywords->value;
return TRUE;
}
keywords++;
_process_boolean_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) {
if (next == '\0') {
- *((notmuch_bool_t *)arg_desc->output_var) = TRUE;
+ *arg_desc->opt_bool = TRUE;
return TRUE;
}
if (strcmp (arg_str, "false") == 0) {
- *((notmuch_bool_t *)arg_desc->output_var) = FALSE;
+ *arg_desc->opt_bool = FALSE;
return TRUE;
}
if (strcmp (arg_str, "true") == 0) {
- *((notmuch_bool_t *)arg_desc->output_var) = TRUE;
+ *arg_desc->opt_bool = TRUE;
return TRUE;
}
fprintf (stderr, "Unknown argument \"%s\" for (boolean) option \"%s\".\n", arg_str, arg_desc->name);
return FALSE;
}
- *((int *)arg_desc->output_var) = strtol (arg_str, &endptr, 10);
+ *arg_desc->opt_int = strtol (arg_str, &endptr, 10);
if (*endptr == '\0')
return TRUE;
fprintf (stderr, "String argument for option \"%s\" must be non-empty.\n", arg_desc->name);
return FALSE;
}
- *((const char **)arg_desc->output_var) = arg_str;
+ *arg_desc->opt_string = arg_str;
return TRUE;
}
+/* Return number of non-NULL opt_* fields in opt_desc. */
+static int _opt_set_count (const notmuch_opt_desc_t *opt_desc)
+{
+ return
+ !!opt_desc->opt_inherit +
+ !!opt_desc->opt_bool +
+ !!opt_desc->opt_int +
+ !!opt_desc->opt_keyword +
+ !!opt_desc->opt_flags +
+ !!opt_desc->opt_string +
+ !!opt_desc->opt_position;
+}
+
+/* Return TRUE if opt_desc is valid. */
+static notmuch_bool_t _opt_valid (const notmuch_opt_desc_t *opt_desc)
+{
+ int n = _opt_set_count (opt_desc);
+
+ if (n > 1)
+ INTERNAL_ERROR ("more than one non-NULL opt_* field for argument \"%s\"",
+ opt_desc->name);
+
+ return n > 0;
+}
+
/*
Search for the {pos_arg_index}th position argument, return FALSE if
that does not exist.
const notmuch_opt_desc_t *arg_desc) {
int pos_arg_counter = 0;
- while (arg_desc->opt_type != NOTMUCH_OPT_END){
- if (arg_desc->opt_type == NOTMUCH_OPT_POSITION) {
+ while (_opt_valid (arg_desc)) {
+ if (arg_desc->opt_position) {
if (pos_arg_counter == pos_arg_index) {
- if (arg_desc->output_var) {
- *((const char **)arg_desc->output_var) = arg_str;
- }
+ *arg_desc->opt_position = arg_str;
return TRUE;
}
pos_arg_counter++;
if (opt_index < argc - 1 && strncmp (argv[opt_index + 1], "--", 2) != 0)
next_arg = argv[opt_index + 1];
- for (try = options; try->opt_type != NOTMUCH_OPT_END; try++) {
- if (try->opt_type == NOTMUCH_OPT_INHERIT) {
- int new_index = parse_option (argc, argv, try->output_var, opt_index);
+ for (try = options; _opt_valid (try); try++) {
+ if (try->opt_inherit) {
+ int new_index = parse_option (argc, argv, try->opt_inherit, opt_index);
if (new_index >= 0)
return new_index;
}
if (next != '=' && next != ':' && next != '\0')
continue;
- if (next == '\0' && next_arg != NULL && try->opt_type != NOTMUCH_OPT_BOOLEAN) {
+ if (next == '\0' && next_arg != NULL && ! try->opt_bool) {
next = ' ';
value = next_arg;
opt_index ++;
}
- if (try->output_var == NULL)
- INTERNAL_ERROR ("output pointer NULL for option %s", try->name);
-
notmuch_bool_t opt_status = FALSE;
- switch (try->opt_type) {
- case NOTMUCH_OPT_KEYWORD:
- case NOTMUCH_OPT_KEYWORD_FLAGS:
+ if (try->opt_keyword || try->opt_flags)
opt_status = _process_keyword_arg (try, next, value);
- break;
- case NOTMUCH_OPT_BOOLEAN:
+ else if (try->opt_bool)
opt_status = _process_boolean_arg (try, next, value);
- break;
- case NOTMUCH_OPT_INT:
+ else if (try->opt_int)
opt_status = _process_int_arg (try, next, value);
- break;
- case NOTMUCH_OPT_STRING:
+ else if (try->opt_string)
opt_status = _process_string_arg (try, next, value);
- break;
- case NOTMUCH_OPT_POSITION:
- case NOTMUCH_OPT_END:
- default:
- INTERNAL_ERROR ("unknown or unhandled option type %d", try->opt_type);
- /*UNREACHED*/
- }
+ else
+ INTERNAL_ERROR ("unknown or unhandled option \"%s\"", try->name);
+
if (opt_status)
return opt_index+1;
else
#include "notmuch.h"
-enum notmuch_opt_type {
- NOTMUCH_OPT_END = 0,
- NOTMUCH_OPT_INHERIT, /* another options table */
- NOTMUCH_OPT_BOOLEAN, /* --verbose */
- NOTMUCH_OPT_INT, /* --frob=8 */
- NOTMUCH_OPT_KEYWORD, /* --format=raw|json|text */
- NOTMUCH_OPT_KEYWORD_FLAGS, /* the above with values OR'd together */
- NOTMUCH_OPT_STRING, /* --file=/tmp/gnarf.txt */
- NOTMUCH_OPT_POSITION /* notmuch dump pos_arg */
-};
-
/*
* Describe one of the possibilities for a keyword option
* 'value' will be copied to the output variable
int value;
} notmuch_keyword_t;
-/*
- * Describe one option.
- *
- * First two parameters are mandatory.
- *
- * name is mandatory _except_ for positional arguments.
- *
- * arg_id is currently unused, but could define short arguments.
- *
- * keywords is a (possibly NULL) pointer to an array of keywords
- */
+/* Describe one option. */
typedef struct notmuch_opt_desc {
- enum notmuch_opt_type opt_type;
- void *output_var;
+ /* One and only one of opt_* must be set. */
+ const struct notmuch_opt_desc *opt_inherit;
+ notmuch_bool_t *opt_bool;
+ int *opt_int;
+ int *opt_keyword;
+ int *opt_flags;
+ const char **opt_string;
+ const char **opt_position;
+
+ /* Must be set except for opt_inherit and opt_position. */
const char *name;
- int arg_id;
+
+ /* Must be set for opt_keyword and opt_flags. */
const struct notmuch_keyword *keywords;
} notmuch_opt_desc_t;
#include "command-line-arguments.h"
-extern char *notmuch_requested_db_uuid;
+extern const char *notmuch_requested_db_uuid;
extern const notmuch_opt_desc_t notmuch_shared_options [];
void notmuch_exit_if_unmatched_db_uuid (notmuch_database_t *notmuch);
int opt_index;
notmuch_opt_desc_t options[] = {
- { NOTMUCH_OPT_STRING, &backup_path, "backup", 0, 0 },
- { NOTMUCH_OPT_BOOLEAN, &quiet, "quiet", 'q', 0 },
- { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 },
- { 0, 0, 0, 0, 0}
+ { .opt_string = &backup_path, .name = "backup" },
+ { .opt_bool = &quiet, .name = "quiet" },
+ { .opt_inherit = notmuch_shared_options },
+ { }
};
opt_index = parse_arguments (argc, argv, options, 1);
notmuch_bool_t batch = FALSE;
notmuch_bool_t print_lastmod = FALSE;
FILE *input = stdin;
- char *input_file_name = NULL;
+ const char *input_file_name = NULL;
int ret;
notmuch_opt_desc_t options[] = {
- { NOTMUCH_OPT_KEYWORD, &output, "output", 'o',
+ { .opt_keyword = &output, .name = "output", .keywords =
(notmuch_keyword_t []){ { "threads", OUTPUT_THREADS },
{ "messages", OUTPUT_MESSAGES },
{ "files", OUTPUT_FILES },
{ 0, 0 } } },
- { NOTMUCH_OPT_KEYWORD, &exclude, "exclude", 'x',
+ { .opt_keyword = &exclude, .name = "exclude", .keywords =
(notmuch_keyword_t []){ { "true", EXCLUDE_TRUE },
{ "false", EXCLUDE_FALSE },
{ 0, 0 } } },
- { NOTMUCH_OPT_BOOLEAN, &print_lastmod, "lastmod", 'l', 0 },
- { NOTMUCH_OPT_BOOLEAN, &batch, "batch", 0, 0 },
- { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },
- { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 },
- { 0, 0, 0, 0, 0 }
+ { .opt_bool = &print_lastmod, .name = "lastmod" },
+ { .opt_bool = &batch, .name = "batch" },
+ { .opt_string = &input_file_name, .name = "input" },
+ { .opt_inherit = notmuch_shared_options },
+ { }
};
opt_index = parse_arguments (argc, argv, options, 1);
notmuch_exit_if_unmatched_db_uuid (notmuch);
- char *output_file_name = NULL;
+ const char *output_file_name = NULL;
int opt_index;
int output_format = DUMP_FORMAT_BATCH_TAG;
notmuch_bool_t gzip_output = 0;
notmuch_opt_desc_t options[] = {
- { NOTMUCH_OPT_KEYWORD, &output_format, "format", 'f',
+ { .opt_keyword = &output_format, .name = "format", .keywords =
(notmuch_keyword_t []){ { "sup", DUMP_FORMAT_SUP },
{ "batch-tag", DUMP_FORMAT_BATCH_TAG },
{ 0, 0 } } },
- { NOTMUCH_OPT_KEYWORD_FLAGS, &include, "include", 'I',
+ { .opt_flags = &include, .name = "include", .keywords =
(notmuch_keyword_t []){ { "config", DUMP_INCLUDE_CONFIG },
{ "properties", DUMP_INCLUDE_PROPERTIES },
{ "tags", DUMP_INCLUDE_TAGS} } },
- { NOTMUCH_OPT_STRING, &output_file_name, "output", 'o', 0 },
- { NOTMUCH_OPT_BOOLEAN, &gzip_output, "gzip", 'z', 0 },
- { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 },
- { 0, 0, 0, 0, 0 }
+ { .opt_string = &output_file_name, .name = "output" },
+ { .opt_bool = &gzip_output, .name = "gzip" },
+ { .opt_inherit = notmuch_shared_options },
+ { }
};
opt_index = parse_arguments (argc, argv, options, 1);
unsigned int i;
notmuch_opt_desc_t options[] = {
- { NOTMUCH_OPT_STRING, &folder, "folder", 0, 0 },
- { NOTMUCH_OPT_BOOLEAN, &create_folder, "create-folder", 0, 0 },
- { NOTMUCH_OPT_BOOLEAN, &keep, "keep", 0, 0 },
- { NOTMUCH_OPT_BOOLEAN, &no_hooks, "no-hooks", 'n', 0 },
- { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 },
- { NOTMUCH_OPT_END, 0, 0, 0, 0 }
+ { .opt_string = &folder, .name = "folder" },
+ { .opt_bool = &create_folder, .name = "create-folder" },
+ { .opt_bool = &keep, .name = "keep" },
+ { .opt_bool = &no_hooks, .name = "no-hooks" },
+ { .opt_inherit = notmuch_shared_options },
+ { }
};
opt_index = parse_arguments (argc, argv, options, 1);
notmuch_status_t status;
notmuch_opt_desc_t options[] = {
- { NOTMUCH_OPT_BOOLEAN, &quiet, "quiet", 'q', 0 },
- { NOTMUCH_OPT_BOOLEAN, &verbose, "verbose", 'v', 0 },
- { NOTMUCH_OPT_BOOLEAN, &add_files_state.debug, "debug", 'd', 0 },
- { NOTMUCH_OPT_BOOLEAN, &no_hooks, "no-hooks", 'n', 0 },
- { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 },
- { 0, 0, 0, 0, 0 }
+ { .opt_bool = &quiet, .name = "quiet" },
+ { .opt_bool = &verbose, .name = "verbose" },
+ { .opt_bool = &add_files_state.debug, .name = "debug" },
+ { .opt_bool = &no_hooks, .name = "no-hooks" },
+ { .opt_inherit = notmuch_shared_options },
+ { }
};
opt_index = parse_arguments (argc, argv, options, 1);
sigaction (SIGINT, &action, NULL);
notmuch_opt_desc_t options[] = {
- { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 },
- { 0, 0, 0, 0, 0 }
+ { .opt_inherit = notmuch_shared_options },
+ { }
};
opt_index = parse_arguments (argc, argv, options, 1);
int reply_all = TRUE;
notmuch_opt_desc_t options[] = {
- { NOTMUCH_OPT_KEYWORD, &format, "format", 'f',
+ { .opt_keyword = &format, .name = "format", .keywords =
(notmuch_keyword_t []){ { "default", FORMAT_DEFAULT },
{ "json", FORMAT_JSON },
{ "sexp", FORMAT_SEXP },
{ "headers-only", FORMAT_HEADERS_ONLY },
{ 0, 0 } } },
- { NOTMUCH_OPT_INT, ¬much_format_version, "format-version", 0, 0 },
- { NOTMUCH_OPT_KEYWORD, &reply_all, "reply-to", 'r',
+ { .opt_int = ¬much_format_version, .name = "format-version" },
+ { .opt_keyword = &reply_all, .name = "reply-to", .keywords =
(notmuch_keyword_t []){ { "all", TRUE },
{ "sender", FALSE },
{ 0, 0 } } },
- { NOTMUCH_OPT_BOOLEAN, ¶ms.crypto.decrypt, "decrypt", 'd', 0 },
- { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 },
- { 0, 0, 0, 0, 0 }
+ { .opt_bool = ¶ms.crypto.decrypt, .name = "decrypt" },
+ { .opt_inherit = notmuch_shared_options },
+ { }
};
opt_index = parse_arguments (argc, argv, options, 1);
tag_op_flag_t flags = 0;
tag_op_list_t *tag_ops;
- char *input_file_name = NULL;
+ const char *input_file_name = NULL;
const char *name_for_error = NULL;
gzFile input = NULL;
char *line = NULL;
flags |= TAG_FLAG_MAILDIR_SYNC;
notmuch_opt_desc_t options[] = {
- { NOTMUCH_OPT_KEYWORD, &input_format, "format", 'f',
+ { .opt_keyword = &input_format, .name = "format", .keywords =
(notmuch_keyword_t []){ { "auto", DUMP_FORMAT_AUTO },
{ "batch-tag", DUMP_FORMAT_BATCH_TAG },
{ "sup", DUMP_FORMAT_SUP },
{ 0, 0 } } },
- { NOTMUCH_OPT_KEYWORD_FLAGS, &include, "include", 'I',
+ { .opt_flags = &include, .name = "include", .keywords =
(notmuch_keyword_t []){ { "config", DUMP_INCLUDE_CONFIG },
{ "properties", DUMP_INCLUDE_PROPERTIES },
{ "tags", DUMP_INCLUDE_TAGS} } },
- { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },
- { NOTMUCH_OPT_BOOLEAN, &accumulate, "accumulate", 'a', 0 },
- { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 },
- { 0, 0, 0, 0, 0 }
+ { .opt_string = &input_file_name, .name = "input" },
+ { .opt_bool = &accumulate, .name = "accumulate" },
+ { .opt_inherit = notmuch_shared_options },
+ { }
};
opt_index = parse_arguments (argc, argv, options, 1);
typedef struct {
notmuch_database_t *notmuch;
- format_sel_t format_sel;
+ int format_sel;
sprinter_t *format;
- notmuch_exclude_t exclude;
+ int exclude;
notmuch_query_t *query;
- notmuch_sort_t sort;
- output_t output;
+ int sort;
+ int output;
int offset;
int limit;
int dupe;
GHashTable *addresses;
- dedup_t dedup;
+ int dedup;
} search_context_t;
typedef struct {
};
static const notmuch_opt_desc_t common_options[] = {
- { NOTMUCH_OPT_KEYWORD, &search_context.sort, "sort", 's',
+ { .opt_keyword = &search_context.sort, .name = "sort", .keywords =
(notmuch_keyword_t []){ { "oldest-first", NOTMUCH_SORT_OLDEST_FIRST },
{ "newest-first", NOTMUCH_SORT_NEWEST_FIRST },
{ 0, 0 } } },
- { NOTMUCH_OPT_KEYWORD, &search_context.format_sel, "format", 'f',
+ { .opt_keyword = &search_context.format_sel, .name = "format", .keywords =
(notmuch_keyword_t []){ { "json", NOTMUCH_FORMAT_JSON },
{ "sexp", NOTMUCH_FORMAT_SEXP },
{ "text", NOTMUCH_FORMAT_TEXT },
{ "text0", NOTMUCH_FORMAT_TEXT0 },
{ 0, 0 } } },
- { NOTMUCH_OPT_INT, ¬much_format_version, "format-version", 0, 0 },
- { 0, 0, 0, 0, 0 }
+ { .opt_int = ¬much_format_version, .name = "format-version" },
+ { }
};
int
int opt_index, ret;
notmuch_opt_desc_t options[] = {
- { NOTMUCH_OPT_KEYWORD, &ctx->output, "output", 'o',
+ { .opt_keyword = &ctx->output, .name = "output", .keywords =
(notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY },
{ "threads", OUTPUT_THREADS },
{ "messages", OUTPUT_MESSAGES },
{ "files", OUTPUT_FILES },
{ "tags", OUTPUT_TAGS },
{ 0, 0 } } },
- { NOTMUCH_OPT_KEYWORD, &ctx->exclude, "exclude", 'x',
+ { .opt_keyword = &ctx->exclude, .name = "exclude", .keywords =
(notmuch_keyword_t []){ { "true", NOTMUCH_EXCLUDE_TRUE },
{ "false", NOTMUCH_EXCLUDE_FALSE },
{ "flag", NOTMUCH_EXCLUDE_FLAG },
{ "all", NOTMUCH_EXCLUDE_ALL },
{ 0, 0 } } },
- { NOTMUCH_OPT_INT, &ctx->offset, "offset", 'O', 0 },
- { NOTMUCH_OPT_INT, &ctx->limit, "limit", 'L', 0 },
- { NOTMUCH_OPT_INT, &ctx->dupe, "duplicate", 'D', 0 },
- { NOTMUCH_OPT_INHERIT, (void *) &common_options, NULL, 0, 0 },
- { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 },
- { 0, 0, 0, 0, 0 }
+ { .opt_int = &ctx->offset, .name = "offset" },
+ { .opt_int = &ctx->limit, .name = "limit" },
+ { .opt_int = &ctx->dupe, .name = "duplicate" },
+ { .opt_inherit = common_options },
+ { .opt_inherit = notmuch_shared_options },
+ { }
};
ctx->output = OUTPUT_SUMMARY;
int opt_index, ret;
notmuch_opt_desc_t options[] = {
- { NOTMUCH_OPT_KEYWORD_FLAGS, &ctx->output, "output", 'o',
+ { .opt_flags = &ctx->output, .name = "output", .keywords =
(notmuch_keyword_t []){ { "sender", OUTPUT_SENDER },
{ "recipients", OUTPUT_RECIPIENTS },
{ "count", OUTPUT_COUNT },
{ 0, 0 } } },
- { NOTMUCH_OPT_KEYWORD, &ctx->exclude, "exclude", 'x',
+ { .opt_keyword = &ctx->exclude, .name = "exclude", .keywords =
(notmuch_keyword_t []){ { "true", NOTMUCH_EXCLUDE_TRUE },
{ "false", NOTMUCH_EXCLUDE_FALSE },
{ 0, 0 } } },
- { NOTMUCH_OPT_KEYWORD, &ctx->dedup, "deduplicate", 'D',
+ { .opt_keyword = &ctx->dedup, .name = "deduplicate", .keywords =
(notmuch_keyword_t []){ { "no", DEDUP_NONE },
{ "mailbox", DEDUP_MAILBOX },
{ "address", DEDUP_ADDRESS },
{ 0, 0 } } },
- { NOTMUCH_OPT_INHERIT, (void *) &common_options, NULL, 0, 0 },
- { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 },
- { 0, 0, 0, 0, 0 }
+ { .opt_inherit = common_options },
+ { .opt_inherit = notmuch_shared_options },
+ { }
};
opt_index = parse_arguments (argc, argv, options, 1);
notmuch_bool_t single_message;
notmuch_opt_desc_t options[] = {
- { NOTMUCH_OPT_KEYWORD, &format, "format", 'f',
+ { .opt_keyword = &format, .name = "format", .keywords =
(notmuch_keyword_t []){ { "json", NOTMUCH_FORMAT_JSON },
{ "text", NOTMUCH_FORMAT_TEXT },
{ "sexp", NOTMUCH_FORMAT_SEXP },
{ "mbox", NOTMUCH_FORMAT_MBOX },
{ "raw", NOTMUCH_FORMAT_RAW },
{ 0, 0 } } },
- { NOTMUCH_OPT_INT, ¬much_format_version, "format-version", 0, 0 },
- { NOTMUCH_OPT_BOOLEAN, &exclude, "exclude", 'x', 0 },
- { NOTMUCH_OPT_BOOLEAN, &entire_thread, "entire-thread", 't', 0 },
- { NOTMUCH_OPT_INT, ¶ms.part, "part", 'p', 0 },
- { NOTMUCH_OPT_BOOLEAN, ¶ms.crypto.decrypt, "decrypt", 'd', 0 },
- { NOTMUCH_OPT_BOOLEAN, ¶ms.crypto.verify, "verify", 'v', 0 },
- { NOTMUCH_OPT_BOOLEAN, ¶ms.output_body, "body", 'b', 0 },
- { NOTMUCH_OPT_BOOLEAN, ¶ms.include_html, "include-html", 0, 0 },
- { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 },
- { 0, 0, 0, 0, 0 }
+ { .opt_int = ¬much_format_version, .name = "format-version" },
+ { .opt_bool = &exclude, .name = "exclude" },
+ { .opt_bool = &entire_thread, .name = "entire-thread" },
+ { .opt_int = ¶ms.part, .name = "part" },
+ { .opt_bool = ¶ms.crypto.decrypt, .name = "decrypt" },
+ { .opt_bool = ¶ms.crypto.verify, .name = "verify" },
+ { .opt_bool = ¶ms.output_body, .name = "body" },
+ { .opt_bool = ¶ms.include_html, .name = "include-html" },
+ { .opt_inherit = notmuch_shared_options },
+ { }
};
opt_index = parse_arguments (argc, argv, options, 1);
notmuch_bool_t batch = FALSE;
notmuch_bool_t remove_all = FALSE;
FILE *input = stdin;
- char *input_file_name = NULL;
+ const char *input_file_name = NULL;
int opt_index;
int ret;
sigaction (SIGINT, &action, NULL);
notmuch_opt_desc_t options[] = {
- { NOTMUCH_OPT_BOOLEAN, &batch, "batch", 0, 0 },
- { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },
- { NOTMUCH_OPT_BOOLEAN, &remove_all, "remove-all", 0, 0 },
- { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 },
- { 0, 0, 0, 0, 0 }
+ { .opt_bool = &batch, .name = "batch" },
+ { .opt_string = &input_file_name, .name = "input" },
+ { .opt_bool = &remove_all, .name = "remove-all" },
+ { .opt_inherit = notmuch_shared_options },
+ { }
};
opt_index = parse_arguments (argc, argv, options, 1);
_help_for (const char *topic);
static notmuch_bool_t print_version = FALSE, print_help = FALSE;
-char *notmuch_requested_db_uuid = NULL;
+const char *notmuch_requested_db_uuid = NULL;
const notmuch_opt_desc_t notmuch_shared_options [] = {
- { NOTMUCH_OPT_BOOLEAN, &print_version, "version", 'v', 0 },
- { NOTMUCH_OPT_BOOLEAN, &print_help, "help", 'h', 0 },
- { NOTMUCH_OPT_STRING, ¬much_requested_db_uuid, "uuid", 'u', 0 },
- {0, 0, 0, 0, 0}
+ { .opt_bool = &print_version, .name = "version" },
+ { .opt_bool = &print_help, .name = "help" },
+ { .opt_string = ¬much_requested_db_uuid, .name = "uuid" },
+ { }
};
/* any subcommand wanting to support these options should call
int opt_index;
notmuch_opt_desc_t options[] = {
- { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 },
- { 0, 0, 0, 0, 0 }
+ { .opt_inherit = notmuch_shared_options },
+ { }
};
opt_index = parse_arguments (argc, argv, options, 1);
char *talloc_report;
const char *command_name = NULL;
command_t *command;
- char *config_file_name = NULL;
+ const char *config_file_name = NULL;
notmuch_config_t *config = NULL;
int opt_index;
int ret;
notmuch_opt_desc_t options[] = {
- { NOTMUCH_OPT_STRING, &config_file_name, "config", 'c', 0 },
- { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 },
- { 0, 0, 0, 0, 0 }
+ { .opt_string = &config_file_name, .name = "config" },
+ { .opt_inherit = notmuch_shared_options },
+ { }
};
talloc_enable_null_tracking ();
int kw_val=0;
int fl_val=0;
int int_val=0;
- char *pos_arg1=NULL;
- char *pos_arg2=NULL;
- char *string_val=NULL;
+ const char *pos_arg1=NULL;
+ const char *pos_arg2=NULL;
+ const char *string_val=NULL;
notmuch_opt_desc_t options[] = {
- { NOTMUCH_OPT_KEYWORD, &kw_val, "keyword", 'k',
+ { .opt_keyword = &kw_val, .name = "keyword", .keywords =
(notmuch_keyword_t []){ { "one", 1 },
{ "two", 2 },
{ 0, 0 } } },
- { NOTMUCH_OPT_KEYWORD_FLAGS, &fl_val, "flag", 'f',
+ { .opt_flags = &fl_val, .name = "flag", .keywords =
(notmuch_keyword_t []){ { "one", 1 << 0},
{ "two", 1 << 1 },
{ "three", 1 << 2 },
{ 0, 0 } } },
- { NOTMUCH_OPT_INT, &int_val, "int", 'i', 0},
- { NOTMUCH_OPT_STRING, &string_val, "string", 's', 0},
- { NOTMUCH_OPT_POSITION, &pos_arg1, 0,0, 0},
- { NOTMUCH_OPT_POSITION, &pos_arg2, 0,0, 0},
- { 0, 0, 0, 0, 0 } };
+ { .opt_int = &int_val, .name = "int" },
+ { .opt_string = &string_val, .name = "string" },
+ { .opt_position = &pos_arg1 },
+ { .opt_position = &pos_arg2 },
+ { }
+ };
opt_index = parse_arguments(argc, argv, options, 1);
main (int argc, char **argv)
{
- enum direction dir = DECODE;
+ int dir = DECODE;
int omit_newline = FALSE;
notmuch_opt_desc_t options[] = {
- { NOTMUCH_OPT_KEYWORD, &dir, "direction", 'd',
+ { .opt_keyword = &dir, .name = "direction", .keywords =
(notmuch_keyword_t []){ { "encode", ENCODE },
{ "decode", DECODE },
{ 0, 0 } } },
- { NOTMUCH_OPT_BOOLEAN, &omit_newline, "omit-newline", 'n', 0 },
- { NOTMUCH_OPT_BOOLEAN, &inplace, "in-place", 'i', 0 },
- { 0, 0, 0, 0, 0 }
+ { .opt_bool = &omit_newline, .name = "omit-newline" },
+ { .opt_bool = &inplace, .name = "in-place" },
+ { }
};
int opt_index = parse_arguments (argc, argv, options, 1);
/* stubs since we cannot link with notmuch.o */
const notmuch_opt_desc_t notmuch_shared_options[] = {
- { 0, 0, 0, 0, 0 }
+ { }
};
-char *notmuch_requested_db_uuid = NULL;
+const char *notmuch_requested_db_uuid = NULL;
void
notmuch_process_shared_options (unused (const char *dummy))
void *ctx = talloc_new (NULL);
- char *config_path = NULL;
+ const char *config_path = NULL;
notmuch_config_t *config;
notmuch_database_t *notmuch;
int seed = 734569;
notmuch_opt_desc_t options[] = {
- { NOTMUCH_OPT_STRING, &config_path, "config-path", 'c', 0 },
- { NOTMUCH_OPT_INT, &num_messages, "num-messages", 'n', 0 },
- { NOTMUCH_OPT_INT, &max_tags, "max-tags", 'm', 0 },
- { NOTMUCH_OPT_INT, &message_id_len, "message-id-len", 'M', 0 },
- { NOTMUCH_OPT_INT, &tag_len, "tag-len", 't', 0 },
- { NOTMUCH_OPT_INT, &seed, "seed", 's', 0 },
- { 0, 0, 0, 0, 0 }
+ { .opt_string = &config_path, .name = "config-path" },
+ { .opt_int = &num_messages, .name = "num-messages" },
+ { .opt_int = &max_tags, .name = "max-tags" },
+ { .opt_int = &message_id_len, .name = "message-id-len" },
+ { .opt_int = &tag_len, .name = "tag-len" },
+ { .opt_int = &seed, .name = "seed" },
+ { }
};
int opt_index = parse_arguments (argc, argv, options, 1);