PageRenderTime 31ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/amaya/fetchXMLname.c

https://github.com/pffy/Amaya-Editor
C | 809 lines | 598 code | 68 blank | 143 comment | 314 complexity | 7c08c4f75e708ff313b9837f9c392667 MD5 | raw file
  1. /*
  2. *
  3. * (c) COPYRIGHT INRIA and W3C, 1996-2008
  4. * Please first read the full copyright statement in file COPYRIGHT.
  5. *
  6. */
  7. /*
  8. *
  9. * fetchXMLname
  10. *
  11. * Authors: I. Vatton
  12. * L. Carcone
  13. *
  14. */
  15. #define THOT_EXPORT extern
  16. #include "amaya.h"
  17. #include "parser.h"
  18. #include "HTMLnames.h"
  19. #include "MathMLnames.h"
  20. #include "SVGnames.h"
  21. #include "XLinknames.h"
  22. #include "Templatename.h"
  23. /* define some pointers to let other parser functions access the local table */
  24. int HTML_ENTRIES = (sizeof(XHTMLElemMappingTable) / sizeof(ElemMapping));
  25. ElemMapping *pHTMLGIMapping = XHTMLElemMappingTable;
  26. AttributeMapping *pHTMLAttributeMapping = XHTMLAttributeMappingTable;
  27. XmlEntity *pXhtmlEntityTable = XhtmlEntityTable;
  28. XmlEntity *pMathEntityTable = MathEntityTable;
  29. #include "fetchXMLname_f.h"
  30. #ifdef TEMPLATES
  31. #include "templates.h"
  32. #include "templates_f.h"
  33. #endif /* TEMPLATES */
  34. /* Global variables used by the entity mapping */
  35. static int XHTMLSup = 0;
  36. static int MathSup = 0;
  37. /*----------------------------------------------------------------------
  38. GetXHTMLSSchema returns the XHTML Thot schema for document doc.
  39. ----------------------------------------------------------------------*/
  40. SSchema GetXHTMLSSchema (Document doc)
  41. {
  42. SSchema XHTMLSSchema;
  43. XHTMLSSchema = TtaGetSSchema ("HTML", doc);
  44. if (XHTMLSSchema == NULL)
  45. XHTMLSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc), NULL,
  46. "HTML", "HTMLP");
  47. return (XHTMLSSchema);
  48. }
  49. /*----------------------------------------------------------------------
  50. GetMathMLSSchema returns the MathML Thot schema for document doc.
  51. ----------------------------------------------------------------------*/
  52. SSchema GetMathMLSSchema (Document doc)
  53. {
  54. SSchema MathMLSSchema;
  55. MathMLSSchema = TtaGetSSchema ("MathML", doc);
  56. if (MathMLSSchema == NULL)
  57. MathMLSSchema = TtaNewNature(doc,
  58. TtaGetDocumentSSchema(doc), NULL,
  59. "MathML", "MathMLP");
  60. return (MathMLSSchema);
  61. }
  62. /*----------------------------------------------------------------------
  63. GetSVGSSchema returns the SVG Thot schema for document doc.
  64. ----------------------------------------------------------------------*/
  65. SSchema GetSVGSSchema (Document doc)
  66. {
  67. SSchema SVGSSchema;
  68. SVGSSchema = TtaGetSSchema ("SVG", doc);
  69. if (SVGSSchema == NULL)
  70. SVGSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc), NULL,
  71. "SVG", "SVGP");
  72. return (SVGSSchema);
  73. }
  74. /*----------------------------------------------------------------------
  75. GetXLinkSSchema returns the XLink Thot schema for document doc.
  76. ----------------------------------------------------------------------*/
  77. SSchema GetXLinkSSchema (Document doc)
  78. {
  79. SSchema XLinkSSchema;
  80. XLinkSSchema = TtaGetSSchema ("XLink", doc);
  81. if (XLinkSSchema == NULL)
  82. XLinkSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc), NULL,
  83. "XLink", "XLinkP");
  84. return (XLinkSSchema);
  85. }
  86. /* --------------------------------------------------------------------
  87. GetTemplateSSchema returns the Template Thot schema for document doc.
  88. --------------------------------------------------------------------*/
  89. SSchema GetTemplateSSchema (Document doc)
  90. {
  91. SSchema TemplateSSchema = NULL;
  92. #ifdef TEMPLATES
  93. TemplateSSchema = TtaGetSSchema ("Template", doc);
  94. if (TemplateSSchema == NULL)
  95. {
  96. if (IsTemplateInstanceDocument(doc))
  97. TemplateSSchema = TtaNewNature (doc, TtaGetDocumentSSchema(doc), NULL,
  98. "Template", "TemplatePI");
  99. else
  100. TemplateSSchema = TtaNewNature (doc, TtaGetDocumentSSchema(doc), NULL,
  101. "Template", "TemplateP");
  102. }
  103. #endif /* TEMPLATES */
  104. return (TemplateSSchema);
  105. }
  106. /*----------------------------------------------------------------------
  107. GetTextSSchema returns the TextFile Thot schema for document doc.
  108. (this is not XML, but its useful to have this function here).
  109. ----------------------------------------------------------------------*/
  110. SSchema GetTextSSchema (Document doc)
  111. {
  112. SSchema XLinkSSchema;
  113. XLinkSSchema = TtaGetSSchema ("TextFile", doc);
  114. if (XLinkSSchema == NULL)
  115. XLinkSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc), NULL,
  116. "TextFile", "TextFileP");
  117. return (XLinkSSchema);
  118. }
  119. /*----------------------------------------------------------------------
  120. GetGenericXMLSSchema
  121. Returns the XML Thot schema of name schemaName for the document doc.
  122. ----------------------------------------------------------------------*/
  123. SSchema GetGenericXMLSSchema (const char *schemaName, Document doc)
  124. {
  125. SSchema XMLSSchema;
  126. XMLSSchema = TtaGetSSchema (schemaName, doc);
  127. if (XMLSSchema == NULL)
  128. XMLSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc), NULL,
  129. "XML", "XMLP");
  130. return (XMLSSchema);
  131. }
  132. /*----------------------------------------------------------------------
  133. GetGenericXMLSSchemaByUri
  134. Returns the XML Thot schema for the document doc.
  135. ----------------------------------------------------------------------*/
  136. SSchema GetGenericXMLSSchemaByUri (const char *uriName, Document doc, ThotBool *isnew)
  137. {
  138. SSchema XMLSSchema;
  139. if (uriName == NULL)
  140. XMLSSchema = TtaGetSSchemaByUri ("Default_Uri", doc);
  141. else
  142. XMLSSchema = TtaGetSSchemaByUri (uriName, doc);
  143. if (XMLSSchema == NULL)
  144. {
  145. XMLSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc), uriName,
  146. "XML", "XMLP");
  147. *isnew = TRUE;
  148. }
  149. return (XMLSSchema);
  150. }
  151. /*----------------------------------------------------------------------
  152. GetXMLSSchema returns the XML Thot schema for document doc.
  153. ----------------------------------------------------------------------*/
  154. SSchema GetXMLSSchema (int XMLtype, Document doc)
  155. {
  156. if (XMLtype == XHTML_TYPE)
  157. return GetXHTMLSSchema (doc);
  158. else if (XMLtype == MATH_TYPE)
  159. return GetMathMLSSchema (doc);
  160. else if (XMLtype == SVG_TYPE)
  161. return GetSVGSSchema (doc);
  162. else if (XMLtype == XLINK_TYPE)
  163. return GetXLinkSSchema (doc);
  164. else if (XMLtype == Template_TYPE)
  165. return GetTemplateSSchema (doc);
  166. else
  167. return NULL;
  168. }
  169. /*--------------------------------------------------------------------------
  170. HasNatures
  171. Check if there are MathML and/or SVG natures
  172. --------------------------------------------------------------------------*/
  173. void HasNatures (Document document, ThotBool *useMathML, ThotBool *useSVG)
  174. {
  175. SSchema nature;
  176. char *ptr;
  177. /* look for a MathML or SVG nature within the document */
  178. nature = NULL;
  179. *useMathML = FALSE;
  180. *useSVG = FALSE;
  181. if (DocumentMeta[document] && DocumentMeta[document]->compound)
  182. do
  183. {
  184. TtaNextNature (document, &nature);
  185. if (nature)
  186. {
  187. ptr = TtaGetSSchemaName (nature);
  188. if (!strcmp (ptr, "MathML"))
  189. *useMathML = TRUE;
  190. if (!strcmp (ptr, "SVG"))
  191. *useSVG = TRUE;
  192. }
  193. }
  194. while (nature);
  195. }
  196. /*----------------------------------------------------------------------
  197. MapXMLElementType
  198. Generic function which searchs in the Element Mapping table, selected
  199. by the parameter XMLtype, the entry XMLname and returns the corresponding
  200. Thot element type.
  201. If SSchema is specified (not NULL)in elType, only it is searched.
  202. Returns:
  203. - ElTypeNum and ElSSchema into elType ElTypeNum = 0 if not found.
  204. - content information about this entry
  205. - checkProfile TRUE if the entry is valid for the current Doc profile.
  206. ----------------------------------------------------------------------*/
  207. void MapXMLElementType (int XMLtype, const char *XMLname, ElementType *elType,
  208. char **mappedName, char *content,
  209. ThotBool *checkProfile, Document doc)
  210. {
  211. ElemMapping *ptr;
  212. char c;
  213. int i, profile;
  214. ThotBool xmlformat;
  215. /* Initialize variables */
  216. *mappedName = NULL;
  217. *checkProfile = TRUE;
  218. elType->ElTypeNum = 0;
  219. profile = TtaGetDocumentProfile (doc);
  220. if (profile == L_Annot)
  221. profile = L_Other;
  222. /* case sensitive comparison for xml documents */
  223. xmlformat = (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat);
  224. /* Select the right table */
  225. if (XMLtype == XHTML_TYPE)
  226. {
  227. ptr = XHTMLElemMappingTable;
  228. /* no case sensitive whent there is an explicit "text/html" content_type */
  229. if (xmlformat && DocumentMeta[doc] && DocumentMeta[doc]->content_type &&
  230. !strcmp (DocumentMeta[doc]->content_type, "text/html"))
  231. xmlformat = FALSE;
  232. }
  233. else if (XMLtype == MATH_TYPE)
  234. {
  235. if (profile == L_Basic && DocumentTypes[doc] == docHTML)
  236. {
  237. /* Maths are not allowed in this document */
  238. ptr = NULL;
  239. *checkProfile = FALSE;
  240. }
  241. else
  242. ptr = MathMLElemMappingTable;
  243. }
  244. else if (XMLtype == SVG_TYPE)
  245. {
  246. if (profile == L_Basic && DocumentTypes[doc] == docHTML)
  247. {
  248. /* Graphics are not allowed in this document */
  249. ptr = NULL;
  250. *checkProfile = FALSE;
  251. }
  252. else
  253. ptr = SVGElemMappingTable;
  254. }
  255. #ifdef TEMPLATES
  256. else if (XMLtype == Template_TYPE)
  257. {
  258. if (profile == L_Basic && DocumentTypes[doc] == docHTML)
  259. {
  260. /* Graphics are not allowed in this document */
  261. ptr = NULL;
  262. *checkProfile = FALSE;
  263. }
  264. else
  265. ptr = TemplateElemMappingTable;
  266. }
  267. #endif /* TEMPLATES */
  268. else
  269. ptr = NULL;
  270. if (ptr)
  271. {
  272. /* search in the ElemMappingTable */
  273. i = 0;
  274. /* case insensitive for HTML */
  275. if (!xmlformat && ptr == XHTMLElemMappingTable)
  276. c = tolower (XMLname[0]);
  277. else
  278. c = XMLname[0];
  279. /* look for the first concerned entry in the table */
  280. while (ptr[i].XMLname[0] < c && ptr[i].XMLname[0] != EOS)
  281. i++;
  282. /* look at all entries starting with the right character */
  283. do
  284. if (!xmlformat && ptr == XHTMLElemMappingTable &&
  285. strcasecmp (ptr[i].XMLname, XMLname))
  286. /* it's not the tag */
  287. i++;
  288. else if ((xmlformat || ptr != XHTMLElemMappingTable) &&
  289. strcmp (ptr[i].XMLname, XMLname))
  290. /* it's not the tag */
  291. i++;
  292. else if (XMLtype == XHTML_TYPE && profile != L_Other && !(ptr[i].Level & profile))
  293. {
  294. /* this tag is not valid in the document profile */
  295. *checkProfile = FALSE;
  296. i++;
  297. }
  298. else
  299. {
  300. elType->ElTypeNum = ptr[i].ThotType;
  301. if (elType->ElSSchema == NULL)
  302. {
  303. if (XMLtype == Template_TYPE)
  304. elType->ElSSchema = GetTemplateSSchema(doc);
  305. else
  306. elType->ElSSchema = GetXMLSSchema (XMLtype, doc);
  307. }
  308. *mappedName = ptr[i].XMLname;
  309. *content = ptr[i].XMLcontents;
  310. }
  311. while (elType->ElTypeNum <= 0 && ptr[i].XMLname[0] == c);
  312. }
  313. }
  314. /*----------------------------------------------------------------------
  315. GetXMLElementName
  316. Generic function which searchs in the mapping tables the XML name for
  317. a given Thot type.
  318. ----------------------------------------------------------------------*/
  319. const char *GetXMLElementName (ElementType elType, Document doc)
  320. {
  321. ElemMapping *ptr;
  322. char *name;
  323. int i, profile;
  324. ThotBool invalid = FALSE;
  325. if (elType.ElTypeNum > 0)
  326. {
  327. i = 0;
  328. /* Select the table which matches with the element schema */
  329. name = TtaGetSSchemaName (elType.ElSSchema);
  330. if (strcmp ("MathML", name) == 0)
  331. ptr = MathMLElemMappingTable;
  332. else if (strcmp ("SVG", name) == 0)
  333. ptr = SVGElemMappingTable;
  334. else if (strcmp ("HTML", name) == 0)
  335. ptr = XHTMLElemMappingTable;
  336. #ifdef TEMPLATES
  337. else if (strcmp ("Template", name) == 0)
  338. ptr = TemplateElemMappingTable;
  339. #endif /* TEMPLATES */
  340. else
  341. ptr = NULL;
  342. profile = TtaGetDocumentProfile (doc);
  343. if (profile == L_Annot)
  344. profile = L_Other;
  345. if (ptr)
  346. do
  347. {
  348. if (ptr[i].ThotType == elType.ElTypeNum)
  349. {
  350. if (doc == 0 ||
  351. profile == L_Other || (ptr[i].Level & profile))
  352. return ptr[i].XMLname;
  353. else
  354. invalid = TRUE;
  355. }
  356. i++;
  357. }
  358. while (ptr[i].XMLname[0] != EOS);
  359. }
  360. if (invalid)
  361. return "";
  362. else
  363. return "???";
  364. }
  365. /*----------------------------------------------------------------------
  366. IsXMLElementInline
  367. Generic function which searchs in the mapping tables if a given
  368. Thot type is an inline character or not
  369. ----------------------------------------------------------------------*/
  370. ThotBool IsXMLElementInline (ElementType elType, Document doc)
  371. {
  372. int i;
  373. ThotBool ret = FALSE;
  374. char *name;
  375. ElemMapping *ptr;
  376. if (elType.ElTypeNum > 0)
  377. {
  378. i = 0;
  379. /* Select the table which matches with the element schema */
  380. name = TtaGetSSchemaName (elType.ElSSchema);
  381. if (strcmp ("MathML", name) == 0)
  382. ptr = MathMLElemMappingTable;
  383. else if (strcmp ("SVG", name) == 0)
  384. ptr = SVGElemMappingTable;
  385. else if (strcmp ("HTML", name) == 0)
  386. ptr = XHTMLElemMappingTable;
  387. #ifdef TEMPLATES
  388. else if (strcmp ("Template", name) == 0)
  389. return FALSE;
  390. #endif /* TEMPLATES */
  391. else
  392. ptr = NULL;
  393. if (ptr)
  394. {
  395. while (ptr[i].XMLname[0] != EOS &&
  396. ptr[i].ThotType != elType.ElTypeNum)
  397. i++;
  398. if (ptr[i].ThotType == elType.ElTypeNum)
  399. ret = ptr[i].InlineElem;
  400. }
  401. }
  402. return ret;
  403. }
  404. /*----------------------------------------------------------------------
  405. MapXMLAttributeValue
  406. Search in the Attribute Value Mapping Table the entry for the attribute
  407. ThotAtt and its value attVal. Returns the corresponding Thot value.
  408. ----------------------------------------------------------------------*/
  409. void MapXMLAttributeValue (int XMLtype, char *attVal, const AttributeType *attrType,
  410. int *value)
  411. {
  412. AttrValueMapping *ptr;
  413. int i;
  414. /* Select the right table */
  415. if (XMLtype == XHTML_TYPE)
  416. ptr = XhtmlAttrValueMappingTable;
  417. else if (XMLtype == MATH_TYPE)
  418. ptr = MathMLAttrValueMappingTable;
  419. else if (XMLtype == SVG_TYPE)
  420. ptr = SVGAttrValueMappingTable;
  421. #ifdef TEMPLATES
  422. else if (XMLtype == Template_TYPE)
  423. ptr = TemplateAttrValueMappingTable;
  424. #endif /* TEMPLATES */
  425. else
  426. ptr = NULL;
  427. *value = 0;
  428. i = 0;
  429. if (ptr == NULL)
  430. return;
  431. while (ptr[i].ThotAttr != attrType->AttrTypeNum && ptr[i].ThotAttr != 0)
  432. i++;
  433. if (ptr[i].ThotAttr == attrType->AttrTypeNum)
  434. do
  435. if (!strcmp (ptr[i].XMLattrValue, attVal))
  436. *value = ptr[i].ThotAttrValue;
  437. else
  438. i++;
  439. while (*value == 0 && ptr[i].ThotAttr == attrType->AttrTypeNum);
  440. }
  441. /*----------------------------------------------------------------------
  442. MapXMLAttribute
  443. Generic function which searchs in the Attribute Mapping Table (table)
  444. the entry attrName associated to the element elementName.
  445. Returns the corresponding entry or -1.
  446. ----------------------------------------------------------------------*/
  447. int MapXMLAttribute (int XMLtype, const char *attrName, const char *elementName,
  448. ThotBool *checkProfile, Document doc, int *thotType)
  449. {
  450. AttributeMapping *ptr;
  451. char c;
  452. int i, profile, extraprofile;
  453. ThotBool xmlformat;
  454. /* Initialization */
  455. *checkProfile = TRUE;
  456. i = 1;
  457. *thotType = 0;
  458. /* case sensitive comparison for xml documents */
  459. xmlformat = (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat);
  460. /* Select the right table */
  461. if (XMLtype == XHTML_TYPE)
  462. {
  463. ptr = XHTMLAttributeMappingTable;
  464. /* no case sensitive whent there is an explicit "text/html" content_type */
  465. if (xmlformat && DocumentMeta[doc] && DocumentMeta[doc]->content_type &&
  466. !strcmp (DocumentMeta[doc]->content_type, "text/html"))
  467. xmlformat = FALSE;
  468. }
  469. else if (XMLtype == MATH_TYPE)
  470. ptr = MathMLAttributeMappingTable;
  471. else if (XMLtype == SVG_TYPE)
  472. ptr = SVGAttributeMappingTable;
  473. #ifdef TEMPLATES
  474. else if (XMLtype == Template_TYPE)
  475. ptr = TemplateAttributeMappingTable;
  476. #endif /* TEMPLATES */
  477. else if (XMLtype == XLINK_TYPE)
  478. ptr = XLinkAttributeMappingTable;
  479. else
  480. ptr = NULL;
  481. if (ptr == NULL)
  482. return -1;
  483. if (strcmp (attrName, "unknown_attr") == 0)
  484. {
  485. *thotType = ptr[0].ThotAttribute;
  486. return 0;
  487. }
  488. /* case insensitive for HTML */
  489. if (!xmlformat && ptr == XHTMLAttributeMappingTable)
  490. c = tolower (attrName[0]);
  491. else
  492. c = attrName[0];
  493. profile = TtaGetDocumentProfile (doc);
  494. extraprofile = TtaGetDocumentExtraProfile (doc);
  495. if (profile == L_Annot)
  496. profile = L_Other;
  497. /* look for the first concerned entry in the table */
  498. while (ptr[i].XMLattribute[0] < c && ptr[i].XMLattribute[0] != EOS)
  499. i++;
  500. while (ptr[i].XMLattribute[0] == c)
  501. {
  502. if (!xmlformat && ptr == XHTMLAttributeMappingTable &&
  503. (strcasecmp (ptr[i].XMLattribute, attrName) ||
  504. (ptr[i].XMLelement[0] != EOS && elementName &&
  505. strcasecmp (ptr[i].XMLelement, elementName))))
  506. i++;
  507. else if ((xmlformat || ptr != XHTMLAttributeMappingTable) &&
  508. (strcmp (ptr[i].XMLattribute, attrName) ||
  509. (ptr[i].XMLelement[0] != EOS && elementName &&
  510. strcmp (ptr[i].XMLelement, elementName))))
  511. i++;
  512. else if (profile != L_Other && extraprofile == 0 && !(ptr[i].Level & profile))
  513. {
  514. *checkProfile = FALSE;
  515. i++;
  516. }
  517. else if ((ptr[i].Level == L_RDFaValue) && (extraprofile != L_RDFa))
  518. {
  519. *checkProfile = FALSE;
  520. i++;
  521. }
  522. else
  523. {
  524. /* Special case for the 'name' attribute for elements 'a' and 'map' in xhtml1.1 profile */
  525. if ((profile == L_Xhtml11) &&
  526. !strcmp (attrName, "name") && elementName &&
  527. (!strcmp (elementName, "a") || !strcmp (elementName, "map")))
  528. *checkProfile = FALSE;
  529. /* Special case for the attributes 'rel' and 'rev' for elements 'a' and 'link' */
  530. else if ((!strcmp (attrName, "rel") || !strcmp (attrName, "rev")) &&
  531. elementName &&
  532. (strcmp (elementName, "a") && strcmp (elementName, "link")) &&
  533. (extraprofile != L_RDFa))
  534. *checkProfile = FALSE;
  535. else
  536. *thotType = ptr[i].ThotAttribute;
  537. return (i);
  538. }
  539. }
  540. return (-1);
  541. }
  542. /*----------------------------------------------------------------------
  543. GetXMLAttributeName
  544. Generic function which searchs in the mapping tables the XML name for
  545. a given Thot type.
  546. ----------------------------------------------------------------------*/
  547. const char *GetXMLAttributeName (AttributeType attrType, ElementType elType,
  548. Document doc)
  549. {
  550. AttributeMapping *ptr;
  551. char *name;
  552. const char *tag;
  553. int i, profile, extraprofile;
  554. ThotBool invalid = FALSE;
  555. if (attrType.AttrTypeNum > 0)
  556. {
  557. /* get the specific element tag */
  558. if (elType.ElTypeNum > 0)
  559. tag = GetXMLElementName (elType, doc);
  560. else
  561. tag = "";
  562. i = 0;
  563. /* Select the table which matches with the element schema */
  564. name = TtaGetSSchemaName (attrType.AttrSSchema);
  565. if (strcmp ("MathML", name) == 0)
  566. ptr = MathMLAttributeMappingTable;
  567. #ifdef _SVG
  568. else if (strcmp ("SVG", name) == 0)
  569. ptr = SVGAttributeMappingTable;
  570. #endif /* _SVG */
  571. else if (strcmp ("XLink", name) == 0)
  572. ptr = XLinkAttributeMappingTable;
  573. #ifdef TEMPLATES
  574. else if (strcmp ("Template",name) == 0)
  575. ptr = TemplateAttributeMappingTable;
  576. #endif /* TEMPLATES */
  577. else
  578. ptr = XHTMLAttributeMappingTable;
  579. profile = TtaGetDocumentProfile (doc);
  580. extraprofile = TtaGetDocumentExtraProfile (doc);
  581. if (profile == L_Annot)
  582. profile = L_Other;
  583. if (ptr)
  584. do
  585. {
  586. if (ptr[i].ThotAttribute == attrType.AttrTypeNum &&
  587. (ptr[i].XMLelement[0] == EOS || !strcmp (ptr[i].XMLelement, tag)))
  588. {
  589. if (doc != 0 && profile != L_Other && extraprofile == L_NoExtraProfile && !(ptr[i].Level & profile))
  590. invalid = TRUE;
  591. else if (doc != 0 && ptr[i].Level == L_RDFaValue && extraprofile != L_RDFa)
  592. invalid = TRUE;
  593. else if ((attrType.AttrTypeNum == HTML_ATTR_REL ||
  594. attrType.AttrTypeNum == HTML_ATTR_REV) &&
  595. elType.ElTypeNum != HTML_EL_Anchor &&
  596. elType.ElTypeNum != HTML_EL_LINK &&
  597. extraprofile != L_RDFa)
  598. invalid = TRUE;
  599. else
  600. return ptr[i].XMLattribute;
  601. }
  602. i++;
  603. }
  604. while (ptr[i].XMLattribute[0] != EOS);
  605. }
  606. if (invalid)
  607. return "";
  608. else
  609. return "???";
  610. }
  611. /*----------------------------------------------------------------------
  612. HasADoctype returns TRUE if the document includes a DocType
  613. ----------------------------------------------------------------------*/
  614. void HasADoctype (Document doc, ThotBool *found, ThotBool *useMath)
  615. {
  616. Element el_doc, el_doctype;
  617. ElementType elType;
  618. char *s;
  619. ThotBool useSVG;
  620. /* Look for a doctype */
  621. el_doc = TtaGetMainRoot (doc);
  622. elType = TtaGetElementType (el_doc);
  623. /* Search the doctype declaration according to the main schema */
  624. s = TtaGetSSchemaName (elType.ElSSchema);
  625. if (strcmp (s, "HTML") == 0)
  626. elType.ElTypeNum = HTML_EL_DOCTYPE;
  627. else if (strcmp (s, "SVG") == 0)
  628. elType.ElTypeNum = SVG_EL_DOCTYPE;
  629. else if (strcmp (s, "MathML") == 0)
  630. elType.ElTypeNum = MathML_EL_DOCTYPE;
  631. else
  632. elType.ElTypeNum = XML_EL_doctype;
  633. el_doctype = TtaSearchTypedElement (elType, SearchInTree, el_doc);
  634. *found = (el_doctype != NULL);
  635. HasNatures (doc, useMath, &useSVG);
  636. }
  637. /*----------------------------------------------------------------------
  638. MapXMLEntity
  639. Generic function which searchs in the Entity Mapping Table (table)
  640. the entry entityName and give the corresponding decimal value.
  641. Returns FALSE if entityName is not found.
  642. ----------------------------------------------------------------------*/
  643. ThotBool MapXMLEntity (int XMLtype, char *entityName, int *entityValue)
  644. {
  645. XmlEntity *ptr;
  646. ThotBool found;
  647. int inf, sup, med, rescomp;
  648. /* Initialization */
  649. found = FALSE;
  650. sup = 0;
  651. /* Select the right table */
  652. if (XMLtype == XHTML_TYPE || XMLtype == Template_TYPE)
  653. {
  654. ptr = XhtmlEntityTable;
  655. if (XHTMLSup == 0)
  656. for (XHTMLSup = 0; ptr[XHTMLSup].charCode > 0; XHTMLSup++);
  657. sup = XHTMLSup;
  658. }
  659. else if (XMLtype == MATH_TYPE)
  660. {
  661. ptr = MathEntityTable;
  662. if (MathSup == 0)
  663. for (MathSup = 0; ptr[MathSup].charCode > 0; MathSup++);
  664. sup = MathSup;
  665. }
  666. else
  667. ptr = NULL;
  668. if (ptr)
  669. {
  670. inf = 0;
  671. while (sup >= inf && !found)
  672. /* Dichotomic research */
  673. {
  674. med = (sup + inf) / 2;
  675. rescomp = strcmp (ptr[med].charName, entityName);
  676. if (rescomp == 0)
  677. {
  678. /* entity found */
  679. *entityValue = ptr[med].charCode;
  680. found = TRUE;
  681. }
  682. else
  683. {
  684. if (rescomp > 0)
  685. sup = med - 1;
  686. else
  687. inf = med + 1;
  688. }
  689. }
  690. }
  691. if (!found && ptr == XhtmlEntityTable)
  692. // check MathML entities
  693. return MapXMLEntity (MATH_TYPE, entityName, entityValue);
  694. return found;
  695. }
  696. /*----------------------------------------------------------------------
  697. MapEntityByCode
  698. Generic function which searchs in the Entity Mapping Table (table)
  699. the entry with code entityValue and give the corresponding name.
  700. withMath is TRUE when MathML entities are accepted.
  701. Returns FALSE if entityValue is not found.
  702. ----------------------------------------------------------------------*/
  703. void MapEntityByCode (int entityValue, Document doc, ThotBool withMath,
  704. char **entityName)
  705. {
  706. XmlEntity *ptr;
  707. ThotBool found;
  708. int i;
  709. /* Select the right table */
  710. if (withMath)
  711. /* look for in the Math entities table */
  712. ptr = MathEntityTable;
  713. else
  714. ptr = XhtmlEntityTable;
  715. if (ptr)
  716. {
  717. /* look for in the HTML entities table */
  718. found = FALSE;
  719. while (ptr && !found)
  720. {
  721. for (i = 0; ptr[i].charCode != 0 && !found; i++)
  722. found = (ptr[i].charCode == entityValue);
  723. if (found)
  724. {
  725. /* entity value found */
  726. i--;
  727. *entityName = (char *) (ptr[i].charName);
  728. }
  729. else if (withMath && ptr != XhtmlEntityTable)
  730. /* look for in the Math entities table */
  731. ptr = XhtmlEntityTable;
  732. else
  733. {
  734. *entityName = NULL;
  735. ptr = NULL;
  736. }
  737. }
  738. }
  739. else
  740. *entityName = NULL;
  741. }