xmlrole.c 33 KB

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