home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 2 / RISC_DISC_2.iso / pd_share / utilities / cli / pgp2 / src / h / zunzip < prev   
Encoding:
Text File  |  1995-06-06  |  10.4 KB  |  333 lines

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