NeoMutt  2024-10-02-37-gfa9146
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
Expando Parse API

Custom function to parse a format string into a Node. More...

Functions

struct ExpandoNodeparse_folder_date (const char *str, int did, int uid, ExpandoParserFlags flags, const char **parsed_until, struct ExpandoParseError *err)
 Parse a Date Expando - Implements ExpandoDefinition::parse() -.
 
struct ExpandoNodenode_condbool_parse (const char *str, const struct ExpandoDefinition *defs, ExpandoParserFlags flags, const char **parsed_until, struct ExpandoParseError *err)
 Parse a CondBool format string - Implements ExpandoDefinition::parse() -.
 
struct ExpandoNodenode_conddate_parse (const char *str, int did, int uid, const char **parsed_until, struct ExpandoParseError *err)
 Parse a CondDate format string - Implements ExpandoDefinition::parse() -.
 
struct ExpandoNodenode_padding_parse (const char *str, int did, int uid, ExpandoParserFlags flags, const char **parsed_until, struct ExpandoParseError *err)
 Parse a Padding Expando - Implements ExpandoDefinition::parse() -.
 
struct ExpandoNodeparse_index_date_recv_local (const char *str, int did, int uid, ExpandoParserFlags flags, const char **parsed_until, struct ExpandoParseError *err)
 Parse a Date Expando - Implements ExpandoDefinition::parse() -.
 
struct ExpandoNodeparse_index_date_local (const char *str, int did, int uid, ExpandoParserFlags flags, const char **parsed_until, struct ExpandoParseError *err)
 Parse a Date Expando - Implements ExpandoDefinition::parse() -.
 
struct ExpandoNodeparse_index_date (const char *str, int did, int uid, ExpandoParserFlags flags, const char **parsed_until, struct ExpandoParseError *err)
 Parse a Date Expando - Implements ExpandoDefinition::parse() -.
 
struct ExpandoNodeparse_index_hook (const char *str, int did, int uid, ExpandoParserFlags flags, const char **parsed_until, struct ExpandoParseError *err)
 Parse an index-hook - Implements ExpandoDefinition::parse() -.
 
struct ExpandoNodeparse_tags_transformed (const char *str, int did, int uid, ExpandoParserFlags flags, const char **parsed_until, struct ExpandoParseError *err)
 Parse a Tags-Transformed Expando - Implements ExpandoDefinition::parse() -.
 
struct ExpandoNodeparse_subject (const char *str, int did, int uid, ExpandoParserFlags flags, const char **parsed_until, struct ExpandoParseError *err)
 Parse a Subject Expando - Implements ExpandoDefinition::parse() -.
 
struct ExpandoNodeparse_pgp_date (const char *str, int did, int uid, ExpandoParserFlags flags, const char **parsed_until, struct ExpandoParseError *err)
 Parse a Date Expando - Implements ExpandoDefinition::parse() -.
 

Detailed Description

Custom function to parse a format string into a Node.

Parameters
[in]strString to parse
[in]didDomain ID of the data
[in]uidUnique ID of the data
[in]flagsFlags, e.g. EP_CONDITIONAL
[out]parsed_untilFirst character after the parsed string
[out]errBuffer for error message
Return values
ptrParsed Node

Function Documentation

◆ parse_folder_date()

struct ExpandoNode * parse_folder_date ( const char *  str,
int  did,
int  uid,
ExpandoParserFlags  flags,
const char **  parsed_until,
struct ExpandoParseError err 
)

Parse a Date Expando - Implements ExpandoDefinition::parse() -.

Parse a custom Expando of the form, "%[string]". The "string" will be passed to strftime().

Definition at line 62 of file config.c.

65{
66 if (flags & EP_CONDITIONAL)
67 {
68 return node_conddate_parse(str + 1, did, uid, parsed_until, err);
69 }
70
71 return node_expando_parse_enclosure(str, did, uid, ']', parsed_until, err);
72}
#define EP_CONDITIONAL
Expando is being used as a condition.
Definition: definition.h:43
struct ExpandoNode * node_conddate_parse(const char *str, int did, int uid, const char **parsed_until, struct ExpandoParseError *err)
Parse a CondDate format string - Implements ExpandoDefinition::parse() -.
struct ExpandoNode * node_expando_parse_enclosure(const char *str, int did, int uid, char terminator, const char **parsed_until, struct ExpandoParseError *err)
Parse an enclosed Expando.
Definition: node_expando.c:285
+ Here is the call graph for this function:

◆ node_condbool_parse()

