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