diff options
author | gramanas <anastasis.gramm2@gmail.com> | 2018-10-25 19:06:34 +0300 |
---|---|---|
committer | gramanas <anastasis.gramm2@gmail.com> | 2018-10-25 19:06:34 +0300 |
commit | c3267a360860de225fa0af666d99f60d03266249 (patch) | |
tree | 6d9db577082bec43074c07194d14ce9694754ce0 | |
parent | d29c929e444d69ea7d4ce146f67f4c8df36baa95 (diff) | |
download | ck-c3267a360860de225fa0af666d99f60d03266249.tar.gz ck-c3267a360860de225fa0af666d99f60d03266249.tar.bz2 ck-c3267a360860de225fa0af666d99f60d03266249.zip |
Fix config parser bug
-rw-r--r-- | CMakeLists.txt | 3 | ||||
-rw-r--r-- | src/ck.c | 3 | ||||
-rw-r--r-- | src/confparser.c | 27 |
3 files changed, 17 insertions, 16 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b1bc41..3808c3c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,9 @@ project(ck C) set(ck_MAJOR_VERSION 0) set(ck_MINOR_VERSION 7) +# c flags +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") + # options option(CK_ASAN "Build with asan") option(CK_DEBUG "Build with debug symbols") @@ -54,7 +54,7 @@ int main(int argc, char *argv[]) { goto error; } /* Finally parse the config file and exit on error */ - if (!config_file_parse(&conf, &opt)) { + if (config_file_parse(&conf, &opt)) { goto error; } } @@ -73,7 +73,6 @@ int main(int argc, char *argv[]) { error: free_user_opt(&opt); free_conf(&conf); - close: report_errlog(); return 0; } diff --git a/src/confparser.c b/src/confparser.c index 95c8704..4599a84 100644 --- a/src/confparser.c +++ b/src/confparser.c @@ -17,8 +17,10 @@ ERRLOG(configfile); const char * const CONFIG_NAME = "/ckrc"; void conf_values_initialize(Conf *c) { - c->scrt_dir = NULL; - c->vc_dir = NULL; +#define X(var, str, name) \ + c->var = NULL; + CONFIG_VARIABLES_TABLE +#undef X } int remove_newline(char buff[]) { @@ -67,6 +69,7 @@ ConfigParserResult parse(Conf *conf, UserOpt *opt) { char confName[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; } int flag = 1; @@ -97,17 +100,14 @@ ConfigParserResult parse(Conf *conf, UserOpt *opt) { else { ERR("Config error in line: %s", line); } + flag = 0; } } -#define X(var, str) \ - if (conf->var == NULL) { \ - flag = 0; \ - CONFIG_VARIABLES_TABLE -#undef X + if (flag) { return CPR_OK; } - return CPR_NO_CONFIG_FILE; + return CPR_WRONG_CONFIG; } int config_file_parse(Conf *conf, UserOpt *opt) { @@ -116,18 +116,17 @@ int config_file_parse(Conf *conf, UserOpt *opt) { #define X(var,str,name) \ case CPR_WRONG_##var: \ ERR("%s %s defined in config doesn't exist", name, conf->var); \ - return 0; \ + return -1; \ break; CONFIG_VARIABLES_TABLE #undef X - case CPR_NO_CONFIG_FILE: - ERR("The config file specified could not be found"); + case CPR_OK: return 0; + case CPR_NO_CONFIG_FILE: case CPR_WRONG_CONFIG: - ERR("Config help\n"); - case CPR_OK: - return 1; + break; } + return -1; } void free_conf(Conf *conf) { |