NeoMutt  2024-04-16-36-g75b6fb
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, const char **parsed_until, int did, int uid, ExpandoParserFlags flags, struct ExpandoParseError *error)
 Parse a Date Expando - Implements ExpandoDefinition::parse() -.
 
struct ExpandoNodenode_condbool_parse (const char *s, const char **parsed_until, const struct ExpandoDefinition *defs, ExpandoParserFlags flags, struct ExpandoParseError *error)
 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 *error)
 Parse a CondDate format string - Implements ExpandoDefinition::parse() -.
 
struct ExpandoNodenode_padding_parse (const char *str, const char **parsed_until, int did, int uid, ExpandoParserFlags flags, struct ExpandoParseError *error)
 Parse a Padding Expando - Implements ExpandoDefinition::parse() -.
 
struct ExpandoNodeparse_index_date_recv_local (const char *str, const char **parsed_until, int did, int uid, ExpandoParserFlags flags, struct ExpandoParseError *error)
 Parse a Date Expando - Implements ExpandoDefinition::parse() -.
 
struct ExpandoNodeparse_index_date_local (const char *str, const char **parsed_until, int did, int uid, ExpandoParserFlags flags, struct ExpandoParseError *error)
 Parse a Date Expando - Implements ExpandoDefinition::parse() -.
 
struct ExpandoNodeparse_index_date (const char *str, const char **parsed_until, int did, int uid, ExpandoParserFlags flags, struct ExpandoParseError *error)
 Parse a Date Expando - Implements ExpandoDefinition::parse() -.
 
struct ExpandoNodeparse_index_hook (const char *str, const char **parsed_until, int did, int uid, ExpandoParserFlags flags, struct ExpandoParseError *error)
 Parse an index-hook - Implements ExpandoDefinition::parse() -.
 
struct ExpandoNodeparse_tags_transformed (const char *str, const char **parsed_until, int did, int uid, ExpandoParserFlags flags, struct ExpandoParseError *error)
 Parse a Tags-Transformed Expando - Implements ExpandoDefinition::parse() -.
 
struct ExpandoNodeparse_subject (const char *str, const char **parsed_until, int did, int uid, ExpandoParserFlags flags, struct ExpandoParseError *error)
 Parse a Subject Expando - Implements ExpandoDefinition::parse() -.
 
struct ExpandoNodeparse_pgp_date (const char *str, const char **parsed_until, int did, int uid, ExpandoParserFlags flags, struct ExpandoParseError *error)
 Parse a Date Expando - Implements ExpandoDefinition::parse() -.
 

Detailed Description

Custom function to parse a format string into a Node.

Parameters
[in]strFormat String to parse
[in,out]parsed_untilFirst character after the parsed string
[in]didDomain ID of the data
[in]uidUnique ID of the data
[out]errorPlace for error message
Return values
ptrParsed Node

Function Documentation

◆ parse_folder_date()

struct ExpandoNode * parse_folder_date ( const char *  str,
const char **  parsed_until,
int  did,
int  uid,
ExpandoParserFlags  flags,
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 *error)
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 *error)
Parse an enclosed Expando.
Definition: node_expando.c:291
+ Here is the call graph for this function:

◆ node_condbool_parse()

struct ExpandoNode * node_condbool_parse ( const char *  s,
const char **  parsed_until,
const struct ExpandoDefinition defs,
ExpandoParserFlags  flags,
struct ExpandoParseError error 
)

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

Definition at line 68 of file node_condbool.c.

72{
73 const struct ExpandoDefinition *definition = defs;
74
75 const char *format_end = skip_until_classic_expando(s);
76 const char *expando_end = skip_classic_expando(format_end, defs);
77 char expando[128] = { 0 };
78 const int expando_len = expando_end - format_end;
79 mutt_strn_copy(expando, format_end, expando_len, sizeof(expando));
80
81 while (definition && definition->short_name)
82 {
83 if (mutt_str_equal(definition->short_name, expando))
84 {
85 if (definition->parse)
86 {
87 return definition->parse(s, parsed_until, definition->did,
88 definition->uid, flags, error);
89 }
90 else
91 {
92 *parsed_until = expando_end;
93 return node_condbool_new(format_end, expando_end, definition->did,
94 definition->uid);
95 }
96 }
97
98 definition++;
99 }
100
101 error->position = format_end;
102 // L10N: e.g. "Unknown expando: %Q"
103 snprintf(error->message, sizeof(error->message), _("Unknown expando: %%%.*s"),
104 expando_len, format_end);
105 return NULL;
106}
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:654
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:354
struct ExpandoNode * node_condbool_new(const char *start, const char *end, int did, int uid)
Create a new CondBool ExpandoNode.
Definition: node_condbool.c:50
Definition of a format string.
Definition: definition.h:52
short uid
Unique ID in domain.
Definition: definition.h:56
short did
Domain ID.
Definition: definition.h:55
struct ExpandoNode *(* parse)(const char *str, const char **parsed_until, int did, int uid, ExpandoParserFlags flags, struct ExpandoParseError *error)
Definition: definition.h:70
const char * short_name
Short Expando name, e.g. "n".
Definition: definition.h:53
char message[128]
Error message.
Definition: parse.h:35
const char * position
Position of error in original string.
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,
const char **  parsed_until,
int  did,
int  uid,
struct ExpandoParseError error 
)

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

