140 if (!str || !parsed_until || !err)
143 const char *start = str;
157 else if (*str ==
'=')
174 unsigned short number = 0;
177 if (!end_ptr || (number == USHRT_MAX))
180 snprintf(err->
message,
sizeof(err->
message),
_(
"Invalid number: %s"), str);
194 unsigned short number = 1;
200 if (!end_ptr || (number == USHRT_MAX))
203 snprintf(err->
message,
sizeof(err->
message),
_(
"Invalid number: %s"), str);
215 fmt->
leader = (number == 0) ?
' ' :
'0';
265 return def->
parse(str, fmt, def->
did, def->
uid, flags, parsed_until, err);
269 *parsed_until = str + len;
306 *parsed_until = str + len;
310 flags, parsed_until, err);
311 if (node || (err->
message[0] !=
'\0'))
360 snprintf(err->
message,
sizeof(err->
message),
_(
"Unknown expando: %%%.1s"), *parsed_until);
400 const char *end = str + strspn(str,
"abcdefghijklmnopqrstuvwxyz0123456789-");
410 snprintf(err->
message,
sizeof(err->
message),
_(
"Expando is missing closing '}'"));
416 _(
"Unknown expando: %%{%.*s}"), (
int) (end - str), str);
425 if ((*parsed_until)[0] ==
'}')
446 while (str[0] !=
'\0')
448 if (*str == terminator)
477 int uid,
char terminator,
479 const char **parsed_until,
487 if (*expando_end != terminator)
493 _(
"Expando is missing terminator: '%c'"), terminator);
497 *parsed_until = expando_end + 1;
502 for (; str < expando_end; str++)
550 erc_match->
get_string(node, data, flags, buf_expando);
552 if (fmt && fmt->
lower)
558 ASSERT(erc_match &&
"Unknown UID");
560 const long num = erc_match->
get_number(node, data, flags);
567 if ((precision < 0) && (fmt->
leader ==
'0'))
574 buf_printf(buf_expando,
"%.*ld", precision, num);
596 if (priv->
color > -1)
601 if (priv->
color > -1)
const char * mutt_str_atous(const char *str, unsigned short *dst)
Convert ASCII string to an unsigned short.
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Color and attribute parsing.
ColorId
List of all coloured objects.
@ MT_COLOR_INDEX
Index: default colour.
bool mutt_isdigit(int arg)
Wrapper for isdigit(3)
Define an Expando format string.
uint8_t ExpandoParserFlags
const struct ExpandoRenderCallback * find_get_string(const struct ExpandoRenderCallback *erc, int did, int uid)
Find a get_string() callback function.
void buf_lower_special(struct Buffer *buf)
Convert to lowercase, excluding special characters.
const struct ExpandoRenderCallback * find_get_number(const struct ExpandoRenderCallback *erc, int did, int uid)
Find a get_number() callback function.
int node_expando_render(const struct ExpandoNode *node, const struct ExpandoRenderCallback *erc, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
Render an Expando Node - Implements ExpandoNode::render() -.
Convenience wrapper for the gui headers.
@ MUTT_SPECIAL_INDEX
Colour indicator.
#define FREE(x)
Free memory and set the pointer to NULL.
#define MIN(a, b)
Return the minimum of two values.
#define MUTT_MEM_CALLOC(n, type)
Convenience wrapper for the library headers.
bool mutt_strn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings (to a maximum), safely.
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
struct ExpandoNode * node_new(void)
Create a new empty ExpandoNode.
void node_free(struct ExpandoNode **ptr)
Free an ExpandoNode and its private data.
@ ENT_EXPANDO
Expando, e.g. 'n'.
struct ExpandoNode * node_expando_parse(const char *str, const struct ExpandoDefinition *defs, ExpandoParserFlags flags, const char **parsed_until, struct ExpandoParseError *err)
Parse an Expando format string.
void node_expando_private_free(void **ptr)
Free Expando private data - Implements ExpandoNode::ndata_free()
void node_expando_set_color(const struct ExpandoNode *node, int cid)
Set the colour for an Expando.
void node_expando_set_has_tree(const struct ExpandoNode *node, bool has_tree)
Set the has_tree flag for an Expando.
struct ExpandoNode * parse_long_name(const char *str, const struct ExpandoDefinition *defs, ExpandoParserFlags flags, struct ExpandoFormat *fmt, const char **parsed_until, struct ExpandoParseError *err)
Create an expando by its long name.
void add_color(struct Buffer *buf, enum ColorId cid)
Add a colour code to a buffer.
struct NodeExpandoPrivate * node_expando_private_new(void)
Create new Expando private data.
struct ExpandoNode * node_expando_new(struct ExpandoFormat *fmt, int did, int uid)
Create a new Expando ExpandoNode.
struct ExpandoNode * node_expando_parse_enclosure(const char *str, int did, int uid, char terminator, struct ExpandoFormat *fmt, const char **parsed_until, struct ExpandoParseError *err)
Parse an enclosed Expando.
struct ExpandoNode * node_expando_parse_name(const char *str, const struct ExpandoDefinition *defs, ExpandoParserFlags flags, const char **parsed_until, struct ExpandoParseError *err)
Parse an Expando format string.
const char * skip_until_ch(const char *str, char terminator)
Search a string for a terminator character.
struct ExpandoNode * parse_short_name(const char *str, const struct ExpandoDefinition *defs, ExpandoParserFlags flags, struct ExpandoFormat *fmt, const char **parsed_until, struct ExpandoParseError *err)
Create an expando by its short name.
struct ExpandoFormat * parse_format(const char *str, const char **parsed_until, struct ExpandoParseError *err)
Parse a format string.
Expando Node for an Expando.
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Render Expandos using Data.
String manipulation buffer.
char * data
Pointer to data.
Definition of a format string.
short uid
Unique ID in domain.
struct ExpandoNode *(* parse)(const char *str, struct ExpandoFormat *fmt, int did, int uid, ExpandoParserFlags flags, const char **parsed_until, struct ExpandoParseError *err)
const char * long_name
Long Expando name, e.g. "name".
const char * short_name
Short Expando name, e.g. "n".
int uid
Unique ID, e.g. ED_EMA_SIZE.
void * ndata
Private node data.
struct ExpandoFormat * format
Formatting info.
int(* render)(const struct ExpandoNode *node, const struct ExpandoRenderCallback *erc, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
int did
Domain ID, e.g. ED_EMAIL.
const char * text
Node-specific text.
enum ExpandoNodeType type
Type of Node, e.g. ENT_EXPANDO.
void(* ndata_free)(void **ptr)
Function to free the private node data.
Buffer for parsing errors.
char message[1024]
Error message.
const char * position
Position of error in original string.
get_string_t get_string
Callback function to get a string.
get_number_t get_number
Callback function to get a number.
Private data for an Expando -.
bool has_tree
Contains tree characters, used in $index_format's s.