Return to fetchXMLname.c CVS log | Up to [Public] / Amaya / amaya |
1.1 cvs 1: /* 2: * 1.13 cvs 3: * (c) COPYRIGHT MIT and INRIA, 1996-2000 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: 24: /* define a pointer to let other parser functions access the local table */ 25: int HTML_ENTRIES = (sizeof(XHTMLElemMappingTable) / sizeof(ElemMapping)); 26: ElemMapping *pHTMLGIMapping = XHTMLElemMappingTable; 27: AttributeMapping *pHTMLAttributeMapping = XHTMLAttributeMappingTable; 1.14 cvs 28: 1.1 cvs 29: 30: #include "fetchXMLname_f.h" 31: 32: /*---------------------------------------------------------------------- 1.14 cvs 33: GetXHTMLSSchema returns the XHTML Thot schema for document doc. 34: ----------------------------------------------------------------------*/ 35: #ifdef __STDC__ 36: SSchema GetXHTMLSSchema (Document doc) 37: #else 38: SSchema GetXHTMLSSchema (doc) 39: Document doc; 40: 41: #endif 42: { 43: SSchema XHTMLSSchema; 44: 45: XHTMLSSchema = TtaGetSSchema (TEXT("HTML"), doc); 46: if (XHTMLSSchema == NULL) 1.17 cvs 47: XHTMLSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc), 1.14 cvs 48: TEXT("HTML"), TEXT("HTMLP")); 49: return (XHTMLSSchema); 50: } 51: 52: /*---------------------------------------------------------------------- 1.1 cvs 53: GetMathMLSSchema returns the MathML Thot schema for document doc. 54: ----------------------------------------------------------------------*/ 55: #ifdef __STDC__ 56: SSchema GetMathMLSSchema (Document doc) 57: #else 58: SSchema GetMathMLSSchema (doc) 59: Document doc; 60: 61: #endif 62: { 63: SSchema MathMLSSchema; 64: 1.13 cvs 65: MathMLSSchema = TtaGetSSchema (TEXT("MathML"), doc); 66: if (MathMLSSchema == NULL) 1.17 cvs 67: MathMLSSchema = TtaNewNature(doc, 68: TtaGetDocumentSSchema(doc), TEXT("MathML"), 1.13 cvs 69: TEXT("MathMLP")); 70: return (MathMLSSchema); 1.1 cvs 71: } 72: 73: /*---------------------------------------------------------------------- 74: GetGraphMLSSchema returns the GraphML Thot schema for document doc. 75: ----------------------------------------------------------------------*/ 76: #ifdef __STDC__ 77: SSchema GetGraphMLSSchema (Document doc) 78: #else 79: SSchema GetGraphMLSSchema (doc) 80: Document doc; 81: 82: #endif 83: { 84: SSchema GraphMLSSchema; 85: 1.8 cvs 86: GraphMLSSchema = TtaGetSSchema (TEXT("GraphML"), doc); 1.1 cvs 87: if (GraphMLSSchema == NULL) 1.17 cvs 88: GraphMLSSchema = TtaNewNature(doc, 89: TtaGetDocumentSSchema(doc), TEXT("GraphML"), 1.13 cvs 90: TEXT("GraphMLP")); 1.1 cvs 91: return (GraphMLSSchema); 92: } 93: 94: /*---------------------------------------------------------------------- 1.13 cvs 95: GetXLinkSSchema returns the XLink Thot schema for document doc. 96: ----------------------------------------------------------------------*/ 97: #ifdef __STDC__ 98: SSchema GetXLinkSSchema (Document doc) 99: #else 100: SSchema GetXLinkSSchema (doc) 101: Document doc; 102: 103: #endif 104: { 105: SSchema XLinkSSchema; 106: 107: XLinkSSchema = TtaGetSSchema (TEXT("XLink"), doc); 108: if (XLinkSSchema == NULL) 1.17 cvs 109: XLinkSSchema = TtaNewNature(doc, TtaGetDocumentSSchema(doc), TEXT("XLink"), 1.13 cvs 110: TEXT("XLinkP")); 111: return (XLinkSSchema); 112: } 113: 114: /*---------------------------------------------------------------------- 115: GetXMLSSchema returns the XML Thot schema for document doc. 1.1 cvs 116: ----------------------------------------------------------------------*/ 117: #ifdef __STDC__ 118: SSchema GetXMLSSchema (int XMLtype, Document doc) 119: #else 120: SSchema GetXMLSSchema (XMLtype, doc) 121: Document doc; 122: int XMLtype; 123: #endif 124: { 1.14 cvs 125: if (XMLtype == XHTML_TYPE) 126: return GetXHTMLSSchema (doc); 127: else if (XMLtype == MATH_TYPE) 1.13 cvs 128: return GetMathMLSSchema (doc); 129: else if (XMLtype == GRAPH_TYPE) 130: return GetGraphMLSSchema (doc); 131: else if (XMLtype == XLINK_TYPE) 1.15 cvs 132: return GetXLinkSSchema (doc); 1.13 cvs 133: else 134: return NULL; 1.1 cvs 135: } 136: 137: 138: /*---------------------------------------------------------------------- 1.22 cvs 139: MapXMLElementType 140: Generic function which searchs in the Element Mapping table, selected 141: by the parameter XMLtype, the entry XMLname and returns the corresponding 142: Thot element type. 1.1 cvs 143: Returns: 1.22 cvs 144: - ElTypeNum and ElSSchema into elType ElTypeNum = 0 if not found. 1.1 cvs 145: - content 146: ----------------------------------------------------------------------*/ 147: #ifdef __STDC__ 1.14 cvs 148: void MapXMLElementType (int XMLtype, 149: STRING XMLname, 150: ElementType *elType, 151: STRING *mappedName, 152: CHAR_T *content, 153: Document doc) 1.1 cvs 154: #else 1.14 cvs 155: void MapXMLElementType (XMLtype, 156: XMLname, 157: elType, 158: mappedName, 159: content, 160: doc) 1.6 cvs 161: int XMLtype; 1.12 cvs 162: STRING XMLname; 163: ElementType *elType; 164: STRING *mappedName; 165: CHAR_T *content; 1.6 cvs 166: Document doc; 1.1 cvs 167: #endif 168: { 169: int i; 170: ElemMapping *ptr; 171: 172: /* Select the right table */ 1.14 cvs 173: if (XMLtype == XHTML_TYPE) 174: ptr = XHTMLElemMappingTable; 175: else if (XMLtype == MATH_TYPE) 1.1 cvs 176: ptr = MathMLElemMappingTable; 177: else if (XMLtype == GRAPH_TYPE) 178: ptr = GraphMLElemMappingTable; 179: else 180: ptr = NULL; 1.16 cvs 181: *mappedName = NULL; 1.1 cvs 182: elType->ElTypeNum = 0; 183: if (ptr != NULL) 184: { 185: /* search in the ElemMappingTable */ 186: i = 0; 187: /* look for the first concerned entry in the table */ 1.22 cvs 188: while (ptr[i].XMLname[0] < XMLname[0] && ptr[i].XMLname[0] != WC_EOS) 1.1 cvs 189: i++; 1.22 cvs 190: 1.1 cvs 191: /* look at all entries starting with the right character */ 192: do 1.22 cvs 193: if (ustrcmp (ptr[i].XMLname, XMLname) || ptr[i].Level > ParsingLevel[doc]) 194: /* it's not the tag or this tag is not valid for the current parsing level */ 1.1 cvs 195: i++; 196: else 197: { 198: elType->ElTypeNum = ptr[i].ThotType; 199: if (elType->ElSSchema == NULL) 200: elType->ElSSchema = GetXMLSSchema (XMLtype, doc); 201: *mappedName = ptr[i].XMLname; 202: *content = ptr[i].XMLcontents; 203: } 204: while (elType->ElTypeNum <= 0 && ptr[i].XMLname[0] == XMLname[0]); 205: } 206: } 207: 208: 209: /*---------------------------------------------------------------------- 210: GetXMLElementName 1.22 cvs 211: Generic function which searchs in the mapping table the XML name for 212: a given Thot type. 1.1 cvs 213: ----------------------------------------------------------------------*/ 214: #ifdef __STDC__ 1.25 cvs 215: CHAR_T* GetXMLElementName (ElementType elType, Document doc) 1.1 cvs 216: #else 1.25 cvs 217: CHAR_T* GetXMLElementName (elType, doc) 1.1 cvs 218: ElementType elType; 1.25 cvs 219: Document doc; 1.1 cvs 220: #endif 221: { 1.27 cvs 222: ElemMapping *ptr; 223: STRING name; 224: int i; 225: ThotBool invalid = FALSE; 226: 227: if (elType.ElTypeNum > 0) 228: { 229: i = 0; 230: /* Select the table which matches with the element schema */ 231: name = TtaGetSSchemaName (elType.ElSSchema); 232: if (ustrcmp (TEXT("MathML"), name) == 0) 233: ptr = MathMLElemMappingTable; 234: else if (ustrcmp (TEXT("GraphML"), name) == 0) 235: ptr = GraphMLElemMappingTable; 236: else 237: ptr = XHTMLElemMappingTable; 238: 239: if (ptr) 240: do 241: { 242: if (ptr[i].ThotType == elType.ElTypeNum) 243: { 244: if (doc == 0 || ptr[i].Level <= ParsingLevel[doc]) 245: return ptr[i].XMLname; 246: else 247: invalid = TRUE; 248: } 249: i++; 250: } 251: while (ptr[i].XMLname[0] != WC_EOS); 252: } 253: if (invalid) 254: return TEXT(""); 255: else 256: return TEXT("???"); 1.22 cvs 257: } 1.25 cvs 258: 259: 1.29 ! cvs 260: ! 261: /*---------------------------------------------------------------------- ! 262: GetXMLElementName ! 263: Generic function which searchs in the mapping table if a given ! 264: Thot type is an inline character or not ! 265: ----------------------------------------------------------------------*/ ! 266: #ifdef __STDC__ ! 267: ThotBool IsXMLElementInline (Element el) ! 268: #else ! 269: ThotBool IsXMLElementInline (el) ! 270: Element el; ! 271: #endif ! 272: { ! 273: ElementType elType; ! 274: int i; ! 275: ThotBool ret = FALSE; ! 276: STRING name; ! 277: ElemMapping *ptr; ! 278: ! 279: elType = TtaGetElementType (el); ! 280: if (elType.ElTypeNum > 0) ! 281: { ! 282: i = 0; ! 283: /* Select the table which matches with the element schema */ ! 284: name = TtaGetSSchemaName (elType.ElSSchema); ! 285: if (ustrcmp (TEXT("MathML"), name) == 0) ! 286: ptr = MathMLElemMappingTable; ! 287: else if (ustrcmp (TEXT("GraphML"), name) == 0) ! 288: ptr = GraphMLElemMappingTable; ! 289: else ! 290: ptr = XHTMLElemMappingTable; ! 291: ! 292: if (ptr) ! 293: { ! 294: while (ptr[i].XMLname[0] != WC_EOS && ! 295: ptr[i].ThotType != elType.ElTypeNum) ! 296: i++; ! 297: if (ptr[i].ThotType == elType.ElTypeNum) ! 298: ret = ptr[i].Inline; ! 299: } ! 300: } ! 301: return ret; ! 302: } ! 303: ! 304: 1.22 cvs 305: /*---------------------------------------------------------------------- 1.24 cvs 306: MapXMLAttribute 1.22 cvs 307: Generic function which searchs in the Attribute Mapping Table (table) 308: the entry attrName associated to the element elementName. 1.24 cvs 309: Returns the corresponding entry or -1. 1.22 cvs 310: ----------------------------------------------------------------------*/ 311: #ifdef __STDC__ 1.24 cvs 312: int MapXMLAttribute (int XMLtype, 313: CHAR_T *attrName, 1.22 cvs 314: CHAR_T *elementName, 315: Document doc, 1.24 cvs 316: int *thotType) 1.22 cvs 317: #else 1.24 cvs 318: int MapXMLAttribute (XMLtype, 319: attrName, 1.22 cvs 320: elementName, 321: doc, 1.24 cvs 322: thotType) 323: int XMLtype; 1.22 cvs 324: CHAR_T *attrName; 325: CHAR_T *elementName; 326: Document doc; 1.24 cvs 327: int *thotType; 1.22 cvs 328: #endif 329: { 1.24 cvs 330: int i; 331: AttributeMapping *ptr; 332: 333: /* Select the right table */ 334: if (XMLtype == XHTML_TYPE) 335: ptr = XHTMLAttributeMappingTable; 336: else if (XMLtype == MATH_TYPE) 337: ptr = MathMLAttributeMappingTable; 338: else if (XMLtype == GRAPH_TYPE) 339: ptr = GraphMLAttributeMappingTable; 340: else if (XMLtype == XLINK_TYPE) 341: ptr = XLinkAttributeMappingTable; 342: else 343: ptr = NULL; 344: 345: i = 1; 346: *thotType = 0; 347: if (ptr == NULL) 348: return -1; 1.22 cvs 349: 350: /* look for the first concerned entry in the table */ 1.24 cvs 351: while (ptr[i].XMLattribute[0] < attrName[0] && ptr[i].XMLattribute[0] != WC_EOS) 1.22 cvs 352: i++; 1.24 cvs 353: while (ptr[i].XMLattribute[0] == attrName[0]) 1.22 cvs 354: { 1.24 cvs 355: if (ptr[i].Level > ParsingLevel[doc] || 356: ustrcmp (ptr[i].XMLattribute, attrName) || 357: (ptr[i].XMLelement[0] != WC_EOS && ustrcmp (ptr[i].XMLelement, elementName))) 1.22 cvs 358: i++; 359: else 1.24 cvs 360: { 361: *thotType = ptr[i].ThotAttribute; 362: return (i); 363: } 1.22 cvs 364: } 1.24 cvs 365: return (-1); 1.25 cvs 366: } 367: 368: 369: /*---------------------------------------------------------------------- 370: GetXMLElementName 371: Generic function which searchs in the mapping table the XML name for 372: a given Thot type. 373: ----------------------------------------------------------------------*/ 374: #ifdef __STDC__ 1.28 cvs 375: CHAR_T* GetXMLAttributeName (AttributeType attrType, ElementType elType, Document doc) 1.25 cvs 376: #else 1.28 cvs 377: CHAR_T* GetXMLAttributeName (attrType, elType, doc) 1.25 cvs 378: AttributeType attrType; 1.28 cvs 379: ElementType elType; 1.25 cvs 380: Document doc; 381: #endif 382: { 383: AttributeMapping *ptr; 1.28 cvs 384: STRING name, tag; 1.25 cvs 385: int i; 1.27 cvs 386: ThotBool invalid = FALSE; 1.25 cvs 387: 1.27 cvs 388: if (attrType.AttrTypeNum > 0) 389: { 1.28 cvs 390: /* get the specific element tag */ 391: if (elType.ElTypeNum > 0) 392: tag = GetXMLElementName (elType, doc); 393: else 394: tag = TEXT(""); 395: 1.27 cvs 396: i = 0; 397: /* Select the table which matches with the element schema */ 398: name = TtaGetSSchemaName (attrType.AttrSSchema); 399: if (ustrcmp (TEXT("MathML"), name) == 0) 400: ptr = MathMLAttributeMappingTable; 401: else if (ustrcmp (TEXT("GraphML"), name) == 0) 402: ptr = GraphMLAttributeMappingTable; 403: else if (ustrcmp (TEXT("XLink"), name) == 0) 404: ptr = XLinkAttributeMappingTable; 405: else 406: ptr = XHTMLAttributeMappingTable; 407: 408: if (ptr) 409: do 410: { 1.28 cvs 411: if (ptr[i].ThotAttribute == attrType.AttrTypeNum && 412: (ptr[i].XMLelement[0] == WC_EOS || 413: !ustrcmp (ptr[i].XMLelement, tag))) 1.25 cvs 414: { 1.26 cvs 415: if (doc == 0 || ptr[i].Level <= ParsingLevel[doc]) 1.25 cvs 416: return ptr[i].XMLattribute; 417: else 1.27 cvs 418: invalid = TRUE; 1.25 cvs 419: } 420: i++; 1.27 cvs 421: } 422: while (ptr[i].XMLattribute[0] != WC_EOS); 423: } 424: if (invalid) 425: return TEXT(""); 426: else 427: return TEXT("???"); 1.1 cvs 428: }