Skip to content

Commit

Permalink
fix: fix getMainArguments function
Browse files Browse the repository at this point in the history
Co-authored-by: Tiago Giannotti <[email protected]>
  • Loading branch information
hozlucas28 and TiagoGiannotti committed Oct 11, 2024
1 parent 5a42f5a commit c1e0df6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 38 deletions.
12 changes: 6 additions & 6 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ int main(int argc, char* argv[]) {
setDefaultMainArguments(&mainArguments);
getMainArguments(&mainArguments, argc, argv);

// printf("> dashboardRows --> %d\n", mainArguments.dashboardRows);
// printf("> dashboardCols --> %d\n", mainArguments.dashboardCols);
// printf("> pattern --> %s\n", mainArguments.pattern);
// printf("> maximumGeneration --> %d\n", mainArguments.maximumGeneration);
// printf("> delay --> %d\n", mainArguments.delay);
// printf("> platform --> %s\n", mainArguments.platform);
printf("> dashboardRows --> %d\n", mainArguments.dashboardRows);
printf("> dashboardCols --> %d\n", mainArguments.dashboardCols);
printf("> pattern --> \"%s\"\n", mainArguments.pattern);
printf("> maximumGeneration --> %d\n", mainArguments.maximumGeneration);
printf("> delay --> %d\n", mainArguments.delay);
printf("> platform --> \"%s\"\n", mainArguments.platform);

// free(mainArguments.pattern);
// free(mainArguments.platform);
Expand Down
48 changes: 16 additions & 32 deletions src/utilities.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,60 +12,44 @@
void getMainArguments(TMainArguments* pMainArguments, int argc, char* argv[]) {
int i;

char argumentName[50];
char* argumentName;
char* argumentValue;
char* sep;

int argumentValueInt;

for (i = 1; i < argc; i++) {
argumentValue = malloc(50 * sizeof(char));
sscanf(*(argv + i), "-- %[a-z|-] = %[-|a-z| |0-9]", argumentName, argumentValue);
argumentName = *(argv + i);
sep = strrchr(argumentName, '=');
argumentValue = sep + 1;
*sep = '\0';

if (strcmp(argumentName, "dashboard-rows") == 0) {
if (strcmp(argumentName, "--dashboard-rows") == 0) {
sscanf(argumentValue, "%d", &argumentValueInt);
if (validateRows(argumentValueInt)) pMainArguments->dashboardRows = argumentValueInt;

free(argumentValue);

} else if (strcmp(argumentName, "dashboard-cols") == 0) {
} else if (strcmp(argumentName, "--dashboard-cols") == 0) {
sscanf(argumentValue, "%d", &argumentValueInt);
if (validateCols(argumentValueInt)) pMainArguments->dashboardCols = argumentValueInt;

free(argumentValue);

} else if (strcmp(argumentName, "pattern") == 0) {
if (validatePattern(argumentValue)) {
pMainArguments->pattern = argumentValue;
} else {
free(argumentValue);
};
} else if (strcmp(argumentName, "--pattern") == 0) {
if (validatePattern(argumentValue)) pMainArguments->pattern = argumentValue;

} else if (strcmp(argumentName, "maximum-generation") == 0) {
} else if (strcmp(argumentName, "--maximum-generation") == 0) {
if (validateGeneration(argumentValue)) {
sscanf(argumentValue, "%d", &argumentValueInt);
pMainArguments->maximumGeneration = argumentValueInt;
}

free(argumentValue);
};

} else if (strcmp(argumentName, "delay") == 0) {
} else if (strcmp(argumentName, "--delay") == 0) {
if (validateDelay(argumentValue)) {
sscanf(argumentValue, "%d", &argumentValueInt);
pMainArguments->delay = argumentValueInt;
};

free(argumentValue);

} else if (strcmp(argumentName, "platform") == 0) {
if (validatePlatform(argumentValue)) {
pMainArguments->platform = argumentValue;
} else {
free(argumentValue);
};

} else {
free(argumentValue);
}
} else if (strcmp(argumentName, "--platform") == 0) {
if (validatePlatform(argumentValue)) pMainArguments->platform = argumentValue;
};
}
}

Expand Down

0 comments on commit c1e0df6

Please sign in to comment.