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>
This commit is contained in:
parent
3788df6d78
commit
e9611ce3a6
10
src/args.c
10
src/args.c
@ -83,7 +83,7 @@ enum {
|
|||||||
static void usage(void)
|
static void usage(void)
|
||||||
{
|
{
|
||||||
printf("%s\n", _("usage: calcurse [--daemon|-F|-G|-g|-i<file>|-Q|--status|-x[<format>]]\n"
|
printf("%s\n", _("usage: calcurse [--daemon|-F|-G|-g|-i<file>|-Q|--status|-x[<format>]]\n"
|
||||||
" [-c<file>] [-C<file] [-D<path>] [-h] [-q] [--read-only] [-v]\n"
|
" [-c<file>] [-C<path>] [-D<path>] [-h] [-q] [--read-only] [-v]\n"
|
||||||
" [--filter-*] [--format-*]"));
|
" [--filter-*] [--format-*]"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ static void help_arg(void)
|
|||||||
putchar('\n');
|
putchar('\n');
|
||||||
printf("%s\n", _("Miscellaneous:"));
|
printf("%s\n", _("Miscellaneous:"));
|
||||||
printf("%s\n", _(" -c, --calendar <file> Specify the calendar data file to use"));
|
printf("%s\n", _(" -c, --calendar <file> Specify the calendar data file to use"));
|
||||||
printf("%s\n", _(" -C, --conf <file> Specify the configuration file to use"));
|
printf("%s\n", _(" -C, --conf <path> Specify the configuration path to use"));
|
||||||
printf("%s\n", _(" --daemon Run notification daemon in the background"));
|
printf("%s\n", _(" --daemon Run notification daemon in the background"));
|
||||||
printf("%s\n", _(" -D, --directory <path> Specify the data directory to use"));
|
printf("%s\n", _(" -D, --directory <path> Specify the data directory to use"));
|
||||||
printf("%s\n", _(" -g, --gc Run the garbage collector and exit"));
|
printf("%s\n", _(" -g, --gc Run the garbage collector and exit"));
|
||||||
@ -406,7 +406,7 @@ int parse_args(int argc, char **argv)
|
|||||||
int dump_imported = 0, export_uid = 0;
|
int dump_imported = 0, export_uid = 0;
|
||||||
/* Data file locations */
|
/* Data file locations */
|
||||||
const char *datadir = NULL;
|
const char *datadir = NULL;
|
||||||
const char *cfile = NULL, *ifile = NULL, *conffile = NULL;
|
const char *cfile = NULL, *ifile = NULL, *confdir = NULL;
|
||||||
|
|
||||||
int non_interactive = 1;
|
int non_interactive = 1;
|
||||||
int ch;
|
int ch;
|
||||||
@ -479,7 +479,7 @@ int parse_args(int argc, char **argv)
|
|||||||
cfile = optarg;
|
cfile = optarg;
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
conffile = optarg;
|
confdir = optarg;
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
if (is_all_digit(optarg) ||
|
if (is_all_digit(optarg) ||
|
||||||
@ -726,7 +726,7 @@ int parse_args(int argc, char **argv)
|
|||||||
else if (range < 0)
|
else if (range < 0)
|
||||||
from = date_sec_change(to, 0, range);
|
from = date_sec_change(to, 0, range);
|
||||||
|
|
||||||
io_init(cfile, datadir, conffile);
|
io_init(cfile, datadir, confdir);
|
||||||
io_check_dir(path_dir);
|
io_check_dir(path_dir);
|
||||||
io_check_dir(path_notes);
|
io_check_dir(path_notes);
|
||||||
|
|
||||||
|
41
src/io.c
41
src/io.c
@ -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
|
* 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
|
* one (~/.calcurse/apts) is taken. If the one given does not exist, it
|
||||||
* is created.
|
* is created.
|
||||||
* The datadir argument can be use to specify an alternative data root dir.
|
* The datadir argument can be used to specify an alternative data root dir.
|
||||||
* The conffile argument can be use to specify an alternative configuration file.
|
* 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;
|
const char *home;
|
||||||
|
|
||||||
if (datadir != NULL) {
|
if (datadir != NULL) {
|
||||||
home = datadir;
|
home = datadir;
|
||||||
|
|
||||||
snprintf(path_dir, BUFSIZ, "%s", home);
|
snprintf(path_dir, BUFSIZ, "%s", home);
|
||||||
if (conffile)
|
if (!confdir)
|
||||||
snprintf(path_conf, BUFSIZ, "%s", conffile);
|
confdir = path_dir;
|
||||||
else
|
|
||||||
snprintf(path_conf, BUFSIZ, "%s/" CONF_PATH_NAME, home);
|
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_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_cpid, BUFSIZ, "%s/" CPID_PATH_NAME, home);
|
||||||
snprintf(path_dpid, BUFSIZ, "%s/" DPID_PATH_NAME, home);
|
snprintf(path_dpid, BUFSIZ, "%s/" DPID_PATH_NAME, home);
|
||||||
snprintf(path_dmon_log, BUFSIZ, "%s/" DLOG_PATH_NAME,
|
snprintf(path_notes, BUFSIZ, "%s/" NOTES_DIR_NAME, home);
|
||||||
home);
|
snprintf(path_dmon_log, BUFSIZ, "%s/" DLOG_PATH_NAME, home);
|
||||||
snprintf(path_hooks, BUFSIZ, "%s/" HOOKS_DIR_NAME, home);
|
|
||||||
} else {
|
} else {
|
||||||
home = getenv("HOME");
|
home = getenv("HOME");
|
||||||
if (home == NULL) {
|
if (home == NULL) {
|
||||||
home = ".";
|
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);
|
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_todo, BUFSIZ, "%s/" TODO_PATH, home);
|
||||||
snprintf(path_keys, BUFSIZ, "%s/" KEYS_PATH, home);
|
|
||||||
snprintf(path_cpid, BUFSIZ, "%s/" CPID_PATH, home);
|
snprintf(path_cpid, BUFSIZ, "%s/" CPID_PATH, home);
|
||||||
snprintf(path_dpid, BUFSIZ, "%s/" DPID_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_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) {
|
if (cfile == NULL) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user