[comp.compression] A few fixes for pgencode/pgdecode

Peter_Gutmann@kcbbs.gen.nz (Peter Gutmann) (03/29/91)

Oh dear!  It appears that a line of pgdecode was truncated at 80 columns   
(sorry folks!).  Here's the full version:  It's towards the end of the  
pgdecode source:  
  
    /* Nitpick to make sure there's an end line */  
    if( fgets( buffer, sizeof( buffer ), inFilePtr ) == NULL || \  
        strcmp( buffer, "end\n" ) )  
                  
Thanks to Michael Lawler for pointing this out.  
  
Also, after I'd posted the code I realised I was being a bit over-paranoid   
with the code in encodeFile()/decodeFile().  In particular replacing the two  
while loops:  
  
        while( bitCount < LONG_CODE_BITS )  
            {  
            bitBuffer |= getc( inFilePtr ) << bitCount;  
            bitCount += CHAR_BIT;  
            }  
  
and:  
  
        while( bitCount >= CHAR_BIT )  
            {  
            putc( bitBuffer & 0xFF, outFilePtr );  
            bitBuffer >>= CHAR_BIT;  
            bitCount -= CHAR_BIT;  
            }  
  
with simple if statements:  
  
        if( bitCount < LONG_CODE_BITS )  
  
and:  
  
        if( bitCount >= CHAR_BIT )  
  
should give a slight program speedup.  
  
Another thing which I think I should mention is that the encoded files may   
not pass unscathed through some networks:  I think some of the chars produced 
have no EBCDIC equivalent for example (but I'll let the experts comment on  
that one).  
  
----------------------------------------------------------------------------  
  
 Peter_Gutmann@kcbbs.gen.nz || peter@nacjack.gen.nz || pgut1@cs.aukuni.ac.nz  
                     (In order of decreasing reliability)  
Warning!  
  Something large, scaly, and with fangs a foot long lives between <yoursite> 
and <mysite>.  Every now and then it kills and eats messages.  If you don't  
receive a reply within a week, try resending...  

madler@nntp-server.caltech.edu (Mark Adler) (03/30/91)

Peter Gutmann writes about his pgencode and pgdecode programs:

> Another thing which I think I should mention is that the encoded files may   
> not pass unscathed through some networks:  I think some of the chars produced 
> have no EBCDIC equivalent for example (but I'll let the experts comment on  
> that one).  

Since Peter uses all 94 non-control ASCII characters (I think of space as
a control character), the stuff will indeed have a hard time making it
through most any ASCII-EBCDIC translation.  Also, the code won't work as
is on an EBCDIC machine.

However, I have just stolen Peter's algorithm and added it to my ship
program as a "fast" encoding option.  I modified it slightly to use 86
(safe) characters instead of 94, and to make zeros encode better than,
rather than worse than other values.

As a reminder, ship uses base 85 encoding by default, includes a crc for
each file, will send multiple files, will automatically break files for
mailing, will automatically mail them, and will reassemble them at the
other end, checking for the correct sequence.  I will send it to anyone
who's interested in using it, provided they report back to me if it works,
and if they had to make any changes to get it to compile, run, or mail.

Mark Adler
madler@pooh.caltech.edu