This commit is contained in:
Bohdan Kapliuk 2025-01-12 16:46:49 +02:00
parent 6f3656f641
commit e4f772058e

View File

@ -13,20 +13,21 @@ void print_help() {
}
int main(int argc, char* argv[]) {
int result = 1;
if (argc < 2) {
fprintf(stderr, "Chyba: Chybaju argumenty. Pouzite -h pre zobrazenie pomoci.\n");
return 0;
result = 0;
}
if (strcmp(argv[1], "-h") == 0) {
print_help();
return 0;
result = 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 0;
result = 0;
}
const char* input_file = argv[2];
@ -37,30 +38,30 @@ int main(int argc, char* argv[]) {
result = compress_1(input_file, output_file);
if (result < 0) {
fprintf(stderr, "Chyba: Kompresia zlyhala.\n");
return 1;
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");
exit(0);
result = 0;
}
} 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;
result = 0;
}
} 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;
result = 0;
}
} else {
fprintf(stderr, "Chyba: Neznámy argument. Použite -h pre zobrazenie pomoci.\n");
return 1;
result = 0;
}
return 0;
return result;
}