Annotation of pgp/src/zunzip.h, revision 1.1.1.3

1.1.1.2   root        1: /*---------------------------------------------------------------------------
                      2: 
                      3:   unzip.h
                      4: 
                      5:   This header file is used by all of the unzip source files.  Its contents
                      6:   were divided into seven more-or-less separate sections but have been
                      7:   hacked to death to minimize the total size and maximize compile speed by
                      8:   not including stuff not needed for the inflate-only compile.
                      9: 
                     10:   Modified 25 Jun 92 - HAJK
                     11:   Fix support for use in PGP/VMS
                     12:   ---------------------------------------------------------------------------*/
                     13: 
                     14: /***************************/
                     15: /*  OS-Dependent Includes  */
                     16: /***************************/
                     17: 
1.1.1.3 ! root       18: #include       "usuals.h"
        !            19: #include       "system.h"
1.1.1.2   root       20: 
                     21: #ifndef MINIX            /* Minix needs it after all the other includes (?) */
                     22: #  include <stdio.h>     /* this is your standard header for all C compiles */
                     23: #endif
                     24: 
                     25: /*---------------------------------------------------------------------------
                     26:     Next, a word from our Unix (mostly) sponsors:
                     27:   ---------------------------------------------------------------------------*/
                     28: 
                     29: #ifdef UNIX
                     30: #  ifdef AMIGA
                     31: #    include <libraries/dos.h>
                     32: #  else /* !AMIGA */
                     33: #    ifndef NO_PARAM_H
                     34: #      include <sys/param.h>   /* conflict with <sys/types.h>, some systems? */
                     35: #    endif /* !NO_PARAM_H */
                     36: #  endif /* ?AMIGA */
                     37: 
                     38: #  ifndef BSIZE
                     39: #    ifdef MINIX
                     40: #      define BSIZE   1024
                     41: #    else /* !MINIX */
                     42: #      define BSIZE   DEV_BSIZE  /* assume common for all Unix systems */
                     43: #    endif /* ?MINIX */
                     44: #  endif
                     45: 
                     46: #  ifndef BSD
                     47: #    if !defined(AMIGA) && !defined(MINIX)
                     48: #      define NO_MKDIR           /* for mapped_name() */
                     49: #    endif /* !AMIGA && !MINIX */
                     50: #    include <time.h>
                     51: #  else   /* BSD */
                     52: #    include <sys/time.h>
                     53: #    include <sys/timeb.h>
                     54: #  endif
                     55: 
                     56: #else   /* !UNIX */
                     57: #  define BSIZE   512               /* disk block size */
                     58: #endif /* ?UNIX */
                     59: 
                     60: /*---------------------------------------------------------------------------
                     61:     And now, our MS-DOS and OS/2 corner:
                     62:   ---------------------------------------------------------------------------*/
                     63: 
                     64: #ifdef __TURBOC__
                     65: #  define DOS_OS2             /* Turbo C under DOS, MSC under DOS or OS2    */
                     66: #  ifndef __BORLANDC__        /* There appears to be a bug ?? in Borland's  */
                     67: #      include <alloc.h>
                     68: #  endif
                     69: #else                         /* NOT Turbo C...                             */
                     70: #  ifdef MSDOS                /*   but still MS-DOS, so we'll assume it's   */
                     71: #    ifndef MSC               /*   Microsoft's compiler and fake the ID, if */
                     72: #      define MSC             /*   necessary (it is in 5.0; apparently not  */
                     73: #    endif                    /*   in 5.1 and 6.0)                          */
                     74: #    include <dos.h>          /* _dos_setftime()                            */
                     75: #  endif
                     76: #  ifdef OS2                  /* stuff for DOS and OS/2 family version */
                     77: #    ifndef MSC
                     78: #      define MSC
                     79: #    endif
                     80: #    define INCL_BASE
                     81: #    define INCL_NOPM
                     82: #    include <os2.h>          /* DosQFileInfo(), DosSetFileInfo()? */
                     83: #  endif
                     84: #endif
                     85: 
                     86: #ifdef MSC                    /* defined for all versions of MSC now         */
                     87: #  define DOS_OS2             /* Turbo C under DOS, MSC under DOS or OS/2    */
                     88: #  if defined(_MSC_VER) && (_MSC_VER >= 600)      /* new with 5.1 or 6.0 ... */
                     89: #    undef DECLARE_ERRNO      /* errno is now a function in a dynamic link   */
                     90: #  endif                      /*   library (or something)--incompatible with */
                     91: #endif                        /*   the usual "extern int errno" declaration  */
                     92: 
                     93: #ifdef DOS_OS2                /* defined for both Turbo C, MSC */
                     94: #  include <io.h>             /* lseek(), open(), setftime(), dup(), creat() */
                     95: #  include <time.h>           /* localtime() */
                     96: #endif
                     97: 
                     98: /*---------------------------------------------------------------------------
                     99:     Followed by some VMS (mostly) stuff:
                    100:   ---------------------------------------------------------------------------*/
                    101: 
                    102: #ifdef VMS
                    103: #  include <time.h>             /* the usual non-BSD time functions */
                    104: #  include <file.h>             /* same things as fcntl.h has */
                    105: #  include <rmsdef.h>           /* RMS error codes */
                    106: #  define UNIX                 /* can share most of same code from now on */
                    107: #  define RETURN   return      /* Don't Fake return    */
                    108: #else /* !VMS */
                    109: #  define RETURN   return       /* only used in main() */
                    110: #  ifdef V7
                    111: #    define O_RDONLY  0
                    112: #    define O_WRONLY  1
                    113: #    define O_RDWR    2
                    114: #  else /* !V7 */
                    115: #    ifdef MTS
                    116: #      include <sys/file.h>     /* MTS uses this instead of fcntl.h */
                    117: #    else /* !MTS */
                    118: #      ifdef COHERENT           /* Coherent 3.10/Mark Williams C */
                    119: #        include <sys/fcntl.h>
                    120: #        define SHORT_NAMES
                    121: #        define tzset  settz
                    122: #      else /* !COHERENT */
                    123: #        include <fcntl.h>      /* #define O_BINARY 0x8000 (no CR/LF */
                    124: #      endif /* ?COHERENT */    /*   translation), as used in open() */
                    125: #    endif /* ?MTS */
                    126: #  endif /* ?V7 */
                    127: #endif /* ?VMS */
                    128: 
                    129: /*---------------------------------------------------------------------------
                    130:     And some Mac stuff for good measure:
                    131:   ---------------------------------------------------------------------------*/
                    132: 
                    133: #ifdef THINK_C
                    134: #  define MACOS
                    135: #  ifndef __STDC__            /* THINK_C isn't truly ANSI-standard, */
                    136: #    define __STDC__ 1        /*   but it understands prototypes...so */
                    137: #  endif                      /*   it's close enough for our purposes */
                    138: #  include <time.h>
                    139: #  include <unix.h>
                    140: #  include "macstat.h"
                    141: #endif
                    142: #ifdef MPW                    /* not tested yet - should be easy enough tho */
                    143: #  define MACOS
                    144: #  include <time.h>
                    145: #  include <fcntl.h>
                    146: #  include "macstat.h"
                    147: #endif
                    148: 
                    149: /*---------------------------------------------------------------------------
                    150:     And finally, some random extra stuff:
                    151:   ---------------------------------------------------------------------------*/
                    152: 
                    153: #include <stdlib.h>      /* standard library prototypes, malloc(), etc. */
                    154: #include <string.h>      /* defines strcpy, strcmp, memcpy, etc. */
                    155: 
                    156: #ifdef MINIX
                    157: #  include <stdio.h>
                    158: #endif
                    159: 
                    160: 
                    161: /*************/
                    162: /*  Defines  */
                    163: /*************/
                    164: 
                    165: #define INBUFSIZ          BUFSIZ   /* same as stdio uses */
                    166: #define OUTBUFSIZ       0x2000     /* unImplode needs power of 2, >= 0x2000 */
                    167: 
                    168: #define MAX_BITS      13                 /* used in unShrink() */
                    169: #define HSIZE         (1 << MAX_BITS)    /* size of global work area */
                    170: 
                    171: #define LF   10   /* '\n' on ASCII machines.  Must be 10 due to EBCDIC */
                    172: #define CR   13   /* '\r' on ASCII machines.  Must be 13 due to EBCDIC */
                    173: 
                    174: #ifdef AMIGA
                    175: #  define FFLUSH    fflush(stderr);
                    176: #else /* !AMIGA */
                    177: #  define FFLUSH
                    178: #endif /* ?AMIGA */
                    179: 
                    180: #ifndef TRUE
                    181: #  define TRUE      1   /* sort of obvious */
                    182: #  define FALSE     0
                    183: #endif
                    184: 
                    185: #ifndef SEEK_SET        /* These should all be declared in stdio.h!  But   */
                    186: #  define SEEK_SET  0   /*  since they're not (in many cases), do so here. */
                    187: #  define SEEK_CUR  1
                    188: #  define SEEK_END  2
                    189: #endif
                    190: 
                    191: /**************/
                    192: /*  Typedefs  */
                    193: /**************/
                    194: 
                    195: typedef long             longint;
                    196: typedef unsigned short   UWORD;
                    197: #ifndef OS2
                    198: typedef unsigned long    ULONG;
                    199: #endif
                    200: 
                    201: /*************************/
                    202: /*  Function Prototypes  */
                    203: /*************************/
                    204: 
