rmultimarkdown 6.4.0.4 → 6.7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/Rakefile +7 -13
- data/ext/Makefile +67 -55
- data/ext/extconf.rb +7 -5
- data/ext/mmd/aho-corasick.c +8 -8
- data/ext/mmd/aho-corasick.h +3 -3
- data/ext/mmd/argtable3.c +6537 -0
- data/ext/mmd/argtable3.h +273 -0
- data/ext/mmd/beamer.c +12 -1
- data/ext/mmd/char.c +120 -27
- data/ext/mmd/char.h +23 -23
- data/ext/mmd/critic_markup.c +7 -6
- data/ext/mmd/d_string.c +88 -32
- data/ext/mmd/{include/d_string.h → d_string.h} +50 -38
- data/ext/mmd/epub.c +36 -12
- data/ext/mmd/epub.h +2 -2
- data/ext/mmd/file.c +50 -40
- data/ext/mmd/file.h +2 -2
- data/ext/mmd/html.c +164 -99
- data/ext/mmd/html.h +3 -2
- data/ext/mmd/i18n.h +15 -11
- data/ext/mmd/itmz-lexer.c +16978 -0
- data/ext/mmd/itmz-lexer.h +132 -0
- data/ext/mmd/itmz-parser.c +1189 -0
- data/ext/mmd/itmz-parser.h +11 -0
- data/ext/mmd/itmz-reader.c +388 -0
- data/ext/mmd/itmz-reader.h +111 -0
- data/ext/mmd/itmz.c +567 -0
- data/ext/mmd/itmz.h +117 -0
- data/ext/mmd/latex.c +93 -41
- data/ext/mmd/lexer.c +3506 -2774
- data/ext/mmd/{include/libMultiMarkdown.h → libMultiMarkdown.h} +49 -2
- data/ext/mmd/main.c +612 -0
- data/ext/mmd/memoir.c +4 -1
- data/ext/mmd/miniz.c +6905 -6680
- data/ext/mmd/miniz.h +456 -476
- data/ext/mmd/mmd.c +399 -94
- data/ext/mmd/mmd.h +25 -25
- data/ext/mmd/object_pool.h +3 -3
- data/ext/mmd/opendocument-content.c +137 -69
- data/ext/mmd/opendocument-content.h +2 -2
- data/ext/mmd/opendocument.c +35 -14
- data/ext/mmd/opendocument.h +2 -2
- data/ext/mmd/opml-lexer.c +259 -637
- data/ext/mmd/opml-lexer.h +1 -17
- data/ext/mmd/opml-parser.c +194 -188
- data/ext/mmd/opml-reader.c +72 -142
- data/ext/mmd/opml-reader.h +1 -1
- data/ext/mmd/opml.c +13 -13
- data/ext/mmd/opml.h +1 -1
- data/ext/mmd/parser.c +1623 -1244
- data/ext/mmd/rng.c +8 -3
- data/ext/mmd/scanners.c +66625 -103198
- data/ext/mmd/scanners.h +1 -0
- data/ext/mmd/stack.c +62 -20
- data/ext/mmd/stack.h +10 -21
- data/ext/mmd/textbundle.c +23 -7
- data/ext/mmd/textbundle.h +2 -2
- data/ext/mmd/token.c +42 -16
- data/ext/mmd/{include/token.h → token.h} +22 -8
- data/ext/mmd/token_pairs.c +0 -16
- data/ext/mmd/transclude.c +6 -2
- data/ext/mmd/uthash.h +745 -745
- data/ext/mmd/version.h +8 -8
- data/ext/mmd/writer.c +225 -63
- data/ext/mmd/writer.h +50 -36
- data/ext/mmd/xml.c +855 -0
- data/ext/mmd/xml.h +134 -0
- data/ext/mmd/zip.c +71 -4
- data/ext/mmd/zip.h +7 -1
- data/ext/ruby_multi_markdown.c +9 -18
- data/lib/multi_markdown/version.rb +1 -1
- data/lib/multi_markdown.bundle +0 -0
- data/rmultimarkdown.gemspec +0 -2
- metadata +22 -28
- data/ext/mmd/char_lookup.c +0 -212
data/ext/mmd/xml.c
ADDED
|
@@ -0,0 +1,855 @@
|
|
|
1
|
+
/* Generated by re2c 1.3 on Tue Sep 28 18:26:57 2021 */
|
|
2
|
+
/**
|
|
3
|
+
|
|
4
|
+
MultiMarkdown -- Lightweight markup processor to produce HTML, LaTeX, and more.
|
|
5
|
+
|
|
6
|
+
@file xml.c
|
|
7
|
+
|
|
8
|
+
@brief Utilities to help parse XML files
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@author Fletcher T. Penney
|
|
12
|
+
@bug
|
|
13
|
+
|
|
14
|
+
**/
|
|
15
|
+
|
|
16
|
+
/*
|
|
17
|
+
|
|
18
|
+
Copyright © 2016 - 2019 Fletcher T. Penney.
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
The `MultiMarkdown 6` project is released under the MIT License..
|
|
22
|
+
|
|
23
|
+
GLibFacade.c and GLibFacade.h are from the MultiMarkdown v4 project:
|
|
24
|
+
|
|
25
|
+
https://github.com/fletcher/MultiMarkdown-4/
|
|
26
|
+
|
|
27
|
+
MMD 4 is released under both the MIT License and GPL.
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
CuTest is released under the zlib/libpng license. See CuTest.c for the
|
|
31
|
+
text of the license.
|
|
32
|
+
|
|
33
|
+
uthash library:
|
|
34
|
+
Copyright (c) 2005-2016, Troy D. Hanson
|
|
35
|
+
|
|
36
|
+
Licensed under Revised BSD license
|
|
37
|
+
|
|
38
|
+
miniz library:
|
|
39
|
+
Copyright 2013-2014 RAD Game Tools and Valve Software
|
|
40
|
+
Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
|
|
41
|
+
|
|
42
|
+
Licensed under the MIT license
|
|
43
|
+
|
|
44
|
+
argtable3 library:
|
|
45
|
+
Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann
|
|
46
|
+
<sheitmann@users.sourceforge.net>
|
|
47
|
+
All rights reserved.
|
|
48
|
+
|
|
49
|
+
Licensed under the Revised BSD License
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
## The MIT License ##
|
|
53
|
+
|
|
54
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
55
|
+
a copy of this software and associated documentation files (the
|
|
56
|
+
"Software"), to deal in the Software without restriction, including
|
|
57
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
58
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
59
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
60
|
+
the following conditions:
|
|
61
|
+
|
|
62
|
+
The above copyright notice and this permission notice shall be
|
|
63
|
+
included in all copies or substantial portions of the Software.
|
|
64
|
+
|
|
65
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
66
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
67
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
68
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
69
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
70
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
71
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
## Revised BSD License ##
|
|
75
|
+
|
|
76
|
+
Redistribution and use in source and binary forms, with or without
|
|
77
|
+
modification, are permitted provided that the following conditions are
|
|
78
|
+
met:
|
|
79
|
+
* Redistributions of source code must retain the above copyright
|
|
80
|
+
notice, this list of conditions and the following disclaimer.
|
|
81
|
+
* Redistributions in binary form must reproduce the above
|
|
82
|
+
copyright notice, this list of conditions and the following
|
|
83
|
+
disclaimer in the documentation and/or other materials provided
|
|
84
|
+
with the distribution.
|
|
85
|
+
* Neither the name of the <organization> nor the
|
|
86
|
+
names of its contributors may be used to endorse or promote
|
|
87
|
+
products derived from this software without specific prior
|
|
88
|
+
written permission.
|
|
89
|
+
|
|
90
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
91
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
92
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
93
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT
|
|
94
|
+
HOLDER> BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
95
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
96
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES LOSS OF USE, DATA, OR
|
|
97
|
+
PROFITS OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
98
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
99
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
100
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
*/
|
|
104
|
+
|
|
105
|
+
#include <ctype.h>
|
|
106
|
+
#include <stdlib.h>
|
|
107
|
+
#include <string.h>
|
|
108
|
+
|
|
109
|
+
#include "d_string.h"
|
|
110
|
+
#include "xml.h"
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
#define print(x) d_string_append(out, x)
|
|
114
|
+
#define print_const(x) d_string_append_c_array(out, x, sizeof(x) - 1)
|
|
115
|
+
#define print_char(x) d_string_append_c(out, x)
|
|
116
|
+
#define printf(...) d_string_append_printf(out, __VA_ARGS__)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
/// strndup not available on all platforms
|
|
120
|
+
static char * my_strndup(const char * source, size_t n) {
|
|
121
|
+
if (source == NULL) {
|
|
122
|
+
return NULL;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
size_t len = 0;
|
|
126
|
+
char * result;
|
|
127
|
+
const char * test = source;
|
|
128
|
+
|
|
129
|
+
// strlen is too slow if strlen(source) >> n
|
|
130
|
+
for (len = 0; len < n; ++len) {
|
|
131
|
+
if (*test == '\0') {
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
test++;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
result = malloc(len + 1);
|
|
139
|
+
|
|
140
|
+
if (result) {
|
|
141
|
+
memcpy(result, source, len);
|
|
142
|
+
result[len] = '\0';
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return result;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
/// skip through whitespace
|
|
153
|
+
size_t xml_scan_wsnl(const char * c) {
|
|
154
|
+
const char * start = c;
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
{
|
|
158
|
+
unsigned char yych;
|
|
159
|
+
yych = *c;
|
|
160
|
+
|
|
161
|
+
switch (yych) {
|
|
162
|
+
case '\t':
|
|
163
|
+
case '\n':
|
|
164
|
+
case '\r':
|
|
165
|
+
case ' ':
|
|
166
|
+
goto yy4;
|
|
167
|
+
|
|
168
|
+
default:
|
|
169
|
+
goto yy2;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
yy2:
|
|
173
|
+
++c;
|
|
174
|
+
{
|
|
175
|
+
return 0;
|
|
176
|
+
}
|
|
177
|
+
yy4:
|
|
178
|
+
yych = *++c;
|
|
179
|
+
|
|
180
|
+
switch (yych) {
|
|
181
|
+
case '\t':
|
|
182
|
+
case '\n':
|
|
183
|
+
case '\r':
|
|
184
|
+
case ' ':
|
|
185
|
+
goto yy4;
|
|
186
|
+
|
|
187
|
+
default:
|
|
188
|
+
goto yy6;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
yy6: {
|
|
192
|
+
return (size_t)( c - start );
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
/// scan generic attribute_name
|
|
200
|
+
size_t xml_scan_attribute_name(const char * c) {
|
|
201
|
+
;
|
|
202
|
+
const char * start = c;
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
{
|
|
206
|
+
unsigned char yych;
|
|
207
|
+
yych = *c;
|
|
208
|
+
|
|
209
|
+
switch (yych) {
|
|
210
|
+
case ':':
|
|
211
|
+
case 'A':
|
|
212
|
+
case 'B':
|
|
213
|
+
case 'C':
|
|
214
|
+
case 'D':
|
|
215
|
+
case 'E':
|
|
216
|
+
case 'F':
|
|
217
|
+
case 'G':
|
|
218
|
+
case 'H':
|
|
219
|
+
case 'I':
|
|
220
|
+
case 'J':
|
|
221
|
+
case 'K':
|
|
222
|
+
case 'L':
|
|
223
|
+
case 'M':
|
|
224
|
+
case 'N':
|
|
225
|
+
case 'O':
|
|
226
|
+
case 'P':
|
|
227
|
+
case 'Q':
|
|
228
|
+
case 'R':
|
|
229
|
+
case 'S':
|
|
230
|
+
case 'T':
|
|
231
|
+
case 'U':
|
|
232
|
+
case 'V':
|
|
233
|
+
case 'W':
|
|
234
|
+
case 'X':
|
|
235
|
+
case 'Y':
|
|
236
|
+
case 'Z':
|
|
237
|
+
case '_':
|
|
238
|
+
case 'a':
|
|
239
|
+
case 'b':
|
|
240
|
+
case 'c':
|
|
241
|
+
case 'd':
|
|
242
|
+
case 'e':
|
|
243
|
+
case 'f':
|
|
244
|
+
case 'g':
|
|
245
|
+
case 'h':
|
|
246
|
+
case 'i':
|
|
247
|
+
case 'j':
|
|
248
|
+
case 'k':
|
|
249
|
+
case 'l':
|
|
250
|
+
case 'm':
|
|
251
|
+
case 'n':
|
|
252
|
+
case 'o':
|
|
253
|
+
case 'p':
|
|
254
|
+
case 'q':
|
|
255
|
+
case 'r':
|
|
256
|
+
case 's':
|
|
257
|
+
case 't':
|
|
258
|
+
case 'u':
|
|
259
|
+
case 'v':
|
|
260
|
+
case 'w':
|
|
261
|
+
case 'x':
|
|
262
|
+
case 'y':
|
|
263
|
+
case 'z':
|
|
264
|
+
goto yy11;
|
|
265
|
+
|
|
266
|
+
default:
|
|
267
|
+
goto yy9;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
yy9:
|
|
271
|
+
++c;
|
|
272
|
+
{
|
|
273
|
+
return 0;
|
|
274
|
+
}
|
|
275
|
+
yy11:
|
|
276
|
+
yych = *++c;
|
|
277
|
+
|
|
278
|
+
switch (yych) {
|
|
279
|
+
case '-':
|
|
280
|
+
case '.':
|
|
281
|
+
case '0':
|
|
282
|
+
case '1':
|
|
283
|
+
case '2':
|
|
284
|
+
case '3':
|
|
285
|
+
case '4':
|
|
286
|
+
case '5':
|
|
287
|
+
case '6':
|
|
288
|
+
case '7':
|
|
289
|
+
case '8':
|
|
290
|
+
case '9':
|
|
291
|
+
case ':':
|
|
292
|
+
case 'A':
|
|
293
|
+
case 'B':
|
|
294
|
+
case 'C':
|
|
295
|
+
case 'D':
|
|
296
|
+
case 'E':
|
|
297
|
+
case 'F':
|
|
298
|
+
case 'G':
|
|
299
|
+
case 'H':
|
|
300
|
+
case 'I':
|
|
301
|
+
case 'J':
|
|
302
|
+
case 'K':
|
|
303
|
+
case 'L':
|
|
304
|
+
case 'M':
|
|
305
|
+
case 'N':
|
|
306
|
+
case 'O':
|
|
307
|
+
case 'P':
|
|
308
|
+
case 'Q':
|
|
309
|
+
case 'R':
|
|
310
|
+
case 'S':
|
|
311
|
+
case 'T':
|
|
312
|
+
case 'U':
|
|
313
|
+
case 'V':
|
|
314
|
+
case 'W':
|
|
315
|
+
case 'X':
|
|
316
|
+
case 'Y':
|
|
317
|
+
case 'Z':
|
|
318
|
+
case '_':
|
|
319
|
+
case 'a':
|
|
320
|
+
case 'b':
|
|
321
|
+
case 'c':
|
|
322
|
+
case 'd':
|
|
323
|
+
case 'e':
|
|
324
|
+
case 'f':
|
|
325
|
+
case 'g':
|
|
326
|
+
case 'h':
|
|
327
|
+
case 'i':
|
|
328
|
+
case 'j':
|
|
329
|
+
case 'k':
|
|
330
|
+
case 'l':
|
|
331
|
+
case 'm':
|
|
332
|
+
case 'n':
|
|
333
|
+
case 'o':
|
|
334
|
+
case 'p':
|
|
335
|
+
case 'q':
|
|
336
|
+
case 'r':
|
|
337
|
+
case 's':
|
|
338
|
+
case 't':
|
|
339
|
+
case 'u':
|
|
340
|
+
case 'v':
|
|
341
|
+
case 'w':
|
|
342
|
+
case 'x':
|
|
343
|
+
case 'y':
|
|
344
|
+
case 'z':
|
|
345
|
+
goto yy11;
|
|
346
|
+
|
|
347
|
+
default:
|
|
348
|
+
goto yy13;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
yy13: {
|
|
352
|
+
return (size_t)( c - start );
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
/// scan until start of value, if present
|
|
360
|
+
size_t xml_scan_until_value(const char * c) {
|
|
361
|
+
const char * marker = NULL;
|
|
362
|
+
const char * start = c;
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
{
|
|
366
|
+
unsigned char yych;
|
|
367
|
+
yych = *c;
|
|
368
|
+
|
|
369
|
+
switch (yych) {
|
|
370
|
+
case '\t':
|
|
371
|
+
case '\n':
|
|
372
|
+
case '\r':
|
|
373
|
+
case ' ':
|
|
374
|
+
goto yy18;
|
|
375
|
+
|
|
376
|
+
case '=':
|
|
377
|
+
goto yy19;
|
|
378
|
+
|
|
379
|
+
default:
|
|
380
|
+
goto yy16;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
yy16:
|
|
384
|
+
++c;
|
|
385
|
+
yy17: {
|
|
386
|
+
return 0;
|
|
387
|
+
}
|
|
388
|
+
yy18:
|
|
389
|
+
yych = *(marker = ++c);
|
|
390
|
+
|
|
391
|
+
switch (yych) {
|
|
392
|
+
case '\t':
|
|
393
|
+
case '\n':
|
|
394
|
+
case '\r':
|
|
395
|
+
case ' ':
|
|
396
|
+
goto yy20;
|
|
397
|
+
|
|
398
|
+
case '=':
|
|
399
|
+
goto yy23;
|
|
400
|
+
|
|
401
|
+
default:
|
|
402
|
+
goto yy17;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
yy19:
|
|
406
|
+
yych = *(marker = ++c);
|
|
407
|
+
|
|
408
|
+
switch (yych) {
|
|
409
|
+
case '\t':
|
|
410
|
+
case '\n':
|
|
411
|
+
case '\r':
|
|
412
|
+
case ' ':
|
|
413
|
+
goto yy23;
|
|
414
|
+
|
|
415
|
+
case '"':
|
|
416
|
+
marker = c;
|
|
417
|
+
goto yy25;
|
|
418
|
+
|
|
419
|
+
case '\'':
|
|
420
|
+
marker = c;
|
|
421
|
+
goto yy27;
|
|
422
|
+
|
|
423
|
+
default:
|
|
424
|
+
goto yy17;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
yy20:
|
|
428
|
+
yych = *++c;
|
|
429
|
+
|
|
430
|
+
switch (yych) {
|
|
431
|
+
case '\t':
|
|
432
|
+
case '\n':
|
|
433
|
+
case '\r':
|
|
434
|
+
case ' ':
|
|
435
|
+
goto yy20;
|
|
436
|
+
|
|
437
|
+
case '=':
|
|
438
|
+
goto yy23;
|
|
439
|
+
|
|
440
|
+
default:
|
|
441
|
+
goto yy22;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
yy22:
|
|
445
|
+
c = marker;
|
|
446
|
+
goto yy17;
|
|
447
|
+
yy23:
|
|
448
|
+
yych = *++c;
|
|
449
|
+
|
|
450
|
+
switch (yych) {
|
|
451
|
+
case '\t':
|
|
452
|
+
case '\n':
|
|
453
|
+
case '\r':
|
|
454
|
+
case ' ':
|
|
455
|
+
goto yy23;
|
|
456
|
+
|
|
457
|
+
case '"':
|
|
458
|
+
marker = c;
|
|
459
|
+
goto yy25;
|
|
460
|
+
|
|
461
|
+
case '\'':
|
|
462
|
+
marker = c;
|
|
463
|
+
goto yy27;
|
|
464
|
+
|
|
465
|
+
default:
|
|
466
|
+
goto yy22;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
yy25:
|
|
470
|
+
yych = *++c;
|
|
471
|
+
|
|
472
|
+
switch (yych) {
|
|
473
|
+
case 0x00:
|
|
474
|
+
goto yy22;
|
|
475
|
+
|
|
476
|
+
case '"':
|
|
477
|
+
goto yy29;
|
|
478
|
+
|
|
479
|
+
default:
|
|
480
|
+
goto yy25;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
yy27:
|
|
484
|
+
yych = *++c;
|
|
485
|
+
|
|
486
|
+
switch (yych) {
|
|
487
|
+
case 0x00:
|
|
488
|
+
goto yy22;
|
|
489
|
+
|
|
490
|
+
case '\'':
|
|
491
|
+
goto yy29;
|
|
492
|
+
|
|
493
|
+
default:
|
|
494
|
+
goto yy27;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
yy29:
|
|
498
|
+
++c;
|
|
499
|
+
c = marker;
|
|
500
|
+
{
|
|
501
|
+
return (size_t)( c - start );
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
/// scan value
|
|
509
|
+
size_t xml_scan_value(const char * c) {
|
|
510
|
+
const char * marker = NULL;
|
|
511
|
+
const char * start = c;
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
{
|
|
515
|
+
unsigned char yych;
|
|
516
|
+
yych = *c;
|
|
517
|
+
|
|
518
|
+
switch (yych) {
|
|
519
|
+
case '"':
|
|
520
|
+
goto yy35;
|
|
521
|
+
|
|
522
|
+
case '\'':
|
|
523
|
+
goto yy36;
|
|
524
|
+
|
|
525
|
+
default:
|
|
526
|
+
goto yy33;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
yy33:
|
|
530
|
+
++c;
|
|
531
|
+
yy34: {
|
|
532
|
+
return 0;
|
|
533
|
+
}
|
|
534
|
+
yy35:
|
|
535
|
+
yych = *(marker = ++c);
|
|
536
|
+
|
|
537
|
+
if (yych <= 0x00) {
|
|
538
|
+
goto yy34;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
goto yy38;
|
|
542
|
+
yy36:
|
|
543
|
+
yych = *(marker = ++c);
|
|
544
|
+
|
|
545
|
+
if (yych <= 0x00) {
|
|
546
|
+
goto yy34;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
goto yy43;
|
|
550
|
+
yy37:
|
|
551
|
+
yych = *++c;
|
|
552
|
+
yy38:
|
|
553
|
+
|
|
554
|
+
switch (yych) {
|
|
555
|
+
case 0x00:
|
|
556
|
+
goto yy39;
|
|
557
|
+
|
|
558
|
+
case '"':
|
|
559
|
+
goto yy40;
|
|
560
|
+
|
|
561
|
+
default:
|
|
562
|
+
goto yy37;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
yy39:
|
|
566
|
+
c = marker;
|
|
567
|
+
goto yy34;
|
|
568
|
+
yy40:
|
|
569
|
+
++c;
|
|
570
|
+
{
|
|
571
|
+
return (size_t)( c - start );
|
|
572
|
+
}
|
|
573
|
+
yy42:
|
|
574
|
+
yych = *++c;
|
|
575
|
+
yy43:
|
|
576
|
+
|
|
577
|
+
switch (yych) {
|
|
578
|
+
case 0x00:
|
|
579
|
+
goto yy39;
|
|
580
|
+
|
|
581
|
+
case '\'':
|
|
582
|
+
goto yy40;
|
|
583
|
+
|
|
584
|
+
default:
|
|
585
|
+
goto yy42;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
/// Does the string include encoded newline?
|
|
593
|
+
size_t xml_scan_encoded_newline(const char * c, size_t len) {
|
|
594
|
+
const char * marker = NULL;
|
|
595
|
+
const char * start = c;
|
|
596
|
+
|
|
597
|
+
scan:
|
|
598
|
+
|
|
599
|
+
if ((*c == '\0') || ((c - start) > len)) {
|
|
600
|
+
// Not found
|
|
601
|
+
return -1;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
|
|
605
|
+
{
|
|
606
|
+
unsigned char yych;
|
|
607
|
+
yych = *c;
|
|
608
|
+
|
|
609
|
+
switch (yych) {
|
|
610
|
+
case '&':
|
|
611
|
+
goto yy48;
|
|
612
|
+
|
|
613
|
+
default:
|
|
614
|
+
goto yy46;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
yy46:
|
|
618
|
+
++c;
|
|
619
|
+
yy47: {
|
|
620
|
+
goto scan;
|
|
621
|
+
}
|
|
622
|
+
yy48:
|
|
623
|
+
yych = *(marker = ++c);
|
|
624
|
+
|
|
625
|
+
switch (yych) {
|
|
626
|
+
case '#':
|
|
627
|
+
goto yy49;
|
|
628
|
+
|
|
629
|
+
default:
|
|
630
|
+
goto yy47;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
yy49:
|
|
634
|
+
yych = *++c;
|
|
635
|
+
|
|
636
|
+
switch (yych) {
|
|
637
|
+
case '1':
|
|
638
|
+
goto yy51;
|
|
639
|
+
|
|
640
|
+
default:
|
|
641
|
+
goto yy50;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
yy50:
|
|
645
|
+
c = marker;
|
|
646
|
+
goto yy47;
|
|
647
|
+
yy51:
|
|
648
|
+
yych = *++c;
|
|
649
|
+
|
|
650
|
+
switch (yych) {
|
|
651
|
+
case '0':
|
|
652
|
+
case '3':
|
|
653
|
+
goto yy52;
|
|
654
|
+
|
|
655
|
+
default:
|
|
656
|
+
goto yy50;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
yy52:
|
|
660
|
+
yych = *++c;
|
|
661
|
+
|
|
662
|
+
switch (yych) {
|
|
663
|
+
case ';':
|
|
664
|
+
goto yy53;
|
|
665
|
+
|
|
666
|
+
default:
|
|
667
|
+
goto yy50;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
yy53:
|
|
671
|
+
++c;
|
|
672
|
+
{
|
|
673
|
+
return (size_t)(c - start);
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
|
|
680
|
+
/// Decode XML encoded text and print to DString
|
|
681
|
+
void print_xml_as_text(DString * out, const char * source, size_t start, size_t len) {
|
|
682
|
+
const char * s_start = &source[start];
|
|
683
|
+
const char * s_stop = &source[start + len];
|
|
684
|
+
|
|
685
|
+
char * c = (char *) s_start;
|
|
686
|
+
|
|
687
|
+
while (c < s_stop) {
|
|
688
|
+
switch (*c) {
|
|
689
|
+
case '&':
|
|
690
|
+
switch (*++c) {
|
|
691
|
+
case '#':
|
|
692
|
+
if (strncmp(c, "#10;", 4) == 0) {
|
|
693
|
+
print_char('\n');
|
|
694
|
+
c += 4;
|
|
695
|
+
continue;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
if (strncmp(c, "#9;", 3) == 0) {
|
|
699
|
+
print_char('\t');
|
|
700
|
+
c += 3;
|
|
701
|
+
continue;
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
if (strncmp(c, "#13;", 4) == 0) {
|
|
705
|
+
print_char('\r');
|
|
706
|
+
c += 4;
|
|
707
|
+
continue;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
break;
|
|
711
|
+
|
|
712
|
+
case 'a':
|
|
713
|
+
if (strncmp(c, "amp;", 4) == 0) {
|
|
714
|
+
print_char('&');
|
|
715
|
+
c += 4;
|
|
716
|
+
continue;
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
if (strncmp(c, "apos;", 5) == 0) {
|
|
720
|
+
print_char('\'');
|
|
721
|
+
c += 5;
|
|
722
|
+
continue;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
break;
|
|
726
|
+
|
|
727
|
+
case 'l':
|
|
728
|
+
if (strncmp(c, "lt;", 3) == 0) {
|
|
729
|
+
print_char('<');
|
|
730
|
+
c += 3;
|
|
731
|
+
continue;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
break;
|
|
735
|
+
|
|
736
|
+
case 'g':
|
|
737
|
+
if (strncmp(c, "gt;", 3) == 0) {
|
|
738
|
+
print_char('>');
|
|
739
|
+
c += 3;
|
|
740
|
+
continue;
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
break;
|
|
744
|
+
|
|
745
|
+
case 'q':
|
|
746
|
+
if (strncmp(c, "quot;", 5) == 0) {
|
|
747
|
+
print_char('"');
|
|
748
|
+
c += 5;
|
|
749
|
+
continue;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
break;
|
|
753
|
+
|
|
754
|
+
default:
|
|
755
|
+
break;
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
print_char('&');
|
|
759
|
+
continue;
|
|
760
|
+
break;
|
|
761
|
+
|
|
762
|
+
default:
|
|
763
|
+
print_char(*c);
|
|
764
|
+
break;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
c++;
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
|
|
772
|
+
/// Parse XML text for attribute and value
|
|
773
|
+
size_t xml_extract_attribute(const char * source, size_t start, char ** attr, char ** value) {
|
|
774
|
+
size_t cursor = start;
|
|
775
|
+
size_t len = 0;
|
|
776
|
+
|
|
777
|
+
if (*attr) {
|
|
778
|
+
free(*attr);
|
|
779
|
+
*attr = NULL;
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
if (*value) {
|
|
783
|
+
free(*value);
|
|
784
|
+
*value = NULL;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
// Skip leading whitespace
|
|
788
|
+
cursor += xml_scan_wsnl(&source[start]);
|
|
789
|
+
|
|
790
|
+
len = xml_scan_attribute_name(&source[cursor]);
|
|
791
|
+
|
|
792
|
+
if (len) {
|
|
793
|
+
// Copy attribute name
|
|
794
|
+
*attr = my_strndup(&source[cursor], len);
|
|
795
|
+
|
|
796
|
+
cursor += len;
|
|
797
|
+
|
|
798
|
+
// Value?
|
|
799
|
+
cursor += xml_scan_until_value(&source[cursor]);
|
|
800
|
+
len = xml_scan_value(&source[cursor]);
|
|
801
|
+
|
|
802
|
+
if (len) {
|
|
803
|
+
*value = my_strndup(&source[cursor + 1], len - 2);
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
cursor += len;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
|
|
810
|
+
return cursor - start;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
|
|
814
|
+
/// Extract attribute with specified name
|
|
815
|
+
char * xml_extract_named_attribute(const char * source, size_t start, const char * name) {
|
|
816
|
+
char * lower_name = my_strndup(name, strlen(name));
|
|
817
|
+
char * result = NULL;
|
|
818
|
+
|
|
819
|
+
// Use lower case for easy comparison
|
|
820
|
+
for (int i = 0; lower_name[i]; i++) {
|
|
821
|
+
lower_name[i] = tolower(lower_name[i]);
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
char * attr = NULL, * value = NULL, * lower_attr = NULL;
|
|
825
|
+
|
|
826
|
+
do {
|
|
827
|
+
start += xml_extract_attribute(source, start, &attr, &value);
|
|
828
|
+
|
|
829
|
+
if (attr) {
|
|
830
|
+
lower_attr = my_strndup(attr, strlen(attr));
|
|
831
|
+
|
|
832
|
+
// Use lower case for easy comparison
|
|
833
|
+
for (int i = 0; lower_name[i]; i++) {
|
|
834
|
+
lower_attr[i] = tolower(lower_attr[i]);
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
if (strcmp(lower_name, lower_attr) == 0) {
|
|
838
|
+
// Match
|
|
839
|
+
result = value;
|
|
840
|
+
value = NULL;
|
|
841
|
+
free(lower_attr);
|
|
842
|
+
goto finish;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
free(lower_attr);
|
|
846
|
+
}
|
|
847
|
+
} while (attr);
|
|
848
|
+
|
|
849
|
+
finish:
|
|
850
|
+
free(attr);
|
|
851
|
+
free(value);
|
|
852
|
+
free(lower_name);
|
|
853
|
+
|
|
854
|
+
return result;
|
|
855
|
+
}
|