EMILE/second/uncompress.c

96 lines
1.7 KiB
C
Raw Normal View History

2004-02-15 20:46:45 +00:00
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#include <stdio.h>
#include <malloc.h>
2005-05-22 21:14:41 +00:00
#include <string.h>
2004-02-15 20:46:45 +00:00
#include "console.h"
#include "uncompress.h"
#include "misc.h"
/*
* gzip declarations
*/
#define OF(args) args
typedef unsigned char uch;
typedef unsigned short ush;
typedef unsigned long ulg;
#define WSIZE 0x8000 /* Window size must be at least 32k, */
/* and a power of two */
static long bytes_out = 0;
static uch *inbuf; /* input buffer */
static uch window[WSIZE]; /* Sliding window buffer */
2004-02-15 20:46:45 +00:00
static unsigned inptr; /* index of next byte to be processed in inbuf */
2004-02-15 20:46:45 +00:00
static unsigned outcnt = 0; /* bytes in output buffer */
#define get_byte() (inbuf[inptr++])
2004-02-15 20:46:45 +00:00
static uch *output_data;
2004-02-15 20:46:45 +00:00
static unsigned long output_ptr = 0;
#define Assert(cond,msg)
#define Trace(x)
#define Tracev(x)
#define Tracevv(x)
#define Tracec(c,x)
#define Tracecv(c,x)
#define memzero(s, n) memset ((s), 0, (n))
static void gzip_mark(void **ptr)
{
}
static void gzip_release(void **ptr)
{
}
static void flush_window(void);
2005-06-06 19:36:13 +00:00
#define STATIC static
2004-02-15 20:46:45 +00:00
#include "inflate.c"
static void flush_window(void)
{
ulg c = crc; /* temporary variable */
unsigned n;
uch *in, *out, ch;
in = window;
out = output_data + output_ptr;
for (n = 0; n < outcnt; n++) {
ch = *out++ = *in++;
c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
}
crc = c;
bytes_out += (ulg)outcnt;
output_ptr += (ulg)outcnt;
outcnt = 0;
console_putchar('.');
2004-02-15 20:46:45 +00:00
}
unsigned long uncompress(char* buf, char* image)
2004-02-15 20:46:45 +00:00
{
output_data = buf;
inbuf = (uch*)image;
inptr = 0;
2004-02-15 20:46:45 +00:00
makecrc();
printf("Uncompressing kernel to %p", buf);
2005-06-06 19:36:13 +00:00
2004-02-15 20:46:45 +00:00
gunzip();
2004-06-03 22:38:24 +00:00
return output_ptr;
2004-02-15 20:46:45 +00:00
}