xmlrole.c 33 KB

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