[Note to [EMAIL PROTECTED] subscribers: This mail concerns
a patch to add support for gzipped usb.ids file to usbutils. The first
iteration has been done privately with Thomas Sailer]


> Hi Aurelien,
Hi!

> in principle ok with me, but I find the ifdef's sprinkled around in the
> file slightly disgusting. Can you reduce the ifdef orgy by refactoring
> parse_file (move the contents of the while-fgets loop into another
> function, and then have two parse_file's, one for zipped, and one for
> plain files)? 

I have tried to do that, however it is not possible easily as there is a
lot of call to continue inside the while loop. I have instead use 
#define directives to select the normal or the gzip function. This 
results in only one #ifdef. You will find the new patch attached. I hope
you will like this solution :)

> And can the "zippedness" of the input file be
> autodetected? That would allow distributions for a smoother upgrade path
> (in fedora, f.e., the usb.ids file and usbutils are separate packages,
> so autodetecting the file type would decouple updating both packages).

This is already the case when compiled with gzip support. Actually this
is a feature of the zlib library, that can open normal file using the 
gz* functions when the gzip header is not found.

> And can you please post your message(s) also to [EMAIL PROTECTED]

Done with this mail :-)

Bye,
Aurelien

-- 
  .''`.  Aurelien Jarno             | GPG: 1024D/F1BCDB73
 : :' :  Debian developer           | Electrical Engineer
 `. `'   [EMAIL PROTECTED]         | [EMAIL PROTECTED]
   `-    people.debian.org/~aurel32 | www.aurel32.net
--- usbutils-0.72.orig/configure.in
+++ usbutils-0.72/configure.in
@@ -34,6 +34,24 @@
 AC_CHECK_LIB(usb, usb_get_string_simple, ,
        [AC_MSG_ERROR(get libusb 0.1.8 or newer)])
 
+
+dnl zlib on enabled by default (if found)
+USE_ZLIB=yes
+AC_ARG_ENABLE(zlib,
+  AC_HELP_STRING([--disable-zlib],
+                 [disable support for zlib]),
+  [
+    if eval "test x$enable_zlib = xno"; then
+      USE_ZLIB=
+    fi
+  ])
+if test "$USE_ZLIB" = "yes" ; then
+  AC_CHECK_LIB(z, inflateEnd)
+  if test "${ac_cv_lib_z_inflateEnd}" = "yes" ; then
+    HAVE_ZLIB="yes"
+  fi
+fi
+
 #AC_ARG_ENABLE(usbmodules,
 #      [  --enable-usbmodules     build usbmodules (for Linux 2.4)],
 #      [ case "${enableval}" in
--- usbutils-0.72.orig/names.c
+++ usbutils-0.72/names.c
@@ -38,6 +38,19 @@
 #include "config.h"
 #endif
 
+#ifdef HAVE_LIBZ
+#include <zlib.h>
+#define        my_file                         gzFile
+#define        my_fopen(path, mode)            gzopen(path, mode)
+#define        my_fgets(s, size, stream)       gzgets(stream, s, size)
+#define        my_close(f)                     gzclose(f)
+#else
+#define        my_file                         FILE*
+#define        my_fopen(path, mode)            fopen(path, mode)
+#define        my_fgets(s, size, stream)       fgets(s, size, stream)
+#define        my_close(f)                     fclose(f)
+#endif
+
 #include "names.h"
 
 
@@ -454,14 +467,14 @@
 
 #define DBG(x) 
 
-static void parse(FILE *f)
+static void parse(my_file f)
 {
        char buf[512], *cp;
        unsigned int linectr = 0;
        int lastvendor = -1, lastclass = -1, lastsubclass = -1, lasthut=-1, 
lastlang=-1;
        unsigned int u;
 
-       while (fgets(buf, sizeof(buf), f)) {
+       while (my_fgets(buf, sizeof(buf), f)) {
                linectr++;
                /* remove line ends */
                if ((cp = strchr(buf, 13)))
@@ -785,12 +798,12 @@
 
 int names_init(char *n)
 {
-       FILE *f;
+       my_file f;
        
-       if (!(f = fopen(n, "r"))) {
+       if (!(f = my_fopen(n, "r"))) {
                return errno;
        }
        parse(f);
-       fclose(f);
+       my_close(f);
        return 0;
 }
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to