1 --- libglade/libglade-2.0.pc.in 2001-12-12 14:26:54.000000000 +0000
2 +++ libglade/libglade-2.0.pc.in 2004-01-12 20:08:06.000000000 +0000
5 Description: a library for dynamically loading GLADE interface files
7 -Requires: gtk+-2.0 libxml-2.0
8 +Requires: gtk+-2.0 @PKGCFG_REQUIRE_LIBXML2@
9 Libs: -L${libdir} -lglade-2.0
10 Cflags: -I${includedir}/libglade-2.0
13 --- libglade/glade/glade-parser.c.orig 2004-02-11 01:26:01.000000000 +0000
14 +++ libglade/glade/glade-parser.c 2005-01-01 11:26:37.000000000 +0000
16 # define dgettext(Domain, String) (String)
19 -#include <libxml/parser.h>
20 +#ifdef USE_GMARKUP_PARSER
23 +# include <libxml/parser.h>
26 +#ifdef USE_GMARKUP_PARSER
27 +# define xmlChar gchar
30 #include "glade-parser.h"
31 #include "glade-private.h"
34 if (!strcmp(name, "glade-interface")) {
35 state->state = PARSER_GLADE_INTERFACE;
38 +#ifndef USE_GMARKUP_PARSER
40 /* check for correct XML namespace */
41 for (i = 0; attrs && attrs[i] != NULL; i += 2) {
42 if (!strcmp(attrs[i], "xmlns") &&
44 g_warning("unknown attribute `%s' for <glade-interface>",
51 g_warning("Expected <glade-interface>. Got <%s>.", name);
52 state->prev_state = state->state;
53 @@ -1056,12 +1068,18 @@
57 +#ifndef USE_GMARKUP_PARSER
60 glade_parser_get_entity(GladeParseState *state, const xmlChar *name)
62 return xmlGetPredefinedEntity(name);
65 +#endif /* !defined(USE_GMARKUP_PARSER) */
67 +#ifndef USE_GMARKUP_PARSER
70 glade_parser_warning(GladeParseState *state, const char *msg, ...)
72 @@ -1072,6 +1090,10 @@
76 +#endif /* !defined(USE_GMARKUP_PARSER) */
78 +#ifndef USE_GMARKUP_PARSER
81 glade_parser_error(GladeParseState *state, const char *msg, ...)
83 @@ -1082,6 +1104,10 @@
87 +#endif /* !defined(USE_GMARKUP_PARSER) */
89 +#ifndef USE_GMARKUP_PARSER
92 glade_parser_fatal_error(GladeParseState *state, const char *msg, ...)
94 @@ -1092,6 +1118,10 @@
98 +#endif /* !defined(USE_GMARKUP_PARSER) */
100 +#ifndef USE_GMARKUP_PARSER
102 static xmlSAXHandler glade_parser = {
103 0, /* internalSubset */
104 0, /* isStandalone */
105 @@ -1119,6 +1149,82 @@
106 (fatalErrorSAXFunc)glade_parser_fatal_error, /* fatalError */
109 +#else /* USE_GMARKUP_PARSER */
112 +glade_parser_start_element_wrapper(GMarkupParseContext *context,
114 + const gchar **attr_names,
115 + const gchar **attr_values,
121 + /* Pack attribute names/values from two separate
122 + * arrays (GMarkupParser style) into one single
123 + * array (libxml SAXParser style). This is not
124 + * very efficient, but we do it to make the
125 + * GMarkupParser code as little invasive as
128 + while (attr_names[i] != NULL) {
134 + const gchar *attr[(i*2)+1];
137 + for (j=0, k=0; k < i; j += 2)
139 + attr[j] = attr_names[k];
140 + attr[j+1] = attr_values[k];
145 + glade_parser_start_element((GladeParseState*)state, name, attr);
150 +glade_parser_end_element_wrapper(GMarkupParseContext *context,
155 + glade_parser_end_element((GladeParseState*)state, name);
159 +glade_parser_characters_wrapper(GMarkupParseContext *context,
160 + const gchar *chars,
165 + glade_parser_characters((GladeParseState*)state, chars, (int) len);
169 +glade_parser_error(GMarkupParseContext *context, GError *err, gpointer data)
171 + g_log("Glade-Parser", G_LOG_LEVEL_CRITICAL, "%s", err->message);
174 +static const GMarkupParser glade_parser = {
175 + glade_parser_start_element_wrapper, /* element open */
176 + glade_parser_end_element_wrapper, /* element close */
177 + glade_parser_characters_wrapper, /* text content */
178 + NULL, /* passthrough */
179 + glade_parser_error, /* parse error */
182 +#endif /* USE_GMARKUP_PARSER */
186 widget_info_free(GladeWidgetInfo *info)
188 @@ -1182,6 +1288,9 @@
190 * Returns: the GladeInterface structure for the XML file.
193 +#ifndef USE_GMARKUP_PARSER
196 glade_parser_parse_file(const gchar *file, const gchar *domain)
198 @@ -1213,6 +1322,31 @@
199 return state.interface;
202 +#else /* defined(USE_GMARKUP_PARSER) */
205 +glade_parser_parse_file(const gchar *file, const gchar *domain)
207 + GladeInterface *interface;
208 + GError *err = NULL;
209 + gchar *content = NULL;
212 + if (!g_file_get_contents(file, &content, &clen, &err)) {
213 + g_warning("could not load glade file: %s", err->message);
218 + interface = glade_parser_parse_buffer(content, (gint) clen, domain);
225 +#endif /* USE_GMARKUP_PARSER */
228 * glade_parser_parse_buffer
229 * @buffer: a buffer in memory containing XML data.
230 @@ -1228,6 +1362,9 @@
232 * Returns: the GladeInterface structure for the XML buffer.
235 +#ifndef USE_GMARKUP_PARSER
238 glade_parser_parse_buffer(const gchar *buffer, gint len, const gchar *domain)
240 @@ -1254,6 +1391,161 @@
241 return state.interface;
244 +#else /* defined(USE_GMARKUP_PARSER) */
247 +static GladeInterface *
248 +glade_parser_parse_buffer_internal(const gchar *buffer, gint len, const gchar *domain)
250 + GMarkupParseContext *context;
251 + GladeParseState state = { 0 };
252 + GError *err = NULL;
254 + state.interface = NULL;
256 + state.domain = domain;
258 + state.domain = textdomain(NULL);
260 + /* FIXME: This strstr() is not safe, as it ignores the len
261 + * argument and assumes the buffer is NUL-terminated */
262 + if (strstr(buffer, "<?xml") == NULL) {
263 + g_warning("No XML header found in document!");
267 + context = g_markup_parse_context_new(&glade_parser, (GMarkupParseFlags) 0, &state, NULL);
269 + glade_parser_start_document(&state);
271 + if (!g_markup_parse_context_parse(context, buffer, (gssize) len, &err)) {
272 + g_warning("document not well formed: %s", err->message);
274 + if (state.interface)
275 + glade_interface_destroy (state.interface);
279 + glade_parser_end_document(&state);
281 + if (state.state != PARSER_FINISH) {
282 + g_warning("did not finish in PARSER_FINISH state!");
284 + if (state.interface)
285 + glade_interface_destroy(state.interface);
290 + return state.interface;
293 +struct _gzip_rfc1952_hdr
295 + guint8 id1, id2, cm, flags;
301 +static GladeInterface *
302 +glade_parser_parse_gzipped_buffer(const gchar *buffer, gint len, const gchar *domain)
304 + struct _gzip_rfc1952_hdr *hdr = (struct _gzip_rfc1952_hdr*)buffer;
305 + struct z_stream_s zstream;
306 + GladeInterface *interface;
307 + const guint8 *cbuf; /* start of compressed data */
308 + guint8 *decompress_buf;
309 + gulong decompress_len = 0;
312 + g_assert(hdr != NULL && hdr->id1 == 0x1f && hdr->id2 == 0x8b);
314 + if (hdr->cm != Z_DEFLATED) {
315 + g_warning("Unknown decompression method %u", (guint) hdr->cm);
319 + /* Uncompressed size (modulo 2^32) is last
320 + * 4 bytes of gzipped file, and little endian.
322 + decompress_len = GUINT32_FROM_LE(*((guint32*)(((guint8*)buffer) + len - 4)));
324 + /* paranoid mode: glade files > 5MB are unlikely */
325 + g_return_val_if_fail(decompress_len < 5*1024*1024, NULL);
327 + decompress_buf = g_malloc0(decompress_len + 1); /* +1 for NUL-terminator */
329 + /* find start of compressed data, skipping header stuff */
330 + cbuf = (guint8*)buffer + 10;
331 + if (hdr->flags & 0x04) {
332 + guint16 xlen = GUINT16_FROM_LE(*((guint16*)cbuf));
335 + if (hdr->flags & 0x08) {
336 + guint16 onamelen = strlen(cbuf);
337 + cbuf += onamelen + 1;
339 + if (hdr->flags & 0x10) {
340 + guint16 commentlen = strlen(cbuf);
341 + cbuf += commentlen + 1;
343 + if (hdr->flags & 0x02)
345 + cbuf += 2; /* skip header CRC16 */
348 + zstream.next_in = (void*)cbuf;
349 + zstream.avail_in = (uLongf) len - ((void*)cbuf-(void*)buffer) - 4 - 4 +1;
350 + zstream.next_out = decompress_buf;
351 + zstream.avail_out= decompress_len;
352 + zstream.zalloc = Z_NULL;
353 + zstream.zfree = Z_NULL;
354 + zstream.opaque = Z_NULL;
356 + ret = inflateInit2(&zstream, -MAX_WBITS);
359 + g_warning("inflateInit2() failed. zlib error code: %d", ret);
360 + g_free(decompress_buf);
364 + ret = inflate(&zstream, Z_FINISH);
366 + if (ret != Z_STREAM_END) {
367 + g_warning("zlib decompression failed. zlib error code: %d", ret);
368 + g_free(decompress_buf);
372 + interface = glade_parser_parse_buffer_internal(decompress_buf, decompress_len, domain);
374 + g_free(decompress_buf);
380 +glade_parser_parse_buffer(const gchar *buffer, gint len, const gchar *domain)
382 + g_return_val_if_fail(buffer != NULL, NULL);
383 + g_return_val_if_fail(len > 0, NULL);
385 + /* Check if buffer is gzipped */
386 + if (buffer[0] == 0x1f && buffer[1] == (gchar)0x8b) {
387 + return glade_parser_parse_gzipped_buffer(buffer, len, domain);
390 + /* Buffer is cleartext. */
391 + return glade_parser_parse_buffer_internal(buffer, len, domain);
394 +#endif /* USE_GMARKUP_PARSER */
397 +#ifndef USE_GMARKUP_PARSER
400 dump_widget(xmlNode *parent, GladeWidgetInfo *info, gint indent)
402 @@ -1373,6 +1665,8 @@
403 xmlNodeAddContent(widget, " ");
406 +#endif /* !defined(USE_GMARKUP_PARSER) */
409 * glade_interface_dump
410 * @interface: the GladeInterface
411 @@ -1381,6 +1675,9 @@
412 * This function dumps the contents of a GladeInterface into a file as
413 * XML. It is intended mainly as a debugging tool.
416 +#ifndef USE_GMARKUP_PARSER
419 glade_interface_dump(GladeInterface *interface, const gchar *filename)
421 @@ -1419,6 +1716,17 @@
425 +#else /* defined(USE_GMARKUP_PARSER) */
428 +glade_interface_dump(GladeInterface *interface, const gchar *filename)
430 + g_warning("glade_interface_dump() is only available with libxml2.");
433 +#endif /* USE_GMARKUP_PARSER */
438 main(int argc, char **argv) {
441 --- libglade-2.4.0/configure.in.orig 2005-01-01 12:23:37.000000000 +0000
442 +++ libglade-2.4.0/configure.in 2005-01-01 12:35:31.000000000 +0000
444 AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
446 PKG_CHECK_MODULES(LIBGLADE, [dnl
447 - libxml-2.0 >= required_libxml_version dnl
448 atk >= required_atk_version dnl
449 gtk+-2.0 >= required_gtk_version dnl
450 glib-2.0 >= required_glib_version])
451 AC_SUBST(LIBGLADE_LIBS)
452 AC_SUBST(LIBGLADE_CFLAGS)
456 +AC_ARG_WITH([libxml2],
457 + AC_HELP_STRING([--without-libxml2], [Don't use libxml2, use Glib's GMarkupParser instead]),
458 + [disable_xml2=yes],
461 +AC_MSG_CHECKING([if we are using libxml2])
462 +if test "x$disable_xml2" == "xno"; then
464 + PKG_CHECK_MODULES(XML2, libxml-2.0 >= 2.4.10)
465 + PKGCFG_REQUIRE_LIBXML2="libxml-2.0"
466 + LIBGLADE_CFLAGS="$LIBGLADE_CFLAGS $XML2_CFLAGS"
467 + LIBGLADE_LIBS="$LIBGLADE_LIBS $XML2_LIBS"
469 + LIBGLADE_CFLAGS="$LIBGLADE_CFLAGS -DUSE_GMARKUP_PARSER"
470 + PKGCFG_REQUIRE_LIBXML2=""
475 +AC_SUBST(XML2_CFLAGS)
476 +AC_SUBST(PKGCFG_REQUIRE_LIBXML2)
478 AC_MSG_CHECKING([for native Win32])
485 +if test "x$disable_xml2" == "xyes"; then
486 + echo "*****************************************************"
487 + echo " You chose to disable libxml2 and use Glib's"
488 + echo " GMarkupParser instead."
490 + echo " Please bear in mind that using libglade with"
491 + echo " GMarkupParser is an experimental feature only."
493 + echo " Please post problems or success stories to"
494 + echo " the glade-devel mailing list. Thank you."
495 + echo "*****************************************************"
502 dnl gettext stuff ... there is no message catalog for libglade -- libglade