-
Notifications
You must be signed in to change notification settings - Fork 13
/
buffer.h
98 lines (66 loc) · 1.49 KB
/
buffer.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
#ifndef BUFFER_H
#define BUFFER_H
#include <stdbool.h>
#include <stdlib.h>
typedef enum DIRECTION {
UP,
DOWN,
RIGHT,
LEFT
} DIRECTION;
typedef enum MODE {
NORMAL,
INSERT_FRONT,
INSERT_BACK,
VISUAL,
EX
} MODE;
typedef struct echar {
char c;
struct echar *prev;
struct echar *next;
} echar_t;
typedef struct row {
echar_t *current;
echar_t *head;
echar_t *last;
size_t line_size;
bool is_dirty;
struct row *prev;
struct row *next;
} row_t;
typedef struct buffer {
row_t *current;
row_t *head;
row_t *last;
// total number of rows out there
size_t num_rows;
// current char/row (x, y) index
size_t current_char;
size_t current_row;
bool is_dirty;
const char *filename;
// insert/normal/visual/ex
MODE mode;
} buffer_t;
buffer_t *init_buffer(const char *filename);
void add_char(row_t *r, char c);
void drop_char(row_t *r);
void append_char(buffer_t *buf, char c);
void prepend_char(buffer_t *buf, char c);
void delete_char(buffer_t *buf);
row_t *init_row(const char *line);
void destroy_row(row_t *r);
void append_row(buffer_t *buf, const char *line);
void prepend_row(buffer_t *buf, const char *line);
void join_row(buffer_t *buf);
void split_row(buffer_t *buf);
void move_current(buffer_t *buf, DIRECTION d);
void to_right(buffer_t *buf);
void to_left(buffer_t *buf);
void to_top(buffer_t *buf);
void to_bottom(buffer_t *buf);
void clear_row(row_t *r);
void delete_row(buffer_t *buf);
void destroy_buffer(buffer_t *buf);
#endif