Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id CE02A6DE1502 for ; Sun, 7 Jun 2015 08:05:21 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.219 X-Spam-Level: X-Spam-Status: No, score=0.219 tagged_above=-999 required=5 tests=[AWL=0.209, T_HEADER_FROM_DIFFERENT_DOMAINS=0.01] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PPh9UVjqxtFE for ; Sun, 7 Jun 2015 08:05:20 -0700 (PDT) Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net [87.98.215.224]) by arlo.cworth.org (Postfix) with ESMTPS id 154076DE119C for ; Sun, 7 Jun 2015 08:05:20 -0700 (PDT) Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim 4.80) (envelope-from ) id 1Z1c7q-0004pb-Eu; Sun, 07 Jun 2015 15:04:38 +0000 Received: (nullmailer pid 7864 invoked by uid 1000); Sun, 07 Jun 2015 15:02:11 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 08/10] cli: add utility routine to print error status. Date: Sun, 7 Jun 2015 17:02:01 +0200 Message-Id: <1433689323-7520-9-git-send-email-david@tethera.net> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1433689323-7520-1-git-send-email-david@tethera.net> References: <1433689323-7520-1-git-send-email-david@tethera.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Jun 2015 15:05:21 -0000 No attention to formatting here, initially just focus on getting the relevant strings out of the library. --- Makefile.local | 1 + notmuch-client.h | 9 +++++++++ status.c | 21 +++++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 status.c diff --git a/Makefile.local b/Makefile.local index 6d54742..4de39b8 100644 --- a/Makefile.local +++ b/Makefile.local @@ -271,6 +271,7 @@ dataclean: distclean notmuch_client_srcs = \ command-line-arguments.c\ debugger.c \ + status.c \ gmime-filter-reply.c \ hooks.c \ notmuch.c \ diff --git a/notmuch-client.h b/notmuch-client.h index 78680aa..0f52038 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -465,6 +465,15 @@ notmuch_database_dump (notmuch_database_t *notmuch, dump_format_t output_format, notmuch_bool_t gzip_output); +/* If status is non-zero (i.e. error) print appropriate + messages to stderr. +*/ + +notmuch_status_t +print_status_query (const char *loc, + const notmuch_query_t *query, + notmuch_status_t status); + #include "command-line-arguments.h" extern const notmuch_opt_desc_t notmuch_shared_options []; void notmuch_process_shared_options (const char* subcommand_name); diff --git a/status.c b/status.c new file mode 100644 index 0000000..8fa81cb --- /dev/null +++ b/status.c @@ -0,0 +1,21 @@ +#include "notmuch-client.h" + +notmuch_status_t +print_status_query (const char *loc, + const notmuch_query_t *query, + notmuch_status_t status) +{ + if (status) { + const char *msg; + notmuch_database_t *notmuch; + + fprintf (stderr, "%s: %s\n", loc, + notmuch_status_to_string (status)); + + notmuch = notmuch_query_get_database (query); + msg = notmuch_database_status_string (notmuch); + if (msg) + fputs (msg, stderr); + } + return status; +} -- 2.1.4