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 D0B326DE1502 for ; Sat, 9 Jan 2016 18:51:58 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.312 X-Spam-Level: X-Spam-Status: No, score=-0.312 tagged_above=-999 required=5 tests=[AWL=0.239, RP_MATCHES_RCVD=-0.55, SPF_PASS=-0.001] 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 y4_z5J2r28ib for ; Sat, 9 Jan 2016 18:51:57 -0800 (PST) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id 769886DE02DA for ; Sat, 9 Jan 2016 18:51:55 -0800 (PST) Received: from remotemail by fethera.tethera.net with local (Exim 4.84) (envelope-from ) id 1aI66c-0007DW-07; Sat, 09 Jan 2016 21:51:46 -0500 Received: (nullmailer pid 29659 invoked by uid 1000); Sun, 10 Jan 2016 02:51:47 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [WIP patch 8/9] lib: make string representation of metadata class public Date: Sat, 9 Jan 2016 22:51:40 -0400 Message-Id: <1452394301-29499-9-git-send-email-david@tethera.net> X-Mailer: git-send-email 2.6.4 In-Reply-To: <1452394301-29499-1-git-send-email-david@tethera.net> References: <1452394301-29499-1-git-send-email-david@tethera.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.20 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, 10 Jan 2016 02:51:58 -0000 This is needed for e.g. notmuch-dump --- lib/metadata.cc | 34 +++++++++++++++++++++++----------- lib/notmuch.h | 5 +++++ 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/lib/metadata.cc b/lib/metadata.cc index 79a0a9e..34b46e0 100644 --- a/lib/metadata.cc +++ b/lib/metadata.cc @@ -34,16 +34,28 @@ _notmuch_metadata_destroy (notmuch_metadata_t *list) { delete list->iterator; return 0; } -static + +typedef struct prefix { + notmuch_metadata_class_t mclass; + const char *prefix; +} prefix_t; + +static prefix_t METADATA_PREFIX[] = { + {NOTMUCH_METADATA_CONFIG, "C"}, +}; + +#define ARRAY_SIZE(arr) (sizeof (arr) / sizeof (arr[0])) + const char * -_find_metadata_prefix (notmuch_metadata_class_t mclass) +notmuch_metadata_prefix_string (notmuch_metadata_class_t mclass) { - switch (mclass) { - case NOTMUCH_METADATA_CONFIG: - return "C"; - default: - return NULL; + unsigned int i; + + for (i=0; i < ARRAY_SIZE(METADATA_PREFIX); i++) { + if (METADATA_PREFIX[0].mclass == mclass) + return METADATA_PREFIX[i].prefix; } + return NULL; } notmuch_status_t _make_key(void *ctx, notmuch_metadata_class_t mclass, @@ -55,7 +67,7 @@ notmuch_status_t _make_key(void *ctx, notmuch_metadata_class_t mclass, if (!out) return NOTMUCH_STATUS_NULL_POINTER; - prefix = _find_metadata_prefix(mclass); + prefix = notmuch_metadata_prefix_string(mclass); if (!prefix) return NOTMUCH_STATUS_UNSUPPORTED_OPERATION; @@ -169,7 +181,7 @@ notmuch_database_get_all_metadata (notmuch_database_t *notmuch, notmuch_metadata_t *list = NULL; notmuch_status_t status = NOTMUCH_STATUS_SUCCESS; - const char *prefix = _find_metadata_prefix (mclass); + const char *prefix = notmuch_metadata_prefix_string (mclass); list = talloc (notmuch, notmuch_metadata_t); if (!list) { @@ -207,7 +219,7 @@ notmuch_database_get_all_metadata (notmuch_database_t *notmuch, notmuch_bool_t notmuch_metadata_valid (notmuch_metadata_t *metadata) { - const char *prefix = _find_metadata_prefix (metadata->mclass); + const char *prefix = notmuch_metadata_prefix_string (metadata->mclass); if (*(metadata->iterator) == metadata->notmuch->xapian_db->metadata_keys_end()) return FALSE; @@ -217,7 +229,7 @@ notmuch_metadata_valid (notmuch_metadata_t *metadata) const char * notmuch_metadata_key (notmuch_metadata_t *metadata) { - const char *prefix = _find_metadata_prefix (metadata->mclass); + const char *prefix = notmuch_metadata_prefix_string (metadata->mclass); if (metadata->current_key) talloc_free (metadata->current_key); diff --git a/lib/notmuch.h b/lib/notmuch.h index 6773253..657a7d6 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -1897,6 +1897,11 @@ notmuch_metadata_move_to_next (notmuch_metadata_t *metadata); void notmuch_metadata_destroy (notmuch_metadata_t * metadata); +/** + * convert enum to string + */ +const char * +notmuch_metadata_prefix_string (notmuch_metadata_class_t mclass); /* @} */ NOTMUCH_END_DECLS -- 2.6.4