1.1.1.3 ! root      205: #ifdef PROTO
        !           206: 
        !           207: /* The following is for non-ansi compilers supporting prototypes */
        !           208: /* (e.g. old SGI compilers and Borland C in non-ansi mode */ 
        !           209: 
        !           210: #define __(X)   X   /*  Inc.  Should probably give them a call and see   */
        !           211: #endif
        !           212: 
1.1.1.2   root      213: #ifndef __              /* This amusing little construct was swiped without  */
                    214: #  if __STDC__          /*  permission from the fine folks at Cray Research, */
                    215: #    define __(X)   X   /*  Inc.  Should probably give them a call and see   */
                    216: #  else                 /*  if they mind, but....  Then again, I can't think */
                    217: #    define __(X)   ()  /*  of any other way to do this, so maybe it's an    */
                    218: #  endif                /*  algorithm?  Whatever, thanks to CRI.  (Note:     */
                    219: #endif                  /*  keep interior stuff parenthesized.)              */
                    220: /*
                    221:  * Toad Hall Note:  Not to worry:  I've seen this somewhere else too,
                    222:  * so obviously it's been stolen more than once.
                    223:  * That makes it public domain, right?
                    224:  */
                    225: 
                    226: /*---------------------------------------------------------------------------
                    227:     Functions in file_io.c and crypt.c:
                    228:   ---------------------------------------------------------------------------*/
                    229: 
                    230: int    open_input_file           __( (void) );
                    231: int    readbuf                   __( (char *buf, register unsigned size) );
                    232: int    create_output_file        __( (void) );
                    233: int    FillBitBuffer             __( (void) );
                    234: int    ReadByte                  __( (UWORD *x) );
                    235: int    FlushOutput               __( (void) );
                    236: 
                    237: /*---------------------------------------------------------------------------
                    238:     Uncompression functions (all internal compression routines, enclosed in
                    239:     comments below, are prototyped in their respective files and are invisi-
                    240:     ble to external functions):
                    241:   ---------------------------------------------------------------------------*/
                    242: 
                    243: void   inflate                  __( (void) );                  /* inflate.c */
                    244: int unzip                              __( ( FILE *inFile, FILE *outFile ) );
                    245: 
                    246: /************/
                    247: /*  Macros  */
                    248: /************/
                    249: 
                    250: #ifndef min    /* MSC defines this in stdlib.h */
                    251: #  define min(a,b)   ((a) < (b) ? (a) : (b))
                    252: #endif
                    253: 
                    254: #define OUTB(intc) {*outptr++=intc; if (++outcnt==OUTBUFSIZ) FlushOutput();}
                    255: 
                    256: /*
                    257:  *  macro OUTB(intc)
                    258:  *  {
                    259:  *      *outptr++ = intc;
                    260:  *      if (++outcnt == OUTBUFSIZ)
                    261:  *          FlushOutput();
                    262:  *  }
                    263:  *
                    264:  */
                    265: 
                    266: 
