1 /* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
2 See the file COPYING for copying permission.
5 #ifdef COMPILED_FROM_DSP
9 #elif defined(__MSDOS__)
10 #include "dosconfig.h"
11 #elif defined(MACOS_CLASSIC)
12 #include "macconfig.h"
14 #include "expat_config.h"
15 #endif /* ndef COMPILED_FROM_DSP */
23 that ,| are not mixed in a model group
28 static const char KW_ANY
[] = {
29 ASCII_A
, ASCII_N
, ASCII_Y
, '\0' };
30 static const char KW_ATTLIST
[] = {
31 ASCII_A
, ASCII_T
, ASCII_T
, ASCII_L
, ASCII_I
, ASCII_S
, ASCII_T
, '\0' };
32 static const char KW_CDATA
[] = {
33 ASCII_C
, ASCII_D
, ASCII_A
, ASCII_T
, ASCII_A
, '\0' };
34 static const char KW_DOCTYPE
[] = {
35 ASCII_D
, ASCII_O
, ASCII_C
, ASCII_T
, ASCII_Y
, ASCII_P
, ASCII_E
, '\0' };
36 static const char KW_ELEMENT
[] = {
37 ASCII_E
, ASCII_L
, ASCII_E
, ASCII_M
, ASCII_E
, ASCII_N
, ASCII_T
, '\0' };
38 static const char KW_EMPTY
[] = {
39 ASCII_E
, ASCII_M
, ASCII_P
, ASCII_T
, ASCII_Y
, '\0' };
40 static const char KW_ENTITIES
[] = {
41 ASCII_E
, ASCII_N
, ASCII_T
, ASCII_I
, ASCII_T
, ASCII_I
, ASCII_E
, ASCII_S
,
43 static const char KW_ENTITY
[] = {
44 ASCII_E
, ASCII_N
, ASCII_T
, ASCII_I
, ASCII_T
, ASCII_Y
, '\0' };
45 static const char KW_FIXED
[] = {
46 ASCII_F
, ASCII_I
, ASCII_X
, ASCII_E
, ASCII_D
, '\0' };
47 static const char KW_ID
[] = {
48 ASCII_I
, ASCII_D
, '\0' };
49 static const char KW_IDREF
[] = {
50 ASCII_I
, ASCII_D
, ASCII_R
, ASCII_E
, ASCII_F
, '\0' };
51 static const char KW_IDREFS
[] = {
52 ASCII_I
, ASCII_D
, ASCII_R
, ASCII_E
, ASCII_F
, ASCII_S
, '\0' };
53 static const char KW_IGNORE
[] = {
54 ASCII_I
, ASCII_G
, ASCII_N
, ASCII_O
, ASCII_R
, ASCII_E
, '\0' };
55 static const char KW_IMPLIED
[] = {
56 ASCII_I
, ASCII_M
, ASCII_P
, ASCII_L
, ASCII_I
, ASCII_E
, ASCII_D
, '\0' };
57 static const char KW_INCLUDE
[] = {
58 ASCII_I
, ASCII_N
, ASCII_C
, ASCII_L
, ASCII_U
, ASCII_D
, ASCII_E
, '\0' };
59 static const char KW_NDATA
[] = {
60 ASCII_N
, ASCII_D
, ASCII_A
, ASCII_T
, ASCII_A
, '\0' };
61 static const char KW_NMTOKEN
[] = {
62 ASCII_N
, ASCII_M
, ASCII_T
, ASCII_O
, ASCII_K
, ASCII_E
, ASCII_N
, '\0' };
63 static const char KW_NMTOKENS
[] = {
64 ASCII_N
, ASCII_M
, ASCII_T
, ASCII_O
, ASCII_K
, ASCII_E
, ASCII_N
, ASCII_S
,
66 static const char KW_NOTATION
[] =
67 { ASCII_N
, ASCII_O
, ASCII_T
, ASCII_A
, ASCII_T
, ASCII_I
, ASCII_O
, ASCII_N
,
69 static const char KW_PCDATA
[] = {
70 ASCII_P
, ASCII_C
, ASCII_D
, ASCII_A
, ASCII_T
, ASCII_A
, '\0' };
71 static const char KW_PUBLIC
[] = {
72 ASCII_P
, ASCII_U
, ASCII_B
, ASCII_L
, ASCII_I
, ASCII_C
, '\0' };
73 static const char KW_REQUIRED
[] = {
74 ASCII_R
, ASCII_E
, ASCII_Q
, ASCII_U
, ASCII_I
, ASCII_R
, ASCII_E
, ASCII_D
,
76 static const char KW_SYSTEM
[] = {
77 ASCII_S
, ASCII_Y
, ASCII_S
, ASCII_T
, ASCII_E
, ASCII_M
, '\0' };
79 #ifndef MIN_BYTES_PER_CHAR
80 #define MIN_BYTES_PER_CHAR(enc) ((enc)->minBytesPerChar)
84 #define setTopLevel(state) \
85 ((state)->handler = ((state)->documentEntity \
88 #else /* not XML_DTD */
89 #define setTopLevel(state) ((state)->handler = internalSubset)
90 #endif /* not XML_DTD */
92 typedef int PTRCALL
PROLOG_HANDLER(PROLOG_STATE
*state
,
99 prolog0
, prolog1
, prolog2
,
100 doctype0
, doctype1
, doctype2
, doctype3
, doctype4
, doctype5
,
102 entity0
, entity1
, entity2
, entity3
, entity4
, entity5
, entity6
,
103 entity7
, entity8
, entity9
, entity10
,
104 notation0
, notation1
, notation2
, notation3
, notation4
,
105 attlist0
, attlist1
, attlist2
, attlist3
, attlist4
, attlist5
, attlist6
,
106 attlist7
, attlist8
, attlist9
,
107 element0
, element1
, element2
, element3
, element4
, element5
, element6
,
110 externalSubset0
, externalSubset1
,
111 condSect0
, condSect1
, condSect2
,
116 static int FASTCALL
common(PROLOG_STATE
*state
, int tok
);
119 prolog0(PROLOG_STATE
*state
,
126 case XML_TOK_PROLOG_S
:
127 state
->handler
= prolog1
;
128 return XML_ROLE_NONE
;
129 case XML_TOK_XML_DECL
:
130 state
->handler
= prolog1
;
131 return XML_ROLE_XML_DECL
;
133 state
->handler
= prolog1
;
135 case XML_TOK_COMMENT
:
136 state
->handler
= prolog1
;
137 return XML_ROLE_COMMENT
;
139 return XML_ROLE_NONE
;
140 case XML_TOK_DECL_OPEN
:
141 if (!XmlNameMatchesAscii(enc
,
142 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
146 state
->handler
= doctype0
;
147 return XML_ROLE_DOCTYPE_NONE
;
148 case XML_TOK_INSTANCE_START
:
149 state
->handler
= error
;
150 return XML_ROLE_INSTANCE_START
;
152 return common(state
, tok
);
156 prolog1(PROLOG_STATE
*state
,
163 case XML_TOK_PROLOG_S
:
164 return XML_ROLE_NONE
;
167 case XML_TOK_COMMENT
:
168 return XML_ROLE_COMMENT
;
170 return XML_ROLE_NONE
;
171 case XML_TOK_DECL_OPEN
:
172 if (!XmlNameMatchesAscii(enc
,
173 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
177 state
->handler
= doctype0
;
178 return XML_ROLE_DOCTYPE_NONE
;
179 case XML_TOK_INSTANCE_START
:
180 state
->handler
= error
;
181 return XML_ROLE_INSTANCE_START
;
183 return common(state
, tok
);
187 prolog2(PROLOG_STATE
*state
,
194 case XML_TOK_PROLOG_S
:
195 return XML_ROLE_NONE
;
198 case XML_TOK_COMMENT
:
199 return XML_ROLE_COMMENT
;
200 case XML_TOK_INSTANCE_START
:
201 state
->handler
= error
;
202 return XML_ROLE_INSTANCE_START
;
204 return common(state
, tok
);
208 doctype0(PROLOG_STATE
*state
,
215 case XML_TOK_PROLOG_S
:
216 return XML_ROLE_DOCTYPE_NONE
;
218 case XML_TOK_PREFIXED_NAME
:
219 state
->handler
= doctype1
;
220 return XML_ROLE_DOCTYPE_NAME
;
222 return common(state
, tok
);
226 doctype1(PROLOG_STATE
*state
,
233 case XML_TOK_PROLOG_S
:
234 return XML_ROLE_DOCTYPE_NONE
;
235 case XML_TOK_OPEN_BRACKET
:
236 state
->handler
= internalSubset
;
237 return XML_ROLE_DOCTYPE_INTERNAL_SUBSET
;
238 case XML_TOK_DECL_CLOSE
:
239 state
->handler
= prolog2
;
240 return XML_ROLE_DOCTYPE_CLOSE
;
242 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_SYSTEM
)) {
243 state
->handler
= doctype3
;
244 return XML_ROLE_DOCTYPE_NONE
;
246 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_PUBLIC
)) {
247 state
->handler
= doctype2
;
248 return XML_ROLE_DOCTYPE_NONE
;
252 return common(state
, tok
);
256 doctype2(PROLOG_STATE
*state
,
263 case XML_TOK_PROLOG_S
:
264 return XML_ROLE_DOCTYPE_NONE
;
265 case XML_TOK_LITERAL
:
266 state
->handler
= doctype3
;
267 return XML_ROLE_DOCTYPE_PUBLIC_ID
;
269 return common(state
, tok
);
273 doctype3(PROLOG_STATE
*state
,
280 case XML_TOK_PROLOG_S
:
281 return XML_ROLE_DOCTYPE_NONE
;
282 case XML_TOK_LITERAL
:
283 state
->handler
= doctype4
;
284 return XML_ROLE_DOCTYPE_SYSTEM_ID
;
286 return common(state
, tok
);
290 doctype4(PROLOG_STATE
*state
,
297 case XML_TOK_PROLOG_S
:
298 return XML_ROLE_DOCTYPE_NONE
;
299 case XML_TOK_OPEN_BRACKET
:
300 state
->handler
= internalSubset
;
301 return XML_ROLE_DOCTYPE_INTERNAL_SUBSET
;
302 case XML_TOK_DECL_CLOSE
:
303 state
->handler
= prolog2
;
304 return XML_ROLE_DOCTYPE_CLOSE
;
306 return common(state
, tok
);
310 doctype5(PROLOG_STATE
*state
,
317 case XML_TOK_PROLOG_S
:
318 return XML_ROLE_DOCTYPE_NONE
;
319 case XML_TOK_DECL_CLOSE
:
320 state
->handler
= prolog2
;
321 return XML_ROLE_DOCTYPE_CLOSE
;
323 return common(state
, tok
);
327 internalSubset(PROLOG_STATE
*state
,
334 case XML_TOK_PROLOG_S
:
335 return XML_ROLE_NONE
;
336 case XML_TOK_DECL_OPEN
:
337 if (XmlNameMatchesAscii(enc
,
338 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
341 state
->handler
= entity0
;
342 return XML_ROLE_ENTITY_NONE
;
344 if (XmlNameMatchesAscii(enc
,
345 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
348 state
->handler
= attlist0
;
349 return XML_ROLE_ATTLIST_NONE
;
351 if (XmlNameMatchesAscii(enc
,
352 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
355 state
->handler
= element0
;
356 return XML_ROLE_ELEMENT_NONE
;
358 if (XmlNameMatchesAscii(enc
,
359 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
362 state
->handler
= notation0
;
363 return XML_ROLE_NOTATION_NONE
;
368 case XML_TOK_COMMENT
:
369 return XML_ROLE_COMMENT
;
370 case XML_TOK_PARAM_ENTITY_REF
:
371 return XML_ROLE_PARAM_ENTITY_REF
;
372 case XML_TOK_CLOSE_BRACKET
:
373 state
->handler
= doctype5
;
374 return XML_ROLE_DOCTYPE_NONE
;
376 return common(state
, tok
);
382 externalSubset0(PROLOG_STATE
*state
,
388 state
->handler
= externalSubset1
;
389 if (tok
== XML_TOK_XML_DECL
)
390 return XML_ROLE_TEXT_DECL
;
391 return externalSubset1(state
, tok
, ptr
, end
, enc
);
395 externalSubset1(PROLOG_STATE
*state
,
402 case XML_TOK_COND_SECT_OPEN
:
403 state
->handler
= condSect0
;
404 return XML_ROLE_NONE
;
405 case XML_TOK_COND_SECT_CLOSE
:
406 if (state
->includeLevel
== 0)
408 state
->includeLevel
-= 1;
409 return XML_ROLE_NONE
;
410 case XML_TOK_PROLOG_S
:
411 return XML_ROLE_NONE
;
412 case XML_TOK_CLOSE_BRACKET
:
415 if (state
->includeLevel
)
417 return XML_ROLE_NONE
;
419 return internalSubset(state
, tok
, ptr
, end
, enc
);
421 return common(state
, tok
);
427 entity0(PROLOG_STATE
*state
,
434 case XML_TOK_PROLOG_S
:
435 return XML_ROLE_ENTITY_NONE
;
436 case XML_TOK_PERCENT
:
437 state
->handler
= entity1
;
438 return XML_ROLE_ENTITY_NONE
;
440 state
->handler
= entity2
;
441 return XML_ROLE_GENERAL_ENTITY_NAME
;
443 return common(state
, tok
);
447 entity1(PROLOG_STATE
*state
,
454 case XML_TOK_PROLOG_S
:
455 return XML_ROLE_ENTITY_NONE
;
457 state
->handler
= entity7
;
458 return XML_ROLE_PARAM_ENTITY_NAME
;
460 return common(state
, tok
);
464 entity2(PROLOG_STATE
*state
,
471 case XML_TOK_PROLOG_S
:
472 return XML_ROLE_ENTITY_NONE
;
474 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_SYSTEM
)) {
475 state
->handler
= entity4
;
476 return XML_ROLE_ENTITY_NONE
;
478 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_PUBLIC
)) {
479 state
->handler
= entity3
;
480 return XML_ROLE_ENTITY_NONE
;
483 case XML_TOK_LITERAL
:
484 state
->handler
= declClose
;
485 state
->role_none
= XML_ROLE_ENTITY_NONE
;
486 return XML_ROLE_ENTITY_VALUE
;
488 return common(state
, tok
);
492 entity3(PROLOG_STATE
*state
,
499 case XML_TOK_PROLOG_S
:
500 return XML_ROLE_ENTITY_NONE
;
501 case XML_TOK_LITERAL
:
502 state
->handler
= entity4
;
503 return XML_ROLE_ENTITY_PUBLIC_ID
;
505 return common(state
, tok
);
509 entity4(PROLOG_STATE
*state
,
516 case XML_TOK_PROLOG_S
:
517 return XML_ROLE_ENTITY_NONE
;
518 case XML_TOK_LITERAL
:
519 state
->handler
= entity5
;
520 return XML_ROLE_ENTITY_SYSTEM_ID
;
522 return common(state
, tok
);
526 entity5(PROLOG_STATE
*state
,
533 case XML_TOK_PROLOG_S
:
534 return XML_ROLE_ENTITY_NONE
;
535 case XML_TOK_DECL_CLOSE
:
537 return XML_ROLE_ENTITY_COMPLETE
;
539 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_NDATA
)) {
540 state
->handler
= entity6
;
541 return XML_ROLE_ENTITY_NONE
;
545 return common(state
, tok
);
549 entity6(PROLOG_STATE
*state
,
556 case XML_TOK_PROLOG_S
:
557 return XML_ROLE_ENTITY_NONE
;
559 state
->handler
= declClose
;
560 state
->role_none
= XML_ROLE_ENTITY_NONE
;
561 return XML_ROLE_ENTITY_NOTATION_NAME
;
563 return common(state
, tok
);
567 entity7(PROLOG_STATE
*state
,
574 case XML_TOK_PROLOG_S
:
575 return XML_ROLE_ENTITY_NONE
;
577 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_SYSTEM
)) {
578 state
->handler
= entity9
;
579 return XML_ROLE_ENTITY_NONE
;
581 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_PUBLIC
)) {
582 state
->handler
= entity8
;
583 return XML_ROLE_ENTITY_NONE
;
586 case XML_TOK_LITERAL
:
587 state
->handler
= declClose
;
588 state
->role_none
= XML_ROLE_ENTITY_NONE
;
589 return XML_ROLE_ENTITY_VALUE
;
591 return common(state
, tok
);
595 entity8(PROLOG_STATE
*state
,
602 case XML_TOK_PROLOG_S
:
603 return XML_ROLE_ENTITY_NONE
;
604 case XML_TOK_LITERAL
:
605 state
->handler
= entity9
;
606 return XML_ROLE_ENTITY_PUBLIC_ID
;
608 return common(state
, tok
);
612 entity9(PROLOG_STATE
*state
,
619 case XML_TOK_PROLOG_S
:
620 return XML_ROLE_ENTITY_NONE
;
621 case XML_TOK_LITERAL
:
622 state
->handler
= entity10
;
623 return XML_ROLE_ENTITY_SYSTEM_ID
;
625 return common(state
, tok
);
629 entity10(PROLOG_STATE
*state
,
636 case XML_TOK_PROLOG_S
:
637 return XML_ROLE_ENTITY_NONE
;
638 case XML_TOK_DECL_CLOSE
:
640 return XML_ROLE_ENTITY_COMPLETE
;
642 return common(state
, tok
);
646 notation0(PROLOG_STATE
*state
,
653 case XML_TOK_PROLOG_S
:
654 return XML_ROLE_NOTATION_NONE
;
656 state
->handler
= notation1
;
657 return XML_ROLE_NOTATION_NAME
;
659 return common(state
, tok
);
663 notation1(PROLOG_STATE
*state
,
670 case XML_TOK_PROLOG_S
:
671 return XML_ROLE_NOTATION_NONE
;
673 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_SYSTEM
)) {
674 state
->handler
= notation3
;
675 return XML_ROLE_NOTATION_NONE
;
677 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_PUBLIC
)) {
678 state
->handler
= notation2
;
679 return XML_ROLE_NOTATION_NONE
;
683 return common(state
, tok
);
687 notation2(PROLOG_STATE
*state
,
694 case XML_TOK_PROLOG_S
:
695 return XML_ROLE_NOTATION_NONE
;
696 case XML_TOK_LITERAL
:
697 state
->handler
= notation4
;
698 return XML_ROLE_NOTATION_PUBLIC_ID
;
700 return common(state
, tok
);
704 notation3(PROLOG_STATE
*state
,
711 case XML_TOK_PROLOG_S
:
712 return XML_ROLE_NOTATION_NONE
;
713 case XML_TOK_LITERAL
:
714 state
->handler
= declClose
;
715 state
->role_none
= XML_ROLE_NOTATION_NONE
;
716 return XML_ROLE_NOTATION_SYSTEM_ID
;
718 return common(state
, tok
);
722 notation4(PROLOG_STATE
*state
,
729 case XML_TOK_PROLOG_S
:
730 return XML_ROLE_NOTATION_NONE
;
731 case XML_TOK_LITERAL
:
732 state
->handler
= declClose
;
733 state
->role_none
= XML_ROLE_NOTATION_NONE
;
734 return XML_ROLE_NOTATION_SYSTEM_ID
;
735 case XML_TOK_DECL_CLOSE
:
737 return XML_ROLE_NOTATION_NO_SYSTEM_ID
;
739 return common(state
, tok
);
743 attlist0(PROLOG_STATE
*state
,
750 case XML_TOK_PROLOG_S
:
751 return XML_ROLE_ATTLIST_NONE
;
753 case XML_TOK_PREFIXED_NAME
:
754 state
->handler
= attlist1
;
755 return XML_ROLE_ATTLIST_ELEMENT_NAME
;
757 return common(state
, tok
);
761 attlist1(PROLOG_STATE
*state
,
768 case XML_TOK_PROLOG_S
:
769 return XML_ROLE_ATTLIST_NONE
;
770 case XML_TOK_DECL_CLOSE
:
772 return XML_ROLE_ATTLIST_NONE
;
774 case XML_TOK_PREFIXED_NAME
:
775 state
->handler
= attlist2
;
776 return XML_ROLE_ATTRIBUTE_NAME
;
778 return common(state
, tok
);
782 attlist2(PROLOG_STATE
*state
,
789 case XML_TOK_PROLOG_S
:
790 return XML_ROLE_ATTLIST_NONE
;
793 static const char *types
[] = {
804 for (i
= 0; i
< (int)(sizeof(types
)/sizeof(types
[0])); i
++)
805 if (XmlNameMatchesAscii(enc
, ptr
, end
, types
[i
])) {
806 state
->handler
= attlist8
;
807 return XML_ROLE_ATTRIBUTE_TYPE_CDATA
+ i
;
810 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_NOTATION
)) {
811 state
->handler
= attlist5
;
812 return XML_ROLE_ATTLIST_NONE
;
815 case XML_TOK_OPEN_PAREN
:
816 state
->handler
= attlist3
;
817 return XML_ROLE_ATTLIST_NONE
;
819 return common(state
, tok
);
823 attlist3(PROLOG_STATE
*state
,
830 case XML_TOK_PROLOG_S
:
831 return XML_ROLE_ATTLIST_NONE
;
832 case XML_TOK_NMTOKEN
:
834 case XML_TOK_PREFIXED_NAME
:
835 state
->handler
= attlist4
;
836 return XML_ROLE_ATTRIBUTE_ENUM_VALUE
;
838 return common(state
, tok
);
842 attlist4(PROLOG_STATE
*state
,
849 case XML_TOK_PROLOG_S
:
850 return XML_ROLE_ATTLIST_NONE
;
851 case XML_TOK_CLOSE_PAREN
:
852 state
->handler
= attlist8
;
853 return XML_ROLE_ATTLIST_NONE
;
855 state
->handler
= attlist3
;
856 return XML_ROLE_ATTLIST_NONE
;
858 return common(state
, tok
);
862 attlist5(PROLOG_STATE
*state
,
869 case XML_TOK_PROLOG_S
:
870 return XML_ROLE_ATTLIST_NONE
;
871 case XML_TOK_OPEN_PAREN
:
872 state
->handler
= attlist6
;
873 return XML_ROLE_ATTLIST_NONE
;
875 return common(state
, tok
);
879 attlist6(PROLOG_STATE
*state
,
886 case XML_TOK_PROLOG_S
:
887 return XML_ROLE_ATTLIST_NONE
;
889 state
->handler
= attlist7
;
890 return XML_ROLE_ATTRIBUTE_NOTATION_VALUE
;
892 return common(state
, tok
);
896 attlist7(PROLOG_STATE
*state
,
903 case XML_TOK_PROLOG_S
:
904 return XML_ROLE_ATTLIST_NONE
;
905 case XML_TOK_CLOSE_PAREN
:
906 state
->handler
= attlist8
;
907 return XML_ROLE_ATTLIST_NONE
;
909 state
->handler
= attlist6
;
910 return XML_ROLE_ATTLIST_NONE
;
912 return common(state
, tok
);
917 attlist8(PROLOG_STATE
*state
,
924 case XML_TOK_PROLOG_S
:
925 return XML_ROLE_ATTLIST_NONE
;
926 case XML_TOK_POUND_NAME
:
927 if (XmlNameMatchesAscii(enc
,
928 ptr
+ MIN_BYTES_PER_CHAR(enc
),
931 state
->handler
= attlist1
;
932 return XML_ROLE_IMPLIED_ATTRIBUTE_VALUE
;
934 if (XmlNameMatchesAscii(enc
,
935 ptr
+ MIN_BYTES_PER_CHAR(enc
),
938 state
->handler
= attlist1
;
939 return XML_ROLE_REQUIRED_ATTRIBUTE_VALUE
;
941 if (XmlNameMatchesAscii(enc
,
942 ptr
+ MIN_BYTES_PER_CHAR(enc
),
945 state
->handler
= attlist9
;
946 return XML_ROLE_ATTLIST_NONE
;
949 case XML_TOK_LITERAL
:
950 state
->handler
= attlist1
;
951 return XML_ROLE_DEFAULT_ATTRIBUTE_VALUE
;
953 return common(state
, tok
);
957 attlist9(PROLOG_STATE
*state
,
964 case XML_TOK_PROLOG_S
:
965 return XML_ROLE_ATTLIST_NONE
;
966 case XML_TOK_LITERAL
:
967 state
->handler
= attlist1
;
968 return XML_ROLE_FIXED_ATTRIBUTE_VALUE
;
970 return common(state
, tok
);
974 element0(PROLOG_STATE
*state
,
981 case XML_TOK_PROLOG_S
:
982 return XML_ROLE_ELEMENT_NONE
;
984 case XML_TOK_PREFIXED_NAME
:
985 state
->handler
= element1
;
986 return XML_ROLE_ELEMENT_NAME
;
988 return common(state
, tok
);
992 element1(PROLOG_STATE
*state
,
999 case XML_TOK_PROLOG_S
:
1000 return XML_ROLE_ELEMENT_NONE
;
1002 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_EMPTY
)) {
1003 state
->handler
= declClose
;
1004 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1005 return XML_ROLE_CONTENT_EMPTY
;
1007 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_ANY
)) {
1008 state
->handler
= declClose
;
1009 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1010 return XML_ROLE_CONTENT_ANY
;
1013 case XML_TOK_OPEN_PAREN
:
1014 state
->handler
= element2
;
1016 return XML_ROLE_GROUP_OPEN
;
1018 return common(state
, tok
);
1022 element2(PROLOG_STATE
*state
,
1026 const ENCODING
*enc
)
1029 case XML_TOK_PROLOG_S
:
1030 return XML_ROLE_ELEMENT_NONE
;
1031 case XML_TOK_POUND_NAME
:
1032 if (XmlNameMatchesAscii(enc
,
1033 ptr
+ MIN_BYTES_PER_CHAR(enc
),
1036 state
->handler
= element3
;
1037 return XML_ROLE_CONTENT_PCDATA
;
1040 case XML_TOK_OPEN_PAREN
:
1042 state
->handler
= element6
;
1043 return XML_ROLE_GROUP_OPEN
;
1045 case XML_TOK_PREFIXED_NAME
:
1046 state
->handler
= element7
;
1047 return XML_ROLE_CONTENT_ELEMENT
;
1048 case XML_TOK_NAME_QUESTION
:
1049 state
->handler
= element7
;
1050 return XML_ROLE_CONTENT_ELEMENT_OPT
;
1051 case XML_TOK_NAME_ASTERISK
:
1052 state
->handler
= element7
;
1053 return XML_ROLE_CONTENT_ELEMENT_REP
;
1054 case XML_TOK_NAME_PLUS
:
1055 state
->handler
= element7
;
1056 return XML_ROLE_CONTENT_ELEMENT_PLUS
;
1058 return common(state
, tok
);
1062 element3(PROLOG_STATE
*state
,
1066 const ENCODING
*enc
)
1069 case XML_TOK_PROLOG_S
:
1070 return XML_ROLE_ELEMENT_NONE
;
1071 case XML_TOK_CLOSE_PAREN
:
1072 state
->handler
= declClose
;
1073 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1074 return XML_ROLE_GROUP_CLOSE
;
1075 case XML_TOK_CLOSE_PAREN_ASTERISK
:
1076 state
->handler
= declClose
;
1077 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1078 return XML_ROLE_GROUP_CLOSE_REP
;
1080 state
->handler
= element4
;
1081 return XML_ROLE_ELEMENT_NONE
;
1083 return common(state
, tok
);
1087 element4(PROLOG_STATE
*state
,
1091 const ENCODING
*enc
)
1094 case XML_TOK_PROLOG_S
:
1095 return XML_ROLE_ELEMENT_NONE
;
1097 case XML_TOK_PREFIXED_NAME
:
1098 state
->handler
= element5
;
1099 return XML_ROLE_CONTENT_ELEMENT
;
1101 return common(state
, tok
);
1105 element5(PROLOG_STATE
*state
,
1109 const ENCODING
*enc
)
1112 case XML_TOK_PROLOG_S
:
1113 return XML_ROLE_ELEMENT_NONE
;
1114 case XML_TOK_CLOSE_PAREN_ASTERISK
:
1115 state
->handler
= declClose
;
1116 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1117 return XML_ROLE_GROUP_CLOSE_REP
;
1119 state
->handler
= element4
;
1120 return XML_ROLE_ELEMENT_NONE
;
1122 return common(state
, tok
);
1126 element6(PROLOG_STATE
*state
,
1130 const ENCODING
*enc
)
1133 case XML_TOK_PROLOG_S
:
1134 return XML_ROLE_ELEMENT_NONE
;
1135 case XML_TOK_OPEN_PAREN
:
1137 return XML_ROLE_GROUP_OPEN
;
1139 case XML_TOK_PREFIXED_NAME
:
1140 state
->handler
= element7
;
1141 return XML_ROLE_CONTENT_ELEMENT
;
1142 case XML_TOK_NAME_QUESTION
:
1143 state
->handler
= element7
;
1144 return XML_ROLE_CONTENT_ELEMENT_OPT
;
1145 case XML_TOK_NAME_ASTERISK
:
1146 state
->handler
= element7
;
1147 return XML_ROLE_CONTENT_ELEMENT_REP
;
1148 case XML_TOK_NAME_PLUS
:
1149 state
->handler
= element7
;
1150 return XML_ROLE_CONTENT_ELEMENT_PLUS
;
1152 return common(state
, tok
);
1156 element7(PROLOG_STATE
*state
,
1160 const ENCODING
*enc
)
1163 case XML_TOK_PROLOG_S
:
1164 return XML_ROLE_ELEMENT_NONE
;
1165 case XML_TOK_CLOSE_PAREN
:
1167 if (state
->level
== 0) {
1168 state
->handler
= declClose
;
1169 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1171 return XML_ROLE_GROUP_CLOSE
;
1172 case XML_TOK_CLOSE_PAREN_ASTERISK
:
1174 if (state
->level
== 0) {
1175 state
->handler
= declClose
;
1176 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1178 return XML_ROLE_GROUP_CLOSE_REP
;
1179 case XML_TOK_CLOSE_PAREN_QUESTION
:
1181 if (state
->level
== 0) {
1182 state
->handler
= declClose
;
1183 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1185 return XML_ROLE_GROUP_CLOSE_OPT
;
1186 case XML_TOK_CLOSE_PAREN_PLUS
:
1188 if (state
->level
== 0) {
1189 state
->handler
= declClose
;
1190 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1192 return XML_ROLE_GROUP_CLOSE_PLUS
;
1194 state
->handler
= element6
;
1195 return XML_ROLE_GROUP_SEQUENCE
;
1197 state
->handler
= element6
;
1198 return XML_ROLE_GROUP_CHOICE
;
1200 return common(state
, tok
);
1206 condSect0(PROLOG_STATE
*state
,
1210 const ENCODING
*enc
)
1213 case XML_TOK_PROLOG_S
:
1214 return XML_ROLE_NONE
;
1216 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_INCLUDE
)) {
1217 state
->handler
= condSect1
;
1218 return XML_ROLE_NONE
;
1220 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_IGNORE
)) {
1221 state
->handler
= condSect2
;
1222 return XML_ROLE_NONE
;
1226 return common(state
, tok
);
1230 condSect1(PROLOG_STATE
*state
,
1234 const ENCODING
*enc
)
1237 case XML_TOK_PROLOG_S
:
1238 return XML_ROLE_NONE
;
1239 case XML_TOK_OPEN_BRACKET
:
1240 state
->handler
= externalSubset1
;
1241 state
->includeLevel
+= 1;
1242 return XML_ROLE_NONE
;
1244 return common(state
, tok
);
1248 condSect2(PROLOG_STATE
*state
,
1252 const ENCODING
*enc
)
1255 case XML_TOK_PROLOG_S
:
1256 return XML_ROLE_NONE
;
1257 case XML_TOK_OPEN_BRACKET
:
1258 state
->handler
= externalSubset1
;
1259 return XML_ROLE_IGNORE_SECT
;
1261 return common(state
, tok
);
1264 #endif /* XML_DTD */
1267 declClose(PROLOG_STATE
*state
,
1271 const ENCODING
*enc
)
1274 case XML_TOK_PROLOG_S
:
1275 return state
->role_none
;
1276 case XML_TOK_DECL_CLOSE
:
1278 return state
->role_none
;
1280 return common(state
, tok
);
1284 error(PROLOG_STATE
*state
,
1288 const ENCODING
*enc
)
1290 return XML_ROLE_NONE
;
1294 common(PROLOG_STATE
*state
, int tok
)
1297 if (!state
->documentEntity
&& tok
== XML_TOK_PARAM_ENTITY_REF
)
1298 return XML_ROLE_INNER_PARAM_ENTITY_REF
;
1300 state
->handler
= error
;
1301 return XML_ROLE_ERROR
;
1305 XmlPrologStateInit(PROLOG_STATE
*state
)
1307 state
->handler
= prolog0
;
1309 state
->documentEntity
= 1;
1310 state
->includeLevel
= 0;
1311 state
->inEntityValue
= 0;
1312 #endif /* XML_DTD */
1318 XmlPrologStateInitExternalEntity(PROLOG_STATE
*state
)
1320 state
->handler
= externalSubset0
;
1321 state
->documentEntity
= 0;
1322 state
->includeLevel
= 0;
1325 #endif /* XML_DTD */