Return to fetchHTMLname.c CVS log | Up to [Public] / Amaya / amaya |
1.1 cvs 1: /* 2: * 1.15 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: * fetchHTMLname 11: * 12: * Author: I. Vatton 13: * 14: */ 1.13 cvs 15: 1.1 cvs 16: /* This module is used by the html2thot parser and the css parser. */ 17: 1.2 cvs 18: #define THOT_EXPORT 1.1 cvs 19: #include "amaya.h" 20: #include "fetchHTMLname.h" 21: #include "parser.h" 22: 1.3 cvs 23: #include "fetchHTMLname_f.h" 24: #include "fetchXMLname_f.h" 25: 1.20 ! cvs 26: ! 27: /*---------------------------------------------------------------------- ! 28: LowercaseGI converts uppercases into lovercases ! 29: GI is the input string ! 30: gi is the output string ! 31: ----------------------------------------------------------------------*/ ! 32: #ifdef __STDC__ ! 33: static void LowercaseGI (CHAR_T *GI, CHAR_T *gi) ! 34: #else ! 35: static void LowercaseGI (GI, gi) ! 36: CHAR_T *GI; ! 37: CHAR_T *gi; ! 38: #endif 1.4 cvs 39: { 1.20 ! cvs 40: int i; 1.1 cvs 41: 1.20 ! cvs 42: for (i = 0; GI[i] != WC_EOS; i++) ! 43: { ! 44: if (GI[i] >= TEXT('A') && GI[i] <= TEXT('Z')) ! 45: gi[i] = (CHAR_T) ((int) GI[i] + 32); ! 46: else ! 47: gi[i] = GI[i]; ! 48: } ! 49: gi[i] = WC_EOS; ! 50: } 1.4 cvs 51: 1.1 cvs 52: 53: /*---------------------------------------------------------------------- 54: MapGI 55: search in the mapping tables the entry for the element of 56: name GI and returns the rank of that entry. 57: When returning, schema contains the Thot SSchema that defines that element, 58: Returns -1 and schema = NULL if not found. 59: ----------------------------------------------------------------------*/ 60: #ifdef __STDC__ 1.20 ! cvs 61: int MapGI (CHAR_T *gi, SSchema *schema, Document doc) 1.1 cvs 62: #else 63: int MapGI (gi, schema, doc) 1.12 cvs 64: CHAR_T* gi; 1.9 cvs 65: SSchema* schema; 1.1 cvs 66: Document doc; 67: #endif 68: { 1.9 cvs 69: ElementType elType; 1.11 cvs 70: CHAR_T* ptr; 1.12 cvs 71: CHAR_T c; 1.9 cvs 72: int i; 73: int entry; 1.14 cvs 74: ThotBool isHTML; 1.1 cvs 75: 76: /* TODO: use NameSpaces to search in the right table */ 77: entry = -1; 78: if (*schema == NULL) 79: { 80: isHTML = FALSE; 81: ptr = NULL; 82: } 83: else 84: { 85: ptr = TtaGetSSchemaName (*schema); 1.11 cvs 86: isHTML = !ustrcmp (ptr, TEXT("HTML")); 1.1 cvs 87: } 88: 89: i = 0; 90: if (*schema == NULL || isHTML) 91: { 92: /* 93: First convert the first char into lower case to locate 94: registered tags in the HTML mapping table. 95: Entries are registered in upper case and in alphabetic order. 96: */ 97: 98: /* TODO: define a function which works on unicode */ 1.12 cvs 99: c = utolower (gi[0]); 1.1 cvs 100: /* look for the first concerned entry in the table */ 1.16 cvs 101: while (pHTMLGIMapping[i].XMLname[0] < c 102: && pHTMLGIMapping[i].XMLname[0] != EOS) 1.1 cvs 103: i++; 104: 105: /* look at all entries starting with the right character */ 106: do 107: { 1.16 cvs 108: if (ustrcasecmp (pHTMLGIMapping[i].XMLname, gi)) 1.1 cvs 109: i++; 110: else 111: entry = i; 112: } 1.16 cvs 113: while (entry < 0 && pHTMLGIMapping[i].XMLname[0] == c); 1.1 cvs 114: } 115: 116: if (entry < 0) 117: if (*schema != NULL && isHTML) 118: *schema = NULL; 119: else 120: /* not found. Look at the XML mapping tables */ 121: { 122: elType.ElTypeNum = 0; 123: elType.ElSSchema = *schema; 124: 1.11 cvs 125: if (!ptr || !ustrcmp (ptr, TEXT("MathML"))) 1.1 cvs 126: MapXMLElementType (MATH_TYPE, gi, &elType, &ptr, &c, doc); 1.11 cvs 127: if (elType.ElTypeNum == 0 && (!ptr || !ustrcmp (ptr, TEXT("GraphML")))) 1.1 cvs 128: MapXMLElementType (GRAPH_TYPE, gi, &elType, &ptr, &c, doc); 129: if (elType.ElTypeNum == 0) 130: { 131: entry = -1; 132: elType.ElSSchema = NULL; 133: *schema = NULL; 134: } 135: else 136: { 137: entry = elType.ElTypeNum; 138: *schema = elType.ElSSchema; 139: } 140: } 141: return entry; 142: } 143: 144: /*---------------------------------------------------------------------- 145: GIType search in mapping tables the Element type associated with 146: a given GI Name. If not found returns zero. 147: ----------------------------------------------------------------------*/ 148: #ifdef __STDC__ 1.12 cvs 149: void GIType (CHAR_T* gi, ElementType *elType, Document doc) 1.1 cvs 150: #else 151: void GIType (gi, elType, doc) 1.12 cvs 152: CHAR_T* gi; 1.9 cvs 153: ElementType* elType; 154: Document doc; 1.1 cvs 155: #endif 156: { 1.12 cvs 157: CHAR_T c; 158: CHAR_T* ptr; 1.1 cvs 159: int i; 160: 161: /* TODO: use NameSpaces to search in the right table */ 162: elType->ElSSchema = NULL; 163: elType->ElTypeNum = 0; 164: 165: /* 166: First convert the first char into lower case to locate 167: registered tags in the HTML mapping table. 168: Entries are registered in upper case and in alphabetic order. 169: */ 170: 171: /* TODO: define a function which works on unicode */ 1.12 cvs 172: c = utolower (gi[0]); 1.1 cvs 173: 174: i = 0; 175: /* look for the first concerned entry in the table */ 1.16 cvs 176: while (pHTMLGIMapping[i].XMLname[0] < c && 177: pHTMLGIMapping[i].XMLname[0] != EOS) 1.1 cvs 178: i++; 179: /* look at all entries starting with the right character */ 180: do 181: { 1.16 cvs 182: if (!ustrcasecmp (pHTMLGIMapping[i].XMLname, gi)) 1.4 cvs 183: { 184: if (doc != 0) 1.11 cvs 185: elType->ElSSchema = TtaGetSSchema (TEXT("HTML"), doc); 1.16 cvs 186: elType->ElTypeNum = pHTMLGIMapping[i].ThotType; 1.4 cvs 187: return; 188: } 1.1 cvs 189: i++; 190: } 1.16 cvs 191: while (pHTMLGIMapping[i].XMLname[0] == c); 1.1 cvs 192: 193: /* if not found, look at the XML mapping tables */ 194: MapXMLElementType (MATH_TYPE, gi, elType, &ptr, &c, doc); 195: if (elType->ElTypeNum == 0) 1.4 cvs 196: MapXMLElementType (GRAPH_TYPE, gi, elType, &ptr, &c, doc); 197: } 198: 199: /*---------------------------------------------------------------------- 200: MapAttr search in all AttributeMappingTables the entry for the 201: attribute of name Attr and returns a pointer to that entry, 202: as well as the corresponding Thot SSchema 203: ----------------------------------------------------------------------*/ 204: #ifdef __STDC__ 1.18 cvs 205: AttributeMapping *MapAttr (CHAR_T *attrName, SSchema *schema, int elemEntry, Document doc) 1.4 cvs 206: #else 1.18 cvs 207: AttributeMapping *MapAttr (attrName, schema, elemEntry, doc) 208: CHAR_T *attrName; 209: SSchema *schema; 1.4 cvs 210: int elemEntry; 211: Document doc; 212: #endif 213: { 1.20 ! cvs 214: typeName attr, elem; 1.18 cvs 215: int i; 1.20 ! cvs 216: int thotType; ! 217: 1.18 cvs 218: *schema = TtaGetDocumentSSchema (doc); 1.20 ! cvs 219: LowercaseGI (attrName, attr); ! 220: LowercaseGI (pHTMLGIMapping[elemEntry].XMLname, elem); ! 221: i = MapXMLAttribute (XHTML_TYPE, attr, elem, doc, &thotType); ! 222: if (i < 0) 1.18 cvs 223: /* not found */ 224: return (NULL); 1.4 cvs 225: else 1.20 ! cvs 226: return (&(pHTMLAttributeMapping[i])); 1.4 cvs 227: } 228: 1.18 cvs 229: 1.4 cvs 230: /*---------------------------------------------------------------------- 1.18 cvs 231: MapHTMLAttribute 232: Search in the Attribute Mapping Table the entry for the attribute 233: of name Attr and returns the corresponding Thot attribute type. 1.4 cvs 234: ----------------------------------------------------------------------*/ 235: #ifdef __STDC__ 1.18 cvs 236: AttributeMapping *MapHTMLAttribute (CHAR_T *attrName, 237: AttributeType *attrType, 238: CHAR_T *elementName, 239: Document doc) 1.4 cvs 240: #else 1.18 cvs 241: AttributeMapping *MapHTMLAttribute (attrName, 242: attrType, 243: elementName, 244: doc) 245: CHAR_T* attrName; 246: AttributeType* attrType; 247: CHAR_T* elementName; 248: Document doc; 1.4 cvs 249: #endif 250: { 1.18 cvs 251: int i; 1.4 cvs 252: 1.18 cvs 253: attrType->AttrSSchema = GetXHTMLSSchema (doc); 1.20 ! cvs 254: i = MapXMLAttribute (XHTML_TYPE, attrName, elementName, doc, &(attrType->AttrTypeNum)); ! 255: if (i < 0) ! 256: return (NULL); 1.4 cvs 257: else 1.20 ! cvs 258: return (&(pHTMLAttributeMapping[i])); 1.1 cvs 259: } 1.18 cvs 260: