sk1
This commit is contained in:
parent
6e906c76fc
commit
f64b7a8677
75
sk1/main.c
75
sk1/main.c
@ -1,45 +1,66 @@
|
||||
#include "compressor.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "compressor.h"
|
||||
|
||||
void print_usage() {
|
||||
printf("Usage:\n");
|
||||
printf("./compressor -c infile outfile\n");
|
||||
printf("./compressor -d infile outfile\n");
|
||||
printf("./compressor -h\n");
|
||||
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 < 4) {
|
||||
print_usage();
|
||||
return 1;
|
||||
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 -1;
|
||||
}
|
||||
|
||||
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* operation = argv[1];
|
||||
const char* input_file = argv[2];
|
||||
const char* output_file = argv[3];
|
||||
int result = 0;
|
||||
|
||||
int result = 1;
|
||||
|
||||
if (strcmp(operation, "-c") == 0) {
|
||||
if (compress_1(input_file, output_file) == 0) {
|
||||
result = 0;
|
||||
} else if (compress_2(input_file, output_file) == 0) {
|
||||
result = 0;
|
||||
if (strcmp(argv[1], "-c") == 0) {
|
||||
result = compress_1(input_file, output_file);
|
||||
if (result < 0) {
|
||||
fprintf(stderr, "Chyba: Kompresia zlyhala.\n");
|
||||
return -1;
|
||||
}
|
||||
} else if (strcmp(operation, "-d") == 0) {
|
||||
if (decompress_1(input_file, output_file) == 0) {
|
||||
result = 0;
|
||||
} else if (decompress_2(input_file, output_file) == 0) {
|
||||
result = 0;
|
||||
} else if (strcmp(argv[1], "-d") == 0) {
|
||||
result = decompress_1(input_file, output_file);
|
||||
if (result < 0) {
|
||||
fprintf(stderr, "Chyba: Dekompresia zlyhala.\n");
|
||||
return -1;
|
||||
}
|
||||
} else if (strcmp(argv[1], "-c2") == 0) {
|
||||
result = compress_2(input_file, output_file);
|
||||
if (result < 0) {
|
||||
fprintf(stderr, "Chyba: Kompresia zlyhala.\n");
|
||||
return -1;
|
||||
}
|
||||
} else if (strcmp(argv[1], "-d2") == 0) {
|
||||
result = decompress_2(input_file, output_file);
|
||||
if (result < 0) {
|
||||
fprintf(stderr, "Chyba: Dekompresia zlyhala.\n");
|
||||
return -1;
|
||||
}
|
||||
} else if (strcmp(operation, "-h") == 0) {
|
||||
print_usage();
|
||||
result = 0;
|
||||
} else {
|
||||
print_usage();
|
||||
fprintf(stderr, "Chyba: Neznámy argument. Použite -h pre zobrazenie pomoci.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return result;
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user