1 /* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
2 See the file COPYING for copying permission.
7 #ifdef COMPILED_FROM_DSP
10 #include "os2config.h"
11 #elif defined(__MSDOS__)
12 #include "dosconfig.h"
13 #elif defined(MACOS_CLASSIC)
14 #include "macconfig.h"
15 #elif defined(__amigaos__)
16 #include "amigaconfig.h"
17 #elif defined(__WATCOMC__)
18 #include "watcomconfig.h"
20 #ifdef HAVE_EXPAT_CONFIG_H
21 #include <expat_config.h>
23 #endif /* ndef COMPILED_FROM_DSP */
25 #include "expat_external.h"
32 that ,| are not mixed in a model group
37 static const char KW_ANY
[] = {
38 ASCII_A
, ASCII_N
, ASCII_Y
, '\0' };
39 static const char KW_ATTLIST
[] = {
40 ASCII_A
, ASCII_T
, ASCII_T
, ASCII_L
, ASCII_I
, ASCII_S
, ASCII_T
, '\0' };
41 static const char KW_CDATA
[] = {
42 ASCII_C
, ASCII_D
, ASCII_A
, ASCII_T
, ASCII_A
, '\0' };
43 static const char KW_DOCTYPE
[] = {
44 ASCII_D
, ASCII_O
, ASCII_C
, ASCII_T
, ASCII_Y
, ASCII_P
, ASCII_E
, '\0' };
45 static const char KW_ELEMENT
[] = {
46 ASCII_E
, ASCII_L
, ASCII_E
, ASCII_M
, ASCII_E
, ASCII_N
, ASCII_T
, '\0' };
47 static const char KW_EMPTY
[] = {
48 ASCII_E
, ASCII_M
, ASCII_P
, ASCII_T
, ASCII_Y
, '\0' };
49 static const char KW_ENTITIES
[] = {
50 ASCII_E
, ASCII_N
, ASCII_T
, ASCII_I
, ASCII_T
, ASCII_I
, ASCII_E
, ASCII_S
,
52 static const char KW_ENTITY
[] = {
53 ASCII_E
, ASCII_N
, ASCII_T
, ASCII_I
, ASCII_T
, ASCII_Y
, '\0' };
54 static const char KW_FIXED
[] = {
55 ASCII_F
, ASCII_I
, ASCII_X
, ASCII_E
, ASCII_D
, '\0' };
56 static const char KW_ID
[] = {
57 ASCII_I
, ASCII_D
, '\0' };
58 static const char KW_IDREF
[] = {
59 ASCII_I
, ASCII_D
, ASCII_R
, ASCII_E
, ASCII_F
, '\0' };
60 static const char KW_IDREFS
[] = {
61 ASCII_I
, ASCII_D
, ASCII_R
, ASCII_E
, ASCII_F
, ASCII_S
, '\0' };
63 static const char KW_IGNORE
[] = {
64 ASCII_I
, ASCII_G
, ASCII_N
, ASCII_O
, ASCII_R
, ASCII_E
, '\0' };
66 static const char KW_IMPLIED
[] = {
67 ASCII_I
, ASCII_M
, ASCII_P
, ASCII_L
, ASCII_I
, ASCII_E
, ASCII_D
, '\0' };
69 static const char KW_INCLUDE
[] = {
70 ASCII_I
, ASCII_N
, ASCII_C
, ASCII_L
, ASCII_U
, ASCII_D
, ASCII_E
, '\0' };
72 static const char KW_NDATA
[] = {
73 ASCII_N
, ASCII_D
, ASCII_A
, ASCII_T
, ASCII_A
, '\0' };
74 static const char KW_NMTOKEN
[] = {
75 ASCII_N
, ASCII_M
, ASCII_T
, ASCII_O
, ASCII_K
, ASCII_E
, ASCII_N
, '\0' };
76 static const char KW_NMTOKENS
[] = {
77 ASCII_N
, ASCII_M
, ASCII_T
, ASCII_O
, ASCII_K
, ASCII_E
, ASCII_N
, ASCII_S
,
79 static const char KW_NOTATION
[] =
80 { ASCII_N
, ASCII_O
, ASCII_T
, ASCII_A
, ASCII_T
, ASCII_I
, ASCII_O
, ASCII_N
,
82 static const char KW_PCDATA
[] = {
83 ASCII_P
, ASCII_C
, ASCII_D
, ASCII_A
, ASCII_T
, ASCII_A
, '\0' };
84 static const char KW_PUBLIC
[] = {
85 ASCII_P
, ASCII_U
, ASCII_B
, ASCII_L
, ASCII_I
, ASCII_C
, '\0' };
86 static const char KW_REQUIRED
[] = {
87 ASCII_R
, ASCII_E
, ASCII_Q
, ASCII_U
, ASCII_I
, ASCII_R
, ASCII_E
, ASCII_D
,
89 static const char KW_SYSTEM
[] = {
90 ASCII_S
, ASCII_Y
, ASCII_S
, ASCII_T
, ASCII_E
, ASCII_M
, '\0' };
92 #ifndef MIN_BYTES_PER_CHAR
93 #define MIN_BYTES_PER_CHAR(enc) ((enc)->minBytesPerChar)
97 #define setTopLevel(state) \
98 ((state)->handler = ((state)->documentEntity \
101 #else /* not XML_DTD */
102 #define setTopLevel(state) ((state)->handler = internalSubset)
103 #endif /* not XML_DTD */
105 typedef int PTRCALL
PROLOG_HANDLER(PROLOG_STATE
*state
,
109 const ENCODING
*enc
);
111 static PROLOG_HANDLER
112 prolog0
, prolog1
, prolog2
,
113 doctype0
, doctype1
, doctype2
, doctype3
, doctype4
, doctype5
,
115 entity0
, entity1
, entity2
, entity3
, entity4
, entity5
, entity6
,
116 entity7
, entity8
, entity9
, entity10
,
117 notation0
, notation1
, notation2
, notation3
, notation4
,
118 attlist0
, attlist1
, attlist2
, attlist3
, attlist4
, attlist5
, attlist6
,
119 attlist7
, attlist8
, attlist9
,
120 element0
, element1
, element2
, element3
, element4
, element5
, element6
,
123 externalSubset0
, externalSubset1
,
124 condSect0
, condSect1
, condSect2
,
129 static int FASTCALL
common(PROLOG_STATE
*state
, int tok
);
132 prolog0(PROLOG_STATE
*state
,
139 case XML_TOK_PROLOG_S
:
140 state
->handler
= prolog1
;
141 return XML_ROLE_NONE
;
142 case XML_TOK_XML_DECL
:
143 state
->handler
= prolog1
;
144 return XML_ROLE_XML_DECL
;
146 state
->handler
= prolog1
;
148 case XML_TOK_COMMENT
:
149 state
->handler
= prolog1
;
150 return XML_ROLE_COMMENT
;
152 return XML_ROLE_NONE
;
153 case XML_TOK_DECL_OPEN
:
154 if (!XmlNameMatchesAscii(enc
,
155 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
159 state
->handler
= doctype0
;
160 return XML_ROLE_DOCTYPE_NONE
;
161 case XML_TOK_INSTANCE_START
:
162 state
->handler
= error
;
163 return XML_ROLE_INSTANCE_START
;
165 return common(state
, tok
);
169 prolog1(PROLOG_STATE
*state
,
176 case XML_TOK_PROLOG_S
:
177 return XML_ROLE_NONE
;
180 case XML_TOK_COMMENT
:
181 return XML_ROLE_COMMENT
;
183 return XML_ROLE_NONE
;
184 case XML_TOK_DECL_OPEN
:
185 if (!XmlNameMatchesAscii(enc
,
186 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
190 state
->handler
= doctype0
;
191 return XML_ROLE_DOCTYPE_NONE
;
192 case XML_TOK_INSTANCE_START
:
193 state
->handler
= error
;
194 return XML_ROLE_INSTANCE_START
;
196 return common(state
, tok
);
200 prolog2(PROLOG_STATE
*state
,
207 case XML_TOK_PROLOG_S
:
208 return XML_ROLE_NONE
;
211 case XML_TOK_COMMENT
:
212 return XML_ROLE_COMMENT
;
213 case XML_TOK_INSTANCE_START
:
214 state
->handler
= error
;
215 return XML_ROLE_INSTANCE_START
;
217 return common(state
, tok
);
221 doctype0(PROLOG_STATE
*state
,
228 case XML_TOK_PROLOG_S
:
229 return XML_ROLE_DOCTYPE_NONE
;
231 case XML_TOK_PREFIXED_NAME
:
232 state
->handler
= doctype1
;
233 return XML_ROLE_DOCTYPE_NAME
;
235 return common(state
, tok
);
239 doctype1(PROLOG_STATE
*state
,
246 case XML_TOK_PROLOG_S
:
247 return XML_ROLE_DOCTYPE_NONE
;
248 case XML_TOK_OPEN_BRACKET
:
249 state
->handler
= internalSubset
;
250 return XML_ROLE_DOCTYPE_INTERNAL_SUBSET
;
251 case XML_TOK_DECL_CLOSE
:
252 state
->handler
= prolog2
;
253 return XML_ROLE_DOCTYPE_CLOSE
;
255 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_SYSTEM
)) {
256 state
->handler
= doctype3
;
257 return XML_ROLE_DOCTYPE_NONE
;
259 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_PUBLIC
)) {
260 state
->handler
= doctype2
;
261 return XML_ROLE_DOCTYPE_NONE
;
265 return common(state
, tok
);
269 doctype2(PROLOG_STATE
*state
,
276 case XML_TOK_PROLOG_S
:
277 return XML_ROLE_DOCTYPE_NONE
;
278 case XML_TOK_LITERAL
:
279 state
->handler
= doctype3
;
280 return XML_ROLE_DOCTYPE_PUBLIC_ID
;
282 return common(state
, tok
);
286 doctype3(PROLOG_STATE
*state
,
293 case XML_TOK_PROLOG_S
:
294 return XML_ROLE_DOCTYPE_NONE
;
295 case XML_TOK_LITERAL
:
296 state
->handler
= doctype4
;
297 return XML_ROLE_DOCTYPE_SYSTEM_ID
;
299 return common(state
, tok
);
303 doctype4(PROLOG_STATE
*state
,
310 case XML_TOK_PROLOG_S
:
311 return XML_ROLE_DOCTYPE_NONE
;
312 case XML_TOK_OPEN_BRACKET
:
313 state
->handler
= internalSubset
;
314 return XML_ROLE_DOCTYPE_INTERNAL_SUBSET
;
315 case XML_TOK_DECL_CLOSE
:
316 state
->handler
= prolog2
;
317 return XML_ROLE_DOCTYPE_CLOSE
;
319 return common(state
, tok
);
323 doctype5(PROLOG_STATE
*state
,
330 case XML_TOK_PROLOG_S
:
331 return XML_ROLE_DOCTYPE_NONE
;
332 case XML_TOK_DECL_CLOSE
:
333 state
->handler
= prolog2
;
334 return XML_ROLE_DOCTYPE_CLOSE
;
336 return common(state
, tok
);
340 internalSubset(PROLOG_STATE
*state
,
347 case XML_TOK_PROLOG_S
:
348 return XML_ROLE_NONE
;
349 case XML_TOK_DECL_OPEN
:
350 if (XmlNameMatchesAscii(enc
,
351 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
354 state
->handler
= entity0
;
355 return XML_ROLE_ENTITY_NONE
;
357 if (XmlNameMatchesAscii(enc
,
358 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
361 state
->handler
= attlist0
;
362 return XML_ROLE_ATTLIST_NONE
;
364 if (XmlNameMatchesAscii(enc
,
365 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
368 state
->handler
= element0
;
369 return XML_ROLE_ELEMENT_NONE
;
371 if (XmlNameMatchesAscii(enc
,
372 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
375 state
->handler
= notation0
;
376 return XML_ROLE_NOTATION_NONE
;
381 case XML_TOK_COMMENT
:
382 return XML_ROLE_COMMENT
;
383 case XML_TOK_PARAM_ENTITY_REF
:
384 return XML_ROLE_PARAM_ENTITY_REF
;
385 case XML_TOK_CLOSE_BRACKET
:
386 state
->handler
= doctype5
;
387 return XML_ROLE_DOCTYPE_NONE
;
389 return XML_ROLE_NONE
;
391 return common(state
, tok
);
397 externalSubset0(PROLOG_STATE
*state
,
403 state
->handler
= externalSubset1
;
404 if (tok
== XML_TOK_XML_DECL
)
405 return XML_ROLE_TEXT_DECL
;
406 return externalSubset1(state
, tok
, ptr
, end
, enc
);
410 externalSubset1(PROLOG_STATE
*state
,
417 case XML_TOK_COND_SECT_OPEN
:
418 state
->handler
= condSect0
;
419 return XML_ROLE_NONE
;
420 case XML_TOK_COND_SECT_CLOSE
:
421 if (state
->includeLevel
== 0)
423 state
->includeLevel
-= 1;
424 return XML_ROLE_NONE
;
425 case XML_TOK_PROLOG_S
:
426 return XML_ROLE_NONE
;
427 case XML_TOK_CLOSE_BRACKET
:
430 if (state
->includeLevel
)
432 return XML_ROLE_NONE
;
434 return internalSubset(state
, tok
, ptr
, end
, enc
);
436 return common(state
, tok
);
442 entity0(PROLOG_STATE
*state
,
449 case XML_TOK_PROLOG_S
:
450 return XML_ROLE_ENTITY_NONE
;
451 case XML_TOK_PERCENT
:
452 state
->handler
= entity1
;
453 return XML_ROLE_ENTITY_NONE
;
455 state
->handler
= entity2
;
456 return XML_ROLE_GENERAL_ENTITY_NAME
;
458 return common(state
, tok
);
462 entity1(PROLOG_STATE
*state
,
469 case XML_TOK_PROLOG_S
:
470 return XML_ROLE_ENTITY_NONE
;
472 state
->handler
= entity7
;
473 return XML_ROLE_PARAM_ENTITY_NAME
;
475 return common(state
, tok
);
479 entity2(PROLOG_STATE
*state
,
486 case XML_TOK_PROLOG_S
:
487 return XML_ROLE_ENTITY_NONE
;
489 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_SYSTEM
)) {
490 state
->handler
= entity4
;
491 return XML_ROLE_ENTITY_NONE
;
493 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_PUBLIC
)) {
494 state
->handler
= entity3
;
495 return XML_ROLE_ENTITY_NONE
;
498 case XML_TOK_LITERAL
:
499 state
->handler
= declClose
;
500 state
->role_none
= XML_ROLE_ENTITY_NONE
;
501 return XML_ROLE_ENTITY_VALUE
;
503 return common(state
, tok
);
507 entity3(PROLOG_STATE
*state
,
514 case XML_TOK_PROLOG_S
:
515 return XML_ROLE_ENTITY_NONE
;
516 case XML_TOK_LITERAL
:
517 state
->handler
= entity4
;
518 return XML_ROLE_ENTITY_PUBLIC_ID
;
520 return common(state
, tok
);
524 entity4(PROLOG_STATE
*state
,
531 case XML_TOK_PROLOG_S
:
532 return XML_ROLE_ENTITY_NONE
;
533 case XML_TOK_LITERAL
:
534 state
->handler
= entity5
;
535 return XML_ROLE_ENTITY_SYSTEM_ID
;
537 return common(state
, tok
);
541 entity5(PROLOG_STATE
*state
,
548 case XML_TOK_PROLOG_S
:
549 return XML_ROLE_ENTITY_NONE
;
550 case XML_TOK_DECL_CLOSE
:
552 return XML_ROLE_ENTITY_COMPLETE
;
554 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_NDATA
)) {
555 state
->handler
= entity6
;
556 return XML_ROLE_ENTITY_NONE
;
560 return common(state
, tok
);
564 entity6(PROLOG_STATE
*state
,
571 case XML_TOK_PROLOG_S
:
572 return XML_ROLE_ENTITY_NONE
;
574 state
->handler
= declClose
;
575 state
->role_none
= XML_ROLE_ENTITY_NONE
;
576 return XML_ROLE_ENTITY_NOTATION_NAME
;
578 return common(state
, tok
);
582 entity7(PROLOG_STATE
*state
,
589 case XML_TOK_PROLOG_S
:
590 return XML_ROLE_ENTITY_NONE
;
592 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_SYSTEM
)) {
593 state
->handler
= entity9
;
594 return XML_ROLE_ENTITY_NONE
;
596 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_PUBLIC
)) {
597 state
->handler
= entity8
;
598 return XML_ROLE_ENTITY_NONE
;
601 case XML_TOK_LITERAL
:
602 state
->handler
= declClose
;
603 state
->role_none
= XML_ROLE_ENTITY_NONE
;
604 return XML_ROLE_ENTITY_VALUE
;
606 return common(state
, tok
);
610 entity8(PROLOG_STATE
*state
,
617 case XML_TOK_PROLOG_S
:
618 return XML_ROLE_ENTITY_NONE
;
619 case XML_TOK_LITERAL
:
620 state
->handler
= entity9
;
621 return XML_ROLE_ENTITY_PUBLIC_ID
;
623 return common(state
, tok
);
627 entity9(PROLOG_STATE
*state
,
634 case XML_TOK_PROLOG_S
:
635 return XML_ROLE_ENTITY_NONE
;
636 case XML_TOK_LITERAL
:
637 state
->handler
= entity10
;
638 return XML_ROLE_ENTITY_SYSTEM_ID
;
640 return common(state
, tok
);
644 entity10(PROLOG_STATE
*state
,
651 case XML_TOK_PROLOG_S
:
652 return XML_ROLE_ENTITY_NONE
;
653 case XML_TOK_DECL_CLOSE
:
655 return XML_ROLE_ENTITY_COMPLETE
;
657 return common(state
, tok
);
661 notation0(PROLOG_STATE
*state
,
668 case XML_TOK_PROLOG_S
:
669 return XML_ROLE_NOTATION_NONE
;
671 state
->handler
= notation1
;
672 return XML_ROLE_NOTATION_NAME
;
674 return common(state
, tok
);
678 notation1(PROLOG_STATE
*state
,
685 case XML_TOK_PROLOG_S
:
686 return XML_ROLE_NOTATION_NONE
;
688 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_SYSTEM
)) {
689 state
->handler
= notation3
;
690 return XML_ROLE_NOTATION_NONE
;
692 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_PUBLIC
)) {
693 state
->handler
= notation2
;
694 return XML_ROLE_NOTATION_NONE
;
698 return common(state
, tok
);
702 notation2(PROLOG_STATE
*state
,
709 case XML_TOK_PROLOG_S
:
710 return XML_ROLE_NOTATION_NONE
;
711 case XML_TOK_LITERAL
:
712 state
->handler
= notation4
;
713 return XML_ROLE_NOTATION_PUBLIC_ID
;
715 return common(state
, tok
);
719 notation3(PROLOG_STATE
*state
,
726 case XML_TOK_PROLOG_S
:
727 return XML_ROLE_NOTATION_NONE
;
728 case XML_TOK_LITERAL
:
729 state
->handler
= declClose
;
730 state
->role_none
= XML_ROLE_NOTATION_NONE
;
731 return XML_ROLE_NOTATION_SYSTEM_ID
;
733 return common(state
, tok
);
737 notation4(PROLOG_STATE
*state
,
744 case XML_TOK_PROLOG_S
:
745 return XML_ROLE_NOTATION_NONE
;
746 case XML_TOK_LITERAL
:
747 state
->handler
= declClose
;
748 state
->role_none
= XML_ROLE_NOTATION_NONE
;
749 return XML_ROLE_NOTATION_SYSTEM_ID
;
750 case XML_TOK_DECL_CLOSE
:
752 return XML_ROLE_NOTATION_NO_SYSTEM_ID
;
754 return common(state
, tok
);
758 attlist0(PROLOG_STATE
*state
,
765 case XML_TOK_PROLOG_S
:
766 return XML_ROLE_ATTLIST_NONE
;
768 case XML_TOK_PREFIXED_NAME
:
769 state
->handler
= attlist1
;
770 return XML_ROLE_ATTLIST_ELEMENT_NAME
;
772 return common(state
, tok
);
776 attlist1(PROLOG_STATE
*state
,
783 case XML_TOK_PROLOG_S
:
784 return XML_ROLE_ATTLIST_NONE
;
785 case XML_TOK_DECL_CLOSE
:
787 return XML_ROLE_ATTLIST_NONE
;
789 case XML_TOK_PREFIXED_NAME
:
790 state
->handler
= attlist2
;
791 return XML_ROLE_ATTRIBUTE_NAME
;
793 return common(state
, tok
);
797 attlist2(PROLOG_STATE
*state
,
804 case XML_TOK_PROLOG_S
:
805 return XML_ROLE_ATTLIST_NONE
;
808 static const char * const types
[] = {
819 for (i
= 0; i
< (int)(sizeof(types
)/sizeof(types
[0])); i
++)
820 if (XmlNameMatchesAscii(enc
, ptr
, end
, types
[i
])) {
821 state
->handler
= attlist8
;
822 return XML_ROLE_ATTRIBUTE_TYPE_CDATA
+ i
;
825 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_NOTATION
)) {
826 state
->handler
= attlist5
;
827 return XML_ROLE_ATTLIST_NONE
;
830 case XML_TOK_OPEN_PAREN
:
831 state
->handler
= attlist3
;
832 return XML_ROLE_ATTLIST_NONE
;
834 return common(state
, tok
);
838 attlist3(PROLOG_STATE
*state
,
845 case XML_TOK_PROLOG_S
:
846 return XML_ROLE_ATTLIST_NONE
;
847 case XML_TOK_NMTOKEN
:
849 case XML_TOK_PREFIXED_NAME
:
850 state
->handler
= attlist4
;
851 return XML_ROLE_ATTRIBUTE_ENUM_VALUE
;
853 return common(state
, tok
);
857 attlist4(PROLOG_STATE
*state
,
864 case XML_TOK_PROLOG_S
:
865 return XML_ROLE_ATTLIST_NONE
;
866 case XML_TOK_CLOSE_PAREN
:
867 state
->handler
= attlist8
;
868 return XML_ROLE_ATTLIST_NONE
;
870 state
->handler
= attlist3
;
871 return XML_ROLE_ATTLIST_NONE
;
873 return common(state
, tok
);
877 attlist5(PROLOG_STATE
*state
,
884 case XML_TOK_PROLOG_S
:
885 return XML_ROLE_ATTLIST_NONE
;
886 case XML_TOK_OPEN_PAREN
:
887 state
->handler
= attlist6
;
888 return XML_ROLE_ATTLIST_NONE
;
890 return common(state
, tok
);
894 attlist6(PROLOG_STATE
*state
,
901 case XML_TOK_PROLOG_S
:
902 return XML_ROLE_ATTLIST_NONE
;
904 state
->handler
= attlist7
;
905 return XML_ROLE_ATTRIBUTE_NOTATION_VALUE
;
907 return common(state
, tok
);
911 attlist7(PROLOG_STATE
*state
,
918 case XML_TOK_PROLOG_S
:
919 return XML_ROLE_ATTLIST_NONE
;
920 case XML_TOK_CLOSE_PAREN
:
921 state
->handler
= attlist8
;
922 return XML_ROLE_ATTLIST_NONE
;
924 state
->handler
= attlist6
;
925 return XML_ROLE_ATTLIST_NONE
;
927 return common(state
, tok
);
932 attlist8(PROLOG_STATE
*state
,
939 case XML_TOK_PROLOG_S
:
940 return XML_ROLE_ATTLIST_NONE
;
941 case XML_TOK_POUND_NAME
:
942 if (XmlNameMatchesAscii(enc
,
943 ptr
+ MIN_BYTES_PER_CHAR(enc
),
946 state
->handler
= attlist1
;
947 return XML_ROLE_IMPLIED_ATTRIBUTE_VALUE
;
949 if (XmlNameMatchesAscii(enc
,
950 ptr
+ MIN_BYTES_PER_CHAR(enc
),
953 state
->handler
= attlist1
;
954 return XML_ROLE_REQUIRED_ATTRIBUTE_VALUE
;
956 if (XmlNameMatchesAscii(enc
,
957 ptr
+ MIN_BYTES_PER_CHAR(enc
),
960 state
->handler
= attlist9
;
961 return XML_ROLE_ATTLIST_NONE
;
964 case XML_TOK_LITERAL
:
965 state
->handler
= attlist1
;
966 return XML_ROLE_DEFAULT_ATTRIBUTE_VALUE
;
968 return common(state
, tok
);
972 attlist9(PROLOG_STATE
*state
,
979 case XML_TOK_PROLOG_S
:
980 return XML_ROLE_ATTLIST_NONE
;
981 case XML_TOK_LITERAL
:
982 state
->handler
= attlist1
;
983 return XML_ROLE_FIXED_ATTRIBUTE_VALUE
;
985 return common(state
, tok
);
989 element0(PROLOG_STATE
*state
,
996 case XML_TOK_PROLOG_S
:
997 return XML_ROLE_ELEMENT_NONE
;
999 case XML_TOK_PREFIXED_NAME
:
1000 state
->handler
= element1
;
1001 return XML_ROLE_ELEMENT_NAME
;
1003 return common(state
, tok
);
1007 element1(PROLOG_STATE
*state
,
1011 const ENCODING
*enc
)
1014 case XML_TOK_PROLOG_S
:
1015 return XML_ROLE_ELEMENT_NONE
;
1017 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_EMPTY
)) {
1018 state
->handler
= declClose
;
1019 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1020 return XML_ROLE_CONTENT_EMPTY
;
1022 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_ANY
)) {
1023 state
->handler
= declClose
;
1024 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1025 return XML_ROLE_CONTENT_ANY
;
1028 case XML_TOK_OPEN_PAREN
:
1029 state
->handler
= element2
;
1031 return XML_ROLE_GROUP_OPEN
;
1033 return common(state
, tok
);
1037 element2(PROLOG_STATE
*state
,
1041 const ENCODING
*enc
)
1044 case XML_TOK_PROLOG_S
:
1045 return XML_ROLE_ELEMENT_NONE
;
1046 case XML_TOK_POUND_NAME
:
1047 if (XmlNameMatchesAscii(enc
,
1048 ptr
+ MIN_BYTES_PER_CHAR(enc
),
1051 state
->handler
= element3
;
1052 return XML_ROLE_CONTENT_PCDATA
;
1055 case XML_TOK_OPEN_PAREN
:
1057 state
->handler
= element6
;
1058 return XML_ROLE_GROUP_OPEN
;
1060 case XML_TOK_PREFIXED_NAME
:
1061 state
->handler
= element7
;
1062 return XML_ROLE_CONTENT_ELEMENT
;
1063 case XML_TOK_NAME_QUESTION
:
1064 state
->handler
= element7
;
1065 return XML_ROLE_CONTENT_ELEMENT_OPT
;
1066 case XML_TOK_NAME_ASTERISK
:
1067 state
->handler
= element7
;
1068 return XML_ROLE_CONTENT_ELEMENT_REP
;
1069 case XML_TOK_NAME_PLUS
:
1070 state
->handler
= element7
;
1071 return XML_ROLE_CONTENT_ELEMENT_PLUS
;
1073 return common(state
, tok
);
1077 element3(PROLOG_STATE
*state
,
1081 const ENCODING
*enc
)
1084 case XML_TOK_PROLOG_S
:
1085 return XML_ROLE_ELEMENT_NONE
;
1086 case XML_TOK_CLOSE_PAREN
:
1087 state
->handler
= declClose
;
1088 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1089 return XML_ROLE_GROUP_CLOSE
;
1090 case XML_TOK_CLOSE_PAREN_ASTERISK
:
1091 state
->handler
= declClose
;
1092 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1093 return XML_ROLE_GROUP_CLOSE_REP
;
1095 state
->handler
= element4
;
1096 return XML_ROLE_ELEMENT_NONE
;
1098 return common(state
, tok
);
1102 element4(PROLOG_STATE
*state
,
1106 const ENCODING
*enc
)
1109 case XML_TOK_PROLOG_S
:
1110 return XML_ROLE_ELEMENT_NONE
;
1112 case XML_TOK_PREFIXED_NAME
:
1113 state
->handler
= element5
;
1114 return XML_ROLE_CONTENT_ELEMENT
;
1116 return common(state
, tok
);
1120 element5(PROLOG_STATE
*state
,
1124 const ENCODING
*enc
)
1127 case XML_TOK_PROLOG_S
:
1128 return XML_ROLE_ELEMENT_NONE
;
1129 case XML_TOK_CLOSE_PAREN_ASTERISK
:
1130 state
->handler
= declClose
;
1131 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1132 return XML_ROLE_GROUP_CLOSE_REP
;
1134 state
->handler
= element4
;
1135 return XML_ROLE_ELEMENT_NONE
;
1137 return common(state
, tok
);
1141 element6(PROLOG_STATE
*state
,
1145 const ENCODING
*enc
)
1148 case XML_TOK_PROLOG_S
:
1149 return XML_ROLE_ELEMENT_NONE
;
1150 case XML_TOK_OPEN_PAREN
:
1152 return XML_ROLE_GROUP_OPEN
;
1154 case XML_TOK_PREFIXED_NAME
:
1155 state
->handler
= element7
;
1156 return XML_ROLE_CONTENT_ELEMENT
;
1157 case XML_TOK_NAME_QUESTION
:
1158 state
->handler
= element7
;
1159 return XML_ROLE_CONTENT_ELEMENT_OPT
;
1160 case XML_TOK_NAME_ASTERISK
:
1161 state
->handler
= element7
;
1162 return XML_ROLE_CONTENT_ELEMENT_REP
;
1163 case XML_TOK_NAME_PLUS
:
1164 state
->handler
= element7
;
1165 return XML_ROLE_CONTENT_ELEMENT_PLUS
;
1167 return common(state
, tok
);
1171 element7(PROLOG_STATE
*state
,
1175 const ENCODING
*enc
)
1178 case XML_TOK_PROLOG_S
:
1179 return XML_ROLE_ELEMENT_NONE
;
1180 case XML_TOK_CLOSE_PAREN
:
1182 if (state
->level
== 0) {
1183 state
->handler
= declClose
;
1184 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1186 return XML_ROLE_GROUP_CLOSE
;
1187 case XML_TOK_CLOSE_PAREN_ASTERISK
:
1189 if (state
->level
== 0) {
1190 state
->handler
= declClose
;
1191 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1193 return XML_ROLE_GROUP_CLOSE_REP
;
1194 case XML_TOK_CLOSE_PAREN_QUESTION
:
1196 if (state
->level
== 0) {
1197 state
->handler
= declClose
;
1198 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1200 return XML_ROLE_GROUP_CLOSE_OPT
;
1201 case XML_TOK_CLOSE_PAREN_PLUS
:
1203 if (state
->level
== 0) {
1204 state
->handler
= declClose
;
1205 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1207 return XML_ROLE_GROUP_CLOSE_PLUS
;
1209 state
->handler
= element6
;
1210 return XML_ROLE_GROUP_SEQUENCE
;
1212 state
->handler
= element6
;
1213 return XML_ROLE_GROUP_CHOICE
;
1215 return common(state
, tok
);
1221 condSect0(PROLOG_STATE
*state
,
1225 const ENCODING
*enc
)
1228 case XML_TOK_PROLOG_S
:
1229 return XML_ROLE_NONE
;
1231 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_INCLUDE
)) {
1232 state
->handler
= condSect1
;
1233 return XML_ROLE_NONE
;
1235 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_IGNORE
)) {
1236 state
->handler
= condSect2
;
1237 return XML_ROLE_NONE
;
1241 return common(state
, tok
);
1245 condSect1(PROLOG_STATE
*state
,
1249 const ENCODING
*enc
)
1252 case XML_TOK_PROLOG_S
:
1253 return XML_ROLE_NONE
;
1254 case XML_TOK_OPEN_BRACKET
:
1255 state
->handler
= externalSubset1
;
1256 state
->includeLevel
+= 1;
1257 return XML_ROLE_NONE
;
1259 return common(state
, tok
);
1263 condSect2(PROLOG_STATE
*state
,
1267 const ENCODING
*enc
)
1270 case XML_TOK_PROLOG_S
:
1271 return XML_ROLE_NONE
;
1272 case XML_TOK_OPEN_BRACKET
:
1273 state
->handler
= externalSubset1
;
1274 return XML_ROLE_IGNORE_SECT
;
1276 return common(state
, tok
);
1279 #endif /* XML_DTD */
1282 declClose(PROLOG_STATE
*state
,
1286 const ENCODING
*enc
)
1289 case XML_TOK_PROLOG_S
:
1290 return state
->role_none
;
1291 case XML_TOK_DECL_CLOSE
:
1293 return state
->role_none
;
1295 return common(state
, tok
);
1299 error(PROLOG_STATE
*state
,
1303 const ENCODING
*enc
)
1305 return XML_ROLE_NONE
;
1309 common(PROLOG_STATE
*state
, int tok
)
1312 if (!state
->documentEntity
&& tok
== XML_TOK_PARAM_ENTITY_REF
)
1313 return XML_ROLE_INNER_PARAM_ENTITY_REF
;
1315 state
->handler
= error
;
1316 return XML_ROLE_ERROR
;
1320 XmlPrologStateInit(PROLOG_STATE
*state
)
1322 state
->handler
= prolog0
;
1324 state
->documentEntity
= 1;
1325 state
->includeLevel
= 0;
1326 state
->inEntityValue
= 0;
1327 #endif /* XML_DTD */
1333 XmlPrologStateInitExternalEntity(PROLOG_STATE
*state
)
1335 state
->handler
= externalSubset0
;
1336 state
->documentEntity
= 0;
1337 state
->includeLevel
= 0;
1340 #endif /* XML_DTD */