NeoMutt  2025-12-11-58-g09398d
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
serial.c File Reference

Dump the details of an Expando Tree. More...

#include "config.h"
#include <limits.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "mutt/lib.h"
#include "debug/lib.h"
#include "serial.h"
#include "expando.h"
#include "node.h"
#include "node_conddate.h"
#include "node_condition.h"
#include "node_padding.h"
+ Include dependency graph for serial.c:

Go to the source code of this file.

Functions

static void dump_node (const struct ExpandoNode *node, struct Buffer *buf)
 
static void dump_did_uid (const struct ExpandoNode *node, struct Buffer *buf)
 
static void dump_node_condition (const struct ExpandoNode *node, struct Buffer *buf)
 
static void dump_node_condbool (const struct ExpandoNode *node, struct Buffer *buf)
 
static void dump_node_conddate (const struct ExpandoNode *node, struct Buffer *buf)
 
static void dump_node_container (const struct ExpandoNode *node, struct Buffer *buf)
 
static void dump_node_empty (const struct ExpandoNode *node, struct Buffer *buf)
 
static void dump_node_expando (const struct ExpandoNode *node, struct Buffer *buf)
 
static void dump_node_padding (const struct ExpandoNode *node, struct Buffer *buf)
 
static void dump_node_text (const struct ExpandoNode *node, struct Buffer *buf)
 
void expando_serialise (const struct Expando *exp, struct Buffer *buf)
 

Detailed Description

Dump the details of an Expando Tree.

Authors
  • 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 serial.c.

Function Documentation

◆ dump_node()

static void dump_node ( const struct ExpandoNode * node,
struct Buffer * buf )
static

Definition at line 240 of file serial.c.

241{
242 if (!node || !buf)
243 return;
244
245 switch (node->type)
246 {
247 case ENT_CONDITION:
248 dump_node_condition(node, buf);
249 break;
250 case ENT_CONDBOOL:
251 dump_node_condbool(node, buf);
252 break;
253 case ENT_CONDDATE:
254 dump_node_conddate(node, buf);
255 break;
256 case ENT_CONTAINER:
257 dump_node_container(node, buf);
258 break;
259 case ENT_EMPTY:
260 dump_node_empty(node, buf);
261 break;
262 case ENT_EXPANDO:
263 dump_node_expando(node, buf);
264 break;
265 case ENT_PADDING:
266 dump_node_padding(node, buf);
267 break;
268 case ENT_TEXT:
269 dump_node_text(node, buf);
270 break;
271 default:
272 ASSERT(false);
273 }
274}
@ ENT_EXPANDO
Expando, e.g. 'n'.
Definition node.h:39
@ ENT_CONTAINER
Container for other nodes.
Definition node.h:44
@ ENT_CONDITION
True/False condition.
Definition node.h:41
@ ENT_TEXT
Plain text.
Definition node.h:38
@ ENT_CONDDATE
True/False date condition.
Definition node.h:43
@ ENT_EMPTY
Empty.
Definition node.h:37
@ ENT_CONDBOOL
True/False boolean condition.
Definition node.h:42
@ ENT_PADDING
Padding: soft, hard, EOL.
Definition node.h:40
static void dump_node_condition(const struct ExpandoNode *node, struct Buffer *buf)
Definition serial.c:52
static void dump_node_padding(const struct ExpandoNode *node, struct Buffer *buf)
Definition serial.c:186
static void dump_node_condbool(const struct ExpandoNode *node, struct Buffer *buf)
Definition serial.c:88
static void dump_node_text(const struct ExpandoNode *node, struct Buffer *buf)
Definition serial.c:220
static void dump_node_empty(const struct ExpandoNode *node, struct Buffer *buf)
Definition serial.c:133
static void dump_node_conddate(const struct ExpandoNode *node, struct Buffer *buf)
Definition serial.c:99
static void dump_node_container(const struct ExpandoNode *node, struct Buffer *buf)
Definition serial.c:117
static void dump_node_expando(const struct ExpandoNode *node, struct Buffer *buf)
Definition serial.c:152
#define ASSERT(COND)
Definition signal2.h:60
enum ExpandoNodeType type
Type of Node, e.g. ENT_EXPANDO.
Definition node.h:68
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dump_did_uid()

static void dump_did_uid ( const struct ExpandoNode * node,
struct Buffer * buf )
static

Definition at line 45 of file serial.c.

46{
47 const char *did = name_expando_domain(node->did);
48 const char *uid = name_expando_uid(node->did, node->uid);
49 buf_add_printf(buf, "(%s,%s)", did, uid);
50}
int buf_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition buffer.c:204
const char * name_expando_uid(enum ExpandoDomain did, int uid)
const char * name_expando_domain(enum ExpandoDomain did)
int uid
Unique ID, e.g. ED_EMA_SIZE.
Definition node.h:70
int did
Domain ID, e.g. ED_EMAIL.
Definition node.h:69
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dump_node_condition()

