From 8830a7181684493f43b491197e7bdad17d9e8150 Mon Sep 17 00:00:00 2001 From: Tomi Ollila Date: Sun, 18 Aug 2013 21:09:15 +0300 Subject: [PATCH] Re: [PATCH 2/2] cli: define config getters and setters using a macro --- 22/0fe3bb6b0557b31c133d82a2999eb3849ca9ce | 240 ++++++++++++++++++++++ 1 file changed, 240 insertions(+) create mode 100644 22/0fe3bb6b0557b31c133d82a2999eb3849ca9ce diff --git a/22/0fe3bb6b0557b31c133d82a2999eb3849ca9ce b/22/0fe3bb6b0557b31c133d82a2999eb3849ca9ce new file mode 100644 index 000000000..0ee79c155 --- /dev/null +++ b/22/0fe3bb6b0557b31c133d82a2999eb3849ca9ce @@ -0,0 +1,240 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 95822431FDD + for ; Sun, 18 Aug 2013 11:09:25 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0 +X-Spam-Level: +X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] + autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id A8itxHlr638i for ; + Sun, 18 Aug 2013 11:09:21 -0700 (PDT) +Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) + by olra.theworths.org (Postfix) with ESMTP id D198A431FDB + for ; Sun, 18 Aug 2013 11:09:20 -0700 (PDT) +Received: from guru.guru-group.fi (localhost [IPv6:::1]) + by guru.guru-group.fi (Postfix) with ESMTP id 07228100086; + Sun, 18 Aug 2013 21:09:16 +0300 (EEST) +From: Tomi Ollila +To: Jani Nikula , notmuch@notmuchmail.org +Subject: Re: [PATCH 2/2] cli: define config getters and setters using a macro +In-Reply-To: <1376839205-5115-2-git-send-email-jani@nikula.org> +References: <1376839205-5115-1-git-send-email-jani@nikula.org> + <1376839205-5115-2-git-send-email-jani@nikula.org> +User-Agent: Notmuch/0.16+3~g340c058 (http://notmuchmail.org) Emacs/24.3.1 + (x86_64-unknown-linux-gnu) +X-Face: HhBM'cA~ +MIME-Version: 1.0 +Content-Type: text/plain +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +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, 18 Aug 2013 18:09:25 -0000 + +On Sun, Aug 18 2013, Jani Nikula wrote: + +> There's plenty of duplicated code in defining the functions for config +> get/set. Add macros to define the functions. +> +> --- +> +> This might be a bit too tricky for some people's tastes... let's see! +> ;) + +Yes, a bit tricky. Nevertheless I like these... + +Additionally id:1376839205-5115-1-git-send-email-jani@nikula.org LGTM. + +Tomi + + +> --- +> notmuch-config.c | 141 ++++++++++++++---------------------------------------- +> 1 file changed, 37 insertions(+), 104 deletions(-) +> +> diff --git a/notmuch-config.c b/notmuch-config.c +> index 305d213..fcee0fc 100644 +> --- a/notmuch-config.c +> +++ b/notmuch-config.c +> @@ -520,6 +520,18 @@ _config_set (notmuch_config_t *config, char **field, +> *field = NULL; +> } +> +> +#define DEFINE_CONFIG_GET(group, key) \ +> + const char * \ +> + notmuch_config_get_ ## group ## _ ## key (notmuch_config_t *config) { \ +> + return _config_get (config, &config->group ## _ ## key, #group, #key); \ +> + } +> + +> +#define DEFINE_CONFIG_SET(group, key) \ +> + void \ +> + notmuch_config_set_ ## group ## _ ## key (notmuch_config_t *config, const char *value) { \ +> + _config_set (config, &config->group ## _ ## key, #group, #key, value); \ +> + } +> + +> static const char ** +> _config_get_list (notmuch_config_t *config, +> const char *section, const char *key, +> @@ -562,112 +574,33 @@ _config_set_list (notmuch_config_t *config, +> *config_var = NULL; +> } +> +> -const char * +> -notmuch_config_get_database_path (notmuch_config_t *config) +> -{ +> - return _config_get (config, &config->database_path, "database", "path"); +> -} +> - +> -void +> -notmuch_config_set_database_path (notmuch_config_t *config, +> - const char *database_path) +> -{ +> - _config_set (config, &config->database_path, "database", "path", database_path); +> -} +> - +> -const char * +> -notmuch_config_get_user_name (notmuch_config_t *config) +> -{ +> - return _config_get (config, &config->user_name, "user", "name"); +> -} +> - +> -void +> -notmuch_config_set_user_name (notmuch_config_t *config, +> - const char *user_name) +> -{ +> - _config_set (config, &config->user_name, "user", "name", user_name); +> -} +> - +> -const char * +> -notmuch_config_get_user_primary_email (notmuch_config_t *config) +> -{ +> - return _config_get (config, &config->user_primary_email, "user", "primary_email"); +> -} +> - +> -void +> -notmuch_config_set_user_primary_email (notmuch_config_t *config, +> - const char *primary_email) +> -{ +> - _config_set (config, &config->user_primary_email, "user", "primary_email", primary_email); +> -} +> - +> -const char ** +> -notmuch_config_get_user_other_email (notmuch_config_t *config, size_t *length) +> -{ +> - return _config_get_list (config, "user", "other_email", +> - &(config->user_other_email), +> - &(config->user_other_email_length), length); +> -} +> - +> -const char ** +> -notmuch_config_get_new_tags (notmuch_config_t *config, size_t *length) +> -{ +> - return _config_get_list (config, "new", "tags", +> - &(config->new_tags), +> - &(config->new_tags_length), length); +> -} +> - +> -const char ** +> -notmuch_config_get_new_ignore (notmuch_config_t *config, size_t *length) +> -{ +> - return _config_get_list (config, "new", "ignore", +> - &(config->new_ignore), +> - &(config->new_ignore_length), length); +> -} +> - +> -void +> -notmuch_config_set_user_other_email (notmuch_config_t *config, +> - const char *list[], +> - size_t length) +> -{ +> - _config_set_list (config, "user", "other_email", list, length, +> - &(config->user_other_email)); +> -} +> - +> -void +> -notmuch_config_set_new_tags (notmuch_config_t *config, +> - const char *list[], +> - size_t length) +> -{ +> - _config_set_list (config, "new", "tags", list, length, +> - &(config->new_tags)); +> -} +> - +> -void +> -notmuch_config_set_new_ignore (notmuch_config_t *config, +> - const char *list[], +> - size_t length) +> -{ +> - _config_set_list (config, "new", "ignore", list, length, +> - &(config->new_ignore)); +> -} +> +#define DEFINE_CONFIG_GET_LIST(group, key) \ +> + const char ** \ +> + notmuch_config_get_ ## group ## _ ## key (notmuch_config_t *config, size_t *length) { \ +> + return _config_get_list (config, #group, #key, &config->group ## _ ## key, &config->group ## _ ## key ## _ ## length, length); \ +> + } +> +> -const char ** +> -notmuch_config_get_search_exclude_tags (notmuch_config_t *config, size_t *length) +> -{ +> - return _config_get_list (config, "search", "exclude_tags", +> - &(config->search_exclude_tags), +> - &(config->search_exclude_tags_length), length); +> -} +> +#define DEFINE_CONFIG_SET_LIST(group, key) \ +> + void \ +> + notmuch_config_set_ ## group ## _ ## key (notmuch_config_t *config, const char *list[], size_t length) { \ +> + _config_set_list (config, #group, #key, list, length, &config->group ## _ ## key); \ +> + } +> +> -void +> -notmuch_config_set_search_exclude_tags (notmuch_config_t *config, +> - const char *list[], +> - size_t length) +> -{ +> - _config_set_list (config, "search", "exclude_tags", list, length, +> - &(config->search_exclude_tags)); +> -} +> +DEFINE_CONFIG_GET(database, path); +> +DEFINE_CONFIG_SET(database, path); +> +DEFINE_CONFIG_GET(user, name); +> +DEFINE_CONFIG_SET(user, name); +> +DEFINE_CONFIG_GET(user, primary_email); +> +DEFINE_CONFIG_SET(user, primary_email); +> + +> +DEFINE_CONFIG_GET_LIST(user, other_email); +> +DEFINE_CONFIG_SET_LIST(user, other_email); +> +DEFINE_CONFIG_GET_LIST(new, tags); +> +DEFINE_CONFIG_SET_LIST(new, tags); +> +DEFINE_CONFIG_GET_LIST(new, ignore); +> +DEFINE_CONFIG_SET_LIST(new, ignore); +> +DEFINE_CONFIG_GET_LIST(search, exclude_tags); +> +DEFINE_CONFIG_SET_LIST(search, exclude_tags); +> +> /* Given a configuration item of the form . return the +> * component group and key. If any error occurs, print a message on +> -- +> 1.7.10.4 +> +> _______________________________________________ +> notmuch mailing list +> notmuch@notmuchmail.org +> http://notmuchmail.org/mailman/listinfo/notmuch -- 2.26.2