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