point and padding became redundant.. do remove padding type from xsd and use point...
[dana/openbox.git] / tools / themetoxml / themetoxml.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3    themetoxml.c for the Openbox window manager
4    Copyright (c) 2007        Dana Jansens
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    See the COPYING file for a copy of the GNU General Public License.
17 */
18
19 #include "rgb.h"
20
21 #include <X11/Xlib.h>
22 #include <X11/Xresource.h>
23 #include <glib.h>
24 #include <libxml/parser.h>
25 #include <unistd.h>
26 #include <ctype.h>
27 #include <string.h>
28
29 static gboolean read_int(XrmDatabase db, gchar *rname, gint *value);
30 static gboolean read_string(XrmDatabase db, gchar *rname, gchar **value);
31 static gboolean read_color(XrmDatabase db, gchar *rname,
32                            gint *r, gint *g, gint *b);
33
34 static int parse_inline_number(char *p)
35 {
36     int neg = 1;
37     int res = 0;
38     if (*p == '-') {
39         neg = -1;
40         ++p;
41     }
42     for (; isdigit(*p); ++p)
43         res = res * 10 + *p - '0';
44     res *= neg;
45     return res;
46 }
47
48 static gchar *create_class_name(gchar *rname)
49 {
50     gchar *rclass = g_strdup(rname);
51     gchar *p = rclass;
52
53     while (TRUE) {
54         *p = toupper(*p);
55         p = strchr(p+1, '.');
56         if (p == NULL) break;
57         ++p;
58         if (*p == '\0') break;
59     }
60     return rclass;
61 }
62
63 static gboolean read_int(XrmDatabase db, gchar *rname, gint *value)
64 {
65     gboolean ret = FALSE;
66     gchar *rclass = create_class_name(rname);
67     gchar *rettype, *end;
68     XrmValue retvalue;
69   
70     if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
71         retvalue.addr != NULL) {
72         *value = (gint)strtol(retvalue.addr, &end, 10);
73         if (end != retvalue.addr)
74             ret = TRUE;
75     }
76
77     g_free(rclass);
78     return ret;
79 }
80
81 static gboolean read_string(XrmDatabase db, gchar *rname, gchar **value)
82 {
83     gboolean ret = FALSE;
84     gchar *rclass = create_class_name(rname);
85     gchar *rettype;
86     XrmValue retvalue;
87   
88     if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
89         retvalue.addr != NULL) {
90         *value = retvalue.addr;
91         g_strstrip(*value);
92         ret = TRUE;
93     }
94
95     g_free(rclass);
96     return ret;
97 }
98
99 static gchar hextodec(gchar h)
100 {
101     if (h >= '0' && h <= '9') return h - '0';
102     else if (h >= 'a' && h <= 'f') return h - 'a' + 10;
103     else if (h >= 'A' && h <= 'F') return h - 'A' + 10;
104     return -1;
105 }
106
107 static gboolean parse_color(gchar *c, gint *r, gint *g, gint *b)
108 {
109     int dig1, dig2, i, color[3];
110     int len = strlen(c);
111
112     if (len > 4 && c[0] == 'r' && c[1] == 'g' && c[2] == 'b' && c[3] == ':') {
113         c += 4;
114         for (i = 0; i < 3; ++i) {
115             dig1 = hextodec(c[0]);
116             if (c[1] == '/') { dig2 = dig1; c+=2; }
117             else { dig2 = hextodec(c[1]); c+=3; }
118
119             if (dig1 < 0 || dig2 < 0) return FALSE;
120             
121             color[i] = dig1*16 + dig2;
122         }
123         *r = color[0]; *g = color[1]; *b = color[2];
124         return TRUE;
125     } else if ((len == 4 || len == 7) && c[0] == '#') {
126         c++;
127         for (i = 0; i < 3; ++i) {
128             dig1 = hextodec(c[0]);
129             if (len == 4) { dig2 = dig1; c++; }
130             else { dig2 = hextodec(c[1]); c+=2; }
131
132             if (dig1 < 0 || dig2 < 0) return FALSE;
133             
134             color[i] = dig1*16 + dig2;
135         }
136         *r = color[0]; *g = color[1]; *b = color[2];
137         return TRUE;
138     } else {
139         int i;
140
141         for (i = 0; colornames[i].name != NULL; ++i) {
142             if (!strcmp(colornames[i].name, c)) {
143                 *r = colornames[i].r;
144                 *g = colornames[i].g;
145                 *b = colornames[i].b;
146                 return TRUE;
147             }
148         }
149     }
150     return FALSE;
151 }
152
153 static gboolean read_color(XrmDatabase db, gchar *rname,
154                            gint *r, gint *g, gint *b)
155 {
156     gboolean ret = FALSE;
157     gchar *rclass = create_class_name(rname);
158     gchar *rettype;
159     XrmValue retvalue;
160   
161     if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) &&
162         retvalue.addr != NULL) {
163         ret = parse_color(retvalue.addr, r, g, b);
164     }
165
166     g_free(rclass);
167     return ret;
168 }
169
170 xmlNodePtr go(xmlNodePtr node, const char *s)
171 {
172     xmlNodePtr p;
173
174     for (p = node->children; p; p = p->next) {
175         if (!xmlStrcasecmp(p->name, (const xmlChar*) s))
176             return p;
177     }
178     return xmlAddChild(node, xmlNewNode(NULL, (const xmlChar*) s));
179 }
180
181 static gchar number[20];
182 static inline gchar* NUM(int i) {
183     g_snprintf(number, 20, "%d", i); return number;
184 }
185 static xmlDocPtr doc;
186 static xmlNodePtr root;
187
188 #define GO1(a) (go(root, a))
189 #define GO2(a,b) (go(GO1(a), b))
190 #define GO3(a,b,c) (go(GO2(a, b), c))
191 #define GO4(a,b,c,d) (go(GO3(a, b, c), d))
192 #define GO5(a,b,c,d,e) (go(GO4(a, b, c, d), e))
193 #define GO6(a,b,c,d,e,f) (go(GO5(a, b, c, d, e), f))
194 #define GO7(a,b,c,d,e,f,g) (go(GO6(a, b, c, d, e, f), g))
195
196 #define CONT1(a,cont) (xmlNodeSetContent(GO1(a), (const xmlChar*)cont))
197 #define CONT2(a,b,cont) (xmlNodeSetContent(GO2(a,b), (const xmlChar*)cont))
198 #define CONT3(a,b,c,cont) (xmlNodeSetContent(GO3(a,b,c), (const xmlChar*)cont))
199 #define CONT4(a,b,c,d,cont) (xmlNodeSetContent(GO4(a,b,c,d), (const xmlChar*)cont))
200 #define CONT5(a,b,c,d,e,cont) (xmlNodeSetContent(GO5(a,b,c,d,e), (const xmlChar*)cont))
201 #define CONT6(a,b,c,d,e,f,cont) (xmlNodeSetContent(GO6(a,b,c,d,e,f), (const xmlChar*)cont))
202
203 #define ATTR1(a,name,cont) (xmlSetProp(GO1(a), (const xmlChar*)name, (const xmlChar*)cont))
204 #define ATTR2(a,b,name,cont) (xmlSetProp(GO2(a,b), (const xmlChar*)name, (const xmlChar*)cont))
205 #define ATTR3(a,b,c,name,cont) (xmlSetProp(GO3(a,b,c), (const xmlChar*)name, (const xmlChar*)cont))
206 #define ATTR4(a,b,c,d,name,cont) (xmlSetProp(GO4(a,b,c,d), (const xmlChar*)name, (const xmlChar*)cont))
207 #define ATTR5(a,b,c,d,e,name,cont) (xmlSetProp(GO5(a,b,c,d,e), (const xmlChar*)name, (const xmlChar*)cont))
208 #define ATTR6(a,b,c,d,e,f,name,cont) (xmlSetProp(GO6(a,b,c,d,e,f), (const xmlChar*)name, (const xmlChar*)cont))
209 #define ATTR7(a,b,c,d,e,f,g,name,cont) (xmlSetProp(GO7(a,b,c,d,e,f,g), (const xmlChar*)name, (const xmlChar*)cont))
210
211 #define COLOR1(a,R,G,B,A) (ATTR1(a,"r",NUM(R)), \
212                            ATTR1(a,"g",NUM(G)), \
213                            ATTR1(a,"b",NUM(B)), \
214                            ATTR1(a,"a",NUM(A)))
215 #define COLOR2(a,b,R,G,B,A) (ATTR2(a,b,"r",NUM(R)), \
216                              ATTR2(a,b,"g",NUM(G)), \
217                              ATTR2(a,b,"b",NUM(B)), \
218                              ATTR2(a,b,"a",NUM(A)))
219 #define COLOR3(a,b,c,R,G,B,A) (ATTR3(a,b,c,"r",NUM(R)), \
220                                ATTR3(a,b,c,"g",NUM(G)), \
221                                ATTR3(a,b,c,"b",NUM(B)), \
222                                ATTR3(a,b,c,"a",NUM(A)))
223 #define COLOR4(a,b,c,d,R,G,B,A) (ATTR4(a,b,c,d,"r",NUM(R)), \
224                                  ATTR4(a,b,c,d,"g",NUM(G)), \
225                                  ATTR4(a,b,c,d,"b",NUM(B)), \
226                                  ATTR4(a,b,c,d,"a",NUM(A)))
227 #define COLOR5(a,b,c,d,e,R,G,B,A) (ATTR5(a,b,c,d,e,"r",NUM(R)), \
228                                    ATTR5(a,b,c,d,e,"g",NUM(G)), \
229                                    ATTR5(a,b,c,d,e,"b",NUM(B)), \
230                                    ATTR5(a,b,c,d,e,"a",NUM(A)))
231 #define COLOR6(a,b,c,d,e,f,R,G,B,A) (ATTR6(a,b,c,d,e,f,"r",NUM(R)), \
232                                      ATTR6(a,b,c,d,e,f,"g",NUM(G)), \
233                                      ATTR6(a,b,c,d,e,f,"b",NUM(B)), \
234                                      ATTR6(a,b,c,d,e,f,"a",NUM(A)))
235
236 #define APPEARANCE2(res,a,b) \
237 { \
238     if (read_string(db, res, &s)) \
239         CONT3(a, b, "style", s); \
240     if (read_color(db, res".color", &i, &j, &k)) \
241         COLOR3(a, b, "primary", i, j, k, 255); \
242     if (read_color(db, res".colorTo", &i, &j, &k)) \
243         COLOR3(a, b, "secondary", i, j, k, 255); \
244     if (read_color(db, res".border.color", &i, &j, &k)) \
245         COLOR3(a, b, "border", i, j, k, 255); \
246     if (read_color(db, res".interlace.color", &i, &j, &k)) \
247         COLOR3(a, b, "interlace", i, j, k, 255); \
248 }
249
250 #define APPEARANCE3(res,a,b,c) \
251 { \
252     if (read_string(db, res, &s)) \
253         CONT4(a, b, c, "style", s); \
254     if (read_color(db, res".color", &i, &j, &k)) \
255         COLOR4(a, b, c, "primary", i, j, k, 255); \
256     if (read_color(db, res".colorTo", &i, &j, &k)) \
257         COLOR4(a, b, c, "secondary", i, j, k, 255); \
258     if (read_color(db, res".border.color", &i, &j, &k)) \
259         COLOR4(a, b, c, "border", i, j, k, 255); \
260     if (read_color(db, res".interlace.color", &i, &j, &k)) \
261         COLOR4(a, b, c, "interlace", i, j, k, 255); \
262 }
263
264 #define APPEARANCE4(res,a,b,c,d) \
265 { \
266     if (read_string(db, res, &s)) \
267         CONT5(a, b, c, d, "style", s); \
268     if (read_color(db, res".color", &i, &j, &k)) \
269         COLOR5(a, b, c, d, "primary", i, j, k, 255); \
270     if (read_color(db, res".colorTo", &i, &j, &k)) \
271         COLOR5(a, b, c, d, "secondary", i, j, k, 255); \
272     if (read_color(db, res".border.color", &i, &j, &k)) \
273         COLOR5(a, b, c, d, "border", i, j, k, 255); \
274     if (read_color(db, res".interlace.color", &i, &j, &k)) \
275         COLOR5(a, b, c, d, "interlace", i, j, k, 255); \
276 }
277
278 int main(int argc, char **argv)
279 {
280     XrmDatabase db;
281     int i,j,k;
282     gchar *s;
283     int ret = 0;
284
285     if (argc > 1) {
286         fprintf(stderr, "themetoxml (C) 2007 Dana Jansens\n"
287                 "This tool takes an older Openbox3 themerc file on stdin,"
288                 " and gives back the\n"
289                 "theme in the newer themerc.xml XML style.\n");
290         return 0;
291     }
292     {
293         gchar *buf = g_new(gchar, 1000);
294         gint sz = 1000;
295         gint r = 0, rthis;
296
297         while ((rthis = read(0, buf + r, sz - r)) > 0) {
298             r+=rthis;
299             if (r==sz) {
300                 sz+=1000;
301                 buf = g_renew(gchar,buf,sz);
302             }
303         }
304         
305
306         if ((db = XrmGetStringDatabase(buf)) == NULL) {
307             fprintf(stderr, "Unable to read the database from stdin\n");
308             return 1;
309         }
310         g_free(buf);
311     }
312
313     doc = xmlNewDoc((const xmlChar*) "1.0");
314     xmlDocSetRootElement
315         (doc,(root = xmlNewNode(NULL, (const xmlChar*)"openbox_theme")));
316     xmlSetProp(root, (const xmlChar*)"version", (const xmlChar*)"1");
317     xmlSetProp(root, (const xmlChar*)"xmlns",
318                (const xmlChar*)"http://openbox.org/themerc");
319
320     if (read_int(db, "window.handle.width", &i))
321         CONT2("dimensions", "handle", NUM(i));
322
323     if (read_int(db, "padding.width", &i)) {
324         ATTR2("dimensions", "padding", "x", NUM(i));
325         ATTR2("dimensions", "padding", "y", NUM(i));
326     }
327     
328     if (read_int(db, "borderWidth", &i)) {
329         CONT3("window", "border", "width", NUM(i));
330         CONT3("menu", "border", "width", NUM(i));
331     } else if (read_int(db, "border.width", &i)) {
332         CONT3("window", "border", "width", NUM(i));
333         CONT3("menu", "border", "width", NUM(i));
334     }
335
336     if (read_color(db, "border.color", &i, &j, &k)) {
337         COLOR3("window", "border", "primary", i, j, k, 255);
338         COLOR3("menu", "border", "primary", i, j, k, 255);
339     }
340
341     if (read_int(db, "window.client.padding.width", &i)) {
342         ATTR2("window", "clientpadding", "x", NUM(i));
343         ATTR2("window", "clientpadding", "y", NUM(i));
344     }
345
346     if (read_string(db, "window.label.text.justify", &s)) {
347         if (!g_ascii_strcasecmp(s, "right")) s = "right";
348         else if (!g_ascii_strcasecmp(s, "center")) s = "center";
349         else s = "left";
350         CONT2("window", "justify", s);
351     }
352
353     if (read_string(db, "menu.title.text.justify", &s)) {
354         if (!g_ascii_strcasecmp(s, "right")) s = "right";
355         else if (!g_ascii_strcasecmp(s, "center")) s = "center";
356         else s = "left";
357         CONT2("menu", "justify", s);
358     }
359
360     if (read_int(db, "menu.overlap", &i))
361         CONT2("menu", "overlap", NUM(i));
362
363     if (read_color(db, "window.active.client.color", &i, &j, &k))
364         COLOR3("window","active","clientpadding",i,j,k,255);
365     
366     if (read_color(db, "window.inactive.client.color", &i, &j, &k))
367         COLOR3("window","inactive","clientpadding",i,j,k,255);
368
369     if (read_color(db, "window.active.label.text.color", &i, &j, &k))
370         COLOR5("window","active","label","text","primary",i,j,k,255);
371
372     if (read_color(db, "window.inactive.label.text.color", &i, &j, &k))
373         COLOR5("window","inactive","label","text","primary",i,j,k,255);
374
375     if (read_color(db, "window.active.button.unpressed.image.color",
376                    &i, &j, &k))
377         COLOR5("window","active","buttons","unpressed","image",i,j,k,255);
378
379     if (read_color(db, "window.inactive.button.unpressed.image.color",
380                    &i, &j, &k))
381         COLOR5("window","inactive","buttons","unpressed","image",i,j,k,255);
382
383     if (read_color(db, "window.active.button.pressed.image.color",
384                    &i, &j, &k))
385         COLOR5("window","active","buttons","pressed","image",i,j,k,255);
386
387     if (read_color(db, "window.inactive.button.pressed.image.color",
388                    &i, &j, &k))
389         COLOR5("window","inactive","buttons","pressed","image",i,j,k,255);
390
391     if (read_color(db, "window.active.button.disabled.image.color",
392                    &i, &j, &k))
393         COLOR5("window","active","buttons","disabled","image",i,j,k,255);
394
395     if (read_color(db, "window.inactive.button.disabled.image.color",
396                    &i, &j, &k))
397         COLOR5("window","inactive","buttons","disabled","image",i,j,k,255);
398
399     if (read_color(db, "window.active.button.hover.image.color",
400                    &i, &j, &k))
401         COLOR5("window","active","buttons","hover","image",i,j,k,255);
402
403     if (read_color(db, "window.inactive.button.hover.image.color",
404                    &i, &j, &k))
405         COLOR5("window","inactive","buttons","hover","image",i,j,k,255);
406
407     if (read_color(db, "window.active.button.toggled.image.color",
408                    &i, &j, &k))
409         COLOR5("window","active","buttons","toggled","image",i,j,k,255);
410
411     if (read_color(db, "window.inactive.button.toggled.image.color",
412                    &i, &j, &k))
413         COLOR5("window","inactive","buttons","toggled","image",i,j,k,255);
414
415     if (read_color(db, "menu.title.text.color",
416                    &i, &j, &k))
417         COLOR4("menu","title","text","primary",i,j,k,255);
418
419     if (read_color(db, "menu.items.text.color",
420                    &i, &j, &k))
421         COLOR3("menu","inactive","primary",i,j,k,255);
422
423     if (read_color(db, "menu.items.disabled.text.color",
424                    &i, &j, &k))
425         COLOR3("menu","disabled","primary",i,j,k,255);
426
427     if (read_color(db, "menu.items.active.text.color",
428                    &i, &j, &k))
429         COLOR4("menu","active","text","primary",i,j,k,255);
430
431     APPEARANCE3("window.active.title.bg", "window", "active", "titlebar");
432     APPEARANCE3("window.inactive.title.bg", "window", "inactive", "titlebar");
433     APPEARANCE3("window.active.label.bg", "window", "active", "label");
434     APPEARANCE3("window.inactive.label.bg", "window", "inactive", "label");
435     APPEARANCE3("window.active.handle.bg", "window", "active", "handle");
436     APPEARANCE3("window.inactive.handle.bg", "window", "inactive", "handle");
437     APPEARANCE3("window.active.grip.bg", "window", "active", "grip");
438     APPEARANCE3("window.inactive.grip.bg", "window", "inactive", "grip");
439     APPEARANCE2("menu.items.bg", "menu", "entries");
440     APPEARANCE2("menu.items.active.bg", "menu", "active");
441     APPEARANCE2("menu.title.bg", "menu", "title");
442
443     APPEARANCE4("window.active.button.disabled.bg",
444                 "window", "active", "buttons", "disabled");
445     APPEARANCE4("window.inactive.button.disabled.bg",
446                 "window", "inactive", "buttons", "disabled");
447     APPEARANCE4("window.active.button.pressed.bg",
448                 "window", "active", "buttons", "pressed");
449     APPEARANCE4("window.inactive.button.pressed.bg",
450                 "window", "inactive", "buttons", "pressed");
451     APPEARANCE4("window.active.button.toggled.bg",
452                 "window", "active", "buttons", "toggled");
453     APPEARANCE4("window.inactive.button.toggled.bg",
454                 "window", "inactive", "buttons", "toggled");
455     APPEARANCE4("window.active.button.unpressed.bg",
456                 "window", "active", "buttons", "unpressed");
457     APPEARANCE4("window.inactive.button.unpressed.bg",
458                 "window", "inactive", "buttons", "unpressed");
459     APPEARANCE4("window.active.button.hover.bg",
460                 "window", "active", "buttons", "hover");
461     APPEARANCE4("window.inactive.button.hover.bg",
462                 "window", "inactive", "buttons", "hover");
463
464     if (read_string(db, "window.active.label.text.font", &s)) {
465         char *p;
466         if (strstr(s, "shadow=y")) {
467             if ((p = strstr(s, "shadowoffset=")))
468                 i = parse_inline_number(p + strlen("shadowoffset="));
469             else
470                 i = 1;
471             ATTR6("window","active","label","text","shadow","offset",
472                      "x",NUM(i));
473             ATTR6("window","active","label","text","shadow","offset",
474                      "y",NUM(i));
475         }
476         if ((p = strstr(s, "shadowtint=")))
477         {
478             i = parse_inline_number(p + strlen("shadowtint="));
479             j = (i > 0 ? 0 : 255);
480             i = ABS(i);
481             COLOR6("window","active","label","text","shadow","primary",
482                    j,j,j,i);
483         }
484     }
485
486     if (read_string(db, "window.inactive.label.text.font", &s)) {
487         char *p;
488         if (strstr(s, "shadow=y")) {
489             if ((p = strstr(s, "shadowoffset=")))
490                 i = parse_inline_number(p + strlen("shadowoffset="));
491             else
492                 i = 1;
493             ATTR6("window","inactive","label","text","shadow","offset",
494                      "x",NUM(i));
495             ATTR6("window","inactive","label","text","shadow","offset",
496                      "y",NUM(i));
497         }
498         if ((p = strstr(s, "shadowtint=")))
499         {
500             i = parse_inline_number(p + strlen("shadowtint="));
501             j = (i > 0 ? 0 : 255);
502             i = ABS(i);
503             COLOR6("window","inactive","label","text","shadow","primary",
504                    j,j,j,i);
505         }
506     }
507
508     if (read_string(db, "menu.title.text.font", &s)) {
509         char *p;
510         if (strstr(s, "shadow=y")) {
511             if ((p = strstr(s, "shadowoffset=")))
512                 i = parse_inline_number(p + strlen("shadowoffset="));
513             else
514                 i = 1;
515             ATTR5("menu","title","text","shadow","offset","x",NUM(i));
516             ATTR5("menu","title","text","shadow","offset","y",NUM(i));
517         }
518         if ((p = strstr(s, "shadowtint=")))
519         {
520             i = parse_inline_number(p + strlen("shadowtint="));
521             j = (i > 0 ? 0 : 255);
522             i = ABS(i);
523             COLOR5("menu","title","text","shadow","primary",j,j,j,i);
524         }
525     }
526
527     if (read_string(db, "menu.items.text.font", &s)) {
528         char *p;
529         if (strstr(s, "shadow=y")) {
530             if ((p = strstr(s, "shadowoffset=")))
531                 i = parse_inline_number(p + strlen("shadowoffset="));
532             else
533                 i = 1;
534             ATTR4("menu","inactive","shadow","offset","x",NUM(i));
535             ATTR4("menu","inactive","shadow","offset","y",NUM(i));
536             ATTR5("menu","active","text","shadow","offset","x",NUM(i));
537             ATTR5("menu","active","text","shadow","offset","y",NUM(i));
538             ATTR4("menu","disabled","shadow","offset","x",NUM(i));
539             ATTR4("menu","disabled","shadow","offset","y",NUM(i));
540         }
541         if ((p = strstr(s, "shadowtint=")))
542         {
543             i = parse_inline_number(p + strlen("shadowtint="));
544             j = (i > 0 ? 0 : 255);
545             i = ABS(i);
546             COLOR4("menu","inactive","shadow","primary",j,j,j,i);
547             COLOR5("menu","active","text","shadow","primary",j,j,j,i);
548             COLOR4("menu","disabled","shadow","primary",j,j,j,i);
549         }
550     }
551
552     if (xmlSaveFormatFile("-", doc, 1) < 0) {
553         fprintf(stderr, "Error writing the xml tree\n");
554         ret = 1;
555     }
556
557     xmlFreeDoc(doc);
558     return ret;
559 }