| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#include "buffer.h" |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
#include |
|
4
|
|
|
|
|
|
|
#include |
|
5
|
|
|
|
|
|
|
#include |
|
6
|
|
|
|
|
|
|
#include |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
void * |
|
9
|
53
|
|
|
|
|
|
hoedown_malloc(size_t size) |
|
10
|
|
|
|
|
|
|
{ |
|
11
|
53
|
|
|
|
|
|
void *ret = malloc(size); |
|
12
|
|
|
|
|
|
|
|
|
13
|
53
|
50
|
|
|
|
|
if (!ret) { |
|
14
|
0
|
|
|
|
|
|
fprintf(stderr, "Allocation failed.\n"); |
|
15
|
0
|
|
|
|
|
|
abort(); |
|
16
|
|
|
|
|
|
|
} |
|
17
|
|
|
|
|
|
|
|
|
18
|
53
|
|
|
|
|
|
return ret; |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
void * |
|
22
|
3
|
|
|
|
|
|
hoedown_calloc(size_t nmemb, size_t size) |
|
23
|
|
|
|
|
|
|
{ |
|
24
|
3
|
|
|
|
|
|
void *ret = calloc(nmemb, size); |
|
25
|
|
|
|
|
|
|
|
|
26
|
3
|
50
|
|
|
|
|
if (!ret) { |
|
27
|
0
|
|
|
|
|
|
fprintf(stderr, "Allocation failed.\n"); |
|
28
|
0
|
|
|
|
|
|
abort(); |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
3
|
|
|
|
|
|
return ret; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
void * |
|
35
|
51
|
|
|
|
|
|
hoedown_realloc(void *ptr, size_t size) |
|
36
|
|
|
|
|
|
|
{ |
|
37
|
51
|
|
|
|
|
|
void *ret = realloc(ptr, size); |
|
38
|
|
|
|
|
|
|
|
|
39
|
51
|
50
|
|
|
|
|
if (!ret) { |
|
40
|
0
|
|
|
|
|
|
fprintf(stderr, "Allocation failed.\n"); |
|
41
|
0
|
|
|
|
|
|
abort(); |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
51
|
|
|
|
|
|
return ret; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
void |
|
48
|
32
|
|
|
|
|
|
hoedown_buffer_init( |
|
49
|
|
|
|
|
|
|
hoedown_buffer *buf, |
|
50
|
|
|
|
|
|
|
size_t unit, |
|
51
|
|
|
|
|
|
|
hoedown_realloc_callback data_realloc, |
|
52
|
|
|
|
|
|
|
hoedown_free_callback data_free, |
|
53
|
|
|
|
|
|
|
hoedown_free_callback buffer_free) |
|
54
|
|
|
|
|
|
|
{ |
|
55
|
32
|
50
|
|
|
|
|
assert(buf); |
|
56
|
|
|
|
|
|
|
|
|
57
|
32
|
|
|
|
|
|
buf->data = NULL; |
|
58
|
32
|
|
|
|
|
|
buf->size = buf->asize = 0; |
|
59
|
32
|
|
|
|
|
|
buf->unit = unit; |
|
60
|
32
|
|
|
|
|
|
buf->data_realloc = data_realloc; |
|
61
|
32
|
|
|
|
|
|
buf->data_free = data_free; |
|
62
|
32
|
|
|
|
|
|
buf->buffer_free = buffer_free; |
|
63
|
32
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
void |
|
66
|
0
|
|
|
|
|
|
hoedown_buffer_uninit(hoedown_buffer *buf) |
|
67
|
|
|
|
|
|
|
{ |
|
68
|
0
|
0
|
|
|
|
|
assert(buf && buf->unit); |
|
|
|
0
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
buf->data_free(buf->data); |
|
70
|
0
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
hoedown_buffer * |
|
73
|
32
|
|
|
|
|
|
hoedown_buffer_new(size_t unit) |
|
74
|
|
|
|
|
|
|
{ |
|
75
|
32
|
|
|
|
|
|
hoedown_buffer *ret = hoedown_malloc(sizeof (hoedown_buffer)); |
|
76
|
32
|
|
|
|
|
|
hoedown_buffer_init(ret, unit, hoedown_realloc, free, free); |
|
77
|
32
|
|
|
|
|
|
return ret; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
void |
|
81
|
20
|
|
|
|
|
|
hoedown_buffer_free(hoedown_buffer *buf) |
|
82
|
|
|
|
|
|
|
{ |
|
83
|
20
|
50
|
|
|
|
|
if (!buf) return; |
|
84
|
20
|
50
|
|
|
|
|
assert(buf && buf->unit); |
|
|
|
50
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
|
86
|
20
|
|
|
|
|
|
buf->data_free(buf->data); |
|
87
|
|
|
|
|
|
|
|
|
88
|
20
|
50
|
|
|
|
|
if (buf->buffer_free) |
|
89
|
20
|
|
|
|
|
|
buf->buffer_free(buf); |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
void |
|
93
|
0
|
|
|
|
|
|
hoedown_buffer_reset(hoedown_buffer *buf) |
|
94
|
|
|
|
|
|
|
{ |
|
95
|
0
|
0
|
|
|
|
|
assert(buf && buf->unit); |
|
|
|
0
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
buf->data_free(buf->data); |
|
98
|
0
|
|
|
|
|
|
buf->data = NULL; |
|
99
|
0
|
|
|
|
|
|
buf->size = buf->asize = 0; |
|
100
|
0
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
void |
|
103
|
79
|
|
|
|
|
|
hoedown_buffer_grow(hoedown_buffer *buf, size_t neosz) |
|
104
|
|
|
|
|
|
|
{ |
|
105
|
|
|
|
|
|
|
size_t neoasz; |
|
106
|
79
|
50
|
|
|
|
|
assert(buf && buf->unit); |
|
|
|
50
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
|
108
|
79
|
100
|
|
|
|
|
if (buf->asize >= neosz) |
|
109
|
|
|
|
|
|
|
return; |
|
110
|
|
|
|
|
|
|
|
|
111
|
37
|
|
|
|
|
|
neoasz = buf->asize + buf->unit; |
|
112
|
54
|
100
|
|
|
|
|
while (neoasz < neosz) |
|
113
|
17
|
|
|
|
|
|
neoasz += buf->unit; |
|
114
|
|
|
|
|
|
|
|
|
115
|
37
|
|
|
|
|
|
buf->data = buf->data_realloc(buf->data, neoasz); |
|
116
|
37
|
|
|
|
|
|
buf->asize = neoasz; |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
void |
|
120
|
180
|
|
|
|
|
|
hoedown_buffer_put(hoedown_buffer *buf, const uint8_t *data, size_t size) |
|
121
|
|
|
|
|
|
|
{ |
|
122
|
180
|
50
|
|
|
|
|
assert(buf && buf->unit); |
|
|
|
50
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
|
124
|
180
|
100
|
|
|
|
|
if (buf->size + size > buf->asize) |
|
125
|
18
|
|
|
|
|
|
hoedown_buffer_grow(buf, buf->size + size); |
|
126
|
|
|
|
|
|
|
|
|
127
|
180
|
|
|
|
|
|
memcpy(buf->data + buf->size, data, size); |
|
128
|
180
|
|
|
|
|
|
buf->size += size; |
|
129
|
180
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
void |
|
132
|
0
|
|
|
|
|
|
hoedown_buffer_puts(hoedown_buffer *buf, const char *str) |
|
133
|
|
|
|
|
|
|
{ |
|
134
|
0
|
|
|
|
|
|
hoedown_buffer_put(buf, (const uint8_t *)str, strlen(str)); |
|
135
|
0
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
void |
|
138
|
55
|
|
|
|
|
|
hoedown_buffer_putc(hoedown_buffer *buf, uint8_t c) |
|
139
|
|
|
|
|
|
|
{ |
|
140
|
55
|
50
|
|
|
|
|
assert(buf && buf->unit); |
|
|
|
50
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
|
142
|
55
|
50
|
|
|
|
|
if (buf->size >= buf->asize) |
|
143
|
0
|
|
|
|
|
|
hoedown_buffer_grow(buf, buf->size + 1); |
|
144
|
|
|
|
|
|
|
|
|
145
|
55
|
|
|
|
|
|
buf->data[buf->size] = c; |
|
146
|
55
|
|
|
|
|
|
buf->size += 1; |
|
147
|
55
|
|
|
|
|
|
} |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
int |
|
150
|
0
|
|
|
|
|
|
hoedown_buffer_putf(hoedown_buffer *buf, FILE *file) |
|
151
|
|
|
|
|
|
|
{ |
|
152
|
0
|
0
|
|
|
|
|
assert(buf && buf->unit); |
|
|
|
0
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
|
154
|
0
|
0
|
|
|
|
|
while (!(feof(file) || ferror(file))) { |
|
|
|
0
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
|
hoedown_buffer_grow(buf, buf->size + buf->unit); |
|
156
|
0
|
|
|
|
|
|
buf->size += fread(buf->data + buf->size, 1, buf->unit, file); |
|
157
|
|
|
|
|
|
|
} |
|
158
|
|
|
|
|
|
|
|
|
159
|
0
|
|
|
|
|
|
return ferror(file); |
|
160
|
|
|
|
|
|
|
} |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
void |
|
163
|
0
|
|
|
|
|
|
hoedown_buffer_set(hoedown_buffer *buf, const uint8_t *data, size_t size) |
|
164
|
|
|
|
|
|
|
{ |
|
165
|
0
|
0
|
|
|
|
|
assert(buf && buf->unit); |
|
|
|
0
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
|
|
167
|
0
|
0
|
|
|
|
|
if (size > buf->asize) |
|
168
|
0
|
|
|
|
|
|
hoedown_buffer_grow(buf, size); |
|
169
|
|
|
|
|
|
|
|
|
170
|
0
|
|
|
|
|
|
memcpy(buf->data, data, size); |
|
171
|
0
|
|
|
|
|
|
buf->size = size; |
|
172
|
0
|
|
|
|
|
|
} |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
void |
|
175
|
0
|
|
|
|
|
|
hoedown_buffer_sets(hoedown_buffer *buf, const char *str) |
|
176
|
|
|
|
|
|
|
{ |
|
177
|
0
|
|
|
|
|
|
hoedown_buffer_set(buf, (const uint8_t *)str, strlen(str)); |
|
178
|
0
|
|
|
|
|
|
} |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
int |
|
181
|
0
|
|
|
|
|
|
hoedown_buffer_eq(const hoedown_buffer *buf, const uint8_t *data, size_t size) |
|
182
|
|
|
|
|
|
|
{ |
|
183
|
0
|
0
|
|
|
|
|
if (buf->size != size) return 0; |
|
184
|
0
|
|
|
|
|
|
return memcmp(buf->data, data, size) == 0; |
|
185
|
|
|
|
|
|
|
} |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
int |
|
188
|
0
|
|
|
|
|
|
hoedown_buffer_eqs(const hoedown_buffer *buf, const char *str) |
|
189
|
|
|
|
|
|
|
{ |
|
190
|
0
|
|
|
|
|
|
return hoedown_buffer_eq(buf, (const uint8_t *)str, strlen(str)); |
|
191
|
|
|
|
|
|
|
} |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
int |
|
194
|
1
|
|
|
|
|
|
hoedown_buffer_prefix(const hoedown_buffer *buf, const char *prefix) |
|
195
|
|
|
|
|
|
|
{ |
|
196
|
|
|
|
|
|
|
size_t i; |
|
197
|
|
|
|
|
|
|
|
|
198
|
1
|
50
|
|
|
|
|
for (i = 0; i < buf->size; ++i) { |
|
199
|
1
|
50
|
|
|
|
|
if (prefix[i] == 0) |
|
200
|
|
|
|
|
|
|
return 0; |
|
201
|
|
|
|
|
|
|
|
|
202
|
1
|
50
|
|
|
|
|
if (buf->data[i] != prefix[i]) |
|
203
|
1
|
|
|
|
|
|
return buf->data[i] - prefix[i]; |
|
204
|
|
|
|
|
|
|
} |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
return 0; |
|
207
|
|
|
|
|
|
|
} |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
void |
|
210
|
0
|
|
|
|
|
|
hoedown_buffer_slurp(hoedown_buffer *buf, size_t size) |
|
211
|
|
|
|
|
|
|
{ |
|
212
|
0
|
0
|
|
|
|
|
assert(buf && buf->unit); |
|
|
|
0
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
|
|
214
|
0
|
0
|
|
|
|
|
if (size >= buf->size) { |
|
215
|
0
|
|
|
|
|
|
buf->size = 0; |
|
216
|
0
|
|
|
|
|
|
return; |
|
217
|
|
|
|
|
|
|
} |
|
218
|
|
|
|
|
|
|
|
|
219
|
0
|
|
|
|
|
|
buf->size -= size; |
|
220
|
0
|
|
|
|
|
|
memmove(buf->data, buf->data + size, buf->size); |
|
221
|
|
|
|
|
|
|
} |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
const char * |
|
224
|
7
|
|
|
|
|
|
hoedown_buffer_cstr(hoedown_buffer *buf) |
|
225
|
|
|
|
|
|
|
{ |
|
226
|
7
|
50
|
|
|
|
|
assert(buf && buf->unit); |
|
|
|
50
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
|
|
228
|
7
|
50
|
|
|
|
|
if (buf->size < buf->asize && buf->data[buf->size] == 0) |
|
|
|
100
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
return (char *)buf->data; |
|
230
|
|
|
|
|
|
|
|
|
231
|
1
|
|
|
|
|
|
hoedown_buffer_grow(buf, buf->size + 1); |
|
232
|
1
|
|
|
|
|
|
buf->data[buf->size] = 0; |
|
233
|
|
|
|
|
|
|
|
|
234
|
1
|
|
|
|
|
|
return (char *)buf->data; |
|
235
|
|
|
|
|
|
|
} |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
void |
|
238
|
39
|
|
|
|
|
|
hoedown_buffer_printf(hoedown_buffer *buf, const char *fmt, ...) |
|
239
|
|
|
|
|
|
|
{ |
|
240
|
|
|
|
|
|
|
va_list ap; |
|
241
|
|
|
|
|
|
|
int n; |
|
242
|
|
|
|
|
|
|
|
|
243
|
39
|
50
|
|
|
|
|
assert(buf && buf->unit); |
|
|
|
50
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
|
|
245
|
39
|
100
|
|
|
|
|
if (buf->size >= buf->asize) |
|
246
|
1
|
|
|
|
|
|
hoedown_buffer_grow(buf, buf->size + 1); |
|
247
|
|
|
|
|
|
|
|
|
248
|
39
|
|
|
|
|
|
va_start(ap, fmt); |
|
249
|
39
|
|
|
|
|
|
n = vsnprintf((char *)buf->data + buf->size, buf->asize - buf->size, fmt, ap); |
|
250
|
39
|
|
|
|
|
|
va_end(ap); |
|
251
|
|
|
|
|
|
|
|
|
252
|
39
|
50
|
|
|
|
|
if (n < 0) { |
|
253
|
|
|
|
|
|
|
#ifndef _MSC_VER |
|
254
|
0
|
|
|
|
|
|
return; |
|
255
|
|
|
|
|
|
|
#else |
|
256
|
|
|
|
|
|
|
va_start(ap, fmt); |
|
257
|
|
|
|
|
|
|
n = _vscprintf(fmt, ap); |
|
258
|
|
|
|
|
|
|
va_end(ap); |
|
259
|
|
|
|
|
|
|
#endif |
|
260
|
|
|
|
|
|
|
} |
|
261
|
|
|
|
|
|
|
|
|
262
|
39
|
100
|
|
|
|
|
if ((size_t)n >= buf->asize - buf->size) { |
|
263
|
1
|
|
|
|
|
|
hoedown_buffer_grow(buf, buf->size + n + 1); |
|
264
|
|
|
|
|
|
|
|
|
265
|
1
|
|
|
|
|
|
va_start(ap, fmt); |
|
266
|
1
|
|
|
|
|
|
n = vsnprintf((char *)buf->data + buf->size, buf->asize - buf->size, fmt, ap); |
|
267
|
1
|
|
|
|
|
|
va_end(ap); |
|
268
|
|
|
|
|
|
|
} |
|
269
|
|
|
|
|
|
|
|
|
270
|
39
|
50
|
|
|
|
|
if (n < 0) |
|
271
|
|
|
|
|
|
|
return; |
|
272
|
|
|
|
|
|
|
|
|
273
|
39
|
|
|
|
|
|
buf->size += n; |
|
274
|
|
|
|
|
|
|
} |
|
275
|
|
|
|
|
|
|
|
|
276
|
0
|
|
|
|
|
|
void hoedown_buffer_put_utf8(hoedown_buffer *buf, unsigned int c) { |
|
277
|
|
|
|
|
|
|
unsigned char unichar[4]; |
|
278
|
|
|
|
|
|
|
|
|
279
|
0
|
0
|
|
|
|
|
assert(buf && buf->unit); |
|
|
|
0
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
|
|
281
|
0
|
0
|
|
|
|
|
if (c < 0x80) { |
|
282
|
0
|
|
|
|
|
|
hoedown_buffer_putc(buf, c); |
|
283
|
|
|
|
|
|
|
} |
|
284
|
0
|
0
|
|
|
|
|
else if (c < 0x800) { |
|
285
|
0
|
|
|
|
|
|
unichar[0] = 192 + (c / 64); |
|
286
|
0
|
|
|
|
|
|
unichar[1] = 128 + (c % 64); |
|
287
|
0
|
|
|
|
|
|
hoedown_buffer_put(buf, unichar, 2); |
|
288
|
|
|
|
|
|
|
} |
|
289
|
0
|
0
|
|
|
|
|
else if (c - 0xd800u < 0x800) { |
|
290
|
0
|
|
|
|
|
|
HOEDOWN_BUFPUTSL(buf, "\xef\xbf\xbd"); |
|
291
|
|
|
|
|
|
|
} |
|
292
|
0
|
0
|
|
|
|
|
else if (c < 0x10000) { |
|
293
|
0
|
|
|
|
|
|
unichar[0] = 224 + (c / 4096); |
|
294
|
0
|
|
|
|
|
|
unichar[1] = 128 + (c / 64) % 64; |
|
295
|
0
|
|
|
|
|
|
unichar[2] = 128 + (c % 64); |
|
296
|
0
|
|
|
|
|
|
hoedown_buffer_put(buf, unichar, 3); |
|
297
|
|
|
|
|
|
|
} |
|
298
|
0
|
0
|
|
|
|
|
else if (c < 0x110000) { |
|
299
|
0
|
|
|
|
|
|
unichar[0] = 240 + (c / 262144); |
|
300
|
0
|
|
|
|
|
|
unichar[1] = 128 + (c / 4096) % 64; |
|
301
|
0
|
|
|
|
|
|
unichar[2] = 128 + (c / 64) % 64; |
|
302
|
0
|
|
|
|
|
|
unichar[3] = 128 + (c % 64); |
|
303
|
0
|
|
|
|
|
|
hoedown_buffer_put(buf, unichar, 4); |
|
304
|
|
|
|
|
|
|
} |
|
305
|
|
|
|
|
|
|
else { |
|
306
|
0
|
|
|
|
|
|
HOEDOWN_BUFPUTSL(buf, "\xef\xbf\xbd"); |
|
307
|
|
|
|
|
|
|
} |
|
308
|
0
|
|
|
|
|
|
} |