NeoMutt  2024-04-16-36-g75b6fb
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
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.

Functions

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.

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 expando.c.

Function Documentation

◆ expando_new()

struct Expando * expando_new ( const char *  format)

Create an Expando from a string.

Parameters
formatFormat string to parse
Return values
ptrNew Expando object

Definition at line 43 of file expando.c.

44{
45 struct Expando *exp = mutt_mem_calloc(1, sizeof(struct Expando));
46 exp->string = mutt_str_dup(format);
47 return exp;
48}
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
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.

Parameters
[out]ptrExpando to free

Definition at line 54 of file expando.c.

55{
56 if (!ptr || !*ptr)
57 return;
58
59 struct Expando *exp = *ptr;
60
61 node_tree_free(&exp->tree);
62 FREE(&exp->string);
63
64 FREE(ptr);
65}
#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 * tree
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.

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

Definition at line 74 of file expando.c.

76{
77 if (!str || !defs)
78 return NULL;
79
80 struct Expando *exp = expando_new(str);
81
82 struct ExpandoParseError error = { 0 };
83 struct ExpandoNode *root = NULL;
84
85 node_tree_parse(&root, exp->string, defs, &error);
86
87 if (error.position)
88 {
89 buf_strcpy(err, error.message);
90 node_tree_free(&root);
91 expando_free(&exp);
92 return NULL;
93 }
94
95 exp->tree = root;
96 return exp;
97}
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:394
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:300
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:67
Buffer for parsing errors.
Definition: parse.h:34
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:

◆ 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.

Parameters
[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.

111{
112 if (!exp || !exp->tree || !rdata)
113 return 0;
114
115 // Give enough space for a long command line
116 if (max_cols == -1)
117 max_cols = 8192;
118
119 struct ExpandoNode *root = exp->tree;
120 return node_tree_render(root, rdata, buf, max_cols, data, flags);
121}
int node_tree_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.

Parameters
aFirst Expando
bSecond Expando
Return values
trueThey are identical

Definition at line 129 of file expando.c.

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