-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtree.h
85 lines (67 loc) · 1.91 KB
/
tree.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (C) 2011-2012 YesLogic Pty. Ltd.
// Released as Open Source (see COPYING.txt for details)
#ifndef TREE_H
#define TREE_H
#include "token.h"
typedef struct node_s node;
typedef struct element_node_s element_node;
typedef struct text_node_s text_node;
typedef struct comment_node_s comment_node;
/*--------------------------------------------------------------------------*/
typedef enum {
ELEMENT_N,
TEXT_N,
COMMENT_N
} node_type;
struct node_s {
node_type type;
node *parent;
node *previous_sibling;
node *next_sibling;
node *first_child;
node *last_child;
};
struct element_node_s {
node_type type;
node *parent;
node *previous_sibling;
node *next_sibling;
node *first_child;
node *last_child;
unsigned char *name;
attribute_list *attributes;
namespace_type name_space;
};
struct text_node_s {
node_type type;
node *parent;
node *previous_sibling;
node *next_sibling;
node *first_child;
node *last_child;
unsigned char *text_data;
};
struct comment_node_s {
node_type type;
node *parent;
node *previous_sibling;
node *next_sibling;
node *first_child;
node *last_child;
unsigned char *comment_data;
};
/*--------------------------------------------------------------------------*/
element_node *create_element_node(unsigned char *name, attribute_list *attributes, namespace_type name_space);
text_node *create_text_node(void);
comment_node *create_comment_node(unsigned char *comment);
void add_child_node(element_node *parent, node *child_node);
void insert_child_node(node *parent, node *child_node, node *child_2);
void remove_last_child_node(node *parent);
void remove_child_node_from_parent(node *child_node);
void print_parent_node(node *n);
void print_child_nodes(node *n);
void print_node(node *n);
void free_node(node *n);
void print_tree(node *root);
void free_tree(node *root);
#endif