NeoMutt  2024-10-02-7-gd3e66a
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
node.h File Reference

Basic Expando Node. More...

#include <stdbool.h>
#include "mutt/lib.h"
#include "format.h"
#include "render.h"
+ Include dependency graph for node.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ExpandoFormat
 Formatting information for an Expando. More...
 
struct  ExpandoNode
 Basic Expando Node. More...
 

Enumerations

enum  ExpandoNodeType {
  ENT_EMPTY = 0 , ENT_TEXT , ENT_EXPANDO , ENT_PADDING ,
  ENT_CONDITION , ENT_CONDBOOL , ENT_CONDDATE , ENT_CONTAINER
}
 Type of Expando Node. More...
 

Functions

 ARRAY_HEAD (ExpandoNodeArray, struct ExpandoNode *)
 
struct ExpandoNodenode_new (void)
 Create a new empty ExpandoNode.
 
void node_free (struct ExpandoNode **ptr)
 Free an ExpandoNode and its private data.
 
void node_tree_free (struct ExpandoNode **ptr)
 Free a tree of ExpandoNodes.
 
void node_append (struct ExpandoNode **root, struct ExpandoNode *new_node)
 Append an ExpandoNode to an existing node.
 
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.h.

Enumeration Type Documentation

◆ ExpandoNodeType

Type of Expando Node.

Enumerator
ENT_EMPTY 

Empty.

ENT_TEXT 

Plain text.

ENT_EXPANDO 

Expando, e.g. 'n'.

ENT_PADDING 

Padding: soft, hard, EOL.

ENT_CONDITION 

True/False condition.

ENT_CONDBOOL 

True/False boolean condition.

ENT_CONDDATE 

True/False date condition.

ENT_CONTAINER 

Container for other nodes.

Definition at line 35 of file node.h.

36{
37 ENT_EMPTY = 0,
38 ENT_TEXT,
45};
@ 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

Function Documentation

◆ ARRAY_HEAD()

ARRAY_HEAD ( ExpandoNodeArray  ,
struct ExpandoNode  
)

◆ 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, sizeof(struct ExpandoNode));
42}
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:51
Basic Expando Node.
Definition: node.h:69
+ Here is the call graph for this function:
+ 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 if (node->ndata_free)
55 {
56 node->ndata_free(&node->ndata);
57 }
58
59 struct ExpandoNode **enp = NULL;
60 ARRAY_FOREACH(enp, &node->children)
61 {
62 node_tree_free(enp);
63 }
64
65 FREE(&node->format);
66
67 ARRAY_FREE(&node->children);
68
69 FREE(ptr);
70}
#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:45
void node_tree_free(struct ExpandoNode **ptr)
Free a tree of ExpandoNodes.
Definition: node.c:76
void * ndata
Private node data.
Definition: node.h:82
struct ExpandoFormat * format
Formatting info.
Definition: node.h:75
void(* ndata_free)(void **ptr)
Function to free the private node data.
Definition: node.h:83
struct ExpandoNodeArray children
Children nodes.
Definition: node.h:77
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ node_tree_free()

void node_tree_free ( struct ExpandoNode **  ptr)

Free a tree of ExpandoNodes.

Parameters
ptrRoot of tree to free

Definition at line 76 of file node.c.

77{
78 if (!ptr || !*ptr)
79 return;
80
81 struct ExpandoNode *node = *ptr;
82 while (node)
83 {
84 struct ExpandoNode *n = node;
85 node = node->next;
86 node_free(&n);
87 }
88
89 *ptr = NULL;
90}
void node_free(struct ExpandoNode **ptr)
Free an ExpandoNode and its private data.
Definition: node.c:48
struct ExpandoNode * next
Linked list.
Definition: node.h:71
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ node_append()

void node_append ( struct ExpandoNode **  root,
struct ExpandoNode new_node 
)

Append an ExpandoNode to an existing node.

Parameters
[in,out]rootExisting node (may be NULL)
[in]new_nodeNode to add

Definition at line 116 of file node.c.

117{
118 if (!*root)
119 {
120 *root = new_node;
121 return;
122 }
123
124 struct ExpandoNode *node = *root;
125 while (node->next)
126 {
127 node = node->next;
128 }
129
130 node->next = new_node;
131}
+ 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 99 of file node.c.

100{
101 if (!node)
102 return NULL;
103
104 struct ExpandoNode **ptr = ARRAY_GET(&node->children, index);
105 if (!ptr)
106 return NULL;
107
108 return *ptr;
109}
#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 138 of file node.c.

139{
140 if (!node)
141 return NULL;
142
143 while (true)
144 {
145 if (node->next)
146 {
147 node = node->next;
148 continue;
149 }
150
151 size_t size = ARRAY_SIZE(&node->children);
152 if (size == 0)
153 break;
154
155 struct ExpandoNode *last = node_get_child(node, size - 1);
156 if (!last)
157 break; // LCOV_EXCL_LINE
158
159 node = last;
160 }
161
162 return node;
163}
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:87
struct ExpandoNode * node_get_child(const struct ExpandoNode *node, int index)
Get a child of an ExpandoNode.
Definition: node.c:99
+ Here is the call graph for this function:
+ Here is the caller graph for this function: