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