ENH: set expected failure for tests
[cmake.git] / Utilities / cmexpat / xmlrole.c
blob0d30eab26e1eef82d36bd0c2c2ed8dcb195a9e60
1 /*
2 Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
3 See the file COPYING for copying permission.
4 */
6 static char RCSId[]
7 = "$Header: /cvsroot/CMake/CMake/Utilities/cmexpat/xmlrole.c,v 1.1 2004-06-25 18:04:12 andy Exp $";
8 const char* cm_expat_GetXMLRole_RCSId()
10 /* Avoid warning about unused static without removing RCSId from original. */
11 return RCSId;
14 #include <cmexpat/expatConfig.h>
16 #include "xmlrole.h"
17 #include "ascii.h"
19 /* Doesn't check:
21 that ,| are not mixed in a model group
22 content of literals
26 static const char KW_ANY[] = { ASCII_A, ASCII_N, ASCII_Y, '\0' };
27 static const char KW_ATTLIST[] = { ASCII_A, ASCII_T, ASCII_T, ASCII_L, ASCII_I, ASCII_S, ASCII_T, '\0' };
28 static const char KW_CDATA[] = { ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' };
29 static const char KW_DOCTYPE[] = { ASCII_D, ASCII_O, ASCII_C, ASCII_T, ASCII_Y, ASCII_P, ASCII_E, '\0' };
30 static const char KW_ELEMENT[] = { ASCII_E, ASCII_L, ASCII_E, ASCII_M, ASCII_E, ASCII_N, ASCII_T, '\0' };
31 static const char KW_EMPTY[] = { ASCII_E, ASCII_M, ASCII_P, ASCII_T, ASCII_Y, '\0' };
32 static const char KW_ENTITIES[] = { ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, ASCII_I, ASCII_E, ASCII_S, '\0' };
33 static const char KW_ENTITY[] = { ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, ASCII_Y, '\0' };
34 static const char KW_FIXED[] = { ASCII_F, ASCII_I, ASCII_X, ASCII_E, ASCII_D, '\0' };
35 static const char KW_ID[] = { ASCII_I, ASCII_D, '\0' };
36 static const char KW_IDREF[] = { ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, '\0' };
37 static const char KW_IDREFS[] = { ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, ASCII_S, '\0' };
38 static const char KW_IGNORE[] = { ASCII_I, ASCII_G, ASCII_N, ASCII_O, ASCII_R, ASCII_E, '\0' };
39 static const char KW_IMPLIED[] = { ASCII_I, ASCII_M, ASCII_P, ASCII_L, ASCII_I, ASCII_E, ASCII_D, '\0' };
40 static const char KW_INCLUDE[] = { ASCII_I, ASCII_N, ASCII_C, ASCII_L, ASCII_U, ASCII_D, ASCII_E, '\0' };
41 static const char KW_NDATA[] = { ASCII_N, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' };
42 static const char KW_NMTOKEN[] = { ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, ASCII_E, ASCII_N, '\0' };
43 static const char KW_NMTOKENS[] = { ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, ASCII_E, ASCII_N, ASCII_S, '\0' };
44 static const char KW_NOTATION[] = { ASCII_N, ASCII_O, ASCII_T, ASCII_A, ASCII_T, ASCII_I, ASCII_O, ASCII_N, '\0' };
45 static const char KW_PCDATA[] = { ASCII_P, ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' };
46 static const char KW_PUBLIC[] = { ASCII_P, ASCII_U, ASCII_B, ASCII_L, ASCII_I, ASCII_C, '\0' };
47 static const char KW_REQUIRED[] = { ASCII_R, ASCII_E, ASCII_Q, ASCII_U, ASCII_I, ASCII_R, ASCII_E, ASCII_D, '\0' };
48 static const char KW_SYSTEM[] = { ASCII_S, ASCII_Y, ASCII_S, ASCII_T, ASCII_E, ASCII_M, '\0' };
50 #ifndef MIN_BYTES_PER_CHAR
51 #define MIN_BYTES_PER_CHAR(enc) ((enc)->minBytesPerChar)
52 #endif
54 #ifdef XML_DTD
55 #define setTopLevel(state) \
56 ((state)->handler = ((state)->documentEntity \
57 ? internalSubset \
58 : externalSubset1))
59 #else /* not XML_DTD */
60 #define setTopLevel(state) ((state)->handler = internalSubset)
61 #endif /* not XML_DTD */
63 typedef int PROLOG_HANDLER(PROLOG_STATE *state,
64 int tok,
65 const char *ptr,
66 const char *end,
67 const ENCODING *enc);
69 static PROLOG_HANDLER
70 prolog0, prolog1, prolog2,
71 doctype0, doctype1, doctype2, doctype3, doctype4, doctype5,
72 internalSubset,
73 entity0, entity1, entity2, entity3, entity4, entity5, entity6,
74 entity7, entity8, entity9,
75 notation0, notation1, notation2, notation3, notation4,
76 attlist0, attlist1, attlist2, attlist3, attlist4, attlist5, attlist6,
77 attlist7, attlist8, attlist9,
78 element0, element1, element2, element3, element4, element5, element6,
79 element7,
80 #ifdef XML_DTD
81 externalSubset0, externalSubset1,
82 condSect0, condSect1, condSect2,
83 #endif /* XML_DTD */
84 declClose,
85 error;
87 static
88 int common(PROLOG_STATE *state, int tok);
90 static
91 int prolog0(PROLOG_STATE *state,
92 int tok,
93 const char *ptr,
94 const char *end,
95 const ENCODING *enc)
97 switch (tok) {
98 case XML_TOK_PROLOG_S:
99 state->handler = prolog1;
100 return XML_ROLE_NONE;
101 case XML_TOK_XML_DECL:
102 state->handler = prolog1;
103 return XML_ROLE_XML_DECL;
104 case XML_TOK_PI:
105 state->handler = prolog1;
106 return XML_ROLE_NONE;
107 case XML_TOK_COMMENT:
108 state->handler = prolog1;
109 case XML_TOK_BOM:
110 return XML_ROLE_NONE;
111 case XML_TOK_DECL_OPEN:
112 if (!XmlNameMatchesAscii(enc,
113 ptr + 2 * MIN_BYTES_PER_CHAR(enc),
114 end,
115 KW_DOCTYPE))
116 break;
117 state->handler = doctype0;
118 return XML_ROLE_NONE;
119 case XML_TOK_INSTANCE_START:
120 state->handler = error;
121 return XML_ROLE_INSTANCE_START;
123 return common(state, tok);
126 static
127 int prolog1(PROLOG_STATE *state,
128 int tok,
129 const char *ptr,
130 const char *end,
131 const ENCODING *enc)
133 switch (tok) {
134 case XML_TOK_PROLOG_S:
135 return XML_ROLE_NONE;
136 case XML_TOK_PI:
137 case XML_TOK_COMMENT:
138 case XML_TOK_BOM:
139 return XML_ROLE_NONE;
140 case XML_TOK_DECL_OPEN:
141 if (!XmlNameMatchesAscii(enc,
142 ptr + 2 * MIN_BYTES_PER_CHAR(enc),
143 end,
144 KW_DOCTYPE))
145 break;
146 state->handler = doctype0;
147 return XML_ROLE_NONE;
148 case XML_TOK_INSTANCE_START:
149 state->handler = error;
150 return XML_ROLE_INSTANCE_START;
152 return common(state, tok);
155 static
156 int prolog2(PROLOG_STATE *state,
157 int tok,
158 const char *ptr,
159 const char *end,
160 const ENCODING *enc)
162 cmExpatUnused(ptr);
163 cmExpatUnused(end);
164 cmExpatUnused(enc);
165 switch (tok) {
166 case XML_TOK_PROLOG_S:
167 return XML_ROLE_NONE;
168 case XML_TOK_PI:
169 case XML_TOK_COMMENT:
170 return XML_ROLE_NONE;
171 case XML_TOK_INSTANCE_START:
172 state->handler = error;
173 return XML_ROLE_INSTANCE_START;
175 return common(state, tok);
178 static
179 int doctype0(PROLOG_STATE *state,
180 int tok,
181 const char *ptr,
182 const char *end,
183 const ENCODING *enc)
185 cmExpatUnused(ptr);
186 cmExpatUnused(end);
187 cmExpatUnused(enc);
188 switch (tok) {
189 case XML_TOK_PROLOG_S:
190 return XML_ROLE_NONE;
191 case XML_TOK_NAME:
192 case XML_TOK_PREFIXED_NAME:
193 state->handler = doctype1;
194 return XML_ROLE_DOCTYPE_NAME;
196 return common(state, tok);
199 static
200 int doctype1(PROLOG_STATE *state,
201 int tok,
202 const char *ptr,
203 const char *end,
204 const ENCODING *enc)
206 switch (tok) {
207 case XML_TOK_PROLOG_S:
208 return XML_ROLE_NONE;
209 case XML_TOK_OPEN_BRACKET:
210 state->handler = internalSubset;
211 return XML_ROLE_DOCTYPE_INTERNAL_SUBSET;
212 case XML_TOK_DECL_CLOSE:
213 state->handler = prolog2;
214 return XML_ROLE_DOCTYPE_CLOSE;
215 case XML_TOK_NAME:
216 if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) {
217 state->handler = doctype3;
218 return XML_ROLE_NONE;
220 if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) {
221 state->handler = doctype2;
222 return XML_ROLE_NONE;
224 break;
226 return common(state, tok);
229 static
230 int doctype2(PROLOG_STATE *state,
231 int tok,
232 const char *ptr,
233 const char *end,
234 const ENCODING *enc)
236 cmExpatUnused(ptr);
237 cmExpatUnused(end);
238 cmExpatUnused(enc);
239 switch (tok) {
240 case XML_TOK_PROLOG_S:
241 return XML_ROLE_NONE;
242 case XML_TOK_LITERAL:
243 state->handler = doctype3;
244 return XML_ROLE_DOCTYPE_PUBLIC_ID;
246 return common(state, tok);
249 static
250 int doctype3(PROLOG_STATE *state,
251 int tok,
252 const char *ptr,
253 const char *end,
254 const ENCODING *enc)
256 cmExpatUnused(ptr);
257 cmExpatUnused(end);
258 cmExpatUnused(enc);
259 switch (tok) {
260 case XML_TOK_PROLOG_S:
261 return XML_ROLE_NONE;
262 case XML_TOK_LITERAL:
263 state->handler = doctype4;
264 return XML_ROLE_DOCTYPE_SYSTEM_ID;
266 return common(state, tok);
269 static
270 int doctype4(PROLOG_STATE *state,
271 int tok,
272 const char *ptr,
273 const char *end,
274 const ENCODING *enc)
276 cmExpatUnused(ptr);
277 cmExpatUnused(end);
278 cmExpatUnused(enc);
279 switch (tok) {
280 case XML_TOK_PROLOG_S:
281 return XML_ROLE_NONE;
282 case XML_TOK_OPEN_BRACKET:
283 state->handler = internalSubset;
284 return XML_ROLE_DOCTYPE_INTERNAL_SUBSET;
285 case XML_TOK_DECL_CLOSE:
286 state->handler = prolog2;
287 return XML_ROLE_DOCTYPE_CLOSE;
289 return common(state, tok);
292 static
293 int doctype5(PROLOG_STATE *state,
294 int tok,
295 const char *ptr,
296 const char *end,
297 const ENCODING *enc)
299 cmExpatUnused(ptr);
300 cmExpatUnused(end);
301 cmExpatUnused(enc);
302 switch (tok) {
303 case XML_TOK_PROLOG_S:
304 return XML_ROLE_NONE;
305 case XML_TOK_DECL_CLOSE:
306 state->handler = prolog2;
307 return XML_ROLE_DOCTYPE_CLOSE;
309 return common(state, tok);
312 static
313 int internalSubset(PROLOG_STATE *state,
314 int tok,
315 const char *ptr,
316 const char *end,
317 const ENCODING *enc)
319 switch (tok) {
320 case XML_TOK_PROLOG_S:
321 return XML_ROLE_NONE;
322 case XML_TOK_DECL_OPEN:
323 if (XmlNameMatchesAscii(enc,
324 ptr + 2 * MIN_BYTES_PER_CHAR(enc),
325 end,
326 KW_ENTITY)) {
327 state->handler = entity0;
328 return XML_ROLE_NONE;
330 if (XmlNameMatchesAscii(enc,
331 ptr + 2 * MIN_BYTES_PER_CHAR(enc),
332 end,
333 KW_ATTLIST)) {
334 state->handler = attlist0;
335 return XML_ROLE_NONE;
337 if (XmlNameMatchesAscii(enc,
338 ptr + 2 * MIN_BYTES_PER_CHAR(enc),
339 end,
340 KW_ELEMENT)) {
341 state->handler = element0;
342 return XML_ROLE_NONE;
344 if (XmlNameMatchesAscii(enc,
345 ptr + 2 * MIN_BYTES_PER_CHAR(enc),
346 end,
347 KW_NOTATION)) {
348 state->handler = notation0;
349 return XML_ROLE_NONE;
351 break;
352 case XML_TOK_PI:
353 case XML_TOK_COMMENT:
354 return XML_ROLE_NONE;
355 case XML_TOK_PARAM_ENTITY_REF:
356 return XML_ROLE_PARAM_ENTITY_REF;
357 case XML_TOK_CLOSE_BRACKET:
358 state->handler = doctype5;
359 return XML_ROLE_NONE;
361 return common(state, tok);
364 #ifdef XML_DTD
366 static
367 int externalSubset0(PROLOG_STATE *state,
368 int tok,
369 const char *ptr,
370 const char *end,
371 const ENCODING *enc)
373 state->handler = externalSubset1;
374 if (tok == XML_TOK_XML_DECL)
375 return XML_ROLE_TEXT_DECL;
376 return externalSubset1(state, tok, ptr, end, enc);
379 static
380 int externalSubset1(PROLOG_STATE *state,
381 int tok,
382 const char *ptr,
383 const char *end,
384 const ENCODING *enc)
386 switch (tok) {
387 case XML_TOK_COND_SECT_OPEN:
388 state->handler = condSect0;
389 return XML_ROLE_NONE;
390 case XML_TOK_COND_SECT_CLOSE:
391 if (state->includeLevel == 0)
392 break;
393 state->includeLevel -= 1;
394 return XML_ROLE_NONE;
395 case XML_TOK_PROLOG_S:
396 return XML_ROLE_NONE;
397 case XML_TOK_CLOSE_BRACKET:
398 break;
399 case XML_TOK_NONE:
400 if (state->includeLevel)
401 break;
402 return XML_ROLE_NONE;
403 default:
404 return internalSubset(state, tok, ptr, end, enc);
406 return common(state, tok);
409 #endif /* XML_DTD */
411 static
412 int entity0(PROLOG_STATE *state,
413 int tok,
414 const char *ptr,
415 const char *end,
416 const ENCODING *enc)
418 cmExpatUnused(ptr);
419 cmExpatUnused(end);
420 cmExpatUnused(enc);
421 switch (tok) {
422 case XML_TOK_PROLOG_S:
423 return XML_ROLE_NONE;
424 case XML_TOK_PERCENT:
425 state->handler = entity1;
426 return XML_ROLE_NONE;
427 case XML_TOK_NAME:
428 state->handler = entity2;
429 return XML_ROLE_GENERAL_ENTITY_NAME;
431 return common(state, tok);
434 static
435 int entity1(PROLOG_STATE *state,
436 int tok,
437 const char *ptr,
438 const char *end,
439 const ENCODING *enc)
441 cmExpatUnused(ptr);
442 cmExpatUnused(end);
443 cmExpatUnused(enc);
444 switch (tok) {
445 case XML_TOK_PROLOG_S:
446 return XML_ROLE_NONE;
447 case XML_TOK_NAME:
448 state->handler = entity7;
449 return XML_ROLE_PARAM_ENTITY_NAME;
451 return common(state, tok);
454 static
455 int entity2(PROLOG_STATE *state,
456 int tok,
457 const char *ptr,
458 const char *end,
459 const ENCODING *enc)
461 switch (tok) {
462 case XML_TOK_PROLOG_S:
463 return XML_ROLE_NONE;
464 case XML_TOK_NAME:
465 if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) {
466 state->handler = entity4;
467 return XML_ROLE_NONE;
469 if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) {
470 state->handler = entity3;
471 return XML_ROLE_NONE;
473 break;
474 case XML_TOK_LITERAL:
475 state->handler = declClose;
476 return XML_ROLE_ENTITY_VALUE;
478 return common(state, tok);
481 static
482 int entity3(PROLOG_STATE *state,
483 int tok,
484 const char *ptr,
485 const char *end,
486 const ENCODING *enc)
488 cmExpatUnused(ptr);
489 cmExpatUnused(end);
490 cmExpatUnused(enc);
491 switch (tok) {
492 case XML_TOK_PROLOG_S:
493 return XML_ROLE_NONE;
494 case XML_TOK_LITERAL:
495 state->handler = entity4;
496 return XML_ROLE_ENTITY_PUBLIC_ID;
498 return common(state, tok);
502 static
503 int entity4(PROLOG_STATE *state,
504 int tok,
505 const char *ptr,
506 const char *end,
507 const ENCODING *enc)
509 cmExpatUnused(ptr);
510 cmExpatUnused(end);
511 cmExpatUnused(enc);
512 switch (tok) {
513 case XML_TOK_PROLOG_S:
514 return XML_ROLE_NONE;
515 case XML_TOK_LITERAL:
516 state->handler = entity5;
517 return XML_ROLE_ENTITY_SYSTEM_ID;
519 return common(state, tok);
522 static
523 int entity5(PROLOG_STATE *state,
524 int tok,
525 const char *ptr,
526 const char *end,
527 const ENCODING *enc)
529 switch (tok) {
530 case XML_TOK_PROLOG_S:
531 return XML_ROLE_NONE;
532 case XML_TOK_DECL_CLOSE:
533 setTopLevel(state);
534 return XML_ROLE_ENTITY_COMPLETE;
535 case XML_TOK_NAME:
536 if (XmlNameMatchesAscii(enc, ptr, end, KW_NDATA)) {
537 state->handler = entity6;
538 return XML_ROLE_NONE;
540 break;
542 return common(state, tok);
545 static
546 int entity6(PROLOG_STATE *state,
547 int tok,
548 const char *ptr,
549 const char *end,
550 const ENCODING *enc)
552 cmExpatUnused(ptr);
553 cmExpatUnused(end);
554 cmExpatUnused(enc);
555 switch (tok) {
556 case XML_TOK_PROLOG_S:
557 return XML_ROLE_NONE;
558 case XML_TOK_NAME:
559 state->handler = declClose;
560 return XML_ROLE_ENTITY_NOTATION_NAME;
562 return common(state, tok);
565 static
566 int entity7(PROLOG_STATE *state,
567 int tok,
568 const char *ptr,
569 const char *end,
570 const ENCODING *enc)
572 switch (tok) {
573 case XML_TOK_PROLOG_S:
574 return XML_ROLE_NONE;
575 case XML_TOK_NAME:
576 if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) {
577 state->handler = entity9;
578 return XML_ROLE_NONE;
580 if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) {
581 state->handler = entity8;
582 return XML_ROLE_NONE;
584 break;
585 case XML_TOK_LITERAL:
586 state->handler = declClose;
587 return XML_ROLE_ENTITY_VALUE;
589 return common(state, tok);
592 static
593 int entity8(PROLOG_STATE *state,
594 int tok,
595 const char *ptr,
596 const char *end,
597 const ENCODING *enc)
599 cmExpatUnused(ptr);
600 cmExpatUnused(end);
601 cmExpatUnused(enc);
602 switch (tok) {
603 case XML_TOK_PROLOG_S:
604 return XML_ROLE_NONE;
605 case XML_TOK_LITERAL:
606 state->handler = entity9;
607 return XML_ROLE_ENTITY_PUBLIC_ID;
609 return common(state, tok);
612 static
613 int entity9(PROLOG_STATE *state,
614 int tok,
615 const char *ptr,
616 const char *end,
617 const ENCODING *enc)
619 cmExpatUnused(ptr);
620 cmExpatUnused(end);
621 cmExpatUnused(enc);
622 switch (tok) {
623 case XML_TOK_PROLOG_S:
624 return XML_ROLE_NONE;
625 case XML_TOK_LITERAL:
626 state->handler = declClose;
627 return XML_ROLE_ENTITY_SYSTEM_ID;
629 return common(state, tok);
632 static
633 int notation0(PROLOG_STATE *state,
634 int tok,
635 const char *ptr,
636 const char *end,
637 const ENCODING *enc)
639 cmExpatUnused(ptr);
640 cmExpatUnused(end);
641 cmExpatUnused(enc);
642 switch (tok) {
643 case XML_TOK_PROLOG_S:
644 return XML_ROLE_NONE;
645 case XML_TOK_NAME:
646 state->handler = notation1;
647 return XML_ROLE_NOTATION_NAME;
649 return common(state, tok);
652 static
653 int notation1(PROLOG_STATE *state,
654 int tok,
655 const char *ptr,
656 const char *end,
657 const ENCODING *enc)
659 switch (tok) {
660 case XML_TOK_PROLOG_S:
661 return XML_ROLE_NONE;
662 case XML_TOK_NAME:
663 if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) {
664 state->handler = notation3;
665 return XML_ROLE_NONE;
667 if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) {
668 state->handler = notation2;
669 return XML_ROLE_NONE;
671 break;
673 return common(state, tok);
676 static
677 int notation2(PROLOG_STATE *state,
678 int tok,
679 const char *ptr,
680 const char *end,
681 const ENCODING *enc)
683 cmExpatUnused(ptr);
684 cmExpatUnused(end);
685 cmExpatUnused(enc);
686 switch (tok) {
687 case XML_TOK_PROLOG_S:
688 return XML_ROLE_NONE;
689 case XML_TOK_LITERAL:
690 state->handler = notation4;
691 return XML_ROLE_NOTATION_PUBLIC_ID;
693 return common(state, tok);
696 static
697 int notation3(PROLOG_STATE *state,
698 int tok,
699 const char *ptr,
700 const char *end,
701 const ENCODING *enc)
703 cmExpatUnused(ptr);
704 cmExpatUnused(end);
705 cmExpatUnused(enc);
706 switch (tok) {
707 case XML_TOK_PROLOG_S:
708 return XML_ROLE_NONE;
709 case XML_TOK_LITERAL:
710 state->handler = declClose;
711 return XML_ROLE_NOTATION_SYSTEM_ID;
713 return common(state, tok);
716 static
717 int notation4(PROLOG_STATE *state,
718 int tok,
719 const char *ptr,
720 const char *end,
721 const ENCODING *enc)
723 cmExpatUnused(ptr);
724 cmExpatUnused(end);
725 cmExpatUnused(enc);
726 switch (tok) {
727 case XML_TOK_PROLOG_S:
728 return XML_ROLE_NONE;
729 case XML_TOK_LITERAL:
730 state->handler = declClose;
731 return XML_ROLE_NOTATION_SYSTEM_ID;
732 case XML_TOK_DECL_CLOSE:
733 setTopLevel(state);
734 return XML_ROLE_NOTATION_NO_SYSTEM_ID;
736 return common(state, tok);
739 static
740 int attlist0(PROLOG_STATE *state,
741 int tok,
742 const char *ptr,
743 const char *end,
744 const ENCODING *enc)
746 cmExpatUnused(ptr);
747 cmExpatUnused(end);
748 cmExpatUnused(enc);
749 switch (tok) {
750 case XML_TOK_PROLOG_S:
751 return XML_ROLE_NONE;
752 case XML_TOK_NAME:
753 case XML_TOK_PREFIXED_NAME:
754 state->handler = attlist1;
755 return XML_ROLE_ATTLIST_ELEMENT_NAME;
757 return common(state, tok);
760 static
761 int attlist1(PROLOG_STATE *state,
762 int tok,
763 const char *ptr,
764 const char *end,
765 const ENCODING *enc)
767 cmExpatUnused(ptr);
768 cmExpatUnused(end);
769 cmExpatUnused(enc);
770 switch (tok) {
771 case XML_TOK_PROLOG_S:
772 return XML_ROLE_NONE;
773 case XML_TOK_DECL_CLOSE:
774 setTopLevel(state);
775 return XML_ROLE_NONE;
776 case XML_TOK_NAME:
777 case XML_TOK_PREFIXED_NAME:
778 state->handler = attlist2;
779 return XML_ROLE_ATTRIBUTE_NAME;
781 return common(state, tok);
784 static
785 int attlist2(PROLOG_STATE *state,
786 int tok,
787 const char *ptr,
788 const char *end,
789 const ENCODING *enc)
791 cmExpatUnused(ptr);
792 cmExpatUnused(end);
793 cmExpatUnused(enc);
794 switch (tok) {
795 case XML_TOK_PROLOG_S:
796 return XML_ROLE_NONE;
797 case XML_TOK_NAME:
799 static const char *types[] = {
800 KW_CDATA,
801 KW_ID,
802 KW_IDREF,
803 KW_IDREFS,
804 KW_ENTITY,
805 KW_ENTITIES,
806 KW_NMTOKEN,
807 KW_NMTOKENS,
809 int i;
810 for (i = 0; i < (int)(sizeof(types)/sizeof(types[0])); i++)
811 if (XmlNameMatchesAscii(enc, ptr, end, types[i])) {
812 state->handler = attlist8;
813 return XML_ROLE_ATTRIBUTE_TYPE_CDATA + i;
816 if (XmlNameMatchesAscii(enc, ptr, end, KW_NOTATION)) {
817 state->handler = attlist5;
818 return XML_ROLE_NONE;
820 break;
821 case XML_TOK_OPEN_PAREN:
822 state->handler = attlist3;
823 return XML_ROLE_NONE;
825 return common(state, tok);
828 static
829 int attlist3(PROLOG_STATE *state,
830 int tok,
831 const char *ptr,
832 const char *end,
833 const ENCODING *enc)
835 cmExpatUnused(ptr);
836 cmExpatUnused(end);
837 cmExpatUnused(enc);
838 switch (tok) {
839 case XML_TOK_PROLOG_S:
840 return XML_ROLE_NONE;
841 case XML_TOK_NMTOKEN:
842 case XML_TOK_NAME:
843 case XML_TOK_PREFIXED_NAME:
844 state->handler = attlist4;
845 return XML_ROLE_ATTRIBUTE_ENUM_VALUE;
847 return common(state, tok);
850 static
851 int attlist4(PROLOG_STATE *state,
852 int tok,
853 const char *ptr,
854 const char *end,
855 const ENCODING *enc)
857 cmExpatUnused(ptr);
858 cmExpatUnused(end);
859 cmExpatUnused(enc);
860 switch (tok) {
861 case XML_TOK_PROLOG_S:
862 return XML_ROLE_NONE;
863 case XML_TOK_CLOSE_PAREN:
864 state->handler = attlist8;
865 return XML_ROLE_NONE;
866 case XML_TOK_OR:
867 state->handler = attlist3;
868 return XML_ROLE_NONE;
870 return common(state, tok);
873 static
874 int attlist5(PROLOG_STATE *state,
875 int tok,
876 const char *ptr,
877 const char *end,
878 const ENCODING *enc)
880 cmExpatUnused(ptr);
881 cmExpatUnused(end);
882 cmExpatUnused(enc);
883 switch (tok) {
884 case XML_TOK_PROLOG_S:
885 return XML_ROLE_NONE;
886 case XML_TOK_OPEN_PAREN:
887 state->handler = attlist6;
888 return XML_ROLE_NONE;
890 return common(state, tok);
894 static
895 int attlist6(PROLOG_STATE *state,
896 int tok,
897 const char *ptr,
898 const char *end,
899 const ENCODING *enc)
901 cmExpatUnused(ptr);
902 cmExpatUnused(end);
903 cmExpatUnused(enc);
904 switch (tok) {
905 case XML_TOK_PROLOG_S:
906 return XML_ROLE_NONE;
907 case XML_TOK_NAME:
908 state->handler = attlist7;
909 return XML_ROLE_ATTRIBUTE_NOTATION_VALUE;
911 return common(state, tok);
914 static
915 int attlist7(PROLOG_STATE *state,
916 int tok,
917 const char *ptr,
918 const char *end,
919 const ENCODING *enc)
921 cmExpatUnused(ptr);
922 cmExpatUnused(end);
923 cmExpatUnused(enc);
924 switch (tok) {
925 case XML_TOK_PROLOG_S:
926 return XML_ROLE_NONE;
927 case XML_TOK_CLOSE_PAREN:
928 state->handler = attlist8;
929 return XML_ROLE_NONE;
930 case XML_TOK_OR:
931 state->handler = attlist6;
932 return XML_ROLE_NONE;
934 return common(state, tok);
937 /* default value */
938 static
939 int attlist8(PROLOG_STATE *state,
940 int tok,
941 const char *ptr,
942 const char *end,
943 const ENCODING *enc)
945 cmExpatUnused(ptr);
946 cmExpatUnused(end);
947 cmExpatUnused(enc);
948 switch (tok) {
949 case XML_TOK_PROLOG_S:
950 return XML_ROLE_NONE;
951 case XML_TOK_POUND_NAME:
952 if (XmlNameMatchesAscii(enc,
953 ptr + MIN_BYTES_PER_CHAR(enc),
954 end,
955 KW_IMPLIED)) {
956 state->handler = attlist1;
957 return XML_ROLE_IMPLIED_ATTRIBUTE_VALUE;
959 if (XmlNameMatchesAscii(enc,
960 ptr + MIN_BYTES_PER_CHAR(enc),
961 end,
962 KW_REQUIRED)) {
963 state->handler = attlist1;
964 return XML_ROLE_REQUIRED_ATTRIBUTE_VALUE;
966 if (XmlNameMatchesAscii(enc,
967 ptr + MIN_BYTES_PER_CHAR(enc),
968 end,
969 KW_FIXED)) {
970 state->handler = attlist9;
971 return XML_ROLE_NONE;
973 break;
974 case XML_TOK_LITERAL:
975 state->handler = attlist1;
976 return XML_ROLE_DEFAULT_ATTRIBUTE_VALUE;
978 return common(state, tok);
981 static
982 int attlist9(PROLOG_STATE *state,
983 int tok,
984 const char *ptr,
985 const char *end,
986 const ENCODING *enc)
988 cmExpatUnused(ptr);
989 cmExpatUnused(end);
990 cmExpatUnused(enc);
991 switch (tok) {
992 case XML_TOK_PROLOG_S:
993 return XML_ROLE_NONE;
994 case XML_TOK_LITERAL:
995 state->handler = attlist1;
996 return XML_ROLE_FIXED_ATTRIBUTE_VALUE;
998 return common(state, tok);
1001 static
1002 int element0(PROLOG_STATE *state,
1003 int tok,
1004 const char *ptr,
1005 const char *end,
1006 const ENCODING *enc)
1008 cmExpatUnused(ptr);
1009 cmExpatUnused(end);
1010 cmExpatUnused(enc);
1011 switch (tok) {
1012 case XML_TOK_PROLOG_S:
1013 return XML_ROLE_NONE;
1014 case XML_TOK_NAME:
1015 case XML_TOK_PREFIXED_NAME:
1016 state->handler = element1;
1017 return XML_ROLE_ELEMENT_NAME;
1019 return common(state, tok);
1022 static
1023 int element1(PROLOG_STATE *state,
1024 int tok,
1025 const char *ptr,
1026 const char *end,
1027 const ENCODING *enc)
1029 cmExpatUnused(ptr);
1030 cmExpatUnused(end);
1031 cmExpatUnused(enc);
1032 switch (tok) {
1033 case XML_TOK_PROLOG_S:
1034 return XML_ROLE_NONE;
1035 case XML_TOK_NAME:
1036 if (XmlNameMatchesAscii(enc, ptr, end, KW_EMPTY)) {
1037 state->handler = declClose;
1038 return XML_ROLE_CONTENT_EMPTY;
1040 if (XmlNameMatchesAscii(enc, ptr, end, KW_ANY)) {
1041 state->handler = declClose;
1042 return XML_ROLE_CONTENT_ANY;
1044 break;
1045 case XML_TOK_OPEN_PAREN:
1046 state->handler = element2;
1047 state->level = 1;
1048 return XML_ROLE_GROUP_OPEN;
1050 return common(state, tok);
1053 static
1054 int element2(PROLOG_STATE *state,
1055 int tok,
1056 const char *ptr,
1057 const char *end,
1058 const ENCODING *enc)
1060 cmExpatUnused(ptr);
1061 cmExpatUnused(end);
1062 cmExpatUnused(enc);
1063 switch (tok) {
1064 case XML_TOK_PROLOG_S:
1065 return XML_ROLE_NONE;
1066 case XML_TOK_POUND_NAME:
1067 if (XmlNameMatchesAscii(enc,
1068 ptr + MIN_BYTES_PER_CHAR(enc),
1069 end,
1070 KW_PCDATA)) {
1071 state->handler = element3;
1072 return XML_ROLE_CONTENT_PCDATA;
1074 break;
1075 case XML_TOK_OPEN_PAREN:
1076 state->level = 2;
1077 state->handler = element6;
1078 return XML_ROLE_GROUP_OPEN;
1079 case XML_TOK_NAME:
1080 case XML_TOK_PREFIXED_NAME:
1081 state->handler = element7;
1082 return XML_ROLE_CONTENT_ELEMENT;
1083 case XML_TOK_NAME_QUESTION:
1084 state->handler = element7;
1085 return XML_ROLE_CONTENT_ELEMENT_OPT;
1086 case XML_TOK_NAME_ASTERISK:
1087 state->handler = element7;
1088 return XML_ROLE_CONTENT_ELEMENT_REP;
1089 case XML_TOK_NAME_PLUS:
1090 state->handler = element7;
1091 return XML_ROLE_CONTENT_ELEMENT_PLUS;
1093 return common(state, tok);
1096 static
1097 int element3(PROLOG_STATE *state,
1098 int tok,
1099 const char *ptr,
1100 const char *end,
1101 const ENCODING *enc)
1103 cmExpatUnused(ptr);
1104 cmExpatUnused(end);
1105 cmExpatUnused(enc);
1106 switch (tok) {
1107 case XML_TOK_PROLOG_S:
1108 return XML_ROLE_NONE;
1109 case XML_TOK_CLOSE_PAREN:
1110 state->handler = declClose;
1111 return XML_ROLE_GROUP_CLOSE;
1112 case XML_TOK_CLOSE_PAREN_ASTERISK:
1113 state->handler = declClose;
1114 return XML_ROLE_GROUP_CLOSE_REP;
1115 case XML_TOK_OR:
1116 state->handler = element4;
1117 return XML_ROLE_NONE;
1119 return common(state, tok);
1122 static
1123 int element4(PROLOG_STATE *state,
1124 int tok,
1125 const char *ptr,
1126 const char *end,
1127 const ENCODING *enc)
1129 cmExpatUnused(ptr);
1130 cmExpatUnused(end);
1131 cmExpatUnused(enc);
1132 switch (tok) {
1133 case XML_TOK_PROLOG_S:
1134 return XML_ROLE_NONE;
1135 case XML_TOK_NAME:
1136 case XML_TOK_PREFIXED_NAME:
1137 state->handler = element5;
1138 return XML_ROLE_CONTENT_ELEMENT;
1140 return common(state, tok);
1143 static
1144 int element5(PROLOG_STATE *state,
1145 int tok,
1146 const char *ptr,
1147 const char *end,
1148 const ENCODING *enc)
1150 cmExpatUnused(ptr);
1151 cmExpatUnused(end);
1152 cmExpatUnused(enc);
1153 switch (tok) {
1154 case XML_TOK_PROLOG_S:
1155 return XML_ROLE_NONE;
1156 case XML_TOK_CLOSE_PAREN_ASTERISK:
1157 state->handler = declClose;
1158 return XML_ROLE_GROUP_CLOSE_REP;
1159 case XML_TOK_OR:
1160 state->handler = element4;
1161 return XML_ROLE_NONE;
1163 return common(state, tok);
1166 static
1167 int element6(PROLOG_STATE *state,
1168 int tok,
1169 const char *ptr,
1170 const char *end,
1171 const ENCODING *enc)
1173 cmExpatUnused(ptr);
1174 cmExpatUnused(end);
1175 cmExpatUnused(enc);
1176 switch (tok) {
1177 case XML_TOK_PROLOG_S:
1178 return XML_ROLE_NONE;
1179 case XML_TOK_OPEN_PAREN:
1180 state->level += 1;
1181 return XML_ROLE_GROUP_OPEN;
1182 case XML_TOK_NAME:
1183 case XML_TOK_PREFIXED_NAME:
1184 state->handler = element7;
1185 return XML_ROLE_CONTENT_ELEMENT;
1186 case XML_TOK_NAME_QUESTION:
1187 state->handler = element7;
1188 return XML_ROLE_CONTENT_ELEMENT_OPT;
1189 case XML_TOK_NAME_ASTERISK:
1190 state->handler = element7;
1191 return XML_ROLE_CONTENT_ELEMENT_REP;
1192 case XML_TOK_NAME_PLUS:
1193 state->handler = element7;
1194 return XML_ROLE_CONTENT_ELEMENT_PLUS;
1196 return common(state, tok);
1199 static
1200 int element7(PROLOG_STATE *state,
1201 int tok,
1202 const char *ptr,
1203 const char *end,
1204 const ENCODING *enc)
1206 cmExpatUnused(ptr);
1207 cmExpatUnused(end);
1208 cmExpatUnused(enc);
1209 switch (tok) {
1210 case XML_TOK_PROLOG_S:
1211 return XML_ROLE_NONE;
1212 case XML_TOK_CLOSE_PAREN:
1213 state->level -= 1;
1214 if (state->level == 0)
1215 state->handler = declClose;
1216 return XML_ROLE_GROUP_CLOSE;
1217 case XML_TOK_CLOSE_PAREN_ASTERISK:
1218 state->level -= 1;
1219 if (state->level == 0)
1220 state->handler = declClose;
1221 return XML_ROLE_GROUP_CLOSE_REP;
1222 case XML_TOK_CLOSE_PAREN_QUESTION:
1223 state->level -= 1;
1224 if (state->level == 0)
1225 state->handler = declClose;
1226 return XML_ROLE_GROUP_CLOSE_OPT;
1227 case XML_TOK_CLOSE_PAREN_PLUS:
1228 state->level -= 1;
1229 if (state->level == 0)
1230 state->handler = declClose;
1231 return XML_ROLE_GROUP_CLOSE_PLUS;
1232 case XML_TOK_COMMA:
1233 state->handler = element6;
1234 return XML_ROLE_GROUP_SEQUENCE;
1235 case XML_TOK_OR:
1236 state->handler = element6;
1237 return XML_ROLE_GROUP_CHOICE;
1239 return common(state, tok);
1242 #ifdef XML_DTD
1244 static
1245 int condSect0(PROLOG_STATE *state,
1246 int tok,
1247 const char *ptr,
1248 const char *end,
1249 const ENCODING *enc)
1251 cmExpatUnused(ptr);
1252 cmExpatUnused(end);
1253 cmExpatUnused(enc);
1254 switch (tok) {
1255 case XML_TOK_PROLOG_S:
1256 return XML_ROLE_NONE;
1257 case XML_TOK_NAME:
1258 if (XmlNameMatchesAscii(enc, ptr, end, KW_INCLUDE)) {
1259 state->handler = condSect1;
1260 return XML_ROLE_NONE;
1262 if (XmlNameMatchesAscii(enc, ptr, end, KW_IGNORE)) {
1263 state->handler = condSect2;
1264 return XML_ROLE_NONE;
1266 break;
1268 return common(state, tok);
1271 static
1272 int condSect1(PROLOG_STATE *state,
1273 int tok,
1274 const char *ptr,
1275 const char *end,
1276 const ENCODING *enc)
1278 cmExpatUnused(ptr);
1279 cmExpatUnused(end);
1280 cmExpatUnused(enc);
1281 switch (tok) {
1282 case XML_TOK_PROLOG_S:
1283 return XML_ROLE_NONE;
1284 case XML_TOK_OPEN_BRACKET:
1285 state->handler = externalSubset1;
1286 state->includeLevel += 1;
1287 return XML_ROLE_NONE;
1289 return common(state, tok);
1292 static
1293 int condSect2(PROLOG_STATE *state,
1294 int tok,
1295 const char *ptr,
1296 const char *end,
1297 const ENCODING *enc)
1299 cmExpatUnused(ptr);
1300 cmExpatUnused(end);
1301 cmExpatUnused(enc);
1302 switch (tok) {
1303 case XML_TOK_PROLOG_S:
1304 return XML_ROLE_NONE;
1305 case XML_TOK_OPEN_BRACKET:
1306 state->handler = externalSubset1;
1307 return XML_ROLE_IGNORE_SECT;
1309 return common(state, tok);
1312 #endif /* XML_DTD */
1314 static
1315 int declClose(PROLOG_STATE *state,
1316 int tok,
1317 const char *ptr,
1318 const char *end,
1319 const ENCODING *enc)
1321 cmExpatUnused(ptr);
1322 cmExpatUnused(end);
1323 cmExpatUnused(enc);
1324 switch (tok) {
1325 case XML_TOK_PROLOG_S:
1326 return XML_ROLE_NONE;
1327 case XML_TOK_DECL_CLOSE:
1328 setTopLevel(state);
1329 return XML_ROLE_NONE;
1331 return common(state, tok);
1334 #if 0
1336 static
1337 int ignore(PROLOG_STATE *state,
1338 int tok,
1339 const char *ptr,
1340 const char *end,
1341 const ENCODING *enc)
1343 cmExpatUnused(ptr);
1344 cmExpatUnused(end);
1345 cmExpatUnused(enc);
1346 switch (tok) {
1347 case XML_TOK_DECL_CLOSE:
1348 state->handler = internalSubset;
1349 return 0;
1350 default:
1351 return XML_ROLE_NONE;
1353 return common(state, tok);
1355 #endif
1357 static
1358 int error(PROLOG_STATE *state,
1359 int tok,
1360 const char *ptr,
1361 const char *end,
1362 const ENCODING *enc)
1364 cmExpatUnused(state);
1365 cmExpatUnused(tok);
1366 cmExpatUnused(ptr);
1367 cmExpatUnused(end);
1368 cmExpatUnused(enc);
1369 return XML_ROLE_NONE;
1372 static
1373 int common(PROLOG_STATE *state, int tok)
1375 #ifdef XML_DTD
1376 if (!state->documentEntity && tok == XML_TOK_PARAM_ENTITY_REF)
1377 return XML_ROLE_INNER_PARAM_ENTITY_REF;
1378 #endif
1379 state->handler = error;
1380 return XML_ROLE_ERROR;
1383 void XmlPrologStateInit(PROLOG_STATE *state)
1385 state->handler = prolog0;
1386 #ifdef XML_DTD
1387 state->documentEntity = 1;
1388 state->includeLevel = 0;
1389 #endif /* XML_DTD */
1392 #ifdef XML_DTD
1394 void XmlPrologStateInitExternalEntity(PROLOG_STATE *state)
1396 state->handler = externalSubset0;
1397 state->documentEntity = 0;
1398 state->includeLevel = 0;
1401 #endif /* XML_DTD */