ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
xmlrole.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file xmlrole.cc
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 
37 static const char KW_ANY[] = {
38  ASCII_A, ASCII_N, ASCII_Y, '\0' };
39 static const char KW_ATTLIST[] = {
41 static const char KW_CDATA[] = {
43 static const char KW_DOCTYPE[] = {
45 static const char KW_ELEMENT[] = {
47 static const char KW_EMPTY[] = {
49 static const char KW_ENTITIES[] = {
51  '\0' };
52 static const char KW_ENTITY[] = {
54 static const char KW_FIXED[] = {
56 static const char KW_ID[] = {
57  ASCII_I, ASCII_D, '\0' };
58 static const char KW_IDREF[] = {
60 static const char KW_IDREFS[] = {
62 #ifdef XML_DTD
63 static const char KW_IGNORE[] = {
65 #endif
66 static const char KW_IMPLIED[] = {
68 #ifdef XML_DTD
69 static const char KW_INCLUDE[] = {
71 #endif
72 static const char KW_NDATA[] = {
74 static const char KW_NMTOKEN[] = {
76 static const char KW_NMTOKENS[] = {
78  '\0' };
79 static const char KW_NOTATION[] =
81  '\0' };
82 static const char KW_PCDATA[] = {
84 static const char KW_PUBLIC[] = {
86 static const char KW_REQUIRED[] = {
88  '\0' };
89 static 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 
111 static PROLOG_HANDLER
121  element7,
122 #ifdef XML_DTD
123  externalSubset0, externalSubset1,
124  condSect0, condSect1, condSect2,
125 #endif /* XML_DTD */
126  declClose,
127  error;
128 
129 static int FASTCALL common(PROLOG_STATE *state, int tok);
130 
131 static int PTRCALL
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;
153  case XML_TOK_DECL_OPEN:
154  if (!XmlNameMatchesAscii(enc,
155  ptr + 2 * MIN_BYTES_PER_CHAR(enc),
156  end,
157  KW_DOCTYPE))
158  break;
159  state->handler = doctype0;
160  return XML_ROLE_DOCTYPE_NONE;
162  state->handler = error;
164  }
165  return common(state, tok);
166 }
167 
168 static int PTRCALL
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;
184  case XML_TOK_DECL_OPEN:
185  if (!XmlNameMatchesAscii(enc,
186  ptr + 2 * MIN_BYTES_PER_CHAR(enc),
187  end,
188  KW_DOCTYPE))
189  break;
190  state->handler = doctype0;
191  return XML_ROLE_DOCTYPE_NONE;
193  state->handler = error;
195  }
196  return common(state, tok);
197 }
198 
199 static int PTRCALL
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 
220 static int PTRCALL
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:
229  return XML_ROLE_DOCTYPE_NONE;
230  case XML_TOK_NAME:
232  state->handler = doctype1;
233  return XML_ROLE_DOCTYPE_NAME;
234  }
235  return common(state, tok);
236 }
237 
238 static int PTRCALL
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:
247  return XML_ROLE_DOCTYPE_NONE;
249  state->handler = internalSubset;
251  case XML_TOK_DECL_CLOSE:
252  state->handler = prolog2;
253  return XML_ROLE_DOCTYPE_CLOSE;
254  case XML_TOK_NAME:
255  if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) {
256  state->handler = doctype3;
257  return XML_ROLE_DOCTYPE_NONE;
258  }
259  if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) {
260  state->handler = doctype2;
261  return XML_ROLE_DOCTYPE_NONE;
262  }
263  break;
264  }
265  return common(state, tok);
266 }
267 
268 static int PTRCALL
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:
277  return XML_ROLE_DOCTYPE_NONE;
278  case XML_TOK_LITERAL:
279  state->handler = doctype3;
281  }
282  return common(state, tok);
283 }
284 
285 static int PTRCALL
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:
294  return XML_ROLE_DOCTYPE_NONE;
295  case XML_TOK_LITERAL:
296  state->handler = doctype4;
298  }
299  return common(state, tok);
300 }
301 
302 static int PTRCALL
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:
311  return XML_ROLE_DOCTYPE_NONE;
313  state->handler = internalSubset;
315  case XML_TOK_DECL_CLOSE:
316  state->handler = prolog2;
317  return XML_ROLE_DOCTYPE_CLOSE;
318  }
319  return common(state, tok);
320 }
321 
322 static int PTRCALL
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:
331  return XML_ROLE_DOCTYPE_NONE;
332  case XML_TOK_DECL_CLOSE:
333  state->handler = prolog2;
334  return XML_ROLE_DOCTYPE_CLOSE;
335  }
336  return common(state, tok);
337 }
338 
339 static int PTRCALL
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;
349  case XML_TOK_DECL_OPEN:
350  if (XmlNameMatchesAscii(enc,
351  ptr + 2 * MIN_BYTES_PER_CHAR(enc),
352  end,
353  KW_ENTITY)) {
354  state->handler = entity0;
355  return XML_ROLE_ENTITY_NONE;
356  }
357  if (XmlNameMatchesAscii(enc,
358  ptr + 2 * MIN_BYTES_PER_CHAR(enc),
359  end,
360  KW_ATTLIST)) {
361  state->handler = attlist0;
362  return XML_ROLE_ATTLIST_NONE;
363  }
364  if (XmlNameMatchesAscii(enc,
365  ptr + 2 * MIN_BYTES_PER_CHAR(enc),
366  end,
367  KW_ELEMENT)) {
368  state->handler = element0;
369  return XML_ROLE_ELEMENT_NONE;
370  }
371  if (XmlNameMatchesAscii(enc,
372  ptr + 2 * MIN_BYTES_PER_CHAR(enc),
373  end,
374  KW_NOTATION)) {
375  state->handler = notation0;
376  return XML_ROLE_NOTATION_NONE;
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;
387  return XML_ROLE_DOCTYPE_NONE;
388  case XML_TOK_NONE:
389  return XML_ROLE_NONE;
390  }
391  return common(state, tok);
392 }
393 
394 #ifdef XML_DTD
395 
396 static int PTRCALL
397 externalSubset0(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 
409 static int PTRCALL
410 externalSubset1(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 
441 static int PTRCALL
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:
450  return XML_ROLE_ENTITY_NONE;
451  case XML_TOK_PERCENT:
452  state->handler = entity1;
453  return XML_ROLE_ENTITY_NONE;
454  case XML_TOK_NAME:
455  state->handler = entity2;
457  }
458  return common(state, tok);
459 }
460 
461 static int PTRCALL
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:
470  return XML_ROLE_ENTITY_NONE;
471  case XML_TOK_NAME:
472  state->handler = entity7;
474  }
475  return common(state, tok);
476 }
477 
478 static int PTRCALL
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:
487  return XML_ROLE_ENTITY_NONE;
488  case XML_TOK_NAME:
489  if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) {
490  state->handler = entity4;
491  return XML_ROLE_ENTITY_NONE;
492  }
493  if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) {
494  state->handler = entity3;
495  return XML_ROLE_ENTITY_NONE;
496  }
497  break;
498  case XML_TOK_LITERAL:
499  state->handler = declClose;
501  return XML_ROLE_ENTITY_VALUE;
502  }
503  return common(state, tok);
504 }
505 
506 static int PTRCALL
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:
515  return XML_ROLE_ENTITY_NONE;
516  case XML_TOK_LITERAL:
517  state->handler = entity4;
519  }
520  return common(state, tok);
521 }
522 
523 static int PTRCALL
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:
532  return XML_ROLE_ENTITY_NONE;
533  case XML_TOK_LITERAL:
534  state->handler = entity5;
536  }
537  return common(state, tok);
538 }
539 
540 static int PTRCALL
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:
549  return XML_ROLE_ENTITY_NONE;
550  case XML_TOK_DECL_CLOSE:
551  setTopLevel(state);
553  case XML_TOK_NAME:
554  if (XmlNameMatchesAscii(enc, ptr, end, KW_NDATA)) {
555  state->handler = entity6;
556  return XML_ROLE_ENTITY_NONE;
557  }
558  break;
559  }
560  return common(state, tok);
561 }
562 
563 static int PTRCALL
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:
572  return XML_ROLE_ENTITY_NONE;
573  case XML_TOK_NAME:
574  state->handler = declClose;
577  }
578  return common(state, tok);
579 }
580 
581 static int PTRCALL
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:
590  return XML_ROLE_ENTITY_NONE;
591  case XML_TOK_NAME:
592  if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) {
593  state->handler = entity9;
594  return XML_ROLE_ENTITY_NONE;
595  }
596  if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) {
597  state->handler = entity8;
598  return XML_ROLE_ENTITY_NONE;
599  }
600  break;
601  case XML_TOK_LITERAL:
602  state->handler = declClose;
604  return XML_ROLE_ENTITY_VALUE;
605  }
606  return common(state, tok);
607 }
608 
609 static int PTRCALL
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:
618  return XML_ROLE_ENTITY_NONE;
619  case XML_TOK_LITERAL:
620  state->handler = entity9;
622  }
623  return common(state, tok);
624 }
625 
626 static int PTRCALL
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:
635  return XML_ROLE_ENTITY_NONE;
636  case XML_TOK_LITERAL:
637  state->handler = entity10;
639  }
640  return common(state, tok);
641 }
642 
643 static int PTRCALL
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:
652  return XML_ROLE_ENTITY_NONE;
653  case XML_TOK_DECL_CLOSE:
654  setTopLevel(state);
656  }
657  return common(state, tok);
658 }
659 
660 static int PTRCALL
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:
669  return XML_ROLE_NOTATION_NONE;
670  case XML_TOK_NAME:
671  state->handler = notation1;
672  return XML_ROLE_NOTATION_NAME;
673  }
674  return common(state, tok);
675 }
676 
677 static int PTRCALL
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:
686  return XML_ROLE_NOTATION_NONE;
687  case XML_TOK_NAME:
688  if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) {
689  state->handler = notation3;
690  return XML_ROLE_NOTATION_NONE;
691  }
692  if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) {
693  state->handler = notation2;
694  return XML_ROLE_NOTATION_NONE;
695  }
696  break;
697  }
698  return common(state, tok);
699 }
700 
701 static int PTRCALL
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:
710  return XML_ROLE_NOTATION_NONE;
711  case XML_TOK_LITERAL:
712  state->handler = notation4;
714  }
715  return common(state, tok);
716 }
717 
718 static int PTRCALL
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:
727  return XML_ROLE_NOTATION_NONE;
728  case XML_TOK_LITERAL:
729  state->handler = declClose;
732  }
733  return common(state, tok);
734 }
735 
736 static int PTRCALL
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:
745  return XML_ROLE_NOTATION_NONE;
746  case XML_TOK_LITERAL:
747  state->handler = declClose;
750  case XML_TOK_DECL_CLOSE:
751  setTopLevel(state);
753  }
754  return common(state, tok);
755 }
756 
757 static int PTRCALL
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:
766  return XML_ROLE_ATTLIST_NONE;
767  case XML_TOK_NAME:
769  state->handler = attlist1;
771  }
772  return common(state, tok);
773 }
774 
775 static int PTRCALL
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:
784  return XML_ROLE_ATTLIST_NONE;
785  case XML_TOK_DECL_CLOSE:
786  setTopLevel(state);
787  return XML_ROLE_ATTLIST_NONE;
788  case XML_TOK_NAME:
790  state->handler = attlist2;
792  }
793  return common(state, tok);
794 }
795 
796 static int PTRCALL
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:
805  return XML_ROLE_ATTLIST_NONE;
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;
827  return XML_ROLE_ATTLIST_NONE;
828  }
829  break;
830  case XML_TOK_OPEN_PAREN:
831  state->handler = attlist3;
832  return XML_ROLE_ATTLIST_NONE;
833  }
834  return common(state, tok);
835 }
836 
837 static int PTRCALL
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:
846  return XML_ROLE_ATTLIST_NONE;
847  case XML_TOK_NMTOKEN:
848  case XML_TOK_NAME:
850  state->handler = attlist4;
852  }
853  return common(state, tok);
854 }
855 
856 static int PTRCALL
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:
865  return XML_ROLE_ATTLIST_NONE;
866  case XML_TOK_CLOSE_PAREN:
867  state->handler = attlist8;
868  return XML_ROLE_ATTLIST_NONE;
869  case XML_TOK_OR:
870  state->handler = attlist3;
871  return XML_ROLE_ATTLIST_NONE;
872  }
873  return common(state, tok);
874 }
875 
876 static int PTRCALL
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:
885  return XML_ROLE_ATTLIST_NONE;
886  case XML_TOK_OPEN_PAREN:
887  state->handler = attlist6;
888  return XML_ROLE_ATTLIST_NONE;
889  }
890  return common(state, tok);
891 }
892 
893 static int PTRCALL
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:
902  return XML_ROLE_ATTLIST_NONE;
903  case XML_TOK_NAME:
904  state->handler = attlist7;
906  }
907  return common(state, tok);
908 }
909 
910 static int PTRCALL
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:
919  return XML_ROLE_ATTLIST_NONE;
920  case XML_TOK_CLOSE_PAREN:
921  state->handler = attlist8;
922  return XML_ROLE_ATTLIST_NONE;
923  case XML_TOK_OR:
924  state->handler = attlist6;
925  return XML_ROLE_ATTLIST_NONE;
926  }
927  return common(state, tok);
928 }
929 
930 /* default value */
931 static int PTRCALL
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:
940  return XML_ROLE_ATTLIST_NONE;
941  case XML_TOK_POUND_NAME:
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;
961  return XML_ROLE_ATTLIST_NONE;
962  }
963  break;
964  case XML_TOK_LITERAL:
965  state->handler = attlist1;
967  }
968  return common(state, tok);
969 }
970 
971 static int PTRCALL
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:
980  return XML_ROLE_ATTLIST_NONE;
981  case XML_TOK_LITERAL:
982  state->handler = attlist1;
984  }
985  return common(state, tok);
986 }
987 
988 static int PTRCALL
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:
997  return XML_ROLE_ELEMENT_NONE;
998  case XML_TOK_NAME:
1000  state->handler = element1;
1001  return XML_ROLE_ELEMENT_NAME;
1002  }
1003  return common(state, tok);
1004 }
1005 
1006 static int PTRCALL
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;
1020  return XML_ROLE_CONTENT_EMPTY;
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 
1036 static int PTRCALL
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;
1052  return XML_ROLE_CONTENT_PCDATA;
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:
1060  case XML_TOK_PREFIXED_NAME:
1061  state->handler = element7;
1062  return XML_ROLE_CONTENT_ELEMENT;
1063  case XML_TOK_NAME_QUESTION:
1064  state->handler = element7;
1066  case XML_TOK_NAME_ASTERISK:
1067  state->handler = element7;
1069  case XML_TOK_NAME_PLUS:
1070  state->handler = element7;
1072  }
1073  return common(state, tok);
1074 }
1075 
1076 static int PTRCALL
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;
1086  case XML_TOK_CLOSE_PAREN:
1087  state->handler = declClose;
1089  return XML_ROLE_GROUP_CLOSE;
1091  state->handler = declClose;
1093  return XML_ROLE_GROUP_CLOSE_REP;
1094  case XML_TOK_OR:
1095  state->handler = element4;
1096  return XML_ROLE_ELEMENT_NONE;
1097  }
1098  return common(state, tok);
1099 }
1100 
1101 static int PTRCALL
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:
1112  case XML_TOK_PREFIXED_NAME:
1113  state->handler = element5;
1114  return XML_ROLE_CONTENT_ELEMENT;
1115  }
1116  return common(state, tok);
1117 }
1118 
1119 static int PTRCALL
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;
1132  return XML_ROLE_GROUP_CLOSE_REP;
1133  case XML_TOK_OR:
1134  state->handler = element4;
1135  return XML_ROLE_ELEMENT_NONE;
1136  }
1137  return common(state, tok);
1138 }
1139 
1140 static int PTRCALL
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:
1154  case XML_TOK_PREFIXED_NAME:
1155  state->handler = element7;
1156  return XML_ROLE_CONTENT_ELEMENT;
1157  case XML_TOK_NAME_QUESTION:
1158  state->handler = element7;
1160  case XML_TOK_NAME_ASTERISK:
1161  state->handler = element7;
1163  case XML_TOK_NAME_PLUS:
1164  state->handler = element7;
1166  }
1167  return common(state, tok);
1168 }
1169 
1170 static int PTRCALL
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;
1180  case XML_TOK_CLOSE_PAREN:
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  }
1193  return XML_ROLE_GROUP_CLOSE_REP;
1195  state->level -= 1;
1196  if (state->level == 0) {
1197  state->handler = declClose;
1199  }
1200  return XML_ROLE_GROUP_CLOSE_OPT;
1202  state->level -= 1;
1203  if (state->level == 0) {
1204  state->handler = declClose;
1206  }
1208  case XML_TOK_COMMA:
1209  state->handler = element6;
1210  return XML_ROLE_GROUP_SEQUENCE;
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 
1220 static int PTRCALL
1221 condSect0(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 
1244 static int PTRCALL
1245 condSect1(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;
1254  case XML_TOK_OPEN_BRACKET:
1255  state->handler = externalSubset1;
1256  state->includeLevel += 1;
1257  return XML_ROLE_NONE;
1258  }
1259  return common(state, tok);
1260 }
1261 
1262 static int PTRCALL
1263 condSect2(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;
1272  case XML_TOK_OPEN_BRACKET:
1273  state->handler = externalSubset1;
1274  return XML_ROLE_IGNORE_SECT;
1275  }
1276  return common(state, tok);
1277 }
1278 
1279 #endif /* XML_DTD */
1280 
1281 static int PTRCALL
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 
1298 static int PTRCALL
1300  int tok,
1301  const char *ptr,
1302  const char *end,
1303  const ENCODING *enc)
1304 {
1305  return XML_ROLE_NONE;
1306 }
1307 
1308 static int FASTCALL
1309 common(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 
1319 void
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 
1332 void
1333 XmlPrologStateInitExternalEntity(PROLOG_STATE *state)
1334 {
1335  state->handler = externalSubset0;
1336  state->documentEntity = 0;
1337  state->includeLevel = 0;
1338 }
1339 
1340 #endif /* XML_DTD */