NeoMutt  2024-04-25-100-gcb3684
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 *str, 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:296
+ 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 error 
)

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

Definition at line 66 of file node_condbool.c.

70{
71 const struct ExpandoDefinition *definition = 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 (definition && definition->short_name)
80 {
81 if (mutt_str_equal(definition->short_name, expando))
82 {
83 if (definition->parse)
84 {
85 return definition->parse(str, parsed_until, definition->did,
86 definition->uid, flags, error);
87 }
88 else
89 {
90 *parsed_until = expando_end;
91 return node_condbool_new(format_end, expando_end, definition->did,
92 definition->uid);
93 }
94 }
95
96 definition++;
97 }
98
99 error->position = format_end;
100 // L10N: e.g. "Unknown expando: %Q"
101 snprintf(error->message, sizeof(error->message), _("Unknown expando: %%%.*s"),
102 expando_len, format_end);
103 return NULL;
104}
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
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
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 error 
)

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 error->position = str;
163 snprintf(error->message, sizeof(error->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 error->position = str;
175 snprintf(error->message, sizeof(error->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,
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 163 of file mutt_config.c.

166{
167 if (flags & EP_CONDITIONAL)
168 {
169 return node_conddate_parse(str + 1, parsed_until, did, uid, error);
170 }
171
172 return node_expando_parse_enclosure(str, parsed_until, did, uid, ')', error);
173}
+ 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 181 of file mutt_config.c.

184{
185 if (flags & EP_CONDITIONAL)
186 {
187 return node_conddate_parse(str + 1, parsed_until, did, uid, error);
188 }
189
190 return node_expando_parse_enclosure(str, parsed_until, did, uid, ']', error);
191}
+ 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 199 of file mutt_config.c.

202{
203 if (flags & EP_CONDITIONAL)
204 {
205 return node_conddate_parse(str + 1, parsed_until, did, uid, error);
206 }
207
208 return node_expando_parse_enclosure(str, parsed_until, did, uid, '}', error);
209}
+ 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 218 of file mutt_config.c.

221{
222 if (flags & EP_CONDITIONAL)
223 {
224 snprintf(error->message, sizeof(error->message),
225 _("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:237
Basic Expando Node.
Definition: node.h:69
const char * end
End of string data.
Definition: node.h:80
+ 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 ARRAY_ADD(&node_cont->children, node_tree);
279 return node_cont;
280}
#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,
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: