-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilities.c
78 lines (60 loc) · 2.55 KB
/
utilities.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "./utilities.h"
#include <stdio.h>
#include <string.h>
#include "../libs/main.h"
#include "./macros.h"
#include "./sdl/main.h"
#include "./validators.h"
void getMainArguments(TMainArguments* pMainArguments, const int argc, char* argv[]) {
size_t i;
char* argumentName;
char* argumentValue;
char* sep;
int argumentValueInt;
for (i = 1; i < argc; i++) {
argumentName = *(argv + i);
sep = strrchr(argumentName, '=');
if (sep == NULL) continue;
argumentValue = sep + 1;
*sep = '\0';
if (strcmp(argumentName, "--dashboard-rows") == 0) {
sscanf(argumentValue, "%d", &argumentValueInt);
if (validateRows(argumentValueInt)) pMainArguments->dashboardRows = argumentValueInt;
} else if (strcmp(argumentName, "--dashboard-cols") == 0) {
sscanf(argumentValue, "%d", &argumentValueInt);
if (validateCols(argumentValueInt)) pMainArguments->dashboardCols = argumentValueInt;
} else if (strcmp(argumentName, "--pattern") == 0) {
if (validatePattern(argumentValue)) pMainArguments->pattern = argumentValue;
} else if (strcmp(argumentName, "--maximum-generation") == 0) {
if (validateGeneration(argumentValue)) {
sscanf(argumentValue, "%d", &argumentValueInt);
pMainArguments->maximumGeneration = argumentValueInt;
};
} else if (strcmp(argumentName, "--delay") == 0) {
if (validateDelay(argumentValue)) {
sscanf(argumentValue, "%d", &argumentValueInt);
pMainArguments->delay = argumentValueInt;
};
} else if (strcmp(argumentName, "--platform") == 0) {
if (validatePlatform(argumentValue)) pMainArguments->platform = argumentValue;
} else if (strcmp(argumentName, "--initial-state-file") == 0) {
if (validateInitialStateFile(argumentValue))
pMainArguments->initialStateFile = argumentValue;
};
}
}
void setDefaultMainArguments(TMainArguments* pMainArguments) {
int screenWidth;
int screenHeight;
if (!getScreenResolution(&screenWidth, &screenHeight)) {
screenWidth = 640;
screenHeight = 360;
};
pMainArguments->dashboardRows = (screenHeight / CELL_SIZE) * 0.93;
pMainArguments->dashboardCols = (screenWidth / CELL_SIZE) * 0.99;
pMainArguments->pattern = "";
pMainArguments->maximumGeneration = 0;
pMainArguments->delay = 0;
pMainArguments->platform = "";
pMainArguments->initialStateFile = "";
}