1 diff -urN libglade-2.4.2.orig/configure.in libglade-2.4.2/configure.in
2 --- libglade-2.4.2.orig/configure.in 2005-02-11 12:42:58.000000000 +0100
3 +++ libglade-2.4.2/configure.in 2005-03-22 01:22:00.000000000 +0100
5 AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
7 PKG_CHECK_MODULES(LIBGLADE, [dnl
8 - libxml-2.0 >= required_libxml_version dnl
9 atk >= required_atk_version dnl
10 gtk+-2.0 >= required_gtk_version dnl
11 glib-2.0 >= required_glib_version])
14 +AC_ARG_WITH([libxml2],
15 + AC_HELP_STRING([--without-libxml2], [Don't use libxml2, use Glib's GMarkupParser instead]),
19 +AC_MSG_CHECKING([if we are using libxml2])
20 +if test "x$disable_xml2" == "xno"; then
22 + PKG_CHECK_MODULES(XML2, libxml-2.0 >= 2.4.10)
23 + PKGCFG_REQUIRE_LIBXML2="libxml-2.0"
24 + LIBGLADE_CFLAGS="$LIBGLADE_CFLAGS $XML2_CFLAGS"
25 + LIBGLADE_LIBS="$LIBGLADE_LIBS $XML2_LIBS"
27 + LIBGLADE_CFLAGS="$LIBGLADE_CFLAGS -DUSE_GMARKUP_PARSER"
28 + PKGCFG_REQUIRE_LIBXML2=""
33 +AC_SUBST(XML2_CFLAGS)
34 +AC_SUBST(PKGCFG_REQUIRE_LIBXML2)
36 AC_MSG_CHECKING([for native Win32])
43 +if test "x$disable_xml2" == "xyes"; then
44 + echo "*****************************************************"
45 + echo " You chose to disable libxml2 and use Glib's"
46 + echo " GMarkupParser instead."
48 + echo " Please bear in mind that using libglade with"
49 + echo " GMarkupParser is an experimental feature only."
51 + echo " Please post problems or success stories to"
52 + echo " the glade-devel mailing list. Thank you."
53 + echo "*****************************************************"
60 dnl gettext stuff ... there is no message catalog for libglade -- libglade
61 diff -urN libglade-2.4.2.orig/glade/glade-parser.c libglade-2.4.2/glade/glade-parser.c
62 --- libglade-2.4.2.orig/glade/glade-parser.c 2004-11-11 11:56:13.000000000 +0100
63 +++ libglade-2.4.2/glade/glade-parser.c 2005-03-22 01:20:00.000000000 +0100
65 # define dgettext(Domain, String) (String)
68 -#include <libxml/parser.h>
69 +#ifdef USE_GMARKUP_PARSER
72 +# include <libxml/parser.h>
75 +#ifdef USE_GMARKUP_PARSER
76 +# define xmlChar gchar
79 #include "glade-parser.h"
80 #include "glade-private.h"
83 if (!strcmp(name, "glade-interface")) {
84 state->state = PARSER_GLADE_INTERFACE;
87 +#ifndef USE_GMARKUP_PARSER
89 /* check for correct XML namespace */
90 for (i = 0; attrs && attrs[i] != NULL; i += 2) {
91 if (!strcmp(attrs[i], "xmlns") &&
93 g_warning("unknown attribute `%s' for <glade-interface>",
100 g_warning("Expected <glade-interface>. Got <%s>.", name);
101 state->prev_state = state->state;
102 @@ -1063,12 +1075,18 @@
106 +#ifndef USE_GMARKUP_PARSER
109 glade_parser_get_entity(GladeParseState *state, const xmlChar *name)
111 return xmlGetPredefinedEntity(name);
114 +#endif /* !defined(USE_GMARKUP_PARSER) */
116 +#ifndef USE_GMARKUP_PARSER
119 glade_parser_warning(GladeParseState *state, const char *msg, ...)
121 @@ -1079,6 +1097,10 @@
125 +#endif /* !defined(USE_GMARKUP_PARSER) */
127 +#ifndef USE_GMARKUP_PARSER
130 glade_parser_error(GladeParseState *state, const char *msg, ...)
132 @@ -1089,6 +1111,10 @@
136 +#endif /* !defined(USE_GMARKUP_PARSER) */
138 +#ifndef USE_GMARKUP_PARSER
141 glade_parser_fatal_error(GladeParseState *state, const char *msg, ...)
143 @@ -1099,6 +1125,10 @@
147 +#endif /* !defined(USE_GMARKUP_PARSER) */
149 +#ifndef USE_GMARKUP_PARSER
151 static xmlSAXHandler glade_parser = {
152 (internalSubsetSAXFunc)NULL, /* internalSubset */
153 (isStandaloneSAXFunc)NULL, /* isStandalone */
154 @@ -1126,6 +1156,82 @@
155 (fatalErrorSAXFunc)glade_parser_fatal_error, /* fatalError */
158 +#else /* USE_GMARKUP_PARSER */
161 +glade_parser_start_element_wrapper(GMarkupParseContext *context,
163 + const gchar **attr_names,
164 + const gchar **attr_values,
170 + /* Pack attribute names/values from two separate
171 + * arrays (GMarkupParser style) into one single
172 + * array (libxml SAXParser style). This is not
173 + * very efficient, but we do it to make the
174 + * GMarkupParser code as little invasive as
177 + while (attr_names[i] != NULL) {
183 + const gchar *attr[(i*2)+1];
186 + for (j=0, k=0; k < i; j += 2)
188 + attr[j] = attr_names[k];
189 + attr[j+1] = attr_values[k];
194 + glade_parser_start_element((GladeParseState*)state, name, attr);
199 +glade_parser_end_element_wrapper(GMarkupParseContext *context,
204 + glade_parser_end_element((GladeParseState*)state, name);
208 +glade_parser_characters_wrapper(GMarkupParseContext *context,
209 + const gchar *chars,
214 + glade_parser_characters((GladeParseState*)state, chars, (int) len);
218 +glade_parser_error(GMarkupParseContext *context, GError *err, gpointer data)
220 + g_log("Glade-Parser", G_LOG_LEVEL_CRITICAL, "%s", err->message);
223 +static const GMarkupParser glade_parser = {
224 + glade_parser_start_element_wrapper, /* element open */
225 + glade_parser_end_element_wrapper, /* element close */
226 + glade_parser_characters_wrapper, /* text content */
227 + NULL, /* passthrough */
228 + glade_parser_error, /* parse error */
231 +#endif /* USE_GMARKUP_PARSER */
235 widget_info_free(GladeWidgetInfo *info)
237 @@ -1191,6 +1297,9 @@
239 * Returns: the GladeInterface structure for the XML file.
242 +#ifndef USE_GMARKUP_PARSER
245 glade_parser_parse_file(const gchar *file, const gchar *domain)
247 @@ -1222,6 +1331,31 @@
248 return state.interface;
251 +#else /* defined(USE_GMARKUP_PARSER) */
254 +glade_parser_parse_file(const gchar *file, const gchar *domain)
256 + GladeInterface *interface;
257 + GError *err = NULL;
258 + gchar *content = NULL;
261 + if (!g_file_get_contents(file, &content, &clen, &err)) {
262 + g_warning("could not load glade file: %s", err->message);
267 + interface = glade_parser_parse_buffer(content, (gint) clen, domain);
274 +#endif /* USE_GMARKUP_PARSER */
277 * glade_parser_parse_buffer
278 * @buffer: a buffer in memory containing XML data.
279 @@ -1237,6 +1371,9 @@
281 * Returns: the GladeInterface structure for the XML buffer.
284 +#ifndef USE_GMARKUP_PARSER
287 glade_parser_parse_buffer(const gchar *buffer, gint len, const gchar *domain)
289 @@ -1263,6 +1400,161 @@
290 return state.interface;
293 +#else /* defined(USE_GMARKUP_PARSER) */
296 +static GladeInterface *
297 +glade_parser_parse_buffer_internal(const gchar *buffer, gint len, const gchar *domain)
299 + GMarkupParseContext *context;
300 + GladeParseState state = { 0 };
301 + GError *err = NULL;
303 + state.interface = NULL;
305 + state.domain = domain;
307 + state.domain = textdomain(NULL);
309 + /* FIXME: This strstr() is not safe, as it ignores the len
310 + * argument and assumes the buffer is NUL-terminated */
311 + if (strstr(buffer, "<?xml") == NULL) {
312 + g_warning("No XML header found in document!");
316 + context = g_markup_parse_context_new(&glade_parser, (GMarkupParseFlags) 0, &state, NULL);
318 + glade_parser_start_document(&state);
320 + if (!g_markup_parse_context_parse(context, buffer, (gssize) len, &err)) {
321 + g_warning("document not well formed: %s", err->message);
323 + if (state.interface)
324 + glade_interface_destroy (state.interface);
328 + glade_parser_end_document(&state);
330 + if (state.state != PARSER_FINISH) {
331 + g_warning("did not finish in PARSER_FINISH state!");
333 + if (state.interface)
334 + glade_interface_destroy(state.interface);
339 + return state.interface;
342 +struct _gzip_rfc1952_hdr
344 + guint8 id1, id2, cm, flags;
350 +static GladeInterface *
351 +glade_parser_parse_gzipped_buffer(const gchar *buffer, gint len, const gchar *domain)
353 + struct _gzip_rfc1952_hdr *hdr = (struct _gzip_rfc1952_hdr*)buffer;
354 + struct z_stream_s zstream;
355 + GladeInterface *interface;
356 + const guint8 *cbuf; /* start of compressed data */
357 + guint8 *decompress_buf;
358 + gulong decompress_len = 0;
361 + g_assert(hdr != NULL && hdr->id1 == 0x1f && hdr->id2 == 0x8b);
363 + if (hdr->cm != Z_DEFLATED) {
364 + g_warning("Unknown decompression method %u", (guint) hdr->cm);
368 + /* Uncompressed size (modulo 2^32) is last
369 + * 4 bytes of gzipped file, and little endian.
371 + decompress_len = GUINT32_FROM_LE(*((guint32*)(((guint8*)buffer) + len - 4)));
373 + /* paranoid mode: glade files > 5MB are unlikely */
374 + g_return_val_if_fail(decompress_len < 5*1024*1024, NULL);
376 + decompress_buf = g_malloc0(decompress_len + 1); /* +1 for NUL-terminator */
378 + /* find start of compressed data, skipping header stuff */
379 + cbuf = (guint8*)buffer + 10;
380 + if (hdr->flags & 0x04) {
381 + guint16 xlen = GUINT16_FROM_LE(*((guint16*)cbuf));
384 + if (hdr->flags & 0x08) {
385 + guint16 onamelen = strlen(cbuf);
386 + cbuf += onamelen + 1;
388 + if (hdr->flags & 0x10) {
389 + guint16 commentlen = strlen(cbuf);
390 + cbuf += commentlen + 1;
392 + if (hdr->flags & 0x02)
394 + cbuf += 2; /* skip header CRC16 */
397 + zstream.next_in = (void*)cbuf;
398 + zstream.avail_in = (uLongf) len - ((void*)cbuf-(void*)buffer) - 4 - 4 +1;
399 + zstream.next_out = decompress_buf;
400 + zstream.avail_out= decompress_len;
401 + zstream.zalloc = Z_NULL;
402 + zstream.zfree = Z_NULL;
403 + zstream.opaque = Z_NULL;
405 + ret = inflateInit2(&zstream, -MAX_WBITS);
408 + g_warning("inflateInit2() failed. zlib error code: %d", ret);
409 + g_free(decompress_buf);
413 + ret = inflate(&zstream, Z_FINISH);
415 + if (ret != Z_STREAM_END) {
416 + g_warning("zlib decompression failed. zlib error code: %d", ret);
417 + g_free(decompress_buf);
421 + interface = glade_parser_parse_buffer_internal(decompress_buf, decompress_len, domain);
423 + g_free(decompress_buf);
429 +glade_parser_parse_buffer(const gchar *buffer, gint len, const gchar *domain)
431 + g_return_val_if_fail(buffer != NULL, NULL);
432 + g_return_val_if_fail(len > 0, NULL);
434 + /* Check if buffer is gzipped */
435 + if (buffer[0] == 0x1f && buffer[1] == (gchar)0x8b) {
436 + return glade_parser_parse_gzipped_buffer(buffer, len, domain);
439 + /* Buffer is cleartext. */
440 + return glade_parser_parse_buffer_internal(buffer, len, domain);
443 +#endif /* USE_GMARKUP_PARSER */
446 +#ifndef USE_GMARKUP_PARSER
449 dump_widget(xmlNode *parent, GladeWidgetInfo *info, gint indent)
451 @@ -1382,6 +1674,8 @@
452 xmlNodeAddContent(widget, " ");
455 +#endif /* !defined(USE_GMARKUP_PARSER) */
458 * glade_interface_dump
459 * @interface: the GladeInterface
460 @@ -1390,6 +1684,9 @@
461 * This function dumps the contents of a GladeInterface into a file as
462 * XML. It is intended mainly as a debugging tool.
465 +#ifndef USE_GMARKUP_PARSER
468 glade_interface_dump(GladeInterface *interface, const gchar *filename)
470 @@ -1428,6 +1725,17 @@
474 +#else /* defined(USE_GMARKUP_PARSER) */
477 +glade_interface_dump(GladeInterface *interface, const gchar *filename)
479 + g_warning("glade_interface_dump() is only available with libxml2.");
482 +#endif /* USE_GMARKUP_PARSER */
487 main(int argc, char **argv) {
488 diff -urN libglade-2.4.2.orig/libglade-2.0.pc.in libglade-2.4.2/libglade-2.0.pc.in
489 --- libglade-2.4.2.orig/libglade-2.0.pc.in 2001-12-12 15:28:23.000000000 +0100
490 +++ libglade-2.4.2/libglade-2.0.pc.in 2005-03-22 01:20:00.000000000 +0100
493 Description: a library for dynamically loading GLADE interface files
495 -Requires: gtk+-2.0 libxml-2.0
496 +Requires: gtk+-2.0 @PKGCFG_REQUIRE_LIBXML2@
497 Libs: -L${libdir} -lglade-2.0
498 Cflags: -I${includedir}/libglade-2.0