]>
Commit | Line | Data |
---|---|---|
5e9f2524 VS |
1 | /* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd |
2 | See the file COPYING for copying permission. | |
3 | */ | |
4 | ||
11a3e7b6 VZ |
5 | #include <stddef.h> |
6 | ||
5e9f2524 VS |
7 | #ifdef COMPILED_FROM_DSP |
8 | #include "winconfig.h" | |
8ce8835c WS |
9 | #elif defined(OS2_32) |
10 | #include "os2config.h" | |
b8af111f WS |
11 | #elif defined(__MSDOS__) |
12 | #include "dosconfig.h" | |
5e9f2524 VS |
13 | #elif defined(MACOS_CLASSIC) |
14 | #include "macconfig.h" | |
11a3e7b6 VZ |
15 | #elif defined(__amigaos__) |
16 | #include "amigaconfig.h" | |
17 | #elif defined(__WATCOMC__) | |
18 | #include "watcomconfig.h" | |
5e9f2524 | 19 | #else |
11a3e7b6 VZ |
20 | #ifdef HAVE_EXPAT_CONFIG_H |
21 | #include <expat_config.h> | |
22 | #endif | |
5e9f2524 VS |
23 | #endif /* ndef COMPILED_FROM_DSP */ |
24 | ||
11a3e7b6 | 25 | #include "expat_external.h" |
5e9f2524 VS |
26 | #include "internal.h" |
27 | #include "xmlrole.h" | |
28 | #include "ascii.h" | |
29 | ||
30 | /* Doesn't check: | |
31 | ||
32 | that ,| are not mixed in a model group | |
33 | content of literals | |
34 | ||
35 | */ | |
36 | ||
37 | static const char KW_ANY[] = { | |
38 | ASCII_A, ASCII_N, ASCII_Y, '\0' }; | |
39 | static const char KW_ATTLIST[] = { | |
40 | ASCII_A, ASCII_T, ASCII_T, ASCII_L, ASCII_I, ASCII_S, ASCII_T, '\0' }; | |
41 | static const char KW_CDATA[] = { | |
42 | ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' }; | |
43 | static const char KW_DOCTYPE[] = { | |
44 | ASCII_D, ASCII_O, ASCII_C, ASCII_T, ASCII_Y, ASCII_P, ASCII_E, '\0' }; | |
45 | static const char KW_ELEMENT[] = { | |
46 | ASCII_E, ASCII_L, ASCII_E, ASCII_M, ASCII_E, ASCII_N, ASCII_T, '\0' }; | |
47 | static const char KW_EMPTY[] = { | |
48 | ASCII_E, ASCII_M, ASCII_P, ASCII_T, ASCII_Y, '\0' }; | |
49 | static const char KW_ENTITIES[] = { | |
50 | ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, ASCII_I, ASCII_E, ASCII_S, | |
51 | '\0' }; | |
52 | static const char KW_ENTITY[] = { | |
53 | ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, ASCII_Y, '\0' }; | |
54 | static const char KW_FIXED[] = { | |
55 | ASCII_F, ASCII_I, ASCII_X, ASCII_E, ASCII_D, '\0' }; | |
56 | static const char KW_ID[] = { | |
57 | ASCII_I, ASCII_D, '\0' }; | |
58 | static const char KW_IDREF[] = { | |
59 | ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, '\0' }; | |
60 | static const char KW_IDREFS[] = { | |
61 | ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, ASCII_S, '\0' }; | |
11a3e7b6 | 62 | #ifdef XML_DTD |
5e9f2524 VS |
63 | static const char KW_IGNORE[] = { |
64 | ASCII_I, ASCII_G, ASCII_N, ASCII_O, ASCII_R, ASCII_E, '\0' }; | |
11a3e7b6 | 65 | #endif |
5e9f2524 VS |
66 | static const char KW_IMPLIED[] = { |
67 | ASCII_I, ASCII_M, ASCII_P, ASCII_L, ASCII_I, ASCII_E, ASCII_D, '\0' }; | |
11a3e7b6 | 68 | #ifdef XML_DTD |
5e9f2524 VS |
69 | static const char KW_INCLUDE[] = { |
70 | ASCII_I, ASCII_N, ASCII_C, ASCII_L, ASCII_U, ASCII_D, ASCII_E, '\0' }; | |
11a3e7b6 | 71 | #endif |
5e9f2524 VS |
72 | static const char KW_NDATA[] = { |
73 | ASCII_N, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' }; | |
74 | static const char KW_NMTOKEN[] = { | |
75 | ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, ASCII_E, ASCII_N, '\0' }; | |
76 | static const char KW_NMTOKENS[] = { | |
77 | ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, ASCII_E, ASCII_N, ASCII_S, | |
78 | '\0' }; | |
79 | static const char KW_NOTATION[] = | |
80 | { ASCII_N, ASCII_O, ASCII_T, ASCII_A, ASCII_T, ASCII_I, ASCII_O, ASCII_N, | |
81 | '\0' }; | |
82 | static const char KW_PCDATA[] = { | |
83 | ASCII_P, ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' }; | |
84 | static const char KW_PUBLIC[] = { | |
85 | ASCII_P, ASCII_U, ASCII_B, ASCII_L, ASCII_I, ASCII_C, '\0' }; | |
86 | static const char KW_REQUIRED[] = { | |
87 | ASCII_R, ASCII_E, ASCII_Q, ASCII_U, ASCII_I, ASCII_R, ASCII_E, ASCII_D, | |
88 | '\0' }; | |
89 | static const char KW_SYSTEM[] = { | |
90 | ASCII_S, ASCII_Y, ASCII_S, ASCII_T, ASCII_E, ASCII_M, '\0' }; | |
91 | ||
92 | #ifndef MIN_BYTES_PER_CHAR | |
93 | #define MIN_BYTES_PER_CHAR(enc) ((enc)->minBytesPerChar) | |
94 | #endif | |
95 | ||
96 | #ifdef XML_DTD | |
97 | #define setTopLevel(state) \ | |
98 | ((state)->handler = ((state)->documentEntity \ | |
99 | ? internalSubset \ | |
100 | : externalSubset1)) | |
101 | #else /* not XML_DTD */ | |
102 | #define setTopLevel(state) ((state)->handler = internalSubset) | |
103 | #endif /* not XML_DTD */ | |
104 | ||
105 | typedef int PTRCALL PROLOG_HANDLER(PROLOG_STATE *state, | |
106 | int tok, | |
107 | const char *ptr, | |
108 | const char *end, | |
109 | const ENCODING *enc); | |
110 | ||
111 | static PROLOG_HANDLER | |
112 | prolog0, prolog1, prolog2, | |
113 | doctype0, doctype1, doctype2, doctype3, doctype4, doctype5, | |
114 | internalSubset, | |
115 | entity0, entity1, entity2, entity3, entity4, entity5, entity6, | |
116 | entity7, entity8, entity9, entity10, | |
117 | notation0, notation1, notation2, notation3, notation4, | |
118 | attlist0, attlist1, attlist2, attlist3, attlist4, attlist5, attlist6, | |
119 | attlist7, attlist8, attlist9, | |
120 | element0, element1, element2, element3, element4, element5, element6, | |
121 | element7, | |
122 | #ifdef XML_DTD | |
123 | externalSubset0, externalSubset1, | |
124 | condSect0, condSect1, condSect2, | |
125 | #endif /* XML_DTD */ | |
126 | declClose, | |
127 | error; | |
128 | ||
129 | static int FASTCALL common(PROLOG_STATE *state, int tok); | |
130 | ||
131 | static int PTRCALL | |
132 | prolog0(PROLOG_STATE *state, | |
133 | int tok, | |
134 | const char *ptr, | |
135 | const char *end, | |
136 | const ENCODING *enc) | |
137 | { | |
138 | switch (tok) { | |
139 | case XML_TOK_PROLOG_S: | |
140 | state->handler = prolog1; | |
141 | return XML_ROLE_NONE; | |
142 | case XML_TOK_XML_DECL: | |
143 | state->handler = prolog1; | |
144 | return XML_ROLE_XML_DECL; | |
145 | case XML_TOK_PI: | |
146 | state->handler = prolog1; | |
147 | return XML_ROLE_PI; | |
148 | case XML_TOK_COMMENT: | |
149 | state->handler = prolog1; | |
150 | return XML_ROLE_COMMENT; | |
151 | case XML_TOK_BOM: | |
152 | return XML_ROLE_NONE; | |
153 | case XML_TOK_DECL_OPEN: | |
154 | if (!XmlNameMatchesAscii(enc, | |
155 | ptr + 2 * MIN_BYTES_PER_CHAR(enc), | |
156 | end, | |
157 | KW_DOCTYPE)) | |
158 | break; | |
159 | state->handler = doctype0; | |
160 | return XML_ROLE_DOCTYPE_NONE; | |
161 | case XML_TOK_INSTANCE_START: | |
162 | state->handler = error; | |
163 | return XML_ROLE_INSTANCE_START; | |
164 | } | |
165 | return common(state, tok); | |
166 | } | |
167 | ||
168 | static int PTRCALL | |
169 | prolog1(PROLOG_STATE *state, | |
170 | int tok, | |
171 | const char *ptr, | |
172 | const char *end, | |
173 | const ENCODING *enc) | |
174 | { | |
175 | switch (tok) { | |
176 | case XML_TOK_PROLOG_S: | |
177 | return XML_ROLE_NONE; | |
178 | case XML_TOK_PI: | |
179 | return XML_ROLE_PI; | |
180 | case XML_TOK_COMMENT: | |
181 | return XML_ROLE_COMMENT; | |
182 | case XML_TOK_BOM: | |
183 | return XML_ROLE_NONE; | |
184 | case XML_TOK_DECL_OPEN: | |
185 | if (!XmlNameMatchesAscii(enc, | |
186 | ptr + 2 * MIN_BYTES_PER_CHAR(enc), | |
187 | end, | |
188 | KW_DOCTYPE)) | |
189 | break; | |
190 | state->handler = doctype0; | |
191 | return XML_ROLE_DOCTYPE_NONE; | |
192 | case XML_TOK_INSTANCE_START: | |
193 | state->handler = error; | |
194 | return XML_ROLE_INSTANCE_START; | |
195 | } | |
196 | return common(state, tok); | |
197 | } | |
198 | ||
199 | static int PTRCALL | |
200 | prolog2(PROLOG_STATE *state, | |
201 | int tok, | |
202 | const char *ptr, | |
203 | const char *end, | |
204 | const ENCODING *enc) | |
205 | { | |
206 | switch (tok) { | |
207 | case XML_TOK_PROLOG_S: | |
208 | return XML_ROLE_NONE; | |
209 | case XML_TOK_PI: | |
210 | return XML_ROLE_PI; | |
211 | case XML_TOK_COMMENT: | |
212 | return XML_ROLE_COMMENT; | |
213 | case XML_TOK_INSTANCE_START: | |
214 | state->handler = error; | |
215 | return XML_ROLE_INSTANCE_START; | |
216 | } | |
217 | return common(state, tok); | |
218 | } | |
219 | ||
220 | static int PTRCALL | |
221 | doctype0(PROLOG_STATE *state, | |
222 | int tok, | |
223 | const char *ptr, | |
224 | const char *end, | |
225 | const ENCODING *enc) | |
226 | { | |
227 | switch (tok) { | |
228 | case XML_TOK_PROLOG_S: | |
229 | return XML_ROLE_DOCTYPE_NONE; | |
230 | case XML_TOK_NAME: | |
231 | case XML_TOK_PREFIXED_NAME: | |
232 | state->handler = doctype1; | |
233 | return XML_ROLE_DOCTYPE_NAME; | |
234 | } | |
235 | return common(state, tok); | |
236 | } | |
237 | ||
238 | static int PTRCALL | |
239 | doctype1(PROLOG_STATE *state, | |
240 | int tok, | |
241 | const char *ptr, | |
242 | const char *end, | |
243 | const ENCODING *enc) | |
244 | { | |
245 | switch (tok) { | |
246 | case XML_TOK_PROLOG_S: | |
247 | return XML_ROLE_DOCTYPE_NONE; | |
248 | case XML_TOK_OPEN_BRACKET: | |
249 | state->handler = internalSubset; | |
250 | return XML_ROLE_DOCTYPE_INTERNAL_SUBSET; | |
251 | case XML_TOK_DECL_CLOSE: | |
252 | state->handler = prolog2; | |
253 | return XML_ROLE_DOCTYPE_CLOSE; | |
254 | case XML_TOK_NAME: | |
255 | if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) { | |
256 | state->handler = doctype3; | |
257 | return XML_ROLE_DOCTYPE_NONE; | |
258 | } | |
259 | if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) { | |
260 | state->handler = doctype2; | |
261 | return XML_ROLE_DOCTYPE_NONE; | |
262 | } | |
263 | break; | |
264 | } | |
265 | return common(state, tok); | |
266 | } | |
267 | ||
268 | static int PTRCALL | |
269 | doctype2(PROLOG_STATE *state, | |
270 | int tok, | |
271 | const char *ptr, | |
272 | const char *end, | |
273 | const ENCODING *enc) | |
274 | { | |
275 | switch (tok) { | |
276 | case XML_TOK_PROLOG_S: | |
277 | return XML_ROLE_DOCTYPE_NONE; | |
278 | case XML_TOK_LITERAL: | |
279 | state->handler = doctype3; | |
280 | return XML_ROLE_DOCTYPE_PUBLIC_ID; | |
281 | } | |
282 | return common(state, tok); | |
283 | } | |
284 | ||
285 | static int PTRCALL | |
286 | doctype3(PROLOG_STATE *state, | |
287 | int tok, | |
288 | const char *ptr, | |
289 | const char *end, | |
290 | const ENCODING *enc) | |
291 | { | |
292 | switch (tok) { | |
293 | case XML_TOK_PROLOG_S: | |
294 | return XML_ROLE_DOCTYPE_NONE; | |
295 | case XML_TOK_LITERAL: | |
296 | state->handler = doctype4; | |
297 | return XML_ROLE_DOCTYPE_SYSTEM_ID; | |
298 | } | |
299 | return common(state, tok); | |
300 | } | |
301 | ||
302 | static int PTRCALL | |
303 | doctype4(PROLOG_STATE *state, | |
304 | int tok, | |
305 | const char *ptr, | |
306 | const char *end, | |
307 | const ENCODING *enc) | |
308 | { | |
309 | switch (tok) { | |
310 | case XML_TOK_PROLOG_S: | |
311 | return XML_ROLE_DOCTYPE_NONE; | |
312 | case XML_TOK_OPEN_BRACKET: | |
313 | state->handler = internalSubset; | |
314 | return XML_ROLE_DOCTYPE_INTERNAL_SUBSET; | |
315 | case XML_TOK_DECL_CLOSE: | |
316 | state->handler = prolog2; | |
317 | return XML_ROLE_DOCTYPE_CLOSE; | |
318 | } | |
319 | return common(state, tok); | |
320 | } | |
321 | ||
322 | static int PTRCALL | |
323 | doctype5(PROLOG_STATE *state, | |
324 | int tok, | |
325 | const char *ptr, | |
326 | const char *end, | |
327 | const ENCODING *enc) | |
328 | { | |
329 | switch (tok) { | |
330 | case XML_TOK_PROLOG_S: | |
331 | return XML_ROLE_DOCTYPE_NONE; | |
332 | case XML_TOK_DECL_CLOSE: | |
333 | state->handler = prolog2; | |
334 | return XML_ROLE_DOCTYPE_CLOSE; | |
335 | } | |
336 | return common(state, tok); | |
337 | } | |
338 | ||
339 | static int PTRCALL | |
340 | internalSubset(PROLOG_STATE *state, | |
341 | int tok, | |
342 | const char *ptr, | |
343 | const char *end, | |
344 | const ENCODING *enc) | |
345 | { | |
346 | switch (tok) { | |
347 | case XML_TOK_PROLOG_S: | |
348 | return XML_ROLE_NONE; | |
349 | case XML_TOK_DECL_OPEN: | |
350 | if (XmlNameMatchesAscii(enc, | |
351 | ptr + 2 * MIN_BYTES_PER_CHAR(enc), | |
352 | end, | |
353 | KW_ENTITY)) { | |
354 | state->handler = entity0; | |
355 | return XML_ROLE_ENTITY_NONE; | |
356 | } | |
357 | if (XmlNameMatchesAscii(enc, | |
358 | ptr + 2 * MIN_BYTES_PER_CHAR(enc), | |
359 | end, | |
360 | KW_ATTLIST)) { | |
361 | state->handler = attlist0; | |
362 | return XML_ROLE_ATTLIST_NONE; | |
363 | } | |
364 | if (XmlNameMatchesAscii(enc, | |
365 | ptr + 2 * MIN_BYTES_PER_CHAR(enc), | |
366 | end, | |
367 | KW_ELEMENT)) { | |
368 | state->handler = element0; | |
369 | return XML_ROLE_ELEMENT_NONE; | |
370 | } | |
371 | if (XmlNameMatchesAscii(enc, | |
372 | ptr + 2 * MIN_BYTES_PER_CHAR(enc), | |
373 | end, | |
374 | KW_NOTATION)) { | |
375 | state->handler = notation0; | |
376 | return XML_ROLE_NOTATION_NONE; | |
377 | } | |
378 | break; | |
379 | case XML_TOK_PI: | |
380 | return XML_ROLE_PI; | |
381 | case XML_TOK_COMMENT: | |
382 | return XML_ROLE_COMMENT; | |
383 | case XML_TOK_PARAM_ENTITY_REF: | |
384 | return XML_ROLE_PARAM_ENTITY_REF; | |
385 | case XML_TOK_CLOSE_BRACKET: | |
386 | state->handler = doctype5; | |
387 | return XML_ROLE_DOCTYPE_NONE; | |
11a3e7b6 VZ |
388 | case XML_TOK_NONE: |
389 | return XML_ROLE_NONE; | |
5e9f2524 VS |
390 | } |
391 | return common(state, tok); | |
392 | } | |
393 | ||
394 | #ifdef XML_DTD | |
395 | ||
396 | static int PTRCALL | |
397 | externalSubset0(PROLOG_STATE *state, | |
398 | int tok, | |
399 | const char *ptr, | |
400 | const char *end, | |
401 | const ENCODING *enc) | |
402 | { | |
403 | state->handler = externalSubset1; | |
404 | if (tok == XML_TOK_XML_DECL) | |
405 | return XML_ROLE_TEXT_DECL; | |
406 | return externalSubset1(state, tok, ptr, end, enc); | |
407 | } | |
408 | ||
409 | static int PTRCALL | |
410 | externalSubset1(PROLOG_STATE *state, | |
411 | int tok, | |
412 | const char *ptr, | |
413 | const char *end, | |
414 | const ENCODING *enc) | |
415 | { | |
416 | switch (tok) { | |
417 | case XML_TOK_COND_SECT_OPEN: | |
418 | state->handler = condSect0; | |
419 | return XML_ROLE_NONE; | |
420 | case XML_TOK_COND_SECT_CLOSE: | |
421 | if (state->includeLevel == 0) | |
422 | break; | |
423 | state->includeLevel -= 1; | |
424 | return XML_ROLE_NONE; | |
425 | case XML_TOK_PROLOG_S: | |
426 | return XML_ROLE_NONE; | |
427 | case XML_TOK_CLOSE_BRACKET: | |
428 | break; | |
429 | case XML_TOK_NONE: | |
430 | if (state->includeLevel) | |
431 | break; | |
432 | return XML_ROLE_NONE; | |
433 | default: | |
434 | return internalSubset(state, tok, ptr, end, enc); | |
435 | } | |
436 | return common(state, tok); | |
437 | } | |
438 | ||
439 | #endif /* XML_DTD */ | |
440 | ||
441 | static int PTRCALL | |
442 | entity0(PROLOG_STATE *state, | |
443 | int tok, | |
444 | const char *ptr, | |
445 | const char *end, | |
446 | const ENCODING *enc) | |
447 | { | |
448 | switch (tok) { | |
449 | case XML_TOK_PROLOG_S: | |
450 | return XML_ROLE_ENTITY_NONE; | |
451 | case XML_TOK_PERCENT: | |
452 | state->handler = entity1; | |
453 | return XML_ROLE_ENTITY_NONE; | |
454 | case XML_TOK_NAME: | |
455 | state->handler = entity2; | |
456 | return XML_ROLE_GENERAL_ENTITY_NAME; | |
457 | } | |
458 | return common(state, tok); | |
459 | } | |
460 | ||
461 | static int PTRCALL | |
462 | entity1(PROLOG_STATE *state, | |
463 | int tok, | |
464 | const char *ptr, | |
465 | const char *end, | |
466 | const ENCODING *enc) | |
467 | { | |
468 | switch (tok) { | |
469 | case XML_TOK_PROLOG_S: | |
470 | return XML_ROLE_ENTITY_NONE; | |
471 | case XML_TOK_NAME: | |
472 | state->handler = entity7; | |
473 | return XML_ROLE_PARAM_ENTITY_NAME; | |
474 | } | |
475 | return common(state, tok); | |
476 | } | |
477 | ||
478 | static int PTRCALL | |
479 | entity2(PROLOG_STATE *state, | |
480 | int tok, | |
481 | const char *ptr, | |
482 | const char *end, | |
483 | const ENCODING *enc) | |
484 | { | |
485 | switch (tok) { | |
486 | case XML_TOK_PROLOG_S: | |
487 | return XML_ROLE_ENTITY_NONE; | |
488 | case XML_TOK_NAME: | |
489 | if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) { | |
490 | state->handler = entity4; | |
491 | return XML_ROLE_ENTITY_NONE; | |
492 | } | |
493 | if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) { | |
494 | state->handler = entity3; | |
495 | return XML_ROLE_ENTITY_NONE; | |
496 | } | |
497 | break; | |
498 | case XML_TOK_LITERAL: | |
499 | state->handler = declClose; | |
500 | state->role_none = XML_ROLE_ENTITY_NONE; | |
501 | return XML_ROLE_ENTITY_VALUE; | |
502 | } | |
503 | return common(state, tok); | |
504 | } | |
505 | ||
506 | static int PTRCALL | |
507 | entity3(PROLOG_STATE *state, | |
508 | int tok, | |
509 | const char *ptr, | |
510 | const char *end, | |
511 | const ENCODING *enc) | |
512 | { | |
513 | switch (tok) { | |
514 | case XML_TOK_PROLOG_S: | |
515 | return XML_ROLE_ENTITY_NONE; | |
516 | case XML_TOK_LITERAL: | |
517 | state->handler = entity4; | |
518 | return XML_ROLE_ENTITY_PUBLIC_ID; | |
519 | } | |
520 | return common(state, tok); | |
521 | } | |
522 | ||
523 | static int PTRCALL | |
524 | entity4(PROLOG_STATE *state, | |
525 | int tok, | |
526 | const char *ptr, | |
527 | const char *end, | |
528 | const ENCODING *enc) | |
529 | { | |
530 | switch (tok) { | |
531 | case XML_TOK_PROLOG_S: | |
532 | return XML_ROLE_ENTITY_NONE; | |
533 | case XML_TOK_LITERAL: | |
534 | state->handler = entity5; | |
535 | return XML_ROLE_ENTITY_SYSTEM_ID; | |
536 | } | |
537 | return common(state, tok); | |
538 | } | |
539 | ||
540 | static int PTRCALL | |
541 | entity5(PROLOG_STATE *state, | |
542 | int tok, | |
543 | const char *ptr, | |
544 | const char *end, | |
545 | const ENCODING *enc) | |
546 | { | |
547 | switch (tok) { | |
548 | case XML_TOK_PROLOG_S: | |
549 | return XML_ROLE_ENTITY_NONE; | |
550 | case XML_TOK_DECL_CLOSE: | |
551 | setTopLevel(state); | |
552 | return XML_ROLE_ENTITY_COMPLETE; | |
553 | case XML_TOK_NAME: | |
554 | if (XmlNameMatchesAscii(enc, ptr, end, KW_NDATA)) { | |
555 | state->handler = entity6; | |
556 | return XML_ROLE_ENTITY_NONE; | |
557 | } | |
558 | break; | |
559 | } | |
560 | return common(state, tok); | |
561 | } | |
562 | ||
563 | static int PTRCALL | |
564 | entity6(PROLOG_STATE *state, | |
565 | int tok, | |
566 | const char *ptr, | |
567 | const char *end, | |
568 | const ENCODING *enc) | |
569 | { | |
570 | switch (tok) { | |
571 | case XML_TOK_PROLOG_S: | |
572 | return XML_ROLE_ENTITY_NONE; | |
573 | case XML_TOK_NAME: | |
574 | state->handler = declClose; | |
575 | state->role_none = XML_ROLE_ENTITY_NONE; | |
576 | return XML_ROLE_ENTITY_NOTATION_NAME; | |
577 | } | |
578 | return common(state, tok); | |
579 | } | |
580 | ||
581 | static int PTRCALL | |
582 | entity7(PROLOG_STATE *state, | |
583 | int tok, | |
584 | const char *ptr, | |
585 | const char *end, | |
586 | const ENCODING *enc) | |
587 | { | |
588 | switch (tok) { | |
589 | case XML_TOK_PROLOG_S: | |
590 | return XML_ROLE_ENTITY_NONE; | |
591 | case XML_TOK_NAME: | |
592 | if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) { | |
593 | state->handler = entity9; | |
594 | return XML_ROLE_ENTITY_NONE; | |
595 | } | |
596 | if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) { | |
597 | state->handler = entity8; | |
598 | return XML_ROLE_ENTITY_NONE; | |
599 | } | |
600 | break; | |
601 | case XML_TOK_LITERAL: | |
602 | state->handler = declClose; | |
603 | state->role_none = XML_ROLE_ENTITY_NONE; | |
604 | return XML_ROLE_ENTITY_VALUE; | |
605 | } | |
606 | return common(state, tok); | |
607 | } | |
608 | ||
609 | static int PTRCALL | |
610 | entity8(PROLOG_STATE *state, | |
611 | int tok, | |
612 | const char *ptr, | |
613 | const char *end, | |
614 | const ENCODING *enc) | |
615 | { | |
616 | switch (tok) { | |
617 | case XML_TOK_PROLOG_S: | |
618 | return XML_ROLE_ENTITY_NONE; | |
619 | case XML_TOK_LITERAL: | |
620 | state->handler = entity9; | |
621 | return XML_ROLE_ENTITY_PUBLIC_ID; | |
622 | } | |
623 | return common(state, tok); | |
624 | } | |
625 | ||
626 | static int PTRCALL | |
627 | entity9(PROLOG_STATE *state, | |
628 | int tok, | |
629 | const char *ptr, | |
630 | const char *end, | |
631 | const ENCODING *enc) | |
632 | { | |
633 | switch (tok) { | |
634 | case XML_TOK_PROLOG_S: | |
635 | return XML_ROLE_ENTITY_NONE; | |
636 | case XML_TOK_LITERAL: | |
637 | state->handler = entity10; | |
638 | return XML_ROLE_ENTITY_SYSTEM_ID; | |
639 | } | |
640 | return common(state, tok); | |
641 | } | |
642 | ||
643 | static int PTRCALL | |
644 | entity10(PROLOG_STATE *state, | |
645 | int tok, | |
646 | const char *ptr, | |
647 | const char *end, | |
648 | const ENCODING *enc) | |
649 | { | |
650 | switch (tok) { | |
651 | case XML_TOK_PROLOG_S: | |
652 | return XML_ROLE_ENTITY_NONE; | |
653 | case XML_TOK_DECL_CLOSE: | |
654 | setTopLevel(state); | |
655 | return XML_ROLE_ENTITY_COMPLETE; | |
656 | } | |
657 | return common(state, tok); | |
658 | } | |
659 | ||
660 | static int PTRCALL | |
661 | notation0(PROLOG_STATE *state, | |
662 | int tok, | |
663 | const char *ptr, | |
664 | const char *end, | |
665 | const ENCODING *enc) | |
666 | { | |
667 | switch (tok) { | |
668 | case XML_TOK_PROLOG_S: | |
669 | return XML_ROLE_NOTATION_NONE; | |
670 | case XML_TOK_NAME: | |
671 | state->handler = notation1; | |
672 | return XML_ROLE_NOTATION_NAME; | |
673 | } | |
674 | return common(state, tok); | |
675 | } | |
676 | ||
677 | static int PTRCALL | |
678 | notation1(PROLOG_STATE *state, | |
679 | int tok, | |
680 | const char *ptr, | |
681 | const char *end, | |
682 | const ENCODING *enc) | |
683 | { | |
684 | switch (tok) { | |
685 | case XML_TOK_PROLOG_S: | |
686 | return XML_ROLE_NOTATION_NONE; | |
687 | case XML_TOK_NAME: | |
688 | if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) { | |
689 | state->handler = notation3; | |
690 | return XML_ROLE_NOTATION_NONE; | |
691 | } | |
692 | if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) { | |
693 | state->handler = notation2; | |
694 | return XML_ROLE_NOTATION_NONE; | |
695 | } | |
696 | break; | |
697 | } | |
698 | return common(state, tok); | |
699 | } | |
700 | ||
701 | static int PTRCALL | |
702 | notation2(PROLOG_STATE *state, | |
703 | int tok, | |
704 | const char *ptr, | |
705 | const char *end, | |
706 | const ENCODING *enc) | |
707 | { | |
708 | switch (tok) { | |
709 | case XML_TOK_PROLOG_S: | |
710 | return XML_ROLE_NOTATION_NONE; | |
711 | case XML_TOK_LITERAL: | |
712 | state->handler = notation4; | |
713 | return XML_ROLE_NOTATION_PUBLIC_ID; | |
714 | } | |
715 | return common(state, tok); | |
716 | } | |
717 | ||
718 | static int PTRCALL | |
719 | notation3(PROLOG_STATE *state, | |
720 | int tok, | |
721 | const char *ptr, | |
722 | const char *end, | |
723 | const ENCODING *enc) | |
724 | { | |
725 | switch (tok) { | |
726 | case XML_TOK_PROLOG_S: | |
727 | return XML_ROLE_NOTATION_NONE; | |
728 | case XML_TOK_LITERAL: | |
729 | state->handler = declClose; | |
730 | state->role_none = XML_ROLE_NOTATION_NONE; | |
731 | return XML_ROLE_NOTATION_SYSTEM_ID; | |
732 | } | |
733 | return common(state, tok); | |
734 | } | |
735 | ||
736 | static int PTRCALL | |
737 | notation4(PROLOG_STATE *state, | |
738 | int tok, | |
739 | const char *ptr, | |
740 | const char *end, | |
741 | const ENCODING *enc) | |
742 | { | |
743 | switch (tok) { | |
744 | case XML_TOK_PROLOG_S: | |
745 | return XML_ROLE_NOTATION_NONE; | |
746 | case XML_TOK_LITERAL: | |
747 | state->handler = declClose; | |
748 | state->role_none = XML_ROLE_NOTATION_NONE; | |
749 | return XML_ROLE_NOTATION_SYSTEM_ID; | |
750 | case XML_TOK_DECL_CLOSE: | |
751 | setTopLevel(state); | |
752 | return XML_ROLE_NOTATION_NO_SYSTEM_ID; | |
753 | } | |
754 | return common(state, tok); | |
755 | } | |
756 | ||
757 | static int PTRCALL | |
758 | attlist0(PROLOG_STATE *state, | |
759 | int tok, | |
760 | const char *ptr, | |
761 | const char *end, | |
762 | const ENCODING *enc) | |
763 | { | |
764 | switch (tok) { | |
765 | case XML_TOK_PROLOG_S: | |
766 | return XML_ROLE_ATTLIST_NONE; | |
767 | case XML_TOK_NAME: | |
768 | case XML_TOK_PREFIXED_NAME: | |
769 | state->handler = attlist1; | |
770 | return XML_ROLE_ATTLIST_ELEMENT_NAME; | |
771 | } | |
772 | return common(state, tok); | |
773 | } | |
774 | ||
775 | static int PTRCALL | |
776 | attlist1(PROLOG_STATE *state, | |
777 | int tok, | |
778 | const char *ptr, | |
779 | const char *end, | |
780 | const ENCODING *enc) | |
781 | { | |
782 | switch (tok) { | |
783 | case XML_TOK_PROLOG_S: | |
784 | return XML_ROLE_ATTLIST_NONE; | |
785 | case XML_TOK_DECL_CLOSE: | |
786 | setTopLevel(state); | |
787 | return XML_ROLE_ATTLIST_NONE; | |
788 | case XML_TOK_NAME: | |
789 | case XML_TOK_PREFIXED_NAME: | |
790 | state->handler = attlist2; | |
791 | return XML_ROLE_ATTRIBUTE_NAME; | |
792 | } | |
793 | return common(state, tok); | |
794 | } | |
795 | ||
796 | static int PTRCALL | |
797 | attlist2(PROLOG_STATE *state, | |
798 | int tok, | |
799 | const char *ptr, | |
800 | const char *end, | |
801 | const ENCODING *enc) | |
802 | { | |
803 | switch (tok) { | |
804 | case XML_TOK_PROLOG_S: | |
805 | return XML_ROLE_ATTLIST_NONE; | |
806 | case XML_TOK_NAME: | |
807 | { | |
11a3e7b6 | 808 | static const char * const types[] = { |
5e9f2524 VS |
809 | KW_CDATA, |
810 | KW_ID, | |
811 | KW_IDREF, | |
812 | KW_IDREFS, | |
813 | KW_ENTITY, | |
814 | KW_ENTITIES, | |
815 | KW_NMTOKEN, | |
816 | KW_NMTOKENS, | |
817 | }; | |
818 | int i; | |
819 | for (i = 0; i < (int)(sizeof(types)/sizeof(types[0])); i++) | |
820 | if (XmlNameMatchesAscii(enc, ptr, end, types[i])) { | |
821 | state->handler = attlist8; | |
822 | return XML_ROLE_ATTRIBUTE_TYPE_CDATA + i; | |
823 | } | |
824 | } | |
825 | if (XmlNameMatchesAscii(enc, ptr, end, KW_NOTATION)) { | |
826 | state->handler = attlist5; | |
827 | return XML_ROLE_ATTLIST_NONE; | |
828 | } | |
829 | break; | |
830 | case XML_TOK_OPEN_PAREN: | |
831 | state->handler = attlist3; | |
832 | return XML_ROLE_ATTLIST_NONE; | |
833 | } | |
834 | return common(state, tok); | |
835 | } | |
836 | ||
837 | static int PTRCALL | |
838 | attlist3(PROLOG_STATE *state, | |
839 | int tok, | |
840 | const char *ptr, | |
841 | const char *end, | |
842 | const ENCODING *enc) | |
843 | { | |
844 | switch (tok) { | |
845 | case XML_TOK_PROLOG_S: | |
846 | return XML_ROLE_ATTLIST_NONE; | |
847 | case XML_TOK_NMTOKEN: | |
848 | case XML_TOK_NAME: | |
849 | case XML_TOK_PREFIXED_NAME: | |
850 | state->handler = attlist4; | |
851 | return XML_ROLE_ATTRIBUTE_ENUM_VALUE; | |
852 | } | |
853 | return common(state, tok); | |
854 | } | |
855 | ||
856 | static int PTRCALL | |
857 | attlist4(PROLOG_STATE *state, | |
858 | int tok, | |
859 | const char *ptr, | |
860 | const char *end, | |
861 | const ENCODING *enc) | |
862 | { | |
863 | switch (tok) { | |
864 | case XML_TOK_PROLOG_S: | |
865 | return XML_ROLE_ATTLIST_NONE; | |
866 | case XML_TOK_CLOSE_PAREN: | |
867 | state->handler = attlist8; | |
868 | return XML_ROLE_ATTLIST_NONE; | |
869 | case XML_TOK_OR: | |
870 | state->handler = attlist3; | |
871 | return XML_ROLE_ATTLIST_NONE; | |
872 | } | |
873 | return common(state, tok); | |
874 | } | |
875 | ||
876 | static int PTRCALL | |
877 | attlist5(PROLOG_STATE *state, | |
878 | int tok, | |
879 | const char *ptr, | |
880 | const char *end, | |
881 | const ENCODING *enc) | |
882 | { | |
883 | switch (tok) { | |
884 | case XML_TOK_PROLOG_S: | |
885 | return XML_ROLE_ATTLIST_NONE; | |
886 | case XML_TOK_OPEN_PAREN: | |
887 | state->handler = attlist6; | |
888 | return XML_ROLE_ATTLIST_NONE; | |
889 | } | |
890 | return common(state, tok); | |
891 | } | |
892 | ||
893 | static int PTRCALL | |
894 | attlist6(PROLOG_STATE *state, | |
895 | int tok, | |
896 | const char *ptr, | |
897 | const char *end, | |
898 | const ENCODING *enc) | |
899 | { | |
900 | switch (tok) { | |
901 | case XML_TOK_PROLOG_S: | |
902 | return XML_ROLE_ATTLIST_NONE; | |
903 | case XML_TOK_NAME: | |
904 | state->handler = attlist7; | |
905 | return XML_ROLE_ATTRIBUTE_NOTATION_VALUE; | |
906 | } | |
907 | return common(state, tok); | |
908 | } | |
909 | ||
910 | static int PTRCALL | |
911 | attlist7(PROLOG_STATE *state, | |
912 | int tok, | |
913 | const char *ptr, | |
914 | const char *end, | |
915 | const ENCODING *enc) | |
916 | { | |
917 | switch (tok) { | |
918 | case XML_TOK_PROLOG_S: | |
919 | return XML_ROLE_ATTLIST_NONE; | |
920 | case XML_TOK_CLOSE_PAREN: | |
921 | state->handler = attlist8; | |
922 | return XML_ROLE_ATTLIST_NONE; | |
923 | case XML_TOK_OR: | |
924 | state->handler = attlist6; | |
925 | return XML_ROLE_ATTLIST_NONE; | |
926 | } | |
927 | return common(state, tok); | |
928 | } | |
929 | ||
930 | /* default value */ | |
931 | static int PTRCALL | |
932 | attlist8(PROLOG_STATE *state, | |
933 | int tok, | |
934 | const char *ptr, | |
935 | const char *end, | |
936 | const ENCODING *enc) | |
937 | { | |
938 | switch (tok) { | |
939 | case XML_TOK_PROLOG_S: | |
940 | return XML_ROLE_ATTLIST_NONE; | |
941 | case XML_TOK_POUND_NAME: | |
942 | if (XmlNameMatchesAscii(enc, | |
943 | ptr + MIN_BYTES_PER_CHAR(enc), | |
944 | end, | |
945 | KW_IMPLIED)) { | |
946 | state->handler = attlist1; | |
947 | return XML_ROLE_IMPLIED_ATTRIBUTE_VALUE; | |
948 | } | |
949 | if (XmlNameMatchesAscii(enc, | |
950 | ptr + MIN_BYTES_PER_CHAR(enc), | |
951 | end, | |
952 | KW_REQUIRED)) { | |
953 | state->handler = attlist1; | |
954 | return XML_ROLE_REQUIRED_ATTRIBUTE_VALUE; | |
955 | } | |
956 | if (XmlNameMatchesAscii(enc, | |
957 | ptr + MIN_BYTES_PER_CHAR(enc), | |
958 | end, | |
959 | KW_FIXED)) { | |
960 | state->handler = attlist9; | |
961 | return XML_ROLE_ATTLIST_NONE; | |
962 | } | |
963 | break; | |
964 | case XML_TOK_LITERAL: | |
965 | state->handler = attlist1; | |
966 | return XML_ROLE_DEFAULT_ATTRIBUTE_VALUE; | |
967 | } | |
968 | return common(state, tok); | |
969 | } | |
970 | ||
971 | static int PTRCALL | |
972 | attlist9(PROLOG_STATE *state, | |
973 | int tok, | |
974 | const char *ptr, | |
975 | const char *end, | |
976 | const ENCODING *enc) | |
977 | { | |
978 | switch (tok) { | |
979 | case XML_TOK_PROLOG_S: | |
980 | return XML_ROLE_ATTLIST_NONE; | |
981 | case XML_TOK_LITERAL: | |
982 | state->handler = attlist1; | |
983 | return XML_ROLE_FIXED_ATTRIBUTE_VALUE; | |
984 | } | |
985 | return common(state, tok); | |
986 | } | |
987 | ||
988 | static int PTRCALL | |
989 | element0(PROLOG_STATE *state, | |
990 | int tok, | |
991 | const char *ptr, | |
992 | const char *end, | |
993 | const ENCODING *enc) | |
994 | { | |
995 | switch (tok) { | |
996 | case XML_TOK_PROLOG_S: | |
997 | return XML_ROLE_ELEMENT_NONE; | |
998 | case XML_TOK_NAME: | |
999 | case XML_TOK_PREFIXED_NAME: | |
1000 | state->handler = element1; | |
1001 | return XML_ROLE_ELEMENT_NAME; | |
1002 | } | |
1003 | return common(state, tok); | |
1004 | } | |
1005 | ||
1006 | static int PTRCALL | |
1007 | element1(PROLOG_STATE *state, | |
1008 | int tok, | |
1009 | const char *ptr, | |
1010 | const char *end, | |
1011 | const ENCODING *enc) | |
1012 | { | |
1013 | switch (tok) { | |
1014 | case XML_TOK_PROLOG_S: | |
1015 | return XML_ROLE_ELEMENT_NONE; | |
1016 | case XML_TOK_NAME: | |
1017 | if (XmlNameMatchesAscii(enc, ptr, end, KW_EMPTY)) { | |
1018 | state->handler = declClose; | |
1019 | state->role_none = XML_ROLE_ELEMENT_NONE; | |
1020 | return XML_ROLE_CONTENT_EMPTY; | |
1021 | } | |
1022 | if (XmlNameMatchesAscii(enc, ptr, end, KW_ANY)) { | |
1023 | state->handler = declClose; | |
1024 | state->role_none = XML_ROLE_ELEMENT_NONE; | |
1025 | return XML_ROLE_CONTENT_ANY; | |
1026 | } | |
1027 | break; | |
1028 | case XML_TOK_OPEN_PAREN: | |
1029 | state->handler = element2; | |
1030 | state->level = 1; | |
1031 | return XML_ROLE_GROUP_OPEN; | |
1032 | } | |
1033 | return common(state, tok); | |
1034 | } | |
1035 | ||
1036 | static int PTRCALL | |
1037 | element2(PROLOG_STATE *state, | |
1038 | int tok, | |
1039 | const char *ptr, | |
1040 | const char *end, | |
1041 | const ENCODING *enc) | |
1042 | { | |
1043 | switch (tok) { | |
1044 | case XML_TOK_PROLOG_S: | |
1045 | return XML_ROLE_ELEMENT_NONE; | |
1046 | case XML_TOK_POUND_NAME: | |
1047 | if (XmlNameMatchesAscii(enc, | |
1048 | ptr + MIN_BYTES_PER_CHAR(enc), | |
1049 | end, | |
1050 | KW_PCDATA)) { | |
1051 | state->handler = element3; | |
1052 | return XML_ROLE_CONTENT_PCDATA; | |
1053 | } | |
1054 | break; | |
1055 | case XML_TOK_OPEN_PAREN: | |
1056 | state->level = 2; | |
1057 | state->handler = element6; | |
1058 | return XML_ROLE_GROUP_OPEN; | |
1059 | case XML_TOK_NAME: | |
1060 | case XML_TOK_PREFIXED_NAME: | |
1061 | state->handler = element7; | |
1062 | return XML_ROLE_CONTENT_ELEMENT; | |
1063 | case XML_TOK_NAME_QUESTION: | |
1064 | state->handler = element7; | |
1065 | return XML_ROLE_CONTENT_ELEMENT_OPT; | |
1066 | case XML_TOK_NAME_ASTERISK: | |
1067 | state->handler = element7; | |
1068 | return XML_ROLE_CONTENT_ELEMENT_REP; | |
1069 | case XML_TOK_NAME_PLUS: | |
1070 | state->handler = element7; | |
1071 | return XML_ROLE_CONTENT_ELEMENT_PLUS; | |
1072 | } | |
1073 | return common(state, tok); | |
1074 | } | |
1075 | ||
1076 | static int PTRCALL | |
1077 | element3(PROLOG_STATE *state, | |
1078 | int tok, | |
1079 | const char *ptr, | |
1080 | const char *end, | |
1081 | const ENCODING *enc) | |
1082 | { | |
1083 | switch (tok) { | |
1084 | case XML_TOK_PROLOG_S: | |
1085 | return XML_ROLE_ELEMENT_NONE; | |
1086 | case XML_TOK_CLOSE_PAREN: | |
1087 | state->handler = declClose; | |
1088 | state->role_none = XML_ROLE_ELEMENT_NONE; | |
1089 | return XML_ROLE_GROUP_CLOSE; | |
1090 | case XML_TOK_CLOSE_PAREN_ASTERISK: | |
1091 | state->handler = declClose; | |
1092 | state->role_none = XML_ROLE_ELEMENT_NONE; | |
1093 | return XML_ROLE_GROUP_CLOSE_REP; | |
1094 | case XML_TOK_OR: | |
1095 | state->handler = element4; | |
1096 | return XML_ROLE_ELEMENT_NONE; | |
1097 | } | |
1098 | return common(state, tok); | |
1099 | } | |
1100 | ||
1101 | static int PTRCALL | |
1102 | element4(PROLOG_STATE *state, | |
1103 | int tok, | |
1104 | const char *ptr, | |
1105 | const char *end, | |
1106 | const ENCODING *enc) | |
1107 | { | |
1108 | switch (tok) { | |
1109 | case XML_TOK_PROLOG_S: | |
1110 | return XML_ROLE_ELEMENT_NONE; | |
1111 | case XML_TOK_NAME: | |
1112 | case XML_TOK_PREFIXED_NAME: | |
1113 | state->handler = element5; | |
1114 | return XML_ROLE_CONTENT_ELEMENT; | |
1115 | } | |
1116 | return common(state, tok); | |
1117 | } | |
1118 | ||
1119 | static int PTRCALL | |
1120 | element5(PROLOG_STATE *state, | |
1121 | int tok, | |
1122 | const char *ptr, | |
1123 | const char *end, | |
1124 | const ENCODING *enc) | |
1125 | { | |
1126 | switch (tok) { | |
1127 | case XML_TOK_PROLOG_S: | |
1128 | return XML_ROLE_ELEMENT_NONE; | |
1129 | case XML_TOK_CLOSE_PAREN_ASTERISK: | |
1130 | state->handler = declClose; | |
1131 | state->role_none = XML_ROLE_ELEMENT_NONE; | |
1132 | return XML_ROLE_GROUP_CLOSE_REP; | |
1133 | case XML_TOK_OR: | |
1134 | state->handler = element4; | |
1135 | return XML_ROLE_ELEMENT_NONE; | |
1136 | } | |
1137 | return common(state, tok); | |
1138 | } | |
1139 | ||
1140 | static int PTRCALL | |
1141 | element6(PROLOG_STATE *state, | |
1142 | int tok, | |
1143 | const char *ptr, | |
1144 | const char *end, | |
1145 | const ENCODING *enc) | |
1146 | { | |
1147 | switch (tok) { | |
1148 | case XML_TOK_PROLOG_S: | |
1149 | return XML_ROLE_ELEMENT_NONE; | |
1150 | case XML_TOK_OPEN_PAREN: | |
1151 | state->level += 1; | |
1152 | return XML_ROLE_GROUP_OPEN; | |
1153 | case XML_TOK_NAME: | |
1154 | case XML_TOK_PREFIXED_NAME: | |
1155 | state->handler = element7; | |
1156 | return XML_ROLE_CONTENT_ELEMENT; | |
1157 | case XML_TOK_NAME_QUESTION: | |
1158 | state->handler = element7; | |
1159 | return XML_ROLE_CONTENT_ELEMENT_OPT; | |
1160 | case XML_TOK_NAME_ASTERISK: | |
1161 | state->handler = element7; | |
1162 | return XML_ROLE_CONTENT_ELEMENT_REP; | |
1163 | case XML_TOK_NAME_PLUS: | |
1164 | state->handler = element7; | |
1165 | return XML_ROLE_CONTENT_ELEMENT_PLUS; | |
1166 | } | |
1167 | return common(state, tok); | |
1168 | } | |
1169 | ||
1170 | static int PTRCALL | |
1171 | element7(PROLOG_STATE *state, | |
1172 | int tok, | |
1173 | const char *ptr, | |
1174 | const char *end, | |
1175 | const ENCODING *enc) | |
1176 | { | |
1177 | switch (tok) { | |
1178 | case XML_TOK_PROLOG_S: | |
1179 | return XML_ROLE_ELEMENT_NONE; | |
1180 | case XML_TOK_CLOSE_PAREN: | |
1181 | state->level -= 1; | |
1182 | if (state->level == 0) { | |
1183 | state->handler = declClose; | |
1184 | state->role_none = XML_ROLE_ELEMENT_NONE; | |
1185 | } | |
1186 | return XML_ROLE_GROUP_CLOSE; | |
1187 | case XML_TOK_CLOSE_PAREN_ASTERISK: | |
1188 | state->level -= 1; | |
1189 | if (state->level == 0) { | |
1190 | state->handler = declClose; | |
1191 | state->role_none = XML_ROLE_ELEMENT_NONE; | |
1192 | } | |
1193 | return XML_ROLE_GROUP_CLOSE_REP; | |
1194 | case XML_TOK_CLOSE_PAREN_QUESTION: | |
1195 | state->level -= 1; | |
1196 | if (state->level == 0) { | |
1197 | state->handler = declClose; | |
1198 | state->role_none = XML_ROLE_ELEMENT_NONE; | |
1199 | } | |
1200 | return XML_ROLE_GROUP_CLOSE_OPT; | |
1201 | case XML_TOK_CLOSE_PAREN_PLUS: | |
1202 | state->level -= 1; | |
1203 | if (state->level == 0) { | |
1204 | state->handler = declClose; | |
1205 | state->role_none = XML_ROLE_ELEMENT_NONE; | |
1206 | } | |
1207 | return XML_ROLE_GROUP_CLOSE_PLUS; | |
1208 | case XML_TOK_COMMA: | |
1209 | state->handler = element6; | |
1210 | return XML_ROLE_GROUP_SEQUENCE; | |
1211 | case XML_TOK_OR: | |
1212 | state->handler = element6; | |
1213 | return XML_ROLE_GROUP_CHOICE; | |
1214 | } | |
1215 | return common(state, tok); | |
1216 | } | |
1217 | ||
1218 | #ifdef XML_DTD | |
1219 | ||
1220 | static int PTRCALL | |
1221 | condSect0(PROLOG_STATE *state, | |
1222 | int tok, | |
1223 | const char *ptr, | |
1224 | const char *end, | |
1225 | const ENCODING *enc) | |
1226 | { | |
1227 | switch (tok) { | |
1228 | case XML_TOK_PROLOG_S: | |
1229 | return XML_ROLE_NONE; | |
1230 | case XML_TOK_NAME: | |
1231 | if (XmlNameMatchesAscii(enc, ptr, end, KW_INCLUDE)) { | |
1232 | state->handler = condSect1; | |
1233 | return XML_ROLE_NONE; | |
1234 | } | |
1235 | if (XmlNameMatchesAscii(enc, ptr, end, KW_IGNORE)) { | |
1236 | state->handler = condSect2; | |
1237 | return XML_ROLE_NONE; | |
1238 | } | |
1239 | break; | |
1240 | } | |
1241 | return common(state, tok); | |
1242 | } | |
1243 | ||
1244 | static int PTRCALL | |
1245 | condSect1(PROLOG_STATE *state, | |
1246 | int tok, | |
1247 | const char *ptr, | |
1248 | const char *end, | |
1249 | const ENCODING *enc) | |
1250 | { | |
1251 | switch (tok) { | |
1252 | case XML_TOK_PROLOG_S: | |
1253 | return XML_ROLE_NONE; | |
1254 | case XML_TOK_OPEN_BRACKET: | |
1255 | state->handler = externalSubset1; | |
1256 | state->includeLevel += 1; | |
1257 | return XML_ROLE_NONE; | |
1258 | } | |
1259 | return common(state, tok); | |
1260 | } | |
1261 | ||
1262 | static int PTRCALL | |
1263 | condSect2(PROLOG_STATE *state, | |
1264 | int tok, | |
1265 | const char *ptr, | |
1266 | const char *end, | |
1267 | const ENCODING *enc) | |
1268 | { | |
1269 | switch (tok) { | |
1270 | case XML_TOK_PROLOG_S: | |
1271 | return XML_ROLE_NONE; | |
1272 | case XML_TOK_OPEN_BRACKET: | |
1273 | state->handler = externalSubset1; | |
1274 | return XML_ROLE_IGNORE_SECT; | |
1275 | } | |
1276 | return common(state, tok); | |
1277 | } | |
1278 | ||
1279 | #endif /* XML_DTD */ | |
1280 | ||
1281 | static int PTRCALL | |
1282 | declClose(PROLOG_STATE *state, | |
1283 | int tok, | |
1284 | const char *ptr, | |
1285 | const char *end, | |
1286 | const ENCODING *enc) | |
1287 | { | |
1288 | switch (tok) { | |
1289 | case XML_TOK_PROLOG_S: | |
1290 | return state->role_none; | |
1291 | case XML_TOK_DECL_CLOSE: | |
1292 | setTopLevel(state); | |
1293 | return state->role_none; | |
1294 | } | |
1295 | return common(state, tok); | |
1296 | } | |
1297 | ||
1298 | static int PTRCALL | |
1299 | error(PROLOG_STATE *state, | |
1300 | int tok, | |
1301 | const char *ptr, | |
1302 | const char *end, | |
1303 | const ENCODING *enc) | |
1304 | { | |
1305 | return XML_ROLE_NONE; | |
1306 | } | |
1307 | ||
1308 | static int FASTCALL | |
1309 | common(PROLOG_STATE *state, int tok) | |
1310 | { | |
1311 | #ifdef XML_DTD | |
1312 | if (!state->documentEntity && tok == XML_TOK_PARAM_ENTITY_REF) | |
1313 | return XML_ROLE_INNER_PARAM_ENTITY_REF; | |
1314 | #endif | |
1315 | state->handler = error; | |
1316 | return XML_ROLE_ERROR; | |
1317 | } | |
1318 | ||
1319 | void | |
1320 | XmlPrologStateInit(PROLOG_STATE *state) | |
1321 | { | |
1322 | state->handler = prolog0; | |
1323 | #ifdef XML_DTD | |
1324 | state->documentEntity = 1; | |
1325 | state->includeLevel = 0; | |
1326 | state->inEntityValue = 0; | |
1327 | #endif /* XML_DTD */ | |
1328 | } | |
1329 | ||
1330 | #ifdef XML_DTD | |
1331 | ||
1332 | void | |
1333 | XmlPrologStateInitExternalEntity(PROLOG_STATE *state) | |
1334 | { | |
1335 | state->handler = externalSubset0; | |
1336 | state->documentEntity = 0; | |
1337 | state->includeLevel = 0; | |
1338 | } | |
1339 | ||
1340 | #endif /* XML_DTD */ |