Removed (pretty inconsistently used) tab chars from source code base.
This commit is contained in:
@@ -21,22 +21,22 @@
|
||||
*/
|
||||
unsigned inflatemem(char* dest, const char* source)
|
||||
{
|
||||
z_stream stream;
|
||||
z_stream stream;
|
||||
|
||||
stream.next_in = (Bytef*) source;
|
||||
stream.avail_in = 65535;
|
||||
stream.next_in = (Bytef*) source;
|
||||
stream.avail_in = 65535;
|
||||
|
||||
stream.next_out = dest;
|
||||
stream.avail_out = 65535;
|
||||
stream.next_out = dest;
|
||||
stream.avail_out = 65535;
|
||||
|
||||
stream.zalloc = (alloc_func) 0;
|
||||
stream.zfree = (free_func) 0;
|
||||
stream.zalloc = (alloc_func) 0;
|
||||
stream.zfree = (free_func) 0;
|
||||
|
||||
inflateInit2(&stream, -MAX_WBITS);
|
||||
inflate(&stream, Z_FINISH);
|
||||
inflateEnd(&stream);
|
||||
inflateInit2(&stream, -MAX_WBITS);
|
||||
inflate(&stream, Z_FINISH);
|
||||
inflateEnd(&stream);
|
||||
|
||||
return stream.total_out;
|
||||
return stream.total_out;
|
||||
}
|
||||
#endif /* __CC65__ */
|
||||
|
||||
@@ -63,11 +63,11 @@ unsigned inflatemem(char* dest, const char* source)
|
||||
*/
|
||||
|
||||
/* Flags in the GZIP header. */
|
||||
#define FTEXT 1 /* Extra text */
|
||||
#define FHCRC 2 /* Header CRC */
|
||||
#define FEXTRA 4 /* Extra field */
|
||||
#define FNAME 8 /* File name */
|
||||
#define FCOMMENT 16 /* File comment */
|
||||
#define FTEXT 1 /* Extra text */
|
||||
#define FHCRC 2 /* Header CRC */
|
||||
#define FEXTRA 4 /* Extra field */
|
||||
#define FNAME 8 /* File name */
|
||||
#define FCOMMENT 16 /* File comment */
|
||||
|
||||
/*
|
||||
* We read whole GZIP file into this buffer.
|
||||
@@ -94,82 +94,82 @@ static unsigned char buffer[26000];
|
||||
*/
|
||||
unsigned uncompress_buffer(unsigned complen)
|
||||
{
|
||||
unsigned char* ptr;
|
||||
unsigned long crc;
|
||||
unsigned long unclen;
|
||||
void* ptr2;
|
||||
unsigned unclen2;
|
||||
unsigned char* ptr;
|
||||
unsigned long crc;
|
||||
unsigned long unclen;
|
||||
void* ptr2;
|
||||
unsigned unclen2;
|
||||
|
||||
/* check GZIP signature */
|
||||
if (buffer[0] != 0x1f || buffer[1] != 0x8b) {
|
||||
puts("Not GZIP format");
|
||||
return 0;
|
||||
}
|
||||
/* check GZIP signature */
|
||||
if (buffer[0] != 0x1f || buffer[1] != 0x8b) {
|
||||
puts("Not GZIP format");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* check compression method (it is always (?) "deflate") */
|
||||
if (buffer[2] != 8) {
|
||||
puts("Unsupported compression method");
|
||||
return 0;
|
||||
}
|
||||
/* check compression method (it is always (?) "deflate") */
|
||||
if (buffer[2] != 8) {
|
||||
puts("Unsupported compression method");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* get CRC from GZIP trailer */
|
||||
crc = GET_LONG(buffer + complen - 8);
|
||||
/* get CRC from GZIP trailer */
|
||||
crc = GET_LONG(buffer + complen - 8);
|
||||
|
||||
/* get uncompressed length from GZIP trailer */
|
||||
unclen = GET_LONG(buffer + complen - 4);
|
||||
if (unclen > sizeof(buffer)) {
|
||||
puts("Uncompressed size too big");
|
||||
return 0;
|
||||
}
|
||||
/* get uncompressed length from GZIP trailer */
|
||||
unclen = GET_LONG(buffer + complen - 4);
|
||||
if (unclen > sizeof(buffer)) {
|
||||
puts("Uncompressed size too big");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* skip extra field, file name, comment and crc */
|
||||
ptr = buffer + 10;
|
||||
if (buffer[3] & FEXTRA)
|
||||
ptr = buffer + 12 + GET_WORD(buffer + 10);
|
||||
if (buffer[3] & FNAME)
|
||||
while (*ptr++ != 0);
|
||||
if (buffer[3] & FCOMMENT)
|
||||
while (*ptr++ != 0);
|
||||
if (buffer[3] & FHCRC)
|
||||
ptr += 2;
|
||||
/* skip extra field, file name, comment and crc */
|
||||
ptr = buffer + 10;
|
||||
if (buffer[3] & FEXTRA)
|
||||
ptr = buffer + 12 + GET_WORD(buffer + 10);
|
||||
if (buffer[3] & FNAME)
|
||||
while (*ptr++ != 0);
|
||||
if (buffer[3] & FCOMMENT)
|
||||
while (*ptr++ != 0);
|
||||
if (buffer[3] & FHCRC)
|
||||
ptr += 2;
|
||||
|
||||
/*
|
||||
* calculate length of raw "deflate" data
|
||||
* (without the GZIP header and 8-byte trailer)
|
||||
*/
|
||||
complen -= (ptr - buffer) + 8;
|
||||
/*
|
||||
* calculate length of raw "deflate" data
|
||||
* (without the GZIP header and 8-byte trailer)
|
||||
*/
|
||||
complen -= (ptr - buffer) + 8;
|
||||
|
||||
/*
|
||||
* We will move the compressed data to the end of buffer[].
|
||||
* Thus the compressed data and the decompressed data (written from
|
||||
* the beginning of buffer[]) may overlap, as long as the decompressed
|
||||
* data doesn't go further than unread compressed data.
|
||||
* ptr2 points to the beginning of compressed data at the end
|
||||
* of buffer[].
|
||||
*/
|
||||
ptr2 = buffer + sizeof(buffer) - complen;
|
||||
/* move the compressed data to end of buffer[] */
|
||||
memmove(ptr2, ptr, complen);
|
||||
/*
|
||||
* We will move the compressed data to the end of buffer[].
|
||||
* Thus the compressed data and the decompressed data (written from
|
||||
* the beginning of buffer[]) may overlap, as long as the decompressed
|
||||
* data doesn't go further than unread compressed data.
|
||||
* ptr2 points to the beginning of compressed data at the end
|
||||
* of buffer[].
|
||||
*/
|
||||
ptr2 = buffer + sizeof(buffer) - complen;
|
||||
/* move the compressed data to end of buffer[] */
|
||||
memmove(ptr2, ptr, complen);
|
||||
|
||||
/* uncompress */
|
||||
puts("Inflating...");
|
||||
unclen2 = inflatemem(buffer, ptr2);
|
||||
/* uncompress */
|
||||
puts("Inflating...");
|
||||
unclen2 = inflatemem(buffer, ptr2);
|
||||
|
||||
/* verify uncompressed length */
|
||||
if (unclen2 != (unsigned) unclen) {
|
||||
puts("Uncompressed size does not match");
|
||||
return 0;
|
||||
}
|
||||
/* verify uncompressed length */
|
||||
if (unclen2 != (unsigned) unclen) {
|
||||
puts("Uncompressed size does not match");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* verify CRC */
|
||||
puts("Calculating CRC...");
|
||||
if (crc32(crc32(0L, Z_NULL, 0), buffer, unclen2) != crc) {
|
||||
puts("CRC mismatch");
|
||||
return 0;
|
||||
}
|
||||
/* verify CRC */
|
||||
puts("Calculating CRC...");
|
||||
if (crc32(crc32(0L, Z_NULL, 0), buffer, unclen2) != crc) {
|
||||
puts("CRC mismatch");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* return number of uncompressed bytes */
|
||||
return unclen2;
|
||||
/* return number of uncompressed bytes */
|
||||
return unclen2;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -177,52 +177,52 @@ unsigned uncompress_buffer(unsigned complen)
|
||||
*/
|
||||
char* get_fname(void)
|
||||
{
|
||||
static char filename[100];
|
||||
unsigned len;
|
||||
fgets(filename, sizeof(filename), stdin);
|
||||
len = strlen(filename);
|
||||
if (len >= 1 && filename[len - 1] == '\n')
|
||||
filename[len - 1] = '\0';
|
||||
return filename;
|
||||
static char filename[100];
|
||||
unsigned len;
|
||||
fgets(filename, sizeof(filename), stdin);
|
||||
len = strlen(filename);
|
||||
if (len >= 1 && filename[len - 1] == '\n')
|
||||
filename[len - 1] = '\0';
|
||||
return filename;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
FILE* fp;
|
||||
unsigned length;
|
||||
FILE* fp;
|
||||
unsigned length;
|
||||
|
||||
/* read GZIP file */
|
||||
puts("GZIP file name:");
|
||||
fp = fopen(get_fname(), "rb");
|
||||
if (!fp) {
|
||||
puts("Can't open GZIP file");
|
||||
return 1;
|
||||
}
|
||||
length = fread(buffer, 1, sizeof(buffer), fp);
|
||||
fclose(fp);
|
||||
if (length == sizeof(buffer)) {
|
||||
puts("File is too long");
|
||||
return 1;
|
||||
}
|
||||
/* read GZIP file */
|
||||
puts("GZIP file name:");
|
||||
fp = fopen(get_fname(), "rb");
|
||||
if (!fp) {
|
||||
puts("Can't open GZIP file");
|
||||
return 1;
|
||||
}
|
||||
length = fread(buffer, 1, sizeof(buffer), fp);
|
||||
fclose(fp);
|
||||
if (length == sizeof(buffer)) {
|
||||
puts("File is too long");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* decompress */
|
||||
length = uncompress_buffer(length);
|
||||
if (length == 0)
|
||||
return 1;
|
||||
/* decompress */
|
||||
length = uncompress_buffer(length);
|
||||
if (length == 0)
|
||||
return 1;
|
||||
|
||||
/* write uncompressed file */
|
||||
puts("Uncompressed file name:");
|
||||
fp = fopen(get_fname(), "wb");
|
||||
if (!fp) {
|
||||
puts("Can't create output file");
|
||||
return 1;
|
||||
}
|
||||
if (fwrite(buffer, 1, length, fp) != length) {
|
||||
puts("Error while writing output file");
|
||||
return 1;
|
||||
}
|
||||
fclose(fp);
|
||||
/* write uncompressed file */
|
||||
puts("Uncompressed file name:");
|
||||
fp = fopen(get_fname(), "wb");
|
||||
if (!fp) {
|
||||
puts("Can't create output file");
|
||||
return 1;
|
||||
}
|
||||
if (fwrite(buffer, 1, length, fp) != length) {
|
||||
puts("Error while writing output file");
|
||||
return 1;
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
puts("Ok.");
|
||||
return 0;
|
||||
puts("Ok.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user