commit a41cb80

uint  ·  2026-10-23 19:53:04 +0000 UTC
parent 9947f27
Define nodes, create and free them
4 files changed,  +58, -1
M expl
M expl.c
A expl.h
+1, -1
1@@ -1,5 +1,5 @@
2 CC = cc
3-CFLAGS = -ansi -pedantic -Wall -Wextra -Werror
4+CFLAGS = -ansi -pedantic -Wall -Wextra
5 SRC = expl.c
6 OUT = expl
7 
M expl
+0, -0
M expl.c
+35, -0
 1@@ -1,6 +1,41 @@
 2 #include <stdio.h>
 3 #include <stdlib.h>
 4 
 5+#include "expl.h"
 6+
 7+static expl_node* node_new(expl_type type);
 8+static void node_free(expl_node* node);
 9+
10+static expl_node*
11+new_node(expl_type type)
12+{
13+	expl_node* node = malloc(sizeof(*node));
14+	if (!node)
15+		return NULL;
16+
17+	node->type = type;
18+	node->value = NULL;
19+	node->child = NULL;
20+	node->next = NULL;
21+
22+	return node;
23+}
24+
25+static void
26+node_free(expl_node* node)
27+{
28+	if (!node)
29+		return;
30+
31+	if (node->value)
32+		free(node->value);
33+
34+	node_free(node->child);
35+	node_free(node->next);
36+
37+	free(node);
38+}
39+
40 int
41 main(void)
42 {
A expl.h
+22, -0
 1@@ -0,0 +1,22 @@
 2+#ifndef EXPL_H
 3+#define EXPL_H
 4+
 5+typedef enum {
 6+	EXPL_ATOM,
 7+	EXPL_STRING,
 8+	EXPL_LIST,
 9+
10+	EXPL_TYPE_COUNT
11+} expl_type;
12+
13+typedef struct expl_node expl_node;
14+
15+struct expl_node {
16+	char*      value;
17+	expl_type  type;
18+	expl_node* child;
19+	expl_node* next;
20+};
21+
22+#endif /* EXPL_H */
23+