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(__WATCOMC__)
14 #include "watcomconfig.h"
16 #ifdef HAVE_EXPAT_CONFIG_H
17 #include <expat_config.h>
19 #endif /* ndef COMPILED_FROM_DSP */
21 #include "expat_external.h"
28 that ,| are not mixed in a model group
33 static const char KW_ANY
[] = {
34 ASCII_A
, ASCII_N
, ASCII_Y
, '\0' };
35 static const char KW_ATTLIST
[] = {
36 ASCII_A
, ASCII_T
, ASCII_T
, ASCII_L
, ASCII_I
, ASCII_S
, ASCII_T
, '\0' };
37 static const char KW_CDATA
[] = {
38 ASCII_C
, ASCII_D
, ASCII_A
, ASCII_T
, ASCII_A
, '\0' };
39 static const char KW_DOCTYPE
[] = {
40 ASCII_D
, ASCII_O
, ASCII_C
, ASCII_T
, ASCII_Y
, ASCII_P
, ASCII_E
, '\0' };
41 static const char KW_ELEMENT
[] = {
42 ASCII_E
, ASCII_L
, ASCII_E
, ASCII_M
, ASCII_E
, ASCII_N
, ASCII_T
, '\0' };
43 static const char KW_EMPTY
[] = {
44 ASCII_E
, ASCII_M
, ASCII_P
, ASCII_T
, ASCII_Y
, '\0' };
45 static const char KW_ENTITIES
[] = {
46 ASCII_E
, ASCII_N
, ASCII_T
, ASCII_I
, ASCII_T
, ASCII_I
, ASCII_E
, ASCII_S
,
48 static const char KW_ENTITY
[] = {
49 ASCII_E
, ASCII_N
, ASCII_T
, ASCII_I
, ASCII_T
, ASCII_Y
, '\0' };
50 static const char KW_FIXED
[] = {
51 ASCII_F
, ASCII_I
, ASCII_X
, ASCII_E
, ASCII_D
, '\0' };
52 static const char KW_ID
[] = {
53 ASCII_I
, ASCII_D
, '\0' };
54 static const char KW_IDREF
[] = {
55 ASCII_I
, ASCII_D
, ASCII_R
, ASCII_E
, ASCII_F
, '\0' };
56 static const char KW_IDREFS
[] = {
57 ASCII_I
, ASCII_D
, ASCII_R
, ASCII_E
, ASCII_F
, ASCII_S
, '\0' };
59 static const char KW_IGNORE
[] = {
60 ASCII_I
, ASCII_G
, ASCII_N
, ASCII_O
, ASCII_R
, ASCII_E
, '\0' };
62 static const char KW_IMPLIED
[] = {
63 ASCII_I
, ASCII_M
, ASCII_P
, ASCII_L
, ASCII_I
, ASCII_E
, ASCII_D
, '\0' };
65 static const char KW_INCLUDE
[] = {
66 ASCII_I
, ASCII_N
, ASCII_C
, ASCII_L
, ASCII_U
, ASCII_D
, ASCII_E
, '\0' };
68 static const char KW_NDATA
[] = {
69 ASCII_N
, ASCII_D
, ASCII_A
, ASCII_T
, ASCII_A
, '\0' };
70 static const char KW_NMTOKEN
[] = {
71 ASCII_N
, ASCII_M
, ASCII_T
, ASCII_O
, ASCII_K
, ASCII_E
, ASCII_N
, '\0' };
72 static const char KW_NMTOKENS
[] = {
73 ASCII_N
, ASCII_M
, ASCII_T
, ASCII_O
, ASCII_K
, ASCII_E
, ASCII_N
, ASCII_S
,
75 static const char KW_NOTATION
[] =
76 { ASCII_N
, ASCII_O
, ASCII_T
, ASCII_A
, ASCII_T
, ASCII_I
, ASCII_O
, ASCII_N
,
78 static const char KW_PCDATA
[] = {
79 ASCII_P
, ASCII_C
, ASCII_D
, ASCII_A
, ASCII_T
, ASCII_A
, '\0' };
80 static const char KW_PUBLIC
[] = {
81 ASCII_P
, ASCII_U
, ASCII_B
, ASCII_L
, ASCII_I
, ASCII_C
, '\0' };
82 static const char KW_REQUIRED
[] = {
83 ASCII_R
, ASCII_E
, ASCII_Q
, ASCII_U
, ASCII_I
, ASCII_R
, ASCII_E
, ASCII_D
,
85 static const char KW_SYSTEM
[] = {
86 ASCII_S
, ASCII_Y
, ASCII_S
, ASCII_T
, ASCII_E
, ASCII_M
, '\0' };
88 #ifndef MIN_BYTES_PER_CHAR
89 #define MIN_BYTES_PER_CHAR(enc) ((enc)->minBytesPerChar)
93 #define setTopLevel(state) \
94 ((state)->handler = ((state)->documentEntity \
97 #else /* not XML_DTD */
98 #define setTopLevel(state) ((state)->handler = internalSubset)
99 #endif /* not XML_DTD */
101 typedef int PTRCALL
PROLOG_HANDLER(PROLOG_STATE
*state
,
105 const ENCODING
*enc
);
107 static PROLOG_HANDLER
108 prolog0
, prolog1
, prolog2
,
109 doctype0
, doctype1
, doctype2
, doctype3
, doctype4
, doctype5
,
111 entity0
, entity1
, entity2
, entity3
, entity4
, entity5
, entity6
,
112 entity7
, entity8
, entity9
, entity10
,
113 notation0
, notation1
, notation2
, notation3
, notation4
,
114 attlist0
, attlist1
, attlist2
, attlist3
, attlist4
, attlist5
, attlist6
,
115 attlist7
, attlist8
, attlist9
,
116 element0
, element1
, element2
, element3
, element4
, element5
, element6
,
119 externalSubset0
, externalSubset1
,
120 condSect0
, condSect1
, condSect2
,
125 static int FASTCALL
common(PROLOG_STATE
*state
, int tok
);
128 prolog0(PROLOG_STATE
*state
,
135 case XML_TOK_PROLOG_S
:
136 state
->handler
= prolog1
;
137 return XML_ROLE_NONE
;
138 case XML_TOK_XML_DECL
:
139 state
->handler
= prolog1
;
140 return XML_ROLE_XML_DECL
;
142 state
->handler
= prolog1
;
144 case XML_TOK_COMMENT
:
145 state
->handler
= prolog1
;
146 return XML_ROLE_COMMENT
;
148 return XML_ROLE_NONE
;
149 case XML_TOK_DECL_OPEN
:
150 if (!XmlNameMatchesAscii(enc
,
151 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
155 state
->handler
= doctype0
;
156 return XML_ROLE_DOCTYPE_NONE
;
157 case XML_TOK_INSTANCE_START
:
158 state
->handler
= error
;
159 return XML_ROLE_INSTANCE_START
;
161 return common(state
, tok
);
165 prolog1(PROLOG_STATE
*state
,
172 case XML_TOK_PROLOG_S
:
173 return XML_ROLE_NONE
;
176 case XML_TOK_COMMENT
:
177 return XML_ROLE_COMMENT
;
179 return XML_ROLE_NONE
;
180 case XML_TOK_DECL_OPEN
:
181 if (!XmlNameMatchesAscii(enc
,
182 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
186 state
->handler
= doctype0
;
187 return XML_ROLE_DOCTYPE_NONE
;
188 case XML_TOK_INSTANCE_START
:
189 state
->handler
= error
;
190 return XML_ROLE_INSTANCE_START
;
192 return common(state
, tok
);
196 prolog2(PROLOG_STATE
*state
,
203 case XML_TOK_PROLOG_S
:
204 return XML_ROLE_NONE
;
207 case XML_TOK_COMMENT
:
208 return XML_ROLE_COMMENT
;
209 case XML_TOK_INSTANCE_START
:
210 state
->handler
= error
;
211 return XML_ROLE_INSTANCE_START
;
213 return common(state
, tok
);
217 doctype0(PROLOG_STATE
*state
,
224 case XML_TOK_PROLOG_S
:
225 return XML_ROLE_DOCTYPE_NONE
;
227 case XML_TOK_PREFIXED_NAME
:
228 state
->handler
= doctype1
;
229 return XML_ROLE_DOCTYPE_NAME
;
231 return common(state
, tok
);
235 doctype1(PROLOG_STATE
*state
,
242 case XML_TOK_PROLOG_S
:
243 return XML_ROLE_DOCTYPE_NONE
;
244 case XML_TOK_OPEN_BRACKET
:
245 state
->handler
= internalSubset
;
246 return XML_ROLE_DOCTYPE_INTERNAL_SUBSET
;
247 case XML_TOK_DECL_CLOSE
:
248 state
->handler
= prolog2
;
249 return XML_ROLE_DOCTYPE_CLOSE
;
251 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_SYSTEM
)) {
252 state
->handler
= doctype3
;
253 return XML_ROLE_DOCTYPE_NONE
;
255 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_PUBLIC
)) {
256 state
->handler
= doctype2
;
257 return XML_ROLE_DOCTYPE_NONE
;
261 return common(state
, tok
);
265 doctype2(PROLOG_STATE
*state
,
272 case XML_TOK_PROLOG_S
:
273 return XML_ROLE_DOCTYPE_NONE
;
274 case XML_TOK_LITERAL
:
275 state
->handler
= doctype3
;
276 return XML_ROLE_DOCTYPE_PUBLIC_ID
;
278 return common(state
, tok
);
282 doctype3(PROLOG_STATE
*state
,
289 case XML_TOK_PROLOG_S
:
290 return XML_ROLE_DOCTYPE_NONE
;
291 case XML_TOK_LITERAL
:
292 state
->handler
= doctype4
;
293 return XML_ROLE_DOCTYPE_SYSTEM_ID
;
295 return common(state
, tok
);
299 doctype4(PROLOG_STATE
*state
,
306 case XML_TOK_PROLOG_S
:
307 return XML_ROLE_DOCTYPE_NONE
;
308 case XML_TOK_OPEN_BRACKET
:
309 state
->handler
= internalSubset
;
310 return XML_ROLE_DOCTYPE_INTERNAL_SUBSET
;
311 case XML_TOK_DECL_CLOSE
:
312 state
->handler
= prolog2
;
313 return XML_ROLE_DOCTYPE_CLOSE
;
315 return common(state
, tok
);
319 doctype5(PROLOG_STATE
*state
,
326 case XML_TOK_PROLOG_S
:
327 return XML_ROLE_DOCTYPE_NONE
;
328 case XML_TOK_DECL_CLOSE
:
329 state
->handler
= prolog2
;
330 return XML_ROLE_DOCTYPE_CLOSE
;
332 return common(state
, tok
);
336 internalSubset(PROLOG_STATE
*state
,
343 case XML_TOK_PROLOG_S
:
344 return XML_ROLE_NONE
;
345 case XML_TOK_DECL_OPEN
:
346 if (XmlNameMatchesAscii(enc
,
347 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
350 state
->handler
= entity0
;
351 return XML_ROLE_ENTITY_NONE
;
353 if (XmlNameMatchesAscii(enc
,
354 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
357 state
->handler
= attlist0
;
358 return XML_ROLE_ATTLIST_NONE
;
360 if (XmlNameMatchesAscii(enc
,
361 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
364 state
->handler
= element0
;
365 return XML_ROLE_ELEMENT_NONE
;
367 if (XmlNameMatchesAscii(enc
,
368 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
371 state
->handler
= notation0
;
372 return XML_ROLE_NOTATION_NONE
;
377 case XML_TOK_COMMENT
:
378 return XML_ROLE_COMMENT
;
379 case XML_TOK_PARAM_ENTITY_REF
:
380 return XML_ROLE_PARAM_ENTITY_REF
;
381 case XML_TOK_CLOSE_BRACKET
:
382 state
->handler
= doctype5
;
383 return XML_ROLE_DOCTYPE_NONE
;
385 return XML_ROLE_NONE
;
387 return common(state
, tok
);
393 externalSubset0(PROLOG_STATE
*state
,
399 state
->handler
= externalSubset1
;
400 if (tok
== XML_TOK_XML_DECL
)
401 return XML_ROLE_TEXT_DECL
;
402 return externalSubset1(state
, tok
, ptr
, end
, enc
);
406 externalSubset1(PROLOG_STATE
*state
,
413 case XML_TOK_COND_SECT_OPEN
:
414 state
->handler
= condSect0
;
415 return XML_ROLE_NONE
;
416 case XML_TOK_COND_SECT_CLOSE
:
417 if (state
->includeLevel
== 0)
419 state
->includeLevel
-= 1;
420 return XML_ROLE_NONE
;
421 case XML_TOK_PROLOG_S
:
422 return XML_ROLE_NONE
;
423 case XML_TOK_CLOSE_BRACKET
:
426 if (state
->includeLevel
)
428 return XML_ROLE_NONE
;
430 return internalSubset(state
, tok
, ptr
, end
, enc
);
432 return common(state
, tok
);
438 entity0(PROLOG_STATE
*state
,
445 case XML_TOK_PROLOG_S
:
446 return XML_ROLE_ENTITY_NONE
;
447 case XML_TOK_PERCENT
:
448 state
->handler
= entity1
;
449 return XML_ROLE_ENTITY_NONE
;
451 state
->handler
= entity2
;
452 return XML_ROLE_GENERAL_ENTITY_NAME
;
454 return common(state
, tok
);
458 entity1(PROLOG_STATE
*state
,
465 case XML_TOK_PROLOG_S
:
466 return XML_ROLE_ENTITY_NONE
;
468 state
->handler
= entity7
;
469 return XML_ROLE_PARAM_ENTITY_NAME
;
471 return common(state
, tok
);
475 entity2(PROLOG_STATE
*state
,
482 case XML_TOK_PROLOG_S
:
483 return XML_ROLE_ENTITY_NONE
;
485 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_SYSTEM
)) {
486 state
->handler
= entity4
;
487 return XML_ROLE_ENTITY_NONE
;
489 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_PUBLIC
)) {
490 state
->handler
= entity3
;
491 return XML_ROLE_ENTITY_NONE
;
494 case XML_TOK_LITERAL
:
495 state
->handler
= declClose
;
496 state
->role_none
= XML_ROLE_ENTITY_NONE
;
497 return XML_ROLE_ENTITY_VALUE
;
499 return common(state
, tok
);
503 entity3(PROLOG_STATE
*state
,
510 case XML_TOK_PROLOG_S
:
511 return XML_ROLE_ENTITY_NONE
;
512 case XML_TOK_LITERAL
:
513 state
->handler
= entity4
;
514 return XML_ROLE_ENTITY_PUBLIC_ID
;
516 return common(state
, tok
);
520 entity4(PROLOG_STATE
*state
,
527 case XML_TOK_PROLOG_S
:
528 return XML_ROLE_ENTITY_NONE
;
529 case XML_TOK_LITERAL
:
530 state
->handler
= entity5
;
531 return XML_ROLE_ENTITY_SYSTEM_ID
;
533 return common(state
, tok
);
537 entity5(PROLOG_STATE
*state
,
544 case XML_TOK_PROLOG_S
:
545 return XML_ROLE_ENTITY_NONE
;
546 case XML_TOK_DECL_CLOSE
:
548 return XML_ROLE_ENTITY_COMPLETE
;
550 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_NDATA
)) {
551 state
->handler
= entity6
;
552 return XML_ROLE_ENTITY_NONE
;
556 return common(state
, tok
);
560 entity6(PROLOG_STATE
*state
,
567 case XML_TOK_PROLOG_S
:
568 return XML_ROLE_ENTITY_NONE
;
570 state
->handler
= declClose
;
571 state
->role_none
= XML_ROLE_ENTITY_NONE
;
572 return XML_ROLE_ENTITY_NOTATION_NAME
;
574 return common(state
, tok
);
578 entity7(PROLOG_STATE
*state
,
585 case XML_TOK_PROLOG_S
:
586 return XML_ROLE_ENTITY_NONE
;
588 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_SYSTEM
)) {
589 state
->handler
= entity9
;
590 return XML_ROLE_ENTITY_NONE
;
592 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_PUBLIC
)) {
593 state
->handler
= entity8
;
594 return XML_ROLE_ENTITY_NONE
;
597 case XML_TOK_LITERAL
:
598 state
->handler
= declClose
;
599 state
->role_none
= XML_ROLE_ENTITY_NONE
;
600 return XML_ROLE_ENTITY_VALUE
;
602 return common(state
, tok
);
606 entity8(PROLOG_STATE
*state
,
613 case XML_TOK_PROLOG_S
:
614 return XML_ROLE_ENTITY_NONE
;
615 case XML_TOK_LITERAL
:
616 state
->handler
= entity9
;
617 return XML_ROLE_ENTITY_PUBLIC_ID
;
619 return common(state
, tok
);
623 entity9(PROLOG_STATE
*state
,
630 case XML_TOK_PROLOG_S
:
631 return XML_ROLE_ENTITY_NONE
;
632 case XML_TOK_LITERAL
:
633 state
->handler
= entity10
;
634 return XML_ROLE_ENTITY_SYSTEM_ID
;
636 return common(state
, tok
);
640 entity10(PROLOG_STATE
*state
,
647 case XML_TOK_PROLOG_S
:
648 return XML_ROLE_ENTITY_NONE
;
649 case XML_TOK_DECL_CLOSE
:
651 return XML_ROLE_ENTITY_COMPLETE
;
653 return common(state
, tok
);
657 notation0(PROLOG_STATE
*state
,
664 case XML_TOK_PROLOG_S
:
665 return XML_ROLE_NOTATION_NONE
;
667 state
->handler
= notation1
;
668 return XML_ROLE_NOTATION_NAME
;
670 return common(state
, tok
);
674 notation1(PROLOG_STATE
*state
,
681 case XML_TOK_PROLOG_S
:
682 return XML_ROLE_NOTATION_NONE
;
684 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_SYSTEM
)) {
685 state
->handler
= notation3
;
686 return XML_ROLE_NOTATION_NONE
;
688 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_PUBLIC
)) {
689 state
->handler
= notation2
;
690 return XML_ROLE_NOTATION_NONE
;
694 return common(state
, tok
);
698 notation2(PROLOG_STATE
*state
,
705 case XML_TOK_PROLOG_S
:
706 return XML_ROLE_NOTATION_NONE
;
707 case XML_TOK_LITERAL
:
708 state
->handler
= notation4
;
709 return XML_ROLE_NOTATION_PUBLIC_ID
;
711 return common(state
, tok
);
715 notation3(PROLOG_STATE
*state
,
722 case XML_TOK_PROLOG_S
:
723 return XML_ROLE_NOTATION_NONE
;
724 case XML_TOK_LITERAL
:
725 state
->handler
= declClose
;
726 state
->role_none
= XML_ROLE_NOTATION_NONE
;
727 return XML_ROLE_NOTATION_SYSTEM_ID
;
729 return common(state
, tok
);
733 notation4(PROLOG_STATE
*state
,
740 case XML_TOK_PROLOG_S
:
741 return XML_ROLE_NOTATION_NONE
;
742 case XML_TOK_LITERAL
:
743 state
->handler
= declClose
;
744 state
->role_none
= XML_ROLE_NOTATION_NONE
;
745 return XML_ROLE_NOTATION_SYSTEM_ID
;
746 case XML_TOK_DECL_CLOSE
:
748 return XML_ROLE_NOTATION_NO_SYSTEM_ID
;
750 return common(state
, tok
);
754 attlist0(PROLOG_STATE
*state
,
761 case XML_TOK_PROLOG_S
:
762 return XML_ROLE_ATTLIST_NONE
;
764 case XML_TOK_PREFIXED_NAME
:
765 state
->handler
= attlist1
;
766 return XML_ROLE_ATTLIST_ELEMENT_NAME
;
768 return common(state
, tok
);
772 attlist1(PROLOG_STATE
*state
,
779 case XML_TOK_PROLOG_S
:
780 return XML_ROLE_ATTLIST_NONE
;
781 case XML_TOK_DECL_CLOSE
:
783 return XML_ROLE_ATTLIST_NONE
;
785 case XML_TOK_PREFIXED_NAME
:
786 state
->handler
= attlist2
;
787 return XML_ROLE_ATTRIBUTE_NAME
;
789 return common(state
, tok
);
793 attlist2(PROLOG_STATE
*state
,
800 case XML_TOK_PROLOG_S
:
801 return XML_ROLE_ATTLIST_NONE
;
804 static const char * const types
[] = {
815 for (i
= 0; i
< (int)(sizeof(types
)/sizeof(types
[0])); i
++)
816 if (XmlNameMatchesAscii(enc
, ptr
, end
, types
[i
])) {
817 state
->handler
= attlist8
;
818 return XML_ROLE_ATTRIBUTE_TYPE_CDATA
+ i
;
821 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_NOTATION
)) {
822 state
->handler
= attlist5
;
823 return XML_ROLE_ATTLIST_NONE
;
826 case XML_TOK_OPEN_PAREN
:
827 state
->handler
= attlist3
;
828 return XML_ROLE_ATTLIST_NONE
;
830 return common(state
, tok
);
834 attlist3(PROLOG_STATE
*state
,
841 case XML_TOK_PROLOG_S
:
842 return XML_ROLE_ATTLIST_NONE
;
843 case XML_TOK_NMTOKEN
:
845 case XML_TOK_PREFIXED_NAME
:
846 state
->handler
= attlist4
;
847 return XML_ROLE_ATTRIBUTE_ENUM_VALUE
;
849 return common(state
, tok
);
853 attlist4(PROLOG_STATE
*state
,
860 case XML_TOK_PROLOG_S
:
861 return XML_ROLE_ATTLIST_NONE
;
862 case XML_TOK_CLOSE_PAREN
:
863 state
->handler
= attlist8
;
864 return XML_ROLE_ATTLIST_NONE
;
866 state
->handler
= attlist3
;
867 return XML_ROLE_ATTLIST_NONE
;
869 return common(state
, tok
);
873 attlist5(PROLOG_STATE
*state
,
880 case XML_TOK_PROLOG_S
:
881 return XML_ROLE_ATTLIST_NONE
;
882 case XML_TOK_OPEN_PAREN
:
883 state
->handler
= attlist6
;
884 return XML_ROLE_ATTLIST_NONE
;
886 return common(state
, tok
);
890 attlist6(PROLOG_STATE
*state
,
897 case XML_TOK_PROLOG_S
:
898 return XML_ROLE_ATTLIST_NONE
;
900 state
->handler
= attlist7
;
901 return XML_ROLE_ATTRIBUTE_NOTATION_VALUE
;
903 return common(state
, tok
);
907 attlist7(PROLOG_STATE
*state
,
914 case XML_TOK_PROLOG_S
:
915 return XML_ROLE_ATTLIST_NONE
;
916 case XML_TOK_CLOSE_PAREN
:
917 state
->handler
= attlist8
;
918 return XML_ROLE_ATTLIST_NONE
;
920 state
->handler
= attlist6
;
921 return XML_ROLE_ATTLIST_NONE
;
923 return common(state
, tok
);
928 attlist8(PROLOG_STATE
*state
,
935 case XML_TOK_PROLOG_S
:
936 return XML_ROLE_ATTLIST_NONE
;
937 case XML_TOK_POUND_NAME
:
938 if (XmlNameMatchesAscii(enc
,
939 ptr
+ MIN_BYTES_PER_CHAR(enc
),
942 state
->handler
= attlist1
;
943 return XML_ROLE_IMPLIED_ATTRIBUTE_VALUE
;
945 if (XmlNameMatchesAscii(enc
,
946 ptr
+ MIN_BYTES_PER_CHAR(enc
),
949 state
->handler
= attlist1
;
950 return XML_ROLE_REQUIRED_ATTRIBUTE_VALUE
;
952 if (XmlNameMatchesAscii(enc
,
953 ptr
+ MIN_BYTES_PER_CHAR(enc
),
956 state
->handler
= attlist9
;
957 return XML_ROLE_ATTLIST_NONE
;
960 case XML_TOK_LITERAL
:
961 state
->handler
= attlist1
;
962 return XML_ROLE_DEFAULT_ATTRIBUTE_VALUE
;
964 return common(state
, tok
);
968 attlist9(PROLOG_STATE
*state
,
975 case XML_TOK_PROLOG_S
:
976 return XML_ROLE_ATTLIST_NONE
;
977 case XML_TOK_LITERAL
:
978 state
->handler
= attlist1
;
979 return XML_ROLE_FIXED_ATTRIBUTE_VALUE
;
981 return common(state
, tok
);
985 element0(PROLOG_STATE
*state
,
992 case XML_TOK_PROLOG_S
:
993 return XML_ROLE_ELEMENT_NONE
;
995 case XML_TOK_PREFIXED_NAME
:
996 state
->handler
= element1
;
997 return XML_ROLE_ELEMENT_NAME
;
999 return common(state
, tok
);
1003 element1(PROLOG_STATE
*state
,
1007 const ENCODING
*enc
)
1010 case XML_TOK_PROLOG_S
:
1011 return XML_ROLE_ELEMENT_NONE
;
1013 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_EMPTY
)) {
1014 state
->handler
= declClose
;
1015 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1016 return XML_ROLE_CONTENT_EMPTY
;
1018 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_ANY
)) {
1019 state
->handler
= declClose
;
1020 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1021 return XML_ROLE_CONTENT_ANY
;
1024 case XML_TOK_OPEN_PAREN
:
1025 state
->handler
= element2
;
1027 return XML_ROLE_GROUP_OPEN
;
1029 return common(state
, tok
);
1033 element2(PROLOG_STATE
*state
,
1037 const ENCODING
*enc
)
1040 case XML_TOK_PROLOG_S
:
1041 return XML_ROLE_ELEMENT_NONE
;
1042 case XML_TOK_POUND_NAME
:
1043 if (XmlNameMatchesAscii(enc
,
1044 ptr
+ MIN_BYTES_PER_CHAR(enc
),
1047 state
->handler
= element3
;
1048 return XML_ROLE_CONTENT_PCDATA
;
1051 case XML_TOK_OPEN_PAREN
:
1053 state
->handler
= element6
;
1054 return XML_ROLE_GROUP_OPEN
;
1056 case XML_TOK_PREFIXED_NAME
:
1057 state
->handler
= element7
;
1058 return XML_ROLE_CONTENT_ELEMENT
;
1059 case XML_TOK_NAME_QUESTION
:
1060 state
->handler
= element7
;
1061 return XML_ROLE_CONTENT_ELEMENT_OPT
;
1062 case XML_TOK_NAME_ASTERISK
:
1063 state
->handler
= element7
;
1064 return XML_ROLE_CONTENT_ELEMENT_REP
;
1065 case XML_TOK_NAME_PLUS
:
1066 state
->handler
= element7
;
1067 return XML_ROLE_CONTENT_ELEMENT_PLUS
;
1069 return common(state
, tok
);
1073 element3(PROLOG_STATE
*state
,
1077 const ENCODING
*enc
)
1080 case XML_TOK_PROLOG_S
:
1081 return XML_ROLE_ELEMENT_NONE
;
1082 case XML_TOK_CLOSE_PAREN
:
1083 state
->handler
= declClose
;
1084 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1085 return XML_ROLE_GROUP_CLOSE
;
1086 case XML_TOK_CLOSE_PAREN_ASTERISK
:
1087 state
->handler
= declClose
;
1088 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1089 return XML_ROLE_GROUP_CLOSE_REP
;
1091 state
->handler
= element4
;
1092 return XML_ROLE_ELEMENT_NONE
;
1094 return common(state
, tok
);
1098 element4(PROLOG_STATE
*state
,
1102 const ENCODING
*enc
)
1105 case XML_TOK_PROLOG_S
:
1106 return XML_ROLE_ELEMENT_NONE
;
1108 case XML_TOK_PREFIXED_NAME
:
1109 state
->handler
= element5
;
1110 return XML_ROLE_CONTENT_ELEMENT
;
1112 return common(state
, tok
);
1116 element5(PROLOG_STATE
*state
,
1120 const ENCODING
*enc
)
1123 case XML_TOK_PROLOG_S
:
1124 return XML_ROLE_ELEMENT_NONE
;
1125 case XML_TOK_CLOSE_PAREN_ASTERISK
:
1126 state
->handler
= declClose
;
1127 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1128 return XML_ROLE_GROUP_CLOSE_REP
;
1130 state
->handler
= element4
;
1131 return XML_ROLE_ELEMENT_NONE
;
1133 return common(state
, tok
);
1137 element6(PROLOG_STATE
*state
,
1141 const ENCODING
*enc
)
1144 case XML_TOK_PROLOG_S
:
1145 return XML_ROLE_ELEMENT_NONE
;
1146 case XML_TOK_OPEN_PAREN
:
1148 return XML_ROLE_GROUP_OPEN
;
1150 case XML_TOK_PREFIXED_NAME
:
1151 state
->handler
= element7
;
1152 return XML_ROLE_CONTENT_ELEMENT
;
1153 case XML_TOK_NAME_QUESTION
:
1154 state
->handler
= element7
;
1155 return XML_ROLE_CONTENT_ELEMENT_OPT
;
1156 case XML_TOK_NAME_ASTERISK
:
1157 state
->handler
= element7
;
1158 return XML_ROLE_CONTENT_ELEMENT_REP
;
1159 case XML_TOK_NAME_PLUS
:
1160 state
->handler
= element7
;
1161 return XML_ROLE_CONTENT_ELEMENT_PLUS
;
1163 return common(state
, tok
);
1167 element7(PROLOG_STATE
*state
,
1171 const ENCODING
*enc
)
1174 case XML_TOK_PROLOG_S
:
1175 return XML_ROLE_ELEMENT_NONE
;
1176 case XML_TOK_CLOSE_PAREN
:
1178 if (state
->level
== 0) {
1179 state
->handler
= declClose
;
1180 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1182 return XML_ROLE_GROUP_CLOSE
;
1183 case XML_TOK_CLOSE_PAREN_ASTERISK
:
1185 if (state
->level
== 0) {
1186 state
->handler
= declClose
;
1187 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1189 return XML_ROLE_GROUP_CLOSE_REP
;
1190 case XML_TOK_CLOSE_PAREN_QUESTION
:
1192 if (state
->level
== 0) {
1193 state
->handler
= declClose
;
1194 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1196 return XML_ROLE_GROUP_CLOSE_OPT
;
1197 case XML_TOK_CLOSE_PAREN_PLUS
:
1199 if (state
->level
== 0) {
1200 state
->handler
= declClose
;
1201 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1203 return XML_ROLE_GROUP_CLOSE_PLUS
;
1205 state
->handler
= element6
;
1206 return XML_ROLE_GROUP_SEQUENCE
;
1208 state
->handler
= element6
;
1209 return XML_ROLE_GROUP_CHOICE
;
1211 return common(state
, tok
);
1217 condSect0(PROLOG_STATE
*state
,
1221 const ENCODING
*enc
)
1224 case XML_TOK_PROLOG_S
:
1225 return XML_ROLE_NONE
;
1227 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_INCLUDE
)) {
1228 state
->handler
= condSect1
;
1229 return XML_ROLE_NONE
;
1231 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_IGNORE
)) {
1232 state
->handler
= condSect2
;
1233 return XML_ROLE_NONE
;
1237 return common(state
, tok
);
1241 condSect1(PROLOG_STATE
*state
,
1245 const ENCODING
*enc
)
1248 case XML_TOK_PROLOG_S
:
1249 return XML_ROLE_NONE
;
1250 case XML_TOK_OPEN_BRACKET
:
1251 state
->handler
= externalSubset1
;
1252 state
->includeLevel
+= 1;
1253 return XML_ROLE_NONE
;
1255 return common(state
, tok
);
1259 condSect2(PROLOG_STATE
*state
,
1263 const ENCODING
*enc
)
1266 case XML_TOK_PROLOG_S
:
1267 return XML_ROLE_NONE
;
1268 case XML_TOK_OPEN_BRACKET
:
1269 state
->handler
= externalSubset1
;
1270 return XML_ROLE_IGNORE_SECT
;
1272 return common(state
, tok
);
1275 #endif /* XML_DTD */
1278 declClose(PROLOG_STATE
*state
,
1282 const ENCODING
*enc
)
1285 case XML_TOK_PROLOG_S
:
1286 return state
->role_none
;
1287 case XML_TOK_DECL_CLOSE
:
1289 return state
->role_none
;
1291 return common(state
, tok
);
1295 error(PROLOG_STATE
*state
,
1299 const ENCODING
*enc
)
1301 return XML_ROLE_NONE
;
1305 common(PROLOG_STATE
*state
, int tok
)
1308 if (!state
->documentEntity
&& tok
== XML_TOK_PARAM_ENTITY_REF
)
1309 return XML_ROLE_INNER_PARAM_ENTITY_REF
;
1311 state
->handler
= error
;
1312 return XML_ROLE_ERROR
;
1316 XmlPrologStateInit(PROLOG_STATE
*state
)
1318 state
->handler
= prolog0
;
1320 state
->documentEntity
= 1;
1321 state
->includeLevel
= 0;
1322 state
->inEntityValue
= 0;
1323 #endif /* XML_DTD */
1329 XmlPrologStateInitExternalEntity(PROLOG_STATE
*state
)
1331 state
->handler
= externalSubset0
;
1332 state
->documentEntity
= 0;
1333 state
->includeLevel
= 0;
1336 #endif /* XML_DTD */