2 Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
3 See the file copying.txt for copying permission.
12 that ,| are not mixed in a model group
17 static const char KW_ANY
[] = { ASCII_A
, ASCII_N
, ASCII_Y
, '\0' };
18 static const char KW_ATTLIST
[] = { ASCII_A
, ASCII_T
, ASCII_T
, ASCII_L
, ASCII_I
, ASCII_S
, ASCII_T
, '\0' };
19 static const char KW_CDATA
[] = { ASCII_C
, ASCII_D
, ASCII_A
, ASCII_T
, ASCII_A
, '\0' };
20 static const char KW_DOCTYPE
[] = { ASCII_D
, ASCII_O
, ASCII_C
, ASCII_T
, ASCII_Y
, ASCII_P
, ASCII_E
, '\0' };
21 static const char KW_ELEMENT
[] = { ASCII_E
, ASCII_L
, ASCII_E
, ASCII_M
, ASCII_E
, ASCII_N
, ASCII_T
, '\0' };
22 static const char KW_EMPTY
[] = { ASCII_E
, ASCII_M
, ASCII_P
, ASCII_T
, ASCII_Y
, '\0' };
23 static const char KW_ENTITIES
[] = { ASCII_E
, ASCII_N
, ASCII_T
, ASCII_I
, ASCII_T
, ASCII_I
, ASCII_E
, ASCII_S
, '\0' };
24 static const char KW_ENTITY
[] = { ASCII_E
, ASCII_N
, ASCII_T
, ASCII_I
, ASCII_T
, ASCII_Y
, '\0' };
25 static const char KW_FIXED
[] = { ASCII_F
, ASCII_I
, ASCII_X
, ASCII_E
, ASCII_D
, '\0' };
26 static const char KW_ID
[] = { ASCII_I
, ASCII_D
, '\0' };
27 static const char KW_IDREF
[] = { ASCII_I
, ASCII_D
, ASCII_R
, ASCII_E
, ASCII_F
, '\0' };
28 static const char KW_IDREFS
[] = { ASCII_I
, ASCII_D
, ASCII_R
, ASCII_E
, ASCII_F
, ASCII_S
, '\0' };
29 /* Remove compiler warnings for not using when XML_DTD is not defined */
31 static const char KW_INCLUDE
[] = { ASCII_I
, ASCII_N
, ASCII_C
, ASCII_L
, ASCII_U
, ASCII_D
, ASCII_E
, '\0' };
32 static const char KW_IGNORE
[] = { ASCII_I
, ASCII_G
, ASCII_N
, ASCII_O
, ASCII_R
, ASCII_E
, '\0' };
34 static const char KW_IMPLIED
[] = { ASCII_I
, ASCII_M
, ASCII_P
, ASCII_L
, ASCII_I
, ASCII_E
, ASCII_D
, '\0' };
35 static const char KW_NDATA
[] = { ASCII_N
, ASCII_D
, ASCII_A
, ASCII_T
, ASCII_A
, '\0' };
36 static const char KW_NMTOKEN
[] = { ASCII_N
, ASCII_M
, ASCII_T
, ASCII_O
, ASCII_K
, ASCII_E
, ASCII_N
, '\0' };
37 static const char KW_NMTOKENS
[] = { ASCII_N
, ASCII_M
, ASCII_T
, ASCII_O
, ASCII_K
, ASCII_E
, ASCII_N
, ASCII_S
, '\0' };
38 static const char KW_NOTATION
[] = { ASCII_N
, ASCII_O
, ASCII_T
, ASCII_A
, ASCII_T
, ASCII_I
, ASCII_O
, ASCII_N
, '\0' };
39 static const char KW_PCDATA
[] = { ASCII_P
, ASCII_C
, ASCII_D
, ASCII_A
, ASCII_T
, ASCII_A
, '\0' };
40 static const char KW_PUBLIC
[] = { ASCII_P
, ASCII_U
, ASCII_B
, ASCII_L
, ASCII_I
, ASCII_C
, '\0' };
41 static const char KW_REQUIRED
[] = { ASCII_R
, ASCII_E
, ASCII_Q
, ASCII_U
, ASCII_I
, ASCII_R
, ASCII_E
, ASCII_D
, '\0' };
42 static const char KW_SYSTEM
[] = { ASCII_S
, ASCII_Y
, ASCII_S
, ASCII_T
, ASCII_E
, ASCII_M
, '\0' };
44 #ifndef MIN_BYTES_PER_CHAR
45 #define MIN_BYTES_PER_CHAR(enc) ((enc)->minBytesPerChar)
49 #define setTopLevel(state) \
50 ((state)->handler = ((state)->documentEntity \
53 #else /* not XML_DTD */
54 #define setTopLevel(state) ((state)->handler = internalSubset)
55 #endif /* not XML_DTD */
57 typedef int PROLOG_HANDLER(PROLOG_STATE
*state
,
64 prolog0
, prolog1
, prolog2
,
65 doctype0
, doctype1
, doctype2
, doctype3
, doctype4
, doctype5
,
67 entity0
, entity1
, entity2
, entity3
, entity4
, entity5
, entity6
,
68 entity7
, entity8
, entity9
,
69 notation0
, notation1
, notation2
, notation3
, notation4
,
70 attlist0
, attlist1
, attlist2
, attlist3
, attlist4
, attlist5
, attlist6
,
71 attlist7
, attlist8
, attlist9
,
72 element0
, element1
, element2
, element3
, element4
, element5
, element6
,
75 externalSubset0
, externalSubset1
,
76 condSect0
, condSect1
, condSect2
,
82 int common(PROLOG_STATE
*state
, int tok
);
85 int prolog0(PROLOG_STATE
*state
,
92 case XML_TOK_PROLOG_S
:
93 state
->handler
= prolog1
;
95 case XML_TOK_XML_DECL
:
96 state
->handler
= prolog1
;
97 return XML_ROLE_XML_DECL
;
99 state
->handler
= prolog1
;
100 return XML_ROLE_NONE
;
101 case XML_TOK_COMMENT
:
102 state
->handler
= prolog1
;
104 return XML_ROLE_NONE
;
105 case XML_TOK_DECL_OPEN
:
106 if (!XmlNameMatchesAscii(enc
,
107 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
111 state
->handler
= doctype0
;
112 return XML_ROLE_NONE
;
113 case XML_TOK_INSTANCE_START
:
114 state
->handler
= error
;
115 return XML_ROLE_INSTANCE_START
;
117 return common(state
, tok
);
121 int prolog1(PROLOG_STATE
*state
,
128 case XML_TOK_PROLOG_S
:
129 return XML_ROLE_NONE
;
131 case XML_TOK_COMMENT
:
133 return XML_ROLE_NONE
;
134 case XML_TOK_DECL_OPEN
:
135 if (!XmlNameMatchesAscii(enc
,
136 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
140 state
->handler
= doctype0
;
141 return XML_ROLE_NONE
;
142 case XML_TOK_INSTANCE_START
:
143 state
->handler
= error
;
144 return XML_ROLE_INSTANCE_START
;
146 return common(state
, tok
);
150 int prolog2(PROLOG_STATE
*state
,
157 case XML_TOK_PROLOG_S
:
158 return XML_ROLE_NONE
;
160 case XML_TOK_COMMENT
:
161 return XML_ROLE_NONE
;
162 case XML_TOK_INSTANCE_START
:
163 state
->handler
= error
;
164 return XML_ROLE_INSTANCE_START
;
166 return common(state
, tok
);
170 int doctype0(PROLOG_STATE
*state
,
177 case XML_TOK_PROLOG_S
:
178 return XML_ROLE_NONE
;
180 case XML_TOK_PREFIXED_NAME
:
181 state
->handler
= doctype1
;
182 return XML_ROLE_DOCTYPE_NAME
;
184 return common(state
, tok
);
188 int doctype1(PROLOG_STATE
*state
,
195 case XML_TOK_PROLOG_S
:
196 return XML_ROLE_NONE
;
197 case XML_TOK_OPEN_BRACKET
:
198 state
->handler
= internalSubset
;
199 return XML_ROLE_NONE
;
200 case XML_TOK_DECL_CLOSE
:
201 state
->handler
= prolog2
;
202 return XML_ROLE_DOCTYPE_CLOSE
;
204 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_SYSTEM
)) {
205 state
->handler
= doctype3
;
206 return XML_ROLE_NONE
;
208 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_PUBLIC
)) {
209 state
->handler
= doctype2
;
210 return XML_ROLE_NONE
;
214 return common(state
, tok
);
218 int doctype2(PROLOG_STATE
*state
,
225 case XML_TOK_PROLOG_S
:
226 return XML_ROLE_NONE
;
227 case XML_TOK_LITERAL
:
228 state
->handler
= doctype3
;
229 return XML_ROLE_DOCTYPE_PUBLIC_ID
;
231 return common(state
, tok
);
235 int doctype3(PROLOG_STATE
*state
,
242 case XML_TOK_PROLOG_S
:
243 return XML_ROLE_NONE
;
244 case XML_TOK_LITERAL
:
245 state
->handler
= doctype4
;
246 return XML_ROLE_DOCTYPE_SYSTEM_ID
;
248 return common(state
, tok
);
252 int doctype4(PROLOG_STATE
*state
,
259 case XML_TOK_PROLOG_S
:
260 return XML_ROLE_NONE
;
261 case XML_TOK_OPEN_BRACKET
:
262 state
->handler
= internalSubset
;
263 return XML_ROLE_NONE
;
264 case XML_TOK_DECL_CLOSE
:
265 state
->handler
= prolog2
;
266 return XML_ROLE_DOCTYPE_CLOSE
;
268 return common(state
, tok
);
272 int doctype5(PROLOG_STATE
*state
,
279 case XML_TOK_PROLOG_S
:
280 return XML_ROLE_NONE
;
281 case XML_TOK_DECL_CLOSE
:
282 state
->handler
= prolog2
;
283 return XML_ROLE_DOCTYPE_CLOSE
;
285 return common(state
, tok
);
289 int internalSubset(PROLOG_STATE
*state
,
296 case XML_TOK_PROLOG_S
:
297 return XML_ROLE_NONE
;
298 case XML_TOK_DECL_OPEN
:
299 if (XmlNameMatchesAscii(enc
,
300 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
303 state
->handler
= entity0
;
304 return XML_ROLE_NONE
;
306 if (XmlNameMatchesAscii(enc
,
307 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
310 state
->handler
= attlist0
;
311 return XML_ROLE_NONE
;
313 if (XmlNameMatchesAscii(enc
,
314 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
317 state
->handler
= element0
;
318 return XML_ROLE_NONE
;
320 if (XmlNameMatchesAscii(enc
,
321 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
324 state
->handler
= notation0
;
325 return XML_ROLE_NONE
;
329 case XML_TOK_COMMENT
:
330 return XML_ROLE_NONE
;
331 case XML_TOK_PARAM_ENTITY_REF
:
332 return XML_ROLE_PARAM_ENTITY_REF
;
333 case XML_TOK_CLOSE_BRACKET
:
334 state
->handler
= doctype5
;
335 return XML_ROLE_NONE
;
337 return common(state
, tok
);
343 int externalSubset0(PROLOG_STATE
*state
,
349 state
->handler
= externalSubset1
;
350 if (tok
== XML_TOK_XML_DECL
)
351 return XML_ROLE_TEXT_DECL
;
352 return externalSubset1(state
, tok
, ptr
, end
, enc
);
356 int externalSubset1(PROLOG_STATE
*state
,
363 case XML_TOK_COND_SECT_OPEN
:
364 state
->handler
= condSect0
;
365 return XML_ROLE_NONE
;
366 case XML_TOK_COND_SECT_CLOSE
:
367 if (state
->includeLevel
== 0)
369 state
->includeLevel
-= 1;
370 return XML_ROLE_NONE
;
371 case XML_TOK_PROLOG_S
:
372 return XML_ROLE_NONE
;
373 case XML_TOK_CLOSE_BRACKET
:
376 if (state
->includeLevel
)
378 return XML_ROLE_NONE
;
380 return internalSubset(state
, tok
, ptr
, end
, enc
);
382 return common(state
, tok
);
388 int entity0(PROLOG_STATE
*state
,
395 case XML_TOK_PROLOG_S
:
396 return XML_ROLE_NONE
;
397 case XML_TOK_PERCENT
:
398 state
->handler
= entity1
;
399 return XML_ROLE_NONE
;
401 state
->handler
= entity2
;
402 return XML_ROLE_GENERAL_ENTITY_NAME
;
404 return common(state
, tok
);
408 int entity1(PROLOG_STATE
*state
,
415 case XML_TOK_PROLOG_S
:
416 return XML_ROLE_NONE
;
418 state
->handler
= entity7
;
419 return XML_ROLE_PARAM_ENTITY_NAME
;
421 return common(state
, tok
);
425 int entity2(PROLOG_STATE
*state
,
432 case XML_TOK_PROLOG_S
:
433 return XML_ROLE_NONE
;
435 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_SYSTEM
)) {
436 state
->handler
= entity4
;
437 return XML_ROLE_NONE
;
439 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_PUBLIC
)) {
440 state
->handler
= entity3
;
441 return XML_ROLE_NONE
;
444 case XML_TOK_LITERAL
:
445 state
->handler
= declClose
;
446 return XML_ROLE_ENTITY_VALUE
;
448 return common(state
, tok
);
452 int entity3(PROLOG_STATE
*state
,
459 case XML_TOK_PROLOG_S
:
460 return XML_ROLE_NONE
;
461 case XML_TOK_LITERAL
:
462 state
->handler
= entity4
;
463 return XML_ROLE_ENTITY_PUBLIC_ID
;
465 return common(state
, tok
);
470 int entity4(PROLOG_STATE
*state
,
477 case XML_TOK_PROLOG_S
:
478 return XML_ROLE_NONE
;
479 case XML_TOK_LITERAL
:
480 state
->handler
= entity5
;
481 return XML_ROLE_ENTITY_SYSTEM_ID
;
483 return common(state
, tok
);
487 int entity5(PROLOG_STATE
*state
,
494 case XML_TOK_PROLOG_S
:
495 return XML_ROLE_NONE
;
496 case XML_TOK_DECL_CLOSE
:
498 return XML_ROLE_EXTERNAL_GENERAL_ENTITY_NO_NOTATION
;
500 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_NDATA
)) {
501 state
->handler
= entity6
;
502 return XML_ROLE_NONE
;
506 return common(state
, tok
);
510 int entity6(PROLOG_STATE
*state
,
517 case XML_TOK_PROLOG_S
:
518 return XML_ROLE_NONE
;
520 state
->handler
= declClose
;
521 return XML_ROLE_ENTITY_NOTATION_NAME
;
523 return common(state
, tok
);
527 int entity7(PROLOG_STATE
*state
,
534 case XML_TOK_PROLOG_S
:
535 return XML_ROLE_NONE
;
537 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_SYSTEM
)) {
538 state
->handler
= entity9
;
539 return XML_ROLE_NONE
;
541 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_PUBLIC
)) {
542 state
->handler
= entity8
;
543 return XML_ROLE_NONE
;
546 case XML_TOK_LITERAL
:
547 state
->handler
= declClose
;
548 return XML_ROLE_ENTITY_VALUE
;
550 return common(state
, tok
);
554 int entity8(PROLOG_STATE
*state
,
561 case XML_TOK_PROLOG_S
:
562 return XML_ROLE_NONE
;
563 case XML_TOK_LITERAL
:
564 state
->handler
= entity9
;
565 return XML_ROLE_ENTITY_PUBLIC_ID
;
567 return common(state
, tok
);
571 int entity9(PROLOG_STATE
*state
,
578 case XML_TOK_PROLOG_S
:
579 return XML_ROLE_NONE
;
580 case XML_TOK_LITERAL
:
581 state
->handler
= declClose
;
582 return XML_ROLE_ENTITY_SYSTEM_ID
;
584 return common(state
, tok
);
588 int notation0(PROLOG_STATE
*state
,
595 case XML_TOK_PROLOG_S
:
596 return XML_ROLE_NONE
;
598 state
->handler
= notation1
;
599 return XML_ROLE_NOTATION_NAME
;
601 return common(state
, tok
);
605 int notation1(PROLOG_STATE
*state
,
612 case XML_TOK_PROLOG_S
:
613 return XML_ROLE_NONE
;
615 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_SYSTEM
)) {
616 state
->handler
= notation3
;
617 return XML_ROLE_NONE
;
619 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_PUBLIC
)) {
620 state
->handler
= notation2
;
621 return XML_ROLE_NONE
;
625 return common(state
, tok
);
629 int notation2(PROLOG_STATE
*state
,
636 case XML_TOK_PROLOG_S
:
637 return XML_ROLE_NONE
;
638 case XML_TOK_LITERAL
:
639 state
->handler
= notation4
;
640 return XML_ROLE_NOTATION_PUBLIC_ID
;
642 return common(state
, tok
);
646 int notation3(PROLOG_STATE
*state
,
653 case XML_TOK_PROLOG_S
:
654 return XML_ROLE_NONE
;
655 case XML_TOK_LITERAL
:
656 state
->handler
= declClose
;
657 return XML_ROLE_NOTATION_SYSTEM_ID
;
659 return common(state
, tok
);
663 int notation4(PROLOG_STATE
*state
,
670 case XML_TOK_PROLOG_S
:
671 return XML_ROLE_NONE
;
672 case XML_TOK_LITERAL
:
673 state
->handler
= declClose
;
674 return XML_ROLE_NOTATION_SYSTEM_ID
;
675 case XML_TOK_DECL_CLOSE
:
677 return XML_ROLE_NOTATION_NO_SYSTEM_ID
;
679 return common(state
, tok
);
683 int attlist0(PROLOG_STATE
*state
,
690 case XML_TOK_PROLOG_S
:
691 return XML_ROLE_NONE
;
693 case XML_TOK_PREFIXED_NAME
:
694 state
->handler
= attlist1
;
695 return XML_ROLE_ATTLIST_ELEMENT_NAME
;
697 return common(state
, tok
);
701 int attlist1(PROLOG_STATE
*state
,
708 case XML_TOK_PROLOG_S
:
709 return XML_ROLE_NONE
;
710 case XML_TOK_DECL_CLOSE
:
712 return XML_ROLE_NONE
;
714 case XML_TOK_PREFIXED_NAME
:
715 state
->handler
= attlist2
;
716 return XML_ROLE_ATTRIBUTE_NAME
;
718 return common(state
, tok
);
722 int attlist2(PROLOG_STATE
*state
,
729 case XML_TOK_PROLOG_S
:
730 return XML_ROLE_NONE
;
733 static const char *types
[] = {
744 for (i
= 0; i
< (int)(sizeof(types
)/sizeof(types
[0])); i
++)
745 if (XmlNameMatchesAscii(enc
, ptr
, end
, types
[i
])) {
746 state
->handler
= attlist8
;
747 return XML_ROLE_ATTRIBUTE_TYPE_CDATA
+ i
;
750 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_NOTATION
)) {
751 state
->handler
= attlist5
;
752 return XML_ROLE_NONE
;
755 case XML_TOK_OPEN_PAREN
:
756 state
->handler
= attlist3
;
757 return XML_ROLE_NONE
;
759 return common(state
, tok
);
763 int attlist3(PROLOG_STATE
*state
,
770 case XML_TOK_PROLOG_S
:
771 return XML_ROLE_NONE
;
772 case XML_TOK_NMTOKEN
:
774 case XML_TOK_PREFIXED_NAME
:
775 state
->handler
= attlist4
;
776 return XML_ROLE_ATTRIBUTE_ENUM_VALUE
;
778 return common(state
, tok
);
782 int attlist4(PROLOG_STATE
*state
,
789 case XML_TOK_PROLOG_S
:
790 return XML_ROLE_NONE
;
791 case XML_TOK_CLOSE_PAREN
:
792 state
->handler
= attlist8
;
793 return XML_ROLE_NONE
;
795 state
->handler
= attlist3
;
796 return XML_ROLE_NONE
;
798 return common(state
, tok
);
802 int attlist5(PROLOG_STATE
*state
,
809 case XML_TOK_PROLOG_S
:
810 return XML_ROLE_NONE
;
811 case XML_TOK_OPEN_PAREN
:
812 state
->handler
= attlist6
;
813 return XML_ROLE_NONE
;
815 return common(state
, tok
);
820 int attlist6(PROLOG_STATE
*state
,
827 case XML_TOK_PROLOG_S
:
828 return XML_ROLE_NONE
;
830 state
->handler
= attlist7
;
831 return XML_ROLE_ATTRIBUTE_NOTATION_VALUE
;
833 return common(state
, tok
);
837 int attlist7(PROLOG_STATE
*state
,
844 case XML_TOK_PROLOG_S
:
845 return XML_ROLE_NONE
;
846 case XML_TOK_CLOSE_PAREN
:
847 state
->handler
= attlist8
;
848 return XML_ROLE_NONE
;
850 state
->handler
= attlist6
;
851 return XML_ROLE_NONE
;
853 return common(state
, tok
);
858 int attlist8(PROLOG_STATE
*state
,
865 case XML_TOK_PROLOG_S
:
866 return XML_ROLE_NONE
;
867 case XML_TOK_POUND_NAME
:
868 if (XmlNameMatchesAscii(enc
,
869 ptr
+ MIN_BYTES_PER_CHAR(enc
),
872 state
->handler
= attlist1
;
873 return XML_ROLE_IMPLIED_ATTRIBUTE_VALUE
;
875 if (XmlNameMatchesAscii(enc
,
876 ptr
+ MIN_BYTES_PER_CHAR(enc
),
879 state
->handler
= attlist1
;
880 return XML_ROLE_REQUIRED_ATTRIBUTE_VALUE
;
882 if (XmlNameMatchesAscii(enc
,
883 ptr
+ MIN_BYTES_PER_CHAR(enc
),
886 state
->handler
= attlist9
;
887 return XML_ROLE_NONE
;
890 case XML_TOK_LITERAL
:
891 state
->handler
= attlist1
;
892 return XML_ROLE_DEFAULT_ATTRIBUTE_VALUE
;
894 return common(state
, tok
);
898 int attlist9(PROLOG_STATE
*state
,
905 case XML_TOK_PROLOG_S
:
906 return XML_ROLE_NONE
;
907 case XML_TOK_LITERAL
:
908 state
->handler
= attlist1
;
909 return XML_ROLE_FIXED_ATTRIBUTE_VALUE
;
911 return common(state
, tok
);
915 int element0(PROLOG_STATE
*state
,
922 case XML_TOK_PROLOG_S
:
923 return XML_ROLE_NONE
;
925 case XML_TOK_PREFIXED_NAME
:
926 state
->handler
= element1
;
927 return XML_ROLE_ELEMENT_NAME
;
929 return common(state
, tok
);
933 int element1(PROLOG_STATE
*state
,
940 case XML_TOK_PROLOG_S
:
941 return XML_ROLE_NONE
;
943 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_EMPTY
)) {
944 state
->handler
= declClose
;
945 return XML_ROLE_CONTENT_EMPTY
;
947 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_ANY
)) {
948 state
->handler
= declClose
;
949 return XML_ROLE_CONTENT_ANY
;
952 case XML_TOK_OPEN_PAREN
:
953 state
->handler
= element2
;
955 return XML_ROLE_GROUP_OPEN
;
957 return common(state
, tok
);
961 int element2(PROLOG_STATE
*state
,
968 case XML_TOK_PROLOG_S
:
969 return XML_ROLE_NONE
;
970 case XML_TOK_POUND_NAME
:
971 if (XmlNameMatchesAscii(enc
,
972 ptr
+ MIN_BYTES_PER_CHAR(enc
),
975 state
->handler
= element3
;
976 return XML_ROLE_CONTENT_PCDATA
;
979 case XML_TOK_OPEN_PAREN
:
981 state
->handler
= element6
;
982 return XML_ROLE_GROUP_OPEN
;
984 case XML_TOK_PREFIXED_NAME
:
985 state
->handler
= element7
;
986 return XML_ROLE_CONTENT_ELEMENT
;
987 case XML_TOK_NAME_QUESTION
:
988 state
->handler
= element7
;
989 return XML_ROLE_CONTENT_ELEMENT_OPT
;
990 case XML_TOK_NAME_ASTERISK
:
991 state
->handler
= element7
;
992 return XML_ROLE_CONTENT_ELEMENT_REP
;
993 case XML_TOK_NAME_PLUS
:
994 state
->handler
= element7
;
995 return XML_ROLE_CONTENT_ELEMENT_PLUS
;
997 return common(state
, tok
);
1001 int element3(PROLOG_STATE
*state
,
1005 const ENCODING
*enc
)
1008 case XML_TOK_PROLOG_S
:
1009 return XML_ROLE_NONE
;
1010 case XML_TOK_CLOSE_PAREN
:
1011 case XML_TOK_CLOSE_PAREN_ASTERISK
:
1012 state
->handler
= declClose
;
1013 return XML_ROLE_GROUP_CLOSE_REP
;
1015 state
->handler
= element4
;
1016 return XML_ROLE_NONE
;
1018 return common(state
, tok
);
1022 int element4(PROLOG_STATE
*state
,
1026 const ENCODING
*enc
)
1029 case XML_TOK_PROLOG_S
:
1030 return XML_ROLE_NONE
;
1032 case XML_TOK_PREFIXED_NAME
:
1033 state
->handler
= element5
;
1034 return XML_ROLE_CONTENT_ELEMENT
;
1036 return common(state
, tok
);
1040 int element5(PROLOG_STATE
*state
,
1044 const ENCODING
*enc
)
1047 case XML_TOK_PROLOG_S
:
1048 return XML_ROLE_NONE
;
1049 case XML_TOK_CLOSE_PAREN_ASTERISK
:
1050 state
->handler
= declClose
;
1051 return XML_ROLE_GROUP_CLOSE_REP
;
1053 state
->handler
= element4
;
1054 return XML_ROLE_NONE
;
1056 return common(state
, tok
);
1060 int element6(PROLOG_STATE
*state
,
1064 const ENCODING
*enc
)
1067 case XML_TOK_PROLOG_S
:
1068 return XML_ROLE_NONE
;
1069 case XML_TOK_OPEN_PAREN
:
1071 return XML_ROLE_GROUP_OPEN
;
1073 case XML_TOK_PREFIXED_NAME
:
1074 state
->handler
= element7
;
1075 return XML_ROLE_CONTENT_ELEMENT
;
1076 case XML_TOK_NAME_QUESTION
:
1077 state
->handler
= element7
;
1078 return XML_ROLE_CONTENT_ELEMENT_OPT
;
1079 case XML_TOK_NAME_ASTERISK
:
1080 state
->handler
= element7
;
1081 return XML_ROLE_CONTENT_ELEMENT_REP
;
1082 case XML_TOK_NAME_PLUS
:
1083 state
->handler
= element7
;
1084 return XML_ROLE_CONTENT_ELEMENT_PLUS
;
1086 return common(state
, tok
);
1090 int element7(PROLOG_STATE
*state
,
1094 const ENCODING
*enc
)
1097 case XML_TOK_PROLOG_S
:
1098 return XML_ROLE_NONE
;
1099 case XML_TOK_CLOSE_PAREN
:
1101 if (state
->level
== 0)
1102 state
->handler
= declClose
;
1103 return XML_ROLE_GROUP_CLOSE
;
1104 case XML_TOK_CLOSE_PAREN_ASTERISK
:
1106 if (state
->level
== 0)
1107 state
->handler
= declClose
;
1108 return XML_ROLE_GROUP_CLOSE_REP
;
1109 case XML_TOK_CLOSE_PAREN_QUESTION
:
1111 if (state
->level
== 0)
1112 state
->handler
= declClose
;
1113 return XML_ROLE_GROUP_CLOSE_OPT
;
1114 case XML_TOK_CLOSE_PAREN_PLUS
:
1116 if (state
->level
== 0)
1117 state
->handler
= declClose
;
1118 return XML_ROLE_GROUP_CLOSE_PLUS
;
1120 state
->handler
= element6
;
1121 return XML_ROLE_GROUP_SEQUENCE
;
1123 state
->handler
= element6
;
1124 return XML_ROLE_GROUP_CHOICE
;
1126 return common(state
, tok
);
1132 int condSect0(PROLOG_STATE
*state
,
1136 const ENCODING
*enc
)
1139 case XML_TOK_PROLOG_S
:
1140 return XML_ROLE_NONE
;
1142 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_INCLUDE
)) {
1143 state
->handler
= condSect1
;
1144 return XML_ROLE_NONE
;
1146 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_IGNORE
)) {
1147 state
->handler
= condSect2
;
1148 return XML_ROLE_NONE
;
1152 return common(state
, tok
);
1156 int condSect1(PROLOG_STATE
*state
,
1160 const ENCODING
*enc
)
1163 case XML_TOK_PROLOG_S
:
1164 return XML_ROLE_NONE
;
1165 case XML_TOK_OPEN_BRACKET
:
1166 state
->handler
= externalSubset1
;
1167 state
->includeLevel
+= 1;
1168 return XML_ROLE_NONE
;
1170 return common(state
, tok
);
1174 int condSect2(PROLOG_STATE
*state
,
1178 const ENCODING
*enc
)
1181 case XML_TOK_PROLOG_S
:
1182 return XML_ROLE_NONE
;
1183 case XML_TOK_OPEN_BRACKET
:
1184 state
->handler
= externalSubset1
;
1185 return XML_ROLE_IGNORE_SECT
;
1187 return common(state
, tok
);
1190 #endif /* XML_DTD */
1193 int declClose(PROLOG_STATE
*state
,
1197 const ENCODING
*enc
)
1200 case XML_TOK_PROLOG_S
:
1201 return XML_ROLE_NONE
;
1202 case XML_TOK_DECL_CLOSE
:
1204 return XML_ROLE_NONE
;
1206 return common(state
, tok
);
1212 int ignore(PROLOG_STATE
*state
,
1216 const ENCODING
*enc
)
1219 case XML_TOK_DECL_CLOSE
:
1220 state
->handler
= internalSubset
;
1223 return XML_ROLE_NONE
;
1225 return common(state
, tok
);
1230 int error(PROLOG_STATE
*state
,
1234 const ENCODING
*enc
)
1236 return XML_ROLE_NONE
;
1240 int common(PROLOG_STATE
*state
, int tok
)
1243 if (!state
->documentEntity
&& tok
== XML_TOK_PARAM_ENTITY_REF
)
1244 return XML_ROLE_INNER_PARAM_ENTITY_REF
;
1246 state
->handler
= error
;
1247 return XML_ROLE_ERROR
;
1250 void XmlPrologStateInit(PROLOG_STATE
*state
)
1252 state
->handler
= prolog0
;
1254 state
->documentEntity
= 1;
1255 state
->includeLevel
= 0;
1256 #endif /* XML_DTD */
1261 void XmlPrologStateInitExternalEntity(PROLOG_STATE
*state
)
1263 state
->handler
= externalSubset0
;
1264 state
->documentEntity
= 0;
1265 state
->includeLevel
= 0;
1268 #endif /* XML_DTD */