NeoMutt  2024-10-02-37-gfa9146
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 (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 struct ExpandoDefinition *defs, ExpandoParserFlags flags, const char **parsed_until, struct ExpandoParseError *err)
 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, int did, int uid, char terminator, const char **parsed_until, struct ExpandoParseError *err)
 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 ( struct ExpandoFormat fmt,
int  did,
int  uid 
)

Create a new Expando ExpandoNode.

Parameters
fmtFormatting data
didDomain ID
uidUnique ID
Return values
ptrNew Expando ExpandoNode

Definition at line 78 of file node_expando.c.

79{
80 struct ExpandoNode *node = node_new();
81
82 node->type = ENT_EXPANDO;
83 node->did = did;
84 node->uid = uid;
86
87 node->format = fmt;
88
91
92 return node;
93}
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:336
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:67
int uid
Unique ID, e.g. ED_EMA_SIZE.
Definition: node.h:70
int(* render)(const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
Definition: node.h:91
void * ndata
Private node data.
Definition: node.h:77
struct ExpandoFormat * format
Formatting info.
Definition: node.h:72
int did
Domain ID, e.g. ED_EMAIL.
Definition: node.h:69
enum ExpandoNodeType type
Type of Node, e.g. ENT_EXPANDO.
Definition: node.h:68
void(* ndata_free)(void **ptr)
Function to free the private node data.
Definition: node.h:78
+ 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 100 of file node_expando.c.

101{
102 if (!node || (node->type != ENT_EXPANDO) || !node->ndata)
103 return;
104
105 struct NodeExpandoPrivate *priv = node->ndata;
106
107 priv->color = cid;
108}
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 115 of file node_expando.c.

116{
117 if (!node || (node->type != ENT_EXPANDO) || !node->ndata)
118 return;
119
120 struct NodeExpandoPrivate *priv = node->ndata;
121
122 priv->has_tree = has_tree;
123}
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 struct ExpandoDefinition defs,
ExpandoParserFlags  flags,
const char **  parsed_until,
struct ExpandoParseError err 
)

Parse an Expando format string.

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

Definition at line 229 of file node_expando.c.

232{
233 const struct ExpandoDefinition *def = defs;
234
235 const char *format_end = skip_until_classic_expando(str);
236 const char *expando_end = skip_classic_expando(format_end, defs);
237 char expando[128] = { 0 };
238 const int expando_len = expando_end - format_end;
239 mutt_strn_copy(expando, format_end, expando_len, sizeof(expando));
240
241 struct ExpandoFormat *fmt = parse_format(str, format_end, err);
242 if (err->position)
243 {
244 FREE(&fmt);
245 return NULL;
246 }
247
248 while (def && def->short_name)
249 {
250 if (mutt_str_equal(def->short_name, expando))
251 {
252 if (def->parse && !(flags & EP_NO_CUSTOM_PARSE))
253 {
254 FREE(&fmt);
255 return def->parse(str, def->did, def->uid, flags, parsed_until, err);
256 }
257 else
258 {
259 *parsed_until = expando_end;
260 return node_expando_new(fmt, def->did, def->uid);
261 }
262 }
263
264 def++;
265 }
266
267 err->position = format_end;
268 // L10N: e.g. "Unknown expando: %Q"
269 snprintf(err->message, sizeof(err->message), _("Unknown expando: %%%.*s"),
270 expando_len, format_end);
271 FREE(&fmt);
272 return NULL;
273}
#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 *err)
Parse a format string.
Definition: node_expando.c:134
struct ExpandoNode * node_expando_new(struct ExpandoFormat *fmt, int did, int uid)
Create a new Expando ExpandoNode.
Definition: node_expando.c:78
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
Formatting information for an Expando.
Definition: node.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_expando_parse_enclosure()

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.

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

Definition at line 285 of file node_expando.c.

288{
289 const char *format_end = skip_until_classic_expando(str);
290
291 format_end++; // skip opening char
292
293 const char *expando_end = skip_until_ch(format_end, terminator);
294
295 if (*expando_end != terminator)
296 {
297 err->position = expando_end;
298 snprintf(err->message, sizeof(err->message),
299 // L10N: Expando is missing a terminator character
300 // e.g. "%[..." is missing the final ']'
301 _("Expando is missing terminator: '%c'"), terminator);
302 return NULL;
303 }
304
305 // revert skipping for fmt
306 struct ExpandoFormat *fmt = parse_format(str, format_end - 1, err);
307 if (err->position)
308 {
309 FREE(&fmt);
310 return NULL;
311 }
312
313 *parsed_until = expando_end + 1;
314
315 struct ExpandoNode *node = node_expando_new(fmt, did, uid);
316 node->text = mutt_strn_dup(format_end, expando_end - format_end);
317 return node;
318}
const char * skip_until_ch(const char *start, char terminator)
Search a string for a terminator character.
Definition: helpers.c:94
char * mutt_strn_dup(const char *begin, size_t len)
Duplicate a sub-string.
Definition: string.c:380
const char * text
Node-specific text.
Definition: node.h:73
+ Here is the call graph for this function:
+ Here is the caller graph for this function: