Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1265 lines
28 KiB

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