int parent[0x1ff], left[0x1ff], right[0x1ff];
count_bytes(raw, raw_size, count);
make_tree(count, parent, left, right);
unsigned char *zipped = malloc(raw_size);
int bit = compress(zipped, raw_size, raw, raw_size, parent,
left);
if (bit == raw_size * 8) {
printf("This file is not suitable for zipping.\n");
goto finalize;
}
FILE *zip_file = fopen(argv[3], "wb");
fwrite("\xf0\xf1" "LiMeng", sizeof(char), 8, zip_file);
fwrite(&VERSION, sizeof(int), 1, zip_file);
fwrite(left, sizeof(int), 0x1ff, zip_file);
fwrite(right, sizeof(int), 0x1ff, zip_file);
fwrite(&bit, sizeof(int), 1, zip_file);
fwrite(&raw_size, sizeof(long), 1, zip_file);
fwrite(zipped, bit / 8 + 1, 1, zip_file);
fclose(zip_file);
finalize:
free(raw);
free(zipped);
break;
}
case 'd': {
int left[0x1ff], right[0x1ff], bit, ver;
long byte;
char magic[8];
FILE *zip_file = fopen(argv[2], "rb");
fread(magic, sizeof(char), 8, zip_file);
fread(&ver, sizeof(int), 1, zip_file);
if (memcmp(magic, "\xf0\xf1" "LiMeng", 8) || ver != VERSION)
{
printf("This is not a valid zip file.\n");
return 3;
}
fread(left, sizeof(int), 0x1ff, zip_file);
fread(right, sizeof(int), 0x1ff, zip_file);
fread(&bit, sizeof(int), 1, zip_file);
unsigned char *zipped = malloc(bit / 8 + 1);
fread(&byte, sizeof(long), 1, zip_file);
unsigned char *raw = malloc(byte);