struct ExpandoNode * node_condbool_parse ( const char *  str,
const struct ExpandoDefinition defs,
ExpandoParserFlags  flags,
const char **  parsed_until,
struct ExpandoParseError err 
)

Parse a CondBool format string - Implements ExpandoDefinition::parse() -.

Definition at line 63 of file node_condbool.c.

67{
68 const struct ExpandoDefinition *def = defs;
69
70 const char *format_end = skip_until_classic_expando(str);
71 const char *expando_end = skip_classic_expando(format_end, defs);
72 char expando[128] = { 0 };
73 const int expando_len = expando_end - format_end;
74 mutt_strn_copy(expando, format_end, expando_len, sizeof(expando));
75
76 while (def && def->short_name)
77 {
78 if (mutt_str_equal(def->short_name, expando))
79 {
80 if (def->parse)
81 {
82 return def->parse(str, def->did, def->uid, flags, parsed_until, err);
83 }
84 else
85 {
86 *parsed_until = expando_end;
87 return node_condbool_new(format_end, expando_end, def->did, def->uid);
88 }
89 }
90
91 def++;
92 }
93
94 err->position = format_end;
95 // L10N: e.g. "Unknown expando: %Q"
96 snprintf(err->message, sizeof(err->message), _("Unknown expando: %%%.*s"),
97 expando_len, format_end);
98 return NULL;
99}
const char * skip_classic_expando(const char *str, const struct ExpandoDefinition *defs)
Skip over the text of an Expando.
Definition: helpers.c:144
const char * skip_until_classic_expando(const char *start)
Search through string until we reach an Expando character.
Definition: helpers.c:128
#define _(a)
Definition: message.h:28
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:660
char * mutt_strn_copy(char *dest, const char *src, size_t len, size_t dsize)
Copy a sub-string into a buffer.
Definition: string.c:360
struct ExpandoNode * node_condbool_new(const char *start, const char *end, int did, int uid)
Create a new CondBool ExpandoNode.
Definition: node_condbool.c:48
Definition of a format string.
Definition: definition.h:52
short uid
Unique ID in domain.
Definition: definition.h:56
struct ExpandoNode *(* parse)(const char *str, int did, int uid, ExpandoParserFlags flags, const char **parsed_until, struct ExpandoParseError *err)
Definition: definition.h:71
short did
Domain ID.
Definition: definition.h:55
const char * short_name
Short Expando name, e.g. "n".
Definition: definition.h:53
const char * position
Position of error in original string.
Definition: parse.h:37
char message[256]
Error message.
Definition: parse.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ node_conddate_parse()

struct ExpandoNode * node_conddate_parse ( const char *  str,
int  did,
int  uid,
const char **  parsed_until,
struct ExpandoParseError err 
)

Parse a CondDate format string - Implements ExpandoDefinition::parse() -.

Definition at line 208 of file node_conddate.c.

211{
212 int count = 0;
213 char period = '\0';
214
215 if (isdigit(*str))
216 {
217 unsigned short number = 0;
218 const char *end_ptr = mutt_str_atous(str, &number);
219
220 // NOTE(g0mb4): str is NOT null-terminated
221 if (!end_ptr || (number == USHRT_MAX))
222 {
223 err->position = str;
224 snprintf(err->message, sizeof(err->message), _("Invalid number: %s"), str);
225 return NULL;
226 }
227
228 count = number;
229 str = end_ptr;
230 };
231
232 // Allowed periods: year, month, week, day, hour, minute
233 if (!strchr("ymwdHM", *str))
234 {
235 err->position = str;
236 snprintf(err->message, sizeof(err->message),
237 // L10N: The 'ymwdHM' should not be translated
238 _("Invalid time period: '%c', must be one of 'ymwdHM'"), *str);
239 return NULL;
240 }
241
242 period = *str;
243 *parsed_until = str + 1;
244
245 return node_conddate_new(count, period, did, uid);
246}
const char * mutt_str_atous(const char *str, unsigned short *dst)
Convert ASCII string to an unsigned short.
Definition: atoi.c:266
struct ExpandoNode * node_conddate_new(int count, char period, int did, int uid)
Create a new CondDate ExpandoNode.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ node_padding_parse()

struct ExpandoNode * node_padding_parse ( const char *  str,
int  did,
int  uid,
ExpandoParserFlags  flags,
const char **  parsed_until,
struct ExpandoParseError err 
)

Parse a Padding Expando - Implements ExpandoDefinition::parse() -.

Parse a Padding Expando of the form, "%|X", "%>X" or "%*X", where the character 'X' will be used to fill the space.

Definition at line 234 of file node_padding.c.