static void dump_node_condition ( const struct ExpandoNode * node,
struct Buffer * buf )
static

Definition at line 52 of file serial.c.

53{
54 buf_addstr(buf, "<COND");
55
56 // dump_did_uid(node, buf);
57
58 // These shouldn't happen
59 if (node->text)
60 buf_add_printf(buf, ",text=%s", node->text);
61
62 struct ExpandoNode *node_cond = node_get_child(node, ENC_CONDITION);
63 struct ExpandoNode *node_true = node_get_child(node, ENC_TRUE);
64 struct ExpandoNode *node_false = node_get_child(node, ENC_FALSE);
65
66 ASSERT(node_cond);
67 buf_addstr(buf, ":");
68 dump_node(node_cond, buf);
69 buf_addstr(buf, "|");
70 dump_node(node_true, buf);
71 buf_addstr(buf, "|");
72 dump_node(node_false, buf);
73
74 const struct ExpandoFormat *fmt = node->format;
75 if (fmt)
76 {
77 const char *just = name_format_justify(fmt->justification);
78 if (fmt->max_cols == INT_MAX)
79 buf_add_printf(buf, ":{%d,MAX,%s,'%c'}", fmt->min_cols, just + 8, fmt->leader);
80 else
81 buf_add_printf(buf, ":{%d,%d,%s,'%c'}", fmt->min_cols, fmt->max_cols,
82 just + 8, fmt->leader);
83 }
84
85 buf_addstr(buf, ">");
86}
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition buffer.c:226
const char * name_format_justify(enum FormatJustify just)
struct ExpandoNode * node_get_child(const struct ExpandoNode *node, int index)
Get a child of an ExpandoNode.
Definition node.c:91
@ ENC_CONDITION
Index of Condition Node.
@ ENC_FALSE
Index of False Node.
@ ENC_TRUE
Index of True Node.
static void dump_node(const struct ExpandoNode *node, struct Buffer *buf)
Definition serial.c:240
Formatting information for an Expando.
Definition node.h:53
char leader
Leader character, 0 or space.
Definition node.h:57
enum FormatJustify justification
Justification: left, centre, right.
Definition node.h:56
int min_cols
Minimum number of screen columns.
Definition node.h:54
int max_cols
Maximum number of screen columns.
Definition node.h:55
Basic Expando Node.
Definition node.h:67
struct ExpandoFormat * format
Formatting info.
Definition node.h:72
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:

◆ dump_node_condbool()

static void dump_node_condbool ( const struct ExpandoNode * node,
struct Buffer * buf )
static

Definition at line 88 of file serial.c.

89{
90 buf_addstr(buf, "<BOOL");
91 dump_did_uid(node, buf);
92
93 ASSERT(node->ndata != NULL);
94 ASSERT(node->ndata_free != NULL);
95
96 buf_addstr(buf, ">");
97}
static void dump_did_uid(const struct ExpandoNode *node, struct Buffer *buf)
Definition serial.c:45
void * ndata
Private node data.
Definition node.h:77
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:

◆ dump_node_conddate()

static void dump_node_conddate ( const struct ExpandoNode * node,
struct Buffer * buf )
static

Definition at line 99 of file serial.c.

100{
101 buf_addstr(buf, "<DATE:");
102
103 dump_did_uid(node, buf);
104
105 ASSERT(node->ndata);
106 ASSERT(node->ndata_free);
107 struct NodeCondDatePrivate *priv = node->ndata;
108 buf_add_printf(buf, ":%d:%c", priv->count, priv->period);
109
110 // These shouldn't happen
111 if (node->text)
112 buf_add_printf(buf, ",text=%s", node->text);
113
114 buf_addstr(buf, ">");
115}
Private data for a Conditional Date -.
int count
Number of 'units' to count.
char period
Units, e.g. 'd' Day or 'm' Month.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dump_node_container()

static void dump_node_container ( const struct ExpandoNode * node,
struct Buffer * buf )
static

Definition at line 117 of file serial.c.

118{
119 buf_addstr(buf, "<CONT:");
120
121 struct ExpandoNode **np = NULL;
122 ARRAY_FOREACH(np, &node->children)
123 {
124 if (!np || !*np)
125 continue;
126
127 dump_node(*np, buf);
128 }
129
130 buf_addstr(buf, ">");
131}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:214
struct ExpandoNodeArray children
Children nodes.
Definition node.h:75
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dump_node_empty()

static void dump_node_empty ( const struct ExpandoNode * node,
struct Buffer * buf )
static

Definition at line 133 of file serial.c.

