-
Notifications
You must be signed in to change notification settings - Fork 6
/
buffer.h
75 lines (59 loc) · 1.31 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
#ifndef BUFFER_H
#define BUFFER_H
#include <stdbool.h>
#include <stdint.h>
#include <wchar.h>
#define NONE ((size_t)-1)
typedef size_t lineno;
typedef size_t colno;
struct POS{
lineno l;
colno c;
};
struct LINE{
size_t a, n;
wchar_t *s;
};
struct TAG{
POS p1;
POS p2;
int v;
};
typedef enum{ /* note that these must be in descending order by priority */
VIRTCURS,
HIGHLIGHT,
BLOCK,
TAG_MAX
} tag;
typedef uint64_t txn;
struct BUFFER{
size_t a, n;
LINE *l;
bool canundo, dirty;
int nbegin;
txn t;
JOURNAL *j;
TAG tags[TAG_MAX];
};
BUFFER *openbuffer(void);
void closebuffer(BUFFER *b);
bool insertline(BUFFER *b, lineno l);
bool inserttext(BUFFER *b, POS p, const wchar_t *s, size_t n);
bool deleteline(BUFFER *b, lineno l);
bool deletetext(BUFFER *b, POS p, size_t n);
wint_t charat(const BUFFER *b, POS p);
bool prev(const BUFFER *b, POS *p);
bool next(const BUFFER *b, POS *p);
bool attop(const BUFFER *b, POS p);
bool atbot(const BUFFER *b, POS p);
bool ateol(const BUFFER *b, POS p);
POS pos(lineno l, colno c);
bool settag(BUFFER *b, tag t, POS p1, POS p2, int v);
void cleartag(BUFFER *b, tag t);
void enableundo(BUFFER *b);
bool mark(BUFFER *b);
void begin(BUFFER *b);
bool commit(BUFFER *b);
bool undo(BUFFER *b, POS *p);
void clearundo(BUFFER *b);
#endif