Definition at line 149 of file node_conddate.c.

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

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 232 of file node_padding.c.

235{
236 if (flags & EP_CONDITIONAL)
237 {
238 snprintf(error->message, sizeof(error->message),
239 // L10N: Conditional Expandos can only depend on other Expandos
240 // e.g. "%<X?apple>" displays "apple" if "%X" is true.
241 _("Padding cannot be used as a condition"));
242 error->position = str;
243 return NULL;
244 }
245
246 enum ExpandoPadType pt = 0;
247 if (*str == '|')
248 {
249 pt = EPT_FILL_EOL;
250 }
251 else if (*str == '>')
252 {
253 pt = EPT_HARD_FILL;
254 }
255 else if (*str == '*')
256 {
257 pt = EPT_SOFT_FILL;
258 }
259 else
260 {
261 return NULL;
262 }
263 str++;
264
265 const size_t consumed = mutt_mb_charlen(str, NULL);
266
267 *parsed_until = str + consumed;
268 return node_padding_new(pt, str, str + consumed);
269}
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:198
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,
const char **  parsed_until,
int  did,
int  uid,
ExpandoParserFlags  flags,
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 164 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,
const char **  parsed_until,
int  did,
int  uid,
ExpandoParserFlags  flags,
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,
const char **  parsed_until,
int  did,
int  uid,
ExpandoParserFlags  flags,
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,
const char **  parsed_until,
int  did,
int  uid,
ExpandoParserFlags  flags,
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), "index-hook cannot be used as a condition");
226 error->position = str;
227 return NULL;
228 }
229
230 return node_expando_parse_enclosure(str, parsed_until, did, uid, '@', error);
231}
+ Here is the call graph for this function:

◆ parse_tags_transformed()

struct ExpandoNode * parse_tags_transformed ( const char *  str,
const char **  parsed_until,
int  did,
int  uid,
ExpandoParserFlags  flags,
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 238 of file mutt_config.c.

241{
242 // Let the basic expando parser do the work
243 flags |= EP_NO_CUSTOM_PARSE;
244 struct ExpandoNode *node = node_expando_parse(str, parsed_until,
245 IndexFormatDef, flags, error);
246
247 // but adjust the node to take one more character
248 node->end++;
249 (*parsed_until)++;
250
251 return node;
252}
#define EP_NO_CUSTOM_PARSE
Don't use the custom parser.
Definition: definition.h:44
const struct ExpandoDefinition IndexFormatDef[]
Expando definitions.
Definition: mutt_config.c:295
struct ExpandoNode * node_expando_parse(const char *str, const char **parsed_until, const struct ExpandoDefinition *defs, ExpandoParserFlags flags, struct ExpandoParseError *error)
Parse an Expando format string.
Definition: node_expando.c:232
Basic Expando Node.
Definition: node.h:67
const char * end
End of string data.
Definition: node.h:78
+ Here is the call graph for this function:

◆ parse_subject()

struct ExpandoNode * parse_subject ( const char *  str,
const char **  parsed_until,
int  did,
int  uid,
ExpandoParserFlags  flags,
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 260 of file mutt_config.c.

263{
264 // Let the basic expando parser do the work
265 flags |= EP_NO_CUSTOM_PARSE;
266 struct ExpandoNode *node_subj = node_expando_parse(str, parsed_until,
267 IndexFormatDef, flags, error);
268
269 struct ExpandoNode *node_tree = node_expando_new(node_subj->start, node_subj->end,
271 node_tree->next = node_subj;
272
273 // Move the formatting info to the container
274 struct ExpandoNode *node_cont = node_container_new();
275 node_cont->format = node_subj->format;
276 node_subj->format = NULL;
277
278 node_set_child(node_cont, 0, node_tree);
279 return node_cont;
280}
@ ED_ENVELOPE
Envelope ED_ENV_ ExpandoDataEnvelope.
Definition: domain.h:42
@ ED_ENV_THREAD_TREE
Email.tree.
Definition: envelope.h:117
void node_set_child(struct ExpandoNode *node, int index, struct ExpandoNode *child)
Set the child of an ExpandoNode.
Definition: node.c: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:81
struct ExpandoFormat * format
Formatting info.
Definition: node.h:73
struct ExpandoNode * next
Linked list.
Definition: node.h:69
const char * start
Start of string data.
Definition: node.h:77
+ Here is the call graph for this function:

◆ parse_pgp_date()

struct ExpandoNode * parse_pgp_date ( const char *  str,
const char **  parsed_until,
int  did,
int  uid,
ExpandoParserFlags  flags,
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: