From 00d59d543a8e82435e4cbeab70b88122b6cd3cb7 Mon Sep 17 00:00:00 2001 From: Cem Date: Sat, 20 Jun 2026 18:22:02 +0200 Subject: [PATCH] parsing: help message added, fixed some other issues. waiting for the fully functional algorithm to do the benchmarking/tests --- Implementierung/1 | Bin 0 -> 54 bytes Implementierung/main.c | 110 ++++++++++++++++++++++++++++++----------- 2 files changed, 82 insertions(+), 28 deletions(-) create mode 100644 Implementierung/1 diff --git a/Implementierung/1 b/Implementierung/1 new file mode 100644 index 0000000000000000000000000000000000000000..68b3db306c562f9a98af68822876b751d3a95bbd GIT binary patch literal 54 ecmZ?rHDiDP5Ul}agD6G@2{=!fn}Gp@VE_O=Q2}`X literal 0 HcmV?d00001 diff --git a/Implementierung/main.c b/Implementierung/main.c index dd0eee1..453b2bf 100644 --- a/Implementierung/main.c +++ b/Implementierung/main.c @@ -9,6 +9,51 @@ void save_bmp(const char *filename, unsigned char *img, size_t width, ssize_t height); +unsigned tests(void) { + return 0; + // run the tests +} + +void benchmarking(void) { + // do the benchmarking +} + +const char* help_messsage = "Help Message\n\n" + "Usage:\n" + " ./tricorn [OPTIONS]\n\n" + "Options:\n" + "-V \n" + " Selects the implementation to use.\n" + " -V 0 uses the main implementation.\n" + " If no argument is given, -V is used.\n" + " Example: -V 1\n\n" + "-B \n" + " Benchmarks the selected implementation.\n" + " The argument chooses how many times the function is called.\n" + " Example: -B 5\n\n" + "-s ,\n" + " Sets the starting point of the function.\n" + " Example: -s -2.0,1.5\n\n" + "-d ,\n" + " Sets the width and the height of the generated image.\n" + " Example: -d 800,600\n\n" + "-n \n" + " Sets the maximum number of iterations per pixel.\n" + " Example: -n 255\n\n" + "-r \n" + " Sets the resolution per pixel.\n" + " Example: -r 0.01\n\n" + "-o \n" + " Sets the output file name.\n" + " The file name must end with .bmp\n" + " Example: -o image.bmp\n\n" + "-C, --color\n" + " Enables colored output.\n\n" + "-h, --help\n" + " Displays the help message and exits.\n\n" + "-t, --test\n" + " Runs the tests, prints the results, and exists.\n"; + int main(int argc, char** argv) { int opt_long; @@ -38,16 +83,17 @@ int main(int argc, char** argv) - int version_to_use = 0; - unsigned amount_function_called; - unsigned n; - float starting_point_real; - float starting_point_imaginary; - size_t width; - ssize_t height; - float step_amount; - char* output_data; - _Bool colored = 0; + int version_to_use = 0; // actual initial value + _Bool colored = 0; // actual initial value + + unsigned amount_function_called = 0; // initial values, so that the compiler doesn't complain + unsigned n = 0; + float starting_point_real = 0; + float starting_point_imaginary = 0; + size_t width = 0; + ssize_t height = 0; + float resolution = 0; + char* output_data = 0; opt_long = getopt_long(argc,argv,optstring, long_options, NULL); @@ -59,6 +105,8 @@ int main(int argc, char** argv) case 'V': // done, function needed version_to_use = strtol(optarg,NULL,10); printf("version is %d\n", version_to_use); + // call different version functions + // Die Implementierung, die verwendet werden soll. Hierbei soll mit // -V 0 Ihre Hauptimplementierung verwendet werden. Wenn diese Option nicht // gesetzt wird, soll ebenfalls die Hauptimplementierung ausgeführt werden @@ -67,15 +115,20 @@ int main(int argc, char** argv) case 'B': // done, function needed // wird die Laufzeit der angegebenen Implementierung gemessen und ausgegeben (do this later) amount_function_called = strtoul(optarg,NULL,10); + benchmarking(); printf("amount function called is %d\n", amount_function_called); + // call benchmarking function + // Das Argument dieser Option gibt die Anzahl an Wiederholungen des Funktionsaufrufs an, z. B.-B 5 . - break; + return EXIT_FAILURE; case 's': char* imaginary_string; starting_point_real = strtof(optarg,&imaginary_string); // split into two starting_point_imaginary = strtof(imaginary_string + 1,NULL); // this is horrible - printf("real %d, img %d\n", starting_point_real,starting_point_imaginary); + printf("real %f, img %f\n", starting_point_real,starting_point_imaginary); + + // s , — Startpunkt der Berechnung break; @@ -83,7 +136,7 @@ int main(int argc, char** argv) char* height_string; width = strtol(optarg,&height_string,10); height = strtol(height_string + 1,NULL,10); - printf("width %d, height %d\n", width,height); + printf("width %zu, height %zd\n", width,height); // -d , —Breite und Höhe des Bildausschnitts break; @@ -94,55 +147,56 @@ int main(int argc, char** argv) break; case 'r': - step_amount = strtof(optarg,NULL); - printf("r:%d\n", step_amount); + resolution = strtof(optarg,NULL); + printf("r:%f\n", resolution); // r —Schrittweite pro Bildpixel break; case 'o': output_data = malloc(strlen(optarg) + 1); strcpy(output_data,optarg); - printf("%s\n", output_data); // test + printf("output data: %s\n", output_data); // test // -o —Ausgabedatei break; - case 'C': + case 'C': // done colored = 1; printf("colored:%d\n",colored); // C|--color —Farbausgabe break; - case 'h': + case 'h': // done + printf("%s",help_messsage); // print help message // Eine Beschreibung aller Optionen des Programms und Verwendungsbeispiele werden ausgegeben und das Programm danach beendet. // Die Beschreibung soll mit "Help Message" anfangen. - break; + return EXIT_SUCCESS; - case 't': - - // do testing + case 't': // done, function needed // Führt eine vordefinierte Testsuite aus, welche sämtliche von Ihnen // verwendete Benchmarking-Szenarien gesammelt durchläuft. Das Programm gibt // die jeweiligen Parameter, eine kurze Beschreibungen sowie die Ergebnisse in einer // übersichtlichen und gut lesbaren Form aus und terminiert anschließend. - break; + return tests() ? EXIT_FAILURE : EXIT_SUCCESS; - default: // case '?' -> when the argument is not valid + default: // idk + // case '?' -> when the argument is not valid + fprintf(stderr,"ERROR: Invalid argument -%c:\n",optopt); // print error msg - break; + return EXIT_FAILURE; } opt_long = getopt_long(argc,argv,optstring, long_options, NULL); } float complex complexA = (starting_point_real + starting_point_imaginary*I); - char tempArr[width*height*3]; + unsigned char tempArr[width*height*3]; printf("yashar\n"); - tricorn(complexA,width,height,step_amount,n,colored,tempArr); + tricorn(complexA,width,height,resolution,n,colored,tempArr); printf("yashar\n"); save_bmp(output_data,tempArr,width,height); - free(optarg); // + free(output_data); // return 0; }