fixed: more bugfixed and constraints for inputs while parsing
This commit is contained in:
+26
-12
@@ -201,7 +201,7 @@ int main(int argc, char** argv)
|
|||||||
_Bool oGiven = false;
|
_Bool oGiven = false;
|
||||||
_Bool dGiven = false;
|
_Bool dGiven = false;
|
||||||
_Bool sGiven = false;
|
_Bool sGiven = false;
|
||||||
int amount_function_called = -1; // initial values, so that the compiler doesn't complain
|
size_t amount_function_called = 0; // initial values, so that the compiler doesn't complain
|
||||||
unsigned n = 0;
|
unsigned n = 0;
|
||||||
float starting_point_real = -1;
|
float starting_point_real = -1;
|
||||||
float starting_point_imaginary = -1;
|
float starting_point_imaginary = -1;
|
||||||
@@ -217,14 +217,14 @@ int main(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
switch (opt_long)
|
switch (opt_long)
|
||||||
{
|
{
|
||||||
case 'V': // done, function needed
|
case 'V': {// done, function needed
|
||||||
char *end;
|
char *end;
|
||||||
version_to_use = strtol(optarg,&end,10);
|
version_to_use = strtol(optarg,&end,10);
|
||||||
|
|
||||||
|
|
||||||
if (version_to_use < 0 || version_to_use > 5 || end == optarg || *end != '\0')
|
if (version_to_use < 0 || version_to_use > 5 || end == optarg || *end != '\0')
|
||||||
{
|
{
|
||||||
fprintf(stderr,"Invalid version to use: V%d. Available versions are : V0,V1,V2,V3,V4,V5\n", version_to_use);
|
fprintf(stderr,"Invalid version to use: V%s. Available versions are : V0,V1,V2,V3,V4,V5\n", optarg);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
printf("version is %d\n", version_to_use);
|
printf("version is %d\n", version_to_use);
|
||||||
@@ -234,18 +234,21 @@ int main(int argc, char** argv)
|
|||||||
// -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
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
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)
|
||||||
char *end;
|
char *end;
|
||||||
amount_function_called = strtol(optarg,&end,10);
|
long value = strtol(optarg,&end,10);
|
||||||
|
|
||||||
if (amount_function_called <= 0 || end == optarg || *end != '\0') {
|
if (value <= 0 || end == optarg || *end != '\0') {
|
||||||
fprintf(stderr, "Invalid benchmarking input, the value should be greater than 0\n");
|
fprintf(stderr, "Invalid benchmarking input: %s\n", optarg);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
amount_function_called = (size_t)value;
|
||||||
will_benchmark = true;
|
will_benchmark = true;
|
||||||
printf("amount function called is %d\n", amount_function_called);
|
printf("amount function called is %zu\n", amount_function_called);
|
||||||
// call benchmarking function
|
// 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 .
|
||||||
@@ -282,7 +285,7 @@ int main(int argc, char** argv)
|
|||||||
dGiven = true;
|
dGiven = true;
|
||||||
char* height_string;
|
char* height_string;
|
||||||
char *end;
|
char *end;
|
||||||
width = strtol(optarg,&height_string,10);
|
long widthValue = strtol(optarg,&height_string,10);
|
||||||
|
|
||||||
if (height_string == optarg || *height_string != ',')
|
if (height_string == optarg || *height_string != ',')
|
||||||
{
|
{
|
||||||
@@ -290,13 +293,23 @@ int main(int argc, char** argv)
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
height = strtol(height_string + 1,&end,10);
|
long heightValue = strtol(height_string + 1,&end,10);
|
||||||
|
|
||||||
if (end == height_string + 1 || *end != '\0')
|
if (end == height_string + 1 || *end != '\0')
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Invalid height or extra characters: %s\n",optarg);
|
fprintf(stderr, "Invalid height or extra characters: %s\n",optarg);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (widthValue <= 0 || heightValue == 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Width must be > 0 and height must not be 0: %s\n", optarg);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
width = (size_t)widthValue;
|
||||||
|
height = (ssize_t)heightValue;
|
||||||
|
|
||||||
printf("width %zu, height %zd\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;
|
||||||
@@ -305,15 +318,16 @@ int main(int argc, char** argv)
|
|||||||
case 'n': {
|
case 'n': {
|
||||||
nGiven = true;
|
nGiven = true;
|
||||||
char* end;
|
char* end;
|
||||||
n = strtol(optarg,&end,10);
|
long nValue = strtol(optarg,&end,10);
|
||||||
|
|
||||||
if (end == optarg || *end != '\0' || n <= 0)
|
if (end == optarg || *end != '\0' || nValue <= 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Invalid n value: %s\n", optarg);
|
fprintf(stderr, "Invalid n value: %s\n", optarg);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("n:%d\n",n);
|
n = (unsigned) nValue;
|
||||||
|
printf("n:%u\n",n);
|
||||||
// -n <Zahl> —MaximaleAnzahlanIterationen pro Bildpixel
|
// -n <Zahl> —MaximaleAnzahlanIterationen pro Bildpixel
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user