Add sk1/main.c
This commit is contained in:
parent
1ea576b3a3
commit
babf4f5ed3
51
sk1/main.c
Normal file
51
sk1/main.c
Normal file
@ -0,0 +1,51 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "compressor.h"
|
||||
|
||||
void print_help() {
|
||||
printf("Usage:\n");
|
||||
printf(" ./compressor -c1 infile outfile Compress using algorithm 1 (Huffman)\n");
|
||||
printf(" ./compressor -d1 infile outfile Decompress using algorithm 1 (Huffman)\n");
|
||||
printf(" ./compressor -c2 infile outfile Compress using algorithm 2 (RLE)\n");
|
||||
printf(" ./compressor -d2 infile outfile Decompress using algorithm 2 (RLE)\n");
|
||||
printf(" ./compressor -h Show 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;
|
||||
}
|
||||
|
||||
if (argc != 4) {
|
||||
fprintf(stderr, "Error: Invalid number of arguments.\n");
|
||||
print_help();
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char* mode = argv[1];
|
||||
const char* infile = argv[2];
|
||||
const char* outfile = argv[3];
|
||||
|
||||
if (strcmp(mode, "-c1") == 0) {
|
||||
compress_1(infile, outfile);
|
||||
} else if (strcmp(mode, "-d1") == 0) {
|
||||
decompress_1(infile, outfile);
|
||||
} else if (strcmp(mode, "-c2") == 0) {
|
||||
compress_2(infile, outfile);
|
||||
} else if (strcmp(mode, "-d2") == 0) {
|
||||
decompress_2(infile, outfile);
|
||||
} else {
|
||||
fprintf(stderr, "Error: Unknown mode '%s'.\n", mode);
|
||||
print_help();
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user