NeoMutt  2024-10-02-24-gaf3843
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 *error)
 Parse a Date Expando - Implements ExpandoDefinition::parse() -.
 
struct ExpandoNodenode_condbool_parse (const char *str, const char **parsed_until, const struct ExpandoDefinition *defs, ExpandoParserFlags flags, struct ExpandoParseError *err)
 Parse a CondBool format string - Implements ExpandoDefinition::parse() -.
 
struct ExpandoNodenode_conddate_parse (const char *str, const char **parsed_until, int did, int uid, 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 *error)
 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 *error)
 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 *error)
 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 *error)
 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 *error)
 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 *error)
 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 *error)
 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 error 
)

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, parsed_until, did, uid, error);
69 }
70
71 return node_expando_parse_enclosure(str, parsed_until, did, uid, ']', error);
72}
#define EP_CONDITIONAL
Expando is being used as a condition.
Definition: definition.h:43
struct ExpandoNode * node_conddate_parse(const char *str, const char **parsed_until, int did, int uid, struct ExpandoParseError *err)
Parse a CondDate format string - Implements ExpandoDefinition::parse() -.
struct ExpandoNode * node_expando_parse_enclosure(const char *str, const char **parsed_until, int did, int uid, char terminator, struct ExpandoParseError *err)
Parse an enclosed Expando.
Definition: node_expando.c:294
+ Here is the call graph for this function:

◆ node_condbool_parse()

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

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

Definition at line 66 of file node_condbool.c.

70{
71 const struct ExpandoDefinition *def = defs;
72
73 const char *format_end = skip_until_classic_expando(str);
74 const char *expando_end = skip_classic_expando(format_end, defs);
75 char expando[128] = { 0 };
76 const int expando_len = expando_end - format_end;
77 mutt_strn_copy(expando, format_end, expando_len, sizeof(expando));
78
79 while (def && def->short_name)
80 {
81 if (mutt_str_equal(def->short_name, expando))
82 {
83 if (def->parse)
84 {
85 return def->parse(str, def->did, def->uid, flags, parsed_until, err);
86 }
87 else
88 {
89 *parsed_until = expando_end;
90 return node_condbool_new(format_end, expando_end, def->did, def->uid);
91 }
92 }
93
94 def++;
95 }
96
97 err->position = format_end;
98 // L10N: e.g. "Unknown expando: %Q"
99 snprintf(err->message, sizeof(err->message), _("Unknown expando: %%%.*s"),
100 expando_len, format_end);
101 return NULL;
102}
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:36
char message[256]
Error message.
Definition: parse.h:35
+ 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,
const char **  parsed_until,
int  did,
int  uid,
struct ExpandoParseError err 
)

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

Definition at line 148 of file node_conddate.c.

150{
151 int count = 1;
152 char period = '\0';
153
154 if (isdigit(*str))
155 {
156 unsigned short number = 0;
157 const char *end_ptr = mutt_str_atous(str, &number);
158
159 // NOTE(g0mb4): str is NOT null-terminated
160 if (!end_ptr || (number == USHRT_MAX))
161 {
162 err->position = str;
163 snprintf(err->message, sizeof(err->message), _("Invalid number: %s"), str);
164 return NULL;
165 }
166
167 count = number;
168 str = end_ptr;
169 };
170
171 // Allowed periods: year, month, week, day, hour, minute
172 if (!strchr("ymwdHM", *str))
173 {
174 err->position = str;
175 snprintf(err->message, sizeof(err->message),
176 // L10N: The 'ymwdHM' should not be translated
177 _("Invalid time period: '%c', must be one of 'ymwdHM'"), *str);
178 return NULL;
179 }
180
181 period = *str;
182 *parsed_until = str + 1;
183
184 return node_conddate_new(count, period, did, uid);
185}
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 235 of file node_padding.c.

