Annotation of Amaya/amaya/fetchXMLname.c, revision 1.34
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.32 cvs 148: void MapXMLElementType (int XMLtype,
149: STRING XMLname,
150: ElementType *elType,
151: STRING *mappedName,
152: CHAR_T *content,
153: ThotBool *highEnoughLevel,
154: Document doc)
1.1 cvs 155: #else
1.32 cvs 156: void MapXMLElementType (XMLtype, XMLname, elType, mappedName,
157: content, highEnoughLevel, doc)
158: int XMLtype;
159: STRING XMLname;
160: ElementType *elType;
161: STRING *mappedName;
162: CHAR_T *content;
163: ThotBool *highEnoughLevel;
164: Document doc;
1.1 cvs 165: #endif
166: {
167: int i;
168: ElemMapping *ptr;
169:
1.32 cvs 170: /* Initialize variables */
171: *mappedName = NULL;
172: *highEnoughLevel = TRUE;
173: elType->ElTypeNum = 0;
174:
1.1 cvs 175: /* Select the right table */
1.14 cvs 176: if (XMLtype == XHTML_TYPE)
177: ptr = XHTMLElemMappingTable;
178: else if (XMLtype == MATH_TYPE)
1.31 cvs 179: {
180: if (ParsingLevel[doc] == L_Basic && DocumentTypes[doc] == docHTML)
1.32 cvs 181: {
182: /* Maths are not allowed in this document */
183: ptr = NULL;
184: *highEnoughLevel = FALSE;
185: }
1.31 cvs 186: else
187: ptr = MathMLElemMappingTable;
188: }
1.1 cvs 189: else if (XMLtype == GRAPH_TYPE)
1.31 cvs 190: {
191: if (ParsingLevel[doc] == L_Basic && DocumentTypes[doc] == docHTML)
1.32 cvs 192: {
193: /* Graphics are not allowed in this document */
194: ptr = NULL;
195: *highEnoughLevel = FALSE;
196: }
1.31 cvs 197: else
198: ptr = GraphMLElemMappingTable;
199: }
1.1 cvs 200: else
201: ptr = NULL;
1.32 cvs 202:
1.1 cvs 203: if (ptr != NULL)
204: {
205: /* search in the ElemMappingTable */
206: i = 0;
207: /* look for the first concerned entry in the table */
1.22 cvs 208: while (ptr[i].XMLname[0] < XMLname[0] && ptr[i].XMLname[0] != WC_EOS)
1.32 cvs 209: i++;
1.1 cvs 210: /* look at all entries starting with the right character */
211: do
1.32 cvs 212: if (ustrcmp (ptr[i].XMLname, XMLname))
213: /* it's not the tag */
1.1 cvs 214: i++;
1.32 cvs 215: else if (ptr[i].Level > ParsingLevel[doc])
216: {
217: /* this tag is not valid for the current parsing level */
218: *highEnoughLevel = FALSE;
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.22 cvs 236: Generic function which searchs in the mapping table the XML name for
237: a given Thot type.
1.1 cvs 238: ----------------------------------------------------------------------*/
239: #ifdef __STDC__
1.25 cvs 240: CHAR_T* GetXMLElementName (ElementType elType, Document doc)
1.1 cvs 241: #else
1.25 cvs 242: CHAR_T* GetXMLElementName (elType, doc)
1.1 cvs 243: ElementType elType;
1.25 cvs 244: Document doc;
1.1 cvs 245: #endif
246: {
1.27 cvs 247: ElemMapping *ptr;
248: STRING name;
249: int i;
250: ThotBool invalid = FALSE;
251:
252: if (elType.ElTypeNum > 0)
253: {
254: i = 0;
255: /* Select the table which matches with the element schema */
256: name = TtaGetSSchemaName (elType.ElSSchema);
257: if (ustrcmp (TEXT("MathML"), name) == 0)
258: ptr = MathMLElemMappingTable;
259: else if (ustrcmp (TEXT("GraphML"), name) == 0)
260: ptr = GraphMLElemMappingTable;
261: else
262: ptr = XHTMLElemMappingTable;
263:
264: if (ptr)
265: do
266: {
267: if (ptr[i].ThotType == elType.ElTypeNum)
268: {
269: if (doc == 0 || ptr[i].Level <= ParsingLevel[doc])
270: return ptr[i].XMLname;
271: else
272: invalid = TRUE;
273: }
274: i++;
275: }
276: while (ptr[i].XMLname[0] != WC_EOS);
277: }
278: if (invalid)
279: return TEXT("");
280: else
281: return TEXT("???");
1.22 cvs 282: }
1.25 cvs 283:
284:
1.29 cvs 285:
286: /*----------------------------------------------------------------------
1.30 cvs 287: IsXMLElementInline
1.29 cvs 288: Generic function which searchs in the mapping table if a given
289: Thot type is an inline character or not
290: ----------------------------------------------------------------------*/
291: #ifdef __STDC__
1.34 ! cvs 292: ThotBool IsXMLElementInline (ElementType elType)
1.29 cvs 293: #else
1.34 ! cvs 294: ThotBool IsXMLElementInline (elType)
! 295: ElementType el;
1.29 cvs 296: #endif
297: {
1.34 ! cvs 298: int i;
! 299: ThotBool ret = FALSE;
! 300: STRING name;
! 301: ElemMapping *ptr;
1.29 cvs 302:
303: if (elType.ElTypeNum > 0)
304: {
305: i = 0;
306: /* Select the table which matches with the element schema */
307: name = TtaGetSSchemaName (elType.ElSSchema);
308: if (ustrcmp (TEXT("MathML"), name) == 0)
309: ptr = MathMLElemMappingTable;
310: else if (ustrcmp (TEXT("GraphML"), name) == 0)
311: ptr = GraphMLElemMappingTable;
312: else
313: ptr = XHTMLElemMappingTable;
314:
315: if (ptr)
316: {
317: while (ptr[i].XMLname[0] != WC_EOS &&
318: ptr[i].ThotType != elType.ElTypeNum)
319: i++;
320: if (ptr[i].ThotType == elType.ElTypeNum)
321: ret = ptr[i].Inline;
322: }
323: }
324: return ret;
325: }
326:
327:
1.22 cvs 328: /*----------------------------------------------------------------------
1.24 cvs 329: MapXMLAttribute
1.22 cvs 330: Generic function which searchs in the Attribute Mapping Table (table)
331: the entry attrName associated to the element elementName.
1.24 cvs 332: Returns the corresponding entry or -1.
1.22 cvs 333: ----------------------------------------------------------------------*/
334: #ifdef __STDC__
1.33 cvs 335: int MapXMLAttribute (int XMLtype, CHAR_T *attrName,
336: CHAR_T *elementName, ThotBool *highEnoughLevel,
337: Document doc, int *thotType)
1.22 cvs 338: #else
1.33 cvs 339: int MapXMLAttribute (XMLtype, attrName, elementName,
340: highEnoughLevel, doc, thotType)
341: int XMLtype;
342: CHAR_T *attrName;
343: CHAR_T *elementName;
344: ThotBool *highEnoughLevel;
345: Document doc;
346: int *thotType;
1.22 cvs 347: #endif
348: {
1.24 cvs 349: int i;
350: AttributeMapping *ptr;
351:
1.33 cvs 352: /* Initialization */
353: *highEnoughLevel = TRUE;
354: i = 1;
355: *thotType = 0;
356:
1.24 cvs 357: /* Select the right table */
358: if (XMLtype == XHTML_TYPE)
359: ptr = XHTMLAttributeMappingTable;
360: else if (XMLtype == MATH_TYPE)
361: ptr = MathMLAttributeMappingTable;
362: else if (XMLtype == GRAPH_TYPE)
363: ptr = GraphMLAttributeMappingTable;
364: else if (XMLtype == XLINK_TYPE)
365: ptr = XLinkAttributeMappingTable;
366: else
367: ptr = NULL;
368:
369: if (ptr == NULL)
370: return -1;
1.22 cvs 371:
372: /* look for the first concerned entry in the table */
1.33 cvs 373: while (ptr[i].XMLattribute[0] < attrName[0] &&
374: ptr[i].XMLattribute[0] != WC_EOS)
1.22 cvs 375: i++;
1.33 cvs 376:
1.24 cvs 377: while (ptr[i].XMLattribute[0] == attrName[0])
1.22 cvs 378: {
1.33 cvs 379: if (ustrcmp (ptr[i].XMLattribute, attrName) ||
380: (ptr[i].XMLelement[0] != WC_EOS &&
381: ustrcmp (ptr[i].XMLelement, elementName)))
1.22 cvs 382: i++;
1.33 cvs 383: else if (ptr[i].Level > ParsingLevel[doc])
384: {
385: *highEnoughLevel = FALSE;
386: i++;
387: }
1.22 cvs 388: else
1.24 cvs 389: {
390: *thotType = ptr[i].ThotAttribute;
391: return (i);
392: }
1.22 cvs 393: }
1.24 cvs 394: return (-1);
1.25 cvs 395: }
396:
397:
398: /*----------------------------------------------------------------------
399: GetXMLElementName
400: Generic function which searchs in the mapping table the XML name for
401: a given Thot type.
402: ----------------------------------------------------------------------*/
403: #ifdef __STDC__
1.28 cvs 404: CHAR_T* GetXMLAttributeName (AttributeType attrType, ElementType elType, Document doc)
1.25 cvs 405: #else
1.28 cvs 406: CHAR_T* GetXMLAttributeName (attrType, elType, doc)
1.25 cvs 407: AttributeType attrType;
1.28 cvs 408: ElementType elType;
1.25 cvs 409: Document doc;
410: #endif
411: {
412: AttributeMapping *ptr;
1.28 cvs 413: STRING name, tag;
1.25 cvs 414: int i;
1.27 cvs 415: ThotBool invalid = FALSE;
1.25 cvs 416:
1.27 cvs 417: if (attrType.AttrTypeNum > 0)
418: {
1.28 cvs 419: /* get the specific element tag */
420: if (elType.ElTypeNum > 0)
421: tag = GetXMLElementName (elType, doc);
422: else
423: tag = TEXT("");
424:
1.27 cvs 425: i = 0;
426: /* Select the table which matches with the element schema */
427: name = TtaGetSSchemaName (attrType.AttrSSchema);
428: if (ustrcmp (TEXT("MathML"), name) == 0)
429: ptr = MathMLAttributeMappingTable;
430: else if (ustrcmp (TEXT("GraphML"), name) == 0)
431: ptr = GraphMLAttributeMappingTable;
432: else if (ustrcmp (TEXT("XLink"), name) == 0)
433: ptr = XLinkAttributeMappingTable;
434: else
435: ptr = XHTMLAttributeMappingTable;
436:
437: if (ptr)
438: do
439: {
1.28 cvs 440: if (ptr[i].ThotAttribute == attrType.AttrTypeNum &&
441: (ptr[i].XMLelement[0] == WC_EOS ||
442: !ustrcmp (ptr[i].XMLelement, tag)))
1.25 cvs 443: {
1.26 cvs 444: if (doc == 0 || ptr[i].Level <= ParsingLevel[doc])
1.25 cvs 445: return ptr[i].XMLattribute;
446: else
1.27 cvs 447: invalid = TRUE;
1.25 cvs 448: }
449: i++;
1.27 cvs 450: }
451: while (ptr[i].XMLattribute[0] != WC_EOS);
452: }
453: if (invalid)
454: return TEXT("");
455: else
456: return TEXT("???");
1.1 cvs 457: }
Webmaster