5 * gzip support routine declartions..
6 * =========================================================
15 # define DBG(x) printf x
30 static unsigned char *inbuf; /* input buffer */
31 static unsigned int insize; /* valid bytes in inbuf */
32 static unsigned int inptr; /* index of next byte to be processed in inbuf */
35 #define get_byte() (inptr < insize ? inbuf[inptr++] : 0)
37 static unsigned char get_byte(void)
40 unsigned char byte = (inptr < insize ? inbuf[inptr++] : 0);
42 printf("%02x ", byte);
43 if ((++count & 0x0f) == 0) {
52 static void flush_window(void);
54 static long bytes_out; /* total bytes compressed */
55 static unsigned outcnt; /* bytes in output buffer */
57 #define WSIZE 0x8000 /* Window size must be at least 32k, and a power of two */
58 static unsigned char window[WSIZE]; /* Sliding window buffer */
68 #define memzero(s, n) memset ((s), 0, (n))
70 typedef unsigned char uch;
71 typedef unsigned short ush;
72 typedef unsigned long ulg;
79 /* Variables that gunzip doesn't need to see... */
80 static unsigned char *output_ptr;
81 static unsigned long end_offset;
82 static struct unzip_region {
84 unsigned long end_offset;
87 /* Data provided by the header */
88 extern unsigned char zipped_data[];
89 extern unsigned char zipped_data_end[];
90 extern unsigned char entry;
91 /* Assembly language routines */
92 extern void jmp_to_program_entry(void *);
94 /* ===========================================================================
95 * Write the output window window[0..outcnt-1] and update crc and bytes_out.
96 * (Used for the decompressed data only.)
98 static void flush_window(void)
100 ulg c = crc; /* temporary variable */
111 limit = end_offset - bytes_out +n;
112 if (limit > outcnt) {
116 DBG(("flush 0x%08lx start 0x%08lx limit 0x%08lx\n",
117 (unsigned long) out, (unsigned long)n, limit));
118 for (; n < limit; n++) {
120 c = crc_32_tab[((int) c ^ ch) & 0xff] ^ (c >> 8);
123 bytes_out += (out - output_ptr);
125 if (bytes_out == end_offset) {
126 if (output_ptr == (unsigned char *)(&unzip_region+1)) {
127 output_ptr = (unsigned char *)(unzip_region.start);
128 end_offset = unzip_region.end_offset;
130 output_ptr = (unsigned char *)&unzip_region;
131 end_offset += sizeof(unzip_region);
139 void gunzip_setup(void)
141 DBG(("gunzip_setup\n"));
145 end_offset = sizeof(unzip_region);
146 output_ptr = (unsigned char *)&unzip_region;
148 inbuf = &zipped_data[0];
149 insize = zipped_data_end - zipped_data;
153 DBG(("gunzip_setup_done\n"));
157 int kunzip(int argc, char **argv)
161 DBG(("pre_gunzip\n"));
163 error("gunzip failed");
167 DBG(("pre_jmp_to_program_entry: %p\n", &entry ));
168 jmp_to_program_entry(&entry);