Renamed exrternal.h to expat_external.h.
[mirror-ossqm-expat.git] / lib / xmlrole.c
blob1924fcb4dbe243ed7d474cdd450de7ca937dba4b
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 #else
12 #ifdef HAVE_EXPAT_CONFIG_H
13 #include <expat_config.h>
14 #endif
15 #endif /* ndef COMPILED_FROM_DSP */
17 #include "expat_external.h"
18 #include "internal.h"
19 #include "xmlrole.h"
20 #include "ascii.h"
22 /* Doesn't check:
24 that ,| are not mixed in a model group
25 content of literals
29 static const char KW_ANY[] = {
30 ASCII_A, ASCII_N, ASCII_Y, '\0' };
31 static const char KW_ATTLIST[] = {
32 ASCII_A, ASCII_T, ASCII_T, ASCII_L, ASCII_I, ASCII_S, ASCII_T, '\0' };
33 static const char KW_CDATA[] = {
34 ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' };
35 static const char KW_DOCTYPE[] = {
36 ASCII_D, ASCII_O, ASCII_C, ASCII_T, ASCII_Y, ASCII_P, ASCII_E, '\0' };
37 static const char KW_ELEMENT[] = {
38 ASCII_E, ASCII_L, ASCII_E, ASCII_M, ASCII_E, ASCII_N, ASCII_T, '\0' };
39 static const char KW_EMPTY[] = {
40 ASCII_E, ASCII_M, ASCII_P, ASCII_T, ASCII_Y, '\0' };
41 static const char KW_ENTITIES[] = {
42 ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, ASCII_I, ASCII_E, ASCII_S,
43 '\0' };
44 static const char KW_ENTITY[] = {
45 ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, ASCII_Y, '\0' };
46 static const char KW_FIXED[] = {
47 ASCII_F, ASCII_I, ASCII_X, ASCII_E, ASCII_D, '\0' };
48 static const char KW_ID[] = {
49 ASCII_I, ASCII_D, '\0' };
50 static const char KW_IDREF[] = {
51 ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, '\0' };
52 static const char KW_IDREFS[] = {
53 ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, ASCII_S, '\0' };
54 static const char KW_IGNORE[] = {
55 ASCII_I, ASCII_G, ASCII_N, ASCII_O, ASCII_R, ASCII_E, '\0' };
56 static const char KW_IMPLIED[] = {
57 ASCII_I, ASCII_M, ASCII_P, ASCII_L, ASCII_I, ASCII_E, ASCII_D, '\0' };
58 static const char KW_INCLUDE[] = {
59 ASCII_I, ASCII_N, ASCII_C, ASCII_L, ASCII_U, ASCII_D, ASCII_E, '\0' };
60 static const char KW_NDATA[] = {
61 ASCII_N, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' };
62 static const char KW_NMTOKEN[] = {
63 ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, ASCII_E, ASCII_N, '\0' };
64 static const char KW_NMTOKENS[] = {
65 ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, ASCII_E, ASCII_N, ASCII_S,
66 '\0' };
67 static const char KW_NOTATION[] =
68 { ASCII_N, ASCII_O, ASCII_T, ASCII_A, ASCII_T, ASCII_I, ASCII_O, ASCII_N,
69 '\0' };
70 static const char KW_PCDATA[] = {
71 ASCII_P, ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' };
72 static const char KW_PUBLIC[] = {
73 ASCII_P, ASCII_U, ASCII_B, ASCII_L, ASCII_I, ASCII_C, '\0' };
74 static const char KW_REQUIRED[] = {
75 ASCII_R, ASCII_E, ASCII_Q, ASCII_U, ASCII_I, ASCII_R, ASCII_E, ASCII_D,
76 '\0' };
77 static const char KW_SYSTEM[] = {
78 ASCII_S, ASCII_Y, ASCII_S, ASCII_T, ASCII_E, ASCII_M, '\0' };
80 #ifndef MIN_BYTES_PER_CHAR
81 #define MIN_BYTES_PER_CHAR(enc) ((enc)->minBytesPerChar)
82 #endif
84 #ifdef XML_DTD
85 #define setTopLevel(state) \
86 ((state)->handler = ((state)->documentEntity \
87 ? internalSubset \
88 : externalSubset1))
89 #else /* not XML_DTD */
90 #define setTopLevel(state) ((state)->handler = internalSubset)
91 #endif /* not XML_DTD */
93 typedef int PTRCALL PROLOG_HANDLER(PROLOG_STATE *state,
94 int tok,
95 const char *ptr,
96 const char *end,
97 const ENCODING *enc);
99 static PROLOG_HANDLER
100 prolog0, prolog1, prolog2,
101 doctype0, doctype1, doctype2, doctype3, doctype4, doctype5,
102 internalSubset,
103 entity0, entity1, entity2, entity3, entity4, entity5, entity6,
104 entity7, entity8, entity9, entity10,
105 notation0, notation1, notation2, notation3, notation4,
106 attlist0, attlist1, attlist2, attlist3, attlist4, attlist5, attlist6,
107 attlist7, attlist8, attlist9,
108 element0, element1, element2, element3, element4, element5, element6,
109 element7,
110 #ifdef XML_DTD
111 externalSubset0, externalSubset1,
112 condSect0, condSect1, condSect2,
113 #endif /* XML_DTD */
114 declClose,
115 error;
117 static int FASTCALL common(PROLOG_STATE *state, int tok);
119 static int PTRCALL
120 prolog0(PROLOG_STATE *state,
121 int tok,
122 const char *ptr,
123 const char *end,
124 const ENCODING *enc)
126 switch (tok) {
127 case XML_TOK_PROLOG_S:
128 state->handler = prolog1;
129 return XML_ROLE_NONE;
130 case XML_TOK_XML_DECL:
131 state->handler = prolog1;
132 return XML_ROLE_XML_DECL;
133 case XML_TOK_PI:
134 state->handler = prolog1;
135 return XML_ROLE_PI;
136 case XML_TOK_COMMENT:
137 state->handler = prolog1;
138 return XML_ROLE_COMMENT;
139 case XML_TOK_BOM:
140 return XML_ROLE_NONE;
141 case XML_TOK_DECL_OPEN:
142 if (!XmlNameMatchesAscii(enc,
143 ptr + 2 * MIN_BYTES_PER_CHAR(enc),
144 end,
145 KW_DOCTYPE))
146 break;
147 state->handler = doctype0;
148 return XML_ROLE_DOCTYPE_NONE;
149 case XML_TOK_INSTANCE_START:
150 state->handler = error;
151 return XML_ROLE_INSTANCE_START;
153 return common(state, tok);
156 static int PTRCALL
157 prolog1(PROLOG_STATE *state,
158 int tok,
159 const char *ptr,
160 const char *end,
161 const ENCODING *enc)
163 switch (tok) {
164 case XML_TOK_PROLOG_S:
165 return XML_ROLE_NONE;
166 case XML_TOK_PI:
167 return XML_ROLE_PI;
168 case XML_TOK_COMMENT:
169 return XML_ROLE_COMMENT;
170 case XML_TOK_BOM:
171 return XML_ROLE_NONE;
172 case XML_TOK_DECL_OPEN:
173 if (!XmlNameMatchesAscii(enc,
174 ptr + 2 * MIN_BYTES_PER_CHAR(enc),
175 end,
176 KW_DOCTYPE))
177 break;
178 state->handler = doctype0;
179 return XML_ROLE_DOCTYPE_NONE;
180 case XML_TOK_INSTANCE_START:
181 state->handler = error;
182 return XML_ROLE_INSTANCE_START;
184 return common(state, tok);
187 static int PTRCALL
188 prolog2(PROLOG_STATE *state,
189 int tok,
190 const char *ptr,
191 const char *end,
192 const ENCODING *enc)
194 switch (tok) {
195 case XML_TOK_PROLOG_S:
196 return XML_ROLE_NONE;
197 case XML_TOK_PI:
198 return XML_ROLE_PI;
199 case XML_TOK_COMMENT:
200 return XML_ROLE_COMMENT;
201 case XML_TOK_INSTANCE_START:
202 state->handler = error;
203 return XML_ROLE_INSTANCE_START;
205 return common(state, tok);
208 static int PTRCALL
209 doctype0(PROLOG_STATE *state,
210 int tok,
211 const char *ptr,
212 const char *end,
213 const ENCODING *enc)
215 switch (tok) {
216 case XML_TOK_PROLOG_S:
217 return XML_ROLE_DOCTYPE_NONE;
218 case XML_TOK_NAME:
219 case XML_TOK_PREFIXED_NAME:
220 state->handler = doctype1;
221 return XML_ROLE_DOCTYPE_NAME;
223 return common(state, tok);
226 static int PTRCALL
227 doctype1(PROLOG_STATE *state,
228 int tok,
229 const char *ptr,
230 const char *end,
231 const ENCODING *enc)
233 switch (tok) {
234 case XML_TOK_PROLOG_S:
235 return XML_ROLE_DOCTYPE_NONE;
236 case XML_TOK_OPEN_BRACKET:
237 state->handler = internalSubset;
238 return XML_ROLE_DOCTYPE_INTERNAL_SUBSET;
239 case XML_TOK_DECL_CLOSE:
240 state->handler = prolog2;
241 return XML_ROLE_DOCTYPE_CLOSE;
242 case XML_TOK_NAME:
243 if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) {
244 state->handler = doctype3;
245 return XML_ROLE_DOCTYPE_NONE;
247 if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) {
248 state->handler = doctype2;
249 return XML_ROLE_DOCTYPE_NONE;
251 break;
253 return common(state, tok);
256 static int PTRCALL
257 doctype2(PROLOG_STATE *state,
258 int tok,
259 const char *ptr,
260 const char *end,
261 const ENCODING *enc)
263 switch (tok) {
264 case XML_TOK_PROLOG_S:
265 return XML_ROLE_DOCTYPE_NONE;
266 case XML_TOK_LITERAL:
267 state->handler = doctype3;
268 return XML_ROLE_DOCTYPE_PUBLIC_ID;
270 return common(state, tok);
273 static int PTRCALL
274 doctype3(PROLOG_STATE *state,
275 int tok,
276 const char *ptr,
277 const char *end,
278 const ENCODING *enc)
280 switch (tok) {
281 case XML_TOK_PROLOG_S:
282 return XML_ROLE_DOCTYPE_NONE;
283 case XML_TOK_LITERAL:
284 state->handler = doctype4;
285 return XML_ROLE_DOCTYPE_SYSTEM_ID;
287 return common(state, tok);
290 static int PTRCALL
291 doctype4(PROLOG_STATE *state,
292 int tok,
293 const char *ptr,
294 const char *end,
295 const ENCODING *enc)
297 switch (tok) {
298 case XML_TOK_PROLOG_S:
299 return XML_ROLE_DOCTYPE_NONE;
300 case XML_TOK_OPEN_BRACKET:
301 state->handler = internalSubset;
302 return XML_ROLE_DOCTYPE_INTERNAL_SUBSET;
303 case XML_TOK_DECL_CLOSE:
304 state->handler = prolog2;
305 return XML_ROLE_DOCTYPE_CLOSE;
307 return common(state, tok);
310 static int PTRCALL
311 doctype5(PROLOG_STATE *state,
312 int tok,
313 const char *ptr,
314 const char *end,
315 const ENCODING *enc)
317 switch (tok) {
318 case XML_TOK_PROLOG_S:
319 return XML_ROLE_DOCTYPE_NONE;
320 case XML_TOK_DECL_CLOSE:
321 state->handler = prolog2;
322 return XML_ROLE_DOCTYPE_CLOSE;
324 return common(state, tok);
327 static int PTRCALL
328 internalSubset(PROLOG_STATE *state,
329 int tok,
330 const char *ptr,
331 const char *end,
332 const ENCODING *enc)
334 switch (tok) {
335 case XML_TOK_PROLOG_S:
336 return XML_ROLE_NONE;
337 case XML_TOK_DECL_OPEN:
338 if (XmlNameMatchesAscii(enc,
339 ptr + 2 * MIN_BYTES_PER_CHAR(enc),
340 end,
341 KW_ENTITY)) {
342 state->handler = entity0;
343 return XML_ROLE_ENTITY_NONE;
345 if (XmlNameMatchesAscii(enc,
346 ptr + 2 * MIN_BYTES_PER_CHAR(enc),
347 end,
348 KW_ATTLIST)) {
349 state->handler = attlist0;
350 return XML_ROLE_ATTLIST_NONE;
352 if (XmlNameMatchesAscii(enc,
353 ptr + 2 * MIN_BYTES_PER_CHAR(enc),
354 end,
355 KW_ELEMENT)) {
356 state->handler = element0;
357 return XML_ROLE_ELEMENT_NONE;
359 if (XmlNameMatchesAscii(enc,
360 ptr + 2 * MIN_BYTES_PER_CHAR(enc),
361 end,
362 KW_NOTATION)) {
363 state->handler = notation0;
364 return XML_ROLE_NOTATION_NONE;
366 break;
367 case XML_TOK_PI:
368 return XML_ROLE_PI;
369 case XML_TOK_COMMENT:
370 return XML_ROLE_COMMENT;
371 case XML_TOK_PARAM_ENTITY_REF:
372 return XML_ROLE_PARAM_ENTITY_REF;
373 case XML_TOK_CLOSE_BRACKET:
374 state->handler = doctype5;
375 return XML_ROLE_DOCTYPE_NONE;
376 case XML_TOK_NONE:
377 return XML_ROLE_NONE;
379 return common(state, tok);
382 #ifdef XML_DTD
384 static int PTRCALL
385 externalSubset0(PROLOG_STATE *state,
386 int tok,
387 const char *ptr,
388 const char *end,
389 const ENCODING *enc)
391 state->handler = externalSubset1;
392 if (tok == XML_TOK_XML_DECL)
393 return XML_ROLE_TEXT_DECL;
394 return externalSubset1(state, tok, ptr, end, enc);
397 static int PTRCALL
398 externalSubset1(PROLOG_STATE *state,
399 int tok,
400 const char *ptr,
401 const char *end,
402 const ENCODING *enc)
404 switch (tok) {
405 case XML_TOK_COND_SECT_OPEN:
406 state->handler = condSect0;
407 return XML_ROLE_NONE;
408 case XML_TOK_COND_SECT_CLOSE:
409 if (state->includeLevel == 0)
410 break;
411 state->includeLevel -= 1;
412 return XML_ROLE_NONE;
413 case XML_TOK_PROLOG_S:
414 return XML_ROLE_NONE;
415 case XML_TOK_CLOSE_BRACKET:
416 break;
417 case XML_TOK_NONE:
418 if (state->includeLevel)
419 break;
420 return XML_ROLE_NONE;
421 default:
422 return internalSubset(state, tok, ptr, end, enc);
424 return common(state, tok);
427 #endif /* XML_DTD */
429 static int PTRCALL
430 entity0(PROLOG_STATE *state,
431 int tok,
432 const char *ptr,
433 const char *end,
434 const ENCODING *enc)
436 switch (tok) {
437 case XML_TOK_PROLOG_S:
438 return XML_ROLE_ENTITY_NONE;
439 case XML_TOK_PERCENT:
440 state->handler = entity1;
441 return XML_ROLE_ENTITY_NONE;
442 case XML_TOK_NAME:
443 state->handler = entity2;
444 return XML_ROLE_GENERAL_ENTITY_NAME;
446 return common(state, tok);
449 static int PTRCALL
450 entity1(PROLOG_STATE *state,
451 int tok,
452 const char *ptr,
453 const char *end,
454 const ENCODING *enc)
456 switch (tok) {
457 case XML_TOK_PROLOG_S:
458 return XML_ROLE_ENTITY_NONE;
459 case XML_TOK_NAME:
460 state->handler = entity7;
461 return XML_ROLE_PARAM_ENTITY_NAME;
463 return common(state, tok);
466 static int PTRCALL
467 entity2(PROLOG_STATE *state,
468 int tok,
469 const char *ptr,
470 const char *end,
471 const ENCODING *enc)
473 switch (tok) {
474 case XML_TOK_PROLOG_S:
475 return XML_ROLE_ENTITY_NONE;
476 case XML_TOK_NAME:
477 if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) {
478 state->handler = entity4;
479 return XML_ROLE_ENTITY_NONE;
481 if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) {
482 state->handler = entity3;
483 return XML_ROLE_ENTITY_NONE;
485 break;
486 case XML_TOK_LITERAL:
487 state->handler = declClose;
488 state->role_none = XML_ROLE_ENTITY_NONE;
489 return XML_ROLE_ENTITY_VALUE;
491 return common(state, tok);
494 static int PTRCALL
495 entity3(PROLOG_STATE *state,
496 int tok,
497 const char *ptr,
498 const char *end,
499 const ENCODING *enc)
501 switch (tok) {
502 case XML_TOK_PROLOG_S:
503 return XML_ROLE_ENTITY_NONE;
504 case XML_TOK_LITERAL:
505 state->handler = entity4;
506 return XML_ROLE_ENTITY_PUBLIC_ID;
508 return common(state, tok);
511 static int PTRCALL
512 entity4(PROLOG_STATE *state,
513 int tok,
514 const char *ptr,
515 const char *end,
516 const ENCODING *enc)
518 switch (tok) {
519 case XML_TOK_PROLOG_S:
520 return XML_ROLE_ENTITY_NONE;
521 case XML_TOK_LITERAL:
522 state->handler = entity5;
523 return XML_ROLE_ENTITY_SYSTEM_ID;
525 return common(state, tok);
528 static int PTRCALL
529 entity5(PROLOG_STATE *state,
530 int tok,
531 const char *ptr,
532 const char *end,
533 const ENCODING *enc)
535 switch (tok) {
536 case XML_TOK_PROLOG_S:
537 return XML_ROLE_ENTITY_NONE;
538 case XML_TOK_DECL_CLOSE:
539 setTopLevel(state);
540 return XML_ROLE_ENTITY_COMPLETE;
541 case XML_TOK_NAME:
542 if (XmlNameMatchesAscii(enc, ptr, end, KW_NDATA)) {
543 state->handler = entity6;
544 return XML_ROLE_ENTITY_NONE;
546 break;
548 return common(state, tok);
551 static int PTRCALL
552 entity6(PROLOG_STATE *state,
553 int tok,
554 const char *ptr,
555 const char *end,
556 const ENCODING *enc)
558 switch (tok) {
559 case XML_TOK_PROLOG_S:
560 return XML_ROLE_ENTITY_NONE;
561 case XML_TOK_NAME:
562 state->handler = declClose;
563 state->role_none = XML_ROLE_ENTITY_NONE;
564 return XML_ROLE_ENTITY_NOTATION_NAME;
566 return common(state, tok);
569 static int PTRCALL
570 entity7(PROLOG_STATE *state,
571 int tok,
572 const char *ptr,
573 const char *end,
574 const ENCODING *enc)
576 switch (tok) {
577 case XML_TOK_PROLOG_S:
578 return XML_ROLE_ENTITY_NONE;
579 case XML_TOK_NAME:
580 if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) {
581 state->handler = entity9;
582 return XML_ROLE_ENTITY_NONE;
584 if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) {
585 state->handler = entity8;
586 return XML_ROLE_ENTITY_NONE;
588 break;
589 case XML_TOK_LITERAL:
590 state->handler = declClose;
591 state->role_none = XML_ROLE_ENTITY_NONE;
592 return XML_ROLE_ENTITY_VALUE;
594 return common(state, tok);
597 static int PTRCALL
598 entity8(PROLOG_STATE *state,
599 int tok,
600 const char *ptr,
601 const char *end,
602 const ENCODING *enc)
604 switch (tok) {
605 case XML_TOK_PROLOG_S:
606 return XML_ROLE_ENTITY_NONE;
607 case XML_TOK_LITERAL:
608 state->handler = entity9;
609 return XML_ROLE_ENTITY_PUBLIC_ID;
611 return common(state, tok);
614 static int PTRCALL
615 entity9(PROLOG_STATE *state,
616 int tok,
617 const char *ptr,
618 const char *end,
619 const ENCODING *enc)
621 switch (tok) {
622 case XML_TOK_PROLOG_S:
623 return XML_ROLE_ENTITY_NONE;
624 case XML_TOK_LITERAL:
625 state->handler = entity10;
626 return XML_ROLE_ENTITY_SYSTEM_ID;
628 return common(state, tok);
631 static int PTRCALL
632 entity10(PROLOG_STATE *state,
633 int tok,
634 const char *ptr,
635 const char *end,
636 const ENCODING *enc)
638 switch (tok) {
639 case XML_TOK_PROLOG_S:
640 return XML_ROLE_ENTITY_NONE;
641 case XML_TOK_DECL_CLOSE:
642 setTopLevel(state);
643 return XML_ROLE_ENTITY_COMPLETE;
645 return common(state, tok);
648 static int PTRCALL
649 notation0(PROLOG_STATE *state,
650 int tok,
651 const char *ptr,
652 const char *end,
653 const ENCODING *enc)
655 switch (tok) {
656 case XML_TOK_PROLOG_S:
657 return XML_ROLE_NOTATION_NONE;
658 case XML_TOK_NAME:
659 state->handler = notation1;
660 return XML_ROLE_NOTATION_NAME;
662 return common(state, tok);
665 static int PTRCALL
666 notation1(PROLOG_STATE *state,
667 int tok,
668 const char *ptr,
669 const char *end,
670 const ENCODING *enc)
672 switch (tok) {
673 case XML_TOK_PROLOG_S:
674 return XML_ROLE_NOTATION_NONE;
675 case XML_TOK_NAME:
676 if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) {
677 state->handler = notation3;
678 return XML_ROLE_NOTATION_NONE;
680 if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) {
681 state->handler = notation2;
682 return XML_ROLE_NOTATION_NONE;
684 break;
686 return common(state, tok);
689 static int PTRCALL
690 notation2(PROLOG_STATE *state,
691 int tok,
692 const char *ptr,
693 const char *end,
694 const ENCODING *enc)
696 switch (tok) {
697 case XML_TOK_PROLOG_S:
698 return XML_ROLE_NOTATION_NONE;
699 case XML_TOK_LITERAL:
700 state->handler = notation4;
701 return XML_ROLE_NOTATION_PUBLIC_ID;
703 return common(state, tok);
706 static int PTRCALL
707 notation3(PROLOG_STATE *state,
708 int tok,
709 const char *ptr,
710 const char *end,
711 const ENCODING *enc)
713 switch (tok) {
714 case XML_TOK_PROLOG_S:
715 return XML_ROLE_NOTATION_NONE;
716 case XML_TOK_LITERAL:
717 state->handler = declClose;
718 state->role_none = XML_ROLE_NOTATION_NONE;
719 return XML_ROLE_NOTATION_SYSTEM_ID;
721 return common(state, tok);
724 static int PTRCALL
725 notation4(PROLOG_STATE *state,
726 int tok,
727 const char *ptr,
728 const char *end,
729 const ENCODING *enc)
731 switch (tok) {
732 case XML_TOK_PROLOG_S:
733 return XML_ROLE_NOTATION_NONE;
734 case XML_TOK_LITERAL:
735 state->handler = declClose;
736 state->role_none = XML_ROLE_NOTATION_NONE;
737 return XML_ROLE_NOTATION_SYSTEM_ID;
738 case XML_TOK_DECL_CLOSE:
739 setTopLevel(state);
740 return XML_ROLE_NOTATION_NO_SYSTEM_ID;
742 return common(state, tok);
745 static int PTRCALL
746 attlist0(PROLOG_STATE *state,
747 int tok,
748 const char *ptr,
749 const char *end,
750 const ENCODING *enc)
752 switch (tok) {
753 case XML_TOK_PROLOG_S:
754 return XML_ROLE_ATTLIST_NONE;
755 case XML_TOK_NAME:
756 case XML_TOK_PREFIXED_NAME:
757 state->handler = attlist1;
758 return XML_ROLE_ATTLIST_ELEMENT_NAME;
760 return common(state, tok);
763 static int PTRCALL
764 attlist1(PROLOG_STATE *state,
765 int tok,
766 const char *ptr,
767 const char *end,
768 const ENCODING *enc)
770 switch (tok) {
771 case XML_TOK_PROLOG_S:
772 return XML_ROLE_ATTLIST_NONE;
773 case XML_TOK_DECL_CLOSE:
774 setTopLevel(state);
775 return XML_ROLE_ATTLIST_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 int PTRCALL
785 attlist2(PROLOG_STATE *state,
786 int tok,
787 const char *ptr,
788 const char *end,
789 const ENCODING *enc)
791 switch (tok) {
792 case XML_TOK_PROLOG_S:
793 return XML_ROLE_ATTLIST_NONE;
794 case XML_TOK_NAME:
796 static const char *types[] = {
797 KW_CDATA,
798 KW_ID,
799 KW_IDREF,
800 KW_IDREFS,
801 KW_ENTITY,
802 KW_ENTITIES,
803 KW_NMTOKEN,
804 KW_NMTOKENS,
806 int i;
807 for (i = 0; i < (int)(sizeof(types)/sizeof(types[0])); i++)
808 if (XmlNameMatchesAscii(enc, ptr, end, types[i])) {
809 state->handler = attlist8;
810 return XML_ROLE_ATTRIBUTE_TYPE_CDATA + i;
813 if (XmlNameMatchesAscii(enc, ptr, end, KW_NOTATION)) {
814 state->handler = attlist5;
815 return XML_ROLE_ATTLIST_NONE;
817 break;
818 case XML_TOK_OPEN_PAREN:
819 state->handler = attlist3;
820 return XML_ROLE_ATTLIST_NONE;
822 return common(state, tok);
825 static int PTRCALL
826 attlist3(PROLOG_STATE *state,
827 int tok,
828 const char *ptr,
829 const char *end,
830 const ENCODING *enc)
832 switch (tok) {
833 case XML_TOK_PROLOG_S:
834 return XML_ROLE_ATTLIST_NONE;
835 case XML_TOK_NMTOKEN:
836 case XML_TOK_NAME:
837 case XML_TOK_PREFIXED_NAME:
838 state->handler = attlist4;
839 return XML_ROLE_ATTRIBUTE_ENUM_VALUE;
841 return common(state, tok);
844 static int PTRCALL
845 attlist4(PROLOG_STATE *state,
846 int tok,
847 const char *ptr,
848 const char *end,
849 const ENCODING *enc)
851 switch (tok) {
852 case XML_TOK_PROLOG_S:
853 return XML_ROLE_ATTLIST_NONE;
854 case XML_TOK_CLOSE_PAREN:
855 state->handler = attlist8;
856 return XML_ROLE_ATTLIST_NONE;
857 case XML_TOK_OR:
858 state->handler = attlist3;
859 return XML_ROLE_ATTLIST_NONE;
861 return common(state, tok);
864 static int PTRCALL
865 attlist5(PROLOG_STATE *state,
866 int tok,
867 const char *ptr,
868 const char *end,
869 const ENCODING *enc)
871 switch (tok) {
872 case XML_TOK_PROLOG_S:
873 return XML_ROLE_ATTLIST_NONE;
874 case XML_TOK_OPEN_PAREN:
875 state->handler = attlist6;
876 return XML_ROLE_ATTLIST_NONE;
878 return common(state, tok);
881 static int PTRCALL
882 attlist6(PROLOG_STATE *state,
883 int tok,
884 const char *ptr,
885 const char *end,
886 const ENCODING *enc)
888 switch (tok) {
889 case XML_TOK_PROLOG_S:
890 return XML_ROLE_ATTLIST_NONE;
891 case XML_TOK_NAME:
892 state->handler = attlist7;
893 return XML_ROLE_ATTRIBUTE_NOTATION_VALUE;
895 return common(state, tok);
898 static int PTRCALL
899 attlist7(PROLOG_STATE *state,
900 int tok,
901 const char *ptr,
902 const char *end,
903 const ENCODING *enc)
905 switch (tok) {
906 case XML_TOK_PROLOG_S:
907 return XML_ROLE_ATTLIST_NONE;
908 case XML_TOK_CLOSE_PAREN:
909 state->handler = attlist8;
910 return XML_ROLE_ATTLIST_NONE;
911 case XML_TOK_OR:
912 state->handler = attlist6;
913 return XML_ROLE_ATTLIST_NONE;
915 return common(state, tok);
918 /* default value */
919 static int PTRCALL
920 attlist8(PROLOG_STATE *state,
921 int tok,
922 const char *ptr,
923 const char *end,
924 const ENCODING *enc)
926 switch (tok) {
927 case XML_TOK_PROLOG_S:
928 return XML_ROLE_ATTLIST_NONE;
929 case XML_TOK_POUND_NAME:
930 if (XmlNameMatchesAscii(enc,
931 ptr + MIN_BYTES_PER_CHAR(enc),
932 end,
933 KW_IMPLIED)) {
934 state->handler = attlist1;
935 return XML_ROLE_IMPLIED_ATTRIBUTE_VALUE;
937 if (XmlNameMatchesAscii(enc,
938 ptr + MIN_BYTES_PER_CHAR(enc),
939 end,
940 KW_REQUIRED)) {
941 state->handler = attlist1;
942 return XML_ROLE_REQUIRED_ATTRIBUTE_VALUE;
944 if (XmlNameMatchesAscii(enc,
945 ptr + MIN_BYTES_PER_CHAR(enc),
946 end,
947 KW_FIXED)) {
948 state->handler = attlist9;
949 return XML_ROLE_ATTLIST_NONE;
951 break;
952 case XML_TOK_LITERAL:
953 state->handler = attlist1;
954 return XML_ROLE_DEFAULT_ATTRIBUTE_VALUE;
956 return common(state, tok);
959 static int PTRCALL
960 attlist9(PROLOG_STATE *state,
961 int tok,
962 const char *ptr,
963 const char *end,
964 const ENCODING *enc)
966 switch (tok) {
967 case XML_TOK_PROLOG_S:
968 return XML_ROLE_ATTLIST_NONE;
969 case XML_TOK_LITERAL:
970 state->handler = attlist1;
971 return XML_ROLE_FIXED_ATTRIBUTE_VALUE;
973 return common(state, tok);
976 static int PTRCALL
977 element0(PROLOG_STATE *state,
978 int tok,
979 const char *ptr,
980 const char *end,
981 const ENCODING *enc)
983 switch (tok) {
984 case XML_TOK_PROLOG_S:
985 return XML_ROLE_ELEMENT_NONE;
986 case XML_TOK_NAME:
987 case XML_TOK_PREFIXED_NAME:
988 state->handler = element1;
989 return XML_ROLE_ELEMENT_NAME;
991 return common(state, tok);
994 static int PTRCALL
995 element1(PROLOG_STATE *state,
996 int tok,
997 const char *ptr,
998 const char *end,
999 const ENCODING *enc)
1001 switch (tok) {
1002 case XML_TOK_PROLOG_S:
1003 return XML_ROLE_ELEMENT_NONE;
1004 case XML_TOK_NAME:
1005 if (XmlNameMatchesAscii(enc, ptr, end, KW_EMPTY)) {
1006 state->handler = declClose;
1007 state->role_none = XML_ROLE_ELEMENT_NONE;
1008 return XML_ROLE_CONTENT_EMPTY;
1010 if (XmlNameMatchesAscii(enc, ptr, end, KW_ANY)) {
1011 state->handler = declClose;
1012 state->role_none = XML_ROLE_ELEMENT_NONE;
1013 return XML_ROLE_CONTENT_ANY;
1015 break;
1016 case XML_TOK_OPEN_PAREN:
1017 state->handler = element2;
1018 state->level = 1;
1019 return XML_ROLE_GROUP_OPEN;
1021 return common(state, tok);
1024 static int PTRCALL
1025 element2(PROLOG_STATE *state,
1026 int tok,
1027 const char *ptr,
1028 const char *end,
1029 const ENCODING *enc)
1031 switch (tok) {
1032 case XML_TOK_PROLOG_S:
1033 return XML_ROLE_ELEMENT_NONE;
1034 case XML_TOK_POUND_NAME:
1035 if (XmlNameMatchesAscii(enc,
1036 ptr + MIN_BYTES_PER_CHAR(enc),
1037 end,
1038 KW_PCDATA)) {
1039 state->handler = element3;
1040 return XML_ROLE_CONTENT_PCDATA;
1042 break;
1043 case XML_TOK_OPEN_PAREN:
1044 state->level = 2;
1045 state->handler = element6;
1046 return XML_ROLE_GROUP_OPEN;
1047 case XML_TOK_NAME:
1048 case XML_TOK_PREFIXED_NAME:
1049 state->handler = element7;
1050 return XML_ROLE_CONTENT_ELEMENT;
1051 case XML_TOK_NAME_QUESTION:
1052 state->handler = element7;
1053 return XML_ROLE_CONTENT_ELEMENT_OPT;
1054 case XML_TOK_NAME_ASTERISK:
1055 state->handler = element7;
1056 return XML_ROLE_CONTENT_ELEMENT_REP;
1057 case XML_TOK_NAME_PLUS:
1058 state->handler = element7;
1059 return XML_ROLE_CONTENT_ELEMENT_PLUS;
1061 return common(state, tok);
1064 static int PTRCALL
1065 element3(PROLOG_STATE *state,
1066 int tok,
1067 const char *ptr,
1068 const char *end,
1069 const ENCODING *enc)
1071 switch (tok) {
1072 case XML_TOK_PROLOG_S:
1073 return XML_ROLE_ELEMENT_NONE;
1074 case XML_TOK_CLOSE_PAREN:
1075 state->handler = declClose;
1076 state->role_none = XML_ROLE_ELEMENT_NONE;
1077 return XML_ROLE_GROUP_CLOSE;
1078 case XML_TOK_CLOSE_PAREN_ASTERISK:
1079 state->handler = declClose;
1080 state->role_none = XML_ROLE_ELEMENT_NONE;
1081 return XML_ROLE_GROUP_CLOSE_REP;
1082 case XML_TOK_OR:
1083 state->handler = element4;
1084 return XML_ROLE_ELEMENT_NONE;
1086 return common(state, tok);
1089 static int PTRCALL
1090 element4(PROLOG_STATE *state,
1091 int tok,
1092 const char *ptr,
1093 const char *end,
1094 const ENCODING *enc)
1096 switch (tok) {
1097 case XML_TOK_PROLOG_S:
1098 return XML_ROLE_ELEMENT_NONE;
1099 case XML_TOK_NAME:
1100 case XML_TOK_PREFIXED_NAME:
1101 state->handler = element5;
1102 return XML_ROLE_CONTENT_ELEMENT;
1104 return common(state, tok);
1107 static int PTRCALL
1108 element5(PROLOG_STATE *state,
1109 int tok,
1110 const char *ptr,
1111 const char *end,
1112 const ENCODING *enc)
1114 switch (tok) {
1115 case XML_TOK_PROLOG_S:
1116 return XML_ROLE_ELEMENT_NONE;
1117 case XML_TOK_CLOSE_PAREN_ASTERISK:
1118 state->handler = declClose;
1119 state->role_none = XML_ROLE_ELEMENT_NONE;
1120 return XML_ROLE_GROUP_CLOSE_REP;
1121 case XML_TOK_OR:
1122 state->handler = element4;
1123 return XML_ROLE_ELEMENT_NONE;
1125 return common(state, tok);
1128 static int PTRCALL
1129 element6(PROLOG_STATE *state,
1130 int tok,
1131 const char *ptr,
1132 const char *end,
1133 const ENCODING *enc)
1135 switch (tok) {
1136 case XML_TOK_PROLOG_S:
1137 return XML_ROLE_ELEMENT_NONE;
1138 case XML_TOK_OPEN_PAREN:
1139 state->level += 1;
1140 return XML_ROLE_GROUP_OPEN;
1141 case XML_TOK_NAME:
1142 case XML_TOK_PREFIXED_NAME:
1143 state->handler = element7;
1144 return XML_ROLE_CONTENT_ELEMENT;
1145 case XML_TOK_NAME_QUESTION:
1146 state->handler = element7;
1147 return XML_ROLE_CONTENT_ELEMENT_OPT;
1148 case XML_TOK_NAME_ASTERISK:
1149 state->handler = element7;
1150 return XML_ROLE_CONTENT_ELEMENT_REP;
1151 case XML_TOK_NAME_PLUS:
1152 state->handler = element7;
1153 return XML_ROLE_CONTENT_ELEMENT_PLUS;
1155 return common(state, tok);
1158 static int PTRCALL
1159 element7(PROLOG_STATE *state,
1160 int tok,
1161 const char *ptr,
1162 const char *end,
1163 const ENCODING *enc)
1165 switch (tok) {
1166 case XML_TOK_PROLOG_S:
1167 return XML_ROLE_ELEMENT_NONE;
1168 case XML_TOK_CLOSE_PAREN:
1169 state->level -= 1;
1170 if (state->level == 0) {
1171 state->handler = declClose;
1172 state->role_none = XML_ROLE_ELEMENT_NONE;
1174 return XML_ROLE_GROUP_CLOSE;
1175 case XML_TOK_CLOSE_PAREN_ASTERISK:
1176 state->level -= 1;
1177 if (state->level == 0) {
1178 state->handler = declClose;
1179 state->role_none = XML_ROLE_ELEMENT_NONE;
1181 return XML_ROLE_GROUP_CLOSE_REP;
1182 case XML_TOK_CLOSE_PAREN_QUESTION:
1183 state->level -= 1;
1184 if (state->level == 0) {
1185 state->handler = declClose;
1186 state->role_none = XML_ROLE_ELEMENT_NONE;
1188 return XML_ROLE_GROUP_CLOSE_OPT;
1189 case XML_TOK_CLOSE_PAREN_PLUS:
1190 state->level -= 1;
1191 if (state->level == 0) {
1192 state->handler = declClose;
1193 state->role_none = XML_ROLE_ELEMENT_NONE;
1195 return XML_ROLE_GROUP_CLOSE_PLUS;
1196 case XML_TOK_COMMA:
1197 state->handler = element6;
1198 return XML_ROLE_GROUP_SEQUENCE;
1199 case XML_TOK_OR:
1200 state->handler = element6;
1201 return XML_ROLE_GROUP_CHOICE;
1203 return common(state, tok);
1206 #ifdef XML_DTD
1208 static int PTRCALL
1209 condSect0(PROLOG_STATE *state,
1210 int tok,
1211 const char *ptr,
1212 const char *end,
1213 const ENCODING *enc)
1215 switch (tok) {
1216 case XML_TOK_PROLOG_S:
1217 return XML_ROLE_NONE;
1218 case XML_TOK_NAME:
1219 if (XmlNameMatchesAscii(enc, ptr, end, KW_INCLUDE)) {
1220 state->handler = condSect1;
1221 return XML_ROLE_NONE;
1223 if (XmlNameMatchesAscii(enc, ptr, end, KW_IGNORE)) {
1224 state->handler = condSect2;
1225 return XML_ROLE_NONE;
1227 break;
1229 return common(state, tok);
1232 static int PTRCALL
1233 condSect1(PROLOG_STATE *state,
1234 int tok,
1235 const char *ptr,
1236 const char *end,
1237 const ENCODING *enc)
1239 switch (tok) {
1240 case XML_TOK_PROLOG_S:
1241 return XML_ROLE_NONE;
1242 case XML_TOK_OPEN_BRACKET:
1243 state->handler = externalSubset1;
1244 state->includeLevel += 1;
1245 return XML_ROLE_NONE;
1247 return common(state, tok);
1250 static int PTRCALL
1251 condSect2(PROLOG_STATE *state,
1252 int tok,
1253 const char *ptr,
1254 const char *end,
1255 const ENCODING *enc)
1257 switch (tok) {
1258 case XML_TOK_PROLOG_S:
1259 return XML_ROLE_NONE;
1260 case XML_TOK_OPEN_BRACKET:
1261 state->handler = externalSubset1;
1262 return XML_ROLE_IGNORE_SECT;
1264 return common(state, tok);
1267 #endif /* XML_DTD */
1269 static int PTRCALL
1270 declClose(PROLOG_STATE *state,
1271 int tok,
1272 const char *ptr,
1273 const char *end,
1274 const ENCODING *enc)
1276 switch (tok) {
1277 case XML_TOK_PROLOG_S:
1278 return state->role_none;
1279 case XML_TOK_DECL_CLOSE:
1280 setTopLevel(state);
1281 return state->role_none;
1283 return common(state, tok);
1286 static int PTRCALL
1287 error(PROLOG_STATE *state,
1288 int tok,
1289 const char *ptr,
1290 const char *end,
1291 const ENCODING *enc)
1293 return XML_ROLE_NONE;
1296 static int FASTCALL
1297 common(PROLOG_STATE *state, int tok)
1299 #ifdef XML_DTD
1300 if (!state->documentEntity && tok == XML_TOK_PARAM_ENTITY_REF)
1301 return XML_ROLE_INNER_PARAM_ENTITY_REF;
1302 #endif
1303 state->handler = error;
1304 return XML_ROLE_ERROR;
1307 void
1308 XmlPrologStateInit(PROLOG_STATE *state)
1310 state->handler = prolog0;
1311 #ifdef XML_DTD
1312 state->documentEntity = 1;
1313 state->includeLevel = 0;
1314 state->inEntityValue = 0;
1315 #endif /* XML_DTD */
1318 #ifdef XML_DTD
1320 void
1321 XmlPrologStateInitExternalEntity(PROLOG_STATE *state)
1323 state->handler = externalSubset0;
1324 state->documentEntity = 0;
1325 state->includeLevel = 0;
1328 #endif /* XML_DTD */