Allow passing both "-D" and "-c"

This is particularly useful if one wants to use configuration and key
bindings from a specific directory, while using an appointment file from
somewhere else. "-c" has precedence over "-D".

Also update the usage message, man page and documentation.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
Lukas Fleischer 2012-06-27 12:07:02 +02:00
parent 7a75415a61
commit 86c465b0e5
4 changed files with 53 additions and 58 deletions

View File

@ -42,7 +42,7 @@ Synopsis
-------- --------
[verse] [verse]
*calcurse* [*-h*|*-v*] [*-an*] [*-t*[num]] [*-c*<file> | *-D*<dir>] *calcurse* [*-h*|*-v*] [*-an*] [*-t*[num]] [*-c*<file>] [*-D*<dir>]
[*-i*<file>] [*-x*[format]] [*-d* <date>|<num>] [*-i*<file>] [*-x*[format]] [*-d* <date>|<num>]
[*-s*[date]] [*-r*[range]] [*-S* <regex>] [*--status*] [*-s*[date]] [*-r*[range]] [*-S* <regex>] [*--status*]
@ -65,9 +65,8 @@ The following options are supported:
from which to read the appointments can be specified using the *-c* flag. from which to read the appointments can be specified using the *-c* flag.
*-c* <file>, *--calendar* <file>:: *-c* <file>, *--calendar* <file>::
Specify the calendar file to use. The default calendar is Specify the calendar file to use. The default calendar is *~/.calcurse/apts*
*~/.calcurse/apts* (see section 'FILES' below). This option is incompatible (see section 'FILES' below). This option has precedence over *-D*.
with -*D*.
*-d* <date|num>, *--day* <date|num>:: *-d* <date|num>, *--day* <date|num>::
Print the appointments for the given date or for the given number of Print the appointments for the given date or for the given number of
@ -100,8 +99,8 @@ menu. Four formats are available:
appointments can be specified using the *-c* flag. appointments can be specified using the *-c* flag.
*-D* <dir>, *--directory* <dir>:: *-D* <dir>, *--directory* <dir>::
Specify the data directory to use. This option is incompatible with -c. Specify the data directory to use. If not specified, the default directory is
If not specified, the default directory is *~/.calcurse/*. *~/.calcurse/*.
*--format-apt* <format>:: *--format-apt* <format>::
Specify a format to control the output of appointments in non-interactive Specify a format to control the output of appointments in non-interactive

View File

@ -181,8 +181,9 @@ long options are supported):
from which to read the appointments can be specified using the `-c` flag. from which to read the appointments can be specified using the `-c` flag.
`-c <file>, --calendar <file>`:: `-c <file>, --calendar <file>`::
Specify the calendar file to use. The default calendar is Specify the calendar file to use. The default calendar is `~/.calcurse/apts`
`~/.calcurse/apts` (see section <<basics_files,calcurse files>>). (see section <<basics_files,calcurse files>>). This option has precedence
over `-D`.
`-d <date|num>, --day <date|num>`:: `-d <date|num>, --day <date|num>`::
Print the appointments for the given date or for the given number of Print the appointments for the given date or for the given number of
@ -206,8 +207,8 @@ Note: as for the `-a` flag, the calendar from which to read the appointments
can be specified using the `-c` flag. can be specified using the `-c` flag.
`-D <dir>, --directory <dir>`:: `-D <dir>, --directory <dir>`::
Specify the data directory to use. This option is incompatible with -c. Specify the data directory to use. If not specified, the default directory is
If not specified, the default directory is `~/.calcurse/`. `~/.calcurse/`.
`--format-apt <format>`:: `--format-apt <format>`::
Specify a format to control the output of appointments in non-interactive Specify a format to control the output of appointments in non-interactive

View File

@ -62,7 +62,7 @@ static void usage(void)
const char *arg_usage = const char *arg_usage =
_("Usage: calcurse [-g|-h|-v] [-an] [-t[num]] [-i<file>] [-x[format]]\n" _("Usage: calcurse [-g|-h|-v] [-an] [-t[num]] [-i<file>] [-x[format]]\n"
" [-d <date>|<num>] [-s[date]] [-r[range]]\n" " [-d <date>|<num>] [-s[date]] [-r[range]]\n"
" [-c<file> | -D<dir>] [-S<regex>] [--status]\n" " [-c<file>] [-D<dir>] [-S<regex>] [--status]\n"
" [--read-only]\n"); " [--read-only]\n");
fputs(arg_usage, stdout); fputs(arg_usage, stdout);
} }
@ -112,9 +112,9 @@ static void help_arg(void)
" Don't save configuration nor appointments/todos. Use with care.\n" " Don't save configuration nor appointments/todos. Use with care.\n"
"\nFiles:\n" "\nFiles:\n"
" -c <file>, --calendar <file>\n" " -c <file>, --calendar <file>\n"
" specify the calendar <file> to use (incompatible with '-D').\n" " specify the calendar <file> to use (has precedence over '-D').\n"
"\n -D <dir>, --directory <dir>\n" "\n -D <dir>, --directory <dir>\n"
" specify the data directory to use (incompatible with '-c').\n" " specify the data directory to use.\n"
"\tIf not specified, the default directory is ~/.calcurse\n" "\tIf not specified, the default directory is ~/.calcurse\n"
"\nNon-interactive:\n" "\nNon-interactive:\n"
" -a, --appointment\n" " -a, --appointment\n"
@ -445,9 +445,7 @@ int parse_args(int argc, char **argv)
int unknown_flag = 0; int unknown_flag = 0;
/* Command-line flags */ /* Command-line flags */
int aflag = 0; /* -a: print appointments for current day */ int aflag = 0; /* -a: print appointments for current day */
int cflag = 0; /* -c: specify the calendar file to use */
int dflag = 0; /* -d: print appointments for a specified days */ int dflag = 0; /* -d: print appointments for a specified days */
int Dflag = 0; /* -D: specify data directory to use */
int hflag = 0; /* -h: print help text */ int hflag = 0; /* -h: print help text */
int gflag = 0; /* -g: run garbage collector */ int gflag = 0; /* -g: run garbage collector */
int iflag = 0; /* -i: import data */ int iflag = 0; /* -i: import data */
@ -516,7 +514,6 @@ int parse_args(int argc, char **argv)
load_data++; load_data++;
break; break;
case 'c': case 'c':
cflag = 1;
multiple_flag++; multiple_flag++;
cfile = optarg; cfile = optarg;
load_data++; load_data++;
@ -528,7 +525,6 @@ int parse_args(int argc, char **argv)
ddate = optarg; ddate = optarg;
break; break;
case 'D': case 'D':
Dflag = 1;
datadir = optarg; datadir = optarg;
break; break;
case 'h': case 'h':
@ -638,11 +634,6 @@ int parse_args(int argc, char **argv)
usage_try(); usage_try();
return EXIT_FAILURE; return EXIT_FAILURE;
/* Incorrect arguments */ /* Incorrect arguments */
} else if (Dflag && cflag) {
fputs(_("Options '-D' and '-c' cannot be used at the same time\n"), stderr);
usage();
usage_try();
return EXIT_FAILURE;
} else if (Sflag && !(aflag || dflag || rflag || sflag || tflag)) { } else if (Sflag && !(aflag || dflag || rflag || sflag || tflag)) {
fputs(_("Option '-S' must be used with either '-d', '-r', '-s', " fputs(_("Option '-S' must be used with either '-d', '-r', '-s', "
"'-a' or '-t'\n"), stderr); "'-a' or '-t'\n"), stderr);

View File

@ -231,7 +231,6 @@ void io_init(const char *cfile, const char *datadir)
snprintf(path_todo, BUFSIZ, "%s/" TODO_PATH_NAME, home); snprintf(path_todo, BUFSIZ, "%s/" TODO_PATH_NAME, home);
snprintf(path_conf, BUFSIZ, "%s/" CONF_PATH_NAME, home); snprintf(path_conf, BUFSIZ, "%s/" CONF_PATH_NAME, home);
snprintf(path_notes, BUFSIZ, "%s/" NOTES_DIR_NAME, home); snprintf(path_notes, BUFSIZ, "%s/" NOTES_DIR_NAME, home);
snprintf(path_apts, BUFSIZ, "%s/" APTS_PATH_NAME, home);
snprintf(path_keys, BUFSIZ, "%s/" KEYS_PATH_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);
@ -249,43 +248,48 @@ void io_init(const char *cfile, const char *datadir)
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_dmon_log, BUFSIZ, "%s/" DLOG_PATH, home);
snprintf(path_notes, BUFSIZ, "%s/" NOTES_DIR, home); snprintf(path_notes, BUFSIZ, "%s/" NOTES_DIR, home);
if (cfile == NULL) { }
snprintf(path_apts, BUFSIZ, "%s/" APTS_PATH, home);
if (cfile == NULL) {
if (datadir != NULL) {
snprintf(path_apts, BUFSIZ, "%s/" APTS_PATH_NAME, home);
} else { } else {
snprintf(apts_file, BUFSIZ, "%s", cfile); snprintf(path_apts, BUFSIZ, "%s/" APTS_PATH, home);
strncpy(path_apts, apts_file, BUFSIZ);
/* check if the file exists, otherwise create it */
data_file = fopen(path_apts, "r");
if (data_file == NULL) {
printf(_("%s does not exist, create it now [y or n] ? "), path_apts);
ch = getchar();
switch (ch) {
case 'N':
case 'n':
puts(_("aborting...\n"));
exit_calcurse(EXIT_FAILURE);
break;
case 'Y':
case 'y':
data_file = fopen(path_apts, "w");
if (data_file == NULL) {
perror(path_apts);
exit_calcurse(EXIT_FAILURE);
} else {
printf(_("%s successfully created\n"), path_apts);
puts(_("starting interactive mode...\n"));
}
break;
default:
puts(_("aborting...\n"));
exit_calcurse(EXIT_FAILURE);
break;
}
}
file_close(data_file, __FILE_POS__);
} }
} else {
snprintf(apts_file, BUFSIZ, "%s", cfile);
strncpy(path_apts, apts_file, BUFSIZ);
/* check if the file exists, otherwise create it */
data_file = fopen(path_apts, "r");
if (data_file == NULL) {
printf(_("%s does not exist, create it now [y or n] ? "), path_apts);
ch = getchar();
switch (ch) {
case 'N':
case 'n':
puts(_("aborting...\n"));
exit_calcurse(EXIT_FAILURE);
break;
case 'Y':
case 'y':
data_file = fopen(path_apts, "w");
if (data_file == NULL) {
perror(path_apts);
exit_calcurse(EXIT_FAILURE);
} else {
printf(_("%s successfully created\n"), path_apts);
puts(_("starting interactive mode...\n"));
}
break;
default:
puts(_("aborting...\n"));
exit_calcurse(EXIT_FAILURE);
break;
}
}
file_close(data_file, __FILE_POS__);
} }
} }