Return to fetchXMLname.c CVS log | Up to [Public] / Amaya / amaya |
1.1 cvs 1: /* 2: * 1.38 cvs 3: * (c) COPYRIGHT MIT and INRIA, 1996-2001 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.46 cvs 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.42 cvs 53: /*----------------------------------------------------------------------charName 1.1 cvs 54: GetMathMLSSchema returns the MathML Thot schema for document doc. 55: ----------------------------------------------------------------------*/ 1.46 cvs 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.49 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.46 cvs 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.46 cvs 100: GetGenericXMLSSchema returns the XML Thot schema for the document doc. 101: ----------------------------------------------------------------------*/ 102: SSchema GetGenericXMLSSchema (Document doc) 103: 104: { 105: SSchema XMLSSchema; 106: 107: XMLSSchema = TtaGetSSchema ("XML", doc); 108: if (XMLSSchema == NULL) 109: XMLSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc), 110: "XML", "XMLP"); 111: return (XMLSSchema); 112: } 113: 114: /*---------------------------------------------------------------------- 115: GetGenericXMLSSchemaByUri returns the XML Thot schema for the document doc. 116: ----------------------------------------------------------------------*/ 117: SSchema GetGenericXMLSSchemaByUri (char *uriName, Document doc, ThotBool *isnew) 118: 119: { 120: SSchema XMLSSchema; 121: 122: XMLSSchema = TtaGetSSchemaByUri (uriName, doc); 123: if (XMLSSchema == NULL) 124: { 125: XMLSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc), 126: "XML", "XMLP"); 127: *isnew = TRUE; 128: } 129: return (XMLSSchema); 130: } 131: 132: /*---------------------------------------------------------------------- 1.13 cvs 133: GetXMLSSchema returns the XML Thot schema for document doc. 1.1 cvs 134: ----------------------------------------------------------------------*/ 1.45 cvs 135: SSchema GetXMLSSchema (int XMLtype, Document doc) 1.38 cvs 136: 1.1 cvs 137: { 1.14 cvs 138: if (XMLtype == XHTML_TYPE) 139: return GetXHTMLSSchema (doc); 140: else if (XMLtype == MATH_TYPE) 1.13 cvs 141: return GetMathMLSSchema (doc); 1.51 cvs 142: else if (XMLtype == SVG_TYPE) 1.49 vatton 143: return GetSVGSSchema (doc); 1.13 cvs 144: else if (XMLtype == XLINK_TYPE) 1.15 cvs 145: return GetXLinkSSchema (doc); 1.13 cvs 146: else 147: return NULL; 1.1 cvs 148: } 149: 150: 151: /*---------------------------------------------------------------------- 1.22 cvs 152: MapXMLElementType 153: Generic function which searchs in the Element Mapping table, selected 154: by the parameter XMLtype, the entry XMLname and returns the corresponding 155: Thot element type. 1.1 cvs 156: Returns: 1.22 cvs 157: - ElTypeNum and ElSSchema into elType ElTypeNum = 0 if not found. 1.1 cvs 158: - content 159: ----------------------------------------------------------------------*/ 1.46 cvs 160: void MapXMLElementType (int XMLtype, 161: char *XMLname, 162: ElementType *elType, 163: char **mappedName, 164: char *content, 165: ThotBool *highEnoughLevel, 1.45 cvs 166: Document doc) 1.1 cvs 167: { 168: int i; 169: ElemMapping *ptr; 170: 1.32 cvs 171: /* Initialize variables */ 172: *mappedName = NULL; 173: *highEnoughLevel = TRUE; 174: elType->ElTypeNum = 0; 175: 1.1 cvs 176: /* Select the right table */ 1.14 cvs 177: if (XMLtype == XHTML_TYPE) 178: ptr = XHTMLElemMappingTable; 179: else if (XMLtype == MATH_TYPE) 1.31 cvs 180: { 181: if (ParsingLevel[doc] == L_Basic && DocumentTypes[doc] == docHTML) 1.32 cvs 182: { 183: /* Maths are not allowed in this document */ 184: ptr = NULL; 185: *highEnoughLevel = FALSE; 186: } 1.31 cvs 187: else 188: ptr = MathMLElemMappingTable; 189: } 1.51 cvs 190: else if (XMLtype == SVG_TYPE) 1.31 cvs 191: { 192: if (ParsingLevel[doc] == L_Basic && DocumentTypes[doc] == docHTML) 1.32 cvs 193: { 194: /* Graphics are not allowed in this document */ 195: ptr = NULL; 196: *highEnoughLevel = FALSE; 197: } 1.31 cvs 198: else 1.49 vatton 199: ptr = SVGElemMappingTable; 1.31 cvs 200: } 1.1 cvs 201: else 202: ptr = NULL; 1.32 cvs 203: 1.1 cvs 204: if (ptr != NULL) 205: { 206: /* search in the ElemMappingTable */ 207: i = 0; 208: /* look for the first concerned entry in the table */ 1.44 cvs 209: while (ptr[i].XMLname[0] < XMLname[0] && ptr[i].XMLname[0] != EOS) 1.32 cvs 210: i++; 1.1 cvs 211: /* look at all entries starting with the right character */ 212: do 1.44 cvs 213: if (strcmp (ptr[i].XMLname, XMLname)) 1.32 cvs 214: /* it's not the tag */ 1.1 cvs 215: i++; 1.37 cvs 216: else if (ParsingLevel[doc] != L_Other && 1.47 cvs 217: !(ptr[i].Level & ParsingLevel[doc])) 1.32 cvs 218: { 219: /* this tag is not valid for the current parsing level */ 220: *highEnoughLevel = FALSE; 221: i++; 222: } 1.1 cvs 223: else 224: { 225: elType->ElTypeNum = ptr[i].ThotType; 226: if (elType->ElSSchema == NULL) 227: elType->ElSSchema = GetXMLSSchema (XMLtype, doc); 228: *mappedName = ptr[i].XMLname; 229: *content = ptr[i].XMLcontents; 230: } 231: while (elType->ElTypeNum <= 0 && ptr[i].XMLname[0] == XMLname[0]); 232: } 233: } 234: 235: 236: /*---------------------------------------------------------------------- 237: GetXMLElementName 1.52 ! cvs 238: Generic function which searchs in the mapping tables the XML name for 1.22 cvs 239: a given Thot type. 1.1 cvs 240: ----------------------------------------------------------------------*/ 1.44 cvs 241: char* GetXMLElementName (ElementType elType, Document doc) 1.1 cvs 242: { 1.46 cvs 243: ElemMapping *ptr; 244: char *name; 245: int i; 246: ThotBool invalid = FALSE; 1.27 cvs 247: 248: if (elType.ElTypeNum > 0) 249: { 250: i = 0; 251: /* Select the table which matches with the element schema */ 252: name = TtaGetSSchemaName (elType.ElSSchema); 1.44 cvs 253: if (strcmp ("MathML", name) == 0) 1.27 cvs 254: ptr = MathMLElemMappingTable; 1.49 vatton 255: else if (strcmp ("SVG", name) == 0) 256: ptr = SVGElemMappingTable; 1.27 cvs 257: else 258: ptr = XHTMLElemMappingTable; 259: 260: if (ptr) 261: do 262: { 263: if (ptr[i].ThotType == elType.ElTypeNum) 264: { 1.37 cvs 265: if (doc == 0 || 266: ParsingLevel[doc] == L_Other || 1.47 cvs 267: (ptr[i].Level & ParsingLevel[doc])) 1.27 cvs 268: return ptr[i].XMLname; 269: else 270: invalid = TRUE; 271: } 272: i++; 273: } 1.44 cvs 274: while (ptr[i].XMLname[0] != EOS); 1.27 cvs 275: } 276: if (invalid) 1.43 cvs 277: return ""; 1.27 cvs 278: else 1.43 cvs 279: return "???"; 1.22 cvs 280: } 1.25 cvs 281: 282: 1.29 cvs 283: 284: /*---------------------------------------------------------------------- 1.30 cvs 285: IsXMLElementInline 1.52 ! cvs 286: Generic function which searchs in the mapping tables if a given 1.29 cvs 287: Thot type is an inline character or not 288: ----------------------------------------------------------------------*/ 1.52 ! cvs 289: ThotBool IsXMLElementInline (ElementType elType, Document doc) 1.29 cvs 290: { 1.34 cvs 291: int i; 292: ThotBool ret = FALSE; 1.45 cvs 293: char *name; 1.34 cvs 294: ElemMapping *ptr; 1.29 cvs 295: 296: if (elType.ElTypeNum > 0) 297: { 298: i = 0; 299: /* Select the table which matches with the element schema */ 300: name = TtaGetSSchemaName (elType.ElSSchema); 1.44 cvs 301: if (strcmp ("MathML", name) == 0) 1.29 cvs 302: ptr = MathMLElemMappingTable; 1.49 vatton 303: else if (strcmp ("SVG", name) == 0) 304: ptr = SVGElemMappingTable; 1.52 ! cvs 305: else if (strcmp ("HTML", name) == 0) ! 306: ptr = XHTMLElemMappingTable; 1.29 cvs 307: else 1.52 ! cvs 308: ptr = NULL; 1.29 cvs 309: 310: if (ptr) 311: { 1.44 cvs 312: while (ptr[i].XMLname[0] != EOS && 1.29 cvs 313: ptr[i].ThotType != elType.ElTypeNum) 314: i++; 315: if (ptr[i].ThotType == elType.ElTypeNum) 316: ret = ptr[i].Inline; 317: } 318: } 319: return ret; 320: } 321: 1.22 cvs 322: /*---------------------------------------------------------------------- 1.24 cvs 323: MapXMLAttribute 1.22 cvs 324: Generic function which searchs in the Attribute Mapping Table (table) 325: the entry attrName associated to the element elementName. 1.24 cvs 326: Returns the corresponding entry or -1. 1.22 cvs 327: ----------------------------------------------------------------------*/ 1.44 cvs 328: int MapXMLAttribute (int XMLtype, char *attrName, 329: char *elementName, ThotBool *highEnoughLevel, 1.33 cvs 330: Document doc, int *thotType) 1.22 cvs 331: { 1.24 cvs 332: int i; 333: AttributeMapping *ptr; 334: 1.33 cvs 335: /* Initialization */ 336: *highEnoughLevel = TRUE; 337: i = 1; 338: *thotType = 0; 1.50 cvs 339: 340: /* Select the right table */ 341: if (XMLtype == XHTML_TYPE) 342: ptr = XHTMLAttributeMappingTable; 343: else if (XMLtype == MATH_TYPE) 344: ptr = MathMLAttributeMappingTable; 1.51 cvs 345: else if (XMLtype == SVG_TYPE) 1.50 cvs 346: ptr = SVGAttributeMappingTable; 347: else if (XMLtype == XLINK_TYPE) 348: ptr = XLinkAttributeMappingTable; 349: else 350: ptr = NULL; 351: 1.24 cvs 352: if (ptr == NULL) 353: return -1; 1.50 cvs 354: 355: if (strcmp (attrName, "unknown_attr") == 0) 356: { 357: *thotType = ptr[0].ThotAttribute; 358: return 0; 359: } 1.22 cvs 360: 361: /* look for the first concerned entry in the table */ 1.33 cvs 362: while (ptr[i].XMLattribute[0] < attrName[0] && 1.44 cvs 363: ptr[i].XMLattribute[0] != EOS) 1.22 cvs 364: i++; 1.33 cvs 365: 1.24 cvs 366: while (ptr[i].XMLattribute[0] == attrName[0]) 1.22 cvs 367: { 1.44 cvs 368: if (strcmp (ptr[i].XMLattribute, attrName) || 369: (ptr[i].XMLelement[0] != EOS && 370: strcmp (ptr[i].XMLelement, elementName))) 1.22 cvs 371: i++; 1.47 cvs 372: else if (ParsingLevel[doc] != L_Other && 373: !(ptr[i].Level & ParsingLevel[doc])) 1.33 cvs 374: { 375: *highEnoughLevel = FALSE; 376: i++; 377: } 1.22 cvs 378: else 1.24 cvs 379: { 380: *thotType = ptr[i].ThotAttribute; 381: return (i); 382: } 1.22 cvs 383: } 1.24 cvs 384: return (-1); 1.25 cvs 385: } 386: 387: 388: /*---------------------------------------------------------------------- 1.37 cvs 389: GetXMLAttributeName 1.52 ! cvs 390: Generic function which searchs in the mapping tables the XML name for 1.25 cvs 391: a given Thot type. 392: ----------------------------------------------------------------------*/ 1.44 cvs 393: char* GetXMLAttributeName (AttributeType attrType, 1.46 cvs 394: ElementType elType, 395: Document doc) 1.25 cvs 396: { 397: AttributeMapping *ptr; 1.45 cvs 398: char *name, *tag; 1.25 cvs 399: int i; 1.27 cvs 400: ThotBool invalid = FALSE; 1.25 cvs 401: 1.27 cvs 402: if (attrType.AttrTypeNum > 0) 403: { 1.28 cvs 404: /* get the specific element tag */ 405: if (elType.ElTypeNum > 0) 406: tag = GetXMLElementName (elType, doc); 407: else 1.43 cvs 408: tag = ""; 1.28 cvs 409: 1.27 cvs 410: i = 0; 411: /* Select the table which matches with the element schema */ 412: name = TtaGetSSchemaName (attrType.AttrSSchema); 1.44 cvs 413: if (strcmp ("MathML", name) == 0) 1.27 cvs 414: ptr = MathMLAttributeMappingTable; 1.49 vatton 415: else if (strcmp ("SVG", name) == 0) 416: ptr = SVGAttributeMappingTable; 1.44 cvs 417: else if (strcmp ("XLink", name) == 0) 1.27 cvs 418: ptr = XLinkAttributeMappingTable; 419: else 420: ptr = XHTMLAttributeMappingTable; 421: 422: if (ptr) 423: do 424: { 1.28 cvs 425: if (ptr[i].ThotAttribute == attrType.AttrTypeNum && 1.44 cvs 426: (ptr[i].XMLelement[0] == EOS || 427: !strcmp (ptr[i].XMLelement, tag))) 1.25 cvs 428: { 1.48 cvs 429: if (doc != 0 && 430: ParsingLevel[doc] != L_Other && 431: !(ptr[i].Level & ParsingLevel[doc])) 432: invalid = TRUE; 433: else 1.25 cvs 434: return ptr[i].XMLattribute; 435: } 436: i++; 1.27 cvs 437: } 1.44 cvs 438: while (ptr[i].XMLattribute[0] != EOS); 1.27 cvs 439: } 440: if (invalid) 1.43 cvs 441: return ""; 1.27 cvs 442: else 1.43 cvs 443: return "???"; 1.36 cvs 444: } 445: 446: /*---------------------------------------------------------------------- 447: MapXMLEntity 448: Generic function which searchs in the Entity Mapping Table (table) 449: the entry entityName and give the corresponding decimal value. 450: Returns FALSE if entityName is not found. 451: ----------------------------------------------------------------------*/ 1.46 cvs 452: ThotBool MapXMLEntity (int XMLtype, char *entityName, int *entityValue) 1.36 cvs 453: { 454: XmlEntity *ptr; 455: ThotBool found; 1.38 cvs 456: int inf, sup, med, rescomp; 1.36 cvs 457: 1.38 cvs 458: /* Initialization */ 1.36 cvs 459: found = FALSE; 1.42 cvs 460: sup = 0; 1.36 cvs 461: 462: /* Select the right table */ 463: if (XMLtype == XHTML_TYPE) 1.39 cvs 464: { 465: ptr = XhtmlEntityTable; 466: if (XHTMLSup == 0) 467: for (XHTMLSup = 0; ptr[XHTMLSup].charCode > 0; XHTMLSup++); 468: sup = XHTMLSup; 469: } 1.36 cvs 470: else if (XMLtype == MATH_TYPE) 1.39 cvs 471: { 472: ptr = MathEntityTable; 473: if (MathSup == 0) 474: for (MathSup = 0; ptr[MathSup].charCode > 0; MathSup++); 475: sup = MathSup; 476: } 1.36 cvs 477: else 478: ptr = NULL; 479: 480: if (ptr == NULL) 1.38 cvs 481: return found; 482: 483: inf = 0; 484: while (sup >= inf && !found) 485: /* Dichotomic research */ 1.36 cvs 486: { 1.38 cvs 487: med = (sup + inf) / 2; 1.44 cvs 488: rescomp = strcmp (ptr[med].charName, entityName); 1.38 cvs 489: if (rescomp == 0) 490: { 491: /* entity found */ 492: *entityValue = ptr[med].charCode; 493: found = TRUE; 494: } 495: else 496: { 497: if (rescomp > 0) 498: sup = med - 1; 499: else 500: inf = med + 1; 501: } 1.36 cvs 502: } 1.38 cvs 503: return found; 504: } 1.39 cvs 505: 506: /*---------------------------------------------------------------------- 507: MapEntityByCode 508: Generic function which searchs in the Entity Mapping Table (table) 509: the entry with code entityValue and give the corresponding name. 510: Returns FALSE if entityValue is not found. 511: ----------------------------------------------------------------------*/ 1.40 cvs 512: void MapEntityByCode (int entityValue, char **entityName) 1.39 cvs 513: { 514: XmlEntity *ptr; 515: ThotBool found; 516: int i; 517: 518: /* Select the right table */ 1.40 cvs 519: ptr = XhtmlEntityTable; 520: if (ptr) 521: { 1.41 cvs 522: /* look for in the HTML entities table */ 1.40 cvs 523: found = FALSE; 1.41 cvs 524: while (ptr && !found) 525: { 526: for (i = 0; ptr[i].charCode >= 0 && !found; i++) 527: found = (ptr[i].charCode == entityValue); 1.39 cvs 528: 1.41 cvs 529: if (found) 530: { 531: /* entity value found */ 532: i--; 533: *entityName = (char *) (ptr[i].charName); 534: } 535: else if (ptr != MathEntityTable) 536: /* look for in the Math entities table */ 537: ptr = MathEntityTable; 538: else 539: { 540: *entityName = NULL; 541: ptr = NULL; 542: } 1.40 cvs 543: } 544: } 1.39 cvs 545: else 1.40 cvs 546: *entityName = NULL; 1.39 cvs 547: }