diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/actionhelper.c | 40 | ||||
-rw-r--r-- | src/actionhelper.h | 6 | ||||
-rw-r--r-- | src/confparser.c | 39 | ||||
-rw-r--r-- | src/confparser.h | 2 |
4 files changed, 47 insertions, 40 deletions
diff --git a/src/actionhelper.c b/src/actionhelper.c index 75cc03f..14e8782 100644 --- a/src/actionhelper.c +++ b/src/actionhelper.c @@ -11,6 +11,7 @@ #include <libgen.h> #include "actionhelper.h" +#include "confparser.h" #include "ckerrlog.h" ERRLOG(action); @@ -155,6 +156,45 @@ void edit_print_suggested_configs(DB *db, const char *pName) { list_free(paths); } +int init_create_config_file(UserOpt *opt) { + char absVCdir[STR_L]; + if (!util_file_exists(list_get_at(opt->args, 0), absVCdir)) { + ERR("Version control directory: %s does not exist.", list_get_at(opt->args, 0)); + return 1; + } + + char absSRdir[STR_L]; + if (!util_file_exists(list_get_at(opt->args, 1), absSRdir)) { + ERR("Secret directory: %s does not exist.", list_get_at(opt->args, 1)); + return 1; + } + + if (!util_file_exists(opt->confDir, NULL)) { + util_mkdir(opt->confDir); + } + + char confName[STR_L]; + make_config_name(confName, opt->confDir); + FILE *f; + if ((f = fopen(confName, "w")) == NULL) { + return 1; + } + + char tmp[200]; + strcpy(tmp, "version_control_dir = "); + strcat(tmp, absVCdir); + strcat(tmp, "\n"); + fputs(tmp, f); + + strcpy(tmp, "secret_dir = "); + strcat(tmp, absSRdir); + strcat(tmp, "\n"); + fputs(tmp, f); + + fclose(f); + return 0; +} + ListOpt list_make_options(cklist *args) { list_rewind(args); ListOpt listOpt = { diff --git a/src/actionhelper.h b/src/actionhelper.h index d211df8..5bcb7ac 100644 --- a/src/actionhelper.h +++ b/src/actionhelper.h @@ -20,6 +20,12 @@ #include "cklist.h" #include "dblayer.h" +/********/ +/* INIT */ +/********/ + +extern int init_create_config_file(UserOpt *opt); + /*******/ /* ADD */ /*******/ diff --git a/src/confparser.c b/src/confparser.c index 2a11467..2463d79 100644 --- a/src/confparser.c +++ b/src/confparser.c @@ -142,42 +142,3 @@ void free_conf(Conf *conf) { CONFIG_VARIABLES_TABLE #undef X } - -int init_create_config_file(UserOpt *opt) { - char absVCdir[STR_L]; - if (!util_file_exists(list_get_at(opt->args, 0), absVCdir)) { - ERR("Version control directory: %s\ndoes not exist.\n", list_get_at(opt->args, 0)); - return 1; - } - - char absSRdir[STR_L]; - if (!util_file_exists(list_get_at(opt->args, 1), absSRdir)) { - ERR("Secret directory: %s\ndoes not exist.\n", list_get_at(opt->args, 1)); - return 1; - } - - if (!util_file_exists(opt->confDir, NULL)) { - util_mkdir(opt->confDir); - } - - char confName[STR_L]; - make_config_name(confName, opt->confDir); - FILE *f; - if ((f = fopen(confName, "w")) == NULL) { - return 1; - } - - char tmp[200]; - strcpy(tmp, "version_control_dir = "); - strcat(tmp, absVCdir); - strcat(tmp, "\n"); - fputs(tmp, f); - - strcpy(tmp, "secret_dir = "); - strcat(tmp, absSRdir); - strcat(tmp, "\n"); - fputs(tmp, f); - - fclose(f); - return 0; -} diff --git a/src/confparser.h b/src/confparser.h index b121a59..75201e4 100644 --- a/src/confparser.h +++ b/src/confparser.h @@ -52,6 +52,6 @@ struct ConfigValues { /* Parse the configuration file and fill the conf struct */ extern int config_file_parse(Conf *conf, UserOpt *opt); -extern int init_create_config_file(UserOpt *opt); +extern void make_config_name(char * ret, const char *confPath); extern void free_conf(Conf *conf); #endif // CONFPARSER_H |