Annotation of Amaya/amaya/fetchXMLname.c, revision 1.25
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: {
222: int i;
223: ElemMapping *ptr;
224: STRING name;
225:
226: if (elType.ElTypeNum > 0)
227: {
228: i = 0;
229: /* Select the table which matches with the element schema */
230: name = TtaGetSSchemaName (elType.ElSSchema);
231: if (ustrcmp (TEXT("MathML"), name) == 0)
232: ptr = MathMLElemMappingTable;
1.4 cvs 233: else if (ustrcmp (TEXT("GraphML"), name) == 0)
1.1 cvs 234: ptr = GraphMLElemMappingTable;
1.4 cvs 235: else
1.25 ! cvs 236: ptr = XHTMLElemMappingTable;
1.1 cvs 237:
1.4 cvs 238: if (ptr)
239: do
240: {
1.25 ! cvs 241: if (ptr[i].ThotType == elType.ElTypeNum)
! 242: {
! 243: if (ptr[i].Level <= ParsingLevel[doc])
! 244: return ptr[i].XMLname;
! 245: else
! 246: return TEXT("???");
! 247: }
! 248: i++;
1.4 cvs 249: }
1.22 cvs 250: while (ptr[i].XMLname[0] != WC_EOS);
1.1 cvs 251: }
1.25 ! cvs 252: return TEXT("???");
1.22 cvs 253: }
1.25 ! cvs 254:
! 255:
1.22 cvs 256: /*----------------------------------------------------------------------
1.24 cvs 257: MapXMLAttribute
1.22 cvs 258: Generic function which searchs in the Attribute Mapping Table (table)
259: the entry attrName associated to the element elementName.
1.24 cvs 260: Returns the corresponding entry or -1.
1.22 cvs 261: ----------------------------------------------------------------------*/
262: #ifdef __STDC__
1.24 cvs 263: int MapXMLAttribute (int XMLtype,
264: CHAR_T *attrName,
1.22 cvs 265: CHAR_T *elementName,
266: Document doc,
1.24 cvs 267: int *thotType)
1.22 cvs 268: #else
1.24 cvs 269: int MapXMLAttribute (XMLtype,
270: attrName,
1.22 cvs 271: elementName,
272: doc,
1.24 cvs 273: thotType)
274: int XMLtype;
1.22 cvs 275: CHAR_T *attrName;
276: CHAR_T *elementName;
277: Document doc;
1.24 cvs 278: int *thotType;
1.22 cvs 279: #endif
280: {
1.24 cvs 281: int i;
282: AttributeMapping *ptr;
283:
284: /* Select the right table */
285: if (XMLtype == XHTML_TYPE)
286: ptr = XHTMLAttributeMappingTable;
287: else if (XMLtype == MATH_TYPE)
288: ptr = MathMLAttributeMappingTable;
289: else if (XMLtype == GRAPH_TYPE)
290: ptr = GraphMLAttributeMappingTable;
291: else if (XMLtype == XLINK_TYPE)
292: ptr = XLinkAttributeMappingTable;
293: else
294: ptr = NULL;
295:
296: i = 1;
297: *thotType = 0;
298: if (ptr == NULL)
299: return -1;
1.22 cvs 300:
301: /* look for the first concerned entry in the table */
1.24 cvs 302: while (ptr[i].XMLattribute[0] < attrName[0] && ptr[i].XMLattribute[0] != WC_EOS)
1.22 cvs 303: i++;
1.24 cvs 304: while (ptr[i].XMLattribute[0] == attrName[0])
1.22 cvs 305: {
1.24 cvs 306: if (ptr[i].Level > ParsingLevel[doc] ||
307: ustrcmp (ptr[i].XMLattribute, attrName) ||
308: (ptr[i].XMLelement[0] != WC_EOS && ustrcmp (ptr[i].XMLelement, elementName)))
1.22 cvs 309: i++;
310: else
1.24 cvs 311: {
312: *thotType = ptr[i].ThotAttribute;
313: return (i);
314: }
1.22 cvs 315: }
1.24 cvs 316: return (-1);
1.25 ! cvs 317: }
! 318:
! 319:
! 320: /*----------------------------------------------------------------------
! 321: GetXMLElementName
! 322: Generic function which searchs in the mapping table the XML name for
! 323: a given Thot type.
! 324: ----------------------------------------------------------------------*/
! 325: #ifdef __STDC__
! 326: CHAR_T* GetXMLAttributeName (AttributeType attrType, Document doc)
! 327: #else
! 328: CHAR_T* GetXMLAttributeName (attrType, doc)
! 329: AttributeType attrType;
! 330: Document doc;
! 331: #endif
! 332: {
! 333: AttributeMapping *ptr;
! 334: STRING name;
! 335: int i;
! 336:
! 337: if (attrType.AttrTypeNum > 0)
! 338: {
! 339: i = 0;
! 340: /* Select the table which matches with the element schema */
! 341: name = TtaGetSSchemaName (attrType.AttrSSchema);
! 342: if (ustrcmp (TEXT("MathML"), name) == 0)
! 343: ptr = MathMLAttributeMappingTable;
! 344: else if (ustrcmp (TEXT("GraphML"), name) == 0)
! 345: ptr = GraphMLAttributeMappingTable;
! 346: else if (ustrcmp (TEXT("XLink"), name) == 0)
! 347: ptr = XLinkAttributeMappingTable;
! 348: else
! 349: ptr = XHTMLAttributeMappingTable;
! 350:
! 351: if (ptr)
! 352: do
! 353: {
! 354: if (ptr[i].ThotAttribute == attrType.AttrTypeNum)
! 355: {
! 356: if (ptr[i].Level <= ParsingLevel[doc])
! 357: return ptr[i].XMLattribute;
! 358: else
! 359: return TEXT("???");
! 360: }
! 361: i++;
! 362: }
! 363: while (ptr[i].XMLattribute[0] != WC_EOS);
! 364: }
! 365: return TEXT("???");
1.1 cvs 366: }
Webmaster