Annotation of Amaya/amaya/fetchXMLname.c, revision 1.27
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.22 cvs 260: /*----------------------------------------------------------------------
1.24 cvs 261: MapXMLAttribute
1.22 cvs 262: Generic function which searchs in the Attribute Mapping Table (table)
263: the entry attrName associated to the element elementName.
1.24 cvs 264: Returns the corresponding entry or -1.
1.22 cvs 265: ----------------------------------------------------------------------*/
266: #ifdef __STDC__
1.24 cvs 267: int MapXMLAttribute (int XMLtype,
268: CHAR_T *attrName,
1.22 cvs 269: CHAR_T *elementName,
270: Document doc,
1.24 cvs 271: int *thotType)
1.22 cvs 272: #else
1.24 cvs 273: int MapXMLAttribute (XMLtype,
274: attrName,
1.22 cvs 275: elementName,
276: doc,
1.24 cvs 277: thotType)
278: int XMLtype;
1.22 cvs 279: CHAR_T *attrName;
280: CHAR_T *elementName;
281: Document doc;
1.24 cvs 282: int *thotType;
1.22 cvs 283: #endif
284: {
1.24 cvs 285: int i;
286: AttributeMapping *ptr;
287:
288: /* Select the right table */
289: if (XMLtype == XHTML_TYPE)
290: ptr = XHTMLAttributeMappingTable;
291: else if (XMLtype == MATH_TYPE)
292: ptr = MathMLAttributeMappingTable;
293: else if (XMLtype == GRAPH_TYPE)
294: ptr = GraphMLAttributeMappingTable;
295: else if (XMLtype == XLINK_TYPE)
296: ptr = XLinkAttributeMappingTable;
297: else
298: ptr = NULL;
299:
300: i = 1;
301: *thotType = 0;
302: if (ptr == NULL)
303: return -1;
1.22 cvs 304:
305: /* look for the first concerned entry in the table */
1.24 cvs 306: while (ptr[i].XMLattribute[0] < attrName[0] && ptr[i].XMLattribute[0] != WC_EOS)
1.22 cvs 307: i++;
1.24 cvs 308: while (ptr[i].XMLattribute[0] == attrName[0])
1.22 cvs 309: {
1.24 cvs 310: if (ptr[i].Level > ParsingLevel[doc] ||
311: ustrcmp (ptr[i].XMLattribute, attrName) ||
312: (ptr[i].XMLelement[0] != WC_EOS && ustrcmp (ptr[i].XMLelement, elementName)))
1.22 cvs 313: i++;
314: else
1.24 cvs 315: {
316: *thotType = ptr[i].ThotAttribute;
317: return (i);
318: }
1.22 cvs 319: }
1.24 cvs 320: return (-1);
1.25 cvs 321: }
322:
323:
324: /*----------------------------------------------------------------------
325: GetXMLElementName
326: Generic function which searchs in the mapping table the XML name for
327: a given Thot type.
328: ----------------------------------------------------------------------*/
329: #ifdef __STDC__
330: CHAR_T* GetXMLAttributeName (AttributeType attrType, Document doc)
331: #else
332: CHAR_T* GetXMLAttributeName (attrType, doc)
333: AttributeType attrType;
334: Document doc;
335: #endif
336: {
337: AttributeMapping *ptr;
338: STRING name;
339: int i;
1.27 ! cvs 340: ThotBool invalid = FALSE;
1.25 cvs 341:
1.27 ! cvs 342: if (attrType.AttrTypeNum > 0)
! 343: {
! 344: i = 0;
! 345: /* Select the table which matches with the element schema */
! 346: name = TtaGetSSchemaName (attrType.AttrSSchema);
! 347: if (ustrcmp (TEXT("MathML"), name) == 0)
! 348: ptr = MathMLAttributeMappingTable;
! 349: else if (ustrcmp (TEXT("GraphML"), name) == 0)
! 350: ptr = GraphMLAttributeMappingTable;
! 351: else if (ustrcmp (TEXT("XLink"), name) == 0)
! 352: ptr = XLinkAttributeMappingTable;
! 353: else
! 354: ptr = XHTMLAttributeMappingTable;
! 355:
! 356: if (ptr)
! 357: do
! 358: {
1.25 cvs 359: if (ptr[i].ThotAttribute == attrType.AttrTypeNum)
360: {
1.26 cvs 361: if (doc == 0 || ptr[i].Level <= ParsingLevel[doc])
1.25 cvs 362: return ptr[i].XMLattribute;
363: else
1.27 ! cvs 364: invalid = TRUE;
1.25 cvs 365: }
366: i++;
1.27 ! cvs 367: }
! 368: while (ptr[i].XMLattribute[0] != WC_EOS);
! 369: }
! 370: if (invalid)
! 371: return TEXT("");
! 372: else
! 373: return TEXT("???");
1.1 cvs 374: }
Webmaster