]> git.notmuchmail.org Git - notmuch/blob - status.c
emacs/tree: add notmuch-tree-archive-message-than-next-or-exit
[notmuch] / status.c
1 #include "notmuch-client.h"
2
3 notmuch_status_t
4 print_status_query (const char *loc,
5                     const notmuch_query_t *query,
6                     notmuch_status_t status)
7 {
8     if (status) {
9         const char *msg;
10         notmuch_database_t *notmuch;
11
12         fprintf (stderr, "%s: %s\n", loc,
13                  notmuch_status_to_string (status));
14
15         notmuch = notmuch_query_get_database (query);
16         msg = notmuch_database_status_string (notmuch);
17         if (msg)
18             fputs (msg, stderr);
19     }
20     return status;
21 }
22
23 notmuch_status_t
24 print_status_message (const char *loc,
25                       const notmuch_message_t *message,
26                       notmuch_status_t status)
27 {
28     if (status) {
29         const char *msg;
30         notmuch_database_t *notmuch;
31
32         fprintf (stderr, "%s: %s\n", loc,
33                  notmuch_status_to_string (status));
34
35         notmuch = notmuch_message_get_database (message);
36         msg = notmuch_database_status_string (notmuch);
37         if (msg)
38             fputs (msg, stderr);
39     }
40     return status;
41 }
42
43 notmuch_status_t
44 print_status_database (const char *loc,
45                        const notmuch_database_t *notmuch,
46                        notmuch_status_t status)
47 {
48     if (status) {
49         const char *msg;
50
51         fprintf (stderr, "%s: %s\n", loc,
52                  notmuch_status_to_string (status));
53         msg = notmuch_database_status_string (notmuch);
54         if (msg)
55             fputs (msg, stderr);
56     }
57     return status;
58 }
59
60 int
61 status_to_exit (notmuch_status_t status)
62 {
63     switch (status) {
64     case NOTMUCH_STATUS_SUCCESS:
65         return EXIT_SUCCESS;
66     case NOTMUCH_STATUS_OUT_OF_MEMORY:
67     case NOTMUCH_STATUS_XAPIAN_EXCEPTION:
68     case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
69     case NOTMUCH_STATUS_FILE_ERROR:
70         return EX_TEMPFAIL;
71     default:
72         return EXIT_FAILURE;
73     }
74 }