Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
xmlrole.cc
Go to the documentation of this file.
1/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
2 See the file COPYING for copying permission.
3*/
4
5#if defined(__clang__) || defined(__GNUC__)
6#pragma GCC diagnostic ignored "-Wunused-parameter"
7#endif
8
9#include <stddef.h>
10
11#ifdef COMPILED_FROM_DSP
12#include "winconfig.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"
19#else
20#ifdef HAVE_EXPAT_CONFIG_H
21#include <expat_config.h>
22#endif
23#endif /* ndef COMPILED_FROM_DSP */
24
25#include "expat_external.h"
26#include "internal.h"
27#include "xmlrole.h"
28#include "ascii.h"
29
30/* Doesn't check:
31
32 that ,| are not mixed in a model group
33 content of literals
34
35*/
36
37static const char KW_ANY[] = {
38 ASCII_A, ASCII_N, ASCII_Y, '\0' };
39static const char KW_ATTLIST[] = {
41static const char KW_CDATA[] = {
43static const char KW_DOCTYPE[] = {
45static const char KW_ELEMENT[] = {
47static const char KW_EMPTY[] = {
49static const char KW_ENTITIES[] = {
51 '\0' };
52static const char KW_ENTITY[] = {
54static const char KW_FIXED[] = {
56static const char KW_ID[] = {
57 ASCII_I, ASCII_D, '\0' };
58static const char KW_IDREF[] = {
60static const char KW_IDREFS[] = {
62#ifdef XML_DTD
63static const char KW_IGNORE[] = {
65#endif
66static const char KW_IMPLIED[] = {
68#ifdef XML_DTD
69static const char KW_INCLUDE[] = {
71#endif
72static const char KW_NDATA[] = {
74static const char KW_NMTOKEN[] = {
76static const char KW_NMTOKENS[] = {
78 '\0' };
79static const char KW_NOTATION[] =
81 '\0' };
82static const char KW_PCDATA[] = {
84static const char KW_PUBLIC[] = {
86static const char KW_REQUIRED[] = {
88 '\0' };
89static const char KW_SYSTEM[] = {
91
92#ifndef MIN_BYTES_PER_CHAR
93#define MIN_BYTES_PER_CHAR(enc) ((enc)->minBytesPerChar)
94#endif
95
96#ifdef XML_DTD
97#define setTopLevel(state) \
98 ((state)->handler = ((state)->documentEntity \
99 ? internalSubset \
100 : externalSubset1))
101#else /* not XML_DTD */
102#define setTopLevel(state) ((state)->handler = internalSubset)
103#endif /* not XML_DTD */
104
106 int tok,
107 const char *ptr,
108 const char *end,
109 const ENCODING *enc);
110
111static PROLOG_HANDLER
112 prolog0, prolog1, prolog2,
113 doctype0, doctype1, doctype2, doctype3, doctype4, doctype5,
114 internalSubset,
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,
121 element7,
122#ifdef XML_DTD
123 externalSubset0, externalSubset1,
124 condSect0, condSect1, condSect2,
125#endif /* XML_DTD */
126 declClose,
127 error;
128
129static int FASTCALL common(PROLOG_STATE *state, int tok);
130
131static int PTRCALL
132prolog0(PROLOG_STATE *state,
133 int tok,
134 const char *ptr,
135 const char *end,
136 const ENCODING *enc)
137{
138 switch (tok) {
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;
145 case XML_TOK_PI:
146 state->handler = prolog1;
147 return XML_ROLE_PI;
148 case XML_TOK_COMMENT:
149 state->handler = prolog1;
150 return XML_ROLE_COMMENT;
151 case XML_TOK_BOM:
152 return XML_ROLE_NONE;
154 if (!XmlNameMatchesAscii(enc,
155 ptr + 2 * MIN_BYTES_PER_CHAR(enc),
156 end,
157 KW_DOCTYPE))
158 break;
159 state->handler = doctype0;
162 state->handler = error;
164 }
165 return common(state, tok);
166}
167
168static int PTRCALL
169prolog1(PROLOG_STATE *state,
170 int tok,
171 const char *ptr,
172 const char *end,
173 const ENCODING *enc)
174{
175 switch (tok) {
176 case XML_TOK_PROLOG_S:
177 return XML_ROLE_NONE;
178 case XML_TOK_PI:
179 return XML_ROLE_PI;
180 case XML_TOK_COMMENT:
181 return XML_ROLE_COMMENT;
182 case XML_TOK_BOM:
183 return XML_ROLE_NONE;
185 if (!XmlNameMatchesAscii(enc,
186 ptr + 2 * MIN_BYTES_PER_CHAR(enc),
187 end,
188 KW_DOCTYPE))
189 break;
190 state->handler = doctype0;
193 state->handler = error;
195 }
196 return common(state, tok);
197}
198
199static int PTRCALL
200prolog2(PROLOG_STATE *state,
201 int tok,
202 const char *ptr,
203 const char *end,
204 const ENCODING *enc)
205{
206 switch (tok) {
207 case XML_TOK_PROLOG_S:
208 return XML_ROLE_NONE;
209 case XML_TOK_PI:
210 return XML_ROLE_PI;
211 case XML_TOK_COMMENT:
212 return XML_ROLE_COMMENT;
214 state->handler = error;
216 }
217 return common(state, tok);
218}
219
220static int PTRCALL
221doctype0(PROLOG_STATE *state,
222 int tok,
223 const char *ptr,
224 const char *end,
225 const ENCODING *enc)
226{
227 switch (tok) {
228 case XML_TOK_PROLOG_S:
230 case XML_TOK_NAME:
232 state->handler = doctype1;
234 }
235 return common(state, tok);
236}
237
238static int PTRCALL
239doctype1(PROLOG_STATE *state,
240 int tok,
241 const char *ptr,
242 const char *end,
243 const ENCODING *enc)
244{
245 switch (tok) {
246 case XML_TOK_PROLOG_S:
249 state->handler = internalSubset;
252 state->handler = prolog2;
254 case XML_TOK_NAME:
255 if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) {
256 state->handler = doctype3;
258 }
259 if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) {
260 state->handler = doctype2;
262 }
263 break;
264 }
265 return common(state, tok);
266}
267
268static int PTRCALL
269doctype2(PROLOG_STATE *state,
270 int tok,
271 const char *ptr,
272 const char *end,
273 const ENCODING *enc)
274{
275 switch (tok) {
276 case XML_TOK_PROLOG_S:
278 case XML_TOK_LITERAL:
279 state->handler = doctype3;
281 }
282 return common(state, tok);
283}
284
285static int PTRCALL
286doctype3(PROLOG_STATE *state,
287 int tok,
288 const char *ptr,
289 const char *end,
290 const ENCODING *enc)
291{
292 switch (tok) {
293 case XML_TOK_PROLOG_S:
295 case XML_TOK_LITERAL:
296 state->handler = doctype4;
298 }
299 return common(state, tok);
300}
301
302static int PTRCALL
303doctype4(PROLOG_STATE *state,
304 int tok,
305 const char *ptr,
306 const char *end,
307 const ENCODING *enc)
308{
309 switch (tok) {
310 case XML_TOK_PROLOG_S:
313 state->handler = internalSubset;
316 state->handler = prolog2;
318 }
319 return common(state, tok);
320}
321
322static int PTRCALL
323doctype5(PROLOG_STATE *state,
324 int tok,
325 const char *ptr,
326 const char *end,
327 const ENCODING *enc)
328{
329 switch (tok) {
330 case XML_TOK_PROLOG_S:
333 state->handler = prolog2;
335 }
336 return common(state, tok);
337}
338
339static int PTRCALL
340internalSubset(PROLOG_STATE *state,
341 int tok,
342 const char *ptr,
343 const char *end,
344 const ENCODING *enc)
345{
346 switch (tok) {
347 case XML_TOK_PROLOG_S:
348 return XML_ROLE_NONE;
350 if (XmlNameMatchesAscii(enc,
351 ptr + 2 * MIN_BYTES_PER_CHAR(enc),
352 end,
353 KW_ENTITY)) {
354 state->handler = entity0;
356 }
357 if (XmlNameMatchesAscii(enc,
358 ptr + 2 * MIN_BYTES_PER_CHAR(enc),
359 end,
360 KW_ATTLIST)) {
361 state->handler = attlist0;
363 }
364 if (XmlNameMatchesAscii(enc,
365 ptr + 2 * MIN_BYTES_PER_CHAR(enc),
366 end,
367 KW_ELEMENT)) {
368 state->handler = element0;
370 }
371 if (XmlNameMatchesAscii(enc,
372 ptr + 2 * MIN_BYTES_PER_CHAR(enc),
373 end,
374 KW_NOTATION)) {
375 state->handler = notation0;
377 }
378 break;
379 case XML_TOK_PI:
380 return XML_ROLE_PI;
381 case XML_TOK_COMMENT:
382 return XML_ROLE_COMMENT;
386 state->handler = doctype5;
388 case XML_TOK_NONE:
389 return XML_ROLE_NONE;
390 }
391 return common(state, tok);
392}
393
394#ifdef XML_DTD
395
396static int PTRCALL
397externalSubset0(PROLOG_STATE *state,
398 int tok,
399 const char *ptr,
400 const char *end,
401 const ENCODING *enc)
402{
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);
407}
408
409static int PTRCALL
410externalSubset1(PROLOG_STATE *state,
411 int tok,
412 const char *ptr,
413 const char *end,
414 const ENCODING *enc)
415{
416 switch (tok) {
418 state->handler = condSect0;
419 return XML_ROLE_NONE;
421 if (state->includeLevel == 0)
422 break;
423 state->includeLevel -= 1;
424 return XML_ROLE_NONE;
425 case XML_TOK_PROLOG_S:
426 return XML_ROLE_NONE;
428 break;
429 case XML_TOK_NONE:
430 if (state->includeLevel)
431 break;
432 return XML_ROLE_NONE;
433 default:
434 return internalSubset(state, tok, ptr, end, enc);
435 }
436 return common(state, tok);
437}
438
439#endif /* XML_DTD */
440
441static int PTRCALL
442entity0(PROLOG_STATE *state,
443 int tok,
444 const char *ptr,
445 const char *end,
446 const ENCODING *enc)
447{
448 switch (tok) {
449 case XML_TOK_PROLOG_S:
451 case XML_TOK_PERCENT:
452 state->handler = entity1;
454 case XML_TOK_NAME:
455 state->handler = entity2;
457 }
458 return common(state, tok);
459}
460
461static int PTRCALL
462entity1(PROLOG_STATE *state,
463 int tok,
464 const char *ptr,
465 const char *end,
466 const ENCODING *enc)
467{
468 switch (tok) {
469 case XML_TOK_PROLOG_S:
471 case XML_TOK_NAME:
472 state->handler = entity7;
474 }
475 return common(state, tok);
476}
477
478static int PTRCALL
479entity2(PROLOG_STATE *state,
480 int tok,
481 const char *ptr,
482 const char *end,
483 const ENCODING *enc)
484{
485 switch (tok) {
486 case XML_TOK_PROLOG_S:
488 case XML_TOK_NAME:
489 if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) {
490 state->handler = entity4;
492 }
493 if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) {
494 state->handler = entity3;
496 }
497 break;
498 case XML_TOK_LITERAL:
499 state->handler = declClose;
502 }
503 return common(state, tok);
504}
505
506static int PTRCALL
507entity3(PROLOG_STATE *state,
508 int tok,
509 const char *ptr,
510 const char *end,
511 const ENCODING *enc)
512{
513 switch (tok) {
514 case XML_TOK_PROLOG_S:
516 case XML_TOK_LITERAL:
517 state->handler = entity4;
519 }
520 return common(state, tok);
521}
522
523static int PTRCALL
524entity4(PROLOG_STATE *state,
525 int tok,
526 const char *ptr,
527 const char *end,
528 const ENCODING *enc)
529{
530 switch (tok) {
531 case XML_TOK_PROLOG_S:
533 case XML_TOK_LITERAL:
534 state->handler = entity5;
536 }
537 return common(state, tok);
538}
539
540static int PTRCALL
541entity5(PROLOG_STATE *state,
542 int tok,
543 const char *ptr,
544 const char *end,
545 const ENCODING *enc)
546{
547 switch (tok) {
548 case XML_TOK_PROLOG_S:
551 setTopLevel(state);
553 case XML_TOK_NAME:
554 if (XmlNameMatchesAscii(enc, ptr, end, KW_NDATA)) {
555 state->handler = entity6;
557 }
558 break;
559 }
560 return common(state, tok);
561}
562
563static int PTRCALL
564entity6(PROLOG_STATE *state,
565 int tok,
566 const char *ptr,
567 const char *end,
568 const ENCODING *enc)
569{
570 switch (tok) {
571 case XML_TOK_PROLOG_S:
573 case XML_TOK_NAME:
574 state->handler = declClose;
577 }
578 return common(state, tok);
579}
580
581static int PTRCALL
582entity7(PROLOG_STATE *state,
583 int tok,
584 const char *ptr,
585 const char *end,
586 const ENCODING *enc)
587{
588 switch (tok) {
589 case XML_TOK_PROLOG_S:
591 case XML_TOK_NAME:
592 if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) {
593 state->handler = entity9;
595 }
596 if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) {
597 state->handler = entity8;
599 }
600 break;
601 case XML_TOK_LITERAL:
602 state->handler = declClose;
605 }
606 return common(state, tok);
607}
608
609static int PTRCALL
610entity8(PROLOG_STATE *state,
611 int tok,
612 const char *ptr,
613 const char *end,
614 const ENCODING *enc)
615{
616 switch (tok) {
617 case XML_TOK_PROLOG_S:
619 case XML_TOK_LITERAL:
620 state->handler = entity9;
622 }
623 return common(state, tok);
624}
625
626static int PTRCALL
627entity9(PROLOG_STATE *state,
628 int tok,
629 const char *ptr,
630 const char *end,
631 const ENCODING *enc)
632{
633 switch (tok) {
634 case XML_TOK_PROLOG_S:
636 case XML_TOK_LITERAL:
637 state->handler = entity10;
639 }
640 return common(state, tok);
641}
642
643static int PTRCALL
644entity10(PROLOG_STATE *state,
645 int tok,
646 const char *ptr,
647 const char *end,
648 const ENCODING *enc)
649{
650 switch (tok) {
651 case XML_TOK_PROLOG_S:
654 setTopLevel(state);
656 }
657 return common(state, tok);
658}
659
660static int PTRCALL
661notation0(PROLOG_STATE *state,
662 int tok,
663 const char *ptr,
664 const char *end,
665 const ENCODING *enc)
666{
667 switch (tok) {
668 case XML_TOK_PROLOG_S:
670 case XML_TOK_NAME:
671 state->handler = notation1;
673 }
674 return common(state, tok);
675}
676
677static int PTRCALL
678notation1(PROLOG_STATE *state,
679 int tok,
680 const char *ptr,
681 const char *end,
682 const ENCODING *enc)
683{
684 switch (tok) {
685 case XML_TOK_PROLOG_S:
687 case XML_TOK_NAME:
688 if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) {
689 state->handler = notation3;
691 }
692 if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) {
693 state->handler = notation2;
695 }
696 break;
697 }
698 return common(state, tok);
699}
700
701static int PTRCALL
702notation2(PROLOG_STATE *state,
703 int tok,
704 const char *ptr,
705 const char *end,
706 const ENCODING *enc)
707{
708 switch (tok) {
709 case XML_TOK_PROLOG_S:
711 case XML_TOK_LITERAL:
712 state->handler = notation4;
714 }
715 return common(state, tok);
716}
717
718static int PTRCALL
719notation3(PROLOG_STATE *state,
720 int tok,
721 const char *ptr,
722 const char *end,
723 const ENCODING *enc)
724{
725 switch (tok) {
726 case XML_TOK_PROLOG_S:
728 case XML_TOK_LITERAL:
729 state->handler = declClose;
732 }
733 return common(state, tok);
734}
735
736static int PTRCALL
737notation4(PROLOG_STATE *state,
738 int tok,
739 const char *ptr,
740 const char *end,
741 const ENCODING *enc)
742{
743 switch (tok) {
744 case XML_TOK_PROLOG_S:
746 case XML_TOK_LITERAL:
747 state->handler = declClose;
751 setTopLevel(state);
753 }
754 return common(state, tok);
755}
756
757static int PTRCALL
758attlist0(PROLOG_STATE *state,
759 int tok,
760 const char *ptr,
761 const char *end,
762 const ENCODING *enc)
763{
764 switch (tok) {
765 case XML_TOK_PROLOG_S:
767 case XML_TOK_NAME:
769 state->handler = attlist1;
771 }
772 return common(state, tok);
773}
774
775static int PTRCALL
776attlist1(PROLOG_STATE *state,
777 int tok,
778 const char *ptr,
779 const char *end,
780 const ENCODING *enc)
781{
782 switch (tok) {
783 case XML_TOK_PROLOG_S:
786 setTopLevel(state);
788 case XML_TOK_NAME:
790 state->handler = attlist2;
792 }
793 return common(state, tok);
794}
795
796static int PTRCALL
797attlist2(PROLOG_STATE *state,
798 int tok,
799 const char *ptr,
800 const char *end,
801 const ENCODING *enc)
802{
803 switch (tok) {
804 case XML_TOK_PROLOG_S:
806 case XML_TOK_NAME:
807 {
808 static const char * const types[] = {
809 KW_CDATA,
810 KW_ID,
811 KW_IDREF,
812 KW_IDREFS,
813 KW_ENTITY,
814 KW_ENTITIES,
815 KW_NMTOKEN,
816 KW_NMTOKENS,
817 };
818 int i;
819 for (i = 0; i < (int)(sizeof(types)/sizeof(types[0])); i++)
820 if (XmlNameMatchesAscii(enc, ptr, end, types[i])) {
821 state->handler = attlist8;
823 }
824 }
825 if (XmlNameMatchesAscii(enc, ptr, end, KW_NOTATION)) {
826 state->handler = attlist5;
828 }
829 break;
831 state->handler = attlist3;
833 }
834 return common(state, tok);
835}
836
837static int PTRCALL
838attlist3(PROLOG_STATE *state,
839 int tok,
840 const char *ptr,
841 const char *end,
842 const ENCODING *enc)
843{
844 switch (tok) {
845 case XML_TOK_PROLOG_S:
847 case XML_TOK_NMTOKEN:
848 case XML_TOK_NAME:
850 state->handler = attlist4;
852 }
853 return common(state, tok);
854}
855
856static int PTRCALL
857attlist4(PROLOG_STATE *state,
858 int tok,
859 const char *ptr,
860 const char *end,
861 const ENCODING *enc)
862{
863 switch (tok) {
864 case XML_TOK_PROLOG_S:
867 state->handler = attlist8;
869 case XML_TOK_OR:
870 state->handler = attlist3;
872 }
873 return common(state, tok);
874}
875
876static int PTRCALL
877attlist5(PROLOG_STATE *state,
878 int tok,
879 const char *ptr,
880 const char *end,
881 const ENCODING *enc)
882{
883 switch (tok) {
884 case XML_TOK_PROLOG_S:
887 state->handler = attlist6;
889 }
890 return common(state, tok);
891}
892
893static int PTRCALL
894attlist6(PROLOG_STATE *state,
895 int tok,
896 const char *ptr,
897 const char *end,
898 const ENCODING *enc)
899{
900 switch (tok) {
901 case XML_TOK_PROLOG_S:
903 case XML_TOK_NAME:
904 state->handler = attlist7;
906 }
907 return common(state, tok);
908}
909
910static int PTRCALL
911attlist7(PROLOG_STATE *state,
912 int tok,
913 const char *ptr,
914 const char *end,
915 const ENCODING *enc)
916{
917 switch (tok) {
918 case XML_TOK_PROLOG_S:
921 state->handler = attlist8;
923 case XML_TOK_OR:
924 state->handler = attlist6;
926 }
927 return common(state, tok);
928}
929
930/* default value */
931static int PTRCALL
932attlist8(PROLOG_STATE *state,
933 int tok,
934 const char *ptr,
935 const char *end,
936 const ENCODING *enc)
937{
938 switch (tok) {
939 case XML_TOK_PROLOG_S:
942 if (XmlNameMatchesAscii(enc,
943 ptr + MIN_BYTES_PER_CHAR(enc),
944 end,
945 KW_IMPLIED)) {
946 state->handler = attlist1;
948 }
949 if (XmlNameMatchesAscii(enc,
950 ptr + MIN_BYTES_PER_CHAR(enc),
951 end,
952 KW_REQUIRED)) {
953 state->handler = attlist1;
955 }
956 if (XmlNameMatchesAscii(enc,
957 ptr + MIN_BYTES_PER_CHAR(enc),
958 end,
959 KW_FIXED)) {
960 state->handler = attlist9;
962 }
963 break;
964 case XML_TOK_LITERAL:
965 state->handler = attlist1;
967 }
968 return common(state, tok);
969}
970
971static int PTRCALL
972attlist9(PROLOG_STATE *state,
973 int tok,
974 const char *ptr,
975 const char *end,
976 const ENCODING *enc)
977{
978 switch (tok) {
979 case XML_TOK_PROLOG_S:
981 case XML_TOK_LITERAL:
982 state->handler = attlist1;
984 }
985 return common(state, tok);
986}
987
988static int PTRCALL
989element0(PROLOG_STATE *state,
990 int tok,
991 const char *ptr,
992 const char *end,
993 const ENCODING *enc)
994{
995 switch (tok) {
996 case XML_TOK_PROLOG_S:
998 case XML_TOK_NAME:
1000 state->handler = element1;
1001 return XML_ROLE_ELEMENT_NAME;
1002 }
1003 return common(state, tok);
1004}
1005
1006static int PTRCALL
1007element1(PROLOG_STATE *state,
1008 int tok,
1009 const char *ptr,
1010 const char *end,
1011 const ENCODING *enc)
1012{
1013 switch (tok) {
1014 case XML_TOK_PROLOG_S:
1015 return XML_ROLE_ELEMENT_NONE;
1016 case XML_TOK_NAME:
1017 if (XmlNameMatchesAscii(enc, ptr, end, KW_EMPTY)) {
1018 state->handler = declClose;
1021 }
1022 if (XmlNameMatchesAscii(enc, ptr, end, KW_ANY)) {
1023 state->handler = declClose;
1025 return XML_ROLE_CONTENT_ANY;
1026 }
1027 break;
1028 case XML_TOK_OPEN_PAREN:
1029 state->handler = element2;
1030 state->level = 1;
1031 return XML_ROLE_GROUP_OPEN;
1032 }
1033 return common(state, tok);
1034}
1035
1036static int PTRCALL
1037element2(PROLOG_STATE *state,
1038 int tok,
1039 const char *ptr,
1040 const char *end,
1041 const ENCODING *enc)
1042{
1043 switch (tok) {
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),
1049 end,
1050 KW_PCDATA)) {
1051 state->handler = element3;
1053 }
1054 break;
1055 case XML_TOK_OPEN_PAREN:
1056 state->level = 2;
1057 state->handler = element6;
1058 return XML_ROLE_GROUP_OPEN;
1059 case XML_TOK_NAME:
1061 state->handler = element7;
1064 state->handler = element7;
1067 state->handler = element7;
1069 case XML_TOK_NAME_PLUS:
1070 state->handler = element7;
1072 }
1073 return common(state, tok);
1074}
1075
1076static int PTRCALL
1077element3(PROLOG_STATE *state,
1078 int tok,
1079 const char *ptr,
1080 const char *end,
1081 const ENCODING *enc)
1082{
1083 switch (tok) {
1084 case XML_TOK_PROLOG_S:
1085 return XML_ROLE_ELEMENT_NONE;
1087 state->handler = declClose;
1089 return XML_ROLE_GROUP_CLOSE;
1091 state->handler = declClose;
1094 case XML_TOK_OR:
1095 state->handler = element4;
1096 return XML_ROLE_ELEMENT_NONE;
1097 }
1098 return common(state, tok);
1099}
1100
1101static int PTRCALL
1102element4(PROLOG_STATE *state,
1103 int tok,
1104 const char *ptr,
1105 const char *end,
1106 const ENCODING *enc)
1107{
1108 switch (tok) {
1109 case XML_TOK_PROLOG_S:
1110 return XML_ROLE_ELEMENT_NONE;
1111 case XML_TOK_NAME:
1113 state->handler = element5;
1115 }
1116 return common(state, tok);
1117}
1118
1119static int PTRCALL
1120element5(PROLOG_STATE *state,
1121 int tok,
1122 const char *ptr,
1123 const char *end,
1124 const ENCODING *enc)
1125{
1126 switch (tok) {
1127 case XML_TOK_PROLOG_S:
1128 return XML_ROLE_ELEMENT_NONE;
1130 state->handler = declClose;
1133 case XML_TOK_OR:
1134 state->handler = element4;
1135 return XML_ROLE_ELEMENT_NONE;
1136 }
1137 return common(state, tok);
1138}
1139
1140static int PTRCALL
1141element6(PROLOG_STATE *state,
1142 int tok,
1143 const char *ptr,
1144 const char *end,
1145 const ENCODING *enc)
1146{
1147 switch (tok) {
1148 case XML_TOK_PROLOG_S:
1149 return XML_ROLE_ELEMENT_NONE;
1150 case XML_TOK_OPEN_PAREN:
1151 state->level += 1;
1152 return XML_ROLE_GROUP_OPEN;
1153 case XML_TOK_NAME:
1155 state->handler = element7;
1158 state->handler = element7;
1161 state->handler = element7;
1163 case XML_TOK_NAME_PLUS:
1164 state->handler = element7;
1166 }
1167 return common(state, tok);
1168}
1169
1170static int PTRCALL
1171element7(PROLOG_STATE *state,
1172 int tok,
1173 const char *ptr,
1174 const char *end,
1175 const ENCODING *enc)
1176{
1177 switch (tok) {
1178 case XML_TOK_PROLOG_S:
1179 return XML_ROLE_ELEMENT_NONE;
1181 state->level -= 1;
1182 if (state->level == 0) {
1183 state->handler = declClose;
1185 }
1186 return XML_ROLE_GROUP_CLOSE;
1188 state->level -= 1;
1189 if (state->level == 0) {
1190 state->handler = declClose;
1192 }
1195 state->level -= 1;
1196 if (state->level == 0) {
1197 state->handler = declClose;
1199 }
1202 state->level -= 1;
1203 if (state->level == 0) {
1204 state->handler = declClose;
1206 }
1208 case XML_TOK_COMMA:
1209 state->handler = element6;
1211 case XML_TOK_OR:
1212 state->handler = element6;
1213 return XML_ROLE_GROUP_CHOICE;
1214 }
1215 return common(state, tok);
1216}
1217
1218#ifdef XML_DTD
1219
1220static int PTRCALL
1221condSect0(PROLOG_STATE *state,
1222 int tok,
1223 const char *ptr,
1224 const char *end,
1225 const ENCODING *enc)
1226{
1227 switch (tok) {
1228 case XML_TOK_PROLOG_S:
1229 return XML_ROLE_NONE;
1230 case XML_TOK_NAME:
1231 if (XmlNameMatchesAscii(enc, ptr, end, KW_INCLUDE)) {
1232 state->handler = condSect1;
1233 return XML_ROLE_NONE;
1234 }
1235 if (XmlNameMatchesAscii(enc, ptr, end, KW_IGNORE)) {
1236 state->handler = condSect2;
1237 return XML_ROLE_NONE;
1238 }
1239 break;
1240 }
1241 return common(state, tok);
1242}
1243
1244static int PTRCALL
1245condSect1(PROLOG_STATE *state,
1246 int tok,
1247 const char *ptr,
1248 const char *end,
1249 const ENCODING *enc)
1250{
1251 switch (tok) {
1252 case XML_TOK_PROLOG_S:
1253 return XML_ROLE_NONE;
1255 state->handler = externalSubset1;
1256 state->includeLevel += 1;
1257 return XML_ROLE_NONE;
1258 }
1259 return common(state, tok);
1260}
1261
1262static int PTRCALL
1263condSect2(PROLOG_STATE *state,
1264 int tok,
1265 const char *ptr,
1266 const char *end,
1267 const ENCODING *enc)
1268{
1269 switch (tok) {
1270 case XML_TOK_PROLOG_S:
1271 return XML_ROLE_NONE;
1273 state->handler = externalSubset1;
1274 return XML_ROLE_IGNORE_SECT;
1275 }
1276 return common(state, tok);
1277}
1278
1279#endif /* XML_DTD */
1280
1281static int PTRCALL
1282declClose(PROLOG_STATE *state,
1283 int tok,
1284 const char *ptr,
1285 const char *end,
1286 const ENCODING *enc)
1287{
1288 switch (tok) {
1289 case XML_TOK_PROLOG_S:
1290 return state->role_none;
1291 case XML_TOK_DECL_CLOSE:
1292 setTopLevel(state);
1293 return state->role_none;
1294 }
1295 return common(state, tok);
1296}
1297
1298static int PTRCALL
1299error(PROLOG_STATE *state,
1300 int tok,
1301 const char *ptr,
1302 const char *end,
1303 const ENCODING *enc)
1304{
1305 return XML_ROLE_NONE;
1306}
1307
1308static int FASTCALL
1309common(PROLOG_STATE *state, int tok)
1310{
1311#ifdef XML_DTD
1312 if (!state->documentEntity && tok == XML_TOK_PARAM_ENTITY_REF)
1313 return XML_ROLE_INNER_PARAM_ENTITY_REF;
1314#endif
1315 state->handler = error;
1316 return XML_ROLE_ERROR;
1317}
1318
1319void
1321{
1322 state->handler = prolog0;
1323#ifdef XML_DTD
1324 state->documentEntity = 1;
1325 state->includeLevel = 0;
1326 state->inEntityValue = 0;
1327#endif /* XML_DTD */
1328}
1329
1330#ifdef XML_DTD
1331
1332void
1333XmlPrologStateInitExternalEntity(PROLOG_STATE *state)
1334{
1335 state->handler = externalSubset0;
1336 state->documentEntity = 0;
1337 state->includeLevel = 0;
1338}
1339
1340#endif /* XML_DTD */
#define ASCII_X
Definition: ascii.h:28
#define ASCII_F
Definition: ascii.h:10
#define ASCII_E
Definition: ascii.h:9
#define ASCII_C
Definition: ascii.h:7
#define ASCII_O
Definition: ascii.h:19
#define ASCII_N
Definition: ascii.h:18
#define ASCII_D
Definition: ascii.h:8
#define ASCII_G
Definition: ascii.h:11
#define ASCII_I
Definition: ascii.h:13
#define ASCII_A
Definition: ascii.h:5
#define ASCII_R
Definition: ascii.h:22
#define ASCII_U
Definition: ascii.h:25
#define ASCII_P
Definition: ascii.h:20
#define ASCII_M
Definition: ascii.h:17
#define ASCII_K
Definition: ascii.h:15
#define ASCII_L
Definition: ascii.h:16
#define ASCII_Q
Definition: ascii.h:21
#define ASCII_B
Definition: ascii.h:6
#define ASCII_S
Definition: ascii.h:23
#define ASCII_T
Definition: ascii.h:24
#define ASCII_Y
Definition: ascii.h:29
#define FASTCALL
Definition: internal.h:48
#define PTRCALL
Definition: internal.h:52
unsigned level
Definition: xmlrole.h:93
int role_none
Definition: xmlrole.h:94
#define setTopLevel(state)
Definition: xmlrole.cc:102
int PTRCALL PROLOG_HANDLER(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc)
Definition: xmlrole.cc:105
void XmlPrologStateInit(PROLOG_STATE *state)
Definition: xmlrole.cc:1320
#define MIN_BYTES_PER_CHAR(enc)
Definition: xmlrole.cc:93
@ XML_ROLE_GROUP_CHOICE
Definition: xmlrole.h:71
@ XML_ROLE_NOTATION_PUBLIC_ID
Definition: xmlrole.h:43
@ XML_ROLE_ERROR
Definition: xmlrole.h:21
@ XML_ROLE_GROUP_CLOSE_REP
Definition: xmlrole.h:68
@ XML_ROLE_CONTENT_PCDATA
Definition: xmlrole.h:65
@ XML_ROLE_CONTENT_ELEMENT_REP
Definition: xmlrole.h:74
@ XML_ROLE_ENTITY_COMPLETE
Definition: xmlrole.h:37
@ XML_ROLE_DOCTYPE_INTERNAL_SUBSET
Definition: xmlrole.h:29
@ XML_ROLE_NOTATION_NO_SYSTEM_ID
Definition: xmlrole.h:42
@ XML_ROLE_DOCTYPE_NONE
Definition: xmlrole.h:25
@ XML_ROLE_PARAM_ENTITY_REF
Definition: xmlrole.h:84
@ XML_ROLE_GROUP_CLOSE
Definition: xmlrole.h:67
@ XML_ROLE_DOCTYPE_CLOSE
Definition: xmlrole.h:30
@ XML_ROLE_ENTITY_NOTATION_NAME
Definition: xmlrole.h:38
@ XML_ROLE_GROUP_SEQUENCE
Definition: xmlrole.h:72
@ XML_ROLE_ATTLIST_ELEMENT_NAME
Definition: xmlrole.h:56
@ XML_ROLE_GROUP_CLOSE_OPT
Definition: xmlrole.h:69
@ XML_ROLE_IMPLIED_ATTRIBUTE_VALUE
Definition: xmlrole.h:57
@ XML_ROLE_ATTRIBUTE_TYPE_CDATA
Definition: xmlrole.h:45
@ XML_ROLE_COMMENT
Definition: xmlrole.h:78
@ XML_ROLE_ATTRIBUTE_ENUM_VALUE
Definition: xmlrole.h:53
@ XML_ROLE_ENTITY_SYSTEM_ID
Definition: xmlrole.h:35
@ XML_ROLE_CONTENT_ELEMENT
Definition: xmlrole.h:73
@ XML_ROLE_ATTLIST_NONE
Definition: xmlrole.h:55
@ XML_ROLE_ATTRIBUTE_NOTATION_VALUE
Definition: xmlrole.h:54
@ XML_ROLE_DOCTYPE_SYSTEM_ID
Definition: xmlrole.h:27
@ XML_ROLE_NOTATION_SYSTEM_ID
Definition: xmlrole.h:41
@ XML_ROLE_PI
Definition: xmlrole.h:77
@ XML_ROLE_ATTRIBUTE_NAME
Definition: xmlrole.h:44
@ XML_ROLE_CONTENT_ANY
Definition: xmlrole.h:63
@ XML_ROLE_ENTITY_NONE
Definition: xmlrole.h:33
@ XML_ROLE_NONE
Definition: xmlrole.h:22
@ XML_ROLE_ELEMENT_NONE
Definition: xmlrole.h:61
@ XML_ROLE_ENTITY_PUBLIC_ID
Definition: xmlrole.h:36
@ XML_ROLE_INSTANCE_START
Definition: xmlrole.h:24
@ XML_ROLE_DOCTYPE_NAME
Definition: xmlrole.h:26
@ XML_ROLE_NOTATION_NAME
Definition: xmlrole.h:40
@ XML_ROLE_CONTENT_ELEMENT_PLUS
Definition: xmlrole.h:76
@ XML_ROLE_GENERAL_ENTITY_NAME
Definition: xmlrole.h:31
@ XML_ROLE_PARAM_ENTITY_NAME
Definition: xmlrole.h:32
@ XML_ROLE_DEFAULT_ATTRIBUTE_VALUE
Definition: xmlrole.h:59
@ XML_ROLE_NOTATION_NONE
Definition: xmlrole.h:39
@ XML_ROLE_XML_DECL
Definition: xmlrole.h:23
@ XML_ROLE_GROUP_CLOSE_PLUS
Definition: xmlrole.h:70
@ XML_ROLE_REQUIRED_ATTRIBUTE_VALUE
Definition: xmlrole.h:58
@ XML_ROLE_GROUP_OPEN
Definition: xmlrole.h:66
@ XML_ROLE_CONTENT_EMPTY
Definition: xmlrole.h:64
@ XML_ROLE_FIXED_ATTRIBUTE_VALUE
Definition: xmlrole.h:60
@ XML_ROLE_CONTENT_ELEMENT_OPT
Definition: xmlrole.h:75
@ XML_ROLE_DOCTYPE_PUBLIC_ID
Definition: xmlrole.h:28
@ XML_ROLE_ELEMENT_NAME
Definition: xmlrole.h:62
@ XML_ROLE_ENTITY_VALUE
Definition: xmlrole.h:34
#define XML_TOK_NAME
Definition: xmltok.h:49
#define XML_TOK_CLOSE_PAREN_ASTERISK
Definition: xmltok.h:69
#define XML_TOK_DECL_OPEN
Definition: xmltok.h:47
#define XML_TOK_PREFIXED_NAME
Definition: xmltok.h:82
#define XML_TOK_OPEN_PAREN
Definition: xmltok.h:54
#define XML_TOK_PI
Definition: xmltok.h:40
#define XML_TOK_OPEN_BRACKET
Definition: xmltok.h:56
#define XML_TOK_NMTOKEN
Definition: xmltok.h:50
#define XML_TOK_CLOSE_PAREN_PLUS
Definition: xmltok.h:70
#define XML_TOK_CLOSE_PAREN
Definition: xmltok.h:55
#define XML_TOK_NAME_ASTERISK
Definition: xmltok.h:64
#define XML_TOK_DECL_CLOSE
Definition: xmltok.h:48
#define XML_TOK_COMMENT
Definition: xmltok.h:42
#define XML_TOK_NAME_PLUS
Definition: xmltok.h:65
#define XML_TOK_NAME_QUESTION
Definition: xmltok.h:63
#define XML_TOK_COND_SECT_CLOSE
Definition: xmltok.h:67
#define XML_TOK_XML_DECL
Definition: xmltok.h:41
#define XML_TOK_PROLOG_S
Definition: xmltok.h:46
#define XML_TOK_COND_SECT_OPEN
Definition: xmltok.h:66
#define XML_TOK_POUND_NAME
Definition: xmltok.h:51
#define XML_TOK_PARAM_ENTITY_REF
Definition: xmltok.h:59
#define XML_TOK_CLOSE_BRACKET
Definition: xmltok.h:57
#define XML_TOK_PERCENT
Definition: xmltok.h:53
#define XmlNameMatchesAscii(enc, ptr1, end1, ptr2)
Definition: xmltok.h:229
#define XML_TOK_OR
Definition: xmltok.h:52
#define XML_TOK_COMMA
Definition: xmltok.h:71
#define XML_TOK_LITERAL
Definition: xmltok.h:58
#define XML_TOK_NONE
Definition: xmltok.h:17
#define XML_TOK_INSTANCE_START
Definition: xmltok.h:60
#define XML_TOK_CLOSE_PAREN_QUESTION
Definition: xmltok.h:68
#define XML_TOK_BOM
Definition: xmltok.h:43