cURL / Mailing Lists / curl-users / Single Mail

curl-users

Patch for compressed help

From: Gisle Vanem <gvanem_at_broadpark.no>
Date: Mon, 28 Jul 2003 20:08:04 +0200

I cannot get the ./src/mkhelp.pl script to generate compressed help text.
Seems the $c variable is unitialised; where is it assigned from $ARGV[0]?

I'm no Perl expert, but came up with this patch:

--- ./src/mkhelp.pl.org Wed Jul 28 14:16:34 2003
+++ ./src/mkhelp.pl Mon Jul 28 16:12:24 2003
@@ -6,10 +6,19 @@
 # THEY DON'T FIT ME :-)

 # Get readme file as parameter:
-$README = $ARGV[0];
+
+my ($c, $README);
+
+if ($ARGV[0] eq "-c") {
+ $c = 1;
+ $README = $ARGV[1];
+} else {
+ $c = 0;
+ $README = $ARGV[0];
+}

-------------------------------------------------------------------------------------

The second problem is that
  open(GZIP, "|gzip -9 >dumpit.gz")

just doesn't work under my Perl (ActiveState perl for Win32).
"gzip -tv dumpit.gz" fails. I assume it's related to binary/ascii mode
of STDOUT or something hairy. Or maybe it's my gzip which is too
old (1.2.4). I patched mkhelp.pl by simply spawning "gzip -9f dumpit".

But this needed some more checks in hugehelp() before inflating
the buffer.

-----------------------------------------------------------------------------------
@@ -70,14 +79,13 @@
 if($c) {
     my @test = `gzip --version 2>&1`;
     if($test[0] =~ /gzip/) {
- open(GZIP, "|gzip -9 >dumpit.gz") ||
- die "can't run gzip, try without -c";
- binmode GZIP;
+ open(DUMP, ">dumpit") || die "can't open dump file, try without -c";
         for(@out) {
- print GZIP $_;
+ print DUMP $_;
             $gzip += length($_);
         }
- close(GZIP);
+ close(DUMP);
+ system("gzip -9f dumpit");

         open(GZIP, "<dumpit.gz");
         binmode GZIP;
@@ -103,6 +110,7 @@
  * Generation time: $now
  */
 #include <stdio.h>
+#include <string.h>
 HEAD
     ;
 if($c) {
@@ -131,26 +139,63 @@
     print "\n};\n";

     print <<EOF
-/* Decompress and send to stdout a gzip-compressed buffer */
+
+#define HEAD_CRC 0x02 /* bit 1 set: header CRC present */
+#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
+#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
+#define COMMENT 0x10 /* bit 4 set: file comment present */
+
+/* Decompress and send to stdout a gzip-compressed buffer
+ */
 void hugehelp(void)
 {
   unsigned char buf[0x10000];
- int status,headerlen;
+ const unsigned char *p;
+ int status, rc;
+ int gz_method, gz_flags;
   z_stream z;

- /* Make sure no gzip options are set */
- if (hugehelpgz[3] & 0xfe)
- return;
-
- headerlen = 10;
- z.avail_in = sizeof(hugehelpgz) - headerlen;
- z.next_in = (unsigned char *)hugehelpgz + headerlen;
+ p = hugehelpgz + 2; /* assume gz magic okay */
+ gz_method = *p++;
+ gz_flags = *p++;
+
+ p += 6; /* skip gzip header */
+
+ if (gz_method != Z_DEFLATED) {
+ fprintf (stderr, "hugehelp(): gzip not deflated\\n");
+ return;
+ }
+
+ if (gz_flags & EXTRA_FIELD) {
+ int extra_len = *p + (*(p+1) << 8);
+ p += extra_len;
+ }
+
+ if (gz_flags & ORIG_NAME) { /* skip the original file name */
+ while (*p)
+ p++;
+ p++;
+ }
+
+ if (gz_flags & COMMENT) { /* skip the .gz file comment */
+ while (*p)
+ p++;
+ p++;
+ }
+
+ if (gz_flags & HEAD_CRC) /* skip the header crc */
+ p += 2;
+
+ memset (&z, 0, sizeof(z));
+ z.avail_in = sizeof(hugehelpgz) - (p - hugehelpgz);
+ z.next_in = p;
   z.zalloc = (alloc_func)Z_NULL;
   z.zfree = (free_func)Z_NULL;
- z.opaque = 0;

- if (inflateInit2(&z, -MAX_WBITS) != Z_OK)
+ if ((rc = inflateInit2(&z, -MAX_WBITS)) != Z_OK) {
+ fprintf (stderr, "hugehelp(): inflateInit2() failed, rc %d\\n", rc);
     return;
+ }

   for (;;) {
     z.avail_out = (int)sizeof(buf);
@@ -160,8 +205,10 @@
       fwrite(buf, sizeof(buf) - z.avail_out, 1, stdout);
       if (status == Z_STREAM_END)
          break;
- } else
+ } else {
+ fprintf (stderr, "hugehelp(): inflate() failed, rc %d\\n", status);
       break; /* Error */
+ }
   }
   inflateEnd(&z);
 }

-----------------------------------------------------------------------------------

PS. Anybody know how to get groff/nroff to produce a wider
man output?

Gisle V.

# rm /bin/laden
/bin/laden: Not found

-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
Received on 2003-07-28