File libgweather-bnc428346-compress.patch of Package libgweather

Index: configure.in
===================================================================
--- configure.in	(révision 475)
+++ configure.in	(copie de travail)
@@ -40,6 +40,18 @@ AC_ARG_ENABLE(all-translations-in-one-xm
         [enable_big_xml=no])
 AM_CONDITIONAL(USE_ONE_BIG_XML, test "x$enable_big_xml" = "xyes")
 
+AC_ARG_ENABLE(locations-compression,
+        [AC_HELP_STRING([--enable-locations-compression],
+                        [Compress Locations.xml files])],
+        [enable_locations_compression=yes],
+        [enable_locations_compression=no])
+if test "x$enable_locations_compression" = "xyes"; then
+    COMPRESS_EXT=.gz
+else
+    COMPRESS_EXT=
+fi
+AC_SUBST(COMPRESS_EXT)
+
 GNOME_COMPILE_WARNINGS
 
 dnl ***************************************************************************
@@ -223,4 +235,5 @@ libgweather-$VERSION configure summary:
 	Source code location:		${srcdir}
 	Compiler:			${CC}
 	Locations.xml translations:	${LOCATIONS_XML_TRANSLATIONS}
+	Locations.xml compression:	${enable_locations_compression}
 " >&2
Index: data/Makefile.am
===================================================================
--- data/Makefile.am	(révision 475)
+++ data/Makefile.am	(copie de travail)
@@ -8,10 +8,13 @@ if USE_ONE_BIG_XML
 
 LOCATIONS_STAMP = 
 
-libgweatherlocations_DATA = $(libgweatherlocations_in_files:.xml.in=.xml)
+libgweatherlocations_DATA = $(libgweatherlocations_in_files:.xml.in=.xml$(COMPRESS_EXT))
 
-%.xml: %.xml.in $(wildcard $(top_srcdir)/po-locations/*.po)
-	LC_ALL=C $(INTLTOOL_MERGE) -x -u -c $(top_builddir)/po-locations/.intltool-merge-cache $(top_srcdir)/po-locations $< $@
+%.xml$(COMPRESS_EXT): %.xml.in $(wildcard $(top_srcdir)/po-locations/*.po)
+	LC_ALL=C $(INTLTOOL_MERGE) -x -u -c $(top_builddir)/po-locations/.intltool-merge-cache $(top_srcdir)/po-locations $< `echo $@ | sed "s/.xml$(COMPRESS_EXT)/.xml/"`
+	if test "x$(COMPRESS_EXT)" = "x.gz"; then				\
+		gzip --force `echo $@ | sed "s/.xml$(COMPRESS_EXT)/.xml/"`;	\
+	fi
 
 else # USE_ONE_BIG_XML
 
@@ -22,24 +25,30 @@ PO_LOCATIONS = $(shell if test -n "$(LIN
 # Helper variable
 libgweatherlocations_data = $(libgweatherlocations_in_files:.xml.in=.xml)
 
-libgweatherlocations_DATA = $(shell echo $(PO_LOCATIONS) | sed "s|$(top_srcdir)/po-locations/|Locations.|g;s|\.po|.xml|g") $(libgweatherlocations_data)
+libgweatherlocations_DATA = $(shell echo $(PO_LOCATIONS) | sed "s|$(top_srcdir)/po-locations/|Locations.|g;s|\.po|.xml$(COMPRESS_EXT)|g") $(libgweatherlocations_data)$(COMPRESS_EXT)
 
 # We need this step so that we merge all the make Locations.xy.xml destinations
 # into one unique destination. This makes -j2 work. (Else, we end up with
 # multiple and conflicting calls to intltool-merge)
 $(libgweatherlocations_DATA): $(LOCATIONS_STAMP)
 
-$(LOCATIONS_STAMP): $(libgweatherlocations_in_files) $(PO_LOCATIONS)
+$(LOCATIONS_STAMP): $(libgweatherlocations_in_files) $(PO_LOCATIONS) Makefile
 	LC_ALL=C $(INTLTOOL_MERGE) --multiple-output --xml-style --utf8 --cache=$(top_builddir)/po-locations/.intltool-merge-cache $(top_srcdir)/po-locations $< $(libgweatherlocations_data)
 	for pofile in $(PO_LOCATIONS); do \
 		locale=`echo $$pofile | sed "s;$(top_srcdir)/po-locations/\(.*\)\.po;\1;"`;	\
 		xmllint --noblanks -o Locations.$$locale.xml $$locale/$(libgweatherlocations_data); \
 		rm -f $$locale/$(libgweatherlocations_data);		\
 		test -d $$locale && rmdir $$locale;			\
+		if test "x$(COMPRESS_EXT)" = "x.gz"; then		\
+			gzip --force Locations.$$locale.xml;		\
+		fi;							\
 	done
 	xmllint --noblanks -o Locations.xml C/$(libgweatherlocations_data)
 	rm -f C/$(libgweatherlocations_data)
 	test -d C && rmdir C
+	if test "x$(COMPRESS_EXT)" = "x.gz"; then			\
+		gzip --force Locations.xml;				\
+	fi
 	touch $@
 
 endif # USE_ONE_BIG_XML
Index: libgweather/parser.c
===================================================================
--- libgweather/parser.c	(révision 475)
+++ libgweather/parser.c	(copie de travail)
@@ -155,6 +155,7 @@ GWeatherParser *
 gweather_parser_new (gboolean use_regions)
 {
     GWeatherParser *parser;
+    int zlib_support;
     int i, keep_going;
     char *filename;
     char *tagname, *format;
@@ -165,6 +166,8 @@ gweather_parser_new (gboolean use_region
     parser->use_regions = use_regions;
     parser->locales = g_get_language_names ();
 
+    zlib_support = xmlHasFeature (XML_WITH_ZLIB);
+
     /* First try to load a locale-specific XML. It's much faster. */
     filename = NULL;
     for (i = 0; parser->locales[i] != NULL; i++) {
@@ -177,6 +180,19 @@ gweather_parser_new (gboolean use_region
 
 	g_free (filename);
 	filename = NULL;
+
+        if (!zlib_support)
+            continue;
+
+	filename = g_strdup_printf ("%s/Locations.%s.xml.gz",
+				    GWEATHER_XML_LOCATION_DIR,
+				    parser->locales[i]);
+
+	if (g_file_test (filename, G_FILE_TEST_IS_REGULAR))
+	    break;
+
+	g_free (filename);
+	filename = NULL;
     }
 
     /* Fall back on the file containing either all translations, or only
@@ -185,6 +201,11 @@ gweather_parser_new (gboolean use_region
     if (!filename)
 	filename = g_strdup (GWEATHER_XML_LOCATION_DIR "/Locations.xml");
 
+    if (!g_file_test (filename, G_FILE_TEST_IS_REGULAR) && zlib_support) {
+        g_free (filename);
+	filename = g_strdup (GWEATHER_XML_LOCATION_DIR "/Locations.xml.gz");
+    }
+
     /* Open the xml file containing the different locations */
     parser->xml = xmlNewTextReaderFilename (filename);
     g_free (filename);
openSUSE Build Service is sponsored by