summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQuentin Hibon <qh.public@yahoo.com>2018-08-25 12:04:12 +0200
committerLukas Fleischer <lfleischer@calcurse.org>2018-10-21 20:02:57 +0200
commit65064ceed10acdb09f7f6a26f4ab743e2a5e8086 (patch)
tree019f56a05dd7d308fba9b31e5b9e846e83595bb1 /src
parent8104c4aaf4c15b56d85aba682d7ce9bb3067b7b3 (diff)
downloadcalcurse-65064ceed10acdb09f7f6a26f4ab743e2a5e8086.tar.gz
calcurse-65064ceed10acdb09f7f6a26f4ab743e2a5e8086.zip
Check if the configuration folder exists
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'src')
-rw-r--r--src/calcurse.h1
-rw-r--r--src/io.c28
-rw-r--r--src/vars.c1
3 files changed, 20 insertions, 10 deletions
diff --git a/src/calcurse.h b/src/calcurse.h
index a54f2bc..fb20da7 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -1216,6 +1216,7 @@ extern int want_reload;
extern const char *datefmt_str[DATE_FORMATS];
extern int days[12];
extern char path_dir[BUFSIZ];
+extern char path_conf_dir[BUFSIZ];
extern char path_todo[BUFSIZ];
extern char path_apts[BUFSIZ];
extern char path_conf[BUFSIZ];
diff --git a/src/io.c b/src/io.c
index d3c9c0b..68e6f73 100644
--- a/src/io.c
+++ b/src/io.c
@@ -144,17 +144,21 @@ unsigned io_fprintln(const char *fname, const char *fmt, ...)
void io_init(const char *cfile, const char *datadir, const char *confdir)
{
const char *home;
+ const char *conf_home;
if (datadir != NULL) {
home = datadir;
+ if (confdir == NULL)
+ conf_home = home;
+ else
+ conf_home = confdir;
snprintf(path_dir, BUFSIZ, "%s", home);
- if (!confdir)
- confdir = path_dir;
- snprintf(path_conf, BUFSIZ, "%s/" CONF_PATH_NAME, confdir);
- snprintf(path_keys, BUFSIZ, "%s/" KEYS_PATH_NAME, confdir);
- snprintf(path_hooks, BUFSIZ, "%s/" HOOKS_DIR_NAME, confdir);
+ snprintf(path_conf_dir, BUFSIZ, "%s", conf_home);
+ snprintf(path_conf, BUFSIZ, "%s/" CONF_PATH_NAME, conf_home);
+ snprintf(path_keys, BUFSIZ, "%s/" KEYS_PATH_NAME, conf_home);
+ snprintf(path_hooks, BUFSIZ, "%s/" HOOKS_DIR_NAME, conf_home);
snprintf(path_todo, BUFSIZ, "%s/" TODO_PATH_NAME, home);
snprintf(path_cpid, BUFSIZ, "%s/" CPID_PATH_NAME, home);
@@ -166,14 +170,17 @@ void io_init(const char *cfile, const char *datadir, const char *confdir)
if (home == NULL) {
home = ".";
}
+ if (confdir == NULL)
+ conf_home = home;
+ else
+ conf_home = confdir;
snprintf(path_dir, BUFSIZ, "%s/" DIR_NAME, home);
- if (!confdir)
- confdir = path_dir;
- snprintf(path_conf, BUFSIZ, "%s/" CONF_PATH_NAME, confdir);
- snprintf(path_keys, BUFSIZ, "%s/" KEYS_PATH_NAME, confdir);
- snprintf(path_hooks, BUFSIZ, "%s/" HOOKS_DIR_NAME, confdir);
+ snprintf(path_conf_dir, BUFSIZ, "%s", conf_home);
+ snprintf(path_conf, BUFSIZ, "%s/" CONF_PATH_NAME, conf_home);
+ snprintf(path_keys, BUFSIZ, "%s/" KEYS_PATH_NAME, conf_home);
+ snprintf(path_hooks, BUFSIZ, "%s/" HOOKS_DIR_NAME, conf_home);
snprintf(path_todo, BUFSIZ, "%s/" TODO_PATH, home);
snprintf(path_cpid, BUFSIZ, "%s/" CPID_PATH, home);
@@ -1152,6 +1159,7 @@ int io_check_data_files(void)
int missing = 0;
missing += io_check_dir(path_dir) ? 0 : 1;
+ missing += io_check_dir(path_conf_dir) ? 0 : 1;
missing += io_check_dir(path_notes) ? 0 : 1;
missing += io_check_file(path_todo) ? 0 : 1;
missing += io_check_file(path_apts) ? 0 : 1;
diff --git a/src/vars.c b/src/vars.c
index 30393fd..0ebac8f 100644
--- a/src/vars.c
+++ b/src/vars.c
@@ -80,6 +80,7 @@ int days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
* io_init()
*/
char path_dir[] = "";
+char path_conf_dir[] = "";
char path_todo[] = "";
char path_apts[] = "";
char path_conf[] = "";