134{
135 buf_addstr(buf, "<EMPTY");
136
137 // These shouldn't happen
138 if (node->did != 0)
139 buf_add_printf(buf, ",did=%d", node->did);
140 if (node->uid != 0)
141 buf_add_printf(buf, ",uid=%d", node->uid);
142 if (node->text)
143 buf_add_printf(buf, ",text=%s", node->text);
144 if (node->ndata)
145 buf_add_printf(buf, ",ndata=%p", node->ndata);
146 if (node->ndata_free)
147 buf_add_printf(buf, ",ndata_free=%p", (void *) (intptr_t) node->ndata_free);
148
149 buf_addstr(buf, ">");
150}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dump_node_expando()

static void dump_node_expando ( const struct ExpandoNode * node,
struct Buffer * buf )
static

Definition at line 152 of file serial.c.

153{
154 buf_addstr(buf, "<EXP:");
155
156 if (node->text)
157 buf_add_printf(buf, "'%s'", node->text);
158
159 ASSERT(node->did != 0);
160 ASSERT(node->uid != 0);
161 dump_did_uid(node, buf);
162
163 ASSERT(node->ndata);
164 ASSERT(node->ndata_free);
165
166 const struct ExpandoFormat *fmt = node->format;
167 if (fmt)
168 {
169 const char *just = name_format_justify(fmt->justification);
170 if (fmt->max_cols == INT_MAX)
171 buf_add_printf(buf, ":{%d,MAX,%s,'%c'}", fmt->min_cols, just + 8, fmt->leader);
172 else
173 buf_add_printf(buf, ":{%d,%d,%s,'%c'}", fmt->min_cols, fmt->max_cols,
174 just + 8, fmt->leader);
175 }
176
177 // These shouldn't happen
178 // if (node->ndata)
179 // buf_add_printf(buf, ",ndata=%p", node->ndata);
180 // if (node->ndata_free)
181 // buf_add_printf(buf, ",ndata_free=%p", (void *) (intptr_t) node->ndata_free);
182
183 buf_addstr(buf, ">");
184}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dump_node_padding()

static void dump_node_padding ( const struct ExpandoNode * node,
struct Buffer * buf )
static

Definition at line 186 of file serial.c.

187{
188 buf_addstr(buf, "<PAD:");
189
190 ASSERT(node->ndata);
191 ASSERT(node->ndata_free);
192 struct NodePaddingPrivate *priv = node->ndata;
193
194 struct ExpandoNode *left = node_get_child(node, ENP_LEFT);
195 struct ExpandoNode *right = node_get_child(node, ENP_RIGHT);
196
197 const char *pt = name_expando_pad_type(priv->pad_type);
198 pt += 4; // Skip "EPT_" prefix
199 buf_add_printf(buf, "%s:", pt);
200
201 ASSERT(node->text);
202 buf_add_printf(buf, "'%s'", node->text);
203
204 buf_addstr(buf, ":");
205 dump_node(left, buf);
206 buf_addstr(buf, "|");
207 dump_node(right, buf);
208
209 // buf_add_printf(buf, ":(%s,%zu)", priv->buffer_start, priv->buffer_len);
210
211 // These shouldn't happen
212 // if (node->did != 0)
213 // buf_add_printf(buf, ",did=%d", node->did);
214 // if (node->uid != 0)
215 // buf_add_printf(buf, ",uid=%d", node->uid);
216
217 buf_addstr(buf, ">");
218}
const char * name_expando_pad_type(enum ExpandoPadType type)
@ ENP_LEFT
Index of Left-Hand Nodes.
@ ENP_RIGHT
Index of Right-Hand Nodes.
Private data for a Padding Node -.
enum ExpandoPadType pad_type
Padding type.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dump_node_text()

static void dump_node_text ( const struct ExpandoNode * node,
struct Buffer * buf )
static

Definition at line 220 of file serial.c.

221{
222 buf_addstr(buf, "<TEXT:");
223
224 ASSERT(node->text);
225 buf_add_printf(buf, "'%s'", node->text);
226
227 // These shouldn't happen
228 // if (node->did != 0)
229 // buf_add_printf(buf, ",did=%d", node->did);
230 // if (node->uid != 0)
231 // buf_add_printf(buf, ",uid=%d", node->uid);
232 if (node->ndata)
233 buf_add_printf(buf, ",ndata=%p", node->ndata);
234 if (node->ndata_free)
235 buf_add_printf(buf, ",ndata_free=%p", (void *) (intptr_t) node->ndata_free);
236
237 buf_addstr(buf, ">");
238}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ expando_serialise()

void expando_serialise ( const struct Expando * exp,
struct Buffer * buf )

Definition at line 276 of file serial.c.

277{
278 if (!exp || !buf)
279 return;
280
281 dump_node(exp->node, buf);
282}
struct ExpandoNode * node
Parsed tree.
Definition expando.h:43
+ Here is the call graph for this function: