-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathll.h
103 lines (85 loc) · 2.53 KB
/
ll.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#ifndef LL_H
#define LL_H
#include <regex.h>
/*
* public:
* node_t *gbl_current_node;
* typedef struct {
* node_t *prev;
* char *s;
* node_t *next;
* } node_t;
*
* ll_add_next(node, s)
* ll_add_prev(node, s)
* ll_make_node(prev, s, next)
* ll_remove_node(node)
* ll_next(node, num)
* ll_prev(node, num)
* ll_at(num)
* ll_free()
*
*/
/*
* Declarations
*/
/* The pointer type for a node in the global linked list */
typedef struct node_t node_t;
/* Used by undo functions */
extern node_t brake;
/*
* Constructive Functions
*/
/* Add a node with 's' as its value next to 'node' */
node_t *ll_add_next(node_t *node, char *s);
/* Add a node with 's' as its value before 'node' */
node_t *ll_add_prev(node_t *node, char *s);
/* Return a node with 's' as its values, 'prev' and 'next' as its pointers */
node_t *ll_make_node(node_t *prev, char *s, node_t *next);
node_t *ll_attach_nodes(node_t *n1, node_t *n2);
/* Initialise the global list */
node_t *ll_init();
/* Join (Concatenate) the strings of n1 and n2 */
node_t *ll_join_nodes(node_t *n1, node_t *n2);
void ll_set_current_node(node_t *node);
void ll_set_s(node_t *n, char *s);
node_t *ll_make_shallow(char *s);
/*
* Destructive Functions
*/
node_t *ll_remove_node(node_t *node);
/* Detach but don't free 'node' */
node_t *ll_remove_shallow(node_t *node);
void ll_detach_node(node_t *node);
/* Free the global list */
void ll_free();
void ll_free_node(node_t* node);
void ll_cut_node(node_t *n, int where);
/*
* Lookup Functions
*/
/* return the node which is 'offset' distance apart from 'node' */
node_t *ll_next(node_t *node, int offset);
node_t *ll_prev(node_t *node, int offset);
/* return the next node that matches 'reg' after 'node' */
node_t *ll_reg_next(node_t *node, regex_t *reg);
node_t *ll_reg_prev(node_t *node, regex_t *reg);
/* return the next node that DOES NOT match 'reg' after 'node' */
node_t *ll_reg_next_invert(node_t *node, regex_t *reg);
node_t *ll_reg_prev_invert(node_t *node, regex_t *reg);
/* Linked lists are 0 indexed */
node_t *ll_at(int n);
node_t *global_head();
node_t *global_current();
node_t *global_tail();
/* Access the value of a node */
char *ll_s(node_t *node);
/* return the length of the string at 'node', i.e. node->size */
ssize_t ll_node_size(node_t *node);
/* First node of the global list, according to the current convention */
node_t *ll_first_node();
node_t *ll_last_node();
/* return the line number in the global list corresponding 'node' */
int ll_node_index(node_t *node);
ssize_t ll_len();
#endif