From a8abf55717ee733db8d799fc556a15aedd93fa67 Mon Sep 17 00:00:00 2001 From: Cem Date: Wed, 8 Jul 2026 00:00:30 +0200 Subject: [PATCH] added: no longer accepts when an input is lacking --- Implementierung/main.c | 53 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/Implementierung/main.c b/Implementierung/main.c index 4089666..0c458ad 100644 --- a/Implementierung/main.c +++ b/Implementierung/main.c @@ -52,7 +52,7 @@ void benchmarking(size_t benchmarking_amount, int version_to_use, float complex tricorn_implementation = tricorn_V5; break; default: - printf("Invalid version to use"); + fprintf(stderr,"Invalid version to use: V%d. Available versions are : V0,V1,V2,V3,V4,V5\n",version_to_use); return; } @@ -97,7 +97,31 @@ unsigned tests(void) { free(tempArrNotColored); return 0; -} +} + +void checkInputs(_Bool n,_Bool r,_Bool o,_Bool d,_Bool s) { + if (!n) + { + fprintf(stderr, "ERROR: Input n not given.\n"); + } + if (!r) + { + fprintf(stderr, "ERROR: Input r not given.\n"); + } + if (!o) + { + fprintf(stderr, "ERROR: Input o not given.\n"); + } + if (!d) + { + fprintf(stderr, "ERROR: Input d not given.\n"); + } + if (!s) + { + fprintf(stderr, "ERROR: Input s not given.\n"); + } + +} // REMOVE LATER: interesting test command ./tricorn -s -2.0,0.6 -r 0.0010 -n 200 -d 1920,1080 -o image.bmp -C @@ -171,6 +195,12 @@ int main(int argc, char** argv) _Bool will_benchmark = false; // actual initial value _Bool will_test = false; + + _Bool nGiven = false; + _Bool rGiven = false; + _Bool oGiven = false; + _Bool dGiven = false; + _Bool sGiven = false; int amount_function_called = -1; // initial values, so that the compiler doesn't complain unsigned n = 0; float starting_point_real = -1; @@ -189,7 +219,11 @@ int main(int argc, char** argv) { case 'V': // done, function needed version_to_use = strtol(optarg,NULL,10); - + if (version_to_use < 0 || version_to_use > 5) + { + fprintf(stderr,"Invalid version to use: V%d. Available versions are : V0,V1,V2,V3,V4,V5\n", version_to_use); + return EXIT_FAILURE; + } printf("version is %d\n", version_to_use); // call different version functions @@ -202,7 +236,7 @@ int main(int argc, char** argv) // wird die Laufzeit der angegebenen Implementierung gemessen und ausgegeben (do this later) amount_function_called = strtol(optarg,NULL,10); if (amount_function_called <= 0) { - printf("Invalid benchmarking input, the value should be greater than 0\n"); + fprintf(stderr, "Invalid benchmarking input, the value should be greater than 0\n"); return 1; } will_benchmark = true; @@ -213,6 +247,7 @@ int main(int argc, char** argv) break; case 's': { + sGiven = true; char *imaginary_string; char *end; @@ -238,6 +273,7 @@ int main(int argc, char** argv) } case 'd': { + dGiven = true; char* height_string; char *end; width = strtol(optarg,&height_string,10); @@ -261,12 +297,14 @@ int main(int argc, char** argv) } case 'n': + nGiven = true; n = strtol(optarg,NULL,10); printf("n:%d\n",n); // -n —MaximaleAnzahlanIterationen pro Bildpixel break; case 'r': { + rGiven = true; char *end; resolution = strtof(optarg,&end); if (end == optarg || *end != '\0') @@ -280,6 +318,7 @@ int main(int argc, char** argv) } case 'o': + oGiven = true; output_data = malloc(strlen(optarg) + 1); strcpy(output_data,optarg); printf("output data: %s\n", output_data); // test @@ -331,6 +370,12 @@ int main(int argc, char** argv) return tests() ? EXIT_FAILURE : EXIT_SUCCESS; } + if (!(nGiven && rGiven && oGiven && dGiven && sGiven)) + { + checkInputs(nGiven,rGiven,oGiven,dGiven,sGiven); + return EXIT_FAILURE; + } + if (will_benchmark) { printf("\nDoing benchmarking. No images will be created\n");