From 37ea68685afceb9d7949a2cfd30e7e3df302ad13 Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Sun, 18 Aug 2013 18:20:05 +0300 Subject: [PATCH] [PATCH 2/2] cli: define config getters and setters using a macro --- 31/1f8b6df665fb152bffc23b8e3120a851dc6ebd | 240 ++++++++++++++++++++++ 1 file changed, 240 insertions(+) create mode 100644 31/1f8b6df665fb152bffc23b8e3120a851dc6ebd diff --git a/31/1f8b6df665fb152bffc23b8e3120a851dc6ebd b/31/1f8b6df665fb152bffc23b8e3120a851dc6ebd new file mode 100644 index 000000000..251078b5a --- /dev/null +++ b/31/1f8b6df665fb152bffc23b8e3120a851dc6ebd @@ -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 F037B421177 + for ; Sun, 18 Aug 2013 08:20:11 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 LJ-9KPbXPW4G for ; + Sun, 18 Aug 2013 08:20:06 -0700 (PDT) +Received: from mail-bk0-f51.google.com (mail-bk0-f51.google.com + [209.85.214.51]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 25838429E59 + for ; Sun, 18 Aug 2013 08:20:06 -0700 (PDT) +Received: by mail-bk0-f51.google.com with SMTP id mx10so1111067bkb.38 + for ; Sun, 18 Aug 2013 08:20:04 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=google.com; s=20120113; + h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to + :references; + bh=dX/jB0P4THWXkMen1TrH0kki1cbjh3Wg7fyJpyBuGWA=; + b=IYbdtoUmwccyBn7SFM/Xi0ns+bkrtEvfdFRF1j+ssosy4xjHFQya2sQherIy9U8pX/ + oja6zKhPB6O0ozpyY6FOmUKA/cY4ZC+h2TmYpoiNcq8M67p7ObTDt525DVEc+RlH9YxX + MA7m6zNuKGJmhOps4W+ne8fk2ZkiGRBMLqfOeueqswpC/VLRft2w6adUPWUM8LKybXw0 + 1dOqOgY9dwjR+MLAtNKXcB2xvL5p3oOwGkKsIy+z159JupVIq9ivigW/tlZ8jkALYQcF + oIIbMDz3Cnyszv3nRG1o7Tn0bbllmHlK7RfHqvinjPY7hMRY9n6J64JVw0sQTo5bQqK/ + Mplg== +X-Gm-Message-State: + ALoCoQnLCgoZfghpOR3oXcPaw/+CHM9oMNr1BX5I/kUOLOP14X0XhKkhbs4AdGH5hP8CvhKs87MF +X-Received: by 10.205.10.132 with SMTP id pa4mr6969943bkb.15.1376839204800; + Sun, 18 Aug 2013 08:20:04 -0700 (PDT) +Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi. + [88.195.111.91]) + by mx.google.com with ESMTPSA id nv4sm949614bkb.3.1969.12.31.16.00.00 + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Sun, 18 Aug 2013 08:20:04 -0700 (PDT) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: [PATCH 2/2] cli: define config getters and setters using a macro +Date: Sun, 18 Aug 2013 18:20:05 +0300 +Message-Id: <1376839205-5115-2-git-send-email-jani@nikula.org> +X-Mailer: git-send-email 1.7.10.4 +In-Reply-To: <1376839205-5115-1-git-send-email-jani@nikula.org> +References: <1376839205-5115-1-git-send-email-jani@nikula.org> +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 15:20:12 -0000 + +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! +;) +--- + 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 + -- 2.26.2