1 Return-Path: <bremner@tethera.net>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by arlo.cworth.org (Postfix) with ESMTP id D0B326DE1502
\r
6 for <notmuch@notmuchmail.org>; Sat, 9 Jan 2016 18:51:58 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org
\r
11 X-Spam-Status: No, score=-0.312 tagged_above=-999 required=5 tests=[AWL=0.239,
\r
12 RP_MATCHES_RCVD=-0.55, SPF_PASS=-0.001] autolearn=disabled
\r
13 Received: from arlo.cworth.org ([127.0.0.1])
\r
14 by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id y4_z5J2r28ib for <notmuch@notmuchmail.org>;
\r
16 Sat, 9 Jan 2016 18:51:57 -0800 (PST)
\r
17 Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])
\r
18 by arlo.cworth.org (Postfix) with ESMTPS id 769886DE02DA
\r
19 for <notmuch@notmuchmail.org>; Sat, 9 Jan 2016 18:51:55 -0800 (PST)
\r
20 Received: from remotemail by fethera.tethera.net with local (Exim 4.84)
\r
21 (envelope-from <bremner@tethera.net>)
\r
22 id 1aI66c-0007DW-07; Sat, 09 Jan 2016 21:51:46 -0500
\r
23 Received: (nullmailer pid 29659 invoked by uid 1000);
\r
24 Sun, 10 Jan 2016 02:51:47 -0000
\r
25 From: David Bremner <david@tethera.net>
\r
26 To: notmuch@notmuchmail.org
\r
27 Subject: [WIP patch 8/9] lib: make string representation of metadata class
\r
29 Date: Sat, 9 Jan 2016 22:51:40 -0400
\r
30 Message-Id: <1452394301-29499-9-git-send-email-david@tethera.net>
\r
31 X-Mailer: git-send-email 2.6.4
\r
32 In-Reply-To: <1452394301-29499-1-git-send-email-david@tethera.net>
\r
33 References: <1452394301-29499-1-git-send-email-david@tethera.net>
\r
34 X-BeenThere: notmuch@notmuchmail.org
\r
35 X-Mailman-Version: 2.1.20
\r
37 List-Id: "Use and development of the notmuch mail system."
\r
38 <notmuch.notmuchmail.org>
\r
39 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,
\r
40 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>
\r
42 List-Post: <mailto:notmuch@notmuchmail.org>
\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
44 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,
\r
45 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
46 X-List-Received-Date: Sun, 10 Jan 2016 02:51:58 -0000
\r
48 This is needed for e.g. notmuch-dump
\r
50 lib/metadata.cc | 34 +++++++++++++++++++++++-----------
\r
51 lib/notmuch.h | 5 +++++
\r
52 2 files changed, 28 insertions(+), 11 deletions(-)
\r
54 diff --git a/lib/metadata.cc b/lib/metadata.cc
\r
55 index 79a0a9e..34b46e0 100644
\r
56 --- a/lib/metadata.cc
\r
57 +++ b/lib/metadata.cc
\r
58 @@ -34,16 +34,28 @@ _notmuch_metadata_destroy (notmuch_metadata_t *list) {
\r
59 delete list->iterator;
\r
64 +typedef struct prefix {
\r
65 + notmuch_metadata_class_t mclass;
\r
66 + const char *prefix;
\r
69 +static prefix_t METADATA_PREFIX[] = {
\r
70 + {NOTMUCH_METADATA_CONFIG, "C"},
\r
73 +#define ARRAY_SIZE(arr) (sizeof (arr) / sizeof (arr[0]))
\r
76 -_find_metadata_prefix (notmuch_metadata_class_t mclass)
\r
77 +notmuch_metadata_prefix_string (notmuch_metadata_class_t mclass)
\r
80 - case NOTMUCH_METADATA_CONFIG:
\r
86 + for (i=0; i < ARRAY_SIZE(METADATA_PREFIX); i++) {
\r
87 + if (METADATA_PREFIX[0].mclass == mclass)
\r
88 + return METADATA_PREFIX[i].prefix;
\r
93 notmuch_status_t _make_key(void *ctx, notmuch_metadata_class_t mclass,
\r
94 @@ -55,7 +67,7 @@ notmuch_status_t _make_key(void *ctx, notmuch_metadata_class_t mclass,
\r
96 return NOTMUCH_STATUS_NULL_POINTER;
\r
98 - prefix = _find_metadata_prefix(mclass);
\r
99 + prefix = notmuch_metadata_prefix_string(mclass);
\r
101 return NOTMUCH_STATUS_UNSUPPORTED_OPERATION;
\r
103 @@ -169,7 +181,7 @@ notmuch_database_get_all_metadata (notmuch_database_t *notmuch,
\r
104 notmuch_metadata_t *list = NULL;
\r
105 notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;
\r
107 - const char *prefix = _find_metadata_prefix (mclass);
\r
108 + const char *prefix = notmuch_metadata_prefix_string (mclass);
\r
110 list = talloc (notmuch, notmuch_metadata_t);
\r
112 @@ -207,7 +219,7 @@ notmuch_database_get_all_metadata (notmuch_database_t *notmuch,
\r
114 notmuch_metadata_valid (notmuch_metadata_t *metadata)
\r
116 - const char *prefix = _find_metadata_prefix (metadata->mclass);
\r
117 + const char *prefix = notmuch_metadata_prefix_string (metadata->mclass);
\r
118 if (*(metadata->iterator) == metadata->notmuch->xapian_db->metadata_keys_end())
\r
121 @@ -217,7 +229,7 @@ notmuch_metadata_valid (notmuch_metadata_t *metadata)
\r
123 notmuch_metadata_key (notmuch_metadata_t *metadata)
\r
125 - const char *prefix = _find_metadata_prefix (metadata->mclass);
\r
126 + const char *prefix = notmuch_metadata_prefix_string (metadata->mclass);
\r
128 if (metadata->current_key)
\r
129 talloc_free (metadata->current_key);
\r
130 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
131 index 6773253..657a7d6 100644
\r
132 --- a/lib/notmuch.h
\r
133 +++ b/lib/notmuch.h
\r
134 @@ -1897,6 +1897,11 @@ notmuch_metadata_move_to_next (notmuch_metadata_t *metadata);
\r
136 notmuch_metadata_destroy (notmuch_metadata_t * metadata);
\r
139 + * convert enum to string
\r
142 +notmuch_metadata_prefix_string (notmuch_metadata_class_t mclass);
\r