Skip to content

Commit

Permalink
refactory main
Browse files Browse the repository at this point in the history
  • Loading branch information
scovl committed May 2, 2024
1 parent 09e0c16 commit 17f957f
Showing 1 changed file with 1 addition and 46 deletions.
47 changes: 1 addition & 46 deletions src/main.c
Original file line number Diff line number Diff line change
@@ -1,52 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h> // Necessário para a função isspace
#include "config.h"

char* trim_space(char* str) {
char* end;

while (isspace((unsigned char)*str) || *str == '"') str++;

if (*str == 0)
return str;

end = str + strlen(str) - 1;

while (end > str && (isspace((unsigned char)*end) || *end == '"')) end--;

end[1] = '\0';

return str;
}


bool validate_option(const char* key, const char* value) {
for (size_t i = 0; i < sizeof(config_options) / sizeof(ConfigOption); i++) {
if (strcmp(config_options[i].name, key) == 0) {
switch (config_options[i].type) {
case TYPE_STRING:
return true;
case TYPE_INT:
for (size_t j = 0; value[j] != '\0'; j++) {
if (!isdigit(value[j]) && !(value[j] == '-' && j == 0)) {
return false;
}
}
return true;
case TYPE_BOOL:
for (int j = 0; config_options[i].valid_values[j] != NULL; j++) {
if (strcmp(config_options[i].valid_values[j], value) == 0) {
return true;
}
}
return false;
}
}
}
return true;
}
#include "validation_utils.h" // Inclui o novo cabeçalho para as funções de validação

int main(int argc, char* argv[]) {
if (argc != 2) {
Expand Down

0 comments on commit 17f957f

Please sign in to comment.