Switch to Linux kernel coding style

Convert our code base to adhere to Linux kernel coding style using
Lindent, with the following exceptions:

* Use spaces, instead of tabs, for indentation.
* Use 2-character indentations (instead of 8 characters).

Rationale: We currently have too much levels of indentation. Using
8-character tabs would make huge code parts unreadable. These need to be
cleaned up before we can switch to 8 characters.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
Lukas Fleischer 2012-05-21 10:13:05 +02:00
parent 47c52ae7bb
commit cfd8ede2b3
33 changed files with 9138 additions and 10647 deletions

View File

@ -45,42 +45,37 @@ llist_ts_t alist_p;
static struct apoint bkp_cut_apoint; static struct apoint bkp_cut_apoint;
static int hilt; static int hilt;
void void apoint_free_bkp(void)
apoint_free_bkp (void)
{ {
if (bkp_cut_apoint.mesg) if (bkp_cut_apoint.mesg) {
{ mem_free(bkp_cut_apoint.mesg);
mem_free (bkp_cut_apoint.mesg);
bkp_cut_apoint.mesg = 0; bkp_cut_apoint.mesg = 0;
} }
erase_note (&bkp_cut_apoint.note); erase_note(&bkp_cut_apoint.note);
} }
static void static void apoint_free(struct apoint *apt)
apoint_free (struct apoint *apt)
{ {
mem_free (apt->mesg); mem_free(apt->mesg);
erase_note (&apt->note); erase_note(&apt->note);
mem_free (apt); mem_free(apt);
} }
static void static void apoint_dup(struct apoint *in, struct apoint *bkp)
apoint_dup (struct apoint *in, struct apoint *bkp)
{ {
EXIT_IF (!in || !bkp, _("null pointer")); EXIT_IF(!in || !bkp, _("null pointer"));
bkp->start = in->start; bkp->start = in->start;
bkp->dur = in->dur; bkp->dur = in->dur;
bkp->state = in->state; bkp->state = in->state;
bkp->mesg = mem_strdup (in->mesg); bkp->mesg = mem_strdup(in->mesg);
if (in->note) if (in->note)
bkp->note = mem_strdup (in->note); bkp->note = mem_strdup(in->note);
} }
void void apoint_llist_init(void)
apoint_llist_init (void)
{ {
LLIST_TS_INIT (&alist_p); LLIST_TS_INIT(&alist_p);
} }
/* /*
@ -88,60 +83,54 @@ apoint_llist_init (void)
* list. No need to be thread safe, as only the main process remains when * list. No need to be thread safe, as only the main process remains when
* calling this function. * calling this function.
*/ */
void void apoint_llist_free(void)
apoint_llist_free (void)
{ {
LLIST_TS_FREE_INNER (&alist_p, apoint_free); LLIST_TS_FREE_INNER(&alist_p, apoint_free);
LLIST_TS_FREE (&alist_p); LLIST_TS_FREE(&alist_p);
} }
/* Sets which appointment is highlighted. */ /* Sets which appointment is highlighted. */
void void apoint_hilt_set(int highlighted)
apoint_hilt_set (int highlighted)
{ {
hilt = highlighted; hilt = highlighted;
} }
void void apoint_hilt_decrease(int n)
apoint_hilt_decrease (int n)
{ {
hilt -= n; hilt -= n;
} }
void void apoint_hilt_increase(int n)
apoint_hilt_increase (int n)
{ {
hilt += n; hilt += n;
} }
/* Return which appointment is highlighted. */ /* Return which appointment is highlighted. */
int int apoint_hilt(void)
apoint_hilt (void)
{ {
return hilt; return hilt;
} }
static int static int apoint_cmp_start(struct apoint *a, struct apoint *b)
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 * struct apoint *apoint_new(char *mesg, char *note, long start, long dur,
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 = mem_malloc(sizeof(struct apoint));
apt->mesg = mem_strdup (mesg); apt->mesg = mem_strdup(mesg);
apt->note = (note != NULL) ? mem_strdup (note) : NULL; apt->note = (note != NULL) ? mem_strdup(note) : NULL;
apt->state = state; apt->state = state;
apt->start = start; apt->start = start;
apt->dur = dur; apt->dur = dur;
LLIST_TS_LOCK (&alist_p); LLIST_TS_LOCK(&alist_p);
LLIST_TS_ADD_SORTED (&alist_p, apt, apoint_cmp_start); LLIST_TS_ADD_SORTED(&alist_p, apt, apoint_cmp_start);
LLIST_TS_UNLOCK (&alist_p); LLIST_TS_UNLOCK(&alist_p);
return apt; return apt;
} }
@ -150,20 +139,21 @@ apoint_new (char *mesg, char *note, long start, long dur, char state)
* Add an item in either the appointment or the event list, * Add an item in either the appointment or the event list,
* depending if the start time is entered or not. * depending if the start time is entered or not.
*/ */
void void apoint_add(void)
apoint_add (void)
{ {
#define LTIME 6 #define LTIME 6
#define LDUR 12 #define LDUR 12
const char *mesg_1 = const char *mesg_1 =
_("Enter start time ([hh:mm]), leave blank for an all-day event : "); _("Enter start time ([hh:mm]), leave blank for an all-day event : ");
const char *mesg_2 = const char *mesg_2 =
_("Enter end time ([hh:mm]) or duration ([+hh:mm], [+xxxdxxhxxm] or [+mm]) : "); _
("Enter end time ([hh:mm]) or duration ([+hh:mm], [+xxxdxxhxxm] or [+mm]) : ");
const char *mesg_3 = _("Enter description :"); const char *mesg_3 = _("Enter description :");
const char *format_message_1 = const char *format_message_1 =
_("You entered an invalid start time, should be [hh:mm]"); _("You entered an invalid start time, should be [hh:mm]");
const char *format_message_2 = const char *format_message_2 =
_("Invalid end time/duration, should be [hh:mm], [+hh:mm], [+xxxdxxhxxm] or [+mm]"); _
("Invalid end time/duration, should be [hh:mm], [+hh:mm], [+xxxdxxhxxm] or [+mm]");
const char *enter_str = _("Press [Enter] to continue"); const char *enter_str = _("Press [Enter] to continue");
int Id = 1; int Id = 1;
char item_time[LDUR] = ""; char item_time[LDUR] = "";
@ -175,26 +165,21 @@ apoint_add (void)
int is_appointment = 1; int is_appointment = 1;
/* Get the starting time */ /* Get the starting time */
for (;;) for (;;) {
{ status_mesg(mesg_1, "");
status_mesg (mesg_1, ""); if (getstring(win[STA].p, item_time, LTIME, 0, 1) != GETSTRING_ESC) {
if (getstring (win[STA].p, item_time, LTIME, 0, 1) != GETSTRING_ESC) if (strlen(item_time) == 0) {
{
if (strlen (item_time) == 0)
{
is_appointment = 0; is_appointment = 0;
break; break;
} }
if (parse_time (item_time, &heures, &minutes) == 1) if (parse_time(item_time, &heures, &minutes) == 1)
break; break;
else else {
{ status_mesg(format_message_1, enter_str);
status_mesg (format_message_1, enter_str); wgetch(win[STA].p);
wgetch (win[STA].p);
} }
} } else
else
return; return;
} }
@ -203,90 +188,71 @@ apoint_add (void)
* depending on the starting time, and record the * depending on the starting time, and record the
* corresponding item. * corresponding item.
*/ */
if (is_appointment) if (is_appointment) { /* Get the appointment duration */
{ /* Get the appointment duration */
item_time[0] = '\0'; item_time[0] = '\0';
for (;;) for (;;) {
{ status_mesg(mesg_2, "");
status_mesg (mesg_2, ""); if (getstring(win[STA].p, item_time, LDUR, 0, 1) != GETSTRING_ESC) {
if (getstring (win[STA].p, item_time, LDUR, 0, 1) != GETSTRING_ESC) if (*item_time == '+' && parse_duration(item_time + 1,
{
if (*item_time == '+' && parse_duration (item_time + 1,
&apoint_duration) == 1) &apoint_duration) == 1)
break; break;
else if (parse_time (item_time, &end_h, &end_m) == 1) else if (parse_time(item_time, &end_h, &end_m) == 1) {
{ if (end_h < heures || ((end_h == heures) && (end_m < minutes))) {
if (end_h < heures || ((end_h == heures) && (end_m < minutes)))
{
apoint_duration = MININSEC - minutes + end_m apoint_duration = MININSEC - minutes + end_m
+ (24 + end_h - (heures + 1)) * MININSEC; + (24 + end_h - (heures + 1)) * MININSEC;
} } else {
else
{
apoint_duration = MININSEC - minutes apoint_duration = MININSEC - minutes
+ end_m + (end_h - (heures + 1)) * MININSEC; + end_m + (end_h - (heures + 1)) * MININSEC;
} }
break; break;
} else {
status_mesg(format_message_2, enter_str);
wgetch(win[STA].p);
} }
else } else
{
status_mesg (format_message_2, enter_str);
wgetch (win[STA].p);
}
}
else
return; return;
} }
} } else /* Insert the event Id */
else /* Insert the event Id */
Id = 1; Id = 1;
status_mesg (mesg_3, ""); status_mesg(mesg_3, "");
if (getstring (win[STA].p, item_mesg, BUFSIZ, 0, 1) == GETSTRING_VALID) if (getstring(win[STA].p, item_mesg, BUFSIZ, 0, 1) == GETSTRING_VALID) {
{ if (is_appointment) {
if (is_appointment) apoint_start = date2sec(*calendar_get_slctd_day(), heures, minutes);
{ apoint_new(item_mesg, 0L, apoint_start, min2sec(apoint_duration), 0L);
apoint_start = date2sec (*calendar_get_slctd_day (), heures, minutes); if (notify_bar())
apoint_new (item_mesg, 0L, apoint_start, min2sec (apoint_duration), 0L); notify_check_added(item_mesg, apoint_start, 0L);
if (notify_bar ()) } else
notify_check_added (item_mesg, apoint_start, 0L); event_new(item_mesg, 0L, date2sec(*calendar_get_slctd_day(), 0, 0), Id);
}
else
event_new (item_mesg, 0L, date2sec (*calendar_get_slctd_day (), 0, 0), Id);
if (hilt == 0) if (hilt == 0)
hilt++; hilt++;
} }
wins_erase_status_bar (); wins_erase_status_bar();
} }
/* Delete an item from the appointment list. */ /* Delete an item from the appointment list. */
void void apoint_delete(unsigned *nb_events, unsigned *nb_apoints)
apoint_delete (unsigned *nb_events, unsigned *nb_apoints)
{ {
const char *del_app_str = _("Do you really want to delete this item ?"); const char *del_app_str = _("Do you really want to delete this item ?");
long date; long date;
int nb_items = *nb_apoints + *nb_events; int nb_items = *nb_apoints + *nb_events;
int to_be_removed = 0; int to_be_removed = 0;
date = calendar_get_slctd_day_sec (); date = calendar_get_slctd_day_sec();
if (nb_items == 0) if (nb_items == 0)
return; return;
if (conf.confirm_delete) if (conf.confirm_delete) {
{ if (status_ask_bool(del_app_str) != 1) {
if (status_ask_bool (del_app_str) != 1) wins_erase_status_bar();
{
wins_erase_status_bar ();
return; return;
} }
} }
if (nb_items != 0) if (nb_items != 0) {
{ switch (day_erase_item(date, hilt, ERASE_DONT_FORCE)) {
switch (day_erase_item (date, hilt, ERASE_DONT_FORCE))
{
case EVNT: case EVNT:
case RECUR_EVNT: case RECUR_EVNT:
(*nb_events)--; (*nb_events)--;
@ -300,7 +266,7 @@ apoint_delete (unsigned *nb_events, unsigned *nb_apoints)
case 0: case 0:
return; return;
default: default:
EXIT (_("no such type")); EXIT(_("no such type"));
/* NOTREACHED */ /* NOTREACHED */
} }
@ -314,8 +280,7 @@ apoint_delete (unsigned *nb_events, unsigned *nb_apoints)
} }
/* Cut an item, so that it can be pasted somewhere else later. */ /* Cut an item, so that it can be pasted somewhere else later. */
int int apoint_cut(unsigned *nb_events, unsigned *nb_apoints)
apoint_cut (unsigned *nb_events, unsigned *nb_apoints)
{ {
const int NBITEMS = *nb_apoints + *nb_events; const int NBITEMS = *nb_apoints + *nb_events;
int item_type, to_be_removed; int item_type, to_be_removed;
@ -324,20 +289,16 @@ apoint_cut (unsigned *nb_events, unsigned *nb_apoints)
if (NBITEMS == 0) if (NBITEMS == 0)
return 0; return 0;
date = calendar_get_slctd_day_sec (); date = calendar_get_slctd_day_sec();
item_type = day_cut_item (date, hilt); item_type = day_cut_item(date, hilt);
if (item_type == EVNT || item_type == RECUR_EVNT) if (item_type == EVNT || item_type == RECUR_EVNT) {
{
(*nb_events)--; (*nb_events)--;
to_be_removed = 1; to_be_removed = 1;
} } else if (item_type == APPT || item_type == RECUR_APPT) {
else if (item_type == APPT || item_type == RECUR_APPT)
{
(*nb_apoints)--; (*nb_apoints)--;
to_be_removed = 3; to_be_removed = 3;
} } else
else EXIT(_("no such type"));
EXIT (_("no such type"));
/* NOTREACHED */ /* NOTREACHED */
if (hilt > 1) if (hilt > 1)
@ -351,14 +312,13 @@ apoint_cut (unsigned *nb_events, unsigned *nb_apoints)
} }
/* Paste a previously cut item. */ /* Paste a previously cut item. */
void void apoint_paste(unsigned *nb_events, unsigned *nb_apoints, int cut_item_type)
apoint_paste (unsigned *nb_events, unsigned *nb_apoints, int cut_item_type)
{ {
int item_type; int item_type;
long date; long date;
date = calendar_get_slctd_day_sec (); date = calendar_get_slctd_day_sec();
item_type = day_paste_item (date, cut_item_type); item_type = day_paste_item(date, cut_item_type);
if (item_type == EVNT || item_type == RECUR_EVNT) if (item_type == EVNT || item_type == RECUR_EVNT)
(*nb_events)++; (*nb_events)++;
else if (item_type == APPT || item_type == RECUR_APPT) else if (item_type == APPT || item_type == RECUR_APPT)
@ -370,77 +330,72 @@ apoint_paste (unsigned *nb_events, unsigned *nb_apoints, int cut_item_type)
hilt++; hilt++;
} }
unsigned unsigned apoint_inday(struct apoint *i, long start)
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 void apoint_sec2str(struct apoint *o, long day, char *start, char *end)
apoint_sec2str (struct apoint *o, long day, char *start, char *end)
{ {
struct tm *lt; struct tm *lt;
time_t t; time_t t;
if (o->start < day) if (o->start < day)
strncpy (start, "..:..", 6); strncpy(start, "..:..", 6);
else else {
{
t = o->start; t = o->start;
lt = localtime (&t); lt = localtime(&t);
snprintf (start, HRMIN_SIZE, "%02u:%02u", lt->tm_hour, lt->tm_min); snprintf(start, HRMIN_SIZE, "%02u:%02u", lt->tm_hour, lt->tm_min);
} }
if (o->start + o->dur > day + DAYINSEC) if (o->start + o->dur > day + DAYINSEC)
strncpy (end, "..:..", 6); strncpy(end, "..:..", 6);
else else {
{
t = o->start + o->dur; t = o->start + o->dur;
lt = localtime (&t); lt = localtime(&t);
snprintf (end, HRMIN_SIZE, "%02u:%02u", lt->tm_hour, lt->tm_min); snprintf(end, HRMIN_SIZE, "%02u:%02u", lt->tm_hour, lt->tm_min);
} }
} }
void void apoint_write(struct apoint *o, FILE * f)
apoint_write (struct apoint *o, FILE *f)
{ {
struct tm *lt; struct tm *lt;
time_t t; time_t t;
t = o->start; t = o->start;
lt = localtime (&t); lt = localtime(&t);
fprintf (f, "%02u/%02u/%04u @ %02u:%02u", lt->tm_mon + 1, lt->tm_mday, fprintf(f, "%02u/%02u/%04u @ %02u:%02u", lt->tm_mon + 1, lt->tm_mday,
1900 + lt->tm_year, lt->tm_hour, lt->tm_min); 1900 + lt->tm_year, lt->tm_hour, lt->tm_min);
t = o->start + o->dur; t = o->start + o->dur;
lt = localtime (&t); lt = localtime(&t);
fprintf (f, " -> %02u/%02u/%04u @ %02u:%02u ", lt->tm_mon + 1, lt->tm_mday, fprintf(f, " -> %02u/%02u/%04u @ %02u:%02u ", lt->tm_mon + 1, lt->tm_mday,
1900 + lt->tm_year, lt->tm_hour, lt->tm_min); 1900 + lt->tm_year, lt->tm_hour, lt->tm_min);
if (o->note != NULL) if (o->note != NULL)
fprintf (f, ">%s ", o->note); fprintf(f, ">%s ", o->note);
if (o->state & APOINT_NOTIFY) if (o->state & APOINT_NOTIFY)
fputc ('!', f); fputc('!', f);
else else
fputc ('|', f); fputc('|', f);
fprintf (f, "%s\n", o->mesg); fprintf(f, "%s\n", o->mesg);
} }
struct apoint * struct apoint *apoint_scan(FILE * f, struct tm start, struct tm end, char state,
apoint_scan (FILE *f, struct tm start, struct tm end, char state, char *note) char *note)
{ {
char buf[BUFSIZ], *newline; char buf[BUFSIZ], *newline;
time_t tstart, tend, t; time_t tstart, tend, t;
t = time (NULL); t = time(NULL);
localtime (&t); localtime(&t);
/* Read the appointment description */ /* Read the appointment description */
if (!fgets (buf, sizeof buf, f)) if (!fgets(buf, sizeof buf, f))
return NULL; return NULL;
newline = strchr (buf, '\n'); newline = strchr(buf, '\n');
if (newline) if (newline)
*newline = '\0'; *newline = '\0';
@ -451,61 +406,58 @@ apoint_scan (FILE *f, struct tm start, struct tm end, char state, char *note)
end.tm_year -= 1900; end.tm_year -= 1900;
end.tm_mon--; end.tm_mon--;
tstart = mktime (&start); tstart = mktime(&start);
tend = mktime (&end); tend = mktime(&end);
EXIT_IF (tstart == -1 || tend == -1 || tstart > tend, EXIT_IF(tstart == -1 || tend == -1 || tstart > tend,
_("date error in appointment")); _("date error in appointment"));
return apoint_new (buf, note, tstart, tend - tstart, state); return apoint_new(buf, note, tstart, tend - tstart, state);
} }
/* Retrieve an appointment from the list, given the day and item position. */ /* Retrieve an appointment from the list, given the day and item position. */
struct apoint * struct apoint *apoint_get(long day, int pos)
apoint_get (long day, int pos)
{ {
llist_item_t *i = LLIST_TS_FIND_NTH (&alist_p, pos, day, apoint_inday); llist_item_t *i = LLIST_TS_FIND_NTH(&alist_p, pos, day, apoint_inday);
if (i) if (i)
return LLIST_TS_GET_DATA (i); return LLIST_TS_GET_DATA(i);
EXIT (_("item not found")); EXIT(_("item not found"));
/* NOTREACHED */ /* NOTREACHED */
} }
void void apoint_delete_bynum(long start, unsigned num, enum eraseflg flag)
apoint_delete_bynum (long start, unsigned num, enum eraseflg flag)
{ {
llist_item_t *i; llist_item_t *i;
int need_check_notify = 0; int need_check_notify = 0;
LLIST_TS_LOCK (&alist_p); LLIST_TS_LOCK(&alist_p);
i = LLIST_TS_FIND_NTH (&alist_p, num, start, apoint_inday); i = LLIST_TS_FIND_NTH(&alist_p, num, start, apoint_inday);
if (!i) if (!i)
EXIT (_("no such appointment")); EXIT(_("no such appointment"));
struct apoint *apt = LLIST_TS_GET_DATA (i); struct apoint *apt = LLIST_TS_GET_DATA(i);
switch (flag) switch (flag) {
{
case ERASE_FORCE_ONLY_NOTE: case ERASE_FORCE_ONLY_NOTE:
erase_note (&apt->note); erase_note(&apt->note);
break; break;
case ERASE_CUT: case ERASE_CUT:
apoint_free_bkp (); apoint_free_bkp();
apoint_dup (apt, &bkp_cut_apoint); apoint_dup(apt, &bkp_cut_apoint);
erase_note (&apt->note); erase_note(&apt->note);
/* FALLTHROUGH */ /* FALLTHROUGH */
default: default:
if (notify_bar ()) if (notify_bar())
need_check_notify = notify_same_item (apt->start); need_check_notify = notify_same_item(apt->start);
LLIST_TS_REMOVE (&alist_p, i); LLIST_TS_REMOVE(&alist_p, i);
mem_free (apt->mesg); mem_free(apt->mesg);
mem_free (apt); mem_free(apt);
if (need_check_notify) if (need_check_notify)
notify_check_next_app (0); notify_check_next_app(0);
break; break;
} }
LLIST_TS_UNLOCK (&alist_p); LLIST_TS_UNLOCK(&alist_p);
} }
/* /*
@ -513,8 +465,7 @@ apoint_delete_bynum (long start, unsigned num, enum eraseflg flag)
* the appointment panel. This is to help the appointment scroll function * the appointment panel. This is to help the appointment scroll function
* to place beggining of the pad correctly. * to place beggining of the pad correctly.
*/ */
static int static int get_item_line(int item_nb, int nb_events_inday)
get_item_line (int item_nb, int nb_events_inday)
{ {
int separator = 2; int separator = 2;
int line = 0; int line = 0;
@ -531,15 +482,14 @@ get_item_line (int item_nb, int nb_events_inday)
* Update (if necessary) the first displayed pad line to make the * Update (if necessary) the first displayed pad line to make the
* appointment panel scroll down next time pnoutrefresh is called. * appointment panel scroll down next time pnoutrefresh is called.
*/ */
void void apoint_scroll_pad_down(int nb_events_inday, int win_length)
apoint_scroll_pad_down (int nb_events_inday, int win_length)
{ {
int pad_last_line = 0; int pad_last_line = 0;
int item_first_line = 0, item_last_line = 0; int item_first_line = 0, item_last_line = 0;
int borders = 6; int borders = 6;
int awin_length = win_length - borders; int awin_length = win_length - borders;
item_first_line = get_item_line (hilt, nb_events_inday); item_first_line = get_item_line(hilt, nb_events_inday);
if (hilt < nb_events_inday) if (hilt < nb_events_inday)
item_last_line = item_first_line; item_last_line = item_first_line;
else else
@ -553,18 +503,16 @@ apoint_scroll_pad_down (int nb_events_inday, int win_length)
* Update (if necessary) the first displayed pad line to make the * Update (if necessary) the first displayed pad line to make the
* appointment panel scroll up next time pnoutrefresh is called. * appointment panel scroll up next time pnoutrefresh is called.
*/ */
void void apoint_scroll_pad_up(int nb_events_inday)
apoint_scroll_pad_up (int nb_events_inday)
{ {
int item_first_line = 0; int item_first_line = 0;
item_first_line = get_item_line (hilt, nb_events_inday); item_first_line = get_item_line(hilt, nb_events_inday);
if (item_first_line < apad.first_onscreen) if (item_first_line < apad.first_onscreen)
apad.first_onscreen = item_first_line; apad.first_onscreen = item_first_line;
} }
static int static int apoint_starts_after(struct apoint *apt, long time)
apoint_starts_after (struct apoint *apt, long time)
{ {
return apt->start > time; return apt->start > time;
} }
@ -573,28 +521,25 @@ apoint_starts_after (struct apoint *apt, long time)
* Look in the appointment list if we have an item which starts before the item * 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). * stored in the notify_app structure (which is the next item to be notified).
*/ */
struct notify_app * struct notify_app *apoint_check_next(struct notify_app *app, long start)
apoint_check_next (struct notify_app *app, long start)
{ {
llist_item_t *i; llist_item_t *i;
LLIST_TS_LOCK (&alist_p); LLIST_TS_LOCK(&alist_p);
i = LLIST_TS_FIND_FIRST (&alist_p, start, apoint_starts_after); i = LLIST_TS_FIND_FIRST(&alist_p, start, apoint_starts_after);
if (i) if (i) {
{ struct apoint *apt = LLIST_TS_GET_DATA(i);
struct apoint *apt = LLIST_TS_GET_DATA (i);
if (apt->start <= app->time) if (apt->start <= app->time) {
{
app->time = apt->start; app->time = apt->start;
app->txt = mem_strdup (apt->mesg); app->txt = mem_strdup(apt->mesg);
app->state = apt->state; app->state = apt->state;
app->got_app = 1; app->got_app = 1;
} }
} }
LLIST_TS_UNLOCK (&alist_p); LLIST_TS_UNLOCK(&alist_p);
return app; return app;
} }
@ -602,44 +547,40 @@ apoint_check_next (struct notify_app *app, long start)
/* /*
* Switch notification state. * Switch notification state.
*/ */
void void apoint_switch_notify(void)
apoint_switch_notify (void)
{ {
struct day_item *p; struct day_item *p;
long date; long date;
int apoint_nb = 0, need_chk_notify; int apoint_nb = 0, need_chk_notify;
p = day_get_item (hilt); p = day_get_item(hilt);
if (p->type != APPT && p->type != RECUR_APPT) if (p->type != APPT && p->type != RECUR_APPT)
return; return;
date = calendar_get_slctd_day_sec (); date = calendar_get_slctd_day_sec();
if (p->type == RECUR_APPT) if (p->type == RECUR_APPT) {
{ recur_apoint_switch_notify(date, p->appt_pos);
recur_apoint_switch_notify (date, p->appt_pos);
return; return;
} } else if (p->type == APPT)
else if (p->type == APPT) apoint_nb = day_item_nb(date, hilt, APPT);
apoint_nb = day_item_nb (date, hilt, APPT);
need_chk_notify = 0; need_chk_notify = 0;
LLIST_TS_LOCK (&alist_p); LLIST_TS_LOCK(&alist_p);
struct apoint *apt = apoint_get (date, apoint_nb); struct apoint *apt = apoint_get(date, apoint_nb);
apt->state ^= APOINT_NOTIFY; apt->state ^= APOINT_NOTIFY;
if (notify_bar ()) if (notify_bar())
notify_check_added (apt->mesg, apt->start, apt->state); notify_check_added(apt->mesg, apt->start, apt->state);
if (need_chk_notify) if (need_chk_notify)
notify_check_next_app (0); notify_check_next_app(0);
LLIST_TS_UNLOCK (&alist_p); LLIST_TS_UNLOCK(&alist_p);
} }
/* Updates the Appointment panel */ /* Updates the Appointment panel */
void void apoint_update_panel(int which_pan)
apoint_update_panel (int which_pan)
{ {
int title_xpos; int title_xpos;
int bordr = 1; int bordr = 1;
@ -650,56 +591,53 @@ apoint_update_panel (int which_pan)
struct date slctd_date; struct date slctd_date;
/* variable inits */ /* variable inits */
slctd_date = *calendar_get_slctd_day (); slctd_date = *calendar_get_slctd_day();
title_xpos = win[APP].w - (strlen (_(monthnames[slctd_date.mm - 1])) + 16); title_xpos = win[APP].w - (strlen(_(monthnames[slctd_date.mm - 1])) + 16);
if (slctd_date.dd < 10) if (slctd_date.dd < 10)
title_xpos++; title_xpos++;
date = date2sec (slctd_date, 0, 0); date = date2sec(slctd_date, 0, 0);
day_write_pad (date, app_width, app_length, (which_pan == APP) ? hilt : 0); day_write_pad(date, app_width, app_length, (which_pan == APP) ? hilt : 0);
/* Print current date in the top right window corner. */ /* Print current date in the top right window corner. */
erase_window_part (win[APP].p, 1, title_lines, win[APP].w - 2, erase_window_part(win[APP].p, 1, title_lines, win[APP].w - 2, win[APP].h - 2);
win[APP].h - 2); custom_apply_attr(win[APP].p, ATTR_HIGHEST);
custom_apply_attr (win[APP].p, ATTR_HIGHEST); mvwprintw(win[APP].p, title_lines, title_xpos, "%s %s %d, %d",
mvwprintw (win[APP].p, title_lines, title_xpos, "%s %s %d, %d", calendar_get_pom(date), _(monthnames[slctd_date.mm - 1]),
calendar_get_pom (date), _(monthnames[slctd_date.mm - 1]),
slctd_date.dd, slctd_date.yyyy); slctd_date.dd, slctd_date.yyyy);
custom_remove_attr (win[APP].p, ATTR_HIGHEST); custom_remove_attr(win[APP].p, ATTR_HIGHEST);
/* Draw the scrollbar if necessary. */ /* Draw the scrollbar if necessary. */
if ((apad.length >= app_length) || (apad.first_onscreen > 0)) if ((apad.length >= app_length) || (apad.first_onscreen > 0)) {
{ float ratio = ((float)app_length) / ((float)apad.length);
float ratio = ((float) app_length) / ((float) apad.length); int sbar_length = (int)(ratio * app_length);
int sbar_length = (int) (ratio * app_length); int highend = (int)(ratio * apad.first_onscreen);
int highend = (int) (ratio * apad.first_onscreen);
unsigned hilt_bar = (which_pan == APP) ? 1 : 0; unsigned hilt_bar = (which_pan == APP) ? 1 : 0;
int sbar_top = highend + title_lines + 1; int sbar_top = highend + title_lines + 1;
if ((sbar_top + sbar_length) > win[APP].h - 1) if ((sbar_top + sbar_length) > win[APP].h - 1)
sbar_length = win[APP].h - 1 - sbar_top; sbar_length = win[APP].h - 1 - sbar_top;
draw_scrollbar (win[APP].p, sbar_top, win[APP].w - 2, sbar_length, draw_scrollbar(win[APP].p, sbar_top, win[APP].w - 2, sbar_length,
title_lines + 1, win[APP].h - 1, hilt_bar); title_lines + 1, win[APP].h - 1, hilt_bar);
} }
wnoutrefresh (win[APP].p); wnoutrefresh(win[APP].p);
pnoutrefresh (apad.ptrwin, apad.first_onscreen, 0, pnoutrefresh(apad.ptrwin, apad.first_onscreen, 0,
win[APP].y + title_lines + 1, win[APP].x + bordr, win[APP].y + title_lines + 1, win[APP].x + bordr,
win[APP].y + win[APP].h - 2 * bordr, win[APP].y + win[APP].h - 2 * bordr,
win[APP].x + win[APP].w - 3 * bordr); win[APP].x + win[APP].w - 3 * bordr);
} }
void void apoint_paste_item(void)
apoint_paste_item (void)
{ {
long bkp_time, bkp_start; long bkp_time, bkp_start;
bkp_time = get_item_time (bkp_cut_apoint.start); bkp_time = get_item_time(bkp_cut_apoint.start);
bkp_start = calendar_get_slctd_day_sec () + bkp_time; bkp_start = calendar_get_slctd_day_sec() + bkp_time;
apoint_new (bkp_cut_apoint.mesg, bkp_cut_apoint.note, bkp_start, apoint_new(bkp_cut_apoint.mesg, bkp_cut_apoint.note, bkp_start,
bkp_cut_apoint.dur, bkp_cut_apoint.state); bkp_cut_apoint.dur, bkp_cut_apoint.state);
if (notify_bar ()) if (notify_bar())
notify_check_added (bkp_cut_apoint.mesg, bkp_start, bkp_cut_apoint.state); notify_check_added(bkp_cut_apoint.mesg, bkp_start, bkp_cut_apoint.state);
apoint_free_bkp (); apoint_free_bkp();
} }

View File

@ -58,43 +58,39 @@ enum {
/* /*
* Print Calcurse usage and exit. * Print Calcurse usage and exit.
*/ */
static void static void usage(void)
usage (void)
{ {
const char *arg_usage = const char *arg_usage =
_("Usage: calcurse [-g|-h|-v] [-an] [-t[num]] [-i<file>] [-x[format]]\n" _("Usage: calcurse [-g|-h|-v] [-an] [-t[num]] [-i<file>] [-x[format]]\n"
" [-d <date>|<num>] [-s[date]] [-r[range]]\n" " [-d <date>|<num>] [-s[date]] [-r[range]]\n"
" [-c<file> | -D<dir>] [-S<regex>] [--status]\n" " [-c<file> | -D<dir>] [-S<regex>] [--status]\n"
" [--read-only]\n"); " [--read-only]\n");
fputs (arg_usage, stdout); fputs(arg_usage, stdout);
} }
static void static void usage_try(void)
usage_try (void)
{ {
const char *arg_usage_try = _("Try 'calcurse -h' for more information.\n"); const char *arg_usage_try = _("Try 'calcurse -h' for more information.\n");
fputs (arg_usage_try, stdout); fputs(arg_usage_try, stdout);
} }
/* /*
* Print Calcurse version with a short copyright text and exit. * Print Calcurse version with a short copyright text and exit.
*/ */
static void static void version_arg(void)
version_arg (void)
{ {
const char *vtext = const char *vtext =
_("\nCopyright (c) 2004-2012 calcurse Development Team.\n" _("\nCopyright (c) 2004-2012 calcurse Development Team.\n"
"This is free software; see the source for copying conditions.\n"); "This is free software; see the source for copying conditions.\n");
fprintf (stdout, _("Calcurse %s - text-based organizer\n"), VERSION); fprintf(stdout, _("Calcurse %s - text-based organizer\n"), VERSION);
fputs (vtext, stdout); fputs(vtext, stdout);
} }
/* /*
* Print the command line options and exit. * Print the command line options and exit.
*/ */
static void static void help_arg(void)
help_arg (void)
{ {
const char *htext = const char *htext =
_("\nMiscellaneous:\n" _("\nMiscellaneous:\n"
@ -154,9 +150,9 @@ help_arg (void)
"or read the manpage.\n" "or read the manpage.\n"
"Mail bug reports and suggestions to <misc@calcurse.org>.\n"); "Mail bug reports and suggestions to <misc@calcurse.org>.\n");
fprintf (stdout, _("Calcurse %s - text-based organizer\n"), VERSION); fprintf(stdout, _("Calcurse %s - text-based organizer\n"), VERSION);
usage (); usage();
fputs (htext, stdout); fputs(htext, stdout);
} }
/* /*
@ -170,26 +166,24 @@ help_arg (void)
* The status is obtained by looking at pid files in user data directory * The status is obtained by looking at pid files in user data directory
* (.calcurse.pid and .daemon.pid). * (.calcurse.pid and .daemon.pid).
*/ */
static void static void status_arg(void)
status_arg (void)
{ {
int cpid, dpid; int cpid, dpid;
cpid = io_get_pid (path_cpid); cpid = io_get_pid(path_cpid);
dpid = io_get_pid (path_dpid); dpid = io_get_pid(path_dpid);
EXIT_IF (cpid && dpid, EXIT_IF(cpid && dpid,
_("Error: both calcurse (pid: %d) and its daemon (pid: %d)\n" _("Error: both calcurse (pid: %d) and its daemon (pid: %d)\n"
"seem to be running at the same time!\n" "seem to be running at the same time!\n"
"Please check manually and restart calcurse.\n"), "Please check manually and restart calcurse.\n"), cpid, dpid);
cpid, dpid);
if (cpid) if (cpid)
fprintf (stdout, _("calcurse is running (pid %d)\n"), cpid); fprintf(stdout, _("calcurse is running (pid %d)\n"), cpid);
else if (dpid) else if (dpid)
fprintf (stdout, _("calcurse is running in background (pid %d)\n"), dpid); fprintf(stdout, _("calcurse is running in background (pid %d)\n"), dpid);
else else
puts (_("calcurse is not running\n")); puts(_("calcurse is not running\n"));
} }
/* /*
@ -199,8 +193,7 @@ status_arg (void)
* If priority == 0, only completed tasks will be displayed. * If priority == 0, only completed tasks will be displayed.
* If regex is not null, only the matching todos are printed. * If regex is not null, only the matching todos are printed.
*/ */
static void static void todo_arg(int priority, const char *format, regex_t * regex)
todo_arg (int priority, const char *format, regex_t *regex)
{ {
llist_item_t *i; llist_item_t *i;
int title = 1; int title = 1;
@ -218,26 +211,20 @@ todo_arg (int priority, const char *format, regex_t *regex)
} \ } \
} while (0) } while (0)
LLIST_FOREACH (&todolist, i) LLIST_FOREACH(&todolist, i) {
{ struct todo *todo = LLIST_TS_GET_DATA(i);
struct todo *todo = LLIST_TS_GET_DATA (i); if (regex && regexec(regex, todo->mesg, 0, 0, 0) != 0)
if (regex && regexec (regex, todo->mesg, 0, 0, 0) != 0)
continue; continue;
if (todo->id < 0) /* completed task */ if (todo->id < 0) { /* completed task */
{ if (priority == 0) {
if (priority == 0)
{
DISPLAY_TITLE; DISPLAY_TITLE;
print_todo (format, todo); print_todo(format, todo);
} }
} } else {
else if (priority < 0 || todo->id == priority) {
{
if (priority < 0 || todo->id == priority)
{
DISPLAY_TITLE; DISPLAY_TITLE;
print_todo (format, todo); print_todo(format, todo);
} }
} }
} }
@ -246,11 +233,10 @@ todo_arg (int priority, const char *format, regex_t *regex)
} }
/* Print the next appointment within the upcoming 24 hours. */ /* Print the next appointment within the upcoming 24 hours. */
static void static void next_arg(void)
next_arg (void)
{ {
struct notify_app next_app; struct notify_app next_app;
const long current_time = now (); const long current_time = now();
int time_left, hours_left, min_left; int time_left, hours_left, min_left;
char mesg[BUFSIZ]; char mesg[BUFSIZ];
@ -258,37 +244,35 @@ next_arg (void)
next_app.got_app = 0; next_app.got_app = 0;
next_app.txt = NULL; next_app.txt = NULL;
next_app = *recur_apoint_check_next (&next_app, current_time, get_today ()); next_app = *recur_apoint_check_next(&next_app, current_time, get_today());
next_app = *apoint_check_next (&next_app, current_time); next_app = *apoint_check_next(&next_app, current_time);
if (next_app.got_app) if (next_app.got_app) {
{
time_left = next_app.time - current_time; time_left = next_app.time - current_time;
hours_left = (time_left / HOURINSEC); hours_left = (time_left / HOURINSEC);
min_left = (time_left - hours_left * HOURINSEC) / MININSEC; min_left = (time_left - hours_left * HOURINSEC) / MININSEC;
fputs (_("next appointment:\n"), stdout); fputs(_("next appointment:\n"), stdout);
snprintf (mesg, BUFSIZ, " [%02d:%02d] %s\n", hours_left, min_left, snprintf(mesg, BUFSIZ, " [%02d:%02d] %s\n", hours_left, min_left,
next_app.txt); next_app.txt);
fputs (mesg, stdout); fputs(mesg, stdout);
mem_free (next_app.txt); mem_free(next_app.txt);
} }
} }
/* /*
* Print the date on stdout. * Print the date on stdout.
*/ */
static void static void arg_print_date(long date)
arg_print_date (long date)
{ {
char date_str[BUFSIZ]; char date_str[BUFSIZ];
time_t t; time_t t;
struct tm *lt; struct tm *lt;
t = date; t = date;
lt = localtime (&t); lt = localtime(&t);
strftime (date_str, BUFSIZ, conf.output_datefmt, lt); strftime(date_str, BUFSIZ, conf.output_datefmt, lt);
fputs (date_str, stdout); fputs(date_str, stdout);
fputs (":\n", stdout); fputs(":\n", stdout);
} }
/* /*
@ -298,9 +282,9 @@ arg_print_date (long date)
* If regex is not null, only the matching appointments or events are printed. * If regex is not null, only the matching appointments or events are printed.
*/ */
static int static int
app_arg (int add_line, struct date *day, long date, const char *fmt_apt, 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, const char *fmt_rapt, const char *fmt_ev, const char *fmt_rev,
regex_t *regex) regex_t * regex)
{ {
llist_item_t *i, *j; llist_item_t *i, *j;
long today; long today;
@ -308,7 +292,7 @@ app_arg (int add_line, struct date *day, long date, const char *fmt_apt,
int app_found = 0; int app_found = 0;
if (date == 0) if (date == 0)
today = get_sec_date (*day); today = get_sec_date(*day);
else else
today = date; today = date;
@ -317,131 +301,113 @@ app_arg (int add_line, struct date *day, long date, const char *fmt_apt,
* that date and it is the first one, and then print all the events for * that date and it is the first one, and then print all the events for
* that date. * that date.
*/ */
LLIST_FIND_FOREACH (&recur_elist, today, recur_event_inday, i) LLIST_FIND_FOREACH(&recur_elist, today, recur_event_inday, i) {
{ struct recur_event *re = LLIST_GET_DATA(i);
struct recur_event *re = LLIST_GET_DATA (i); if (regex && regexec(regex, re->mesg, 0, 0, 0) != 0)
if (regex && regexec (regex, re->mesg, 0, 0, 0) != 0)
continue; continue;
app_found = 1; app_found = 1;
if (add_line) if (add_line) {
{ fputs("\n", stdout);
fputs ("\n", stdout);
add_line = 0; add_line = 0;
} }
if (print_date) if (print_date) {
{ arg_print_date(today);
arg_print_date (today);
print_date = 0; print_date = 0;
} }
print_recur_event (fmt_rev, today, re); print_recur_event(fmt_rev, today, re);
} }
LLIST_FIND_FOREACH_CONT (&eventlist, today, event_inday, i) LLIST_FIND_FOREACH_CONT(&eventlist, today, event_inday, i) {
{ struct event *ev = LLIST_TS_GET_DATA(i);
struct event *ev = LLIST_TS_GET_DATA (i); if (regex && regexec(regex, ev->mesg, 0, 0, 0) != 0)
if (regex && regexec (regex, ev->mesg, 0, 0, 0) != 0)
continue; continue;
app_found = 1; app_found = 1;
if (add_line) if (add_line) {
{ fputs("\n", stdout);
fputs ("\n", stdout);
add_line = 0; add_line = 0;
} }
if (print_date) if (print_date) {
{ arg_print_date(today);
arg_print_date (today);
print_date = 0; print_date = 0;
} }
print_event (fmt_ev, today, ev); print_event(fmt_ev, today, ev);
} }
/* Same process is performed but this time on the appointments. */ /* Same process is performed but this time on the appointments. */
LLIST_TS_LOCK (&alist_p); LLIST_TS_LOCK(&alist_p);
LLIST_TS_LOCK (&recur_alist_p); LLIST_TS_LOCK(&recur_alist_p);
/* /*
* Iterate over regular appointments and recurrent ones simultaneously (fixes * Iterate over regular appointments and recurrent ones simultaneously (fixes
* http://lists.calcurse.org/bugs/msg00002.html). * http://lists.calcurse.org/bugs/msg00002.html).
*/ */
i = LLIST_TS_FIND_FIRST (&alist_p, today, apoint_inday); i = LLIST_TS_FIND_FIRST(&alist_p, today, apoint_inday);
j = LLIST_TS_FIND_FIRST (&recur_alist_p, today, recur_apoint_inday); j = LLIST_TS_FIND_FIRST(&recur_alist_p, today, recur_apoint_inday);
while (i || j) while (i || j) {
{ struct apoint *apt = LLIST_TS_GET_DATA(i);
struct apoint *apt = LLIST_TS_GET_DATA (i); struct recur_apoint *ra = LLIST_TS_GET_DATA(j);
struct recur_apoint *ra = LLIST_TS_GET_DATA (j);
unsigned occurrence; unsigned occurrence;
while (i && regex && regexec (regex, apt->mesg, 0, 0, 0) != 0) while (i && regex && regexec(regex, apt->mesg, 0, 0, 0) != 0) {
{ i = LLIST_TS_FIND_NEXT(i, today, apoint_inday);
i = LLIST_TS_FIND_NEXT (i, today, apoint_inday); apt = LLIST_TS_GET_DATA(i);
apt = LLIST_TS_GET_DATA (i);
} }
while (j && regex && regexec (regex, ra->mesg, 0, 0, 0) != 0) while (j && regex && regexec(regex, ra->mesg, 0, 0, 0) != 0) {
{ j = LLIST_TS_FIND_NEXT(j, today, recur_apoint_inday);
j = LLIST_TS_FIND_NEXT (j, today, recur_apoint_inday); ra = LLIST_TS_GET_DATA(j);
ra = LLIST_TS_GET_DATA (j);
} }
if (apt && ra) if (apt && ra) {
{ if (recur_apoint_find_occurrence(ra, today, &occurrence) &&
if (recur_apoint_find_occurrence (ra, today, &occurrence) &&
apt->start <= occurrence) apt->start <= occurrence)
ra = NULL; ra = NULL;
else else
apt = NULL; apt = NULL;
} }
if (apt) if (apt) {
{
app_found = 1; app_found = 1;
if (add_line) if (add_line) {
{ fputs("\n", stdout);
fputs ("\n", stdout);
add_line = 0; add_line = 0;
} }
if (print_date) if (print_date) {
{ arg_print_date(today);
arg_print_date (today);
print_date = 0; print_date = 0;
} }
print_apoint (fmt_apt, today, apt); print_apoint(fmt_apt, today, apt);
i = LLIST_TS_FIND_NEXT (i, today, apoint_inday); i = LLIST_TS_FIND_NEXT(i, today, apoint_inday);
} } else if (ra) {
else if (ra)
{
app_found = 1; app_found = 1;
if (add_line) if (add_line) {
{ fputs("\n", stdout);
fputs ("\n", stdout);
add_line = 0; add_line = 0;
} }
if (print_date) if (print_date) {
{ arg_print_date(today);
arg_print_date (today);
print_date = 0; print_date = 0;
} }
recur_apoint_find_occurrence (ra, today, &occurrence); recur_apoint_find_occurrence(ra, today, &occurrence);
print_recur_apoint (fmt_rapt, today, occurrence, ra); print_recur_apoint(fmt_rapt, today, occurrence, ra);
apt = NULL; apt = NULL;
j = LLIST_TS_FIND_NEXT (j, today, recur_apoint_inday); j = LLIST_TS_FIND_NEXT(j, today, recur_apoint_inday);
} }
} }
LLIST_TS_UNLOCK (&recur_alist_p); LLIST_TS_UNLOCK(&recur_alist_p);
LLIST_TS_UNLOCK (&alist_p); LLIST_TS_UNLOCK(&alist_p);
return app_found; return app_found;
} }
static void static void more_info(void)
more_info (void)
{ {
fputs (_("\nFor more information, type '?' from within Calcurse, " fputs(_("\nFor more information, type '?' from within Calcurse, "
"or read the manpage.\n"), stdout); "or read the manpage.\n"), stdout);
fputs (_("Mail bug reports and suggestions to " fputs(_("Mail bug reports and suggestions to "
"<misc@calcurse.org>.\n"), stdout); "<misc@calcurse.org>.\n"), stdout);
} }
@ -451,24 +417,23 @@ more_info (void)
* to format the output correctly. * to format the output correctly.
*/ */
static void static void
display_app (struct tm *t, int numdays, int add_line, const char *fmt_apt, 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, const char *fmt_rapt, const char *fmt_ev, const char *fmt_rev,
regex_t *regex) regex_t * regex)
{ {
int i, app_found; int i, app_found;
struct date day; struct date day;
for (i = 0; i < numdays; i++) for (i = 0; i < numdays; i++) {
{
day.dd = t->tm_mday; day.dd = t->tm_mday;
day.mm = t->tm_mon + 1; day.mm = t->tm_mon + 1;
day.yyyy = t->tm_year + 1900; day.yyyy = t->tm_year + 1900;
app_found = app_arg (add_line, &day, 0, fmt_apt, fmt_rapt, fmt_ev, app_found = app_arg(add_line, &day, 0, fmt_apt, fmt_rapt, fmt_ev,
fmt_rev, regex); fmt_rev, regex);
if (app_found) if (app_found)
add_line = 1; add_line = 1;
t->tm_mday++; t->tm_mday++;
mktime (t); mktime(t);
} }
} }
@ -477,9 +442,9 @@ display_app (struct tm *t, int numdays, int add_line, const char *fmt_apt,
* days. * days.
*/ */
static void static void
date_arg (const char *ddate, int add_line, const char *fmt_apt, date_arg(const char *ddate, int add_line, const char *fmt_apt,
const char *fmt_rapt, const char *fmt_ev, const char *fmt_rev, const char *fmt_rapt, const char *fmt_ev, const char *fmt_rev,
regex_t *regex) regex_t * regex)
{ {
int i; int i;
struct date day; struct date day;
@ -492,43 +457,36 @@ date_arg (const char *ddate, int add_line, const char *fmt_apt,
* Check (with the argument length) if a date or a number of days * Check (with the argument length) if a date or a number of days
* was entered, and then call app_arg() to print appointments * was entered, and then call app_arg() to print appointments
*/ */
arg_len = strlen (ddate); arg_len = strlen(ddate);
if (arg_len <= 4) if (arg_len <= 4) { /* a number of days was entered */
{ /* a number of days was entered */ for (i = 0; i <= arg_len - 1; i++) {
for (i = 0; i <= arg_len - 1; i++) if (isdigit(ddate[i]))
{
if (isdigit (ddate[i]))
num_digit++; num_digit++;
} }
if (num_digit == arg_len) if (num_digit == arg_len)
numdays = atoi (ddate); numdays = atoi(ddate);
/* /*
* Get current date, and print appointments for each day * Get current date, and print appointments for each day
* in the chosen interval. app_found and add_line are used * in the chosen interval. app_found and add_line are used
* to format the output correctly. * to format the output correctly.
*/ */
timer = time (NULL); timer = time(NULL);
t = *localtime (&timer); t = *localtime(&timer);
display_app (&t, numdays, add_line, fmt_apt, fmt_rapt, fmt_ev, fmt_rev, display_app(&t, numdays, add_line, fmt_apt, fmt_rapt, fmt_ev, fmt_rev,
regex); regex);
} } else { /* a date was entered */
else if (parse_date(ddate, conf.input_datefmt, (int *)&day.yyyy,
{ /* a date was entered */ (int *)&day.mm, (int *)&day.dd, NULL)) {
if (parse_date (ddate, conf.input_datefmt, (int *)&day.yyyy, app_arg(add_line, &day, 0, fmt_apt, fmt_rapt, fmt_ev, fmt_rev, regex);
(int *)&day.mm, (int *)&day.dd, NULL)) } else {
{
app_arg (add_line, &day, 0, fmt_apt, fmt_rapt, fmt_ev, fmt_rev, regex);
}
else
{
char outstr[BUFSIZ]; char outstr[BUFSIZ];
fputs (_("Argument to the '-d' flag is not valid\n"), stderr); fputs(_("Argument to the '-d' flag is not valid\n"), stderr);
snprintf (outstr, BUFSIZ, snprintf(outstr, BUFSIZ,
"Possible argument format are: '%s' or 'n'\n", "Possible argument format are: '%s' or 'n'\n",
DATEFMT_DESC (conf.input_datefmt)); DATEFMT_DESC(conf.input_datefmt));
fputs (_(outstr), stdout); fputs(_(outstr), stdout);
more_info (); more_info();
} }
} }
} }
@ -542,9 +500,9 @@ date_arg (const char *ddate, int add_line, const char *fmt_apt,
* Many thanks to Erik Saule for providing this function. * Many thanks to Erik Saule for providing this function.
*/ */
static void static void
date_arg_extended (const char *startday, const char *range, int add_line, date_arg_extended(const char *startday, const char *range, int add_line,
const char *fmt_apt, const char *fmt_rapt, const char *fmt_apt, const char *fmt_rapt,
const char *fmt_ev, const char *fmt_rev, regex_t *regex) const char *fmt_ev, const char *fmt_rev, regex_t * regex)
{ {
int i, numdays = 1, error = 0, arg_len = 0; int i, numdays = 1, error = 0, arg_len = 0;
static struct tm t; static struct tm t;
@ -553,58 +511,47 @@ date_arg_extended (const char *startday, const char *range, int add_line,
/* /*
* Check arguments and extract information * Check arguments and extract information
*/ */
if (range != NULL) if (range != NULL) {
{ arg_len = strlen(range);
arg_len = strlen (range); for (i = 0; i <= arg_len - 1; i++) {
for (i = 0; i <= arg_len - 1; i++) if (!isdigit(range[i]))
{
if (!isdigit (range[i]))
error = 1; error = 1;
} }
if (!error) if (!error)
numdays = atoi (range); numdays = atoi(range);
} }
timer = time (NULL); timer = time(NULL);
t = *localtime (&timer); t = *localtime(&timer);
if (startday != NULL) if (startday != NULL) {
{ if (parse_date(startday, conf.input_datefmt, (int *)&t.tm_year,
if (parse_date (startday, conf.input_datefmt, (int *)&t.tm_year, (int *)&t.tm_mon, (int *)&t.tm_mday, NULL)) {
(int *)&t.tm_mon, (int *)&t.tm_mday, NULL))
{
t.tm_year -= 1900; t.tm_year -= 1900;
t.tm_mon--; t.tm_mon--;
mktime (&t); mktime(&t);
} } else {
else
{
error = 1; error = 1;
} }
} }
if (!error) if (!error) {
{ display_app(&t, numdays, add_line, fmt_apt, fmt_rapt, fmt_ev, fmt_rev,
display_app (&t, numdays, add_line, fmt_apt, fmt_rapt, fmt_ev, fmt_rev,
regex); regex);
} } else {
else
{
char outstr[BUFSIZ]; char outstr[BUFSIZ];
fputs (_("Argument is not valid\n"), stderr); fputs(_("Argument is not valid\n"), stderr);
snprintf (outstr, BUFSIZ, snprintf(outstr, BUFSIZ,
"Argument format for -s and --startday is: '%s'\n", "Argument format for -s and --startday is: '%s'\n",
DATEFMT_DESC (conf.input_datefmt)); DATEFMT_DESC(conf.input_datefmt));
fputs (_(outstr), stdout); fputs(_(outstr), stdout);
fputs (_("Argument format for -r and --range is: 'n'\n"), stdout); fputs(_("Argument format for -r and --range is: 'n'\n"), stdout);
more_info (); more_info();
} }
} }
/* /*
* Parse the command-line arguments and call the appropriate * Parse the command-line arguments and call the appropriate
* routines to handle those arguments. Also initialize the data paths. * routines to handle those arguments. Also initialize the data paths.
*/ */
int int parse_args(int argc, char **argv)
parse_args (int argc, char **argv)
{ {
int ch, add_line = 0; int ch, add_line = 0;
int unknown_flag = 0; int unknown_flag = 0;
@ -637,8 +584,7 @@ parse_args (int argc, char **argv)
/* Long options only */ /* Long options only */
int statusflag = 0; /* --status: get the status of running instances */ int statusflag = 0; /* --status: get the status of running instances */
enum enum {
{
STATUS_OPT = CHAR_MAX + 1 STATUS_OPT = CHAR_MAX + 1
}; };
@ -671,10 +617,8 @@ parse_args (int argc, char **argv)
{NULL, no_argument, NULL, 0} {NULL, no_argument, NULL, 0}
}; };
while ((ch = getopt_long (argc, argv, optstr, longopts, NULL)) != -1) while ((ch = getopt_long(argc, argv, optstr, longopts, NULL)) != -1) {
{ switch (ch) {
switch (ch)
{
case STATUS_OPT: case STATUS_OPT:
statusflag = 1; statusflag = 1;
break; break;
@ -729,11 +673,10 @@ parse_args (int argc, char **argv)
startday = optarg; startday = optarg;
break; break;
case 'S': case 'S':
EXIT_IF (Sflag > 0, EXIT_IF(Sflag > 0, _("Can not handle more than one regular expression."));
_("Can not handle more than one regular expression."));
Sflag = 1; Sflag = 1;
if (regcomp (&reg, optarg, REG_EXTENDED)) if (regcomp(&reg, optarg, REG_EXTENDED))
EXIT (_("Could not compile regular expression.")); EXIT(_("Could not compile regular expression."));
preg = &reg; preg = &reg;
break; break;
case 't': case 't':
@ -741,17 +684,14 @@ parse_args (int argc, char **argv)
multiple_flag++; multiple_flag++;
load_data++; load_data++;
add_line = 1; add_line = 1;
if (optarg != NULL) if (optarg != NULL) {
{ tnum = atoi(optarg);
tnum = atoi (optarg); if (tnum < 0 || tnum > 9) {
if (tnum < 0 || tnum > 9) usage();
{ usage_try();
usage ();
usage_try ();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
} } else
else
tnum = -1; tnum = -1;
break; break;
case 'v': case 'v':
@ -761,23 +701,19 @@ parse_args (int argc, char **argv)
xflag = 1; xflag = 1;
multiple_flag++; multiple_flag++;
load_data++; load_data++;
if (optarg != NULL) if (optarg != NULL) {
{ if (strcmp(optarg, "ical") == 0)
if (strcmp (optarg, "ical") == 0)
xfmt = IO_EXPORT_ICAL; xfmt = IO_EXPORT_ICAL;
else if (strcmp (optarg, "pcal") == 0) else if (strcmp(optarg, "pcal") == 0)
xfmt = IO_EXPORT_PCAL; xfmt = IO_EXPORT_PCAL;
else else {
{ fputs(_("Argument for '-x' should be either "
fputs (_("Argument for '-x' should be either "
"'ical' or 'pcal'\n"), stderr); "'ical' or 'pcal'\n"), stderr);
usage (); usage();
usage_try (); usage_try();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
} } else {
else
{
xfmt = IO_EXPORT_ICAL; xfmt = IO_EXPORT_ICAL;
} }
break; break;
@ -800,8 +736,8 @@ parse_args (int argc, char **argv)
read_only = 1; read_only = 1;
break; break;
default: default:
usage (); usage();
usage_try (); usage_try();
unknown_flag = 1; unknown_flag = 1;
non_interactive = 1; non_interactive = 1;
/* NOTREACHED */ /* NOTREACHED */
@ -809,146 +745,115 @@ parse_args (int argc, char **argv)
} }
argc -= optind; argc -= optind;
if (argc >= 1) if (argc >= 1) {
{ usage();
usage (); usage_try();
usage_try ();
return EXIT_FAILURE; return EXIT_FAILURE;
/* Incorrect arguments */ /* Incorrect arguments */
} } else if (Dflag && cflag) {
else if (Dflag && cflag) fputs(_("Options '-D' and '-c' cannot be used at the same time\n"), stderr);
{ usage();
fputs (_("Options '-D' and '-c' cannot be used at the same time\n"), usage_try();
stderr);
usage ();
usage_try ();
return EXIT_FAILURE; return EXIT_FAILURE;
} } else if (Sflag && !(aflag || dflag || rflag || sflag || tflag)) {
else if (Sflag && !(aflag || dflag || rflag || sflag || tflag)) fputs(_("Option '-S' must be used with either '-d', '-r', '-s', "
{
fputs (_("Option '-S' must be used with either '-d', '-r', '-s', "
"'-a' or '-t'\n"), stderr); "'-a' or '-t'\n"), stderr);
usage (); usage();
usage_try (); usage_try();
return EXIT_FAILURE; return EXIT_FAILURE;
} } else {
else if (unknown_flag) {
{
if (unknown_flag)
{
non_interactive = 1; non_interactive = 1;
} } else if (hflag) {
else if (hflag) help_arg();
{
help_arg ();
non_interactive = 1; non_interactive = 1;
} } else if (vflag) {
else if (vflag) version_arg();
{
version_arg ();
non_interactive = 1; non_interactive = 1;
} } else if (statusflag) {
else if (statusflag) io_init(cfile, datadir);
{ status_arg();
io_init (cfile, datadir);
status_arg ();
non_interactive = 1; non_interactive = 1;
} } else if (gflag) {
else if (gflag) io_init(cfile, datadir);
{ io_check_dir(path_dir, NULL);
io_init (cfile, datadir); io_check_dir(path_notes, NULL);
io_check_dir (path_dir, NULL); io_check_file(path_apts, NULL);
io_check_dir (path_notes, NULL); io_check_file(path_todo, NULL);
io_check_file (path_apts, NULL); io_load_app();
io_check_file (path_todo, NULL); io_load_todo();
io_load_app (); note_gc();
io_load_todo ();
note_gc ();
non_interactive = 1; non_interactive = 1;
} else if (multiple_flag) {
if (load_data) {
io_init(cfile, datadir);
io_check_dir(path_dir, NULL);
io_check_dir(path_notes, NULL);
} }
else if (multiple_flag) if (iflag) {
{ io_check_file(path_apts, NULL);
if (load_data) io_check_file(path_todo, NULL);
{
io_init (cfile, datadir);
io_check_dir (path_dir, NULL);
io_check_dir (path_notes, NULL);
}
if (iflag)
{
io_check_file (path_apts, NULL);
io_check_file (path_todo, NULL);
/* Get default pager in case we need to show a log file. */ /* Get default pager in case we need to show a log file. */
vars_init (); vars_init();
io_load_app (); io_load_app();
io_load_todo (); io_load_todo();
io_import_data (IO_IMPORT_ICAL, ifile); io_import_data(IO_IMPORT_ICAL, ifile);
io_save_apts (); io_save_apts();
io_save_todo (); io_save_todo();
non_interactive = 1; non_interactive = 1;
} }
if (xflag) if (xflag) {
{ io_check_file(path_apts, NULL);
io_check_file (path_apts, NULL); io_check_file(path_todo, NULL);
io_check_file (path_todo, NULL); io_load_app();
io_load_app (); io_load_todo();
io_load_todo (); io_export_data(xfmt);
io_export_data (xfmt);
non_interactive = 1; non_interactive = 1;
return non_interactive; return non_interactive;
} }
if (tflag) if (tflag) {
{ io_check_file(path_todo, NULL);
io_check_file (path_todo, NULL); io_load_todo();
io_load_todo (); todo_arg(tnum, fmt_todo, preg);
todo_arg (tnum, fmt_todo, preg);
non_interactive = 1; non_interactive = 1;
} }
if (nflag) if (nflag) {
{ io_check_file(path_apts, NULL);
io_check_file (path_apts, NULL); io_load_app();
io_load_app (); next_arg();
next_arg ();
non_interactive = 1; non_interactive = 1;
} }
if (dflag || rflag || sflag) if (dflag || rflag || sflag) {
{ io_check_file(path_apts, NULL);
io_check_file (path_apts, NULL); io_check_file(path_conf, NULL);
io_check_file (path_conf, NULL); io_load_app();
io_load_app (); config_load(); /* To get output date format. */
config_load (); /* To get output date format. */
if (dflag) if (dflag)
date_arg (ddate, add_line, fmt_apt, fmt_rapt, fmt_ev, fmt_rev, date_arg(ddate, add_line, fmt_apt, fmt_rapt, fmt_ev, fmt_rev, preg);
preg);
if (rflag || sflag) if (rflag || sflag)
date_arg_extended (startday, range, add_line, fmt_apt, date_arg_extended(startday, range, add_line, fmt_apt,
fmt_rapt, fmt_ev, fmt_rev, preg); fmt_rapt, fmt_ev, fmt_rev, preg);
non_interactive = 1; non_interactive = 1;
} } else if (aflag) {
else if (aflag)
{
struct date day; struct date day;
io_check_file (path_apts, NULL); io_check_file(path_apts, NULL);
io_check_file (path_conf, NULL); io_check_file(path_conf, NULL);
vars_init (); vars_init();
config_load (); /* To get output date format. */ config_load(); /* To get output date format. */
io_load_app (); io_load_app();
day.dd = day.mm = day.yyyy = 0; day.dd = day.mm = day.yyyy = 0;
app_arg (add_line, &day, 0, fmt_apt, fmt_rapt, fmt_ev, fmt_rev, app_arg(add_line, &day, 0, fmt_apt, fmt_rapt, fmt_ev, fmt_rev, preg);
preg);
non_interactive = 1; non_interactive = 1;
} }
} } else {
else
{
non_interactive = 0; non_interactive = 0;
io_init (cfile, datadir); io_init(cfile, datadir);
} }
} }
if (preg) if (preg)
regfree (preg); regfree(preg);
return non_interactive; return non_interactive;
} }

View File

@ -42,14 +42,13 @@
* Store the events and appointments for the selected day and reset the * Store the events and appointments for the selected day and reset the
* appointment highlight pointer if a new day was selected. * appointment highlight pointer if a new day was selected.
*/ */
static struct day_items_nb static struct day_items_nb do_storage(int day_changed)
do_storage (int day_changed)
{ {
struct day_items_nb inday = *day_process_storage (calendar_get_slctd_day (), struct day_items_nb inday = *day_process_storage(calendar_get_slctd_day(),
day_changed, &inday); day_changed, &inday);
if (day_changed) if (day_changed)
apoint_hilt_set (1); apoint_hilt_set(1);
return inday; return inday;
} }
@ -61,8 +60,7 @@ do_storage (int day_changed)
* and one can choose between different color schemes and layouts. * and one can choose between different color schemes and layouts.
* All of the commands are documented within an online help system. * All of the commands are documented within an online help system.
*/ */
int int main(int argc, char **argv)
main (int argc, char **argv)
{ {
struct day_items_nb inday; struct day_items_nb inday;
int no_data_file = 1; int no_data_file = 1;
@ -70,209 +68,195 @@ main (int argc, char **argv)
int count; int count;
#if ENABLE_NLS #if ENABLE_NLS
setlocale (LC_ALL, ""); setlocale(LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR); bindtextdomain(PACKAGE, LOCALEDIR);
textdomain (PACKAGE); textdomain(PACKAGE);
#endif /* ENABLE_NLS */ #endif /* ENABLE_NLS */
/* Thread-safe data structure init */ /* Thread-safe data structure init */
apoint_llist_init (); apoint_llist_init();
recur_apoint_llist_init (); recur_apoint_llist_init();
/* Initialize non-thread-safe data structures. */ /* Initialize non-thread-safe data structures. */
event_llist_init (); event_llist_init();
todo_init_list (); todo_init_list();
/* /*
* Begin by parsing and handling command line arguments. * Begin by parsing and handling command line arguments.
* The data path is also initialized here. * The data path is also initialized here.
*/ */
if (parse_args (argc, argv)) if (parse_args(argc, argv)) {
{
/* Non-interactive mode. */ /* Non-interactive mode. */
exit_calcurse (EXIT_SUCCESS); exit_calcurse(EXIT_SUCCESS);
} } else {
else no_data_file = io_check_data_files();
{ dmon_stop();
no_data_file = io_check_data_files (); io_set_lock();
dmon_stop ();
io_set_lock ();
} }
/* Begin of interactive mode with ncurses interface. */ /* Begin of interactive mode with ncurses interface. */
sigs_init (); /* signal handling init */ sigs_init(); /* signal handling init */
initscr (); /* start the curses mode */ initscr(); /* start the curses mode */
cbreak (); /* control chars generate a signal */ cbreak(); /* control chars generate a signal */
noecho (); /* controls echoing of typed chars */ noecho(); /* controls echoing of typed chars */
curs_set (0); /* make cursor invisible */ curs_set(0); /* make cursor invisible */
calendar_set_current_date (); calendar_set_current_date();
notify_init_vars (); notify_init_vars();
wins_get_config (); wins_get_config();
/* Check if terminal supports color. */ /* Check if terminal supports color. */
if (has_colors ()) if (has_colors()) {
{
colorize = 1; colorize = 1;
background = COLOR_BLACK; background = COLOR_BLACK;
foreground = COLOR_WHITE; foreground = COLOR_WHITE;
start_color (); start_color();
#ifdef NCURSES_VERSION #ifdef NCURSES_VERSION
if (use_default_colors () != ERR) if (use_default_colors() != ERR) {
{
background = -1; background = -1;
foreground = -1; foreground = -1;
} }
#endif /* NCURSES_VERSION */ #endif /* NCURSES_VERSION */
/* Color assignment */ /* Color assignment */
init_pair (COLR_RED, COLOR_RED, background); init_pair(COLR_RED, COLOR_RED, background);
init_pair (COLR_GREEN, COLOR_GREEN, background); init_pair(COLR_GREEN, COLOR_GREEN, background);
init_pair (COLR_YELLOW, COLOR_YELLOW, background); init_pair(COLR_YELLOW, COLOR_YELLOW, background);
init_pair (COLR_BLUE, COLOR_BLUE, background); init_pair(COLR_BLUE, COLOR_BLUE, background);
init_pair (COLR_MAGENTA, COLOR_MAGENTA, background); init_pair(COLR_MAGENTA, COLOR_MAGENTA, background);
init_pair (COLR_CYAN, COLOR_CYAN, background); init_pair(COLR_CYAN, COLOR_CYAN, background);
init_pair (COLR_DEFAULT, foreground, background); init_pair(COLR_DEFAULT, foreground, background);
init_pair (COLR_HIGH, COLOR_BLACK, COLOR_GREEN); init_pair(COLR_HIGH, COLOR_BLACK, COLOR_GREEN);
init_pair (COLR_CUSTOM, COLOR_RED, background); init_pair(COLR_CUSTOM, COLOR_RED, background);
} } else {
else
{
colorize = 0; colorize = 0;
background = COLOR_BLACK; background = COLOR_BLACK;
} }
vars_init (); vars_init();
wins_init (); wins_init();
wins_slctd_init (); wins_slctd_init();
notify_init_bar (); notify_init_bar();
wins_reset_status_page (); wins_reset_status_page();
/* /*
* Read the data from files : first the user * Read the data from files : first the user
* configuration (the display is then updated), and then * configuration (the display is then updated), and then
* the todo list, appointments and events. * the todo list, appointments and events.
*/ */
config_load (); config_load();
wins_erase_status_bar (); wins_erase_status_bar();
io_load_keys (conf.pager); io_load_keys(conf.pager);
io_load_todo (); io_load_todo();
io_load_app (); io_load_app();
wins_reinit (); wins_reinit();
if (conf.system_dialogs) if (conf.system_dialogs) {
{ wins_update(FLAG_ALL);
wins_update (FLAG_ALL); io_startup_screen(no_data_file);
io_startup_screen (no_data_file);
} }
inday = *day_process_storage (0, 0, &inday); inday = *day_process_storage(0, 0, &inday);
wins_slctd_set (CAL); wins_slctd_set(CAL);
wins_update (FLAG_ALL); wins_update(FLAG_ALL);
/* Start miscellaneous threads. */ /* Start miscellaneous threads. */
if (notify_bar ()) if (notify_bar())
notify_start_main_thread (); notify_start_main_thread();
calendar_start_date_thread (); calendar_start_date_thread();
if (conf.periodic_save > 0) if (conf.periodic_save > 0)
io_start_psave_thread (); io_start_psave_thread();
/* User input */ /* User input */
for (;;) for (;;) {
{
int key; int key;
if (resize) if (resize) {
{
resize = 0; resize = 0;
wins_reset (); wins_reset();
} }
key = keys_getch (win[STA].p, &count); key = keys_getch(win[STA].p, &count);
switch (key) switch (key) {
{
case KEY_GENERIC_REDRAW: case KEY_GENERIC_REDRAW:
resize = 1; resize = 1;
break; break;
case KEY_GENERIC_CHANGE_VIEW: case KEY_GENERIC_CHANGE_VIEW:
wins_reset_status_page (); wins_reset_status_page();
wins_slctd_next (); wins_slctd_next();
/* Select the event to highlight. */ /* Select the event to highlight. */
switch (wins_slctd ()) switch (wins_slctd()) {
{
case TOD: case TOD:
if ((todo_hilt () == 0) && (todo_nb () > 0)) if ((todo_hilt() == 0) && (todo_nb() > 0))
todo_hilt_set (1); todo_hilt_set(1);
break; break;
case APP: case APP:
if ((apoint_hilt () == 0) && if ((apoint_hilt() == 0) && ((inday.nb_events + inday.nb_apoints) > 0))
((inday.nb_events + inday.nb_apoints) > 0)) apoint_hilt_set(1);
apoint_hilt_set (1);
break; break;
default: default:
break; break;
} }
wins_update (FLAG_ALL); wins_update(FLAG_ALL);
break; break;
case KEY_GENERIC_OTHER_CMD: case KEY_GENERIC_OTHER_CMD:
wins_other_status_page (wins_slctd ()); wins_other_status_page(wins_slctd());
wins_update (FLAG_STA); wins_update(FLAG_STA);
break; break;
case KEY_GENERIC_GOTO: case KEY_GENERIC_GOTO:
case KEY_GENERIC_GOTO_TODAY: case KEY_GENERIC_GOTO_TODAY:
wins_erase_status_bar (); wins_erase_status_bar();
calendar_set_current_date (); calendar_set_current_date();
if (key == KEY_GENERIC_GOTO_TODAY) if (key == KEY_GENERIC_GOTO_TODAY)
calendar_goto_today (); calendar_goto_today();
else else
calendar_change_day (conf.input_datefmt); calendar_change_day(conf.input_datefmt);
inday = do_storage (1); inday = do_storage(1);
wins_update (FLAG_CAL | FLAG_APP | FLAG_STA); wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
break; break;
case KEY_VIEW_ITEM: case KEY_VIEW_ITEM:
if ((wins_slctd () == APP) && (apoint_hilt () != 0)) if ((wins_slctd() == APP) && (apoint_hilt() != 0))
day_popup_item (); day_popup_item();
else if ((wins_slctd () == TOD) && (todo_hilt () != 0)) else if ((wins_slctd() == TOD) && (todo_hilt() != 0))
item_in_popup (NULL, NULL, todo_saved_mesg (), _("To do :")); item_in_popup(NULL, NULL, todo_saved_mesg(), _("To do :"));
wins_update (FLAG_ALL); wins_update(FLAG_ALL);
break; break;
case KEY_GENERIC_CONFIG_MENU: case KEY_GENERIC_CONFIG_MENU:
wins_erase_status_bar (); wins_erase_status_bar();
custom_config_main (); custom_config_main();
inday = do_storage (0); inday = do_storage(0);
wins_update (FLAG_ALL); wins_update(FLAG_ALL);
break; break;
case KEY_GENERIC_ADD_APPT: case KEY_GENERIC_ADD_APPT:
apoint_add (); apoint_add();
inday = do_storage (1); inday = do_storage(1);
wins_update (FLAG_CAL | FLAG_APP | FLAG_STA); wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
break; break;
case KEY_GENERIC_ADD_TODO: case KEY_GENERIC_ADD_TODO:
todo_new_item (); todo_new_item();
if (todo_hilt () == 0 && todo_nb () == 1) if (todo_hilt() == 0 && todo_nb() == 1)
todo_hilt_increase (1); todo_hilt_increase(1);
wins_update (FLAG_TOD | FLAG_STA); wins_update(FLAG_TOD | FLAG_STA);
break; break;
case KEY_ADD_ITEM: case KEY_ADD_ITEM:
switch (wins_slctd ()) switch (wins_slctd()) {
{
case APP: case APP:
apoint_add (); apoint_add();
inday = do_storage (0); inday = do_storage(0);
wins_update (FLAG_CAL | FLAG_APP | FLAG_STA); wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
break; break;
case TOD: case TOD:
todo_new_item (); todo_new_item();
if (todo_hilt () == 0 && todo_nb () == 1) if (todo_hilt() == 0 && todo_nb() == 1)
todo_hilt_increase (1); todo_hilt_increase(1);
wins_update (FLAG_TOD | FLAG_STA); wins_update(FLAG_TOD | FLAG_STA);
break; break;
default: default:
break; break;
@ -280,283 +264,248 @@ main (int argc, char **argv)
break; break;
case KEY_EDIT_ITEM: case KEY_EDIT_ITEM:
if (wins_slctd () == APP && apoint_hilt () != 0) if (wins_slctd() == APP && apoint_hilt() != 0) {
{ day_edit_item();
day_edit_item (); inday = do_storage(0);
inday = do_storage (0); wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
wins_update (FLAG_CAL | FLAG_APP | FLAG_STA); } else if (wins_slctd() == TOD && todo_hilt() != 0) {
} todo_edit_item();
else if (wins_slctd () == TOD && todo_hilt () != 0) wins_update(FLAG_TOD | FLAG_STA);
{
todo_edit_item ();
wins_update (FLAG_TOD | FLAG_STA);
} }
break; break;
case KEY_DEL_ITEM: case KEY_DEL_ITEM:
if (wins_slctd () == APP && apoint_hilt () != 0) if (wins_slctd() == APP && apoint_hilt() != 0) {
{ apoint_delete(&inday.nb_events, &inday.nb_apoints);
apoint_delete (&inday.nb_events, &inday.nb_apoints); inday = do_storage(0);
inday = do_storage (0); wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
wins_update (FLAG_CAL | FLAG_APP | FLAG_STA); } else if (wins_slctd() == TOD && todo_hilt() != 0) {
} todo_delete();
else if (wins_slctd () == TOD && todo_hilt () != 0) wins_update(FLAG_TOD | FLAG_STA);
{
todo_delete ();
wins_update (FLAG_TOD | FLAG_STA);
} }
break; break;
case KEY_GENERIC_CUT: case KEY_GENERIC_CUT:
if (wins_slctd () == APP && apoint_hilt () != 0) if (wins_slctd() == APP && apoint_hilt() != 0) {
{ cut_item = apoint_cut(&inday.nb_events, &inday.nb_apoints);
cut_item = apoint_cut (&inday.nb_events, &inday.nb_apoints); inday = do_storage(0);
inday = do_storage (0); wins_update(FLAG_CAL | FLAG_APP);
wins_update (FLAG_CAL | FLAG_APP);
} }
break; break;
case KEY_GENERIC_PASTE: case KEY_GENERIC_PASTE:
if (wins_slctd () == APP) if (wins_slctd() == APP) {
{ apoint_paste(&inday.nb_events, &inday.nb_apoints, cut_item);
apoint_paste (&inday.nb_events, &inday.nb_apoints, cut_item);
cut_item = 0; cut_item = 0;
inday = do_storage (0); inday = do_storage(0);
wins_update (FLAG_CAL | FLAG_APP); wins_update(FLAG_CAL | FLAG_APP);
} }
break; break;
case KEY_REPEAT_ITEM: case KEY_REPEAT_ITEM:
if (wins_slctd () == APP && apoint_hilt () != 0) if (wins_slctd() == APP && apoint_hilt() != 0)
recur_repeat_item (); recur_repeat_item();
inday = do_storage (0); inday = do_storage(0);
wins_update (FLAG_CAL | FLAG_APP | FLAG_STA); wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
break; break;
case KEY_FLAG_ITEM: case KEY_FLAG_ITEM:
if (wins_slctd () == APP && apoint_hilt () != 0) if (wins_slctd() == APP && apoint_hilt() != 0) {
{ apoint_switch_notify();
apoint_switch_notify (); inday = do_storage(0);
inday = do_storage (0); wins_update(FLAG_APP);
wins_update (FLAG_APP); } else if (wins_slctd() == TOD && todo_hilt() != 0) {
} todo_flag();
else if (wins_slctd () == TOD && todo_hilt () != 0) wins_update(FLAG_TOD);
{
todo_flag ();
wins_update (FLAG_TOD);
} }
break; break;
case KEY_PIPE_ITEM: case KEY_PIPE_ITEM:
if (wins_slctd () == APP && apoint_hilt () != 0) if (wins_slctd() == APP && apoint_hilt() != 0)
day_pipe_item (); day_pipe_item();
else if (wins_slctd () == TOD && todo_hilt () != 0) else if (wins_slctd() == TOD && todo_hilt() != 0)
todo_pipe_item (); todo_pipe_item();
wins_update (FLAG_ALL); wins_update(FLAG_ALL);
break; break;
case KEY_RAISE_PRIORITY: case KEY_RAISE_PRIORITY:
case KEY_LOWER_PRIORITY: case KEY_LOWER_PRIORITY:
if (wins_slctd () == TOD && todo_hilt () != 0) if (wins_slctd() == TOD && todo_hilt() != 0) {
{ todo_chg_priority(key);
todo_chg_priority (key); if (todo_hilt_pos() < 0)
if (todo_hilt_pos () < 0) todo_set_first(todo_hilt());
todo_set_first (todo_hilt ()); else if (todo_hilt_pos() >= win[TOD].h - 4)
else if (todo_hilt_pos () >= win[TOD].h - 4) todo_set_first(todo_hilt() - win[TOD].h + 5);
todo_set_first (todo_hilt () - win[TOD].h + 5); wins_update(FLAG_TOD);
wins_update (FLAG_TOD);
} }
break; break;
case KEY_EDIT_NOTE: case KEY_EDIT_NOTE:
if (wins_slctd () == APP && apoint_hilt () != 0) if (wins_slctd() == APP && apoint_hilt() != 0) {
{ day_edit_note(conf.editor);
day_edit_note (conf.editor); inday = do_storage(0);
inday = do_storage (0); } else if (wins_slctd() == TOD && todo_hilt() != 0)
} todo_edit_note(conf.editor);
else if (wins_slctd () == TOD && todo_hilt () != 0) wins_update(FLAG_ALL);
todo_edit_note (conf.editor);
wins_update (FLAG_ALL);
break; break;
case KEY_VIEW_NOTE: case KEY_VIEW_NOTE:
if (wins_slctd () == APP && apoint_hilt () != 0) if (wins_slctd() == APP && apoint_hilt() != 0)
day_view_note (conf.pager); day_view_note(conf.pager);
else if (wins_slctd () == TOD && todo_hilt () != 0) else if (wins_slctd() == TOD && todo_hilt() != 0)
todo_view_note (conf.pager); todo_view_note(conf.pager);
wins_update (FLAG_ALL); wins_update(FLAG_ALL);
break; break;
case KEY_GENERIC_HELP: case KEY_GENERIC_HELP:
wins_status_bar (); wins_status_bar();
help_screen (); help_screen();
wins_update (FLAG_ALL); wins_update(FLAG_ALL);
break; break;
case KEY_GENERIC_SAVE: case KEY_GENERIC_SAVE:
io_save_cal (IO_SAVE_DISPLAY_BAR); io_save_cal(IO_SAVE_DISPLAY_BAR);
wins_update (FLAG_STA); wins_update(FLAG_STA);
break; break;
case KEY_GENERIC_IMPORT: case KEY_GENERIC_IMPORT:
wins_erase_status_bar (); wins_erase_status_bar();
io_import_data (IO_IMPORT_ICAL, NULL); io_import_data(IO_IMPORT_ICAL, NULL);
inday = do_storage (0); inday = do_storage(0);
wins_update (FLAG_ALL); wins_update(FLAG_ALL);
break; break;
case KEY_GENERIC_EXPORT: case KEY_GENERIC_EXPORT:
wins_erase_status_bar (); wins_erase_status_bar();
io_export_bar (); io_export_bar();
while ((key = wgetch (win[STA].p)) != 'q') while ((key = wgetch(win[STA].p)) != 'q') {
{ switch (key) {
switch (key)
{
case 'I': case 'I':
case 'i': case 'i':
io_export_data (IO_EXPORT_ICAL); io_export_data(IO_EXPORT_ICAL);
break; break;
case 'P': case 'P':
case 'p': case 'p':
io_export_data (IO_EXPORT_PCAL); io_export_data(IO_EXPORT_PCAL);
break; break;
} }
wins_reset (); wins_reset();
wins_update (FLAG_ALL); wins_update(FLAG_ALL);
wins_erase_status_bar (); wins_erase_status_bar();
io_export_bar (); io_export_bar();
} }
inday = do_storage (0); inday = do_storage(0);
wins_update (FLAG_ALL); wins_update(FLAG_ALL);
break; break;
case KEY_GENERIC_NEXT_DAY: case KEY_GENERIC_NEXT_DAY:
case KEY_MOVE_RIGHT: case KEY_MOVE_RIGHT:
if (wins_slctd () == CAL || key == KEY_GENERIC_NEXT_DAY) if (wins_slctd() == CAL || key == KEY_GENERIC_NEXT_DAY) {
{ calendar_move(RIGHT, count);
calendar_move (RIGHT, count); inday = do_storage(1);
inday = do_storage (1); wins_update(FLAG_CAL | FLAG_APP);
wins_update (FLAG_CAL | FLAG_APP);
} }
break; break;
case KEY_GENERIC_PREV_DAY: case KEY_GENERIC_PREV_DAY:
case KEY_MOVE_LEFT: case KEY_MOVE_LEFT:
if (wins_slctd () == CAL || key == KEY_GENERIC_PREV_DAY) if (wins_slctd() == CAL || key == KEY_GENERIC_PREV_DAY) {
{ calendar_move(LEFT, count);
calendar_move (LEFT, count); inday = do_storage(1);
inday = do_storage (1); wins_update(FLAG_CAL | FLAG_APP);
wins_update (FLAG_CAL | FLAG_APP);
} }
break; break;
case KEY_GENERIC_PREV_WEEK: case KEY_GENERIC_PREV_WEEK:
case KEY_MOVE_UP: case KEY_MOVE_UP:
if (wins_slctd () == CAL || key == KEY_GENERIC_PREV_WEEK) if (wins_slctd() == CAL || key == KEY_GENERIC_PREV_WEEK) {
{ calendar_move(UP, count);
calendar_move (UP, count); inday = do_storage(1);
inday = do_storage (1); wins_update(FLAG_CAL | FLAG_APP);
wins_update (FLAG_CAL | FLAG_APP); } else if (wins_slctd() == APP) {
} if (count >= apoint_hilt())
else if (wins_slctd () == APP) count = apoint_hilt() - 1;
{ apoint_hilt_decrease(count);
if (count >= apoint_hilt ()) apoint_scroll_pad_up(inday.nb_events);
count = apoint_hilt () - 1; wins_update(FLAG_APP);
apoint_hilt_decrease (count); } else if (wins_slctd() == TOD) {
apoint_scroll_pad_up (inday.nb_events); if (count >= todo_hilt())
wins_update (FLAG_APP); count = todo_hilt() - 1;
} todo_hilt_decrease(count);
else if (wins_slctd () == TOD) if (todo_hilt_pos() < 0)
{ todo_first_increase(todo_hilt_pos());
if (count >= todo_hilt ()) wins_update(FLAG_TOD);
count = todo_hilt () - 1;
todo_hilt_decrease (count);
if (todo_hilt_pos () < 0)
todo_first_increase (todo_hilt_pos ());
wins_update (FLAG_TOD);
} }
break; break;
case KEY_GENERIC_NEXT_WEEK: case KEY_GENERIC_NEXT_WEEK:
case KEY_MOVE_DOWN: case KEY_MOVE_DOWN:
if (wins_slctd () == CAL || key == KEY_GENERIC_NEXT_WEEK) if (wins_slctd() == CAL || key == KEY_GENERIC_NEXT_WEEK) {
{ calendar_move(DOWN, count);
calendar_move (DOWN, count); inday = do_storage(1);
inday = do_storage (1); wins_update(FLAG_CAL | FLAG_APP);
wins_update (FLAG_CAL | FLAG_APP); } else if (wins_slctd() == APP) {
} if (count > inday.nb_events + inday.nb_apoints - apoint_hilt())
else if (wins_slctd () == APP) count = inday.nb_events + inday.nb_apoints - apoint_hilt();
{ apoint_hilt_increase(count);
if (count > inday.nb_events + inday.nb_apoints - apoint_hilt ()) apoint_scroll_pad_down(inday.nb_events, win[APP].h);
count = inday.nb_events + inday.nb_apoints - apoint_hilt (); wins_update(FLAG_APP);
apoint_hilt_increase (count); } else if (wins_slctd() == TOD) {
apoint_scroll_pad_down (inday.nb_events, win[APP].h); if (count > todo_nb() - todo_hilt())
wins_update (FLAG_APP); count = todo_nb() - todo_hilt();
} todo_hilt_increase(count);
else if (wins_slctd () == TOD) if (todo_hilt_pos() >= win[TOD].h - 4)
{ todo_first_increase(todo_hilt_pos() - win[TOD].h + 5);
if (count > todo_nb () - todo_hilt ()) wins_update(FLAG_TOD);
count = todo_nb () - todo_hilt ();
todo_hilt_increase (count);
if (todo_hilt_pos () >= win[TOD].h - 4)
todo_first_increase (todo_hilt_pos () - win[TOD].h + 5);
wins_update (FLAG_TOD);
} }
break; break;
case KEY_START_OF_WEEK: case KEY_START_OF_WEEK:
if (wins_slctd () == CAL) if (wins_slctd() == CAL) {
{ calendar_move(WEEK_START, count);
calendar_move (WEEK_START, count); inday = do_storage(1);
inday = do_storage (1); wins_update(FLAG_CAL | FLAG_APP);
wins_update (FLAG_CAL | FLAG_APP);
} }
break; break;
case KEY_END_OF_WEEK: case KEY_END_OF_WEEK:
if (wins_slctd () == CAL) if (wins_slctd() == CAL) {
{ calendar_move(WEEK_END, count);
calendar_move (WEEK_END, count); inday = do_storage(1);
inday = do_storage (1); wins_update(FLAG_CAL | FLAG_APP);
wins_update (FLAG_CAL | FLAG_APP);
} }
break; break;
case KEY_GENERIC_SCROLL_UP: case KEY_GENERIC_SCROLL_UP:
if (wins_slctd () == CAL) if (wins_slctd() == CAL) {
{ calendar_view_prev();
calendar_view_prev (); wins_update(FLAG_CAL | FLAG_APP);
wins_update (FLAG_CAL | FLAG_APP);
} }
break; break;
case KEY_GENERIC_SCROLL_DOWN: case KEY_GENERIC_SCROLL_DOWN:
if (wins_slctd () == CAL) if (wins_slctd() == CAL) {
{ calendar_view_next();
calendar_view_next (); wins_update(FLAG_CAL | FLAG_APP);
wins_update (FLAG_CAL | FLAG_APP);
} }
break; break;
case KEY_GENERIC_QUIT: case KEY_GENERIC_QUIT:
if (conf.auto_save) if (conf.auto_save)
io_save_cal (IO_SAVE_DISPLAY_BAR); io_save_cal(IO_SAVE_DISPLAY_BAR);
if (conf.auto_gc) if (conf.auto_gc)
note_gc (); note_gc();
if (conf.confirm_quit) if (conf.confirm_quit) {
{ if (status_ask_bool(_("Do you really want to quit ?")) == 1)
if (status_ask_bool (_("Do you really want to quit ?")) == 1) exit_calcurse(EXIT_SUCCESS);
exit_calcurse (EXIT_SUCCESS); else {
else wins_erase_status_bar();
{ wins_update(FLAG_STA);
wins_erase_status_bar ();
wins_update (FLAG_STA);
break; break;
} }
} } else
else exit_calcurse(EXIT_SUCCESS);
exit_calcurse (EXIT_SUCCESS);
break; break;
case KEY_RESIZE: case KEY_RESIZE:

View File

@ -40,13 +40,13 @@
#include "config.h" #include "config.h"
#ifdef HAVE_NCURSES_H #ifdef HAVE_NCURSES_H
# include <ncurses.h> #include <ncurses.h>
#elif defined HAVE_NCURSES_NCURSES_H #elif defined HAVE_NCURSES_NCURSES_H
# include <ncurses/ncurses.h> #include <ncurses/ncurses.h>
#elif defined HAVE_NCURSESW_NCURSES_H #elif defined HAVE_NCURSESW_NCURSES_H
# include <ncursesw/ncurses.h> #include <ncursesw/ncurses.h>
#else #else
# error "Missing ncurses header. Aborting..." #error "Missing ncurses header. Aborting..."
#endif #endif
#include <pthread.h> #include <pthread.h>
@ -60,24 +60,24 @@
/* Internationalization. */ /* Internationalization. */
#if ENABLE_NLS #if ENABLE_NLS
# include <locale.h> #include <locale.h>
# include <libintl.h> #include <libintl.h>
# undef _ #undef _
# define _(String) gettext(String) #define _(String) gettext(String)
# ifdef gettext_noop #ifdef gettext_noop
# define N_(String) gettext_noop(String) #define N_(String) gettext_noop(String)
# else #else
# define N_(String) (String) #define N_(String) (String)
# endif #endif
#else /* NLS disabled */ #else /* NLS disabled */
# define _(String) (String) #define _(String) (String)
# define N_(String) (String) #define N_(String) (String)
# define textdomain(String) (String) #define textdomain(String) (String)
# define gettext(String) (String) #define gettext(String) (String)
# define dgettext(String) (String) #define dgettext(String) (String)
# define dcgettext(String) (String) #define dcgettext(String) (String)
# define bindtextdomain(String) (String) #define bindtextdomain(String) (String)
# define bind_textdomain_codeset(Domain,Codeset) (Codeset) #define bind_textdomain_codeset(Domain,Codeset) (Codeset)
#endif /* ENABLE_NLS */ #endif /* ENABLE_NLS */
/* Paths configuration. */ /* Paths configuration. */
@ -270,8 +270,7 @@ struct date {
}; };
/* Appointment definition. */ /* Appointment definition. */
struct apoint struct apoint {
{
long start; /* seconds since 1 jan 1970 */ long start; /* seconds since 1 jan 1970 */
long dur; /* duration of the appointment in seconds */ long dur; /* duration of the appointment in seconds */
@ -569,376 +568,367 @@ enum save_display {
/* apoint.c */ /* apoint.c */
extern llist_ts_t alist_p; extern llist_ts_t alist_p;
void apoint_free_bkp (void); void apoint_free_bkp(void);
void apoint_llist_init (void); void apoint_llist_init(void);
void apoint_llist_free (void); void apoint_llist_free(void);
void apoint_hilt_set (int); void apoint_hilt_set(int);
void apoint_hilt_decrease (int); void apoint_hilt_decrease(int);
void apoint_hilt_increase (int); void apoint_hilt_increase(int);
int apoint_hilt (void); int apoint_hilt(void);
struct apoint *apoint_new (char *, char *, long, long, char); struct apoint *apoint_new(char *, char *, long, long, char);
void apoint_add (void); void apoint_add(void);
void apoint_delete (unsigned *, unsigned *); void apoint_delete(unsigned *, unsigned *);
int apoint_cut (unsigned *, unsigned *); int apoint_cut(unsigned *, unsigned *);
void apoint_paste (unsigned *, unsigned *, int); void apoint_paste(unsigned *, unsigned *, int);
unsigned apoint_inday (struct apoint *, long); unsigned apoint_inday(struct apoint *, long);
void apoint_sec2str (struct apoint *, long, char *, char *); void apoint_sec2str(struct apoint *, long, char *, char *);
void apoint_write (struct apoint *, FILE *); void apoint_write(struct apoint *, FILE *);
struct apoint *apoint_scan (FILE *, struct tm, struct tm, char, char *); struct apoint *apoint_scan(FILE *, struct tm, struct tm, char, char *);
struct apoint *apoint_get (long, int); struct apoint *apoint_get(long, int);
void apoint_delete_bynum (long, unsigned, enum eraseflg); void apoint_delete_bynum(long, unsigned, enum eraseflg);
void apoint_scroll_pad_down (int, int); void apoint_scroll_pad_down(int, int);
void apoint_scroll_pad_up (int); void apoint_scroll_pad_up(int);
struct notify_app *apoint_check_next (struct notify_app *, long); struct notify_app *apoint_check_next(struct notify_app *, long);
void apoint_switch_notify (void); void apoint_switch_notify(void);
void apoint_update_panel (int); void apoint_update_panel(int);
void apoint_paste_item (void); void apoint_paste_item(void);
/* args.c */ /* args.c */
int parse_args (int, char **); int parse_args(int, char **);
/* calendar.c */ /* calendar.c */
void calendar_view_next (void); void calendar_view_next(void);
void calendar_view_prev (void); void calendar_view_prev(void);
void calendar_set_view (int); void calendar_set_view(int);
int calendar_get_view (void); int calendar_get_view(void);
void calendar_start_date_thread (void); void calendar_start_date_thread(void);
void calendar_stop_date_thread (void); void calendar_stop_date_thread(void);
void calendar_set_current_date (void); void calendar_set_current_date(void);
void calendar_set_first_day_of_week (enum wday); void calendar_set_first_day_of_week(enum wday);
void calendar_change_first_day_of_week (void); void calendar_change_first_day_of_week(void);
unsigned calendar_week_begins_on_monday (void); unsigned calendar_week_begins_on_monday(void);
void calendar_store_current_date (struct date *); void calendar_store_current_date(struct date *);
void calendar_init_slctd_day (void); void calendar_init_slctd_day(void);
struct date *calendar_get_slctd_day (void); struct date *calendar_get_slctd_day(void);
long calendar_get_slctd_day_sec (void); long calendar_get_slctd_day_sec(void);
void calendar_update_panel (struct window *); void calendar_update_panel(struct window *);
void calendar_goto_today (void); void calendar_goto_today(void);
void calendar_change_day (int); void calendar_change_day(int);
void calendar_move (enum move, int); void calendar_move(enum move, int);
long calendar_start_of_year (void); long calendar_start_of_year(void);
long calendar_end_of_year (void); long calendar_end_of_year(void);
const char *calendar_get_pom (time_t); const char *calendar_get_pom(time_t);
/* config.c */ /* config.c */
void config_load (void); void config_load(void);
unsigned config_save (void); unsigned config_save(void);
/* custom.c */ /* custom.c */
void custom_init_attr (void); void custom_init_attr(void);
void custom_apply_attr (WINDOW *, int); void custom_apply_attr(WINDOW *, int);
void custom_remove_attr (WINDOW *, int); void custom_remove_attr(WINDOW *, int);
void custom_config_bar (void); void custom_config_bar(void);
void custom_layout_config (void); void custom_layout_config(void);
void custom_sidebar_config (void); void custom_sidebar_config(void);
void custom_color_config (void); void custom_color_config(void);
void custom_color_theme_name (char *); void custom_color_theme_name(char *);
void custom_confwin_init (struct window *, const char *); void custom_confwin_init(struct window *, const char *);
void custom_set_swsiz (struct scrollwin *); void custom_set_swsiz(struct scrollwin *);
void custom_general_config (void); void custom_general_config(void);
void custom_keys_config (void); void custom_keys_config(void);
void custom_config_main (void); void custom_config_main(void);
/* day.c */ /* day.c */
void day_free_list (void); void day_free_list(void);
struct day_items_nb *day_process_storage (struct date *, unsigned, struct day_items_nb *day_process_storage(struct date *, unsigned,
struct day_items_nb *); struct day_items_nb *);
void day_write_pad (long, int, int, int); void day_write_pad(long, int, int, int);
void day_popup_item (void); void day_popup_item(void);
int day_check_if_item (struct date); int day_check_if_item(struct date);
unsigned day_chk_busy_slices (struct date, int, int *); unsigned day_chk_busy_slices(struct date, int, int *);
void day_edit_item (void); void day_edit_item(void);
int day_erase_item (long, int, enum eraseflg); int day_erase_item(long, int, enum eraseflg);
int day_cut_item (long, int); int day_cut_item(long, int);
int day_paste_item (long, int); int day_paste_item(long, int);
struct day_item *day_get_item (int); struct day_item *day_get_item(int);
int day_item_nb (long, int, int); int day_item_nb(long, int, int);
void day_edit_note (const char *); void day_edit_note(const char *);
void day_view_note (const char *); void day_view_note(const char *);
void day_pipe_item (void); void day_pipe_item(void);
/* dmon.c */ /* dmon.c */
void dmon_start (int); void dmon_start(int);
void dmon_stop (void); void dmon_stop(void);
/* event.c */ /* event.c */
extern llist_t eventlist; extern llist_t eventlist;
void event_free_bkp (void); void event_free_bkp(void);
void event_llist_init (void); void event_llist_init(void);
void event_llist_free (void); void event_llist_free(void);
struct event *event_new (char *, char *, long, int); struct event *event_new(char *, char *, long, int);
unsigned event_inday (struct event *, long); unsigned event_inday(struct event *, long);
void event_write (struct event *, FILE *); void event_write(struct event *, FILE *);
struct event *event_scan (FILE *, struct tm, int, char *); struct event *event_scan(FILE *, struct tm, int, char *);
struct event *event_get (long, int); struct event *event_get(long, int);
void event_delete_bynum (long, unsigned, enum eraseflg); void event_delete_bynum(long, unsigned, enum eraseflg);
void event_paste_item (void); void event_paste_item(void);
/* help.c */ /* help.c */
void help_wins_init (struct scrollwin *, int, int, int, int); void help_wins_init(struct scrollwin *, int, int, int, int);
void help_screen (void); void help_screen(void);
/* getstring.c */ /* getstring.c */
enum getstr getstring (WINDOW *, char *, int, int, int); enum getstr getstring(WINDOW *, char *, int, int, int);
int updatestring (WINDOW *, char **, int, int); int updatestring(WINDOW *, char **, int, int);
/* ical.c */ /* ical.c */
void ical_import_data (FILE *, FILE *, unsigned *, unsigned *, unsigned *, void ical_import_data(FILE *, FILE *, unsigned *, unsigned *, unsigned *,
unsigned *, unsigned *); unsigned *, unsigned *);
void ical_export_data (FILE *); void ical_export_data(FILE *);
/* io.c */ /* io.c */
unsigned io_fprintln (const char *, const char *, ...); unsigned io_fprintln(const char *, const char *, ...);
void io_init (const char *, const char *); void io_init(const char *, const char *);
void io_extract_data (char *, const char *, int); void io_extract_data(char *, const char *, int);
unsigned io_save_apts (void); unsigned io_save_apts(void);
unsigned io_save_todo (void); unsigned io_save_todo(void);
unsigned io_save_keys (void); unsigned io_save_keys(void);
void io_save_cal (enum save_display); void io_save_cal(enum save_display);
void io_load_app (void); void io_load_app(void);
void io_load_todo (void); void io_load_todo(void);
void io_load_keys (const char *); void io_load_keys(const char *);
void io_check_dir (char *, int *); void io_check_dir(char *, int *);
unsigned io_file_exist (char *); unsigned io_file_exist(char *);
void io_check_file (char *, int *); void io_check_file(char *, int *);
int io_check_data_files (void); int io_check_data_files(void);
void io_startup_screen (int); void io_startup_screen(int);
void io_export_data (enum export_type); void io_export_data(enum export_type);
void io_export_bar (void); void io_export_bar(void);
void io_import_data (enum import_type, const char *); void io_import_data(enum import_type, const char *);
struct io_file *io_log_init (void); struct io_file *io_log_init(void);
void io_log_print (struct io_file *, int, const char *); void io_log_print(struct io_file *, int, const char *);
void io_log_display (struct io_file *, const char *, const char *); void io_log_display(struct io_file *, const char *, const char *);
void io_log_free (struct io_file *); void io_log_free(struct io_file *);
void io_start_psave_thread (void); void io_start_psave_thread(void);
void io_stop_psave_thread (void); void io_stop_psave_thread(void);
void io_set_lock (void); void io_set_lock(void);
unsigned io_dump_pid (char *); unsigned io_dump_pid(char *);
unsigned io_get_pid (char *); unsigned io_get_pid(char *);
int io_file_is_empty (char *); int io_file_is_empty(char *);
int io_file_cp (const char *, const char *); int io_file_cp(const char *, const char *);
/* keys.c */ /* keys.c */
void keys_init (void); void keys_init(void);
void keys_free (void); void keys_free(void);
void keys_dump_defaults (char *); void keys_dump_defaults(char *);
const char *keys_get_label (enum key); const char *keys_get_label(enum key);
enum key keys_get_action (int); enum key keys_get_action(int);
enum key keys_getch (WINDOW *win, int *); enum key keys_getch(WINDOW * win, int *);
int keys_assign_binding (int, enum key); int keys_assign_binding(int, enum key);
void keys_remove_binding (int, enum key); void keys_remove_binding(int, enum key);
int keys_str2int (const char *); int keys_str2int(const char *);
const char *keys_int2str (int); const char *keys_int2str(int);
int keys_action_count_keys (enum key); int keys_action_count_keys(enum key);
const char *keys_action_firstkey (enum key); const char *keys_action_firstkey(enum key);
const char *keys_action_nkey (enum key, int); const char *keys_action_nkey(enum key, int);
char *keys_action_allkeys (enum key); char *keys_action_allkeys(enum key);
void keys_display_bindings_bar (WINDOW *, struct binding *[], int, int, void keys_display_bindings_bar(WINDOW *, struct binding *[], int, int,
int, struct binding *); int, struct binding *);
void keys_popup_info (enum key); void keys_popup_info(enum key);
void keys_save_bindings (FILE *); void keys_save_bindings(FILE *);
int keys_check_missing_bindings (void); int keys_check_missing_bindings(void);
void keys_fill_missing (void); void keys_fill_missing(void);
/* mem.c */ /* mem.c */
void *xmalloc (size_t); void *xmalloc(size_t);
void *xcalloc (size_t, size_t); void *xcalloc(size_t, size_t);
void *xrealloc (void *, size_t, size_t); void *xrealloc(void *, size_t, size_t);
char *xstrdup (const char *); char *xstrdup(const char *);
void xfree (void *); void xfree(void *);
#ifdef CALCURSE_MEMORY_DEBUG #ifdef CALCURSE_MEMORY_DEBUG
# define mem_malloc(s) dbg_malloc ((s), __FILE_POS__) #define mem_malloc(s) dbg_malloc ((s), __FILE_POS__)
# define mem_calloc(n, s) dbg_calloc ((n), (s), __FILE_POS__) #define mem_calloc(n, s) dbg_calloc ((n), (s), __FILE_POS__)
# define mem_realloc(p, n, s) dbg_realloc ((p), (n), (s), __FILE_POS__) #define mem_realloc(p, n, s) dbg_realloc ((p), (n), (s), __FILE_POS__)
# define mem_strdup(s) dbg_strdup ((s), __FILE_POS__) #define mem_strdup(s) dbg_strdup ((s), __FILE_POS__)
# define mem_free(p) dbg_free ((p), __FILE_POS__) #define mem_free(p) dbg_free ((p), __FILE_POS__)
void *dbg_malloc (size_t, const char *); void *dbg_malloc(size_t, const char *);
void *dbg_calloc (size_t, size_t, const char *); void *dbg_calloc(size_t, size_t, const char *);
void *dbg_realloc (void *, size_t, size_t, const char *); void *dbg_realloc(void *, size_t, size_t, const char *);
char *dbg_strdup (const char *, const char *); char *dbg_strdup(const char *, const char *);
void dbg_free (void *, const char *); void dbg_free(void *, const char *);
void mem_stats (void); void mem_stats(void);
#else /* MEMORY DEBUG disabled */ #else /* MEMORY DEBUG disabled */
# define mem_malloc(s) xmalloc ((s)) #define mem_malloc(s) xmalloc ((s))
# define mem_calloc(n, s) xcalloc ((n), (s)) #define mem_calloc(n, s) xcalloc ((n), (s))
# define mem_realloc(p, n, s) xrealloc ((p), (n), (s)) #define mem_realloc(p, n, s) xrealloc ((p), (n), (s))
# define mem_strdup(s) xstrdup ((s)) #define mem_strdup(s) xstrdup ((s))
# define mem_free(p) xfree ((p)) #define mem_free(p) xfree ((p))
# define mem_stats() #define mem_stats()
#endif /* CALCURSE_MEMORY_DEBUG */ #endif /* CALCURSE_MEMORY_DEBUG */
/* note.c */ /* note.c */
char *generate_note (const char *); char *generate_note(const char *);
void edit_note (char **, const char *); void edit_note(char **, const char *);
void view_note (const char *, const char *); void view_note(const char *, const char *);
void erase_note (char **); void erase_note(char **);
void note_read (char *, FILE *); void note_read(char *, FILE *);
void note_gc (void); void note_gc(void);
/* notify.c */ /* notify.c */
int notify_time_left (void); int notify_time_left(void);
unsigned notify_needs_reminder (void); unsigned notify_needs_reminder(void);
void notify_update_app (long, char, char *); void notify_update_app(long, char, char *);
int notify_bar (void); int notify_bar(void);
void notify_init_vars (void); void notify_init_vars(void);
void notify_init_bar (void); void notify_init_bar(void);
void notify_free_app (void); void notify_free_app(void);
void notify_start_main_thread (void); void notify_start_main_thread(void);
void notify_stop_main_thread (void); void notify_stop_main_thread(void);
void notify_reinit_bar (void); void notify_reinit_bar(void);
unsigned notify_launch_cmd (void); unsigned notify_launch_cmd(void);
void notify_update_bar (void); void notify_update_bar(void);
unsigned notify_get_next (struct notify_app *); unsigned notify_get_next(struct notify_app *);
unsigned notify_get_next_bkgd (void); unsigned notify_get_next_bkgd(void);
char *notify_app_txt (void); char *notify_app_txt(void);
void notify_check_next_app (int); void notify_check_next_app(int);
void notify_check_added (char *, long, char); void notify_check_added(char *, long, char);
void notify_check_repeated (struct recur_apoint *); void notify_check_repeated(struct recur_apoint *);
int notify_same_item (long); int notify_same_item(long);
int notify_same_recur_item (struct recur_apoint *); int notify_same_recur_item(struct recur_apoint *);
void notify_config_bar (void); void notify_config_bar(void);
/* pcal.c */ /* pcal.c */
void pcal_export_data (FILE *); void pcal_export_data(FILE *);
/* recur.c */ /* recur.c */
extern llist_ts_t recur_alist_p; extern llist_ts_t recur_alist_p;
extern llist_t recur_elist; extern llist_t recur_elist;
void recur_event_free_bkp (void); void recur_event_free_bkp(void);
void recur_apoint_free_bkp (void); void recur_apoint_free_bkp(void);
void recur_apoint_llist_init (void); void recur_apoint_llist_init(void);
void recur_apoint_llist_free (void); void recur_apoint_llist_free(void);
void recur_event_llist_free (void); void recur_event_llist_free(void);
struct recur_apoint *recur_apoint_new (char *, char *, long, long, char, 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, struct recur_event *recur_event_new(char *, char *, long, int, int, int,
long, llist_t *); long, llist_t *);
char recur_def2char (enum recur_type); char recur_def2char(enum recur_type);
int recur_char2def (char); int recur_char2def(char);
struct recur_apoint *recur_apoint_scan (FILE *, struct tm, struct tm, struct recur_apoint *recur_apoint_scan(FILE *, struct tm, struct tm,
char, int, struct tm, char *, char, int, struct tm, char *,
llist_t *, char); llist_t *, char);
struct recur_event *recur_event_scan (FILE *, struct tm, int, char, struct recur_event *recur_event_scan(FILE *, struct tm, int, char,
int, struct tm, char *, int, struct tm, char *, llist_t *);
llist_t *); void recur_apoint_write(struct recur_apoint *, FILE *);
void recur_apoint_write (struct recur_apoint *, FILE *); void recur_event_write(struct recur_event *, FILE *);
void recur_event_write (struct recur_event *, FILE *); void recur_save_data(FILE *);
void recur_save_data (FILE *); unsigned recur_item_find_occurrence(long, long, llist_t *, int,
unsigned recur_item_find_occurrence (long, long, llist_t *, int,
int, long, long, unsigned *); int, long, long, unsigned *);
unsigned recur_apoint_find_occurrence (struct recur_apoint *, unsigned recur_apoint_find_occurrence(struct recur_apoint *, long, unsigned *);
long, unsigned *); unsigned recur_event_find_occurrence(struct recur_event *, long, unsigned *);
unsigned recur_event_find_occurrence (struct recur_event *, long, unsigned recur_item_inday(long, long, llist_t *, int, int, long, long);
unsigned *);
unsigned recur_item_inday (long, long, llist_t *, int, int, long,
long);
unsigned recur_apoint_inday(struct recur_apoint *, long); unsigned recur_apoint_inday(struct recur_apoint *, long);
unsigned recur_event_inday(struct recur_event *, long); unsigned recur_event_inday(struct recur_event *, long);
void recur_event_erase (long, unsigned, unsigned, void recur_event_erase(long, unsigned, unsigned, enum eraseflg);
enum eraseflg); void recur_apoint_erase(long, unsigned, unsigned, enum eraseflg);
void recur_apoint_erase (long, unsigned, unsigned, void recur_repeat_item(void);
enum eraseflg); void recur_exc_scan(llist_t *, FILE *);
void recur_repeat_item (void); struct notify_app *recur_apoint_check_next(struct notify_app *, long, long);
void recur_exc_scan (llist_t *, FILE *); struct recur_apoint *recur_get_apoint(long, int);
struct notify_app *recur_apoint_check_next (struct notify_app *, long, long); struct recur_event *recur_get_event(long, int);
struct recur_apoint *recur_get_apoint (long, int); void recur_apoint_switch_notify(long, int);
struct recur_event *recur_get_event (long, int); void recur_event_paste_item(void);
void recur_apoint_switch_notify (long, int); void recur_apoint_paste_item(void);
void recur_event_paste_item (void);
void recur_apoint_paste_item (void);
/* sigs.c */ /* sigs.c */
void sigs_init (void); void sigs_init(void);
unsigned sigs_set_hdlr (int, void (*)(int)); unsigned sigs_set_hdlr(int, void (*)(int));
/* todo.c */ /* todo.c */
extern llist_t todolist; extern llist_t todolist;
void todo_hilt_set (int); void todo_hilt_set(int);
void todo_hilt_decrease (int); void todo_hilt_decrease(int);
void todo_hilt_increase (int); void todo_hilt_increase(int);
int todo_hilt (void); int todo_hilt(void);
int todo_nb (void); int todo_nb(void);
void todo_set_nb (int); void todo_set_nb(int);
void todo_set_first (int); void todo_set_first(int);
void todo_first_increase (int); void todo_first_increase(int);
void todo_first_decrease (int); void todo_first_decrease(int);
int todo_hilt_pos (void); int todo_hilt_pos(void);
char *todo_saved_mesg (void); char *todo_saved_mesg(void);
void todo_new_item (void); void todo_new_item(void);
struct todo *todo_add (char *, int, char *); struct todo *todo_add(char *, int, char *);
void todo_write (struct todo *, FILE *); void todo_write(struct todo *, FILE *);
void todo_flag (void); void todo_flag(void);
void todo_delete (void); void todo_delete(void);
void todo_chg_priority (int); void todo_chg_priority(int);
void todo_edit_item (void); void todo_edit_item(void);
void todo_update_panel (int); void todo_update_panel(int);
void todo_edit_note (const char *); void todo_edit_note(const char *);
void todo_view_note (const char *); void todo_view_note(const char *);
void todo_pipe_item (void); void todo_pipe_item(void);
void todo_init_list (void); void todo_init_list(void);
void todo_free_list (void); void todo_free_list(void);
/* utf8.c */ /* utf8.c */
int utf8_width (char *); int utf8_width(char *);
int utf8_strwidth (char *); int utf8_strwidth(char *);
/* utils.c */ /* utils.c */
void exit_calcurse (int) __attribute__((__noreturn__)); void exit_calcurse(int) __attribute__ ((__noreturn__));
void free_user_data (void); void free_user_data(void);
void fatalbox (const char *); void fatalbox(const char *);
void warnbox (const char *); void warnbox(const char *);
void status_mesg (const char *, const char *); void status_mesg(const char *, const char *);
int status_ask_choice (const char *, const char[], int); int status_ask_choice(const char *, const char[], int);
int status_ask_bool (const char *); int status_ask_bool(const char *);
int status_ask_simplechoice (const char *, const char *[], int); int status_ask_simplechoice(const char *, const char *[], int);
void erase_window_part (WINDOW *, int, int, int, int); void erase_window_part(WINDOW *, int, int, int, int);
WINDOW *popup (int, int, int, int, const char *, const char *, int); WINDOW *popup(int, int, int, int, const char *, const char *, int);
void print_in_middle (WINDOW *, int, int, int, const char *); void print_in_middle(WINDOW *, int, int, int, const char *);
int is_all_digit (const char *); int is_all_digit(const char *);
long get_item_time (long); long get_item_time(long);
int get_item_hour (long); int get_item_hour(long);
int get_item_min (long); int get_item_min(long);
long date2sec (struct date, unsigned, unsigned); long date2sec(struct date, unsigned, unsigned);
char *date_sec2date_str (long, const char *); char *date_sec2date_str(long, const char *);
void date_sec2date_fmt (long, const char *, char *); void date_sec2date_fmt(long, const char *, char *);
long date_sec_change (long, int, int); long date_sec_change(long, int, int);
long update_time_in_date (long, unsigned, unsigned); long update_time_in_date(long, unsigned, unsigned);
long get_sec_date (struct date); long get_sec_date(struct date);
long min2sec (unsigned); long min2sec(unsigned);
void draw_scrollbar (WINDOW *, int, int, int, int, int, unsigned); void draw_scrollbar(WINDOW *, int, int, int, int, int, unsigned);
void item_in_popup (const char *, const char *, const char *, void item_in_popup(const char *, const char *, const char *, const char *);
const char *); long get_today(void);
long get_today (void); long now(void);
long now (void); char *nowstr(void);
char *nowstr (void); long mystrtol(const char *);
long mystrtol (const char *); void print_bool_option_incolor(WINDOW *, unsigned, int, int);
void print_bool_option_incolor (WINDOW *, unsigned, int, int); const char *get_tempdir(void);
const char *get_tempdir (void); char *new_tempfile(const char *, int);
char *new_tempfile (const char *, int); int parse_date(const char *, enum datefmt, int *, int *, int *, struct date *);
int parse_date (const char *, enum datefmt, int *, int *, int *, int parse_time(const char *, unsigned *, unsigned *);
struct date *); int parse_duration(const char *, unsigned *);
int parse_time (const char *, unsigned *, unsigned *); void str_toupper(char *);
int parse_duration (const char *, unsigned *); void file_close(FILE *, const char *);
void str_toupper (char *); void psleep(unsigned);
void file_close (FILE *, const char *); int fork_exec(int *, int *, const char *, const char *const *);
void psleep (unsigned); int shell_exec(int *, int *, const char *, const char *const *);
int fork_exec (int *, int *, const char *, const char *const *); int child_wait(int *, int *, int);
int shell_exec (int *, int *, const char *, const char *const *); void press_any_key(void);
int child_wait (int *, int *, int); void print_apoint(const char *, long, struct apoint *);
void press_any_key (void); void print_event(const char *, long, struct event *);
void print_apoint (const char *, long, struct apoint *); void print_recur_apoint(const char *, long, unsigned, struct recur_apoint *);
void print_event (const char *, long, struct event *); void print_recur_event(const char *, long, struct recur_event *);
void print_recur_apoint (const char *, long, unsigned, void print_todo(const char *, struct todo *);
struct recur_apoint *);
void print_recur_event (const char *, long, struct recur_event *);
void print_todo (const char *, struct todo *);
/* vars.c */ /* vars.c */
extern int col, row; extern int col, row;
@ -963,44 +953,44 @@ extern struct conf conf;
extern struct pad apad; extern struct pad apad;
extern struct nbar nbar; extern struct nbar nbar;
extern struct dmon_conf dmon; extern struct dmon_conf dmon;
void vars_init (void); void vars_init(void);
/* wins.c */ /* wins.c */
extern struct window win[NBWINS]; extern struct window win[NBWINS];
int wins_refresh (void); int wins_refresh(void);
int wins_wrefresh (WINDOW *); int wins_wrefresh(WINDOW *);
int wins_doupdate (void); int wins_doupdate(void);
int wins_layout (void); int wins_layout(void);
void wins_set_layout (int); void wins_set_layout(int);
unsigned wins_sbar_width (void); unsigned wins_sbar_width(void);
unsigned wins_sbar_wperc (void); unsigned wins_sbar_wperc(void);
void wins_set_sbar_width (unsigned); void wins_set_sbar_width(unsigned);
void wins_sbar_winc (void); void wins_sbar_winc(void);
void wins_sbar_wdec (void); void wins_sbar_wdec(void);
void wins_slctd_init (void); void wins_slctd_init(void);
enum win wins_slctd (void); enum win wins_slctd(void);
void wins_slctd_set (enum win); void wins_slctd_set(enum win);
void wins_slctd_next (void); void wins_slctd_next(void);
void wins_init (void); void wins_init(void);
void wins_scrollwin_init (struct scrollwin *); void wins_scrollwin_init(struct scrollwin *);
void wins_scrollwin_delete (struct scrollwin *); void wins_scrollwin_delete(struct scrollwin *);
void wins_scrollwin_display (struct scrollwin *); void wins_scrollwin_display(struct scrollwin *);
void wins_scrollwin_up (struct scrollwin *, int); void wins_scrollwin_up(struct scrollwin *, int);
void wins_scrollwin_down (struct scrollwin *, int); void wins_scrollwin_down(struct scrollwin *, int);
void wins_reinit (void); void wins_reinit(void);
void wins_reinit_panels (void); void wins_reinit_panels(void);
void wins_show (WINDOW *, const char *); void wins_show(WINDOW *, const char *);
void wins_get_config (void); void wins_get_config(void);
void wins_update_border (int); void wins_update_border(int);
void wins_update_panels (int); void wins_update_panels(int);
void wins_update (int); void wins_update(int);
void wins_reset (void); void wins_reset(void);
void wins_prepare_external (void); void wins_prepare_external(void);
void wins_unprepare_external (void); void wins_unprepare_external(void);
void wins_launch_external (const char *, const char *); void wins_launch_external(const char *, const char *);
void wins_status_bar (void); void wins_status_bar(void);
void wins_erase_status_bar (void); void wins_erase_status_bar(void);
void wins_other_status_page (int); void wins_other_status_page(int);
void wins_reset_status_page (void); void wins_reset_status_page(void);
#endif /* CALCURSE_H */ #endif /* CALCURSE_H */

View File

@ -77,103 +77,91 @@ static unsigned calendar_view, week_begins_on_monday;
static pthread_mutex_t date_thread_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t date_thread_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_t calendar_t_date; static pthread_t calendar_t_date;
static void draw_monthly_view (struct window *, struct date *, unsigned); static void draw_monthly_view(struct window *, struct date *, unsigned);
static void draw_weekly_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 *, static void (*draw_calendar[CAL_VIEWS]) (struct window *, struct date *,
unsigned) = unsigned) = {
{draw_monthly_view, draw_weekly_view}; draw_monthly_view, draw_weekly_view};
/* Switch between calendar views (monthly view is selected by default). */ /* Switch between calendar views (monthly view is selected by default). */
void void calendar_view_next(void)
calendar_view_next (void)
{ {
calendar_view++; calendar_view++;
if (calendar_view == CAL_VIEWS) if (calendar_view == CAL_VIEWS)
calendar_view = 0; calendar_view = 0;
} }
void void calendar_view_prev(void)
calendar_view_prev (void)
{ {
if (calendar_view == 0) if (calendar_view == 0)
calendar_view = CAL_VIEWS; calendar_view = CAL_VIEWS;
calendar_view--; calendar_view--;
} }
void void calendar_set_view(int view)
calendar_set_view (int view)
{ {
calendar_view = (view < 0 || view >= CAL_VIEWS) ? CAL_MONTH_VIEW : view; calendar_view = (view < 0 || view >= CAL_VIEWS) ? CAL_MONTH_VIEW : view;
} }
int int calendar_get_view(void)
calendar_get_view (void)
{ {
return (int)calendar_view; return (int)calendar_view;
} }
/* Thread needed to update current date in calendar. */ /* Thread needed to update current date in calendar. */
/* ARGSUSED0 */ /* ARGSUSED0 */
static void * static void *calendar_date_thread(void *arg)
calendar_date_thread (void *arg)
{ {
time_t actual, tomorrow; time_t actual, tomorrow;
for (;;) for (;;) {
{ tomorrow = (time_t) (get_today() + DAYINSEC);
tomorrow = (time_t) (get_today () + DAYINSEC);
while ((actual = time (NULL)) < tomorrow) while ((actual = time(NULL)) < tomorrow)
sleep (tomorrow - actual); sleep(tomorrow - actual);
calendar_set_current_date (); calendar_set_current_date();
calendar_update_panel (&win[CAL]); calendar_update_panel(&win[CAL]);
} }
return NULL; return NULL;
} }
/* Launch the calendar date thread. */ /* Launch the calendar date thread. */
void void calendar_start_date_thread(void)
calendar_start_date_thread (void)
{ {
pthread_create (&calendar_t_date, NULL, calendar_date_thread, NULL); pthread_create(&calendar_t_date, NULL, calendar_date_thread, NULL);
} }
/* Stop the calendar date thread. */ /* Stop the calendar date thread. */
void void calendar_stop_date_thread(void)
calendar_stop_date_thread (void)
{ {
if (calendar_t_date) if (calendar_t_date) {
{ pthread_cancel(calendar_t_date);
pthread_cancel (calendar_t_date); pthread_join(calendar_t_date, NULL);
pthread_join (calendar_t_date, NULL);
} }
} }
/* Set static variable today to current date */ /* Set static variable today to current date */
void void calendar_set_current_date(void)
calendar_set_current_date (void)
{ {
time_t timer; time_t timer;
struct tm *tm; struct tm *tm;
timer = time (NULL); timer = time(NULL);
tm = localtime (&timer); tm = localtime(&timer);
pthread_mutex_lock (&date_thread_mutex); pthread_mutex_lock(&date_thread_mutex);
today.dd = tm->tm_mday; today.dd = tm->tm_mday;
today.mm = tm->tm_mon + 1; today.mm = tm->tm_mon + 1;
today.yyyy = tm->tm_year + 1900; today.yyyy = tm->tm_year + 1900;
pthread_mutex_unlock (&date_thread_mutex); pthread_mutex_unlock(&date_thread_mutex);
} }
/* Needed to display sunday or monday as the first day of week in calendar. */ /* Needed to display sunday or monday as the first day of week in calendar. */
void void calendar_set_first_day_of_week(enum wday first_day)
calendar_set_first_day_of_week (enum wday first_day)
{ {
switch (first_day) switch (first_day) {
{
case SUNDAY: case SUNDAY:
week_begins_on_monday = 0; week_begins_on_monday = 0;
break; break;
@ -181,94 +169,83 @@ calendar_set_first_day_of_week (enum wday first_day)
week_begins_on_monday = 1; week_begins_on_monday = 1;
break; break;
default: default:
ERROR_MSG (_("ERROR setting first day of week")); ERROR_MSG(_("ERROR setting first day of week"));
week_begins_on_monday = 0; week_begins_on_monday = 0;
/* NOTREACHED */ /* NOTREACHED */
} }
} }
/* Swap first day of week in calendar. */ /* Swap first day of week in calendar. */
void void calendar_change_first_day_of_week(void)
calendar_change_first_day_of_week (void)
{ {
week_begins_on_monday = !week_begins_on_monday; week_begins_on_monday = !week_begins_on_monday;
} }
/* Return 1 if week begins on monday, 0 otherwise. */ /* Return 1 if week begins on monday, 0 otherwise. */
unsigned unsigned calendar_week_begins_on_monday(void)
calendar_week_begins_on_monday (void)
{ {
return week_begins_on_monday; return week_begins_on_monday;
} }
/* Fill in the given variable with the current date. */ /* Fill in the given variable with the current date. */
void void calendar_store_current_date(struct date *date)
calendar_store_current_date (struct date *date)
{ {
pthread_mutex_lock (&date_thread_mutex); pthread_mutex_lock(&date_thread_mutex);
*date = today; *date = today;
pthread_mutex_unlock (&date_thread_mutex); pthread_mutex_unlock(&date_thread_mutex);
} }
/* This is to start at the current date in calendar. */ /* This is to start at the current date in calendar. */
void void calendar_init_slctd_day(void)
calendar_init_slctd_day (void)
{ {
calendar_store_current_date (&slctd_day); calendar_store_current_date(&slctd_day);
} }
/* Return the selected day in calendar */ /* Return the selected day in calendar */
struct date * struct date *calendar_get_slctd_day(void)
calendar_get_slctd_day (void)
{ {
return &slctd_day; return &slctd_day;
} }
/* Returned value represents the selected day in calendar (in seconds) */ /* Returned value represents the selected day in calendar (in seconds) */
long long calendar_get_slctd_day_sec(void)
calendar_get_slctd_day_sec (void)
{ {
return date2sec (slctd_day, 0, 0); return date2sec(slctd_day, 0, 0);
} }
static int static int calendar_get_wday(struct date *date)
calendar_get_wday (struct date *date)
{ {
struct tm t; struct tm t;
memset (&t, 0, sizeof (struct tm)); memset(&t, 0, sizeof(struct tm));
t.tm_mday = date->dd; t.tm_mday = date->dd;
t.tm_mon = date->mm - 1; t.tm_mon = date->mm - 1;
t.tm_year = date->yyyy - 1900; t.tm_year = date->yyyy - 1900;
mktime (&t); mktime(&t);
return t.tm_wday; return t.tm_wday;
} }
static unsigned static unsigned months_to_days(unsigned month)
months_to_days (unsigned month)
{ {
return (month * 3057 - 3007) / 100; return (month * 3057 - 3007) / 100;
} }
static long years_to_days(unsigned year)
static long
years_to_days (unsigned year)
{ {
return year * 365L + year / 4 - year / 100 + year / 400; return year * 365L + year / 4 - year / 100 + year / 400;
} }
static long static long ymd_to_scalar(unsigned year, unsigned month, unsigned day)
ymd_to_scalar (unsigned year, unsigned month, unsigned day)
{ {
long scalar; long scalar;
scalar = day + months_to_days (month); scalar = day + months_to_days(month);
if (month > 2) if (month > 2)
scalar -= ISLEAP (year) ? 1 : 2; scalar -= ISLEAP(year) ? 1 : 2;
year--; year--;
scalar += years_to_days (year); scalar += years_to_days(year);
return scalar; return scalar;
} }
@ -277,8 +254,7 @@ ymd_to_scalar (unsigned year, unsigned month, unsigned day)
* Used to change date by adding a certain amount of days or weeks. * Used to change date by adding a certain amount of days or weeks.
* Returns 0 on success, 1 otherwise. * Returns 0 on success, 1 otherwise.
*/ */
static int static int date_change(struct tm *date, int delta_month, int delta_day)
date_change (struct tm *date, int delta_month, int delta_day)
{ {
struct tm t; struct tm t;
@ -286,10 +262,9 @@ date_change (struct tm *date, int delta_month, int delta_day)
t.tm_mon += delta_month; t.tm_mon += delta_month;
t.tm_mday += delta_day; t.tm_mday += delta_day;
if (mktime (&t) == -1) if (mktime(&t) == -1)
return 1; return 1;
else else {
{
*date = t; *date = t;
return 0; return 0;
} }
@ -297,7 +272,7 @@ date_change (struct tm *date, int delta_month, int delta_day)
/* Draw the monthly view inside calendar panel. */ /* Draw the monthly view inside calendar panel. */
static void static void
draw_monthly_view (struct window *cwin, struct date *current_day, draw_monthly_view(struct window *cwin, struct date *current_day,
unsigned sunday_first) unsigned sunday_first)
{ {
const int OFFY = 2 + (CALHEIGHT - 9) / 2; const int OFFY = 2 + (CALHEIGHT - 9) / 2;
@ -311,53 +286,50 @@ draw_monthly_view (struct window *cwin, struct date *current_day,
yr = slctd_day.yyyy; yr = slctd_day.yyyy;
/* offset for centering calendar in window */ /* offset for centering calendar in window */
SBAR_WIDTH = wins_sbar_width (); SBAR_WIDTH = wins_sbar_width();
OFFX = (SBAR_WIDTH - 27) / 2; OFFX = (SBAR_WIDTH - 27) / 2;
ofs_y = OFFY; ofs_y = OFFY;
ofs_x = OFFX; ofs_x = OFFX;
/* checking the number of days in february */ /* checking the number of days in february */
numdays = days[mo - 1]; numdays = days[mo - 1];
if (2 == mo && ISLEAP (yr)) if (2 == mo && ISLEAP(yr))
++numdays; ++numdays;
/* /*
* the first calendar day will be monday or sunday, depending on * the first calendar day will be monday or sunday, depending on
* 'week_begins_on_monday' value * 'week_begins_on_monday' value
*/ */
c_day_1 = (int) ((ymd_to_scalar (yr, mo, 1 + sunday_first) - (long) 1) % 7L); c_day_1 = (int)((ymd_to_scalar(yr, mo, 1 + sunday_first) - (long)1) % 7L);
/* Write the current month and year on top of the calendar */ /* Write the current month and year on top of the calendar */
custom_apply_attr (cwin->p, ATTR_HIGHEST); custom_apply_attr(cwin->p, ATTR_HIGHEST);
mvwprintw (cwin->p, ofs_y, mvwprintw(cwin->p, ofs_y,
(SBAR_WIDTH - (strlen (_(monthnames[mo - 1])) + 5)) / 2, (SBAR_WIDTH - (strlen(_(monthnames[mo - 1])) + 5)) / 2,
"%s %d", _(monthnames[mo - 1]), slctd_day.yyyy); "%s %d", _(monthnames[mo - 1]), slctd_day.yyyy);
custom_remove_attr (cwin->p, ATTR_HIGHEST); custom_remove_attr(cwin->p, ATTR_HIGHEST);
++ofs_y; ++ofs_y;
/* print the days, with regards to the first day of the week */ /* print the days, with regards to the first day of the week */
custom_apply_attr (cwin->p, ATTR_HIGHEST); custom_apply_attr(cwin->p, ATTR_HIGHEST);
for (j = 0; j < WEEKINDAYS; j++) for (j = 0; j < WEEKINDAYS; j++) {
{ mvwprintw(cwin->p, ofs_y, ofs_x + 4 * j, "%s",
mvwprintw (cwin->p, ofs_y, ofs_x + 4 * j, "%s",
_(daynames[1 + j - sunday_first])); _(daynames[1 + j - sunday_first]));
} }
custom_remove_attr (cwin->p, ATTR_HIGHEST); custom_remove_attr(cwin->p, ATTR_HIGHEST);
day_1_sav = (c_day_1 + 1) * 3 + c_day_1 - 7; day_1_sav = (c_day_1 + 1) * 3 + c_day_1 - 7;
for (c_day = 1; c_day <= numdays; ++c_day, ++c_day_1, c_day_1 %= 7) for (c_day = 1; c_day <= numdays; ++c_day, ++c_day_1, c_day_1 %= 7) {
{
check_day.dd = c_day; check_day.dd = c_day;
check_day.mm = slctd_day.mm; check_day.mm = slctd_day.mm;
check_day.yyyy = slctd_day.yyyy; check_day.yyyy = slctd_day.yyyy;
/* check if the day contains an event or an appointment */ /* check if the day contains an event or an appointment */
item_this_day = day_check_if_item (check_day); item_this_day = day_check_if_item(check_day);
/* Go to next line, the week is over. */ /* Go to next line, the week is over. */
if (!c_day_1 && 1 != c_day) if (!c_day_1 && 1 != c_day) {
{
ofs_y++; ofs_y++;
ofs_x = OFFX - day_1_sav - 4 * c_day; ofs_x = OFFX - day_1_sav - 4 * c_day;
} }
@ -366,46 +338,35 @@ draw_monthly_view (struct window *cwin, struct date *current_day,
if (c_day == current_day->dd if (c_day == current_day->dd
&& current_day->mm == slctd_day.mm && current_day->mm == slctd_day.mm
&& current_day->yyyy == slctd_day.yyyy && current_day->yyyy == slctd_day.yyyy
&& current_day->dd != slctd_day.dd) && current_day->dd != slctd_day.dd) {
{ custom_apply_attr(cwin->p, ATTR_LOWEST);
custom_apply_attr (cwin->p, ATTR_LOWEST); mvwprintw(cwin->p, ofs_y + 1,
mvwprintw (cwin->p, ofs_y + 1,
ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day); ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day);
custom_remove_attr (cwin->p, ATTR_LOWEST); custom_remove_attr(cwin->p, ATTR_LOWEST);
} } else if (c_day == slctd_day.dd) {
else if (c_day == slctd_day.dd)
{
/* This is the selected day, print it according to user's theme. */ /* This is the selected day, print it according to user's theme. */
custom_apply_attr (cwin->p, ATTR_HIGHEST); custom_apply_attr(cwin->p, ATTR_HIGHEST);
mvwprintw (cwin->p, ofs_y + 1, mvwprintw(cwin->p, ofs_y + 1,
ofs_x + day_1_sav + 4 * c_day + 1, "%2d", ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day);
c_day); custom_remove_attr(cwin->p, ATTR_HIGHEST);
custom_remove_attr (cwin->p, ATTR_HIGHEST); } else if (item_this_day) {
} custom_apply_attr(cwin->p, ATTR_LOW);
else if (item_this_day) mvwprintw(cwin->p, ofs_y + 1,
{ ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day);
custom_apply_attr (cwin->p, ATTR_LOW); custom_remove_attr(cwin->p, ATTR_LOW);
mvwprintw (cwin->p, ofs_y + 1, } else
ofs_x + day_1_sav + 4 * c_day + 1, "%2d",
c_day);
custom_remove_attr (cwin->p, ATTR_LOW);
}
else
/* otherwise, print normal days in black */ /* otherwise, print normal days in black */
mvwprintw (cwin->p, ofs_y + 1, mvwprintw(cwin->p, ofs_y + 1,
ofs_x + day_1_sav + 4 * c_day + 1, "%2d", ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day);
c_day);
} }
} }
static int static int weeknum(const struct tm *t, int firstweekday)
weeknum (const struct tm *t, int firstweekday)
{ {
int wday, wnum; int wday, wnum;
wday = t->tm_wday; wday = t->tm_wday;
if (firstweekday == MONDAY) if (firstweekday == MONDAY) {
{
if (wday == SUNDAY) if (wday == SUNDAY)
wday = 6; wday = 6;
else else
@ -421,19 +382,17 @@ weeknum (const struct tm *t, int firstweekday)
/* /*
* Compute the week number according to ISO 8601. * Compute the week number according to ISO 8601.
*/ */
static int static int ISO8601weeknum(const struct tm *t)
ISO8601weeknum (const struct tm *t)
{ {
int wnum, jan1day; int wnum, jan1day;
wnum = weeknum (t, MONDAY); wnum = weeknum(t, MONDAY);
jan1day = t->tm_wday - (t->tm_yday % WEEKINDAYS); jan1day = t->tm_wday - (t->tm_yday % WEEKINDAYS);
if (jan1day < 0) if (jan1day < 0)
jan1day += WEEKINDAYS; jan1day += WEEKINDAYS;
switch (jan1day) switch (jan1day) {
{
case MONDAY: case MONDAY:
break; break;
case TUESDAY: case TUESDAY:
@ -444,8 +403,7 @@ ISO8601weeknum (const struct tm *t)
case FRIDAY: case FRIDAY:
case SATURDAY: case SATURDAY:
case SUNDAY: case SUNDAY:
if (wnum == 0) if (wnum == 0) {
{
/* Get week number of last week of last year. */ /* Get week number of last week of last year. */
struct tm dec31ly; /* 12/31 last year */ struct tm dec31ly; /* 12/31 last year */
@ -454,14 +412,13 @@ ISO8601weeknum (const struct tm *t)
dec31ly.tm_mon = 11; dec31ly.tm_mon = 11;
dec31ly.tm_mday = 31; dec31ly.tm_mday = 31;
dec31ly.tm_wday = (jan1day == SUNDAY) ? 6 : jan1day - 1; dec31ly.tm_wday = (jan1day == SUNDAY) ? 6 : jan1day - 1;
dec31ly.tm_yday = 364 + ISLEAP (dec31ly.tm_year + 1900); dec31ly.tm_yday = 364 + ISLEAP(dec31ly.tm_year + 1900);
wnum = ISO8601weeknum (&dec31ly); wnum = ISO8601weeknum(&dec31ly);
} }
break; break;
} }
if (t->tm_mon == 11) if (t->tm_mon == 11) {
{
int wday, mday; int wday, mday;
wday = t->tm_wday; wday = t->tm_wday;
@ -477,7 +434,7 @@ ISO8601weeknum (const struct tm *t)
/* Draw the weekly view inside calendar panel. */ /* Draw the weekly view inside calendar panel. */
static void static void
draw_weekly_view (struct window *cwin, struct date *current_day, draw_weekly_view(struct window *cwin, struct date *current_day,
unsigned sunday_first) unsigned sunday_first)
{ {
#define DAYSLICESNO 6 #define DAYSLICESNO 6
@ -486,46 +443,45 @@ draw_weekly_view (struct window *cwin, struct date *current_day,
struct tm t; struct tm t;
int OFFX, j, c_wday, days_to_remove, weeknum; int OFFX, j, c_wday, days_to_remove, weeknum;
OFFX = (wins_sbar_width () - WCALWIDTH) / 2 + 1; OFFX = (wins_sbar_width() - WCALWIDTH) / 2 + 1;
/* Fill in a tm structure with the first day of the selected week. */ /* Fill in a tm structure with the first day of the selected week. */
c_wday = calendar_get_wday (&slctd_day); c_wday = calendar_get_wday(&slctd_day);
if (sunday_first) if (sunday_first)
days_to_remove = c_wday; days_to_remove = c_wday;
else else
days_to_remove = c_wday == 0 ? WEEKINDAYS - 1 : c_wday - 1; days_to_remove = c_wday == 0 ? WEEKINDAYS - 1 : c_wday - 1;
memset (&t, 0, sizeof (struct tm)); memset(&t, 0, sizeof(struct tm));
t.tm_mday = slctd_day.dd; t.tm_mday = slctd_day.dd;
t.tm_mon = slctd_day.mm - 1; t.tm_mon = slctd_day.mm - 1;
t.tm_year = slctd_day.yyyy - 1900; t.tm_year = slctd_day.yyyy - 1900;
mktime (&t); mktime(&t);
date_change (&t, 0, -days_to_remove); date_change(&t, 0, -days_to_remove);
/* Print the week number. */ /* Print the week number. */
weeknum = ISO8601weeknum (&t); weeknum = ISO8601weeknum(&t);
custom_apply_attr (cwin->p, ATTR_HIGHEST); custom_apply_attr(cwin->p, ATTR_HIGHEST);
mvwprintw (cwin->p, 2, cwin->w - 9, "(# %02d)", weeknum); mvwprintw(cwin->p, 2, cwin->w - 9, "(# %02d)", weeknum);
custom_remove_attr (cwin->p, ATTR_HIGHEST); custom_remove_attr(cwin->p, ATTR_HIGHEST);
/* Now draw calendar view. */ /* Now draw calendar view. */
for (j = 0; j < WEEKINDAYS; j++) for (j = 0; j < WEEKINDAYS; j++) {
{
struct date date; struct date date;
unsigned attr, item_this_day; unsigned attr, item_this_day;
int i, slices[DAYSLICESNO]; int i, slices[DAYSLICESNO];
/* print the day names, with regards to the first day of the week */ /* print the day names, with regards to the first day of the week */
custom_apply_attr (cwin->p, ATTR_HIGHEST); custom_apply_attr(cwin->p, ATTR_HIGHEST);
mvwprintw (cwin->p, OFFY, OFFX + 4 * j, "%s", mvwprintw(cwin->p, OFFY, OFFX + 4 * j, "%s",
_(daynames[1 + j - sunday_first])); _(daynames[1 + j - sunday_first]));
custom_remove_attr (cwin->p, ATTR_HIGHEST); custom_remove_attr(cwin->p, ATTR_HIGHEST);
/* Check if the day to be printed has an item or not. */ /* Check if the day to be printed has an item or not. */
date.dd = t.tm_mday; date.dd = t.tm_mday;
date.mm = t.tm_mon + 1; date.mm = t.tm_mon + 1;
date.yyyy = t.tm_year + 1900; date.yyyy = t.tm_year + 1900;
item_this_day = day_check_if_item (date); item_this_day = day_check_if_item(date);
/* Print the day numbers with appropriate decoration. */ /* Print the day numbers with appropriate decoration. */
if (t.tm_mday == current_day->dd if (t.tm_mday == current_day->dd
@ -541,74 +497,69 @@ draw_weekly_view (struct window *cwin, struct date *current_day,
attr = 0; attr = 0;
if (attr) if (attr)
custom_apply_attr (cwin->p, attr); custom_apply_attr(cwin->p, attr);
mvwprintw (cwin->p, OFFY + 1, OFFX + 1 + 4 * j, "%02d", t.tm_mday); mvwprintw(cwin->p, OFFY + 1, OFFX + 1 + 4 * j, "%02d", t.tm_mday);
if (attr) if (attr)
custom_remove_attr (cwin->p, attr); custom_remove_attr(cwin->p, attr);
/* Draw slices indicating appointment times. */ /* Draw slices indicating appointment times. */
memset (slices, 0, DAYSLICESNO * sizeof *slices); memset(slices, 0, DAYSLICESNO * sizeof *slices);
if (day_chk_busy_slices (date, DAYSLICESNO, slices)) if (day_chk_busy_slices(date, DAYSLICESNO, slices)) {
{ for (i = 0; i < DAYSLICESNO; i++) {
for (i = 0; i < DAYSLICESNO; i++)
{
if (j != WEEKINDAYS - 1 && i != DAYSLICESNO - 1) if (j != WEEKINDAYS - 1 && i != DAYSLICESNO - 1)
mvwhline (cwin->p, OFFY + 2 + i, OFFX + 3 + 4 * j, ACS_S9, 2); mvwhline(cwin->p, OFFY + 2 + i, OFFX + 3 + 4 * j, ACS_S9, 2);
if (slices[i]) if (slices[i]) {
{
int highlight; int highlight;
highlight = (t.tm_mday == slctd_day.dd) ? 1 : 0; highlight = (t.tm_mday == slctd_day.dd) ? 1 : 0;
if (highlight) if (highlight)
custom_apply_attr (cwin->p, attr); custom_apply_attr(cwin->p, attr);
wattron (cwin->p, A_REVERSE); wattron(cwin->p, A_REVERSE);
mvwprintw (cwin->p, OFFY + 2 + i, OFFX + 1 + 4 * j, " "); mvwprintw(cwin->p, OFFY + 2 + i, OFFX + 1 + 4 * j, " ");
mvwprintw (cwin->p, OFFY + 2 + i, OFFX + 2 + 4 * j, " "); mvwprintw(cwin->p, OFFY + 2 + i, OFFX + 2 + 4 * j, " ");
wattroff (cwin->p, A_REVERSE); wattroff(cwin->p, A_REVERSE);
if (highlight) if (highlight)
custom_remove_attr (cwin->p, attr); custom_remove_attr(cwin->p, attr);
} }
} }
} }
/* get next day */ /* get next day */
date_change (&t, 0, 1); date_change(&t, 0, 1);
} }
/* Draw marks to indicate midday on the sides of the calendar. */ /* Draw marks to indicate midday on the sides of the calendar. */
custom_apply_attr (cwin->p, ATTR_HIGHEST); custom_apply_attr(cwin->p, ATTR_HIGHEST);
mvwhline (cwin->p, OFFY + 1 + DAYSLICESNO / 2, OFFX, ACS_S9, 1); mvwhline(cwin->p, OFFY + 1 + DAYSLICESNO / 2, OFFX, ACS_S9, 1);
mvwhline (cwin->p, OFFY + 1 + DAYSLICESNO / 2, mvwhline(cwin->p, OFFY + 1 + DAYSLICESNO / 2,
OFFX + WCALWIDTH - 3, ACS_S9, 1); OFFX + WCALWIDTH - 3, ACS_S9, 1);
custom_remove_attr (cwin->p, ATTR_HIGHEST); custom_remove_attr(cwin->p, ATTR_HIGHEST);
#undef DAYSLICESNO #undef DAYSLICESNO
} }
/* Function used to display the calendar panel. */ /* Function used to display the calendar panel. */
void void calendar_update_panel(struct window *cwin)
calendar_update_panel (struct window *cwin)
{ {
struct date current_day; struct date current_day;
unsigned sunday_first; unsigned sunday_first;
calendar_store_current_date (&current_day); calendar_store_current_date(&current_day);
erase_window_part (cwin->p, 1, 3, cwin->w - 2, cwin->h - 2); erase_window_part(cwin->p, 1, 3, cwin->w - 2, cwin->h - 2);
mvwhline (cwin->p, 2, 1, ACS_HLINE, cwin->w - 2); mvwhline(cwin->p, 2, 1, ACS_HLINE, cwin->w - 2);
sunday_first = calendar_week_begins_on_monday () ? 0 : 1; sunday_first = calendar_week_begins_on_monday()? 0 : 1;
draw_calendar[calendar_view] (cwin, &current_day, sunday_first); draw_calendar[calendar_view] (cwin, &current_day, sunday_first);
wnoutrefresh (cwin->p); wnoutrefresh(cwin->p);
} }
/* Set the selected day in calendar to current day. */ /* Set the selected day in calendar to current day. */
void void calendar_goto_today(void)
calendar_goto_today (void)
{ {
struct date today; struct date today;
calendar_store_current_date (&today); calendar_store_current_date(&today);
slctd_day.dd = today.dd; slctd_day.dd = today.dd;
slctd_day.mm = today.mm; slctd_day.mm = today.mm;
slctd_day.yyyy = today.yyyy; slctd_day.yyyy = today.yyyy;
@ -620,8 +571,7 @@ calendar_goto_today (void)
* If the entered date is empty, automatically jump to the current date. * If the entered date is empty, automatically jump to the current date.
* slctd_day is updated with the newly selected date. * slctd_day is updated with the newly selected date.
*/ */
void void calendar_change_day(int datefmt)
calendar_change_day (int datefmt)
{ {
#define LDAY 11 #define LDAY 11
char selected_day[LDAY] = ""; char selected_day[LDAY] = "";
@ -634,32 +584,26 @@ calendar_change_day (int datefmt)
const char *mesg_line2 = _("Press [ENTER] to continue"); const char *mesg_line2 = _("Press [ENTER] to continue");
const char *request_date = "Enter the day to go to [ENTER for today] : %s"; const char *request_date = "Enter the day to go to [ENTER for today] : %s";
while (wrong_day) while (wrong_day) {
{ snprintf(outstr, BUFSIZ, request_date, DATEFMT_DESC(datefmt));
snprintf (outstr, BUFSIZ, request_date, DATEFMT_DESC (datefmt)); status_mesg(_(outstr), "");
status_mesg (_(outstr), ""); if (getstring(win[STA].p, selected_day, LDAY, 0, 1) == GETSTRING_ESC)
if (getstring (win[STA].p, selected_day, LDAY, 0, 1) == GETSTRING_ESC)
return; return;
else else {
{ if (strlen(selected_day) == 0) {
if (strlen (selected_day) == 0)
{
wrong_day = 0; wrong_day = 0;
calendar_goto_today (); calendar_goto_today();
} } else if (parse_date(selected_day, datefmt, &dyear, &dmonth, &dday,
else if (parse_date (selected_day, datefmt, &dyear, &dmonth, &dday, calendar_get_slctd_day())) {
calendar_get_slctd_day ()))
{
wrong_day = 0; wrong_day = 0;
/* go to chosen day */ /* go to chosen day */
slctd_day.dd = dday; slctd_day.dd = dday;
slctd_day.mm = dmonth; slctd_day.mm = dmonth;
slctd_day.yyyy = dyear; slctd_day.yyyy = dyear;
} }
if (wrong_day) if (wrong_day) {
{ status_mesg(mesg_line1, mesg_line2);
status_mesg (mesg_line1, mesg_line2); wgetch(win[STA].p);
wgetch (win[STA].p);
} }
} }
} }
@ -667,66 +611,60 @@ calendar_change_day (int datefmt)
return; return;
} }
void void calendar_move(enum move move, int count)
calendar_move (enum move move, int count)
{ {
int ret, days_to_remove, days_to_add; int ret, days_to_remove, days_to_add;
struct tm t; struct tm t;
memset (&t, 0, sizeof (struct tm)); memset(&t, 0, sizeof(struct tm));
t.tm_mday = slctd_day.dd; t.tm_mday = slctd_day.dd;
t.tm_mon = slctd_day.mm - 1; t.tm_mon = slctd_day.mm - 1;
t.tm_year = slctd_day.yyyy - 1900; t.tm_year = slctd_day.yyyy - 1900;
switch (move) switch (move) {
{
case UP: case UP:
ret = date_change (&t, 0, -count * WEEKINDAYS); ret = date_change(&t, 0, -count * WEEKINDAYS);
break; break;
case DOWN: case DOWN:
ret = date_change (&t, 0, count * WEEKINDAYS); ret = date_change(&t, 0, count * WEEKINDAYS);
break; break;
case LEFT: case LEFT:
ret = date_change (&t, 0, -count); ret = date_change(&t, 0, -count);
break; break;
case RIGHT: case RIGHT:
ret = date_change (&t, 0, count); ret = date_change(&t, 0, count);
break; break;
case WEEK_START: case WEEK_START:
/* Normalize struct tm to get week day number. */ /* Normalize struct tm to get week day number. */
mktime (&t); mktime(&t);
if (calendar_week_begins_on_monday ()) if (calendar_week_begins_on_monday())
days_to_remove = ((t.tm_wday == 0) ? WEEKINDAYS - 1 : t.tm_wday - 1); days_to_remove = ((t.tm_wday == 0) ? WEEKINDAYS - 1 : t.tm_wday - 1);
else else
days_to_remove = ((t.tm_wday == 0) ? 0 : t.tm_wday); days_to_remove = ((t.tm_wday == 0) ? 0 : t.tm_wday);
days_to_remove += (count - 1) * WEEKINDAYS; days_to_remove += (count - 1) * WEEKINDAYS;
ret = date_change (&t, 0, -days_to_remove); ret = date_change(&t, 0, -days_to_remove);
break; break;
case WEEK_END: case WEEK_END:
mktime (&t); mktime(&t);
if (calendar_week_begins_on_monday ()) if (calendar_week_begins_on_monday())
days_to_add = ((t.tm_wday == 0) ? 0 : WEEKINDAYS - t.tm_wday); days_to_add = ((t.tm_wday == 0) ? 0 : WEEKINDAYS - t.tm_wday);
else else
days_to_add = ((t.tm_wday == 0) ? days_to_add = ((t.tm_wday == 0) ?
WEEKINDAYS - 1 : WEEKINDAYS - 1 - t.tm_wday); WEEKINDAYS - 1 : WEEKINDAYS - 1 - t.tm_wday);
days_to_add += (count - 1) * WEEKINDAYS; days_to_add += (count - 1) * WEEKINDAYS;
ret = date_change (&t, 0, days_to_add); ret = date_change(&t, 0, days_to_add);
break; break;
default: default:
ret = 1; ret = 1;
/* NOTREACHED */ /* NOTREACHED */
} }
if (ret == 0) if (ret == 0) {
{ if (t.tm_year < 2) {
if (t.tm_year < 2)
{
t.tm_mday = 1; t.tm_mday = 1;
t.tm_mon = 0; t.tm_mon = 0;
t.tm_year = 2; t.tm_year = 2;
} } else if (t.tm_year > 137) {
else if (t.tm_year > 137)
{
t.tm_mday = 31; t.tm_mday = 31;
t.tm_mon = 11; t.tm_mon = 11;
t.tm_year = 137; t.tm_year = 137;
@ -739,39 +677,37 @@ calendar_move (enum move move, int count)
} }
/* Returns the beginning of current year as a long. */ /* Returns the beginning of current year as a long. */
long long calendar_start_of_year(void)
calendar_start_of_year (void)
{ {
time_t timer; time_t timer;
struct tm *tm; struct tm *tm;
timer = time (NULL); timer = time(NULL);
tm = localtime (&timer); tm = localtime(&timer);
tm->tm_mon = 0; tm->tm_mon = 0;
tm->tm_mday = 1; tm->tm_mday = 1;
tm->tm_hour = 0; tm->tm_hour = 0;
tm->tm_min = 0; tm->tm_min = 0;
tm->tm_sec = 0; tm->tm_sec = 0;
timer = mktime (tm); timer = mktime(tm);
return (long)timer; return (long)timer;
} }
long long calendar_end_of_year(void)
calendar_end_of_year (void)
{ {
time_t timer; time_t timer;
struct tm *tm; struct tm *tm;
timer = time (NULL); timer = time(NULL);
tm = localtime (&timer); tm = localtime(&timer);
tm->tm_mon = 0; tm->tm_mon = 0;
tm->tm_mday = 1; tm->tm_mday = 1;
tm->tm_hour = 0; tm->tm_hour = 0;
tm->tm_min = 0; tm->tm_min = 0;
tm->tm_sec = 0; tm->tm_sec = 0;
tm->tm_year++; tm->tm_year++;
timer = mktime (tm); timer = mktime(tm);
return (long)(timer - 1); return (long)(timer - 1);
} }
@ -817,8 +753,7 @@ calendar_end_of_year (void)
* dtor -- * dtor --
* convert degrees to radians * convert degrees to radians
*/ */
static double static double dtor(double deg)
dtor (double deg)
{ {
return deg * M_PI / 180; return deg * M_PI / 180;
} }
@ -827,8 +762,7 @@ dtor (double deg)
* adj360 -- * adj360 --
* adjust value so 0 <= deg <= 360 * adjust value so 0 <= deg <= 360
*/ */
static void static void adj360(double *deg)
adj360 (double *deg)
{ {
for (;;) for (;;)
if (*deg < 0.0) if (*deg < 0.0)
@ -843,36 +777,35 @@ adj360 (double *deg)
* potm -- * potm --
* return phase of the moon * return phase of the moon
*/ */
static double static double potm(double days)
potm (double days)
{ {
double N, Msol, Ec, LambdaSol, l, Mm, Ev, Ac, A3, Mmprime; double N, Msol, Ec, LambdaSol, l, Mm, Ev, Ac, A3, Mmprime;
double A4, lprime, V, ldprime, D, Nm; double A4, lprime, V, ldprime, D, Nm;
N = 360.0 * days / 365.242191; /* sec 46 #3 */ N = 360.0 * days / 365.242191; /* sec 46 #3 */
adj360 (&N); adj360(&N);
Msol = N + EPSILONg - RHOg; /* sec 46 #4 */ Msol = N + EPSILONg - RHOg; /* sec 46 #4 */
adj360 (&Msol); adj360(&Msol);
Ec = 360 / M_PI * ECCEN * sin (dtor (Msol)); /* sec 46 #5 */ Ec = 360 / M_PI * ECCEN * sin(dtor(Msol)); /* sec 46 #5 */
LambdaSol = N + Ec + EPSILONg; /* sec 46 #6 */ LambdaSol = N + Ec + EPSILONg; /* sec 46 #6 */
adj360 (&LambdaSol); adj360(&LambdaSol);
l = 13.1763966 * days + lzero; /* sec 65 #4 */ l = 13.1763966 * days + lzero; /* sec 65 #4 */
adj360 (&l); adj360(&l);
Mm = l - (0.1114041 * days) - Pzero; /* sec 65 #5 */ Mm = l - (0.1114041 * days) - Pzero; /* sec 65 #5 */
adj360 (&Mm); adj360(&Mm);
Nm = Nzero - (0.0529539 * days); /* sec 65 #6 */ Nm = Nzero - (0.0529539 * days); /* sec 65 #6 */
adj360 (&Nm); adj360(&Nm);
Ev = 1.2739 * sin (dtor (2 * (l - LambdaSol) - Mm)); /* sec 65 #7 */ Ev = 1.2739 * sin(dtor(2 * (l - LambdaSol) - Mm)); /* sec 65 #7 */
Ac = 0.1858 * sin (dtor (Msol)); /* sec 65 #8 */ Ac = 0.1858 * sin(dtor(Msol)); /* sec 65 #8 */
A3 = 0.37 * sin (dtor (Msol)); A3 = 0.37 * sin(dtor(Msol));
Mmprime = Mm + Ev - Ac - A3; /* sec 65 #9 */ Mmprime = Mm + Ev - Ac - A3; /* sec 65 #9 */
Ec = 6.2886 * sin (dtor (Mmprime)); /* sec 65 #10 */ Ec = 6.2886 * sin(dtor(Mmprime)); /* sec 65 #10 */
A4 = 0.214 * sin (dtor (2 * Mmprime)); /* sec 65 #11 */ A4 = 0.214 * sin(dtor(2 * Mmprime)); /* sec 65 #11 */
lprime = l + Ev + Ec - Ac + A4; /* sec 65 #12 */ lprime = l + Ev + Ec - Ac + A4; /* sec 65 #12 */
V = 0.6583 * sin (dtor (2 * (lprime - LambdaSol))); /* sec 65 #13 */ V = 0.6583 * sin(dtor(2 * (lprime - LambdaSol))); /* sec 65 #13 */
ldprime = lprime + V; /* sec 65 #14 */ ldprime = lprime + V; /* sec 65 #14 */
D = ldprime - LambdaSol; /* sec 67 #2 */ D = ldprime - LambdaSol; /* sec 67 #2 */
return 50.0 * (1 - cos (dtor (D))); /* sec 67 #3 */ return 50.0 * (1 - cos(dtor(D))); /* sec 67 #3 */
} }
/* /*
@ -886,23 +819,22 @@ potm (double days)
* Updated to the Third Edition of Duffett-Smith's book, IX 1998 * Updated to the Third Edition of Duffett-Smith's book, IX 1998
* *
*/ */
static double static double pom(time_t tmpt)
pom (time_t tmpt)
{ {
struct tm *GMT; struct tm *GMT;
double days; double days;
int cnt; int cnt;
GMT = gmtime (&tmpt); GMT = gmtime(&tmpt);
days = (GMT->tm_yday + 1) + ((GMT->tm_hour + (GMT->tm_min / 60.0) + days = (GMT->tm_yday + 1) + ((GMT->tm_hour + (GMT->tm_min / 60.0) +
(GMT->tm_sec / 3600.0)) / 24.0); (GMT->tm_sec / 3600.0)) / 24.0);
for (cnt = EPOCH; cnt < GMT->tm_year; ++cnt) for (cnt = EPOCH; cnt < GMT->tm_year; ++cnt)
days += ISLEAP (cnt + TM_YEAR_BASE) ? 366 : 365; days += ISLEAP(cnt + TM_YEAR_BASE) ? 366 : 365;
/* Selected time could be before EPOCH */ /* Selected time could be before EPOCH */
for (cnt = GMT->tm_year; cnt < EPOCH; ++cnt) for (cnt = GMT->tm_year; cnt < EPOCH; ++cnt)
days -= ISLEAP (cnt + TM_YEAR_BASE) ? 366 : 365; days -= ISLEAP(cnt + TM_YEAR_BASE) ? 366 : 365;
return potm (days); return potm(days);
} }
/* /*
@ -910,24 +842,23 @@ pom (time_t tmpt)
* Careful: date is the selected day in calendar at 00:00, so it represents * Careful: date is the selected day in calendar at 00:00, so it represents
* the phase of the moon for previous day. * the phase of the moon for previous day.
*/ */
const char * const char *calendar_get_pom(time_t date)
calendar_get_pom (time_t date)
{ {
const char *pom_pict[MOON_PHASES] = { " ", "|) ", "(|)", "(| ", " | " }; const char *pom_pict[MOON_PHASES] = { " ", "|) ", "(|)", "(| ", " | " };
enum pom phase = NO_POM; enum pom phase = NO_POM;
double pom_today, relative_pom, pom_yesterday, pom_tomorrow; double pom_today, relative_pom, pom_yesterday, pom_tomorrow;
const double half = 50.0; const double half = 50.0;
pom_yesterday = pom (date); pom_yesterday = pom(date);
pom_today = pom (date + DAYINSEC); pom_today = pom(date + DAYINSEC);
relative_pom = abs (pom_today - half); relative_pom = abs(pom_today - half);
pom_tomorrow = pom (date + 2 * DAYINSEC); pom_tomorrow = pom(date + 2 * DAYINSEC);
if (pom_today > pom_yesterday && pom_today > pom_tomorrow) if (pom_today > pom_yesterday && pom_today > pom_tomorrow)
phase = FULL_MOON; phase = FULL_MOON;
else if (pom_today < pom_yesterday && pom_today < pom_tomorrow) else if (pom_today < pom_yesterday && pom_today < pom_tomorrow)
phase = NEW_MOON; phase = NEW_MOON;
else if (relative_pom < abs (pom_yesterday - half) else if (relative_pom < abs(pom_yesterday - half)
&& relative_pom < abs (pom_tomorrow - half)) && relative_pom < abs(pom_tomorrow - half))
phase = (pom_tomorrow > pom_today) ? FIRST_QUARTER : LAST_QUARTER; phase = (pom_tomorrow > pom_today) ? FIRST_QUARTER : LAST_QUARTER;
return pom_pict[phase]; return pom_pict[phase];

View File

@ -49,28 +49,28 @@ struct confvar {
void *target; void *target;
}; };
static int config_parse_bool (unsigned *, const char *); static int config_parse_bool(unsigned *, const char *);
static int config_serialize_bool (char *, unsigned *); static int config_serialize_bool(char *, unsigned *);
static int config_parse_int (int *, const char *); static int config_parse_int(int *, const char *);
static int config_serialize_int (char *, int *); static int config_serialize_int(char *, int *);
static int config_parse_unsigned (unsigned *, const char *); static int config_parse_unsigned(unsigned *, const char *);
static int config_serialize_unsigned (char *, unsigned *); static int config_serialize_unsigned(char *, unsigned *);
static int config_parse_str (char *, const char *); static int config_parse_str(char *, const char *);
static int config_serialize_str (char *, const char *); static int config_serialize_str(char *, const char *);
static int config_parse_calendar_view (void *, const char *); static int config_parse_calendar_view(void *, const char *);
static int config_serialize_calendar_view (char *, void *); static int config_serialize_calendar_view(char *, void *);
static int config_parse_first_day_of_week (void *, const char *); static int config_parse_first_day_of_week(void *, const char *);
static int config_serialize_first_day_of_week (char *, void *); static int config_serialize_first_day_of_week(char *, void *);
static int config_parse_color_theme (void *, const char *); static int config_parse_color_theme(void *, const char *);
static int config_serialize_color_theme (char *, void *); static int config_serialize_color_theme(char *, void *);
static int config_parse_layout (void *, const char *); static int config_parse_layout(void *, const char *);
static int config_serialize_layout (char *, void *); static int config_serialize_layout(char *, void *);
static int config_parse_sidebar_width (void *, const char *); static int config_parse_sidebar_width(void *, const char *);
static int config_serialize_sidebar_width (char *, void *); static int config_serialize_sidebar_width(char *, void *);
static int config_parse_output_datefmt (void *, const char *); static int config_parse_output_datefmt(void *, const char *);
static int config_serialize_output_datefmt (char *, void *); static int config_serialize_output_datefmt(char *, void *);
static int config_parse_input_datefmt (void *, const char *); static int config_parse_input_datefmt(void *, const char *);
static int config_serialize_input_datefmt (char *, void *); static int config_serialize_input_datefmt(char *, void *);
#define CONFIG_HANDLER_BOOL(var) (config_fn_parse_t) config_parse_bool, \ #define CONFIG_HANDLER_BOOL(var) (config_fn_parse_t) config_parse_bool, \
(config_fn_serialize_t) config_serialize_bool, &(var) (config_fn_serialize_t) config_serialize_bool, &(var)
@ -82,44 +82,49 @@ static int config_serialize_input_datefmt (char *, void *);
(config_fn_serialize_t) config_serialize_str, &(var) (config_fn_serialize_t) config_serialize_str, &(var)
static const struct confvar confmap[] = { static const struct confvar confmap[] = {
{ "appearance.calendarview", config_parse_calendar_view, config_serialize_calendar_view, NULL }, {"appearance.calendarview", config_parse_calendar_view,
{ "appearance.layout", config_parse_layout, config_serialize_layout, NULL }, config_serialize_calendar_view, NULL},
{ "appearance.notifybar", CONFIG_HANDLER_BOOL (nbar.show) }, {"appearance.layout", config_parse_layout, config_serialize_layout, NULL},
{ "appearance.sidebarwidth", config_parse_sidebar_width, config_serialize_sidebar_width, NULL }, {"appearance.notifybar", CONFIG_HANDLER_BOOL(nbar.show)},
{ "appearance.theme", config_parse_color_theme, config_serialize_color_theme, NULL }, {"appearance.sidebarwidth", config_parse_sidebar_width,
{ "daemon.enable", CONFIG_HANDLER_BOOL (dmon.enable) }, config_serialize_sidebar_width, NULL},
{ "daemon.log", CONFIG_HANDLER_BOOL (dmon.log) }, {"appearance.theme", config_parse_color_theme, config_serialize_color_theme,
{ "format.inputdate", config_parse_input_datefmt, config_serialize_input_datefmt, NULL }, NULL},
{ "format.notifydate", CONFIG_HANDLER_STR (nbar.datefmt) }, {"daemon.enable", CONFIG_HANDLER_BOOL(dmon.enable)},
{ "format.notifytime", CONFIG_HANDLER_STR (nbar.timefmt) }, {"daemon.log", CONFIG_HANDLER_BOOL(dmon.log)},
{ "format.outputdate", config_parse_output_datefmt, config_serialize_output_datefmt, NULL }, {"format.inputdate", config_parse_input_datefmt,
{ "general.autogc", CONFIG_HANDLER_BOOL (conf.auto_gc) }, config_serialize_input_datefmt, NULL},
{ "general.autosave", CONFIG_HANDLER_BOOL (conf.auto_save) }, {"format.notifydate", CONFIG_HANDLER_STR(nbar.datefmt)},
{ "general.confirmdelete", CONFIG_HANDLER_BOOL (conf.confirm_delete) }, {"format.notifytime", CONFIG_HANDLER_STR(nbar.timefmt)},
{ "general.confirmquit", CONFIG_HANDLER_BOOL (conf.confirm_quit) }, {"format.outputdate", config_parse_output_datefmt,
{ "general.firstdayofweek", config_parse_first_day_of_week, config_serialize_first_day_of_week, NULL }, config_serialize_output_datefmt, NULL},
{ "general.periodicsave", CONFIG_HANDLER_UNSIGNED (conf.periodic_save) }, {"general.autogc", CONFIG_HANDLER_BOOL(conf.auto_gc)},
{ "general.progressbar", CONFIG_HANDLER_BOOL (conf.progress_bar) }, {"general.autosave", CONFIG_HANDLER_BOOL(conf.auto_save)},
{ "general.systemdialogs", CONFIG_HANDLER_BOOL (conf.system_dialogs) }, {"general.confirmdelete", CONFIG_HANDLER_BOOL(conf.confirm_delete)},
{ "notification.command", CONFIG_HANDLER_STR (nbar.cmd) }, {"general.confirmquit", CONFIG_HANDLER_BOOL(conf.confirm_quit)},
{ "notification.notifyall", CONFIG_HANDLER_BOOL (nbar.notify_all) }, {"general.firstdayofweek", config_parse_first_day_of_week,
{ "notification.warning", CONFIG_HANDLER_INT (nbar.cntdwn) } 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 { struct config_save_status {
FILE *fp; FILE *fp;
int done[sizeof (confmap) / sizeof (confmap[0])]; int done[sizeof(confmap) / sizeof(confmap[0])];
}; };
typedef int (*config_fn_walk_cb_t) (const char *, const char *, void *); typedef int (*config_fn_walk_cb_t) (const char *, const char *, void *);
typedef int (*config_fn_walk_junk_cb_t) (const char *, void *); typedef int (*config_fn_walk_junk_cb_t) (const char *, void *);
static int static int config_parse_bool(unsigned *dest, const char *val)
config_parse_bool (unsigned *dest, const char *val)
{ {
if (strcmp (val, "yes") == 0) if (strcmp(val, "yes") == 0)
*dest = 1; *dest = 1;
else if (strcmp (val, "no") == 0) else if (strcmp(val, "no") == 0)
*dest = 0; *dest = 0;
else else
return 0; return 0;
@ -127,55 +132,51 @@ config_parse_bool (unsigned *dest, const char *val)
return 1; return 1;
} }
static int static int config_parse_unsigned(unsigned *dest, const char *val)
config_parse_unsigned (unsigned *dest, const char *val)
{ {
if (is_all_digit (val)) if (is_all_digit(val))
*dest = atoi (val); *dest = atoi(val);
else else
return 0; return 0;
return 1; return 1;
} }
static int static int config_parse_int(int *dest, const char *val)
config_parse_int (int *dest, const char *val)
{ {
if ((*val == '+' || *val == '-' || isdigit (*val)) && is_all_digit (val + 1)) if ((*val == '+' || *val == '-' || isdigit(*val)) && is_all_digit(val + 1))
*dest = atoi (val); *dest = atoi(val);
else else
return 0; return 0;
return 1; return 1;
} }
static int static int config_parse_str(char *dest, const char *val)
config_parse_str (char *dest, const char *val)
{ {
strncpy (dest, val, BUFSIZ); strncpy(dest, val, BUFSIZ);
return 1; return 1;
} }
static int static int config_parse_color(int *dest, const char *val)
config_parse_color (int *dest, const char *val)
{ {
if (!strcmp (val, "black")) if (!strcmp(val, "black"))
*dest = COLOR_BLACK; *dest = COLOR_BLACK;
else if (!strcmp (val, "red")) else if (!strcmp(val, "red"))
*dest = COLOR_RED; *dest = COLOR_RED;
else if (!strcmp (val, "green")) else if (!strcmp(val, "green"))
*dest = COLOR_GREEN; *dest = COLOR_GREEN;
else if (!strcmp (val, "yellow")) else if (!strcmp(val, "yellow"))
*dest = COLOR_YELLOW; *dest = COLOR_YELLOW;
else if (!strcmp (val, "blue")) else if (!strcmp(val, "blue"))
*dest = COLOR_BLUE; *dest = COLOR_BLUE;
else if (!strcmp (val, "magenta")) else if (!strcmp(val, "magenta"))
*dest = COLOR_MAGENTA; *dest = COLOR_MAGENTA;
else if (!strcmp (val, "cyan")) else if (!strcmp(val, "cyan"))
*dest = COLOR_CYAN; *dest = COLOR_CYAN;
else if (!strcmp (val, "white")) else if (!strcmp(val, "white"))
*dest = COLOR_WHITE; *dest = COLOR_WHITE;
else if (!strcmp (val, "default")) else if (!strcmp(val, "default"))
*dest = background; *dest = background;
else else
return 0; return 0;
@ -183,111 +184,96 @@ config_parse_color (int *dest, const char *val)
return 1; return 1;
} }
static int static int config_parse_color_pair(int *dest1, int *dest2, const char *val)
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) if (sscanf(val, "%s on %s", s1, s2) != 2)
return 0; 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 static int config_parse_calendar_view(void *dummy, const char *val)
config_parse_calendar_view (void *dummy, const char *val)
{ {
calendar_set_view (atoi (val)); calendar_set_view(atoi(val));
return 1; return 1;
} }
static int static int config_parse_first_day_of_week(void *dummy, const char *val)
config_parse_first_day_of_week (void *dummy, const char *val)
{ {
if (!strcmp (val, "monday")) if (!strcmp(val, "monday"))
calendar_set_first_day_of_week (MONDAY); calendar_set_first_day_of_week(MONDAY);
else if (!strcmp (val, "sunday")) else if (!strcmp(val, "sunday"))
calendar_set_first_day_of_week (SUNDAY); calendar_set_first_day_of_week(SUNDAY);
else else
return 0; return 0;
return 1; return 1;
} }
static int static int config_parse_color_theme(void *dummy, const char *val)
config_parse_color_theme (void *dummy, const char *val)
{ {
int color1, color2; int color1, color2;
if (!config_parse_color_pair (&color1, &color2, val)) if (!config_parse_color_pair(&color1, &color2, val))
return 0; return 0;
init_pair (COLR_CUSTOM, color1, color2); init_pair(COLR_CUSTOM, color1, color2);
return 1; return 1;
} }
static int static int config_parse_layout(void *dummy, const char *val)
config_parse_layout (void *dummy, const char *val)
{ {
wins_set_layout (atoi (val)); wins_set_layout(atoi(val));
return 1; return 1;
} }
static int static int config_parse_sidebar_width(void *dummy, const char *val)
config_parse_sidebar_width (void *dummy, const char *val)
{ {
wins_set_sbar_width (atoi (val)); wins_set_sbar_width(atoi(val));
return 1; return 1;
} }
static int static int config_parse_output_datefmt(void *dummy, const char *val)
config_parse_output_datefmt (void *dummy, const char *val)
{ {
if (val[0] != '\0') if (val[0] != '\0')
return config_parse_str (conf.output_datefmt, val); return config_parse_str(conf.output_datefmt, val);
return 1; return 1;
} }
static int static int config_parse_input_datefmt(void *dummy, const char *val)
config_parse_input_datefmt (void *dummy, const char *val)
{ {
if (config_parse_int (&conf.input_datefmt, val)) { if (config_parse_int(&conf.input_datefmt, val)) {
if (conf.input_datefmt <= 0 || conf.input_datefmt >= DATE_FORMATS) if (conf.input_datefmt <= 0 || conf.input_datefmt >= DATE_FORMATS)
conf.input_datefmt = 1; conf.input_datefmt = 1;
return 1; return 1;
} } else
else
return 0; return 0;
} }
/* Set a configuration variable. */ /* Set a configuration variable. */
static int static int config_set_conf(const char *key, const char *value)
config_set_conf (const char *key, const char *value)
{ {
int i; int i;
if (!key) if (!key)
return -1; return -1;
for (i = 0; i < sizeof (confmap) / sizeof (confmap[0]); i++) for (i = 0; i < sizeof(confmap) / sizeof(confmap[0]); i++) {
{ if (!strcmp(confmap[i].key, key))
if (!strcmp (confmap[i].key, key)) return confmap[i].fn_parse(confmap[i].target, value);
return confmap[i].fn_parse (confmap[i].target, value);
} }
return -1; return -1;
} }
static int static int config_serialize_bool(char *dest, unsigned *val)
config_serialize_bool (char *dest, unsigned *val)
{ {
if (*val) if (*val) {
{
dest[0] = 'y'; dest[0] = 'y';
dest[1] = 'e'; dest[1] = 'e';
dest[2] = 's'; dest[2] = 's';
dest[3] = '\0'; dest[3] = '\0';
} } else {
else
{
dest[0] = 'n'; dest[0] = 'n';
dest[1] = 'o'; dest[1] = 'o';
dest[2] = '\0'; dest[2] = '\0';
@ -296,24 +282,21 @@ config_serialize_bool (char *dest, unsigned *val)
return 1; return 1;
} }
static int static int config_serialize_unsigned(char *dest, unsigned *val)
config_serialize_unsigned (char *dest, unsigned *val)
{ {
snprintf (dest, BUFSIZ, "%u", *val); snprintf(dest, BUFSIZ, "%u", *val);
return 1; return 1;
} }
static int static int config_serialize_int(char *dest, int *val)
config_serialize_int (char *dest, int *val)
{ {
snprintf (dest, BUFSIZ, "%d", *val); snprintf(dest, BUFSIZ, "%d", *val);
return 1; return 1;
} }
static int static int config_serialize_str(char *dest, const char *val)
config_serialize_str (char *dest, const char *val)
{ {
strncpy (dest, val, BUFSIZ); strncpy(dest, val, BUFSIZ);
return 1; return 1;
} }
@ -325,8 +308,7 @@ config_serialize_str (char *dest, const char *val)
* If ncurses library was compiled with --enable-ext-funcs, * If ncurses library was compiled with --enable-ext-funcs,
* then default color is -1. * then default color is -1.
*/ */
static void static void config_color_theme_name(char *theme_name)
config_color_theme_name (char *theme_name)
{ {
#define MAXCOLORS 8 #define MAXCOLORS 8
#define NBCOLORS 2 #define NBCOLORS 2
@ -349,37 +331,32 @@ config_color_theme_name (char *theme_name)
}; };
if (!colorize) if (!colorize)
strncpy (theme_name, "0", BUFSIZ); strncpy(theme_name, "0", BUFSIZ);
else else {
{ pair_content(COLR_CUSTOM, &color[0], &color[1]);
pair_content (COLR_CUSTOM, &color[0], &color[1]); for (i = 0; i < NBCOLORS; i++) {
for (i = 0; i < NBCOLORS; i++)
{
if ((color[i] == DEFAULTCOLOR) || (color[i] == DEFAULTCOLOR_EXT)) if ((color[i] == DEFAULTCOLOR) || (color[i] == DEFAULTCOLOR_EXT))
color_name[i] = default_color; color_name[i] = default_color;
else if (color[i] >= 0 && color[i] <= MAXCOLORS) else if (color[i] >= 0 && color[i] <= MAXCOLORS)
color_name[i] = name[color[i]]; color_name[i] = name[color[i]];
else else {
{ EXIT(_("unknown color"));
EXIT (_("unknown color"));
/* NOTREACHED */ /* NOTREACHED */
} }
} }
snprintf (theme_name, BUFSIZ, "%s on %s", color_name[0], color_name[1]); snprintf(theme_name, BUFSIZ, "%s on %s", color_name[0], color_name[1]);
} }
} }
static int static int config_serialize_calendar_view(char *buf, void *dummy)
config_serialize_calendar_view (char *buf, void *dummy)
{ {
int tmp = calendar_get_view (); int tmp = calendar_get_view();
return config_serialize_int (buf, &tmp); return config_serialize_int(buf, &tmp);
} }
static int static int config_serialize_first_day_of_week(char *buf, void *dummy)
config_serialize_first_day_of_week (char *buf, void *dummy)
{ {
if (calendar_week_begins_on_monday ()) if (calendar_week_begins_on_monday())
strcpy(buf, "monday"); strcpy(buf, "monday");
else else
strcpy(buf, "sunday"); strcpy(buf, "sunday");
@ -387,42 +364,37 @@ config_serialize_first_day_of_week (char *buf, void *dummy)
return 1; return 1;
} }
static int static int config_serialize_color_theme(char *buf, void *dummy)
config_serialize_color_theme (char *buf, void *dummy)
{ {
config_color_theme_name (buf); config_color_theme_name(buf);
return 1; return 1;
} }
static int static int config_serialize_layout(char *buf, void *dummy)
config_serialize_layout (char *buf, void *dummy)
{ {
int tmp = wins_layout (); int tmp = wins_layout();
return config_serialize_int (buf, &tmp); return config_serialize_int(buf, &tmp);
} }
static int static int config_serialize_sidebar_width(char *buf, void *dummy)
config_serialize_sidebar_width (char *buf, void *dummy)
{ {
int tmp = wins_sbar_wperc (); int tmp = wins_sbar_wperc();
return config_serialize_int (buf, &tmp); return config_serialize_int(buf, &tmp);
} }
static int static int config_serialize_output_datefmt(char *buf, void *dummy)
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 static int config_serialize_input_datefmt(char *buf, void *dummy)
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. */ /* Serialize the value of a configuration variable. */
static int static int
config_serialize_conf (char *buf, const char *key, config_serialize_conf(char *buf, const char *key,
struct config_save_status *status) struct config_save_status *status)
{ {
int i; int i;
@ -430,17 +402,13 @@ config_serialize_conf (char *buf, const char *key,
if (!key) if (!key)
return -1; return -1;
for (i = 0; i < sizeof (confmap) / sizeof (confmap[0]); i++) for (i = 0; i < sizeof(confmap) / sizeof(confmap[0]); i++) {
{ if (!strcmp(confmap[i].key, key)) {
if (!strcmp (confmap[i].key, key)) if (confmap[i].fn_serialize(buf, confmap[i].target)) {
{
if (confmap[i].fn_serialize (buf, confmap[i].target))
{
if (status) if (status)
status->done[i] = 1; status->done[i] = 1;
return 1; return 1;
} } else
else
return 0; return 0;
} }
} }
@ -449,34 +417,31 @@ config_serialize_conf (char *buf, const char *key,
} }
static void static void
config_file_walk (config_fn_walk_cb_t fn_cb, config_file_walk(config_fn_walk_cb_t fn_cb,
config_fn_walk_junk_cb_t fn_junk_cb, void *data) config_fn_walk_junk_cb_t fn_junk_cb, void *data)
{ {
FILE *data_file; FILE *data_file;
char buf[BUFSIZ], e_conf[BUFSIZ]; char buf[BUFSIZ], e_conf[BUFSIZ];
char *key, *value; char *key, *value;
data_file = fopen (path_conf, "r"); data_file = fopen(path_conf, "r");
EXIT_IF (data_file == NULL, _("failed to open configuration file")); EXIT_IF(data_file == NULL, _("failed to open configuration file"));
pthread_mutex_lock (&nbar.mutex); pthread_mutex_lock(&nbar.mutex);
for (;;) for (;;) {
{ if (fgets(buf, sizeof buf, data_file) == NULL)
if (fgets (buf, sizeof buf, data_file) == NULL)
break; break;
io_extract_data (e_conf, buf, sizeof buf); io_extract_data(e_conf, buf, sizeof buf);
if (*e_conf == '\0') if (*e_conf == '\0') {
{
if (fn_junk_cb) if (fn_junk_cb)
fn_junk_cb (buf, data); fn_junk_cb(buf, data);
continue; continue;
} }
key = e_conf; key = e_conf;
value = strchr (e_conf, '='); value = strchr(e_conf, '=');
if (value) if (value) {
{
*value = '\0'; *value = '\0';
value++; value++;
} }
@ -502,80 +467,74 @@ config_file_walk (config_fn_walk_cb_t fn_cb,
strcmp(key, "output_datefmt") == 0 || strcmp(key, "output_datefmt") == 0 ||
strcmp(key, "input_datefmt") == 0 || strcmp(key, "input_datefmt") == 0 ||
strcmp(key, "notify-daemon_enable") == 0 || strcmp(key, "notify-daemon_enable") == 0 ||
strcmp(key, "notify-daemon_log") == 0) strcmp(key, "notify-daemon_log") == 0) {
{ WARN_MSG(_("Pre-3.0.0 configuration file format detected, "
WARN_MSG (_("Pre-3.0.0 configuration file format detected, "
"please upgrade running `calcurse-upgrade`.")); "please upgrade running `calcurse-upgrade`."));
} }
if (value && (*value == '\0' || *value == '\n')) if (value && (*value == '\0' || *value == '\n')) {
{
/* Backward compatibility mode. */ /* Backward compatibility mode. */
if (fgets (buf, sizeof buf, data_file) == NULL) if (fgets(buf, sizeof buf, data_file) == NULL)
break; break;
io_extract_data (e_conf, buf, sizeof buf); io_extract_data(e_conf, buf, sizeof buf);
value = e_conf; value = e_conf;
} }
fn_cb (key, value, data); fn_cb(key, value, data);
} }
file_close (data_file, __FILE_POS__); file_close(data_file, __FILE_POS__);
pthread_mutex_unlock (&nbar.mutex); pthread_mutex_unlock(&nbar.mutex);
} }
static int static int config_load_cb(const char *key, const char *value, void *dummy)
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) if (result < 0)
EXIT (_("configuration variable unknown: \"%s\""), key); EXIT(_("configuration variable unknown: \"%s\""), key);
/* NOTREACHED */ /* NOTREACHED */
else if (result == 0) else if (result == 0)
EXIT (_("wrong configuration variable format for \"%s\""), key); EXIT(_("wrong configuration variable format for \"%s\""), key);
/* NOTREACHED */ /* NOTREACHED */
return 1; return 1;
} }
/* Load the user configuration. */ /* Load the user configuration. */
void void config_load(void)
config_load (void)
{ {
config_file_walk (config_load_cb, NULL, NULL); config_file_walk(config_load_cb, NULL, NULL);
} }
static int static int config_save_cb(const char *key, const char *value, void *status)
config_save_cb (const char *key, const char *value, void *status)
{ {
char buf[BUFSIZ]; char buf[BUFSIZ];
int result = config_serialize_conf (buf, key, (struct config_save_status *) status); int result =
config_serialize_conf(buf, key, (struct config_save_status *)status);
if (result < 0) if (result < 0)
EXIT (_("configuration variable unknown: \"%s\""), key); EXIT(_("configuration variable unknown: \"%s\""), key);
/* NOTREACHED */ /* NOTREACHED */
else if (result == 0) else if (result == 0)
EXIT (_("wrong configuration variable format for \"%s\""), key); EXIT(_("wrong configuration variable format for \"%s\""), key);
/* NOTREACHED */ /* NOTREACHED */
fputs (key, ((struct config_save_status *) status)->fp); fputs(key, ((struct config_save_status *)status)->fp);
fputc ('=', ((struct config_save_status *) status)->fp); fputc('=', ((struct config_save_status *)status)->fp);
fputs (buf, ((struct config_save_status *) status)->fp); fputs(buf, ((struct config_save_status *)status)->fp);
fputc ('\n', ((struct config_save_status *) status)->fp); fputc('\n', ((struct config_save_status *)status)->fp);
return 1; return 1;
} }
static int static int config_save_junk_cb(const char *data, void *status)
config_save_junk_cb (const char *data, void *status)
{ {
fputs (data, ((struct config_save_status *) status)->fp); fputs(data, ((struct config_save_status *)status)->fp);
return 1; return 1;
} }
/* Save the user configuration. */ /* Save the user configuration. */
unsigned unsigned config_save(void)
config_save (void)
{ {
char tmppath[BUFSIZ]; char tmppath[BUFSIZ];
char *tmpext; char *tmpext;
@ -585,32 +544,31 @@ config_save (void)
if (read_only) if (read_only)
return 1; return 1;
strncpy (tmppath, get_tempdir (), BUFSIZ); strncpy(tmppath, get_tempdir(), BUFSIZ);
strncat (tmppath, "/" CONF_PATH_NAME ".", BUFSIZ - strlen (tmppath) - 1); strncat(tmppath, "/" CONF_PATH_NAME ".", BUFSIZ - strlen(tmppath) - 1);
if ((tmpext = new_tempfile (tmppath, TMPEXTSIZ)) == NULL) if ((tmpext = new_tempfile(tmppath, TMPEXTSIZ)) == NULL)
return 0; return 0;
strncat (tmppath, tmpext, BUFSIZ - strlen (tmppath) - 1); strncat(tmppath, tmpext, BUFSIZ - strlen(tmppath) - 1);
mem_free (tmpext); mem_free(tmpext);
status.fp = fopen (tmppath, "w"); status.fp = fopen(tmppath, "w");
if (!status.fp) if (!status.fp)
return 0; 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. */ /* Set variables that were missing from the configuration file. */
for (i = 0; i < sizeof (confmap) / sizeof (confmap[0]); i++) for (i = 0; i < sizeof(confmap) / sizeof(confmap[0]); i++) {
{
if (!status.done[i]) if (!status.done[i])
config_save_cb (confmap[i].key, NULL, &status); 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)) if (io_file_cp(tmppath, path_conf))
unlink (tmppath); unlink(tmppath);
return 1; return 1;
} }

File diff suppressed because it is too large Load Diff

732
src/day.c

File diff suppressed because it is too large Load Diff

View File

@ -64,26 +64,22 @@
static unsigned data_loaded; static unsigned data_loaded;
static void static void dmon_sigs_hdlr(int sig)
dmon_sigs_hdlr (int sig)
{ {
if (data_loaded) if (data_loaded)
free_user_data (); 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) if (unlink(path_dpid) != 0) {
{ DMON_LOG(_("Could not remove daemon lock file: %s\n"), strerror(errno));
DMON_LOG (_("Could not remove daemon lock file: %s\n"), exit(EXIT_FAILURE);
strerror (errno));
exit (EXIT_FAILURE);
} }
exit (EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
static unsigned static unsigned daemonize(int status)
daemonize (int status)
{ {
int fd; int fd;
@ -93,15 +89,14 @@ daemonize (int status)
* First need to fork in order to become a child of the init process, * First need to fork in order to become a child of the init process,
* once the father exits. * once the father exits.
*/ */
switch (fork ()) switch (fork()) {
{
case -1: /* fork error */ case -1: /* fork error */
EXIT (_("Could not fork: %s\n"), strerror (errno)); EXIT(_("Could not fork: %s\n"), strerror(errno));
break; break;
case 0: /* child */ case 0: /* child */
break; break;
default: /* parent */ default: /* parent */
exit (status); exit(status);
} }
/* /*
@ -110,10 +105,9 @@ daemonize (int status)
* Obtain a new process group and session in order to get detached from the * Obtain a new process group and session in order to get detached from the
* controlling terminal. * controlling terminal.
*/ */
if (setsid () == -1) if (setsid() == -1) {
{ DMON_LOG(_("Could not detach from the controlling terminal: %s\n"),
DMON_LOG (_("Could not detach from the controlling terminal: %s\n"), strerror(errno));
strerror (errno));
return 0; return 0;
} }
@ -121,82 +115,74 @@ daemonize (int status)
* Change working directory to root directory, * Change working directory to root directory,
* to prevent filesystem unmounts. * to prevent filesystem unmounts.
*/ */
if (chdir ("/") == -1) if (chdir("/") == -1) {
{ DMON_LOG(_("Could not change working directory: %s\n"), strerror(errno));
DMON_LOG (_("Could not change working directory: %s\n"),
strerror (errno));
return 0; return 0;
} }
/* Redirect standard file descriptors to /dev/null. */ /* Redirect standard file descriptors to /dev/null. */
if ((fd = open (_PATH_DEVNULL, O_RDWR, 0)) != -1) if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
{ dup2(fd, STDIN_FILENO);
dup2 (fd, STDIN_FILENO); dup2(fd, STDOUT_FILENO);
dup2 (fd, STDOUT_FILENO); dup2(fd, STDERR_FILENO);
dup2 (fd, STDERR_FILENO);
if (fd > 2) if (fd > 2)
close (fd); close(fd);
} }
/* Write access for the owner only. */ /* Write access for the owner only. */
umask (0022); umask(0022);
if (!sigs_set_hdlr (SIGINT, dmon_sigs_hdlr) if (!sigs_set_hdlr(SIGINT, dmon_sigs_hdlr)
|| !sigs_set_hdlr (SIGTERM, dmon_sigs_hdlr) || !sigs_set_hdlr(SIGTERM, dmon_sigs_hdlr)
|| !sigs_set_hdlr (SIGALRM, dmon_sigs_hdlr) || !sigs_set_hdlr(SIGALRM, dmon_sigs_hdlr)
|| !sigs_set_hdlr (SIGQUIT, dmon_sigs_hdlr) || !sigs_set_hdlr(SIGQUIT, dmon_sigs_hdlr)
|| !sigs_set_hdlr (SIGCHLD, SIG_IGN)) || !sigs_set_hdlr(SIGCHLD, SIG_IGN))
return 0; return 0;
return 1; return 1;
} }
void void dmon_start(int parent_exit_status)
dmon_start (int parent_exit_status)
{ {
if (!daemonize (parent_exit_status)) if (!daemonize(parent_exit_status))
DMON_ABRT (_("Cannot daemonize, aborting\n")); DMON_ABRT(_("Cannot daemonize, aborting\n"));
if (!io_dump_pid (path_dpid)) if (!io_dump_pid(path_dpid))
DMON_ABRT (_("Could not set lock file\n")); DMON_ABRT(_("Could not set lock file\n"));
if (!io_file_exist (path_conf)) if (!io_file_exist(path_conf))
DMON_ABRT (_("Could not access \"%s\": %s\n"), DMON_ABRT(_("Could not access \"%s\": %s\n"), path_conf, strerror(errno));
path_conf, strerror (errno)); config_load();
config_load ();
if (!io_file_exist (path_apts)) if (!io_file_exist(path_apts))
DMON_ABRT (_("Could not access \"%s\": %s\n"), DMON_ABRT(_("Could not access \"%s\": %s\n"), path_apts, strerror(errno));
path_apts, strerror (errno)); apoint_llist_init();
apoint_llist_init (); recur_apoint_llist_init();
recur_apoint_llist_init (); event_llist_init();
event_llist_init (); todo_init_list();
todo_init_list (); io_load_app();
io_load_app ();
data_loaded = 1; data_loaded = 1;
DMON_LOG (_("started at %s\n"), nowstr ()); DMON_LOG(_("started at %s\n"), nowstr());
for (;;) for (;;) {
{
int left; int left;
if (!notify_get_next_bkgd ()) if (!notify_get_next_bkgd())
DMON_ABRT (_("error loading next appointment\n")); DMON_ABRT(_("error loading next appointment\n"));
left = notify_time_left (); left = notify_time_left();
if (left > 0 && left < nbar.cntdwn && notify_needs_reminder ()) if (left > 0 && left < nbar.cntdwn && notify_needs_reminder()) {
{ DMON_LOG(_("launching notification at %s for: \"%s\"\n"),
DMON_LOG (_("launching notification at %s for: \"%s\"\n"), nowstr(), notify_app_txt());
nowstr (), notify_app_txt ()); if (!notify_launch_cmd())
if (!notify_launch_cmd ()) DMON_LOG(_("error while sending notification\n"));
DMON_LOG (_("error while sending notification\n"));
} }
DMON_LOG (ngettext ("sleeping at %s for %d second\n", DMON_LOG(ngettext("sleeping at %s for %d second\n",
"sleeping at %s for %d seconds\n", "sleeping at %s for %d seconds\n",
DMON_SLEEP_TIME), nowstr (), DMON_SLEEP_TIME); DMON_SLEEP_TIME), nowstr(), DMON_SLEEP_TIME);
psleep (DMON_SLEEP_TIME); psleep(DMON_SLEEP_TIME);
DMON_LOG (_("awakened at %s\n"), nowstr ()); DMON_LOG(_("awakened at %s\n"), nowstr());
} }
} }
@ -204,15 +190,14 @@ dmon_start (int parent_exit_status)
* Check if calcurse is running in background, and if yes, send a SIGINT * Check if calcurse is running in background, and if yes, send a SIGINT
* signal to stop it. * signal to stop it.
*/ */
void void dmon_stop(void)
dmon_stop (void)
{ {
int dpid; int dpid;
dpid = io_get_pid (path_dpid); dpid = io_get_pid(path_dpid);
if (!dpid) if (!dpid)
return; return;
if (kill ((pid_t)dpid, SIGINT) < 0 && errno != ESRCH) if (kill((pid_t) dpid, SIGINT) < 0 && errno != ESRCH)
EXIT (_("Could not stop calcurse daemon: %s\n"), strerror (errno)); EXIT(_("Could not stop calcurse daemon: %s\n"), strerror(errno));
} }

View File

@ -44,113 +44,101 @@
llist_t eventlist; llist_t eventlist;
static struct event bkp_cut_event; static struct event bkp_cut_event;
void void event_free_bkp(void)
event_free_bkp (void)
{ {
if (bkp_cut_event.mesg) if (bkp_cut_event.mesg) {
{ mem_free(bkp_cut_event.mesg);
mem_free (bkp_cut_event.mesg);
bkp_cut_event.mesg = 0; bkp_cut_event.mesg = 0;
} }
erase_note (&bkp_cut_event.note); erase_note(&bkp_cut_event.note);
} }
static void static void event_free(struct event *ev)
event_free (struct event *ev)
{ {
mem_free (ev->mesg); mem_free(ev->mesg);
erase_note (&ev->note); erase_note(&ev->note);
mem_free (ev); mem_free(ev);
} }
static void static void event_dup(struct event *in, struct event *bkp)
event_dup (struct event *in, struct event *bkp)
{ {
EXIT_IF (!in || !bkp, _("null pointer")); EXIT_IF(!in || !bkp, _("null pointer"));
bkp->id = in->id; bkp->id = in->id;
bkp->day = in->day; bkp->day = in->day;
bkp->mesg = mem_strdup (in->mesg); bkp->mesg = mem_strdup(in->mesg);
if (in->note) if (in->note)
bkp->note = mem_strdup (in->note); bkp->note = mem_strdup(in->note);
} }
void void event_llist_init(void)
event_llist_init (void)
{ {
LLIST_INIT (&eventlist); LLIST_INIT(&eventlist);
} }
void void event_llist_free(void)
event_llist_free (void)
{ {
LLIST_FREE_INNER (&eventlist, event_free); LLIST_FREE_INNER(&eventlist, event_free);
LLIST_FREE (&eventlist); LLIST_FREE(&eventlist);
} }
static int static int event_cmp_day(struct event *a, struct event *b)
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 */ /* Create a new event */
struct event * struct event *event_new(char *mesg, char *note, long day, int id)
event_new (char *mesg, char *note, long day, int id)
{ {
struct event *ev; struct event *ev;
ev = mem_malloc (sizeof (struct event)); ev = mem_malloc(sizeof(struct event));
ev->mesg = mem_strdup (mesg); ev->mesg = mem_strdup(mesg);
ev->day = day; ev->day = day;
ev->id = id; ev->id = id;
ev->note = (note != NULL) ? mem_strdup (note) : NULL; 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 */ /* Check if the event belongs to the selected day */
unsigned unsigned event_inday(struct event *i, long start)
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 */ /* Write to file the event in user-friendly format */
void void event_write(struct event *o, FILE * f)
event_write (struct event *o, FILE *f)
{ {
struct tm *lt; struct tm *lt;
time_t t; time_t t;
t = o->day; t = o->day;
lt = localtime (&t); lt = localtime(&t);
fprintf (f, "%02u/%02u/%04u [%d] ", lt->tm_mon + 1, lt->tm_mday, fprintf(f, "%02u/%02u/%04u [%d] ", lt->tm_mon + 1, lt->tm_mday,
1900 + lt->tm_year, o->id); 1900 + lt->tm_year, o->id);
if (o->note != NULL) if (o->note != NULL)
fprintf (f, ">%s ", o->note); fprintf(f, ">%s ", o->note);
fprintf (f, "%s\n", o->mesg); fprintf(f, "%s\n", o->mesg);
} }
/* Load the events from file */ /* Load the events from file */
struct event * struct event *event_scan(FILE * f, struct tm start, int id, char *note)
event_scan (FILE *f, struct tm start, int id, char *note)
{ {
char buf[BUFSIZ], *nl; char buf[BUFSIZ], *nl;
time_t tstart, t; time_t tstart, t;
t = time (NULL); t = time(NULL);
localtime (&t); localtime(&t);
/* Read the event description */ /* Read the event description */
if (!fgets (buf, sizeof buf, f)) if (!fgets(buf, sizeof buf, f))
return NULL; return NULL;
nl = strchr (buf, '\n'); nl = strchr(buf, '\n');
if (nl) if (nl) {
{
*nl = '\0'; *nl = '\0';
} }
start.tm_hour = 0; start.tm_hour = 0;
@ -160,57 +148,53 @@ event_scan (FILE *f, struct tm start, int id, char *note)
start.tm_year -= 1900; start.tm_year -= 1900;
start.tm_mon--; start.tm_mon--;
tstart = mktime (&start); tstart = mktime(&start);
EXIT_IF (tstart == -1, _("date error in the event\n")); EXIT_IF(tstart == -1, _("date error in the event\n"));
return event_new (buf, note, tstart, id); return event_new(buf, note, tstart, id);
} }
/* Retrieve an event from the list, given the day and item position. */ /* Retrieve an event from the list, given the day and item position. */
struct event * struct event *event_get(long day, int pos)
event_get (long day, int pos)
{ {
llist_item_t *i = LLIST_FIND_NTH (&eventlist, pos, day, event_inday); llist_item_t *i = LLIST_FIND_NTH(&eventlist, pos, day, event_inday);
if (i) if (i)
return LLIST_TS_GET_DATA (i); return LLIST_TS_GET_DATA(i);
EXIT (_("event not found")); EXIT(_("event not found"));
/* NOTREACHED */ /* NOTREACHED */
} }
/* Delete an event from the list. */ /* Delete an event from the list. */
void void event_delete_bynum(long start, unsigned num, enum eraseflg flag)
event_delete_bynum (long start, unsigned num, enum eraseflg flag)
{ {
llist_item_t *i = LLIST_FIND_NTH (&eventlist, num, start, event_inday); llist_item_t *i = LLIST_FIND_NTH(&eventlist, num, start, event_inday);
if (!i) if (!i)
EXIT (_("no such appointment")); EXIT(_("no such appointment"));
struct event *ev = LLIST_TS_GET_DATA (i); struct event *ev = LLIST_TS_GET_DATA(i);
switch (flag) switch (flag) {
{
case ERASE_FORCE_ONLY_NOTE: case ERASE_FORCE_ONLY_NOTE:
erase_note (&ev->note); erase_note(&ev->note);
break; break;
case ERASE_CUT: case ERASE_CUT:
event_free_bkp (); event_free_bkp();
event_dup (ev, &bkp_cut_event); event_dup(ev, &bkp_cut_event);
erase_note (&ev->note); erase_note(&ev->note);
/* FALLTHROUGH */ /* FALLTHROUGH */
default: default:
LLIST_REMOVE (&eventlist, i); LLIST_REMOVE(&eventlist, i);
mem_free (ev->mesg); mem_free(ev->mesg);
mem_free (ev); mem_free(ev);
break; break;
} }
} }
void void event_paste_item(void)
event_paste_item (void)
{ {
event_new (bkp_cut_event.mesg, bkp_cut_event.note, event_new(bkp_cut_event.mesg, bkp_cut_event.note,
date2sec (*calendar_get_slctd_day (), 0, 0), bkp_cut_event.id); date2sec(*calendar_get_slctd_day(), 0, 0), bkp_cut_event.id);
event_free_bkp (); event_free_bkp();
} }

View File

@ -48,14 +48,13 @@ struct getstr_status {
}; };
/* Print the string at the desired position. */ /* Print the string at the desired position. */
static void static void getstr_print(WINDOW * win, int x, int y, struct getstr_status *st)
getstr_print (WINDOW *win, int x, int y, struct getstr_status *st)
{ {
char c = 0; char c = 0;
/* print string */ /* print string */
mvwaddnstr (win, y, x, &st->s[st->ci[st->scrpos].offset], -1); mvwaddnstr(win, y, x, &st->s[st->ci[st->scrpos].offset], -1);
wclrtoeol (win); wclrtoeol(win);
/* print scrolling indicator */ /* print scrolling indicator */
if (st->scrpos > 0 && st->ci[st->len].dpyoff - if (st->scrpos > 0 && st->ci[st->len].dpyoff -
@ -65,62 +64,57 @@ getstr_print (WINDOW *win, int x, int y, struct getstr_status *st)
c = '<'; c = '<';
else if (st->ci[st->len].dpyoff - st->ci[st->scrpos].dpyoff > col - 2) else if (st->ci[st->len].dpyoff - st->ci[st->scrpos].dpyoff > col - 2)
c = '>'; c = '>';
mvwprintw (win, y, col - 2, " %c", c); mvwprintw(win, y, col - 2, " %c", c);
/* print cursor */ /* print cursor */
wmove (win, y, st->ci[st->pos].dpyoff - st->ci[st->scrpos].dpyoff); wmove(win, y, st->ci[st->pos].dpyoff - st->ci[st->scrpos].dpyoff);
wchgat (win, 1, A_REVERSE, COLR_CUSTOM, NULL); wchgat(win, 1, A_REVERSE, COLR_CUSTOM, NULL);
} }
/* Delete a character at the given position in string. */ /* Delete a character at the given position in string. */
static void static void getstr_del_char(struct getstr_status *st)
getstr_del_char (struct getstr_status *st)
{ {
char *str = st->s + st->ci[st->pos].offset; char *str = st->s + st->ci[st->pos].offset;
int cl = st->ci[st->pos + 1].offset - 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 cw = st->ci[st->pos + 1].dpyoff - st->ci[st->pos].dpyoff;
int i; int i;
memmove (str, str + cl, strlen (str) + 1); memmove(str, str + cl, strlen(str) + 1);
st->len--; st->len--;
for (i = st->pos; i <= st->len; i++) for (i = st->pos; i <= st->len; i++) {
{
st->ci[i].offset = st->ci[i + 1].offset - cl; st->ci[i].offset = st->ci[i + 1].offset - cl;
st->ci[i].dpyoff = st->ci[i + 1].dpyoff - cw; st->ci[i].dpyoff = st->ci[i + 1].dpyoff - cw;
} }
} }
/* Add a character at the given position in string. */ /* Add a character at the given position in string. */
static void static void getstr_ins_char(struct getstr_status *st, char *c)
getstr_ins_char (struct getstr_status *st, char *c)
{ {
char *str = st->s + st->ci[st->pos].offset; char *str = st->s + st->ci[st->pos].offset;
int cl = UTF8_LENGTH (c[0]); int cl = UTF8_LENGTH(c[0]);
int cw = utf8_width (c); int cw = utf8_width(c);
int i; int i;
memmove (str + cl, str, strlen (str) + 1); memmove(str + cl, str, strlen(str) + 1);
for (i = 0; i < cl; i++, str++) for (i = 0; i < cl; i++, str++)
*str = c[i]; *str = c[i];
for (i = st->len; i >= st->pos; i--) for (i = st->len; i >= st->pos; i--) {
{
st->ci[i + 1].offset = st->ci[i].offset + cl; st->ci[i + 1].offset = st->ci[i].offset + cl;
st->ci[i + 1].dpyoff = st->ci[i].dpyoff + cw; st->ci[i + 1].dpyoff = st->ci[i].dpyoff + cw;
} }
st->len++; st->len++;
} }
static void static void bell(void)
bell (void)
{ {
putchar ('\a'); putchar('\a');
} }
/* Initialize getstring data structure. */ /* Initialize getstring data structure. */
static void 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;
@ -128,14 +122,13 @@ getstr_init (struct getstr_status *st, char *str, struct getstr_charinfo *ci)
st->ci = ci; st->ci = ci;
st->len = width = 0; st->len = width = 0;
while (*str) while (*str) {
{
st->ci[st->len].offset = str - st->s; st->ci[st->len].offset = str - st->s;
st->ci[st->len].dpyoff = width; st->ci[st->len].dpyoff = width;
st->len++; st->len++;
width += utf8_width (str); width += utf8_width(str);
str += UTF8_LENGTH (*str); str += UTF8_LENGTH(*str);
} }
st->ci[st->len].offset = str - st->s; st->ci[st->len].offset = str - st->s;
st->ci[st->len].dpyoff = width; st->ci[st->len].dpyoff = width;
@ -145,26 +138,21 @@ getstr_init (struct getstr_status *st, char *str, struct getstr_charinfo *ci)
} }
/* Scroll left/right if the cursor moves outside the window range. */ /* Scroll left/right if the cursor moves outside the window range. */
static void static void getstr_fixscr(struct getstr_status *st)
getstr_fixscr (struct getstr_status *st)
{ {
const int pgsize = col / 3; const int pgsize = col / 3;
int pgskip; int pgskip;
while (st->pos < st->scrpos) while (st->pos < st->scrpos) {
{
pgskip = 0; pgskip = 0;
while (pgskip < pgsize && st->scrpos > 0) while (pgskip < pgsize && st->scrpos > 0) {
{
st->scrpos--; st->scrpos--;
pgskip += st->ci[st->scrpos + 1].dpyoff - st->ci[st->scrpos].dpyoff; 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) while (st->ci[st->pos].dpyoff - st->ci[st->scrpos].dpyoff > col - 2) {
{
pgskip = 0; pgskip = 0;
while (pgskip < pgsize && st->scrpos < st->len) while (pgskip < pgsize && st->scrpos < st->len) {
{
pgskip += st->ci[st->scrpos + 1].dpyoff - st->ci[st->scrpos].dpyoff; pgskip += st->ci[st->scrpos + 1].dpyoff - st->ci[st->scrpos].dpyoff;
st->scrpos++; st->scrpos++;
} }
@ -179,8 +167,7 @@ getstr_fixscr (struct getstr_status *st)
* environment, otherwise the cursor would move from place to place without * environment, otherwise the cursor would move from place to place without
* control. * control.
*/ */
enum getstr enum getstr getstring(WINDOW * win, char *str, int l, int x, int y)
getstring (WINDOW *win, char *str, int l, int x, int y)
{ {
struct getstr_status st; struct getstr_status st;
struct getstr_charinfo ci[l + 1]; struct getstr_charinfo ci[l + 1];
@ -188,112 +175,106 @@ getstring (WINDOW *win, char *str, int l, int x, int y)
int ch, k; int ch, k;
char c[UTF8_MAXLEN]; char c[UTF8_MAXLEN];
getstr_init (&st, str, ci); getstr_init(&st, str, ci);
custom_apply_attr (win, ATTR_HIGHEST); custom_apply_attr(win, ATTR_HIGHEST);
for (;;) { for (;;) {
getstr_fixscr (&st); getstr_fixscr(&st);
getstr_print (win, x, y, &st); getstr_print(win, x, y, &st);
wins_doupdate (); wins_doupdate();
if ((ch = wgetch (win)) == '\n') break; if ((ch = wgetch(win)) == '\n')
switch (ch) break;
{ switch (ch) {
case KEY_BACKSPACE: /* delete one character */ case KEY_BACKSPACE: /* delete one character */
case 330: case 330:
case 127: case 127:
case CTRL ('H'): 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) { if (st.pos > 0) {
while (st.pos && st.s[st.ci[st.pos - 1].offset] == ' ')
{
st.pos--; st.pos--;
getstr_del_char (&st); getstr_del_char(&st);
} } else
while (st.pos && st.s[st.ci[st.pos - 1].offset] != ' ') bell();
{
st.pos--;
getstr_del_char (&st);
}
}
else
bell ();
break; break;
case CTRL ('K'): /* delete to end-of-line */ 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.s[st.ci[st.pos].offset] = 0;
st.len = st.pos; st.len = st.pos;
break; break;
case CTRL ('A'): /* go to begginning of string */ case CTRL('A'): /* go to begginning of string */
st.pos = 0; st.pos = 0;
break; break;
case CTRL ('E'): /* go to end of string */ case CTRL('E'): /* go to end of string */
st.pos = st.len; st.pos = st.len;
break; break;
case KEY_LEFT: /* move one char backward */ case KEY_LEFT: /* move one char backward */
case CTRL ('B'): case CTRL('B'):
if (st.pos > 0) st.pos--; if (st.pos > 0)
st.pos--;
break; break;
case KEY_RIGHT: /* move one char forward */ case KEY_RIGHT: /* move one char forward */
case CTRL ('F'): case CTRL('F'):
if (st.pos < st.len) st.pos++; if (st.pos < st.len)
st.pos++;
break; break;
case ESCAPE: /* cancel editing */ case ESCAPE: /* cancel editing */
return GETSTRING_ESC; return GETSTRING_ESC;
break; break;
default: /* insert one character */ default: /* insert one character */
c[0] = ch; c[0] = ch;
for (k = 1; k < MIN (UTF8_LENGTH (c[0]), UTF8_MAXLEN); k++) for (k = 1; k < MIN(UTF8_LENGTH(c[0]), UTF8_MAXLEN); k++)
c[k] = (unsigned char)wgetch (win); c[k] = (unsigned char)wgetch(win);
if (st.ci[st.len].offset + k < l) if (st.ci[st.len].offset + k < l) {
{ getstr_ins_char(&st, c);
getstr_ins_char (&st, c);
st.pos++; st.pos++;
} }
} }
} }
custom_remove_attr (win, ATTR_HIGHEST); custom_remove_attr(win, ATTR_HIGHEST);
return st.len == 0 ? GETSTRING_RET : GETSTRING_VALID; return st.len == 0 ? GETSTRING_RET : GETSTRING_VALID;
} }
/* Update an already existing string. */ /* Update an already existing string. */
int int updatestring(WINDOW * win, char **str, int x, int y)
updatestring (WINDOW *win, char **str, int x, int y)
{ {
int len = strlen (*str); int len = strlen(*str);
char *buf; char *buf;
enum getstr ret; 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); buf = mem_malloc(BUFSIZ);
memcpy (buf, *str, len + 1); memcpy(buf, *str, len + 1);
ret = getstring (win, buf, BUFSIZ, x, y); ret = getstring(win, buf, BUFSIZ, x, y);
if (ret == GETSTRING_VALID) if (ret == GETSTRING_VALID) {
{ len = strlen(buf);
len = strlen (buf); *str = mem_realloc(*str, len + 1, 1);
*str = mem_realloc (*str, len + 1, 1); EXIT_IF(*str == NULL, _("out of memory"));
EXIT_IF (*str == NULL, _("out of memory")); memcpy(*str, buf, len + 1);
memcpy (*str, buf, len + 1);
} }
mem_free (buf); mem_free(buf);
return ret; return ret;
} }

View File

@ -48,8 +48,7 @@ typedef struct {
char text[HELPTEXTSIZ]; char text[HELPTEXTSIZ];
} help_page_t; } help_page_t;
typedef enum typedef enum {
{
HELP_MAIN, HELP_MAIN,
HELP_SAVE, HELP_SAVE,
HELP_IMPORT, HELP_IMPORT,
@ -74,18 +73,15 @@ typedef enum
HELP_CREDITS, HELP_CREDITS,
HELPSCREENS, HELPSCREENS,
NOPAGE NOPAGE
} } help_pages_e;
help_pages_e;
/* Returns the number of lines in an help text. */ /* Returns the number of lines in an help text. */
static int static int get_help_lines(char *text)
get_help_lines (char *text)
{ {
int i, newline; int i, newline;
newline = 0; newline = 0;
for (i = 0; text[i]; i++) for (i = 0; text[i]; i++) {
{
if (text[i] == '\n') if (text[i] == '\n')
newline++; newline++;
} }
@ -97,7 +93,7 @@ get_help_lines (char *text)
* of lines that were written. * of lines that were written.
*/ */
static int 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; int colnum, rownum;
const char *bindings_title = "key bindings: %s"; const char *bindings_title = "key bindings: %s";
@ -105,12 +101,11 @@ help_write_pad (struct window *win, char *title, char *text, enum key action)
colnum = 0; colnum = 0;
rownum = 0; rownum = 0;
erase_window_part (win->p, rownum, colnum, BUFSIZ, win->w); erase_window_part(win->p, rownum, colnum, BUFSIZ, win->w);
custom_apply_attr (win->p, ATTR_HIGHEST); custom_apply_attr(win->p, ATTR_HIGHEST);
mvwprintw (win->p, rownum, colnum, "%s", title); mvwprintw(win->p, rownum, colnum, "%s", title);
if ((int) action != KEY_RESIZE && action < NBKEYS) { if ((int)action != KEY_RESIZE && action < NBKEYS) {
switch (action) switch (action) {
{
case KEY_END_OF_WEEK: case KEY_END_OF_WEEK:
case KEY_START_OF_WEEK: case KEY_START_OF_WEEK:
case KEY_MOVE_UP: case KEY_MOVE_UP:
@ -131,20 +126,19 @@ help_write_pad (struct window *win, char *title, char *text, enum key action)
case KEY_GENERIC_PASTE: case KEY_GENERIC_PASTE:
break; break;
default: default:
bindings = keys_action_allkeys (action); bindings = keys_action_allkeys(action);
if (bindings) if (bindings) {
{ colnum = win->w - strlen(bindings_title) - strlen(bindings);
colnum = win->w - strlen (bindings_title) - strlen (bindings); mvwprintw(win->p, rownum, colnum, bindings_title, bindings);
mvwprintw (win->p, rownum, colnum, bindings_title, bindings);
} }
} }
} }
colnum = 0; colnum = 0;
rownum += get_help_lines (title); rownum += get_help_lines(title);
custom_remove_attr (win->p, ATTR_HIGHEST); custom_remove_attr(win->p, ATTR_HIGHEST);
mvwprintw (win->p, rownum, colnum, "%s", text); mvwprintw(win->p, rownum, colnum, "%s", text);
rownum += get_help_lines (text); rownum += get_help_lines(text);
return rownum; return rownum;
} }
@ -152,8 +146,7 @@ help_write_pad (struct window *win, char *title, char *text, enum key action)
* Create and init help screen and its pad, which is used to make the scrolling * Create and init help screen and its pad, which is used to make the scrolling
* faster. * faster.
*/ */
void void help_wins_init(struct scrollwin *hwin, int x, int y, int h, int w)
help_wins_init (struct scrollwin *hwin, int x, int y, int h, int w)
{ {
const int PADOFFSET = 4; const int PADOFFSET = 4;
const int TITLELINES = 3; const int TITLELINES = 3;
@ -169,48 +162,44 @@ help_wins_init (struct scrollwin *hwin, int x, int y, int h, int w)
hwin->pad.w = hwin->win.w - 2 * PADOFFSET + 1; hwin->pad.w = hwin->win.w - 2 * PADOFFSET + 1;
hwin->label = _("Calcurse help"); hwin->label = _("Calcurse help");
wins_scrollwin_init (hwin); wins_scrollwin_init(hwin);
wins_show (hwin->win.p, hwin->label); wins_show(hwin->win.p, hwin->label);
} }
/* /*
* Delete the existing windows and recreate them with their new * Delete the existing windows and recreate them with their new
* size and placement. * size and placement.
*/ */
static void static void help_wins_reinit(struct scrollwin *hwin)
help_wins_reinit (struct scrollwin *hwin)
{ {
wins_scrollwin_delete (hwin); wins_scrollwin_delete(hwin);
wins_get_config (); wins_get_config();
help_wins_init (hwin, 0, 0, (notify_bar ()) ? row - 3 : row - 2, col); help_wins_init(hwin, 0, 0, (notify_bar())? row - 3 : row - 2, col);
} }
/* Reset the screen, needed when resizing terminal for example. */ /* Reset the screen, needed when resizing terminal for example. */
static void static void help_wins_reset(struct scrollwin *hwin)
help_wins_reset (struct scrollwin *hwin)
{ {
endwin (); endwin();
wins_refresh (); wins_refresh();
curs_set (0); curs_set(0);
delwin (win[STA].p); delwin(win[STA].p);
help_wins_reinit (hwin); help_wins_reinit(hwin);
win[STA].p = newwin (win[STA].h, win[STA].w, win[STA].y, win[STA].x); win[STA].p = newwin(win[STA].h, win[STA].w, win[STA].y, win[STA].x);
keypad (win[STA].p, TRUE); keypad(win[STA].p, TRUE);
if (notify_bar ()) if (notify_bar())
notify_reinit_bar (); notify_reinit_bar();
wins_status_bar (); wins_status_bar();
if (notify_bar ()) if (notify_bar())
notify_update_bar (); notify_update_bar();
} }
/* Association between a key pressed and its corresponding help page. */ /* Association between a key pressed and its corresponding help page. */
static int static int wanted_page(int ch)
wanted_page (int ch)
{ {
int page; int page;
switch (ch) switch (ch) {
{
case KEY_GENERIC_HELP: case KEY_GENERIC_HELP:
page = HELP_MAIN; page = HELP_MAIN;
@ -323,8 +312,7 @@ wanted_page (int ch)
} }
/* Draws the help screen */ /* Draws the help screen */
void void help_screen(void)
help_screen (void)
{ {
enum { enum {
MOVE_UP, MOVE_UP,
@ -342,8 +330,9 @@ help_screen (void)
hscr[HELP_MAIN].title = hscr[HELP_MAIN].title =
_(" Welcome to Calcurse. This is the main help screen.\n"); _(" Welcome to Calcurse. This is the main help screen.\n");
snprintf (hscr[HELP_MAIN].text, HELPTEXTSIZ, snprintf(hscr[HELP_MAIN].text, HELPTEXTSIZ,
_("Moving around: Press '%s' or '%s' to scroll text upward or downward\n" _
("Moving around: Press '%s' or '%s' to scroll text upward or downward\n"
" inside help screens, if necessary.\n\n" " inside help screens, if necessary.\n\n"
" Exit help: When finished, press '%s' to exit help and go back to\n" " Exit help: When finished, press '%s' to exit help and go back to\n"
" the main Calcurse screen.\n\n" " the main Calcurse screen.\n\n"
@ -357,13 +346,13 @@ help_screen (void)
" description screen are indicated the user-defined key\n" " description screen are indicated the user-defined key\n"
" bindings that lead to the action.\n\n" " bindings that lead to the action.\n\n"
" Credits: Press '%s' for credits."), " Credits: Press '%s' for credits."),
keys_action_firstkey (KEY_GENERIC_SCROLL_UP), keys_action_firstkey(KEY_GENERIC_SCROLL_UP),
keys_action_firstkey (KEY_GENERIC_SCROLL_DOWN), keys_action_firstkey(KEY_GENERIC_SCROLL_DOWN),
keys_action_firstkey (KEY_GENERIC_QUIT), keys_action_firstkey(KEY_GENERIC_QUIT),
keys_action_firstkey (KEY_GENERIC_CREDITS)); keys_action_firstkey(KEY_GENERIC_CREDITS));
hscr[HELP_SAVE].title = _("Save\n"); hscr[HELP_SAVE].title = _("Save\n");
snprintf (hscr[HELP_SAVE].text, HELPTEXTSIZ, snprintf(hscr[HELP_SAVE].text, HELPTEXTSIZ,
_("Save calcurse data.\n" _("Save calcurse data.\n"
"Data are splitted into four different files which contain :" "Data are splitted into four different files which contain :"
"\n\n" "\n\n"
@ -376,7 +365,7 @@ help_screen (void)
"automatically before quitting.")); "automatically before quitting."));
hscr[HELP_IMPORT].title = _("Import\n"); hscr[HELP_IMPORT].title = _("Import\n");
snprintf (hscr[HELP_IMPORT].text, HELPTEXTSIZ, snprintf(hscr[HELP_IMPORT].text, HELPTEXTSIZ,
_("Import data from an icalendar file.\n" _("Import data from an icalendar file.\n"
"You will be asked to enter the file name from which to load ical\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" "items. At the end of the import process, and if the general option\n"
@ -394,7 +383,7 @@ help_screen (void)
"the item could not be imported.\n")); "the item could not be imported.\n"));
hscr[HELP_EXPORT].title = _("Export\n"); hscr[HELP_EXPORT].title = _("Export\n");
snprintf (hscr[HELP_EXPORT].text, HELPTEXTSIZ, snprintf(hscr[HELP_EXPORT].text, HELPTEXTSIZ,
_("Export calcurse data (appointments, events and todos).\n" _("Export calcurse data (appointments, events and todos).\n"
"This leads to the export submenu, from which you can choose between\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" "two different export formats: 'ical' and 'pcal'. Choosing one of\n"
@ -409,15 +398,12 @@ help_screen (void)
"Calcurse data are exported in the following order:\n" "Calcurse data are exported in the following order:\n"
" events, appointments, todos.\n")); " events, appointments, todos.\n"));
strncpy (keystr[MOVE_UP], keys_action_allkeys (KEY_MOVE_UP), BUFSIZ); strncpy(keystr[MOVE_UP], keys_action_allkeys(KEY_MOVE_UP), BUFSIZ);
strncpy (keystr[MOVE_DOWN], keys_action_allkeys (KEY_MOVE_DOWN), strncpy(keystr[MOVE_DOWN], keys_action_allkeys(KEY_MOVE_DOWN), BUFSIZ);
BUFSIZ); strncpy(keystr[MOVE_LEFT], keys_action_allkeys(KEY_MOVE_LEFT), BUFSIZ);
strncpy (keystr[MOVE_LEFT], keys_action_allkeys (KEY_MOVE_LEFT), strncpy(keystr[MOVE_RIGHT], keys_action_allkeys(KEY_MOVE_RIGHT), BUFSIZ);
BUFSIZ);
strncpy (keystr[MOVE_RIGHT], keys_action_allkeys (KEY_MOVE_RIGHT),
BUFSIZ);
hscr[HELP_DISPLACEMENT].title = _("Displacement keys\n"); hscr[HELP_DISPLACEMENT].title = _("Displacement keys\n");
snprintf (hscr[HELP_DISPLACEMENT].text, HELPTEXTSIZ, snprintf(hscr[HELP_DISPLACEMENT].text, HELPTEXTSIZ,
_("Move around inside calcurse screens.\n" _("Move around inside calcurse screens.\n"
"The following scheme summarizes how to get around:\n\n" "The following scheme summarizes how to get around:\n\n"
" move up\n" " move up\n"
@ -440,12 +426,13 @@ help_screen (void)
"the week.\n"), "the week.\n"),
keystr[MOVE_UP], keystr[MOVE_LEFT], keystr[MOVE_UP], keystr[MOVE_LEFT],
keystr[MOVE_RIGHT], keystr[MOVE_DOWN], keystr[MOVE_RIGHT], keystr[MOVE_DOWN],
keys_action_firstkey (KEY_START_OF_WEEK), keys_action_firstkey(KEY_START_OF_WEEK),
keys_action_firstkey (KEY_END_OF_WEEK)); keys_action_firstkey(KEY_END_OF_WEEK));
hscr[HELP_VIEW].title = _("View\n"); hscr[HELP_VIEW].title = _("View\n");
snprintf (hscr[HELP_VIEW].text, HELPTEXTSIZ, snprintf(hscr[HELP_VIEW].text, HELPTEXTSIZ,
_("View the item you select in either the Todo or Appointment panel.\n" _
("View the item you select in either the Todo or Appointment panel.\n"
"\nThis is usefull when an event description is longer than the " "\nThis is usefull when an event description is longer than the "
"available\nspace to display it. " "available\nspace to display it. "
"If that is the case, the description will be\n" "If that is the case, the description will be\n"
@ -453,19 +440,18 @@ help_screen (void)
"description, just press '%s' and a popup window will appear, containing\n" "description, just press '%s' and a popup window will appear, containing\n"
"the whole event.\n" "the whole event.\n"
"\nPress any key to close the popup window and go back to the main\n" "\nPress any key to close the popup window and go back to the main\n"
"Calcurse screen."), "Calcurse screen."), keys_action_firstkey(KEY_VIEW_ITEM));
keys_action_firstkey (KEY_VIEW_ITEM));
hscr[HELP_PIPE].title = _("Pipe\n"); hscr[HELP_PIPE].title = _("Pipe\n");
snprintf (hscr[HELP_PIPE].text, HELPTEXTSIZ, snprintf(hscr[HELP_PIPE].text, HELPTEXTSIZ,
_("Pipe the selected item to an external program.\n" _("Pipe the selected item to an external program.\n"
"\nPress the '%s' key to pipe the currently selected appointment or\n" "\nPress the '%s' key to pipe the currently selected appointment or\n"
"todo entry to an external program.\n" "todo entry to an external program.\n"
"\nYou will be driven back to calcurse as soon as the program exits.\n"), "\nYou will be driven back to calcurse as soon as the program exits.\n"),
keys_action_firstkey (KEY_PIPE_ITEM)); keys_action_firstkey(KEY_PIPE_ITEM));
hscr[HELP_TAB].title = _("Tab\n"); hscr[HELP_TAB].title = _("Tab\n");
snprintf (hscr[HELP_TAB].text, HELPTEXTSIZ, snprintf(hscr[HELP_TAB].text, HELPTEXTSIZ,
_("Switch between panels.\n" _("Switch between panels.\n"
"The panel currently in use has its border colorized.\n" "The panel currently in use has its border colorized.\n"
"\nSome actions are possible only if the right panel is selected.\n" "\nSome actions are possible only if the right panel is selected.\n"
@ -475,12 +461,12 @@ help_screen (void)
"\nNotice that at the bottom of the screen the list of possible actions\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" "change while pressing '%s', so you always know what action can be\n"
"performed on the selected panel."), "performed on the selected panel."),
keys_action_firstkey (KEY_GENERIC_CHANGE_VIEW), keys_action_firstkey(KEY_GENERIC_CHANGE_VIEW),
keys_action_firstkey (KEY_ADD_ITEM), keys_action_firstkey(KEY_ADD_ITEM),
keys_action_firstkey (KEY_GENERIC_CHANGE_VIEW)); keys_action_firstkey(KEY_GENERIC_CHANGE_VIEW));
hscr[HELP_GOTO].title = _("Goto\n"); hscr[HELP_GOTO].title = _("Goto\n");
snprintf (hscr[HELP_GOTO].text, HELPTEXTSIZ, snprintf(hscr[HELP_GOTO].text, HELPTEXTSIZ,
_("Jump to a specific day in the calendar.\n" _("Jump to a specific day in the calendar.\n"
"\nUsing this command, you do not need to travel to that day using\n" "\nUsing this command, you do not need to travel to that day using\n"
"the displacement keys inside the calendar panel.\n" "the displacement keys inside the calendar panel.\n"
@ -488,10 +474,10 @@ help_screen (void)
"system current date and you will be taken to that date.\n" "system current date and you will be taken to that date.\n"
"\nNotice that pressing '%s', whatever panel is\n" "\nNotice that pressing '%s', whatever panel is\n"
"selected, will select current day in the calendar."), "selected, will select current day in the calendar."),
keys_action_firstkey (KEY_GENERIC_GOTO_TODAY)); keys_action_firstkey(KEY_GENERIC_GOTO_TODAY));
hscr[HELP_DELETE].title = _("Delete\n"); hscr[HELP_DELETE].title = _("Delete\n");
snprintf (hscr[HELP_DELETE].text, HELPTEXTSIZ, snprintf(hscr[HELP_DELETE].text, HELPTEXTSIZ,
_("Delete an element in the ToDo or Appointment list.\n" _("Delete an element in the ToDo or Appointment list.\n"
"\nDepending on which panel is selected when you press the delete key,\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" "the hilighted item of either the ToDo or Appointment list will be \n"
@ -505,8 +491,9 @@ help_screen (void)
"next time you launch Calcurse.")); "next time you launch Calcurse."));
hscr[HELP_ADD].title = _("Add\n"); hscr[HELP_ADD].title = _("Add\n");
snprintf (hscr[HELP_ADD].text, HELPTEXTSIZ, snprintf(hscr[HELP_ADD].text, HELPTEXTSIZ,
_("Add an item in either the ToDo or Appointment list, depending on which\n" _
("Add an item in either the ToDo or Appointment list, depending on which\n"
"panel is selected when you press '%s'.\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" "\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 " "\ndescription of this new item. Then you will be asked to specify the "
@ -535,15 +522,16 @@ help_screen (void)
" added.\n" " added.\n"
" o do not forget to save the calendar data to retrieve the new\n" " o do not forget to save the calendar data to retrieve the new\n"
" event next time you launch Calcurse."), " event next time you launch Calcurse."),
keys_action_firstkey (KEY_ADD_ITEM), keys_action_firstkey(KEY_ADD_ITEM),
keys_action_firstkey (KEY_RAISE_PRIORITY), keys_action_firstkey(KEY_RAISE_PRIORITY),
keys_action_firstkey (KEY_LOWER_PRIORITY), keys_action_firstkey(KEY_LOWER_PRIORITY),
keys_action_firstkey (KEY_ADD_ITEM), keys_action_firstkey(KEY_ADD_ITEM),
keys_action_firstkey (KEY_ADD_ITEM)); keys_action_firstkey(KEY_ADD_ITEM));
hscr[HELP_CUT_PASTE].title = _("Cut and Paste\n"); hscr[HELP_CUT_PASTE].title = _("Cut and Paste\n");
snprintf (hscr[HELP_CUT_PASTE].text, HELPTEXTSIZ, snprintf(hscr[HELP_CUT_PASTE].text, HELPTEXTSIZ,
_("Cut and paste the currently selected item. This is useful to quickly\n" _
("Cut and paste the currently selected item. This is useful to quickly\n"
"move an item from one date to another.\n" "move an item from one date to another.\n"
"To do so, one must first highlight the item that needs to be moved,\n" "To do so, one must first highlight the item that needs to be moved,\n"
"then press '%s' to cut this item. It will be removed from the panel.\n" "then press '%s' to cut this item. It will be removed from the panel.\n"
@ -554,11 +542,11 @@ help_screen (void)
"Be careful that if two cuts are performed successively without pasting\n" "Be careful that if two cuts are performed successively without pasting\n"
"between them, the item that was cut at first will be lost, together\n" "between them, the item that was cut at first will be lost, together\n"
"with its associated note if it had one."), "with its associated note if it had one."),
keys_action_firstkey (KEY_GENERIC_CUT), keys_action_firstkey(KEY_GENERIC_CUT),
keys_action_firstkey (KEY_GENERIC_PASTE)); keys_action_firstkey(KEY_GENERIC_PASTE));
hscr[HELP_EDIT].title = _("Edit Item\n"); hscr[HELP_EDIT].title = _("Edit Item\n");
snprintf (hscr[HELP_EDIT].text, HELPTEXTSIZ, snprintf(hscr[HELP_EDIT].text, HELPTEXTSIZ,
_("Edit the item which is currently selected.\n" _("Edit the item which is currently selected.\n"
"Depending on the item type (appointment, event, or todo), and if it is\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" "repeated or not, you will be asked to choose one of the item properties"
@ -575,8 +563,9 @@ help_screen (void)
" modified properties next time you launch Calcurse.")); " modified properties next time you launch Calcurse."));
hscr[HELP_ENOTE].title = _("EditNote\n"); hscr[HELP_ENOTE].title = _("EditNote\n");
snprintf (hscr[HELP_ENOTE].text, HELPTEXTSIZ, snprintf(hscr[HELP_ENOTE].text, HELPTEXTSIZ,
_("Attach a note to any type of item, or edit an already existing note.\n" _
("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" "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" "of your item description, or if you would like to add sub-tasks to an\n"
"already existing todo item for example.\n" "already existing todo item for example.\n"
@ -593,30 +582,30 @@ help_screen (void)
"\nOnce the item note is edited and saved, quit your favorite editor.\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" "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."), "\nof the highlighted item, meaning there is a note attached to it."),
keys_action_firstkey (KEY_EDIT_NOTE)); keys_action_firstkey(KEY_EDIT_NOTE));
hscr[HELP_VNOTE].title = _("ViewNote\n"); hscr[HELP_VNOTE].title = _("ViewNote\n");
snprintf (hscr[HELP_VNOTE].text, HELPTEXTSIZ, snprintf(hscr[HELP_VNOTE].text, HELPTEXTSIZ,
_("View a note which was previously attached to an item (an item which\n" _
("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" "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" "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" "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" "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 " "\nwas pressed, you will be driven to an external pager to view that "
"note.\n" "note.\n" "The default pager is chosen the following way:\n"
"The default pager is chosen the following way:\n"
" o if the 'PAGER' environment variable is set, then this will be\n" " o if the 'PAGER' environment variable is set, then this will be\n"
" the default viewer to be called.\n" " the default viewer to be called.\n"
" o if the above environment variable is not set, then\n" " o if the above environment variable is not set, then\n"
" '/usr/bin/less' will be used.\n" " '/usr/bin/less' will be used.\n"
"As for editing a note, quit the pager and you will be driven back to\n" "As for editing a note, quit the pager and you will be driven back to\n"
"Calcurse."), "Calcurse."), keys_action_firstkey(KEY_EDIT_NOTE),
keys_action_firstkey (KEY_EDIT_NOTE), keys_action_firstkey(KEY_VIEW_NOTE));
keys_action_firstkey (KEY_VIEW_NOTE));
hscr[HELP_PRIORITY].title = _("Priority\n"); hscr[HELP_PRIORITY].title = _("Priority\n");
snprintf (hscr[HELP_PRIORITY].text, HELPTEXTSIZ, snprintf(hscr[HELP_PRIORITY].text, HELPTEXTSIZ,
_("Change the priority of the currently selected item in the ToDo list.\n" _
("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" "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" "todo description. This number goes from 9 for the lowest priority to\n"
"1 for the highest priority.\n" "1 for the highest priority.\n"
@ -629,11 +618,11 @@ help_screen (void)
"panel may change,\ndepending on the priority of the items above it.\n\n" "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" "At the opposite, to lower a todo priority, press '%s'. The todo position"
"\nmay also change depending on the priority of the items below."), "\nmay also change depending on the priority of the items below."),
keys_action_firstkey (KEY_RAISE_PRIORITY), keys_action_firstkey(KEY_RAISE_PRIORITY),
keys_action_firstkey (KEY_LOWER_PRIORITY)); keys_action_firstkey(KEY_LOWER_PRIORITY));
hscr[HELP_REPEAT].title = _("Repeat\n"); hscr[HELP_REPEAT].title = _("Repeat\n");
snprintf (hscr[HELP_REPEAT].text, HELPTEXTSIZ, snprintf(hscr[HELP_REPEAT].text, HELPTEXTSIZ,
_("Repeat an event or an appointment.\n" _("Repeat an event or an appointment.\n"
"You must first select the item to be repeated by moving inside the\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" "appointment panel. Then pressing '%s' will lead you to a set of three\n"
@ -657,11 +646,12 @@ help_screen (void)
" o the 'Repeat' and 'Delete' command can be mixed to create\n" " o the 'Repeat' and 'Delete' command can be mixed to create\n"
" complicated configurations, as it is possible to delete only\n" " complicated configurations, as it is possible to delete only\n"
" one occurence of a repeated item."), " one occurence of a repeated item."),
keys_action_firstkey (KEY_REPEAT_ITEM)); keys_action_firstkey(KEY_REPEAT_ITEM));
hscr[HELP_FLAG].title = _("Flag Item\n"); hscr[HELP_FLAG].title = _("Flag Item\n");
snprintf (hscr[HELP_FLAG].text, HELPTEXTSIZ, snprintf(hscr[HELP_FLAG].text, HELPTEXTSIZ,
_("Toggle an appointment's 'important' flag or a todo's 'completed' flag.\n" _
("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" "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" "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" "or when using the '-t' command line flag (unless specifying '0' as the\n"
@ -674,7 +664,7 @@ help_screen (void)
"\nand how long before it he gets notified.")); "\nand how long before it he gets notified."));
hscr[HELP_CONFIG].title = _("Config\n"); hscr[HELP_CONFIG].title = _("Config\n");
snprintf (hscr[HELP_CONFIG].text, HELPTEXTSIZ, snprintf(hscr[HELP_CONFIG].text, HELPTEXTSIZ,
_("Open the configuration submenu.\n" _("Open the configuration submenu.\n"
"From this submenu, you can select between color, layout, notification\n" "From this submenu, you can select between color, layout, notification\n"
"and general options, and you can also configure your keybindings.\n" "and general options, and you can also configure your keybindings.\n"
@ -689,8 +679,9 @@ help_screen (void)
"\nnext time you launch Calcurse.")); "\nnext time you launch Calcurse."));
hscr[HELP_GENERAL].title = _("Generic keybindings\n"); hscr[HELP_GENERAL].title = _("Generic keybindings\n");
snprintf (hscr[HELP_GENERAL].text, HELPTEXTSIZ, snprintf(hscr[HELP_GENERAL].text, HELPTEXTSIZ,
_("Some of the keybindings apply whatever panel is selected. They are\n" _
("Some of the keybindings apply whatever panel is selected. They are\n"
"called generic keybinding.\n" "called generic keybinding.\n"
"Here is the list of all the generic key bindings, together with their\n" "Here is the list of all the generic key bindings, together with their\n"
"corresponding action:\n\n" "corresponding action:\n\n"
@ -708,30 +699,30 @@ help_screen (void)
"when inside specific screens such the help screens for example.\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" "They are also used when the calendar screen is selected to switch\n"
"between the available views (monthly and weekly calendar views)."), "between the available views (monthly and weekly calendar views)."),
keys_action_firstkey (KEY_GENERIC_REDRAW), keys_action_firstkey(KEY_GENERIC_REDRAW),
keys_action_firstkey (KEY_GENERIC_ADD_APPT), keys_action_firstkey(KEY_GENERIC_ADD_APPT),
keys_action_firstkey (KEY_GENERIC_ADD_TODO), keys_action_firstkey(KEY_GENERIC_ADD_TODO),
keys_action_firstkey (KEY_GENERIC_PREV_DAY), keys_action_firstkey(KEY_GENERIC_PREV_DAY),
keys_action_firstkey (KEY_GENERIC_NEXT_DAY), keys_action_firstkey(KEY_GENERIC_NEXT_DAY),
keys_action_firstkey (KEY_GENERIC_PREV_WEEK), keys_action_firstkey(KEY_GENERIC_PREV_WEEK),
keys_action_firstkey (KEY_GENERIC_NEXT_WEEK), keys_action_firstkey(KEY_GENERIC_NEXT_WEEK),
keys_action_firstkey (KEY_GENERIC_GOTO_TODAY), keys_action_firstkey(KEY_GENERIC_GOTO_TODAY),
keys_action_firstkey (KEY_GENERIC_SCROLL_UP), keys_action_firstkey(KEY_GENERIC_SCROLL_UP),
keys_action_firstkey (KEY_GENERIC_SCROLL_DOWN)); keys_action_firstkey(KEY_GENERIC_SCROLL_DOWN));
hscr[HELP_OTHER].title = _("OtherCmd\n"); hscr[HELP_OTHER].title = _("OtherCmd\n");
snprintf (hscr[HELP_OTHER].text, HELPTEXTSIZ, snprintf(hscr[HELP_OTHER].text, HELPTEXTSIZ,
_("Switch between status bar help pages.\n" _("Switch between status bar help pages.\n"
"Because the terminal screen is too narrow to display all of the\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" "available commands, you need to press '%s' to see the next set of\n"
"commands together with their keybindings.\n" "commands together with their keybindings.\n"
"Once the last status bar page is reached, pressing '%s' another time\n" "Once the last status bar page is reached, pressing '%s' another time\n"
"leads you back to the first page."), "leads you back to the first page."),
keys_action_firstkey (KEY_GENERIC_OTHER_CMD), keys_action_firstkey(KEY_GENERIC_OTHER_CMD),
keys_action_firstkey (KEY_GENERIC_OTHER_CMD)); keys_action_firstkey(KEY_GENERIC_OTHER_CMD));
hscr[HELP_CREDITS].title = _("Calcurse - text-based organizer"); hscr[HELP_CREDITS].title = _("Calcurse - text-based organizer");
snprintf (hscr[HELP_CREDITS].text, HELPTEXTSIZ, snprintf(hscr[HELP_CREDITS].text, HELPTEXTSIZ,
_("\nCopyright (c) 2004-2012 calcurse Development Team\n" _("\nCopyright (c) 2004-2012 calcurse Development Team\n"
"All rights reserved.\n" "All rights reserved.\n"
"\n" "\n"
@ -751,50 +742,47 @@ help_screen (void)
"Send your feedback or comments to : misc@calcurse.org\n" "Send your feedback or comments to : misc@calcurse.org\n"
"Calcurse home page : http://calcurse.org")); "Calcurse home page : http://calcurse.org"));
help_wins_init (&hwin, 0, 0, (notify_bar ()) ? row - 3 : row - 2, col); help_wins_init(&hwin, 0, 0, (notify_bar())? row - 3 : row - 2, col);
oldpage = HELP_MAIN; oldpage = HELP_MAIN;
need_resize = 0; need_resize = 0;
/* Display the help screen related to user input. */ /* Display the help screen related to user input. */
while (ch != KEY_GENERIC_QUIT) while (ch != KEY_GENERIC_QUIT) {
{ erase_window_part(hwin.win.p, 1, hwin.pad.y, col - 2, hwin.win.h - 2);
erase_window_part (hwin.win.p, 1, hwin.pad.y, col - 2,
hwin.win.h - 2);
switch (ch) { switch (ch) {
case KEY_GENERIC_SCROLL_DOWN: case KEY_GENERIC_SCROLL_DOWN:
wins_scrollwin_down (&hwin, 1); wins_scrollwin_down(&hwin, 1);
break; break;
case KEY_GENERIC_SCROLL_UP: case KEY_GENERIC_SCROLL_UP:
wins_scrollwin_up (&hwin, 1); wins_scrollwin_up(&hwin, 1);
break; break;
default: default:
page = wanted_page (ch); page = wanted_page(ch);
if (page != NOPAGE) { if (page != NOPAGE) {
hwin.first_visible_line = 0; hwin.first_visible_line = 0;
hwin.total_lines = help_write_pad (&hwin.pad, hscr[page].title, hwin.total_lines = help_write_pad(&hwin.pad, hscr[page].title,
hscr[page].text, ch); hscr[page].text, ch);
oldpage = page; oldpage = page;
} }
} }
if (resize) if (resize) {
{
resize = 0; resize = 0;
wins_get_config (); wins_get_config();
help_wins_reset (&hwin); help_wins_reset(&hwin);
hwin.first_visible_line = 0; hwin.first_visible_line = 0;
hwin.total_lines = help_write_pad (&hwin.pad, hscr[oldpage].title, hwin.total_lines = help_write_pad(&hwin.pad, hscr[oldpage].title,
hscr[oldpage].text, ch); hscr[oldpage].text, ch);
need_resize = 1; need_resize = 1;
} }
wins_scrollwin_display (&hwin); wins_scrollwin_display(&hwin);
ch = keys_getch (win[STA].p, NULL); ch = keys_getch(win[STA].p, NULL);
} }
wins_scrollwin_delete (&hwin); wins_scrollwin_delete(&hwin);
if (need_resize) if (need_resize)
wins_reset (); wins_reset();
} }

File diff suppressed because it is too large Load Diff

1107
src/io.c

File diff suppressed because it is too large Load Diff

View File

@ -94,8 +94,7 @@ static struct keydef_s keydef[NBKEYS] = {
{"lower-priority", "-"}, {"lower-priority", "-"},
}; };
static void static void dump_intro(FILE * fd)
dump_intro (FILE *fd)
{ {
const char *intro = const char *intro =
_("#\n" _("#\n"
@ -119,64 +118,56 @@ dump_intro (FILE *fd)
"# A description of what each ACTION keyword is used for is available\n" "# A description of what each ACTION keyword is used for is available\n"
"# from calcurse online configuration menu.\n"); "# from calcurse online configuration menu.\n");
fprintf (fd, "%s\n", intro); fprintf(fd, "%s\n", intro);
} }
void void keys_init(void)
keys_init (void)
{ {
int i; int i;
for (i = 0; i < MAXKEYVAL; i++) for (i = 0; i < MAXKEYVAL; i++)
actions[i] = KEY_UNDEF; actions[i] = KEY_UNDEF;
for (i = 0; i < NBKEYS; i++) for (i = 0; i < NBKEYS; i++)
LLIST_INIT (&keys[i]); LLIST_INIT(&keys[i]);
} }
static void static void key_free(char *s)
key_free (char *s)
{ {
mem_free (s); mem_free(s);
} }
void void keys_free(void)
keys_free (void)
{ {
int i; int i;
for (i = 0; i < NBKEYS; i++) for (i = 0; i < NBKEYS; i++) {
{ LLIST_FREE_INNER(&keys[i], key_free);
LLIST_FREE_INNER (&keys[i], key_free); LLIST_FREE(&keys[i]);
LLIST_FREE (&keys[i]);
} }
} }
void void keys_dump_defaults(char *file)
keys_dump_defaults (char *file)
{ {
FILE *fd; FILE *fd;
int i; int i;
fd = fopen (file, "w"); fd = fopen(file, "w");
EXIT_IF (fd == NULL, _("FATAL ERROR: could not create default keys file.")); EXIT_IF(fd == NULL, _("FATAL ERROR: could not create default keys file."));
dump_intro (fd); dump_intro(fd);
for (i = 0; i < NBKEYS; i++) for (i = 0; i < NBKEYS; i++)
fprintf (fd, "%s %s\n", keydef[i].label, keydef[i].binding); fprintf(fd, "%s %s\n", keydef[i].label, keydef[i].binding);
file_close (fd, __FILE_POS__); file_close(fd, __FILE_POS__);
} }
const char * const char *keys_get_label(enum key key)
keys_get_label (enum key key)
{ {
EXIT_IF (key < 0 || key > NBKEYS, EXIT_IF(key < 0 || key > NBKEYS, _("FATAL ERROR: key value out of bounds"));
_("FATAL ERROR: key value out of bounds"));
return keydef[key].label; return keydef[key].label;
} }
enum key enum key keys_get_action(int pressed)
keys_get_action (int pressed)
{ {
if (pressed < 0 || pressed > MAXKEYVAL) if (pressed < 0 || pressed > MAXKEYVAL)
return -1; return -1;
@ -184,61 +175,52 @@ keys_get_action (int pressed)
return actions[pressed]; return actions[pressed];
} }
enum key enum key keys_getch(WINDOW * win, int *count)
keys_getch (WINDOW *win, int *count)
{ {
int ch = '0'; int ch = '0';
if (count) if (count) {
{
*count = 0; *count = 0;
do do {
{
*count = *count * 10 + ch - '0'; *count = *count * 10 + ch - '0';
ch = wgetch (win); ch = wgetch(win);
} }
while ((ch == '0' && *count > 0) || (ch >= '1' && ch <= '9')); while ((ch == '0' && *count > 0) || (ch >= '1' && ch <= '9'));
if (*count == 0) if (*count == 0)
*count = 1; *count = 1;
} } else
else ch = wgetch(win);
ch = wgetch (win);
switch (ch) switch (ch) {
{
case KEY_RESIZE: case KEY_RESIZE:
return KEY_RESIZE; return KEY_RESIZE;
default: default:
return keys_get_action (ch); return keys_get_action(ch);
} }
} }
static void static void add_key_str(enum key action, int key)
add_key_str (enum key action, int key)
{ {
if (action < 0 || action > NBKEYS) if (action < 0 || action > NBKEYS)
return; return;
LLIST_ADD (&keys[action], mem_strdup (keys_int2str (key))); LLIST_ADD(&keys[action], mem_strdup(keys_int2str(key)));
} }
int int keys_assign_binding(int key, enum key action)
keys_assign_binding (int key, enum key action)
{ {
if (key < 0 || key > MAXKEYVAL || actions[key] != KEY_UNDEF) if (key < 0 || key > MAXKEYVAL || actions[key] != KEY_UNDEF)
return 1; return 1;
else else {
{
actions[key] = action; actions[key] = action;
add_key_str (action, key); add_key_str(action, key);
} }
return 0; return 0;
} }
static void static void del_key_str(enum key action, int key)
del_key_str (enum key action, int key)
{ {
llist_item_t *i; llist_item_t *i;
char oldstr[BUFSIZ]; char oldstr[BUFSIZ];
@ -246,30 +228,25 @@ del_key_str (enum key action, int key)
if (action < 0 || action > NBKEYS) if (action < 0 || action > NBKEYS)
return; return;
strncpy (oldstr, keys_int2str (key), BUFSIZ); strncpy(oldstr, keys_int2str(key), BUFSIZ);
LLIST_FOREACH (&keys[action], i) LLIST_FOREACH(&keys[action], i) {
{ if (strcmp(LLIST_GET_DATA(i), oldstr) == 0) {
if (strcmp (LLIST_GET_DATA (i), oldstr) == 0) LLIST_REMOVE(&keys[action], i);
{
LLIST_REMOVE (&keys[action], i);
return; return;
} }
} }
} }
void void keys_remove_binding(int key, enum key action)
keys_remove_binding (int key, enum key action)
{ {
if (key >= 0 && key <= MAXKEYVAL) if (key >= 0 && key <= MAXKEYVAL) {
{
actions[key] = KEY_UNDEF; actions[key] = KEY_UNDEF;
del_key_str (action, key); del_key_str(action, key);
} }
} }
int int keys_str2int(const char *key)
keys_str2int (const char *key)
{ {
const char CONTROL_KEY[] = "C-"; const char CONTROL_KEY[] = "C-";
const char TAB_KEY[] = "TAB"; const char TAB_KEY[] = "TAB";
@ -284,42 +261,39 @@ keys_str2int (const char *key)
if (!key) if (!key)
return -1; return -1;
if (strlen (key) == 1) if (strlen(key) == 1)
return (int)key[0]; return (int)key[0];
else else {
{
if (key[0] == '^') if (key[0] == '^')
return CTRL ((int)key[1]); return CTRL((int)key[1]);
else if (!strncmp (key, CONTROL_KEY, sizeof (CONTROL_KEY) - 1)) else if (!strncmp(key, CONTROL_KEY, sizeof(CONTROL_KEY) - 1))
return CTRL ((int)key[sizeof (CONTROL_KEY) - 1]); return CTRL((int)key[sizeof(CONTROL_KEY) - 1]);
else if (!strcmp (key, TAB_KEY)) else if (!strcmp(key, TAB_KEY))
return TAB; return TAB;
else if (!strcmp (key, ESCAPE_KEY)) else if (!strcmp(key, ESCAPE_KEY))
return ESCAPE; return ESCAPE;
else if (!strcmp (key, SPACE_KEY)) else if (!strcmp(key, SPACE_KEY))
return SPACE; return SPACE;
else if (!strcmp (key, CURSES_KEY_UP)) else if (!strcmp(key, CURSES_KEY_UP))
return KEY_UP; return KEY_UP;
else if (!strcmp (key, CURSES_KEY_DOWN)) else if (!strcmp(key, CURSES_KEY_DOWN))
return KEY_DOWN; return KEY_DOWN;
else if (!strcmp (key, CURSES_KEY_LEFT)) else if (!strcmp(key, CURSES_KEY_LEFT))
return KEY_LEFT; return KEY_LEFT;
else if (!strcmp (key, CURSES_KEY_RIGHT)) else if (!strcmp(key, CURSES_KEY_RIGHT))
return KEY_RIGHT; return KEY_RIGHT;
else if (!strcmp (key, CURSES_KEY_HOME)) else if (!strcmp(key, CURSES_KEY_HOME))
return KEY_HOME; return KEY_HOME;
else if (!strcmp (key, CURSES_KEY_END)) else if (!strcmp(key, CURSES_KEY_END))
return KEY_END; return KEY_END;
else else
return -1; return -1;
} }
} }
const char * const char *keys_int2str(int key)
keys_int2str (int key)
{ {
switch (key) switch (key) {
{
case TAB: case TAB:
return "TAB"; return "TAB";
case SPACE: case SPACE:
@ -339,79 +313,70 @@ keys_int2str (int key)
case KEY_END: case KEY_END:
return "KEY_END"; return "KEY_END";
default: default:
return (char *)keyname (key); return (char *)keyname(key);
} }
} }
int int keys_action_count_keys(enum key action)
keys_action_count_keys (enum key action)
{ {
llist_item_t *i; llist_item_t *i;
int n = 0; int n = 0;
LLIST_FOREACH (&keys[action], i) LLIST_FOREACH(&keys[action], i)
n++; n++;
return n; return n;
} }
const char * const char *keys_action_firstkey(enum key action)
keys_action_firstkey (enum key action)
{ {
const char *s = LLIST_GET_DATA (LLIST_FIRST (&keys[action])); const char *s = LLIST_GET_DATA(LLIST_FIRST(&keys[action]));
return (s != NULL) ? s : "XXX"; return (s != NULL) ? s : "XXX";
} }
const char * const char *keys_action_nkey(enum key action, int keynum)
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 * char *keys_action_allkeys(enum key action)
keys_action_allkeys (enum key action)
{ {
llist_item_t *i; llist_item_t *i;
static char keystr[BUFSIZ]; static char keystr[BUFSIZ];
const char *CHAR_SPACE = " "; const char *CHAR_SPACE = " ";
if (!LLIST_FIRST (&keys[action])) if (!LLIST_FIRST(&keys[action]))
return NULL; return NULL;
keystr[0] = '\0'; keystr[0] = '\0';
LLIST_FOREACH (&keys[action], i) LLIST_FOREACH(&keys[action], i) {
{ const int MAXLEN = sizeof(keystr) - 1 - strlen(keystr);
const int MAXLEN = sizeof (keystr) - 1 - strlen (keystr); strncat(keystr, LLIST_GET_DATA(i), MAXLEN - 1);
strncat (keystr, LLIST_GET_DATA (i), MAXLEN - 1); strncat(keystr, CHAR_SPACE, 1);
strncat (keystr, CHAR_SPACE, 1);
} }
return keystr; return keystr;
} }
/* Need this to display keys properly inside status bar. */ /* Need this to display keys properly inside status bar. */
static char * static char *keys_format_label(char *key, int keylen)
keys_format_label (char *key, int keylen)
{ {
static char fmtkey[BUFSIZ]; static char fmtkey[BUFSIZ];
const int len = strlen (key); const int len = strlen(key);
const char dot = '.'; const char dot = '.';
int i; int i;
if (keylen > BUFSIZ) if (keylen > BUFSIZ)
return NULL; return NULL;
memset (fmtkey, 0, sizeof(fmtkey)); memset(fmtkey, 0, sizeof(fmtkey));
if (len == 0) if (len == 0)
strncpy (fmtkey, "?", sizeof (fmtkey)); strncpy(fmtkey, "?", sizeof(fmtkey));
else if (len <= keylen) else if (len <= keylen) {
{
for (i = 0; i < keylen - len; i++) for (i = 0; i < keylen - len; i++)
fmtkey[i] = ' '; fmtkey[i] = ' ';
strncat (fmtkey, key, keylen); strncat(fmtkey, key, keylen);
} } else {
else
{
for (i = 0; i < keylen - 1; i++) for (i = 0; i < keylen - 1; i++)
fmtkey[i] = key[i]; fmtkey[i] = key[i];
fmtkey[keylen - 1] = dot; fmtkey[keylen - 1] = dot;
@ -420,7 +385,7 @@ keys_format_label (char *key, int keylen)
} }
void void
keys_display_bindings_bar (WINDOW *win, struct binding *bindings[], int count, keys_display_bindings_bar(WINDOW * win, struct binding *bindings[], int count,
int page_base, int page_size, struct binding *more) int page_base, int page_size, struct binding *more)
{ {
/* Padding between two key bindings. */ /* Padding between two key bindings. */
@ -430,9 +395,8 @@ keys_display_bindings_bar (WINDOW *win, struct binding *bindings[], int count,
int i; int i;
wins_erase_status_bar (); wins_erase_status_bar();
for (i = 0; i < page_size && page_base + i < count; i++) for (i = 0; i < page_size && page_base + i < count; i++) {
{
/* Location of key and label. */ /* Location of key and label. */
const int key_pos_x = (i / 2) * cmd_len; const int key_pos_x = (i / 2) * cmd_len;
const int key_pos_y = i % 2; const int key_pos_y = i % 2;
@ -447,58 +411,46 @@ keys_display_bindings_bar (WINDOW *win, struct binding *bindings[], int count,
else else
binding = more; binding = more;
strncpy (key, keys_action_firstkey (binding->action), KEYS_KEYLEN); strncpy(key, keys_action_firstkey(binding->action), KEYS_KEYLEN);
key[KEYS_KEYLEN] = '\0'; key[KEYS_KEYLEN] = '\0';
fmtkey = keys_format_label (key, KEYS_KEYLEN); fmtkey = keys_format_label(key, KEYS_KEYLEN);
custom_apply_attr (win, ATTR_HIGHEST); custom_apply_attr(win, ATTR_HIGHEST);
mvwprintw (win, key_pos_y, key_pos_x, fmtkey); mvwprintw(win, key_pos_y, key_pos_x, fmtkey);
custom_remove_attr (win, ATTR_HIGHEST); custom_remove_attr(win, ATTR_HIGHEST);
mvwprintw (win, label_pos_y, label_pos_x, binding->label); mvwprintw(win, label_pos_y, label_pos_x, binding->label);
} }
wnoutrefresh (win); wnoutrefresh(win);
} }
/* /*
* Display information about the given key. * Display information about the given key.
* (could not add the keys descriptions to keydef variable, because of i18n). * (could not add the keys descriptions to keydef variable, because of i18n).
*/ */
void void keys_popup_info(enum key key)
keys_popup_info (enum key key)
{ {
char *info[NBKEYS]; char *info[NBKEYS];
WINDOW *infowin; WINDOW *infowin;
info[KEY_GENERIC_CANCEL] = info[KEY_GENERIC_CANCEL] = _("Cancel the ongoing action.");
_("Cancel the ongoing action."); info[KEY_GENERIC_SELECT] = _("Select the highlighted item.");
info[KEY_GENERIC_SELECT] =
_("Select the highlighted item.");
info[KEY_GENERIC_CREDITS] = info[KEY_GENERIC_CREDITS] =
_("Print general information about calcurse's authors, license, etc."); _("Print general information about calcurse's authors, license, etc.");
info[KEY_GENERIC_HELP] = info[KEY_GENERIC_HELP] =
_("Display hints whenever some help screens are available."); _("Display hints whenever some help screens are available.");
info[KEY_GENERIC_QUIT] = info[KEY_GENERIC_QUIT] = _("Exit from the current menu, or quit calcurse.");
_("Exit from the current menu, or quit calcurse."); info[KEY_GENERIC_SAVE] = _("Save calcurse data.");
info[KEY_GENERIC_SAVE] = info[KEY_GENERIC_CUT] = _("Help for `generic-cut`.");
_("Save calcurse data."); info[KEY_GENERIC_PASTE] = _("Help for `generic-paste`.");
info[KEY_GENERIC_CUT] =
_("Help for `generic-cut`.");
info[KEY_GENERIC_PASTE] =
_("Help for `generic-paste`.");
info[KEY_GENERIC_CHANGE_VIEW] = info[KEY_GENERIC_CHANGE_VIEW] =
_("Select next panel in calcurse main screen."); _("Select next panel in calcurse main screen.");
info[KEY_GENERIC_IMPORT] = info[KEY_GENERIC_IMPORT] = _("Import data from an external file.");
_("Import data from an external file."); info[KEY_GENERIC_EXPORT] = _("Export data to a new file format.");
info[KEY_GENERIC_EXPORT] = info[KEY_GENERIC_GOTO] = _("Select the day to go to.");
_("Export data to a new file format.");
info[KEY_GENERIC_GOTO] =
_("Select the day to go to.");
info[KEY_GENERIC_OTHER_CMD] = info[KEY_GENERIC_OTHER_CMD] =
_("Show next possible actions inside status bar."); _("Show next possible actions inside status bar.");
info[KEY_GENERIC_CONFIG_MENU] = info[KEY_GENERIC_CONFIG_MENU] = _("Enter the configuration menu.");
_("Enter the configuration menu."); info[KEY_GENERIC_REDRAW] = _("Redraw calcurse's screen.");
info[KEY_GENERIC_REDRAW] =
_("Redraw calcurse's screen.");
info[KEY_GENERIC_ADD_APPT] = info[KEY_GENERIC_ADD_APPT] =
_("Add an appointment, whichever panel is currently selected."); _("Add an appointment, whichever panel is currently selected.");
info[KEY_GENERIC_ADD_TODO] = info[KEY_GENERIC_ADD_TODO] =
@ -509,122 +461,103 @@ keys_popup_info (enum key key)
_("Move to previous day in calendar, whichever panel is currently " _("Move to previous day in calendar, whichever panel is currently "
"selected."); "selected.");
info[KEY_GENERIC_NEXT_WEEK] = info[KEY_GENERIC_NEXT_WEEK] =
_("Move to next week in calendar, whichever panel is currently selected."); _
("Move to next week in calendar, whichever panel is currently selected.");
info[KEY_GENERIC_PREV_WEEK] = info[KEY_GENERIC_PREV_WEEK] =
_("Move to previous week in calendar, whichever panel is currently " _("Move to previous week in calendar, whichever panel is currently "
"selected"); "selected");
info[KEY_GENERIC_SCROLL_DOWN] = info[KEY_GENERIC_SCROLL_DOWN] =
_("Scroll window down (e.g. when displaying text inside a popup window)."); _
("Scroll window down (e.g. when displaying text inside a popup window).");
info[KEY_GENERIC_SCROLL_UP] = info[KEY_GENERIC_SCROLL_UP] =
_("Scroll window up (e.g. when displaying text inside a popup window)."); _("Scroll window up (e.g. when displaying text inside a popup window).");
info[KEY_GENERIC_GOTO_TODAY] = info[KEY_GENERIC_GOTO_TODAY] = _("Go to today, whichever panel is selected.");
_("Go to today, whichever panel is selected."); info[KEY_MOVE_RIGHT] = _("Move to the right.");
info[KEY_MOVE_RIGHT] = info[KEY_MOVE_LEFT] = _("Move to the left.");
_("Move to the right."); info[KEY_MOVE_DOWN] = _("Move down.");
info[KEY_MOVE_LEFT] = info[KEY_MOVE_UP] = _("Move up.");
_("Move to the left.");
info[KEY_MOVE_DOWN] =
_("Move down.");
info[KEY_MOVE_UP] =
_("Move up.");
info[KEY_START_OF_WEEK] = info[KEY_START_OF_WEEK] =
_("Select the first day of the current week when inside the calendar " _("Select the first day of the current week when inside the calendar "
"panel."); "panel.");
info[KEY_END_OF_WEEK] = info[KEY_END_OF_WEEK] =
_("Select the last day of the current week when inside the calendar " _("Select the last day of the current week when inside the calendar "
"panel."); "panel.");
info[KEY_ADD_ITEM] = info[KEY_ADD_ITEM] = _("Add an item to the currently selected panel.");
_("Add an item to the currently selected panel."); info[KEY_DEL_ITEM] = _("Delete the currently selected item.");
info[KEY_DEL_ITEM] = info[KEY_EDIT_ITEM] = _("Edit the currently seleted item.");
_("Delete the currently selected item.");
info[KEY_EDIT_ITEM] =
_("Edit the currently seleted item.");
info[KEY_VIEW_ITEM] = info[KEY_VIEW_ITEM] =
_("Display the currently selected item inside a popup window."); _("Display the currently selected item inside a popup window.");
info[KEY_FLAG_ITEM] = info[KEY_FLAG_ITEM] = _("Flag the currently selected item as important.");
_("Flag the currently selected item as important."); info[KEY_REPEAT_ITEM] = _("Repeat an item");
info[KEY_REPEAT_ITEM] =
_("Repeat an item");
info[KEY_PIPE_ITEM] = info[KEY_PIPE_ITEM] =
_("Pipe the currently selected item to an external program."); _("Pipe the currently selected item to an external program.");
info[KEY_EDIT_NOTE] = info[KEY_EDIT_NOTE] =
_("Attach (or edit if one exists) a note to the currently selected item"); _("Attach (or edit if one exists) a note to the currently selected item");
info[KEY_VIEW_NOTE] = info[KEY_VIEW_NOTE] =
_("View the note attached to the currently selected item."); _("View the note attached to the currently selected item.");
info[KEY_RAISE_PRIORITY] = info[KEY_RAISE_PRIORITY] = _("Raise a task priority inside the todo panel.");
_("Raise a task priority inside the todo panel."); info[KEY_LOWER_PRIORITY] = _("Lower a task priority inside the todo panel.");
info[KEY_LOWER_PRIORITY] =
_("Lower a task priority inside the todo panel.");
if (key < 0 || key > NBKEYS) if (key < 0 || key > NBKEYS)
return; return;
#define WINROW 10 #define WINROW 10
#define WINCOL (col - 4) #define WINCOL (col - 4)
infowin = popup (WINROW, WINCOL, (row - WINROW) / 2, (col - WINCOL) / 2, infowin = popup(WINROW, WINCOL, (row - WINROW) / 2, (col - WINCOL) / 2,
keydef[key].label, info[key], 1); keydef[key].label, info[key], 1);
keys_getch (infowin, NULL); keys_getch(infowin, NULL);
delwin (infowin); delwin(infowin);
#undef WINROW #undef WINROW
#undef WINCOL #undef WINCOL
} }
void void keys_save_bindings(FILE * fd)
keys_save_bindings (FILE *fd)
{ {
int i; int i;
EXIT_IF (fd == NULL, _("FATAL ERROR: null file pointer.")); EXIT_IF(fd == NULL, _("FATAL ERROR: null file pointer."));
dump_intro (fd); dump_intro(fd);
for (i = 0; i < NBKEYS; i++) for (i = 0; i < NBKEYS; i++)
fprintf (fd, "%s %s\n", keydef[i].label, keys_action_allkeys (i)); fprintf(fd, "%s %s\n", keydef[i].label, keys_action_allkeys(i));
} }
int int keys_check_missing_bindings(void)
keys_check_missing_bindings (void)
{ {
int i; int i;
for (i = 0; i < NBKEYS; i++) for (i = 0; i < NBKEYS; i++) {
{ if (!LLIST_FIRST(&keys[i]))
if (!LLIST_FIRST (&keys[i]))
return 1; return 1;
} }
return 0; return 0;
} }
void void keys_fill_missing(void)
keys_fill_missing (void)
{ {
int i; int i;
for (i = 0; i < NBKEYS; i++) for (i = 0; i < NBKEYS; i++) {
{ if (!LLIST_FIRST(&keys[i])) {
if (!LLIST_FIRST (&keys[i]))
{
char *p, tmpbuf[BUFSIZ]; char *p, tmpbuf[BUFSIZ];
strncpy (tmpbuf, keydef[i].binding, BUFSIZ); strncpy(tmpbuf, keydef[i].binding, BUFSIZ);
p = tmpbuf; p = tmpbuf;
for (;;) for (;;) {
{
char key_ch[BUFSIZ]; char key_ch[BUFSIZ];
while (*p == ' ') while (*p == ' ')
p++; p++;
if (sscanf (p, "%s", key_ch) == 1) if (sscanf(p, "%s", key_ch) == 1) {
{
int ch, used; int ch, used;
ch = keys_str2int (key_ch); ch = keys_str2int(key_ch);
used = keys_assign_binding (ch, i); used = keys_assign_binding(ch, i);
if (used) if (used)
WARN_MSG (_("When adding default key for \"%s\", " WARN_MSG(_("When adding default key for \"%s\", "
"\"%s\" was already assigned!"), "\"%s\" was already assigned!"),
keydef[i].label, key_ch); keydef[i].label, key_ch);
p += strlen (key_ch) + 1; p += strlen(key_ch) + 1;
} } else
else
break; break;
} }
} }

View File

@ -39,8 +39,7 @@
/* /*
* Initialize a list. * Initialize a list.
*/ */
void void llist_init(llist_t * l)
llist_init (llist_t *l)
{ {
l->head = NULL; l->head = NULL;
l->tail = NULL; l->tail = NULL;
@ -49,15 +48,13 @@ llist_init (llist_t *l)
/* /*
* Free a list, but not the contained data. * Free a list, but not the contained data.
*/ */
void void llist_free(llist_t * l)
llist_free (llist_t *l)
{ {
llist_item_t *i, *t; llist_item_t *i, *t;
for (i = l->head; i; i = t) for (i = l->head; i; i = t) {
{
t = i->next; t = i->next;
mem_free (i); mem_free(i);
} }
l->head = NULL; l->head = NULL;
@ -67,15 +64,12 @@ llist_free (llist_t *l)
/* /*
* Free the data contained in a list. * Free the data contained in a list.
*/ */
void void llist_free_inner(llist_t * l, llist_fn_free_t fn_free)
llist_free_inner (llist_t *l, llist_fn_free_t fn_free)
{ {
llist_item_t *i; llist_item_t *i;
for (i = l->head; i; i = i->next) for (i = l->head; i; i = i->next) {
{ if (i->data) {
if (i->data)
{
fn_free(i->data); fn_free(i->data);
i->data = NULL; i->data = NULL;
} }
@ -85,8 +79,7 @@ llist_free_inner (llist_t *l, llist_fn_free_t fn_free)
/* /*
* Get the first item of a list. * Get the first item of a list.
*/ */
llist_item_t * llist_item_t *llist_first(llist_t * l)
llist_first (llist_t *l)
{ {
return l->head; return l->head;
} }
@ -94,8 +87,7 @@ llist_first (llist_t *l)
/* /*
* Get the nth item of a list. * Get the nth item of a list.
*/ */
llist_item_t * llist_item_t *llist_nth(llist_t * l, int n)
llist_nth (llist_t *l, int n)
{ {
llist_item_t *i; llist_item_t *i;
@ -111,8 +103,7 @@ llist_nth (llist_t *l, int n)
/* /*
* Get the successor of a list item. * Get the successor of a list item.
*/ */
llist_item_t * llist_item_t *llist_next(llist_item_t * i)
llist_next (llist_item_t *i)
{ {
return i ? i->next : NULL; return i ? i->next : NULL;
} }
@ -121,10 +112,10 @@ llist_next (llist_item_t *i)
* Return the successor of a list item if it is matched by some filter * Return the successor of a list item if it is matched by some filter
* callback. Return NULL otherwise. * callback. Return NULL otherwise.
*/ */
llist_item_t * llist_item_t *llist_next_filter(llist_item_t * i, long data,
llist_next_filter (llist_item_t *i, long data, llist_fn_match_t fn_match) llist_fn_match_t fn_match)
{ {
if (i && i->next && fn_match (i->next->data, data)) if (i && i->next && fn_match(i->next->data, data))
return i->next; return i->next;
else else
return NULL; return NULL;
@ -133,8 +124,7 @@ llist_next_filter (llist_item_t *i, long data, llist_fn_match_t fn_match)
/* /*
* Get the actual data of an item. * Get the actual data of an item.
*/ */
void * void *llist_get_data(llist_item_t * i)
llist_get_data (llist_item_t *i)
{ {
return i ? i->data : NULL; return i ? i->data : NULL;
} }
@ -142,20 +132,17 @@ llist_get_data (llist_item_t *i)
/* /*
* Add an item at the end of a list. * Add an item at the end of a list.
*/ */
void void llist_add(llist_t * l, void *data)
llist_add (llist_t *l, void *data)
{ {
llist_item_t *o = mem_malloc (sizeof (llist_item_t)); llist_item_t *o = mem_malloc(sizeof(llist_item_t));
if (o) if (o) {
{
o->data = data; o->data = data;
o->next = NULL; o->next = NULL;
if (!l->head) if (!l->head)
l->head = l->tail = o; l->head = l->tail = o;
else else {
{
l->tail->next = o; l->tail->next = o;
l->tail = o; l->tail = o;
} }
@ -165,31 +152,24 @@ llist_add (llist_t *l, void *data)
/* /*
* Add an item to a sorted list. * Add an item to a sorted list.
*/ */
void void llist_add_sorted(llist_t * l, void *data, llist_fn_cmp_t fn_cmp)
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 *o = mem_malloc(sizeof(llist_item_t));
llist_item_t *i; llist_item_t *i;
if (o) if (o) {
{
o->data = data; o->data = data;
o->next = NULL; o->next = NULL;
if (!l->head) if (!l->head)
l->head = l->tail = o; l->head = l->tail = o;
else if (fn_cmp(o->data, l->tail->data) >= 0) else if (fn_cmp(o->data, l->tail->data) >= 0) {
{
l->tail->next = o; l->tail->next = o;
l->tail = o; l->tail = o;
} } else if (fn_cmp(o->data, l->head->data) < 0) {
else if (fn_cmp(o->data, l->head->data) < 0)
{
o->next = l->head; o->next = l->head;
l->head = o; l->head = o;
} } else {
else
{
i = l->head; i = l->head;
while (i->next && fn_cmp(o->data, i->next->data) >= 0) while (i->next && fn_cmp(o->data, i->next->data) >= 0)
i = i->next; i = i->next;
@ -202,41 +182,36 @@ llist_add_sorted (llist_t *l, void *data, llist_fn_cmp_t fn_cmp)
/* /*
* Remove an item from a list. * Remove an item from a list.
*/ */
void void llist_remove(llist_t * l, llist_item_t * i)
llist_remove (llist_t *l, llist_item_t *i)
{ {
llist_item_t *j = NULL; llist_item_t *j = NULL;
if (l->head && i == l->head) if (l->head && i == l->head)
l->head = i->next; l->head = i->next;
else else {
{ for (j = l->head; j && j->next != i; j = j->next) ;
for (j = l->head; j && j->next != i; j = j->next)
;
} }
if (i) if (i) {
{
if (j) if (j)
j->next = i->next; j->next = i->next;
if (i == l->tail) if (i == l->tail)
l->tail = j; l->tail = j;
mem_free (i); mem_free(i);
} }
} }
/* /*
* Find the first item matched by some filter callback. * Find the first item matched by some filter callback.
*/ */
llist_item_t * llist_item_t *llist_find_first(llist_t * l, long data,
llist_find_first (llist_t *l, long data, llist_fn_match_t fn_match) llist_fn_match_t fn_match)
{ {
llist_item_t *i; llist_item_t *i;
for (i = l->head; i; i = i->next) for (i = l->head; i; i = i->next) {
{ if (fn_match(i->data, data))
if (fn_match (i->data, data))
return i; return i;
} }
@ -246,15 +221,13 @@ llist_find_first (llist_t *l, long data, llist_fn_match_t fn_match)
/* /*
* Find the next item matched by some filter callback. * Find the next item matched by some filter callback.
*/ */
llist_item_t * llist_item_t *llist_find_next(llist_item_t * i, long data,
llist_find_next (llist_item_t *i, long data, llist_fn_match_t fn_match) llist_fn_match_t fn_match)
{ {
if (i) if (i) {
{
i = i->next; i = i->next;
for (; i; i = i->next) for (; i; i = i->next) {
{ if (fn_match(i->data, data))
if (fn_match (i->data, data))
return i; return i;
} }
} }
@ -265,17 +238,16 @@ llist_find_next (llist_item_t *i, long data, llist_fn_match_t fn_match)
/* /*
* Find the nth item matched by some filter callback. * Find the nth item matched by some filter callback.
*/ */
llist_item_t * llist_item_t *llist_find_nth(llist_t * l, int n, long data,
llist_find_nth (llist_t *l, int n, long data, llist_fn_match_t fn_match) llist_fn_match_t fn_match)
{ {
llist_item_t *i; llist_item_t *i;
if (n < 0) if (n < 0)
return NULL; return NULL;
for (i = l->head; i; i = i->next) for (i = l->head; i; i = i->next) {
{ if (fn_match(i->data, data) && (n-- == 0))
if (fn_match (i->data, data) && (n-- == 0))
return i; return i;
} }

View File

@ -52,9 +52,9 @@ typedef int (*llist_fn_match_t) (void *, long);
typedef void (*llist_fn_free_t) (void *); typedef void (*llist_fn_free_t) (void *);
/* Initialization and deallocation. */ /* Initialization and deallocation. */
void llist_init (llist_t *); void llist_init(llist_t *);
void llist_free (llist_t *); void llist_free(llist_t *);
void llist_free_inner (llist_t *, llist_fn_free_t); void llist_free_inner(llist_t *, llist_fn_free_t);
#define LLIST_INIT(l) llist_init(l) #define LLIST_INIT(l) llist_init(l)
#define LLIST_FREE(l) llist_free(l) #define LLIST_FREE(l) llist_free(l)
@ -62,13 +62,13 @@ void llist_free_inner (llist_t *, llist_fn_free_t);
llist_free_inner(l, (llist_fn_free_t)fn_free) llist_free_inner(l, (llist_fn_free_t)fn_free)
/* Retrieving list items. */ /* Retrieving list items. */
llist_item_t *llist_first (llist_t *); llist_item_t *llist_first(llist_t *);
llist_item_t *llist_nth (llist_t *, int); llist_item_t *llist_nth(llist_t *, int);
llist_item_t *llist_next (llist_item_t *); llist_item_t *llist_next(llist_item_t *);
llist_item_t *llist_next_filter (llist_item_t *, long, llist_fn_match_t); llist_item_t *llist_next_filter(llist_item_t *, long, llist_fn_match_t);
llist_item_t *llist_find_first (llist_t *, long, llist_fn_match_t); llist_item_t *llist_find_first(llist_t *, long, llist_fn_match_t);
llist_item_t *llist_find_next (llist_item_t *, long, llist_fn_match_t); llist_item_t *llist_find_next(llist_item_t *, long, llist_fn_match_t);
llist_item_t *llist_find_nth (llist_t *, int, long, llist_fn_match_t); llist_item_t *llist_find_nth(llist_t *, int, long, llist_fn_match_t);
#define LLIST_FIRST(l) llist_first(l) #define LLIST_FIRST(l) llist_first(l)
#define LLIST_NTH(l, n) llist_nth(l, n) #define LLIST_NTH(l, n) llist_nth(l, n)
@ -91,14 +91,14 @@ llist_item_t *llist_find_nth (llist_t *, int, long, llist_fn_match_t);
i = LLIST_NEXT_FILTER (i, data, fn_match)) i = LLIST_NEXT_FILTER (i, data, fn_match))
/* Accessing list item data. */ /* Accessing list item data. */
void *llist_get_data (llist_item_t *); void *llist_get_data(llist_item_t *);
#define LLIST_GET_DATA(i) llist_get_data(i) #define LLIST_GET_DATA(i) llist_get_data(i)
/* List manipulation. */ /* List manipulation. */
void llist_add (llist_t *, void *); void llist_add(llist_t *, void *);
void llist_add_sorted (llist_t *, void *, llist_fn_cmp_t); void llist_add_sorted(llist_t *, void *, llist_fn_cmp_t);
void llist_remove (llist_t *, llist_item_t *); void llist_remove(llist_t *, llist_item_t *);
#define LLIST_ADD(l, data) llist_add(l, data) #define LLIST_ADD(l, data) llist_add(l, data)
#define LLIST_ADD_SORTED(l, data, fn_cmp) \ #define LLIST_ADD_SORTED(l, data, fn_cmp) \

View File

@ -90,4 +90,3 @@ struct llist_ts {
#define LLIST_TS_REMOVE(l_ts, i) llist_remove ((llist_t *)l_ts, i) #define LLIST_TS_REMOVE(l_ts, i) llist_remove ((llist_t *)l_ts, i)
#define LLIST_TS_ADD_SORTED(l_ts, data, fn_cmp) \ #define LLIST_TS_ADD_SORTED(l_ts, data, fn_cmp) \
llist_add_sorted ((llist_t *)l_ts, data, (llist_fn_cmp_t)fn_cmp) llist_add_sorted ((llist_t *)l_ts, data, (llist_fn_cmp_t)fn_cmp)

164
src/mem.c
View File

@ -71,75 +71,68 @@ static struct mem_stats mstats;
#endif /* CALCURSE_MEMORY_DEBUG */ #endif /* CALCURSE_MEMORY_DEBUG */
void *xmalloc(size_t size)
void *
xmalloc (size_t size)
{ {
void *p; void *p;
EXIT_IF (size == 0, _("xmalloc: zero size")); EXIT_IF(size == 0, _("xmalloc: zero size"));
p = malloc (size); p = malloc(size);
EXIT_IF (p == NULL, _("xmalloc: out of memory")); EXIT_IF(p == NULL, _("xmalloc: out of memory"));
return p; return p;
} }
void * void *xcalloc(size_t nmemb, size_t size)
xcalloc (size_t nmemb, size_t size)
{ {
void *p; void *p;
EXIT_IF (nmemb == 0 || size == 0, _("xcalloc: zero size")); EXIT_IF(nmemb == 0 || size == 0, _("xcalloc: zero size"));
EXIT_IF (SIZE_MAX / nmemb < size, _("xcalloc: overflow")); EXIT_IF(SIZE_MAX / nmemb < size, _("xcalloc: overflow"));
p = calloc (nmemb, size); p = calloc(nmemb, size);
EXIT_IF (p == NULL, _("xcalloc: out of memory")); EXIT_IF(p == NULL, _("xcalloc: out of memory"));
return p; return p;
} }
void * void *xrealloc(void *ptr, size_t nmemb, size_t size)
xrealloc (void *ptr, size_t nmemb, size_t size)
{ {
void *new_ptr; void *new_ptr;
size_t new_size; size_t new_size;
new_size = nmemb * size; new_size = nmemb * size;
EXIT_IF (new_size == 0, _("xrealloc: zero size")); EXIT_IF(new_size == 0, _("xrealloc: zero size"));
EXIT_IF (SIZE_MAX / nmemb < size, _("xrealloc: overflow")); EXIT_IF(SIZE_MAX / nmemb < size, _("xrealloc: overflow"));
new_ptr = realloc (ptr, new_size); new_ptr = realloc(ptr, new_size);
EXIT_IF (new_ptr == NULL, _("xrealloc: out of memory")); EXIT_IF(new_ptr == NULL, _("xrealloc: out of memory"));
return new_ptr; return new_ptr;
} }
char * char *xstrdup(const char *str)
xstrdup (const char *str)
{ {
size_t len; size_t len;
char *cp; char *cp;
len = strlen (str) + 1; len = strlen(str) + 1;
cp = xmalloc (len); cp = xmalloc(len);
return strncpy (cp, str, len); return strncpy(cp, str, len);
} }
void void xfree(void *p)
xfree (void *p)
{ {
EXIT_IF (p == NULL, _("xfree: null pointer")); EXIT_IF(p == NULL, _("xfree: null pointer"));
free (p); free(p);
} }
#ifdef CALCURSE_MEMORY_DEBUG #ifdef CALCURSE_MEMORY_DEBUG
static unsigned static unsigned stats_add_blk(size_t size, const char *pos)
stats_add_blk (size_t size, const char *pos)
{ {
struct mem_blk *o, **i; struct mem_blk *o, **i;
o = malloc (sizeof (*o)); o = malloc(sizeof(*o));
EXIT_IF (o == NULL, _("could not allocate memory to store block info")); EXIT_IF(o == NULL, _("could not allocate memory to store block info"));
mstats.ncall++; mstats.ncall++;
@ -147,49 +140,44 @@ stats_add_blk (size_t size, const char *pos)
o->size = (unsigned)size; o->size = (unsigned)size;
o->next = 0; o->next = 0;
for (i = &mstats.blk; *i; i = &(*i)->next) for (i = &mstats.blk; *i; i = &(*i)->next) ;
;
o->id = mstats.ncall; o->id = mstats.ncall;
*i = o; *i = o;
return o->id; return o->id;
} }
static void static void stats_del_blk(unsigned id)
stats_del_blk (unsigned id)
{ {
struct mem_blk *o, **i; struct mem_blk *o, **i;
i = &mstats.blk; i = &mstats.blk;
for (o = mstats.blk; o; o = o->next) for (o = mstats.blk; o; o = o->next) {
{ if (o->id == id) {
if (o->id == id)
{
*i = o->next; *i = o->next;
free (o); free(o);
return; return;
} }
i = &o->next; i = &o->next;
} }
EXIT (_("Block not found")); EXIT(_("Block not found"));
/* NOTREACHED */ /* NOTREACHED */
} }
void * void *dbg_malloc(size_t size, const char *pos)
dbg_malloc (size_t size, const char *pos)
{ {
unsigned *buf; unsigned *buf;
if (size == 0) if (size == 0)
return NULL; return NULL;
size = EXTRA_SPACE + (size + sizeof (unsigned) - 1) / sizeof (unsigned); size = EXTRA_SPACE + (size + sizeof(unsigned) - 1) / sizeof(unsigned);
buf = xmalloc (size * sizeof (unsigned)); buf = xmalloc(size * sizeof(unsigned));
buf[BLK_STATE] = MAGIC_ALLOC; /* state of the block */ buf[BLK_STATE] = MAGIC_ALLOC; /* state of the block */
buf[BLK_SIZE] = size; /* size 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[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[size - 1] = buf[BLK_ID]; /* mark at end of block */
mstats.nalloc += size; mstats.nalloc += size;
@ -197,53 +185,50 @@ dbg_malloc (size_t size, const char *pos)
return (void *)(buf + EXTRA_SPACE_START); return (void *)(buf + EXTRA_SPACE_START);
} }
void * void *dbg_calloc(size_t nmemb, size_t size, const char *pos)
dbg_calloc (size_t nmemb, size_t size, const char *pos)
{ {
void *buf; void *buf;
if (!nmemb || !size) if (!nmemb || !size)
return NULL; return NULL;
EXIT_IF (nmemb > SIZE_MAX / size, _("overflow at %s"), pos); EXIT_IF(nmemb > SIZE_MAX / size, _("overflow at %s"), pos);
size *= nmemb; size *= nmemb;
if ((buf = dbg_malloc (size, pos)) == NULL) if ((buf = dbg_malloc(size, pos)) == NULL)
return NULL; return NULL;
memset (buf, 0, size); memset(buf, 0, size);
return buf; return buf;
} }
void * void *dbg_realloc(void *ptr, size_t nmemb, size_t size, const char *pos)
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) if (ptr == NULL)
return NULL; return NULL;
new_size = nmemb *size; new_size = nmemb * size;
if (new_size == 0) if (new_size == 0)
return NULL; 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) if ((buf = dbg_malloc(new_size, pos)) == NULL)
return NULL; return NULL;
old_size = *((unsigned *)ptr - EXTRA_SPACE_START + BLK_SIZE); old_size = *((unsigned *)ptr - EXTRA_SPACE_START + BLK_SIZE);
cpy_size = (old_size > new_size) ? new_size : old_size; cpy_size = (old_size > new_size) ? new_size : old_size;
memmove (buf, ptr, cpy_size); memmove(buf, ptr, cpy_size);
mem_free (ptr); mem_free(ptr);
return (void *)buf; return (void *)buf;
} }
char * char *dbg_strdup(const char *s, const char *pos)
dbg_strdup (const char *s, const char *pos)
{ {
size_t size; size_t size;
char *buf; char *buf;
@ -251,70 +236,65 @@ dbg_strdup (const char *s, const char *pos)
if (s == NULL) if (s == NULL)
return NULL; return NULL;
size = strlen (s); size = strlen(s);
if ((buf = dbg_malloc (size + 1, pos)) == NULL) if ((buf = dbg_malloc(size + 1, pos)) == NULL)
return NULL; return NULL;
return strncpy (buf, s, size + 1); return strncpy(buf, s, size + 1);
} }
void void dbg_free(void *ptr, const char *pos)
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; buf = (unsigned *)ptr - EXTRA_SPACE_START;
size = buf[BLK_SIZE]; size = buf[BLK_SIZE];
EXIT_IF (buf[BLK_STATE] == MAGIC_FREE, EXIT_IF(buf[BLK_STATE] == MAGIC_FREE,
_("block seems already freed at %s"), pos); _("block seems already freed at %s"), pos);
EXIT_IF (buf[BLK_STATE] != MAGIC_ALLOC, EXIT_IF(buf[BLK_STATE] != MAGIC_ALLOC, _("corrupt block header at %s"), pos);
_("corrupt block header at %s"), pos); EXIT_IF(buf[size - 1] != buf[BLK_ID],
EXIT_IF (buf[size - 1] != buf[BLK_ID],
_("corrupt block end at %s, (end = %u, should be %d)"), pos, _("corrupt block end at %s, (end = %u, should be %d)"), pos,
buf[size - 1], buf[BLK_ID]); 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); free(buf);
mstats.nfree += size; mstats.nfree += size;
} }
static void static void dump_block_info(struct mem_blk *blk)
dump_block_info (struct mem_blk *blk)
{ {
if (blk == NULL) if (blk == NULL)
return; return;
puts (_("---==== MEMORY BLOCK ====----------------\n")); puts(_("---==== MEMORY BLOCK ====----------------\n"));
printf (_(" id: %u\n"), blk->id); printf(_(" id: %u\n"), blk->id);
printf (_(" size: %u\n"), blk->size); printf(_(" size: %u\n"), blk->size);
printf (_(" allocated in: %s\n"), blk->pos); printf(_(" allocated in: %s\n"), blk->pos);
puts (_("-----------------------------------------\n")); puts(_("-----------------------------------------\n"));
} }
void void mem_stats(void)
mem_stats (void)
{ {
putchar ('\n'); putchar('\n');
puts (_("+------------------------------+\n")); puts(_("+------------------------------+\n"));
puts (_("| calcurse memory usage report |\n")); puts(_("| calcurse memory usage report |\n"));
puts (_("+------------------------------+\n")); puts(_("+------------------------------+\n"));
printf (_(" number of calls: %u\n"), mstats.ncall); printf(_(" number of calls: %u\n"), mstats.ncall);
printf (_(" allocated blocks: %u\n"), mstats.nalloc); printf(_(" allocated blocks: %u\n"), mstats.nalloc);
printf (_(" unfreed blocks: %u\n"), mstats.nalloc - mstats.nfree); printf(_(" unfreed blocks: %u\n"), mstats.nalloc - mstats.nfree);
putchar ('\n'); putchar('\n');
if (mstats.nfree < mstats.nalloc) if (mstats.nfree < mstats.nalloc) {
{
struct mem_blk *blk; struct mem_blk *blk;
for (blk = mstats.blk; blk; blk = blk->next) for (blk = mstats.blk; blk; blk = blk->next)
dump_block_info (blk); dump_block_info(blk);
} }
} }

View File

@ -43,135 +43,124 @@
struct note_gc_hash { struct note_gc_hash {
char *hash; char *hash;
char buf[MAX_NOTESIZ + 1]; char buf[MAX_NOTESIZ + 1];
HTABLE_ENTRY (note_gc_hash); 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 *); static int note_gc_cmp(struct note_gc_hash *, struct note_gc_hash *);
HTABLE_HEAD (htp, NOTE_GC_HSIZE, note_gc_hash); HTABLE_HEAD(htp, NOTE_GC_HSIZE, note_gc_hash);
HTABLE_PROTOTYPE (htp, note_gc_hash) HTABLE_PROTOTYPE(htp, note_gc_hash)
HTABLE_GENERATE (htp, note_gc_hash, note_gc_extract_key, note_gc_cmp) HTABLE_GENERATE(htp, note_gc_hash, note_gc_extract_key, note_gc_cmp)
/* Create note file from a string and return a newly allocated string that /* Create note file from a string and return a newly allocated string that
* contains its name. */ * contains its name. */
char * char *generate_note(const char *str)
generate_note (const char *str)
{ {
char *sha1 = mem_malloc (SHA1_DIGESTLEN * 2 + 1); char *sha1 = mem_malloc(SHA1_DIGESTLEN * 2 + 1);
char notepath[BUFSIZ]; char notepath[BUFSIZ];
FILE *fp; FILE *fp;
sha1_digest (str, sha1); sha1_digest(str, sha1);
snprintf (notepath, BUFSIZ, "%s%s", path_notes, sha1); snprintf(notepath, BUFSIZ, "%s%s", path_notes, sha1);
fp = fopen (notepath, "w"); fp = fopen(notepath, "w");
EXIT_IF (fp == NULL, _("Warning: could not open %s, Aborting..."), notepath); EXIT_IF(fp == NULL, _("Warning: could not open %s, Aborting..."), notepath);
fputs (str, fp); fputs(str, fp);
file_close (fp, __FILE_POS__); file_close(fp, __FILE_POS__);
return sha1; return sha1;
} }
/* Edit a note with an external editor. */ /* Edit a note with an external editor. */
void void edit_note(char **note, const char *editor)
edit_note (char **note, const char *editor)
{ {
char tmppath[BUFSIZ]; char tmppath[BUFSIZ];
char *tmpext; char *tmpext;
char notepath[BUFSIZ]; char notepath[BUFSIZ];
char *sha1 = mem_malloc (SHA1_DIGESTLEN * 2 + 1); char *sha1 = mem_malloc(SHA1_DIGESTLEN * 2 + 1);
FILE *fp; FILE *fp;
strncpy (tmppath, get_tempdir (), BUFSIZ); strncpy(tmppath, get_tempdir(), BUFSIZ);
strncat (tmppath, "/calcurse-note.", BUFSIZ - strlen (tmppath) - 1); strncat(tmppath, "/calcurse-note.", BUFSIZ - strlen(tmppath) - 1);
if ((tmpext = new_tempfile (tmppath, TMPEXTSIZ)) == NULL) if ((tmpext = new_tempfile(tmppath, TMPEXTSIZ)) == NULL)
return; return;
strncat (tmppath, tmpext, BUFSIZ - strlen (tmppath) - 1); strncat(tmppath, tmpext, BUFSIZ - strlen(tmppath) - 1);
mem_free (tmpext); mem_free(tmpext);
if (*note != NULL) if (*note != NULL) {
{ snprintf(notepath, BUFSIZ, "%s%s", path_notes, *note);
snprintf (notepath, BUFSIZ, "%s%s", path_notes, *note); io_file_cp(notepath, tmppath);
io_file_cp (notepath, tmppath);
} }
wins_launch_external (tmppath, editor); wins_launch_external(tmppath, editor);
if (io_file_is_empty (tmppath) > 0) if (io_file_is_empty(tmppath) > 0)
erase_note (note); erase_note(note);
else if ((fp = fopen (tmppath, "r"))) else if ((fp = fopen(tmppath, "r"))) {
{ sha1_stream(fp, sha1);
sha1_stream (fp, sha1); fclose(fp);
fclose (fp);
*note = sha1; *note = sha1;
snprintf (notepath, BUFSIZ, "%s%s", path_notes, *note); snprintf(notepath, BUFSIZ, "%s%s", path_notes, *note);
io_file_cp (tmppath, notepath); io_file_cp(tmppath, notepath);
} }
unlink (tmppath); unlink(tmppath);
} }
/* View a note in an external pager. */ /* View a note in an external pager. */
void void view_note(const char *note, const char *pager)
view_note (const char *note, const char *pager)
{ {
char fullname[BUFSIZ]; char fullname[BUFSIZ];
if (note == NULL) if (note == NULL)
return; return;
snprintf (fullname, BUFSIZ, "%s%s", path_notes, note); snprintf(fullname, BUFSIZ, "%s%s", path_notes, note);
wins_launch_external (fullname, pager); wins_launch_external(fullname, pager);
} }
/* Erase a note previously attached to an item. */ /* Erase a note previously attached to an item. */
void void erase_note(char **note)
erase_note (char **note)
{ {
if (*note == NULL) if (*note == NULL)
return; return;
mem_free (*note); mem_free(*note);
*note = NULL; *note = NULL;
} }
/* Read a serialized note file name from a stream and deserialize it. */ /* Read a serialized note file name from a stream and deserialize it. */
void void note_read(char *buffer, FILE * fp)
note_read (char *buffer, FILE *fp)
{ {
int i; int i;
for (i = 0; i < MAX_NOTESIZ; i++) for (i = 0; i < MAX_NOTESIZ; i++) {
{ buffer[i] = getc(fp);
buffer[i] = getc (fp); if (buffer[i] == ' ') {
if (buffer[i] == ' ')
{
buffer[i] = '\0'; buffer[i] = '\0';
return; return;
} }
} }
while (getc (fp) != ' '); while (getc(fp) != ' ') ;
buffer[MAX_NOTESIZ] = '\0'; buffer[MAX_NOTESIZ] = '\0';
} }
static void static void
note_gc_extract_key (struct note_gc_hash *data, const char **key, int *len) note_gc_extract_key(struct note_gc_hash *data, const char **key, int *len)
{ {
*key = data->hash; *key = data->hash;
*len = strlen (data->hash); *len = strlen(data->hash);
} }
static int static int note_gc_cmp(struct note_gc_hash *a, struct note_gc_hash *b)
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. */ /* Spot and unlink unused note files. */
void void note_gc(void)
note_gc (void)
{ {
struct htp gc_htable = HTABLE_INITIALIZER (&gc_htable); struct htp gc_htable = HTABLE_INITIALIZER(&gc_htable);
struct note_gc_hash *hp; struct note_gc_hash *hp;
DIR *dirp; DIR *dirp;
struct dirent *dp; struct dirent *dp;
@ -179,81 +168,68 @@ note_gc (void)
struct note_gc_hash tmph; struct note_gc_hash tmph;
char notepath[BUFSIZ]; char notepath[BUFSIZ];
if (!(dirp = opendir (path_notes))) if (!(dirp = opendir(path_notes)))
return; return;
/* Insert all note file names into a hash table. */ /* Insert all note file names into a hash table. */
do do {
{ if ((dp = readdir(dirp)) && *(dp->d_name) != '.') {
if ((dp = readdir (dirp)) && *(dp->d_name) != '.') hp = mem_malloc(sizeof(struct note_gc_hash));
{
hp = mem_malloc (sizeof (struct note_gc_hash));
strncpy (hp->buf, dp->d_name, MAX_NOTESIZ + 1); strncpy(hp->buf, dp->d_name, MAX_NOTESIZ + 1);
hp->hash = hp->buf; hp->hash = hp->buf;
HTABLE_INSERT (htp, &gc_htable, hp); HTABLE_INSERT(htp, &gc_htable, hp);
} }
} }
while (dp); while (dp);
closedir (dirp); closedir(dirp);
/* Remove hashes that are actually in use. */ /* Remove hashes that are actually in use. */
LLIST_TS_FOREACH (&alist_p, i) LLIST_TS_FOREACH(&alist_p, i) {
{ struct apoint *apt = LLIST_GET_DATA(i);
struct apoint *apt = LLIST_GET_DATA (i); if (apt->note) {
if (apt->note)
{
tmph.hash = apt->note; tmph.hash = apt->note;
free (HTABLE_REMOVE (htp, &gc_htable, &tmph)); free(HTABLE_REMOVE(htp, &gc_htable, &tmph));
} }
} }
LLIST_FOREACH (&eventlist, i) LLIST_FOREACH(&eventlist, i) {
{ struct event *ev = LLIST_GET_DATA(i);
struct event *ev = LLIST_GET_DATA (i); if (ev->note) {
if (ev->note)
{
tmph.hash = ev->note; tmph.hash = ev->note;
free (HTABLE_REMOVE (htp, &gc_htable, &tmph)); free(HTABLE_REMOVE(htp, &gc_htable, &tmph));
} }
} }
LLIST_TS_FOREACH (&recur_alist_p, i) LLIST_TS_FOREACH(&recur_alist_p, i) {
{ struct recur_apoint *rapt = LLIST_GET_DATA(i);
struct recur_apoint *rapt = LLIST_GET_DATA (i); if (rapt->note) {
if (rapt->note)
{
tmph.hash = rapt->note; tmph.hash = rapt->note;
free (HTABLE_REMOVE (htp, &gc_htable, &tmph)); free(HTABLE_REMOVE(htp, &gc_htable, &tmph));
} }
} }
LLIST_FOREACH (&recur_elist, i) LLIST_FOREACH(&recur_elist, i) {
{ struct recur_event *rev = LLIST_GET_DATA(i);
struct recur_event *rev = LLIST_GET_DATA (i); if (rev->note) {
if (rev->note)
{
tmph.hash = rev->note; tmph.hash = rev->note;
free (HTABLE_REMOVE (htp, &gc_htable, &tmph)); free(HTABLE_REMOVE(htp, &gc_htable, &tmph));
} }
} }
LLIST_FOREACH (&todolist, i) LLIST_FOREACH(&todolist, i) {
{ struct todo *todo = LLIST_GET_DATA(i);
struct todo *todo = LLIST_GET_DATA (i); if (todo->note) {
if (todo->note)
{
tmph.hash = todo->note; tmph.hash = todo->note;
free (HTABLE_REMOVE (htp, &gc_htable, &tmph)); free(HTABLE_REMOVE(htp, &gc_htable, &tmph));
} }
} }
/* Unlink unused note files. */ /* Unlink unused note files. */
HTABLE_FOREACH (hp, htp, &gc_htable) HTABLE_FOREACH(hp, htp, &gc_htable) {
{ snprintf(notepath, BUFSIZ, "%s%s", path_notes, hp->hash);
snprintf (notepath, BUFSIZ, "%s%s", path_notes, hp->hash); unlink(notepath);
unlink (notepath);
} }
} }

View File

@ -60,13 +60,12 @@ static pthread_t notify_t_main;
* Return the number of seconds before next appointment * Return the number of seconds before next appointment
* (0 if no upcoming appointment). * (0 if no upcoming appointment).
*/ */
int int notify_time_left(void)
notify_time_left (void)
{ {
time_t ntimer; time_t ntimer;
int left; int left;
ntimer = time (NULL); ntimer = time(NULL);
left = notify_app.time - ntimer; left = notify_app.time - ntimer;
return left > 0 ? left : 0; return left > 0 ? left : 0;
@ -76,8 +75,7 @@ notify_time_left (void)
* Return 1 if the reminder was not sent already for the upcoming * Return 1 if the reminder was not sent already for the upcoming
* appointment. * appointment.
*/ */
unsigned unsigned notify_needs_reminder(void)
notify_needs_reminder (void)
{ {
if (notify_app.got_app if (notify_app.got_app
&& (((notify_app.state & APOINT_NOTIFY) && !nbar.notify_all) || && (((notify_app.state & APOINT_NOTIFY) && !nbar.notify_all) ||
@ -92,64 +90,59 @@ notify_needs_reminder (void)
* Note: the mutex associated with this structure must be locked by the * Note: the mutex associated with this structure must be locked by the
* caller! * caller!
*/ */
void void notify_update_app(long start, char state, char *msg)
notify_update_app (long start, char state, char *msg)
{ {
notify_free_app (); notify_free_app();
notify_app.got_app = 1; notify_app.got_app = 1;
notify_app.time = start; notify_app.time = start;
notify_app.state = state; notify_app.state = state;
notify_app.txt = mem_strdup (msg); notify_app.txt = mem_strdup(msg);
} }
/* Return 1 if we need to display the notify-bar, else 0. */ /* Return 1 if we need to display the notify-bar, else 0. */
int int notify_bar(void)
notify_bar (void)
{ {
int display_bar = 0; int display_bar = 0;
pthread_mutex_lock (&nbar.mutex); pthread_mutex_lock(&nbar.mutex);
display_bar = (nbar.show) ? 1 : 0; display_bar = (nbar.show) ? 1 : 0;
pthread_mutex_unlock (&nbar.mutex); pthread_mutex_unlock(&nbar.mutex);
return display_bar; return display_bar;
} }
/* Initialize the nbar variable used to store notification options. */ /* Initialize the nbar variable used to store notification options. */
void void notify_init_vars(void)
notify_init_vars (void)
{ {
const char *time_format = "%T"; const char *time_format = "%T";
const char *date_format = "%a %F"; const char *date_format = "%a %F";
const char *cmd = "printf '\\a'"; const char *cmd = "printf '\\a'";
pthread_mutex_init (&nbar.mutex, NULL); pthread_mutex_init(&nbar.mutex, NULL);
nbar.show = 1; nbar.show = 1;
nbar.cntdwn = 300; nbar.cntdwn = 300;
strncpy (nbar.datefmt, date_format, strlen (date_format) + 1); strncpy(nbar.datefmt, date_format, strlen(date_format) + 1);
strncpy (nbar.timefmt, time_format, strlen (time_format) + 1); strncpy(nbar.timefmt, time_format, strlen(time_format) + 1);
strncpy (nbar.cmd, cmd, strlen (cmd) + 1); strncpy(nbar.cmd, cmd, strlen(cmd) + 1);
if ((nbar.shell = getenv ("SHELL")) == NULL) if ((nbar.shell = getenv("SHELL")) == NULL)
nbar.shell = "/bin/sh"; nbar.shell = "/bin/sh";
nbar.notify_all = 0; nbar.notify_all = 0;
pthread_attr_init (&detached_thread_attr); pthread_attr_init(&detached_thread_attr);
pthread_attr_setdetachstate (&detached_thread_attr, PTHREAD_CREATE_DETACHED); pthread_attr_setdetachstate(&detached_thread_attr, PTHREAD_CREATE_DETACHED);
} }
/* Extract the appointment file name from the complete file path. */ /* Extract the appointment file name from the complete file path. */
static void static void extract_aptsfile(void)
extract_aptsfile (void)
{ {
char *file; char *file;
file = strrchr (path_apts, '/'); file = strrchr(path_apts, '/');
if (!file) if (!file)
notify.apts_file = path_apts; notify.apts_file = path_apts;
else else {
{
notify.apts_file = file; notify.apts_file = file;
notify.apts_file++; notify.apts_file++;
} }
@ -160,39 +153,35 @@ extract_aptsfile (void)
* creating the notification window (l is the number of lines, c the * creating the notification window (l is the number of lines, c the
* number of columns, y and x are its coordinates). * number of columns, y and x are its coordinates).
*/ */
void void notify_init_bar(void)
notify_init_bar (void)
{ {
pthread_mutex_init (&notify.mutex, NULL); pthread_mutex_init(&notify.mutex, NULL);
pthread_mutex_init (&notify_app.mutex, NULL); pthread_mutex_init(&notify_app.mutex, NULL);
notify_app.got_app = 0; notify_app.got_app = 0;
notify_app.txt = 0; notify_app.txt = 0;
notify.win = newwin (win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x); notify.win = newwin(win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x);
extract_aptsfile (); extract_aptsfile();
} }
/* /*
* Free memory associated with the notify_app structure. * Free memory associated with the notify_app structure.
*/ */
void void notify_free_app(void)
notify_free_app (void)
{ {
notify_app.time = 0; notify_app.time = 0;
notify_app.got_app = 0; notify_app.got_app = 0;
notify_app.state = APOINT_NULL; notify_app.state = APOINT_NULL;
if (notify_app.txt) if (notify_app.txt)
mem_free (notify_app.txt); mem_free(notify_app.txt);
notify_app.txt = 0; notify_app.txt = 0;
} }
/* Stop the notify-bar main thread. */ /* Stop the notify-bar main thread. */
void void notify_stop_main_thread(void)
notify_stop_main_thread (void)
{ {
if (notify_t_main) if (notify_t_main) {
{ pthread_cancel(notify_t_main);
pthread_cancel (notify_t_main); pthread_join(notify_t_main, NULL);
pthread_join (notify_t_main, NULL);
} }
} }
@ -200,16 +189,14 @@ notify_stop_main_thread (void)
* The calcurse window geometry has changed so we need to reset the * The calcurse window geometry has changed so we need to reset the
* notification window. * notification window.
*/ */
void void notify_reinit_bar(void)
notify_reinit_bar (void)
{ {
delwin (notify.win); delwin(notify.win);
notify.win = newwin (win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x); notify.win = newwin(win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x);
} }
/* Launch user defined command as a notification. */ /* Launch user defined command as a notification. */
unsigned unsigned notify_launch_cmd(void)
notify_launch_cmd (void)
{ {
int pid; int pid;
@ -218,22 +205,18 @@ notify_launch_cmd (void)
notify_app.state |= APOINT_NOTIFIED; notify_app.state |= APOINT_NOTIFIED;
pid = fork (); pid = fork();
if (pid < 0) if (pid < 0) {
{ ERROR_MSG(_("error while launching command: could not fork"));
ERROR_MSG (_("error while launching command: could not fork"));
return 0; return 0;
} } else if (pid == 0) {
else if (pid == 0)
{
/* Child: launch user defined command */ /* Child: launch user defined command */
if (execlp (nbar.shell, nbar.shell, "-c", nbar.cmd, NULL) < 0) if (execlp(nbar.shell, nbar.shell, "-c", nbar.cmd, NULL) < 0) {
{ ERROR_MSG(_("error while launching command"));
ERROR_MSG (_("error while launching command")); _exit(1);
_exit (1);
} }
_exit (0); _exit(0);
} }
return 1; return 1;
@ -243,8 +226,7 @@ notify_launch_cmd (void)
* Update the notification bar. This is useful when changing color theme * Update the notification bar. This is useful when changing color theme
* for example. * for example.
*/ */
void void notify_update_bar(void)
notify_update_bar (void)
{ {
const int space = 3; const int space = 3;
int file_pos, date_pos, app_pos, txt_max_len, too_long = 0; int file_pos, date_pos, app_pos, txt_max_len, too_long = 0;
@ -252,39 +234,35 @@ notify_update_bar (void)
char buf[BUFSIZ]; char buf[BUFSIZ];
date_pos = space; date_pos = space;
pthread_mutex_lock (&notify.mutex); pthread_mutex_lock(&notify.mutex);
file_pos = strlen (notify.date) + strlen (notify.time) + 7 + 2 * space; file_pos = strlen(notify.date) + strlen(notify.time) + 7 + 2 * space;
app_pos = file_pos + strlen (notify.apts_file) + 2 + space; app_pos = file_pos + strlen(notify.apts_file) + 2 + space;
txt_max_len = col - (app_pos + 12 + space); txt_max_len = col - (app_pos + 12 + space);
custom_apply_attr (notify.win, ATTR_HIGHEST); custom_apply_attr(notify.win, ATTR_HIGHEST);
wattron (notify.win, A_UNDERLINE | A_REVERSE); wattron(notify.win, A_UNDERLINE | A_REVERSE);
mvwhline (notify.win, 0, 0, ACS_HLINE, col); mvwhline(notify.win, 0, 0, ACS_HLINE, col);
mvwprintw (notify.win, 0, date_pos, "[ %s | %s ]", mvwprintw(notify.win, 0, date_pos, "[ %s | %s ]", notify.date, notify.time);
notify.date, notify.time); mvwprintw(notify.win, 0, file_pos, "(%s)", notify.apts_file);
mvwprintw (notify.win, 0, file_pos, "(%s)", notify.apts_file);
pthread_mutex_lock (&notify_app.mutex); pthread_mutex_lock(&notify_app.mutex);
if (notify_app.got_app) if (notify_app.got_app) {
{ if (strlen(notify_app.txt) > txt_max_len) {
if (strlen (notify_app.txt) > txt_max_len)
{
int shrink_len; int shrink_len;
too_long = 1; too_long = 1;
shrink_len = txt_max_len > 3 ? txt_max_len - 3 : 1; shrink_len = txt_max_len > 3 ? txt_max_len - 3 : 1;
strncpy (buf, notify_app.txt, shrink_len); strncpy(buf, notify_app.txt, shrink_len);
buf[shrink_len] = '\0'; buf[shrink_len] = '\0';
} }
time_left = notify_time_left (); time_left = notify_time_left();
if (time_left > 0) if (time_left > 0) {
{
int hours_left, minutes_left; int hours_left, minutes_left;
hours_left = (time_left / HOURINSEC); hours_left = (time_left / HOURINSEC);
minutes_left = (time_left - hours_left * HOURINSEC) / MININSEC; minutes_left = (time_left - hours_left * HOURINSEC) / MININSEC;
pthread_mutex_lock (&nbar.mutex); pthread_mutex_lock(&nbar.mutex);
if (time_left < nbar.cntdwn && if (time_left < nbar.cntdwn &&
(((notify_app.state & APOINT_NOTIFY) && !nbar.notify_all) || (((notify_app.state & APOINT_NOTIFY) && !nbar.notify_all) ||
@ -294,42 +272,39 @@ notify_update_bar (void)
blinking = 0; blinking = 0;
if (blinking) if (blinking)
wattron (notify.win, A_BLINK); wattron(notify.win, A_BLINK);
if (too_long) if (too_long)
mvwprintw (notify.win, 0, app_pos, "> %02d:%02d :: %s.. <", mvwprintw(notify.win, 0, app_pos, "> %02d:%02d :: %s.. <",
hours_left, minutes_left, buf); hours_left, minutes_left, buf);
else else
mvwprintw (notify.win, 0, app_pos, "> %02d:%02d :: %s <", mvwprintw(notify.win, 0, app_pos, "> %02d:%02d :: %s <",
hours_left, minutes_left, notify_app.txt); hours_left, minutes_left, notify_app.txt);
if (blinking) if (blinking)
wattroff (notify.win, A_BLINK); wattroff(notify.win, A_BLINK);
if (blinking) if (blinking)
notify_launch_cmd (); notify_launch_cmd();
pthread_mutex_unlock (&nbar.mutex); pthread_mutex_unlock(&nbar.mutex);
} } else {
else
{
notify_app.got_app = 0; notify_app.got_app = 0;
pthread_mutex_unlock (&notify_app.mutex); pthread_mutex_unlock(&notify_app.mutex);
pthread_mutex_unlock (&notify.mutex); pthread_mutex_unlock(&notify.mutex);
notify_check_next_app (0); notify_check_next_app(0);
return; return;
} }
} }
pthread_mutex_unlock (&notify_app.mutex); pthread_mutex_unlock(&notify_app.mutex);
wattroff (notify.win, A_UNDERLINE | A_REVERSE); wattroff(notify.win, A_UNDERLINE | A_REVERSE);
custom_remove_attr (notify.win, ATTR_HIGHEST); custom_remove_attr(notify.win, ATTR_HIGHEST);
wins_wrefresh (notify.win); wins_wrefresh(notify.win);
pthread_mutex_unlock (&notify.mutex); pthread_mutex_unlock(&notify.mutex);
} }
/* Update the notication bar content */ /* Update the notication bar content */
/* ARGSUSED0 */ /* ARGSUSED0 */
static void * static void *notify_main_thread(void *arg)
notify_main_thread (void *arg)
{ {
const unsigned thread_sleep = 1; const unsigned thread_sleep = 1;
const unsigned check_app = MININSEC; const unsigned check_app = MININSEC;
@ -340,49 +315,46 @@ notify_main_thread (void *arg)
elapse = 0; elapse = 0;
for (;;) for (;;) {
{ ntimer = time(NULL);
ntimer = time (NULL); ntime = localtime(&ntimer);
ntime = localtime (&ntimer); pthread_mutex_lock(&notify.mutex);
pthread_mutex_lock (&notify.mutex); pthread_mutex_lock(&nbar.mutex);
pthread_mutex_lock (&nbar.mutex); strftime(notify.time, NOTIFY_FIELD_LENGTH, nbar.timefmt, ntime);
strftime (notify.time, NOTIFY_FIELD_LENGTH, nbar.timefmt, ntime); strftime(notify.date, NOTIFY_FIELD_LENGTH, nbar.datefmt, ntime);
strftime (notify.date, NOTIFY_FIELD_LENGTH, nbar.datefmt, ntime); pthread_mutex_unlock(&nbar.mutex);
pthread_mutex_unlock (&nbar.mutex); pthread_mutex_unlock(&notify.mutex);
pthread_mutex_unlock (&notify.mutex); notify_update_bar();
notify_update_bar (); psleep(thread_sleep);
psleep (thread_sleep);
elapse += thread_sleep; elapse += thread_sleep;
if (elapse >= check_app) if (elapse >= check_app) {
{
elapse = 0; elapse = 0;
pthread_mutex_lock (&notify_app.mutex); pthread_mutex_lock(&notify_app.mutex);
got_app = notify_app.got_app; got_app = notify_app.got_app;
pthread_mutex_unlock (&notify_app.mutex); pthread_mutex_unlock(&notify_app.mutex);
if (!got_app) if (!got_app)
notify_check_next_app (0); notify_check_next_app(0);
} }
} }
pthread_exit (NULL); pthread_exit(NULL);
} }
/* Fill the given structure with information about next appointment. */ /* Fill the given structure with information about next appointment. */
unsigned unsigned notify_get_next(struct notify_app *a)
notify_get_next (struct notify_app *a)
{ {
time_t current_time; time_t current_time;
if (!a) if (!a)
return 0; return 0;
current_time = time (NULL); current_time = time(NULL);
a->time = current_time + DAYINSEC; a->time = current_time + DAYINSEC;
a->got_app = 0; a->got_app = 0;
a->state = 0; a->state = 0;
a->txt = NULL; a->txt = NULL;
recur_apoint_check_next (a, current_time, get_today ()); recur_apoint_check_next(a, current_time, get_today());
apoint_check_next (a, current_time); apoint_check_next(a, current_time);
return 1; return 1;
} }
@ -391,36 +363,31 @@ notify_get_next (struct notify_app *a)
* This is used for the daemon to check if we have an upcoming appointment or * This is used for the daemon to check if we have an upcoming appointment or
* not. * not.
*/ */
unsigned unsigned notify_get_next_bkgd(void)
notify_get_next_bkgd (void)
{ {
struct notify_app a; struct notify_app a;
a.txt = NULL; a.txt = NULL;
if (!notify_get_next (&a)) if (!notify_get_next(&a))
return 0; return 0;
if (!a.got_app) if (!a.got_app) {
{
/* No next appointment, reset the previous notified one. */ /* No next appointment, reset the previous notified one. */
notify_app.got_app = 0; notify_app.got_app = 0;
return 1; return 1;
} } else {
else if (!notify_same_item(a.time))
{ notify_update_app(a.time, a.state, a.txt);
if (!notify_same_item (a.time))
notify_update_app (a.time, a.state, a.txt);
} }
if (a.txt) if (a.txt)
mem_free (a.txt); mem_free(a.txt);
return 1; return 1;
} }
/* Return the description of next appointment to be notified. */ /* Return the description of next appointment to be notified. */
char * char *notify_app_txt(void)
notify_app_txt (void)
{ {
if (notify_app.got_app) if (notify_app.got_app)
return notify_app.txt; return notify_app.txt;
@ -430,153 +397,128 @@ notify_app_txt (void)
/* Look for the next appointment within the next 24 hours. */ /* Look for the next appointment within the next 24 hours. */
/* ARGSUSED0 */ /* ARGSUSED0 */
static void * static void *notify_thread_app(void *arg)
notify_thread_app (void *arg)
{ {
struct notify_app tmp_app; struct notify_app tmp_app;
int force = (arg ? 1 : 0); int force = (arg ? 1 : 0);
if (!notify_get_next (&tmp_app)) if (!notify_get_next(&tmp_app))
pthread_exit (NULL); pthread_exit(NULL);
if (!tmp_app.got_app) if (!tmp_app.got_app) {
{ pthread_mutex_lock(&notify_app.mutex);
pthread_mutex_lock (&notify_app.mutex); notify_free_app();
notify_free_app (); pthread_mutex_unlock(&notify_app.mutex);
pthread_mutex_unlock (&notify_app.mutex); } else {
} if (force || !notify_same_item(tmp_app.time)) {
else pthread_mutex_lock(&notify_app.mutex);
{ notify_update_app(tmp_app.time, tmp_app.state, tmp_app.txt);
if (force || !notify_same_item (tmp_app.time)) pthread_mutex_unlock(&notify_app.mutex);
{
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) if (tmp_app.txt)
mem_free (tmp_app.txt); mem_free(tmp_app.txt);
notify_update_bar (); notify_update_bar();
pthread_exit (NULL); pthread_exit(NULL);
} }
/* Launch the thread notify_thread_app to look for next appointment. */ /* Launch the thread notify_thread_app to look for next appointment. */
void void notify_check_next_app(int force)
notify_check_next_app (int force)
{ {
pthread_t notify_t_app; pthread_t notify_t_app;
void *arg = (force ? (void *)1 : NULL); void *arg = (force ? (void *)1 : NULL);
pthread_create (&notify_t_app, &detached_thread_attr, notify_thread_app, pthread_create(&notify_t_app, &detached_thread_attr, notify_thread_app, arg);
arg);
return; return;
} }
/* Check if the newly created appointment is to be notified. */ /* Check if the newly created appointment is to be notified. */
void void notify_check_added(char *mesg, long start, char state)
notify_check_added (char *mesg, long start, char state)
{ {
time_t current_time; time_t current_time;
int update_notify = 0; int update_notify = 0;
long gap; long gap;
current_time = time (NULL); current_time = time(NULL);
pthread_mutex_lock (&notify_app.mutex); pthread_mutex_lock(&notify_app.mutex);
if (!notify_app.got_app) if (!notify_app.got_app) {
{
gap = start - current_time; gap = start - current_time;
if (gap >= 0 && gap <= DAYINSEC) if (gap >= 0 && gap <= DAYINSEC)
update_notify = 1; update_notify = 1;
} } else if (start < notify_app.time && start >= current_time) {
else if (start < notify_app.time && start >= current_time)
{
update_notify = 1; update_notify = 1;
} } else if (start == notify_app.time && state != notify_app.state)
else if (start == notify_app.time && state != notify_app.state)
update_notify = 1; update_notify = 1;
if (update_notify) if (update_notify) {
{ notify_update_app(start, state, mesg);
notify_update_app (start, state, mesg);
} }
pthread_mutex_unlock (&notify_app.mutex); pthread_mutex_unlock(&notify_app.mutex);
notify_update_bar (); notify_update_bar();
} }
/* Check if the newly repeated appointment is to be notified. */ /* Check if the newly repeated appointment is to be notified. */
void void notify_check_repeated(struct recur_apoint *i)
notify_check_repeated (struct recur_apoint *i)
{ {
unsigned real_app_time; unsigned real_app_time;
int update_notify = 0; int update_notify = 0;
time_t current_time; time_t current_time;
current_time = time (NULL); current_time = time(NULL);
pthread_mutex_lock (&notify_app.mutex); pthread_mutex_lock(&notify_app.mutex);
if (recur_item_find_occurrence (i->start, i->dur, &i->exc, i->rpt->type, if (recur_item_find_occurrence(i->start, i->dur, &i->exc, i->rpt->type,
i->rpt->freq, i->rpt->until, get_today (), i->rpt->freq, i->rpt->until, get_today(),
&real_app_time)) &real_app_time)) {
{ if (!notify_app.got_app) {
if (!notify_app.got_app)
{
if (real_app_time - current_time <= DAYINSEC) if (real_app_time - current_time <= DAYINSEC)
update_notify = 1; update_notify = 1;
} } else if (real_app_time < notify_app.time && real_app_time >= current_time) {
else if (real_app_time < notify_app.time && update_notify = 1;
real_app_time >= current_time) } else if (real_app_time == notify_app.time && i->state != notify_app.state)
{
update_notify = 1; update_notify = 1;
} }
else if (real_app_time == notify_app.time && if (update_notify) {
i->state != notify_app.state) notify_update_app(real_app_time, i->state, i->mesg);
update_notify = 1;
} }
if (update_notify) pthread_mutex_unlock(&notify_app.mutex);
{ notify_update_bar();
notify_update_app (real_app_time, i->state, i->mesg);
}
pthread_mutex_unlock (&notify_app.mutex);
notify_update_bar ();
} }
int int notify_same_item(long time)
notify_same_item (long time)
{ {
int same = 0; int same = 0;
pthread_mutex_lock (&(notify_app.mutex)); pthread_mutex_lock(&(notify_app.mutex));
if (notify_app.got_app && notify_app.time == time) if (notify_app.got_app && notify_app.time == time)
same = 1; same = 1;
pthread_mutex_unlock (&(notify_app.mutex)); pthread_mutex_unlock(&(notify_app.mutex));
return same; return same;
} }
int int notify_same_recur_item(struct recur_apoint *i)
notify_same_recur_item (struct recur_apoint *i)
{ {
int same = 0; int same = 0;
unsigned item_start = 0; unsigned item_start = 0;
recur_item_find_occurrence (i->start, i->dur, &i->exc, i->rpt->type, recur_item_find_occurrence(i->start, i->dur, &i->exc, i->rpt->type,
i->rpt->freq, i->rpt->until, get_today (), i->rpt->freq, i->rpt->until, get_today(),
&item_start); &item_start);
pthread_mutex_lock (&notify_app.mutex); pthread_mutex_lock(&notify_app.mutex);
if (notify_app.got_app && item_start == notify_app.time) if (notify_app.got_app && item_start == notify_app.time)
same = 1; same = 1;
pthread_mutex_unlock (&(notify_app.mutex)); pthread_mutex_unlock(&(notify_app.mutex));
return same; return same;
} }
/* Launch the notify-bar main thread. */ /* Launch the notify-bar main thread. */
void void notify_start_main_thread(void)
notify_start_main_thread (void)
{ {
pthread_create (&notify_t_main, NULL, notify_main_thread, NULL); pthread_create(&notify_t_main, NULL, notify_main_thread, NULL);
notify_check_next_app (0); notify_check_next_app(0);
} }
/* /*
@ -585,52 +527,46 @@ notify_start_main_thread (void)
* (either YES or NO), or an option holding a string value. * (either YES or NO), or an option holding a string value.
*/ */
static void static void
print_option (WINDOW *win, unsigned x, unsigned y, char *name, 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 XOFF = 4;
const int MAXCOL = col - 3; const int MAXCOL = col - 3;
int x_opt, len; int x_opt, len;
x_opt = x + XOFF + strlen (name); x_opt = x + XOFF + strlen(name);
mvwprintw (win, y, x, "[%u] %s", num, name); mvwprintw(win, y, x, "[%u] %s", num, name);
erase_window_part (win, x_opt, y, MAXCOL, y); erase_window_part(win, x_opt, y, MAXCOL, y);
if ((len = strlen (valstr)) != 0) if ((len = strlen(valstr)) != 0) {
{
unsigned maxlen; unsigned maxlen;
maxlen = MAXCOL - x_opt - 2; maxlen = MAXCOL - x_opt - 2;
custom_apply_attr (win, ATTR_HIGHEST); custom_apply_attr(win, ATTR_HIGHEST);
if (len < maxlen) if (len < maxlen)
mvwprintw (win, y, x_opt, "%s", valstr); mvwprintw(win, y, x_opt, "%s", valstr);
else else {
{
char buf[BUFSIZ]; char buf[BUFSIZ];
strncpy (buf, valstr, maxlen - 1); strncpy(buf, valstr, maxlen - 1);
buf[maxlen - 1] = '\0'; buf[maxlen - 1] = '\0';
mvwprintw (win, y, x_opt, "%s...", buf); mvwprintw(win, y, x_opt, "%s...", buf);
} }
custom_remove_attr (win, ATTR_HIGHEST); custom_remove_attr(win, ATTR_HIGHEST);
} } else
else print_bool_option_incolor(win, valbool, y, x_opt);
print_bool_option_incolor (win, valbool, y, x_opt); mvwprintw(win, y + 1, x, desc);
mvwprintw (win, y + 1, x, desc);
} }
/* Print options related to the notify-bar. */ /* Print options related to the notify-bar. */
static unsigned static unsigned print_config_options(WINDOW * optwin)
print_config_options (WINDOW *optwin)
{ {
const int XORIG = 3; const int XORIG = 3;
const int YORIG = 0; const int YORIG = 0;
const int YOFF = 3; const int YOFF = 3;
enum enum { SHOW, DATE, CLOCK, WARN, CMD, NOTIFY_ALL, DMON, DMON_LOG, NB_OPT };
{ SHOW, DATE, CLOCK, WARN, CMD, NOTIFY_ALL, DMON, DMON_LOG, NB_OPT };
struct opt_s struct opt_s {
{
char *name; char *name;
char *desc; char *desc;
char valstr[BUFSIZ]; char valstr[BUFSIZ];
@ -656,7 +592,8 @@ print_config_options (WINDOW *optwin)
opt[CMD].desc = _("(Command used to notify user of an upcoming appointment)"); opt[CMD].desc = _("(Command used to notify user of an upcoming appointment)");
opt[NOTIFY_ALL].name = _("notification.notifyall = "); opt[NOTIFY_ALL].name = _("notification.notifyall = ");
opt[NOTIFY_ALL].desc = _("(Notify all appointments instead of flagged ones only)"); opt[NOTIFY_ALL].desc =
_("(Notify all appointments instead of flagged ones only)");
opt[DMON].name = _("daemon.enable = "); opt[DMON].name = _("daemon.enable = ");
opt[DMON].desc = _("(Run in background to get notifications after exiting)"); opt[DMON].desc = _("(Run in background to get notifications after exiting)");
@ -664,18 +601,18 @@ print_config_options (WINDOW *optwin)
opt[DMON_LOG].name = _("daemon.log = "); opt[DMON_LOG].name = _("daemon.log = ");
opt[DMON_LOG].desc = _("(Log activity when running in background)"); opt[DMON_LOG].desc = _("(Log activity when running in background)");
pthread_mutex_lock (&nbar.mutex); pthread_mutex_lock(&nbar.mutex);
/* String value options */ /* String value options */
strncpy (opt[DATE].valstr, nbar.datefmt, BUFSIZ); strncpy(opt[DATE].valstr, nbar.datefmt, BUFSIZ);
strncpy (opt[CLOCK].valstr, nbar.timefmt, BUFSIZ); strncpy(opt[CLOCK].valstr, nbar.timefmt, BUFSIZ);
snprintf (opt[WARN].valstr, BUFSIZ, "%d", nbar.cntdwn); snprintf(opt[WARN].valstr, BUFSIZ, "%d", nbar.cntdwn);
strncpy (opt[CMD].valstr, nbar.cmd, BUFSIZ); strncpy(opt[CMD].valstr, nbar.cmd, BUFSIZ);
/* Boolean options */ /* Boolean options */
opt[SHOW].valnum = nbar.show; opt[SHOW].valnum = nbar.show;
opt[NOTIFY_ALL].valnum = nbar.notify_all; opt[NOTIFY_ALL].valnum = nbar.notify_all;
pthread_mutex_unlock (&nbar.mutex); pthread_mutex_unlock(&nbar.mutex);
opt[DMON].valnum = dmon.enable; opt[DMON].valnum = dmon.enable;
opt[DMON_LOG].valnum = dmon.log; opt[DMON_LOG].valnum = dmon.log;
@ -683,137 +620,127 @@ print_config_options (WINDOW *optwin)
opt[SHOW].valstr[0] = opt[NOTIFY_ALL].valstr[0] = opt[DMON].valstr[0] = opt[SHOW].valstr[0] = opt[NOTIFY_ALL].valstr[0] = opt[DMON].valstr[0] =
opt[DMON_LOG].valstr[0] = '\0'; opt[DMON_LOG].valstr[0] = '\0';
for (i = 0; i < NB_OPT; i++) for (i = 0; i < NB_OPT; i++) {
{
int y; int y;
y = YORIG + i * YOFF; y = YORIG + i * YOFF;
print_option (optwin, XORIG, y, opt[i].name, opt[i].valstr, print_option(optwin, XORIG, y, opt[i].name, opt[i].valstr,
opt[i].valnum, opt[i].desc, i + 1); opt[i].valnum, opt[i].desc, i + 1);
} }
return YORIG + NB_OPT * YOFF; return YORIG + NB_OPT * YOFF;
} }
static void static void reinit_conf_win(struct scrollwin *win)
reinit_conf_win (struct scrollwin *win)
{ {
unsigned first_line; unsigned first_line;
first_line = win->first_visible_line; first_line = win->first_visible_line;
wins_scrollwin_delete (win); wins_scrollwin_delete(win);
custom_set_swsiz (win); custom_set_swsiz(win);
wins_scrollwin_init (win); wins_scrollwin_init(win);
wins_show (win->win.p, win->label); wins_show(win->win.p, win->label);
win->first_visible_line = first_line; win->first_visible_line = first_line;
} }
/* Notify-bar configuration. */ /* Notify-bar configuration. */
void void notify_config_bar(void)
notify_config_bar (void)
{ {
struct scrollwin cwin; struct scrollwin cwin;
char *buf; char *buf;
const char *number_str = const char *number_str = _("Enter an option number to change its value");
_("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 *keys =
_("(Press '^P' or '^N' to move up or down, 'Q' to quit)");
const char *date_str = const char *date_str =
_("Enter the date format (see 'man 3 strftime' for possible formats) "); _("Enter the date format (see 'man 3 strftime' for possible formats) ");
const char *time_str = const char *time_str =
_("Enter the time format (see 'man 3 strftime' for possible formats) "); _("Enter the time format (see 'man 3 strftime' for possible formats) ");
const char *count_str = const char *count_str =
_("Enter the number of seconds (0 not to be warned before an appointment)"); _
("Enter the number of seconds (0 not to be warned before an appointment)");
const char *cmd_str = _("Enter the notification command "); const char *cmd_str = _("Enter the notification command ");
int ch; int ch;
clear (); clear();
custom_set_swsiz (&cwin); custom_set_swsiz(&cwin);
cwin.label = _("notification options"); cwin.label = _("notification options");
wins_scrollwin_init (&cwin); wins_scrollwin_init(&cwin);
wins_show (cwin.win.p, cwin.label); wins_show(cwin.win.p, cwin.label);
status_mesg (number_str, keys); status_mesg(number_str, keys);
cwin.total_lines = print_config_options (cwin.pad.p); cwin.total_lines = print_config_options(cwin.pad.p);
wins_scrollwin_display (&cwin); wins_scrollwin_display(&cwin);
buf = mem_malloc (BUFSIZ); buf = mem_malloc(BUFSIZ);
while ((ch = wgetch (win[STA].p)) != 'q') while ((ch = wgetch(win[STA].p)) != 'q') {
{
buf[0] = '\0'; buf[0] = '\0';
switch (ch) switch (ch) {
{ case CTRL('N'):
case CTRL ('N'): wins_scrollwin_down(&cwin, 1);
wins_scrollwin_down (&cwin, 1);
break; break;
case CTRL ('P'): case CTRL('P'):
wins_scrollwin_up (&cwin, 1); wins_scrollwin_up(&cwin, 1);
break; break;
case '1': case '1':
pthread_mutex_lock (&nbar.mutex); pthread_mutex_lock(&nbar.mutex);
nbar.show = !nbar.show; nbar.show = !nbar.show;
pthread_mutex_unlock (&nbar.mutex); pthread_mutex_unlock(&nbar.mutex);
if (notify_bar ()) if (notify_bar())
notify_start_main_thread (); notify_start_main_thread();
else else
notify_stop_main_thread (); notify_stop_main_thread();
wins_scrollwin_delete (&cwin); wins_scrollwin_delete(&cwin);
reinit_conf_win (&cwin); reinit_conf_win(&cwin);
break; break;
case '2': case '2':
status_mesg (date_str, ""); status_mesg(date_str, "");
pthread_mutex_lock (&nbar.mutex); pthread_mutex_lock(&nbar.mutex);
strncpy (buf, nbar.datefmt, strlen (nbar.datefmt) + 1); strncpy(buf, nbar.datefmt, strlen(nbar.datefmt) + 1);
pthread_mutex_unlock (&nbar.mutex); pthread_mutex_unlock(&nbar.mutex);
if (updatestring (win[STA].p, &buf, 0, 1) == 0) if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
{ pthread_mutex_lock(&nbar.mutex);
pthread_mutex_lock (&nbar.mutex); strncpy(nbar.datefmt, buf, strlen(buf) + 1);
strncpy (nbar.datefmt, buf, strlen (buf) + 1); pthread_mutex_unlock(&nbar.mutex);
pthread_mutex_unlock (&nbar.mutex);
} }
break; break;
case '3': case '3':
status_mesg (time_str, ""); status_mesg(time_str, "");
pthread_mutex_lock (&nbar.mutex); pthread_mutex_lock(&nbar.mutex);
strncpy (buf, nbar.timefmt, strlen (nbar.timefmt) + 1); strncpy(buf, nbar.timefmt, strlen(nbar.timefmt) + 1);
pthread_mutex_unlock (&nbar.mutex); pthread_mutex_unlock(&nbar.mutex);
if (updatestring (win[STA].p, &buf, 0, 1) == 0) if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
{ pthread_mutex_lock(&nbar.mutex);
pthread_mutex_lock (&nbar.mutex); strncpy(nbar.timefmt, buf, strlen(buf) + 1);
strncpy (nbar.timefmt, buf, strlen (buf) + 1); pthread_mutex_unlock(&nbar.mutex);
pthread_mutex_unlock (&nbar.mutex);
} }
break; break;
case '4': case '4':
status_mesg (count_str, ""); status_mesg(count_str, "");
pthread_mutex_lock (&nbar.mutex); pthread_mutex_lock(&nbar.mutex);
printf (buf, "%d", nbar.cntdwn); printf(buf, "%d", nbar.cntdwn);
pthread_mutex_unlock (&nbar.mutex); pthread_mutex_unlock(&nbar.mutex);
if (updatestring (win[STA].p, &buf, 0, 1) == 0 && if (updatestring(win[STA].p, &buf, 0, 1) == 0 &&
is_all_digit (buf) && atoi (buf) >= 0 && atoi (buf) <= DAYINSEC) is_all_digit(buf) && atoi(buf) >= 0 && atoi(buf) <= DAYINSEC) {
{ pthread_mutex_lock(&nbar.mutex);
pthread_mutex_lock (&nbar.mutex); nbar.cntdwn = atoi(buf);
nbar.cntdwn = atoi (buf); pthread_mutex_unlock(&nbar.mutex);
pthread_mutex_unlock (&nbar.mutex);
} }
break; break;
case '5': case '5':
status_mesg (cmd_str, ""); status_mesg(cmd_str, "");
pthread_mutex_lock (&nbar.mutex); pthread_mutex_lock(&nbar.mutex);
strncpy (buf, nbar.cmd, strlen (nbar.cmd) + 1); strncpy(buf, nbar.cmd, strlen(nbar.cmd) + 1);
pthread_mutex_unlock (&nbar.mutex); pthread_mutex_unlock(&nbar.mutex);
if (updatestring (win[STA].p, &buf, 0, 1) == 0) if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
{ pthread_mutex_lock(&nbar.mutex);
pthread_mutex_lock (&nbar.mutex); strncpy(nbar.cmd, buf, strlen(buf) + 1);
strncpy (nbar.cmd, buf, strlen (buf) + 1); pthread_mutex_unlock(&nbar.mutex);
pthread_mutex_unlock (&nbar.mutex);
} }
break; break;
case '6': case '6':
pthread_mutex_lock (&nbar.mutex); pthread_mutex_lock(&nbar.mutex);
nbar.notify_all = !nbar.notify_all; nbar.notify_all = !nbar.notify_all;
pthread_mutex_unlock (&nbar.mutex); pthread_mutex_unlock(&nbar.mutex);
notify_check_next_app (1); notify_check_next_app(1);
break; break;
case '7': case '7':
dmon.enable = !dmon.enable; dmon.enable = !dmon.enable;
@ -823,28 +750,25 @@ notify_config_bar (void)
break; break;
} }
if (resize) if (resize) {
{
resize = 0; resize = 0;
wins_get_config (); wins_get_config();
wins_reset (); wins_reset();
reinit_conf_win (&cwin); reinit_conf_win(&cwin);
delwin (win[STA].p); delwin(win[STA].p);
win[STA].p = newwin (win[STA].h, win[STA].w, win[STA].y, win[STA].p = newwin(win[STA].h, win[STA].w, win[STA].y, win[STA].x);
win[STA].x); keypad(win[STA].p, TRUE);
keypad (win[STA].p, TRUE); if (notify_bar()) {
if (notify_bar ()) notify_reinit_bar();
{ notify_update_bar();
notify_reinit_bar ();
notify_update_bar ();
} }
clearok (curscr, TRUE); clearok(curscr, TRUE);
} }
status_mesg (number_str, keys); status_mesg(number_str, keys);
cwin.total_lines = print_config_options (cwin.pad.p); cwin.total_lines = print_config_options(cwin.pad.p);
wins_scrollwin_display (&cwin); wins_scrollwin_display(&cwin);
} }
mem_free (buf); mem_free(buf);
wins_scrollwin_delete (&cwin); wins_scrollwin_delete(&cwin);
} }

View File

@ -39,279 +39,253 @@
#include "calcurse.h" #include "calcurse.h"
/* Static functions used to add export functionalities. */ /* Static functions used to add export functionalities. */
static void pcal_export_header (FILE *); static void pcal_export_header(FILE *);
static void pcal_export_recur_events (FILE *); static void pcal_export_recur_events(FILE *);
static void pcal_export_events (FILE *); static void pcal_export_events(FILE *);
static void pcal_export_recur_apoints (FILE *); static void pcal_export_recur_apoints(FILE *);
static void pcal_export_apoints (FILE *); static void pcal_export_apoints(FILE *);
static void pcal_export_todo (FILE *); static void pcal_export_todo(FILE *);
static void pcal_export_footer (FILE *); static void pcal_export_footer(FILE *);
/* Type definition for callbacks to export functions. */ /* Type definition for callbacks to export functions. */
typedef void (*cb_dump_t)(FILE *, long, long, char *); typedef void (*cb_dump_t) (FILE *, long, long, char *);
/* /*
* Travel through each occurence of an item, and execute the given callback * Travel through each occurence of an item, and execute the given callback
* (mainly used to export data). * (mainly used to export data).
*/ */
static void static void
foreach_date_dump (const long date_end, struct rpt *rpt, llist_t *exc, foreach_date_dump(const long date_end, struct rpt *rpt, llist_t * exc,
long item_first_date, long item_dur, char *item_mesg, long item_first_date, long item_dur, char *item_mesg,
cb_dump_t cb_dump, FILE *stream) cb_dump_t cb_dump, FILE * stream)
{ {
long date, item_time; long date, item_time;
struct tm lt; struct tm lt;
time_t t; time_t t;
t = item_first_date; t = item_first_date;
lt = *localtime (&t); lt = *localtime(&t);
lt.tm_hour = lt.tm_min = lt.tm_sec = 0; lt.tm_hour = lt.tm_min = lt.tm_sec = 0;
lt.tm_isdst = -1; lt.tm_isdst = -1;
date = mktime (&lt); date = mktime(&lt);
item_time = item_first_date - date; item_time = item_first_date - date;
while (date <= date_end && date <= rpt->until) while (date <= date_end && date <= rpt->until) {
{ if (recur_item_inday(item_first_date, item_dur, exc, rpt->type,
if (recur_item_inday (item_first_date, item_dur, exc, rpt->type, rpt->freq, rpt->until, date)) {
rpt->freq, rpt->until, date)) (*cb_dump) (stream, date + item_time, item_dur, item_mesg);
{
(*cb_dump)(stream, date + item_time, item_dur, item_mesg);
} }
switch (rpt->type) switch (rpt->type) {
{
case RECUR_DAILY: case RECUR_DAILY:
date = date_sec_change (date, 0, rpt->freq); date = date_sec_change(date, 0, rpt->freq);
break; break;
case RECUR_WEEKLY: case RECUR_WEEKLY:
date = date_sec_change (date, 0, rpt->freq * WEEKINDAYS); date = date_sec_change(date, 0, rpt->freq * WEEKINDAYS);
break; break;
case RECUR_MONTHLY: case RECUR_MONTHLY:
date = date_sec_change (date, rpt->freq, 0); date = date_sec_change(date, rpt->freq, 0);
break; break;
case RECUR_YEARLY: case RECUR_YEARLY:
date = date_sec_change (date, rpt->freq * 12, 0); date = date_sec_change(date, rpt->freq * 12, 0);
break; break;
default: default:
EXIT (_("incoherent repetition type")); EXIT(_("incoherent repetition type"));
/* NOTREACHED */ /* NOTREACHED */
break; break;
} }
} }
} }
static void static void pcal_export_header(FILE * stream)
pcal_export_header (FILE *stream)
{ {
fputs ("# calcurse pcal export\n", stream); fputs("# calcurse pcal export\n", stream);
fputs ("\n# =======\n# options\n# =======\n", stream); fputs("\n# =======\n# options\n# =======\n", stream);
fprintf (stream, "opt -A -K -l -m -F %s\n", fprintf(stream, "opt -A -K -l -m -F %s\n",
calendar_week_begins_on_monday () ? "Monday" : "Sunday"); calendar_week_begins_on_monday()? "Monday" : "Sunday");
fputs ("# Display week number (i.e. 1-52) on every Monday\n", stream); fputs("# Display week number (i.e. 1-52) on every Monday\n", stream);
fprintf (stream, "all monday in all %s %%w\n", _("Week")); fprintf(stream, "all monday in all %s %%w\n", _("Week"));
fputc ('\n', stream); fputc('\n', stream);
} }
static void static void pcal_export_footer(FILE * stream)
pcal_export_footer (FILE *stream)
{ {
} }
/* Format and dump event data to a pcal formatted file. */ /* Format and dump event data to a pcal formatted file. */
static void static void
pcal_dump_event (FILE *stream, long event_date, long event_dur, 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); date_sec2date_fmt(event_date, "%b %d", pcal_date);
fprintf (stream, "%s %s\n", pcal_date, event_mesg); fprintf(stream, "%s %s\n", pcal_date, event_mesg);
} }
/* Format and dump appointment data to a pcal formatted file. */ /* Format and dump appointment data to a pcal formatted file. */
static void static void
pcal_dump_apoint (FILE *stream, long apoint_date, long apoint_dur, 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, "%b %d", pcal_date);
date_sec2date_fmt (apoint_date, "%R", pcal_beg); date_sec2date_fmt(apoint_date, "%R", pcal_beg);
date_sec2date_fmt (apoint_date + apoint_dur, "%R", pcal_end); date_sec2date_fmt(apoint_date + apoint_dur, "%R", pcal_end);
fprintf (stream, "%s ", pcal_date); fprintf(stream, "%s ", pcal_date);
fprintf (stream, "(%s -> %s) %s\n", pcal_beg, pcal_end, apoint_mesg); fprintf(stream, "(%s -> %s) %s\n", pcal_beg, pcal_end, apoint_mesg);
} }
static void static void pcal_export_recur_events(FILE * stream)
pcal_export_recur_events (FILE *stream)
{ {
llist_item_t *i; llist_item_t *i;
char pcal_date[BUFSIZ]; char pcal_date[BUFSIZ];
fputs ("\n# =============", stream); fputs("\n# =============", stream);
fputs ("\n# Recur. Events", stream); fputs("\n# Recur. Events", stream);
fputs ("\n# =============\n", stream); fputs("\n# =============\n", stream);
fputs ("# (pcal does not support from..until dates specification\n", stream); fputs("# (pcal does not support from..until dates specification\n", stream);
LLIST_FOREACH (&recur_elist, i) LLIST_FOREACH(&recur_elist, i) {
{ struct recur_event *rev = LLIST_GET_DATA(i);
struct recur_event *rev = LLIST_GET_DATA (i); if (rev->rpt->until == 0 && rev->rpt->freq == 1) {
if (rev->rpt->until == 0 && rev->rpt->freq == 1) switch (rev->rpt->type) {
{
switch (rev->rpt->type)
{
case RECUR_DAILY: case RECUR_DAILY:
date_sec2date_fmt (rev->day, "%b %d", pcal_date); date_sec2date_fmt(rev->day, "%b %d", pcal_date);
fprintf (stream, "all day on_or_after %s %s\n", pcal_date, fprintf(stream, "all day on_or_after %s %s\n", pcal_date, rev->mesg);
rev->mesg);
break; break;
case RECUR_WEEKLY: case RECUR_WEEKLY:
date_sec2date_fmt (rev->day, "%a", pcal_date); date_sec2date_fmt(rev->day, "%a", pcal_date);
fprintf (stream, "all %s on_or_after ", pcal_date); fprintf(stream, "all %s on_or_after ", pcal_date);
date_sec2date_fmt (rev->day, "%b %d", pcal_date); date_sec2date_fmt(rev->day, "%b %d", pcal_date);
fprintf (stream, "%s %s\n", pcal_date, rev->mesg); fprintf(stream, "%s %s\n", pcal_date, rev->mesg);
break; break;
case RECUR_MONTHLY: case RECUR_MONTHLY:
date_sec2date_fmt (rev->day, "%d", pcal_date); date_sec2date_fmt(rev->day, "%d", pcal_date);
fprintf (stream, "day on all %s %s\n", pcal_date, rev->mesg); fprintf(stream, "day on all %s %s\n", pcal_date, rev->mesg);
break; break;
case RECUR_YEARLY: case RECUR_YEARLY:
date_sec2date_fmt (rev->day, "%b %d", pcal_date); date_sec2date_fmt(rev->day, "%b %d", pcal_date);
fprintf (stream, "%s %s\n", pcal_date, rev->mesg); fprintf(stream, "%s %s\n", pcal_date, rev->mesg);
break; break;
default: default:
EXIT (_("incoherent repetition type")); EXIT(_("incoherent repetition type"));
} }
} } else {
else const long YEAR_START = calendar_start_of_year();
{ const long YEAR_END = calendar_end_of_year();
const long YEAR_START = calendar_start_of_year ();
const long YEAR_END = calendar_end_of_year ();
if (rev->day < YEAR_END && rev->day > YEAR_START) if (rev->day < YEAR_END && rev->day > YEAR_START)
foreach_date_dump (YEAR_END, rev->rpt, &rev->exc, rev->day, 0, foreach_date_dump(YEAR_END, rev->rpt, &rev->exc, rev->day, 0,
rev->mesg, (cb_dump_t) pcal_dump_event, stream); rev->mesg, (cb_dump_t) pcal_dump_event, stream);
} }
} }
} }
static void static void pcal_export_events(FILE * stream)
pcal_export_events (FILE *stream)
{ {
llist_item_t *i; llist_item_t *i;
fputs ("\n# ======\n# Events\n# ======\n", stream); fputs("\n# ======\n# Events\n# ======\n", stream);
LLIST_FOREACH (&eventlist, i) LLIST_FOREACH(&eventlist, i) {
{ struct event *ev = LLIST_TS_GET_DATA(i);
struct event *ev = LLIST_TS_GET_DATA (i); pcal_dump_event(stream, ev->day, 0, ev->mesg);
pcal_dump_event (stream, ev->day, 0, ev->mesg);
} }
fputc ('\n', stream); fputc('\n', stream);
} }
static void static void pcal_export_recur_apoints(FILE * stream)
pcal_export_recur_apoints (FILE *stream)
{ {
llist_item_t *i; llist_item_t *i;
char pcal_date[BUFSIZ], pcal_beg[BUFSIZ], pcal_end[BUFSIZ]; char pcal_date[BUFSIZ], pcal_beg[BUFSIZ], pcal_end[BUFSIZ];
fputs ("\n# ==============", stream); fputs("\n# ==============", stream);
fputs ("\n# Recur. Apoints", stream); fputs("\n# Recur. Apoints", stream);
fputs ("\n# ==============\n", stream); fputs("\n# ==============\n", stream);
fputs ("# (pcal does not support from..until dates specification\n", stream); fputs("# (pcal does not support from..until dates specification\n", stream);
LLIST_TS_FOREACH (&recur_alist_p, i) LLIST_TS_FOREACH(&recur_alist_p, i) {
{ struct recur_apoint *rapt = LLIST_TS_GET_DATA(i);
struct recur_apoint *rapt = LLIST_TS_GET_DATA (i);
if (rapt->rpt->until == 0 && rapt->rpt->freq == 1) if (rapt->rpt->until == 0 && rapt->rpt->freq == 1) {
{ date_sec2date_fmt(rapt->start, "%R", pcal_beg);
date_sec2date_fmt (rapt->start, "%R", pcal_beg); date_sec2date_fmt(rapt->start + rapt->dur, "%R", pcal_end);
date_sec2date_fmt (rapt->start + rapt->dur, "%R", pcal_end); switch (rapt->rpt->type) {
switch (rapt->rpt->type)
{
case RECUR_DAILY: case RECUR_DAILY:
date_sec2date_fmt (rapt->start, "%b %d", pcal_date); date_sec2date_fmt(rapt->start, "%b %d", pcal_date);
fprintf (stream, "all day on_or_after %s (%s -> %s) %s\n", fprintf(stream, "all day on_or_after %s (%s -> %s) %s\n",
pcal_date, pcal_beg, pcal_end, rapt->mesg); pcal_date, pcal_beg, pcal_end, rapt->mesg);
break; break;
case RECUR_WEEKLY: case RECUR_WEEKLY:
date_sec2date_fmt (rapt->start, "%a", pcal_date); date_sec2date_fmt(rapt->start, "%a", pcal_date);
fprintf (stream, "all %s on_or_after ", pcal_date); fprintf(stream, "all %s on_or_after ", pcal_date);
date_sec2date_fmt (rapt->start, "%b %d", pcal_date); date_sec2date_fmt(rapt->start, "%b %d", pcal_date);
fprintf (stream, "%s (%s -> %s) %s\n", pcal_date, pcal_beg, fprintf(stream, "%s (%s -> %s) %s\n", pcal_date, pcal_beg,
pcal_end, rapt->mesg); pcal_end, rapt->mesg);
break; break;
case RECUR_MONTHLY: case RECUR_MONTHLY:
date_sec2date_fmt (rapt->start, "%d", pcal_date); date_sec2date_fmt(rapt->start, "%d", pcal_date);
fprintf (stream, "day on all %s (%s -> %s) %s\n", pcal_date, fprintf(stream, "day on all %s (%s -> %s) %s\n", pcal_date,
pcal_beg, pcal_end, rapt->mesg); pcal_beg, pcal_end, rapt->mesg);
break; break;
case RECUR_YEARLY: case RECUR_YEARLY:
date_sec2date_fmt (rapt->start, "%b %d", pcal_date); date_sec2date_fmt(rapt->start, "%b %d", pcal_date);
fprintf (stream, "%s (%s -> %s) %s\n", pcal_date, pcal_beg, fprintf(stream, "%s (%s -> %s) %s\n", pcal_date, pcal_beg,
pcal_end, rapt->mesg); pcal_end, rapt->mesg);
break; break;
default: default:
EXIT (_("incoherent repetition type")); EXIT(_("incoherent repetition type"));
} }
} } else {
else const long YEAR_START = calendar_start_of_year();
{ const long YEAR_END = calendar_end_of_year();
const long YEAR_START = calendar_start_of_year ();
const long YEAR_END = calendar_end_of_year ();
if (rapt->start < YEAR_END && rapt->start > YEAR_START) if (rapt->start < YEAR_END && rapt->start > YEAR_START)
foreach_date_dump (YEAR_END, rapt->rpt, &rapt->exc, rapt->start, foreach_date_dump(YEAR_END, rapt->rpt, &rapt->exc, rapt->start,
rapt->dur, rapt->mesg, rapt->dur, rapt->mesg,
(cb_dump_t)pcal_dump_apoint, stream); (cb_dump_t) pcal_dump_apoint, stream);
} }
} }
} }
static void static void pcal_export_apoints(FILE * stream)
pcal_export_apoints (FILE *stream)
{ {
llist_item_t *i; llist_item_t *i;
fputs ("\n# ============\n# Appointments\n# ============\n", stream); fputs("\n# ============\n# Appointments\n# ============\n", stream);
LLIST_TS_LOCK (&alist_p); LLIST_TS_LOCK(&alist_p);
LLIST_TS_FOREACH (&alist_p, i) LLIST_TS_FOREACH(&alist_p, i) {
{ struct apoint *apt = LLIST_TS_GET_DATA(i);
struct apoint *apt = LLIST_TS_GET_DATA (i); pcal_dump_apoint(stream, apt->start, apt->dur, apt->mesg);
pcal_dump_apoint (stream, apt->start, apt->dur, apt->mesg);
} }
LLIST_TS_UNLOCK (&alist_p); LLIST_TS_UNLOCK(&alist_p);
fputc ('\n', stream); fputc('\n', stream);
} }
static void static void pcal_export_todo(FILE * stream)
pcal_export_todo (FILE *stream)
{ {
llist_item_t *i; llist_item_t *i;
fputs ("#\n# Todos\n#\n", stream); fputs("#\n# Todos\n#\n", stream);
LLIST_FOREACH (&todolist, i) LLIST_FOREACH(&todolist, i) {
{ struct todo *todo = LLIST_TS_GET_DATA(i);
struct todo *todo = LLIST_TS_GET_DATA (i);
if (todo->id < 0) /* completed items */ if (todo->id < 0) /* completed items */
continue; continue;
fputs ("note all ", stream); fputs("note all ", stream);
fprintf (stream, "%d. %s\n", todo->id, todo->mesg); fprintf(stream, "%d. %s\n", todo->id, todo->mesg);
} }
fputc ('\n', stream); fputc('\n', stream);
} }
/* Export calcurse data. */ /* Export calcurse data. */
void void pcal_export_data(FILE * stream)
pcal_export_data (FILE *stream)
{ {
pcal_export_header (stream); pcal_export_header(stream);
pcal_export_recur_events (stream); pcal_export_recur_events(stream);
pcal_export_events (stream); pcal_export_events(stream);
pcal_export_recur_apoints (stream); pcal_export_recur_apoints(stream);
pcal_export_apoints (stream); pcal_export_apoints(stream);
pcal_export_todo (stream); pcal_export_todo(stream);
pcal_export_footer (stream); pcal_export_footer(stream);
} }

File diff suppressed because it is too large Load Diff

View File

@ -67,61 +67,100 @@
#define R4(v, w, x, y, z, i) z += (w ^ x ^ y) + blk (i) + 0xCA62C1D6 + \ #define R4(v, w, x, y, z, i) z += (w ^ x ^ y) + blk (i) + 0xCA62C1D6 + \
rol (v, 5); w = rol (w, 30); rol (v, 5); w = rol (w, 30);
static void static void sha1_transform(uint32_t state[5], const uint8_t buffer[64])
sha1_transform (uint32_t state[5], const uint8_t buffer[64])
{ {
typedef union { typedef union {
uint8_t c[64]; uint8_t c[64];
uint32_t l[16]; uint32_t l[16];
} b64_t; } b64_t;
b64_t *block = (b64_t *)buffer; b64_t *block = (b64_t *) buffer;
uint32_t a = state[0]; uint32_t a = state[0];
uint32_t b = state[1]; uint32_t b = state[1];
uint32_t c = state[2]; uint32_t c = state[2];
uint32_t d = state[3]; uint32_t d = state[3];
uint32_t e = state[4]; uint32_t e = state[4];
R0 (a, b, c, d, e, 0); R0 (e, a, b, c, d, 1); R0(a, b, c, d, e, 0);
R0 (d, e, a, b, c, 2); R0 (c, d, e, a, b, 3); R0(e, a, b, c, d, 1);
R0 (b, c, d, e, a, 4); R0 (a, b, c, d, e, 5); R0(d, e, a, b, c, 2);
R0 (e, a, b, c, d, 6); R0 (d, e, a, b, c, 7); R0(c, d, e, a, b, 3);
R0 (c, d, e, a, b, 8); R0 (b, c, d, e, a, 9); R0(b, c, d, e, a, 4);
R0 (a, b, c, d, e, 10); R0 (e, a, b, c, d, 11); R0(a, b, c, d, e, 5);
R0 (d, e, a, b, c, 12); R0 (c, d, e, a, b, 13); R0(e, a, b, c, d, 6);
R0 (b, c, d, e, a, 14); R0 (a, b, c, d, e, 15); R0(d, e, a, b, c, 7);
R1 (e, a, b, c, d, 16); R1 (d, e, a, b, c, 17); R0(c, d, e, a, b, 8);
R1 (c, d, e, a, b, 18); R1 (b, c, d, e, a, 19); R0(b, c, d, e, a, 9);
R2 (a, b, c, d, e, 20); R2 (e, a, b, c, d, 21); R0(a, b, c, d, e, 10);
R2 (d, e, a, b, c, 22); R2 (c, d, e, a, b, 23); R0(e, a, b, c, d, 11);
R2 (b, c, d, e, a, 24); R2 (a, b, c, d, e, 25); R0(d, e, a, b, c, 12);
R2 (e, a, b, c, d, 26); R2 (d, e, a, b, c, 27); R0(c, d, e, a, b, 13);
R2 (c, d, e, a, b, 28); R2 (b, c, d, e, a, 29); R0(b, c, d, e, a, 14);
R2 (a, b, c, d, e, 30); R2 (e, a, b, c, d, 31); R0(a, b, c, d, e, 15);
R2 (d, e, a, b, c, 32); R2 (c, d, e, a, b, 33); R1(e, a, b, c, d, 16);
R2 (b, c, d, e, a, 34); R2 (a, b, c, d, e, 35); R1(d, e, a, b, c, 17);
R2 (e, a, b, c, d, 36); R2 (d, e, a, b, c, 37); R1(c, d, e, a, b, 18);
R2 (c, d, e, a, b, 38); R2 (b, c, d, e, a, 39); R1(b, c, d, e, a, 19);
R3 (a, b, c, d, e, 40); R3 (e, a, b, c, d, 41); R2(a, b, c, d, e, 20);
R3 (d, e, a, b, c, 42); R3 (c, d, e, a, b, 43); R2(e, a, b, c, d, 21);
R3 (b, c, d, e, a, 44); R3 (a, b, c, d, e, 45); R2(d, e, a, b, c, 22);
R3 (e, a, b, c, d, 46); R3 (d, e, a, b, c, 47); R2(c, d, e, a, b, 23);
R3 (c, d, e, a, b, 48); R3 (b, c, d, e, a, 49); R2(b, c, d, e, a, 24);
R3 (a, b, c, d, e, 50); R3 (e, a, b, c, d, 51); R2(a, b, c, d, e, 25);
R3 (d, e, a, b, c, 52); R3 (c, d, e, a, b, 53); R2(e, a, b, c, d, 26);
R3 (b, c, d, e, a, 54); R3 (a, b, c, d, e, 55); R2(d, e, a, b, c, 27);
R3 (e, a, b, c, d, 56); R3 (d, e, a, b, c, 57); R2(c, d, e, a, b, 28);
R3 (c, d, e, a, b, 58); R3 (b, c, d, e, a, 59); R2(b, c, d, e, a, 29);
R4 (a, b, c, d, e, 60); R4 (e, a, b, c, d, 61); R2(a, b, c, d, e, 30);
R4 (d, e, a, b, c, 62); R4 (c, d, e, a, b, 63); R2(e, a, b, c, d, 31);
R4 (b, c, d, e, a, 64); R4 (a, b, c, d, e, 65); R2(d, e, a, b, c, 32);
R4 (e, a, b, c, d, 66); R4 (d, e, a, b, c, 67); R2(c, d, e, a, b, 33);
R4 (c, d, e, a, b, 68); R4 (b, c, d, e, a, 69); R2(b, c, d, e, a, 34);
R4 (a, b, c, d, e, 70); R4 (e, a, b, c, d, 71); R2(a, b, c, d, e, 35);
R4 (d, e, a, b, c, 72); R4 (c, d, e, a, b, 73); R2(e, a, b, c, d, 36);
R4 (b, c, d, e, a, 74); R4 (a, b, c, d, e, 75); R2(d, e, a, b, c, 37);
R4 (e, a, b, c, d, 76); R4 (d, e, a, b, c, 77); R2(c, d, e, a, b, 38);
R4 (c, d, e, a, b, 78); R4 (b, c, d, e, a, 79); 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[0] += a;
state[1] += b; state[1] += b;
@ -132,9 +171,7 @@ sha1_transform (uint32_t state[5], const uint8_t buffer[64])
a = b = c = d = e = 0; a = b = c = d = e = 0;
} }
void sha1_init(sha1_ctx_t * ctx)
void
sha1_init (sha1_ctx_t *ctx)
{ {
ctx->state[0] = 0x67452301; ctx->state[0] = 0x67452301;
ctx->state[1] = 0xEFCDAB89; ctx->state[1] = 0xEFCDAB89;
@ -145,8 +182,7 @@ sha1_init (sha1_ctx_t *ctx)
ctx->count[0] = ctx->count[1] = 0; ctx->count[0] = ctx->count[1] = 0;
} }
void void sha1_update(sha1_ctx_t * ctx, const uint8_t * data, unsigned int len)
sha1_update (sha1_ctx_t *ctx, const uint8_t *data, unsigned int len)
{ {
unsigned int i, j; unsigned int i, j;
@ -155,67 +191,59 @@ sha1_update (sha1_ctx_t *ctx, const uint8_t *data, unsigned int len)
ctx->count[1]++; ctx->count[1]++;
ctx->count[1] += (len >> 29); ctx->count[1] += (len >> 29);
if (j + len > 63) if (j + len > 63) {
{ memcpy(&ctx->buffer[j], data, (i = 64 - j));
memcpy (&ctx->buffer[j], data, (i = 64 - j)); sha1_transform(ctx->state, ctx->buffer);
sha1_transform (ctx->state, ctx->buffer);
for (; i + 63 < len; i += 64) for (; i + 63 < len; i += 64)
sha1_transform (ctx->state, &data[i]); sha1_transform(ctx->state, &data[i]);
j = 0; j = 0;
} } else
else
i = 0; i = 0;
memcpy (&ctx->buffer[j], &data[i], len - i); memcpy(&ctx->buffer[j], &data[i], len - i);
} }
void sha1_final(sha1_ctx_t * ctx, uint8_t digest[SHA1_DIGESTLEN])
void
sha1_final (sha1_ctx_t *ctx, uint8_t digest[SHA1_DIGESTLEN])
{ {
uint32_t i, j; uint32_t i, j;
uint8_t finalcount[8]; uint8_t finalcount[8];
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++) {
{ finalcount[i] = (uint8_t) ((ctx->count[(i >= 4 ? 0 : 1)] >>
finalcount[i] = (uint8_t)((ctx->count[(i >= 4 ? 0 : 1)] >>
((3 - (i & 3)) * 8)) & 255); ((3 - (i & 3)) * 8)) & 255);
} }
sha1_update (ctx, (uint8_t *)"\200", 1); sha1_update(ctx, (uint8_t *) "\200", 1);
while ((ctx->count[0] & 504) != 448) while ((ctx->count[0] & 504) != 448)
sha1_update (ctx, (uint8_t *)"\0", 1); sha1_update(ctx, (uint8_t *) "\0", 1);
sha1_update (ctx, finalcount, 8); sha1_update(ctx, finalcount, 8);
for (i = 0; i < SHA1_DIGESTLEN; i++) for (i = 0; i < SHA1_DIGESTLEN; i++)
digest[i] = (uint8_t)((ctx->state[i >> 2] >> ((3 - (i & 3)) * 8)) & 255); digest[i] = (uint8_t) ((ctx->state[i >> 2] >> ((3 - (i & 3)) * 8)) & 255);
i = j = 0; i = j = 0;
memset (ctx->buffer, 0, SHA1_BLOCKLEN); memset(ctx->buffer, 0, SHA1_BLOCKLEN);
memset (ctx->state, 0, SHA1_DIGESTLEN); memset(ctx->state, 0, SHA1_DIGESTLEN);
memset (ctx->count, 0, 8); memset(ctx->count, 0, 8);
memset (&finalcount, 0, 8); memset(&finalcount, 0, 8);
} }
void void sha1_digest(const char *data, char *buffer)
sha1_digest (const char *data, char *buffer)
{ {
sha1_ctx_t ctx; sha1_ctx_t ctx;
uint8_t digest[SHA1_DIGESTLEN]; uint8_t digest[SHA1_DIGESTLEN];
int i; int i;
sha1_init (&ctx); sha1_init(&ctx);
sha1_update (&ctx, (const uint8_t *)data, strlen (data)); sha1_update(&ctx, (const uint8_t *)data, strlen(data));
sha1_final (&ctx, (uint8_t *)digest); sha1_final(&ctx, (uint8_t *) digest);
for (i = 0; i < SHA1_DIGESTLEN; i++) for (i = 0; i < SHA1_DIGESTLEN; i++) {
{ snprintf(buffer, 3, "%02x", digest[i]);
snprintf (buffer, 3, "%02x", digest[i]); buffer += sizeof(char) * 2;
buffer += sizeof (char) * 2;
} }
} }
void void sha1_stream(FILE * fp, char *buffer)
sha1_stream (FILE *fp, char *buffer)
{ {
sha1_ctx_t ctx; sha1_ctx_t ctx;
uint8_t data[BUFSIZ]; uint8_t data[BUFSIZ];
@ -223,19 +251,17 @@ sha1_stream (FILE *fp, char *buffer)
uint8_t digest[SHA1_DIGESTLEN]; uint8_t digest[SHA1_DIGESTLEN];
int i; int i;
sha1_init (&ctx); sha1_init(&ctx);
while (!feof (fp)) while (!feof(fp)) {
{ bytes_read = fread(data, 1, BUFSIZ, fp);
bytes_read = fread (data, 1, BUFSIZ, fp); sha1_update(&ctx, data, bytes_read);
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++) for (i = 0; i < SHA1_DIGESTLEN; i++) {
{ snprintf(buffer, 3, "%02x", digest[i]);
snprintf (buffer, 3, "%02x", digest[i]); buffer += sizeof(char) * 2;
buffer += sizeof (char) * 2;
} }
} }

View File

@ -50,8 +50,8 @@ typedef struct {
uint8_t buffer[SHA1_BLOCKLEN]; uint8_t buffer[SHA1_BLOCKLEN];
} sha1_ctx_t; } sha1_ctx_t;
void sha1_init (sha1_ctx_t *); void sha1_init(sha1_ctx_t *);
void sha1_update (sha1_ctx_t *, const uint8_t *, unsigned int); void sha1_update(sha1_ctx_t *, const uint8_t *, unsigned int);
void sha1_final (sha1_ctx_t *, uint8_t *); void sha1_final(sha1_ctx_t *, uint8_t *);
void sha1_digest (const char *, char *); void sha1_digest(const char *, char *);
void sha1_stream (FILE *, char *); void sha1_stream(FILE *, char *);

View File

@ -53,44 +53,36 @@
* This is needed to avoid zombie processes running on system. * This is needed to avoid zombie processes running on system.
* Also catch CTRL-C (SIGINT), and SIGWINCH to resize screen automatically. * Also catch CTRL-C (SIGINT), and SIGWINCH to resize screen automatically.
*/ */
static void static void generic_hdlr(int sig)
generic_hdlr (int sig)
{ {
switch (sig) switch (sig) {
{
case SIGCHLD: case SIGCHLD:
while (waitpid (WAIT_MYPGRP, NULL, WNOHANG) > 0) while (waitpid(WAIT_MYPGRP, NULL, WNOHANG) > 0) ;
;
break; break;
case SIGWINCH: case SIGWINCH:
resize = 1; resize = 1;
clearok (curscr, TRUE); clearok(curscr, TRUE);
ungetch (KEY_RESIZE); ungetch(KEY_RESIZE);
break; break;
case SIGTERM: case SIGTERM:
if (unlink (path_cpid) != 0) if (unlink(path_cpid) != 0) {
{ EXIT(_("Could not remove calcurse lock file: %s\n"), strerror(errno));
EXIT (_("Could not remove calcurse lock file: %s\n"),
strerror (errno));
} }
exit (EXIT_SUCCESS); exit(EXIT_SUCCESS);
break; break;
} }
} }
unsigned unsigned sigs_set_hdlr(int sig, void (*handler) (int))
sigs_set_hdlr (int sig, void (*handler)(int))
{ {
struct sigaction sa; struct sigaction sa;
memset (&sa, 0, sizeof sa); memset(&sa, 0, sizeof sa);
sigemptyset (&sa.sa_mask); sigemptyset(&sa.sa_mask);
sa.sa_handler = handler; sa.sa_handler = handler;
sa.sa_flags = 0; sa.sa_flags = 0;
if (sigaction (sig, &sa, NULL) == -1) if (sigaction(sig, &sa, NULL) == -1) {
{ ERROR_MSG(_("Error setting signal #%d : %s\n"), sig, strerror(errno));
ERROR_MSG (_("Error setting signal #%d : %s\n"),
sig, strerror (errno));
return 0; return 0;
} }
@ -98,12 +90,11 @@ sigs_set_hdlr (int sig, void (*handler)(int))
} }
/* Signal handling init. */ /* Signal handling init. */
void void sigs_init()
sigs_init ()
{ {
if (!sigs_set_hdlr (SIGCHLD, generic_hdlr) if (!sigs_set_hdlr(SIGCHLD, generic_hdlr)
|| !sigs_set_hdlr (SIGWINCH, generic_hdlr) || !sigs_set_hdlr(SIGWINCH, generic_hdlr)
|| !sigs_set_hdlr (SIGTERM, generic_hdlr) || !sigs_set_hdlr(SIGTERM, generic_hdlr)
|| !sigs_set_hdlr (SIGINT, SIG_IGN)) || !sigs_set_hdlr(SIGINT, SIG_IGN))
exit_calcurse (1); exit_calcurse(1);
} }

View File

@ -47,67 +47,57 @@ static int first = 1;
static char *msgsav; static char *msgsav;
/* Returns a structure containing the selected item. */ /* Returns a structure containing the selected item. */
static struct todo * static struct todo *todo_get_item(int item_number)
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));
} }
/* Sets which todo is highlighted. */ /* Sets which todo is highlighted. */
void void todo_hilt_set(int highlighted)
todo_hilt_set (int highlighted)
{ {
hilt = highlighted; hilt = highlighted;
} }
void void todo_hilt_decrease(int n)
todo_hilt_decrease (int n)
{ {
hilt -= n; hilt -= n;
} }
void void todo_hilt_increase(int n)
todo_hilt_increase (int n)
{ {
hilt += n; hilt += n;
} }
/* Return which todo is highlighted. */ /* Return which todo is highlighted. */
int int todo_hilt(void)
todo_hilt (void)
{ {
return hilt; return hilt;
} }
/* Return the number of todos. */ /* Return the number of todos. */
int int todo_nb(void)
todo_nb (void)
{ {
return todos; return todos;
} }
/* Set the number of todos. */ /* Set the number of todos. */
void void todo_set_nb(int nb)
todo_set_nb (int nb)
{ {
todos = nb; todos = nb;
} }
/* Set which one is the first todo to be displayed. */ /* Set which one is the first todo to be displayed. */
void void todo_set_first(int nb)
todo_set_first (int nb)
{ {
first = nb; first = nb;
} }
void void todo_first_increase(int n)
todo_first_increase (int n)
{ {
first += n; first += n;
} }
void void todo_first_decrease(int n)
todo_first_decrease (int n)
{ {
first -= n; first -= n;
} }
@ -116,51 +106,46 @@ todo_first_decrease (int n)
* Return the position of the hilghlighted item, relative to the first one * Return the position of the hilghlighted item, relative to the first one
* displayed. * displayed.
*/ */
int int todo_hilt_pos(void)
todo_hilt_pos (void)
{ {
return hilt - first; return hilt - first;
} }
/* Return the last visited todo. */ /* Return the last visited todo. */
char * char *todo_saved_mesg(void)
todo_saved_mesg (void)
{ {
return msgsav; return msgsav;
} }
/* Request user to enter a new todo item. */ /* Request user to enter a new todo item. */
void void todo_new_item(void)
todo_new_item (void)
{ {
int ch = 0; int ch = 0;
const char *mesg = _("Enter the new ToDo item : "); const char *mesg = _("Enter the new ToDo item : ");
const char *mesg_id = _("Enter the ToDo priority [1 (highest) - 9 (lowest)] :"); const char *mesg_id =
_("Enter the ToDo priority [1 (highest) - 9 (lowest)] :");
char todo_input[BUFSIZ] = ""; char todo_input[BUFSIZ] = "";
status_mesg (mesg, ""); status_mesg(mesg, "");
if (getstring (win[STA].p, todo_input, BUFSIZ, 0, 1) == GETSTRING_VALID) if (getstring(win[STA].p, todo_input, BUFSIZ, 0, 1) == GETSTRING_VALID) {
{ while ((ch < '1') || (ch > '9')) {
while ((ch < '1') || (ch > '9')) status_mesg(mesg_id, "");
{ ch = wgetch(win[STA].p);
status_mesg (mesg_id, "");
ch = wgetch (win[STA].p);
} }
todo_add (todo_input, ch - '0', NULL); todo_add(todo_input, ch - '0', NULL);
todos++; todos++;
} }
} }
static int static int todo_cmp_id(struct todo *a, struct todo *b)
todo_cmp_id (struct todo *a, struct todo *b)
{ {
/* /*
* As of version 2.6, todo items can have a negative id, which means they * 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 * were completed. To keep them sorted, we need to consider the absolute id
* value. * value.
*/ */
int abs_a = abs (a->id); int abs_a = abs(a->id);
int abs_b = abs (b->id); int abs_b = abs(b->id);
return abs_a < abs_b ? -1 : (abs_a == abs_b ? 0 : 1); return abs_a < abs_b ? -1 : (abs_a == abs_b ? 0 : 1);
} }
@ -168,59 +153,55 @@ todo_cmp_id (struct todo *a, struct todo *b)
/* /*
* Add an item in the todo linked list. * Add an item in the todo linked list.
*/ */
struct todo * struct todo *todo_add(char *mesg, int id, char *note)
todo_add (char *mesg, int id, char *note)
{ {
struct todo *todo; struct todo *todo;
todo = mem_malloc (sizeof (struct todo)); todo = mem_malloc(sizeof(struct todo));
todo->mesg = mem_strdup (mesg); todo->mesg = mem_strdup(mesg);
todo->id = id; todo->id = id;
todo->note = (note != NULL && note[0] != '\0') ? mem_strdup (note) : NULL; 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 void todo_write(struct todo *todo, FILE * f)
todo_write (struct todo *todo, FILE *f)
{ {
if (todo->note) if (todo->note)
fprintf (f, "[%d]>%s %s\n", todo->id, todo->note, todo->mesg); fprintf(f, "[%d]>%s %s\n", todo->id, todo->note, todo->mesg);
else else
fprintf (f, "[%d] %s\n", todo->id, todo->mesg); fprintf(f, "[%d] %s\n", todo->id, todo->mesg);
} }
/* Delete a note previously attached to a todo item. */ /* Delete a note previously attached to a todo item. */
static void static void todo_delete_note_bynum(unsigned num)
todo_delete_note_bynum (unsigned num)
{ {
llist_item_t *i = LLIST_NTH (&todolist, num); llist_item_t *i = LLIST_NTH(&todolist, num);
if (!i) if (!i)
EXIT (_("no such todo")); EXIT(_("no such todo"));
struct todo *todo = LLIST_TS_GET_DATA (i); struct todo *todo = LLIST_TS_GET_DATA(i);
if (!todo->note) if (!todo->note)
EXIT (_("no note attached")); EXIT(_("no note attached"));
erase_note (&todo->note); erase_note(&todo->note);
} }
/* Delete an item from the todo linked list. */ /* Delete an item from the todo linked list. */
static void static void todo_delete_bynum(unsigned num)
todo_delete_bynum (unsigned num)
{ {
llist_item_t *i = LLIST_NTH (&todolist, num); llist_item_t *i = LLIST_NTH(&todolist, num);
if (!i) if (!i)
EXIT (_("no such todo")); EXIT(_("no such todo"));
struct todo *todo = LLIST_TS_GET_DATA (i); struct todo *todo = LLIST_TS_GET_DATA(i);
LLIST_REMOVE (&todolist, i); LLIST_REMOVE(&todolist, i);
mem_free (todo->mesg); mem_free(todo->mesg);
erase_note (&todo->note); erase_note(&todo->note);
mem_free (todo); mem_free(todo);
} }
/* /*
@ -229,18 +210,16 @@ todo_delete_bynum (unsigned num)
* This way, it is easy to retrive its original priority if the user decides * This way, it is easy to retrive its original priority if the user decides
* that in fact it was not completed. * that in fact it was not completed.
*/ */
void void todo_flag(void)
todo_flag (void)
{ {
struct todo *t; struct todo *t;
t = todo_get_item (hilt); t = todo_get_item(hilt);
t->id = -t->id; t->id = -t->id;
} }
/* Delete an item from the ToDo list. */ /* Delete an item from the ToDo list. */
void void todo_delete(void)
todo_delete (void)
{ {
const char *del_todo_str = _("Do you really want to delete this task ?"); const char *del_todo_str = _("Do you really want to delete this task ?");
const char *erase_warning = const char *erase_warning =
@ -251,22 +230,20 @@ todo_delete (void)
int answer; int answer;
if ((todos <= 0) || if ((todos <= 0) ||
(conf.confirm_delete && (status_ask_bool (del_todo_str) != 1))) (conf.confirm_delete && (status_ask_bool(del_todo_str) != 1))) {
{ wins_erase_status_bar();
wins_erase_status_bar ();
return; return;
} }
/* This todo item doesn't have any note associated. */ /* This todo item doesn't have any note associated. */
if (todo_get_item (hilt)->note == NULL) if (todo_get_item(hilt)->note == NULL)
answer = 1; answer = 1;
else else
answer = status_ask_choice (erase_warning, erase_choice, nb_erase_choice); answer = status_ask_choice(erase_warning, erase_choice, nb_erase_choice);
switch (answer) switch (answer) {
{
case 1: case 1:
todo_delete_bynum (hilt - 1); todo_delete_bynum(hilt - 1);
todos--; todos--;
if (hilt > 1) if (hilt > 1)
hilt--; hilt--;
@ -276,10 +253,10 @@ todo_delete (void)
first--; first--;
break; break;
case 2: case 2:
todo_delete_note_bynum (hilt - 1); todo_delete_note_bynum(hilt - 1);
break; break;
default: default:
wins_erase_status_bar (); wins_erase_status_bar();
return; return;
} }
} }
@ -288,41 +265,37 @@ todo_delete (void)
* Returns the position into the linked list corresponding to the * Returns the position into the linked list corresponding to the
* given todo item. * given todo item.
*/ */
static int static int todo_get_position(struct todo *needle)
todo_get_position (struct todo *needle)
{ {
llist_item_t *i; llist_item_t *i;
int n = 0; int n = 0;
LLIST_FOREACH (&todolist, i) LLIST_FOREACH(&todolist, i) {
{
n++; n++;
if (LLIST_TS_GET_DATA (i) == needle) if (LLIST_TS_GET_DATA(i) == needle)
return n; return n;
} }
EXIT (_("todo not found")); EXIT(_("todo not found"));
return -1; /* avoid compiler warnings */ return -1; /* avoid compiler warnings */
} }
/* Change an item priority by pressing '+' or '-' inside TODO panel. */ /* Change an item priority by pressing '+' or '-' inside TODO panel. */
void void todo_chg_priority(int action)
todo_chg_priority (int action)
{ {
struct todo *backup; struct todo *backup;
char backup_mesg[BUFSIZ]; char backup_mesg[BUFSIZ];
int backup_id; int backup_id;
char backup_note[MAX_NOTESIZ + 1]; char backup_note[MAX_NOTESIZ + 1];
backup = todo_get_item (hilt); backup = todo_get_item(hilt);
strncpy (backup_mesg, backup->mesg, strlen (backup->mesg) + 1); strncpy(backup_mesg, backup->mesg, strlen(backup->mesg) + 1);
backup_id = backup->id; backup_id = backup->id;
if (backup->note) if (backup->note)
strncpy (backup_note, backup->note, MAX_NOTESIZ + 1); strncpy(backup_note, backup->note, MAX_NOTESIZ + 1);
else else
backup_note[0] = '\0'; backup_note[0] = '\0';
switch (action) switch (action) {
{
case KEY_RAISE_PRIORITY: case KEY_RAISE_PRIORITY:
if (backup_id > 1) if (backup_id > 1)
backup_id--; backup_id--;
@ -336,30 +309,29 @@ todo_chg_priority (int action)
return; return;
break; break;
default: default:
EXIT (_("no such action")); EXIT(_("no such action"));
/* NOTREACHED */ /* NOTREACHED */
} }
todo_delete_bynum (hilt - 1); todo_delete_bynum(hilt - 1);
backup = todo_add (backup_mesg, backup_id, backup_note); backup = todo_add(backup_mesg, backup_id, backup_note);
hilt = todo_get_position (backup); hilt = todo_get_position(backup);
} }
/* Edit the description of an already existing todo item. */ /* Edit the description of an already existing todo item. */
void void todo_edit_item(void)
todo_edit_item (void)
{ {
struct todo *i; struct todo *i;
const char *mesg = _("Enter the new ToDo description :"); const char *mesg = _("Enter the new ToDo description :");
status_mesg (mesg, ""); status_mesg(mesg, "");
i = todo_get_item (hilt); i = todo_get_item(hilt);
updatestring (win[STA].p, &i->mesg, 0, 1); updatestring(win[STA].p, &i->mesg, 0, 1);
} }
/* Display todo items in the corresponding panel. */ /* Display todo items in the corresponding panel. */
static void static void
display_todo_item (int incolor, char *msg, int prio, int note, int width, int y, display_todo_item(int incolor, char *msg, int prio, int note, int width, int y,
int x) int x)
{ {
WINDOW *w; WINDOW *w;
@ -370,35 +342,32 @@ display_todo_item (int incolor, char *msg, int prio, int note, int width, int y,
w = win[TOD].p; w = win[TOD].p;
ch_note = (note) ? '>' : '.'; ch_note = (note) ? '>' : '.';
if (prio > 0) if (prio > 0)
snprintf (priostr, sizeof priostr, "%d", prio); snprintf(priostr, sizeof priostr, "%d", prio);
else else
strncpy (priostr, "X", sizeof priostr); strncpy(priostr, "X", sizeof priostr);
if (incolor == 0) if (incolor == 0)
custom_apply_attr (w, ATTR_HIGHEST); custom_apply_attr(w, ATTR_HIGHEST);
if (utf8_strwidth (msg) < width) if (utf8_strwidth(msg) < width)
mvwprintw (w, y, x, "%s%c %s", priostr, ch_note, msg); mvwprintw(w, y, x, "%s%c %s", priostr, ch_note, msg);
else else {
{ for (i = 0; msg[i] && width > 0; i++) {
for (i = 0; msg[i] && width > 0; i++) if (!UTF8_ISCONT(msg[i]))
{ width -= utf8_width(&msg[i]);
if (!UTF8_ISCONT (msg[i]))
width -= utf8_width (&msg[i]);
buf[i] = msg[i]; buf[i] = msg[i];
} }
if (i) if (i)
buf[i - 1] = 0; buf[i - 1] = 0;
else else
buf[0] = 0; buf[0] = 0;
mvwprintw (w, y, x, "%s%c %s...", priostr, ch_note, buf); mvwprintw(w, y, x, "%s%c %s...", priostr, ch_note, buf);
} }
if (incolor == 0) if (incolor == 0)
custom_remove_attr (w, ATTR_HIGHEST); custom_remove_attr(w, ATTR_HIGHEST);
} }
/* Updates the ToDo panel. */ /* Updates the ToDo panel. */
void void todo_update_panel(int which_pan)
todo_update_panel (int which_pan)
{ {
llist_item_t *i; llist_item_t *i;
int len = win[TOD].w - 8; int len = win[TOD].w - 8;
@ -411,62 +380,54 @@ todo_update_panel (int which_pan)
int incolor = -1; int incolor = -1;
/* Print todo item in the panel. */ /* Print todo item in the panel. */
erase_window_part (win[TOD].p, 1, title_lines, win[TOD].w - 2, erase_window_part(win[TOD].p, 1, title_lines, win[TOD].w - 2, win[TOD].h - 2);
win[TOD].h - 2); LLIST_FOREACH(&todolist, i) {
LLIST_FOREACH (&todolist, i) struct todo *todo = LLIST_TS_GET_DATA(i);
{
struct todo *todo = LLIST_TS_GET_DATA (i);
num_todo++; num_todo++;
t_realpos = num_todo - first; t_realpos = num_todo - first;
incolor = (which_pan == TOD) ? num_todo - hilt : num_todo; incolor = (which_pan == TOD) ? num_todo - hilt : num_todo;
if (incolor == 0) if (incolor == 0)
msgsav = todo->mesg; msgsav = todo->mesg;
if (t_realpos >= 0 && t_realpos < max_items) if (t_realpos >= 0 && t_realpos < max_items) {
{ display_todo_item(incolor, todo->mesg, todo->id,
display_todo_item (incolor, todo->mesg, todo->id, (todo->note != NULL) ? 1 : 0, len, y_offset, x_offset);
(todo->note != NULL) ? 1 : 0, len, y_offset,
x_offset);
y_offset = y_offset + todo_lines; y_offset = y_offset + todo_lines;
} }
} }
/* Draw the scrollbar if necessary. */ /* Draw the scrollbar if necessary. */
if (todos > max_items) if (todos > max_items) {
{ float ratio = ((float)max_items) / ((float)todos);
float ratio = ((float) max_items) / ((float) todos); int sbar_length = (int)(ratio * (max_items + 1));
int sbar_length = (int) (ratio * (max_items + 1)); int highend = (int)(ratio * first);
int highend = (int) (ratio * first);
unsigned hilt_bar = (which_pan == TOD) ? 1 : 0; unsigned hilt_bar = (which_pan == TOD) ? 1 : 0;
int sbar_top = highend + title_lines; int sbar_top = highend + title_lines;
if ((sbar_top + sbar_length) > win[TOD].h - 1) if ((sbar_top + sbar_length) > win[TOD].h - 1)
sbar_length = win[TOD].h - 1 - sbar_top; sbar_length = win[TOD].h - 1 - sbar_top;
draw_scrollbar (win[TOD].p, sbar_top, win[TOD].w - 2, draw_scrollbar(win[TOD].p, sbar_top, win[TOD].w - 2,
sbar_length, title_lines, win[TOD].h - 1, hilt_bar); sbar_length, title_lines, win[TOD].h - 1, hilt_bar);
} }
wnoutrefresh (win[TOD].p); wnoutrefresh(win[TOD].p);
} }
/* Attach a note to a todo */ /* Attach a note to a todo */
void void todo_edit_note(const char *editor)
todo_edit_note (const char *editor)
{ {
struct todo *i = todo_get_item (hilt); struct todo *i = todo_get_item(hilt);
edit_note (&i->note, editor); edit_note(&i->note, editor);
} }
/* View a note previously attached to a todo */ /* View a note previously attached to a todo */
void void todo_view_note(const char *pager)
todo_view_note (const char *pager)
{ {
struct todo *i = todo_get_item (hilt); struct todo *i = todo_get_item(hilt);
view_note (i->note, pager); view_note(i->note, pager);
} }
/* Pipe a todo item to an external program. */ /* Pipe a todo item to an external program. */
void void todo_pipe_item(void)
todo_pipe_item (void)
{ {
char cmd[BUFSIZ] = ""; char cmd[BUFSIZ] = "";
char const *arg[] = { cmd, NULL }; char const *arg[] = { cmd, NULL };
@ -475,42 +436,38 @@ todo_pipe_item (void)
FILE *fpout; FILE *fpout;
struct todo *todo; struct todo *todo;
status_mesg (_("Pipe item to external command:"), ""); status_mesg(_("Pipe item to external command:"), "");
if (getstring (win[STA].p, cmd, BUFSIZ, 0, 1) != GETSTRING_VALID) if (getstring(win[STA].p, cmd, BUFSIZ, 0, 1) != GETSTRING_VALID)
return; return;
wins_prepare_external (); wins_prepare_external();
if ((pid = shell_exec (NULL, &pout, *arg, arg))) if ((pid = shell_exec(NULL, &pout, *arg, arg))) {
{ fpout = fdopen(pout, "w");
fpout = fdopen (pout, "w");
todo = todo_get_item (hilt); todo = todo_get_item(hilt);
todo_write (todo, fpout); todo_write(todo, fpout);
fclose (fpout); fclose(fpout);
child_wait (NULL, &pout, pid); child_wait(NULL, &pout, pid);
press_any_key (); press_any_key();
} }
wins_unprepare_external (); wins_unprepare_external();
} }
static void static void todo_free(struct todo *todo)
todo_free (struct todo *todo)
{ {
mem_free (todo->mesg); mem_free(todo->mesg);
erase_note (&todo->note); erase_note(&todo->note);
mem_free (todo); mem_free(todo);
} }
void void todo_init_list(void)
todo_init_list (void)
{ {
LLIST_INIT (&todolist); LLIST_INIT(&todolist);
} }
void void todo_free_list(void)
todo_free_list (void)
{ {
LLIST_FREE_INNER (&todolist, todo_free); LLIST_FREE_INNER(&todolist, todo_free);
LLIST_FREE (&todolist); LLIST_FREE(&todolist);
} }

View File

@ -41,245 +41,243 @@ struct utf8_range {
}; };
static const struct utf8_range utf8_widthtab[] = { static const struct utf8_range utf8_widthtab[] = {
{ 0x00300, 0x0036f, 0 }, {0x00300, 0x0036f, 0},
{ 0x00483, 0x00489, 0 }, {0x00483, 0x00489, 0},
{ 0x00591, 0x005bd, 0 }, {0x00591, 0x005bd, 0},
{ 0x005bf, 0x005bf, 0 }, {0x005bf, 0x005bf, 0},
{ 0x005c1, 0x005c2, 0 }, {0x005c1, 0x005c2, 0},
{ 0x005c4, 0x005c5, 0 }, {0x005c4, 0x005c5, 0},
{ 0x005c7, 0x005c7, 0 }, {0x005c7, 0x005c7, 0},
{ 0x00610, 0x0061a, 0 }, {0x00610, 0x0061a, 0},
{ 0x0064b, 0x0065e, 0 }, {0x0064b, 0x0065e, 0},
{ 0x00670, 0x00670, 0 }, {0x00670, 0x00670, 0},
{ 0x006d6, 0x006dc, 0 }, {0x006d6, 0x006dc, 0},
{ 0x006de, 0x006e4, 0 }, {0x006de, 0x006e4, 0},
{ 0x006e7, 0x006e8, 0 }, {0x006e7, 0x006e8, 0},
{ 0x006ea, 0x006ed, 0 }, {0x006ea, 0x006ed, 0},
{ 0x00711, 0x00711, 0 }, {0x00711, 0x00711, 0},
{ 0x00730, 0x0074a, 0 }, {0x00730, 0x0074a, 0},
{ 0x007a6, 0x007b0, 0 }, {0x007a6, 0x007b0, 0},
{ 0x007eb, 0x007f3, 0 }, {0x007eb, 0x007f3, 0},
{ 0x00816, 0x00819, 0 }, {0x00816, 0x00819, 0},
{ 0x0081b, 0x00823, 0 }, {0x0081b, 0x00823, 0},
{ 0x00825, 0x00827, 0 }, {0x00825, 0x00827, 0},
{ 0x00829, 0x0082d, 0 }, {0x00829, 0x0082d, 0},
{ 0x00900, 0x00903, 0 }, {0x00900, 0x00903, 0},
{ 0x0093c, 0x0093c, 0 }, {0x0093c, 0x0093c, 0},
{ 0x0093e, 0x0094e, 0 }, {0x0093e, 0x0094e, 0},
{ 0x00951, 0x00955, 0 }, {0x00951, 0x00955, 0},
{ 0x00962, 0x00963, 0 }, {0x00962, 0x00963, 0},
{ 0x00981, 0x00983, 0 }, {0x00981, 0x00983, 0},
{ 0x009bc, 0x009bc, 0 }, {0x009bc, 0x009bc, 0},
{ 0x009be, 0x009c4, 0 }, {0x009be, 0x009c4, 0},
{ 0x009c7, 0x009c8, 0 }, {0x009c7, 0x009c8, 0},
{ 0x009cb, 0x009cd, 0 }, {0x009cb, 0x009cd, 0},
{ 0x009d7, 0x009d7, 0 }, {0x009d7, 0x009d7, 0},
{ 0x009e2, 0x009e3, 0 }, {0x009e2, 0x009e3, 0},
{ 0x00a01, 0x00a03, 0 }, {0x00a01, 0x00a03, 0},
{ 0x00a3c, 0x00a3c, 0 }, {0x00a3c, 0x00a3c, 0},
{ 0x00a3e, 0x00a42, 0 }, {0x00a3e, 0x00a42, 0},
{ 0x00a47, 0x00a48, 0 }, {0x00a47, 0x00a48, 0},
{ 0x00a4b, 0x00a4d, 0 }, {0x00a4b, 0x00a4d, 0},
{ 0x00a51, 0x00a51, 0 }, {0x00a51, 0x00a51, 0},
{ 0x00a70, 0x00a71, 0 }, {0x00a70, 0x00a71, 0},
{ 0x00a75, 0x00a75, 0 }, {0x00a75, 0x00a75, 0},
{ 0x00a81, 0x00a83, 0 }, {0x00a81, 0x00a83, 0},
{ 0x00abc, 0x00abc, 0 }, {0x00abc, 0x00abc, 0},
{ 0x00abe, 0x00ac5, 0 }, {0x00abe, 0x00ac5, 0},
{ 0x00ac7, 0x00ac9, 0 }, {0x00ac7, 0x00ac9, 0},
{ 0x00acb, 0x00acd, 0 }, {0x00acb, 0x00acd, 0},
{ 0x00ae2, 0x00ae3, 0 }, {0x00ae2, 0x00ae3, 0},
{ 0x00b01, 0x00b03, 0 }, {0x00b01, 0x00b03, 0},
{ 0x00b3c, 0x00b3c, 0 }, {0x00b3c, 0x00b3c, 0},
{ 0x00b3e, 0x00b44, 0 }, {0x00b3e, 0x00b44, 0},
{ 0x00b47, 0x00b48, 0 }, {0x00b47, 0x00b48, 0},
{ 0x00b4b, 0x00b4d, 0 }, {0x00b4b, 0x00b4d, 0},
{ 0x00b56, 0x00b57, 0 }, {0x00b56, 0x00b57, 0},
{ 0x00b62, 0x00b63, 0 }, {0x00b62, 0x00b63, 0},
{ 0x00b82, 0x00b82, 0 }, {0x00b82, 0x00b82, 0},
{ 0x00bbe, 0x00bc2, 0 }, {0x00bbe, 0x00bc2, 0},
{ 0x00bc6, 0x00bc8, 0 }, {0x00bc6, 0x00bc8, 0},
{ 0x00bca, 0x00bcd, 0 }, {0x00bca, 0x00bcd, 0},
{ 0x00bd7, 0x00bd7, 0 }, {0x00bd7, 0x00bd7, 0},
{ 0x00c01, 0x00c03, 0 }, {0x00c01, 0x00c03, 0},
{ 0x00c3e, 0x00c44, 0 }, {0x00c3e, 0x00c44, 0},
{ 0x00c46, 0x00c48, 0 }, {0x00c46, 0x00c48, 0},
{ 0x00c4a, 0x00c4d, 0 }, {0x00c4a, 0x00c4d, 0},
{ 0x00c55, 0x00c56, 0 }, {0x00c55, 0x00c56, 0},
{ 0x00c62, 0x00c63, 0 }, {0x00c62, 0x00c63, 0},
{ 0x00c82, 0x00c83, 0 }, {0x00c82, 0x00c83, 0},
{ 0x00cbc, 0x00cbc, 0 }, {0x00cbc, 0x00cbc, 0},
{ 0x00cbe, 0x00cc4, 0 }, {0x00cbe, 0x00cc4, 0},
{ 0x00cc6, 0x00cc8, 0 }, {0x00cc6, 0x00cc8, 0},
{ 0x00cca, 0x00ccd, 0 }, {0x00cca, 0x00ccd, 0},
{ 0x00cd5, 0x00cd6, 0 }, {0x00cd5, 0x00cd6, 0},
{ 0x00ce2, 0x00ce3, 0 }, {0x00ce2, 0x00ce3, 0},
{ 0x00d02, 0x00d03, 0 }, {0x00d02, 0x00d03, 0},
{ 0x00d3e, 0x00d44, 0 }, {0x00d3e, 0x00d44, 0},
{ 0x00d46, 0x00d48, 0 }, {0x00d46, 0x00d48, 0},
{ 0x00d4a, 0x00d4d, 0 }, {0x00d4a, 0x00d4d, 0},
{ 0x00d57, 0x00d57, 0 }, {0x00d57, 0x00d57, 0},
{ 0x00d62, 0x00d63, 0 }, {0x00d62, 0x00d63, 0},
{ 0x00d82, 0x00d83, 0 }, {0x00d82, 0x00d83, 0},
{ 0x00dca, 0x00dca, 0 }, {0x00dca, 0x00dca, 0},
{ 0x00dcf, 0x00dd4, 0 }, {0x00dcf, 0x00dd4, 0},
{ 0x00dd6, 0x00dd6, 0 }, {0x00dd6, 0x00dd6, 0},
{ 0x00dd8, 0x00ddf, 0 }, {0x00dd8, 0x00ddf, 0},
{ 0x00df2, 0x00df3, 0 }, {0x00df2, 0x00df3, 0},
{ 0x00e31, 0x00e31, 0 }, {0x00e31, 0x00e31, 0},
{ 0x00e34, 0x00e3a, 0 }, {0x00e34, 0x00e3a, 0},
{ 0x00e47, 0x00e4e, 0 }, {0x00e47, 0x00e4e, 0},
{ 0x00eb1, 0x00eb1, 0 }, {0x00eb1, 0x00eb1, 0},
{ 0x00eb4, 0x00eb9, 0 }, {0x00eb4, 0x00eb9, 0},
{ 0x00ebb, 0x00ebc, 0 }, {0x00ebb, 0x00ebc, 0},
{ 0x00ec8, 0x00ecd, 0 }, {0x00ec8, 0x00ecd, 0},
{ 0x00f18, 0x00f19, 0 }, {0x00f18, 0x00f19, 0},
{ 0x00f35, 0x00f35, 0 }, {0x00f35, 0x00f35, 0},
{ 0x00f37, 0x00f37, 0 }, {0x00f37, 0x00f37, 0},
{ 0x00f39, 0x00f39, 0 }, {0x00f39, 0x00f39, 0},
{ 0x00f3e, 0x00f3f, 0 }, {0x00f3e, 0x00f3f, 0},
{ 0x00f71, 0x00f84, 0 }, {0x00f71, 0x00f84, 0},
{ 0x00f86, 0x00f87, 0 }, {0x00f86, 0x00f87, 0},
{ 0x00f90, 0x00f97, 0 }, {0x00f90, 0x00f97, 0},
{ 0x00f99, 0x00fbc, 0 }, {0x00f99, 0x00fbc, 0},
{ 0x00fc6, 0x00fc6, 0 }, {0x00fc6, 0x00fc6, 0},
{ 0x0102b, 0x0103e, 0 }, {0x0102b, 0x0103e, 0},
{ 0x01056, 0x01059, 0 }, {0x01056, 0x01059, 0},
{ 0x0105e, 0x01060, 0 }, {0x0105e, 0x01060, 0},
{ 0x01062, 0x01064, 0 }, {0x01062, 0x01064, 0},
{ 0x01067, 0x0106d, 0 }, {0x01067, 0x0106d, 0},
{ 0x01071, 0x01074, 0 }, {0x01071, 0x01074, 0},
{ 0x01082, 0x0108d, 0 }, {0x01082, 0x0108d, 0},
{ 0x0108f, 0x0108f, 0 }, {0x0108f, 0x0108f, 0},
{ 0x0109a, 0x0109d, 0 }, {0x0109a, 0x0109d, 0},
{ 0x01100, 0x0115f, 2 }, {0x01100, 0x0115f, 2},
{ 0x011a3, 0x011a7, 2 }, {0x011a3, 0x011a7, 2},
{ 0x011fa, 0x011ff, 2 }, {0x011fa, 0x011ff, 2},
{ 0x0135f, 0x0135f, 0 }, {0x0135f, 0x0135f, 0},
{ 0x01712, 0x01714, 0 }, {0x01712, 0x01714, 0},
{ 0x01732, 0x01734, 0 }, {0x01732, 0x01734, 0},
{ 0x01752, 0x01753, 0 }, {0x01752, 0x01753, 0},
{ 0x01772, 0x01773, 0 }, {0x01772, 0x01773, 0},
{ 0x017b6, 0x017d3, 0 }, {0x017b6, 0x017d3, 0},
{ 0x017dd, 0x017dd, 0 }, {0x017dd, 0x017dd, 0},
{ 0x0180b, 0x0180d, 0 }, {0x0180b, 0x0180d, 0},
{ 0x018a9, 0x018a9, 0 }, {0x018a9, 0x018a9, 0},
{ 0x01920, 0x0192b, 0 }, {0x01920, 0x0192b, 0},
{ 0x01930, 0x0193b, 0 }, {0x01930, 0x0193b, 0},
{ 0x019b0, 0x019c0, 0 }, {0x019b0, 0x019c0, 0},
{ 0x019c8, 0x019c9, 0 }, {0x019c8, 0x019c9, 0},
{ 0x01a17, 0x01a1b, 0 }, {0x01a17, 0x01a1b, 0},
{ 0x01a55, 0x01a5e, 0 }, {0x01a55, 0x01a5e, 0},
{ 0x01a60, 0x01a7c, 0 }, {0x01a60, 0x01a7c, 0},
{ 0x01a7f, 0x01a7f, 0 }, {0x01a7f, 0x01a7f, 0},
{ 0x01b00, 0x01b04, 0 }, {0x01b00, 0x01b04, 0},
{ 0x01b34, 0x01b44, 0 }, {0x01b34, 0x01b44, 0},
{ 0x01b6b, 0x01b73, 0 }, {0x01b6b, 0x01b73, 0},
{ 0x01b80, 0x01b82, 0 }, {0x01b80, 0x01b82, 0},
{ 0x01ba1, 0x01baa, 0 }, {0x01ba1, 0x01baa, 0},
{ 0x01c24, 0x01c37, 0 }, {0x01c24, 0x01c37, 0},
{ 0x01cd0, 0x01cd2, 0 }, {0x01cd0, 0x01cd2, 0},
{ 0x01cd4, 0x01ce8, 0 }, {0x01cd4, 0x01ce8, 0},
{ 0x01ced, 0x01ced, 0 }, {0x01ced, 0x01ced, 0},
{ 0x01cf2, 0x01cf2, 0 }, {0x01cf2, 0x01cf2, 0},
{ 0x01dc0, 0x01de6, 0 }, {0x01dc0, 0x01de6, 0},
{ 0x01dfd, 0x01dff, 0 }, {0x01dfd, 0x01dff, 0},
{ 0x020d0, 0x020f0, 0 }, {0x020d0, 0x020f0, 0},
{ 0x02329, 0x0232a, 2 }, {0x02329, 0x0232a, 2},
{ 0x02cef, 0x02cf1, 0 }, {0x02cef, 0x02cf1, 0},
{ 0x02de0, 0x02dff, 0 }, {0x02de0, 0x02dff, 0},
{ 0x02e80, 0x02e99, 2 }, {0x02e80, 0x02e99, 2},
{ 0x02e9b, 0x02ef3, 2 }, {0x02e9b, 0x02ef3, 2},
{ 0x02f00, 0x02fd5, 2 }, {0x02f00, 0x02fd5, 2},
{ 0x02ff0, 0x02ffb, 2 }, {0x02ff0, 0x02ffb, 2},
{ 0x03000, 0x03029, 2 }, {0x03000, 0x03029, 2},
{ 0x0302a, 0x0302f, 0 }, {0x0302a, 0x0302f, 0},
{ 0x03030, 0x0303e, 2 }, {0x03030, 0x0303e, 2},
{ 0x03041, 0x03096, 2 }, {0x03041, 0x03096, 2},
{ 0x03099, 0x0309a, 0 }, {0x03099, 0x0309a, 0},
{ 0x0309b, 0x030ff, 2 }, {0x0309b, 0x030ff, 2},
{ 0x03105, 0x0312d, 2 }, {0x03105, 0x0312d, 2},
{ 0x03131, 0x0318e, 2 }, {0x03131, 0x0318e, 2},
{ 0x03190, 0x031b7, 2 }, {0x03190, 0x031b7, 2},
{ 0x031c0, 0x031e3, 2 }, {0x031c0, 0x031e3, 2},
{ 0x031f0, 0x0321e, 2 }, {0x031f0, 0x0321e, 2},
{ 0x03220, 0x03247, 2 }, {0x03220, 0x03247, 2},
{ 0x03250, 0x032fe, 2 }, {0x03250, 0x032fe, 2},
{ 0x03300, 0x04dbf, 2 }, {0x03300, 0x04dbf, 2},
{ 0x04e00, 0x0a48c, 2 }, {0x04e00, 0x0a48c, 2},
{ 0x0a490, 0x0a4c6, 2 }, {0x0a490, 0x0a4c6, 2},
{ 0x0a66f, 0x0a672, 0 }, {0x0a66f, 0x0a672, 0},
{ 0x0a67c, 0x0a67d, 0 }, {0x0a67c, 0x0a67d, 0},
{ 0x0a6f0, 0x0a6f1, 0 }, {0x0a6f0, 0x0a6f1, 0},
{ 0x0a802, 0x0a802, 0 }, {0x0a802, 0x0a802, 0},
{ 0x0a806, 0x0a806, 0 }, {0x0a806, 0x0a806, 0},
{ 0x0a80b, 0x0a80b, 0 }, {0x0a80b, 0x0a80b, 0},
{ 0x0a823, 0x0a827, 0 }, {0x0a823, 0x0a827, 0},
{ 0x0a880, 0x0a881, 0 }, {0x0a880, 0x0a881, 0},
{ 0x0a8b4, 0x0a8c4, 0 }, {0x0a8b4, 0x0a8c4, 0},
{ 0x0a8e0, 0x0a8f1, 0 }, {0x0a8e0, 0x0a8f1, 0},
{ 0x0a926, 0x0a92d, 0 }, {0x0a926, 0x0a92d, 0},
{ 0x0a947, 0x0a953, 0 }, {0x0a947, 0x0a953, 0},
{ 0x0a960, 0x0a97c, 2 }, {0x0a960, 0x0a97c, 2},
{ 0x0a980, 0x0a983, 0 }, {0x0a980, 0x0a983, 0},
{ 0x0a9b3, 0x0a9c0, 0 }, {0x0a9b3, 0x0a9c0, 0},
{ 0x0aa29, 0x0aa36, 0 }, {0x0aa29, 0x0aa36, 0},
{ 0x0aa43, 0x0aa43, 0 }, {0x0aa43, 0x0aa43, 0},
{ 0x0aa4c, 0x0aa4d, 0 }, {0x0aa4c, 0x0aa4d, 0},
{ 0x0aa7b, 0x0aa7b, 0 }, {0x0aa7b, 0x0aa7b, 0},
{ 0x0aab0, 0x0aab0, 0 }, {0x0aab0, 0x0aab0, 0},
{ 0x0aab2, 0x0aab4, 0 }, {0x0aab2, 0x0aab4, 0},
{ 0x0aab7, 0x0aab8, 0 }, {0x0aab7, 0x0aab8, 0},
{ 0x0aabe, 0x0aabf, 0 }, {0x0aabe, 0x0aabf, 0},
{ 0x0aac1, 0x0aac1, 0 }, {0x0aac1, 0x0aac1, 0},
{ 0x0abe3, 0x0abea, 0 }, {0x0abe3, 0x0abea, 0},
{ 0x0abec, 0x0abed, 0 }, {0x0abec, 0x0abed, 0},
{ 0x0ac00, 0x0d7a3, 2 }, {0x0ac00, 0x0d7a3, 2},
{ 0x0d7b0, 0x0d7c6, 2 }, {0x0d7b0, 0x0d7c6, 2},
{ 0x0d7cb, 0x0d7fb, 2 }, {0x0d7cb, 0x0d7fb, 2},
{ 0x0f900, 0x0faff, 2 }, {0x0f900, 0x0faff, 2},
{ 0x0fb1e, 0x0fb1e, 0 }, {0x0fb1e, 0x0fb1e, 0},
{ 0x0fe00, 0x0fe0f, 0 }, {0x0fe00, 0x0fe0f, 0},
{ 0x0fe10, 0x0fe19, 2 }, {0x0fe10, 0x0fe19, 2},
{ 0x0fe20, 0x0fe26, 0 }, {0x0fe20, 0x0fe26, 0},
{ 0x0fe30, 0x0fe52, 2 }, {0x0fe30, 0x0fe52, 2},
{ 0x0fe54, 0x0fe66, 2 }, {0x0fe54, 0x0fe66, 2},
{ 0x0fe68, 0x0fe6b, 2 }, {0x0fe68, 0x0fe6b, 2},
{ 0x0ff01, 0x0ff60, 2 }, {0x0ff01, 0x0ff60, 2},
{ 0x0ffe0, 0x0ffe6, 2 }, {0x0ffe0, 0x0ffe6, 2},
{ 0x101fd, 0x101fd, 0 }, {0x101fd, 0x101fd, 0},
{ 0x10a01, 0x10a03, 0 }, {0x10a01, 0x10a03, 0},
{ 0x10a05, 0x10a06, 0 }, {0x10a05, 0x10a06, 0},
{ 0x10a0c, 0x10a0f, 0 }, {0x10a0c, 0x10a0f, 0},
{ 0x10a38, 0x10a3a, 0 }, {0x10a38, 0x10a3a, 0},
{ 0x10a3f, 0x10a3f, 0 }, {0x10a3f, 0x10a3f, 0},
{ 0x11080, 0x11082, 0 }, {0x11080, 0x11082, 0},
{ 0x110b0, 0x110ba, 0 }, {0x110b0, 0x110ba, 0},
{ 0x1d165, 0x1d169, 0 }, {0x1d165, 0x1d169, 0},
{ 0x1d16d, 0x1d172, 0 }, {0x1d16d, 0x1d172, 0},
{ 0x1d17b, 0x1d182, 0 }, {0x1d17b, 0x1d182, 0},
{ 0x1d185, 0x1d18b, 0 }, {0x1d185, 0x1d18b, 0},
{ 0x1d1aa, 0x1d1ad, 0 }, {0x1d1aa, 0x1d1ad, 0},
{ 0x1d242, 0x1d244, 0 }, {0x1d242, 0x1d244, 0},
{ 0x1f200, 0x1f200, 2 }, {0x1f200, 0x1f200, 2},
{ 0x1f210, 0x1f231, 2 }, {0x1f210, 0x1f231, 2},
{ 0x1f240, 0x1f248, 2 }, {0x1f240, 0x1f248, 2},
{ 0x20000, 0x2fffd, 2 }, {0x20000, 0x2fffd, 2},
{ 0x30000, 0x3fffd, 2 }, {0x30000, 0x3fffd, 2},
{ 0xe0100, 0xe01ef, 0 } {0xe0100, 0xe01ef, 0}
}; };
/* Get the width of a UTF-8 character. */ /* Get the width of a UTF-8 character. */
int int utf8_width(char *s)
utf8_width (char *s)
{ {
int val, low, high, cur; int val, low, high, cur;
if (UTF8_ISCONT (*s)) if (UTF8_ISCONT(*s))
return 0; return 0;
switch (UTF8_LENGTH (*s)) switch (UTF8_LENGTH(*s)) {
{
case 1: case 1:
val = s[0]; val = s[0];
break; break;
@ -287,8 +285,7 @@ utf8_width (char *s)
val = (s[1] & 0x3f) | (s[0] & 0x1f) << 6; val = (s[1] & 0x3f) | (s[0] & 0x1f) << 6;
break; break;
case 3: case 3:
val = ((s[2] & 0x3f) | (s[1] & 0x3f) << 6) | val = ((s[2] & 0x3f) | (s[1] & 0x3f) << 6) | (s[0] & 0x0f) << 12;
(s[0] & 0x0f) << 12;
break; break;
case 4: case 4:
val = (((s[3] & 0x3f) | (s[2] & 0x3f) << 6) | val = (((s[3] & 0x3f) | (s[2] & 0x3f) << 6) |
@ -296,8 +293,7 @@ utf8_width (char *s)
break; break;
case 5: case 5:
val = ((((s[4] & 0x3f) | (s[3] & 0x3f) << 6) | val = ((((s[4] & 0x3f) | (s[3] & 0x3f) << 6) |
(s[2] & 0x3f) << 12) | (s[1] & 0x3f) << 18) | (s[2] & 0x3f) << 12) | (s[1] & 0x3f) << 18) | (s[0] & 0x3f) << 24;
(s[0] & 0x3f) << 24;
break; break;
case 6: case 6:
val = (((((s[5] & 0x3f) | (s[4] & 0x3f) << 6) | val = (((((s[5] & 0x3f) | (s[4] & 0x3f) << 6) |
@ -310,17 +306,14 @@ utf8_width (char *s)
low = 0; low = 0;
high = sizeof(utf8_widthtab) / sizeof(utf8_widthtab[0]); high = sizeof(utf8_widthtab) / sizeof(utf8_widthtab[0]);
do do {
{
cur = (low + high) / 2; cur = (low + high) / 2;
if (val >= utf8_widthtab[cur].min) if (val >= utf8_widthtab[cur].min) {
{
if (val <= utf8_widthtab[cur].max) if (val <= utf8_widthtab[cur].max)
return utf8_widthtab[cur].width; return utf8_widthtab[cur].width;
else else
low = cur + 1; low = cur + 1;
} } else
else
high = cur - 1; high = cur - 1;
} }
while (low <= high); while (low <= high);
@ -329,15 +322,13 @@ utf8_width (char *s)
} }
/* Get the width of a UTF-8 string. */ /* Get the width of a UTF-8 string. */
int int utf8_strwidth(char *s)
utf8_strwidth (char *s)
{ {
int width = 0; int width = 0;
for (; s && *s; s++) for (; s && *s; s++) {
{ if (!UTF8_ISCONT(*s))
if (!UTF8_ISCONT (*s)) width += utf8_width(s);
width += utf8_width (s);
} }
return width; return width;

File diff suppressed because it is too large Load Diff

View File

@ -65,6 +65,7 @@ int read_only = 0;
* variables to store calendar names * variables to store calendar names
*/ */
int days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
const char *monthnames[12] = { const char *monthnames[12] = {
N_("January"), N_("January"),
N_("February"), N_("February"),
@ -120,8 +121,7 @@ struct dmon_conf dmon;
/* /*
* Variables init * Variables init
*/ */
void void vars_init(void)
vars_init (void)
{ {
const char *ed, *pg; const char *ed, *pg;
@ -133,33 +133,33 @@ vars_init (void)
conf.periodic_save = 0; conf.periodic_save = 0;
conf.system_dialogs = 1; conf.system_dialogs = 1;
conf.progress_bar = 1; conf.progress_bar = 1;
strncpy (conf.output_datefmt, "%D", 3); strncpy(conf.output_datefmt, "%D", 3);
conf.input_datefmt = 1; conf.input_datefmt = 1;
/* Default external editor and pager */ /* Default external editor and pager */
ed = getenv ("VISUAL"); ed = getenv("VISUAL");
if (ed == NULL || ed[0] == '\0') if (ed == NULL || ed[0] == '\0')
ed = getenv ("EDITOR"); ed = getenv("EDITOR");
if (ed == NULL || ed[0] == '\0') if (ed == NULL || ed[0] == '\0')
ed = DEFAULT_EDITOR; ed = DEFAULT_EDITOR;
conf.editor = ed; conf.editor = ed;
pg = getenv ("PAGER"); pg = getenv("PAGER");
if (pg == NULL || pg[0] == '\0') if (pg == NULL || pg[0] == '\0')
pg = DEFAULT_PAGER; pg = DEFAULT_PAGER;
conf.pager = pg; conf.pager = pg;
wins_set_layout (1); wins_set_layout(1);
calendar_set_first_day_of_week (MONDAY); calendar_set_first_day_of_week(MONDAY);
/* Pad structure to scroll text inside the appointment panel */ /* Pad structure to scroll text inside the appointment panel */
apad.length = 1; apad.length = 1;
apad.first_onscreen = 0; apad.first_onscreen = 0;
/* Attribute definitions for color and non-color terminals */ /* Attribute definitions for color and non-color terminals */
custom_init_attr (); custom_init_attr();
/* Start at the current date */ /* Start at the current date */
calendar_init_slctd_day (); calendar_init_slctd_day();
} }

View File

@ -63,82 +63,73 @@ static int layout;
*/ */
static pthread_mutex_t screen_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t screen_mutex = PTHREAD_MUTEX_INITIALIZER;
static unsigned static unsigned screen_acquire(void)
screen_acquire (void)
{ {
if (pthread_mutex_lock (&screen_mutex) != 0) if (pthread_mutex_lock(&screen_mutex) != 0)
return 0; return 0;
else else
return 1; return 1;
} }
static void static void screen_release(void)
screen_release (void)
{ {
pthread_mutex_unlock (&screen_mutex); pthread_mutex_unlock(&screen_mutex);
} }
int int wins_refresh(void)
wins_refresh (void)
{ {
int rc; int rc;
if (!screen_acquire ()) if (!screen_acquire())
return ERR; return ERR;
rc = refresh (); rc = refresh();
screen_release (); screen_release();
return rc; return rc;
} }
int int wins_wrefresh(WINDOW * win)
wins_wrefresh (WINDOW *win)
{ {
int rc; int rc;
if (!win || !screen_acquire ()) if (!win || !screen_acquire())
return ERR; return ERR;
rc = wrefresh (win); rc = wrefresh(win);
screen_release (); screen_release();
return rc; return rc;
} }
int int wins_doupdate(void)
wins_doupdate (void)
{ {
int rc; int rc;
if (!screen_acquire ()) if (!screen_acquire())
return ERR; return ERR;
rc = doupdate (); rc = doupdate();
screen_release (); screen_release();
return rc; return rc;
} }
/* Get the current layout. */ /* Get the current layout. */
int int wins_layout(void)
wins_layout (void)
{ {
return layout; return layout;
} }
/* Set the current layout. */ /* Set the current layout. */
void void wins_set_layout(int nb)
wins_set_layout (int nb)
{ {
layout = nb; layout = nb;
} }
/* Get the current side bar width. */ /* Get the current side bar width. */
unsigned unsigned wins_sbar_width(void)
wins_sbar_width (void)
{ {
if (sbarwidth_perc > SBARMAXWIDTHPERC) if (sbarwidth_perc > SBARMAXWIDTHPERC)
return col * SBARMAXWIDTHPERC / 100; return col * SBARMAXWIDTHPERC / 100;
else else {
{
unsigned sbarwidth = (unsigned)(col * sbarwidth_perc / 100); unsigned sbarwidth = (unsigned)(col * sbarwidth_perc / 100);
return (sbarwidth < SBARMINWIDTH) ? SBARMINWIDTH : sbarwidth; return (sbarwidth < SBARMINWIDTH) ? SBARMINWIDTH : sbarwidth;
} }
@ -148,8 +139,7 @@ wins_sbar_width (void)
* Return the side bar width in percentage of the total number of columns * Return the side bar width in percentage of the total number of columns
* available in calcurse's screen. * available in calcurse's screen.
*/ */
unsigned unsigned wins_sbar_wperc(void)
wins_sbar_wperc (void)
{ {
return sbarwidth_perc > SBARMAXWIDTHPERC ? SBARMAXWIDTHPERC : sbarwidth_perc; return sbarwidth_perc > SBARMAXWIDTHPERC ? SBARMAXWIDTHPERC : sbarwidth_perc;
} }
@ -160,51 +150,44 @@ wins_sbar_wperc (void)
* The side bar could not have a width representing more than 50% of the screen, * The side bar could not have a width representing more than 50% of the screen,
* and could not be less than SBARMINWIDTH characters. * and could not be less than SBARMINWIDTH characters.
*/ */
void void wins_set_sbar_width(unsigned perc)
wins_set_sbar_width (unsigned perc)
{ {
sbarwidth_perc = perc; sbarwidth_perc = perc;
} }
/* Change the width of the side bar within acceptable boundaries. */ /* Change the width of the side bar within acceptable boundaries. */
void void wins_sbar_winc(void)
wins_sbar_winc (void)
{ {
if (sbarwidth_perc < SBARMAXWIDTHPERC) if (sbarwidth_perc < SBARMAXWIDTHPERC)
sbarwidth_perc++; sbarwidth_perc++;
} }
void void wins_sbar_wdec(void)
wins_sbar_wdec (void)
{ {
if (sbarwidth_perc > 0) if (sbarwidth_perc > 0)
sbarwidth_perc--; sbarwidth_perc--;
} }
/* Initialize the selected window in calcurse's interface. */ /* Initialize the selected window in calcurse's interface. */
void void wins_slctd_init(void)
wins_slctd_init (void)
{ {
wins_slctd_set (CAL); wins_slctd_set(CAL);
} }
/* Returns an enum which corresponds to the window which is selected. */ /* Returns an enum which corresponds to the window which is selected. */
enum win enum win wins_slctd(void)
wins_slctd (void)
{ {
return slctd_win; return slctd_win;
} }
/* Sets the selected window. */ /* Sets the selected window. */
void void wins_slctd_set(enum win window)
wins_slctd_set (enum win window)
{ {
slctd_win = window; slctd_win = window;
} }
/* TAB key was hit in the interface, need to select next window. */ /* TAB key was hit in the interface, need to select next window. */
void void wins_slctd_next(void)
wins_slctd_next (void)
{ {
if (slctd_win == TOD) if (slctd_win == TOD)
slctd_win = CAL; slctd_win = CAL;
@ -212,34 +195,32 @@ wins_slctd_next (void)
slctd_win++; slctd_win++;
} }
static void static void wins_init_panels(void)
wins_init_panels (void)
{ {
win[CAL].p = newwin (CALHEIGHT, wins_sbar_width (), win[CAL].y, win[CAL].x); win[CAL].p = newwin(CALHEIGHT, wins_sbar_width(), win[CAL].y, win[CAL].x);
wins_show (win[CAL].p, _("Calendar")); wins_show(win[CAL].p, _("Calendar"));
win[APP].p = newwin (win[APP].h, win[APP].w, win[APP].y, win[APP].x); win[APP].p = newwin(win[APP].h, win[APP].w, win[APP].y, win[APP].x);
wins_show (win[APP].p, _("Appointments")); wins_show(win[APP].p, _("Appointments"));
apad.width = win[APP].w - 3; apad.width = win[APP].w - 3;
apad.ptrwin = newpad (apad.length, apad.width); apad.ptrwin = newpad(apad.length, apad.width);
win[TOD].p = newwin (win[TOD].h, win[TOD].w, win[TOD].y, win[TOD].x); win[TOD].p = newwin(win[TOD].h, win[TOD].w, win[TOD].y, win[TOD].x);
wins_show (win[TOD].p, _("ToDo")); wins_show(win[TOD].p, _("ToDo"));
/* Enable function keys (i.e. arrow keys) in those windows */ /* Enable function keys (i.e. arrow keys) in those windows */
keypad (win[CAL].p, TRUE); keypad(win[CAL].p, TRUE);
keypad (win[APP].p, TRUE); keypad(win[APP].p, TRUE);
keypad (win[TOD].p, TRUE); keypad(win[TOD].p, TRUE);
} }
/* Create all the windows. */ /* Create all the windows. */
void void wins_init(void)
wins_init (void)
{ {
wins_init_panels (); wins_init_panels();
win[STA].p = newwin (win[STA].h, win[STA].w, win[STA].y, win[STA].x); win[STA].p = newwin(win[STA].h, win[STA].w, win[STA].y, win[STA].x);
keypad (win[STA].p, TRUE); keypad(win[STA].p, TRUE);
/* Notify that the curses mode is now launched. */ /* Notify that the curses mode is now launched. */
ui_mode = UI_CURSES; ui_mode = UI_CURSES;
@ -249,116 +230,105 @@ wins_init (void)
* Create a new window and its associated pad, which is used to make the * Create a new window and its associated pad, which is used to make the
* scrolling faster. * scrolling faster.
*/ */
void void wins_scrollwin_init(struct scrollwin *sw)
wins_scrollwin_init (struct scrollwin *sw)
{ {
EXIT_IF (sw == NULL, "null pointer"); EXIT_IF(sw == NULL, "null pointer");
sw->win.p = newwin (sw->win.h, sw->win.w, sw->win.y, sw->win.x); sw->win.p = newwin(sw->win.h, sw->win.w, sw->win.y, sw->win.x);
sw->pad.p = newpad (sw->pad.h, sw->pad.w); sw->pad.p = newpad(sw->pad.h, sw->pad.w);
sw->first_visible_line = 0; sw->first_visible_line = 0;
sw->total_lines = 0; sw->total_lines = 0;
} }
/* Free an already created scrollwin. */ /* Free an already created scrollwin. */
void void wins_scrollwin_delete(struct scrollwin *sw)
wins_scrollwin_delete (struct scrollwin *sw)
{ {
EXIT_IF (sw == NULL, "null pointer"); EXIT_IF(sw == NULL, "null pointer");
delwin(sw->win.p); delwin(sw->win.p);
delwin(sw->pad.p); delwin(sw->pad.p);
} }
/* Display a scrolling window. */ /* Display a scrolling window. */
void void wins_scrollwin_display(struct scrollwin *sw)
wins_scrollwin_display (struct scrollwin *sw)
{ {
const int visible_lines = sw->win.h - sw->pad.y - 1; const int visible_lines = sw->win.h - sw->pad.y - 1;
if (sw->total_lines > visible_lines) if (sw->total_lines > visible_lines) {
{ float ratio = ((float)visible_lines) / ((float)sw->total_lines);
float ratio = ((float) visible_lines) / ((float) sw->total_lines); int sbar_length = (int)(ratio * visible_lines);
int sbar_length = (int) (ratio * visible_lines); int highend = (int)(ratio * sw->first_visible_line);
int highend = (int) (ratio * sw->first_visible_line);
int sbar_top = highend + sw->pad.y + 1; int sbar_top = highend + sw->pad.y + 1;
if ((sbar_top + sbar_length) > sw->win.h - 1) if ((sbar_top + sbar_length) > sw->win.h - 1)
sbar_length = sw->win.h - sbar_top; sbar_length = sw->win.h - sbar_top;
draw_scrollbar (sw->win.p, sbar_top, sw->win.w + sw->win.x - 2, draw_scrollbar(sw->win.p, sbar_top, sw->win.w + sw->win.x - 2,
sbar_length, sw->pad.y + 1, sw->win.h - 1, 1); sbar_length, sw->pad.y + 1, sw->win.h - 1, 1);
} }
wmove (win[STA].p, 0, 0); wmove(win[STA].p, 0, 0);
wnoutrefresh (sw->win.p); wnoutrefresh(sw->win.p);
pnoutrefresh (sw->pad.p, sw->first_visible_line, 0, sw->pad.y, sw->pad.x, pnoutrefresh(sw->pad.p, sw->first_visible_line, 0, sw->pad.y, sw->pad.x,
sw->win.h - sw->pad.y + 1, sw->win.w - sw->win.x); sw->win.h - sw->pad.y + 1, sw->win.w - sw->win.x);
wins_doupdate (); wins_doupdate();
} }
void void wins_scrollwin_up(struct scrollwin *sw, int amount)
wins_scrollwin_up (struct scrollwin *sw, int amount)
{ {
if (sw->first_visible_line > 0) if (sw->first_visible_line > 0)
sw->first_visible_line -= amount; sw->first_visible_line -= amount;
} }
void void wins_scrollwin_down(struct scrollwin *sw, int amount)
wins_scrollwin_down (struct scrollwin *sw, int amount)
{ {
if (sw->total_lines if (sw->total_lines > (sw->first_visible_line + sw->win.h - sw->pad.y - 1))
> (sw->first_visible_line + sw->win.h - sw->pad.y - 1))
sw->first_visible_line += amount; sw->first_visible_line += amount;
} }
void void wins_reinit_panels(void)
wins_reinit_panels (void)
{ {
delwin (win[CAL].p); delwin(win[CAL].p);
delwin (win[APP].p); delwin(win[APP].p);
delwin (apad.ptrwin); delwin(apad.ptrwin);
delwin (win[TOD].p); delwin(win[TOD].p);
wins_get_config (); wins_get_config();
wins_init_panels (); wins_init_panels();
} }
/* /*
* Delete the existing windows and recreate them with their new * Delete the existing windows and recreate them with their new
* size and placement. * size and placement.
*/ */
void void wins_reinit(void)
wins_reinit (void)
{ {
delwin (win[CAL].p); delwin(win[CAL].p);
delwin (win[APP].p); delwin(win[APP].p);
delwin (apad.ptrwin); delwin(apad.ptrwin);
delwin (win[TOD].p); delwin(win[TOD].p);
delwin (win[STA].p); delwin(win[STA].p);
wins_get_config (); wins_get_config();
wins_init (); wins_init();
if (notify_bar ()) if (notify_bar())
notify_reinit_bar (); notify_reinit_bar();
} }
/* Show the window with a border and a label. */ /* Show the window with a border and a label. */
void void wins_show(WINDOW * win, const char *label)
wins_show (WINDOW *win, const char *label)
{ {
int width = getmaxx (win); int width = getmaxx(win);
box (win, 0, 0); box(win, 0, 0);
mvwaddch (win, 2, 0, ACS_LTEE); mvwaddch(win, 2, 0, ACS_LTEE);
mvwhline (win, 2, 1, ACS_HLINE, width - 2); mvwhline(win, 2, 1, ACS_HLINE, width - 2);
mvwaddch (win, 2, width - 1, ACS_RTEE); mvwaddch(win, 2, width - 1, ACS_RTEE);
print_in_middle (win, 1, 0, width, label); print_in_middle(win, 1, 0, width, label);
} }
/* /*
* Get the screen size and recalculate the windows configurations. * Get the screen size and recalculate the windows configurations.
*/ */
void void wins_get_config(void)
wins_get_config (void)
{ {
/* Get the screen configuration */ /* Get the screen configuration */
getmaxyx (stdscr, row, col); getmaxyx(stdscr, row, col);
/* fixed values for status, notification bars and calendar */ /* fixed values for status, notification bars and calendar */
win[STA].h = STATUSHEIGHT; win[STA].h = STATUSHEIGHT;
@ -366,33 +336,27 @@ wins_get_config (void)
win[STA].y = row - win[STA].h; win[STA].y = row - win[STA].h;
win[STA].x = 0; win[STA].x = 0;
if (notify_bar ()) if (notify_bar()) {
{
win[NOT].h = 1; win[NOT].h = 1;
win[NOT].w = col; win[NOT].w = col;
win[NOT].y = win[STA].y - 1; win[NOT].y = win[STA].y - 1;
win[NOT].x = 0; win[NOT].x = 0;
} } else {
else
{
win[NOT].h = 0; win[NOT].h = 0;
win[NOT].w = 0; win[NOT].w = 0;
win[NOT].y = 0; win[NOT].y = 0;
win[NOT].x = 0; win[NOT].x = 0;
} }
win[CAL].w = wins_sbar_width (); win[CAL].w = wins_sbar_width();
win[CAL].h = CALHEIGHT; win[CAL].h = CALHEIGHT;
if (layout <= 4) if (layout <= 4) { /* APPOINTMENT is the biggest panel */
{ /* APPOINTMENT is the biggest panel */
win[APP].w = col - win[CAL].w; win[APP].w = col - win[CAL].w;
win[APP].h = row - (win[STA].h + win[NOT].h); win[APP].h = row - (win[STA].h + win[NOT].h);
win[TOD].w = win[CAL].w; win[TOD].w = win[CAL].w;
win[TOD].h = row - (win[CAL].h + win[STA].h + win[NOT].h); win[TOD].h = row - (win[CAL].h + win[STA].h + win[NOT].h);
} } else { /* TODO is the biggest panel */
else
{ /* TODO is the biggest panel */
win[TOD].w = col - win[CAL].w; win[TOD].w = col - win[CAL].w;
win[TOD].h = row - (win[STA].h + win[NOT].h); win[TOD].h = row - (win[STA].h + win[NOT].h);
win[APP].w = win[CAL].w; win[APP].w = win[CAL].w;
@ -400,8 +364,7 @@ wins_get_config (void)
} }
/* defining the layout */ /* defining the layout */
switch (layout) switch (layout) {
{
case 1: case 1:
win[APP].y = 0; win[APP].y = 0;
win[APP].x = 0; win[APP].x = 0;
@ -470,165 +433,141 @@ wins_get_config (void)
} }
/* draw panel border in color */ /* draw panel border in color */
static void static void border_color(WINDOW * window)
border_color (WINDOW *window)
{ {
int color_attr = A_BOLD; int color_attr = A_BOLD;
int no_color_attr = A_BOLD; int no_color_attr = A_BOLD;
if (colorize) if (colorize) {
{ wattron(window, color_attr | COLOR_PAIR(COLR_CUSTOM));
wattron (window, color_attr | COLOR_PAIR (COLR_CUSTOM)); box(window, 0, 0);
box (window, 0, 0); } else {
wattron(window, no_color_attr);
box(window, 0, 0);
} }
else if (colorize) {
{ wattroff(window, color_attr | COLOR_PAIR(COLR_CUSTOM));
wattron (window, no_color_attr); } else {
box (window, 0, 0); wattroff(window, no_color_attr);
} }
if (colorize) wnoutrefresh(window);
{
wattroff (window, color_attr | COLOR_PAIR (COLR_CUSTOM));
}
else
{
wattroff (window, no_color_attr);
}
wnoutrefresh (window);
} }
/* draw panel border without any color */ /* draw panel border without any color */
static void static void border_nocolor(WINDOW * window)
border_nocolor (WINDOW *window)
{ {
int color_attr = A_BOLD; int color_attr = A_BOLD;
int no_color_attr = A_DIM; int no_color_attr = A_DIM;
if (colorize) if (colorize) {
{ wattron(window, color_attr | COLOR_PAIR(COLR_DEFAULT));
wattron (window, color_attr | COLOR_PAIR (COLR_DEFAULT)); } else {
wattron(window, no_color_attr);
} }
else box(window, 0, 0);
{ if (colorize) {
wattron (window, no_color_attr); wattroff(window, color_attr | COLOR_PAIR(COLR_DEFAULT));
} else {
wattroff(window, no_color_attr);
} }
box (window, 0, 0); wnoutrefresh(window);
if (colorize)
{
wattroff (window, color_attr | COLOR_PAIR (COLR_DEFAULT));
}
else
{
wattroff (window, no_color_attr);
}
wnoutrefresh (window);
} }
void void wins_update_border(int flags)
wins_update_border (int flags)
{ {
if (flags & FLAG_CAL) if (flags & FLAG_CAL) {
{
if (slctd_win == CAL) if (slctd_win == CAL)
border_color (win[CAL].p); border_color(win[CAL].p);
else else
border_nocolor (win[CAL].p); border_nocolor(win[CAL].p);
} }
if (flags & FLAG_APP) if (flags & FLAG_APP) {
{
if (slctd_win == APP) if (slctd_win == APP)
border_color (win[APP].p); border_color(win[APP].p);
else else
border_nocolor (win[APP].p); border_nocolor(win[APP].p);
} }
if (flags & FLAG_TOD) if (flags & FLAG_TOD) {
{
if (slctd_win == TOD) if (slctd_win == TOD)
border_color (win[TOD].p); border_color(win[TOD].p);
else else
border_nocolor (win[TOD].p); border_nocolor(win[TOD].p);
} }
} }
void void wins_update_panels(int flags)
wins_update_panels (int flags)
{ {
if (flags & FLAG_APP) if (flags & FLAG_APP)
apoint_update_panel (slctd_win); apoint_update_panel(slctd_win);
if (flags & FLAG_TOD) if (flags & FLAG_TOD)
todo_update_panel (slctd_win); todo_update_panel(slctd_win);
if (flags & FLAG_CAL) if (flags & FLAG_CAL)
calendar_update_panel (&win[CAL]); calendar_update_panel(&win[CAL]);
} }
/* /*
* Update all of the three windows and put a border around the * Update all of the three windows and put a border around the
* selected window. * selected window.
*/ */
void void wins_update(int flags)
wins_update (int flags)
{ {
wins_update_border (flags); wins_update_border(flags);
wins_update_panels (flags); wins_update_panels(flags);
if (flags & FLAG_STA) if (flags & FLAG_STA)
wins_status_bar (); wins_status_bar();
if ((flags & FLAG_NOT) && notify_bar ()) if ((flags & FLAG_NOT) && notify_bar())
notify_update_bar (); notify_update_bar();
wmove (win[STA].p, 0, 0); wmove(win[STA].p, 0, 0);
wins_doupdate (); wins_doupdate();
} }
/* Reset the screen, needed when resizing terminal for example. */ /* Reset the screen, needed when resizing terminal for example. */
void void wins_reset(void)
wins_reset (void)
{ {
endwin (); endwin();
wins_refresh (); wins_refresh();
curs_set (0); curs_set(0);
wins_reinit (); wins_reinit();
wins_update (FLAG_ALL); wins_update(FLAG_ALL);
} }
/* Prepare windows for the execution of an external command. */ /* Prepare windows for the execution of an external command. */
void void wins_prepare_external(void)
wins_prepare_external (void)
{ {
if (notify_bar ()) if (notify_bar())
notify_stop_main_thread (); notify_stop_main_thread();
def_prog_mode (); def_prog_mode();
ui_mode = UI_CMDLINE; ui_mode = UI_CMDLINE;
clear (); clear();
wins_refresh (); wins_refresh();
endwin (); endwin();
} }
/* Restore windows when returning from an external command. */ /* Restore windows when returning from an external command. */
void void wins_unprepare_external(void)
wins_unprepare_external (void)
{ {
reset_prog_mode (); reset_prog_mode();
clearok (curscr, TRUE); clearok(curscr, TRUE);
curs_set (0); curs_set(0);
ui_mode = UI_CURSES; ui_mode = UI_CURSES;
wins_refresh (); wins_refresh();
if (notify_bar ()) if (notify_bar())
notify_start_main_thread (); notify_start_main_thread();
} }
/* /*
* While inside interactive mode, launch the external command cmd on the given * While inside interactive mode, launch the external command cmd on the given
* file. * file.
*/ */
void void wins_launch_external(const char *file, const char *cmd)
wins_launch_external (const char *file, const char *cmd)
{ {
const char *arg[] = { cmd, file, NULL }; const char *arg[] = { cmd, file, NULL };
int pid; int pid;
wins_prepare_external (); wins_prepare_external();
if ((pid = shell_exec (NULL, NULL, *arg, arg))) if ((pid = shell_exec(NULL, NULL, *arg, arg)))
child_wait (NULL, NULL, pid); child_wait(NULL, NULL, pid);
wins_unprepare_external (); wins_unprepare_external();
} }
#define NB_CAL_CMDS 27 /* number of commands while in cal view */ #define NB_CAL_CMDS 27 /* number of commands while in cal view */
@ -643,47 +582,46 @@ static unsigned status_page;
* table, and update the NB_CAL_CMDS, NB_APP_CMDS or NB_TOD_CMDS defines, * table, and update the NB_CAL_CMDS, NB_APP_CMDS or NB_TOD_CMDS defines,
* depending on which panel the added keybind is assigned to. * depending on which panel the added keybind is assigned to.
*/ */
void void wins_status_bar(void)
wins_status_bar (void)
{ {
struct binding help = {_("Help"), KEY_GENERIC_HELP}; struct binding help = { _("Help"), KEY_GENERIC_HELP };
struct binding quit = {_("Quit"), KEY_GENERIC_QUIT}; struct binding quit = { _("Quit"), KEY_GENERIC_QUIT };
struct binding save = {_("Save"), KEY_GENERIC_SAVE}; struct binding save = { _("Save"), KEY_GENERIC_SAVE };
struct binding cut = {_("Cut"), KEY_GENERIC_CUT}; struct binding cut = { _("Cut"), KEY_GENERIC_CUT };
struct binding paste = {_("Paste"), KEY_GENERIC_PASTE}; struct binding paste = { _("Paste"), KEY_GENERIC_PASTE };
struct binding chgvu = {_("Chg Win"), KEY_GENERIC_CHANGE_VIEW}; struct binding chgvu = { _("Chg Win"), KEY_GENERIC_CHANGE_VIEW };
struct binding import = {_("Import"), KEY_GENERIC_IMPORT}; struct binding import = { _("Import"), KEY_GENERIC_IMPORT };
struct binding export = {_("Export"), KEY_GENERIC_EXPORT}; struct binding export = { _("Export"), KEY_GENERIC_EXPORT };
struct binding togo = {_("Go to"), KEY_GENERIC_GOTO}; struct binding togo = { _("Go to"), KEY_GENERIC_GOTO };
struct binding conf = {_("Config"), KEY_GENERIC_CONFIG_MENU}; struct binding conf = { _("Config"), KEY_GENERIC_CONFIG_MENU };
struct binding draw = {_("Redraw"), KEY_GENERIC_REDRAW}; struct binding draw = { _("Redraw"), KEY_GENERIC_REDRAW };
struct binding appt = {_("Add Appt"), KEY_GENERIC_ADD_APPT}; struct binding appt = { _("Add Appt"), KEY_GENERIC_ADD_APPT };
struct binding todo = {_("Add Todo"), KEY_GENERIC_ADD_TODO}; struct binding todo = { _("Add Todo"), KEY_GENERIC_ADD_TODO };
struct binding gnday = {_("+1 Day"), KEY_GENERIC_NEXT_DAY}; struct binding gnday = { _("+1 Day"), KEY_GENERIC_NEXT_DAY };
struct binding gpday = {_("-1 Day"), KEY_GENERIC_PREV_DAY}; struct binding gpday = { _("-1 Day"), KEY_GENERIC_PREV_DAY };
struct binding gnweek = {_("+1 Week"), KEY_GENERIC_NEXT_WEEK}; struct binding gnweek = { _("+1 Week"), KEY_GENERIC_NEXT_WEEK };
struct binding gpweek = {_("-1 Week"), KEY_GENERIC_PREV_WEEK}; struct binding gpweek = { _("-1 Week"), KEY_GENERIC_PREV_WEEK };
struct binding today = {_("Today"), KEY_GENERIC_GOTO_TODAY}; struct binding today = { _("Today"), KEY_GENERIC_GOTO_TODAY };
struct binding nview = {_("Nxt View"), KEY_GENERIC_SCROLL_DOWN}; struct binding nview = { _("Nxt View"), KEY_GENERIC_SCROLL_DOWN };
struct binding pview = {_("Prv View"), KEY_GENERIC_SCROLL_UP}; struct binding pview = { _("Prv View"), KEY_GENERIC_SCROLL_UP };
struct binding up = {_("Up"), KEY_MOVE_UP}; struct binding up = { _("Up"), KEY_MOVE_UP };
struct binding down = {_("Down"), KEY_MOVE_DOWN}; struct binding down = { _("Down"), KEY_MOVE_DOWN };
struct binding left = {_("Left"), KEY_MOVE_LEFT}; struct binding left = { _("Left"), KEY_MOVE_LEFT };
struct binding right = {_("Right"), KEY_MOVE_RIGHT}; struct binding right = { _("Right"), KEY_MOVE_RIGHT };
struct binding weekb = {_("beg Week"), KEY_START_OF_WEEK}; struct binding weekb = { _("beg Week"), KEY_START_OF_WEEK };
struct binding weeke = {_("end Week"), KEY_END_OF_WEEK}; struct binding weeke = { _("end Week"), KEY_END_OF_WEEK };
struct binding add = {_("Add Item"), KEY_ADD_ITEM}; struct binding add = { _("Add Item"), KEY_ADD_ITEM };
struct binding del = {_("Del Item"), KEY_DEL_ITEM}; struct binding del = { _("Del Item"), KEY_DEL_ITEM };
struct binding edit = {_("Edit Itm"), KEY_EDIT_ITEM}; struct binding edit = { _("Edit Itm"), KEY_EDIT_ITEM };
struct binding view = {_("View"), KEY_VIEW_ITEM}; struct binding view = { _("View"), KEY_VIEW_ITEM };
struct binding pipe = {_("Pipe"), KEY_PIPE_ITEM}; struct binding pipe = { _("Pipe"), KEY_PIPE_ITEM };
struct binding flag = {_("Flag Itm"), KEY_FLAG_ITEM}; struct binding flag = { _("Flag Itm"), KEY_FLAG_ITEM };
struct binding rept = {_("Repeat"), KEY_REPEAT_ITEM}; struct binding rept = { _("Repeat"), KEY_REPEAT_ITEM };
struct binding enote = {_("EditNote"), KEY_EDIT_NOTE}; struct binding enote = { _("EditNote"), KEY_EDIT_NOTE };
struct binding vnote = {_("ViewNote"), KEY_VIEW_NOTE}; struct binding vnote = { _("ViewNote"), KEY_VIEW_NOTE };
struct binding rprio = {_("Prio.+"), KEY_RAISE_PRIORITY}; struct binding rprio = { _("Prio.+"), KEY_RAISE_PRIORITY };
struct binding lprio = {_("Prio.-"), KEY_LOWER_PRIORITY}; struct binding lprio = { _("Prio.-"), KEY_LOWER_PRIORITY };
struct binding othr = {_("OtherCmd"), KEY_GENERIC_OTHER_CMD}; struct binding othr = { _("OtherCmd"), KEY_GENERIC_OTHER_CMD };
struct binding *bindings_cal[] = { struct binding *bindings_cal[] = {
&help, &quit, &save, &chgvu, &nview, &pview, &up, &down, &left, &right, &help, &quit, &save, &chgvu, &nview, &pview, &up, &down, &left, &right,
@ -703,50 +641,46 @@ wins_status_bar (void)
&gnweek, &gpweek, &togo, &today, &conf, &appt, &todo, &draw &gnweek, &gpweek, &togo, &today, &conf, &appt, &todo, &draw
}; };
enum win active_panel = wins_slctd (); enum win active_panel = wins_slctd();
struct binding **bindings; struct binding **bindings;
int bindings_size; int bindings_size;
switch (active_panel) switch (active_panel) {
{
case CAL: case CAL:
bindings = bindings_cal; bindings = bindings_cal;
bindings_size = sizeof (bindings_cal) / sizeof (bindings_cal[0]); bindings_size = sizeof(bindings_cal) / sizeof(bindings_cal[0]);
break; break;
case APP: case APP:
bindings = bindings_apoint; bindings = bindings_apoint;
bindings_size = sizeof (bindings_apoint) / sizeof (bindings_apoint[0]); bindings_size = sizeof(bindings_apoint) / sizeof(bindings_apoint[0]);
break; break;
case TOD: case TOD:
bindings = bindings_todo; bindings = bindings_todo;
bindings_size = sizeof (bindings_todo) / sizeof (bindings_todo[0]); bindings_size = sizeof(bindings_todo) / sizeof(bindings_todo[0]);
break; break;
default: default:
EXIT (_("unknown panel")); EXIT(_("unknown panel"));
/* NOTREACHED */ /* NOTREACHED */
} }
keys_display_bindings_bar (win[STA].p, bindings, bindings_size, keys_display_bindings_bar(win[STA].p, bindings, bindings_size,
(KEYS_CMDS_PER_LINE * 2 - 1) * (status_page - 1), (KEYS_CMDS_PER_LINE * 2 - 1) * (status_page - 1),
KEYS_CMDS_PER_LINE * 2, &othr); KEYS_CMDS_PER_LINE * 2, &othr);
} }
/* Erase status bar. */ /* Erase status bar. */
void void wins_erase_status_bar(void)
wins_erase_status_bar (void)
{ {
erase_window_part (win[STA].p, 0, 0, col, STATUSHEIGHT); erase_window_part(win[STA].p, 0, 0, col, STATUSHEIGHT);
} }
/* Update the status bar page number to display other commands. */ /* Update the status bar page number to display other commands. */
void void wins_other_status_page(int panel)
wins_other_status_page (int panel)
{ {
int nb_item, max_page; int nb_item, max_page;
switch (panel) switch (panel) {
{
case CAL: case CAL:
nb_item = NB_CAL_CMDS; nb_item = NB_CAL_CMDS;
break; break;
@ -757,7 +691,7 @@ wins_other_status_page (int panel)
nb_item = NB_TOD_CMDS; nb_item = NB_TOD_CMDS;
break; break;
default: default:
EXIT (_("unknown panel")); EXIT(_("unknown panel"));
/* NOTREACHED */ /* NOTREACHED */
} }
max_page = nb_item / (KEYS_CMDS_PER_LINE * 2 - 1) + 1; max_page = nb_item / (KEYS_CMDS_PER_LINE * 2 - 1) + 1;
@ -765,8 +699,7 @@ wins_other_status_page (int panel)
} }
/* Reset the status bar page. */ /* Reset the status bar page. */
void void wins_reset_status_page(void)
wins_reset_status_page (void)
{ {
status_page = 1; status_page = 1;
} }

View File

@ -50,63 +50,53 @@
* appropriate file descriptors are written to pfdin/pfdout. * appropriate file descriptors are written to pfdin/pfdout.
*/ */
static int static int
fork_exec (int *pfdin, int *pfdout, const char *path, char *const *arg) fork_exec(int *pfdin, int *pfdout, const char *path, char *const *arg)
{ {
int pin[2], pout[2]; int pin[2], pout[2];
int pid; int pid;
if (pfdin && (pipe (pin) == -1)) if (pfdin && (pipe(pin) == -1))
return 0; return 0;
if (pfdout && (pipe (pout) == -1)) if (pfdout && (pipe(pout) == -1))
return 0; return 0;
if ((pid = fork ()) == 0) if ((pid = fork()) == 0) {
{ if (pfdout) {
if (dup2(pout[0], STDIN_FILENO) < 0)
_exit(127);
close(pout[0]);
close(pout[1]);
}
if (pfdin) {
if (dup2(pin[1], STDOUT_FILENO) < 0)
_exit(127);
close(pin[0]);
close(pin[1]);
}
execvp(path, arg);
_exit(127);
} else {
if (pfdin)
close(pin[1]);
if (pfdout) if (pfdout)
{ close(pout[0]);
if (dup2 (pout[0], STDIN_FILENO) < 0)
_exit (127);
close (pout[0]);
close (pout[1]);
}
if (pfdin) if (pid > 0) {
{ if (pfdin) {
if (dup2 (pin[1], STDOUT_FILENO) < 0) fcntl(pin[0], F_SETFD, FD_CLOEXEC);
_exit (127);
close (pin[0]);
close (pin[1]);
}
execvp (path, arg);
_exit (127);
}
else
{
if (pfdin)
close (pin[1]);
if (pfdout)
close (pout[0]);
if (pid > 0)
{
if (pfdin)
{
fcntl (pin[0], F_SETFD, FD_CLOEXEC);
*pfdin = pin[0]; *pfdin = pin[0];
} }
if (pfdout) if (pfdout) {
{ fcntl(pout[1], F_SETFD, FD_CLOEXEC);
fcntl (pout[1], F_SETFD, FD_CLOEXEC);
*pfdout = pout[1]; *pfdout = pout[1];
} }
} } else {
else
{
if (pfdin) if (pfdin)
close (pin[0]); close(pin[0]);
if (pfdout) if (pfdout)
close (pout[1]); close(pout[1]);
return 0; return 0;
} }
} }
@ -114,44 +104,40 @@ fork_exec (int *pfdin, int *pfdout, const char *path, char *const *arg)
} }
/* Wait for a child process to terminate. */ /* Wait for a child process to terminate. */
static int static int child_wait(int *pfdin, int *pfdout, int pid)
child_wait (int *pfdin, int *pfdout, int pid)
{ {
int stat; int stat;
if (pfdin) if (pfdin)
close (*pfdin); close(*pfdin);
if (pfdout) if (pfdout)
close (*pfdout); close(*pfdout);
waitpid (pid, &stat, 0); waitpid(pid, &stat, 0);
return stat; return stat;
} }
/* Print error message and bail out. */ /* Print error message and bail out. */
static void static void die(const char *format, ...)
die (const char *format, ...)
{ {
va_list arg; va_list arg;
va_start (arg, format); va_start(arg, format);
fprintf (stderr, "error: "); fprintf(stderr, "error: ");
vfprintf (stderr, format, arg); vfprintf(stderr, format, arg);
va_end (arg); va_end(arg);
exit (1); exit(1);
} }
/* Print usage message. */ /* Print usage message. */
static void static void usage(void)
usage (void)
{ {
printf ("usage: run-test [-h|--help] <test>...\n"); printf("usage: run-test [-h|--help] <test>...\n");
} }
/* Run test with a specific name. */ /* Run test with a specific name. */
static int static int run_test(const char *name, int expect_failure)
run_test (const char *name, int expect_failure)
{ {
char filename[BUFSIZ]; char filename[BUFSIZ];
char *arg1[3], *arg2[3]; char *arg1[3], *arg2[3];
@ -160,90 +146,81 @@ run_test (const char *name, int expect_failure)
char buf1[BUFSIZ], buf2[BUFSIZ]; char buf1[BUFSIZ], buf2[BUFSIZ];
int ret = 1; int ret = 1;
if (snprintf (filename, BUFSIZ, "./%s", name) >= BUFSIZ) if (snprintf(filename, BUFSIZ, "./%s", name) >= BUFSIZ)
die ("file name too long\n"); die("file name too long\n");
if (access (filename, F_OK) != 0) if (access(filename, F_OK) != 0) {
{ if (snprintf(filename, BUFSIZ, "./%s.sh", name) >= BUFSIZ)
if (snprintf (filename, BUFSIZ, "./%s.sh", name) >= BUFSIZ) die("file name too long\n");
die ("file name too long\n");
if (access (filename, F_OK) != 0) if (access(filename, F_OK) != 0)
die ("test not found: %s\n", name); die("test not found: %s\n", name);
} }
if (access (filename, X_OK) != 0) if (access(filename, X_OK) != 0)
die ("script is not executable: %s\n", filename); die("script is not executable: %s\n", filename);
arg1[0] = arg2[0] = filename; arg1[0] = arg2[0] = filename;
arg1[1] = "expected"; arg1[1] = "expected";
arg2[1] = "actual"; arg2[1] = "actual";
arg1[2] = arg2[2] = NULL; arg1[2] = arg2[2] = NULL;
printf ("Running %s...", name); printf("Running %s...", name);
if ((pid1 = fork_exec (&pin1, NULL, *arg1, arg1)) < 0) if ((pid1 = fork_exec(&pin1, NULL, *arg1, arg1)) < 0)
die("failed to execute %s: %s\n", filename, strerror (errno)); die("failed to execute %s: %s\n", filename, strerror(errno));
if ((pid2 = fork_exec (&pin2, NULL, *arg2, arg2)) < 0) if ((pid2 = fork_exec(&pin2, NULL, *arg2, arg2)) < 0)
die("failed to execute %s: %s\n", filename, strerror (errno)); die("failed to execute %s: %s\n", filename, strerror(errno));
fpin1 = fdopen (pin1, "r"); fpin1 = fdopen(pin1, "r");
fpin2 = fdopen (pin2, "r"); fpin2 = fdopen(pin2, "r");
while (fgets (buf1, BUFSIZ, fpin1)) while (fgets(buf1, BUFSIZ, fpin1)) {
{ if (!fgets(buf2, BUFSIZ, fpin2) || strcmp(buf1, buf2) != 0) {
if (!fgets (buf2, BUFSIZ, fpin2) || strcmp (buf1, buf2) != 0)
{
ret = 0; ret = 0;
break; break;
} }
} }
if (fpin1) if (fpin1)
fclose (fpin1); fclose(fpin1);
if (fpin2) if (fpin2)
fclose (fpin2); fclose(fpin2);
if (child_wait (&pin1, NULL, pid1) != 0) if (child_wait(&pin1, NULL, pid1) != 0)
ret = 0; ret = 0;
if (child_wait (&pin2, NULL, pid2) != 0) if (child_wait(&pin2, NULL, pid2) != 0)
ret = 0; ret = 0;
if (expect_failure) if (expect_failure)
ret = 1 - ret; ret = 1 - ret;
if (ret == 1) if (ret == 1)
printf (" ok\n"); printf(" ok\n");
else else
printf (" FAIL\n"); printf(" FAIL\n");
return ret; return ret;
} }
int int main(int argc, char **argv)
main (int argc, char **argv)
{ {
int i; int i;
if (!argv[1]) if (!argv[1])
die ("no tests specified, bailing out\n"); die("no tests specified, bailing out\n");
else if (strcmp (argv[1], "-h") == 0 || strcmp (argv[1], "--help") == 0) else if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) {
{
usage(); usage();
return 0; return 0;
} }
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++) {
{ if (*argv[i] == '!') {
if (*argv[i] == '!') if (!run_test(argv[i] + 1, 1))
{
if (!run_test (argv[i] + 1, 1))
return 1; return 1;
} } else {
else if (!run_test(argv[i], 0))
{
if (!run_test (argv[i], 0))
return 1; return 1;
} }
} }