Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
xmlrole.c
Go to the documentation of this file.
1/*
2 __ __ _
3 ___\ \/ /_ __ __ _| |_
4 / _ \\ /| '_ \ / _` | __|
5 | __// \| |_) | (_| | |_
6 \___/_/\_\ .__/ \__,_|\__|
7 |_| XML parser
8
9 Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
10 Copyright (c) 2000 Clark Cooper <[email protected]>
11 Copyright (c) 2002 Greg Stein <[email protected]>
12 Copyright (c) 2002-2006 Karl Waclawek <[email protected]>
13 Copyright (c) 2002-2003 Fred L. Drake, Jr. <[email protected]>
14 Copyright (c) 2005-2009 Steven Solie <[email protected]>
15 Copyright (c) 2016-2021 Sebastian Pipping <[email protected]>
16 Copyright (c) 2017 Rhodri James <[email protected]>
17 Copyright (c) 2019 David Loffredo <[email protected]>
18 Copyright (c) 2021 Dong-hee Na <[email protected]>
19 Licensed under the MIT license:
20
21 Permission is hereby granted, free of charge, to any person obtaining
22 a copy of this software and associated documentation files (the
23 "Software"), to deal in the Software without restriction, including
24 without limitation the rights to use, copy, modify, merge, publish,
25 distribute, sublicense, and/or sell copies of the Software, and to permit
26 persons to whom the Software is furnished to do so, subject to the
27 following conditions:
28
29 The above copyright notice and this permission notice shall be included
30 in all copies or substantial portions of the Software.
31
32 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
34 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
35 NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
36 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
37 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
38 USE OR OTHER DEALINGS IN THE SOFTWARE.
39*/
40
41#include <expat_config.h>
42
43#include <stddef.h>
44
45#ifdef _WIN32
46# include "winconfig.h"
47#endif
48
49#include "expat_external.h"
50#include "internal.h"
51#include "xmlrole.h"
52#include "ascii.h"
53
54/* Doesn't check:
55
56 that ,| are not mixed in a model group
57 content of literals
58
59*/
60
61static const char KW_ANY[] = {ASCII_A, ASCII_N, ASCII_Y, '\0'};
62static const char KW_ATTLIST[]
64static const char KW_CDATA[]
66static const char KW_DOCTYPE[]
68static const char KW_ELEMENT[]
70static const char KW_EMPTY[]
72static const char KW_ENTITIES[] = {ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T,
73 ASCII_I, ASCII_E, ASCII_S, '\0'};
74static const char KW_ENTITY[]
76static const char KW_FIXED[]
78static const char KW_ID[] = {ASCII_I, ASCII_D, '\0'};
79static const char KW_IDREF[]
81static const char KW_IDREFS[]
83#ifdef XML_DTD
84static const char KW_IGNORE[]
86#endif
87static const char KW_IMPLIED[]
89#ifdef XML_DTD
90static const char KW_INCLUDE[]
92#endif
93static const char KW_NDATA[]
95static const char KW_NMTOKEN[]
97static const char KW_NMTOKENS[] = {ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K,
98 ASCII_E, ASCII_N, ASCII_S, '\0'};
99static const char KW_NOTATION[] = {ASCII_N, ASCII_O, ASCII_T, ASCII_A, ASCII_T,
100 ASCII_I, ASCII_O, ASCII_N, '\0'};
101static const char KW_PCDATA[]
103static const char KW_PUBLIC[]
105static const char KW_REQUIRED[] = {ASCII_R, ASCII_E, ASCII_Q, ASCII_U, ASCII_I,
106 ASCII_R, ASCII_E, ASCII_D, '\0'};
107static const char KW_SYSTEM[]
109
110#ifndef MIN_BYTES_PER_CHAR
111# define MIN_BYTES_PER_CHAR(enc) ((enc)->minBytesPerChar)
112#endif
113
114#ifdef XML_DTD
115# define setTopLevel(state) \
116 ((state)->handler \
117 = ((state)->documentEntity ? internalSubset : externalSubset1))
118#else /* not XML_DTD */
119# define setTopLevel(state) ((state)->handler = internalSubset)
120#endif /* not XML_DTD */
121
122typedef int PTRCALL PROLOG_HANDLER(PROLOG_STATE *state, int tok,
123 const char *ptr, const char *end,
124 const ENCODING *enc);
125
126static PROLOG_HANDLER prolog0, prolog1, prolog2, doctype0, doctype1, doctype2,
127 doctype3, doctype4, doctype5, internalSubset, entity0, entity1, entity2,
128 entity3, entity4, entity5, entity6, entity7, entity8, entity9, entity10,
129 notation0, notation1, notation2, notation3, notation4, attlist0, attlist1,
130 attlist2, attlist3, attlist4, attlist5, attlist6, attlist7, attlist8,
131 attlist9, element0, element1, element2, element3, element4, element5,
132 element6, element7,
133#ifdef XML_DTD
134 externalSubset0, externalSubset1, condSect0, condSect1, condSect2,
135#endif /* XML_DTD */
136 declClose, error;
137
138static int FASTCALL common(PROLOG_STATE *state, int tok);
139
140static int PTRCALL
141prolog0(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
142 const ENCODING *enc) {
143 switch (tok) {
144 case XML_TOK_PROLOG_S:
145 state->handler = prolog1;
146 return XML_ROLE_NONE;
147 case XML_TOK_XML_DECL:
148 state->handler = prolog1;
149 return XML_ROLE_XML_DECL;
150 case XML_TOK_PI:
151 state->handler = prolog1;
152 return XML_ROLE_PI;
153 case XML_TOK_COMMENT:
154 state->handler = prolog1;
155 return XML_ROLE_COMMENT;
156 case XML_TOK_BOM:
157 return XML_ROLE_NONE;
159 if (! XmlNameMatchesAscii(enc, ptr + 2 * MIN_BYTES_PER_CHAR(enc), end,
160 KW_DOCTYPE))
161 break;
162 state->handler = doctype0;
165 state->handler = error;
167 }
168 return common(state, tok);
169}
170
171static int PTRCALL
172prolog1(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
173 const ENCODING *enc) {
174 switch (tok) {
175 case XML_TOK_PROLOG_S:
176 return XML_ROLE_NONE;
177 case XML_TOK_PI:
178 return XML_ROLE_PI;
179 case XML_TOK_COMMENT:
180 return XML_ROLE_COMMENT;
181 case XML_TOK_BOM:
182 /* This case can never arise. To reach this role function, the
183 * parse must have passed through prolog0 and therefore have had
184 * some form of input, even if only a space. At that point, a
185 * byte order mark is no longer a valid character (though
186 * technically it should be interpreted as a non-breaking space),
187 * so will be rejected by the tokenizing stages.
188 */
189 return XML_ROLE_NONE; /* LCOV_EXCL_LINE */
191 if (! XmlNameMatchesAscii(enc, ptr + 2 * MIN_BYTES_PER_CHAR(enc), end,
192 KW_DOCTYPE))
193 break;
194 state->handler = doctype0;
197 state->handler = error;
199 }
200 return common(state, tok);
201}
202
203static int PTRCALL
204prolog2(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
205 const ENCODING *enc) {
206 UNUSED_P(ptr);
207 UNUSED_P(end);
208 UNUSED_P(enc);
209 switch (tok) {
210 case XML_TOK_PROLOG_S:
211 return XML_ROLE_NONE;
212 case XML_TOK_PI:
213 return XML_ROLE_PI;
214 case XML_TOK_COMMENT:
215 return XML_ROLE_COMMENT;
217 state->handler = error;
219 }
220 return common(state, tok);
221}
222
223static int PTRCALL
224doctype0(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
225 const ENCODING *enc) {
226 UNUSED_P(ptr);
227 UNUSED_P(end);
228 UNUSED_P(enc);
229 switch (tok) {
230 case XML_TOK_PROLOG_S:
232 case XML_TOK_NAME:
234 state->handler = doctype1;
236 }
237 return common(state, tok);
238}
239
240static int PTRCALL
241doctype1(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
242 const ENCODING *enc) {
243 switch (tok) {
244 case XML_TOK_PROLOG_S:
247 state->handler = internalSubset;
250 state->handler = prolog2;
252 case XML_TOK_NAME:
253 if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) {
254 state->handler = doctype3;
256 }
257 if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) {
258 state->handler = doctype2;
260 }
261 break;
262 }
263 return common(state, tok);
264}
265
266static int PTRCALL
267doctype2(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
268 const ENCODING *enc) {
269 UNUSED_P(ptr);
270 UNUSED_P(end);
271 UNUSED_P(enc);
272 switch (tok) {
273 case XML_TOK_PROLOG_S:
275 case XML_TOK_LITERAL:
276 state->handler = doctype3;
278 }
279 return common(state, tok);
280}
281
282static int PTRCALL
283doctype3(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
284 const ENCODING *enc) {
285 UNUSED_P(ptr);
286 UNUSED_P(end);
287 UNUSED_P(enc);
288 switch (tok) {
289 case XML_TOK_PROLOG_S:
291 case XML_TOK_LITERAL:
292 state->handler = doctype4;
294 }
295 return common(state, tok);
296}
297
298static int PTRCALL
299doctype4(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
300 const ENCODING *enc) {
301 UNUSED_P(ptr);
302 UNUSED_P(end);
303 UNUSED_P(enc);
304 switch (tok) {
305 case XML_TOK_PROLOG_S:
308 state->handler = internalSubset;
311 state->handler = prolog2;
313 }
314 return common(state, tok);
315}
316
317static int PTRCALL
318doctype5(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
319 const ENCODING *enc) {
320 UNUSED_P(ptr);
321 UNUSED_P(end);
322 UNUSED_P(enc);
323 switch (tok) {
324 case XML_TOK_PROLOG_S:
327 state->handler = prolog2;
329 }
330 return common(state, tok);
331}
332
333static int PTRCALL
334internalSubset(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
335 const ENCODING *enc) {
336 switch (tok) {
337 case XML_TOK_PROLOG_S:
338 return XML_ROLE_NONE;
340 if (XmlNameMatchesAscii(enc, ptr + 2 * MIN_BYTES_PER_CHAR(enc), end,
341 KW_ENTITY)) {
342 state->handler = entity0;
344 }
345 if (XmlNameMatchesAscii(enc, ptr + 2 * MIN_BYTES_PER_CHAR(enc), end,
346 KW_ATTLIST)) {
347 state->handler = attlist0;
349 }
350 if (XmlNameMatchesAscii(enc, ptr + 2 * MIN_BYTES_PER_CHAR(enc), end,
351 KW_ELEMENT)) {
352 state->handler = element0;
354 }
355 if (XmlNameMatchesAscii(enc, ptr + 2 * MIN_BYTES_PER_CHAR(enc), end,
356 KW_NOTATION)) {
357 state->handler = notation0;
359 }
360 break;
361 case XML_TOK_PI:
362 return XML_ROLE_PI;
363 case XML_TOK_COMMENT:
364 return XML_ROLE_COMMENT;
368 state->handler = doctype5;
370 case XML_TOK_NONE:
371 return XML_ROLE_NONE;
372 }
373 return common(state, tok);
374}
375
376#ifdef XML_DTD
377
378static int PTRCALL
379externalSubset0(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
380 const ENCODING *enc) {
381 state->handler = externalSubset1;
382 if (tok == XML_TOK_XML_DECL)
383 return XML_ROLE_TEXT_DECL;
384 return externalSubset1(state, tok, ptr, end, enc);
385}
386
387static int PTRCALL
388externalSubset1(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
389 const ENCODING *enc) {
390 switch (tok) {
392 state->handler = condSect0;
393 return XML_ROLE_NONE;
395 if (state->includeLevel == 0)
396 break;
397 state->includeLevel -= 1;
398 return XML_ROLE_NONE;
399 case XML_TOK_PROLOG_S:
400 return XML_ROLE_NONE;
402 break;
403 case XML_TOK_NONE:
404 if (state->includeLevel)
405 break;
406 return XML_ROLE_NONE;
407 default:
408 return internalSubset(state, tok, ptr, end, enc);
409 }
410 return common(state, tok);
411}
412
413#endif /* XML_DTD */
414
415static int PTRCALL
416entity0(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
417 const ENCODING *enc) {
418 UNUSED_P(ptr);
419 UNUSED_P(end);
420 UNUSED_P(enc);
421 switch (tok) {
422 case XML_TOK_PROLOG_S:
424 case XML_TOK_PERCENT:
425 state->handler = entity1;
427 case XML_TOK_NAME:
428 state->handler = entity2;
430 }
431 return common(state, tok);
432}
433
434static int PTRCALL
435entity1(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
436 const ENCODING *enc) {
437 UNUSED_P(ptr);
438 UNUSED_P(end);
439 UNUSED_P(enc);
440 switch (tok) {
441 case XML_TOK_PROLOG_S:
443 case XML_TOK_NAME:
444 state->handler = entity7;
446 }
447 return common(state, tok);
448}
449
450static int PTRCALL
451entity2(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
452 const ENCODING *enc) {
453 switch (tok) {
454 case XML_TOK_PROLOG_S:
456 case XML_TOK_NAME:
457 if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) {
458 state->handler = entity4;
460 }
461 if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) {
462 state->handler = entity3;
464 }
465 break;
466 case XML_TOK_LITERAL:
467 state->handler = declClose;
470 }
471 return common(state, tok);
472}
473
474static int PTRCALL
475entity3(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
476 const ENCODING *enc) {
477 UNUSED_P(ptr);
478 UNUSED_P(end);
479 UNUSED_P(enc);
480 switch (tok) {
481 case XML_TOK_PROLOG_S:
483 case XML_TOK_LITERAL:
484 state->handler = entity4;
486 }
487 return common(state, tok);
488}
489
490static int PTRCALL
491entity4(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
492 const ENCODING *enc) {
493 UNUSED_P(ptr);
494 UNUSED_P(end);
495 UNUSED_P(enc);
496 switch (tok) {
497 case XML_TOK_PROLOG_S:
499 case XML_TOK_LITERAL:
500 state->handler = entity5;
502 }
503 return common(state, tok);
504}
505
506static int PTRCALL
507entity5(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
508 const ENCODING *enc) {
509 switch (tok) {
510 case XML_TOK_PROLOG_S:
513 setTopLevel(state);
515 case XML_TOK_NAME:
516 if (XmlNameMatchesAscii(enc, ptr, end, KW_NDATA)) {
517 state->handler = entity6;
519 }
520 break;
521 }
522 return common(state, tok);
523}
524
525static int PTRCALL
526entity6(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
527 const ENCODING *enc) {
528 UNUSED_P(ptr);
529 UNUSED_P(end);
530 UNUSED_P(enc);
531 switch (tok) {
532 case XML_TOK_PROLOG_S:
534 case XML_TOK_NAME:
535 state->handler = declClose;
538 }
539 return common(state, tok);
540}
541
542static int PTRCALL
543entity7(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
544 const ENCODING *enc) {
545 switch (tok) {
546 case XML_TOK_PROLOG_S:
548 case XML_TOK_NAME:
549 if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) {
550 state->handler = entity9;
552 }
553 if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) {
554 state->handler = entity8;
556 }
557 break;
558 case XML_TOK_LITERAL:
559 state->handler = declClose;
562 }
563 return common(state, tok);
564}
565
566static int PTRCALL
567entity8(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
568 const ENCODING *enc) {
569 UNUSED_P(ptr);
570 UNUSED_P(end);
571 UNUSED_P(enc);
572 switch (tok) {
573 case XML_TOK_PROLOG_S:
575 case XML_TOK_LITERAL:
576 state->handler = entity9;
578 }
579 return common(state, tok);
580}
581
582static int PTRCALL
583entity9(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
584 const ENCODING *enc) {
585 UNUSED_P(ptr);
586 UNUSED_P(end);
587 UNUSED_P(enc);
588 switch (tok) {
589 case XML_TOK_PROLOG_S:
591 case XML_TOK_LITERAL:
592 state->handler = entity10;
594 }
595 return common(state, tok);
596}
597
598static int PTRCALL
599entity10(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
600 const ENCODING *enc) {
601 UNUSED_P(ptr);
602 UNUSED_P(end);
603 UNUSED_P(enc);
604 switch (tok) {
605 case XML_TOK_PROLOG_S:
608 setTopLevel(state);
610 }
611 return common(state, tok);
612}
613
614static int PTRCALL
615notation0(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
616 const ENCODING *enc) {
617 UNUSED_P(ptr);
618 UNUSED_P(end);
619 UNUSED_P(enc);
620 switch (tok) {
621 case XML_TOK_PROLOG_S:
623 case XML_TOK_NAME:
624 state->handler = notation1;
626 }
627 return common(state, tok);
628}
629
630static int PTRCALL
631notation1(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
632 const ENCODING *enc) {
633 switch (tok) {
634 case XML_TOK_PROLOG_S:
636 case XML_TOK_NAME:
637 if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) {
638 state->handler = notation3;
640 }
641 if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) {
642 state->handler = notation2;
644 }
645 break;
646 }
647 return common(state, tok);
648}
649
650static int PTRCALL
651notation2(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
652 const ENCODING *enc) {
653 UNUSED_P(ptr);
654 UNUSED_P(end);
655 UNUSED_P(enc);
656 switch (tok) {
657 case XML_TOK_PROLOG_S:
659 case XML_TOK_LITERAL:
660 state->handler = notation4;
662 }
663 return common(state, tok);
664}
665
666static int PTRCALL
667notation3(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
668 const ENCODING *enc) {
669 UNUSED_P(ptr);
670 UNUSED_P(end);
671 UNUSED_P(enc);
672 switch (tok) {
673 case XML_TOK_PROLOG_S:
675 case XML_TOK_LITERAL:
676 state->handler = declClose;
679 }
680 return common(state, tok);
681}
682
683static int PTRCALL
684notation4(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
685 const ENCODING *enc) {
686 UNUSED_P(ptr);
687 UNUSED_P(end);
688 UNUSED_P(enc);
689 switch (tok) {
690 case XML_TOK_PROLOG_S:
692 case XML_TOK_LITERAL:
693 state->handler = declClose;
697 setTopLevel(state);
699 }
700 return common(state, tok);
701}
702
703static int PTRCALL
704attlist0(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
705 const ENCODING *enc) {
706 UNUSED_P(ptr);
707 UNUSED_P(end);
708 UNUSED_P(enc);
709 switch (tok) {
710 case XML_TOK_PROLOG_S:
712 case XML_TOK_NAME:
714 state->handler = attlist1;
716 }
717 return common(state, tok);
718}
719
720static int PTRCALL
721attlist1(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
722 const ENCODING *enc) {
723 UNUSED_P(ptr);
724 UNUSED_P(end);
725 UNUSED_P(enc);
726 switch (tok) {
727 case XML_TOK_PROLOG_S:
730 setTopLevel(state);
732 case XML_TOK_NAME:
734 state->handler = attlist2;
736 }
737 return common(state, tok);
738}
739
740static int PTRCALL
741attlist2(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
742 const ENCODING *enc) {
743 switch (tok) {
744 case XML_TOK_PROLOG_S:
746 case XML_TOK_NAME: {
747 static const char *const types[] = {
748 KW_CDATA, KW_ID, KW_IDREF, KW_IDREFS,
749 KW_ENTITY, KW_ENTITIES, KW_NMTOKEN, KW_NMTOKENS,
750 };
751 int i;
752 for (i = 0; i < (int)(sizeof(types) / sizeof(types[0])); i++)
753 if (XmlNameMatchesAscii(enc, ptr, end, types[i])) {
754 state->handler = attlist8;
756 }
757 }
758 if (XmlNameMatchesAscii(enc, ptr, end, KW_NOTATION)) {
759 state->handler = attlist5;
761 }
762 break;
764 state->handler = attlist3;
766 }
767 return common(state, tok);
768}
769
770static int PTRCALL
771attlist3(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
772 const ENCODING *enc) {
773 UNUSED_P(ptr);
774 UNUSED_P(end);
775 UNUSED_P(enc);
776 switch (tok) {
777 case XML_TOK_PROLOG_S:
779 case XML_TOK_NMTOKEN:
780 case XML_TOK_NAME:
782 state->handler = attlist4;
784 }
785 return common(state, tok);
786}
787
788static int PTRCALL
789attlist4(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
790 const ENCODING *enc) {
791 UNUSED_P(ptr);
792 UNUSED_P(end);
793 UNUSED_P(enc);
794 switch (tok) {
795 case XML_TOK_PROLOG_S:
798 state->handler = attlist8;
800 case XML_TOK_OR:
801 state->handler = attlist3;
803 }
804 return common(state, tok);
805}
806
807static int PTRCALL
808attlist5(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
809 const ENCODING *enc) {
810 UNUSED_P(ptr);
811 UNUSED_P(end);
812 UNUSED_P(enc);
813 switch (tok) {
814 case XML_TOK_PROLOG_S:
817 state->handler = attlist6;
819 }
820 return common(state, tok);
821}
822
823static int PTRCALL
824attlist6(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
825 const ENCODING *enc) {
826 UNUSED_P(ptr);
827 UNUSED_P(end);
828 UNUSED_P(enc);
829 switch (tok) {
830 case XML_TOK_PROLOG_S:
832 case XML_TOK_NAME:
833 state->handler = attlist7;
835 }
836 return common(state, tok);
837}
838
839static int PTRCALL
840attlist7(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
841 const ENCODING *enc) {
842 UNUSED_P(ptr);
843 UNUSED_P(end);
844 UNUSED_P(enc);
845 switch (tok) {
846 case XML_TOK_PROLOG_S:
849 state->handler = attlist8;
851 case XML_TOK_OR:
852 state->handler = attlist6;
854 }
855 return common(state, tok);
856}
857
858/* default value */
859static int PTRCALL
860attlist8(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
861 const ENCODING *enc) {
862 switch (tok) {
863 case XML_TOK_PROLOG_S:
866 if (XmlNameMatchesAscii(enc, ptr + MIN_BYTES_PER_CHAR(enc), end,
867 KW_IMPLIED)) {
868 state->handler = attlist1;
870 }
871 if (XmlNameMatchesAscii(enc, ptr + MIN_BYTES_PER_CHAR(enc), end,
872 KW_REQUIRED)) {
873 state->handler = attlist1;
875 }
876 if (XmlNameMatchesAscii(enc, ptr + MIN_BYTES_PER_CHAR(enc), end,
877 KW_FIXED)) {
878 state->handler = attlist9;
880 }
881 break;
882 case XML_TOK_LITERAL:
883 state->handler = attlist1;
885 }
886 return common(state, tok);
887}
888
889static int PTRCALL
890attlist9(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
891 const ENCODING *enc) {
892 UNUSED_P(ptr);
893 UNUSED_P(end);
894 UNUSED_P(enc);
895 switch (tok) {
896 case XML_TOK_PROLOG_S:
898 case XML_TOK_LITERAL:
899 state->handler = attlist1;
901 }
902 return common(state, tok);
903}
904
905static int PTRCALL
906element0(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
907 const ENCODING *enc) {
908 UNUSED_P(ptr);
909 UNUSED_P(end);
910 UNUSED_P(enc);
911 switch (tok) {
912 case XML_TOK_PROLOG_S:
914 case XML_TOK_NAME:
916 state->handler = element1;
918 }
919 return common(state, tok);
920}
921
922static int PTRCALL
923element1(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
924 const ENCODING *enc) {
925 switch (tok) {
926 case XML_TOK_PROLOG_S:
928 case XML_TOK_NAME:
929 if (XmlNameMatchesAscii(enc, ptr, end, KW_EMPTY)) {
930 state->handler = declClose;
933 }
934 if (XmlNameMatchesAscii(enc, ptr, end, KW_ANY)) {
935 state->handler = declClose;
938 }
939 break;
941 state->handler = element2;
942 state->level = 1;
943 return XML_ROLE_GROUP_OPEN;
944 }
945 return common(state, tok);
946}
947
948static int PTRCALL
949element2(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
950 const ENCODING *enc) {
951 switch (tok) {
952 case XML_TOK_PROLOG_S:
955 if (XmlNameMatchesAscii(enc, ptr + MIN_BYTES_PER_CHAR(enc), end,
956 KW_PCDATA)) {
957 state->handler = element3;
959 }
960 break;
962 state->level = 2;
963 state->handler = element6;
964 return XML_ROLE_GROUP_OPEN;
965 case XML_TOK_NAME:
967 state->handler = element7;
970 state->handler = element7;
973 state->handler = element7;
976 state->handler = element7;
978 }
979 return common(state, tok);
980}
981
982static int PTRCALL
983element3(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
984 const ENCODING *enc) {
985 UNUSED_P(ptr);
986 UNUSED_P(end);
987 UNUSED_P(enc);
988 switch (tok) {
989 case XML_TOK_PROLOG_S:
992 state->handler = declClose;
996 state->handler = declClose;
999 case XML_TOK_OR:
1000 state->handler = element4;
1001 return XML_ROLE_ELEMENT_NONE;
1002 }
1003 return common(state, tok);
1004}
1005
1006static int PTRCALL
1007element4(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
1008 const ENCODING *enc) {
1009 UNUSED_P(ptr);
1010 UNUSED_P(end);
1011 UNUSED_P(enc);
1012 switch (tok) {
1013 case XML_TOK_PROLOG_S:
1014 return XML_ROLE_ELEMENT_NONE;
1015 case XML_TOK_NAME:
1017 state->handler = element5;
1019 }
1020 return common(state, tok);
1021}
1022
1023static int PTRCALL
1024element5(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
1025 const ENCODING *enc) {
1026 UNUSED_P(ptr);
1027 UNUSED_P(end);
1028 UNUSED_P(enc);
1029 switch (tok) {
1030 case XML_TOK_PROLOG_S:
1031 return XML_ROLE_ELEMENT_NONE;
1033 state->handler = declClose;
1036 case XML_TOK_OR:
1037 state->handler = element4;
1038 return XML_ROLE_ELEMENT_NONE;
1039 }
1040 return common(state, tok);
1041}
1042
1043static int PTRCALL
1044element6(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
1045 const ENCODING *enc) {
1046 UNUSED_P(ptr);
1047 UNUSED_P(end);
1048 UNUSED_P(enc);
1049 switch (tok) {
1050 case XML_TOK_PROLOG_S:
1051 return XML_ROLE_ELEMENT_NONE;
1052 case XML_TOK_OPEN_PAREN:
1053 state->level += 1;
1054 return XML_ROLE_GROUP_OPEN;
1055 case XML_TOK_NAME:
1057 state->handler = element7;
1060 state->handler = element7;
1063 state->handler = element7;
1065 case XML_TOK_NAME_PLUS:
1066 state->handler = element7;
1068 }
1069 return common(state, tok);
1070}
1071
1072static int PTRCALL
1073element7(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
1074 const ENCODING *enc) {
1075 UNUSED_P(ptr);
1076 UNUSED_P(end);
1077 UNUSED_P(enc);
1078 switch (tok) {
1079 case XML_TOK_PROLOG_S:
1080 return XML_ROLE_ELEMENT_NONE;
1082 state->level -= 1;
1083 if (state->level == 0) {
1084 state->handler = declClose;
1086 }
1087 return XML_ROLE_GROUP_CLOSE;
1089 state->level -= 1;
1090 if (state->level == 0) {
1091 state->handler = declClose;
1093 }
1096 state->level -= 1;
1097 if (state->level == 0) {
1098 state->handler = declClose;
1100 }
1103 state->level -= 1;
1104 if (state->level == 0) {
1105 state->handler = declClose;
1107 }
1109 case XML_TOK_COMMA:
1110 state->handler = element6;
1112 case XML_TOK_OR:
1113 state->handler = element6;
1114 return XML_ROLE_GROUP_CHOICE;
1115 }
1116 return common(state, tok);
1117}
1118
1119#ifdef XML_DTD
1120
1121static int PTRCALL
1122condSect0(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
1123 const ENCODING *enc) {
1124 switch (tok) {
1125 case XML_TOK_PROLOG_S:
1126 return XML_ROLE_NONE;
1127 case XML_TOK_NAME:
1128 if (XmlNameMatchesAscii(enc, ptr, end, KW_INCLUDE)) {
1129 state->handler = condSect1;
1130 return XML_ROLE_NONE;
1131 }
1132 if (XmlNameMatchesAscii(enc, ptr, end, KW_IGNORE)) {
1133 state->handler = condSect2;
1134 return XML_ROLE_NONE;
1135 }
1136 break;
1137 }
1138 return common(state, tok);
1139}
1140
1141static int PTRCALL
1142condSect1(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
1143 const ENCODING *enc) {
1144 UNUSED_P(ptr);
1145 UNUSED_P(end);
1146 UNUSED_P(enc);
1147 switch (tok) {
1148 case XML_TOK_PROLOG_S:
1149 return XML_ROLE_NONE;
1151 state->handler = externalSubset1;
1152 state->includeLevel += 1;
1153 return XML_ROLE_NONE;
1154 }
1155 return common(state, tok);
1156}
1157
1158static int PTRCALL
1159condSect2(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
1160 const ENCODING *enc) {
1161 UNUSED_P(ptr);
1162 UNUSED_P(end);
1163 UNUSED_P(enc);
1164 switch (tok) {
1165 case XML_TOK_PROLOG_S:
1166 return XML_ROLE_NONE;
1168 state->handler = externalSubset1;
1169 return XML_ROLE_IGNORE_SECT;
1170 }
1171 return common(state, tok);
1172}
1173
1174#endif /* XML_DTD */
1175
1176static int PTRCALL
1177declClose(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
1178 const ENCODING *enc) {
1179 UNUSED_P(ptr);
1180 UNUSED_P(end);
1181 UNUSED_P(enc);
1182 switch (tok) {
1183 case XML_TOK_PROLOG_S:
1184 return state->role_none;
1185 case XML_TOK_DECL_CLOSE:
1186 setTopLevel(state);
1187 return state->role_none;
1188 }
1189 return common(state, tok);
1190}
1191
1192/* This function will only be invoked if the internal logic of the
1193 * parser has broken down. It is used in two cases:
1194 *
1195 * 1: When the XML prolog has been finished. At this point the
1196 * processor (the parser level above these role handlers) should
1197 * switch from prologProcessor to contentProcessor and reinitialise
1198 * the handler function.
1199 *
1200 * 2: When an error has been detected (via common() below). At this
1201 * point again the processor should be switched to errorProcessor,
1202 * which will never call a handler.
1203 *
1204 * The result of this is that error() can only be called if the
1205 * processor switch failed to happen, which is an internal error and
1206 * therefore we shouldn't be able to provoke it simply by using the
1207 * library. It is a necessary backstop, however, so we merely exclude
1208 * it from the coverage statistics.
1209 *
1210 * LCOV_EXCL_START
1211 */
1212static int PTRCALL
1213error(PROLOG_STATE *state, int tok, const char *ptr, const char *end,
1214 const ENCODING *enc) {
1215 UNUSED_P(state);
1216 UNUSED_P(tok);
1217 UNUSED_P(ptr);
1218 UNUSED_P(end);
1219 UNUSED_P(enc);
1220 return XML_ROLE_NONE;
1221}
1222/* LCOV_EXCL_STOP */
1223
1224static int FASTCALL
1225common(PROLOG_STATE *state, int tok) {
1226#ifdef XML_DTD
1227 if (! state->documentEntity && tok == XML_TOK_PARAM_ENTITY_REF)
1228 return XML_ROLE_INNER_PARAM_ENTITY_REF;
1229#else
1230 UNUSED_P(tok);
1231#endif
1232 state->handler = error;
1233 return XML_ROLE_ERROR;
1234}
1235
1236void
1238 state->handler = prolog0;
1239#ifdef XML_DTD
1240 state->documentEntity = 1;
1241 state->includeLevel = 0;
1242 state->inEntityValue = 0;
1243#endif /* XML_DTD */
1244}
1245
1246#ifdef XML_DTD
1247
1248void
1249XmlPrologStateInitExternalEntity(PROLOG_STATE *state) {
1250 state->handler = externalSubset0;
1251 state->documentEntity = 0;
1252 state->includeLevel = 0;
1253}
1254
1255#endif /* XML_DTD */
#define ASCII_X
Definition: ascii.h:59
#define ASCII_F
Definition: ascii.h:41
#define ASCII_E
Definition: ascii.h:40
#define ASCII_C
Definition: ascii.h:38
#define ASCII_O
Definition: ascii.h:50
#define ASCII_N
Definition: ascii.h:49
#define ASCII_D
Definition: ascii.h:39
#define ASCII_G
Definition: ascii.h:42
#define ASCII_I
Definition: ascii.h:44
#define ASCII_A
Definition: ascii.h:36
#define ASCII_R
Definition: ascii.h:53
#define ASCII_U
Definition: ascii.h:56
#define ASCII_P
Definition: ascii.h:51
#define ASCII_M
Definition: ascii.h:48
#define ASCII_K
Definition: ascii.h:46
#define ASCII_L
Definition: ascii.h:47
#define ASCII_Q
Definition: ascii.h:52
#define ASCII_B
Definition: ascii.h:37
#define ASCII_S
Definition: ascii.h:54
#define ASCII_T
Definition: ascii.h:55
#define ASCII_Y
Definition: ascii.h:60
#define FASTCALL
Definition: internal.h:81
#define UNUSED_P(p)
Definition: internal.h:135
#define PTRCALL
Definition: internal.h:85
unsigned level
Definition: xmlrole.h:121
int role_none
Definition: xmlrole.h:122
#define setTopLevel(state)
Definition: xmlrole.c:119
int PTRCALL PROLOG_HANDLER(PROLOG_STATE *state, int tok, const char *ptr, const char *end, const ENCODING *enc)
Definition: xmlrole.c:122
void XmlPrologStateInit(PROLOG_STATE *state)
Definition: xmlrole.c:1237
#define MIN_BYTES_PER_CHAR(enc)
Definition: xmlrole.c:111
@ XML_ROLE_GROUP_CHOICE
Definition: xmlrole.h:102
@ XML_ROLE_NOTATION_PUBLIC_ID
Definition: xmlrole.h:74
@ XML_ROLE_ERROR
Definition: xmlrole.h:52
@ XML_ROLE_GROUP_CLOSE_REP
Definition: xmlrole.h:99
@ XML_ROLE_CONTENT_PCDATA
Definition: xmlrole.h:96
@ XML_ROLE_CONTENT_ELEMENT_REP
Definition: xmlrole.h:105
@ XML_ROLE_ENTITY_COMPLETE
Definition: xmlrole.h:68
@ XML_ROLE_DOCTYPE_INTERNAL_SUBSET
Definition: xmlrole.h:60
@ XML_ROLE_NOTATION_NO_SYSTEM_ID
Definition: xmlrole.h:73
@ XML_ROLE_DOCTYPE_NONE
Definition: xmlrole.h:56
@ XML_ROLE_PARAM_ENTITY_REF
Definition: xmlrole.h:115
@ XML_ROLE_GROUP_CLOSE
Definition: xmlrole.h:98
@ XML_ROLE_DOCTYPE_CLOSE
Definition: xmlrole.h:61
@ XML_ROLE_ENTITY_NOTATION_NAME
Definition: xmlrole.h:69
@ XML_ROLE_GROUP_SEQUENCE
Definition: xmlrole.h:103
@ XML_ROLE_ATTLIST_ELEMENT_NAME
Definition: xmlrole.h:87
@ XML_ROLE_GROUP_CLOSE_OPT
Definition: xmlrole.h:100
@ XML_ROLE_IMPLIED_ATTRIBUTE_VALUE
Definition: xmlrole.h:88
@ XML_ROLE_ATTRIBUTE_TYPE_CDATA
Definition: xmlrole.h:76
@ XML_ROLE_COMMENT
Definition: xmlrole.h:109
@ XML_ROLE_ATTRIBUTE_ENUM_VALUE
Definition: xmlrole.h:84
@ XML_ROLE_ENTITY_SYSTEM_ID
Definition: xmlrole.h:66
@ XML_ROLE_CONTENT_ELEMENT
Definition: xmlrole.h:104
@ XML_ROLE_ATTLIST_NONE
Definition: xmlrole.h:86
@ XML_ROLE_ATTRIBUTE_NOTATION_VALUE
Definition: xmlrole.h:85
@ XML_ROLE_DOCTYPE_SYSTEM_ID
Definition: xmlrole.h:58
@ XML_ROLE_NOTATION_SYSTEM_ID
Definition: xmlrole.h:72
@ XML_ROLE_PI
Definition: xmlrole.h:108
@ XML_ROLE_ATTRIBUTE_NAME
Definition: xmlrole.h:75
@ XML_ROLE_CONTENT_ANY
Definition: xmlrole.h:94
@ XML_ROLE_ENTITY_NONE
Definition: xmlrole.h:64
@ XML_ROLE_NONE
Definition: xmlrole.h:53
@ XML_ROLE_ELEMENT_NONE
Definition: xmlrole.h:92
@ XML_ROLE_ENTITY_PUBLIC_ID
Definition: xmlrole.h:67
@ XML_ROLE_INSTANCE_START
Definition: xmlrole.h:55
@ XML_ROLE_DOCTYPE_NAME
Definition: xmlrole.h:57
@ XML_ROLE_NOTATION_NAME
Definition: xmlrole.h:71
@ XML_ROLE_CONTENT_ELEMENT_PLUS
Definition: xmlrole.h:107
@ XML_ROLE_GENERAL_ENTITY_NAME
Definition: xmlrole.h:62
@ XML_ROLE_PARAM_ENTITY_NAME
Definition: xmlrole.h:63
@ XML_ROLE_DEFAULT_ATTRIBUTE_VALUE
Definition: xmlrole.h:90
@ XML_ROLE_NOTATION_NONE
Definition: xmlrole.h:70
@ XML_ROLE_XML_DECL
Definition: xmlrole.h:54
@ XML_ROLE_GROUP_CLOSE_PLUS
Definition: xmlrole.h:101
@ XML_ROLE_REQUIRED_ATTRIBUTE_VALUE
Definition: xmlrole.h:89
@ XML_ROLE_GROUP_OPEN
Definition: xmlrole.h:97
@ XML_ROLE_CONTENT_EMPTY
Definition: xmlrole.h:95
@ XML_ROLE_FIXED_ATTRIBUTE_VALUE
Definition: xmlrole.h:91
@ XML_ROLE_CONTENT_ELEMENT_OPT
Definition: xmlrole.h:106
@ XML_ROLE_DOCTYPE_PUBLIC_ID
Definition: xmlrole.h:59
@ XML_ROLE_ELEMENT_NAME
Definition: xmlrole.h:93
@ XML_ROLE_ENTITY_VALUE
Definition: xmlrole.h:65
#define XML_TOK_NAME
Definition: xmltok.h:83
#define XML_TOK_CLOSE_PAREN_ASTERISK
Definition: xmltok.h:103
#define XML_TOK_DECL_OPEN
Definition: xmltok.h:81
#define XML_TOK_PREFIXED_NAME
Definition: xmltok.h:116
#define XML_TOK_OPEN_PAREN
Definition: xmltok.h:88
#define XML_TOK_PI
Definition: xmltok.h:74
#define XML_TOK_OPEN_BRACKET
Definition: xmltok.h:90
#define XML_TOK_NMTOKEN
Definition: xmltok.h:84
#define XML_TOK_CLOSE_PAREN_PLUS
Definition: xmltok.h:104
#define XML_TOK_CLOSE_PAREN
Definition: xmltok.h:89
#define XML_TOK_NAME_ASTERISK
Definition: xmltok.h:98
#define XML_TOK_DECL_CLOSE
Definition: xmltok.h:82
#define XML_TOK_COMMENT
Definition: xmltok.h:76
#define XML_TOK_NAME_PLUS
Definition: xmltok.h:99
#define XML_TOK_NAME_QUESTION
Definition: xmltok.h:97
#define XML_TOK_COND_SECT_CLOSE
Definition: xmltok.h:101
#define XML_TOK_XML_DECL
Definition: xmltok.h:75
#define XML_TOK_PROLOG_S
Definition: xmltok.h:80
#define XML_TOK_COND_SECT_OPEN
Definition: xmltok.h:100
#define XML_TOK_POUND_NAME
Definition: xmltok.h:85
#define XML_TOK_PARAM_ENTITY_REF
Definition: xmltok.h:93
#define XML_TOK_CLOSE_BRACKET
Definition: xmltok.h:91
#define XML_TOK_PERCENT
Definition: xmltok.h:87
#define XmlNameMatchesAscii(enc, ptr1, end1, ptr2)
Definition: xmltok.h:252
#define XML_TOK_OR
Definition: xmltok.h:86
#define XML_TOK_COMMA
Definition: xmltok.h:105
#define XML_TOK_LITERAL
Definition: xmltok.h:92
#define XML_TOK_NONE
Definition: xmltok.h:50
#define XML_TOK_INSTANCE_START
Definition: xmltok.h:94
#define XML_TOK_CLOSE_PAREN_QUESTION
Definition: xmltok.h:102
#define XML_TOK_BOM
Definition: xmltok.h:77