1 /* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
2 See the file COPYING for copying permission.
5 #ifdef COMPILED_FROM_DSP
7 #elif defined(MACOS_CLASSIC)
9 #elif defined(__amigaos4__)
10 #include "amigaconfig.h"
12 #ifdef HAVE_EXPAT_CONFIG_H
13 #include <expat_config.h>
15 #endif /* ndef COMPILED_FROM_DSP */
17 #include "expat_external.h"
24 that ,| are not mixed in a model group
29 static const char KW_ANY
[] = {
30 ASCII_A
, ASCII_N
, ASCII_Y
, '\0' };
31 static const char KW_ATTLIST
[] = {
32 ASCII_A
, ASCII_T
, ASCII_T
, ASCII_L
, ASCII_I
, ASCII_S
, ASCII_T
, '\0' };
33 static const char KW_CDATA
[] = {
34 ASCII_C
, ASCII_D
, ASCII_A
, ASCII_T
, ASCII_A
, '\0' };
35 static const char KW_DOCTYPE
[] = {
36 ASCII_D
, ASCII_O
, ASCII_C
, ASCII_T
, ASCII_Y
, ASCII_P
, ASCII_E
, '\0' };
37 static const char KW_ELEMENT
[] = {
38 ASCII_E
, ASCII_L
, ASCII_E
, ASCII_M
, ASCII_E
, ASCII_N
, ASCII_T
, '\0' };
39 static const char KW_EMPTY
[] = {
40 ASCII_E
, ASCII_M
, ASCII_P
, ASCII_T
, ASCII_Y
, '\0' };
41 static const char KW_ENTITIES
[] = {
42 ASCII_E
, ASCII_N
, ASCII_T
, ASCII_I
, ASCII_T
, ASCII_I
, ASCII_E
, ASCII_S
,
44 static const char KW_ENTITY
[] = {
45 ASCII_E
, ASCII_N
, ASCII_T
, ASCII_I
, ASCII_T
, ASCII_Y
, '\0' };
46 static const char KW_FIXED
[] = {
47 ASCII_F
, ASCII_I
, ASCII_X
, ASCII_E
, ASCII_D
, '\0' };
48 static const char KW_ID
[] = {
49 ASCII_I
, ASCII_D
, '\0' };
50 static const char KW_IDREF
[] = {
51 ASCII_I
, ASCII_D
, ASCII_R
, ASCII_E
, ASCII_F
, '\0' };
52 static const char KW_IDREFS
[] = {
53 ASCII_I
, ASCII_D
, ASCII_R
, ASCII_E
, ASCII_F
, ASCII_S
, '\0' };
54 #if !defined(__AROS__)
55 static const char KW_IGNORE
[] = {
56 ASCII_I
, ASCII_G
, ASCII_N
, ASCII_O
, ASCII_R
, ASCII_E
, '\0' };
58 static const char KW_IMPLIED
[] = {
59 ASCII_I
, ASCII_M
, ASCII_P
, ASCII_L
, ASCII_I
, ASCII_E
, ASCII_D
, '\0' };
60 #if !defined(__AROS__)
61 static const char KW_INCLUDE
[] = {
62 ASCII_I
, ASCII_N
, ASCII_C
, ASCII_L
, ASCII_U
, ASCII_D
, ASCII_E
, '\0' };
64 static const char KW_NDATA
[] = {
65 ASCII_N
, ASCII_D
, ASCII_A
, ASCII_T
, ASCII_A
, '\0' };
66 static const char KW_NMTOKEN
[] = {
67 ASCII_N
, ASCII_M
, ASCII_T
, ASCII_O
, ASCII_K
, ASCII_E
, ASCII_N
, '\0' };
68 static const char KW_NMTOKENS
[] = {
69 ASCII_N
, ASCII_M
, ASCII_T
, ASCII_O
, ASCII_K
, ASCII_E
, ASCII_N
, ASCII_S
,
71 static const char KW_NOTATION
[] =
72 { ASCII_N
, ASCII_O
, ASCII_T
, ASCII_A
, ASCII_T
, ASCII_I
, ASCII_O
, ASCII_N
,
74 static const char KW_PCDATA
[] = {
75 ASCII_P
, ASCII_C
, ASCII_D
, ASCII_A
, ASCII_T
, ASCII_A
, '\0' };
76 static const char KW_PUBLIC
[] = {
77 ASCII_P
, ASCII_U
, ASCII_B
, ASCII_L
, ASCII_I
, ASCII_C
, '\0' };
78 static const char KW_REQUIRED
[] = {
79 ASCII_R
, ASCII_E
, ASCII_Q
, ASCII_U
, ASCII_I
, ASCII_R
, ASCII_E
, ASCII_D
,
81 static const char KW_SYSTEM
[] = {
82 ASCII_S
, ASCII_Y
, ASCII_S
, ASCII_T
, ASCII_E
, ASCII_M
, '\0' };
84 #ifndef MIN_BYTES_PER_CHAR
85 #define MIN_BYTES_PER_CHAR(enc) ((enc)->minBytesPerChar)
89 #define setTopLevel(state) \
90 ((state)->handler = ((state)->documentEntity \
93 #else /* not XML_DTD */
94 #define setTopLevel(state) ((state)->handler = internalSubset)
95 #endif /* not XML_DTD */
97 typedef int PTRCALL
PROLOG_HANDLER(PROLOG_STATE
*state
,
101 const ENCODING
*enc
);
103 static PROLOG_HANDLER
104 prolog0
, prolog1
, prolog2
,
105 doctype0
, doctype1
, doctype2
, doctype3
, doctype4
, doctype5
,
107 entity0
, entity1
, entity2
, entity3
, entity4
, entity5
, entity6
,
108 entity7
, entity8
, entity9
, entity10
,
109 notation0
, notation1
, notation2
, notation3
, notation4
,
110 attlist0
, attlist1
, attlist2
, attlist3
, attlist4
, attlist5
, attlist6
,
111 attlist7
, attlist8
, attlist9
,
112 element0
, element1
, element2
, element3
, element4
, element5
, element6
,
115 externalSubset0
, externalSubset1
,
116 condSect0
, condSect1
, condSect2
,
121 static int FASTCALL
common(PROLOG_STATE
*state
, int tok
);
124 prolog0(PROLOG_STATE
*state
,
131 case XML_TOK_PROLOG_S
:
132 state
->handler
= prolog1
;
133 return XML_ROLE_NONE
;
134 case XML_TOK_XML_DECL
:
135 state
->handler
= prolog1
;
136 return XML_ROLE_XML_DECL
;
138 state
->handler
= prolog1
;
140 case XML_TOK_COMMENT
:
141 state
->handler
= prolog1
;
142 return XML_ROLE_COMMENT
;
144 return XML_ROLE_NONE
;
145 case XML_TOK_DECL_OPEN
:
146 if (!XmlNameMatchesAscii(enc
,
147 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
151 state
->handler
= doctype0
;
152 return XML_ROLE_DOCTYPE_NONE
;
153 case XML_TOK_INSTANCE_START
:
154 state
->handler
= error
;
155 return XML_ROLE_INSTANCE_START
;
157 return common(state
, tok
);
161 prolog1(PROLOG_STATE
*state
,
168 case XML_TOK_PROLOG_S
:
169 return XML_ROLE_NONE
;
172 case XML_TOK_COMMENT
:
173 return XML_ROLE_COMMENT
;
175 return XML_ROLE_NONE
;
176 case XML_TOK_DECL_OPEN
:
177 if (!XmlNameMatchesAscii(enc
,
178 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
182 state
->handler
= doctype0
;
183 return XML_ROLE_DOCTYPE_NONE
;
184 case XML_TOK_INSTANCE_START
:
185 state
->handler
= error
;
186 return XML_ROLE_INSTANCE_START
;
188 return common(state
, tok
);
192 prolog2(PROLOG_STATE
*state
,
199 case XML_TOK_PROLOG_S
:
200 return XML_ROLE_NONE
;
203 case XML_TOK_COMMENT
:
204 return XML_ROLE_COMMENT
;
205 case XML_TOK_INSTANCE_START
:
206 state
->handler
= error
;
207 return XML_ROLE_INSTANCE_START
;
209 return common(state
, tok
);
213 doctype0(PROLOG_STATE
*state
,
220 case XML_TOK_PROLOG_S
:
221 return XML_ROLE_DOCTYPE_NONE
;
223 case XML_TOK_PREFIXED_NAME
:
224 state
->handler
= doctype1
;
225 return XML_ROLE_DOCTYPE_NAME
;
227 return common(state
, tok
);
231 doctype1(PROLOG_STATE
*state
,
238 case XML_TOK_PROLOG_S
:
239 return XML_ROLE_DOCTYPE_NONE
;
240 case XML_TOK_OPEN_BRACKET
:
241 state
->handler
= internalSubset
;
242 return XML_ROLE_DOCTYPE_INTERNAL_SUBSET
;
243 case XML_TOK_DECL_CLOSE
:
244 state
->handler
= prolog2
;
245 return XML_ROLE_DOCTYPE_CLOSE
;
247 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_SYSTEM
)) {
248 state
->handler
= doctype3
;
249 return XML_ROLE_DOCTYPE_NONE
;
251 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_PUBLIC
)) {
252 state
->handler
= doctype2
;
253 return XML_ROLE_DOCTYPE_NONE
;
257 return common(state
, tok
);
261 doctype2(PROLOG_STATE
*state
,
268 case XML_TOK_PROLOG_S
:
269 return XML_ROLE_DOCTYPE_NONE
;
270 case XML_TOK_LITERAL
:
271 state
->handler
= doctype3
;
272 return XML_ROLE_DOCTYPE_PUBLIC_ID
;
274 return common(state
, tok
);
278 doctype3(PROLOG_STATE
*state
,
285 case XML_TOK_PROLOG_S
:
286 return XML_ROLE_DOCTYPE_NONE
;
287 case XML_TOK_LITERAL
:
288 state
->handler
= doctype4
;
289 return XML_ROLE_DOCTYPE_SYSTEM_ID
;
291 return common(state
, tok
);
295 doctype4(PROLOG_STATE
*state
,
302 case XML_TOK_PROLOG_S
:
303 return XML_ROLE_DOCTYPE_NONE
;
304 case XML_TOK_OPEN_BRACKET
:
305 state
->handler
= internalSubset
;
306 return XML_ROLE_DOCTYPE_INTERNAL_SUBSET
;
307 case XML_TOK_DECL_CLOSE
:
308 state
->handler
= prolog2
;
309 return XML_ROLE_DOCTYPE_CLOSE
;
311 return common(state
, tok
);
315 doctype5(PROLOG_STATE
*state
,
322 case XML_TOK_PROLOG_S
:
323 return XML_ROLE_DOCTYPE_NONE
;
324 case XML_TOK_DECL_CLOSE
:
325 state
->handler
= prolog2
;
326 return XML_ROLE_DOCTYPE_CLOSE
;
328 return common(state
, tok
);
332 internalSubset(PROLOG_STATE
*state
,
339 case XML_TOK_PROLOG_S
:
340 return XML_ROLE_NONE
;
341 case XML_TOK_DECL_OPEN
:
342 if (XmlNameMatchesAscii(enc
,
343 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
346 state
->handler
= entity0
;
347 return XML_ROLE_ENTITY_NONE
;
349 if (XmlNameMatchesAscii(enc
,
350 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
353 state
->handler
= attlist0
;
354 return XML_ROLE_ATTLIST_NONE
;
356 if (XmlNameMatchesAscii(enc
,
357 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
360 state
->handler
= element0
;
361 return XML_ROLE_ELEMENT_NONE
;
363 if (XmlNameMatchesAscii(enc
,
364 ptr
+ 2 * MIN_BYTES_PER_CHAR(enc
),
367 state
->handler
= notation0
;
368 return XML_ROLE_NOTATION_NONE
;
373 case XML_TOK_COMMENT
:
374 return XML_ROLE_COMMENT
;
375 case XML_TOK_PARAM_ENTITY_REF
:
376 return XML_ROLE_PARAM_ENTITY_REF
;
377 case XML_TOK_CLOSE_BRACKET
:
378 state
->handler
= doctype5
;
379 return XML_ROLE_DOCTYPE_NONE
;
381 return XML_ROLE_NONE
;
383 return common(state
, tok
);
389 externalSubset0(PROLOG_STATE
*state
,
395 state
->handler
= externalSubset1
;
396 if (tok
== XML_TOK_XML_DECL
)
397 return XML_ROLE_TEXT_DECL
;
398 return externalSubset1(state
, tok
, ptr
, end
, enc
);
402 externalSubset1(PROLOG_STATE
*state
,
409 case XML_TOK_COND_SECT_OPEN
:
410 state
->handler
= condSect0
;
411 return XML_ROLE_NONE
;
412 case XML_TOK_COND_SECT_CLOSE
:
413 if (state
->includeLevel
== 0)
415 state
->includeLevel
-= 1;
416 return XML_ROLE_NONE
;
417 case XML_TOK_PROLOG_S
:
418 return XML_ROLE_NONE
;
419 case XML_TOK_CLOSE_BRACKET
:
422 if (state
->includeLevel
)
424 return XML_ROLE_NONE
;
426 return internalSubset(state
, tok
, ptr
, end
, enc
);
428 return common(state
, tok
);
434 entity0(PROLOG_STATE
*state
,
441 case XML_TOK_PROLOG_S
:
442 return XML_ROLE_ENTITY_NONE
;
443 case XML_TOK_PERCENT
:
444 state
->handler
= entity1
;
445 return XML_ROLE_ENTITY_NONE
;
447 state
->handler
= entity2
;
448 return XML_ROLE_GENERAL_ENTITY_NAME
;
450 return common(state
, tok
);
454 entity1(PROLOG_STATE
*state
,
461 case XML_TOK_PROLOG_S
:
462 return XML_ROLE_ENTITY_NONE
;
464 state
->handler
= entity7
;
465 return XML_ROLE_PARAM_ENTITY_NAME
;
467 return common(state
, tok
);
471 entity2(PROLOG_STATE
*state
,
478 case XML_TOK_PROLOG_S
:
479 return XML_ROLE_ENTITY_NONE
;
481 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_SYSTEM
)) {
482 state
->handler
= entity4
;
483 return XML_ROLE_ENTITY_NONE
;
485 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_PUBLIC
)) {
486 state
->handler
= entity3
;
487 return XML_ROLE_ENTITY_NONE
;
490 case XML_TOK_LITERAL
:
491 state
->handler
= declClose
;
492 state
->role_none
= XML_ROLE_ENTITY_NONE
;
493 return XML_ROLE_ENTITY_VALUE
;
495 return common(state
, tok
);
499 entity3(PROLOG_STATE
*state
,
506 case XML_TOK_PROLOG_S
:
507 return XML_ROLE_ENTITY_NONE
;
508 case XML_TOK_LITERAL
:
509 state
->handler
= entity4
;
510 return XML_ROLE_ENTITY_PUBLIC_ID
;
512 return common(state
, tok
);
516 entity4(PROLOG_STATE
*state
,
523 case XML_TOK_PROLOG_S
:
524 return XML_ROLE_ENTITY_NONE
;
525 case XML_TOK_LITERAL
:
526 state
->handler
= entity5
;
527 return XML_ROLE_ENTITY_SYSTEM_ID
;
529 return common(state
, tok
);
533 entity5(PROLOG_STATE
*state
,
540 case XML_TOK_PROLOG_S
:
541 return XML_ROLE_ENTITY_NONE
;
542 case XML_TOK_DECL_CLOSE
:
544 return XML_ROLE_ENTITY_COMPLETE
;
546 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_NDATA
)) {
547 state
->handler
= entity6
;
548 return XML_ROLE_ENTITY_NONE
;
552 return common(state
, tok
);
556 entity6(PROLOG_STATE
*state
,
563 case XML_TOK_PROLOG_S
:
564 return XML_ROLE_ENTITY_NONE
;
566 state
->handler
= declClose
;
567 state
->role_none
= XML_ROLE_ENTITY_NONE
;
568 return XML_ROLE_ENTITY_NOTATION_NAME
;
570 return common(state
, tok
);
574 entity7(PROLOG_STATE
*state
,
581 case XML_TOK_PROLOG_S
:
582 return XML_ROLE_ENTITY_NONE
;
584 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_SYSTEM
)) {
585 state
->handler
= entity9
;
586 return XML_ROLE_ENTITY_NONE
;
588 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_PUBLIC
)) {
589 state
->handler
= entity8
;
590 return XML_ROLE_ENTITY_NONE
;
593 case XML_TOK_LITERAL
:
594 state
->handler
= declClose
;
595 state
->role_none
= XML_ROLE_ENTITY_NONE
;
596 return XML_ROLE_ENTITY_VALUE
;
598 return common(state
, tok
);
602 entity8(PROLOG_STATE
*state
,
609 case XML_TOK_PROLOG_S
:
610 return XML_ROLE_ENTITY_NONE
;
611 case XML_TOK_LITERAL
:
612 state
->handler
= entity9
;
613 return XML_ROLE_ENTITY_PUBLIC_ID
;
615 return common(state
, tok
);
619 entity9(PROLOG_STATE
*state
,
626 case XML_TOK_PROLOG_S
:
627 return XML_ROLE_ENTITY_NONE
;
628 case XML_TOK_LITERAL
:
629 state
->handler
= entity10
;
630 return XML_ROLE_ENTITY_SYSTEM_ID
;
632 return common(state
, tok
);
636 entity10(PROLOG_STATE
*state
,
643 case XML_TOK_PROLOG_S
:
644 return XML_ROLE_ENTITY_NONE
;
645 case XML_TOK_DECL_CLOSE
:
647 return XML_ROLE_ENTITY_COMPLETE
;
649 return common(state
, tok
);
653 notation0(PROLOG_STATE
*state
,
660 case XML_TOK_PROLOG_S
:
661 return XML_ROLE_NOTATION_NONE
;
663 state
->handler
= notation1
;
664 return XML_ROLE_NOTATION_NAME
;
666 return common(state
, tok
);
670 notation1(PROLOG_STATE
*state
,
677 case XML_TOK_PROLOG_S
:
678 return XML_ROLE_NOTATION_NONE
;
680 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_SYSTEM
)) {
681 state
->handler
= notation3
;
682 return XML_ROLE_NOTATION_NONE
;
684 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_PUBLIC
)) {
685 state
->handler
= notation2
;
686 return XML_ROLE_NOTATION_NONE
;
690 return common(state
, tok
);
694 notation2(PROLOG_STATE
*state
,
701 case XML_TOK_PROLOG_S
:
702 return XML_ROLE_NOTATION_NONE
;
703 case XML_TOK_LITERAL
:
704 state
->handler
= notation4
;
705 return XML_ROLE_NOTATION_PUBLIC_ID
;
707 return common(state
, tok
);
711 notation3(PROLOG_STATE
*state
,
718 case XML_TOK_PROLOG_S
:
719 return XML_ROLE_NOTATION_NONE
;
720 case XML_TOK_LITERAL
:
721 state
->handler
= declClose
;
722 state
->role_none
= XML_ROLE_NOTATION_NONE
;
723 return XML_ROLE_NOTATION_SYSTEM_ID
;
725 return common(state
, tok
);
729 notation4(PROLOG_STATE
*state
,
736 case XML_TOK_PROLOG_S
:
737 return XML_ROLE_NOTATION_NONE
;
738 case XML_TOK_LITERAL
:
739 state
->handler
= declClose
;
740 state
->role_none
= XML_ROLE_NOTATION_NONE
;
741 return XML_ROLE_NOTATION_SYSTEM_ID
;
742 case XML_TOK_DECL_CLOSE
:
744 return XML_ROLE_NOTATION_NO_SYSTEM_ID
;
746 return common(state
, tok
);
750 attlist0(PROLOG_STATE
*state
,
757 case XML_TOK_PROLOG_S
:
758 return XML_ROLE_ATTLIST_NONE
;
760 case XML_TOK_PREFIXED_NAME
:
761 state
->handler
= attlist1
;
762 return XML_ROLE_ATTLIST_ELEMENT_NAME
;
764 return common(state
, tok
);
768 attlist1(PROLOG_STATE
*state
,
775 case XML_TOK_PROLOG_S
:
776 return XML_ROLE_ATTLIST_NONE
;
777 case XML_TOK_DECL_CLOSE
:
779 return XML_ROLE_ATTLIST_NONE
;
781 case XML_TOK_PREFIXED_NAME
:
782 state
->handler
= attlist2
;
783 return XML_ROLE_ATTRIBUTE_NAME
;
785 return common(state
, tok
);
789 attlist2(PROLOG_STATE
*state
,
796 case XML_TOK_PROLOG_S
:
797 return XML_ROLE_ATTLIST_NONE
;
800 static const char * const types
[] = {
811 for (i
= 0; i
< (int)(sizeof(types
)/sizeof(types
[0])); i
++)
812 if (XmlNameMatchesAscii(enc
, ptr
, end
, types
[i
])) {
813 state
->handler
= attlist8
;
814 return XML_ROLE_ATTRIBUTE_TYPE_CDATA
+ i
;
817 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_NOTATION
)) {
818 state
->handler
= attlist5
;
819 return XML_ROLE_ATTLIST_NONE
;
822 case XML_TOK_OPEN_PAREN
:
823 state
->handler
= attlist3
;
824 return XML_ROLE_ATTLIST_NONE
;
826 return common(state
, tok
);
830 attlist3(PROLOG_STATE
*state
,
837 case XML_TOK_PROLOG_S
:
838 return XML_ROLE_ATTLIST_NONE
;
839 case XML_TOK_NMTOKEN
:
841 case XML_TOK_PREFIXED_NAME
:
842 state
->handler
= attlist4
;
843 return XML_ROLE_ATTRIBUTE_ENUM_VALUE
;
845 return common(state
, tok
);
849 attlist4(PROLOG_STATE
*state
,
856 case XML_TOK_PROLOG_S
:
857 return XML_ROLE_ATTLIST_NONE
;
858 case XML_TOK_CLOSE_PAREN
:
859 state
->handler
= attlist8
;
860 return XML_ROLE_ATTLIST_NONE
;
862 state
->handler
= attlist3
;
863 return XML_ROLE_ATTLIST_NONE
;
865 return common(state
, tok
);
869 attlist5(PROLOG_STATE
*state
,
876 case XML_TOK_PROLOG_S
:
877 return XML_ROLE_ATTLIST_NONE
;
878 case XML_TOK_OPEN_PAREN
:
879 state
->handler
= attlist6
;
880 return XML_ROLE_ATTLIST_NONE
;
882 return common(state
, tok
);
886 attlist6(PROLOG_STATE
*state
,
893 case XML_TOK_PROLOG_S
:
894 return XML_ROLE_ATTLIST_NONE
;
896 state
->handler
= attlist7
;
897 return XML_ROLE_ATTRIBUTE_NOTATION_VALUE
;
899 return common(state
, tok
);
903 attlist7(PROLOG_STATE
*state
,
910 case XML_TOK_PROLOG_S
:
911 return XML_ROLE_ATTLIST_NONE
;
912 case XML_TOK_CLOSE_PAREN
:
913 state
->handler
= attlist8
;
914 return XML_ROLE_ATTLIST_NONE
;
916 state
->handler
= attlist6
;
917 return XML_ROLE_ATTLIST_NONE
;
919 return common(state
, tok
);
924 attlist8(PROLOG_STATE
*state
,
931 case XML_TOK_PROLOG_S
:
932 return XML_ROLE_ATTLIST_NONE
;
933 case XML_TOK_POUND_NAME
:
934 if (XmlNameMatchesAscii(enc
,
935 ptr
+ MIN_BYTES_PER_CHAR(enc
),
938 state
->handler
= attlist1
;
939 return XML_ROLE_IMPLIED_ATTRIBUTE_VALUE
;
941 if (XmlNameMatchesAscii(enc
,
942 ptr
+ MIN_BYTES_PER_CHAR(enc
),
945 state
->handler
= attlist1
;
946 return XML_ROLE_REQUIRED_ATTRIBUTE_VALUE
;
948 if (XmlNameMatchesAscii(enc
,
949 ptr
+ MIN_BYTES_PER_CHAR(enc
),
952 state
->handler
= attlist9
;
953 return XML_ROLE_ATTLIST_NONE
;
956 case XML_TOK_LITERAL
:
957 state
->handler
= attlist1
;
958 return XML_ROLE_DEFAULT_ATTRIBUTE_VALUE
;
960 return common(state
, tok
);
964 attlist9(PROLOG_STATE
*state
,
971 case XML_TOK_PROLOG_S
:
972 return XML_ROLE_ATTLIST_NONE
;
973 case XML_TOK_LITERAL
:
974 state
->handler
= attlist1
;
975 return XML_ROLE_FIXED_ATTRIBUTE_VALUE
;
977 return common(state
, tok
);
981 element0(PROLOG_STATE
*state
,
988 case XML_TOK_PROLOG_S
:
989 return XML_ROLE_ELEMENT_NONE
;
991 case XML_TOK_PREFIXED_NAME
:
992 state
->handler
= element1
;
993 return XML_ROLE_ELEMENT_NAME
;
995 return common(state
, tok
);
999 element1(PROLOG_STATE
*state
,
1003 const ENCODING
*enc
)
1006 case XML_TOK_PROLOG_S
:
1007 return XML_ROLE_ELEMENT_NONE
;
1009 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_EMPTY
)) {
1010 state
->handler
= declClose
;
1011 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1012 return XML_ROLE_CONTENT_EMPTY
;
1014 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_ANY
)) {
1015 state
->handler
= declClose
;
1016 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1017 return XML_ROLE_CONTENT_ANY
;
1020 case XML_TOK_OPEN_PAREN
:
1021 state
->handler
= element2
;
1023 return XML_ROLE_GROUP_OPEN
;
1025 return common(state
, tok
);
1029 element2(PROLOG_STATE
*state
,
1033 const ENCODING
*enc
)
1036 case XML_TOK_PROLOG_S
:
1037 return XML_ROLE_ELEMENT_NONE
;
1038 case XML_TOK_POUND_NAME
:
1039 if (XmlNameMatchesAscii(enc
,
1040 ptr
+ MIN_BYTES_PER_CHAR(enc
),
1043 state
->handler
= element3
;
1044 return XML_ROLE_CONTENT_PCDATA
;
1047 case XML_TOK_OPEN_PAREN
:
1049 state
->handler
= element6
;
1050 return XML_ROLE_GROUP_OPEN
;
1052 case XML_TOK_PREFIXED_NAME
:
1053 state
->handler
= element7
;
1054 return XML_ROLE_CONTENT_ELEMENT
;
1055 case XML_TOK_NAME_QUESTION
:
1056 state
->handler
= element7
;
1057 return XML_ROLE_CONTENT_ELEMENT_OPT
;
1058 case XML_TOK_NAME_ASTERISK
:
1059 state
->handler
= element7
;
1060 return XML_ROLE_CONTENT_ELEMENT_REP
;
1061 case XML_TOK_NAME_PLUS
:
1062 state
->handler
= element7
;
1063 return XML_ROLE_CONTENT_ELEMENT_PLUS
;
1065 return common(state
, tok
);
1069 element3(PROLOG_STATE
*state
,
1073 const ENCODING
*enc
)
1076 case XML_TOK_PROLOG_S
:
1077 return XML_ROLE_ELEMENT_NONE
;
1078 case XML_TOK_CLOSE_PAREN
:
1079 state
->handler
= declClose
;
1080 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1081 return XML_ROLE_GROUP_CLOSE
;
1082 case XML_TOK_CLOSE_PAREN_ASTERISK
:
1083 state
->handler
= declClose
;
1084 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1085 return XML_ROLE_GROUP_CLOSE_REP
;
1087 state
->handler
= element4
;
1088 return XML_ROLE_ELEMENT_NONE
;
1090 return common(state
, tok
);
1094 element4(PROLOG_STATE
*state
,
1098 const ENCODING
*enc
)
1101 case XML_TOK_PROLOG_S
:
1102 return XML_ROLE_ELEMENT_NONE
;
1104 case XML_TOK_PREFIXED_NAME
:
1105 state
->handler
= element5
;
1106 return XML_ROLE_CONTENT_ELEMENT
;
1108 return common(state
, tok
);
1112 element5(PROLOG_STATE
*state
,
1116 const ENCODING
*enc
)
1119 case XML_TOK_PROLOG_S
:
1120 return XML_ROLE_ELEMENT_NONE
;
1121 case XML_TOK_CLOSE_PAREN_ASTERISK
:
1122 state
->handler
= declClose
;
1123 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1124 return XML_ROLE_GROUP_CLOSE_REP
;
1126 state
->handler
= element4
;
1127 return XML_ROLE_ELEMENT_NONE
;
1129 return common(state
, tok
);
1133 element6(PROLOG_STATE
*state
,
1137 const ENCODING
*enc
)
1140 case XML_TOK_PROLOG_S
:
1141 return XML_ROLE_ELEMENT_NONE
;
1142 case XML_TOK_OPEN_PAREN
:
1144 return XML_ROLE_GROUP_OPEN
;
1146 case XML_TOK_PREFIXED_NAME
:
1147 state
->handler
= element7
;
1148 return XML_ROLE_CONTENT_ELEMENT
;
1149 case XML_TOK_NAME_QUESTION
:
1150 state
->handler
= element7
;
1151 return XML_ROLE_CONTENT_ELEMENT_OPT
;
1152 case XML_TOK_NAME_ASTERISK
:
1153 state
->handler
= element7
;
1154 return XML_ROLE_CONTENT_ELEMENT_REP
;
1155 case XML_TOK_NAME_PLUS
:
1156 state
->handler
= element7
;
1157 return XML_ROLE_CONTENT_ELEMENT_PLUS
;
1159 return common(state
, tok
);
1163 element7(PROLOG_STATE
*state
,
1167 const ENCODING
*enc
)
1170 case XML_TOK_PROLOG_S
:
1171 return XML_ROLE_ELEMENT_NONE
;
1172 case XML_TOK_CLOSE_PAREN
:
1174 if (state
->level
== 0) {
1175 state
->handler
= declClose
;
1176 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1178 return XML_ROLE_GROUP_CLOSE
;
1179 case XML_TOK_CLOSE_PAREN_ASTERISK
:
1181 if (state
->level
== 0) {
1182 state
->handler
= declClose
;
1183 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1185 return XML_ROLE_GROUP_CLOSE_REP
;
1186 case XML_TOK_CLOSE_PAREN_QUESTION
:
1188 if (state
->level
== 0) {
1189 state
->handler
= declClose
;
1190 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1192 return XML_ROLE_GROUP_CLOSE_OPT
;
1193 case XML_TOK_CLOSE_PAREN_PLUS
:
1195 if (state
->level
== 0) {
1196 state
->handler
= declClose
;
1197 state
->role_none
= XML_ROLE_ELEMENT_NONE
;
1199 return XML_ROLE_GROUP_CLOSE_PLUS
;
1201 state
->handler
= element6
;
1202 return XML_ROLE_GROUP_SEQUENCE
;
1204 state
->handler
= element6
;
1205 return XML_ROLE_GROUP_CHOICE
;
1207 return common(state
, tok
);
1213 condSect0(PROLOG_STATE
*state
,
1217 const ENCODING
*enc
)
1220 case XML_TOK_PROLOG_S
:
1221 return XML_ROLE_NONE
;
1223 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_INCLUDE
)) {
1224 state
->handler
= condSect1
;
1225 return XML_ROLE_NONE
;
1227 if (XmlNameMatchesAscii(enc
, ptr
, end
, KW_IGNORE
)) {
1228 state
->handler
= condSect2
;
1229 return XML_ROLE_NONE
;
1233 return common(state
, tok
);
1237 condSect1(PROLOG_STATE
*state
,
1241 const ENCODING
*enc
)
1244 case XML_TOK_PROLOG_S
:
1245 return XML_ROLE_NONE
;
1246 case XML_TOK_OPEN_BRACKET
:
1247 state
->handler
= externalSubset1
;
1248 state
->includeLevel
+= 1;
1249 return XML_ROLE_NONE
;
1251 return common(state
, tok
);
1255 condSect2(PROLOG_STATE
*state
,
1259 const ENCODING
*enc
)
1262 case XML_TOK_PROLOG_S
:
1263 return XML_ROLE_NONE
;
1264 case XML_TOK_OPEN_BRACKET
:
1265 state
->handler
= externalSubset1
;
1266 return XML_ROLE_IGNORE_SECT
;
1268 return common(state
, tok
);
1271 #endif /* XML_DTD */
1274 declClose(PROLOG_STATE
*state
,
1278 const ENCODING
*enc
)
1281 case XML_TOK_PROLOG_S
:
1282 return state
->role_none
;
1283 case XML_TOK_DECL_CLOSE
:
1285 return state
->role_none
;
1287 return common(state
, tok
);
1291 error(PROLOG_STATE
*state
,
1295 const ENCODING
*enc
)
1297 return XML_ROLE_NONE
;
1301 common(PROLOG_STATE
*state
, int tok
)
1304 if (!state
->documentEntity
&& tok
== XML_TOK_PARAM_ENTITY_REF
)
1305 return XML_ROLE_INNER_PARAM_ENTITY_REF
;
1307 state
->handler
= error
;
1308 return XML_ROLE_ERROR
;
1312 XmlPrologStateInit(PROLOG_STATE
*state
)
1314 state
->handler
= prolog0
;
1316 state
->documentEntity
= 1;
1317 state
->includeLevel
= 0;
1318 state
->inEntityValue
= 0;
1319 #endif /* XML_DTD */
1325 XmlPrologStateInitExternalEntity(PROLOG_STATE
*state
)
1327 state
->handler
= externalSubset0
;
1328 state
->documentEntity
= 0;
1329 state
->includeLevel
= 0;
1332 #endif /* XML_DTD */