NeoMutt  2024-04-25-91-gb0e085
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
node_expando.h File Reference

Expando Node for an Expando. More...

#include <stdbool.h>
#include "definition.h"
#include "render.h"
+ Include dependency graph for node_expando.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  NodeExpandoPrivate
 Private data for an Expando. More...
 

Functions

struct ExpandoNodenode_expando_new (const char *start, const char *end, struct ExpandoFormat *fmt, int did, int uid)
 Create a new Expando ExpandoNode.
 
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.
 
struct ExpandoNodenode_expando_parse (const char *str, const char **parsed_until, const struct ExpandoDefinition *defs, ExpandoParserFlags flags, struct ExpandoParseError *error)
 Parse an Expando format string.
 
int node_expando_render (const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
 Render an Expando Node - Implements ExpandoNode::render() -.
 
struct ExpandoNodenode_expando_parse_enclosure (const char *str, const char **parsed_until, int did, int uid, char terminator, struct ExpandoParseError *error)
 Parse an enclosed Expando.
 

Detailed Description

Expando Node for an Expando.

Authors
  • Tóth János
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file node_expando.h.

Function Documentation

◆ node_expando_new()

struct ExpandoNode * node_expando_new ( const char *  start,
const char *  end,
struct ExpandoFormat fmt,
int  did,
int  uid 
)

Create a new Expando ExpandoNode.

Parameters
startStart of Expando string
endEnd of Expando string
fmtFormatting data
didDomain ID
uidUnique ID
Return values
ptrNew Expando ExpandoNode

Definition at line 80 of file node_expando.c.

82{
83 struct ExpandoNode *node = node_new();
84
85 node->type = ENT_EXPANDO;
86 node->start = start;
87 node->end = end;
88
89 node->did = did;
90 node->uid = uid;
92
93 node->format = fmt;
94
97
98 return node;
99}
int node_expando_render(const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
Render an Expando Node - Implements ExpandoNode::render() -.
Definition: node_expando.c:344
struct ExpandoNode * node_new(void)
Create a new empty ExpandoNode.
Definition: node.c:39
@ ENT_EXPANDO
Expando, e.g. 'n'.
Definition: node.h:39
void node_expando_private_free(void **ptr)
Free Expando private data - Implements ExpandoNode::ndata_free()
Definition: node_expando.c:63
struct NodeExpandoPrivate * node_expando_private_new(void)
Create new Expando private data.
Definition: node_expando.c:49
Basic Expando Node.
Definition: node.h:69
int uid
Unique ID, e.g. ED_EMA_SIZE.
Definition: node.h:73
int(* render)(const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
Definition: node.h:96
void * ndata
Private node data.
Definition: node.h:82
struct ExpandoFormat * format
Formatting info.
Definition: node.h:75
const char * end
End of string data.
Definition: node.h:80
int did
Domain ID, e.g. ED_EMAIL.
Definition: node.h:72
enum ExpandoNodeType type
Type of Node, e.g. ENT_EXPANDO.
Definition: node.h:70
const char * start
Start of string data.
Definition: node.h:79
void(* ndata_free)(void **ptr)
Function to free the private node data.
Definition: node.h:83
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ node_expando_set_color()

void node_expando_set_color ( const struct ExpandoNode node,
int  cid 
)

Set the colour for an Expando.

Parameters
nodeNode to alter
cidColour

Definition at line 106 of file node_expando.c.

107{
108 if (!node || (node->type != ENT_EXPANDO) || !node->ndata)
109 return;
110
111 struct NodeExpandoPrivate *priv = node->ndata;
112
113 priv->color = cid;
114}
Private data for an Expando.
Definition: node_expando.h:40
int color
ColorId to use.
Definition: node_expando.h:41
+ Here is the caller graph for this function:

◆ node_expando_set_has_tree()

void node_expando_set_has_tree ( const struct ExpandoNode node,
bool  has_tree 
)

Set the has_tree flag for an Expando.

Parameters
nodeNode to alter
has_treeFlag to set

Definition at line 121 of file node_expando.c.

122{
123 if (!node || (node->type != ENT_EXPANDO) || !node->ndata)
124 return;
125
126 struct NodeExpandoPrivate *priv = node->ndata;
127
128 priv->has_tree = has_tree;
129}
bool has_tree
Contains tree characters, used in $index_format's s.
Definition: node_expando.h:42
+ Here is the caller graph for this function:

◆ node_expando_parse()

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.

Parameters
[in]strString to parse
[out]parsed_untilFirst character after parsed string
[in]defsExpando definitions
[in]flagsFlag for conditional expandos
[out]errorBuffer for errors
Return values
ptrNew ExpandoNode

Definition at line 237 of file node_expando.c.

241{
242 const struct ExpandoDefinition *definition = defs;
243
244 const char *format_end = skip_until_classic_expando(str);
245 const char *expando_end = skip_classic_expando(format_end, defs);
246 char expando[128] = { 0 };
247 const int expando_len = expando_end - format_end;
248 mutt_strn_copy(expando, format_end, expando_len, sizeof(expando));
249
250 struct ExpandoFormat *fmt = parse_format(str, format_end, error);
251 if (error->position)
252 {
253 FREE(&fmt);
254 return NULL;
255 }
256
257 while (definition && definition->short_name)
258 {
259 if (mutt_str_equal(definition->short_name, expando))
260 {
261 if (definition->parse && !(flags & EP_NO_CUSTOM_PARSE))
262 {
263 FREE(&fmt);
264 return definition->parse(str, parsed_until, definition->did,
265 definition->uid, flags, error);
266 }
267 else
268 {
269 *parsed_until = expando_end;
270 return node_expando_new(format_end, expando_end, fmt, definition->did,
271 definition->uid);
272 }
273 }
274
275 definition++;
276 }
277
278 error->position = format_end;
279 // L10N: e.g. "Unknown expando: %Q"
280 snprintf(error->message, sizeof(error->message), _("Unknown expando: %%%.*s"),
281 expando_len, format_end);
282 FREE(&fmt);
283 return NULL;
284}
#define EP_NO_CUSTOM_PARSE
Don't use the custom parser.
Definition: definition.h:44
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 FREE(x)
Definition: memory.h:45
#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 ExpandoFormat * parse_format(const char *start, const char *end, struct ExpandoParseError *error)
Parse a format string.
Definition: node_expando.c:140
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
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
Formatting information for an Expando.
Definition: node.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_expando_parse_enclosure()

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.

Parameters
strString to parse
parsed_untilFirst character after the parsed string
didDomain ID
uidUnique ID
terminatorTerminating character
errorBuffer for errors
Return values
ptrNew ExpandoNode

Definition at line 296 of file node_expando.c.

299{
300 const char *format_end = skip_until_classic_expando(str);
301
302 format_end++; // skip opening char
303
304 const char *expando_end = skip_until_ch(format_end, terminator);
305
306 if (*expando_end != terminator)
307 {
308 error->position = expando_end;
309 snprintf(error->message, sizeof(error->message),
310 // L10N: Expando is missing a terminator character
311 // e.g. "%[..." is missing the final ']'
312 _("Expando is missing terminator: '%c'"), terminator);
313 return NULL;
314 }
315
316 // revert skipping for fmt
317 struct ExpandoFormat *fmt = parse_format(str, format_end - 1, error);
318 if (error->position)
319 {
320 FREE(&fmt);
321 return NULL;
322 }
323
324 *parsed_until = expando_end + 1;
325 return node_expando_new(format_end, expando_end, fmt, did, uid);
326}
const char * skip_until_ch(const char *start, char terminator)
Search a string for a terminator character.
Definition: helpers.c:94
+ Here is the call graph for this function:
+ Here is the caller graph for this function: