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"
11 #elif defined(__amigaos__)
12 #include "amigaconfig.h"
13 #elif defined(__AROS__)
14 #include "arosconfig.h"
15 #elif defined(__WATCOMC__)
16 #include "watcomconfig.h"
18 #ifdef HAVE_EXPAT_CONFIG_H
19 #include <expat_config.h>
21 #endif /* ndef COMPILED_FROM_DSP */
23 #include "expat_external.h"
30 that ,| are not mixed in a model group
35 static const char KW_ANY
[] = {
36 ASCII_A
, ASCII_N
, ASCII_Y
, '\0' };
37 static const char KW_ATTLIST
[] = {
38 ASCII_A
, ASCII_T
, ASCII_T
, ASCII_L
, ASCII_I
, ASCII_S
, ASCII_T
, '\0' };
39 static const char KW_CDATA
[] = {
40 ASCII_C
, ASCII_D
, ASCII_A
, ASCII_T
, ASCII_A
, '\0' };
41 static const char KW_DOCTYPE
[] = {
42 ASCII_D
, ASCII_O
, ASCII_C
, ASCII_T
, ASCII_Y
, ASCII_P
, ASCII_E
, '\0' };
43 static const char KW_ELEMENT
[] = {
44 ASCII_E
, ASCII_L
, ASCII_E
, ASCII_M
, ASCII_E
, ASCII_N
, ASCII_T
, '\0' };
45 static const char KW_EMPTY
[] = {
46 ASCII_E
, ASCII_M
, ASCII_P
, ASCII_T
, ASCII_Y
, '\0' };
47 static const char KW_ENTITIES
[] = {
48 ASCII_E
, ASCII_N
, ASCII_T
, ASCII_I
, ASCII_T
, ASCII_I
, ASCII_E
, ASCII_S
,
50 static const char KW_ENTITY
[] = {
51 ASCII_E
, ASCII_N
, ASCII_T
, ASCII_I
, ASCII_T
, ASCII_Y
, '\0' };
52 static const char KW_FIXED
[] = {
53 ASCII_F
, ASCII_I
, ASCII_X
, ASCII_E
, ASCII_D
, '\0' };
54 static const char KW_ID
[] = {
55 ASCII_I
, ASCII_D
, '\0' };
56 static const char KW_IDREF
[] = {
57 ASCII_I
, ASCII_D
, ASCII_R
, ASCII_E
, ASCII_F
, '\0' };
58 static const char KW_IDREFS
[] = {
59 ASCII_I
, ASCII_D
, ASCII_R
, ASCII_E
, ASCII_F
, ASCII_S
, '\0' };
61 static const char KW_IGNORE
[] = {
62 ASCII_I
, ASCII_G
, ASCII_N
, ASCII_O
, ASCII_R
, ASCII_E
, '\0' };
64 static const char KW_IMPLIED
[] = {
65 ASCII_I
, ASCII_M
, ASCII_P
, ASCII_L
, ASCII_I
, ASCII_E
, ASCII_D
, '\0' };
67 static const char KW_INCLUDE
[] = {
68 ASCII_I
, ASCII_N
, ASCII_C
, ASCII_L
, ASCII_U
, ASCII_D
, ASCII_E
, '\0' };
70 static const char KW_NDATA
[] = {
71 ASCII_N
, ASCII_D
, ASCII_A
, ASCII_T
, ASCII_A
, '\0' };
72 static const char KW_NMTOKEN
[] = {
73 ASCII_N
, ASCII_M
, ASCII_T
, ASCII_O
, ASCII_K
, ASCII_E
, ASCII_N
, '\0' };
74 static const char KW_NMTOKENS
[] = {
75 ASCII_N
, ASCII_M
, ASCII_T
, ASCII_O
, ASCII_K
, ASCII_E
, ASCII_N
, ASCII_S
,
77 static const char KW_NOTATION
[] =
78 { ASCII_N
, ASCII_O
, ASCII_T
, ASCII_A
, ASCII_T
, ASCII_I
, ASCII_O
, ASCII_N
,
80 static const char KW_PCDATA
[] = {
81 ASCII_P
, ASCII_C
, ASCII_D
, ASCII_A
, ASCII_T
, ASCII_A
, '\0' };
82 static const char KW_PUBLIC
[] = {
83 ASCII_P
, ASCII_U
, ASCII_B
, ASCII_L
, ASCII_I
, ASCII_C
, '\0' };
84 static const char KW_REQUIRED
[] = {
85 ASCII_R
, ASCII_E
, ASCII_Q
, ASCII_U
, ASCII_I
, ASCII_R
, ASCII_E
, ASCII_D
,
87 static const char KW_SYSTEM
[] = {
88 ASCII_S
, ASCII_Y
, ASCII_S
, ASCII_T
, ASCII_E
, ASCII_M
, '\0' };
90 #ifndef MIN_BYTES_PER_CHAR
91 #define MIN_BYTES_PER_CHAR(enc) ((enc)->minBytesPerChar)
95 #define setTopLevel(state) \
96 ((state)->handler = ((state)->documentEntity \
99 #else /* not XML_DTD */
100 #define setTopLevel(state) ((state)->handler = internalSubset)
101 #endif /* not XML_DTD */
103 typedef int PTRCALL
PROLOG_HANDLER(PROLOG_STATE
*state
,
107 const ENCODING
*enc
);
109 static PROLOG_HANDLER
110 prolog0
, prolog1
, prolog2
,
111 doctype0
, doctype1
, doctype2
, doctype3
, doctype4
, doctype5
,
113 entity0
, entity1
, entity2
, entity3
, entity4
, entity5
, entity6
,
114 entity7
, entity8
, entity9
, entity10
,
115 notation0
, notation1
, notation2
, notation3
, notation4
,
116 attlist0
, attlist1
, attlist2
, attlist3
, attlist4
, attlist5
, attlist6
,
117 attlist7
, attlist8
, attlist9
,
118 element0
, element1
, element2
, element3
, element4
, element5
, element6
,
121 externalSubset0
, externalSubset1
,
122 condSect0
, condSect1
, condSect2
,
127 static int FASTCALL
common(PROLOG_STATE
*state
, int tok
);
130 prolog0(PROLOG_STATE
*state
,
137 case XML_TOK_PROLOG_S
:
138 state
->handler
= prolog1
;
139 return XML_ROLE_NONE
;
140 case XML_TOK_XML_DECL
:
141 state
->handler
= prolog1
;
142 return XML_ROLE_XML_DECL
;
144 state
->handler
= prolog1
;
146 case XML_TOK_COMMENT
:
147 state
->handler
= prolog1
;
148 return XML_ROLE_COMMENT
;
150 return XML_ROLE_NONE
;
151 case XML_TOK_DECL_OPEN
:
152 if (!XmlNameMatchesAscii(enc
,
153 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
157 state
->handler
= doctype0
;
158 return XML_ROLE_DOCTYPE_NONE
;
159 case XML_TOK_INSTANCE_START
:
160 state
->handler
= error
;
161 return XML_ROLE_INSTANCE_START
;
163 return common(state
, tok
);
167 prolog1(PROLOG_STATE
*state
,
174 case XML_TOK_PROLOG_S
:
175 return XML_ROLE_NONE
;
178 case XML_TOK_COMMENT
:
179 return XML_ROLE_COMMENT
;
181 return XML_ROLE_NONE
;
182 case XML_TOK_DECL_OPEN
:
183 if (!XmlNameMatchesAscii(enc
,
184 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
188 state
->handler
= doctype0
;
189 return XML_ROLE_DOCTYPE_NONE
;
190 case XML_TOK_INSTANCE_START
:
191 state
->handler
= error
;
192 return XML_ROLE_INSTANCE_START
;
194 return common(state
, tok
);
198 prolog2(PROLOG_STATE
*state
,
205 case XML_TOK_PROLOG_S
:
206 return XML_ROLE_NONE
;
209 case XML_TOK_COMMENT
:
210 return XML_ROLE_COMMENT
;
211 case XML_TOK_INSTANCE_START
:
212 state
->handler
= error
;
213 return XML_ROLE_INSTANCE_START
;
215 return common(state
, tok
);
219 doctype0(PROLOG_STATE
*state
,
226 case XML_TOK_PROLOG_S
:
227 return XML_ROLE_DOCTYPE_NONE
;
229 case XML_TOK_PREFIXED_NAME
:
230 state
->handler
= doctype1
;
231 return XML_ROLE_DOCTYPE_NAME
;
233 return common(state
, tok
);
237 doctype1(PROLOG_STATE
*state
,
244 case XML_TOK_PROLOG_S
:
245 return XML_ROLE_DOCTYPE_NONE
;
246 case XML_TOK_OPEN_BRACKET
:
247 state
->handler
= internalSubset
;
248 return XML_ROLE_DOCTYPE_INTERNAL_SUBSET
;
249 case XML_TOK_DECL_CLOSE
:
250 state
->handler
= prolog2
;
251 return XML_ROLE_DOCTYPE_CLOSE
;
253 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_SYSTEM
)) {
254 state
->handler
= doctype3
;
255 return XML_ROLE_DOCTYPE_NONE
;
257 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_PUBLIC
)) {
258 state
->handler
= doctype2
;
259 return XML_ROLE_DOCTYPE_NONE
;
263 return common(state
, tok
);
267 doctype2(PROLOG_STATE
*state
,
274 case XML_TOK_PROLOG_S
:
275 return XML_ROLE_DOCTYPE_NONE
;
276 case XML_TOK_LITERAL
:
277 state
->handler
= doctype3
;
278 return XML_ROLE_DOCTYPE_PUBLIC_ID
;
280 return common(state
, tok
);
284 doctype3(PROLOG_STATE
*state
,
291 case XML_TOK_PROLOG_S
:
292 return XML_ROLE_DOCTYPE_NONE
;
293 case XML_TOK_LITERAL
:
294 state
->handler
= doctype4
;
295 return XML_ROLE_DOCTYPE_SYSTEM_ID
;
297 return common(state
, tok
);
301 doctype4(PROLOG_STATE
*state
,
308 case XML_TOK_PROLOG_S
:
309 return XML_ROLE_DOCTYPE_NONE
;
310 case XML_TOK_OPEN_BRACKET
:
311 state
->handler
= internalSubset
;
312 return XML_ROLE_DOCTYPE_INTERNAL_SUBSET
;
313 case XML_TOK_DECL_CLOSE
:
314 state
->handler
= prolog2
;
315 return XML_ROLE_DOCTYPE_CLOSE
;
317 return common(state
, tok
);
321 doctype5(PROLOG_STATE
*state
,
328 case XML_TOK_PROLOG_S
:
329 return XML_ROLE_DOCTYPE_NONE
;
330 case XML_TOK_DECL_CLOSE
:
331 state
->handler
= prolog2
;
332 return XML_ROLE_DOCTYPE_CLOSE
;
334 return common(state
, tok
);
338 internalSubset(PROLOG_STATE
*state
,
345 case XML_TOK_PROLOG_S
:
346 return XML_ROLE_NONE
;
347 case XML_TOK_DECL_OPEN
:
348 if (XmlNameMatchesAscii(enc
,
349 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
352 state
->handler
= entity0
;
353 return XML_ROLE_ENTITY_NONE
;
355 if (XmlNameMatchesAscii(enc
,
356 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
359 state
->handler
= attlist0
;
360 return XML_ROLE_ATTLIST_NONE
;
362 if (XmlNameMatchesAscii(enc
,
363 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
366 state
->handler
= element0
;
367 return XML_ROLE_ELEMENT_NONE
;
369 if (XmlNameMatchesAscii(enc
,
370 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
373 state
->handler
= notation0
;
374 return XML_ROLE_NOTATION_NONE
;
379 case XML_TOK_COMMENT
:
380 return XML_ROLE_COMMENT
;
381 case XML_TOK_PARAM_ENTITY_REF
:
382 return XML_ROLE_PARAM_ENTITY_REF
;
383 case XML_TOK_CLOSE_BRACKET
:
384 state
->handler
= doctype5
;
385 return XML_ROLE_DOCTYPE_NONE
;
387 return XML_ROLE_NONE
;
389 return common(state
, tok
);
395 externalSubset0(PROLOG_STATE
*state
,
401 state
->handler
= externalSubset1
;
402 if (tok
== XML_TOK_XML_DECL
)
403 return XML_ROLE_TEXT_DECL
;
404 return externalSubset1(state
, tok
, ptr
, end
, enc
);
408 externalSubset1(PROLOG_STATE
*state
,
415 case XML_TOK_COND_SECT_OPEN
:
416 state
->handler
= condSect0
;
417 return XML_ROLE_NONE
;
418 case XML_TOK_COND_SECT_CLOSE
:
419 if (state
->includeLevel
== 0)
421 state
->includeLevel
-= 1;
422 return XML_ROLE_NONE
;
423 case XML_TOK_PROLOG_S
:
424 return XML_ROLE_NONE
;
425 case XML_TOK_CLOSE_BRACKET
:
428 if (state
->includeLevel
)
430 return XML_ROLE_NONE
;
432 return internalSubset(state
, tok
, ptr
, end
, enc
);
434 return common(state
, tok
);
440 entity0(PROLOG_STATE
*state
,
447 case XML_TOK_PROLOG_S
:
448 return XML_ROLE_ENTITY_NONE
;
449 case XML_TOK_PERCENT
:
450 state
->handler
= entity1
;
451 return XML_ROLE_ENTITY_NONE
;
453 state
->handler
= entity2
;
454 return XML_ROLE_GENERAL_ENTITY_NAME
;
456 return common(state
, tok
);
460 entity1(PROLOG_STATE
*state
,
467 case XML_TOK_PROLOG_S
:
468 return XML_ROLE_ENTITY_NONE
;
470 state
->handler
= entity7
;
471 return XML_ROLE_PARAM_ENTITY_NAME
;
473 return common(state
, tok
);
477 entity2(PROLOG_STATE
*state
,
484 case XML_TOK_PROLOG_S
:
485 return XML_ROLE_ENTITY_NONE
;
487 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_SYSTEM
)) {
488 state
->handler
= entity4
;
489 return XML_ROLE_ENTITY_NONE
;
491 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_PUBLIC
)) {
492 state
->handler
= entity3
;
493 return XML_ROLE_ENTITY_NONE
;
496 case XML_TOK_LITERAL
:
497 state
->handler
= declClose
;
498 state
->role_none
= XML_ROLE_ENTITY_NONE
;
499 return XML_ROLE_ENTITY_VALUE
;
501 return common(state
, tok
);
505 entity3(PROLOG_STATE
*state
,
512 case XML_TOK_PROLOG_S
:
513 return XML_ROLE_ENTITY_NONE
;
514 case XML_TOK_LITERAL
:
515 state
->handler
= entity4
;
516 return XML_ROLE_ENTITY_PUBLIC_ID
;
518 return common(state
, tok
);
522 entity4(PROLOG_STATE
*state
,
529 case XML_TOK_PROLOG_S
:
530 return XML_ROLE_ENTITY_NONE
;
531 case XML_TOK_LITERAL
:
532 state
->handler
= entity5
;
533 return XML_ROLE_ENTITY_SYSTEM_ID
;
535 return common(state
, tok
);
539 entity5(PROLOG_STATE
*state
,
546 case XML_TOK_PROLOG_S
:
547 return XML_ROLE_ENTITY_NONE
;
548 case XML_TOK_DECL_CLOSE
:
550 return XML_ROLE_ENTITY_COMPLETE
;
552 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_NDATA
)) {
553 state
->handler
= entity6
;
554 return XML_ROLE_ENTITY_NONE
;
558 return common(state
, tok
);
562 entity6(PROLOG_STATE
*state
,
569 case XML_TOK_PROLOG_S
:
570 return XML_ROLE_ENTITY_NONE
;
572 state
->handler
= declClose
;
573 state
->role_none
= XML_ROLE_ENTITY_NONE
;
574 return XML_ROLE_ENTITY_NOTATION_NAME
;
576 return common(state
, tok
);
580 entity7(PROLOG_STATE
*state
,
587 case XML_TOK_PROLOG_S
:
588 return XML_ROLE_ENTITY_NONE
;
590 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_SYSTEM
)) {
591 state
->handler
= entity9
;
592 return XML_ROLE_ENTITY_NONE
;
594 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_PUBLIC
)) {
595 state
->handler
= entity8
;
596 return XML_ROLE_ENTITY_NONE
;
599 case XML_TOK_LITERAL
:
600 state
->handler
= declClose
;
601 state
->role_none
= XML_ROLE_ENTITY_NONE
;
602 return XML_ROLE_ENTITY_VALUE
;
604 return common(state
, tok
);
608 entity8(PROLOG_STATE
*state
,
615 case XML_TOK_PROLOG_S
:
616 return XML_ROLE_ENTITY_NONE
;
617 case XML_TOK_LITERAL
:
618 state
->handler
= entity9
;
619 return XML_ROLE_ENTITY_PUBLIC_ID
;
621 return common(state
, tok
);
625 entity9(PROLOG_STATE
*state
,
632 case XML_TOK_PROLOG_S
:
633 return XML_ROLE_ENTITY_NONE
;
634 case XML_TOK_LITERAL
:
635 state
->handler
= entity10
;
636 return XML_ROLE_ENTITY_SYSTEM_ID
;
638 return common(state
, tok
);
642 entity10(PROLOG_STATE
*state
,
649 case XML_TOK_PROLOG_S
:
650 return XML_ROLE_ENTITY_NONE
;
651 case XML_TOK_DECL_CLOSE
:
653 return XML_ROLE_ENTITY_COMPLETE
;
655 return common(state
, tok
);
659 notation0(PROLOG_STATE
*state
,
666 case XML_TOK_PROLOG_S
:
667 return XML_ROLE_NOTATION_NONE
;
669 state
->handler
= notation1
;
670 return XML_ROLE_NOTATION_NAME
;
672 return common(state
, tok
);
676 notation1(PROLOG_STATE
*state
,
683 case XML_TOK_PROLOG_S
:
684 return XML_ROLE_NOTATION_NONE
;
686 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_SYSTEM
)) {
687 state
->handler
= notation3
;
688 return XML_ROLE_NOTATION_NONE
;
690 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_PUBLIC
)) {
691 state
->handler
= notation2
;
692 return XML_ROLE_NOTATION_NONE
;
696 return common(state
, tok
);
700 notation2(PROLOG_STATE
*state
,
707 case XML_TOK_PROLOG_S
:
708 return XML_ROLE_NOTATION_NONE
;
709 case XML_TOK_LITERAL
:
710 state
->handler
= notation4
;
711 return XML_ROLE_NOTATION_PUBLIC_ID
;
713 return common(state
, tok
);
717 notation3(PROLOG_STATE
*state
,
724 case XML_TOK_PROLOG_S
:
725 return XML_ROLE_NOTATION_NONE
;
726 case XML_TOK_LITERAL
:
727 state
->handler
= declClose
;
728 state
->role_none
= XML_ROLE_NOTATION_NONE
;
729 return XML_ROLE_NOTATION_SYSTEM_ID
;
731 return common(state
, tok
);
735 notation4(PROLOG_STATE
*state
,
742 case XML_TOK_PROLOG_S
:
743 return XML_ROLE_NOTATION_NONE
;
744 case XML_TOK_LITERAL
:
745 state
->handler
= declClose
;
746 state
->role_none
= XML_ROLE_NOTATION_NONE
;
747 return XML_ROLE_NOTATION_SYSTEM_ID
;
748 case XML_TOK_DECL_CLOSE
:
750 return XML_ROLE_NOTATION_NO_SYSTEM_ID
;
752 return common(state
, tok
);
756 attlist0(PROLOG_STATE
*state
,
763 case XML_TOK_PROLOG_S
:
764 return XML_ROLE_ATTLIST_NONE
;
766 case XML_TOK_PREFIXED_NAME
:
767 state
->handler
= attlist1
;
768 return XML_ROLE_ATTLIST_ELEMENT_NAME
;
770 return common(state
, tok
);
774 attlist1(PROLOG_STATE
*state
,
781 case XML_TOK_PROLOG_S
:
782 return XML_ROLE_ATTLIST_NONE
;
783 case XML_TOK_DECL_CLOSE
:
785 return XML_ROLE_ATTLIST_NONE
;
787 case XML_TOK_PREFIXED_NAME
:
788 state
->handler
= attlist2
;
789 return XML_ROLE_ATTRIBUTE_NAME
;
791 return common(state
, tok
);
795 attlist2(PROLOG_STATE
*state
,
802 case XML_TOK_PROLOG_S
:
803 return XML_ROLE_ATTLIST_NONE
;
806 static const char * const types
[] = {
817 for (i
= 0; i
< (int)(sizeof(types
)/sizeof(types
[0])); i
++)
818 if (XmlNameMatchesAscii(enc
, ptr
, end
, types
[i
])) {
819 state
->handler
= attlist8
;
820 return XML_ROLE_ATTRIBUTE_TYPE_CDATA
+ i
;
823 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_NOTATION
)) {
824 state
->handler
= attlist5
;
825 return XML_ROLE_ATTLIST_NONE
;
828 case XML_TOK_OPEN_PAREN
:
829 state
->handler
= attlist3
;
830 return XML_ROLE_ATTLIST_NONE
;
832 return common(state
, tok
);
836 attlist3(PROLOG_STATE
*state
,
843 case XML_TOK_PROLOG_S
:
844 return XML_ROLE_ATTLIST_NONE
;
845 case XML_TOK_NMTOKEN
:
847 case XML_TOK_PREFIXED_NAME
:
848 state
->handler
= attlist4
;
849 return XML_ROLE_ATTRIBUTE_ENUM_VALUE
;
851 return common(state
, tok
);
855 attlist4(PROLOG_STATE
*state
,
862 case XML_TOK_PROLOG_S
:
863 return XML_ROLE_ATTLIST_NONE
;
864 case XML_TOK_CLOSE_PAREN
:
865 state
->handler
= attlist8
;
866 return XML_ROLE_ATTLIST_NONE
;
868 state
->handler
= attlist3
;
869 return XML_ROLE_ATTLIST_NONE
;
871 return common(state
, tok
);
875 attlist5(PROLOG_STATE
*state
,
882 case XML_TOK_PROLOG_S
:
883 return XML_ROLE_ATTLIST_NONE
;
884 case XML_TOK_OPEN_PAREN
:
885 state
->handler
= attlist6
;
886 return XML_ROLE_ATTLIST_NONE
;
888 return common(state
, tok
);
892 attlist6(PROLOG_STATE
*state
,
899 case XML_TOK_PROLOG_S
:
900 return XML_ROLE_ATTLIST_NONE
;
902 state
->handler
= attlist7
;
903 return XML_ROLE_ATTRIBUTE_NOTATION_VALUE
;
905 return common(state
, tok
);
909 attlist7(PROLOG_STATE
*state
,
916 case XML_TOK_PROLOG_S
:
917 return XML_ROLE_ATTLIST_NONE
;
918 case XML_TOK_CLOSE_PAREN
:
919 state
->handler
= attlist8
;
920 return XML_ROLE_ATTLIST_NONE
;
922 state
->handler
= attlist6
;
923 return XML_ROLE_ATTLIST_NONE
;
925 return common(state
, tok
);
930 attlist8(PROLOG_STATE
*state
,
937 case XML_TOK_PROLOG_S
:
938 return XML_ROLE_ATTLIST_NONE
;
939 case XML_TOK_POUND_NAME
:
940 if (XmlNameMatchesAscii(enc
,
941 ptr
+ MIN_BYTES_PER_CHAR(enc
),
944 state
->handler
= attlist1
;
945 return XML_ROLE_IMPLIED_ATTRIBUTE_VALUE
;
947 if (XmlNameMatchesAscii(enc
,
948 ptr
+ MIN_BYTES_PER_CHAR(enc
),
951 state
->handler
= attlist1
;
952 return XML_ROLE_REQUIRED_ATTRIBUTE_VALUE
;
954 if (XmlNameMatchesAscii(enc
,
955 ptr
+ MIN_BYTES_PER_CHAR(enc
),
958 state
->handler
= attlist9
;
959 return XML_ROLE_ATTLIST_NONE
;
962 case XML_TOK_LITERAL
:
963 state
->handler
= attlist1
;
964 return XML_ROLE_DEFAULT_ATTRIBUTE_VALUE
;
966 return common(state
, tok
);
970 attlist9(PROLOG_STATE
*state
,
977 case XML_TOK_PROLOG_S
:
978 return XML_ROLE_ATTLIST_NONE
;
979 case XML_TOK_LITERAL
:
980 state
->handler
= attlist1
;
981 return XML_ROLE_FIXED_ATTRIBUTE_VALUE
;
983 return common(state
, tok
);
987 element0(PROLOG_STATE
*state
,
994 case XML_TOK_PROLOG_S
:
995 return XML_ROLE_ELEMENT_NONE
;
997 case XML_TOK_PREFIXED_NAME
:
998 state
->handler
= element1
;
999 return XML_ROLE_ELEMENT_NAME
;
1001 return common(state
, tok
);
1005 element1(PROLOG_STATE
*state
,
1009 const ENCODING
*enc
)
1012 case XML_TOK_PROLOG_S
:
1013 return XML_ROLE_ELEMENT_NONE
;
1015 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_EMPTY
)) {
1016 state
->handler
= declClose
;
1017 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1018 return XML_ROLE_CONTENT_EMPTY
;
1020 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_ANY
)) {
1021 state
->handler
= declClose
;
1022 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1023 return XML_ROLE_CONTENT_ANY
;
1026 case XML_TOK_OPEN_PAREN
:
1027 state
->handler
= element2
;
1029 return XML_ROLE_GROUP_OPEN
;
1031 return common(state
, tok
);
1035 element2(PROLOG_STATE
*state
,
1039 const ENCODING
*enc
)
1042 case XML_TOK_PROLOG_S
:
1043 return XML_ROLE_ELEMENT_NONE
;
1044 case XML_TOK_POUND_NAME
:
1045 if (XmlNameMatchesAscii(enc
,
1046 ptr
+ MIN_BYTES_PER_CHAR(enc
),
1049 state
->handler
= element3
;
1050 return XML_ROLE_CONTENT_PCDATA
;
1053 case XML_TOK_OPEN_PAREN
:
1055 state
->handler
= element6
;
1056 return XML_ROLE_GROUP_OPEN
;
1058 case XML_TOK_PREFIXED_NAME
:
1059 state
->handler
= element7
;
1060 return XML_ROLE_CONTENT_ELEMENT
;
1061 case XML_TOK_NAME_QUESTION
:
1062 state
->handler
= element7
;
1063 return XML_ROLE_CONTENT_ELEMENT_OPT
;
1064 case XML_TOK_NAME_ASTERISK
:
1065 state
->handler
= element7
;
1066 return XML_ROLE_CONTENT_ELEMENT_REP
;
1067 case XML_TOK_NAME_PLUS
:
1068 state
->handler
= element7
;
1069 return XML_ROLE_CONTENT_ELEMENT_PLUS
;
1071 return common(state
, tok
);
1075 element3(PROLOG_STATE
*state
,
1079 const ENCODING
*enc
)
1082 case XML_TOK_PROLOG_S
:
1083 return XML_ROLE_ELEMENT_NONE
;
1084 case XML_TOK_CLOSE_PAREN
:
1085 state
->handler
= declClose
;
1086 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1087 return XML_ROLE_GROUP_CLOSE
;
1088 case XML_TOK_CLOSE_PAREN_ASTERISK
:
1089 state
->handler
= declClose
;
1090 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1091 return XML_ROLE_GROUP_CLOSE_REP
;
1093 state
->handler
= element4
;
1094 return XML_ROLE_ELEMENT_NONE
;
1096 return common(state
, tok
);
1100 element4(PROLOG_STATE
*state
,
1104 const ENCODING
*enc
)
1107 case XML_TOK_PROLOG_S
:
1108 return XML_ROLE_ELEMENT_NONE
;
1110 case XML_TOK_PREFIXED_NAME
:
1111 state
->handler
= element5
;
1112 return XML_ROLE_CONTENT_ELEMENT
;
1114 return common(state
, tok
);
1118 element5(PROLOG_STATE
*state
,
1122 const ENCODING
*enc
)
1125 case XML_TOK_PROLOG_S
:
1126 return XML_ROLE_ELEMENT_NONE
;
1127 case XML_TOK_CLOSE_PAREN_ASTERISK
:
1128 state
->handler
= declClose
;
1129 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1130 return XML_ROLE_GROUP_CLOSE_REP
;
1132 state
->handler
= element4
;
1133 return XML_ROLE_ELEMENT_NONE
;
1135 return common(state
, tok
);
1139 element6(PROLOG_STATE
*state
,
1143 const ENCODING
*enc
)
1146 case XML_TOK_PROLOG_S
:
1147 return XML_ROLE_ELEMENT_NONE
;
1148 case XML_TOK_OPEN_PAREN
:
1150 return XML_ROLE_GROUP_OPEN
;
1152 case XML_TOK_PREFIXED_NAME
:
1153 state
->handler
= element7
;
1154 return XML_ROLE_CONTENT_ELEMENT
;
1155 case XML_TOK_NAME_QUESTION
:
1156 state
->handler
= element7
;
1157 return XML_ROLE_CONTENT_ELEMENT_OPT
;
1158 case XML_TOK_NAME_ASTERISK
:
1159 state
->handler
= element7
;
1160 return XML_ROLE_CONTENT_ELEMENT_REP
;
1161 case XML_TOK_NAME_PLUS
:
1162 state
->handler
= element7
;
1163 return XML_ROLE_CONTENT_ELEMENT_PLUS
;
1165 return common(state
, tok
);
1169 element7(PROLOG_STATE
*state
,
1173 const ENCODING
*enc
)
1176 case XML_TOK_PROLOG_S
:
1177 return XML_ROLE_ELEMENT_NONE
;
1178 case XML_TOK_CLOSE_PAREN
:
1180 if (state
->level
== 0) {
1181 state
->handler
= declClose
;
1182 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1184 return XML_ROLE_GROUP_CLOSE
;
1185 case XML_TOK_CLOSE_PAREN_ASTERISK
:
1187 if (state
->level
== 0) {
1188 state
->handler
= declClose
;
1189 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1191 return XML_ROLE_GROUP_CLOSE_REP
;
1192 case XML_TOK_CLOSE_PAREN_QUESTION
:
1194 if (state
->level
== 0) {
1195 state
->handler
= declClose
;
1196 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1198 return XML_ROLE_GROUP_CLOSE_OPT
;
1199 case XML_TOK_CLOSE_PAREN_PLUS
:
1201 if (state
->level
== 0) {
1202 state
->handler
= declClose
;
1203 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1205 return XML_ROLE_GROUP_CLOSE_PLUS
;
1207 state
->handler
= element6
;
1208 return XML_ROLE_GROUP_SEQUENCE
;
1210 state
->handler
= element6
;
1211 return XML_ROLE_GROUP_CHOICE
;
1213 return common(state
, tok
);
1219 condSect0(PROLOG_STATE
*state
,
1223 const ENCODING
*enc
)
1226 case XML_TOK_PROLOG_S
:
1227 return XML_ROLE_NONE
;
1229 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_INCLUDE
)) {
1230 state
->handler
= condSect1
;
1231 return XML_ROLE_NONE
;
1233 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_IGNORE
)) {
1234 state
->handler
= condSect2
;
1235 return XML_ROLE_NONE
;
1239 return common(state
, tok
);
1243 condSect1(PROLOG_STATE
*state
,
1247 const ENCODING
*enc
)
1250 case XML_TOK_PROLOG_S
:
1251 return XML_ROLE_NONE
;
1252 case XML_TOK_OPEN_BRACKET
:
1253 state
->handler
= externalSubset1
;
1254 state
->includeLevel
+= 1;
1255 return XML_ROLE_NONE
;
1257 return common(state
, tok
);
1261 condSect2(PROLOG_STATE
*state
,
1265 const ENCODING
*enc
)
1268 case XML_TOK_PROLOG_S
:
1269 return XML_ROLE_NONE
;
1270 case XML_TOK_OPEN_BRACKET
:
1271 state
->handler
= externalSubset1
;
1272 return XML_ROLE_IGNORE_SECT
;
1274 return common(state
, tok
);
1277 #endif /* XML_DTD */
1280 declClose(PROLOG_STATE
*state
,
1284 const ENCODING
*enc
)
1287 case XML_TOK_PROLOG_S
:
1288 return state
->role_none
;
1289 case XML_TOK_DECL_CLOSE
:
1291 return state
->role_none
;
1293 return common(state
, tok
);
1297 error(PROLOG_STATE
*state
,
1301 const ENCODING
*enc
)
1303 return XML_ROLE_NONE
;
1307 common(PROLOG_STATE
*state
, int tok
)
1310 if (!state
->documentEntity
&& tok
== XML_TOK_PARAM_ENTITY_REF
)
1311 return XML_ROLE_INNER_PARAM_ENTITY_REF
;
1313 state
->handler
= error
;
1314 return XML_ROLE_ERROR
;
1318 XmlPrologStateInit(PROLOG_STATE
*state
)
1320 state
->handler
= prolog0
;
1322 state
->documentEntity
= 1;
1323 state
->includeLevel
= 0;
1324 state
->inEntityValue
= 0;
1325 #endif /* XML_DTD */
1331 XmlPrologStateInitExternalEntity(PROLOG_STATE
*state
)
1333 state
->handler
= externalSubset0
;
1334 state
->documentEntity
= 0;
1335 state
->includeLevel
= 0;
1338 #endif /* XML_DTD */