From babf4f5ed38454bbb1a2a9ceaeb760f5234502ca Mon Sep 17 00:00:00 2001 From: Yurii Chechur Date: Tue, 24 Dec 2024 15:01:40 +0000 Subject: [PATCH] Add sk1/main.c --- sk1/main.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 sk1/main.c diff --git a/sk1/main.c b/sk1/main.c new file mode 100644 index 0000000..8afb615 --- /dev/null +++ b/sk1/main.c @@ -0,0 +1,51 @@ +#include +#include +#include +#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; +}