From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id D0D126DE191D for ; Tue, 3 Nov 2015 11:50:27 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Spam-Flag: NO X-Spam-Score: -0.542 X-Spam-Level: X-Spam-Status: No, score=-0.542 tagged_above=-999 required=5 tests=[AWL=0.178, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01] 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 nNVzYz3QnOZh for ; Tue, 3 Nov 2015 11:50:26 -0800 (PST) Received: from mail-wi0-f176.google.com (mail-wi0-f176.google.com [209.85.212.176]) by arlo.cworth.org (Postfix) with ESMTPS id CADC86DE13DA for ; Tue, 3 Nov 2015 11:50:17 -0800 (PST) Received: by wikq8 with SMTP id q8so78806578wik.1 for ; Tue, 03 Nov 2015 11:50:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nikula_org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=z9SveoyXSbFAFaDD1ocYZR0BU9Q76zFgrdIJNYNIhCI=; b=oz2iGKrR4ob1PavAINlcj8zeyQ5s8KGlxBqJbz61KkUUns+upeuhQklC8mNffSZ7FG uiEitC8URwXiJNYtR/cyaesWwDAGGZKg4zhqvx64ouHt/wFqj3TvaFs0PED9ee+/aZZ/ IbKVnsWLJi9CkQ8BJVtEBEqObTvU+REP9/B+KKoXMLzEh0G1+XwYaV2ejmysNozL18pD 5HJnmbDEjD/4YtLsurU/i75DTpakOXA42p4p1IArBGiP98ozDqrps9rWRf8Ce5ZsQJS2 +W8s8BUmEjwC/23u9ZhScynX01A+Q3GeBw7QCkWklgB/YOTzBBDq8cY3V2SJJm/v5Asp F9NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=z9SveoyXSbFAFaDD1ocYZR0BU9Q76zFgrdIJNYNIhCI=; b=HD71Quo5ZWzCp6MMDg+hDLojgsYnqfR5dn/WeZmnBsd/Ys6ZoPibPE4y1n51P4nlYx ps7eEqFnezEFrIbcutq/1cAIDXd/fUsLGV68cN2cZSAIVVAgGXLGhgwkFE0Inmpxp++k wYQqyn7FKXFXbl+Ty1ay9LQuipnsKuJWPyMNOIKvpBhp40FGq6/ASOC7YElYLJyqKnK+ QJchOndpp8ddnJ1a5C1YXO2uEgB5QunfXV5LXPLquIUipy/9gHnBztzBEVhlVck6tWgZ cVJIN/qCGdQRbq+xr1BbpDtMp1hsNjOCaE3wA7b3LMQhVVkvkt28JLxo9DTe67Rq3R6y u//w== X-Gm-Message-State: ALoCoQkkh8Qf+Q1WVtq+kbDOQCFpfleHpkheORotVIMoRbUj4v08gZcMtOrsrWtTxeNBxZwEYY7x X-Received: by 10.194.175.226 with SMTP id cd2mr35732863wjc.30.1446580216139; Tue, 03 Nov 2015 11:50:16 -0800 (PST) Received: from localhost (mobile-access-bceec0-208.dhcp.inet.fi. [188.238.192.208]) by smtp.gmail.com with ESMTPSA id h198sm24928364wmd.9.2015.11.03.11.50.15 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Nov 2015 11:50:15 -0800 (PST) From: Jani Nikula To: notmuch@notmuchmail.org Subject: [RFC 4/5] cli: add notmuch config append command to append to string list configs Date: Tue, 3 Nov 2015 21:49:32 +0200 Message-Id: <0fadf414bc7086c5abddc3cbdd2c9da5f286f6ad.1446579858.git.jani@nikula.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: 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: Tue, 03 Nov 2015 19:50:28 -0000 Make it easy to add new entries to string list configs. For example, 'notmuch config append new.ignore my-non-mail-file'. --- notmuch-config.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/notmuch-config.c b/notmuch-config.c index d252bb25d4bb..96c73b0cc2ac 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -831,6 +831,46 @@ notmuch_config_command_set (notmuch_config_t *config, char *item, int argc, char } static int +notmuch_config_command_append (notmuch_config_t *config, char *item, + int argc, char *argv[]) +{ + char **value, **new_value; + size_t i, length, new_length; + char *group, *key; + + if (_item_split (item, &group, &key)) + return 1; + + value = g_key_file_get_string_list (config->key_file, group, key, + &length, NULL); + if (value == NULL) + length = 0; + + new_length = length + argc; + new_value = talloc_size (NULL, new_length * sizeof (char *)); + if (! new_value) + return 1; + + for (i = 0; i < new_length; i++) { + if (i < length) + new_value[i] = value[i]; + else + new_value[i] = argv[i - length]; + } + + if (new_length == 1) + g_key_file_set_string (config->key_file, group, key, new_value[0]); + else + g_key_file_set_string_list (config->key_file, group, key, + (const gchar **) new_value, new_length); + + g_strfreev (value); + talloc_free (new_value); + + return notmuch_config_save (config); +} + +static int notmuch_config_command_list (notmuch_config_t *config) { char **groups; @@ -905,6 +945,13 @@ notmuch_config_command (notmuch_config_t *config, int argc, char *argv[]) return EXIT_FAILURE; } ret = notmuch_config_command_set (config, argv[1], argc - 2, argv + 2); + } else if (strcmp (argv[0], "append") == 0) { + if (argc < 3) { + fprintf (stderr, "Error: notmuch config append requires at least " + "two arguments.\n"); + return EXIT_FAILURE; + } + ret = notmuch_config_command_append (config, argv[1], argc - 2, argv + 2); } else if (strcmp (argv[0], "list") == 0) { ret = notmuch_config_command_list (config); } else { -- 2.1.4