]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/libglade/libglade-2.4.0/no-xml2.patch
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / libglade / libglade-2.4.0 / no-xml2.patch
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
3 @@ -11,8 +11,8 @@
4  Name: Libglade
5  Description: a library for dynamically loading GLADE interface files
6  Version: @VERSION@
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
11  
12
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
15 @@ -34,7 +34,15 @@
16  #  define dgettext(Domain, String) (String)
17  #endif
18  
19 -#include <libxml/parser.h>
20 +#ifdef USE_GMARKUP_PARSER
21 +#  include <zlib.h>
22 +#else
23 +#  include <libxml/parser.h>
24 +#endif
25 +
26 +#ifdef USE_GMARKUP_PARSER
27 +#  define xmlChar gchar
28 +#endif
29  
30  #include "glade-parser.h"
31  #include "glade-private.h"
32 @@ -507,7 +515,9 @@
33      case PARSER_START:
34         if (!strcmp(name, "glade-interface")) {
35             state->state = PARSER_GLADE_INTERFACE;
36 -#if 0
37 +
38 +#ifndef USE_GMARKUP_PARSER
39 + #if 0
40             /* check for correct XML namespace */
41             for (i = 0; attrs && attrs[i] != NULL; i += 2) {
42                 if (!strcmp(attrs[i], "xmlns") &&
43 @@ -517,7 +527,9 @@
44                     g_warning("unknown attribute `%s' for <glade-interface>",
45                               attrs[i]);
46             }
47 + #endif
48  #endif
49 +
50         } else {
51             g_warning("Expected <glade-interface>.  Got <%s>.", name);
52             state->prev_state = state->state;
53 @@ -1056,12 +1068,18 @@
54      }
55  }
56  
57 +#ifndef USE_GMARKUP_PARSER
58 +
59  static xmlEntityPtr
60  glade_parser_get_entity(GladeParseState *state, const xmlChar *name)
61  {
62      return xmlGetPredefinedEntity(name);
63  }
64  
65 +#endif /* !defined(USE_GMARKUP_PARSER) */
66 +
67 +#ifndef USE_GMARKUP_PARSER
68 +
69  static void
70  glade_parser_warning(GladeParseState *state, const char *msg, ...)
71  {
72 @@ -1072,6 +1090,10 @@
73      va_end(args);
74  }
75  
76 +#endif /* !defined(USE_GMARKUP_PARSER) */
77 +
78 +#ifndef USE_GMARKUP_PARSER
79 +
80  static void
81  glade_parser_error(GladeParseState *state, const char *msg, ...)
82  {
83 @@ -1082,6 +1104,10 @@
84      va_end(args);
85  }
86  
87 +#endif /* !defined(USE_GMARKUP_PARSER) */
88 +
89 +#ifndef USE_GMARKUP_PARSER
90 +
91  static void
92  glade_parser_fatal_error(GladeParseState *state, const char *msg, ...)
93  {
94 @@ -1092,6 +1118,10 @@
95      va_end(args);
96  }
97  
98 +#endif /* !defined(USE_GMARKUP_PARSER) */
99 +
100 +#ifndef USE_GMARKUP_PARSER
101 +
102  static xmlSAXHandler glade_parser = {
103      0, /* internalSubset */
104      0, /* isStandalone */
105 @@ -1119,6 +1149,82 @@
106      (fatalErrorSAXFunc)glade_parser_fatal_error, /* fatalError */
107  };
108  
109 +#else /* USE_GMARKUP_PARSER */
110 +
111 +static void
112 +glade_parser_start_element_wrapper(GMarkupParseContext *context,
113 +                                   const gchar         *name, 
114 +                                   const gchar        **attr_names,
115 +                                   const gchar        **attr_values,
116 +                                   gpointer             state,
117 +                                   GError             **error)
118 +{
119 +    guint i = 0;
120 +
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
126 +     *  possible. */
127 +
128 +    while (attr_names[i] != NULL) {
129 +      ++i;
130 +    }
131 +
132 +    if (1)
133 +    {
134 +        const gchar *attr[(i*2)+1];
135 +        guint j, k;
136 +       
137 +        for (j=0, k=0;  k < i;  j += 2)
138 +        {
139 +            attr[j] = attr_names[k];
140 +            attr[j+1] = attr_values[k];
141 +            ++k;
142 +        }
143 +        attr[i*2] = NULL;
144 +
145 +        glade_parser_start_element((GladeParseState*)state, name, attr);
146 +    }
147 +}
148 +
149 +static void
150 +glade_parser_end_element_wrapper(GMarkupParseContext *context, 
151 +                                 const gchar         *name,
152 +                                 gpointer             state,
153 +                                 GError             **err)
154 +{
155 +    glade_parser_end_element((GladeParseState*)state, name);
156 +}
157 +
158 +static void
159 +glade_parser_characters_wrapper(GMarkupParseContext *context, 
160 +                                const gchar         *chars, 
161 +                                gsize                len,
162 +                                gpointer             state,
163 +                                GError             **err)
164 +{
165 +    glade_parser_characters((GladeParseState*)state, chars, (int) len);
166 +}
167 +
168 +static void
169 +glade_parser_error(GMarkupParseContext *context, GError *err, gpointer data)
170 +{
171 +    g_log("Glade-Parser", G_LOG_LEVEL_CRITICAL, "%s", err->message);
172 +}
173 +
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    */
180 +};
181 +
182 +#endif /* USE_GMARKUP_PARSER */
183 +
184 +
185  static void
186  widget_info_free(GladeWidgetInfo *info)
187  {
188 @@ -1182,6 +1288,9 @@
189   *
190   * Returns: the GladeInterface structure for the XML file.
191   */
192 +
193 +#ifndef USE_GMARKUP_PARSER
194 +
195  GladeInterface *
196  glade_parser_parse_file(const gchar *file, const gchar *domain)
197  {
198 @@ -1213,6 +1322,31 @@
199      return state.interface;
200  }
201  
202 +#else /* defined(USE_GMARKUP_PARSER) */
203 +
204 +GladeInterface *
205 +glade_parser_parse_file(const gchar *file, const gchar *domain)
206 +{
207 +    GladeInterface  *interface;
208 +    GError          *err     = NULL;
209 +    gchar           *content = NULL;
210 +    gsize            clen;
211 +
212 +    if (!g_file_get_contents(file, &content, &clen, &err)) {
213 +        g_warning("could not load glade file: %s", err->message);
214 +        g_error_free(err);
215 +        return NULL;
216 +    }
217 +
218 +    interface = glade_parser_parse_buffer(content, (gint) clen, domain);
219 +
220 +    g_free(content);
221 +
222 +    return interface;
223 +}
224 +
225 +#endif /* USE_GMARKUP_PARSER */
226 +
227  /**
228   * glade_parser_parse_buffer
229   * @buffer: a buffer in memory containing XML data.
230 @@ -1228,6 +1362,9 @@
231   *
232   * Returns: the GladeInterface structure for the XML buffer.
233   */
234 +
235 +#ifndef USE_GMARKUP_PARSER
236 +
237  GladeInterface *
238  glade_parser_parse_buffer(const gchar *buffer, gint len, const gchar *domain)
239  {
240 @@ -1254,6 +1391,161 @@
241      return state.interface;
242  }
243  
244 +#else /* defined(USE_GMARKUP_PARSER) */
245 +
246 +
247 +static GladeInterface *
248 +glade_parser_parse_buffer_internal(const gchar *buffer, gint len, const gchar *domain)
249 +{
250 +       GMarkupParseContext  *context;
251 +       GladeParseState       state = { 0 };
252 +       GError               *err   = NULL;
253 +
254 +       state.interface = NULL;
255 +       if (domain)
256 +               state.domain = domain;
257 +       else
258 +               state.domain = textdomain(NULL);
259 +
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!");
264 +               return NULL;
265 +       }
266 +
267 +       context = g_markup_parse_context_new(&glade_parser, (GMarkupParseFlags) 0, &state, NULL);
268 +
269 +       glade_parser_start_document(&state);
270 +
271 +       if (!g_markup_parse_context_parse(context, buffer, (gssize) len, &err)) {
272 +               g_warning("document not well formed: %s", err->message);
273 +               g_error_free(err);
274 +               if (state.interface)
275 +                       glade_interface_destroy (state.interface);
276 +               return NULL;
277 +       }
278 +
279 +       glade_parser_end_document(&state);
280 +
281 +       if (state.state != PARSER_FINISH) {
282 +               g_warning("did not finish in PARSER_FINISH state!");
283 +
284 +               if (state.interface)
285 +                       glade_interface_destroy(state.interface);
286 +
287 +               return NULL;
288 +       }
289 +
290 +       return state.interface;
291 +}
292 +
293 +struct _gzip_rfc1952_hdr
294 +{
295 +       guint8  id1, id2, cm, flags;
296 +       guint32 mtime;
297 +       guint8  xflags;
298 +       guint8  os;
299 +};
300 +
301 +static GladeInterface *
302 +glade_parser_parse_gzipped_buffer(const gchar *buffer, gint len, const gchar *domain)
303 +{
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;
310 +       gint                      ret;
311 +
312 +       g_assert(hdr != NULL && hdr->id1 == 0x1f && hdr->id2 == 0x8b);
313 +
314 +       if (hdr->cm != Z_DEFLATED) {
315 +               g_warning("Unknown decompression method %u", (guint) hdr->cm);
316 +               return NULL;
317 +       }
318 +
319 +       /* Uncompressed size (modulo 2^32) is last
320 +        *  4 bytes of gzipped file, and little endian.
321 +        *  See RFC 1952 */
322 +       decompress_len = GUINT32_FROM_LE(*((guint32*)(((guint8*)buffer) + len - 4)));
323 +
324 +       /* paranoid mode: glade files > 5MB are unlikely */
325 +       g_return_val_if_fail(decompress_len < 5*1024*1024, NULL);
326 +
327 +       decompress_buf = g_malloc0(decompress_len + 1); /* +1 for NUL-terminator */
328 +
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));
333 +               cbuf += xlen + 2;
334 +       }
335 +       if (hdr->flags & 0x08) {
336 +               guint16 onamelen = strlen(cbuf);
337 +               cbuf += onamelen + 1;
338 +       }
339 +       if (hdr->flags & 0x10) {
340 +               guint16 commentlen = strlen(cbuf);
341 +               cbuf += commentlen + 1;
342 +       }
343 +       if (hdr->flags & 0x02)
344 +       {
345 +               cbuf += 2; /* skip header CRC16 */
346 +       }
347 +
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;
355 +
356 +       ret = inflateInit2(&zstream, -MAX_WBITS);
357 +
358 +       if (ret != Z_OK) {
359 +               g_warning("inflateInit2() failed. zlib error code: %d", ret);
360 +               g_free(decompress_buf);
361 +               return NULL;
362 +       }
363 +
364 +       ret = inflate(&zstream, Z_FINISH);
365 +
366 +       if (ret != Z_STREAM_END) {
367 +               g_warning("zlib decompression failed. zlib error code: %d", ret);
368 +               g_free(decompress_buf);
369 +               return NULL;
370 +       }
371 +
372 +       interface = glade_parser_parse_buffer_internal(decompress_buf, decompress_len, domain);
373 +
374 +       g_free(decompress_buf);
375 +
376 +       return interface;
377 +}
378 +
379 +GladeInterface *
380 +glade_parser_parse_buffer(const gchar *buffer, gint len, const gchar *domain)
381 +{
382 +       g_return_val_if_fail(buffer != NULL, NULL);
383 +       g_return_val_if_fail(len > 0, NULL);
384 +
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);
388 +       }
389 +
390 +       /* Buffer is cleartext. */
391 +       return glade_parser_parse_buffer_internal(buffer, len, domain);
392 +}
393 +
394 +#endif /* USE_GMARKUP_PARSER */
395 +
396 +
397 +#ifndef USE_GMARKUP_PARSER
398 +
399  static void
400  dump_widget(xmlNode *parent, GladeWidgetInfo *info, gint indent)
401  {
402 @@ -1373,6 +1665,8 @@
403         xmlNodeAddContent(widget, "  ");
404  }
405  
406 +#endif /* !defined(USE_GMARKUP_PARSER) */
407 +
408  /**
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.
414   */
415 +
416 +#ifndef USE_GMARKUP_PARSER
417 +
418  void
419  glade_interface_dump(GladeInterface *interface, const gchar *filename)
420  {
421 @@ -1419,6 +1716,17 @@
422      xmlFreeDoc(doc);
423  }
424  
425 +#else /* defined(USE_GMARKUP_PARSER) */
426 +
427 +void
428 +glade_interface_dump(GladeInterface *interface, const gchar *filename)
429 +{
430 +    g_warning("glade_interface_dump() is only available with libxml2.");
431 +}
432 +
433 +#endif /* USE_GMARKUP_PARSER */
434 +
435 +
436  #if 0
437  int
438  main(int argc, char **argv) {
439
440
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
443 @@ -48,13 +48,36 @@
444  AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
445  
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)
453  
454 +
455 +disable_xml2=no
456 +AC_ARG_WITH([libxml2],
457 +  AC_HELP_STRING([--without-libxml2], [Don't use libxml2, use Glib's GMarkupParser instead]),
458 +  [disable_xml2=yes],
459 +  [disable_xml2=no])
460 +
461 +AC_MSG_CHECKING([if we are using libxml2])
462 +if test "x$disable_xml2" == "xno"; then
463 +  AC_MSG_RESULT(yes)
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"
468 +else
469 +  LIBGLADE_CFLAGS="$LIBGLADE_CFLAGS -DUSE_GMARKUP_PARSER"
470 +  PKGCFG_REQUIRE_LIBXML2=""
471 +  AC_MSG_RESULT(no)
472 +fi
473 +
474 +AC_SUBST(XML2_LIBS)
475 +AC_SUBST(XML2_CFLAGS)
476 +AC_SUBST(PKGCFG_REQUIRE_LIBXML2)
477 +
478  AC_MSG_CHECKING([for native Win32])
479  case "$host" in
480    *-*-mingw*)
481 @@ -114,6 +137,21 @@
482    fi
483  fi
484  
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." 
489 +  echo  
490 +  echo "  Please bear in mind that using libglade with"
491 +  echo "  GMarkupParser is an experimental feature only."
492 +  echo
493 +  echo "  Please post problems or success stories to"
494 +  echo "  the glade-devel mailing list. Thank you."
495 +  echo "*****************************************************"
496 +fi
497 +
498 +
499 +
500  GTK_DOC_CHECK(1.0)
501  
502  dnl gettext stuff ... there is no message catalog for libglade -- libglade