NeoMutt
2025-12-11-1039-g550ac6
Teaching an old dog new tricks
DOXYGEN
Toggle main menu visibility
Loading...
Searching...
No Matches
node.c
Go to the documentation of this file.
1
23
29
30
#include "config.h"
31
#include <stddef.h>
32
#include "
mutt/lib.h
"
33
#include "
node.h
"
34
39
struct
ExpandoNode
*
node_new
(
void
)
40
{
41
return
MUTT_MEM_CALLOC
(1,
struct
ExpandoNode
);
42
}
43
48
void
node_free
(
struct
ExpandoNode
**ptr)
49
{
50
if
(!ptr || !*ptr)
51
return
;
52
53
struct
ExpandoNode
*node = *ptr;
54
55
struct
ExpandoNode
**enp = NULL;
56
ARRAY_FOREACH
(enp, &node->
children
)
57
{
58
node_free
(enp);
59
}
60
ARRAY_FREE
(&node->
children
);
61
62
if
(node->
ndata_free
)
63
node->
ndata_free
(&node->
ndata
);
64
65
FREE
(&node->
format
);
66
FREE
(&node->
text
);
67
68
FREE
(ptr);
69
}
70
76
void
node_add_child
(
struct
ExpandoNode
*node,
struct
ExpandoNode
*child)
77
{
78
if
(!node)
79
return
;
80
81
ARRAY_ADD
(&node->
children
, child);
82
}
83
91
struct
ExpandoNode
*
node_get_child
(
const
struct
ExpandoNode
*node,
int
index)
92
{
93
if
(!node)
94
return
NULL;
95
96
struct
ExpandoNode
**ptr =
ARRAY_GET
(&node->
children
, index);
97
if
(!ptr)
98
return
NULL;
99
100
return
*ptr;
101
}
102
108
struct
ExpandoNode
*
node_last
(
struct
ExpandoNode
*node)
109
{
110
if
(!node)
111
return
NULL;
112
113
struct
ExpandoNode
**np = NULL;
114
while
((np =
ARRAY_LAST
(&node->
children
)) && *np)
115
{
116
node = *np;
117
}
118
119
return
node;
120
}
ARRAY_ADD
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition
array.h:157
ARRAY_FOREACH
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition
array.h:223
ARRAY_LAST
#define ARRAY_LAST(head)
Convenience method to get the last element.
Definition
array.h:145
ARRAY_FREE
#define ARRAY_FREE(head)
Release all memory.
Definition
array.h:209
ARRAY_GET
#define ARRAY_GET(head, idx)
Return the element at index.
Definition
array.h:109
FREE
#define FREE(x)
Free memory and set the pointer to NULL.
Definition
memory.h:68
MUTT_MEM_CALLOC
#define MUTT_MEM_CALLOC(n, type)
Definition
memory.h:52
lib.h
Convenience wrapper for the library headers.
node_new
struct ExpandoNode * node_new(void)
Create a new empty ExpandoNode.
Definition
node.c:39
node_get_child
struct ExpandoNode * node_get_child(const struct ExpandoNode *node, int index)
Get a child of an ExpandoNode.
Definition
node.c:91
node_add_child
void node_add_child(struct ExpandoNode *node, struct ExpandoNode *child)
Add a child to an ExpandoNode.
Definition
node.c:76
node_last
struct ExpandoNode * node_last(struct ExpandoNode *node)
Find the last Node in a tree.
Definition
node.c:108
node_free
void node_free(struct ExpandoNode **ptr)
Free an ExpandoNode and its private data.
Definition
node.c:48
node.h
Basic Expando Node.
ExpandoNode
Basic Expando Node.
Definition
node.h:67
ExpandoNode::ndata
void * ndata
Private node data.
Definition
node.h:77
ExpandoNode::format
struct ExpandoFormat * format
Formatting info.
Definition
node.h:72
ExpandoNode::text
const char * text
Node-specific text.
Definition
node.h:73
ExpandoNode::ndata_free
void(* ndata_free)(void **ptr)
Function to free the private node data.
Definition
node.h:78
ExpandoNode::children
struct ExpandoNodeArray children
Children nodes.
Definition
node.h:75