2 Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
3 See the file COPYING for copying permission.
7 = "$Header: /cvsroot/CMake/CMake/Utilities/cmexpat/xmlrole.c,v 1.1 2004-06-25 18:04:12 andy Exp $";
8 const char* cm_expat_GetXMLRole_RCSId()
10 /* Avoid warning about unused static without removing RCSId from original. */
14 #include <cmexpat/expatConfig.h>
21 that ,| are not mixed in a model group
26 static const char KW_ANY
[] = { ASCII_A
, ASCII_N
, ASCII_Y
, '\0' };
27 static const char KW_ATTLIST
[] = { ASCII_A
, ASCII_T
, ASCII_T
, ASCII_L
, ASCII_I
, ASCII_S
, ASCII_T
, '\0' };
28 static const char KW_CDATA
[] = { ASCII_C
, ASCII_D
, ASCII_A
, ASCII_T
, ASCII_A
, '\0' };
29 static const char KW_DOCTYPE
[] = { ASCII_D
, ASCII_O
, ASCII_C
, ASCII_T
, ASCII_Y
, ASCII_P
, ASCII_E
, '\0' };
30 static const char KW_ELEMENT
[] = { ASCII_E
, ASCII_L
, ASCII_E
, ASCII_M
, ASCII_E
, ASCII_N
, ASCII_T
, '\0' };
31 static const char KW_EMPTY
[] = { ASCII_E
, ASCII_M
, ASCII_P
, ASCII_T
, ASCII_Y
, '\0' };
32 static const char KW_ENTITIES
[] = { ASCII_E
, ASCII_N
, ASCII_T
, ASCII_I
, ASCII_T
, ASCII_I
, ASCII_E
, ASCII_S
, '\0' };
33 static const char KW_ENTITY
[] = { ASCII_E
, ASCII_N
, ASCII_T
, ASCII_I
, ASCII_T
, ASCII_Y
, '\0' };
34 static const char KW_FIXED
[] = { ASCII_F
, ASCII_I
, ASCII_X
, ASCII_E
, ASCII_D
, '\0' };
35 static const char KW_ID
[] = { ASCII_I
, ASCII_D
, '\0' };
36 static const char KW_IDREF
[] = { ASCII_I
, ASCII_D
, ASCII_R
, ASCII_E
, ASCII_F
, '\0' };
37 static const char KW_IDREFS
[] = { ASCII_I
, ASCII_D
, ASCII_R
, ASCII_E
, ASCII_F
, ASCII_S
, '\0' };
38 static const char KW_IGNORE
[] = { ASCII_I
, ASCII_G
, ASCII_N
, ASCII_O
, ASCII_R
, ASCII_E
, '\0' };
39 static const char KW_IMPLIED
[] = { ASCII_I
, ASCII_M
, ASCII_P
, ASCII_L
, ASCII_I
, ASCII_E
, ASCII_D
, '\0' };
40 static const char KW_INCLUDE
[] = { ASCII_I
, ASCII_N
, ASCII_C
, ASCII_L
, ASCII_U
, ASCII_D
, ASCII_E
, '\0' };
41 static const char KW_NDATA
[] = { ASCII_N
, ASCII_D
, ASCII_A
, ASCII_T
, ASCII_A
, '\0' };
42 static const char KW_NMTOKEN
[] = { ASCII_N
, ASCII_M
, ASCII_T
, ASCII_O
, ASCII_K
, ASCII_E
, ASCII_N
, '\0' };
43 static const char KW_NMTOKENS
[] = { ASCII_N
, ASCII_M
, ASCII_T
, ASCII_O
, ASCII_K
, ASCII_E
, ASCII_N
, ASCII_S
, '\0' };
44 static const char KW_NOTATION
[] = { ASCII_N
, ASCII_O
, ASCII_T
, ASCII_A
, ASCII_T
, ASCII_I
, ASCII_O
, ASCII_N
, '\0' };
45 static const char KW_PCDATA
[] = { ASCII_P
, ASCII_C
, ASCII_D
, ASCII_A
, ASCII_T
, ASCII_A
, '\0' };
46 static const char KW_PUBLIC
[] = { ASCII_P
, ASCII_U
, ASCII_B
, ASCII_L
, ASCII_I
, ASCII_C
, '\0' };
47 static const char KW_REQUIRED
[] = { ASCII_R
, ASCII_E
, ASCII_Q
, ASCII_U
, ASCII_I
, ASCII_R
, ASCII_E
, ASCII_D
, '\0' };
48 static const char KW_SYSTEM
[] = { ASCII_S
, ASCII_Y
, ASCII_S
, ASCII_T
, ASCII_E
, ASCII_M
, '\0' };
50 #ifndef MIN_BYTES_PER_CHAR
51 #define MIN_BYTES_PER_CHAR(enc) ((enc)->minBytesPerChar)
55 #define setTopLevel(state) \
56 ((state)->handler = ((state)->documentEntity \
59 #else /* not XML_DTD */
60 #define setTopLevel(state) ((state)->handler = internalSubset)
61 #endif /* not XML_DTD */
63 typedef int PROLOG_HANDLER(PROLOG_STATE
*state
,
70 prolog0
, prolog1
, prolog2
,
71 doctype0
, doctype1
, doctype2
, doctype3
, doctype4
, doctype5
,
73 entity0
, entity1
, entity2
, entity3
, entity4
, entity5
, entity6
,
74 entity7
, entity8
, entity9
,
75 notation0
, notation1
, notation2
, notation3
, notation4
,
76 attlist0
, attlist1
, attlist2
, attlist3
, attlist4
, attlist5
, attlist6
,
77 attlist7
, attlist8
, attlist9
,
78 element0
, element1
, element2
, element3
, element4
, element5
, element6
,
81 externalSubset0
, externalSubset1
,
82 condSect0
, condSect1
, condSect2
,
88 int common(PROLOG_STATE
*state
, int tok
);
91 int prolog0(PROLOG_STATE
*state
,
98 case XML_TOK_PROLOG_S
:
99 state
->handler
= prolog1
;
100 return XML_ROLE_NONE
;
101 case XML_TOK_XML_DECL
:
102 state
->handler
= prolog1
;
103 return XML_ROLE_XML_DECL
;
105 state
->handler
= prolog1
;
106 return XML_ROLE_NONE
;
107 case XML_TOK_COMMENT
:
108 state
->handler
= prolog1
;
110 return XML_ROLE_NONE
;
111 case XML_TOK_DECL_OPEN
:
112 if (!XmlNameMatchesAscii(enc
,
113 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
117 state
->handler
= doctype0
;
118 return XML_ROLE_NONE
;
119 case XML_TOK_INSTANCE_START
:
120 state
->handler
= error
;
121 return XML_ROLE_INSTANCE_START
;
123 return common(state
, tok
);
127 int prolog1(PROLOG_STATE
*state
,
134 case XML_TOK_PROLOG_S
:
135 return XML_ROLE_NONE
;
137 case XML_TOK_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_NONE
;
148 case XML_TOK_INSTANCE_START
:
149 state
->handler
= error
;
150 return XML_ROLE_INSTANCE_START
;
152 return common(state
, tok
);
156 int prolog2(PROLOG_STATE
*state
,
166 case XML_TOK_PROLOG_S
:
167 return XML_ROLE_NONE
;
169 case XML_TOK_COMMENT
:
170 return XML_ROLE_NONE
;
171 case XML_TOK_INSTANCE_START
:
172 state
->handler
= error
;
173 return XML_ROLE_INSTANCE_START
;
175 return common(state
, tok
);
179 int doctype0(PROLOG_STATE
*state
,
189 case XML_TOK_PROLOG_S
:
190 return XML_ROLE_NONE
;
192 case XML_TOK_PREFIXED_NAME
:
193 state
->handler
= doctype1
;
194 return XML_ROLE_DOCTYPE_NAME
;
196 return common(state
, tok
);
200 int doctype1(PROLOG_STATE
*state
,
207 case XML_TOK_PROLOG_S
:
208 return XML_ROLE_NONE
;
209 case XML_TOK_OPEN_BRACKET
:
210 state
->handler
= internalSubset
;
211 return XML_ROLE_DOCTYPE_INTERNAL_SUBSET
;
212 case XML_TOK_DECL_CLOSE
:
213 state
->handler
= prolog2
;
214 return XML_ROLE_DOCTYPE_CLOSE
;
216 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_SYSTEM
)) {
217 state
->handler
= doctype3
;
218 return XML_ROLE_NONE
;
220 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_PUBLIC
)) {
221 state
->handler
= doctype2
;
222 return XML_ROLE_NONE
;
226 return common(state
, tok
);
230 int doctype2(PROLOG_STATE
*state
,
240 case XML_TOK_PROLOG_S
:
241 return XML_ROLE_NONE
;
242 case XML_TOK_LITERAL
:
243 state
->handler
= doctype3
;
244 return XML_ROLE_DOCTYPE_PUBLIC_ID
;
246 return common(state
, tok
);
250 int doctype3(PROLOG_STATE
*state
,
260 case XML_TOK_PROLOG_S
:
261 return XML_ROLE_NONE
;
262 case XML_TOK_LITERAL
:
263 state
->handler
= doctype4
;
264 return XML_ROLE_DOCTYPE_SYSTEM_ID
;
266 return common(state
, tok
);
270 int doctype4(PROLOG_STATE
*state
,
280 case XML_TOK_PROLOG_S
:
281 return XML_ROLE_NONE
;
282 case XML_TOK_OPEN_BRACKET
:
283 state
->handler
= internalSubset
;
284 return XML_ROLE_DOCTYPE_INTERNAL_SUBSET
;
285 case XML_TOK_DECL_CLOSE
:
286 state
->handler
= prolog2
;
287 return XML_ROLE_DOCTYPE_CLOSE
;
289 return common(state
, tok
);
293 int doctype5(PROLOG_STATE
*state
,
303 case XML_TOK_PROLOG_S
:
304 return XML_ROLE_NONE
;
305 case XML_TOK_DECL_CLOSE
:
306 state
->handler
= prolog2
;
307 return XML_ROLE_DOCTYPE_CLOSE
;
309 return common(state
, tok
);
313 int internalSubset(PROLOG_STATE
*state
,
320 case XML_TOK_PROLOG_S
:
321 return XML_ROLE_NONE
;
322 case XML_TOK_DECL_OPEN
:
323 if (XmlNameMatchesAscii(enc
,
324 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
327 state
->handler
= entity0
;
328 return XML_ROLE_NONE
;
330 if (XmlNameMatchesAscii(enc
,
331 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
334 state
->handler
= attlist0
;
335 return XML_ROLE_NONE
;
337 if (XmlNameMatchesAscii(enc
,
338 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
341 state
->handler
= element0
;
342 return XML_ROLE_NONE
;
344 if (XmlNameMatchesAscii(enc
,
345 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
348 state
->handler
= notation0
;
349 return XML_ROLE_NONE
;
353 case XML_TOK_COMMENT
:
354 return XML_ROLE_NONE
;
355 case XML_TOK_PARAM_ENTITY_REF
:
356 return XML_ROLE_PARAM_ENTITY_REF
;
357 case XML_TOK_CLOSE_BRACKET
:
358 state
->handler
= doctype5
;
359 return XML_ROLE_NONE
;
361 return common(state
, tok
);
367 int externalSubset0(PROLOG_STATE
*state
,
373 state
->handler
= externalSubset1
;
374 if (tok
== XML_TOK_XML_DECL
)
375 return XML_ROLE_TEXT_DECL
;
376 return externalSubset1(state
, tok
, ptr
, end
, enc
);
380 int externalSubset1(PROLOG_STATE
*state
,
387 case XML_TOK_COND_SECT_OPEN
:
388 state
->handler
= condSect0
;
389 return XML_ROLE_NONE
;
390 case XML_TOK_COND_SECT_CLOSE
:
391 if (state
->includeLevel
== 0)
393 state
->includeLevel
-= 1;
394 return XML_ROLE_NONE
;
395 case XML_TOK_PROLOG_S
:
396 return XML_ROLE_NONE
;
397 case XML_TOK_CLOSE_BRACKET
:
400 if (state
->includeLevel
)
402 return XML_ROLE_NONE
;
404 return internalSubset(state
, tok
, ptr
, end
, enc
);
406 return common(state
, tok
);
412 int entity0(PROLOG_STATE
*state
,
422 case XML_TOK_PROLOG_S
:
423 return XML_ROLE_NONE
;
424 case XML_TOK_PERCENT
:
425 state
->handler
= entity1
;
426 return XML_ROLE_NONE
;
428 state
->handler
= entity2
;
429 return XML_ROLE_GENERAL_ENTITY_NAME
;
431 return common(state
, tok
);
435 int entity1(PROLOG_STATE
*state
,
445 case XML_TOK_PROLOG_S
:
446 return XML_ROLE_NONE
;
448 state
->handler
= entity7
;
449 return XML_ROLE_PARAM_ENTITY_NAME
;
451 return common(state
, tok
);
455 int entity2(PROLOG_STATE
*state
,
462 case XML_TOK_PROLOG_S
:
463 return XML_ROLE_NONE
;
465 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_SYSTEM
)) {
466 state
->handler
= entity4
;
467 return XML_ROLE_NONE
;
469 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_PUBLIC
)) {
470 state
->handler
= entity3
;
471 return XML_ROLE_NONE
;
474 case XML_TOK_LITERAL
:
475 state
->handler
= declClose
;
476 return XML_ROLE_ENTITY_VALUE
;
478 return common(state
, tok
);
482 int entity3(PROLOG_STATE
*state
,
492 case XML_TOK_PROLOG_S
:
493 return XML_ROLE_NONE
;
494 case XML_TOK_LITERAL
:
495 state
->handler
= entity4
;
496 return XML_ROLE_ENTITY_PUBLIC_ID
;
498 return common(state
, tok
);
503 int entity4(PROLOG_STATE
*state
,
513 case XML_TOK_PROLOG_S
:
514 return XML_ROLE_NONE
;
515 case XML_TOK_LITERAL
:
516 state
->handler
= entity5
;
517 return XML_ROLE_ENTITY_SYSTEM_ID
;
519 return common(state
, tok
);
523 int entity5(PROLOG_STATE
*state
,
530 case XML_TOK_PROLOG_S
:
531 return XML_ROLE_NONE
;
532 case XML_TOK_DECL_CLOSE
:
534 return XML_ROLE_ENTITY_COMPLETE
;
536 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_NDATA
)) {
537 state
->handler
= entity6
;
538 return XML_ROLE_NONE
;
542 return common(state
, tok
);
546 int entity6(PROLOG_STATE
*state
,
556 case XML_TOK_PROLOG_S
:
557 return XML_ROLE_NONE
;
559 state
->handler
= declClose
;
560 return XML_ROLE_ENTITY_NOTATION_NAME
;
562 return common(state
, tok
);
566 int entity7(PROLOG_STATE
*state
,
573 case XML_TOK_PROLOG_S
:
574 return XML_ROLE_NONE
;
576 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_SYSTEM
)) {
577 state
->handler
= entity9
;
578 return XML_ROLE_NONE
;
580 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_PUBLIC
)) {
581 state
->handler
= entity8
;
582 return XML_ROLE_NONE
;
585 case XML_TOK_LITERAL
:
586 state
->handler
= declClose
;
587 return XML_ROLE_ENTITY_VALUE
;
589 return common(state
, tok
);
593 int entity8(PROLOG_STATE
*state
,
603 case XML_TOK_PROLOG_S
:
604 return XML_ROLE_NONE
;
605 case XML_TOK_LITERAL
:
606 state
->handler
= entity9
;
607 return XML_ROLE_ENTITY_PUBLIC_ID
;
609 return common(state
, tok
);
613 int entity9(PROLOG_STATE
*state
,
623 case XML_TOK_PROLOG_S
:
624 return XML_ROLE_NONE
;
625 case XML_TOK_LITERAL
:
626 state
->handler
= declClose
;
627 return XML_ROLE_ENTITY_SYSTEM_ID
;
629 return common(state
, tok
);
633 int notation0(PROLOG_STATE
*state
,
643 case XML_TOK_PROLOG_S
:
644 return XML_ROLE_NONE
;
646 state
->handler
= notation1
;
647 return XML_ROLE_NOTATION_NAME
;
649 return common(state
, tok
);
653 int notation1(PROLOG_STATE
*state
,
660 case XML_TOK_PROLOG_S
:
661 return XML_ROLE_NONE
;
663 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_SYSTEM
)) {
664 state
->handler
= notation3
;
665 return XML_ROLE_NONE
;
667 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_PUBLIC
)) {
668 state
->handler
= notation2
;
669 return XML_ROLE_NONE
;
673 return common(state
, tok
);
677 int notation2(PROLOG_STATE
*state
,
687 case XML_TOK_PROLOG_S
:
688 return XML_ROLE_NONE
;
689 case XML_TOK_LITERAL
:
690 state
->handler
= notation4
;
691 return XML_ROLE_NOTATION_PUBLIC_ID
;
693 return common(state
, tok
);
697 int notation3(PROLOG_STATE
*state
,
707 case XML_TOK_PROLOG_S
:
708 return XML_ROLE_NONE
;
709 case XML_TOK_LITERAL
:
710 state
->handler
= declClose
;
711 return XML_ROLE_NOTATION_SYSTEM_ID
;
713 return common(state
, tok
);
717 int notation4(PROLOG_STATE
*state
,
727 case XML_TOK_PROLOG_S
:
728 return XML_ROLE_NONE
;
729 case XML_TOK_LITERAL
:
730 state
->handler
= declClose
;
731 return XML_ROLE_NOTATION_SYSTEM_ID
;
732 case XML_TOK_DECL_CLOSE
:
734 return XML_ROLE_NOTATION_NO_SYSTEM_ID
;
736 return common(state
, tok
);
740 int attlist0(PROLOG_STATE
*state
,
750 case XML_TOK_PROLOG_S
:
751 return XML_ROLE_NONE
;
753 case XML_TOK_PREFIXED_NAME
:
754 state
->handler
= attlist1
;
755 return XML_ROLE_ATTLIST_ELEMENT_NAME
;
757 return common(state
, tok
);
761 int attlist1(PROLOG_STATE
*state
,
771 case XML_TOK_PROLOG_S
:
772 return XML_ROLE_NONE
;
773 case XML_TOK_DECL_CLOSE
:
775 return XML_ROLE_NONE
;
777 case XML_TOK_PREFIXED_NAME
:
778 state
->handler
= attlist2
;
779 return XML_ROLE_ATTRIBUTE_NAME
;
781 return common(state
, tok
);
785 int attlist2(PROLOG_STATE
*state
,
795 case XML_TOK_PROLOG_S
:
796 return XML_ROLE_NONE
;
799 static const char *types
[] = {
810 for (i
= 0; i
< (int)(sizeof(types
)/sizeof(types
[0])); i
++)
811 if (XmlNameMatchesAscii(enc
, ptr
, end
, types
[i
])) {
812 state
->handler
= attlist8
;
813 return XML_ROLE_ATTRIBUTE_TYPE_CDATA
+ i
;
816 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_NOTATION
)) {
817 state
->handler
= attlist5
;
818 return XML_ROLE_NONE
;
821 case XML_TOK_OPEN_PAREN
:
822 state
->handler
= attlist3
;
823 return XML_ROLE_NONE
;
825 return common(state
, tok
);
829 int attlist3(PROLOG_STATE
*state
,
839 case XML_TOK_PROLOG_S
:
840 return XML_ROLE_NONE
;
841 case XML_TOK_NMTOKEN
:
843 case XML_TOK_PREFIXED_NAME
:
844 state
->handler
= attlist4
;
845 return XML_ROLE_ATTRIBUTE_ENUM_VALUE
;
847 return common(state
, tok
);
851 int attlist4(PROLOG_STATE
*state
,
861 case XML_TOK_PROLOG_S
:
862 return XML_ROLE_NONE
;
863 case XML_TOK_CLOSE_PAREN
:
864 state
->handler
= attlist8
;
865 return XML_ROLE_NONE
;
867 state
->handler
= attlist3
;
868 return XML_ROLE_NONE
;
870 return common(state
, tok
);
874 int attlist5(PROLOG_STATE
*state
,
884 case XML_TOK_PROLOG_S
:
885 return XML_ROLE_NONE
;
886 case XML_TOK_OPEN_PAREN
:
887 state
->handler
= attlist6
;
888 return XML_ROLE_NONE
;
890 return common(state
, tok
);
895 int attlist6(PROLOG_STATE
*state
,
905 case XML_TOK_PROLOG_S
:
906 return XML_ROLE_NONE
;
908 state
->handler
= attlist7
;
909 return XML_ROLE_ATTRIBUTE_NOTATION_VALUE
;
911 return common(state
, tok
);
915 int attlist7(PROLOG_STATE
*state
,
925 case XML_TOK_PROLOG_S
:
926 return XML_ROLE_NONE
;
927 case XML_TOK_CLOSE_PAREN
:
928 state
->handler
= attlist8
;
929 return XML_ROLE_NONE
;
931 state
->handler
= attlist6
;
932 return XML_ROLE_NONE
;
934 return common(state
, tok
);
939 int attlist8(PROLOG_STATE
*state
,
949 case XML_TOK_PROLOG_S
:
950 return XML_ROLE_NONE
;
951 case XML_TOK_POUND_NAME
:
952 if (XmlNameMatchesAscii(enc
,
953 ptr
+ MIN_BYTES_PER_CHAR(enc
),
956 state
->handler
= attlist1
;
957 return XML_ROLE_IMPLIED_ATTRIBUTE_VALUE
;
959 if (XmlNameMatchesAscii(enc
,
960 ptr
+ MIN_BYTES_PER_CHAR(enc
),
963 state
->handler
= attlist1
;
964 return XML_ROLE_REQUIRED_ATTRIBUTE_VALUE
;
966 if (XmlNameMatchesAscii(enc
,
967 ptr
+ MIN_BYTES_PER_CHAR(enc
),
970 state
->handler
= attlist9
;
971 return XML_ROLE_NONE
;
974 case XML_TOK_LITERAL
:
975 state
->handler
= attlist1
;
976 return XML_ROLE_DEFAULT_ATTRIBUTE_VALUE
;
978 return common(state
, tok
);
982 int attlist9(PROLOG_STATE
*state
,
992 case XML_TOK_PROLOG_S
:
993 return XML_ROLE_NONE
;
994 case XML_TOK_LITERAL
:
995 state
->handler
= attlist1
;
996 return XML_ROLE_FIXED_ATTRIBUTE_VALUE
;
998 return common(state
, tok
);
1002 int element0(PROLOG_STATE
*state
,
1006 const ENCODING
*enc
)
1012 case XML_TOK_PROLOG_S
:
1013 return XML_ROLE_NONE
;
1015 case XML_TOK_PREFIXED_NAME
:
1016 state
->handler
= element1
;
1017 return XML_ROLE_ELEMENT_NAME
;
1019 return common(state
, tok
);
1023 int element1(PROLOG_STATE
*state
,
1027 const ENCODING
*enc
)
1033 case XML_TOK_PROLOG_S
:
1034 return XML_ROLE_NONE
;
1036 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_EMPTY
)) {
1037 state
->handler
= declClose
;
1038 return XML_ROLE_CONTENT_EMPTY
;
1040 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_ANY
)) {
1041 state
->handler
= declClose
;
1042 return XML_ROLE_CONTENT_ANY
;
1045 case XML_TOK_OPEN_PAREN
:
1046 state
->handler
= element2
;
1048 return XML_ROLE_GROUP_OPEN
;
1050 return common(state
, tok
);
1054 int element2(PROLOG_STATE
*state
,
1058 const ENCODING
*enc
)
1064 case XML_TOK_PROLOG_S
:
1065 return XML_ROLE_NONE
;
1066 case XML_TOK_POUND_NAME
:
1067 if (XmlNameMatchesAscii(enc
,
1068 ptr
+ MIN_BYTES_PER_CHAR(enc
),
1071 state
->handler
= element3
;
1072 return XML_ROLE_CONTENT_PCDATA
;
1075 case XML_TOK_OPEN_PAREN
:
1077 state
->handler
= element6
;
1078 return XML_ROLE_GROUP_OPEN
;
1080 case XML_TOK_PREFIXED_NAME
:
1081 state
->handler
= element7
;
1082 return XML_ROLE_CONTENT_ELEMENT
;
1083 case XML_TOK_NAME_QUESTION
:
1084 state
->handler
= element7
;
1085 return XML_ROLE_CONTENT_ELEMENT_OPT
;
1086 case XML_TOK_NAME_ASTERISK
:
1087 state
->handler
= element7
;
1088 return XML_ROLE_CONTENT_ELEMENT_REP
;
1089 case XML_TOK_NAME_PLUS
:
1090 state
->handler
= element7
;
1091 return XML_ROLE_CONTENT_ELEMENT_PLUS
;
1093 return common(state
, tok
);
1097 int element3(PROLOG_STATE
*state
,
1101 const ENCODING
*enc
)
1107 case XML_TOK_PROLOG_S
:
1108 return XML_ROLE_NONE
;
1109 case XML_TOK_CLOSE_PAREN
:
1110 state
->handler
= declClose
;
1111 return XML_ROLE_GROUP_CLOSE
;
1112 case XML_TOK_CLOSE_PAREN_ASTERISK
:
1113 state
->handler
= declClose
;
1114 return XML_ROLE_GROUP_CLOSE_REP
;
1116 state
->handler
= element4
;
1117 return XML_ROLE_NONE
;
1119 return common(state
, tok
);
1123 int element4(PROLOG_STATE
*state
,
1127 const ENCODING
*enc
)
1133 case XML_TOK_PROLOG_S
:
1134 return XML_ROLE_NONE
;
1136 case XML_TOK_PREFIXED_NAME
:
1137 state
->handler
= element5
;
1138 return XML_ROLE_CONTENT_ELEMENT
;
1140 return common(state
, tok
);
1144 int element5(PROLOG_STATE
*state
,
1148 const ENCODING
*enc
)
1154 case XML_TOK_PROLOG_S
:
1155 return XML_ROLE_NONE
;
1156 case XML_TOK_CLOSE_PAREN_ASTERISK
:
1157 state
->handler
= declClose
;
1158 return XML_ROLE_GROUP_CLOSE_REP
;
1160 state
->handler
= element4
;
1161 return XML_ROLE_NONE
;
1163 return common(state
, tok
);
1167 int element6(PROLOG_STATE
*state
,
1171 const ENCODING
*enc
)
1177 case XML_TOK_PROLOG_S
:
1178 return XML_ROLE_NONE
;
1179 case XML_TOK_OPEN_PAREN
:
1181 return XML_ROLE_GROUP_OPEN
;
1183 case XML_TOK_PREFIXED_NAME
:
1184 state
->handler
= element7
;
1185 return XML_ROLE_CONTENT_ELEMENT
;
1186 case XML_TOK_NAME_QUESTION
:
1187 state
->handler
= element7
;
1188 return XML_ROLE_CONTENT_ELEMENT_OPT
;
1189 case XML_TOK_NAME_ASTERISK
:
1190 state
->handler
= element7
;
1191 return XML_ROLE_CONTENT_ELEMENT_REP
;
1192 case XML_TOK_NAME_PLUS
:
1193 state
->handler
= element7
;
1194 return XML_ROLE_CONTENT_ELEMENT_PLUS
;
1196 return common(state
, tok
);
1200 int element7(PROLOG_STATE
*state
,
1204 const ENCODING
*enc
)
1210 case XML_TOK_PROLOG_S
:
1211 return XML_ROLE_NONE
;
1212 case XML_TOK_CLOSE_PAREN
:
1214 if (state
->level
== 0)
1215 state
->handler
= declClose
;
1216 return XML_ROLE_GROUP_CLOSE
;
1217 case XML_TOK_CLOSE_PAREN_ASTERISK
:
1219 if (state
->level
== 0)
1220 state
->handler
= declClose
;
1221 return XML_ROLE_GROUP_CLOSE_REP
;
1222 case XML_TOK_CLOSE_PAREN_QUESTION
:
1224 if (state
->level
== 0)
1225 state
->handler
= declClose
;
1226 return XML_ROLE_GROUP_CLOSE_OPT
;
1227 case XML_TOK_CLOSE_PAREN_PLUS
:
1229 if (state
->level
== 0)
1230 state
->handler
= declClose
;
1231 return XML_ROLE_GROUP_CLOSE_PLUS
;
1233 state
->handler
= element6
;
1234 return XML_ROLE_GROUP_SEQUENCE
;
1236 state
->handler
= element6
;
1237 return XML_ROLE_GROUP_CHOICE
;
1239 return common(state
, tok
);
1245 int condSect0(PROLOG_STATE
*state
,
1249 const ENCODING
*enc
)
1255 case XML_TOK_PROLOG_S
:
1256 return XML_ROLE_NONE
;
1258 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_INCLUDE
)) {
1259 state
->handler
= condSect1
;
1260 return XML_ROLE_NONE
;
1262 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_IGNORE
)) {
1263 state
->handler
= condSect2
;
1264 return XML_ROLE_NONE
;
1268 return common(state
, tok
);
1272 int condSect1(PROLOG_STATE
*state
,
1276 const ENCODING
*enc
)
1282 case XML_TOK_PROLOG_S
:
1283 return XML_ROLE_NONE
;
1284 case XML_TOK_OPEN_BRACKET
:
1285 state
->handler
= externalSubset1
;
1286 state
->includeLevel
+= 1;
1287 return XML_ROLE_NONE
;
1289 return common(state
, tok
);
1293 int condSect2(PROLOG_STATE
*state
,
1297 const ENCODING
*enc
)
1303 case XML_TOK_PROLOG_S
:
1304 return XML_ROLE_NONE
;
1305 case XML_TOK_OPEN_BRACKET
:
1306 state
->handler
= externalSubset1
;
1307 return XML_ROLE_IGNORE_SECT
;
1309 return common(state
, tok
);
1312 #endif /* XML_DTD */
1315 int declClose(PROLOG_STATE
*state
,
1319 const ENCODING
*enc
)
1325 case XML_TOK_PROLOG_S
:
1326 return XML_ROLE_NONE
;
1327 case XML_TOK_DECL_CLOSE
:
1329 return XML_ROLE_NONE
;
1331 return common(state
, tok
);
1337 int ignore(PROLOG_STATE
*state
,
1341 const ENCODING
*enc
)
1347 case XML_TOK_DECL_CLOSE
:
1348 state
->handler
= internalSubset
;
1351 return XML_ROLE_NONE
;
1353 return common(state
, tok
);
1358 int error(PROLOG_STATE
*state
,
1362 const ENCODING
*enc
)
1364 cmExpatUnused(state
);
1369 return XML_ROLE_NONE
;
1373 int common(PROLOG_STATE
*state
, int tok
)
1376 if (!state
->documentEntity
&& tok
== XML_TOK_PARAM_ENTITY_REF
)
1377 return XML_ROLE_INNER_PARAM_ENTITY_REF
;
1379 state
->handler
= error
;
1380 return XML_ROLE_ERROR
;
1383 void XmlPrologStateInit(PROLOG_STATE
*state
)
1385 state
->handler
= prolog0
;
1387 state
->documentEntity
= 1;
1388 state
->includeLevel
= 0;
1389 #endif /* XML_DTD */
1394 void XmlPrologStateInitExternalEntity(PROLOG_STATE
*state
)
1396 state
->handler
= externalSubset0
;
1397 state
->documentEntity
= 0;
1398 state
->includeLevel
= 0;
1401 #endif /* XML_DTD */