]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/lablgtk_gtkmathview/lablgtk-20000829_gtkmathview-0.2.0/minidom/ml_minidom.c
- the mathql interpreter is not helm-dependent any more
[helm.git] / helm / DEVEL / lablgtk_gtkmathview / lablgtk-20000829_gtkmathview-0.2.0 / minidom / ml_minidom.c
1
2 #include <assert.h>
3 #include <mlvalues.h>
4 #include <memory.h>
5
6 #include "minidom.h"
7
8 #define Val_ptr(p)        ((value) (p))
9 #define Val_option(p,f)   ((p != NULL) ? ml_some(f(p)) : Val_unit)
10 #define Val_mDOMString(s) (copy_string((char*) (s)))
11 #define mDOMString_val(v) ((mDOMStringRef) String_val(v))
12
13 static value
14 ml_some(value v)
15 {
16   CAMLparam1(v);
17   value ret = alloc_small(1,0);
18   Field(ret,0) = v;
19   CAMLreturn(ret);
20 }
21
22 value
23 ml_string_of_mDOMString(value s)
24 {
25   CAMLparam1(s);
26   CAMLreturn(s);
27 }
28
29 value
30 ml_mDOMString_of_string(value s)
31 {
32   CAMLparam1(s);
33   CAMLreturn(s);
34 }
35
36 value
37 ml_doc_load(value file_name)
38 {
39   mDOMDocRef doc_ref;
40
41   CAMLparam1(file_name);
42
43   doc_ref = mdom_load(String_val(file_name), FALSE, NULL);
44   if (doc_ref == NULL) failwith("minidom: could not load document");
45
46   CAMLreturn((value) doc_ref);
47 }
48
49 value
50 ml_doc_unload(value doc)
51 {
52   CAMLparam1(doc);
53
54   mdom_unload((mDOMDocRef) doc);
55
56   CAMLreturn(Val_unit);
57 }
58
59 value
60 ml_doc_new(value s)
61 {
62   mDOMDocRef doc_ref;
63
64   CAMLparam1(s);
65
66   doc_ref = mdom_doc_new(mDOMString_val(s));
67   if (doc_ref == NULL) failwith("minidom: could not create new document");
68
69   CAMLreturn((value) doc_ref);
70 }
71
72
73 value
74 ml_doc_get_root_node(value doc)
75 {
76   mDOMNodeRef root;
77
78   CAMLparam1(doc);
79   root = mdom_doc_get_root_node((mDOMDocRef) doc);
80   if (root == NULL) failwith("minidom: document has no root node!");
81
82   CAMLreturn((value) root);
83 }
84
85 value
86 ml_doc_add_entity(value doc, value name, value content)
87 {
88   mDOMEntityRef ent;
89
90   CAMLparam3(doc, name, content);
91   ent = mdom_doc_add_entity((mDOMDocRef) doc, mDOMString_val(name), mDOMString_val(content));
92   if (ent == NULL) failwith("minidom: could not add entity");
93
94   CAMLreturn((value) ent);
95 }
96
97 value
98 ml_doc_get_entity(value doc, value name)
99 {
100   mDOMEntityRef ent;
101
102   CAMLparam2(doc, name);
103   ent = mdom_doc_get_entity((mDOMDocRef) doc, mDOMString_val(name));
104
105   CAMLreturn(Val_option(ent, Val_ptr));
106 }
107
108 value
109 ml_doc_get_predefined_entity(value name)
110 {
111   mDOMEntityRef ent;
112
113   CAMLparam1(name);
114   ent = mdom_get_predefined_entity(mDOMString_val(name));
115
116   CAMLreturn(Val_option(ent, Val_ptr));
117 }
118
119 value
120 ml_entity_get_content(value ent)
121 {
122   CAMLparam1(ent);
123   CAMLreturn(Val_mDOMString(mdom_entity_get_content((mDOMEntityRef) ent)));
124 }
125
126 value
127 ml_node_is_text(value node)
128 {
129   CAMLparam1(node);
130   CAMLreturn(Val_bool(mdom_node_is_text((mDOMNodeRef) node)));
131 }
132
133 value
134 ml_node_is_element(value node)
135 {
136   CAMLparam1(node);
137   CAMLreturn(Val_bool(mdom_node_is_element((mDOMNodeRef) node)));
138 }
139
140 value
141 ml_node_is_blank(value node)
142 {
143   CAMLparam1(node);
144   CAMLreturn(Val_bool(mdom_node_is_blank((mDOMNodeRef) node)));
145 }
146
147 value
148 ml_node_is_entity_ref(value node)
149 {
150   CAMLparam1(node);
151   CAMLreturn(Val_bool(mdom_node_is_entity_ref((mDOMNodeRef) node)));
152 }
153
154 value
155 ml_node_get_type(value node)
156 {
157   CAMLparam1(node);
158   CAMLreturn(Val_int(mdom_node_get_type((mDOMNodeRef) node)));
159 }
160
161 value
162 ml_node_get_name(value node)
163 {
164   CAMLparam1(node);
165   CAMLreturn(Val_option(mdom_node_get_name((mDOMNodeRef) node), Val_mDOMString));
166 }
167
168 value
169 ml_node_get_content(value node)
170 {
171   CAMLparam1(node);
172   CAMLreturn(Val_option(mdom_node_get_content((mDOMNodeRef) node), Val_mDOMString));
173 }
174
175 value
176 ml_node_get_ns_uri(value node)
177 {
178   CAMLparam1(node);
179   CAMLreturn(Val_option(mdom_node_get_ns_uri((mDOMNodeRef) node), Val_mDOMString));
180 }
181
182 value
183 ml_node_get_attribute(value node, value name)
184 {
185   CAMLparam2(node,name);
186   CAMLreturn(Val_option(mdom_node_get_attribute((mDOMNodeRef) node, String_val(name)), Val_mDOMString));
187 }
188
189 value
190 ml_node_get_attribute_ns(value node, value name, value ns_uri)
191 {
192   CAMLparam2(node,name);
193   CAMLreturn(Val_option(mdom_node_get_attribute_ns((mDOMNodeRef) node,
194                                                    String_val(name),
195                                                    String_val(ns_uri)), Val_mDOMString));
196 }
197
198 value
199 ml_node_get_parent(value node)
200 {
201   CAMLparam1(node);
202   CAMLreturn(Val_option(mdom_node_get_parent((mDOMNodeRef) node), Val_ptr));
203 }
204
205 value
206 ml_node_get_prev_sibling(value node)
207 {
208   CAMLparam1(node);
209   CAMLreturn(Val_option(mdom_node_get_prev_sibling((mDOMNodeRef) node), Val_ptr));
210 }
211
212 value
213 ml_node_get_next_sibling(value node)
214 {
215   CAMLparam1(node);
216   CAMLreturn(Val_option(mdom_node_get_next_sibling((mDOMNodeRef) node), Val_ptr));
217 }
218
219 value
220 ml_node_get_first_child(value node)
221 {
222   CAMLparam1(node);
223   CAMLreturn(Val_option(mdom_node_get_first_child((mDOMNodeRef) node), Val_ptr));
224 }
225
226 value
227 ml_node_get_first_attribute(value node)
228 {
229   CAMLparam1(node);
230   CAMLreturn(Val_option(mdom_node_get_first_attribute((mDOMNodeRef) node), Val_ptr));
231 }
232
233 value
234 ml_node_is_first(value node)
235 {
236   CAMLparam1(node);
237   CAMLreturn(Val_bool(mdom_node_is_first((mDOMNodeRef) node)));
238 }
239
240 value
241 ml_node_is_last(value node)
242 {
243   CAMLparam1(node);
244   CAMLreturn(Val_bool(mdom_node_is_last((mDOMNodeRef) node)));
245 }
246
247 value
248 ml_attr_get_name(value attr)
249 {
250   CAMLparam1(attr);
251   CAMLreturn(Val_option(mdom_attr_get_name((mDOMAttrRef) attr), Val_mDOMString));
252 }
253
254 value
255 ml_attr_get_ns_uri(value attr)
256 {
257   CAMLparam1(attr);
258   CAMLreturn(Val_option(mdom_attr_get_ns_uri((mDOMAttrRef) attr), Val_mDOMString));
259 }
260
261 value
262 ml_attr_get_value(value attr)
263 {
264   CAMLparam1(attr);
265   CAMLreturn(Val_option(mdom_attr_get_value((mDOMAttrRef) attr), Val_mDOMString));
266 }
267
268 value
269 ml_attr_get_prev_sibling(value attr)
270 {
271   CAMLparam1(attr);
272   CAMLreturn(Val_option(mdom_attr_get_prev_sibling((mDOMAttrRef) attr), Val_ptr));
273 }
274
275 value
276 ml_attr_get_next_sibling(value attr)
277 {
278   CAMLparam1(attr);
279   CAMLreturn(Val_option(mdom_attr_get_next_sibling((mDOMAttrRef) attr), Val_ptr));
280 }
281
282 value
283 ml_attr_get_parent(value attr)
284 {
285   CAMLparam1(attr);
286   CAMLreturn(Val_option(mdom_attr_get_parent((mDOMAttrRef) attr), Val_ptr));
287 }
288