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