NeoMutt  2024-12-12-14-g7b49f7
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
node.c File Reference

Basic Expando Node. More...

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

Go to the source code of this file.

Functions

struct ExpandoNodenode_new (void)
 Create a new empty ExpandoNode.
 
void node_free (struct ExpandoNode **ptr)
 Free an ExpandoNode and its private data.
 
void node_add_child (struct ExpandoNode *node, struct ExpandoNode *child)
 Add a child to an ExpandoNode.
 
struct ExpandoNodenode_get_child (const struct ExpandoNode *node, int index)
 Get a child of an ExpandoNode.
 
struct ExpandoNodenode_last (struct ExpandoNode *node)
 Find the last Node in a tree.
 

Detailed Description

Basic Expando Node.

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

Function Documentation

◆ node_new()

struct ExpandoNode * node_new ( void  )

Create a new empty ExpandoNode.

Return values
ptrNew ExpandoNode

Definition at line 39 of file node.c.

40{
41 return MUTT_MEM_CALLOC(1, struct ExpandoNode);
42}
#define MUTT_MEM_CALLOC(n, type)
Definition: memory.h:40
Basic Expando Node.
Definition: node.h:67
+ Here is the caller graph for this function:

◆ node_free()

void node_free ( struct ExpandoNode **  ptr)

Free an ExpandoNode and its private data.

Parameters
ptrNode to free

Definition at line 48 of file node.c.

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}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:212
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:204
#define FREE(x)
Definition: memory.h:55
void node_free(struct ExpandoNode **ptr)
Free an ExpandoNode and its private data.
Definition: node.c:48
void * ndata
Private node data.
Definition: node.h:77
struct ExpandoFormat * format
Formatting info.
Definition: node.h:72
const char * text
Node-specific text.
Definition: node.h:73
void(* ndata_free)(void **ptr)
Function to free the private node data.
Definition: node.h:78
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:

◆ node_add_child()

void node_add_child ( struct ExpandoNode node,
struct ExpandoNode child 
)

Add a child to an ExpandoNode.

Parameters
nodeParent node
childChild node

Definition at line 76 of file node.c.

77{
78 if (!node)
79 return;
80
81 ARRAY_ADD(&node->children, child);
82}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:156
+ Here is the caller graph for this function:

◆ node_get_child()

struct ExpandoNode * node_get_child ( const struct ExpandoNode node,
int  index 
)

Get a child of an ExpandoNode.

Parameters
nodeParent node
indexIndex of child to get
Return values
ptrChild node
NULLNo child, or index out of range

Definition at line 91 of file node.c.

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}
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:109
+ Here is the caller graph for this function:

◆ node_last()

struct ExpandoNode * node_last ( struct ExpandoNode node)

Find the last Node in a tree.

Parameters
nodeRoot Node
Return values
ptrLast Node

Definition at line 108 of file node.c.

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}
#define ARRAY_LAST(head)
Convenience method to get the last element.
Definition: array.h:144
+ Here is the caller graph for this function: