NeoMutt  2024-04-25-85-g27bab4
Teaching an old dog new tricks
No Matches
expando.c File Reference

Parsed Expando. More...

#include "config.h"
#include <stddef.h>
#include "mutt/lib.h"
#include "expando.h"
#include "node.h"
#include "parse.h"
#include "render.h"
+ Include dependency graph for expando.c:

Go to the source code of this file.


struct Expandoexpando_new (const char *format)
 Create an Expando from a string.
void expando_free (struct Expando **ptr)
 Free an Expando object.
struct Expandoexpando_parse (const char *str, const struct ExpandoDefinition *defs, struct Buffer *err)
 Parse an Expando string.
int expando_render (const struct Expando *exp, const struct ExpandoRenderData *rdata, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
 Render an Expando + data into a string.
bool expando_equal (const struct Expando *a, const struct Expando *b)
 Compare two expandos.

Detailed Description

Parsed Expando.

  • 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

Definition in file expando.c.

Function Documentation

◆ expando_new()

struct Expando * expando_new ( const char *  format)

Create an Expando from a string.

formatFormat string to parse
Return values
ptrNew Expando object

Definition at line 43 of file expando.c.

45 struct Expando *exp = mutt_mem_calloc(1, sizeof(struct Expando));
46 exp->string = mutt_str_dup(format);
47 return exp;
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:51
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
Parsed Expando trees.
Definition: expando.h:41
const char * string
Pointer to the parsed string.
Definition: expando.h:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ expando_free()

void expando_free ( struct Expando **  ptr)

Free an Expando object.

[out]ptrExpando to free

Definition at line 54 of file expando.c.

56 if (!ptr || !*ptr)
57 return;
59 struct Expando *exp = *ptr;
61 node_tree_free(&exp->node);
62 FREE(&exp->string);
64 FREE(ptr);
#define FREE(x)
Definition: memory.h:45
void node_tree_free(struct ExpandoNode **ptr)
Free a tree of ExpandoNodes.
Definition: node.c:76
struct ExpandoNode * node
Parsed tree.
Definition: expando.h:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ expando_parse()

struct Expando * expando_parse ( const char *  str,
const struct ExpandoDefinition defs,
struct Buffer err 

Parse an Expando string.

strString to parse
defsData defining Expando
errBuffer for error messages
Return values
ptrNew Expando

Definition at line 74 of file expando.c.

77 if (!str || !defs)
78 return NULL;
80 struct Expando *exp = expando_new(str);
82 struct ExpandoParseError error = { 0 };
83 struct ExpandoNode *root = NULL;
85 node_tree_parse(&root, exp->string, defs, &error);
87 if (error.position)
88 {
89 buf_strcpy(err, error.message);
90 node_tree_free(&root);
91 expando_free(&exp);
92 return NULL;
93 }
95 exp->node = root;
96 return exp;
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:395
void node_tree_parse(struct ExpandoNode **root, const char *string, const struct ExpandoDefinition *defs, struct ExpandoParseError *error)
Parse a format string into ExpandoNodes.
Definition: parse.c:301
struct Expando * expando_new(const char *format)
Create an Expando from a string.
Definition: expando.c:43
void expando_free(struct Expando **ptr)
Free an Expando object.
Definition: expando.c:54
Basic Expando Node.
Definition: node.h:69
Buffer for parsing errors.
Definition: parse.h:34
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:

◆ expando_render()

int expando_render ( const struct Expando exp,
const struct ExpandoRenderData rdata,
void *  data,
MuttFormatFlags  flags,
int  max_cols,
struct Buffer buf 

Render an Expando + data into a string.

[in]expExpando containing the expando tree
[in]rdataExpando render data
[in]dataCallback data
[in]flagsCallback flags
[in]max_colsNumber of screen columns (-1 means unlimited)
[out]bufBuffer in which to save string
Return values
objNumber of bytes written to buf and screen columns used

Definition at line 109 of file expando.c.

112 if (!exp || !exp->node || !rdata)
113 return 0;
115 // Give enough space for a long command line
116 if (max_cols == -1)
117 max_cols = 8192;
119 return node_render(exp->node, rdata, buf, max_cols, data, flags);
int node_render(const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
Render a tree of ExpandoNodes into a string.
Definition: render.c:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ expando_equal()

bool expando_equal ( const struct Expando a,
const struct Expando b 

Compare two expandos.

aFirst Expando
bSecond Expando
Return values
trueThey are identical

Definition at line 128 of file expando.c.

130 if (!a && !b) /* both empty */
131 return true;
132 if (!a ^ !b) /* one is empty, but not the other */
133 return false;
135 return mutt_str_equal(a->string, b->string);
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:660
+ Here is the call graph for this function:
+ Here is the caller graph for this function: