aboutsummaryrefslogtreecommitdiffstats
path: root/src/confparser.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/confparser.c')
-rw-r--r--src/confparser.c75
1 files changed, 20 insertions, 55 deletions
diff --git a/src/confparser.c b/src/confparser.c
index 4599a84..6dea001 100644
--- a/src/confparser.c
+++ b/src/confparser.c
@@ -23,16 +23,6 @@ void conf_values_initialize(Conf *c) {
#undef X
}
-int remove_newline(char buff[]) {
- int initLength = strlen(buff);
- for (int i = 0; i < initLength; i++) {
- if (buff[i] == '\n') {
- buff[i] = ' ';
- }
- }
- return strlen(buff);
-}
-
int read_next_line(char *line, FILE *f) {
char nextLine[STR_L];
if (fgets(nextLine, STR_L, f) == NULL) {
@@ -63,70 +53,45 @@ void make_config_name(char * ret, const char *confPath) {
strcpy(ret, tmp);
}
-ConfigParserResult parse(Conf *conf, UserOpt *opt) {
+int config_file_parse(Conf *conf, UserOpt *opt) {
+ LOG("Using '%s' for ck configuration directory", opt->confDir);
conf_values_initialize(conf);
FILE *confPtr;
char confName[STR_L];
+ char line[STR_L];
+ char matched[STR_L];
+
make_config_name(confName, opt->confDir);
if ((confPtr = fopen(confName, "r")) == NULL) {
ERR("%s is not readable, check the permissions.", confName)
- return CPR_NO_CONFIG_FILE;
+ return -1;
}
- int flag = 1;
- char line[STR_L];
- char matched[STR_L];
while (read_next_line(line, confPtr) == 0) {
if (strlen(line) > STR_L) {
- return CPR_WRONG_CONFIG;
+ return -1;
}
switch(match_variables(line, matched)) {
-#define X(var, str, name) \
- case CV_##var: \
- conf->var = malloc(strlen(matched)+1); \
- strcpy(conf->var, matched); \
- if (!util_is_dir(matched)) { \
- return CPR_WRONG_##var; \
- } \
- LOG("Found %s: %s", name, conf->var); \
+#define X(var, str, name) \
+ case CV_##var: \
+ conf->var = malloc(strlen(matched)+1); \
+ strcpy(conf->var, matched); \
+ if (!util_is_dir(matched)) { \
+ ERR("%s %s defined in config doesn't exist", \
+ name, conf->var); \
+ return -1; \
+ } \
+ LOG("Found %s: %s", name, conf->var); \
break;
CONFIG_VARIABLES_TABLE
#undef X
case CV_NO_VAL_OR_COMMENT:
break;
default:
- if (line[strlen(line) - 1] == '\n') {
- ERR("Config error in line: %.*s", strlen(line) - 1, line);
- }
- else {
- ERR("Config error in line: %s", line);
- }
- flag = 0;
+ ERR("In line: %s", line);
+ return -1;
}
}
-
- if (flag) {
- return CPR_OK;
- }
- return CPR_WRONG_CONFIG;
-}
-
-int config_file_parse(Conf *conf, UserOpt *opt) {
- LOG("Using '%s' for ck configuration directory", opt->confDir);
- switch (parse(conf, opt)) {
-#define X(var,str,name) \
- case CPR_WRONG_##var: \
- ERR("%s %s defined in config doesn't exist", name, conf->var); \
- return -1; \
- break;
- CONFIG_VARIABLES_TABLE
-#undef X
- case CPR_OK:
- return 0;
- case CPR_NO_CONFIG_FILE:
- case CPR_WRONG_CONFIG:
- break;
- }
- return -1;
+ return 0;
}
void free_conf(Conf *conf) {