X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=notmuch-search.c;h=a96f07d53eab5fa073a539286c96f57213ebadbe;hp=621862289f043ba4e77b488a176e34937aaa3e3d;hb=3fbb518335fe2271a31a6c4779affa4df42cf203;hpb=102f58d7a4532aa5f7a21edfd24758be864ea8d4 diff --git a/notmuch-search.c b/notmuch-search.c index 62186228..a96f07d5 100644 --- a/notmuch-search.c +++ b/notmuch-search.c @@ -283,16 +283,9 @@ do_search_tags (notmuch_database_t *notmuch, return 0; } -enum { - EXCLUDE_TRUE, - EXCLUDE_FALSE, - EXCLUDE_FLAG, -}; - int -notmuch_search_command (void *ctx, int argc, char *argv[]) +notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]) { - notmuch_config_t *config; notmuch_database_t *notmuch; notmuch_query_t *query; char *query_str; @@ -302,11 +295,15 @@ notmuch_search_command (void *ctx, int argc, char *argv[]) output_t output = OUTPUT_SUMMARY; int offset = 0; int limit = -1; /* unlimited */ - int exclude = EXCLUDE_TRUE; + notmuch_exclude_t exclude = NOTMUCH_EXCLUDE_TRUE; unsigned int i; - enum { NOTMUCH_FORMAT_JSON, NOTMUCH_FORMAT_TEXT, NOTMUCH_FORMAT_SEXP } - format_sel = NOTMUCH_FORMAT_TEXT; + enum { + NOTMUCH_FORMAT_JSON, + NOTMUCH_FORMAT_TEXT, + NOTMUCH_FORMAT_TEXT0, + NOTMUCH_FORMAT_SEXP + } format_sel = NOTMUCH_FORMAT_TEXT; notmuch_opt_desc_t options[] = { { NOTMUCH_OPT_KEYWORD, &sort, "sort", 's', @@ -317,7 +314,9 @@ notmuch_search_command (void *ctx, int argc, char *argv[]) (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 }, { NOTMUCH_OPT_KEYWORD, &output, "output", 'o', (notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY }, { "threads", OUTPUT_THREADS }, @@ -326,9 +325,10 @@ notmuch_search_command (void *ctx, int argc, char *argv[]) { "tags", OUTPUT_TAGS }, { 0, 0 } } }, { NOTMUCH_OPT_KEYWORD, &exclude, "exclude", 'x', - (notmuch_keyword_t []){ { "true", EXCLUDE_TRUE }, - { "false", EXCLUDE_FALSE }, - { "flag", EXCLUDE_FLAG }, + (notmuch_keyword_t []){ { "true", NOTMUCH_EXCLUDE_TRUE }, + { "false", NOTMUCH_EXCLUDE_FALSE }, + { "flag", NOTMUCH_EXCLUDE_FLAG }, + { "all", NOTMUCH_EXCLUDE_ALL }, { 0, 0 } } }, { NOTMUCH_OPT_INT, &offset, "offset", 'O', 0 }, { NOTMUCH_OPT_INT, &limit, "limit", 'L', 0 }, @@ -343,22 +343,27 @@ notmuch_search_command (void *ctx, int argc, char *argv[]) switch (format_sel) { case NOTMUCH_FORMAT_TEXT: - format = sprinter_text_create (ctx, stdout); + format = sprinter_text_create (config, stdout); + break; + case NOTMUCH_FORMAT_TEXT0: + if (output == OUTPUT_SUMMARY) { + fprintf (stderr, "Error: --format=text0 is not compatible with --output=summary.\n"); + return 1; + } + format = sprinter_text0_create (config, stdout); break; case NOTMUCH_FORMAT_JSON: - format = sprinter_json_create (ctx, stdout); + format = sprinter_json_create (config, stdout); break; case NOTMUCH_FORMAT_SEXP: - format = sprinter_sexp_create (ctx, stdout); + format = sprinter_sexp_create (config, stdout); break; default: /* this should never happen */ INTERNAL_ERROR("no output format selected"); } - config = notmuch_config_open (ctx, NULL, NULL); - if (config == NULL) - return 1; + notmuch_exit_if_unsupported_format (); if (notmuch_database_open (notmuch_config_get_database_path (config), NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much)) @@ -382,15 +387,15 @@ notmuch_search_command (void *ctx, int argc, char *argv[]) notmuch_query_set_sort (query, sort); - if (exclude == EXCLUDE_FLAG && output != OUTPUT_SUMMARY) { + if (exclude == NOTMUCH_EXCLUDE_FLAG && output != OUTPUT_SUMMARY) { /* If we are not doing summary output there is nowhere to * print the excluded flag so fall back on including the * excluded messages. */ fprintf (stderr, "Warning: this output format cannot flag excluded messages.\n"); - exclude = EXCLUDE_FALSE; + exclude = NOTMUCH_EXCLUDE_FALSE; } - if (exclude == EXCLUDE_TRUE || exclude == EXCLUDE_FLAG) { + if (exclude != NOTMUCH_EXCLUDE_FALSE) { const char **search_exclude_tags; size_t search_exclude_tags_length; @@ -398,8 +403,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[]) (config, &search_exclude_tags_length); for (i = 0; i < search_exclude_tags_length; i++) notmuch_query_add_tag_exclude (query, search_exclude_tags[i]); - if (exclude == EXCLUDE_FLAG) - notmuch_query_set_omit_excluded (query, FALSE); + notmuch_query_set_omit_excluded (query, exclude); } switch (output) {