139 if (!str || !parsed_until || !err)
142 const char *start = str;
156 else if (*str ==
'=')
173 unsigned short number = 0;
176 if (!end_ptr || (number == USHRT_MAX))
179 snprintf(err->
message,
sizeof(err->
message),
_(
"Invalid number: %s"), str);
193 unsigned short number = 1;
199 if (!end_ptr || (number == USHRT_MAX))
202 snprintf(err->
message,
sizeof(err->
message),
_(
"Invalid number: %s"), str);
214 fmt->
leader = (number == 0) ?
' ' :
'0';
262 return def->
parse(str, fmt, def->
did, def->
uid, flags, parsed_until, err);
266 *parsed_until = str + len;
306 snprintf(err->
message,
sizeof(err->
message),
_(
"Unknown expando: %%%.1s"), *parsed_until);
319 while (str[0] !=
'\0')
321 if (*str == terminator)
350 int uid,
char terminator,
352 const char **parsed_until,
360 if (*expando_end != terminator)
366 _(
"Expando is missing terminator: '%c'"), terminator);
370 *parsed_until = expando_end + 1;
375 for (; str < expando_end; str++)
423 erc_match->
get_string(node, data, flags, buf_expando);
425 if (fmt && fmt->
lower)
431 ASSERT(erc_match &&
"Unknown UID");
433 const long num = erc_match->
get_number(node, data, flags);
440 if ((precision < 0) && (fmt->
leader ==
'0'))
447 buf_printf(buf_expando,
"%.*ld", precision, num);
469 if (priv->
color > -1)
474 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 colored objects.
@ MT_COLOR_INDEX
Index: default colour.
Define an Expando format string.
#define EP_NO_CUSTOM_PARSE
Don't use the custom parser.
uint8_t ExpandoParserFlags
Flags for expando_parse(), e.g. EP_CONDITIONAL.
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() -.
#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.
Create/manipulate threading in emails.
@ MUTT_SPECIAL_INDEX
Colour indicator.
struct ExpandoNode * node_new(void)
Create a new empty ExpandoNode.
@ 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.
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.
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.
uint8_t MuttFormatFlags
Flags for expando_render(), e.g. MUTT_FORMAT_FORCESUBJ.
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 * 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.
Private data for an Expando -.
bool has_tree
Contains tree characters, used in $index_format's s.