-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.c
105 lines (102 loc) · 1.85 KB
/
types.c
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
104
105
/*
* Line structure: calling newLine() will return an empty line containing only
* zeros
*/
typedef struct Line Line;
struct Line {
char *c;
size_t blen;
size_t clen;
size_t mlen;
Line *next;
Line *prev;
};
Line *newLine()
{
Line *line;
line = malloc(sizeof(Line));
line->c = malloc(LINESIZE);
line->c[0] = 0;
line->blen = 0;
line->clen = 0;
line->mlen = LINESIZE;
line->next = 0;
line->prev = 0;
return line;
}
/*
* Filepos structure: calling newFilepos() will return an empty Filepos
*/
typedef struct Filepos Filepos;
struct Filepos {
Line *l;
size_t p;
};
Filepos *newFilepos()
{
Filepos *fp;
fp = malloc(sizeof(Filepos));
fp->l = 0;
fp->p = 0;
return fp;
}
/*
* File structure: calling newFile() will return a File with an empty Line and
* a cursor and anchor pointing to the first line. next, prev and path will
* be zero
*/
typedef struct File File;
struct File {
Line *first;
Line *sel;
Filepos *cur;
Filepos *anc;
File *next;
File *prev;
char *path;
char *type;
};
File *newFile()
{
File *file;
file = malloc(sizeof(File));
file->first = newLine();
file->sel = 0;
file->cur = newFilepos();
file->cur->l = file->first;
file->anc = newFilepos();
file->anc->l = file->first;
file->next = 0;
file->prev = 0;
file->path = 0;
file->type = 0;
return file;
}
typedef struct Cmd Cmd;
struct Cmd{
char *msg; // message to be displayed
char *type; // type
char *c; // content
char input; // input method 0=full input 1=only numbers
size_t cur; // cursor
size_t anc; // anchor
size_t blen; // byte lenght
size_t clen; // content lenght
size_t mlen; // lenght of malloced line
};
Cmd *newCmd()
{
Cmd *cmd;
cmd = malloc(sizeof(Cmd));
cmd->msg = 0;
cmd->type = 0;
cmd->c = malloc(LINESIZE);
cmd->c[0] = 0;
cmd->input = 0;
cmd->cur = 0;
cmd->anc = 0;
cmd->blen = 0;
cmd->clen = 0;
cmd->mlen = 0;
return cmd;
}