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