#if defined(__STDC__) || defined(PROTO)
# define OF(args) args
#else
# define OF(args) ()
#endif
#ifdef __STDC__
typedef void *voidp;
#else
typedef char *voidp;
#endif
#include <stdio.h>
#include <sys/types.h>
#if defined HAVE_STRING_H || defined STDC_HEADERS
# include <string.h>
# if !defined STDC_HEADERS && defined HAVE_MEMORY_H && !defined __GNUC__
# include <memory.h>
# endif
# define memzero(s, n) memset ((voidp)(s), 0, (n))
#else
# include <strings.h>
# define strchr index
# define strrchr rindex
# define memcpy(d, s, n) bcopy((s), (d), (n))
# define memcmp(s1, s2, n) bcmp((s1), (s2), (n))
# define memzero(s, n) bzero((s), (n))
#endif
#ifndef RETSIGTYPE
# define RETSIGTYPE void
#endif
#define local static
typedef unsigned char uch;
typedef unsigned short ush;
typedef unsigned long ulg;
#define OK 0
#define ERROR 1
#define WARNING 2
#define STORED 0
#define COMPRESSED 1
#define PACKED 2
#define LZHED 3
#define DEFLATED 8
#define MAX_METHODS 9
extern int method;
#ifndef INBUFSIZ
# ifdef SMALL_MEM
# define INBUFSIZ 0x2000
# else
# define INBUFSIZ 0x8000
# endif
#endif
#define INBUF_EXTRA 64
#ifndef OUTBUFSIZ
# ifdef SMALL_MEM
# define OUTBUFSIZ 8192
# else
# define OUTBUFSIZ 16384
# endif
#endif
#define OUTBUF_EXTRA 2048
#ifndef DIST_BUFSIZE
# ifdef SMALL_MEM
# define DIST_BUFSIZE 0x2000
# else
# define DIST_BUFSIZE 0x8000
# endif
#endif
#ifdef DYN_ALLOC
# define EXTERN(type, array) extern type * near array
# define DECLARE(type, array, size) type * near array
# define ALLOC(type, array, size) { \
array = (type*)fcalloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \
if (array == NULL) error("insufficient memory"); \
}
# define FREE(array) {if (array != NULL) fcfree(array), array=NULL;}
#else
# define EXTERN(type, array) extern type array[]
# define DECLARE(type, array, size) type array[size]
# define ALLOC(type, array, size)
# define FREE(array)
#endif
EXTERN(uch, inbuf);
EXTERN(uch, outbuf);
EXTERN(ush, d_buf);
EXTERN(uch, window);
#define tab_suffix window
#ifndef MAXSEG_64K
# define tab_prefix prev
# define head (prev+WSIZE)
EXTERN(ush, tab_prefix);
#else
# define tab_prefix0 prev
# define head tab_prefix1
EXTERN(ush, tab_prefix0);
EXTERN(ush, tab_prefix1);
#endif
extern unsigned insize;
extern unsigned inptr;
extern unsigned outcnt;
extern off_t bytes_in;
extern off_t bytes_out;
extern off_t header_bytes;
extern int ifd;
extern int ofd;
extern char ifname[];
extern char ofname[];
extern char *progname;
extern time_t time_stamp;
extern off_t ifile_size;
typedef int file_t;
#define NO_FILE (-1)
#define PACK_MAGIC "\037\036"
#define GZIP_MAGIC "\037\213"
#define OLD_GZIP_MAGIC "\037\236"
#define LZH_MAGIC "\037\240"
#define PKZIP_MAGIC "\120\113\003\004"
#define ASCII_FLAG 0x01
#define CONTINUATION 0x02
#define EXTRA_FIELD 0x04
#define ORIG_NAME 0x08
#define COMMENT 0x10
#define ENCRYPTED 0x20
#define RESERVED 0xC0
#define UNKNOWN 0xffff
#define BINARY 0
#define ASCII 1
#ifndef WSIZE
# define WSIZE 0x8000
#endif
#define MIN_MATCH 3
#define MAX_MATCH 258
#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
#define MAX_DIST (WSIZE-MIN_LOOKAHEAD)
extern int decrypt;
extern int exit_code;
extern int verbose;
extern int quiet;
extern int level;
extern int test;
extern int to_stdout;
extern int save_orig_name;
#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf(0))
#define try_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf(1))
#define put_byte(c) {outbuf[outcnt++]=(uch)(c); if (outcnt==OUTBUFSIZ)\
flush_outbuf();}
#define put_ubyte(c) {window[outcnt++]=(uch)(c); if (outcnt==WSIZE)\
flush_window();}
#define put_short(w) \
{ if (outcnt < OUTBUFSIZ-2) { \
outbuf[outcnt++] = (uch) ((w) & 0xff); \
outbuf[outcnt++] = (uch) ((ush)(w) >> 8); \
} else { \
put_byte((uch)((w) & 0xff)); \
put_byte((uch)((ush)(w) >> 8)); \
} \
}
#define put_long(n) { \
put_short((n) & 0xffff); \
put_short(((ulg)(n)) >> 16); \
}
#define seekable() 0
#define translate_eol 0
#define tolow(c) (isupper (c) ? tolower (c) : (c))
#define SH(p) ((ush)(uch)((p)[0]) | ((ush)(uch)((p)[1]) << 8))
#define LG(p) ((ulg)(SH(p)) | ((ulg)(SH((p)+2)) << 16))
#ifdef DEBUG
# define Assert(cond,msg) {if(!(cond)) error(msg);}
# define Trace(x) fprintf x
# define Tracev(x) {if (verbose) fprintf x ;}
# define Tracevv(x) {if (verbose>1) fprintf x ;}
# define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
#else
# define Assert(cond,msg)
# define Trace(x)
# define Tracev(x)
# define Tracevv(x)
# define Tracec(c,x)
# define Tracecv(c,x)
#endif
#define WARN(msg) {if (!quiet) fprintf msg ; \
if (exit_code == OK) exit_code = WARNING;}
extern int zip OF((int in, int out));
extern int file_read OF((char *buf, unsigned size));
extern int unzip OF((int in, int out));
extern int check_zipfile OF((int in));
extern int unpack OF((int in, int out));
extern int unlzh OF((int in, int out));
RETSIGTYPE abort_gzip OF((void));
void lm_init OF((int pack_level, ush *flags));
off_t deflate OF((void));
void ct_init OF((ush *attr, int *method));
int ct_tally OF((int dist, int lc));
off_t flush_block OF((char *buf, ulg stored_len, int eof));
void bi_init OF((file_t zipfile));
void send_bits OF((int value, int length));
unsigned bi_reverse OF((unsigned value, int length));
void bi_windup OF((void));
void copy_block OF((char *buf, unsigned len, int header));
extern int (*read_buf) OF((char *buf, unsigned size));
extern int copy OF((int in, int out));
extern ulg updcrc OF((uch *s, unsigned n));
extern void clear_bufs OF((void));
extern int fill_inbuf OF((int eof_ok));
extern void flush_outbuf OF((void));
extern void flush_window OF((void));
extern void write_buf OF((int fd, voidp buf, unsigned cnt));
extern char *strlwr OF((char *s));
extern char *base_name OF((char *fname));
extern int xunlink OF((char *fname));
extern void make_simple_name OF((char *name));
extern char *add_envopt OF((int *argcp, char ***argvp, char *env));
extern void error OF((char *m));
extern void warning OF((char *m));
extern void read_error OF((void));
extern void write_error OF((void));
extern void display_ratio OF((off_t num, off_t den, FILE *file));
extern void fprint_off OF((FILE *, off_t, int));
extern voidp xmalloc OF((unsigned int size));
extern int inflate OF((void));
extern int yesno OF((void));