aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2013-04-13 23:31:06 +0200
committerLukas Fleischer <calcurse@cryptocrack.de>2013-04-14 00:19:01 +0200
commit694d28eb78dfad98e2e7ea670d93a153d8efd368 (patch)
tree485dc11d3644d9dadb5fd4d67c5ef8103be79623 /src
parent9907069f442c56c90b67accb2d8fbd046dfce6db (diff)
downloadcalcurse-694d28eb78dfad98e2e7ea670d93a153d8efd368.tar.gz
calcurse-694d28eb78dfad98e2e7ea670d93a153d8efd368.zip
Use tabs instead of spaces for indentation
This completes our switch to the Linux kernel coding style. Note that we still use deeply nested constructs at some places which need to be fixed up later. Converted using the `Lindent` script from the Linux kernel code base, along with some manual fixes. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Diffstat (limited to 'src')
-rw-r--r--src/apoint.c273
-rw-r--r--src/args.c1107
-rw-r--r--src/calcurse.c847
-rw-r--r--src/calcurse.h449
-rw-r--r--src/config.c698
-rw-r--r--src/custom.c1869
-rw-r--r--src/day.c937
-rw-r--r--src/dmon.c233
-rw-r--r--src/event.c140
-rw-r--r--src/getstring.c383
-rw-r--r--src/help.c1417
-rw-r--r--src/htable.h2
-rw-r--r--src/ical.c1652
-rw-r--r--src/io.c1939
-rw-r--r--src/keys.c880
-rw-r--r--src/llist.c271
-rw-r--r--src/llist.h8
-rw-r--r--src/llist_ts.h6
-rw-r--r--src/mem.c281
-rw-r--r--src/note.c290
-rw-r--r--src/notify.c1082
-rw-r--r--src/pcal.c384
-rw-r--r--src/recur.c1105
-rw-r--r--src/sha1.c321
-rw-r--r--src/sha1.h6
-rw-r--r--src/sigs.c72
-rw-r--r--src/todo.c100
-rw-r--r--src/ui-calendar.c1182
-rw-r--r--src/ui-day.c1503
-rw-r--r--src/ui-todo.c360
-rw-r--r--src/utf8.c556
-rw-r--r--src/utils.c1889
-rw-r--r--src/vars.c132
-rw-r--r--src/wins.c779
34 files changed, 11867 insertions, 11286 deletions
diff --git a/src/apoint.c b/src/apoint.c
index ca400e9..f00dd1e 100644
--- a/src/apoint.c
+++ b/src/apoint.c
@@ -45,31 +45,31 @@ llist_ts_t alist_p;
void apoint_free(struct apoint *apt)
{
- mem_free(apt->mesg);
- erase_note(&apt->note);
- mem_free(apt);
+ mem_free(apt->mesg);
+ erase_note(&apt->note);
+ mem_free(apt);
}
struct apoint *apoint_dup(struct apoint *in)
{
- EXIT_IF(!in, _("null pointer"));
-
- struct apoint *apt = mem_malloc(sizeof(struct apoint));
- apt->start = in->start;
- apt->dur = in->dur;
- apt->state = in->state;
- apt->mesg = mem_strdup(in->mesg);
- if (in->note)
- apt->note = mem_strdup(in->note);
- else
- apt->note = NULL;
-
- return apt;
+ EXIT_IF(!in, _("null pointer"));
+
+ struct apoint *apt = mem_malloc(sizeof(struct apoint));
+ apt->start = in->start;
+ apt->dur = in->dur;
+ apt->state = in->state;
+ apt->mesg = mem_strdup(in->mesg);
+ if (in->note)
+ apt->note = mem_strdup(in->note);
+ else
+ apt->note = NULL;
+
+ return apt;
}
void apoint_llist_init(void)
{
- LLIST_TS_INIT(&alist_p);
+ LLIST_TS_INIT(&alist_p);
}
/*
@@ -79,142 +79,145 @@ void apoint_llist_init(void)
*/
void apoint_llist_free(void)
{
- LLIST_TS_FREE_INNER(&alist_p, apoint_free);
- LLIST_TS_FREE(&alist_p);
+ LLIST_TS_FREE_INNER(&alist_p, apoint_free);
+ LLIST_TS_FREE(&alist_p);
}
static int apoint_cmp_start(struct apoint *a, struct apoint *b)
{
- return a->start < b->start ? -1 : (a->start == b->start ? 0 : 1);
+ return a->start < b->start ? -1 : (a->start == b->start ? 0 : 1);
}
struct apoint *apoint_new(char *mesg, char *note, long start, long dur,
- char state)
+ char state)
{
- struct apoint *apt;
+ struct apoint *apt;
- apt = mem_malloc(sizeof(struct apoint));
- apt->mesg = mem_strdup(mesg);
- apt->note = (note != NULL) ? mem_strdup(note) : NULL;
- apt->state = state;
- apt->start = start;
- apt->dur = dur;
+ apt = mem_malloc(sizeof(struct apoint));
+ apt->mesg = mem_strdup(mesg);
+ apt->note = (note != NULL) ? mem_strdup(note) : NULL;
+ apt->state = state;
+ apt->start = start;
+ apt->dur = dur;
- LLIST_TS_LOCK(&alist_p);
- LLIST_TS_ADD_SORTED(&alist_p, apt, apoint_cmp_start);
- LLIST_TS_UNLOCK(&alist_p);
+ LLIST_TS_LOCK(&alist_p);
+ LLIST_TS_ADD_SORTED(&alist_p, apt, apoint_cmp_start);
+ LLIST_TS_UNLOCK(&alist_p);
- return apt;
+ return apt;
}
unsigned apoint_inday(struct apoint *i, long *start)
{
- return (i->start <= *start + DAYINSEC && i->start + i->dur > *start);
+ return (i->start <= *start + DAYINSEC
+ && i->start + i->dur > *start);
}
void apoint_sec2str(struct apoint *o, long day, char *start, char *end)
{
- struct tm lt;
- time_t t;
-
- if (o->start < day) {
- strncpy(start, "..:..", 6);
- } else {
- t = o->start;
- localtime_r(&t, &lt);
- snprintf(start, HRMIN_SIZE, "%02u:%02u", lt.tm_hour, lt.tm_min);
- }
- if (o->start + o->dur > day + DAYINSEC) {
- strncpy(end, "..:..", 6);
- } else {
- t = o->start + o->dur;
- localtime_r(&t, &lt);
- snprintf(end, HRMIN_SIZE, "%02u:%02u", lt.tm_hour, lt.tm_min);
- }
+ struct tm lt;
+ time_t t;
+
+ if (o->start < day) {
+ strncpy(start, "..:..", 6);
+ } else {
+ t = o->start;
+ localtime_r(&t, &lt);
+ snprintf(start, HRMIN_SIZE, "%02u:%02u", lt.tm_hour,
+ lt.tm_min);
+ }
+ if (o->start + o->dur > day + DAYINSEC) {
+ strncpy(end, "..:..", 6);
+ } else {
+ t = o->start + o->dur;
+ localtime_r(&t, &lt);
+ snprintf(end, HRMIN_SIZE, "%02u:%02u", lt.tm_hour,
+ lt.tm_min);
+ }
}
void apoint_write(struct apoint *o, FILE * f)
{
- struct tm lt;
- time_t t;
+ struct tm lt;
+ time_t t;
- t = o->start;
- localtime_r(&t, &lt);
- fprintf(f, "%02u/%02u/%04u @ %02u:%02u", lt.tm_mon + 1, lt.tm_mday,
- 1900 + lt.tm_year, lt.tm_hour, lt.tm_min);
+ t = o->start;
+ localtime_r(&t, &lt);
+ fprintf(f, "%02u/%02u/%04u @ %02u:%02u", lt.tm_mon + 1, lt.tm_mday,
+ 1900 + lt.tm_year, lt.tm_hour, lt.tm_min);
- t = o->start + o->dur;
- localtime_r(&t, &lt);
- fprintf(f, " -> %02u/%02u/%04u @ %02u:%02u ", lt.tm_mon + 1, lt.tm_mday,
- 1900 + lt.tm_year, lt.tm_hour, lt.tm_min);
+ t = o->start + o->dur;
+ localtime_r(&t, &lt);
+ fprintf(f, " -> %02u/%02u/%04u @ %02u:%02u ", lt.tm_mon + 1,
+ lt.tm_mday, 1900 + lt.tm_year, lt.tm_hour, lt.tm_min);
- if (o->note != NULL)
- fprintf(f, ">%s ", o->note);
+ if (o->note != NULL)
+ fprintf(f, ">%s ", o->note);
- if (o->state & APOINT_NOTIFY)
- fputc('!', f);
- else
- fputc('|', f);
+ if (o->state & APOINT_NOTIFY)
+ fputc('!', f);
+ else
+ fputc('|', f);
- fprintf(f, "%s\n", o->mesg);
+ fprintf(f, "%s\n", o->mesg);
}
-struct apoint *apoint_scan(FILE * f, struct tm start, struct tm end, char state,
- char *note)
+struct apoint *apoint_scan(FILE * f, struct tm start, struct tm end,
+ char state, char *note)
{
- char buf[BUFSIZ], *newline;
- time_t tstart, tend;
-
- EXIT_IF(!check_date(start.tm_year, start.tm_mon, start.tm_mday) ||
- !check_date(end.tm_year, end.tm_mon, end.tm_mday) ||
- !check_time(start.tm_hour, start.tm_min) ||
- !check_time(end.tm_hour, end.tm_min),
- _("date error in appointment"));
-
- /* Read the appointment description */
- if (!fgets(buf, sizeof buf, f))
- return NULL;
-
- newline = strchr(buf, '\n');
- if (newline)
- *newline = '\0';
-
- start.tm_sec = end.tm_sec = 0;
- start.tm_isdst = end.tm_isdst = -1;
- start.tm_year -= 1900;
- start.tm_mon--;
- end.tm_year -= 1900;
- end.tm_mon--;
-
- tstart = mktime(&start);
- tend = mktime(&end);
- EXIT_IF(tstart == -1 || tend == -1 || tstart > tend,
- _("date error in appointment"));
- return apoint_new(buf, note, tstart, tend - tstart, state);
+ char buf[BUFSIZ], *newline;
+ time_t tstart, tend;
+
+ EXIT_IF(!check_date(start.tm_year, start.tm_mon, start.tm_mday) ||
+ !check_date(end.tm_year, end.tm_mon, end.tm_mday) ||
+ !check_time(start.tm_hour, start.tm_min) ||
+ !check_time(end.tm_hour, end.tm_min),
+ _("date error in appointment"));
+
+ /* Read the appointment description */
+ if (!fgets(buf, sizeof buf, f))
+ return NULL;
+
+ newline = strchr(buf, '\n');
+ if (newline)
+ *newline = '\0';
+
+ start.tm_sec = end.tm_sec = 0;
+ start.tm_isdst = end.tm_isdst = -1;
+ start.tm_year -= 1900;
+ start.tm_mon--;
+ end.tm_year -= 1900;
+ end.tm_mon--;
+
+ tstart = mktime(&start);
+ tend = mktime(&end);
+ EXIT_IF(tstart == -1 || tend == -1 || tstart > tend,
+ _("date error in appointment"));
+ return apoint_new(buf, note, tstart, tend - tstart, state);
}
void apoint_delete(struct apoint *apt)
{
- LLIST_TS_LOCK(&alist_p);
+ LLIST_TS_LOCK(&alist_p);
- llist_item_t *i = LLIST_TS_FIND_FIRST(&alist_p, apt, NULL);
- int need_check_notify = 0;
+ llist_item_t *i = LLIST_TS_FIND_FIRST(&alist_p, apt, NULL);
+ int need_check_notify = 0;
- if (!i)
- EXIT(_("no such appointment"));
+ if (!i)
+ EXIT(_("no such appointment"));
- if (notify_bar())
- need_check_notify = notify_same_item(apt->start);
- LLIST_TS_REMOVE(&alist_p, i);
- if (need_check_notify)
- notify_check_next_app(0);
+ if (notify_bar())
+ need_check_notify = notify_same_item(apt->start);
+ LLIST_TS_REMOVE(&alist_p, i);
+ if (need_check_notify)
+ notify_check_next_app(0);
- LLIST_TS_UNLOCK(&alist_p);
+ LLIST_TS_UNLOCK(&alist_p);
}
static int apoint_starts_after(struct apoint *apt, long *time)
{
- return apt->start > *time;
+ return apt->start > *time;
}
/*
@@ -223,25 +226,25 @@ static int apoint_starts_after(struct apoint *apt, long *time)
*/
struct notify_app *apoint_check_next(struct notify_app *app, long start)
{
- llist_item_t *i;
+ llist_item_t *i;
- LLIST_TS_LOCK(&alist_p);
- i = LLIST_TS_FIND_FIRST(&alist_p, &start, apoint_starts_after);
+ LLIST_TS_LOCK(&alist_p);
+ i = LLIST_TS_FIND_FIRST(&alist_p, &start, apoint_starts_after);
- if (i) {
- struct apoint *apt = LLIST_TS_GET_DATA(i);
+ if (i) {
+ struct apoint *apt = LLIST_TS_GET_DATA(i);
- if (apt->start <= app->time) {
- app->time = apt->start;
- app->txt = mem_strdup(apt->mesg);
- app->state = apt->state;
- app->got_app = 1;
- }
- }
+ if (apt->start <= app->time) {
+ app->time = apt->start;
+ app->txt = mem_strdup(apt->mesg);
+ app->state = apt->state;
+ app->got_app = 1;
+ }
+ }
- LLIST_TS_UNLOCK(&alist_p);
+ LLIST_TS_UNLOCK(&alist_p);
- return app;
+ return app;
}
/*
@@ -249,23 +252,23 @@ struct notify_app *apoint_check_next(struct notify_app *app, long start)
*/
void apoint_switch_notify(struct apoint *apt)
{
- LLIST_TS_LOCK(&alist_p);
+ LLIST_TS_LOCK(&alist_p);
- apt->state ^= APOINT_NOTIFY;
- if (notify_bar())
- notify_check_added(apt->mesg, apt->start, apt->state);
+ apt->state ^= APOINT_NOTIFY;
+ if (notify_bar())
+ notify_check_added(apt->mesg, apt->start, apt->state);
- LLIST_TS_UNLOCK(&alist_p);
+ LLIST_TS_UNLOCK(&alist_p);
}
void apoint_paste_item(struct apoint *apt, long date)
{
- apt->start = date + get_item_time(apt->start);
+ apt->start = date + get_item_time(apt->start);
- LLIST_TS_LOCK(&alist_p);
- LLIST_TS_ADD_SORTED(&alist_p, apt, apoint_cmp_start);
- LLIST_TS_UNLOCK(&alist_p);
+ LLIST_TS_LOCK(&alist_p);
+ LLIST_TS_ADD_SORTED(&alist_p, apt, apoint_cmp_start);
+ LLIST_TS_UNLOCK(&alist_p);
- if (notify_bar())
- notify_check_added(apt->mesg, apt->start, apt->state);
+ if (notify_bar())
+ notify_check_added(apt->mesg, apt->start, apt->state);
}
diff --git a/src/args.c b/src/args.c
index 8687130..8b1da49 100644
--- a/src/args.c
+++ b/src/args.c
@@ -46,12 +46,12 @@
/* Long options */
enum {
- OPT_FMT_APT = 1000,
- OPT_FMT_RAPT,
- OPT_FMT_EV,
- OPT_FMT_REV,
- OPT_FMT_TODO,
- OPT_READ_ONLY
+ OPT_FMT_APT = 1000,
+ OPT_FMT_RAPT,
+ OPT_FMT_EV,
+ OPT_FMT_REV,
+ OPT_FMT_TODO,
+ OPT_READ_ONLY
};
/*
@@ -59,18 +59,19 @@ enum {
*/
static void usage(void)
{
- const char *arg_usage =
- _("Usage: calcurse [-g|-h|-v] [-an] [-t[num]] [-i<file>] [-x[format]]\n"
- " [-d <date>|<num>] [-s[date]] [-r[range]]\n"
- " [-c<file>] [-D<dir>] [-S<regex>] [--status]\n"
- " [--read-only]\n");
- fputs(arg_usage, stdout);
+ const char *arg_usage =
+ _("Usage: calcurse [-g|-h|-v] [-an] [-t[num]] [-i<file>] [-x[format]]\n"
+ " [-d <date>|<num>] [-s[date]] [-r[range]]\n"
+ " [-c<file>] [-D<dir>] [-S<regex>] [--status]\n"
+ " [--read-only]\n");
+ fputs(arg_usage, stdout);
}
static void usage_try(void)
{
- const char *arg_usage_try = _("Try 'calcurse -h' for more information.\n");
- fputs(arg_usage_try, stdout);
+ const char *arg_usage_try =
+ _("Try 'calcurse -h' for more information.\n");
+ fputs(arg_usage_try, stdout);
}
/*
@@ -78,21 +79,22 @@ static void usage_try(void)
*/
static void version_arg(void)
{
- const char *vtext =
- _("\nCopyright (c) 2004-2013 calcurse Development Team.\n"
- "This is free software; see the source for copying conditions.\n");
+ const char *vtext =
+ _("\nCopyright (c) 2004-2013 calcurse Development Team.\n"
+ "This is free software; see the source for copying conditions.\n");
- fprintf(stdout, _("Calcurse %s - text-based organizer\n"), VERSION);
- fputs(vtext, stdout);
+ fprintf(stdout, _("Calcurse %s - text-based organizer\n"),
+ VERSION);
+ fputs(vtext, stdout);
}
static void more_info(void)
{
- fputs(_("\nFor more information, type '?' from within Calcurse, "
- "or read the manpage.\n"), stdout);
- fputs(_("Mail feature requests and suggestions to <misc@calcurse.org>.\n"),
- stdout);
- fputs(_("Mail bug reports to <bugs@calcurse.org>.\n"), stdout);
+ fputs(_("\nFor more information, type '?' from within Calcurse, "
+ "or read the manpage.\n"), stdout);
+ fputs(_("Mail feature requests and suggestions to <misc@calcurse.org>.\n"),
+ stdout);
+ fputs(_("Mail bug reports to <bugs@calcurse.org>.\n"), stdout);
}
/*
@@ -100,65 +102,66 @@ static void more_info(void)
*/
static void help_arg(void)
{
- const char *htext =
- _("\nMiscellaneous:\n"
- " -h, --help\n"
- " print this help and exit.\n"
- "\n -v, --version\n"
- " print calcurse version and exit.\n"
- "\n --status\n"
- " display the status of running instances of calcurse.\n"
- "\n --read-only\n"
- " Don't save configuration nor appointments/todos. Use with care.\n"
- "\nFiles:\n"
- " -c <file>, --calendar <file>\n"
- " specify the calendar <file> to use (has precedence over '-D').\n"
- "\n -D <dir>, --directory <dir>\n"
- " specify the data directory to use.\n"
- "\tIf not specified, the default directory is ~/.calcurse\n"
- "\nNon-interactive:\n"
- " -a, --appointment\n"
- " print events and appointments for current day and exit.\n"
- "\n -d <date|num>, --day <date|num>\n"
- " print events and appointments for <date> or <num> upcoming days and"
- "\n\texit. To specify both a starting date and a range, use the\n"
- "\t'--startday' and the '--range' option.\n"
- "\n -g, --gc\n"
- " run the garbage collector for note files and exit. \n"
- "\n -i <file>, --import <file>\n"
- " import the icalendar data contained in <file>. \n"
- "\n -n, --next\n"
- " print next appointment within upcoming 24 hours "
- "and exit. Also given\n\tis the remaining time before this "
- "next appointment.\n"
- "\n -r[num], --range[=num]\n"
- " print events and appointments for the [num] number of days"
- "\n\tand exit. If no [num] is given, a range of 1 day is considered.\n"
- "\n -s[date], --startday[=date]\n"
- " print events and appointments from [date] and exit.\n"
- "\tIf no [date] is given, the current day is considered.\n"
- "\n -S<regex>, --search=<regex>\n"
- " search for the given regular expression within events, appointments,\n"
- "\tand todos description.\n"
- "\n -t[num], --todo[=num]\n"
- " print todo list and exit. If the optional number [num] is given,\n"
- "\tthen only todos having a priority equal to [num] will be returned.\n"
- "\tThe priority number must be between 1 (highest) and 9 (lowest).\n"
- "\tIt is also possible to specify '0' for the priority, in which case\n"
- "\tonly completed tasks will be shown.\n"
- "\n -x[format], --export[=format]\n"
- " export user data to the specified format. Events, appointments and\n"
- "\ttodos are converted and echoed to stdout.\n"
- "\tTwo possible formats are available: 'ical' and 'pcal'.\n"
- "\tIf the optional argument format is not given, ical format is\n"
- "\tselected by default.\n"
- "\tnote: redirect standard output to export data to a file,\n"
- "\tby issuing a command such as: calcurse --export > calcurse.dat\n");
-
- fprintf(stdout, _("Calcurse %s - text-based organizer\n"), VERSION);
- usage();
- fputs(htext, stdout);
- more_info();
+ const char *htext =
+ _("\nMiscellaneous:\n"
+ " -h, --help\n"
+ " print this help and exit.\n"
+ "\n -v, --version\n"
+ " print calcurse version and exit.\n"
+ "\n --status\n"
+ " display the status of running instances of calcurse.\n"
+ "\n --read-only\n"
+ " Don't save configuration nor appointments/todos. Use with care.\n"
+ "\nFiles:\n"
+ " -c <file>, --calendar <file>\n"
+ " specify the calendar <file> to use (has precedence over '-D').\n"
+ "\n -D <dir>, --directory <dir>\n"
+ " specify the data directory to use.\n"
+ "\tIf not specified, the default directory is ~/.calcurse\n"
+ "\nNon-interactive:\n"
+ " -a, --appointment\n"
+ " print events and appointments for current day and exit.\n"
+ "\n -d <date|num>, --day <date|num>\n"
+ " print events and appointments for <date> or <num> upcoming days and"
+ "\n\texit. To specify both a starting date and a range, use the\n"
+ "\t'--startday' and the '--range' option.\n"
+ "\n -g, --gc\n"
+ " run the garbage collector for note files and exit. \n"
+ "\n -i <file>, --import <file>\n"
+ " import the icalendar data contained in <file>. \n"
+ "\n -n, --next\n"
+ " print next appointment within upcoming 24 hours "
+ "and exit. Also given\n\tis the remaining time before this "
+ "next appointment.\n"
+ "\n -r[num], --range[=num]\n"
+ " print events and appointments for the [num] number of days"
+ "\n\tand exit. If no [num] is given, a range of 1 day is considered.\n"
+ "\n -s[date], --startday[=date]\n"
+ " print events and appointments from [date] and exit.\n"
+ "\tIf no [date] is given, the current day is considered.\n"
+ "\n -S<regex>, --search=<regex>\n"
+ " search for the given regular expression within events, appointments,\n"
+ "\tand todos description.\n"
+ "\n -t[num], --todo[=num]\n"
+ " print todo list and exit. If the optional number [num] is given,\n"
+ "\tthen only todos having a priority equal to [num] will be returned.\n"
+ "\tThe priority number must be between 1 (highest) and 9 (lowest).\n"
+ "\tIt is also possible to specify '0' for the priority, in which case\n"
+ "\tonly completed tasks will be shown.\n"
+ "\n -x[format], --export[=format]\n"
+ " export user data to the specified format. Events, appointments and\n"
+ "\ttodos are converted and echoed to stdout.\n"
+ "\tTwo possible formats are available: 'ical' and 'pcal'.\n"
+ "\tIf the optional argument format is not given, ical format is\n"
+ "\tselected by default.\n"
+ "\tnote: redirect standard output to export data to a file,\n"
+ "\tby issuing a command such as: calcurse --export > calcurse.dat\n");
+
+ fprintf(stdout, _("Calcurse %s - text-based organizer\n"),
+ VERSION);
+ usage();
+ fputs(htext, stdout);
+ more_info();
}
/*
@@ -174,22 +177,25 @@ static void help_arg(void)
*/
static void status_arg(void)
{
- int cpid, dpid;
-
- cpid = io_get_pid(path_cpid);
- dpid = io_get_pid(path_dpid);
-
- EXIT_IF(cpid && dpid,
- _("Error: both calcurse (pid: %d) and its daemon (pid: %d)\n"
- "seem to be running at the same time!\n"
- "Please check manually and restart calcurse.\n"), cpid, dpid);
-
- if (cpid)
- fprintf(stdout, _("calcurse is running (pid %d)\n"), cpid);
- else if (dpid)
- fprintf(stdout, _("calcurse is running in background (pid %d)\n"), dpid);
- else
- puts(_("calcurse is not running\n"));
+ int cpid, dpid;
+
+ cpid = io_get_pid(path_cpid);
+ dpid = io_get_pid(path_dpid);
+
+ EXIT_IF(cpid && dpid,
+ _("Error: both calcurse (pid: %d) and its daemon (pid: %d)\n"
+ "seem to be running at the same time!\n"
+ "Please check manually and restart calcurse.\n"), cpid,
+ dpid);
+
+ if (cpid)
+ fprintf(stdout, _("calcurse is running (pid %d)\n"), cpid);
+ else if (dpid)
+ fprintf(stdout,
+ _("calcurse is running in background (pid %d)\n"),
+ dpid);
+ else
+ puts(_("calcurse is not running\n"));
}
/*
@@ -201,13 +207,13 @@ static void status_arg(void)
*/
static void todo_arg(int priority, const char *format, regex_t * regex)
{
- llist_item_t *i;
- int title = 1;
- const char *titlestr;
- const char *all_todos_title = _("to do:\n");
- const char *completed_title = _("completed tasks:\n");
+ llist_item_t *i;
+ int title = 1;
+ const char *titlestr;
+ const char *all_todos_title = _("to do:\n");
+ const char *completed_title = _("completed tasks:\n");
- titlestr = priority == 0 ? completed_title : all_todos_title;
+ titlestr = priority == 0 ? completed_title : all_todos_title;
#define DISPLAY_TITLE do { \
if (title) \
@@ -217,23 +223,23 @@ static void todo_arg(int priority, const char *format, regex_t * regex)
} \
} while (0)
- LLIST_FOREACH(&todolist, i) {
- struct todo *todo = LLIST_TS_GET_DATA(i);
- if (regex && regexec(regex, todo->mesg, 0, 0, 0) != 0)
- continue;
-
- if (todo->id < 0) { /* completed task */
- if (priority == 0) {
- DISPLAY_TITLE;
- print_todo(format, todo);
- }
- } else {
- if (priority < 0 || todo->id == priority) {
- DISPLAY_TITLE;
- print_todo(format, todo);
- }
- }
- }
+ LLIST_FOREACH(&todolist, i) {
+ struct todo *todo = LLIST_TS_GET_DATA(i);
+ if (regex && regexec(regex, todo->mesg, 0, 0, 0) != 0)
+ continue;
+
+ if (todo->id < 0) { /* completed task */
+ if (priority == 0) {
+ DISPLAY_TITLE;
+ print_todo(format, todo);
+ }
+ } else {
+ if (priority < 0 || todo->id == priority) {
+ DISPLAY_TITLE;
+ print_todo(format, todo);
+ }
+ }
+ }
#undef DISPLAY_TITLE
}
@@ -241,26 +247,27 @@ static void todo_arg(int priority, const char *format, regex_t * regex)
/* Print the next appointment within the upcoming 24 hours. */
static void next_arg(void)
{
- struct notify_app next_app;
- const long current_time = now();
- int time_left, hours_left, min_left;
-
- next_app.time = current_time + DAYINSEC;
- next_app.got_app = 0;
- next_app.txt = NULL;
-
- next_app = *recur_apoint_check_next(&next_app, current_time, get_today());
- next_app = *apoint_check_next(&next_app, current_time);
-
- if (next_app.got_app) {
- time_left = next_app.time - current_time;
- hours_left = (time_left / HOURINSEC);
- min_left = (time_left - hours_left * HOURINSEC) / MININSEC;
- fputs(_("next appointment:\n"), stdout);
- fprintf(stdout, " [%02d:%02d] %s\n", hours_left, min_left,
- next_app.txt);
- mem_free(next_app.txt);
- }
+ struct notify_app next_app;
+ const long current_time = now();
+ int time_left, hours_left, min_left;
+
+ next_app.time = current_time + DAYINSEC;
+ next_app.got_app = 0;
+ next_app.txt = NULL;
+
+ next_app =
+ *recur_apoint_check_next(&next_app, current_time, get_today());
+ next_app = *apoint_check_next(&next_app, current_time);
+
+ if (next_app.got_app) {
+ time_left = next_app.time - current_time;
+ hours_left = (time_left / HOURINSEC);
+ min_left = (time_left - hours_left * HOURINSEC) / MININSEC;
+ fputs(_("next appointment:\n"), stdout);
+ fprintf(stdout, " [%02d:%02d] %s\n", hours_left,
+ min_left, next_app.txt);
+ mem_free(next_app.txt);
+ }
}
/*
@@ -268,13 +275,13 @@ static void next_arg(void)
*/
static void arg_print_date(long date)
{
- char date_str[BUFSIZ];
- struct tm lt;
+ char date_str[BUFSIZ];
+ struct tm lt;
- localtime_r((time_t *)&date, &lt);
- strftime(date_str, BUFSIZ, conf.output_datefmt, &lt);
- fputs(date_str, stdout);
- fputs(":\n", stdout);
+ localtime_r((time_t *) & date, &lt);
+ strftime(date_str, BUFSIZ, conf.output_datefmt, &lt);
+ fputs(date_str, stdout);
+ fputs(":\n", stdout);
}
/*
@@ -285,22 +292,22 @@ static void arg_print_date(long date)
*/
static int
app_arg(int add_line, struct date *day, long date, const char *fmt_apt,
- const char *fmt_rapt, const char *fmt_ev, const char *fmt_rev,
- regex_t *regex)
+ const char *fmt_rapt, const char *fmt_ev, const char *fmt_rev,
+ regex_t * regex)
{
- if (date == 0)
- date = get_sec_date(*day);
+ if (date == 0)
+ date = get_sec_date(*day);
- int n = day_store_items(date, NULL, NULL, regex);
+ int n = day_store_items(date, NULL, NULL, regex);
- if (n > 0) {
- if (add_line)
- fputs("\n", stdout);
- arg_print_date(date);
- day_write_stdout(date, fmt_apt, fmt_rapt, fmt_ev, fmt_rev);
- }
+ if (n > 0) {
+ if (add_line)
+ fputs("\n", stdout);
+ arg_print_date(date);
+ day_write_stdout(date, fmt_apt, fmt_rapt, fmt_ev, fmt_rev);
+ }
- return n;
+ return n;
}
/*
@@ -310,23 +317,24 @@ app_arg(int add_line, struct date *day, long date, const char *fmt_apt,
*/
static void
display_app(struct tm *t, int numdays, int add_line, const char *fmt_apt,
- const char *fmt_rapt, const char *fmt_ev, const char *fmt_rev,
- regex_t * regex)
+ const char *fmt_rapt, const char *fmt_ev, const char *fmt_rev,
+ regex_t * regex)
{
- int i, app_found;
- struct date day;
-
- for (i = 0; i < numdays; i++) {
- day.dd = t->tm_mday;
- day.mm = t->tm_mon + 1;
- day.yyyy = t->tm_year + 1900;
- app_found = app_arg(add_line, &day, 0, fmt_apt, fmt_rapt, fmt_ev,
- fmt_rev, regex);
- if (app_found)
- add_line = 1;
- t->tm_mday++;
- mktime(t);
- }
+ int i, app_found;
+ struct date day;
+
+ for (i = 0; i < numdays; i++) {
+ day.dd = t->tm_mday;
+ day.mm = t->tm_mon + 1;
+ day.yyyy = t->tm_year + 1900;
+ app_found =
+ app_arg(add_line, &day, 0, fmt_apt, fmt_rapt, fmt_ev,
+ fmt_rev, regex);
+ if (app_found)
+ add_line = 1;
+ t->tm_mday++;
+ mktime(t);
+ }
}
/*
@@ -335,39 +343,42 @@ display_app(struct tm *t, int numdays, int add_line, const char *fmt_apt,
*/
static void
date_arg(const char *ddate, int add_line, const char *fmt_apt,
- const char *fmt_rapt, const char *fmt_ev, const char *fmt_rev,
- regex_t * regex)
+ const char *fmt_rapt, const char *fmt_ev, const char *fmt_rev,
+ regex_t * regex)
{
- struct date day;
- static struct tm t;
- time_t timer;
-
- /*
- * Check (with the argument length) if a date or a number of days
- * was entered, and then call app_arg() to print appointments
- */
- if (strlen(ddate) <= 4 && is_all_digit(ddate)) {
- /*
- * A number of days was entered. Get current date and print appointments
- * for each day in the chosen interval. app_found and add_line are used to
- * format the output correctly.
- */
- timer = time(NULL);
- localtime_r(&timer, &t);
- display_app(&t, atoi(ddate), add_line, fmt_apt, fmt_rapt, fmt_ev, fmt_rev,
- regex);
- } else {
- /* A date was entered. */
- if (parse_date(ddate, conf.input_datefmt, (int *)&day.yyyy,
- (int *)&day.mm, (int *)&day.dd, NULL)) {
- app_arg(add_line, &day, 0, fmt_apt, fmt_rapt, fmt_ev, fmt_rev, regex);
- } else {
- fputs(_("Argument to the '-d' flag is not valid\n"), stderr);
- fprintf(stdout, _("Possible argument format are: '%s' or 'n'\n"),
- DATEFMT_DESC(conf.input_datefmt));
- more_info();
- }
- }
+ struct date day;
+ static struct tm t;
+ time_t timer;
+
+ /*
+ * Check (with the argument length) if a date or a number of days
+ * was entered, and then call app_arg() to print appointments
+ */
+ if (strlen(ddate) <= 4 && is_all_digit(ddate)) {
+ /*
+ * A number of days was entered. Get current date and print appointments
+ * for each day in the chosen interval. app_found and add_line are used to
+ * format the output correctly.
+ */
+ timer = time(NULL);
+ localtime_r(&timer, &t);
+ display_app(&t, atoi(ddate), add_line, fmt_apt, fmt_rapt,
+ fmt_ev, fmt_rev, regex);
+ } else {
+ /* A date was entered. */
+ if (parse_date(ddate, conf.input_datefmt, (int *)&day.yyyy,
+ (int *)&day.mm, (int *)&day.dd, NULL)) {
+ app_arg(add_line, &day, 0, fmt_apt, fmt_rapt,
+ fmt_ev, fmt_rev, regex);
+ } else {
+ fputs(_("Argument to the '-d' flag is not valid\n"),
+ stderr);
+ fprintf(stdout,
+ _("Possible argument format are: '%s' or 'n'\n"),
+ DATEFMT_DESC(conf.input_datefmt));
+ more_info();
+ }
+ }
}
/*
@@ -380,45 +391,48 @@ date_arg(const char *ddate, int add_line, const char *fmt_apt,
*/
static void
date_arg_extended(const char *startday, const char *range, int add_line,
- const char *fmt_apt, const char *fmt_rapt,
- const char *fmt_ev, const char *fmt_rev, regex_t * regex)
+ const char *fmt_apt, const char *fmt_rapt,
+ const char *fmt_ev, const char *fmt_rev, regex_t * regex)
{
- int numdays = 1, error = 0;
- static struct tm t;
- time_t timer;
-
- /*
- * Check arguments and extract information
- */
- if (range != NULL) {
- if (is_all_digit(range)) {
- numdays = atoi(range);
- } else {
- error = 1;
- }
- }
- timer = time(NULL);
- localtime_r(&timer, &t);
- if (startday != NULL) {
- if (parse_date(startday, conf.input_datefmt, (int *)&t.tm_year,
- (int *)&t.tm_mon, (int *)&t.tm_mday, NULL)) {
- t.tm_year -= 1900;
- t.tm_mon--;
- mktime(&t);
- } else {
- error = 1;
- }
- }
- if (!error) {
- display_app(&t, numdays, add_line, fmt_apt, fmt_rapt, fmt_ev, fmt_rev,
- regex);
- } else {
- fputs(_("Argument is not valid\n"), stderr);
- fprintf(stdout, _("Argument format for -s and --startday is: '%s'\n"),
- DATEFMT_DESC(conf.input_datefmt));
- fputs(_("Argument format for -r and --range is: 'n'\n"), stdout);
- more_info();
- }
+ int numdays = 1, error = 0;
+ static struct tm t;
+ time_t timer;
+
+ /*
+ * Check arguments and extract information
+ */
+ if (range != NULL) {
+ if (is_all_digit(range)) {
+ numdays = atoi(range);
+ } else {
+ error = 1;
+ }
+ }
+ timer = time(NULL);
+ localtime_r(&timer, &t);
+ if (startday != NULL) {
+ if (parse_date
+ (startday, conf.input_datefmt, (int *)&t.tm_year,
+ (int *)&t.tm_mon, (int *)&t.tm_mday, NULL)) {
+ t.tm_year -= 1900;
+ t.tm_mon--;
+ mktime(&t);
+ } else {
+ error = 1;
+ }
+ }
+ if (!error) {
+ display_app(&t, numdays, add_line, fmt_apt, fmt_rapt,
+ fmt_ev, fmt_rev, regex);
+ } else {
+ fputs(_("Argument is not valid\n"), stderr);
+ fprintf(stdout,
+ _("Argument format for -s and --startday is: '%s'\n"),
+ DATEFMT_DESC(conf.input_datefmt));
+ fputs(_("Argument format for -r and --range is: 'n'\n"),
+ stdout);
+ more_info();
+ }
}
/*
@@ -427,299 +441,310 @@ date_arg_extended(const char *startday, const char *range, int add_line,
*/
int parse_args(int argc, char **argv)
{
- int ch, add_line = 0;
- int unknown_flag = 0;
- /* Command-line flags */
- int aflag = 0; /* -a: print appointments for current day */
- int dflag = 0; /* -d: print appointments for a specified days */
- int hflag = 0; /* -h: print help text */
- int gflag = 0; /* -g: run garbage collector */
- int iflag = 0; /* -i: import data */
- int nflag = 0; /* -n: print next appointment */
- int rflag = 0; /* -r: specify the range of days to consider */
- int sflag = 0; /* -s: specify the first day to consider */
- int Sflag = 0; /* -S: specify a regex to search for */
- int tflag = 0; /* -t: print todo list */
- int vflag = 0; /* -v: print version number */
- int xflag = 0; /* -x: export data */
- /* Format strings */
- const char *fmt_apt = " - %S -> %E\n\t%m\n";
- const char *fmt_rapt = " - %S -> %E\n\t%m\n";
- const char *fmt_ev = " * %m\n";
- const char *fmt_rev = " * %m\n";
- const char *fmt_todo = "%p. %m\n";
-
- int tnum = 0, xfmt = 0, non_interactive = 0, multiple_flag = 0, load_data = 0;
- const char *ddate = "", *cfile = NULL, *range = NULL, *startday = NULL;
- const char *datadir = NULL, *ifile = NULL;
- regex_t reg, *preg = NULL;
-
- /* Long options only */
- int statusflag = 0; /* --status: get the status of running instances */
- enum {
- STATUS_OPT = CHAR_MAX + 1
- };
-
- static const char *optstr = "ghvnNax::t::d:c:r::s::S:D:i:";
-
- struct option longopts[] = {
- {"appointment", no_argument, NULL, 'a'},
- {"calendar", required_argument, NULL, 'c'},
- {"day", required_argument, NULL, 'd'},
- {"directory", required_argument, NULL, 'D'},
- {"gc", no_argument, NULL, 'g'},
- {"help", no_argument, NULL, 'h'},
- {"import", required_argument, NULL, 'i'},
- {"next", no_argument, NULL, 'n'},
- {"note", no_argument, NULL, 'N'},
- {"range", optional_argument, NULL, 'r'},
- {"startday", optional_argument, NULL, 's'},
- {"search", required_argument, NULL, 'S'},
- {"status", no_argument, NULL, STATUS_OPT},
- {"todo", optional_argument, NULL, 't'},
- {"version", no_argument, NULL, 'v'},
- {"export", optional_argument, NULL, 'x'},
-
- {"format-apt", required_argument, NULL, OPT_FMT_APT},
- {"format-recur-apt", required_argument, NULL, OPT_FMT_RAPT},
- {"format-event", required_argument, NULL, OPT_FMT_EV},
- {"format-recur-event", required_argument, NULL, OPT_FMT_REV},
- {"format-todo", required_argument, NULL, OPT_FMT_TODO},
- {"read-only", no_argument, NULL, OPT_READ_ONLY},
- {NULL, no_argument, NULL, 0}
- };
-
- while ((ch = getopt_long(argc, argv, optstr, longopts, NULL)) != -1) {
- switch (ch) {
- case STATUS_OPT:
- statusflag = 1;
- break;
- case 'a':
- aflag = 1;
- multiple_flag++;
- load_data++;
- break;
- case 'c':
- multiple_flag++;
- cfile = optarg;
- load_data++;
- break;
- case 'd':
- dflag = 1;
- multiple_flag++;
- load_data++;
- ddate = optarg;
- break;
- case 'D':
- datadir = optarg;
- break;
- case 'h':
- hflag = 1;
- break;
- case 'g':
- gflag = 1;
- break;
- case 'i':
- iflag = 1;
- multiple_flag++;
- load_data++;
- ifile = optarg;
- break;
- case 'n':
- nflag = 1;
- multiple_flag++;
- load_data++;
- break;
- case 'r':
- rflag = 1;
- multiple_flag++;
- load_data++;
- range = optarg;
- break;
- case 's':
- sflag = 1;
- multiple_flag++;
- load_data++;
- startday = optarg;
- break;
- case 'S':
- EXIT_IF(Sflag > 0, _("Can not handle more than one regular expression."));
- Sflag = 1;
- if (regcomp(&reg, optarg, REG_EXTENDED))
- EXIT(_("Could not compile regular expression."));
- preg = &reg;
- break;
- case 't':
- tflag = 1;
- multiple_flag++;
- load_data++;
- add_line = 1;
- if (optarg != NULL) {
- tnum = atoi(optarg);
- if (tnum < 0 || tnum > 9) {
- usage();
- usage_try();
- return EXIT_FAILURE;
- }
- } else {
- tnum = -1;
- }
- break;
- case 'v':
- vflag = 1;
- break;
- case 'x':
- xflag = 1;
- multiple_flag++;
- load_data++;
- if (optarg != NULL) {
- if (strcmp(optarg, "ical") == 0) {
- xfmt = IO_EXPORT_ICAL;
- } else if (strcmp(optarg, "pcal") == 0) {
- xfmt = IO_EXPORT_PCAL;
- } else {
- fputs(_("Argument for '-x' should be either "
- "'ical' or 'pcal'\n"), stderr);
- usage();
- usage_try();
- return EXIT_FAILURE;
- }
- } else {
- xfmt = IO_EXPORT_ICAL;
- }
- break;
- case OPT_FMT_APT:
- fmt_apt = optarg;
- break;
- case OPT_FMT_RAPT:
- fmt_rapt = optarg;
- break;
- case OPT_FMT_EV:
- fmt_ev = optarg;
- break;
- case OPT_FMT_REV:
- fmt_rev = optarg;
- break;
- case OPT_FMT_TODO:
- fmt_todo = optarg;
- break;
- case OPT_READ_ONLY:
- read_only = 1;
- break;
- default:
- usage();
- usage_try();
- unknown_flag = 1;
- non_interactive = 1;
- /* NOTREACHED */
- }
- }
- argc -= optind;
-
- if (argc >= 1) {
- usage();
- usage_try();
- return EXIT_FAILURE;
- /* Incorrect arguments */
- } else if (Sflag && !(aflag || dflag || rflag || sflag || tflag)) {
- fputs(_("Option '-S' must be used with either '-d', '-r', '-s', "
- "'-a' or '-t'\n"), stderr);
- usage();
- usage_try();
- return EXIT_FAILURE;
- } else {
- if (unknown_flag) {
- non_interactive = 1;
- } else if (hflag) {
- help_arg();
- non_interactive = 1;
- } else if (vflag) {
- version_arg();
- non_interactive = 1;
- } else if (statusflag) {
- io_init(cfile, datadir);
- status_arg();
- non_interactive = 1;
- } else if (gflag) {
- io_init(cfile, datadir);
- io_check_dir(path_dir);
- io_check_dir(path_notes);
- io_check_file(path_apts);
- io_check_file(path_todo);
- io_load_app();
- io_load_todo();
- note_gc();
- non_interactive = 1;
- } else if (multiple_flag) {
- if (load_data) {
- io_init(cfile, datadir);
- io_check_dir(path_dir);
- io_check_dir(path_notes);
- }
- if (iflag) {
- io_check_file(path_apts);
- io_check_file(path_todo);
- /* Get default pager in case we need to show a log file. */
- vars_init();
- io_load_app();
- io_load_todo();
- io_import_data(IO_IMPORT_ICAL, ifile);
- io_save_apts();
- io_save_todo();
- non_interactive = 1;
- }
- if (xflag) {
- io_check_file(path_apts);
- io_check_file(path_todo);
- io_load_app();
- io_load_todo();
- io_export_data(xfmt);
- non_interactive = 1;
- return non_interactive;
- }
- if (tflag) {
- io_check_file(path_todo);
- io_load_todo();
- todo_arg(tnum, fmt_todo, preg);
- non_interactive = 1;
- }
- if (nflag) {
- io_check_file(path_apts);
- io_load_app();
- next_arg();
- non_interactive = 1;
- }
- if (dflag || rflag || sflag) {
- io_check_file(path_apts);
- io_check_file(path_conf);
- io_load_app();
- config_load(); /* To get output date format. */
- if (dflag)
- date_arg(ddate, add_line, fmt_apt, fmt_rapt, fmt_ev, fmt_rev, preg);
- if (rflag || sflag)
- date_arg_extended(startday, range, add_line, fmt_apt,
- fmt_rapt, fmt_ev, fmt_rev, preg);
- non_interactive = 1;
- } else if (aflag) {
- struct date day;
-
- io_check_file(path_apts);
- io_check_file(path_conf);
- vars_init();
- config_load(); /* To get output date format. */
- io_load_app();
- day.dd = day.mm = day.yyyy = 0;
- app_arg(add_line, &day, 0, fmt_apt, fmt_rapt, fmt_ev, fmt_rev, preg);
- non_interactive = 1;
- }
- } else {
- non_interactive = 0;
- io_init(cfile, datadir);
- }
- }
-
- if (preg)
- regfree(preg);
-
- return non_interactive;
+ int ch, add_line = 0;
+ int unknown_flag = 0;
+ /* Command-line flags */
+ int aflag = 0; /* -a: print appointments for current day */
+ int dflag = 0; /* -d: print appointments for a specified days */
+ int hflag = 0; /* -h: print help text */
+ int gflag = 0; /* -g: run garbage collector */
+ int iflag = 0; /* -i: import data */
+ int nflag = 0; /* -n: print next appointment */
+ int rflag = 0; /* -r: specify the range of days to consider */
+ int sflag = 0; /* -s: specify the first day to consider */
+ int Sflag = 0; /* -S: specify a regex to search for */
+ int tflag = 0; /* -t: print todo list */
+ int vflag = 0; /* -v: print version number */
+ int xflag = 0; /* -x: export data */
+ /* Format strings */
+ const char *fmt_apt = " - %S -> %E\n\t%m\n";
+ const char *fmt_rapt = " - %S -> %E\n\t%m\n";
+ const char *fmt_ev = " * %m\n";
+ const char *fmt_rev = " * %m\n";
+ const char *fmt_todo = "%p. %m\n";
+
+ int tnum = 0, xfmt = 0, non_interactive = 0, multiple_flag =
+ 0, load_data = 0;
+ const char *ddate = "", *cfile = NULL, *range = NULL, *startday =
+ NULL;
+ const char *datadir = NULL, *ifile = NULL;
+ regex_t reg, *preg = NULL;
+
+ /* Long options only */
+ int statusflag = 0; /* --status: get the status of running instances */
+ enum {
+ STATUS_OPT = CHAR_MAX + 1
+ };
+
+ static const char *optstr = "ghvnNax::t::d:c:r::s::S:D:i:";
+
+ struct option longopts[] = {
+ {"appointment", no_argument, NULL, 'a'},
+ {"calendar", required_argument, NULL, 'c'},
+ {"day", required_argument, NULL, 'd'},
+ {"directory", required_argument, NULL, 'D'},
+ {"gc", no_argument, NULL, 'g'},
+ {"help", no_argument, NULL, 'h'},
+ {"import", required_argument, NULL, 'i'},
+ {"next", no_argument, NULL, 'n'},
+ {"note", no_argument, NULL, 'N'},
+ {"range", optional_argument, NULL, 'r'},
+ {"startday", optional_argument, NULL, 's'},
+ {"search", required_argument, NULL, 'S'},
+ {"status", no_argument, NULL, STATUS_OPT},
+ {"todo", optional_argument, NULL, 't'},
+ {"version", no_argument, NULL, 'v'},
+ {"export", optional_argument, NULL, 'x'},
+
+ {"format-apt", required_argument, NULL, OPT_FMT_APT},
+ {"format-recur-apt", required_argument, NULL, OPT_FMT_RAPT},
+ {"format-event", required_argument, NULL, OPT_FMT_EV},
+ {"format-recur-event", required_argument, NULL, OPT_FMT_REV},
+ {"format-todo", required_argument, NULL, OPT_FMT_TODO},
+ {"read-only", no_argument, NULL, OPT_READ_ONLY},
+ {NULL, no_argument, NULL, 0}
+ };
+
+ while ((ch =
+ getopt_long(argc, argv, optstr, longopts, NULL)) != -1) {
+ switch (ch) {
+ case STATUS_OPT:
+ statusflag = 1;
+ break;
+ case 'a':
+ aflag = 1;
+ multiple_flag++;
+ load_data++;
+ break;
+ case 'c':
+ multiple_flag++;
+ cfile = optarg;
+ load_data++;
+ break;
+ case 'd':
+ dflag = 1;
+ multiple_flag++;
+ load_data++;
+ ddate = optarg;
+ break;
+ case 'D':
+ datadir = optarg;
+ break;
+ case 'h':
+ hflag = 1;
+ break;
+ case 'g':
+ gflag = 1;
+ break;
+ case 'i':
+ iflag = 1;
+ multiple_flag++;
+ load_data++;
+ ifile = optarg;
+ break;
+ case 'n':
+ nflag = 1;
+ multiple_flag++;
+ load_data++;
+ break;
+ case 'r':
+ rflag = 1;
+ multiple_flag++;
+ load_data++;
+ range = optarg;
+ break;
+ case 's':
+ sflag = 1;
+ multiple_flag++;
+ load_data++;
+ startday = optarg;
+ break;
+ case 'S':
+ EXIT_IF(Sflag > 0,
+ _("Can not handle more than one regular expression."));
+ Sflag = 1;
+ if (regcomp(&reg, optarg, REG_EXTENDED))
+ EXIT(_("Could not compile regular expression."));
+ preg = &reg;
+ break;
+ case 't':
+ tflag = 1;
+ multiple_flag++;
+ load_data++;
+ add_line = 1;
+ if (optarg != NULL) {
+ tnum = atoi(optarg);
+ if (tnum < 0 || tnum > 9) {
+ usage();
+ usage_try();
+ return EXIT_FAILURE;
+ }
+ } else {
+ tnum = -1;
+ }
+ break;
+ case 'v':
+ vflag = 1;
+ break;
+ case 'x':
+ xflag = 1;
+ multiple_flag++;
+ load_data++;
+ if (optarg != NULL) {
+ if (strcmp(optarg, "ical") == 0) {
+ xfmt = IO_EXPORT_ICAL;
+ } else if (strcmp(optarg, "pcal") == 0) {
+ xfmt = IO_EXPORT_PCAL;
+ } else {
+ fputs(_("Argument for '-x' should be either "
+ "'ical' or 'pcal'\n"),
+ stderr);
+ usage();
+ usage_try();
+ return EXIT_FAILURE;
+ }
+ } else {
+ xfmt = IO_EXPORT_ICAL;
+ }
+ break;
+ case OPT_FMT_APT:
+ fmt_apt = optarg;
+ break;
+ case OPT_FMT_RAPT:
+ fmt_rapt = optarg;
+ break;
+ case OPT_FMT_EV:
+ fmt_ev = optarg;
+ break;
+ case OPT_FMT_REV:
+ fmt_rev = optarg;
+ break;
+ case OPT_FMT_TODO:
+ fmt_todo = optarg;
+ break;
+ case OPT_READ_ONLY:
+ read_only = 1;
+ break;
+ default:
+ usage();
+ usage_try();
+ unknown_flag = 1;
+ non_interactive = 1;
+ /* NOTREACHED */
+ }
+ }
+ argc -= optind;
+
+ if (argc >= 1) {
+ usage();
+ usage_try();
+ return EXIT_FAILURE;
+ /* Incorrect arguments */
+ } else if (Sflag && !(aflag || dflag || rflag || sflag || tflag)) {
+ fputs(_("Option '-S' must be used with either '-d', '-r', '-s', "
+ "'-a' or '-t'\n"), stderr);
+ usage();
+ usage_try();
+ return EXIT_FAILURE;
+ } else {
+ if (unknown_flag) {
+ non_interactive = 1;
+ } else if (hflag) {
+ help_arg();
+ non_interactive = 1;
+ } else if (vflag) {
+ version_arg();
+ non_interactive = 1;
+ } else if (statusflag) {
+ io_init(cfile, datadir);
+ status_arg();
+ non_interactive = 1;
+ } else if (gflag) {
+ io_init(cfile, datadir);
+ io_check_dir(path_dir);
+ io_check_dir(path_notes);
+ io_check_file(path_apts);
+ io_check_file(path_todo);
+ io_load_app();
+ io_load_todo();
+ note_gc();
+ non_interactive = 1;
+ } else if (multiple_flag) {
+ if (load_data) {
+ io_init(cfile, datadir);
+ io_check_dir(path_dir);
+ io_check_dir(path_notes);
+ }
+ if (iflag) {
+ io_check_file(path_apts);
+ io_check_file(path_todo);
+ /* Get default pager in case we need to show a log file. */
+ vars_init();
+ io_load_app();
+ io_load_todo();
+ io_import_data(IO_IMPORT_ICAL, ifile);
+ io_save_apts();
+ io_save_todo();
+ non_interactive = 1;
+ }
+ if (xflag) {
+ io_check_file(path_apts);
+ io_check_file(path_todo);
+ io_load_app();
+ io_load_todo();
+ io_export_data(xfmt);
+ non_interactive = 1;
+ return non_interactive;
+ }
+ if (tflag) {
+ io_check_file(path_todo);
+ io_load_todo();
+ todo_arg(tnum, fmt_todo, preg);
+ non_interactive = 1;
+ }
+ if (nflag) {
+ io_check_file(path_apts);
+ io_load_app();
+ next_arg();
+ non_interactive = 1;
+ }
+ if (dflag || rflag || sflag) {
+ io_check_file(path_apts);
+ io_check_file(path_conf);
+ io_load_app();
+ config_load(); /* To get output date format. */
+ if (dflag)
+ date_arg(ddate, add_line, fmt_apt,
+ fmt_rapt, fmt_ev, fmt_rev,
+ preg);
+ if (rflag || sflag)
+ date_arg_extended(startday, range,
+ add_line,
+ fmt_apt,
+ fmt_rapt, fmt_ev,
+ fmt_rev, preg);
+ non_interactive = 1;
+ } else if (aflag) {
+ struct date day;
+
+ io_check_file(path_apts);
+ io_check_file(path_conf);
+ vars_init();
+ config_load(); /* To get output date format. */
+ io_load_app();
+ day.dd = day.mm = day.yyyy = 0;
+ app_arg(add_line, &day, 0, fmt_apt,
+ fmt_rapt, fmt_ev, fmt_rev, preg);
+ non_interactive = 1;
+ }
+ } else {
+ non_interactive = 0;
+ io_init(cfile, datadir);
+ }
+ }
+
+ if (preg)
+ regfree(preg);
+
+ return non_interactive;
}
diff --git a/src/calcurse.c b/src/calcurse.c
index 59f912e..7ab9c6a 100644
--- a/src/calcurse.c
+++ b/src/calcurse.c
@@ -49,432 +49,443 @@ int count, reg;
*/
static struct day_items_nb do_storage(int day_changed)
{
- struct day_items_nb inday = day_process_storage(ui_calendar_get_slctd_day(),
- day_changed);
+ struct day_items_nb inday =
+ day_process_storage(ui_calendar_get_slctd_day(),
+ day_changed);
- if (day_changed) {
- if ((inday.nb_events + inday.nb_apoints) > 0)
- ui_day_hilt_set(1);
- else
- ui_day_hilt_set(0);
- }
+ if (day_changed) {
+ if ((inday.nb_events + inday.nb_apoints) > 0)
+ ui_day_hilt_set(1);
+ else
+ ui_day_hilt_set(0);
+ }
- return inday;
+ return inday;
}
static inline void key_generic_change_view(void)
{
- wins_reset_status_page();
- wins_slctd_next();
-
- /* Select the event to highlight. */
- switch (wins_slctd()) {
- case TOD:
- if ((ui_todo_hilt() == 0) && (ui_todo_nb() > 0))
- ui_todo_hilt_set(1);
- break;
- case APP:
- if ((ui_day_hilt() == 0) && ((inday.nb_events + inday.nb_apoints) > 0))
- ui_day_hilt_set(1);
- break;
- default:
- break;
- }
- wins_update(FLAG_ALL);
+ wins_reset_status_page();
+ wins_slctd_next();
+
+ /* Select the event to highlight. */
+ switch (wins_slctd()) {
+ case TOD:
+ if ((ui_todo_hilt() == 0) && (ui_todo_nb() > 0))
+ ui_todo_hilt_set(1);
+ break;
+ case APP:
+ if ((ui_day_hilt() == 0)
+ && ((inday.nb_events + inday.nb_apoints) > 0))
+ ui_day_hilt_set(1);
+ break;
+ default:
+ break;
+ }
+ wins_update(FLAG_ALL);
}
static inline void key_generic_other_cmd(void)
{
- wins_other_status_page(wins_slctd());
- wins_update(FLAG_STA);
+ wins_other_status_page(wins_slctd());
+ wins_update(FLAG_STA);
}
static inline void key_generic_goto(void)
{
- wins_erase_status_bar();
- ui_calendar_set_current_date();
- ui_calendar_change_day(conf.input_datefmt);
- inday = do_storage(1);
- wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
+ wins_erase_status_bar();
+ ui_calendar_set_current_date();
+ ui_calendar_change_day(conf.input_datefmt);
+ inday = do_storage(1);
+ wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
}
static inline void key_generic_goto_today(void)
{
- wins_erase_status_bar();
- ui_calendar_set_current_date();
- ui_calendar_goto_today();
- inday = do_storage(1);
- wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
+ wins_erase_status_bar();
+ ui_calendar_set_current_date();
+ ui_calendar_goto_today();
+ inday = do_storage(1);
+ wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
}
static inline void key_view_item(void)
{
- if ((wins_slctd() == APP) && (ui_day_hilt() != 0))
- day_popup_item(day_get_item(ui_day_hilt()));
- else if ((wins_slctd() == TOD) && (ui_todo_hilt() != 0))
- item_in_popup(NULL, NULL, ui_todo_saved_mesg(), _("To do :"));
- wins_update(FLAG_ALL);
+ if ((wins_slctd() == APP) && (ui_day_hilt() != 0))
+ day_popup_item(day_get_item(ui_day_hilt()));
+ else if ((wins_slctd() == TOD) && (ui_todo_hilt() != 0))
+ item_in_popup(NULL, NULL, ui_todo_saved_mesg(),
+ _("To do :"));
+ wins_update(FLAG_ALL);
}
static inline void key_generic_config_menu(void)
{
- wins_erase_status_bar();
- custom_config_main();
- inday = do_storage(0);
- wins_update(FLAG_ALL);
+ wins_erase_status_bar();
+ custom_config_main();
+ inday = do_storage(0);
+ wins_update(FLAG_ALL);
}
static inline void key_generic_add_appt(void)
{
- ui_day_item_add();
- inday = do_storage(1);
- wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
+ ui_day_item_add();
+ inday = do_storage(1);
+ wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
}
static inline void key_generic_add_todo(void)
{
- ui_todo_add();
- if (ui_todo_hilt() == 0 && ui_todo_nb() == 1)
- ui_todo_hilt_increase(1);
- wins_update(FLAG_TOD | FLAG_STA);
+ ui_todo_add();
+ if (ui_todo_hilt() == 0 && ui_todo_nb() == 1)
+ ui_todo_hilt_increase(1);
+ wins_update(FLAG_TOD | FLAG_STA);
}
static inline void key_add_item(void)
{
- switch (wins_slctd()) {
- case APP:
- ui_day_item_add();
- inday = do_storage(0);
- wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
- break;
- case TOD:
- ui_todo_add();
- if (ui_todo_hilt() == 0 && ui_todo_nb() == 1)
- ui_todo_hilt_increase(1);
- wins_update(FLAG_TOD | FLAG_STA);
- break;
- default:
- break;
- }
+ switch (wins_slctd()) {
+ case APP:
+ ui_day_item_add();
+ inday = do_storage(0);
+ wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
+ break;
+ case TOD:
+ ui_todo_add();
+ if (ui_todo_hilt() == 0 && ui_todo_nb() == 1)
+ ui_todo_hilt_increase(1);
+ wins_update(FLAG_TOD | FLAG_STA);
+ break;
+ default:
+ break;
+ }
}
static inline void key_edit_item(void)
{
- if (wins_slctd() == APP && ui_day_hilt() != 0) {
- ui_day_item_edit();
- inday = do_storage(0);
- wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
- } else if (wins_slctd() == TOD && ui_todo_hilt() != 0) {
- ui_todo_edit();
- wins_update(FLAG_TOD | FLAG_STA);
- }
+ if (wins_slctd() == APP && ui_day_hilt() != 0) {
+ ui_day_item_edit();
+ inday = do_storage(0);
+ wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
+ } else if (wins_slctd() == TOD && ui_todo_hilt() != 0) {
+ ui_todo_edit();
+ wins_update(FLAG_TOD | FLAG_STA);
+ }
}
static inline void key_del_item(void)
{
- if (wins_slctd() == APP && ui_day_hilt() != 0) {
- ui_day_item_delete(&inday.nb_events, &inday.nb_apoints, reg);
- inday = do_storage(0);
- wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
- } else if (wins_slctd() == TOD && ui_todo_hilt() != 0) {
- ui_todo_delete();
- wins_update(FLAG_TOD | FLAG_STA);
- }
+ if (wins_slctd() == APP && ui_day_hilt() != 0) {
+ ui_day_item_delete(&inday.nb_events, &inday.nb_apoints,
+ reg);
+ inday = do_storage(0);
+ wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
+ } else if (wins_slctd() == TOD && ui_todo_hilt() != 0) {
+ ui_todo_delete();
+ wins_update(FLAG_TOD | FLAG_STA);
+ }
}
static inline void key_generic_copy(void)
{
- if (wins_slctd() == APP && ui_day_hilt() != 0) {
- ui_day_item_copy(&inday.nb_events, &inday.nb_apoints, reg);
- inday = do_storage(0);
- wins_update(FLAG_CAL | FLAG_APP);
- }
+ if (wins_slctd() == APP && ui_day_hilt() != 0) {
+ ui_day_item_copy(&inday.nb_events, &inday.nb_apoints, reg);
+ inday = do_storage(0);
+ wins_update(FLAG_CAL | FLAG_APP);
+ }
}
static inline void key_generic_paste(void)
{
- if (wins_slctd() == APP) {
- ui_day_item_paste(&inday.nb_events, &inday.nb_apoints, reg);
- inday = do_storage(0);
- wins_update(FLAG_CAL | FLAG_APP);
- }
+ if (wins_slctd() == APP) {
+ ui_day_item_paste(&inday.nb_events, &inday.nb_apoints,
+ reg);
+ inday = do_storage(0);
+ wins_update(FLAG_CAL | FLAG_APP);
+ }
}
static inline void key_repeat_item(void)
{
- if (wins_slctd() == APP && ui_day_hilt() != 0)
- ui_day_item_repeat();
- inday = do_storage(0);
- wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
+ if (wins_slctd() == APP && ui_day_hilt() != 0)
+ ui_day_item_repeat();
+ inday = do_storage(0);
+ wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
}
static inline void key_flag_item(void)
{
- if (wins_slctd() == APP && ui_day_hilt() != 0) {
- day_item_switch_notify(day_get_item(ui_day_hilt()));
- inday = do_storage(0);
- wins_update(FLAG_APP);
- } else if (wins_slctd() == TOD && ui_todo_hilt() != 0) {
- todo_flag(todo_get_item(ui_todo_hilt()));
- wins_update(FLAG_TOD);
- }
+ if (wins_slctd() == APP && ui_day_hilt() != 0) {
+ day_item_switch_notify(day_get_item(ui_day_hilt()));
+ inday = do_storage(0);
+ wins_update(FLAG_APP);
+ } else if (wins_slctd() == TOD && ui_todo_hilt() != 0) {
+ todo_flag(todo_get_item(ui_todo_hilt()));
+ wins_update(FLAG_TOD);
+ }
}
static inline void key_pipe_item(void)
{
- if (wins_slctd() == APP && ui_day_hilt() != 0)
- ui_day_item_pipe();
- else if (wins_slctd() == TOD && ui_todo_hilt() != 0)
- ui_todo_pipe();
- wins_update(FLAG_ALL);
+ if (wins_slctd() == APP && ui_day_hilt() != 0)
+ ui_day_item_pipe();
+ else if (wins_slctd() == TOD && ui_todo_hilt() != 0)
+ ui_todo_pipe();
+ wins_update(FLAG_ALL);
}
static inline void change_priority(int diff)
{
- if (wins_slctd() == TOD && ui_todo_hilt() != 0) {
- ui_todo_chg_priority(todo_get_item(ui_todo_hilt()), diff);
- if (ui_todo_hilt_pos() < 0)
- ui_todo_set_first(ui_todo_hilt());
- else if (ui_todo_hilt_pos() >= win[TOD].h - 4)
- ui_todo_set_first(ui_todo_hilt() - win[TOD].h + 5);
- wins_update(FLAG_TOD);
- }
+ if (wins_slctd() == TOD && ui_todo_hilt() != 0) {
+ ui_todo_chg_priority(todo_get_item(ui_todo_hilt()), diff);
+ if (ui_todo_hilt_pos() < 0)
+ ui_todo_set_first(ui_todo_hilt());
+ else if (ui_todo_hilt_pos() >= win[TOD].h - 4)
+ ui_todo_set_first(ui_todo_hilt() - win[TOD].h + 5);
+ wins_update(FLAG_TOD);
+ }
}
static inline void key_raise_priority(void)
{
- change_priority(1);
+ change_priority(1);
}
static inline void key_lower_priority(void)
{
- change_priority(-1);
+ change_priority(-1);
}
static inline void key_edit_note(void)
{
- if (wins_slctd() == APP && ui_day_hilt() != 0) {
- day_edit_note(day_get_item(ui_day_hilt()), conf.editor);
- inday = do_storage(0);
- } else if (wins_slctd() == TOD && ui_todo_hilt() != 0) {
- todo_edit_note(todo_get_item(ui_todo_hilt()), conf.editor);
- }
- wins_update(FLAG_ALL);
+ if (wins_slctd() == APP && ui_day_hilt() != 0) {
+ day_edit_note(day_get_item(ui_day_hilt()), conf.editor);
+ inday = do_storage(0);
+ } else if (wins_slctd() == TOD && ui_todo_hilt() != 0) {
+ todo_edit_note(todo_get_item(ui_todo_hilt()), conf.editor);
+ }
+ wins_update(FLAG_ALL);
}
static inline void key_view_note(void)
{
- if (wins_slctd() == APP && ui_day_hilt() != 0)
- day_view_note(day_get_item(ui_day_hilt()), conf.pager);
- else if (wins_slctd() == TOD && ui_todo_hilt() != 0)
- todo_view_note(todo_get_item(ui_todo_hilt()), conf.pager);
- wins_update(FLAG_ALL);
+ if (wins_slctd() == APP && ui_day_hilt() != 0)
+ day_view_note(day_get_item(ui_day_hilt()), conf.pager);
+ else if (wins_slctd() == TOD && ui_todo_hilt() != 0)
+ todo_view_note(todo_get_item(ui_todo_hilt()), conf.pager);
+ wins_update(FLAG_ALL);
}
static inline void key_generic_help(void)
{
- wins_status_bar();
- help_screen();
- wins_update(FLAG_ALL);
+ wins_status_bar();
+ help_screen();
+ wins_update(FLAG_ALL);
}
static inline void key_generic_save(void)
{
- io_save_cal(IO_SAVE_DISPLAY_BAR);
- wins_update(FLAG_STA);
+ io_save_cal(IO_SAVE_DISPLAY_BAR);
+ wins_update(FLAG_STA);
}
static inline void key_generic_import(void)
{
- wins_erase_status_bar();
- io_import_data(IO_IMPORT_ICAL, NULL);
- ui_calendar_monthly_view_cache_set_invalid();
- inday = do_storage(0);
- wins_update(FLAG_ALL);
+ wins_erase_status_bar();
+ io_import_data(IO_IMPORT_ICAL, NULL);
+ ui_calendar_monthly_view_cache_set_invalid();
+ inday = do_storage(0);
+ wins_update(FLAG_ALL);
}
static inline void key_generic_export()
{
- const char *export_msg = _("Export to (i)cal or (p)cal format?");
- const char *export_choices = _("[ip]");
- const int nb_export_choices = 2;
+ const char *export_msg = _("Export to (i)cal or (p)cal format?");
+ const char *export_choices = _("[ip]");
+ const int nb_export_choices = 2;
- wins_erase_status_bar();
+ wins_erase_status_bar();
- switch (status_ask_choice(export_msg, export_choices, nb_export_choices)) {
- case 1:
- io_export_data(IO_EXPORT_ICAL);
- break;
- case 2:
- io_export_data(IO_EXPORT_PCAL);
- break;
- default: /* User escaped */
- break;
- }
+ switch (status_ask_choice
+ (export_msg, export_choices, nb_export_choices)) {
+ case 1:
+ io_export_data(IO_EXPORT_ICAL);
+ break;
+ case 2:
+ io_export_data(IO_EXPORT_PCAL);
+ break;
+ default: /* User escaped */
+ break;
+ }
- inday = do_storage(0);
- wins_update(FLAG_ALL);
+ inday = do_storage(0);
+ wins_update(FLAG_ALL);
}
static inline void key_generic_prev_day(void)
{
- ui_calendar_move(DAY_PREV, count);
- inday = do_storage(1);
- wins_update(FLAG_CAL | FLAG_APP);
+ ui_calendar_move(DAY_PREV, count);
+ inday = do_storage(1);
+ wins_update(FLAG_CAL | FLAG_APP);
}
static inline void key_move_left(void)
{
- if (wins_slctd() == CAL)
- key_generic_prev_day();
+ if (wins_slctd() == CAL)
+ key_generic_prev_day();
}
static inline void key_generic_next_day(void)
{
- ui_calendar_move(DAY_NEXT, count);
- inday = do_storage(1);
- wins_update(FLAG_CAL | FLAG_APP);
+ ui_calendar_move(DAY_NEXT, count);
+ inday = do_storage(1);
+ wins_update(FLAG_CAL | FLAG_APP);
}
static inline void key_move_right(void)
{
- if (wins_slctd() == CAL)
- key_generic_next_day();
+ if (wins_slctd() == CAL)
+ key_generic_next_day();
}
static inline void key_generic_prev_week(void)
{
- ui_calendar_move(WEEK_PREV, count);
- inday = do_storage(1);
- wins_update(FLAG_CAL | FLAG_APP);
+ ui_calendar_move(WEEK_PREV, count);
+ inday = do_storage(1);
+ wins_update(FLAG_CAL | FLAG_APP);
}
static inline void key_move_up(void)
{
- if (wins_slctd() == CAL) {
- key_generic_prev_week();
- } else if (wins_slctd() == APP) {
- if (count >= ui_day_hilt())
- count = ui_day_hilt() - 1;
- ui_day_hilt_decrease(count);
- ui_day_scroll_pad_up(inday.nb_events);
- wins_update(FLAG_APP);
- } else if (wins_slctd() == TOD) {
- if (count >= ui_todo_hilt())
- count = ui_todo_hilt() - 1;
- ui_todo_hilt_decrease(count);
- if (ui_todo_hilt_pos() < 0)
- ui_todo_first_increase(ui_todo_hilt_pos());
- wins_update(FLAG_TOD);
- }
+ if (wins_slctd() == CAL) {
+ key_generic_prev_week();
+ } else if (wins_slctd() == APP) {
+ if (count >= ui_day_hilt())
+ count = ui_day_hilt() - 1;
+ ui_day_hilt_decrease(count);
+ ui_day_scroll_pad_up(inday.nb_events);
+ wins_update(FLAG_APP);
+ } else if (wins_slctd() == TOD) {
+ if (count >= ui_todo_hilt())
+ count = ui_todo_hilt() - 1;
+ ui_todo_hilt_decrease(count);
+ if (ui_todo_hilt_pos() < 0)
+ ui_todo_first_increase(ui_todo_hilt_pos());
+ wins_update(FLAG_TOD);
+ }
}
static inline void key_generic_next_week(void)
{
- ui_calendar_move(WEEK_NEXT, count);
- inday = do_storage(1);
- wins_update(FLAG_CAL | FLAG_APP);
+ ui_calendar_move(WEEK_NEXT, count);
+ inday = do_storage(1);
+ wins_update(FLAG_CAL | FLAG_APP);
}
static inline void key_move_down(void)
{
- if (wins_slctd() == CAL) {
- key_generic_next_week();
- } else if (wins_slctd() == APP) {
- if (count > inday.nb_events + inday.nb_apoints - ui_day_hilt())
- count = inday.nb_events + inday.nb_apoints - ui_day_hilt();
- ui_day_hilt_increase(count);
- ui_day_scroll_pad_down(inday.nb_events, win[APP].h);
- wins_update(FLAG_APP);
- } else if (wins_slctd() == TOD) {
- if (count > ui_todo_nb() - ui_todo_hilt())
- count = ui_todo_nb() - ui_todo_hilt();
- ui_todo_hilt_increase(count);
- if (ui_todo_hilt_pos() >= win[TOD].h - 4)
- ui_todo_first_increase(ui_todo_hilt_pos() - win[TOD].h + 5);
- wins_update(FLAG_TOD);
- }
+ if (wins_slctd() == CAL) {
+ key_generic_next_week();
+ } else if (wins_slctd() == APP) {
+ if (count >
+ inday.nb_events + inday.nb_apoints - ui_day_hilt())
+ count =
+ inday.nb_events + inday.nb_apoints -
+ ui_day_hilt();
+ ui_day_hilt_increase(count);
+ ui_day_scroll_pad_down(inday.nb_events, win[APP].h);
+ wins_update(FLAG_APP);
+ } else if (wins_slctd() == TOD) {
+ if (count > ui_todo_nb() - ui_todo_hilt())
+ count = ui_todo_nb() - ui_todo_hilt();
+ ui_todo_hilt_increase(count);
+ if (ui_todo_hilt_pos() >= win[TOD].h - 4)
+ ui_todo_first_increase(ui_todo_hilt_pos() -
+ win[TOD].h + 5);
+ wins_update(FLAG_TOD);
+ }
}
static inline void key_generic_prev_month(void)
{
- ui_calendar_move(MONTH_PREV, count);
- inday = do_storage(1);
- wins_update(FLAG_CAL | FLAG_APP);
+ ui_calendar_move(MONTH_PREV, count);
+ inday = do_storage(1);
+ wins_update(FLAG_CAL | FLAG_APP);
}
static inline void key_generic_next_month(void)
{
- ui_calendar_move(MONTH_NEXT, count);
- inday = do_storage(1);
- wins_update(FLAG_CAL | FLAG_APP);
+ ui_calendar_move(MONTH_NEXT, count);
+ inday = do_storage(1);
+ wins_update(FLAG_CAL | FLAG_APP);
}
static inline void key_generic_prev_year(void)
{
- ui_calendar_move(YEAR_PREV, count);
- inday = do_storage(1);
- wins_update(FLAG_CAL | FLAG_APP);
+ ui_calendar_move(YEAR_PREV, count);
+ inday = do_storage(1);
+ wins_update(FLAG_CAL | FLAG_APP);
}
static inline void key_generic_next_year(void)
{
- ui_calendar_move(YEAR_NEXT, count);
- inday = do_storage(1);
- wins_update(FLAG_CAL | FLAG_APP);
+ ui_calendar_move(YEAR_NEXT, count);
+ inday = do_storage(1);
+ wins_update(FLAG_CAL | FLAG_APP);
}
static inline void key_start_of_week(void)
{
- if (wins_slctd() == CAL) {
- ui_calendar_move(WEEK_START, count);
- inday = do_storage(1);
- wins_update(FLAG_CAL | FLAG_APP);
- }
+ if (wins_slctd() == CAL) {
+ ui_calendar_move(WEEK_START, count);
+ inday = do_storage(1);
+ wins_update(FLAG_CAL | FLAG_APP);
+ }
}
static inline void key_end_of_week(void)
{
- if (wins_slctd() == CAL) {
- ui_calendar_move(WEEK_END, count);
- inday = do_storage(1);
- wins_update(FLAG_CAL | FLAG_APP);
- }
+ if (wins_slctd() == CAL) {
+ ui_calendar_move(WEEK_END, count);
+ inday = do_storage(1);
+ wins_update(FLAG_CAL | FLAG_APP);
+ }
}
static inline void key_generic_scroll_up(void)
{
- if (wins_slctd() == CAL) {
- ui_calendar_view_prev();
- wins_update(FLAG_CAL | FLAG_APP);
- }
+ if (wins_slctd() == CAL) {
+ ui_calendar_view_prev();
+ wins_update(FLAG_CAL | FLAG_APP);
+ }
}
static inline void key_generic_scroll_down(void)
{
- if (wins_slctd() == CAL) {
- ui_calendar_view_next();
- wins_update(FLAG_CAL | FLAG_APP);
- }
+ if (wins_slctd() == CAL) {
+ ui_calendar_view_next();
+ wins_update(FLAG_CAL | FLAG_APP);
+ }
}
static inline void key_generic_quit(void)
{
- if (conf.auto_save)
- io_save_cal(IO_SAVE_DISPLAY_BAR);
- if (conf.auto_gc)
- note_gc();
+ if (conf.auto_save)
+ io_save_cal(IO_SAVE_DISPLAY_BAR);
+ if (conf.auto_gc)
+ note_gc();
- if (conf.confirm_quit) {
- if (status_ask_bool(_("Do you really want to quit ?")) == 1) {
- exit_calcurse(EXIT_SUCCESS);
- } else {
- wins_erase_status_bar();
- wins_update(FLAG_STA);
- }
- } else {
- exit_calcurse(EXIT_SUCCESS);
- }
+ if (conf.confirm_quit) {
+ if (status_ask_bool(_("Do you really want to quit ?")) ==
+ 1) {
+ exit_calcurse(EXIT_SUCCESS);
+ } else {
+ wins_erase_status_bar();
+ wins_update(FLAG_STA);
+ }
+ } else {
+ exit_calcurse(EXIT_SUCCESS);
+ }
}
/*
@@ -486,178 +497,178 @@ static inline void key_generic_quit(void)
*/
int main(int argc, char **argv)
{
- int no_data_file = 1;
+ int no_data_file = 1;
#if ENABLE_NLS
- setlocale(LC_ALL, "");
- bindtextdomain(PACKAGE, LOCALEDIR);
- textdomain(PACKAGE);
+ setlocale(LC_ALL, "");
+ bindtextdomain(PACKAGE, LOCALEDIR);
+ textdomain(PACKAGE);
#endif /* ENABLE_NLS */
- /* Thread-safe data structure init */
- apoint_llist_init();
- recur_apoint_llist_init();
-
- /* Initialize non-thread-safe data structures. */
- event_llist_init();
- todo_init_list();
-
- /*
- * Begin by parsing and handling command line arguments.
- * The data path is also initialized here.
- */
- if (parse_args(argc, argv)) {
- /* Non-interactive mode. */
- exit_calcurse(EXIT_SUCCESS);
- } else {
- no_data_file = io_check_data_files();
- dmon_stop();
- io_set_lock();
- }
-
- /* Begin of interactive mode with ncurses interface. */
- sigs_init(); /* signal handling init */
- initscr(); /* start the curses mode */
- cbreak(); /* control chars generate a signal */
- noecho(); /* controls echoing of typed chars */
- curs_set(0); /* make cursor invisible */
- ui_calendar_set_current_date();
- notify_init_vars();
- wins_get_config();
-
- /* Check if terminal supports color. */
- if (has_colors()) {
- colorize = 1;
- background = COLOR_BLACK;
- foreground = COLOR_WHITE;
- start_color();
+ /* Thread-safe data structure init */
+ apoint_llist_init();
+ recur_apoint_llist_init();
+
+ /* Initialize non-thread-safe data structures. */
+ event_llist_init();
+ todo_init_list();
+
+ /*
+ * Begin by parsing and handling command line arguments.
+ * The data path is also initialized here.
+ */
+ if (parse_args(argc, argv)) {
+ /* Non-interactive mode. */
+ exit_calcurse(EXIT_SUCCESS);
+ } else {
+ no_data_file = io_check_data_files();
+ dmon_stop();
+ io_set_lock();
+ }
+
+ /* Begin of interactive mode with ncurses interface. */
+ sigs_init(); /* signal handling init */
+ initscr(); /* start the curses mode */
+ cbreak(); /* control chars generate a signal */
+ noecho(); /* controls echoing of typed chars */
+ curs_set(0); /* make cursor invisible */
+ ui_calendar_set_current_date();
+ notify_init_vars();
+ wins_get_config();
+
+ /* Check if terminal supports color. */
+ if (has_colors()) {
+ colorize = 1;
+ background = COLOR_BLACK;
+ foreground = COLOR_WHITE;
+ start_color();
#ifdef NCURSES_VERSION
- if (use_default_colors() != ERR) {
- background = -1;
- foreground = -1;
- }
+ if (use_default_colors() != ERR) {
+ background = -1;
+ foreground = -1;
+ }
#endif /* NCURSES_VERSION */
- /* Color assignment */
- init_pair(COLR_RED, COLOR_RED, background);
- init_pair(COLR_GREEN, COLOR_GREEN, background);
- init_pair(COLR_YELLOW, COLOR_YELLOW, background);
- init_pair(COLR_BLUE, COLOR_BLUE, background);
- init_pair(COLR_MAGENTA, COLOR_MAGENTA, background);
- init_pair(COLR_CYAN, COLOR_CYAN, background);
- init_pair(COLR_DEFAULT, foreground, background);
- init_pair(COLR_HIGH, COLOR_BLACK, COLOR_GREEN);
- init_pair(COLR_CUSTOM, COLOR_RED, background);
- } else {
- colorize = 0;
- background = COLOR_BLACK;
- }
-
- vars_init();
- wins_init();
- /* Default to the calendar panel -- this is overridden later. */
- wins_slctd_set(CAL);
- notify_init_bar();
- wins_reset_status_page();
-
- /*
- * Read the data from files : first the user
- * configuration (the display is then updated), and then
- * the todo list, appointments and events.
- */
- config_load();
- wins_erase_status_bar();
- io_load_keys(conf.pager);
- io_load_todo();
- io_load_app();
- wins_reinit();
- /*
- * Refresh the hidden key handler window here to prevent wgetch() from
- * implicitly calling wrefresh() later (causing ncurses race conditions).
- */
- wins_wrefresh(win[KEY].p);
- if (conf.system_dialogs) {
- wins_update(FLAG_ALL);
- io_startup_screen(no_data_file);
- }
- inday = day_process_storage(0, 0);
- wins_slctd_set(conf.default_panel);
- wins_update(FLAG_ALL);
-
- /* Start miscellaneous threads. */
- if (notify_bar())
- notify_start_main_thread();
- ui_calendar_start_date_thread();
- if (conf.periodic_save > 0)
- io_start_psave_thread();
-
- /* User input */
- for (;;) {
- int key;
-
- if (resize) {
- resize = 0;
- wins_reset();
- }
-
- key = keys_getch(win[KEY].p, &count, &reg);
- switch (key) {
- case KEY_GENERIC_REDRAW:
- resize = 1;
- break;
-
- HANDLE_KEY(KEY_GENERIC_CHANGE_VIEW, key_generic_change_view);
- HANDLE_KEY(KEY_GENERIC_OTHER_CMD, key_generic_other_cmd);
- HANDLE_KEY(KEY_GENERIC_GOTO, key_generic_goto);
- HANDLE_KEY(KEY_GENERIC_GOTO_TODAY, key_generic_goto_today);
- HANDLE_KEY(KEY_VIEW_ITEM, key_view_item);
- HANDLE_KEY(KEY_GENERIC_CONFIG_MENU, key_generic_config_menu);
- HANDLE_KEY(KEY_GENERIC_ADD_APPT, key_generic_add_appt);
- HANDLE_KEY(KEY_GENERIC_ADD_TODO, key_generic_add_todo);
- HANDLE_KEY(KEY_ADD_ITEM, key_add_item);
- HANDLE_KEY(KEY_EDIT_ITEM, key_edit_item);
- HANDLE_KEY(KEY_DEL_ITEM, key_del_item);
- HANDLE_KEY(KEY_GENERIC_COPY, key_generic_copy);
- HANDLE_KEY(KEY_GENERIC_PASTE, key_generic_paste);
- HANDLE_KEY(KEY_REPEAT_ITEM, key_repeat_item);
- HANDLE_KEY(KEY_FLAG_ITEM, key_flag_item);
- HANDLE_KEY(KEY_PIPE_ITEM, key_pipe_item);
- HANDLE_KEY(KEY_RAISE_PRIORITY, key_raise_priority);
- HANDLE_KEY(KEY_LOWER_PRIORITY, key_lower_priority);
- HANDLE_KEY(KEY_EDIT_NOTE, key_edit_note);
- HANDLE_KEY(KEY_VIEW_NOTE, key_view_note);
- HANDLE_KEY(KEY_GENERIC_HELP, key_generic_help);
- HANDLE_KEY(KEY_GENERIC_SAVE, key_generic_save);
- HANDLE_KEY(KEY_GENERIC_IMPORT, key_generic_import);
- HANDLE_KEY(KEY_GENERIC_EXPORT, key_generic_export);
- HANDLE_KEY(KEY_GENERIC_PREV_DAY, key_generic_prev_day);
- HANDLE_KEY(KEY_MOVE_LEFT, key_move_left);
- HANDLE_KEY(KEY_GENERIC_NEXT_DAY, key_generic_next_day);
- HANDLE_KEY(KEY_MOVE_RIGHT, key_move_right);
- HANDLE_KEY(KEY_GENERIC_PREV_WEEK, key_generic_prev_week);
- HANDLE_KEY(KEY_MOVE_UP, key_move_up);
- HANDLE_KEY(KEY_GENERIC_NEXT_WEEK, key_generic_next_week);
- HANDLE_KEY(KEY_MOVE_DOWN, key_move_down);
- HANDLE_KEY(KEY_GENERIC_PREV_MONTH, key_generic_prev_month);
- HANDLE_KEY(KEY_GENERIC_NEXT_MONTH, key_generic_next_month);
- HANDLE_KEY(KEY_GENERIC_PREV_YEAR, key_generic_prev_year);
- HANDLE_KEY(KEY_GENERIC_NEXT_YEAR, key_generic_next_year);
- HANDLE_KEY(KEY_START_OF_WEEK, key_start_of_week);
- HANDLE_KEY(KEY_END_OF_WEEK, key_end_of_week);
- HANDLE_KEY(KEY_GENERIC_SCROLL_UP, key_generic_scroll_up);
- HANDLE_KEY(KEY_GENERIC_SCROLL_DOWN, key_generic_scroll_down);
- HANDLE_KEY(KEY_GENERIC_QUIT, key_generic_quit);
-
- case KEY_RESIZE:
- case ERR:
- /* Do not reset the count parameter on resize or error. */
- continue;
-
- default:
- break;
- }
-
- count = 0;
- }
+ /* Color assignment */
+ init_pair(COLR_RED, COLOR_RED, background);
+ init_pair(COLR_GREEN, COLOR_GREEN, background);
+ init_pair(COLR_YELLOW, COLOR_YELLOW, background);
+ init_pair(COLR_BLUE, COLOR_BLUE, background);
+ init_pair(COLR_MAGENTA, COLOR_MAGENTA, background);
+ init_pair(COLR_CYAN, COLOR_CYAN, background);
+ init_pair(COLR_DEFAULT, foreground, background);
+ init_pair(COLR_HIGH, COLOR_BLACK, COLOR_GREEN);
+ init_pair(COLR_CUSTOM, COLOR_RED, background);
+ } else {
+ colorize = 0;
+ background = COLOR_BLACK;
+ }
+
+ vars_init();
+ wins_init();
+ /* Default to the calendar panel -- this is overridden later. */
+ wins_slctd_set(CAL);
+ notify_init_bar();
+ wins_reset_status_page();
+
+ /*
+ * Read the data from files : first the user
+ * configuration (the display is then updated), and then
+ * the todo list, appointments and events.
+ */
+ config_load();
+ wins_erase_status_bar();
+ io_load_keys(conf.pager);
+ io_load_todo();
+ io_load_app();
+ wins_reinit();
+ /*
+ * Refresh the hidden key handler window here to prevent wgetch() from
+ * implicitly calling wrefresh() later (causing ncurses race conditions).
+ */
+ wins_wrefresh(win[KEY].p);
+ if (conf.system_dialogs) {
+ wins_update(FLAG_ALL);
+ io_startup_screen(no_data_file);
+ }
+ inday = day_process_storage(0, 0);
+ wins_slctd_set(conf.default_panel);
+ wins_update(FLAG_ALL);
+
+ /* Start miscellaneous threads. */
+ if (notify_bar())
+ notify_start_main_thread();
+ ui_calendar_start_date_thread();
+ if (conf.periodic_save > 0)
+ io_start_psave_thread();
+
+ /* User input */
+ for (;;) {
+ int key;
+
+ if (resize) {
+ resize = 0;
+ wins_reset();
+ }
+
+ key = keys_getch(win[KEY].p, &count, &reg);
+ switch (key) {
+ case KEY_GENERIC_REDRAW:
+ resize = 1;
+ break;
+
+ HANDLE_KEY(KEY_GENERIC_CHANGE_VIEW, key_generic_change_view);
+ HANDLE_KEY(KEY_GENERIC_OTHER_CMD, key_generic_other_cmd);
+ HANDLE_KEY(KEY_GENERIC_GOTO, key_generic_goto);
+ HANDLE_KEY(KEY_GENERIC_GOTO_TODAY, key_generic_goto_today);
+ HANDLE_KEY(KEY_VIEW_ITEM, key_view_item);
+ HANDLE_KEY(KEY_GENERIC_CONFIG_MENU, key_generic_config_menu);
+ HANDLE_KEY(KEY_GENERIC_ADD_APPT, key_generic_add_appt);
+ HANDLE_KEY(KEY_GENERIC_ADD_TODO, key_generic_add_todo);
+ HANDLE_KEY(KEY_ADD_ITEM, key_add_item);
+ HANDLE_KEY(KEY_EDIT_ITEM, key_edit_item);
+ HANDLE_KEY(KEY_DEL_ITEM, key_del_item);
+ HANDLE_KEY(KEY_GENERIC_COPY, key_generic_copy);
+ HANDLE_KEY(KEY_GENERIC_PASTE, key_generic_paste);
+ HANDLE_KEY(KEY_REPEAT_ITEM, key_repeat_item);
+ HANDLE_KEY(KEY_FLAG_ITEM, key_flag_item);
+ HANDLE_KEY(KEY_PIPE_ITEM, key_pipe_item);
+ HANDLE_KEY(KEY_RAISE_PRIORITY, key_raise_priority);
+ HANDLE_KEY(KEY_LOWER_PRIORITY, key_lower_priority);
+ HANDLE_KEY(KEY_EDIT_NOTE, key_edit_note);
+ HANDLE_KEY(KEY_VIEW_NOTE, key_view_note);
+ HANDLE_KEY(KEY_GENERIC_HELP, key_generic_help);
+ HANDLE_KEY(KEY_GENERIC_SAVE, key_generic_save);
+ HANDLE_KEY(KEY_GENERIC_IMPORT, key_generic_import);
+ HANDLE_KEY(KEY_GENERIC_EXPORT, key_generic_export);
+ HANDLE_KEY(KEY_GENERIC_PREV_DAY, key_generic_prev_day);
+ HANDLE_KEY(KEY_MOVE_LEFT, key_move_left);
+ HANDLE_KEY(KEY_GENERIC_NEXT_DAY, key_generic_next_day);
+ HANDLE_KEY(KEY_MOVE_RIGHT, key_move_right);
+ HANDLE_KEY(KEY_GENERIC_PREV_WEEK, key_generic_prev_week);
+ HANDLE_KEY(KEY_MOVE_UP, key_move_up);
+ HANDLE_KEY(KEY_GENERIC_NEXT_WEEK, key_generic_next_week);
+ HANDLE_KEY(KEY_MOVE_DOWN, key_move_down);
+ HANDLE_KEY(KEY_GENERIC_PREV_MONTH, key_generic_prev_month);
+ HANDLE_KEY(KEY_GENERIC_NEXT_MONTH, key_generic_next_month);
+ HANDLE_KEY(KEY_GENERIC_PREV_YEAR, key_generic_prev_year);
+ HANDLE_KEY(KEY_GENERIC_NEXT_YEAR, key_generic_next_year);
+ HANDLE_KEY(KEY_START_OF_WEEK, key_start_of_week);
+ HANDLE_KEY(KEY_END_OF_WEEK, key_end_of_week);
+ HANDLE_KEY(KEY_GENERIC_SCROLL_UP, key_generic_scroll_up);
+ HANDLE_KEY(KEY_GENERIC_SCROLL_DOWN, key_generic_scroll_down);
+ HANDLE_KEY(KEY_GENERIC_QUIT, key_generic_quit);
+
+ case KEY_RESIZE:
+ case ERR:
+ /* Do not reset the count parameter on resize or error. */
+ continue;
+
+ default:
+ break;
+ }
+
+ count = 0;
+ }
}
diff --git a/src/calcurse.h b/src/calcurse.h
index e8313b0..1dfd648 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -156,9 +156,9 @@
#define TAB 9
#define SPACE 32
-#define KEYS_KEYLEN 3 /* length of each keybinding */
-#define KEYS_LABELEN 8 /* length of command description */
-#define KEYS_CMDS_PER_LINE 6 /* max number of commands per line */
+#define KEYS_KEYLEN 3 /* length of each keybinding */
+#define KEYS_LABELEN 8 /* length of command description */
+#define KEYS_CMDS_PER_LINE 6 /* max number of commands per line */
/* Register definitions. */
#define REG_BLACK_HOLE 37
@@ -234,45 +234,45 @@
#define MIN(x,y) ((x)<(y)?(x):(y))
enum win {
- CAL,
- APP,
- TOD,
- NOT,
- STA,
- KEY,
- NBWINS
+ CAL,
+ APP,
+ TOD,
+ NOT,
+ STA,
+ KEY,
+ NBWINS
};
/* General configuration variables. */
struct conf {
- unsigned auto_save;
- unsigned auto_gc;
- unsigned periodic_save;
- unsigned confirm_quit;
- unsigned confirm_delete;
- enum win default_panel;
- unsigned compact_panels;
- unsigned system_dialogs;
- unsigned progress_bar;
- const char *editor;
- const char *pager;
- char output_datefmt[BUFSIZ]; /* format for displaying date */
- int input_datefmt; /* format for reading date */
+ unsigned auto_save;
+ unsigned auto_gc;
+ unsigned periodic_save;
+ unsigned confirm_quit;
+ unsigned confirm_delete;
+ enum win default_panel;
+ unsigned compact_panels;
+ unsigned system_dialogs;
+ unsigned progress_bar;
+ const char *editor;
+ const char *pager;
+ char output_datefmt[BUFSIZ]; /* format for displaying date */
+ int input_datefmt; /* format for reading date */
};
/* Daemon-related configuration. */
struct dmon_conf {
- unsigned enable; /* launch daemon automatically when exiting */
- unsigned log; /* log daemon activity */
+ unsigned enable; /* launch daemon automatically when exiting */
+ unsigned log; /* log daemon activity */
};
/* Input date formats. */
enum datefmt {
- DATEFMT_MMDDYYYY = 1,
- DATEFMT_DDMMYYYY,
- DATEFMT_YYYYMMDD,
- DATEFMT_ISO,
- DATEFMT_MAX
+ DATEFMT_MMDDYYYY = 1,
+ DATEFMT_DDMMYYYY,
+ DATEFMT_YYYYMMDD,
+ DATEFMT_ISO,
+ DATEFMT_MAX
};
#define DATE_FORMATS (DATEFMT_MAX - 1)
@@ -286,179 +286,179 @@ enum datefmt {
(datefmt == DATEFMT_YYYYMMDD ? _("yyyy/mm/dd") : _("yyyy-mm-dd"))))
struct date {
- unsigned dd;
- unsigned mm;
- unsigned yyyy;
+ unsigned dd;
+ unsigned mm;
+ unsigned yyyy;
};
/* Appointment definition. */
struct apoint {
- long start; /* seconds since 1 jan 1970 */
- long dur; /* duration of the appointment in seconds */
+ long start; /* seconds since 1 jan 1970 */
+ long dur; /* duration of the appointment in seconds */
#define APOINT_NULL 0x0
-#define APOINT_NOTIFY 0x1 /* Item needs to be notified */
-#define APOINT_NOTIFIED 0x2 /* Item was already notified */
- int state;
+#define APOINT_NOTIFY 0x1 /* Item needs to be notified */
+#define APOINT_NOTIFIED 0x2 /* Item was already notified */
+ int state;
- char *mesg;
- char *note;
+ char *mesg;
+ char *note;
};
/* Event definition. */
struct event {
- int id; /* event identifier */
- long day; /* seconds since 1 jan 1970 */
- char *mesg;
- char *note;
+ int id; /* event identifier */
+ long day; /* seconds since 1 jan 1970 */
+ char *mesg;
+ char *note;
};
/* Todo item definition. */
struct todo {
- char *mesg;
- int id;
- char *note;
+ char *mesg;
+ int id;
+ char *note;
};
/* Number of items in current day. */
struct day_items_nb {
- unsigned nb_events;
- unsigned nb_apoints;
+ unsigned nb_events;
+ unsigned nb_apoints;
};
struct excp {
- long st; /* beggining of the considered day, in seconds */
+ long st; /* beggining of the considered day, in seconds */
};
enum recur_type {
- RECUR_NO,
- RECUR_DAILY,
- RECUR_WEEKLY,
- RECUR_MONTHLY,
- RECUR_YEARLY,
- RECUR_TYPES
+ RECUR_NO,
+ RECUR_DAILY,
+ RECUR_WEEKLY,
+ RECUR_MONTHLY,
+ RECUR_YEARLY,
+ RECUR_TYPES
};
/* To describe an item's repetition. */
struct rpt {
- enum recur_type type; /* repetition type */
- int freq; /* repetition frequence */
- long until; /* ending date for repeated event */
+ enum recur_type type; /* repetition type */
+ int freq; /* repetition frequence */
+ long until; /* ending date for repeated event */
};
/* Recurrent appointment definition. */
struct recur_apoint {
- struct rpt *rpt; /* information about repetition */
- llist_t exc; /* days when the item should not be repeated */
- long start; /* beggining of the appointment */
- long dur; /* duration of the appointment */
- char state; /* 8 bits to store item state */
- char *mesg; /* appointment description */
- char *note; /* note attached to appointment */
+ struct rpt *rpt; /* information about repetition */
+ llist_t exc; /* days when the item should not be repeated */
+ long start; /* beggining of the appointment */
+ long dur; /* duration of the appointment */
+ char state; /* 8 bits to store item state */
+ char *mesg; /* appointment description */
+ char *note; /* note attached to appointment */
};
/* Reccurent event definition. */
struct recur_event {
- struct rpt *rpt; /* information about repetition */
- llist_t exc; /* days when the item should not be repeated */
- int id; /* event type */
- long day; /* day at which event occurs */
- char *mesg; /* event description */
- char *note; /* note attached to event */
+ struct rpt *rpt; /* information about repetition */
+ llist_t exc; /* days when the item should not be repeated */
+ int id; /* event type */
+ long day; /* day at which event occurs */
+ char *mesg; /* event description */
+ char *note; /* note attached to event */
};
/* Generic pointer data type for appointments and events. */
union aptev_ptr {
- struct apoint *apt;
- struct event *ev;
- struct recur_apoint *rapt;
- struct recur_event *rev;
+ struct apoint *apt;
+ struct event *ev;
+ struct recur_apoint *rapt;
+ struct recur_event *rev;
};
/* Generic item description (to hold appointments, events...). */
struct day_item {
- int type; /* (recursive or normal) event or appointment */
- long start; /* start time of the repetition occurrence */
- union aptev_ptr item; /* pointer to the actual item */
+ int type; /* (recursive or normal) event or appointment */
+ long start; /* start time of the repetition occurrence */
+ union aptev_ptr item; /* pointer to the actual item */
};
/* Available view for the calendar panel. */
enum {
- CAL_MONTH_VIEW,
- CAL_WEEK_VIEW,
- CAL_VIEWS
+ CAL_MONTH_VIEW,
+ CAL_WEEK_VIEW,
+ CAL_VIEWS
};
struct notify_app {
- long time;
- int got_app;
- char *txt;
- char state;
- pthread_mutex_t mutex;
+ long time;
+ int got_app;
+ char *txt;
+ char state;
+ pthread_mutex_t mutex;
};
struct io_file {
- FILE *fd;
- char name[BUFSIZ];
+ FILE *fd;
+ char name[BUFSIZ];
};
/* Available keys. */
enum key {
- KEY_GENERIC_CANCEL,
- KEY_GENERIC_SELECT,
- KEY_GENERIC_CREDITS,
- KEY_GENERIC_HELP,
- KEY_GENERIC_QUIT,
- KEY_GENERIC_SAVE,
- KEY_GENERIC_COPY,
- KEY_GENERIC_PASTE,
- KEY_GENERIC_CHANGE_VIEW,
- KEY_GENERIC_IMPORT,
- KEY_GENERIC_EXPORT,
- KEY_GENERIC_GOTO,
- KEY_GENERIC_OTHER_CMD,
- KEY_GENERIC_CONFIG_MENU,
- KEY_GENERIC_REDRAW,
- KEY_GENERIC_ADD_APPT,
- KEY_GENERIC_ADD_TODO,
- KEY_GENERIC_PREV_DAY,
- KEY_GENERIC_NEXT_DAY,
- KEY_GENERIC_PREV_WEEK,
- KEY_GENERIC_NEXT_WEEK,
- KEY_GENERIC_PREV_MONTH,
- KEY_GENERIC_NEXT_MONTH,
- KEY_GENERIC_PREV_YEAR,
- KEY_GENERIC_NEXT_YEAR,
- KEY_GENERIC_SCROLL_DOWN,
- KEY_GENERIC_SCROLL_UP,
- KEY_GENERIC_GOTO_TODAY,
-
- KEY_MOVE_RIGHT,
- KEY_MOVE_LEFT,
- KEY_MOVE_DOWN,
- KEY_MOVE_UP,
- KEY_START_OF_WEEK,
- KEY_END_OF_WEEK,
- KEY_ADD_ITEM,
- KEY_DEL_ITEM,
- KEY_EDIT_ITEM,
- KEY_VIEW_ITEM,
- KEY_PIPE_ITEM,
- KEY_FLAG_ITEM,
- KEY_REPEAT_ITEM,
- KEY_EDIT_NOTE,
- KEY_VIEW_NOTE,
- KEY_RAISE_PRIORITY,
- KEY_LOWER_PRIORITY,
-
- NBKEYS,
- KEY_UNDEF
+ KEY_GENERIC_CANCEL,
+ KEY_GENERIC_SELECT,
+ KEY_GENERIC_CREDITS,
+ KEY_GENERIC_HELP,
+ KEY_GENERIC_QUIT,
+ KEY_GENERIC_SAVE,
+ KEY_GENERIC_COPY,
+ KEY_GENERIC_PASTE,
+ KEY_GENERIC_CHANGE_VIEW,
+ KEY_GENERIC_IMPORT,
+ KEY_GENERIC_EXPORT,
+ KEY_GENERIC_GOTO,
+ KEY_GENERIC_OTHER_CMD,
+ KEY_GENERIC_CONFIG_MENU,
+ KEY_GENERIC_REDRAW,
+ KEY_GENERIC_ADD_APPT,
+ KEY_GENERIC_ADD_TODO,
+ KEY_GENERIC_PREV_DAY,
+ KEY_GENERIC_NEXT_DAY,
+ KEY_GENERIC_PREV_WEEK,
+ KEY_GENERIC_NEXT_WEEK,
+ KEY_GENERIC_PREV_MONTH,
+ KEY_GENERIC_NEXT_MONTH,
+ KEY_GENERIC_PREV_YEAR,
+ KEY_GENERIC_NEXT_YEAR,
+ KEY_GENERIC_SCROLL_DOWN,
+ KEY_GENERIC_SCROLL_UP,
+ KEY_GENERIC_GOTO_TODAY,
+
+ KEY_MOVE_RIGHT,
+ KEY_MOVE_LEFT,
+ KEY_MOVE_DOWN,
+ KEY_MOVE_UP,
+ KEY_START_OF_WEEK,
+ KEY_END_OF_WEEK,
+ KEY_ADD_ITEM,
+ KEY_DEL_ITEM,
+ KEY_EDIT_ITEM,
+ KEY_VIEW_ITEM,
+ KEY_PIPE_ITEM,
+ KEY_FLAG_ITEM,
+ KEY_REPEAT_ITEM,
+ KEY_EDIT_NOTE,
+ KEY_VIEW_NOTE,
+ KEY_RAISE_PRIORITY,
+ KEY_LOWER_PRIORITY,
+
+ NBKEYS,
+ KEY_UNDEF
};
/* To describe a key binding. */
struct binding {
- char *label;
- enum key action;
+ char *label;
+ enum key action;
};
#define FLAG_CAL (1 << CAL)
@@ -485,122 +485,122 @@ struct binding {
pthread_cleanup_pop(0);
enum ui_mode {
- UI_CURSES,
- UI_CMDLINE,
- UI_MODES
+ UI_CURSES,
+ UI_CMDLINE,
+ UI_MODES
};
/* Generic window structure. */
struct window {
- WINDOW *p; /* pointer to window */
- unsigned w; /* width */
- unsigned h; /* height */
- int x; /* x position */
- int y; /* y position */
+ WINDOW *p; /* pointer to window */
+ unsigned w; /* width */
+ unsigned h; /* height */
+ int x; /* x position */
+ int y; /* y position */
};
/* Generic scrolling window structure. */
struct scrollwin {
- struct window win;
- struct window pad;
- unsigned first_visible_line;
- unsigned total_lines;
- const char *label;
+ struct window win;
+ struct window pad;
+ unsigned first_visible_line;
+ unsigned total_lines;
+ const char *label;
};
/* Pad structure to handle scrolling. */
struct pad {
- int width;
- int length;
- int first_onscreen; /* first line to be displayed inside window */
- WINDOW *ptrwin; /* pointer to the pad window */
+ int width;
+ int length;
+ int first_onscreen; /* first line to be displayed inside window */
+ WINDOW *ptrwin; /* pointer to the pad window */
};
/* Notification bar definition. */
struct nbar {
- unsigned show; /* display or hide the notify-bar */
- int cntdwn; /* warn when time left before next app
- becomes lesser than cntdwn */
- char datefmt[BUFSIZ]; /* format for displaying date */
- char timefmt[BUFSIZ]; /* format for displaying time */
- char cmd[BUFSIZ]; /* notification command */
- const char *shell; /* user shell to launch notif. cmd */
- unsigned notify_all; /* notify all appointments */
- pthread_mutex_t mutex;
+ unsigned show; /* display or hide the notify-bar */
+ int cntdwn; /* warn when time left before next app
+ becomes lesser than cntdwn */
+ char datefmt[BUFSIZ]; /* format for displaying date */
+ char timefmt[BUFSIZ]; /* format for displaying time */
+ char cmd[BUFSIZ]; /* notification command */
+ const char *shell; /* user shell to launch notif. cmd */
+ unsigned notify_all; /* notify all appointments */
+ pthread_mutex_t mutex;
};
/* Available types of items. */
enum item_type {
- RECUR_EVNT = 1,
- EVNT,
- RECUR_APPT,
- APPT,
- MAX_TYPES = APPT
+ RECUR_EVNT = 1,
+ EVNT,
+ RECUR_APPT,
+ APPT,
+ MAX_TYPES = APPT
};
/* Return codes for the getstring() function. */
enum getstr {
- GETSTRING_VALID,
- GETSTRING_ESC, /* user pressed escape to cancel editing. */
- GETSTRING_RET /* return was pressed without entering any text. */
+ GETSTRING_VALID,
+ GETSTRING_ESC, /* user pressed escape to cancel editing. */
+ GETSTRING_RET /* return was pressed without entering any text. */
};
/* Week days. */
enum wday {
- SUNDAY,
- MONDAY,
- TUESDAY,
- WEDNESDAY,
- THURSDAY,
- FRIDAY,
- SATURDAY,
- WDAYS
+ SUNDAY,
+ MONDAY,
+ TUESDAY,
+ WEDNESDAY,
+ THURSDAY,
+ FRIDAY,
+ SATURDAY,
+ WDAYS
};
/* Possible movements inside calendar. */
enum move {
- DAY_PREV,
- DAY_NEXT,
- WEEK_PREV,
- WEEK_NEXT,
- WEEK_START,
- WEEK_END,
- MONTH_PREV,
- MONTH_NEXT,
- YEAR_PREV,
- YEAR_NEXT
+ DAY_PREV,
+ DAY_NEXT,
+ WEEK_PREV,
+ WEEK_NEXT,
+ WEEK_START,
+ WEEK_END,
+ MONTH_PREV,
+ MONTH_NEXT,
+ YEAR_PREV,
+ YEAR_NEXT
};
/* Available color pairs. */
enum {
- COLR_RED = 1,
- COLR_GREEN,
- COLR_YELLOW,
- COLR_BLUE,
- COLR_MAGENTA,
- COLR_CYAN,
- COLR_DEFAULT,
- COLR_HIGH,
- COLR_CUSTOM
+ COLR_RED = 1,
+ COLR_GREEN,
+ COLR_YELLOW,
+ COLR_BLUE,
+ COLR_MAGENTA,
+ COLR_CYAN,
+ COLR_DEFAULT,
+ COLR_HIGH,
+ COLR_CUSTOM
};
/* Available import types. */
enum import_type {
- IO_IMPORT_ICAL,
- IO_IMPORT_NBTYPES
+ IO_IMPORT_ICAL,
+ IO_IMPORT_NBTYPES
};
/* Available export types. */
enum export_type {
- IO_EXPORT_ICAL,
- IO_EXPORT_PCAL,
- IO_EXPORT_NBTYPES
+ IO_EXPORT_ICAL,
+ IO_EXPORT_PCAL,
+ IO_EXPORT_NBTYPES
};
/* To customize the display when saving data. */
enum save_display {
- IO_SAVE_DISPLAY_BAR,
- IO_SAVE_DISPLAY_NONE
+ IO_SAVE_DISPLAY_BAR,
+ IO_SAVE_DISPLAY_NONE
};
/* apoint.c */
@@ -687,7 +687,7 @@ int day_store_items(long, unsigned *, unsigned *, regex_t *);
struct day_items_nb day_process_storage(struct date *, unsigned);
void day_write_pad(long, int, int, int);
void day_write_stdout(long, const char *, const char *, const char *,
- const char *);
+ const char *);
void day_popup_item(struct day_item *);
int day_check_if_item(struct date);
unsigned day_chk_busy_slices(struct date, int, int *);
@@ -726,7 +726,7 @@ int updatestring(WINDOW *, char **, int, int);
/* ical.c */
void ical_import_data(FILE *, FILE *, unsigned *, unsigned *, unsigned *,
- unsigned *, unsigned *);
+ unsigned *, unsigned *);
void ical_export_data(FILE *);
/* interaction.c */
@@ -789,7 +789,7 @@ const char *keys_action_firstkey(enum key);
const char *keys_action_nkey(enum key, int);
char *keys_action_allkeys(enum key);
void keys_display_bindings_bar(WINDOW *, struct binding *[], int, int,
- int, struct binding *);
+ int, struct binding *);
void keys_popup_info(enum key);
void keys_save_bindings(FILE *);
int keys_check_missing_bindings(void);
@@ -875,23 +875,25 @@ void recur_apoint_llist_init(void);
void recur_apoint_llist_free(void);
void recur_event_llist_free(void);
struct recur_apoint *recur_apoint_new(char *, char *, long, long, char,
- int, int, long, llist_t *);
+ int, int, long, llist_t *);
struct recur_event *recur_event_new(char *, char *, long, int, int, int,
- long, llist_t *);
+ long, llist_t *);
char recur_def2char(enum recur_type);
int recur_char2def(char);
struct recur_apoint *recur_apoint_scan(FILE *, struct tm, struct tm,
- char, int, struct tm, char *,
- llist_t *, char);
+ char, int, struct tm, char *,
+ llist_t *, char);
struct recur_event *recur_event_scan(FILE *, struct tm, int, char,
- int, struct tm, char *, llist_t *);
+ int, struct tm, char *, llist_t *);
void recur_apoint_write(struct recur_apoint *, FILE *);
void recur_event_write(struct recur_event *, FILE *);
void recur_save_data(FILE *);
unsigned recur_item_find_occurrence(long, long, llist_t *, int,
- int, long, long, unsigned *);
-unsigned recur_apoint_find_occurrence(struct recur_apoint *, long, unsigned *);
-unsigned recur_event_find_occurrence(struct recur_event *, long, unsigned *);
+ int, long, long, unsigned *);
+unsigned recur_apoint_find_occurrence(struct recur_apoint *, long,
+ unsigned *);
+unsigned recur_event_find_occurrence(struct recur_event *, long,
+ unsigned *);
unsigned recur_item_inday(long, long, llist_t *, int, int, long, long);
unsigned recur_apoint_inday(struct recur_apoint *, long *);
unsigned recur_event_inday(struct recur_event *, long *);
@@ -900,7 +902,8 @@ void recur_apoint_add_exc(struct recur_apoint *, long);
void recur_event_erase(struct recur_event *);
void recur_apoint_erase(struct recur_apoint *);
void recur_exc_scan(llist_t *, FILE *);
-struct notify_app *recur_apoint_check_next(struct notify_app *, long, long);
+struct notify_app *recur_apoint_check_next(struct notify_app *, long,
+ long);
void recur_apoint_switch_notify(struct recur_apoint *);
void recur_event_paste_item(struct recur_event *, long);
void recur_apoint_paste_item(struct recur_apoint *, long);
@@ -975,7 +978,8 @@ void print_bool_option_incolor(WINDOW *, unsigned, int, int);
const char *get_tempdir(void);
char *new_tempfile(const char *, int);
int check_date(unsigned, unsigned, unsigned);
-int parse_date(const char *, enum datefmt, int *, int *, int *, struct date *);
+int parse_date(const char *, enum datefmt, int *, int *, int *,
+ struct date *);
int check_time(unsigned, unsigned);
int parse_time(const char *, unsigned *, unsigned *);
int parse_duration(const char *, unsigned *);
@@ -987,7 +991,8 @@ int child_wait(int *, int *, int);
void press_any_key(void);
void print_apoint(const char *, long, struct apoint *);
void print_event(const char *, long, struct event *);
-void print_recur_apoint(const char *, long, unsigned, struct recur_apoint *);
+void print_recur_apoint(const char *, long, unsigned,
+ struct recur_apoint *);
void print_recur_event(const char *, long, struct recur_event *);
void print_todo(const char *, struct todo *);
diff --git a/src/config.c b/src/config.c
index 083b9cf..39ac338 100644
--- a/src/config.c
+++ b/src/config.c
@@ -43,10 +43,10 @@ typedef int (*config_fn_parse_t) (void *, const char *);
typedef int (*config_fn_serialize_t) (char *, void *);
struct confvar {
- const char *key;
- config_fn_parse_t fn_parse;
- config_fn_serialize_t fn_serialize;
- void *target;
+ const char *key;
+ config_fn_parse_t fn_parse;
+ config_fn_serialize_t fn_serialize;
+ void *target;
};
static int config_parse_bool(unsigned *, const char *);
@@ -84,42 +84,35 @@ static int config_serialize_input_datefmt(char *, void *);
(config_fn_serialize_t) config_serialize_str, &(var)
static const struct confvar confmap[] = {
- {"appearance.calendarview", config_parse_calendar_view,
- config_serialize_calendar_view, NULL},
- {"appearance.compactpanels", CONFIG_HANDLER_BOOL(conf.compact_panels)},
- {"appearance.defaultpanel", config_parse_default_panel,
- config_serialize_default_panel, NULL},
- {"appearance.layout", config_parse_layout, config_serialize_layout, NULL},
- {"appearance.notifybar", CONFIG_HANDLER_BOOL(nbar.show)},
- {"appearance.sidebarwidth", config_parse_sidebar_width,
- config_serialize_sidebar_width, NULL},
- {"appearance.theme", config_parse_color_theme, config_serialize_color_theme,
- NULL},
- {"daemon.enable", CONFIG_HANDLER_BOOL(dmon.enable)},
- {"daemon.log", CONFIG_HANDLER_BOOL(dmon.log)},
- {"format.inputdate", config_parse_input_datefmt,
- config_serialize_input_datefmt, NULL},
- {"format.notifydate", CONFIG_HANDLER_STR(nbar.datefmt)},
- {"format.notifytime", CONFIG_HANDLER_STR(nbar.timefmt)},
- {"format.outputdate", config_parse_output_datefmt,
- config_serialize_output_datefmt, NULL},
- {"general.autogc", CONFIG_HANDLER_BOOL(conf.auto_gc)},
- {"general.autosave", CONFIG_HANDLER_BOOL(conf.auto_save)},
- {"general.confirmdelete", CONFIG_HANDLER_BOOL(conf.confirm_delete)},
- {"general.confirmquit", CONFIG_HANDLER_BOOL(conf.confirm_quit)},
- {"general.firstdayofweek", config_parse_first_day_of_week,
- config_serialize_first_day_of_week, NULL},
- {"general.periodicsave", CONFIG_HANDLER_UNSIGNED(conf.periodic_save)},
- {"general.progressbar", CONFIG_HANDLER_BOOL(conf.progress_bar)},
- {"general.systemdialogs", CONFIG_HANDLER_BOOL(conf.system_dialogs)},
- {"notification.command", CONFIG_HANDLER_STR(nbar.cmd)},
- {"notification.notifyall", CONFIG_HANDLER_BOOL(nbar.notify_all)},
- {"notification.warning", CONFIG_HANDLER_INT(nbar.cntdwn)}
+ {"appearance.calendarview", config_parse_calendar_view, config_serialize_calendar_view, NULL},
+ {"appearance.compactpanels", CONFIG_HANDLER_BOOL(conf.compact_panels)},
+ {"appearance.defaultpanel", config_parse_default_panel, config_serialize_default_panel, NULL},
+ {"appearance.layout", config_parse_layout, config_serialize_layout, NULL},
+ {"appearance.notifybar", CONFIG_HANDLER_BOOL(nbar.show)},
+ {"appearance.sidebarwidth", config_parse_sidebar_width, config_serialize_sidebar_width, NULL},
+ {"appearance.theme", config_parse_color_theme, config_serialize_color_theme, NULL},
+ {"daemon.enable", CONFIG_HANDLER_BOOL(dmon.enable)},
+ {"daemon.log", CONFIG_HANDLER_BOOL(dmon.log)},
+ {"format.inputdate", config_parse_input_datefmt, config_serialize_input_datefmt, NULL},
+ {"format.notifydate", CONFIG_HANDLER_STR(nbar.datefmt)},
+ {"format.notifytime", CONFIG_HANDLER_STR(nbar.timefmt)},
+ {"format.outputdate", config_parse_output_datefmt, config_serialize_output_datefmt, NULL},
+ {"general.autogc", CONFIG_HANDLER_BOOL(conf.auto_gc)},
+ {"general.autosave", CONFIG_HANDLER_BOOL(conf.auto_save)},
+ {"general.confirmdelete", CONFIG_HANDLER_BOOL(conf.confirm_delete)},
+ {"general.confirmquit", CONFIG_HANDLER_BOOL(conf.confirm_quit)},
+ {"general.firstdayofweek", config_parse_first_day_of_week, config_serialize_first_day_of_week, NULL},
+ {"general.periodicsave", CONFIG_HANDLER_UNSIGNED(conf.periodic_save)},
+ {"general.progressbar", CONFIG_HANDLER_BOOL(conf.progress_bar)},
+ {"general.systemdialogs", CONFIG_HANDLER_BOOL(conf.system_dialogs)},
+ {"notification.command", CONFIG_HANDLER_STR(nbar.cmd)},
+ {"notification.notifyall", CONFIG_HANDLER_BOOL(nbar.notify_all)},
+ {"notification.warning", CONFIG_HANDLER_INT(nbar.cntdwn)}
};
struct config_save_status {
- FILE *fp;
- int done[sizeof(confmap) / sizeof(confmap[0])];
+ FILE *fp;
+ int done[sizeof(confmap) / sizeof(confmap[0])];
};
typedef int (*config_fn_walk_cb_t) (const char *, const char *, void *);
@@ -127,207 +120,211 @@ typedef int (*config_fn_walk_junk_cb_t) (const char *, void *);
static int config_parse_bool(unsigned *dest, const char *val)
{
- if (strcmp(val, "yes") == 0)
- *dest = 1;
- else if (strcmp(val, "no") == 0)
- *dest = 0;
- else
- return 0;
+ if (strcmp(val, "yes") == 0)
+ *dest = 1;
+ else if (strcmp(val, "no") == 0)
+ *dest = 0;
+ else
+ return 0;
- return 1;
+ return 1;
}
static int config_parse_unsigned(unsigned *dest, const char *val)
{
- if (is_all_digit(val))
- *dest = atoi(val);
- else
- return 0;
+ if (is_all_digit(val))
+ *dest = atoi(val);
+ else
+ return 0;
- return 1;
+ return 1;
}
static int config_parse_int(int *dest, const char *val)
{
- if ((*val == '+' || *val == '-' || isdigit(*val)) && is_all_digit(val + 1))
- *dest = atoi(val);
- else
- return 0;
+ if ((*val == '+' || *val == '-' || isdigit(*val))
+ && is_all_digit(val + 1))
+ *dest = atoi(val);
+ else
+ return 0;
- return 1;
+ return 1;
}
static int config_parse_str(char *dest, const char *val)
{
- strncpy(dest, val, BUFSIZ);
- return 1;
+ strncpy(dest, val, BUFSIZ);
+ return 1;
}
static int config_parse_color(int *dest, const char *val)
{
- if (!strcmp(val, "black"))
- *dest = COLOR_BLACK;
- else if (!strcmp(val, "red"))
- *dest = COLOR_RED;
- else if (!strcmp(val, "green"))
- *dest = COLOR_GREEN;
- else if (!strcmp(val, "yellow"))
- *dest = COLOR_YELLOW;
- else if (!strcmp(val, "blue"))
- *dest = COLOR_BLUE;
- else if (!strcmp(val, "magenta"))
- *dest = COLOR_MAGENTA;
- else if (!strcmp(val, "cyan"))
- *dest = COLOR_CYAN;
- else if (!strcmp(val, "white"))
- *dest = COLOR_WHITE;
- else if (!strcmp(val, "default"))
- *dest = background;
- else
- return 0;
-
- return 1;
+ if (!strcmp(val, "black"))
+ *dest = COLOR_BLACK;
+ else if (!strcmp(val, "red"))
+ *dest = COLOR_RED;
+ else if (!strcmp(val, "green"))
+ *dest = COLOR_GREEN;
+ else if (!strcmp(val, "yellow"))
+ *dest = COLOR_YELLOW;
+ else if (!strcmp(val, "blue"))
+ *dest = COLOR_BLUE;
+ else if (!strcmp(val, "magenta"))
+ *dest = COLOR_MAGENTA;
+ else if (!strcmp(val, "cyan"))
+ *dest = COLOR_CYAN;
+ else if (!strcmp(val, "white"))
+ *dest = COLOR_WHITE;
+ else if (!strcmp(val, "default"))
+ *dest = background;
+ else
+ return 0;
+
+ return 1;
}
static int config_parse_color_pair(int *dest1, int *dest2, const char *val)
{
- char s1[BUFSIZ], s2[BUFSIZ];
+ char s1[BUFSIZ], s2[BUFSIZ];
- if (sscanf(val, "%s on %s", s1, s2) != 2)
- return 0;
+ if (sscanf(val, "%s on %s", s1, s2) != 2)
+ return 0;
- return (config_parse_color(dest1, s1) && config_parse_color(dest2, s2));
+ return (config_parse_color(dest1, s1)
+ && config_parse_color(dest2, s2));
}
static int config_parse_calendar_view(void *dummy, const char *val)
{
- if (!strcmp(val, "monthly"))
- ui_calendar_set_view(CAL_MONTH_VIEW);
- else if (!strcmp(val, "weekly"))
- ui_calendar_set_view(CAL_WEEK_VIEW);
- else
- return 0;
+ if (!strcmp(val, "monthly"))
+ ui_calendar_set_view(CAL_MONTH_VIEW);
+ else if (!strcmp(val, "weekly"))
+ ui_calendar_set_view(CAL_WEEK_VIEW);
+ else
+ return 0;
- return 1;
+ return 1;
}
static int config_parse_default_panel(void *dummy, const char *val)
{
- if (!strcmp(val, "calendar"))
- conf.default_panel = CAL;
- else if (!strcmp(val, "appointments"))
- conf.default_panel = APP;
- else if (!strcmp(val, "todo"))
- conf.default_panel = TOD;
- else
- return 0;
+ if (!strcmp(val, "calendar"))
+ conf.default_panel = CAL;
+ else if (!strcmp(val, "appointments"))
+ conf.default_panel = APP;
+ else if (!strcmp(val, "todo"))
+ conf.default_panel = TOD;
+ else
+ return 0;
- return 1;
+ return 1;
}
static int config_parse_first_day_of_week(void *dummy, const char *val)
{
- if (!strcmp(val, "monday"))
- ui_calendar_set_first_day_of_week(MONDAY);
- else if (!strcmp(val, "sunday"))
- ui_calendar_set_first_day_of_week(SUNDAY);
- else
- return 0;
+ if (!strcmp(val, "monday"))
+ ui_calendar_set_first_day_of_week(MONDAY);
+ else if (!strcmp(val, "sunday"))
+ ui_calendar_set_first_day_of_week(SUNDAY);
+ else
+ return 0;
- return 1;
+ return 1;
}
static int config_parse_color_theme(void *dummy, const char *val)
{
- int color1, color2;
- if (!strcmp(val, "0") || !strcmp(val, "none")) {
- colorize = 0;
- return 1;
- }
- if (!config_parse_color_pair(&color1, &color2, val))
- return 0;
- init_pair(COLR_CUSTOM, color1, color2);
- return 1;
+ int color1, color2;
+ if (!strcmp(val, "0") || !strcmp(val, "none")) {
+ colorize = 0;
+ return 1;
+ }
+ if (!config_parse_color_pair(&color1, &color2, val))
+ return 0;
+ init_pair(COLR_CUSTOM, color1, color2);
+ return 1;
}
static int config_parse_layout(void *dummy, const char *val)
{
- wins_set_layout(atoi(val));
- return 1;
+ wins_set_layout(atoi(val));
+ return 1;
}
static int config_parse_sidebar_width(void *dummy, const char *val)
{
- wins_set_sbar_width(atoi(val));
- return 1;
+ wins_set_sbar_width(atoi(val));
+ return 1;
}
static int config_parse_output_datefmt(void *dummy, const char *val)
{
- if (val[0] != '\0')
- return config_parse_str(conf.output_datefmt, val);
- return 1;
+ if (val[0] != '\0')
+ return config_parse_str(conf.output_datefmt, val);
+ return 1;
}
static int config_parse_input_datefmt(void *dummy, const char *val)
{
- if (config_parse_int(&conf.input_datefmt, val)) {
- if (conf.input_datefmt <= 0 || conf.input_datefmt > DATE_FORMATS)
- conf.input_datefmt = 1;
- return 1;
- } else {
- return 0;
- }
+ if (config_parse_int(&conf.input_datefmt, val)) {
+ if (conf.input_datefmt <= 0
+ || conf.input_datefmt > DATE_FORMATS)
+ conf.input_datefmt = 1;
+ return 1;
+ } else {
+ return 0;
+ }
}
/* Set a configuration variable. */
static int config_set_conf(const char *key, const char *value)
{
- int i;
+ int i;
- if (!key)
- return -1;
+ if (!key)
+ return -1;
- for (i = 0; i < sizeof(confmap) / sizeof(confmap[0]); i++) {
- if (!strcmp(confmap[i].key, key))
- return confmap[i].fn_parse(confmap[i].target, value);
- }
+ for (i = 0; i < sizeof(confmap) / sizeof(confmap[0]); i++) {
+ if (!strcmp(confmap[i].key, key))
+ return confmap[i].fn_parse(confmap[i].target,
+ value);
+ }
- return -1;
+ return -1;
}
static int config_serialize_bool(char *dest, unsigned *val)
{
- if (*val) {
- dest[0] = 'y';
- dest[1] = 'e';
- dest[2] = 's';
- dest[3] = '\0';
- } else {
- dest[0] = 'n';
- dest[1] = 'o';
- dest[2] = '\0';
- }
+ if (*val) {
+ dest[0] = 'y';
+ dest[1] = 'e';
+ dest[2] = 's';
+ dest[3] = '\0';
+ } else {
+ dest[0] = 'n';
+ dest[1] = 'o';
+ dest[2] = '\0';
+ }
- return 1;
+ return 1;
}
static int config_serialize_unsigned(char *dest, unsigned *val)
{
- snprintf(dest, BUFSIZ, "%u", *val);
- return 1;
+ snprintf(dest, BUFSIZ, "%u", *val);
+ return 1;
}
static int config_serialize_int(char *dest, int *val)
{
- snprintf(dest, BUFSIZ, "%d", *val);
- return 1;
+ snprintf(dest, BUFSIZ, "%d", *val);
+ return 1;
}
static int config_serialize_str(char *dest, const char *val)
{
- strncpy(dest, val, BUFSIZ);
- return 1;
+ strncpy(dest, val, BUFSIZ);
+ return 1;
}
/*
@@ -345,281 +342,290 @@ static void config_color_theme_name(char *theme_name)
#define DEFAULTCOLOR 255
#define DEFAULTCOLOR_EXT -1
- int i;
- short color[NBCOLORS];
- const char *color_name[NBCOLORS];
- const char *default_color = "default";
- const char *name[MAXCOLORS] = {
- "black",
- "red",
- "green",
- "yellow",
- "blue",
- "magenta",
- "cyan",
- "white"
- };
-
- if (!colorize) {
- strncpy(theme_name, "none", BUFSIZ);
- } else {
- pair_content(COLR_CUSTOM, &color[0], &color[1]);
- for (i = 0; i < NBCOLORS; i++) {
- if ((color[i] == DEFAULTCOLOR) || (color[i] == DEFAULTCOLOR_EXT)) {
- color_name[i] = default_color;
- } else if (color[i] >= 0 && color[i] <= MAXCOLORS) {
- color_name[i] = name[color[i]];
- } else {
- EXIT(_("unknown color"));
- /* NOTREACHED */
- }
- }
- snprintf(theme_name, BUFSIZ, "%s on %s", color_name[0], color_name[1]);
- }
+ int i;
+ short color[NBCOLORS];
+ const char *color_name[NBCOLORS];
+ const char *default_color = "default";
+ const char *name[MAXCOLORS] = {
+ "black",
+ "red",
+ "green",
+ "yellow",
+ "blue",
+ "magenta",
+ "cyan",
+ "white"
+ };
+
+ if (!colorize) {
+ strncpy(theme_name, "none", BUFSIZ);
+ } else {
+ pair_content(COLR_CUSTOM, &color[0], &color[1]);
+ for (i = 0; i < NBCOLORS; i++) {
+ if ((color[i] == DEFAULTCOLOR)
+ || (color[i] == DEFAULTCOLOR_EXT)) {
+ color_name[i] = default_color;
+ } else if (color[i] >= 0 && color[i] <= MAXCOLORS) {
+ color_name[i] = name[color[i]];
+ } else {
+ EXIT(_("unknown color"));
+ /* NOTREACHED */
+ }
+ }
+ snprintf(theme_name, BUFSIZ, "%s on %s", color_name[0],
+ color_name[1]);
+ }
}
static int config_serialize_calendar_view(char *buf, void *dummy)
{
- if (ui_calendar_get_view() == CAL_WEEK_VIEW)
- strcpy(buf, "weekly");
- else
- strcpy(buf, "monthly");
+ if (ui_calendar_get_view() == CAL_WEEK_VIEW)
+ strcpy(buf, "weekly");
+ else
+ strcpy(buf, "monthly");
- return 1;
+ return 1;
}
static int config_serialize_default_panel(char *buf, void *dummy)
{
- if (conf.default_panel == CAL)
- strcpy(buf, "calendar");
- else if (conf.default_panel == APP)
- strcpy(buf, "appointments");
- else
- strcpy(buf, "todo");
+ if (conf.default_panel == CAL)
+ strcpy(buf, "calendar");
+ else if (conf.default_panel == APP)
+ strcpy(buf, "appointments");
+ else
+ strcpy(buf, "todo");
- return 1;
+ return 1;
}
static int config_serialize_first_day_of_week(char *buf, void *dummy)
{
- if (ui_calendar_week_begins_on_monday())
- strcpy(buf, "monday");
- else
- strcpy(buf, "sunday");
+ if (ui_calendar_week_begins_on_monday())
+ strcpy(buf, "monday");
+ else
+ strcpy(buf, "sunday");
- return 1;
+ return 1;
}
static int config_serialize_color_theme(char *buf, void *dummy)
{
- config_color_theme_name(buf);
- return 1;
+ config_color_theme_name(buf);
+ return 1;
}
static int config_serialize_layout(char *buf, void *dummy)
{
- int tmp = wins_layout();
- return config_serialize_int(buf, &tmp);
+ int tmp = wins_layout();
+ return config_serialize_int(buf, &tmp);
}
static int config_serialize_sidebar_width(char *buf, void *dummy)
{
- int tmp = wins_sbar_wperc();
- return config_serialize_int(buf, &tmp);
+ int tmp = wins_sbar_wperc();
+ return config_serialize_int(buf, &tmp);
}
static int config_serialize_output_datefmt(char *buf, void *dummy)
{
- return config_serialize_str(buf, conf.output_datefmt);
+ return config_serialize_str(buf, conf.output_datefmt);
}
static int config_serialize_input_datefmt(char *buf, void *dummy)
{
- return config_serialize_int(buf, &conf.input_datefmt);
+ return config_serialize_int(buf, &conf.input_datefmt);
}
/* Serialize the value of a configuration variable. */
static int
config_serialize_conf(char *buf, const char *key,
- struct config_save_status *status)
+ struct config_save_status *status)
{
- int i;
+ int i;
- if (!key)
- return -1;
+ if (!key)
+ return -1;
- for (i = 0; i < sizeof(confmap) / sizeof(confmap[0]); i++) {
- if (!strcmp(confmap[i].key, key)) {
- if (confmap[i].fn_serialize(buf, confmap[i].target)) {
- if (status)
- status->done[i] = 1;
- return 1;
- } else {
- return 0;
- }
- }
- }
+ for (i = 0; i < sizeof(confmap) / sizeof(confmap[0]); i++) {
+ if (!strcmp(confmap[i].key, key)) {
+ if (confmap[i].
+ fn_serialize(buf, confmap[i].target)) {
+ if (status)
+ status->done[i] = 1;
+ return 1;
+ } else {
+ return 0;
+ }
+ }
+ }
- return -1;
+ return -1;
}
static void
config_file_walk(config_fn_walk_cb_t fn_cb,
- config_fn_walk_junk_cb_t fn_junk_cb, void *data)
-{
- FILE *data_file;
- char buf[BUFSIZ], e_conf[BUFSIZ];
- char *key, *value;
-
- data_file = fopen(path_conf, "r");
- EXIT_IF(data_file == NULL, _("failed to open configuration file"));
-
- pthread_mutex_lock(&nbar.mutex);
- for (;;) {
- if (fgets(buf, sizeof buf, data_file) == NULL)
- break;
- io_extract_data(e_conf, buf, sizeof buf);
-
- if (*e_conf == '\0') {
- if (fn_junk_cb)
- fn_junk_cb(buf, data);
- continue;
- }
-
- key = e_conf;
- value = strchr(e_conf, '=');
- if (value) {
- *value = '\0';
- value++;
- } else {
- EXIT(_("invalid configuration directive: \"%s\""), e_conf);
- }
-
- if (strcmp(key, "auto_save") == 0 ||
- strcmp(key, "auto_gc") == 0 ||
- strcmp(key, "periodic_save") == 0 ||
- strcmp(key, "confirm_quit") == 0 ||
- strcmp(key, "confirm_delete") == 0 ||
- strcmp(key, "skip_system_dialogs") == 0 ||
- strcmp(key, "skip_progress_bar") == 0 ||
- strcmp(key, "calendar_default_view") == 0 ||
- strcmp(key, "week_begins_on_monday") == 0 ||
- strcmp(key, "color-theme") == 0 ||
- strcmp(key, "layout") == 0 ||
- strcmp(key, "side-bar_width") == 0 ||
- strcmp(key, "notify-bar_show") == 0 ||
- strcmp(key, "notify-bar_date") == 0 ||
- strcmp(key, "notify-bar_clock") == 0 ||
- strcmp(key, "notify-bar_warning") == 0 ||
- strcmp(key, "notify-bar_command") == 0 ||
- strcmp(key, "notify-all") == 0 ||
- strcmp(key, "output_datefmt") == 0 ||
- strcmp(key, "input_datefmt") == 0 ||
- strcmp(key, "notify-daemon_enable") == 0 ||
- strcmp(key, "notify-daemon_log") == 0) {
- WARN_MSG(_("Pre-3.0.0 configuration file format detected, "
- "please upgrade running `calcurse-upgrade`."));
- }
-
- if (value && (*value == '\0' || *value == '\n')) {
- /* Backward compatibility mode. */
- if (fgets(buf, sizeof buf, data_file) == NULL)
- break;
- io_extract_data(e_conf, buf, sizeof buf);
- value = e_conf;
- }
-
- fn_cb(key, value, data);
- }
- file_close(data_file, __FILE_POS__);
- pthread_mutex_unlock(&nbar.mutex);
+ config_fn_walk_junk_cb_t fn_junk_cb, void *data)
+{
+ FILE *data_file;
+ char buf[BUFSIZ], e_conf[BUFSIZ];
+ char *key, *value;
+
+ data_file = fopen(path_conf, "r");
+ EXIT_IF(data_file == NULL, _("failed to open configuration file"));
+
+ pthread_mutex_lock(&nbar.mutex);
+ for (;;) {
+ if (fgets(buf, sizeof buf, data_file) == NULL)
+ break;
+ io_extract_data(e_conf, buf, sizeof buf);
+
+ if (*e_conf == '\0') {
+ if (fn_junk_cb)
+ fn_junk_cb(buf, data);
+ continue;
+ }
+
+ key = e_conf;
+ value = strchr(e_conf, '=');
+ if (value) {
+ *value = '\0';
+ value++;
+ } else {
+ EXIT(_("invalid configuration directive: \"%s\""),
+ e_conf);
+ }
+
+ if (strcmp(key, "auto_save") == 0 ||
+ strcmp(key, "auto_gc") == 0 ||
+ strcmp(key, "periodic_save") == 0 ||
+ strcmp(key, "confirm_quit") == 0 ||
+ strcmp(key, "confirm_delete") == 0 ||
+ strcmp(key, "skip_system_dialogs") == 0 ||
+ strcmp(key, "skip_progress_bar") == 0 ||
+ strcmp(key, "calendar_default_view") == 0 ||
+ strcmp(key, "week_begins_on_monday") == 0 ||
+ strcmp(key, "color-theme") == 0 ||
+ strcmp(key, "layout") == 0 ||
+ strcmp(key, "side-bar_width") == 0 ||
+ strcmp(key, "notify-bar_show") == 0 ||
+ strcmp(key, "notify-bar_date") == 0 ||
+ strcmp(key, "notify-bar_clock") == 0 ||
+ strcmp(key, "notify-bar_warning") == 0 ||
+ strcmp(key, "notify-bar_command") == 0 ||
+ strcmp(key, "notify-all") == 0 ||
+ strcmp(key, "output_datefmt") == 0 ||
+ strcmp(key, "input_datefmt") == 0 ||
+ strcmp(key, "notify-daemon_enable") == 0 ||
+ strcmp(key, "notify-daemon_log") == 0) {
+ WARN_MSG(_("Pre-3.0.0 configuration file format detected, "
+ "please upgrade running `calcurse-upgrade`."));
+ }
+
+ if (value && (*value == '\0' || *value == '\n')) {
+ /* Backward compatibility mode. */
+ if (fgets(buf, sizeof buf, data_file) == NULL)
+ break;
+ io_extract_data(e_conf, buf, sizeof buf);
+ value = e_conf;
+ }
+
+ fn_cb(key, value, data);
+ }
+ file_close(data_file, __FILE_POS__);
+ pthread_mutex_unlock(&nbar.mutex);
}
static int config_load_cb(const char *key, const char *value, void *dummy)
{
- int result = config_set_conf(key, value);
+ int result = config_set_conf(key, value);
- if (result < 0) {
- EXIT(_("configuration variable unknown: \"%s\""), key);
- /* NOTREACHED */
- } else if (result == 0) {
- EXIT(_("wrong configuration variable format for \"%s\""), key);
- /* NOTREACHED */
- }
+ if (result < 0) {
+ EXIT(_("configuration variable unknown: \"%s\""), key);
+ /* NOTREACHED */
+ } else if (result == 0) {
+ EXIT(_("wrong configuration variable format for \"%s\""),
+ key);
+ /* NOTREACHED */
+ }
- return 1;
+ return 1;
}
/* Load the user configuration. */
void config_load(void)
{
- config_file_walk(config_load_cb, NULL, NULL);
+ config_file_walk(config_load_cb, NULL, NULL);
}
static int config_save_cb(const char *key, const char *value, void *status)
{
- char buf[BUFSIZ];
- int result =
- config_serialize_conf(buf, key, (struct config_save_status *)status);
+ char buf[BUFSIZ];
+ int result =
+ config_serialize_conf(buf, key,
+ (struct config_save_status *)status);
- if (result < 0) {
- EXIT(_("configuration variable unknown: \"%s\""), key);
- /* NOTREACHED */
- } else if (result == 0) {
- EXIT(_("wrong configuration variable format for \"%s\""), key);
- /* NOTREACHED */
- }
+ if (result < 0) {
+ EXIT(_("configuration variable unknown: \"%s\""), key);
+ /* NOTREACHED */
+ } else if (result == 0) {
+ EXIT(_("wrong configuration variable format for \"%s\""),
+ key);
+ /* NOTREACHED */
+ }
- fputs(key, ((struct config_save_status *)status)->fp);
- fputc('=', ((struct config_save_status *)status)->fp);
- fputs(buf, ((struct config_save_status *)status)->fp);
- fputc('\n', ((struct config_save_status *)status)->fp);
+ fputs(key, ((struct config_save_status *)status)->fp);
+ fputc('=', ((struct config_save_status *)status)->fp);
+ fputs(buf, ((struct config_save_status *)status)->fp);
+ fputc('\n', ((struct config_save_status *)status)->fp);
- return 1;
+ return 1;
}
static int config_save_junk_cb(const char *data, void *status)
{
- fputs(data, ((struct config_save_status *)status)->fp);
- return 1;
+ fputs(data, ((struct config_save_status *)status)->fp);
+ return 1;
}
/* Save the user configuration. */
unsigned config_save(void)
{
- char tmppath[BUFSIZ];
- char *tmpext;
- struct config_save_status status;
- int i;
+ char tmppath[BUFSIZ];
+ char *tmpext;
+ struct config_save_status status;
+ int i;
- if (read_only)
- return 1;
+ if (read_only)
+ return 1;
- strncpy(tmppath, get_tempdir(), BUFSIZ);
- strncat(tmppath, "/" CONF_PATH_NAME ".", BUFSIZ - strlen(tmppath) - 1);
- if ((tmpext = new_tempfile(tmppath, TMPEXTSIZ)) == NULL)
- return 0;
- strncat(tmppath, tmpext, BUFSIZ - strlen(tmppath) - 1);
- mem_free(tmpext);
+ strncpy(tmppath, get_tempdir(), BUFSIZ);
+ strncat(tmppath, "/" CONF_PATH_NAME ".",
+ BUFSIZ - strlen(tmppath) - 1);
+ if ((tmpext = new_tempfile(tmppath, TMPEXTSIZ)) == NULL)
+ return 0;
+ strncat(tmppath, tmpext, BUFSIZ - strlen(tmppath) - 1);
+ mem_free(tmpext);
- status.fp = fopen(tmppath, "w");
- if (!status.fp)
- return 0;
+ status.fp = fopen(tmppath, "w");
+ if (!status.fp)
+ return 0;
- memset(status.done, 0, sizeof(status.done));
+ memset(status.done, 0, sizeof(status.done));
- config_file_walk(config_save_cb, config_save_junk_cb, (void *)&status);
+ config_file_walk(config_save_cb, config_save_junk_cb,
+ (void *)&status);
- /* Set variables that were missing from the configuration file. */
- for (i = 0; i < sizeof(confmap) / sizeof(confmap[0]); i++) {
- if (!status.done[i])
- config_save_cb(confmap[i].key, NULL, &status);
- }
+ /* Set variables that were missing from the configuration file. */
+ for (i = 0; i < sizeof(confmap) / sizeof(confmap[0]); i++) {
+ if (!status.done[i])
+ config_save_cb(confmap[i].key, NULL, &status);
+ }
- file_close(status.fp, __FILE_POS__);
+ file_close(status.fp, __FILE_POS__);
- if (io_file_cp(tmppath, path_conf))
- unlink(tmppath);
+ if (io_file_cp(tmppath, path_conf))
+ unlink(tmppath);
- return 1;
+ return 1;
}
diff --git a/src/custom.c b/src/custom.c
index 6f573c5..6ae8abc 100644
--- a/src/custom.c
+++ b/src/custom.c
@@ -42,8 +42,8 @@
#include "calcurse.h"
struct attribute {
- int color[7];
- int nocolor[7];
+ int color[7];
+ int nocolor[7];
};
static struct attribute attr;
@@ -58,225 +58,230 @@ static struct attribute attr;
*/
void custom_init_attr(void)
{
- attr.color[ATTR_HIGHEST] = COLOR_PAIR(COLR_CUSTOM);
- attr.color[ATTR_HIGH] = COLOR_PAIR(COLR_HIGH);
- attr.color[ATTR_MIDDLE] = COLOR_PAIR(COLR_RED);
- attr.color[ATTR_LOW] = COLOR_PAIR(COLR_CYAN);
- attr.color[ATTR_LOWEST] = COLOR_PAIR(COLR_YELLOW);
- attr.color[ATTR_TRUE] = COLOR_PAIR(COLR_GREEN);
- attr.color[ATTR_FALSE] = COLOR_PAIR(COLR_RED);
-
- attr.nocolor[ATTR_HIGHEST] = A_BOLD;
- attr.nocolor[ATTR_HIGH] = A_REVERSE;
- attr.nocolor[ATTR_MIDDLE] = A_REVERSE;
- attr.nocolor[ATTR_LOW] = A_UNDERLINE;
- attr.nocolor[ATTR_LOWEST] = A_BOLD;
- attr.nocolor[ATTR_TRUE] = A_BOLD;
- attr.nocolor[ATTR_FALSE] = A_DIM;
+ attr.color[ATTR_HIGHEST] = COLOR_PAIR(COLR_CUSTOM);
+ attr.color[ATTR_HIGH] = COLOR_PAIR(COLR_HIGH);
+ attr.color[ATTR_MIDDLE] = COLOR_PAIR(COLR_RED);
+ attr.color[ATTR_LOW] = COLOR_PAIR(COLR_CYAN);
+ attr.color[ATTR_LOWEST] = COLOR_PAIR(COLR_YELLOW);
+ attr.color[ATTR_TRUE] = COLOR_PAIR(COLR_GREEN);
+ attr.color[ATTR_FALSE] = COLOR_PAIR(COLR_RED);
+
+ attr.nocolor[ATTR_HIGHEST] = A_BOLD;
+ attr.nocolor[ATTR_HIGH] = A_REVERSE;
+ attr.nocolor[ATTR_MIDDLE] = A_REVERSE;
+ attr.nocolor[ATTR_LOW] = A_UNDERLINE;
+ attr.nocolor[ATTR_LOWEST] = A_BOLD;
+ attr.nocolor[ATTR_TRUE] = A_BOLD;
+ attr.nocolor[ATTR_FALSE] = A_DIM;
}
/* Apply window attribute */
void custom_apply_attr(WINDOW * win, int attr_num)
{
- if (colorize)
- wattron(win, attr.color[attr_num]);
- else
- wattron(win, attr.nocolor[attr_num]);
+ if (colorize)
+ wattron(win, attr.color[attr_num]);
+ else
+ wattron(win, attr.nocolor[attr_num]);
}
/* Remove window attribute */
void custom_remove_attr(WINDOW * win, int attr_num)
{
- if (colorize)
- wattroff(win, attr.color[attr_num]);
- else
- wattroff(win, attr.nocolor[attr_num]);
+ if (colorize)
+ wattroff(win, attr.color[attr_num]);
+ else
+ wattroff(win, attr.nocolor[attr_num]);
}
/* Draws the configuration bar */
void custom_config_bar(void)
{
- const int SMLSPC = 2;
- const int SPC = 15;
-
- custom_apply_attr(win[STA].p, ATTR_HIGHEST);
- mvwaddstr(win[STA].p, 0, 2, "Q");
- mvwaddstr(win[STA].p, 1, 2, "G");
- mvwaddstr(win[STA].p, 0, 2 + SPC, "L");
- mvwaddstr(win[STA].p, 1, 2 + SPC, "S");
- mvwaddstr(win[STA].p, 0, 2 + 2 * SPC, "C");
- mvwaddstr(win[STA].p, 1, 2 + 2 * SPC, "N");
- mvwaddstr(win[STA].p, 0, 2 + 3 * SPC, "K");
- custom_remove_attr(win[STA].p, ATTR_HIGHEST);
-
- mvwaddstr(win[STA].p, 0, 2 + SMLSPC, _("Exit"));
- mvwaddstr(win[STA].p, 1, 2 + SMLSPC, _("General"));
- mvwaddstr(win[STA].p, 0, 2 + SPC + SMLSPC, _("Layout"));
- mvwaddstr(win[STA].p, 1, 2 + SPC + SMLSPC, _("Sidebar"));
- mvwaddstr(win[STA].p, 0, 2 + 2 * SPC + SMLSPC, _("Color"));
- mvwaddstr(win[STA].p, 1, 2 + 2 * SPC + SMLSPC, _("Notify"));
- mvwaddstr(win[STA].p, 0, 2 + 3 * SPC + SMLSPC, _("Keys"));
-
- wnoutrefresh(win[STA].p);
- wmove(win[STA].p, 0, 0);
- wins_doupdate();
+ const int SMLSPC = 2;
+ const int SPC = 15;
+
+ custom_apply_attr(win[STA].p, ATTR_HIGHEST);
+ mvwaddstr(win[STA].p, 0, 2, "Q");
+ mvwaddstr(win[STA].p, 1, 2, "G");
+ mvwaddstr(win[STA].p, 0, 2 + SPC, "L");
+ mvwaddstr(win[STA].p, 1, 2 + SPC, "S");
+ mvwaddstr(win[STA].p, 0, 2 + 2 * SPC, "C");
+ mvwaddstr(win[STA].p, 1, 2 + 2 * SPC, "N");
+ mvwaddstr(win[STA].p, 0, 2 + 3 * SPC, "K");
+ custom_remove_attr(win[STA].p, ATTR_HIGHEST);
+
+ mvwaddstr(win[STA].p, 0, 2 + SMLSPC, _("Exit"));
+ mvwaddstr(win[STA].p, 1, 2 + SMLSPC, _("General"));
+ mvwaddstr(win[STA].p, 0, 2 + SPC + SMLSPC, _("Layout"));
+ mvwaddstr(win[STA].p, 1, 2 + SPC + SMLSPC, _("Sidebar"));
+ mvwaddstr(win[STA].p, 0, 2 + 2 * SPC + SMLSPC, _("Color"));
+ mvwaddstr(win[STA].p, 1, 2 + 2 * SPC + SMLSPC, _("Notify"));
+ mvwaddstr(win[STA].p, 0, 2 + 3 * SPC + SMLSPC, _("Keys"));
+
+ wnoutrefresh(win[STA].p);
+ wmove(win[STA].p, 0, 0);
+ wins_doupdate();
}
static void layout_selection_bar(void)
{
- struct binding quit = { _("Exit"), KEY_GENERIC_QUIT };
- struct binding select = { _("Select"), KEY_GENERIC_SELECT };
- struct binding up = { _("Up"), KEY_MOVE_UP };
- struct binding down = { _("Down"), KEY_MOVE_DOWN };
- struct binding left = { _("Left"), KEY_MOVE_LEFT };
- struct binding right = { _("Right"), KEY_MOVE_RIGHT };
- struct binding help = { _("Help"), KEY_GENERIC_HELP };
-
- struct binding *bindings[] = {
- &quit, &select, &up, &down, &left, &right, &help
- };
- int bindings_size = sizeof(bindings) / sizeof(bindings[0]);
-
- keys_display_bindings_bar(win[STA].p, bindings, bindings_size, 0,
- bindings_size, NULL);
+ struct binding quit = { _("Exit"), KEY_GENERIC_QUIT };
+ struct binding select = { _("Select"), KEY_GENERIC_SELECT };
+ struct binding up = { _("Up"), KEY_MOVE_UP };
+ struct binding down = { _("Down"), KEY_MOVE_DOWN };
+ struct binding left = { _("Left"), KEY_MOVE_LEFT };
+ struct binding right = { _("Right"), KEY_MOVE_RIGHT };
+ struct binding help = { _("Help"), KEY_GENERIC_HELP };
+
+ struct binding *bindings[] = {
+ &quit, &select, &up, &down, &left, &right, &help
+ };
+ int bindings_size = sizeof(bindings) / sizeof(bindings[0]);
+
+ keys_display_bindings_bar(win[STA].p, bindings, bindings_size, 0,
+ bindings_size, NULL);
}
#define NBLAYOUTS 8
#define LAYOUTSPERCOL 2
/* Used to display available layouts in layout configuration menu. */
-static void display_layout_config(struct window *lwin, int mark, int cursor)
+static void display_layout_config(struct window *lwin, int mark,
+ int cursor)
{
#define CURSOR (32 | A_REVERSE)
#define MARK 88
#define LAYOUTH 5
#define LAYOUTW 9
- const char *box = "[ ]";
- const int BOXSIZ = strlen(box);
- const int NBCOLS = NBLAYOUTS / LAYOUTSPERCOL;
- const int COLSIZ = LAYOUTW + BOXSIZ + 1;
- const int XSPC = (lwin->w - NBCOLS * COLSIZ) / (NBCOLS + 1);
- const int XOFST = (lwin->w - NBCOLS * (XSPC + COLSIZ)) / 2;
- const int YSPC =
- (lwin->h - 8 - LAYOUTSPERCOL * LAYOUTH) / (LAYOUTSPERCOL + 1);
- const int YOFST = (lwin->h - LAYOUTSPERCOL * (YSPC + LAYOUTH)) / 2;
- enum { YPOS, XPOS, NBPOS };
- int pos[NBLAYOUTS][NBPOS];
- const char *layouts[LAYOUTH][NBLAYOUTS] = {
- {"+---+---+", "+---+---+", "+---+---+", "+---+---+", "+---+---+",
- "+---+---+", "+---+---+", "+---+---+"},
- {"| | c |", "| | t |", "| c | |", "| t | |", "| | c |",
- "| | a |", "| c | |", "| a | |"},
- {"| a +---+", "| a +---+", "+---+ a |", "|---+ a |", "| t +---+",
- "| t +---+", "+---+ t |", "+---+ t |"},
- {"| | t |", "| | c |", "| t | |", "| c | |", "| | a |",
- "| | c |", "| a | |", "| c | |"},
- {"+---+---+", "+---+---+", "+---+---+", "+---+---+", "+---+---+",
- "+---+---+", "+---+---+", "+---+---+"}
- };
- int i;
-
- for (i = 0; i < NBLAYOUTS; i++) {
- pos[i][YPOS] = YOFST + (i % LAYOUTSPERCOL) * (YSPC + LAYOUTH);
- pos[i][XPOS] = XOFST + (i / LAYOUTSPERCOL) * (XSPC + COLSIZ);
- }
-
- for (i = 0; i < NBLAYOUTS; i++) {
- int j;
-
- mvwaddstr(lwin->p, pos[i][YPOS] + 2, pos[i][XPOS], box);
- if (i == mark)
- custom_apply_attr(lwin->p, ATTR_HIGHEST);
- for (j = 0; j < LAYOUTH; j++) {
- mvwaddstr(lwin->p, pos[i][YPOS] + j, pos[i][XPOS] + BOXSIZ + 1,
- layouts[j][i]);
- }
- if (i == mark)
- custom_remove_attr(lwin->p, ATTR_HIGHEST);
- }
- mvwaddch(lwin->p, pos[mark][YPOS] + 2, pos[mark][XPOS] + 1, MARK);
- mvwaddch(lwin->p, pos[cursor][YPOS] + 2, pos[cursor][XPOS] + 1, CURSOR);
-
- layout_selection_bar();
- wnoutrefresh(win[STA].p);
- wnoutrefresh(lwin->p);
- wins_doupdate();
- if (notify_bar())
- notify_update_bar();
+ const char *box = "[ ]";
+ const int BOXSIZ = strlen(box);
+ const int NBCOLS = NBLAYOUTS / LAYOUTSPERCOL;
+ const int COLSIZ = LAYOUTW + BOXSIZ + 1;
+ const int XSPC = (lwin->w - NBCOLS * COLSIZ) / (NBCOLS + 1);
+ const int XOFST = (lwin->w - NBCOLS * (XSPC + COLSIZ)) / 2;
+ const int YSPC =
+ (lwin->h - 8 - LAYOUTSPERCOL * LAYOUTH) / (LAYOUTSPERCOL + 1);
+ const int YOFST = (lwin->h - LAYOUTSPERCOL * (YSPC + LAYOUTH)) / 2;
+ enum { YPOS, XPOS, NBPOS };
+ int pos[NBLAYOUTS][NBPOS];
+ const char *layouts[LAYOUTH][NBLAYOUTS] = {
+ {"+---+---+", "+---+---+", "+---+---+", "+---+---+", "+---+---+", "+---+---+", "+---+---+", "+---+---+"},
+ {"| | c |", "| | t |", "| c | |", "| t | |", "| | c |", "| | a |", "| c | |", "| a | |"},
+ {"| a +---+", "| a +---+", "+---+ a |", "|---+ a |", "| t +---+", "| t +---+", "+---+ t |", "+---+ t |"},
+ {"| | t |", "| | c |", "| t | |", "| c | |", "| | a |", "| | c |", "| a | |", "| c | |"},
+ {"+---+---+", "+---+---+", "+---+---+", "+---+---+", "+---+---+", "+---+---+", "+---+---+", "+---+---+"}
+ };
+ int i;
+
+ for (i = 0; i < NBLAYOUTS; i++) {
+ pos[i][YPOS] =
+ YOFST + (i % LAYOUTSPERCOL) * (YSPC + LAYOUTH);
+ pos[i][XPOS] =
+ XOFST + (i / LAYOUTSPERCOL) * (XSPC + COLSIZ);
+ }
+
+ for (i = 0; i < NBLAYOUTS; i++) {
+ int j;
+
+ mvwaddstr(lwin->p, pos[i][YPOS] + 2, pos[i][XPOS], box);
+ if (i == mark)
+ custom_apply_attr(lwin->p, ATTR_HIGHEST);
+ for (j = 0; j < LAYOUTH; j++) {
+ mvwaddstr(lwin->p, pos[i][YPOS] + j,
+ pos[i][XPOS] + BOXSIZ + 1,
+ layouts[j][i]);
+ }
+ if (i == mark)
+ custom_remove_attr(lwin->p, ATTR_HIGHEST);
+ }
+ mvwaddch(lwin->p, pos[mark][YPOS] + 2, pos[mark][XPOS] + 1, MARK);
+ mvwaddch(lwin->p, pos[cursor][YPOS] + 2, pos[cursor][XPOS] + 1,
+ CURSOR);
+
+ layout_selection_bar();
+ wnoutrefresh(win[STA].p);
+ wnoutrefresh(lwin->p);
+ wins_doupdate();
+ if (notify_bar())
+ notify_update_bar();
}
/* Choose the layout */
void custom_layout_config(void)
{
- struct scrollwin hwin;
- struct window conf_win;
- int ch, mark, cursor, need_reset;
- const char *label = _("layout configuration");
- const char *help_text =
- _("With this configuration menu, one can choose where panels will be\n"
- "displayed inside calcurse screen. \n"
- "It is possible to choose between eight different configurations.\n"
- "\nIn the configuration representations, letters correspond to:\n\n"
- " 'c' -> calendar panel\n\n"
- " 'a' -> appointment panel\n\n" " 't' -> todo panel\n\n");
-
- conf_win.p = NULL;
- custom_confwin_init(&conf_win, label);
- cursor = mark = wins_layout() - 1;
- display_layout_config(&conf_win, mark, cursor);
- clear();
-
- while ((ch = keys_getch(win[KEY].p, NULL, NULL)) != KEY_GENERIC_QUIT) {
- need_reset = 0;
- switch (ch) {
- case KEY_GENERIC_HELP:
- help_wins_init(&hwin, 0, 0, (notify_bar())? row - 3 : row - 2, col);
- mvwprintw(hwin.pad.p, 1, 0, help_text, SBARMINWIDTH);
- hwin.total_lines = 7;
- wins_scrollwin_display(&hwin);
- wgetch(hwin.win.p);
- wins_scrollwin_delete(&hwin);
- need_reset = 1;
- break;
- case KEY_GENERIC_SELECT:
- mark = cursor;
- break;
- case KEY_MOVE_DOWN:
- if (cursor % LAYOUTSPERCOL < LAYOUTSPERCOL - 1)
- cursor++;
- break;
- case KEY_MOVE_UP:
- if (cursor % LAYOUTSPERCOL > 0)
- cursor--;
- break;
- case KEY_MOVE_LEFT:
- if (cursor >= LAYOUTSPERCOL)
- cursor -= LAYOUTSPERCOL;
- break;
- case KEY_MOVE_RIGHT:
- if (cursor < NBLAYOUTS - LAYOUTSPERCOL)
- cursor += LAYOUTSPERCOL;
- break;
- case KEY_GENERIC_CANCEL:
- need_reset = 1;
- break;
- }
-
- if (resize) {
- resize = 0;
- endwin();
- wins_refresh();
- curs_set(0);
- need_reset = 1;
- }
-
- if (need_reset)
- custom_confwin_init(&conf_win, label);
-
- display_layout_config(&conf_win, mark, cursor);
- }
- wins_set_layout(mark + 1);
- delwin(conf_win.p);
+ struct scrollwin hwin;
+ struct window conf_win;
+ int ch, mark, cursor, need_reset;
+ const char *label = _("layout configuration");
+ const char *help_text =
+ _("With this configuration menu, one can choose where panels will be\n"
+ "displayed inside calcurse screen. \n"
+ "It is possible to choose between eight different configurations.\n"
+ "\nIn the configuration representations, letters correspond to:\n\n"
+ " 'c' -> calendar panel\n\n"
+ " 'a' -> appointment panel\n\n"
+ " 't' -> todo panel\n\n");
+
+ conf_win.p = NULL;
+ custom_confwin_init(&conf_win, label);
+ cursor = mark = wins_layout() - 1;
+ display_layout_config(&conf_win, mark, cursor);
+ clear();
+
+ while ((ch =
+ keys_getch(win[KEY].p, NULL, NULL)) != KEY_GENERIC_QUIT) {
+ need_reset = 0;
+ switch (ch) {
+ case KEY_GENERIC_HELP:
+ help_wins_init(&hwin, 0, 0,
+ (notify_bar())? row - 3 : row - 2,
+ col);
+ mvwprintw(hwin.pad.p, 1, 0, help_text,
+ SBARMINWIDTH);
+ hwin.total_lines = 7;
+ wins_scrollwin_display(&hwin);
+ wgetch(hwin.win.p);
+ wins_scrollwin_delete(&hwin);
+ need_reset = 1;
+ break;
+ case KEY_GENERIC_SELECT:
+ mark = cursor;
+ break;
+ case KEY_MOVE_DOWN:
+ if (cursor % LAYOUTSPERCOL < LAYOUTSPERCOL - 1)
+ cursor++;
+ break;
+ case KEY_MOVE_UP:
+ if (cursor % LAYOUTSPERCOL > 0)
+ cursor--;
+ break;
+ case KEY_MOVE_LEFT:
+ if (cursor >= LAYOUTSPERCOL)
+ cursor -= LAYOUTSPERCOL;
+ break;
+ case KEY_MOVE_RIGHT:
+ if (cursor < NBLAYOUTS - LAYOUTSPERCOL)
+ cursor += LAYOUTSPERCOL;
+ break;
+ case KEY_GENERIC_CANCEL:
+ need_reset = 1;
+ break;
+ }
+
+ if (resize) {
+ resize = 0;
+ endwin();
+ wins_refresh();
+ curs_set(0);
+ need_reset = 1;
+ }
+
+ if (need_reset)
+ custom_confwin_init(&conf_win, label);
+
+ display_layout_config(&conf_win, mark, cursor);
+ }
+ wins_set_layout(mark + 1);
+ delwin(conf_win.p);
}
#undef NBLAYOUTS
@@ -285,71 +290,74 @@ void custom_layout_config(void)
/* Sidebar configuration screen. */
void custom_sidebar_config(void)
{
- struct scrollwin hwin;
- struct binding quit = { _("Exit"), KEY_GENERIC_QUIT };
- struct binding inc = { _("Width +"), KEY_MOVE_UP };
- struct binding dec = { _("Width -"), KEY_MOVE_DOWN };
- struct binding help = { _("Help"), KEY_GENERIC_HELP };
- struct binding *bindings[] = {
- &inc, &dec, &help, &quit
- };
- const char *help_text =
- _
- ("This configuration screen is used to change the width of the side bar.\n"
- "The side bar is the part of the screen which contains two panels:\n"
- "the calendar and, depending on the chosen layout, either the todo list\n"
- "or the appointment list.\n\n"
- "The side bar width can be up to 50%% of the total screen width, but\n"
- "can't be smaller than %d characters wide.\n\n");
- int ch, bindings_size;
-
- bindings_size = sizeof(bindings) / sizeof(bindings[0]);
-
- keys_display_bindings_bar(win[STA].p, bindings, bindings_size, 0,
- bindings_size, NULL);
- wins_doupdate();
-
- while ((ch = keys_getch(win[KEY].p, NULL, NULL)) != KEY_GENERIC_QUIT) {
- switch (ch) {
- case KEY_MOVE_UP:
- wins_sbar_winc();
- break;
- case KEY_MOVE_DOWN:
- wins_sbar_wdec();
- break;
- case KEY_GENERIC_HELP:
- help_wins_init(&hwin, 0, 0, (notify_bar())? row - 3 : row - 2, col);
- mvwaddstr(hwin.pad.p, 1, 0, help_text);
- hwin.total_lines = 6;
- wins_scrollwin_display(&hwin);
- wgetch(hwin.win.p);
- wins_scrollwin_delete(&hwin);
- break;
- case KEY_RESIZE:
- break;
- default:
- continue;
- }
-
- if (resize) {
- resize = 0;
- wins_reset();
- } else {
- wins_reinit_panels();
- wins_update_border(FLAG_ALL);
- wins_update_panels(FLAG_ALL);
- keys_display_bindings_bar(win[STA].p, bindings, bindings_size, 0,
- bindings_size, NULL);
- wins_doupdate();
- }
- }
+ struct scrollwin hwin;
+ struct binding quit = { _("Exit"), KEY_GENERIC_QUIT };
+ struct binding inc = { _("Width +"), KEY_MOVE_UP };
+ struct binding dec = { _("Width -"), KEY_MOVE_DOWN };
+ struct binding help = { _("Help"), KEY_GENERIC_HELP };
+ struct binding *bindings[] = {
+ &inc, &dec, &help, &quit
+ };
+ const char *help_text =
+ _("This configuration screen is used to change the width of the side bar.\n"
+ "The side bar is the part of the screen which contains two panels:\n"
+ "the calendar and, depending on the chosen layout, either the todo list\n"
+ "or the appointment list.\n\n"
+ "The side bar width can be up to 50%% of the total screen width, but\n"
+ "can't be smaller than %d characters wide.\n\n");
+ int ch, bindings_size;
+
+ bindings_size = sizeof(bindings) / sizeof(bindings[0]);
+
+ keys_display_bindings_bar(win[STA].p, bindings, bindings_size, 0,
+ bindings_size, NULL);
+ wins_doupdate();
+
+ while ((ch =
+ keys_getch(win[KEY].p, NULL, NULL)) != KEY_GENERIC_QUIT) {
+ switch (ch) {
+ case KEY_MOVE_UP:
+ wins_sbar_winc();
+ break;
+ case KEY_MOVE_DOWN:
+ wins_sbar_wdec();
+ break;
+ case KEY_GENERIC_HELP:
+ help_wins_init(&hwin, 0, 0,
+ (notify_bar())? row - 3 : row - 2,
+ col);
+ mvwaddstr(hwin.pad.p, 1, 0, help_text);
+ hwin.total_lines = 6;
+ wins_scrollwin_display(&hwin);
+ wgetch(hwin.win.p);
+ wins_scrollwin_delete(&hwin);
+ break;
+ case KEY_RESIZE:
+ break;
+ default:
+ continue;
+ }
+
+ if (resize) {
+ resize = 0;
+ wins_reset();
+ } else {
+ wins_reinit_panels();
+ wins_update_border(FLAG_ALL);
+ wins_update_panels(FLAG_ALL);
+ keys_display_bindings_bar(win[STA].p, bindings,
+ bindings_size, 0,
+ bindings_size, NULL);
+ wins_doupdate();
+ }
+ }
}
static void set_confwin_attr(struct window *cwin)
{
- cwin->h = (notify_bar())? row - 3 : row - 2;
- cwin->w = col;
- cwin->x = cwin->y = 0;
+ cwin->h = (notify_bar())? row - 3 : row - 2;
+ cwin->w = col;
+ cwin->x = cwin->y = 0;
}
/*
@@ -358,43 +366,45 @@ static void set_confwin_attr(struct window *cwin)
*/
void custom_confwin_init(struct window *confwin, const char *label)
{
- if (confwin->p) {
- erase_window_part(confwin->p, confwin->x, confwin->y,
- confwin->x + confwin->w, confwin->y + confwin->h);
- delwin(confwin->p);
- }
-
- wins_get_config();
- set_confwin_attr(confwin);
- confwin->p = newwin(confwin->h, col, 0, 0);
- box(confwin->p, 0, 0);
- wins_show(confwin->p, label);
- delwin(win[STA].p);
- win[STA].p = newwin(win[STA].h, win[STA].w, win[STA].y, win[STA].x);
- keypad(win[STA].p, TRUE);
- if (notify_bar()) {
- notify_reinit_bar();
- notify_update_bar();
- }
+ if (confwin->p) {
+ erase_window_part(confwin->p, confwin->x, confwin->y,
+ confwin->x + confwin->w,
+ confwin->y + confwin->h);
+ delwin(confwin->p);
+ }
+
+ wins_get_config();
+ set_confwin_attr(confwin);
+ confwin->p = newwin(confwin->h, col, 0, 0);
+ box(confwin->p, 0, 0);
+ wins_show(confwin->p, label);
+ delwin(win[STA].p);
+ win[STA].p =
+ newwin(win[STA].h, win[STA].w, win[STA].y, win[STA].x);
+ keypad(win[STA].p, TRUE);
+ if (notify_bar()) {
+ notify_reinit_bar();
+ notify_update_bar();
+ }
}
static void color_selection_bar(void)
{
- struct binding quit = { _("Exit"), KEY_GENERIC_QUIT };
- struct binding select = { _("Select"), KEY_GENERIC_SELECT };
- struct binding nocolor = { _("No color"), KEY_GENERIC_CANCEL };
- struct binding up = { _("Up"), KEY_MOVE_UP };
- struct binding down = { _("Down"), KEY_MOVE_DOWN };
- struct binding left = { _("Left"), KEY_MOVE_LEFT };
- struct binding right = { _("Right"), KEY_MOVE_RIGHT };
-
- struct binding *bindings[] = {
- &quit, &nocolor, &up, &down, &left, &right, &select
- };
- int bindings_size = sizeof(bindings) / sizeof(bindings[0]);
-
- keys_display_bindings_bar(win[STA].p, bindings, bindings_size, 0,
- bindings_size, NULL);
+ struct binding quit = { _("Exit"), KEY_GENERIC_QUIT };
+ struct binding select = { _("Select"), KEY_GENERIC_SELECT };
+ struct binding nocolor = { _("No color"), KEY_GENERIC_CANCEL };
+ struct binding up = { _("Up"), KEY_MOVE_UP };
+ struct binding down = { _("Down"), KEY_MOVE_DOWN };
+ struct binding left = { _("Left"), KEY_MOVE_LEFT };
+ struct binding right = { _("Right"), KEY_MOVE_RIGHT };
+
+ struct binding *bindings[] = {
+ &quit, &nocolor, &up, &down, &left, &right, &select
+ };
+ int bindings_size = sizeof(bindings) / sizeof(bindings[0]);
+
+ keys_display_bindings_bar(win[STA].p, bindings, bindings_size, 0,
+ bindings_size, NULL);
}
/*
@@ -403,7 +413,7 @@ static void color_selection_bar(void)
*/
static void
display_color_config(struct window *cwin, int *mark_fore, int *mark_back,
- int cursor, int theme_changed)
+ int cursor, int theme_changed)
{
#define SIZE (2 * (NBUSERCOLORS + 1))
#define DEFAULTCOLOR 255
@@ -411,676 +421,719 @@ display_color_config(struct window *cwin, int *mark_fore, int *mark_back,
#define CURSOR (32 | A_REVERSE)
#define MARK 88
- const char *fore_txt = _("Foreground");
- const char *back_txt = _("Background");
- const char *default_txt = _("(terminal's default)");
- const char *bar = " ";
- const char *box = "[ ]";
- const unsigned Y = 3;
- const unsigned XOFST = 5;
- const unsigned YSPC = (cwin->h - 8) / (NBUSERCOLORS + 1);
- const unsigned BARSIZ = strlen(bar);
- const unsigned BOXSIZ = strlen(box);
- const unsigned XSPC = (cwin->w - 2 * BARSIZ - 2 * BOXSIZ - 6) / 3;
- const unsigned XFORE = XSPC;
- const unsigned XBACK = 2 * XSPC + BOXSIZ + XOFST + BARSIZ;
- enum { YPOS, XPOS, NBPOS };
- unsigned i;
- int pos[SIZE][NBPOS];
- short colr_fore, colr_back;
- int colr[SIZE] = {
- COLR_RED, COLR_GREEN, COLR_YELLOW, COLR_BLUE,
- COLR_MAGENTA, COLR_CYAN, COLR_DEFAULT,
- COLR_RED, COLR_GREEN, COLR_YELLOW, COLR_BLUE,
- COLR_MAGENTA, COLR_CYAN, COLR_DEFAULT
- };
-
- for (i = 0; i < NBUSERCOLORS + 1; i++) {
- pos[i][YPOS] = Y + YSPC * (i + 1);
- pos[NBUSERCOLORS + i + 1][YPOS] = Y + YSPC * (i + 1);
- pos[i][XPOS] = XFORE;
- pos[NBUSERCOLORS + i + 1][XPOS] = XBACK;
- }
-
- if (colorize) {
- if (theme_changed) {
- pair_content(colr[*mark_fore], &colr_fore, 0L);
- if (colr_fore == 255)
- colr_fore = -1;
- pair_content(colr[*mark_back], &colr_back, 0L);
- if (colr_back == 255)
- colr_back = -1;
- init_pair(COLR_CUSTOM, colr_fore, colr_back);
- } else {
- /* Retrieve the actual color theme. */
- pair_content(COLR_CUSTOM, &colr_fore, &colr_back);
-
- if ((colr_fore == DEFAULTCOLOR) || (colr_fore == DEFAULTCOLOR_EXT)) {
- *mark_fore = NBUSERCOLORS;
- } else {
- for (i = 0; i < NBUSERCOLORS + 1; i++)
- if (colr_fore == colr[i])
- *mark_fore = i;
- }
-
- if ((colr_back == DEFAULTCOLOR) || (colr_back == DEFAULTCOLOR_EXT)) {
- *mark_back = SIZE - 1;
- } else {
- for (i = 0; i < NBUSERCOLORS + 1; i++)
- if (colr_back == colr[NBUSERCOLORS + 1 + i])
- *mark_back = NBUSERCOLORS + 1 + i;
- }
- }
- }
-
- /* color boxes */
- for (i = 0; i < SIZE - 1; i++) {
- mvwaddstr(cwin->p, pos[i][YPOS], pos[i][XPOS], box);
- wattron(cwin->p, COLOR_PAIR(colr[i]) | A_REVERSE);
- mvwaddstr(cwin->p, pos[i][YPOS], pos[i][XPOS] + XOFST, bar);
- wattroff(cwin->p, COLOR_PAIR(colr[i]) | A_REVERSE);
- }
-
- /* Terminal's default color */
- i = SIZE - 1;
- mvwaddstr(cwin->p, pos[i][YPOS], pos[i][XPOS], box);
- wattron(cwin->p, COLOR_PAIR(colr[i]));
- mvwaddstr(cwin->p, pos[i][YPOS], pos[i][XPOS] + XOFST, bar);
- wattroff(cwin->p, COLOR_PAIR(colr[i]));
- mvwaddstr(cwin->p, pos[NBUSERCOLORS][YPOS] + 1,
- pos[NBUSERCOLORS][XPOS] + XOFST, default_txt);
- mvwaddstr(cwin->p, pos[SIZE - 1][YPOS] + 1,
- pos[SIZE - 1][XPOS] + XOFST, default_txt);
-
- custom_apply_attr(cwin->p, ATTR_HIGHEST);
- mvwaddstr(cwin->p, Y, XFORE + XOFST, fore_txt);
- mvwaddstr(cwin->p, Y, XBACK + XOFST, back_txt);
- custom_remove_attr(cwin->p, ATTR_HIGHEST);
-
- if (colorize) {
- mvwaddch(cwin->p, pos[*mark_fore][YPOS], pos[*mark_fore][XPOS] + 1, MARK);
- mvwaddch(cwin->p, pos[*mark_back][YPOS], pos[*mark_back][XPOS] + 1, MARK);
- }
-
- mvwaddch(cwin->p, pos[cursor][YPOS], pos[cursor][XPOS] + 1, CURSOR);
- color_selection_bar();
- wnoutrefresh(win[STA].p);
- wnoutrefresh(cwin->p);
- wins_doupdate();
- if (notify_bar())
- notify_update_bar();
+ const char *fore_txt = _("Foreground");
+ const char *back_txt = _("Background");
+ const char *default_txt = _("(terminal's default)");
+ const char *bar = " ";
+ const char *box = "[ ]";
+ const unsigned Y = 3;
+ const unsigned XOFST = 5;
+ const unsigned YSPC = (cwin->h - 8) / (NBUSERCOLORS + 1);
+ const unsigned BARSIZ = strlen(bar);
+ const unsigned BOXSIZ = strlen(box);
+ const unsigned XSPC = (cwin->w - 2 * BARSIZ - 2 * BOXSIZ - 6) / 3;
+ const unsigned XFORE = XSPC;
+ const unsigned XBACK = 2 * XSPC + BOXSIZ + XOFST + BARSIZ;
+ enum { YPOS, XPOS, NBPOS };
+ unsigned i;
+ int pos[SIZE][NBPOS];
+ short colr_fore, colr_back;
+ int colr[SIZE] = {
+ COLR_RED, COLR_GREEN, COLR_YELLOW, COLR_BLUE,
+ COLR_MAGENTA, COLR_CYAN, COLR_DEFAULT,
+ COLR_RED, COLR_GREEN, COLR_YELLOW, COLR_BLUE,
+ COLR_MAGENTA, COLR_CYAN, COLR_DEFAULT
+ };
+
+ for (i = 0; i < NBUSERCOLORS + 1; i++) {
+ pos[i][YPOS] = Y + YSPC * (i + 1);
+ pos[NBUSERCOLORS + i + 1][YPOS] = Y + YSPC * (i + 1);
+ pos[i][XPOS] = XFORE;
+ pos[NBUSERCOLORS + i + 1][XPOS] = XBACK;
+ }
+
+ if (colorize) {
+ if (theme_changed) {
+ pair_content(colr[*mark_fore], &colr_fore, 0L);
+ if (colr_fore == 255)
+ colr_fore = -1;
+ pair_content(colr[*mark_back], &colr_back, 0L);
+ if (colr_back == 255)
+ colr_back = -1;
+ init_pair(COLR_CUSTOM, colr_fore, colr_back);
+ } else {
+ /* Retrieve the actual color theme. */
+ pair_content(COLR_CUSTOM, &colr_fore, &colr_back);
+
+ if ((colr_fore == DEFAULTCOLOR)
+ || (colr_fore == DEFAULTCOLOR_EXT)) {
+ *mark_fore = NBUSERCOLORS;
+ } else {
+ for (i = 0; i < NBUSERCOLORS + 1; i++)
+ if (colr_fore == colr[i])
+ *mark_fore = i;
+ }
+
+ if ((colr_back == DEFAULTCOLOR)
+ || (colr_back == DEFAULTCOLOR_EXT)) {
+ *mark_back = SIZE - 1;
+ } else {
+ for (i = 0; i < NBUSERCOLORS + 1; i++)
+ if (colr_back ==
+ colr[NBUSERCOLORS + 1 + i])
+ *mark_back =
+ NBUSERCOLORS + 1 + i;
+ }
+ }
+ }
+
+ /* color boxes */
+ for (i = 0; i < SIZE - 1; i++) {
+ mvwaddstr(cwin->p, pos[i][YPOS], pos[i][XPOS], box);
+ wattron(cwin->p, COLOR_PAIR(colr[i]) | A_REVERSE);
+ mvwaddstr(cwin->p, pos[i][YPOS], pos[i][XPOS] + XOFST,
+ bar);
+ wattroff(cwin->p, COLOR_PAIR(colr[i]) | A_REVERSE);
+ }
+
+ /* Terminal's default color */
+ i = SIZE - 1;
+ mvwaddstr(cwin->p, pos[i][YPOS], pos[i][XPOS], box);
+ wattron(cwin->p, COLOR_PAIR(colr[i]));
+ mvwaddstr(cwin->p, pos[i][YPOS], pos[i][XPOS] + XOFST, bar);
+ wattroff(cwin->p, COLOR_PAIR(colr[i]));
+ mvwaddstr(cwin->p, pos[NBUSERCOLORS][YPOS] + 1,
+ pos[NBUSERCOLORS][XPOS] + XOFST, default_txt);
+ mvwaddstr(cwin->p, pos[SIZE - 1][YPOS] + 1,
+ pos[SIZE - 1][XPOS] + XOFST, default_txt);
+
+ custom_apply_attr(cwin->p, ATTR_HIGHEST);
+ mvwaddstr(cwin->p, Y, XFORE + XOFST, fore_txt);
+ mvwaddstr(cwin->p, Y, XBACK + XOFST, back_txt);
+ custom_remove_attr(cwin->p, ATTR_HIGHEST);
+
+ if (colorize) {
+ mvwaddch(cwin->p, pos[*mark_fore][YPOS],
+ pos[*mark_fore][XPOS] + 1, MARK);
+ mvwaddch(cwin->p, pos[*mark_back][YPOS],
+ pos[*mark_back][XPOS] + 1, MARK);
+ }
+
+ mvwaddch(cwin->p, pos[cursor][YPOS], pos[cursor][XPOS] + 1,
+ CURSOR);
+ color_selection_bar();
+ wnoutrefresh(win[STA].p);
+ wnoutrefresh(cwin->p);
+ wins_doupdate();
+ if (notify_bar())
+ notify_update_bar();
}
/* Color theme configuration. */
void custom_color_config(void)
{
- struct window conf_win;
- int ch, cursor, need_reset, theme_changed;
- int mark_fore, mark_back;
- const char *label = _("color theme");
-
- conf_win.p = 0;
- custom_confwin_init(&conf_win, label);
- mark_fore = NBUSERCOLORS;
- mark_back = SIZE - 1;
- cursor = 0;
- theme_changed = 0;
- display_color_config(&conf_win, &mark_fore, &mark_back, cursor,
- theme_changed);
- clear();
-
- while ((ch = keys_getch(win[KEY].p, NULL, NULL)) != KEY_GENERIC_QUIT) {
- need_reset = 0;
- theme_changed = 0;
-
- switch (ch) {
- case KEY_GENERIC_SELECT:
- colorize = 1;
- need_reset = 1;
- theme_changed = 1;
- if (cursor > NBUSERCOLORS)
- mark_back = cursor;
- else
- mark_fore = cursor;
- break;
-
- case KEY_MOVE_DOWN:
- if (cursor < SIZE - 1)
- ++cursor;
- break;
-
- case KEY_MOVE_UP:
- if (cursor > 0)
- --cursor;
- break;
-
- case KEY_MOVE_LEFT:
- if (cursor > NBUSERCOLORS)
- cursor -= (NBUSERCOLORS + 1);
- break;
-
- case KEY_MOVE_RIGHT:
- if (cursor <= NBUSERCOLORS)
- cursor += (NBUSERCOLORS + 1);
- break;
-
- case KEY_GENERIC_CANCEL:
- colorize = 0;
- need_reset = 1;
- break;
- }
-
- if (resize) {
- resize = 0;
- endwin();
- wins_refresh();
- curs_set(0);
- need_reset = 1;
- }
-
- if (need_reset)
- custom_confwin_init(&conf_win, label);
-
- display_color_config(&conf_win, &mark_fore, &mark_back, cursor,
- theme_changed);
- }
- delwin(conf_win.p);
+ struct window conf_win;
+ int ch, cursor, need_reset, theme_changed;
+ int mark_fore, mark_back;
+ const char *label = _("color theme");
+
+ conf_win.p = 0;
+ custom_confwin_init(&conf_win, label);
+ mark_fore = NBUSERCOLORS;
+ mark_back = SIZE - 1;
+ cursor = 0;
+ theme_changed = 0;
+ display_color_config(&conf_win, &mark_fore, &mark_back, cursor,
+ theme_changed);
+ clear();
+
+ while ((ch =
+ keys_getch(win[KEY].p, NULL, NULL)) != KEY_GENERIC_QUIT) {
+ need_reset = 0;
+ theme_changed = 0;
+
+ switch (ch) {
+ case KEY_GENERIC_SELECT:
+ colorize = 1;
+ need_reset = 1;
+ theme_changed = 1;
+ if (cursor > NBUSERCOLORS)
+ mark_back = cursor;
+ else
+ mark_fore = cursor;
+ break;
+
+ case KEY_MOVE_DOWN:
+ if (cursor < SIZE - 1)
+ ++cursor;
+ break;
+
+ case KEY_MOVE_UP:
+ if (cursor > 0)
+ --cursor;
+ break;
+
+ case KEY_MOVE_LEFT:
+ if (cursor > NBUSERCOLORS)
+ cursor -= (NBUSERCOLORS + 1);
+ break;
+
+ case KEY_MOVE_RIGHT:
+ if (cursor <= NBUSERCOLORS)
+ cursor += (NBUSERCOLORS + 1);
+ break;
+
+ case KEY_GENERIC_CANCEL:
+ colorize = 0;
+ need_reset = 1;
+ break;
+ }
+
+ if (resize) {
+ resize = 0;
+ endwin();
+ wins_refresh();
+ curs_set(0);
+ need_reset = 1;
+ }
+
+ if (need_reset)
+ custom_confwin_init(&conf_win, label);
+
+ display_color_config(&conf_win, &mark_fore, &mark_back,
+ cursor, theme_changed);
+ }
+ delwin(conf_win.p);
}
/* Prints the general options. */
static int print_general_options(WINDOW * win)
{
- enum {
- AUTO_SAVE,
- AUTO_GC,
- PERIODIC_SAVE,
- CONFIRM_QUIT,
- CONFIRM_DELETE,
- SYSTEM_DIAGS,
- PROGRESS_BAR,
- FIRST_DAY_OF_WEEK,
- OUTPUT_DATE_FMT,
- INPUT_DATE_FMT,
- NB_OPTIONS
- };
- const int XPOS = 1;
- const int YOFF = 3;
- int y;
- char *opt[NB_OPTIONS] = {
- "general.autosave = ",
- "general.autogc = ",
- "general.periodicsave = ",
- "general.confirmquit = ",
- "general.confirmdelete = ",
- "general.systemdialogs = ",
- "general.progressbar = ",
- "general.firstdayofweek = ",
- "format.outputdate = ",
- "format.inputdate = "
- };
-
- y = 0;
- mvwprintw(win, y, XPOS, "[1] %s ", opt[AUTO_SAVE]);
- print_bool_option_incolor(win, conf.auto_save, y,
- XPOS + 4 + strlen(opt[AUTO_SAVE]));
- mvwaddstr(win, y + 1, XPOS,
- _("(if set to YES, automatic save is done when quitting)"));
- y += YOFF;
- mvwprintw(win, y, XPOS, "[2] %s ", opt[AUTO_GC]);
- print_bool_option_incolor(win, conf.auto_gc, y,
- XPOS + 4 + strlen(opt[AUTO_GC]));
- mvwaddstr(win, y + 1, XPOS, _("(run the garbage collector when quitting)"));
- y += YOFF;
- mvwprintw(win, y, XPOS, "[3] %s ", opt[PERIODIC_SAVE]);
- custom_apply_attr(win, ATTR_HIGHEST);
- mvwprintw(win, y, XPOS + 4 + strlen(opt[PERIODIC_SAVE]), "%d",
- conf.periodic_save);
- custom_remove_attr(win, ATTR_HIGHEST);
- mvwaddstr(win, y + 1, XPOS,
- _("(if not null, automatically save data every 'periodic_save' "
- "minutes)"));
- y += YOFF;
- mvwprintw(win, y, XPOS, "[4] %s ", opt[CONFIRM_QUIT]);
- print_bool_option_incolor(win, conf.confirm_quit, y,
- XPOS + 4 + strlen(opt[CONFIRM_QUIT]));
- mvwaddstr(win, y + 1, XPOS,
- _("(if set to YES, confirmation is required before quitting)"));
- y += YOFF;
- mvwprintw(win, y, XPOS, "[5] %s ", opt[CONFIRM_DELETE]);
- print_bool_option_incolor(win, conf.confirm_delete, y,
- XPOS + 4 + strlen(opt[CONFIRM_DELETE]));
- mvwaddstr(win, y + 1, XPOS,
- _("(if set to YES, confirmation is required "
- "before deleting an event)"));
- y += YOFF;
- mvwprintw(win, y, XPOS, "[6] %s ", opt[SYSTEM_DIAGS]);
- print_bool_option_incolor(win, conf.system_dialogs, y,
- XPOS + 4 + strlen(opt[SYSTEM_DIAGS]));
- mvwaddstr(win, y + 1, XPOS,
- _("(if set to YES, messages about loaded "
- "and saved data will be displayed)"));
- y += YOFF;
- mvwprintw(win, y, XPOS, "[7] %s ", opt[PROGRESS_BAR]);
- print_bool_option_incolor(win, conf.progress_bar, y,
- XPOS + 4 + strlen(opt[PROGRESS_BAR]));
- mvwaddstr(win, y + 1, XPOS,
- _("(if set to YES, progress bar will be displayed "
- "when saving data)"));
- y += YOFF;
- mvwprintw(win, y, XPOS, "[8] %s ", opt[FIRST_DAY_OF_WEEK]);
- custom_apply_attr(win, ATTR_HIGHEST);
- mvwaddstr(win, y, XPOS + 4 + strlen(opt[FIRST_DAY_OF_WEEK]),
- ui_calendar_week_begins_on_monday()? _("Monday") : _("Sunday"));
- custom_remove_attr(win, ATTR_HIGHEST);
- mvwaddstr(win, y + 1, XPOS,
- _("(specifies the first day of week in the calendar view)"));
- y += YOFF;
- mvwprintw(win, y, XPOS, "[9] %s ", opt[OUTPUT_DATE_FMT]);
- custom_apply_attr(win, ATTR_HIGHEST);
- mvwaddstr(win, y, XPOS + 4 + strlen(opt[OUTPUT_DATE_FMT]),
- conf.output_datefmt);
- custom_remove_attr(win, ATTR_HIGHEST);
- mvwaddstr(win, y + 1, XPOS,
- _("(Format of the date to be displayed in non-interactive mode)"));
- y += YOFF;
- mvwprintw(win, y, XPOS, "[0] %s ", opt[INPUT_DATE_FMT]);
- custom_apply_attr(win, ATTR_HIGHEST);
- mvwprintw(win, y, XPOS + 4 + strlen(opt[INPUT_DATE_FMT]), "%d",
- conf.input_datefmt);
- custom_remove_attr(win, ATTR_HIGHEST);
- mvwaddstr(win, y + 1, XPOS, _("(Format to be used when entering a date: "));
- mvwprintw(win, y + 2, XPOS, " (1) %s, (2) %s, (3) %s, (4) %s)",
- datefmt_str[0], datefmt_str[1], datefmt_str[2], datefmt_str[3]);
-
- return y + YOFF;
+ enum {
+ AUTO_SAVE,
+ AUTO_GC,
+ PERIODIC_SAVE,
+ CONFIRM_QUIT,
+ CONFIRM_DELETE,
+ SYSTEM_DIAGS,
+ PROGRESS_BAR,
+ FIRST_DAY_OF_WEEK,
+ OUTPUT_DATE_FMT,
+ INPUT_DATE_FMT,
+ NB_OPTIONS
+ };
+ const int XPOS = 1;
+ const int YOFF = 3;
+ int y;
+ char *opt[NB_OPTIONS] = {
+ "general.autosave = ",
+ "general.autogc = ",
+ "general.periodicsave = ",
+ "general.confirmquit = ",
+ "general.confirmdelete = ",
+ "general.systemdialogs = ",
+ "general.progressbar = ",
+ "general.firstdayofweek = ",
+ "format.outputdate = ",
+ "format.inputdate = "
+ };
+
+ y = 0;
+ mvwprintw(win, y, XPOS, "[1] %s ", opt[AUTO_SAVE]);
+ print_bool_option_incolor(win, conf.auto_save, y,
+ XPOS + 4 + strlen(opt[AUTO_SAVE]));
+ mvwaddstr(win, y + 1, XPOS,
+ _("(if set to YES, automatic save is done when quitting)"));
+ y += YOFF;
+ mvwprintw(win, y, XPOS, "[2] %s ", opt[AUTO_GC]);
+ print_bool_option_incolor(win, conf.auto_gc, y,
+ XPOS + 4 + strlen(opt[AUTO_GC]));
+ mvwaddstr(win, y + 1, XPOS,
+ _("(run the garbage collector when quitting)"));
+ y += YOFF;
+ mvwprintw(win, y, XPOS, "[3] %s ", opt[PERIODIC_SAVE]);
+ custom_apply_attr(win, ATTR_HIGHEST);
+ mvwprintw(win, y, XPOS + 4 + strlen(opt[PERIODIC_SAVE]), "%d",
+ conf.periodic_save);
+ custom_remove_attr(win, ATTR_HIGHEST);
+ mvwaddstr(win, y + 1, XPOS,
+ _("(if not null, automatically save data every 'periodic_save' "
+ "minutes)"));
+ y += YOFF;
+ mvwprintw(win, y, XPOS, "[4] %s ", opt[CONFIRM_QUIT]);
+ print_bool_option_incolor(win, conf.confirm_quit, y,
+ XPOS + 4 + strlen(opt[CONFIRM_QUIT]));
+ mvwaddstr(win, y + 1, XPOS,
+ _("(if set to YES, confirmation is required before quitting)"));
+ y += YOFF;
+ mvwprintw(win, y, XPOS, "[5] %s ", opt[CONFIRM_DELETE]);
+ print_bool_option_incolor(win, conf.confirm_delete, y,
+ XPOS + 4 + strlen(opt[CONFIRM_DELETE]));
+ mvwaddstr(win, y + 1, XPOS,
+ _("(if set to YES, confirmation is required "
+ "before deleting an event)"));
+ y += YOFF;
+ mvwprintw(win, y, XPOS, "[6] %s ", opt[SYSTEM_DIAGS]);
+ print_bool_option_incolor(win, conf.system_dialogs, y,
+ XPOS + 4 + strlen(opt[SYSTEM_DIAGS]));
+ mvwaddstr(win, y + 1, XPOS,
+ _("(if set to YES, messages about loaded "
+ "and saved data will be displayed)"));
+ y += YOFF;
+ mvwprintw(win, y, XPOS, "[7] %s ", opt[PROGRESS_BAR]);
+ print_bool_option_incolor(win, conf.progress_bar, y,
+ XPOS + 4 + strlen(opt[PROGRESS_BAR]));
+ mvwaddstr(win, y + 1, XPOS,
+ _("(if set to YES, progress bar will be displayed "
+ "when saving data)"));
+ y += YOFF;
+ mvwprintw(win, y, XPOS, "[8] %s ", opt[FIRST_DAY_OF_WEEK]);
+ custom_apply_attr(win, ATTR_HIGHEST);
+ mvwaddstr(win, y, XPOS + 4 + strlen(opt[FIRST_DAY_OF_WEEK]),
+ ui_calendar_week_begins_on_monday()? _("Monday") :
+ _("Sunday"));
+ custom_remove_attr(win, ATTR_HIGHEST);
+ mvwaddstr(win, y + 1, XPOS,
+ _("(specifies the first day of week in the calendar view)"));
+ y += YOFF;
+ mvwprintw(win, y, XPOS, "[9] %s ", opt[OUTPUT_DATE_FMT]);
+ custom_apply_attr(win, ATTR_HIGHEST);
+ mvwaddstr(win, y, XPOS + 4 + strlen(opt[OUTPUT_DATE_FMT]),
+ conf.output_datefmt);
+ custom_remove_attr(win, ATTR_HIGHEST);
+ mvwaddstr(win, y + 1, XPOS,
+ _("(Format of the date to be displayed in non-interactive mode)"));
+ y += YOFF;
+ mvwprintw(win, y, XPOS, "[0] %s ", opt[INPUT_DATE_FMT]);
+ custom_apply_attr(win, ATTR_HIGHEST);
+ mvwprintw(win, y, XPOS + 4 + strlen(opt[INPUT_DATE_FMT]), "%d",
+ conf.input_datefmt);
+ custom_remove_attr(win, ATTR_HIGHEST);
+ mvwaddstr(win, y + 1, XPOS,
+ _("(Format to be used when entering a date: "));
+ mvwprintw(win, y + 2, XPOS, " (1) %s, (2) %s, (3) %s, (4) %s)",
+ datefmt_str[0], datefmt_str[1], datefmt_str[2],
+ datefmt_str[3]);
+
+ return y + YOFF;
}
void custom_set_swsiz(struct scrollwin *sw)
{
- sw->win.x = 0;
- sw->win.y = 0;
- sw->win.h = (notify_bar())? row - 3 : row - 2;
- sw->win.w = col;
-
- sw->pad.x = 1;
- sw->pad.y = 3;
- sw->pad.h = BUFSIZ;
- sw->pad.w = col - 2 * sw->pad.x - 1;
+ sw->win.x = 0;
+ sw->win.y = 0;
+ sw->win.h = (notify_bar())? row - 3 : row - 2;
+ sw->win.w = col;
+
+ sw->pad.x = 1;
+ sw->pad.y = 3;
+ sw->pad.h = BUFSIZ;
+ sw->pad.w = col - 2 * sw->pad.x - 1;
}
/* General configuration. */
void custom_general_config(void)
{
- struct scrollwin cwin;
- const char *number_str = _("Enter an option number to change its value");
- const char *keys = _("(Press '^P' or '^N' to move up or down, 'Q' to quit)");
- const char *output_datefmt_str =
- _("Enter the date format (see 'man 3 strftime' for possible formats) ");
- const char *input_datefmt_prefix = _("Enter the date format: ");
- const char *periodic_save_str =
- _("Enter the delay, in minutes, between automatic saves (0 to disable) ");
- int ch;
- int val;
- char *buf;
-
- clear();
- custom_set_swsiz(&cwin);
- cwin.label = _("general options");
- wins_scrollwin_init(&cwin);
- wins_show(cwin.win.p, cwin.label);
- status_mesg(number_str, keys);
- cwin.total_lines = print_general_options(cwin.pad.p);
- wins_scrollwin_display(&cwin);
-
- buf = mem_malloc(BUFSIZ);
- while ((ch = wgetch(win[KEY].p)) != 'q') {
- buf[0] = '\0';
-
- switch (ch) {
- case CTRL('N'):
- wins_scrollwin_down(&cwin, 1);
- break;
- case CTRL('P'):
- wins_scrollwin_up(&cwin, 1);
- break;
- case '1':
- conf.auto_save = !conf.auto_save;
- break;
- case '2':
- conf.auto_gc = !conf.auto_gc;
- break;
- case '3':
- status_mesg(periodic_save_str, "");
- if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
- val = atoi(buf);
- if (val >= 0)
- conf.periodic_save = val;
- if (conf.periodic_save > 0)
- io_start_psave_thread();
- else if (conf.periodic_save == 0)
- io_stop_psave_thread();
- }
- status_mesg(number_str, keys);
- break;
- case '4':
- conf.confirm_quit = !conf.confirm_quit;
- break;
- case '5':
- conf.confirm_delete = !conf.confirm_delete;
- break;
- case '6':
- conf.system_dialogs = !conf.system_dialogs;
- break;
- case '7':
- conf.progress_bar = !conf.progress_bar;
- break;
- case '8':
- ui_calendar_change_first_day_of_week();
- break;
- case '9':
- status_mesg(output_datefmt_str, "");
- strncpy(buf, conf.output_datefmt, strlen(conf.output_datefmt) + 1);
- if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
- strncpy(conf.output_datefmt, buf, strlen(buf) + 1);
- }
- status_mesg(number_str, keys);
- break;
- case '0':
- val = status_ask_simplechoice(input_datefmt_prefix,
- datefmt_str, DATE_FORMATS);
- if (val != -1)
- conf.input_datefmt = val;
- break;
- }
-
- if (resize) {
- resize = 0;
- wins_reset();
- wins_scrollwin_delete(&cwin);
- custom_set_swsiz(&cwin);
- wins_scrollwin_init(&cwin);
- wins_show(cwin.win.p, cwin.label);
- cwin.first_visible_line = 0;
- delwin(win[STA].p);
- win[STA].p = newwin(win[STA].h, win[STA].w, win[STA].y, win[STA].x);
- keypad(win[STA].p, TRUE);
- if (notify_bar()) {
- notify_reinit_bar();
- notify_update_bar();
- }
- }
-
- status_mesg(number_str, keys);
- cwin.total_lines = print_general_options(cwin.pad.p);
- wins_scrollwin_display(&cwin);
- }
- mem_free(buf);
- wins_scrollwin_delete(&cwin);
+ struct scrollwin cwin;
+ const char *number_str =
+ _("Enter an option number to change its value");
+ const char *keys =
+ _("(Press '^P' or '^N' to move up or down, 'Q' to quit)");
+ const char *output_datefmt_str =
+ _("Enter the date format (see 'man 3 strftime' for possible formats) ");
+ const char *input_datefmt_prefix = _("Enter the date format: ");
+ const char *periodic_save_str =
+ _("Enter the delay, in minutes, between automatic saves (0 to disable) ");
+ int ch;
+ int val;
+ char *buf;
+
+ clear();
+ custom_set_swsiz(&cwin);
+ cwin.label = _("general options");
+ wins_scrollwin_init(&cwin);
+ wins_show(cwin.win.p, cwin.label);
+ status_mesg(number_str, keys);
+ cwin.total_lines = print_general_options(cwin.pad.p);
+ wins_scrollwin_display(&cwin);
+
+ buf = mem_malloc(BUFSIZ);
+ while ((ch = wgetch(win[KEY].p)) != 'q') {
+ buf[0] = '\0';
+
+ switch (ch) {
+ case CTRL('N'):
+ wins_scrollwin_down(&cwin, 1);
+ break;
+ case CTRL('P'):
+ wins_scrollwin_up(&cwin, 1);
+ break;
+ case '1':
+ conf.auto_save = !conf.auto_save;
+ break;
+ case '2':
+ conf.auto_gc = !conf.auto_gc;
+ break;
+ case '3':
+ status_mesg(periodic_save_str, "");
+ if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
+ val = atoi(buf);
+ if (val >= 0)
+ conf.periodic_save = val;
+ if (conf.periodic_save > 0)
+ io_start_psave_thread();
+ else if (conf.periodic_save == 0)
+ io_stop_psave_thread();
+ }
+ status_mesg(number_str, keys);
+ break;
+ case '4':
+ conf.confirm_quit = !conf.confirm_quit;
+ break;
+ case '5':
+ conf.confirm_delete = !conf.confirm_delete;
+ break;
+ case '6':
+ conf.system_dialogs = !conf.system_dialogs;
+ break;
+ case '7':
+ conf.progress_bar = !conf.progress_bar;
+ break;
+ case '8':
+ ui_calendar_change_first_day_of_week();
+ break;
+ case '9':
+ status_mesg(output_datefmt_str, "");
+ strncpy(buf, conf.output_datefmt,
+ strlen(conf.output_datefmt) + 1);
+ if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
+ strncpy(conf.output_datefmt, buf,
+ strlen(buf) + 1);
+ }
+ status_mesg(number_str, keys);
+ break;
+ case '0':
+ val = status_ask_simplechoice(input_datefmt_prefix,
+ datefmt_str,
+ DATE_FORMATS);
+ if (val != -1)
+ conf.input_datefmt = val;
+ break;
+ }
+
+ if (resize) {
+ resize = 0;
+ wins_reset();
+ wins_scrollwin_delete(&cwin);
+ custom_set_swsiz(&cwin);
+ wins_scrollwin_init(&cwin);
+ wins_show(cwin.win.p, cwin.label);
+ cwin.first_visible_line = 0;
+ delwin(win[STA].p);
+ win[STA].p =
+ newwin(win[STA].h, win[STA].w, win[STA].y,
+ win[STA].x);
+ keypad(win[STA].p, TRUE);
+ if (notify_bar()) {
+ notify_reinit_bar();
+ notify_update_bar();
+ }
+ }
+
+ status_mesg(number_str, keys);
+ cwin.total_lines = print_general_options(cwin.pad.p);
+ wins_scrollwin_display(&cwin);
+ }
+ mem_free(buf);
+ wins_scrollwin_delete(&cwin);
}
static void
print_key_incolor(WINDOW * win, const char *option, int pos_y, int pos_x)
{
- const int color = ATTR_HIGHEST;
+ const int color = ATTR_HIGHEST;
- RETURN_IF(!option, _("Undefined option!"));
- custom_apply_attr(win, color);
- mvwprintw(win, pos_y, pos_x, "%s ", option);
- custom_remove_attr(win, color);
+ RETURN_IF(!option, _("Undefined option!"));
+ custom_apply_attr(win, color);
+ mvwprintw(win, pos_y, pos_x, "%s ", option);
+ custom_remove_attr(win, color);
}
static int
-print_keys_bindings(WINDOW * win, int selected_row, int selected_elm, int yoff)
+print_keys_bindings(WINDOW * win, int selected_row, int selected_elm,
+ int yoff)
{
- const int XPOS = 1;
- const int EQUALPOS = 23;
- const int KEYPOS = 25;
- int noelm, action, y;
-
- noelm = y = 0;
- for (action = 0; action < NBKEYS; action++) {
- char actionstr[BUFSIZ];
- int nbkeys;
-
- nbkeys = keys_action_count_keys(action);
- snprintf(actionstr, BUFSIZ, "%s", keys_get_label(action));
- if (action == selected_row)
- custom_apply_attr(win, ATTR_HIGHEST);
- mvwprintw(win, y, XPOS, "%s ", actionstr);
- mvwaddstr(win, y, EQUALPOS, "=");
- if (nbkeys == 0)
- mvwaddstr(win, y, KEYPOS, _("undefined"));
- if (action == selected_row)
- custom_remove_attr(win, ATTR_HIGHEST);
- if (nbkeys > 0) {
- if (action == selected_row) {
- const char *key;
- int pos;
-
- pos = KEYPOS;
- while ((key = keys_action_nkey(action, noelm)) != NULL) {
- if (noelm == selected_elm)
- print_key_incolor(win, key, y, pos);
- else
- mvwprintw(win, y, pos, "%s ", key);
- noelm++;
- pos += strlen(key) + 1;
- }
- } else {
- mvwaddstr(win, y, KEYPOS, keys_action_allkeys(action));
- }
- }
- y += yoff;
- }
-
- return noelm;
+ const int XPOS = 1;
+ const int EQUALPOS = 23;
+ const int KEYPOS = 25;
+ int noelm, action, y;
+
+ noelm = y = 0;
+ for (action = 0; action < NBKEYS; action++) {
+ char actionstr[BUFSIZ];
+ int nbkeys;
+
+ nbkeys = keys_action_count_keys(action);
+ snprintf(actionstr, BUFSIZ, "%s", keys_get_label(action));
+ if (action == selected_row)
+ custom_apply_attr(win, ATTR_HIGHEST);
+ mvwprintw(win, y, XPOS, "%s ", actionstr);
+ mvwaddstr(win, y, EQUALPOS, "=");
+ if (nbkeys == 0)
+ mvwaddstr(win, y, KEYPOS, _("undefined"));
+ if (action == selected_row)
+ custom_remove_attr(win, ATTR_HIGHEST);
+ if (nbkeys > 0) {
+ if (action == selected_row) {
+ const char *key;
+ int pos;
+
+ pos = KEYPOS;
+ while ((key =
+ keys_action_nkey(action,
+ noelm)) != NULL) {
+ if (noelm == selected_elm)
+ print_key_incolor(win, key,
+ y, pos);
+ else
+ mvwprintw(win, y, pos,
+ "%s ", key);
+ noelm++;
+ pos += strlen(key) + 1;
+ }
+ } else {
+ mvwaddstr(win, y, KEYPOS,
+ keys_action_allkeys(action));
+ }
+ }
+ y += yoff;
+ }
+
+ return noelm;
}
static void custom_keys_config_bar(void)
{
- struct binding quit = { _("Exit"), KEY_GENERIC_QUIT };
- struct binding info = { _("Key info"), KEY_GENERIC_HELP };
- struct binding add = { _("Add key"), KEY_ADD_ITEM };
- struct binding del = { _("Del key"), KEY_DEL_ITEM };
- struct binding up = { _("Up"), KEY_MOVE_UP };
- struct binding down = { _("Down"), KEY_MOVE_DOWN };
- struct binding left = { _("Prev Key"), KEY_MOVE_LEFT };
- struct binding right = { _("Next Key"), KEY_MOVE_RIGHT };
-
- struct binding *bindings[] = {
- &quit, &info, &add, &del, &up, &down, &left, &right
- };
- int bindings_size = sizeof(bindings) / sizeof(bindings[0]);
-
- keys_display_bindings_bar(win[STA].p, bindings, bindings_size, 0,
- bindings_size, NULL);
+ struct binding quit = { _("Exit"), KEY_GENERIC_QUIT };
+ struct binding info = { _("Key info"), KEY_GENERIC_HELP };
+ struct binding add = { _("Add key"), KEY_ADD_ITEM };
+ struct binding del = { _("Del key"), KEY_DEL_ITEM };
+ struct binding up = { _("Up"), KEY_MOVE_UP };
+ struct binding down = { _("Down"), KEY_MOVE_DOWN };
+ struct binding left = { _("Prev Key"), KEY_MOVE_LEFT };
+ struct binding right = { _("Next Key"), KEY_MOVE_RIGHT };
+
+ struct binding *bindings[] = {
+ &quit, &info, &add, &del, &up, &down, &left, &right
+ };
+ int bindings_size = sizeof(bindings) / sizeof(bindings[0]);
+
+ keys_display_bindings_bar(win[STA].p, bindings, bindings_size, 0,
+ bindings_size, NULL);
}
void custom_keys_config(void)
{
- struct scrollwin kwin;
- int selrow, selelm, firstrow, lastrow, nbrowelm, nbdisplayed;
- int keyval, used, not_recognized;
- const char *keystr;
- WINDOW *grabwin;
- const int LINESPERKEY = 2;
- const int LABELLINES = 3;
-
- clear();
- custom_set_swsiz(&kwin);
- nbdisplayed = (kwin.win.h - LABELLINES) / LINESPERKEY;
- kwin.label = _("keys configuration");
- wins_scrollwin_init(&kwin);
- wins_show(kwin.win.p, kwin.label);
- custom_keys_config_bar();
- selrow = selelm = 0;
- nbrowelm = print_keys_bindings(kwin.pad.p, selrow, selelm, LINESPERKEY);
- kwin.total_lines = NBKEYS * LINESPERKEY;
- wins_scrollwin_display(&kwin);
- firstrow = 0;
- lastrow = firstrow + nbdisplayed - 1;
- for (;;) {
- int ch;
-
- ch = keys_getch(win[KEY].p, NULL, NULL);
- switch (ch) {
- case KEY_MOVE_UP:
- if (selrow > 0) {
- selrow--;
- selelm = 0;
- if (selrow == firstrow) {
- firstrow--;
- lastrow--;
- wins_scrollwin_up(&kwin, LINESPERKEY);
- }
- }
- break;
- case KEY_MOVE_DOWN:
- if (selrow < NBKEYS - 1) {
- selrow++;
- selelm = 0;
- if (selrow == lastrow) {
- firstrow++;
- lastrow++;
- wins_scrollwin_down(&kwin, LINESPERKEY);
- }
- }
- break;
- case KEY_MOVE_LEFT:
- if (selelm > 0)
- selelm--;
- break;
- case KEY_MOVE_RIGHT:
- if (selelm < nbrowelm - 1)
- selelm++;
- break;
- case KEY_GENERIC_HELP:
- keys_popup_info(selrow);
- break;
- case KEY_ADD_ITEM:
+ struct scrollwin kwin;
+ int selrow, selelm, firstrow, lastrow, nbrowelm, nbdisplayed;
+ int keyval, used, not_recognized;
+ const char *keystr;
+ WINDOW *grabwin;
+ const int LINESPERKEY = 2;
+ const int LABELLINES = 3;
+
+ clear();
+ custom_set_swsiz(&kwin);
+ nbdisplayed = (kwin.win.h - LABELLINES) / LINESPERKEY;
+ kwin.label = _("keys configuration");
+ wins_scrollwin_init(&kwin);
+ wins_show(kwin.win.p, kwin.label);
+ custom_keys_config_bar();
+ selrow = selelm = 0;
+ nbrowelm =
+ print_keys_bindings(kwin.pad.p, selrow, selelm, LINESPERKEY);
+ kwin.total_lines = NBKEYS * LINESPERKEY;
+ wins_scrollwin_display(&kwin);
+ firstrow = 0;
+ lastrow = firstrow + nbdisplayed - 1;
+ for (;;) {
+ int ch;
+
+ ch = keys_getch(win[KEY].p, NULL, NULL);
+ switch (ch) {
+ case KEY_MOVE_UP:
+ if (selrow > 0) {
+ selrow--;
+ selelm = 0;
+ if (selrow == firstrow) {
+ firstrow--;
+ lastrow--;
+ wins_scrollwin_up(&kwin,
+ LINESPERKEY);
+ }
+ }
+ break;
+ case KEY_MOVE_DOWN:
+ if (selrow < NBKEYS - 1) {
+ selrow++;
+ selelm = 0;
+ if (selrow == lastrow) {
+ firstrow++;
+ lastrow++;
+ wins_scrollwin_down(&kwin,
+ LINESPERKEY);
+ }
+ }
+ break;
+ case KEY_MOVE_LEFT:
+ if (selelm > 0)
+ selelm--;
+ break;
+ case KEY_MOVE_RIGHT:
+ if (selelm < nbrowelm - 1)
+ selelm++;
+ break;
+ case KEY_GENERIC_HELP:
+ keys_popup_info(selrow);
+ break;
+ case KEY_ADD_ITEM:
#define WINROW 10
#define WINCOL 50
- do {
- used = 0;
- grabwin = popup(WINROW, WINCOL, (row - WINROW) / 2,
- (col - WINCOL) / 2,
- _("Press the key you want to assign to:"),
- keys_get_label(selrow), 0);
- keyval = wgetch(grabwin);
-
- /* First check if this key would be recognized by calcurse. */
- if (keys_str2int(keys_int2str(keyval)) == -1) {
- not_recognized = 1;
- WARN_MSG(_("This key is not yet recognized by calcurse, "
- "please choose another one."));
- werase(kwin.pad.p);
- nbrowelm = print_keys_bindings(kwin.pad.p, selrow, selelm,
- LINESPERKEY);
- wins_scrollwin_display(&kwin);
- continue;
- } else {
- not_recognized = 0;
- }
-
- /* Is the binding used by this action already? If so, just end the reassignment */
- if (selrow == keys_get_action(keyval)) {
- delwin(grabwin);
- break;
- }
-
- used = keys_assign_binding(keyval, selrow);
- if (used) {
- enum key action;
-
- action = keys_get_action(keyval);
- WARN_MSG(_("This key is already in use for %s, "
- "please choose another one."), keys_get_label(action));
- werase(kwin.pad.p);
- nbrowelm = print_keys_bindings(kwin.pad.p, selrow, selelm,
- LINESPERKEY);
- wins_scrollwin_display(&kwin);
- }
- delwin(grabwin);
- }
- while (used || not_recognized);
- nbrowelm++;
- if (selelm < nbrowelm - 1)
- selelm++;
+ do {
+ used = 0;
+ grabwin =
+ popup(WINROW, WINCOL,
+ (row - WINROW) / 2,
+ (col - WINCOL) / 2,
+ _("Press the key you want to assign to:"),
+ keys_get_label(selrow), 0);
+ keyval = wgetch(grabwin);
+
+ /* First check if this key would be recognized by calcurse. */
+ if (keys_str2int(keys_int2str(keyval)) ==
+ -1) {
+ not_recognized = 1;
+ WARN_MSG(_("This key is not yet recognized by calcurse, "
+ "please choose another one."));
+ werase(kwin.pad.p);
+ nbrowelm =
+ print_keys_bindings(kwin.pad.p,
+ selrow,
+ selelm,
+ LINESPERKEY);
+ wins_scrollwin_display(&kwin);
+ continue;
+ } else {
+ not_recognized = 0;
+ }
+
+ /* Is the binding used by this action already? If so, just end the reassignment */
+ if (selrow == keys_get_action(keyval)) {
+ delwin(grabwin);
+ break;
+ }
+
+ used = keys_assign_binding(keyval, selrow);
+ if (used) {
+ enum key action;
+
+ action = keys_get_action(keyval);
+ WARN_MSG(_("This key is already in use for %s, "
+ "please choose another one."),
+ keys_get_label(action));
+ werase(kwin.pad.p);
+ nbrowelm =
+ print_keys_bindings(kwin.pad.p,
+ selrow,
+ selelm,
+ LINESPERKEY);
+ wins_scrollwin_display(&kwin);
+ }
+ delwin(grabwin);
+ }
+ while (used || not_recognized);
+ nbrowelm++;
+ if (selelm < nbrowelm - 1)
+ selelm++;
#undef WINROW
#undef WINCOL
- break;
- case KEY_DEL_ITEM:
- keystr = keys_action_nkey(selrow, selelm);
- keyval = keys_str2int(keystr);
- keys_remove_binding(keyval, selrow);
- nbrowelm--;
- if (selelm > 0 && selelm <= nbrowelm)
- selelm--;
- break;
- case KEY_GENERIC_QUIT:
- if (keys_check_missing_bindings() != 0) {
- WARN_MSG(_("Some actions do not have any associated " "key bindings!"));
- }
- wins_scrollwin_delete(&kwin);
- return;
- }
- custom_keys_config_bar();
- werase(kwin.pad.p);
- nbrowelm = print_keys_bindings(kwin.pad.p, selrow, selelm, LINESPERKEY);
- wins_scrollwin_display(&kwin);
- }
+ break;
+ case KEY_DEL_ITEM:
+ keystr = keys_action_nkey(selrow, selelm);
+ keyval = keys_str2int(keystr);
+ keys_remove_binding(keyval, selrow);
+ nbrowelm--;
+ if (selelm > 0 && selelm <= nbrowelm)
+ selelm--;
+ break;
+ case KEY_GENERIC_QUIT:
+ if (keys_check_missing_bindings() != 0) {
+ WARN_MSG(_("Some actions do not have any associated "
+ "key bindings!"));
+ }
+ wins_scrollwin_delete(&kwin);
+ return;
+ }
+ custom_keys_config_bar();
+ werase(kwin.pad.p);
+ nbrowelm =
+ print_keys_bindings(kwin.pad.p, selrow, selelm,
+ LINESPERKEY);
+ wins_scrollwin_display(&kwin);
+ }
}
void custom_config_main(void)
{
- const char *no_color_support =
- _("Sorry, colors are not supported by your terminal\n"
- "(Press [ENTER] to continue)");
- int ch;
- int old_layout;
-
- custom_config_bar();
- while ((ch = wgetch(win[KEY].p)) != 'q') {
- switch (ch) {
- case 'C':
- case 'c':
- if (has_colors()) {
- custom_color_config();
- } else {
- colorize = 0;
- wins_erase_status_bar();
- mvwaddstr(win[STA].p, 0, 0, no_color_support);
- wgetch(win[KEY].p);
- }
- break;
- case 'L':
- case 'l':
- old_layout = wins_layout();
- custom_layout_config();
- if (wins_layout() != old_layout)
- wins_reset();
- break;
- case 'G':
- case 'g':
- custom_general_config();
- break;
- case 'N':
- case 'n':
- notify_config_bar();
- break;
- case 'K':
- case 'k':
- custom_keys_config();
- break;
- case 's':
- case 'S':
- custom_sidebar_config();
- break;
- default:
- continue;
- }
- wins_update(FLAG_ALL);
- wins_erase_status_bar();
- custom_config_bar();
- }
+ const char *no_color_support =
+ _("Sorry, colors are not supported by your terminal\n"
+ "(Press [ENTER] to continue)");
+ int ch;
+ int old_layout;
+
+ custom_config_bar();
+ while ((ch = wgetch(win[KEY].p)) != 'q') {
+ switch (ch) {
+ case 'C':
+ case 'c':
+ if (has_colors()) {
+ custom_color_config();
+ } else {
+ colorize = 0;
+ wins_erase_status_bar();
+ mvwaddstr(win[STA].p, 0, 0,
+ no_color_support);
+ wgetch(win[KEY].p);
+ }
+ break;
+ case 'L':
+ case 'l':
+ old_layout = wins_layout();
+ custom_layout_config();
+ if (wins_layout() != old_layout)
+ wins_reset();
+ break;
+ case 'G':
+ case 'g':
+ custom_general_config();
+ break;
+ case 'N':
+ case 'n':
+ notify_config_bar();
+ break;
+ case 'K':
+ case 'k':
+ custom_keys_config();
+ break;
+ case 's':
+ case 'S':
+ custom_sidebar_config();
+ break;
+ default:
+ continue;
+ }
+ wins_update(FLAG_ALL);
+ wins_erase_status_bar();
+ custom_config_bar();
+ }
}
diff --git a/src/day.c b/src/day.c
index 35e17d6..48a6f18 100644
--- a/src/day.c
+++ b/src/day.c
@@ -46,12 +46,12 @@ static llist_t day_items;
static void day_free(struct day_item *day)
{
- mem_free(day);
+ mem_free(day);
}
static void day_init_list(void)
{
- LLIST_INIT(&day_items);
+ LLIST_INIT(&day_items);
}
/*
@@ -61,148 +61,149 @@ static void day_init_list(void)
*/
void day_free_list(void)
{
- LLIST_FREE_INNER(&day_items, day_free);
- LLIST_FREE(&day_items);
+ LLIST_FREE_INNER(&day_items, day_free);
+ LLIST_FREE(&day_items);
}
static int day_cmp_start(struct day_item *a, struct day_item *b)
{
- if (a->type <= EVNT) {
- if (b->type <= EVNT)
- return 0;
- else
- return -1;
- } else if (b->type <= EVNT) {
- return 1;
- } else {
- return a->start < b->start ? -1 : (a->start == b->start ? 0 : 1);
- }
+ if (a->type <= EVNT) {
+ if (b->type <= EVNT)
+ return 0;
+ else
+ return -1;
+ } else if (b->type <= EVNT) {
+ return 1;
+ } else {
+ return a->start < b->start ? -1 : (a->start ==
+ b->start ? 0 : 1);
+ }
}
/* Add an item to the current day list. */
static void day_add_item(int type, long start, union aptev_ptr item)
{
- struct day_item *day = mem_malloc(sizeof(struct day_item));
- day->type = type;
- day->start = start;
- day->item = item;
+ struct day_item *day = mem_malloc(sizeof(struct day_item));
+ day->type = type;
+ day->start = start;
+ day->item = item;
- LLIST_ADD_SORTED(&day_items, day, day_cmp_start);
+ LLIST_ADD_SORTED(&day_items, day, day_cmp_start);
}
/* Get the message of an item. */
char *day_item_get_mesg(struct day_item *day)
{
- switch (day->type) {
- case APPT:
- return day->item.apt->mesg;
- case EVNT:
- return day->item.ev->mesg;
- case RECUR_APPT:
- return day->item.rapt->mesg;
- case RECUR_EVNT:
- return day->item.rev->mesg;
- default:
- return NULL;
- }
+ switch (day->type) {
+ case APPT:
+ return day->item.apt->mesg;
+ case EVNT:
+ return day->item.ev->mesg;
+ case RECUR_APPT:
+ return day->item.rapt->mesg;
+ case RECUR_EVNT:
+ return day->item.rev->mesg;
+ default:
+ return NULL;
+ }
}
/* Get the note attached to an item. */
char *day_item_get_note(struct day_item *day)
{
- switch (day->type) {
- case APPT:
- return day->item.apt->note;
- case EVNT:
- return day->item.ev->note;
- case RECUR_APPT:
- return day->item.rapt->note;
- case RECUR_EVNT:
- return day->item.rev->note;
- default:
- return NULL;
- }
+ switch (day->type) {
+ case APPT:
+ return day->item.apt->note;
+ case EVNT:
+ return day->item.ev->note;
+ case RECUR_APPT:
+ return day->item.rapt->note;
+ case RECUR_EVNT:
+ return day->item.rev->note;
+ default:
+ return NULL;
+ }
}
/* Get the note attached to an item. */
void day_item_erase_note(struct day_item *day)
{
- switch (day->type) {
- case APPT:
- erase_note(&day->item.apt->note);
- break;
- case EVNT:
- erase_note(&day->item.ev->note);
- break;
- case RECUR_APPT:
- erase_note(&day->item.rapt->note);
- break;
- case RECUR_EVNT:
- erase_note(&day->item.rev->note);
- break;
- }
+ switch (day->type) {
+ case APPT:
+ erase_note(&day->item.apt->note);
+ break;
+ case EVNT:
+ erase_note(&day->item.ev->note);
+ break;
+ case RECUR_APPT:
+ erase_note(&day->item.rapt->note);
+ break;
+ case RECUR_EVNT:
+ erase_note(&day->item.rev->note);
+ break;
+ }
}
/* Get the duration of an item. */
long day_item_get_duration(struct day_item *day)
{
- switch (day->type) {
- case APPT:
- return day->item.apt->dur;
- case RECUR_APPT:
- return day->item.rapt->dur;
- default:
- return 0;
- }
+ switch (day->type) {
+ case APPT:
+ return day->item.apt->dur;
+ case RECUR_APPT:
+ return day->item.rapt->dur;
+ default:
+ return 0;
+ }
}
/* Get the notification state of an item. */
int day_item_get_state(struct day_item *day)
{
- switch (day->type) {
- case APPT:
- return day->item.apt->state;
- case RECUR_APPT:
- return day->item.rapt->state;
- default:
- return APOINT_NULL;
- }
+ switch (day->type) {
+ case APPT:
+ return day->item.apt->state;
+ case RECUR_APPT:
+ return day->item.rapt->state;
+ default:
+ return APOINT_NULL;
+ }
}
/* Add an exception to an item. */
void day_item_add_exc(struct day_item *day, long date)
{
- switch (day->type) {
- case RECUR_EVNT:
- recur_event_add_exc(day->item.rev, date);
- case RECUR_APPT:
- recur_apoint_add_exc(day->item.rapt, date);
- }
+ switch (day->type) {
+ case RECUR_EVNT:
+ recur_event_add_exc(day->item.rev, date);
+ case RECUR_APPT:
+ recur_apoint_add_exc(day->item.rapt, date);
+ }
}
/* Clone the actual item. */
void day_item_fork(struct day_item *day_in, struct day_item *day_out)
{
- day_out->type = day_in->type;
- day_out->start = day_in->start;
-
- switch (day_in->type) {
- case APPT:
- day_out->item.apt = apoint_dup(day_in->item.apt);
- break;
- case EVNT:
- day_out->item.ev = event_dup(day_in->item.ev);
- break;
- case RECUR_APPT:
- day_out->item.rapt = recur_apoint_dup(day_in->item.rapt);
- break;
- case RECUR_EVNT:
- day_out->item.rev = recur_event_dup(day_in->item.rev);
- break;
- default:
- EXIT(_("unknown item type"));
- /* NOTREACHED */
- }
+ day_out->type = day_in->type;
+ day_out->start = day_in->start;
+
+ switch (day_in->type) {
+ case APPT:
+ day_out->item.apt = apoint_dup(day_in->item.apt);
+ break;
+ case EVNT:
+ day_out->item.ev = event_dup(day_in->item.ev);
+ break;
+ case RECUR_APPT:
+ day_out->item.rapt = recur_apoint_dup(day_in->item.rapt);
+ break;
+ case RECUR_EVNT:
+ day_out->item.rev = recur_event_dup(day_in->item.rev);
+ break;
+ default:
+ EXIT(_("unknown item type"));
+ /* NOTREACHED */
+ }
}
/*
@@ -212,24 +213,24 @@ void day_item_fork(struct day_item *day_in, struct day_item *day_out)
* dedicated to the selected day.
* Returns the number of events for the selected day.
*/
-static int day_store_events(long date, regex_t *regex)
+static int day_store_events(long date, regex_t * regex)
{
- llist_item_t *i;
- union aptev_ptr p;
- int e_nb = 0;
+ llist_item_t *i;
+ union aptev_ptr p;
+ int e_nb = 0;
- LLIST_FIND_FOREACH_CONT(&eventlist, &date, event_inday, i) {
- struct event *ev = LLIST_TS_GET_DATA(i);
+ LLIST_FIND_FOREACH_CONT(&eventlist, &date, event_inday, i) {
+ struct event *ev = LLIST_TS_GET_DATA(i);
- if (regex && regexec(regex, ev->mesg, 0, 0, 0) != 0)
- continue;
+ if (regex && regexec(regex, ev->mesg, 0, 0, 0) != 0)
+ continue;
- p.ev = ev;
- day_add_item(EVNT, ev->day, p);
- e_nb++;
- }
+ p.ev = ev;
+ day_add_item(EVNT, ev->day, p);
+ e_nb++;
+ }
- return e_nb;
+ return e_nb;
}
/*
@@ -239,24 +240,24 @@ static int day_store_events(long date, regex_t *regex)
* dedicated to the selected day.
* Returns the number of recurrent events for the selected day.
*/
-static int day_store_recur_events(long date, regex_t *regex)
+static int day_store_recur_events(long date, regex_t * regex)
{
- llist_item_t *i;
- union aptev_ptr p;
- int e_nb = 0;
+ llist_item_t *i;
+ union aptev_ptr p;
+ int e_nb = 0;
- LLIST_FIND_FOREACH(&recur_elist, &date, recur_event_inday, i) {
- struct recur_event *rev = LLIST_TS_GET_DATA(i);
+ LLIST_FIND_FOREACH(&recur_elist, &date, recur_event_inday, i) {
+ struct recur_event *rev = LLIST_TS_GET_DATA(i);
- if (regex && regexec(regex, rev->mesg, 0, 0, 0) != 0)
- continue;
+ if (regex && regexec(regex, rev->mesg, 0, 0, 0) != 0)
+ continue;
- p.rev = rev;
- day_add_item(RECUR_EVNT, rev->day, p);
- e_nb++;
- }
+ p.rev = rev;
+ day_add_item(RECUR_EVNT, rev->day, p);
+ e_nb++;
+ }
- return e_nb;
+ return e_nb;
}
/*
@@ -266,30 +267,30 @@ static int day_store_recur_events(long date, regex_t *regex)
* structure dedicated to the selected day.
* Returns the number of appointments for the selected day.
*/
-static int day_store_apoints(long date, regex_t *regex)
+static int day_store_apoints(long date, regex_t * regex)
{
- llist_item_t *i;
- union aptev_ptr p;
- int a_nb = 0;
+ llist_item_t *i;
+ union aptev_ptr p;
+ int a_nb = 0;
- LLIST_TS_LOCK(&alist_p);
- LLIST_TS_FIND_FOREACH(&alist_p, &date, apoint_inday, i) {
- struct apoint *apt = LLIST_TS_GET_DATA(i);
+ LLIST_TS_LOCK(&alist_p);
+ LLIST_TS_FIND_FOREACH(&alist_p, &date, apoint_inday, i) {
+ struct apoint *apt = LLIST_TS_GET_DATA(i);
- if (regex && regexec(regex, apt->mesg, 0, 0, 0) != 0)
- continue;
+ if (regex && regexec(regex, apt->mesg, 0, 0, 0) != 0)
+ continue;
- p.apt = apt;
+ p.apt = apt;
- if (apt->start >= date + DAYINSEC)
- break;
+ if (apt->start >= date + DAYINSEC)
+ break;
- day_add_item(APPT, apt->start, p);
- a_nb++;
- }
- LLIST_TS_UNLOCK(&alist_p);
+ day_add_item(APPT, apt->start, p);
+ a_nb++;
+ }
+ LLIST_TS_UNLOCK(&alist_p);
- return a_nb;
+ return a_nb;
}
/*
@@ -299,30 +300,30 @@ static int day_store_apoints(long date, regex_t *regex)
* structure dedicated to the selected day.
* Returns the number of recurrent appointments for the selected day.
*/
-static int day_store_recur_apoints(long date, regex_t *regex)
+static int day_store_recur_apoints(long date, regex_t * regex)
{
- llist_item_t *i;
- union aptev_ptr p;
- int a_nb = 0;
+ llist_item_t *i;
+ union aptev_ptr p;
+ int a_nb = 0;
- LLIST_TS_LOCK(&recur_alist_p);
- LLIST_TS_FIND_FOREACH(&recur_alist_p, &date, recur_apoint_inday, i) {
- struct recur_apoint *rapt = LLIST_TS_GET_DATA(i);
+ LLIST_TS_LOCK(&recur_alist_p);
+ LLIST_TS_FIND_FOREACH(&recur_alist_p, &date, recur_apoint_inday, i) {
+ struct recur_apoint *rapt = LLIST_TS_GET_DATA(i);
- if (regex && regexec(regex, rapt->mesg, 0, 0, 0) != 0)
- continue;
+ if (regex && regexec(regex, rapt->mesg, 0, 0, 0) != 0)
+ continue;
- p.rapt = rapt;
+ p.rapt = rapt;
- unsigned real_start;
- if (recur_apoint_find_occurrence(rapt, date, &real_start)) {
- day_add_item(RECUR_APPT, real_start, p);
- a_nb++;
- }
- }
- LLIST_TS_UNLOCK(&recur_alist_p);
+ unsigned real_start;
+ if (recur_apoint_find_occurrence(rapt, date, &real_start)) {
+ day_add_item(RECUR_APPT, real_start, p);
+ a_nb++;
+ }
+ }
+ LLIST_TS_UNLOCK(&recur_alist_p);
- return a_nb;
+ return a_nb;
}
/*
@@ -335,25 +336,25 @@ static int day_store_recur_apoints(long date, regex_t *regex)
*/
int
day_store_items(long date, unsigned *pnb_events, unsigned *pnb_apoints,
- regex_t *regex)
+ regex_t * regex)
{
- int nb_events, nb_recur_events;
- int nb_apoints, nb_recur_apoints;
+ int nb_events, nb_recur_events;
+ int nb_apoints, nb_recur_apoints;
- day_free_list();
- day_init_list();
+ day_free_list();
+ day_init_list();
- nb_recur_events = day_store_recur_events(date, regex);
- nb_events = day_store_events(date, regex);
- nb_recur_apoints = day_store_recur_apoints(date, regex);
- nb_apoints = day_store_apoints(date, regex);
+ nb_recur_events = day_store_recur_events(date, regex);
+ nb_events = day_store_events(date, regex);
+ nb_recur_apoints = day_store_recur_apoints(date, regex);
+ nb_apoints = day_store_apoints(date, regex);
- if (pnb_apoints)
- *pnb_apoints = nb_apoints + nb_recur_apoints;
- if (pnb_events)
- *pnb_events = nb_events + nb_recur_events;
+ if (pnb_apoints)
+ *pnb_apoints = nb_apoints + nb_recur_apoints;
+ if (pnb_events)
+ *pnb_events = nb_events + nb_recur_events;
- return nb_events + nb_recur_events + nb_apoints + nb_recur_apoints;
+ return nb_events + nb_recur_events + nb_apoints + nb_recur_apoints;
}
/*
@@ -362,68 +363,69 @@ day_store_items(long date, unsigned *pnb_events, unsigned *pnb_apoints,
* day. This is useful to speed up the appointment panel update.
*/
struct day_items_nb day_process_storage(struct date *slctd_date,
- unsigned day_changed)
+ unsigned day_changed)
{
- long date;
- struct date day;
- struct day_items_nb inday;
+ long date;
+ struct date day;
+ struct day_items_nb inday;
- if (slctd_date)
- day = *slctd_date;
- else
- ui_calendar_store_current_date(&day);
+ if (slctd_date)
+ day = *slctd_date;
+ else
+ ui_calendar_store_current_date(&day);
- date = date2sec(day, 0, 0);
+ date = date2sec(day, 0, 0);
- /* Inits */
- if (apad.length != 0)
- delwin(apad.ptrwin);
+ /* Inits */
+ if (apad.length != 0)
+ delwin(apad.ptrwin);
- /* Store the events and appointments (recursive and normal items). */
- day_store_items(date, &inday.nb_events, &inday.nb_apoints, NULL);
- apad.length = (inday.nb_events + 1 + 3 * inday.nb_apoints);
+ /* Store the events and appointments (recursive and normal items). */
+ day_store_items(date, &inday.nb_events, &inday.nb_apoints, NULL);
+ apad.length = (inday.nb_events + 1 + 3 * inday.nb_apoints);
- /* Create the new pad with its new length. */
- if (day_changed)
- apad.first_onscreen = 0;
- apad.ptrwin = newpad(apad.length, apad.width);
+ /* Create the new pad with its new length. */
+ if (day_changed)
+ apad.first_onscreen = 0;
+ apad.ptrwin = newpad(apad.length, apad.width);
- return inday;
+ return inday;
}
/*
* Print an item date in the appointment panel.
*/
static void
-display_item_date(struct day_item *day, int incolor, long date, int y, int x)
-{
- WINDOW *win;
- char a_st[100], a_end[100];
-
- /* FIXME: Redesign apoint_sec2str() and remove the need for a temporary
- * appointment item here. */
- struct apoint apt_tmp;
- apt_tmp.start = day->start;
- apt_tmp.dur = day_item_get_duration(day);
-
- win = apad.ptrwin;
- apoint_sec2str(&apt_tmp, date, a_st, a_end);
- if (incolor == 0)
- custom_apply_attr(win, ATTR_HIGHEST);
-
- if (day->type == RECUR_EVNT || day->type == RECUR_APPT) {
- if (day_item_get_state(day) & APOINT_NOTIFY)
- mvwprintw(win, y, x, " *!%s -> %s", a_st, a_end);
- else
- mvwprintw(win, y, x, " * %s -> %s", a_st, a_end);
- } else if (day_item_get_state(day) & APOINT_NOTIFY) {
- mvwprintw(win, y, x, " -!%s -> %s", a_st, a_end);
- } else {
- mvwprintw(win, y, x, " - %s -> %s", a_st, a_end);
- }
-
- if (incolor == 0)
- custom_remove_attr(win, ATTR_HIGHEST);
+display_item_date(struct day_item *day, int incolor, long date, int y,
+ int x)
+{
+ WINDOW *win;
+ char a_st[100], a_end[100];
+
+ /* FIXME: Redesign apoint_sec2str() and remove the need for a temporary
+ * appointment item here. */
+ struct apoint apt_tmp;
+ apt_tmp.start = day->start;
+ apt_tmp.dur = day_item_get_duration(day);
+
+ win = apad.ptrwin;
+ apoint_sec2str(&apt_tmp, date, a_st, a_end);
+ if (incolor == 0)
+ custom_apply_attr(win, ATTR_HIGHEST);
+
+ if (day->type == RECUR_EVNT || day->type == RECUR_APPT) {
+ if (day_item_get_state(day) & APOINT_NOTIFY)
+ mvwprintw(win, y, x, " *!%s -> %s", a_st, a_end);
+ else
+ mvwprintw(win, y, x, " * %s -> %s", a_st, a_end);
+ } else if (day_item_get_state(day) & APOINT_NOTIFY) {
+ mvwprintw(win, y, x, " -!%s -> %s", a_st, a_end);
+ } else {
+ mvwprintw(win, y, x, " - %s -> %s", a_st, a_end);
+ }
+
+ if (incolor == 0)
+ custom_remove_attr(win, ATTR_HIGHEST);
}
/*
@@ -432,37 +434,38 @@ display_item_date(struct day_item *day, int incolor, long date, int y, int x)
static void
display_item(struct day_item *day, int incolor, int width, int y, int x)
{
- WINDOW *win;
- int ch_recur, ch_note;
- char buf[width * UTF8_MAXLEN];
- int i;
-
- if (width <= 0)
- return;
-
- char *mesg = day_item_get_mesg(day);
-
- win = apad.ptrwin;
- ch_recur = (day->type == RECUR_EVNT || day->type == RECUR_APPT) ? '*' : ' ';
- ch_note = day_item_get_note(day) ? '>' : ' ';
- if (incolor == 0)
- custom_apply_attr(win, ATTR_HIGHEST);
- if (utf8_strwidth(mesg) < width) {
- mvwprintw(win, y, x, " %c%c%s", ch_recur, ch_note, mesg);
- } else {
- for (i = 0; mesg[i] && width > 0; i++) {
- if (!UTF8_ISCONT(mesg[i]))
- width -= utf8_width(&mesg[i]);
- buf[i] = mesg[i];
- }
- if (i)
- buf[i - 1] = 0;
- else
- buf[0] = 0;
- mvwprintw(win, y, x, " %c%c%s...", ch_recur, ch_note, buf);
- }
- if (incolor == 0)
- custom_remove_attr(win, ATTR_HIGHEST);
+ WINDOW *win;
+ int ch_recur, ch_note;
+ char buf[width * UTF8_MAXLEN];
+ int i;
+
+ if (width <= 0)
+ return;
+
+ char *mesg = day_item_get_mesg(day);
+
+ win = apad.ptrwin;
+ ch_recur = (day->type == RECUR_EVNT
+ || day->type == RECUR_APPT) ? '*' : ' ';
+ ch_note = day_item_get_note(day) ? '>' : ' ';
+ if (incolor == 0)
+ custom_apply_attr(win, ATTR_HIGHEST);
+ if (utf8_strwidth(mesg) < width) {
+ mvwprintw(win, y, x, " %c%c%s", ch_recur, ch_note, mesg);
+ } else {
+ for (i = 0; mesg[i] && width > 0; i++) {
+ if (!UTF8_ISCONT(mesg[i]))
+ width -= utf8_width(&mesg[i]);
+ buf[i] = mesg[i];
+ }
+ if (i)
+ buf[i - 1] = 0;
+ else
+ buf[0] = 0;
+ mvwprintw(win, y, x, " %c%c%s...", ch_recur, ch_note, buf);
+ }
+ if (incolor == 0)
+ custom_remove_attr(win, ATTR_HIGHEST);
}
/*
@@ -472,87 +475,94 @@ display_item(struct day_item *day, int incolor, int width, int y, int x)
*/
void day_write_pad(long date, int width, int length, int incolor)
{
- llist_item_t *i;
- int line, item_number;
- const int x_pos = 0;
- unsigned draw_line = 0;
-
- line = item_number = 0;
-
- LLIST_FOREACH(&day_items, i) {
- struct day_item *day = LLIST_TS_GET_DATA(i);
-
- /* First print the events for current day. */
- if (day->type < RECUR_APPT) {
- item_number++;
- display_item(day, item_number - incolor, width - 7, line, x_pos);
- line++;
- draw_line = 1;
- } else {
- /* Draw a line between events and appointments. */
- if (line > 0 && draw_line) {
- wmove(apad.ptrwin, line, 0);
- whline(apad.ptrwin, 0, width);
- draw_line = 0;
- }
- /* Last print the appointments for current day. */
- item_number++;
- display_item_date(day, item_number - incolor, date, line + 1, x_pos);
- display_item(day, item_number - incolor, width - 7, line + 2, x_pos);
- line += 3;
- }
- }
+ llist_item_t *i;
+ int line, item_number;
+ const int x_pos = 0;
+ unsigned draw_line = 0;
+
+ line = item_number = 0;
+
+ LLIST_FOREACH(&day_items, i) {
+ struct day_item *day = LLIST_TS_GET_DATA(i);
+
+ /* First print the events for current day. */
+ if (day->type < RECUR_APPT) {
+ item_number++;
+ display_item(day, item_number - incolor, width - 7,
+ line, x_pos);
+ line++;
+ draw_line = 1;
+ } else {
+ /* Draw a line between events and appointments. */
+ if (line > 0 && draw_line) {
+ wmove(apad.ptrwin, line, 0);
+ whline(apad.ptrwin, 0, width);
+ draw_line = 0;
+ }
+ /* Last print the appointments for current day. */
+ item_number++;
+ display_item_date(day, item_number - incolor, date,
+ line + 1, x_pos);
+ display_item(day, item_number - incolor, width - 7,
+ line + 2, x_pos);
+ line += 3;
+ }
+ }
}
/* Write the appointments and events for the selected day to stdout. */
void day_write_stdout(long date, const char *fmt_apt, const char *fmt_rapt,
- const char *fmt_ev, const char *fmt_rev)
-{
- llist_item_t *i;
-
- LLIST_FOREACH(&day_items, i) {
- struct day_item *day = LLIST_TS_GET_DATA(i);
-
- switch (day->type) {
- case APPT:
- print_apoint(fmt_apt, date, day->item.apt);
- break;
- case EVNT:
- print_event(fmt_ev, date, day->item.ev);
- break;
- case RECUR_APPT:
- print_recur_apoint(fmt_rapt, date, day->start, day->item.rapt);
- break;
- case RECUR_EVNT:
- print_recur_event(fmt_rev, date, day->item.rev);
- break;
- default:
- EXIT(_("unknown item type"));
- /* NOTREACHED */
- }
- }
+ const char *fmt_ev, const char *fmt_rev)
+{
+ llist_item_t *i;
+
+ LLIST_FOREACH(&day_items, i) {
+ struct day_item *day = LLIST_TS_GET_DATA(i);
+
+ switch (day->type) {
+ case APPT:
+ print_apoint(fmt_apt, date, day->item.apt);
+ break;
+ case EVNT:
+ print_event(fmt_ev, date, day->item.ev);
+ break;
+ case RECUR_APPT:
+ print_recur_apoint(fmt_rapt, date, day->start,
+ day->item.rapt);
+ break;
+ case RECUR_EVNT:
+ print_recur_event(fmt_rev, date, day->item.rev);
+ break;
+ default:
+ EXIT(_("unknown item type"));
+ /* NOTREACHED */
+ }
+ }
}
/* Display an item inside a popup window. */
void day_popup_item(struct day_item *day)
{
- if (day->type == EVNT || day->type == RECUR_EVNT) {
- item_in_popup(NULL, NULL, day_item_get_mesg(day), _("Event :"));
- } else if (day->type == APPT || day->type == RECUR_APPT) {
- char a_st[100], a_end[100];
+ if (day->type == EVNT || day->type == RECUR_EVNT) {
+ item_in_popup(NULL, NULL, day_item_get_mesg(day),
+ _("Event :"));
+ } else if (day->type == APPT || day->type == RECUR_APPT) {
+ char a_st[100], a_end[100];
- /* FIXME: Redesign apoint_sec2str() and remove the need for a temporary
- * appointment item here. */
- struct apoint apt_tmp;
- apt_tmp.start = day->start;
- apt_tmp.dur = day_item_get_duration(day);
- apoint_sec2str(&apt_tmp, ui_calendar_get_slctd_day_sec(), a_st, a_end);
+ /* FIXME: Redesign apoint_sec2str() and remove the need for a temporary
+ * appointment item here. */
+ struct apoint apt_tmp;
+ apt_tmp.start = day->start;
+ apt_tmp.dur = day_item_get_duration(day);
+ apoint_sec2str(&apt_tmp, ui_calendar_get_slctd_day_sec(),
+ a_st, a_end);
- item_in_popup(a_st, a_end, day_item_get_mesg(day), _("Appointment :"));
- } else {
- EXIT(_("unknown item type"));
- /* NOTREACHED */
- }
+ item_in_popup(a_st, a_end, day_item_get_mesg(day),
+ _("Appointment :"));
+ } else {
+ EXIT(_("unknown item type"));
+ /* NOTREACHED */
+ }
}
/*
@@ -561,45 +571,47 @@ void day_popup_item(struct day_item *day)
*/
int day_check_if_item(struct date day)
{
- const long date = date2sec(day, 0, 0);
+ const long date = date2sec(day, 0, 0);
- if (LLIST_FIND_FIRST(&recur_elist, (long *)&date, recur_event_inday))
- return 1;
+ if (LLIST_FIND_FIRST
+ (&recur_elist, (long *)&date, recur_event_inday))
+ return 1;
- LLIST_TS_LOCK(&recur_alist_p);
- if (LLIST_TS_FIND_FIRST(&recur_alist_p, (long *)&date, recur_apoint_inday)) {
- LLIST_TS_UNLOCK(&recur_alist_p);
- return 1;
- }
- LLIST_TS_UNLOCK(&recur_alist_p);
+ LLIST_TS_LOCK(&recur_alist_p);
+ if (LLIST_TS_FIND_FIRST
+ (&recur_alist_p, (long *)&date, recur_apoint_inday)) {
+ LLIST_TS_UNLOCK(&recur_alist_p);
+ return 1;
+ }
+ LLIST_TS_UNLOCK(&recur_alist_p);
- if (LLIST_FIND_FIRST(&eventlist, (long *)&date, event_inday))
- return 1;
+ if (LLIST_FIND_FIRST(&eventlist, (long *)&date, event_inday))
+ return 1;
- LLIST_TS_LOCK(&alist_p);
- if (LLIST_TS_FIND_FIRST(&alist_p, (long *)&date, apoint_inday)) {
- LLIST_TS_UNLOCK(&alist_p);
- return 1;
- }
- LLIST_TS_UNLOCK(&alist_p);
+ LLIST_TS_LOCK(&alist_p);
+ if (LLIST_TS_FIND_FIRST(&alist_p, (long *)&date, apoint_inday)) {
+ LLIST_TS_UNLOCK(&alist_p);
+ return 1;
+ }
+ LLIST_TS_UNLOCK(&alist_p);
- return 0;
+ return 0;
}
static unsigned fill_slices(int *slices, int slicesno, int first, int last)
{
- int i;
+ int i;
- if (first < 0 || last < first)
- return 0;
+ if (first < 0 || last < first)
+ return 0;
- if (last >= slicesno)
- last = slicesno - 1; /* Appointment spanning more than one day. */
+ if (last >= slicesno)
+ last = slicesno - 1; /* Appointment spanning more than one day. */
- for (i = first; i <= last; i++)
- slices[i] = 1;
+ for (i = first; i <= last; i++)
+ slices[i] = 1;
- return 1;
+ return 1;
}
/*
@@ -609,153 +621,156 @@ static unsigned fill_slices(int *slices, int slicesno, int first, int last)
*/
unsigned day_chk_busy_slices(struct date day, int slicesno, int *slices)
{
- llist_item_t *i;
- int slicelen;
- const long date = date2sec(day, 0, 0);
+ llist_item_t *i;
+ int slicelen;
+ const long date = date2sec(day, 0, 0);
- slicelen = DAYINSEC / slicesno;
+ slicelen = DAYINSEC / slicesno;
#define SLICENUM(tsec) ((tsec) / slicelen % slicesno)
- LLIST_TS_LOCK(&recur_alist_p);
- LLIST_TS_FIND_FOREACH(&recur_alist_p, (long *)&date, recur_apoint_inday, i) {
- struct apoint *rapt = LLIST_TS_GET_DATA(i);
- long start = get_item_time(rapt->start);
- long end = get_item_time(rapt->start + rapt->dur);
-
- if (rapt->start < date)
- start = 0;
- if (rapt->start + rapt->dur >= date + DAYINSEC)
- end = DAYINSEC - 1;
-
- if (!fill_slices(slices, slicesno, SLICENUM(start), SLICENUM(end))) {
- LLIST_TS_UNLOCK(&recur_alist_p);
- return 0;
- }
- }
- LLIST_TS_UNLOCK(&recur_alist_p);
-
- LLIST_TS_LOCK(&alist_p);
- LLIST_TS_FIND_FOREACH(&alist_p, (long *)&date, apoint_inday, i) {
- struct apoint *apt = LLIST_TS_GET_DATA(i);
- long start = get_item_time(apt->start);
- long end = get_item_time(apt->start + apt->dur);
-
- if (apt->start >= date + DAYINSEC)
- break;
- if (apt->start < date)
- start = 0;
- if (apt->start + apt->dur >= date + DAYINSEC)
- end = DAYINSEC - 1;
-
- if (!fill_slices(slices, slicesno, SLICENUM(start), SLICENUM(end))) {
- LLIST_TS_UNLOCK(&alist_p);
- return 0;
- }
- }
- LLIST_TS_UNLOCK(&alist_p);
+ LLIST_TS_LOCK(&recur_alist_p);
+ LLIST_TS_FIND_FOREACH(&recur_alist_p, (long *)&date,
+ recur_apoint_inday, i) {
+ struct apoint *rapt = LLIST_TS_GET_DATA(i);
+ long start = get_item_time(rapt->start);
+ long end = get_item_time(rapt->start + rapt->dur);
+
+ if (rapt->start < date)
+ start = 0;
+ if (rapt->start + rapt->dur >= date + DAYINSEC)
+ end = DAYINSEC - 1;
+
+ if (!fill_slices
+ (slices, slicesno, SLICENUM(start), SLICENUM(end))) {
+ LLIST_TS_UNLOCK(&recur_alist_p);
+ return 0;
+ }
+ }
+ LLIST_TS_UNLOCK(&recur_alist_p);
+
+ LLIST_TS_LOCK(&alist_p);
+ LLIST_TS_FIND_FOREACH(&alist_p, (long *)&date, apoint_inday, i) {
+ struct apoint *apt = LLIST_TS_GET_DATA(i);
+ long start = get_item_time(apt->start);
+ long end = get_item_time(apt->start + apt->dur);
+
+ if (apt->start >= date + DAYINSEC)
+ break;
+ if (apt->start < date)
+ start = 0;
+ if (apt->start + apt->dur >= date + DAYINSEC)
+ end = DAYINSEC - 1;
+
+ if (!fill_slices
+ (slices, slicesno, SLICENUM(start), SLICENUM(end))) {
+ LLIST_TS_UNLOCK(&alist_p);
+ return 0;
+ }
+ }
+ LLIST_TS_UNLOCK(&alist_p);
#undef SLICENUM
- return 1;
+ return 1;
}
/* Cut an item so it can be pasted somewhere else later. */
struct day_item *day_cut_item(long date, int item_number)
{
- struct day_item *p = day_get_item(item_number);
-
- switch (p->type) {
- case EVNT:
- event_delete(p->item.ev);
- break;
- case RECUR_EVNT:
- recur_event_erase(p->item.rev);
- break;
- case APPT:
- apoint_delete(p->item.apt);
- break;
- case RECUR_APPT:
- recur_apoint_erase(p->item.rapt);
- break;
- default:
- EXIT(_("unknwon type"));
- /* NOTREACHED */
- }
-
- return p;
+ struct day_item *p = day_get_item(item_number);
+
+ switch (p->type) {
+ case EVNT:
+ event_delete(p->item.ev);
+ break;
+ case RECUR_EVNT:
+ recur_event_erase(p->item.rev);
+ break;
+ case APPT:
+ apoint_delete(p->item.apt);
+ break;
+ case RECUR_APPT:
+ recur_apoint_erase(p->item.rapt);
+ break;
+ default:
+ EXIT(_("unknwon type"));
+ /* NOTREACHED */
+ }
+
+ return p;
}
/* Paste a previously cut item. */
int day_paste_item(struct day_item *p, long date)
{
- switch (p->type) {
- case 0:
- return 0;
- case EVNT:
- event_paste_item(p->item.ev, date);
- break;
- case RECUR_EVNT:
- recur_event_paste_item(p->item.rev, date);
- break;
- case APPT:
- apoint_paste_item(p->item.apt, date);
- break;
- case RECUR_APPT:
- recur_apoint_paste_item(p->item.rapt, date);
- break;
- default:
- EXIT(_("unknwon type"));
- /* NOTREACHED */
- }
-
- return p->type;
+ switch (p->type) {
+ case 0:
+ return 0;
+ case EVNT:
+ event_paste_item(p->item.ev, date);
+ break;
+ case RECUR_EVNT:
+ recur_event_paste_item(p->item.rev, date);
+ break;
+ case APPT:
+ apoint_paste_item(p->item.apt, date);
+ break;
+ case RECUR_APPT:
+ recur_apoint_paste_item(p->item.rapt, date);
+ break;
+ default:
+ EXIT(_("unknwon type"));
+ /* NOTREACHED */
+ }
+
+ return p->type;
}
/* Returns a structure containing the selected item. */
struct day_item *day_get_item(int item_number)
{
- return LLIST_GET_DATA(LLIST_NTH(&day_items, item_number - 1));
+ return LLIST_GET_DATA(LLIST_NTH(&day_items, item_number - 1));
}
/* Attach a note to an appointment or event. */
void day_edit_note(struct day_item *p, const char *editor)
{
- char *note;
+ char *note;
- note = day_item_get_note(p);
- edit_note(&note, editor);
+ note = day_item_get_note(p);
+ edit_note(&note, editor);
- switch (p->type) {
- case RECUR_EVNT:
- p->item.rev->note = note;
- break;
- case EVNT:
- p->item.ev->note = note;
- break;
- case RECUR_APPT:
- p->item.rapt->note = note;
- break;
- case APPT:
- p->item.apt->note = note;
- break;
- }
+ switch (p->type) {
+ case RECUR_EVNT:
+ p->item.rev->note = note;
+ break;
+ case EVNT:
+ p->item.ev->note = note;
+ break;
+ case RECUR_APPT:
+ p->item.rapt->note = note;
+ break;
+ case APPT:
+ p->item.apt->note = note;
+ break;
+ }
}
/* View a note previously attached to an appointment or event */
void day_view_note(struct day_item *p, const char *pager)
{
- view_note(day_item_get_note(p), pager);
+ view_note(day_item_get_note(p), pager);
}
/* Switch notification state for an item. */
void day_item_switch_notify(struct day_item *p)
{
- switch (p->type) {
- case RECUR_APPT:
- recur_apoint_switch_notify(p->item.rapt);
- break;
- case APPT:
- apoint_switch_notify(p->item.apt);
- break;
- }
+ switch (p->type) {
+ case RECUR_APPT:
+ recur_apoint_switch_notify(p->item.rapt);
+ break;
+ case APPT:
+ apoint_switch_notify(p->item.apt);
+ break;
+ }
}
diff --git a/src/dmon.c b/src/dmon.c
index 0fd7962..d1ef1cd 100644
--- a/src/dmon.c
+++ b/src/dmon.c
@@ -66,124 +66,130 @@ static unsigned data_loaded;
static void dmon_sigs_hdlr(int sig)
{
- if (data_loaded)
- free_user_data();
+ if (data_loaded)
+ free_user_data();
- DMON_LOG(_("terminated at %s with signal %d\n"), nowstr(), sig);
+ DMON_LOG(_("terminated at %s with signal %d\n"), nowstr(), sig);
- if (unlink(path_dpid) != 0) {
- DMON_LOG(_("Could not remove daemon lock file: %s\n"), strerror(errno));
- exit(EXIT_FAILURE);
- }
+ if (unlink(path_dpid) != 0) {
+ DMON_LOG(_("Could not remove daemon lock file: %s\n"),
+ strerror(errno));
+ exit(EXIT_FAILURE);
+ }
- exit(EXIT_SUCCESS);
+ exit(EXIT_SUCCESS);
}
static unsigned daemonize(int status)
{
- int fd;
-
- /*
- * Operate in the background: Daemonizing.
- *
- * First need to fork in order to become a child of the init process,
- * once the father exits.
- */
- switch (fork()) {
- case -1: /* fork error */
- EXIT(_("Could not fork: %s\n"), strerror(errno));
- break;
- case 0: /* child */
- break;
- default: /* parent */
- exit(status);
- }
-
- /*
- * Process independency.
- *
- * Obtain a new process group and session in order to get detached from the
- * controlling terminal.
- */
- if (setsid() == -1) {
- DMON_LOG(_("Could not detach from the controlling terminal: %s\n"),
- strerror(errno));
- return 0;
- }
-
- /*
- * Change working directory to root directory,
- * to prevent filesystem unmounts.
- */
- if (chdir("/") == -1) {
- DMON_LOG(_("Could not change working directory: %s\n"), strerror(errno));
- return 0;
- }
-
- /* Redirect standard file descriptors to /dev/null. */
- if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
- dup2(fd, STDIN_FILENO);
- dup2(fd, STDOUT_FILENO);
- dup2(fd, STDERR_FILENO);
- if (fd > 2)
- close(fd);
- }
-
- /* Write access for the owner only. */
- umask(0022);
-
- if (!sigs_set_hdlr(SIGINT, dmon_sigs_hdlr)
- || !sigs_set_hdlr(SIGTERM, dmon_sigs_hdlr)
- || !sigs_set_hdlr(SIGALRM, dmon_sigs_hdlr)
- || !sigs_set_hdlr(SIGQUIT, dmon_sigs_hdlr)
- || !sigs_set_hdlr(SIGCHLD, SIG_IGN))
- return 0;
-
- return 1;
+ int fd;
+
+ /*
+ * Operate in the background: Daemonizing.
+ *
+ * First need to fork in order to become a child of the init process,
+ * once the father exits.
+ */
+ switch (fork()) {
+ case -1: /* fork error */
+ EXIT(_("Could not fork: %s\n"), strerror(errno));
+ break;
+ case 0: /* child */
+ break;
+ default: /* parent */
+ exit(status);
+ }
+
+ /*
+ * Process independency.
+ *
+ * Obtain a new process group and session in order to get detached from the
+ * controlling terminal.
+ */
+ if (setsid() == -1) {
+ DMON_LOG(_("Could not detach from the controlling terminal: %s\n"),
+ strerror(errno));
+ return 0;
+ }
+
+ /*
+ * Change working directory to root directory,
+ * to prevent filesystem unmounts.
+ */
+ if (chdir("/") == -1) {
+ DMON_LOG(_("Could not change working directory: %s\n"),
+ strerror(errno));
+ return 0;
+ }
+
+ /* Redirect standard file descriptors to /dev/null. */
+ if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
+ dup2(fd, STDIN_FILENO);
+ dup2(fd, STDOUT_FILENO);
+ dup2(fd, STDERR_FILENO);
+ if (fd > 2)
+ close(fd);
+ }
+
+ /* Write access for the owner only. */
+ umask(0022);
+
+ if (!sigs_set_hdlr(SIGINT, dmon_sigs_hdlr)
+ || !sigs_set_hdlr(SIGTERM, dmon_sigs_hdlr)
+ || !sigs_set_hdlr(SIGALRM, dmon_sigs_hdlr)
+ || !sigs_set_hdlr(SIGQUIT, dmon_sigs_hdlr)
+ || !sigs_set_hdlr(SIGCHLD, SIG_IGN))
+ return 0;
+
+ return 1;
}
void dmon_start(int parent_exit_status)
{
- if (!daemonize(parent_exit_status))
- DMON_ABRT(_("Cannot daemonize, aborting\n"));
-
- if (!io_dump_pid(path_dpid))
- DMON_ABRT(_("Could not set lock file\n"));
-
- if (!io_file_exist(path_conf))
- DMON_ABRT(_("Could not access \"%s\": %s\n"), path_conf, strerror(errno));
- config_load();
-
- if (!io_file_exist(path_apts))
- DMON_ABRT(_("Could not access \"%s\": %s\n"), path_apts, strerror(errno));
- apoint_llist_init();
- recur_apoint_llist_init();
- event_llist_init();
- todo_init_list();
- io_load_app();
- data_loaded = 1;
-
- DMON_LOG(_("started at %s\n"), nowstr());
- for (;;) {
- int left;
-
- if (!notify_get_next_bkgd())
- DMON_ABRT(_("error loading next appointment\n"));
-
- left = notify_time_left();
- if (left > 0 && left < nbar.cntdwn && notify_needs_reminder()) {
- DMON_LOG(_("launching notification at %s for: \"%s\"\n"),
- nowstr(), notify_app_txt());
- if (!notify_launch_cmd())
- DMON_LOG(_("error while sending notification\n"));
- }
-
- DMON_LOG(ngettext("sleeping at %s for %d second\n",
- "sleeping at %s for %d seconds\n",
- DMON_SLEEP_TIME), nowstr(), DMON_SLEEP_TIME);
- psleep(DMON_SLEEP_TIME);
- DMON_LOG(_("awakened at %s\n"), nowstr());
- }
+ if (!daemonize(parent_exit_status))
+ DMON_ABRT(_("Cannot daemonize, aborting\n"));
+
+ if (!io_dump_pid(path_dpid))
+ DMON_ABRT(_("Could not set lock file\n"));
+
+ if (!io_file_exist(path_conf))
+ DMON_ABRT(_("Could not access \"%s\": %s\n"), path_conf,
+ strerror(errno));
+ config_load();
+
+ if (!io_file_exist(path_apts))
+ DMON_ABRT(_("Could not access \"%s\": %s\n"), path_apts,
+ strerror(errno));
+ apoint_llist_init();
+ recur_apoint_llist_init();
+ event_llist_init();
+ todo_init_list();
+ io_load_app();
+ data_loaded = 1;
+
+ DMON_LOG(_("started at %s\n"), nowstr());
+ for (;;) {
+ int left;
+
+ if (!notify_get_next_bkgd())
+ DMON_ABRT(_("error loading next appointment\n"));
+
+ left = notify_time_left();
+ if (left > 0 && left < nbar.cntdwn
+ && notify_needs_reminder()) {
+ DMON_LOG(_("launching notification at %s for: \"%s\"\n"),
+ nowstr(), notify_app_txt());
+ if (!notify_launch_cmd())
+ DMON_LOG(_("error while sending notification\n"));
+ }
+
+ DMON_LOG(ngettext("sleeping at %s for %d second\n",
+ "sleeping at %s for %d seconds\n",
+ DMON_SLEEP_TIME), nowstr(),
+ DMON_SLEEP_TIME);
+ psleep(DMON_SLEEP_TIME);
+ DMON_LOG(_("awakened at %s\n"), nowstr());
+ }
}
/*
@@ -192,12 +198,13 @@ void dmon_start(int parent_exit_status)
*/
void dmon_stop(void)
{
- int dpid;
+ int dpid;
- dpid = io_get_pid(path_dpid);
- if (!dpid)
- return;
+ dpid = io_get_pid(path_dpid);
+ if (!dpid)
+ return;
- if (kill((pid_t) dpid, SIGINT) < 0 && errno != ESRCH)
- EXIT(_("Could not stop calcurse daemon: %s\n"), strerror(errno));
+ if (kill((pid_t) dpid, SIGINT) < 0 && errno != ESRCH)
+ EXIT(_("Could not stop calcurse daemon: %s\n"),
+ strerror(errno));
}
diff --git a/src/event.c b/src/event.c
index 637dd6d..38305b8 100644
--- a/src/event.c
+++ b/src/event.c
@@ -45,124 +45,124 @@ llist_t eventlist;
void event_free(struct event *ev)
{
- mem_free(ev->mesg);
- erase_note(&ev->note);
- mem_free(ev);
+ mem_free(ev->mesg);
+ erase_note(&ev->note);
+ mem_free(ev);
}
struct event *event_dup(struct event *in)
{
- EXIT_IF(!in, _("null pointer"));
-
- struct event *ev = mem_malloc(sizeof(struct event));
- ev->id = in->id;
- ev->day = in->day;
- ev->mesg = mem_strdup(in->mesg);
- if (in->note)
- ev->note = mem_strdup(in->note);
- else
- ev->note = NULL;
-
- return ev;
+ EXIT_IF(!in, _("null pointer"));
+
+ struct event *ev = mem_malloc(sizeof(struct event));
+ ev->id = in->id;
+ ev->day = in->day;
+ ev->mesg = mem_strdup(in->mesg);
+ if (in->note)
+ ev->note = mem_strdup(in->note);
+ else
+ ev->note = NULL;
+
+ return ev;
}
void event_llist_init(void)
{
- LLIST_INIT(&eventlist);
+ LLIST_INIT(&eventlist);
}
void event_llist_free(void)
{
- LLIST_FREE_INNER(&eventlist, event_free);
- LLIST_FREE(&eventlist);
+ LLIST_FREE_INNER(&eventlist, event_free);
+ LLIST_FREE(&eventlist);
}
static int event_cmp_day(struct event *a, struct event *b)
{
- return a->day < b->day ? -1 : (a->day == b->day ? 0 : 1);
+ return a->day < b->day ? -1 : (a->day == b->day ? 0 : 1);
}
/* Create a new event */
struct event *event_new(char *mesg, char *note, long day, int id)
{
- struct event *ev;
+ struct event *ev;
- ev = mem_malloc(sizeof(struct event));
- ev->mesg = mem_strdup(mesg);
- ev->day = day;
- ev->id = id;
- ev->note = (note != NULL) ? mem_strdup(note) : NULL;
+ ev = mem_malloc(sizeof(struct event));
+ ev->mesg = mem_strdup(mesg);
+ ev->day = day;
+ ev->id = id;
+ ev->note = (note != NULL) ? mem_strdup(note) : NULL;
- LLIST_ADD_SORTED(&eventlist, ev, event_cmp_day);
+ LLIST_ADD_SORTED(&eventlist, ev, event_cmp_day);
- return ev;
+ return ev;
}
/* Check if the event belongs to the selected day */
unsigned event_inday(struct event *i, long *start)
{
- return (i->day < *start + DAYINSEC && i->day >= *start);
+ return (i->day < *start + DAYINSEC && i->day >= *start);
}
/* Write to file the event in user-friendly format */
void event_write(struct event *o, FILE * f)
{
- struct tm lt;
- time_t t;
-
- t = o->day;
- localtime_r(&t, &lt);
- fprintf(f, "%02u/%02u/%04u [%d] ", lt.tm_mon + 1, lt.tm_mday,
- 1900 + lt.tm_year, o->id);
- if (o->note != NULL)
- fprintf(f, ">%s ", o->note);
- fprintf(f, "%s\n", o->mesg);
+ struct tm lt;
+ time_t t;
+
+ t = o->day;
+ localtime_r(&t, &lt);
+ fprintf(f, "%02u/%02u/%04u [%d] ", lt.tm_mon + 1, lt.tm_mday,
+ 1900 + lt.tm_year, o->id);
+ if (o->note != NULL)
+ fprintf(f, ">%s ", o->note);
+ fprintf(f, "%s\n", o->mesg);
}
/* Load the events from file */
struct event *event_scan(FILE * f, struct tm start, int id, char *note)
{
- char buf[BUFSIZ], *nl;
- time_t tstart;
-
- EXIT_IF(!check_date(start.tm_year, start.tm_mon, start.tm_mday) ||
- !check_time(start.tm_hour, start.tm_min),
- _("date error in event"));
-
- /* Read the event description */
- if (!fgets(buf, sizeof buf, f))
- return NULL;
-
- nl = strchr(buf, '\n');
- if (nl) {
- *nl = '\0';
- }
- start.tm_hour = 0;
- start.tm_min = 0;
- start.tm_sec = 0;
- start.tm_isdst = -1;
- start.tm_year -= 1900;
- start.tm_mon--;
-
- tstart = mktime(&start);
- EXIT_IF(tstart == -1, _("date error in the event\n"));
-
- return event_new(buf, note, tstart, id);
+ char buf[BUFSIZ], *nl;
+ time_t tstart;
+
+ EXIT_IF(!check_date(start.tm_year, start.tm_mon, start.tm_mday) ||
+ !check_time(start.tm_hour, start.tm_min),
+ _("date error in event"));
+
+ /* Read the event description */
+ if (!fgets(buf, sizeof buf, f))
+ return NULL;
+
+ nl = strchr(buf, '\n');
+ if (nl) {
+ *nl = '\0';
+ }
+ start.tm_hour = 0;
+ start.tm_min = 0;
+ start.tm_sec = 0;
+ start.tm_isdst = -1;
+ start.tm_year -= 1900;
+ start.tm_mon--;
+
+ tstart = mktime(&start);
+ EXIT_IF(tstart == -1, _("date error in the event\n"));
+
+ return event_new(buf, note, tstart, id);
}
/* Delete an event from the list. */
void event_delete(struct event *ev)
{
- llist_item_t *i = LLIST_FIND_FIRST(&eventlist, ev, NULL);
+ llist_item_t *i = LLIST_FIND_FIRST(&eventlist, ev, NULL);
- if (!i)
- EXIT(_("no such appointment"));
+ if (!i)
+ EXIT(_("no such appointment"));
- LLIST_REMOVE(&eventlist, i);
+ LLIST_REMOVE(&eventlist, i);
}
void event_paste_item(struct event *ev, long date)
{
- ev->day = date;
- LLIST_ADD_SORTED(&eventlist, ev, event_cmp_day);
+ ev->day = date;
+ LLIST_ADD_SORTED(&eventlist, ev, event_cmp_day);
}
diff --git a/src/getstring.c b/src/getstring.c
index aedd842..513ad67 100644
--- a/src/getstring.c
+++ b/src/getstring.c
@@ -37,126 +37,134 @@
#include "calcurse.h"
struct getstr_charinfo {
- unsigned int offset, dpyoff;
+ unsigned int offset, dpyoff;
};
struct getstr_status {
- char *s;
- struct getstr_charinfo *ci;
- int pos, len;
- int scrpos;
+ char *s;
+ struct getstr_charinfo *ci;
+ int pos, len;
+ int scrpos;
};
/* Print the string at the desired position. */
-static void getstr_print(WINDOW * win, int x, int y, struct getstr_status *st)
+static void getstr_print(WINDOW * win, int x, int y,
+ struct getstr_status *st)
{
- char c = 0;
-
- /* print string */
- mvwaddnstr(win, y, x, &st->s[st->ci[st->scrpos].offset], -1);
- wclrtoeol(win);
-
- /* print scrolling indicator */
- if (st->scrpos > 0 && st->ci[st->len].dpyoff -
- st->ci[st->scrpos].dpyoff > col - 2)
- c = '*';
- else if (st->scrpos > 0)
- c = '<';
- else if (st->ci[st->len].dpyoff - st->ci[st->scrpos].dpyoff > col - 2)
- c = '>';
- mvwprintw(win, y, col - 2, " %c", c);
-
- /* print cursor */
- wmove(win, y, st->ci[st->pos].dpyoff - st->ci[st->scrpos].dpyoff);
- wchgat(win, 1, A_REVERSE, COLR_CUSTOM, NULL);
+ char c = 0;
+
+ /* print string */
+ mvwaddnstr(win, y, x, &st->s[st->ci[st->scrpos].offset], -1);
+ wclrtoeol(win);
+
+ /* print scrolling indicator */
+ if (st->scrpos > 0 && st->ci[st->len].dpyoff -
+ st->ci[st->scrpos].dpyoff > col - 2)
+ c = '*';
+ else if (st->scrpos > 0)
+ c = '<';
+ else if (st->ci[st->len].dpyoff - st->ci[st->scrpos].dpyoff >
+ col - 2)
+ c = '>';
+ mvwprintw(win, y, col - 2, " %c", c);
+
+ /* print cursor */
+ wmove(win, y, st->ci[st->pos].dpyoff - st->ci[st->scrpos].dpyoff);
+ wchgat(win, 1, A_REVERSE, COLR_CUSTOM, NULL);
}
/* Delete a character at the given position in string. */
static void getstr_del_char(struct getstr_status *st)
{
- char *str = st->s + st->ci[st->pos].offset;
- int cl = st->ci[st->pos + 1].offset - st->ci[st->pos].offset;
- int cw = st->ci[st->pos + 1].dpyoff - st->ci[st->pos].dpyoff;
- int i;
-
- memmove(str, str + cl, strlen(str) + 1);
-
- st->len--;
- for (i = st->pos; i <= st->len; i++) {
- st->ci[i].offset = st->ci[i + 1].offset - cl;
- st->ci[i].dpyoff = st->ci[i + 1].dpyoff - cw;
- }
+ char *str = st->s + st->ci[st->pos].offset;
+ int cl = st->ci[st->pos + 1].offset - st->ci[st->pos].offset;
+ int cw = st->ci[st->pos + 1].dpyoff - st->ci[st->pos].dpyoff;
+ int i;
+
+ memmove(str, str + cl, strlen(str) + 1);
+
+ st->len--;
+ for (i = st->pos; i <= st->len; i++) {
+ st->ci[i].offset = st->ci[i + 1].offset - cl;
+ st->ci[i].dpyoff = st->ci[i + 1].dpyoff - cw;
+ }
}
/* Add a character at the given position in string. */
static void getstr_ins_char(struct getstr_status *st, char *c)
{
- char *str = st->s + st->ci[st->pos].offset;
- int cl = UTF8_LENGTH(c[0]);
- int cw = utf8_width(c);
- int i;
-
- memmove(str + cl, str, strlen(str) + 1);
- for (i = 0; i < cl; i++, str++)
- *str = c[i];
-
- for (i = st->len; i >= st->pos; i--) {
- st->ci[i + 1].offset = st->ci[i].offset + cl;
- st->ci[i + 1].dpyoff = st->ci[i].dpyoff + cw;
- }
- st->len++;
+ char *str = st->s + st->ci[st->pos].offset;
+ int cl = UTF8_LENGTH(c[0]);
+ int cw = utf8_width(c);
+ int i;
+
+ memmove(str + cl, str, strlen(str) + 1);
+ for (i = 0; i < cl; i++, str++)
+ *str = c[i];
+
+ for (i = st->len; i >= st->pos; i--) {
+ st->ci[i + 1].offset = st->ci[i].offset + cl;
+ st->ci[i + 1].dpyoff = st->ci[i].dpyoff + cw;
+ }
+ st->len++;
}
static void bell(void)
{
- putchar('\a');
+ putchar('\a');
}
/* Initialize getstring data structure. */
static void
-getstr_init(struct getstr_status *st, char *str, struct getstr_charinfo *ci)
+getstr_init(struct getstr_status *st, char *str,
+ struct getstr_charinfo *ci)
{
- int width;
+ int width;
- st->s = str;
- st->ci = ci;
+ st->s = str;
+ st->ci = ci;
- st->len = width = 0;
- while (*str) {
- st->ci[st->len].offset = str - st->s;
- st->ci[st->len].dpyoff = width;
+ st->len = width = 0;
+ while (*str) {
+ st->ci[st->len].offset = str - st->s;
+ st->ci[st->len].dpyoff = width;
- st->len++;
- width += utf8_width(str);
- str += UTF8_LENGTH(*str);
- }
- st->ci[st->len].offset = str - st->s;
- st->ci[st->len].dpyoff = width;
+ st->len++;
+ width += utf8_width(str);
+ str += UTF8_LENGTH(*str);
+ }
+ st->ci[st->len].offset = str - st->s;
+ st->ci[st->len].dpyoff = width;
- st->pos = st->len;
- st->scrpos = 0;
+ st->pos = st->len;
+ st->scrpos = 0;
}
/* Scroll left/right if the cursor moves outside the window range. */
static void getstr_fixscr(struct getstr_status *st)
{
- const int pgsize = col / 3;
- int pgskip;
-
- while (st->pos < st->scrpos) {
- pgskip = 0;
- while (pgskip < pgsize && st->scrpos > 0) {
- st->scrpos--;
- pgskip += st->ci[st->scrpos + 1].dpyoff - st->ci[st->scrpos].dpyoff;
- }
- }
- while (st->ci[st->pos].dpyoff - st->ci[st->scrpos].dpyoff > col - 2) {
- pgskip = 0;
- while (pgskip < pgsize && st->scrpos < st->len) {
- pgskip += st->ci[st->scrpos + 1].dpyoff - st->ci[st->scrpos].dpyoff;
- st->scrpos++;
- }
- }
+ const int pgsize = col / 3;
+ int pgskip;
+
+ while (st->pos < st->scrpos) {
+ pgskip = 0;
+ while (pgskip < pgsize && st->scrpos > 0) {
+ st->scrpos--;
+ pgskip +=
+ st->ci[st->scrpos + 1].dpyoff -
+ st->ci[st->scrpos].dpyoff;
+ }
+ }
+ while (st->ci[st->pos].dpyoff - st->ci[st->scrpos].dpyoff >
+ col - 2) {
+ pgskip = 0;
+ while (pgskip < pgsize && st->scrpos < st->len) {
+ pgskip +=
+ st->ci[st->scrpos + 1].dpyoff -
+ st->ci[st->scrpos].dpyoff;
+ st->scrpos++;
+ }
+ }
}
/*
@@ -169,114 +177,119 @@ static void getstr_fixscr(struct getstr_status *st)
*/
enum getstr getstring(WINDOW * win, char *str, int l, int x, int y)
{
- struct getstr_status st;
- struct getstr_charinfo ci[l + 1];
-
- int ch, k;
- char c[UTF8_MAXLEN];
-
- getstr_init(&st, str, ci);
- custom_apply_attr(win, ATTR_HIGHEST);
-
- for (;;) {
- getstr_fixscr(&st);
- getstr_print(win, x, y, &st);
- wins_doupdate();
-
- if ((ch = wgetch(win)) == '\n')
- break;
- switch (ch) {
- case KEY_BACKSPACE: /* delete one character */
- case 330:
- case 127:
- case CTRL('H'):
- if (st.pos > 0) {
- st.pos--;
- getstr_del_char(&st);
- } else {
- bell();
- }
- break;
- case CTRL('D'): /* delete next character */
- if (st.pos < st.len)
- getstr_del_char(&st);
- else
- bell();
- break;
- case CTRL('W'): /* delete a word */
- if (st.pos > 0) {
- while (st.pos && st.s[st.ci[st.pos - 1].offset] == ' ') {
- st.pos--;
- getstr_del_char(&st);
- }
- while (st.pos && st.s[st.ci[st.pos - 1].offset] != ' ') {
- st.pos--;
- getstr_del_char(&st);
- }
- } else {
- bell();
- }
- break;
- case CTRL('K'): /* delete to end-of-line */
- st.s[st.ci[st.pos].offset] = 0;
- st.len = st.pos;
- break;
- case CTRL('A'): /* go to begginning of string */
- st.pos = 0;
- break;
- case CTRL('E'): /* go to end of string */
- st.pos = st.len;
- break;
- case KEY_LEFT: /* move one char backward */
- case CTRL('B'):
- if (st.pos > 0)
- st.pos--;
- break;
- case KEY_RIGHT: /* move one char forward */
- case CTRL('F'):
- if (st.pos < st.len)
- st.pos++;
- break;
- case ESCAPE: /* cancel editing */
- return GETSTRING_ESC;
- break;
- default: /* insert one character */
- c[0] = ch;
- for (k = 1; k < MIN(UTF8_LENGTH(c[0]), UTF8_MAXLEN); k++)
- c[k] = (unsigned char)wgetch(win);
- if (st.ci[st.len].offset + k < l) {
- getstr_ins_char(&st, c);
- st.pos++;
- }
- }
- }
-
- custom_remove_attr(win, ATTR_HIGHEST);
-
- return st.len == 0 ? GETSTRING_RET : GETSTRING_VALID;
+ struct getstr_status st;
+ struct getstr_charinfo ci[l + 1];
+
+ int ch, k;
+ char c[UTF8_MAXLEN];
+
+ getstr_init(&st, str, ci);
+ custom_apply_attr(win, ATTR_HIGHEST);
+
+ for (;;) {
+ getstr_fixscr(&st);
+ getstr_print(win, x, y, &st);
+ wins_doupdate();
+
+ if ((ch = wgetch(win)) == '\n')
+ break;
+ switch (ch) {
+ case KEY_BACKSPACE: /* delete one character */
+ case 330:
+ case 127:
+ case CTRL('H'):
+ if (st.pos > 0) {
+ st.pos--;
+ getstr_del_char(&st);
+ } else {
+ bell();
+ }
+ break;
+ case CTRL('D'): /* delete next character */
+ if (st.pos < st.len)
+ getstr_del_char(&st);
+ else
+ bell();
+ break;
+ case CTRL('W'): /* delete a word */
+ if (st.pos > 0) {
+ while (st.pos
+ && st.s[st.ci[st.pos - 1].offset] ==
+ ' ') {
+ st.pos--;
+ getstr_del_char(&st);
+ }
+ while (st.pos
+ && st.s[st.ci[st.pos - 1].offset] !=
+ ' ') {
+ st.pos--;
+ getstr_del_char(&st);
+ }
+ } else {
+ bell();
+ }
+ break;
+ case CTRL('K'): /* delete to end-of-line */
+ st.s[st.ci[st.pos].offset] = 0;
+ st.len = st.pos;
+ break;
+ case CTRL('A'): /* go to begginning of string */
+ st.pos = 0;
+ break;
+ case CTRL('E'): /* go to end of string */
+ st.pos = st.len;
+ break;
+ case KEY_LEFT: /* move one char backward */
+ case CTRL('B'):
+ if (st.pos > 0)
+ st.pos--;
+ break;
+ case KEY_RIGHT: /* move one char forward */
+ case CTRL('F'):
+ if (st.pos < st.len)
+ st.pos++;
+ break;
+ case ESCAPE: /* cancel editing */
+ return GETSTRING_ESC;
+ break;
+ default: /* insert one character */
+ c[0] = ch;
+ for (k = 1;
+ k < MIN(UTF8_LENGTH(c[0]), UTF8_MAXLEN); k++)
+ c[k] = (unsigned char)wgetch(win);
+ if (st.ci[st.len].offset + k < l) {
+ getstr_ins_char(&st, c);
+ st.pos++;
+ }
+ }
+ }
+
+ custom_remove_attr(win, ATTR_HIGHEST);
+
+ return st.len == 0 ? GETSTRING_RET : GETSTRING_VALID;
}
/* Update an already existing string. */
int updatestring(WINDOW * win, char **str, int x, int y)
{
- int len = strlen(*str);
- char *buf;
- enum getstr ret;
+ int len = strlen(*str);
+ char *buf;
+ enum getstr ret;
- EXIT_IF(len + 1 > BUFSIZ, _("Internal error: line too long"));
+ EXIT_IF(len + 1 > BUFSIZ, _("Internal error: line too long"));
- buf = mem_malloc(BUFSIZ);
- memcpy(buf, *str, len + 1);
+ buf = mem_malloc(BUFSIZ);
+ memcpy(buf, *str, len + 1);
- ret = getstring(win, buf, BUFSIZ, x, y);
+ ret = getstring(win, buf, BUFSIZ, x, y);
- if (ret == GETSTRING_VALID) {
- len = strlen(buf);
- *str = mem_realloc(*str, len + 1, 1);
- EXIT_IF(*str == NULL, _("out of memory"));
- memcpy(*str, buf, len + 1);
- }
+ if (ret == GETSTRING_VALID) {
+ len = strlen(buf);
+ *str = mem_realloc(*str, len + 1, 1);
+ EXIT_IF(*str == NULL, _("out of memory"));
+ memcpy(*str, buf, len + 1);
+ }
- mem_free(buf);
- return ret;
+ mem_free(buf);
+ return ret;
}
diff --git a/src/help.c b/src/help.c
index 289f814..b4dcb07 100644
--- a/src/help.c
+++ b/src/help.c
@@ -44,48 +44,48 @@
#define HELPTEXTSIZ 4096
typedef struct {
- char *title;
- char text[HELPTEXTSIZ];
+ char *title;
+ char text[HELPTEXTSIZ];
} help_page_t;
typedef enum {
- HELP_MAIN,
- HELP_SAVE,
- HELP_IMPORT,
- HELP_EXPORT,
- HELP_DISPLACEMENT,
- HELP_VIEW,
- HELP_PIPE,
- HELP_TAB,
- HELP_GOTO,
- HELP_DELETE,
- HELP_ADD,
- HELP_COPY_PASTE,
- HELP_EDIT,
- HELP_ENOTE,
- HELP_VNOTE,
- HELP_PRIORITY,
- HELP_REPEAT,
- HELP_FLAG,
- HELP_CONFIG,
- HELP_GENERAL,
- HELP_OTHER,
- HELP_CREDITS,
- HELPSCREENS,
- NOPAGE
+ HELP_MAIN,
+ HELP_SAVE,
+ HELP_IMPORT,
+ HELP_EXPORT,
+ HELP_DISPLACEMENT,
+ HELP_VIEW,
+ HELP_PIPE,
+ HELP_TAB,
+ HELP_GOTO,
+ HELP_DELETE,
+ HELP_ADD,
+ HELP_COPY_PASTE,
+ HELP_EDIT,
+ HELP_ENOTE,
+ HELP_VNOTE,
+ HELP_PRIORITY,
+ HELP_REPEAT,
+ HELP_FLAG,
+ HELP_CONFIG,
+ HELP_GENERAL,
+ HELP_OTHER,
+ HELP_CREDITS,
+ HELPSCREENS,
+ NOPAGE
} help_pages_e;
/* Returns the number of lines in an help text. */
static int get_help_lines(char *text)
{
- int i, newline;
-
- newline = 0;
- for (i = 0; text[i]; i++) {
- if (text[i] == '\n')
- newline++;
- }
- return newline + 1;
+ int i, newline;
+
+ newline = 0;
+ for (i = 0; text[i]; i++) {
+ if (text[i] == '\n')
+ newline++;
+ }
+ return newline + 1;
}
/*
@@ -93,57 +93,61 @@ static int get_help_lines(char *text)
* of lines that were written.
*/
static int
-help_write_pad(struct window *win, char *title, char *text, enum key action)
+help_write_pad(struct window *win, char *title, char *text,
+ enum key action)
{
- int colnum, rownum;
- const char *bindings_title = _("key bindings: %s");
- char *bindings;
-
- colnum = 0;
- rownum = 0;
- erase_window_part(win->p, rownum, colnum, BUFSIZ, win->w);
- custom_apply_attr(win->p, ATTR_HIGHEST);
- mvwaddstr(win->p, rownum, colnum, title);
- if ((int)action != KEY_RESIZE && action < NBKEYS) {
- switch (action) {
- case KEY_END_OF_WEEK:
- case KEY_START_OF_WEEK:
- case KEY_MOVE_UP:
- case KEY_MOVE_DOWN:
- case KEY_MOVE_RIGHT:
- case KEY_MOVE_LEFT:
- case KEY_GENERIC_HELP:
- case KEY_GENERIC_REDRAW:
- case KEY_GENERIC_ADD_APPT:
- case KEY_GENERIC_ADD_TODO:
- case KEY_GENERIC_PREV_DAY:
- case KEY_GENERIC_NEXT_DAY:
- case KEY_GENERIC_PREV_WEEK:
- case KEY_GENERIC_NEXT_WEEK:
- case KEY_GENERIC_PREV_MONTH:
- case KEY_GENERIC_NEXT_MONTH:
- case KEY_GENERIC_PREV_YEAR:
- case KEY_GENERIC_NEXT_YEAR:
- case KEY_GENERIC_GOTO_TODAY:
- case KEY_GENERIC_CREDITS:
- case KEY_GENERIC_COPY:
- case KEY_GENERIC_PASTE:
- break;
- default:
- bindings = keys_action_allkeys(action);
-
- if (bindings) {
- colnum = win->w - strlen(bindings_title) - strlen(bindings);
- mvwprintw(win->p, rownum, colnum, bindings_title, bindings);
- }
- }
- }
- colnum = 0;
- rownum += get_help_lines(title);
- custom_remove_attr(win->p, ATTR_HIGHEST);
- mvwaddstr(win->p, rownum, colnum, text);
- rownum += get_help_lines(text);
- return rownum;
+ int colnum, rownum;
+ const char *bindings_title = _("key bindings: %s");
+ char *bindings;
+
+ colnum = 0;
+ rownum = 0;
+ erase_window_part(win->p, rownum, colnum, BUFSIZ, win->w);
+ custom_apply_attr(win->p, ATTR_HIGHEST);
+ mvwaddstr(win->p, rownum, colnum, title);
+ if ((int)action != KEY_RESIZE && action < NBKEYS) {
+ switch (action) {
+ case KEY_END_OF_WEEK:
+ case KEY_START_OF_WEEK:
+ case KEY_MOVE_UP:
+ case KEY_MOVE_DOWN:
+ case KEY_MOVE_RIGHT:
+ case KEY_MOVE_LEFT:
+ case KEY_GENERIC_HELP:
+ case KEY_GENERIC_REDRAW:
+ case KEY_GENERIC_ADD_APPT:
+ case KEY_GENERIC_ADD_TODO:
+ case KEY_GENERIC_PREV_DAY:
+ case KEY_GENERIC_NEXT_DAY:
+ case KEY_GENERIC_PREV_WEEK:
+ case KEY_GENERIC_NEXT_WEEK:
+ case KEY_GENERIC_PREV_MONTH:
+ case KEY_GENERIC_NEXT_MONTH:
+ case KEY_GENERIC_PREV_YEAR:
+ case KEY_GENERIC_NEXT_YEAR:
+ case KEY_GENERIC_GOTO_TODAY:
+ case KEY_GENERIC_CREDITS:
+ case KEY_GENERIC_COPY:
+ case KEY_GENERIC_PASTE:
+ break;
+ default:
+ bindings = keys_action_allkeys(action);
+
+ if (bindings) {
+ colnum =
+ win->w - strlen(bindings_title) -
+ strlen(bindings);
+ mvwprintw(win->p, rownum, colnum,
+ bindings_title, bindings);
+ }
+ }
+ }
+ colnum = 0;
+ rownum += get_help_lines(title);
+ custom_remove_attr(win->p, ATTR_HIGHEST);
+ mvwaddstr(win->p, rownum, colnum, text);
+ rownum += get_help_lines(text);
+ return rownum;
}
/*
@@ -152,22 +156,22 @@ help_write_pad(struct window *win, char *title, char *text, enum key action)
*/
void help_wins_init(struct scrollwin *hwin, int x, int y, int h, int w)
{
- const int PADOFFSET = 4;
- const int TITLELINES = 3;
-
- hwin->win.x = x;
- hwin->win.y = y;
- hwin->win.h = h;
- hwin->win.w = w;
-
- hwin->pad.x = PADOFFSET;
- hwin->pad.y = TITLELINES;
- hwin->pad.h = BUFSIZ;
- hwin->pad.w = hwin->win.w - 2 * PADOFFSET + 1;
-
- hwin->label = _("Calcurse help");
- wins_scrollwin_init(hwin);
- wins_show(hwin->win.p, hwin->label);
+ const int PADOFFSET = 4;
+ const int TITLELINES = 3;
+
+ hwin->win.x = x;
+ hwin->win.y = y;
+ hwin->win.h = h;
+ hwin->win.w = w;
+
+ hwin->pad.x = PADOFFSET;
+ hwin->pad.y = TITLELINES;
+ hwin->pad.h = BUFSIZ;
+ hwin->pad.w = hwin->win.w - 2 * PADOFFSET + 1;
+
+ hwin->label = _("Calcurse help");
+ wins_scrollwin_init(hwin);
+ wins_show(hwin->win.p, hwin->label);
}
/*
@@ -176,626 +180,625 @@ void help_wins_init(struct scrollwin *hwin, int x, int y, int h, int w)
*/
static void help_wins_reinit(struct scrollwin *hwin)
{
- wins_scrollwin_delete(hwin);
- wins_get_config();
- help_wins_init(hwin, 0, 0, (notify_bar())? row - 3 : row - 2, col);
+ wins_scrollwin_delete(hwin);
+ wins_get_config();
+ help_wins_init(hwin, 0, 0, (notify_bar())? row - 3 : row - 2, col);
}
/* Reset the screen, needed when resizing terminal for example. */
static void help_wins_reset(struct scrollwin *hwin)
{
- endwin();
- wins_refresh();
- curs_set(0);
- delwin(win[STA].p);
- help_wins_reinit(hwin);
- win[STA].p = newwin(win[STA].h, win[STA].w, win[STA].y, win[STA].x);
- keypad(win[STA].p, TRUE);
- if (notify_bar())
- notify_reinit_bar();
- wins_status_bar();
- if (notify_bar())
- notify_update_bar();
+ endwin();
+ wins_refresh();
+ curs_set(0);
+ delwin(win[STA].p);
+ help_wins_reinit(hwin);
+ win[STA].p =
+ newwin(win[STA].h, win[STA].w, win[STA].y, win[STA].x);
+ keypad(win[STA].p, TRUE);
+ if (notify_bar())
+ notify_reinit_bar();
+ wins_status_bar();
+ if (notify_bar())
+ notify_update_bar();
}
/* Association between a key pressed and its corresponding help page. */
static int wanted_page(int ch)
{
- int page;
-
- switch (ch) {
-
- case KEY_GENERIC_HELP:
- page = HELP_MAIN;
- break;
-
- case KEY_FLAG_ITEM:
- page = HELP_FLAG;
- break;
-
- case KEY_GENERIC_REDRAW:
- case KEY_GENERIC_ADD_APPT:
- case KEY_GENERIC_ADD_TODO:
- case KEY_GENERIC_PREV_DAY:
- case KEY_GENERIC_NEXT_DAY:
- case KEY_GENERIC_PREV_WEEK:
- case KEY_GENERIC_NEXT_WEEK:
- case KEY_GENERIC_PREV_MONTH:
- case KEY_GENERIC_NEXT_MONTH:
- case KEY_GENERIC_PREV_YEAR:
- case KEY_GENERIC_NEXT_YEAR:
- case KEY_GENERIC_GOTO_TODAY:
- page = HELP_GENERAL;
- break;
-
- case KEY_GENERIC_SAVE:
- page = HELP_SAVE;
- break;
-
- case KEY_GENERIC_IMPORT:
- page = HELP_IMPORT;
- break;
-
- case KEY_GENERIC_EXPORT:
- page = HELP_EXPORT;
- break;
-
- case KEY_END_OF_WEEK:
- case KEY_START_OF_WEEK:
- case KEY_MOVE_UP:
- case KEY_MOVE_DOWN:
- case KEY_MOVE_RIGHT:
- case KEY_MOVE_LEFT:
- page = HELP_DISPLACEMENT;
- break;
-
- case KEY_ADD_ITEM:
- page = HELP_ADD;
- break;
-
- case KEY_GENERIC_GOTO:
- page = HELP_GOTO;
- break;
-
- case KEY_DEL_ITEM:
- page = HELP_DELETE;
- break;
-
- case KEY_GENERIC_COPY:
- case KEY_GENERIC_PASTE:
- page = HELP_COPY_PASTE;
- break;
-
- case KEY_EDIT_ITEM:
- page = HELP_EDIT;
- break;
-
- case KEY_EDIT_NOTE:
- page = HELP_ENOTE;
- break;
-
- case KEY_VIEW_NOTE:
- page = HELP_VNOTE;
- break;
-
- case KEY_GENERIC_CONFIG_MENU:
- page = HELP_CONFIG;
- break;
-
- case KEY_GENERIC_OTHER_CMD:
- page = HELP_OTHER;
- break;
-
- case KEY_REPEAT_ITEM:
- page = HELP_REPEAT;
- break;
-
- case KEY_VIEW_ITEM:
- page = HELP_VIEW;
- break;
-
- case KEY_PIPE_ITEM:
- page = HELP_PIPE;
- break;
-
- case KEY_RAISE_PRIORITY:
- case KEY_LOWER_PRIORITY:
- page = HELP_PRIORITY;
- break;
-
- case KEY_GENERIC_CHANGE_VIEW:
- page = HELP_TAB;
- break;
-
- case KEY_GENERIC_CREDITS:
- page = HELP_CREDITS;
- break;
-
- default:
- page = NOPAGE;
- break;
- }
-
- return page;
+ int page;
+
+ switch (ch) {
+
+ case KEY_GENERIC_HELP:
+ page = HELP_MAIN;
+ break;
+
+ case KEY_FLAG_ITEM:
+ page = HELP_FLAG;
+ break;
+
+ case KEY_GENERIC_REDRAW:
+ case KEY_GENERIC_ADD_APPT:
+ case KEY_GENERIC_ADD_TODO:
+ case KEY_GENERIC_PREV_DAY:
+ case KEY_GENERIC_NEXT_DAY:
+ case KEY_GENERIC_PREV_WEEK:
+ case KEY_GENERIC_NEXT_WEEK:
+ case KEY_GENERIC_PREV_MONTH:
+ case KEY_GENERIC_NEXT_MONTH:
+ case KEY_GENERIC_PREV_YEAR:
+ case KEY_GENERIC_NEXT_YEAR:
+ case KEY_GENERIC_GOTO_TODAY:
+ page = HELP_GENERAL;
+ break;
+
+ case KEY_GENERIC_SAVE:
+ page = HELP_SAVE;
+ break;
+
+ case KEY_GENERIC_IMPORT:
+ page = HELP_IMPORT;
+ break;
+
+ case KEY_GENERIC_EXPORT:
+ page = HELP_EXPORT;
+ break;
+
+ case KEY_END_OF_WEEK:
+ case KEY_START_OF_WEEK:
+ case KEY_MOVE_UP:
+ case KEY_MOVE_DOWN:
+ case KEY_MOVE_RIGHT:
+ case KEY_MOVE_LEFT:
+ page = HELP_DISPLACEMENT;
+ break;
+
+ case KEY_ADD_ITEM:
+ page = HELP_ADD;
+ break;
+
+ case KEY_GENERIC_GOTO:
+ page = HELP_GOTO;
+ break;
+
+ case KEY_DEL_ITEM:
+ page = HELP_DELETE;
+ break;
+
+ case KEY_GENERIC_COPY:
+ case KEY_GENERIC_PASTE:
+ page = HELP_COPY_PASTE;
+ break;
+
+ case KEY_EDIT_ITEM:
+ page = HELP_EDIT;
+ break;
+
+ case KEY_EDIT_NOTE:
+ page = HELP_ENOTE;
+ break;
+
+ case KEY_VIEW_NOTE:
+ page = HELP_VNOTE;
+ break;
+
+ case KEY_GENERIC_CONFIG_MENU:
+ page = HELP_CONFIG;
+ break;
+
+ case KEY_GENERIC_OTHER_CMD:
+ page = HELP_OTHER;
+ break;
+
+ case KEY_REPEAT_ITEM:
+ page = HELP_REPEAT;
+ break;
+
+ case KEY_VIEW_ITEM:
+ page = HELP_VIEW;
+ break;
+
+ case KEY_PIPE_ITEM:
+ page = HELP_PIPE;
+ break;
+
+ case KEY_RAISE_PRIORITY:
+ case KEY_LOWER_PRIORITY:
+ page = HELP_PRIORITY;
+ break;
+
+ case KEY_GENERIC_CHANGE_VIEW:
+ page = HELP_TAB;
+ break;
+
+ case KEY_GENERIC_CREDITS:
+ page = HELP_CREDITS;
+ break;
+
+ default:
+ page = NOPAGE;
+ break;
+ }
+
+ return page;
}
/* Draws the help screen */
void help_screen(void)
{
- enum {
- MOVE_UP,
- MOVE_DOWN,
- MOVE_LEFT,
- MOVE_RIGHT,
- DIRECTIONS
- };
- struct scrollwin hwin;
- int need_resize;
- enum key ch = KEY_GENERIC_HELP;
- int page, oldpage;
- help_page_t hscr[HELPSCREENS];
- char keystr[DIRECTIONS][BUFSIZ];
-
- hscr[HELP_MAIN].title =
- _(" Welcome to Calcurse. This is the main help screen.\n");
- snprintf(hscr[HELP_MAIN].text, HELPTEXTSIZ,
- _
- ("Moving around: Press '%s' or '%s' to scroll text upward or downward\n"
- " inside help screens, if necessary.\n\n"
- " Exit help: When finished, press '%s' to exit help and go back to\n"
- " the main Calcurse screen.\n\n"
- " Help topic: At the bottom of this screen you can see a panel with\n"
- " different fields, represented by a letter and a short\n"
- " title. This panel contains all the available actions\n"
- " you can perform when using Calcurse.\n"
- " By pressing one of the letters appearing in this\n"
- " panel, you will be shown a short description of the\n"
- " corresponding action. At the top right side of the\n"
- " description screen are indicated the user-defined key\n"
- " bindings that lead to the action.\n\n"
- " Credits: Press '%s' for credits."),
- keys_action_firstkey(KEY_GENERIC_SCROLL_UP),
- keys_action_firstkey(KEY_GENERIC_SCROLL_DOWN),
- keys_action_firstkey(KEY_GENERIC_QUIT),
- keys_action_firstkey(KEY_GENERIC_CREDITS));
-
- hscr[HELP_SAVE].title = _("Save\n");
- snprintf(hscr[HELP_SAVE].text, HELPTEXTSIZ,
- _("Save calcurse data.\n"
- "Data are splitted into four different files which contain :"
- "\n\n"
- " / ~/.calcurse/conf -> user configuration\n"
- " | (layout, color, general options)\n"
- " | ~/.calcurse/apts -> data related to the appointments\n"
- " | ~/.calcurse/todo -> data related to the todo list\n"
- " \\ ~/.calcurse/keys -> user-defined key bindings\n"
- "\nIn the config menu, you can choose to save the Calcurse data\n"
- "automatically before quitting."));
-
- hscr[HELP_IMPORT].title = _("Import\n");
- snprintf(hscr[HELP_IMPORT].text, HELPTEXTSIZ,
- _("Import data from an icalendar file.\n"
- "You will be asked to enter the file name from which to load ical\n"
- "items. At the end of the import process, and if the general option\n"
- "'system_dialogs' is set to 'yes', a report indicating how many items\n"
- "were imported is shown.\n"
- "This report contains the total number of lines read, the number of\n"
- "appointments, events and todo items which were successfully imported,\n"
- "together with the number of items for which problems occured and that\n"
- "were skipped, if any.\n\n"
- "If one or more items could not be imported, one has the possibility to\n"
- "read the import process report in order to identify which problems\n"
- "occured.\n"
- "In this report is shown one item per line, with the line in the input\n"
- "stream at which this item begins, together with the description of why\n"
- "the item could not be imported.\n"));
-
- hscr[HELP_EXPORT].title = _("Export\n");
- snprintf(hscr[HELP_EXPORT].text, HELPTEXTSIZ,
- _("Export calcurse data (appointments, events and todos).\n"
- "This leads to the export submenu, from which you can choose between\n"
- "two different export formats: 'ical' and 'pcal'. Choosing one of\n"
- "those formats lets you export calcurse data to icalendar or pcal\n"
- "format.\n\n"
- "You first need to specify the file to which the data will be exported.\n"
- "By default, this file is:\n\n"
- " ~/calcurse.ics\n\n"
- "for an ical export, and:\n\n"
- " ~/calcurse.txt\n\n"
- "for a pcal export.\n\n"
- "Calcurse data are exported in the following order:\n"
- " events, appointments, todos.\n"));
-
- strncpy(keystr[MOVE_UP], keys_action_allkeys(KEY_MOVE_UP), BUFSIZ);
- strncpy(keystr[MOVE_DOWN], keys_action_allkeys(KEY_MOVE_DOWN), BUFSIZ);
- strncpy(keystr[MOVE_LEFT], keys_action_allkeys(KEY_MOVE_LEFT), BUFSIZ);
- strncpy(keystr[MOVE_RIGHT], keys_action_allkeys(KEY_MOVE_RIGHT), BUFSIZ);
- hscr[HELP_DISPLACEMENT].title = _("Displacement keys\n");
- snprintf(hscr[HELP_DISPLACEMENT].text, HELPTEXTSIZ,
- _("Move around inside calcurse screens.\n"
- "The following scheme summarizes how to get around:\n\n"
- " move up\n"
- " move to previous week\n"
- "\n"
- " %s\n"
- " move left ^ \n"
- " move to previous day |\n"
- " %s\n"
- " <-- + -->\n"
- " %s\n"
- " | move right\n"
- " v move to next day\n"
- " %s\n"
- "\n"
- " move to next week\n"
- " move down\n"
- "\nMoreover, while inside the calendar panel, the '%s' key moves\n"
- "to the first day of the week, and the '%s' key selects the last day of\n"
- "the week.\n"),
- keystr[MOVE_UP], keystr[MOVE_LEFT],
- keystr[MOVE_RIGHT], keystr[MOVE_DOWN],
- keys_action_firstkey(KEY_START_OF_WEEK),
- keys_action_firstkey(KEY_END_OF_WEEK));
-
- hscr[HELP_VIEW].title = _("View\n");
- snprintf(hscr[HELP_VIEW].text, HELPTEXTSIZ,
- _
- ("View the item you select in either the Todo or Appointment panel.\n"
- "\nThis is usefull when an event description is longer than the "
- "available\nspace to display it. "
- "If that is the case, the description will be\n"
- "shortened and its end replaced by '...'. To be able to read the entire\n"
- "description, just press '%s' and a popup window will appear, containing\n"
- "the whole event.\n"
- "\nPress any key to close the popup window and go back to the main\n"
- "Calcurse screen."), keys_action_firstkey(KEY_VIEW_ITEM));
-
- hscr[HELP_PIPE].title = _("Pipe\n");
- snprintf(hscr[HELP_PIPE].text, HELPTEXTSIZ,
- _("Pipe the selected item to an external program.\n"
- "\nPress the '%s' key to pipe the currently selected appointment or\n"
- "todo entry to an external program.\n"
- "\nYou will be driven back to calcurse as soon as the program exits.\n"),
- keys_action_firstkey(KEY_PIPE_ITEM));
-
- hscr[HELP_TAB].title = _("Tab\n");
- snprintf(hscr[HELP_TAB].text, HELPTEXTSIZ,
- _("Switch between panels.\n"
- "The panel currently in use has its border colorized.\n"
- "\nSome actions are possible only if the right panel is selected.\n"
- "For example, if you want to add a task in the TODO list, you need first"
- "\nto press the '%s' key to get the TODO panel selected. Then you can\n"
- "press '%s' to add your item.\n"
- "\nNotice that at the bottom of the screen the list of possible actions\n"
- "change while pressing '%s', so you always know what action can be\n"
- "performed on the selected panel."),
- keys_action_firstkey(KEY_GENERIC_CHANGE_VIEW),
- keys_action_firstkey(KEY_ADD_ITEM),
- keys_action_firstkey(KEY_GENERIC_CHANGE_VIEW));
-
- hscr[HELP_GOTO].title = _("Goto\n");
- snprintf(hscr[HELP_GOTO].text, HELPTEXTSIZ,
- _("Jump to a specific day in the calendar.\n"
- "\nUsing this command, you do not need to travel to that day using\n"
- "the displacement keys inside the calendar panel.\n"
- "If you hit [ENTER] without specifying any date, Calcurse checks the\n"
- "system current date and you will be taken to that date.\n"
- "\nNotice that pressing '%s', whatever panel is\n"
- "selected, will select current day in the calendar."),
- keys_action_firstkey(KEY_GENERIC_GOTO_TODAY));
-
- hscr[HELP_DELETE].title = _("Delete\n");
- snprintf(hscr[HELP_DELETE].text, HELPTEXTSIZ,
- _("Delete an element in the ToDo or Appointment list.\n"
- "\nDepending on which panel is selected when you press the delete key,\n"
- "the hilighted item of either the ToDo or Appointment list will be \n"
- "removed from this list.\n"
- "\nIf the item to be deleted is recurrent, you will be asked if you\n"
- "wish to suppress all of the item occurences or just the one you\n"
- "selected.\n"
- "\nIf the general option 'confirm_delete' is set to 'YES', then you will"
- "\nbe asked for confirmation before deleting the selected event.\n"
- "Do not forget to save the calendar data to retrieve the modifications\n"
- "next time you launch Calcurse."));
-
- hscr[HELP_ADD].title = _("Add\n");
- snprintf(hscr[HELP_ADD].text, HELPTEXTSIZ,
- _
- ("Add an item in either the ToDo or Appointment list, depending on which\n"
- "panel is selected when you press '%s'.\n"
- "\nTo enter a new item in the TODO list, you will need first to enter the"
- "\ndescription of this new item. Then you will be asked to specify the "
- "todo\npriority. This priority is represented by a number going from 9 "
- "for the\nlowest priority, to 1 for the highest one. It is still "
- "possible to\nchange the item priority afterwards, by using the '%s' and "
- "'%s' keys\ninside the todo panel.\n"
- "\nIf the APPOINTMENT panel is selected while pressing '%s', you will be\n"
- "able to enter either a new appointment or a new all-day long event.\n"
- "To enter a new event, press [ENTER] instead of the item start time, "
- "and\njust fill in the event description.\n"
- "To enter a new appointment to be added in the APPOINTMENT list, you\n"
- "will need to enter successively the time at which the appointment\n"
- "begins, the appointment length (either by specifying the end time in\n"
- "[hh:mm] or the duration in [+hh:mm], [+xxdxxhxxm] or [+mm] format), \n"
- "and the description of the event.\n"
- "\nThe day at which occurs the event or appointment is the day currently"
- "\nselected in the calendar, so you need to move to the desired day "
- "before\npressing '%s'.\n" "\nNotes:\n"
- " o if an appointment lasts for such a long time that it continues\n"
- " on the next days, this event will be indicated on all the\n"
- " corresponding days, and the beginning or ending hour will be\n"
- " replaced by '..' if the event does not begin or end on the day.\n"
- " o if you only press [ENTER] at the APPOINTMENT or TODO event\n"
- " description prompt, without any description, no item will be\n"
- " added.\n"
- " o do not forget to save the calendar data to retrieve the new\n"
- " event next time you launch Calcurse."),
- keys_action_firstkey(KEY_ADD_ITEM),
- keys_action_firstkey(KEY_RAISE_PRIORITY),
- keys_action_firstkey(KEY_LOWER_PRIORITY),
- keys_action_firstkey(KEY_ADD_ITEM),
- keys_action_firstkey(KEY_ADD_ITEM));
-
- hscr[HELP_COPY_PASTE].title = _("Copy and Paste\n");
- snprintf(hscr[HELP_COPY_PASTE].text, HELPTEXTSIZ,
- _
- (
- "Copy and paste the currently selected item. This is useful to quickly\n"
- "copy an item from one date to another. To do so, one must first\n"
- "highlight the item that needs to be copied, then press '%s' to copy.\n"
- "Once the new date is chosen in the calendar, the appointment panel must\n"
- "be selected and the '%s' key must be pressed to paste the item. The item\n"
- "will appear in the appointment panel, assigned to the newly selected\n"
- "date.\n\n"),
- keys_action_firstkey(KEY_GENERIC_COPY),
- keys_action_firstkey(KEY_GENERIC_PASTE));
-
- hscr[HELP_EDIT].title = _("Edit Item\n");
- snprintf(hscr[HELP_EDIT].text, HELPTEXTSIZ,
- _("Edit the item which is currently selected.\n"
- "Depending on the item type (appointment, event, or todo), and if it is\n"
- "repeated or not, you will be asked to choose one of the item properties"
- "\nto modify. An item property is one of the following: the start time, "
- "the\nend time, the description, or the item repetition.\n"
- "Once you have chosen the property you want to modify, you will be shown"
- "\nits actual value, and you will be able to change it as you like.\n"
- "\nNotes:\n"
- " o if you choose to edit the item repetition properties, you will\n"
- " be asked to re-enter all of the repetition characteristics\n"
- " (repetition type, frequence, and ending date). Moreover, the\n"
- " previous data concerning the deleted occurences will be lost.\n"
- " o do not forget to save the calendar data to retrieve the\n"
- " modified properties next time you launch Calcurse."));
-
- hscr[HELP_ENOTE].title = _("EditNote\n");
- snprintf(hscr[HELP_ENOTE].text, HELPTEXTSIZ,
- _
- ("Attach a note to any type of item, or edit an already existing note.\n"
- "This feature is useful if you do not have enough space to store all\n"
- "of your item description, or if you would like to add sub-tasks to an\n"
- "already existing todo item for example.\n"
- "Before pressing the '%s' key, you first need to highlight the item you\n"
- "want the note to be attached to. Then you will be driven to an\n"
- "external editor to edit your note. This editor is chosen the following\n"
- "way:\n"
- " o if the 'VISUAL' environment variable is set, then this will be\n"
- " the default editor to be called.\n"
- " o if 'VISUAL' is not set, then the 'EDITOR' environment variable\n"
- " will be used as the default editor.\n"
- " o if none of the above environment variables is set, then\n"
- " '/usr/bin/vi' will be used.\n"
- "\nOnce the item note is edited and saved, quit your favorite editor.\n"
- "You will then go back to Calcurse, and the '>' sign will appear in front"
- "\nof the highlighted item, meaning there is a note attached to it."),
- keys_action_firstkey(KEY_EDIT_NOTE));
-
- hscr[HELP_VNOTE].title = _("ViewNote\n");
- snprintf(hscr[HELP_VNOTE].text, HELPTEXTSIZ,
- _
- ("View a note which was previously attached to an item (an item which\n"
- "owns a note has a '>' sign in front of it).\n"
- "This command only permits to view the note, not to edit it (to do so,\n"
- "use the 'EditNote' command, by pressing the '%s' key).\n"
- "Once you highlighted an item with a note attached to it, and the '%s' key"
- "\nwas pressed, you will be driven to an external pager to view that "
- "note.\n" "The default pager is chosen the following way:\n"
- " o if the 'PAGER' environment variable is set, then this will be\n"
- " the default viewer to be called.\n"
- " o if the above environment variable is not set, then\n"
- " '/usr/bin/less' will be used.\n"
- "As for editing a note, quit the pager and you will be driven back to\n"
- "Calcurse."), keys_action_firstkey(KEY_EDIT_NOTE),
- keys_action_firstkey(KEY_VIEW_NOTE));
-
- hscr[HELP_PRIORITY].title = _("Priority\n");
- snprintf(hscr[HELP_PRIORITY].text, HELPTEXTSIZ,
- _
- ("Change the priority of the currently selected item in the ToDo list.\n"
- "Priorities are represented by the number appearing in front of the\n"
- "todo description. This number goes from 9 for the lowest priority to\n"
- "1 for the highest priority.\n"
- "Todo having higher priorities are placed first (at the top) inside the\n"
- "todo panel.\n\n"
- "If you want to raise the priority of a todo item, you need to press "
- "'%s'.\n"
- "In doing so, the number in front of this item will decrease, "
- "meaning its\npriority increases. The item position inside the todo "
- "panel may change,\ndepending on the priority of the items above it.\n\n"
- "At the opposite, to lower a todo priority, press '%s'. The todo position"
- "\nmay also change depending on the priority of the items below."),
- keys_action_firstkey(KEY_RAISE_PRIORITY),
- keys_action_firstkey(KEY_LOWER_PRIORITY));
-
- hscr[HELP_REPEAT].title = _("Repeat\n");
- snprintf(hscr[HELP_REPEAT].text, HELPTEXTSIZ,
- _("Repeat an event or an appointment.\n"
- "You must first select the item to be repeated by moving inside the\n"
- "appointment panel. Then pressing '%s' will lead you to a set of three\n"
- "questions, with which you will be able to specify the repetition\n"
- "characteristics:\n\n"
- " o type: you can choose between a daily, weekly, monthly or\n"
- " yearly repetition by pressing 'D', 'W', 'M' or 'Y'\n"
- " respectively.\n\n"
- " o frequence: this indicates how often the item shall be repeated.\n"
- " For example, if you want to remember an anniversary,\n"
- " choose a 'yearly' repetition with a frequence of '1',\n"
- " which means it must be repeated every year. Another\n"
- " example: if you go to the restaurant every two days,\n"
- " choose a 'daily' repetition with a frequence of '2'.\n\n"
- " o ending date: this specifies when to stop repeating the selected\n"
- " event or appointment. To indicate an endless \n"
- " repetition, enter '0' and the item will be repeated\n"
- " forever.\n" "\nNotes:\n"
- " o repeated items are marked with an '*' inside the appointment\n"
- " panel, to be easily recognizable from non-repeated ones.\n"
- " o the 'Repeat' and 'Delete' command can be mixed to create\n"
- " complicated configurations, as it is possible to delete only\n"
- " one occurence of a repeated item."),
- keys_action_firstkey(KEY_REPEAT_ITEM));
-
- hscr[HELP_FLAG].title = _("Flag Item\n");
- snprintf(hscr[HELP_FLAG].text, HELPTEXTSIZ,
- _
- ("Toggle an appointment's 'important' flag or a todo's 'completed' flag.\n"
- "If a todo is flagged as completed, its priority number will be replaced\n"
- "by an 'X' sign. Completed tasks will no longer appear in exported data\n"
- "or when using the '-t' command line flag (unless specifying '0' as the\n"
- "priority number, in which case only completed tasks will be shown).\n\n"
- "If an appointment is flagged as important, an exclamation mark appears\n"
- "in front of it, and you will be warned if time gets closed to the\n"
- "appointment start time.\n"
- "To customize the way one gets notified, the configuration submenu lets\n"
- "you choose the command launched to warn user of an upcoming appointment,"
- "\nand how long before it he gets notified."));
-
- hscr[HELP_CONFIG].title = _("Config\n");
- snprintf(hscr[HELP_CONFIG].text, HELPTEXTSIZ,
- _("Open the configuration submenu.\n"
- "From this submenu, you can select between color, layout, notification\n"
- "and general options, and you can also configure your keybindings.\n"
- "\nThe color submenu lets you choose the color theme.\n"
- "The layout submenu lets you choose the Calcurse screen layout, in other"
- "\nwords where to place the three different panels on the screen.\n"
- "The general options submenu brings a screen with the different options"
- "\nwhich modifies the way Calcurse interacts with the user.\n"
- "The notify submenu allows you to change the notify-bar settings.\n"
- "The keys submenu lets you define your own key bindings.\n"
- "\nDo not forget to save the calendar data to retrieve your configuration"
- "\nnext time you launch Calcurse."));
-
- hscr[HELP_GENERAL].title = _("Generic keybindings\n");
- snprintf(hscr[HELP_GENERAL].text, HELPTEXTSIZ,
- _
- ("Some of the keybindings apply whatever panel is selected. They are\n"
- "called generic keybinding.\n"
- "Here is the list of all the generic key bindings, together with their\n"
- "corresponding action:\n\n"
- " '%s' : Redraw function -> redraws calcurse panels, this is useful if\n"
- " you resize your terminal screen or when\n"
- " garbage appears inside the display\n"
- " '%s' : Add Appointment -> add an appointment or an event\n"
- " '%s' : Add ToDo -> add a todo\n"
- " '%s' : -1 Day -> move to previous day\n"
- " '%s' : +1 Day -> move to next day\n"
- " '%s' : -1 Week -> move to previous week\n"
- " '%s' : +1 Week -> move to next week\n"
- " '%s' : -1 Month -> move to previous month\n"
- " '%s' : +1 Month -> move to next month\n"
- " '%s' : -1 Year -> move to previous year\n"
- " '%s' : +1 Year -> move to next year\n"
- " '%s' : Goto today -> move to current day\n"
- "\nThe '%s' and '%s' keys are used to scroll text upward or downward\n"
- "when inside specific screens such the help screens for example.\n"
- "They are also used when the calendar screen is selected to switch\n"
- "between the available views (monthly and weekly calendar views)."),
- keys_action_firstkey(KEY_GENERIC_REDRAW),
- keys_action_firstkey(KEY_GENERIC_ADD_APPT),
- keys_action_firstkey(KEY_GENERIC_ADD_TODO),
- keys_action_firstkey(KEY_GENERIC_PREV_DAY),
- keys_action_firstkey(KEY_GENERIC_NEXT_DAY),
- keys_action_firstkey(KEY_GENERIC_PREV_WEEK),
- keys_action_firstkey(KEY_GENERIC_NEXT_WEEK),
- keys_action_firstkey(KEY_GENERIC_PREV_MONTH),
- keys_action_firstkey(KEY_GENERIC_NEXT_MONTH),
- keys_action_firstkey(KEY_GENERIC_PREV_YEAR),
- keys_action_firstkey(KEY_GENERIC_NEXT_YEAR),
- keys_action_firstkey(KEY_GENERIC_GOTO_TODAY),
- keys_action_firstkey(KEY_GENERIC_SCROLL_UP),
- keys_action_firstkey(KEY_GENERIC_SCROLL_DOWN));
-
- hscr[HELP_OTHER].title = _("OtherCmd\n");
- snprintf(hscr[HELP_OTHER].text, HELPTEXTSIZ,
- _("Switch between status bar help pages.\n"
- "Because the terminal screen is too narrow to display all of the\n"
- "available commands, you need to press '%s' to see the next set of\n"
- "commands together with their keybindings.\n"
- "Once the last status bar page is reached, pressing '%s' another time\n"
- "leads you back to the first page."),
- keys_action_firstkey(KEY_GENERIC_OTHER_CMD),
- keys_action_firstkey(KEY_GENERIC_OTHER_CMD));
-
- hscr[HELP_CREDITS].title = _("Calcurse - text-based organizer");
- snprintf(hscr[HELP_CREDITS].text, HELPTEXTSIZ,
- _("\nCopyright (c) 2004-2013 calcurse Development Team\n"
- "All rights reserved.\n"
- "\n"
- "Redistribution and use in source and binary forms, with or without\n"
- "modification, are permitted provided that the following conditions\n"
- "are met:\n"
- "\n"
- "\t- Redistributions of source code must retain the above\n"
- "\t copyright notice, this list of conditions and the\n"
- "\t following disclaimer.\n"
- "\n"
- "\t- Redistributions in binary form must reproduce the above\n"
- "\t copyright notice, this list of conditions and the\n"
- "\t following disclaimer in the documentation and/or other\n"
- "\t materials provided with the distribution.\n"
- "\n\n"
- "Send your feedback or comments to : misc@calcurse.org\n"
- "Calcurse home page : http://calcurse.org"));
-
- help_wins_init(&hwin, 0, 0, (notify_bar())? row - 3 : row - 2, col);
- oldpage = HELP_MAIN;
- need_resize = 0;
-
- /* Display the help screen related to user input. */
- while (ch != KEY_GENERIC_QUIT) {
- erase_window_part(hwin.win.p, 1, hwin.pad.y, col - 2, hwin.win.h - 2);
-
- switch (ch) {
- case KEY_GENERIC_SCROLL_DOWN:
- wins_scrollwin_down(&hwin, 1);
- break;
-
- case KEY_GENERIC_SCROLL_UP:
- wins_scrollwin_up(&hwin, 1);
- break;
-
- default:
- page = wanted_page(ch);
- if (page != NOPAGE) {
- hwin.first_visible_line = 0;
- hwin.total_lines = help_write_pad(&hwin.pad, hscr[page].title,
- hscr[page].text, ch);
- oldpage = page;
- }
- }
-
- if (resize) {
- resize = 0;
- wins_get_config();
- help_wins_reset(&hwin);
- hwin.first_visible_line = 0;
- hwin.total_lines = help_write_pad(&hwin.pad, hscr[oldpage].title,
- hscr[oldpage].text, ch);
- need_resize = 1;
- }
-
- wins_scrollwin_display(&hwin);
- ch = keys_getch(win[KEY].p, NULL, NULL);
- }
- wins_scrollwin_delete(&hwin);
- if (need_resize)
- wins_reset();
+ enum {
+ MOVE_UP,
+ MOVE_DOWN,
+ MOVE_LEFT,
+ MOVE_RIGHT,
+ DIRECTIONS
+ };
+ struct scrollwin hwin;
+ int need_resize;
+ enum key ch = KEY_GENERIC_HELP;
+ int page, oldpage;
+ help_page_t hscr[HELPSCREENS];
+ char keystr[DIRECTIONS][BUFSIZ];
+
+ hscr[HELP_MAIN].title =
+ _(" Welcome to Calcurse. This is the main help screen.\n");
+ snprintf(hscr[HELP_MAIN].text, HELPTEXTSIZ,
+ _("Moving around: Press '%s' or '%s' to scroll text upward or downward\n"
+ " inside help screens, if necessary.\n\n"
+ " Exit help: When finished, press '%s' to exit help and go back to\n"
+ " the main Calcurse screen.\n\n"
+ " Help topic: At the bottom of this screen you can see a panel with\n"
+ " different fields, represented by a letter and a short\n"
+ " title. This panel contains all the available actions\n"
+ " you can perform when using Calcurse.\n"
+ " By pressing one of the letters appearing in this\n"
+ " panel, you will be shown a short description of the\n"
+ " corresponding action. At the top right side of the\n"
+ " description screen are indicated the user-defined key\n"
+ " bindings that lead to the action.\n\n"
+ " Credits: Press '%s' for credits."),
+ keys_action_firstkey(KEY_GENERIC_SCROLL_UP),
+ keys_action_firstkey(KEY_GENERIC_SCROLL_DOWN),
+ keys_action_firstkey(KEY_GENERIC_QUIT),
+ keys_action_firstkey(KEY_GENERIC_CREDITS));
+
+ hscr[HELP_SAVE].title = _("Save\n");
+ snprintf(hscr[HELP_SAVE].text, HELPTEXTSIZ,
+ _("Save calcurse data.\n"
+ "Data are splitted into four different files which contain :"
+ "\n\n"
+ " / ~/.calcurse/conf -> user configuration\n"
+ " | (layout, color, general options)\n"
+ " | ~/.calcurse/apts -> data related to the appointments\n"
+ " | ~/.calcurse/todo -> data related to the todo list\n"
+ " \\ ~/.calcurse/keys -> user-defined key bindings\n"
+ "\nIn the config menu, you can choose to save the Calcurse data\n"
+ "automatically before quitting."));
+
+ hscr[HELP_IMPORT].title = _("Import\n");
+ snprintf(hscr[HELP_IMPORT].text, HELPTEXTSIZ,
+ _("Import data from an icalendar file.\n"
+ "You will be asked to enter the file name from which to load ical\n"
+ "items. At the end of the import process, and if the general option\n"
+ "'system_dialogs' is set to 'yes', a report indicating how many items\n"
+ "were imported is shown.\n"
+ "This report contains the total number of lines read, the number of\n"
+ "appointments, events and todo items which were successfully imported,\n"
+ "together with the number of items for which problems occured and that\n"
+ "were skipped, if any.\n\n"
+ "If one or more items could not be imported, one has the possibility to\n"
+ "read the import process report in order to identify which problems\n"
+ "occured.\n"
+ "In this report is shown one item per line, with the line in the input\n"
+ "stream at which this item begins, together with the description of why\n"
+ "the item could not be imported.\n"));
+
+ hscr[HELP_EXPORT].title = _("Export\n");
+ snprintf(hscr[HELP_EXPORT].text, HELPTEXTSIZ,
+ _("Export calcurse data (appointments, events and todos).\n"
+ "This leads to the export submenu, from which you can choose between\n"
+ "two different export formats: 'ical' and 'pcal'. Choosing one of\n"
+ "those formats lets you export calcurse data to icalendar or pcal\n"
+ "format.\n\n"
+ "You first need to specify the file to which the data will be exported.\n"
+ "By default, this file is:\n\n" " ~/calcurse.ics\n\n"
+ "for an ical export, and:\n\n" " ~/calcurse.txt\n\n"
+ "for a pcal export.\n\n"
+ "Calcurse data are exported in the following order:\n"
+ " events, appointments, todos.\n"));
+
+ strncpy(keystr[MOVE_UP], keys_action_allkeys(KEY_MOVE_UP), BUFSIZ);
+ strncpy(keystr[MOVE_DOWN], keys_action_allkeys(KEY_MOVE_DOWN),
+ BUFSIZ);
+ strncpy(keystr[MOVE_LEFT], keys_action_allkeys(KEY_MOVE_LEFT),
+ BUFSIZ);
+ strncpy(keystr[MOVE_RIGHT], keys_action_allkeys(KEY_MOVE_RIGHT),
+ BUFSIZ);
+ hscr[HELP_DISPLACEMENT].title = _("Displacement keys\n");
+ snprintf(hscr[HELP_DISPLACEMENT].text, HELPTEXTSIZ,
+ _("Move around inside calcurse screens.\n"
+ "The following scheme summarizes how to get around:\n\n"
+ " move up\n"
+ " move to previous week\n"
+ "\n"
+ " %s\n"
+ " move left ^ \n"
+ " move to previous day |\n"
+ " %s\n"
+ " <-- + -->\n"
+ " %s\n"
+ " | move right\n"
+ " v move to next day\n"
+ " %s\n"
+ "\n"
+ " move to next week\n"
+ " move down\n"
+ "\nMoreover, while inside the calendar panel, the '%s' key moves\n"
+ "to the first day of the week, and the '%s' key selects the last day of\n"
+ "the week.\n"),
+ keystr[MOVE_UP], keystr[MOVE_LEFT],
+ keystr[MOVE_RIGHT], keystr[MOVE_DOWN],
+ keys_action_firstkey(KEY_START_OF_WEEK),
+ keys_action_firstkey(KEY_END_OF_WEEK));
+
+ hscr[HELP_VIEW].title = _("View\n");
+ snprintf(hscr[HELP_VIEW].text, HELPTEXTSIZ,
+ _("View the item you select in either the Todo or Appointment panel.\n"
+ "\nThis is usefull when an event description is longer than the "
+ "available\nspace to display it. "
+ "If that is the case, the description will be\n"
+ "shortened and its end replaced by '...'. To be able to read the entire\n"
+ "description, just press '%s' and a popup window will appear, containing\n"
+ "the whole event.\n"
+ "\nPress any key to close the popup window and go back to the main\n"
+ "Calcurse screen."),
+ keys_action_firstkey(KEY_VIEW_ITEM));
+
+ hscr[HELP_PIPE].title = _("Pipe\n");
+ snprintf(hscr[HELP_PIPE].text, HELPTEXTSIZ,
+ _("Pipe the selected item to an external program.\n"
+ "\nPress the '%s' key to pipe the currently selected appointment or\n"
+ "todo entry to an external program.\n"
+ "\nYou will be driven back to calcurse as soon as the program exits.\n"),
+ keys_action_firstkey(KEY_PIPE_ITEM));
+
+ hscr[HELP_TAB].title = _("Tab\n");
+ snprintf(hscr[HELP_TAB].text, HELPTEXTSIZ,
+ _("Switch between panels.\n"
+ "The panel currently in use has its border colorized.\n"
+ "\nSome actions are possible only if the right panel is selected.\n"
+ "For example, if you want to add a task in the TODO list, you need first"
+ "\nto press the '%s' key to get the TODO panel selected. Then you can\n"
+ "press '%s' to add your item.\n"
+ "\nNotice that at the bottom of the screen the list of possible actions\n"
+ "change while pressing '%s', so you always know what action can be\n"
+ "performed on the selected panel."),
+ keys_action_firstkey(KEY_GENERIC_CHANGE_VIEW),
+ keys_action_firstkey(KEY_ADD_ITEM),
+ keys_action_firstkey(KEY_GENERIC_CHANGE_VIEW));
+
+ hscr[HELP_GOTO].title = _("Goto\n");
+ snprintf(hscr[HELP_GOTO].text, HELPTEXTSIZ,
+ _("Jump to a specific day in the calendar.\n"
+ "\nUsing this command, you do not need to travel to that day using\n"
+ "the displacement keys inside the calendar panel.\n"
+ "If you hit [ENTER] without specifying any date, Calcurse checks the\n"
+ "system current date and you will be taken to that date.\n"
+ "\nNotice that pressing '%s', whatever panel is\n"
+ "selected, will select current day in the calendar."),
+ keys_action_firstkey(KEY_GENERIC_GOTO_TODAY));
+
+ hscr[HELP_DELETE].title = _("Delete\n");
+ snprintf(hscr[HELP_DELETE].text, HELPTEXTSIZ,
+ _("Delete an element in the ToDo or Appointment list.\n"
+ "\nDepending on which panel is selected when you press the delete key,\n"
+ "the hilighted item of either the ToDo or Appointment list will be \n"
+ "removed from this list.\n"
+ "\nIf the item to be deleted is recurrent, you will be asked if you\n"
+ "wish to suppress all of the item occurences or just the one you\n"
+ "selected.\n"
+ "\nIf the general option 'confirm_delete' is set to 'YES', then you will"
+ "\nbe asked for confirmation before deleting the selected event.\n"
+ "Do not forget to save the calendar data to retrieve the modifications\n"
+ "next time you launch Calcurse."));
+
+ hscr[HELP_ADD].title = _("Add\n");
+ snprintf(hscr[HELP_ADD].text, HELPTEXTSIZ,
+ _("Add an item in either the ToDo or Appointment list, depending on which\n"
+ "panel is selected when you press '%s'.\n"
+ "\nTo enter a new item in the TODO list, you will need first to enter the"
+ "\ndescription of this new item. Then you will be asked to specify the "
+ "todo\npriority. This priority is represented by a number going from 9 "
+ "for the\nlowest priority, to 1 for the highest one. It is still "
+ "possible to\nchange the item priority afterwards, by using the '%s' and "
+ "'%s' keys\ninside the todo panel.\n"
+ "\nIf the APPOINTMENT panel is selected while pressing '%s', you will be\n"
+ "able to enter either a new appointment or a new all-day long event.\n"
+ "To enter a new event, press [ENTER] instead of the item start time, "
+ "and\njust fill in the event description.\n"
+ "To enter a new appointment to be added in the APPOINTMENT list, you\n"
+ "will need to enter successively the time at which the appointment\n"
+ "begins, the appointment length (either by specifying the end time in\n"
+ "[hh:mm] or the duration in [+hh:mm], [+xxdxxhxxm] or [+mm] format), \n"
+ "and the description of the event.\n"
+ "\nThe day at which occurs the event or appointment is the day currently"
+ "\nselected in the calendar, so you need to move to the desired day "
+ "before\npressing '%s'.\n" "\nNotes:\n"
+ " o if an appointment lasts for such a long time that it continues\n"
+ " on the next days, this event will be indicated on all the\n"
+ " corresponding days, and the beginning or ending hour will be\n"
+ " replaced by '..' if the event does not begin or end on the day.\n"
+ " o if you only press [ENTER] at the APPOINTMENT or TODO event\n"
+ " description prompt, without any description, no item will be\n"
+ " added.\n"
+ " o do not forget to save the calendar data to retrieve the new\n"
+ " event next time you launch Calcurse."),
+ keys_action_firstkey(KEY_ADD_ITEM),
+ keys_action_firstkey(KEY_RAISE_PRIORITY),
+ keys_action_firstkey(KEY_LOWER_PRIORITY),
+ keys_action_firstkey(KEY_ADD_ITEM),
+ keys_action_firstkey(KEY_ADD_ITEM));
+
+ hscr[HELP_COPY_PASTE].title = _("Copy and Paste\n");
+ snprintf(hscr[HELP_COPY_PASTE].text, HELPTEXTSIZ,
+ _("Copy and paste the currently selected item. This is useful to quickly\n"
+ "copy an item from one date to another. To do so, one must first\n"
+ "highlight the item that needs to be copied, then press '%s' to copy.\n"
+ "Once the new date is chosen in the calendar, the appointment panel must\n"
+ "be selected and the '%s' key must be pressed to paste the item. The item\n"
+ "will appear in the appointment panel, assigned to the newly selected\n"
+ "date.\n\n"),
+ keys_action_firstkey(KEY_GENERIC_COPY),
+ keys_action_firstkey(KEY_GENERIC_PASTE));
+
+ hscr[HELP_EDIT].title = _("Edit Item\n");
+ snprintf(hscr[HELP_EDIT].text, HELPTEXTSIZ,
+ _("Edit the item which is currently selected.\n"
+ "Depending on the item type (appointment, event, or todo), and if it is\n"
+ "repeated or not, you will be asked to choose one of the item properties"
+ "\nto modify. An item property is one of the following: the start time, "
+ "the\nend time, the description, or the item repetition.\n"
+ "Once you have chosen the property you want to modify, you will be shown"
+ "\nits actual value, and you will be able to change it as you like.\n"
+ "\nNotes:\n"
+ " o if you choose to edit the item repetition properties, you will\n"
+ " be asked to re-enter all of the repetition characteristics\n"
+ " (repetition type, frequence, and ending date). Moreover, the\n"
+ " previous data concerning the deleted occurences will be lost.\n"
+ " o do not forget to save the calendar data to retrieve the\n"
+ " modified properties next time you launch Calcurse."));
+
+ hscr[HELP_ENOTE].title = _("EditNote\n");
+ snprintf(hscr[HELP_ENOTE].text, HELPTEXTSIZ,
+ _("Attach a note to any type of item, or edit an already existing note.\n"
+ "This feature is useful if you do not have enough space to store all\n"
+ "of your item description, or if you would like to add sub-tasks to an\n"
+ "already existing todo item for example.\n"
+ "Before pressing the '%s' key, you first need to highlight the item you\n"
+ "want the note to be attached to. Then you will be driven to an\n"
+ "external editor to edit your note. This editor is chosen the following\n"
+ "way:\n"
+ " o if the 'VISUAL' environment variable is set, then this will be\n"
+ " the default editor to be called.\n"
+ " o if 'VISUAL' is not set, then the 'EDITOR' environment variable\n"
+ " will be used as the default editor.\n"
+ " o if none of the above environment variables is set, then\n"
+ " '/usr/bin/vi' will be used.\n"
+ "\nOnce the item note is edited and saved, quit your favorite editor.\n"
+ "You will then go back to Calcurse, and the '>' sign will appear in front"
+ "\nof the highlighted item, meaning there is a note attached to it."),
+ keys_action_firstkey(KEY_EDIT_NOTE));
+
+ hscr[HELP_VNOTE].title = _("ViewNote\n");
+ snprintf(hscr[HELP_VNOTE].text, HELPTEXTSIZ,
+ _("View a note which was previously attached to an item (an item which\n"
+ "owns a note has a '>' sign in front of it).\n"
+ "This command only permits to view the note, not to edit it (to do so,\n"
+ "use the 'EditNote' command, by pressing the '%s' key).\n"
+ "Once you highlighted an item with a note attached to it, and the '%s' key"
+ "\nwas pressed, you will be driven to an external pager to view that "
+ "note.\n"
+ "The default pager is chosen the following way:\n"
+ " o if the 'PAGER' environment variable is set, then this will be\n"
+ " the default viewer to be called.\n"
+ " o if the above environment variable is not set, then\n"
+ " '/usr/bin/less' will be used.\n"
+ "As for editing a note, quit the pager and you will be driven back to\n"
+ "Calcurse."), keys_action_firstkey(KEY_EDIT_NOTE),
+ keys_action_firstkey(KEY_VIEW_NOTE));
+
+ hscr[HELP_PRIORITY].title = _("Priority\n");
+ snprintf(hscr[HELP_PRIORITY].text, HELPTEXTSIZ,
+ _("Change the priority of the currently selected item in the ToDo list.\n"
+ "Priorities are represented by the number appearing in front of the\n"
+ "todo description. This number goes from 9 for the lowest priority to\n"
+ "1 for the highest priority.\n"
+ "Todo having higher priorities are placed first (at the top) inside the\n"
+ "todo panel.\n\n"
+ "If you want to raise the priority of a todo item, you need to press "
+ "'%s'.\n"
+ "In doing so, the number in front of this item will decrease, "
+ "meaning its\npriority increases. The item position inside the todo "
+ "panel may change,\ndepending on the priority of the items above it.\n\n"
+ "At the opposite, to lower a todo priority, press '%s'. The todo position"
+ "\nmay also change depending on the priority of the items below."),
+ keys_action_firstkey(KEY_RAISE_PRIORITY),
+ keys_action_firstkey(KEY_LOWER_PRIORITY));
+
+ hscr[HELP_REPEAT].title = _("Repeat\n");
+ snprintf(hscr[HELP_REPEAT].text, HELPTEXTSIZ,
+ _("Repeat an event or an appointment.\n"
+ "You must first select the item to be repeated by moving inside the\n"
+ "appointment panel. Then pressing '%s' will lead you to a set of three\n"
+ "questions, with which you will be able to specify the repetition\n"
+ "characteristics:\n\n"
+ " o type: you can choose between a daily, weekly, monthly or\n"
+ " yearly repetition by pressing 'D', 'W', 'M' or 'Y'\n"
+ " respectively.\n\n"
+ " o frequence: this indicates how often the item shall be repeated.\n"
+ " For example, if you want to remember an anniversary,\n"
+ " choose a 'yearly' repetition with a frequence of '1',\n"
+ " which means it must be repeated every year. Another\n"
+ " example: if you go to the restaurant every two days,\n"
+ " choose a 'daily' repetition with a frequence of '2'.\n\n"
+ " o ending date: this specifies when to stop repeating the selected\n"
+ " event or appointment. To indicate an endless \n"
+ " repetition, enter '0' and the item will be repeated\n"
+ " forever.\n" "\nNotes:\n"
+ " o repeated items are marked with an '*' inside the appointment\n"
+ " panel, to be easily recognizable from non-repeated ones.\n"
+ " o the 'Repeat' and 'Delete' command can be mixed to create\n"
+ " complicated configurations, as it is possible to delete only\n"
+ " one occurence of a repeated item."),
+ keys_action_firstkey(KEY_REPEAT_ITEM));
+
+ hscr[HELP_FLAG].title = _("Flag Item\n");
+ snprintf(hscr[HELP_FLAG].text, HELPTEXTSIZ,
+ _("Toggle an appointment's 'important' flag or a todo's 'completed' flag.\n"
+ "If a todo is flagged as completed, its priority number will be replaced\n"
+ "by an 'X' sign. Completed tasks will no longer appear in exported data\n"
+ "or when using the '-t' command line flag (unless specifying '0' as the\n"
+ "priority number, in which case only completed tasks will be shown).\n\n"
+ "If an appointment is flagged as important, an exclamation mark appears\n"
+ "in front of it, and you will be warned if time gets closed to the\n"
+ "appointment start time.\n"
+ "To customize the way one gets notified, the configuration submenu lets\n"
+ "you choose the command launched to warn user of an upcoming appointment,"
+ "\nand how long before it he gets notified."));
+
+ hscr[HELP_CONFIG].title = _("Config\n");
+ snprintf(hscr[HELP_CONFIG].text, HELPTEXTSIZ,
+ _("Open the configuration submenu.\n"
+ "From this submenu, you can select between color, layout, notification\n"
+ "and general options, and you can also configure your keybindings.\n"
+ "\nThe color submenu lets you choose the color theme.\n"
+ "The layout submenu lets you choose the Calcurse screen layout, in other"
+ "\nwords where to place the three different panels on the screen.\n"
+ "The general options submenu brings a screen with the different options"
+ "\nwhich modifies the way Calcurse interacts with the user.\n"
+ "The notify submenu allows you to change the notify-bar settings.\n"
+ "The keys submenu lets you define your own key bindings.\n"
+ "\nDo not forget to save the calendar data to retrieve your configuration"
+ "\nnext time you launch Calcurse."));
+
+ hscr[HELP_GENERAL].title = _("Generic keybindings\n");
+ snprintf(hscr[HELP_GENERAL].text, HELPTEXTSIZ,
+ _("Some of the keybindings apply whatever panel is selected. They are\n"
+ "called generic keybinding.\n"
+ "Here is the list of all the generic key bindings, together with their\n"
+ "corresponding action:\n\n"
+ " '%s' : Redraw function -> redraws calcurse panels, this is useful if\n"
+ " you resize your terminal screen or when\n"
+ " garbage appears inside the display\n"
+ " '%s' : Add Appointment -> add an appointment or an event\n"
+ " '%s' : Add ToDo -> add a todo\n"
+ " '%s' : -1 Day -> move to previous day\n"
+ " '%s' : +1 Day -> move to next day\n"
+ " '%s' : -1 Week -> move to previous week\n"
+ " '%s' : +1 Week -> move to next week\n"
+ " '%s' : -1 Month -> move to previous month\n"
+ " '%s' : +1 Month -> move to next month\n"
+ " '%s' : -1 Year -> move to previous year\n"
+ " '%s' : +1 Year -> move to next year\n"
+ " '%s' : Goto today -> move to current day\n"
+ "\nThe '%s' and '%s' keys are used to scroll text upward or downward\n"
+ "when inside specific screens such the help screens for example.\n"
+ "They are also used when the calendar screen is selected to switch\n"
+ "between the available views (monthly and weekly calendar views)."),
+ keys_action_firstkey(KEY_GENERIC_REDRAW),
+ keys_action_firstkey(KEY_GENERIC_ADD_APPT),
+ keys_action_firstkey(KEY_GENERIC_ADD_TODO),
+ keys_action_firstkey(KEY_GENERIC_PREV_DAY),
+ keys_action_firstkey(KEY_GENERIC_NEXT_DAY),
+ keys_action_firstkey(KEY_GENERIC_PREV_WEEK),
+ keys_action_firstkey(KEY_GENERIC_NEXT_WEEK),
+ keys_action_firstkey(KEY_GENERIC_PREV_MONTH),
+ keys_action_firstkey(KEY_GENERIC_NEXT_MONTH),
+ keys_action_firstkey(KEY_GENERIC_PREV_YEAR),
+ keys_action_firstkey(KEY_GENERIC_NEXT_YEAR),
+ keys_action_firstkey(KEY_GENERIC_GOTO_TODAY),
+ keys_action_firstkey(KEY_GENERIC_SCROLL_UP),
+ keys_action_firstkey(KEY_GENERIC_SCROLL_DOWN));
+
+ hscr[HELP_OTHER].title = _("OtherCmd\n");
+ snprintf(hscr[HELP_OTHER].text, HELPTEXTSIZ,
+ _("Switch between status bar help pages.\n"
+ "Because the terminal screen is too narrow to display all of the\n"
+ "available commands, you need to press '%s' to see the next set of\n"
+ "commands together with their keybindings.\n"
+ "Once the last status bar page is reached, pressing '%s' another time\n"
+ "leads you back to the first page."),
+ keys_action_firstkey(KEY_GENERIC_OTHER_CMD),
+ keys_action_firstkey(KEY_GENERIC_OTHER_CMD));
+
+ hscr[HELP_CREDITS].title = _("Calcurse - text-based organizer");
+ snprintf(hscr[HELP_CREDITS].text, HELPTEXTSIZ,
+ _("\nCopyright (c) 2004-2013 calcurse Development Team\n"
+ "All rights reserved.\n"
+ "\n"
+ "Redistribution and use in source and binary forms, with or without\n"
+ "modification, are permitted provided that the following conditions\n"
+ "are met:\n"
+ "\n"
+ "\t- Redistributions of source code must retain the above\n"
+ "\t copyright notice, this list of conditions and the\n"
+ "\t following disclaimer.\n"
+ "\n"
+ "\t- Redistributions in binary form must reproduce the above\n"
+ "\t copyright notice, this list of conditions and the\n"
+ "\t following disclaimer in the documentation and/or other\n"
+ "\t materials provided with the distribution.\n"
+ "\n\n"
+ "Send your feedback or comments to : misc@calcurse.org\n"
+ "Calcurse home page : http://calcurse.org"));
+
+ help_wins_init(&hwin, 0, 0, (notify_bar())? row - 3 : row - 2,
+ col);
+ oldpage = HELP_MAIN;
+ need_resize = 0;
+
+ /* Display the help screen related to user input. */
+ while (ch != KEY_GENERIC_QUIT) {
+ erase_window_part(hwin.win.p, 1, hwin.pad.y, col - 2,
+ hwin.win.h - 2);
+
+ switch (ch) {
+ case KEY_GENERIC_SCROLL_DOWN:
+ wins_scrollwin_down(&hwin, 1);
+ break;
+
+ case KEY_GENERIC_SCROLL_UP:
+ wins_scrollwin_up(&hwin, 1);
+ break;
+
+ default:
+ page = wanted_page(ch);
+ if (page != NOPAGE) {
+ hwin.first_visible_line = 0;
+ hwin.total_lines =
+ help_write_pad(&hwin.pad,
+ hscr[page].title,
+ hscr[page].text, ch);
+ oldpage = page;
+ }
+ }
+
+ if (resize) {
+ resize = 0;
+ wins_get_config();
+ help_wins_reset(&hwin);
+ hwin.first_visible_line = 0;
+ hwin.total_lines =
+ help_write_pad(&hwin.pad, hscr[oldpage].title,
+ hscr[oldpage].text, ch);
+ need_resize = 1;
+ }
+
+ wins_scrollwin_display(&hwin);
+ ch = keys_getch(win[KEY].p, NULL, NULL);
+ }
+ wins_scrollwin_delete(&hwin);
+ if (need_resize)
+ wins_reset();
}
diff --git a/src/htable.h b/src/htable.h
index a9317e0..445f6fb 100644
--- a/src/htable.h
+++ b/src/htable.h
@@ -69,7 +69,7 @@ struct name { \
}
#define HTABLE_ENTRY(type) \
-struct type *next /* To build the bucket chain list. */
+struct type *next /* To build the bucket chain list. */
#define HTABLE_SIZE(head) \
(sizeof (*(head)->bkts) ? sizeof ((head)->bkts) / sizeof (*(head)->bkts) : 0)
diff --git a/src/ical.c b/src/ical.c
index bd53a0c..0aa5da7 100644
--- a/src/ical.c
+++ b/src/ical.c
@@ -43,22 +43,22 @@
#define ICALDATETIMEFMT "%Y%m%dT%H%M%S"
typedef enum {
- ICAL_VEVENT,
- ICAL_VTODO,
- ICAL_TYPES
+ ICAL_VEVENT,
+ ICAL_VTODO,
+ ICAL_TYPES
} ical_types_e;
typedef enum {
- UNDEFINED,
- APPOINTMENT,
- EVENT
+ UNDEFINED,
+ APPOINTMENT,
+ EVENT
} ical_vevent_e;
typedef struct {
- enum recur_type type;
- int freq;
- long until;
- unsigned count;
+ enum recur_type type;
+ int freq;
+ long until;
+ unsigned count;
} ical_rpt_t;
static void ical_export_header(FILE *);
@@ -75,191 +75,198 @@ static const char *ical_recur_type[RECUR_TYPES] =
/* iCal alarm notification. */
static void ical_export_valarm(FILE * stream)
{
- fputs("BEGIN:VALARM\n", stream);
- pthread_mutex_lock(&nbar.mutex);
- fprintf(stream, "TRIGGER:-P%dS\n", nbar.cntdwn);
- pthread_mutex_unlock(&nbar.mutex);
- fputs("ACTION:DISPLAY\n", stream);
- fputs("END:VALARM\n", stream);
+ fputs("BEGIN:VALARM\n", stream);
+ pthread_mutex_lock(&nbar.mutex);
+ fprintf(stream, "TRIGGER:-P%dS\n", nbar.cntdwn);
+ pthread_mutex_unlock(&nbar.mutex);
+ fputs("ACTION:DISPLAY\n", stream);
+ fputs("END:VALARM\n", stream);
}
/* Export header. */
static void ical_export_header(FILE * stream)
{
- fputs("BEGIN:VCALENDAR\n", stream);
- fprintf(stream, "PRODID:-//calcurse//NONSGML v%s//EN\n", VERSION);
- fputs("VERSION:2.0\n", stream);
+ fputs("BEGIN:VCALENDAR\n", stream);
+ fprintf(stream, "PRODID:-//calcurse//NONSGML v%s//EN\n", VERSION);
+ fputs("VERSION:2.0\n", stream);
}
/* Export footer. */
static void ical_export_footer(FILE * stream)
{
- fputs("END:VCALENDAR\n", stream);
+ fputs("END:VCALENDAR\n", stream);
}
/* Export recurrent events. */
static void ical_export_recur_events(FILE * stream)
{
- llist_item_t *i, *j;
- char ical_date[BUFSIZ];
-
- LLIST_FOREACH(&recur_elist, i) {
- struct recur_event *rev = LLIST_GET_DATA(i);
- date_sec2date_fmt(rev->day, ICALDATEFMT, ical_date);
- fputs("BEGIN:VEVENT\n", stream);
- fprintf(stream, "DTSTART:%s\n", ical_date);
- fprintf(stream, "RRULE:FREQ=%s;INTERVAL=%d",
- ical_recur_type[rev->rpt->type], rev->rpt->freq);
-
- if (rev->rpt->until != 0) {
- date_sec2date_fmt(rev->rpt->until, ICALDATEFMT, ical_date);
- fprintf(stream, ";UNTIL=%s\n", ical_date);
- } else {
- fputc('\n', stream);
- }
-
- if (LLIST_FIRST(&rev->exc)) {
- fputs("EXDATE:", stream);
- LLIST_FOREACH(&rev->exc, j) {
- struct excp *exc = LLIST_GET_DATA(j);
- date_sec2date_fmt(exc->st, ICALDATEFMT, ical_date);
- fprintf(stream, "%s", ical_date);
- if (LLIST_NEXT(j))
- fputc(',', stream);
- else
- fputc('\n', stream);
- }
- }
-
- fprintf(stream, "SUMMARY:%s\n", rev->mesg);
- fputs("END:VEVENT\n", stream);
- }
+ llist_item_t *i, *j;
+ char ical_date[BUFSIZ];
+
+ LLIST_FOREACH(&recur_elist, i) {
+ struct recur_event *rev = LLIST_GET_DATA(i);
+ date_sec2date_fmt(rev->day, ICALDATEFMT, ical_date);
+ fputs("BEGIN:VEVENT\n", stream);
+ fprintf(stream, "DTSTART:%s\n", ical_date);
+ fprintf(stream, "RRULE:FREQ=%s;INTERVAL=%d",
+ ical_recur_type[rev->rpt->type], rev->rpt->freq);
+
+ if (rev->rpt->until != 0) {
+ date_sec2date_fmt(rev->rpt->until, ICALDATEFMT,
+ ical_date);
+ fprintf(stream, ";UNTIL=%s\n", ical_date);
+ } else {
+ fputc('\n', stream);
+ }
+
+ if (LLIST_FIRST(&rev->exc)) {
+ fputs("EXDATE:", stream);
+ LLIST_FOREACH(&rev->exc, j) {
+ struct excp *exc = LLIST_GET_DATA(j);
+ date_sec2date_fmt(exc->st, ICALDATEFMT,
+ ical_date);
+ fprintf(stream, "%s", ical_date);
+ if (LLIST_NEXT(j))
+ fputc(',', stream);
+ else
+ fputc('\n', stream);
+ }
+ }
+
+ fprintf(stream, "SUMMARY:%s\n", rev->mesg);
+ fputs("END:VEVENT\n", stream);
+ }
}
/* Export events. */
static void ical_export_events(FILE * stream)
{
- llist_item_t *i;
- char ical_date[BUFSIZ];
-
- LLIST_FOREACH(&eventlist, i) {
- struct event *ev = LLIST_TS_GET_DATA(i);
- date_sec2date_fmt(ev->day, ICALDATEFMT, ical_date);
- fputs("BEGIN:VEVENT\n", stream);
- fprintf(stream, "DTSTART:%s\n", ical_date);
- fprintf(stream, "SUMMARY:%s\n", ev->mesg);
- fputs("END:VEVENT\n", stream);
- }
+ llist_item_t *i;
+ char ical_date[BUFSIZ];
+
+ LLIST_FOREACH(&eventlist, i) {
+ struct event *ev = LLIST_TS_GET_DATA(i);
+ date_sec2date_fmt(ev->day, ICALDATEFMT, ical_date);
+ fputs("BEGIN:VEVENT\n", stream);
+ fprintf(stream, "DTSTART:%s\n", ical_date);
+ fprintf(stream, "SUMMARY:%s\n", ev->mesg);
+ fputs("END:VEVENT\n", stream);
+ }
}
/* Export recurrent appointments. */
static void ical_export_recur_apoints(FILE * stream)
{
- llist_item_t *i, *j;
- char ical_datetime[BUFSIZ];
- char ical_date[BUFSIZ];
-
- LLIST_TS_LOCK(&recur_alist_p);
- LLIST_TS_FOREACH(&recur_alist_p, i) {
- struct recur_apoint *rapt = LLIST_TS_GET_DATA(i);
-
- date_sec2date_fmt(rapt->start, ICALDATETIMEFMT, ical_datetime);
- fputs("BEGIN:VEVENT\n", stream);
- fprintf(stream, "DTSTART:%s\n", ical_datetime);
- fprintf(stream, "DURATION:PT0H0M%ldS\n", rapt->dur);
- fprintf(stream, "RRULE:FREQ=%s;INTERVAL=%d",
- ical_recur_type[rapt->rpt->type], rapt->rpt->freq);
-
- if (rapt->rpt->until != 0) {
- date_sec2date_fmt(rapt->rpt->until + HOURINSEC, ICALDATEFMT, ical_date);
- fprintf(stream, ";UNTIL=%s\n", ical_date);
- } else {
- fputc('\n', stream);
- }
-
- if (LLIST_FIRST(&rapt->exc)) {
- fputs("EXDATE:", stream);
- LLIST_FOREACH(&rapt->exc, j) {
- struct excp *exc = LLIST_GET_DATA(j);
- date_sec2date_fmt(exc->st, ICALDATEFMT, ical_date);
- fprintf(stream, "%s", ical_date);
- if (LLIST_NEXT(j))
- fputc(',', stream);
- else
- fputc('\n', stream);
- }
- }
-
- fprintf(stream, "SUMMARY:%s\n", rapt->mesg);
- if (rapt->state & APOINT_NOTIFY)
- ical_export_valarm(stream);
- fputs("END:VEVENT\n", stream);
- }
- LLIST_TS_UNLOCK(&recur_alist_p);
+ llist_item_t *i, *j;
+ char ical_datetime[BUFSIZ];
+ char ical_date[BUFSIZ];
+
+ LLIST_TS_LOCK(&recur_alist_p);
+ LLIST_TS_FOREACH(&recur_alist_p, i) {
+ struct recur_apoint *rapt = LLIST_TS_GET_DATA(i);
+
+ date_sec2date_fmt(rapt->start, ICALDATETIMEFMT,
+ ical_datetime);
+ fputs("BEGIN:VEVENT\n", stream);
+ fprintf(stream, "DTSTART:%s\n", ical_datetime);
+ fprintf(stream, "DURATION:PT0H0M%ldS\n", rapt->dur);
+ fprintf(stream, "RRULE:FREQ=%s;INTERVAL=%d",
+ ical_recur_type[rapt->rpt->type], rapt->rpt->freq);
+
+ if (rapt->rpt->until != 0) {
+ date_sec2date_fmt(rapt->rpt->until + HOURINSEC,
+ ICALDATEFMT, ical_date);
+ fprintf(stream, ";UNTIL=%s\n", ical_date);
+ } else {
+ fputc('\n', stream);
+ }
+
+ if (LLIST_FIRST(&rapt->exc)) {
+ fputs("EXDATE:", stream);
+ LLIST_FOREACH(&rapt->exc, j) {
+ struct excp *exc = LLIST_GET_DATA(j);
+ date_sec2date_fmt(exc->st, ICALDATEFMT,
+ ical_date);
+ fprintf(stream, "%s", ical_date);
+ if (LLIST_NEXT(j))
+ fputc(',', stream);
+ else
+ fputc('\n', stream);
+ }
+ }
+
+ fprintf(stream, "SUMMARY:%s\n", rapt->mesg);
+ if (rapt->state & APOINT_NOTIFY)
+ ical_export_valarm(stream);
+ fputs("END:VEVENT\n", stream);
+ }
+ LLIST_TS_UNLOCK(&recur_alist_p);
}
/* Export appointments. */
static void ical_export_apoints(FILE * stream)
{
- llist_item_t *i;
- char ical_datetime[BUFSIZ];
-
- LLIST_TS_LOCK(&alist_p);
- LLIST_TS_FOREACH(&alist_p, i) {
- struct apoint *apt = LLIST_TS_GET_DATA(i);
- date_sec2date_fmt(apt->start, ICALDATETIMEFMT, ical_datetime);
- fputs("BEGIN:VEVENT\n", stream);
- fprintf(stream, "DTSTART:%s\n", ical_datetime);
- fprintf(stream, "DURATION:P%ldDT%ldH%ldM%ldS\n",
- apt->dur / DAYINSEC,
- (apt->dur / HOURINSEC) % DAYINHOURS,
- (apt->dur / MININSEC) % HOURINMIN, apt->dur % MININSEC);
- fprintf(stream, "SUMMARY:%s\n", apt->mesg);
- if (apt->state & APOINT_NOTIFY)
- ical_export_valarm(stream);
- fputs("END:VEVENT\n", stream);
- }
- LLIST_TS_UNLOCK(&alist_p);
+ llist_item_t *i;
+ char ical_datetime[BUFSIZ];
+
+ LLIST_TS_LOCK(&alist_p);
+ LLIST_TS_FOREACH(&alist_p, i) {
+ struct apoint *apt = LLIST_TS_GET_DATA(i);
+ date_sec2date_fmt(apt->start, ICALDATETIMEFMT,
+ ical_datetime);
+ fputs("BEGIN:VEVENT\n", stream);
+ fprintf(stream, "DTSTART:%s\n", ical_datetime);
+ fprintf(stream, "DURATION:P%ldDT%ldH%ldM%ldS\n",
+ apt->dur / DAYINSEC,
+ (apt->dur / HOURINSEC) % DAYINHOURS,
+ (apt->dur / MININSEC) % HOURINMIN,
+ apt->dur % MININSEC);
+ fprintf(stream, "SUMMARY:%s\n", apt->mesg);
+ if (apt->state & APOINT_NOTIFY)
+ ical_export_valarm(stream);
+ fputs("END:VEVENT\n", stream);
+ }
+ LLIST_TS_UNLOCK(&alist_p);
}
/* Export todo items. */
static void ical_export_todo(FILE * stream)
{
- llist_item_t *i;
-
- LLIST_FOREACH(&todolist, i) {
- struct todo *todo = LLIST_TS_GET_DATA(i);
- if (todo->id < 0) /* completed items */
- continue;
-
- fputs("BEGIN:VTODO\n", stream);
- fprintf(stream, "PRIORITY:%d\n", todo->id);
- fprintf(stream, "SUMMARY:%s\n", todo->mesg);
- fputs("END:VTODO\n", stream);
- }
+ llist_item_t *i;
+
+ LLIST_FOREACH(&todolist, i) {
+ struct todo *todo = LLIST_TS_GET_DATA(i);
+ if (todo->id < 0) /* completed items */
+ continue;
+
+ fputs("BEGIN:VTODO\n", stream);
+ fprintf(stream, "PRIORITY:%d\n", todo->id);
+ fprintf(stream, "SUMMARY:%s\n", todo->mesg);
+ fputs("END:VTODO\n", stream);
+ }
}
/* Print a header to describe import log report format. */
static void ical_log_init(FILE * log, int major, int minor)
{
- const char *header =
- "+-------------------------------------------------------------------+\n"
- "| Calcurse icalendar import log. |\n"
- "| |\n"
- "| Items imported from icalendar file, version %d.%d |\n"
- "| Some items could not be imported, they are described hereafter. |\n"
- "| The log line format is as follows: |\n"
- "| |\n"
- "| TYPE [LINE]: DESCRIPTION |\n"
- "| |\n"
- "| where: |\n"
- "| * TYPE represents the item type ('VEVENT' or 'VTODO') |\n"
- "| * LINE is the line in the input stream at which this item begins |\n"
- "| * DESCRIPTION indicates why the item could not be imported |\n"
- "+-------------------------------------------------------------------+\n\n";
-
- if (log)
- fprintf(log, header, major, minor);
+ const char *header =
+ "+-------------------------------------------------------------------+\n"
+ "| Calcurse icalendar import log. |\n"
+ "| |\n"
+ "| Items imported from icalendar file, version %d.%d |\n"
+ "| Some items could not be imported, they are described hereafter. |\n"
+ "| The log line format is as follows: |\n"
+ "| |\n"
+ "| TYPE [LINE]: DESCRIPTION |\n"
+ "| |\n"
+ "| where: |\n"
+ "| * TYPE represents the item type ('VEVENT' or 'VTODO') |\n"
+ "| * LINE is the line in the input stream at which this item begins |\n"
+ "| * DESCRIPTION indicates why the item could not be imported |\n"
+ "+-------------------------------------------------------------------+\n\n";
+
+ if (log)
+ fprintf(log, header, major, minor);
}
/*
@@ -268,66 +275,67 @@ static void ical_log_init(FILE * log, int major, int minor)
* first line inside the icalendar file), together with a message describing the
* problem.
*/
-static void ical_log(FILE * log, ical_types_e type, unsigned lineno, char *msg)
+static void ical_log(FILE * log, ical_types_e type, unsigned lineno,
+ char *msg)
{
- const char *typestr[ICAL_TYPES] = { "VEVENT", "VTODO" };
+ const char *typestr[ICAL_TYPES] = { "VEVENT", "VTODO" };
- RETURN_IF(type < 0 || type >= ICAL_TYPES, _("unknown ical type"));
- if (log)
- fprintf(log, "%s [%d]: %s\n", typestr[type], lineno, msg);
+ RETURN_IF(type < 0 || type >= ICAL_TYPES, _("unknown ical type"));
+ if (log)
+ fprintf(log, "%s [%d]: %s\n", typestr[type], lineno, msg);
}
static void ical_store_todo(int priority, char *mesg, char *note)
{
- todo_add(mesg, priority, note);
- mem_free(mesg);
- erase_note(&note);
+ todo_add(mesg, priority, note);
+ mem_free(mesg);
+ erase_note(&note);
}
static void
-ical_store_event(char *mesg, char *note, long day, long end, ical_rpt_t * rpt,
- llist_t * exc)
+ical_store_event(char *mesg, char *note, long day, long end,
+ ical_rpt_t * rpt, llist_t * exc)
{
- const int EVENTID = 1;
-
- if (rpt) {
- recur_event_new(mesg, note, day, EVENTID, rpt->type, rpt->freq,
- rpt->until, exc);
- mem_free(rpt);
- } else if (end && end != day) {
- /* Here we have an event that spans over several days. */
- rpt = mem_malloc(sizeof(ical_rpt_t));
- rpt->type = RECUR_DAILY;
- rpt->freq = 1;
- rpt->count = 0;
- rpt->until = end;
- recur_event_new(mesg, note, day, EVENTID, rpt->type, rpt->freq,
- rpt->until, exc);
- mem_free(rpt);
- } else {
- event_new(mesg, note, day, EVENTID);
- }
- mem_free(mesg);
- erase_note(&note);
+ const int EVENTID = 1;
+
+ if (rpt) {
+ recur_event_new(mesg, note, day, EVENTID, rpt->type,
+ rpt->freq, rpt->until, exc);
+ mem_free(rpt);
+ } else if (end && end != day) {
+ /* Here we have an event that spans over several days. */
+ rpt = mem_malloc(sizeof(ical_rpt_t));
+ rpt->type = RECUR_DAILY;
+ rpt->freq = 1;
+ rpt->count = 0;
+ rpt->until = end;
+ recur_event_new(mesg, note, day, EVENTID, rpt->type,
+ rpt->freq, rpt->until, exc);
+ mem_free(rpt);
+ } else {
+ event_new(mesg, note, day, EVENTID);
+ }
+ mem_free(mesg);
+ erase_note(&note);
}
static void
ical_store_apoint(char *mesg, char *note, long start, long dur,
- ical_rpt_t * rpt, llist_t * exc, int has_alarm)
+ ical_rpt_t * rpt, llist_t * exc, int has_alarm)
{
- char state = 0L;
-
- if (has_alarm)
- state |= APOINT_NOTIFY;
- if (rpt) {
- recur_apoint_new(mesg, note, start, dur, state, rpt->type, rpt->freq,
- rpt->until, exc);
- mem_free(rpt);
- } else {
- apoint_new(mesg, note, start, dur, state);
- }
- mem_free(mesg);
- erase_note(&note);
+ char state = 0L;
+
+ if (has_alarm)
+ state |= APOINT_NOTIFY;
+ if (rpt) {
+ recur_apoint_new(mesg, note, start, dur, state, rpt->type,
+ rpt->freq, rpt->until, exc);
+ mem_free(rpt);
+ } else {
+ apoint_new(mesg, note, start, dur, state);
+ }
+ mem_free(mesg);
+ erase_note(&note);
}
/*
@@ -345,101 +353,101 @@ ical_store_apoint(char *mesg, char *note, long start, long dur,
*/
static char *ical_unformat_line(char *line)
{
- char *p, uline[BUFSIZ];
- int len;
-
- if (strlen(line) >= BUFSIZ)
- return NULL;
-
- memset(uline, 0, BUFSIZ);
- for (len = 0, p = line; *p; p++) {
- switch (*p) {
- case '\\':
- switch (*(p + 1)) {
- case 'n':
- uline[len++] = '\n';
- p++;
- break;
- case 't':
- uline[len++] = '\t';
- p++;
- break;
- case ';':
- case ':':
- case ',':
- uline[len++] = *(p + 1);
- p++;
- break;
- default:
- uline[len++] = *p;
- break;
- }
- break;
- default:
- uline[len++] = *p;
- break;
- }
- }
-
- return mem_strdup(uline);
+ char *p, uline[BUFSIZ];
+ int len;
+
+ if (strlen(line) >= BUFSIZ)
+ return NULL;
+
+ memset(uline, 0, BUFSIZ);
+ for (len = 0, p = line; *p; p++) {
+ switch (*p) {
+ case '\\':
+ switch (*(p + 1)) {
+ case 'n':
+ uline[len++] = '\n';
+ p++;
+ break;
+ case 't':
+ uline[len++] = '\t';
+ p++;
+ break;
+ case ';':
+ case ':':
+ case ',':
+ uline[len++] = *(p + 1);
+ p++;
+ break;
+ default:
+ uline[len++] = *p;
+ break;
+ }
+ break;
+ default:
+ uline[len++] = *p;
+ break;
+ }
+ }
+
+ return mem_strdup(uline);
}
static void
ical_readline_init(FILE * fdi, char *buf, char *lstore, unsigned *ln)
{
- char *eol;
-
- *buf = *lstore = '\0';
- if (fgets(lstore, BUFSIZ, fdi)) {
- if ((eol = strchr(lstore, '\n')) != NULL)
- *eol = '\0';
- (*ln)++;
- }
+ char *eol;
+
+ *buf = *lstore = '\0';
+ if (fgets(lstore, BUFSIZ, fdi)) {
+ if ((eol = strchr(lstore, '\n')) != NULL)
+ *eol = '\0';
+ (*ln)++;
+ }
}
static int ical_readline(FILE * fdi, char *buf, char *lstore, unsigned *ln)
{
- char *eol;
-
- strncpy(buf, lstore, BUFSIZ);
- (*ln)++;
-
- while (fgets(lstore, BUFSIZ, fdi) != NULL) {
- if ((eol = strchr(lstore, '\n')) != NULL)
- *eol = '\0';
- if (*lstore != SPACE && *lstore != TAB)
- break;
- strncat(buf, lstore + 1, BUFSIZ - strlen(buf) - 1);
- (*ln)++;
- }
-
- if (feof(fdi)) {
- *lstore = '\0';
- if (*buf == '\0')
- return 0;
- }
-
- return 1;
+ char *eol;
+
+ strncpy(buf, lstore, BUFSIZ);
+ (*ln)++;
+
+ while (fgets(lstore, BUFSIZ, fdi) != NULL) {
+ if ((eol = strchr(lstore, '\n')) != NULL)
+ *eol = '\0';
+ if (*lstore != SPACE && *lstore != TAB)
+ break;
+ strncat(buf, lstore + 1, BUFSIZ - strlen(buf) - 1);
+ (*ln)++;
+ }
+
+ if (feof(fdi)) {
+ *lstore = '\0';
+ if (*buf == '\0')
+ return 0;
+ }
+
+ return 1;
}
static int
ical_chk_header(FILE * fd, char *buf, char *lstore, unsigned *lineno,
- int *major, int *minor)
+ int *major, int *minor)
{
- const char icalheader[] = "BEGIN:VCALENDAR";
+ const char icalheader[] = "BEGIN:VCALENDAR";
- if (!ical_readline(fd, buf, lstore, lineno))
- return 0;
+ if (!ical_readline(fd, buf, lstore, lineno))
+ return 0;
- if (strncasecmp(buf, icalheader, sizeof(icalheader) - 1) != 0)
- return 0;
+ if (strncasecmp(buf, icalheader, sizeof(icalheader) - 1) != 0)
+ return 0;
- while (!sscanf(buf, "VERSION:%d.%d", major, minor)) {
- if (!ical_readline(fd, buf, lstore, lineno))
- return 0;
- }
+ while (!sscanf(buf, "VERSION:%d.%d", major, minor)) {
+ if (!ical_readline(fd, buf, lstore, lineno))
+ return 0;
+ }
- return 1;
+ return 1;
}
/*
@@ -456,50 +464,54 @@ ical_chk_header(FILE * fd, char *buf, char *lstore, unsigned *lineno,
*/
static long ical_datetime2long(char *datestr, ical_vevent_e * type)
{
- const int NOTFOUND = 0, FORMAT_DATE = 3, FORMAT_DATETIME = 5;
- struct date date;
- unsigned hour, min;
- long datelong;
- int format;
-
- format = sscanf(datestr, "%04u%02u%02uT%02u%02u",
- &date.yyyy, &date.mm, &date.dd, &hour, &min);
- if (format == FORMAT_DATE) {
- if (type)
- *type = EVENT;
- datelong = date2sec(date, 0, 0);
- } else if (format == FORMAT_DATETIME) {
- if (type)
- *type = APPOINTMENT;
- datelong = date2sec(date, hour, min);
- } else {
- datelong = NOTFOUND;
- }
- return datelong;
+ const int NOTFOUND = 0, FORMAT_DATE = 3, FORMAT_DATETIME = 5;
+ struct date date;
+ unsigned hour, min;
+ long datelong;
+ int format;
+
+ format = sscanf(datestr, "%04u%02u%02uT%02u%02u",
+ &date.yyyy, &date.mm, &date.dd, &hour, &min);
+ if (format == FORMAT_DATE) {
+ if (type)
+ *type = EVENT;
+ datelong = date2sec(date, 0, 0);
+ } else if (format == FORMAT_DATETIME) {
+ if (type)
+ *type = APPOINTMENT;
+ datelong = date2sec(date, hour, min);
+ } else {
+ datelong = NOTFOUND;
+ }
+ return datelong;
}
static long ical_durtime2long(char *timestr)
{
- long timelong;
- char *p;
-
- if ((p = strchr(timestr, 'T')) == NULL) {
- timelong = 0;
- } else {
- int nbmatch;
- struct {
- unsigned hour, min, sec;
- } time;
-
- p++;
- memset(&time, 0, sizeof time);
- nbmatch = sscanf(p, "%uH%uM%uS", &time.hour, &time.min, &time.sec);
- if (nbmatch < 1 || nbmatch > 3)
- timelong = 0;
- else
- timelong = time.hour * HOURINSEC + time.min * MININSEC + time.sec;
- }
- return timelong;
+ long timelong;
+ char *p;
+
+ if ((p = strchr(timestr, 'T')) == NULL) {
+ timelong = 0;
+ } else {
+ int nbmatch;
+ struct {
+ unsigned hour, min, sec;
+ } time;
+
+ p++;
+ memset(&time, 0, sizeof time);
+ nbmatch =
+ sscanf(p, "%uH%uM%uS", &time.hour, &time.min,
+ &time.sec);
+ if (nbmatch < 1 || nbmatch > 3)
+ timelong = 0;
+ else
+ timelong =
+ time.hour * HOURINSEC + time.min * MININSEC +
+ time.sec;
+ }
+ return timelong;
}
/*
@@ -529,44 +541,45 @@ static long ical_durtime2long(char *timestr)
*/
static long ical_dur2long(char *durstr)
{
- const int NOTFOUND = -1;
- long durlong;
- char *p;
- struct {
- unsigned week, day;
- } date;
-
- memset(&date, 0, sizeof date);
- if ((p = strchr(durstr, 'P')) == NULL) {
- durlong = NOTFOUND;
- } else {
- p++;
- if (*p == '-')
- return NOTFOUND;
- else if (*p == '+')
- p++;
-
- if (*p == 'T') { /* dur-time */
- durlong = ical_durtime2long(p);
- } else if (strchr(p, 'W')) { /* dur-week */
- if (sscanf(p, "%u", &date.week) == 1)
- durlong = date.week * WEEKINDAYS * DAYINSEC;
- else
- durlong = NOTFOUND;
- } else {
- if (strchr(p, 'D')) { /* dur-date */
- if (sscanf(p, "%uD", &date.day) == 1) {
- durlong = date.day * DAYINSEC;
- durlong += ical_durtime2long(p);
- } else {
- durlong = NOTFOUND;
- }
- } else {
- durlong = NOTFOUND;
- }
- }
- }
- return durlong;
+ const int NOTFOUND = -1;
+ long durlong;
+ char *p;
+ struct {
+ unsigned week, day;
+ } date;
+
+ memset(&date, 0, sizeof date);
+ if ((p = strchr(durstr, 'P')) == NULL) {
+ durlong = NOTFOUND;
+ } else {
+ p++;
+ if (*p == '-')
+ return NOTFOUND;
+ else if (*p == '+')
+ p++;
+
+ if (*p == 'T') { /* dur-time */
+ durlong = ical_durtime2long(p);
+ } else if (strchr(p, 'W')) { /* dur-week */
+ if (sscanf(p, "%u", &date.week) == 1)
+ durlong =
+ date.week * WEEKINDAYS * DAYINSEC;
+ else
+ durlong = NOTFOUND;
+ } else {
+ if (strchr(p, 'D')) { /* dur-date */
+ if (sscanf(p, "%uD", &date.day) == 1) {
+ durlong = date.day * DAYINSEC;
+ durlong += ical_durtime2long(p);
+ } else {
+ durlong = NOTFOUND;
+ }
+ } else {
+ durlong = NOTFOUND;
+ }
+ }
+ }
+ return durlong;
}
/*
@@ -579,28 +592,35 @@ static long ical_dur2long(char *durstr)
*/
static long ical_compute_rpt_until(long start, ical_rpt_t * rpt)
{
- long until;
-
- switch (rpt->type) {
- case RECUR_DAILY:
- until = date_sec_change(start, 0, rpt->freq * (rpt->count - 1));
- break;
- case RECUR_WEEKLY:
- until = date_sec_change(start, 0,
- rpt->freq * WEEKINDAYS * (rpt->count - 1));
- break;
- case RECUR_MONTHLY:
- until = date_sec_change(start, rpt->freq * (rpt->count - 1), 0);
- break;
- case RECUR_YEARLY:
- until = date_sec_change(start, rpt->freq * 12 * (rpt->count - 1), 0);
- break;
- default:
- until = 0;
- break;
- /* NOTREACHED */
- }
- return until;
+ long until;
+
+ switch (rpt->type) {
+ case RECUR_DAILY:
+ until =
+ date_sec_change(start, 0,
+ rpt->freq * (rpt->count - 1));
+ break;
+ case RECUR_WEEKLY:
+ until = date_sec_change(start, 0,
+ rpt->freq * WEEKINDAYS *
+ (rpt->count - 1));
+ break;
+ case RECUR_MONTHLY:
+ until =
+ date_sec_change(start, rpt->freq * (rpt->count - 1),
+ 0);
+ break;
+ case RECUR_YEARLY:
+ until =
+ date_sec_change(start,
+ rpt->freq * 12 * (rpt->count - 1), 0);
+ break;
+ default:
+ until = 0;
+ break;
+ /* NOTREACHED */
+ }
+ return until;
}
/*
@@ -641,106 +661,117 @@ static long ical_compute_rpt_until(long start, ical_rpt_t * rpt)
* )
*/
static ical_rpt_t *ical_read_rrule(FILE * log, char *rrulestr,
- unsigned *noskipped, const int itemline)
+ unsigned *noskipped, const int itemline)
{
- const char daily[] = "DAILY";
- const char weekly[] = "WEEKLY";
- const char monthly[] = "MONTHLY";
- const char yearly[] = "YEARLY";
- const char count[] = "COUNT=";
- const char interv[] = "INTERVAL=";
- unsigned interval;
- ical_rpt_t *rpt;
- char *p;
-
- rpt = NULL;
- if ((p = strchr(rrulestr, ':')) != NULL) {
- char freqstr[BUFSIZ];
-
- p++;
- rpt = mem_malloc(sizeof(ical_rpt_t));
- memset(rpt, 0, sizeof(ical_rpt_t));
- if (sscanf(p, "FREQ=%s", freqstr) != 1) {
- ical_log(log, ICAL_VEVENT, itemline,
- _("recurrence frequence not found."));
- (*noskipped)++;
- mem_free(rpt);
- return NULL;
- } else {
- if (strncmp(freqstr, daily, sizeof(daily) - 1) == 0) {
- rpt->type = RECUR_DAILY;
- } else if (strncmp(freqstr, weekly, sizeof(weekly) - 1) == 0) {
- rpt->type = RECUR_WEEKLY;
- } else if (strncmp(freqstr, monthly, sizeof(monthly) - 1) == 0) {
- rpt->type = RECUR_MONTHLY;
- } else if (strncmp(freqstr, yearly, sizeof(yearly) - 1) == 0) {
- rpt->type = RECUR_YEARLY;
- } else {
- ical_log(log, ICAL_VEVENT, itemline,
- _("recurrence frequence not recognized."));
- (*noskipped)++;
- mem_free(rpt);
- return NULL;
- }
- }
- /*
- The UNTIL rule part defines a date-time value which bounds the
- recurrence rule in an inclusive manner. If not present, and the
- COUNT rule part is also not present, the RRULE is considered to
- repeat forever.
-
- The COUNT rule part defines the number of occurrences at which to
- range-bound the recurrence. The "DTSTART" property value, if
- specified, counts as the first occurrence.
- */
- if ((p = strstr(rrulestr, "UNTIL")) != NULL) {
- char *untilstr;
-
- untilstr = strchr(p, '=');
- rpt->until = ical_datetime2long(++untilstr, NULL);
- } else {
- unsigned cnt;
- char *countstr;
-
- if ((countstr = strstr(rrulestr, count)) != NULL) {
- countstr += sizeof(count) - 1;
- if (sscanf(countstr, "%u", &cnt) != 1) {
- rpt->until = 0;
- /* endless repetition */
- } else {
- rpt->count = cnt;
- }
- } else {
- rpt->until = 0;
- }
- }
-
- if ((p = strstr(rrulestr, interv)) != NULL) {
- p += sizeof(interv) - 1;
- if (sscanf(p, "%u", &interval) != 1) {
- rpt->freq = 1;
- /* default frequence if none specified */
- } else {
- rpt->freq = interval;
- }
- } else {
- rpt->freq = 1;
- }
- } else {
- ical_log(log, ICAL_VEVENT, itemline, _("recurrence rule malformed."));
- (*noskipped)++;
- }
- return rpt;
+ const char daily[] = "DAILY";
+ const char weekly[] = "WEEKLY";
+ const char monthly[] = "MONTHLY";
+ const char yearly[] = "YEARLY";
+ const char count[] = "COUNT=";
+ const char interv[] = "INTERVAL=";
+ unsigned interval;
+ ical_rpt_t *rpt;
+ char *p;
+
+ rpt = NULL;
+ if ((p = strchr(rrulestr, ':')) != NULL) {
+ char freqstr[BUFSIZ];
+
+ p++;
+ rpt = mem_malloc(sizeof(ical_rpt_t));
+ memset(rpt, 0, sizeof(ical_rpt_t));
+ if (sscanf(p, "FREQ=%s", freqstr) != 1) {
+ ical_log(log, ICAL_VEVENT, itemline,
+ _("recurrence frequence not found."));
+ (*noskipped)++;
+ mem_free(rpt);
+ return NULL;
+ } else {
+ if (strncmp(freqstr, daily, sizeof(daily) - 1) ==
+ 0) {
+ rpt->type = RECUR_DAILY;
+ } else
+ if (strncmp
+ (freqstr, weekly,
+ sizeof(weekly) - 1) == 0) {
+ rpt->type = RECUR_WEEKLY;
+ } else
+ if (strncmp
+ (freqstr, monthly,
+ sizeof(monthly) - 1) == 0) {
+ rpt->type = RECUR_MONTHLY;
+ } else
+ if (strncmp
+ (freqstr, yearly,
+ sizeof(yearly) - 1) == 0) {
+ rpt->type = RECUR_YEARLY;
+ } else {
+ ical_log(log, ICAL_VEVENT, itemline,
+ _("recurrence frequence not recognized."));
+ (*noskipped)++;
+ mem_free(rpt);
+ return NULL;
+ }
+ }
+ /*
+ The UNTIL rule part defines a date-time value which bounds the
+ recurrence rule in an inclusive manner. If not present, and the
+ COUNT rule part is also not present, the RRULE is considered to
+ repeat forever.
+
+ The COUNT rule part defines the number of occurrences at which to
+ range-bound the recurrence. The "DTSTART" property value, if
+ specified, counts as the first occurrence.
+ */
+ if ((p = strstr(rrulestr, "UNTIL")) != NULL) {
+ char *untilstr;
+
+ untilstr = strchr(p, '=');
+ rpt->until = ical_datetime2long(++untilstr, NULL);
+ } else {
+ unsigned cnt;
+ char *countstr;
+
+ if ((countstr = strstr(rrulestr, count)) != NULL) {
+ countstr += sizeof(count) - 1;
+ if (sscanf(countstr, "%u", &cnt) != 1) {
+ rpt->until = 0;
+ /* endless repetition */
+ } else {
+ rpt->count = cnt;
+ }
+ } else {
+ rpt->until = 0;
+ }
+ }
+
+ if ((p = strstr(rrulestr, interv)) != NULL) {
+ p += sizeof(interv) - 1;
+ if (sscanf(p, "%u", &interval) != 1) {
+ rpt->freq = 1;
+ /* default frequence if none specified */
+ } else {
+ rpt->freq = interval;
+ }
+ } else {
+ rpt->freq = 1;
+ }
+ } else {
+ ical_log(log, ICAL_VEVENT, itemline,
+ _("recurrence rule malformed."));
+ (*noskipped)++;
+ }
+ return rpt;
}
static void ical_add_exc(llist_t * exc_head, long date)
{
- if (date != 0) {
- struct excp *exc = mem_malloc(sizeof(struct excp));
- exc->st = date;
+ if (date != 0) {
+ struct excp *exc = mem_malloc(sizeof(struct excp));
+ exc->st = date;
- LLIST_ADD(exc_head, exc);
- }
+ LLIST_ADD(exc_head, exc);
+ }
}
/*
@@ -748,340 +779,417 @@ static void ical_add_exc(llist_t * exc_head, long date)
* recurring calendar component.
*/
static void
-ical_read_exdate(llist_t * exc, FILE * log, char *exstr, unsigned *noskipped,
- const int itemline)
+ical_read_exdate(llist_t * exc, FILE * log, char *exstr,
+ unsigned *noskipped, const int itemline)
{
- char *p, *q;
- long date;
-
- LLIST_INIT(exc);
- if ((p = strchr(exstr, ':')) != NULL) {
- p++;
- while ((q = strchr(p, ',')) != NULL) {
- char buf[BUFSIZ];
- const int buflen = q - p;
-
- strncpy(buf, p, buflen);
- buf[buflen] = '\0';
- date = ical_datetime2long(buf, NULL);
- ical_add_exc(exc, date);
- p = ++q;
- }
- date = ical_datetime2long(p, NULL);
- ical_add_exc(exc, date);
- } else {
- ical_log(log, ICAL_VEVENT, itemline,
- _("recurrence exception dates malformed."));
- (*noskipped)++;
- }
+ char *p, *q;
+ long date;
+
+ LLIST_INIT(exc);
+ if ((p = strchr(exstr, ':')) != NULL) {
+ p++;
+ while ((q = strchr(p, ',')) != NULL) {
+ char buf[BUFSIZ];
+ const int buflen = q - p;
+
+ strncpy(buf, p, buflen);
+ buf[buflen] = '\0';
+ date = ical_datetime2long(buf, NULL);
+ ical_add_exc(exc, date);
+ p = ++q;
+ }
+ date = ical_datetime2long(p, NULL);
+ ical_add_exc(exc, date);
+ } else {
+ ical_log(log, ICAL_VEVENT, itemline,
+ _("recurrence exception dates malformed."));
+ (*noskipped)++;
+ }
}
/* Return an allocated string containing the name of the newly created note. */
static char *ical_read_note(char *line, unsigned *noskipped,
- ical_types_e item_type, const int itemline,
- FILE * log)
+ ical_types_e item_type, const int itemline,
+ FILE * log)
{
- char *p, *notestr, *note;
-
- if ((p = strchr(line, ':')) != NULL) {
- p++;
- notestr = ical_unformat_line(p);
- if (notestr == NULL) {
- ical_log(log, item_type, itemline,
- _("could not get entire item description."));
- (*noskipped)++;
- return NULL;
- } else if (strlen(notestr) == 0) {
- mem_free(notestr);
- return NULL;
- } else {
- note = generate_note(notestr);
- mem_free(notestr);
- return note;
- }
- } else {
- ical_log(log, item_type, itemline, _("description malformed."));
- (*noskipped)++;
- return NULL;
- }
+ char *p, *notestr, *note;
+
+ if ((p = strchr(line, ':')) != NULL) {
+ p++;
+ notestr = ical_unformat_line(p);
+ if (notestr == NULL) {
+ ical_log(log, item_type, itemline,
+ _("could not get entire item description."));
+ (*noskipped)++;
+ return NULL;
+ } else if (strlen(notestr) == 0) {
+ mem_free(notestr);
+ return NULL;
+ } else {
+ note = generate_note(notestr);
+ mem_free(notestr);
+ return note;
+ }
+ } else {
+ ical_log(log, item_type, itemline,
+ _("description malformed."));
+ (*noskipped)++;
+ return NULL;
+ }
}
/* Returns an allocated string containing the ical item summary. */
static char *ical_read_summary(char *line)
{
- char *p, *summary;
-
- if ((p = strchr(line, ':')) != NULL) {
- p++;
- summary = ical_unformat_line(p);
- return summary;
- } else {
- return NULL;
- }
+ char *p, *summary;
+
+ if ((p = strchr(line, ':')) != NULL) {
+ p++;
+ summary = ical_unformat_line(p);
+ return summary;
+ } else {
+ return NULL;
+ }
}
static void
-ical_read_event(FILE * fdi, FILE * log, unsigned *noevents, unsigned *noapoints,
- unsigned *noskipped, char *buf, char *lstore, unsigned *lineno)
+ical_read_event(FILE * fdi, FILE * log, unsigned *noevents,
+ unsigned *noapoints, unsigned *noskipped, char *buf,
+ char *lstore, unsigned *lineno)
{
- const int ITEMLINE = *lineno;
- const char endevent[] = "END:VEVENT";
- const char summary[] = "SUMMARY";
- const char dtstart[] = "DTSTART";
- const char dtend[] = "DTEND";
- const char duration[] = "DURATION";
- const char rrule[] = "RRULE";
- const char exdate[] = "EXDATE";
- const char alarm[] = "BEGIN:VALARM";
- const char endalarm[] = "END:VALARM";
- const char desc[] = "DESCRIPTION";
- ical_vevent_e vevent_type;
- char *p;
- struct {
- llist_t exc;
- ical_rpt_t *rpt;
- char *mesg, *note;
- long start, end, dur;
- int has_alarm;
- } vevent;
- int skip_alarm;
-
- vevent_type = UNDEFINED;
- memset(&vevent, 0, sizeof vevent);
- skip_alarm = 0;
- while (ical_readline(fdi, buf, lstore, lineno)) {
- if (skip_alarm) {
- /* Need to skip VALARM properties because some keywords could
- interfere, such as DURATION, SUMMARY,.. */
- if (strncasecmp(buf, endalarm, sizeof(endalarm) - 1) == 0)
- skip_alarm = 0;
- continue;
- }
- if (strncasecmp(buf, endevent, sizeof(endevent) - 1) == 0) {
- if (vevent.mesg) {
- if (vevent.rpt && vevent.rpt->count)
- vevent.rpt->until = ical_compute_rpt_until(vevent.start, vevent.rpt);
-
- switch (vevent_type) {
- case APPOINTMENT:
- if (vevent.start == 0) {
- ical_log(log, ICAL_VEVENT, ITEMLINE,
- _("appointment has no start time."));
- goto cleanup;
- }
- if (vevent.dur == 0) {
- if (vevent.end == 0) {
- ical_log(log, ICAL_VEVENT, ITEMLINE,
- _("could not compute duration " "(no end time)."));
- goto cleanup;
- } else if (vevent.start == vevent.end) {
- vevent_type = EVENT;
- vevent.end = 0L;
- ical_store_event(vevent.mesg, vevent.note,
- vevent.start, vevent.end,
- vevent.rpt, &vevent.exc);
- (*noevents)++;
- return;
- } else {
- vevent.dur = vevent.end - vevent.start;
- if (vevent.dur < 0) {
- ical_log(log, ICAL_VEVENT, ITEMLINE,
- _("item has a negative duration."));
- goto cleanup;
- }
- }
- }
- ical_store_apoint(vevent.mesg, vevent.note, vevent.start,
- vevent.dur, vevent.rpt, &vevent.exc,
- vevent.has_alarm);
- (*noapoints)++;
- break;
- case EVENT:
- if (vevent.start == 0) {
- ical_log(log, ICAL_VEVENT, ITEMLINE,
- _("event date is not defined."));
- goto cleanup;
- }
- ical_store_event(vevent.mesg, vevent.note, vevent.start,
- vevent.end, vevent.rpt, &vevent.exc);
- (*noevents)++;
- break;
- case UNDEFINED:
- ical_log(log, ICAL_VEVENT, ITEMLINE,
- _("item could not be identified."));
- goto cleanup;
- break;
- }
- } else {
- ical_log(log, ICAL_VEVENT, ITEMLINE,
- _("could not retrieve item summary."));
- goto cleanup;
- }
- return;
- } else {
- if (strncasecmp(buf, dtstart, sizeof(dtstart) - 1) == 0) {
- if ((p = strchr(buf, ':')) != NULL)
- vevent.start = ical_datetime2long(++p, &vevent_type);
- if (!vevent.start) {
- ical_log(log, ICAL_VEVENT, ITEMLINE,
- _("could not retrieve event start time."));
- goto cleanup;
- }
- } else if (strncasecmp(buf, dtend, sizeof(dtend) - 1) == 0) {
- if ((p = strchr(buf, ':')) != NULL)
- vevent.end = ical_datetime2long(++p, &vevent_type);
- if (!vevent.end) {
- ical_log(log, ICAL_VEVENT, ITEMLINE,
- _("could not retrieve event end time."));
- goto cleanup;
- }
- } else if (strncasecmp(buf, duration, sizeof(duration) - 1) == 0) {
- if ((vevent.dur = ical_dur2long(buf)) <= 0) {
- ical_log(log, ICAL_VEVENT, ITEMLINE, _("item duration malformed."));
- goto cleanup;
- }
- } else if (strncasecmp(buf, rrule, sizeof(rrule) - 1) == 0) {
- vevent.rpt = ical_read_rrule(log, buf, noskipped, ITEMLINE);
- } else if (strncasecmp(buf, exdate, sizeof(exdate) - 1) == 0) {
- ical_read_exdate(&vevent.exc, log, buf, noskipped, ITEMLINE);
- } else if (strncasecmp(buf, summary, sizeof(summary) - 1) == 0) {
- vevent.mesg = ical_read_summary(buf);
- } else if (strncasecmp(buf, alarm, sizeof(alarm) - 1) == 0) {
- skip_alarm = 1;
- vevent.has_alarm = 1;
- } else if (strncasecmp(buf, desc, sizeof(desc) - 1) == 0) {
- vevent.note = ical_read_note(buf, noskipped, ICAL_VEVENT,
- ITEMLINE, log);
- }
- }
- }
- ical_log(log, ICAL_VEVENT, ITEMLINE,
- _("The ical file seems to be malformed. "
- "The end of item was not found."));
+ const int ITEMLINE = *lineno;
+ const char endevent[] = "END:VEVENT";
+ const char summary[] = "SUMMARY";
+ const char dtstart[] = "DTSTART";
+ const char dtend[] = "DTEND";
+ const char duration[] = "DURATION";
+ const char rrule[] = "RRULE";
+ const char exdate[] = "EXDATE";
+ const char alarm[] = "BEGIN:VALARM";
+ const char endalarm[] = "END:VALARM";
+ const char desc[] = "DESCRIPTION";
+ ical_vevent_e vevent_type;
+ char *p;
+ struct {
+ llist_t exc;
+ ical_rpt_t *rpt;
+ char *mesg, *note;
+ long start, end, dur;
+ int has_alarm;
+ } vevent;
+ int skip_alarm;
+
+ vevent_type = UNDEFINED;
+ memset(&vevent, 0, sizeof vevent);
+ skip_alarm = 0;
+ while (ical_readline(fdi, buf, lstore, lineno)) {
+ if (skip_alarm) {
+ /* Need to skip VALARM properties because some keywords could
+ interfere, such as DURATION, SUMMARY,.. */
+ if (strncasecmp
+ (buf, endalarm, sizeof(endalarm) - 1) == 0)
+ skip_alarm = 0;
+ continue;
+ }
+ if (strncasecmp(buf, endevent, sizeof(endevent) - 1) == 0) {
+ if (vevent.mesg) {
+ if (vevent.rpt && vevent.rpt->count)
+ vevent.rpt->until =
+ ical_compute_rpt_until(vevent.
+ start,
+ vevent.
+ rpt);
+
+ switch (vevent_type) {
+ case APPOINTMENT:
+ if (vevent.start == 0) {
+ ical_log(log, ICAL_VEVENT,
+ ITEMLINE,
+ _("appointment has no start time."));
+ goto cleanup;
+ }
+ if (vevent.dur == 0) {
+ if (vevent.end == 0) {
+ ical_log(log,
+ ICAL_VEVENT,
+ ITEMLINE,
+ _("could not compute duration "
+ "(no end time)."));
+ goto cleanup;
+ } else if (vevent.start ==
+ vevent.end) {
+ vevent_type =
+ EVENT;
+ vevent.end = 0L;
+ ical_store_event
+ (vevent.mesg,
+ vevent.note,
+ vevent.start,
+ vevent.end,
+ vevent.rpt,
+ &vevent.exc);
+ (*noevents)++;
+ return;
+ } else {
+ vevent.dur =
+ vevent.end -
+ vevent.start;
+ if (vevent.dur < 0) {
+ ical_log
+ (log,
+ ICAL_VEVENT,
+ ITEMLINE,
+ _("item has a negative duration."));
+ goto cleanup;
+ }
+ }
+ }
+ ical_store_apoint(vevent.mesg,
+ vevent.note,
+ vevent.start,
+ vevent.dur,
+ vevent.rpt,
+ &vevent.exc,
+ vevent.
+ has_alarm);
+ (*noapoints)++;
+ break;
+ case EVENT:
+ if (vevent.start == 0) {
+ ical_log(log, ICAL_VEVENT,
+ ITEMLINE,
+ _("event date is not defined."));
+ goto cleanup;
+ }
+ ical_store_event(vevent.mesg,
+ vevent.note,
+ vevent.start,
+ vevent.end,
+ vevent.rpt,
+ &vevent.exc);
+ (*noevents)++;
+ break;
+ case UNDEFINED:
+ ical_log(log, ICAL_VEVENT,
+ ITEMLINE,
+ _("item could not be identified."));
+ goto cleanup;
+ break;
+ }
+ } else {
+ ical_log(log, ICAL_VEVENT, ITEMLINE,
+ _("could not retrieve item summary."));
+ goto cleanup;
+ }
+ return;
+ } else {
+ if (strncasecmp(buf, dtstart, sizeof(dtstart) - 1)
+ == 0) {
+ if ((p = strchr(buf, ':')) != NULL)
+ vevent.start =
+ ical_datetime2long(++p,
+ &vevent_type);
+ if (!vevent.start) {
+ ical_log(log, ICAL_VEVENT,
+ ITEMLINE,
+ _("could not retrieve event start time."));
+ goto cleanup;
+ }
+ } else
+ if (strncasecmp(buf, dtend, sizeof(dtend) - 1)
+ == 0) {
+ if ((p = strchr(buf, ':')) != NULL)
+ vevent.end =
+ ical_datetime2long(++p,
+ &vevent_type);
+ if (!vevent.end) {
+ ical_log(log, ICAL_VEVENT,
+ ITEMLINE,
+ _("could not retrieve event end time."));
+ goto cleanup;
+ }
+ } else
+ if (strncasecmp
+ (buf, duration,
+ sizeof(duration) - 1) == 0) {
+ if ((vevent.dur = ical_dur2long(buf)) <= 0) {
+ ical_log(log, ICAL_VEVENT,
+ ITEMLINE,
+ _("item duration malformed."));
+ goto cleanup;
+ }
+ } else
+ if (strncasecmp(buf, rrule, sizeof(rrule) - 1)
+ == 0) {
+ vevent.rpt =
+ ical_read_rrule(log, buf, noskipped,
+ ITEMLINE);
+ } else
+ if (strncasecmp
+ (buf, exdate, sizeof(exdate) - 1) == 0) {
+ ical_read_exdate(&vevent.exc, log, buf,
+ noskipped, ITEMLINE);
+ } else
+ if (strncasecmp
+ (buf, summary, sizeof(summary) - 1) == 0) {
+ vevent.mesg = ical_read_summary(buf);
+ } else
+ if (strncasecmp(buf, alarm, sizeof(alarm) - 1)
+ == 0) {
+ skip_alarm = 1;
+ vevent.has_alarm = 1;
+ } else if (strncasecmp(buf, desc, sizeof(desc) - 1)
+ == 0) {
+ vevent.note =
+ ical_read_note(buf, noskipped,
+ ICAL_VEVENT, ITEMLINE,
+ log);
+ }
+ }
+ }
+ ical_log(log, ICAL_VEVENT, ITEMLINE,
+ _("The ical file seems to be malformed. "
+ "The end of item was not found."));
cleanup:
- if (vevent.note)
- mem_free(vevent.note);
- if (vevent.mesg)
- mem_free(vevent.mesg);
- if (vevent.rpt)
- mem_free(vevent.rpt);
- LLIST_FREE(&vevent.exc);
- (*noskipped)++;
+ if (vevent.note)
+ mem_free(vevent.note);
+ if (vevent.mesg)
+ mem_free(vevent.mesg);
+ if (vevent.rpt)
+ mem_free(vevent.rpt);
+ LLIST_FREE(&vevent.exc);
+ (*noskipped)++;
}
static void
-ical_read_todo(FILE * fdi, FILE * log, unsigned *notodos, unsigned *noskipped,
- char *buf, char *lstore, unsigned *lineno)
+ical_read_todo(FILE * fdi, FILE * log, unsigned *notodos,
+ unsigned *noskipped, char *buf, char *lstore,
+ unsigned *lineno)
{
- const char endtodo[] = "END:VTODO";
- const char summary[] = "SUMMARY";
- const char alarm[] = "BEGIN:VALARM";
- const char endalarm[] = "END:VALARM";
- const char desc[] = "DESCRIPTION";
- const int LOWEST = 9;
- const int ITEMLINE = *lineno;
- struct {
- char *mesg, *note;
- int has_priority, priority;
- } vtodo;
- int skip_alarm;
-
- memset(&vtodo, 0, sizeof vtodo);
- skip_alarm = 0;
- while (ical_readline(fdi, buf, lstore, lineno)) {
- if (skip_alarm) {
- /* Need to skip VALARM properties because some keywords could
- interfere, such as DURATION, SUMMARY,.. */
- if (strncasecmp(buf, endalarm, sizeof(endalarm) - 1) == 0)
- skip_alarm = 0;
- continue;
- }
- if (strncasecmp(buf, endtodo, sizeof(endtodo) - 1) == 0) {
- if (!vtodo.has_priority)
- vtodo.priority = LOWEST;
- if (vtodo.mesg) {
- ical_store_todo(vtodo.priority, vtodo.mesg, vtodo.note);
- (*notodos)++;
- } else {
- ical_log(log, ICAL_VTODO, ITEMLINE,
- _("could not retrieve item summary."));
- goto cleanup;
- }
- return;
- } else {
- int tmpint;
-
- if (strncasecmp(buf, "PRIORITY:", sizeof("PRIORITY:") - 1) == 0) {
- sscanf(buf, "%d", &tmpint);
- if (tmpint <= 9 && tmpint >= 1) {
- vtodo.priority = tmpint;
- vtodo.has_priority = 1;
- } else {
- ical_log(log, ICAL_VTODO, ITEMLINE,
- _("item priority is not acceptable "
- "(must be between 1 and 9)."));
- vtodo.priority = LOWEST;
- }
- } else if (strncasecmp(buf, summary, sizeof(summary) - 1) == 0) {
- vtodo.mesg = ical_read_summary(buf);
- } else if (strncasecmp(buf, alarm, sizeof(alarm) - 1) == 0) {
- skip_alarm = 1;
- } else if (strncasecmp(buf, desc, sizeof(desc) - 1) == 0) {
- vtodo.note = ical_read_note(buf, noskipped, ICAL_VTODO, ITEMLINE, log);
- }
- }
- }
- ical_log(log, ICAL_VTODO, ITEMLINE,
- _("The ical file seems to be malformed. "
- "The end of item was not found."));
+ const char endtodo[] = "END:VTODO";
+ const char summary[] = "SUMMARY";
+ const char alarm[] = "BEGIN:VALARM";
+ const char endalarm[] = "END:VALARM";
+ const char desc[] = "DESCRIPTION";
+ const int LOWEST = 9;
+ const int ITEMLINE = *lineno;
+ struct {
+ char *mesg, *note;
+ int has_priority, priority;
+ } vtodo;
+ int skip_alarm;
+
+ memset(&vtodo, 0, sizeof vtodo);
+ skip_alarm = 0;
+ while (ical_readline(fdi, buf, lstore, lineno)) {
+ if (skip_alarm) {
+ /* Need to skip VALARM properties because some keywords could
+ interfere, such as DURATION, SUMMARY,.. */
+ if (strncasecmp
+ (buf, endalarm, sizeof(endalarm) - 1) == 0)
+ skip_alarm = 0;
+ continue;
+ }
+ if (strncasecmp(buf, endtodo, sizeof(endtodo) - 1) == 0) {
+ if (!vtodo.has_priority)
+ vtodo.priority = LOWEST;
+ if (vtodo.mesg) {
+ ical_store_todo(vtodo.priority, vtodo.mesg,
+ vtodo.note);
+ (*notodos)++;
+ } else {
+ ical_log(log, ICAL_VTODO, ITEMLINE,
+ _("could not retrieve item summary."));
+ goto cleanup;
+ }
+ return;
+ } else {
+ int tmpint;
+
+ if (strncasecmp
+ (buf, "PRIORITY:",
+ sizeof("PRIORITY:") - 1) == 0) {
+ sscanf(buf, "%d", &tmpint);
+ if (tmpint <= 9 && tmpint >= 1) {
+ vtodo.priority = tmpint;
+ vtodo.has_priority = 1;
+ } else {
+ ical_log(log, ICAL_VTODO, ITEMLINE,
+ _("item priority is not acceptable "
+ "(must be between 1 and 9)."));
+ vtodo.priority = LOWEST;
+ }
+ } else
+ if (strncasecmp
+ (buf, summary, sizeof(summary) - 1) == 0) {
+ vtodo.mesg = ical_read_summary(buf);
+ } else
+ if (strncasecmp(buf, alarm, sizeof(alarm) - 1)
+ == 0) {
+ skip_alarm = 1;
+ } else if (strncasecmp(buf, desc, sizeof(desc) - 1)
+ == 0) {
+ vtodo.note =
+ ical_read_note(buf, noskipped,
+ ICAL_VTODO, ITEMLINE,
+ log);
+ }
+ }
+ }
+ ical_log(log, ICAL_VTODO, ITEMLINE,
+ _("The ical file seems to be malformed. "
+ "The end of item was not found."));
cleanup:
- if (vtodo.note)
- mem_free(vtodo.note);
- if (vtodo.mesg)
- mem_free(vtodo.mesg);
- (*noskipped)++;
+ if (vtodo.note)
+ mem_free(vtodo.note);
+ if (vtodo.mesg)
+ mem_free(vtodo.mesg);
+ (*noskipped)++;
}
/* Import calcurse data. */
void
-ical_import_data(FILE * stream, FILE * log, unsigned *events, unsigned *apoints,
- unsigned *todos, unsigned *lines, unsigned *skipped)
+ical_import_data(FILE * stream, FILE * log, unsigned *events,
+ unsigned *apoints, unsigned *todos, unsigned *lines,
+ unsigned *skipped)
{
- const char vevent[] = "BEGIN:VEVENT";
- const char vtodo[] = "BEGIN:VTODO";
- char buf[BUFSIZ], lstore[BUFSIZ];
- int major, minor;
-
- ical_readline_init(stream, buf, lstore, lines);
- RETURN_IF(!ical_chk_header(stream, buf, lstore, lines, &major, &minor),
- _("Warning: ical header malformed or wrong version number. "
- "Aborting..."));
-
- ical_log_init(log, major, minor);
-
- while (ical_readline(stream, buf, lstore, lines)) {
- (*lines)++;
- if (strncasecmp(buf, vevent, sizeof(vevent) - 1) == 0) {
- ical_read_event(stream, log, events, apoints, skipped, buf, lstore,
- lines);
- } else if (strncasecmp(buf, vtodo, sizeof(vtodo) - 1) == 0) {
- ical_read_todo(stream, log, todos, skipped, buf, lstore, lines);
- }
- }
+ const char vevent[] = "BEGIN:VEVENT";
+ const char vtodo[] = "BEGIN:VTODO";
+ char buf[BUFSIZ], lstore[BUFSIZ];
+ int major, minor;
+
+ ical_readline_init(stream, buf, lstore, lines);
+ RETURN_IF(!ical_chk_header
+ (stream, buf, lstore, lines, &major, &minor),
+ _("Warning: ical header malformed or wrong version number. "
+ "Aborting..."));
+
+ ical_log_init(log, major, minor);
+
+ while (ical_readline(stream, buf, lstore, lines)) {
+ (*lines)++;
+ if (strncasecmp(buf, vevent, sizeof(vevent) - 1) == 0) {
+ ical_read_event(stream, log, events, apoints,
+ skipped, buf, lstore, lines);
+ } else if (strncasecmp(buf, vtodo, sizeof(vtodo) - 1) == 0) {
+ ical_read_todo(stream, log, todos, skipped, buf,
+ lstore, lines);
+ }
+ }
}
/* Export calcurse data. */
void ical_export_data(FILE * stream)
{
- ical_export_header(stream);
- ical_export_recur_events(stream);
- ical_export_events(stream);
- ical_export_recur_apoints(stream);
- ical_export_apoints(stream);
- ical_export_todo(stream);
- ical_export_footer(stream);
+ ical_export_header(stream);
+ ical_export_recur_events(stream);
+ ical_export_events(stream);
+ ical_export_recur_apoints(stream);
+ ical_export_apoints(stream);
+ ical_export_todo(stream);
+ ical_export_footer(stream);
}
diff --git a/src/io.c b/src/io.c
index c1b3631..0f5d711 100644
--- a/src/io.c
+++ b/src/io.c
@@ -48,40 +48,40 @@
#include "sha1.h"
typedef enum {
- PROGRESS_BAR_SAVE,
- PROGRESS_BAR_LOAD,
- PROGRESS_BAR_EXPORT
+ PROGRESS_BAR_SAVE,
+ PROGRESS_BAR_LOAD,
+ PROGRESS_BAR_EXPORT
} progress_bar_t;
enum {
- PROGRESS_BAR_CONF,
- PROGRESS_BAR_TODO,
- PROGRESS_BAR_APTS,
- PROGRESS_BAR_KEYS
+ PROGRESS_BAR_CONF,
+ PROGRESS_BAR_TODO,
+ PROGRESS_BAR_APTS,
+ PROGRESS_BAR_KEYS
};
enum {
- PROGRESS_BAR_EXPORT_EVENTS,
- PROGRESS_BAR_EXPORT_APOINTS,
- PROGRESS_BAR_EXPORT_TODO
+ PROGRESS_BAR_EXPORT_EVENTS,
+ PROGRESS_BAR_EXPORT_APOINTS,
+ PROGRESS_BAR_EXPORT_TODO
};
struct ht_keybindings_s {
- const char *label;
- enum key key;
- HTABLE_ENTRY(ht_keybindings_s);
+ const char *label;
+ enum key key;
+ HTABLE_ENTRY(ht_keybindings_s);
};
static void load_keys_ht_getkey(struct ht_keybindings_s *, const char **,
- int *);
+ int *);
static int load_keys_ht_compare(struct ht_keybindings_s *,
- struct ht_keybindings_s *);
+ struct ht_keybindings_s *);
#define HSIZE 256
HTABLE_HEAD(ht_keybindings, HSIZE, ht_keybindings_s);
HTABLE_PROTOTYPE(ht_keybindings, ht_keybindings_s)
HTABLE_GENERATE(ht_keybindings, ht_keybindings_s, load_keys_ht_getkey,
- load_keys_ht_compare)
+ load_keys_ht_compare)
/* Draw a progress bar while saving, loading or exporting data. */
static void progress_bar(progress_bar_t type, int progress)
@@ -89,59 +89,63 @@ static void progress_bar(progress_bar_t type, int progress)
#define NBFILES 4
#define NBEXPORTED 3
#define LABELENGTH 15
- int i, step, steps;
- const char *mesg_sav = _("Saving...");
- const char *mesg_load = _("Loading...");
- const char *mesg_export = _("Exporting...");
- const char *error_msg = _("Internal error while displaying progress bar");
- const char *barchar = "|";
- const char *file[NBFILES] = {
- "[ conf ]",
- "[ todo ]",
- "[ apts ]",
- "[ keys ]"
- };
- const char *data[NBEXPORTED] = {
- "[ events ]",
- "[appointments]",
- "[ todo ]"
- };
- int ipos = LABELENGTH + 2;
- int epos[NBFILES];
-
- /* progress bar length init. */
- ipos = LABELENGTH + 2;
- steps = (type == PROGRESS_BAR_EXPORT) ? NBEXPORTED : NBFILES;
- step = floor(col / (steps + 1));
- for (i = 0; i < steps - 1; i++)
- epos[i] = (i + 2) * step;
- epos[steps - 1] = col - 2;
-
- switch (type) {
- case PROGRESS_BAR_SAVE:
- EXIT_IF(progress < 0 || progress > PROGRESS_BAR_KEYS, "%s", error_msg);
- status_mesg(mesg_sav, file[progress]);
- break;
- case PROGRESS_BAR_LOAD:
- EXIT_IF(progress < 0 || progress > PROGRESS_BAR_KEYS, "%s", error_msg);
- status_mesg(mesg_load, file[progress]);
- break;
- case PROGRESS_BAR_EXPORT:
- EXIT_IF(progress < 0
- || progress > PROGRESS_BAR_EXPORT_TODO, "%s", error_msg);
- status_mesg(mesg_export, data[progress]);
- break;
- }
-
- /* Draw the progress bar. */
- mvwaddstr(win[STA].p, 1, ipos, barchar);
- mvwaddstr(win[STA].p, 1, epos[steps - 1], barchar);
- custom_apply_attr(win[STA].p, ATTR_HIGHEST);
- for (i = ipos + 1; i < epos[progress]; i++)
- mvwaddch(win[STA].p, 1, i, ' ' | A_REVERSE);
- custom_remove_attr(win[STA].p, ATTR_HIGHEST);
- wmove(win[STA].p, 0, 0);
- wins_wrefresh(win[STA].p);
+ int i, step, steps;
+ const char *mesg_sav = _("Saving...");
+ const char *mesg_load = _("Loading...");
+ const char *mesg_export = _("Exporting...");
+ const char *error_msg =
+ _("Internal error while displaying progress bar");
+ const char *barchar = "|";
+ const char *file[NBFILES] = {
+ "[ conf ]",
+ "[ todo ]",
+ "[ apts ]",
+ "[ keys ]"
+ };
+ const char *data[NBEXPORTED] = {
+ "[ events ]",
+ "[appointments]",
+ "[ todo ]"
+ };
+ int ipos = LABELENGTH + 2;
+ int epos[NBFILES];
+
+ /* progress bar length init. */
+ ipos = LABELENGTH + 2;
+ steps = (type == PROGRESS_BAR_EXPORT) ? NBEXPORTED : NBFILES;
+ step = floor(col / (steps + 1));
+ for (i = 0; i < steps - 1; i++)
+ epos[i] = (i + 2) * step;
+ epos[steps - 1] = col - 2;
+
+ switch (type) {
+ case PROGRESS_BAR_SAVE:
+ EXIT_IF(progress < 0
+ || progress > PROGRESS_BAR_KEYS, "%s", error_msg);
+ status_mesg(mesg_sav, file[progress]);
+ break;
+ case PROGRESS_BAR_LOAD:
+ EXIT_IF(progress < 0
+ || progress > PROGRESS_BAR_KEYS, "%s", error_msg);
+ status_mesg(mesg_load, file[progress]);
+ break;
+ case PROGRESS_BAR_EXPORT:
+ EXIT_IF(progress < 0
+ || progress > PROGRESS_BAR_EXPORT_TODO, "%s",
+ error_msg);
+ status_mesg(mesg_export, data[progress]);
+ break;
+ }
+
+ /* Draw the progress bar. */
+ mvwaddstr(win[STA].p, 1, ipos, barchar);
+ mvwaddstr(win[STA].p, 1, epos[steps - 1], barchar);
+ custom_apply_attr(win[STA].p, ATTR_HIGHEST);
+ for (i = ipos + 1; i < epos[progress]; i++)
+ mvwaddch(win[STA].p, 1, i, ' ' | A_REVERSE);
+ custom_remove_attr(win[STA].p, ATTR_HIGHEST);
+ wmove(win[STA].p, 0, 0);
+ wins_wrefresh(win[STA].p);
#undef NBFILES
#undef NBEXPORTED
#undef LABELENGTH
@@ -150,63 +154,66 @@ static void progress_bar(progress_bar_t type, int progress)
/* Ask user for a file name to export data to. */
static FILE *get_export_stream(enum export_type type)
{
- FILE *stream;
- char *home, *stream_name;
- const char *question = _("Choose the file used to export calcurse data:");
- const char *wrong_name =
- _("The file cannot be accessed, please enter another file name.");
- const char *press_enter = _("Press [ENTER] to continue.");
- const char *file_ext[IO_EXPORT_NBTYPES] = { "ical", "txt" };
-
- stream = NULL;
- stream_name = (char *)mem_malloc(BUFSIZ);
- if ((home = getenv("HOME")) != NULL)
- snprintf(stream_name, BUFSIZ, "%s/calcurse.%s", home, file_ext[type]);
- else
- snprintf(stream_name, BUFSIZ, "%s/calcurse.%s", get_tempdir(),
- file_ext[type]);
-
- while (stream == NULL) {
- status_mesg(question, "");
- if (updatestring(win[STA].p, &stream_name, 0, 1)) {
- mem_free(stream_name);
- return NULL;
- }
- stream = fopen(stream_name, "w");
- if (stream == NULL) {
- status_mesg(wrong_name, press_enter);
- wgetch(win[KEY].p);
- }
- }
- mem_free(stream_name);
-
- return stream;
+ FILE *stream;
+ char *home, *stream_name;
+ const char *question =
+ _("Choose the file used to export calcurse data:");
+ const char *wrong_name =
+ _("The file cannot be accessed, please enter another file name.");
+ const char *press_enter = _("Press [ENTER] to continue.");
+ const char *file_ext[IO_EXPORT_NBTYPES] = { "ical", "txt" };
+
+ stream = NULL;
+ stream_name = (char *)mem_malloc(BUFSIZ);
+ if ((home = getenv("HOME")) != NULL)
+ snprintf(stream_name, BUFSIZ, "%s/calcurse.%s", home,
+ file_ext[type]);
+ else
+ snprintf(stream_name, BUFSIZ, "%s/calcurse.%s",
+ get_tempdir(), file_ext[type]);
+
+ while (stream == NULL) {
+ status_mesg(question, "");
+ if (updatestring(win[STA].p, &stream_name, 0, 1)) {
+ mem_free(stream_name);
+ return NULL;
+ }
+ stream = fopen(stream_name, "w");
+ if (stream == NULL) {
+ status_mesg(wrong_name, press_enter);
+ wgetch(win[KEY].p);
+ }
+ }
+ mem_free(stream_name);
+
+ return stream;
}
/* Append a line to a file. */
unsigned io_fprintln(const char *fname, const char *fmt, ...)
{
- FILE *fp;
- va_list ap;
- char buf[BUFSIZ];
- int ret;
+ FILE *fp;
+ va_list ap;
+ char buf[BUFSIZ];
+ int ret;
- fp = fopen(fname, "a");
- RETVAL_IF(!fp, 0, _("Failed to open \"%s\", - %s\n"), fname, strerror(errno));
+ fp = fopen(fname, "a");
+ RETVAL_IF(!fp, 0, _("Failed to open \"%s\", - %s\n"), fname,
+ strerror(errno));
- va_start(ap, fmt);
- ret = vsnprintf(buf, sizeof buf, fmt, ap);
- RETVAL_IF(ret < 0, 0, _("Failed to build message\n"));
- va_end(ap);
+ va_start(ap, fmt);
+ ret = vsnprintf(buf, sizeof buf, fmt, ap);
+ RETVAL_IF(ret < 0, 0, _("Failed to build message\n"));
+ va_end(ap);
- ret = fprintf(fp, "%s", buf);
- RETVAL_IF(ret < 0, 0, _("Failed to print message \"%s\"\n"), buf);
+ ret = fprintf(fp, "%s", buf);
+ RETVAL_IF(ret < 0, 0, _("Failed to print message \"%s\"\n"), buf);
- ret = fclose(fp);
- RETVAL_IF(ret != 0, 0, _("Failed to close \"%s\" - %s\n"),
- fname, strerror(errno));
+ ret = fclose(fp);
+ RETVAL_IF(ret != 0, 0, _("Failed to close \"%s\" - %s\n"),
+ fname, strerror(errno));
- return 1;
+ return 1;
}
/*
@@ -218,90 +225,94 @@ unsigned io_fprintln(const char *fname, const char *fmt, ...)
*/
void io_init(const char *cfile, const char *datadir)
{
- FILE *data_file;
- const char *home;
- char apts_file[BUFSIZ] = "";
- int ch;
-
- if (datadir != NULL) {
- home = datadir;
- snprintf(path_dir, BUFSIZ, "%s", home);
- snprintf(path_todo, BUFSIZ, "%s/" TODO_PATH_NAME, home);
- snprintf(path_conf, BUFSIZ, "%s/" CONF_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);
- } else {
- home = getenv("HOME");
- if (home == NULL) {
- home = ".";
- }
- snprintf(path_dir, BUFSIZ, "%s/" DIR_NAME, home);
- snprintf(path_todo, BUFSIZ, "%s/" TODO_PATH, home);
- snprintf(path_conf, BUFSIZ, "%s/" CONF_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);
- }
-
- if (cfile == NULL) {
- if (datadir != NULL) {
- snprintf(path_apts, BUFSIZ, "%s/" APTS_PATH_NAME, home);
- } else {
- snprintf(path_apts, BUFSIZ, "%s/" APTS_PATH, home);
- }
- } 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__);
- }
+ FILE *data_file;
+ const char *home;
+ char apts_file[BUFSIZ] = "";
+ int ch;
+
+ if (datadir != NULL) {
+ home = datadir;
+ snprintf(path_dir, BUFSIZ, "%s", home);
+ snprintf(path_todo, BUFSIZ, "%s/" TODO_PATH_NAME, home);
+ snprintf(path_conf, BUFSIZ, "%s/" CONF_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);
+ } else {
+ home = getenv("HOME");
+ if (home == NULL) {
+ home = ".";
+ }
+ snprintf(path_dir, BUFSIZ, "%s/" DIR_NAME, home);
+ snprintf(path_todo, BUFSIZ, "%s/" TODO_PATH, home);
+ snprintf(path_conf, BUFSIZ, "%s/" CONF_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);
+ }
+
+ if (cfile == NULL) {
+ if (datadir != NULL) {
+ snprintf(path_apts, BUFSIZ, "%s/" APTS_PATH_NAME,
+ home);
+ } else {
+ snprintf(path_apts, BUFSIZ, "%s/" APTS_PATH, home);
+ }
+ } 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__);
+ }
}
void io_extract_data(char *dst_data, const char *org, int len)
{
- int i;
-
- for (; *org == ' ' || *org == '\t'; org++) ;
- for (i = 0; i < len - 1; i++) {
- if (*org == '\n' || *org == '\0' || *org == '#')
- break;
- *dst_data++ = *org++;
- }
- *dst_data = '\0';
+ int i;
+
+ for (; *org == ' ' || *org == '\t'; org++) ;
+ for (i = 0; i < len - 1; i++) {
+ if (*org == '\n' || *org == '\0' || *org == '#')
+ break;
+ *dst_data++ = *org++;
+ }
+ *dst_data = '\0';
}
static pthread_mutex_t io_save_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -313,124 +324,125 @@ static pthread_mutex_t io_save_mutex = PTHREAD_MUTEX_INITIALIZER;
*/
unsigned io_save_apts(void)
{
- llist_item_t *i;
- FILE *fp;
+ llist_item_t *i;
+ FILE *fp;
- if (read_only)
- return 1;
+ if (read_only)
+ return 1;
- if ((fp = fopen(path_apts, "w")) == NULL)
- return 0;
+ if ((fp = fopen(path_apts, "w")) == NULL)
+ return 0;
- recur_save_data(fp);
+ recur_save_data(fp);
- if (ui_mode == UI_CURSES)
- LLIST_TS_LOCK(&alist_p);
- LLIST_TS_FOREACH(&alist_p, i) {
- struct apoint *apt = LLIST_TS_GET_DATA(i);
- apoint_write(apt, fp);
- }
- if (ui_mode == UI_CURSES)
- LLIST_TS_UNLOCK(&alist_p);
+ if (ui_mode == UI_CURSES)
+ LLIST_TS_LOCK(&alist_p);
+ LLIST_TS_FOREACH(&alist_p, i) {
+ struct apoint *apt = LLIST_TS_GET_DATA(i);
+ apoint_write(apt, fp);
+ }
+ if (ui_mode == UI_CURSES)
+ LLIST_TS_UNLOCK(&alist_p);
- LLIST_FOREACH(&eventlist, i) {
- struct event *ev = LLIST_TS_GET_DATA(i);
- event_write(ev, fp);
- }
- file_close(fp, __FILE_POS__);
+ LLIST_FOREACH(&eventlist, i) {
+ struct event *ev = LLIST_TS_GET_DATA(i);
+ event_write(ev, fp);
+ }
+ file_close(fp, __FILE_POS__);
- return 1;
+ return 1;
}
/* Save the todo data file. */
unsigned io_save_todo(void)
{
- llist_item_t *i;
- FILE *fp;
+ llist_item_t *i;
+ FILE *fp;
- if (read_only)
- return 1;
+ if (read_only)
+ return 1;
- if ((fp = fopen(path_todo, "w")) == NULL)
- return 0;
+ if ((fp = fopen(path_todo, "w")) == NULL)
+ return 0;
- LLIST_FOREACH(&todolist, i) {
- struct todo *todo = LLIST_TS_GET_DATA(i);
- todo_write(todo, fp);
- }
- file_close(fp, __FILE_POS__);
+ LLIST_FOREACH(&todolist, i) {
+ struct todo *todo = LLIST_TS_GET_DATA(i);
+ todo_write(todo, fp);
+ }
+ file_close(fp, __FILE_POS__);
- return 1;
+ return 1;
}
/* Save user-defined keys */
unsigned io_save_keys(void)
{
- FILE *fp;
+ FILE *fp;
- if (read_only)
- return 1;
+ if (read_only)
+ return 1;
- if ((fp = fopen(path_keys, "w")) == NULL)
- return 0;
+ if ((fp = fopen(path_keys, "w")) == NULL)
+ return 0;
- keys_save_bindings(fp);
- file_close(fp, __FILE_POS__);
+ keys_save_bindings(fp);
+ file_close(fp, __FILE_POS__);
- return 1;
+ return 1;
}
/* Save the calendar data */
void io_save_cal(enum save_display display)
{
- const char *access_pb = _("Problems accessing data file ...");
- const char *save_success = _("The data files were successfully saved");
- const char *enter = _("Press [ENTER] to continue");
- int show_bar;
-
- if (read_only)
- return;
-
- pthread_mutex_lock(&io_save_mutex);
-
- show_bar = 0;
- if (ui_mode == UI_CURSES && display == IO_SAVE_DISPLAY_BAR
- && conf.progress_bar)
- show_bar = 1;
-
- if (show_bar)
- progress_bar(PROGRESS_BAR_SAVE, PROGRESS_BAR_CONF);
- if (!config_save())
- ERROR_MSG("%s", access_pb);
-
- if (show_bar)
- progress_bar(PROGRESS_BAR_SAVE, PROGRESS_BAR_TODO);
- if (!io_save_todo())
- ERROR_MSG("%s", access_pb);
-
- if (show_bar)
- progress_bar(PROGRESS_BAR_SAVE, PROGRESS_BAR_APTS);
- if (!io_save_apts())
- ERROR_MSG("%s", access_pb);
-
- if (show_bar)
- progress_bar(PROGRESS_BAR_SAVE, PROGRESS_BAR_KEYS);
- if (!io_save_keys())
- ERROR_MSG("%s", access_pb);
-
- /* Print a message telling data were saved */
- if (ui_mode == UI_CURSES && conf.system_dialogs) {
- status_mesg(save_success, enter);
- wgetch(win[KEY].p);
- }
-
- pthread_mutex_unlock(&io_save_mutex);
+ const char *access_pb = _("Problems accessing data file ...");
+ const char *save_success =
+ _("The data files were successfully saved");
+ const char *enter = _("Press [ENTER] to continue");
+ int show_bar;
+
+ if (read_only)
+ return;
+
+ pthread_mutex_lock(&io_save_mutex);
+
+ show_bar = 0;
+ if (ui_mode == UI_CURSES && display == IO_SAVE_DISPLAY_BAR
+ && conf.progress_bar)
+ show_bar = 1;
+
+ if (show_bar)
+ progress_bar(PROGRESS_BAR_SAVE, PROGRESS_BAR_CONF);
+ if (!config_save())
+ ERROR_MSG("%s", access_pb);
+
+ if (show_bar)
+ progress_bar(PROGRESS_BAR_SAVE, PROGRESS_BAR_TODO);
+ if (!io_save_todo())
+ ERROR_MSG("%s", access_pb);
+
+ if (show_bar)
+ progress_bar(PROGRESS_BAR_SAVE, PROGRESS_BAR_APTS);
+ if (!io_save_apts())
+ ERROR_MSG("%s", access_pb);
+
+ if (show_bar)
+ progress_bar(PROGRESS_BAR_SAVE, PROGRESS_BAR_KEYS);
+ if (!io_save_keys())
+ ERROR_MSG("%s", access_pb);
+
+ /* Print a message telling data were saved */
+ if (ui_mode == UI_CURSES && conf.system_dialogs) {
+ status_mesg(save_success, enter);
+ wgetch(win[KEY].p);
+ }
+
+ pthread_mutex_unlock(&io_save_mutex);
}
static void io_load_error(const char *filename, unsigned line,
- const char *mesg)
+ const char *mesg)
{
- EXIT("%s:%u: %s", filename, line, mesg);
+ EXIT("%s:%u: %s", filename, line, mesg);
}
/*
@@ -440,230 +452,252 @@ static void io_load_error(const char *filename, unsigned line,
*/
void io_load_app(void)
{
- FILE *data_file;
- int c, is_appointment, is_event, is_recursive;
- struct tm start, end, until, lt;
- llist_t exc;
- time_t t;
- int id = 0;
- int freq;
- char type, state = 0L;
- char note[MAX_NOTESIZ + 1], *notep;
- unsigned line = 0;
-
- t = time(NULL);
- localtime_r(&t, &lt);
- start = end = until = lt;
-
- data_file = fopen(path_apts, "r");
- EXIT_IF(data_file == NULL, _("failed to open appointment file"));
-
- for (;;) {
- LLIST_INIT(&exc);
- is_appointment = is_event = is_recursive = 0;
- line++;
- c = getc(data_file);
- if (c == EOF)
- break;
- ungetc(c, data_file);
-
- /* Read the date first: it is common to both events
- * and appointments.
- */
- if (fscanf(data_file, "%d / %d / %d ",
- &start.tm_mon, &start.tm_mday, &start.tm_year) != 3)
- io_load_error(path_apts, line, _("syntax error in the item date"));
-
- /* Read the next character : if it is an '@' then we have
- * an appointment, else if it is an '[' we have en event.
- */
- c = getc(data_file);
-
- if (c == '@')
- is_appointment = 1;
- else if (c == '[')
- is_event = 1;
- else
- io_load_error(path_apts, line, _("no event nor appointment found"));
-
- /* Read the remaining informations. */
- if (is_appointment) {
- if (fscanf(data_file, " %d : %d -> %d / %d / %d @ %d : %d ",
- &start.tm_hour, &start.tm_min,
- &end.tm_mon, &end.tm_mday, &end.tm_year,
- &end.tm_hour, &end.tm_min) != 7)
- io_load_error(path_apts, line,
- _("syntax error in item time or duration"));
- } else if (is_event) {
- if (fscanf(data_file, " %d ", &id) != 1 || getc(data_file) != ']')
- io_load_error(path_apts, line, _("syntax error in item identifier"));
- while ((c = getc(data_file)) == ' ') ;
- ungetc(c, data_file);
- } else {
- io_load_error(path_apts, line,
- _("wrong format in the appointment or event"));
- /* NOTREACHED */
- }
-
- /* Check if we have a recursive item. */
- c = getc(data_file);
-
- if (c == '{') {
- is_recursive = 1;
- if (fscanf(data_file, " %d%c ", &freq, &type) != 2)
- io_load_error(path_apts, line, _("syntax error in item repetition"));
-
- c = getc(data_file);
- if (c == '}') { /* endless recurrent item */
- until.tm_year = 0;
- while ((c = getc(data_file)) == ' ') ;
- ungetc(c, data_file);
- } else if (c == '-' && getc(data_file) == '>') {
- if (fscanf(data_file, " %d / %d / %d ", &until.tm_mon,
- &until.tm_mday, &until.tm_year) != 3)
- io_load_error(path_apts, line, _("syntax error in item repetition"));
- c = getc(data_file);
- if (c == '!') {
- ungetc(c, data_file);
- recur_exc_scan(&exc, data_file);
- while ((c = getc(data_file)) == ' ') ;
- ungetc(c, data_file);
- } else if (c == '}') {
- while ((c = getc(data_file)) == ' ') ;
- ungetc(c, data_file);
- } else {
- io_load_error(path_apts, line, _("syntax error in item repetition"));
- }
- } else if (c == '!') { /* endless item with exceptions */
- ungetc(c, data_file);
- recur_exc_scan(&exc, data_file);
- while ((c = getc(data_file)) == ' ') ;
- ungetc(c, data_file);
- until.tm_year = 0;
- } else {
- io_load_error(path_apts, line,
- _("wrong format in the appointment or event"));
- /* NOTREACHED */
- }
- } else {
- ungetc(c, data_file);
- }
-
- /* Check if a note is attached to the item. */
- c = getc(data_file);
- if (c == '>') {
- note_read(note, data_file);
- notep = note;
- } else {
- notep = NULL;
- ungetc(c, data_file);
- }
-
- /*
- * Last: read the item description and load it into its
- * corresponding linked list, depending on the item type.
- */
- if (is_appointment) {
- c = getc(data_file);
- if (c == '!') {
- state |= APOINT_NOTIFY;
- while ((c = getc(data_file)) == ' ') ;
- ungetc(c, data_file);
- } else if (c == '|') {
- state = 0L;
- while ((c = getc(data_file)) == ' ') ;
- ungetc(c, data_file);
- } else {
- io_load_error(path_apts, line, _("syntax error in item repetition"));
- }
- if (is_recursive) {
- recur_apoint_scan(data_file, start, end,
- type, freq, until, notep, &exc, state);
- } else {
- apoint_scan(data_file, start, end, state, notep);
- }
- } else if (is_event) {
- if (is_recursive) {
- recur_event_scan(data_file, start, id, type, freq, until, notep, &exc);
- } else {
- event_scan(data_file, start, id, notep);
- }
- } else {
- io_load_error(path_apts, line,
- _("wrong format in the appointment or event"));
- /* NOTREACHED */
- }
- }
- file_close(data_file, __FILE_POS__);
+ FILE *data_file;
+ int c, is_appointment, is_event, is_recursive;
+ struct tm start, end, until, lt;
+ llist_t exc;
+ time_t t;
+ int id = 0;
+ int freq;
+ char type, state = 0L;
+ char note[MAX_NOTESIZ + 1], *notep;
+ unsigned line = 0;
+
+ t = time(NULL);
+ localtime_r(&t, &lt);
+ start = end = until = lt;
+
+ data_file = fopen(path_apts, "r");
+ EXIT_IF(data_file == NULL, _("failed to open appointment file"));
+
+ for (;;) {
+ LLIST_INIT(&exc);
+ is_appointment = is_event = is_recursive = 0;
+ line++;
+ c = getc(data_file);
+ if (c == EOF)
+ break;
+ ungetc(c, data_file);
+
+ /* Read the date first: it is common to both events
+ * and appointments.
+ */
+ if (fscanf(data_file, "%d / %d / %d ",
+ &start.tm_mon, &start.tm_mday,
+ &start.tm_year) != 3)
+ io_load_error(path_apts, line,
+ _("syntax error in the item date"));
+
+ /* Read the next character : if it is an '@' then we have
+ * an appointment, else if it is an '[' we have en event.
+ */
+ c = getc(data_file);
+
+ if (c == '@')
+ is_appointment = 1;
+ else if (c == '[')
+ is_event = 1;
+ else
+ io_load_error(path_apts, line,
+ _("no event nor appointment found"));
+
+ /* Read the remaining informations. */
+ if (is_appointment) {
+ if (fscanf
+ (data_file,
+ " %d : %d -> %d / %d / %d @ %d : %d ",
+ &start.tm_hour, &start.tm_min, &end.tm_mon,
+ &end.tm_mday, &end.tm_year, &end.tm_hour,
+ &end.tm_min) != 7)
+ io_load_error(path_apts, line,
+ _("syntax error in item time or duration"));
+ } else if (is_event) {
+ if (fscanf(data_file, " %d ", &id) != 1
+ || getc(data_file) != ']')
+ io_load_error(path_apts, line,
+ _("syntax error in item identifier"));
+ while ((c = getc(data_file)) == ' ') ;
+ ungetc(c, data_file);
+ } else {
+ io_load_error(path_apts, line,
+ _("wrong format in the appointment or event"));
+ /* NOTREACHED */
+ }
+
+ /* Check if we have a recursive item. */
+ c = getc(data_file);
+
+ if (c == '{') {
+ is_recursive = 1;
+ if (fscanf(data_file, " %d%c ", &freq, &type) != 2)
+ io_load_error(path_apts, line,
+ _("syntax error in item repetition"));
+
+ c = getc(data_file);
+ if (c == '}') { /* endless recurrent item */
+ until.tm_year = 0;
+ while ((c = getc(data_file)) == ' ') ;
+ ungetc(c, data_file);
+ } else if (c == '-' && getc(data_file) == '>') {
+ if (fscanf
+ (data_file, " %d / %d / %d ",
+ &until.tm_mon, &until.tm_mday,
+ &until.tm_year) != 3)
+ io_load_error(path_apts, line,
+ _("syntax error in item repetition"));
+ c = getc(data_file);
+ if (c == '!') {
+ ungetc(c, data_file);
+ recur_exc_scan(&exc, data_file);
+ while ((c =
+ getc(data_file)) == ' ') ;
+ ungetc(c, data_file);
+ } else if (c == '}') {
+ while ((c =
+ getc(data_file)) == ' ') ;
+ ungetc(c, data_file);
+ } else {
+ io_load_error(path_apts, line,
+ _("syntax error in item repetition"));
+ }
+ } else if (c == '!') { /* endless item with exceptions */
+ ungetc(c, data_file);
+ recur_exc_scan(&exc, data_file);
+ while ((c = getc(data_file)) == ' ') ;
+ ungetc(c, data_file);
+ until.tm_year = 0;
+ } else {
+ io_load_error(path_apts, line,
+ _("wrong format in the appointment or event"));
+ /* NOTREACHED */
+ }
+ } else {
+ ungetc(c, data_file);
+ }
+
+ /* Check if a note is attached to the item. */
+ c = getc(data_file);
+ if (c == '>') {
+ note_read(note, data_file);
+ notep = note;
+ } else {
+ notep = NULL;
+ ungetc(c, data_file);
+ }
+
+ /*
+ * Last: read the item description and load it into its
+ * corresponding linked list, depending on the item type.
+ */
+ if (is_appointment) {
+ c = getc(data_file);
+ if (c == '!') {
+ state |= APOINT_NOTIFY;
+ while ((c = getc(data_file)) == ' ') ;
+ ungetc(c, data_file);
+ } else if (c == '|') {
+ state = 0L;
+ while ((c = getc(data_file)) == ' ') ;
+ ungetc(c, data_file);
+ } else {
+ io_load_error(path_apts, line,
+ _("syntax error in item repetition"));
+ }
+ if (is_recursive) {
+ recur_apoint_scan(data_file, start, end,
+ type, freq, until, notep,
+ &exc, state);
+ } else {
+ apoint_scan(data_file, start, end, state,
+ notep);
+ }
+ } else if (is_event) {
+ if (is_recursive) {
+ recur_event_scan(data_file, start, id,
+ type, freq, until, notep,
+ &exc);
+ } else {
+ event_scan(data_file, start, id, notep);
+ }
+ } else {
+ io_load_error(path_apts, line,
+ _("wrong format in the appointment or event"));
+ /* NOTREACHED */
+ }
+ }
+ file_close(data_file, __FILE_POS__);
}
/* Load the todo data */
void io_load_todo(void)
{
- FILE *data_file;
- char *newline;
- int nb_tod = 0;
- int c, id;
- char buf[BUFSIZ], e_todo[BUFSIZ], note[MAX_NOTESIZ + 1];
- unsigned line = 0;
-
- data_file = fopen(path_todo, "r");
- EXIT_IF(data_file == NULL, _("failed to open todo file"));
-
- for (;;) {
- line++;
- c = getc(data_file);
- if (c == EOF) {
- break;
- } else if (c == '[') { /* new style with id */
- if (fscanf(data_file, " %d ", &id) != 1 || getc(data_file) != ']')
- io_load_error(path_todo, line, _("syntax error in item identifier"));
- while ((c = getc(data_file)) == ' ') ;
- ungetc(c, data_file);
- } else {
- id = 9;
- ungetc(c, data_file);
- }
- /* Now read the attached note, if any. */
- c = getc(data_file);
- if (c == '>') {
- note_read(note, data_file);
- } else {
- note[0] = '\0';
- ungetc(c, data_file);
- }
- /* Then read todo description. */
- if (!fgets(buf, sizeof buf, data_file))
- buf[0] = '\0';
- newline = strchr(buf, '\n');
- if (newline)
- *newline = '\0';
- io_extract_data(e_todo, buf, sizeof buf);
- todo_add(e_todo, id, note);
- ++nb_tod;
- }
- file_close(data_file, __FILE_POS__);
- ui_todo_set_nb(nb_tod);
+ FILE *data_file;
+ char *newline;
+ int nb_tod = 0;
+ int c, id;
+ char buf[BUFSIZ], e_todo[BUFSIZ], note[MAX_NOTESIZ + 1];
+ unsigned line = 0;
+
+ data_file = fopen(path_todo, "r");
+ EXIT_IF(data_file == NULL, _("failed to open todo file"));
+
+ for (;;) {
+ line++;
+ c = getc(data_file);
+ if (c == EOF) {
+ break;
+ } else if (c == '[') { /* new style with id */
+ if (fscanf(data_file, " %d ", &id) != 1
+ || getc(data_file) != ']')
+ io_load_error(path_todo, line,
+ _("syntax error in item identifier"));
+ while ((c = getc(data_file)) == ' ') ;
+ ungetc(c, data_file);
+ } else {
+ id = 9;
+ ungetc(c, data_file);
+ }
+ /* Now read the attached note, if any. */
+ c = getc(data_file);
+ if (c == '>') {
+ note_read(note, data_file);
+ } else {
+ note[0] = '\0';
+ ungetc(c, data_file);
+ }
+ /* Then read todo description. */
+ if (!fgets(buf, sizeof buf, data_file))
+ buf[0] = '\0';
+ newline = strchr(buf, '\n');
+ if (newline)
+ *newline = '\0';
+ io_extract_data(e_todo, buf, sizeof buf);
+ todo_add(e_todo, id, note);
+ ++nb_tod;
+ }
+ file_close(data_file, __FILE_POS__);
+ ui_todo_set_nb(nb_tod);
}
static void
-load_keys_ht_getkey(struct ht_keybindings_s *data, const char **key, int *len)
+load_keys_ht_getkey(struct ht_keybindings_s *data, const char **key,
+ int *len)
{
- *key = data->label;
- *len = strlen(data->label);
+ *key = data->label;
+ *len = strlen(data->label);
}
static int
load_keys_ht_compare(struct ht_keybindings_s *data1,
- struct ht_keybindings_s *data2)
+ struct ht_keybindings_s *data2)
{
- const int KEYLEN = strlen(data1->label);
+ const int KEYLEN = strlen(data1->label);
- if (strlen(data2->label) == KEYLEN
- && !memcmp(data1->label, data2->label, KEYLEN))
- return 0;
- else
- return 1;
+ if (strlen(data2->label) == KEYLEN
+ && !memcmp(data1->label, data2->label, KEYLEN))
+ return 0;
+ else
+ return 1;
}
/*
@@ -673,7 +707,7 @@ load_keys_ht_compare(struct ht_keybindings_s *data1,
*/
static int is_blank(int c)
{
- return c == ' ' || c == '\t';
+ return c == ' ' || c == '\t';
}
/*
@@ -685,176 +719,192 @@ static int is_blank(int c)
*/
void io_load_keys(const char *pager)
{
- struct ht_keybindings_s keys[NBKEYS];
- FILE *keyfp;
- char buf[BUFSIZ];
- struct io_file *log;
- int i, skipped, loaded, line;
- const int MAX_ERRORS = 5;
-
- keys_init();
-
- struct ht_keybindings ht_keys = HTABLE_INITIALIZER(&ht_keys);
-
- for (i = 0; i < NBKEYS; i++) {
- keys[i].key = (enum key)i;
- keys[i].label = keys_get_label((enum key)i);
- HTABLE_INSERT(ht_keybindings, &ht_keys, &keys[i]);
- }
-
- keyfp = fopen(path_keys, "r");
- EXIT_IF(keyfp == NULL, _("failed to open key file"));
-
- log = io_log_init();
- skipped = loaded = line = 0;
- while (fgets(buf, BUFSIZ, keyfp) != NULL) {
- char key_label[BUFSIZ], *p;
- struct ht_keybindings_s *ht_elm, ht_entry;
- const int AWAITED = 1;
- int assigned;
-
- line++;
- if (skipped > MAX_ERRORS) {
- const char *too_many =
- _("\nToo many errors while reading configuration file!\n"
- "Please backup your keys file, remove it from directory, "
- "and launch calcurse again.\n");
-
- io_log_print(log, line, too_many);
- break;
- }
- for (p = buf; is_blank((int)*p); p++) ;
- if (p != buf)
- memmove(buf, p, strlen(p));
- if (buf[0] == '#' || buf[0] == '\n')
- continue;
-
- if (sscanf(buf, "%s", key_label) != AWAITED) {
- skipped++;
- io_log_print(log, line, _("Could not read key label"));
- continue;
- }
-
- /* Skip legacy entries. */
- if (strcmp(key_label, "generic-cut") == 0)
- continue;
-
- ht_entry.label = key_label;
- p = buf + strlen(key_label) + 1;
- ht_elm = HTABLE_LOOKUP(ht_keybindings, &ht_keys, &ht_entry);
- if (!ht_elm) {
- skipped++;
- io_log_print(log, line, _("Key label not recognized"));
- continue;
- }
- assigned = 0;
- for (;;) {
- char key_ch[BUFSIZ], tmpbuf[BUFSIZ];
-
- while (*p == ' ')
- p++;
- (void)strncpy(tmpbuf, p, BUFSIZ);
- if (sscanf(tmpbuf, "%s", key_ch) == AWAITED) {
- int ch;
-
- if ((ch = keys_str2int(key_ch)) < 0) {
- char unknown_key[BUFSIZ];
-
- skipped++;
- (void)snprintf(unknown_key, BUFSIZ,
- _("Error reading key: \"%s\""), key_ch);
- io_log_print(log, line, unknown_key);
- } else {
- int used;
-
- used = keys_assign_binding(ch, ht_elm->key);
- if (used) {
- char already_assigned[BUFSIZ];
-
- skipped++;
- (void)snprintf(already_assigned, BUFSIZ,
- _("\"%s\" assigned multiple times!"), key_ch);
- io_log_print(log, line, already_assigned);
- } else {
- assigned++;
- }
- }
- p += strlen(key_ch) + 1;
- } else {
- if (assigned)
- loaded++;
- break;
- }
- }
- }
- file_close(keyfp, __FILE_POS__);
- file_close(log->fd, __FILE_POS__);
- if (skipped > 0) {
- const char *view_log =
- _("There were some errors when loading keys file, see log file ?");
-
- io_log_display(log, view_log, pager);
- }
- io_log_free(log);
- EXIT_IF(skipped > MAX_ERRORS,
- _("Too many errors while reading keys file, aborting..."));
- if (loaded < NBKEYS)
- keys_fill_missing();
- if (keys_check_missing_bindings())
- WARN_MSG(_("Some actions do not have any associated key bindings!"));
+ struct ht_keybindings_s keys[NBKEYS];
+ FILE *keyfp;
+ char buf[BUFSIZ];
+ struct io_file *log;
+ int i, skipped, loaded, line;
+ const int MAX_ERRORS = 5;
+
+ keys_init();
+
+ struct ht_keybindings ht_keys = HTABLE_INITIALIZER(&ht_keys);
+
+ for (i = 0; i < NBKEYS; i++) {
+ keys[i].key = (enum key)i;
+ keys[i].label = keys_get_label((enum key)i);
+ HTABLE_INSERT(ht_keybindings, &ht_keys, &keys[i]);
+ }
+
+ keyfp = fopen(path_keys, "r");
+ EXIT_IF(keyfp == NULL, _("failed to open key file"));
+
+ log = io_log_init();
+ skipped = loaded = line = 0;
+ while (fgets(buf, BUFSIZ, keyfp) != NULL) {
+ char key_label[BUFSIZ], *p;
+ struct ht_keybindings_s *ht_elm, ht_entry;
+ const int AWAITED = 1;
+ int assigned;
+
+ line++;
+ if (skipped > MAX_ERRORS) {
+ const char *too_many =
+ _("\nToo many errors while reading configuration file!\n"
+ "Please backup your keys file, remove it from directory, "
+ "and launch calcurse again.\n");
+
+ io_log_print(log, line, too_many);
+ break;
+ }
+ for (p = buf; is_blank((int)*p); p++) ;
+ if (p != buf)
+ memmove(buf, p, strlen(p));
+ if (buf[0] == '#' || buf[0] == '\n')
+ continue;
+
+ if (sscanf(buf, "%s", key_label) != AWAITED) {
+ skipped++;
+ io_log_print(log, line,
+ _("Could not read key label"));
+ continue;
+ }
+
+ /* Skip legacy entries. */
+ if (strcmp(key_label, "generic-cut") == 0)
+ continue;
+
+ ht_entry.label = key_label;
+ p = buf + strlen(key_label) + 1;
+ ht_elm =
+ HTABLE_LOOKUP(ht_keybindings, &ht_keys, &ht_entry);
+ if (!ht_elm) {
+ skipped++;
+ io_log_print(log, line,
+ _("Key label not recognized"));
+ continue;
+ }
+ assigned = 0;
+ for (;;) {
+ char key_ch[BUFSIZ], tmpbuf[BUFSIZ];
+
+ while (*p == ' ')
+ p++;
+ (void)strncpy(tmpbuf, p, BUFSIZ);
+ if (sscanf(tmpbuf, "%s", key_ch) == AWAITED) {
+ int ch;
+
+ if ((ch = keys_str2int(key_ch)) < 0) {
+ char unknown_key[BUFSIZ];
+
+ skipped++;
+ (void)snprintf(unknown_key, BUFSIZ,
+ _("Error reading key: \"%s\""),
+ key_ch);
+ io_log_print(log, line,
+ unknown_key);
+ } else {
+ int used;
+
+ used =
+ keys_assign_binding(ch,
+ ht_elm->
+ key);
+ if (used) {
+ char already_assigned
+ [BUFSIZ];
+
+ skipped++;
+ (void)
+ snprintf
+ (already_assigned,
+ BUFSIZ,
+ _("\"%s\" assigned multiple times!"),
+ key_ch);
+ io_log_print(log, line,
+ already_assigned);
+ } else {
+ assigned++;
+ }
+ }
+ p += strlen(key_ch) + 1;
+ } else {
+ if (assigned)
+ loaded++;
+ break;
+ }
+ }
+ }
+ file_close(keyfp, __FILE_POS__);
+ file_close(log->fd, __FILE_POS__);
+ if (skipped > 0) {
+ const char *view_log =
+ _("There were some errors when loading keys file, see log file ?");
+
+ io_log_display(log, view_log, pager);
+ }
+ io_log_free(log);
+ EXIT_IF(skipped > MAX_ERRORS,
+ _("Too many errors while reading keys file, aborting..."));
+ if (loaded < NBKEYS)
+ keys_fill_missing();
+ if (keys_check_missing_bindings())
+ WARN_MSG(_("Some actions do not have any associated key bindings!"));
}
int io_check_dir(const char *dir)
{
- if (read_only)
- return -1;
-
- errno = 0;
- if (mkdir(dir, 0700) != 0) {
- if (errno != EEXIST) {
- fprintf(stderr, _("FATAL ERROR: could not create %s: %s\n"), dir,
- strerror(errno));
- exit_calcurse(EXIT_FAILURE);
- } else {
- return 1;
- }
- } else {
- return 0;
- }
+ if (read_only)
+ return -1;
+
+ errno = 0;
+ if (mkdir(dir, 0700) != 0) {
+ if (errno != EEXIST) {
+ fprintf(stderr,
+ _("FATAL ERROR: could not create %s: %s\n"),
+ dir, strerror(errno));
+ exit_calcurse(EXIT_FAILURE);
+ } else {
+ return 1;
+ }
+ } else {
+ return 0;
+ }
}
unsigned io_file_exist(const char *file)
{
- FILE *fd;
-
- if (file && (fd = fopen(file, "r")) != NULL) {
- fclose(fd);
- return 1;
- } else {
- return 0;
- }
+ FILE *fd;
+
+ if (file && (fd = fopen(file, "r")) != NULL) {
+ fclose(fd);
+ return 1;
+ } else {
+ return 0;
+ }
}
int io_check_file(const char *file)
{
- if (read_only)
- return -1;
-
- errno = 0;
- if (io_file_exist(file)) {
- return 1;
- } else {
- FILE *fd;
-
- if ((fd = fopen(file, "w")) == NULL) {
- fprintf(stderr, _("FATAL ERROR: could not create %s: %s\n"), file,
- strerror(errno));
- exit_calcurse(EXIT_FAILURE);
- }
- file_close(fd, __FILE_POS__);
-
- return 0;
- }
+ if (read_only)
+ return -1;
+
+ errno = 0;
+ if (io_file_exist(file)) {
+ return 1;
+ } else {
+ FILE *fd;
+
+ if ((fd = fopen(file, "w")) == NULL) {
+ fprintf(stderr,
+ _("FATAL ERROR: could not create %s: %s\n"),
+ file, strerror(errno));
+ exit_calcurse(EXIT_FAILURE);
+ }
+ file_close(fd, __FILE_POS__);
+
+ return 0;
+ }
}
/*
@@ -871,98 +921,100 @@ int io_check_file(const char *file)
*/
int io_check_data_files(void)
{
- int missing = 0;
+ int missing = 0;
- missing += io_check_dir(path_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;
- missing += io_check_file(path_conf) ? 0 : 1;
+ missing += io_check_dir(path_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;
+ missing += io_check_file(path_conf) ? 0 : 1;
- if (!io_check_file(path_keys)) {
- missing++;
- keys_dump_defaults(path_keys);
- }
+ if (!io_check_file(path_keys)) {
+ missing++;
+ keys_dump_defaults(path_keys);
+ }
- return missing;
+ return missing;
}
/* Draw the startup screen */
void io_startup_screen(int no_data_file)
{
- const char *enter = _("Press [ENTER] to continue");
+ const char *enter = _("Press [ENTER] to continue");
- if (no_data_file)
- status_mesg(_("Welcome to Calcurse. Missing data files were created."),
- enter);
- else
- status_mesg(_("Data files found. Data will be loaded now."), enter);
+ if (no_data_file)
+ status_mesg(_("Welcome to Calcurse. Missing data files were created."),
+ enter);
+ else
+ status_mesg(_("Data files found. Data will be loaded now."),
+ enter);
- wgetch(win[KEY].p);
+ wgetch(win[KEY].p);
}
/* Export calcurse data. */
void io_export_data(enum export_type type)
{
- FILE *stream = NULL;
- const char *success = _("The data were successfully exported");
- const char *enter = _("Press [ENTER] to continue");
-
- if (type < IO_EXPORT_ICAL || type >= IO_EXPORT_NBTYPES)
- EXIT(_("unknown export type"));
-
- switch (ui_mode) {
- case UI_CMDLINE:
- stream = stdout;
- break;
- case UI_CURSES:
- stream = get_export_stream(type);
- break;
- default:
- EXIT(_("wrong export mode"));
- /* NOTREACHED */
- }
-
- if (stream == NULL)
- return;
-
- if (type == IO_EXPORT_ICAL)
- ical_export_data(stream);
- else if (type == IO_EXPORT_PCAL)
- pcal_export_data(stream);
-
- if (conf.system_dialogs && ui_mode == UI_CURSES) {
- status_mesg(success, enter);
- wgetch(win[KEY].p);
- }
+ FILE *stream = NULL;
+ const char *success = _("The data were successfully exported");
+ const char *enter = _("Press [ENTER] to continue");
+
+ if (type < IO_EXPORT_ICAL || type >= IO_EXPORT_NBTYPES)
+ EXIT(_("unknown export type"));
+
+ switch (ui_mode) {
+ case UI_CMDLINE:
+ stream = stdout;
+ break;
+ case UI_CURSES:
+ stream = get_export_stream(type);
+ break;
+ default:
+ EXIT(_("wrong export mode"));
+ /* NOTREACHED */
+ }
+
+ if (stream == NULL)
+ return;
+
+ if (type == IO_EXPORT_ICAL)
+ ical_export_data(stream);
+ else if (type == IO_EXPORT_PCAL)
+ pcal_export_data(stream);
+
+ if (conf.system_dialogs && ui_mode == UI_CURSES) {
+ status_mesg(success, enter);
+ wgetch(win[KEY].p);
+ }
}
static FILE *get_import_stream(enum import_type type)
{
- FILE *stream = NULL;
- char *stream_name;
- const char *ask_fname = _("Enter the file name to import data from:");
- const char *wrong_file =
- _("The file cannot be accessed, please enter another file name.");
- const char *press_enter = _("Press [ENTER] to continue.");
-
- stream_name = mem_malloc(BUFSIZ);
- memset(stream_name, 0, BUFSIZ);
- while (stream == NULL) {
- status_mesg(ask_fname, "");
- if (updatestring(win[STA].p, &stream_name, 0, 1)) {
- mem_free(stream_name);
- return NULL;
- }
- stream = fopen(stream_name, "r");
- if (stream == NULL) {
- status_mesg(wrong_file, press_enter);
- wgetch(win[KEY].p);
- }
- }
- mem_free(stream_name);
-
- return stream;
+ FILE *stream = NULL;
+ char *stream_name;
+ const char *ask_fname =
+ _("Enter the file name to import data from:");
+ const char *wrong_file =
+ _("The file cannot be accessed, please enter another file name.");
+ const char *press_enter = _("Press [ENTER] to continue.");
+
+ stream_name = mem_malloc(BUFSIZ);
+ memset(stream_name, 0, BUFSIZ);
+ while (stream == NULL) {
+ status_mesg(ask_fname, "");
+ if (updatestring(win[STA].p, &stream_name, 0, 1)) {
+ mem_free(stream_name);
+ return NULL;
+ }
+ stream = fopen(stream_name, "r");
+ if (stream == NULL) {
+ status_mesg(wrong_file, press_enter);
+ wgetch(win[KEY].p);
+ }
+ }
+ mem_free(stream_name);
+
+ return stream;
}
/*
@@ -973,146 +1025,153 @@ static FILE *get_import_stream(enum import_type type)
*/
void io_import_data(enum import_type type, const char *stream_name)
{
- const char *proc_report = _("Import process report: %04d lines read ");
- char stats_str[4][BUFSIZ];
- FILE *stream = NULL;
- struct io_file *log;
- struct {
- unsigned events, apoints, todos, lines, skipped;
- } stats;
-
- EXIT_IF(type < 0 || type >= IO_IMPORT_NBTYPES, _("unknown import type"));
- switch (ui_mode) {
- case UI_CMDLINE:
- stream = fopen(stream_name, "r");
- EXIT_IF(stream == NULL,
- _("FATAL ERROR: the input file cannot be accessed, "
- "Aborting..."));
- break;
- case UI_CURSES:
- stream = get_import_stream(type);
- break;
- default:
- EXIT(_("FATAL ERROR: wrong import mode"));
- /* NOTREACHED */
- }
-
- if (stream == NULL)
- return;
-
- memset(&stats, 0, sizeof stats);
-
- log = io_log_init();
- if (log == NULL) {
- if (stream != stdin)
- file_close(stream, __FILE_POS__);
- return;
- }
-
- if (type == IO_IMPORT_ICAL)
- ical_import_data(stream, log->fd, &stats.events, &stats.apoints,
- &stats.todos, &stats.lines, &stats.skipped);
-
- if (stream != stdin)
- file_close(stream, __FILE_POS__);
-
- snprintf(stats_str[0], BUFSIZ,
- ngettext("%d app", "%d apps", stats.apoints), stats.apoints);
- snprintf(stats_str[1], BUFSIZ,
- ngettext("%d event", "%d events", stats.events), stats.events);
- snprintf(stats_str[2], BUFSIZ,
- ngettext("%d todo", "%d todos", stats.todos), stats.todos);
- snprintf(stats_str[3], BUFSIZ, _("%d skipped"), stats.skipped);
-
- /* Update the number of todo items. */
- ui_todo_set_nb(ui_todo_nb() + stats.todos);
-
- if (ui_mode == UI_CURSES && conf.system_dialogs) {
- char read[BUFSIZ], stat[BUFSIZ];
-
- snprintf(read, BUFSIZ, proc_report, stats.lines);
- snprintf(stat, BUFSIZ, "%s / %s / %s / %s (%s)", stats_str[0],
- stats_str[1], stats_str[2], stats_str[3],
- _("Press [ENTER] to continue"));
- status_mesg(read, stat);
- wgetch(win[KEY].p);
- } else if (ui_mode == UI_CMDLINE) {
- printf(proc_report, stats.lines);
- printf("\n%s / %s / %s / %s\n", stats_str[0], stats_str[1],
- stats_str[2], stats_str[3]);
- }
-
- /* User has the choice to look at the log file if some items could not be
- imported.
- */
- file_close(log->fd, __FILE_POS__);
- if (stats.skipped > 0) {
- const char *view_log =
- _("Some items could not be imported, see log file ?");
-
- io_log_display(log, view_log, conf.pager);
- }
- io_log_free(log);
+ const char *proc_report =
+ _("Import process report: %04d lines read ");
+ char stats_str[4][BUFSIZ];
+ FILE *stream = NULL;
+ struct io_file *log;
+ struct {
+ unsigned events, apoints, todos, lines, skipped;
+ } stats;
+
+ EXIT_IF(type < 0
+ || type >= IO_IMPORT_NBTYPES, _("unknown import type"));
+ switch (ui_mode) {
+ case UI_CMDLINE:
+ stream = fopen(stream_name, "r");
+ EXIT_IF(stream == NULL,
+ _("FATAL ERROR: the input file cannot be accessed, "
+ "Aborting..."));
+ break;
+ case UI_CURSES:
+ stream = get_import_stream(type);
+ break;
+ default:
+ EXIT(_("FATAL ERROR: wrong import mode"));
+ /* NOTREACHED */
+ }
+
+ if (stream == NULL)
+ return;
+
+ memset(&stats, 0, sizeof stats);
+
+ log = io_log_init();
+ if (log == NULL) {
+ if (stream != stdin)
+ file_close(stream, __FILE_POS__);
+ return;
+ }
+
+ if (type == IO_IMPORT_ICAL)
+ ical_import_data(stream, log->fd, &stats.events,
+ &stats.apoints, &stats.todos,
+ &stats.lines, &stats.skipped);
+
+ if (stream != stdin)
+ file_close(stream, __FILE_POS__);
+
+ snprintf(stats_str[0], BUFSIZ,
+ ngettext("%d app", "%d apps", stats.apoints),
+ stats.apoints);
+ snprintf(stats_str[1], BUFSIZ,
+ ngettext("%d event", "%d events", stats.events),
+ stats.events);
+ snprintf(stats_str[2], BUFSIZ,
+ ngettext("%d todo", "%d todos", stats.todos),
+ stats.todos);
+ snprintf(stats_str[3], BUFSIZ, _("%d skipped"), stats.skipped);
+
+ /* Update the number of todo items. */
+ ui_todo_set_nb(ui_todo_nb() + stats.todos);
+
+ if (ui_mode == UI_CURSES && conf.system_dialogs) {
+ char read[BUFSIZ], stat[BUFSIZ];
+
+ snprintf(read, BUFSIZ, proc_report, stats.lines);
+ snprintf(stat, BUFSIZ, "%s / %s / %s / %s (%s)",
+ stats_str[0], stats_str[1], stats_str[2],
+ stats_str[3], _("Press [ENTER] to continue"));
+ status_mesg(read, stat);
+ wgetch(win[KEY].p);
+ } else if (ui_mode == UI_CMDLINE) {
+ printf(proc_report, stats.lines);
+ printf("\n%s / %s / %s / %s\n", stats_str[0], stats_str[1],
+ stats_str[2], stats_str[3]);
+ }
+
+ /* User has the choice to look at the log file if some items could not be
+ imported.
+ */
+ file_close(log->fd, __FILE_POS__);
+ if (stats.skipped > 0) {
+ const char *view_log =
+ _("Some items could not be imported, see log file ?");
+
+ io_log_display(log, view_log, conf.pager);
+ }
+ io_log_free(log);
}
struct io_file *io_log_init(void)
{
- char logprefix[BUFSIZ];
- char *logname;
- struct io_file *log;
-
- snprintf(logprefix, BUFSIZ, "%s/calcurse_log.", get_tempdir());
- logname = new_tempfile(logprefix, TMPEXTSIZ);
- RETVAL_IF(logname == NULL, 0,
- _("Warning: could not create temporary log file, Aborting..."));
- log = mem_malloc(sizeof(struct io_file));
- RETVAL_IF(log == NULL, 0,
- _("Warning: could not open temporary log file, Aborting..."));
- snprintf(log->name, sizeof(log->name), "%s%s", logprefix, logname);
- mem_free(logname);
- log->fd = fopen(log->name, "w");
- if (log->fd == NULL) {
- ERROR_MSG(_("Warning: could not open temporary log file, Aborting..."));
- mem_free(log);
- return 0;
- }
-
- return log;
+ char logprefix[BUFSIZ];
+ char *logname;
+ struct io_file *log;
+
+ snprintf(logprefix, BUFSIZ, "%s/calcurse_log.", get_tempdir());
+ logname = new_tempfile(logprefix, TMPEXTSIZ);
+ RETVAL_IF(logname == NULL, 0,
+ _("Warning: could not create temporary log file, Aborting..."));
+ log = mem_malloc(sizeof(struct io_file));
+ RETVAL_IF(log == NULL, 0,
+ _("Warning: could not open temporary log file, Aborting..."));
+ snprintf(log->name, sizeof(log->name), "%s%s", logprefix, logname);
+ mem_free(logname);
+ log->fd = fopen(log->name, "w");
+ if (log->fd == NULL) {
+ ERROR_MSG(_("Warning: could not open temporary log file, Aborting..."));
+ mem_free(log);
+ return 0;
+ }
+
+ return log;
}
void io_log_print(struct io_file *log, int line, const char *msg)
{
- if (log && log->fd)
- fprintf(log->fd, "line %d: %s\n", line, msg);
+ if (log && log->fd)
+ fprintf(log->fd, "line %d: %s\n", line, msg);
}
-void io_log_display(struct io_file *log, const char *msg, const char *pager)
+void io_log_display(struct io_file *log, const char *msg,
+ const char *pager)
{
- RETURN_IF(log == NULL, _("No log file to display!"));
- if (ui_mode == UI_CMDLINE) {
- printf("\n%s [y/n] ", msg);
- if (fgetc(stdin) == 'y') {
- const char *arg[] = { pager, log->name, NULL };
- int pid;
-
- if ((pid = fork_exec(NULL, NULL, pager, arg)))
- child_wait(NULL, NULL, pid);
- }
- } else {
- if (status_ask_bool(msg) == 1)
- wins_launch_external(log->name, pager);
- wins_erase_status_bar();
- }
+ RETURN_IF(log == NULL, _("No log file to display!"));
+ if (ui_mode == UI_CMDLINE) {
+ printf("\n%s [y/n] ", msg);
+ if (fgetc(stdin) == 'y') {
+ const char *arg[] = { pager, log->name, NULL };
+ int pid;
+
+ if ((pid = fork_exec(NULL, NULL, pager, arg)))
+ child_wait(NULL, NULL, pid);
+ }
+ } else {
+ if (status_ask_bool(msg) == 1)
+ wins_launch_external(log->name, pager);
+ wins_erase_status_bar();
+ }
}
void io_log_free(struct io_file *log)
{
- if (!log)
- return;
- EXIT_IF(unlink(log->name) != 0,
- _("Warning: could not erase temporary log file %s, Aborting..."),
- log->name);
- mem_free(log);
+ if (!log)
+ return;
+ EXIT_IF(unlink(log->name) != 0,
+ _("Warning: could not erase temporary log file %s, Aborting..."),
+ log->name);
+ mem_free(log);
}
static pthread_t io_t_psave;
@@ -1120,28 +1179,28 @@ static pthread_t io_t_psave;
/* Thread used to periodically save data. */
static void *io_psave_thread(void *arg)
{
- int delay = conf.periodic_save;
- EXIT_IF(delay < 0, _("Invalid delay"));
+ int delay = conf.periodic_save;
+ EXIT_IF(delay < 0, _("Invalid delay"));
- for (;;) {
- sleep(delay * MININSEC);
- io_save_cal(IO_SAVE_DISPLAY_NONE);
- }
+ for (;;) {
+ sleep(delay * MININSEC);
+ io_save_cal(IO_SAVE_DISPLAY_NONE);
+ }
}
/* Launch the thread which handles periodic saves. */
void io_start_psave_thread(void)
{
- pthread_create(&io_t_psave, NULL, io_psave_thread, NULL);
+ pthread_create(&io_t_psave, NULL, io_psave_thread, NULL);
}
/* Stop periodic data saves. */
void io_stop_psave_thread(void)
{
- if (io_t_psave) {
- pthread_cancel(io_t_psave);
- pthread_join(io_t_psave, NULL);
- }
+ if (io_t_psave) {
+ pthread_cancel(io_t_psave);
+ pthread_join(io_t_psave, NULL);
+ }
}
/*
@@ -1157,32 +1216,33 @@ void io_stop_psave_thread(void)
*/
void io_set_lock(void)
{
- FILE *lock = fopen(path_cpid, "r");
- int pid;
-
- if (lock != NULL) {
- /* If there is a lock file, check whether the process exists. */
- if (fscanf(lock, "%d", &pid) == 1) {
- fclose(lock);
- if (kill(pid, 0) != 0 && errno == ESRCH)
- lock = NULL;
- } else {
- fclose(lock);
- }
- }
-
- if (lock != NULL) {
- fprintf(stderr,
- _("\nWARNING: it seems that another calcurse instance is "
- "already running.\n"
- "If this is not the case, please remove the following "
- "lock file: \n\"%s\"\n" "and restart calcurse.\n"), path_cpid);
- exit(EXIT_FAILURE);
- } else {
- if (!io_dump_pid(path_cpid))
- EXIT(_("FATAL ERROR: could not create %s: %s\n"),
- path_cpid, strerror(errno));
- }
+ FILE *lock = fopen(path_cpid, "r");
+ int pid;
+
+ if (lock != NULL) {
+ /* If there is a lock file, check whether the process exists. */
+ if (fscanf(lock, "%d", &pid) == 1) {
+ fclose(lock);
+ if (kill(pid, 0) != 0 && errno == ESRCH)
+ lock = NULL;
+ } else {
+ fclose(lock);
+ }
+ }
+
+ if (lock != NULL) {
+ fprintf(stderr,
+ _("\nWARNING: it seems that another calcurse instance is "
+ "already running.\n"
+ "If this is not the case, please remove the following "
+ "lock file: \n\"%s\"\n"
+ "and restart calcurse.\n"), path_cpid);
+ exit(EXIT_FAILURE);
+ } else {
+ if (!io_dump_pid(path_cpid))
+ EXIT(_("FATAL ERROR: could not create %s: %s\n"),
+ path_cpid, strerror(errno));
+ }
}
/*
@@ -1191,18 +1251,18 @@ void io_set_lock(void)
*/
unsigned io_dump_pid(char *file)
{
- pid_t pid;
- FILE *fp;
+ pid_t pid;
+ FILE *fp;
- if (!file)
- return 0;
+ if (!file)
+ return 0;
- pid = getpid();
- if (!(fp = fopen(file, "w"))
- || fprintf(fp, "%ld\n", (long)pid) < 0 || fclose(fp) != 0)
- return 0;
+ pid = getpid();
+ if (!(fp = fopen(file, "w"))
+ || fprintf(fp, "%ld\n", (long)pid) < 0 || fclose(fp) != 0)
+ return 0;
- return 1;
+ return 1;
}
/*
@@ -1212,21 +1272,21 @@ unsigned io_dump_pid(char *file)
*/
unsigned io_get_pid(char *file)
{
- FILE *fp;
- unsigned pid;
+ FILE *fp;
+ unsigned pid;
- if (!file)
- return 0;
+ if (!file)
+ return 0;
- if ((fp = fopen(file, "r")) == NULL)
- return 0;
+ if ((fp = fopen(file, "r")) == NULL)
+ return 0;
- if (fscanf(fp, "%u", &pid) != 1)
- return 0;
+ if (fscanf(fp, "%u", &pid) != 1)
+ return 0;
- fclose(fp);
+ fclose(fp);
- return pid;
+ return pid;
}
/*
@@ -1234,19 +1294,19 @@ unsigned io_get_pid(char *file)
*/
int io_file_is_empty(char *file)
{
- FILE *fp;
-
- if (file && (fp = fopen(file, "r"))) {
- if ((fgetc(fp) == '\n' && fgetc(fp) == EOF) || feof(fp)) {
- fclose(fp);
- return 1;
- } else {
- fclose(fp);
- return 0;
- }
- }
-
- return -1;
+ FILE *fp;
+
+ if (file && (fp = fopen(file, "r"))) {
+ if ((fgetc(fp) == '\n' && fgetc(fp) == EOF) || feof(fp)) {
+ fclose(fp);
+ return 1;
+ } else {
+ fclose(fp);
+ return 0;
+ }
+ }
+
+ return -1;
}
/*
@@ -1254,27 +1314,28 @@ int io_file_is_empty(char *file)
*/
int io_file_cp(const char *src, const char *dst)
{
- FILE *fp_src, *fp_dst;
- char *buffer[BUFSIZ];
- unsigned int bytes_read;
-
- if (!(fp_src = fopen(src, "rb")))
- return 0;
- if (!(fp_dst = fopen(dst, "wb")))
- return 0;
-
- while (!feof(fp_src)) {
- bytes_read = fread(buffer, 1, BUFSIZ, fp_src);
- if (bytes_read > 0) {
- if (fwrite(buffer, 1, bytes_read, fp_dst) != bytes_read)
- return 0;
- } else {
- return 0;
- }
- }
-
- fclose(fp_dst);
- fclose(fp_src);
-
- return 1;
+ FILE *fp_src, *fp_dst;
+ char *buffer[BUFSIZ];
+ unsigned int bytes_read;
+
+ if (!(fp_src = fopen(src, "rb")))
+ return 0;
+ if (!(fp_dst = fopen(dst, "wb")))
+ return 0;
+
+ while (!feof(fp_src)) {
+ bytes_read = fread(buffer, 1, BUFSIZ, fp_src);
+ if (bytes_read > 0) {
+ if (fwrite(buffer, 1, bytes_read, fp_dst) !=
+ bytes_read)
+ return 0;
+ } else {
+ return 0;
+ }
+ }
+
+ fclose(fp_dst);
+ fclose(fp_src);
+
+ return 1;
}
diff --git a/src/keys.c b/src/keys.c
index f4b81c7..0ef3085 100644
--- a/src/keys.c
+++ b/src/keys.c
@@ -39,406 +39,416 @@
#include "calcurse.h"
-#define MAXKEYVAL KEY_MAX /* ncurses defines KEY_MAX as maximum key value */
+#define MAXKEYVAL KEY_MAX /* ncurses defines KEY_MAX as maximum key value */
struct keydef_s {
- const char *label;
- const char *binding;
+ const char *label;
+ const char *binding;
};
static llist_t keys[NBKEYS];
static enum key actions[MAXKEYVAL];
static struct keydef_s keydef[NBKEYS] = {
- {"generic-cancel", "ESC"},
- {"generic-select", "SPC"},
- {"generic-credits", "@"},
- {"generic-help", "?"},
- {"generic-quit", "q Q"},
- {"generic-save", "s S C-s"},
- {"generic-copy", "c"},
- {"generic-paste", "p C-v"},
- {"generic-change-view", "TAB"},
- {"generic-import", "i I"},
- {"generic-export", "x X"},
- {"generic-goto", "g G"},
- {"generic-other-cmd", "o O"},
- {"generic-config-menu", "C"},
- {"generic-redraw", "C-r"},
- {"generic-add-appt", "C-a"},
- {"generic-add-todo", "C-t"},
- {"generic-prev-day", "T C-h"},
- {"generic-next-day", "t C-l"},
- {"generic-prev-week", "W C-k"},
- {"generic-next-week", "w C-j"},
- {"generic-prev-month", "M"},
- {"generic-next-month", "m"},
- {"generic-prev-year", "Y"},
- {"generic-next-year", "y"},
- {"generic-scroll-down", "C-n"},
- {"generic-scroll-up", "C-p"},
- {"generic-goto-today", "C-g"},
-
- {"move-right", "l L RGT"},
- {"move-left", "h H LFT"},
- {"move-down", "j J DWN"},
- {"move-up", "k K UP"},
- {"start-of-week", "0"},
- {"end-of-week", "$"},
- {"add-item", "a A"},
- {"del-item", "d D"},
- {"edit-item", "e E"},
- {"view-item", "v V"},
- {"pipe-item", "|"},
- {"flag-item", "!"},
- {"repeat", "r R"},
- {"edit-note", "n N"},
- {"view-note", ">"},
- {"raise-priority", "+"},
- {"lower-priority", "-"},
+ {"generic-cancel", "ESC"},
+ {"generic-select", "SPC"},
+ {"generic-credits", "@"},
+ {"generic-help", "?"},
+ {"generic-quit", "q Q"},
+ {"generic-save", "s S C-s"},
+ {"generic-copy", "c"},
+ {"generic-paste", "p C-v"},
+ {"generic-change-view", "TAB"},
+ {"generic-import", "i I"},
+ {"generic-export", "x X"},
+ {"generic-goto", "g G"},
+ {"generic-other-cmd", "o O"},
+ {"generic-config-menu", "C"},
+ {"generic-redraw", "C-r"},
+ {"generic-add-appt", "C-a"},
+ {"generic-add-todo", "C-t"},
+ {"generic-prev-day", "T C-h"},
+ {"generic-next-day", "t C-l"},
+ {"generic-prev-week", "W C-k"},
+ {"generic-next-week", "w C-j"},
+ {"generic-prev-month", "M"},
+ {"generic-next-month", "m"},
+ {"generic-prev-year", "Y"},
+ {"generic-next-year", "y"},
+ {"generic-scroll-down", "C-n"},
+ {"generic-scroll-up", "C-p"},
+ {"generic-goto-today", "C-g"},
+
+ {"move-right", "l L RGT"},
+ {"move-left", "h H LFT"},
+ {"move-down", "j J DWN"},
+ {"move-up", "k K UP"},
+ {"start-of-week", "0"},
+ {"end-of-week", "$"},
+ {"add-item", "a A"},
+ {"del-item", "d D"},
+ {"edit-item", "e E"},
+ {"view-item", "v V"},
+ {"pipe-item", "|"},
+ {"flag-item", "!"},
+ {"repeat", "r R"},
+ {"edit-note", "n N"},
+ {"view-note", ">"},
+ {"raise-priority", "+"},
+ {"lower-priority", "-"},
};
static void dump_intro(FILE * fd)
{
- const char *intro =
- _("#\n"
- "# Calcurse keys configuration file\n#\n"
- "# This file sets the keybindings used by Calcurse.\n"
- "# Lines beginning with \"#\" are comments, and ignored by Calcurse.\n"
- "# To assign a keybinding to an action, this file must contain a line\n"
- "# with the following syntax:\n#\n"
- "# ACTION KEY1 KEY2 ... KEYn\n#\n"
- "# Where ACTION is what will be performed when KEY1, KEY2, ..., or KEYn\n"
- "# will be pressed.\n"
- "#\n"
- "# To define bindings which use the CONTROL key, prefix the key with "
- "'C-'.\n"
- "# The escape, space bar and horizontal Tab key can be specified using\n"
- "# the 'ESC', 'SPC' and 'TAB' keyword, respectively.\n"
- "# Arrow keys can also be specified with the UP, DWN, LFT, RGT keywords.\n"
- "# Last, Home and End keys can be assigned using 'KEY_HOME' and 'KEY_END'\n"
- "# keywords."
- "\n#\n"
- "# A description of what each ACTION keyword is used for is available\n"
- "# from calcurse online configuration menu.\n");
-
- fprintf(fd, "%s\n", intro);
+ const char *intro =
+ _("#\n"
+ "# Calcurse keys configuration file\n#\n"
+ "# This file sets the keybindings used by Calcurse.\n"
+ "# Lines beginning with \"#\" are comments, and ignored by Calcurse.\n"
+ "# To assign a keybinding to an action, this file must contain a line\n"
+ "# with the following syntax:\n#\n"
+ "# ACTION KEY1 KEY2 ... KEYn\n#\n"
+ "# Where ACTION is what will be performed when KEY1, KEY2, ..., or KEYn\n"
+ "# will be pressed.\n"
+ "#\n"
+ "# To define bindings which use the CONTROL key, prefix the key with "
+ "'C-'.\n"
+ "# The escape, space bar and horizontal Tab key can be specified using\n"
+ "# the 'ESC', 'SPC' and 'TAB' keyword, respectively.\n"
+ "# Arrow keys can also be specified with the UP, DWN, LFT, RGT keywords.\n"
+ "# Last, Home and End keys can be assigned using 'KEY_HOME' and 'KEY_END'\n"
+ "# keywords."
+ "\n#\n"
+ "# A description of what each ACTION keyword is used for is available\n"
+ "# from calcurse online configuration menu.\n");
+
+ fprintf(fd, "%s\n", intro);
}
void keys_init(void)
{
- int i;
+ int i;
- for (i = 0; i < MAXKEYVAL; i++)
- actions[i] = KEY_UNDEF;
- for (i = 0; i < NBKEYS; i++)
- LLIST_INIT(&keys[i]);
+ for (i = 0; i < MAXKEYVAL; i++)
+ actions[i] = KEY_UNDEF;
+ for (i = 0; i < NBKEYS; i++)
+ LLIST_INIT(&keys[i]);
}
static void key_free(char *s)
{
- mem_free(s);
+ mem_free(s);
}
void keys_free(void)
{
- int i;
+ int i;
- for (i = 0; i < NBKEYS; i++) {
- LLIST_FREE_INNER(&keys[i], key_free);
- LLIST_FREE(&keys[i]);
- }
+ for (i = 0; i < NBKEYS; i++) {
+ LLIST_FREE_INNER(&keys[i], key_free);
+ LLIST_FREE(&keys[i]);
+ }
}
void keys_dump_defaults(char *file)
{
- FILE *fd;
- int i;
-
- fd = fopen(file, "w");
- EXIT_IF(fd == NULL, _("FATAL ERROR: could not create default keys file."));
-
- dump_intro(fd);
- for (i = 0; i < NBKEYS; i++)
- fprintf(fd, "%s %s\n", keydef[i].label, keydef[i].binding);
- file_close(fd, __FILE_POS__);
+ FILE *fd;
+ int i;
+
+ fd = fopen(file, "w");
+ EXIT_IF(fd == NULL,
+ _("FATAL ERROR: could not create default keys file."));
+
+ dump_intro(fd);
+ for (i = 0; i < NBKEYS; i++)
+ fprintf(fd, "%s %s\n", keydef[i].label,
+ keydef[i].binding);
+ file_close(fd, __FILE_POS__);
}
const char *keys_get_label(enum key key)
{
- EXIT_IF(key < 0 || key > NBKEYS, _("FATAL ERROR: key value out of bounds"));
+ EXIT_IF(key < 0
+ || key > NBKEYS,
+ _("FATAL ERROR: key value out of bounds"));
- return keydef[key].label;
+ return keydef[key].label;
}
enum key keys_get_action(int pressed)
{
- if (pressed < 0 || pressed > MAXKEYVAL)
- return -1;
- else
- return actions[pressed];
+ if (pressed < 0 || pressed > MAXKEYVAL)
+ return -1;
+ else
+ return actions[pressed];
}
enum key keys_getch(WINDOW * win, int *count, int *reg)
{
- int ch = '0';
-
- if (count && reg) {
- *count = 0;
- *reg = 0;
- do {
- *count = *count * 10 + ch - '0';
- ch = wgetch(win);
- }
- while ((ch == '0' && *count > 0) || (ch >= '1' && ch <= '9'));
-
- if (*count == 0)
- *count = 1;
-
- if (ch == '"') {
- ch = wgetch(win);
- if (ch >= '1' && ch <= '9') {
- *reg = ch - '1' + 1;
- } else if (ch >= 'a' && ch <= 'z') {
- *reg = ch - 'a' + 10;
- } else if (ch == '_') {
- *reg = REG_BLACK_HOLE;
- }
- ch = wgetch(win);
- }
- } else {
- ch = wgetch(win);
- }
-
- switch (ch) {
- case KEY_RESIZE:
- return KEY_RESIZE;
- default:
- return keys_get_action(ch);
- }
+ int ch = '0';
+
+ if (count && reg) {
+ *count = 0;
+ *reg = 0;
+ do {
+ *count = *count * 10 + ch - '0';
+ ch = wgetch(win);
+ }
+ while ((ch == '0' && *count > 0)
+ || (ch >= '1' && ch <= '9'));
+
+ if (*count == 0)
+ *count = 1;
+
+ if (ch == '"') {
+ ch = wgetch(win);
+ if (ch >= '1' && ch <= '9') {
+ *reg = ch - '1' + 1;
+ } else if (ch >= 'a' && ch <= 'z') {
+ *reg = ch - 'a' + 10;
+ } else if (ch == '_') {
+ *reg = REG_BLACK_HOLE;
+ }
+ ch = wgetch(win);
+ }
+ } else {
+ ch = wgetch(win);
+ }
+
+ switch (ch) {
+ case KEY_RESIZE:
+ return KEY_RESIZE;
+ default:
+ return keys_get_action(ch);
+ }
}
static void add_key_str(enum key action, int key)
{
- if (action > NBKEYS)
- return;
+ if (action > NBKEYS)
+ return;
- LLIST_ADD(&keys[action], mem_strdup(keys_int2str(key)));
+ LLIST_ADD(&keys[action], mem_strdup(keys_int2str(key)));
}
int keys_assign_binding(int key, enum key action)
{
- if (key < 0 || key > MAXKEYVAL || actions[key] != KEY_UNDEF) {
- return 1;
- } else {
- actions[key] = action;
- add_key_str(action, key);
- }
-
- return 0;
+ if (key < 0 || key > MAXKEYVAL || actions[key] != KEY_UNDEF) {
+ return 1;
+ } else {
+ actions[key] = action;
+ add_key_str(action, key);
+ }
+
+ return 0;
}
static void del_key_str(enum key action, int key)
{
- llist_item_t *i;
- char oldstr[BUFSIZ];
+ llist_item_t *i;
+ char oldstr[BUFSIZ];
- if (action > NBKEYS)
- return;
+ if (action > NBKEYS)
+ return;
- strncpy(oldstr, keys_int2str(key), BUFSIZ);
+ strncpy(oldstr, keys_int2str(key), BUFSIZ);
- LLIST_FOREACH(&keys[action], i) {
- if (strcmp(LLIST_GET_DATA(i), oldstr) == 0) {
- LLIST_REMOVE(&keys[action], i);
- return;
- }
- }
+ LLIST_FOREACH(&keys[action], i) {
+ if (strcmp(LLIST_GET_DATA(i), oldstr) == 0) {
+ LLIST_REMOVE(&keys[action], i);
+ return;
+ }
+ }
}
void keys_remove_binding(int key, enum key action)
{
- if (key >= 0 && key <= MAXKEYVAL) {
- actions[key] = KEY_UNDEF;
- del_key_str(action, key);
- }
+ if (key >= 0 && key <= MAXKEYVAL) {
+ actions[key] = KEY_UNDEF;
+ del_key_str(action, key);
+ }
}
int keys_str2int(const char *key)
{
- const char CONTROL_KEY[] = "C-";
- const char TAB_KEY[] = "TAB";
- const char SPACE_KEY[] = "SPC";
- const char ESCAPE_KEY[] = "ESC";
- const char CURSES_KEY_UP[] = "UP";
- const char CURSES_KEY_DOWN[] = "DWN";
- const char CURSES_KEY_LEFT[] = "LFT";
- const char CURSES_KEY_RIGHT[] = "RGT";
- const char CURSES_KEY_HOME[] = "KEY_HOME";
- const char CURSES_KEY_END[] = "KEY_END";
-
- if (!key)
- return -1;
- if (strlen(key) == 1) {
- return (int)key[0];
- } else {
- if (key[0] == '^')
- return CTRL((int)key[1]);
- else if (!strncmp(key, CONTROL_KEY, sizeof(CONTROL_KEY) - 1))
- return CTRL((int)key[sizeof(CONTROL_KEY) - 1]);
- else if (!strcmp(key, TAB_KEY))
- return TAB;
- else if (!strcmp(key, ESCAPE_KEY))
- return ESCAPE;
- else if (!strcmp(key, SPACE_KEY))
- return SPACE;
- else if (!strcmp(key, CURSES_KEY_UP))
- return KEY_UP;
- else if (!strcmp(key, CURSES_KEY_DOWN))
- return KEY_DOWN;
- else if (!strcmp(key, CURSES_KEY_LEFT))
- return KEY_LEFT;
- else if (!strcmp(key, CURSES_KEY_RIGHT))
- return KEY_RIGHT;
- else if (!strcmp(key, CURSES_KEY_HOME))
- return KEY_HOME;
- else if (!strcmp(key, CURSES_KEY_END))
- return KEY_END;
- else
- return -1;
- }
+ const char CONTROL_KEY[] = "C-";
+ const char TAB_KEY[] = "TAB";
+ const char SPACE_KEY[] = "SPC";
+ const char ESCAPE_KEY[] = "ESC";
+ const char CURSES_KEY_UP[] = "UP";
+ const char CURSES_KEY_DOWN[] = "DWN";
+ const char CURSES_KEY_LEFT[] = "LFT";
+ const char CURSES_KEY_RIGHT[] = "RGT";
+ const char CURSES_KEY_HOME[] = "KEY_HOME";
+ const char CURSES_KEY_END[] = "KEY_END";
+
+ if (!key)
+ return -1;
+ if (strlen(key) == 1) {
+ return (int)key[0];
+ } else {
+ if (key[0] == '^')
+ return CTRL((int)key[1]);
+ else if (!strncmp
+ (key, CONTROL_KEY, sizeof(CONTROL_KEY) - 1))
+ return CTRL((int)key[sizeof(CONTROL_KEY) - 1]);
+ else if (!strcmp(key, TAB_KEY))
+ return TAB;
+ else if (!strcmp(key, ESCAPE_KEY))
+ return ESCAPE;
+ else if (!strcmp(key, SPACE_KEY))
+ return SPACE;
+ else if (!strcmp(key, CURSES_KEY_UP))
+ return KEY_UP;
+ else if (!strcmp(key, CURSES_KEY_DOWN))
+ return KEY_DOWN;
+ else if (!strcmp(key, CURSES_KEY_LEFT))
+ return KEY_LEFT;
+ else if (!strcmp(key, CURSES_KEY_RIGHT))
+ return KEY_RIGHT;
+ else if (!strcmp(key, CURSES_KEY_HOME))
+ return KEY_HOME;
+ else if (!strcmp(key, CURSES_KEY_END))
+ return KEY_END;
+ else
+ return -1;
+ }
}
const char *keys_int2str(int key)
{
- switch (key) {
- case TAB:
- return "TAB";
- case SPACE:
- return "SPC";
- case ESCAPE:
- return "ESC";
- case KEY_UP:
- return "UP";
- case KEY_DOWN:
- return "DWN";
- case KEY_LEFT:
- return "LFT";
- case KEY_RIGHT:
- return "RGT";
- case KEY_HOME:
- return "KEY_HOME";
- case KEY_END:
- return "KEY_END";
- default:
- return (char *)keyname(key);
- }
+ switch (key) {
+ case TAB:
+ return "TAB";
+ case SPACE:
+ return "SPC";
+ case ESCAPE:
+ return "ESC";
+ case KEY_UP:
+ return "UP";
+ case KEY_DOWN:
+ return "DWN";
+ case KEY_LEFT:
+ return "LFT";
+ case KEY_RIGHT:
+ return "RGT";
+ case KEY_HOME:
+ return "KEY_HOME";
+ case KEY_END:
+ return "KEY_END";
+ default:
+ return (char *)keyname(key);
+ }
}
int keys_action_count_keys(enum key action)
{
- llist_item_t *i;
- int n = 0;
+ llist_item_t *i;
+ int n = 0;
- LLIST_FOREACH(&keys[action], i)
- n++;
+ LLIST_FOREACH(&keys[action], i)
+ n++;
- return n;
+ return n;
}
const char *keys_action_firstkey(enum key action)
{
- const char *s = LLIST_GET_DATA(LLIST_FIRST(&keys[action]));
- return (s != NULL) ? s : "XXX";
+ const char *s = LLIST_GET_DATA(LLIST_FIRST(&keys[action]));
+ return (s != NULL) ? s : "XXX";
}
const char *keys_action_nkey(enum key action, int keynum)
{
- return LLIST_GET_DATA(LLIST_NTH(&keys[action], keynum));
+ return LLIST_GET_DATA(LLIST_NTH(&keys[action], keynum));
}
char *keys_action_allkeys(enum key action)
{
- llist_item_t *i;
- static char keystr[BUFSIZ];
- const char *CHAR_SPACE = " ";
+ llist_item_t *i;
+ static char keystr[BUFSIZ];
+ const char *CHAR_SPACE = " ";
- if (!LLIST_FIRST(&keys[action]))
- return NULL;
+ if (!LLIST_FIRST(&keys[action]))
+ return NULL;
- keystr[0] = '\0';
- LLIST_FOREACH(&keys[action], i) {
- const int MAXLEN = sizeof(keystr) - 1 - strlen(keystr);
- strncat(keystr, LLIST_GET_DATA(i), MAXLEN - 1);
- strncat(keystr, CHAR_SPACE, 1);
- }
+ keystr[0] = '\0';
+ LLIST_FOREACH(&keys[action], i) {
+ const int MAXLEN = sizeof(keystr) - 1 - strlen(keystr);
+ strncat(keystr, LLIST_GET_DATA(i), MAXLEN - 1);
+ strncat(keystr, CHAR_SPACE, 1);
+ }
- return keystr;
+ return keystr;
}
/* Need this to display keys properly inside status bar. */
static char *keys_format_label(char *key, int keylen)
{
- static char fmtkey[BUFSIZ];
- const int len = strlen(key);
- const char dot = '.';
- int i;
-
- if (keylen > BUFSIZ)
- return NULL;
-
- memset(fmtkey, 0, sizeof(fmtkey));
- if (len == 0) {
- strncpy(fmtkey, "?", sizeof(fmtkey));
- } else if (len <= keylen) {
- for (i = 0; i < keylen - len; i++)
- fmtkey[i] = ' ';
- strncat(fmtkey, key, keylen);
- } else {
- for (i = 0; i < keylen - 1; i++)
- fmtkey[i] = key[i];
- fmtkey[keylen - 1] = dot;
- }
- return fmtkey;
+ static char fmtkey[BUFSIZ];
+ const int len = strlen(key);
+ const char dot = '.';
+ int i;
+
+ if (keylen > BUFSIZ)
+ return NULL;
+
+ memset(fmtkey, 0, sizeof(fmtkey));
+ if (len == 0) {
+ strncpy(fmtkey, "?", sizeof(fmtkey));
+ } else if (len <= keylen) {
+ for (i = 0; i < keylen - len; i++)
+ fmtkey[i] = ' ';
+ strncat(fmtkey, key, keylen);
+ } else {
+ for (i = 0; i < keylen - 1; i++)
+ fmtkey[i] = key[i];
+ fmtkey[keylen - 1] = dot;
+ }
+ return fmtkey;
}
void
-keys_display_bindings_bar(WINDOW * win, struct binding *bindings[], int count,
- int page_base, int page_size, struct binding *more)
+keys_display_bindings_bar(WINDOW * win, struct binding *bindings[],
+ int count, int page_base, int page_size,
+ struct binding *more)
{
- /* Padding between two key bindings. */
- const int padding = (col * 2) / page_size - (KEYS_KEYLEN + KEYS_LABELEN + 1);
- /* Total length of a key binding (including padding). */
- const int cmd_len = KEYS_KEYLEN + KEYS_LABELEN + 1 + padding;
-
- int i;
-
- wins_erase_status_bar();
- for (i = 0; i < page_size && page_base + i < count; i++) {
- /* Location of key and label. */
- const int key_pos_x = (i / 2) * cmd_len;
- const int key_pos_y = i % 2;
- const int label_pos_x = key_pos_x + KEYS_KEYLEN + 1;
- const int label_pos_y = key_pos_y;
-
- struct binding *binding;
- char key[KEYS_KEYLEN + 1], *fmtkey;
-
- if (!more || i < page_size - 1 || page_base + i == count - 1)
- binding = bindings[page_base + i];
- else
- binding = more;
-
- strncpy(key, keys_action_firstkey(binding->action), KEYS_KEYLEN);
- key[KEYS_KEYLEN] = '\0';
- fmtkey = keys_format_label(key, KEYS_KEYLEN);
-
- custom_apply_attr(win, ATTR_HIGHEST);
- mvwaddstr(win, key_pos_y, key_pos_x, fmtkey);
- custom_remove_attr(win, ATTR_HIGHEST);
- mvwaddstr(win, label_pos_y, label_pos_x, binding->label);
- }
- wnoutrefresh(win);
+ /* Padding between two key bindings. */
+ const int padding =
+ (col * 2) / page_size - (KEYS_KEYLEN + KEYS_LABELEN + 1);
+ /* Total length of a key binding (including padding). */
+ const int cmd_len = KEYS_KEYLEN + KEYS_LABELEN + 1 + padding;
+
+ int i;
+
+ wins_erase_status_bar();
+ for (i = 0; i < page_size && page_base + i < count; i++) {
+ /* Location of key and label. */
+ const int key_pos_x = (i / 2) * cmd_len;
+ const int key_pos_y = i % 2;
+ const int label_pos_x = key_pos_x + KEYS_KEYLEN + 1;
+ const int label_pos_y = key_pos_y;
+
+ struct binding *binding;
+ char key[KEYS_KEYLEN + 1], *fmtkey;
+
+ if (!more || i < page_size - 1
+ || page_base + i == count - 1)
+ binding = bindings[page_base + i];
+ else
+ binding = more;
+
+ strncpy(key, keys_action_firstkey(binding->action),
+ KEYS_KEYLEN);
+ key[KEYS_KEYLEN] = '\0';
+ fmtkey = keys_format_label(key, KEYS_KEYLEN);
+
+ custom_apply_attr(win, ATTR_HIGHEST);
+ mvwaddstr(win, key_pos_y, key_pos_x, fmtkey);
+ custom_remove_attr(win, ATTR_HIGHEST);
+ mvwaddstr(win, label_pos_y, label_pos_x, binding->label);
+ }
+ wnoutrefresh(win);
}
/*
@@ -447,155 +457,161 @@ keys_display_bindings_bar(WINDOW * win, struct binding *bindings[], int count,
*/
void keys_popup_info(enum key key)
{
- char *info[NBKEYS];
- WINDOW *infowin;
-
- info[KEY_GENERIC_CANCEL] = _("Cancel the ongoing action.");
- info[KEY_GENERIC_SELECT] = _("Select the highlighted item.");
- info[KEY_GENERIC_CREDITS] =
- _("Print general information about calcurse's authors, license, etc.");
- info[KEY_GENERIC_HELP] =
- _("Display hints whenever some help screens are available.");
- info[KEY_GENERIC_QUIT] = _("Exit from the current menu, or quit calcurse.");
- info[KEY_GENERIC_SAVE] = _("Save calcurse data.");
- info[KEY_GENERIC_COPY] = _("Copy the item that is currently selected.");
- info[KEY_GENERIC_PASTE] = _("Paste an item at the current position.");
- info[KEY_GENERIC_CHANGE_VIEW] =
- _("Select next panel in calcurse main screen.");
- info[KEY_GENERIC_IMPORT] = _("Import data from an external file.");
- info[KEY_GENERIC_EXPORT] = _("Export data to a new file format.");
- info[KEY_GENERIC_GOTO] = _("Select the day to go to.");
- info[KEY_GENERIC_OTHER_CMD] =
- _("Show next possible actions inside status bar.");
- info[KEY_GENERIC_CONFIG_MENU] = _("Enter the configuration menu.");
- info[KEY_GENERIC_REDRAW] = _("Redraw calcurse's screen.");
- info[KEY_GENERIC_ADD_APPT] =
- _("Add an appointment, whichever panel is currently selected.");
- info[KEY_GENERIC_ADD_TODO] =
- _("Add a todo item, whichever panel is currently selected.");
- info[KEY_GENERIC_PREV_DAY] =
- _("Move to previous day in calendar, whichever panel is currently "
- "selected.");
- info[KEY_GENERIC_NEXT_DAY] =
- _("Move to next day in calendar, whichever panel is currently selected.");
- info[KEY_GENERIC_PREV_WEEK] =
- _("Move to previous week in calendar, whichever panel is currently "
- "selected");
- info[KEY_GENERIC_NEXT_WEEK] =
- _
- ("Move to next week in calendar, whichever panel is currently selected.");
- info[KEY_GENERIC_PREV_MONTH] =
- _("Move to previous month in calendar, whichever panel is currently "
- "selected");
- info[KEY_GENERIC_NEXT_MONTH] =
- _
- ("Move to next month in calendar, whichever panel is currently "
- "selected.");
- info[KEY_GENERIC_PREV_YEAR] =
- _("Move to previous year in calendar, whichever panel is currently "
- "selected");
- info[KEY_GENERIC_NEXT_YEAR] =
- _
- ("Move to next year in calendar, whichever panel is currently selected.");
- info[KEY_GENERIC_SCROLL_DOWN] =
- _
- ("Scroll window down (e.g. when displaying text inside a popup window).");
- info[KEY_GENERIC_SCROLL_UP] =
- _("Scroll window up (e.g. when displaying text inside a popup window).");
- info[KEY_GENERIC_GOTO_TODAY] = _("Go to today, whichever panel is selected.");
- info[KEY_MOVE_RIGHT] = _("Move to the right.");
- info[KEY_MOVE_LEFT] = _("Move to the left.");
- info[KEY_MOVE_DOWN] = _("Move down.");
- info[KEY_MOVE_UP] = _("Move up.");
- info[KEY_START_OF_WEEK] =
- _("Select the first day of the current week when inside the calendar "
- "panel.");
- info[KEY_END_OF_WEEK] =
- _("Select the last day of the current week when inside the calendar "
- "panel.");
- info[KEY_ADD_ITEM] = _("Add an item to the currently selected panel.");
- info[KEY_DEL_ITEM] = _("Delete the currently selected item.");
- info[KEY_EDIT_ITEM] = _("Edit the currently seleted item.");
- info[KEY_VIEW_ITEM] =
- _("Display the currently selected item inside a popup window.");
- info[KEY_FLAG_ITEM] = _("Flag the currently selected item as important.");
- info[KEY_REPEAT_ITEM] = _("Repeat an item");
- info[KEY_PIPE_ITEM] =
- _("Pipe the currently selected item to an external program.");
- info[KEY_EDIT_NOTE] =
- _("Attach (or edit if one exists) a note to the currently selected item");
- info[KEY_VIEW_NOTE] =
- _("View the note attached to the currently selected item.");
- info[KEY_RAISE_PRIORITY] = _("Raise a task priority inside the todo panel.");
- info[KEY_LOWER_PRIORITY] = _("Lower a task priority inside the todo panel.");
-
- if (key > NBKEYS)
- return;
+ char *info[NBKEYS];
+ WINDOW *infowin;
+
+ info[KEY_GENERIC_CANCEL] = _("Cancel the ongoing action.");
+ info[KEY_GENERIC_SELECT] = _("Select the highlighted item.");
+ info[KEY_GENERIC_CREDITS] =
+ _("Print general information about calcurse's authors, license, etc.");
+ info[KEY_GENERIC_HELP] =
+ _("Display hints whenever some help screens are available.");
+ info[KEY_GENERIC_QUIT] =
+ _("Exit from the current menu, or quit calcurse.");
+ info[KEY_GENERIC_SAVE] = _("Save calcurse data.");
+ info[KEY_GENERIC_COPY] =
+ _("Copy the item that is currently selected.");
+ info[KEY_GENERIC_PASTE] =
+ _("Paste an item at the current position.");
+ info[KEY_GENERIC_CHANGE_VIEW] =
+ _("Select next panel in calcurse main screen.");
+ info[KEY_GENERIC_IMPORT] = _("Import data from an external file.");
+ info[KEY_GENERIC_EXPORT] = _("Export data to a new file format.");
+ info[KEY_GENERIC_GOTO] = _("Select the day to go to.");
+ info[KEY_GENERIC_OTHER_CMD] =
+ _("Show next possible actions inside status bar.");
+ info[KEY_GENERIC_CONFIG_MENU] = _("Enter the configuration menu.");
+ info[KEY_GENERIC_REDRAW] = _("Redraw calcurse's screen.");
+ info[KEY_GENERIC_ADD_APPT] =
+ _("Add an appointment, whichever panel is currently selected.");
+ info[KEY_GENERIC_ADD_TODO] =
+ _("Add a todo item, whichever panel is currently selected.");
+ info[KEY_GENERIC_PREV_DAY] =
+ _("Move to previous day in calendar, whichever panel is currently "
+ "selected.");
+ info[KEY_GENERIC_NEXT_DAY] =
+ _("Move to next day in calendar, whichever panel is currently selected.");
+ info[KEY_GENERIC_PREV_WEEK] =
+ _("Move to previous week in calendar, whichever panel is currently "
+ "selected");
+ info[KEY_GENERIC_NEXT_WEEK] =
+ _("Move to next week in calendar, whichever panel is currently selected.");
+ info[KEY_GENERIC_PREV_MONTH] =
+ _("Move to previous month in calendar, whichever panel is currently "
+ "selected");
+ info[KEY_GENERIC_NEXT_MONTH] =
+ _("Move to next month in calendar, whichever panel is currently "
+ "selected.");
+ info[KEY_GENERIC_PREV_YEAR] =
+ _("Move to previous year in calendar, whichever panel is currently "
+ "selected");
+ info[KEY_GENERIC_NEXT_YEAR] =
+ _("Move to next year in calendar, whichever panel is currently selected.");
+ info[KEY_GENERIC_SCROLL_DOWN] =
+ _("Scroll window down (e.g. when displaying text inside a popup window).");
+ info[KEY_GENERIC_SCROLL_UP] =
+ _("Scroll window up (e.g. when displaying text inside a popup window).");
+ info[KEY_GENERIC_GOTO_TODAY] =
+ _("Go to today, whichever panel is selected.");
+ info[KEY_MOVE_RIGHT] = _("Move to the right.");
+ info[KEY_MOVE_LEFT] = _("Move to the left.");
+ info[KEY_MOVE_DOWN] = _("Move down.");
+ info[KEY_MOVE_UP] = _("Move up.");
+ info[KEY_START_OF_WEEK] =
+ _("Select the first day of the current week when inside the calendar "
+ "panel.");
+ info[KEY_END_OF_WEEK] =
+ _("Select the last day of the current week when inside the calendar "
+ "panel.");
+ info[KEY_ADD_ITEM] =
+ _("Add an item to the currently selected panel.");
+ info[KEY_DEL_ITEM] = _("Delete the currently selected item.");
+ info[KEY_EDIT_ITEM] = _("Edit the currently seleted item.");
+ info[KEY_VIEW_ITEM] =
+ _("Display the currently selected item inside a popup window.");
+ info[KEY_FLAG_ITEM] =
+ _("Flag the currently selected item as important.");
+ info[KEY_REPEAT_ITEM] = _("Repeat an item");
+ info[KEY_PIPE_ITEM] =
+ _("Pipe the currently selected item to an external program.");
+ info[KEY_EDIT_NOTE] =
+ _("Attach (or edit if one exists) a note to the currently selected item");
+ info[KEY_VIEW_NOTE] =
+ _("View the note attached to the currently selected item.");
+ info[KEY_RAISE_PRIORITY] =
+ _("Raise a task priority inside the todo panel.");
+ info[KEY_LOWER_PRIORITY] =
+ _("Lower a task priority inside the todo panel.");
+
+ if (key > NBKEYS)
+ return;
#define WINROW 10
#define WINCOL (col - 4)
- infowin = popup(WINROW, WINCOL, (row - WINROW) / 2, (col - WINCOL) / 2,
- keydef[key].label, info[key], 1);
- keys_getch(infowin, NULL, NULL);
- delwin(infowin);
+ infowin =
+ popup(WINROW, WINCOL, (row - WINROW) / 2, (col - WINCOL) / 2,
+ keydef[key].label, info[key], 1);
+ keys_getch(infowin, NULL, NULL);
+ delwin(infowin);
#undef WINROW
#undef WINCOL
}
void keys_save_bindings(FILE * fd)
{
- int i;
- char *action;
-
- EXIT_IF(fd == NULL, _("FATAL ERROR: null file pointer."));
- dump_intro(fd);
- for (i = 0; i < NBKEYS; i++) {
- action = keys_action_allkeys(i);
- if (action)
- fprintf(fd, "%s %s\n", keydef[i].label, action);
- }
+ int i;
+ char *action;
+
+ EXIT_IF(fd == NULL, _("FATAL ERROR: null file pointer."));
+ dump_intro(fd);
+ for (i = 0; i < NBKEYS; i++) {
+ action = keys_action_allkeys(i);
+ if (action)
+ fprintf(fd, "%s %s\n", keydef[i].label, action);
+ }
}
int keys_check_missing_bindings(void)
{
- int i;
+ int i;
- for (i = 0; i < NBKEYS; i++) {
- if (!LLIST_FIRST(&keys[i]))
- return 1;
- }
- return 0;
+ for (i = 0; i < NBKEYS; i++) {
+ if (!LLIST_FIRST(&keys[i]))
+ return 1;
+ }
+ return 0;
}
void keys_fill_missing(void)
{
- int i;
-
- for (i = 0; i < NBKEYS; i++) {
- if (!LLIST_FIRST(&keys[i])) {
- char *p, tmpbuf[BUFSIZ];
-
- strncpy(tmpbuf, keydef[i].binding, BUFSIZ);
- p = tmpbuf;
- for (;;) {
- char key_ch[BUFSIZ];
-
- while (*p == ' ')
- p++;
- if (sscanf(p, "%s", key_ch) == 1) {
- int ch, used;
-
- ch = keys_str2int(key_ch);
- used = keys_assign_binding(ch, i);
- if (used)
- WARN_MSG(_("When adding default key for \"%s\", "
- "\"%s\" was already assigned!"),
- keydef[i].label, key_ch);
- p += strlen(key_ch) + 1;
- } else {
- break;
- }
- }
- }
- }
+ int i;
+
+ for (i = 0; i < NBKEYS; i++) {
+ if (!LLIST_FIRST(&keys[i])) {
+ char *p, tmpbuf[BUFSIZ];
+
+ strncpy(tmpbuf, keydef[i].binding, BUFSIZ);
+ p = tmpbuf;
+ for (;;) {
+ char key_ch[BUFSIZ];
+
+ while (*p == ' ')
+ p++;
+ if (sscanf(p, "%s", key_ch) == 1) {
+ int ch, used;
+
+ ch = keys_str2int(key_ch);
+ used = keys_assign_binding(ch, i);
+ if (used)
+ WARN_MSG(_("When adding default key for \"%s\", "
+ "\"%s\" was already assigned!"),
+ keydef[i].label,
+ key_ch);
+ p += strlen(key_ch) + 1;
+ } else {
+ break;
+ }
+ }
+ }
+ }
}
diff --git a/src/llist.c b/src/llist.c
index 97e57f2..72d1849 100644
--- a/src/llist.c
+++ b/src/llist.c
@@ -41,8 +41,8 @@
*/
void llist_init(llist_t * l)
{
- l->head = NULL;
- l->tail = NULL;
+ l->head = NULL;
+ l->tail = NULL;
}
/*
@@ -50,15 +50,15 @@ void llist_init(llist_t * l)
*/
void llist_free(llist_t * l)
{
- llist_item_t *i, *t;
+ llist_item_t *i, *t;
- for (i = l->head; i; i = t) {
- t = i->next;
- mem_free(i);
- }
+ for (i = l->head; i; i = t) {
+ t = i->next;
+ mem_free(i);
+ }
- l->head = NULL;
- l->tail = NULL;
+ l->head = NULL;
+ l->tail = NULL;
}
/*
@@ -66,14 +66,14 @@ void llist_free(llist_t * l)
*/
void llist_free_inner(llist_t * l, llist_fn_free_t fn_free)
{
- llist_item_t *i;
-
- for (i = l->head; i; i = i->next) {
- if (i->data) {
- fn_free(i->data);
- i->data = NULL;
- }
- }
+ llist_item_t *i;
+
+ for (i = l->head; i; i = i->next) {
+ if (i->data) {
+ fn_free(i->data);
+ i->data = NULL;
+ }
+ }
}
/*
@@ -81,7 +81,7 @@ void llist_free_inner(llist_t * l, llist_fn_free_t fn_free)
*/
llist_item_t *llist_first(llist_t * l)
{
- return l->head;
+ return l->head;
}
/*
@@ -89,15 +89,15 @@ llist_item_t *llist_first(llist_t * l)
*/
llist_item_t *llist_nth(llist_t * l, int n)
{
- llist_item_t *i;
+ llist_item_t *i;
- if (n < 0)
- return NULL;
+ if (n < 0)
+ return NULL;
- for (i = l->head; i && n != 0; n--)
- i = i->next;
+ for (i = l->head; i && n != 0; n--)
+ i = i->next;
- return i;
+ return i;
}
/*
@@ -105,7 +105,7 @@ llist_item_t *llist_nth(llist_t * l, int n)
*/
llist_item_t *llist_next(llist_item_t * i)
{
- return i ? i->next : NULL;
+ return i ? i->next : NULL;
}
/*
@@ -113,12 +113,12 @@ llist_item_t *llist_next(llist_item_t * i)
* callback. Return NULL otherwise.
*/
llist_item_t *llist_next_filter(llist_item_t * i, void *data,
- llist_fn_match_t fn_match)
+ llist_fn_match_t fn_match)
{
- if (i && i->next && fn_match(i->next->data, data))
- return i->next;
- else
- return NULL;
+ if (i && i->next && fn_match(i->next->data, data))
+ return i->next;
+ else
+ return NULL;
}
/*
@@ -126,7 +126,7 @@ llist_item_t *llist_next_filter(llist_item_t * i, void *data,
*/
void *llist_get_data(llist_item_t * i)
{
- return i ? i->data : NULL;
+ return i ? i->data : NULL;
}
/*
@@ -134,19 +134,19 @@ void *llist_get_data(llist_item_t * i)
*/
void llist_add(llist_t * l, void *data)
{
- llist_item_t *o = mem_malloc(sizeof(llist_item_t));
-
- if (o) {
- o->data = data;
- o->next = NULL;
-
- if (!l->head) {
- l->head = l->tail = o;
- } else {
- l->tail->next = o;
- l->tail = o;
- }
- }
+ llist_item_t *o = mem_malloc(sizeof(llist_item_t));
+
+ if (o) {
+ o->data = data;
+ o->next = NULL;
+
+ if (!l->head) {
+ l->head = l->tail = o;
+ } else {
+ l->tail->next = o;
+ l->tail = o;
+ }
+ }
}
/*
@@ -154,29 +154,30 @@ void llist_add(llist_t * l, void *data)
*/
void llist_add_sorted(llist_t * l, void *data, llist_fn_cmp_t fn_cmp)
{
- llist_item_t *o = mem_malloc(sizeof(llist_item_t));
- llist_item_t *i;
-
- if (o) {
- o->data = data;
- o->next = NULL;
-
- if (!l->head) {
- l->head = l->tail = o;
- } else if (fn_cmp(o->data, l->tail->data) >= 0) {
- l->tail->next = o;
- l->tail = o;
- } else if (fn_cmp(o->data, l->head->data) < 0) {
- o->next = l->head;
- l->head = o;
- } else {
- i = l->head;
- while (i->next && fn_cmp(o->data, i->next->data) >= 0)
- i = i->next;
- o->next = i->next;
- i->next = o;
- }
- }
+ llist_item_t *o = mem_malloc(sizeof(llist_item_t));
+ llist_item_t *i;
+
+ if (o) {
+ o->data = data;
+ o->next = NULL;
+
+ if (!l->head) {
+ l->head = l->tail = o;
+ } else if (fn_cmp(o->data, l->tail->data) >= 0) {
+ l->tail->next = o;
+ l->tail = o;
+ } else if (fn_cmp(o->data, l->head->data) < 0) {
+ o->next = l->head;
+ l->head = o;
+ } else {
+ i = l->head;
+ while (i->next
+ && fn_cmp(o->data, i->next->data) >= 0)
+ i = i->next;
+ o->next = i->next;
+ i->next = o;
+ }
+ }
}
/*
@@ -184,93 +185,93 @@ void llist_add_sorted(llist_t * l, void *data, llist_fn_cmp_t fn_cmp)
*/
void llist_remove(llist_t * l, llist_item_t * i)
{
- llist_item_t *j = NULL;
-
- if (l->head && i == l->head) {
- l->head = i->next;
- } else {
- for (j = l->head; j && j->next != i; j = j->next) ;
- }
-
- if (i) {
- if (j)
- j->next = i->next;
- if (i == l->tail)
- l->tail = j;
-
- mem_free(i);
- }
+ llist_item_t *j = NULL;
+
+ if (l->head && i == l->head) {
+ l->head = i->next;
+ } else {
+ for (j = l->head; j && j->next != i; j = j->next) ;
+ }
+
+ if (i) {
+ if (j)
+ j->next = i->next;
+ if (i == l->tail)
+ l->tail = j;
+
+ mem_free(i);
+ }
}
/*
* Find the first item matched by some filter callback.
*/
llist_item_t *llist_find_first(llist_t * l, void *data,
- llist_fn_match_t fn_match)
+ llist_fn_match_t fn_match)
{
- llist_item_t *i;
-
- if (fn_match) {
- for (i = l->head; i; i = i->next) {
- if (fn_match(i->data, data))
- return i;
- }
- } else {
- for (i = l->head; i; i = i->next) {
- if (i->data == data)
- return i;
- }
- }
-
- return NULL;
+ llist_item_t *i;
+
+ if (fn_match) {
+ for (i = l->head; i; i = i->next) {
+ if (fn_match(i->data, data))
+ return i;
+ }
+ } else {
+ for (i = l->head; i; i = i->next) {
+ if (i->data == data)
+ return i;
+ }
+ }
+
+ return NULL;
}
/*
* Find the next item matched by some filter callback.
*/
llist_item_t *llist_find_next(llist_item_t * i, void *data,
- llist_fn_match_t fn_match)
+ llist_fn_match_t fn_match)
{
- if (i) {
- i = i->next;
- if (fn_match) {
- for (; i; i = i->next) {
- if (fn_match(i->data, data))
- return i;
- }
- } else {
- for (; i; i = i->next) {
- if (i->data == data)
- return i;
- }
- }
- }
-
- return NULL;
+ if (i) {
+ i = i->next;
+ if (fn_match) {
+ for (; i; i = i->next) {
+ if (fn_match(i->data, data))
+ return i;
+ }
+ } else {
+ for (; i; i = i->next) {
+ if (i->data == data)
+ return i;
+ }
+ }
+ }
+
+ return NULL;
}
/*
* Find the nth item matched by some filter callback.
*/
llist_item_t *llist_find_nth(llist_t * l, int n, void *data,
- llist_fn_match_t fn_match)
+ llist_fn_match_t fn_match)
{
- llist_item_t *i;
-
- if (n < 0)
- return NULL;
-
- if (fn_match) {
- for (i = l->head; i; i = i->next) {
- if (fn_match(i->data, data) && (n-- == 0))
- return i;
- }
- } else {
- for (i = l->head; i; i = i->next) {
- if ((i->data == data) && (n-- == 0))
- return i;
- }
- }
-
- return NULL;
+ llist_item_t *i;
+
+ if (n < 0)
+ return NULL;
+
+ if (fn_match) {
+ for (i = l->head; i; i = i->next) {
+ if (fn_match(i->data, data) && (n-- == 0))
+ return i;
+ }
+ } else {
+ for (i = l->head; i; i = i->next) {
+ if ((i->data == data) && (n-- == 0))
+ return i;
+ }
+ }
+
+ return NULL;
}
diff --git a/src/llist.h b/src/llist.h
index 7c4d590..9b3a952 100644
--- a/src/llist.h
+++ b/src/llist.h
@@ -37,14 +37,14 @@
/* Linked lists. */
typedef struct llist_item llist_item_t;
struct llist_item {
- struct llist_item *next;
- void *data;
+ struct llist_item *next;
+ void *data;
};
typedef struct llist llist_t;
struct llist {
- struct llist_item *head;
- struct llist_item *tail;
+ struct llist_item *head;
+ struct llist_item *tail;
};
typedef int (*llist_fn_cmp_t) (void *, void *);
diff --git a/src/llist_ts.h b/src/llist_ts.h
index 7663a2d..2c015f1 100644
--- a/src/llist_ts.h
+++ b/src/llist_ts.h
@@ -37,9 +37,9 @@
/* Thread-safe linked lists. */
typedef struct llist_ts llist_ts_t;
struct llist_ts {
- llist_item_t *head;
- llist_item_t *tail;
- pthread_mutex_t mutex;
+ llist_item_t *head;
+ llist_item_t *tail;
+ pthread_mutex_t mutex;
};
/* Initialization and deallocation. */
diff --git a/src/mem.c b/src/mem.c
index 8889cc0..a351818 100644
--- a/src/mem.c
+++ b/src/mem.c
@@ -44,10 +44,10 @@
#ifdef CALCURSE_MEMORY_DEBUG
enum {
- BLK_STATE,
- BLK_SIZE,
- BLK_ID,
- EXTRA_SPACE_START
+ BLK_STATE,
+ BLK_SIZE,
+ BLK_ID,
+ EXTRA_SPACE_START
};
#define EXTRA_SPACE_END 1
@@ -57,14 +57,14 @@ enum {
#define MAGIC_FREE 0xdf
struct mem_blk {
- unsigned id, size;
- const char *pos;
- struct mem_blk *next;
+ unsigned id, size;
+ const char *pos;
+ struct mem_blk *next;
};
struct mem_stats {
- unsigned ncall, nalloc, nfree;
- struct mem_blk *blk;
+ unsigned ncall, nalloc, nfree;
+ struct mem_blk *blk;
};
static struct mem_stats mstats;
@@ -73,229 +73,232 @@ static struct mem_stats mstats;
void *xmalloc(size_t size)
{
- void *p;
+ void *p;
- EXIT_IF(size == 0, _("xmalloc: zero size"));
- p = malloc(size);
- EXIT_IF(p == NULL, _("xmalloc: out of memory"));
+ EXIT_IF(size == 0, _("xmalloc: zero size"));
+ p = malloc(size);
+ EXIT_IF(p == NULL, _("xmalloc: out of memory"));
- return p;
+ return p;
}
void *xcalloc(size_t nmemb, size_t size)
{
- void *p;
+ void *p;
- EXIT_IF(nmemb == 0 || size == 0, _("xcalloc: zero size"));
- EXIT_IF(SIZE_MAX / nmemb < size, _("xcalloc: overflow"));
- p = calloc(nmemb, size);
- EXIT_IF(p == NULL, _("xcalloc: out of memory"));
+ EXIT_IF(nmemb == 0 || size == 0, _("xcalloc: zero size"));
+ EXIT_IF(SIZE_MAX / nmemb < size, _("xcalloc: overflow"));
+ p = calloc(nmemb, size);
+ EXIT_IF(p == NULL, _("xcalloc: out of memory"));
- return p;
+ return p;
}
void *xrealloc(void *ptr, size_t nmemb, size_t size)
{
- void *new_ptr;
- size_t new_size;
+ void *new_ptr;
+ size_t new_size;
- new_size = nmemb * size;
- EXIT_IF(new_size == 0, _("xrealloc: zero size"));
- EXIT_IF(SIZE_MAX / nmemb < size, _("xrealloc: overflow"));
- new_ptr = realloc(ptr, new_size);
- EXIT_IF(new_ptr == NULL, _("xrealloc: out of memory"));
+ new_size = nmemb * size;
+ EXIT_IF(new_size == 0, _("xrealloc: zero size"));
+ EXIT_IF(SIZE_MAX / nmemb < size, _("xrealloc: overflow"));
+ new_ptr = realloc(ptr, new_size);
+ EXIT_IF(new_ptr == NULL, _("xrealloc: out of memory"));
- return new_ptr;
+ return new_ptr;
}
char *xstrdup(const char *str)
{
- size_t len;
- char *cp;
+ size_t len;
+ char *cp;
- len = strlen(str) + 1;
- cp = xmalloc(len);
+ len = strlen(str) + 1;
+ cp = xmalloc(len);
- return strncpy(cp, str, len);
+ return strncpy(cp, str, len);
}
void xfree(void *p)
{
- EXIT_IF(p == NULL, _("xfree: null pointer"));
- free(p);
+ EXIT_IF(p == NULL, _("xfree: null pointer"));
+ free(p);
}
#ifdef CALCURSE_MEMORY_DEBUG
static unsigned stats_add_blk(size_t size, const char *pos)
{
- struct mem_blk *o, **i;
+ struct mem_blk *o, **i;
- o = malloc(sizeof(*o));
- EXIT_IF(o == NULL, _("could not allocate memory to store block info"));
+ o = malloc(sizeof(*o));
+ EXIT_IF(o == NULL,
+ _("could not allocate memory to store block info"));
- mstats.ncall++;
+ mstats.ncall++;
- o->pos = pos;
- o->size = (unsigned)size;
- o->next = 0;
+ o->pos = pos;
+ o->size = (unsigned)size;
+ o->next = 0;
- for (i = &mstats.blk; *i; i = &(*i)->next) ;
- o->id = mstats.ncall;
- *i = o;
+ for (i = &mstats.blk; *i; i = &(*i)->next) ;
+ o->id = mstats.ncall;
+ *i = o;
- return o->id;
+ return o->id;
}
static void stats_del_blk(unsigned id)
{
- struct mem_blk *o, **i;
-
- i = &mstats.blk;
- for (o = mstats.blk; o; o = o->next) {
- if (o->id == id) {
- *i = o->next;
- free(o);
- return;
- }
- i = &o->next;
- }
-
- EXIT(_("Block not found"));
- /* NOTREACHED */
+ struct mem_blk *o, **i;
+
+ i = &mstats.blk;
+ for (o = mstats.blk; o; o = o->next) {
+ if (o->id == id) {
+ *i = o->next;
+ free(o);
+ return;
+ }
+ i = &o->next;
+ }
+
+ EXIT(_("Block not found"));
+ /* NOTREACHED */
}
void *dbg_malloc(size_t size, const char *pos)
{
- unsigned *buf;
+ unsigned *buf;
- if (size == 0)
- return NULL;
+ if (size == 0)
+ return NULL;
- size = EXTRA_SPACE + (size + sizeof(unsigned) - 1) / sizeof(unsigned);
- buf = xmalloc(size * sizeof(unsigned));
+ size =
+ EXTRA_SPACE + (size + sizeof(unsigned) - 1) / sizeof(unsigned);
+ buf = xmalloc(size * sizeof(unsigned));
- buf[BLK_STATE] = MAGIC_ALLOC; /* state of the block */
- buf[BLK_SIZE] = size; /* size of the block */
- buf[BLK_ID] = stats_add_blk(size, pos); /* identify a block by its id */
- buf[size - 1] = buf[BLK_ID]; /* mark at end of block */
+ buf[BLK_STATE] = MAGIC_ALLOC; /* state of the block */
+ buf[BLK_SIZE] = size; /* size of the block */
+ buf[BLK_ID] = stats_add_blk(size, pos); /* identify a block by its id */
+ buf[size - 1] = buf[BLK_ID]; /* mark at end of block */
- mstats.nalloc += size;
+ mstats.nalloc += size;
- return (void *)(buf + EXTRA_SPACE_START);
+ return (void *)(buf + EXTRA_SPACE_START);
}
void *dbg_calloc(size_t nmemb, size_t size, const char *pos)
{
- void *buf;
+ void *buf;
- if (!nmemb || !size)
- return NULL;
+ if (!nmemb || !size)
+ return NULL;
- EXIT_IF(nmemb > SIZE_MAX / size, _("overflow at %s"), pos);
+ EXIT_IF(nmemb > SIZE_MAX / size, _("overflow at %s"), pos);
- size *= nmemb;
- if ((buf = dbg_malloc(size, pos)) == NULL)
- return NULL;
+ size *= nmemb;
+ if ((buf = dbg_malloc(size, pos)) == NULL)
+ return NULL;
- memset(buf, 0, size);
+ memset(buf, 0, size);
- return buf;
+ return buf;
}
void *dbg_realloc(void *ptr, size_t nmemb, size_t size, const char *pos)
{
- unsigned *buf, old_size, new_size, cpy_size;
+ unsigned *buf, old_size, new_size, cpy_size;
- if (ptr == NULL)
- return NULL;
+ if (ptr == NULL)
+ return NULL;
- new_size = nmemb * size;
- if (new_size == 0)
- return NULL;
+ new_size = nmemb * size;
+ if (new_size == 0)
+ return NULL;
- EXIT_IF(nmemb > SIZE_MAX / size, _("overflow at %s"), pos);
+ EXIT_IF(nmemb > SIZE_MAX / size, _("overflow at %s"), pos);
- if ((buf = dbg_malloc(new_size, pos)) == NULL)
- return NULL;
+ if ((buf = dbg_malloc(new_size, pos)) == NULL)
+ return NULL;
- old_size = *((unsigned *)ptr - EXTRA_SPACE_START + BLK_SIZE);
- cpy_size = (old_size > new_size) ? new_size : old_size;
- memmove(buf, ptr, cpy_size);
+ old_size = *((unsigned *)ptr - EXTRA_SPACE_START + BLK_SIZE);
+ cpy_size = (old_size > new_size) ? new_size : old_size;
+ memmove(buf, ptr, cpy_size);
- mem_free(ptr);
+ mem_free(ptr);
- return (void *)buf;
+ return (void *)buf;
}
char *dbg_strdup(const char *s, const char *pos)
{
- size_t size;
- char *buf;
+ size_t size;
+ char *buf;
- if (s == NULL)
- return NULL;
+ if (s == NULL)
+ return NULL;
- size = strlen(s);
- if ((buf = dbg_malloc(size + 1, pos)) == NULL)
- return NULL;
+ size = strlen(s);
+ if ((buf = dbg_malloc(size + 1, pos)) == NULL)
+ return NULL;
- return strncpy(buf, s, size + 1);
+ return strncpy(buf, s, size + 1);
}
void dbg_free(void *ptr, const char *pos)
{
- unsigned *buf, size;
+ unsigned *buf, size;
- EXIT_IF(ptr == NULL, _("dbg_free: null pointer at %s"), pos);
+ EXIT_IF(ptr == NULL, _("dbg_free: null pointer at %s"), pos);
- buf = (unsigned *)ptr - EXTRA_SPACE_START;
- size = buf[BLK_SIZE];
+ buf = (unsigned *)ptr - EXTRA_SPACE_START;
+ size = buf[BLK_SIZE];
- EXIT_IF(buf[BLK_STATE] == MAGIC_FREE,
- _("block seems already freed at %s"), pos);
- EXIT_IF(buf[BLK_STATE] != MAGIC_ALLOC, _("corrupt block header at %s"), pos);
- EXIT_IF(buf[size - 1] != buf[BLK_ID],
- _("corrupt block end at %s, (end = %u, should be %d)"), pos,
- buf[size - 1], buf[BLK_ID]);
+ EXIT_IF(buf[BLK_STATE] == MAGIC_FREE,
+ _("block seems already freed at %s"), pos);
+ EXIT_IF(buf[BLK_STATE] != MAGIC_ALLOC,
+ _("corrupt block header at %s"), pos);
+ EXIT_IF(buf[size - 1] != buf[BLK_ID],
+ _("corrupt block end at %s, (end = %u, should be %d)"),
+ pos, buf[size - 1], buf[BLK_ID]);
- buf[0] = MAGIC_FREE;
+ buf[0] = MAGIC_FREE;
- stats_del_blk(buf[BLK_ID]);
+ stats_del_blk(buf[BLK_ID]);
- free(buf);
- mstats.nfree += size;
+ free(buf);
+ mstats.nfree += size;
}
static void dump_block_info(struct mem_blk *blk)
{
- if (blk == NULL)
- return;
-
- puts(_("---==== MEMORY BLOCK ====----------------\n"));
- printf(_(" id: %u\n"), blk->id);
- printf(_(" size: %u\n"), blk->size);
- printf(_(" allocated in: %s\n"), blk->pos);
- puts(_("-----------------------------------------\n"));
+ if (blk == NULL)
+ return;
+
+ puts(_("---==== MEMORY BLOCK ====----------------\n"));
+ printf(_(" id: %u\n"), blk->id);
+ printf(_(" size: %u\n"), blk->size);
+ printf(_(" allocated in: %s\n"), blk->pos);
+ puts(_("-----------------------------------------\n"));
}
void mem_stats(void)
{
- putchar('\n');
- puts(_("+------------------------------+\n"));
- puts(_("| calcurse memory usage report |\n"));
- puts(_("+------------------------------+\n"));
- printf(_(" number of calls: %u\n"), mstats.ncall);
- printf(_(" allocated blocks: %u\n"), mstats.nalloc);
- printf(_(" unfreed blocks: %u\n"), mstats.nalloc - mstats.nfree);
- putchar('\n');
-
- if (mstats.nfree < mstats.nalloc) {
- struct mem_blk *blk;
-
- for (blk = mstats.blk; blk; blk = blk->next)
- dump_block_info(blk);
- }
+ putchar('\n');
+ puts(_("+------------------------------+\n"));
+ puts(_("| calcurse memory usage report |\n"));
+ puts(_("+------------------------------+\n"));
+ printf(_(" number of calls: %u\n"), mstats.ncall);
+ printf(_(" allocated blocks: %u\n"), mstats.nalloc);
+ printf(_(" unfreed blocks: %u\n"), mstats.nalloc - mstats.nfree);
+ putchar('\n');
+
+ if (mstats.nfree < mstats.nalloc) {
+ struct mem_blk *blk;
+
+ for (blk = mstats.blk; blk; blk = blk->next)
+ dump_block_info(blk);
+ }
}
#endif /* CALCURSE_MEMORY_DEBUG */
diff --git a/src/note.c b/src/note.c
index e8c9fb0..a6e48d7 100644
--- a/src/note.c
+++ b/src/note.c
@@ -41,12 +41,13 @@
#include "sha1.h"
struct note_gc_hash {
- char *hash;
- char buf[MAX_NOTESIZ + 1];
- HTABLE_ENTRY(note_gc_hash);
+ char *hash;
+ char buf[MAX_NOTESIZ + 1];
+ HTABLE_ENTRY(note_gc_hash);
};
-static void note_gc_extract_key(struct note_gc_hash *, const char **, int *);
+static void note_gc_extract_key(struct note_gc_hash *, const char **,
+ int *);
static int note_gc_cmp(struct note_gc_hash *, struct note_gc_hash *);
HTABLE_HEAD(htp, NOTE_GC_HSIZE, note_gc_hash);
@@ -57,179 +58,180 @@ HTABLE_PROTOTYPE(htp, note_gc_hash)
* contains its name. */
char *generate_note(const char *str)
{
- char *sha1 = mem_malloc(SHA1_DIGESTLEN * 2 + 1);
- char notepath[BUFSIZ];
- FILE *fp;
-
- sha1_digest(str, sha1);
- snprintf(notepath, BUFSIZ, "%s%s", path_notes, sha1);
- fp = fopen(notepath, "w");
- EXIT_IF(fp == NULL, _("Warning: could not open %s, Aborting..."), notepath);
- fputs(str, fp);
- file_close(fp, __FILE_POS__);
-
- return sha1;
+ char *sha1 = mem_malloc(SHA1_DIGESTLEN * 2 + 1);
+ char notepath[BUFSIZ];
+ FILE *fp;
+
+ sha1_digest(str, sha1);
+ snprintf(notepath, BUFSIZ, "%s%s", path_notes, sha1);
+ fp = fopen(notepath, "w");
+ EXIT_IF(fp == NULL, _("Warning: could not open %s, Aborting..."),
+ notepath);
+ fputs(str, fp);
+ file_close(fp, __FILE_POS__);
+
+ return sha1;
}
/* Edit a note with an external editor. */
void edit_note(char **note, const char *editor)
{
- char tmppath[BUFSIZ];
- char *tmpext;
- char notepath[BUFSIZ];
- char *sha1 = mem_malloc(SHA1_DIGESTLEN * 2 + 1);
- FILE *fp;
-
- strncpy(tmppath, get_tempdir(), BUFSIZ);
- strncat(tmppath, "/calcurse-note.", BUFSIZ - strlen(tmppath) - 1);
- if ((tmpext = new_tempfile(tmppath, TMPEXTSIZ)) == NULL)
- return;
- strncat(tmppath, tmpext, BUFSIZ - strlen(tmppath) - 1);
- mem_free(tmpext);
-
- if (*note != NULL) {
- snprintf(notepath, BUFSIZ, "%s%s", path_notes, *note);
- io_file_cp(notepath, tmppath);
- }
-
- wins_launch_external(tmppath, editor);
-
- if (io_file_is_empty(tmppath) > 0) {
- erase_note(note);
- } else if ((fp = fopen(tmppath, "r"))) {
- sha1_stream(fp, sha1);
- fclose(fp);
- *note = sha1;
-
- snprintf(notepath, BUFSIZ, "%s%s", path_notes, *note);
- io_file_cp(tmppath, notepath);
- }
-
- unlink(tmppath);
+ char tmppath[BUFSIZ];
+ char *tmpext;
+ char notepath[BUFSIZ];
+ char *sha1 = mem_malloc(SHA1_DIGESTLEN * 2 + 1);
+ FILE *fp;
+
+ strncpy(tmppath, get_tempdir(), BUFSIZ);
+ strncat(tmppath, "/calcurse-note.", BUFSIZ - strlen(tmppath) - 1);
+ if ((tmpext = new_tempfile(tmppath, TMPEXTSIZ)) == NULL)
+ return;
+ strncat(tmppath, tmpext, BUFSIZ - strlen(tmppath) - 1);
+ mem_free(tmpext);
+
+ if (*note != NULL) {
+ snprintf(notepath, BUFSIZ, "%s%s", path_notes, *note);
+ io_file_cp(notepath, tmppath);
+ }
+
+ wins_launch_external(tmppath, editor);
+
+ if (io_file_is_empty(tmppath) > 0) {
+ erase_note(note);
+ } else if ((fp = fopen(tmppath, "r"))) {
+ sha1_stream(fp, sha1);
+ fclose(fp);
+ *note = sha1;
+
+ snprintf(notepath, BUFSIZ, "%s%s", path_notes, *note);
+ io_file_cp(tmppath, notepath);
+ }
+
+ unlink(tmppath);
}
/* View a note in an external pager. */
void view_note(const char *note, const char *pager)
{
- char fullname[BUFSIZ];
+ char fullname[BUFSIZ];
- if (note == NULL)
- return;
- snprintf(fullname, BUFSIZ, "%s%s", path_notes, note);
- wins_launch_external(fullname, pager);
+ if (note == NULL)
+ return;
+ snprintf(fullname, BUFSIZ, "%s%s", path_notes, note);
+ wins_launch_external(fullname, pager);
}
/* Erase a note previously attached to an item. */
void erase_note(char **note)
{
- if (*note == NULL)
- return;
- mem_free(*note);
- *note = NULL;
+ if (*note == NULL)
+ return;
+ mem_free(*note);
+ *note = NULL;
}
/* Read a serialized note file name from a stream and deserialize it. */
void note_read(char *buffer, FILE * fp)
{
- int i;
-
- for (i = 0; i < MAX_NOTESIZ; i++) {
- buffer[i] = getc(fp);
- if (buffer[i] == ' ') {
- buffer[i] = '\0';
- return;
- }
- }
-
- while (getc(fp) != ' ') ;
- buffer[MAX_NOTESIZ] = '\0';
+ int i;
+
+ for (i = 0; i < MAX_NOTESIZ; i++) {
+ buffer[i] = getc(fp);
+ if (buffer[i] == ' ') {
+ buffer[i] = '\0';
+ return;
+ }
+ }
+
+ while (getc(fp) != ' ') ;
+ buffer[MAX_NOTESIZ] = '\0';
}
static void
note_gc_extract_key(struct note_gc_hash *data, const char **key, int *len)
{
- *key = data->hash;
- *len = strlen(data->hash);
+ *key = data->hash;
+ *len = strlen(data->hash);
}
static int note_gc_cmp(struct note_gc_hash *a, struct note_gc_hash *b)
{
- return strcmp(a->hash, b->hash);
+ return strcmp(a->hash, b->hash);
}
/* Spot and unlink unused note files. */
void note_gc(void)
{
- struct htp gc_htable = HTABLE_INITIALIZER(&gc_htable);
- struct note_gc_hash *hp;
- DIR *dirp;
- struct dirent *dp;
- llist_item_t *i;
- struct note_gc_hash tmph;
- char notepath[BUFSIZ];
-
- if (!(dirp = opendir(path_notes)))
- return;
-
- /* Insert all note file names into a hash table. */
- do {
- if ((dp = readdir(dirp)) && *(dp->d_name) != '.') {
- hp = mem_malloc(sizeof(struct note_gc_hash));
-
- strncpy(hp->buf, dp->d_name, MAX_NOTESIZ + 1);
- hp->hash = hp->buf;
-
- HTABLE_INSERT(htp, &gc_htable, hp);
- }
- }
- while (dp);
-
- closedir(dirp);
-
- /* Remove hashes that are actually in use. */
- LLIST_TS_FOREACH(&alist_p, i) {
- struct apoint *apt = LLIST_GET_DATA(i);
- if (apt->note) {
- tmph.hash = apt->note;
- free(HTABLE_REMOVE(htp, &gc_htable, &tmph));
- }
- }
-
- LLIST_FOREACH(&eventlist, i) {
- struct event *ev = LLIST_GET_DATA(i);
- if (ev->note) {
- tmph.hash = ev->note;
- free(HTABLE_REMOVE(htp, &gc_htable, &tmph));
- }
- }
-
- LLIST_TS_FOREACH(&recur_alist_p, i) {
- struct recur_apoint *rapt = LLIST_GET_DATA(i);
- if (rapt->note) {
- tmph.hash = rapt->note;
- free(HTABLE_REMOVE(htp, &gc_htable, &tmph));
- }
- }
-
- LLIST_FOREACH(&recur_elist, i) {
- struct recur_event *rev = LLIST_GET_DATA(i);
- if (rev->note) {
- tmph.hash = rev->note;
- free(HTABLE_REMOVE(htp, &gc_htable, &tmph));
- }
- }
-
- LLIST_FOREACH(&todolist, i) {
- struct todo *todo = LLIST_GET_DATA(i);
- if (todo->note) {
- tmph.hash = todo->note;
- free(HTABLE_REMOVE(htp, &gc_htable, &tmph));
- }
- }
-
- /* Unlink unused note files. */
- HTABLE_FOREACH(hp, htp, &gc_htable) {
- snprintf(notepath, BUFSIZ, "%s%s", path_notes, hp->hash);
- unlink(notepath);
- }
+ struct htp gc_htable = HTABLE_INITIALIZER(&gc_htable);
+ struct note_gc_hash *hp;
+ DIR *dirp;
+ struct dirent *dp;
+ llist_item_t *i;
+ struct note_gc_hash tmph;
+ char notepath[BUFSIZ];
+
+ if (!(dirp = opendir(path_notes)))
+ return;
+
+ /* Insert all note file names into a hash table. */
+ do {
+ if ((dp = readdir(dirp)) && *(dp->d_name) != '.') {
+ hp = mem_malloc(sizeof(struct note_gc_hash));
+
+ strncpy(hp->buf, dp->d_name, MAX_NOTESIZ + 1);
+ hp->hash = hp->buf;
+
+ HTABLE_INSERT(htp, &gc_htable, hp);
+ }
+ }
+ while (dp);
+
+ closedir(dirp);
+
+ /* Remove hashes that are actually in use. */
+ LLIST_TS_FOREACH(&alist_p, i) {
+ struct apoint *apt = LLIST_GET_DATA(i);
+ if (apt->note) {
+ tmph.hash = apt->note;
+ free(HTABLE_REMOVE(htp, &gc_htable, &tmph));
+ }
+ }
+
+ LLIST_FOREACH(&eventlist, i) {
+ struct event *ev = LLIST_GET_DATA(i);
+ if (ev->note) {
+ tmph.hash = ev->note;
+ free(HTABLE_REMOVE(htp, &gc_htable, &tmph));
+ }
+ }
+
+ LLIST_TS_FOREACH(&recur_alist_p, i) {
+ struct recur_apoint *rapt = LLIST_GET_DATA(i);
+ if (rapt->note) {
+ tmph.hash = rapt->note;
+ free(HTABLE_REMOVE(htp, &gc_htable, &tmph));
+ }
+ }
+
+ LLIST_FOREACH(&recur_elist, i) {
+ struct recur_event *rev = LLIST_GET_DATA(i);
+ if (rev->note) {
+ tmph.hash = rev->note;
+ free(HTABLE_REMOVE(htp, &gc_htable, &tmph));
+ }
+ }
+
+ LLIST_FOREACH(&todolist, i) {
+ struct todo *todo = LLIST_GET_DATA(i);
+ if (todo->note) {
+ tmph.hash = todo->note;
+ free(HTABLE_REMOVE(htp, &gc_htable, &tmph));
+ }
+ }
+
+ /* Unlink unused note files. */
+ HTABLE_FOREACH(hp, htp, &gc_htable) {
+ snprintf(notepath, BUFSIZ, "%s%s", path_notes, hp->hash);
+ unlink(notepath);
+ }
}
diff --git a/src/notify.c b/src/notify.c
index 36aad5a..816da3c 100644
--- a/src/notify.c
+++ b/src/notify.c
@@ -44,11 +44,11 @@
#define NOTIFY_FIELD_LENGTH 25
struct notify_vars {
- WINDOW *win;
- char *apts_file;
- char time[NOTIFY_FIELD_LENGTH];
- char date[NOTIFY_FIELD_LENGTH];
- pthread_mutex_t mutex;
+ WINDOW *win;
+ char *apts_file;
+ char time[NOTIFY_FIELD_LENGTH];
+ char date[NOTIFY_FIELD_LENGTH];
+ pthread_mutex_t mutex;
};
static struct notify_vars notify;
@@ -62,13 +62,13 @@ static pthread_t notify_t_main;
*/
int notify_time_left(void)
{
- time_t ntimer;
- int left;
+ time_t ntimer;
+ int left;
- ntimer = time(NULL);
- left = notify_app.time - ntimer;
+ ntimer = time(NULL);
+ left = notify_app.time - ntimer;
- return left > 0 ? left : 0;
+ return left > 0 ? left : 0;
}
/*
@@ -77,12 +77,12 @@ int notify_time_left(void)
*/
unsigned notify_needs_reminder(void)
{
- if (notify_app.got_app
- && (((notify_app.state & APOINT_NOTIFY) && !nbar.notify_all) ||
- (!(notify_app.state & APOINT_NOTIFY) && nbar.notify_all))
- && !(notify_app.state & APOINT_NOTIFIED))
- return 1;
- return 0;
+ if (notify_app.got_app
+ && (((notify_app.state & APOINT_NOTIFY) && !nbar.notify_all) ||
+ (!(notify_app.state & APOINT_NOTIFY) && nbar.notify_all))
+ && !(notify_app.state & APOINT_NOTIFIED))
+ return 1;
+ return 0;
}
/*
@@ -92,60 +92,61 @@ unsigned notify_needs_reminder(void)
*/
void notify_update_app(long start, char state, char *msg)
{
- notify_free_app();
- notify_app.got_app = 1;
- notify_app.time = start;
- notify_app.state = state;
- notify_app.txt = mem_strdup(msg);
+ notify_free_app();
+ notify_app.got_app = 1;
+ notify_app.time = start;
+ notify_app.state = state;
+ notify_app.txt = mem_strdup(msg);
}
/* Return 1 if we need to display the notify-bar, else 0. */
int notify_bar(void)
{
- int display_bar = 0;
+ int display_bar = 0;
- pthread_mutex_lock(&nbar.mutex);
- display_bar = (nbar.show) ? 1 : 0;
- pthread_mutex_unlock(&nbar.mutex);
+ pthread_mutex_lock(&nbar.mutex);
+ display_bar = (nbar.show) ? 1 : 0;
+ pthread_mutex_unlock(&nbar.mutex);
- return display_bar;
+ return display_bar;
}
/* Initialize the nbar variable used to store notification options. */
void notify_init_vars(void)
{
- const char *time_format = "%T";
- const char *date_format = "%a %F";
- const char *cmd = "printf '\\a'";
+ const char *time_format = "%T";
+ const char *date_format = "%a %F";
+ const char *cmd = "printf '\\a'";
- pthread_mutex_init(&nbar.mutex, NULL);
- nbar.show = 1;
- nbar.cntdwn = 300;
- strncpy(nbar.datefmt, date_format, strlen(date_format) + 1);
- strncpy(nbar.timefmt, time_format, strlen(time_format) + 1);
- strncpy(nbar.cmd, cmd, strlen(cmd) + 1);
+ pthread_mutex_init(&nbar.mutex, NULL);
+ nbar.show = 1;
+ nbar.cntdwn = 300;
+ strncpy(nbar.datefmt, date_format, strlen(date_format) + 1);
+ strncpy(nbar.timefmt, time_format, strlen(time_format) + 1);
+ strncpy(nbar.cmd, cmd, strlen(cmd) + 1);
- if ((nbar.shell = getenv("SHELL")) == NULL)
- nbar.shell = "/bin/sh";
+ if ((nbar.shell = getenv("SHELL")) == NULL)
+ nbar.shell = "/bin/sh";
- nbar.notify_all = 0;
+ nbar.notify_all = 0;
- pthread_attr_init(&detached_thread_attr);
- pthread_attr_setdetachstate(&detached_thread_attr, PTHREAD_CREATE_DETACHED);
+ pthread_attr_init(&detached_thread_attr);
+ pthread_attr_setdetachstate(&detached_thread_attr,
+ PTHREAD_CREATE_DETACHED);
}
/* Extract the appointment file name from the complete file path. */
static void extract_aptsfile(void)
{
- char *file;
-
- file = strrchr(path_apts, '/');
- if (!file) {
- notify.apts_file = path_apts;
- } else {
- notify.apts_file = file;
- notify.apts_file++;
- }
+ char *file;
+
+ file = strrchr(path_apts, '/');
+ if (!file) {
+ notify.apts_file = path_apts;
+ } else {
+ notify.apts_file = file;
+ notify.apts_file++;
+ }
}
/*
@@ -155,12 +156,13 @@ static void extract_aptsfile(void)
*/
void notify_init_bar(void)
{
- pthread_mutex_init(&notify.mutex, NULL);
- pthread_mutex_init(&notify_app.mutex, NULL);
- notify_app.got_app = 0;
- notify_app.txt = 0;
- notify.win = newwin(win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x);
- extract_aptsfile();
+ pthread_mutex_init(&notify.mutex, NULL);
+ pthread_mutex_init(&notify_app.mutex, NULL);
+ notify_app.got_app = 0;
+ notify_app.txt = 0;
+ notify.win =
+ newwin(win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x);
+ extract_aptsfile();
}
/*
@@ -168,21 +170,21 @@ void notify_init_bar(void)
*/
void notify_free_app(void)
{
- notify_app.time = 0;
- notify_app.got_app = 0;
- notify_app.state = APOINT_NULL;
- if (notify_app.txt)
- mem_free(notify_app.txt);
- notify_app.txt = 0;
+ notify_app.time = 0;
+ notify_app.got_app = 0;
+ notify_app.state = APOINT_NULL;
+ if (notify_app.txt)
+ mem_free(notify_app.txt);
+ notify_app.txt = 0;
}
/* Stop the notify-bar main thread. */
void notify_stop_main_thread(void)
{
- if (notify_t_main) {
- pthread_cancel(notify_t_main);
- pthread_join(notify_t_main, NULL);
- }
+ if (notify_t_main) {
+ pthread_cancel(notify_t_main);
+ pthread_join(notify_t_main, NULL);
+ }
}
/*
@@ -191,35 +193,37 @@ void notify_stop_main_thread(void)
*/
void notify_reinit_bar(void)
{
- delwin(notify.win);
- notify.win = newwin(win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x);
+ delwin(notify.win);
+ notify.win =
+ newwin(win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x);
}
/* Launch user defined command as a notification. */
unsigned notify_launch_cmd(void)
{
- int pid;
+ int pid;
- if (notify_app.state & APOINT_NOTIFIED)
- return 1;
+ if (notify_app.state & APOINT_NOTIFIED)
+ return 1;
- notify_app.state |= APOINT_NOTIFIED;
+ notify_app.state |= APOINT_NOTIFIED;
- pid = fork();
+ pid = fork();
- if (pid < 0) {
- ERROR_MSG(_("error while launching command: could not fork"));
- return 0;
- } else if (pid == 0) {
- /* Child: launch user defined command */
- if (execlp(nbar.shell, nbar.shell, "-c", nbar.cmd, NULL) < 0) {
- ERROR_MSG(_("error while launching command"));
- _exit(1);
- }
- _exit(0);
- }
+ if (pid < 0) {
+ ERROR_MSG(_("error while launching command: could not fork"));
+ return 0;
+ } else if (pid == 0) {
+ /* Child: launch user defined command */
+ if (execlp(nbar.shell, nbar.shell, "-c", nbar.cmd, NULL) <
+ 0) {
+ ERROR_MSG(_("error while launching command"));
+ _exit(1);
+ }
+ _exit(0);
+ }
- return 1;
+ return 1;
}
/*
@@ -228,141 +232,152 @@ unsigned notify_launch_cmd(void)
*/
void notify_update_bar(void)
{
- const int space = 3;
- int file_pos, date_pos, app_pos, txt_max_len, too_long = 0;
- int time_left, blinking;
- char buf[BUFSIZ];
-
- date_pos = space;
- pthread_mutex_lock(&notify.mutex);
-
- file_pos = strlen(notify.date) + strlen(notify.time) + 7 + 2 * space;
- app_pos = file_pos + strlen(notify.apts_file) + 2 + space;
- txt_max_len = col - (app_pos + 12 + space);
-
- WINS_NBAR_LOCK;
- custom_apply_attr(notify.win, ATTR_HIGHEST);
- wattron(notify.win, A_UNDERLINE | A_REVERSE);
- mvwhline(notify.win, 0, 0, ACS_HLINE, col);
- mvwprintw(notify.win, 0, date_pos, "[ %s | %s ]", notify.date, notify.time);
- mvwprintw(notify.win, 0, file_pos, "(%s)", notify.apts_file);
- WINS_NBAR_UNLOCK;
-
- pthread_mutex_lock(&notify_app.mutex);
- if (notify_app.got_app) {
- if (strlen(notify_app.txt) > txt_max_len) {
- int shrink_len;
-
- too_long = 1;
- shrink_len = txt_max_len > 3 ? txt_max_len - 3 : 1;
- strncpy(buf, notify_app.txt, shrink_len);
- buf[shrink_len] = '\0';
- }
- time_left = notify_time_left();
- if (time_left > 0) {
- int hours_left, minutes_left;
-
- hours_left = (time_left / HOURINSEC);
- minutes_left = (time_left - hours_left * HOURINSEC) / MININSEC;
- pthread_mutex_lock(&nbar.mutex);
-
- if (time_left < nbar.cntdwn &&
- (((notify_app.state & APOINT_NOTIFY) && !nbar.notify_all) ||
- (!(notify_app.state & APOINT_NOTIFY) && nbar.notify_all)))
- blinking = 1;
- else
- blinking = 0;
-
- WINS_NBAR_LOCK;
- if (blinking)
- wattron(notify.win, A_BLINK);
- if (too_long)
- mvwprintw(notify.win, 0, app_pos, "> %02d:%02d :: %s.. <",
- hours_left, minutes_left, buf);
- else
- mvwprintw(notify.win, 0, app_pos, "> %02d:%02d :: %s <",
- hours_left, minutes_left, notify_app.txt);
- if (blinking)
- wattroff(notify.win, A_BLINK);
- WINS_NBAR_UNLOCK;
-
- if (blinking)
- notify_launch_cmd();
- pthread_mutex_unlock(&nbar.mutex);
- } else {
- notify_app.got_app = 0;
- pthread_mutex_unlock(&notify_app.mutex);
- pthread_mutex_unlock(&notify.mutex);
- notify_check_next_app(0);
- return;
- }
- }
- pthread_mutex_unlock(&notify_app.mutex);
-
- WINS_NBAR_LOCK;
- wattroff(notify.win, A_UNDERLINE | A_REVERSE);
- custom_remove_attr(notify.win, ATTR_HIGHEST);
- WINS_NBAR_UNLOCK;
- wins_wrefresh(notify.win);
-
- pthread_mutex_unlock(&notify.mutex);
+ const int space = 3;
+ int file_pos, date_pos, app_pos, txt_max_len, too_long = 0;
+ int time_left, blinking;
+ char buf[BUFSIZ];
+
+ date_pos = space;
+ pthread_mutex_lock(&notify.mutex);
+
+ file_pos =
+ strlen(notify.date) + strlen(notify.time) + 7 + 2 * space;
+ app_pos = file_pos + strlen(notify.apts_file) + 2 + space;
+ txt_max_len = col - (app_pos + 12 + space);
+
+ WINS_NBAR_LOCK;
+ custom_apply_attr(notify.win, ATTR_HIGHEST);
+ wattron(notify.win, A_UNDERLINE | A_REVERSE);
+ mvwhline(notify.win, 0, 0, ACS_HLINE, col);
+ mvwprintw(notify.win, 0, date_pos, "[ %s | %s ]", notify.date,
+ notify.time);
+ mvwprintw(notify.win, 0, file_pos, "(%s)", notify.apts_file);
+ WINS_NBAR_UNLOCK;
+
+ pthread_mutex_lock(&notify_app.mutex);
+ if (notify_app.got_app) {
+ if (strlen(notify_app.txt) > txt_max_len) {
+ int shrink_len;
+
+ too_long = 1;
+ shrink_len = txt_max_len > 3 ? txt_max_len - 3 : 1;
+ strncpy(buf, notify_app.txt, shrink_len);
+ buf[shrink_len] = '\0';
+ }
+ time_left = notify_time_left();
+ if (time_left > 0) {
+ int hours_left, minutes_left;
+
+ hours_left = (time_left / HOURINSEC);
+ minutes_left =
+ (time_left -
+ hours_left * HOURINSEC) / MININSEC;
+ pthread_mutex_lock(&nbar.mutex);
+
+ if (time_left < nbar.cntdwn &&
+ (((notify_app.state & APOINT_NOTIFY)
+ && !nbar.notify_all)
+ || (!(notify_app.state & APOINT_NOTIFY)
+ && nbar.notify_all)))
+ blinking = 1;
+ else
+ blinking = 0;
+
+ WINS_NBAR_LOCK;
+ if (blinking)
+ wattron(notify.win, A_BLINK);
+ if (too_long)
+ mvwprintw(notify.win, 0, app_pos,
+ "> %02d:%02d :: %s.. <",
+ hours_left, minutes_left, buf);
+ else
+ mvwprintw(notify.win, 0, app_pos,
+ "> %02d:%02d :: %s <",
+ hours_left, minutes_left,
+ notify_app.txt);
+ if (blinking)
+ wattroff(notify.win, A_BLINK);
+ WINS_NBAR_UNLOCK;
+
+ if (blinking)
+ notify_launch_cmd();
+ pthread_mutex_unlock(&nbar.mutex);
+ } else {
+ notify_app.got_app = 0;
+ pthread_mutex_unlock(&notify_app.mutex);
+ pthread_mutex_unlock(&notify.mutex);
+ notify_check_next_app(0);
+ return;
+ }
+ }
+ pthread_mutex_unlock(&notify_app.mutex);
+
+ WINS_NBAR_LOCK;
+ wattroff(notify.win, A_UNDERLINE | A_REVERSE);
+ custom_remove_attr(notify.win, ATTR_HIGHEST);
+ WINS_NBAR_UNLOCK;
+ wins_wrefresh(notify.win);
+
+ pthread_mutex_unlock(&notify.mutex);
}
/* Update the notication bar content */
/* ARGSUSED0 */
static void *notify_main_thread(void *arg)
{
- const unsigned thread_sleep = 1;
- const unsigned check_app = MININSEC;
- int elapse = 0;
- int got_app;
- struct tm ntime;
- time_t ntimer;
-
- elapse = 0;
-
- for (;;) {
- ntimer = time(NULL);
- localtime_r(&ntimer, &ntime);
- pthread_mutex_lock(&notify.mutex);
- pthread_mutex_lock(&nbar.mutex);
- strftime(notify.time, NOTIFY_FIELD_LENGTH, nbar.timefmt, &ntime);
- strftime(notify.date, NOTIFY_FIELD_LENGTH, nbar.datefmt, &ntime);
- pthread_mutex_unlock(&nbar.mutex);
- pthread_mutex_unlock(&notify.mutex);
- notify_update_bar();
- psleep(thread_sleep);
- elapse += thread_sleep;
- if (elapse >= check_app) {
- elapse = 0;
- pthread_mutex_lock(&notify_app.mutex);
- got_app = notify_app.got_app;
- pthread_mutex_unlock(&notify_app.mutex);
- if (!got_app)
- notify_check_next_app(0);
- }
- }
- pthread_exit(NULL);
+ const unsigned thread_sleep = 1;
+ const unsigned check_app = MININSEC;
+ int elapse = 0;
+ int got_app;
+ struct tm ntime;
+ time_t ntimer;
+
+ elapse = 0;
+
+ for (;;) {
+ ntimer = time(NULL);
+ localtime_r(&ntimer, &ntime);
+ pthread_mutex_lock(&notify.mutex);
+ pthread_mutex_lock(&nbar.mutex);
+ strftime(notify.time, NOTIFY_FIELD_LENGTH, nbar.timefmt,
+ &ntime);
+ strftime(notify.date, NOTIFY_FIELD_LENGTH, nbar.datefmt,
+ &ntime);
+ pthread_mutex_unlock(&nbar.mutex);
+ pthread_mutex_unlock(&notify.mutex);
+ notify_update_bar();
+ psleep(thread_sleep);
+ elapse += thread_sleep;
+ if (elapse >= check_app) {
+ elapse = 0;
+ pthread_mutex_lock(&notify_app.mutex);
+ got_app = notify_app.got_app;
+ pthread_mutex_unlock(&notify_app.mutex);
+ if (!got_app)
+ notify_check_next_app(0);
+ }
+ }
+ pthread_exit(NULL);
}
/* Fill the given structure with information about next appointment. */
unsigned notify_get_next(struct notify_app *a)
{
- time_t current_time;
+ time_t current_time;
- if (!a)
- return 0;
+ if (!a)
+ return 0;
- current_time = time(NULL);
+ current_time = time(NULL);
- a->time = current_time + DAYINSEC;
- a->got_app = 0;
- a->state = 0;
- a->txt = NULL;
- recur_apoint_check_next(a, current_time, get_today());
- apoint_check_next(a, current_time);
+ a->time = current_time + DAYINSEC;
+ a->got_app = 0;
+ a->state = 0;
+ a->txt = NULL;
+ recur_apoint_check_next(a, current_time, get_today());
+ apoint_check_next(a, current_time);
- return 1;
+ return 1;
}
/*
@@ -371,162 +386,166 @@ unsigned notify_get_next(struct notify_app *a)
*/
unsigned notify_get_next_bkgd(void)
{
- struct notify_app a;
+ struct notify_app a;
- a.txt = NULL;
- if (!notify_get_next(&a))
- return 0;
+ a.txt = NULL;
+ if (!notify_get_next(&a))
+ return 0;
- if (!a.got_app) {
- /* No next appointment, reset the previous notified one. */
- notify_app.got_app = 0;
- return 1;
- } else {
- if (!notify_same_item(a.time))
- notify_update_app(a.time, a.state, a.txt);
- }
+ if (!a.got_app) {
+ /* No next appointment, reset the previous notified one. */
+ notify_app.got_app = 0;
+ return 1;
+ } else {
+ if (!notify_same_item(a.time))
+ notify_update_app(a.time, a.state, a.txt);
+ }
- if (a.txt)
- mem_free(a.txt);
+ if (a.txt)
+ mem_free(a.txt);
- return 1;
+ return 1;
}
/* Return the description of next appointment to be notified. */
char *notify_app_txt(void)
{
- if (notify_app.got_app)
- return notify_app.txt;
- else
- return NULL;
+ if (notify_app.got_app)
+ return notify_app.txt;
+ else
+ return NULL;
}
/* Look for the next appointment within the next 24 hours. */
/* ARGSUSED0 */
static void *notify_thread_app(void *arg)
{
- struct notify_app tmp_app;
- int force = (arg ? 1 : 0);
-
- if (!notify_get_next(&tmp_app))
- pthread_exit(NULL);
-
- if (!tmp_app.got_app) {
- pthread_mutex_lock(&notify_app.mutex);
- notify_free_app();
- pthread_mutex_unlock(&notify_app.mutex);
- } else {
- if (force || !notify_same_item(tmp_app.time)) {
- pthread_mutex_lock(&notify_app.mutex);
- notify_update_app(tmp_app.time, tmp_app.state, tmp_app.txt);
- pthread_mutex_unlock(&notify_app.mutex);
- }
- }
-
- if (tmp_app.txt)
- mem_free(tmp_app.txt);
- notify_update_bar();
-
- pthread_exit(NULL);
+ struct notify_app tmp_app;
+ int force = (arg ? 1 : 0);
+
+ if (!notify_get_next(&tmp_app))
+ pthread_exit(NULL);
+
+ if (!tmp_app.got_app) {
+ pthread_mutex_lock(&notify_app.mutex);
+ notify_free_app();
+ pthread_mutex_unlock(&notify_app.mutex);
+ } else {
+ if (force || !notify_same_item(tmp_app.time)) {
+ pthread_mutex_lock(&notify_app.mutex);
+ notify_update_app(tmp_app.time, tmp_app.state,
+ tmp_app.txt);
+ pthread_mutex_unlock(&notify_app.mutex);
+ }
+ }
+
+ if (tmp_app.txt)
+ mem_free(tmp_app.txt);
+ notify_update_bar();
+
+ pthread_exit(NULL);
}
/* Launch the thread notify_thread_app to look for next appointment. */
void notify_check_next_app(int force)
{
- pthread_t notify_t_app;
- void *arg = (force ? (void *)1 : NULL);
+ pthread_t notify_t_app;
+ void *arg = (force ? (void *)1 : NULL);
- pthread_create(&notify_t_app, &detached_thread_attr, notify_thread_app, arg);
- return;
+ pthread_create(&notify_t_app, &detached_thread_attr,
+ notify_thread_app, arg);
+ return;
}
/* Check if the newly created appointment is to be notified. */
void notify_check_added(char *mesg, long start, char state)
{
- time_t current_time;
- int update_notify = 0;
- long gap;
-
- current_time = time(NULL);
- pthread_mutex_lock(&notify_app.mutex);
- if (!notify_app.got_app) {
- gap = start - current_time;
- if (gap >= 0 && gap <= DAYINSEC)
- update_notify = 1;
- } else if (start < notify_app.time && start >= current_time) {
- update_notify = 1;
- } else if (start == notify_app.time && state != notify_app.state) {
- update_notify = 1;
- }
-
- if (update_notify) {
- notify_update_app(start, state, mesg);
- }
- pthread_mutex_unlock(&notify_app.mutex);
- notify_update_bar();
+ time_t current_time;
+ int update_notify = 0;
+ long gap;
+
+ current_time = time(NULL);
+ pthread_mutex_lock(&notify_app.mutex);
+ if (!notify_app.got_app) {
+ gap = start - current_time;
+ if (gap >= 0 && gap <= DAYINSEC)
+ update_notify = 1;
+ } else if (start < notify_app.time && start >= current_time) {
+ update_notify = 1;
+ } else if (start == notify_app.time && state != notify_app.state) {
+ update_notify = 1;
+ }
+
+ if (update_notify) {
+ notify_update_app(start, state, mesg);
+ }
+ pthread_mutex_unlock(&notify_app.mutex);
+ notify_update_bar();
}
/* Check if the newly repeated appointment is to be notified. */
void notify_check_repeated(struct recur_apoint *i)
{
- unsigned real_app_time;
- int update_notify = 0;
- time_t current_time;
-
- current_time = time(NULL);
- pthread_mutex_lock(&notify_app.mutex);
- if (recur_item_find_occurrence(i->start, i->dur, &i->exc, i->rpt->type,
- i->rpt->freq, i->rpt->until, get_today(),
- &real_app_time)) {
- if (!notify_app.got_app) {
- if (real_app_time - current_time <= DAYINSEC)
- update_notify = 1;
- } else if (real_app_time < notify_app.time && real_app_time >= current_time) {
- update_notify = 1;
- } else if (real_app_time == notify_app.time && i->state != notify_app.state) {
- update_notify = 1;
- }
- }
- if (update_notify) {
- notify_update_app(real_app_time, i->state, i->mesg);
- }
- pthread_mutex_unlock(&notify_app.mutex);
- notify_update_bar();
+ unsigned real_app_time;
+ int update_notify = 0;
+ time_t current_time;
+
+ current_time = time(NULL);
+ pthread_mutex_lock(&notify_app.mutex);
+ if (recur_item_find_occurrence
+ (i->start, i->dur, &i->exc, i->rpt->type, i->rpt->freq,
+ i->rpt->until, get_today(), &real_app_time)) {
+ if (!notify_app.got_app) {
+ if (real_app_time - current_time <= DAYINSEC)
+ update_notify = 1;
+ } else if (real_app_time < notify_app.time
+ && real_app_time >= current_time) {
+ update_notify = 1;
+ } else if (real_app_time == notify_app.time
+ && i->state != notify_app.state) {
+ update_notify = 1;
+ }
+ }
+ if (update_notify) {
+ notify_update_app(real_app_time, i->state, i->mesg);
+ }
+ pthread_mutex_unlock(&notify_app.mutex);
+ notify_update_bar();
}
int notify_same_item(long time)
{
- int same = 0;
+ int same = 0;
- pthread_mutex_lock(&(notify_app.mutex));
- if (notify_app.got_app && notify_app.time == time)
- same = 1;
- pthread_mutex_unlock(&(notify_app.mutex));
+ pthread_mutex_lock(&(notify_app.mutex));
+ if (notify_app.got_app && notify_app.time == time)
+ same = 1;
+ pthread_mutex_unlock(&(notify_app.mutex));
- return same;
+ return same;
}
int notify_same_recur_item(struct recur_apoint *i)
{
- int same = 0;
- unsigned item_start = 0;
-
- recur_item_find_occurrence(i->start, i->dur, &i->exc, i->rpt->type,
- i->rpt->freq, i->rpt->until, get_today(),
- &item_start);
- pthread_mutex_lock(&notify_app.mutex);
- if (notify_app.got_app && item_start == notify_app.time)
- same = 1;
- pthread_mutex_unlock(&(notify_app.mutex));
-
- return same;
+ int same = 0;
+ unsigned item_start = 0;
+
+ recur_item_find_occurrence(i->start, i->dur, &i->exc, i->rpt->type,
+ i->rpt->freq, i->rpt->until,
+ get_today(), &item_start);
+ pthread_mutex_lock(&notify_app.mutex);
+ if (notify_app.got_app && item_start == notify_app.time)
+ same = 1;
+ pthread_mutex_unlock(&(notify_app.mutex));
+
+ return same;
}
/* Launch the notify-bar main thread. */
void notify_start_main_thread(void)
{
- pthread_create(&notify_t_main, NULL, notify_main_thread, NULL);
- notify_check_next_app(0);
+ pthread_create(&notify_t_main, NULL, notify_main_thread, NULL);
+ notify_check_next_app(0);
}
/*
@@ -536,248 +555,263 @@ void notify_start_main_thread(void)
*/
static void
print_option(WINDOW * win, unsigned x, unsigned y, char *name,
- char *valstr, unsigned valbool, char *desc, unsigned num)
+ char *valstr, unsigned valbool, char *desc, unsigned num)
{
- const int XOFF = 4;
- const int MAXCOL = col - 3;
- int x_opt, len;
-
- x_opt = x + XOFF + strlen(name);
- mvwprintw(win, y, x, "[%u] %s", num, name);
- erase_window_part(win, x_opt, y, MAXCOL, y);
- if ((len = strlen(valstr)) != 0) {
- unsigned maxlen;
-
- maxlen = MAXCOL - x_opt - 2;
- custom_apply_attr(win, ATTR_HIGHEST);
- if (len < maxlen) {
- mvwaddstr(win, y, x_opt, valstr);
- } else {
- char buf[BUFSIZ];
-
- strncpy(buf, valstr, maxlen - 1);
- buf[maxlen - 1] = '\0';
- mvwprintw(win, y, x_opt, "%s...", buf);
- }
- custom_remove_attr(win, ATTR_HIGHEST);
- } else {
- print_bool_option_incolor(win, valbool, y, x_opt);
- }
- mvwaddstr(win, y + 1, x, desc);
+ const int XOFF = 4;
+ const int MAXCOL = col - 3;
+ int x_opt, len;
+
+ x_opt = x + XOFF + strlen(name);
+ mvwprintw(win, y, x, "[%u] %s", num, name);
+ erase_window_part(win, x_opt, y, MAXCOL, y);
+ if ((len = strlen(valstr)) != 0) {
+ unsigned maxlen;
+
+ maxlen = MAXCOL - x_opt - 2;
+ custom_apply_attr(win, ATTR_HIGHEST);
+ if (len < maxlen) {
+ mvwaddstr(win, y, x_opt, valstr);
+ } else {
+ char buf[BUFSIZ];
+
+ strncpy(buf, valstr, maxlen - 1);
+ buf[maxlen - 1] = '\0';
+ mvwprintw(win, y, x_opt, "%s...", buf);
+ }
+ custom_remove_attr(win, ATTR_HIGHEST);
+ } else {
+ print_bool_option_incolor(win, valbool, y, x_opt);
+ }
+ mvwaddstr(win, y + 1, x, desc);
}
/* Print options related to the notify-bar. */
static unsigned print_config_options(WINDOW * optwin)
{
- const int XORIG = 3;
- const int YORIG = 0;
- const int YOFF = 3;
+ const int XORIG = 3;
+ const int YORIG = 0;
+ const int YOFF = 3;
- enum { SHOW, DATE, CLOCK, WARN, CMD, NOTIFY_ALL, DMON, DMON_LOG, NB_OPT };
+ enum { SHOW, DATE, CLOCK, WARN, CMD, NOTIFY_ALL, DMON, DMON_LOG,
+ NB_OPT };
- struct opt_s {
- char *name;
- char *desc;
- char valstr[BUFSIZ];
- unsigned valnum;
- } opt[NB_OPT];
+ struct opt_s {
+ char *name;
+ char *desc;
+ char valstr[BUFSIZ];
+ unsigned valnum;
+ } opt[NB_OPT];
- int i;
+ int i;
- opt[SHOW].name = "appearance.notifybar = ";
- opt[SHOW].desc = _("(if set to YES, notify-bar will be displayed)");
+ opt[SHOW].name = "appearance.notifybar = ";
+ opt[SHOW].desc =
+ _("(if set to YES, notify-bar will be displayed)");
- opt[DATE].name = "format.notifydate = ";
- opt[DATE].desc = _("(Format of the date to be displayed inside notify-bar)");
+ opt[DATE].name = "format.notifydate = ";
+ opt[DATE].desc =
+ _("(Format of the date to be displayed inside notify-bar)");
- opt[CLOCK].name = "format.notifytime = ";
- opt[CLOCK].desc = _("(Format of the time to be displayed inside notify-bar)");
+ opt[CLOCK].name = "format.notifytime = ";
+ opt[CLOCK].desc =
+ _("(Format of the time to be displayed inside notify-bar)");
- opt[WARN].name = "notification.warning = ";
- opt[WARN].desc = _("(Warn user if an appointment is within next "
- "'notify-bar_warning' seconds)");
+ opt[WARN].name = "notification.warning = ";
+ opt[WARN].desc = _("(Warn user if an appointment is within next "
+ "'notify-bar_warning' seconds)");
- opt[CMD].name = "notification.command = ";
- opt[CMD].desc = _("(Command used to notify user of an upcoming appointment)");
+ opt[CMD].name = "notification.command = ";
+ opt[CMD].desc =
+ _("(Command used to notify user of an upcoming appointment)");
- opt[NOTIFY_ALL].name = "notification.notifyall = ";
- opt[NOTIFY_ALL].desc =
- _("(Notify all appointments instead of flagged ones only)");
+ opt[NOTIFY_ALL].name = "notification.notifyall = ";
+ opt[NOTIFY_ALL].desc =
+ _("(Notify all appointments instead of flagged ones only)");
- opt[DMON].name = "daemon.enable = ";
- opt[DMON].desc = _("(Run in background to get notifications after exiting)");
+ opt[DMON].name = "daemon.enable = ";
+ opt[DMON].desc =
+ _("(Run in background to get notifications after exiting)");
- opt[DMON_LOG].name = "daemon.log = ";
- opt[DMON_LOG].desc = _("(Log activity when running in background)");
+ opt[DMON_LOG].name = "daemon.log = ";
+ opt[DMON_LOG].desc =
+ _("(Log activity when running in background)");
- pthread_mutex_lock(&nbar.mutex);
+ pthread_mutex_lock(&nbar.mutex);
- /* String value options */
- strncpy(opt[DATE].valstr, nbar.datefmt, BUFSIZ);
- strncpy(opt[CLOCK].valstr, nbar.timefmt, BUFSIZ);
- snprintf(opt[WARN].valstr, BUFSIZ, "%d", nbar.cntdwn);
- strncpy(opt[CMD].valstr, nbar.cmd, BUFSIZ);
+ /* String value options */
+ strncpy(opt[DATE].valstr, nbar.datefmt, BUFSIZ);
+ strncpy(opt[CLOCK].valstr, nbar.timefmt, BUFSIZ);
+ snprintf(opt[WARN].valstr, BUFSIZ, "%d", nbar.cntdwn);
+ strncpy(opt[CMD].valstr, nbar.cmd, BUFSIZ);
- /* Boolean options */
- opt[SHOW].valnum = nbar.show;
- opt[NOTIFY_ALL].valnum = nbar.notify_all;
- pthread_mutex_unlock(&nbar.mutex);
+ /* Boolean options */
+ opt[SHOW].valnum = nbar.show;
+ opt[NOTIFY_ALL].valnum = nbar.notify_all;
+ pthread_mutex_unlock(&nbar.mutex);
- opt[DMON].valnum = dmon.enable;
- opt[DMON_LOG].valnum = dmon.log;
+ opt[DMON].valnum = dmon.enable;
+ opt[DMON_LOG].valnum = dmon.log;
- opt[SHOW].valstr[0] = opt[NOTIFY_ALL].valstr[0] = opt[DMON].valstr[0] =
- opt[DMON_LOG].valstr[0] = '\0';
+ opt[SHOW].valstr[0] = opt[NOTIFY_ALL].valstr[0] =
+ opt[DMON].valstr[0] = opt[DMON_LOG].valstr[0] = '\0';
- for (i = 0; i < NB_OPT; i++) {
- int y;
+ for (i = 0; i < NB_OPT; i++) {
+ int y;
- y = YORIG + i * YOFF;
- print_option(optwin, XORIG, y, opt[i].name, opt[i].valstr,
- opt[i].valnum, opt[i].desc, i + 1);
- }
+ y = YORIG + i * YOFF;
+ print_option(optwin, XORIG, y, opt[i].name, opt[i].valstr,
+ opt[i].valnum, opt[i].desc, i + 1);
+ }
- return YORIG + NB_OPT * YOFF;
+ return YORIG + NB_OPT * YOFF;
}
static void reinit_conf_win(struct scrollwin *win)
{
- unsigned first_line;
-
- first_line = win->first_visible_line;
- wins_scrollwin_delete(win);
- custom_set_swsiz(win);
- wins_scrollwin_init(win);
- wins_show(win->win.p, win->label);
- win->first_visible_line = first_line;
+ unsigned first_line;
+
+ first_line = win->first_visible_line;
+ wins_scrollwin_delete(win);
+ custom_set_swsiz(win);
+ wins_scrollwin_init(win);
+ wins_show(win->win.p, win->label);
+ win->first_visible_line = first_line;
}
/* Notify-bar configuration. */
void notify_config_bar(void)
{
- struct scrollwin cwin;
- char *buf;
- const char *number_str = _("Enter an option number to change its value");
- const char *keys = _("(Press '^P' or '^N' to move up or down, 'Q' to quit)");
- const char *date_str =
- _("Enter the date format (see 'man 3 strftime' for possible formats) ");
- const char *time_str =
- _("Enter the time format (see 'man 3 strftime' for possible formats) ");
- const char *count_str =
- _
- ("Enter the number of seconds (0 not to be warned before an appointment)");
- const char *cmd_str = _("Enter the notification command ");
- int ch;
-
- clear();
- custom_set_swsiz(&cwin);
- cwin.label = _("notification options");
- wins_scrollwin_init(&cwin);
- wins_show(cwin.win.p, cwin.label);
- status_mesg(number_str, keys);
- cwin.total_lines = print_config_options(cwin.pad.p);
- wins_scrollwin_display(&cwin);
-
- buf = mem_malloc(BUFSIZ);
- while ((ch = wgetch(win[KEY].p)) != 'q') {
- buf[0] = '\0';
-
- switch (ch) {
- case CTRL('N'):
- wins_scrollwin_down(&cwin, 1);
- break;
- case CTRL('P'):
- wins_scrollwin_up(&cwin, 1);
- break;
- case '1':
- pthread_mutex_lock(&nbar.mutex);
- nbar.show = !nbar.show;
- pthread_mutex_unlock(&nbar.mutex);
- if (notify_bar())
- notify_start_main_thread();
- else
- notify_stop_main_thread();
- wins_scrollwin_delete(&cwin);
- reinit_conf_win(&cwin);
- break;
- case '2':
- status_mesg(date_str, "");
- pthread_mutex_lock(&nbar.mutex);
- strncpy(buf, nbar.datefmt, strlen(nbar.datefmt) + 1);
- pthread_mutex_unlock(&nbar.mutex);
- if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
- pthread_mutex_lock(&nbar.mutex);
- strncpy(nbar.datefmt, buf, strlen(buf) + 1);
- pthread_mutex_unlock(&nbar.mutex);
- }
- break;
- case '3':
- status_mesg(time_str, "");
- pthread_mutex_lock(&nbar.mutex);
- strncpy(buf, nbar.timefmt, strlen(nbar.timefmt) + 1);
- pthread_mutex_unlock(&nbar.mutex);
- if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
- pthread_mutex_lock(&nbar.mutex);
- strncpy(nbar.timefmt, buf, strlen(buf) + 1);
- pthread_mutex_unlock(&nbar.mutex);
- }
- break;
- case '4':
- status_mesg(count_str, "");
- pthread_mutex_lock(&nbar.mutex);
- snprintf(buf, BUFSIZ, "%d", nbar.cntdwn);
- pthread_mutex_unlock(&nbar.mutex);
- if (updatestring(win[STA].p, &buf, 0, 1) == 0 &&
- is_all_digit(buf) && atoi(buf) >= 0 && atoi(buf) <= DAYINSEC) {
- pthread_mutex_lock(&nbar.mutex);
- nbar.cntdwn = atoi(buf);
- pthread_mutex_unlock(&nbar.mutex);
- }
- break;
- case '5':
- status_mesg(cmd_str, "");
- pthread_mutex_lock(&nbar.mutex);
- strncpy(buf, nbar.cmd, strlen(nbar.cmd) + 1);
- pthread_mutex_unlock(&nbar.mutex);
- if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
- pthread_mutex_lock(&nbar.mutex);
- strncpy(nbar.cmd, buf, strlen(buf) + 1);
- pthread_mutex_unlock(&nbar.mutex);
- }
- break;
- case '6':
- pthread_mutex_lock(&nbar.mutex);
- nbar.notify_all = !nbar.notify_all;
- pthread_mutex_unlock(&nbar.mutex);
- notify_check_next_app(1);
- break;
- case '7':
- dmon.enable = !dmon.enable;
- break;
- case '8':
- dmon.log = !dmon.log;
- break;
- }
-
- if (resize) {
- resize = 0;
- wins_get_config();
- wins_reset();
- reinit_conf_win(&cwin);
- delwin(win[STA].p);
- win[STA].p = newwin(win[STA].h, win[STA].w, win[STA].y, win[STA].x);
- keypad(win[STA].p, TRUE);
- if (notify_bar()) {
- notify_reinit_bar();
- notify_update_bar();
- }
- clearok(curscr, TRUE);
- }
-
- status_mesg(number_str, keys);
- cwin.total_lines = print_config_options(cwin.pad.p);
- wins_scrollwin_display(&cwin);
- }
- mem_free(buf);
- wins_scrollwin_delete(&cwin);
+ struct scrollwin cwin;
+ char *buf;
+ const char *number_str =
+ _("Enter an option number to change its value");
+ const char *keys =
+ _("(Press '^P' or '^N' to move up or down, 'Q' to quit)");
+ const char *date_str =
+ _("Enter the date format (see 'man 3 strftime' for possible formats) ");
+ const char *time_str =
+ _("Enter the time format (see 'man 3 strftime' for possible formats) ");
+ const char *count_str =
+ _("Enter the number of seconds (0 not to be warned before an appointment)");
+ const char *cmd_str = _("Enter the notification command ");
+ int ch;
+
+ clear();
+ custom_set_swsiz(&cwin);
+ cwin.label = _("notification options");
+ wins_scrollwin_init(&cwin);
+ wins_show(cwin.win.p, cwin.label);
+ status_mesg(number_str, keys);
+ cwin.total_lines = print_config_options(cwin.pad.p);
+ wins_scrollwin_display(&cwin);
+
+ buf = mem_malloc(BUFSIZ);
+ while ((ch = wgetch(win[KEY].p)) != 'q') {
+ buf[0] = '\0';
+
+ switch (ch) {
+ case CTRL('N'):
+ wins_scrollwin_down(&cwin, 1);
+ break;
+ case CTRL('P'):
+ wins_scrollwin_up(&cwin, 1);
+ break;
+ case '1':
+ pthread_mutex_lock(&nbar.mutex);
+ nbar.show = !nbar.show;
+ pthread_mutex_unlock(&nbar.mutex);
+ if (notify_bar())
+ notify_start_main_thread();
+ else
+ notify_stop_main_thread();
+ wins_scrollwin_delete(&cwin);
+ reinit_conf_win(&cwin);
+ break;
+ case '2':
+ status_mesg(date_str, "");
+ pthread_mutex_lock(&nbar.mutex);
+ strncpy(buf, nbar.datefmt,
+ strlen(nbar.datefmt) + 1);
+ pthread_mutex_unlock(&nbar.mutex);
+ if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
+ pthread_mutex_lock(&nbar.mutex);
+ strncpy(nbar.datefmt, buf,
+ strlen(buf) + 1);
+ pthread_mutex_unlock(&nbar.mutex);
+ }
+ break;
+ case '3':
+ status_mesg(time_str, "");
+ pthread_mutex_lock(&nbar.mutex);
+ strncpy(buf, nbar.timefmt,
+ strlen(nbar.timefmt) + 1);
+ pthread_mutex_unlock(&nbar.mutex);
+ if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
+ pthread_mutex_lock(&nbar.mutex);
+ strncpy(nbar.timefmt, buf,
+ strlen(buf) + 1);
+ pthread_mutex_unlock(&nbar.mutex);
+ }
+ break;
+ case '4':
+ status_mesg(count_str, "");
+ pthread_mutex_lock(&nbar.mutex);
+ snprintf(buf, BUFSIZ, "%d", nbar.cntdwn);
+ pthread_mutex_unlock(&nbar.mutex);
+ if (updatestring(win[STA].p, &buf, 0, 1) == 0 &&
+ is_all_digit(buf) && atoi(buf) >= 0
+ && atoi(buf) <= DAYINSEC) {
+ pthread_mutex_lock(&nbar.mutex);
+ nbar.cntdwn = atoi(buf);
+ pthread_mutex_unlock(&nbar.mutex);
+ }
+ break;
+ case '5':
+ status_mesg(cmd_str, "");
+ pthread_mutex_lock(&nbar.mutex);
+ strncpy(buf, nbar.cmd, strlen(nbar.cmd) + 1);
+ pthread_mutex_unlock(&nbar.mutex);
+ if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
+ pthread_mutex_lock(&nbar.mutex);
+ strncpy(nbar.cmd, buf, strlen(buf) + 1);
+ pthread_mutex_unlock(&nbar.mutex);
+ }
+ break;
+ case '6':
+ pthread_mutex_lock(&nbar.mutex);
+ nbar.notify_all = !nbar.notify_all;
+ pthread_mutex_unlock(&nbar.mutex);
+ notify_check_next_app(1);
+ break;
+ case '7':
+ dmon.enable = !dmon.enable;
+ break;
+ case '8':
+ dmon.log = !dmon.log;
+ break;
+ }
+
+ if (resize) {
+ resize = 0;
+ wins_get_config();
+ wins_reset();
+ reinit_conf_win(&cwin);
+ delwin(win[STA].p);
+ win[STA].p =
+ newwin(win[STA].h, win[STA].w, win[STA].y,
+ win[STA].x);
+ keypad(win[STA].p, TRUE);
+ if (notify_bar()) {
+ notify_reinit_bar();
+ notify_update_bar();
+ }
+ clearok(curscr, TRUE);
+ }
+
+ status_mesg(number_str, keys);
+ cwin.total_lines = print_config_options(cwin.pad.p);
+ wins_scrollwin_display(&cwin);
+ }
+ mem_free(buf);
+ wins_scrollwin_delete(&cwin);
}
diff --git a/src/pcal.c b/src/pcal.c
index e2721e6..a9fdefd 100644
--- a/src/pcal.c
+++ b/src/pcal.c
@@ -56,55 +56,60 @@ typedef void (*cb_dump_t) (FILE *, long, long, char *);
*/
static void
foreach_date_dump(const long date_end, struct rpt *rpt, llist_t * exc,
- long item_first_date, long item_dur, char *item_mesg,
- cb_dump_t cb_dump, FILE * stream)
+ long item_first_date, long item_dur, char *item_mesg,
+ cb_dump_t cb_dump, FILE * stream)
{
- long date, item_time;
- struct tm lt;
- time_t t;
+ long date, item_time;
+ struct tm lt;
+ time_t t;
- t = item_first_date;
- localtime_r(&t, &lt);
- lt.tm_hour = lt.tm_min = lt.tm_sec = 0;
- lt.tm_isdst = -1;
- date = mktime(&lt);
- item_time = item_first_date - date;
+ t = item_first_date;
+ localtime_r(&t, &lt);
+ lt.tm_hour = lt.tm_min = lt.tm_sec = 0;
+ lt.tm_isdst = -1;
+ date = mktime(&lt);
+ item_time = item_first_date - date;
- while (date <= date_end && date <= rpt->until) {
- if (recur_item_inday(item_first_date, item_dur, exc, rpt->type,
- rpt->freq, rpt->until, date)) {
- (*cb_dump) (stream, date + item_time, item_dur, item_mesg);
- }
- switch (rpt->type) {
- case RECUR_DAILY:
- date = date_sec_change(date, 0, rpt->freq);
- break;
- case RECUR_WEEKLY:
- date = date_sec_change(date, 0, rpt->freq * WEEKINDAYS);
- break;
- case RECUR_MONTHLY:
- date = date_sec_change(date, rpt->freq, 0);
- break;
- case RECUR_YEARLY:
- date = date_sec_change(date, rpt->freq * 12, 0);
- break;
- default:
- EXIT(_("incoherent repetition type"));
- /* NOTREACHED */
- break;
- }
- }
+ while (date <= date_end && date <= rpt->until) {
+ if (recur_item_inday
+ (item_first_date, item_dur, exc, rpt->type, rpt->freq,
+ rpt->until, date)) {
+ (*cb_dump) (stream, date + item_time, item_dur,
+ item_mesg);
+ }
+ switch (rpt->type) {
+ case RECUR_DAILY:
+ date = date_sec_change(date, 0, rpt->freq);
+ break;
+ case RECUR_WEEKLY:
+ date =
+ date_sec_change(date, 0,
+ rpt->freq * WEEKINDAYS);
+ break;
+ case RECUR_MONTHLY:
+ date = date_sec_change(date, rpt->freq, 0);
+ break;
+ case RECUR_YEARLY:
+ date = date_sec_change(date, rpt->freq * 12, 0);
+ break;
+ default:
+ EXIT(_("incoherent repetition type"));
+ /* NOTREACHED */
+ break;
+ }
+ }
}
static void pcal_export_header(FILE * stream)
{
- fputs("# calcurse pcal export\n", stream);
- fputs("\n# =======\n# options\n# =======\n", stream);
- fprintf(stream, "opt -A -K -l -m -F %s\n",
- ui_calendar_week_begins_on_monday()? "Monday" : "Sunday");
- fputs("# Display week number (i.e. 1-52) on every Monday\n", stream);
- fprintf(stream, "all monday in all week %%w\n");
- fputc('\n', stream);
+ fputs("# calcurse pcal export\n", stream);
+ fputs("\n# =======\n# options\n# =======\n", stream);
+ fprintf(stream, "opt -A -K -l -m -F %s\n",
+ ui_calendar_week_begins_on_monday()? "Monday" : "Sunday");
+ fputs("# Display week number (i.e. 1-52) on every Monday\n",
+ stream);
+ fprintf(stream, "all monday in all week %%w\n");
+ fputc('\n', stream);
}
static void pcal_export_footer(FILE * stream)
@@ -114,178 +119,215 @@ static void pcal_export_footer(FILE * stream)
/* Format and dump event data to a pcal formatted file. */
static void
pcal_dump_event(FILE * stream, long event_date, long event_dur,
- char *event_mesg)
+ char *event_mesg)
{
- char pcal_date[BUFSIZ];
+ char pcal_date[BUFSIZ];
- date_sec2date_fmt(event_date, "%b %d", pcal_date);
- fprintf(stream, "%s %s\n", pcal_date, event_mesg);
+ date_sec2date_fmt(event_date, "%b %d", pcal_date);
+ fprintf(stream, "%s %s\n", pcal_date, event_mesg);
}
/* Format and dump appointment data to a pcal formatted file. */
static void
pcal_dump_apoint(FILE * stream, long apoint_date, long apoint_dur,
- char *apoint_mesg)
+ char *apoint_mesg)
{
- char pcal_date[BUFSIZ], pcal_beg[BUFSIZ], pcal_end[BUFSIZ];
+ char pcal_date[BUFSIZ], pcal_beg[BUFSIZ], pcal_end[BUFSIZ];
- date_sec2date_fmt(apoint_date, "%b %d", pcal_date);
- date_sec2date_fmt(apoint_date, "%R", pcal_beg);
- date_sec2date_fmt(apoint_date + apoint_dur, "%R", pcal_end);
- fprintf(stream, "%s ", pcal_date);
- fprintf(stream, "(%s -> %s) %s\n", pcal_beg, pcal_end, apoint_mesg);
+ date_sec2date_fmt(apoint_date, "%b %d", pcal_date);
+ date_sec2date_fmt(apoint_date, "%R", pcal_beg);
+ date_sec2date_fmt(apoint_date + apoint_dur, "%R", pcal_end);
+ fprintf(stream, "%s ", pcal_date);
+ fprintf(stream, "(%s -> %s) %s\n", pcal_beg, pcal_end,
+ apoint_mesg);
}
static void pcal_export_recur_events(FILE * stream)
{
- llist_item_t *i;
- char pcal_date[BUFSIZ];
+ llist_item_t *i;
+ char pcal_date[BUFSIZ];
- fputs("\n# =============", stream);
- fputs("\n# Recur. Events", stream);
- fputs("\n# =============\n", stream);
- fputs("# (pcal does not support from..until dates specification\n", stream);
+ fputs("\n# =============", stream);
+ fputs("\n# Recur. Events", stream);
+ fputs("\n# =============\n", stream);
+ fputs("# (pcal does not support from..until dates specification\n",
+ stream);
- LLIST_FOREACH(&recur_elist, i) {
- struct recur_event *rev = LLIST_GET_DATA(i);
- if (rev->rpt->until == 0 && rev->rpt->freq == 1) {
- switch (rev->rpt->type) {
- case RECUR_DAILY:
- date_sec2date_fmt(rev->day, "%b %d", pcal_date);
- fprintf(stream, "all day on_or_after %s %s\n", pcal_date, rev->mesg);
- break;
- case RECUR_WEEKLY:
- date_sec2date_fmt(rev->day, "%a", pcal_date);
- fprintf(stream, "all %s on_or_after ", pcal_date);
- date_sec2date_fmt(rev->day, "%b %d", pcal_date);
- fprintf(stream, "%s %s\n", pcal_date, rev->mesg);
- break;
- case RECUR_MONTHLY:
- date_sec2date_fmt(rev->day, "%d", pcal_date);
- fprintf(stream, "day on all %s %s\n", pcal_date, rev->mesg);
- break;
- case RECUR_YEARLY:
- date_sec2date_fmt(rev->day, "%b %d", pcal_date);
- fprintf(stream, "%s %s\n", pcal_date, rev->mesg);
- break;
- default:
- EXIT(_("incoherent repetition type"));
- }
- } else {
- const long YEAR_START = ui_calendar_start_of_year();
- const long YEAR_END = ui_calendar_end_of_year();
+ LLIST_FOREACH(&recur_elist, i) {
+ struct recur_event *rev = LLIST_GET_DATA(i);
+ if (rev->rpt->until == 0 && rev->rpt->freq == 1) {
+ switch (rev->rpt->type) {
+ case RECUR_DAILY:
+ date_sec2date_fmt(rev->day, "%b %d",
+ pcal_date);
+ fprintf(stream,
+ "all day on_or_after %s %s\n",
+ pcal_date, rev->mesg);
+ break;
+ case RECUR_WEEKLY:
+ date_sec2date_fmt(rev->day, "%a",
+ pcal_date);
+ fprintf(stream, "all %s on_or_after ",
+ pcal_date);
+ date_sec2date_fmt(rev->day, "%b %d",
+ pcal_date);
+ fprintf(stream, "%s %s\n", pcal_date,
+ rev->mesg);
+ break;
+ case RECUR_MONTHLY:
+ date_sec2date_fmt(rev->day, "%d",
+ pcal_date);
+ fprintf(stream, "day on all %s %s\n",
+ pcal_date, rev->mesg);
+ break;
+ case RECUR_YEARLY:
+ date_sec2date_fmt(rev->day, "%b %d",
+ pcal_date);
+ fprintf(stream, "%s %s\n", pcal_date,
+ rev->mesg);
+ break;
+ default:
+ EXIT(_("incoherent repetition type"));
+ }
+ } else {
+ const long YEAR_START =
+ ui_calendar_start_of_year();
+ const long YEAR_END = ui_calendar_end_of_year();
- if (rev->day < YEAR_END && rev->day > YEAR_START)
- foreach_date_dump(YEAR_END, rev->rpt, &rev->exc, rev->day, 0,
- rev->mesg, (cb_dump_t) pcal_dump_event, stream);
- }
- }
+ if (rev->day < YEAR_END && rev->day > YEAR_START)
+ foreach_date_dump(YEAR_END, rev->rpt,
+ &rev->exc, rev->day, 0,
+ rev->mesg,
+ (cb_dump_t)
+ pcal_dump_event, stream);
+ }
+ }
}
static void pcal_export_events(FILE * stream)
{
- llist_item_t *i;
+ llist_item_t *i;
- fputs("\n# ======\n# Events\n# ======\n", stream);
- LLIST_FOREACH(&eventlist, i) {
- struct event *ev = LLIST_TS_GET_DATA(i);
- pcal_dump_event(stream, ev->day, 0, ev->mesg);
- }
- fputc('\n', stream);
+ fputs("\n# ======\n# Events\n# ======\n", stream);
+ LLIST_FOREACH(&eventlist, i) {
+ struct event *ev = LLIST_TS_GET_DATA(i);
+ pcal_dump_event(stream, ev->day, 0, ev->mesg);
+ }
+ fputc('\n', stream);
}
static void pcal_export_recur_apoints(FILE * stream)
{
- llist_item_t *i;
- char pcal_date[BUFSIZ], pcal_beg[BUFSIZ], pcal_end[BUFSIZ];
+ llist_item_t *i;
+ char pcal_date[BUFSIZ], pcal_beg[BUFSIZ], pcal_end[BUFSIZ];
- fputs("\n# ==============", stream);
- fputs("\n# Recur. Apoints", stream);
- fputs("\n# ==============\n", stream);
- fputs("# (pcal does not support from..until dates specification\n", stream);
+ fputs("\n# ==============", stream);
+ fputs("\n# Recur. Apoints", stream);
+ fputs("\n# ==============\n", stream);
+ fputs("# (pcal does not support from..until dates specification\n",
+ stream);
- LLIST_TS_FOREACH(&recur_alist_p, i) {
- struct recur_apoint *rapt = LLIST_TS_GET_DATA(i);
+ LLIST_TS_FOREACH(&recur_alist_p, i) {
+ struct recur_apoint *rapt = LLIST_TS_GET_DATA(i);
- if (rapt->rpt->until == 0 && rapt->rpt->freq == 1) {
- date_sec2date_fmt(rapt->start, "%R", pcal_beg);
- date_sec2date_fmt(rapt->start + rapt->dur, "%R", pcal_end);
- switch (rapt->rpt->type) {
- case RECUR_DAILY:
- date_sec2date_fmt(rapt->start, "%b %d", pcal_date);
- fprintf(stream, "all day on_or_after %s (%s -> %s) %s\n",
- pcal_date, pcal_beg, pcal_end, rapt->mesg);
- break;
- case RECUR_WEEKLY:
- date_sec2date_fmt(rapt->start, "%a", pcal_date);
- fprintf(stream, "all %s on_or_after ", pcal_date);
- date_sec2date_fmt(rapt->start, "%b %d", pcal_date);
- fprintf(stream, "%s (%s -> %s) %s\n", pcal_date, pcal_beg,
- pcal_end, rapt->mesg);
- break;
- case RECUR_MONTHLY:
- date_sec2date_fmt(rapt->start, "%d", pcal_date);
- fprintf(stream, "day on all %s (%s -> %s) %s\n", pcal_date,
- pcal_beg, pcal_end, rapt->mesg);
- break;
- case RECUR_YEARLY:
- date_sec2date_fmt(rapt->start, "%b %d", pcal_date);
- fprintf(stream, "%s (%s -> %s) %s\n", pcal_date, pcal_beg,
- pcal_end, rapt->mesg);
- break;
- default:
- EXIT(_("incoherent repetition type"));
- }
- } else {
- const long YEAR_START = ui_calendar_start_of_year();
- const long YEAR_END = ui_calendar_end_of_year();
+ if (rapt->rpt->until == 0 && rapt->rpt->freq == 1) {
+ date_sec2date_fmt(rapt->start, "%R", pcal_beg);
+ date_sec2date_fmt(rapt->start + rapt->dur, "%R",
+ pcal_end);
+ switch (rapt->rpt->type) {
+ case RECUR_DAILY:
+ date_sec2date_fmt(rapt->start, "%b %d",
+ pcal_date);
+ fprintf(stream,
+ "all day on_or_after %s (%s -> %s) %s\n",
+ pcal_date, pcal_beg, pcal_end,
+ rapt->mesg);
+ break;
+ case RECUR_WEEKLY:
+ date_sec2date_fmt(rapt->start, "%a",
+ pcal_date);
+ fprintf(stream, "all %s on_or_after ",
+ pcal_date);
+ date_sec2date_fmt(rapt->start, "%b %d",
+ pcal_date);
+ fprintf(stream, "%s (%s -> %s) %s\n",
+ pcal_date, pcal_beg, pcal_end,
+ rapt->mesg);
+ break;
+ case RECUR_MONTHLY:
+ date_sec2date_fmt(rapt->start, "%d",
+ pcal_date);
+ fprintf(stream,
+ "day on all %s (%s -> %s) %s\n",
+ pcal_date, pcal_beg, pcal_end,
+ rapt->mesg);
+ break;
+ case RECUR_YEARLY:
+ date_sec2date_fmt(rapt->start, "%b %d",
+ pcal_date);
+ fprintf(stream, "%s (%s -> %s) %s\n",
+ pcal_date, pcal_beg, pcal_end,
+ rapt->mesg);
+ break;
+ default:
+ EXIT(_("incoherent repetition type"));
+ }
+ } else {
+ const long YEAR_START =
+ ui_calendar_start_of_year();
+ const long YEAR_END = ui_calendar_end_of_year();
- if (rapt->start < YEAR_END && rapt->start > YEAR_START)
- foreach_date_dump(YEAR_END, rapt->rpt, &rapt->exc, rapt->start,
- rapt->dur, rapt->mesg,
- (cb_dump_t) pcal_dump_apoint, stream);
- }
- }
+ if (rapt->start < YEAR_END
+ && rapt->start > YEAR_START)
+ foreach_date_dump(YEAR_END, rapt->rpt,
+ &rapt->exc, rapt->start,
+ rapt->dur, rapt->mesg,
+ (cb_dump_t)
+ pcal_dump_apoint,
+ stream);
+ }
+ }
}
static void pcal_export_apoints(FILE * stream)
{
- llist_item_t *i;
+ llist_item_t *i;
- fputs("\n# ============\n# Appointments\n# ============\n", stream);
- LLIST_TS_LOCK(&alist_p);
- LLIST_TS_FOREACH(&alist_p, i) {
- struct apoint *apt = LLIST_TS_GET_DATA(i);
- pcal_dump_apoint(stream, apt->start, apt->dur, apt->mesg);
- }
- LLIST_TS_UNLOCK(&alist_p);
- fputc('\n', stream);
+ fputs("\n# ============\n# Appointments\n# ============\n",
+ stream);
+ LLIST_TS_LOCK(&alist_p);
+ LLIST_TS_FOREACH(&alist_p, i) {
+ struct apoint *apt = LLIST_TS_GET_DATA(i);
+ pcal_dump_apoint(stream, apt->start, apt->dur, apt->mesg);
+ }
+ LLIST_TS_UNLOCK(&alist_p);
+ fputc('\n', stream);
}
static void pcal_export_todo(FILE * stream)
{
- llist_item_t *i;
+ llist_item_t *i;
- fputs("#\n# Todos\n#\n", stream);
- LLIST_FOREACH(&todolist, i) {
- struct todo *todo = LLIST_TS_GET_DATA(i);
- if (todo->id < 0) /* completed items */
- continue;
+ fputs("#\n# Todos\n#\n", stream);
+ LLIST_FOREACH(&todolist, i) {
+ struct todo *todo = LLIST_TS_GET_DATA(i);
+ if (todo->id < 0) /* completed items */
+ continue;
- fputs("note all ", stream);
- fprintf(stream, "%d. %s\n", todo->id, todo->mesg);
- }
- fputc('\n', stream);
+ fputs("note all ", stream);
+ fprintf(stream, "%d. %s\n", todo->id, todo->mesg);
+ }
+ fputc('\n', stream);
}
/* Export calcurse data. */
void pcal_export_data(FILE * stream)
{
- pcal_export_header(stream);
- pcal_export_recur_events(stream);
- pcal_export_events(stream);
- pcal_export_recur_apoints(stream);
- pcal_export_apoints(stream);
- pcal_export_todo(stream);
- pcal_export_footer(stream);
+ pcal_export_header(stream);
+ pcal_export_recur_events(stream);
+ pcal_export_events(stream);
+ pcal_export_recur_apoints(stream);
+ pcal_export_apoints(stream);
+ pcal_export_todo(stream);
+ pcal_export_footer(stream);
}
diff --git a/src/recur.c b/src/recur.c
index 8a2f79f..9ac0363 100644
--- a/src/recur.c
+++ b/src/recur.c
@@ -47,198 +47,202 @@ llist_t recur_elist;
static void free_exc(struct excp *exc)
{
- mem_free(exc);
+ mem_free(exc);
}
static void free_exc_list(llist_t * exc)
{
- LLIST_FREE_INNER(exc, free_exc);
- LLIST_FREE(exc);
+ LLIST_FREE_INNER(exc, free_exc);
+ LLIST_FREE(exc);
}
static int exc_cmp_day(struct excp *a, struct excp *b)
{
- return a->st < b->st ? -1 : (a->st == b->st ? 0 : 1);
+ return a->st < b->st ? -1 : (a->st == b->st ? 0 : 1);
}
static void recur_add_exc(llist_t * exc, long day)
{
- struct excp *o = mem_malloc(sizeof(struct excp));
- o->st = day;
+ struct excp *o = mem_malloc(sizeof(struct excp));
+ o->st = day;
- LLIST_ADD_SORTED(exc, o, exc_cmp_day);
+ LLIST_ADD_SORTED(exc, o, exc_cmp_day);
}
static void exc_dup(llist_t * in, llist_t * exc)
{
- llist_item_t *i;
+ llist_item_t *i;
- LLIST_INIT(in);
+ LLIST_INIT(in);
- if (exc) {
- LLIST_FOREACH(exc, i) {
- struct excp *p = LLIST_GET_DATA(i);
- recur_add_exc(in, p->st);
- }
- }
+ if (exc) {
+ LLIST_FOREACH(exc, i) {
+ struct excp *p = LLIST_GET_DATA(i);
+ recur_add_exc(in, p->st);
+ }
+ }
}
struct recur_event *recur_event_dup(struct recur_event *in)
{
- EXIT_IF(!in, _("null pointer"));
+ EXIT_IF(!in, _("null pointer"));
- struct recur_event *rev = mem_malloc(sizeof(struct recur_event));
+ struct recur_event *rev = mem_malloc(sizeof(struct recur_event));
- rev->id = in->id;
- rev->day = in->day;
- rev->mesg = mem_strdup(in->mesg);
+ rev->id = in->id;
+ rev->day = in->day;
+ rev->mesg = mem_strdup(in->mesg);
- rev->rpt = mem_malloc(sizeof(struct rpt));
- rev->rpt->type = in->rpt->type;
- rev->rpt->freq = in->rpt->freq;
- rev->rpt->until = in->rpt->until;
+ rev->rpt = mem_malloc(sizeof(struct rpt));
+ rev->rpt->type = in->rpt->type;
+ rev->rpt->freq = in->rpt->freq;
+ rev->rpt->until = in->rpt->until;
- exc_dup(&rev->exc, &in->exc);
+ exc_dup(&rev->exc, &in->exc);
- if (in->note)
- rev->note = mem_strdup(in->note);
- else
- rev->note = NULL;
+ if (in->note)
+ rev->note = mem_strdup(in->note);
+ else
+ rev->note = NULL;
- return rev;
+ return rev;
}
struct recur_apoint *recur_apoint_dup(struct recur_apoint *in)
{
- EXIT_IF(!in, _("null pointer"));
+ EXIT_IF(!in, _("null pointer"));
- struct recur_apoint *rapt = mem_malloc(sizeof(struct recur_apoint));
+ struct recur_apoint *rapt =
+ mem_malloc(sizeof(struct recur_apoint));
- rapt->start = in->start;
- rapt->dur = in->dur;
- rapt->state = in->state;
- rapt->mesg = mem_strdup(in->mesg);
+ rapt->start = in->start;
+ rapt->dur = in->dur;
+ rapt->state = in->state;
+ rapt->mesg = mem_strdup(in->mesg);
- rapt->rpt = mem_malloc(sizeof(struct rpt));
- rapt->rpt->type = in->rpt->type;
- rapt->rpt->freq = in->rpt->freq;
- rapt->rpt->until = in->rpt->until;
+ rapt->rpt = mem_malloc(sizeof(struct rpt));
+ rapt->rpt->type = in->rpt->type;
+ rapt->rpt->freq = in->rpt->freq;
+ rapt->rpt->until = in->rpt->until;
- exc_dup(&rapt->exc, &in->exc);
+ exc_dup(&rapt->exc, &in->exc);
- if (in->note)
- rapt->note = mem_strdup(in->note);
- else
- rapt->note = NULL;
+ if (in->note)
+ rapt->note = mem_strdup(in->note);
+ else
+ rapt->note = NULL;
- return rapt;
+ return rapt;
}
void recur_apoint_llist_init(void)
{
- LLIST_TS_INIT(&recur_alist_p);
+ LLIST_TS_INIT(&recur_alist_p);
}
void recur_apoint_free(struct recur_apoint *rapt)
{
- mem_free(rapt->mesg);
- if (rapt->note)
- mem_free(rapt->note);
- if (rapt->rpt)
- mem_free(rapt->rpt);
- free_exc_list(&rapt->exc);
- mem_free(rapt);
+ mem_free(rapt->mesg);
+ if (rapt->note)
+ mem_free(rapt->note);
+ if (rapt->rpt)
+ mem_free(rapt->rpt);
+ free_exc_list(&rapt->exc);
+ mem_free(rapt);
}
void recur_event_free(struct recur_event *rev)
{
- mem_free(rev->mesg);
- if (rev->note)
- mem_free(rev->note);
- if (rev->rpt)
- mem_free(rev->rpt);
- free_exc_list(&rev->exc);
- mem_free(rev);
+ mem_free(rev->mesg);
+ if (rev->note)
+ mem_free(rev->note);
+ if (rev->rpt)
+ mem_free(rev->rpt);
+ free_exc_list(&rev->exc);
+ mem_free(rev);
}
void recur_apoint_llist_free(void)
{
- LLIST_TS_FREE_INNER(&recur_alist_p, recur_apoint_free);
- LLIST_TS_FREE(&recur_alist_p);
+ LLIST_TS_FREE_INNER(&recur_alist_p, recur_apoint_free);
+ LLIST_TS_FREE(&recur_alist_p);
}
void recur_event_llist_free(void)
{
- LLIST_FREE_INNER(&recur_elist, recur_event_free);
- LLIST_FREE(&recur_elist);
+ LLIST_FREE_INNER(&recur_elist, recur_event_free);
+ LLIST_FREE(&recur_elist);
}
static int
recur_apoint_cmp_start(struct recur_apoint *a, struct recur_apoint *b)
{
- return a->start < b->start ? -1 : (a->start == b->start ? 0 : 1);
+ return a->start < b->start ? -1 : (a->start == b->start ? 0 : 1);
}
-static int recur_event_cmp_day(struct recur_event *a, struct recur_event *b)
+static int recur_event_cmp_day(struct recur_event *a,
+ struct recur_event *b)
{
- return a->day < b->day ? -1 : (a->day == b->day ? 0 : 1);
+ return a->day < b->day ? -1 : (a->day == b->day ? 0 : 1);
}
/* Insert a new recursive appointment in the general linked list */
struct recur_apoint *recur_apoint_new(char *mesg, char *note, long start,
- long dur, char state, int type, int freq,
- long until, llist_t * except)
-{
- struct recur_apoint *rapt = mem_malloc(sizeof(struct recur_apoint));
-
- rapt->rpt = mem_malloc(sizeof(struct rpt));
- rapt->mesg = mem_strdup(mesg);
- rapt->note = (note != NULL) ? mem_strdup(note) : 0;
- rapt->start = start;
- rapt->state = state;
- rapt->dur = dur;
- rapt->rpt->type = type;
- rapt->rpt->freq = freq;
- rapt->rpt->until = until;
- if (except) {
- exc_dup(&rapt->exc, except);
- free_exc_list(except);
- } else {
- LLIST_INIT(&rapt->exc);
- }
-
- LLIST_TS_LOCK(&recur_alist_p);
- LLIST_TS_ADD_SORTED(&recur_alist_p, rapt, recur_apoint_cmp_start);
- LLIST_TS_UNLOCK(&recur_alist_p);
-
- return rapt;
+ long dur, char state, int type,
+ int freq, long until,
+ llist_t * except)
+{
+ struct recur_apoint *rapt =
+ mem_malloc(sizeof(struct recur_apoint));
+
+ rapt->rpt = mem_malloc(sizeof(struct rpt));
+ rapt->mesg = mem_strdup(mesg);
+ rapt->note = (note != NULL) ? mem_strdup(note) : 0;
+ rapt->start = start;
+ rapt->state = state;
+ rapt->dur = dur;
+ rapt->rpt->type = type;
+ rapt->rpt->freq = freq;
+ rapt->rpt->until = until;
+ if (except) {
+ exc_dup(&rapt->exc, except);
+ free_exc_list(except);
+ } else {
+ LLIST_INIT(&rapt->exc);
+ }
+
+ LLIST_TS_LOCK(&recur_alist_p);
+ LLIST_TS_ADD_SORTED(&recur_alist_p, rapt, recur_apoint_cmp_start);
+ LLIST_TS_UNLOCK(&recur_alist_p);
+
+ return rapt;
}
/* Insert a new recursive event in the general linked list */
-struct recur_event *recur_event_new(char *mesg, char *note, long day, int id,
- int type, int freq, long until,
- llist_t * except)
+struct recur_event *recur_event_new(char *mesg, char *note, long day,
+ int id, int type, int freq, long until,
+ llist_t * except)
{
- struct recur_event *rev = mem_malloc(sizeof(struct recur_event));
+ struct recur_event *rev = mem_malloc(sizeof(struct recur_event));
- rev->rpt = mem_malloc(sizeof(struct rpt));
- rev->mesg = mem_strdup(mesg);
- rev->note = (note != NULL) ? mem_strdup(note) : 0;
- rev->day = day;
- rev->id = id;
- rev->rpt->type = type;
- rev->rpt->freq = freq;
- rev->rpt->until = until;
- if (except) {
- exc_dup(&rev->exc, except);
- free_exc_list(except);
- } else {
- LLIST_INIT(&rev->exc);
- }
+ rev->rpt = mem_malloc(sizeof(struct rpt));
+ rev->mesg = mem_strdup(mesg);
+ rev->note = (note != NULL) ? mem_strdup(note) : 0;
+ rev->day = day;
+ rev->id = id;
+ rev->rpt->type = type;
+ rev->rpt->freq = freq;
+ rev->rpt->until = until;
+ if (except) {
+ exc_dup(&rev->exc, except);
+ free_exc_list(except);
+ } else {
+ LLIST_INIT(&rev->exc);
+ }
- LLIST_ADD_SORTED(&recur_elist, rev, recur_event_cmp_day);
+ LLIST_ADD_SORTED(&recur_elist, rev, recur_event_cmp_day);
- return rev;
+ return rev;
}
/*
@@ -247,27 +251,27 @@ struct recur_event *recur_event_new(char *mesg, char *note, long day, int id,
*/
char recur_def2char(enum recur_type define)
{
- char recur_char;
-
- switch (define) {
- case RECUR_DAILY:
- recur_char = 'D';
- break;
- case RECUR_WEEKLY:
- recur_char = 'W';
- break;
- case RECUR_MONTHLY:
- recur_char = 'M';
- break;
- case RECUR_YEARLY:
- recur_char = 'Y';
- break;
- default:
- EXIT(_("unknown repetition type"));
- return 0;
- }
-
- return recur_char;
+ char recur_char;
+
+ switch (define) {
+ case RECUR_DAILY:
+ recur_char = 'D';
+ break;
+ case RECUR_WEEKLY:
+ recur_char = 'W';
+ break;
+ case RECUR_MONTHLY:
+ recur_char = 'M';
+ break;
+ case RECUR_YEARLY:
+ recur_char = 'Y';
+ break;
+ default:
+ EXIT(_("unknown repetition type"));
+ return 0;
+ }
+
+ return recur_char;
}
/*
@@ -276,225 +280,230 @@ char recur_def2char(enum recur_type define)
*/
int recur_char2def(char type)
{
- int recur_def;
-
- switch (type) {
- case 'D':
- recur_def = RECUR_DAILY;
- break;
- case 'W':
- recur_def = RECUR_WEEKLY;
- break;
- case 'M':
- recur_def = RECUR_MONTHLY;
- break;
- case 'Y':
- recur_def = RECUR_YEARLY;
- break;
- default:
- EXIT(_("unknown character"));
- return 0;
- }
- return recur_def;
+ int recur_def;
+
+ switch (type) {
+ case 'D':
+ recur_def = RECUR_DAILY;
+ break;
+ case 'W':
+ recur_def = RECUR_WEEKLY;
+ break;
+ case 'M':
+ recur_def = RECUR_MONTHLY;
+ break;
+ case 'Y':
+ recur_def = RECUR_YEARLY;
+ break;
+ default:
+ EXIT(_("unknown character"));
+ return 0;
+ }
+ return recur_def;
}
/* Write days for which recurrent items should not be repeated. */
static void recur_write_exc(llist_t * lexc, FILE * f)
{
- llist_item_t *i;
- struct tm lt;
- time_t t;
- int st_mon, st_day, st_year;
+ llist_item_t *i;
+ struct tm lt;
+ time_t t;
+ int st_mon, st_day, st_year;
- LLIST_FOREACH(lexc, i) {
- struct excp *exc = LLIST_GET_DATA(i);
- t = exc->st;
- localtime_r(&t, &lt);
- st_mon = lt.tm_mon + 1;
- st_day = lt.tm_mday;
- st_year = lt.tm_year + 1900;
- fprintf(f, " !%02u/%02u/%04u", st_mon, st_day, st_year);
- }
+ LLIST_FOREACH(lexc, i) {
+ struct excp *exc = LLIST_GET_DATA(i);
+ t = exc->st;
+ localtime_r(&t, &lt);
+ st_mon = lt.tm_mon + 1;
+ st_day = lt.tm_mday;
+ st_year = lt.tm_year + 1900;
+ fprintf(f, " !%02u/%02u/%04u", st_mon, st_day, st_year);
+ }
}
/* Load the recursive appointment description */
-struct recur_apoint *recur_apoint_scan(FILE * f, struct tm start, struct tm end,
- char type, int freq, struct tm until,
- char *note, llist_t * exc, char state)
-{
- char buf[BUFSIZ], *nl;
- time_t tstart, tend, tuntil;
-
- EXIT_IF(!check_date(start.tm_year, start.tm_mon, start.tm_mday) ||
- !check_date(end.tm_year, end.tm_mon, end.tm_mday) ||
- !check_time(start.tm_hour, start.tm_min) ||
- !check_time(end.tm_hour, end.tm_min) ||
- (until.tm_year != 0 && !check_date(until.tm_year, until.tm_mon,
- until.tm_mday)),
- _("date error in appointment"));
-
- /* Read the appointment description */
- if (!fgets(buf, sizeof buf, f))
- return NULL;
-
- nl = strchr(buf, '\n');
- if (nl) {
- *nl = '\0';
- }
- start.tm_sec = end.tm_sec = 0;
- start.tm_isdst = end.tm_isdst = -1;
- start.tm_year -= 1900;
- start.tm_mon--;
- end.tm_year -= 1900;
- end.tm_mon--;
- tstart = mktime(&start);
- tend = mktime(&end);
-
- if (until.tm_year != 0) {
- until.tm_hour = 23;
- until.tm_min = 59;
- until.tm_sec = 0;
- until.tm_isdst = -1;
- until.tm_year -= 1900;
- until.tm_mon--;
- tuntil = mktime(&until);
- } else {
- tuntil = 0;
- }
- EXIT_IF(tstart == -1 || tend == -1 || tstart > tend || tuntil == -1,
- _("date error in appointment"));
-
- return recur_apoint_new(buf, note, tstart, tend - tstart, state,
- recur_char2def(type), freq, tuntil, exc);
+struct recur_apoint *recur_apoint_scan(FILE * f, struct tm start,
+ struct tm end, char type, int freq,
+ struct tm until, char *note,
+ llist_t * exc, char state)
+{
+ char buf[BUFSIZ], *nl;
+ time_t tstart, tend, tuntil;
+
+ EXIT_IF(!check_date(start.tm_year, start.tm_mon, start.tm_mday) ||
+ !check_date(end.tm_year, end.tm_mon, end.tm_mday) ||
+ !check_time(start.tm_hour, start.tm_min) ||
+ !check_time(end.tm_hour, end.tm_min) ||
+ (until.tm_year != 0
+ && !check_date(until.tm_year, until.tm_mon,
+ until.tm_mday)),
+ _("date error in appointment"));
+
+ /* Read the appointment description */
+ if (!fgets(buf, sizeof buf, f))
+ return NULL;
+
+ nl = strchr(buf, '\n');
+ if (nl) {
+ *nl = '\0';
+ }
+ start.tm_sec = end.tm_sec = 0;
+ start.tm_isdst = end.tm_isdst = -1;
+ start.tm_year -= 1900;
+ start.tm_mon--;
+ end.tm_year -= 1900;
+ end.tm_mon--;
+ tstart = mktime(&start);
+ tend = mktime(&end);
+
+ if (until.tm_year != 0) {
+ until.tm_hour = 23;
+ until.tm_min = 59;
+ until.tm_sec = 0;
+ until.tm_isdst = -1;
+ until.tm_year -= 1900;
+ until.tm_mon--;
+ tuntil = mktime(&until);
+ } else {
+ tuntil = 0;
+ }
+ EXIT_IF(tstart == -1 || tend == -1 || tstart > tend
+ || tuntil == -1, _("date error in appointment"));
+
+ return recur_apoint_new(buf, note, tstart, tend - tstart, state,
+ recur_char2def(type), freq, tuntil, exc);
}
/* Load the recursive events from file */
struct recur_event *recur_event_scan(FILE * f, struct tm start, int id,
- char type, int freq, struct tm until,
- char *note, llist_t * exc)
-{
- char buf[BUFSIZ], *nl;
- time_t tstart, tuntil;
-
- EXIT_IF(!check_date(start.tm_year, start.tm_mon, start.tm_mday) ||
- !check_time(start.tm_hour, start.tm_min) ||
- (until.tm_year != 0 && !check_date(until.tm_year, until.tm_mon,
- until.tm_mday)),
- _("date error in event"));
-
- /* Read the event description */
- if (!fgets(buf, sizeof buf, f))
- return NULL;
-
- nl = strchr(buf, '\n');
- if (nl) {
- *nl = '\0';
- }
- start.tm_hour = until.tm_hour = 0;
- start.tm_min = until.tm_min = 0;
- start.tm_sec = until.tm_sec = 0;
- start.tm_isdst = until.tm_isdst = -1;
- start.tm_year -= 1900;
- start.tm_mon--;
- if (until.tm_year != 0) {
- until.tm_year -= 1900;
- until.tm_mon--;
- tuntil = mktime(&until);
- } else {
- tuntil = 0;
- }
- tstart = mktime(&start);
- EXIT_IF(tstart == -1 || tuntil == -1, _("date error in event"));
-
- return recur_event_new(buf, note, tstart, id, recur_char2def(type), freq,
- tuntil, exc);
+ char type, int freq, struct tm until,
+ char *note, llist_t * exc)
+{
+ char buf[BUFSIZ], *nl;
+ time_t tstart, tuntil;
+
+ EXIT_IF(!check_date(start.tm_year, start.tm_mon, start.tm_mday) ||
+ !check_time(start.tm_hour, start.tm_min) ||
+ (until.tm_year != 0
+ && !check_date(until.tm_year, until.tm_mon,
+ until.tm_mday)), _("date error in event"));
+
+ /* Read the event description */
+ if (!fgets(buf, sizeof buf, f))
+ return NULL;
+
+ nl = strchr(buf, '\n');
+ if (nl) {
+ *nl = '\0';
+ }
+ start.tm_hour = until.tm_hour = 0;
+ start.tm_min = until.tm_min = 0;
+ start.tm_sec = until.tm_sec = 0;
+ start.tm_isdst = until.tm_isdst = -1;
+ start.tm_year -= 1900;
+ start.tm_mon--;
+ if (until.tm_year != 0) {
+ until.tm_year -= 1900;
+ until.tm_mon--;
+ tuntil = mktime(&until);
+ } else {
+ tuntil = 0;
+ }
+ tstart = mktime(&start);
+ EXIT_IF(tstart == -1 || tuntil == -1, _("date error in event"));
+
+ return recur_event_new(buf, note, tstart, id, recur_char2def(type),
+ freq, tuntil, exc);
}
/* Writting of a recursive appointment into file. */
void recur_apoint_write(struct recur_apoint *o, FILE * f)
{
- struct tm lt;
- time_t t;
-
- t = o->start;
- localtime_r(&t, &lt);
- fprintf(f, "%02u/%02u/%04u @ %02u:%02u", lt.tm_mon + 1, lt.tm_mday,
- 1900 + lt.tm_year, lt.tm_hour, lt.tm_min);
-
- t = o->start + o->dur;
- localtime_r(&t, &lt);
- fprintf(f, " -> %02u/%02u/%04u @ %02u:%02u", lt.tm_mon + 1, lt.tm_mday,
- 1900 + lt.tm_year, lt.tm_hour, lt.tm_min);
-
- t = o->rpt->until;
- if (t == 0) { /* We have an endless recurrent appointment. */
- fprintf(f, " {%d%c", o->rpt->freq, recur_def2char(o->rpt->type));
- } else {
- localtime_r(&t, &lt);
- fprintf(f, " {%d%c -> %02u/%02u/%04u", o->rpt->freq,
- recur_def2char(o->rpt->type), lt.tm_mon + 1, lt.tm_mday,
- 1900 + lt.tm_year);
- }
- recur_write_exc(&o->exc, f);
- fputs("} ", f);
- if (o->note != NULL)
- fprintf(f, ">%s ", o->note);
- if (o->state & APOINT_NOTIFY)
- fputc('!', f);
- else
- fputc('|', f);
- fprintf(f, "%s\n", o->mesg);
+ struct tm lt;
+ time_t t;
+
+ t = o->start;
+ localtime_r(&t, &lt);
+ fprintf(f, "%02u/%02u/%04u @ %02u:%02u", lt.tm_mon + 1, lt.tm_mday,
+ 1900 + lt.tm_year, lt.tm_hour, lt.tm_min);
+
+ t = o->start + o->dur;
+ localtime_r(&t, &lt);
+ fprintf(f, " -> %02u/%02u/%04u @ %02u:%02u", lt.tm_mon + 1,
+ lt.tm_mday, 1900 + lt.tm_year, lt.tm_hour, lt.tm_min);
+
+ t = o->rpt->until;
+ if (t == 0) { /* We have an endless recurrent appointment. */
+ fprintf(f, " {%d%c", o->rpt->freq,
+ recur_def2char(o->rpt->type));
+ } else {
+ localtime_r(&t, &lt);
+ fprintf(f, " {%d%c -> %02u/%02u/%04u", o->rpt->freq,
+ recur_def2char(o->rpt->type), lt.tm_mon + 1,
+ lt.tm_mday, 1900 + lt.tm_year);
+ }
+ recur_write_exc(&o->exc, f);
+ fputs("} ", f);
+ if (o->note != NULL)
+ fprintf(f, ">%s ", o->note);
+ if (o->state & APOINT_NOTIFY)
+ fputc('!', f);
+ else
+ fputc('|', f);
+ fprintf(f, "%s\n", o->mesg);
}
/* Writting of a recursive event into file. */
void recur_event_write(struct recur_event *o, FILE * f)
{
- struct tm lt;
- time_t t;
- int st_mon, st_day, st_year;
- int end_mon, end_day, end_year;
-
- t = o->day;
- localtime_r(&t, &lt);
- st_mon = lt.tm_mon + 1;
- st_day = lt.tm_mday;
- st_year = lt.tm_year + 1900;
- t = o->rpt->until;
- if (t == 0) { /* We have an endless recurrent event. */
- fprintf(f, "%02u/%02u/%04u [%d] {%d%c", st_mon, st_day, st_year, o->id,
- o->rpt->freq, recur_def2char(o->rpt->type));
- } else {
- localtime_r(&t, &lt);
- end_mon = lt.tm_mon + 1;
- end_day = lt.tm_mday;
- end_year = lt.tm_year + 1900;
- fprintf(f, "%02u/%02u/%04u [%d] {%d%c -> %02u/%02u/%04u", st_mon,
- st_day, st_year, o->id, o->rpt->freq,
- recur_def2char(o->rpt->type), end_mon, end_day, end_year);
- }
- recur_write_exc(&o->exc, f);
- fputs("} ", f);
- if (o->note != NULL)
- fprintf(f, ">%s ", o->note);
- fprintf(f, "%s\n", o->mesg);
+ struct tm lt;
+ time_t t;
+ int st_mon, st_day, st_year;
+ int end_mon, end_day, end_year;
+
+ t = o->day;
+ localtime_r(&t, &lt);
+ st_mon = lt.tm_mon + 1;
+ st_day = lt.tm_mday;
+ st_year = lt.tm_year + 1900;
+ t = o->rpt->until;
+ if (t == 0) { /* We have an endless recurrent event. */
+ fprintf(f, "%02u/%02u/%04u [%d] {%d%c", st_mon, st_day,
+ st_year, o->id, o->rpt->freq,
+ recur_def2char(o->rpt->type));
+ } else {
+ localtime_r(&t, &lt);
+ end_mon = lt.tm_mon + 1;
+ end_day = lt.tm_mday;
+ end_year = lt.tm_year + 1900;
+ fprintf(f, "%02u/%02u/%04u [%d] {%d%c -> %02u/%02u/%04u",
+ st_mon, st_day, st_year, o->id, o->rpt->freq,
+ recur_def2char(o->rpt->type), end_mon, end_day,
+ end_year);
+ }
+ recur_write_exc(&o->exc, f);
+ fputs("} ", f);
+ if (o->note != NULL)
+ fprintf(f, ">%s ", o->note);
+ fprintf(f, "%s\n", o->mesg);
}
/* Write recursive items to file. */
void recur_save_data(FILE * f)
{
- llist_item_t *i;
+ llist_item_t *i;
- LLIST_FOREACH(&recur_elist, i) {
- struct recur_event *rev = LLIST_GET_DATA(i);
- recur_event_write(rev, f);
- }
+ LLIST_FOREACH(&recur_elist, i) {
+ struct recur_event *rev = LLIST_GET_DATA(i);
+ recur_event_write(rev, f);
+ }
- LLIST_TS_LOCK(&recur_alist_p);
- LLIST_TS_FOREACH(&recur_alist_p, i) {
- struct recur_apoint *rapt = LLIST_GET_DATA(i);
- recur_apoint_write(rapt, f);
- }
- LLIST_TS_UNLOCK(&recur_alist_p);
+ LLIST_TS_LOCK(&recur_alist_p);
+ LLIST_TS_FOREACH(&recur_alist_p, i) {
+ struct recur_apoint *rapt = LLIST_GET_DATA(i);
+ recur_apoint_write(rapt, f);
+ }
+ LLIST_TS_UNLOCK(&recur_alist_p);
}
/*
@@ -512,45 +521,45 @@ void recur_save_data(FILE * f)
/* Calculate the difference in days between two dates. */
static long diff_days(struct tm lt_start, struct tm lt_end)
{
- long diff;
+ long diff;
- if (lt_end.tm_year < lt_start.tm_year)
- return 0;
+ if (lt_end.tm_year < lt_start.tm_year)
+ return 0;
- diff = lt_end.tm_yday - lt_start.tm_yday;
+ diff = lt_end.tm_yday - lt_start.tm_yday;
- if (lt_end.tm_year > lt_start.tm_year) {
- diff += (lt_end.tm_year - lt_start.tm_year) * YEARINDAYS;
- diff += LEAPCOUNT(lt_start.tm_year + TM_YEAR_BASE,
- lt_end.tm_year + TM_YEAR_BASE - 1);
- }
+ if (lt_end.tm_year > lt_start.tm_year) {
+ diff += (lt_end.tm_year - lt_start.tm_year) * YEARINDAYS;
+ diff += LEAPCOUNT(lt_start.tm_year + TM_YEAR_BASE,
+ lt_end.tm_year + TM_YEAR_BASE - 1);
+ }
- return diff;
+ return diff;
}
/* Calculate the difference in months between two dates. */
static long diff_months(struct tm lt_start, struct tm lt_end)
{
- long diff;
+ long diff;
- if (lt_end.tm_year < lt_start.tm_year)
- return 0;
+ if (lt_end.tm_year < lt_start.tm_year)
+ return 0;
- diff = lt_end.tm_mon - lt_start.tm_mon;
- diff += (lt_end.tm_year - lt_start.tm_year) * YEARINMONTHS;
+ diff = lt_end.tm_mon - lt_start.tm_mon;
+ diff += (lt_end.tm_year - lt_start.tm_year) * YEARINMONTHS;
- return diff;
+ return diff;
}
/* Calculate the difference in years between two dates. */
static long diff_years(struct tm lt_start, struct tm lt_end)
{
- return lt_end.tm_year - lt_start.tm_year;
+ return lt_end.tm_year - lt_start.tm_year;
}
static int exc_inday(struct excp *exc, long *day_start)
{
- return (exc->st >= *day_start && exc->st < *day_start + DAYINSEC);
+ return (exc->st >= *day_start && exc->st < *day_start + DAYINSEC);
}
/*
@@ -563,189 +572,198 @@ static int exc_inday(struct excp *exc, long *day_start)
* calculation of recurrent dates after a turn of years.
*/
unsigned
-recur_item_find_occurrence(long item_start, long item_dur, llist_t * item_exc,
- int rpt_type, int rpt_freq, long rpt_until,
- long day_start, unsigned *occurrence)
-{
- struct date start_date;
- long diff, span;
- struct tm lt_day, lt_item, lt_item_day;
- time_t t;
-
- if (day_start < item_start - DAYINSEC + 1)
- return 0;
-
- if (rpt_until != 0 && day_start >= rpt_until + item_dur)
- return 0;
-
- t = day_start;
- localtime_r(&t, &lt_day);
-
- t = item_start;
- localtime_r(&t, &lt_item);
-
- lt_item_day = lt_item;
- lt_item_day.tm_sec = lt_item_day.tm_min = lt_item_day.tm_hour = 0;
-
- span = (item_start - mktime(&lt_item_day) + item_dur - 1) / DAYINSEC;
-
- switch (rpt_type) {
- case RECUR_DAILY:
- diff = diff_days(lt_item_day, lt_day) % rpt_freq;
- lt_item_day.tm_mday = lt_day.tm_mday - diff;
- lt_item_day.tm_mon = lt_day.tm_mon;
- lt_item_day.tm_year = lt_day.tm_year;
- break;
- case RECUR_WEEKLY:
- diff = diff_days(lt_item_day, lt_day) % (rpt_freq * WEEKINDAYS);
- lt_item_day.tm_mday = lt_day.tm_mday - diff;
- lt_item_day.tm_mon = lt_day.tm_mon;
- lt_item_day.tm_year = lt_day.tm_year;
- break;
- case RECUR_MONTHLY:
- diff = diff_months(lt_item_day, lt_day) % rpt_freq;
- if (lt_day.tm_mday < lt_item_day.tm_mday)
- diff++;
- lt_item_day.tm_mon = lt_day.tm_mon - diff;
- lt_item_day.tm_year = lt_day.tm_year;
- break;
- case RECUR_YEARLY:
- diff = diff_years(lt_item_day, lt_day) % rpt_freq;
- if (lt_day.tm_mon < lt_item_day.tm_mon ||
- (lt_day.tm_mon == lt_item_day.tm_mon &&
- lt_day.tm_mday < lt_item_day.tm_mday))
- diff++;
- lt_item_day.tm_year = lt_day.tm_year - diff;
- break;
- default:
- EXIT(_("unknown item type"));
- }
-
- lt_item_day.tm_isdst = lt_day.tm_isdst;
- t = mktime(&lt_item_day);
-
- if (LLIST_FIND_FIRST(item_exc, &t, exc_inday))
- return 0;
-
- if (rpt_until != 0 && t > rpt_until)
- return 0;
-
- localtime_r(&t, &lt_item_day);
- diff = diff_days(lt_item_day, lt_day);
-
- if (diff <= span) {
- if (occurrence) {
- start_date.dd = lt_item_day.tm_mday;
- start_date.mm = lt_item_day.tm_mon + 1;
- start_date.yyyy = lt_item_day.tm_year + 1900;
-
- *occurrence = date2sec(start_date, lt_item.tm_hour, lt_item.tm_min);
- }
-
- return 1;
- } else {
- return 0;
- }
+recur_item_find_occurrence(long item_start, long item_dur,
+ llist_t * item_exc, int rpt_type, int rpt_freq,
+ long rpt_until, long day_start,
+ unsigned *occurrence)
+{
+ struct date start_date;
+ long diff, span;
+ struct tm lt_day, lt_item, lt_item_day;
+ time_t t;
+
+ if (day_start < item_start - DAYINSEC + 1)
+ return 0;
+
+ if (rpt_until != 0 && day_start >= rpt_until + item_dur)
+ return 0;
+
+ t = day_start;
+ localtime_r(&t, &lt_day);
+
+ t = item_start;
+ localtime_r(&t, &lt_item);
+
+ lt_item_day = lt_item;
+ lt_item_day.tm_sec = lt_item_day.tm_min = lt_item_day.tm_hour = 0;
+
+ span =
+ (item_start - mktime(&lt_item_day) + item_dur - 1) / DAYINSEC;
+
+ switch (rpt_type) {
+ case RECUR_DAILY:
+ diff = diff_days(lt_item_day, lt_day) % rpt_freq;
+ lt_item_day.tm_mday = lt_day.tm_mday - diff;
+ lt_item_day.tm_mon = lt_day.tm_mon;
+ lt_item_day.tm_year = lt_day.tm_year;
+ break;
+ case RECUR_WEEKLY:
+ diff =
+ diff_days(lt_item_day,
+ lt_day) % (rpt_freq * WEEKINDAYS);
+ lt_item_day.tm_mday = lt_day.tm_mday - diff;
+ lt_item_day.tm_mon = lt_day.tm_mon;
+ lt_item_day.tm_year = lt_day.tm_year;
+ break;
+ case RECUR_MONTHLY:
+ diff = diff_months(lt_item_day, lt_day) % rpt_freq;
+ if (lt_day.tm_mday < lt_item_day.tm_mday)
+ diff++;
+ lt_item_day.tm_mon = lt_day.tm_mon - diff;
+ lt_item_day.tm_year = lt_day.tm_year;
+ break;
+ case RECUR_YEARLY:
+ diff = diff_years(lt_item_day, lt_day) % rpt_freq;
+ if (lt_day.tm_mon < lt_item_day.tm_mon ||
+ (lt_day.tm_mon == lt_item_day.tm_mon &&
+ lt_day.tm_mday < lt_item_day.tm_mday))
+ diff++;
+ lt_item_day.tm_year = lt_day.tm_year - diff;
+ break;
+ default:
+ EXIT(_("unknown item type"));
+ }
+
+ lt_item_day.tm_isdst = lt_day.tm_isdst;
+ t = mktime(&lt_item_day);
+
+ if (LLIST_FIND_FIRST(item_exc, &t, exc_inday))
+ return 0;
+
+ if (rpt_until != 0 && t > rpt_until)
+ return 0;
+
+ localtime_r(&t, &lt_item_day);
+ diff = diff_days(lt_item_day, lt_day);
+
+ if (diff <= span) {
+ if (occurrence) {
+ start_date.dd = lt_item_day.tm_mday;
+ start_date.mm = lt_item_day.tm_mon + 1;
+ start_date.yyyy = lt_item_day.tm_year + 1900;
+
+ *occurrence =
+ date2sec(start_date, lt_item.tm_hour,
+ lt_item.tm_min);
+ }
+
+ return 1;
+ } else {
+ return 0;
+ }
}
unsigned
recur_apoint_find_occurrence(struct recur_apoint *rapt, long day_start,
- unsigned *occurrence)
+ unsigned *occurrence)
{
- return recur_item_find_occurrence(rapt->start, rapt->dur, &rapt->exc,
- rapt->rpt->type, rapt->rpt->freq,
- rapt->rpt->until, day_start, occurrence);
+ return recur_item_find_occurrence(rapt->start, rapt->dur,
+ &rapt->exc, rapt->rpt->type,
+ rapt->rpt->freq,
+ rapt->rpt->until, day_start,
+ occurrence);
}
unsigned
recur_event_find_occurrence(struct recur_event *rev, long day_start,
- unsigned *occurrence)
+ unsigned *occurrence)
{
- return recur_item_find_occurrence(rev->day, DAYINSEC, &rev->exc,
- rev->rpt->type, rev->rpt->freq,
- rev->rpt->until, day_start, occurrence);
+ return recur_item_find_occurrence(rev->day, DAYINSEC, &rev->exc,
+ rev->rpt->type, rev->rpt->freq,
+ rev->rpt->until, day_start,
+ occurrence);
}
/* Check if a recurrent item belongs to the selected day. */
unsigned
recur_item_inday(long item_start, long item_dur, llist_t * item_exc,
- int rpt_type, int rpt_freq, long rpt_until, long day_start)
+ int rpt_type, int rpt_freq, long rpt_until,
+ long day_start)
{
- /* We do not need the (real) start time of the occurrence here, so just
- * ignore the buffer. */
- return recur_item_find_occurrence(item_start, item_dur, item_exc, rpt_type,
- rpt_freq, rpt_until, day_start, NULL);
+ /* We do not need the (real) start time of the occurrence here, so just
+ * ignore the buffer. */
+ return recur_item_find_occurrence(item_start, item_dur, item_exc,
+ rpt_type, rpt_freq, rpt_until,
+ day_start, NULL);
}
unsigned recur_apoint_inday(struct recur_apoint *rapt, long *day_start)
{
- return recur_item_inday(rapt->start, rapt->dur, &rapt->exc, rapt->rpt->type,
- rapt->rpt->freq, rapt->rpt->until, *day_start);
+ return recur_item_inday(rapt->start, rapt->dur, &rapt->exc,
+ rapt->rpt->type, rapt->rpt->freq,
+ rapt->rpt->until, *day_start);
}
unsigned recur_event_inday(struct recur_event *rev, long *day_start)
{
- return recur_item_inday(rev->day, DAYINSEC, &rev->exc, rev->rpt->type,
- rev->rpt->freq, rev->rpt->until, *day_start);
+ return recur_item_inday(rev->day, DAYINSEC, &rev->exc,
+ rev->rpt->type, rev->rpt->freq,
+ rev->rpt->until, *day_start);
}
/* Add an exception to a recurrent event. */
-void
-recur_event_add_exc(struct recur_event *rev, long date)
+void recur_event_add_exc(struct recur_event *rev, long date)
{
- recur_add_exc(&rev->exc, date);
+ recur_add_exc(&rev->exc, date);
}
/* Add an exception to a recurrent appointment. */
-void
-recur_apoint_add_exc(struct recur_apoint *rapt, long date)
+void recur_apoint_add_exc(struct recur_apoint *rapt, long date)
{
- int need_check_notify = 0;
+ int need_check_notify = 0;
- if (notify_bar())
- need_check_notify = notify_same_recur_item(rapt);
- recur_add_exc(&rapt->exc, date);
- if (need_check_notify)
- notify_check_next_app(0);
+ if (notify_bar())
+ need_check_notify = notify_same_recur_item(rapt);
+ recur_add_exc(&rapt->exc, date);
+ if (need_check_notify)
+ notify_check_next_app(0);
}
/*
* Delete a recurrent event from the list (if delete_whole is not null),
* or delete only one occurence of the recurrent event.
*/
-void
-recur_event_erase(struct recur_event *rev)
+void recur_event_erase(struct recur_event *rev)
{
- llist_item_t *i = LLIST_FIND_FIRST(&recur_elist, rev, NULL);
+ llist_item_t *i = LLIST_FIND_FIRST(&recur_elist, rev, NULL);
- if (!i)
- EXIT(_("event not found"));
+ if (!i)
+ EXIT(_("event not found"));
- LLIST_REMOVE(&recur_elist, i);
+ LLIST_REMOVE(&recur_elist, i);
}
/*
* Delete a recurrent appointment from the list (if delete_whole is not null),
* or delete only one occurence of the recurrent appointment.
*/
-void
-recur_apoint_erase(struct recur_apoint *rapt)
+void recur_apoint_erase(struct recur_apoint *rapt)
{
- LLIST_TS_LOCK(&recur_alist_p);
+ LLIST_TS_LOCK(&recur_alist_p);
- llist_item_t *i = LLIST_TS_FIND_FIRST(&recur_alist_p, rapt, NULL);
- int need_check_notify = 0;
+ llist_item_t *i = LLIST_TS_FIND_FIRST(&recur_alist_p, rapt, NULL);
+ int need_check_notify = 0;
- if (!i)
- EXIT(_("appointment not found"));
+ if (!i)
+ EXIT(_("appointment not found"));
- if (notify_bar())
- need_check_notify = notify_same_recur_item(rapt);
- LLIST_TS_REMOVE(&recur_alist_p, i);
- if (need_check_notify)
- notify_check_next_app(0);
+ if (notify_bar())
+ need_check_notify = notify_same_recur_item(rapt);
+ LLIST_TS_REMOVE(&recur_alist_p, i);
+ if (need_check_notify)
+ notify_check_next_app(0);
- LLIST_TS_UNLOCK(&recur_alist_p);
+ LLIST_TS_UNLOCK(&recur_alist_p);
}
/*
@@ -754,116 +772,117 @@ recur_apoint_erase(struct recur_apoint *rapt)
*/
void recur_exc_scan(llist_t * lexc, FILE * data_file)
{
- int c = 0;
- struct tm day;
+ int c = 0;
+ struct tm day;
- LLIST_INIT(lexc);
- while ((c = getc(data_file)) == '!') {
- ungetc(c, data_file);
- if (fscanf(data_file, "!%d / %d / %d ",
- &day.tm_mon, &day.tm_mday, &day.tm_year) != 3) {
- EXIT(_("syntax error in item date"));
- }
+ LLIST_INIT(lexc);
+ while ((c = getc(data_file)) == '!') {
+ ungetc(c, data_file);
+ if (fscanf(data_file, "!%d / %d / %d ",
+ &day.tm_mon, &day.tm_mday, &day.tm_year) != 3) {
+ EXIT(_("syntax error in item date"));
+ }
- EXIT_IF(!check_date(day.tm_year, day.tm_mon, day.tm_mday) ||
- !check_time(day.tm_hour, day.tm_min),
- _("date error in item exception"));
+ EXIT_IF(!check_date(day.tm_year, day.tm_mon, day.tm_mday)
+ || !check_time(day.tm_hour, day.tm_min),
+ _("date error in item exception"));
- day.tm_hour = 0;
- day.tm_min = day.tm_sec = 0;
- day.tm_isdst = -1;
- day.tm_year -= 1900;
- day.tm_mon--;
- struct excp *exc = mem_malloc(sizeof(struct excp));
- exc->st = mktime(&day);
- LLIST_ADD(lexc, exc);
- }
+ day.tm_hour = 0;
+ day.tm_min = day.tm_sec = 0;
+ day.tm_isdst = -1;
+ day.tm_year -= 1900;
+ day.tm_mon--;
+ struct excp *exc = mem_malloc(sizeof(struct excp));
+ exc->st = mktime(&day);
+ LLIST_ADD(lexc, exc);
+ }
}
static int recur_apoint_starts_before(struct recur_apoint *rapt, long time)
{
- return rapt->start < time;
+ return rapt->start < time;
}
/*
* Look in the appointment list if we have an item which starts before the item
* stored in the notify_app structure (which is the next item to be notified).
*/
-struct notify_app *recur_apoint_check_next(struct notify_app *app, long start,
- long day)
+struct notify_app *recur_apoint_check_next(struct notify_app *app,
+ long start, long day)
{
- llist_item_t *i;
- unsigned real_recur_start_time;
+ llist_item_t *i;
+ unsigned real_recur_start_time;
- LLIST_TS_LOCK(&recur_alist_p);
- LLIST_TS_FIND_FOREACH(&recur_alist_p, &app->time, recur_apoint_starts_before,
- i) {
- struct recur_apoint *rapt = LLIST_TS_GET_DATA(i);
+ LLIST_TS_LOCK(&recur_alist_p);
+ LLIST_TS_FIND_FOREACH(&recur_alist_p, &app->time,
+ recur_apoint_starts_before, i) {
+ struct recur_apoint *rapt = LLIST_TS_GET_DATA(i);
- if (recur_apoint_find_occurrence(rapt, day, &real_recur_start_time) &&
- real_recur_start_time > start) {
- app->time = real_recur_start_time;
- app->txt = mem_strdup(rapt->mesg);
- app->state = rapt->state;
- app->got_app = 1;
- }
- }
- LLIST_TS_UNLOCK(&recur_alist_p);
+ if (recur_apoint_find_occurrence
+ (rapt, day, &real_recur_start_time)
+ && real_recur_start_time > start) {
+ app->time = real_recur_start_time;
+ app->txt = mem_strdup(rapt->mesg);
+ app->state = rapt->state;
+ app->got_app = 1;
+ }
+ }
+ LLIST_TS_UNLOCK(&recur_alist_p);
- return app;
+ return app;
}
/* Switch recurrent item notification state. */
void recur_apoint_switch_notify(struct recur_apoint *rapt)
{
- LLIST_TS_LOCK(&recur_alist_p);
+ LLIST_TS_LOCK(&recur_alist_p);
- rapt->state ^= APOINT_NOTIFY;
- if (notify_bar())
- notify_check_repeated(rapt);
+ rapt->state ^= APOINT_NOTIFY;
+ if (notify_bar())
+ notify_check_repeated(rapt);
- LLIST_TS_UNLOCK(&recur_alist_p);
+ LLIST_TS_UNLOCK(&recur_alist_p);
}
void recur_event_paste_item(struct recur_event *rev, long date)
{
- long time_shift;
- llist_item_t *i;
+ long time_shift;
+ llist_item_t *i;
- time_shift = date - rev->day;
- rev->day += time_shift;
+ time_shift = date - rev->day;
+ rev->day += time_shift;
- if (rev->rpt->until != 0)
- rev->rpt->until += time_shift;
+ if (rev->rpt->until != 0)
+ rev->rpt->until += time_shift;
- LLIST_FOREACH(&rev->exc, i) {
- struct excp *exc = LLIST_GET_DATA(i);
- exc->st += time_shift;
- }
+ LLIST_FOREACH(&rev->exc, i) {
+ struct excp *exc = LLIST_GET_DATA(i);
+ exc->st += time_shift;
+ }
- LLIST_ADD_SORTED(&recur_elist, rev, recur_event_cmp_day);
+ LLIST_ADD_SORTED(&recur_elist, rev, recur_event_cmp_day);
}
void recur_apoint_paste_item(struct recur_apoint *rapt, long date)
{
- long time_shift;
- llist_item_t *i;
+ long time_shift;
+ llist_item_t *i;
- time_shift = (date + get_item_time(rapt->start)) - rapt->start;
- rapt->start += time_shift;
+ time_shift = (date + get_item_time(rapt->start)) - rapt->start;
+ rapt->start += time_shift;
- if (rapt->rpt->until != 0)
- rapt->rpt->until += time_shift;
+ if (rapt->rpt->until != 0)
+ rapt->rpt->until += time_shift;
- LLIST_FOREACH(&rapt->exc, i) {
- struct excp *exc = LLIST_GET_DATA(i);
- exc->st += time_shift;
- }
+ LLIST_FOREACH(&rapt->exc, i) {
+ struct excp *exc = LLIST_GET_DATA(i);
+ exc->st += time_shift;
+ }
- LLIST_TS_LOCK(&recur_alist_p);
- LLIST_TS_ADD_SORTED(&recur_alist_p, rapt, recur_apoint_cmp_start);
- LLIST_TS_UNLOCK(&recur_alist_p);
+ LLIST_TS_LOCK(&recur_alist_p);
+ LLIST_TS_ADD_SORTED(&recur_alist_p, rapt, recur_apoint_cmp_start);
+ LLIST_TS_UNLOCK(&recur_alist_p);
- if (notify_bar())
- notify_check_repeated(rapt);
+ if (notify_bar())
+ notify_check_repeated(rapt);
}
diff --git a/src/sha1.c b/src/sha1.c
index ad68bd3..d32c241 100644
--- a/src/sha1.c
+++ b/src/sha1.c
@@ -69,200 +69,203 @@
static void sha1_transform(uint32_t state[5], const uint8_t buffer[64])
{
- typedef union {
- uint8_t c[64];
- uint32_t l[16];
- } b64_t;
+ typedef union {
+ uint8_t c[64];
+ uint32_t l[16];
+ } b64_t;
- b64_t *block = (b64_t *) buffer;
- uint32_t a = state[0];
- uint32_t b = state[1];
- uint32_t c = state[2];
- uint32_t d = state[3];
- uint32_t e = state[4];
+ b64_t *block = (b64_t *) buffer;
+ uint32_t a = state[0];
+ uint32_t b = state[1];
+ uint32_t c = state[2];
+ uint32_t d = state[3];
+ uint32_t e = state[4];
- R0(a, b, c, d, e, 0);
- R0(e, a, b, c, d, 1);
- R0(d, e, a, b, c, 2);
- R0(c, d, e, a, b, 3);
- R0(b, c, d, e, a, 4);
- R0(a, b, c, d, e, 5);
- R0(e, a, b, c, d, 6);
- R0(d, e, a, b, c, 7);
- R0(c, d, e, a, b, 8);
- R0(b, c, d, e, a, 9);
- R0(a, b, c, d, e, 10);
- R0(e, a, b, c, d, 11);
- R0(d, e, a, b, c, 12);
- R0(c, d, e, a, b, 13);
- R0(b, c, d, e, a, 14);
- R0(a, b, c, d, e, 15);
- R1(e, a, b, c, d, 16);
- R1(d, e, a, b, c, 17);
- R1(c, d, e, a, b, 18);
- R1(b, c, d, e, a, 19);
- R2(a, b, c, d, e, 20);
- R2(e, a, b, c, d, 21);
- R2(d, e, a, b, c, 22);
- R2(c, d, e, a, b, 23);
- R2(b, c, d, e, a, 24);
- R2(a, b, c, d, e, 25);
- R2(e, a, b, c, d, 26);
- R2(d, e, a, b, c, 27);
- R2(c, d, e, a, b, 28);
- R2(b, c, d, e, a, 29);
- R2(a, b, c, d, e, 30);
- R2(e, a, b, c, d, 31);
- R2(d, e, a, b, c, 32);
- R2(c, d, e, a, b, 33);
- R2(b, c, d, e, a, 34);
- R2(a, b, c, d, e, 35);
- R2(e, a, b, c, d, 36);
- R2(d, e, a, b, c, 37);
- R2(c, d, e, a, b, 38);
- R2(b, c, d, e, a, 39);
- R3(a, b, c, d, e, 40);
- R3(e, a, b, c, d, 41);
- R3(d, e, a, b, c, 42);
- R3(c, d, e, a, b, 43);
- R3(b, c, d, e, a, 44);
- R3(a, b, c, d, e, 45);
- R3(e, a, b, c, d, 46);
- R3(d, e, a, b, c, 47);
- R3(c, d, e, a, b, 48);
- R3(b, c, d, e, a, 49);
- R3(a, b, c, d, e, 50);
- R3(e, a, b, c, d, 51);
- R3(d, e, a, b, c, 52);
- R3(c, d, e, a, b, 53);
- R3(b, c, d, e, a, 54);
- R3(a, b, c, d, e, 55);
- R3(e, a, b, c, d, 56);
- R3(d, e, a, b, c, 57);
- R3(c, d, e, a, b, 58);
- R3(b, c, d, e, a, 59);
- R4(a, b, c, d, e, 60);
- R4(e, a, b, c, d, 61);
- R4(d, e, a, b, c, 62);
- R4(c, d, e, a, b, 63);
- R4(b, c, d, e, a, 64);
- R4(a, b, c, d, e, 65);
- R4(e, a, b, c, d, 66);
- R4(d, e, a, b, c, 67);
- R4(c, d, e, a, b, 68);
- R4(b, c, d, e, a, 69);
- R4(a, b, c, d, e, 70);
- R4(e, a, b, c, d, 71);
- R4(d, e, a, b, c, 72);
- R4(c, d, e, a, b, 73);
- R4(b, c, d, e, a, 74);
- R4(a, b, c, d, e, 75);
- R4(e, a, b, c, d, 76);
- R4(d, e, a, b, c, 77);
- R4(c, d, e, a, b, 78);
- R4(b, c, d, e, a, 79);
+ R0(a, b, c, d, e, 0);
+ R0(e, a, b, c, d, 1);
+ R0(d, e, a, b, c, 2);
+ R0(c, d, e, a, b, 3);
+ R0(b, c, d, e, a, 4);
+ R0(a, b, c, d, e, 5);
+ R0(e, a, b, c, d, 6);
+ R0(d, e, a, b, c, 7);
+ R0(c, d, e, a, b, 8);
+ R0(b, c, d, e, a, 9);
+ R0(a, b, c, d, e, 10);
+ R0(e, a, b, c, d, 11);
+ R0(d, e, a, b, c, 12);
+ R0(c, d, e, a, b, 13);
+ R0(b, c, d, e, a, 14);
+ R0(a, b, c, d, e, 15);
+ R1(e, a, b, c, d, 16);
+ R1(d, e, a, b, c, 17);
+ R1(c, d, e, a, b, 18);
+ R1(b, c, d, e, a, 19);
+ R2(a, b, c, d, e, 20);
+ R2(e, a, b, c, d, 21);
+ R2(d, e, a, b, c, 22);
+ R2(c, d, e, a, b, 23);
+ R2(b, c, d, e, a, 24);
+ R2(a, b, c, d, e, 25);
+ R2(e, a, b, c, d, 26);
+ R2(d, e, a, b, c, 27);
+ R2(c, d, e, a, b, 28);
+ R2(b, c, d, e, a, 29);
+ R2(a, b, c, d, e, 30);
+ R2(e, a, b, c, d, 31);
+ R2(d, e, a, b, c, 32);
+ R2(c, d, e, a, b, 33);
+ R2(b, c, d, e, a, 34);
+ R2(a, b, c, d, e, 35);
+ R2(e, a, b, c, d, 36);
+ R2(d, e, a, b, c, 37);
+ R2(c, d, e, a, b, 38);
+ R2(b, c, d, e, a, 39);
+ R3(a, b, c, d, e, 40);
+ R3(e, a, b, c, d, 41);
+ R3(d, e, a, b, c, 42);
+ R3(c, d, e, a, b, 43);
+ R3(b, c, d, e, a, 44);
+ R3(a, b, c, d, e, 45);
+ R3(e, a, b, c, d, 46);
+ R3(d, e, a, b, c, 47);
+ R3(c, d, e, a, b, 48);
+ R3(b, c, d, e, a, 49);
+ R3(a, b, c, d, e, 50);
+ R3(e, a, b, c, d, 51);
+ R3(d, e, a, b, c, 52);
+ R3(c, d, e, a, b, 53);
+ R3(b, c, d, e, a, 54);
+ R3(a, b, c, d, e, 55);
+ R3(e, a, b, c, d, 56);
+ R3(d, e, a, b, c, 57);
+ R3(c, d, e, a, b, 58);
+ R3(b, c, d, e, a, 59);
+ R4(a, b, c, d, e, 60);
+ R4(e, a, b, c, d, 61);
+ R4(d, e, a, b, c, 62);
+ R4(c, d, e, a, b, 63);
+ R4(b, c, d, e, a, 64);
+ R4(a, b, c, d, e, 65);
+ R4(e, a, b, c, d, 66);
+ R4(d, e, a, b, c, 67);
+ R4(c, d, e, a, b, 68);
+ R4(b, c, d, e, a, 69);
+ R4(a, b, c, d, e, 70);
+ R4(e, a, b, c, d, 71);
+ R4(d, e, a, b, c, 72);
+ R4(c, d, e, a, b, 73);
+ R4(b, c, d, e, a, 74);
+ R4(a, b, c, d, e, 75);
+ R4(e, a, b, c, d, 76);
+ R4(d, e, a, b, c, 77);
+ R4(c, d, e, a, b, 78);
+ R4(b, c, d, e, a, 79);
- state[0] += a;
- state[1] += b;
- state[2] += c;
- state[3] += d;
- state[4] += e;
+ state[0] += a;
+ state[1] += b;
+ state[2] += c;
+ state[3] += d;
+ state[4] += e;
- a = b = c = d = e = 0;
+ a = b = c = d = e = 0;
}
void sha1_init(sha1_ctx_t * ctx)
{
- ctx->state[0] = 0x67452301;
- ctx->state[1] = 0xEFCDAB89;
- ctx->state[2] = 0x98BADCFE;
- ctx->state[3] = 0x10325476;
- ctx->state[4] = 0xC3D2E1F0;
+ ctx->state[0] = 0x67452301;
+ ctx->state[1] = 0xEFCDAB89;
+ ctx->state[2] = 0x98BADCFE;
+ ctx->state[3] = 0x10325476;
+ ctx->state[4] = 0xC3D2E1F0;
- ctx->count[0] = ctx->count[1] = 0;
+ ctx->count[0] = ctx->count[1] = 0;
}
void sha1_update(sha1_ctx_t * ctx, const uint8_t * data, unsigned int len)
{
- unsigned int i, j;
+ unsigned int i, j;
- j = (ctx->count[0] >> 3) & 63;
- if ((ctx->count[0] += len << 3) < (len << 3))
- ctx->count[1]++;
- ctx->count[1] += (len >> 29);
+ j = (ctx->count[0] >> 3) & 63;
+ if ((ctx->count[0] += len << 3) < (len << 3))
+ ctx->count[1]++;
+ ctx->count[1] += (len >> 29);
- if (j + len > 63) {
- memcpy(&ctx->buffer[j], data, (i = 64 - j));
- sha1_transform(ctx->state, ctx->buffer);
- for (; i + 63 < len; i += 64)
- sha1_transform(ctx->state, &data[i]);
- j = 0;
- } else {
- i = 0;
- }
- memcpy(&ctx->buffer[j], &data[i], len - i);
+ if (j + len > 63) {
+ memcpy(&ctx->buffer[j], data, (i = 64 - j));
+ sha1_transform(ctx->state, ctx->buffer);
+ for (; i + 63 < len; i += 64)
+ sha1_transform(ctx->state, &data[i]);
+ j = 0;
+ } else {
+ i = 0;
+ }
+ memcpy(&ctx->buffer[j], &data[i], len - i);
}
void sha1_final(sha1_ctx_t * ctx, uint8_t digest[SHA1_DIGESTLEN])
{
- uint32_t i, j;
- uint8_t finalcount[8];
+ uint32_t i, j;
+ uint8_t finalcount[8];
- for (i = 0; i < 8; i++) {
- finalcount[i] = (uint8_t) ((ctx->count[(i >= 4 ? 0 : 1)] >>
- ((3 - (i & 3)) * 8)) & 255);
- }
+ for (i = 0; i < 8; i++) {
+ finalcount[i] = (uint8_t) ((ctx->count[(i >= 4 ? 0 : 1)] >>
+ ((3 - (i & 3)) * 8)) & 255);
+ }
- sha1_update(ctx, (uint8_t *) "\200", 1);
- while ((ctx->count[0] & 504) != 448)
- sha1_update(ctx, (uint8_t *) "\0", 1);
+ sha1_update(ctx, (uint8_t *) "\200", 1);
+ while ((ctx->count[0] & 504) != 448)
+ sha1_update(ctx, (uint8_t *) "\0", 1);
- sha1_update(ctx, finalcount, 8);
- for (i = 0; i < SHA1_DIGESTLEN; i++)
- digest[i] = (uint8_t) ((ctx->state[i >> 2] >> ((3 - (i & 3)) * 8)) & 255);
+ sha1_update(ctx, finalcount, 8);
+ for (i = 0; i < SHA1_DIGESTLEN; i++)
+ digest[i] =
+ (uint8_t) ((ctx->
+ state[i >> 2] >> ((3 - (i & 3)) *
+ 8)) & 255);
- i = j = 0;
- memset(ctx->buffer, 0, SHA1_BLOCKLEN);
- memset(ctx->state, 0, SHA1_DIGESTLEN);
- memset(ctx->count, 0, 8);
- memset(&finalcount, 0, 8);
+ i = j = 0;
+ memset(ctx->buffer, 0, SHA1_BLOCKLEN);
+ memset(ctx->state, 0, SHA1_DIGESTLEN);
+ memset(ctx->count, 0, 8);
+ memset(&finalcount, 0, 8);
}
void sha1_digest(const char *data, char *buffer)
{
- sha1_ctx_t ctx;
- uint8_t digest[SHA1_DIGESTLEN];
- int i;
+ sha1_ctx_t ctx;
+ uint8_t digest[SHA1_DIGESTLEN];
+ int i;
- sha1_init(&ctx);
- sha1_update(&ctx, (const uint8_t *)data, strlen(data));
- sha1_final(&ctx, (uint8_t *) digest);
+ sha1_init(&ctx);
+ sha1_update(&ctx, (const uint8_t *)data, strlen(data));
+ sha1_final(&ctx, (uint8_t *) digest);
- for (i = 0; i < SHA1_DIGESTLEN; i++) {
- snprintf(buffer, 3, "%02x", digest[i]);
- buffer += sizeof(char) * 2;
- }
+ for (i = 0; i < SHA1_DIGESTLEN; i++) {
+ snprintf(buffer, 3, "%02x", digest[i]);
+ buffer += sizeof(char) * 2;
+ }
}
void sha1_stream(FILE * fp, char *buffer)
{
- sha1_ctx_t ctx;
- uint8_t data[BUFSIZ];
- size_t bytes_read;
- uint8_t digest[SHA1_DIGESTLEN];
- int i;
+ sha1_ctx_t ctx;
+ uint8_t data[BUFSIZ];
+ size_t bytes_read;
+ uint8_t digest[SHA1_DIGESTLEN];
+ int i;
- sha1_init(&ctx);
+ sha1_init(&ctx);
- while (!feof(fp)) {
- bytes_read = fread(data, 1, BUFSIZ, fp);
- sha1_update(&ctx, data, bytes_read);
- }
+ while (!feof(fp)) {
+ bytes_read = fread(data, 1, BUFSIZ, fp);
+ sha1_update(&ctx, data, bytes_read);
+ }
- sha1_final(&ctx, (uint8_t *) digest);
+ sha1_final(&ctx, (uint8_t *) digest);
- for (i = 0; i < SHA1_DIGESTLEN; i++) {
- snprintf(buffer, 3, "%02x", digest[i]);
- buffer += sizeof(char) * 2;
- }
+ for (i = 0; i < SHA1_DIGESTLEN; i++) {
+ snprintf(buffer, 3, "%02x", digest[i]);
+ buffer += sizeof(char) * 2;
+ }
}
diff --git a/src/sha1.h b/src/sha1.h
index 8f80bef..479c3b6 100644
--- a/src/sha1.h
+++ b/src/sha1.h
@@ -45,9 +45,9 @@
#define SHA1_DIGESTLEN 20
typedef struct {
- uint32_t state[5];
- uint32_t count[2];
- uint8_t buffer[SHA1_BLOCKLEN];
+ uint32_t state[5];
+ uint32_t count[2];
+ uint8_t buffer[SHA1_BLOCKLEN];
} sha1_ctx_t;
void sha1_init(sha1_ctx_t *);
diff --git a/src/sigs.c b/src/sigs.c
index 68dcdfd..e746a01 100644
--- a/src/sigs.c
+++ b/src/sigs.c
@@ -65,60 +65,62 @@
*/
static void generic_hdlr(int sig)
{
- switch (sig) {
- case SIGCHLD:
- while (waitpid(WAIT_MYPGRP, NULL, WNOHANG) > 0) ;
- break;
- case SIGWINCH:
- resize = 1;
- clearok(curscr, TRUE);
- ungetch(KEY_RESIZE);
- break;
- case SIGTERM:
- if (unlink(path_cpid) != 0) {
- EXIT(_("Could not remove calcurse lock file: %s\n"), strerror(errno));
- }
- exit(EXIT_SUCCESS);
- break;
- }
+ switch (sig) {
+ case SIGCHLD:
+ while (waitpid(WAIT_MYPGRP, NULL, WNOHANG) > 0) ;
+ break;
+ case SIGWINCH:
+ resize = 1;
+ clearok(curscr, TRUE);
+ ungetch(KEY_RESIZE);
+ break;
+ case SIGTERM:
+ if (unlink(path_cpid) != 0) {
+ EXIT(_("Could not remove calcurse lock file: %s\n"),
+ strerror(errno));
+ }
+ exit(EXIT_SUCCESS);
+ break;
+ }
}
unsigned sigs_set_hdlr(int sig, void (*handler) (int))
{
- struct sigaction sa;
+ struct sigaction sa;
- memset(&sa, 0, sizeof sa);
- sigemptyset(&sa.sa_mask);
- sa.sa_handler = handler;
- sa.sa_flags = 0;
- if (sigaction(sig, &sa, NULL) == -1) {
- ERROR_MSG(_("Error setting signal #%d : %s\n"), sig, strerror(errno));
- return 0;
- }
+ memset(&sa, 0, sizeof sa);
+ sigemptyset(&sa.sa_mask);
+ sa.sa_handler = handler;
+ sa.sa_flags = 0;
+ if (sigaction(sig, &sa, NULL) == -1) {
+ ERROR_MSG(_("Error setting signal #%d : %s\n"), sig,
+ strerror(errno));
+ return 0;
+ }
- return 1;
+ return 1;
}
/* Signal handling init. */
void sigs_init()
{
- if (!sigs_set_hdlr(SIGCHLD, generic_hdlr)
- || !sigs_set_hdlr(SIGWINCH, generic_hdlr)
- || !sigs_set_hdlr(SIGTERM, generic_hdlr)
- || !sigs_set_hdlr(SIGINT, SIG_IGN))
- exit_calcurse(1);
+ if (!sigs_set_hdlr(SIGCHLD, generic_hdlr)
+ || !sigs_set_hdlr(SIGWINCH, generic_hdlr)
+ || !sigs_set_hdlr(SIGTERM, generic_hdlr)
+ || !sigs_set_hdlr(SIGINT, SIG_IGN))
+ exit_calcurse(1);
}
/* Ignore SIGWINCH and SIGTERM signals. */
void sigs_ignore(void)
{
- sigs_set_hdlr(SIGWINCH, SIG_IGN);
- sigs_set_hdlr(SIGTERM, SIG_IGN);
+ sigs_set_hdlr(SIGWINCH, SIG_IGN);
+ sigs_set_hdlr(SIGTERM, SIG_IGN);
}
/* No longer ignore SIGWINCH and SIGTERM signals. */
void sigs_unignore(void)
{
- sigs_set_hdlr(SIGWINCH, generic_hdlr);
- sigs_set_hdlr(SIGTERM, generic_hdlr);
+ sigs_set_hdlr(SIGWINCH, generic_hdlr);
+ sigs_set_hdlr(SIGTERM, generic_hdlr);
}
diff --git a/src/todo.c b/src/todo.c
index a0d464f..50ee447 100644
--- a/src/todo.c
+++ b/src/todo.c
@@ -45,20 +45,20 @@ llist_t todolist;
/* Returns a structure containing the selected item. */
struct todo *todo_get_item(int item_number)
{
- return LLIST_GET_DATA(LLIST_NTH(&todolist, item_number - 1));
+ return LLIST_GET_DATA(LLIST_NTH(&todolist, item_number - 1));
}
static int todo_cmp_id(struct todo *a, struct todo *b)
{
- /*
- * As of version 2.6, todo items can have a negative id, which means they
- * were completed. To keep them sorted, we need to consider the absolute id
- * value.
- */
- int abs_a = abs(a->id);
- int abs_b = abs(b->id);
-
- return abs_a < abs_b ? -1 : (abs_a == abs_b ? 0 : 1);
+ /*
+ * As of version 2.6, todo items can have a negative id, which means they
+ * were completed. To keep them sorted, we need to consider the absolute id
+ * value.
+ */
+ int abs_a = abs(a->id);
+ int abs_b = abs(b->id);
+
+ return abs_a < abs_b ? -1 : (abs_a == abs_b ? 0 : 1);
}
/*
@@ -66,46 +66,48 @@ static int todo_cmp_id(struct todo *a, struct todo *b)
*/
struct todo *todo_add(char *mesg, int id, char *note)
{
- struct todo *todo;
+ struct todo *todo;
- todo = mem_malloc(sizeof(struct todo));
- todo->mesg = mem_strdup(mesg);
- todo->id = id;
- todo->note = (note != NULL && note[0] != '\0') ? mem_strdup(note) : NULL;
+ todo = mem_malloc(sizeof(struct todo));
+ todo->mesg = mem_strdup(mesg);
+ todo->id = id;
+ todo->note = (note != NULL
+ && note[0] != '\0') ? mem_strdup(note) : NULL;
- LLIST_ADD_SORTED(&todolist, todo, todo_cmp_id);
+ LLIST_ADD_SORTED(&todolist, todo, todo_cmp_id);
- return todo;
+ return todo;
}
void todo_write(struct todo *todo, FILE * f)
{
- if (todo->note)
- fprintf(f, "[%d]>%s %s\n", todo->id, todo->note, todo->mesg);
- else
- fprintf(f, "[%d] %s\n", todo->id, todo->mesg);
+ if (todo->note)
+ fprintf(f, "[%d]>%s %s\n", todo->id, todo->note,
+ todo->mesg);
+ else
+ fprintf(f, "[%d] %s\n", todo->id, todo->mesg);
}
/* Delete a note previously attached to a todo item. */
void todo_delete_note(struct todo *todo)
{
- if (!todo->note)
- EXIT(_("no note attached"));
- erase_note(&todo->note);
+ if (!todo->note)
+ EXIT(_("no note attached"));
+ erase_note(&todo->note);
}
/* Delete an item from the todo linked list. */
void todo_delete(struct todo *todo)
{
- llist_item_t *i = LLIST_FIND_FIRST(&todolist, todo, NULL);
+ llist_item_t *i = LLIST_FIND_FIRST(&todolist, todo, NULL);
- if (!i)
- EXIT(_("no such todo"));
+ if (!i)
+ EXIT(_("no such todo"));
- LLIST_REMOVE(&todolist, i);
- mem_free(todo->mesg);
- erase_note(&todo->note);
- mem_free(todo);
+ LLIST_REMOVE(&todolist, i);
+ mem_free(todo->mesg);
+ erase_note(&todo->note);
+ mem_free(todo);
}
/*
@@ -116,7 +118,7 @@ void todo_delete(struct todo *todo)
*/
void todo_flag(struct todo *t)
{
- t->id = -t->id;
+ t->id = -t->id;
}
/*
@@ -125,45 +127,45 @@ void todo_flag(struct todo *t)
*/
int todo_get_position(struct todo *needle)
{
- llist_item_t *i;
- int n = 0;
+ llist_item_t *i;
+ int n = 0;
- LLIST_FOREACH(&todolist, i) {
- n++;
- if (LLIST_TS_GET_DATA(i) == needle)
- return n;
- }
+ LLIST_FOREACH(&todolist, i) {
+ n++;
+ if (LLIST_TS_GET_DATA(i) == needle)
+ return n;
+ }
- EXIT(_("todo not found"));
- return -1; /* avoid compiler warnings */
+ EXIT(_("todo not found"));
+ return -1; /* avoid compiler warnings */
}
/* Attach a note to a todo */
void todo_edit_note(struct todo *i, const char *editor)
{
- edit_note(&i->note, editor);
+ edit_note(&i->note, editor);
}
/* View a note previously attached to a todo */
void todo_view_note(struct todo *i, const char *pager)
{
- view_note(i->note, pager);
+ view_note(i->note, pager);
}
void todo_free(struct todo *todo)
{
- mem_free(todo->mesg);
- erase_note(&todo->note);
- mem_free(todo);
+ mem_free(todo->mesg);
+ erase_note(&todo->note);
+ mem_free(todo);
}
void todo_init_list(void)
{
- LLIST_INIT(&todolist);
+ LLIST_INIT(&todolist);
}
void todo_free_list(void)
{
- LLIST_FREE_INNER(&todolist, todo_free);
- LLIST_FREE(&todolist);
+ LLIST_FREE_INNER(&todolist, todo_free);
+ LLIST_FREE(&todolist);
}
diff --git a/src/ui-calendar.c b/src/ui-calendar.c
index a312a99..f23d578 100644
--- a/src/ui-calendar.c
+++ b/src/ui-calendar.c
@@ -48,22 +48,22 @@
#endif
#define EPOCH 90
-#define EPSILONg 279.403303 /* solar ecliptic long at EPOCH */
-#define RHOg 282.768422 /* solar ecliptic long of perigee at EPOCH */
-#define ECCEN 0.016713 /* solar orbit eccentricity */
-#define lzero 318.351648 /* lunar mean long at EPOCH */
-#define Pzero 36.340410 /* lunar mean long of perigee at EPOCH */
-#define Nzero 318.510107 /* lunar mean long of node at EPOCH */
+#define EPSILONg 279.403303 /* solar ecliptic long at EPOCH */
+#define RHOg 282.768422 /* solar ecliptic long of perigee at EPOCH */
+#define ECCEN 0.016713 /* solar orbit eccentricity */
+#define lzero 318.351648 /* lunar mean long at EPOCH */
+#define Pzero 36.340410 /* lunar mean long of perigee at EPOCH */
+#define Nzero 318.510107 /* lunar mean long of node at EPOCH */
#define ISLEAP(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)
enum pom {
- NO_POM,
- FIRST_QUARTER,
- FULL_MOON,
- LAST_QUARTER,
- NEW_MOON,
- MOON_PHASES
+ NO_POM,
+ FIRST_QUARTER,
+ FULL_MOON,
+ LAST_QUARTER,
+ NEW_MOON,
+ MOON_PHASES
};
static struct date today, slctd_day;
@@ -74,7 +74,7 @@ static pthread_t ui_calendar_t_date;
static void draw_monthly_view(struct window *, struct date *, unsigned);
static void draw_weekly_view(struct window *, struct date *, unsigned);
static void (*draw_calendar[CAL_VIEWS]) (struct window *, struct date *,
- unsigned) = {
+ unsigned) = {
draw_monthly_view, draw_weekly_view};
static int monthly_view_cache[MAXDAYSPERMONTH];
@@ -84,168 +84,170 @@ static int monthly_view_cache_month = 0;
/* Switch between calendar views (monthly view is selected by default). */
void ui_calendar_view_next(void)
{
- ui_calendar_view++;
- if (ui_calendar_view == CAL_VIEWS)
- ui_calendar_view = 0;
+ ui_calendar_view++;
+ if (ui_calendar_view == CAL_VIEWS)
+ ui_calendar_view = 0;
}
void ui_calendar_view_prev(void)
{
- if (ui_calendar_view == 0)
- ui_calendar_view = CAL_VIEWS;
- ui_calendar_view--;
+ if (ui_calendar_view == 0)
+ ui_calendar_view = CAL_VIEWS;
+ ui_calendar_view--;
}
void ui_calendar_set_view(int view)
{
- ui_calendar_view = (view < 0 || view >= CAL_VIEWS) ? CAL_MONTH_VIEW : view;
+ ui_calendar_view = (view < 0
+ || view >= CAL_VIEWS) ? CAL_MONTH_VIEW : view;
}
int ui_calendar_get_view(void)
{
- return (int)ui_calendar_view;
+ return (int)ui_calendar_view;
}
/* Thread needed to update current date in calendar. */
/* ARGSUSED0 */
static void *ui_calendar_date_thread(void *arg)
{
- time_t actual, tomorrow;
+ time_t actual, tomorrow;
- for (;;) {
- tomorrow = (time_t) (get_today() + DAYINSEC);
+ for (;;) {
+ tomorrow = (time_t) (get_today() + DAYINSEC);
- while ((actual = time(NULL)) < tomorrow)
- sleep(tomorrow - actual);
+ while ((actual = time(NULL)) < tomorrow)
+ sleep(tomorrow - actual);
- ui_calendar_set_current_date();
- ui_calendar_update_panel(&win[CAL]);
- }
+ ui_calendar_set_current_date();
+ ui_calendar_update_panel(&win[CAL]);
+ }
- return NULL;
+ return NULL;
}
/* Launch the calendar date thread. */
void ui_calendar_start_date_thread(void)
{
- pthread_create(&ui_calendar_t_date, NULL, ui_calendar_date_thread, NULL);
+ pthread_create(&ui_calendar_t_date, NULL, ui_calendar_date_thread,
+ NULL);
}
/* Stop the calendar date thread. */
void ui_calendar_stop_date_thread(void)
{
- if (ui_calendar_t_da