Magellan Linux

Contents of /trunk/mkinitrd-magellan/klibc/usr/gzip/gzip.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 532 - (show annotations) (download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 9 months ago) by niro
File MIME type: text/plain
File size: 10080 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd

1 /* gzip.h -- common declarations for all gzip modules
2 * Copyright (C) 1992-1993 Jean-loup Gailly.
3 * This is free software; you can redistribute it and/or modify it under the
4 * terms of the GNU General Public License, see the file COPYING.
5 */
6
7 #if defined(__STDC__) || defined(PROTO)
8 # define OF(args) args
9 #else
10 # define OF(args) ()
11 #endif
12
13 #ifdef __STDC__
14 typedef void *voidp;
15 #else
16 typedef char *voidp;
17 #endif
18
19 /* I don't like nested includes, but the string and io functions are used
20 * too often
21 */
22 #include <stdio.h>
23 #include <string.h>
24 #define memzero(s, n) memset ((voidp)(s), 0, (n))
25
26 #define local static
27
28 typedef unsigned char uch;
29 typedef unsigned short ush;
30 typedef unsigned long ulg;
31
32 /* Return codes from gzip */
33 #define OK 0
34 #define ERROR 1
35 #define WARNING 2
36
37 /* Compression methods (see algorithm.doc) */
38 #define STORED 0
39 #define COMPRESSED 1
40 #define PACKED 2
41 #define LZHED 3
42 /* methods 4 to 7 reserved */
43 #define DEFLATED 8
44 #define MAX_METHODS 9
45 extern int method; /* compression method */
46
47 /* To save memory for 16 bit systems, some arrays are overlaid between
48 * the various modules:
49 * deflate: prev+head window d_buf l_buf outbuf
50 * unlzw: tab_prefix tab_suffix stack inbuf outbuf
51 * inflate: window inbuf
52 * unpack: window inbuf prefix_len
53 * unlzh: left+right window c_table inbuf c_len
54 * For compression, input is done in window[]. For decompression, output
55 * is done in window except for unlzw.
56 */
57
58 #ifndef INBUFSIZ
59 # ifdef SMALL_MEM
60 # define INBUFSIZ 0x2000 /* input buffer size */
61 # else
62 # define INBUFSIZ 0x8000 /* input buffer size */
63 # endif
64 #endif
65 #define INBUF_EXTRA 64 /* required by unlzw() */
66
67 #ifndef OUTBUFSIZ
68 # ifdef SMALL_MEM
69 # define OUTBUFSIZ 8192 /* output buffer size */
70 # else
71 # define OUTBUFSIZ 16384 /* output buffer size */
72 # endif
73 #endif
74 #define OUTBUF_EXTRA 2048 /* required by unlzw() */
75
76 #ifndef DIST_BUFSIZE
77 # ifdef SMALL_MEM
78 # define DIST_BUFSIZE 0x2000 /* buffer for distances, see trees.c */
79 # else
80 # define DIST_BUFSIZE 0x8000 /* buffer for distances, see trees.c */
81 # endif
82 #endif
83
84 #ifdef DYN_ALLOC
85 # define EXTERN(type, array) extern type * near array
86 # define DECLARE(type, array, size) type * near array
87 # define ALLOC(type, array, size) { \
88 array = (type*)fcalloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \
89 if (array == NULL) error("insufficient memory"); \
90 }
91 # define FREE(array) {if (array != NULL) fcfree(array), array=NULL;}
92 #else
93 # define EXTERN(type, array) extern type array[]
94 # define DECLARE(type, array, size) type array[size]
95 # define ALLOC(type, array, size)
96 # define FREE(array)
97 #endif
98
99 EXTERN(uch, inbuf); /* input buffer */
100 EXTERN(uch, outbuf); /* output buffer */
101 EXTERN(ush, d_buf); /* buffer for distances, see trees.c */
102 EXTERN(uch, window); /* Sliding window and suffix table (unlzw) */
103 #define tab_suffix window
104 #ifndef MAXSEG_64K
105 # define tab_prefix prev /* hash link (see deflate.c) */
106 # define head (prev+WSIZE) /* hash head (see deflate.c) */
107 EXTERN(ush, tab_prefix); /* prefix code (see unlzw.c) */
108 #else
109 # define tab_prefix0 prev
110 # define head tab_prefix1
111 EXTERN(ush, tab_prefix0); /* prefix for even codes */
112 EXTERN(ush, tab_prefix1); /* prefix for odd codes */
113 #endif
114
115 extern unsigned insize; /* valid bytes in inbuf */
116 extern unsigned inptr; /* index of next byte to be processed in inbuf */
117 extern unsigned outcnt; /* bytes in output buffer */
118
119 extern long bytes_in; /* number of input bytes */
120 extern long bytes_out; /* number of output bytes */
121 extern long header_bytes;/* number of bytes in gzip header */
122
123 #define isize bytes_in
124 /* for compatibility with old zip sources (to be cleaned) */
125
126 extern int ifd; /* input file descriptor */
127 extern int ofd; /* output file descriptor */
128 extern char ifname[]; /* input file name or "stdin" */
129 extern char ofname[]; /* output file name or "stdout" */
130 extern char *progname; /* program name */
131
132 extern time_t time_stamp; /* original time stamp (modification time) */
133 extern long ifile_size; /* input file size, -1 for devices (debug only) */
134
135 typedef int file_t; /* Do not use stdio */
136 #define NO_FILE (-1) /* in memory compression */
137
138
139 #define PACK_MAGIC "\037\036" /* Magic header for packed files */
140 #define GZIP_MAGIC "\037\213" /* Magic header for gzip files, 1F 8B */
141 #define OLD_GZIP_MAGIC "\037\236" /* Magic header for gzip 0.5 = freeze 1.x */
142 #define LZH_MAGIC "\037\240" /* Magic header for SCO LZH Compress files*/
143 #define PKZIP_MAGIC "\120\113\003\004" /* Magic header for pkzip files */
144
145 /* gzip flag byte */
146 #define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
147 #define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
148 #define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
149 #define ORIG_NAME 0x08 /* bit 3 set: original file name present */
150 #define COMMENT 0x10 /* bit 4 set: file comment present */
151 #define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
152 #define RESERVED 0xC0 /* bit 6,7: reserved */
153
154 /* internal file attribute */
155 #define UNKNOWN 0xffff
156 #define BINARY 0
157 #define ASCII 1
158
159 #ifndef WSIZE
160 # define WSIZE 0x8000 /* window size--must be a power of two, and */
161 #endif /* at least 32K for zip's deflate method */
162
163 #define MIN_MATCH 3
164 #define MAX_MATCH 258
165 /* The minimum and maximum match lengths */
166
167 #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
168 /* Minimum amount of lookahead, except at the end of the input file.
169 * See deflate.c for comments about the MIN_MATCH+1.
170 */
171
172 #define MAX_DIST (WSIZE-MIN_LOOKAHEAD)
173 /* In order to simplify the code, particularly on 16 bit machines, match
174 * distances are limited to MAX_DIST instead of WSIZE.
175 */
176
177 extern int decrypt; /* flag to turn on decryption */
178 extern int exit_code; /* program exit code */
179 extern int verbose; /* be verbose (-v) */
180 extern int quiet; /* be quiet (-q) */
181 extern int level; /* compression level */
182 extern int test; /* check .z file integrity */
183 extern int to_stdout; /* output to stdout (-c) */
184 extern int save_orig_name; /* set if original name must be saved */
185
186 #define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf(0))
187 #define try_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf(1))
188
189 /* put_byte is used for the compressed output, put_ubyte for the
190 * uncompressed output. However unlzw() uses window for its
191 * suffix table instead of its output buffer, so it does not use put_ubyte
192 * (to be cleaned up).
193 */
194 #define put_byte(c) {outbuf[outcnt++]=(uch)(c); if (outcnt==OUTBUFSIZ)\
195 flush_outbuf();}
196 #define put_ubyte(c) {window[outcnt++]=(uch)(c); if (outcnt==WSIZE)\
197 flush_window();}
198
199 /* Output a 16 bit value, lsb first */
200 #define put_short(w) \
201 { if (outcnt < OUTBUFSIZ-2) { \
202 outbuf[outcnt++] = (uch) ((w) & 0xff); \
203 outbuf[outcnt++] = (uch) ((ush)(w) >> 8); \
204 } else { \
205 put_byte((uch)((w) & 0xff)); \
206 put_byte((uch)((ush)(w) >> 8)); \
207 } \
208 }
209
210 /* Output a 32 bit value to the bit stream, lsb first */
211 #define put_long(n) { \
212 put_short((n) & 0xffff); \
213 put_short(((ulg)(n)) >> 16); \
214 }
215
216 #define seekable() 0 /* force sequential output */
217 #define translate_eol 0 /* no option -a yet */
218
219 #define tolow(c) (isupper(c) ? (c)-'A'+'a' : (c)) /* force to lower case */
220
221 /* Macros for getting two-byte and four-byte header values */
222 #define SH(p) ((ush)(uch)((p)[0]) | ((ush)(uch)((p)[1]) << 8))
223 #define LG(p) ((ulg)(SH(p)) | ((ulg)(SH((p)+2)) << 16))
224
225 /* Diagnostic functions */
226 #ifdef DEBUG
227 # define Assert(cond,msg) {if(!(cond)) error(msg);}
228 # define Trace(x) fprintf x
229 # define Tracev(x) {if (verbose) fprintf x ;}
230 # define Tracevv(x) {if (verbose>1) fprintf x ;}
231 # define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
232 # define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
233 #else
234 # define Assert(cond,msg)
235 # define Trace(x)
236 # define Tracev(x)
237 # define Tracevv(x)
238 # define Tracec(c,x)
239 # define Tracecv(c,x)
240 #endif
241
242 #define WARN(msg) {if (!quiet) fprintf msg ; \
243 if (exit_code == OK) exit_code = WARNING;}
244
245 /* in zip.c: */
246 extern int zip OF((int in, int out));
247 extern int file_read OF((char *buf, unsigned size));
248
249 /* in unzip.c */
250 extern int unzip OF((int in, int out));
251 extern int check_zipfile OF((int in));
252
253 /* in gzip.c */
254 void abort_gzip OF((void));
255
256 /* in deflate.c */
257 void lm_init OF((int pack_level, ush *flags));
258 ulg deflate OF((void));
259
260 /* in trees.c */
261 void ct_init OF((ush *attr, int *method));
262 int ct_tally OF((int dist, int lc));
263 ulg flush_block OF((char *buf, ulg stored_len, int eof));
264
265 /* in bits.c */
266 void bi_init OF((file_t zipfile));
267 void send_bits OF((int value, int length));
268 unsigned bi_reverse OF((unsigned value, int length));
269 void bi_windup OF((void));
270 void copy_block OF((char *buf, unsigned len, int header));
271 extern int (*read_buf) OF((char *buf, unsigned size));
272
273 /* in util.c: */
274 extern int copy OF((int in, int out));
275 extern ulg updcrc OF((uch *s, unsigned n));
276 extern void clear_bufs OF((void));
277 extern int fill_inbuf OF((int eof_ok));
278 extern void flush_outbuf OF((void));
279 extern void flush_window OF((void));
280 extern void write_buf OF((int fd, voidp buf, unsigned cnt));
281 extern char *strlwr OF((char *s));
282 extern char *basename OF((char *fname));
283 extern void make_simple_name OF((char *name));
284 extern char *add_envopt OF((int *argcp, char ***argvp, char *env));
285 extern void error OF((char *m));
286 extern void warn OF((char *a, char *b));
287 extern void read_error OF((void));
288 extern void write_error OF((void));
289 extern void display_ratio OF((long num, long den, FILE *file));
290 extern voidp xmalloc OF((unsigned int size));
291
292 /* in inflate.c */
293 extern int inflate OF((void));
294
295 /* stuff from lzw.h */
296 #ifndef BITS
297 # define BITS 16
298 #endif