Skip to content

Commit

Permalink
Reconsider the config type bitmap entirely
Browse files Browse the repository at this point in the history
Instead of forty different seemingly-randomly-named flags with explicit
bits specified, decide on (a) a consistent naming scheme, (b) actually
correctly namespacing them, and (c) allocating the bits automatically.
  • Loading branch information
nabijaczleweli authored and flatcap committed Jan 22, 2024
1 parent 8e897d1 commit 3e6c9f8
Show file tree
Hide file tree
Showing 74 changed files with 550 additions and 528 deletions.
4 changes: 2 additions & 2 deletions address/config_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ static int address_string_set(const struct ConfigSet *cs, void *var, struct Conf
else
{
/* set the default/initial value */
if (cdef->type & DT_INITIAL_SET)
if (cdef->type & D_INTERNAL_INITIAL_SET)
FREE(&cdef->initial);

cdef->type |= DT_INITIAL_SET;
cdef->type |= D_INTERNAL_INITIAL_SET;
cdef->initial = (intptr_t) mutt_str_dup(value);
}

Expand Down
2 changes: 1 addition & 1 deletion alias/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void parse_alias_tags(const char *tags, struct TagList *tl)
if (!tags || !tl)
return;

struct Slist *sl = slist_parse(tags, SLIST_SEP_COMMA);
struct Slist *sl = slist_parse(tags, D_SLIST_SEP_COMMA);
if (slist_is_empty(sl))
{
slist_free(&sl);
Expand Down
10 changes: 5 additions & 5 deletions alias/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ static const struct Mapping SortAliasMethods[] = {
*/
static struct ConfigDef AliasVars[] = {
// clang-format off
{ "alias_file", DT_PATH|DT_PATH_FILE, IP "~/.neomuttrc", 0, NULL,
{ "alias_file", DT_PATH|D_PATH_FILE, IP "~/.neomuttrc", 0, NULL,
"Save new aliases to this file"
},
{ "alias_format", DT_STRING|DT_NOT_EMPTY, IP "%3n %f%t %-15a %-56r | %c", 0, NULL,
{ "alias_format", DT_STRING|D_NOT_EMPTY, IP "%3n %f%t %-15a %-56r | %c", 0, NULL,
"printf-like format string for the alias menu"
},
{ "sort_alias", DT_SORT|DT_SORT_REVERSE, SORT_ALIAS, IP SortAliasMethods, NULL,
{ "sort_alias", DT_SORT|D_SORT_REVERSE, SORT_ALIAS, IP SortAliasMethods, NULL,
"Sort method for the alias menu"
},
{ "query_command", DT_STRING|DT_COMMAND, 0, 0, NULL,
{ "query_command", DT_STRING|D_STRING_COMMAND, 0, 0, NULL,
"External command to query and external address book"
},
{ "query_format", DT_STRING|DT_NOT_EMPTY, IP "%3c %t %-25.25n %-25.25a | %e", 0, NULL,
{ "query_format", DT_STRING|D_NOT_EMPTY, IP "%3c %t %-25.25n %-25.25a | %e", 0, NULL,
"printf-like format string for the query menu (address book)"
},
{ NULL },
Expand Down
2 changes: 1 addition & 1 deletion autocrypt/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static struct ConfigDef AutocryptVars[] = {
{ "autocrypt_acct_format", DT_STRING, IP "%4n %-30a %20p %10s", 0, NULL,
"Format of the autocrypt account menu"
},
{ "autocrypt_dir", DT_PATH|DT_PATH_DIR, IP "~/.mutt/autocrypt", 0, NULL,
{ "autocrypt_dir", DT_PATH|D_PATH_DIR, IP "~/.mutt/autocrypt", 0, NULL,
"Location of autocrypt files, including the GPG keyring and SQLite database"
},
{ "autocrypt_reply", DT_BOOL, true, 0, NULL,
Expand Down
10 changes: 5 additions & 5 deletions browser/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,22 @@ static struct ConfigDef BrowserVars[] = {
{ "browser_abbreviate_mailboxes", DT_BOOL, true, 0, NULL,
"Abbreviate mailboxes using '~' and '=' in the browser"
},
{ "folder_format", DT_STRING|DT_NOT_EMPTY, IP "%2C %t %N %F %2l %-8.8u %-8.8g %8s %d %i", 0, NULL,
{ "folder_format", DT_STRING|D_NOT_EMPTY, IP "%2C %t %N %F %2l %-8.8u %-8.8g %8s %d %i", 0, NULL,
"printf-like format string for the browser's display of folders"
},
{ "group_index_format", DT_STRING|DT_NOT_EMPTY, IP "%4C %M%N %5s %-45.45f %d", 0, NULL,
{ "group_index_format", DT_STRING|D_NOT_EMPTY, IP "%4C %M%N %5s %-45.45f %d", 0, NULL,
"(nntp) printf-like format string for the browser's display of newsgroups"
},
{ "mailbox_folder_format", DT_STRING|DT_NOT_EMPTY, IP "%2C %<n?%6n& > %6m %i", 0, NULL,
{ "mailbox_folder_format", DT_STRING|D_NOT_EMPTY, IP "%2C %<n?%6n& > %6m %i", 0, NULL,
"printf-like format string for the browser's display of mailbox folders"
},
{ "mask", DT_REGEX|DT_REGEX_MATCH_CASE|DT_REGEX_ALLOW_NOT|DT_REGEX_NOSUB, IP "!^\\.[^.]", 0, NULL,
{ "mask", DT_REGEX|D_REGEX_MATCH_CASE|D_REGEX_ALLOW_NOT|D_REGEX_NOSUB, IP "!^\\.[^.]", 0, NULL,
"Only display files/dirs matching this regex in the browser"
},
{ "show_only_unread", DT_BOOL, false, 0, NULL,
"(nntp) Only show subscribed newsgroups with unread articles"
},
{ "sort_browser", DT_SORT|DT_SORT_REVERSE, SORT_ALPHA, IP SortBrowserMethods, NULL,
{ "sort_browser", DT_SORT|D_SORT_REVERSE, SORT_ALPHA, IP SortBrowserMethods, NULL,
"Sort method for the browser"
},
{ "browser_sort_dirs_first", DT_BOOL, false, 0, NULL,
Expand Down
2 changes: 1 addition & 1 deletion complete/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ int mutt_command_complete(struct CompletionData *cd, struct Buffer *buf, int pos
he = he_list[i];
const int type = DTYPE(he->type);

if ((type == DT_SYNONYM) || (type & DT_DEPRECATED))
if ((type == DT_SYNONYM) || (type & D_INTERNAL_DEPRECATED))
continue;

candidate(cd, cd->user_typed, he->key.strkey, cd->completed, sizeof(cd->completed));
Expand Down
2 changes: 1 addition & 1 deletion compose/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static struct ConfigDef ComposeVars[] = {
{ "edit_headers", DT_BOOL, false, 0, NULL,
"Let the user edit the email headers whilst editing an email"
},
{ "ispell", DT_STRING|DT_COMMAND, IP ISPELL, 0, NULL,
{ "ispell", DT_STRING|D_STRING_COMMAND, IP ISPELL, 0, NULL,
"External command to perform spell-checking"
},
{ "postpone", DT_QUAD, MUTT_ASKYES, 0, NULL,
Expand Down
7 changes: 4 additions & 3 deletions config/charset.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "mutt/lib.h"
#include "charset.h"
#include "set.h"
#include "types.h"

/**
* charset_validator - Validate the "charset" config variables - Implements ConfigDef::validator() - @ingroup cfg_def_validator
Expand All @@ -47,14 +48,14 @@ int charset_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef,

const char *str = (const char *) value;

if ((cdef->type & DT_CHARSET_SINGLE) && strchr(str, ':'))
if ((cdef->type & D_CHARSET_SINGLE) && strchr(str, ':'))
{
buf_printf(err, _("'charset' must contain exactly one character set name"));
return CSR_ERR_INVALID;
}

int rc = CSR_SUCCESS;
bool strict = (cdef->type & DT_CHARSET_STRICT);
bool strict = (cdef->type & D_CHARSET_STRICT);
char *q = NULL;
char *s = mutt_str_dup(str);

Expand Down Expand Up @@ -88,7 +89,7 @@ int charset_slist_validator(const struct ConfigSet *cs, const struct ConfigDef *
const struct Slist *list = (const struct Slist *) value;

int rc = CSR_SUCCESS;
bool strict = (cdef->type & DT_CHARSET_STRICT);
bool strict = (cdef->type & D_CHARSET_STRICT);

const struct ListNode *np = NULL;
STAILQ_FOREACH(np, &list->head, entries)
Expand Down
5 changes: 0 additions & 5 deletions config/charset.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@

#include <stdint.h>

/* Note: To save space, sets of config variable flags are packed into a uint32_t.
* When adding flags, check all config variables to ensure there are no overlaps of values */
#define DT_CHARSET_SINGLE (1 << 24) ///< Flag for charset_validator to allow only one charset
#define DT_CHARSET_STRICT (1 << 25) ///< Flag for charset_validator to use strict char check

struct Buffer;
struct ConfigDef;
struct ConfigSet;
Expand Down
6 changes: 3 additions & 3 deletions config/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ bool dump_config(struct ConfigSet *cs, ConfigDumpFlags flags, FILE *fp)
if ((type == DT_SYNONYM) && !(flags & CS_DUMP_SHOW_SYNONYMS))
continue;

if ((he->type & DT_DEPRECATED) && !(flags & CS_DUMP_SHOW_DEPRECATED))
if ((he->type & D_INTERNAL_DEPRECATED) && !(flags & CS_DUMP_SHOW_DEPRECATED))
continue;

if (type != DT_SYNONYM)
Expand All @@ -206,7 +206,7 @@ bool dump_config(struct ConfigSet *cs, ConfigDumpFlags flags, FILE *fp)
}

const struct ConfigDef *cdef = he->data;
if ((type == DT_STRING) && IS_SENSITIVE(cdef->type) &&
if ((type == DT_STRING) && (cdef->type & D_SENSITIVE) &&
(flags & CS_DUMP_HIDE_SENSITIVE) && !buf_is_empty(value))
{
buf_reset(value);
Expand Down Expand Up @@ -235,7 +235,7 @@ bool dump_config(struct ConfigSet *cs, ConfigDumpFlags flags, FILE *fp)
break; /* LCOV_EXCL_LINE */
}

if (((type == DT_PATH) || IS_MAILBOX(he->type)) && !(he->type & DT_MAILBOX))
if (((type == DT_PATH) || IS_MAILBOX(he->type)) && !(he->type & D_STRING_MAILBOX))
mutt_pretty_mailbox(initial->data, initial->dsize);

if ((type != DT_BOOL) && (type != DT_NUMBER) && (type != DT_LONG) &&
Expand Down
8 changes: 4 additions & 4 deletions config/long.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static int long_string_set(const struct ConfigSet *cs, void *var, struct ConfigD
return CSR_ERR_INVALID | CSR_INV_TYPE;
}

if ((num < 0) && (cdef->type & DT_NOT_NEGATIVE))
if ((num < 0) && (cdef->type & D_INTEGER_NOT_NEGATIVE))
{
buf_printf(err, _("Option %s may not be negative"), cdef->name);
return CSR_ERR_INVALID | CSR_INV_VALIDATOR;
Expand Down Expand Up @@ -111,7 +111,7 @@ static int long_string_get(const struct ConfigSet *cs, void *var,
static int long_native_set(const struct ConfigSet *cs, void *var,
const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
{
if ((value < 0) && (cdef->type & DT_NOT_NEGATIVE))
if ((value < 0) && (cdef->type & D_INTEGER_NOT_NEGATIVE))
{
buf_printf(err, _("Option %s may not be negative"), cdef->name);
return CSR_ERR_INVALID | CSR_INV_VALIDATOR;
Expand Down Expand Up @@ -159,7 +159,7 @@ static int long_string_plus_equals(const struct ConfigSet *cs, void *var,
}

long result = *((long *) var) + num;
if ((result < 0) && (cdef->type & DT_NOT_NEGATIVE))
if ((result < 0) && (cdef->type & D_INTEGER_NOT_NEGATIVE))
{
buf_printf(err, _("Option %s may not be negative"), cdef->name);
return CSR_ERR_INVALID | CSR_INV_VALIDATOR;
Expand Down Expand Up @@ -198,7 +198,7 @@ static int long_string_minus_equals(const struct ConfigSet *cs, void *var,
}

long result = *((long *) var) - num;
if ((result < 0) && (cdef->type & DT_NOT_NEGATIVE))
if ((result < 0) && (cdef->type & D_INTEGER_NOT_NEGATIVE))
{
buf_printf(err, _("Option %s may not be negative"), cdef->name);
return CSR_ERR_INVALID | CSR_INV_VALIDATOR;
Expand Down
4 changes: 2 additions & 2 deletions config/mbtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ static int mbtable_string_set(const struct ConfigSet *cs, void *var, struct Conf
}
else
{
if (cdef->type & DT_INITIAL_SET)
if (cdef->type & D_INTERNAL_INITIAL_SET)
FREE(&cdef->initial);

cdef->type |= DT_INITIAL_SET;
cdef->type |= D_INTERNAL_INITIAL_SET;
cdef->initial = (intptr_t) mutt_str_dup(value);
}

Expand Down
4 changes: 2 additions & 2 deletions config/myvar.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ static int myvar_string_set(const struct ConfigSet *cs, void *var, struct Config
}
else
{
if (cdef->type & DT_INITIAL_SET)
if (cdef->type & D_INTERNAL_INITIAL_SET)
FREE(&cdef->initial);

cdef->type |= DT_INITIAL_SET;
cdef->type |= D_INTERNAL_INITIAL_SET;
cdef->initial = (intptr_t) mutt_str_dup(value);
}

Expand Down
8 changes: 4 additions & 4 deletions config/number.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static int number_string_set(const struct ConfigSet *cs, void *var, struct Confi
return CSR_ERR_INVALID | CSR_INV_TYPE;
}

if ((num < 0) && (cdef->type & DT_NOT_NEGATIVE))
if ((num < 0) && (cdef->type & D_INTEGER_NOT_NEGATIVE))
{
buf_printf(err, _("Option %s may not be negative"), cdef->name);
return CSR_ERR_INVALID | CSR_INV_VALIDATOR;
Expand Down Expand Up @@ -125,7 +125,7 @@ static int number_native_set(const struct ConfigSet *cs, void *var,
return CSR_ERR_INVALID | CSR_INV_TYPE;
}

if ((value < 0) && (cdef->type & DT_NOT_NEGATIVE))
if ((value < 0) && (cdef->type & D_INTEGER_NOT_NEGATIVE))
{
buf_printf(err, _("Option %s may not be negative"), cdef->name);
return CSR_ERR_INVALID | CSR_INV_VALIDATOR;
Expand Down Expand Up @@ -179,7 +179,7 @@ static int number_string_plus_equals(const struct ConfigSet *cs, void *var,
return CSR_ERR_INVALID | CSR_INV_TYPE;
}

if ((result < 0) && (cdef->type & DT_NOT_NEGATIVE))
if ((result < 0) && (cdef->type & D_INTEGER_NOT_NEGATIVE))
{
buf_printf(err, _("Option %s may not be negative"), cdef->name);
return CSR_ERR_INVALID | CSR_INV_VALIDATOR;
Expand Down Expand Up @@ -221,7 +221,7 @@ static int number_string_minus_equals(const struct ConfigSet *cs, void *var,
return CSR_ERR_INVALID | CSR_INV_TYPE;
}

if ((result < 0) && (cdef->type & DT_NOT_NEGATIVE))
if ((result < 0) && (cdef->type & D_INTEGER_NOT_NEGATIVE))
{
buf_printf(err, _("Option %s may not be negative"), cdef->name);
return CSR_ERR_INVALID | CSR_INV_VALIDATOR;
Expand Down
14 changes: 7 additions & 7 deletions config/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ static int path_string_set(const struct ConfigSet *cs, void *var, struct ConfigD
if (value && (value[0] == '\0'))
value = NULL;

if (!value && (cdef->type & DT_NOT_EMPTY))
if (!value && (cdef->type & D_NOT_EMPTY))
{
buf_printf(err, _("Option %s may not be empty"), cdef->name);
return CSR_ERR_INVALID | CSR_INV_VALIDATOR;
Expand All @@ -117,18 +117,18 @@ static int path_string_set(const struct ConfigSet *cs, void *var, struct ConfigD

path_destroy(cs, var, cdef);

const char *str = path_tidy(value, cdef->type & DT_PATH_DIR);
const char *str = path_tidy(value, cdef->type & D_PATH_DIR);
if (!str)
rc |= CSR_SUC_EMPTY;

*(const char **) var = str;
}
else
{
if (cdef->type & DT_INITIAL_SET)
if (cdef->type & D_INTERNAL_INITIAL_SET)
FREE(&cdef->initial);

cdef->type |= DT_INITIAL_SET;
cdef->type |= D_INTERNAL_INITIAL_SET;
cdef->initial = (intptr_t) mutt_str_dup(value);
}

Expand Down Expand Up @@ -167,7 +167,7 @@ static int path_native_set(const struct ConfigSet *cs, void *var,
if (str && (str[0] == '\0'))
value = 0;

if ((value == 0) && (cdef->type & DT_NOT_EMPTY))
if ((value == 0) && (cdef->type & D_NOT_EMPTY))
{
buf_printf(err, _("Option %s may not be empty"), cdef->name);
return CSR_ERR_INVALID | CSR_INV_VALIDATOR;
Expand All @@ -191,7 +191,7 @@ static int path_native_set(const struct ConfigSet *cs, void *var,

path_destroy(cs, var, cdef);

str = path_tidy(str, cdef->type & DT_PATH_DIR);
str = path_tidy(str, cdef->type & D_PATH_DIR);
rc = CSR_SUCCESS;
if (!str)
rc |= CSR_SUC_EMPTY;
Expand Down Expand Up @@ -219,7 +219,7 @@ static int path_reset(const struct ConfigSet *cs, void *var,
{
int rc = CSR_SUCCESS;

const char *str = path_tidy((const char *) cdef->initial, cdef->type & DT_PATH_DIR);
const char *str = path_tidy((const char *) cdef->initial, cdef->type & D_PATH_DIR);
if (!str)
rc |= CSR_SUC_EMPTY;

Expand Down
14 changes: 7 additions & 7 deletions config/regex.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static void regex_destroy(const struct ConfigSet *cs, void *var, const struct Co
/**
* regex_new - Create an Regex from a string
* @param str Regular expression
* @param flags Type flags, e.g. #DT_REGEX_MATCH_CASE
* @param flags Type flags, e.g. #D_REGEX_MATCH_CASE
* @param err Buffer for error messages
* @retval ptr New Regex object
* @retval NULL Error
Expand All @@ -109,14 +109,14 @@ struct Regex *regex_new(const char *str, uint32_t flags, struct Buffer *err)
reg->pattern = mutt_str_dup(str);

/* Should we use smart case matching? */
if (((flags & DT_REGEX_MATCH_CASE) == 0) && mutt_mb_is_lower(str))
if (((flags & D_REGEX_MATCH_CASE) == 0) && mutt_mb_is_lower(str))
rflags |= REG_ICASE;

if ((flags & DT_REGEX_NOSUB))
if ((flags & D_REGEX_NOSUB))
rflags |= REG_NOSUB;

/* Is a prefix of '!' allowed? */
if (((flags & DT_REGEX_ALLOW_NOT) != 0) && (str[0] == '!'))
if (((flags & D_REGEX_ALLOW_NOT) != 0) && (str[0] == '!'))
{
reg->pat_not = true;
str++;
Expand Down Expand Up @@ -184,10 +184,10 @@ static int regex_string_set(const struct ConfigSet *cs, void *var, struct Config
}
else
{
if (cdef->type & DT_INITIAL_SET)
if (cdef->type & D_INTERNAL_INITIAL_SET)
FREE(&cdef->initial);

cdef->type |= DT_INITIAL_SET;
cdef->type |= D_INTERNAL_INITIAL_SET;
cdef->initial = (intptr_t) mutt_str_dup(value);
}

Expand Down Expand Up @@ -248,7 +248,7 @@ static int regex_native_set(const struct ConfigSet *cs, void *var,

if (orig && orig->pattern)
{
const uint32_t flags = orig->pat_not ? DT_REGEX_ALLOW_NOT : 0;
const uint32_t flags = orig->pat_not ? D_REGEX_ALLOW_NOT : 0;
r = regex_new(orig->pattern, flags, err);
if (!r)
rc = CSR_ERR_INVALID;
Expand Down
Loading

0 comments on commit 3e6c9f8

Please sign in to comment.