aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xChangeLog4
-rwxr-xr-xsrc/apoint.c966
-rwxr-xr-xsrc/apoint.h72
-rwxr-xr-xsrc/args.c1001
-rwxr-xr-xsrc/args.h4
-rwxr-xr-xsrc/calcurse.c870
-rwxr-xr-xsrc/calendar.c742
-rwxr-xr-xsrc/calendar.h98
-rwxr-xr-xsrc/custom.c1419
-rwxr-xr-xsrc/custom.h87
-rwxr-xr-xsrc/day.c1432
-rwxr-xr-xsrc/day.h66
-rwxr-xr-xsrc/event.c216
-rwxr-xr-xsrc/event.h27
-rwxr-xr-xsrc/help.c1060
-rwxr-xr-xsrc/help.h14
-rwxr-xr-xsrc/i18n.h34
-rwxr-xr-xsrc/io.c1526
-rwxr-xr-xsrc/io.h32
-rwxr-xr-xsrc/notify.c958
-rwxr-xr-xsrc/notify.h58
-rwxr-xr-xsrc/recur.c1477
-rwxr-xr-xsrc/recur.h128
-rwxr-xr-xsrc/sigs.c74
-rwxr-xr-xsrc/sigs.h6
-rwxr-xr-xsrc/todo.c647
-rwxr-xr-xsrc/todo.h53
-rwxr-xr-xsrc/utils.c1370
-rwxr-xr-xsrc/utils.h124
-rwxr-xr-xsrc/vars.c135
-rwxr-xr-xsrc/vars.h86
-rwxr-xr-xsrc/wins.c573
-rwxr-xr-xsrc/wins.h66
33 files changed, 7992 insertions, 7433 deletions
diff --git a/ChangeLog b/ChangeLog
index 3b66c05..8d216eb 100755
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+12 Apr 2008:
+ Yet another style for source code. GNU style now used (I am fed up
+ with tabs...)
+
09 Apr 2008:
Tony's patch concerning date format configuration imported, many
thanks to him
diff --git a/src/apoint.c b/src/apoint.c
index 380599a..c57f24c 100755
--- a/src/apoint.c
+++ b/src/apoint.c
@@ -1,4 +1,4 @@
-/* $calcurse: apoint.c,v 1.21 2008/01/20 10:45:38 culot Exp $ */
+/* $calcurse: apoint.c,v 1.22 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -40,386 +40,420 @@
#include "calendar.h"
apoint_llist_t *alist_p;
-static int hilt = 0;
+static int hilt = 0;
-int
-apoint_llist_init(void)
+int
+apoint_llist_init (void)
{
- alist_p = (apoint_llist_t *) malloc(sizeof(apoint_llist_t));
- alist_p->root = NULL;
- pthread_mutex_init(&(alist_p->mutex), NULL);
+ alist_p = (apoint_llist_t *) malloc (sizeof (apoint_llist_t));
+ alist_p->root = NULL;
+ pthread_mutex_init (&(alist_p->mutex), NULL);
- return 0;
+ return (0);
}
/* Sets which appointment is highlighted. */
void
-apoint_hilt_set(int highlighted)
+apoint_hilt_set (int highlighted)
{
- hilt = highlighted;
+ hilt = highlighted;
}
void
-apoint_hilt_decrease(void)
+apoint_hilt_decrease (void)
{
- hilt--;
+ hilt--;
}
void
-apoint_hilt_increase(void)
+apoint_hilt_increase (void)
{
- hilt++;
+ hilt++;
}
/* Return which appointment is highlighted. */
int
-apoint_hilt(void)
+apoint_hilt (void)
{
- return (hilt);
+ return (hilt);
}
apoint_llist_node_t *
-apoint_new(char *mesg, char *note, long start, long dur, char state)
+apoint_new (char *mesg, char *note, long start, long dur, char state)
{
- apoint_llist_node_t *o, **i;
-
- o = (apoint_llist_node_t *) malloc(sizeof(apoint_llist_node_t));
- o->mesg = (char *) malloc(strlen(mesg) + 1);
- strncpy(o->mesg, mesg, strlen(mesg) + 1);
- o->note = (note != NULL) ? strdup(note) : NULL;
- o->state = state;
- o->start = start;
- o->dur = dur;
-
- pthread_mutex_lock(&(alist_p->mutex));
- i = &alist_p->root;
- for (;;) {
- if (*i == 0 || (*i)->start > start) {
- o->next = *i;
- *i = o;
- break;
- }
- i = &(*i)->next;
+ apoint_llist_node_t *o, **i;
+
+ o = (apoint_llist_node_t *) malloc (sizeof (apoint_llist_node_t));
+ o->mesg = (char *) malloc (strlen (mesg) + 1);
+ strncpy (o->mesg, mesg, strlen (mesg) + 1);
+ o->note = (note != NULL) ? strdup (note) : NULL;
+ o->state = state;
+ o->start = start;
+ o->dur = dur;
+
+ pthread_mutex_lock (&(alist_p->mutex));
+ i = &alist_p->root;
+ for (;;)
+ {
+ if (*i == 0 || (*i)->start > start)
+ {
+ o->next = *i;
+ *i = o;
+ break;
}
- pthread_mutex_unlock(&(alist_p->mutex));
+ i = &(*i)->next;
+ }
+ pthread_mutex_unlock (&(alist_p->mutex));
- return o;
+ return (o);
}
/*
* Add an item in either the appointment or the event list,
* depending if the start time is entered or not.
*/
-void
-apoint_add(void)
+void
+apoint_add (void)
{
#define LTIME 6
- char *mesg_1 = _("Enter start time ([hh:mm] or [h:mm]), leave blank for an all-day event : ");
- char *mesg_2 = _("Enter end time ([hh:mm] or [h:mm]) or duration (in minutes) : ");
- char *mesg_3 = _("Enter description :");
- char *format_message_1 = _("You entered an invalid start time, should be [h:mm] or [hh:mm]");
- char *format_message_2 = _("You entered an invalid end time, should be [h:mm] or [hh:mm] or [mm]");
- char *enter_str = _("Press [Enter] to continue");
- int Id = 1;
- char item_time[LTIME] = "";
- char item_mesg[BUFSIZ] = "";
- long apoint_duration = 0, apoint_start;
- apoint_llist_node_t *apoint_pointeur;
- struct event_s *event_pointeur;
- unsigned heures, minutes;
- unsigned end_h, end_m;
- int is_appointment = 1;
-
- /* Get the starting time */
- while (check_time(item_time) != 1) {
- status_mesg(mesg_1, "");
- if (getstring(win[STA].p, item_time, LTIME, 0, 1) !=
- GETSTRING_ESC) {
- if (strlen(item_time) == 0){
- is_appointment = 0;
- break;
- } else if (check_time(item_time) != 1) {
- status_mesg(format_message_1, enter_str);
- wgetch(win[STA].p);
- } else
- sscanf(item_time, "%u:%u", &heures, &minutes);
- } else
- return;
+ char *mesg_1 =
+ _("Enter start time ([hh:mm] or [h:mm]), "
+ "leave blank for an all-day event : ");
+ char *mesg_2 =
+ _("Enter end time ([hh:mm] or [h:mm]) or duration (in minutes) : ");
+ char *mesg_3 = _("Enter description :");
+ char *format_message_1 =
+ _("You entered an invalid start time, should be [h:mm] or [hh:mm]");
+ char *format_message_2 =
+ _("You entered an invalid end time, should be [h:mm] or [hh:mm] or [mm]");
+ char *enter_str = _("Press [Enter] to continue");
+ int Id = 1;
+ char item_time[LTIME] = "";
+ char item_mesg[BUFSIZ] = "";
+ long apoint_duration = 0, apoint_start;
+ apoint_llist_node_t *apoint_pointeur;
+ struct event_s *event_pointeur;
+ unsigned heures, minutes;
+ unsigned end_h, end_m;
+ int is_appointment = 1;
+
+ /* Get the starting time */
+ while (check_time (item_time) != 1)
+ {
+ status_mesg (mesg_1, "");
+ if (getstring (win[STA].p, item_time, LTIME, 0, 1) != GETSTRING_ESC)
+ {
+ if (strlen (item_time) == 0)
+ {
+ is_appointment = 0;
+ break;
+ }
+ else if (check_time (item_time) != 1)
+ {
+ status_mesg (format_message_1, enter_str);
+ wgetch (win[STA].p);
+ }
+ else
+ sscanf (item_time, "%u:%u", &heures, &minutes);
}
- /*
- * Check if an event or appointment is entered,
- * depending on the starting time, and record the
- * corresponding item.
- */
- if (is_appointment){ /* Get the appointment duration */
- item_time[0] = '\0';
- while (check_time(item_time) == 0) {
- status_mesg(mesg_2, "");
- if (getstring(win[STA].p, item_time, LTIME, 0, 1) !=
- GETSTRING_VALID)
- return; //nothing entered, cancel adding of event
- else if (check_time(item_time) == 0) {
- status_mesg(format_message_2, enter_str);
- wgetch(win[STA].p);
- } else {
- if (check_time(item_time) == 2)
- apoint_duration = atoi(item_time);
- else if (check_time(item_time) == 1) {
- sscanf(item_time, "%u:%u",
- &end_h, &end_m);
- if (end_h < heures){
- apoint_duration =
- MININSEC - minutes + end_m
- +
- (24 + end_h - (heures + 1))
- * MININSEC;
- } else {
- apoint_duration =
- MININSEC - minutes +
- end_m +
- (end_h - (heures + 1)) *
- MININSEC;
- }
- }
- }
- }
- } else /* Insert the event Id */
- Id = 1;
-
- status_mesg(mesg_3, "");
- if (getstring(win[STA].p, item_mesg, BUFSIZ, 0, 1) ==
- GETSTRING_VALID) {
- if (is_appointment) {
- apoint_start =
- date2sec(*calendar_get_slctd_day(), heures,
- minutes);
- apoint_pointeur = apoint_new(item_mesg, 0L, apoint_start,
- min2sec(apoint_duration), 0L);
- if (notify_bar())
- notify_check_added(item_mesg, apoint_start, 0L);
- } else
- event_pointeur = event_new(item_mesg, 0L,
- date2sec(*calendar_get_slctd_day(), 12, 0), Id);
-
- if (hilt == 0)
- hilt++;
+ else
+ return;
+ }
+ /*
+ * Check if an event or appointment is entered,
+ * depending on the starting time, and record the
+ * corresponding item.
+ */
+ if (is_appointment)
+ { /* Get the appointment duration */
+ item_time[0] = '\0';
+ while (check_time (item_time) == 0)
+ {
+ status_mesg (mesg_2, "");
+ if (getstring (win[STA].p, item_time, LTIME, 0, 1) != GETSTRING_VALID)
+ return; //nothing entered, cancel adding of event
+ else if (check_time (item_time) == 0)
+ {
+ status_mesg (format_message_2, enter_str);
+ wgetch (win[STA].p);
+ }
+ else
+ {
+ if (check_time (item_time) == 2)
+ apoint_duration = atoi (item_time);
+ else if (check_time (item_time) == 1)
+ {
+ sscanf (item_time, "%u:%u", &end_h, &end_m);
+ if (end_h < heures)
+ {
+ apoint_duration = MININSEC - minutes + end_m
+ + (24 + end_h - (heures + 1)) * MININSEC;
+ }
+ else
+ {
+ apoint_duration = MININSEC - minutes
+ + end_m + (end_h - (heures + 1)) * MININSEC;
+ }
+ }
+ }
+ }
+ }
+ else /* Insert the event Id */
+ Id = 1;
+
+ status_mesg (mesg_3, "");
+ if (getstring (win[STA].p, item_mesg, BUFSIZ, 0, 1) == GETSTRING_VALID)
+ {
+ if (is_appointment)
+ {
+ apoint_start = date2sec (*calendar_get_slctd_day (), heures, minutes);
+ apoint_pointeur = apoint_new (item_mesg, 0L, apoint_start,
+ min2sec (apoint_duration), 0L);
+ if (notify_bar ())
+ notify_check_added (item_mesg, apoint_start, 0L);
}
- erase_status_bar();
+ else
+ event_pointeur = event_new (item_mesg, 0L,
+ date2sec (*calendar_get_slctd_day (), 12,
+ 0), Id);
+
+ if (hilt == 0)
+ hilt++;
+ }
+ erase_status_bar ();
}
/* Delete an item from the appointment list. */
-void
-apoint_delete(conf_t *conf, unsigned *nb_events, unsigned *nb_apoints)
+void
+apoint_delete (conf_t *conf, unsigned *nb_events, unsigned *nb_apoints)
{
- char *choices = "[y/n] ";
- char *del_app_str = _("Do you really want to delete this item ?");
- const char *errmsg = _("FATAL ERROR in apoint_delete: no such type\n");
- long date;
- int nb_items = *nb_apoints + *nb_events;
- bool go_for_deletion = false;
- int to_be_removed = 0;
- int answer = 0;
- int deleted_item_type = 0;
-
- date = calendar_get_slctd_day_sec();
-
- if (conf->confirm_delete) {
- status_mesg(del_app_str, choices);
- answer = wgetch(win[STA].p);
- if ( (answer == 'y') && (nb_items != 0) )
- go_for_deletion = true;
- else {
- erase_status_bar();
- return;
- }
- } else
- if (nb_items != 0)
- go_for_deletion = true;
-
- if (go_for_deletion) {
- if (nb_items != 0) {
- deleted_item_type =
- day_erase_item(date, hilt, ERASE_DONT_FORCE);
- if (deleted_item_type == EVNT ||
- deleted_item_type == RECUR_EVNT) {
- (*nb_events)--;
- to_be_removed = 1;
- } else if (deleted_item_type == APPT ||
- deleted_item_type == RECUR_APPT) {
- (*nb_apoints)--;
- to_be_removed = 3;
- } else if (deleted_item_type == 0) {
- to_be_removed = 0;
- } else
- ierror(errmsg, IERROR_FATAL);
- /* NOTREACHED */
-
- if (hilt > 1)
- hilt--;
- if (apad->first_onscreen >= to_be_removed)
- apad->first_onscreen =
- apad->first_onscreen -
- to_be_removed;
- if (nb_items == 1)
- hilt = 0;
- }
+ char *choices = "[y/n] ";
+ char *del_app_str = _("Do you really want to delete this item ?");
+ const char *errmsg = _("FATAL ERROR in apoint_delete: no such type\n");
+ long date;
+ int nb_items = *nb_apoints + *nb_events;
+ bool go_for_deletion = false;
+ int to_be_removed = 0;
+ int answer = 0;
+ int deleted_item_type = 0;
+
+ date = calendar_get_slctd_day_sec ();
+
+ if (conf->confirm_delete)
+ {
+ status_mesg (del_app_str, choices);
+ answer = wgetch (win[STA].p);
+ if ((answer == 'y') && (nb_items != 0))
+ go_for_deletion = true;
+ else
+ {
+ erase_status_bar ();
+ return;
+ }
+ }
+ else if (nb_items != 0)
+ go_for_deletion = true;
+
+ if (go_for_deletion)
+ {
+ if (nb_items != 0)
+ {
+ deleted_item_type = day_erase_item (date, hilt, ERASE_DONT_FORCE);
+ if (deleted_item_type == EVNT || deleted_item_type == RECUR_EVNT)
+ {
+ (*nb_events)--;
+ to_be_removed = 1;
+ }
+ else if (deleted_item_type == APPT || deleted_item_type == RECUR_APPT)
+ {
+ (*nb_apoints)--;
+ to_be_removed = 3;
+ }
+ else if (deleted_item_type == 0)
+ {
+ to_be_removed = 0;
+ }
+ else
+ ierror (errmsg, IERROR_FATAL);
+ /* NOTREACHED */
+
+ if (hilt > 1)
+ hilt--;
+ if (apad->first_onscreen >= to_be_removed)
+ apad->first_onscreen = apad->first_onscreen - to_be_removed;
+ if (nb_items == 1)
+ hilt = 0;
}
+ }
}
-unsigned
-apoint_inday(apoint_llist_node_t *i, long start)
+unsigned
+apoint_inday (apoint_llist_node_t *i, long start)
{
- if (i->start <= start + DAYINSEC && i->start + i->dur > start) {
- return 1;
- }
- return 0;
+ if (i->start <= start + DAYINSEC && i->start + i->dur > start)
+ {
+ return (1);
+ }
+ return (0);
}
-void
-apoint_sec2str(apoint_llist_node_t *o, int type, long day, char *start,
- char *end)
+void
+apoint_sec2str (apoint_llist_node_t *o, int type, long day, char *start,
+ char *end)
{
- struct tm *lt;
- time_t t;
-
- if (o->start < day && type == APPT) {
- strncpy(start, "..:..", 6);
- } else {
- t = o->start;
- lt = localtime(&t);
- snprintf(start, HRMIN_SIZE, "%02u:%02u", lt->tm_hour,
- lt->tm_min);
- }
- if (o->start + o->dur > day + DAYINSEC && type == APPT) {
- strncpy(end, "..:..", 6);
- } else {
- t = o->start + o->dur;
- lt = localtime(&t);
- snprintf(end, HRMIN_SIZE, "%02u:%02u", lt->tm_hour,
- lt->tm_min);
- }
+ struct tm *lt;
+ time_t t;
+
+ if (o->start < day && type == APPT)
+ {
+ strncpy (start, "..:..", 6);
+ }
+ else
+ {
+ t = o->start;
+ lt = localtime (&t);
+ snprintf (start, HRMIN_SIZE, "%02u:%02u", lt->tm_hour, lt->tm_min);
+ }
+ if (o->start + o->dur > day + DAYINSEC && type == APPT)
+ {
+ strncpy (end, "..:..", 6);
+ }
+ else
+ {
+ t = o->start + o->dur;
+ lt = localtime (&t);
+ snprintf (end, HRMIN_SIZE, "%02u:%02u", lt->tm_hour, lt->tm_min);
+ }
}
-void
-apoint_write(apoint_llist_node_t *o, FILE * f)
+void
+apoint_write (apoint_llist_node_t *o, FILE *f)
{
- struct tm *lt;
- time_t t;
-
- t = o->start;
- lt = localtime(&t);
- fprintf(f, "%02u/%02u/%04u @ %02u:%02u",
- lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year,
- lt->tm_hour, lt->tm_min);
-
- t = o->start + o->dur;
- lt = localtime(&t);
- fprintf(f, " -> %02u/%02u/%04u @ %02u:%02u ",
- lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year,
- lt->tm_hour, lt->tm_min);
-
- if (o->note != NULL)
- fprintf(f, ">%s ", o->note);
-
- if (o->state & APOINT_NOTIFY)
- fprintf(f, "!");
- else
- fprintf(f, "|");
-
- fprintf(f, "%s\n", o->mesg);
+ struct tm *lt;
+ time_t t;
+
+ t = o->start;
+ lt = localtime (&t);
+ fprintf (f, "%02u/%02u/%04u @ %02u:%02u",
+ lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year, lt->tm_hour,
+ lt->tm_min);
+
+ t = o->start + o->dur;
+ lt = localtime (&t);
+ fprintf (f, " -> %02u/%02u/%04u @ %02u:%02u ",
+ lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year, lt->tm_hour,
+ lt->tm_min);
+
+ if (o->note != NULL)
+ fprintf (f, ">%s ", o->note);
+
+ if (o->state & APOINT_NOTIFY)
+ fprintf (f, "!");
+ else
+ fprintf (f, "|");
+
+ fprintf (f, "%s\n", o->mesg);
}
apoint_llist_node_t *
-apoint_scan(FILE * f, struct tm start, struct tm end, char state, char *note)
+apoint_scan (FILE *f, struct tm start, struct tm end, char state, char *note)
{
- struct tm *lt;
- char buf[MESG_MAXSIZE], *nl;
- time_t tstart, tend, t;
-
- t = time(NULL);
- lt = localtime(&t);
-
- /* Read the appointment description */
- fgets(buf, MESG_MAXSIZE, f);
- nl = strchr(buf, '\n');
- if (nl) {
- *nl = '\0';
- }
-
- start.tm_sec = end.tm_sec = 0;
- start.tm_isdst = end.tm_isdst = -1;
- start.tm_year -= 1900;
- start.tm_mon--;
- end.tm_year -= 1900;
- end.tm_mon--;
-
- tstart = mktime(&start);
- tend = mktime(&end);
- if (tstart == -1 || tend == -1 || tstart > tend) {
- fputs(_("FATAL ERROR in apoint_scan: date error in the appointment\n"), stderr);
- exit(EXIT_FAILURE);
- }
- return (apoint_new(buf, note, tstart, tend - tstart, state));
+ struct tm *lt;
+ char buf[MESG_MAXSIZE], *nl;
+ time_t tstart, tend, t;
+
+ t = time (NULL);
+ lt = localtime (&t);
+
+ /* Read the appointment description */
+ fgets (buf, MESG_MAXSIZE, f);
+ nl = strchr (buf, '\n');
+ if (nl)
+ {
+ *nl = '\0';
+ }
+
+ start.tm_sec = end.tm_sec = 0;
+ start.tm_isdst = end.tm_isdst = -1;
+ start.tm_year -= 1900;
+ start.tm_mon--;
+ end.tm_year -= 1900;
+ end.tm_mon--;
+
+ tstart = mktime (&start);
+ tend = mktime (&end);
+ if (tstart == -1 || tend == -1 || tstart > tend)
+ {
+ fputs (_("FATAL ERROR in apoint_scan: date error in the appointment\n"),
+ stderr);
+ exit (EXIT_FAILURE);
+ }
+ return (apoint_new (buf, note, tstart, tend - tstart, state));
}
/* Retrieve an appointment from the list, given the day and item position. */
apoint_llist_node_t *
-apoint_get(long day, int pos)
+apoint_get (long day, int pos)
{
- apoint_llist_node_t *o;
- int n;
-
- n = 0;
- for (o = alist_p->root; o; o = o->next) {
- if (apoint_inday(o, day)) {
- if (n == pos)
- return o;
- n++;
- }
+ apoint_llist_node_t *o;
+ int n;
+
+ n = 0;
+ for (o = alist_p->root; o; o = o->next)
+ {
+ if (apoint_inday (o, day))
+ {
+ if (n == pos)
+ return (o);
+ n++;
}
- /* NOTREACHED */
- fputs(_("FATAL ERROR in apoint_get: no such item\n"), stderr);
- exit(EXIT_FAILURE);
+ }
+ /* NOTREACHED */
+ fputs (_("FATAL ERROR in apoint_get: no such item\n"), stderr);
+ exit (EXIT_FAILURE);
}
-void
-apoint_delete_bynum(long start, unsigned num, erase_flag_e flag)
+void
+apoint_delete_bynum (long start, unsigned num, erase_flag_e flag)
{
- unsigned n;
- int need_check_notify = 0;
- apoint_llist_node_t *i, **iptr;
-
- n = 0;
- pthread_mutex_lock(&(alist_p->mutex));
- iptr = &alist_p->root;
- for (i = alist_p->root; i != 0; i = i->next) {
- if (apoint_inday(i, start)) {
- if (n == num) {
- if (flag == ERASE_FORCE_ONLY_NOTE)
- erase_note(&i->note, flag);
- else {
- if (notify_bar())
- need_check_notify =
- notify_same_item(i->start);
- *iptr = i->next;
- free(i->mesg);
- erase_note(&i->note, flag);
- free(i);
- pthread_mutex_unlock(&(alist_p->mutex));
- if (need_check_notify)
- notify_check_next_app();
- }
- return;
- }
- n++;
+ unsigned n;
+ int need_check_notify = 0;
+ apoint_llist_node_t *i, **iptr;
+
+ n = 0;
+ pthread_mutex_lock (&(alist_p->mutex));
+ iptr = &alist_p->root;
+ for (i = alist_p->root; i != 0; i = i->next)
+ {
+ if (apoint_inday (i, start))
+ {
+ if (n == num)
+ {
+ if (flag == ERASE_FORCE_ONLY_NOTE)
+ erase_note (&i->note, flag);
+ else
+ {
+ if (notify_bar ())
+ need_check_notify = notify_same_item (i->start);
+ *iptr = i->next;
+ free (i->mesg);
+ erase_note (&i->note, flag);
+ free (i);
+ pthread_mutex_unlock (&(alist_p->mutex));
+ if (need_check_notify)
+ notify_check_next_app ();
}
- iptr = &i->next;
+ return;
+ }
+ n++;
}
- pthread_mutex_unlock(&(alist_p->mutex));
+ iptr = &i->next;
+ }
+ pthread_mutex_unlock (&(alist_p->mutex));
- /* NOTREACHED */
- ierror(_("FATAL ERROR in apoint_delete_bynum: no such appointment"),
- IERROR_FATAL);
+ /* NOTREACHED */
+ ierror (_("FATAL ERROR in apoint_delete_bynum: no such appointment"),
+ IERROR_FATAL);
}
/*
@@ -427,54 +461,54 @@ apoint_delete_bynum(long start, unsigned num, erase_flag_e flag)
* the appointment panel. This is to help the appointment scroll function
* to place beggining of the pad correctly.
*/
-static int
-get_item_line(int item_nb, int nb_events_inday)
+static int
+get_item_line (int item_nb, int nb_events_inday)
{
- int separator = 2;
- int line = 0;
-
- if (item_nb <= nb_events_inday)
- line = item_nb - 1;
- else
- line = nb_events_inday + separator +
- (item_nb - (nb_events_inday + 1))*3 - 1;
- return line;
+ int separator = 2;
+ int line = 0;
+
+ if (item_nb <= nb_events_inday)
+ line = item_nb - 1;
+ else
+ line = nb_events_inday + separator
+ + (item_nb - (nb_events_inday + 1)) * 3 - 1;
+ return line;
}
/*
* Update (if necessary) the first displayed pad line to make the
* appointment panel scroll down next time pnoutrefresh is called.
*/
-void
-apoint_scroll_pad_down(int nb_events_inday, int win_length)
+void
+apoint_scroll_pad_down (int nb_events_inday, int win_length)
{
- int pad_last_line = 0;
- int item_first_line = 0, item_last_line = 0;
- int borders = 6;
- int awin_length = win_length - borders;
-
- item_first_line = get_item_line(hilt, nb_events_inday);
- if (hilt < nb_events_inday)
- item_last_line = item_first_line;
- else
- item_last_line = item_first_line + 1;
- pad_last_line = apad->first_onscreen + awin_length;
- if (item_last_line >= pad_last_line)
- apad->first_onscreen = item_last_line - awin_length;
+ int pad_last_line = 0;
+ int item_first_line = 0, item_last_line = 0;
+ int borders = 6;
+ int awin_length = win_length - borders;
+
+ item_first_line = get_item_line (hilt, nb_events_inday);
+ if (hilt < nb_events_inday)
+ item_last_line = item_first_line;
+ else
+ item_last_line = item_first_line + 1;
+ pad_last_line = apad->first_onscreen + awin_length;
+ if (item_last_line >= pad_last_line)
+ apad->first_onscreen = item_last_line - awin_length;
}
/*
* Update (if necessary) the first displayed pad line to make the
* appointment panel scroll up next time pnoutrefresh is called.
*/
-void
-apoint_scroll_pad_up(int nb_events_inday)
+void
+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);
- if (item_first_line < apad->first_onscreen)
- apad->first_onscreen = item_first_line;
+ item_first_line = get_item_line (hilt, nb_events_inday);
+ if (item_first_line < apad->first_onscreen)
+ apad->first_onscreen = item_first_line;
}
/*
@@ -482,27 +516,32 @@ apoint_scroll_pad_up(int nb_events_inday)
* stored in the notify_app structure (which is the next item to be notified).
*/
struct notify_app_s *
-apoint_check_next(struct notify_app_s *app, long start)
+apoint_check_next (struct notify_app_s *app, long start)
{
- apoint_llist_node_t *i;
-
- pthread_mutex_lock(&(alist_p->mutex));
- for (i = alist_p->root; i != 0; i = i->next) {
- if (i->start > app->time) {
- pthread_mutex_unlock(&(alist_p->mutex));
- return app;
- } else {
- if (i->start > start) {
- app->time = i->start;
- app->txt = mycpy(i->mesg);
- app->state = i->state;
- app->got_app = 1;
- }
- }
+ apoint_llist_node_t *i;
+
+ pthread_mutex_lock (&(alist_p->mutex));
+ for (i = alist_p->root; i != 0; i = i->next)
+ {
+ if (i->start > app->time)
+ {
+ pthread_mutex_unlock (&(alist_p->mutex));
+ return (app);
+ }
+ else
+ {
+ if (i->start > start)
+ {
+ app->time = i->start;
+ app->txt = mycpy (i->mesg);
+ app->state = i->state;
+ app->got_app = 1;
+ }
}
- pthread_mutex_unlock(&(alist_p->mutex));
+ }
+ pthread_mutex_unlock (&(alist_p->mutex));
- return app;
+ return (app);
}
/*
@@ -510,115 +549,120 @@ apoint_check_next(struct notify_app_s *app, long start)
* recur_apoint_s
*/
apoint_llist_node_t *
-apoint_recur_s2apoint_s(recur_apoint_llist_node_t *p)
+apoint_recur_s2apoint_s (recur_apoint_llist_node_t *p)
{
- apoint_llist_node_t *a;
-
- a = (apoint_llist_node_t *) malloc(sizeof(apoint_llist_node_t));
- a->mesg = (char *) malloc(strlen(p->mesg) + 1);
- a->start = p->start;
- a->dur = p->dur;
- a->mesg = p->mesg;
- return a;
+ apoint_llist_node_t *a;
+
+ a = (apoint_llist_node_t *) malloc (sizeof (apoint_llist_node_t));
+ a->mesg = (char *) malloc (strlen (p->mesg) + 1);
+ a->start = p->start;
+ a->dur = p->dur;
+ a->mesg = p->mesg;
+ return (a);
}
/*
* Switch notification state.
*/
void
-apoint_switch_notify(void)
+apoint_switch_notify (void)
{
- apoint_llist_node_t *apoint;
- struct day_item_s *p;
- long date;
- int apoint_nb = 0, n, need_chk_notify;
-
- p = day_get_item(hilt);
- if (p->type != APPT && p->type != RECUR_APPT)
- return;
-
- date = calendar_get_slctd_day_sec();
-
- if (p->type == RECUR_APPT) {
- recur_apoint_switch_notify(date, p->appt_pos);
- return;
- } else if (p->type == APPT)
- apoint_nb = day_item_nb(date, hilt, APPT);
-
- n = 0;
- need_chk_notify = 0;
- pthread_mutex_lock(&(alist_p->mutex));
-
- for (apoint = alist_p->root; apoint != 0; apoint = apoint->next) {
- if (apoint_inday(apoint, date)) {
- if (n == apoint_nb) {
- apoint->state ^= APOINT_NOTIFY;
-
- if (notify_bar())
- notify_check_added(apoint->mesg,
- apoint->start, apoint->state);
-
- pthread_mutex_unlock(&(alist_p->mutex));
- if (need_chk_notify)
- notify_check_next_app();
- return;
- }
- n++;
- }
+ apoint_llist_node_t *apoint;
+ struct day_item_s *p;
+ long date;
+ int apoint_nb = 0, n, need_chk_notify;
+
+ p = day_get_item (hilt);
+ if (p->type != APPT && p->type != RECUR_APPT)
+ return;
+
+ date = calendar_get_slctd_day_sec ();
+
+ if (p->type == RECUR_APPT)
+ {
+ recur_apoint_switch_notify (date, p->appt_pos);
+ return;
+ }
+ else if (p->type == APPT)
+ apoint_nb = day_item_nb (date, hilt, APPT);
+
+ n = 0;
+ need_chk_notify = 0;
+ pthread_mutex_lock (&(alist_p->mutex));
+
+ for (apoint = alist_p->root; apoint != 0; apoint = apoint->next)
+ {
+ if (apoint_inday (apoint, date))
+ {
+ if (n == apoint_nb)
+ {
+ apoint->state ^= APOINT_NOTIFY;
+ if (notify_bar ())
+ {
+ notify_check_added (apoint->mesg, apoint->start,
+ apoint->state);
+ }
+ pthread_mutex_unlock (&(alist_p->mutex));
+ if (need_chk_notify)
+ notify_check_next_app ();
+ return;
+ }
+ n++;
}
- pthread_mutex_unlock(&(alist_p->mutex));
+ }
+ pthread_mutex_unlock (&(alist_p->mutex));
- /* NOTREACHED */
- ierror(
- _("FATAL ERROR in apoint_switch_notify: no such appointment"),
- IERROR_FATAL);
+ /* NOTREACHED */
+ ierror (_("FATAL ERROR in apoint_switch_notify: no such appointment"),
+ IERROR_FATAL);
}
/* Updates the Appointment panel */
-void
-apoint_update_panel(window_t *winapp, int which_pan)
+void
+apoint_update_panel (window_t *winapp, int which_pan)
{
- int title_xpos;
- int bordr = 1;
- int title_lines = 3;
- int app_width = winapp->w - bordr;
- int app_length = winapp->h - bordr - title_lines;
- long date;
- date_t slctd_date;
-
- /* variable inits */
- slctd_date = *calendar_get_slctd_day();
- title_xpos = winapp->w - (strlen(_(monthnames[slctd_date.mm - 1])) + 16);
- if (slctd_date.dd < 10)
- title_xpos++;
- date = date2sec(slctd_date, 0, 0);
- day_write_pad(date, app_width, app_length, hilt);
-
- /* Print current date in the top right window corner. */
- erase_window_part(win[APP].p, 1, title_lines, winapp->w - 2,
- winapp->h - 2);
- custom_apply_attr(win[APP].p, ATTR_HIGHEST);
- mvwprintw(win[APP].p, title_lines, title_xpos, "%s %s %d, %d",
- calendar_get_pom(date), _(monthnames[slctd_date.mm - 1]),
- slctd_date.dd, slctd_date.yyyy);
- custom_remove_attr(win[APP].p, ATTR_HIGHEST);
-
- /* Draw the scrollbar if necessary. */
- if ((apad->length >= app_length)||(apad->first_onscreen > 0)) {
- float ratio = ((float) app_length) / ((float) apad->length);
- int sbar_length = (int) (ratio * app_length);
- int highend = (int) (ratio * apad->first_onscreen);
- bool hilt_bar = (which_pan == APP) ? true : false;
- int sbar_top = highend + title_lines + 1;
-
- if ((sbar_top + sbar_length) > winapp->h - 1)
- sbar_length = winapp->h - 1 - sbar_top;
- draw_scrollbar(win[APP].p, sbar_top, winapp->w - 2, sbar_length,
- title_lines + 1, winapp->h - 1, hilt_bar);
- }
-
- wnoutrefresh(win[APP].p);
- pnoutrefresh(apad->ptrwin, apad->first_onscreen, 0,
- winapp->y + title_lines + 1, winapp->x + bordr,
- winapp->y + winapp->h - 2*bordr, winapp->x + winapp->w - 3*bordr);
+ int title_xpos;
+ int bordr = 1;
+ int title_lines = 3;
+ int app_width = winapp->w - bordr;
+ int app_length = winapp->h - bordr - title_lines;
+ long date;
+ date_t slctd_date;
+
+ /* variable inits */
+ slctd_date = *calendar_get_slctd_day ();
+ title_xpos = winapp->w - (strlen (_(monthnames[slctd_date.mm - 1])) + 16);
+ if (slctd_date.dd < 10)
+ title_xpos++;
+ date = date2sec (slctd_date, 0, 0);
+ day_write_pad (date, app_width, app_length, hilt);
+
+ /* Print current date in the top right window corner. */
+ erase_window_part (win[APP].p, 1, title_lines, winapp->w - 2, winapp->h - 2);
+ custom_apply_attr (win[APP].p, ATTR_HIGHEST);
+ mvwprintw (win[APP].p, title_lines, title_xpos, "%s %s %d, %d",
+ calendar_get_pom (date), _(monthnames[slctd_date.mm - 1]),
+ slctd_date.dd, slctd_date.yyyy);
+ custom_remove_attr (win[APP].p, ATTR_HIGHEST);
+
+ /* Draw the scrollbar if necessary. */
+ if ((apad->length >= app_length) || (apad->first_onscreen > 0))
+ {
+ float ratio = ((float) app_length) / ((float) apad->length);
+ int sbar_length = (int) (ratio * app_length);
+ int highend = (int) (ratio * apad->first_onscreen);
+ bool hilt_bar = (which_pan == APP) ? true : false;
+ int sbar_top = highend + title_lines + 1;
+
+ if ((sbar_top + sbar_length) > winapp->h - 1)
+ sbar_length = winapp->h - 1 - sbar_top;
+ draw_scrollbar (win[APP].p, sbar_top, winapp->w - 2, sbar_length,
+ title_lines + 1, winapp->h - 1, hilt_bar);
+ }
+
+ wnoutrefresh (win[APP].p);
+ pnoutrefresh (apad->ptrwin, apad->first_onscreen, 0,
+ winapp->y + title_lines + 1, winapp->x + bordr,
+ winapp->y + winapp->h - 2 * bordr,
+ winapp->x + winapp->w - 3 * bordr);
}
diff --git a/src/apoint.h b/src/apoint.h
index 9c1e7ef..ef09684 100755
--- a/src/apoint.h
+++ b/src/apoint.h
@@ -1,4 +1,4 @@
-/* $calcurse: apoint.h,v 1.12 2008/01/20 10:45:38 culot Exp $ */
+/* $calcurse: apoint.h,v 1.13 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -39,42 +39,46 @@
#define APOINT_NOTIFY 0x1 /* Item needs to be notified */
#define APOINT_NOTIFIED 0x2 /* Item was already notified */
-typedef struct apoint_llist_node {
- struct apoint_llist_node *next;
- long start; /* seconds since 1 jan 1970 */
- long dur; /* duration of the appointment in seconds */
- char state; /* 8 bits to store item state */
- char *mesg;
- char *note;
-} apoint_llist_node_t;
+typedef struct apoint_llist_node
+{
+ struct apoint_llist_node *next;
+ long start; /* seconds since 1 jan 1970 */
+ long dur; /* duration of the appointment in seconds */
+ char state; /* 8 bits to store item state */
+ char *mesg;
+ char *note;
+}
+apoint_llist_node_t;
-typedef struct apoint_llist {
- apoint_llist_node_t *root;
- pthread_mutex_t mutex;
-} apoint_llist_t;
+typedef struct apoint_llist
+{
+ apoint_llist_node_t *root;
+ pthread_mutex_t mutex;
+}
+apoint_llist_t;
extern apoint_llist_t *alist_p;
-int apoint_llist_init(void);
-void apoint_hilt_set(int);
-void apoint_hilt_decrease(void);
-void apoint_hilt_increase(void);
-int apoint_hilt(void);
-apoint_llist_node_t *apoint_new(char *, char *, long, long, char);
-void apoint_add(void);
-void apoint_delete(conf_t *, unsigned *, unsigned *);
-unsigned apoint_inday(apoint_llist_node_t *, long);
-void apoint_sec2str(apoint_llist_node_t *, int, long,
- char *, char *);
-void apoint_write(apoint_llist_node_t *, FILE *);
-apoint_llist_node_t *apoint_scan(FILE *, struct tm, struct tm, char, char *);
-apoint_llist_node_t *apoint_get(long, int);
-void apoint_delete_bynum(long, unsigned, erase_flag_e);
-void apoint_scroll_pad_down(int, int);
-void apoint_scroll_pad_up(int);
-struct notify_app_s *apoint_check_next(struct notify_app_s *, long);
-apoint_llist_node_t *apoint_recur_s2apoint_s(recur_apoint_llist_node_t *);
-void apoint_switch_notify(void);
-void apoint_update_panel(window_t *, int);
+int apoint_llist_init (void);
+void apoint_hilt_set (int);
+void apoint_hilt_decrease (void);
+void apoint_hilt_increase (void);
+int apoint_hilt (void);
+apoint_llist_node_t *apoint_new (char *, char *, long, long, char);
+void apoint_add (void);
+void apoint_delete (conf_t *, unsigned *, unsigned *);
+unsigned apoint_inday (apoint_llist_node_t *, long);
+void apoint_sec2str (apoint_llist_node_t *, int, long, char *,
+ char *);
+void apoint_write (apoint_llist_node_t *, FILE *);
+apoint_llist_node_t *apoint_scan (FILE *, struct tm, struct tm, char, char *);
+apoint_llist_node_t *apoint_get (long, int);
+void apoint_delete_bynum (long, unsigned, erase_flag_e);
+void apoint_scroll_pad_down (int, int);
+void apoint_scroll_pad_up (int);
+struct notify_app_s *apoint_check_next (struct notify_app_s *, long);
+apoint_llist_node_t *apoint_recur_s2apoint_s (recur_apoint_llist_node_t *);
+void apoint_switch_notify (void);
+void apoint_update_panel (window_t *, int);
#endif /* CALCURSE_APOINT_H */
diff --git a/src/args.c b/src/args.c
index 5701a09..bd42458 100755
--- a/src/args.c
+++ b/src/args.c
@@ -1,4 +1,4 @@
-/* $calcurse: args.c,v 1.31 2008/04/09 20:38:29 culot Exp $ */
+/* $calcurse: args.c,v 1.32 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -44,88 +44,84 @@
/*
* Print Calcurse usage and exit.
*/
-static void
-usage()
+static void
+usage ()
{
- char *arg_usage =
- _("Usage: calcurse [-h|-v] [-x] [-N] [-an] [-t[num]] [-d date|num] [-c file]\n");
-
- fputs(arg_usage, stdout);
+ char *arg_usage =
+ _("Usage: calcurse [-h|-v] [-x] [-N] [-an] [-t[num]] [-d date|num] "
+ "[-c file]\n");
+ fputs (arg_usage, stdout);
}
-static void
-usage_try()
+static void
+usage_try ()
{
- char *arg_usage_try =
- _("Try 'calcurse -h' for more information.\n");
-
- fputs(arg_usage_try, stdout);
+ char *arg_usage_try = _("Try 'calcurse -h' for more information.\n");
+ fputs (arg_usage_try, stdout);
}
/*
* Print Calcurse version with a short copyright text and exit.
*/
-static void
-version_arg()
+static void
+version_arg ()
{
- char vtitle[BUFSIZ];
- char *vtext =
- _("\nCopyright (c) 2004-2007 Frederic Culot.\n"
- "This is free software; see the source for copying conditions.\n");
-
- snprintf(vtitle, BUFSIZ,
- _("Calcurse %s - text-based organizer\n"), VERSION);
- fputs(vtitle, stdout);
- fputs(vtext, stdout);
+ char vtitle[BUFSIZ];
+ char *vtext =
+ _("\nCopyright (c) 2004-2008 Frederic Culot.\n"
+ "This is free software; see the source for copying conditions.\n");
+
+ snprintf (vtitle, BUFSIZ, _("Calcurse %s - text-based organizer\n"), VERSION);
+ fputs (vtitle, stdout);
+ fputs (vtext, stdout);
}
/*
* Print the command line options and exit.
*/
-static void
-help_arg()
+static void
+help_arg ()
{
- char htitle[BUFSIZ];
- char *htext =
- _("\nMiscellaneous:\n"
- " -h, --help\n"
- " print this help and exit.\n"
- "\n -v, --version\n"
- " print calcurse version and exit.\n"
- "\nFiles:\n"
- " -c <file>, --calendar <file>\n"
- " specify the calendar <file> to use.\n"
- "\nNon-interactive:\n"
- " -a, --appointment\n"
- " print events and appointments for current day and exit.\n"
- "\n -d <date|num>, --day <date|num>\n"
- " print events and appointments for <date> or <num> upcoming days and"
- "\n\texit. Possible formats are: 'mm/dd/yyyy' or 'n'.\n"
- "\n -n, --next\n"
- " print next appointment within upcoming 24 hours "
- "and exit. Also given\n\tis the remaining time before this "
- "next appointment.\n"
- "\n -N, --note\n"
- " when used with the '-a' or '-t' flag, also print note content\n"
- " if one is associated with the displayed item.\n"
- "\n -t[num], --todo[=num]\n"
- " print todo list and exit. If the optional number [num] is given,\n"
- "\tthen only todos having a priority equal to [num] will be returned.\n"
- "\tnote: priority number must be between 1 (highest) and 9 (lowest).\n"
- "\n -x, --export\n"
- " export user data to iCalendar format. Events, appointments and\n"
- "\ttodos are converted and echoed to stdout.\n"
- "\tnote: redirect standard output to export data to a file,\n"
- "\tby issuing a command such as: calcurse --export > my_data.ics\n"
- "\nFor more information, type '?' from within Calcurse, "
- "or read the manpage.\n"
- "Mail bug reports and suggestions to <calcurse@culot.org>.\n");
-
- snprintf(htitle, BUFSIZ,
- _("Calcurse %s - text-based organizer\n"), VERSION);
- fputs(htitle, stdout);
- usage();
- fputs(htext, stdout);
+ char htitle[BUFSIZ];
+ char *htext =
+ _("\nMiscellaneous:\n"
+ " -h, --help\n"
+ " print this help and exit.\n"
+ "\n -v, --version\n"
+ " print calcurse version and exit.\n"
+ "\nFiles:\n"
+ " -c <file>, --calendar <file>\n"
+ " specify the calendar <file> to use.\n"
+ "\nNon-interactive:\n"
+ " -a, --appointment\n"
+ " print events and appointments for current day and exit.\n"
+ "\n -d <date|num>, --day <date|num>\n"
+ " print events and appointments for <date> or <num> upcoming days and"
+ "\n\texit. Possible formats are: 'mm/dd/yyyy' or 'n'.\n"
+ "\n -n, --next\n"
+ " print next appointment within upcoming 24 hours "
+ "and exit. Also given\n\tis the remaining time before this "
+ "next appointment.\n"
+ "\n -N, --note\n"
+ " when used with the '-a' or '-t' flag, also print note content\n"
+ " if one is associated with the displayed item.\n"
+ "\n -t[num], --todo[=num]\n"
+ " print todo list and exit. If the optional number [num] is given,\n"
+ "\tthen only todos having a priority equal to [num] will be returned.\n"
+ "\tnote: priority number must be between 1 (highest) and 9 (lowest).\n"
+ "\n -x, --export\n"
+ " export user data to iCalendar format. Events, appointments and\n"
+ "\ttodos are converted and echoed to stdout.\n"
+ "\tnote: redirect standard output to export data to a file,\n"
+ "\tby issuing a command such as: calcurse --export > my_data.ics\n"
+ "\nFor more information, type '?' from within Calcurse, "
+ "or read the manpage.\n"
+ "Mail bug reports and suggestions to <calcurse@culot.org>.\n");
+
+ snprintf (htitle, BUFSIZ, _("Calcurse %s - text-based organizer\n"), VERSION);
+ fputs (htitle, stdout);
+ usage ();
+ fputs (htext, stdout);
}
/*
@@ -136,111 +132,119 @@ help_arg()
*
* (patch submitted by Erik Saule).
*/
-static void
-print_notefile(FILE *out, char *filename, int nbtab)
+static void
+print_notefile (FILE *out, char *filename, int nbtab)
{
- char path_to_notefile[BUFSIZ];
- FILE *notefile;
- char linestarter[BUFSIZ] = "";
- char buffer[BUFSIZ];
- int i;
- int printlinestarter = 1;
-
- for (i = 0; i < nbtab; i++)
- strcat(linestarter, "\t");
-
- snprintf(path_to_notefile, BUFSIZ, "%s/%s", path_notes, filename);
- notefile = fopen(path_to_notefile, "r");
- if (notefile) {
- while (fgets(buffer, BUFSIZ, notefile) != NULL) {
- if (printlinestarter) {
- fputs(linestarter,out);
- printlinestarter = 0;
- }
- fputs(buffer, out);
- if (buffer[strlen(buffer) - 1] == '\n')
- printlinestarter = 1;
- }
- fputs("\n", out);
- fclose(notefile);
- } else {
- fputs(linestarter, out);
- fputs(_("No note file found\n"), out);
+ char path_to_notefile[BUFSIZ];
+ FILE *notefile;
+ char linestarter[BUFSIZ] = "";
+ char buffer[BUFSIZ];
+ int i;
+ int printlinestarter = 1;
+
+ for (i = 0; i < nbtab; i++)
+ strcat (linestarter, "\t");
+
+ snprintf (path_to_notefile, BUFSIZ, "%s/%s", path_notes, filename);
+ notefile = fopen (path_to_notefile, "r");
+ if (notefile)
+ {
+ while (fgets (buffer, BUFSIZ, notefile) != NULL)
+ {
+ if (printlinestarter)
+ {
+ fputs (linestarter, out);
+ printlinestarter = 0;
+ }
+ fputs (buffer, out);
+ if (buffer[strlen (buffer) - 1] == '\n')
+ printlinestarter = 1;
}
+ fputs ("\n", out);
+ fclose (notefile);
+ }
+ else
+ {
+ fputs (linestarter, out);
+ fputs (_("No note file found\n"), out);
+ }
}
/*
* Print todo list and exit. If a priority number is given (say not equal to
* zero), then only todo items that have this priority will be displayed.
*/
-static void
-todo_arg(int priority, int print_note)
+static void
+todo_arg (int priority, int print_note)
{
- struct todo_s *i;
- int title = 1;
- char priority_str[BUFSIZ] = "";
-
- io_load_todo();
- for (i = todolist; i != 0; i = i->next) {
- if (priority == 0 || i->id == priority) {
- if (title) {
- fputs(_("to do:\n"),stdout);
- title = 0;
- }
- snprintf(priority_str, BUFSIZ, "%d. ", i->id);
- fputs(priority_str, stdout);
- fputs(i->mesg, stdout);
- fputs("\n", stdout);
- if (print_note && i->note)
- print_notefile(stdout, i->note, 1);
- }
+ struct todo_s *i;
+ int title = 1;
+ char priority_str[BUFSIZ] = "";
+
+ io_load_todo ();
+ for (i = todolist; i != 0; i = i->next)
+ {
+ if (priority == 0 || i->id == priority)
+ {
+ if (title)
+ {
+ fputs (_("to do:\n"), stdout);
+ title = 0;
+ }
+ snprintf (priority_str, BUFSIZ, "%d. ", i->id);
+ fputs (priority_str, stdout);
+ fputs (i->mesg, stdout);
+ fputs ("\n", stdout);
+ if (print_note && i->note)
+ print_notefile (stdout, i->note, 1);
}
+ }
}
/* Print the next appointment within the upcoming 24 hours. */
-static void
-next_arg(void)
+static void
+next_arg (void)
{
- struct notify_app_s next_app;
- const long current_time = now();
- int time_left, hours_left, min_left;
- char mesg[BUFSIZ];
-
- next_app.time = current_time + DAYINSEC;
- next_app.got_app = 0;
- next_app.txt = NULL;
-
- next_app = *recur_apoint_check_next(&next_app, current_time,
- get_today());
- next_app = *apoint_check_next(&next_app, current_time);
-
- if (next_app.got_app) {
- time_left = next_app.time - current_time;
- hours_left = (time_left / HOURINSEC);
- min_left = (time_left - hours_left * HOURINSEC) / MININSEC;
- fputs(_("next appointment:\n"), stdout);
- snprintf(mesg, BUFSIZ, " [%02d:%02d] %s\n",
- hours_left, min_left, next_app.txt);
- fputs(mesg, stdout);
- free(next_app.txt);
- }
+ struct notify_app_s next_app;
+ const long current_time = now ();
+ int time_left, hours_left, min_left;
+ char mesg[BUFSIZ];
+
+ next_app.time = current_time + DAYINSEC;
+ next_app.got_app = 0;
+ next_app.txt = NULL;
+
+ next_app = *recur_apoint_check_next (&next_app, current_time, get_today ());
+ next_app = *apoint_check_next (&next_app, current_time);
+
+ if (next_app.got_app)
+ {
+ time_left = next_app.time - current_time;
+ hours_left = (time_left / HOURINSEC);
+ min_left = (time_left - hours_left * HOURINSEC) / MININSEC;
+ fputs (_("next appointment:\n"), stdout);
+ snprintf (mesg, BUFSIZ, " [%02d:%02d] %s\n", hours_left, min_left,
+ next_app.txt);
+ fputs (mesg, stdout);
+ free (next_app.txt);
+ }
}
/*
* Print the date on stdout.
*/
-static void
-arg_print_date(long date, conf_t *conf)
+static void
+arg_print_date (long date, conf_t *conf)
{
- char date_str[BUFSIZ];
- time_t t;
- struct tm *lt;
-
- t = date;
- lt = localtime(&t);
- strftime(date_str, BUFSIZ, conf->output_datefmt, lt);
- fputs(date_str,stdout);
- fputs(":\n",stdout);
+ char date_str[BUFSIZ];
+ time_t t;
+ struct tm *lt;
+
+ t = date;
+ lt = localtime (&t);
+ strftime (date_str, BUFSIZ, conf->output_datefmt, lt);
+ fputs (date_str, stdout);
+ fputs (":\n", stdout);
}
/*
@@ -248,351 +252,398 @@ arg_print_date(long date, conf_t *conf)
* If no day is given, the given date is used.
* If there is also no date given, current date is considered.
*/
-static int
-app_arg(int add_line, date_t *day, long date, int print_note, conf_t *conf)
+static int
+app_arg (int add_line, date_t *day, long date, int print_note, conf_t *conf)
{
- struct recur_event_s *re;
- struct event_s *j;
- recur_apoint_llist_node_t *ra;
- apoint_llist_node_t *i;
- long today;
- bool print_date = true;
- int app_found = 0;
- char apoint_start_time[100];
- char apoint_end_time[100];
-
- if (date == 0)
- today = get_sec_date(*day);
- else
- today = date;
-
- /*
- * Calculate and print the selected date if there is an event for
- * that date and it is the first one, and then print all the events for
- * that date.
- */
- for (re = recur_elist; re != 0; re = re->next) {
- if (recur_item_inday(re->day, re->exc, re->rpt->type,
- re->rpt->freq, re->rpt->until, today)) {
- app_found = 1;
- if (add_line) {
- fputs("\n", stdout);
- add_line = 0;
- }
- if (print_date) {
- arg_print_date(today, conf);
- print_date = false;
- }
- fputs(" * ", stdout);
- fputs(re->mesg, stdout); fputs("\n", stdout);
- if (print_note && re->note)
- print_notefile(stdout, re->note, 2);
- }
+ struct recur_event_s *re;
+ struct event_s *j;
+ recur_apoint_llist_node_t *ra;
+ apoint_llist_node_t *i;
+ long today;
+ bool print_date = true;
+ int app_found = 0;
+ char apoint_start_time[100];
+ char apoint_end_time[100];
+
+ if (date == 0)
+ today = get_sec_date (*day);
+ else
+ today = date;
+
+ /*
+ * Calculate and print the selected date if there is an event for
+ * that date and it is the first one, and then print all the events for
+ * that date.
+ */
+ for (re = recur_elist; re != 0; re = re->next)
+ {
+ if (recur_item_inday (re->day, re->exc, re->rpt->type, re->rpt->freq,
+ re->rpt->until, today))
+ {
+ app_found = 1;
+ if (add_line)
+ {
+ fputs ("\n", stdout);
+ add_line = 0;
+ }
+ if (print_date)
+ {
+ arg_print_date (today, conf);
+ print_date = false;
+ }
+ fputs (" * ", stdout);
+ fputs (re->mesg, stdout);
+ fputs ("\n", stdout);
+ if (print_note && re->note)
+ print_notefile (stdout, re->note, 2);
}
-
- for (j = eventlist; j != 0; j = j->next) {
- if (event_inday(j, today)) {
- app_found = 1;
- if (add_line) {
- fputs("\n",stdout);
- add_line = 0;
- }
- if (print_date) {
- arg_print_date(today, conf);
- print_date = false;
- }
- fputs(" * ", stdout);
- fputs(j->mesg, stdout);
- fputs("\n", stdout);
- if (print_note && j->note)
- print_notefile(stdout, j->note, 2);
- }
+ }
+
+ for (j = eventlist; j != 0; j = j->next)
+ {
+ if (event_inday (j, today))
+ {
+ app_found = 1;
+ if (add_line)
+ {
+ fputs ("\n", stdout);
+ add_line = 0;
+ }
+ if (print_date)
+ {
+ arg_print_date (today, conf);
+ print_date = false;
+ }
+ fputs (" * ", stdout);
+ fputs (j->mesg, stdout);
+ fputs ("\n", stdout);
+ if (print_note && j->note)
+ print_notefile (stdout, j->note, 2);
}
-
- /* Same process is performed but this time on the appointments. */
- pthread_mutex_lock(&(recur_alist_p->mutex));
- for (ra = recur_alist_p->root; ra != 0; ra = ra->next) {
- if (recur_item_inday(ra->start, ra->exc, ra->rpt->type,
- ra->rpt->freq, ra->rpt->until, today)) {
- app_found = 1;
- if (add_line) {
- fputs("\n",stdout);
- add_line = 0;
- }
- if (print_date) {
- arg_print_date(today, conf);
- print_date = false;
- }
- apoint_sec2str(apoint_recur_s2apoint_s(ra),
- RECUR_APPT, today, apoint_start_time,
- apoint_end_time);
- fputs(" - ", stdout);
- fputs(apoint_start_time, stdout);
- fputs(" -> ", stdout);
- fputs(apoint_end_time, stdout);
- fputs("\n\t", stdout);
- fputs(ra->mesg, stdout);
- fputs("\n", stdout);
- if (print_note && ra->note)
- print_notefile(stdout, ra->note, 2);
- }
+ }
+
+ /* Same process is performed but this time on the appointments. */
+ pthread_mutex_lock (&(recur_alist_p->mutex));
+ for (ra = recur_alist_p->root; ra != 0; ra = ra->next)
+ {
+ if (recur_item_inday (ra->start, ra->exc, ra->rpt->type, ra->rpt->freq,
+ ra->rpt->until, today))
+ {
+ app_found = 1;
+ if (add_line)
+ {
+ fputs ("\n", stdout);
+ add_line = 0;
+ }
+ if (print_date)
+ {
+ arg_print_date (today, conf);
+ print_date = false;
+ }
+ apoint_sec2str (apoint_recur_s2apoint_s (ra), RECUR_APPT, today,
+ apoint_start_time, apoint_end_time);
+ fputs (" - ", stdout);
+ fputs (apoint_start_time, stdout);
+ fputs (" -> ", stdout);
+ fputs (apoint_end_time, stdout);
+ fputs ("\n\t", stdout);
+ fputs (ra->mesg, stdout);
+ fputs ("\n", stdout);
+ if (print_note && ra->note)
+ print_notefile (stdout, ra->note, 2);
}
- pthread_mutex_unlock(&(recur_alist_p->mutex));
-
- pthread_mutex_lock(&(alist_p->mutex));
- for (i = alist_p->root; i != 0; i = i->next) {
- if (apoint_inday(i, today)) {
- app_found = 1;
- if (add_line) {
- fputs("\n",stdout);
- add_line = 0;
- }
- if (print_date) {
- arg_print_date(today, conf);
- print_date = false;
- }
- apoint_sec2str(i, APPT, today, apoint_start_time,
- apoint_end_time);
- fputs(" - ", stdout);
- fputs(apoint_start_time, stdout);
- fputs(" -> ", stdout);
- fputs(apoint_end_time, stdout);
- fputs("\n\t", stdout);
- fputs(i->mesg, stdout);
- fputs("\n", stdout);
- if (print_note && i->note)
- print_notefile(stdout, i->note, 2);
- }
+ }
+ pthread_mutex_unlock (&(recur_alist_p->mutex));
+
+ pthread_mutex_lock (&(alist_p->mutex));
+ for (i = alist_p->root; i != 0; i = i->next)
+ {
+ if (apoint_inday (i, today))
+ {
+ app_found = 1;
+ if (add_line)
+ {
+ fputs ("\n", stdout);
+ add_line = 0;
+ }
+ if (print_date)
+ {
+ arg_print_date (today, conf);
+ print_date = false;
+ }
+ apoint_sec2str (i, APPT, today, apoint_start_time, apoint_end_time);
+ fputs (" - ", stdout);
+ fputs (apoint_start_time, stdout);
+ fputs (" -> ", stdout);
+ fputs (apoint_end_time, stdout);
+ fputs ("\n\t", stdout);
+ fputs (i->mesg, stdout);
+ fputs ("\n", stdout);
+ if (print_note && i->note)
+ print_notefile (stdout, i->note, 2);
}
- pthread_mutex_unlock(&(alist_p->mutex));
+ }
+ pthread_mutex_unlock (&(alist_p->mutex));
- return app_found;
+ return (app_found);
}
/*
* Print appointment for the given date or for the given n upcoming
* days.
*/
-static void
-date_arg(char *ddate, int add_line, int print_note, conf_t *conf)
+static void
+date_arg (char *ddate, int add_line, int print_note, conf_t *conf)
{
- int i;
- date_t day;
- int numdays = 0, num_digit = 0;
- int arg_len = 0, app_found = 0;
- static struct tm t;
- time_t timer;
-
- /*
- * Check (with the argument length) if a date or a number of days
- * was entered, and then call app_arg() to print appointments
- */
- arg_len = strlen(ddate);
- if (arg_len <= 4) { /* a number of days was entered */
- for (i = 0; i <= arg_len-1; i++) {
- if (isdigit(ddate[i]))
- num_digit++;
- }
- if (num_digit == arg_len)
- numdays = atoi(ddate);
-
- /*
- * Get current date, and print appointments for each day
- * in the chosen interval. app_found and add_line are used
- * to format the output correctly.
- */
- timer = time(NULL);
- t = *localtime(&timer);
-
- for (i = 0; i < numdays; i++) {
- day.dd = t.tm_mday;
- day.mm = t.tm_mon + 1;
- day.yyyy = t.tm_year + 1900;
- app_found = app_arg(add_line, &day, 0, print_note, conf);
- if (app_found)
- add_line = 1;
- t.tm_mday++;
- mktime(&t);
- }
- } else { /* a date was entered */
- if (parse_date(ddate, conf->input_datefmt,
- &day.yyyy, &day.mm, &day.dd)) {
- app_found = app_arg(add_line, &day, 0, print_note, conf);
- } else {
- fputs(_("Argument to the '-d' flag is not valid\n"),
- stdout);
- char outstr[BUFSIZ];
- snprintf(outstr, BUFSIZ, "Possible argument format are: '%s' or 'n'\n",
- DATEFMT_DESC(conf->input_datefmt));
- fputs(_(outstr), stdout);
- fputs(_("\nFor more information, type '?' from within Calcurse, or read the manpage.\n"),
- stdout);
- fputs
- (_("Mail bug reports and suggestions to <calcurse@culot.org>.\n"),
- stdout);
- }
+ int i;
+ date_t day;
+ int numdays = 0, num_digit = 0;
+ int arg_len = 0, app_found = 0;
+ static struct tm t;
+ time_t timer;
+
+ /*
+ * Check (with the argument length) if a date or a number of days
+ * was entered, and then call app_arg() to print appointments
+ */
+ arg_len = strlen (ddate);
+ if (arg_len <= 4)
+ { /* a number of days was entered */
+ for (i = 0; i <= arg_len - 1; i++)
+ {
+ if (isdigit (ddate[i]))
+ num_digit++;
+ }
+ if (num_digit == arg_len)
+ numdays = atoi (ddate);
+
+ /*
+ * Get current date, and print appointments for each day
+ * in the chosen interval. app_found and add_line are used
+ * to format the output correctly.
+ */
+ timer = time (NULL);
+ t = *localtime (&timer);
+
+ for (i = 0; i < numdays; i++)
+ {
+ day.dd = t.tm_mday;
+ day.mm = t.tm_mon + 1;
+ day.yyyy = t.tm_year + 1900;
+ app_found = app_arg (add_line, &day, 0, print_note, conf);
+ if (app_found)
+ add_line = 1;
+ t.tm_mday++;
+ mktime (&t);
+ }
+ }
+ else
+ { /* a date was entered */
+ if (parse_date (ddate, conf->input_datefmt, &day.yyyy, &day.mm, &day.dd))
+ {
+ app_found = app_arg (add_line, &day, 0, print_note, conf);
}
+ else
+ {
+ fputs (_("Argument to the '-d' flag is not valid\n"), stdout);
+ char outstr[BUFSIZ];
+ snprintf (outstr, BUFSIZ,
+ "Possible argument format are: '%s' or 'n'\n",
+ DATEFMT_DESC (conf->input_datefmt));
+ fputs (_(outstr), stdout);
+ fputs (_("\nFor more information, type '?' from within Calcurse, "
+ "or read the manpage.\n"),
+ stdout);
+ fputs (_("Mail bug reports and suggestions to "
+ "<calcurse@culot.org>.\n"), stdout);
+ }
+ }
}
/*
* Parse the command-line arguments and call the appropriate
* routines to handle those arguments. Also initialize the data paths.
*/
-int
-parse_args(int argc, char **argv, conf_t *conf)
+int
+parse_args (int argc, char **argv, conf_t *conf)
{
- int ch, add_line = 0;
- int unknown_flag = 0, app_found = 0;
- /* Command-line flags */
- int aflag = 0; /* -a: print appointments for current day */
- int cflag = 0; /* -c: specify the calendar file to use */
- int dflag = 0; /* -d: print appointments for a specified days */
- int hflag = 0; /* -h: print help text */
- int nflag = 0; /* -n: print next appointment */
- int Nflag = 0; /* -N: also print note content with apps and todos */
- int tflag = 0; /* -t: print todo list */
- int vflag = 0; /* -v: print version number */
- int xflag = 0; /* -x: export data to iCalendar format */
-
- int tnum = 0;
- int non_interactive = 0, multiple_flag = 0, load_data = 0;
- int no_file = 1;
- char *ddate = "", *cfile = NULL;
-
- static char *optstr = "hvnNaxt::d:c:";
-
- struct option longopts[] = {
- {"appointment", no_argument, NULL, 'a'},
- {"calendar", required_argument, NULL, 'c'},
- {"day", required_argument, NULL, 'd'},
- {"help", no_argument, NULL, 'h'},
- {"next", no_argument, NULL, 'n'},
- {"note", no_argument, NULL, 'N'},
- {"todo", optional_argument, NULL, 't'},
- {"version", no_argument, NULL, 'v'},
- {"export", no_argument, NULL, 'x'},
- {NULL, no_argument, NULL, 0}
- };
-
- while ((ch = getopt_long(argc, argv, optstr, longopts, NULL)) != -1) {
- switch (ch) {
- case 'a':
- aflag = 1;
- multiple_flag++;
- load_data++;
- break;
- case 'c':
- cflag = 1;
- multiple_flag++;
- load_data++;
- cfile = optarg;
- break;
- case 'd':
- dflag = 1;
- multiple_flag++;
- load_data++;
- ddate = optarg;
- break;
- case 'h':
- hflag = 1;
- break;
- case 'n':
- nflag = 1;
- multiple_flag++;
- load_data++;
- break;
- case 'N':
- Nflag = 1;
- break;
- case 't':
- tflag = 1;
- multiple_flag++;
- load_data++;
- add_line = 1;
- if (optarg != NULL) {
- tnum = atoi(optarg);
- if (tnum < 1 || tnum > 9) {
- usage();
- usage_try();
- return EXIT_FAILURE;
- }
- } else
- tnum = 0;
- break;
- case 'v':
- vflag = 1;
- break;
- case 'x':
- xflag = 1;
- multiple_flag++;
- load_data++;
- break;
- default:
- usage();
- usage_try();
- unknown_flag = 1;
- non_interactive = 1;
- /* NOTREACHED */
+ int ch, add_line = 0;
+ int unknown_flag = 0, app_found = 0;
+ /* Command-line flags */
+ int aflag = 0; /* -a: print appointments for current day */
+ int cflag = 0; /* -c: specify the calendar file to use */
+ int dflag = 0; /* -d: print appointments for a specified days */
+ int hflag = 0; /* -h: print help text */
+ int nflag = 0; /* -n: print next appointment */
+ int Nflag = 0; /* -N: also print note content with apps and todos */
+ int tflag = 0; /* -t: print todo list */
+ int vflag = 0; /* -v: print version number */
+ int xflag = 0; /* -x: export data to iCalendar format */
+
+ int tnum = 0;
+ int non_interactive = 0, multiple_flag = 0, load_data = 0;
+ int no_file = 1;
+ char *ddate = "", *cfile = NULL;
+
+ static char *optstr = "hvnNaxt::d:c:";
+
+ struct option longopts[] = {
+ {"appointment", no_argument, NULL, 'a'},
+ {"calendar", required_argument, NULL, 'c'},
+ {"day", required_argument, NULL, 'd'},
+ {"help", no_argument, NULL, 'h'},
+ {"next", no_argument, NULL, 'n'},
+ {"note", no_argument, NULL, 'N'},
+ {"todo", optional_argument, NULL, 't'},
+ {"version", no_argument, NULL, 'v'},
+ {"export", no_argument, NULL, 'x'},
+ {NULL, no_argument, NULL, 0}
+ };
+
+ while ((ch = getopt_long (argc, argv, optstr, longopts, NULL)) != -1)
+ {
+ switch (ch)
+ {
+ case 'a':
+ aflag = 1;
+ multiple_flag++;
+ load_data++;
+ break;
+ case 'c':
+ cflag = 1;
+ multiple_flag++;
+ load_data++;
+ cfile = optarg;
+ break;
+ case 'd':
+ dflag = 1;
+ multiple_flag++;
+ load_data++;
+ ddate = optarg;
+ break;
+ case 'h':
+ hflag = 1;
+ break;
+ case 'n':
+ nflag = 1;
+ multiple_flag++;
+ load_data++;
+ break;
+ case 'N':
+ Nflag = 1;
+ break;
+ case 't':
+ tflag = 1;
+ multiple_flag++;
+ load_data++;
+ add_line = 1;
+ if (optarg != NULL)
+ {
+ tnum = atoi (optarg);
+ if (tnum < 1 || tnum > 9)
+ {
+ usage ();
+ usage_try ();
+ return (EXIT_FAILURE);
}
+ }
+ else
+ tnum = 0;
+ break;
+ case 'v':
+ vflag = 1;
+ break;
+ case 'x':
+ xflag = 1;
+ multiple_flag++;
+ load_data++;
+ break;
+ default:
+ usage ();
+ usage_try ();
+ unknown_flag = 1;
+ non_interactive = 1;
+ /* NOTREACHED */
}
- argc -= optind;
- argv += optind;
-
- if (argc >= 1) { /* incorrect arguments */
- usage();
- usage_try();
- return EXIT_FAILURE;
- } else {
- if (unknown_flag) {
- non_interactive = 1;
- } else if (hflag) {
- help_arg();
- non_interactive = 1;
- } else if (vflag) {
- version_arg();
- non_interactive = 1;
- } else if (multiple_flag) {
- if (load_data) {
- io_init(cfile);
- no_file = io_check_data_files();
- if (dflag || aflag || nflag || xflag)
- io_load_app();
- }
- if (xflag) {
- notify_init_vars();
- custom_load_conf(conf, 0);
- io_export_data(IO_EXPORT_NONINTERACTIVE, conf);
- non_interactive = 1;
- return (non_interactive);
- }
- if (tflag) {
- todo_arg(tnum, Nflag);
- non_interactive = 1;
- }
- if (nflag) {
- next_arg();
- non_interactive = 1;
- }
- if (dflag) {
- notify_init_vars();
- vars_init(conf);
- custom_load_conf(conf, 0);
- date_arg(ddate, add_line, Nflag, conf);
- non_interactive = 1;
- } else if (aflag) {
- date_t day;
- day.dd = day.mm = day.yyyy = 0;
- notify_init_vars();
- vars_init(conf);
- custom_load_conf(conf, 0);
- app_found = app_arg(add_line, &day, 0, Nflag, conf);
- non_interactive = 1;
- }
- } else {
- non_interactive = 0;
- io_init(cfile);
- no_file = io_check_data_files();
- }
- return (non_interactive);
+ }
+ argc -= optind;
+ argv += optind;
+
+ if (argc >= 1)
+ {
+ usage ();
+ usage_try ();
+ return (EXIT_FAILURE);
+ /* Incorrect arguments */
+ }
+ else
+ {
+ if (unknown_flag)
+ {
+ non_interactive = 1;
+ }
+ else if (hflag)
+ {
+ help_arg ();
+ non_interactive = 1;
+ }
+ else if (vflag)
+ {
+ version_arg ();
+ non_interactive = 1;
+ }
+ else if (multiple_flag)
+ {
+ if (load_data)
+ {
+ io_init (cfile);
+ no_file = io_check_data_files ();
+ if (dflag || aflag || nflag || xflag)
+ io_load_app ();
+ }
+ if (xflag)
+ {
+ notify_init_vars ();
+ custom_load_conf (conf, 0);
+ io_export_data (IO_EXPORT_NONINTERACTIVE, conf);
+ non_interactive = 1;
+ return (non_interactive);
+ }
+ if (tflag)
+ {
+ todo_arg (tnum, Nflag);
+ non_interactive = 1;
+ }
+ if (nflag)
+ {
+ next_arg ();
+ non_interactive = 1;
+ }
+ if (dflag)
+ {
+ notify_init_vars ();
+ vars_init (conf);
+ custom_load_conf (conf, 0);
+ date_arg (ddate, add_line, Nflag, conf);
+ non_interactive = 1;
+ }
+ else if (aflag)
+ {
+ date_t day;
+ day.dd = day.mm = day.yyyy = 0;
+ notify_init_vars ();
+ vars_init (conf);
+ custom_load_conf (conf, 0);
+ app_found = app_arg (add_line, &day, 0, Nflag, conf);
+ non_interactive = 1;
+ }
+ }
+ else
+ {
+ non_interactive = 0;
+ io_init (cfile);
+ no_file = io_check_data_files ();
}
+ return (non_interactive);
+ }
}
diff --git a/src/args.h b/src/args.h
index 5fe51bf..a0923af 100755
--- a/src/args.h
+++ b/src/args.h
@@ -1,4 +1,4 @@
-/* $calcurse: args.h,v 1.8 2007/07/28 13:11:42 culot Exp $ */
+/* $calcurse: args.h,v 1.9 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -27,6 +27,6 @@
#ifndef CALCURSE_ARGS_H
#define CALCURSE_ARGS_H
-int parse_args(int, char **, conf_t *);
+int parse_args (int, char **, conf_t *);
#endif /* CALCURSE_ARGS_H */
diff --git a/src/calcurse.c b/src/calcurse.c
index 4e7acb7..2c814f0 100755
--- a/src/calcurse.c
+++ b/src/calcurse.c
@@ -1,4 +1,4 @@
-/* $calcurse: calcurse.c,v 1.61 2008/04/09 20:38:29 culot Exp $ */
+/* $calcurse: calcurse.c,v 1.62 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -44,446 +44,466 @@
/*
- * Calcurse is a text-based personal organizer which helps keeping track
+ * Calcurse is a text-based personal organizer which helps keeping track
* of events and everyday tasks. It contains a calendar, a 'todo' list,
* and puts your appointments in order. The user interface is configurable,
* and one can choose between different color schemes and layouts.
* All of the commands are documented within an online help system.
*/
-int
-main(int argc, char **argv)
+int
+main (int argc, char **argv)
{
- conf_t conf;
- day_items_nb_t inday;
- int ch, background, foreground;
- int non_interactive;
- int no_data_file = 1;
- int sav_hilt_app = 0;
- int sav_hilt_tod = 0;
- struct sigaction sigact;
- bool do_storage = false;
- bool do_update = true;
- bool day_changed = false;
- char *no_color_support =
- _("Sorry, colors are not supported by your terminal\n"
- "(Press [ENTER] to continue)");
- char *quit_message = _("Do you really want to quit ?");
- char choices[] = "[y/n] ";
+ conf_t conf;
+ day_items_nb_t inday;
+ int ch, background, foreground;
+ int non_interactive;
+ int no_data_file = 1;
+ int sav_hilt_app = 0;
+ int sav_hilt_tod = 0;
+ struct sigaction sigact;
+ bool do_storage = false;
+ bool do_update = true;
+ bool day_changed = false;
+ char *no_color_support =
+ _("Sorry, colors are not supported by your terminal\n"
+ "(Press [ENTER] to continue)");
+ char *quit_message = _("Do you really want to quit ?");
+ char choices[] = "[y/n] ";
#if ENABLE_NLS
- setlocale (LC_ALL, "");
- bindtextdomain (PACKAGE, LOCALEDIR);
- textdomain (PACKAGE);
+ setlocale (LC_ALL, "");
+ bindtextdomain (PACKAGE, LOCALEDIR);
+ textdomain (PACKAGE);
#endif /* ENABLE_NLS */
-
- /* Thread-safe data structure init */
- apoint_llist_init();
- recur_apoint_llist_init();
-
- /*
- * Begin by parsing and handling command line arguments.
- * The data path is also initialized here.
- */
- non_interactive = parse_args(argc, argv, &conf);
- if (non_interactive)
- return (EXIT_SUCCESS);
-
- /* Begin of interactive mode with ncurses interface. */
- sigs_init(&sigact); /* signal handling init */
- initscr(); /* start the curses mode */
- cbreak(); /* control chars generate a signal */
- noecho(); /* controls echoing of typed chars */
- curs_set(0); /* make cursor invisible */
- calendar_set_current_date();
- notify_init_vars();
- wins_get_config();
-
- /* Check if terminal supports color. */
- if (has_colors()) {
- colorize = true;
- background = COLOR_BLACK;
- foreground = COLOR_WHITE;
- start_color();
-#ifdef NCURSES_VERSION
- if (use_default_colors() != ERR) {
- background = -1;
- foreground = -1;
- }
-#endif /* NCURSES_VERSION */
+ /* Thread-safe data structure init */
+ apoint_llist_init ();
+ recur_apoint_llist_init ();
+
+ /*
+ * Begin by parsing and handling command line arguments.
+ * The data path is also initialized here.
+ */
+ non_interactive = parse_args (argc, argv, &conf);
+ if (non_interactive)
+ return (EXIT_SUCCESS);
+
+ /* Begin of interactive mode with ncurses interface. */
+ sigs_init (&sigact); /* signal handling init */
+ initscr (); /* start the curses mode */
+ cbreak (); /* control chars generate a signal */
+ noecho (); /* controls echoing of typed chars */
+ curs_set (0); /* make cursor invisible */
+ calendar_set_current_date ();
+ notify_init_vars ();
+ wins_get_config ();
+
+ /* Check if terminal supports color. */
+ if (has_colors ())
+ {
+ colorize = true;
+ background = COLOR_BLACK;
+ foreground = COLOR_WHITE;
+ start_color ();
- /* Color assignment */
- init_pair(COLR_RED, COLOR_RED, background);
- init_pair(COLR_GREEN, COLOR_GREEN, background);
- init_pair(COLR_YELLOW, COLOR_YELLOW, background);
- init_pair(COLR_BLUE, COLOR_BLUE, background);
- init_pair(COLR_MAGENTA, COLOR_MAGENTA, background);
- init_pair(COLR_CYAN, COLOR_CYAN, background);
- init_pair(COLR_DEFAULT, foreground, background);
- init_pair(COLR_HIGH, COLOR_BLACK, COLOR_GREEN);
- init_pair(COLR_CUSTOM, COLOR_RED, background);
-
- } else {
- colorize = false;
- background = COLOR_BLACK;
+#ifdef NCURSES_VERSION
+ if (use_default_colors () != ERR)
+ {
+ background = -1;
+ foreground = -1;
}
+#endif /* NCURSES_VERSION */
- vars_init(&conf);
- wins_init();
- wins_slctd_init();
- notify_init_bar();
- reset_status_page();
-
- /*
- * Read the data from files : first the user
- * configuration (the display is then updated), and then
- * the todo list, appointments and events.
- */
- no_data_file = io_check_data_files();
- custom_load_conf(&conf, background);
- erase_status_bar();
- io_load_todo();
- io_load_app();
- wins_reinit();
- if (notify_bar()) {
- notify_start_main_thread();
- notify_check_next_app();
- }
- wins_update();
- io_startup_screen(conf.skip_system_dialogs, no_data_file);
- inday = *day_process_storage(0, day_changed, &inday);
- wins_slctd_set(CAL);
- wins_update();
- calendar_start_date_thread();
-
- /* User input */
- for (;;) {
-
- do_update = true;
- ch = wgetch(win[STA].p);
-
- switch (ch) {
-
- case ERR:
- do_update = false;
- break;
-
- case CTRL('R'):
- case KEY_RESIZE:
- do_update = false;
- wins_reset();
- break;
-
- case 9: /* The TAB key was hit. */
- reset_status_page();
- /* Save previously highlighted event. */
- switch (wins_slctd()) {
- case TOD:
- sav_hilt_tod = todo_hilt();
- todo_hilt_set(0);
- break;
- case APP:
- sav_hilt_app = apoint_hilt();
- apoint_hilt_set(0);
- break;
- default:
- break;
- }
- wins_slctd_next();
-
- /* Select the event to highlight. */
- switch (wins_slctd()) {
- case TOD:
- if ((sav_hilt_tod == 0) && (todo_nb() != 0))
- todo_hilt_set(1);
- else
- todo_hilt_set(sav_hilt_tod);
- break;
- case APP:
- if ((sav_hilt_app == 0) &&
- ((inday.nb_events + inday.nb_apoints) != 0))
- apoint_hilt_set(1);
- else
- apoint_hilt_set(sav_hilt_app);
- break;
- default:
- break;
- }
- break;
-
- case 'O':
- case 'o':
- other_status_page(wins_slctd());
- break;
-
- case 'G':
- case 'g': /* Goto function */
- erase_status_bar();
- calendar_set_current_date();
- calendar_change_day(conf.input_datefmt);
- do_storage = true;
- day_changed = true;
- break;
-
- case 'V':
- case 'v': /* View function */
- if ((wins_slctd() == APP) && (apoint_hilt() != 0))
- day_popup_item();
- else if ((wins_slctd() == TOD) && (todo_hilt() != 0))
- item_in_popup(NULL, NULL, todo_saved_mesg(),
- _("To do :"));
- break;
-
+ /* Color assignment */
+ init_pair (COLR_RED, COLOR_RED, background);
+ init_pair (COLR_GREEN, COLOR_GREEN, background);
+ init_pair (COLR_YELLOW, COLOR_YELLOW, background);
+ init_pair (COLR_BLUE, COLOR_BLUE, background);
+ init_pair (COLR_MAGENTA, COLOR_MAGENTA, background);
+ init_pair (COLR_CYAN, COLOR_CYAN, background);
+ init_pair (COLR_DEFAULT, foreground, background);
+ init_pair (COLR_HIGH, COLOR_BLACK, COLOR_GREEN);
+ init_pair (COLR_CUSTOM, COLOR_RED, background);
+
+ }
+ else
+ {
+ colorize = false;
+ background = COLOR_BLACK;
+ }
+
+ vars_init (&conf);
+ wins_init ();
+ wins_slctd_init ();
+ notify_init_bar ();
+ reset_status_page ();
+
+ /*
+ * Read the data from files : first the user
+ * configuration (the display is then updated), and then
+ * the todo list, appointments and events.
+ */
+ no_data_file = io_check_data_files ();
+ custom_load_conf (&conf, background);
+ erase_status_bar ();
+ io_load_todo ();
+ io_load_app ();
+ wins_reinit ();
+ if (notify_bar ())
+ {
+ notify_start_main_thread ();
+ notify_check_next_app ();
+ }
+ wins_update ();
+ io_startup_screen (conf.skip_system_dialogs, no_data_file);
+ inday = *day_process_storage (0, day_changed, &inday);
+ wins_slctd_set (CAL);
+ wins_update ();
+ calendar_start_date_thread ();
+
+ /* User input */
+ for (;;)
+ {
+ do_update = true;
+ ch = wgetch (win[STA].p);
+ switch (ch)
+ {
+ case ERR:
+ do_update = false;
+ break;
+
+ case CTRL ('R'):
+ case KEY_RESIZE:
+ do_update = false;
+ wins_reset ();
+ break;
+
+ case 9: /* The TAB key was hit. */
+ reset_status_page ();
+ /* Save previously highlighted event. */
+ switch (wins_slctd ())
+ {
+ case TOD:
+ sav_hilt_tod = todo_hilt ();
+ todo_hilt_set (0);
+ break;
+ case APP:
+ sav_hilt_app = apoint_hilt ();
+ apoint_hilt_set (0);
+ break;
+ default:
+ break;
+ }
+ wins_slctd_next ();
+
+ /* Select the event to highlight. */
+ switch (wins_slctd ())
+ {
+ case TOD:
+ if ((sav_hilt_tod == 0) && (todo_nb () != 0))
+ todo_hilt_set (1);
+ else
+ todo_hilt_set (sav_hilt_tod);
+ break;
+ case APP:
+ if ((sav_hilt_app == 0)
+ && ((inday.nb_events + inday.nb_apoints) != 0))
+ apoint_hilt_set (1);
+ else
+ apoint_hilt_set (sav_hilt_app);
+ break;
+ default:
+ break;
+ }
+ break;
+
+ case 'O':
+ case 'o':
+ other_status_page (wins_slctd ());
+ break;
+
+ case 'G':
+ case 'g': /* Goto function */
+ erase_status_bar ();
+ calendar_set_current_date ();
+ calendar_change_day (conf.input_datefmt);
+ do_storage = true;
+ day_changed = true;
+ break;
+
+ case 'V':
+ case 'v': /* View function */
+ if ((wins_slctd () == APP) && (apoint_hilt () != 0))
+ day_popup_item ();
+ else if ((wins_slctd () == TOD) && (todo_hilt () != 0))
+ item_in_popup (NULL, NULL, todo_saved_mesg (), _("To do :"));
+ break;
+
+ case 'C':
+ case 'c': /* Configuration menu */
+ erase_status_bar ();
+ config_bar ();
+ while ((ch = wgetch (win[STA].p)) != 'q')
+ {
+ switch (ch)
+ {
case 'C':
- case 'c': /* Configuration menu */
- erase_status_bar();
- config_bar();
- while ((ch = wgetch(win[STA].p)) != 'q') {
- switch (ch) {
- case 'C':
- case 'c':
- if (has_colors())
- custom_color_config();
- else {
- colorize = false;
- erase_status_bar();
- mvwprintw(win[STA].p, 0, 0,
- _(no_color_support));
- wgetch(win[STA].p);
- }
- break;
- case 'L':
- case 'l':
- layout_config();
- break;
- case 'G':
- case 'g':
- custom_general_config(&conf);
- break;
- case 'N':
- case 'n':
- notify_config_bar();
- break;
- }
- wins_reset();
- wins_update();
- do_storage = true;
- erase_status_bar();
- config_bar();
- }
- wins_update();
- break;
-
- case CTRL('A'): /* Add an app, whatever panel selected */
- apoint_add();
- do_storage = true;
- break;
-
- case CTRL('T'): /* Add a todo, whatever panel selected */
- todo_new_item();
- if (todo_hilt() == 0 && todo_nb() == 1)
- todo_hilt_increase();
- break;
-
- case 'A':
- case 'a': /* Add an item */
- switch (wins_slctd()) {
- case APP:
- apoint_add();
- do_storage = true;
- break;
- case TOD:
- todo_new_item();
- if (todo_hilt() == 0 && todo_nb() == 1)
- todo_hilt_increase();
- break;
- default:
- break;
- }
- break;
-
- case 'E':
- case 'e': /* Edit an existing item */
- if (wins_slctd() == APP && apoint_hilt() != 0)
- day_edit_item(&conf);
- else if (wins_slctd() == TOD && todo_hilt() != 0)
- todo_edit_item();
- do_storage = true;
- break;
-
- case 'D':
- case 'd': /* Delete an item */
- if (wins_slctd() == APP && apoint_hilt() != 0)
- apoint_delete(&conf, &inday.nb_events,
- &inday.nb_apoints);
- else if (wins_slctd() == TOD && todo_hilt() != 0)
- todo_delete(&conf);
- do_storage = true;
- break;
-
- case 'R':
- case 'r':
- if (wins_slctd() == APP && apoint_hilt() != 0)
- recur_repeat_item(&conf);
- do_storage = true;
- break;
-
- case '!':
- if (wins_slctd() == APP && apoint_hilt() != 0)
- apoint_switch_notify();
- do_storage = true;
- break;
-
- case '+':
- case '-':
- if (wins_slctd() == TOD && todo_hilt() != 0) {
- todo_chg_priority(ch);
- if (todo_hilt_pos() < 0)
- todo_set_first(todo_hilt());
- else if (todo_hilt_pos() >= win[TOD].h - 4)
- todo_set_first(todo_hilt() -
- win[TOD].h + 5);
- }
- break;
-
+ case 'c':
+ if (has_colors ())
+ custom_color_config ();
+ else
+ {
+ colorize = false;
+ erase_status_bar ();
+ mvwprintw (win[STA].p, 0, 0, _(no_color_support));
+ wgetch (win[STA].p);
+ }
+ break;
+ case 'L':
+ case 'l':
+ layout_config ();
+ break;
+ case 'G':
+ case 'g':
+ custom_general_config (&conf);
+ break;
case 'N':
- case 'n':
- /* Attach a note to an item, create it if necessary */
- if (wins_slctd() == APP && apoint_hilt() != 0)
- day_edit_note(conf.editor);
- else if (wins_slctd() == TOD && todo_hilt() != 0)
- todo_edit_note(conf.editor);
- do_storage = true;
- break;
-
- case '>':
- /* View a note previously attached to an item */
- if (wins_slctd() == APP && apoint_hilt() != 0)
- day_view_note(conf.pager);
- else if (wins_slctd() == TOD && todo_hilt() != 0)
- todo_view_note(conf.pager);
- break;
-
- case '?': /* Online help system */
- status_bar();
- help_screen();
- break;
-
- case 'S':
- case 's': /* Save function */
- io_save_cal(&conf);
- break;
-
- case 'X':
- case 'x': /* Export function */
- io_export_data(IO_EXPORT_INTERACTIVE, &conf);
- break;
-
- case (261): /* right arrow */
- case ('L'):
- case ('l'):
- case CTRL('L'):
- if (wins_slctd() == CAL || ch == CTRL('L')) {
- do_storage = true;
- day_changed = true;
- calendar_move(RIGHT);
- }
- break;
-
- case (260): /* left arrow */
- case ('H'):
- case ('h'):
- case CTRL('H'):
- if (wins_slctd() == CAL || ch == CTRL('H')) {
- do_storage = true;
- day_changed = true;
- calendar_move(LEFT);
- }
- break;
-
- case (259): /* up arrow */
- case ('K'):
- case ('k'):
- case CTRL('K'):
- if (wins_slctd() == CAL || ch == CTRL('K')) {
- do_storage = true;
- day_changed = true;
- calendar_move(UP);
- } else {
- if ((wins_slctd() == APP) &&
- (apoint_hilt() > 1)) {
- apoint_hilt_decrease();
- apoint_scroll_pad_up(inday.nb_events);
- } else if ((wins_slctd() == TOD) &&
- (todo_hilt() > 1)) {
- todo_hilt_decrease();
- if (todo_hilt_pos() < 0)
- todo_first_decrease();
- }
- }
- break;
-
- case (258): /* down arrow */
- case ('J'):
- case ('j'):
- case CTRL('J'):
- if (wins_slctd() == CAL || ch == CTRL('J')) {
- do_storage = true;
- day_changed = true;
- calendar_move(DOWN);
- } else {
- if ((wins_slctd() == APP) &&
- (apoint_hilt() < inday.nb_events +
- inday.nb_apoints)) {
- apoint_hilt_increase();
- apoint_scroll_pad_down(inday.nb_events,
- win[APP].h);
- }
- if ((wins_slctd() == TOD) &&
- (todo_hilt() < todo_nb())) {
- todo_hilt_increase();
- if (todo_hilt_pos() == win[TOD].h - 4)
- todo_first_increase();
- }
- }
- break;
-
- case ('Q'): /* Quit calcurse :( */
- case ('q'):
- if (conf.auto_save)
- io_save_cal(&conf);
-
- if (conf.confirm_quit) {
- status_mesg(_(quit_message), choices);
- ch = wgetch(win[STA].p);
- if ( ch == 'y' )
- exit_calcurse(EXIT_SUCCESS);
- else {
- erase_status_bar();
- break;
- }
- } else
- exit_calcurse(EXIT_SUCCESS);
- break;
-
- default:
- do_update = false;
- break;
+ case 'n':
+ notify_config_bar ();
+ break;
}
-
- if (do_storage) {
- inday = *day_process_storage(calendar_get_slctd_day(),
- day_changed, &inday);
- do_storage = !do_storage;
- if (day_changed) {
- sav_hilt_app = 0;
- day_changed = !day_changed;
- if ((wins_slctd() == APP) &&
- (inday.nb_events + inday.nb_apoints != 0))
- apoint_hilt_set(1);
- }
+ wins_reset ();
+ wins_update ();
+ do_storage = true;
+ erase_status_bar ();
+ config_bar ();
+ }
+ wins_update ();
+ break;
+
+ case CTRL ('A'): /* Add an app, whatever panel selected */
+ apoint_add ();
+ do_storage = true;
+ break;
+
+ case CTRL ('T'): /* Add a todo, whatever panel selected */
+ todo_new_item ();
+ if (todo_hilt () == 0 && todo_nb () == 1)
+ todo_hilt_increase ();
+ break;
+
+ case 'A':
+ case 'a': /* Add an item */
+ switch (wins_slctd ())
+ {
+ case APP:
+ apoint_add ();
+ do_storage = true;
+ break;
+ case TOD:
+ todo_new_item ();
+ if (todo_hilt () == 0 && todo_nb () == 1)
+ todo_hilt_increase ();
+ break;
+ default:
+ break;
+ }
+ break;
+
+ case 'E':
+ case 'e': /* Edit an existing item */
+ if (wins_slctd () == APP && apoint_hilt () != 0)
+ day_edit_item (&conf);
+ else if (wins_slctd () == TOD && todo_hilt () != 0)
+ todo_edit_item ();
+ do_storage = true;
+ break;
+
+ case 'D':
+ case 'd': /* Delete an item */
+ if (wins_slctd () == APP && apoint_hilt () != 0)
+ apoint_delete (&conf, &inday.nb_events, &inday.nb_apoints);
+ else if (wins_slctd () == TOD && todo_hilt () != 0)
+ todo_delete (&conf);
+ do_storage = true;
+ break;
+
+ case 'R':
+ case 'r':
+ if (wins_slctd () == APP && apoint_hilt () != 0)
+ recur_repeat_item (&conf);
+ do_storage = true;
+ break;
+
+ case '!':
+ if (wins_slctd () == APP && apoint_hilt () != 0)
+ apoint_switch_notify ();
+ do_storage = true;
+ break;
+
+ case '+':
+ case '-':
+ if (wins_slctd () == TOD && todo_hilt () != 0)
+ {
+ todo_chg_priority (ch);
+ if (todo_hilt_pos () < 0)
+ todo_set_first (todo_hilt ());
+ else if (todo_hilt_pos () >= win[TOD].h - 4)
+ todo_set_first (todo_hilt () - win[TOD].h + 5);
+ }
+ break;
+
+ case 'N':
+ case 'n':
+ /* Attach a note to an item, create it if necessary */
+ if (wins_slctd () == APP && apoint_hilt () != 0)
+ day_edit_note (conf.editor);
+ else if (wins_slctd () == TOD && todo_hilt () != 0)
+ todo_edit_note (conf.editor);
+ do_storage = true;
+ break;
+
+ case '>':
+ /* View a note previously attached to an item */
+ if (wins_slctd () == APP && apoint_hilt () != 0)
+ day_view_note (conf.pager);
+ else if (wins_slctd () == TOD && todo_hilt () != 0)
+ todo_view_note (conf.pager);
+ break;
+
+ case '?': /* Online help system */
+ status_bar ();
+ help_screen ();
+ break;
+
+ case 'S':
+ case 's': /* Save function */
+ io_save_cal (&conf);
+ break;
+
+ case 'X':
+ case 'x': /* Export function */
+ io_export_data (IO_EXPORT_INTERACTIVE, &conf);
+ break;
+
+ case (261): /* right arrow */
+ case ('L'):
+ case ('l'):
+ case CTRL ('L'):
+ if (wins_slctd () == CAL || ch == CTRL ('L'))
+ {
+ do_storage = true;
+ day_changed = true;
+ calendar_move (RIGHT);
+ }
+ break;
+
+ case (260): /* left arrow */
+ case ('H'):
+ case ('h'):
+ case CTRL ('H'):
+ if (wins_slctd () == CAL || ch == CTRL ('H'))
+ {
+ do_storage = true;
+ day_changed = true;
+ calendar_move (LEFT);
+ }
+ break;
+
+ case (259): /* up arrow */
+ case ('K'):
+ case ('k'):
+ case CTRL ('K'):
+ if (wins_slctd () == CAL || ch == CTRL ('K'))
+ {
+ do_storage = true;
+ day_changed = true;
+ calendar_move (UP);
+ }
+ else
+ {
+ if ((wins_slctd () == APP) && (apoint_hilt () > 1))
+ {
+ apoint_hilt_decrease ();
+ apoint_scroll_pad_up (inday.nb_events);
+ }
+ else if ((wins_slctd () == TOD) && (todo_hilt () > 1))
+ {
+ todo_hilt_decrease ();
+ if (todo_hilt_pos () < 0)
+ todo_first_decrease ();
+ }
+ }
+ break;
+
+ case (258): /* down arrow */
+ case ('J'):
+ case ('j'):
+ case CTRL ('J'):
+ if (wins_slctd () == CAL || ch == CTRL ('J'))
+ {
+ do_storage = true;
+ day_changed = true;
+ calendar_move (DOWN);
+ }
+ else
+ {
+ if ((wins_slctd () == APP) &&
+ (apoint_hilt () < inday.nb_events + inday.nb_apoints))
+ {
+ apoint_hilt_increase ();
+ apoint_scroll_pad_down (inday.nb_events, win[APP].h);
}
- if (do_update)
- wins_update();
+ if ((wins_slctd () == TOD) && (todo_hilt () < todo_nb ()))
+ {
+ todo_hilt_increase ();
+ if (todo_hilt_pos () == win[TOD].h - 4)
+ todo_first_increase ();
+ }
+ }
+ break;
+
+ case ('Q'): /* Quit calcurse :( */
+ case ('q'):
+ if (conf.auto_save)
+ io_save_cal (&conf);
+
+ if (conf.confirm_quit)
+ {
+ status_mesg (_(quit_message), choices);
+ ch = wgetch (win[STA].p);
+ if (ch == 'y')
+ exit_calcurse (EXIT_SUCCESS);
+ else
+ {
+ erase_status_bar ();
+ break;
+ }
+ }
+ else
+ exit_calcurse (EXIT_SUCCESS);
+ break;
+
+ default:
+ do_update = false;
+ break;
+ }
+
+ if (do_storage)
+ {
+ inday = *day_process_storage (calendar_get_slctd_day (),
+ day_changed, &inday);
+ do_storage = !do_storage;
+ if (day_changed)
+ {
+ sav_hilt_app = 0;
+ day_changed = !day_changed;
+ if ((wins_slctd () == APP) &&
+ (inday.nb_events + inday.nb_apoints != 0))
+ apoint_hilt_set (1);
+ }
}
+ if (do_update)
+ wins_update ();
+ }
}
diff --git a/src/calendar.c b/src/calendar.c
index 93b461c..6c1d957 100755
--- a/src/calendar.c
+++ b/src/calendar.c
@@ -1,4 +1,4 @@
-/* $calcurse: calendar.c,v 1.14 2008/04/09 20:38:29 culot Exp $ */
+/* $calcurse: calendar.c,v 1.15 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -55,273 +55,276 @@
#define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)
-static date_t today, slctd_day;
-static bool week_begins_on_monday;
-static pthread_mutex_t date_thread_mutex = PTHREAD_MUTEX_INITIALIZER;
-static pthread_t calendar_t_date;
+static date_t today, slctd_day;
+static bool week_begins_on_monday;
+static pthread_mutex_t date_thread_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_t calendar_t_date;
/* Thread needed to update current date in calendar. */
static void *
-calendar_date_thread(void *arg)
+calendar_date_thread (void *arg)
{
- time_t now, tomorrow;
+ time_t now, tomorrow;
- for (;;) {
- tomorrow = (time_t)(get_today() + DAYINSEC);
+ for (;;)
+ {
+ tomorrow = (time_t) (get_today () + DAYINSEC);
- while ((now = time(NULL)) < tomorrow) {
- sleep(tomorrow - now);
- }
-
- calendar_set_current_date();
- calendar_update_panel(win[CAL].p);
+ while ((now = time (NULL)) < tomorrow)
+ {
+ sleep (tomorrow - now);
}
- pthread_exit((void*) 0);
+ calendar_set_current_date ();
+ calendar_update_panel (win[CAL].p);
+ }
+
+ pthread_exit ((void *) 0);
}
/* Launch the calendar date thread. */
-void
-calendar_start_date_thread(void)
+void
+calendar_start_date_thread (void)
{
- pthread_create(&calendar_t_date, NULL, calendar_date_thread, NULL);
- return;
+ pthread_create (&calendar_t_date, NULL, calendar_date_thread, NULL);
+ return;
}
/* Stop the calendar date thread. */
-void
-calendar_stop_date_thread(void)
+void
+calendar_stop_date_thread (void)
{
- pthread_cancel(calendar_t_date);
- return;
+ pthread_cancel (calendar_t_date);
+ return;
}
/* Set static variable today to current date */
-void
-calendar_set_current_date(void)
+void
+calendar_set_current_date (void)
{
- time_t timer;
- struct tm *tm;
+ time_t timer;
+ struct tm *tm;
- timer = time(NULL);
- tm = localtime(&timer);
+ timer = time (NULL);
+ tm = localtime (&timer);
- pthread_mutex_lock(&date_thread_mutex);
- today.dd = tm->tm_mday;
- today.mm = tm->tm_mon + 1;
- today.yyyy = tm->tm_year + 1900;
- pthread_mutex_unlock(&date_thread_mutex);
+ pthread_mutex_lock (&date_thread_mutex);
+ today.dd = tm->tm_mday;
+ today.mm = tm->tm_mon + 1;
+ today.yyyy = tm->tm_year + 1900;
+ pthread_mutex_unlock (&date_thread_mutex);
}
/* Needed to display sunday or monday as the first day of week in calendar. */
void
-calendar_set_first_day_of_week(wday_e first_day)
+calendar_set_first_day_of_week (wday_e first_day)
{
- switch (first_day) {
- case SUNDAY:
- week_begins_on_monday = false;
- break;
- case MONDAY:
- week_begins_on_monday = true;
- break;
- default:
- fputs(_("ERROR in calendar_set_first_day_of_week\n"), stderr);
- week_begins_on_monday = false;
- /* NOTREACHED */
- }
+ switch (first_day)
+ {
+ case SUNDAY:
+ week_begins_on_monday = false;
+ break;
+ case MONDAY:
+ week_begins_on_monday = true;
+ break;
+ default:
+ fputs (_("ERROR in calendar_set_first_day_of_week\n"), stderr);
+ week_begins_on_monday = false;
+ /* NOTREACHED */
+ }
}
/* Swap first day of week in calendar. */
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 true if week begins on monday, false otherwise. */
bool
-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. */
void
-calendar_store_current_date(date_t *date)
+calendar_store_current_date (date_t *date)
{
- pthread_mutex_lock(&date_thread_mutex);
- *date = today;
- pthread_mutex_unlock(&date_thread_mutex);
+ pthread_mutex_lock (&date_thread_mutex);
+ *date = today;
+ pthread_mutex_unlock (&date_thread_mutex);
}
/* This is to start at the current date in calendar. */
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 */
date_t *
-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) */
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
-isBissextile(unsigned year)
+static int
+isBissextile (unsigned year)
{
- return (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0));
+ return (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0));
}
-static unsigned
-months_to_days(unsigned month)
+static unsigned
+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
-ymd_to_scalar(unsigned year, unsigned month, unsigned day)
+static long
+ymd_to_scalar (unsigned year, unsigned month, unsigned day)
{
- long scalar;
+ long scalar;
- scalar = day + months_to_days(month);
- if (month > 2)
- scalar -= isBissextile(year) ? 1 : 2;
- year--;
- scalar += years_to_days(year);
+ scalar = day + months_to_days (month);
+ if (month > 2)
+ scalar -= isBissextile (year) ? 1 : 2;
+ year--;
+ scalar += years_to_days (year);
- return (scalar);
+ return (scalar);
}
/* Function used to display the calendar panel. */
void
-calendar_update_panel(WINDOW *cwin)
+calendar_update_panel (WINDOW *cwin)
{
- date_t current_day, check_day;
- int c_day, c_day_1, day_1_sav, numdays, j;
- unsigned yr, mo;
- int ofs_x, ofs_y;
- int item_this_day = 0;
- int title_lines = 3;
- int sunday_first = 0;
-
- /* inits */
- calendar_store_current_date(&current_day);
- erase_window_part(cwin, 1, title_lines, CALWIDTH - 2, CALHEIGHT - 2);
- mo = slctd_day.mm;
- yr = slctd_day.yyyy;
- if (!calendar_week_begins_on_monday())
- sunday_first = 1;
-
- /* offset for centering calendar in window */
- ofs_y = 2 + (CALHEIGHT - 9) / 2;
- ofs_x = (CALWIDTH - 27) / 2;
-
- /* checking the number of days in february */
- numdays = days[mo - 1];
- if (2 == mo && isBissextile(yr))
- ++numdays;
-
- /*
- * the first calendar day will be monday or sunday, depending on
- * 'week_begins_on_monday' value
- */
- 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 */
- custom_apply_attr(cwin, ATTR_HIGH);
- mvwprintw(cwin, ofs_y,
- (CALWIDTH - (strlen(_(monthnames[mo - 1])) + 5)) / 2,
- "%s %d", _(monthnames[mo - 1]), slctd_day.yyyy);
- custom_remove_attr(cwin, ATTR_HIGH);
- ++ofs_y;
-
- /* print the days, with regards to the first day of the week */
- custom_apply_attr(cwin, ATTR_HIGH);
- for (j = 0; j < 7; j++) {
- mvwprintw(cwin, ofs_y, ofs_x + 4 * j, "%s",
- _(daynames[1 + j - sunday_first]));
+ date_t current_day, check_day;
+ int c_day, c_day_1, day_1_sav, numdays, j;
+ unsigned yr, mo;
+ int ofs_x, ofs_y;
+ int item_this_day = 0;
+ int title_lines = 3;
+ int sunday_first = 0;
+
+ /* inits */
+ calendar_store_current_date (&current_day);
+ erase_window_part (cwin, 1, title_lines, CALWIDTH - 2, CALHEIGHT - 2);
+ mo = slctd_day.mm;
+ yr = slctd_day.yyyy;
+ if (!calendar_week_begins_on_monday ())
+ sunday_first = 1;
+
+ /* offset for centering calendar in window */
+ ofs_y = 2 + (CALHEIGHT - 9) / 2;
+ ofs_x = (CALWIDTH - 27) / 2;
+
+ /* checking the number of days in february */
+ numdays = days[mo - 1];
+ if (2 == mo && isBissextile (yr))
+ ++numdays;
+
+ /*
+ * the first calendar day will be monday or sunday, depending on
+ * 'week_begins_on_monday' value
+ */
+ 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 */
+ custom_apply_attr (cwin, ATTR_HIGH);
+ mvwprintw (cwin, ofs_y, (CALWIDTH - (strlen (_(monthnames[mo - 1])) + 5)) / 2,
+ "%s %d", _(monthnames[mo - 1]), slctd_day.yyyy);
+ custom_remove_attr (cwin, ATTR_HIGH);
+ ++ofs_y;
+
+ /* print the days, with regards to the first day of the week */
+ custom_apply_attr (cwin, ATTR_HIGH);
+ for (j = 0; j < 7; j++)
+ {
+ mvwprintw (cwin, ofs_y, ofs_x + 4 * j, "%s",
+ _(daynames[1 + j - sunday_first]));
+ }
+ custom_remove_attr (cwin, ATTR_HIGH);
+
+ 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)
+ {
+ check_day.dd = c_day;
+ check_day.mm = slctd_day.mm;
+ check_day.yyyy = slctd_day.yyyy;
+
+ /* check if the day contains an event or an appointment */
+ item_this_day = day_check_if_item (check_day);
+
+ /* Go to next line, the week is over. */
+ if (!c_day_1 && 1 != c_day)
+ {
+ ++ofs_y;
+ ofs_x = 2 - day_1_sav - 4 * c_day - 1;
}
- custom_remove_attr(cwin, ATTR_HIGH);
-
- 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) {
- check_day.dd = c_day;
- check_day.mm = slctd_day.mm;
- check_day.yyyy = slctd_day.yyyy;
-
- /* check if the day contains an event or an appointment */
- item_this_day =
- day_check_if_item(check_day);
-
- /* Go to next line, the week is over. */
- if (!c_day_1 && 1 != c_day) {
- ++ofs_y;
- ofs_x = 2 - day_1_sav - 4 * c_day - 1;
- }
-
- /* This is today, so print it in yellow. */
- if (c_day == current_day.dd && current_day.mm == slctd_day.mm
- && current_day.yyyy == slctd_day.yyyy &&
- current_day.dd != slctd_day.dd) {
-
- custom_apply_attr(cwin, ATTR_LOWEST);
- mvwprintw(cwin, ofs_y + 1,
- ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day);
- custom_remove_attr(cwin, ATTR_LOWEST);
-
- } else if (c_day == slctd_day.dd &&
- ( (current_day.dd != slctd_day.dd) ||
- (current_day.mm != slctd_day.mm)
- || (current_day.yyyy != slctd_day.yyyy))) {
-
- /* This is the selected day, print it in red. */
- custom_apply_attr(cwin, ATTR_MIDDLE);
- mvwprintw(cwin, ofs_y + 1,
- ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day);
- custom_remove_attr(cwin, ATTR_MIDDLE);
-
- } else if (c_day == slctd_day.dd &&
- current_day.dd == slctd_day.dd &&
- current_day.mm == slctd_day.mm &&
- current_day.yyyy == slctd_day.yyyy) {
-
- /* today is the selected day */
- custom_apply_attr(cwin, ATTR_MIDDLE);
- mvwprintw(cwin, ofs_y + 1,
- ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day);
- custom_remove_attr(cwin, ATTR_MIDDLE);
-
- } else if (item_this_day) {
- custom_apply_attr(cwin, ATTR_LOW);
- mvwprintw(cwin, ofs_y + 1,
- ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day);
- custom_remove_attr(cwin, ATTR_LOW);
- } else
- /* otherwise, print normal days in black */
- mvwprintw(cwin, ofs_y + 1,
- ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day);
+ /* This is today, so print it in yellow. */
+ if (c_day == current_day.dd && current_day.mm == slctd_day.mm
+ && current_day.yyyy == slctd_day.yyyy
+ && current_day.dd != slctd_day.dd)
+ {
+ custom_apply_attr (cwin, ATTR_LOWEST);
+ mvwprintw (cwin, ofs_y + 1,
+ ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day);
+ custom_remove_attr (cwin, ATTR_LOWEST);
+ }
+ else if (c_day == slctd_day.dd &&
+ ((current_day.dd != slctd_day.dd)
+ || (current_day.mm != slctd_day.mm)
+ || (current_day.yyyy != slctd_day.yyyy)))
+ {
+ /* This is the selected day, print it in red. */
+ custom_apply_attr (cwin, ATTR_MIDDLE);
+ mvwprintw (cwin, ofs_y + 1, ofs_x + day_1_sav + 4 * c_day + 1, "%2d",
+ c_day);
+ custom_remove_attr (cwin, ATTR_MIDDLE);
+ }
+ else if (c_day == slctd_day.dd && current_day.dd == slctd_day.dd
+ && current_day.mm == slctd_day.mm
+ && current_day.yyyy == slctd_day.yyyy)
+ {
+ /* today is the selected day */
+ custom_apply_attr (cwin, ATTR_MIDDLE);
+ mvwprintw (cwin, ofs_y + 1, ofs_x + day_1_sav + 4 * c_day + 1, "%2d",
+ c_day);
+ custom_remove_attr (cwin, ATTR_MIDDLE);
+ }
+ else if (item_this_day)
+ {
+ custom_apply_attr (cwin, ATTR_LOW);
+ mvwprintw (cwin, ofs_y + 1, ofs_x + day_1_sav + 4 * c_day + 1, "%2d",
+ c_day);
+ custom_remove_attr (cwin, ATTR_LOW);
}
- wnoutrefresh(cwin);
+ else
+ /* otherwise, print normal days in black */
+ mvwprintw (cwin, ofs_y + 1, ofs_x + day_1_sav + 4 * c_day + 1, "%2d",
+ c_day);
+ }
+ wnoutrefresh (cwin);
}
/*
@@ -332,60 +335,58 @@ calendar_update_panel(WINDOW *cwin)
* with the newly selected date.
*/
void
-calendar_change_day(int datefmt)
+calendar_change_day (int datefmt)
{
#define LDAY 11
- char selected_day[LDAY] = "";
- char outstr[BUFSIZ];
- date_t today;
- int dday, dmonth, dyear;
- int wrong_day = 1;
- char *mesg_line1 =
- _("The day you entered is not valid (should be between 01/01/1902 and 12/31/2037)");
- char *mesg_line2 = _("Press [ENTER] to continue");
- char *request_date =
- "Enter the day to go to [ENTER for today] : %s";
-
- while (wrong_day) {
- snprintf(outstr, BUFSIZ, request_date,
- DATEFMT_DESC(datefmt));
- status_mesg(_(outstr), "");
- if (getstring(win[STA].p, selected_day, LDAY, 0, 1) ==
- GETSTRING_ESC)
- return;
- else {
- if (strlen(selected_day) == 0) {
- calendar_store_current_date(&today);
-
- /* go to today */
- wrong_day = 0;
- slctd_day.dd = today.dd;
- slctd_day.mm = today.mm;
- slctd_day.yyyy = today.yyyy;
-
- } else if (strlen(selected_day) != LDAY - 1) {
-
- wrong_day = 1;
-
- } else if (parse_date(selected_day, datefmt,
- &dyear, &dmonth, &dday)) {
-
- wrong_day = 0;
-
- /* go to chosen day */
- slctd_day.dd = dday;
- slctd_day.mm = dmonth;
- slctd_day.yyyy = dyear;
- }
-
- if (wrong_day) {
- status_mesg(mesg_line1, mesg_line2);
- wgetch(win[STA].p);
- }
- }
+ char selected_day[LDAY] = "";
+ char outstr[BUFSIZ];
+ date_t today;
+ int dday, dmonth, dyear;
+ int wrong_day = 1;
+ char *mesg_line1 =
+ _("The day you entered is not valid "
+ "(should be between 01/01/1902 and 12/31/2037)");
+ char *mesg_line2 = _("Press [ENTER] to continue");
+ char *request_date = "Enter the day to go to [ENTER for today] : %s";
+
+ while (wrong_day)
+ {
+ snprintf (outstr, BUFSIZ, request_date, DATEFMT_DESC (datefmt));
+ status_mesg (_(outstr), "");
+ if (getstring (win[STA].p, selected_day, LDAY, 0, 1) == GETSTRING_ESC)
+ return;
+ else
+ {
+ if (strlen (selected_day) == 0)
+ {
+ calendar_store_current_date (&today);
+ /* go to today */
+ wrong_day = 0;
+ slctd_day.dd = today.dd;
+ slctd_day.mm = today.mm;
+ slctd_day.yyyy = today.yyyy;
+ }
+ else if (strlen (selected_day) != LDAY - 1)
+ {
+ wrong_day = 1;
+ }
+ else if (parse_date (selected_day, datefmt, &dyear, &dmonth, &dday))
+ {
+ wrong_day = 0;
+ /* go to chosen day */
+ slctd_day.dd = dday;
+ slctd_day.mm = dmonth;
+ slctd_day.yyyy = dyear;
+ }
+ if (wrong_day)
+ {
+ status_mesg (mesg_line1, mesg_line2);
+ wgetch (win[STA].p);
+ }
}
+ }
- return;
+ return;
}
/*
@@ -393,68 +394,70 @@ calendar_change_day(int datefmt)
* Returns 0 on success, 1 otherwise.
*/
int
-date_change(struct tm *date, int delta_month, int delta_day)
-{
- struct tm t;
-
- t = *date;
- t.tm_mon += delta_month;
- t.tm_mday += delta_day;
-
- if (mktime(&t) == -1)
- return (1);
- else {
- *date = t;
- return (0);
- }
+date_change (struct tm *date, int delta_month, int delta_day)
+{
+ struct tm t;
+
+ t = *date;
+ t.tm_mon += delta_month;
+ t.tm_mday += delta_day;
+
+ if (mktime (&t) == -1)
+ return (1);
+ else
+ {
+ *date = t;
+ return (0);
+ }
}
void
-calendar_move(move_t move)
+calendar_move (move_t move)
{
- int ret;
- struct tm t;
-
- memset(&t, 0, sizeof(struct tm));
- t.tm_mday = slctd_day.dd;
- t.tm_mon = slctd_day.mm - 1;
- t.tm_year = slctd_day.yyyy - 1900;
-
- switch (move) {
- case UP:
- if ((slctd_day.dd <= 7) && (slctd_day.mm == 1) &&
- (slctd_day.yyyy == 1902))
- return;
- ret = date_change(&t, 0, -WEEKINDAYS);
- break;
- case DOWN:
- if ((slctd_day.dd > days[slctd_day.mm - 1] - 7)
- && (slctd_day.mm == 12) && (slctd_day.yyyy == 2037))
- return;
- ret = date_change(&t, 0, WEEKINDAYS);
- break;
- case LEFT:
- if ((slctd_day.dd == 1) && (slctd_day.mm == 1) &&
- (slctd_day.yyyy == 1902))
- return;
- ret = date_change(&t, 0, -1);
- break;
- case RIGHT:
- if ((slctd_day.dd == 31) && (slctd_day.mm == 12) &&
- (slctd_day.yyyy == 2037))
- return;
- ret = date_change(&t, 0, 1);
- break;
- default:
- ret = 1;
- /* NOTREACHED */
- }
-
- if (ret == 0) {
- slctd_day.dd = t.tm_mday;
- slctd_day.mm = t.tm_mon + 1;
- slctd_day.yyyy = t.tm_year + 1900;
- }
+ int ret;
+ struct tm t;
+
+ memset (&t, 0, sizeof (struct tm));
+ t.tm_mday = slctd_day.dd;
+ t.tm_mon = slctd_day.mm - 1;
+ t.tm_year = slctd_day.yyyy - 1900;
+
+ switch (move)
+ {
+ case UP:
+ if ((slctd_day.dd <= 7) && (slctd_day.mm == 1)
+ && (slctd_day.yyyy == 1902))
+ return;
+ ret = date_change (&t, 0, -WEEKINDAYS);
+ break;
+ case DOWN:
+ if ((slctd_day.dd > days[slctd_day.mm - 1] - 7)
+ && (slctd_day.mm == 12) && (slctd_day.yyyy == 2037))
+ return;
+ ret = date_change (&t, 0, WEEKINDAYS);
+ break;
+ case LEFT:
+ if ((slctd_day.dd == 1) && (slctd_day.mm == 1)
+ && (slctd_day.yyyy == 1902))
+ return;
+ ret = date_change (&t, 0, -1);
+ break;
+ case RIGHT:
+ if ((slctd_day.dd == 31) && (slctd_day.mm == 12)
+ && (slctd_day.yyyy == 2037))
+ return;
+ ret = date_change (&t, 0, 1);
+ break;
+ default:
+ ret = 1;
+ /* NOTREACHED */
+ }
+ if (ret == 0)
+ {
+ slctd_day.dd = t.tm_mday;
+ slctd_day.mm = t.tm_mon + 1;
+ slctd_day.yyyy = t.tm_year + 1900;
+ }
}
/*
@@ -499,9 +502,9 @@ calendar_move(move_t move)
* convert degrees to radians
*/
static double
-dtor(double deg)
+dtor (double deg)
{
- return(deg * M_PI / 180);
+ return (deg * M_PI / 180);
}
/*
@@ -509,15 +512,15 @@ dtor(double deg)
* adjust value so 0 <= deg <= 360
*/
static void
-adj360(double *deg)
+adj360 (double *deg)
{
- for (;;)
- if (*deg < 0.0)
- *deg += 360.0;
- else if (*deg > 360.0)
- *deg -= 360.0;
- else
- break;
+ for (;;)
+ if (*deg < 0.0)
+ *deg += 360.0;
+ else if (*deg > 360.0)
+ *deg -= 360.0;
+ else
+ break;
}
/*
@@ -525,35 +528,35 @@ adj360(double *deg)
* return phase of the moon
*/
static double
-potm(double days)
+potm (double days)
{
- double N, Msol, Ec, LambdaSol, l, Mm, Ev, Ac, A3, Mmprime;
- double A4, lprime, V, ldprime, D, Nm;
-
- N = 360.0 * days / 365.242191; /* sec 46 #3 */
- adj360(&N);
- Msol = N + EPSILONg - RHOg; /* sec 46 #4 */
- adj360(&Msol);
- Ec = 360 / M_PI * ECCEN * sin(dtor(Msol)); /* sec 46 #5 */
- LambdaSol = N + Ec + EPSILONg; /* sec 46 #6 */
- adj360(&LambdaSol);
- l = 13.1763966 * days + lzero; /* sec 65 #4 */
- adj360(&l);
- Mm = l - (0.1114041 * days) - Pzero; /* sec 65 #5 */
- adj360(&Mm);
- Nm = Nzero - (0.0529539 * days); /* sec 65 #6 */
- adj360(&Nm);
- Ev = 1.2739 * sin(dtor(2*(l - LambdaSol) - Mm)); /* sec 65 #7 */
- Ac = 0.1858 * sin(dtor(Msol)); /* sec 65 #8 */
- A3 = 0.37 * sin(dtor(Msol));
- Mmprime = Mm + Ev - Ac - A3; /* sec 65 #9 */
- Ec = 6.2886 * sin(dtor(Mmprime)); /* sec 65 #10 */
- A4 = 0.214 * sin(dtor(2 * Mmprime)); /* sec 65 #11 */
- lprime = l + Ev + Ec - Ac + A4; /* sec 65 #12 */
- V = 0.6583 * sin(dtor(2 * (lprime - LambdaSol))); /* sec 65 #13 */
- ldprime = lprime + V; /* sec 65 #14 */
- D = ldprime - LambdaSol; /* sec 67 #2 */
- return(50.0 * (1 - cos(dtor(D)))); /* sec 67 #3 */
+ double N, Msol, Ec, LambdaSol, l, Mm, Ev, Ac, A3, Mmprime;
+ double A4, lprime, V, ldprime, D, Nm;
+
+ N = 360.0 * days / 365.242191; /* sec 46 #3 */
+ adj360 (&N);
+ Msol = N + EPSILONg - RHOg; /* sec 46 #4 */
+ adj360 (&Msol);
+ Ec = 360 / M_PI * ECCEN * sin (dtor (Msol)); /* sec 46 #5 */
+ LambdaSol = N + Ec + EPSILONg; /* sec 46 #6 */
+ adj360 (&LambdaSol);
+ l = 13.1763966 * days + lzero; /* sec 65 #4 */
+ adj360 (&l);
+ Mm = l - (0.1114041 * days) - Pzero; /* sec 65 #5 */
+ adj360 (&Mm);
+ Nm = Nzero - (0.0529539 * days); /* sec 65 #6 */
+ adj360 (&Nm);
+ Ev = 1.2739 * sin (dtor (2 * (l - LambdaSol) - Mm)); /* sec 65 #7 */
+ Ac = 0.1858 * sin (dtor (Msol)); /* sec 65 #8 */
+ A3 = 0.37 * sin (dtor (Msol));
+ Mmprime = Mm + Ev - Ac - A3; /* sec 65 #9 */
+ Ec = 6.2886 * sin (dtor (Mmprime)); /* sec 65 #10 */
+ A4 = 0.214 * sin (dtor (2 * Mmprime)); /* sec 65 #11 */
+ lprime = l + Ev + Ec - Ac + A4; /* sec 65 #12 */
+ V = 0.6583 * sin (dtor (2 * (lprime - LambdaSol))); /* sec 65 #13 */
+ ldprime = lprime + V; /* sec 65 #14 */
+ D = ldprime - LambdaSol; /* sec 67 #2 */
+ return (50.0 * (1 - cos (dtor (D)))); /* sec 67 #3 */
}
/*
@@ -568,24 +571,24 @@ potm(double days)
*
*/
static double
-pom(time_t tmpt)
+pom (time_t tmpt)
{
- struct tm *GMT;
- double days;
- int cnt;
- pom_e pom;
-
- pom = NO_POM;
- GMT = gmtime(&tmpt);
- days = (GMT->tm_yday + 1) + ((GMT->tm_hour +
- (GMT->tm_min / 60.0) + (GMT->tm_sec / 3600.0)) / 24.0);
- for (cnt = EPOCH; cnt < GMT->tm_year; ++cnt)
- days += isleap(cnt + TM_YEAR_BASE) ? 366 : 365;
- /* Selected time could be before EPOCH */
- for (cnt = GMT->tm_year; cnt < EPOCH; ++cnt)
- days -= isleap(cnt + TM_YEAR_BASE) ? 366 : 365;
-
- return (potm(days));
+ struct tm *GMT;
+ double days;
+ int cnt;
+ pom_e pom;
+
+ pom = NO_POM;
+ GMT = gmtime (&tmpt);
+ days = (GMT->tm_yday + 1) + ((GMT->tm_hour + (GMT->tm_min / 60.0) +
+ (GMT->tm_sec / 3600.0)) / 24.0);
+ for (cnt = EPOCH; cnt < GMT->tm_year; ++cnt)
+ days += isleap (cnt + TM_YEAR_BASE) ? 366 : 365;
+ /* Selected time could be before EPOCH */
+ for (cnt = GMT->tm_year; cnt < EPOCH; ++cnt)
+ days -= isleap (cnt + TM_YEAR_BASE) ? 366 : 365;
+
+ return (potm (days));
}
/*
@@ -594,25 +597,24 @@ pom(time_t tmpt)
* the phase of the moon for previous day.
*/
char *
-calendar_get_pom(time_t date)
+calendar_get_pom (time_t date)
{
- char *pom_pict[MOON_PHASES] = {" ", "|) ", "(|)", "(| ", " | "};
- pom_e phase = NO_POM;
- double pom_today, relative_pom, pom_yesterday, pom_tomorrow;
- const double half = 50.0;
-
- pom_yesterday = pom(date);
- pom_today = pom(date + DAYINSEC);
- relative_pom = abs(pom_today - half);
- pom_tomorrow = pom(date + 2 * DAYINSEC);
- if (pom_today > pom_yesterday && pom_today > pom_tomorrow)
- phase = FULL_MOON;
- else if (pom_today < pom_yesterday && pom_today < pom_tomorrow)
- phase = NEW_MOON;
- else if (relative_pom < abs(pom_yesterday - half) &&
- relative_pom < abs(pom_tomorrow - half))
- phase = (pom_tomorrow > pom_today) ?
- FIRST_QUARTER : LAST_QUARTER;
-
- return (pom_pict[phase]);
+ char *pom_pict[MOON_PHASES] = { " ", "|) ", "(|)", "(| ", " | " };
+ pom_e phase = NO_POM;
+ double pom_today, relative_pom, pom_yesterday, pom_tomorrow;
+ const double half = 50.0;
+
+ pom_yesterday = pom (date);
+ pom_today = pom (date + DAYINSEC);
+ relative_pom = abs (pom_today - half);
+ pom_tomorrow = pom (date + 2 * DAYINSEC);
+ if (pom_today > pom_yesterday && pom_today > pom_tomorrow)
+ phase = FULL_MOON;
+ else if (pom_today < pom_yesterday && pom_today < pom_tomorrow)
+ phase = NEW_MOON;
+ else if (relative_pom < abs (pom_yesterday - half)
+ && relative_pom < abs (pom_tomorrow - half))
+ phase = (pom_tomorrow > pom_today) ? FIRST_QUARTER : LAST_QUARTER;
+
+ return (pom_pict[phase]);
}
diff --git a/src/calendar.h b/src/calendar.h
index 270ab97..3e1736d 100755
--- a/src/calendar.h
+++ b/src/calendar.h
@@ -1,4 +1,4 @@
-/* $calcurse: calendar.h,v 1.9 2008/04/09 20:38:29 culot Exp $ */
+/* $calcurse: calendar.h,v 1.10 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -34,53 +34,61 @@
#define CALHEIGHT 12
#define CALWIDTH 30
-typedef enum { /* days of week */
- SUNDAY,
- MONDAY,
- TUESDAY,
- WEDNESDAY,
- THURSDAY,
- FRIDAY,
- SATURDAY,
- WDAYS
-} wday_e;
+typedef enum
+{ /* days of week */
+ SUNDAY,
+ MONDAY,
+ TUESDAY,
+ WEDNESDAY,
+ THURSDAY,
+ FRIDAY,
+ SATURDAY,
+ WDAYS
+}
+wday_e;
-typedef struct {
- unsigned dd;
- unsigned mm;
- unsigned yyyy;
-} date_t;
+typedef struct
+{
+ unsigned dd;
+ unsigned mm;
+ unsigned yyyy;
+}
+date_t;
-typedef enum {
- NO_POM,
- FIRST_QUARTER,
- FULL_MOON,
- LAST_QUARTER,
- NEW_MOON,
- MOON_PHASES
-} pom_e;
+typedef enum
+{
+ NO_POM,
+ FIRST_QUARTER,
+ FULL_MOON,
+ LAST_QUARTER,
+ NEW_MOON,
+ MOON_PHASES
+}
+pom_e;
-typedef enum {
- UP,
- DOWN,
- LEFT,
- RIGHT,
- MOVES
-} move_t;
+typedef enum
+{
+ UP,
+ DOWN,
+ LEFT,
+ RIGHT,
+ MOVES
+}
+move_t;
-void calendar_start_date_thread(void);
-void calendar_stop_date_thread(void);
-void calendar_set_current_date(void);
-void calendar_set_first_day_of_week(wday_e);
-void calendar_change_first_day_of_week(void);
-bool calendar_week_begins_on_monday(void);
-void calendar_store_current_date(date_t *);
-void calendar_init_slctd_day(void);
-date_t *calendar_get_slctd_day(void);
-long calendar_get_slctd_day_sec(void);
-void calendar_update_panel(WINDOW *);
-void calendar_change_day(int datefmt);
-void calendar_move(move_t);
-char *calendar_get_pom(time_t);
+void calendar_start_date_thread (void);
+void calendar_stop_date_thread (void);
+void calendar_set_current_date (void);
+void calendar_set_first_day_of_week (wday_e);
+void calendar_change_first_day_of_week (void);
+bool calendar_week_begins_on_monday (void);
+void calendar_store_current_date (date_t *);
+void calendar_init_slctd_day (void);
+date_t *calendar_get_slctd_day (void);
+long calendar_get_slctd_day_sec (void);
+void calendar_update_panel (WINDOW *);
+void calendar_change_day (int);
+void calendar_move (move_t);
+char *calendar_get_pom (time_t);
#endif /* CALCURSE_CALENDAR_H */
diff --git a/src/custom.c b/src/custom.c
index ce77cde..b59ec4e 100755
--- a/src/custom.c
+++ b/src/custom.c
@@ -1,4 +1,4 @@
-/* $calcurse: custom.c,v 1.19 2008/04/09 20:38:29 culot Exp $ */
+/* $calcurse: custom.c,v 1.20 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -35,18 +35,19 @@
static struct attribute_s attr;
-static bool
-fill_config_var(char *string)
+static bool
+fill_config_var (char *string)
{
- if (strncmp(string, "yes", 3) == 0)
- return (true);
- else if (strncmp(string, "no", 2) == 0)
- return (false);
- else {
- fputs(_("FATAL ERROR in fill_config_var: "
- "wrong configuration variable format.\n"), stderr);
- return (EXIT_FAILURE);
- }
+ if (strncmp (string, "yes", 3) == 0)
+ return (true);
+ else if (strncmp (string, "no", 2) == 0)
+ return (false);
+ else
+ {
+ fputs (_("FATAL ERROR in fill_config_var: "
+ "wrong configuration variable format.\n"), stderr);
+ return (EXIT_FAILURE);
+ }
}
/*
@@ -55,103 +56,109 @@ fill_config_var(char *string)
* differently (number between 1 and 8).
*/
static void
-custom_load_color(char *color, int background)
+custom_load_color (char *color, int background)
{
#define AWAITED_COLORS 2
- int i, len, color_num;
- char c[AWAITED_COLORS][BUFSIZ];
- int colr[AWAITED_COLORS];
- const char *wrong_color_number =
- _("FATAL ERROR in custom_load_color: wrong color number.\n");
- const char *wrong_color_name =
- _("FATAL ERROR in custom_load_color: wrong color name.\n");
- const char *wrong_variable_format =
- _("FATAL ERROR in custom_load_color: "
- "wrong configuration variable format.\n");
-
- len = strlen(color);
-
- if (len > 1) {
- /* New version configuration */
- if (sscanf(color, "%s on %s", c[0], c[1]) != AWAITED_COLORS) {
- fputs(_("FATAL ERROR in custom_load_color: "
- "missing colors in config file.\n"), stderr);
- exit(EXIT_FAILURE);
- /* NOTREACHED */
- };
-
- for (i = 0; i < AWAITED_COLORS; i++) {
- if (!strncmp(c[i], "black", 5))
- colr[i] = COLOR_BLACK;
- else if (!strncmp(c[i], "red", 3))
- colr[i] = COLOR_RED;
- else if (!strncmp(c[i], "green", 5))
- colr[i] = COLOR_GREEN;
- else if (!strncmp(c[i], "yellow", 6))
- colr[i] = COLOR_YELLOW;
- else if (!strncmp(c[i], "blue", 4))
- colr[i] = COLOR_BLUE;
- else if (!strncmp(c[i], "magenta", 7))
- colr[i] = COLOR_MAGENTA;
- else if (!strncmp(c[i], "cyan", 4))
- colr[i] = COLOR_CYAN;
- else if (!strncmp(c[i], "white", 5))
- colr[i] = COLOR_WHITE;
- else if (!strncmp(c[i], "default", 7))
- colr[i] = background;
- else {
- fputs(wrong_color_name, stderr);
- exit(EXIT_FAILURE);
- /* NOTREACHED */
- }
- }
-
- init_pair(COLR_CUSTOM, colr[0], colr[1]);
-
- } else if (len > 0 && len < 2) {
- /* Old version configuration */
- color_num = atoi(color);
-
- switch (color_num) {
- case 0:
- colorize = false;
- break;
- case 1:
- init_pair(COLR_CUSTOM, COLOR_RED, background);
- break;
- case 2:
- init_pair(COLR_CUSTOM, COLOR_GREEN, background);
- break;
- case 3:
- init_pair(COLR_CUSTOM, COLOR_BLUE, background);
- break;
- case 4:
- init_pair(COLR_CUSTOM, COLOR_CYAN, background);
- break;
- case 5:
- init_pair(COLR_CUSTOM, COLOR_YELLOW, background);
- break;
- case 6:
- init_pair(COLR_CUSTOM, COLOR_BLACK, COLR_GREEN);
- break;
- case 7:
- init_pair(COLR_CUSTOM, COLOR_BLACK, COLR_YELLOW);
- break;
- case 8:
- init_pair(COLR_CUSTOM, COLOR_RED, COLR_BLUE);
- break;
- default:
- fputs(wrong_color_number, stderr);
- exit(EXIT_FAILURE);
- /* NOTREACHED */
- }
-
- } else {
- fputs(wrong_variable_format, stderr);
- exit(EXIT_FAILURE);
- /* NOTREACHED */
+ int i, len, color_num;
+ char c[AWAITED_COLORS][BUFSIZ];
+ int colr[AWAITED_COLORS];
+ const char *wrong_color_number =
+ _("FATAL ERROR in custom_load_color: wrong color number.\n");
+ const char *wrong_color_name =
+ _("FATAL ERROR in custom_load_color: wrong color name.\n");
+ const char *wrong_variable_format =
+ _("FATAL ERROR in custom_load_color: "
+ "wrong configuration variable format.\n");
+
+ len = strlen (color);
+
+ if (len > 1)
+ {
+ /* New version configuration */
+ if (sscanf (color, "%s on %s", c[0], c[1]) != AWAITED_COLORS)
+ {
+ fputs (_("FATAL ERROR in custom_load_color: "
+ "missing colors in config file.\n"), stderr);
+ exit (EXIT_FAILURE);
+ /* NOTREACHED */
+ };
+
+ for (i = 0; i < AWAITED_COLORS; i++)
+ {
+ if (!strncmp (c[i], "black", 5))
+ colr[i] = COLOR_BLACK;
+ else if (!strncmp (c[i], "red", 3))
+ colr[i] = COLOR_RED;
+ else if (!strncmp (c[i], "green", 5))
+ colr[i] = COLOR_GREEN;
+ else if (!strncmp (c[i], "yellow", 6))
+ colr[i] = COLOR_YELLOW;
+ else if (!strncmp (c[i], "blue", 4))
+ colr[i] = COLOR_BLUE;
+ else if (!strncmp (c[i], "magenta", 7))
+ colr[i] = COLOR_MAGENTA;
+ else if (!strncmp (c[i], "cyan", 4))
+ colr[i] = COLOR_CYAN;
+ else if (!strncmp (c[i], "white", 5))
+ colr[i] = COLOR_WHITE;
+ else if (!strncmp (c[i], "default", 7))
+ colr[i] = background;
+ else
+ {
+ fputs (wrong_color_name, stderr);
+ exit (EXIT_FAILURE);
+ /* NOTREACHED */
+ }
}
+ init_pair (COLR_CUSTOM, colr[0], colr[1]);
+ }
+ else if (len > 0 && len < 2)
+ {
+ /* Old version configuration */
+ color_num = atoi (color);
+
+ switch (color_num)
+ {
+ case 0:
+ colorize = false;
+ break;
+ case 1:
+ init_pair (COLR_CUSTOM, COLOR_RED, background);
+ break;
+ case 2:
+ init_pair (COLR_CUSTOM, COLOR_GREEN, background);
+ break;
+ case 3:
+ init_pair (COLR_CUSTOM, COLOR_BLUE, background);
+ break;
+ case 4:
+ init_pair (COLR_CUSTOM, COLOR_CYAN, background);
+ break;
+ case 5:
+ init_pair (COLR_CUSTOM, COLOR_YELLOW, background);
+ break;
+ case 6:
+ init_pair (COLR_CUSTOM, COLOR_BLACK, COLR_GREEN);
+ break;
+ case 7:
+ init_pair (COLR_CUSTOM, COLOR_BLACK, COLR_YELLOW);
+ break;
+ case 8:
+ init_pair (COLR_CUSTOM, COLOR_RED, COLR_BLUE);
+ break;
+ default:
+ fputs (wrong_color_number, stderr);
+ exit (EXIT_FAILURE);
+ /* NOTREACHED */
+ }
+ }
+ else
+ {
+ fputs (wrong_variable_format, stderr);
+ exit (EXIT_FAILURE);
+ /* NOTREACHED */
+ }
}
/*
@@ -162,233 +169,241 @@ custom_load_color(char *color, int background)
* ATTR_LOW are for days inside calendar panel which contains an event
* ATTR_LOWEST are for current day inside calendar panel
*/
-void
-custom_init_attr(void)
+void
+custom_init_attr (void)
{
- attr.color[ATTR_HIGHEST] = COLOR_PAIR(COLR_CUSTOM);
- attr.color[ATTR_HIGH] = COLOR_PAIR(COLR_HIGH);
- attr.color[ATTR_MIDDLE] = COLOR_PAIR(COLR_RED);
- attr.color[ATTR_LOW] = COLOR_PAIR(COLR_CYAN);
- attr.color[ATTR_LOWEST] = COLOR_PAIR(COLR_YELLOW);
- attr.color[ATTR_TRUE] = COLOR_PAIR(COLR_GREEN);
- attr.color[ATTR_FALSE] = COLOR_PAIR(COLR_RED);
-
- attr.nocolor[ATTR_HIGHEST] = A_BOLD;
- attr.nocolor[ATTR_HIGH] = A_REVERSE;
- attr.nocolor[ATTR_MIDDLE] = A_REVERSE;
- attr.nocolor[ATTR_LOW] = A_UNDERLINE;
- attr.nocolor[ATTR_LOWEST] = A_BOLD;
- attr.nocolor[ATTR_TRUE] = A_BOLD;
- attr.nocolor[ATTR_FALSE] = A_DIM;
+ attr.color[ATTR_HIGHEST] = COLOR_PAIR (COLR_CUSTOM);
+ attr.color[ATTR_HIGH] = COLOR_PAIR (COLR_HIGH);
+ attr.color[ATTR_MIDDLE] = COLOR_PAIR (COLR_RED);
+ attr.color[ATTR_LOW] = COLOR_PAIR (COLR_CYAN);
+ attr.color[ATTR_LOWEST] = COLOR_PAIR (COLR_YELLOW);
+ attr.color[ATTR_TRUE] = COLOR_PAIR (COLR_GREEN);
+ attr.color[ATTR_FALSE] = COLOR_PAIR (COLR_RED);
+
+ attr.nocolor[ATTR_HIGHEST] = A_BOLD;
+ attr.nocolor[ATTR_HIGH] = A_REVERSE;
+ attr.nocolor[ATTR_MIDDLE] = A_REVERSE;
+ attr.nocolor[ATTR_LOW] = A_UNDERLINE;
+ attr.nocolor[ATTR_LOWEST] = A_BOLD;
+ attr.nocolor[ATTR_TRUE] = A_BOLD;
+ attr.nocolor[ATTR_FALSE] = A_DIM;
}
/* Apply window attribute */
-void
-custom_apply_attr(WINDOW *win, int attr_num)
+void
+custom_apply_attr (WINDOW * win, int attr_num)
{
- if (colorize)
- wattron(win, attr.color[attr_num]);
- else
- wattron(win, attr.nocolor[attr_num]);
+ if (colorize)
+ wattron (win, attr.color[attr_num]);
+ else
+ wattron (win, attr.nocolor[attr_num]);
}
/* Remove window attribute */
-void
-custom_remove_attr(WINDOW *win, int attr_num)
+void
+custom_remove_attr (WINDOW * win, int attr_num)
{
- if (colorize)
- wattroff(win, attr.color[attr_num]);
- else
- wattroff(win, attr.nocolor[attr_num]);
+ if (colorize)
+ wattroff (win, attr.color[attr_num]);
+ else
+ wattroff (win, attr.nocolor[attr_num]);
}
/* Load the user configuration. */
-void
-custom_load_conf(conf_t *conf, int background)
+void
+custom_load_conf (conf_t * conf, int background)
{
- FILE *data_file;
- char *mesg_line1 = _("Failed to open config file");
- char *mesg_line2 = _("Press [ENTER] to continue");
- char buf[100], e_conf[100];
- int var;
-
- data_file = fopen(path_conf, "r");
- if (data_file == NULL) {
- status_mesg(mesg_line1, mesg_line2);
- wnoutrefresh(win[STA].p);
- doupdate();
- wgetch(win[STA].p);
+ FILE *data_file;
+ char *mesg_line1 = _("Failed to open config file");
+ char *mesg_line2 = _("Press [ENTER] to continue");
+ char buf[100], e_conf[100];
+ int var;
+
+ data_file = fopen (path_conf, "r");
+ if (data_file == NULL)
+ {
+ status_mesg (mesg_line1, mesg_line2);
+ wnoutrefresh (win[STA].p);
+ doupdate ();
+ wgetch (win[STA].p);
+ }
+ var = 0;
+ pthread_mutex_lock (&nbar->mutex);
+ for (;;)
+ {
+ if (fgets (buf, 99, data_file) == NULL)
+ {
+ break;
}
- var = 0;
- pthread_mutex_lock(&nbar->mutex);
- for (;;) {
- if (fgets(buf, 99, data_file) == NULL) {
- break;
- }
- io_extract_data(e_conf, buf, strlen(buf));
-
- switch (var) {
- case CUSTOM_CONF_NOVARIABLE:
- break;
- case CUSTOM_CONF_AUTOSAVE:
- conf->auto_save = fill_config_var(e_conf);
- var = 0;
- break;
- case CUSTOM_CONF_CONFIRMQUIT:
- conf->confirm_quit = fill_config_var(e_conf);
- var = 0;
- break;
- case CUSTOM_CONF_CONFIRMDELETE:
- conf->confirm_delete = fill_config_var(e_conf);
- var = 0;
- break;
- case CUSTOM_CONF_SKIPSYSTEMDIALOGS:
- conf->skip_system_dialogs = fill_config_var(e_conf);
- var = 0;
- break;
- case CUSTOM_CONF_SKIPPROGRESSBAR:
- conf->skip_progress_bar = fill_config_var(e_conf);
- var = 0;
- break;
- case CUSTOM_CONF_WEEKBEGINSONMONDAY:
- if (fill_config_var(e_conf))
- calendar_set_first_day_of_week(MONDAY);
- else
- calendar_set_first_day_of_week(SUNDAY);
- var = 0;
- break;
- case CUSTOM_CONF_COLORTHEME:
- custom_load_color(e_conf, background);
- var = 0;
- break;
- case CUSTOM_CONF_LAYOUT:
- wins_set_layout(atoi(e_conf));
- var = 0;
- break;
- case CUSTOM_CONF_NOTIFYBARSHOW:
- nbar->show = fill_config_var(e_conf);
- var = 0;
- break;
- case CUSTOM_CONF_NOTIFYBARDATE:
- strncpy(nbar->datefmt, e_conf, strlen(e_conf) + 1);
- var = 0;
- break;
- case CUSTOM_CONF_NOTIFYBARCLOCK:
- strncpy(nbar->timefmt, e_conf, strlen(e_conf) + 1);
- var = 0;
- break;
- case CUSTOM_CONF_NOTIFYBARWARNING:
- nbar->cntdwn = atoi(e_conf);
- var = 0;
- break;
- case CUSTOM_CONF_NOTIFYBARCOMMAND:
- strncpy(nbar->cmd, e_conf, strlen(e_conf) + 1);
- var = 0;
- break;
- case CUSTOM_CONF_OUTPUTDATEFMT:
- if (e_conf[0] != '\0')
- strncpy(conf->output_datefmt, e_conf, strlen(e_conf) + 1);
- var = 0;
- break;
- case CUSTOM_CONF_INPUTDATEFMT:
- conf->input_datefmt = atoi(e_conf);
- if (conf->input_datefmt < 1 || conf->input_datefmt > 3)
- conf->input_datefmt = 1;
- var = 0;
- break;
- default:
- fputs(_("FATAL ERROR in custom_load_conf: "
- "configuration variable unknown.\n"), stderr);
- exit(EXIT_FAILURE);
- /* NOTREACHED */
- }
-
- if (strncmp(e_conf, "auto_save=", 10) == 0)
- var = CUSTOM_CONF_AUTOSAVE;
- else if (strncmp(e_conf, "confirm_quit=", 13) == 0)
- var = CUSTOM_CONF_CONFIRMQUIT;
- else if (strncmp(e_conf, "confirm_delete=", 15) == 0)
- var = CUSTOM_CONF_CONFIRMDELETE;
- else if (strncmp(e_conf, "skip_system_dialogs=", 20) == 0)
- var = CUSTOM_CONF_SKIPSYSTEMDIALOGS;
- else if (strncmp(e_conf, "skip_progress_bar=", 18) == 0)
- var = CUSTOM_CONF_SKIPPROGRESSBAR;
- else if (strncmp(e_conf, "week_begins_on_monday=", 23) == 0)
- var = CUSTOM_CONF_WEEKBEGINSONMONDAY;
- else if (strncmp(e_conf, "color-theme=", 12) == 0)
- var = CUSTOM_CONF_COLORTHEME;
- else if (strncmp(e_conf, "layout=", 7) == 0)
- var = CUSTOM_CONF_LAYOUT;
- else if (strncmp(e_conf, "notify-bar_show=", 16) ==0)
- var = CUSTOM_CONF_NOTIFYBARSHOW;
- else if (strncmp(e_conf, "notify-bar_date=", 16) ==0)
- var = CUSTOM_CONF_NOTIFYBARDATE;
- else if (strncmp(e_conf, "notify-bar_clock=", 17) ==0)
- var = CUSTOM_CONF_NOTIFYBARCLOCK;
- else if (strncmp(e_conf, "notify-bar_warning=", 19) ==0)
- var = CUSTOM_CONF_NOTIFYBARWARNING;
- else if (strncmp(e_conf, "notify-bar_command=", 19) ==0)
- var = CUSTOM_CONF_NOTIFYBARCOMMAND;
- else if (strncmp(e_conf, "output_datefmt=", 12) ==0)
- var = CUSTOM_CONF_OUTPUTDATEFMT;
- else if (strncmp(e_conf, "input_datefmt=", 12) ==0)
- var = CUSTOM_CONF_INPUTDATEFMT;
+ io_extract_data (e_conf, buf, strlen (buf));
+
+ switch (var)
+ {
+ case CUSTOM_CONF_NOVARIABLE:
+ break;
+ case CUSTOM_CONF_AUTOSAVE:
+ conf->auto_save = fill_config_var (e_conf);
+ var = 0;
+ break;
+ case CUSTOM_CONF_CONFIRMQUIT:
+ conf->confirm_quit = fill_config_var (e_conf);
+ var = 0;
+ break;
+ case CUSTOM_CONF_CONFIRMDELETE:
+ conf->confirm_delete = fill_config_var (e_conf);
+ var = 0;
+ break;
+ case CUSTOM_CONF_SKIPSYSTEMDIALOGS:
+ conf->skip_system_dialogs = fill_config_var (e_conf);
+ var = 0;
+ break;
+ case CUSTOM_CONF_SKIPPROGRESSBAR:
+ conf->skip_progress_bar = fill_config_var (e_conf);
+ var = 0;
+ break;
+ case CUSTOM_CONF_WEEKBEGINSONMONDAY:
+ if (fill_config_var (e_conf))
+ calendar_set_first_day_of_week (MONDAY);
+ else
+ calendar_set_first_day_of_week (SUNDAY);
+ var = 0;
+ break;
+ case CUSTOM_CONF_COLORTHEME:
+ custom_load_color (e_conf, background);
+ var = 0;
+ break;
+ case CUSTOM_CONF_LAYOUT:
+ wins_set_layout (atoi (e_conf));
+ var = 0;
+ break;
+ case CUSTOM_CONF_NOTIFYBARSHOW:
+ nbar->show = fill_config_var (e_conf);
+ var = 0;
+ break;
+ case CUSTOM_CONF_NOTIFYBARDATE:
+ strncpy (nbar->datefmt, e_conf, strlen (e_conf) + 1);
+ var = 0;
+ break;
+ case CUSTOM_CONF_NOTIFYBARCLOCK:
+ strncpy (nbar->timefmt, e_conf, strlen (e_conf) + 1);
+ var = 0;
+ break;
+ case CUSTOM_CONF_NOTIFYBARWARNING:
+ nbar->cntdwn = atoi (e_conf);
+ var = 0;
+ break;
+ case CUSTOM_CONF_NOTIFYBARCOMMAND:
+ strncpy (nbar->cmd, e_conf, strlen (e_conf) + 1);
+ var = 0;
+ break;
+ case CUSTOM_CONF_OUTPUTDATEFMT:
+ if (e_conf[0] != '\0')
+ strncpy (conf->output_datefmt, e_conf, strlen (e_conf) + 1);
+ var = 0;
+ break;
+ case CUSTOM_CONF_INPUTDATEFMT:
+ conf->input_datefmt = atoi (e_conf);
+ if (conf->input_datefmt < 1 || conf->input_datefmt > 3)
+ conf->input_datefmt = 1;
+ var = 0;
+ break;
+ default:
+ fputs (_("FATAL ERROR in custom_load_conf: "
+ "configuration variable unknown.\n"), stderr);
+ exit (EXIT_FAILURE);
+ /* NOTREACHED */
}
- fclose(data_file);
- pthread_mutex_unlock(&nbar->mutex);
+
+ if (strncmp (e_conf, "auto_save=", 10) == 0)
+ var = CUSTOM_CONF_AUTOSAVE;
+ else if (strncmp (e_conf, "confirm_quit=", 13) == 0)
+ var = CUSTOM_CONF_CONFIRMQUIT;
+ else if (strncmp (e_conf, "confirm_delete=", 15) == 0)
+ var = CUSTOM_CONF_CONFIRMDELETE;
+ else if (strncmp (e_conf, "skip_system_dialogs=", 20) == 0)
+ var = CUSTOM_CONF_SKIPSYSTEMDIALOGS;
+ else if (strncmp (e_conf, "skip_progress_bar=", 18) == 0)
+ var = CUSTOM_CONF_SKIPPROGRESSBAR;
+ else if (strncmp (e_conf, "week_begins_on_monday=", 23) == 0)
+ var = CUSTOM_CONF_WEEKBEGINSONMONDAY;
+ else if (strncmp (e_conf, "color-theme=", 12) == 0)
+ var = CUSTOM_CONF_COLORTHEME;
+ else if (strncmp (e_conf, "layout=", 7) == 0)
+ var = CUSTOM_CONF_LAYOUT;
+ else if (strncmp (e_conf, "notify-bar_show=", 16) == 0)
+ var = CUSTOM_CONF_NOTIFYBARSHOW;
+ else if (strncmp (e_conf, "notify-bar_date=", 16) == 0)
+ var = CUSTOM_CONF_NOTIFYBARDATE;
+ else if (strncmp (e_conf, "notify-bar_clock=", 17) == 0)
+ var = CUSTOM_CONF_NOTIFYBARCLOCK;
+ else if (strncmp (e_conf, "notify-bar_warning=", 19) == 0)
+ var = CUSTOM_CONF_NOTIFYBARWARNING;
+ else if (strncmp (e_conf, "notify-bar_command=", 19) == 0)
+ var = CUSTOM_CONF_NOTIFYBARCOMMAND;
+ else if (strncmp (e_conf, "output_datefmt=", 12) == 0)
+ var = CUSTOM_CONF_OUTPUTDATEFMT;
+ else if (strncmp (e_conf, "input_datefmt=", 12) == 0)
+ var = CUSTOM_CONF_INPUTDATEFMT;
+ }
+ fclose (data_file);
+ pthread_mutex_unlock (&nbar->mutex);
}
/* Draws the configuration bar */
-void
-config_bar(void)
+void
+config_bar (void)
{
- int smlspc, spc;
-
- smlspc = 2;
- spc = 15;
-
- custom_apply_attr(win[STA].p, ATTR_HIGHEST);
- mvwprintw(win[STA].p, 0, 2, "Q");
- mvwprintw(win[STA].p, 1, 2, "G");
- mvwprintw(win[STA].p, 0, 2 + spc, "L");
- mvwprintw(win[STA].p, 1, 2 + spc, "C");
- mvwprintw(win[STA].p, 0, 2 + 2*spc, "N");
- custom_remove_attr(win[STA].p, ATTR_HIGHEST);
-
- mvwprintw(win[STA].p, 0, 2 + smlspc, _("Exit"));
- mvwprintw(win[STA].p, 1, 2 + smlspc, _("General"));
- mvwprintw(win[STA].p, 0, 2 + spc + smlspc, _("Layout"));
- mvwprintw(win[STA].p, 1, 2 + spc + smlspc, _("Color"));
- mvwprintw(win[STA].p, 0, 2 + 2*spc + smlspc, _("Notify"));
-
- wnoutrefresh(win[STA].p);
- wmove(win[STA].p, 0, 0);
- doupdate();
+ int smlspc, spc;
+
+ smlspc = 2;
+ spc = 15;
+
+ custom_apply_attr (win[STA].p, ATTR_HIGHEST);
+ mvwprintw (win[STA].p, 0, 2, "Q");
+ mvwprintw (win[STA].p, 1, 2, "G");
+ mvwprintw (win[STA].p, 0, 2 + spc, "L");
+ mvwprintw (win[STA].p, 1, 2 + spc, "C");
+ mvwprintw (win[STA].p, 0, 2 + 2 * spc, "N");
+ custom_remove_attr (win[STA].p, ATTR_HIGHEST);
+
+ mvwprintw (win[STA].p, 0, 2 + smlspc, _("Exit"));
+ mvwprintw (win[STA].p, 1, 2 + smlspc, _("General"));
+ mvwprintw (win[STA].p, 0, 2 + spc + smlspc, _("Layout"));
+ mvwprintw (win[STA].p, 1, 2 + spc + smlspc, _("Color"));
+ mvwprintw (win[STA].p, 0, 2 + 2 * spc + smlspc, _("Notify"));
+
+ wnoutrefresh (win[STA].p);
+ wmove (win[STA].p, 0, 0);
+ doupdate ();
}
/* Choose the layout */
-void
-layout_config(void)
+void
+layout_config (void)
{
- int ch;
- char *layout_mesg = _("Pick the desired layout on next screen [press ENTER]");
- char *choice_mesg = _("('A'= Appointment panel, 'C'= calendar panel, 'T'= todo panel)");
- char *layout_up_mesg =
- _(" AC AT CA TA TC TA CT AT");
- char *layout_down_mesg =
- _(" [1]AT [2]AC [3]TA [4]CA [5]TA [6]TC [7]AT [8]CT");
-
- status_mesg(layout_mesg, choice_mesg);
- wgetch(win[STA].p);
- status_mesg(layout_up_mesg, layout_down_mesg);
- wnoutrefresh(win[STA].p);
- doupdate();
- while ((ch = wgetch(win[STA].p)) != 'q') {
- if ( ch <= '8' && ch >= '1' ) {
- wins_set_layout(ch - '0');
- return;
- }
+ int ch;
+ char *layout_mesg =
+ _("Pick the desired layout on next screen [press ENTER]");
+ char *choice_mesg =
+ _("('A'= Appointment panel, 'C'= calendar panel, 'T'= todo panel)");
+ char *layout_up_mesg =
+ _(" AC AT CA TA TC TA CT AT");
+ char *layout_down_mesg =
+ _(" [1]AT [2]AC [3]TA [4]CA [5]TA [6]TC [7]AT [8]CT");
+
+ status_mesg (layout_mesg, choice_mesg);
+ wgetch (win[STA].p);
+ status_mesg (layout_up_mesg, layout_down_mesg);
+ wnoutrefresh (win[STA].p);
+ doupdate ();
+ while ((ch = wgetch (win[STA].p)) != 'q')
+ {
+ if (ch <= '8' && ch >= '1')
+ {
+ wins_set_layout (ch - '0');
+ return;
}
+ }
}
/*
@@ -396,22 +411,21 @@ layout_config(void)
* (useful in case of window resize).
*/
void
-custom_confwin_init(window_t *confwin, char *label)
+custom_confwin_init (window_t *confwin, char *label)
{
- wins_get_config();
- confwin->h = (notify_bar()) ? row - 3 : row - 2;
- confwin->p = newwin(confwin->h, col, 0, 0);
- box(confwin->p, 0, 0);
- wins_show(confwin->p, label);
- delwin(win[STA].p);
- win[STA].p = newwin(win[STA].h, win[STA].w, win[STA].y,
- win[STA].x);
- keypad(win[STA].p, TRUE);
- if (notify_bar()) {
- notify_reinit_bar(win[NOT].h, win[NOT].w,
- win[NOT].y, win[NOT].x);
- notify_update_bar();
- }
+ wins_get_config ();
+ confwin->h = (notify_bar ())? row - 3 : row - 2;
+ confwin->p = newwin (confwin->h, col, 0, 0);
+ box (confwin->p, 0, 0);
+ wins_show (confwin->p, label);
+ delwin (win[STA].p);
+ win[STA].p = newwin (win[STA].h, win[STA].w, win[STA].y, win[STA].x);
+ keypad (win[STA].p, TRUE);
+ if (notify_bar ())
+ {
+ notify_reinit_bar (win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x);
+ notify_update_bar ();
+ }
}
/*
@@ -419,8 +433,8 @@ custom_confwin_init(window_t *confwin, char *label)
* This is useful for window resizing.
*/
static void
-display_color_config(window_t *cwin, int *mark_fore, int *mark_back,
- int cursor, int need_reset, int theme_changed)
+display_color_config (window_t *cwin, int *mark_fore, int *mark_back,
+ int cursor, int need_reset, int theme_changed)
{
#define SIZE (2 * (NBUSERCOLORS + 1))
#define DEFAULTCOLOR 255
@@ -429,201 +443,207 @@ display_color_config(window_t *cwin, int *mark_fore, int *mark_back,
#define SPACE 32
#define MARK 88
- char *fore_txt = _("Foreground");
- char *back_txt = _("Background");
- char *default_txt = _("(terminal's default)");
- char *bar = " ";
- char *box = "[ ]";
- char *choose_color_1 = _("Use 'X' or SPACE to select a color, "
- "'H/L' 'J/K' or arrow keys to move");
- char *choose_color_2 = _("('0' for no color, 'Q' to exit) :");
- char label[BUFSIZ];
- const unsigned Y = 3;
- const unsigned XOFST = 5;
- const unsigned YSPC = (row - 8) / (NBUSERCOLORS + 1);
- const unsigned BARSIZ = strlen(bar);
- const unsigned BOXSIZ = strlen(box);
- const unsigned XSPC = (col - 2 * BARSIZ - 2 * BOXSIZ - 6) / 3;
- const unsigned XFORE = XSPC;
- const unsigned XBACK = 2 * XSPC + BOXSIZ + XOFST + BARSIZ;
- enum {YPOS, XPOS, NBPOS};
- unsigned i;
- int pos[SIZE][NBPOS];
- short colr_fore, colr_back;
- int colr[SIZE] = {
- COLR_RED, COLR_GREEN, COLR_YELLOW, COLR_BLUE,
- COLR_MAGENTA, COLR_CYAN, COLR_DEFAULT,
- COLR_RED, COLR_GREEN, COLR_YELLOW, COLR_BLUE,
- COLR_MAGENTA, COLR_CYAN, COLR_DEFAULT
- };
-
- for (i = 0; i < NBUSERCOLORS + 1; i++) {
- pos[i][YPOS] = Y + YSPC * (i + 1);
- pos[NBUSERCOLORS + i + 1][YPOS] = Y + YSPC * (i + 1);
- pos[i][XPOS] = XFORE;
- pos[NBUSERCOLORS + i + 1][XPOS] = XBACK;
- }
-
- if (need_reset) {
- if (cwin->p != NULL)
- delwin(cwin->p);
- snprintf(label, BUFSIZ, _("CalCurse %s | color theme"),
- VERSION);
- custom_confwin_init(cwin, label);
- }
-
- if (colorize) {
- if (theme_changed) {
- pair_content(colr[*mark_fore], &colr_fore, 0L);
- if (colr_fore == 255)
- colr_fore = -1;
- pair_content(colr[*mark_back], &colr_back, 0L);
- if (colr_back == 255)
- colr_back = -1;
- init_pair(COLR_CUSTOM, colr_fore, colr_back);
- } else {
- /* Retrieve the actual color theme. */
- pair_content(COLR_CUSTOM, &colr_fore, &colr_back);
-
- if ((colr_fore == DEFAULTCOLOR) ||
- (colr_fore == DEFAULTCOLOR_EXT))
- *mark_fore = NBUSERCOLORS;
- else
- for (i = 0; i < NBUSERCOLORS + 1; i++)
- if (colr_fore == colr[i])
- *mark_fore = i;
-
- if ((colr_back == DEFAULTCOLOR) ||
- (colr_back == DEFAULTCOLOR_EXT))
- *mark_back = SIZE - 1;
- else
- for (i = 0; i < NBUSERCOLORS + 1; i++)
- if (colr_back ==
- colr[NBUSERCOLORS + 1 + i])
- *mark_back =
- NBUSERCOLORS + 1 + i;
- }
+ char *fore_txt = _("Foreground");
+ char *back_txt = _("Background");
+ char *default_txt = _("(terminal's default)");
+ char *bar = " ";
+ char *box = "[ ]";
+ char *choose_color_1 = _("Use 'X' or SPACE to select a color, "
+ "'H/L' 'J/K' or arrow keys to move");
+ char *choose_color_2 = _("('0' for no color, 'Q' to exit) :");
+ char label[BUFSIZ];
+ const unsigned Y = 3;
+ const unsigned XOFST = 5;
+ const unsigned YSPC = (row - 8) / (NBUSERCOLORS + 1);
+ const unsigned BARSIZ = strlen (bar);
+ const unsigned BOXSIZ = strlen (box);
+ const unsigned XSPC = (col - 2 * BARSIZ - 2 * BOXSIZ - 6) / 3;
+ const unsigned XFORE = XSPC;
+ const unsigned XBACK = 2 * XSPC + BOXSIZ + XOFST + BARSIZ;
+ enum
+ { YPOS, XPOS, NBPOS };
+ unsigned i;
+ int pos[SIZE][NBPOS];
+ short colr_fore, colr_back;
+ int colr[SIZE] = {
+ COLR_RED, COLR_GREEN, COLR_YELLOW, COLR_BLUE,
+ COLR_MAGENTA, COLR_CYAN, COLR_DEFAULT,
+ COLR_RED, COLR_GREEN, COLR_YELLOW, COLR_BLUE,
+ COLR_MAGENTA, COLR_CYAN, COLR_DEFAULT
+ };
+
+ for (i = 0; i < NBUSERCOLORS + 1; i++)
+ {
+ pos[i][YPOS] = Y + YSPC * (i + 1);
+ pos[NBUSERCOLORS + i + 1][YPOS] = Y + YSPC * (i + 1);
+ pos[i][XPOS] = XFORE;
+ pos[NBUSERCOLORS + i + 1][XPOS] = XBACK;
+ }
+
+ if (need_reset)
+ {
+ if (cwin->p != NULL)
+ delwin (cwin->p);
+ snprintf (label, BUFSIZ, _("CalCurse %s | color theme"), VERSION);
+ custom_confwin_init (cwin, label);
+ }
+
+ if (colorize)
+ {
+ if (theme_changed)
+ {
+ pair_content (colr[*mark_fore], &colr_fore, 0L);
+ if (colr_fore == 255)
+ colr_fore = -1;
+ pair_content (colr[*mark_back], &colr_back, 0L);
+ if (colr_back == 255)
+ colr_back = -1;
+ init_pair (COLR_CUSTOM, colr_fore, colr_back);
}
-
- /* color boxes */
- for (i = 0; i < SIZE - 1; i++) {
- mvwprintw(cwin->p, pos[i][YPOS], pos[i][XPOS], box);
- wattron(cwin->p, COLOR_PAIR(colr[i]) | A_REVERSE);
- mvwprintw(cwin->p, pos[i][YPOS], pos[i][XPOS] + XOFST, bar);
- wattroff(cwin->p, COLOR_PAIR(colr[i]) | A_REVERSE);
- }
-
- /* Terminal's default color */
- i = SIZE - 1;
- mvwprintw(cwin->p, pos[i][YPOS], pos[i][XPOS], box);
- wattron(cwin->p, COLOR_PAIR(colr[i]));
- mvwprintw(cwin->p, pos[i][YPOS], pos[i][XPOS] + XOFST, bar);
- wattroff(cwin->p, COLOR_PAIR(colr[i]));
- mvwprintw(cwin->p, pos[NBUSERCOLORS][YPOS] + 1,
- pos[NBUSERCOLORS][XPOS] + XOFST, default_txt);
- mvwprintw(cwin->p, pos[SIZE - 1][YPOS] + 1,
- pos[SIZE - 1][XPOS] + XOFST, default_txt);
-
- custom_apply_attr(cwin->p, ATTR_HIGHEST);
- mvwprintw(cwin->p, Y, XFORE + XOFST, fore_txt);
- mvwprintw(cwin->p, Y, XBACK + XOFST, back_txt);
- custom_remove_attr(cwin->p, ATTR_HIGHEST);
-
- if (colorize) {
- mvwaddch(cwin->p, pos[*mark_fore][YPOS],
- pos[*mark_fore][XPOS] + 1, MARK);
- mvwaddch(cwin->p, pos[*mark_back][YPOS],
- pos[*mark_back][XPOS] + 1, MARK);
+ else
+ {
+ /* Retrieve the actual color theme. */
+ pair_content (COLR_CUSTOM, &colr_fore, &colr_back);
+
+ if ((colr_fore == DEFAULTCOLOR) || (colr_fore == DEFAULTCOLOR_EXT))
+ *mark_fore = NBUSERCOLORS;
+ else
+ for (i = 0; i < NBUSERCOLORS + 1; i++)
+ if (colr_fore == colr[i])
+ *mark_fore = i;
+
+ if ((colr_back == DEFAULTCOLOR) || (colr_back == DEFAULTCOLOR_EXT))
+ *mark_back = SIZE - 1;
+ else
+ for (i = 0; i < NBUSERCOLORS + 1; i++)
+ if (colr_back == colr[NBUSERCOLORS + 1 + i])
+ *mark_back = NBUSERCOLORS + 1 + i;
}
-
- mvwaddch(cwin->p, pos[cursor][YPOS], pos[cursor][XPOS] + 1, CURSOR);
- status_mesg(choose_color_1, choose_color_2);
- wnoutrefresh(win[STA].p);
- wnoutrefresh(cwin->p);
- doupdate();
- if (notify_bar())
- notify_update_bar();
+ }
+
+ /* color boxes */
+ for (i = 0; i < SIZE - 1; i++)
+ {
+ mvwprintw (cwin->p, pos[i][YPOS], pos[i][XPOS], box);
+ wattron (cwin->p, COLOR_PAIR (colr[i]) | A_REVERSE);
+ mvwprintw (cwin->p, pos[i][YPOS], pos[i][XPOS] + XOFST, bar);
+ wattroff (cwin->p, COLOR_PAIR (colr[i]) | A_REVERSE);
+ }
+
+ /* Terminal's default color */
+ i = SIZE - 1;
+ mvwprintw (cwin->p, pos[i][YPOS], pos[i][XPOS], box);
+ wattron (cwin->p, COLOR_PAIR (colr[i]));
+ mvwprintw (cwin->p, pos[i][YPOS], pos[i][XPOS] + XOFST, bar);
+ wattroff (cwin->p, COLOR_PAIR (colr[i]));
+ mvwprintw (cwin->p, pos[NBUSERCOLORS][YPOS] + 1,
+ pos[NBUSERCOLORS][XPOS] + XOFST, default_txt);
+ mvwprintw (cwin->p, pos[SIZE - 1][YPOS] + 1,
+ pos[SIZE - 1][XPOS] + XOFST, default_txt);
+
+ custom_apply_attr (cwin->p, ATTR_HIGHEST);
+ mvwprintw (cwin->p, Y, XFORE + XOFST, fore_txt);
+ mvwprintw (cwin->p, Y, XBACK + XOFST, back_txt);
+ custom_remove_attr (cwin->p, ATTR_HIGHEST);
+
+ if (colorize)
+ {
+ mvwaddch (cwin->p, pos[*mark_fore][YPOS],
+ pos[*mark_fore][XPOS] + 1, MARK);
+ mvwaddch (cwin->p, pos[*mark_back][YPOS],
+ pos[*mark_back][XPOS] + 1, MARK);
+ }
+
+ mvwaddch (cwin->p, pos[cursor][YPOS], pos[cursor][XPOS] + 1, CURSOR);
+ status_mesg (choose_color_1, choose_color_2);
+ wnoutrefresh (win[STA].p);
+ wnoutrefresh (cwin->p);
+ doupdate ();
+ if (notify_bar ())
+ notify_update_bar ();
}
/* Color theme configuration. */
void
-custom_color_config(void)
+custom_color_config (void)
{
- window_t conf_win;
- int ch, cursor, need_reset, theme_changed;
- int mark_fore, mark_back;
-
- mark_fore = NBUSERCOLORS;
- mark_back = SIZE - 1;
- clear();
- cursor = 0;
- need_reset = 1;
- theme_changed = 0;
- conf_win.p = NULL;
- display_color_config(&conf_win, &mark_fore, &mark_back, cursor,
- need_reset, theme_changed);
-
- while ((ch = wgetch(win[STA].p)) != 'q') {
- need_reset = 0;
- theme_changed = 0;
-
- switch (ch) {
- case KEY_RESIZE:
- endwin();
- refresh();
- curs_set(0);
- need_reset = 1;
- break;
-
- case SPACE:
- case 'X':
- case 'x':
- colorize = true;
- need_reset = 1;
- theme_changed = 1;
- if (cursor > NBUSERCOLORS)
- mark_back = cursor;
- else
- mark_fore = cursor;
- break;
-
- case 258:
- case 'J':
- case 'j':
- if (cursor < SIZE - 1)
- ++cursor;
- break;
-
- case 259:
- case 'K':
- case 'k':
- if (cursor > 0)
- --cursor;
- break;
-
- case 260:
- case 'H':
- case 'h':
- if (cursor > NBUSERCOLORS)
- cursor -= (NBUSERCOLORS + 1);
- break;
-
- case 261:
- case 'L':
- case 'l':
- if (cursor <= NBUSERCOLORS)
- cursor += (NBUSERCOLORS + 1);
- break;
-
- case '0':
- colorize = false;
- need_reset = 1;
- break;
- }
- display_color_config(&conf_win, &mark_fore, &mark_back, cursor,
- need_reset, theme_changed);
+ window_t conf_win;
+ int ch, cursor, need_reset, theme_changed;
+ int mark_fore, mark_back;
+
+ mark_fore = NBUSERCOLORS;
+ mark_back = SIZE - 1;
+ clear ();
+ cursor = 0;
+ need_reset = 1;
+ theme_changed = 0;
+ conf_win.p = NULL;
+ display_color_config (&conf_win, &mark_fore, &mark_back, cursor,
+ need_reset, theme_changed);
+
+ while ((ch = wgetch (win[STA].p)) != 'q')
+ {
+ need_reset = 0;
+ theme_changed = 0;
+
+ switch (ch)
+ {
+ case KEY_RESIZE:
+ endwin ();
+ refresh ();
+ curs_set (0);
+ need_reset = 1;
+ break;
+
+ case SPACE:
+ case 'X':
+ case 'x':
+ colorize = true;
+ need_reset = 1;
+ theme_changed = 1;
+ if (cursor > NBUSERCOLORS)
+ mark_back = cursor;
+ else
+ mark_fore = cursor;
+ break;
+
+ case 258:
+ case 'J':
+ case 'j':
+ if (cursor < SIZE - 1)
+ ++cursor;
+ break;
+
+ case 259:
+ case 'K':
+ case 'k':
+ if (cursor > 0)
+ --cursor;
+ break;
+
+ case 260:
+ case 'H':
+ case 'h':
+ if (cursor > NBUSERCOLORS)
+ cursor -= (NBUSERCOLORS + 1);
+ break;
+
+ case 261:
+ case 'L':
+ case 'l':
+ if (cursor <= NBUSERCOLORS)
+ cursor += (NBUSERCOLORS + 1);
+ break;
+
+ case '0':
+ colorize = false;
+ need_reset = 1;
+ break;
}
- delwin(conf_win.p);
+ display_color_config (&conf_win, &mark_fore, &mark_back, cursor,
+ need_reset, theme_changed);
+ }
+ delwin (conf_win.p);
}
/*
@@ -635,201 +655,214 @@ custom_color_config(void)
* then default color is -1.
*/
void
-custom_color_theme_name(char *theme_name)
+custom_color_theme_name (char *theme_name)
{
#define MAXCOLORS 8
#define NBCOLORS 2
#define DEFAULTCOLOR 255
#define DEFAULTCOLOR_EXT -1
- int i;
- short color[NBCOLORS];
- char *color_name[NBCOLORS];
- char *default_color = "default";
- char *name[MAXCOLORS] = {
- "black",
- "red",
- "green",
- "yellow",
- "blue",
- "magenta",
- "cyan",
- "white"};
- const char *error_txt =
- _("FATAL ERROR in custom_color_theme_name: unknown color\n");
-
- if (!colorize)
- snprintf(theme_name, BUFSIZ, "0");
- else {
- pair_content(COLR_CUSTOM, &color[0], &color[1]);
- for (i = 0; i < NBCOLORS; i++) {
- if ((color[i] == DEFAULTCOLOR) ||
- (color[i] == DEFAULTCOLOR_EXT))
- color_name[i] = default_color;
- else if (color[i] >= 0 && color[i] <= MAXCOLORS)
- color_name[i] = name[color[i]];
- else {
- fputs(error_txt, stderr);
- exit(EXIT_FAILURE);
- /* NOTREACHED */
- }
- }
- snprintf(theme_name, BUFSIZ, "%s on %s", color_name[0],
- color_name[1]);
+ int i;
+ short color[NBCOLORS];
+ char *color_name[NBCOLORS];
+ char *default_color = "default";
+ char *name[MAXCOLORS] = {
+ "black",
+ "red",
+ "green",
+ "yellow",
+ "blue",
+ "magenta",
+ "cyan",
+ "white"
+ };
+ const char *error_txt =
+ _("FATAL ERROR in custom_color_theme_name: unknown color\n");
+
+ if (!colorize)
+ snprintf (theme_name, BUFSIZ, "0");
+ else
+ {
+ pair_content (COLR_CUSTOM, &color[0], &color[1]);
+ for (i = 0; i < NBCOLORS; i++)
+ {
+ if ((color[i] == DEFAULTCOLOR) || (color[i] == DEFAULTCOLOR_EXT))
+ color_name[i] = default_color;
+ else if (color[i] >= 0 && color[i] <= MAXCOLORS)
+ color_name[i] = name[color[i]];
+ else
+ {
+ fputs (error_txt, stderr);
+ exit (EXIT_FAILURE);
+ /* NOTREACHED */
+ }
}
+ snprintf (theme_name, BUFSIZ, "%s on %s", color_name[0], color_name[1]);
+ }
}
/* Prints the general options. */
-static void
-custom_print_general_options(WINDOW *optwin, conf_t *conf)
+static void
+custom_print_general_options (WINDOW *optwin, conf_t *conf)
{
- int x_pos, y_pos;
- char *option1 = _("auto_save = ");
- char *option2 = _("confirm_quit = ");
- char *option3 = _("confirm_delete = ");
- char *option4 = _("skip_system_dialogs = ");
- char *option5 = _("skip_progress_bar = ");
- char *option6 = _("week_begins_on_monday = ");
- char *option7 = _("output_datefmt = ");
- char *option8 = _("input_datefmt = ");
-
- x_pos = 3;
- y_pos = 3;
-
- mvwprintw(optwin, y_pos, x_pos, "[1] %s ", option1);
- print_option_incolor(optwin, conf->auto_save, y_pos,
- x_pos + 4 + strlen(option1));
- mvwprintw(optwin, y_pos + 1, x_pos,
- _("(if set to YES, automatic save is done when quitting)"));
-
- mvwprintw(optwin, y_pos + 3, x_pos, "[2] %s ", option2);
- print_option_incolor(optwin, conf->confirm_quit, y_pos + 3,
- x_pos + 4 + strlen(option2));
- mvwprintw(optwin, y_pos + 4, x_pos,
- _("(if set to YES, confirmation is required before quitting)"));
-
- mvwprintw(optwin, y_pos + 6, x_pos, "[3] %s ", option3);
- print_option_incolor(optwin, conf->confirm_delete, y_pos + 6,
- x_pos + 4 + strlen(option3));
- mvwprintw(optwin, y_pos + 7, x_pos,
- _("(if set to YES, confirmation is required before deleting an event)"));
-
- mvwprintw(optwin, y_pos + 9, x_pos, "[4] %s ", option4);
- print_option_incolor(optwin, conf->skip_system_dialogs, y_pos + 9,
- x_pos + 4 + strlen(option4));
- mvwprintw(optwin, y_pos + 10, x_pos,
- _("(if set to YES, messages about loaded and saved data will not be displayed)"));
-
- mvwprintw(optwin, y_pos + 12, x_pos, "[5] %s ", option5);
- print_option_incolor(optwin, conf->skip_progress_bar , y_pos + 12,
- x_pos + 4 + strlen(option5));
- mvwprintw(optwin, y_pos + 13, x_pos,
- _("(if set to YES, progress bar will not be displayed when saving data)"));
-
- mvwprintw(optwin, y_pos + 15, x_pos, "[6] %s ", option6);
- print_option_incolor(optwin, calendar_week_begins_on_monday(), y_pos + 15,
- x_pos + 4 + strlen(option6));
- mvwprintw(optwin, y_pos + 16, x_pos,
- _("(if set to YES, monday is the first day of the week, else it is sunday)"));
-
- mvwprintw(optwin, y_pos + 18, x_pos, "[7] %s ", option7);
- custom_apply_attr(optwin, ATTR_HIGHEST);
- mvwprintw(optwin, y_pos + 18, x_pos + 4 + strlen(option7), "%s",
- conf->output_datefmt);
- custom_remove_attr(optwin, ATTR_HIGHEST);
- mvwprintw(optwin, y_pos + 19, x_pos,
- _("(Format of the date to be displayed in non-interactive mode)"));
-
- mvwprintw(optwin, y_pos + 21, x_pos, "[8] %s ", option8);
- custom_apply_attr(optwin, ATTR_HIGHEST);
- mvwprintw(optwin, y_pos + 21, x_pos + 4 + strlen(option7), "%d",
- conf->input_datefmt);
- custom_remove_attr(optwin, ATTR_HIGHEST);
- mvwprintw(optwin, y_pos + 22, x_pos,
- _("(Format to be used when entering a date: 1-mm/dd/yyyy, 2-dd/mm/yyyy, 3-yyyy/mm/dd)"));
-
- wmove(win[STA].p, 1, 0);
- wnoutrefresh(optwin);
- doupdate();
+ int x_pos, y_pos;
+ char *option1 = _("auto_save = ");
+ char *option2 = _("confirm_quit = ");
+ char *option3 = _("confirm_delete = ");
+ char *option4 = _("skip_system_dialogs = ");
+ char *option5 = _("skip_progress_bar = ");
+ char *option6 = _("week_begins_on_monday = ");
+ char *option7 = _("output_datefmt = ");
+ char *option8 = _("input_datefmt = ");
+
+ x_pos = 3;
+ y_pos = 3;
+
+ mvwprintw (optwin, y_pos, x_pos, "[1] %s ", option1);
+ print_option_incolor (optwin, conf->auto_save, y_pos,
+ x_pos + 4 + strlen (option1));
+ mvwprintw (optwin, y_pos + 1, x_pos,
+ _("(if set to YES, automatic save is done when quitting)"));
+
+ mvwprintw (optwin, y_pos + 3, x_pos, "[2] %s ", option2);
+ print_option_incolor (optwin, conf->confirm_quit, y_pos + 3,
+ x_pos + 4 + strlen (option2));
+ mvwprintw (optwin, y_pos + 4, x_pos,
+ _("(if set to YES, confirmation is required before quitting)"));
+
+ mvwprintw (optwin, y_pos + 6, x_pos, "[3] %s ", option3);
+ print_option_incolor (optwin, conf->confirm_delete, y_pos + 6,
+ x_pos + 4 + strlen (option3));
+ mvwprintw (optwin, y_pos + 7, x_pos,
+ _("(if set to YES, confirmation is required "
+ "before deleting an event)"));
+
+ mvwprintw (optwin, y_pos + 9, x_pos, "[4] %s ", option4);
+ print_option_incolor (optwin, conf->skip_system_dialogs, y_pos + 9,
+ x_pos + 4 + strlen (option4));
+ mvwprintw (optwin, y_pos + 10, x_pos,
+ _("(if set to YES, messages about loaded "
+ "and saved data will not be displayed)"));
+
+ mvwprintw (optwin, y_pos + 12, x_pos, "[5] %s ", option5);
+ print_option_incolor (optwin, conf->skip_progress_bar, y_pos + 12,
+ x_pos + 4 + strlen (option5));
+ mvwprintw (optwin, y_pos + 13, x_pos,
+ _("(if set to YES, progress bar will not be displayed "
+ "when saving data)"));
+
+ mvwprintw (optwin, y_pos + 15, x_pos, "[6] %s ", option6);
+ print_option_incolor (optwin, calendar_week_begins_on_monday (), y_pos + 15,
+ x_pos + 4 + strlen (option6));
+ mvwprintw (optwin, y_pos + 16, x_pos,
+ _("(if set to YES, monday is the first day of the week, "
+ "else it is sunday)"));
+
+ mvwprintw (optwin, y_pos + 18, x_pos, "[7] %s ", option7);
+ custom_apply_attr (optwin, ATTR_HIGHEST);
+ mvwprintw (optwin, y_pos + 18, x_pos + 4 + strlen (option7), "%s",
+ conf->output_datefmt);
+ custom_remove_attr (optwin, ATTR_HIGHEST);
+ mvwprintw (optwin, y_pos + 19, x_pos,
+ _("(Format of the date to be displayed in non-interactive mode)"));
+
+ mvwprintw (optwin, y_pos + 21, x_pos, "[8] %s ", option8);
+ custom_apply_attr (optwin, ATTR_HIGHEST);
+ mvwprintw (optwin, y_pos + 21, x_pos + 4 + strlen (option7), "%d",
+ conf->input_datefmt);
+ custom_remove_attr (optwin, ATTR_HIGHEST);
+ mvwprintw (optwin, y_pos + 22, x_pos,
+ _("(Format to be used when entering a date: "
+ "1-mm/dd/yyyy, 2-dd/mm/yyyy, 3-yyyy/mm/dd)"));
+
+ wmove (win[STA].p, 1, 0);
+ wnoutrefresh (optwin);
+ doupdate ();
}
/* General configuration. */
-void
-custom_general_config(conf_t *conf)
+void
+custom_general_config (conf_t *conf)
{
- window_t conf_win;
- char *number_str = _("Enter an option number to change its value [Q to quit] ");
- char *output_datefmt_str =
- _("Enter the date format (see 'man 3 strftime' for possible formats) ");
- char *input_datefmt_str =
- _("Enter the date format (1-mm/dd/yyyy, 2-dd/mm/yyyy, 3-yyyy/mm/dd) ");
- int ch;
- char label[BUFSIZ];
- char *buf = (char *) malloc(BUFSIZ);
-
- clear();
- snprintf(label, BUFSIZ, _("CalCurse %s | general options"), VERSION);
- custom_confwin_init(&conf_win, label);
- status_mesg(number_str, "");
- custom_print_general_options(conf_win.p, conf);
- while ((ch = wgetch(win[STA].p)) != 'q') {
- switch (ch) {
- case KEY_RESIZE:
- endwin();
- refresh();
- curs_set(0);
- delwin(conf_win.p);
- custom_confwin_init(&conf_win, label);
- delwin(win[STA].p);
- win[STA].p = newwin(win[STA].h, win[STA].w, win[STA].y,
- win[STA].x);
- keypad(win[STA].p, TRUE);
- if (notify_bar()) {
- notify_reinit_bar(win[NOT].h, win[NOT].w,
- win[NOT].y, win[NOT].x);
- notify_update_bar();
- }
- break;
- case '1':
- conf->auto_save = !conf->auto_save;
- break;
- case '2':
- conf->confirm_quit = !conf->confirm_quit;
- break;
- case '3':
- conf->confirm_delete = !conf->confirm_delete;
- break;
- case '4':
- conf->skip_system_dialogs =
- !conf->skip_system_dialogs;
- break;
- case '5':
- conf->skip_progress_bar =
- !conf->skip_progress_bar;
- break;
- case '6':
- calendar_change_first_day_of_week();
- break;
- case '7':
- status_mesg(output_datefmt_str, "");
- strncpy(buf, conf->output_datefmt, strlen(conf->output_datefmt) + 1);
- if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
- strncpy(conf->output_datefmt, buf, strlen(buf) + 1);
- }
- status_mesg(number_str, "");
- break;
- case '8':
- status_mesg(input_datefmt_str, "");
- if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
- int val = atoi(buf);
- if (val >= 1 && val <= 3) conf->input_datefmt = val;
- }
- status_mesg(number_str, "");
- break;
- }
- status_mesg(number_str, "");
- custom_print_general_options(conf_win.p, conf);
+ window_t conf_win;
+ char *number_str =
+ _("Enter an option number to change its value [Q to quit] ");
+ char *output_datefmt_str =
+ _("Enter the date format (see 'man 3 strftime' for possible formats) ");
+ char *input_datefmt_str =
+ _("Enter the date format (1-mm/dd/yyyy, 2-dd/mm/yyyy, 3-yyyy/mm/dd) ");
+ int ch;
+ char label[BUFSIZ];
+ char *buf = (char *) malloc (BUFSIZ);
+
+ clear ();
+ snprintf (label, BUFSIZ, _("CalCurse %s | general options"), VERSION);
+ custom_confwin_init (&conf_win, label);
+ status_mesg (number_str, "");
+ custom_print_general_options (conf_win.p, conf);
+ while ((ch = wgetch (win[STA].p)) != 'q')
+ {
+ switch (ch)
+ {
+ case KEY_RESIZE:
+ endwin ();
+ refresh ();
+ curs_set (0);
+ delwin (conf_win.p);
+ custom_confwin_init (&conf_win, label);
+ delwin (win[STA].p);
+ win[STA].p = newwin (win[STA].h, win[STA].w, win[STA].y,
+ win[STA].x);
+ keypad (win[STA].p, TRUE);
+ if (notify_bar ())
+ {
+ notify_reinit_bar (win[NOT].h, win[NOT].w, win[NOT].y,
+ win[NOT].x);
+ notify_update_bar ();
+ }
+ break;
+ case '1':
+ conf->auto_save = !conf->auto_save;
+ break;
+ case '2':
+ conf->confirm_quit = !conf->confirm_quit;
+ break;
+ case '3':
+ conf->confirm_delete = !conf->confirm_delete;
+ break;
+ case '4':
+ conf->skip_system_dialogs = !conf->skip_system_dialogs;
+ break;
+ case '5':
+ conf->skip_progress_bar = !conf->skip_progress_bar;
+ break;
+ case '6':
+ calendar_change_first_day_of_week ();
+ break;
+ case '7':
+ status_mesg (output_datefmt_str, "");
+ strncpy (buf, conf->output_datefmt,
+ strlen (conf->output_datefmt) + 1);
+ if (updatestring (win[STA].p, &buf, 0, 1) == 0)
+ {
+ strncpy (conf->output_datefmt, buf, strlen (buf) + 1);
+ }
+ status_mesg (number_str, "");
+ break;
+ case '8':
+ status_mesg (input_datefmt_str, "");
+ if (updatestring (win[STA].p, &buf, 0, 1) == 0)
+ {
+ int val = atoi (buf);
+ if (val >= 1 && val <= 3)
+ conf->input_datefmt = val;
+ }
+ status_mesg (number_str, "");
+ break;
}
- free(buf);
- delwin(conf_win.p);
+ status_mesg (number_str, "");
+ custom_print_general_options (conf_win.p, conf);
+ }
+ free (buf);
+ delwin (conf_win.p);
}
diff --git a/src/custom.h b/src/custom.h
index fd9d78a..4c21284 100755
--- a/src/custom.h
+++ b/src/custom.h
@@ -1,4 +1,4 @@
-/* $calcurse: custom.h,v 1.11 2008/04/09 20:38:29 culot Exp $ */
+/* $calcurse: custom.h,v 1.12 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -32,52 +32,55 @@
#define NBUSERCOLORS 6
-enum { /* Color pairs */
- COLR_RED = 1,
- COLR_GREEN,
- COLR_YELLOW,
- COLR_BLUE,
- COLR_MAGENTA,
- COLR_CYAN,
- COLR_DEFAULT,
- COLR_HIGH,
- COLR_CUSTOM
+enum
+{ /* Color pairs */
+ COLR_RED = 1,
+ COLR_GREEN,
+ COLR_YELLOW,
+ COLR_BLUE,
+ COLR_MAGENTA,
+ COLR_CYAN,
+ COLR_DEFAULT,
+ COLR_HIGH,
+ COLR_CUSTOM
};
-enum { /* Configuration variables */
- CUSTOM_CONF_NOVARIABLE,
- CUSTOM_CONF_AUTOSAVE,
- CUSTOM_CONF_CONFIRMQUIT,
- CUSTOM_CONF_CONFIRMDELETE,
- CUSTOM_CONF_SKIPSYSTEMDIALOGS,
- CUSTOM_CONF_SKIPPROGRESSBAR,
- CUSTOM_CONF_WEEKBEGINSONMONDAY,
- CUSTOM_CONF_COLORTHEME,
- CUSTOM_CONF_LAYOUT,
- CUSTOM_CONF_NOTIFYBARSHOW,
- CUSTOM_CONF_NOTIFYBARDATE,
- CUSTOM_CONF_NOTIFYBARCLOCK,
- CUSTOM_CONF_NOTIFYBARWARNING,
- CUSTOM_CONF_NOTIFYBARCOMMAND,
- CUSTOM_CONF_OUTPUTDATEFMT,
- CUSTOM_CONF_INPUTDATEFMT,
- CUSTOM_CONF_VARIABLES
+enum
+{ /* Configuration variables */
+ CUSTOM_CONF_NOVARIABLE,
+ CUSTOM_CONF_AUTOSAVE,
+ CUSTOM_CONF_CONFIRMQUIT,
+ CUSTOM_CONF_CONFIRMDELETE,
+ CUSTOM_CONF_SKIPSYSTEMDIALOGS,
+ CUSTOM_CONF_SKIPPROGRESSBAR,
+ CUSTOM_CONF_WEEKBEGINSONMONDAY,
+ CUSTOM_CONF_COLORTHEME,
+ CUSTOM_CONF_LAYOUT,
+ CUSTOM_CONF_NOTIFYBARSHOW,
+ CUSTOM_CONF_NOTIFYBARDATE,
+ CUSTOM_CONF_NOTIFYBARCLOCK,
+ CUSTOM_CONF_NOTIFYBARWARNING,
+ CUSTOM_CONF_NOTIFYBARCOMMAND,
+ CUSTOM_CONF_OUTPUTDATEFMT,
+ CUSTOM_CONF_INPUTDATEFMT,
+ CUSTOM_CONF_VARIABLES
};
-struct attribute_s {
- int color[7];
- int nocolor[7];
+struct attribute_s
+{
+ int color[7];
+ int nocolor[7];
};
-void custom_init_attr(void);
-void custom_apply_attr(WINDOW *, int);
-void custom_remove_attr(WINDOW *, int);
-void custom_load_conf(conf_t *, int);
-void config_bar(void);
-void layout_config(void);
-void custom_color_config(void);
-void custom_color_theme_name(char *);
-void custom_confwin_init(window_t *, char *);
-void custom_general_config(conf_t *);
+void custom_init_attr (void);
+void custom_apply_attr (WINDOW *, int);
+void custom_remove_attr (WINDOW *, int);
+void custom_load_conf (conf_t *, int);
+void config_bar (void);
+void layout_config (void);
+void custom_color_config (void);
+void custom_color_theme_name (char *);
+void custom_confwin_init (window_t *, char *);
+void custom_general_config (conf_t *);
#endif /* CALCURSE_CUSTOM_H */
diff --git a/src/day.c b/src/day.c
index e2a587f..fcb8d6c 100755
--- a/src/day.c
+++ b/src/day.c
@@ -1,4 +1,4 @@
-/* $calcurse: day.c,v 1.35 2008/04/09 20:38:29 culot Exp $ */
+/* $calcurse: day.c,v 1.36 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -36,83 +36,90 @@
#include "custom.h"
#include "day.h"
-static struct day_item_s *day_items_ptr;
-static struct day_saved_item_s *day_saved_item = NULL;
+static struct day_item_s *day_items_ptr;
+static struct day_saved_item_s *day_saved_item = NULL;
/* Free the current day linked list containing the events and appointments. */
-static void
-day_free_list(void)
+static void
+day_free_list (void)
{
- struct day_item_s *p, *q;
-
- for (p = day_items_ptr; p != 0; p = q) {
- q = p->next;
- free(p->mesg);
- free(p);
- }
- day_items_ptr = NULL;
+ struct day_item_s *p, *q;
+
+ for (p = day_items_ptr; p != 0; p = q)
+ {
+ q = p->next;
+ free (p->mesg);
+ free (p);
+ }
+ day_items_ptr = NULL;
}
/* Add an event in the current day list */
static struct day_item_s *
-day_add_event(int type, char *mesg, char *note, long day, int id)
+day_add_event (int type, char *mesg, char *note, long day, int id)
{
- struct day_item_s *o, **i;
- o = (struct day_item_s *) malloc(sizeof(struct day_item_s));
- o->mesg = (char *) malloc(strlen(mesg) + 1);
- strncpy(o->mesg, mesg, strlen(mesg) + 1);
- o->note = note;
- o->type = type;
- o->appt_dur = 0;
- o->appt_pos = 0;
- o->start = day;
- o->evnt_id = id;
- i = &day_items_ptr;
- for (;;) {
- if (*i == 0) {
- o->next = *i;
- *i = o;
- break;
- }
- i = &(*i)->next;
+ struct day_item_s *o, **i;
+ o = (struct day_item_s *) malloc (sizeof (struct day_item_s));
+ o->mesg = (char *) malloc (strlen (mesg) + 1);
+ strncpy (o->mesg, mesg, strlen (mesg) + 1);
+ o->note = note;
+ o->type = type;
+ o->appt_dur = 0;
+ o->appt_pos = 0;
+ o->start = day;
+ o->evnt_id = id;
+ i = &day_items_ptr;
+ for (;;)
+ {
+ if (*i == 0)
+ {
+ o->next = *i;
+ *i = o;
+ break;
}
- return o;
+ i = &(*i)->next;
+ }
+ return (o);
}
/* Add an appointment in the current day list. */
static struct day_item_s *
-day_add_apoint(int type, char *mesg, char *note, long start, long dur,
- char state, int real_pos)
+day_add_apoint (int type, char *mesg, char *note, long start, long dur,
+ char state, int real_pos)
{
- struct day_item_s *o, **i;
- int insert_item = 0;
-
- o = (struct day_item_s *) malloc(sizeof(struct day_item_s));
- o->mesg = (char *) malloc(strlen(mesg) + 1);
- strncpy(o->mesg, mesg, strlen(mesg) + 1);
- o->note = note;
- o->start = start;
- o->appt_dur = dur;
- o->appt_pos = real_pos;
- o->state = state;
- o->type = type;
- o->evnt_id = 0;
- i = &day_items_ptr;
- for (;;) {
- if (*i == 0) {
- insert_item = 1;
- } else if ( ((*i)->start > start) &&
- ((*i)->type > EVNT) ) {
- insert_item = 1;
- }
- if (insert_item) {
- o->next = *i;
- *i = o;
- break;
- }
- i = &(*i)->next;
+ struct day_item_s *o, **i;
+ int insert_item = 0;
+
+ o = (struct day_item_s *) malloc (sizeof (struct day_item_s));
+ o->mesg = (char *) malloc (strlen (mesg) + 1);
+ strncpy (o->mesg, mesg, strlen (mesg) + 1);
+ o->note = note;
+ o->start = start;
+ o->appt_dur = dur;
+ o->appt_pos = real_pos;
+ o->state = state;
+ o->type = type;
+ o->evnt_id = 0;
+ i = &day_items_ptr;
+ for (;;)
+ {
+ if (*i == 0)
+ {
+ insert_item = 1;
+ }
+ else if (((*i)->start > start) && ((*i)->type > EVNT))
+ {
+ insert_item = 1;
+ }
+ if (insert_item)
+ {
+ o->next = *i;
+ *i = o;
+ break;
}
- return o;
+ i = &(*i)->next;
+ }
+ return (o);
}
/*
@@ -122,22 +129,23 @@ day_add_apoint(int type, char *mesg, char *note, long start, long dur,
* dedicated to the selected day.
* Returns the number of events for the selected day.
*/
-static int
-day_store_events(long date)
+static int
+day_store_events (long date)
{
- struct event_s *j;
- struct day_item_s *ptr;
- int e_nb = 0;
-
- for (j = eventlist; j != 0; j = j->next) {
- if (event_inday(j, date)) {
- e_nb++;
- ptr = day_add_event(EVNT, j->mesg, j->note, j->day,
- j->id);
- }
+ struct event_s *j;
+ struct day_item_s *ptr;
+ int e_nb = 0;
+
+ for (j = eventlist; j != 0; j = j->next)
+ {
+ if (event_inday (j, date))
+ {
+ e_nb++;
+ ptr = day_add_event (EVNT, j->mesg, j->note, j->day, j->id);
}
+ }
- return e_nb;
+ return (e_nb);
}
/*
@@ -147,23 +155,24 @@ day_store_events(long date)
* dedicated to the selected day.
* Returns the number of recurrent events for the selected day.
*/
-static int
-day_store_recur_events(long date)
+static int
+day_store_recur_events (long date)
{
- struct recur_event_s *j;
- struct day_item_s *ptr;
- int e_nb = 0;
-
- for (j = recur_elist; j != 0; j = j->next) {
- if (recur_item_inday(j->day, j->exc, j->rpt->type, j->rpt->freq,
- j->rpt->until, date)) {
- e_nb++;
- ptr = day_add_event(RECUR_EVNT, j->mesg, j->note,
- j->day, j->id);
- }
+ struct recur_event_s *j;
+ struct day_item_s *ptr;
+ int e_nb = 0;
+
+ for (j = recur_elist; j != 0; j = j->next)
+ {
+ if (recur_item_inday (j->day, j->exc, j->rpt->type, j->rpt->freq,
+ j->rpt->until, date))
+ {
+ e_nb++;
+ ptr = day_add_event (RECUR_EVNT, j->mesg, j->note, j->day, j->id);
}
+ }
- return e_nb;
+ return (e_nb);
}
/*
@@ -173,24 +182,26 @@ day_store_recur_events(long date)
* structure dedicated to the selected day.
* Returns the number of appointments for the selected day.
*/
-static int
-day_store_apoints(long date)
+static int
+day_store_apoints (long date)
{
- apoint_llist_node_t *j;
- struct day_item_s *ptr;
- int a_nb = 0;
-
- pthread_mutex_lock(&(alist_p->mutex));
- for (j = alist_p->root; j != 0; j = j->next) {
- if (apoint_inday(j, date)) {
- a_nb++;
- ptr = day_add_apoint(APPT, j->mesg, j->note, j->start,
- j->dur, j->state, 0);
- }
+ apoint_llist_node_t *j;
+ struct day_item_s *ptr;
+ int a_nb = 0;
+
+ pthread_mutex_lock (&(alist_p->mutex));
+ for (j = alist_p->root; j != 0; j = j->next)
+ {
+ if (apoint_inday (j, date))
+ {
+ a_nb++;
+ ptr = day_add_apoint (APPT, j->mesg, j->note, j->start,
+ j->dur, j->state, 0);
}
- pthread_mutex_unlock(&(alist_p->mutex));
+ }
+ pthread_mutex_unlock (&(alist_p->mutex));
- return a_nb;
+ return (a_nb);
}
/*
@@ -200,27 +211,30 @@ day_store_apoints(long date)
* structure dedicated to the selected day.
* Returns the number of recurrent appointments for the selected day.
*/
-static int
-day_store_recur_apoints(long date)
+static int
+day_store_recur_apoints (long date)
{
- recur_apoint_llist_node_t *j;
- struct day_item_s *ptr;
- long real_start;
- int a_nb = 0, n = 0;
-
- pthread_mutex_lock(&(recur_alist_p->mutex));
- for (j = recur_alist_p->root; j != 0; j = j->next) {
- if ((real_start = recur_item_inday(j->start, j->exc,
- j->rpt->type, j->rpt->freq, j->rpt->until, date)) ){
- a_nb++;
- ptr = day_add_apoint(RECUR_APPT, j->mesg, j->note,
- real_start, j->dur, j->state, n);
- n++;
- }
+ recur_apoint_llist_node_t *j;
+ struct day_item_s *ptr;
+ long real_start;
+ int a_nb = 0, n = 0;
+
+ pthread_mutex_lock (&(recur_alist_p->mutex));
+ for (j = recur_alist_p->root; j != 0; j = j->next)
+ {
+ if ((real_start = recur_item_inday (j->start, j->exc,
+ j->rpt->type, j->rpt->freq,
+ j->rpt->until, date)))
+ {
+ a_nb++;
+ ptr = day_add_apoint (RECUR_APPT, j->mesg, j->note,
+ real_start, j->dur, j->state, n);
+ n++;
}
- pthread_mutex_unlock(&(recur_alist_p->mutex));
+ }
+ pthread_mutex_unlock (&(recur_alist_p->mutex));
- return a_nb;
+ return (a_nb);
}
/*
@@ -231,30 +245,30 @@ day_store_recur_apoints(long date)
* and the length of the new pad to write is returned.
* The number of events and appointments in the current day are also updated.
*/
-static int
-day_store_items(long date, unsigned *pnb_events, unsigned *pnb_apoints)
+static int
+day_store_items (long date, unsigned *pnb_events, unsigned *pnb_apoints)
{
- int pad_length;
- int nb_events, nb_recur_events;
- int nb_apoints, nb_recur_apoints;
-
- pad_length = nb_events = nb_apoints = 0;
- nb_recur_events = nb_recur_apoints = 0;
-
- if (day_items_ptr != 0)
- day_free_list();
- nb_recur_events = day_store_recur_events(date);
- nb_events = day_store_events(date);
- *pnb_events = nb_events;
- nb_recur_apoints = day_store_recur_apoints(date);
- nb_apoints = day_store_apoints(date);
- *pnb_apoints = nb_apoints;
- pad_length = nb_recur_events + nb_events + 1 +
- 3*(nb_recur_apoints + nb_apoints);
- *pnb_apoints += nb_recur_apoints;
- *pnb_events += nb_recur_events;
-
- return pad_length;
+ int pad_length;
+ int nb_events, nb_recur_events;
+ int nb_apoints, nb_recur_apoints;
+
+ pad_length = nb_events = nb_apoints = 0;
+ nb_recur_events = nb_recur_apoints = 0;
+
+ if (day_items_ptr != 0)
+ day_free_list ();
+ nb_recur_events = day_store_recur_events (date);
+ nb_events = day_store_events (date);
+ *pnb_events = nb_events;
+ nb_recur_apoints = day_store_recur_apoints (date);
+ nb_apoints = day_store_apoints (date);
+ *pnb_apoints = nb_apoints;
+ pad_length = (nb_recur_events + nb_events + 1 +
+ 3 * (nb_recur_apoints + nb_apoints));
+ *pnb_apoints += nb_recur_apoints;
+ *pnb_events += nb_recur_events;
+
+ return (pad_length);
}
/*
@@ -263,32 +277,32 @@ day_store_items(long date, unsigned *pnb_events, unsigned *pnb_apoints)
* day. This is useful to speed up the appointment panel update.
*/
day_items_nb_t *
-day_process_storage(date_t *slctd_date, bool day_changed, day_items_nb_t *inday)
+day_process_storage (date_t *slctd_date, bool day_changed,
+ day_items_nb_t *inday)
{
- long date;
- date_t day;
+ long date;
+ date_t day;
- if (slctd_date)
- day = *slctd_date;
- else
- calendar_store_current_date(&day);
+ if (slctd_date)
+ day = *slctd_date;
+ else
+ calendar_store_current_date (&day);
- date = date2sec(day, 0, 0);
+ date = date2sec (day, 0, 0);
- /* Inits */
- if (apad->length != 0)
- delwin(apad->ptrwin);
+ /* Inits */
+ if (apad->length != 0)
+ delwin (apad->ptrwin);
- /* Store the events and appointments (recursive and normal items). */
- apad->length = day_store_items(date,
- &inday->nb_events, &inday->nb_apoints);
+ /* Store the events and appointments (recursive and normal items). */
+ apad->length = day_store_items (date, &inday->nb_events, &inday->nb_apoints);
- /* Create the new pad with its new length. */
- if (day_changed)
- apad->first_onscreen = 0;
- apad->ptrwin = newpad(apad->length, apad->width);
+ /* Create the new pad with its new length. */
+ if (day_changed)
+ apad->first_onscreen = 0;
+ apad->ptrwin = newpad (apad->length, apad->width);
- return (inday);
+ return (inday);
}
/*
@@ -296,69 +310,70 @@ day_process_storage(date_t *slctd_date, bool day_changed, day_items_nb_t *inday)
* day_item_s
*/
static void
-day_item_s2apoint_s(apoint_llist_node_t *a, struct day_item_s *p)
+day_item_s2apoint_s (apoint_llist_node_t *a, struct day_item_s *p)
{
- a->state = p->state;
- a->start = p->start;
- a->dur = p->appt_dur;
- a->mesg = p->mesg;
+ a->state = p->state;
+ a->start = p->start;
+ a->dur = p->appt_dur;
+ a->mesg = p->mesg;
}
/*
* Print an item date in the appointment panel.
*/
-static void
-display_item_date(int incolor, apoint_llist_node_t *i, int type, long date,
- int y, int x)
+static void
+display_item_date (int incolor, apoint_llist_node_t *i, int type, long date,
+ int y, int x)
{
- WINDOW *win;
- char a_st[100], a_end[100];
- int recur = 0;
-
- win = apad->ptrwin;
- apoint_sec2str(i, type, date, a_st, a_end);
- if (type == RECUR_EVNT || type == RECUR_APPT)
- recur = 1;
- if (incolor == 0)
- custom_apply_attr(win, ATTR_HIGHEST);
- if (recur)
- if (i->state & APOINT_NOTIFY)
- mvwprintw(win, y, x, " *!%s -> %s", a_st, a_end);
- else
- mvwprintw(win, y, x, " * %s -> %s", a_st, a_end);
- else
- if (i->state & APOINT_NOTIFY)
- mvwprintw(win, y, x, " -!%s -> %s", a_st, a_end);
- else
- mvwprintw(win, y, x, " - %s -> %s", a_st, a_end);
- if (incolor == 0)
- custom_remove_attr(win, ATTR_HIGHEST);
+ WINDOW *win;
+ char a_st[100], a_end[100];
+ int recur = 0;
+
+ win = apad->ptrwin;
+ apoint_sec2str (i, type, date, a_st, a_end);
+ if (type == RECUR_EVNT || type == RECUR_APPT)
+ recur = 1;
+ if (incolor == 0)
+ custom_apply_attr (win, ATTR_HIGHEST);
+ if (recur)
+ if (i->state & APOINT_NOTIFY)
+ mvwprintw (win, y, x, " *!%s -> %s", a_st, a_end);
+ else
+ mvwprintw (win, y, x, " * %s -> %s", a_st, a_end);
+ else if (i->state & APOINT_NOTIFY)
+ mvwprintw (win, y, x, " -!%s -> %s", a_st, a_end);
+ else
+ mvwprintw (win, y, x, " - %s -> %s", a_st, a_end);
+ if (incolor == 0)
+ custom_remove_attr (win, ATTR_HIGHEST);
}
/*
* Print an item description in the corresponding panel window.
*/
-static void
-display_item(int incolor, char *msg, int recur, int note, int len, int y, int x)
+static void
+display_item (int incolor, char *msg, int recur, int note, int len, int y,
+ int x)
{
- WINDOW *win;
- int ch_recur, ch_note;
- char buf[len];
-
- win = apad->ptrwin;
- ch_recur = (recur) ? '*' : ' ';
- ch_note = (note) ? '>' : ' ';
- if (incolor == 0)
- custom_apply_attr(win, ATTR_HIGHEST);
- if (strlen(msg) < len)
- mvwprintw(win, y, x, " %c%c%s", ch_recur, ch_note, msg);
- else {
- strncpy(buf, msg, len - 1);
- buf[len - 1] = '\0';
- mvwprintw(win, y, x, " %c%c%s...", ch_recur, ch_note, buf);
- }
- if (incolor == 0)
- custom_remove_attr(win, ATTR_HIGHEST);
+ WINDOW *win;
+ int ch_recur, ch_note;
+ char buf[len];
+
+ win = apad->ptrwin;
+ ch_recur = (recur) ? '*' : ' ';
+ ch_note = (note) ? '>' : ' ';
+ if (incolor == 0)
+ custom_apply_attr (win, ATTR_HIGHEST);
+ if (strlen (msg) < len)
+ mvwprintw (win, y, x, " %c%c%s", ch_recur, ch_note, msg);
+ else
+ {
+ strncpy (buf, msg, len - 1);
+ buf[len - 1] = '\0';
+ mvwprintw (win, y, x, " %c%c%s...", ch_recur, ch_note, buf);
+ }
+ if (incolor == 0)
+ custom_remove_attr (win, ATTR_HIGHEST);
}
/*
@@ -368,394 +383,426 @@ display_item(int incolor, char *msg, int recur, int note, int len, int y, int x)
* structure (pointed by day_saved_item), to be later displayed in a
* popup window if requested.
*/
-void
-day_write_pad(long date, int width, int length, int incolor)
+void
+day_write_pad (long date, int width, int length, int incolor)
{
- struct day_item_s *p;
- apoint_llist_node_t a;
- int line, item_number, max_pos, recur;
- const int x_pos = 0;
- bool draw_line = false;
-
- line = item_number = 0;
- max_pos = length;
-
- /* Initialize the structure used to store highlited item. */
- if (day_saved_item == NULL) {
- day_saved_item = (struct day_saved_item_s *)
- malloc(sizeof(struct day_saved_item_s));
- day_saved_item->mesg = (char *) malloc(sizeof(char));
- }
-
- for (p = day_items_ptr; p != 0; p = p->next) {
- if (p->type == RECUR_EVNT || p->type == RECUR_APPT)
- recur = 1;
- else
- recur = 0;
- /* First print the events for current day. */
- if (p->type < RECUR_APPT) {
- item_number++;
- if (item_number - incolor == 0) {
- day_saved_item->type = p->type;
- day_saved_item->mesg = p->mesg;
- }
- display_item(item_number - incolor, p->mesg, recur,
- (p->note != NULL) ? 1 : 0, width - 7, line, x_pos);
- line++;
- draw_line = true;
- } else {
- /* Draw a line between events and appointments. */
- if (line > 0 && draw_line){
- wmove(apad->ptrwin, line, 0);
- whline(apad->ptrwin, 0, width);
- draw_line = false;
- }
-
- /* Last print the appointments for current day. */
- item_number++;
- day_item_s2apoint_s(&a, p);
- if (item_number - incolor == 0) {
- day_saved_item->type = p->type;
- day_saved_item->mesg = p->mesg;
- apoint_sec2str(&a, p->type, date,
- day_saved_item->start, day_saved_item->end);
- }
- display_item_date(item_number - incolor, &a, p->type,
- date, line + 1, x_pos);
- display_item(item_number - incolor, p->mesg, 0,
- (p->note != NULL) ? 1 : 0, width - 7, line + 2,
- x_pos);
- line += 3;
- }
+ struct day_item_s *p;
+ apoint_llist_node_t a;
+ int line, item_number, max_pos, recur;
+ const int x_pos = 0;
+ bool draw_line = false;
+
+ line = item_number = 0;
+ max_pos = length;
+
+ /* Initialize the structure used to store highlited item. */
+ if (day_saved_item == NULL)
+ {
+ day_saved_item = (struct day_saved_item_s *)
+ malloc (sizeof (struct day_saved_item_s));
+ day_saved_item->mesg = (char *) malloc (sizeof (char));
+ }
+
+ for (p = day_items_ptr; p != 0; p = p->next)
+ {
+ if (p->type == RECUR_EVNT || p->type == RECUR_APPT)
+ recur = 1;
+ else
+ recur = 0;
+ /* First print the events for current day. */
+ if (p->type < RECUR_APPT)
+ {
+ item_number++;
+ if (item_number - incolor == 0)
+ {
+ day_saved_item->type = p->type;
+ day_saved_item->mesg = p->mesg;
+ }
+ display_item (item_number - incolor, p->mesg, recur,
+ (p->note != NULL) ? 1 : 0, width - 7, line, x_pos);
+ line++;
+ draw_line = true;
+ }
+ else
+ {
+ /* Draw a line between events and appointments. */
+ if (line > 0 && draw_line)
+ {
+ wmove (apad->ptrwin, line, 0);
+ whline (apad->ptrwin, 0, width);
+ draw_line = false;
+ }
+ /* Last print the appointments for current day. */
+ item_number++;
+ day_item_s2apoint_s (&a, p);
+ if (item_number - incolor == 0)
+ {
+ day_saved_item->type = p->type;
+ day_saved_item->mesg = p->mesg;
+ apoint_sec2str (&a, p->type, date,
+ day_saved_item->start, day_saved_item->end);
+ }
+ display_item_date (item_number - incolor, &a, p->type,
+ date, line + 1, x_pos);
+ display_item (item_number - incolor, p->mesg, 0,
+ (p->note != NULL) ? 1 : 0, width - 7, line + 2,
+ x_pos);
+ line += 3;
}
+ }
}
/* Display an item inside a popup window. */
-void
-day_popup_item(void)
+void
+day_popup_item (void)
{
- char *error =
- _("FATAL ERROR in day_popup_item: unknown item type\n");
-
- if (day_saved_item->type == EVNT || day_saved_item->type == RECUR_EVNT)
- item_in_popup(NULL, NULL, day_saved_item->mesg, _("Event :"));
- else if (day_saved_item->type == APPT ||
- day_saved_item->type == RECUR_APPT)
- item_in_popup(day_saved_item->start, day_saved_item->end,
- day_saved_item->mesg, _("Appointment :"));
- else
- ierror(error, IERROR_FATAL);
- /* NOTREACHED */
+ char *error = _("FATAL ERROR in day_popup_item: unknown item type\n");
+
+ if (day_saved_item->type == EVNT || day_saved_item->type == RECUR_EVNT)
+ item_in_popup (NULL, NULL, day_saved_item->mesg, _("Event :"));
+ else if (day_saved_item->type == APPT || day_saved_item->type == RECUR_APPT)
+ item_in_popup (day_saved_item->start, day_saved_item->end,
+ day_saved_item->mesg, _("Appointment :"));
+ else
+ ierror (error, IERROR_FATAL);
+ /* NOTREACHED */
}
/*
* Need to know if there is an item for the current selected day inside
* calendar. This is used to put the correct colors inside calendar panel.
*/
-int
-day_check_if_item(date_t day)
+int
+day_check_if_item (date_t day)
{
- struct recur_event_s *re;
- recur_apoint_llist_node_t *ra;
- struct event_s *e;
- apoint_llist_node_t *a;
- const long date = date2sec(day, 0, 0);
-
- for (re = recur_elist; re != 0; re = re->next)
- if (recur_item_inday(re->day, re->exc, re->rpt->type,
- re->rpt->freq, re->rpt->until, date))
- return 1;
-
- pthread_mutex_lock(&(recur_alist_p->mutex));
- for (ra = recur_alist_p->root; ra != 0; ra = ra->next)
- if (recur_item_inday(ra->start, ra->exc, ra->rpt->type,
- ra->rpt->freq, ra->rpt->until, date)) {
- pthread_mutex_unlock(
- &(recur_alist_p->mutex));
- return 1;
- }
- pthread_mutex_unlock(&(recur_alist_p->mutex));
-
- for (e = eventlist; e != 0; e = e->next)
- if (event_inday(e, date))
- return 1;
-
- pthread_mutex_lock(&(alist_p->mutex));
- for (a = alist_p->root; a != 0; a = a->next)
- if (apoint_inday(a, date)) {
- pthread_mutex_unlock(&(alist_p->mutex));
- return 1;
- }
- pthread_mutex_unlock(&(alist_p->mutex));
-
- return 0;
+ struct recur_event_s *re;
+ recur_apoint_llist_node_t *ra;
+ struct event_s *e;
+ apoint_llist_node_t *a;
+ const long date = date2sec (day, 0, 0);
+
+ for (re = recur_elist; re != 0; re = re->next)
+ if (recur_item_inday (re->day, re->exc, re->rpt->type,
+ re->rpt->freq, re->rpt->until, date))
+ return (1);
+
+ pthread_mutex_lock (&(recur_alist_p->mutex));
+ for (ra = recur_alist_p->root; ra != 0; ra = ra->next)
+ if (recur_item_inday (ra->start, ra->exc, ra->rpt->type,
+ ra->rpt->freq, ra->rpt->until, date))
+ {
+ pthread_mutex_unlock (&(recur_alist_p->mutex));
+ return (1);
+ }
+ pthread_mutex_unlock (&(recur_alist_p->mutex));
+
+ for (e = eventlist; e != 0; e = e->next)
+ if (event_inday (e, date))
+ return (1);
+
+ pthread_mutex_lock (&(alist_p->mutex));
+ for (a = alist_p->root; a != 0; a = a->next)
+ if (apoint_inday (a, date))
+ {
+ pthread_mutex_unlock (&(alist_p->mutex));
+ return (1);
+ }
+ pthread_mutex_unlock (&(alist_p->mutex));
+
+ return (0);
}
/* Request the user to enter a new time. */
static char *
-day_edit_time(long time)
+day_edit_time (long time)
{
- char *timestr;
- char *msg_time = _("Enter the new time ([hh:mm] or [h:mm]) : ");
- char *enter_str = _("Press [Enter] to continue");
- char *fmt_msg =
- _("You entered an invalid time, should be [h:mm] or [hh:mm]");
-
- while (1) {
- status_mesg(msg_time, "");
- timestr = date_sec2hour_str(time);
- updatestring(win[STA].p, &timestr, 0, 1);
- if (check_time(timestr) != 1 || strlen(timestr) == 0) {
- status_mesg(fmt_msg, enter_str);
- wgetch(win[STA].p);
- } else
- return (timestr);
+ char *timestr;
+ char *msg_time = _("Enter the new time ([hh:mm] or [h:mm]) : ");
+ char *enter_str = _("Press [Enter] to continue");
+ char *fmt_msg = _("You entered an invalid time, should be [h:mm] or [hh:mm]");
+
+ while (1)
+ {
+ status_mesg (msg_time, "");
+ timestr = date_sec2hour_str (time);
+ updatestring (win[STA].p, &timestr, 0, 1);
+ if (check_time (timestr) != 1 || strlen (timestr) == 0)
+ {
+ status_mesg (fmt_msg, enter_str);
+ wgetch (win[STA].p);
}
+ else
+ return (timestr);
+ }
}
static void
-update_start_time(long *start, long *dur)
+update_start_time (long *start, long *dur)
{
- long newtime;
- unsigned hr, mn;
- int valid_date;
- char *timestr;
- char *msg_wrong_time =
- _("Invalid time: start time must be before end time!");
- char *msg_enter = _("Press [Enter] to continue");
-
- do {
- timestr = day_edit_time(*start);
- sscanf(timestr, "%u:%u", &hr, &mn);
- free(timestr);
- newtime = update_time_in_date(*start, hr, mn);
- if (newtime < *start + *dur) {
- *dur -= (newtime - *start);
- *start = newtime;
- valid_date = 1;
- } else {
- status_mesg(msg_wrong_time, msg_enter);
- wgetch(win[STA].p);
- valid_date = 0;
- }
- } while (valid_date == 0);
+ long newtime;
+ unsigned hr, mn;
+ int valid_date;
+ char *timestr;
+ char *msg_wrong_time = _("Invalid time: start time must be before end time!");
+ char *msg_enter = _("Press [Enter] to continue");
+
+ do
+ {
+ timestr = day_edit_time (*start);
+ sscanf (timestr, "%u:%u", &hr, &mn);
+ free (timestr);
+ newtime = update_time_in_date (*start, hr, mn);
+ if (newtime < *start + *dur)
+ {
+ *dur -= (newtime - *start);
+ *start = newtime;
+ valid_date = 1;
+ }
+ else
+ {
+ status_mesg (msg_wrong_time, msg_enter);
+ wgetch (win[STA].p);
+ valid_date = 0;
+ }
+ }
+ while (valid_date == 0);
}
static void
-update_duration(long *start, long *dur)
+update_duration (long *start, long *dur)
{
- long newtime;
- unsigned hr, mn;
- char *timestr;
-
- timestr = day_edit_time(*start + *dur);
- sscanf(timestr, "%u:%u", &hr, &mn);
- free(timestr);
- newtime = update_time_in_date(*start, hr, mn);
- *dur = (newtime > *start) ? newtime - *start :
- DAYINSEC + newtime - *start;
+ long newtime;
+ unsigned hr, mn;
+ char *timestr;
+
+ timestr = day_edit_time (*start + *dur);
+ sscanf (timestr, "%u:%u", &hr, &mn);
+ free (timestr);
+ newtime = update_time_in_date (*start, hr, mn);
+ *dur = (newtime > *start) ? newtime - *start : DAYINSEC + newtime - *start;
}
static void
-update_desc(char **desc)
+update_desc (char **desc)
{
- status_mesg(_("Enter the new item description:"), "");
- updatestring(win[STA].p, desc, 0, 1);
+ status_mesg (_("Enter the new item description:"), "");
+ updatestring (win[STA].p, desc, 0, 1);
}
static void
-update_rept(struct rpt_s **rpt, const long start, conf_t *conf)
+update_rept (struct rpt_s **rpt, const long start, conf_t *conf)
{
- const int SINGLECHAR = 2;
- int ch, cancel, newfreq, date_entered;
- long newuntil;
- char outstr[BUFSIZ];
- char *typstr, *freqstr, *timstr;
- char *msg_rpt_type =
- _("Enter the new repetition type: (D)aily, (W)eekly, "
- "(M)onthly, (Y)early");
- char *msg_rpt_ans = _("[D/W/M/Y] ");
- char *msg_wrong_freq = _("The frequence you entered is not valid.");
- char *msg_wrong_time =
- _("Invalid time: start time must be before end time!");
- char *msg_wrong_date = _("The entered date is not valid.");
- char *msg_fmts = "Possible formats are [%s] or '0' "
- "for an endless repetetition";
- char *msg_enter = _("Press [Enter] to continue");
-
- do {
- status_mesg(msg_rpt_type, msg_rpt_ans);
- typstr = (char *)malloc(sizeof(char) * SINGLECHAR);
- snprintf(typstr, SINGLECHAR, "%c", recur_def2char((*rpt)->type));
- cancel = updatestring(win[STA].p, &typstr, 0, 1);
- if (cancel) {
- free(typstr);
- return;
- } else {
- ch = toupper(*typstr);
- free(typstr);
- }
- } while ((ch != 'D') && (ch != 'W') && (ch != 'M') && (ch != 'Y'));
-
- do {
- status_mesg(_("Enter the new repetition frequence:"), "");
- freqstr = (char *)malloc(BUFSIZ);
- snprintf(freqstr, BUFSIZ, "%d", (*rpt)->freq);
- cancel = updatestring(win[STA].p, &freqstr, 0, 1);
- if (cancel) {
- free(freqstr);
- return;
- } else {
- newfreq = atoi(freqstr);
- free(freqstr);
- if (newfreq == 0) {
- status_mesg(msg_wrong_freq, msg_enter);
- wgetch(win[STA].p);
- }
- }
- } while (newfreq == 0);
-
- do {
- snprintf(outstr, BUFSIZ, "Enter the new ending date: [%s] or '0'",
- DATEFMT_DESC(conf->input_datefmt));
- status_mesg(_(outstr), "");
- timstr = date_sec2date_str((*rpt)->until, DATEFMT(conf->input_datefmt));
- cancel = updatestring(win[STA].p, &timstr, 0, 1);
- if (cancel) {
- free(timstr);
- return;
- }
- if (strcmp(timstr, "0") == 0) {
- newuntil = 0;
- date_entered = 1;
- } else {
- struct tm *lt;
- time_t t;
- date_t new_date;
- int newmonth, newday, newyear;
-
- if (parse_date(timstr, conf->input_datefmt,
- &newyear, &newmonth, &newday)) {
- t = start;
- lt = localtime(&t);
- new_date.dd = newday;
- new_date.mm = newmonth;
- new_date.yyyy = newyear;
- newuntil = date2sec(new_date, lt->tm_hour,
- lt->tm_min);
- if (newuntil < start) {
- status_mesg(msg_wrong_time, msg_enter);
- wgetch(win[STA].p);
- date_entered = 0;
- } else
- date_entered = 1;
- } else {
- snprintf(outstr, BUFSIZ, msg_fmts,
- DATEFMT_DESC(conf->input_datefmt));
- status_mesg(msg_wrong_date, _(outstr));
- wgetch(win[STA].p);
- date_entered = 0;
- }
+ const int SINGLECHAR = 2;
+ int ch, cancel, newfreq, date_entered;
+ long newuntil;
+ char outstr[BUFSIZ];
+ char *typstr, *freqstr, *timstr;
+ char *msg_rpt_type = _("Enter the new repetition type: (D)aily, (W)eekly, "
+ "(M)onthly, (Y)early");
+ char *msg_rpt_ans = _("[D/W/M/Y] ");
+ char *msg_wrong_freq = _("The frequence you entered is not valid.");
+ char *msg_wrong_time = _("Invalid time: start time must be before end time!");
+ char *msg_wrong_date = _("The entered date is not valid.");
+ char *msg_fmts =
+ "Possible formats are [%s] or '0' for an endless repetetition";
+ char *msg_enter = _("Press [Enter] to continue");
+
+ do
+ {
+ status_mesg (msg_rpt_type, msg_rpt_ans);
+ typstr = (char *) malloc (sizeof (char) * SINGLECHAR);
+ snprintf (typstr, SINGLECHAR, "%c", recur_def2char ((*rpt)->type));
+ cancel = updatestring (win[STA].p, &typstr, 0, 1);
+ if (cancel)
+ {
+ free (typstr);
+ return;
+ }
+ else
+ {
+ ch = toupper (*typstr);
+ free (typstr);
+ }
+ }
+ while ((ch != 'D') && (ch != 'W') && (ch != 'M') && (ch != 'Y'));
+
+ do
+ {
+ status_mesg (_("Enter the new repetition frequence:"), "");
+ freqstr = (char *) malloc (BUFSIZ);
+ snprintf (freqstr, BUFSIZ, "%d", (*rpt)->freq);
+ cancel = updatestring (win[STA].p, &freqstr, 0, 1);
+ if (cancel)
+ {
+ free (freqstr);
+ return;
+ }
+ else
+ {
+ newfreq = atoi (freqstr);
+ free (freqstr);
+ if (newfreq == 0)
+ {
+ status_mesg (msg_wrong_freq, msg_enter);
+ wgetch (win[STA].p);
+ }
+ }
+ }
+ while (newfreq == 0);
+
+ do
+ {
+ snprintf (outstr, BUFSIZ, "Enter the new ending date: [%s] or '0'",
+ DATEFMT_DESC (conf->input_datefmt));
+ status_mesg (_(outstr), "");
+ timstr =
+ date_sec2date_str ((*rpt)->until, DATEFMT (conf->input_datefmt));
+ cancel = updatestring (win[STA].p, &timstr, 0, 1);
+ if (cancel)
+ {
+ free (timstr);
+ return;
+ }
+ if (strcmp (timstr, "0") == 0)
+ {
+ newuntil = 0;
+ date_entered = 1;
+ }
+ else
+ {
+ struct tm *lt;
+ time_t t;
+ date_t new_date;
+ int newmonth, newday, newyear;
+
+ if (parse_date (timstr, conf->input_datefmt,
+ &newyear, &newmonth, &newday))
+ {
+ t = start;
+ lt = localtime (&t);
+ new_date.dd = newday;
+ new_date.mm = newmonth;
+ new_date.yyyy = newyear;
+ newuntil = date2sec (new_date, lt->tm_hour, lt->tm_min);
+ if (newuntil < start)
+ {
+ status_mesg (msg_wrong_time, msg_enter);
+ wgetch (win[STA].p);
+ date_entered = 0;
}
- } while (date_entered == 0);
+ else
+ date_entered = 1;
+ }
+ else
+ {
+ snprintf (outstr, BUFSIZ, msg_fmts,
+ DATEFMT_DESC (conf->input_datefmt));
+ status_mesg (msg_wrong_date, _(outstr));
+ wgetch (win[STA].p);
+ date_entered = 0;
+ }
+ }
+ }
+ while (date_entered == 0);
- free(timstr);
- (*rpt)->type = recur_char2def(ch);
- (*rpt)->freq = newfreq;
- (*rpt)->until = newuntil;
+ free (timstr);
+ (*rpt)->type = recur_char2def (ch);
+ (*rpt)->freq = newfreq;
+ (*rpt)->until = newuntil;
}
/* Edit an already existing item. */
-void
-day_edit_item(conf_t *conf)
+void
+day_edit_item (conf_t *conf)
{
#define STRT '1'
#define END '2'
#define DESC '3'
#define REPT '4'
- struct day_item_s *p;
- struct recur_event_s *re;
- struct event_s *e;
- recur_apoint_llist_node_t *ra;
- apoint_llist_node_t *a;
- long date;
- int item_num, ch;
-
- item_num = apoint_hilt();
- p = day_get_item(item_num);
- date = calendar_get_slctd_day_sec();
-
- ch = 0;
- switch (p->type) {
- case RECUR_EVNT:
- re = recur_get_event(date,
- day_item_nb(date, item_num, RECUR_EVNT));
- status_mesg(_("Edit: (1)Description or (2)Repetition?"),
- "[1/2] ");
- while (ch != '1' && ch != '2' && ch != ESCAPE)
- ch = wgetch(win[STA].p);
- switch (ch) {
- case '1':
- update_desc(&re->mesg);
- break;
- case '2':
- update_rept(&re->rpt, re->day, conf);
- break;
- default:
- return;
- }
- break;
- case EVNT:
- e = event_get(date, day_item_nb(date, item_num, EVNT));
- update_desc(&e->mesg);
- break;
- case RECUR_APPT:
- ra = recur_get_apoint(date,
- day_item_nb(date, item_num, RECUR_APPT));
- status_mesg(_("Edit: (1)Start time, (2)End time, "
- "(3)Description or (4)Repetition?"), "[1/2/3/4] ");
- while (ch != STRT && ch != END && ch != DESC &&
- ch != REPT && ch != ESCAPE)
- ch = wgetch(win[STA].p);
- switch (ch) {
- case STRT:
- update_start_time(&ra->start, &ra->dur);
- break;
- case END:
- update_duration(&ra->start, &ra->dur);
- break;
- case DESC:
- update_desc(&ra->mesg);
- break;
- case REPT:
- update_rept(&ra->rpt, ra->start, conf);
- break;
- case ESCAPE:
- return;
- }
- break;
- case APPT:
- a = apoint_get(date, day_item_nb(date, item_num, APPT));
- status_mesg(_("Edit: (1)Start time, (2)End time "
- "or (3)Description?"), "[1/2/3] ");
- while (ch != STRT && ch != END && ch != DESC && ch != ESCAPE)
- ch = wgetch(win[STA].p);
- switch (ch) {
- case STRT:
- update_start_time(&a->start, &a->dur);
- break;
- case END:
- update_duration(&a->start, &a->dur);
- break;
- case DESC:
- update_desc(&a->mesg);
- break;
- case ESCAPE:
- return;
- }
- break;
+ struct day_item_s *p;
+ struct recur_event_s *re;
+ struct event_s *e;
+ recur_apoint_llist_node_t *ra;
+ apoint_llist_node_t *a;
+ long date;
+ int item_num, ch;
+
+ item_num = apoint_hilt ();
+ p = day_get_item (item_num);
+ date = calendar_get_slctd_day_sec ();
+
+ ch = 0;
+ switch (p->type)
+ {
+ case RECUR_EVNT:
+ re = recur_get_event (date, day_item_nb (date, item_num, RECUR_EVNT));
+ status_mesg (_("Edit: (1)Description or (2)Repetition?"), "[1/2] ");
+ while (ch != '1' && ch != '2' && ch != ESCAPE)
+ ch = wgetch (win[STA].p);
+ switch (ch)
+ {
+ case '1':
+ update_desc (&re->mesg);
+ break;
+ case '2':
+ update_rept (&re->rpt, re->day, conf);
+ break;
+ default:
+ return;
+ }
+ break;
+ case EVNT:
+ e = event_get (date, day_item_nb (date, item_num, EVNT));
+ update_desc (&e->mesg);
+ break;
+ case RECUR_APPT:
+ ra = recur_get_apoint (date, day_item_nb (date, item_num, RECUR_APPT));
+ status_mesg (_("Edit: (1)Start time, (2)End time, "
+ "(3)Description or (4)Repetition?"), "[1/2/3/4] ");
+ while (ch != STRT && ch != END && ch != DESC &&
+ ch != REPT && ch != ESCAPE)
+ ch = wgetch (win[STA].p);
+ switch (ch)
+ {
+ case STRT:
+ update_start_time (&ra->start, &ra->dur);
+ break;
+ case END:
+ update_duration (&ra->start, &ra->dur);
+ break;
+ case DESC:
+ update_desc (&ra->mesg);
+ break;
+ case REPT:
+ update_rept (&ra->rpt, ra->start, conf);
+ break;
+ case ESCAPE:
+ return;
}
+ break;
+ case APPT:
+ a = apoint_get (date, day_item_nb (date, item_num, APPT));
+ status_mesg (_("Edit: (1)Start time, (2)End time "
+ "or (3)Description?"), "[1/2/3] ");
+ while (ch != STRT && ch != END && ch != DESC && ch != ESCAPE)
+ ch = wgetch (win[STA].p);
+ switch (ch)
+ {
+ case STRT:
+ update_start_time (&a->start, &a->dur);
+ break;
+ case END:
+ update_duration (&a->start, &a->dur);
+ break;
+ case DESC:
+ update_desc (&a->mesg);
+ break;
+ case ESCAPE:
+ return;
+ }
+ break;
+ }
}
/*
@@ -764,158 +811,173 @@ day_edit_item(conf_t *conf)
* recurrent appointments and appointments) and then to test the
* type of the item to be deleted.
*/
-int
-day_erase_item(long date, int item_number, erase_flag_e flag)
+int
+day_erase_item (long date, int item_number, erase_flag_e flag)
{
- struct day_item_s *p;
- char *erase_warning =
- _("This item is recurrent. "
- "Delete (a)ll occurences or just this (o)ne ?");
- char *note_warning =
- _("This item has a note attached to it. "
- "Delete (i)tem or just its (n)ote ?");
- char *note_choice = _("[i/n] ");
- char *erase_choice = _("[a/o] ");
- int ch = 0, ans;
- unsigned delete_whole;
-
- p = day_get_item(item_number);
- if (flag == ERASE_DONT_FORCE) {
- ans = 0;
- if (p->note == NULL)
- ans = 'i';
- while (ans != 'i' && ans != 'n') {
- status_mesg(note_warning, note_choice);
- ans = wgetch(win[STA].p);
- }
- if (ans == 'i')
- flag = ERASE_FORCE;
- else
- flag = ERASE_FORCE_ONLY_NOTE;
+ struct day_item_s *p;
+ char *erase_warning =
+ _("This item is recurrent. "
+ "Delete (a)ll occurences or just this (o)ne ?");
+ char *note_warning =
+ _("This item has a note attached to it. "
+ "Delete (i)tem or just its (n)ote ?");
+ char *note_choice = _("[i/n] ");
+ char *erase_choice = _("[a/o] ");
+ int ch = 0, ans;
+ unsigned delete_whole;
+
+ p = day_get_item (item_number);
+ if (flag == ERASE_DONT_FORCE)
+ {
+ ans = 0;
+ if (p->note == NULL)
+ ans = 'i';
+ while (ans != 'i' && ans != 'n')
+ {
+ status_mesg (note_warning, note_choice);
+ ans = wgetch (win[STA].p);
}
- if (p->type == EVNT) {
- event_delete_bynum(date, day_item_nb(date, item_number, EVNT),
- flag);
- } else if (p->type == APPT) {
- apoint_delete_bynum(date, day_item_nb(date, item_number, APPT),
- flag);
- } else {
- if (flag == ERASE_FORCE_ONLY_NOTE)
- ch = 'a';
- while ( (ch != 'a') && (ch != 'o') && (ch != ESCAPE)) {
- status_mesg(erase_warning, erase_choice);
- ch = wgetch(win[STA].p);
- }
- if (ch == 'a') {
- delete_whole = 1;
- } else if (ch == 'o') {
- delete_whole = 0;
- } else {
- return 0;
- }
- if (p->type == RECUR_EVNT) {
- recur_event_erase(date,
- day_item_nb(date, item_number, RECUR_EVNT),
- delete_whole, flag);
- } else {
- recur_apoint_erase(date, p->appt_pos, delete_whole,
- flag);
- }
+ if (ans == 'i')
+ flag = ERASE_FORCE;
+ else
+ flag = ERASE_FORCE_ONLY_NOTE;
+ }
+ if (p->type == EVNT)
+ {
+ event_delete_bynum (date, day_item_nb (date, item_number, EVNT), flag);
+ }
+ else if (p->type == APPT)
+ {
+ apoint_delete_bynum (date, day_item_nb (date, item_number, APPT), flag);
+ }
+ else
+ {
+ if (flag == ERASE_FORCE_ONLY_NOTE)
+ ch = 'a';
+ while ((ch != 'a') && (ch != 'o') && (ch != ESCAPE))
+ {
+ status_mesg (erase_warning, erase_choice);
+ ch = wgetch (win[STA].p);
+ }
+ if (ch == 'a')
+ {
+ delete_whole = 1;
+ }
+ else if (ch == 'o')
+ {
+ delete_whole = 0;
+ }
+ else
+ {
+ return (0);
+ }
+ if (p->type == RECUR_EVNT)
+ {
+ recur_event_erase (date, day_item_nb (date, item_number, RECUR_EVNT),
+ delete_whole, flag);
}
- return (p->type);
+ else
+ {
+ recur_apoint_erase (date, p->appt_pos, delete_whole, flag);
+ }
+ }
+ return (p->type);
}
/* Returns a structure containing the selected item. */
-struct day_item_s *day_get_item(int item_number)
+struct day_item_s *
+day_get_item (int item_number)
{
- struct day_item_s *o;
- int i;
-
- o = day_items_ptr;
- for (i = 1; i < item_number; i++) {
- o = o->next;
- }
- return o;
+ struct day_item_s *o;
+ int i;
+
+ o = day_items_ptr;
+ for (i = 1; i < item_number; i++)
+ {
+ o = o->next;
+ }
+ return (o);
}
/* Returns the real item number, given its type. */
int
-day_item_nb(long date, int day_num, int type)
+day_item_nb (long date, int day_num, int type)
{
- int i, nb_item[MAX_TYPES];
- struct day_item_s *p;
+ int i, nb_item[MAX_TYPES];
+ struct day_item_s *p;
- for (i = 0; i < MAX_TYPES; i++)
- nb_item[i] = 0;
+ for (i = 0; i < MAX_TYPES; i++)
+ nb_item[i] = 0;
- p = day_items_ptr;
+ p = day_items_ptr;
- for (i = 1; i < day_num; i++) {
- nb_item[p->type - 1]++;
- p = p->next;
- }
+ for (i = 1; i < day_num; i++)
+ {
+ nb_item[p->type - 1]++;
+ p = p->next;
+ }
- return (nb_item[type - 1]);
+ return (nb_item[type - 1]);
}
/* Attach a note to an appointment or event. */
void
-day_edit_note(char *editor)
+day_edit_note (char *editor)
{
- struct day_item_s *p;
- recur_apoint_llist_node_t *ra;
- apoint_llist_node_t *a;
- struct recur_event_s *re;
- struct event_s *e;
- char fullname[BUFSIZ];
- char *filename;
- long date;
- int item_num;
-
- item_num = apoint_hilt();
- p = day_get_item(item_num);
- if (p->note == NULL) {
- if ((filename = new_tempfile(path_notes, NOTESIZ)) == NULL)
- return;
- else
- p->note = filename;
- }
- snprintf(fullname, BUFSIZ, "%s%s", path_notes, p->note);
- wins_launch_external(fullname, editor);
-
- date = calendar_get_slctd_day_sec();
- switch (p->type) {
- case RECUR_EVNT:
- re = recur_get_event(date,
- day_item_nb(date, item_num, RECUR_EVNT));
- re->note = p->note;
- break;
- case EVNT:
- e = event_get(date, day_item_nb(date, item_num, EVNT));
- e->note = p->note;
- break;
- case RECUR_APPT:
- ra = recur_get_apoint(date,
- day_item_nb(date, item_num, RECUR_APPT));
- ra->note = p->note;
- break;
- case APPT:
- a = apoint_get(date, day_item_nb(date, item_num, APPT));
- a->note = p->note;
- break;
- }
+ struct day_item_s *p;
+ recur_apoint_llist_node_t *ra;
+ apoint_llist_node_t *a;
+ struct recur_event_s *re;
+ struct event_s *e;
+ char fullname[BUFSIZ];
+ char *filename;
+ long date;
+ int item_num;
+
+ item_num = apoint_hilt ();
+ p = day_get_item (item_num);
+ if (p->note == NULL)
+ {
+ if ((filename = new_tempfile (path_notes, NOTESIZ)) == NULL)
+ return;
+ else
+ p->note = filename;
+ }
+ snprintf (fullname, BUFSIZ, "%s%s", path_notes, p->note);
+ wins_launch_external (fullname, editor);
+
+ date = calendar_get_slctd_day_sec ();
+ switch (p->type)
+ {
+ case RECUR_EVNT:
+ re = recur_get_event (date, day_item_nb (date, item_num, RECUR_EVNT));
+ re->note = p->note;
+ break;
+ case EVNT:
+ e = event_get (date, day_item_nb (date, item_num, EVNT));
+ e->note = p->note;
+ break;
+ case RECUR_APPT:
+ ra = recur_get_apoint (date, day_item_nb (date, item_num, RECUR_APPT));
+ ra->note = p->note;
+ break;
+ case APPT:
+ a = apoint_get (date, day_item_nb (date, item_num, APPT));
+ a->note = p->note;
+ break;
+ }
}
/* View a note previously attached to an appointment or event */
-void
-day_view_note(char *pager)
+void
+day_view_note (char *pager)
{
- struct day_item_s *p;
- char fullname[BUFSIZ];
-
- p = day_get_item(apoint_hilt());
- if (p->note == NULL)
- return;
- snprintf(fullname, BUFSIZ, "%s%s", path_notes, p->note);
- wins_launch_external(fullname, pager);
+ struct day_item_s *p;
+ char fullname[BUFSIZ];
+
+ p = day_get_item (apoint_hilt ());
+ if (p->note == NULL)
+ return;
+ snprintf (fullname, BUFSIZ, "%s%s", path_notes, p->note);
+ wins_launch_external (fullname, pager);
}
diff --git a/src/day.h b/src/day.h
index 10bf3a5..380d64c 100755
--- a/src/day.h
+++ b/src/day.h
@@ -1,4 +1,4 @@
-/* $calcurse: day.h,v 1.18 2008/04/09 20:38:29 culot Exp $ */
+/* $calcurse: day.h,v 1.19 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -38,40 +38,44 @@
#define RECUR_APPT 3
#define APPT 4
-typedef struct {
- unsigned nb_events;
- unsigned nb_apoints;
-} day_items_nb_t;
+typedef struct
+{
+ unsigned nb_events;
+ unsigned nb_apoints;
+}
+day_items_nb_t;
-struct day_item_s {
- struct day_item_s *next;
- long start; /* seconds since 1 jan 1970 */
- long appt_dur; /* appointment duration in seconds */
- int type; /* (recursive or normal) event or appointment */
- int evnt_id; /* event identifier */
- int appt_pos; /* real position in recurrent list */
- char state; /* appointment state */
- char *mesg; /* item description */
- char *note; /* note attached to item */
+struct day_item_s
+{
+ struct day_item_s *next;
+ long start; /* seconds since 1 jan 1970 */
+ long appt_dur; /* appointment duration in seconds */
+ int type; /* (recursive or normal) event or appointment */
+ int evnt_id; /* event identifier */
+ int appt_pos; /* real position in recurrent list */
+ char state; /* appointment state */
+ char *mesg; /* item description */
+ char *note; /* note attached to item */
};
-struct day_saved_item_s {
- char start[BUFSIZ];
- char end[BUFSIZ];
- char state;
- char type ;
- char *mesg;
+struct day_saved_item_s
+{
+ char start[BUFSIZ];
+ char end[BUFSIZ];
+ char state;
+ char type;
+ char *mesg;
};
-day_items_nb_t *day_process_storage(date_t *, bool, day_items_nb_t *);
-void day_write_pad(long, int, int, int);
-void day_popup_item(void);
-int day_check_if_item(date_t);
-void day_edit_item(conf_t *);
-int day_erase_item(long, int, erase_flag_e);
-struct day_item_s *day_get_item(int);
-int day_item_nb(long, int, int);
-void day_edit_note(char *);
-void day_view_note(char *);
+day_items_nb_t *day_process_storage (date_t *, bool, day_items_nb_t *);
+void day_write_pad (long, int, int, int);
+void day_popup_item (void);
+int day_check_if_item (date_t);
+void day_edit_item (conf_t *);
+int day_erase_item (long, int, erase_flag_e);
+struct day_item_s *day_get_item (int);
+int day_item_nb (long, int, int);
+void day_edit_note (char *);
+void day_view_note (char *);
#endif /* CALCURSE_DAY_H */
diff --git a/src/event.c b/src/event.c
index 47da756..f865868 100755
--- a/src/event.c
+++ b/src/event.c
@@ -1,4 +1,4 @@
-/* $calcurse: event.c,v 1.6 2008/01/20 10:45:38 culot Exp $ */
+/* $calcurse: event.c,v 1.7 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -37,132 +37,144 @@ struct event_s *eventlist;
/* Create a new event */
struct event_s *
-event_new(char *mesg, char *note, long day, int id)
+event_new (char *mesg, char *note, long day, int id)
{
- struct event_s *o, **i;
- o = (struct event_s *) malloc(sizeof(struct event_s));
- o->mesg = (char *) malloc(strlen(mesg) + 1);
- strncpy(o->mesg, mesg, strlen(mesg) + 1);
- o->day = day;
- o->id = id;
- o->note = (note != NULL) ? strdup(note) : NULL;
- i = &eventlist;
- for (;;) {
- if (*i == 0 || (*i)->day > day) {
- o->next = *i;
- *i = o;
- break;
- }
- i = &(*i)->next;
+ struct event_s *o, **i;
+ o = (struct event_s *) malloc (sizeof (struct event_s));
+ o->mesg = (char *) malloc (strlen (mesg) + 1);
+ strncpy (o->mesg, mesg, strlen (mesg) + 1);
+ o->day = day;
+ o->id = id;
+ o->note = (note != NULL) ? strdup (note) : NULL;
+ i = &eventlist;
+ for (;;)
+ {
+ if (*i == 0 || (*i)->day > day)
+ {
+ o->next = *i;
+ *i = o;
+ break;
}
- return o;
+ i = &(*i)->next;
+ }
+ return (o);
}
/* Check if the event belongs to the selected day */
-unsigned
-event_inday(struct event_s *i, long start)
+unsigned
+event_inday (struct event_s *i, long start)
{
- if (i->day <= start + DAYINSEC && i->day > start) {
- return 1;
- }
- return 0;
+ if (i->day <= start + DAYINSEC && i->day > start)
+ {
+ return (1);
+ }
+ return (0);
}
/* Write to file the event in user-friendly format */
-void
-event_write(struct event_s *o, FILE * f)
+void
+event_write (struct event_s *o, FILE *f)
{
- struct tm *lt;
- time_t t;
-
- t = o->day;
- lt = localtime(&t);
- fprintf(f, "%02u/%02u/%04u [%d] ",
- lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year, o->id);
- if (o->note != NULL)
- fprintf(f, ">%s ", o->note);
- fprintf(f, "%s\n", o->mesg);
+ struct tm *lt;
+ time_t t;
+
+ t = o->day;
+ lt = localtime (&t);
+ fprintf (f, "%02u/%02u/%04u [%d] ", lt->tm_mon + 1, lt->tm_mday,
+ 1900 + lt->tm_year, o->id);
+ if (o->note != NULL)
+ fprintf (f, ">%s ", o->note);
+ fprintf (f, "%s\n", o->mesg);
}
/* Load the events from file */
struct event_s *
-event_scan(FILE * f, struct tm start, int id, char *note)
+event_scan (FILE *f, struct tm start, int id, char *note)
{
- struct tm *lt;
- char buf[MESG_MAXSIZE], *nl;
- time_t tstart, t;
-
- t = time(NULL);
- lt = localtime(&t);
-
- /* Read the event description */
- fgets(buf, MESG_MAXSIZE, f);
- nl = strchr(buf, '\n');
- if (nl) {
- *nl = '\0';
- }
- start.tm_hour = 12;
- start.tm_min = 0;
- start.tm_sec = 0;
- start.tm_isdst = -1;
- start.tm_year -= 1900;
- start.tm_mon--;
-
- tstart = mktime(&start);
- if (tstart == -1) {
- fputs(_("FATAL ERROR in event_scan: date error in the event\n"), stderr);
- exit(EXIT_FAILURE);
- }
- return (event_new(buf, note, tstart, id));
+ struct tm *lt;
+ char buf[MESG_MAXSIZE], *nl;
+ time_t tstart, t;
+
+ t = time (NULL);
+ lt = localtime (&t);
+
+ /* Read the event description */
+ fgets (buf, MESG_MAXSIZE, f);
+ nl = strchr (buf, '\n');
+ if (nl)
+ {
+ *nl = '\0';
+ }
+ start.tm_hour = 12;
+ start.tm_min = 0;
+ start.tm_sec = 0;
+ start.tm_isdst = -1;
+ start.tm_year -= 1900;
+ start.tm_mon--;
+
+ tstart = mktime (&start);
+ if (tstart == -1)
+ {
+ fputs (_("FATAL ERROR in event_scan: date error in the event\n"),
+ stderr);
+ exit (EXIT_FAILURE);
+ }
+ return (event_new (buf, note, tstart, id));
}
/* Retrieve an event from the list, given the day and item position. */
struct event_s *
-event_get(long day, int pos)
+event_get (long day, int pos)
{
- struct event_s *o;
- int n;
-
- n = 0;
- for (o = eventlist; o; o = o->next) {
- if (event_inday(o, day)) {
- if (n == pos)
- return o;
- n++;
- }
+ struct event_s *o;
+ int n;
+
+ n = 0;
+ for (o = eventlist; o; o = o->next)
+ {
+ if (event_inday (o, day))
+ {
+ if (n == pos)
+ return o;
+ n++;
}
- /* NOTREACHED */
- fputs(_("FATAL ERROR in event_get: no such item\n"), stderr);
- exit(EXIT_FAILURE);
+ }
+ /* NOTREACHED */
+ fputs (_("FATAL ERROR in event_get: no such item\n"), stderr);
+ exit (EXIT_FAILURE);
}
/* Delete an event from the list. */
-void
-event_delete_bynum(long start, unsigned num, erase_flag_e flag)
+void
+event_delete_bynum (long start, unsigned num, erase_flag_e flag)
{
- unsigned n;
- struct event_s *i, **iptr;
-
- n = 0;
- iptr = &eventlist;
- for (i = eventlist; i != 0; i = i->next) {
- if (event_inday(i, start)) {
- if (n == num) {
- if (flag == ERASE_FORCE_ONLY_NOTE)
- erase_note(&i->note, flag);
- else {
- *iptr = i->next;
- free(i->mesg);
- erase_note(&i->note, flag);
- free(i);
- }
- return;
- }
- n++;
+ unsigned n;
+ struct event_s *i, **iptr;
+
+ n = 0;
+ iptr = &eventlist;
+ for (i = eventlist; i != 0; i = i->next)
+ {
+ if (event_inday (i, start))
+ {
+ if (n == num)
+ {
+ if (flag == ERASE_FORCE_ONLY_NOTE)
+ erase_note (&i->note, flag);
+ else
+ {
+ *iptr = i->next;
+ free (i->mesg);
+ erase_note (&i->note, flag);
+ free (i);
}
- iptr = &i->next;
+ return;
+ }
+ n++;
}
- /* NOTREACHED */
- fputs(_("FATAL ERROR in event_delete_bynum: no such event\n"), stderr);
- exit(EXIT_FAILURE);
+ iptr = &i->next;
+ }
+ /* NOTREACHED */
+ fputs (_("FATAL ERROR in event_delete_bynum: no such event\n"), stderr);
+ exit (EXIT_FAILURE);
}
diff --git a/src/event.h b/src/event.h
index 1de4306..6c6c2d6 100755
--- a/src/event.h
+++ b/src/event.h
@@ -1,4 +1,4 @@
-/* $calcurse: event.h,v 1.5 2008/01/20 10:45:38 culot Exp $ */
+/* $calcurse: event.h,v 1.6 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -32,21 +32,22 @@
#define HRMIN_SIZE 6
#define MESG_MAXSIZE 256
-struct event_s {
- struct event_s *next;
- int id; /* event identifier */
- long day; /* seconds since 1 jan 1970 */
- char *mesg;
- char *note;
+struct event_s
+{
+ struct event_s *next;
+ int id; /* event identifier */
+ long day; /* seconds since 1 jan 1970 */
+ char *mesg;
+ char *note;
};
extern struct event_s *eventlist;
-struct event_s *event_new(char *, char *, long, int);
-unsigned event_inday(struct event_s *, long);
-void event_write(struct event_s *, FILE *);
-struct event_s *event_scan(FILE *, struct tm, int, char *);
-struct event_s *event_get(long, int);
-void event_delete_bynum(long, unsigned, erase_flag_e);
+struct event_s *event_new (char *, char *, long, int);
+unsigned event_inday (struct event_s *, long);
+void event_write (struct event_s *, FILE *);
+struct event_s *event_scan (FILE *, struct tm, int, char *);
+struct event_s *event_get (long, int);
+void event_delete_bynum (long, unsigned, erase_flag_e);
#endif /* CALCURSE_EVENT_H */
diff --git a/src/help.c b/src/help.c
index 5bd7f83..f023d48 100755
--- a/src/help.c
+++ b/src/help.c
@@ -1,8 +1,8 @@
-/* $calcurse: help.c,v 1.21 2008/02/11 21:26:00 culot Exp $ */
+/* $calcurse: help.c,v 1.22 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
- * Copyright (c) 2004-2007 Frederic Culot
+ * Copyright (c) 2004-2008 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -35,61 +35,65 @@
#include "utils.h"
#include "notify.h"
-typedef enum {
- HELP_MAIN,
- HELP_SAVE,
- HELP_EXPORT,
- HELP_DISPLACEMENT,
- HELP_VIEW,
- HELP_TAB,
- HELP_GOTO,
- HELP_DELETE,
- HELP_ADD,
- HELP_EDIT,
- HELP_ENOTE,
- HELP_VNOTE,
- HELP_PRIORITY,
- HELP_REPEAT,
- HELP_FLAG,
- HELP_CONFIG,
- HELP_GENERAL,
- HELP_OTHER,
- HELP_CREDITS,
- HELPSCREENS,
- NOPAGE
-} help_pages_e;
+typedef enum
+{
+ HELP_MAIN,
+ HELP_SAVE,
+ HELP_EXPORT,
+ HELP_DISPLACEMENT,
+ HELP_VIEW,
+ HELP_TAB,
+ HELP_GOTO,
+ HELP_DELETE,
+ HELP_ADD,
+ HELP_EDIT,
+ HELP_ENOTE,
+ HELP_VNOTE,
+ HELP_PRIORITY,
+ HELP_REPEAT,
+ HELP_FLAG,
+ HELP_CONFIG,
+ HELP_GENERAL,
+ HELP_OTHER,
+ HELP_CREDITS,
+ HELPSCREENS,
+ NOPAGE
+}
+help_pages_e;
/* Returns the number of lines in an help text. */
-static int
-get_help_lines(char *text)
+static int
+get_help_lines (char *text)
{
- int i;
- int nl = 0;
-
- for (i = 0; text[i]; i++) {
- if (text[i] == '\n') nl++;
- }
- return nl + 1;
+ int i;
+ int nl = 0;
+
+ for (i = 0; text[i]; i++)
+ {
+ if (text[i] == '\n')
+ nl++;
+ }
+ return (nl + 1);
}
/*
* Write the desired help text inside the help pad, and return the number
* of lines that were written.
*/
-static int
-write_help_pad(window_t *win, help_page_t *hpage)
+static int
+write_help_pad (window_t *win, help_page_t *hpage)
{
- int nl_title = 0;
- int nl_text = 0;
-
- nl_text = get_help_lines(hpage->text);
- nl_title = get_help_lines(hpage->title);
- erase_window_part(win->p, 0, 0, BUFSIZ, win->w);
- custom_apply_attr(win->p, ATTR_HIGHEST);
- mvwprintw(win->p, 0, 0, "%s", hpage->title);
- custom_remove_attr(win->p, ATTR_HIGHEST);
- mvwprintw(win->p, nl_title, 0, "%s", hpage->text);
- return (nl_text + nl_title);
+ int nl_title = 0;
+ int nl_text = 0;
+
+ nl_text = get_help_lines (hpage->text);
+ nl_title = get_help_lines (hpage->title);
+ erase_window_part (win->p, 0, 0, BUFSIZ, win->w);
+ custom_apply_attr (win->p, ATTR_HIGHEST);
+ mvwprintw (win->p, 0, 0, "%s", hpage->title);
+ custom_remove_attr (win->p, ATTR_HIGHEST);
+ mvwprintw (win->p, nl_title, 0, "%s", hpage->text);
+ return (nl_text + nl_title);
}
/*
@@ -97,524 +101,530 @@ write_help_pad(window_t *win, help_page_t *hpage)
* faster.
*/
static void
-help_wins_init(window_t *hwin, window_t *hpad, const int PADOFFSET)
+help_wins_init (window_t *hwin, window_t *hpad, const int PADOFFSET)
{
- char label[BUFSIZ];
-
- hwin->h = (notify_bar()) ? row - 3 : row - 2;
- hwin->p = newwin(hwin->h, col, 0, 0);
- hpad->w = col - 2 * PADOFFSET + 1;
- hpad->p = newpad(BUFSIZ, hpad->w);
- box(hwin->p, 0, 0);
- snprintf(label, BUFSIZ, _("CalCurse %s | help"), VERSION);
- wins_show(hwin->p, label);
+ char label[BUFSIZ];
+
+ hwin->h = (notify_bar ())? row - 3 : row - 2;
+ hwin->p = newwin (hwin->h, col, 0, 0);
+ hpad->w = col - 2 * PADOFFSET + 1;
+ hpad->p = newpad (BUFSIZ, hpad->w);
+ box (hwin->p, 0, 0);
+ snprintf (label, BUFSIZ, _("CalCurse %s | help"), VERSION);
+ wins_show (hwin->p, label);
}
/*
* Delete the existing windows and recreate them with their new
* size and placement.
*/
-static void
-help_wins_reinit(window_t *hwin, window_t *hpad, const int PADOFFSET)
+static void
+help_wins_reinit (window_t *hwin, window_t *hpad, const int PADOFFSET)
{
- delwin(hpad->p);
- delwin(hwin->p);
- wins_get_config();
- help_wins_init(hwin, hpad, PADOFFSET);
+ delwin (hpad->p);
+ delwin (hwin->p);
+ wins_get_config ();
+ help_wins_init (hwin, hpad, PADOFFSET);
}
/* Reset the screen, needed when resizing terminal for example. */
static void
-help_wins_reset(window_t *hwin, window_t *hpad, const int PADOFFSET)
+help_wins_reset (window_t *hwin, window_t *hpad, const int PADOFFSET)
{
- endwin();
- refresh();
- curs_set(0);
- delwin(win[STA].p);
- help_wins_reinit(hwin, hpad, PADOFFSET);
- win[STA].p = newwin(win[STA].h, win[STA].w, win[STA].y, win[STA].x);
- keypad(win[STA].p, TRUE);
- if (notify_bar())
- notify_reinit_bar(win[NOT].h, win[NOT].w, win[NOT].y,
- win[NOT].x);
- status_bar();
- if (notify_bar())
- notify_update_bar();
+ endwin ();
+ refresh ();
+ curs_set (0);
+ delwin (win[STA].p);
+ help_wins_reinit (hwin, hpad, PADOFFSET);
+ win[STA].p = newwin (win[STA].h, win[STA].w, win[STA].y, win[STA].x);
+ keypad (win[STA].p, TRUE);
+ if (notify_bar ())
+ notify_reinit_bar (win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x);
+ status_bar ();
+ if (notify_bar ())
+ notify_update_bar ();
}
/* Association between a key pressed and its corresponding help page. */
static int
-wanted_page(int ch)
+wanted_page (int ch)
{
- int page;
-
- switch (ch) {
-
- case '?':
- page = HELP_MAIN;
- break;
-
- case '!':
- page = HELP_FLAG;
- break;
-
- case CTRL('r'):
- case CTRL('a'):
- case CTRL('t'):
- case CTRL('h'):
- case CTRL('j'):
- case CTRL('k'):
- case CTRL('l'):
- page = HELP_GENERAL;
- break;
-
- case 's':
- page = HELP_SAVE;
- break;
-
- case 'x':
- page = HELP_EXPORT;
- break;
-
- case 'h':
- case 'l':
- case 'j':
- case 'k':
- case 259:
- case 258:
- case 260:
- case 261:
- page = HELP_DISPLACEMENT;
- break;
-
- case 'a':
- page = HELP_ADD;
- break;
-
- case 'g':
- page = HELP_GOTO;
- break;
-
- case 'd':
- page = HELP_DELETE;
- break;
-
- case 'e':
- page = HELP_EDIT;
- break;
-
- case 'n':
- page = HELP_ENOTE;
- break;
-
- case '>':
- page = HELP_VNOTE;
- break;
-
- case 'c':
- page = HELP_CONFIG;
- break;
-
- case 'o':
- page = HELP_OTHER;
- break;
-
- case 'r':
- page = HELP_REPEAT;
- break;
-
- case 'v':
- page = HELP_VIEW;
- break;
-
- case '+':
- case '-':
- page = HELP_PRIORITY;
- break;
-
- case 9:
- page = HELP_TAB;
- break;
-
- case '@':
- page = HELP_CREDITS;
- break;
-
- default:
- page = NOPAGE;
- break;
- }
-
- return (page);
+ int page;
+
+ switch (ch)
+ {
+
+ case '?':
+ page = HELP_MAIN;
+ break;
+
+ case '!':
+ page = HELP_FLAG;
+ break;
+
+ case CTRL ('r'):
+ case CTRL ('a'):
+ case CTRL ('t'):
+ case CTRL ('h'):
+ case CTRL ('j'):
+ case CTRL ('k'):
+ case CTRL ('l'):
+ page = HELP_GENERAL;
+ break;
+
+ case 's':
+ page = HELP_SAVE;
+ break;
+
+ case 'x':
+ page = HELP_EXPORT;
+ break;
+
+ case 'h':
+ case 'l':
+ case 'j':
+ case 'k':
+ case 259:
+ case 258:
+ case 260:
+ case 261:
+ page = HELP_DISPLACEMENT;
+ break;
+
+ case 'a':
+ page = HELP_ADD;
+ break;
+
+ case 'g':
+ page = HELP_GOTO;
+ break;
+
+ case 'd':
+ page = HELP_DELETE;
+ break;
+
+ case 'e':
+ page = HELP_EDIT;
+ break;
+
+ case 'n':
+ page = HELP_ENOTE;
+ break;
+
+ case '>':
+ page = HELP_VNOTE;
+ break;
+
+ case 'c':
+ page = HELP_CONFIG;
+ break;
+
+ case 'o':
+ page = HELP_OTHER;
+ break;
+
+ case 'r':
+ page = HELP_REPEAT;
+ break;
+
+ case 'v':
+ page = HELP_VIEW;
+ break;
+
+ case '+':
+ case '-':
+ page = HELP_PRIORITY;
+ break;
+
+ case 9:
+ page = HELP_TAB;
+ break;
+
+ case '@':
+ page = HELP_CREDITS;
+ break;
+
+ default:
+ page = NOPAGE;
+ break;
+ }
+
+ return (page);
}
/* Draws the help screen */
-void
-help_screen(void)
+void
+help_screen (void)
{
- window_t hwin;
- window_t hpad;
- const int PADOFFSET = 4;
- const int TITLELINES = 3;
- int ch = '?';
- int text_lines;
- int first_line = 0, nl = 0;
- int page, oldpage;
- int need_resize;
- help_page_t hscr[HELPSCREENS];
-
- hscr[HELP_MAIN].title =
- _(" Welcome to Calcurse. This is the main help screen.\n");
- hscr[HELP_MAIN].text =
+ window_t hwin;
+ window_t hpad;
+ const int PADOFFSET = 4;
+ const int TITLELINES = 3;
+ int ch = '?';
+ int text_lines;
+ int first_line = 0, nl = 0;
+ int page, oldpage;
+ int need_resize;
+ help_page_t hscr[HELPSCREENS];
+
+ hscr[HELP_MAIN].title =
+ _(" Welcome to Calcurse. This is the main help screen.\n");
+ hscr[HELP_MAIN].text =
_(" Moving around: Press CTRL-P or CTRL-N to scroll text upward or\n"
- " downward inside help screens, if necessary.\n\n"
- " Exit help: When finished, press 'Q' to exit help and go back\n"
- " to the main Calcurse screen.\n\n"
- " Help topic: At the bottom of this screen you can see a panel\n"
- " with different fields, represented by a letter and\n"
- " a short title. This panel contains all the available\n"
- " actions you can perform when using Calcurse.\n"
- " By pressing one of the letters appearing in this\n"
- " panel, you will be shown a short description of the\n"
- " corresponding action.\n\n"
- " Credits: Press '@' for credits.");
-
- hscr[HELP_SAVE].title = _("Save:\n");
- hscr[HELP_SAVE].text =
+ " downward inside help screens, if necessary.\n\n"
+ " Exit help: When finished, press 'Q' to exit help and go back\n"
+ " to the main Calcurse screen.\n\n"
+ " Help topic: At the bottom of this screen you can see a panel\n"
+ " with different fields, represented by a letter and\n"
+ " a short title. This panel contains all the available\n"
+ " actions you can perform when using Calcurse.\n"
+ " By pressing one of the letters appearing in this\n"
+ " panel, you will be shown a short description of the\n"
+ " corresponding action.\n\n"
+ " Credits: Press '@' for credits.");
+
+ hscr[HELP_SAVE].title = _("Save:\n");
+ hscr[HELP_SAVE].text =
_("Pressing 'S' saves the Calcurse data.\n\n"
- "The data is splitted into three different files which contain :"
- "\n\n"
- " / ~/.calcurse/conf -> the user configuration\n"
- " | (layout, color, general options)\n"
- " | ~/.calcurse/apts -> the data related to the appointments\n"
- " \\ ~/.calcurse/todo -> the data related to the todo list\n"
- "\nIn the config menu, you can choose to save the Calcurse data\n"
- "automatically before quitting.");
-
- hscr[HELP_EXPORT].title = _("Export:\n");
- hscr[HELP_EXPORT].text =
+ "The data is splitted into three different files which contain :"
+ "\n\n"
+ " / ~/.calcurse/conf -> the user configuration\n"
+ " | (layout, color, general options)\n"
+ " | ~/.calcurse/apts -> the data related to the appointments\n"
+ " \\ ~/.calcurse/todo -> the data related to the todo list\n"
+ "\nIn the config menu, you can choose to save the Calcurse data\n"
+ "automatically before quitting.");
+
+ hscr[HELP_EXPORT].title = _("Export:\n");
+ hscr[HELP_EXPORT].text =
_("Pressing 'X' exports the Calcurse data to iCalendar format.\n\n"
- "You first need to specify the file to which the data will be exported.\n"
- "By default, this file is:\n\n"
- " ~/calcurse.ics\n\n"
- "All of the calcurse data are exported, in the following order:\n"
- "events, appointments, todos.\n");
-
- hscr[HELP_DISPLACEMENT].title = _("Displacement keys:\n");
- hscr[HELP_DISPLACEMENT].text =
+ "You first need to specify the file to which the data will be exported.\n"
+ "By default, this file is:\n\n"
+ " ~/calcurse.ics\n\n"
+ "All of the calcurse data are exported, in the following order:\n"
+ "events, appointments, todos.\n");
+
+ hscr[HELP_DISPLACEMENT].title = _("Displacement keys:\n");
+ hscr[HELP_DISPLACEMENT].text =
_("You can use either 'H','J','K','L' or the arrow keys '<','v','^','>'\n"
- "to move into the calendar.\n\n"
- "The following scheme explains how :\n\n"
- " move to previous week\n"
- " K ^ \n"
- " move to previous day H < > L move to next day\n"
- " J v \n"
- " move to next week\n"
- "\nWhen the Appointment or ToDo panel is selected, the up and down keys\n"
- "(respectively K or up arrow, and J or down arrow) allows you to select\n"
- "an item from those lists.");
-
- hscr[HELP_VIEW].title = _("View:\n");
- hscr[HELP_VIEW].text =
+ "to move into the calendar.\n\n"
+ "The following scheme explains how :\n\n"
+ " move to previous week\n"
+ " K ^ \n"
+ " move to previous day H < > L move to next day\n"
+ " J v \n"
+ " move to next week\n"
+ "\nWhen the Appointment or ToDo panel is selected, the up and down keys\n"
+ "(respectively K or up arrow, and J or down arrow) allows you to select\n"
+ "an item from those lists.");
+
+ hscr[HELP_VIEW].title = _("View:\n");
+ hscr[HELP_VIEW].text =
_("Pressing 'V' allows you to view the item you select in either the ToDo\n"
- "or Appointment panel.\n"
- "\nThis is usefull when an event description is longer than the available\n"
- "space to display it. If that is the case, the description will be\n"
- "shortened and its end replaced by '...'. To be able to read the entire\n"
- "description, just press 'V' and a popup window will appear, containing\n"
- "the whole event.\n"
- "\nPress any key to close the popup window and go back to the main\n"
- "Calcurse screen.");
-
- hscr[HELP_TAB].title = _("Tab:\n");
- hscr[HELP_TAB].text =
+ "or Appointment panel.\n"
+ "\nThis is usefull when an event description is longer than the "
+ "available\n space to display it. "
+ "If that is the case, the description will be\n"
+ "shortened and its end replaced by '...'. To be able to read the entire\n"
+ "description, just press 'V' and a popup window will appear, containing\n"
+ "the whole event.\n"
+ "\nPress any key to close the popup window and go back to the main\n"
+ "Calcurse screen.");
+
+ hscr[HELP_TAB].title = _("Tab:\n");
+ hscr[HELP_TAB].text =
_("Pressing 'Tab' allows you to switch between panels.\n"
- "The panel currently in use has its border colorized.\n"
- "\nSome actions are possible only if the right panel is selected.\n"
- "For example, if you want to add a task in the TODO list, you need first\n"
- "to press the 'Tab' key to get the TODO panel selected. Then you can\n"
- "press 'A' to add your item.\n"
- "\nNotice that at the bottom of the screen the list of possible actions\n"
- "change while pressing 'Tab', so you always know what action can be\n"
- "performed on the selected panel.");
-
- hscr[HELP_GOTO].title = _("Goto:\n");
- hscr[HELP_GOTO].text =
+ "The panel currently in use has its border colorized.\n"
+ "\nSome actions are possible only if the right panel is selected.\n"
+ "For example, if you want to add a task in the TODO list, you need first"
+ "\nto press the 'Tab' key to get the TODO panel selected. Then you can\n"
+ "press 'A' to add your item.\n"
+ "\nNotice that at the bottom of the screen the list of possible actions\n"
+ "change while pressing 'Tab', so you always know what action can be\n"
+ "performed on the selected panel.");
+
+ hscr[HELP_GOTO].title = _("Goto:\n");
+ hscr[HELP_GOTO].text =
_("Pressing 'G' allows you to jump to a specific day in the calendar.\n"
- "\nUsing this command, you do not need to travel to that day using\n"
- "the displacement keys inside the calendar panel.\n"
- "If you hit [ENTER] without specifying any date, Calcurse checks the\n"
- "system current date and you will be taken to that date.");
+ "\nUsing this command, you do not need to travel to that day using\n"
+ "the displacement keys inside the calendar panel.\n"
+ "If you hit [ENTER] without specifying any date, Calcurse checks the\n"
+ "system current date and you will be taken to that date.");
- hscr[HELP_DELETE].title = _("Delete:\n");
- hscr[HELP_DELETE].text =
+ hscr[HELP_DELETE].title = _("Delete:\n");
+ hscr[HELP_DELETE].text =
_("Pressing 'D' deletes an element in the ToDo or Appointment list.\n"
- "\nDepending on which panel is selected when you press the delete key,\n"
- "the hilighted item of either the ToDo or Appointment list will be \n"
- "removed from this list.\n"
- "\nIf the item to be deleted is recurrent, you will be asked if you\n"
- "wish to suppress all of the item occurences or just the one you\n"
- "selected.\n"
- "\nIf the general option 'confirm_delete' is set to 'YES', then you will\n"
- "be asked for confirmation before deleting the selected event.\n"
- "Do not forget to save the calendar data to retrieve the modifications\n"
- "next time you launch Calcurse.");
-
- hscr[HELP_ADD].title = _("Add:\n");
- hscr[HELP_ADD].text =
- _("Pressing 'A' allows you to add an item in either the ToDo or Appointment\n"
- "list, depending on which panel is selected when you press 'A'.\n"
- "\nTo enter a new item in the TODO list, you will need first to enter the\n"
- "description of this new item. Then you will be asked to specify the todo\n"
- "priority. This priority is represented by a number going from 9 for the\n"
- "lowest priority, to 1 for the highest one. It is still possible to\n"
- "change the item priority afterwards, by using the '+/-' keys inside the\n"
- "todo panel.\n"
- "\nIf the APPOINTMENT panel is selected while pressing 'A', you will be\n"
- "able to enter either a new appointment or a new all-day long event.\n"
- "To enter a new event, press [ENTER] instead of the item start time, and\n"
- "just fill in the event description.\n"
- "To enter a new appointment to be added in the APPOINTMENT list, you\n"
- "will need to enter successively the time at which the appointment\n"
- "begins, the appointment length (either by specifying the duration in\n"
- "minutes, or the end time in [hh:mm] or [h:mm] format), and the\n"
- "description of the event.\n"
- "\nThe day at which occurs the event or appointment is the day currently\n"
- "selected in the calendar, so you need to move to the desired day before\n"
- "pressing 'A'.\n"
- "\nNotes:\n"
- " o if an appointment lasts for such a long time that it continues\n"
- " on the next days, this event will be indicated on all the\n"
- " corresponding days, and the beginning or ending hour will be\n"
- " replaced by '..' if the event does not begin or end on the day.\n"
- " o if you only press [ENTER] at the APPOINTMENT or TODO event\n"
- " description prompt, without any description, no item will be\n"
- " added.\n"
- " o do not forget to save the calendar data to retrieve the new\n"
- " event next time you launch Calcurse.");
-
- hscr[HELP_EDIT].title = _("Edit Item:\n");
- hscr[HELP_EDIT].text =
+ "\nDepending on which panel is selected when you press the delete key,\n"
+ "the hilighted item of either the ToDo or Appointment list will be \n"
+ "removed from this list.\n"
+ "\nIf the item to be deleted is recurrent, you will be asked if you\n"
+ "wish to suppress all of the item occurences or just the one you\n"
+ "selected.\n"
+ "\nIf the general option 'confirm_delete' is set to 'YES', then you will"
+ "\nbe asked for confirmation before deleting the selected event.\n"
+ "Do not forget to save the calendar data to retrieve the modifications\n"
+ "next time you launch Calcurse.");
+
+ hscr[HELP_ADD].title = _("Add:\n");
+ hscr[HELP_ADD].text =
+ _("Pressing 'A' allows you to add an item in either the ToDo or Appointment"
+ "\nlist, depending on which panel is selected when you press 'A'.\n"
+ "\nTo enter a new item in the TODO list, you will need first to enter the"
+ "\ndescription of this new item. Then you will be asked to specify the "
+ "todo\npriority. This priority is represented by a number going from 9 "
+ "for the\nlowest priority, to 1 for the highest one. It is still "
+ "possible to\nchange the item priority afterwards, by using the '+/-' "
+ "keys inside the\ntodo panel.\n"
+ "\nIf the APPOINTMENT panel is selected while pressing 'A', you will be\n"
+ "able to enter either a new appointment or a new all-day long event.\n"
+ "To enter a new event, press [ENTER] instead of the item start time, "
+ "and\njust fill in the event description.\n"
+ "To enter a new appointment to be added in the APPOINTMENT list, you\n"
+ "will need to enter successively the time at which the appointment\n"
+ "begins, the appointment length (either by specifying the duration in\n"
+ "minutes, or the end time in [hh:mm] or [h:mm] format), and the\n"
+ "description of the event.\n"
+ "\nThe day at which occurs the event or appointment is the day currently"
+ "\nselected in the calendar, so you need to move to the desired day "
+ "before\npressing 'A'.\n" "\nNotes:\n"
+ " o if an appointment lasts for such a long time that it continues\n"
+ " on the next days, this event will be indicated on all the\n"
+ " corresponding days, and the beginning or ending hour will be\n"
+ " replaced by '..' if the event does not begin or end on the day.\n"
+ " o if you only press [ENTER] at the APPOINTMENT or TODO event\n"
+ " description prompt, without any description, no item will be\n"
+ " added.\n"
+ " o do not forget to save the calendar data to retrieve the new\n"
+ " event next time you launch Calcurse.");
+
+ hscr[HELP_EDIT].title = _("Edit Item:\n");
+ hscr[HELP_EDIT].text =
_("Pressing 'E' allows you to edit the item which is currently selected.\n"
- "Depending on the item type (appointment, event, or todo), and if it is\n"
- "repeated or not, you will be asked to choose one of the item properties\n"
- "to modify. An item property is one of the following: the start time, the\n"
- "end time, the description, or the item repetition.\n"
- "Once you have chosen the property you want to modify, you will be shown\n"
- "its actual value, and you will be able to change it as you like.\n"
- "\nNotes:\n"
- " o if you choose to edit the item repetition properties, you will\n"
- " be asked to re-enter all of the repetition characteristics\n"
- " (repetition type, frequence, and ending date). Moreover, the\n"
- " previous data concerning the deleted occurences will be lost.\n"
- " o do not forget to save the calendar data to retrieve the\n"
- " modified properties next time you launch Calcurse.");
-
- hscr[HELP_ENOTE].title = _("EditNote:\n");
- hscr[HELP_ENOTE].text =
+ "Depending on the item type (appointment, event, or todo), and if it is\n"
+ "repeated or not, you will be asked to choose one of the item properties"
+ "\nto modify. An item property is one of the following: the start time, "
+ "the\nend time, the description, or the item repetition.\n"
+ "Once you have chosen the property you want to modify, you will be shown"
+ "\nits actual value, and you will be able to change it as you like.\n"
+ "\nNotes:\n"
+ " o if you choose to edit the item repetition properties, you will\n"
+ " be asked to re-enter all of the repetition characteristics\n"
+ " (repetition type, frequence, and ending date). Moreover, the\n"
+ " previous data concerning the deleted occurences will be lost.\n"
+ " o do not forget to save the calendar data to retrieve the\n"
+ " modified properties next time you launch Calcurse.");
+
+ hscr[HELP_ENOTE].title = _("EditNote:\n");
+ hscr[HELP_ENOTE].text =
_("Pressing 'N' allows you to attach a note to any type of item, or to\n"
- "edit an already existing note.\n"
- "This feature is useful if you do not have enough space to store all\n"
- "of your item description, or if you would like to add sub-tasks to an\n"
- "already existing todo item for example.\n"
- "Before pressing the 'N' key, you first need to highlight the item you\n"
- "want the note to be attached to. Then you will be driven to an\n"
- "external editor to edit your note. This editor is chosen the following\n"
- "way:\n"
- " o if the 'VISUAL' environment variable is set, then this will be\n"
- " the default editor to be called.\n"
- " o if 'VISUAL' is not set, then the 'EDITOR' environment variable\n"
- " will be used as the default editor.\n"
- " o if none of the above environment variables is set, then\n"
- " '/usr/bin/vi' will be used.\n"
- "\nOnce the item note is edited and saved, quit your favorite editor.\n"
- "You will then go back to Calcurse, and the '>' sign will appear in front\n"
- "of the highlighted item, meaning there is a note attached to it.");
-
- hscr[HELP_VNOTE].title = _("ViewNote:\n");
- hscr[HELP_VNOTE].text =
+ "edit an already existing note.\n"
+ "This feature is useful if you do not have enough space to store all\n"
+ "of your item description, or if you would like to add sub-tasks to an\n"
+ "already existing todo item for example.\n"
+ "Before pressing the 'N' key, you first need to highlight the item you\n"
+ "want the note to be attached to. Then you will be driven to an\n"
+ "external editor to edit your note. This editor is chosen the following\n"
+ "way:\n"
+ " o if the 'VISUAL' environment variable is set, then this will be\n"
+ " the default editor to be called.\n"
+ " o if 'VISUAL' is not set, then the 'EDITOR' environment variable\n"
+ " will be used as the default editor.\n"
+ " o if none of the above environment variables is set, then\n"
+ " '/usr/bin/vi' will be used.\n"
+ "\nOnce the item note is edited and saved, quit your favorite editor.\n"
+ "You will then go back to Calcurse, and the '>' sign will appear in front"
+ "\nof the highlighted item, meaning there is a note attached to it.");
+
+ hscr[HELP_VNOTE].title = _("ViewNote:\n");
+ hscr[HELP_VNOTE].text =
_("Pressing the '>' key allows you to view a note which was previously\n"
- "attached to an item (an item which owns a note has a '>' sign in front\n"
- "of it). This command only permits to view the note, not to\n"
- "edit it (to do so, use the 'EditNote' command, using the 'N' key).\n"
- "Once you highlighted an item with a note attached to it, and the 'N' key\n"
- "was pressed, you will be driven to an external pager to view that note.\n"
- "The default pager is chosen the following way:\n"
- " o if the 'PAGER' environment variable is set, then this will be\n"
- " the default viewer to be called.\n"
- " o if the above environment variable is not set, then\n"
- " '/usr/bin/less' will be used.\n"
- "As for the 'N' key, quit the pager and you will be driven back to\n"
- "Calcurse.");
-
- hscr[HELP_PRIORITY].title = _("Priority:\n");
- hscr[HELP_PRIORITY].text =
+ "attached to an item (an item which owns a note has a '>' sign in front\n"
+ "of it). This command only permits to view the note, not to\n"
+ "edit it (to do so, use the 'EditNote' command, using the 'N' key).\n"
+ "Once you highlighted an item with a note attached to it, and the 'N' key"
+ "\nwas pressed, you will be driven to an external pager to view that "
+ "note.\n"
+ "The default pager is chosen the following way:\n"
+ " o if the 'PAGER' environment variable is set, then this will be\n"
+ " the default viewer to be called.\n"
+ " o if the above environment variable is not set, then\n"
+ " '/usr/bin/less' will be used.\n"
+ "As for the 'N' key, quit the pager and you will be driven back to\n"
+ "Calcurse.");
+
+ hscr[HELP_PRIORITY].title = _("Priority:\n");
+ hscr[HELP_PRIORITY].text =
_("Pressing '+' or '-' allows you to change the priority of the currently\n"
- "selected item in the ToDo list. Priorities are represented by the number\n"
- "appearing in front of the todo description. This number goes from 9 for\n"
- "the lowest priority to 1 for the highest priority. Todo having higher\n"
- "priorities are placed first (at the top) inside the todo panel.\n\n"
- "If you want to raise the priority of a todo item, you need to press '+'.\n"
- "In doing so, the number in front of this item will decrease, meaning its\n"
- "priority increases. The item position inside the todo panel may change,\n"
- "depending on the priority of the items above it.\n\n"
- "At the opposite, to lower a todo priority, press '-'. The todo position\n"
- "may also change depending on the priority of the items below.");
-
- hscr[HELP_REPEAT].title = _("Repeat:\n");
- hscr[HELP_REPEAT].text =
+ "selected item in the ToDo list. Priorities are represented by the "
+ "number\nappearing in front of the todo description. This number goes "
+ "from 9 for\nthe lowest priority to 1 for the highest priority. "
+ "Todo having higher\npriorities are placed first (at the top) inside the "
+ "todo panel.\n\n"
+ "If you want to raise the priority of a todo item, you need to press "
+ "'+'.\n"
+ "In doing so, the number in front of this item will decrease, "
+ "meaning its\npriority increases. The item position inside the todo "
+ "panel may change,\ndepending on the priority of the items above it.\n\n"
+ "At the opposite, to lower a todo priority, press '-'. The todo position"
+ "\nmay also change depending on the priority of the items below.");
+
+ hscr[HELP_REPEAT].title = _("Repeat:\n");
+ hscr[HELP_REPEAT].text =
_("Pressing 'R' allows you to repeat an event or an appointment. You must\n"
- "first select the item to be repeated by moving inside the appointment\n"
- "panel. Then pressing 'R' will lead you to a set of three questions, with\n"
- "which you will be able to specify the repetition characteristics:\n\n"
- " o type: you can choose between a daily, weekly, monthly or\n"
- " yearly repetition by pressing 'D', 'W', 'M' or 'Y'\n"
- " respectively.\n\n"
- " o frequence: this indicates how often the item shall be repeated.\n"
- " For example, if you want to remember an anniversary,\n"
- " choose a 'yearly' repetition with a frequence of '1',\n"
- " which means it must be repeated every year. Another\n"
- " example: if you go to the restaurant every two days,\n"
- " choose a 'daily' repetition with a frequence of '2'.\n\n"
- " o ending date: this specifies when to stop repeating the selected\n"
- " event or appointment. To indicate an endless \n"
- " repetition, enter '0' and the item will be repeated\n"
- " forever.\n"
- "\nNotes:\n"
- " o repeated items are marked with an '*' inside the appointment\n"
- " panel, to be easily recognizable from non-repeated ones.\n"
- " o the 'Repeat' and 'Delete' command can be mixed to create\n"
- " complicated configurations, as it is possible to delete only\n"
- " one occurence of a repeated item.");
-
- hscr[HELP_FLAG].title = _("Flag Item:\n");
- hscr[HELP_FLAG].text =
+ "first select the item to be repeated by moving inside the appointment\n"
+ "panel. "
+ "Then pressing 'R' will lead you to a set of three questions, with\n"
+ "which you will be able to specify the repetition characteristics:\n\n"
+ " o type: you can choose between a daily, weekly, monthly or\n"
+ " yearly repetition by pressing 'D', 'W', 'M' or 'Y'\n"
+ " respectively.\n\n"
+ " o frequence: this indicates how often the item shall be repeated.\n"
+ " For example, if you want to remember an anniversary,\n"
+ " choose a 'yearly' repetition with a frequence of '1',\n"
+ " which means it must be repeated every year. Another\n"
+ " example: if you go to the restaurant every two days,\n"
+ " choose a 'daily' repetition with a frequence of '2'.\n\n"
+ " o ending date: this specifies when to stop repeating the selected\n"
+ " event or appointment. To indicate an endless \n"
+ " repetition, enter '0' and the item will be repeated\n"
+ " forever.\n" "\nNotes:\n"
+ " o repeated items are marked with an '*' inside the appointment\n"
+ " panel, to be easily recognizable from non-repeated ones.\n"
+ " o the 'Repeat' and 'Delete' command can be mixed to create\n"
+ " complicated configurations, as it is possible to delete only\n"
+ " one occurence of a repeated item.");
+
+ hscr[HELP_FLAG].title = _("Flag Item:\n");
+ hscr[HELP_FLAG].text =
_("Pressing '!' toggles an appointment's 'important' flag.\n\n"
- "If an item is flagged as important, an exclamation mark appears in front\n"
- "of it, and you will be warned if time gets closed to the appointment\n"
- "start time.\n"
- "To customize the way one gets notified, the configuration submenu lets\n"
- "you choose the command launched to warn user of an upcoming appointment,\n"
- "and how long before it he gets notified.");
-
- hscr[HELP_CONFIG].title = _("Config:\n");
- hscr[HELP_CONFIG].text =
+ "If an item is flagged as important, an exclamation mark appears in front"
+ "\nof it, and you will be warned if time gets closed to the appointment\n"
+ "start time.\n"
+ "To customize the way one gets notified, the configuration submenu lets\n"
+ "you choose the command launched to warn user of an upcoming appointment,"
+ "\nand how long before it he gets notified.");
+
+ hscr[HELP_CONFIG].title = _("Config:\n");
+ hscr[HELP_CONFIG].text =
_("Pressing 'C' leads to the configuration submenu, from which you can\n"
- "select between color, layout, and general options.\n"
- "\nThe color submenu lets you choose the color theme.\n"
- "\nThe layout submenu lets you choose the Calcurse screen layout, in other\n"
- "words where to place the three different panels on the screen.\n"
- "\nThe general options submenu brings a screen with the different options\n"
- "which modifies the way Calcurse interacts with the user.\n"
- "\nThe notify submenu allows you to change the notify-bar settings.\n"
- "\nDo not forget to save the calendar data to retrieve your configuration\n"
- "next time you launch Calcurse.");
-
- hscr[HELP_GENERAL].title = _("General keybindings:\n");
- hscr[HELP_GENERAL].text =
+ "select between color, layout, and general options.\n"
+ "\nThe color submenu lets you choose the color theme.\n"
+ "\nThe layout submenu lets you choose the Calcurse screen layout, in other"
+ "\nwords where to place the three different panels on the screen.\n"
+ "\nThe general options submenu brings a screen with the different options"
+ "\nwhich modifies the way Calcurse interacts with the user.\n"
+ "\nThe notify submenu allows you to change the notify-bar settings.\n"
+ "\nDo not forget to save the calendar data to retrieve your configuration"
+ "\nnext time you launch Calcurse.");
+
+ hscr[HELP_GENERAL].title = _("General keybindings:\n");
+ hscr[HELP_GENERAL].text =
_("Some of the keybindings apply whatever panel is selected. They are\n"
- "called general keybinding and involve the <CONTROL> key, which is\n"
- "represented by the '^' sign in the status bar panel. For example,\n"
- "'^A' means you need to press <CONTROL> and 'A' simultaneously to\n"
- "activate the command. Here is the list of all the general keybindings,\n"
- "together with their corresponding action:\n\n"
- " '^R' : Redraw function -> redraws calcurse panels, this is useful if\n"
- " you resize your terminal screen or when\n"
- " garbage appears inside the display\n"
- " '^A' : Add Appointment -> add an appointment or an event\n"
- " '^T' : Add ToDo -> add a todo\n"
- " '^H' : -1 Day -> move to previous day\n"
- " '^L' : +1 Day -> move to next day\n"
- " '^K' : -1 Week -> move to previous week\n"
- " '^J' : +1 Week -> move to next week");
-
- hscr[HELP_OTHER].title = _("OtherCmd:\n");
- hscr[HELP_OTHER].text =
+ "called general keybinding and involve the <CONTROL> key, which is\n"
+ "represented by the '^' sign in the status bar panel. For example,\n"
+ "'^A' means you need to press <CONTROL> and 'A' simultaneously to\n"
+ "activate the command. Here is the list of all the general keybindings,\n"
+ "together with their corresponding action:\n\n"
+ " '^R' : Redraw function -> redraws calcurse panels, this is useful if\n"
+ " you resize your terminal screen or when\n"
+ " garbage appears inside the display\n"
+ " '^A' : Add Appointment -> add an appointment or an event\n"
+ " '^T' : Add ToDo -> add a todo\n"
+ " '^H' : -1 Day -> move to previous day\n"
+ " '^L' : +1 Day -> move to next day\n"
+ " '^K' : -1 Week -> move to previous week\n"
+ " '^J' : +1 Week -> move to next week");
+
+ hscr[HELP_OTHER].title = _("OtherCmd:\n");
+ hscr[HELP_OTHER].text =
_("Pressing 'O' allows you to switch between status bar help pages.\n"
- "Because the terminal screen is too narrow to display all of the\n"
- "available commands, you need to press 'O' to see the next set of\n"
- "commands together with their keybindings.\n"
- "Once the last status bar page is reached, pressing 'O' another time\n"
- "leads you back to the first page.");
-
- hscr[HELP_CREDITS].title = _("Calcurse - text-based organizer");
- hscr[HELP_CREDITS].text =
- _("Copyright (c) 2004-2007 Frederic Culot\n"
- "\n"
- "This program is free software; you can redistribute it and/or modify\n"
- "it under the terms of the GNU General Public License as published by\n"
- "the Free Software Foundation; either version 2 of the License, or\n"
- "(at your option) any later version.\n"
- "\nThis program is distributed in the hope that it will be useful,\n"
- "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
- "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
- "GNU General Public License for more details.\n"
- "\n\n"
- "Send your feedback or comments to : calcurse@culot.org\n"
- "Calcurse home page : http://culot.org/calcurse");
-
- need_resize = 0;
- page = oldpage = HELP_MAIN;
- help_wins_init(&hwin, &hpad, PADOFFSET);
-
- /* Display the help screen related to user input. */
- while ( ch != 'q' ) {
- erase_window_part(hwin.p, 1, TITLELINES, col - 2, hwin.h - 2);
-
- switch (ch) {
-
- case KEY_RESIZE:
- help_wins_reset(&hwin, &hpad, PADOFFSET);
- first_line = 0;
- nl = write_help_pad(&hpad, &hscr[oldpage]);
- need_resize = 1;
- break;
-
- case CTRL('n') :
- if (nl > (first_line + hwin.h - (PADOFFSET + 1)))
- first_line++;
- break;
-
- case CTRL('p') :
- if (first_line > 0)
- first_line--;
- break;
-
- default:
- page = wanted_page(ch);
- if (page != NOPAGE) {
- first_line = 0;
- nl = write_help_pad(&hpad, &hscr[page]);
- oldpage = page;
- }
- break;
- }
-
- /* Draw the scrollbar if necessary. */
- text_lines = hwin.h - (PADOFFSET + 1);
- if (nl > text_lines) {
- float ratio = ((float) text_lines + 1) / ((float) nl);
- int sbar_length = (int) (ratio * text_lines);
- int highend = (int) (ratio * first_line);
- int sbar_top = highend + TITLELINES + 1;
-
- if ((sbar_top + sbar_length) > hwin.h - 1)
- sbar_length = hwin.h - 1 - sbar_top;
- draw_scrollbar(hwin.p, sbar_top, col - 2,
- sbar_length, TITLELINES + 1, hwin.h - 1, true);
- }
-
- wmove(win[STA].p, 0, 0);
- wnoutrefresh(hwin.p);
- pnoutrefresh(hpad.p, first_line, 0, PADOFFSET, PADOFFSET,
- hwin.h - 2, col - PADOFFSET);
- doupdate();
- ch = wgetch(win[STA].p);
- ch = tolower(ch);
+ "Because the terminal screen is too narrow to display all of the\n"
+ "available commands, you need to press 'O' to see the next set of\n"
+ "commands together with their keybindings.\n"
+ "Once the last status bar page is reached, pressing 'O' another time\n"
+ "leads you back to the first page.");
+
+ hscr[HELP_CREDITS].title = _("Calcurse - text-based organizer");
+ hscr[HELP_CREDITS].text =
+ _("Copyright (c) 2004-2008 Frederic Culot\n"
+ "\n"
+ "This program is free software; you can redistribute it and/or modify\n"
+ "it under the terms of the GNU General Public License as published by\n"
+ "the Free Software Foundation; either version 2 of the License, or\n"
+ "(at your option) any later version.\n"
+ "\nThis program is distributed in the hope that it will be useful,\n"
+ "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
+ "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
+ "GNU General Public License for more details.\n"
+ "\n\n"
+ "Send your feedback or comments to : calcurse@culot.org\n"
+ "Calcurse home page : http://culot.org/calcurse");
+
+ need_resize = 0;
+ page = oldpage = HELP_MAIN;
+ help_wins_init (&hwin, &hpad, PADOFFSET);
+
+ /* Display the help screen related to user input. */
+ while (ch != 'q')
+ {
+ erase_window_part (hwin.p, 1, TITLELINES, col - 2, hwin.h - 2);
+
+ switch (ch)
+ {
+ case KEY_RESIZE:
+ help_wins_reset (&hwin, &hpad, PADOFFSET);
+ first_line = 0;
+ nl = write_help_pad (&hpad, &hscr[oldpage]);
+ need_resize = 1;
+ break;
+
+ case CTRL ('n'):
+ if (nl > (first_line + hwin.h - (PADOFFSET + 1)))
+ first_line++;
+ break;
+
+ case CTRL ('p'):
+ if (first_line > 0)
+ first_line--;
+ break;
+
+ default:
+ page = wanted_page (ch);
+ if (page != NOPAGE)
+ {
+ first_line = 0;
+ nl = write_help_pad (&hpad, &hscr[page]);
+ oldpage = page;
+ }
+ break;
+ }
+
+ /* Draw the scrollbar if necessary. */
+ text_lines = hwin.h - (PADOFFSET + 1);
+ if (nl > text_lines)
+ {
+ float ratio = ((float) text_lines + 1) / ((float) nl);
+ int sbar_length = (int) (ratio * text_lines);
+ int highend = (int) (ratio * first_line);
+ int sbar_top = highend + TITLELINES + 1;
+
+ if ((sbar_top + sbar_length) > hwin.h - 1)
+ sbar_length = hwin.h - 1 - sbar_top;
+ draw_scrollbar (hwin.p, sbar_top, col - 2,
+ sbar_length, TITLELINES + 1, hwin.h - 1, true);
}
- delwin(hpad.p);
- delwin(hwin.p);
- if (need_resize)
- wins_reset();
+ wmove (win[STA].p, 0, 0);
+ wnoutrefresh (hwin.p);
+ pnoutrefresh (hpad.p, first_line, 0, PADOFFSET, PADOFFSET,
+ hwin.h - 2, col - PADOFFSET);
+ doupdate ();
+ ch = wgetch (win[STA].p);
+ ch = tolower (ch);
+ }
+
+ delwin (hpad.p);
+ delwin (hwin.p);
+ if (need_resize)
+ wins_reset ();
}
diff --git a/src/help.h b/src/help.h
index df4fc0a..2753137 100755
--- a/src/help.h
+++ b/src/help.h
@@ -1,4 +1,4 @@
-/* $calcurse: help.h,v 1.4 2007/07/28 13:11:42 culot Exp $ */
+/* $calcurse: help.h,v 1.5 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -27,11 +27,13 @@
#ifndef CALCURSE_HELP_H
#define CALCURSE_HELP_H
-typedef struct {
- char *title;
- char *text;
-} help_page_t;
+typedef struct
+{
+ char *title;
+ char *text;
+}
+help_page_t;
-void help_screen(void);
+void help_screen (void);
#endif /* CALCURSE_HELP_H */
diff --git a/src/i18n.h b/src/i18n.h
index 454a084..082a7c7 100755
--- a/src/i18n.h
+++ b/src/i18n.h
@@ -1,4 +1,4 @@
-/* $calcurse: i18n.h,v 1.1 2006/07/31 21:00:03 culot Exp $ */
+/* $calcurse: i18n.h,v 1.2 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -32,23 +32,23 @@
#endif /* HAVE_CONFIG_H */
#if ENABLE_NLS
- #include <libintl.h>
- #undef _
- #define _(String) gettext(String)
- #ifdef gettext_noop
- #define N_(String) gettext_noop(String)
- #else
- #define N_(String) (String)
- #endif
+#include <libintl.h>
+#undef _
+#define _(String) gettext(String)
+#ifdef gettext_noop
+#define N_(String) gettext_noop(String)
+#else
+#define N_(String) (String)
+#endif
#else /* NLS disabled */
- #define _(String) (String)
- #define N_(String) (String)
- #define textdomain(String) (String)
- #define gettext(String) (String)
- #define dgettext(String) (String)
- #define dcgettext(String) (String)
- #define bindtextdomain(String) (String)
- #define bind_textdomain_codeset(Domain,Codeset) (Codeset)
+#define _(String) (String)
+#define N_(String) (String)
+#define textdomain(String) (String)
+#define gettext(String) (String)
+#define dgettext(String) (String)
+#define dcgettext(String) (String)
+#define bindtextdomain(String) (String)
+#define bind_textdomain_codeset(Domain,Codeset) (Codeset)
#endif /* ENABLE_NLS */
#endif /* CALCURSE_I18N_H */
diff --git a/src/io.c b/src/io.c
index 2396cc7..07efe6f 100755
--- a/src/io.c
+++ b/src/io.c
@@ -1,4 +1,4 @@
-/* $calcurse: io.c,v 1.28 2008/04/09 20:38:29 culot Exp $ */
+/* $calcurse: io.c,v 1.29 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -40,276 +40,291 @@
#include "apoint.h"
#include "io.h"
-typedef enum {
- PROGRESS_BAR_SAVE,
- PROGRESS_BAR_LOAD,
- PROGRESS_BAR_EXPORT
-} progress_bar_t;
+typedef enum
+{
+ PROGRESS_BAR_SAVE,
+ PROGRESS_BAR_LOAD,
+ PROGRESS_BAR_EXPORT
+}
+progress_bar_t;
/* Draw a progress bar while saving, loading or exporting data. */
-static void
-progress_bar(progress_bar_t type, int progress)
+static void
+progress_bar (progress_bar_t type, int progress)
{
#define SLEEPTIME 125000
#define STEPS 3
#define LABELENGTH 15
- int i, step;
- char *mesg_sav = _("Saving...");
- char *mesg_load = _("Loading...");
- char *mesg_export = _("Exporting...");
- char *barchar = "|";
- char file[STEPS][LABELENGTH] = {
- "[ conf ]",
- "[ todo ]",
- "[ apts ]"
- };
- char data[STEPS][LABELENGTH] = {
- "[ events ]",
- "[appointments]",
- "[ todo ]"
- };
- int ipos = LABELENGTH + 2;
- int epos[STEPS];
-
- /* progress bar length init. */
- ipos = LABELENGTH + 2;
- step = floor(col / (STEPS + 1));
- for (i = 0; i < STEPS - 1; i++)
- epos[i] = (i + 2) * step;
- epos[STEPS - 1] = col - 2;
-
- switch (type) {
- case PROGRESS_BAR_SAVE:
- status_mesg(mesg_sav, file[progress]);
- break;
- case PROGRESS_BAR_LOAD:
- status_mesg(mesg_load, file[progress]);
- break;
- case PROGRESS_BAR_EXPORT:
- status_mesg(mesg_export, data[progress]);
- break;
- }
-
- /* Draw the progress bar. */
- mvwprintw(win[STA].p, 1, ipos, barchar);
- mvwprintw(win[STA].p, 1, epos[STEPS - 1], barchar);
- custom_apply_attr(win[STA].p, ATTR_HIGHEST);
- for (i = ipos + 1; i < epos[progress]; i++)
- mvwaddch(win[STA].p, 1, i, ' ' | A_REVERSE);
- custom_remove_attr(win[STA].p, ATTR_HIGHEST);
- wmove(win[STA].p, 0, 0);
- wrefresh(win[STA].p);
- usleep(SLEEPTIME);
+ int i, step;
+ char *mesg_sav = _("Saving...");
+ char *mesg_load = _("Loading...");
+ char *mesg_export = _("Exporting...");
+ char *barchar = "|";
+ char file[STEPS][LABELENGTH] = {
+ "[ conf ]",
+ "[ todo ]",
+ "[ apts ]"
+ };
+ char data[STEPS][LABELENGTH] = {
+ "[ events ]",
+ "[appointments]",
+ "[ todo ]"
+ };
+ int ipos = LABELENGTH + 2;
+ int epos[STEPS];
+
+ /* progress bar length init. */
+ ipos = LABELENGTH + 2;
+ step = floor (col / (STEPS + 1));
+ for (i = 0; i < STEPS - 1; i++)
+ epos[i] = (i + 2) * step;
+ epos[STEPS - 1] = col - 2;
+
+ switch (type)
+ {
+ case PROGRESS_BAR_SAVE:
+ status_mesg (mesg_sav, file[progress]);
+ break;
+ case PROGRESS_BAR_LOAD:
+ status_mesg (mesg_load, file[progress]);
+ break;
+ case PROGRESS_BAR_EXPORT:
+ status_mesg (mesg_export, data[progress]);
+ break;
+ }
+
+ /* Draw the progress bar. */
+ mvwprintw (win[STA].p, 1, ipos, barchar);
+ mvwprintw (win[STA].p, 1, epos[STEPS - 1], barchar);
+ custom_apply_attr (win[STA].p, ATTR_HIGHEST);
+ for (i = ipos + 1; i < epos[progress]; i++)
+ mvwaddch (win[STA].p, 1, i, ' ' | A_REVERSE);
+ custom_remove_attr (win[STA].p, ATTR_HIGHEST);
+ wmove (win[STA].p, 0, 0);
+ wrefresh (win[STA].p);
+ usleep (SLEEPTIME);
}
/* Return the recurrence type to dump in iCal format. */
static char *
-io_recur_type(int type)
+io_recur_type (int type)
{
- char *recur_type[RECUR_TYPES] =
- { "", "DAILY", "WEEKLY", "MONTHLY", "YEARLY" };
-
- return (recur_type[type]);
-}
+ char *recur_type[RECUR_TYPES] =
+ { "", "DAILY", "WEEKLY", "MONTHLY", "YEARLY" };
+
+ return (recur_type[type]);
+}
/* Ask user for a file name to export data to. */
static FILE *
-io_get_export_stream(void)
+io_get_export_stream (void)
{
- FILE *stream;
- char *home, *stream_name;
- char *question =
- _("Choose the file used to export calcurse data:");
- char *wrong_name =
- _("The file cannot be accessed, please enter another file name.");
- char *press_enter =
- _("Press [ENTER] to continue.");
- int cancel;
-
- stream = NULL;
- stream_name = (char *)malloc(BUFSIZ);
- if ((home = getenv("HOME")) != NULL)
- snprintf(stream_name, BUFSIZ, "%s/calcurse.ics", home);
- else
- snprintf(stream_name, BUFSIZ, "/tmp/calcurse.ics");
-
- while (stream == NULL) {
- status_mesg(question, "");
- cancel = updatestring(win[STA].p, &stream_name, 0, 1);
- if (cancel) {
- free(stream_name);
- return (NULL);
- }
- stream = fopen(stream_name, "w");
- if (stream == NULL) {
- status_mesg(wrong_name, press_enter);
- wgetch(win[STA].p);
- }
+ FILE *stream;
+ char *home, *stream_name;
+ char *question = _("Choose the file used to export calcurse data:");
+ char *wrong_name =
+ _("The file cannot be accessed, please enter another file name.");
+ char *press_enter = _("Press [ENTER] to continue.");
+ int cancel;
+
+ stream = NULL;
+ stream_name = (char *) malloc (BUFSIZ);
+ if ((home = getenv ("HOME")) != NULL)
+ snprintf (stream_name, BUFSIZ, "%s/calcurse.ics", home);
+ else
+ snprintf (stream_name, BUFSIZ, "/tmp/calcurse.ics");
+
+ while (stream == NULL)
+ {
+ status_mesg (question, "");
+ cancel = updatestring (win[STA].p, &stream_name, 0, 1);
+ if (cancel)
+ {
+ free (stream_name);
+ return (NULL);
}
- free(stream_name);
-
- return (stream);
-}
+ stream = fopen (stream_name, "w");
+ if (stream == NULL)
+ {
+ status_mesg (wrong_name, press_enter);
+ wgetch (win[STA].p);
+ }
+ }
+ free (stream_name);
+
+ return (stream);
+}
/* iCal alarm notification. */
static void
-io_export_valarm(FILE *stream)
+io_export_valarm (FILE *stream)
{
- fprintf(stream, "BEGIN:VALARM\n");
- pthread_mutex_lock(&nbar->mutex);
- fprintf(stream, "TRIGGER:-P%dS\n", nbar->cntdwn);
- pthread_mutex_unlock(&nbar->mutex);
- fprintf(stream, "ACTION:DISPLAY\n");
- fprintf(stream, "END:VALARM\n");
+ fprintf (stream, "BEGIN:VALARM\n");
+ pthread_mutex_lock (&nbar->mutex);
+ fprintf (stream, "TRIGGER:-P%dS\n", nbar->cntdwn);
+ pthread_mutex_unlock (&nbar->mutex);
+ fprintf (stream, "ACTION:DISPLAY\n");
+ fprintf (stream, "END:VALARM\n");
}
/* Export header. */
static void
-io_export_header(FILE *stream)
+io_export_header (FILE *stream)
{
- fprintf(stream, "BEGIN:VCALENDAR\n");
- fprintf(stream, "PRODID:-//calcurse//NONSGML v%s//EN\n",
- VERSION);
- fprintf(stream, "VERSION:2.0\n");
+ fprintf (stream, "BEGIN:VCALENDAR\n");
+ fprintf (stream, "PRODID:-//calcurse//NONSGML v%s//EN\n", VERSION);
+ fprintf (stream, "VERSION:2.0\n");
}
/* Export footer. */
static void
-io_export_footer(FILE *stream)
+io_export_footer (FILE *stream)
{
- fprintf(stream, "END:VCALENDAR\n");
+ fprintf (stream, "END:VCALENDAR\n");
}
/* Export recurrent events. */
static void
-io_export_recur_events(FILE *stream)
+io_export_recur_events (FILE *stream)
{
- struct recur_event_s *i;
- struct days_s *day;
- char ical_date[BUFSIZ];
-
- for (i = recur_elist; i != 0; i = i->next) {
- date_sec2ical_date(i->day, ical_date);
- fprintf(stream, "BEGIN:VEVENT\n");
- fprintf(stream, "DTSTART:%s\n", ical_date);
- fprintf(stream, "RRULE:FREQ=%s;INTERVAL=%d",
- io_recur_type(i->rpt->type), i->rpt->freq);
-
- if (i->rpt->until != 0) {
- date_sec2ical_date(i->rpt->until, ical_date);
- fprintf(stream, ";UNTIL=%s\n", ical_date);
- } else
- fprintf(stream, "\n");
-
- if (i->exc != NULL) {
- date_sec2ical_date(i->exc->st, ical_date);
- fprintf(stream, "EXDATE:%s", ical_date);
- for (day = i->exc->next; day; day = day->next) {
- date_sec2ical_date(day->st, ical_date);
- fprintf(stream, ",%s", ical_date);
- }
- fprintf(stream, "\n");
- }
-
- fprintf(stream, "SUMMARY:%s\n", i->mesg);
- fprintf(stream, "END:VEVENT\n");
+ struct recur_event_s *i;
+ struct days_s *day;
+ char ical_date[BUFSIZ];
+
+ for (i = recur_elist; i != 0; i = i->next)
+ {
+ date_sec2ical_date (i->day, ical_date);
+ fprintf (stream, "BEGIN:VEVENT\n");
+ fprintf (stream, "DTSTART:%s\n", ical_date);
+ fprintf (stream, "RRULE:FREQ=%s;INTERVAL=%d",
+ io_recur_type (i->rpt->type), i->rpt->freq);
+
+ if (i->rpt->until != 0)
+ {
+ date_sec2ical_date (i->rpt->until, ical_date);
+ fprintf (stream, ";UNTIL=%s\n", ical_date);
+ }
+ else
+ fprintf (stream, "\n");
+
+ if (i->exc != NULL)
+ {
+ date_sec2ical_date (i->exc->st, ical_date);
+ fprintf (stream, "EXDATE:%s", ical_date);
+ for (day = i->exc->next; day; day = day->next)
+ {
+ date_sec2ical_date (day->st, ical_date);
+ fprintf (stream, ",%s", ical_date);
+ }
+ fprintf (stream, "\n");
}
+
+ fprintf (stream, "SUMMARY:%s\n", i->mesg);
+ fprintf (stream, "END:VEVENT\n");
+ }
}
/* Export events. */
static void
-io_export_events(FILE *stream)
+io_export_events (FILE *stream)
{
- struct event_s *i;
- char ical_date[BUFSIZ];
-
- for (i = eventlist; i != 0; i = i->next) {
- date_sec2ical_date(i->day, ical_date);
- fprintf(stream, "BEGIN:VEVENT\n");
- fprintf(stream, "DTSTART:%s\n", ical_date);
- fprintf(stream, "SUMMARY:%s\n", i->mesg);
- fprintf(stream, "END:VEVENT\n");
- }
+ struct event_s *i;
+ char ical_date[BUFSIZ];
+
+ for (i = eventlist; i != 0; i = i->next)
+ {
+ date_sec2ical_date (i->day, ical_date);
+ fprintf (stream, "BEGIN:VEVENT\n");
+ fprintf (stream, "DTSTART:%s\n", ical_date);
+ fprintf (stream, "SUMMARY:%s\n", i->mesg);
+ fprintf (stream, "END:VEVENT\n");
+ }
}
/* Export recurrent appointments. */
static void
-io_export_recur_apoints(FILE *stream)
+io_export_recur_apoints (FILE *stream)
{
- recur_apoint_llist_node_t *i;
- struct days_s *day;
- char ical_datetime[BUFSIZ];
- char ical_date[BUFSIZ];
-
- pthread_mutex_lock(&(recur_alist_p->mutex));
- for (i = recur_alist_p->root; i != 0; i = i->next) {
- date_sec2ical_datetime(i->start, ical_datetime);
- fprintf(stream, "BEGIN:VEVENT\n");
- fprintf(stream, "DTSTART:%s\n", ical_datetime);
- fprintf(stream, "DURATION:P%ldS\n", i->dur);
- fprintf(stream, "RRULE:FREQ=%s;INTERVAL=%d",
- io_recur_type(i->rpt->type), i->rpt->freq);
-
- if (i->rpt->until != 0) {
- date_sec2ical_date(i->rpt->until + HOURINSEC,
- ical_date);
- fprintf(stream, ";UNTIL=%s\n", ical_date);
- } else
- fprintf(stream, "\n");
-
- if (i->exc != NULL) {
- date_sec2ical_date(i->exc->st, ical_date);
- fprintf(stream, "EXDATE:%s", ical_date);
- for (day = i->exc->next; day; day = day->next) {
- date_sec2ical_date(day->st, ical_date);
- fprintf(stream, ",%s", ical_date);
- }
- fprintf(stream, "\n");
- }
-
- fprintf(stream, "SUMMARY:%s\n", i->mesg);
- if (i->state & APOINT_NOTIFY)
- io_export_valarm(stream);
- fprintf(stream, "END:VEVENT\n");
+ recur_apoint_llist_node_t *i;
+ struct days_s *day;
+ char ical_datetime[BUFSIZ];
+ char ical_date[BUFSIZ];
+
+ pthread_mutex_lock (&(recur_alist_p->mutex));
+ for (i = recur_alist_p->root; i != 0; i = i->next)
+ {
+ date_sec2ical_datetime (i->start, ical_datetime);
+ fprintf (stream, "BEGIN:VEVENT\n");
+ fprintf (stream, "DTSTART:%s\n", ical_datetime);
+ fprintf (stream, "DURATION:P%ldS\n", i->dur);
+ fprintf (stream, "RRULE:FREQ=%s;INTERVAL=%d",
+ io_recur_type (i->rpt->type), i->rpt->freq);
+
+ if (i->rpt->until != 0)
+ {
+ date_sec2ical_date (i->rpt->until + HOURINSEC, ical_date);
+ fprintf (stream, ";UNTIL=%s\n", ical_date);
}
- pthread_mutex_unlock(&(recur_alist_p->mutex));
+ else
+ fprintf (stream, "\n");
+
+ if (i->exc != NULL)
+ {
+ date_sec2ical_date (i->exc->st, ical_date);
+ fprintf (stream, "EXDATE:%s", ical_date);
+ for (day = i->exc->next; day; day = day->next)
+ {
+ date_sec2ical_date (day->st, ical_date);
+ fprintf (stream, ",%s", ical_date);
+ }
+ fprintf (stream, "\n");
+ }
+
+ fprintf (stream, "SUMMARY:%s\n", i->mesg);
+ if (i->state & APOINT_NOTIFY)
+ io_export_valarm (stream);
+ fprintf (stream, "END:VEVENT\n");
+ }
+ pthread_mutex_unlock (&(recur_alist_p->mutex));
}
/* Export appointments. */
static void
-io_export_apoints(FILE *stream)
+io_export_apoints (FILE *stream)
{
- apoint_llist_node_t *i;
- char ical_datetime[BUFSIZ];
-
- pthread_mutex_lock(&(alist_p->mutex));
- for (i = alist_p->root; i != 0; i = i->next) {
- date_sec2ical_datetime(i->start, ical_datetime);
- fprintf(stream, "BEGIN:VEVENT\n");
- fprintf(stream, "DTSTART:%s\n", ical_datetime);
- fprintf(stream, "DURATION:P%ldS\n", i->dur);
- fprintf(stream, "SUMMARY:%s\n", i->mesg);
- if (i->state & APOINT_NOTIFY)
- io_export_valarm(stream);
- fprintf(stream, "END:VEVENT\n");
- }
- pthread_mutex_unlock(&(alist_p->mutex));
+ apoint_llist_node_t *i;
+ char ical_datetime[BUFSIZ];
+
+ pthread_mutex_lock (&(alist_p->mutex));
+ for (i = alist_p->root; i != 0; i = i->next)
+ {
+ date_sec2ical_datetime (i->start, ical_datetime);
+ fprintf (stream, "BEGIN:VEVENT\n");
+ fprintf (stream, "DTSTART:%s\n", ical_datetime);
+ fprintf (stream, "DURATION:P%ldS\n", i->dur);
+ fprintf (stream, "SUMMARY:%s\n", i->mesg);
+ if (i->state & APOINT_NOTIFY)
+ io_export_valarm (stream);
+ fprintf (stream, "END:VEVENT\n");
+ }
+ pthread_mutex_unlock (&(alist_p->mutex));
}
/* Export todo items. */
static void
-io_export_todo(FILE *stream)
+io_export_todo (FILE *stream)
{
- struct todo_s *i;
-
- for (i = todolist; i != 0; i = i->next) {
- fprintf(stream, "BEGIN:VTODO\n");
- fprintf(stream, "PRIORITY:%d\n", i->id);
- fprintf(stream, "SUMMARY:%s\n", i->mesg);
- fprintf(stream, "END:VTODO\n");
- }
+ struct todo_s *i;
+
+ for (i = todolist; i != 0; i = i->next)
+ {
+ fprintf (stream, "BEGIN:VTODO\n");
+ fprintf (stream, "PRIORITY:%d\n", i->id);
+ fprintf (stream, "SUMMARY:%s\n", i->mesg);
+ fprintf (stream, "END:VTODO\n");
+ }
}
/*
@@ -319,475 +334,550 @@ io_export_todo(FILE *stream)
* is created.
*/
void
-io_init(char *cfile)
+io_init (char *cfile)
{
- FILE *data_file;
- char *home;
- char apts_file[BUFSIZ] = "";
- int ch;
-
- home = getenv("HOME");
- if (home == NULL) {
- home = ".";
- }
- snprintf(path_dir, BUFSIZ, "%s/" DIR_NAME, home);
- snprintf(path_todo, BUFSIZ, "%s/" TODO_PATH, home);
- snprintf(path_conf, BUFSIZ, "%s/" CONF_PATH, home);
- snprintf(path_notes, BUFSIZ, "%s/" NOTES_DIR, home);
- if (cfile == NULL) {
- snprintf(path_apts, BUFSIZ, "%s/" APTS_PATH, home);
- } else {
- snprintf(apts_file, BUFSIZ, "%s", cfile);
- strncpy(path_apts, apts_file, BUFSIZ);
- /* check if the file exists, otherwise create it */
- data_file = fopen(path_apts, "r");
- if (data_file == NULL) {
- printf(_("%s does not exist, create it now [y or n] ? "), path_apts);
- ch = getchar();
- switch (ch) {
- case 'N':
- case 'n':
- printf(_("aborting...\n"));
- exit(EXIT_FAILURE);
- break;
-
- case 'Y':
- case 'y':
- data_file = fopen(path_apts, "w");
- if (data_file == NULL) {
- perror(path_apts);
- exit(EXIT_FAILURE);
- } else {
- printf(_("%s successfully created\n"),path_apts);
- printf(_("starting interactive mode...\n"));
- }
- break;
-
- default:
- printf(_("aborting...\n"));
- exit(EXIT_FAILURE);
- break;
- }
+ FILE *data_file;
+ char *home;
+ char apts_file[BUFSIZ] = "";
+ int ch;
+
+ home = getenv ("HOME");
+ if (home == NULL)
+ {
+ home = ".";
+ }
+ snprintf (path_dir, BUFSIZ, "%s/" DIR_NAME, home);
+ snprintf (path_todo, BUFSIZ, "%s/" TODO_PATH, home);
+ snprintf (path_conf, BUFSIZ, "%s/" CONF_PATH, home);
+ snprintf (path_notes, BUFSIZ, "%s/" NOTES_DIR, home);
+ if (cfile == NULL)
+ {
+ snprintf (path_apts, BUFSIZ, "%s/" APTS_PATH, home);
+ }
+ else
+ {
+ snprintf (apts_file, BUFSIZ, "%s", cfile);
+ strncpy (path_apts, apts_file, BUFSIZ);
+ /* check if the file exists, otherwise create it */
+ data_file = fopen (path_apts, "r");
+ if (data_file == NULL)
+ {
+ printf (_("%s does not exist, create it now [y or n] ? "), path_apts);
+ ch = getchar ();
+ switch (ch)
+ {
+ case 'N':
+ case 'n':
+ printf (_("aborting...\n"));
+ exit (EXIT_FAILURE);
+ break;
+
+ case 'Y':
+ case 'y':
+ data_file = fopen (path_apts, "w");
+ if (data_file == NULL)
+ {
+ perror (path_apts);
+ exit (EXIT_FAILURE);
+ }
+ else
+ {
+ printf (_("%s successfully created\n"), path_apts);
+ printf (_("starting interactive mode...\n"));
}
- fclose(data_file);
+ break;
+
+ default:
+ printf (_("aborting...\n"));
+ exit (EXIT_FAILURE);
+ break;
+ }
}
+ fclose (data_file);
+ }
}
/* get data from file */
-void
-io_extract_data(char *dst_data, const char *org, int len)
+void
+io_extract_data (char *dst_data, const char *org, int len)
{
- for (;;) {
- if (*org == '\n' || *org == '\0')
- break;
- *dst_data++ = *org++;
- }
- *dst_data = '\0';
+ for (;;)
+ {
+ if (*org == '\n' || *org == '\0')
+ break;
+ *dst_data++ = *org++;
+ }
+ *dst_data = '\0';
}
/* Save the calendar data */
void
-io_save_cal(conf_t *conf)
+io_save_cal (conf_t *conf)
{
- FILE *data_file;
- struct event_s *k;
- apoint_llist_node_t *j;
- struct todo_s *i;
- char theme_name[BUFSIZ];
- char *access_pb = _("Problems accessing data file ...");
- char *config_txt =
- "#\n# Calcurse configuration file\n#\n# This file sets the configuration options used by Calcurse. These\n# options are usually set from within Calcurse. A line beginning with \n# a space or tab is considered to be a continuation of the previous line.\n# For a variable to be unset its value must be blank.\n# To set a variable to the empty string its value should be \"\".\n# Lines beginning with \"#\" are comments, and ignored by Calcurse.\n";
- char *save_success = _("The data files were successfully saved");
- char *enter = _("Press [ENTER] to continue");
- bool show_bar = false;
-
- if (!conf->skip_progress_bar)
- show_bar = true;
-
- /* Save the user configuration. */
-
- if (show_bar)
- progress_bar(PROGRESS_BAR_SAVE, 0);
- data_file = fopen(path_conf, "w");
- if (data_file == (FILE *) 0)
- status_mesg(access_pb, "");
- else {
- custom_color_theme_name(theme_name);
-
- fprintf(data_file, "%s\n", config_txt);
-
- fprintf(data_file,
- "# If this option is set to yes, automatic save is done when quitting\n");
- fprintf(data_file, "auto_save=\n");
- fprintf(data_file, "%s\n", (conf->auto_save) ? "yes" : "no");
-
- fprintf(data_file,
- "\n# If this option is set to yes, confirmation is required before quitting\n");
- fprintf(data_file, "confirm_quit=\n");
- fprintf(data_file, "%s\n", (conf->confirm_quit) ? "yes" : "no");
-
- fprintf(data_file,
- "\n# If this option is set to yes, confirmation is required before deleting an event\n");
- fprintf(data_file, "confirm_delete=\n");
- fprintf(data_file, "%s\n",
- (conf->confirm_delete) ? "yes" : "no");
-
- fprintf(data_file,
- "\n# If this option is set to yes, messages about loaded and saved data will not be displayed\n");
- fprintf(data_file, "skip_system_dialogs=\n");
- fprintf(data_file, "%s\n",
- (conf->skip_system_dialogs) ? "yes" : "no");
-
- fprintf(data_file,
- "\n# If this option is set to yes, progress bar appearing when saving data will not be displayed\n");
- fprintf(data_file, "skip_progress_bar=\n");
- fprintf(data_file, "%s\n",
- (conf->skip_progress_bar) ? "yes" : "no");
-
- fprintf(data_file,
- "\n# If this option is set to yes, monday is the first day of the week, else it is sunday\n");
- fprintf(data_file, "week_begins_on_monday=\n");
- fprintf(data_file, "%s\n",
- (calendar_week_begins_on_monday()) ? "yes" : "no");
-
- fprintf(data_file,
- "\n# This is the color theme used for menus :\n");
- fprintf(data_file, "color-theme=\n");
- fprintf(data_file, "%s\n", theme_name);
-
- fprintf(data_file,
- "\n# This is the layout of the calendar :\n");
- fprintf(data_file, "layout=\n");
- fprintf(data_file, "%d\n", wins_layout());
-
- pthread_mutex_lock(&nbar->mutex);
- fprintf(data_file,
- "\n# If this option is set to yes, notify-bar will be displayed :\n");
- fprintf(data_file, "notify-bar_show=\n");
- fprintf(data_file, "%s\n", (nbar->show) ? "yes" : "no");
-
- fprintf(data_file,
- "\n# Format of the date to be displayed inside notify-bar :\n");
- fprintf(data_file, "notify-bar_date=\n");
- fprintf(data_file, "%s\n", nbar->datefmt);
-
- fprintf(data_file,
- "\n# Format of the time to be displayed inside notify-bar :\n");
- fprintf(data_file, "notify-bar_clock=\n");
- fprintf(data_file, "%s\n", nbar->timefmt);
-
- fprintf(data_file,
- "\n# Warn user if he has an appointment within next 'notify-bar_warning' seconds :\n");
- fprintf(data_file, "notify-bar_warning=\n");
- fprintf(data_file, "%d\n", nbar->cntdwn);
-
- fprintf(data_file,
- "\n# Command used to notify user of an upcoming appointment :\n");
- fprintf(data_file, "notify-bar_command=\n");
- fprintf(data_file, "%s\n", nbar->cmd);
-
- fprintf(data_file,
- "\n# Format of the date to be displayed in non-interactive mode :\n");
- fprintf(data_file, "output_datefmt=\n");
- fprintf(data_file, "%s\n", conf->output_datefmt);
-
- fprintf(data_file,
- "\n# Format to be used when entering a date (1-mm/dd/yyyy, 2-dd/mm/yyyy, 3-yyyy/mm/dd) :\n");
- fprintf(data_file, "input_datefmt=\n");
- fprintf(data_file, "%d\n", conf->input_datefmt);
-
- pthread_mutex_unlock(&nbar->mutex);
-
- fclose(data_file);
+ FILE *data_file;
+ struct event_s *k;
+ apoint_llist_node_t *j;
+ struct todo_s *i;
+ char theme_name[BUFSIZ];
+ char *access_pb = _("Problems accessing data file ...");
+ char *config_txt =
+ "#\n"
+ "# Calcurse configuration file\n#\n"
+ "# This file sets the configuration options used by Calcurse. These\n"
+ "# options are usually set from within Calcurse. A line beginning with \n"
+ "# a space or tab is considered to be a continuation of the previous "
+ "line.\n"
+ "# For a variable to be unset its value must be blank.\n"
+ "# To set a variable to the empty string its value should be \"\".\n"
+ "# Lines beginning with \"#\" are comments, and ignored by Calcurse.\n";
+ char *save_success = _("The data files were successfully saved");
+ char *enter = _("Press [ENTER] to continue");
+ bool show_bar = false;
+
+ if (!conf->skip_progress_bar)
+ show_bar = true;
+
+ /* Save the user configuration. */
+
+ if (show_bar)
+ progress_bar (PROGRESS_BAR_SAVE, 0);
+ data_file = fopen (path_conf, "w");
+ if (data_file == (FILE *) 0)
+ status_mesg (access_pb, "");
+ else
+ {
+ custom_color_theme_name (theme_name);
+
+ fprintf (data_file, "%s\n", config_txt);
+
+ fprintf (data_file,
+ "# If this option is set to yes, "
+ "automatic save is done when quitting\n");
+ fprintf (data_file, "auto_save=\n");
+ fprintf (data_file, "%s\n", (conf->auto_save) ? "yes" : "no");
+
+ fprintf (data_file,
+ "\n# If this option is set to yes, "
+ "confirmation is required before quitting\n");
+ fprintf (data_file, "confirm_quit=\n");
+ fprintf (data_file, "%s\n", (conf->confirm_quit) ? "yes" : "no");
+
+ fprintf (data_file,
+ "\n# If this option is set to yes, "
+ "confirmation is required before deleting an event\n");
+ fprintf (data_file, "confirm_delete=\n");
+ fprintf (data_file, "%s\n", (conf->confirm_delete) ? "yes" : "no");
+
+ fprintf (data_file,
+ "\n# If this option is set to yes, "
+ "messages about loaded and saved data will not be displayed\n");
+ fprintf (data_file, "skip_system_dialogs=\n");
+ fprintf (data_file, "%s\n", (conf->skip_system_dialogs) ? "yes" : "no");
+
+ fprintf (data_file,
+ "\n# If this option is set to yes, progress bar appearing "
+ "when saving data will not be displayed\n");
+ fprintf (data_file, "skip_progress_bar=\n");
+ fprintf (data_file, "%s\n", (conf->skip_progress_bar) ? "yes" : "no");
+
+ fprintf (data_file,
+ "\n# If this option is set to yes, "
+ "monday is the first day of the week, else it is sunday\n");
+ fprintf (data_file, "week_begins_on_monday=\n");
+ fprintf (data_file, "%s\n",
+ (calendar_week_begins_on_monday ())? "yes" : "no");
+
+ fprintf (data_file, "\n# This is the color theme used for menus :\n");
+ fprintf (data_file, "color-theme=\n");
+ fprintf (data_file, "%s\n", theme_name);
+
+ fprintf (data_file, "\n# This is the layout of the calendar :\n");
+ fprintf (data_file, "layout=\n");
+ fprintf (data_file, "%d\n", wins_layout ());
+
+ pthread_mutex_lock (&nbar->mutex);
+ fprintf (data_file,
+ "\n# If this option is set to yes, "
+ "notify-bar will be displayed :\n");
+ fprintf (data_file, "notify-bar_show=\n");
+ fprintf (data_file, "%s\n", (nbar->show) ? "yes" : "no");
+
+ fprintf (data_file,
+ "\n# Format of the date to be displayed inside notify-bar :\n");
+ fprintf (data_file, "notify-bar_date=\n");
+ fprintf (data_file, "%s\n", nbar->datefmt);
+
+ fprintf (data_file,
+ "\n# Format of the time to be displayed inside notify-bar :\n");
+ fprintf (data_file, "notify-bar_clock=\n");
+ fprintf (data_file, "%s\n", nbar->timefmt);
+
+ fprintf (data_file,
+ "\n# Warn user if he has an appointment within next "
+ "'notify-bar_warning' seconds :\n");
+ fprintf (data_file, "notify-bar_warning=\n");
+ fprintf (data_file, "%d\n", nbar->cntdwn);
+
+ fprintf (data_file,
+ "\n# Command used to notify user of "
+ "an upcoming appointment :\n");
+ fprintf (data_file, "notify-bar_command=\n");
+ fprintf (data_file, "%s\n", nbar->cmd);
+
+ fprintf (data_file,
+ "\n# Format of the date to be displayed "
+ "in non-interactive mode :\n");
+ fprintf (data_file, "output_datefmt=\n");
+ fprintf (data_file, "%s\n", conf->output_datefmt);
+
+ fprintf (data_file,
+ "\n# Format to be used when entering a date "
+ "(1-mm/dd/yyyy, 2-dd/mm/yyyy, 3-yyyy/mm/dd) :\n");
+ fprintf (data_file, "input_datefmt=\n");
+ fprintf (data_file, "%d\n", conf->input_datefmt);
+
+ pthread_mutex_unlock (&nbar->mutex);
+
+ fclose (data_file);
+ }
+
+ /* Save the todo data file. */
+ if (show_bar)
+ progress_bar (PROGRESS_BAR_SAVE, 1);
+ data_file = fopen (path_todo, "w");
+ if (data_file == (FILE *) 0)
+ status_mesg (access_pb, "");
+ else
+ {
+ for (i = todolist; i != 0; i = i->next)
+ {
+ if (i->note != NULL)
+ fprintf (data_file, "[%d]>%s %s\n", i->id, i->note, i->mesg);
+ else
+ fprintf (data_file, "[%d] %s\n", i->id, i->mesg);
}
-
- /* Save the todo data file. */
- if (show_bar)
- progress_bar(PROGRESS_BAR_SAVE, 1);
- data_file = fopen(path_todo, "w");
- if (data_file == (FILE *) 0)
- status_mesg(access_pb, "");
- else {
- for (i = todolist; i != 0; i = i->next) {
- if (i->note != NULL)
- fprintf(data_file, "[%d]>%s %s\n", i->id,
- i->note, i->mesg);
- else
- fprintf(data_file, "[%d] %s\n", i->id, i->mesg);
- }
- fclose(data_file);
- }
-
- /*
- * Save the apts data file, which contains the
- * appointments first, and then the events.
- * Recursive items are written first.
- */
- if (show_bar)
- progress_bar(PROGRESS_BAR_SAVE, 2);
- data_file = fopen(path_apts, "w");
- if (data_file == (FILE *) 0)
- status_mesg(access_pb, "");
- else {
- recur_save_data(data_file);
-
- pthread_mutex_lock(&(alist_p->mutex));
- for (j = alist_p->root; j != 0; j = j->next)
- apoint_write(j, data_file);
- pthread_mutex_unlock(&(alist_p->mutex));
-
- for (k = eventlist; k != 0; k = k->next)
- event_write(k, data_file);
- fclose(data_file);
- }
-
-
- /* Print a message telling data were saved */
- if (!conf->skip_system_dialogs) {
- status_mesg(save_success, enter);
- wgetch(win[STA].p);
- }
+ fclose (data_file);
+ }
+
+ /*
+ * Save the apts data file, which contains the
+ * appointments first, and then the events.
+ * Recursive items are written first.
+ */
+ if (show_bar)
+ progress_bar (PROGRESS_BAR_SAVE, 2);
+ data_file = fopen (path_apts, "w");
+ if (data_file == (FILE *) 0)
+ status_mesg (access_pb, "");
+ else
+ {
+ recur_save_data (data_file);
+
+ pthread_mutex_lock (&(alist_p->mutex));
+ for (j = alist_p->root; j != 0; j = j->next)
+ apoint_write (j, data_file);
+ pthread_mutex_unlock (&(alist_p->mutex));
+
+ for (k = eventlist; k != 0; k = k->next)
+ event_write (k, data_file);
+ fclose (data_file);
+ }
+
+ /* Print a message telling data were saved */
+ if (!conf->skip_system_dialogs)
+ {
+ status_mesg (save_success, enter);
+ wgetch (win[STA].p);
+ }
}
/*
* Check what type of data is written in the appointment file,
* and then load either: a new appointment, a new event, or a new
* recursive item (which can also be either an event or an appointment).
- */
-void
-io_load_app(void)
+ */
+void
+io_load_app (void)
{
- FILE *data_file;
- int c, is_appointment, is_event, is_recursive;
- struct tm start, end, until, *lt;
- struct days_s *exc = NULL;
- time_t t;
- int id = 0;
- int freq;
- char type, state = 0L;
- char note[NOTESIZ + 1], *notep;
- char *error =
- _("FATAL ERROR in io_load_app: wrong format in the appointment or event\n");
-
- t = time(NULL);
- lt = localtime(&t);
- start = end = until = *lt;
-
- data_file = fopen(path_apts, "r");
- for (;;) {
- is_appointment = is_event = is_recursive = 0;
- c = getc(data_file);
- if (c == EOF)
- break;
- ungetc(c, data_file);
-
- /* Read the date first: it is common to both events
- * and appointments.
- */
- if (fscanf(data_file, "%u / %u / %u ",
- &start.tm_mon, &start.tm_mday, &start.tm_year) != 3) {
- fputs(_("FATAL ERROR in io_load_app: "
- "syntax error in the item date\n"), stderr);
- exit(EXIT_FAILURE);
- }
-
- /* Read the next character : if it is an '@' then we have
- * an appointment, else if it is an '[' we have en event.
- */
- c = getc(data_file);
-
- if (c == '@')
- is_appointment = 1;
- else if (c == '[')
- is_event = 1;
- else {
- fputs(_("FATAL ERROR in io_load_app: "
- "no event nor appointment found\n"), stderr);
- exit(EXIT_FAILURE);
- }
- ungetc(c, data_file);
-
- /* Read the remaining informations. */
- if (is_appointment) {
- fscanf(data_file, "@ %u : %u -> %u / %u / %u @ %u : %u ",
- &start.tm_hour, &start.tm_min,
- &end.tm_mon, &end.tm_mday, &end.tm_year,
- &end.tm_hour, &end.tm_min);
- } else if (is_event) {
- fscanf(data_file, "[%d] ", &id);
- } else { /* NOT REACHED */
- fputs(error, stderr);
- exit(EXIT_FAILURE);
- }
-
- /* Check if we have a recursive item. */
- c = getc(data_file);
-
- if (c == '{') {
- ungetc(c, data_file);
- is_recursive = 1;
- fscanf(data_file, "{ %d%c ", &freq, &type);
-
- c = getc(data_file);
- if (c == '}') { /* endless recurrent item */
- ungetc(c, data_file);
- fscanf(data_file, "} ");
- until.tm_year = 0;
- } else if (c == '-') {
- ungetc(c, data_file);
- fscanf(data_file, " -> %u / %u / %u ",
- &until.tm_mon, &until.tm_mday,
- &until.tm_year);
- c = getc(data_file);
- if (c == '!') {
- ungetc(c, data_file);
- exc = recur_exc_scan(data_file);
- c = getc(data_file);
- } else {
- ungetc(c, data_file);
- fscanf(data_file, "} ");
- }
- } else if (c == '!') { // endless item with exceptions
- ungetc(c, data_file);
- exc = recur_exc_scan(data_file);
- c = getc(data_file);
- until.tm_year = 0;
- } else { /* NOT REACHED */
- fputs(error, stderr);
- exit(EXIT_FAILURE);
- }
- } else
- ungetc(c, data_file);
-
- /* Check if a note is attached to the item. */
- c = getc(data_file);
- if (c == '>') {
- fgets(note, NOTESIZ + 1, data_file);
- note[NOTESIZ] = '\0';
- notep = note;
- getc(data_file);
- } else {
- notep = NULL;
- ungetc(c, data_file);
- }
+ FILE *data_file;
+ int c, is_appointment, is_event, is_recursive;
+ struct tm start, end, until, *lt;
+ struct days_s *exc = NULL;
+ time_t t;
+ int id = 0;
+ int freq;
+ char type, state = 0L;
+ char note[NOTESIZ + 1], *notep;
+ char *error =
+ _("FATAL ERROR in io_load_app: wrong format in the appointment or event\n");
+
+ t = time (NULL);
+ lt = localtime (&t);
+ start = end = until = *lt;
+
+ data_file = fopen (path_apts, "r");
+ for (;;)
+ {
+ is_appointment = is_event = is_recursive = 0;
+ c = getc (data_file);
+ if (c == EOF)
+ break;
+ ungetc (c, data_file);
+
+ /* Read the date first: it is common to both events
+ * and appointments.
+ */
+ if (fscanf (data_file, "%u / %u / %u ",
+ &start.tm_mon, &start.tm_mday, &start.tm_year) != 3)
+ {
+ fputs (_("FATAL ERROR in io_load_app: "
+ "syntax error in the item date\n"), stderr);
+ exit (EXIT_FAILURE);
+ }
- /*
- * Last: read the item description and load it into its
- * corresponding linked list, depending on the item type.
- */
- if (is_appointment) {
- c = getc(data_file);
- if (c == '!') {
- ungetc(c, data_file);
- fscanf(data_file, " ! ");
- state |= APOINT_NOTIFY;
- } else {
- ungetc(c, data_file);
- fscanf(data_file, " | ");
- state = 0L;
- }
- if (is_recursive) {
- recur_apoint_scan(data_file, start, end,
- type, freq, until, notep, exc, state);
- } else {
- apoint_scan(data_file, start, end, state,
- notep);
- }
- } else if (is_event) {
- if (is_recursive) {
- recur_event_scan(data_file, start, id, type,
- freq, until, notep, exc);
- } else {
- event_scan(data_file, start, id, notep);
- }
- } else { /* NOT REACHED */
- fputs(error, stderr);
- exit(EXIT_FAILURE);
+ /* Read the next character : if it is an '@' then we have
+ * an appointment, else if it is an '[' we have en event.
+ */
+ c = getc (data_file);
+
+ if (c == '@')
+ is_appointment = 1;
+ else if (c == '[')
+ is_event = 1;
+ else
+ {
+ fputs (_("FATAL ERROR in io_load_app: "
+ "no event nor appointment found\n"), stderr);
+ exit (EXIT_FAILURE);
+ }
+ ungetc (c, data_file);
+
+ /* Read the remaining informations. */
+ if (is_appointment)
+ {
+ fscanf (data_file, "@ %u : %u -> %u / %u / %u @ %u : %u ",
+ &start.tm_hour, &start.tm_min,
+ &end.tm_mon, &end.tm_mday, &end.tm_year,
+ &end.tm_hour, &end.tm_min);
+ }
+ else if (is_event)
+ {
+ fscanf (data_file, "[%d] ", &id);
+ }
+ else
+ { /* NOT REACHED */
+ fputs (error, stderr);
+ exit (EXIT_FAILURE);
+ }
+
+ /* Check if we have a recursive item. */
+ c = getc (data_file);
+
+ if (c == '{')
+ {
+ ungetc (c, data_file);
+ is_recursive = 1;
+ fscanf (data_file, "{ %d%c ", &freq, &type);
+
+ c = getc (data_file);
+ if (c == '}')
+ { /* endless recurrent item */
+ ungetc (c, data_file);
+ fscanf (data_file, "} ");
+ until.tm_year = 0;
+ }
+ else if (c == '-')
+ {
+ ungetc (c, data_file);
+ fscanf (data_file, " -> %u / %u / %u ",
+ &until.tm_mon, &until.tm_mday, &until.tm_year);
+ c = getc (data_file);
+ if (c == '!')
+ {
+ ungetc (c, data_file);
+ exc = recur_exc_scan (data_file);
+ c = getc (data_file);
+ }
+ else
+ {
+ ungetc (c, data_file);
+ fscanf (data_file, "} ");
}
+ }
+ else if (c == '!')
+ { // endless item with exceptions
+ ungetc (c, data_file);
+ exc = recur_exc_scan (data_file);
+ c = getc (data_file);
+ until.tm_year = 0;
+ }
+ else
+ { /* NOT REACHED */
+ fputs (error, stderr);
+ exit (EXIT_FAILURE);
+ }
+ }
+ else
+ ungetc (c, data_file);
+
+ /* Check if a note is attached to the item. */
+ c = getc (data_file);
+ if (c == '>')
+ {
+ fgets (note, NOTESIZ + 1, data_file);
+ note[NOTESIZ] = '\0';
+ notep = note;
+ getc (data_file);
+ }
+ else
+ {
+ notep = NULL;
+ ungetc (c, data_file);
}
- fclose(data_file);
+
+ /*
+ * Last: read the item description and load it into its
+ * corresponding linked list, depending on the item type.
+ */
+ if (is_appointment)
+ {
+ c = getc (data_file);
+ if (c == '!')
+ {
+ ungetc (c, data_file);
+ fscanf (data_file, " ! ");
+ state |= APOINT_NOTIFY;
+ }
+ else
+ {
+ ungetc (c, data_file);
+ fscanf (data_file, " | ");
+ state = 0L;
+ }
+ if (is_recursive)
+ {
+ recur_apoint_scan (data_file, start, end,
+ type, freq, until, notep, exc, state);
+ }
+ else
+ {
+ apoint_scan (data_file, start, end, state, notep);
+ }
+ }
+ else if (is_event)
+ {
+ if (is_recursive)
+ {
+ recur_event_scan (data_file, start, id, type,
+ freq, until, notep, exc);
+ }
+ else
+ {
+ event_scan (data_file, start, id, notep);
+ }
+ }
+ else
+ { /* NOT REACHED */
+ fputs (error, stderr);
+ exit (EXIT_FAILURE);
+ }
+ }
+ fclose (data_file);
}
/* Load the todo data */
void
-io_load_todo(void)
+io_load_todo (void)
{
- FILE *data_file;
- char *mesg_line1 = _("Failed to open todo file");
- char *mesg_line2 = _("Press [ENTER] to continue");
- char *nl;
- int nb_tod = 0;
- int c, id;
- char buf[BUFSIZ], e_todo[BUFSIZ], note[NOTESIZ + 1];
-
- data_file = fopen(path_todo, "r");
- if (data_file == NULL) {
- status_mesg(mesg_line1, mesg_line2);
- wgetch(win[STA].p);
+ FILE *data_file;
+ char *mesg_line1 = _("Failed to open todo file");
+ char *mesg_line2 = _("Press [ENTER] to continue");
+ char *nl;
+ int nb_tod = 0;
+ int c, id;
+ char buf[BUFSIZ], e_todo[BUFSIZ], note[NOTESIZ + 1];
+
+ data_file = fopen (path_todo, "r");
+ if (data_file == NULL)
+ {
+ status_mesg (mesg_line1, mesg_line2);
+ wgetch (win[STA].p);
+ }
+ for (;;)
+ {
+ c = getc (data_file);
+ if (c == EOF)
+ {
+ break;
}
- for (;;) {
- c = getc(data_file);
- if (c == EOF) {
- break;
- } else if (c == '[') { /* new style with id */
- fscanf(data_file, "%d]", &id);
- } else {
- id = 9;
- ungetc(c, data_file);
- }
- /* Now read the attached note, if any. */
- c = getc(data_file);
- if (c == '>') {
- fgets(note, NOTESIZ + 1, data_file);
- note[NOTESIZ] = '\0';
- getc(data_file);
- } else
- note[0] = '\0';
- /* Then read todo description. */
- fgets(buf, BUFSIZ, data_file);
- nl = strchr(buf, '\n');
- if (nl) {
- *nl = '\0';
- }
- io_extract_data(e_todo, buf, strlen(buf));
- todo_add(e_todo, id, note);
- ++nb_tod;
+ else if (c == '[')
+ { /* new style with id */
+ fscanf (data_file, "%d]", &id);
+ }
+ else
+ {
+ id = 9;
+ ungetc (c, data_file);
+ }
+ /* Now read the attached note, if any. */
+ c = getc (data_file);
+ if (c == '>')
+ {
+ fgets (note, NOTESIZ + 1, data_file);
+ note[NOTESIZ] = '\0';
+ getc (data_file);
}
- fclose(data_file);
- todo_set_nb(nb_tod);
+ else
+ note[0] = '\0';
+ /* Then read todo description. */
+ fgets (buf, BUFSIZ, data_file);
+ nl = strchr (buf, '\n');
+ if (nl)
+ {
+ *nl = '\0';
+ }
+ io_extract_data (e_todo, buf, strlen (buf));
+ todo_add (e_todo, id, note);
+ ++nb_tod;
+ }
+ fclose (data_file);
+ todo_set_nb (nb_tod);
}
static void
-check_directory(char *dir, int *missing)
+check_directory (char *dir, int *missing)
{
- errno = 0;
- if (mkdir(dir, 0700) != 0) {
- if (errno != EEXIST) {
- fprintf(stderr,
- _("FATAL ERROR: could not create %s: %s\n"),
- dir, strerror(errno));
- exit(EXIT_FAILURE);
- }
- } else
- (*missing)++;
+ errno = 0;
+ if (mkdir (dir, 0700) != 0)
+ {
+ if (errno != EEXIST)
+ {
+ fprintf (stderr, _("FATAL ERROR: could not create %s: %s\n"),
+ dir, strerror (errno));
+ exit (EXIT_FAILURE);
+ }
+ }
+ else
+ (*missing)++;
}
static void
-check_file(char *file, int *missing)
+check_file (char *file, int *missing)
{
- FILE *fd;
-
- errno = 0;
- if ((fd = fopen(file, "r")) == NULL) {
- (*missing)++;
- if ((fd = fopen(file, "w")) == NULL) {
- fprintf(stderr,
- _("FATAL ERROR: could not create %s: %s\n"),
- file, strerror(errno));
- exit(EXIT_FAILURE);
- }
+ FILE *fd;
+
+ errno = 0;
+ if ((fd = fopen (file, "r")) == NULL)
+ {
+ (*missing)++;
+ if ((fd = fopen (file, "w")) == NULL)
+ {
+ fprintf (stderr, _("FATAL ERROR: could not create %s: %s\n"),
+ file, strerror (errno));
+ exit (EXIT_FAILURE);
}
- fclose(fd);
+ }
+ fclose (fd);
}
/*
@@ -801,88 +891,92 @@ check_file(char *file, int *missing)
* |___ apts
* |___ todo
*/
-int
-io_check_data_files(void)
+int
+io_check_data_files (void)
{
- int missing;
-
- missing = 0;
- errno = 0;
- check_directory(path_dir, &missing);
- check_directory(path_notes, &missing);
- check_file(path_todo, &missing);
- check_file(path_apts, &missing);
- check_file(path_conf, &missing);
- return (missing);
+ int missing;
+
+ missing = 0;
+ errno = 0;
+ check_directory (path_dir, &missing);
+ check_directory (path_notes, &missing);
+ check_file (path_todo, &missing);
+ check_file (path_apts, &missing);
+ check_file (path_conf, &missing);
+ return (missing);
}
/* Draw the startup screen */
-void
-io_startup_screen(bool skip_dialogs, int no_data_file)
+void
+io_startup_screen (bool skip_dialogs, int no_data_file)
{
- char *welcome_mesg =
- _("Welcome to Calcurse. Missing data files were created.");
- char *data_mesg = _("Data files found. Data will be loaded now.");
- char *enter = _("Press [ENTER] to continue");
-
- if (no_data_file != 0) {
- status_mesg(welcome_mesg, enter);
- wgetch(win[STA].p);
- } else if (!skip_dialogs) {
- status_mesg(data_mesg, enter);
- wgetch(win[STA].p);
- }
+ char *welcome_mesg =
+ _("Welcome to Calcurse. Missing data files were created.");
+ char *data_mesg = _("Data files found. Data will be loaded now.");
+ char *enter = _("Press [ENTER] to continue");
+
+ if (no_data_file != 0)
+ {
+ status_mesg (welcome_mesg, enter);
+ wgetch (win[STA].p);
+ }
+ else if (!skip_dialogs)
+ {
+ status_mesg (data_mesg, enter);
+ wgetch (win[STA].p);
+ }
}
/* Export calcurse data. */
void
-io_export_data(export_mode_t mode, conf_t *conf)
+io_export_data (export_mode_t mode, conf_t *conf)
{
- FILE *stream;
- char *wrong_mode =
- _("FATAL ERROR in io_export_data: wrong export mode\n");
- char *success = _("The data were successfully exported");
- char *enter = _("Press [ENTER] to continue");
-
- switch (mode) {
- case IO_EXPORT_NONINTERACTIVE:
- stream = stdout;
- break;
- case IO_EXPORT_INTERACTIVE:
- stream = io_get_export_stream();
- break;
- default:
- fputs(wrong_mode, stderr);
- exit(EXIT_FAILURE);
- /* NOTREACHED */
- }
-
- if (stream == NULL)
- return;
-
- io_export_header(stream);
-
- if (!conf->skip_progress_bar && mode == IO_EXPORT_INTERACTIVE)
- progress_bar(PROGRESS_BAR_EXPORT, 0);
- io_export_recur_events(stream);
- io_export_events(stream);
-
- if (!conf->skip_progress_bar && mode == IO_EXPORT_INTERACTIVE)
- progress_bar(PROGRESS_BAR_EXPORT, 1);
- io_export_recur_apoints(stream);
- io_export_apoints(stream);
-
- if (!conf->skip_progress_bar && mode == IO_EXPORT_INTERACTIVE)
- progress_bar(PROGRESS_BAR_EXPORT, 2);
- io_export_todo(stream);
-
- io_export_footer(stream);
-
- if (stream != stdout)
- fclose(stream);
-
- if (!conf->skip_system_dialogs && mode == IO_EXPORT_INTERACTIVE) {
- status_mesg(success, enter);
- wgetch(win[STA].p);
- }
+ FILE *stream;
+ char *wrong_mode = _("FATAL ERROR in io_export_data: wrong export mode\n");
+ char *success = _("The data were successfully exported");
+ char *enter = _("Press [ENTER] to continue");
+
+ switch (mode)
+ {
+ case IO_EXPORT_NONINTERACTIVE:
+ stream = stdout;
+ break;
+ case IO_EXPORT_INTERACTIVE:
+ stream = io_get_export_stream ();
+ break;
+ default:
+ fputs (wrong_mode, stderr);
+ exit (EXIT_FAILURE);
+ /* NOTREACHED */
+ }
+
+ if (stream == NULL)
+ return;
+
+ io_export_header (stream);
+
+ if (!conf->skip_progress_bar && mode == IO_EXPORT_INTERACTIVE)
+ progress_bar (PROGRESS_BAR_EXPORT, 0);
+ io_export_recur_events (stream);
+ io_export_events (stream);
+
+ if (!conf->skip_progress_bar && mode == IO_EXPORT_INTERACTIVE)
+ progress_bar (PROGRESS_BAR_EXPORT, 1);
+ io_export_recur_apoints (stream);
+ io_export_apoints (stream);
+
+ if (!conf->skip_progress_bar && mode == IO_EXPORT_INTERACTIVE)
+ progress_bar (PROGRESS_BAR_EXPORT, 2);
+ io_export_todo (stream);
+
+ io_export_footer (stream);
+
+ if (stream != stdout)
+ fclose (stream);
+
+ if (!conf->skip_system_dialogs && mode == IO_EXPORT_INTERACTIVE)
+ {
+ status_mesg (success, enter);
+ wgetch (win[STA].p);
+ }
}
diff --git a/src/io.h b/src/io.h
index 86f5e98..ebaa193 100755
--- a/src/io.h
+++ b/src/io.h
@@ -1,8 +1,8 @@
-/* $calcurse: io.h,v 1.8 2007/08/15 15:36:27 culot Exp $ */
+/* $calcurse: io.h,v 1.9 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
- * Copyright (c) 2004-2007 Frederic Culot
+ * Copyright (c) 2004-2008 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -29,19 +29,21 @@
#include "vars.h"
-typedef enum {
- IO_EXPORT_NONINTERACTIVE,
- IO_EXPORT_INTERACTIVE,
- IO_EXPORT_NBMODES
-} export_mode_t;
+typedef enum
+{
+ IO_EXPORT_NONINTERACTIVE,
+ IO_EXPORT_INTERACTIVE,
+ IO_EXPORT_NBMODES
+}
+export_mode_t;
-void io_init(char *);
-void io_extract_data(char *, const char *, int);
-void io_save_cal(conf_t *);
-void io_load_app(void);
-void io_load_todo(void);
-int io_check_data_files(void);
-void io_startup_screen(bool, int);
-void io_export_data(export_mode_t, conf_t *);
+void io_init (char *);
+void io_extract_data (char *, const char *, int);
+void io_save_cal (conf_t *);
+void io_load_app (void);
+void io_load_todo (void);
+int io_check_data_files (void);
+void io_startup_screen (bool, int);
+void io_export_data (export_mode_t, conf_t *);
#endif /* CALCURSE_IO_H */
diff --git a/src/notify.c b/src/notify.c
index 0befe8b..0634db1 100755
--- a/src/notify.c
+++ b/src/notify.c
@@ -1,8 +1,8 @@
-/* $calcurse: notify.c,v 1.24 2008/02/10 16:29:50 culot Exp $ */
+/* $calcurse: notify.c,v 1.25 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
- * Copyright (c) 2004-2007 Frederic Culot
+ * Copyright (c) 2004-2008 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -39,51 +39,52 @@ static struct notify_app_s *notify_app = NULL;
static pthread_t notify_t_main;
/* Return 1 if we need to display the notify-bar, else 0. */
-int
-notify_bar(void)
+int
+notify_bar (void)
{
- int display_bar = 0;
+ int display_bar = 0;
- pthread_mutex_lock(&nbar->mutex);
- display_bar = (nbar->show) ? 1 : 0;
- pthread_mutex_unlock(&nbar->mutex);
-
- return display_bar;
+ pthread_mutex_lock (&nbar->mutex);
+ display_bar = (nbar->show) ? 1 : 0;
+ pthread_mutex_unlock (&nbar->mutex);
+
+ return (display_bar);
}
/* Initialize the nbar variable used to store notification options. */
-void
-notify_init_vars(void)
+void
+notify_init_vars (void)
{
- char *time_format = "%T";
- char *date_format = "%a %F";
- char *cmd = "printf '\\a'";
-
- nbar = (struct nbar_s *) malloc(sizeof(struct nbar_s));
- pthread_mutex_init(&nbar->mutex, NULL);
- nbar->show = 1;
- nbar->cntdwn = 300;
- strncpy(nbar->datefmt, date_format, strlen(date_format) + 1);
- strncpy(nbar->timefmt, time_format, strlen(time_format) + 1);
- strncpy(nbar->cmd, cmd, strlen(cmd) + 1);
-
- if ((nbar->shell = getenv("SHELL")) == NULL)
- nbar->shell = "/bin/sh";
+ char *time_format = "%T";
+ char *date_format = "%a %F";
+ char *cmd = "printf '\\a'";
+
+ nbar = (struct nbar_s *) malloc (sizeof (struct nbar_s));
+ pthread_mutex_init (&nbar->mutex, NULL);
+ nbar->show = 1;
+ nbar->cntdwn = 300;
+ strncpy (nbar->datefmt, date_format, strlen (date_format) + 1);
+ strncpy (nbar->timefmt, time_format, strlen (time_format) + 1);
+ strncpy (nbar->cmd, cmd, strlen (cmd) + 1);
+
+ if ((nbar->shell = getenv ("SHELL")) == NULL)
+ nbar->shell = "/bin/sh";
}
/* Extract the appointment file name from the complete file path. */
-static void
-extract_aptsfile(void)
+static void
+extract_aptsfile (void)
{
- char *file;
-
- file = strrchr(path_apts, '/');
- if (!file)
- notify->apts_file = path_apts;
- else {
- notify->apts_file = file;
- notify->apts_file++;
- }
+ char *file;
+
+ file = strrchr (path_apts, '/');
+ if (!file)
+ notify->apts_file = path_apts;
+ else
+ {
+ notify->apts_file = file;
+ notify->apts_file++;
+ }
}
/*
@@ -91,510 +92,531 @@ extract_aptsfile(void)
* creating the notification window (l is the number of lines, c the
* number of columns, y and x are its coordinates).
*/
-void
-notify_init_bar(void)
+void
+notify_init_bar (void)
{
- notify = (struct notify_vars_s *) malloc(sizeof(struct notify_vars_s));
- notify_app = (struct notify_app_s *)
- malloc(sizeof(struct notify_app_s));
- pthread_mutex_init(&notify->mutex, NULL);
- pthread_mutex_init(&notify_app->mutex, NULL);
- notify_app->got_app = 0;
- notify->win = newwin(win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x);
- extract_aptsfile();
+ notify = (struct notify_vars_s *) malloc (sizeof (struct notify_vars_s));
+ notify_app = (struct notify_app_s *) malloc (sizeof (struct notify_app_s));
+ pthread_mutex_init (&notify->mutex, NULL);
+ pthread_mutex_init (&notify_app->mutex, NULL);
+ notify_app->got_app = 0;
+ notify->win = newwin (win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x);
+ extract_aptsfile ();
}
/* Stop the notify-bar main thread. */
-void
-notify_stop_main_thread(void)
+void
+notify_stop_main_thread (void)
{
- pthread_cancel(notify_t_main);
- return;
+ pthread_cancel (notify_t_main);
+ return;
}
/*
* The calcurse window geometry has changed so we need to reset the
* notification window.
*/
-void
-notify_reinit_bar(int l, int c, int y, int x)
+void
+notify_reinit_bar (int l, int c, int y, int x)
{
- delwin(notify->win);
- notify->win = newwin(l, c, y, x);
+ delwin (notify->win);
+ notify->win = newwin (l, c, y, x);
}
/* Launch user defined command as a notification. */
static void
-launch_cmd(char *cmd, char *shell)
+launch_cmd (char *cmd, char *shell)
{
- int pid;
-
- pid = fork();
-
- if (pid < 0)
- ierror(_("FATAL ERROR in launch_cmd: could not fork"),
- IERROR_WARN);
- else if (pid == 0) /* Child: launch user defined command */
- if (execlp(shell, shell, "-c", cmd, (char *)NULL) < 0)
- ierror(_("FATAL ERROR in launch_cmd: could not "
- "launch user command"),
- IERROR_WARN);
+ int pid;
+
+ pid = fork ();
+
+ if (pid < 0)
+ ierror (_("FATAL ERROR in launch_cmd: could not fork"), IERROR_WARN);
+ else if (pid == 0) /* Child: launch user defined command */
+ if (execlp (shell, shell, "-c", cmd, (char *) NULL) < 0)
+ ierror (_("FATAL ERROR in launch_cmd: could not "
+ "launch user command"), IERROR_WARN);
}
/*
* Update the notification bar. This is useful when changing color theme
* for example.
*/
-void
-notify_update_bar(void)
+void
+notify_update_bar (void)
{
- const int space = 3;
- int file_pos, date_pos, app_pos, txt_max_len, too_long = 0;
- int time_left, hours_left, minutes_left;
- int blinking;
- char buf[BUFSIZ];
-
- date_pos = space;
- pthread_mutex_lock(&notify->mutex);
-
- file_pos = strlen(notify->date) + strlen(notify->time) + 7 + 2*space;
- app_pos = file_pos + strlen(notify->apts_file) + 2 + space;
- txt_max_len = col - (app_pos + 12 + space);
-
- custom_apply_attr(notify->win, ATTR_HIGHEST);
- wattron(notify->win, A_UNDERLINE | A_REVERSE);
- mvwhline(notify->win, 0, 0, ACS_HLINE, col);
- mvwprintw(notify->win, 0, date_pos, "[ %s | %s ]",
- notify->date, notify->time);
- mvwprintw(notify->win, 0, file_pos, "(%s)", notify->apts_file);
-
- pthread_mutex_lock(&notify_app->mutex);
- if (notify_app->got_app) {
- if (strlen(notify_app->txt) > txt_max_len) {
- too_long = 1;
- strncpy(buf, notify_app->txt, txt_max_len - 3);
- buf[txt_max_len - 3] = '\0';
- }
-
- time_left = notify_app->time - notify->time_in_sec;
- if (time_left > 0) {
- hours_left = (time_left / HOURINSEC);
- minutes_left = (time_left - hours_left * HOURINSEC) /
- MININSEC;
- pthread_mutex_lock(&nbar->mutex);
-
- if (time_left < nbar->cntdwn &&
- (notify_app->state & APOINT_NOTIFY))
- blinking = 1;
- else
- blinking = 0;
-
- if (blinking)
- wattron(notify->win, A_BLINK);
- if (too_long)
- mvwprintw(notify->win, 0, app_pos,
- "> %02d:%02d :: %s.. <",
- hours_left, minutes_left, buf);
- else
- mvwprintw(notify->win, 0, app_pos,
- "> %02d:%02d :: %s <",
- hours_left, minutes_left,
- notify_app->txt);
- if (blinking)
- wattroff(notify->win, A_BLINK);
-
- if (blinking &&
- !(notify_app->state & APOINT_NOTIFIED)) {
- notify_app->state |= APOINT_NOTIFIED;
- launch_cmd(nbar->cmd, nbar->shell);
- }
- pthread_mutex_unlock(&nbar->mutex);
- } else {
- notify_app->got_app = 0;
- pthread_mutex_unlock(&notify_app->mutex);
- pthread_mutex_unlock(&notify->mutex);
- notify_check_next_app();
- return;
- }
+ const int space = 3;
+ int file_pos, date_pos, app_pos, txt_max_len, too_long = 0;
+ int time_left, hours_left, minutes_left;
+ int blinking;
+ char buf[BUFSIZ];
+
+ date_pos = space;
+ pthread_mutex_lock (&notify->mutex);
+
+ file_pos = strlen (notify->date) + strlen (notify->time) + 7 + 2 * space;
+ app_pos = file_pos + strlen (notify->apts_file) + 2 + space;
+ txt_max_len = col - (app_pos + 12 + space);
+
+ custom_apply_attr (notify->win, ATTR_HIGHEST);
+ wattron (notify->win, A_UNDERLINE | A_REVERSE);
+ mvwhline (notify->win, 0, 0, ACS_HLINE, col);
+ mvwprintw (notify->win, 0, date_pos, "[ %s | %s ]",
+ notify->date, notify->time);
+ mvwprintw (notify->win, 0, file_pos, "(%s)", notify->apts_file);
+
+ pthread_mutex_lock (&notify_app->mutex);
+ if (notify_app->got_app)
+ {
+ if (strlen (notify_app->txt) > txt_max_len)
+ {
+ too_long = 1;
+ strncpy (buf, notify_app->txt, txt_max_len - 3);
+ buf[txt_max_len - 3] = '\0';
+ }
+ time_left = notify_app->time - notify->time_in_sec;
+ if (time_left > 0)
+ {
+ hours_left = (time_left / HOURINSEC);
+ minutes_left = (time_left - hours_left * HOURINSEC) / MININSEC;
+ pthread_mutex_lock (&nbar->mutex);
+
+ if (time_left < nbar->cntdwn && (notify_app->state & APOINT_NOTIFY))
+ blinking = 1;
+ else
+ blinking = 0;
+
+ if (blinking)
+ wattron (notify->win, A_BLINK);
+ if (too_long)
+ mvwprintw (notify->win, 0, app_pos, "> %02d:%02d :: %s.. <",
+ hours_left, minutes_left, buf);
+ else
+ mvwprintw (notify->win, 0, app_pos, "> %02d:%02d :: %s <",
+ hours_left, minutes_left, notify_app->txt);
+ if (blinking)
+ wattroff (notify->win, A_BLINK);
+
+ if (blinking && !(notify_app->state & APOINT_NOTIFIED))
+ {
+ notify_app->state |= APOINT_NOTIFIED;
+ launch_cmd (nbar->cmd, nbar->shell);
+ }
+ pthread_mutex_unlock (&nbar->mutex);
}
- pthread_mutex_unlock(&notify_app->mutex);
+ else
+ {
+ notify_app->got_app = 0;
+ pthread_mutex_unlock (&notify_app->mutex);
+ pthread_mutex_unlock (&notify->mutex);
+ notify_check_next_app ();
+ return;
+ }
+ }
+ pthread_mutex_unlock (&notify_app->mutex);
- wattroff(notify->win, A_UNDERLINE | A_REVERSE);
- custom_remove_attr(notify->win, ATTR_HIGHEST);
- wrefresh(notify->win);
+ wattroff (notify->win, A_UNDERLINE | A_REVERSE);
+ custom_remove_attr (notify->win, ATTR_HIGHEST);
+ wrefresh (notify->win);
- pthread_mutex_unlock(&notify->mutex);
+ pthread_mutex_unlock (&notify->mutex);
}
/* Update the notication bar content */
static void *
-notify_main_thread(void *arg)
+notify_main_thread (void *arg)
{
- const unsigned thread_sleep = 1;
- const unsigned check_app = MININSEC;
- int elapse= 0, got_app = 0;
- struct tm *ntime;
- time_t ntimer;
-
- elapse = 0;
- got_app = 0;
-
- for (;;) {
- ntimer = time(NULL);
- ntime = localtime(&ntimer);
- pthread_mutex_lock(&notify->mutex);
- notify->time_in_sec = ntimer;
- pthread_mutex_lock(&nbar->mutex);
- strftime(notify->time, NOTIFY_FIELD_LENGTH, nbar->timefmt, ntime);
- strftime(notify->date, NOTIFY_FIELD_LENGTH, nbar->datefmt, ntime);
- pthread_mutex_unlock(&nbar->mutex);
- pthread_mutex_unlock(&notify->mutex);
- notify_update_bar();
- sleep(thread_sleep);
- elapse += thread_sleep;
- if (elapse >= check_app) {
- elapse = 0;
- pthread_mutex_lock(&notify_app->mutex);
- got_app = notify_app->got_app;
- pthread_mutex_unlock(&notify_app->mutex);
- if (!got_app)
- notify_check_next_app();
- }
+ const unsigned thread_sleep = 1;
+ const unsigned check_app = MININSEC;
+ int elapse = 0, got_app = 0;
+ struct tm *ntime;
+ time_t ntimer;
+
+ elapse = 0;
+ got_app = 0;
+
+ for (;;)
+ {
+ ntimer = time (NULL);
+ ntime = localtime (&ntimer);
+ pthread_mutex_lock (&notify->mutex);
+ notify->time_in_sec = ntimer;
+ pthread_mutex_lock (&nbar->mutex);
+ strftime (notify->time, NOTIFY_FIELD_LENGTH, nbar->timefmt, ntime);
+ strftime (notify->date, NOTIFY_FIELD_LENGTH, nbar->datefmt, ntime);
+ pthread_mutex_unlock (&nbar->mutex);
+ pthread_mutex_unlock (&notify->mutex);
+ notify_update_bar ();
+ sleep (thread_sleep);
+ elapse += thread_sleep;
+ if (elapse >= check_app)
+ {
+ elapse = 0;
+ pthread_mutex_lock (&notify_app->mutex);
+ got_app = notify_app->got_app;
+ pthread_mutex_unlock (&notify_app->mutex);
+ if (!got_app)
+ notify_check_next_app ();
}
- pthread_exit((void*) 0);
+ }
+ pthread_exit ((void *) 0);
}
/* Look for the next appointment within the next 24 hours. */
static void *
-notify_thread_app(void *arg)
+notify_thread_app (void *arg)
{
- struct notify_app_s *tmp_app;
- time_t current_time;
-
- current_time = time(NULL);
-
- /* Use a temporary structure not to lock the mutex for a too
- * long time while looking for next appointment. */
- tmp_app = (struct notify_app_s *) malloc(sizeof(struct notify_app_s));
- tmp_app->time = current_time + DAYINSEC;
- tmp_app->got_app = 0;
- tmp_app->txt = NULL;
- tmp_app = recur_apoint_check_next(tmp_app, current_time, get_today());
- tmp_app = apoint_check_next(tmp_app, current_time);
-
- pthread_mutex_lock(&notify_app->mutex);
- if (tmp_app->got_app) {
- notify_app->got_app = 1;
- notify_app->time = tmp_app->time;
- notify_app->txt = mycpy(tmp_app->txt);
- notify_app->state = tmp_app->state;
- } else {
- notify_app->got_app = 0;
- }
- pthread_mutex_unlock(&notify_app->mutex);
-
- if (tmp_app->txt != NULL)
- free(tmp_app->txt);
- free(tmp_app);
- notify_update_bar();
-
- pthread_exit((void*) 0);
+ struct notify_app_s *tmp_app;
+ time_t current_time;
+
+ current_time = time (NULL);
+
+ /* Use a temporary structure not to lock the mutex for a too
+ * long time while looking for next appointment. */
+ tmp_app = (struct notify_app_s *) malloc (sizeof (struct notify_app_s));
+ tmp_app->time = current_time + DAYINSEC;
+ tmp_app->got_app = 0;
+ tmp_app->txt = NULL;
+ tmp_app = recur_apoint_check_next (tmp_app, current_time, get_today ());
+ tmp_app = apoint_check_next (tmp_app, current_time);
+
+ pthread_mutex_lock (&notify_app->mutex);
+ if (tmp_app->got_app)
+ {
+ notify_app->got_app = 1;
+ notify_app->time = tmp_app->time;
+ notify_app->txt = mycpy (tmp_app->txt);
+ notify_app->state = tmp_app->state;
+ }
+ else
+ {
+ notify_app->got_app = 0;
+ }
+ pthread_mutex_unlock (&notify_app->mutex);
+
+ if (tmp_app->txt != NULL)
+ free (tmp_app->txt);
+ free (tmp_app);
+ notify_update_bar ();
+
+ pthread_exit ((void *) 0);
}
/* Launch the thread notify_thread_app to look for next appointment. */
-void
-notify_check_next_app(void)
+void
+notify_check_next_app (void)
{
- pthread_t notify_t_app;
+ pthread_t notify_t_app;
- pthread_create(&notify_t_app, NULL, notify_thread_app, NULL);
- return;
+ pthread_create (&notify_t_app, NULL, notify_thread_app, NULL);
+ return;
}
/* Check if the newly created appointment is to be notified. */
-void
-notify_check_added(char *mesg, long start, char state)
+void
+notify_check_added (char *mesg, long start, char state)
{
- time_t current_time;
- int update_notify = 0;
- long gap;
-
- current_time = time(NULL);
- pthread_mutex_lock(&notify_app->mutex);
- if (!notify_app->got_app) {
- gap = start - current_time;
- if (gap >= 0 && gap <= DAYINSEC)
- update_notify = 1;
- } else if (start < notify_app->time && start >= current_time) {
- update_notify = 1;
- } else if (start == notify_app->time && state != notify_app->state)
- update_notify = 1;
-
- if (update_notify) {
- notify_app->got_app = 1;
- notify_app->time = start;
- notify_app->txt = mycpy(mesg);
- notify_app->state = state;
- }
- pthread_mutex_unlock(&notify_app->mutex);
- notify_update_bar();
+ time_t current_time;
+ int update_notify = 0;
+ long gap;
+
+ current_time = time (NULL);
+ pthread_mutex_lock (&notify_app->mutex);
+ if (!notify_app->got_app)
+ {
+ gap = start - current_time;
+ if (gap >= 0 && gap <= DAYINSEC)
+ update_notify = 1;
+ }
+ else if (start < notify_app->time && start >= current_time)
+ {
+ update_notify = 1;
+ }
+ else if (start == notify_app->time && state != notify_app->state)
+ update_notify = 1;
+
+ if (update_notify)
+ {
+ notify_app->got_app = 1;
+ notify_app->time = start;
+ notify_app->txt = mycpy (mesg);
+ notify_app->state = state;
+ }
+ pthread_mutex_unlock (&notify_app->mutex);
+ notify_update_bar ();
}
/* Check if the newly repeated appointment is to be notified. */
-void
-notify_check_repeated(recur_apoint_llist_node_t *i)
+void
+notify_check_repeated (recur_apoint_llist_node_t *i)
{
- long real_app_time;
- int update_notify = 0;
- time_t current_time;
-
- current_time = time(NULL);
- pthread_mutex_lock(&notify_app->mutex);
- if ((real_app_time = recur_item_inday(i->start, i->exc, i->rpt->type,
- i->rpt->freq, i->rpt->until, get_today()) > current_time)) {
- if (!notify_app->got_app) {
- if (real_app_time - current_time <= DAYINSEC)
- update_notify = 1;
- } else if (real_app_time < notify_app->time &&
- real_app_time >= current_time) {
- update_notify = 1;
- } else if (real_app_time == notify_app->time &&
- i->state != notify_app->state)
- update_notify = 1;
+ long real_app_time;
+ int update_notify = 0;
+ time_t current_time;
+
+ current_time = time (NULL);
+ pthread_mutex_lock (&notify_app->mutex);
+ if ((real_app_time = recur_item_inday (i->start, i->exc, i->rpt->type,
+ i->rpt->freq, i->rpt->until,
+ get_today ()) > current_time))
+ {
+ if (!notify_app->got_app)
+ {
+ if (real_app_time - current_time <= DAYINSEC)
+ update_notify = 1;
}
- if (update_notify) {
- notify_app->got_app = 1;
- notify_app->time = real_app_time;
- notify_app->txt = mycpy(i->mesg);
- notify_app->state = i->state;
+ else if (real_app_time < notify_app->time &&
+ real_app_time >= current_time)
+ {
+ update_notify = 1;
}
- pthread_mutex_unlock(&notify_app->mutex);
- notify_update_bar();
+ else if (real_app_time == notify_app->time &&
+ i->state != notify_app->state)
+ update_notify = 1;
+ }
+ if (update_notify)
+ {
+ notify_app->got_app = 1;
+ notify_app->time = real_app_time;
+ notify_app->txt = mycpy (i->mesg);
+ notify_app->state = i->state;
+ }
+ pthread_mutex_unlock (&notify_app->mutex);
+ notify_update_bar ();
}
-int
-notify_same_item(long time)
+int
+notify_same_item (long time)
{
- int same = 0;
-
- pthread_mutex_lock(&(notify_app->mutex));
- if (notify_app->got_app && notify_app->time == time)
- same = 1;
- pthread_mutex_unlock(&(notify_app->mutex));
-
- return same;
+ int same = 0;
+
+ pthread_mutex_lock (&(notify_app->mutex));
+ if (notify_app->got_app && notify_app->time == time)
+ same = 1;
+ pthread_mutex_unlock (&(notify_app->mutex));
+
+ return (same);
}
-int
-notify_same_recur_item(recur_apoint_llist_node_t *i)
+int
+notify_same_recur_item (recur_apoint_llist_node_t *i)
{
- int same = 0;
- long item_start = 0;
+ int same = 0;
+ long item_start = 0;
- item_start = recur_item_inday(i->start, i->exc, i->rpt->type,
- i->rpt->freq, i->rpt->until, get_today());
- pthread_mutex_lock(&notify_app->mutex);
- if (notify_app->got_app && item_start == notify_app->time)
- same = 1;
- pthread_mutex_unlock(&(notify_app->mutex));
+ item_start = recur_item_inday (i->start, i->exc, i->rpt->type,
+ i->rpt->freq, i->rpt->until, get_today ());
+ pthread_mutex_lock (&notify_app->mutex);
+ if (notify_app->got_app && item_start == notify_app->time)
+ same = 1;
+ pthread_mutex_unlock (&(notify_app->mutex));
- return same;
+ return (same);
}
/* Launch the notify-bar main thread. */
-void
-notify_start_main_thread(void)
+void
+notify_start_main_thread (void)
{
- pthread_create(&notify_t_main, NULL, notify_main_thread, NULL);
- notify_check_next_app();
- return;
+ pthread_create (&notify_t_main, NULL, notify_main_thread, NULL);
+ notify_check_next_app ();
+ return;
}
/* Print options related to the notify-bar. */
-static void
-notify_print_options(WINDOW *optwin, int col)
+static void
+notify_print_options (WINDOW *optwin, int col)
{
- enum {SHOW, DATE, CLOCK, WARN, CMD, NB_OPT};
-
- struct opt_s {
- char name[BUFSIZ];
- char desc[BUFSIZ];
- char value[BUFSIZ];
- } opt[NB_OPT];
-
- int i, y, x, l, x_pos, y_pos, x_offset, y_offset, maxcol, maxlen;
- char buf[BUFSIZ];
-
- x_pos = 3;
- x_offset = 4;
- y_pos = 4;
- y_offset = 3;
- maxcol = col - 2;
-
- strncpy(opt[SHOW].name, _("notify-bar_show = "), BUFSIZ);
- strncpy(opt[DATE].name, _("notify-bar_date = "), BUFSIZ);
- strncpy(opt[CLOCK].name, _("notify-bar_clock = "), BUFSIZ);
- strncpy(opt[WARN].name, _("notify-bar_warning = "), BUFSIZ);
- strncpy(opt[CMD].name, _("notify-bar_command = "), BUFSIZ);
-
- strncpy(opt[SHOW].desc,
- _("(if set to YES, notify-bar will be displayed)"),
- BUFSIZ);
- strncpy(opt[DATE].desc,
- _("(Format of the date to be displayed inside notify-bar)"),
- BUFSIZ);
- strncpy(opt[CLOCK].desc,
- _("(Format of the time to be displayed inside notify-bar)"),
- BUFSIZ);
- strncpy(opt[WARN].desc,
- _("(Warn user if an appointment is within next 'notify-bar_warning'"
- " seconds)"),
- BUFSIZ);
- strncpy(opt[CMD].desc,
- _("(Command used to notify user of an upcoming appointment)"),
- BUFSIZ);
-
- pthread_mutex_lock(&nbar->mutex);
-
- strncpy(opt[DATE].value, nbar->datefmt, BUFSIZ);
- strncpy(opt[CLOCK].value, nbar->timefmt, BUFSIZ);
- snprintf(opt[WARN].value, BUFSIZ, "%d", nbar->cntdwn);
- strncpy(opt[CMD].value, nbar->cmd, BUFSIZ);
-
- l = strlen(opt[SHOW].name);
- x = x_pos + x_offset + l;
- mvwprintw(optwin, y_pos, x_pos, "[1] %s", opt[SHOW].name);
- erase_window_part(optwin, x, y_pos, maxcol, y_pos);
- print_option_incolor(optwin, nbar->show, y_pos, x);
- mvwprintw(optwin, y_pos + 1, x_pos, opt[SHOW].desc);
-
- for (i = 1; i < NB_OPT; i++) {
- l = strlen(opt[i].name);
- y = y_pos + i * y_offset;
- x = x_pos + x_offset + l;
- maxlen = maxcol - x - 2;
-
- mvwprintw(optwin, y, x_pos, "[%d] %s", i + 1, opt[i].name);
- erase_window_part(optwin, x, y, maxcol, y);
- custom_apply_attr(optwin, ATTR_HIGHEST);
- if (strlen(opt[i].value) < maxlen)
- mvwprintw(optwin, y, x, "%s", opt[i].value);
- else {
- strncpy(buf, opt[i].value, maxlen - 1);
- buf[maxlen - 1] = '\0';
- mvwprintw(optwin, y, x, "%s...", buf);
- }
- custom_remove_attr(optwin, ATTR_HIGHEST);
- mvwprintw(optwin, y + 1, x_pos, opt[i].desc);
+ enum
+ { SHOW, DATE, CLOCK, WARN, CMD, NB_OPT };
+
+ struct opt_s
+ {
+ char name[BUFSIZ];
+ char desc[BUFSIZ];
+ char value[BUFSIZ];
+ }
+ opt[NB_OPT];
+
+ int i, y, x, l, x_pos, y_pos, x_offset, y_offset, maxcol, maxlen;
+ char buf[BUFSIZ];
+
+ x_pos = 3;
+ x_offset = 4;
+ y_pos = 4;
+ y_offset = 3;
+ maxcol = col - 2;
+
+ strncpy (opt[SHOW].name, _("notify-bar_show = "), BUFSIZ);
+ strncpy (opt[DATE].name, _("notify-bar_date = "), BUFSIZ);
+ strncpy (opt[CLOCK].name, _("notify-bar_clock = "), BUFSIZ);
+ strncpy (opt[WARN].name, _("notify-bar_warning = "), BUFSIZ);
+ strncpy (opt[CMD].name, _("notify-bar_command = "), BUFSIZ);
+
+ strncpy (opt[SHOW].desc,
+ _("(if set to YES, notify-bar will be displayed)"), BUFSIZ);
+ strncpy (opt[DATE].desc,
+ _("(Format of the date to be displayed inside notify-bar)"),
+ BUFSIZ);
+ strncpy (opt[CLOCK].desc,
+ _("(Format of the time to be displayed inside notify-bar)"),
+ BUFSIZ);
+ strncpy (opt[WARN].desc,
+ _("(Warn user if an appointment is within next 'notify-bar_warning'"
+ " seconds)"), BUFSIZ);
+ strncpy (opt[CMD].desc,
+ _("(Command used to notify user of an upcoming appointment)"),
+ BUFSIZ);
+
+ pthread_mutex_lock (&nbar->mutex);
+
+ strncpy (opt[DATE].value, nbar->datefmt, BUFSIZ);
+ strncpy (opt[CLOCK].value, nbar->timefmt, BUFSIZ);
+ snprintf (opt[WARN].value, BUFSIZ, "%d", nbar->cntdwn);
+ strncpy (opt[CMD].value, nbar->cmd, BUFSIZ);
+
+ l = strlen (opt[SHOW].name);
+ x = x_pos + x_offset + l;
+ mvwprintw (optwin, y_pos, x_pos, "[1] %s", opt[SHOW].name);
+ erase_window_part (optwin, x, y_pos, maxcol, y_pos);
+ print_option_incolor (optwin, nbar->show, y_pos, x);
+ mvwprintw (optwin, y_pos + 1, x_pos, opt[SHOW].desc);
+
+ for (i = 1; i < NB_OPT; i++)
+ {
+ l = strlen (opt[i].name);
+ y = y_pos + i * y_offset;
+ x = x_pos + x_offset + l;
+ maxlen = maxcol - x - 2;
+
+ mvwprintw (optwin, y, x_pos, "[%d] %s", i + 1, opt[i].name);
+ erase_window_part (optwin, x, y, maxcol, y);
+ custom_apply_attr (optwin, ATTR_HIGHEST);
+ if (strlen (opt[i].value) < maxlen)
+ mvwprintw (optwin, y, x, "%s", opt[i].value);
+ else
+ {
+ strncpy (buf, opt[i].value, maxlen - 1);
+ buf[maxlen - 1] = '\0';
+ mvwprintw (optwin, y, x, "%s...", buf);
}
-
- pthread_mutex_unlock(&nbar->mutex);
- wmove(win[STA].p, 1, 0);
- wnoutrefresh(optwin);
- doupdate();
+ custom_remove_attr (optwin, ATTR_HIGHEST);
+ mvwprintw (optwin, y + 1, x_pos, opt[i].desc);
+ }
+
+ pthread_mutex_unlock (&nbar->mutex);
+ wmove (win[STA].p, 1, 0);
+ wnoutrefresh (optwin);
+ doupdate ();
}
/* Notify-bar configuration. */
-void
-notify_config_bar(void)
+void
+notify_config_bar (void)
{
- window_t conf_win;
- char label[BUFSIZ];
- char *buf;
- char *number_str =
- _("Enter an option number to change its value [Q to quit] ");
- char *date_str =
- _("Enter the date format (see 'man 3 strftime' for possible formats) ");
- char *time_str =
- _("Enter the time format (see 'man 3 strftime' for possible formats) ");
- char *count_str =
- _("Enter the number of seconds (0 not to be warned before an appointment)");
- char *cmd_str = _("Enter the notification command ");
- int ch = 0 , change_win = 1;
-
- buf = (char *)malloc(BUFSIZ);
- snprintf(label, BUFSIZ, _("CalCurse %s | notify-bar options"), VERSION);
- custom_confwin_init(&conf_win, label);
-
- while (ch != 'q') {
- if (change_win)
- custom_confwin_init(&conf_win, label);
- status_mesg(number_str, "");
- notify_print_options(conf_win.p, col);
- *buf = '\0';
- ch = wgetch(win[STA].p);
-
- switch (ch) {
- case KEY_RESIZE:
- endwin();
- refresh();
- curs_set(0);
- delwin(conf_win.p);
- custom_confwin_init(&conf_win, label);
- break;
- case '1':
- pthread_mutex_lock(&nbar->mutex);
- nbar->show = !nbar->show;
- pthread_mutex_unlock(&nbar->mutex);
- if (notify_bar())
- notify_start_main_thread();
- else
- notify_stop_main_thread();
- delwin(conf_win.p);
- change_win = 1;
- break;
- case '2':
- status_mesg(date_str, "");
- pthread_mutex_lock(&nbar->mutex);
- strncpy(buf, nbar->datefmt, strlen(nbar->datefmt) + 1);
- pthread_mutex_unlock(&nbar->mutex);
- if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
- pthread_mutex_lock(&nbar->mutex);
- strncpy(nbar->datefmt, buf, strlen(buf) + 1);
- pthread_mutex_unlock(&nbar->mutex);
- }
- change_win = 0;
- break;
- case '3':
- status_mesg(time_str, "");
- pthread_mutex_lock(&nbar->mutex);
- strncpy(buf, nbar->timefmt, strlen(nbar->timefmt) + 1);
- pthread_mutex_unlock(&nbar->mutex);
- if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
- pthread_mutex_lock(&nbar->mutex);
- strncpy(nbar->timefmt, buf, strlen(buf) + 1);
- pthread_mutex_unlock(&nbar->mutex);
- }
- change_win = 0;
- break;
- case '4':
- status_mesg(count_str, "");
- pthread_mutex_lock(&nbar->mutex);
- printf(buf, "%d", nbar->cntdwn);
- pthread_mutex_unlock(&nbar->mutex);
- if (updatestring(win[STA].p, &buf, 0, 1) == 0 &&
- is_all_digit(buf) &&
- atoi(buf) >= 0 && atoi(buf) <= DAYINSEC) {
- pthread_mutex_lock(&nbar->mutex);
- nbar->cntdwn = atoi(buf);
- pthread_mutex_unlock(&nbar->mutex);
- }
- change_win = 0;
- break;
- case '5':
- status_mesg(cmd_str, "");
- pthread_mutex_lock(&nbar->mutex);
- strncpy(buf, nbar->cmd, strlen(nbar->cmd) + 1);
- pthread_mutex_unlock(&nbar->mutex);
- if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
- pthread_mutex_lock(&nbar->mutex);
- strncpy(nbar->cmd, buf, strlen(buf) + 1);
- pthread_mutex_unlock(&nbar->mutex);
- }
- change_win = 0;
- break;
- }
+ window_t conf_win;
+ char label[BUFSIZ];
+ char *buf;
+ char *number_str =
+ _("Enter an option number to change its value [Q to quit] ");
+ char *date_str =
+ _("Enter the date format (see 'man 3 strftime' for possible formats) ");
+ char *time_str =
+ _("Enter the time format (see 'man 3 strftime' for possible formats) ");
+ char *count_str =
+ _("Enter the number of seconds (0 not to be warned before an appointment)");
+ char *cmd_str = _("Enter the notification command ");
+ int ch = 0, change_win = 1;
+
+ buf = (char *) malloc (BUFSIZ);
+ snprintf (label, BUFSIZ, _("CalCurse %s | notify-bar options"), VERSION);
+ custom_confwin_init (&conf_win, label);
+
+ while (ch != 'q')
+ {
+ if (change_win)
+ custom_confwin_init (&conf_win, label);
+ status_mesg (number_str, "");
+ notify_print_options (conf_win.p, col);
+ *buf = '\0';
+ ch = wgetch (win[STA].p);
+
+ switch (ch)
+ {
+ case KEY_RESIZE:
+ endwin ();
+ refresh ();
+ curs_set (0);
+ delwin (conf_win.p);
+ custom_confwin_init (&conf_win, label);
+ break;
+ case '1':
+ pthread_mutex_lock (&nbar->mutex);
+ nbar->show = !nbar->show;
+ pthread_mutex_unlock (&nbar->mutex);
+ if (notify_bar ())
+ notify_start_main_thread ();
+ else
+ notify_stop_main_thread ();
+ delwin (conf_win.p);
+ change_win = 1;
+ break;
+ case '2':
+ status_mesg (date_str, "");
+ pthread_mutex_lock (&nbar->mutex);
+ strncpy (buf, nbar->datefmt, strlen (nbar->datefmt) + 1);
+ pthread_mutex_unlock (&nbar->mutex);
+ if (updatestring (win[STA].p, &buf, 0, 1) == 0)
+ {
+ pthread_mutex_lock (&nbar->mutex);
+ strncpy (nbar->datefmt, buf, strlen (buf) + 1);
+ pthread_mutex_unlock (&nbar->mutex);
+ }
+ change_win = 0;
+ break;
+ case '3':
+ status_mesg (time_str, "");
+ pthread_mutex_lock (&nbar->mutex);
+ strncpy (buf, nbar->timefmt, strlen (nbar->timefmt) + 1);
+ pthread_mutex_unlock (&nbar->mutex);
+ if (updatestring (win[STA].p, &buf, 0, 1) == 0)
+ {
+ pthread_mutex_lock (&nbar->mutex);
+ strncpy (nbar->timefmt, buf, strlen (buf) + 1);
+ pthread_mutex_unlock (&nbar->mutex);
+ }
+ change_win = 0;
+ break;
+ case '4':
+ status_mesg (count_str, "");
+ pthread_mutex_lock (&nbar->mutex);
+ printf (buf, "%d", nbar->cntdwn);
+ pthread_mutex_unlock (&nbar->mutex);
+ if (updatestring (win[STA].p, &buf, 0, 1) == 0 &&
+ is_all_digit (buf) && atoi (buf) >= 0 && atoi (buf) <= DAYINSEC)
+ {
+ pthread_mutex_lock (&nbar->mutex);
+ nbar->cntdwn = atoi (buf);
+ pthread_mutex_unlock (&nbar->mutex);
+ }
+ change_win = 0;
+ break;
+ case '5':
+ status_mesg (cmd_str, "");
+ pthread_mutex_lock (&nbar->mutex);
+ strncpy (buf, nbar->cmd, strlen (nbar->cmd) + 1);
+ pthread_mutex_unlock (&nbar->mutex);
+ if (updatestring (win[STA].p, &buf, 0, 1) == 0)
+ {
+ pthread_mutex_lock (&nbar->mutex);
+ strncpy (nbar->cmd, buf, strlen (buf) + 1);
+ pthread_mutex_unlock (&nbar->mutex);
+ }
+ change_win = 0;
+ break;
}
- free(buf);
- delwin(conf_win.p);
+ }
+ free (buf);
+ delwin (conf_win.p);
}
diff --git a/src/notify.h b/src/notify.h
index dccfa2d..32fcab2 100755
--- a/src/notify.h
+++ b/src/notify.h
@@ -1,8 +1,8 @@
-/* $calcurse: notify.h,v 1.12 2007/08/15 15:33:01 culot Exp $ */
+/* $calcurse: notify.h,v 1.13 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
- * Copyright (c) 2004-2007 Frederic Culot
+ * Copyright (c) 2004-2008 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -33,35 +33,37 @@
#define NOTIFY_FIELD_LENGTH 25
-struct notify_vars_s {
- WINDOW *win;
- long time_in_sec;
- char *apts_file;
- char time[NOTIFY_FIELD_LENGTH];
- char date[NOTIFY_FIELD_LENGTH];
- pthread_mutex_t mutex;
+struct notify_vars_s
+{
+ WINDOW *win;
+ long time_in_sec;
+ char *apts_file;
+ char time[NOTIFY_FIELD_LENGTH];
+ char date[NOTIFY_FIELD_LENGTH];
+ pthread_mutex_t mutex;
};
-struct notify_app_s {
- long time;
- int got_app;
- char *txt;
- char state;
- pthread_mutex_t mutex;
+struct notify_app_s
+{
+ long time;
+ int got_app;
+ char *txt;
+ char state;
+ pthread_mutex_t mutex;
};
-int notify_bar(void);
-void notify_init_vars(void);
-void notify_init_bar(void);
-void notify_start_main_thread(void);
-void notify_stop_main_thread(void);
-void notify_reinit_bar(int, int, int, int);
-void notify_update_bar(void);
-void notify_check_next_app(void);
-void notify_check_added(char *, long, char);
-void notify_check_repeated(recur_apoint_llist_node_t *);
-int notify_same_item(long);
-int notify_same_recur_item(recur_apoint_llist_node_t *);
-void notify_config_bar(void);
+int notify_bar (void);
+void notify_init_vars (void);
+void notify_init_bar (void);
+void notify_start_main_thread (void);
+void notify_stop_main_thread (void);
+void notify_reinit_bar (int, int, int, int);
+void notify_update_bar (void);
+void notify_check_next_app (void);
+void notify_check_added (char *, long, char);
+void notify_check_repeated (recur_apoint_llist_node_t *);
+int notify_same_item (long);
+int notify_same_recur_item (recur_apoint_llist_node_t *);
+void notify_config_bar (void);
#endif /* CALCURSE_NOTIFY_H */
diff --git a/src/recur.c b/src/recur.c
index 22f477e..c862188 100755
--- a/src/recur.c
+++ b/src/recur.c
@@ -1,4 +1,4 @@
-/* $calcurse: recur.c,v 1.34 2008/04/09 20:38:29 culot Exp $ */
+/* $calcurse: recur.c,v 1.35 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -39,346 +39,369 @@
recur_apoint_llist_t *recur_alist_p;
struct recur_event_s *recur_elist;
-int
-recur_apoint_llist_init(void)
+int
+recur_apoint_llist_init (void)
{
- recur_alist_p = (recur_apoint_llist_t *)
- malloc(sizeof(recur_apoint_llist_t));
- recur_alist_p->root = NULL;
- pthread_mutex_init(&(recur_alist_p->mutex), NULL);
+ recur_alist_p = (recur_apoint_llist_t *)
+ malloc (sizeof (recur_apoint_llist_t));
+ recur_alist_p->root = NULL;
+ pthread_mutex_init (&(recur_alist_p->mutex), NULL);
- return 0;
+ return (0);
}
/* Insert a new recursive appointment in the general linked list */
static recur_apoint_llist_node_t *
-recur_apoint_new(char *mesg, char *note, long start, long dur, char state,
- int type, int freq, long until, struct days_s *except)
+recur_apoint_new (char *mesg, char *note, long start, long dur, char state,
+ int type, int freq, long until, struct days_s *except)
{
- recur_apoint_llist_node_t *o, **i;
- o = (recur_apoint_llist_node_t *)
- malloc(sizeof(recur_apoint_llist_node_t));
- o->rpt = (struct rpt_s *) malloc(sizeof(struct rpt_s));
- o->mesg = (char *) malloc(strlen(mesg) + 1);
- o->exc = (struct days_s *) malloc(sizeof(struct days_s));
- strncpy(o->mesg, mesg, strlen(mesg) + 1);
- o->note = (note != NULL) ? strdup(note) : NULL;
- o->start = start;
- o->state = state;
- o->dur = dur;
- o->rpt->type = type;
- o->rpt->freq = freq;
- o->rpt->until = until;
- o->exc = except;
-
- pthread_mutex_lock(&(recur_alist_p->mutex));
- i = &recur_alist_p->root;
- for (;;) {
- if (*i == 0 || (*i)->start > start) {
- o->next = *i;
- *i = o;
- break;
- }
- i = &(*i)->next;
+ recur_apoint_llist_node_t *o, **i;
+ o = (recur_apoint_llist_node_t *)
+ malloc (sizeof (recur_apoint_llist_node_t));
+ o->rpt = (struct rpt_s *) malloc (sizeof (struct rpt_s));
+ o->mesg = (char *) malloc (strlen (mesg) + 1);
+ o->exc = (struct days_s *) malloc (sizeof (struct days_s));
+ strncpy (o->mesg, mesg, strlen (mesg) + 1);
+ o->note = (note != NULL) ? strdup (note) : NULL;
+ o->start = start;
+ o->state = state;
+ o->dur = dur;
+ o->rpt->type = type;
+ o->rpt->freq = freq;
+ o->rpt->until = until;
+ o->exc = except;
+
+ pthread_mutex_lock (&(recur_alist_p->mutex));
+ i = &recur_alist_p->root;
+ for (;;)
+ {
+ if (*i == 0 || (*i)->start > start)
+ {
+ o->next = *i;
+ *i = o;
+ break;
}
- pthread_mutex_unlock(&(recur_alist_p->mutex));
+ i = &(*i)->next;
+ }
+ pthread_mutex_unlock (&(recur_alist_p->mutex));
- return o;
+ return (o);
}
/* Insert a new recursive event in the general linked list */
static struct recur_event_s *
-recur_event_new(char *mesg, char *note, long day, int id, int type, int freq,
- long until, struct days_s *except)
+recur_event_new (char *mesg, char *note, long day, int id, int type, int freq,
+ long until, struct days_s *except)
{
- struct recur_event_s *o, **i;
- o = (struct recur_event_s *) malloc(sizeof(struct recur_event_s));
- o->rpt = (struct rpt_s *) malloc(sizeof(struct rpt_s));
- o->mesg = (char *) malloc(strlen(mesg) + 1);
- o->note = (note != NULL) ? strdup(note) : NULL;
- o->exc = (struct days_s *) malloc(sizeof(struct days_s));
- strncpy(o->mesg, mesg, strlen(mesg) + 1);
- o->day = day;
- o->id = id;
- o->rpt->type = type;
- o->rpt->freq = freq;
- o->rpt->until = until;
- o->exc = except;
- i = &recur_elist;
- for (;;) {
- if (*i == 0 || (*i)->day > day) {
- o->next = *i;
- *i = o;
- break;
- }
- i = &(*i)->next;
+ struct recur_event_s *o, **i;
+ o = (struct recur_event_s *) malloc (sizeof (struct recur_event_s));
+ o->rpt = (struct rpt_s *) malloc (sizeof (struct rpt_s));
+ o->mesg = (char *) malloc (strlen (mesg) + 1);
+ o->note = (note != NULL) ? strdup (note) : NULL;
+ o->exc = (struct days_s *) malloc (sizeof (struct days_s));
+ strncpy (o->mesg, mesg, strlen (mesg) + 1);
+ o->day = day;
+ o->id = id;
+ o->rpt->type = type;
+ o->rpt->freq = freq;
+ o->rpt->until = until;
+ o->exc = except;
+ i = &recur_elist;
+ for (;;)
+ {
+ if (*i == 0 || (*i)->day > day)
+ {
+ o->next = *i;
+ *i = o;
+ break;
}
- return o;
+ i = &(*i)->next;
+ }
+ return (o);
}
/*
* Correspondance between the defines on recursive type,
* and the letter to be written in file.
*/
-char
-recur_def2char(recur_types_t define)
+char
+recur_def2char (recur_types_t define)
{
- char recur_char;
- char *error = _("FATAL ERROR in recur_def2char: unknown recur type\n");
-
- switch (define) {
- case RECUR_DAILY:
- recur_char = 'D';
- break;
- case RECUR_WEEKLY:
- recur_char = 'W';
- break;
- case RECUR_MONTHLY:
- recur_char = 'M';
- break;
- case RECUR_YEARLY:
- recur_char = 'Y';
- break;
- default:
- fputs(error, stderr);
- exit(EXIT_FAILURE);
- }
-
- return (recur_char);
+ char recur_char;
+ char *error = _("FATAL ERROR in recur_def2char: unknown recur type\n");
+
+ switch (define)
+ {
+ case RECUR_DAILY:
+ recur_char = 'D';
+ break;
+ case RECUR_WEEKLY:
+ recur_char = 'W';
+ break;
+ case RECUR_MONTHLY:
+ recur_char = 'M';
+ break;
+ case RECUR_YEARLY:
+ recur_char = 'Y';
+ break;
+ default:
+ fputs (error, stderr);
+ exit (EXIT_FAILURE);
+ }
+
+ return (recur_char);
}
/*
* Correspondance between the letters written in file and the defines
* concerning the recursive type.
*/
-int
-recur_char2def(char type)
+int
+recur_char2def (char type)
{
- int recur_def;
- char *error = _("FATAL ERROR in recur_char2def: unknown char\n");
-
- switch (type) {
- case 'D':
- recur_def = RECUR_DAILY;
- break;
- case 'W':
- recur_def = RECUR_WEEKLY;
- break;
- case 'M':
- recur_def = RECUR_MONTHLY;
- break;
- case 'Y':
- recur_def = RECUR_YEARLY;
- break;
- default:
- fputs(error, stderr);
- exit(EXIT_FAILURE);
- }
- return (recur_def);
+ int recur_def;
+ char *error = _("FATAL ERROR in recur_char2def: unknown char\n");
+
+ switch (type)
+ {
+ case 'D':
+ recur_def = RECUR_DAILY;
+ break;
+ case 'W':
+ recur_def = RECUR_WEEKLY;
+ break;
+ case 'M':
+ recur_def = RECUR_MONTHLY;
+ break;
+ case 'Y':
+ recur_def = RECUR_YEARLY;
+ break;
+ default:
+ fputs (error, stderr);
+ exit (EXIT_FAILURE);
+ }
+ return (recur_def);
}
/* Write days for which recurrent items should not be repeated. */
-static void
-recur_write_exc(struct days_s *exc, FILE *f) {
- struct tm *lt;
- time_t t;
- int st_mon, st_day, st_year;
-
- while (exc) {
- t = exc->st;
- lt = localtime(&t);
- st_mon = lt->tm_mon + 1;
- st_day = lt->tm_mday;
- st_year = lt->tm_year + 1900;
- fprintf(f, " !%02u/%02u/%04u", st_mon, st_day, st_year);
- exc = exc->next;
- }
+static void
+recur_write_exc (struct days_s *exc, FILE *f)
+{
+ struct tm *lt;
+ time_t t;
+ int st_mon, st_day, st_year;
+
+ while (exc)
+ {
+ t = exc->st;
+ lt = localtime (&t);
+ st_mon = lt->tm_mon + 1;
+ st_day = lt->tm_mday;
+ st_year = lt->tm_year + 1900;
+ fprintf (f, " !%02u/%02u/%04u", st_mon, st_day, st_year);
+ exc = exc->next;
+ }
}
/* Load the recursive appointment description */
recur_apoint_llist_node_t *
-recur_apoint_scan(FILE * f, struct tm start, struct tm end, char type,
- int freq, struct tm until, char *note, struct days_s *exc, char state)
+recur_apoint_scan (FILE *f, struct tm start, struct tm end, char type,
+ int freq, struct tm until, char *note, struct days_s *exc,
+ char state)
{
- struct tm *lt;
- char buf[MESG_MAXSIZE], *nl;
- time_t tstart, tend, t, tuntil;
-
- t = time(NULL);
- lt = localtime(&t);
-
- /* Read the appointment description */
- fgets(buf, MESG_MAXSIZE, f);
- nl = strchr(buf, '\n');
- if (nl) {
- *nl = '\0';
- }
-
- start.tm_sec = end.tm_sec = 0;
- start.tm_isdst = end.tm_isdst = -1;
- start.tm_year -= 1900;
- start.tm_mon--;
- end.tm_year -= 1900;
- end.tm_mon--;
- tstart = mktime(&start);
- tend = mktime(&end);
-
- if (until.tm_year != 0) {
- until.tm_hour = 23;
- until.tm_min = 59;
- until.tm_sec = 0;
- until.tm_isdst = -1;
- until.tm_year -= 1900;
- until.tm_mon--;
- tuntil = mktime(&until);
- } else {
- tuntil = 0;
- }
-
- if (tstart == -1 || tend == -1 || tstart > tend || tuntil == -1) {
- fputs(_("FATAL ERROR in apoint_scan: date error in the appointment\n"), stderr);
- exit(EXIT_FAILURE);
- }
-
- return (recur_apoint_new(buf, note, tstart, tend - tstart, state,
- recur_char2def(type), freq, tuntil, exc));
+ struct tm *lt;
+ char buf[MESG_MAXSIZE], *nl;
+ time_t tstart, tend, t, tuntil;
+
+ t = time (NULL);
+ lt = localtime (&t);
+
+ /* Read the appointment description */
+ fgets (buf, MESG_MAXSIZE, f);
+ nl = strchr (buf, '\n');
+ if (nl)
+ {
+ *nl = '\0';
+ }
+ start.tm_sec = end.tm_sec = 0;
+ start.tm_isdst = end.tm_isdst = -1;
+ start.tm_year -= 1900;
+ start.tm_mon--;
+ end.tm_year -= 1900;
+ end.tm_mon--;
+ tstart = mktime (&start);
+ tend = mktime (&end);
+
+ if (until.tm_year != 0)
+ {
+ until.tm_hour = 23;
+ until.tm_min = 59;
+ until.tm_sec = 0;
+ until.tm_isdst = -1;
+ until.tm_year -= 1900;
+ until.tm_mon--;
+ tuntil = mktime (&until);
+ }
+ else
+ {
+ tuntil = 0;
+ }
+
+ if (tstart == -1 || tend == -1 || tstart > tend || tuntil == -1)
+ {
+ fputs (_("FATAL ERROR in apoint_scan: date error in the appointment\n"),
+ stderr);
+ exit (EXIT_FAILURE);
+ }
+
+ return (recur_apoint_new (buf, note, tstart, tend - tstart, state,
+ recur_char2def (type), freq, tuntil, exc));
}
/* Load the recursive events from file */
struct recur_event_s *
-recur_event_scan(FILE * f, struct tm start, int id, char type, int freq,
-struct tm until, char *note, struct days_s *exc)
+recur_event_scan (FILE *f, struct tm start, int id, char type, int freq,
+ struct tm until, char *note, struct days_s *exc)
{
- struct tm *lt;
- char buf[MESG_MAXSIZE], *nl;
- time_t tstart, t, tuntil;
-
- t = time(NULL);
- lt = localtime(&t);
-
- /* Read the event description */
- fgets(buf, MESG_MAXSIZE, f);
- nl = strchr(buf, '\n');
- if (nl) {
- *nl = '\0';
- }
-
- start.tm_hour = until.tm_hour = 12;
- start.tm_min = until.tm_min = 0;
- start.tm_sec = until.tm_sec = 0;
- start.tm_isdst = until.tm_isdst = -1;
- start.tm_year -= 1900;
- start.tm_mon--;
- if (until.tm_year != 0) {
- until.tm_year -= 1900;
- until.tm_mon--;
- tuntil = mktime(&until);
- } else {
- tuntil = 0;
- }
- tstart = mktime(&start);
- if ( (tstart == -1) || (tuntil == -1) ) {
- fputs(_("FATAL ERROR in recur_event_scan: "
- "date error in the event\n"), stderr);
- exit(EXIT_FAILURE);
- }
-
- return recur_event_new(buf, note, tstart, id, recur_char2def(type),
- freq, tuntil, exc);
+ struct tm *lt;
+ char buf[MESG_MAXSIZE], *nl;
+ time_t tstart, t, tuntil;
+
+ t = time (NULL);
+ lt = localtime (&t);
+
+ /* Read the event description */
+ fgets (buf, MESG_MAXSIZE, f);
+ nl = strchr (buf, '\n');
+ if (nl)
+ {
+ *nl = '\0';
+ }
+ start.tm_hour = until.tm_hour = 12;
+ start.tm_min = until.tm_min = 0;
+ start.tm_sec = until.tm_sec = 0;
+ start.tm_isdst = until.tm_isdst = -1;
+ start.tm_year -= 1900;
+ start.tm_mon--;
+ if (until.tm_year != 0)
+ {
+ until.tm_year -= 1900;
+ until.tm_mon--;
+ tuntil = mktime (&until);
+ }
+ else
+ {
+ tuntil = 0;
+ }
+ tstart = mktime (&start);
+ if ((tstart == -1) || (tuntil == -1))
+ {
+ fputs (_("FATAL ERROR in recur_event_scan: "
+ "date error in the event\n"), stderr);
+ exit (EXIT_FAILURE);
+ }
+
+ return (recur_event_new (buf, note, tstart, id, recur_char2def (type),
+ freq, tuntil, exc));
}
/* Writting of a recursive appointment into file. */
-static void
-recur_apoint_write(recur_apoint_llist_node_t *o, FILE *f)
+static void
+recur_apoint_write (recur_apoint_llist_node_t *o, FILE *f)
{
- struct tm *lt;
- time_t t;
-
- t = o->start;
- lt = localtime(&t);
- fprintf(f, "%02u/%02u/%04u @ %02u:%02u",
- lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year,
- lt->tm_hour, lt->tm_min);
-
- t = o->start + o->dur;
- lt = localtime(&t);
- fprintf(f, " -> %02u/%02u/%04u @ %02u:%02u",
- lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year,
- lt->tm_hour, lt->tm_min);
-
- t = o->rpt->until;
- if (t == 0) { /* We have an endless recurrent appointment. */
- fprintf(f, " {%d%c", o->rpt->freq,
- recur_def2char(o->rpt->type));
- } else {
- lt = localtime(&t);
- fprintf(f, " {%d%c -> %02u/%02u/%04u",
- o->rpt->freq, recur_def2char(o->rpt->type),
- lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year);
- }
- if (o->exc != 0)
- recur_write_exc(o->exc, f);
- fprintf(f, "} ");
- if (o->note != NULL)
- fprintf(f, ">%s ", o->note);
- if (o->state & APOINT_NOTIFY)
- fprintf(f, "!");
- else
- fprintf(f, "|");
- fprintf(f, "%s\n", o->mesg);
+ struct tm *lt;
+ time_t t;
+
+ t = o->start;
+ lt = localtime (&t);
+ fprintf (f, "%02u/%02u/%04u @ %02u:%02u",
+ lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year,
+ lt->tm_hour, lt->tm_min);
+
+ t = o->start + o->dur;
+ lt = localtime (&t);
+ fprintf (f, " -> %02u/%02u/%04u @ %02u:%02u",
+ lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year,
+ lt->tm_hour, lt->tm_min);
+
+ t = o->rpt->until;
+ if (t == 0)
+ { /* We have an endless recurrent appointment. */
+ fprintf (f, " {%d%c", o->rpt->freq, recur_def2char (o->rpt->type));
+ }
+ else
+ {
+ lt = localtime (&t);
+ fprintf (f, " {%d%c -> %02u/%02u/%04u",
+ o->rpt->freq, recur_def2char (o->rpt->type),
+ lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year);
+ }
+ if (o->exc != 0)
+ recur_write_exc (o->exc, f);
+ fprintf (f, "} ");
+ if (o->note != NULL)
+ fprintf (f, ">%s ", o->note);
+ if (o->state & APOINT_NOTIFY)
+ fprintf (f, "!");
+ else
+ fprintf (f, "|");
+ fprintf (f, "%s\n", o->mesg);
}
/* Writting of a recursive event into file. */
-static void
-recur_event_write(struct recur_event_s *o, FILE *f)
+static void
+recur_event_write (struct recur_event_s *o, FILE *f)
{
- struct tm *lt;
- time_t t;
- int st_mon, st_day, st_year;
- int end_mon, end_day, end_year;
-
- t = o->day;
- lt = localtime(&t);
- st_mon = lt->tm_mon + 1;
- st_day = lt->tm_mday;
- st_year = lt->tm_year + 1900;
- t = o->rpt->until;
- if (t == 0) { /* We have an endless recurrent event. */
- fprintf(f, "%02u/%02u/%04u [%d] {%d%c",
- st_mon, st_day, st_year, o->id, o->rpt->freq,
- recur_def2char(o->rpt->type));
- } else {
- lt = localtime(&t);
- end_mon = lt->tm_mon + 1;
- end_day = lt->tm_mday;
- end_year = lt->tm_year + 1900;
- fprintf(f, "%02u/%02u/%04u [%d] {%d%c -> %02u/%02u/%04u",
- st_mon, st_day, st_year, o->id,
- o->rpt->freq, recur_def2char(o->rpt->type),
- end_mon, end_day, end_year);
- }
- if (o->exc != 0)
- recur_write_exc(o->exc, f);
- fprintf(f, "} ");
- if (o->note != NULL)
- fprintf(f, ">%s ", o->note);
- fprintf(f, "%s\n", o->mesg);
+ struct tm *lt;
+ time_t t;
+ int st_mon, st_day, st_year;
+ int end_mon, end_day, end_year;
+
+ t = o->day;
+ lt = localtime (&t);
+ st_mon = lt->tm_mon + 1;
+ st_day = lt->tm_mday;
+ st_year = lt->tm_year + 1900;
+ t = o->rpt->until;
+ if (t == 0)
+ { /* We have an endless recurrent event. */
+ fprintf (f, "%02u/%02u/%04u [%d] {%d%c",
+ st_mon, st_day, st_year, o->id, o->rpt->freq,
+ recur_def2char (o->rpt->type));
+ }
+ else
+ {
+ lt = localtime (&t);
+ end_mon = lt->tm_mon + 1;
+ end_day = lt->tm_mday;
+ end_year = lt->tm_year + 1900;
+ fprintf (f, "%02u/%02u/%04u [%d] {%d%c -> %02u/%02u/%04u",
+ st_mon, st_day, st_year, o->id,
+ o->rpt->freq, recur_def2char (o->rpt->type),
+ end_mon, end_day, end_year);
+ }
+ if (o->exc != 0)
+ recur_write_exc (o->exc, f);
+ fprintf (f, "} ");
+ if (o->note != NULL)
+ fprintf (f, ">%s ", o->note);
+ fprintf (f, "%s\n", o->mesg);
}
/* Write recursive items to file. */
-void
-recur_save_data(FILE *f)
+void
+recur_save_data (FILE *f)
{
- struct recur_event_s *re;
- recur_apoint_llist_node_t *ra;
+ struct recur_event_s *re;
+ recur_apoint_llist_node_t *ra;
- for (re = recur_elist; re != 0; re = re->next)
- recur_event_write(re, f);
+ for (re = recur_elist; re != 0; re = re->next)
+ recur_event_write (re, f);
- pthread_mutex_lock(&(recur_alist_p->mutex));
- for (ra = recur_alist_p->root; ra != 0; ra = ra->next)
- recur_apoint_write(ra, f);
- pthread_mutex_unlock(&(recur_alist_p->mutex));
+ pthread_mutex_lock (&(recur_alist_p->mutex));
+ for (ra = recur_alist_p->root; ra != 0; ra = ra->next)
+ recur_apoint_write (ra, f);
+ pthread_mutex_unlock (&(recur_alist_p->mutex));
}
/*
@@ -386,211 +409,223 @@ recur_save_data(FILE *f)
* and if yes, return the real start time.
* This function was improved thanks to Tony's patch.
*/
-unsigned
-recur_item_inday(long item_start, struct days_s *item_exc, int rpt_type,
- int rpt_freq, long rpt_until, long day_start)
+unsigned
+recur_item_inday (long item_start, struct days_s *item_exc, int rpt_type,
+ int rpt_freq, long rpt_until, long day_start)
{
- date_t start_date;
- long day_end, diff;
- struct tm lt_item, lt_day;
- struct days_s *exc;
- time_t t;
- char *error =
- _("FATAL ERROR in recur_item_inday: unknown item type\n");
-
- day_end = day_start + DAYINSEC;
- t = day_start;
- lt_day = *localtime(&t);
-
- for (exc = item_exc; exc != 0; exc = exc->next)
- if (exc->st < day_end && exc->st >= day_start)
- return 0;
-
- if (rpt_until == 0) /* we have an endless recurrent item */
- rpt_until = day_end;
-
- if (item_start > day_end || rpt_until < day_start)
- return 0;
-
- t = item_start;
- lt_item = *localtime(&t);
-
- /* For proper calculation, both items must start at same time. */
- day_start += (lt_item.tm_hour * HOURINSEC + lt_item.tm_min * MININSEC +
- lt_item.tm_sec);
-
- switch (rpt_type) {
- case RECUR_DAILY:
- diff = (long)difftime((time_t)day_start, (time_t)item_start);
- if (diff % (rpt_freq * DAYINSEC) != 0)
- return 0;
- lt_item.tm_mday = lt_day.tm_mday;
- lt_item.tm_mon = lt_day.tm_mon;
- lt_item.tm_year = lt_day.tm_year;
- break;
- case RECUR_WEEKLY:
- if (lt_item.tm_wday != lt_day.tm_wday)
- return 0;
- else {
- diff = ((lt_day.tm_yday - lt_item.tm_yday) / WEEKINDAYS);
- if (diff % rpt_freq != 0)
- return 0;
- }
- lt_item.tm_mday = lt_day.tm_mday;
- lt_item.tm_mon = lt_day.tm_mon;
- lt_item.tm_year = lt_day.tm_year;
- break;
- case RECUR_MONTHLY:
- diff = ((lt_day.tm_year - lt_item.tm_year) * 12) +
- (lt_day.tm_mon - lt_item.tm_mon);
- if (diff % rpt_freq != 0)
- return 0;
- lt_item.tm_mon = lt_day.tm_mon;
- lt_item.tm_year = lt_day.tm_year;
- break;
- case RECUR_YEARLY:
- diff = lt_day.tm_year - lt_item.tm_year;
- if (diff % rpt_freq != 0)
- return 0;
- lt_item.tm_year = lt_day.tm_year;
- break;
- default:
- fputs(error, stderr);
- exit(EXIT_FAILURE);
+ date_t start_date;
+ long day_end, diff;
+ struct tm lt_item, lt_day;
+ struct days_s *exc;
+ time_t t;
+ char *error = _("FATAL ERROR in recur_item_inday: unknown item type\n");
+
+ day_end = day_start + DAYINSEC;
+ t = day_start;
+ lt_day = *localtime (&t);
+
+ for (exc = item_exc; exc != 0; exc = exc->next)
+ if (exc->st < day_end && exc->st >= day_start)
+ return (0);
+
+ if (rpt_until == 0) /* we have an endless recurrent item */
+ rpt_until = day_end;
+
+ if (item_start > day_end || rpt_until < day_start)
+ return (0);
+
+ t = item_start;
+ lt_item = *localtime (&t);
+
+ /* For proper calculation, both items must start at same time. */
+ day_start += (lt_item.tm_hour * HOURINSEC + lt_item.tm_min * MININSEC +
+ lt_item.tm_sec);
+
+ switch (rpt_type)
+ {
+ case RECUR_DAILY:
+ diff = (long) difftime ((time_t) day_start, (time_t) item_start);
+ if (diff % (rpt_freq * DAYINSEC) != 0)
+ return (0);
+ lt_item.tm_mday = lt_day.tm_mday;
+ lt_item.tm_mon = lt_day.tm_mon;
+ lt_item.tm_year = lt_day.tm_year;
+ break;
+ case RECUR_WEEKLY:
+ if (lt_item.tm_wday != lt_day.tm_wday)
+ return (0);
+ else
+ {
+ diff = ((lt_day.tm_yday - lt_item.tm_yday) / WEEKINDAYS);
+ if (diff % rpt_freq != 0)
+ return (0);
}
- start_date.dd = lt_item.tm_mday;
- start_date.mm = lt_item.tm_mon + 1;
- start_date.yyyy = lt_item.tm_year + 1900;
- item_start = date2sec(start_date, lt_item.tm_hour, lt_item.tm_min);
-
- if (item_start < day_end && item_start >= day_start)
- return item_start;
- else
- return 0;
+ lt_item.tm_mday = lt_day.tm_mday;
+ lt_item.tm_mon = lt_day.tm_mon;
+ lt_item.tm_year = lt_day.tm_year;
+ break;
+ case RECUR_MONTHLY:
+ diff = (((lt_day.tm_year - lt_item.tm_year) * 12)
+ + (lt_day.tm_mon - lt_item.tm_mon));
+ if (diff % rpt_freq != 0)
+ return (0);
+ lt_item.tm_mon = lt_day.tm_mon;
+ lt_item.tm_year = lt_day.tm_year;
+ break;
+ case RECUR_YEARLY:
+ diff = lt_day.tm_year - lt_item.tm_year;
+ if (diff % rpt_freq != 0)
+ return (0);
+ lt_item.tm_year = lt_day.tm_year;
+ break;
+ default:
+ fputs (error, stderr);
+ exit (EXIT_FAILURE);
+ }
+ start_date.dd = lt_item.tm_mday;
+ start_date.mm = lt_item.tm_mon + 1;
+ start_date.yyyy = lt_item.tm_year + 1900;
+ item_start = date2sec (start_date, lt_item.tm_hour, lt_item.tm_min);
+
+ if (item_start < day_end && item_start >= day_start)
+ return (item_start);
+ else
+ return (0);
}
/*
* Delete a recurrent event from the list (if delete_whole is not null),
* or delete only one occurence of the recurrent event.
*/
-void
-recur_event_erase(long start, unsigned num, unsigned delete_whole,
- erase_flag_e flag)
+void
+recur_event_erase (long start, unsigned num, unsigned delete_whole,
+ erase_flag_e flag)
{
- unsigned n = 0;
- struct recur_event_s *i, **iptr;
- struct days_s *o, **j;
-
- iptr = &recur_elist;
- for (i = recur_elist; i != 0; i = i->next) {
- if (recur_item_inday(i->day, i->exc, i->rpt->type,
- i->rpt->freq, i->rpt->until, start)) {
- if (n == num) {
- if (delete_whole) {
- if (flag == ERASE_FORCE_ONLY_NOTE)
- erase_note(&i->note, flag);
- else {
- *iptr = i->next;
- free(i->mesg);
- free(i->rpt);
- free(i->exc);
- erase_note(&i->note, flag);
- free(i);
- }
- return;
- } else {
- o = (struct days_s *)
- malloc(sizeof(struct days_s));
- o->st = start;
- j = &i->exc;
- for (;;) {
- if(*j==0 || (*j)->st > start) {
- o->next = *j;
- *j = o;
- break;
- }
- j = &(*j)->next;
- }
- return;
- }
- }
- n++;
- }
- iptr = &i->next;
- }
- /* NOTREACHED */
- fputs(_("FATAL ERROR in recur_event_erase: no such event\n"),
- stderr);
- exit(EXIT_FAILURE);
+ unsigned n = 0;
+ struct recur_event_s *i, **iptr;
+ struct days_s *o, **j;
+
+ iptr = &recur_elist;
+ for (i = recur_elist; i != 0; i = i->next)
+ {
+ if (recur_item_inday (i->day, i->exc, i->rpt->type,
+ i->rpt->freq, i->rpt->until, start))
+ {
+ if (n == num)
+ {
+ if (delete_whole)
+ {
+ if (flag == ERASE_FORCE_ONLY_NOTE)
+ erase_note (&i->note, flag);
+ else
+ {
+ *iptr = i->next;
+ free (i->mesg);
+ free (i->rpt);
+ free (i->exc);
+ erase_note (&i->note, flag);
+ free (i);
+ }
+ return;
+ }
+ else
+ {
+ o = (struct days_s *) malloc (sizeof (struct days_s));
+ o->st = start;
+ j = &i->exc;
+ for (;;)
+ {
+ if (*j == 0 || (*j)->st > start)
+ {
+ o->next = *j;
+ *j = o;
+ break;
+ }
+ j = &(*j)->next;
+ }
+ return;
+ }
+ }
+ n++;
+ }
+ iptr = &i->next;
+ }
+ /* NOTREACHED */
+ fputs (_("FATAL ERROR in recur_event_erase: no such event\n"), stderr);
+ exit (EXIT_FAILURE);
}
/*
* Delete a recurrent appointment from the list (if delete_whole is not null),
* or delete only one occurence of the recurrent appointment.
*/
-void
-recur_apoint_erase(long start, unsigned num, unsigned delete_whole,
- erase_flag_e flag)
+void
+recur_apoint_erase (long start, unsigned num, unsigned delete_whole,
+ erase_flag_e flag)
{
- unsigned n = 0;
- recur_apoint_llist_node_t *i, **iptr;
- struct days_s *o, **j;
- int need_check_notify = 0;
-
- pthread_mutex_lock(&(recur_alist_p->mutex));
- iptr = &recur_alist_p->root;
- for (i = recur_alist_p->root; i != 0; i = i->next) {
- if (recur_item_inday(i->start, i->exc, i->rpt->type,
- i->rpt->freq, i->rpt->until, start)) {
- if (n == num) {
- if (notify_bar() &&
- flag != ERASE_FORCE_ONLY_NOTE)
- need_check_notify =
- notify_same_recur_item(i);
- if (delete_whole) {
- if (flag == ERASE_FORCE_ONLY_NOTE)
- erase_note(&i->note, flag);
- else {
- *iptr = i->next;
- free(i->mesg);
- free(i->rpt);
- free(i->exc);
- erase_note(&i->note, flag);
- free(i);
- pthread_mutex_unlock(
- &(recur_alist_p->mutex));
- if (need_check_notify)
- notify_check_next_app();
- }
- return;
- } else {
- o = (struct days_s *)
- malloc(sizeof(struct days_s));
- o->st = start;
- j = &i->exc;
- for (;;) {
- if(*j==0 || (*j)->st > start) {
- o->next = *j;
- *j = o;
- break;
- }
- j = &(*j)->next;
- }
- pthread_mutex_unlock(
- &(recur_alist_p->mutex));
- if (need_check_notify)
- notify_check_next_app();
- return;
- }
+ unsigned n = 0;
+ recur_apoint_llist_node_t *i, **iptr;
+ struct days_s *o, **j;
+ int need_check_notify = 0;
+
+ pthread_mutex_lock (&(recur_alist_p->mutex));
+ iptr = &recur_alist_p->root;
+ for (i = recur_alist_p->root; i != 0; i = i->next)
+ {
+ if (recur_item_inday (i->start, i->exc, i->rpt->type,
+ i->rpt->freq, i->rpt->until, start))
+ {
+ if (n == num)
+ {
+ if (notify_bar () && flag != ERASE_FORCE_ONLY_NOTE)
+ need_check_notify = notify_same_recur_item (i);
+ if (delete_whole)
+ {
+ if (flag == ERASE_FORCE_ONLY_NOTE)
+ erase_note (&i->note, flag);
+ else
+ {
+ *iptr = i->next;
+ free (i->mesg);
+ free (i->rpt);
+ free (i->exc);
+ erase_note (&i->note, flag);
+ free (i);
+ pthread_mutex_unlock (&(recur_alist_p->mutex));
+ if (need_check_notify)
+ notify_check_next_app ();
+ }
+ return;
+ }
+ else
+ {
+ o = (struct days_s *) malloc (sizeof (struct days_s));
+ o->st = start;
+ j = &i->exc;
+ for (;;)
+ {
+ if (*j == 0 || (*j)->st > start)
+ {
+ o->next = *j;
+ *j = o;
+ break;
}
- n++;
- }
- iptr = &i->next;
- }
- /* NOTREACHED */
- fputs(_("FATAL ERROR in recur_apoint_erase: no such appointment\n"),
- stderr);
- exit(EXIT_FAILURE);
+ j = &(*j)->next;
+ }
+ pthread_mutex_unlock (&(recur_alist_p->mutex));
+ if (need_check_notify)
+ notify_check_next_app ();
+ return;
+ }
+ }
+ n++;
+ }
+ iptr = &i->next;
+ }
+ /* NOTREACHED */
+ fputs (_("FATAL ERROR in recur_apoint_erase: no such appointment\n"),
+ stderr);
+ exit (EXIT_FAILURE);
}
/*
@@ -600,165 +635,187 @@ recur_apoint_erase(long start, unsigned num, unsigned delete_whole,
* o repetition end date
* and then delete the selected item to recreate it as a recurrent one
*/
-void
-recur_repeat_item(conf_t *conf)
+void
+recur_repeat_item (conf_t *conf)
{
- struct tm *lt;
- time_t t;
- int ch = 0;
- int date_entered = 0;
- int year = 0, month = 0, day = 0;
- date_t until_date;
- char outstr[BUFSIZ];
- char user_input[BUFSIZ] = "";
- char *mesg_type_1 =
- _("Enter the repetition type: (D)aily, (W)eekly, (M)onthly, (Y)early");
- char *mesg_type_2 = _("[D/W/M/Y] ");
- char *mesg_freq_1 =
- _("Enter the repetition frequence:");
- char *mesg_wrong_freq =
- _("The frequence you entered is not valid.");
- char *mesg_until_1 =
- _("Enter the ending date: [%s] or '0' for an endless repetition");
- char *mesg_wrong_1 = _("The entered date is not valid.");
- char *mesg_wrong_2 =
- _("Possible formats are [%s] or '0' for an endless repetetition");
- char *wrong_type_1 = _("This item is already a repeated one.");
- char *wrong_type_2 = _("Press [ENTER] to continue.");
- char *mesg_older =
- _("Sorry, the date you entered is older than the item start time.");
- int type = 0, freq = 0;
- int item_nb;
- struct day_item_s *p;
- recur_apoint_llist_node_t *ra;
- struct recur_event_s *re;
- long until, date;
-
- item_nb = apoint_hilt();
- p = day_get_item(item_nb);
- if (p->type != APPT && p->type != EVNT) {
- status_mesg(wrong_type_1, wrong_type_2);
- ch = wgetch(win[STA].p);
- return;
- }
-
- while ( (ch != 'D') && (ch != 'W') && (ch != 'M')
- && (ch != 'Y') && (ch != ESCAPE) ) {
- status_mesg(mesg_type_1, mesg_type_2);
- ch = wgetch(win[STA].p);
- ch = toupper(ch);
- }
- if (ch == ESCAPE) {
- return;
- } else {
- type = recur_char2def(ch);
- ch = 0;
- }
-
- while (freq == 0) {
- status_mesg(mesg_freq_1, "");
- if (getstring(win[STA].p, user_input, BUFSIZ, 0, 1) ==
- GETSTRING_VALID) {
- freq = atoi(user_input);
- if (freq == 0) {
- status_mesg(mesg_wrong_freq, wrong_type_2);
- wgetch(win[STA].p);
- }
- user_input[0] = '\0';
- } else
- return;
+ struct tm *lt;
+ time_t t;
+ int ch = 0;
+ int date_entered = 0;
+ int year = 0, month = 0, day = 0;
+ date_t until_date;
+ char outstr[BUFSIZ];
+ char user_input[BUFSIZ] = "";
+ char *mesg_type_1 =
+ _("Enter the repetition type: (D)aily, (W)eekly, (M)onthly, (Y)early");
+ char *mesg_type_2 = _("[D/W/M/Y] ");
+ char *mesg_freq_1 = _("Enter the repetition frequence:");
+ char *mesg_wrong_freq = _("The frequence you entered is not valid.");
+ char *mesg_until_1 =
+ _("Enter the ending date: [%s] or '0' for an endless repetition");
+ char *mesg_wrong_1 = _("The entered date is not valid.");
+ char *mesg_wrong_2 =
+ _("Possible formats are [%s] or '0' for an endless repetetition");
+ char *wrong_type_1 = _("This item is already a repeated one.");
+ char *wrong_type_2 = _("Press [ENTER] to continue.");
+ char *mesg_older =
+ _("Sorry, the date you entered is older than the item start time.");
+ int type = 0, freq = 0;
+ int item_nb;
+ struct day_item_s *p;
+ recur_apoint_llist_node_t *ra;
+ struct recur_event_s *re;
+ long until, date;
+
+ item_nb = apoint_hilt ();
+ p = day_get_item (item_nb);
+ if (p->type != APPT && p->type != EVNT)
+ {
+ status_mesg (wrong_type_1, wrong_type_2);
+ ch = wgetch (win[STA].p);
+ return;
+ }
+
+ while ((ch != 'D') && (ch != 'W') && (ch != 'M')
+ && (ch != 'Y') && (ch != ESCAPE))
+ {
+ status_mesg (mesg_type_1, mesg_type_2);
+ ch = wgetch (win[STA].p);
+ ch = toupper (ch);
+ }
+ if (ch == ESCAPE)
+ {
+ return;
+ }
+ else
+ {
+ type = recur_char2def (ch);
+ ch = 0;
+ }
+
+ while (freq == 0)
+ {
+ status_mesg (mesg_freq_1, "");
+ if (getstring (win[STA].p, user_input, BUFSIZ, 0, 1) == GETSTRING_VALID)
+ {
+ freq = atoi (user_input);
+ if (freq == 0)
+ {
+ status_mesg (mesg_wrong_freq, wrong_type_2);
+ wgetch (win[STA].p);
+ }
+ user_input[0] = '\0';
}
-
- while (!date_entered) {
- snprintf(outstr, BUFSIZ, mesg_until_1,
- DATEFMT_DESC(conf->input_datefmt));
- status_mesg(_(outstr), "");
- if (getstring(win[STA].p, user_input, BUFSIZ, 0, 1) ==
- GETSTRING_VALID) {
- if (strlen(user_input) == 1 &&
- strncmp(user_input, "0", 1) == 0 ) {
- until = 0;
- date_entered = 1;
- } else {
- if (parse_date(user_input, conf->input_datefmt,
- &year, &month, &day)) {
- t = p->start; lt = localtime(&t);
- until_date.dd = day;
- until_date.mm = month;
- until_date.yyyy = year;
- until = date2sec(until_date,
- lt->tm_hour, lt->tm_min);
- if (until < p->start) {
- status_mesg(mesg_older,
- wrong_type_2);
- wgetch(win[STA].p);
- date_entered = 0;
- } else {
- date_entered = 1;
- }
- } else {
- snprintf(outstr, BUFSIZ, mesg_wrong_2,
- DATEFMT_DESC(conf->input_datefmt));
- status_mesg(mesg_wrong_1, _(outstr));
- wgetch(win[STA].p);
- date_entered = 0;
- }
- }
- } else
- return;
- }
-
- date = calendar_get_slctd_day_sec();
- if (p->type == EVNT) {
- re = recur_event_new(p->mesg, p->note, p->start, p->evnt_id,
- type, freq, until, NULL);
- } else if (p->type == APPT) {
- ra = recur_apoint_new(p->mesg, p->note, p->start, p->appt_dur,
- p->state, type, freq, until, NULL);
- if (notify_bar())
- notify_check_repeated(ra);
- } else { /* NOTREACHED */
- fputs(_("FATAL ERROR in recur_repeat_item: wrong item type\n"),
- stderr);
- exit(EXIT_FAILURE);
+ else
+ return;
+ }
+
+ while (!date_entered)
+ {
+ snprintf (outstr, BUFSIZ, mesg_until_1,
+ DATEFMT_DESC (conf->input_datefmt));
+ status_mesg (_(outstr), "");
+ if (getstring (win[STA].p, user_input, BUFSIZ, 0, 1) == GETSTRING_VALID)
+ {
+ if (strlen (user_input) == 1 && strncmp (user_input, "0", 1) == 0)
+ {
+ until = 0;
+ date_entered = 1;
+ }
+ else
+ {
+ if (parse_date (user_input, conf->input_datefmt,
+ &year, &month, &day))
+ {
+ t = p->start;
+ lt = localtime (&t);
+ until_date.dd = day;
+ until_date.mm = month;
+ until_date.yyyy = year;
+ until = date2sec (until_date, lt->tm_hour, lt->tm_min);
+ if (until < p->start)
+ {
+ status_mesg (mesg_older, wrong_type_2);
+ wgetch (win[STA].p);
+ date_entered = 0;
+ }
+ else
+ {
+ date_entered = 1;
+ }
+ }
+ else
+ {
+ snprintf (outstr, BUFSIZ, mesg_wrong_2,
+ DATEFMT_DESC (conf->input_datefmt));
+ status_mesg (mesg_wrong_1, _(outstr));
+ wgetch (win[STA].p);
+ date_entered = 0;
+ }
+ }
}
- day_erase_item(date, item_nb, ERASE_FORCE_KEEP_NOTE);
-}
+ else
+ return;
+ }
+
+ date = calendar_get_slctd_day_sec ();
+ if (p->type == EVNT)
+ {
+ re = recur_event_new (p->mesg, p->note, p->start, p->evnt_id,
+ type, freq, until, NULL);
+ }
+ else if (p->type == APPT)
+ {
+ ra = recur_apoint_new (p->mesg, p->note, p->start, p->appt_dur,
+ p->state, type, freq, until, NULL);
+ if (notify_bar ())
+ notify_check_repeated (ra);
+ }
+ else
+ { /* NOTREACHED */
+ fputs (_("FATAL ERROR in recur_repeat_item: wrong item type\n"),
+ stderr);
+ exit (EXIT_FAILURE);
+ }
+ day_erase_item (date, item_nb, ERASE_FORCE_KEEP_NOTE);
+}
/*
* Read days for which recurrent items must not be repeated
* (such days are called exceptions).
*/
struct days_s *
-recur_exc_scan(FILE *data_file)
+recur_exc_scan (FILE *data_file)
{
- int c = 0;
- struct tm *lt, day;
- time_t t;
- struct days_s *exc_head, *exc;
-
- exc_head = NULL;
- t = time(NULL);
- lt = localtime(&t);
- day = *lt;
- while ((c = getc(data_file)) == '!') {
- ungetc(c, data_file);
- if (fscanf( data_file, "!%u / %u / %u ",
- &day.tm_mon, &day.tm_mday, &day.tm_year) != 3) {
- fputs(_("FATAL ERROR in recur_exc_scan: "
- "syntax error in the item date\n"), stderr);
- exit(EXIT_FAILURE);
- }
- day.tm_sec = 0;
- day.tm_isdst = -1;
- day.tm_year -= 1900;
- day.tm_mon--;
- exc = (struct days_s *) malloc(sizeof(struct days_s));
- exc->st = mktime(&day);
- exc->next = exc_head;
- exc_head = exc;
+ int c = 0;
+ struct tm *lt, day;
+ time_t t;
+ struct days_s *exc_head, *exc;
+
+ exc_head = NULL;
+ t = time (NULL);
+ lt = localtime (&t);
+ day = *lt;
+ while ((c = getc (data_file)) == '!')
+ {
+ ungetc (c, data_file);
+ if (fscanf (data_file, "!%u / %u / %u ",
+ &day.tm_mon, &day.tm_mday, &day.tm_year) != 3)
+ {
+ fputs (_("FATAL ERROR in recur_exc_scan: "
+ "syntax error in the item date\n"), stderr);
+ exit (EXIT_FAILURE);
}
- return exc_head;
+ day.tm_sec = 0;
+ day.tm_isdst = -1;
+ day.tm_year -= 1900;
+ day.tm_mon--;
+ exc = (struct days_s *) malloc (sizeof (struct days_s));
+ exc->st = mktime (&day);
+ exc->next = exc_head;
+ exc_head = exc;
+ }
+ return (exc_head);
}
/*
@@ -766,107 +823,121 @@ recur_exc_scan(FILE *data_file)
* stored in the notify_app structure (which is the next item to be notified).
*/
struct notify_app_s *
-recur_apoint_check_next(struct notify_app_s *app, long start, long day)
+recur_apoint_check_next (struct notify_app_s *app, long start, long day)
{
- recur_apoint_llist_node_t *i;
- long real_recur_start_time;
-
- pthread_mutex_lock(&(recur_alist_p->mutex));
- for (i = recur_alist_p->root; i != 0; i = i->next) {
- if (i->start > app->time) {
- pthread_mutex_unlock(&(recur_alist_p->mutex));
- return app;
- } else {
- real_recur_start_time = recur_item_inday(
- i->start, i->exc, i->rpt->type, i->rpt->freq,
- i->rpt->until, day);
- if (real_recur_start_time > start) {
- app->time = real_recur_start_time;
- app->txt = mycpy(i->mesg);
- app->state = i->state;
- app->got_app = 1;
- }
- }
+ recur_apoint_llist_node_t *i;
+ long real_recur_start_time;
+
+ pthread_mutex_lock (&(recur_alist_p->mutex));
+ for (i = recur_alist_p->root; i != 0; i = i->next)
+ {
+ if (i->start > app->time)
+ {
+ pthread_mutex_unlock (&(recur_alist_p->mutex));
+ return (app);
+ }
+ else
+ {
+ real_recur_start_time =
+ recur_item_inday (i->start, i->exc, i->rpt->type, i->rpt->freq,
+ i->rpt->until, day);
+ if (real_recur_start_time > start)
+ {
+ app->time = real_recur_start_time;
+ app->txt = mycpy (i->mesg);
+ app->state = i->state;
+ app->got_app = 1;
+ }
}
- pthread_mutex_unlock(&(recur_alist_p->mutex));
+ }
+ pthread_mutex_unlock (&(recur_alist_p->mutex));
- return app;
+ return (app);
}
/* Returns a structure containing the selected recurrent appointment. */
recur_apoint_llist_node_t *
-recur_get_apoint(long date, int num)
+recur_get_apoint (long date, int num)
{
- recur_apoint_llist_node_t *o;
- int n = 0;
-
- pthread_mutex_lock(&(recur_alist_p->mutex));
- for (o = recur_alist_p->root; o != 0; o = o->next) {
- if (recur_item_inday(o->start, o->exc, o->rpt->type,
- o->rpt->freq, o->rpt->until, date)) {
- if (n == num) {
- pthread_mutex_unlock(&(recur_alist_p->mutex));
- return o;
- }
- n++;
- }
+ recur_apoint_llist_node_t *o;
+ int n = 0;
+
+ pthread_mutex_lock (&(recur_alist_p->mutex));
+ for (o = recur_alist_p->root; o != 0; o = o->next)
+ {
+ if (recur_item_inday (o->start, o->exc, o->rpt->type,
+ o->rpt->freq, o->rpt->until, date))
+ {
+ if (n == num)
+ {
+ pthread_mutex_unlock (&(recur_alist_p->mutex));
+ return (o);
+ }
+ n++;
}
- /* NOTREACHED */
- fputs(_("FATAL ERROR in recur_get_apoint: no such item\n"), stderr);
- exit(EXIT_FAILURE);
+ }
+ /* NOTREACHED */
+ fputs (_("FATAL ERROR in recur_get_apoint: no such item\n"), stderr);
+ exit (EXIT_FAILURE);
}
/* Returns a structure containing the selected recurrent event. */
struct recur_event_s *
-recur_get_event(long date, int num)
+recur_get_event (long date, int num)
{
- struct recur_event_s *o;
- int n = 0;
-
- for (o = recur_elist; o != 0; o = o->next) {
- if (recur_item_inday(o->day, o->exc, o->rpt->type,
- o->rpt->freq, o->rpt->until, date)) {
- if (n == num) {
- return o;
- }
- n++;
- }
+ struct recur_event_s *o;
+ int n = 0;
+
+ for (o = recur_elist; o != 0; o = o->next)
+ {
+ if (recur_item_inday (o->day, o->exc, o->rpt->type,
+ o->rpt->freq, o->rpt->until, date))
+ {
+ if (n == num)
+ {
+ return (o);
+ }
+ n++;
}
- /* NOTREACHED */
- fputs(_("FATAL ERROR in recur_get_event: no such item\n"), stderr);
- exit(EXIT_FAILURE);
+ }
+ /* NOTREACHED */
+ fputs (_("FATAL ERROR in recur_get_event: no such item\n"), stderr);
+ exit (EXIT_FAILURE);
}
/* Switch recurrent item notification state. */
void
-recur_apoint_switch_notify(long date, int recur_nb)
+recur_apoint_switch_notify (long date, int recur_nb)
{
- int n, need_chk_notify;
- recur_apoint_llist_node_t *o;
-
- n = 0;
- need_chk_notify = 0;
-
- pthread_mutex_lock(&(recur_alist_p->mutex));
- for (o = recur_alist_p->root; o != 0; o = o->next) {
- if (recur_item_inday(o->start, o->exc, o->rpt->type,
- o->rpt->freq, o->rpt->until, date)) {
- if (n == recur_nb) {
- o->state ^= APOINT_NOTIFY;
-
- if (notify_bar())
- notify_check_repeated(o);
-
- pthread_mutex_unlock(&(recur_alist_p->mutex));
- if (need_chk_notify)
- notify_check_next_app();
- return;
- }
- n++;
- }
+ int n, need_chk_notify;
+ recur_apoint_llist_node_t *o;
+
+ n = 0;
+ need_chk_notify = 0;
+
+ pthread_mutex_lock (&(recur_alist_p->mutex));
+ for (o = recur_alist_p->root; o != 0; o = o->next)
+ {
+ if (recur_item_inday (o->start, o->exc, o->rpt->type,
+ o->rpt->freq, o->rpt->until, date))
+ {
+ if (n == recur_nb)
+ {
+ o->state ^= APOINT_NOTIFY;
+
+ if (notify_bar ())
+ notify_check_repeated (o);
+
+ pthread_mutex_unlock (&(recur_alist_p->mutex));
+ if (need_chk_notify)
+ notify_check_next_app ();
+ return;
+ }
+ n++;
}
- /* NOTREACHED */
- fputs(_("FATAL ERROR in recur_apoint_switch_notify: no such item\n"),
- stderr);
- exit(EXIT_FAILURE);
+ }
+ /* NOTREACHED */
+ fputs (_("FATAL ERROR in recur_apoint_switch_notify: no such item\n"),
+ stderr);
+ exit (EXIT_FAILURE);
}
diff --git a/src/recur.h b/src/recur.h
index 0027652..dd81724 100755
--- a/src/recur.h
+++ b/src/recur.h
@@ -1,4 +1,4 @@
-/* $calcurse: recur.h,v 1.18 2008/04/09 20:38:29 culot Exp $ */
+/* $calcurse: recur.h,v 1.19 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -27,75 +27,85 @@
#ifndef CALCURSE_RECUR_H
#define CALCURSE_RECUR_H
-typedef enum { RECUR_NO,
- RECUR_DAILY,
- RECUR_WEEKLY,
- RECUR_MONTHLY,
- RECUR_YEARLY,
- RECUR_TYPES
-} recur_types_t;
+typedef enum
+{ RECUR_NO,
+ RECUR_DAILY,
+ RECUR_WEEKLY,
+ RECUR_MONTHLY,
+ RECUR_YEARLY,
+ RECUR_TYPES
+}
+recur_types_t;
-struct days_s {
- struct days_s *next;
- long st; /* beggining of the considered day, in seconds */
+struct days_s
+{
+ struct days_s *next;
+ long st; /* beggining of the considered day, in seconds */
};
-struct rpt_s {
- int type; /* repetition type, see RECUR_* defines */
- int freq; /* repetition frequence */
- long until; /* ending date for repeated event */
+struct rpt_s
+{
+ int type; /* repetition type, see RECUR_* defines */
+ int freq; /* repetition frequence */
+ long until; /* ending date for repeated event */
};
-typedef struct recur_apoint_llist_node {
- struct recur_apoint_llist_node *next;
- struct rpt_s *rpt; /* information about repetition */
- struct days_s *exc; /* days when the item should not be repeated */
- long start; /* beggining of the appointment */
- long dur; /* duration of the appointment */
- char state; /* 8 bits to store item state */
- char *mesg; /* appointment description */
- char *note; /* note attached to appointment */
-} recur_apoint_llist_node_t;
+typedef struct recur_apoint_llist_node
+{
+ struct recur_apoint_llist_node *next;
+ struct rpt_s *rpt; /* information about repetition */
+ struct days_s *exc; /* days when the item should not be repeated */
+ long start; /* beggining of the appointment */
+ long dur; /* duration of the appointment */
+ char state; /* 8 bits to store item state */
+ char *mesg; /* appointment description */
+ char *note; /* note attached to appointment */
+}
+recur_apoint_llist_node_t;
-typedef struct recur_apoint_llist {
- recur_apoint_llist_node_t *root;
- pthread_mutex_t mutex;
-} recur_apoint_llist_t;
+typedef struct recur_apoint_llist
+{
+ recur_apoint_llist_node_t *root;
+ pthread_mutex_t mutex;
+}
+recur_apoint_llist_t;
-struct recur_event_s {
- struct recur_event_s *next;
- struct rpt_s *rpt; /* information about repetition */
- struct days_s *exc; /* days when the item should not be repeated */
- int id; /* event type */
- long day; /* day at which event occurs */
- char *mesg; /* event description */
- char *note; /* note attached to event */
+struct recur_event_s
+{
+ struct recur_event_s *next;
+ struct rpt_s *rpt; /* information about repetition */
+ struct days_s *exc; /* days when the item should not be repeated */
+ int id; /* event type */
+ long day; /* day at which event occurs */
+ char *mesg; /* event description */
+ char *note; /* note attached to event */
};
extern recur_apoint_llist_t *recur_alist_p;
extern struct recur_event_s *recur_elist;
-int recur_apoint_llist_init(void);
-char recur_def2char(recur_types_t);
-int recur_char2def(char);
-recur_apoint_llist_node_t *recur_apoint_scan(FILE *, struct tm, struct tm,
- char, int, struct tm, char *,
- struct days_s *, char);
-struct recur_event_s *recur_event_scan(FILE *, struct tm, int, char,
- int, struct tm, char *, struct days_s *);
-void recur_save_data(FILE *);
-unsigned recur_item_inday(long, struct days_s *, int,
- int, long, long);
-void recur_event_erase(long, unsigned, unsigned,
- erase_flag_e);
-void recur_apoint_erase(long, unsigned, unsigned,
- erase_flag_e);
-void recur_repeat_item(conf_t *);
-struct days_s *recur_exc_scan(FILE *);
-struct notify_app_s *recur_apoint_check_next(struct notify_app_s *,
- long, long);
-recur_apoint_llist_node_t *recur_get_apoint(long, int);
-struct recur_event_s *recur_get_event(long, int);
-void recur_apoint_switch_notify(long, int);
+int recur_apoint_llist_init (void);
+char recur_def2char (recur_types_t);
+int recur_char2def (char);
+recur_apoint_llist_node_t *recur_apoint_scan (FILE *, struct tm, struct tm,
+ char, int, struct tm, char *,
+ struct days_s *, char);
+struct recur_event_s *recur_event_scan (FILE *, struct tm, int, char,
+ int, struct tm, char *,
+ struct days_s *);
+void recur_save_data (FILE *);
+unsigned recur_item_inday (long, struct days_s *, int, int,
+ long, long);
+void recur_event_erase (long, unsigned, unsigned,
+ erase_flag_e);
+void recur_apoint_erase (long, unsigned, unsigned,
+ erase_flag_e);
+void recur_repeat_item (conf_t *);
+struct days_s *recur_exc_scan (FILE *);
+struct notify_app_s *recur_apoint_check_next (struct notify_app_s *,
+ long, long);
+recur_apoint_llist_node_t *recur_get_apoint (long, int);
+struct recur_event_s *recur_get_event (long, int);
+void recur_apoint_switch_notify (long, int);
#endif /* CALCURSE_RECUR_H */
diff --git a/src/sigs.c b/src/sigs.c
index 84017d8..00ec30f 100755
--- a/src/sigs.c
+++ b/src/sigs.c
@@ -1,8 +1,8 @@
-/* $calcurse: sigs.c,v 1.5 2008/02/14 20:20:23 culot Exp $ */
+/* $calcurse: sigs.c,v 1.6 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
- * Copyright (c) 2007 Frederic Culot
+ * Copyright (c) 2007-2008 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -40,45 +40,49 @@
* Also catch CTRL-C (SIGINT), and SIGWINCH to resize screen automatically.
*/
static void
-signal_handler(int sig)
+signal_handler (int sig)
{
- switch (sig) {
- case SIGCHLD:
- while (waitpid(WAIT_MYPGRP, NULL, WNOHANG) > 0)
- ;
- break;
- case SIGWINCH:
- clearok(curscr, TRUE);
- ungetch(KEY_RESIZE);
- break;
- }
+ switch (sig)
+ {
+ case SIGCHLD:
+ while (waitpid (WAIT_MYPGRP, NULL, WNOHANG) > 0)
+ ;
+ break;
+ case SIGWINCH:
+ clearok (curscr, TRUE);
+ ungetch (KEY_RESIZE);
+ break;
+ }
}
/* Signal handling init. */
void
-sigs_init(struct sigaction *sa)
+sigs_init (struct sigaction *sa)
{
- sa->sa_handler = signal_handler;
- sa->sa_flags = 0;
- sigemptyset(&sa->sa_mask);
- if (sigaction(SIGCHLD, sa, NULL) != 0) {
- perror("sigaction");
- exit(EXIT_FAILURE);
- }
+ sa->sa_handler = signal_handler;
+ sa->sa_flags = 0;
+ sigemptyset (&sa->sa_mask);
+ if (sigaction (SIGCHLD, sa, NULL) != 0)
+ {
+ perror ("sigaction");
+ exit (EXIT_FAILURE);
+ }
- sa->sa_handler = signal_handler;
- sa->sa_flags = 0;
- sigemptyset(&sa->sa_mask);
- if (sigaction(SIGWINCH, sa, NULL) != 0) {
- perror("sigaction");
- exit(EXIT_FAILURE);
- }
+ sa->sa_handler = signal_handler;
+ sa->sa_flags = 0;
+ sigemptyset (&sa->sa_mask);
+ if (sigaction (SIGWINCH, sa, NULL) != 0)
+ {
+ perror ("sigaction");
+ exit (EXIT_FAILURE);
+ }
- sa->sa_handler = SIG_IGN;
- sa->sa_flags = 0;
- sigemptyset(&(sa->sa_mask));
- if (sigaction(SIGINT, sa, NULL) != 0) {
- perror("sigaction");
- exit(EXIT_FAILURE);
- }
+ sa->sa_handler = SIG_IGN;
+ sa->sa_flags = 0;
+ sigemptyset (&(sa->sa_mask));
+ if (sigaction (SIGINT, sa, NULL) != 0)
+ {
+ perror ("sigaction");
+ exit (EXIT_FAILURE);
+ }
}
diff --git a/src/sigs.h b/src/sigs.h
index 0da1050..6db4cec 100755
--- a/src/sigs.h
+++ b/src/sigs.h
@@ -1,8 +1,8 @@
-/* $calcurse: sigs.h,v 1.2 2008/02/14 20:20:23 culot Exp $ */
+/* $calcurse: sigs.h,v 1.3 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
- * Copyright (c) 2007 Frederic Culot
+ * Copyright (c) 2007-2008 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -27,6 +27,6 @@
#ifndef CALCURSE_SIGS_H
#define CALCURSE_SIGS_H
-void sigs_init(struct sigaction *);
+void sigs_init (struct sigaction *);
#endif /* CALCURSE_SIGS_H */
diff --git a/src/todo.c b/src/todo.c
index 20a6e5a..bf3a43d 100755
--- a/src/todo.c
+++ b/src/todo.c
@@ -1,8 +1,8 @@
-/* $calcurse: todo.c,v 1.20 2008/04/04 21:31:20 culot Exp $ */
+/* $calcurse: todo.c,v 1.21 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
- * Copyright (c) 2004-2007 Frederic Culot
+ * Copyright (c) 2004-2008 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -33,433 +33,458 @@
#include "i18n.h"
#include "todo.h"
-struct todo_s *todolist;
-static int hilt = 0;
-static int todos = 0;
-static int first = 1;
-static char *msgsav;
+struct todo_s *todolist;
+static int hilt = 0;
+static int todos = 0;
+static int first = 1;
+static char *msgsav;
/* Returns a structure containing the selected item. */
static struct todo_s *
-todo_get_item(int item_number)
+todo_get_item (int item_number)
{
- struct todo_s *o;
- int i;
-
- o = todolist;
- for (i = 1; i < item_number; i++) {
- o = o->next;
- }
- return o;
+ struct todo_s *o;
+ int i;
+
+ o = todolist;
+ for (i = 1; i < item_number; i++)
+ {
+ o = o->next;
+ }
+ return (o);
}
/* Sets which todo is highlighted. */
void
-todo_hilt_set(int highlighted)
+todo_hilt_set (int highlighted)
{
- hilt = highlighted;
+ hilt = highlighted;
}
void
-todo_hilt_decrease(void)
+todo_hilt_decrease (void)
{
- hilt--;
+ hilt--;
}
void
-todo_hilt_increase(void)
+todo_hilt_increase (void)
{
- hilt++;
+ hilt++;
}
/* Return which todo is highlighted. */
int
-todo_hilt(void)
+todo_hilt (void)
{
- return (hilt);
+ return (hilt);
}
/* Return the number of todos. */
int
-todo_nb(void)
+todo_nb (void)
{
- return (todos);
+ return (todos);
}
/* Set the number of todos. */
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. */
void
-todo_set_first(int nb)
+todo_set_first (int nb)
{
- first = nb;
+ first = nb;
}
void
-todo_first_increase(void)
+todo_first_increase (void)
{
- first++;
+ first++;
}
void
-todo_first_decrease(void)
+todo_first_decrease (void)
{
- first--;
+ first--;
}
/*
* Return the position of the hilghlighted item, relative to the first one
* displayed.
- */
+ */
int
-todo_hilt_pos(void)
+todo_hilt_pos (void)
{
- return (hilt - first);
+ return (hilt - first);
}
/* Return the last visited todo. */
char *
-todo_saved_mesg(void)
+todo_saved_mesg (void)
{
- return (msgsav);
+ return (msgsav);
}
/* Request user to enter a new todo item. */
-void
-todo_new_item(void)
+void
+todo_new_item (void)
{
- int ch = 0;
- char *mesg = _("Enter the new ToDo item : ");
- char *mesg_id =
- _("Enter the ToDo priority [1 (highest) - 9 (lowest)] :");
- char todo_input[BUFSIZ] = "";
-
- status_mesg(mesg, "");
- if (getstring(win[STA].p, todo_input, BUFSIZ, 0, 1) ==
- GETSTRING_VALID) {
- while ( (ch < '1') || (ch > '9') ) {
- status_mesg(mesg_id, "");
- ch = wgetch(win[STA].p);
- }
- todo_add(todo_input, ch - '0', NULL);
- todos++;
+ int ch = 0;
+ char *mesg = _("Enter the new ToDo item : ");
+ char *mesg_id = _("Enter the ToDo priority [1 (highest) - 9 (lowest)] :");
+ char todo_input[BUFSIZ] = "";
+
+ status_mesg (mesg, "");
+ if (getstring (win[STA].p, todo_input, BUFSIZ, 0, 1) == GETSTRING_VALID)
+ {
+ while ((ch < '1') || (ch > '9'))
+ {
+ status_mesg (mesg_id, "");
+ ch = wgetch (win[STA].p);
}
+ todo_add (todo_input, ch - '0', NULL);
+ todos++;
+ }
}
/* Add an item in the todo linked list. */
struct todo_s *
-todo_add(char *mesg, int id, char *note)
+todo_add (char *mesg, int id, char *note)
{
- struct todo_s *o, **i;
- o = (struct todo_s *) malloc(sizeof(struct todo_s));
- o->mesg = (char *) malloc(strlen(mesg) + 1);
- strncpy(o->mesg, mesg, strlen(mesg) + 1);
- o->id = id;
- o->note = (note != NULL && note[0] != '\0') ? strdup(note) : NULL;
- i = &todolist;
- for (;;) {
- if (*i == 0 || (*i)->id > id) {
- o->next = *i;
- *i = o;
- break;
- }
- i = &(*i)->next;
+ struct todo_s *o, **i;
+ o = (struct todo_s *) malloc (sizeof (struct todo_s));
+ o->mesg = (char *) malloc (strlen (mesg) + 1);
+ strncpy (o->mesg, mesg, strlen (mesg) + 1);
+ o->id = id;
+ o->note = (note != NULL && note[0] != '\0') ? strdup (note) : NULL;
+ i = &todolist;
+ for (;;)
+ {
+ if (*i == 0 || (*i)->id > id)
+ {
+ o->next = *i;
+ *i = o;
+ break;
}
- return o;
+ i = &(*i)->next;
+ }
+ return (o);
}
/* Delete a note previously attached to a todo item. */
-static void
-todo_delete_note_bynum(unsigned num)
+static void
+todo_delete_note_bynum (unsigned num)
{
- unsigned n;
- struct todo_s *i, **iptr;
-
- n = 0;
- iptr = &todolist;
- for (i = todolist; i != 0; i = i->next) {
- if (n == num) {
- if (i->note == NULL)
- ierror(
- _("FATAL ERROR in todo_delete_note_bynum: "
- "no note attached\n"), IERROR_FATAL);
- erase_note(&i->note, ERASE_FORCE_ONLY_NOTE);
- return;
- }
- iptr = &i->next;
- n++;
+ unsigned n;
+ struct todo_s *i, **iptr;
+
+ n = 0;
+ iptr = &todolist;
+ for (i = todolist; i != 0; i = i->next)
+ {
+ if (n == num)
+ {
+ if (i->note == NULL)
+ ierror (_("FATAL ERROR in todo_delete_note_bynum: "
+ "no note attached\n"), IERROR_FATAL);
+ erase_note (&i->note, ERASE_FORCE_ONLY_NOTE);
+ return;
}
- /* NOTREACHED */
- ierror(_("FATAL ERROR in todo_delete_note_bynum: no such todo\n"),
- IERROR_FATAL);
- exit(EXIT_FAILURE);
+ iptr = &i->next;
+ n++;
+ }
+ /* NOTREACHED */
+ ierror (_("FATAL ERROR in todo_delete_note_bynum: no such todo\n"),
+ IERROR_FATAL);
+ exit (EXIT_FAILURE);
}
/* Delete an item from the todo linked list. */
-static void
-todo_delete_bynum(unsigned num, erase_flag_e flag)
+static void
+todo_delete_bynum (unsigned num, erase_flag_e flag)
{
- unsigned n;
- struct todo_s *i, **iptr;
-
- n = 0;
- iptr = &todolist;
- for (i = todolist; i != 0; i = i->next) {
- if (n == num) {
- *iptr = i->next;
- free(i->mesg);
- if (i->note != NULL)
- erase_note(&i->note, flag);
- free(i);
- return;
- }
- iptr = &i->next;
- n++;
+ unsigned n;
+ struct todo_s *i, **iptr;
+
+ n = 0;
+ iptr = &todolist;
+ for (i = todolist; i != 0; i = i->next)
+ {
+ if (n == num)
+ {
+ *iptr = i->next;
+ free (i->mesg);
+ if (i->note != NULL)
+ erase_note (&i->note, flag);
+ free (i);
+ return;
}
- /* NOTREACHED */
- ierror(_("FATAL ERROR in todo_delete_bynum: no such todo\n"),
- IERROR_FATAL);
- exit(EXIT_FAILURE);
+ iptr = &i->next;
+ n++;
+ }
+ /* NOTREACHED */
+ ierror (_("FATAL ERROR in todo_delete_bynum: no such todo\n"),
+ IERROR_FATAL);
+ exit (EXIT_FAILURE);
}
/* Delete an item from the ToDo list. */
-void
-todo_delete(conf_t *conf)
+void
+todo_delete (conf_t *conf)
{
- char *choices = "[y/n] ";
- char *del_todo_str = _("Do you really want to delete this task ?");
- char *erase_warning =
- _("This item has a note attached to it. "
- "Delete (t)odo or just its (n)ote ?");
- char *erase_choice =
- _("[t/n] ");
- bool go_for_todo_del = false;
- int answer = 0, has_note;
-
- if (conf->confirm_delete) {
- status_mesg(del_todo_str, choices);
- answer = wgetch(win[STA].p);
- if ( (answer == 'y') && (todos > 0) ) {
- go_for_todo_del = true;
- } else {
- erase_status_bar();
- return;
- }
- } else
- if (todos > 0)
- go_for_todo_del = true;
-
- if (go_for_todo_del == false) {
- erase_status_bar();
- return;
- }
-
- answer = 0;
- has_note = (todo_get_item(hilt)->note != NULL) ? 1 : 0;
- if (has_note == 0)
- answer = 't';
-
- while (answer != 't' && answer != 'n' && answer != ESCAPE) {
- status_mesg(erase_warning, erase_choice);
- answer = wgetch(win[STA].p);
+ char *choices = "[y/n] ";
+ char *del_todo_str = _("Do you really want to delete this task ?");
+ char *erase_warning =
+ _("This item has a note attached to it. "
+ "Delete (t)odo or just its (n)ote ?");
+ char *erase_choice = _("[t/n] ");
+ bool go_for_todo_del = false;
+ int answer = 0, has_note;
+
+ if (conf->confirm_delete)
+ {
+ status_mesg (del_todo_str, choices);
+ answer = wgetch (win[STA].p);
+ if ((answer == 'y') && (todos > 0))
+ {
+ go_for_todo_del = true;
}
-
- switch (answer) {
- case 't':
- todo_delete_bynum(hilt - 1, ERASE_FORCE);
- todos--;
- if (hilt > 1)
- hilt--;
- if (todos == 0)
- hilt = 0;
- if (hilt - first < 0)
- first--;
- break;
- case 'n':
- todo_delete_note_bynum(hilt - 1);
- break;
- default:
- erase_status_bar();
- return;
+ else
+ {
+ erase_status_bar ();
+ return;
}
+ }
+ else if (todos > 0)
+ go_for_todo_del = true;
+
+ if (go_for_todo_del == false)
+ {
+ erase_status_bar ();
+ return;
+ }
+
+ answer = 0;
+ has_note = (todo_get_item (hilt)->note != NULL) ? 1 : 0;
+ if (has_note == 0)
+ answer = 't';
+
+ while (answer != 't' && answer != 'n' && answer != ESCAPE)
+ {
+ status_mesg (erase_warning, erase_choice);
+ answer = wgetch (win[STA].p);
+ }
+
+ switch (answer)
+ {
+ case 't':
+ todo_delete_bynum (hilt - 1, ERASE_FORCE);
+ todos--;
+ if (hilt > 1)
+ hilt--;
+ if (todos == 0)
+ hilt = 0;
+ if (hilt - first < 0)
+ first--;
+ break;
+ case 'n':
+ todo_delete_note_bynum (hilt - 1);
+ break;
+ default:
+ erase_status_bar ();
+ return;
+ }
}
/*
* Returns the position into the linked list corresponding to the
* given todo_s item.
*/
-static int
-todo_get_position(struct todo_s *i)
+static int
+todo_get_position (struct todo_s *i)
{
- struct todo_s *o;
- int n = 1, found = 0;
-
- for (o = todolist; o; o = o->next) {
- if (o == i) {
- found = 1;
- break;
- }
- n++;
+ struct todo_s *o;
+ int n = 1, found = 0;
+
+ for (o = todolist; o; o = o->next)
+ {
+ if (o == i)
+ {
+ found = 1;
+ break;
}
- if (found) {
- return n;
- } else {
- fputs(_("FATAL ERROR in todo_get_position: todo not found\n"),
- stderr);
- exit(EXIT_FAILURE);
- }
+ n++;
+ }
+ if (found)
+ {
+ return (n);
+ }
+ else
+ {
+ fputs (_("FATAL ERROR in todo_get_position: todo not found\n"), stderr);
+ exit (EXIT_FAILURE);
+ }
}
/* Change an item priority by pressing '+' or '-' inside TODO panel. */
void
-todo_chg_priority(int action)
+todo_chg_priority (int action)
{
- struct todo_s *backup;
- char backup_mesg[BUFSIZ];
- int backup_id;
- char backup_note[NOTESIZ + 1];
- int do_chg = 1;
-
- backup = todo_get_item(hilt);
- strncpy(backup_mesg, backup->mesg, strlen(backup->mesg) + 1);
- backup_id = backup->id;
- if (backup->note)
- strncpy(backup_note, backup->note, NOTESIZ + 1);
- else
- backup_note[0] = '\0';
- if (action == '+') {
- (backup_id > 1) ? backup_id-- : do_chg--;
- } else if (action == '-') {
- (backup_id < 9) ? backup_id++ : do_chg--;
- } else { /* NOTREACHED */
- fputs(_("FATAL ERROR in todo_chg_priority: no such action\n"),
- stderr);
- }
- if (do_chg) {
- todo_delete_bynum(hilt - 1, ERASE_FORCE_KEEP_NOTE);
- backup = todo_add(backup_mesg, backup_id, backup_note);
- hilt = todo_get_position(backup);
- }
+ struct todo_s *backup;
+ char backup_mesg[BUFSIZ];
+ int backup_id;
+ char backup_note[NOTESIZ + 1];
+ int do_chg = 1;
+
+ backup = todo_get_item (hilt);
+ strncpy (backup_mesg, backup->mesg, strlen (backup->mesg) + 1);
+ backup_id = backup->id;
+ if (backup->note)
+ strncpy (backup_note, backup->note, NOTESIZ + 1);
+ else
+ backup_note[0] = '\0';
+ if (action == '+')
+ {
+ (backup_id > 1) ? backup_id-- : do_chg--;
+ }
+ else if (action == '-')
+ {
+ (backup_id < 9) ? backup_id++ : do_chg--;
+ }
+ else
+ { /* NOTREACHED */
+ fputs (_("FATAL ERROR in todo_chg_priority: no such action\n"), stderr);
+ }
+ if (do_chg)
+ {
+ todo_delete_bynum (hilt - 1, ERASE_FORCE_KEEP_NOTE);
+ backup = todo_add (backup_mesg, backup_id, backup_note);
+ hilt = todo_get_position (backup);
+ }
}
/* Edit the description of an already existing todo item. */
-void
-todo_edit_item(void)
+void
+todo_edit_item (void)
{
- struct todo_s *i;
- char *mesg = _("Enter the new ToDo description :");
+ struct todo_s *i;
+ char *mesg = _("Enter the new ToDo description :");
- status_mesg(mesg, "");
- i = todo_get_item(hilt);
- updatestring(win[STA].p, &i->mesg, 0, 1);
+ status_mesg (mesg, "");
+ i = todo_get_item (hilt);
+ updatestring (win[STA].p, &i->mesg, 0, 1);
}
/* Display todo items in the corresponding panel. */
static void
-display_todo_item(int incolor, char *msg, int prio, int note, int len, int y,
- int x)
+display_todo_item (int incolor, char *msg, int prio, int note, int len, int y,
+ int x)
{
- WINDOW *w;
- int ch_note;
- char buf[len];
-
- w = win[TOD].p;
- ch_note = (note) ? '>' : '.';
- if (incolor == 0)
- custom_apply_attr(w, ATTR_HIGHEST);
- if (strlen(msg) < len)
- mvwprintw(w, y, x, "%d%c %s", prio, ch_note, msg);
- else {
- strncpy(buf, msg, len - 1);
- buf[len - 1] = '\0';
- mvwprintw(w, y, x, "%d%c %s...", prio, ch_note, buf);
- }
- if (incolor == 0)
- custom_remove_attr(w, ATTR_HIGHEST);
+ WINDOW *w;
+ int ch_note;
+ char buf[len];
+
+ w = win[TOD].p;
+ ch_note = (note) ? '>' : '.';
+ if (incolor == 0)
+ custom_apply_attr (w, ATTR_HIGHEST);
+ if (strlen (msg) < len)
+ mvwprintw (w, y, x, "%d%c %s", prio, ch_note, msg);
+ else
+ {
+ strncpy (buf, msg, len - 1);
+ buf[len - 1] = '\0';
+ mvwprintw (w, y, x, "%d%c %s...", prio, ch_note, buf);
+ }
+ if (incolor == 0)
+ custom_remove_attr (w, ATTR_HIGHEST);
}
/* Updates the ToDo panel. */
-void
-todo_update_panel(window_t *wintod, int which_pan)
+void
+todo_update_panel (window_t *wintod, int which_pan)
{
- struct todo_s *i;
- int len = wintod->w - 8;
- int num_todo = 0;
- int y_offset = 3, x_offset = 1;
- int t_realpos = -1;
- int title_lines = 3;
- int todo_lines = 1;
- int max_items = wintod->h - 4;
- int incolor = -1;
-
- /* Print todo item in the panel. */
- erase_window_part(win[TOD].p, 1, title_lines, wintod->w - 2,
- wintod->h - 2);
- for (i = todolist; i != 0; i = i->next) {
- num_todo++;
- t_realpos = num_todo - first;
- incolor = num_todo - hilt;
- if (incolor == 0)
- msgsav = i->mesg;
- if (t_realpos >= 0 && t_realpos < max_items) {
- display_todo_item(incolor, i->mesg, i->id,
- (i->note != NULL) ? 1 : 0, len, y_offset, x_offset);
- y_offset = y_offset + todo_lines;
- }
+ struct todo_s *i;
+ int len = wintod->w - 8;
+ int num_todo = 0;
+ int y_offset = 3, x_offset = 1;
+ int t_realpos = -1;
+ int title_lines = 3;
+ int todo_lines = 1;
+ int max_items = wintod->h - 4;
+ int incolor = -1;
+
+ /* Print todo item in the panel. */
+ erase_window_part (win[TOD].p, 1, title_lines, wintod->w - 2, wintod->h - 2);
+ for (i = todolist; i != 0; i = i->next)
+ {
+ num_todo++;
+ t_realpos = num_todo - first;
+ incolor = num_todo - hilt;
+ if (incolor == 0)
+ msgsav = i->mesg;
+ if (t_realpos >= 0 && t_realpos < max_items)
+ {
+ display_todo_item (incolor, i->mesg, i->id,
+ (i->note != NULL) ? 1 : 0, len, y_offset,
+ x_offset);
+ y_offset = y_offset + todo_lines;
}
-
- /* Draw the scrollbar if necessary. */
- if (todos > max_items){
- float ratio = ((float) max_items) / ((float) todos);
- int sbar_length = (int) (ratio * (max_items + 1));
- int highend = (int) (ratio * first);
- bool hilt_bar = (which_pan == TOD) ? true : false;
- int sbar_top = highend + title_lines;
-
- if ((sbar_top + sbar_length) > wintod->h - 1)
- sbar_length = wintod->h - 1 - sbar_top;
- draw_scrollbar(win[TOD].p, sbar_top, wintod->w - 2,
- sbar_length, title_lines, wintod->h - 1, hilt_bar);
- }
-
- wnoutrefresh(win[TOD].p);
+ }
+
+ /* Draw the scrollbar if necessary. */
+ if (todos > max_items)
+ {
+ float ratio = ((float) max_items) / ((float) todos);
+ int sbar_length = (int) (ratio * (max_items + 1));
+ int highend = (int) (ratio * first);
+ bool hilt_bar = (which_pan == TOD) ? true : false;
+ int sbar_top = highend + title_lines;
+
+ if ((sbar_top + sbar_length) > wintod->h - 1)
+ sbar_length = wintod->h - 1 - sbar_top;
+ draw_scrollbar (win[TOD].p, sbar_top, wintod->w - 2,
+ sbar_length, title_lines, wintod->h - 1, hilt_bar);
+ }
+
+ wnoutrefresh (win[TOD].p);
}
/* Attach a note to a todo */
-void
-todo_edit_note(char *editor)
+void
+todo_edit_note (char *editor)
{
- struct todo_s *i;
- char fullname[BUFSIZ];
- char *filename;
-
- i = todo_get_item(hilt);
- if (i->note == NULL) {
- if ((filename = new_tempfile(path_notes, NOTESIZ))
- != NULL)
- i->note = filename;
- else
- return;
- }
- snprintf(fullname, BUFSIZ, "%s%s", path_notes, i->note);
- wins_launch_external(fullname, editor);
+ struct todo_s *i;
+ char fullname[BUFSIZ];
+ char *filename;
+
+ i = todo_get_item (hilt);
+ if (i->note == NULL)
+ {
+ if ((filename = new_tempfile (path_notes, NOTESIZ)) != NULL)
+ i->note = filename;
+ else
+ return;
+ }
+ snprintf (fullname, BUFSIZ, "%s%s", path_notes, i->note);
+ wins_launch_external (fullname, editor);
}
/* View a note previously attached to a todo */
-void
-todo_view_note(char *pager)
+void
+todo_view_note (char *pager)
{
- struct todo_s *i;
- char fullname[BUFSIZ];
-
- i = todo_get_item(hilt);
- if (i->note == NULL)
- return;
- snprintf(fullname, BUFSIZ, "%s%s", path_notes, i->note);
- wins_launch_external(fullname, pager);
+ struct todo_s *i;
+ char fullname[BUFSIZ];
+
+ i = todo_get_item (hilt);
+ if (i->note == NULL)
+ return;
+ snprintf (fullname, BUFSIZ, "%s%s", path_notes, i->note);
+ wins_launch_external (fullname, pager);
}
diff --git a/src/todo.h b/src/todo.h
index 2620ef7..e3e0f8e 100755
--- a/src/todo.h
+++ b/src/todo.h
@@ -1,8 +1,8 @@
-/* $calcurse: todo.h,v 1.10 2007/12/30 16:27:59 culot Exp $ */
+/* $calcurse: todo.h,v 1.11 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
- * Copyright (c) 2004-2007 Frederic Culot
+ * Copyright (c) 2004-2008 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -29,33 +29,34 @@
#include "wins.h"
-struct todo_s {
- struct todo_s *next;
- char *mesg;
- int id;
- char *note;
+struct todo_s
+{
+ struct todo_s *next;
+ char *mesg;
+ int id;
+ char *note;
};
extern struct todo_s *todolist;
-void todo_hilt_set(int);
-void todo_hilt_decrease(void);
-void todo_hilt_increase(void);
-int todo_hilt(void);
-int todo_nb(void);
-void todo_set_nb(int);
-void todo_set_first(int);
-void todo_first_increase(void);
-void todo_first_decrease(void);
-int todo_hilt_pos(void);
-char *todo_saved_mesg(void);
-void todo_new_item(void);
-struct todo_s *todo_add(char *, int, char *);
-void todo_delete(conf_t *);
-void todo_chg_priority(int);
-void todo_edit_item(void);
-void todo_update_panel(window_t *, int);
-void todo_edit_note(char *);
-void todo_view_note(char *);
+void todo_hilt_set (int);
+void todo_hilt_decrease (void);
+void todo_hilt_increase (void);
+int todo_hilt (void);
+int todo_nb (void);
+void todo_set_nb (int);
+void todo_set_first (int);
+void todo_first_increase (void);
+void todo_first_decrease (void);
+int todo_hilt_pos (void);
+char *todo_saved_mesg (void);
+void todo_new_item (void);
+struct todo_s *todo_add (char *, int, char *);
+void todo_delete (conf_t *);
+void todo_chg_priority (int);
+void todo_edit_item (void);
+void todo_update_panel (window_t *, int);
+void todo_edit_note (char *);
+void todo_view_note (char *);
#endif /* CALCURSE_TODO_H */
diff --git a/src/utils.c b/src/utils.c
index f7f0717..7f89f90 100755
--- a/src/utils.c
+++ b/src/utils.c
@@ -1,4 +1,4 @@
-/* $calcurse: utils.c,v 1.44 2008/04/09 20:38:29 culot Exp $ */
+/* $calcurse: utils.c,v 1.45 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -24,7 +24,7 @@
*
*/
-#include <time.h>
+#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
@@ -42,139 +42,142 @@
static unsigned status_page;
/* General routine to exit calcurse properly. */
-void
-exit_calcurse(int status)
+void
+exit_calcurse (int status)
{
- clear();
- refresh();
- endwin();
- calendar_stop_date_thread();
- exit(status);
+ clear ();
+ refresh ();
+ endwin ();
+ calendar_stop_date_thread ();
+ exit (status);
}
/* Function to exit on internal error. */
void
-ierror(const char *errmsg, ierror_sev_e sev)
-{
- WINDOW *errwin;
- char *label = _("INTERNAL ERROR");
- char *exitmsg = _("calcurse will now exit...");
- char *reportmsg = _("Please report the following bug:");
- const int winrow = 10;
- const int wincol = col - 2;
- const int msglen = wincol - 2;
- char msg[msglen];
-
- strncpy(msg, errmsg, msglen);
- errwin = newwin(winrow, wincol, (row - winrow) / 2, (col - wincol) / 2);
- custom_apply_attr(errwin, ATTR_HIGHEST);
- box(errwin, 0, 0);
- wins_show(errwin, label);
- if (sev == IERROR_FATAL)
- mvwprintw(errwin, 3, 1, reportmsg);
- mvwprintw(errwin, 5, (wincol - strlen(msg)) / 2, "%s", msg);
- if (sev == IERROR_FATAL)
- mvwprintw(errwin, winrow - 2, wincol - strlen(exitmsg) - 1, "%s",
- exitmsg);
- custom_remove_attr(errwin, ATTR_HIGHEST);
- wrefresh(errwin);
- wgetch(errwin);
- if (sev == IERROR_FATAL)
- exit_calcurse(EXIT_FAILURE);
+ierror (const char *errmsg, ierror_sev_e sev)
+{
+ WINDOW *errwin;
+ char *label = _("INTERNAL ERROR");
+ char *exitmsg = _("calcurse will now exit...");
+ char *reportmsg = _("Please report the following bug:");
+ const int winrow = 10;
+ const int wincol = col - 2;
+ const int msglen = wincol - 2;
+ char msg[msglen];
+
+ strncpy (msg, errmsg, msglen);
+ errwin = newwin (winrow, wincol, (row - winrow) / 2, (col - wincol) / 2);
+ custom_apply_attr (errwin, ATTR_HIGHEST);
+ box (errwin, 0, 0);
+ wins_show (errwin, label);
+ if (sev == IERROR_FATAL)
+ mvwprintw (errwin, 3, 1, reportmsg);
+ mvwprintw (errwin, 5, (wincol - strlen (msg)) / 2, "%s", msg);
+ if (sev == IERROR_FATAL)
+ mvwprintw (errwin, winrow - 2, wincol - strlen (exitmsg) - 1, "%s",
+ exitmsg);
+ custom_remove_attr (errwin, ATTR_HIGHEST);
+ wrefresh (errwin);
+ wgetch (errwin);
+ if (sev == IERROR_FATAL)
+ exit_calcurse (EXIT_FAILURE);
}
/* Function to handle an assertion failure. */
void
-aerror(const char *file, int line, const char *assertion)
+aerror (const char *file, int line, const char *assertion)
{
- char errmsg[BUFSIZ];
+ char errmsg[BUFSIZ];
- snprintf(errmsg, BUFSIZ,
- "assert \"%s\" failed: file \"%s\", line %d", assertion, file, line);
- ierror(errmsg, IERROR_FATAL);
+ snprintf (errmsg, BUFSIZ,
+ "assert \"%s\" failed: file \"%s\", line %d", assertion, file,
+ line);
+ ierror (errmsg, IERROR_FATAL);
}
/*
* Print a message in the status bar.
* Message texts for first line and second line are to be provided.
*/
-void
-status_mesg(char *mesg_line1, char *mesg_line2)
+void
+status_mesg (char *mesg_line1, char *mesg_line2)
{
- erase_status_bar();
- custom_apply_attr(win[STA].p, ATTR_HIGHEST);
- mvwprintw(win[STA].p, 0, 0, mesg_line1);
- mvwprintw(win[STA].p, 1, 0, mesg_line2);
- custom_remove_attr(win[STA].p, ATTR_HIGHEST);
+ erase_status_bar ();
+ custom_apply_attr (win[STA].p, ATTR_HIGHEST);
+ mvwprintw (win[STA].p, 0, 0, mesg_line1);
+ mvwprintw (win[STA].p, 1, 0, mesg_line2);
+ custom_remove_attr (win[STA].p, ATTR_HIGHEST);
}
/* Erase status bar. */
void
-erase_status_bar(void)
+erase_status_bar (void)
{
- erase_window_part(win[STA].p, 0, 0, col, STATUSHEIGHT);
+ erase_window_part (win[STA].p, 0, 0, col, STATUSHEIGHT);
}
/* Erase part of a window. */
-void
-erase_window_part(WINDOW *win, int first_col, int first_row, int last_col,
- int last_row)
+void
+erase_window_part (WINDOW *win, int first_col, int first_row, int last_col,
+ int last_row)
{
- int c, r;
+ int c, r;
- for (r = first_row; r <= last_row; r++){
- for (c = first_col; c <= last_col; c++){
- mvwprintw(win, r, c, " ");
- }
+ for (r = first_row; r <= last_row; r++)
+ {
+ for (c = first_col; c <= last_col; c++)
+ {
+ mvwprintw (win, r, c, " ");
}
- wnoutrefresh(win);
+ }
+ wnoutrefresh (win);
}
/* draws a popup window */
-WINDOW * popup(int pop_row, int pop_col,
- int pop_y, int pop_x, char *pop_lab)
-{
- char *txt_pop = _("Press any key to continue...");
- char label[BUFSIZ];
- WINDOW *popup_win;
-
- popup_win = newwin(pop_row, pop_col, pop_y, pop_x);
- keypad(popup_win, TRUE);
- custom_apply_attr(popup_win, ATTR_HIGHEST);
- box(popup_win, 0, 0);
- snprintf(label, BUFSIZ, "%s", pop_lab);
- wins_show(popup_win, label);
- mvwprintw(popup_win, pop_row - 2, pop_col - (strlen(txt_pop) + 1), "%s",
- txt_pop);
- custom_remove_attr(popup_win, ATTR_HIGHEST);
- wnoutrefresh(popup_win);
- doupdate();
- return popup_win;
+WINDOW *
+popup (int pop_row, int pop_col, int pop_y, int pop_x, char *pop_lab)
+{
+ char *txt_pop = _("Press any key to continue...");
+ char label[BUFSIZ];
+ WINDOW *popup_win;
+
+ popup_win = newwin (pop_row, pop_col, pop_y, pop_x);
+ keypad (popup_win, TRUE);
+ custom_apply_attr (popup_win, ATTR_HIGHEST);
+ box (popup_win, 0, 0);
+ snprintf (label, BUFSIZ, "%s", pop_lab);
+ wins_show (popup_win, label);
+ mvwprintw (popup_win, pop_row - 2, pop_col - (strlen (txt_pop) + 1), "%s",
+ txt_pop);
+ custom_remove_attr (popup_win, ATTR_HIGHEST);
+ wnoutrefresh (popup_win);
+ doupdate ();
+ return (popup_win);
}
/* prints in middle of a panel */
void
-print_in_middle(WINDOW *win, int starty, int startx, int width, char *string)
+print_in_middle (WINDOW *win, int starty, int startx, int width, char *string)
{
- int length, x, y;
- float temp;
+ int length, x, y;
+ float temp;
- if (win == NULL)
- win = stdscr;
- getyx(win, y, x);
- if (startx != 0)
- x = startx;
- if (starty != 0)
- y = starty;
- if (width == 0)
- width = 80;
+ if (win == NULL)
+ win = stdscr;
+ getyx (win, y, x);
+ if (startx != 0)
+ x = startx;
+ if (starty != 0)
+ y = starty;
+ if (width == 0)
+ width = 80;
- length = strlen(string);
- temp = (width - length) / 2;
- x = startx + (int) temp;
- custom_apply_attr(win, ATTR_HIGHEST);
- mvwprintw(win, y, x, "%s", string);
- custom_remove_attr(win, ATTR_HIGHEST);
+ length = strlen (string);
+ temp = (width - length) / 2;
+ x = startx + (int) temp;
+ custom_apply_attr (win, ATTR_HIGHEST);
+ mvwprintw (win, y, x, "%s", string);
+ custom_remove_attr (win, ATTR_HIGHEST);
}
/*
@@ -182,66 +185,72 @@ print_in_middle(WINDOW *win, int starty, int startx, int width, char *string)
* As echoing is not set, we need to know the string we are working on to
* handle display correctly.
*/
-static void
-showcursor(WINDOW *win, int y, int pos, char *str, int l, int offset)
+static void
+showcursor (WINDOW *win, int y, int pos, char *str, int l, int offset)
{
- char *nc;
+ char *nc;
- nc = str + pos;
- wmove(win, y, pos - offset);
- (pos >= l) ? waddch(win, SPC|A_REVERSE) : waddch(win, *nc|A_REVERSE);
+ nc = str + pos;
+ wmove (win, y, pos - offset);
+ (pos >= l) ? waddch (win, SPC | A_REVERSE) : waddch (win, *nc | A_REVERSE);
}
/* Print the string at the desired position. */
-static void
-showstring(WINDOW *win, int y, int x, char *str, int len, int pos)
-{
- const int rec = 30, border = 3;
- const int max_col = col - border, max_len = max_col - rec;
- int page, max_page, offset, c = 0;
- char *orig;
-
- orig = str;
- max_page = (len - rec) / max_len;
- page = (pos - rec) / max_len;
- offset = page * max_len;
- str += offset;
- mvwaddnstr(win, y, x, str, MIN(len, max_col));
- wclrtoeol(win);
- if (page > 0 && page < max_page) {
- c = '*';
- } else if (page > 0) {
- c = '<';
- } else if (page < max_page) {
- c = '>';
- } else
- c = 0;
- mvwprintw(win, y, col - 1, "%c", c);
- showcursor(win, y, pos, orig, len, offset);
+static void
+showstring (WINDOW *win, int y, int x, char *str, int len, int pos)
+{
+ const int rec = 30, border = 3;
+ const int max_col = col - border, max_len = max_col - rec;
+ int page, max_page, offset, c = 0;
+ char *orig;
+
+ orig = str;
+ max_page = (len - rec) / max_len;
+ page = (pos - rec) / max_len;
+ offset = page * max_len;
+ str += offset;
+ mvwaddnstr (win, y, x, str, MIN (len, max_col));
+ wclrtoeol (win);
+ if (page > 0 && page < max_page)
+ {
+ c = '*';
+ }
+ else if (page > 0)
+ {
+ c = '<';
+ }
+ else if (page < max_page)
+ {
+ c = '>';
+ }
+ else
+ c = 0;
+ mvwprintw (win, y, col - 1, "%c", c);
+ showcursor (win, y, pos, orig, len, offset);
}
/* Delete a character at the given position in string. */
-static void
-del_char(int pos, char *str)
+static void
+del_char (int pos, char *str)
{
- int len;
+ int len;
- str += pos;
- len = strlen(str) + 1;
- memmove(str, str + 1, len);
+ str += pos;
+ len = strlen (str) + 1;
+ memmove (str, str + 1, len);
}
/* Add a character at the given position in string. */
static char *
-add_char(int pos, int ch, char *str)
+add_char (int pos, int ch, char *str)
{
- int len;
+ int len;
- str += pos;
- len = strlen(str) + 1;
- memmove(str + 1, str, len);
- *str = ch;
- return (str += len);
+ str += pos;
+ len = strlen (str) + 1;
+ memmove (str + 1, str, len);
+ *str = ch;
+ return (str += len);
}
/*
@@ -252,135 +261,146 @@ add_char(int pos, int ch, char *str)
* environment, otherwise the cursor would move from place to place without
* control.
*/
-int
-getstring(WINDOW *win, char *str, int l, int x, int y)
-{
- int ch, newpos, len = 0;
- char *orig;
-
- orig = str;
- custom_apply_attr(win, ATTR_HIGHEST);
- for (; *str; ++str, ++len)
- ;
- newpos = x + len;
- showstring(win, y, x, orig, len, newpos);
-
- while ((ch = wgetch(win)) != '\n') {
-
- switch (ch) {
-
- case KEY_BACKSPACE: /* delete one character */
- case 330:
- case 127:
- case CTRL('H'):
- if (len > 0) {
- --newpos; --len;
- if (newpos >= x + len)
- --str;
- else /* to be deleted inside string */
- del_char(newpos, orig);
- }
- break;
-
- case CTRL('D'): /* delete next character */
- if (newpos != (x + len)) {
- --len;
- if (newpos >= x + len)
- --str;
- else
- del_char(newpos, orig);
- } else
- printf("\a");
- break;
-
- case CTRL('K'): /* delete to end-of-line */
- str = orig + newpos;
- *str = 0;
- len -= (len - newpos);
- break;
-
- case CTRL('A'): /* go to begginning of string */
- newpos = x;
- break;
-
- case CTRL('E'): /* go to end of string */
- newpos = x + len;
- break;
-
- case KEY_LEFT: /* move one char backward */
- case CTRL('B'):
- if (newpos > x)
- newpos--;
- break;
-
- case KEY_RIGHT: /* move one char forward */
- case CTRL('F'):
- if (newpos < len)
- newpos++;
- break;
-
- case ESCAPE: /* cancel editing */
- return (GETSTRING_ESC);
- break;
-
- default: /* insert one character */
- if (len < l - 1) {
- if (newpos >= len) {
- str = orig + newpos;
- *str++ = ch;
- }
- else // char is to be inserted inside string
- str = add_char(newpos, ch, orig);
- ++len; ++newpos;
- }
-
+int
+getstring (WINDOW *win, char *str, int l, int x, int y)
+{
+ int ch, newpos, len = 0;
+ char *orig;
+
+ orig = str;
+ custom_apply_attr (win, ATTR_HIGHEST);
+ for (; *str; ++str, ++len)
+ ;
+ newpos = x + len;
+ showstring (win, y, x, orig, len, newpos);
+
+ while ((ch = wgetch (win)) != '\n')
+ {
+ switch (ch)
+ {
+ case KEY_BACKSPACE: /* delete one character */
+ case 330:
+ case 127:
+ case CTRL ('H'):
+ if (len > 0)
+ {
+ --newpos;
+ --len;
+ if (newpos >= x + len)
+ --str;
+ else /* to be deleted inside string */
+ del_char (newpos, orig);
+ }
+ break;
+
+ case CTRL ('D'): /* delete next character */
+ if (newpos != (x + len))
+ {
+ --len;
+ if (newpos >= x + len)
+ --str;
+ else
+ del_char (newpos, orig);
+ }
+ else
+ printf ("\a");
+ break;
+
+ case CTRL ('K'): /* delete to end-of-line */
+ str = orig + newpos;
+ *str = 0;
+ len -= (len - newpos);
+ break;
+
+ case CTRL ('A'): /* go to begginning of string */
+ newpos = x;
+ break;
+
+ case CTRL ('E'): /* go to end of string */
+ newpos = x + len;
+ break;
+
+ case KEY_LEFT: /* move one char backward */
+ case CTRL ('B'):
+ if (newpos > x)
+ newpos--;
+ break;
+
+ case KEY_RIGHT: /* move one char forward */
+ case CTRL ('F'):
+ if (newpos < len)
+ newpos++;
+ break;
+
+ case ESCAPE: /* cancel editing */
+ return (GETSTRING_ESC);
+ break;
+
+ default: /* insert one character */
+ if (len < l - 1)
+ {
+ if (newpos >= len)
+ {
+ str = orig + newpos;
+ *str++ = ch;
}
- showstring(win, y, x, orig, len, newpos);
- doupdate();
+ else // char is to be inserted inside string
+ str = add_char (newpos, ch, orig);
+ ++len;
+ ++newpos;
+ }
+
}
- *str = 0;
- custom_remove_attr(win, ATTR_HIGHEST);
- return (len == 0 ? GETSTRING_RET : GETSTRING_VALID);
+ showstring (win, y, x, orig, len, newpos);
+ doupdate ();
+ }
+ *str = 0;
+ custom_remove_attr (win, ATTR_HIGHEST);
+ return (len == 0 ? GETSTRING_RET : GETSTRING_VALID);
}
/* Update an already existing string. */
-int
-updatestring(WINDOW *win, char **str, int x, int y)
-{
- char *newstr;
- int escape, len = strlen(*str) + 1;
-
- newstr = (char *) malloc(BUFSIZ);
- (void)memcpy(newstr, *str, len);
- escape = getstring(win, newstr, BUFSIZ, x, y);
- if (!escape) {
- len = strlen(newstr) + 1;
- if ((*str = (char *) realloc(*str, len)) == NULL) {
- /* NOTREACHED */
- ierror(_("FATAL ERROR in updatestring: out of memory"),
- IERROR_FATAL);
- } else
- (void)memcpy(*str, newstr, len);
- }
- free(newstr);
- return escape;
+int
+updatestring (WINDOW *win, char **str, int x, int y)
+{
+ char *newstr;
+ int escape, len = strlen (*str) + 1;
+
+ newstr = (char *) malloc (BUFSIZ);
+ (void) memcpy (newstr, *str, len);
+ escape = getstring (win, newstr, BUFSIZ, x, y);
+ if (!escape)
+ {
+ len = strlen (newstr) + 1;
+ if ((*str = (char *) realloc (*str, len)) == NULL)
+ {
+ /* NOTREACHED */
+ ierror (_("FATAL ERROR in updatestring: out of memory"),
+ IERROR_FATAL);
+ }
+ else
+ (void) memcpy (*str, newstr, len);
+ }
+ free (newstr);
+ return (escape);
}
/* checks if a string is only made of digits */
-int is_all_digit(char *string)
+int
+is_all_digit (char *string)
{
- int digit, i;
- int all_digit;
+ int digit, i;
+ int all_digit;
- digit = 0;
- all_digit = 0;
+ digit = 0;
+ all_digit = 0;
- for (i = 0; i <= strlen(string); i++)
- if (isdigit(string[i]) != 0)
- digit++;
- if (digit == strlen(string))
- all_digit = 1;
- return all_digit;
+ for (i = 0; i <= strlen (string); i++)
+ if (isdigit (string[i]) != 0)
+ digit++;
+ if (digit == strlen (string))
+ all_digit = 1;
+ return (all_digit);
}
/*
@@ -389,146 +409,148 @@ int is_all_digit(char *string)
* table, and update the NB_CAL_CMDS, NB_APP_CMDS or NB_TOD_CMDS defines in
* utils.h, depending on which panel the added keybind is assigned to.
*/
-void
-status_bar(void)
-{
- window_e which_pan;
- int cmd_length, space_between_cmds, start, end, i, j = 0;
- const int pos[NB_PANELS + 1] =
- {0, NB_CAL_CMDS, NB_CAL_CMDS + NB_APP_CMDS, TOTAL_CMDS};
-
- binding_t help = { " ?", _("Help") };
- binding_t quit = { " Q", _("Quit") };
- binding_t save = { " S", _("Save") };
- binding_t export = { " X", _("Export") };
- binding_t add = { " A", _("Add Item") };
- binding_t del = { " D", _("Del Item") };
- binding_t edit = { " E", _("Edit Itm") };
- binding_t flag = { " !", _("Flag Itm") };
- binding_t day = { "H/L", _("-+1 Day") };
- binding_t week = { "K/J", _("-+1 Week") };
- binding_t updn = { "K/J", _("Up/Down") };
- binding_t rept = { " R", _("Repeat") };
- binding_t prio = { "+/-", _("Priority") };
- binding_t tab = { "Tab", _("Chg View") };
- binding_t togo = { " G", _("Go to") };
- binding_t conf = { " C", _("Config") };
- binding_t view = { " V", _("View") };
- binding_t draw = { " ^R", _("Redraw") };
- binding_t appt = { " ^A", _("Add Appt") };
- binding_t todo = { " ^T", _("Add Todo") };
- binding_t enote = { " N", _("EditNote") };
- binding_t vnote = { " >", _("ViewNote") };
- binding_t eday = { "^HL", _("-+1 Day") };
- binding_t ewek = { "^KJ", _("-+1 Week") };
- binding_t othr = { " O", _("OtherCmd") };
-
- binding_t *binding[TOTAL_CMDS] = {
- /* calendar keys */
- &help, &quit, &save, &export, &day, &week, &tab, &togo, &appt,
- &todo, &conf, &othr, &eday, &ewek, &draw, &othr,
- /* appointment keys */
- &help, &quit, &save, &export, &add, &del, &edit, &view, &rept,
- &updn, &flag, &othr, &enote, &vnote, &appt, &todo, &eday, &ewek,
- &conf, &togo, &tab, &draw, &othr,
- /* todo keys */
- &help, &quit, &save, &export, &add, &del, &edit, &view, &prio,
- &updn, &tab, &othr, &enote, &vnote, &appt, &todo, &eday, &ewek,
- &conf, &togo, &draw, &othr
- };
-
- /* Total length of a command. */
- cmd_length = KEY_LENGTH + LABEL_LENGTH;
- space_between_cmds = floor(col / CMDS_PER_LINE - cmd_length);
- cmd_length += space_between_cmds;
-
- /* Drawing the keybinding with attribute and label without. */
- erase_status_bar();
- which_pan = wins_slctd();
- start = pos[which_pan] + 2 * CMDS_PER_LINE * (status_page - 1);
- end = MIN(start + 2 * CMDS_PER_LINE, pos[which_pan + 1]);
- for (i = start; i < end; i += 2) {
- custom_apply_attr(win[STA].p, ATTR_HIGHEST);
- mvwprintw(win[STA].p, 0, j * cmd_length, binding[i]->key);
- if (i + 1 != end)
- mvwprintw(win[STA].p, 1, j * cmd_length,
- binding[i+1]->key);
- custom_remove_attr(win[STA].p, ATTR_HIGHEST);
- mvwprintw(win[STA].p, 0 , j * cmd_length + KEY_LENGTH,
- binding[i]->label);
- if (i + 1 != end)
- mvwprintw(win[STA].p, 1, j * cmd_length + KEY_LENGTH,
- binding[i+1]->label);
- j++;
- }
- wnoutrefresh(win[STA].p);
-}
-
-long
-date2sec(date_t day, unsigned hour, unsigned min)
-{
- struct tm start, *lt;
- time_t tstart, t;
-
- t = time(NULL);
- lt = localtime(&t);
- start = *lt;
-
- start.tm_mon = day.mm;
- start.tm_mday = day.dd;
- start.tm_year = day.yyyy;
- start.tm_hour = hour;
- start.tm_min = min;
- start.tm_sec = 0;
- start.tm_isdst = -1;
- start.tm_year -= 1900;
- start.tm_mon--;
- tstart = mktime(&start);
- if (tstart == -1) {
- fputs(_("FATAL ERROR in date2sec: failure in mktime\n"),
- stderr);
- fprintf(stderr, "%u %u %u %u %u\n", day.yyyy, day.mm, day.dd,
- hour, min);
- exit(EXIT_FAILURE);
- }
+void
+status_bar (void)
+{
+ window_e which_pan;
+ int cmd_length, space_between_cmds, start, end, i, j = 0;
+ const int pos[NB_PANELS + 1] =
+ { 0, NB_CAL_CMDS, NB_CAL_CMDS + NB_APP_CMDS, TOTAL_CMDS };
+
+ binding_t help = { " ?", _("Help") };
+ binding_t quit = { " Q", _("Quit") };
+ binding_t save = { " S", _("Save") };
+ binding_t export = { " X", _("Export") };
+ binding_t add = { " A", _("Add Item") };
+ binding_t del = { " D", _("Del Item") };
+ binding_t edit = { " E", _("Edit Itm") };
+ binding_t flag = { " !", _("Flag Itm") };
+ binding_t day = { "H/L", _("-+1 Day") };
+ binding_t week = { "K/J", _("-+1 Week") };
+ binding_t updn = { "K/J", _("Up/Down") };
+ binding_t rept = { " R", _("Repeat") };
+ binding_t prio = { "+/-", _("Priority") };
+ binding_t tab = { "Tab", _("Chg View") };
+ binding_t togo = { " G", _("Go to") };
+ binding_t conf = { " C", _("Config") };
+ binding_t view = { " V", _("View") };
+ binding_t draw = { " ^R", _("Redraw") };
+ binding_t appt = { " ^A", _("Add Appt") };
+ binding_t todo = { " ^T", _("Add Todo") };
+ binding_t enote = { " N", _("EditNote") };
+ binding_t vnote = { " >", _("ViewNote") };
+ binding_t eday = { "^HL", _("-+1 Day") };
+ binding_t ewek = { "^KJ", _("-+1 Week") };
+ binding_t othr = { " O", _("OtherCmd") };
+
+ binding_t *binding[TOTAL_CMDS] = {
+ /* calendar keys */
+ &help, &quit, &save, &export, &day, &week, &tab, &togo, &appt,
+ &todo, &conf, &othr, &eday, &ewek, &draw, &othr,
+ /* appointment keys */
+ &help, &quit, &save, &export, &add, &del, &edit, &view, &rept,
+ &updn, &flag, &othr, &enote, &vnote, &appt, &todo, &eday, &ewek,
+ &conf, &togo, &tab, &draw, &othr,
+ /* todo keys */
+ &help, &quit, &save, &export, &add, &del, &edit, &view, &prio,
+ &updn, &tab, &othr, &enote, &vnote, &appt, &todo, &eday, &ewek,
+ &conf, &togo, &draw, &othr
+ };
+
+ /* Total length of a command. */
+ cmd_length = KEY_LENGTH + LABEL_LENGTH;
+ space_between_cmds = floor (col / CMDS_PER_LINE - cmd_length);
+ cmd_length += space_between_cmds;
+
+ /* Drawing the keybinding with attribute and label without. */
+ erase_status_bar ();
+ which_pan = wins_slctd ();
+ start = pos[which_pan] + 2 * CMDS_PER_LINE * (status_page - 1);
+ end = MIN (start + 2 * CMDS_PER_LINE, pos[which_pan + 1]);
+ for (i = start; i < end; i += 2)
+ {
+ custom_apply_attr (win[STA].p, ATTR_HIGHEST);
+ mvwprintw (win[STA].p, 0, j * cmd_length, binding[i]->key);
+ if (i + 1 != end)
+ mvwprintw (win[STA].p, 1, j * cmd_length, binding[i + 1]->key);
+ custom_remove_attr (win[STA].p, ATTR_HIGHEST);
+ mvwprintw (win[STA].p, 0, j * cmd_length + KEY_LENGTH,
+ binding[i]->label);
+ if (i + 1 != end)
+ mvwprintw (win[STA].p, 1, j * cmd_length + KEY_LENGTH,
+ binding[i + 1]->label);
+ j++;
+ }
+ wnoutrefresh (win[STA].p);
+}
- return (tstart);
+long
+date2sec (date_t day, unsigned hour, unsigned min)
+{
+ struct tm start, *lt;
+ time_t tstart, t;
+
+ t = time (NULL);
+ lt = localtime (&t);
+ start = *lt;
+
+ start.tm_mon = day.mm;
+ start.tm_mday = day.dd;
+ start.tm_year = day.yyyy;
+ start.tm_hour = hour;
+ start.tm_min = min;
+ start.tm_sec = 0;
+ start.tm_isdst = -1;
+ start.tm_year -= 1900;
+ start.tm_mon--;
+ tstart = mktime (&start);
+ if (tstart == -1)
+ {
+ fputs (_("FATAL ERROR in date2sec: failure in mktime\n"), stderr);
+ fprintf (stderr, "%u %u %u %u %u\n", day.yyyy, day.mm, day.dd,
+ hour, min);
+ exit (EXIT_FAILURE);
+ }
+
+ return (tstart);
}
/* Return a string containing the hour of a given date in seconds. */
-char *date_sec2hour_str(long sec)
+char *
+date_sec2hour_str (long sec)
{
- const int TIME_LEN = 6;
- struct tm *lt;
- time_t t;
- char *timestr;
-
- t = sec;
- lt = localtime(&t);
- timestr = (char *) malloc(TIME_LEN);
- snprintf(timestr, TIME_LEN, "%02u:%02u", lt->tm_hour, lt->tm_min);
- return timestr;
+ const int TIME_LEN = 6;
+ struct tm *lt;
+ time_t t;
+ char *timestr;
+
+ t = sec;
+ lt = localtime (&t);
+ timestr = (char *) malloc (TIME_LEN);
+ snprintf (timestr, TIME_LEN, "%02u:%02u", lt->tm_hour, lt->tm_min);
+ return (timestr);
}
/* Return a string containing the date, given a date in seconds. */
char *
-date_sec2date_str(long sec, char *datefmt)
-{
- struct tm *lt;
- time_t t;
- char *datestr;
-
- datestr = (char *)malloc(sizeof(char) * BUFSIZ);
-
- if (sec == 0)
- snprintf(datestr, BUFSIZ, "0");
- else {
- t = sec;
- lt = localtime(&t);
- strftime(datestr, BUFSIZ, datefmt, lt);
- }
+date_sec2date_str (long sec, char *datefmt)
+{
+ struct tm *lt;
+ time_t t;
+ char *datestr;
- return (datestr);
+ datestr = (char *) malloc (sizeof (char) * BUFSIZ);
+
+ if (sec == 0)
+ snprintf (datestr, BUFSIZ, "0");
+ else
+ {
+ t = sec;
+ lt = localtime (&t);
+ strftime (datestr, BUFSIZ, datefmt, lt);
+ }
+
+ return (datestr);
}
/*
@@ -537,16 +559,16 @@ date_sec2date_str(long sec, char *datefmt)
* (calcurse event equivalent).
*/
void
-date_sec2ical_date(long sec, char *ical_date)
+date_sec2ical_date (long sec, char *ical_date)
{
#define DATELENGTH 9
- struct tm *lt;
- time_t t;
+ struct tm *lt;
+ time_t t;
- t = sec;
- lt = localtime(&t);
- strftime(ical_date, DATELENGTH, "%Y%m%d", lt);
+ t = sec;
+ lt = localtime (&t);
+ strftime (ical_date, DATELENGTH, "%Y%m%d", lt);
}
/*
@@ -554,36 +576,36 @@ date_sec2ical_date(long sec, char *ical_date)
* seconds. This is used to build iCal VEVENT (calcurse appointment equivalent).
*/
void
-date_sec2ical_datetime(long sec, char *ical_datetime)
+date_sec2ical_datetime (long sec, char *ical_datetime)
{
#define DATETIMELENGTH 16
- struct tm *lt;
- time_t t;
+ struct tm *lt;
+ time_t t;
- t = sec;
- lt = localtime(&t);
- strftime(ical_datetime, DATETIMELENGTH, "%Y%m%dT%H%M%S", lt);
+ t = sec;
+ lt = localtime (&t);
+ strftime (ical_datetime, DATETIMELENGTH, "%Y%m%dT%H%M%S", lt);
}
/*
* Return a long containing the date which is updated taking into account
* the new time and date entered by the user.
*/
-long
-update_time_in_date(long date, unsigned hr, unsigned mn)
+long
+update_time_in_date (long date, unsigned hr, unsigned mn)
{
- struct tm *lt;
- time_t t, new_date;
+ struct tm *lt;
+ time_t t, new_date;
- t = date;
- lt = localtime(&t);
- lt->tm_hour = hr;
- lt->tm_min = mn;
- new_date = mktime(lt);
- ASSERT(new_date != -1);
+ t = date;
+ lt = localtime (&t);
+ lt->tm_hour = hr;
+ lt->tm_min = mn;
+ new_date = mktime (lt);
+ ASSERT (new_date != -1);
- return (new_date);
+ return (new_date);
}
/*
@@ -591,33 +613,34 @@ update_time_in_date(long date, unsigned hr, unsigned mn)
* If no date is entered, current date is chosen.
*/
long
-get_sec_date(date_t date)
-{
- struct tm *ptrtime;
- time_t timer;
- long long_date;
- char current_day[] = "dd ";
- char current_month[] = "mm ";
- char current_year[] = "yyyy ";
-
- if (date.yyyy == 0 && date.mm == 0 && date.dd == 0) {
- timer = time(NULL);
- ptrtime = localtime(&timer);
- strftime(current_day, strlen(current_day), "%d", ptrtime);
- strftime(current_month, strlen(current_month), "%m", ptrtime);
- strftime(current_year, strlen(current_year), "%Y", ptrtime);
- date.mm = atoi(current_month);
- date.dd = atoi(current_day);
- date.yyyy = atoi(current_year);
- }
- long_date = date2sec(date, 0, 0);
- return long_date;
+get_sec_date (date_t date)
+{
+ struct tm *ptrtime;
+ time_t timer;
+ long long_date;
+ char current_day[] = "dd ";
+ char current_month[] = "mm ";
+ char current_year[] = "yyyy ";
+
+ if (date.yyyy == 0 && date.mm == 0 && date.dd == 0)
+ {
+ timer = time (NULL);
+ ptrtime = localtime (&timer);
+ strftime (current_day, strlen (current_day), "%d", ptrtime);
+ strftime (current_month, strlen (current_month), "%m", ptrtime);
+ strftime (current_year, strlen (current_year), "%Y", ptrtime);
+ date.mm = atoi (current_month);
+ date.dd = atoi (current_day);
+ date.yyyy = atoi (current_year);
+ }
+ long_date = date2sec (date, 0, 0);
+ return (long_date);
}
-long
-min2sec(unsigned minutes)
+long
+min2sec (unsigned minutes)
{
- return (minutes * MININSEC);
+ return (minutes * MININSEC);
}
/*
@@ -628,62 +651,59 @@ min2sec(unsigned minutes)
* [h:mm] or [hh:mm] format, and 2 if the entered time is correct and entered
* in [mm] format.
*/
-int
-check_time(char *string)
-{
- int ok = 0;
- char hour[] = " ";
- char minutes[] = " ";
-
- if (((strlen(string) == 2) || (strlen(string) == 3)) &&
- (isdigit(string[0]) != 0) && (isdigit(string[1]) != 0)) {
-
- strncpy(minutes, string, 2);
- if (atoi(minutes) >= 0)
-
- ok = 2; /* [MM] format */
-
- } else if ((strlen(string) == 4) && (isdigit(string[0]) != 0) &&
- (isdigit(string[2]) != 0) && (isdigit(string[3]) != 0) &&
- (string[1] == ':')) {
-
- strncpy(hour, string, 1);
- strncpy(minutes, string + 2, 2);
- if ((atoi(hour) <= 24) && (atoi(hour) >= 0) &&
- (atoi(minutes) < MININSEC) && (atoi(minutes) >= 0))
-
- ok = 1; /* [H:MM] format */
-
- } else if ((strlen(string) == 5) && (isdigit(string[0]) != 0) &&
- (isdigit(string[1]) != 0) && (isdigit(string[3]) != 0) &&
- (isdigit(string[4]) != 0) && (string[2] == ':')) {
-
- strncpy(hour, string, 2);
- strncpy(minutes, string + 3, 2);
- if ((atoi(hour) <= 24) && (atoi(hour) >= 0) &&
- (atoi(minutes) < MININSEC) && (atoi(minutes) >= 0))
-
- ok = 1; /* [HH:MM] format */
- }
-
- return (ok);
+int
+check_time (char *string)
+{
+ int ok = 0;
+ char hour[] = " ";
+ char minutes[] = " ";
+
+ if (((strlen (string) == 2) || (strlen (string) == 3))
+ && (isdigit (string[0]) != 0) && (isdigit (string[1]) != 0))
+ {
+ strncpy (minutes, string, 2);
+ if (atoi (minutes) >= 0)
+ ok = 2; /* [MM] format */
+ }
+ else if ((strlen (string) == 4) && (isdigit (string[0]) != 0)
+ && (isdigit (string[2]) != 0) && (isdigit (string[3]) != 0)
+ && (string[1] == ':'))
+ {
+ strncpy (hour, string, 1);
+ strncpy (minutes, string + 2, 2);
+ if ((atoi (hour) <= 24) && (atoi (hour) >= 0)
+ && (atoi (minutes) < MININSEC) && (atoi (minutes) >= 0))
+ ok = 1; /* [H:MM] format */
+ }
+ else if ((strlen (string) == 5) && (isdigit (string[0]) != 0)
+ && (isdigit (string[1]) != 0) && (isdigit (string[3]) != 0)
+ && (isdigit (string[4]) != 0) && (string[2] == ':'))
+ {
+ strncpy (hour, string, 2);
+ strncpy (minutes, string + 3, 2);
+ if ((atoi (hour) <= 24) && (atoi (hour) >= 0)
+ && (atoi (minutes) < MININSEC) && (atoi (minutes) >= 0))
+ ok = 1; /* [HH:MM] format */
+ }
+ return (ok);
}
/*
* Display a scroll bar when there are so many items that they
* can not be displayed inside the corresponding panel.
*/
-void draw_scrollbar(WINDOW *win, int y, int x, int length,
+void
+draw_scrollbar (WINDOW *win, int y, int x, int length,
int bar_top, int bar_bottom, bool hilt)
{
- mvwvline(win, bar_top, x, ACS_VLINE, bar_bottom - bar_top);
- if (hilt)
- custom_apply_attr(win, ATTR_HIGHEST);
- wattron(win, A_REVERSE);
- mvwvline(win, y, x, ' ', length);
- wattroff(win, A_REVERSE);
- if (hilt)
- custom_remove_attr(win, ATTR_HIGHEST);
+ mvwvline (win, bar_top, x, ACS_VLINE, bar_bottom - bar_top);
+ if (hilt)
+ custom_apply_attr (win, ATTR_HIGHEST);
+ wattron (win, A_REVERSE);
+ mvwvline (win, y, x, ' ', length);
+ wattroff (win, A_REVERSE);
+ if (hilt)
+ custom_remove_attr (win, ATTR_HIGHEST);
}
/*
@@ -691,144 +711,158 @@ void draw_scrollbar(WINDOW *win, int y, int x, int length,
* popup window. This is useful if an item description is too
* long to fit in its corresponding panel window.
*/
-void item_in_popup(char *saved_a_start, char *saved_a_end, char *msg,
- char *pop_title)
-{
- WINDOW *popup_win, *pad;
- const int margin_left = 4, margin_top = 4;
- const int winl = row - 5, winw = col - margin_left;
- const int padl = winl - 2, padw = winw - margin_left;
-
- pad = newpad(padl, padw);
- popup_win = popup(winl, winw, 1, 2, pop_title);
- if (strncmp(pop_title, _("Appointment"), 11) == 0) {
- mvwprintw(popup_win, margin_top, margin_left, "- %s -> %s",
- saved_a_start, saved_a_end);
- }
- mvwprintw(pad, 0, margin_left, "%s", msg);
- wmove(win[STA].p, 0, 0);
- pnoutrefresh(pad, 0, 0, margin_top + 2, margin_left, padl, winw);
- doupdate();
- wgetch(popup_win);
- delwin(pad);
- delwin(popup_win);
+void
+item_in_popup (char *saved_a_start, char *saved_a_end, char *msg,
+ char *pop_title)
+{
+ WINDOW *popup_win, *pad;
+ const int margin_left = 4, margin_top = 4;
+ const int winl = row - 5, winw = col - margin_left;
+ const int padl = winl - 2, padw = winw - margin_left;
+
+ pad = newpad (padl, padw);
+ popup_win = popup (winl, winw, 1, 2, pop_title);
+ if (strncmp (pop_title, _("Appointment"), 11) == 0)
+ {
+ mvwprintw (popup_win, margin_top, margin_left, "- %s -> %s",
+ saved_a_start, saved_a_end);
+ }
+ mvwprintw (pad, 0, margin_left, "%s", msg);
+ wmove (win[STA].p, 0, 0);
+ pnoutrefresh (pad, 0, 0, margin_top + 2, margin_left, padl, winw);
+ doupdate ();
+ wgetch (popup_win);
+ delwin (pad);
+ delwin (popup_win);
}
/* Reset the status bar page. */
-void reset_status_page(void)
+void
+reset_status_page (void)
{
- status_page = 1;
+ status_page = 1;
}
/* Update the status bar page number to display other commands. */
-void other_status_page(int panel)
-{
- int nb_item = 0, max_page;
- char *error = _("FATAL ERROR in other_status_page: unknown panel\n");
-
- switch (panel) {
- case CAL:
- nb_item = NB_CAL_CMDS;
- break;
- case APP:
- nb_item = NB_APP_CMDS;
- break;
- case TOD:
- nb_item = NB_TOD_CMDS;
- break;
- default:
- ierror(error, IERROR_FATAL);
- }
- max_page = ceil( nb_item / (2*CMDS_PER_LINE) ) + 1;
- if (status_page < max_page) {
- status_page++;
- } else {
- status_page = 1;
- }
+void
+other_status_page (int panel)
+{
+ int nb_item = 0, max_page;
+ char *error = _("FATAL ERROR in other_status_page: unknown panel\n");
+
+ switch (panel)
+ {
+ case CAL:
+ nb_item = NB_CAL_CMDS;
+ break;
+ case APP:
+ nb_item = NB_APP_CMDS;
+ break;
+ case TOD:
+ nb_item = NB_TOD_CMDS;
+ break;
+ default:
+ ierror (error, IERROR_FATAL);
+ }
+ max_page = ceil (nb_item / (2 * CMDS_PER_LINE)) + 1;
+ if (status_page < max_page)
+ {
+ status_page++;
+ }
+ else
+ {
+ status_page = 1;
+ }
}
/* Returns the beginning of current day in seconds from 1900. */
-long
-get_today(void)
+long
+get_today (void)
{
- struct tm *lt;
- time_t current_time;
- long current_day;
- date_t day;
+ struct tm *lt;
+ time_t current_time;
+ long current_day;
+ date_t day;
- current_time = time(NULL);
- lt = localtime(&current_time);
- day.mm = lt->tm_mon + 1;
- day.dd = lt->tm_mday;
- day.yyyy = lt->tm_year + 1900;
- current_day = date2sec(day, 0, 0);
+ current_time = time (NULL);
+ lt = localtime (&current_time);
+ day.mm = lt->tm_mon + 1;
+ day.dd = lt->tm_mday;
+ day.yyyy = lt->tm_year + 1900;
+ current_day = date2sec (day, 0, 0);
- return current_day;
+ return (current_day);
}
/* Returns the current time in seconds. */
-long now(void)
+long
+now (void)
{
- time_t current_time;
+ time_t current_time;
- current_time = time(NULL);
- return current_time;
+ current_time = time (NULL);
+ return (current_time);
}
/* Copy a string */
-char *mycpy(const char *src)
+char *
+mycpy (const char *src)
{
- char *string = malloc(strlen(src) + 1);
-
- if (string != NULL)
- return strncpy(string, src, strlen(src) + 1);
- else
- return NULL;
+ char *string = malloc (strlen (src) + 1);
+
+ if (string != NULL)
+ return (strncpy (string, src, strlen (src) + 1));
+ else
+ return (NULL);
}
long
-mystrtol(const char *str)
+mystrtol (const char *str)
{
- char *ep;
- long lval;
- const char *not_a_number =
- _("FATAL ERROR in mystrtol: could not convert string");
- const char *out_of_range =
- _("FATAL ERROR in mystrtol: number is out of range");
+ char *ep;
+ long lval;
+ const char *not_a_number =
+ _("FATAL ERROR in mystrtol: could not convert string");
+ const char *out_of_range =
+ _("FATAL ERROR in mystrtol: number is out of range");
- errno = 0;
- lval = strtol(str, &ep, 10);
- if (str[0] == '\0' || *ep != '\0')
- ierror(not_a_number, IERROR_FATAL);
- if (errno == ERANGE && (lval == LONG_MAX || lval == LONG_MIN))
- ierror(out_of_range, IERROR_FATAL);
+ errno = 0;
+ lval = strtol (str, &ep, 10);
+ if (str[0] == '\0' || *ep != '\0')
+ ierror (not_a_number, IERROR_FATAL);
+ if (errno == ERANGE && (lval == LONG_MAX || lval == LONG_MIN))
+ ierror (out_of_range, IERROR_FATAL);
- return (lval);
+ return (lval);
}
/* Print the given option value with appropriate color. */
-void
-print_option_incolor(WINDOW *win, bool option, int pos_y, int pos_x)
-{
- int color = 0;
- char option_value[BUFSIZ] = "";
-
- if (option == true) {
- color = ATTR_TRUE;
- strncpy(option_value, _("yes"), BUFSIZ);
- } else if (option == false) {
- color = ATTR_FALSE;
- strncpy(option_value, _("no"), BUFSIZ);
- } else {
- ierror(
- _("option not defined - Problem in print_option_incolor()"),
- IERROR_FATAL);
- }
- custom_apply_attr(win, color);
- mvwprintw(win, pos_y, pos_x, "%s", option_value);
- custom_remove_attr(win, color);
- wnoutrefresh(win);
- doupdate();
+void
+print_option_incolor (WINDOW *win, bool option, int pos_y, int pos_x)
+{
+ int color = 0;
+ char option_value[BUFSIZ] = "";
+
+ if (option == true)
+ {
+ color = ATTR_TRUE;
+ strncpy (option_value, _("yes"), BUFSIZ);
+ }
+ else if (option == false)
+ {
+ color = ATTR_FALSE;
+ strncpy (option_value, _("no"), BUFSIZ);
+ }
+ else
+ {
+ ierror (_("option not defined - Problem in print_option_incolor()"),
+ IERROR_FATAL);
+ }
+ custom_apply_attr (win, color);
+ mvwprintw (win, pos_y, pos_x, "%s", option_value);
+ custom_remove_attr (win, color);
+ wnoutrefresh (win);
+ doupdate ();
}
/*
@@ -836,94 +870,98 @@ print_option_incolor(WINDOW *win, bool option, int pos_y, int pos_x)
* the random part of the file name.
*/
char *
-new_tempfile(const char *prefix, int trailing_len)
-{
- char fullname[BUFSIZ];
- int prefix_len, fd;
- FILE *file;
-
- if (prefix == NULL)
- return (NULL);
-
- prefix_len = strlen(prefix);
- if (prefix_len + trailing_len >= BUFSIZ)
- return (NULL);
- memcpy(fullname, prefix, prefix_len);
- memset(fullname + prefix_len, 'X', trailing_len);
- fullname[prefix_len + trailing_len] = '\0';
- if ((fd = mkstemp(fullname)) == -1 ||
- (file = fdopen(fd, "w+")) == NULL) {
- if (fd != -1) {
- unlink(fullname);
- close(fd);
- }
- ierror(
- _("FATAL ERROR: temporary file could not be created!"),
- IERROR_WARN);
- return (NULL);
+new_tempfile (const char *prefix, int trailing_len)
+{
+ char fullname[BUFSIZ];
+ int prefix_len, fd;
+ FILE *file;
+
+ if (prefix == NULL)
+ return (NULL);
+
+ prefix_len = strlen (prefix);
+ if (prefix_len + trailing_len >= BUFSIZ)
+ return (NULL);
+ memcpy (fullname, prefix, prefix_len);
+ memset (fullname + prefix_len, 'X', trailing_len);
+ fullname[prefix_len + trailing_len] = '\0';
+ if ((fd = mkstemp (fullname)) == -1 || (file = fdopen (fd, "w+")) == NULL)
+ {
+ if (fd != -1)
+ {
+ unlink (fullname);
+ close (fd);
}
- fclose(file);
+ ierror (_("FATAL ERROR: temporary file could not be created!"),
+ IERROR_WARN);
+ return (NULL);
+ }
+ fclose (file);
- return (strdup(fullname + prefix_len));
+ return (strdup (fullname + prefix_len));
}
/* Erase a note previously attached to a todo, event or appointment. */
void
-erase_note(char **note, erase_flag_e flag)
+erase_note (char **note, erase_flag_e flag)
{
- char fullname[BUFSIZ];
- char *errmsg = _("FATAL ERROR in erase_note: could not remove note\n");
+ char fullname[BUFSIZ];
+ char *errmsg = _("FATAL ERROR in erase_note: could not remove note\n");
- if (*note == NULL)
- return;
- if (flag != ERASE_FORCE_KEEP_NOTE) {
- snprintf(fullname, BUFSIZ, "%s%s", path_notes, *note);
- if (unlink(fullname) != 0)
- ierror(errmsg, IERROR_FATAL);
- }
- free(*note);
- *note = NULL;
+ if (*note == NULL)
+ return;
+ if (flag != ERASE_FORCE_KEEP_NOTE)
+ {
+ snprintf (fullname, BUFSIZ, "%s%s", path_notes, *note);
+ if (unlink (fullname) != 0)
+ ierror (errmsg, IERROR_FATAL);
+ }
+ free (*note);
+ *note = NULL;
}
+
/*
* Convert a string containing a date into three integers containing the year,
* month and day.
* Returns 1 if sucessfully converted or 0 if the string is an invalid date.
*/
-int parse_date(char *date_string, int datefmt,
- int *year, int *month, int *day) {
- int in1, in2, in3;
- int lyear, lmonth, lday;
- if (date_string == NULL)
- return 0;
- if (sscanf(date_string, "%d / %d / %d", &in1, &in2, &in3) < 3 )
- return 0;
- switch (datefmt) {
- case 1:
- lmonth = in1;
- lday = in2;
- lyear = in3;
- break;
- case 2:
- lday = in1;
- lmonth = in2;
- lyear = in3;
- break;
- case 3:
- lyear = in1;
- lmonth = in2;
- lday = in3;
- break;
- default:
- return (0);
- }
- if (lyear < 1 || lyear > 9999 || lmonth < 1 || lmonth > 12 ||
- lday < 1 || lday > 31)
- return 0;
- if (year != NULL)
- *year = lyear;
- if (month != NULL)
- *month = lmonth;
- if (day != NULL)
- *day = lday;
- return (1);
+int
+parse_date (char *date_string, int datefmt, int *year, int *month, int *day)
+{
+ int in1, in2, in3;
+ int lyear, lmonth, lday;
+ if (date_string == NULL)
+ return (0);
+ if (sscanf (date_string, "%d / %d / %d", &in1, &in2, &in3) < 3)
+ return (0);
+ switch (datefmt)
+ {
+ case 1:
+ lmonth = in1;
+ lday = in2;
+ lyear = in3;
+ break;
+ case 2:
+ lday = in1;
+ lmonth = in2;
+ lyear = in3;
+ break;
+ case 3:
+ lyear = in1;
+ lmonth = in2;
+ lday = in3;
+ break;
+ default:
+ return (0);
+ }
+ if (lyear < 1 || lyear > 9999 || lmonth < 1 || lmonth > 12 || lday < 1
+ || lday > 31)
+ return (0);
+ if (year != NULL)
+ *year = lyear;
+ if (month != NULL)
+ *month = lmonth;
+ if (day != NULL)
+ *day = lday;
+ return (1);
}
diff --git a/src/utils.h b/src/utils.h
index 5580909..c51b7ae 100755
--- a/src/utils.h
+++ b/src/utils.h
@@ -1,4 +1,4 @@
-/* $calcurse: utils.h,v 1.28 2008/04/09 20:38:29 culot Exp $ */
+/* $calcurse: utils.h,v 1.29 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -36,70 +36,76 @@
((e) ? (void)0 : aerror(__FILE__, __LINE__, #e)); \
} while (0)
-#define SPC 32 /* ASCII code for white space */
+#define SPC 32 /* ASCII code for white space */
-#define NB_CAL_CMDS 16 /* number of commands while in cal view */
-#define NB_APP_CMDS 23 /* same thing while in appointment view */
-#define NB_TOD_CMDS 22 /* same thing while in todo view */
+#define NB_CAL_CMDS 16 /* number of commands while in cal view */
+#define NB_APP_CMDS 23 /* same thing while in appointment view */
+#define NB_TOD_CMDS 22 /* same thing while in todo view */
#define TOTAL_CMDS NB_CAL_CMDS + NB_APP_CMDS + NB_TOD_CMDS
-#define NB_PANELS 3 /* 3 panels: CALENDAR, APPOINTMENT, TODO */
-#define CMDS_PER_LINE 6 /* max number of commands per line */
-#define KEY_LENGTH 4 /* length of each keybinding + one space */
-#define LABEL_LENGTH 8 /* length of command description */
+#define NB_PANELS 3 /* 3 panels: CALENDAR, APPOINTMENT, TODO */
+#define CMDS_PER_LINE 6 /* max number of commands per line */
+#define KEY_LENGTH 4 /* length of each keybinding + one space */
+#define LABEL_LENGTH 8 /* length of command description */
-#define GETSTRING_VALID 0 /* value returned by getstring() if text is valid */
-#define GETSTRING_ESC 1 /* user pressed escape to cancel editing */
-#define GETSTRING_RET 2 /* return was pressed without entering any text */
+#define GETSTRING_VALID 0 /* value returned by getstring() if text is valid */
+#define GETSTRING_ESC 1 /* user pressed escape to cancel editing */
+#define GETSTRING_RET 2 /* return was pressed without entering any text */
-typedef struct { /* structure defining a keybinding */
- char *key;
- char *label;
-} binding_t;
+typedef struct
+{ /* structure defining a keybinding */
+ char *key;
+ char *label;
+}
+binding_t;
-typedef enum {
- IERROR_FATAL,
- IERROR_WARN
-} ierror_sev_e;
+typedef enum
+{
+ IERROR_FATAL,
+ IERROR_WARN
+}
+ierror_sev_e;
-typedef enum {
- ERASE_DONT_FORCE,
- ERASE_FORCE,
- ERASE_FORCE_KEEP_NOTE,
- ERASE_FORCE_ONLY_NOTE
-} erase_flag_e;
+typedef enum
+{
+ ERASE_DONT_FORCE,
+ ERASE_FORCE,
+ ERASE_FORCE_KEEP_NOTE,
+ ERASE_FORCE_ONLY_NOTE
+}
+erase_flag_e;
-void exit_calcurse(int);
-void ierror(const char *, ierror_sev_e);
-void aerror(const char *, int, const char *);
-void status_mesg(char *, char *);
-void erase_status_bar(void);
-void erase_window_part(WINDOW *, int, int, int, int);
-WINDOW *popup(int, int, int, int, char *);
-void print_in_middle(WINDOW *, int, int, int, char *);
-int getstring(WINDOW *, char *, int, int, int);
-int updatestring(WINDOW *, char **, int, int);
-int is_all_digit(char *);
-void status_bar(void);
-long date2sec(date_t, unsigned, unsigned);
-char *date_sec2hour_str(long);
-char *date_sec2date_str(long, char *);
-void date_sec2ical_date(long, char *);
-void date_sec2ical_datetime(long, char *);
-long update_time_in_date(long, unsigned, unsigned);
-long get_sec_date(date_t);
-long min2sec(unsigned);
-int check_time(char *);
-void draw_scrollbar(WINDOW *, int, int, int, int, int, bool);
-void item_in_popup(char *, char *, char *, char *);
-void reset_status_page(void);
-void other_status_page(int);
-long get_today(void);
-long now(void);
-char *mycpy(const char *);
-long mystrtol(const char *);
-void print_option_incolor(WINDOW *, bool, int, int);
-char *new_tempfile(const char *, int);
-void erase_note(char **, erase_flag_e);
-int parse_date(char *, int, int *, int *, int *);
+void exit_calcurse (int);
+void ierror (const char *, ierror_sev_e);
+void aerror (const char *, int, const char *);
+void status_mesg (char *, char *);
+void erase_status_bar (void);
+void erase_window_part (WINDOW *, int, int, int, int);
+WINDOW *popup (int, int, int, int, char *);
+void print_in_middle (WINDOW *, int, int, int, char *);
+int getstring (WINDOW *, char *, int, int, int);
+int updatestring (WINDOW *, char **, int, int);
+int is_all_digit (char *);
+void status_bar (void);
+long date2sec (date_t, unsigned, unsigned);
+char *date_sec2hour_str (long);
+char *date_sec2date_str (long, char *);
+void date_sec2ical_date (long, char *);
+void date_sec2ical_datetime (long, char *);
+long update_time_in_date (long, unsigned, unsigned);
+long get_sec_date (date_t);
+long min2sec (unsigned);
+int check_time (char *);
+void draw_scrollbar (WINDOW *, int, int, int, int, int, bool);
+void item_in_popup (char *, char *, char *, char *);
+void reset_status_page (void);
+void other_status_page (int);
+long get_today (void);
+long now (void);
+char *mycpy (const char *);
+long mystrtol (const char *);
+void print_option_incolor (WINDOW *, bool, int, int);
+char *new_tempfile (const char *, int);
+void erase_note (char **, erase_flag_e);
+int parse_date (char *, int, int *, int *, int *);
#endif /* CALCURSE_UTILS_H */
diff --git a/src/vars.c b/src/vars.c
index db09bf8..79e9b66 100755
--- a/src/vars.c
+++ b/src/vars.c
@@ -1,4 +1,4 @@
-/* $calcurse: vars.c,v 1.7 2008/04/09 20:38:29 culot Exp $ */
+/* $calcurse: vars.c,v 1.8 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -45,29 +45,31 @@ bool colorize = false;
* variables to store calendar names
*/
int days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
-char *monthnames[12] =
- { N_("January"),
- N_("February"),
- N_("March"),
- N_("April"),
- N_("May"),
- N_("June"),
- N_("July"),
- N_("August"),
- N_("September"),
- N_("October"),
- N_("November"),
- N_("December") };
-
-char *daynames[8] =
- { N_("Sun"),
- N_("Mon"),
- N_("Tue"),
- N_("Wed"),
- N_("Thu"),
- N_("Fri"),
- N_("Sat"),
- N_("Sun") };
+char *monthnames[12] = {
+ N_("January"),
+ N_("February"),
+ N_("March"),
+ N_("April"),
+ N_("May"),
+ N_("June"),
+ N_("July"),
+ N_("August"),
+ N_("September"),
+ N_("October"),
+ N_("November"),
+ N_("December")
+};
+
+char *daynames[8] = {
+ N_("Sun"),
+ N_("Mon"),
+ N_("Tue"),
+ N_("Wed"),
+ N_("Thu"),
+ N_("Fri"),
+ N_("Sat"),
+ N_("Sun")
+};
/*
* variables to store data path names, which are initialized in
@@ -85,51 +87,50 @@ struct pad_s *apad;
/* Variable to store notify-bar settings. */
struct nbar_s *nbar;
-
/*
* Variables init
*/
-void
-vars_init(conf_t *conf)
+void
+vars_init (conf_t *conf)
{
- char *PATH_VI = "/usr/bin/vi";
- char *PATH_LESS = "/usr/bin/less";
- char *ed, *pg;
-
- /* Variables for user configuration */
- conf->confirm_quit = true;
- conf->confirm_delete = true;
- conf->auto_save = true;
- conf->skip_system_dialogs = false;
- conf->skip_progress_bar = false;
- strncpy(conf->output_datefmt, "%D", 3);
- conf->input_datefmt = 1;
-
- /* Default external editor and pager */
- ed = getenv("VISUAL");
- if (ed == NULL || ed[0] == '\0')
- ed = getenv("EDITOR");
- if (ed == NULL || ed[0] == '\0')
- ed = PATH_VI;
- conf->editor = ed;
-
- pg = getenv("PAGER");
- if (pg == NULL || pg[0] == '\0')
- pg = PATH_LESS;
- conf->pager = pg;
-
- wins_set_layout(1);
-
- calendar_set_first_day_of_week(MONDAY);
-
- /* Pad structure to scroll text inside the appointment panel */
- apad = (struct pad_s *) malloc(sizeof(struct pad_s));
- apad->length = 1;
- apad->first_onscreen = 0;
-
- /* Attribute definitions for color and non-color terminals */
- custom_init_attr();
-
- /* Start at the current date */
- calendar_init_slctd_day();
+ char *PATH_VI = "/usr/bin/vi";
+ char *PATH_LESS = "/usr/bin/less";
+ char *ed, *pg;
+
+ /* Variables for user configuration */
+ conf->confirm_quit = true;
+ conf->confirm_delete = true;
+ conf->auto_save = true;
+ conf->skip_system_dialogs = false;
+ conf->skip_progress_bar = false;
+ strncpy (conf->output_datefmt, "%D", 3);
+ conf->input_datefmt = 1;
+
+ /* Default external editor and pager */
+ ed = getenv ("VISUAL");
+ if (ed == NULL || ed[0] == '\0')
+ ed = getenv ("EDITOR");
+ if (ed == NULL || ed[0] == '\0')
+ ed = PATH_VI;
+ conf->editor = ed;
+
+ pg = getenv ("PAGER");
+ if (pg == NULL || pg[0] == '\0')
+ pg = PATH_LESS;
+ conf->pager = pg;
+
+ wins_set_layout (1);
+
+ calendar_set_first_day_of_week (MONDAY);
+
+ /* Pad structure to scroll text inside the appointment panel */
+ apad = (struct pad_s *) malloc (sizeof (struct pad_s));
+ apad->length = 1;
+ apad->first_onscreen = 0;
+
+ /* Attribute definitions for color and non-color terminals */
+ custom_init_attr ();
+
+ /* Start at the current date */
+ calendar_init_slctd_day ();
}
diff --git a/src/vars.h b/src/vars.h
index 7f3db8f..6b06705 100755
--- a/src/vars.h
+++ b/src/vars.h
@@ -1,4 +1,4 @@
-/* $calcurse: vars.h,v 1.21 2008/04/09 20:38:29 culot Exp $ */
+/* $calcurse: vars.h,v 1.22 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -27,7 +27,7 @@
#ifndef CALCURSE_VARS_H
#define CALCURSE_VARS_H
-#include <ncurses.h>
+#include <ncurses.h>
#include <pthread.h>
#include <stdbool.h>
@@ -47,7 +47,7 @@
#define ATTR_HIGH 5
#define ATTR_HIGHEST 6
-#define DAYINSEC 86400
+#define DAYINSEC 86400
#define HOURINSEC 3600
#define MININSEC 60
#define WEEKINDAYS 7
@@ -61,50 +61,54 @@
#define DATEFMT_DESC(datefmt) (datefmt == 1 ? _("mm/dd/yyyy") : \
(datefmt == 2 ? _("dd/mm/yyyy") : _("yyyy/mm/dd")))
-struct pad_s {
- int width;
- int length;
- int first_onscreen; /* first line to be displayed inside window */
- WINDOW *ptrwin; /* pointer to the pad window */
+struct pad_s
+{
+ int width;
+ int length;
+ int first_onscreen; /* first line to be displayed inside window */
+ WINDOW *ptrwin; /* pointer to the pad window */
};
-struct nbar_s {
- int show; /* display or hide the notify-bar */
- int cntdwn; /* warn when time left before next app
- * becomes lesser than cntdwn */
- char datefmt[BUFSIZ]; /* format for displaying date */
- char timefmt[BUFSIZ]; /* format for displaying time */
- char cmd[BUFSIZ]; /* notification command */
- char *shell; /* user shell to launch notif. cmd */
- pthread_mutex_t mutex;
+struct nbar_s
+{
+ int show; /* display or hide the notify-bar */
+ int cntdwn; /* warn when time left before next app
+ * becomes lesser than cntdwn */
+ char datefmt[BUFSIZ]; /* format for displaying date */
+ char timefmt[BUFSIZ]; /* format for displaying time */
+ char cmd[BUFSIZ]; /* notification command */
+ char *shell; /* user shell to launch notif. cmd */
+ pthread_mutex_t mutex;
};
/* General configuration variables */
-typedef struct {
- bool auto_save;
- bool confirm_quit;
- bool confirm_delete;
- bool skip_system_dialogs;
- bool skip_progress_bar;
- char *editor;
- char *pager;
- char output_datefmt[BUFSIZ]; /* format for displaying date */
- int input_datefmt; /* format for reading date */
-} conf_t;
+typedef struct
+{
+ bool auto_save;
+ bool confirm_quit;
+ bool confirm_delete;
+ bool skip_system_dialogs;
+ bool skip_progress_bar;
+ char *editor;
+ char *pager;
+ char output_datefmt[BUFSIZ]; /* format for displaying date */
+ int input_datefmt; /* format for reading date */
+}
+conf_t;
-extern int col, row;
-extern bool colorize;
-extern int days[12];
-extern char *monthnames[12];
-extern char *daynames[8];
-extern char path_dir[BUFSIZ];
-extern char path_todo[BUFSIZ];
-extern char path_apts[BUFSIZ];
-extern char path_conf[BUFSIZ];
-extern char path_notes[BUFSIZ];
-extern struct pad_s *apad;
-extern struct nbar_s *nbar;
+extern int col, row;
+extern bool colorize;
+extern int days[12];
+extern char *monthnames[12];
+extern char *daynames[8];
+extern char path_dir[BUFSIZ];
+extern char path_todo[BUFSIZ];
+extern char path_apts[BUFSIZ];
+extern char path_conf[BUFSIZ];
+extern char path_notes[BUFSIZ];
+extern struct pad_s *apad;
+extern struct nbar_s *nbar;
-void vars_init(conf_t *conf);
+void vars_init (conf_t *conf);
#endif /* CALCURSE_VARS_H */
diff --git a/src/wins.c b/src/wins.c
index 920d076..489c3da 100755
--- a/src/wins.c
+++ b/src/wins.c
@@ -1,8 +1,8 @@
-/* $calcurse: wins.c,v 1.12 2008/02/14 20:20:23 culot Exp $ */
+/* $calcurse: wins.c,v 1.13 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
- * Copyright (c) 2007 Frederic Culot
+ * Copyright (c) 2007-2008 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -37,331 +37,344 @@
/* Variables to handle calcurse windows. */
window_t win[NBWINS];
-static window_e slctd_win;
-static int layout;
+static window_e slctd_win;
+static int layout;
/* Get the current layout. */
int
-wins_layout(void)
+wins_layout (void)
{
- return (layout);
+ return (layout);
}
/* Set the current layout. */
void
-wins_set_layout(int nb)
+wins_set_layout (int nb)
{
- layout = nb;
+ layout = nb;
}
/* Initialize the selected window in calcurse's interface. */
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. */
window_e
-wins_slctd(void)
+wins_slctd (void)
{
- return (slctd_win);
+ return (slctd_win);
}
/* Sets the selected window. */
void
-wins_slctd_set(window_e window)
+wins_slctd_set (window_e window)
{
- slctd_win = window;
+ slctd_win = window;
}
/* TAB key was hit in the interface, need to select next window. */
void
-wins_slctd_next(void)
+wins_slctd_next (void)
{
- if (slctd_win == TOD)
- slctd_win = CAL;
- else
- slctd_win++;
+ if (slctd_win == TOD)
+ slctd_win = CAL;
+ else
+ slctd_win++;
}
/* Create all the windows. */
-void
-wins_init(void)
+void
+wins_init (void)
{
- char label[BUFSIZ];
-
- /*
- * Create the three main windows plus the status bar and the pad used to
- * display appointments and event.
- */
- win[CAL].p = newwin(CALHEIGHT, CALWIDTH, win[CAL].y, win[CAL].x);
- snprintf(label, BUFSIZ, _("Calendar"));
- wins_show(win[CAL].p, label);
-
- win[APP].p = newwin(win[APP].h, win[APP].w, win[APP].y, win[APP].x);
- snprintf(label, BUFSIZ, _("Appointments"));
- wins_show(win[APP].p, label);
- apad->width = win[APP].w - 3;
- apad->ptrwin = newpad(apad->length, apad->width);
-
- win[TOD].p = newwin(win[TOD].h, win[TOD].w, win[TOD].y, win[TOD].x);
- snprintf(label, BUFSIZ, _("ToDo"));
- wins_show(win[TOD].p, label);
-
- win[STA].p = newwin(win[STA].h, win[STA].w, win[STA].y, win[STA].x);
-
- /* Enable function keys (i.e. arrow keys) in those windows */
- keypad(win[CAL].p, TRUE);
- keypad(win[APP].p, TRUE);
- keypad(win[TOD].p, TRUE);
- keypad(win[STA].p, TRUE);
+ char label[BUFSIZ];
+
+ /*
+ * Create the three main windows plus the status bar and the pad used to
+ * display appointments and event.
+ */
+ win[CAL].p = newwin (CALHEIGHT, CALWIDTH, win[CAL].y, win[CAL].x);
+ snprintf (label, BUFSIZ, _("Calendar"));
+ wins_show (win[CAL].p, label);
+
+ win[APP].p = newwin (win[APP].h, win[APP].w, win[APP].y, win[APP].x);
+ snprintf (label, BUFSIZ, _("Appointments"));
+ wins_show (win[APP].p, label);
+ apad->width = win[APP].w - 3;
+ apad->ptrwin = newpad (apad->length, apad->width);
+
+ win[TOD].p = newwin (win[TOD].h, win[TOD].w, win[TOD].y, win[TOD].x);
+ snprintf (label, BUFSIZ, _("ToDo"));
+ wins_show (win[TOD].p, label);
+
+ win[STA].p = newwin (win[STA].h, win[STA].w, win[STA].y, win[STA].x);
+
+ /* Enable function keys (i.e. arrow keys) in those windows */
+ keypad (win[CAL].p, TRUE);
+ keypad (win[APP].p, TRUE);
+ keypad (win[TOD].p, TRUE);
+ keypad (win[STA].p, TRUE);
}
/*
* Delete the existing windows and recreate them with their new
* size and placement.
*/
-void
-wins_reinit(void)
+void
+wins_reinit (void)
{
- delwin(win[STA].p);
- delwin(win[CAL].p);
- delwin(win[APP].p);
- delwin(apad->ptrwin);
- delwin(win[TOD].p);
- wins_get_config();
- wins_init();
- if (notify_bar())
- notify_reinit_bar(win[NOT].h, win[NOT].w, win[NOT].y,
- win[NOT].x);
+ delwin (win[STA].p);
+ delwin (win[CAL].p);
+ delwin (win[APP].p);
+ delwin (apad->ptrwin);
+ delwin (win[TOD].p);
+ wins_get_config ();
+ wins_init ();
+ if (notify_bar ())
+ notify_reinit_bar (win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x);
}
/* Show the window with a border and a label. */
-void
-wins_show(WINDOW * win, char *label)
+void
+wins_show (WINDOW *win, char *label)
{
- int startx, starty, height, width;
+ int startx, starty, height, width;
- getbegyx(win, starty, startx);
- getmaxyx(win, height, width);
+ getbegyx (win, starty, startx);
+ getmaxyx (win, height, width);
- box(win, 0, 0);
- mvwaddch(win, 2, 0, ACS_LTEE);
- mvwhline(win, 2, 1, ACS_HLINE, width - 2);
- mvwaddch(win, 2, width - 1, ACS_RTEE);
+ box (win, 0, 0);
+ mvwaddch (win, 2, 0, ACS_LTEE);
+ mvwhline (win, 2, 1, ACS_HLINE, width - 2);
+ 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.
*/
-void
-wins_get_config(void)
+void
+wins_get_config (void)
{
- /* Get the screen configuration */
- getmaxyx(stdscr, row, col);
-
- /* fixed values for status, notification bars and calendar */
- win[STA].h = STATUSHEIGHT;
- win[STA].w = col;
- win[STA].y = row - win[STA].h;
- win[STA].x = 0;
-
- if (notify_bar()) {
- win[NOT].h = 1;
- win[NOT].w = col;
- win[NOT].y = win[STA].y - 1;
- win[NOT].x = 0;
- } else {
- win[NOT].h = 0;
- win[NOT].w = 0;
- win[NOT].y = 0;
- win[NOT].x = 0;
- }
-
- if (layout <= 4) { /* APPOINTMENT is the biggest panel */
- win[APP].w = col - CALWIDTH;
- win[APP].h = row - (win[STA].h + win[NOT].h);
- win[TOD].w = CALWIDTH;
- win[TOD].h = row - (CALHEIGHT + win[STA].h + win[NOT].h);
- } else { /* TODO is the biggest panel */
- win[TOD].w = col - CALWIDTH;
- win[TOD].h = row - (win[STA].h + win[NOT].h);
- win[APP].w = CALWIDTH;
- win[APP].h = row - (CALHEIGHT + win[STA].h + win[NOT].h);
- }
-
- /* defining the layout */
- switch (layout) {
- case 1:
- win[APP].y = 0;
- win[APP].x = 0;
- win[CAL].y = 0;
- win[TOD].x = win[APP].w;
- win[TOD].y = CALHEIGHT;
- win[CAL].x = win[APP].w;
- break;
- case 2:
- win[APP].y = 0;
- win[APP].x = 0;
- win[TOD].y = 0;
- win[TOD].x = win[APP].w;
- win[CAL].x = win[APP].w;
- win[CAL].y = win[TOD].h;
- break;
- case 3:
- win[APP].y = 0;
- win[TOD].x = 0;
- win[CAL].x = 0;
- win[CAL].y = 0;
- win[APP].x = CALWIDTH;
- win[TOD].y = CALHEIGHT;
- break;
- case 4:
- win[APP].y = 0;
- win[TOD].x = 0;
- win[TOD].y = 0;
- win[CAL].x = 0;
- win[APP].x = CALWIDTH;
- win[CAL].y = win[TOD].h;
- break;
- case 5:
- win[TOD].y = 0;
- win[TOD].x = 0;
- win[CAL].y = 0;
- win[APP].y = CALHEIGHT;
- win[APP].x = win[TOD].w;
- win[CAL].x = win[TOD].w;
- break;
- case 6:
- win[TOD].y = 0;
- win[TOD].x = 0;
- win[APP].y = 0;
- win[APP].x = win[TOD].w;
- win[CAL].x = win[TOD].w;
- win[CAL].y = win[APP].h;
- break;
- case 7:
- win[TOD].y = 0;
- win[APP].x = 0;
- win[CAL].x = 0;
- win[CAL].y = 0;
- win[TOD].x = CALWIDTH;
- win[APP].y = CALHEIGHT;
- break;
- case 8:
- win[TOD].y = 0;
- win[APP].x = 0;
- win[CAL].x = 0;
- win[APP].y = 0;
- win[TOD].x = CALWIDTH;
- win[CAL].y = win[APP].h;
- break;
- }
+ /* Get the screen configuration */
+ getmaxyx (stdscr, row, col);
+
+ /* fixed values for status, notification bars and calendar */
+ win[STA].h = STATUSHEIGHT;
+ win[STA].w = col;
+ win[STA].y = row - win[STA].h;
+ win[STA].x = 0;
+
+ if (notify_bar ())
+ {
+ win[NOT].h = 1;
+ win[NOT].w = col;
+ win[NOT].y = win[STA].y - 1;
+ win[NOT].x = 0;
+ }
+ else
+ {
+ win[NOT].h = 0;
+ win[NOT].w = 0;
+ win[NOT].y = 0;
+ win[NOT].x = 0;
+ }
+
+ if (layout <= 4)
+ { /* APPOINTMENT is the biggest panel */
+ win[APP].w = col - CALWIDTH;
+ win[APP].h = row - (win[STA].h + win[NOT].h);
+ win[TOD].w = CALWIDTH;
+ win[TOD].h = row - (CALHEIGHT + win[STA].h + win[NOT].h);
+ }
+ else
+ { /* TODO is the biggest panel */
+ win[TOD].w = col - CALWIDTH;
+ win[TOD].h = row - (win[STA].h + win[NOT].h);
+ win[APP].w = CALWIDTH;
+ win[APP].h = row - (CALHEIGHT + win[STA].h + win[NOT].h);
+ }
+
+ /* defining the layout */
+ switch (layout)
+ {
+ case 1:
+ win[APP].y = 0;
+ win[APP].x = 0;
+ win[CAL].y = 0;
+ win[TOD].x = win[APP].w;
+ win[TOD].y = CALHEIGHT;
+ win[CAL].x = win[APP].w;
+ break;
+ case 2:
+ win[APP].y = 0;
+ win[APP].x = 0;
+ win[TOD].y = 0;
+ win[TOD].x = win[APP].w;
+ win[CAL].x = win[APP].w;
+ win[CAL].y = win[TOD].h;
+ break;
+ case 3:
+ win[APP].y = 0;
+ win[TOD].x = 0;
+ win[CAL].x = 0;
+ win[CAL].y = 0;
+ win[APP].x = CALWIDTH;
+ win[TOD].y = CALHEIGHT;
+ break;
+ case 4:
+ win[APP].y = 0;
+ win[TOD].x = 0;
+ win[TOD].y = 0;
+ win[CAL].x = 0;
+ win[APP].x = CALWIDTH;
+ win[CAL].y = win[TOD].h;
+ break;
+ case 5:
+ win[TOD].y = 0;
+ win[TOD].x = 0;
+ win[CAL].y = 0;
+ win[APP].y = CALHEIGHT;
+ win[APP].x = win[TOD].w;
+ win[CAL].x = win[TOD].w;
+ break;
+ case 6:
+ win[TOD].y = 0;
+ win[TOD].x = 0;
+ win[APP].y = 0;
+ win[APP].x = win[TOD].w;
+ win[CAL].x = win[TOD].w;
+ win[CAL].y = win[APP].h;
+ break;
+ case 7:
+ win[TOD].y = 0;
+ win[APP].x = 0;
+ win[CAL].x = 0;
+ win[CAL].y = 0;
+ win[TOD].x = CALWIDTH;
+ win[APP].y = CALHEIGHT;
+ break;
+ case 8:
+ win[TOD].y = 0;
+ win[APP].x = 0;
+ win[CAL].x = 0;
+ win[APP].y = 0;
+ win[TOD].x = CALWIDTH;
+ win[CAL].y = win[APP].h;
+ break;
+ }
}
/* draw panel border in color */
-static void
-border_color(WINDOW *window)
+static void
+border_color (WINDOW *window)
{
- int color_attr = A_BOLD;
- int no_color_attr = A_BOLD;
-
- if (colorize) {
- wattron(window, color_attr | COLOR_PAIR(COLR_CUSTOM));
- box(window, 0, 0);
- } else {
- wattron(window, no_color_attr);
- box(window, 0, 0);
- }
-
- if (colorize) {
- wattroff(window, color_attr | COLOR_PAIR(COLR_CUSTOM));
- } else {
- wattroff(window, no_color_attr);
- }
-
- wnoutrefresh(window);
+ int color_attr = A_BOLD;
+ int no_color_attr = A_BOLD;
+
+ if (colorize)
+ {
+ wattron (window, color_attr | COLOR_PAIR (COLR_CUSTOM));
+ box (window, 0, 0);
+ }
+ else
+ {
+ wattron (window, no_color_attr);
+ box (window, 0, 0);
+ }
+ if (colorize)
+ {
+ wattroff (window, color_attr | COLOR_PAIR (COLR_CUSTOM));
+ }
+ else
+ {
+ wattroff (window, no_color_attr);
+ }
+ wnoutrefresh (window);
}
/* draw panel border without any color */
-static void
-border_nocolor(WINDOW *window)
+static void
+border_nocolor (WINDOW *window)
{
- int color_attr = A_BOLD;
- int no_color_attr = A_DIM;
-
- if (colorize) {
- wattron(window, color_attr | COLOR_PAIR(COLR_DEFAULT));
- } else {
- wattron(window, no_color_attr);
- }
-
- box(window, 0, 0);
-
- if (colorize) {
- wattroff(window, color_attr | COLOR_PAIR(COLR_DEFAULT));
- } else {
- wattroff(window, no_color_attr);
- }
-
- wnoutrefresh(window);
+ int color_attr = A_BOLD;
+ int no_color_attr = A_DIM;
+
+ if (colorize)
+ {
+ wattron (window, color_attr | COLOR_PAIR (COLR_DEFAULT));
+ }
+ else
+ {
+ wattron (window, no_color_attr);
+ }
+ box (window, 0, 0);
+ if (colorize)
+ {
+ wattroff (window, color_attr | COLOR_PAIR (COLR_DEFAULT));
+ }
+ else
+ {
+ wattroff (window, no_color_attr);
+ }
+ wnoutrefresh (window);
}
/*
* Update all of the three windows and put a border around the
* selected window.
*/
-void
-wins_update(void)
+void
+wins_update (void)
{
- switch (slctd_win) {
-
- case CAL:
- border_color(win[CAL].p);
- border_nocolor(win[APP].p);
- border_nocolor(win[TOD].p);
- break;
-
- case APP:
- border_color(win[APP].p);
- border_nocolor(win[CAL].p);
- border_nocolor(win[TOD].p);
- break;
-
- case TOD:
- border_color(win[TOD].p);
- border_nocolor(win[APP].p);
- border_nocolor(win[CAL].p);
- break;
-
- default:
- ierror(_("FATAL ERROR in wins_update: no window selected\n"),
- IERROR_FATAL);
- /* NOTREACHED */
- }
-
- apoint_update_panel(&win[APP], slctd_win);
- todo_update_panel(&win[TOD], slctd_win);
- calendar_update_panel(win[CAL].p);
- status_bar();
- if (notify_bar())
- notify_update_bar();
- wmove(win[STA].p, 0, 0);
- doupdate();
+ switch (slctd_win)
+ {
+ case CAL:
+ border_color (win[CAL].p);
+ border_nocolor (win[APP].p);
+ border_nocolor (win[TOD].p);
+ break;
+
+ case APP:
+ border_color (win[APP].p);
+ border_nocolor (win[CAL].p);
+ border_nocolor (win[TOD].p);
+ break;
+
+ case TOD:
+ border_color (win[TOD].p);
+ border_nocolor (win[APP].p);
+ border_nocolor (win[CAL].p);
+ break;
+
+ default:
+ ierror (_("FATAL ERROR in wins_update: no window selected\n"),
+ IERROR_FATAL);
+ /* NOTREACHED */
+ }
+
+ apoint_update_panel (&win[APP], slctd_win);
+ todo_update_panel (&win[TOD], slctd_win);
+ calendar_update_panel (win[CAL].p);
+ status_bar ();
+ if (notify_bar ())
+ notify_update_bar ();
+ wmove (win[STA].p, 0, 0);
+ doupdate ();
}
/* Reset the screen, needed when resizing terminal for example. */
void
-wins_reset(void)
+wins_reset (void)
{
- endwin();
- refresh();
- curs_set(0);
- wins_reinit();
- wins_update();
+ endwin ();
+ refresh ();
+ curs_set (0);
+ wins_reinit ();
+ wins_update ();
}
/*
@@ -369,30 +382,32 @@ wins_reset(void)
* file.
*/
void
-wins_launch_external(const char *file, const char *cmd)
+wins_launch_external (const char *file, const char *cmd)
{
- char *p;
- int len;
-
- len = strlen(file) + strlen(cmd) + 2; /* Beware of space between cmd and
- file. */
- p = (char *)malloc(sizeof(char) * len);
- if (snprintf(p, len, "%s %s", cmd, file) == -1) {
- free(p);
- return;
- }
- if (notify_bar())
- notify_stop_main_thread();
- def_prog_mode();
- endwin();
- clear();
- refresh();
- system(p);
- reset_prog_mode();
- clearok(curscr, TRUE);
- curs_set(0);
- refresh();
- if (notify_bar())
- notify_start_main_thread();
- free(p);
+ char *p;
+ int len;
+
+ /* Beware of space between cmd and file. */
+ len = strlen (file) + strlen (cmd) + 2;
+
+ p = (char *) malloc (sizeof (char) * len);
+ if (snprintf (p, len, "%s %s", cmd, file) == -1)
+ {
+ free (p);
+ return;
+ }
+ if (notify_bar ())
+ notify_stop_main_thread ();
+ def_prog_mode ();
+ endwin ();
+ clear ();
+ refresh ();
+ system (p);
+ reset_prog_mode ();
+ clearok (curscr, TRUE);
+ curs_set (0);
+ refresh ();
+ if (notify_bar ())
+ notify_start_main_thread ();
+ free (p);
}
diff --git a/src/wins.h b/src/wins.h
index 34c905c..eef9119 100755
--- a/src/wins.h
+++ b/src/wins.h
@@ -1,8 +1,8 @@
-/* $calcurse: wins.h,v 1.6 2008/02/14 20:20:23 culot Exp $ */
+/* $calcurse: wins.h,v 1.7 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
- * Copyright (c) 2007 Frederic Culot
+ * Copyright (c) 2007-2008 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -29,38 +29,42 @@
#include "vars.h"
-typedef enum {
- CAL,
- APP,
- TOD,
- NOT,
- STA,
- NBWINS
-} window_e;
+typedef enum
+{
+ CAL,
+ APP,
+ TOD,
+ NOT,
+ STA,
+ NBWINS
+}
+window_e;
/* Window properties */
-typedef struct {
- WINDOW *p; /* pointer to window */
- unsigned w; /* width */
- unsigned h; /* height */
- int x; /* x position */
- int y; /* y position */
-} window_t;
+typedef struct
+{
+ WINDOW *p; /* pointer to window */
+ unsigned w; /* width */
+ unsigned h; /* height */
+ int x; /* x position */
+ int y; /* y position */
+}
+window_t;
-extern window_t win[NBWINS];
+extern window_t win[NBWINS];
-int wins_layout(void);
-void wins_set_layout(int);
-void wins_slctd_init(void);
-window_e wins_slctd(void);
-void wins_slctd_set(window_e);
-void wins_slctd_next(void);
-void wins_init(void);
-void wins_reinit(void);
-void wins_show(WINDOW *, char *);
-void wins_get_config(void);
-void wins_update(void);
-void wins_reset(void);
-void wins_launch_external(const char *, const char *);
+int wins_layout (void);
+void wins_set_layout (int);
+void wins_slctd_init (void);
+window_e wins_slctd (void);
+void wins_slctd_set (window_e);
+void wins_slctd_next (void);
+void wins_init (void);
+void wins_reinit (void);
+void wins_show (WINDOW *, char *);
+void wins_get_config (void);
+void wins_update (void);
+void wins_reset (void);
+void wins_launch_external (const char *, const char *);
#endif /* CALCURSE_WINS_H */