|
12 | 12 | void getMainArguments(TMainArguments* pMainArguments, int argc, char* argv[]) { |
13 | 13 | int i; |
14 | 14 |
|
15 | | - char argumentName[50]; |
| 15 | + char* argumentName; |
16 | 16 | char* argumentValue; |
| 17 | + char* sep; |
17 | 18 |
|
18 | 19 | int argumentValueInt; |
19 | 20 |
|
20 | 21 | for (i = 1; i < argc; i++) { |
21 | | - argumentValue = malloc(50 * sizeof(char)); |
22 | | - sscanf(*(argv + i), "-- %[a-z|-] = %[-|a-z| |0-9]", argumentName, argumentValue); |
| 22 | + argumentName = *(argv + i); |
| 23 | + sep = strrchr(argumentName, '='); |
| 24 | + argumentValue = sep + 1; |
| 25 | + *sep = '\0'; |
23 | 26 |
|
24 | | - if (strcmp(argumentName, "dashboard-rows") == 0) { |
| 27 | + if (strcmp(argumentName, "--dashboard-rows") == 0) { |
25 | 28 | sscanf(argumentValue, "%d", &argumentValueInt); |
26 | 29 | if (validateRows(argumentValueInt)) pMainArguments->dashboardRows = argumentValueInt; |
27 | 30 |
|
28 | | - free(argumentValue); |
29 | | - |
30 | | - } else if (strcmp(argumentName, "dashboard-cols") == 0) { |
| 31 | + } else if (strcmp(argumentName, "--dashboard-cols") == 0) { |
31 | 32 | sscanf(argumentValue, "%d", &argumentValueInt); |
32 | 33 | if (validateCols(argumentValueInt)) pMainArguments->dashboardCols = argumentValueInt; |
33 | 34 |
|
34 | | - free(argumentValue); |
35 | | - |
36 | | - } else if (strcmp(argumentName, "pattern") == 0) { |
37 | | - if (validatePattern(argumentValue)) { |
38 | | - pMainArguments->pattern = argumentValue; |
39 | | - } else { |
40 | | - free(argumentValue); |
41 | | - }; |
| 35 | + } else if (strcmp(argumentName, "--pattern") == 0) { |
| 36 | + if (validatePattern(argumentValue)) pMainArguments->pattern = argumentValue; |
42 | 37 |
|
43 | | - } else if (strcmp(argumentName, "maximum-generation") == 0) { |
| 38 | + } else if (strcmp(argumentName, "--maximum-generation") == 0) { |
44 | 39 | if (validateGeneration(argumentValue)) { |
45 | 40 | sscanf(argumentValue, "%d", &argumentValueInt); |
46 | 41 | pMainArguments->maximumGeneration = argumentValueInt; |
47 | | - } |
48 | | - |
49 | | - free(argumentValue); |
| 42 | + }; |
50 | 43 |
|
51 | | - } else if (strcmp(argumentName, "delay") == 0) { |
| 44 | + } else if (strcmp(argumentName, "--delay") == 0) { |
52 | 45 | if (validateDelay(argumentValue)) { |
53 | 46 | sscanf(argumentValue, "%d", &argumentValueInt); |
54 | 47 | pMainArguments->delay = argumentValueInt; |
55 | 48 | }; |
56 | 49 |
|
57 | | - free(argumentValue); |
58 | | - |
59 | | - } else if (strcmp(argumentName, "platform") == 0) { |
60 | | - if (validatePlatform(argumentValue)) { |
61 | | - pMainArguments->platform = argumentValue; |
62 | | - } else { |
63 | | - free(argumentValue); |
64 | | - }; |
65 | | - |
66 | | - } else { |
67 | | - free(argumentValue); |
68 | | - } |
| 50 | + } else if (strcmp(argumentName, "--platform") == 0) { |
| 51 | + if (validatePlatform(argumentValue)) pMainArguments->platform = argumentValue; |
| 52 | + }; |
69 | 53 | } |
70 | 54 | } |
71 | 55 |
|
|
0 commit comments