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