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