|
|
1.1.1.8 ! 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: #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: #if defined(__TURBOC__) && !defined(__PUREC__) ! 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 __PUREC__ ! 125: # ifndef C370 /* not defined in C370 library */ ! 126: # include <fcntl.h> /* #define O_BINARY 0x8000 (no CR/LF */ ! 127: # endif /* !C370 */ ! 128: # endif ! 129: # endif /* ?COHERENT */ /* translation), as used in open() */ ! 130: # endif /* ?MTS */ ! 131: # endif /* ?V7 */ ! 132: #endif /* ?VMS */ ! 133: ! 134: /*--------------------------------------------------------------------------- ! 135: And some Mac stuff for good measure: ! 136: ---------------------------------------------------------------------------*/ ! 137: ! 138: #ifdef MACTC5 ! 139: # define MACOS ! 140: # ifndef __STDC__ /* THINK_C isn't truly ANSI-standard, */ ! 141: # define __STDC__ 1 /* but it understands prototypes...so */ ! 142: # endif /* it's close enough for our purposes */ ! 143: # include <time.h> ! 144: # include <unix.h> ! 145: #endif ! 146: #ifdef MPW /* not tested yet - should be easy enough tho */ ! 147: # define MACOS ! 148: # include <time.h> ! 149: # include <fcntl.h> ! 150: # include "macstat.h" ! 151: #endif ! 152: ! 153: /*--------------------------------------------------------------------------- ! 154: And finally, some random extra stuff: ! 155: ---------------------------------------------------------------------------*/ ! 156: ! 157: #include <stdlib.h> /* standard library prototypes, malloc(), etc. */ ! 158: #include <string.h> /* defines strcpy, strcmp, memcpy, etc. */ ! 159: ! 160: #ifdef MINIX ! 161: # include <stdio.h> ! 162: #endif ! 163: ! 164: ! 165: /*************/ ! 166: /* Defines */ ! 167: /*************/ ! 168: ! 169: #define INBUFSIZ BUFSIZ /* same as stdio uses */ ! 170: #define OUTBUFSIZ 0x2000 /* unImplode needs power of 2, >= 0x2000 */ ! 171: ! 172: #define MAX_BITS 13 /* used in unShrink() */ ! 173: #define HSIZE (1 << MAX_BITS) /* size of global work area */ ! 174: ! 175: #ifdef EBCDIC /* already defined in usuals.h */ ! 176: #undef LF ! 177: #undef CR ! 178: #else ! 179: #define LF 10 /* '\n' on ASCII machines. Must be 10 due to EBCDIC */ ! 180: #define CR 13 /* '\r' on ASCII machines. Must be 13 due to EBCDIC */ ! 181: #endif ! 182: ! 183: #ifdef AMIGA ! 184: # define FFLUSH fflush(stderr); ! 185: #else /* !AMIGA */ ! 186: # define FFLUSH ! 187: #endif /* ?AMIGA */ ! 188: ! 189: #ifndef TRUE ! 190: # define TRUE 1 /* sort of obvious */ ! 191: # define FALSE 0 ! 192: #endif ! 193: ! 194: #ifndef SEEK_SET /* These should all be declared in stdio.h! But */ ! 195: # define SEEK_SET 0 /* since they're not (in many cases), do so here. */ ! 196: # define SEEK_CUR 1 ! 197: # define SEEK_END 2 ! 198: #endif ! 199: ! 200: /**************/ ! 201: /* Typedefs */ ! 202: /**************/ ! 203: ! 204: typedef long longint; ! 205: typedef unsigned short UWORD; ! 206: #ifndef OS2 ! 207: typedef unsigned long ULONG; ! 208: #endif ! 209: ! 210: /*************************/ ! 211: /* Function Prototypes */ ! 212: /*************************/ ! 213: ! 214: #ifdef PROTO ! 215: ! 216: /* The following is for non-ansi compilers supporting prototypes */ ! 217: /* (e.g. old SGI compilers and Borland C in non-ansi mode */ ! 218: ! 219: #define __(X) X /* Inc. Should probably give them a call and see */ ! 220: #endif ! 221: ! 222: #ifndef __ /* This amusing little construct was swiped without */ ! 223: # if __STDC__ /* permission from the fine folks at Cray Research, */ ! 224: # define __(X) X /* Inc. Should probably give them a call and see */ ! 225: # else /* if they mind, but.... Then again, I can't think */ ! 226: # define __(X) () /* of any other way to do this, so maybe it's an */ ! 227: # endif /* algorithm? Whatever, thanks to CRI. (Note: */ ! 228: #endif /* keep interior stuff parenthesized.) */ ! 229: /* ! 230: * Toad Hall Note: Not to worry: I've seen this somewhere else too, ! 231: * so obviously it's been stolen more than once. ! 232: * That makes it public domain, right? ! 233: */ ! 234: ! 235: /*--------------------------------------------------------------------------- ! 236: Functions in file_io.c and crypt.c: ! 237: ---------------------------------------------------------------------------*/ ! 238: ! 239: int open_input_file __( (void) ); ! 240: int readbuf __( (char *buf, register unsigned size) ); ! 241: int create_output_file __( (void) ); ! 242: #if 0 ! 243: int FillBitBuffer __( (void) ); ! 244: int ReadByte __( (UWORD *x) ); ! 245: #else ! 246: int FillInBuf __( (void) ); ! 247: #endif ! 248: int FlushOutput __( (void) ); ! 249: ! 250: /*--------------------------------------------------------------------------- ! 251: Uncompression functions (all internal compression routines, enclosed in ! 252: comments below, are prototyped in their respective files and are invisi- ! 253: ble to external functions): ! 254: ---------------------------------------------------------------------------*/ ! 255: ! 256: int inflate __( (void) ); /* inflate.c */ ! 257: int unzip __( ( FILE *inFile, FILE *outFile ) ); ! 258: ! 259: /************/ ! 260: /* Macros */ ! 261: /************/ ! 262: ! 263: #ifndef min /* MSC defines this in stdlib.h */ ! 264: # define min(a,b) ((a) < (b) ? (a) : (b)) ! 265: #endif ! 266: ! 267: #define OUTB(intc) {*outptr++=intc; if (++outcnt==OUTBUFSIZ) FlushOutput();} ! 268: ! 269: /* ! 270: * macro OUTB(intc) ! 271: * { ! 272: * *outptr++ = intc; ! 273: * if (++outcnt == OUTBUFSIZ) ! 274: * FlushOutput(); ! 275: * } ! 276: * ! 277: */ ! 278: ! 279: ! 280: #if 0 ! 281: ! 282: #define READBIT(nbits,zdest) \ ! 283: do \ ! 284: { \ ! 285: if(nbits>bits_left) \ ! 286: FillBitBuffer(); \ ! 287: zdest=(int)(bitbuf&mask_bits[nbits]); \ ! 288: bitbuf>>=nbits; \ ! 289: bits_left-=nbits; \ ! 290: } while(0) ! 291: ! 292: /* ! 293: * macro READBIT(nbits,zdest) ! 294: * { ! 295: * if (nbits > bits_left) ! 296: * FillBitBuffer(); ! 297: * zdest = (int)(bitbuf & mask_bits[nbits]); ! 298: * bitbuf >>= nbits; ! 299: * bits_left -= nbits; ! 300: * } ! 301: * ! 302: */ ! 303: ! 304: #define PEEKBIT(nbits) ( nbits > bits_left ? \ ! 305: (FillBitBuffer(), bitbuf & mask_bits[nbits]) : bitbuf & mask_bits[nbits] ) ! 306: ! 307: #endif ! 308: ! 309: /*************/ ! 310: /* Globals */ ! 311: /*************/ ! 312: ! 313: #if 0 /* FIX */ ! 314: extern longint csize; ! 315: #endif ! 316: ! 317: extern ULONG mask_bits[]; ! 318: ! 319: extern byte *inbuf; ! 320: extern byte *inptr; ! 321: extern int incnt; ! 322: extern ULONG bitbuf; ! 323: extern int bits_left; ! 324: extern boolean zipeof; ! 325: extern int zipfd; ! 326: extern char zipfn[]; ! 327: ! 328: extern byte *outbuf; ! 329: extern byte *outptr; ! 330: extern byte *outout; ! 331: extern longint outpos; ! 332: extern int outcnt; ! 333: extern int outfd; ! 334: extern int disk_full;
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.