xmlrole.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358
  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. /* This case can never arise. To reach this role function, the
  160. * parse must have passed through prolog0 and therefore have had
  161. * some form of input, even if only a space. At that point, a
  162. * byte order mark is no longer a valid character (though
  163. * technically it should be interpreted as a non-breaking space),
  164. * so will be rejected by the tokenizing stages.
  165. */
  166. return XML_ROLE_NONE; /* LCOV_EXCL_LINE */
  167. case XML_TOK_DECL_OPEN:
  168. if (!XmlNameMatchesAscii(enc,
  169. ptr + 2 * MIN_BYTES_PER_CHAR(enc),
  170. end,
  171. KW_DOCTYPE))
  172. break;
  173. state->handler = doctype0;
  174. return XML_ROLE_DOCTYPE_NONE;
  175. case XML_TOK_INSTANCE_START:
  176. state->handler = error;
  177. return XML_ROLE_INSTANCE_START;
  178. }
  179. return common(state, tok);
  180. }
  181. static int PTRCALL
  182. prolog2(PROLOG_STATE *state,
  183. int tok,
  184. const char *UNUSED_P(ptr),
  185. const char *UNUSED_P(end),
  186. const ENCODING *UNUSED_P(enc))
  187. {
  188. switch (tok) {
  189. case XML_TOK_PROLOG_S:
  190. return XML_ROLE_NONE;
  191. case XML_TOK_PI:
  192. return XML_ROLE_PI;
  193. case XML_TOK_COMMENT:
  194. return XML_ROLE_COMMENT;
  195. case XML_TOK_INSTANCE_START:
  196. state->handler = error;
  197. return XML_ROLE_INSTANCE_START;
  198. }
  199. return common(state, tok);
  200. }
  201. static int PTRCALL
  202. doctype0(PROLOG_STATE *state,
  203. int tok,
  204. const char *UNUSED_P(ptr),
  205. const char *UNUSED_P(end),
  206. const ENCODING *UNUSED_P(enc))
  207. {
  208. switch (tok) {
  209. case XML_TOK_PROLOG_S:
  210. return XML_ROLE_DOCTYPE_NONE;
  211. case XML_TOK_NAME:
  212. case XML_TOK_PREFIXED_NAME:
  213. state->handler = doctype1;
  214. return XML_ROLE_DOCTYPE_NAME;
  215. }
  216. return common(state, tok);
  217. }
  218. static int PTRCALL
  219. doctype1(PROLOG_STATE *state,
  220. int tok,
  221. const char *ptr,
  222. const char *end,
  223. const ENCODING *enc)
  224. {
  225. switch (tok) {
  226. case XML_TOK_PROLOG_S:
  227. return XML_ROLE_DOCTYPE_NONE;
  228. case XML_TOK_OPEN_BRACKET:
  229. state->handler = internalSubset;
  230. return XML_ROLE_DOCTYPE_INTERNAL_SUBSET;
  231. case XML_TOK_DECL_CLOSE:
  232. state->handler = prolog2;
  233. return XML_ROLE_DOCTYPE_CLOSE;
  234. case XML_TOK_NAME:
  235. if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) {
  236. state->handler = doctype3;
  237. return XML_ROLE_DOCTYPE_NONE;
  238. }
  239. if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) {
  240. state->handler = doctype2;
  241. return XML_ROLE_DOCTYPE_NONE;
  242. }
  243. break;
  244. }
  245. return common(state, tok);
  246. }
  247. static int PTRCALL
  248. doctype2(PROLOG_STATE *state,
  249. int tok,
  250. const char *UNUSED_P(ptr),
  251. const char *UNUSED_P(end),
  252. const ENCODING *UNUSED_P(enc))
  253. {
  254. switch (tok) {
  255. case XML_TOK_PROLOG_S:
  256. return XML_ROLE_DOCTYPE_NONE;
  257. case XML_TOK_LITERAL:
  258. state->handler = doctype3;
  259. return XML_ROLE_DOCTYPE_PUBLIC_ID;
  260. }
  261. return common(state, tok);
  262. }
  263. static int PTRCALL
  264. doctype3(PROLOG_STATE *state,
  265. int tok,
  266. const char *UNUSED_P(ptr),
  267. const char *UNUSED_P(end),
  268. const ENCODING *UNUSED_P(enc))
  269. {
  270. switch (tok) {
  271. case XML_TOK_PROLOG_S:
  272. return XML_ROLE_DOCTYPE_NONE;
  273. case XML_TOK_LITERAL:
  274. state->handler = doctype4;
  275. return XML_ROLE_DOCTYPE_SYSTEM_ID;
  276. }
  277. return common(state, tok);
  278. }
  279. static int PTRCALL
  280. doctype4(PROLOG_STATE *state,
  281. int tok,
  282. const char *UNUSED_P(ptr),
  283. const char *UNUSED_P(end),
  284. const ENCODING *UNUSED_P(enc))
  285. {
  286. switch (tok) {
  287. case XML_TOK_PROLOG_S:
  288. return XML_ROLE_DOCTYPE_NONE;
  289. case XML_TOK_OPEN_BRACKET:
  290. state->handler = internalSubset;
  291. return XML_ROLE_DOCTYPE_INTERNAL_SUBSET;
  292. case XML_TOK_DECL_CLOSE:
  293. state->handler = prolog2;
  294. return XML_ROLE_DOCTYPE_CLOSE;
  295. }
  296. return common(state, tok);
  297. }
  298. static int PTRCALL
  299. doctype5(PROLOG_STATE *state,
  300. int tok,
  301. const char *UNUSED_P(ptr),
  302. const char *UNUSED_P(end),
  303. const ENCODING *UNUSED_P(enc))
  304. {
  305. switch (tok) {
  306. case XML_TOK_PROLOG_S:
  307. return XML_ROLE_DOCTYPE_NONE;
  308. case XML_TOK_DECL_CLOSE:
  309. state->handler = prolog2;
  310. return XML_ROLE_DOCTYPE_CLOSE;
  311. }
  312. return common(state, tok);
  313. }
  314. static int PTRCALL
  315. internalSubset(PROLOG_STATE *state,
  316. int tok,
  317. const char *ptr,
  318. const char *end,
  319. const ENCODING *enc)
  320. {
  321. switch (tok) {
  322. case XML_TOK_PROLOG_S:
  323. return XML_ROLE_NONE;
  324. case XML_TOK_DECL_OPEN:
  325. if (XmlNameMatchesAscii(enc,
  326. ptr + 2 * MIN_BYTES_PER_CHAR(enc),
  327. end,
  328. KW_ENTITY)) {
  329. state->handler = entity0;
  330. return XML_ROLE_ENTITY_NONE;
  331. }
  332. if (XmlNameMatchesAscii(enc,
  333. ptr + 2 * MIN_BYTES_PER_CHAR(enc),
  334. end,
  335. KW_ATTLIST)) {
  336. state->handler = attlist0;
  337. return XML_ROLE_ATTLIST_NONE;
  338. }
  339. if (XmlNameMatchesAscii(enc,
  340. ptr + 2 * MIN_BYTES_PER_CHAR(enc),
  341. end,
  342. KW_ELEMENT)) {
  343. state->handler = element0;
  344. return XML_ROLE_ELEMENT_NONE;
  345. }
  346. if (XmlNameMatchesAscii(enc,
  347. ptr + 2 * MIN_BYTES_PER_CHAR(enc),
  348. end,
  349. KW_NOTATION)) {
  350. state->handler = notation0;
  351. return XML_ROLE_NOTATION_NONE;
  352. }
  353. break;
  354. case XML_TOK_PI:
  355. return XML_ROLE_PI;
  356. case XML_TOK_COMMENT:
  357. return XML_ROLE_COMMENT;
  358. case XML_TOK_PARAM_ENTITY_REF:
  359. return XML_ROLE_PARAM_ENTITY_REF;
  360. case XML_TOK_CLOSE_BRACKET:
  361. state->handler = doctype5;
  362. return XML_ROLE_DOCTYPE_NONE;
  363. case XML_TOK_NONE:
  364. return XML_ROLE_NONE;
  365. }
  366. return common(state, tok);
  367. }
  368. #ifdef XML_DTD
  369. static int PTRCALL
  370. externalSubset0(PROLOG_STATE *state,
  371. int tok,
  372. const char *ptr,
  373. const char *end,
  374. const ENCODING *enc)
  375. {
  376. state->handler = externalSubset1;
  377. if (tok == XML_TOK_XML_DECL)
  378. return XML_ROLE_TEXT_DECL;
  379. return externalSubset1(state, tok, ptr, end, enc);
  380. }
  381. static int PTRCALL
  382. externalSubset1(PROLOG_STATE *state,
  383. int tok,
  384. const char *ptr,
  385. const char *end,
  386. const ENCODING *enc)
  387. {
  388. switch (tok) {
  389. case XML_TOK_COND_SECT_OPEN:
  390. state->handler = condSect0;
  391. return XML_ROLE_NONE;
  392. case XML_TOK_COND_SECT_CLOSE:
  393. if (state->includeLevel == 0)
  394. break;
  395. state->includeLevel -= 1;
  396. return XML_ROLE_NONE;
  397. case XML_TOK_PROLOG_S:
  398. return XML_ROLE_NONE;
  399. case XML_TOK_CLOSE_BRACKET:
  400. break;
  401. case XML_TOK_NONE:
  402. if (state->includeLevel)
  403. break;
  404. return XML_ROLE_NONE;
  405. default:
  406. return internalSubset(state, tok, ptr, end, enc);
  407. }
  408. return common(state, tok);
  409. }
  410. #endif /* XML_DTD */
  411. static int PTRCALL
  412. entity0(PROLOG_STATE *state,
  413. int tok,
  414. const char *UNUSED_P(ptr),
  415. const char *UNUSED_P(end),
  416. const ENCODING *UNUSED_P(enc))
  417. {
  418. switch (tok) {
  419. case XML_TOK_PROLOG_S:
  420. return XML_ROLE_ENTITY_NONE;
  421. case XML_TOK_PERCENT:
  422. state->handler = entity1;
  423. return XML_ROLE_ENTITY_NONE;
  424. case XML_TOK_NAME:
  425. state->handler = entity2;
  426. return XML_ROLE_GENERAL_ENTITY_NAME;
  427. }
  428. return common(state, tok);
  429. }
  430. static int PTRCALL
  431. entity1(PROLOG_STATE *state,
  432. int tok,
  433. const char *UNUSED_P(ptr),
  434. const char *UNUSED_P(end),
  435. const ENCODING *UNUSED_P(enc))
  436. {
  437. switch (tok) {
  438. case XML_TOK_PROLOG_S:
  439. return XML_ROLE_ENTITY_NONE;
  440. case XML_TOK_NAME:
  441. state->handler = entity7;
  442. return XML_ROLE_PARAM_ENTITY_NAME;
  443. }
  444. return common(state, tok);
  445. }
  446. static int PTRCALL
  447. entity2(PROLOG_STATE *state,
  448. int tok,
  449. const char *ptr,
  450. const char *end,
  451. const ENCODING *enc)
  452. {
  453. switch (tok) {
  454. case XML_TOK_PROLOG_S:
  455. return XML_ROLE_ENTITY_NONE;
  456. case XML_TOK_NAME:
  457. if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) {
  458. state->handler = entity4;
  459. return XML_ROLE_ENTITY_NONE;
  460. }
  461. if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) {
  462. state->handler = entity3;
  463. return XML_ROLE_ENTITY_NONE;
  464. }
  465. break;
  466. case XML_TOK_LITERAL:
  467. state->handler = declClose;
  468. state->role_none = XML_ROLE_ENTITY_NONE;
  469. return XML_ROLE_ENTITY_VALUE;
  470. }
  471. return common(state, tok);
  472. }
  473. static int PTRCALL
  474. entity3(PROLOG_STATE *state,
  475. int tok,
  476. const char *UNUSED_P(ptr),
  477. const char *UNUSED_P(end),
  478. const ENCODING *UNUSED_P(enc))
  479. {
  480. switch (tok) {
  481. case XML_TOK_PROLOG_S:
  482. return XML_ROLE_ENTITY_NONE;
  483. case XML_TOK_LITERAL:
  484. state->handler = entity4;
  485. return XML_ROLE_ENTITY_PUBLIC_ID;
  486. }
  487. return common(state, tok);
  488. }
  489. static int PTRCALL
  490. entity4(PROLOG_STATE *state,
  491. int tok,
  492. const char *UNUSED_P(ptr),
  493. const char *UNUSED_P(end),
  494. const ENCODING *UNUSED_P(enc))
  495. {
  496. switch (tok) {
  497. case XML_TOK_PROLOG_S:
  498. return XML_ROLE_ENTITY_NONE;
  499. case XML_TOK_LITERAL:
  500. state->handler = entity5;
  501. return XML_ROLE_ENTITY_SYSTEM_ID;
  502. }
  503. return common(state, tok);
  504. }
  505. static int PTRCALL
  506. entity5(PROLOG_STATE *state,
  507. int tok,
  508. const char *ptr,
  509. const char *end,
  510. const ENCODING *enc)
  511. {
  512. switch (tok) {
  513. case XML_TOK_PROLOG_S:
  514. return XML_ROLE_ENTITY_NONE;
  515. case XML_TOK_DECL_CLOSE:
  516. setTopLevel(state);
  517. return XML_ROLE_ENTITY_COMPLETE;
  518. case XML_TOK_NAME:
  519. if (XmlNameMatchesAscii(enc, ptr, end, KW_NDATA)) {
  520. state->handler = entity6;
  521. return XML_ROLE_ENTITY_NONE;
  522. }
  523. break;
  524. }
  525. return common(state, tok);
  526. }
  527. static int PTRCALL
  528. entity6(PROLOG_STATE *state,
  529. int tok,
  530. const char *UNUSED_P(ptr),
  531. const char *UNUSED_P(end),
  532. const ENCODING *UNUSED_P(enc))
  533. {
  534. switch (tok) {
  535. case XML_TOK_PROLOG_S:
  536. return XML_ROLE_ENTITY_NONE;
  537. case XML_TOK_NAME:
  538. state->handler = declClose;
  539. state->role_none = XML_ROLE_ENTITY_NONE;
  540. return XML_ROLE_ENTITY_NOTATION_NAME;
  541. }
  542. return common(state, tok);
  543. }
  544. static int PTRCALL
  545. entity7(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_ENTITY_NONE;
  554. case XML_TOK_NAME:
  555. if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) {
  556. state->handler = entity9;
  557. return XML_ROLE_ENTITY_NONE;
  558. }
  559. if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) {
  560. state->handler = entity8;
  561. return XML_ROLE_ENTITY_NONE;
  562. }
  563. break;
  564. case XML_TOK_LITERAL:
  565. state->handler = declClose;
  566. state->role_none = XML_ROLE_ENTITY_NONE;
  567. return XML_ROLE_ENTITY_VALUE;
  568. }
  569. return common(state, tok);
  570. }
  571. static int PTRCALL
  572. entity8(PROLOG_STATE *state,
  573. int tok,
  574. const char *UNUSED_P(ptr),
  575. const char *UNUSED_P(end),
  576. const ENCODING *UNUSED_P(enc))
  577. {
  578. switch (tok) {
  579. case XML_TOK_PROLOG_S:
  580. return XML_ROLE_ENTITY_NONE;
  581. case XML_TOK_LITERAL:
  582. state->handler = entity9;
  583. return XML_ROLE_ENTITY_PUBLIC_ID;
  584. }
  585. return common(state, tok);
  586. }
  587. static int PTRCALL
  588. entity9(PROLOG_STATE *state,
  589. int tok,
  590. const char *UNUSED_P(ptr),
  591. const char *UNUSED_P(end),
  592. const ENCODING *UNUSED_P(enc))
  593. {
  594. switch (tok) {
  595. case XML_TOK_PROLOG_S:
  596. return XML_ROLE_ENTITY_NONE;
  597. case XML_TOK_LITERAL:
  598. state->handler = entity10;
  599. return XML_ROLE_ENTITY_SYSTEM_ID;
  600. }
  601. return common(state, tok);
  602. }
  603. static int PTRCALL
  604. entity10(PROLOG_STATE *state,
  605. int tok,
  606. const char *UNUSED_P(ptr),
  607. const char *UNUSED_P(end),
  608. const ENCODING *UNUSED_P(enc))
  609. {
  610. switch (tok) {
  611. case XML_TOK_PROLOG_S:
  612. return XML_ROLE_ENTITY_NONE;
  613. case XML_TOK_DECL_CLOSE:
  614. setTopLevel(state);
  615. return XML_ROLE_ENTITY_COMPLETE;
  616. }
  617. return common(state, tok);
  618. }
  619. static int PTRCALL
  620. notation0(PROLOG_STATE *state,
  621. int tok,
  622. const char *UNUSED_P(ptr),
  623. const char *UNUSED_P(end),
  624. const ENCODING *UNUSED_P(enc))
  625. {
  626. switch (tok) {
  627. case XML_TOK_PROLOG_S:
  628. return XML_ROLE_NOTATION_NONE;
  629. case XML_TOK_NAME:
  630. state->handler = notation1;
  631. return XML_ROLE_NOTATION_NAME;
  632. }
  633. return common(state, tok);
  634. }
  635. static int PTRCALL
  636. notation1(PROLOG_STATE *state,
  637. int tok,
  638. const char *ptr,
  639. const char *end,
  640. const ENCODING *enc)
  641. {
  642. switch (tok) {
  643. case XML_TOK_PROLOG_S:
  644. return XML_ROLE_NOTATION_NONE;
  645. case XML_TOK_NAME:
  646. if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) {
  647. state->handler = notation3;
  648. return XML_ROLE_NOTATION_NONE;
  649. }
  650. if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) {
  651. state->handler = notation2;
  652. return XML_ROLE_NOTATION_NONE;
  653. }
  654. break;
  655. }
  656. return common(state, tok);
  657. }
  658. static int PTRCALL
  659. notation2(PROLOG_STATE *state,
  660. int tok,
  661. const char *UNUSED_P(ptr),
  662. const char *UNUSED_P(end),
  663. const ENCODING *UNUSED_P(enc))
  664. {
  665. switch (tok) {
  666. case XML_TOK_PROLOG_S:
  667. return XML_ROLE_NOTATION_NONE;
  668. case XML_TOK_LITERAL:
  669. state->handler = notation4;
  670. return XML_ROLE_NOTATION_PUBLIC_ID;
  671. }
  672. return common(state, tok);
  673. }
  674. static int PTRCALL
  675. notation3(PROLOG_STATE *state,
  676. int tok,
  677. const char *UNUSED_P(ptr),
  678. const char *UNUSED_P(end),
  679. const ENCODING *UNUSED_P(enc))
  680. {
  681. switch (tok) {
  682. case XML_TOK_PROLOG_S:
  683. return XML_ROLE_NOTATION_NONE;
  684. case XML_TOK_LITERAL:
  685. state->handler = declClose;
  686. state->role_none = XML_ROLE_NOTATION_NONE;
  687. return XML_ROLE_NOTATION_SYSTEM_ID;
  688. }
  689. return common(state, tok);
  690. }
  691. static int PTRCALL
  692. notation4(PROLOG_STATE *state,
  693. int tok,
  694. const char *UNUSED_P(ptr),
  695. const char *UNUSED_P(end),
  696. const ENCODING *UNUSED_P(enc))
  697. {
  698. switch (tok) {
  699. case XML_TOK_PROLOG_S:
  700. return XML_ROLE_NOTATION_NONE;
  701. case XML_TOK_LITERAL:
  702. state->handler = declClose;
  703. state->role_none = XML_ROLE_NOTATION_NONE;
  704. return XML_ROLE_NOTATION_SYSTEM_ID;
  705. case XML_TOK_DECL_CLOSE:
  706. setTopLevel(state);
  707. return XML_ROLE_NOTATION_NO_SYSTEM_ID;
  708. }
  709. return common(state, tok);
  710. }
  711. static int PTRCALL
  712. attlist0(PROLOG_STATE *state,
  713. int tok,
  714. const char *UNUSED_P(ptr),
  715. const char *UNUSED_P(end),
  716. const ENCODING *UNUSED_P(enc))
  717. {
  718. switch (tok) {
  719. case XML_TOK_PROLOG_S:
  720. return XML_ROLE_ATTLIST_NONE;
  721. case XML_TOK_NAME:
  722. case XML_TOK_PREFIXED_NAME:
  723. state->handler = attlist1;
  724. return XML_ROLE_ATTLIST_ELEMENT_NAME;
  725. }
  726. return common(state, tok);
  727. }
  728. static int PTRCALL
  729. attlist1(PROLOG_STATE *state,
  730. int tok,
  731. const char *UNUSED_P(ptr),
  732. const char *UNUSED_P(end),
  733. const ENCODING *UNUSED_P(enc))
  734. {
  735. switch (tok) {
  736. case XML_TOK_PROLOG_S:
  737. return XML_ROLE_ATTLIST_NONE;
  738. case XML_TOK_DECL_CLOSE:
  739. setTopLevel(state);
  740. return XML_ROLE_ATTLIST_NONE;
  741. case XML_TOK_NAME:
  742. case XML_TOK_PREFIXED_NAME:
  743. state->handler = attlist2;
  744. return XML_ROLE_ATTRIBUTE_NAME;
  745. }
  746. return common(state, tok);
  747. }
  748. static int PTRCALL
  749. attlist2(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_ATTLIST_NONE;
  758. case XML_TOK_NAME:
  759. {
  760. static const char * const types[] = {
  761. KW_CDATA,
  762. KW_ID,
  763. KW_IDREF,
  764. KW_IDREFS,
  765. KW_ENTITY,
  766. KW_ENTITIES,
  767. KW_NMTOKEN,
  768. KW_NMTOKENS,
  769. };
  770. int i;
  771. for (i = 0; i < (int)(sizeof(types)/sizeof(types[0])); i++)
  772. if (XmlNameMatchesAscii(enc, ptr, end, types[i])) {
  773. state->handler = attlist8;
  774. return XML_ROLE_ATTRIBUTE_TYPE_CDATA + i;
  775. }
  776. }
  777. if (XmlNameMatchesAscii(enc, ptr, end, KW_NOTATION)) {
  778. state->handler = attlist5;
  779. return XML_ROLE_ATTLIST_NONE;
  780. }
  781. break;
  782. case XML_TOK_OPEN_PAREN:
  783. state->handler = attlist3;
  784. return XML_ROLE_ATTLIST_NONE;
  785. }
  786. return common(state, tok);
  787. }
  788. static int PTRCALL
  789. attlist3(PROLOG_STATE *state,
  790. int tok,
  791. const char *UNUSED_P(ptr),
  792. const char *UNUSED_P(end),
  793. const ENCODING *UNUSED_P(enc))
  794. {
  795. switch (tok) {
  796. case XML_TOK_PROLOG_S:
  797. return XML_ROLE_ATTLIST_NONE;
  798. case XML_TOK_NMTOKEN:
  799. case XML_TOK_NAME:
  800. case XML_TOK_PREFIXED_NAME:
  801. state->handler = attlist4;
  802. return XML_ROLE_ATTRIBUTE_ENUM_VALUE;
  803. }
  804. return common(state, tok);
  805. }
  806. static int PTRCALL
  807. attlist4(PROLOG_STATE *state,
  808. int tok,
  809. const char *UNUSED_P(ptr),
  810. const char *UNUSED_P(end),
  811. const ENCODING *UNUSED_P(enc))
  812. {
  813. switch (tok) {
  814. case XML_TOK_PROLOG_S:
  815. return XML_ROLE_ATTLIST_NONE;
  816. case XML_TOK_CLOSE_PAREN:
  817. state->handler = attlist8;
  818. return XML_ROLE_ATTLIST_NONE;
  819. case XML_TOK_OR:
  820. state->handler = attlist3;
  821. return XML_ROLE_ATTLIST_NONE;
  822. }
  823. return common(state, tok);
  824. }
  825. static int PTRCALL
  826. attlist5(PROLOG_STATE *state,
  827. int tok,
  828. const char *UNUSED_P(ptr),
  829. const char *UNUSED_P(end),
  830. const ENCODING *UNUSED_P(enc))
  831. {
  832. switch (tok) {
  833. case XML_TOK_PROLOG_S:
  834. return XML_ROLE_ATTLIST_NONE;
  835. case XML_TOK_OPEN_PAREN:
  836. state->handler = attlist6;
  837. return XML_ROLE_ATTLIST_NONE;
  838. }
  839. return common(state, tok);
  840. }
  841. static int PTRCALL
  842. attlist6(PROLOG_STATE *state,
  843. int tok,
  844. const char *UNUSED_P(ptr),
  845. const char *UNUSED_P(end),
  846. const ENCODING *UNUSED_P(enc))
  847. {
  848. switch (tok) {
  849. case XML_TOK_PROLOG_S:
  850. return XML_ROLE_ATTLIST_NONE;
  851. case XML_TOK_NAME:
  852. state->handler = attlist7;
  853. return XML_ROLE_ATTRIBUTE_NOTATION_VALUE;
  854. }
  855. return common(state, tok);
  856. }
  857. static int PTRCALL
  858. attlist7(PROLOG_STATE *state,
  859. int tok,
  860. const char *UNUSED_P(ptr),
  861. const char *UNUSED_P(end),
  862. const ENCODING *UNUSED_P(enc))
  863. {
  864. switch (tok) {
  865. case XML_TOK_PROLOG_S:
  866. return XML_ROLE_ATTLIST_NONE;
  867. case XML_TOK_CLOSE_PAREN:
  868. state->handler = attlist8;
  869. return XML_ROLE_ATTLIST_NONE;
  870. case XML_TOK_OR:
  871. state->handler = attlist6;
  872. return XML_ROLE_ATTLIST_NONE;
  873. }
  874. return common(state, tok);
  875. }
  876. /* default value */
  877. static int PTRCALL
  878. attlist8(PROLOG_STATE *state,
  879. int tok,
  880. const char *ptr,
  881. const char *end,
  882. const ENCODING *enc)
  883. {
  884. switch (tok) {
  885. case XML_TOK_PROLOG_S:
  886. return XML_ROLE_ATTLIST_NONE;
  887. case XML_TOK_POUND_NAME:
  888. if (XmlNameMatchesAscii(enc,
  889. ptr + MIN_BYTES_PER_CHAR(enc),
  890. end,
  891. KW_IMPLIED)) {
  892. state->handler = attlist1;
  893. return XML_ROLE_IMPLIED_ATTRIBUTE_VALUE;
  894. }
  895. if (XmlNameMatchesAscii(enc,
  896. ptr + MIN_BYTES_PER_CHAR(enc),
  897. end,
  898. KW_REQUIRED)) {
  899. state->handler = attlist1;
  900. return XML_ROLE_REQUIRED_ATTRIBUTE_VALUE;
  901. }
  902. if (XmlNameMatchesAscii(enc,
  903. ptr + MIN_BYTES_PER_CHAR(enc),
  904. end,
  905. KW_FIXED)) {
  906. state->handler = attlist9;
  907. return XML_ROLE_ATTLIST_NONE;
  908. }
  909. break;
  910. case XML_TOK_LITERAL:
  911. state->handler = attlist1;
  912. return XML_ROLE_DEFAULT_ATTRIBUTE_VALUE;
  913. }
  914. return common(state, tok);
  915. }
  916. static int PTRCALL
  917. attlist9(PROLOG_STATE *state,
  918. int tok,
  919. const char *UNUSED_P(ptr),
  920. const char *UNUSED_P(end),
  921. const ENCODING *UNUSED_P(enc))
  922. {
  923. switch (tok) {
  924. case XML_TOK_PROLOG_S:
  925. return XML_ROLE_ATTLIST_NONE;
  926. case XML_TOK_LITERAL:
  927. state->handler = attlist1;
  928. return XML_ROLE_FIXED_ATTRIBUTE_VALUE;
  929. }
  930. return common(state, tok);
  931. }
  932. static int PTRCALL
  933. element0(PROLOG_STATE *state,
  934. int tok,
  935. const char *UNUSED_P(ptr),
  936. const char *UNUSED_P(end),
  937. const ENCODING *UNUSED_P(enc))
  938. {
  939. switch (tok) {
  940. case XML_TOK_PROLOG_S:
  941. return XML_ROLE_ELEMENT_NONE;
  942. case XML_TOK_NAME:
  943. case XML_TOK_PREFIXED_NAME:
  944. state->handler = element1;
  945. return XML_ROLE_ELEMENT_NAME;
  946. }
  947. return common(state, tok);
  948. }
  949. static int PTRCALL
  950. element1(PROLOG_STATE *state,
  951. int tok,
  952. const char *ptr,
  953. const char *end,
  954. const ENCODING *enc)
  955. {
  956. switch (tok) {
  957. case XML_TOK_PROLOG_S:
  958. return XML_ROLE_ELEMENT_NONE;
  959. case XML_TOK_NAME:
  960. if (XmlNameMatchesAscii(enc, ptr, end, KW_EMPTY)) {
  961. state->handler = declClose;
  962. state->role_none = XML_ROLE_ELEMENT_NONE;
  963. return XML_ROLE_CONTENT_EMPTY;
  964. }
  965. if (XmlNameMatchesAscii(enc, ptr, end, KW_ANY)) {
  966. state->handler = declClose;
  967. state->role_none = XML_ROLE_ELEMENT_NONE;
  968. return XML_ROLE_CONTENT_ANY;
  969. }
  970. break;
  971. case XML_TOK_OPEN_PAREN:
  972. state->handler = element2;
  973. state->level = 1;
  974. return XML_ROLE_GROUP_OPEN;
  975. }
  976. return common(state, tok);
  977. }
  978. static int PTRCALL
  979. element2(PROLOG_STATE *state,
  980. int tok,
  981. const char *ptr,
  982. const char *end,
  983. const ENCODING *enc)
  984. {
  985. switch (tok) {
  986. case XML_TOK_PROLOG_S:
  987. return XML_ROLE_ELEMENT_NONE;
  988. case XML_TOK_POUND_NAME:
  989. if (XmlNameMatchesAscii(enc,
  990. ptr + MIN_BYTES_PER_CHAR(enc),
  991. end,
  992. KW_PCDATA)) {
  993. state->handler = element3;
  994. return XML_ROLE_CONTENT_PCDATA;
  995. }
  996. break;
  997. case XML_TOK_OPEN_PAREN:
  998. state->level = 2;
  999. state->handler = element6;
  1000. return XML_ROLE_GROUP_OPEN;
  1001. case XML_TOK_NAME:
  1002. case XML_TOK_PREFIXED_NAME:
  1003. state->handler = element7;
  1004. return XML_ROLE_CONTENT_ELEMENT;
  1005. case XML_TOK_NAME_QUESTION:
  1006. state->handler = element7;
  1007. return XML_ROLE_CONTENT_ELEMENT_OPT;
  1008. case XML_TOK_NAME_ASTERISK:
  1009. state->handler = element7;
  1010. return XML_ROLE_CONTENT_ELEMENT_REP;
  1011. case XML_TOK_NAME_PLUS:
  1012. state->handler = element7;
  1013. return XML_ROLE_CONTENT_ELEMENT_PLUS;
  1014. }
  1015. return common(state, tok);
  1016. }
  1017. static int PTRCALL
  1018. element3(PROLOG_STATE *state,
  1019. int tok,
  1020. const char *UNUSED_P(ptr),
  1021. const char *UNUSED_P(end),
  1022. const ENCODING *UNUSED_P(enc))
  1023. {
  1024. switch (tok) {
  1025. case XML_TOK_PROLOG_S:
  1026. return XML_ROLE_ELEMENT_NONE;
  1027. case XML_TOK_CLOSE_PAREN:
  1028. state->handler = declClose;
  1029. state->role_none = XML_ROLE_ELEMENT_NONE;
  1030. return XML_ROLE_GROUP_CLOSE;
  1031. case XML_TOK_CLOSE_PAREN_ASTERISK:
  1032. state->handler = declClose;
  1033. state->role_none = XML_ROLE_ELEMENT_NONE;
  1034. return XML_ROLE_GROUP_CLOSE_REP;
  1035. case XML_TOK_OR:
  1036. state->handler = element4;
  1037. return XML_ROLE_ELEMENT_NONE;
  1038. }
  1039. return common(state, tok);
  1040. }
  1041. static int PTRCALL
  1042. element4(PROLOG_STATE *state,
  1043. int tok,
  1044. const char *UNUSED_P(ptr),
  1045. const char *UNUSED_P(end),
  1046. const ENCODING *UNUSED_P(enc))
  1047. {
  1048. switch (tok) {
  1049. case XML_TOK_PROLOG_S:
  1050. return XML_ROLE_ELEMENT_NONE;
  1051. case XML_TOK_NAME:
  1052. case XML_TOK_PREFIXED_NAME:
  1053. state->handler = element5;
  1054. return XML_ROLE_CONTENT_ELEMENT;
  1055. }
  1056. return common(state, tok);
  1057. }
  1058. static int PTRCALL
  1059. element5(PROLOG_STATE *state,
  1060. int tok,
  1061. const char *UNUSED_P(ptr),
  1062. const char *UNUSED_P(end),
  1063. const ENCODING *UNUSED_P(enc))
  1064. {
  1065. switch (tok) {
  1066. case XML_TOK_PROLOG_S:
  1067. return XML_ROLE_ELEMENT_NONE;
  1068. case XML_TOK_CLOSE_PAREN_ASTERISK:
  1069. state->handler = declClose;
  1070. state->role_none = XML_ROLE_ELEMENT_NONE;
  1071. return XML_ROLE_GROUP_CLOSE_REP;
  1072. case XML_TOK_OR:
  1073. state->handler = element4;
  1074. return XML_ROLE_ELEMENT_NONE;
  1075. }
  1076. return common(state, tok);
  1077. }
  1078. static int PTRCALL
  1079. element6(PROLOG_STATE *state,
  1080. int tok,
  1081. const char *UNUSED_P(ptr),
  1082. const char *UNUSED_P(end),
  1083. const ENCODING *UNUSED_P(enc))
  1084. {
  1085. switch (tok) {
  1086. case XML_TOK_PROLOG_S:
  1087. return XML_ROLE_ELEMENT_NONE;
  1088. case XML_TOK_OPEN_PAREN:
  1089. state->level += 1;
  1090. return XML_ROLE_GROUP_OPEN;
  1091. case XML_TOK_NAME:
  1092. case XML_TOK_PREFIXED_NAME:
  1093. state->handler = element7;
  1094. return XML_ROLE_CONTENT_ELEMENT;
  1095. case XML_TOK_NAME_QUESTION:
  1096. state->handler = element7;
  1097. return XML_ROLE_CONTENT_ELEMENT_OPT;
  1098. case XML_TOK_NAME_ASTERISK:
  1099. state->handler = element7;
  1100. return XML_ROLE_CONTENT_ELEMENT_REP;
  1101. case XML_TOK_NAME_PLUS:
  1102. state->handler = element7;
  1103. return XML_ROLE_CONTENT_ELEMENT_PLUS;
  1104. }
  1105. return common(state, tok);
  1106. }
  1107. static int PTRCALL
  1108. element7(PROLOG_STATE *state,
  1109. int tok,
  1110. const char *UNUSED_P(ptr),
  1111. const char *UNUSED_P(end),
  1112. const ENCODING *UNUSED_P(enc))
  1113. {
  1114. switch (tok) {
  1115. case XML_TOK_PROLOG_S:
  1116. return XML_ROLE_ELEMENT_NONE;
  1117. case XML_TOK_CLOSE_PAREN:
  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;
  1124. case XML_TOK_CLOSE_PAREN_ASTERISK:
  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_REP;
  1131. case XML_TOK_CLOSE_PAREN_QUESTION:
  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_OPT;
  1138. case XML_TOK_CLOSE_PAREN_PLUS:
  1139. state->level -= 1;
  1140. if (state->level == 0) {
  1141. state->handler = declClose;
  1142. state->role_none = XML_ROLE_ELEMENT_NONE;
  1143. }
  1144. return XML_ROLE_GROUP_CLOSE_PLUS;
  1145. case XML_TOK_COMMA:
  1146. state->handler = element6;
  1147. return XML_ROLE_GROUP_SEQUENCE;
  1148. case XML_TOK_OR:
  1149. state->handler = element6;
  1150. return XML_ROLE_GROUP_CHOICE;
  1151. }
  1152. return common(state, tok);
  1153. }
  1154. #ifdef XML_DTD
  1155. static int PTRCALL
  1156. condSect0(PROLOG_STATE *state,
  1157. int tok,
  1158. const char *ptr,
  1159. const char *end,
  1160. const ENCODING *enc)
  1161. {
  1162. switch (tok) {
  1163. case XML_TOK_PROLOG_S:
  1164. return XML_ROLE_NONE;
  1165. case XML_TOK_NAME:
  1166. if (XmlNameMatchesAscii(enc, ptr, end, KW_INCLUDE)) {
  1167. state->handler = condSect1;
  1168. return XML_ROLE_NONE;
  1169. }
  1170. if (XmlNameMatchesAscii(enc, ptr, end, KW_IGNORE)) {
  1171. state->handler = condSect2;
  1172. return XML_ROLE_NONE;
  1173. }
  1174. break;
  1175. }
  1176. return common(state, tok);
  1177. }
  1178. static int PTRCALL
  1179. condSect1(PROLOG_STATE *state,
  1180. int tok,
  1181. const char *UNUSED_P(ptr),
  1182. const char *UNUSED_P(end),
  1183. const ENCODING *UNUSED_P(enc))
  1184. {
  1185. switch (tok) {
  1186. case XML_TOK_PROLOG_S:
  1187. return XML_ROLE_NONE;
  1188. case XML_TOK_OPEN_BRACKET:
  1189. state->handler = externalSubset1;
  1190. state->includeLevel += 1;
  1191. return XML_ROLE_NONE;
  1192. }
  1193. return common(state, tok);
  1194. }
  1195. static int PTRCALL
  1196. condSect2(PROLOG_STATE *state,
  1197. int tok,
  1198. const char *UNUSED_P(ptr),
  1199. const char *UNUSED_P(end),
  1200. const ENCODING *UNUSED_P(enc))
  1201. {
  1202. switch (tok) {
  1203. case XML_TOK_PROLOG_S:
  1204. return XML_ROLE_NONE;
  1205. case XML_TOK_OPEN_BRACKET:
  1206. state->handler = externalSubset1;
  1207. return XML_ROLE_IGNORE_SECT;
  1208. }
  1209. return common(state, tok);
  1210. }
  1211. #endif /* XML_DTD */
  1212. static int PTRCALL
  1213. declClose(PROLOG_STATE *state,
  1214. int tok,
  1215. const char *UNUSED_P(ptr),
  1216. const char *UNUSED_P(end),
  1217. const ENCODING *UNUSED_P(enc))
  1218. {
  1219. switch (tok) {
  1220. case XML_TOK_PROLOG_S:
  1221. return state->role_none;
  1222. case XML_TOK_DECL_CLOSE:
  1223. setTopLevel(state);
  1224. return state->role_none;
  1225. }
  1226. return common(state, tok);
  1227. }
  1228. /* This function will only be invoked if the internal logic of the
  1229. * parser has broken down. It is used in two cases:
  1230. *
  1231. * 1: When the XML prolog has been finished. At this point the
  1232. * processor (the parser level above these role handlers) should
  1233. * switch from prologProcessor to contentProcessor and reinitialise
  1234. * the handler function.
  1235. *
  1236. * 2: When an error has been detected (via common() below). At this
  1237. * point again the processor should be switched to errorProcessor,
  1238. * which will never call a handler.
  1239. *
  1240. * The result of this is that error() can only be called if the
  1241. * processor switch failed to happen, which is an internal error and
  1242. * therefore we shouldn't be able to provoke it simply by using the
  1243. * library. It is a necessary backstop, however, so we merely exclude
  1244. * it from the coverage statistics.
  1245. *
  1246. * LCOV_EXCL_START
  1247. */
  1248. static int PTRCALL
  1249. error(PROLOG_STATE *UNUSED_P(state),
  1250. int UNUSED_P(tok),
  1251. const char *UNUSED_P(ptr),
  1252. const char *UNUSED_P(end),
  1253. const ENCODING *UNUSED_P(enc))
  1254. {
  1255. return XML_ROLE_NONE;
  1256. }
  1257. /* LCOV_EXCL_STOP */
  1258. static int FASTCALL
  1259. common(PROLOG_STATE *state, int tok)
  1260. {
  1261. #ifdef XML_DTD
  1262. if (!state->documentEntity && tok == XML_TOK_PARAM_ENTITY_REF)
  1263. return XML_ROLE_INNER_PARAM_ENTITY_REF;
  1264. #endif
  1265. state->handler = error;
  1266. return XML_ROLE_ERROR;
  1267. }
  1268. void
  1269. XmlPrologStateInit(PROLOG_STATE *state)
  1270. {
  1271. state->handler = prolog0;
  1272. #ifdef XML_DTD
  1273. state->documentEntity = 1;
  1274. state->includeLevel = 0;
  1275. state->inEntityValue = 0;
  1276. #endif /* XML_DTD */
  1277. }
  1278. #ifdef XML_DTD
  1279. void
  1280. XmlPrologStateInitExternalEntity(PROLOG_STATE *state)
  1281. {
  1282. state->handler = externalSubset0;
  1283. state->documentEntity = 0;
  1284. state->includeLevel = 0;
  1285. }
  1286. #endif /* XML_DTD */