1.1.1.3 ! root      267: #define READBIT(nbits,zdest) \
        !           268:        do \
        !           269:        { \
        !           270:                if(nbits>bits_left) \
        !           271:                        FillBitBuffer(); \
        !           272:                zdest=(int)(bitbuf&mask_bits[nbits]); \
        !           273:                bitbuf>>=nbits; \
        !           274:                bits_left-=nbits; \
        !           275:        } while(0)
1.1.1.2   root      276: 
                    277: /*
                    278:  * macro READBIT(nbits,zdest)
                    279:  *  {
                    280:  *      if (nbits > bits_left)
                    281:  *          FillBitBuffer();
                    282:  *      zdest = (int)(bitbuf & mask_bits[nbits]);
                    283:  *      bitbuf >>= nbits;
                    284:  *      bits_left -= nbits;
                    285:  *  }
                    286:  *
                    287:  */
                    288: 
                    289: #define PEEKBIT(nbits) ( nbits > bits_left ? (FillBitBuffer(), bitbuf & mask_bits[nbits]) : bitbuf & mask_bits[nbits] )
                    290: 
                    291: /*************/
                    292: /*  Globals  */
                    293: /*************/
                    294: 
                    295:    extern longint   csize;
                    296: 
                    297:    extern ULONG     mask_bits[];
                    298: 
                    299:    extern byte      *inbuf;
                    300:    extern byte      *inptr;
                    301:    extern int       incnt;
                    302:    extern ULONG     bitbuf;
                    303:    extern int       bits_left;
                    304:    extern boolean   zipeof;
                    305:    extern int       zipfd;
                    306:    extern char      zipfn[];
                    307: 
                    308:    extern byte      *outbuf;
                    309:    extern byte      *outptr;
                    310:    extern byte      *outout;
                    311:    extern longint   outpos;
                    312:    extern int       outcnt;
                    313:    extern int       outfd;
                    314:    extern int       disk_full;

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.