78 lines
2.2 KiB
C
78 lines
2.2 KiB
C
|
#include "compressor.h"
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
|
||
|
void print_help()
|
||
|
{
|
||
|
printf("Usage:\n");
|
||
|
printf(" ./compressor -c1/-c2 infile outfile\t\tCompress infile to outfile\n\t\t\t\t\t\t-c1 Compress using LZ77\n\t\t\t\t\t\t-c2 Compress using huffman coding\n\n");
|
||
|
printf(" ./compressor -d1/-d2 compressed uncompressed\tDecompress compressed to uncompressed\n\t\t\t\t\t\t-d1 Decompress ONLY for LZ77\n\t\t\t\t\t\t-d2 Decompress ONLY for huffman coding\n\n");
|
||
|
printf(" ./compressor -h\t\t\t\tShow this help message\n");
|
||
|
}
|
||
|
|
||
|
int main(int argc, char* argv[])
|
||
|
{
|
||
|
if (argc < 2)
|
||
|
{
|
||
|
print_help();
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
if (strcmp(argv[1], "-h") == 0)
|
||
|
{
|
||
|
print_help();
|
||
|
return 0;
|
||
|
}
|
||
|
else if (strcmp(argv[1], "-c1") == 0 && argc == 4)
|
||
|
{
|
||
|
const char* infile = argv[2];
|
||
|
const char* outfile = argv[3];
|
||
|
if (compress_1(infile, outfile) < 0)
|
||
|
{
|
||
|
fprintf(stderr, "Compression failed\n");
|
||
|
return 1;
|
||
|
}
|
||
|
printf("Compressed successfully.\n");
|
||
|
}
|
||
|
else if (strcmp(argv[1], "-d1") == 0 && argc == 4)
|
||
|
{
|
||
|
const char* compressed = argv[2];
|
||
|
const char* uncompressed = argv[3];
|
||
|
if (decompress_1(compressed, uncompressed) < 0)
|
||
|
{
|
||
|
fprintf(stderr, "Decompression failed\n");
|
||
|
return 1;
|
||
|
}
|
||
|
printf("Decompressed successfully.\n");
|
||
|
}
|
||
|
else if (strcmp(argv[1], "-c2") == 0 && argc == 4)
|
||
|
{
|
||
|
const char* infile = argv[2];
|
||
|
const char* outfile = argv[3];
|
||
|
if (compress_2(infile, outfile) < 0)
|
||
|
{
|
||
|
fprintf(stderr, "Compression failed\n");
|
||
|
return 1;
|
||
|
}
|
||
|
printf("Compressed successfully.\n");
|
||
|
}
|
||
|
else if (strcmp(argv[1], "-d2") == 0 && argc == 4)
|
||
|
{
|
||
|
const char* compressed = argv[2];
|
||
|
const char* uncompressed = argv[3];
|
||
|
if (decompress_2(compressed, uncompressed) < 0)
|
||
|
{
|
||
|
fprintf(stderr, "Decompression failed\n");
|
||
|
return 1;
|
||
|
}
|
||
|
printf("Decompressed successfully.\n");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
print_help();
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|