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