[neomutt-devel] [PATCH 1/2] Fix $reply_regex

наб nabijaczleweli at nabijaczleweli.xyz
Mon Dec 25 02:04:53 CET 2023


On Sun, Dec 24, 2023 at 12:39:55PM +0000, Richard Russon wrote:
> > > ... flags ...
> > a single 32-bit(!) bitfield is has clearly overstayed its welcome
> Probably
Actually not really, this only really uses 23 bits.
And if you reanalyse the slist separator from a bitfield which it isn't
to a number which it is, then that's 22.

> > but this is mostly hidden by being strewn around and inconsistent nomenclature.
> Suggestions welcome
-- >8 --
enum config_type {
	DT_ADDRESS,	///< e-mail address
	DT_BOOL,	///< boolean option
	DT_ENUM,	///< an enumeration
	DT_HCACHE,	///< header cache backend
	DT_LONG,	///< a number (long)
	DT_MBTABLE,	///< multibyte char table
	DT_NUMBER,	///< a number
	DT_PATH,	///< a path to a file/directory
	DT_QUAD,	///< quad-option (no/yes/ask-no/ask-yes)
	DT_REGEX,	///< regular expressions
	DT_SLIST,	///< a list of strings
	DT_SORT,	///< sorting methods
	DT_STRING,	///< a string
	DT_SYNONYM,	///< synonym for another variable
	DT_MYVAR,	///< a user-defined variable (my_foo)
	DT_END,
};
_Static_assert(DT_END - 1 <= 0xF, "allocate another bit");
#define DTYPE(t) ((enum config_type)((t) & 0xF))

enum config_type_field {
	D_B_ON_STARTUP = 4,
	D_B_NOT_EMPTY,
	D_B_SENSITIVE,

	D_B_CHARSET_SINGLE,
	D_B_CHARSET_STRICT,

	D_B_REDRAW_INDEX,
	D_B_REDRAW_RESORT,
	D_B_REDRAW_RESORT_SUB,
	D_B_REDRAW_RESORT_INIT,

	D_B_INTERNAL_FREE_CONFIGDEF,
	D_B_INTERNAL_DEPRECATED,
	D_B_INTERNAL_INHERITED,
	D_B_INTERNAL_INITIAL_SET,

	D_B_CUSTOM_BIT_0,
	D_B_CUSTOM_BIT_1,
	D_B_CUSTOM_BIT_2,
	D_B_CUSTOM_BIT_3,
	D_B_CUSTOM_BIT_4,

	D_B_END,
};
_Static_assert(D_B_END <= 32, "We need to pack everything into 32 bits");

#define D_ON_STARTUP	(1 << D_B_ON_STARTUP)	///< May only be set at startup
#define D_NOT_EMPTY	(1 << D_B_NOT_EMPTY)	///< Empty strings are not allowed
#define D_SENSITIVE	(1 << D_B_SENSITIVE)	///< Contains sensitive value, e.g. password

#define D_CHARSET_SINGLE	(1 << D_B_CHARSET_SINGLE) ///< Flag for charset_validator to allow only one charset
#define D_CHARSET_STRICT	(1 << D_B_CHARSET_STRICT) ///< Flag for charset_validator to use strict char check

#define D_REDRAW_INDEX		(1 << D_B_REDRAW_INDEX) 	///< Redraw the index menu (MENU_INDEX)
#define D_REDRAW_RESORT		(1 << D_B_REDRAW_RESORT) 		///< Resort the mailbox
#define D_REDRAW_RESORT_SUB	(1 << D_B_REDRAW_RESORT_SUB) 		///< Resort subthreads
#define D_REDRAW_RESORT_INIT	(1 << D_B_REDRAW_RESORT_INIT) 	///< Resort from scratch

#define D_INTERNAL_FREE_CONFIGDEF	(1 << D_B_INTERNAL_FREE_CONFIGDEF)		///< Config item must have its ConfigDef freed
#define D_INTERNAL_DEPRECATED		(1 << D_B_INTERNAL_DEPRECATED)	///< Config item shouldn't be used any more
#define D_INTERNAL_INHERITED		(1 << D_B_INTERNAL_INHERITED)		///< Config item is inherited
#define D_INTERNAL_INITIAL_SET		(1 << D_B_INTERNAL_INITIAL_SET)		///< Config item must have its initial value freed

#define D_CUSTOM_BIT_0	(1 << D_B_CUSTOM_BIT_0)
#define D_CUSTOM_BIT_1	(1 << D_B_CUSTOM_BIT_1)
#define D_CUSTOM_BIT_2	(1 << D_B_CUSTOM_BIT_2)
#define D_CUSTOM_BIT_3	(1 << D_B_CUSTOM_BIT_3)
#define D_CUSTOM_BIT_4	(1 << D_B_CUSTOM_BIT_4)



#define D_STRING_MAILBOX D_CUSTOM_BIT_0	///< Don't perform path expansions
#define D_STRING_COMMAND D_CUSTOM_BIT_1	///< A command

