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