238{
239 if (flags & EP_CONDITIONAL)
240 {
241 snprintf(err->message, sizeof(err->message),
242 // L10N: Conditional Expandos can only depend on other Expandos
243 // e.g. "%<X?apple>" displays "apple" if "%X" is true.
244 _("Padding cannot be used as a condition"));
245 err->position = str;
246 return NULL;
247 }
248
249 enum ExpandoPadType pt = 0;
250 if (*str == '|')
251 {
252 pt = EPT_FILL_EOL;
253 }
254 else if (*str == '>')
255 {
256 pt = EPT_HARD_FILL;
257 }
258 else if (*str == '*')
259 {
260 pt = EPT_SOFT_FILL;
261 }
262 else
263 {
264 return NULL;
265 }
266 str++;
267
268 const size_t consumed = mutt_mb_charlen(str, NULL);
269
270 *parsed_until = str + consumed;
271 return node_padding_new(pt, str, str + consumed);
272}
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 error 
)

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, parsed_until, did, uid, error);
171 }
172
173 return node_expando_parse_enclosure(str, parsed_until, did, uid, ')', error);
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 error 
)

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, parsed_until, did, uid, error);
189 }
190
191 return node_expando_parse_enclosure(str, parsed_until, did, uid, ']', error);
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 error 
)

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, parsed_until, did, uid, error);
207 }
208
209 return node_expando_parse_enclosure(str, parsed_until, did, uid, '}', error);
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 error 
)

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(error->message, sizeof(error->message),
226 _("index-hook cannot be used as a condition"));
227 error->position = str;
228 return NULL;
229 }
230
231 return node_expando_parse_enclosure(str, parsed_until, did, uid, '@', error);
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 error 
)

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, parsed_until,
246 IndexFormatDef, flags, error);
247
248 // but adjust the node to take one more character
249 node->end++;
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() -.
const struct ExpandoDefinition IndexFormatDef[]
Expando definitions.
Definition: mutt_config.c:302
@ ENT_CONDBOOL
True/False boolean condition.
Definition: node.h:42
struct ExpandoNode * node_expando_parse(const char *str, const char **parsed_until, const struct ExpandoDefinition *defs, ExpandoParserFlags flags, struct ExpandoParseError *err)
Parse an Expando format string.
Definition: node_expando.c:237
Basic Expando Node.
Definition: node.h:69
int(* render)(const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
Definition: node.h:96
const char * end
End of string data.
Definition: node.h:80
enum ExpandoNodeType type
Type of Node, e.g. ENT_EXPANDO.
Definition: node.h:70
+ 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 error 
)

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, parsed_until,
274 IndexFormatDef, flags, error);
275
276 struct ExpandoNode *node_tree = node_expando_new(node_subj->start, node_subj->end,
278 node_tree->next = node_subj;
279
280 // Move the formatting info to the container
281 struct ExpandoNode *node_cont = node_container_new();
282 node_cont->format = node_subj->format;
283 node_subj->format = NULL;
284
285 ARRAY_ADD(&node_cont->children, node_tree);
286 return node_cont;
287}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:156
@ ED_ENVELOPE
Envelope ED_ENV_ ExpandoDataEnvelope.
Definition: domain.h:42
@ ED_ENV_THREAD_TREE
Email.tree.
Definition: envelope.h:117
struct ExpandoNode * node_container_new(void)
Create a new Container ExpandoNode.
struct ExpandoNode * node_expando_new(const char *start, const char *end, struct ExpandoFormat *fmt, int did, int uid)
Create a new Expando ExpandoNode.
Definition: node_expando.c:80
struct ExpandoFormat * format
Formatting info.
Definition: node.h:75
struct ExpandoNode * next
Linked list.
Definition: node.h:71
const char * start
Start of string data.
Definition: node.h:79
struct ExpandoNodeArray children
Children nodes.
Definition: node.h:77
+ 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 error 
)

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, parsed_until, did, uid, error);
69 }
70
71 return node_expando_parse_enclosure(str, parsed_until, did, uid, ']', error);
72}
+ Here is the call graph for this function: