mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-21 10:28:09 +01:00
cli: use designated initializers for opt desc
Several changes at once, just to not have to change the same lines several times over: - Use designated initializers to initialize opt desc arrays. - Only initialize the needed fields. - Remove arg_id (short options) as unused. - Replace opt_type and output_var with several type safe output variables, where the output variable being non-NULL determines the type. Introduce checks to ensure only one is set. The downside is some waste of const space per argument; this could be saved by retaining opt_type and using a union, but that's still pretty verbose. - Fix some variables due to the type safety. Mostly a good thing, but leads to some enums being changed to ints. This is pedantically correct, but somewhat annoying. We could also cast, but that defeats the purpose a bit. - Terminate the opt desc arrays using {}. The output variable type safety and the ability to add new fields for just some output types or arguments are the big wins. For example, if we wanted to add a variable to set when the argument is present, we could do so for just the arguments that need it. Beauty is in the eye of the beholder, but I think this looks nice when defining the arguments, and reduces some of the verbosity we have there.
This commit is contained in:
parent
d57da17fcd
commit
4a6721970a
18 changed files with 185 additions and 187 deletions
|
@ -22,12 +22,10 @@ _process_keyword_arg (const notmuch_opt_desc_t *arg_desc, char next, const char
|
|||
|
||||
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++;
|
||||
|
@ -43,15 +41,15 @@ static notmuch_bool_t
|
|||
_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);
|
||||
|
@ -67,7 +65,7 @@ _process_int_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg
|
|||
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;
|
||||
|
||||
|
@ -87,10 +85,35 @@ _process_string_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *
|
|||
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.
|
||||
|
@ -101,12 +124,10 @@ parse_position_arg (const char *arg_str, int pos_arg_index,
|
|||
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++;
|
||||
|
@ -138,9 +159,9 @@ parse_option (int argc, char **argv, const notmuch_opt_desc_t *options, int opt_
|
|||
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;
|
||||
}
|
||||
|
@ -163,36 +184,24 @@ parse_option (int argc, char **argv, const notmuch_opt_desc_t *options, int opt_
|
|||
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
|
||||
|
|
|
@ -3,17 +3,6 @@
|
|||
|
||||
#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
|
||||
|
@ -24,22 +13,21 @@ typedef struct notmuch_keyword {
|
|||
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;
|
||||
|
||||
|
|
|
@ -508,7 +508,7 @@ status_to_exit (notmuch_status_t status);
|
|||
|
||||
#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);
|
||||
|
||||
|
|
|
@ -36,10 +36,10 @@ notmuch_compact_command (notmuch_config_t *config, int argc, char *argv[])
|
|||
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);
|
||||
|
|
|
@ -166,24 +166,24 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])
|
|||
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);
|
||||
|
|
|
@ -369,7 +369,7 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
|
|||
|
||||
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;
|
||||
|
@ -377,18 +377,18 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
|
|||
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);
|
||||
|
|
|
@ -463,12 +463,12 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
|
|||
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);
|
||||
|
|
|
@ -959,12 +959,12 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
|
|||
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);
|
||||
|
|
|
@ -99,8 +99,8 @@ notmuch_reindex_command (notmuch_config_t *config, int argc, char *argv[])
|
|||
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);
|
||||
|
|
|
@ -705,20 +705,20 @@ notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[])
|
|||
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);
|
||||
|
|
|
@ -227,7 +227,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
|
|||
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;
|
||||
|
@ -247,20 +247,20 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
|
|||
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);
|
||||
|
|
|
@ -51,17 +51,17 @@ typedef enum {
|
|||
|
||||
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 {
|
||||
|
@ -786,18 +786,18 @@ static search_context_t search_context = {
|
|||
};
|
||||
|
||||
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
|
||||
|
@ -807,25 +807,25 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
|
|||
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;
|
||||
|
@ -873,23 +873,23 @@ notmuch_address_command (notmuch_config_t *config, int argc, char *argv[])
|
|||
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);
|
||||
|
|
|
@ -1093,23 +1093,23 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
|
|||
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);
|
||||
|
|
|
@ -197,7 +197,7 @@ notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[])
|
|||
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;
|
||||
|
||||
|
@ -209,11 +209,11 @@ notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[])
|
|||
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);
|
||||
|
|
22
notmuch.c
22
notmuch.c
|
@ -47,13 +47,13 @@ static int
|
|||
_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
|
||||
|
@ -82,8 +82,8 @@ int notmuch_minimal_options (const char *subcommand_name,
|
|||
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);
|
||||
|
@ -405,15 +405,15 @@ main (int argc, char *argv[])
|
|||
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 ();
|
||||
|
|
|
@ -9,25 +9,26 @@ int main(int argc, char **argv){
|
|||
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);
|
||||
|
||||
|
|
|
@ -44,17 +44,17 @@ int
|
|||
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);
|
||||
|
|
|
@ -116,10 +116,10 @@ random_utf8_string (void *ctx, size_t char_count)
|
|||
|
||||
/* 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))
|
||||
|
@ -140,7 +140,7 @@ main (int argc, char **argv)
|
|||
|
||||
void *ctx = talloc_new (NULL);
|
||||
|
||||
char *config_path = NULL;
|
||||
const char *config_path = NULL;
|
||||
notmuch_config_t *config;
|
||||
notmuch_database_t *notmuch;
|
||||
|
||||
|
@ -155,13 +155,13 @@ main (int argc, char **argv)
|
|||
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);
|
||||
|
|
Loading…
Reference in a new issue