237{
238 if (flags & EP_CONDITIONAL)
239 {
240 snprintf(err->message, sizeof(err->message),
241 // L10N: Conditional Expandos can only depend on other Expandos
242 // e.g. "%<X?apple>" displays "apple" if "%X" is true.
243 _("Padding cannot be used as a condition"));
244 err->position = str;
245 return NULL;
246 }
247
248 enum ExpandoPadType pt = 0;
249 if (*str == '|')
250 {
251 pt = EPT_FILL_EOL;
252 }
253 else if (*str == '>')
254 {
255 pt = EPT_HARD_FILL;
256 }
257 else if (*str == '*')
258 {
259 pt = EPT_SOFT_FILL;
260 }
261 else
262 {
263 return NULL;
264 }
265 str++;
266
267 size_t consumed = mutt_mb_charlen(str, NULL);
268 if (consumed == 0)
269 {
270 str = " "; // Default to a space
271 consumed = 1;
272 }
273
274 *parsed_until = str + consumed;
275 return node_padding_new(pt, str, str + consumed);
276}
int mutt_mb_charlen(const char *s, int *width)
Count the bytes in a (multibyte) character.
Definition: mbyte.c:55
struct ExpandoNode * node_padding_new(enum ExpandoPadType pad_type, const char *start, const char *end)
Creata new Padding ExpandoNode.
Definition: node_padding.c:201
ExpandoPadType
Padding type.
Definition: node_padding.h:43
@ EPT_FILL_EOL
Fill to the end-of-line.
Definition: node_padding.h:44
@ EPT_SOFT_FILL
Soft-fill: right-hand-side will be truncated.
Definition: node_padding.h:46
@ EPT_HARD_FILL
Hard-fill: left-hand-side will be truncated.
Definition: node_padding.h:45
+ Here is the call graph for this function:

◆ parse_index_date_recv_local()

struct ExpandoNode * parse_index_date_recv_local ( const char *  str,
int  did,
int  uid,
ExpandoParserFlags  flags,
const char **  parsed_until,
struct ExpandoParseError err 
)

Parse a Date Expando - Implements ExpandoDefinition::parse() -.

Parse a custom Expando of the form, "%(string)". The "string" will be passed to strftime().

Definition at line 163 of file mutt_config.c.

167{
168 if (flags & EP_CONDITIONAL)
169 {
170 return node_conddate_parse(str + 1, did, uid, parsed_until, err);
171 }
172
173 return node_expando_parse_enclosure(str, did, uid, ')', parsed_until, err);
174}
+ Here is the call graph for this function:

◆ parse_index_date_local()

struct ExpandoNode * parse_index_date_local ( const char *  str,
int  did,
int  uid,
ExpandoParserFlags  flags,
const char **  parsed_until,
struct ExpandoParseError err 
)

Parse a Date Expando - Implements ExpandoDefinition::parse() -.

Parse a custom expando of the form, "%[string]". The "string" will be passed to strftime().

Definition at line 182 of file mutt_config.c.

185{
186 if (flags & EP_CONDITIONAL)
187 {
188 return node_conddate_parse(str + 1, did, uid, parsed_until, err);
189 }
190
191 return node_expando_parse_enclosure(str, did, uid, ']', parsed_until, err);
192}
+ Here is the call graph for this function:

◆ parse_index_date()

struct ExpandoNode * parse_index_date ( const char *  str,
int  did,
int  uid,
ExpandoParserFlags  flags,
const char **  parsed_until,
struct ExpandoParseError err 
)

Parse a Date Expando - Implements ExpandoDefinition::parse() -.

Parse a custom Expando of the form, "%{string}". The "string" will be passed to strftime().

Definition at line 200 of file mutt_config.c.

203{
204 if (flags & EP_CONDITIONAL)
205 {
206 return node_conddate_parse(str + 1, did, uid, parsed_until, err);
207 }
208
209 return node_expando_parse_enclosure(str, did, uid, '}', parsed_until, err);
210}
+ Here is the call graph for this function:

◆ parse_index_hook()

struct ExpandoNode * parse_index_hook ( const char *  str,
int  did,
int  uid,
ExpandoParserFlags  flags,
const char **  parsed_until,
struct ExpandoParseError err 
)

Parse an index-hook - Implements ExpandoDefinition::parse() -.

Parse a custom Expando of the form, "%@name@". The "name" will be looked up as an index-hook, then the result parsed as an Expando.

Definition at line 219 of file mutt_config.c.

