unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Tomi Ollila <tomi.ollila@iki.fi>
To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org
Subject: Re: [Patch v2 04/13] lib/cli: add library API / CLI for compile time options
Date: Wed, 27 Apr 2016 20:47:04 +0300	[thread overview]
Message-ID: <m27ffjvt9j.fsf@guru.guru-group.fi> (raw)
In-Reply-To: <1459015043-8460-5-git-send-email-david@tethera.net>

On Sat, Mar 26 2016, David Bremner <david@tethera.net> wrote:

> This is intentionally low tech; if we have more than two options it may
> make sense to build up what infrastructure is provided.

2 quick notes for this patch -- since it has been like a month when I
looked this it takes time to get re-acquainted to the series again

...IMO this compile time "options" feels a bit odd; what options those are
if those are not options (but fixed things on what is available on the
underlying libraries). something like "features" would be a little less
odd (if there were no "database features" there ;/)

another thing is that these fixed things that were resolved by compile time 
is (re-)checked in compile time. instead of that just the 
HAVE_XAPIAN_COMPACT and HAVE_XAPIAN_FIELD_PROCESSOR could be used

... like: 

notmuch_bool_t
notmuch_options_get (const char *name) {
    if (STRNCMP_LITERAL (name, "compact") == 0) {
	return HAVE_XAPIAN_COMPACT;
	// or return HAVE_XAPIAN_COMPACT? TRUE: FALSE;
	// or return !! HAVE_XAPIAN_COMPACT;
    } else if (STRNCMP_LITERAL (name, "field_processor") == 0) {
	return HAVE_XAPIAN_FIELD_PROCESSOR;
    } else {
	return FALSE;
    }
}

... note: if this notmuch_options_present () function prevails, fix
the later #if check ;D

... and

void
_notmuch_config_list_options () {
    printf("options.compact=%s\n",
	   HAVE_XAPIAN_COMPACT ? "true" : "false");
    printf("options.field_processor=%s\n",
	   HAVE_XAPIAN_FIELD_PROCESSOR ? "true" : "false");
}

(kept the 'options' naming and prefix in this context)

otoh, all this "options" reading using notmuch config interface could
be pos^H^H^H^H put into another series and this naming thing could be
resolved there (proviced that these #if HAVE_XAPIAN ... #endif constructs
can be used conveniently here)

this is how these things look to me now; as usual i may not have 
caught all of the considerations here.

Tomi


> ---
>  doc/man1/notmuch-config.rst |  5 +++++
>  lib/Makefile.local          |  1 +
>  lib/notmuch.h               | 10 +++++++++
>  lib/options.c               | 50 +++++++++++++++++++++++++++++++++++++++++++++
>  notmuch-config.c            | 20 ++++++++++++++++++
>  test/T030-config.sh         |  6 ++++--
>  test/T040-setup.sh          |  6 ++++--
>  test/test-lib.sh            |  6 ++++++
>  8 files changed, 100 insertions(+), 4 deletions(-)
>  create mode 100644 lib/options.c
>
> diff --git a/doc/man1/notmuch-config.rst b/doc/man1/notmuch-config.rst
> index 40c1272..150d764 100644
> --- a/doc/man1/notmuch-config.rst
> +++ b/doc/man1/notmuch-config.rst
> @@ -132,6 +132,11 @@ The available configuration items are described below.
>      
>          Default: ``gpg``.
>  
> +    **options.<name>**
> +
> +	Compile time option <name>. Current possibilities include
> +	"compact" (see **notmuch-compact(1)**)
> +	and "field_processor" (see **notmuch-search-terms(7)**).
>  
>  ENVIRONMENT
>  ===========
> diff --git a/lib/Makefile.local b/lib/Makefile.local
> index 3a07090..4ad0158 100644
> --- a/lib/Makefile.local
> +++ b/lib/Makefile.local
> @@ -39,6 +39,7 @@ libnotmuch_c_srcs =		\
>  	$(dir)/message-file.c	\
>  	$(dir)/messages.c	\
>  	$(dir)/sha1.c		\
> +	$(dir)/options.c	\
>  	$(dir)/tags.c
>  
>  libnotmuch_cxx_srcs =		\
> diff --git a/lib/notmuch.h b/lib/notmuch.h
> index cb46fc0..b29dd5f 100644
> --- a/lib/notmuch.h
> +++ b/lib/notmuch.h
> @@ -1838,6 +1838,16 @@ notmuch_filenames_move_to_next (notmuch_filenames_t *filenames);
>  void
>  notmuch_filenames_destroy (notmuch_filenames_t *filenames);
>  
> +typedef enum {
> +    NOTMUCH_OPTION_COMPACT = 1,
> +    NOTMUCH_OPTION_FIELD_PROCESSOR = 2
> +} notmuch_option_t;
> +
> +notmuch_bool_t
> +notmuch_options_present (notmuch_option_t mask);
> +
> +notmuch_bool_t
> +notmuch_options_get (const char *name);
>  /* @} */
>  
>  NOTMUCH_END_DECLS
> diff --git a/lib/options.c b/lib/options.c
> new file mode 100644
> index 0000000..4e15d92
> --- /dev/null
> +++ b/lib/options.c
> @@ -0,0 +1,50 @@
> +/* notmuch - Not much of an email program, (just index and search)
> + *
> + * Copyright © 2016 David Bremner
> + *
> + * This program is free software: you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation, either version 3 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program.  If not, see http://www.gnu.org/licenses/ .
> + *
> + * Author: David Bremner <david@tethera.net>
> + */
> +
> +#include "notmuch.h"
> +#include "notmuch-private.h"
> +
> +notmuch_bool_t
> +notmuch_options_present (notmuch_option_t mask)
> +{
> +    notmuch_option_t present = 0;
> +
> +#if HAVE_XAPIAN_COMPACT
> +    present |= NOTMUCH_OPTION_COMPACT;
> +#endif
> +
> +#if HAVE_XAPIAN_COMPACT
> +    present |= NOTMUCH_OPTION_FIELD_PROCESSOR;
> +#endif
> +
> +    return (mask & present) != 0;
> +
> +}
> +
> +notmuch_bool_t
> +notmuch_options_get (const char *name) {
> +    if (STRNCMP_LITERAL (name, "compact") == 0) {
> +	return notmuch_options_present (NOTMUCH_OPTION_COMPACT);
> +    } else if (STRNCMP_LITERAL (name, "field_processor") == 0) {
> +	return notmuch_options_present (NOTMUCH_OPTION_FIELD_PROCESSOR);
> +    } else {
> +	return FALSE;
> +    }
> +}
> diff --git a/notmuch-config.c b/notmuch-config.c
> index d252bb2..cfc549d 100644
> --- a/notmuch-config.c
> +++ b/notmuch-config.c
> @@ -750,6 +750,8 @@ _item_split (char *item, char **group, char **key)
>      return 0;
>  }
>  
> +#define OPTION_PREFIX "options."
> +
>  static int
>  notmuch_config_command_get (notmuch_config_t *config, char *item)
>  {
> @@ -773,6 +775,9 @@ notmuch_config_command_get (notmuch_config_t *config, char *item)
>  	tags = notmuch_config_get_new_tags (config, &length);
>  	for (i = 0; i < length; i++)
>  	    printf ("%s\n", tags[i]);
> +    } else if (STRNCMP_LITERAL (item, OPTION_PREFIX) == 0) {
> +	printf ("%s\n",
> +	       notmuch_options_get (item + strlen (OPTION_PREFIX)) ? "true" : "false");
>      } else {
>  	char **value;
>  	size_t i, length;
> @@ -804,6 +809,11 @@ notmuch_config_command_set (notmuch_config_t *config, char *item, int argc, char
>  {
>      char *group, *key;
>  
> +    if (STRNCMP_LITERAL (item, OPTION_PREFIX) == 0) {
> +	fprintf (stderr, "Error: read only option: %s\n", item);
> +	return 1;
> +    }
> +
>      if (_item_split (item, &group, &key))
>  	return 1;
>  
> @@ -830,6 +840,15 @@ notmuch_config_command_set (notmuch_config_t *config, char *item, int argc, char
>      return notmuch_config_save (config);
>  }
>  
> +static
> +void
> +_notmuch_config_list_options () {
> +    printf("options.compact=%s\n",
> +	   notmuch_options_present(NOTMUCH_OPTION_COMPACT) ? "true" : "false");
> +    printf("options.field_processor=%s\n",
> +	   notmuch_options_present(NOTMUCH_OPTION_FIELD_PROCESSOR) ? "true" : "false");
> +}

  reply	other threads:[~2016-04-27 17:47 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-26 17:57 v2 of libconfig, date:foo, and named query patches David Bremner
2016-03-26 17:57 ` [Patch v2 01/13] configure: autodetect xapian-1.3 David Bremner
2016-04-01  9:09   ` Tomi Ollila
2016-04-01 23:29   ` David Bremner
2016-03-26 17:57 ` [Patch v2 02/13] configure: detect Xapian:FieldProcessor David Bremner
2016-03-26 17:57 ` [Patch v2 03/13] lib: optionally support single argument date: queries David Bremner
2016-03-26 17:57 ` [Patch v2 04/13] lib/cli: add library API / CLI for compile time options David Bremner
2016-04-27 17:47   ` Tomi Ollila [this message]
2016-04-30 11:53     ` David Bremner
2016-05-01 17:48       ` Tomi Ollila
2016-03-26 17:57 ` [Patch v2 05/13] configure: check directly for xapian compaction API David Bremner
2016-03-26 17:57 ` [Patch v2 06/13] lib: provide config API David Bremner
2016-03-26 17:57 ` [Patch v2 07/13] lib: config list iterators David Bremner
2016-03-26 17:57 ` [Patch v2 08/13] CLI: add print_status_database David Bremner
2016-03-27 20:25   ` [PATCH] nmbug: ignore # comments David Bremner
2016-03-27 20:38     ` W. Trevor King
2016-03-28  7:14       ` Tomi Ollila
2016-03-28 12:33     ` David Bremner
2016-03-26 17:57 ` [Patch v2 09/13] CLI: add optional config data to dump output David Bremner
2016-03-26 18:13   ` David Bremner
2016-03-26 17:57 ` [Patch v2 10/13] CLI: optionally restore config data David Bremner
2016-03-26 17:57 ` [Patch v2 11/13] CLI: add notmuch-config support for named queries David Bremner
2016-03-26 17:57 ` [Patch v2 12/13] lib: make a global constant for query parser flags David Bremner
2016-03-26 17:57 ` [Patch v2 13/13] lib: add support for named queries David Bremner
2016-04-01 23:57 ` Breaking a really long thread David Mazieres
2016-04-02 12:41   ` David Bremner
2016-04-02 13:56     ` David Mazieres
2016-04-04 11:07       ` Eric
2016-04-04 13:00         ` Mark Walters
2016-04-04 15:38           ` Eric
2016-04-05  5:28           ` David Mazieres
2016-04-09 11:20             ` Daniel Kahn Gillmor
2016-04-09 18:55               ` David Bremner
2016-04-09 22:40                 ` Mark Walters
2016-04-11  2:05                   ` David Bremner
2016-04-11  7:19                     ` Mark Walters
2016-04-11  7:39                       ` David Edmondson
2016-04-11  9:57                         ` David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m27ffjvt9j.fsf@guru.guru-group.fi \
    --to=tomi.ollila@iki.fi \
    --cc=david@tethera.net \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).