Annotation of Amaya/amaya/fetchXMLname.c, revision 1.8
1.1 cvs 1: /*
2: *
3: * (c) COPYRIGHT MIT and INRIA, 1996.
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"
19:
20: /* mapping table of MathML elements */
21: #include "MathML.h"
22: static ElemMapping MathMLElemMappingTable[] =
23: {
24: /* This table MUST be in alphabetical order */
1.6 cvs 25: {"XMLcomment", SPACE, MathML_EL_XMLcomment},
26: {"XMLcomment_line", SPACE, MathML_EL_XMLcomment_line},
27: {"maligngroup", 'E', MathML_EL_MALIGNGROUP},
28: {"malignmark", 'E', MathML_EL_MALIGNMARK},
29: {"merror", SPACE, MathML_EL_MERROR},
30: {"mf", SPACE, MathML_EL_MF}, /* for compatibility with an old version of
1.1 cvs 31: MathML: WD-math-970704 */
1.6 cvs 32: {"mfenced", SPACE, MathML_EL_MFENCED},
33: {"mfrac", SPACE, MathML_EL_MFRAC},
34: {"mi", SPACE, MathML_EL_MI},
35: {"mmultiscripts", SPACE, MathML_EL_MMULTISCRIPTS},
36: {"mn", SPACE, MathML_EL_MN},
37: {"mo", SPACE, MathML_EL_MO},
38: {"mover", SPACE, MathML_EL_MOVER},
39: {"mpadded", SPACE, MathML_EL_MPADDED},
40: {"mphantom", SPACE, MathML_EL_MPHANTOM},
41: {"mprescripts", SPACE, MathML_EL_PrescriptPairs},
42: {"mroot", SPACE, MathML_EL_MROOT},
43: {"mrow", SPACE, MathML_EL_MROW},
44: {"ms", SPACE, MathML_EL_MS},
45: {"mspace", 'E', MathML_EL_MSPACE},
46: {"msqrt", SPACE, MathML_EL_MSQRT},
47: {"mstyle", SPACE, MathML_EL_MSTYLE},
48: {"msub", SPACE, MathML_EL_MSUB},
49: {"msubsup", SPACE, MathML_EL_MSUBSUP},
50: {"msup", SPACE, MathML_EL_MSUP},
51: {"mtable", SPACE, MathML_EL_MTABLE},
52: {"mtd", SPACE, MathML_EL_MTD},
53: {"mtext", SPACE, MathML_EL_MTEXT},
54: {"mtr", SPACE, MathML_EL_MTR},
55: {"munder", SPACE, MathML_EL_MUNDER},
56: {"munderover", SPACE, MathML_EL_MUNDEROVER},
57: {"none", SPACE, MathML_EL_Construct},
58: {"sep", 'E', MathML_EL_SEP},
59: {"", SPACE, 0} /* Last entry. Mandatory */
1.1 cvs 60: };
61:
62: #ifdef GRAPHML
63: /* mapping table of GraphML elements */
64: #include "GraphML.h"
65: static ElemMapping GraphMLElemMappingTable[] =
66: {
67: /* This table MUST be in alphabetical order */
1.6 cvs 68: {"XMLcomment", SPACE, GraphML_EL_XMLcomment},
69: {"XMLcomment_line", SPACE, GraphML_EL_XMLcomment_line},
70: {"circle", SPACE, GraphML_EL_Circle},
71: {"closedspline", SPACE, GraphML_EL_ClosedSpline},
72: {"group", SPACE, GraphML_EL_Group},
73: {"label", 'X', GraphML_EL_Label}, /* see function GraphMLGetDTDName */
74: {"line", 'E', GraphML_EL_Line_},
75: {"math", 'X', GraphML_EL_Math}, /* see function GraphMLGetDTDName */
76: {"oval", SPACE, GraphML_EL_Oval},
77: {"polygon", SPACE, GraphML_EL_Polygon},
78: {"polyline", 'E', GraphML_EL_Polyline},
79: {"rect", SPACE, GraphML_EL_Rectangle},
80: {"roundrect", SPACE, GraphML_EL_RoundRect},
81: {"spline", 'E', GraphML_EL_Spline},
82: {"text", 'X', GraphML_EL_Text_}, /* see function GraphMLGetDTDName */
83: {"", SPACE, 0} /* Last entry. Mandatory */
1.1 cvs 84: };
85: #else /* GRAPHML */
86: /* there is no mapping table of GraphML elements */
87:
88: static ElemMapping *GraphMLElemMappingTable = NULL;
89: #endif /* GRAPHML */
90:
91: #include "fetchXMLname_f.h"
92:
93: /*----------------------------------------------------------------------
94: GetMathMLSSchema returns the MathML Thot schema for document doc.
95: ----------------------------------------------------------------------*/
96: #ifdef __STDC__
97: SSchema GetMathMLSSchema (Document doc)
98: #else
99: SSchema GetMathMLSSchema (doc)
100: Document doc;
101:
102: #endif
103: {
104: SSchema MathMLSSchema;
105:
1.8 ! cvs 106: MathMLSSchema = TtaGetSSchema (TEXT("MathML"), doc);
1.1 cvs 107: if (MathMLSSchema == NULL)
1.8 ! cvs 108: MathMLSSchema = TtaNewNature(TtaGetDocumentSSchema(doc), TEXT("MathML"), TEXT("MathMLP"));
1.1 cvs 109: return (MathMLSSchema);
110: }
111:
112: /*----------------------------------------------------------------------
113: GetGraphMLSSchema returns the GraphML Thot schema for document doc.
114: ----------------------------------------------------------------------*/
115: #ifdef __STDC__
116: SSchema GetGraphMLSSchema (Document doc)
117: #else
118: SSchema GetGraphMLSSchema (doc)
119: Document doc;
120:
121: #endif
122: {
123: SSchema GraphMLSSchema;
124:
1.8 ! cvs 125: GraphMLSSchema = TtaGetSSchema (TEXT("GraphML"), doc);
1.1 cvs 126: if (GraphMLSSchema == NULL)
1.8 ! cvs 127: GraphMLSSchema = TtaNewNature(TtaGetDocumentSSchema(doc), TEXT("GraphML"), TEXT("GraphMLP"));
1.1 cvs 128: return (GraphMLSSchema);
129: }
130:
131: /*----------------------------------------------------------------------
132: GetXMLSSchema returns the XMLML Thot schema for document doc.
133: ----------------------------------------------------------------------*/
134: #ifdef __STDC__
135: SSchema GetXMLSSchema (int XMLtype, Document doc)
136: #else
137: SSchema GetXMLSSchema (XMLtype, doc)
138: Document doc;
139: int XMLtype;
140: #endif
141: {
142: if (XMLtype == MATH_TYPE)
143: return GetMathMLSSchema (doc);
144: else if (XMLtype == GRAPH_TYPE)
145: return GetGraphMLSSchema (doc);
146: else
147: return NULL;
148: }
149:
150:
151: /*----------------------------------------------------------------------
152: MapXMLElementType
153: search in the mapping tables the entry for the element type of name
154: XMLname and returns the corresponding Thot element type.
155: Returns:
156: - ElTypeNum and ElSSchema inelType ElTypeNum = 0 if not found.
157: - content
158: ----------------------------------------------------------------------*/
159: #ifdef __STDC__
1.6 cvs 160: void MapXMLElementType (int XMLtype, char* XMLname, ElementType *elType, char** mappedName, char* content, Document doc)
1.1 cvs 161: #else
162: void MapXMLElementType (XMLtype, XMLname, elType, mappedName, content, doc)
1.6 cvs 163: int XMLtype;
164: char* XMLname;
165: ElementType* elType;
166: char** mappedName;
167: char* content;
168: Document doc;
1.1 cvs 169: #endif
170: {
171: int i;
172: ElemMapping *ptr;
173:
174: /* Select the right table */
175: if (XMLtype == MATH_TYPE)
176: ptr = MathMLElemMappingTable;
177: else if (XMLtype == GRAPH_TYPE)
178: ptr = GraphMLElemMappingTable;
179: else
180: ptr = NULL;
181:
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 */
188: while (ptr[i].XMLname[0] < XMLname[0] && ptr[i].XMLname[0] != EOS)
189: i++;
190: /* look at all entries starting with the right character */
191: do
1.6 cvs 192: if (strcmp (ptr[i].XMLname, XMLname))
1.1 cvs 193: i++;
194: else
195: {
196: elType->ElTypeNum = ptr[i].ThotType;
197: if (elType->ElSSchema == NULL)
198: elType->ElSSchema = GetXMLSSchema (XMLtype, doc);
199: *mappedName = ptr[i].XMLname;
200: *content = ptr[i].XMLcontents;
201: }
202: while (elType->ElTypeNum <= 0 && ptr[i].XMLname[0] == XMLname[0]);
203: }
204: }
205:
206:
207: /*----------------------------------------------------------------------
208: GetXMLElementName
209: search in the mapping tables the XML name for a given Thot type
210: ----------------------------------------------------------------------*/
211: #ifdef __STDC__
1.6 cvs 212: void GetXMLElementName (ElementType elType, char** buffer)
1.1 cvs 213: #else
214: void GetXMLElementName (elType, buffer)
215: ElementType elType;
1.6 cvs 216: char** buffer;
1.1 cvs 217: #endif
218: {
219: int i;
220: ElemMapping *ptr;
221: STRING name;
222:
223: if (elType.ElTypeNum > 0)
224: {
225: i = 0;
226: /* Select the table which matches with the element schema */
227: name = TtaGetSSchemaName (elType.ElSSchema);
228: if (ustrcmp (TEXT("MathML"), name) == 0)
229: ptr = MathMLElemMappingTable;
1.4 cvs 230: else if (ustrcmp (TEXT("GraphML"), name) == 0)
1.1 cvs 231: ptr = GraphMLElemMappingTable;
1.4 cvs 232: else
233: ptr = NULL;
1.1 cvs 234:
1.4 cvs 235: if (ptr)
236: do
237: {
1.1 cvs 238: if (ptr[i].ThotType == elType.ElTypeNum)
239: {
240: *buffer = ptr[i].XMLname;
241: return;
242: }
243: i++;
1.4 cvs 244: }
245: while (ptr[i].XMLname[0] != EOS);
1.1 cvs 246: }
247: *buffer = TEXT("???");
248: return;
249: }
Webmaster