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