4223
|
1 #include "text.h"
|
|
2 #include "xmalloc.h"
|
|
3
|
|
4 #include <stddef.h>
|
|
5
|
|
6 enum {MAGIC = 42};
|
|
7
|
|
8 void text_on(struct text *p) {
|
|
9 p->start = xmalloc(p->size = MAGIC, sizeof *p->start);
|
|
10 p->start[p->length = 0] = NULL;
|
|
11 }
|
|
12
|
|
13 void text_off(struct text *p) {
|
|
14 while (p->length) {
|
|
15 --p->length;
|
|
16 op_end(p->start[p->length]);
|
|
17 xfree(p->start[p->length]);
|
|
18 }
|
|
19 xfree(p->start);
|
|
20 }
|
|
21
|
|
22 void text_1(struct text *p) {
|
|
23 while (p->length >= p->size - 1) {
|
|
24 p->start = xrealloc(p->start, p->size *= 2);
|
|
25 }
|
|
26 }
|
|
27
|
|
28 struct op *text_push(struct text *p, const struct op *src) {
|
|
29 text_1(p);
|
|
30 p->start[p->length] = xmalloc(1, sizeof *p->start[p->length]);
|
|
31 *p->start[p->length++] = *src;
|
|
32 p->start[p->length] = NULL;
|
|
33 return p->start[p->length - 1];
|
|
34 }
|