222{
223 if (flags & EP_CONDITIONAL)
224 {
225 snprintf(err->message, sizeof(err->message),
226 _("index-hook cannot be used as a condition"));
227 err->position = str;
228 return NULL;
229 }
230
231 return node_expando_parse_enclosure(str, did, uid, '@', parsed_until, err);
232}
+ Here is the call graph for this function:

◆ parse_tags_transformed()

struct ExpandoNode * parse_tags_transformed ( const char *  str,
int  did,
int  uid,
ExpandoParserFlags  flags,
const char **  parsed_until,
struct ExpandoParseError err 
)

Parse a Tags-Transformed Expando - Implements ExpandoDefinition::parse() -.

Parse a custom expando of the form, "%G?" where '?' is an alphabetic character.

Definition at line 239 of file mutt_config.c.

242{
243 // Let the basic expando parser do the work
244 flags |= EP_NO_CUSTOM_PARSE;
245 struct ExpandoNode *node = node_expando_parse(str, IndexFormatDef, flags,
246 parsed_until, err);
247
248 // but adjust the node to take one more character
249 node->text = mutt_strn_dup((*parsed_until) - 1, 2);
250 (*parsed_until)++;
251
252 if (flags & EP_CONDITIONAL)
253 {
254 node->type = ENT_CONDBOOL;
256 }
257
258 return node;
259}
#define EP_NO_CUSTOM_PARSE
Don't use the custom parser.
Definition: definition.h:44
int node_condbool_render(const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
Callback for every bool node - Implements ExpandoNode::render() -.
char * mutt_strn_dup(const char *begin, size_t len)
Duplicate a sub-string.
Definition: string.c:380
const struct ExpandoDefinition IndexFormatDef[]
Expando definitions.
Definition: mutt_config.c:301
@ ENT_CONDBOOL
True/False boolean condition.
Definition: node.h:42
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.
Definition: node_expando.c:229
Basic Expando Node.
Definition: node.h:67
int(* render)(const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
Definition: node.h:91
const char * text
Node-specific text.
Definition: node.h:73
enum ExpandoNodeType type
Type of Node, e.g. ENT_EXPANDO.
Definition: node.h:68
+ Here is the call graph for this function:

◆ parse_subject()

struct ExpandoNode * parse_subject ( const char *  str,
int  did,
int  uid,
ExpandoParserFlags  flags,
const char **  parsed_until,
struct ExpandoParseError err 
)

Parse a Subject Expando - Implements ExpandoDefinition::parse() -.

Parse a Subject Expando, "%s", into two separate Nodes. One for the tree, one for the subject.

Definition at line 267 of file mutt_config.c.

270{
271 // Let the basic expando parser do the work
272 flags |= EP_NO_CUSTOM_PARSE;
273 struct ExpandoNode *node_subj = node_expando_parse(str, IndexFormatDef, flags,
274 parsed_until, err);
275
277 // Move the formatting info to the container
278 struct ExpandoNode *node_cont = node_container_new();
279 node_cont->format = node_subj->format;
280 node_subj->format = NULL;
281
282 node_add_child(node_cont, node_tree);
283 node_add_child(node_cont, node_subj);
284
285 return node_cont;
286}
@ ED_ENVELOPE
Envelope ED_ENV_ ExpandoDataEnvelope.
Definition: domain.h:42
@ ED_ENV_THREAD_TREE
Email.tree.
Definition: envelope.h:117
void node_add_child(struct ExpandoNode *node, struct ExpandoNode *child)
Add a child to an ExpandoNode.
Definition: node.c:76
struct ExpandoNode * node_container_new(void)
Create a new Container ExpandoNode.
struct ExpandoNode * node_expando_new(struct ExpandoFormat *fmt, int did, int uid)
Create a new Expando ExpandoNode.
Definition: node_expando.c:78
struct ExpandoFormat * format
Formatting info.
Definition: node.h:72
+ Here is the call graph for this function:

◆ parse_pgp_date()

struct ExpandoNode * parse_pgp_date ( const char *  str,
int  did,
int  uid,
ExpandoParserFlags  flags,
const char **  parsed_until,
struct ExpandoParseError err 
)

Parse a Date Expando - Implements ExpandoDefinition::parse() -.

Parse a custom Expando of the form, "%[string]". The "string" will be passed to strftime().

Definition at line 62 of file config.c.

65{
66 if (flags & EP_CONDITIONAL)
67 {
68 return node_conddate_parse(str + 1, did, uid, parsed_until, err);
69 }
70
71 return node_expando_parse_enclosure(str, did, uid, ']', parsed_until, err);
72}
+ Here is the call graph for this function: