X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=notmuch-count.c;h=b8b03cdbc0d409e04e791e36a4e9ee37c6f51db3;hp=0b6e6f5443964f917d7577bc7719d578c253646c;hb=9a0df8128c1a2f92d03035aebbd7a90eb93ec601;hpb=e7b420a85446fa469df77e24c11f8afa06a2592e diff --git a/notmuch-count.c b/notmuch-count.c index 0b6e6f54..b8b03cdb 100644 --- a/notmuch-count.c +++ b/notmuch-count.c @@ -14,7 +14,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see http://www.gnu.org/licenses/ . + * along with this program. If not, see https://www.gnu.org/licenses/ . * * Author: Keith Packard */ @@ -43,7 +43,7 @@ count_files (notmuch_query_t *query) notmuch_status_t status; int count = 0; - status = notmuch_query_search_messages_st (query, &messages); + status = notmuch_query_search_messages (query, &messages); if (print_status_query ("notmuch count", query, status)) return -1; @@ -87,18 +87,23 @@ print_count (notmuch_database_t *notmuch, const char *query_str, return -1; } - for (i = 0; i < exclude_tags_length; i++) - notmuch_query_add_tag_exclude (query, exclude_tags[i]); + for (i = 0; i < exclude_tags_length; i++) { + status = notmuch_query_add_tag_exclude (query, exclude_tags[i]); + if (status && status != NOTMUCH_STATUS_IGNORED) { + print_status_query ("notmuch count", query, status); + return -1; + } + } switch (output) { case OUTPUT_MESSAGES: - status = notmuch_query_count_messages_st (query, &ucount); + status = notmuch_query_count_messages (query, &ucount); if (print_status_query ("notmuch count", query, status)) return -1; printf ("%u", ucount); break; case OUTPUT_THREADS: - status = notmuch_query_count_threads_st (query, &ucount); + status = notmuch_query_count_threads (query, &ucount); if (print_status_query ("notmuch count", query, status)) return -1; printf ("%u", ucount); @@ -106,7 +111,7 @@ print_count (notmuch_database_t *notmuch, const char *query_str, case OUTPUT_FILES: count = count_files (query); if (count >= 0) { - printf ("%u", count); + printf ("%d", count); } else { ret = -1; goto DONE; @@ -161,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); @@ -199,6 +204,8 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]) if (batch && opt_index != argc) { fprintf (stderr, "--batch and query string are not compatible\n"); + if (input) + fclose (input); return EXIT_FAILURE; }