00001
00002
00003
00004
00005 #include <stddef.h>
00006
00007 #ifdef COMPILED_FROM_DSP
00008 #include "winconfig.h"
00009 #elif defined(MACOS_CLASSIC)
00010 #include "macconfig.h"
00011 #else
00012 #ifdef HAVE_EXPAT_CONFIG_H
00013 #include <expat_config.h>
00014 #endif
00015 #endif
00016
00017 #include "expat_external.h"
00018 #include "internal.h"
00019 #include "xmlrole.h"
00020 #include "ascii.h"
00021
00022
00023
00024
00025
00026
00027
00028
00029 static const char KW_ANY[] = {
00030 ASCII_A, ASCII_N, ASCII_Y, '\0' };
00031 static const char KW_ATTLIST[] = {
00032 ASCII_A, ASCII_T, ASCII_T, ASCII_L, ASCII_I, ASCII_S, ASCII_T, '\0' };
00033 static const char KW_CDATA[] = {
00034 ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' };
00035 static const char KW_DOCTYPE[] = {
00036 ASCII_D, ASCII_O, ASCII_C, ASCII_T, ASCII_Y, ASCII_P, ASCII_E, '\0' };
00037 static const char KW_ELEMENT[] = {
00038 ASCII_E, ASCII_L, ASCII_E, ASCII_M, ASCII_E, ASCII_N, ASCII_T, '\0' };
00039 static const char KW_EMPTY[] = {
00040 ASCII_E, ASCII_M, ASCII_P, ASCII_T, ASCII_Y, '\0' };
00041 static const char KW_ENTITIES[] = {
00042 ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, ASCII_I, ASCII_E, ASCII_S,
00043 '\0' };
00044 static const char KW_ENTITY[] = {
00045 ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, ASCII_Y, '\0' };
00046 static const char KW_FIXED[] = {
00047 ASCII_F, ASCII_I, ASCII_X, ASCII_E, ASCII_D, '\0' };
00048 static const char KW_ID[] = {
00049 ASCII_I, ASCII_D, '\0' };
00050 static const char KW_IDREF[] = {
00051 ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, '\0' };
00052 static const char KW_IDREFS[] = {
00053 ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, ASCII_S, '\0' };
00054 static const char KW_IGNORE[] = {
00055 ASCII_I, ASCII_G, ASCII_N, ASCII_O, ASCII_R, ASCII_E, '\0' };
00056 static const char KW_IMPLIED[] = {
00057 ASCII_I, ASCII_M, ASCII_P, ASCII_L, ASCII_I, ASCII_E, ASCII_D, '\0' };
00058 static const char KW_INCLUDE[] = {
00059 ASCII_I, ASCII_N, ASCII_C, ASCII_L, ASCII_U, ASCII_D, ASCII_E, '\0' };
00060 static const char KW_NDATA[] = {
00061 ASCII_N, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' };
00062 static const char KW_NMTOKEN[] = {
00063 ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, ASCII_E, ASCII_N, '\0' };
00064 static const char KW_NMTOKENS[] = {
00065 ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, ASCII_E, ASCII_N, ASCII_S,
00066 '\0' };
00067 static const char KW_NOTATION[] =
00068 { ASCII_N, ASCII_O, ASCII_T, ASCII_A, ASCII_T, ASCII_I, ASCII_O, ASCII_N,
00069 '\0' };
00070 static const char KW_PCDATA[] = {
00071 ASCII_P, ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' };
00072 static const char KW_PUBLIC[] = {
00073 ASCII_P, ASCII_U, ASCII_B, ASCII_L, ASCII_I, ASCII_C, '\0' };
00074 static const char KW_REQUIRED[] = {
00075 ASCII_R, ASCII_E, ASCII_Q, ASCII_U, ASCII_I, ASCII_R, ASCII_E, ASCII_D,
00076 '\0' };
00077 static const char KW_SYSTEM[] = {
00078 ASCII_S, ASCII_Y, ASCII_S, ASCII_T, ASCII_E, ASCII_M, '\0' };
00079
00080 #ifndef MIN_BYTES_PER_CHAR
00081 #define MIN_BYTES_PER_CHAR(enc) ((enc)->minBytesPerChar)
00082 #endif
00083
00084 #ifdef XML_DTD
00085 #define setTopLevel(state) \
00086 ((state)->handler = ((state)->documentEntity \
00087 ? internalSubset \
00088 : externalSubset1))
00089 #else
00090 #define setTopLevel(state) ((state)->handler = internalSubset)
00091 #endif
00092
00093 typedef int PTRCALL PROLOG_HANDLER(PROLOG_STATE *state,
00094 int tok,
00095 const char *ptr,
00096 const char *end,
00097 const ENCODING *enc);
00098
00099 static PROLOG_HANDLER
00100 prolog0, prolog1, prolog2,
00101 doctype0, doctype1, doctype2, doctype3, doctype4, doctype5,
00102 internalSubset,
00103 entity0, entity1, entity2, entity3, entity4, entity5, entity6,
00104 entity7, entity8, entity9, entity10,
00105 notation0, notation1, notation2, notation3, notation4,
00106 attlist0, attlist1, attlist2, attlist3, attlist4, attlist5, attlist6,
00107 attlist7, attlist8, attlist9,
00108 element0, element1, element2, element3, element4, element5, element6,
00109 element7,
00110 #ifdef XML_DTD
00111 externalSubset0, externalSubset1,
00112 condSect0, condSect1, condSect2,
00113 #endif
00114 declClose,
00115 error;
00116
00117 static int FASTCALL common(PROLOG_STATE *state, int tok);
00118
00119 static int PTRCALL
00120 prolog0(PROLOG_STATE *state,
00121 int tok,
00122 const char *ptr,
00123 const char *end,
00124 const ENCODING *enc)
00125 {
00126 switch (tok) {
00127 case XML_TOK_PROLOG_S:
00128 state->handler = prolog1;
00129 return XML_ROLE_NONE;
00130 case XML_TOK_XML_DECL:
00131 state->handler = prolog1;
00132 return XML_ROLE_XML_DECL;
00133 case XML_TOK_PI:
00134 state->handler = prolog1;
00135 return XML_ROLE_PI;
00136 case XML_TOK_COMMENT:
00137 state->handler = prolog1;
00138 return XML_ROLE_COMMENT;
00139 case XML_TOK_BOM:
00140 return XML_ROLE_NONE;
00141 case XML_TOK_DECL_OPEN:
00142 if (!XmlNameMatchesAscii(enc,
00143 ptr + 2 * MIN_BYTES_PER_CHAR(enc),
00144 end,
00145 KW_DOCTYPE))
00146 break;
00147 state->handler = doctype0;
00148 return XML_ROLE_DOCTYPE_NONE;
00149 case XML_TOK_INSTANCE_START:
00150 state->handler = error;
00151 return XML_ROLE_INSTANCE_START;
00152 }
00153 return common(state, tok);
00154 }
00155
00156 static int PTRCALL
00157 prolog1(PROLOG_STATE *state,
00158 int tok,
00159 const char *ptr,
00160 const char *end,
00161 const ENCODING *enc)
00162 {
00163 switch (tok) {
00164 case XML_TOK_PROLOG_S:
00165 return XML_ROLE_NONE;
00166 case XML_TOK_PI:
00167 return XML_ROLE_PI;
00168 case XML_TOK_COMMENT:
00169 return XML_ROLE_COMMENT;
00170 case XML_TOK_BOM:
00171 return XML_ROLE_NONE;
00172 case XML_TOK_DECL_OPEN:
00173 if (!XmlNameMatchesAscii(enc,
00174 ptr + 2 * MIN_BYTES_PER_CHAR(enc),
00175 end,
00176 KW_DOCTYPE))
00177 break;
00178 state->handler = doctype0;
00179 return XML_ROLE_DOCTYPE_NONE;
00180 case XML_TOK_INSTANCE_START:
00181 state->handler = error;
00182 return XML_ROLE_INSTANCE_START;
00183 }
00184 return common(state, tok);
00185 }
00186
00187 static int PTRCALL
00188 prolog2(PROLOG_STATE *state,
00189 int tok,
00190 const char *ptr,
00191 const char *end,
00192 const ENCODING *enc)
00193 {
00194 switch (tok) {
00195 case XML_TOK_PROLOG_S:
00196 return XML_ROLE_NONE;
00197 case XML_TOK_PI:
00198 return XML_ROLE_PI;
00199 case XML_TOK_COMMENT:
00200 return XML_ROLE_COMMENT;
00201 case XML_TOK_INSTANCE_START:
00202 state->handler = error;
00203 return XML_ROLE_INSTANCE_START;
00204 }
00205 return common(state, tok);
00206 }
00207
00208 static int PTRCALL
00209 doctype0(PROLOG_STATE *state,
00210 int tok,
00211 const char *ptr,
00212 const char *end,
00213 const ENCODING *enc)
00214 {
00215 switch (tok) {
00216 case XML_TOK_PROLOG_S:
00217 return XML_ROLE_DOCTYPE_NONE;
00218 case XML_TOK_NAME:
00219 case XML_TOK_PREFIXED_NAME:
00220 state->handler = doctype1;
00221 return XML_ROLE_DOCTYPE_NAME;
00222 }
00223 return common(state, tok);
00224 }
00225
00226 static int PTRCALL
00227 doctype1(PROLOG_STATE *state,
00228 int tok,
00229 const char *ptr,
00230 const char *end,
00231 const ENCODING *enc)
00232 {
00233 switch (tok) {
00234 case XML_TOK_PROLOG_S:
00235 return XML_ROLE_DOCTYPE_NONE;
00236 case XML_TOK_OPEN_BRACKET:
00237 state->handler = internalSubset;
00238 return XML_ROLE_DOCTYPE_INTERNAL_SUBSET;
00239 case XML_TOK_DECL_CLOSE:
00240 state->handler = prolog2;
00241 return XML_ROLE_DOCTYPE_CLOSE;
00242 case XML_TOK_NAME:
00243 if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) {
00244 state->handler = doctype3;
00245 return XML_ROLE_DOCTYPE_NONE;
00246 }
00247 if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) {
00248 state->handler = doctype2;
00249 return XML_ROLE_DOCTYPE_NONE;
00250 }
00251 break;
00252 }
00253 return common(state, tok);
00254 }
00255
00256 static int PTRCALL
00257 doctype2(PROLOG_STATE *state,
00258 int tok,
00259 const char *ptr,
00260 const char *end,
00261 const ENCODING *enc)
00262 {
00263 switch (tok) {
00264 case XML_TOK_PROLOG_S:
00265 return XML_ROLE_DOCTYPE_NONE;
00266 case XML_TOK_LITERAL:
00267 state->handler = doctype3;
00268 return XML_ROLE_DOCTYPE_PUBLIC_ID;
00269 }
00270 return common(state, tok);
00271 }
00272
00273 static int PTRCALL
00274 doctype3(PROLOG_STATE *state,
00275 int tok,
00276 const char *ptr,
00277 const char *end,
00278 const ENCODING *enc)
00279 {
00280 switch (tok) {
00281 case XML_TOK_PROLOG_S:
00282 return XML_ROLE_DOCTYPE_NONE;
00283 case XML_TOK_LITERAL:
00284 state->handler = doctype4;
00285 return XML_ROLE_DOCTYPE_SYSTEM_ID;
00286 }
00287 return common(state, tok);
00288 }
00289
00290 static int PTRCALL
00291 doctype4(PROLOG_STATE *state,
00292 int tok,
00293 const char *ptr,
00294 const char *end,
00295 const ENCODING *enc)
00296 {
00297 switch (tok) {
00298 case XML_TOK_PROLOG_S:
00299 return XML_ROLE_DOCTYPE_NONE;
00300 case XML_TOK_OPEN_BRACKET:
00301 state->handler = internalSubset;
00302 return XML_ROLE_DOCTYPE_INTERNAL_SUBSET;
00303 case XML_TOK_DECL_CLOSE:
00304 state->handler = prolog2;
00305 return XML_ROLE_DOCTYPE_CLOSE;
00306 }
00307 return common(state, tok);
00308 }
00309
00310 static int PTRCALL
00311 doctype5(PROLOG_STATE *state,
00312 int tok,
00313 const char *ptr,
00314 const char *end,
00315 const ENCODING *enc)
00316 {
00317 switch (tok) {
00318 case XML_TOK_PROLOG_S:
00319 return XML_ROLE_DOCTYPE_NONE;
00320 case XML_TOK_DECL_CLOSE:
00321 state->handler = prolog2;
00322 return XML_ROLE_DOCTYPE_CLOSE;
00323 }
00324 return common(state, tok);
00325 }
00326
00327 static int PTRCALL
00328 internalSubset(PROLOG_STATE *state,
00329 int tok,
00330 const char *ptr,
00331 const char *end,
00332 const ENCODING *enc)
00333 {
00334 switch (tok) {
00335 case XML_TOK_PROLOG_S:
00336 return XML_ROLE_NONE;
00337 case XML_TOK_DECL_OPEN:
00338 if (XmlNameMatchesAscii(enc,
00339 ptr + 2 * MIN_BYTES_PER_CHAR(enc),
00340 end,
00341 KW_ENTITY)) {
00342 state->handler = entity0;
00343 return XML_ROLE_ENTITY_NONE;
00344 }
00345 if (XmlNameMatchesAscii(enc,
00346 ptr + 2 * MIN_BYTES_PER_CHAR(enc),
00347 end,
00348 KW_ATTLIST)) {
00349 state->handler = attlist0;
00350 return XML_ROLE_ATTLIST_NONE;
00351 }
00352 if (XmlNameMatchesAscii(enc,
00353 ptr + 2 * MIN_BYTES_PER_CHAR(enc),
00354 end,
00355 KW_ELEMENT)) {
00356 state->handler = element0;
00357 return XML_ROLE_ELEMENT_NONE;
00358 }
00359 if (XmlNameMatchesAscii(enc,
00360 ptr + 2 * MIN_BYTES_PER_CHAR(enc),
00361 end,
00362 KW_NOTATION)) {
00363 state->handler = notation0;
00364 return XML_ROLE_NOTATION_NONE;
00365 }
00366 break;
00367 case XML_TOK_PI:
00368 return XML_ROLE_PI;
00369 case XML_TOK_COMMENT:
00370 return XML_ROLE_COMMENT;
00371 case XML_TOK_PARAM_ENTITY_REF:
00372 return XML_ROLE_PARAM_ENTITY_REF;
00373 case XML_TOK_CLOSE_BRACKET:
00374 state->handler = doctype5;
00375 return XML_ROLE_DOCTYPE_NONE;
00376 case XML_TOK_NONE:
00377 return XML_ROLE_NONE;
00378 }
00379 return common(state, tok);
00380 }
00381
00382 #ifdef XML_DTD
00383
00384 static int PTRCALL
00385 externalSubset0(PROLOG_STATE *state,
00386 int tok,
00387 const char *ptr,
00388 const char *end,
00389 const ENCODING *enc)
00390 {
00391 state->handler = externalSubset1;
00392 if (tok == XML_TOK_XML_DECL)
00393 return XML_ROLE_TEXT_DECL;
00394 return externalSubset1(state, tok, ptr, end, enc);
00395 }
00396
00397 static int PTRCALL
00398 externalSubset1(PROLOG_STATE *state,
00399 int tok,
00400 const char *ptr,
00401 const char *end,
00402 const ENCODING *enc)
00403 {
00404 switch (tok) {
00405 case XML_TOK_COND_SECT_OPEN:
00406 state->handler = condSect0;
00407 return XML_ROLE_NONE;
00408 case XML_TOK_COND_SECT_CLOSE:
00409 if (state->includeLevel == 0)
00410 break;
00411 state->includeLevel -= 1;
00412 return XML_ROLE_NONE;
00413 case XML_TOK_PROLOG_S:
00414 return XML_ROLE_NONE;
00415 case XML_TOK_CLOSE_BRACKET:
00416 break;
00417 case XML_TOK_NONE:
00418 if (state->includeLevel)
00419 break;
00420 return XML_ROLE_NONE;
00421 default:
00422 return internalSubset(state, tok, ptr, end, enc);
00423 }
00424 return common(state, tok);
00425 }
00426
00427 #endif
00428
00429 static int PTRCALL
00430 entity0(PROLOG_STATE *state,
00431 int tok,
00432 const char *ptr,
00433 const char *end,
00434 const ENCODING *enc)
00435 {
00436 switch (tok) {
00437 case XML_TOK_PROLOG_S:
00438 return XML_ROLE_ENTITY_NONE;
00439 case XML_TOK_PERCENT:
00440 state->handler = entity1;
00441 return XML_ROLE_ENTITY_NONE;
00442 case XML_TOK_NAME:
00443 state->handler = entity2;
00444 return XML_ROLE_GENERAL_ENTITY_NAME;
00445 }
00446 return common(state, tok);
00447 }
00448
00449 static int PTRCALL
00450 entity1(PROLOG_STATE *state,
00451 int tok,
00452 const char *ptr,
00453 const char *end,
00454 const ENCODING *enc)
00455 {
00456 switch (tok) {
00457 case XML_TOK_PROLOG_S:
00458 return XML_ROLE_ENTITY_NONE;
00459 case XML_TOK_NAME:
00460 state->handler = entity7;
00461 return XML_ROLE_PARAM_ENTITY_NAME;
00462 }
00463 return common(state, tok);
00464 }
00465
00466 static int PTRCALL
00467 entity2(PROLOG_STATE *state,
00468 int tok,
00469 const char *ptr,
00470 const char *end,
00471 const ENCODING *enc)
00472 {
00473 switch (tok) {
00474 case XML_TOK_PROLOG_S:
00475 return XML_ROLE_ENTITY_NONE;
00476 case XML_TOK_NAME:
00477 if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) {
00478 state->handler = entity4;
00479 return XML_ROLE_ENTITY_NONE;
00480 }
00481 if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) {
00482 state->handler = entity3;
00483 return XML_ROLE_ENTITY_NONE;
00484 }
00485 break;
00486 case XML_TOK_LITERAL:
00487 state->handler = declClose;
00488 state->role_none = XML_ROLE_ENTITY_NONE;
00489 return XML_ROLE_ENTITY_VALUE;
00490 }
00491 return common(state, tok);
00492 }
00493
00494 static int PTRCALL
00495 entity3(PROLOG_STATE *state,
00496 int tok,
00497 const char *ptr,
00498 const char *end,
00499 const ENCODING *enc)
00500 {
00501 switch (tok) {
00502 case XML_TOK_PROLOG_S:
00503 return XML_ROLE_ENTITY_NONE;
00504 case XML_TOK_LITERAL:
00505 state->handler = entity4;
00506 return XML_ROLE_ENTITY_PUBLIC_ID;
00507 }
00508 return common(state, tok);
00509 }
00510
00511 static int PTRCALL
00512 entity4(PROLOG_STATE *state,
00513 int tok,
00514 const char *ptr,
00515 const char *end,
00516 const ENCODING *enc)
00517 {
00518 switch (tok) {
00519 case XML_TOK_PROLOG_S:
00520 return XML_ROLE_ENTITY_NONE;
00521 case XML_TOK_LITERAL:
00522 state->handler = entity5;
00523 return XML_ROLE_ENTITY_SYSTEM_ID;
00524 }
00525 return common(state, tok);
00526 }
00527
00528 static int PTRCALL
00529 entity5(PROLOG_STATE *state,
00530 int tok,
00531 const char *ptr,
00532 const char *end,
00533 const ENCODING *enc)
00534 {
00535 switch (tok) {
00536 case XML_TOK_PROLOG_S:
00537 return XML_ROLE_ENTITY_NONE;
00538 case XML_TOK_DECL_CLOSE:
00539 setTopLevel(state);
00540 return XML_ROLE_ENTITY_COMPLETE;
00541 case XML_TOK_NAME:
00542 if (XmlNameMatchesAscii(enc, ptr, end, KW_NDATA)) {
00543 state->handler = entity6;
00544 return XML_ROLE_ENTITY_NONE;
00545 }
00546 break;
00547 }
00548 return common(state, tok);
00549 }
00550
00551 static int PTRCALL
00552 entity6(PROLOG_STATE *state,
00553 int tok,
00554 const char *ptr,
00555 const char *end,
00556 const ENCODING *enc)
00557 {
00558 switch (tok) {
00559 case XML_TOK_PROLOG_S:
00560 return XML_ROLE_ENTITY_NONE;
00561 case XML_TOK_NAME:
00562 state->handler = declClose;
00563 state->role_none = XML_ROLE_ENTITY_NONE;
00564 return XML_ROLE_ENTITY_NOTATION_NAME;
00565 }
00566 return common(state, tok);
00567 }
00568
00569 static int PTRCALL
00570 entity7(PROLOG_STATE *state,
00571 int tok,
00572 const char *ptr,
00573 const char *end,
00574 const ENCODING *enc)
00575 {
00576 switch (tok) {
00577 case XML_TOK_PROLOG_S:
00578 return XML_ROLE_ENTITY_NONE;
00579 case XML_TOK_NAME:
00580 if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) {
00581 state->handler = entity9;
00582 return XML_ROLE_ENTITY_NONE;
00583 }
00584 if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) {
00585 state->handler = entity8;
00586 return XML_ROLE_ENTITY_NONE;
00587 }
00588 break;
00589 case XML_TOK_LITERAL:
00590 state->handler = declClose;
00591 state->role_none = XML_ROLE_ENTITY_NONE;
00592 return XML_ROLE_ENTITY_VALUE;
00593 }
00594 return common(state, tok);
00595 }
00596
00597 static int PTRCALL
00598 entity8(PROLOG_STATE *state,
00599 int tok,
00600 const char *ptr,
00601 const char *end,
00602 const ENCODING *enc)
00603 {
00604 switch (tok) {
00605 case XML_TOK_PROLOG_S:
00606 return XML_ROLE_ENTITY_NONE;
00607 case XML_TOK_LITERAL:
00608 state->handler = entity9;
00609 return XML_ROLE_ENTITY_PUBLIC_ID;
00610 }
00611 return common(state, tok);
00612 }
00613
00614 static int PTRCALL
00615 entity9(PROLOG_STATE *state,
00616 int tok,
00617 const char *ptr,
00618 const char *end,
00619 const ENCODING *enc)
00620 {
00621 switch (tok) {
00622 case XML_TOK_PROLOG_S:
00623 return XML_ROLE_ENTITY_NONE;
00624 case XML_TOK_LITERAL:
00625 state->handler = entity10;
00626 return XML_ROLE_ENTITY_SYSTEM_ID;
00627 }
00628 return common(state, tok);
00629 }
00630
00631 static int PTRCALL
00632 entity10(PROLOG_STATE *state,
00633 int tok,
00634 const char *ptr,
00635 const char *end,
00636 const ENCODING *enc)
00637 {
00638 switch (tok) {
00639 case XML_TOK_PROLOG_S:
00640 return XML_ROLE_ENTITY_NONE;
00641 case XML_TOK_DECL_CLOSE:
00642 setTopLevel(state);
00643 return XML_ROLE_ENTITY_COMPLETE;
00644 }
00645 return common(state, tok);
00646 }
00647
00648 static int PTRCALL
00649 notation0(PROLOG_STATE *state,
00650 int tok,
00651 const char *ptr,
00652 const char *end,
00653 const ENCODING *enc)
00654 {
00655 switch (tok) {
00656 case XML_TOK_PROLOG_S:
00657 return XML_ROLE_NOTATION_NONE;
00658 case XML_TOK_NAME:
00659 state->handler = notation1;
00660 return XML_ROLE_NOTATION_NAME;
00661 }
00662 return common(state, tok);
00663 }
00664
00665 static int PTRCALL
00666 notation1(PROLOG_STATE *state,
00667 int tok,
00668 const char *ptr,
00669 const char *end,
00670 const ENCODING *enc)
00671 {
00672 switch (tok) {
00673 case XML_TOK_PROLOG_S:
00674 return XML_ROLE_NOTATION_NONE;
00675 case XML_TOK_NAME:
00676 if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) {
00677 state->handler = notation3;
00678 return XML_ROLE_NOTATION_NONE;
00679 }
00680 if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) {
00681 state->handler = notation2;
00682 return XML_ROLE_NOTATION_NONE;
00683 }
00684 break;
00685 }
00686 return common(state, tok);
00687 }
00688
00689 static int PTRCALL
00690 notation2(PROLOG_STATE *state,
00691 int tok,
00692 const char *ptr,
00693 const char *end,
00694 const ENCODING *enc)
00695 {
00696 switch (tok) {
00697 case XML_TOK_PROLOG_S:
00698 return XML_ROLE_NOTATION_NONE;
00699 case XML_TOK_LITERAL:
00700 state->handler = notation4;
00701 return XML_ROLE_NOTATION_PUBLIC_ID;
00702 }
00703 return common(state, tok);
00704 }
00705
00706 static int PTRCALL
00707 notation3(PROLOG_STATE *state,
00708 int tok,
00709 const char *ptr,
00710 const char *end,
00711 const ENCODING *enc)
00712 {
00713 switch (tok) {
00714 case XML_TOK_PROLOG_S:
00715 return XML_ROLE_NOTATION_NONE;
00716 case XML_TOK_LITERAL:
00717 state->handler = declClose;
00718 state->role_none = XML_ROLE_NOTATION_NONE;
00719 return XML_ROLE_NOTATION_SYSTEM_ID;
00720 }
00721 return common(state, tok);
00722 }
00723
00724 static int PTRCALL
00725 notation4(PROLOG_STATE *state,
00726 int tok,
00727 const char *ptr,
00728 const char *end,
00729 const ENCODING *enc)
00730 {
00731 switch (tok) {
00732 case XML_TOK_PROLOG_S:
00733 return XML_ROLE_NOTATION_NONE;
00734 case XML_TOK_LITERAL:
00735 state->handler = declClose;
00736 state->role_none = XML_ROLE_NOTATION_NONE;
00737 return XML_ROLE_NOTATION_SYSTEM_ID;
00738 case XML_TOK_DECL_CLOSE:
00739 setTopLevel(state);
00740 return XML_ROLE_NOTATION_NO_SYSTEM_ID;
00741 }
00742 return common(state, tok);
00743 }
00744
00745 static int PTRCALL
00746 attlist0(PROLOG_STATE *state,
00747 int tok,
00748 const char *ptr,
00749 const char *end,
00750 const ENCODING *enc)
00751 {
00752 switch (tok) {
00753 case XML_TOK_PROLOG_S:
00754 return XML_ROLE_ATTLIST_NONE;
00755 case XML_TOK_NAME:
00756 case XML_TOK_PREFIXED_NAME:
00757 state->handler = attlist1;
00758 return XML_ROLE_ATTLIST_ELEMENT_NAME;
00759 }
00760 return common(state, tok);
00761 }
00762
00763 static int PTRCALL
00764 attlist1(PROLOG_STATE *state,
00765 int tok,
00766 const char *ptr,
00767 const char *end,
00768 const ENCODING *enc)
00769 {
00770 switch (tok) {
00771 case XML_TOK_PROLOG_S:
00772 return XML_ROLE_ATTLIST_NONE;
00773 case XML_TOK_DECL_CLOSE:
00774 setTopLevel(state);
00775 return XML_ROLE_ATTLIST_NONE;
00776 case XML_TOK_NAME:
00777 case XML_TOK_PREFIXED_NAME:
00778 state->handler = attlist2;
00779 return XML_ROLE_ATTRIBUTE_NAME;
00780 }
00781 return common(state, tok);
00782 }
00783
00784 static int PTRCALL
00785 attlist2(PROLOG_STATE *state,
00786 int tok,
00787 const char *ptr,
00788 const char *end,
00789 const ENCODING *enc)
00790 {
00791 switch (tok) {
00792 case XML_TOK_PROLOG_S:
00793 return XML_ROLE_ATTLIST_NONE;
00794 case XML_TOK_NAME:
00795 {
00796 static const char *types[] = {
00797 KW_CDATA,
00798 KW_ID,
00799 KW_IDREF,
00800 KW_IDREFS,
00801 KW_ENTITY,
00802 KW_ENTITIES,
00803 KW_NMTOKEN,
00804 KW_NMTOKENS,
00805 };
00806 int i;
00807 for (i = 0; i < (int)(sizeof(types)/sizeof(types[0])); i++)
00808 if (XmlNameMatchesAscii(enc, ptr, end, types[i])) {
00809 state->handler = attlist8;
00810 return XML_ROLE_ATTRIBUTE_TYPE_CDATA + i;
00811 }
00812 }
00813 if (XmlNameMatchesAscii(enc, ptr, end, KW_NOTATION)) {
00814 state->handler = attlist5;
00815 return XML_ROLE_ATTLIST_NONE;
00816 }
00817 break;
00818 case XML_TOK_OPEN_PAREN:
00819 state->handler = attlist3;
00820 return XML_ROLE_ATTLIST_NONE;
00821 }
00822 return common(state, tok);
00823 }
00824
00825 static int PTRCALL
00826 attlist3(PROLOG_STATE *state,
00827 int tok,
00828 const char *ptr,
00829 const char *end,
00830 const ENCODING *enc)
00831 {
00832 switch (tok) {
00833 case XML_TOK_PROLOG_S:
00834 return XML_ROLE_ATTLIST_NONE;
00835 case XML_TOK_NMTOKEN:
00836 case XML_TOK_NAME:
00837 case XML_TOK_PREFIXED_NAME:
00838 state->handler = attlist4;
00839 return XML_ROLE_ATTRIBUTE_ENUM_VALUE;
00840 }
00841 return common(state, tok);
00842 }
00843
00844 static int PTRCALL
00845 attlist4(PROLOG_STATE *state,
00846 int tok,
00847 const char *ptr,
00848 const char *end,
00849 const ENCODING *enc)
00850 {
00851 switch (tok) {
00852 case XML_TOK_PROLOG_S:
00853 return XML_ROLE_ATTLIST_NONE;
00854 case XML_TOK_CLOSE_PAREN:
00855 state->handler = attlist8;
00856 return XML_ROLE_ATTLIST_NONE;
00857 case XML_TOK_OR:
00858 state->handler = attlist3;
00859 return XML_ROLE_ATTLIST_NONE;
00860 }
00861 return common(state, tok);
00862 }
00863
00864 static int PTRCALL
00865 attlist5(PROLOG_STATE *state,
00866 int tok,
00867 const char *ptr,
00868 const char *end,
00869 const ENCODING *enc)
00870 {
00871 switch (tok) {
00872 case XML_TOK_PROLOG_S:
00873 return XML_ROLE_ATTLIST_NONE;
00874 case XML_TOK_OPEN_PAREN:
00875 state->handler = attlist6;
00876 return XML_ROLE_ATTLIST_NONE;
00877 }
00878 return common(state, tok);
00879 }
00880
00881 static int PTRCALL
00882 attlist6(PROLOG_STATE *state,
00883 int tok,
00884 const char *ptr,
00885 const char *end,
00886 const ENCODING *enc)
00887 {
00888 switch (tok) {
00889 case XML_TOK_PROLOG_S:
00890 return XML_ROLE_ATTLIST_NONE;
00891 case XML_TOK_NAME:
00892 state->handler = attlist7;
00893 return XML_ROLE_ATTRIBUTE_NOTATION_VALUE;
00894 }
00895 return common(state, tok);
00896 }
00897
00898 static int PTRCALL
00899 attlist7(PROLOG_STATE *state,
00900 int tok,
00901 const char *ptr,
00902 const char *end,
00903 const ENCODING *enc)
00904 {
00905 switch (tok) {
00906 case XML_TOK_PROLOG_S:
00907 return XML_ROLE_ATTLIST_NONE;
00908 case XML_TOK_CLOSE_PAREN:
00909 state->handler = attlist8;
00910 return XML_ROLE_ATTLIST_NONE;
00911 case XML_TOK_OR:
00912 state->handler = attlist6;
00913 return XML_ROLE_ATTLIST_NONE;
00914 }
00915 return common(state, tok);
00916 }
00917
00918
00919 static int PTRCALL
00920 attlist8(PROLOG_STATE *state,
00921 int tok,
00922 const char *ptr,
00923 const char *end,
00924 const ENCODING *enc)
00925 {
00926 switch (tok) {
00927 case XML_TOK_PROLOG_S:
00928 return XML_ROLE_ATTLIST_NONE;
00929 case XML_TOK_POUND_NAME:
00930 if (XmlNameMatchesAscii(enc,
00931 ptr + MIN_BYTES_PER_CHAR(enc),
00932 end,
00933 KW_IMPLIED)) {
00934 state->handler = attlist1;
00935 return XML_ROLE_IMPLIED_ATTRIBUTE_VALUE;
00936 }
00937 if (XmlNameMatchesAscii(enc,
00938 ptr + MIN_BYTES_PER_CHAR(enc),
00939 end,
00940 KW_REQUIRED)) {
00941 state->handler = attlist1;
00942 return XML_ROLE_REQUIRED_ATTRIBUTE_VALUE;
00943 }
00944 if (XmlNameMatchesAscii(enc,
00945 ptr + MIN_BYTES_PER_CHAR(enc),
00946 end,
00947 KW_FIXED)) {
00948 state->handler = attlist9;
00949 return XML_ROLE_ATTLIST_NONE;
00950 }
00951 break;
00952 case XML_TOK_LITERAL:
00953 state->handler = attlist1;
00954 return XML_ROLE_DEFAULT_ATTRIBUTE_VALUE;
00955 }
00956 return common(state, tok);
00957 }
00958
00959 static int PTRCALL
00960 attlist9(PROLOG_STATE *state,
00961 int tok,
00962 const char *ptr,
00963 const char *end,
00964 const ENCODING *enc)
00965 {
00966 switch (tok) {
00967 case XML_TOK_PROLOG_S:
00968 return XML_ROLE_ATTLIST_NONE;
00969 case XML_TOK_LITERAL:
00970 state->handler = attlist1;
00971 return XML_ROLE_FIXED_ATTRIBUTE_VALUE;
00972 }
00973 return common(state, tok);
00974 }
00975
00976 static int PTRCALL
00977 element0(PROLOG_STATE *state,
00978 int tok,
00979 const char *ptr,
00980 const char *end,
00981 const ENCODING *enc)
00982 {
00983 switch (tok) {
00984 case XML_TOK_PROLOG_S:
00985 return XML_ROLE_ELEMENT_NONE;
00986 case XML_TOK_NAME:
00987 case XML_TOK_PREFIXED_NAME:
00988 state->handler = element1;
00989 return XML_ROLE_ELEMENT_NAME;
00990 }
00991 return common(state, tok);
00992 }
00993
00994 static int PTRCALL
00995 element1(PROLOG_STATE *state,
00996 int tok,
00997 const char *ptr,
00998 const char *end,
00999 const ENCODING *enc)
01000 {
01001 switch (tok) {
01002 case XML_TOK_PROLOG_S:
01003 return XML_ROLE_ELEMENT_NONE;
01004 case XML_TOK_NAME:
01005 if (XmlNameMatchesAscii(enc, ptr, end, KW_EMPTY)) {
01006 state->handler = declClose;
01007 state->role_none = XML_ROLE_ELEMENT_NONE;
01008 return XML_ROLE_CONTENT_EMPTY;
01009 }
01010 if (XmlNameMatchesAscii(enc, ptr, end, KW_ANY)) {
01011 state->handler = declClose;
01012 state->role_none = XML_ROLE_ELEMENT_NONE;
01013 return XML_ROLE_CONTENT_ANY;
01014 }
01015 break;
01016 case XML_TOK_OPEN_PAREN:
01017 state->handler = element2;
01018 state->level = 1;
01019 return XML_ROLE_GROUP_OPEN;
01020 }
01021 return common(state, tok);
01022 }
01023
01024 static int PTRCALL
01025 element2(PROLOG_STATE *state,
01026 int tok,
01027 const char *ptr,
01028 const char *end,
01029 const ENCODING *enc)
01030 {
01031 switch (tok) {
01032 case XML_TOK_PROLOG_S:
01033 return XML_ROLE_ELEMENT_NONE;
01034 case XML_TOK_POUND_NAME:
01035 if (XmlNameMatchesAscii(enc,
01036 ptr + MIN_BYTES_PER_CHAR(enc),
01037 end,
01038 KW_PCDATA)) {
01039 state->handler = element3;
01040 return XML_ROLE_CONTENT_PCDATA;
01041 }
01042 break;
01043 case XML_TOK_OPEN_PAREN:
01044 state->level = 2;
01045 state->handler = element6;
01046 return XML_ROLE_GROUP_OPEN;
01047 case XML_TOK_NAME:
01048 case XML_TOK_PREFIXED_NAME:
01049 state->handler = element7;
01050 return XML_ROLE_CONTENT_ELEMENT;
01051 case XML_TOK_NAME_QUESTION:
01052 state->handler = element7;
01053 return XML_ROLE_CONTENT_ELEMENT_OPT;
01054 case XML_TOK_NAME_ASTERISK:
01055 state->handler = element7;
01056 return XML_ROLE_CONTENT_ELEMENT_REP;
01057 case XML_TOK_NAME_PLUS:
01058 state->handler = element7;
01059 return XML_ROLE_CONTENT_ELEMENT_PLUS;
01060 }
01061 return common(state, tok);
01062 }
01063
01064 static int PTRCALL
01065 element3(PROLOG_STATE *state,
01066 int tok,
01067 const char *ptr,
01068 const char *end,
01069 const ENCODING *enc)
01070 {
01071 switch (tok) {
01072 case XML_TOK_PROLOG_S:
01073 return XML_ROLE_ELEMENT_NONE;
01074 case XML_TOK_CLOSE_PAREN:
01075 state->handler = declClose;
01076 state->role_none = XML_ROLE_ELEMENT_NONE;
01077 return XML_ROLE_GROUP_CLOSE;
01078 case XML_TOK_CLOSE_PAREN_ASTERISK:
01079 state->handler = declClose;
01080 state->role_none = XML_ROLE_ELEMENT_NONE;
01081 return XML_ROLE_GROUP_CLOSE_REP;
01082 case XML_TOK_OR:
01083 state->handler = element4;
01084 return XML_ROLE_ELEMENT_NONE;
01085 }
01086 return common(state, tok);
01087 }
01088
01089 static int PTRCALL
01090 element4(PROLOG_STATE *state,
01091 int tok,
01092 const char *ptr,
01093 const char *end,
01094 const ENCODING *enc)
01095 {
01096 switch (tok) {
01097 case XML_TOK_PROLOG_S:
01098 return XML_ROLE_ELEMENT_NONE;
01099 case XML_TOK_NAME:
01100 case XML_TOK_PREFIXED_NAME:
01101 state->handler = element5;
01102 return XML_ROLE_CONTENT_ELEMENT;
01103 }
01104 return common(state, tok);
01105 }
01106
01107 static int PTRCALL
01108 element5(