#define D_INTEGER_NOT_NEGATIVE D_CUSTOM_BIT_0	///< Negative numbers are not allowed

#define D_PATH_DIR  D_CUSTOM_BIT_0	///< Path is a directory
#define D_PATH_FILE D_CUSTOM_BIT_1	///< Path is a file

#define D_REGEX_MATCH_CASE D_CUSTOM_BIT_0	///< Case-sensitive matching
#define D_REGEX_ALLOW_NOT  D_CUSTOM_BIT_1	///< Regex can begin with '!'
#define D_REGEX_NOSUB      D_CUSTOM_BIT_2	///< Do not report what was matched (REG_NOSUB)

#define D_SLIST_SEP_SPACE (0b00 << D_B_CUSTOM_BIT_0)	///< Slist items are space-separated
#define D_SLIST_SEP_COMMA (0b01 << D_B_CUSTOM_BIT_0)	///< Slist items are comma-separated
#define D_SLIST_SEP_COLON (0b10 << D_B_CUSTOM_BIT_0)	///< Slist items are colon-separated
#define D_SLIST_SEP_MASK  (D_CUSTOM_BIT_0 | D_CUSTOM_BIT_1)

#define D_SLIST_ALLOW_DUPES    D_CUSTOM_BIT_2	///< Slist may contain duplicates
#define D_SLIST_ALLOW_EMPTY    D_CUSTOM_BIT_3	///< Slist may be empty
#define D_SLIST_CASE_SENSITIVE D_CUSTOM_BIT_4	///< Slist is case-sensitive

#define D_SORT_LAST    D_CUSTOM_BIT_0	///< Sort flag for -last prefix
#define D_SORT_REVERSE D_CUSTOM_BIT_1	///< Sort flag for -reverse prefix


#define IS_MAILBOX(flags)   (DTYPE(flags) == DT_STRING && (flags & D_STRING_MAILBOX))
#define IS_COMMAND(flags)   (DTYPE(flags) == DT_STRING && (flags & D_STRING_COMMAND))
-- >8 --

This works perfectly well with the existing code,
is trivial to expand in the future,
and is nomenclaturised consistently and scopedly.

devel/config-rebitmap

> > (cs_register_variables() is always called with DT_NO_FLAGS (0)
> >  #define DT_DISABLED      (1 << 30) ///< Config item is disabled
> Yes.  I _had_ plans for that, but I haven't got around to them.
So, dead code.

If you actually start using it you can now trivially and with no
potential conflicts or overflows (imagine!) add it with
-- >8 --
diff --git a/config/types.h b/config/types.h
index a1c50e70..073b943b 100644
--- a/config/types.h
+++ b/config/types.h
@@ -64,4 +64,5 @@ enum config_type_field {
 	D_B_INTERNAL_INHERITED,
 	D_B_INTERNAL_INITIAL_SET,
+	D_B_INTERNAL_DISABLED,
 
 	D_B_CUSTOM_BIT_0,
@@ -91,4 +92,5 @@ _Static_assert(D_B_END <= 32, "We need to pack everything into 32 bits");
 #define D_INTERNAL_INHERITED		(1 << D_B_INTERNAL_INHERITED)		///< Config item is inherited
 #define D_INTERNAL_INITIAL_SET		(1 << D_B_INTERNAL_INITIAL_SET)		///< Config item must have its initial value freed
+#define D_INTERNAL_DISABLED		(1 << D_B_INTERNAL_DISABLED)		///< Config item is disabled
 
 #define D_CUSTOM_BIT_0	(1 << D_B_CUSTOM_BIT_0)
-- >8 --

> > #define DT_INHERIT_ACC   (1 << 12) ///< Config item can be Account-specific
> > #define DT_INHERIT_MBOX  (1 << 13) ///< Config item can be Mailbox-specific
> > are all unused (first two never checked, latter never set)
> The config system supports subsets of config.
Maybe (I see a D_INTERNAL_INHERITED flag).

But
> These are for config inheritance.
is a no probably:
  $ git grep DT_INHERIT_ origin/main
  origin/main:config/types.h:#define DT_INHERIT_ACC   (1 << 12) ///< Config item can be Account-specific
  origin/main:config/types.h:#define DT_INHERIT_MBOX  (1 << 13) ///< Config item can be Mailbox-specific
  origin/main:debug/graphviz.c:    dot_config(fp, m->name, DT_INHERIT_MBOX, m->sub, links);
  origin/main:debug/graphviz.c:    dot_config(fp, a->name, DT_INHERIT_ACC, a->sub, links);
and with how dot_config runs (if(!(c->type & flag)) continue;),
this is dead code, and there aren't any overlapping flags.

наб
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://mailman.neomutt.org/pipermail/neomutt-devel-neomutt.org/attachments/20231225/c44b57df/attachment.sig>


More information about the neomutt-devel mailing list