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