parsing: help message added, fixed some other issues. waiting for the fully functional algorithm to do the benchmarking/tests

This commit is contained in:
Cem
2026-06-20 18:22:02 +02:00
parent d3c796386f
commit 00d59d543a
2 changed files with 82 additions and 28 deletions
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 54 B

+82 -28
View File
@@ -9,6 +9,51 @@
void save_bmp(const char *filename, unsigned char *img, size_t width, ssize_t height); 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 <number>\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 <number>\n"
" Benchmarks the selected implementation.\n"
" The argument chooses how many times the function is called.\n"
" Example: -B 5\n\n"
"-s <real>,<imaginary>\n"
" Sets the starting point of the function.\n"
" Example: -s -2.0,1.5\n\n"
"-d <width>,<height>\n"
" Sets the width and the height of the generated image.\n"
" Example: -d 800,600\n\n"
"-n <number>\n"
" Sets the maximum number of iterations per pixel.\n"
" Example: -n 255\n\n"
"-r <floating-point number>\n"
" Sets the resolution per pixel.\n"
" Example: -r 0.01\n\n"
"-o <filename>\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 main(int argc, char** argv)
{ {
int opt_long; int opt_long;
@@ -38,16 +83,17 @@ int main(int argc, char** argv)
int version_to_use = 0; int version_to_use = 0; // actual initial value
unsigned amount_function_called; _Bool colored = 0; // actual initial value
unsigned n;
float starting_point_real; unsigned amount_function_called = 0; // initial values, so that the compiler doesn't complain
float starting_point_imaginary; unsigned n = 0;
size_t width; float starting_point_real = 0;
ssize_t height; float starting_point_imaginary = 0;
float step_amount; size_t width = 0;
char* output_data; ssize_t height = 0;
_Bool colored = 0; float resolution = 0;
char* output_data = 0;
opt_long = getopt_long(argc,argv,optstring, long_options, NULL); 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 case 'V': // done, function needed
version_to_use = strtol(optarg,NULL,10); version_to_use = strtol(optarg,NULL,10);
printf("version is %d\n", version_to_use); printf("version is %d\n", version_to_use);
// call different version functions
// Die Implementierung, die verwendet werden soll. Hierbei soll mit // Die Implementierung, die verwendet werden soll. Hierbei soll mit
// -V 0 Ihre Hauptimplementierung verwendet werden. Wenn diese Option nicht // -V 0 Ihre Hauptimplementierung verwendet werden. Wenn diese Option nicht
// gesetzt wird, soll ebenfalls die Hauptimplementierung ausgeführt werden // gesetzt wird, soll ebenfalls die Hauptimplementierung ausgeführt werden
@@ -67,15 +115,20 @@ int main(int argc, char** argv)
case 'B': // done, function needed case 'B': // done, function needed
// wird die Laufzeit der angegebenen Implementierung gemessen und ausgegeben (do this later) // wird die Laufzeit der angegebenen Implementierung gemessen und ausgegeben (do this later)
amount_function_called = strtoul(optarg,NULL,10); amount_function_called = strtoul(optarg,NULL,10);
benchmarking();
printf("amount function called is %d\n", amount_function_called); 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 . // Das Argument dieser Option gibt die Anzahl an Wiederholungen des Funktionsaufrufs an, z. B.-B 5 .
break; return EXIT_FAILURE;
case 's': case 's':
char* imaginary_string; char* imaginary_string;
starting_point_real = strtof(optarg,&imaginary_string); // split into two starting_point_real = strtof(optarg,&imaginary_string); // split into two
starting_point_imaginary = strtof(imaginary_string + 1,NULL); // this is horrible 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 <Realteil>,<Imaginärteil> — Startpunkt der Berechnung // s <Realteil>,<Imaginärteil> — Startpunkt der Berechnung
break; break;
@@ -83,7 +136,7 @@ int main(int argc, char** argv)
char* height_string; char* height_string;
width = strtol(optarg,&height_string,10); width = strtol(optarg,&height_string,10);
height = strtol(height_string + 1,NULL,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 <Zahl>,<Zahl> —Breite und Höhe des Bildausschnitts // -d <Zahl>,<Zahl> —Breite und Höhe des Bildausschnitts
break; break;
@@ -94,55 +147,56 @@ int main(int argc, char** argv)
break; break;
case 'r': case 'r':
step_amount = strtof(optarg,NULL); resolution = strtof(optarg,NULL);
printf("r:%d\n", step_amount); printf("r:%f\n", resolution);
// r <Floating Point Zahl> —Schrittweite pro Bildpixel // r <Floating Point Zahl> —Schrittweite pro Bildpixel
break; break;
case 'o': case 'o':
output_data = malloc(strlen(optarg) + 1); output_data = malloc(strlen(optarg) + 1);
strcpy(output_data,optarg); strcpy(output_data,optarg);
printf("%s\n", output_data); // test printf("output data: %s\n", output_data); // test
// -o <Dateiname> —Ausgabedatei // -o <Dateiname> —Ausgabedatei
break; break;
case 'C': case 'C': // done
colored = 1; colored = 1;
printf("colored:%d\n",colored); printf("colored:%d\n",colored);
// C|--color —Farbausgabe // C|--color —Farbausgabe
break; break;
case 'h': case 'h': // done
printf("%s",help_messsage);
// print help message // print help message
// Eine Beschreibung aller Optionen des Programms und Verwendungsbeispiele werden ausgegeben und das Programm danach beendet. // Eine Beschreibung aller Optionen des Programms und Verwendungsbeispiele werden ausgegeben und das Programm danach beendet.
// Die Beschreibung soll mit "Help Message" anfangen. // Die Beschreibung soll mit "Help Message" anfangen.
break; return EXIT_SUCCESS;
case 't': case 't': // done, function needed
// do testing
// Führt eine vordefinierte Testsuite aus, welche sämtliche von Ihnen // Führt eine vordefinierte Testsuite aus, welche sämtliche von Ihnen
// verwendete Benchmarking-Szenarien gesammelt durchläuft. Das Programm gibt // verwendete Benchmarking-Szenarien gesammelt durchläuft. Das Programm gibt
// die jeweiligen Parameter, eine kurze Beschreibungen sowie die Ergebnisse in einer // die jeweiligen Parameter, eine kurze Beschreibungen sowie die Ergebnisse in einer
// übersichtlichen und gut lesbaren Form aus und terminiert anschließend. // ü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 // print error msg
break; return EXIT_FAILURE;
} }
opt_long = getopt_long(argc,argv,optstring, long_options, NULL); opt_long = getopt_long(argc,argv,optstring, long_options, NULL);
} }
float complex complexA = (starting_point_real + starting_point_imaginary*I); float complex complexA = (starting_point_real + starting_point_imaginary*I);
char tempArr[width*height*3]; unsigned char tempArr[width*height*3];
printf("yashar\n"); printf("yashar\n");
tricorn(complexA,width,height,step_amount,n,colored,tempArr); tricorn(complexA,width,height,resolution,n,colored,tempArr);
printf("yashar\n"); printf("yashar\n");
save_bmp(output_data,tempArr,width,height); save_bmp(output_data,tempArr,width,height);
free(optarg); // free(output_data); //
return 0; return 0;
} }