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: * 12: * Author: I. Vatton 13: * 14: */ 15: 16: #define THOT_EXPORT extern 17: #include "amaya.h" 18: #include "parser.h" 1.24 cvs 19: #include "HTMLnames.h" 20: #include "MathMLnames.h" 21: #include "GraphMLnames.h" 22: #include "XLinknames.h" 23: 1.35 cvs 24: /* define some pointers to let other parser functions access the local table */ 1.24 cvs 25: int HTML_ENTRIES = (sizeof(XHTMLElemMappingTable) / sizeof(ElemMapping)); 26: ElemMapping *pHTMLGIMapping = XHTMLElemMappingTable; 27: AttributeMapping *pHTMLAttributeMapping = XHTMLAttributeMappingTable; 1.14 cvs 28: 1.35 cvs 29: XmlEntity *pXhtmlEntityTable = XhtmlEntityTable; 30: XmlEntity *pMathEntityTable = MathEntityTable; 1.1 cvs 31: 32: #include "fetchXMLname_f.h" 33: 1.39 cvs 34: /* Global variables used by the entity mapping */ 35: static int XHTMLSup = 0; 36: static int MathSup = 0; 37: 1.1 cvs 38: /*---------------------------------------------------------------------- 1.14 cvs 39: GetXHTMLSSchema returns the XHTML Thot schema for document doc. 40: ----------------------------------------------------------------------*/ 41: SSchema GetXHTMLSSchema (Document doc) 42: 43: { 44: SSchema XHTMLSSchema; 45: 46: XHTMLSSchema = TtaGetSSchema (TEXT("HTML"), doc); 47: if (XHTMLSSchema == NULL) 1.17 cvs 48: XHTMLSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc), 1.14 cvs 49: TEXT("HTML"), TEXT("HTMLP")); 50: return (XHTMLSSchema); 51: } 52: 1.42 ! cvs 53: /*----------------------------------------------------------------------charName 1.1 cvs 54: GetMathMLSSchema returns the MathML Thot schema for document doc. 55: ----------------------------------------------------------------------*/ 56: SSchema GetMathMLSSchema (Document doc) 57: 58: { 59: SSchema MathMLSSchema; 60: 1.13 cvs 61: MathMLSSchema = TtaGetSSchema (TEXT("MathML"), doc); 62: if (MathMLSSchema == NULL) 1.17 cvs 63: MathMLSSchema = TtaNewNature(doc, 64: TtaGetDocumentSSchema(doc), TEXT("MathML"), 1.13 cvs 65: TEXT("MathMLP")); 66: return (MathMLSSchema); 1.1 cvs 67: } 68: 69: /*---------------------------------------------------------------------- 70: GetGraphMLSSchema returns the GraphML Thot schema for document doc. 71: ----------------------------------------------------------------------*/ 72: SSchema GetGraphMLSSchema (Document doc) 73: 74: { 75: SSchema GraphMLSSchema; 76: 1.8 cvs 77: GraphMLSSchema = TtaGetSSchema (TEXT("GraphML"), doc); 1.1 cvs 78: if (GraphMLSSchema == NULL) 1.17 cvs 79: GraphMLSSchema = TtaNewNature(doc, 80: TtaGetDocumentSSchema(doc), TEXT("GraphML"), 1.13 cvs 81: TEXT("GraphMLP")); 1.1 cvs 82: return (GraphMLSSchema); 83: } 84: 85: /*---------------------------------------------------------------------- 1.13 cvs 86: GetXLinkSSchema returns the XLink Thot schema for document doc. 87: ----------------------------------------------------------------------*/ 88: SSchema GetXLinkSSchema (Document doc) 89: 90: { 91: SSchema XLinkSSchema; 92: 93: XLinkSSchema = TtaGetSSchema (TEXT("XLink"), doc); 94: if (XLinkSSchema == NULL) 1.17 cvs 95: XLinkSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc), TEXT("XLink"), 1.13 cvs 96: TEXT("XLinkP")); 97: return (XLinkSSchema); 98: } 99: 100: /*---------------------------------------------------------------------- 101: GetXMLSSchema returns the XML Thot schema for document doc. 1.1 cvs 102: ----------------------------------------------------------------------*/ 103: SSchema GetXMLSSchema (int XMLtype, Document doc) 1.38 cvs 104: 1.1 cvs 105: { 1.14 cvs 106: if (XMLtype == XHTML_TYPE) 107: return GetXHTMLSSchema (doc); 108: else if (XMLtype == MATH_TYPE) 1.13 cvs 109: return GetMathMLSSchema (doc); 110: else if (XMLtype == GRAPH_TYPE) 111: return GetGraphMLSSchema (doc); 112: else if (XMLtype == XLINK_TYPE) 1.15 cvs 113: return GetXLinkSSchema (doc); 1.13 cvs 114: else 115: return NULL; 1.1 cvs 116: } 117: 118: 119: /*---------------------------------------------------------------------- 1.22 cvs 120: MapXMLElementType 121: Generic function which searchs in the Element Mapping table, selected 122: by the parameter XMLtype, the entry XMLname and returns the corresponding 123: Thot element type. 1.1 cvs 124: Returns: 1.22 cvs 125: - ElTypeNum and ElSSchema into elType ElTypeNum = 0 if not found. 1.1 cvs 126: - content 127: ----------------------------------------------------------------------*/ 1.32 cvs 128: void MapXMLElementType (int XMLtype, 129: STRING XMLname, 130: ElementType *elType, 131: STRING *mappedName, 132: CHAR_T *content, 133: ThotBool *highEnoughLevel, 134: Document doc) 1.1 cvs 135: { 136: int i; 137: ElemMapping *ptr; 138: 1.32 cvs 139: /* Initialize variables */ 140: *mappedName = NULL; 141: *highEnoughLevel = TRUE; 142: elType->ElTypeNum = 0; 143: 1.1 cvs 144: /* Select the right table */ 1.14 cvs 145: if (XMLtype == XHTML_TYPE) 146: ptr = XHTMLElemMappingTable; 147: else if (XMLtype == MATH_TYPE) 1.31 cvs 148: { 149: if (ParsingLevel[doc] == L_Basic && DocumentTypes[doc] == docHTML) 1.32 cvs 150: { 151: /* Maths are not allowed in this document */ 152: ptr = NULL; 153: *highEnoughLevel = FALSE; 154: } 1.31 cvs 155: else 156: ptr = MathMLElemMappingTable; 157: } 1.1 cvs 158: else if (XMLtype == GRAPH_TYPE) 1.31 cvs 159: { 160: if (ParsingLevel[doc] == L_Basic && DocumentTypes[doc] == docHTML) 1.32 cvs 161: { 162: /* Graphics are not allowed in this document */ 163: ptr = NULL; 164: *highEnoughLevel = FALSE; 165: } 1.31 cvs 166: else 167: ptr = GraphMLElemMappingTable; 168: } 1.1 cvs 169: else 170: ptr = NULL; 1.32 cvs 171: 1.1 cvs 172: if (ptr != NULL) 173: { 174: /* search in the ElemMappingTable */ 175: i = 0; 176: /* look for the first concerned entry in the table */ 1.22 cvs 177: while (ptr[i].XMLname[0] < XMLname[0] && ptr[i].XMLname[0] != WC_EOS) 1.32 cvs 178: i++; 1.1 cvs 179: /* look at all entries starting with the right character */ 180: do 1.32 cvs 181: if (ustrcmp (ptr[i].XMLname, XMLname)) 182: /* it's not the tag */ 1.1 cvs 183: i++; 1.37 cvs 184: else if (ParsingLevel[doc] != L_Other && 185: ptr[i].Level > ParsingLevel[doc]) 1.32 cvs 186: { 187: /* this tag is not valid for the current parsing level */ 188: *highEnoughLevel = FALSE; 189: i++; 190: } 1.1 cvs 191: else 192: { 193: elType->ElTypeNum = ptr[i].ThotType; 194: if (elType->ElSSchema == NULL) 195: elType->ElSSchema = GetXMLSSchema (XMLtype, doc); 196: *mappedName = ptr[i].XMLname; 197: *content = ptr[i].XMLcontents; 198: } 199: while (elType->ElTypeNum <= 0 && ptr[i].XMLname[0] == XMLname[0]); 200: } 201: } 202: 203: 204: /*---------------------------------------------------------------------- 205: GetXMLElementName 1.22 cvs 206: Generic function which searchs in the mapping table the XML name for 207: a given Thot type. 1.1 cvs 208: ----------------------------------------------------------------------*/ 1.25 cvs 209: CHAR_T* GetXMLElementName (ElementType elType, Document doc) 1.1 cvs 210: { 1.27 cvs 211: ElemMapping *ptr; 212: STRING name; 213: int i; 214: ThotBool invalid = FALSE; 215: 216: if (elType.ElTypeNum > 0) 217: { 218: i = 0; 219: /* Select the table which matches with the element schema */ 220: name = TtaGetSSchemaName (elType.ElSSchema); 221: if (ustrcmp (TEXT("MathML"), name) == 0) 222: ptr = MathMLElemMappingTable; 223: else if (ustrcmp (TEXT("GraphML"), name) == 0) 224: ptr = GraphMLElemMappingTable; 225: else 226: ptr = XHTMLElemMappingTable; 227: 228: if (ptr) 229: do 230: { 231: if (ptr[i].ThotType == elType.ElTypeNum) 232: { 1.37 cvs 233: if (doc == 0 || 234: ParsingLevel[doc] == L_Other || 235: ptr[i].Level <= ParsingLevel[doc]) 1.27 cvs 236: return ptr[i].XMLname; 237: else 238: invalid = TRUE; 239: } 240: i++; 241: } 242: while (ptr[i].XMLname[0] != WC_EOS); 243: } 244: if (invalid) 245: return TEXT(""); 246: else 247: return TEXT("???"); 1.22 cvs 248: } 1.25 cvs 249: 250: 1.29 cvs 251: 252: /*---------------------------------------------------------------------- 1.30 cvs 253: IsXMLElementInline 1.29 cvs 254: Generic function which searchs in the mapping table if a given 255: Thot type is an inline character or not 256: ----------------------------------------------------------------------*/ 1.34 cvs 257: ThotBool IsXMLElementInline (ElementType elType) 1.38 cvs 258: 1.29 cvs 259: { 1.34 cvs 260: int i; 261: ThotBool ret = FALSE; 262: STRING name; 263: ElemMapping *ptr; 1.29 cvs 264: 265: if (elType.ElTypeNum > 0) 266: { 267: i = 0; 268: /* Select the table which matches with the element schema */ 269: name = TtaGetSSchemaName (elType.ElSSchema); 270: if (ustrcmp (TEXT("MathML"), name) == 0) 271: ptr = MathMLElemMappingTable; 272: else if (ustrcmp (TEXT("GraphML"), name) == 0) 273: ptr = GraphMLElemMappingTable; 274: else 275: ptr = XHTMLElemMappingTable; 276: 277: if (ptr) 278: { 279: while (ptr[i].XMLname[0] != WC_EOS && 280: ptr[i].ThotType != elType.ElTypeNum) 281: i++; 282: if (ptr[i].ThotType == elType.ElTypeNum) 283: ret = ptr[i].Inline; 284: } 285: } 286: return ret; 287: } 288: 1.22 cvs 289: /*---------------------------------------------------------------------- 1.24 cvs 290: MapXMLAttribute 1.22 cvs 291: Generic function which searchs in the Attribute Mapping Table (table) 292: the entry attrName associated to the element elementName. 1.24 cvs 293: Returns the corresponding entry or -1. 1.22 cvs 294: ----------------------------------------------------------------------*/ 1.33 cvs 295: int MapXMLAttribute (int XMLtype, CHAR_T *attrName, 296: CHAR_T *elementName, ThotBool *highEnoughLevel, 297: Document doc, int *thotType) 1.22 cvs 298: { 1.24 cvs 299: int i; 300: AttributeMapping *ptr; 301: 1.33 cvs 302: /* Initialization */ 303: *highEnoughLevel = TRUE; 304: i = 1; 305: *thotType = 0; 306: 1.24 cvs 307: /* Select the right table */ 308: if (XMLtype == XHTML_TYPE) 309: ptr = XHTMLAttributeMappingTable; 310: else if (XMLtype == MATH_TYPE) 311: ptr = MathMLAttributeMappingTable; 312: else if (XMLtype == GRAPH_TYPE) 313: ptr = GraphMLAttributeMappingTable; 314: else if (XMLtype == XLINK_TYPE) 315: ptr = XLinkAttributeMappingTable; 316: else 317: ptr = NULL; 318: 319: if (ptr == NULL) 320: return -1; 1.22 cvs 321: 322: /* look for the first concerned entry in the table */ 1.33 cvs 323: while (ptr[i].XMLattribute[0] < attrName[0] && 324: ptr[i].XMLattribute[0] != WC_EOS) 1.22 cvs 325: i++; 1.33 cvs 326: 1.24 cvs 327: while (ptr[i].XMLattribute[0] == attrName[0]) 1.22 cvs 328: { 1.33 cvs 329: if (ustrcmp (ptr[i].XMLattribute, attrName) || 330: (ptr[i].XMLelement[0] != WC_EOS && 331: ustrcmp (ptr[i].XMLelement, elementName))) 1.22 cvs 332: i++; 1.33 cvs 333: else if (ptr[i].Level > ParsingLevel[doc]) 334: { 335: *highEnoughLevel = FALSE; 336: i++; 337: } 1.22 cvs 338: else 1.24 cvs 339: { 340: *thotType = ptr[i].ThotAttribute; 341: return (i); 342: } 1.22 cvs 343: } 1.24 cvs 344: return (-1); 1.25 cvs 345: } 346: 347: 348: /*---------------------------------------------------------------------- 1.37 cvs 349: GetXMLAttributeName 1.25 cvs 350: Generic function which searchs in the mapping table the XML name for 351: a given Thot type. 352: ----------------------------------------------------------------------*/ 1.38 cvs 353: CHAR_T* GetXMLAttributeName (AttributeType attrType, 354: ElementType elType, 355: Document doc) 1.25 cvs 356: { 357: AttributeMapping *ptr; 1.28 cvs 358: STRING name, tag; 1.25 cvs 359: int i; 1.27 cvs 360: ThotBool invalid = FALSE; 1.25 cvs 361: 1.27 cvs 362: if (attrType.AttrTypeNum > 0) 363: { 1.28 cvs 364: /* get the specific element tag */ 365: if (elType.ElTypeNum > 0) 366: tag = GetXMLElementName (elType, doc); 367: else 368: tag = TEXT(""); 369: 1.27 cvs 370: i = 0; 371: /* Select the table which matches with the element schema */ 372: name = TtaGetSSchemaName (attrType.AttrSSchema); 373: if (ustrcmp (TEXT("MathML"), name) == 0) 374: ptr = MathMLAttributeMappingTable; 375: else if (ustrcmp (TEXT("GraphML"), name) == 0) 376: ptr = GraphMLAttributeMappingTable; 377: else if (ustrcmp (TEXT("XLink"), name) == 0) 378: ptr = XLinkAttributeMappingTable; 379: else 380: ptr = XHTMLAttributeMappingTable; 381: 382: if (ptr) 383: do 384: { 1.28 cvs 385: if (ptr[i].ThotAttribute == attrType.AttrTypeNum && 386: (ptr[i].XMLelement[0] == WC_EOS || 387: !ustrcmp (ptr[i].XMLelement, tag))) 1.25 cvs 388: { 1.26 cvs 389: if (doc == 0 || ptr[i].Level <= ParsingLevel[doc]) 1.25 cvs 390: return ptr[i].XMLattribute; 391: else 1.27 cvs 392: invalid = TRUE; 1.25 cvs 393: } 394: i++; 1.27 cvs 395: } 396: while (ptr[i].XMLattribute[0] != WC_EOS); 397: } 398: if (invalid) 399: return TEXT(""); 400: else 401: return TEXT("???"); 1.36 cvs 402: } 403: 404: /*---------------------------------------------------------------------- 405: MapXMLEntity 406: Generic function which searchs in the Entity Mapping Table (table) 407: the entry entityName and give the corresponding decimal value. 408: Returns FALSE if entityName is not found. 409: ----------------------------------------------------------------------*/ 410: ThotBool MapXMLEntity (int XMLtype, STRING entityName, int *entityValue) 1.38 cvs 411: 1.36 cvs 412: { 413: XmlEntity *ptr; 414: ThotBool found; 1.38 cvs 415: int inf, sup, med, rescomp; 1.36 cvs 416: 1.38 cvs 417: /* Initialization */ 1.36 cvs 418: found = FALSE; 1.42 ! cvs 419: sup = 0; 1.36 cvs 420: 421: /* Select the right table */ 422: if (XMLtype == XHTML_TYPE) 1.39 cvs 423: { 424: ptr = XhtmlEntityTable; 425: if (XHTMLSup == 0) 426: for (XHTMLSup = 0; ptr[XHTMLSup].charCode > 0; XHTMLSup++); 427: sup = XHTMLSup; 428: } 1.36 cvs 429: else if (XMLtype == MATH_TYPE) 1.39 cvs 430: { 431: ptr = MathEntityTable; 432: if (MathSup == 0) 433: for (MathSup = 0; ptr[MathSup].charCode > 0; MathSup++); 434: sup = MathSup; 435: } 1.36 cvs 436: else 437: ptr = NULL; 438: 439: if (ptr == NULL) 1.38 cvs 440: return found; 441: 442: inf = 0; 443: while (sup >= inf && !found) 444: /* Dichotomic research */ 1.36 cvs 445: { 1.38 cvs 446: med = (sup + inf) / 2; 447: rescomp = ustrcmp (ptr[med].charName, entityName); 448: if (rescomp == 0) 449: { 450: /* entity found */ 451: *entityValue = ptr[med].charCode; 452: found = TRUE; 453: } 454: else 455: { 456: if (rescomp > 0) 457: sup = med - 1; 458: else 459: inf = med + 1; 460: } 1.36 cvs 461: } 1.38 cvs 462: return found; 463: } 1.39 cvs 464: 465: /*---------------------------------------------------------------------- 466: MapEntityByCode 467: Generic function which searchs in the Entity Mapping Table (table) 468: the entry with code entityValue and give the corresponding name. 469: Returns FALSE if entityValue is not found. 470: ----------------------------------------------------------------------*/ 1.40 cvs 471: void MapEntityByCode (int entityValue, char **entityName) 1.39 cvs 472: { 473: XmlEntity *ptr; 474: ThotBool found; 475: int i; 476: 477: /* Select the right table */ 1.40 cvs 478: ptr = XhtmlEntityTable; 479: if (ptr) 480: { 1.41 cvs 481: /* look for in the HTML entities table */ 1.40 cvs 482: found = FALSE; 1.41 cvs 483: while (ptr && !found) 484: { 485: for (i = 0; ptr[i].charCode >= 0 && !found; i++) 486: found = (ptr[i].charCode == entityValue); 1.39 cvs 487: 1.41 cvs 488: if (found) 489: { 490: /* entity value found */ 491: i--; 492: *entityName = (char *) (ptr[i].charName); 493: } 494: else if (ptr != MathEntityTable) 495: /* look for in the Math entities table */ 496: ptr = MathEntityTable; 497: else 498: { 499: *entityName = NULL; 500: ptr = NULL; 501: } 1.40 cvs 502: } 503: } 1.39 cvs 504: else 1.40 cvs 505: *entityName = NULL; 1.39 cvs 506: }