1 /* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
2 See the file COPYING for copying permission.
7 #ifdef COMPILED_FROM_DSP
9 #elif defined(MACOS_CLASSIC)
10 #include "macconfig.h"
12 #ifdef HAVE_EXPAT_CONFIG_H
13 #include <expat_config.h>
15 #endif /* ndef COMPILED_FROM_DSP */
17 #include "expat_external.h"
24 that ,| are not mixed in a model group
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
,
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
,
67 static const char KW_NOTATION
[] =
68 { ASCII_N
, ASCII_O
, ASCII_T
, ASCII_A
, ASCII_T
, ASCII_I
, ASCII_O
, ASCII_N
,
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
,
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)
85 #define setTopLevel(state) \
86 ((state)->handler = ((state)->documentEntity \
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
,
100 prolog0
, prolog1
, prolog2
,
101 doctype0
, doctype1
, doctype2
, doctype3
, doctype4
, doctype5
,
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
,
111 externalSubset0
, externalSubset1
,
112 condSect0
, condSect1
, condSect2
,
117 static int FASTCALL
common(PROLOG_STATE
*state
, int tok
);
120 prolog0(PROLOG_STATE
*state
,
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
;
134 state
->handler
= prolog1
;
136 case XML_TOK_COMMENT
:
137 state
->handler
= prolog1
;
138 return XML_ROLE_COMMENT
;
140 return XML_ROLE_NONE
;
141 case XML_TOK_DECL_OPEN
:
142 if (!XmlNameMatchesAscii(enc
,
143 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
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
);
157 prolog1(PROLOG_STATE
*state
,
164 case XML_TOK_PROLOG_S
:
165 return XML_ROLE_NONE
;
168 case XML_TOK_COMMENT
:
169 return XML_ROLE_COMMENT
;
171 return XML_ROLE_NONE
;
172 case XML_TOK_DECL_OPEN
:
173 if (!XmlNameMatchesAscii(enc
,
174 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
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
);
188 prolog2(PROLOG_STATE
*state
,
195 case XML_TOK_PROLOG_S
:
196 return XML_ROLE_NONE
;
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
);
209 doctype0(PROLOG_STATE
*state
,
216 case XML_TOK_PROLOG_S
:
217 return XML_ROLE_DOCTYPE_NONE
;
219 case XML_TOK_PREFIXED_NAME
:
220 state
->handler
= doctype1
;
221 return XML_ROLE_DOCTYPE_NAME
;
223 return common(state
, tok
);
227 doctype1(PROLOG_STATE
*state
,
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
;
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
;
253 return common(state
, tok
);
257 doctype2(PROLOG_STATE
*state
,
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
);
274 doctype3(PROLOG_STATE
*state
,
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
);
291 doctype4(PROLOG_STATE
*state
,
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
);
311 doctype5(PROLOG_STATE
*state
,
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
);
328 internalSubset(PROLOG_STATE
*state
,
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
),
342 state
->handler
= entity0
;
343 return XML_ROLE_ENTITY_NONE
;
345 if (XmlNameMatchesAscii(enc
,
346 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
349 state
->handler
= attlist0
;
350 return XML_ROLE_ATTLIST_NONE
;
352 if (XmlNameMatchesAscii(enc
,
353 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
356 state
->handler
= element0
;
357 return XML_ROLE_ELEMENT_NONE
;
359 if (XmlNameMatchesAscii(enc
,
360 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
363 state
->handler
= notation0
;
364 return XML_ROLE_NOTATION_NONE
;
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
;
377 return XML_ROLE_NONE
;
379 return common(state
, tok
);
385 externalSubset0(PROLOG_STATE
*state
,
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
);
398 externalSubset1(PROLOG_STATE
*state
,
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)
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
:
418 if (state
->includeLevel
)
420 return XML_ROLE_NONE
;
422 return internalSubset(state
, tok
, ptr
, end
, enc
);
424 return common(state
, tok
);
430 entity0(PROLOG_STATE
*state
,
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
;
443 state
->handler
= entity2
;
444 return XML_ROLE_GENERAL_ENTITY_NAME
;
446 return common(state
, tok
);
450 entity1(PROLOG_STATE
*state
,
457 case XML_TOK_PROLOG_S
:
458 return XML_ROLE_ENTITY_NONE
;
460 state
->handler
= entity7
;
461 return XML_ROLE_PARAM_ENTITY_NAME
;
463 return common(state
, tok
);
467 entity2(PROLOG_STATE
*state
,
474 case XML_TOK_PROLOG_S
:
475 return XML_ROLE_ENTITY_NONE
;
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
;
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
);
495 entity3(PROLOG_STATE
*state
,
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
);
512 entity4(PROLOG_STATE
*state
,
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
);
529 entity5(PROLOG_STATE
*state
,
536 case XML_TOK_PROLOG_S
:
537 return XML_ROLE_ENTITY_NONE
;
538 case XML_TOK_DECL_CLOSE
:
540 return XML_ROLE_ENTITY_COMPLETE
;
542 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_NDATA
)) {
543 state
->handler
= entity6
;
544 return XML_ROLE_ENTITY_NONE
;
548 return common(state
, tok
);
552 entity6(PROLOG_STATE
*state
,
559 case XML_TOK_PROLOG_S
:
560 return XML_ROLE_ENTITY_NONE
;
562 state
->handler
= declClose
;
563 state
->role_none
= XML_ROLE_ENTITY_NONE
;
564 return XML_ROLE_ENTITY_NOTATION_NAME
;
566 return common(state
, tok
);
570 entity7(PROLOG_STATE
*state
,
577 case XML_TOK_PROLOG_S
:
578 return XML_ROLE_ENTITY_NONE
;
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
;
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
);
598 entity8(PROLOG_STATE
*state
,
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
);
615 entity9(PROLOG_STATE
*state
,
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
);
632 entity10(PROLOG_STATE
*state
,
639 case XML_TOK_PROLOG_S
:
640 return XML_ROLE_ENTITY_NONE
;
641 case XML_TOK_DECL_CLOSE
:
643 return XML_ROLE_ENTITY_COMPLETE
;
645 return common(state
, tok
);
649 notation0(PROLOG_STATE
*state
,
656 case XML_TOK_PROLOG_S
:
657 return XML_ROLE_NOTATION_NONE
;
659 state
->handler
= notation1
;
660 return XML_ROLE_NOTATION_NAME
;
662 return common(state
, tok
);
666 notation1(PROLOG_STATE
*state
,
673 case XML_TOK_PROLOG_S
:
674 return XML_ROLE_NOTATION_NONE
;
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
;
686 return common(state
, tok
);
690 notation2(PROLOG_STATE
*state
,
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
);
707 notation3(PROLOG_STATE
*state
,
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
);
725 notation4(PROLOG_STATE
*state
,
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
:
740 return XML_ROLE_NOTATION_NO_SYSTEM_ID
;
742 return common(state
, tok
);
746 attlist0(PROLOG_STATE
*state
,
753 case XML_TOK_PROLOG_S
:
754 return XML_ROLE_ATTLIST_NONE
;
756 case XML_TOK_PREFIXED_NAME
:
757 state
->handler
= attlist1
;
758 return XML_ROLE_ATTLIST_ELEMENT_NAME
;
760 return common(state
, tok
);
764 attlist1(PROLOG_STATE
*state
,
771 case XML_TOK_PROLOG_S
:
772 return XML_ROLE_ATTLIST_NONE
;
773 case XML_TOK_DECL_CLOSE
:
775 return XML_ROLE_ATTLIST_NONE
;
777 case XML_TOK_PREFIXED_NAME
:
778 state
->handler
= attlist2
;
779 return XML_ROLE_ATTRIBUTE_NAME
;
781 return common(state
, tok
);
785 attlist2(PROLOG_STATE
*state
,
792 case XML_TOK_PROLOG_S
:
793 return XML_ROLE_ATTLIST_NONE
;
796 static const char *types
[] = {
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
;
818 case XML_TOK_OPEN_PAREN
:
819 state
->handler
= attlist3
;
820 return XML_ROLE_ATTLIST_NONE
;
822 return common(state
, tok
);
826 attlist3(PROLOG_STATE
*state
,
833 case XML_TOK_PROLOG_S
:
834 return XML_ROLE_ATTLIST_NONE
;
835 case XML_TOK_NMTOKEN
:
837 case XML_TOK_PREFIXED_NAME
:
838 state
->handler
= attlist4
;
839 return XML_ROLE_ATTRIBUTE_ENUM_VALUE
;
841 return common(state
, tok
);
845 attlist4(PROLOG_STATE
*state
,
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
;
858 state
->handler
= attlist3
;
859 return XML_ROLE_ATTLIST_NONE
;
861 return common(state
, tok
);
865 attlist5(PROLOG_STATE
*state
,
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
);
882 attlist6(PROLOG_STATE
*state
,
889 case XML_TOK_PROLOG_S
:
890 return XML_ROLE_ATTLIST_NONE
;
892 state
->handler
= attlist7
;
893 return XML_ROLE_ATTRIBUTE_NOTATION_VALUE
;
895 return common(state
, tok
);
899 attlist7(PROLOG_STATE
*state
,
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
;
912 state
->handler
= attlist6
;
913 return XML_ROLE_ATTLIST_NONE
;
915 return common(state
, tok
);
920 attlist8(PROLOG_STATE
*state
,
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
),
934 state
->handler
= attlist1
;
935 return XML_ROLE_IMPLIED_ATTRIBUTE_VALUE
;
937 if (XmlNameMatchesAscii(enc
,
938 ptr
+ MIN_BYTES_PER_CHAR(enc
),
941 state
->handler
= attlist1
;
942 return XML_ROLE_REQUIRED_ATTRIBUTE_VALUE
;
944 if (XmlNameMatchesAscii(enc
,
945 ptr
+ MIN_BYTES_PER_CHAR(enc
),
948 state
->handler
= attlist9
;
949 return XML_ROLE_ATTLIST_NONE
;
952 case XML_TOK_LITERAL
:
953 state
->handler
= attlist1
;
954 return XML_ROLE_DEFAULT_ATTRIBUTE_VALUE
;
956 return common(state
, tok
);
960 attlist9(PROLOG_STATE
*state
,
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
);
977 element0(PROLOG_STATE
*state
,
984 case XML_TOK_PROLOG_S
:
985 return XML_ROLE_ELEMENT_NONE
;
987 case XML_TOK_PREFIXED_NAME
:
988 state
->handler
= element1
;
989 return XML_ROLE_ELEMENT_NAME
;
991 return common(state
, tok
);
995 element1(PROLOG_STATE
*state
,
1002 case XML_TOK_PROLOG_S
:
1003 return XML_ROLE_ELEMENT_NONE
;
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
;
1016 case XML_TOK_OPEN_PAREN
:
1017 state
->handler
= element2
;
1019 return XML_ROLE_GROUP_OPEN
;
1021 return common(state
, tok
);
1025 element2(PROLOG_STATE
*state
,
1029 const ENCODING
*enc
)
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
),
1039 state
->handler
= element3
;
1040 return XML_ROLE_CONTENT_PCDATA
;
1043 case XML_TOK_OPEN_PAREN
:
1045 state
->handler
= element6
;
1046 return XML_ROLE_GROUP_OPEN
;
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
);
1065 element3(PROLOG_STATE
*state
,
1069 const ENCODING
*enc
)
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
;
1083 state
->handler
= element4
;
1084 return XML_ROLE_ELEMENT_NONE
;
1086 return common(state
, tok
);
1090 element4(PROLOG_STATE
*state
,
1094 const ENCODING
*enc
)
1097 case XML_TOK_PROLOG_S
:
1098 return XML_ROLE_ELEMENT_NONE
;
1100 case XML_TOK_PREFIXED_NAME
:
1101 state
->handler
= element5
;
1102 return XML_ROLE_CONTENT_ELEMENT
;
1104 return common(state
, tok
);
1108 element5(PROLOG_STATE
*state
,
1112 const ENCODING
*enc
)
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
;
1122 state
->handler
= element4
;
1123 return XML_ROLE_ELEMENT_NONE
;
1125 return common(state
, tok
);
1129 element6(PROLOG_STATE
*state
,
1133 const ENCODING
*enc
)
1136 case XML_TOK_PROLOG_S
:
1137 return XML_ROLE_ELEMENT_NONE
;
1138 case XML_TOK_OPEN_PAREN
:
1140 return XML_ROLE_GROUP_OPEN
;
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
);
1159 element7(PROLOG_STATE
*state
,
1163 const ENCODING
*enc
)
1166 case XML_TOK_PROLOG_S
:
1167 return XML_ROLE_ELEMENT_NONE
;
1168 case XML_TOK_CLOSE_PAREN
:
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
:
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
:
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
:
1191 if (state
->level
== 0) {
1192 state
->handler
= declClose
;
1193 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1195 return XML_ROLE_GROUP_CLOSE_PLUS
;
1197 state
->handler
= element6
;
1198 return XML_ROLE_GROUP_SEQUENCE
;
1200 state
->handler
= element6
;
1201 return XML_ROLE_GROUP_CHOICE
;
1203 return common(state
, tok
);
1209 condSect0(PROLOG_STATE
*state
,
1213 const ENCODING
*enc
)
1216 case XML_TOK_PROLOG_S
:
1217 return XML_ROLE_NONE
;
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
;
1229 return common(state
, tok
);
1233 condSect1(PROLOG_STATE
*state
,
1237 const ENCODING
*enc
)
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
);
1251 condSect2(PROLOG_STATE
*state
,
1255 const ENCODING
*enc
)
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 */
1270 declClose(PROLOG_STATE
*state
,
1274 const ENCODING
*enc
)
1277 case XML_TOK_PROLOG_S
:
1278 return state
->role_none
;
1279 case XML_TOK_DECL_CLOSE
:
1281 return state
->role_none
;
1283 return common(state
, tok
);
1287 error(PROLOG_STATE
*state
,
1291 const ENCODING
*enc
)
1293 return XML_ROLE_NONE
;
1297 common(PROLOG_STATE
*state
, int tok
)
1300 if (!state
->documentEntity
&& tok
== XML_TOK_PARAM_ENTITY_REF
)
1301 return XML_ROLE_INNER_PARAM_ENTITY_REF
;
1303 state
->handler
= error
;
1304 return XML_ROLE_ERROR
;
1308 XmlPrologStateInit(PROLOG_STATE
*state
)
1310 state
->handler
= prolog0
;
1312 state
->documentEntity
= 1;
1313 state
->includeLevel
= 0;
1314 state
->inEntityValue
= 0;
1315 #endif /* XML_DTD */
1321 XmlPrologStateInitExternalEntity(PROLOG_STATE
*state
)
1323 state
->handler
= externalSubset0
;
1324 state
->documentEntity
= 0;
1325 state
->includeLevel
= 0;
1328 #endif /* XML_DTD */