]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/mlminidom/ml_minidom.c
This commit was manufactured by cvs2svn to create branch 'start'.
[helm.git] / helm / DEVEL / mlminidom / ml_minidom.c
1 /* Copyright (C) 2000, Luca Padovani <luca.padovani@cs.unibo.it>.
2  *
3  * This file is part of mlminidom, the Ocaml binding for minidom.
4  * 
5  * mlminidom is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * mlminidom is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with mlminidom; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18  * 
19  * For details, send a mail to the author.
20  */
21
22 #include <assert.h>
23 #include <mlvalues.h>
24 #include <memory.h>
25
26 #include "minidom.h"
27
28 #define Val_ptr(p)        ((value) (p))
29 #define Val_option(p,f)   ((p != NULL) ? ml_some(f(p)) : Val_unit)
30 #define Val_mDOMString(s) (copy_string((char*) (s)))
31 #define mDOMString_val(v) ((mDOMStringRef) String_val(v))
32
33 static value
34 ml_some(value v)
35 {
36   CAMLparam1(v);
37   value ret = alloc_small(1,0);
38   Field(ret,0) = v;
39   CAMLreturn(ret);
40 }
41
42 value
43 ml_string_of_mDOMString(value s)
44 {
45   CAMLparam1(s);
46   CAMLreturn(s);
47 }
48
49 value
50 ml_mDOMString_of_string(value s)
51 {
52   CAMLparam1(s);
53   CAMLreturn(s);
54 }
55
56 value
57 ml_doc_load(value file_name)
58 {
59   mDOMDocRef doc_ref;
60
61   CAMLparam1(file_name);
62
63   doc_ref = mdom_load(String_val(file_name), FALSE, NULL);
64   if (doc_ref == NULL) failwith("minidom: could not load document");
65
66   CAMLreturn((value) doc_ref);
67 }
68
69 value
70 ml_doc_unload(value doc)
71 {
72   CAMLparam1(doc);
73
74   mdom_unload((mDOMDocRef) doc);
75
76   CAMLreturn(Val_unit);
77 }
78
79 value
80 ml_doc_new(value s)
81 {
82   mDOMDocRef doc_ref;
83
84   CAMLparam1(s);
85
86   doc_ref = mdom_doc_new(mDOMString_val(s));
87   if (doc_ref == NULL) failwith("minidom: could not create new document");
88
89   CAMLreturn((value) doc_ref);
90 }
91
92
93 value
94 ml_doc_get_root_node(value doc)
95 {
96   mDOMNodeRef root;
97
98   CAMLparam1(doc);
99   root = mdom_doc_get_root_node((mDOMDocRef) doc);
100   if (root == NULL) failwith("minidom: document has no root node!");
101
102   CAMLreturn((value) root);
103 }
104
105 value
106 ml_doc_add_entity(value doc, value name, value content)
107 {
108   mDOMEntityRef ent;
109
110   CAMLparam3(doc, name, content);
111   ent = mdom_doc_add_entity((mDOMDocRef) doc, mDOMString_val(name), mDOMString_val(content));
112   if (ent == NULL) failwith("minidom: could not add entity");
113
114   CAMLreturn((value) ent);
115 }
116
117 value
118 ml_doc_get_entity(value doc, value name)
119 {
120   mDOMEntityRef ent;
121
122   CAMLparam2(doc, name);
123   ent = mdom_doc_get_entity((mDOMDocRef) doc, mDOMString_val(name));
124
125   CAMLreturn(Val_option(ent, Val_ptr));
126 }
127
128 value
129 ml_doc_get_predefined_entity(value name)
130 {
131   mDOMEntityRef ent;
132
133   CAMLparam1(name);
134   ent = mdom_get_predefined_entity(mDOMString_val(name));
135
136   CAMLreturn(Val_option(ent, Val_ptr));
137 }
138
139 value
140 ml_entity_get_content(value ent)
141 {
142   CAMLparam1(ent);
143   CAMLreturn(Val_mDOMString(mdom_entity_get_content((mDOMEntityRef) ent)));
144 }
145
146 value
147 ml_node_is_text(value node)
148 {
149   CAMLparam1(node);
150   CAMLreturn(Val_bool(mdom_node_is_text((mDOMNodeRef) node)));
151 }
152
153 value
154 ml_node_is_element(value node)
155 {
156   CAMLparam1(node);
157   CAMLreturn(Val_bool(mdom_node_is_element((mDOMNodeRef) node)));
158 }
159
160 value
161 ml_node_is_blank(value node)
162 {
163   CAMLparam1(node);
164   CAMLreturn(Val_bool(mdom_node_is_blank((mDOMNodeRef) node)));
165 }
166
167 value
168 ml_node_is_entity_ref(value node)
169 {
170   CAMLparam1(node);
171   CAMLreturn(Val_bool(mdom_node_is_entity_ref((mDOMNodeRef) node)));
172 }
173
174 value
175 ml_node_get_type(value node)
176 {
177   CAMLparam1(node);
178   CAMLreturn(Val_int(mdom_node_get_type((mDOMNodeRef) node)));
179 }
180
181 value
182 ml_node_get_name(value node)
183 {
184   CAMLparam1(node);
185   CAMLreturn(Val_option(mdom_node_get_name((mDOMNodeRef) node), Val_mDOMString));
186 }
187
188 value
189 ml_node_get_content(value node)
190 {
191   CAMLparam1(node);
192   CAMLreturn(Val_option(mdom_node_get_content((mDOMNodeRef) node), Val_mDOMString));
193 }
194
195 value
196 ml_node_get_ns_uri(value node)
197 {
198   CAMLparam1(node);
199   CAMLreturn(Val_option(mdom_node_get_ns_uri((mDOMNodeRef) node), Val_mDOMString));
200 }
201
202 value
203 ml_node_get_attribute(value node, value name)
204 {
205   CAMLparam2(node,name);
206   CAMLreturn(Val_option(mdom_node_get_attribute((mDOMNodeRef) node, String_val(name)), Val_mDOMString));
207 }
208
209 value
210 ml_node_get_attribute_ns(value node, value name, value ns_uri)
211 {
212   CAMLparam2(node,name);
213   CAMLreturn(Val_option(mdom_node_get_attribute_ns((mDOMNodeRef) node,
214                                                    String_val(name),
215                                                    String_val(ns_uri)), Val_mDOMString));
216 }
217
218 value
219 ml_node_get_parent(value node)
220 {
221   CAMLparam1(node);
222   CAMLreturn(Val_option(mdom_node_get_parent((mDOMNodeRef) node), Val_ptr));
223 }
224
225 value
226 ml_node_get_prev_sibling(value node)
227 {
228   CAMLparam1(node);
229   CAMLreturn(Val_option(mdom_node_get_prev_sibling((mDOMNodeRef) node), Val_ptr));
230 }
231
232 value
233 ml_node_get_next_sibling(value node)
234 {
235   CAMLparam1(node);
236   CAMLreturn(Val_option(mdom_node_get_next_sibling((mDOMNodeRef) node), Val_ptr));
237 }
238
239 value
240 ml_node_get_first_child(value node)
241 {
242   CAMLparam1(node);
243   CAMLreturn(Val_option(mdom_node_get_first_child((mDOMNodeRef) node), Val_ptr));
244 }
245
246 value
247 ml_node_get_first_attribute(value node)
248 {
249   CAMLparam1(node);
250   CAMLreturn(Val_option(mdom_node_get_first_attribute((mDOMNodeRef) node), Val_ptr));
251 }
252
253 value
254 ml_node_is_first(value node)
255 {
256   CAMLparam1(node);
257   CAMLreturn(Val_bool(mdom_node_is_first((mDOMNodeRef) node)));
258 }
259
260 value
261 ml_node_is_last(value node)
262 {
263   CAMLparam1(node);
264   CAMLreturn(Val_bool(mdom_node_is_last((mDOMNodeRef) node)));
265 }
266
267 value
268 ml_attr_get_name(value attr)
269 {
270   CAMLparam1(attr);
271   CAMLreturn(Val_option(mdom_attr_get_name((mDOMAttrRef) attr), Val_mDOMString));
272 }
273
274 value
275 ml_attr_get_ns_uri(value attr)
276 {
277   CAMLparam1(attr);
278   CAMLreturn(Val_option(mdom_attr_get_ns_uri((mDOMAttrRef) attr), Val_mDOMString));
279 }
280
281 value
282 ml_attr_get_value(value attr)
283 {
284   CAMLparam1(attr);
285   CAMLreturn(Val_option(mdom_attr_get_value((mDOMAttrRef) attr), Val_mDOMString));
286 }
287
288 value
289 ml_attr_get_prev_sibling(value attr)
290 {
291   CAMLparam1(attr);
292   CAMLreturn(Val_option(mdom_attr_get_prev_sibling((mDOMAttrRef) attr), Val_ptr));
293 }
294
295 value
296 ml_attr_get_next_sibling(value attr)
297 {
298   CAMLparam1(attr);
299   CAMLreturn(Val_option(mdom_attr_get_next_sibling((mDOMAttrRef) attr), Val_ptr));
300 }
301
302 value
303 ml_attr_get_parent(value attr)
304 {
305   CAMLparam1(attr);
306   CAMLreturn(Val_option(mdom_attr_get_parent((mDOMAttrRef) attr), Val_ptr));
307 }
308