Annotation of Amaya/amaya/fetchHTMLname.c, revision 1.23
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.21 cvs 42: for (i = 0; GI[i] != WC_EOS && i < MaxTypeNameLength-1; i++)
1.20 cvs 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.23 ! cvs 74: ThotBool isHTML;
! 75: ThotBool level;
1.1 cvs 76:
77: /* TODO: use NameSpaces to search in the right table */
78: entry = -1;
79: if (*schema == NULL)
80: {
81: isHTML = FALSE;
82: ptr = NULL;
83: }
84: else
85: {
86: ptr = TtaGetSSchemaName (*schema);
1.11 cvs 87: isHTML = !ustrcmp (ptr, TEXT("HTML"));
1.1 cvs 88: }
89:
90: i = 0;
91: if (*schema == NULL || isHTML)
92: {
93: /*
94: First convert the first char into lower case to locate
95: registered tags in the HTML mapping table.
96: Entries are registered in upper case and in alphabetic order.
97: */
98:
99: /* TODO: define a function which works on unicode */
1.12 cvs 100: c = utolower (gi[0]);
1.1 cvs 101: /* look for the first concerned entry in the table */
1.16 cvs 102: while (pHTMLGIMapping[i].XMLname[0] < c
103: && pHTMLGIMapping[i].XMLname[0] != EOS)
1.1 cvs 104: i++;
105:
106: /* look at all entries starting with the right character */
107: do
108: {
1.16 cvs 109: if (ustrcasecmp (pHTMLGIMapping[i].XMLname, gi))
1.1 cvs 110: i++;
111: else
112: entry = i;
113: }
1.16 cvs 114: while (entry < 0 && pHTMLGIMapping[i].XMLname[0] == c);
1.1 cvs 115: }
116:
117: if (entry < 0)
1.22 cvs 118: {
119: if (*schema != NULL && isHTML)
120: *schema = NULL;
121: else
122: /* not found. Look at the XML mapping tables */
123: {
124: elType.ElTypeNum = 0;
125: elType.ElSSchema = *schema;
126:
127: if (!ptr || !ustrcmp (ptr, TEXT("MathML")))
1.23 ! cvs 128: MapXMLElementType (MATH_TYPE, gi, &elType, &ptr, &c, &level, doc);
1.22 cvs 129: if (elType.ElTypeNum == 0 && (!ptr || !ustrcmp (ptr, TEXT("GraphML"))))
1.23 ! cvs 130: MapXMLElementType (GRAPH_TYPE, gi, &elType, &ptr, &c, &level, doc);
1.22 cvs 131: if (elType.ElTypeNum == 0)
132: {
133: entry = -1;
134: elType.ElSSchema = NULL;
135: *schema = NULL;
136: }
137: else
138: {
139: entry = elType.ElTypeNum;
140: *schema = elType.ElSSchema;
141: }
142: }
143: }
1.1 cvs 144: return entry;
145: }
146:
147: /*----------------------------------------------------------------------
148: GIType search in mapping tables the Element type associated with
149: a given GI Name. If not found returns zero.
150: ----------------------------------------------------------------------*/
151: #ifdef __STDC__
1.12 cvs 152: void GIType (CHAR_T* gi, ElementType *elType, Document doc)
1.1 cvs 153: #else
154: void GIType (gi, elType, doc)
1.12 cvs 155: CHAR_T* gi;
1.9 cvs 156: ElementType* elType;
157: Document doc;
1.1 cvs 158: #endif
159: {
1.12 cvs 160: CHAR_T c;
161: CHAR_T* ptr;
1.1 cvs 162: int i;
1.23 ! cvs 163: ThotBool level;
1.1 cvs 164:
165: /* TODO: use NameSpaces to search in the right table */
166: elType->ElSSchema = NULL;
167: elType->ElTypeNum = 0;
168:
169: /*
170: First convert the first char into lower case to locate
171: registered tags in the HTML mapping table.
172: Entries are registered in upper case and in alphabetic order.
173: */
174:
175: /* TODO: define a function which works on unicode */
1.12 cvs 176: c = utolower (gi[0]);
1.1 cvs 177:
178: i = 0;
179: /* look for the first concerned entry in the table */
1.16 cvs 180: while (pHTMLGIMapping[i].XMLname[0] < c &&
181: pHTMLGIMapping[i].XMLname[0] != EOS)
1.1 cvs 182: i++;
183: /* look at all entries starting with the right character */
184: do
185: {
1.16 cvs 186: if (!ustrcasecmp (pHTMLGIMapping[i].XMLname, gi))
1.4 cvs 187: {
188: if (doc != 0)
1.11 cvs 189: elType->ElSSchema = TtaGetSSchema (TEXT("HTML"), doc);
1.16 cvs 190: elType->ElTypeNum = pHTMLGIMapping[i].ThotType;
1.4 cvs 191: return;
192: }
1.1 cvs 193: i++;
194: }
1.16 cvs 195: while (pHTMLGIMapping[i].XMLname[0] == c);
1.1 cvs 196:
197: /* if not found, look at the XML mapping tables */
1.23 ! cvs 198: MapXMLElementType (MATH_TYPE, gi, elType, &ptr, &c, &level, doc);
1.1 cvs 199: if (elType->ElTypeNum == 0)
1.23 ! cvs 200: MapXMLElementType (GRAPH_TYPE, gi, elType, &ptr, &c, &level, doc);
1.4 cvs 201: }
202:
203: /*----------------------------------------------------------------------
204: MapAttr search in all AttributeMappingTables the entry for the
205: attribute of name Attr and returns a pointer to that entry,
206: as well as the corresponding Thot SSchema
207: ----------------------------------------------------------------------*/
208: #ifdef __STDC__
1.18 cvs 209: AttributeMapping *MapAttr (CHAR_T *attrName, SSchema *schema, int elemEntry, Document doc)
1.4 cvs 210: #else
1.18 cvs 211: AttributeMapping *MapAttr (attrName, schema, elemEntry, doc)
212: CHAR_T *attrName;
213: SSchema *schema;
1.4 cvs 214: int elemEntry;
215: Document doc;
216: #endif
217: {
1.20 cvs 218: typeName attr, elem;
1.18 cvs 219: int i;
1.20 cvs 220: int thotType;
221:
1.18 cvs 222: *schema = TtaGetDocumentSSchema (doc);
1.20 cvs 223: LowercaseGI (attrName, attr);
224: LowercaseGI (pHTMLGIMapping[elemEntry].XMLname, elem);
225: i = MapXMLAttribute (XHTML_TYPE, attr, elem, doc, &thotType);
226: if (i < 0)
1.18 cvs 227: /* not found */
228: return (NULL);
1.4 cvs 229: else
1.20 cvs 230: return (&(pHTMLAttributeMapping[i]));
1.4 cvs 231: }
232:
1.18 cvs 233:
1.4 cvs 234: /*----------------------------------------------------------------------
1.18 cvs 235: MapHTMLAttribute
236: Search in the Attribute Mapping Table the entry for the attribute
237: of name Attr and returns the corresponding Thot attribute type.
1.4 cvs 238: ----------------------------------------------------------------------*/
239: #ifdef __STDC__
1.18 cvs 240: AttributeMapping *MapHTMLAttribute (CHAR_T *attrName,
241: AttributeType *attrType,
242: CHAR_T *elementName,
243: Document doc)
1.4 cvs 244: #else
1.18 cvs 245: AttributeMapping *MapHTMLAttribute (attrName,
246: attrType,
247: elementName,
248: doc)
249: CHAR_T* attrName;
250: AttributeType* attrType;
251: CHAR_T* elementName;
252: Document doc;
1.4 cvs 253: #endif
254: {
1.18 cvs 255: int i;
1.4 cvs 256:
1.18 cvs 257: attrType->AttrSSchema = GetXHTMLSSchema (doc);
1.20 cvs 258: i = MapXMLAttribute (XHTML_TYPE, attrName, elementName, doc, &(attrType->AttrTypeNum));
259: if (i < 0)
260: return (NULL);
1.4 cvs 261: else
1.20 cvs 262: return (&(pHTMLAttributeMapping[i]));
1.1 cvs 263: }
1.18 cvs 264:
Webmaster