33 lines
784 B
C
33 lines
784 B
C
#include "compressor.h"
|
|
#include <string.h>
|
|
|
|
int main(int argc, char* argv[]) {
|
|
if (argc != 4 || (argv[1][1] != 'c' && argv[1][1] != 'd')) {
|
|
printf("Usage: %s -c input output\n", argv[0]);
|
|
printf("Usage: %s -d output input\n", argv[0]);
|
|
return 1;
|
|
}
|
|
|
|
FILE* infile = fopen(argv[2], "rb");
|
|
FILE* outfile = fopen(argv[3], "wb");
|
|
|
|
if (infile == NULL || outfile == NULL) {
|
|
perror("Error opening files");
|
|
return 1;
|
|
}
|
|
|
|
if (strcmp(argv[1], "-c") == 0) {
|
|
compress(infile, outfile);
|
|
} else if (strcmp(argv[1], "-d") == 0) {
|
|
decompress(infile, outfile);
|
|
} else {
|
|
fprintf(stderr, "Invalid option: %s\n", argv[1]);
|
|
return 1;
|
|
}
|
|
|
|
fclose(infile);
|
|
fclose(outfile);
|
|
|
|
return 0;
|
|
}
|