diff options
author | Quentin Hibon <qh.public@yahoo.com> | 2018-07-29 10:30:22 +0200 |
---|---|---|
committer | Lukas Fleischer <lfleischer@calcurse.org> | 2018-08-05 18:36:25 +0200 |
commit | e9611ce3a6c8e1d7f53bf5fe6102bf6def0d31e0 (patch) | |
tree | 6019315a90e45b9e7547e273124880baae5df73e /src/io.c | |
parent | 3788df6d78a42ff1c8b8bfac02dd67345d01a23b (diff) | |
download | calcurse-e9611ce3a6c8e1d7f53bf5fe6102bf6def0d31e0.tar.gz calcurse-e9611ce3a6c8e1d7f53bf5fe6102bf6def0d31e0.zip |
Use a path instead of a file for -C option
Allows to specify a configuration directory containing:
* conf
* keys
* hooks
When used in combination with -D $ddir, $ddir contains all the other
files not mentioned above.
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'src/io.c')
-rw-r--r-- | src/io.c | 41 |
1 files changed, 22 insertions, 19 deletions
@@ -225,45 +225,48 @@ unsigned io_fprintln(const char *fname, const char *fmt, ...) * which contains the calendar file. If none is given, then the default * one (~/.calcurse/apts) is taken. If the one given does not exist, it * is created. - * The datadir argument can be use to specify an alternative data root dir. - * The conffile argument can be use to specify an alternative configuration file. + * The datadir argument can be used to specify an alternative data root dir. + * The confdir argument can be used to specify an alternative configuration dir. */ -void io_init(const char *cfile, const char *datadir, const char *conffile) +void io_init(const char *cfile, const char *datadir, const char *confdir) { const char *home; if (datadir != NULL) { home = datadir; + snprintf(path_dir, BUFSIZ, "%s", home); - if (conffile) - snprintf(path_conf, BUFSIZ, "%s", conffile); - else - snprintf(path_conf, BUFSIZ, "%s/" CONF_PATH_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_todo, BUFSIZ, "%s/" TODO_PATH_NAME, home); - snprintf(path_notes, BUFSIZ, "%s/" NOTES_DIR_NAME, home); - snprintf(path_keys, BUFSIZ, "%s/" KEYS_PATH_NAME, home); snprintf(path_cpid, BUFSIZ, "%s/" CPID_PATH_NAME, home); snprintf(path_dpid, BUFSIZ, "%s/" DPID_PATH_NAME, home); - snprintf(path_dmon_log, BUFSIZ, "%s/" DLOG_PATH_NAME, - home); - snprintf(path_hooks, BUFSIZ, "%s/" HOOKS_DIR_NAME, home); + snprintf(path_notes, BUFSIZ, "%s/" NOTES_DIR_NAME, home); + snprintf(path_dmon_log, BUFSIZ, "%s/" DLOG_PATH_NAME, home); } else { home = getenv("HOME"); if (home == NULL) { home = "."; } - if (conffile) - snprintf(path_conf, BUFSIZ, "%s", conffile); - else - snprintf(path_conf, BUFSIZ, "%s/" CONF_PATH, home); + 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_todo, BUFSIZ, "%s/" TODO_PATH, home); - snprintf(path_keys, BUFSIZ, "%s/" KEYS_PATH, home); snprintf(path_cpid, BUFSIZ, "%s/" CPID_PATH, home); snprintf(path_dpid, BUFSIZ, "%s/" DPID_PATH, home); - snprintf(path_dmon_log, BUFSIZ, "%s/" DLOG_PATH, home); snprintf(path_notes, BUFSIZ, "%s/" NOTES_DIR, home); - snprintf(path_hooks, BUFSIZ, "%s/" HOOKS_DIR, home); + snprintf(path_dmon_log, BUFSIZ, "%s/" DLOG_PATH, home); } if (cfile == NULL) { |