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