62 lines
1.9 KiB
C
62 lines
1.9 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include "compressor.h"
|
|
|
|
void print_help() {
|
|
printf("Použitie:\n");
|
|
printf(" ./compressor -c infile outfile # Kompresia pomocou algoritmu RLE\n");
|
|
printf(" ./compressor -d infile outfile # Dekompresia pomocou algoritmu RLE\n");
|
|
printf(" ./compressor -c2 infile outfile # Kompresia pomocou algoritmu LZ78\n");
|
|
printf(" ./compressor -d2 infile outfile # Dekompresia pomocou algoritmu LZ78\n");
|
|
printf(" ./compressor -h # Zobrazit pomoc\n");
|
|
}
|
|
|
|
int main(int argc, char* argv[]) {
|
|
if (argc < 2) {
|
|
fprintf(stderr, "Chyba: Chybaju argumenty. Pouzite -h pre zobrazenie pomoci.\n");
|
|
return 1;
|
|
}
|
|
|
|
if (strcmp(argv[1], "-h") == 0) {
|
|
print_help();
|
|
return 0;
|
|
}
|
|
|
|
if ((strcmp(argv[1], "-c") == 0 || strcmp(argv[1], "-d") == 0 ||
|
|
strcmp(argv[1], "-c2") == 0 || strcmp(argv[1], "-d2") == 0) && argc != 4) {
|
|
fprintf(stderr, "Chyba: Nespravny pocet argumentov. Pouzite -h pre zobrazenie pomoci.\n");
|
|
return 1;
|
|
}
|
|
|
|
const char* input_file = argv[2];
|
|
const char* output_file = argv[3];
|
|
int result = 0;
|
|
|
|
if (strcmp(argv[1], "-c") == 0) {
|
|
result = compress_1(input_file, output_file);
|
|
if (result < 0) {
|
|
return 1;
|
|
}
|
|
} else if (strcmp(argv[1], "-d") == 0) {
|
|
result = decompress_1(input_file, output_file);
|
|
if (result < 0) {
|
|
return 1;
|
|
}
|
|
} else if (strcmp(argv[1], "-c2") == 0) {
|
|
result = compress_2(input_file, output_file);
|
|
if (result < 0) {
|
|
return 1;
|
|
}
|
|
} else if (strcmp(argv[1], "-d2") == 0) {
|
|
result = decompress_2(input_file, output_file);
|
|
if (result < 0) {
|
|
return 1;
|
|
}
|
|
} else {
|
|
fprintf(stderr, "Chyba: Neznamy argument. Použite -h pre zobrazenie pomoci.\n");
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
} |