Yet another style for source code. GNU style now used (I am fed up with tabs...)

This commit is contained in:
Frederic Culot 2008-04-12 21:14:03 +00:00
parent 0c281d2c1e
commit efd782699b
33 changed files with 7612 additions and 7053 deletions

View File

@ -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: 09 Apr 2008:
Tony's patch concerning date format configuration imported, many Tony's patch concerning date format configuration imported, many
thanks to him thanks to him

View File

@ -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 * Calcurse - text-based organizer
@ -43,67 +43,69 @@ apoint_llist_t *alist_p;
static int hilt = 0; static int hilt = 0;
int int
apoint_llist_init(void) apoint_llist_init (void)
{ {
alist_p = (apoint_llist_t *) malloc(sizeof(apoint_llist_t)); alist_p = (apoint_llist_t *) malloc (sizeof (apoint_llist_t));
alist_p->root = NULL; alist_p->root = NULL;
pthread_mutex_init(&(alist_p->mutex), NULL); pthread_mutex_init (&(alist_p->mutex), NULL);
return 0; return (0);
} }
/* Sets which appointment is highlighted. */ /* Sets which appointment is highlighted. */
void void
apoint_hilt_set(int highlighted) apoint_hilt_set (int highlighted)
{ {
hilt = highlighted; hilt = highlighted;
} }
void void
apoint_hilt_decrease(void) apoint_hilt_decrease (void)
{ {
hilt--; hilt--;
} }
void void
apoint_hilt_increase(void) apoint_hilt_increase (void)
{ {
hilt++; hilt++;
} }
/* Return which appointment is highlighted. */ /* Return which appointment is highlighted. */
int int
apoint_hilt(void) apoint_hilt (void)
{ {
return (hilt); return (hilt);
} }
apoint_llist_node_t * 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; apoint_llist_node_t *o, **i;
o = (apoint_llist_node_t *) malloc(sizeof(apoint_llist_node_t)); o = (apoint_llist_node_t *) malloc (sizeof (apoint_llist_node_t));
o->mesg = (char *) malloc(strlen(mesg) + 1); o->mesg = (char *) malloc (strlen (mesg) + 1);
strncpy(o->mesg, mesg, strlen(mesg) + 1); strncpy (o->mesg, mesg, strlen (mesg) + 1);
o->note = (note != NULL) ? strdup(note) : NULL; o->note = (note != NULL) ? strdup (note) : NULL;
o->state = state; o->state = state;
o->start = start; o->start = start;
o->dur = dur; o->dur = dur;
pthread_mutex_lock(&(alist_p->mutex)); pthread_mutex_lock (&(alist_p->mutex));
i = &alist_p->root; i = &alist_p->root;
for (;;) { for (;;)
if (*i == 0 || (*i)->start > start) { {
if (*i == 0 || (*i)->start > start)
{
o->next = *i; o->next = *i;
*i = o; *i = o;
break; break;
} }
i = &(*i)->next; i = &(*i)->next;
} }
pthread_mutex_unlock(&(alist_p->mutex)); pthread_mutex_unlock (&(alist_p->mutex));
return o; return (o);
} }
/* /*
@ -111,14 +113,19 @@ apoint_new(char *mesg, char *note, long start, long dur, char state)
* depending if the start time is entered or not. * depending if the start time is entered or not.
*/ */
void void
apoint_add(void) apoint_add (void)
{ {
#define LTIME 6 #define LTIME 6
char *mesg_1 = _("Enter start time ([hh:mm] or [h:mm]), leave blank for an all-day event : "); char *mesg_1 =
char *mesg_2 = _("Enter end time ([hh:mm] or [h:mm]) or duration (in minutes) : "); _("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 *mesg_3 = _("Enter description :");
char *format_message_1 = _("You entered an invalid start time, should be [h:mm] or [hh:mm]"); char *format_message_1 =
char *format_message_2 = _("You entered an invalid end time, should be [h:mm] or [hh:mm] or [mm]"); _("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"); char *enter_str = _("Press [Enter] to continue");
int Id = 1; int Id = 1;
char item_time[LTIME] = ""; char item_time[LTIME] = "";
@ -131,19 +138,25 @@ apoint_add(void)
int is_appointment = 1; int is_appointment = 1;
/* Get the starting time */ /* Get the starting time */
while (check_time(item_time) != 1) { while (check_time (item_time) != 1)
status_mesg(mesg_1, ""); {
if (getstring(win[STA].p, item_time, LTIME, 0, 1) != status_mesg (mesg_1, "");
GETSTRING_ESC) { if (getstring (win[STA].p, item_time, LTIME, 0, 1) != GETSTRING_ESC)
if (strlen(item_time) == 0){ {
if (strlen (item_time) == 0)
{
is_appointment = 0; is_appointment = 0;
break; break;
} else if (check_time(item_time) != 1) { }
status_mesg(format_message_1, enter_str); else if (check_time (item_time) != 1)
wgetch(win[STA].p); {
} else status_mesg (format_message_1, enter_str);
sscanf(item_time, "%u:%u", &heures, &minutes); wgetch (win[STA].p);
} else }
else
sscanf (item_time, "%u:%u", &heures, &minutes);
}
else
return; return;
} }
/* /*
@ -151,65 +164,68 @@ apoint_add(void)
* depending on the starting time, and record the * depending on the starting time, and record the
* corresponding item. * corresponding item.
*/ */
if (is_appointment){ /* Get the appointment duration */ if (is_appointment)
{ /* Get the appointment duration */
item_time[0] = '\0'; item_time[0] = '\0';
while (check_time(item_time) == 0) { while (check_time (item_time) == 0)
status_mesg(mesg_2, ""); {
if (getstring(win[STA].p, item_time, LTIME, 0, 1) != status_mesg (mesg_2, "");
GETSTRING_VALID) if (getstring (win[STA].p, item_time, LTIME, 0, 1) != GETSTRING_VALID)
return; //nothing entered, cancel adding of event return; //nothing entered, cancel adding of event
else if (check_time(item_time) == 0) { else if (check_time (item_time) == 0)
status_mesg(format_message_2, enter_str); {
wgetch(win[STA].p); status_mesg (format_message_2, enter_str);
} else { wgetch (win[STA].p);
if (check_time(item_time) == 2) }
apoint_duration = atoi(item_time); else
else if (check_time(item_time) == 1) { {
sscanf(item_time, "%u:%u", if (check_time (item_time) == 2)
&end_h, &end_m); apoint_duration = atoi (item_time);
if (end_h < heures){ else if (check_time (item_time) == 1)
apoint_duration = {
MININSEC - minutes + end_m sscanf (item_time, "%u:%u", &end_h, &end_m);
+ if (end_h < heures)
(24 + end_h - (heures + 1)) {
* MININSEC; apoint_duration = MININSEC - minutes + end_m
} else { + (24 + end_h - (heures + 1)) * MININSEC;
apoint_duration = }
MININSEC - minutes + else
end_m + {
(end_h - (heures + 1)) * apoint_duration = MININSEC - minutes
MININSEC; + end_m + (end_h - (heures + 1)) * MININSEC;
} }
} }
} }
} }
} else /* Insert the event Id */ }
else /* Insert the event Id */
Id = 1; Id = 1;
status_mesg(mesg_3, ""); status_mesg (mesg_3, "");
if (getstring(win[STA].p, item_mesg, BUFSIZ, 0, 1) == if (getstring (win[STA].p, item_mesg, BUFSIZ, 0, 1) == GETSTRING_VALID)
GETSTRING_VALID) { {
if (is_appointment) { if (is_appointment)
apoint_start = {
date2sec(*calendar_get_slctd_day(), heures, apoint_start = date2sec (*calendar_get_slctd_day (), heures, minutes);
minutes); apoint_pointeur = apoint_new (item_mesg, 0L, apoint_start,
apoint_pointeur = apoint_new(item_mesg, 0L, apoint_start, min2sec (apoint_duration), 0L);
min2sec(apoint_duration), 0L); if (notify_bar ())
if (notify_bar()) notify_check_added (item_mesg, apoint_start, 0L);
notify_check_added(item_mesg, apoint_start, 0L); }
} else else
event_pointeur = event_new(item_mesg, 0L, event_pointeur = event_new (item_mesg, 0L,
date2sec(*calendar_get_slctd_day(), 12, 0), Id); date2sec (*calendar_get_slctd_day (), 12,
0), Id);
if (hilt == 0) if (hilt == 0)
hilt++; hilt++;
} }
erase_status_bar(); erase_status_bar ();
} }
/* Delete an item from the appointment list. */ /* Delete an item from the appointment list. */
void void
apoint_delete(conf_t *conf, unsigned *nb_events, unsigned *nb_apoints) apoint_delete (conf_t *conf, unsigned *nb_events, unsigned *nb_apoints)
{ {
char *choices = "[y/n] "; char *choices = "[y/n] ";
char *del_app_str = _("Do you really want to delete this item ?"); char *del_app_str = _("Do you really want to delete this item ?");
@ -221,45 +237,50 @@ apoint_delete(conf_t *conf, unsigned *nb_events, unsigned *nb_apoints)
int answer = 0; int answer = 0;
int deleted_item_type = 0; int deleted_item_type = 0;
date = calendar_get_slctd_day_sec(); date = calendar_get_slctd_day_sec ();
if (conf->confirm_delete) { if (conf->confirm_delete)
status_mesg(del_app_str, choices); {
answer = wgetch(win[STA].p); status_mesg (del_app_str, choices);
if ( (answer == 'y') && (nb_items != 0) ) answer = wgetch (win[STA].p);
if ((answer == 'y') && (nb_items != 0))
go_for_deletion = true; go_for_deletion = true;
else { else
erase_status_bar(); {
erase_status_bar ();
return; return;
} }
} else }
if (nb_items != 0) else if (nb_items != 0)
go_for_deletion = true; go_for_deletion = true;
if (go_for_deletion) { if (go_for_deletion)
if (nb_items != 0) { {
deleted_item_type = if (nb_items != 0)
day_erase_item(date, hilt, ERASE_DONT_FORCE); {
if (deleted_item_type == EVNT || deleted_item_type = day_erase_item (date, hilt, ERASE_DONT_FORCE);
deleted_item_type == RECUR_EVNT) { if (deleted_item_type == EVNT || deleted_item_type == RECUR_EVNT)
{
(*nb_events)--; (*nb_events)--;
to_be_removed = 1; to_be_removed = 1;
} else if (deleted_item_type == APPT || }
deleted_item_type == RECUR_APPT) { else if (deleted_item_type == APPT || deleted_item_type == RECUR_APPT)
{
(*nb_apoints)--; (*nb_apoints)--;
to_be_removed = 3; to_be_removed = 3;
} else if (deleted_item_type == 0) { }
else if (deleted_item_type == 0)
{
to_be_removed = 0; to_be_removed = 0;
} else }
ierror(errmsg, IERROR_FATAL); else
ierror (errmsg, IERROR_FATAL);
/* NOTREACHED */ /* NOTREACHED */
if (hilt > 1) if (hilt > 1)
hilt--; hilt--;
if (apad->first_onscreen >= to_be_removed) if (apad->first_onscreen >= to_be_removed)
apad->first_onscreen = apad->first_onscreen = apad->first_onscreen - to_be_removed;
apad->first_onscreen -
to_be_removed;
if (nb_items == 1) if (nb_items == 1)
hilt = 0; hilt = 0;
} }
@ -267,82 +288,88 @@ apoint_delete(conf_t *conf, unsigned *nb_events, unsigned *nb_apoints)
} }
unsigned unsigned
apoint_inday(apoint_llist_node_t *i, long start) apoint_inday (apoint_llist_node_t *i, long start)
{ {
if (i->start <= start + DAYINSEC && i->start + i->dur > start) { if (i->start <= start + DAYINSEC && i->start + i->dur > start)
return 1; {
return (1);
} }
return 0; return (0);
} }
void void
apoint_sec2str(apoint_llist_node_t *o, int type, long day, char *start, apoint_sec2str (apoint_llist_node_t *o, int type, long day, char *start,
char *end) char *end)
{ {
struct tm *lt; struct tm *lt;
time_t t; time_t t;
if (o->start < day && type == APPT) { if (o->start < day && type == APPT)
strncpy(start, "..:..", 6); {
} else { strncpy (start, "..:..", 6);
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) { else
strncpy(end, "..:..", 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; t = o->start + o->dur;
lt = localtime(&t); lt = localtime (&t);
snprintf(end, HRMIN_SIZE, "%02u:%02u", lt->tm_hour, snprintf (end, HRMIN_SIZE, "%02u:%02u", lt->tm_hour, lt->tm_min);
lt->tm_min);
} }
} }
void void
apoint_write(apoint_llist_node_t *o, FILE * f) apoint_write (apoint_llist_node_t *o, FILE *f)
{ {
struct tm *lt; struct tm *lt;
time_t t; time_t t;
t = o->start; t = o->start;
lt = localtime(&t); lt = localtime (&t);
fprintf(f, "%02u/%02u/%04u @ %02u:%02u", fprintf (f, "%02u/%02u/%04u @ %02u:%02u",
lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year, lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year, lt->tm_hour,
lt->tm_hour, lt->tm_min); lt->tm_min);
t = o->start + o->dur; t = o->start + o->dur;
lt = localtime(&t); lt = localtime (&t);
fprintf(f, " -> %02u/%02u/%04u @ %02u:%02u ", fprintf (f, " -> %02u/%02u/%04u @ %02u:%02u ",
lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year, lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year, lt->tm_hour,
lt->tm_hour, lt->tm_min); lt->tm_min);
if (o->note != NULL) if (o->note != NULL)
fprintf(f, ">%s ", o->note); fprintf (f, ">%s ", o->note);
if (o->state & APOINT_NOTIFY) if (o->state & APOINT_NOTIFY)
fprintf(f, "!"); fprintf (f, "!");
else else
fprintf(f, "|"); fprintf (f, "|");
fprintf(f, "%s\n", o->mesg); fprintf (f, "%s\n", o->mesg);
} }
apoint_llist_node_t * 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; struct tm *lt;
char buf[MESG_MAXSIZE], *nl; char buf[MESG_MAXSIZE], *nl;
time_t tstart, tend, t; time_t tstart, tend, t;
t = time(NULL); t = time (NULL);
lt = localtime(&t); lt = localtime (&t);
/* Read the appointment description */ /* Read the appointment description */
fgets(buf, MESG_MAXSIZE, f); fgets (buf, MESG_MAXSIZE, f);
nl = strchr(buf, '\n'); nl = strchr (buf, '\n');
if (nl) { if (nl)
{
*nl = '\0'; *nl = '\0';
} }
@ -353,61 +380,68 @@ apoint_scan(FILE * f, struct tm start, struct tm end, char state, char *note)
end.tm_year -= 1900; end.tm_year -= 1900;
end.tm_mon--; end.tm_mon--;
tstart = mktime(&start); tstart = mktime (&start);
tend = mktime(&end); tend = mktime (&end);
if (tstart == -1 || tend == -1 || tstart > tend) { if (tstart == -1 || tend == -1 || tstart > tend)
fputs(_("FATAL ERROR in apoint_scan: date error in the appointment\n"), stderr); {
exit(EXIT_FAILURE); 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)); return (apoint_new (buf, note, tstart, tend - tstart, state));
} }
/* Retrieve an appointment from the list, given the day and item position. */ /* Retrieve an appointment from the list, given the day and item position. */
apoint_llist_node_t * apoint_llist_node_t *
apoint_get(long day, int pos) apoint_get (long day, int pos)
{ {
apoint_llist_node_t *o; apoint_llist_node_t *o;
int n; int n;
n = 0; n = 0;
for (o = alist_p->root; o; o = o->next) { for (o = alist_p->root; o; o = o->next)
if (apoint_inday(o, day)) { {
if (apoint_inday (o, day))
{
if (n == pos) if (n == pos)
return o; return (o);
n++; n++;
} }
} }
/* NOTREACHED */ /* NOTREACHED */
fputs(_("FATAL ERROR in apoint_get: no such item\n"), stderr); fputs (_("FATAL ERROR in apoint_get: no such item\n"), stderr);
exit(EXIT_FAILURE); exit (EXIT_FAILURE);
} }
void void
apoint_delete_bynum(long start, unsigned num, erase_flag_e flag) apoint_delete_bynum (long start, unsigned num, erase_flag_e flag)
{ {
unsigned n; unsigned n;
int need_check_notify = 0; int need_check_notify = 0;
apoint_llist_node_t *i, **iptr; apoint_llist_node_t *i, **iptr;
n = 0; n = 0;
pthread_mutex_lock(&(alist_p->mutex)); pthread_mutex_lock (&(alist_p->mutex));
iptr = &alist_p->root; iptr = &alist_p->root;
for (i = alist_p->root; i != 0; i = i->next) { for (i = alist_p->root; i != 0; i = i->next)
if (apoint_inday(i, start)) { {
if (n == num) { if (apoint_inday (i, start))
{
if (n == num)
{
if (flag == ERASE_FORCE_ONLY_NOTE) if (flag == ERASE_FORCE_ONLY_NOTE)
erase_note(&i->note, flag); erase_note (&i->note, flag);
else { else
if (notify_bar()) {
need_check_notify = if (notify_bar ())
notify_same_item(i->start); need_check_notify = notify_same_item (i->start);
*iptr = i->next; *iptr = i->next;
free(i->mesg); free (i->mesg);
erase_note(&i->note, flag); erase_note (&i->note, flag);
free(i); free (i);
pthread_mutex_unlock(&(alist_p->mutex)); pthread_mutex_unlock (&(alist_p->mutex));
if (need_check_notify) if (need_check_notify)
notify_check_next_app(); notify_check_next_app ();
} }
return; return;
} }
@ -415,10 +449,10 @@ apoint_delete_bynum(long start, unsigned num, erase_flag_e flag)
} }
iptr = &i->next; iptr = &i->next;
} }
pthread_mutex_unlock(&(alist_p->mutex)); pthread_mutex_unlock (&(alist_p->mutex));
/* NOTREACHED */ /* NOTREACHED */
ierror(_("FATAL ERROR in apoint_delete_bynum: no such appointment"), ierror (_("FATAL ERROR in apoint_delete_bynum: no such appointment"),
IERROR_FATAL); IERROR_FATAL);
} }
@ -428,7 +462,7 @@ apoint_delete_bynum(long start, unsigned num, erase_flag_e flag)
* to place beggining of the pad correctly. * to place beggining of the pad correctly.
*/ */
static int static int
get_item_line(int item_nb, int nb_events_inday) get_item_line (int item_nb, int nb_events_inday)
{ {
int separator = 2; int separator = 2;
int line = 0; int line = 0;
@ -436,8 +470,8 @@ get_item_line(int item_nb, int nb_events_inday)
if (item_nb <= nb_events_inday) if (item_nb <= nb_events_inday)
line = item_nb - 1; line = item_nb - 1;
else else
line = nb_events_inday + separator + line = nb_events_inday + separator
(item_nb - (nb_events_inday + 1))*3 - 1; + (item_nb - (nb_events_inday + 1)) * 3 - 1;
return line; return line;
} }
@ -446,14 +480,14 @@ get_item_line(int item_nb, int nb_events_inday)
* appointment panel scroll down next time pnoutrefresh is called. * appointment panel scroll down next time pnoutrefresh is called.
*/ */
void void
apoint_scroll_pad_down(int nb_events_inday, int win_length) apoint_scroll_pad_down (int nb_events_inday, int win_length)
{ {
int pad_last_line = 0; int pad_last_line = 0;
int item_first_line = 0, item_last_line = 0; int item_first_line = 0, item_last_line = 0;
int borders = 6; int borders = 6;
int awin_length = win_length - borders; int awin_length = win_length - borders;
item_first_line = get_item_line(hilt, nb_events_inday); item_first_line = get_item_line (hilt, nb_events_inday);
if (hilt < nb_events_inday) if (hilt < nb_events_inday)
item_last_line = item_first_line; item_last_line = item_first_line;
else else
@ -468,11 +502,11 @@ apoint_scroll_pad_down(int nb_events_inday, int win_length)
* appointment panel scroll up next time pnoutrefresh is called. * appointment panel scroll up next time pnoutrefresh is called.
*/ */
void void
apoint_scroll_pad_up(int nb_events_inday) apoint_scroll_pad_up (int nb_events_inday)
{ {
int item_first_line = 0; int item_first_line = 0;
item_first_line = get_item_line(hilt, nb_events_inday); item_first_line = get_item_line (hilt, nb_events_inday);
if (item_first_line < apad->first_onscreen) if (item_first_line < apad->first_onscreen)
apad->first_onscreen = item_first_line; apad->first_onscreen = item_first_line;
} }
@ -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). * stored in the notify_app structure (which is the next item to be notified).
*/ */
struct notify_app_s * 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; apoint_llist_node_t *i;
pthread_mutex_lock(&(alist_p->mutex)); pthread_mutex_lock (&(alist_p->mutex));
for (i = alist_p->root; i != 0; i = i->next) { for (i = alist_p->root; i != 0; i = i->next)
if (i->start > app->time) { {
pthread_mutex_unlock(&(alist_p->mutex)); if (i->start > app->time)
return app; {
} else { pthread_mutex_unlock (&(alist_p->mutex));
if (i->start > start) { return (app);
}
else
{
if (i->start > start)
{
app->time = i->start; app->time = i->start;
app->txt = mycpy(i->mesg); app->txt = mycpy (i->mesg);
app->state = i->state; app->state = i->state;
app->got_app = 1; app->got_app = 1;
} }
} }
} }
pthread_mutex_unlock(&(alist_p->mutex)); pthread_mutex_unlock (&(alist_p->mutex));
return app; return (app);
} }
/* /*
@ -510,73 +549,77 @@ apoint_check_next(struct notify_app_s *app, long start)
* recur_apoint_s * recur_apoint_s
*/ */
apoint_llist_node_t * 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; apoint_llist_node_t *a;
a = (apoint_llist_node_t *) malloc(sizeof(apoint_llist_node_t)); a = (apoint_llist_node_t *) malloc (sizeof (apoint_llist_node_t));
a->mesg = (char *) malloc(strlen(p->mesg) + 1); a->mesg = (char *) malloc (strlen (p->mesg) + 1);
a->start = p->start; a->start = p->start;
a->dur = p->dur; a->dur = p->dur;
a->mesg = p->mesg; a->mesg = p->mesg;
return a; return (a);
} }
/* /*
* Switch notification state. * Switch notification state.
*/ */
void void
apoint_switch_notify(void) apoint_switch_notify (void)
{ {
apoint_llist_node_t *apoint; apoint_llist_node_t *apoint;
struct day_item_s *p; struct day_item_s *p;
long date; long date;
int apoint_nb = 0, n, need_chk_notify; int apoint_nb = 0, n, need_chk_notify;
p = day_get_item(hilt); p = day_get_item (hilt);
if (p->type != APPT && p->type != RECUR_APPT) if (p->type != APPT && p->type != RECUR_APPT)
return; return;
date = calendar_get_slctd_day_sec(); date = calendar_get_slctd_day_sec ();
if (p->type == RECUR_APPT) { if (p->type == RECUR_APPT)
recur_apoint_switch_notify(date, p->appt_pos); {
recur_apoint_switch_notify (date, p->appt_pos);
return; return;
} else if (p->type == APPT) }
apoint_nb = day_item_nb(date, hilt, APPT); else if (p->type == APPT)
apoint_nb = day_item_nb (date, hilt, APPT);
n = 0; n = 0;
need_chk_notify = 0; need_chk_notify = 0;
pthread_mutex_lock(&(alist_p->mutex)); pthread_mutex_lock (&(alist_p->mutex));
for (apoint = alist_p->root; apoint != 0; apoint = apoint->next) { for (apoint = alist_p->root; apoint != 0; apoint = apoint->next)
if (apoint_inday(apoint, date)) { {
if (n == apoint_nb) { if (apoint_inday (apoint, date))
{
if (n == apoint_nb)
{
apoint->state ^= APOINT_NOTIFY; apoint->state ^= APOINT_NOTIFY;
if (notify_bar ())
if (notify_bar()) {
notify_check_added(apoint->mesg, notify_check_added (apoint->mesg, apoint->start,
apoint->start, apoint->state); apoint->state);
}
pthread_mutex_unlock(&(alist_p->mutex)); pthread_mutex_unlock (&(alist_p->mutex));
if (need_chk_notify) if (need_chk_notify)
notify_check_next_app(); notify_check_next_app ();
return; return;
} }
n++; n++;
} }
} }
pthread_mutex_unlock(&(alist_p->mutex)); pthread_mutex_unlock (&(alist_p->mutex));
/* NOTREACHED */ /* NOTREACHED */
ierror( ierror (_("FATAL ERROR in apoint_switch_notify: no such appointment"),
_("FATAL ERROR in apoint_switch_notify: no such appointment"),
IERROR_FATAL); IERROR_FATAL);
} }
/* Updates the Appointment panel */ /* Updates the Appointment panel */
void void
apoint_update_panel(window_t *winapp, int which_pan) apoint_update_panel (window_t *winapp, int which_pan)
{ {
int title_xpos; int title_xpos;
int bordr = 1; int bordr = 1;
@ -587,24 +630,24 @@ apoint_update_panel(window_t *winapp, int which_pan)
date_t slctd_date; date_t slctd_date;
/* variable inits */ /* variable inits */
slctd_date = *calendar_get_slctd_day(); slctd_date = *calendar_get_slctd_day ();
title_xpos = winapp->w - (strlen(_(monthnames[slctd_date.mm - 1])) + 16); title_xpos = winapp->w - (strlen (_(monthnames[slctd_date.mm - 1])) + 16);
if (slctd_date.dd < 10) if (slctd_date.dd < 10)
title_xpos++; title_xpos++;
date = date2sec(slctd_date, 0, 0); date = date2sec (slctd_date, 0, 0);
day_write_pad(date, app_width, app_length, hilt); day_write_pad (date, app_width, app_length, hilt);
/* Print current date in the top right window corner. */ /* Print current date in the top right window corner. */
erase_window_part(win[APP].p, 1, title_lines, winapp->w - 2, erase_window_part (win[APP].p, 1, title_lines, winapp->w - 2, winapp->h - 2);
winapp->h - 2); custom_apply_attr (win[APP].p, ATTR_HIGHEST);
custom_apply_attr(win[APP].p, ATTR_HIGHEST); mvwprintw (win[APP].p, title_lines, title_xpos, "%s %s %d, %d",
mvwprintw(win[APP].p, title_lines, title_xpos, "%s %s %d, %d", calendar_get_pom (date), _(monthnames[slctd_date.mm - 1]),
calendar_get_pom(date), _(monthnames[slctd_date.mm - 1]),
slctd_date.dd, slctd_date.yyyy); slctd_date.dd, slctd_date.yyyy);
custom_remove_attr(win[APP].p, ATTR_HIGHEST); custom_remove_attr (win[APP].p, ATTR_HIGHEST);
/* Draw the scrollbar if necessary. */ /* Draw the scrollbar if necessary. */
if ((apad->length >= app_length)||(apad->first_onscreen > 0)) { if ((apad->length >= app_length) || (apad->first_onscreen > 0))
{
float ratio = ((float) app_length) / ((float) apad->length); float ratio = ((float) app_length) / ((float) apad->length);
int sbar_length = (int) (ratio * app_length); int sbar_length = (int) (ratio * app_length);
int highend = (int) (ratio * apad->first_onscreen); int highend = (int) (ratio * apad->first_onscreen);
@ -613,12 +656,13 @@ apoint_update_panel(window_t *winapp, int which_pan)
if ((sbar_top + sbar_length) > winapp->h - 1) if ((sbar_top + sbar_length) > winapp->h - 1)
sbar_length = winapp->h - 1 - sbar_top; sbar_length = winapp->h - 1 - sbar_top;
draw_scrollbar(win[APP].p, sbar_top, winapp->w - 2, sbar_length, draw_scrollbar (win[APP].p, sbar_top, winapp->w - 2, sbar_length,
title_lines + 1, winapp->h - 1, hilt_bar); title_lines + 1, winapp->h - 1, hilt_bar);
} }
wnoutrefresh(win[APP].p); wnoutrefresh (win[APP].p);
pnoutrefresh(apad->ptrwin, apad->first_onscreen, 0, pnoutrefresh (apad->ptrwin, apad->first_onscreen, 0,
winapp->y + title_lines + 1, winapp->x + bordr, winapp->y + title_lines + 1, winapp->x + bordr,
winapp->y + winapp->h - 2*bordr, winapp->x + winapp->w - 3*bordr); winapp->y + winapp->h - 2 * bordr,
winapp->x + winapp->w - 3 * bordr);
} }

View File

@ -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 * Calcurse - text-based organizer
@ -39,42 +39,46 @@
#define APOINT_NOTIFY 0x1 /* Item needs to be notified */ #define APOINT_NOTIFY 0x1 /* Item needs to be notified */
#define APOINT_NOTIFIED 0x2 /* Item was already notified */ #define APOINT_NOTIFIED 0x2 /* Item was already notified */
typedef struct apoint_llist_node { typedef struct apoint_llist_node
{
struct apoint_llist_node *next; struct apoint_llist_node *next;
long start; /* seconds since 1 jan 1970 */ long start; /* seconds since 1 jan 1970 */
long dur; /* duration of the appointment in seconds */ long dur; /* duration of the appointment in seconds */
char state; /* 8 bits to store item state */ char state; /* 8 bits to store item state */
char *mesg; char *mesg;
char *note; char *note;
} apoint_llist_node_t; }
apoint_llist_node_t;
typedef struct apoint_llist { typedef struct apoint_llist
{
apoint_llist_node_t *root; apoint_llist_node_t *root;
pthread_mutex_t mutex; pthread_mutex_t mutex;
} apoint_llist_t; }
apoint_llist_t;
extern apoint_llist_t *alist_p; extern apoint_llist_t *alist_p;
int apoint_llist_init(void); int apoint_llist_init (void);
void apoint_hilt_set(int); void apoint_hilt_set (int);
void apoint_hilt_decrease(void); void apoint_hilt_decrease (void);
void apoint_hilt_increase(void); void apoint_hilt_increase (void);
int apoint_hilt(void); int apoint_hilt (void);
apoint_llist_node_t *apoint_new(char *, char *, long, long, char); apoint_llist_node_t *apoint_new (char *, char *, long, long, char);
void apoint_add(void); void apoint_add (void);
void apoint_delete(conf_t *, unsigned *, unsigned *); void apoint_delete (conf_t *, unsigned *, unsigned *);
unsigned apoint_inday(apoint_llist_node_t *, long); unsigned apoint_inday (apoint_llist_node_t *, long);
void apoint_sec2str(apoint_llist_node_t *, int, long, void apoint_sec2str (apoint_llist_node_t *, int, long, char *,
char *, char *); char *);
void apoint_write(apoint_llist_node_t *, FILE *); 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_scan (FILE *, struct tm, struct tm, char, char *);
apoint_llist_node_t *apoint_get(long, int); apoint_llist_node_t *apoint_get (long, int);
void apoint_delete_bynum(long, unsigned, erase_flag_e); void apoint_delete_bynum (long, unsigned, erase_flag_e);
void apoint_scroll_pad_down(int, int); void apoint_scroll_pad_down (int, int);
void apoint_scroll_pad_up(int); void apoint_scroll_pad_up (int);
struct notify_app_s *apoint_check_next(struct notify_app_s *, long); 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 *); apoint_llist_node_t *apoint_recur_s2apoint_s (recur_apoint_llist_node_t *);
void apoint_switch_notify(void); void apoint_switch_notify (void);
void apoint_update_panel(window_t *, int); void apoint_update_panel (window_t *, int);
#endif /* CALCURSE_APOINT_H */ #endif /* CALCURSE_APOINT_H */

View File

@ -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 * Calcurse - text-based organizer
@ -45,45 +45,42 @@
* Print Calcurse usage and exit. * Print Calcurse usage and exit.
*/ */
static void static void
usage() usage ()
{ {
char *arg_usage = char *arg_usage =
_("Usage: calcurse [-h|-v] [-x] [-N] [-an] [-t[num]] [-d date|num] [-c file]\n"); _("Usage: calcurse [-h|-v] [-x] [-N] [-an] [-t[num]] [-d date|num] "
"[-c file]\n");
fputs(arg_usage, stdout); fputs (arg_usage, stdout);
} }
static void static void
usage_try() usage_try ()
{ {
char *arg_usage_try = char *arg_usage_try = _("Try 'calcurse -h' for more information.\n");
_("Try 'calcurse -h' for more information.\n"); fputs (arg_usage_try, stdout);
fputs(arg_usage_try, stdout);
} }
/* /*
* Print Calcurse version with a short copyright text and exit. * Print Calcurse version with a short copyright text and exit.
*/ */
static void static void
version_arg() version_arg ()
{ {
char vtitle[BUFSIZ]; char vtitle[BUFSIZ];
char *vtext = char *vtext =
_("\nCopyright (c) 2004-2007 Frederic Culot.\n" _("\nCopyright (c) 2004-2008 Frederic Culot.\n"
"This is free software; see the source for copying conditions.\n"); "This is free software; see the source for copying conditions.\n");
snprintf(vtitle, BUFSIZ, snprintf (vtitle, BUFSIZ, _("Calcurse %s - text-based organizer\n"), VERSION);
_("Calcurse %s - text-based organizer\n"), VERSION); fputs (vtitle, stdout);
fputs(vtitle, stdout); fputs (vtext, stdout);
fputs(vtext, stdout);
} }
/* /*
* Print the command line options and exit. * Print the command line options and exit.
*/ */
static void static void
help_arg() help_arg ()
{ {
char htitle[BUFSIZ]; char htitle[BUFSIZ];
char *htext = char *htext =
@ -121,11 +118,10 @@ help_arg()
"or read the manpage.\n" "or read the manpage.\n"
"Mail bug reports and suggestions to <calcurse@culot.org>.\n"); "Mail bug reports and suggestions to <calcurse@culot.org>.\n");
snprintf(htitle, BUFSIZ, snprintf (htitle, BUFSIZ, _("Calcurse %s - text-based organizer\n"), VERSION);
_("Calcurse %s - text-based organizer\n"), VERSION); fputs (htitle, stdout);
fputs(htitle, stdout); usage ();
usage(); fputs (htext, stdout);
fputs(htext, stdout);
} }
/* /*
@ -137,7 +133,7 @@ help_arg()
* (patch submitted by Erik Saule). * (patch submitted by Erik Saule).
*/ */
static void static void
print_notefile(FILE *out, char *filename, int nbtab) print_notefile (FILE *out, char *filename, int nbtab)
{ {
char path_to_notefile[BUFSIZ]; char path_to_notefile[BUFSIZ];
FILE *notefile; FILE *notefile;
@ -147,25 +143,30 @@ print_notefile(FILE *out, char *filename, int nbtab)
int printlinestarter = 1; int printlinestarter = 1;
for (i = 0; i < nbtab; i++) for (i = 0; i < nbtab; i++)
strcat(linestarter, "\t"); strcat (linestarter, "\t");
snprintf(path_to_notefile, BUFSIZ, "%s/%s", path_notes, filename); snprintf (path_to_notefile, BUFSIZ, "%s/%s", path_notes, filename);
notefile = fopen(path_to_notefile, "r"); notefile = fopen (path_to_notefile, "r");
if (notefile) { if (notefile)
while (fgets(buffer, BUFSIZ, notefile) != NULL) { {
if (printlinestarter) { while (fgets (buffer, BUFSIZ, notefile) != NULL)
fputs(linestarter,out); {
if (printlinestarter)
{
fputs (linestarter, out);
printlinestarter = 0; printlinestarter = 0;
} }
fputs(buffer, out); fputs (buffer, out);
if (buffer[strlen(buffer) - 1] == '\n') if (buffer[strlen (buffer) - 1] == '\n')
printlinestarter = 1; printlinestarter = 1;
} }
fputs("\n", out); fputs ("\n", out);
fclose(notefile); fclose (notefile);
} else { }
fputs(linestarter, out); else
fputs(_("No note file found\n"), out); {
fputs (linestarter, out);
fputs (_("No note file found\n"), out);
} }
} }
@ -174,35 +175,38 @@ print_notefile(FILE *out, char *filename, int nbtab)
* zero), then only todo items that have this priority will be displayed. * zero), then only todo items that have this priority will be displayed.
*/ */
static void static void
todo_arg(int priority, int print_note) todo_arg (int priority, int print_note)
{ {
struct todo_s *i; struct todo_s *i;
int title = 1; int title = 1;
char priority_str[BUFSIZ] = ""; char priority_str[BUFSIZ] = "";
io_load_todo(); io_load_todo ();
for (i = todolist; i != 0; i = i->next) { for (i = todolist; i != 0; i = i->next)
if (priority == 0 || i->id == priority) { {
if (title) { if (priority == 0 || i->id == priority)
fputs(_("to do:\n"),stdout); {
if (title)
{
fputs (_("to do:\n"), stdout);
title = 0; title = 0;
} }
snprintf(priority_str, BUFSIZ, "%d. ", i->id); snprintf (priority_str, BUFSIZ, "%d. ", i->id);
fputs(priority_str, stdout); fputs (priority_str, stdout);
fputs(i->mesg, stdout); fputs (i->mesg, stdout);
fputs("\n", stdout); fputs ("\n", stdout);
if (print_note && i->note) if (print_note && i->note)
print_notefile(stdout, i->note, 1); print_notefile (stdout, i->note, 1);
} }
} }
} }
/* Print the next appointment within the upcoming 24 hours. */ /* Print the next appointment within the upcoming 24 hours. */
static void static void
next_arg(void) next_arg (void)
{ {
struct notify_app_s next_app; struct notify_app_s next_app;
const long current_time = now(); const long current_time = now ();
int time_left, hours_left, min_left; int time_left, hours_left, min_left;
char mesg[BUFSIZ]; char mesg[BUFSIZ];
@ -210,19 +214,19 @@ next_arg(void)
next_app.got_app = 0; next_app.got_app = 0;
next_app.txt = NULL; next_app.txt = NULL;
next_app = *recur_apoint_check_next(&next_app, current_time, next_app = *recur_apoint_check_next (&next_app, current_time, get_today ());
get_today()); next_app = *apoint_check_next (&next_app, current_time);
next_app = *apoint_check_next(&next_app, current_time);
if (next_app.got_app) { if (next_app.got_app)
{
time_left = next_app.time - current_time; time_left = next_app.time - current_time;
hours_left = (time_left / HOURINSEC); hours_left = (time_left / HOURINSEC);
min_left = (time_left - hours_left * HOURINSEC) / MININSEC; min_left = (time_left - hours_left * HOURINSEC) / MININSEC;
fputs(_("next appointment:\n"), stdout); fputs (_("next appointment:\n"), stdout);
snprintf(mesg, BUFSIZ, " [%02d:%02d] %s\n", snprintf (mesg, BUFSIZ, " [%02d:%02d] %s\n", hours_left, min_left,
hours_left, min_left, next_app.txt); next_app.txt);
fputs(mesg, stdout); fputs (mesg, stdout);
free(next_app.txt); free (next_app.txt);
} }
} }
@ -230,17 +234,17 @@ next_arg(void)
* Print the date on stdout. * Print the date on stdout.
*/ */
static void static void
arg_print_date(long date, conf_t *conf) arg_print_date (long date, conf_t *conf)
{ {
char date_str[BUFSIZ]; char date_str[BUFSIZ];
time_t t; time_t t;
struct tm *lt; struct tm *lt;
t = date; t = date;
lt = localtime(&t); lt = localtime (&t);
strftime(date_str, BUFSIZ, conf->output_datefmt, lt); strftime (date_str, BUFSIZ, conf->output_datefmt, lt);
fputs(date_str,stdout); fputs (date_str, stdout);
fputs(":\n",stdout); fputs (":\n", stdout);
} }
/* /*
@ -249,7 +253,7 @@ arg_print_date(long date, conf_t *conf)
* If there is also no date given, current date is considered. * If there is also no date given, current date is considered.
*/ */
static int static int
app_arg(int add_line, date_t *day, long date, int print_note, conf_t *conf) app_arg (int add_line, date_t *day, long date, int print_note, conf_t *conf)
{ {
struct recur_event_s *re; struct recur_event_s *re;
struct event_s *j; struct event_s *j;
@ -262,7 +266,7 @@ app_arg(int add_line, date_t *day, long date, int print_note, conf_t *conf)
char apoint_end_time[100]; char apoint_end_time[100];
if (date == 0) if (date == 0)
today = get_sec_date(*day); today = get_sec_date (*day);
else else
today = date; today = date;
@ -271,102 +275,117 @@ app_arg(int add_line, date_t *day, long date, int print_note, conf_t *conf)
* that date and it is the first one, and then print all the events for * that date and it is the first one, and then print all the events for
* that date. * that date.
*/ */
for (re = recur_elist; re != 0; re = re->next) { 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)) { if (recur_item_inday (re->day, re->exc, re->rpt->type, re->rpt->freq,
re->rpt->until, today))
{
app_found = 1; app_found = 1;
if (add_line) { if (add_line)
fputs("\n", stdout); {
fputs ("\n", stdout);
add_line = 0; add_line = 0;
} }
if (print_date) { if (print_date)
arg_print_date(today, conf); {
arg_print_date (today, conf);
print_date = false; print_date = false;
} }
fputs(" * ", stdout); fputs (" * ", stdout);
fputs(re->mesg, stdout); fputs("\n", stdout); fputs (re->mesg, stdout);
fputs ("\n", stdout);
if (print_note && re->note) if (print_note && re->note)
print_notefile(stdout, re->note, 2); print_notefile (stdout, re->note, 2);
} }
} }
for (j = eventlist; j != 0; j = j->next) { for (j = eventlist; j != 0; j = j->next)
if (event_inday(j, today)) { {
if (event_inday (j, today))
{
app_found = 1; app_found = 1;
if (add_line) { if (add_line)
fputs("\n",stdout); {
fputs ("\n", stdout);
add_line = 0; add_line = 0;
} }
if (print_date) { if (print_date)
arg_print_date(today, conf); {
arg_print_date (today, conf);
print_date = false; print_date = false;
} }
fputs(" * ", stdout); fputs (" * ", stdout);
fputs(j->mesg, stdout); fputs (j->mesg, stdout);
fputs("\n", stdout); fputs ("\n", stdout);
if (print_note && j->note) if (print_note && j->note)
print_notefile(stdout, j->note, 2); print_notefile (stdout, j->note, 2);
} }
} }
/* Same process is performed but this time on the appointments. */ /* Same process is performed but this time on the appointments. */
pthread_mutex_lock(&(recur_alist_p->mutex)); pthread_mutex_lock (&(recur_alist_p->mutex));
for (ra = recur_alist_p->root; ra != 0; ra = ra->next) { 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)) { if (recur_item_inday (ra->start, ra->exc, ra->rpt->type, ra->rpt->freq,
ra->rpt->until, today))
{
app_found = 1; app_found = 1;
if (add_line) { if (add_line)
fputs("\n",stdout); {
fputs ("\n", stdout);
add_line = 0; add_line = 0;
} }
if (print_date) { if (print_date)
arg_print_date(today, conf); {
arg_print_date (today, conf);
print_date = false; print_date = false;
} }
apoint_sec2str(apoint_recur_s2apoint_s(ra), apoint_sec2str (apoint_recur_s2apoint_s (ra), RECUR_APPT, today,
RECUR_APPT, today, apoint_start_time, apoint_start_time, apoint_end_time);
apoint_end_time); fputs (" - ", stdout);
fputs(" - ", stdout); fputs (apoint_start_time, stdout);
fputs(apoint_start_time, stdout); fputs (" -> ", stdout);
fputs(" -> ", stdout); fputs (apoint_end_time, stdout);
fputs(apoint_end_time, stdout); fputs ("\n\t", stdout);
fputs("\n\t", stdout); fputs (ra->mesg, stdout);
fputs(ra->mesg, stdout); fputs ("\n", stdout);
fputs("\n", stdout);
if (print_note && ra->note) if (print_note && ra->note)
print_notefile(stdout, ra->note, 2); print_notefile (stdout, ra->note, 2);
} }
} }
pthread_mutex_unlock(&(recur_alist_p->mutex)); pthread_mutex_unlock (&(recur_alist_p->mutex));
pthread_mutex_lock(&(alist_p->mutex)); pthread_mutex_lock (&(alist_p->mutex));
for (i = alist_p->root; i != 0; i = i->next) { for (i = alist_p->root; i != 0; i = i->next)
if (apoint_inday(i, today)) { {
if (apoint_inday (i, today))
{
app_found = 1; app_found = 1;
if (add_line) { if (add_line)
fputs("\n",stdout); {
fputs ("\n", stdout);
add_line = 0; add_line = 0;
} }
if (print_date) { if (print_date)
arg_print_date(today, conf); {
arg_print_date (today, conf);
print_date = false; print_date = false;
} }
apoint_sec2str(i, APPT, today, apoint_start_time, apoint_sec2str (i, APPT, today, apoint_start_time, apoint_end_time);
apoint_end_time); fputs (" - ", stdout);
fputs(" - ", stdout); fputs (apoint_start_time, stdout);
fputs(apoint_start_time, stdout); fputs (" -> ", stdout);
fputs(" -> ", stdout); fputs (apoint_end_time, stdout);
fputs(apoint_end_time, stdout); fputs ("\n\t", stdout);
fputs("\n\t", stdout); fputs (i->mesg, stdout);
fputs(i->mesg, stdout); fputs ("\n", stdout);
fputs("\n", stdout);
if (print_note && i->note) if (print_note && i->note)
print_notefile(stdout, i->note, 2); print_notefile (stdout, i->note, 2);
} }
} }
pthread_mutex_unlock(&(alist_p->mutex)); pthread_mutex_unlock (&(alist_p->mutex));
return app_found; return (app_found);
} }
/* /*
@ -374,7 +393,7 @@ app_arg(int add_line, date_t *day, long date, int print_note, conf_t *conf)
* days. * days.
*/ */
static void static void
date_arg(char *ddate, int add_line, int print_note, conf_t *conf) date_arg (char *ddate, int add_line, int print_note, conf_t *conf)
{ {
int i; int i;
date_t day; date_t day;
@ -387,49 +406,56 @@ date_arg(char *ddate, int add_line, int print_note, conf_t *conf)
* Check (with the argument length) if a date or a number of days * Check (with the argument length) if a date or a number of days
* was entered, and then call app_arg() to print appointments * was entered, and then call app_arg() to print appointments
*/ */
arg_len = strlen(ddate); arg_len = strlen (ddate);
if (arg_len <= 4) { /* a number of days was entered */ if (arg_len <= 4)
for (i = 0; i <= arg_len-1; i++) { { /* a number of days was entered */
if (isdigit(ddate[i])) for (i = 0; i <= arg_len - 1; i++)
{
if (isdigit (ddate[i]))
num_digit++; num_digit++;
} }
if (num_digit == arg_len) if (num_digit == arg_len)
numdays = atoi(ddate); numdays = atoi (ddate);
/* /*
* Get current date, and print appointments for each day * Get current date, and print appointments for each day
* in the chosen interval. app_found and add_line are used * in the chosen interval. app_found and add_line are used
* to format the output correctly. * to format the output correctly.
*/ */
timer = time(NULL); timer = time (NULL);
t = *localtime(&timer); t = *localtime (&timer);
for (i = 0; i < numdays; i++) { for (i = 0; i < numdays; i++)
{
day.dd = t.tm_mday; day.dd = t.tm_mday;
day.mm = t.tm_mon + 1; day.mm = t.tm_mon + 1;
day.yyyy = t.tm_year + 1900; day.yyyy = t.tm_year + 1900;
app_found = app_arg(add_line, &day, 0, print_note, conf); app_found = app_arg (add_line, &day, 0, print_note, conf);
if (app_found) if (app_found)
add_line = 1; add_line = 1;
t.tm_mday++; t.tm_mday++;
mktime(&t); mktime (&t);
} }
} else { /* a date was entered */ }
if (parse_date(ddate, conf->input_datefmt, else
&day.yyyy, &day.mm, &day.dd)) { { /* a date was entered */
app_found = app_arg(add_line, &day, 0, print_note, conf); if (parse_date (ddate, conf->input_datefmt, &day.yyyy, &day.mm, &day.dd))
} else { {
fputs(_("Argument to the '-d' flag is not valid\n"), app_found = app_arg (add_line, &day, 0, print_note, conf);
stdout); }
else
{
fputs (_("Argument to the '-d' flag is not valid\n"), stdout);
char outstr[BUFSIZ]; char outstr[BUFSIZ];
snprintf(outstr, BUFSIZ, "Possible argument format are: '%s' or 'n'\n", snprintf (outstr, BUFSIZ,
DATEFMT_DESC(conf->input_datefmt)); "Possible argument format are: '%s' or 'n'\n",
fputs(_(outstr), stdout); DATEFMT_DESC (conf->input_datefmt));
fputs(_("\nFor more information, type '?' from within Calcurse, or read the manpage.\n"), fputs (_(outstr), stdout);
stdout); fputs (_("\nFor more information, type '?' from within Calcurse, "
fputs "or read the manpage.\n"),
(_("Mail bug reports and suggestions to <calcurse@culot.org>.\n"),
stdout); stdout);
fputs (_("Mail bug reports and suggestions to "
"<calcurse@culot.org>.\n"), stdout);
} }
} }
} }
@ -439,7 +465,7 @@ date_arg(char *ddate, int add_line, int print_note, conf_t *conf)
* routines to handle those arguments. Also initialize the data paths. * routines to handle those arguments. Also initialize the data paths.
*/ */
int int
parse_args(int argc, char **argv, conf_t *conf) parse_args (int argc, char **argv, conf_t *conf)
{ {
int ch, add_line = 0; int ch, add_line = 0;
int unknown_flag = 0, app_found = 0; int unknown_flag = 0, app_found = 0;
@ -474,8 +500,10 @@ parse_args(int argc, char **argv, conf_t *conf)
{NULL, no_argument, NULL, 0} {NULL, no_argument, NULL, 0}
}; };
while ((ch = getopt_long(argc, argv, optstr, longopts, NULL)) != -1) { while ((ch = getopt_long (argc, argv, optstr, longopts, NULL)) != -1)
switch (ch) { {
switch (ch)
{
case 'a': case 'a':
aflag = 1; aflag = 1;
multiple_flag++; multiple_flag++;
@ -509,14 +537,17 @@ parse_args(int argc, char **argv, conf_t *conf)
multiple_flag++; multiple_flag++;
load_data++; load_data++;
add_line = 1; add_line = 1;
if (optarg != NULL) { if (optarg != NULL)
tnum = atoi(optarg); {
if (tnum < 1 || tnum > 9) { tnum = atoi (optarg);
usage(); if (tnum < 1 || tnum > 9)
usage_try(); {
return EXIT_FAILURE; usage ();
usage_try ();
return (EXIT_FAILURE);
} }
} else }
else
tnum = 0; tnum = 0;
break; break;
case 'v': case 'v':
@ -528,8 +559,8 @@ parse_args(int argc, char **argv, conf_t *conf)
load_data++; load_data++;
break; break;
default: default:
usage(); usage ();
usage_try(); usage_try ();
unknown_flag = 1; unknown_flag = 1;
non_interactive = 1; non_interactive = 1;
/* NOTREACHED */ /* NOTREACHED */
@ -538,60 +569,80 @@ parse_args(int argc, char **argv, conf_t *conf)
argc -= optind; argc -= optind;
argv += optind; argv += optind;
if (argc >= 1) { /* incorrect arguments */ if (argc >= 1)
usage(); {
usage_try(); usage ();
return EXIT_FAILURE; usage_try ();
} else { return (EXIT_FAILURE);
if (unknown_flag) { /* Incorrect arguments */
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) { else
notify_init_vars(); {
custom_load_conf(conf, 0); if (unknown_flag)
io_export_data(IO_EXPORT_NONINTERACTIVE, conf); {
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; non_interactive = 1;
return (non_interactive); return (non_interactive);
} }
if (tflag) { if (tflag)
todo_arg(tnum, Nflag); {
todo_arg (tnum, Nflag);
non_interactive = 1; non_interactive = 1;
} }
if (nflag) { if (nflag)
next_arg(); {
next_arg ();
non_interactive = 1; non_interactive = 1;
} }
if (dflag) { if (dflag)
notify_init_vars(); {
vars_init(conf); notify_init_vars ();
custom_load_conf(conf, 0); vars_init (conf);
date_arg(ddate, add_line, Nflag, conf); custom_load_conf (conf, 0);
date_arg (ddate, add_line, Nflag, conf);
non_interactive = 1; non_interactive = 1;
} else if (aflag) { }
else if (aflag)
{
date_t day; date_t day;
day.dd = day.mm = day.yyyy = 0; day.dd = day.mm = day.yyyy = 0;
notify_init_vars(); notify_init_vars ();
vars_init(conf); vars_init (conf);
custom_load_conf(conf, 0); custom_load_conf (conf, 0);
app_found = app_arg(add_line, &day, 0, Nflag, conf); app_found = app_arg (add_line, &day, 0, Nflag, conf);
non_interactive = 1; non_interactive = 1;
} }
} else { }
else
{
non_interactive = 0; non_interactive = 0;
io_init(cfile); io_init (cfile);
no_file = io_check_data_files(); no_file = io_check_data_files ();
} }
return (non_interactive); return (non_interactive);
} }

View File

@ -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 * Calcurse - text-based organizer
@ -27,6 +27,6 @@
#ifndef CALCURSE_ARGS_H #ifndef CALCURSE_ARGS_H
#define 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 */ #endif /* CALCURSE_ARGS_H */

View File

@ -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 * Calcurse - text-based organizer
@ -51,7 +51,7 @@
* All of the commands are documented within an online help system. * All of the commands are documented within an online help system.
*/ */
int int
main(int argc, char **argv) main (int argc, char **argv)
{ {
conf_t conf; conf_t conf;
day_items_nb_t inday; day_items_nb_t inday;
@ -77,134 +77,140 @@ main(int argc, char **argv)
#endif /* ENABLE_NLS */ #endif /* ENABLE_NLS */
/* Thread-safe data structure init */ /* Thread-safe data structure init */
apoint_llist_init(); apoint_llist_init ();
recur_apoint_llist_init(); recur_apoint_llist_init ();
/* /*
* Begin by parsing and handling command line arguments. * Begin by parsing and handling command line arguments.
* The data path is also initialized here. * The data path is also initialized here.
*/ */
non_interactive = parse_args(argc, argv, &conf); non_interactive = parse_args (argc, argv, &conf);
if (non_interactive) if (non_interactive)
return (EXIT_SUCCESS); return (EXIT_SUCCESS);
/* Begin of interactive mode with ncurses interface. */ /* Begin of interactive mode with ncurses interface. */
sigs_init(&sigact); /* signal handling init */ sigs_init (&sigact); /* signal handling init */
initscr(); /* start the curses mode */ initscr (); /* start the curses mode */
cbreak(); /* control chars generate a signal */ cbreak (); /* control chars generate a signal */
noecho(); /* controls echoing of typed chars */ noecho (); /* controls echoing of typed chars */
curs_set(0); /* make cursor invisible */ curs_set (0); /* make cursor invisible */
calendar_set_current_date(); calendar_set_current_date ();
notify_init_vars(); notify_init_vars ();
wins_get_config(); wins_get_config ();
/* Check if terminal supports color. */ /* Check if terminal supports color. */
if (has_colors()) { if (has_colors ())
{
colorize = true; colorize = true;
background = COLOR_BLACK; background = COLOR_BLACK;
foreground = COLOR_WHITE; foreground = COLOR_WHITE;
start_color(); start_color ();
#ifdef NCURSES_VERSION #ifdef NCURSES_VERSION
if (use_default_colors() != ERR) { if (use_default_colors () != ERR)
{
background = -1; background = -1;
foreground = -1; foreground = -1;
} }
#endif /* NCURSES_VERSION */ #endif /* NCURSES_VERSION */
/* Color assignment */ /* Color assignment */
init_pair(COLR_RED, COLOR_RED, background); init_pair (COLR_RED, COLOR_RED, background);
init_pair(COLR_GREEN, COLOR_GREEN, background); init_pair (COLR_GREEN, COLOR_GREEN, background);
init_pair(COLR_YELLOW, COLOR_YELLOW, background); init_pair (COLR_YELLOW, COLOR_YELLOW, background);
init_pair(COLR_BLUE, COLOR_BLUE, background); init_pair (COLR_BLUE, COLOR_BLUE, background);
init_pair(COLR_MAGENTA, COLOR_MAGENTA, background); init_pair (COLR_MAGENTA, COLOR_MAGENTA, background);
init_pair(COLR_CYAN, COLOR_CYAN, background); init_pair (COLR_CYAN, COLOR_CYAN, background);
init_pair(COLR_DEFAULT, foreground, background); init_pair (COLR_DEFAULT, foreground, background);
init_pair(COLR_HIGH, COLOR_BLACK, COLOR_GREEN); init_pair (COLR_HIGH, COLOR_BLACK, COLOR_GREEN);
init_pair(COLR_CUSTOM, COLOR_RED, background); init_pair (COLR_CUSTOM, COLOR_RED, background);
} else { }
else
{
colorize = false; colorize = false;
background = COLOR_BLACK; background = COLOR_BLACK;
} }
vars_init(&conf); vars_init (&conf);
wins_init(); wins_init ();
wins_slctd_init(); wins_slctd_init ();
notify_init_bar(); notify_init_bar ();
reset_status_page(); reset_status_page ();
/* /*
* Read the data from files : first the user * Read the data from files : first the user
* configuration (the display is then updated), and then * configuration (the display is then updated), and then
* the todo list, appointments and events. * the todo list, appointments and events.
*/ */
no_data_file = io_check_data_files(); no_data_file = io_check_data_files ();
custom_load_conf(&conf, background); custom_load_conf (&conf, background);
erase_status_bar(); erase_status_bar ();
io_load_todo(); io_load_todo ();
io_load_app(); io_load_app ();
wins_reinit(); wins_reinit ();
if (notify_bar()) { if (notify_bar ())
notify_start_main_thread(); {
notify_check_next_app(); notify_start_main_thread ();
notify_check_next_app ();
} }
wins_update(); wins_update ();
io_startup_screen(conf.skip_system_dialogs, no_data_file); io_startup_screen (conf.skip_system_dialogs, no_data_file);
inday = *day_process_storage(0, day_changed, &inday); inday = *day_process_storage (0, day_changed, &inday);
wins_slctd_set(CAL); wins_slctd_set (CAL);
wins_update(); wins_update ();
calendar_start_date_thread(); calendar_start_date_thread ();
/* User input */ /* User input */
for (;;) { for (;;)
{
do_update = true; do_update = true;
ch = wgetch(win[STA].p); ch = wgetch (win[STA].p);
switch (ch)
switch (ch) { {
case ERR: case ERR:
do_update = false; do_update = false;
break; break;
case CTRL('R'): case CTRL ('R'):
case KEY_RESIZE: case KEY_RESIZE:
do_update = false; do_update = false;
wins_reset(); wins_reset ();
break; break;
case 9: /* The TAB key was hit. */ case 9: /* The TAB key was hit. */
reset_status_page(); reset_status_page ();
/* Save previously highlighted event. */ /* Save previously highlighted event. */
switch (wins_slctd()) { switch (wins_slctd ())
{
case TOD: case TOD:
sav_hilt_tod = todo_hilt(); sav_hilt_tod = todo_hilt ();
todo_hilt_set(0); todo_hilt_set (0);
break; break;
case APP: case APP:
sav_hilt_app = apoint_hilt(); sav_hilt_app = apoint_hilt ();
apoint_hilt_set(0); apoint_hilt_set (0);
break; break;
default: default:
break; break;
} }
wins_slctd_next(); wins_slctd_next ();
/* Select the event to highlight. */ /* Select the event to highlight. */
switch (wins_slctd()) { switch (wins_slctd ())
{
case TOD: case TOD:
if ((sav_hilt_tod == 0) && (todo_nb() != 0)) if ((sav_hilt_tod == 0) && (todo_nb () != 0))
todo_hilt_set(1); todo_hilt_set (1);
else else
todo_hilt_set(sav_hilt_tod); todo_hilt_set (sav_hilt_tod);
break; break;
case APP: case APP:
if ((sav_hilt_app == 0) && if ((sav_hilt_app == 0)
((inday.nb_events + inday.nb_apoints) != 0)) && ((inday.nb_events + inday.nb_apoints) != 0))
apoint_hilt_set(1); apoint_hilt_set (1);
else else
apoint_hilt_set(sav_hilt_app); apoint_hilt_set (sav_hilt_app);
break; break;
default: default:
break; break;
@ -213,89 +219,91 @@ main(int argc, char **argv)
case 'O': case 'O':
case 'o': case 'o':
other_status_page(wins_slctd()); other_status_page (wins_slctd ());
break; break;
case 'G': case 'G':
case 'g': /* Goto function */ case 'g': /* Goto function */
erase_status_bar(); erase_status_bar ();
calendar_set_current_date(); calendar_set_current_date ();
calendar_change_day(conf.input_datefmt); calendar_change_day (conf.input_datefmt);
do_storage = true; do_storage = true;
day_changed = true; day_changed = true;
break; break;
case 'V': case 'V':
case 'v': /* View function */ case 'v': /* View function */
if ((wins_slctd() == APP) && (apoint_hilt() != 0)) if ((wins_slctd () == APP) && (apoint_hilt () != 0))
day_popup_item(); day_popup_item ();
else if ((wins_slctd() == TOD) && (todo_hilt() != 0)) else if ((wins_slctd () == TOD) && (todo_hilt () != 0))
item_in_popup(NULL, NULL, todo_saved_mesg(), item_in_popup (NULL, NULL, todo_saved_mesg (), _("To do :"));
_("To do :"));
break; break;
case 'C': case 'C':
case 'c': /* Configuration menu */ case 'c': /* Configuration menu */
erase_status_bar(); erase_status_bar ();
config_bar(); config_bar ();
while ((ch = wgetch(win[STA].p)) != 'q') { while ((ch = wgetch (win[STA].p)) != 'q')
switch (ch) { {
switch (ch)
{
case 'C': case 'C':
case 'c': case 'c':
if (has_colors()) if (has_colors ())
custom_color_config(); custom_color_config ();
else { else
{
colorize = false; colorize = false;
erase_status_bar(); erase_status_bar ();
mvwprintw(win[STA].p, 0, 0, mvwprintw (win[STA].p, 0, 0, _(no_color_support));
_(no_color_support)); wgetch (win[STA].p);
wgetch(win[STA].p);
} }
break; break;
case 'L': case 'L':
case 'l': case 'l':
layout_config(); layout_config ();
break; break;
case 'G': case 'G':
case 'g': case 'g':
custom_general_config(&conf); custom_general_config (&conf);
break; break;
case 'N': case 'N':
case 'n': case 'n':
notify_config_bar(); notify_config_bar ();
break; break;
} }
wins_reset(); wins_reset ();
wins_update(); wins_update ();
do_storage = true; do_storage = true;
erase_status_bar(); erase_status_bar ();
config_bar(); config_bar ();
} }
wins_update(); wins_update ();
break; break;
case CTRL('A'): /* Add an app, whatever panel selected */ case CTRL ('A'): /* Add an app, whatever panel selected */
apoint_add(); apoint_add ();
do_storage = true; do_storage = true;
break; break;
case CTRL('T'): /* Add a todo, whatever panel selected */ case CTRL ('T'): /* Add a todo, whatever panel selected */
todo_new_item(); todo_new_item ();
if (todo_hilt() == 0 && todo_nb() == 1) if (todo_hilt () == 0 && todo_nb () == 1)
todo_hilt_increase(); todo_hilt_increase ();
break; break;
case 'A': case 'A':
case 'a': /* Add an item */ case 'a': /* Add an item */
switch (wins_slctd()) { switch (wins_slctd ())
{
case APP: case APP:
apoint_add(); apoint_add ();
do_storage = true; do_storage = true;
break; break;
case TOD: case TOD:
todo_new_item(); todo_new_item ();
if (todo_hilt() == 0 && todo_nb() == 1) if (todo_hilt () == 0 && todo_nb () == 1)
todo_hilt_increase(); todo_hilt_increase ();
break; break;
default: default:
break; break;
@ -304,121 +312,126 @@ main(int argc, char **argv)
case 'E': case 'E':
case 'e': /* Edit an existing item */ case 'e': /* Edit an existing item */
if (wins_slctd() == APP && apoint_hilt() != 0) if (wins_slctd () == APP && apoint_hilt () != 0)
day_edit_item(&conf); day_edit_item (&conf);
else if (wins_slctd() == TOD && todo_hilt() != 0) else if (wins_slctd () == TOD && todo_hilt () != 0)
todo_edit_item(); todo_edit_item ();
do_storage = true; do_storage = true;
break; break;
case 'D': case 'D':
case 'd': /* Delete an item */ case 'd': /* Delete an item */
if (wins_slctd() == APP && apoint_hilt() != 0) if (wins_slctd () == APP && apoint_hilt () != 0)
apoint_delete(&conf, &inday.nb_events, apoint_delete (&conf, &inday.nb_events, &inday.nb_apoints);
&inday.nb_apoints); else if (wins_slctd () == TOD && todo_hilt () != 0)
else if (wins_slctd() == TOD && todo_hilt() != 0) todo_delete (&conf);
todo_delete(&conf);
do_storage = true; do_storage = true;
break; break;
case 'R': case 'R':
case 'r': case 'r':
if (wins_slctd() == APP && apoint_hilt() != 0) if (wins_slctd () == APP && apoint_hilt () != 0)
recur_repeat_item(&conf); recur_repeat_item (&conf);
do_storage = true; do_storage = true;
break; break;
case '!': case '!':
if (wins_slctd() == APP && apoint_hilt() != 0) if (wins_slctd () == APP && apoint_hilt () != 0)
apoint_switch_notify(); apoint_switch_notify ();
do_storage = true; do_storage = true;
break; break;
case '+': case '+':
case '-': case '-':
if (wins_slctd() == TOD && todo_hilt() != 0) { if (wins_slctd () == TOD && todo_hilt () != 0)
todo_chg_priority(ch); {
if (todo_hilt_pos() < 0) todo_chg_priority (ch);
todo_set_first(todo_hilt()); if (todo_hilt_pos () < 0)
else if (todo_hilt_pos() >= win[TOD].h - 4) todo_set_first (todo_hilt ());
todo_set_first(todo_hilt() - else if (todo_hilt_pos () >= win[TOD].h - 4)
win[TOD].h + 5); todo_set_first (todo_hilt () - win[TOD].h + 5);
} }
break; break;
case 'N': case 'N':
case 'n': case 'n':
/* Attach a note to an item, create it if necessary */ /* Attach a note to an item, create it if necessary */
if (wins_slctd() == APP && apoint_hilt() != 0) if (wins_slctd () == APP && apoint_hilt () != 0)
day_edit_note(conf.editor); day_edit_note (conf.editor);
else if (wins_slctd() == TOD && todo_hilt() != 0) else if (wins_slctd () == TOD && todo_hilt () != 0)
todo_edit_note(conf.editor); todo_edit_note (conf.editor);
do_storage = true; do_storage = true;
break; break;
case '>': case '>':
/* View a note previously attached to an item */ /* View a note previously attached to an item */
if (wins_slctd() == APP && apoint_hilt() != 0) if (wins_slctd () == APP && apoint_hilt () != 0)
day_view_note(conf.pager); day_view_note (conf.pager);
else if (wins_slctd() == TOD && todo_hilt() != 0) else if (wins_slctd () == TOD && todo_hilt () != 0)
todo_view_note(conf.pager); todo_view_note (conf.pager);
break; break;
case '?': /* Online help system */ case '?': /* Online help system */
status_bar(); status_bar ();
help_screen(); help_screen ();
break; break;
case 'S': case 'S':
case 's': /* Save function */ case 's': /* Save function */
io_save_cal(&conf); io_save_cal (&conf);
break; break;
case 'X': case 'X':
case 'x': /* Export function */ case 'x': /* Export function */
io_export_data(IO_EXPORT_INTERACTIVE, &conf); io_export_data (IO_EXPORT_INTERACTIVE, &conf);
break; break;
case (261): /* right arrow */ case (261): /* right arrow */
case ('L'): case ('L'):
case ('l'): case ('l'):
case CTRL('L'): case CTRL ('L'):
if (wins_slctd() == CAL || ch == CTRL('L')) { if (wins_slctd () == CAL || ch == CTRL ('L'))
{
do_storage = true; do_storage = true;
day_changed = true; day_changed = true;
calendar_move(RIGHT); calendar_move (RIGHT);
} }
break; break;
case (260): /* left arrow */ case (260): /* left arrow */
case ('H'): case ('H'):
case ('h'): case ('h'):
case CTRL('H'): case CTRL ('H'):
if (wins_slctd() == CAL || ch == CTRL('H')) { if (wins_slctd () == CAL || ch == CTRL ('H'))
{
do_storage = true; do_storage = true;
day_changed = true; day_changed = true;
calendar_move(LEFT); calendar_move (LEFT);
} }
break; break;
case (259): /* up arrow */ case (259): /* up arrow */
case ('K'): case ('K'):
case ('k'): case ('k'):
case CTRL('K'): case CTRL ('K'):
if (wins_slctd() == CAL || ch == CTRL('K')) { if (wins_slctd () == CAL || ch == CTRL ('K'))
{
do_storage = true; do_storage = true;
day_changed = true; day_changed = true;
calendar_move(UP); calendar_move (UP);
} else { }
if ((wins_slctd() == APP) && else
(apoint_hilt() > 1)) { {
apoint_hilt_decrease(); if ((wins_slctd () == APP) && (apoint_hilt () > 1))
apoint_scroll_pad_up(inday.nb_events); {
} else if ((wins_slctd() == TOD) && apoint_hilt_decrease ();
(todo_hilt() > 1)) { apoint_scroll_pad_up (inday.nb_events);
todo_hilt_decrease(); }
if (todo_hilt_pos() < 0) else if ((wins_slctd () == TOD) && (todo_hilt () > 1))
todo_first_decrease(); {
todo_hilt_decrease ();
if (todo_hilt_pos () < 0)
todo_first_decrease ();
} }
} }
break; break;
@ -426,24 +439,26 @@ main(int argc, char **argv)
case (258): /* down arrow */ case (258): /* down arrow */
case ('J'): case ('J'):
case ('j'): case ('j'):
case CTRL('J'): case CTRL ('J'):
if (wins_slctd() == CAL || ch == CTRL('J')) { if (wins_slctd () == CAL || ch == CTRL ('J'))
{
do_storage = true; do_storage = true;
day_changed = true; day_changed = true;
calendar_move(DOWN); 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) && else
(todo_hilt() < todo_nb())) { {
todo_hilt_increase(); if ((wins_slctd () == APP) &&
if (todo_hilt_pos() == win[TOD].h - 4) (apoint_hilt () < inday.nb_events + inday.nb_apoints))
todo_first_increase(); {
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; break;
@ -451,19 +466,22 @@ main(int argc, char **argv)
case ('Q'): /* Quit calcurse :( */ case ('Q'): /* Quit calcurse :( */
case ('q'): case ('q'):
if (conf.auto_save) if (conf.auto_save)
io_save_cal(&conf); io_save_cal (&conf);
if (conf.confirm_quit) { if (conf.confirm_quit)
status_mesg(_(quit_message), choices); {
ch = wgetch(win[STA].p); status_mesg (_(quit_message), choices);
if ( ch == 'y' ) ch = wgetch (win[STA].p);
exit_calcurse(EXIT_SUCCESS); if (ch == 'y')
else { exit_calcurse (EXIT_SUCCESS);
erase_status_bar(); else
{
erase_status_bar ();
break; break;
} }
} else }
exit_calcurse(EXIT_SUCCESS); else
exit_calcurse (EXIT_SUCCESS);
break; break;
default: default:
@ -471,19 +489,21 @@ main(int argc, char **argv)
break; break;
} }
if (do_storage) { if (do_storage)
inday = *day_process_storage(calendar_get_slctd_day(), {
inday = *day_process_storage (calendar_get_slctd_day (),
day_changed, &inday); day_changed, &inday);
do_storage = !do_storage; do_storage = !do_storage;
if (day_changed) { if (day_changed)
{
sav_hilt_app = 0; sav_hilt_app = 0;
day_changed = !day_changed; day_changed = !day_changed;
if ((wins_slctd() == APP) && if ((wins_slctd () == APP) &&
(inday.nb_events + inday.nb_apoints != 0)) (inday.nb_events + inday.nb_apoints != 0))
apoint_hilt_set(1); apoint_hilt_set (1);
} }
} }
if (do_update) if (do_update)
wins_update(); wins_update ();
} }
} }

View File

@ -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 * Calcurse - text-based organizer
@ -63,62 +63,65 @@ static pthread_t calendar_t_date;
/* Thread needed to update current date in calendar. */ /* Thread needed to update current date in calendar. */
static void * static void *
calendar_date_thread(void *arg) calendar_date_thread (void *arg)
{ {
time_t now, tomorrow; time_t now, tomorrow;
for (;;) { for (;;)
tomorrow = (time_t)(get_today() + DAYINSEC); {
tomorrow = (time_t) (get_today () + DAYINSEC);
while ((now = time(NULL)) < tomorrow) { while ((now = time (NULL)) < tomorrow)
sleep(tomorrow - now); {
sleep (tomorrow - now);
} }
calendar_set_current_date(); calendar_set_current_date ();
calendar_update_panel(win[CAL].p); calendar_update_panel (win[CAL].p);
} }
pthread_exit((void*) 0); pthread_exit ((void *) 0);
} }
/* Launch the calendar date thread. */ /* Launch the calendar date thread. */
void void
calendar_start_date_thread(void) calendar_start_date_thread (void)
{ {
pthread_create(&calendar_t_date, NULL, calendar_date_thread, NULL); pthread_create (&calendar_t_date, NULL, calendar_date_thread, NULL);
return; return;
} }
/* Stop the calendar date thread. */ /* Stop the calendar date thread. */
void void
calendar_stop_date_thread(void) calendar_stop_date_thread (void)
{ {
pthread_cancel(calendar_t_date); pthread_cancel (calendar_t_date);
return; return;
} }
/* Set static variable today to current date */ /* Set static variable today to current date */
void void
calendar_set_current_date(void) calendar_set_current_date (void)
{ {
time_t timer; time_t timer;
struct tm *tm; struct tm *tm;
timer = time(NULL); timer = time (NULL);
tm = localtime(&timer); tm = localtime (&timer);
pthread_mutex_lock(&date_thread_mutex); pthread_mutex_lock (&date_thread_mutex);
today.dd = tm->tm_mday; today.dd = tm->tm_mday;
today.mm = tm->tm_mon + 1; today.mm = tm->tm_mon + 1;
today.yyyy = tm->tm_year + 1900; today.yyyy = tm->tm_year + 1900;
pthread_mutex_unlock(&date_thread_mutex); pthread_mutex_unlock (&date_thread_mutex);
} }
/* Needed to display sunday or monday as the first day of week in calendar. */ /* Needed to display sunday or monday as the first day of week in calendar. */
void void
calendar_set_first_day_of_week(wday_e first_day) calendar_set_first_day_of_week (wday_e first_day)
{ {
switch (first_day) { switch (first_day)
{
case SUNDAY: case SUNDAY:
week_begins_on_monday = false; week_begins_on_monday = false;
break; break;
@ -126,7 +129,7 @@ calendar_set_first_day_of_week(wday_e first_day)
week_begins_on_monday = true; week_begins_on_monday = true;
break; break;
default: default:
fputs(_("ERROR in calendar_set_first_day_of_week\n"), stderr); fputs (_("ERROR in calendar_set_first_day_of_week\n"), stderr);
week_begins_on_monday = false; week_begins_on_monday = false;
/* NOTREACHED */ /* NOTREACHED */
} }
@ -134,84 +137,84 @@ calendar_set_first_day_of_week(wday_e first_day)
/* Swap first day of week in calendar. */ /* Swap first day of week in calendar. */
void void
calendar_change_first_day_of_week(void) calendar_change_first_day_of_week (void)
{ {
week_begins_on_monday = !week_begins_on_monday; week_begins_on_monday = !week_begins_on_monday;
} }
/* Return true if week begins on monday, false otherwise. */ /* Return true if week begins on monday, false otherwise. */
bool 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. */ /* Fill in the given variable with the current date. */
void void
calendar_store_current_date(date_t *date) calendar_store_current_date (date_t *date)
{ {
pthread_mutex_lock(&date_thread_mutex); pthread_mutex_lock (&date_thread_mutex);
*date = today; *date = today;
pthread_mutex_unlock(&date_thread_mutex); pthread_mutex_unlock (&date_thread_mutex);
} }
/* This is to start at the current date in calendar. */ /* This is to start at the current date in calendar. */
void void
calendar_init_slctd_day(void) calendar_init_slctd_day (void)
{ {
calendar_store_current_date(&slctd_day); calendar_store_current_date (&slctd_day);
} }
/* Return the selected day in calendar */ /* Return the selected day in calendar */
date_t * 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) */ /* Returned value represents the selected day in calendar (in seconds) */
long long
calendar_get_slctd_day_sec(void) calendar_get_slctd_day_sec (void)
{ {
return (date2sec(slctd_day, 0, 0)); return (date2sec (slctd_day, 0, 0));
} }
static int static int
isBissextile(unsigned year) 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 static unsigned
months_to_days(unsigned month) months_to_days (unsigned month)
{ {
return ((month * 3057 - 3007) / 100); return ((month * 3057 - 3007) / 100);
} }
static long static long
years_to_days(unsigned year) years_to_days (unsigned year)
{ {
return (year * 365L + year / 4 - year / 100 + year / 400); return (year * 365L + year / 4 - year / 100 + year / 400);
} }
static long static long
ymd_to_scalar(unsigned year, unsigned month, unsigned day) ymd_to_scalar (unsigned year, unsigned month, unsigned day)
{ {
long scalar; long scalar;
scalar = day + months_to_days(month); scalar = day + months_to_days (month);
if (month > 2) if (month > 2)
scalar -= isBissextile(year) ? 1 : 2; scalar -= isBissextile (year) ? 1 : 2;
year--; year--;
scalar += years_to_days(year); scalar += years_to_days (year);
return (scalar); return (scalar);
} }
/* Function used to display the calendar panel. */ /* Function used to display the calendar panel. */
void void
calendar_update_panel(WINDOW *cwin) calendar_update_panel (WINDOW *cwin)
{ {
date_t current_day, check_day; date_t current_day, check_day;
int c_day, c_day_1, day_1_sav, numdays, j; int c_day, c_day_1, day_1_sav, numdays, j;
@ -222,11 +225,11 @@ calendar_update_panel(WINDOW *cwin)
int sunday_first = 0; int sunday_first = 0;
/* inits */ /* inits */
calendar_store_current_date(&current_day); calendar_store_current_date (&current_day);
erase_window_part(cwin, 1, title_lines, CALWIDTH - 2, CALHEIGHT - 2); erase_window_part (cwin, 1, title_lines, CALWIDTH - 2, CALHEIGHT - 2);
mo = slctd_day.mm; mo = slctd_day.mm;
yr = slctd_day.yyyy; yr = slctd_day.yyyy;
if (!calendar_week_begins_on_monday()) if (!calendar_week_begins_on_monday ())
sunday_first = 1; sunday_first = 1;
/* offset for centering calendar in window */ /* offset for centering calendar in window */
@ -235,93 +238,93 @@ calendar_update_panel(WINDOW *cwin)
/* checking the number of days in february */ /* checking the number of days in february */
numdays = days[mo - 1]; numdays = days[mo - 1];
if (2 == mo && isBissextile(yr)) if (2 == mo && isBissextile (yr))
++numdays; ++numdays;
/* /*
* the first calendar day will be monday or sunday, depending on * the first calendar day will be monday or sunday, depending on
* 'week_begins_on_monday' value * 'week_begins_on_monday' value
*/ */
c_day_1 = c_day_1 = (int) ((ymd_to_scalar (yr, mo, 1 + sunday_first) - (long) 1) % 7L);
(int)((ymd_to_scalar(yr, mo, 1 + sunday_first) - (long)1) % 7L);
/* Write the current month and year on top of the calendar */ /* Write the current month and year on top of the calendar */
custom_apply_attr(cwin, ATTR_HIGH); custom_apply_attr (cwin, ATTR_HIGH);
mvwprintw(cwin, ofs_y, mvwprintw (cwin, ofs_y, (CALWIDTH - (strlen (_(monthnames[mo - 1])) + 5)) / 2,
(CALWIDTH - (strlen(_(monthnames[mo - 1])) + 5)) / 2,
"%s %d", _(monthnames[mo - 1]), slctd_day.yyyy); "%s %d", _(monthnames[mo - 1]), slctd_day.yyyy);
custom_remove_attr(cwin, ATTR_HIGH); custom_remove_attr (cwin, ATTR_HIGH);
++ofs_y; ++ofs_y;
/* print the days, with regards to the first day of the week */ /* print the days, with regards to the first day of the week */
custom_apply_attr(cwin, ATTR_HIGH); custom_apply_attr (cwin, ATTR_HIGH);
for (j = 0; j < 7; j++) { for (j = 0; j < 7; j++)
mvwprintw(cwin, ofs_y, ofs_x + 4 * j, "%s", {
mvwprintw (cwin, ofs_y, ofs_x + 4 * j, "%s",
_(daynames[1 + j - sunday_first])); _(daynames[1 + j - sunday_first]));
} }
custom_remove_attr(cwin, ATTR_HIGH); custom_remove_attr (cwin, ATTR_HIGH);
day_1_sav = (c_day_1 + 1) * 3 + c_day_1 - 7; day_1_sav = (c_day_1 + 1) * 3 + c_day_1 - 7;
for (c_day = 1; c_day <= numdays; ++c_day, ++c_day_1, c_day_1 %= 7) { for (c_day = 1; c_day <= numdays; ++c_day, ++c_day_1, c_day_1 %= 7)
{
check_day.dd = c_day; check_day.dd = c_day;
check_day.mm = slctd_day.mm; check_day.mm = slctd_day.mm;
check_day.yyyy = slctd_day.yyyy; check_day.yyyy = slctd_day.yyyy;
/* check if the day contains an event or an appointment */ /* check if the day contains an event or an appointment */
item_this_day = item_this_day = day_check_if_item (check_day);
day_check_if_item(check_day);
/* Go to next line, the week is over. */ /* Go to next line, the week is over. */
if (!c_day_1 && 1 != c_day) { if (!c_day_1 && 1 != c_day)
{
++ofs_y; ++ofs_y;
ofs_x = 2 - day_1_sav - 4 * c_day - 1; ofs_x = 2 - day_1_sav - 4 * c_day - 1;
} }
/* This is today, so print it in yellow. */ /* This is today, so print it in yellow. */
if (c_day == current_day.dd && current_day.mm == slctd_day.mm if (c_day == current_day.dd && current_day.mm == slctd_day.mm
&& current_day.yyyy == slctd_day.yyyy && && current_day.yyyy == slctd_day.yyyy
current_day.dd != slctd_day.dd) { && current_day.dd != slctd_day.dd)
{
custom_apply_attr(cwin, ATTR_LOWEST); custom_apply_attr (cwin, ATTR_LOWEST);
mvwprintw(cwin, ofs_y + 1, mvwprintw (cwin, ofs_y + 1,
ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day); ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day);
custom_remove_attr(cwin, ATTR_LOWEST); 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);
} }
wnoutrefresh(cwin); 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);
}
wnoutrefresh (cwin);
} }
/* /*
@ -332,7 +335,7 @@ calendar_update_panel(WINDOW *cwin)
* with the newly selected date. * with the newly selected date.
*/ */
void void
calendar_change_day(int datefmt) calendar_change_day (int datefmt)
{ {
#define LDAY 11 #define LDAY 11
char selected_day[LDAY] = ""; char selected_day[LDAY] = "";
@ -341,46 +344,44 @@ calendar_change_day(int datefmt)
int dday, dmonth, dyear; int dday, dmonth, dyear;
int wrong_day = 1; int wrong_day = 1;
char *mesg_line1 = char *mesg_line1 =
_("The day you entered is not valid (should be between 01/01/1902 and 12/31/2037)"); _("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 *mesg_line2 = _("Press [ENTER] to continue");
char *request_date = char *request_date = "Enter the day to go to [ENTER for today] : %s";
"Enter the day to go to [ENTER for today] : %s";
while (wrong_day) { while (wrong_day)
snprintf(outstr, BUFSIZ, request_date, {
DATEFMT_DESC(datefmt)); snprintf (outstr, BUFSIZ, request_date, DATEFMT_DESC (datefmt));
status_mesg(_(outstr), ""); status_mesg (_(outstr), "");
if (getstring(win[STA].p, selected_day, LDAY, 0, 1) == if (getstring (win[STA].p, selected_day, LDAY, 0, 1) == GETSTRING_ESC)
GETSTRING_ESC)
return; return;
else { else
if (strlen(selected_day) == 0) { {
calendar_store_current_date(&today); if (strlen (selected_day) == 0)
{
calendar_store_current_date (&today);
/* go to today */ /* go to today */
wrong_day = 0; wrong_day = 0;
slctd_day.dd = today.dd; slctd_day.dd = today.dd;
slctd_day.mm = today.mm; slctd_day.mm = today.mm;
slctd_day.yyyy = today.yyyy; slctd_day.yyyy = today.yyyy;
}
} else if (strlen(selected_day) != LDAY - 1) { else if (strlen (selected_day) != LDAY - 1)
{
wrong_day = 1; wrong_day = 1;
}
} else if (parse_date(selected_day, datefmt, else if (parse_date (selected_day, datefmt, &dyear, &dmonth, &dday))
&dyear, &dmonth, &dday)) { {
wrong_day = 0; wrong_day = 0;
/* go to chosen day */ /* go to chosen day */
slctd_day.dd = dday; slctd_day.dd = dday;
slctd_day.mm = dmonth; slctd_day.mm = dmonth;
slctd_day.yyyy = dyear; slctd_day.yyyy = dyear;
} }
if (wrong_day)
if (wrong_day) { {
status_mesg(mesg_line1, mesg_line2); status_mesg (mesg_line1, mesg_line2);
wgetch(win[STA].p); wgetch (win[STA].p);
} }
} }
} }
@ -393,7 +394,7 @@ calendar_change_day(int datefmt)
* Returns 0 on success, 1 otherwise. * Returns 0 on success, 1 otherwise.
*/ */
int int
date_change(struct tm *date, int delta_month, int delta_day) date_change (struct tm *date, int delta_month, int delta_day)
{ {
struct tm t; struct tm t;
@ -401,56 +402,58 @@ date_change(struct tm *date, int delta_month, int delta_day)
t.tm_mon += delta_month; t.tm_mon += delta_month;
t.tm_mday += delta_day; t.tm_mday += delta_day;
if (mktime(&t) == -1) if (mktime (&t) == -1)
return (1); return (1);
else { else
{
*date = t; *date = t;
return (0); return (0);
} }
} }
void void
calendar_move(move_t move) calendar_move (move_t move)
{ {
int ret; int ret;
struct tm t; struct tm t;
memset(&t, 0, sizeof(struct tm)); memset (&t, 0, sizeof (struct tm));
t.tm_mday = slctd_day.dd; t.tm_mday = slctd_day.dd;
t.tm_mon = slctd_day.mm - 1; t.tm_mon = slctd_day.mm - 1;
t.tm_year = slctd_day.yyyy - 1900; t.tm_year = slctd_day.yyyy - 1900;
switch (move) { switch (move)
{
case UP: case UP:
if ((slctd_day.dd <= 7) && (slctd_day.mm == 1) && if ((slctd_day.dd <= 7) && (slctd_day.mm == 1)
(slctd_day.yyyy == 1902)) && (slctd_day.yyyy == 1902))
return; return;
ret = date_change(&t, 0, -WEEKINDAYS); ret = date_change (&t, 0, -WEEKINDAYS);
break; break;
case DOWN: case DOWN:
if ((slctd_day.dd > days[slctd_day.mm - 1] - 7) if ((slctd_day.dd > days[slctd_day.mm - 1] - 7)
&& (slctd_day.mm == 12) && (slctd_day.yyyy == 2037)) && (slctd_day.mm == 12) && (slctd_day.yyyy == 2037))
return; return;
ret = date_change(&t, 0, WEEKINDAYS); ret = date_change (&t, 0, WEEKINDAYS);
break; break;
case LEFT: case LEFT:
if ((slctd_day.dd == 1) && (slctd_day.mm == 1) && if ((slctd_day.dd == 1) && (slctd_day.mm == 1)
(slctd_day.yyyy == 1902)) && (slctd_day.yyyy == 1902))
return; return;
ret = date_change(&t, 0, -1); ret = date_change (&t, 0, -1);
break; break;
case RIGHT: case RIGHT:
if ((slctd_day.dd == 31) && (slctd_day.mm == 12) && if ((slctd_day.dd == 31) && (slctd_day.mm == 12)
(slctd_day.yyyy == 2037)) && (slctd_day.yyyy == 2037))
return; return;
ret = date_change(&t, 0, 1); ret = date_change (&t, 0, 1);
break; break;
default: default:
ret = 1; ret = 1;
/* NOTREACHED */ /* NOTREACHED */
} }
if (ret == 0)
if (ret == 0) { {
slctd_day.dd = t.tm_mday; slctd_day.dd = t.tm_mday;
slctd_day.mm = t.tm_mon + 1; slctd_day.mm = t.tm_mon + 1;
slctd_day.yyyy = t.tm_year + 1900; slctd_day.yyyy = t.tm_year + 1900;
@ -499,9 +502,9 @@ calendar_move(move_t move)
* convert degrees to radians * convert degrees to radians
*/ */
static double static double
dtor(double deg) dtor (double deg)
{ {
return(deg * M_PI / 180); return (deg * M_PI / 180);
} }
/* /*
@ -509,7 +512,7 @@ dtor(double deg)
* adjust value so 0 <= deg <= 360 * adjust value so 0 <= deg <= 360
*/ */
static void static void
adj360(double *deg) adj360 (double *deg)
{ {
for (;;) for (;;)
if (*deg < 0.0) if (*deg < 0.0)
@ -525,35 +528,35 @@ adj360(double *deg)
* return phase of the moon * return phase of the moon
*/ */
static double static double
potm(double days) potm (double days)
{ {
double N, Msol, Ec, LambdaSol, l, Mm, Ev, Ac, A3, Mmprime; double N, Msol, Ec, LambdaSol, l, Mm, Ev, Ac, A3, Mmprime;
double A4, lprime, V, ldprime, D, Nm; double A4, lprime, V, ldprime, D, Nm;
N = 360.0 * days / 365.242191; /* sec 46 #3 */ N = 360.0 * days / 365.242191; /* sec 46 #3 */
adj360(&N); adj360 (&N);
Msol = N + EPSILONg - RHOg; /* sec 46 #4 */ Msol = N + EPSILONg - RHOg; /* sec 46 #4 */
adj360(&Msol); adj360 (&Msol);
Ec = 360 / M_PI * ECCEN * sin(dtor(Msol)); /* sec 46 #5 */ Ec = 360 / M_PI * ECCEN * sin (dtor (Msol)); /* sec 46 #5 */
LambdaSol = N + Ec + EPSILONg; /* sec 46 #6 */ LambdaSol = N + Ec + EPSILONg; /* sec 46 #6 */
adj360(&LambdaSol); adj360 (&LambdaSol);
l = 13.1763966 * days + lzero; /* sec 65 #4 */ l = 13.1763966 * days + lzero; /* sec 65 #4 */
adj360(&l); adj360 (&l);
Mm = l - (0.1114041 * days) - Pzero; /* sec 65 #5 */ Mm = l - (0.1114041 * days) - Pzero; /* sec 65 #5 */
adj360(&Mm); adj360 (&Mm);
Nm = Nzero - (0.0529539 * days); /* sec 65 #6 */ Nm = Nzero - (0.0529539 * days); /* sec 65 #6 */
adj360(&Nm); adj360 (&Nm);
Ev = 1.2739 * sin(dtor(2*(l - LambdaSol) - Mm)); /* sec 65 #7 */ Ev = 1.2739 * sin (dtor (2 * (l - LambdaSol) - Mm)); /* sec 65 #7 */
Ac = 0.1858 * sin(dtor(Msol)); /* sec 65 #8 */ Ac = 0.1858 * sin (dtor (Msol)); /* sec 65 #8 */
A3 = 0.37 * sin(dtor(Msol)); A3 = 0.37 * sin (dtor (Msol));
Mmprime = Mm + Ev - Ac - A3; /* sec 65 #9 */ Mmprime = Mm + Ev - Ac - A3; /* sec 65 #9 */
Ec = 6.2886 * sin(dtor(Mmprime)); /* sec 65 #10 */ Ec = 6.2886 * sin (dtor (Mmprime)); /* sec 65 #10 */
A4 = 0.214 * sin(dtor(2 * Mmprime)); /* sec 65 #11 */ A4 = 0.214 * sin (dtor (2 * Mmprime)); /* sec 65 #11 */
lprime = l + Ev + Ec - Ac + A4; /* sec 65 #12 */ lprime = l + Ev + Ec - Ac + A4; /* sec 65 #12 */
V = 0.6583 * sin(dtor(2 * (lprime - LambdaSol))); /* sec 65 #13 */ V = 0.6583 * sin (dtor (2 * (lprime - LambdaSol))); /* sec 65 #13 */
ldprime = lprime + V; /* sec 65 #14 */ ldprime = lprime + V; /* sec 65 #14 */
D = ldprime - LambdaSol; /* sec 67 #2 */ D = ldprime - LambdaSol; /* sec 67 #2 */
return(50.0 * (1 - cos(dtor(D)))); /* sec 67 #3 */ return (50.0 * (1 - cos (dtor (D)))); /* sec 67 #3 */
} }
/* /*
@ -568,7 +571,7 @@ potm(double days)
* *
*/ */
static double static double
pom(time_t tmpt) pom (time_t tmpt)
{ {
struct tm *GMT; struct tm *GMT;
double days; double days;
@ -576,16 +579,16 @@ pom(time_t tmpt)
pom_e pom; pom_e pom;
pom = NO_POM; pom = NO_POM;
GMT = gmtime(&tmpt); GMT = gmtime (&tmpt);
days = (GMT->tm_yday + 1) + ((GMT->tm_hour + days = (GMT->tm_yday + 1) + ((GMT->tm_hour + (GMT->tm_min / 60.0) +
(GMT->tm_min / 60.0) + (GMT->tm_sec / 3600.0)) / 24.0); (GMT->tm_sec / 3600.0)) / 24.0);
for (cnt = EPOCH; cnt < GMT->tm_year; ++cnt) for (cnt = EPOCH; cnt < GMT->tm_year; ++cnt)
days += isleap(cnt + TM_YEAR_BASE) ? 366 : 365; days += isleap (cnt + TM_YEAR_BASE) ? 366 : 365;
/* Selected time could be before EPOCH */ /* Selected time could be before EPOCH */
for (cnt = GMT->tm_year; cnt < EPOCH; ++cnt) for (cnt = GMT->tm_year; cnt < EPOCH; ++cnt)
days -= isleap(cnt + TM_YEAR_BASE) ? 366 : 365; days -= isleap (cnt + TM_YEAR_BASE) ? 366 : 365;
return (potm(days)); return (potm (days));
} }
/* /*
@ -594,25 +597,24 @@ pom(time_t tmpt)
* the phase of the moon for previous day. * the phase of the moon for previous day.
*/ */
char * char *
calendar_get_pom(time_t date) calendar_get_pom (time_t date)
{ {
char *pom_pict[MOON_PHASES] = {" ", "|) ", "(|)", "(| ", " | "}; char *pom_pict[MOON_PHASES] = { " ", "|) ", "(|)", "(| ", " | " };
pom_e phase = NO_POM; pom_e phase = NO_POM;
double pom_today, relative_pom, pom_yesterday, pom_tomorrow; double pom_today, relative_pom, pom_yesterday, pom_tomorrow;
const double half = 50.0; const double half = 50.0;
pom_yesterday = pom(date); pom_yesterday = pom (date);
pom_today = pom(date + DAYINSEC); pom_today = pom (date + DAYINSEC);
relative_pom = abs(pom_today - half); relative_pom = abs (pom_today - half);
pom_tomorrow = pom(date + 2 * DAYINSEC); pom_tomorrow = pom (date + 2 * DAYINSEC);
if (pom_today > pom_yesterday && pom_today > pom_tomorrow) if (pom_today > pom_yesterday && pom_today > pom_tomorrow)
phase = FULL_MOON; phase = FULL_MOON;
else if (pom_today < pom_yesterday && pom_today < pom_tomorrow) else if (pom_today < pom_yesterday && pom_today < pom_tomorrow)
phase = NEW_MOON; phase = NEW_MOON;
else if (relative_pom < abs(pom_yesterday - half) && else if (relative_pom < abs (pom_yesterday - half)
relative_pom < abs(pom_tomorrow - half)) && relative_pom < abs (pom_tomorrow - half))
phase = (pom_tomorrow > pom_today) ? phase = (pom_tomorrow > pom_today) ? FIRST_QUARTER : LAST_QUARTER;
FIRST_QUARTER : LAST_QUARTER;
return (pom_pict[phase]); return (pom_pict[phase]);
} }

View File

@ -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 * Calcurse - text-based organizer
@ -34,7 +34,8 @@
#define CALHEIGHT 12 #define CALHEIGHT 12
#define CALWIDTH 30 #define CALWIDTH 30
typedef enum { /* days of week */ typedef enum
{ /* days of week */
SUNDAY, SUNDAY,
MONDAY, MONDAY,
TUESDAY, TUESDAY,
@ -43,44 +44,51 @@ typedef enum { /* days of week */
FRIDAY, FRIDAY,
SATURDAY, SATURDAY,
WDAYS WDAYS
} wday_e; }
wday_e;
typedef struct { typedef struct
{
unsigned dd; unsigned dd;
unsigned mm; unsigned mm;
unsigned yyyy; unsigned yyyy;
} date_t; }
date_t;
typedef enum { typedef enum
{
NO_POM, NO_POM,
FIRST_QUARTER, FIRST_QUARTER,
FULL_MOON, FULL_MOON,
LAST_QUARTER, LAST_QUARTER,
NEW_MOON, NEW_MOON,
MOON_PHASES MOON_PHASES
} pom_e; }
pom_e;
typedef enum { typedef enum
{
UP, UP,
DOWN, DOWN,
LEFT, LEFT,
RIGHT, RIGHT,
MOVES MOVES
} move_t; }
move_t;
void calendar_start_date_thread(void); void calendar_start_date_thread (void);
void calendar_stop_date_thread(void); void calendar_stop_date_thread (void);
void calendar_set_current_date(void); void calendar_set_current_date (void);
void calendar_set_first_day_of_week(wday_e); void calendar_set_first_day_of_week (wday_e);
void calendar_change_first_day_of_week(void); void calendar_change_first_day_of_week (void);
bool calendar_week_begins_on_monday(void); bool calendar_week_begins_on_monday (void);
void calendar_store_current_date(date_t *); void calendar_store_current_date (date_t *);
void calendar_init_slctd_day(void); void calendar_init_slctd_day (void);
date_t *calendar_get_slctd_day(void); date_t *calendar_get_slctd_day (void);
long calendar_get_slctd_day_sec(void); long calendar_get_slctd_day_sec (void);
void calendar_update_panel(WINDOW *); void calendar_update_panel (WINDOW *);
void calendar_change_day(int datefmt); void calendar_change_day (int);
void calendar_move(move_t); void calendar_move (move_t);
char *calendar_get_pom(time_t); char *calendar_get_pom (time_t);
#endif /* CALCURSE_CALENDAR_H */ #endif /* CALCURSE_CALENDAR_H */

File diff suppressed because it is too large Load Diff

View File

@ -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 * Calcurse - text-based organizer
@ -32,7 +32,8 @@
#define NBUSERCOLORS 6 #define NBUSERCOLORS 6
enum { /* Color pairs */ enum
{ /* Color pairs */
COLR_RED = 1, COLR_RED = 1,
COLR_GREEN, COLR_GREEN,
COLR_YELLOW, COLR_YELLOW,
@ -44,7 +45,8 @@ enum { /* Color pairs */
COLR_CUSTOM COLR_CUSTOM
}; };
enum { /* Configuration variables */ enum
{ /* Configuration variables */
CUSTOM_CONF_NOVARIABLE, CUSTOM_CONF_NOVARIABLE,
CUSTOM_CONF_AUTOSAVE, CUSTOM_CONF_AUTOSAVE,
CUSTOM_CONF_CONFIRMQUIT, CUSTOM_CONF_CONFIRMQUIT,
@ -64,20 +66,21 @@ enum { /* Configuration variables */
CUSTOM_CONF_VARIABLES CUSTOM_CONF_VARIABLES
}; };
struct attribute_s { struct attribute_s
{
int color[7]; int color[7];
int nocolor[7]; int nocolor[7];
}; };
void custom_init_attr(void); void custom_init_attr (void);
void custom_apply_attr(WINDOW *, int); void custom_apply_attr (WINDOW *, int);
void custom_remove_attr(WINDOW *, int); void custom_remove_attr (WINDOW *, int);
void custom_load_conf(conf_t *, int); void custom_load_conf (conf_t *, int);
void config_bar(void); void config_bar (void);
void layout_config(void); void layout_config (void);
void custom_color_config(void); void custom_color_config (void);
void custom_color_theme_name(char *); void custom_color_theme_name (char *);
void custom_confwin_init(window_t *, char *); void custom_confwin_init (window_t *, char *);
void custom_general_config(conf_t *); void custom_general_config (conf_t *);
#endif /* CALCURSE_CUSTOM_H */ #endif /* CALCURSE_CUSTOM_H */

674
src/day.c

File diff suppressed because it is too large Load Diff

View File

@ -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 * Calcurse - text-based organizer
@ -38,12 +38,15 @@
#define RECUR_APPT 3 #define RECUR_APPT 3
#define APPT 4 #define APPT 4
typedef struct { typedef struct
{
unsigned nb_events; unsigned nb_events;
unsigned nb_apoints; unsigned nb_apoints;
} day_items_nb_t; }
day_items_nb_t;
struct day_item_s { struct day_item_s
{
struct day_item_s *next; struct day_item_s *next;
long start; /* seconds since 1 jan 1970 */ long start; /* seconds since 1 jan 1970 */
long appt_dur; /* appointment duration in seconds */ long appt_dur; /* appointment duration in seconds */
@ -55,23 +58,24 @@ struct day_item_s {
char *note; /* note attached to item */ char *note; /* note attached to item */
}; };
struct day_saved_item_s { struct day_saved_item_s
{
char start[BUFSIZ]; char start[BUFSIZ];
char end[BUFSIZ]; char end[BUFSIZ];
char state; char state;
char type ; char type;
char *mesg; char *mesg;
}; };
day_items_nb_t *day_process_storage(date_t *, bool, day_items_nb_t *); day_items_nb_t *day_process_storage (date_t *, bool, day_items_nb_t *);
void day_write_pad(long, int, int, int); void day_write_pad (long, int, int, int);
void day_popup_item(void); void day_popup_item (void);
int day_check_if_item(date_t); int day_check_if_item (date_t);
void day_edit_item(conf_t *); void day_edit_item (conf_t *);
int day_erase_item(long, int, erase_flag_e); int day_erase_item (long, int, erase_flag_e);
struct day_item_s *day_get_item(int); struct day_item_s *day_get_item (int);
int day_item_nb(long, int, int); int day_item_nb (long, int, int);
void day_edit_note(char *); void day_edit_note (char *);
void day_view_note(char *); void day_view_note (char *);
#endif /* CALCURSE_DAY_H */ #endif /* CALCURSE_DAY_H */

View File

@ -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 * Calcurse - text-based organizer
@ -37,68 +37,72 @@ struct event_s *eventlist;
/* Create a new event */ /* Create a new event */
struct event_s * 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; struct event_s *o, **i;
o = (struct event_s *) malloc(sizeof(struct event_s)); o = (struct event_s *) malloc (sizeof (struct event_s));
o->mesg = (char *) malloc(strlen(mesg) + 1); o->mesg = (char *) malloc (strlen (mesg) + 1);
strncpy(o->mesg, mesg, strlen(mesg) + 1); strncpy (o->mesg, mesg, strlen (mesg) + 1);
o->day = day; o->day = day;
o->id = id; o->id = id;
o->note = (note != NULL) ? strdup(note) : NULL; o->note = (note != NULL) ? strdup (note) : NULL;
i = &eventlist; i = &eventlist;
for (;;) { for (;;)
if (*i == 0 || (*i)->day > day) { {
if (*i == 0 || (*i)->day > day)
{
o->next = *i; o->next = *i;
*i = o; *i = o;
break; break;
} }
i = &(*i)->next; i = &(*i)->next;
} }
return o; return (o);
} }
/* Check if the event belongs to the selected day */ /* Check if the event belongs to the selected day */
unsigned unsigned
event_inday(struct event_s *i, long start) event_inday (struct event_s *i, long start)
{ {
if (i->day <= start + DAYINSEC && i->day > start) { if (i->day <= start + DAYINSEC && i->day > start)
return 1; {
return (1);
} }
return 0; return (0);
} }
/* Write to file the event in user-friendly format */ /* Write to file the event in user-friendly format */
void void
event_write(struct event_s *o, FILE * f) event_write (struct event_s *o, FILE *f)
{ {
struct tm *lt; struct tm *lt;
time_t t; time_t t;
t = o->day; t = o->day;
lt = localtime(&t); lt = localtime (&t);
fprintf(f, "%02u/%02u/%04u [%d] ", fprintf (f, "%02u/%02u/%04u [%d] ", lt->tm_mon + 1, lt->tm_mday,
lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year, o->id); 1900 + lt->tm_year, o->id);
if (o->note != NULL) if (o->note != NULL)
fprintf(f, ">%s ", o->note); fprintf (f, ">%s ", o->note);
fprintf(f, "%s\n", o->mesg); fprintf (f, "%s\n", o->mesg);
} }
/* Load the events from file */ /* Load the events from file */
struct event_s * 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; struct tm *lt;
char buf[MESG_MAXSIZE], *nl; char buf[MESG_MAXSIZE], *nl;
time_t tstart, t; time_t tstart, t;
t = time(NULL); t = time (NULL);
lt = localtime(&t); lt = localtime (&t);
/* Read the event description */ /* Read the event description */
fgets(buf, MESG_MAXSIZE, f); fgets (buf, MESG_MAXSIZE, f);
nl = strchr(buf, '\n'); nl = strchr (buf, '\n');
if (nl) { if (nl)
{
*nl = '\0'; *nl = '\0';
} }
start.tm_hour = 12; start.tm_hour = 12;
@ -108,53 +112,61 @@ event_scan(FILE * f, struct tm start, int id, char *note)
start.tm_year -= 1900; start.tm_year -= 1900;
start.tm_mon--; start.tm_mon--;
tstart = mktime(&start); tstart = mktime (&start);
if (tstart == -1) { if (tstart == -1)
fputs(_("FATAL ERROR in event_scan: date error in the event\n"), stderr); {
exit(EXIT_FAILURE); fputs (_("FATAL ERROR in event_scan: date error in the event\n"),
stderr);
exit (EXIT_FAILURE);
} }
return (event_new(buf, note, tstart, id)); return (event_new (buf, note, tstart, id));
} }
/* Retrieve an event from the list, given the day and item position. */ /* Retrieve an event from the list, given the day and item position. */
struct event_s * struct event_s *
event_get(long day, int pos) event_get (long day, int pos)
{ {
struct event_s *o; struct event_s *o;
int n; int n;
n = 0; n = 0;
for (o = eventlist; o; o = o->next) { for (o = eventlist; o; o = o->next)
if (event_inday(o, day)) { {
if (event_inday (o, day))
{
if (n == pos) if (n == pos)
return o; return o;
n++; n++;
} }
} }
/* NOTREACHED */ /* NOTREACHED */
fputs(_("FATAL ERROR in event_get: no such item\n"), stderr); fputs (_("FATAL ERROR in event_get: no such item\n"), stderr);
exit(EXIT_FAILURE); exit (EXIT_FAILURE);
} }
/* Delete an event from the list. */ /* Delete an event from the list. */
void void
event_delete_bynum(long start, unsigned num, erase_flag_e flag) event_delete_bynum (long start, unsigned num, erase_flag_e flag)
{ {
unsigned n; unsigned n;
struct event_s *i, **iptr; struct event_s *i, **iptr;
n = 0; n = 0;
iptr = &eventlist; iptr = &eventlist;
for (i = eventlist; i != 0; i = i->next) { for (i = eventlist; i != 0; i = i->next)
if (event_inday(i, start)) { {
if (n == num) { if (event_inday (i, start))
{
if (n == num)
{
if (flag == ERASE_FORCE_ONLY_NOTE) if (flag == ERASE_FORCE_ONLY_NOTE)
erase_note(&i->note, flag); erase_note (&i->note, flag);
else { else
{
*iptr = i->next; *iptr = i->next;
free(i->mesg); free (i->mesg);
erase_note(&i->note, flag); erase_note (&i->note, flag);
free(i); free (i);
} }
return; return;
} }
@ -163,6 +175,6 @@ event_delete_bynum(long start, unsigned num, erase_flag_e flag)
iptr = &i->next; iptr = &i->next;
} }
/* NOTREACHED */ /* NOTREACHED */
fputs(_("FATAL ERROR in event_delete_bynum: no such event\n"), stderr); fputs (_("FATAL ERROR in event_delete_bynum: no such event\n"), stderr);
exit(EXIT_FAILURE); exit (EXIT_FAILURE);
} }

View File

@ -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 * Calcurse - text-based organizer
@ -32,7 +32,8 @@
#define HRMIN_SIZE 6 #define HRMIN_SIZE 6
#define MESG_MAXSIZE 256 #define MESG_MAXSIZE 256
struct event_s { struct event_s
{
struct event_s *next; struct event_s *next;
int id; /* event identifier */ int id; /* event identifier */
long day; /* seconds since 1 jan 1970 */ long day; /* seconds since 1 jan 1970 */
@ -42,11 +43,11 @@ struct event_s {
extern struct event_s *eventlist; extern struct event_s *eventlist;
struct event_s *event_new(char *, char *, long, int); struct event_s *event_new (char *, char *, long, int);
unsigned event_inday(struct event_s *, long); unsigned event_inday (struct event_s *, long);
void event_write(struct event_s *, FILE *); void event_write (struct event_s *, FILE *);
struct event_s *event_scan(FILE *, struct tm, int, char *); struct event_s *event_scan (FILE *, struct tm, int, char *);
struct event_s *event_get(long, int); struct event_s *event_get (long, int);
void event_delete_bynum(long, unsigned, erase_flag_e); void event_delete_bynum (long, unsigned, erase_flag_e);
#endif /* CALCURSE_EVENT_H */ #endif /* CALCURSE_EVENT_H */

View File

@ -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 * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -35,7 +35,8 @@
#include "utils.h" #include "utils.h"
#include "notify.h" #include "notify.h"
typedef enum { typedef enum
{
HELP_MAIN, HELP_MAIN,
HELP_SAVE, HELP_SAVE,
HELP_EXPORT, HELP_EXPORT,
@ -57,19 +58,22 @@ typedef enum {
HELP_CREDITS, HELP_CREDITS,
HELPSCREENS, HELPSCREENS,
NOPAGE NOPAGE
} help_pages_e; }
help_pages_e;
/* Returns the number of lines in an help text. */ /* Returns the number of lines in an help text. */
static int static int
get_help_lines(char *text) get_help_lines (char *text)
{ {
int i; int i;
int nl = 0; int nl = 0;
for (i = 0; text[i]; i++) { for (i = 0; text[i]; i++)
if (text[i] == '\n') nl++; {
if (text[i] == '\n')
nl++;
} }
return nl + 1; return (nl + 1);
} }
/* /*
@ -77,18 +81,18 @@ get_help_lines(char *text)
* of lines that were written. * of lines that were written.
*/ */
static int static int
write_help_pad(window_t *win, help_page_t *hpage) write_help_pad (window_t *win, help_page_t *hpage)
{ {
int nl_title = 0; int nl_title = 0;
int nl_text = 0; int nl_text = 0;
nl_text = get_help_lines(hpage->text); nl_text = get_help_lines (hpage->text);
nl_title = get_help_lines(hpage->title); nl_title = get_help_lines (hpage->title);
erase_window_part(win->p, 0, 0, BUFSIZ, win->w); erase_window_part (win->p, 0, 0, BUFSIZ, win->w);
custom_apply_attr(win->p, ATTR_HIGHEST); custom_apply_attr (win->p, ATTR_HIGHEST);
mvwprintw(win->p, 0, 0, "%s", hpage->title); mvwprintw (win->p, 0, 0, "%s", hpage->title);
custom_remove_attr(win->p, ATTR_HIGHEST); custom_remove_attr (win->p, ATTR_HIGHEST);
mvwprintw(win->p, nl_title, 0, "%s", hpage->text); mvwprintw (win->p, nl_title, 0, "%s", hpage->text);
return (nl_text + nl_title); return (nl_text + nl_title);
} }
@ -97,17 +101,17 @@ write_help_pad(window_t *win, help_page_t *hpage)
* faster. * faster.
*/ */
static void 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]; char label[BUFSIZ];
hwin->h = (notify_bar()) ? row - 3 : row - 2; hwin->h = (notify_bar ())? row - 3 : row - 2;
hwin->p = newwin(hwin->h, col, 0, 0); hwin->p = newwin (hwin->h, col, 0, 0);
hpad->w = col - 2 * PADOFFSET + 1; hpad->w = col - 2 * PADOFFSET + 1;
hpad->p = newpad(BUFSIZ, hpad->w); hpad->p = newpad (BUFSIZ, hpad->w);
box(hwin->p, 0, 0); box (hwin->p, 0, 0);
snprintf(label, BUFSIZ, _("CalCurse %s | help"), VERSION); snprintf (label, BUFSIZ, _("CalCurse %s | help"), VERSION);
wins_show(hwin->p, label); wins_show (hwin->p, label);
} }
/* /*
@ -115,40 +119,40 @@ help_wins_init(window_t *hwin, window_t *hpad, const int PADOFFSET)
* size and placement. * size and placement.
*/ */
static void static void
help_wins_reinit(window_t *hwin, window_t *hpad, const int PADOFFSET) help_wins_reinit (window_t *hwin, window_t *hpad, const int PADOFFSET)
{ {
delwin(hpad->p); delwin (hpad->p);
delwin(hwin->p); delwin (hwin->p);
wins_get_config(); wins_get_config ();
help_wins_init(hwin, hpad, PADOFFSET); help_wins_init (hwin, hpad, PADOFFSET);
} }
/* Reset the screen, needed when resizing terminal for example. */ /* Reset the screen, needed when resizing terminal for example. */
static void static void
help_wins_reset(window_t *hwin, window_t *hpad, const int PADOFFSET) help_wins_reset (window_t *hwin, window_t *hpad, const int PADOFFSET)
{ {
endwin(); endwin ();
refresh(); refresh ();
curs_set(0); curs_set (0);
delwin(win[STA].p); delwin (win[STA].p);
help_wins_reinit(hwin, hpad, PADOFFSET); help_wins_reinit (hwin, hpad, PADOFFSET);
win[STA].p = newwin(win[STA].h, win[STA].w, win[STA].y, win[STA].x); win[STA].p = newwin (win[STA].h, win[STA].w, win[STA].y, win[STA].x);
keypad(win[STA].p, TRUE); keypad (win[STA].p, TRUE);
if (notify_bar()) if (notify_bar ())
notify_reinit_bar(win[NOT].h, win[NOT].w, win[NOT].y, notify_reinit_bar (win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x);
win[NOT].x); status_bar ();
status_bar(); if (notify_bar ())
if (notify_bar()) notify_update_bar ();
notify_update_bar();
} }
/* Association between a key pressed and its corresponding help page. */ /* Association between a key pressed and its corresponding help page. */
static int static int
wanted_page(int ch) wanted_page (int ch)
{ {
int page; int page;
switch (ch) { switch (ch)
{
case '?': case '?':
page = HELP_MAIN; page = HELP_MAIN;
@ -158,13 +162,13 @@ wanted_page(int ch)
page = HELP_FLAG; page = HELP_FLAG;
break; break;
case CTRL('r'): case CTRL ('r'):
case CTRL('a'): case CTRL ('a'):
case CTRL('t'): case CTRL ('t'):
case CTRL('h'): case CTRL ('h'):
case CTRL('j'): case CTRL ('j'):
case CTRL('k'): case CTRL ('k'):
case CTRL('l'): case CTRL ('l'):
page = HELP_GENERAL; page = HELP_GENERAL;
break; break;
@ -250,7 +254,7 @@ wanted_page(int ch)
/* Draws the help screen */ /* Draws the help screen */
void void
help_screen(void) help_screen (void)
{ {
window_t hwin; window_t hwin;
window_t hpad; window_t hpad;
@ -318,8 +322,9 @@ help_screen(void)
hscr[HELP_VIEW].text = hscr[HELP_VIEW].text =
_("Pressing 'V' allows you to view the item you select in either the ToDo\n" _("Pressing 'V' allows you to view the item you select in either the ToDo\n"
"or Appointment panel.\n" "or Appointment panel.\n"
"\nThis is usefull when an event description is longer than the available\n" "\nThis is usefull when an event description is longer than the "
"space to display it. If that is the case, the description will be\n" "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" "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" "description, just press 'V' and a popup window will appear, containing\n"
"the whole event.\n" "the whole event.\n"
@ -331,8 +336,8 @@ help_screen(void)
_("Pressing 'Tab' allows you to switch between panels.\n" _("Pressing 'Tab' allows you to switch between panels.\n"
"The panel currently in use has its border colorized.\n" "The panel currently in use has its border colorized.\n"
"\nSome actions are possible only if the right panel is selected.\n" "\nSome actions are possible only if the right panel is selected.\n"
"For example, if you want to add a task in the TODO list, you need first\n" "For example, if you want to add a task in the TODO list, you need first"
"to press the 'Tab' key to get the TODO panel selected. Then you can\n" "\nto press the 'Tab' key to get the TODO panel selected. Then you can\n"
"press 'A' to add your item.\n" "press 'A' to add your item.\n"
"\nNotice that at the bottom of the screen the list of possible actions\n" "\nNotice that at the bottom of the screen the list of possible actions\n"
"change while pressing 'Tab', so you always know what action can be\n" "change while pressing 'Tab', so you always know what action can be\n"
@ -355,34 +360,33 @@ help_screen(void)
"\nIf the item to be deleted is recurrent, you will be asked if you\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" "wish to suppress all of the item occurences or just the one you\n"
"selected.\n" "selected.\n"
"\nIf the general option 'confirm_delete' is set to 'YES', then you will\n" "\nIf the general option 'confirm_delete' is set to 'YES', then you will"
"be asked for confirmation before deleting the selected event.\n" "\nbe asked for confirmation before deleting the selected event.\n"
"Do not forget to save the calendar data to retrieve the modifications\n" "Do not forget to save the calendar data to retrieve the modifications\n"
"next time you launch Calcurse."); "next time you launch Calcurse.");
hscr[HELP_ADD].title = _("Add:\n"); hscr[HELP_ADD].title = _("Add:\n");
hscr[HELP_ADD].text = hscr[HELP_ADD].text =
_("Pressing 'A' allows you to add an item in either the ToDo or Appointment\n" _("Pressing 'A' allows you to add an item in either the ToDo or Appointment"
"list, depending on which panel is selected when you press 'A'.\n" "\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\n" "\nTo enter a new item in the TODO list, you will need first to enter the"
"description of this new item. Then you will be asked to specify the todo\n" "\ndescription of this new item. Then you will be asked to specify the "
"priority. This priority is represented by a number going from 9 for the\n" "todo\npriority. This priority is represented by a number going from 9 "
"lowest priority, to 1 for the highest one. It is still possible to\n" "for the\nlowest priority, to 1 for the highest one. It is still "
"change the item priority afterwards, by using the '+/-' keys inside the\n" "possible to\nchange the item priority afterwards, by using the '+/-' "
"todo panel.\n" "keys inside the\ntodo panel.\n"
"\nIf the APPOINTMENT panel is selected while pressing 'A', you will be\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" "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" "To enter a new event, press [ENTER] instead of the item start time, "
"just fill in the event description.\n" "and\njust fill in the event description.\n"
"To enter a new appointment to be added in the APPOINTMENT list, you\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" "will need to enter successively the time at which the appointment\n"
"begins, the appointment length (either by specifying the duration in\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" "minutes, or the end time in [hh:mm] or [h:mm] format), and the\n"
"description of the event.\n" "description of the event.\n"
"\nThe day at which occurs the event or appointment is the day currently\n" "\nThe day at which occurs the event or appointment is the day currently"
"selected in the calendar, so you need to move to the desired day before\n" "\nselected in the calendar, so you need to move to the desired day "
"pressing 'A'.\n" "before\npressing 'A'.\n" "\nNotes:\n"
"\nNotes:\n"
" o if an appointment lasts for such a long time that it continues\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" " on the next days, this event will be indicated on all the\n"
" corresponding days, and the beginning or ending hour will be\n" " corresponding days, and the beginning or ending hour will be\n"
@ -397,11 +401,11 @@ help_screen(void)
hscr[HELP_EDIT].text = hscr[HELP_EDIT].text =
_("Pressing 'E' allows you to edit the item which is currently selected.\n" _("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" "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" "repeated or not, you will be asked to choose one of the item properties"
"to modify. An item property is one of the following: the start time, the\n" "\nto modify. An item property is one of the following: the start time, "
"end time, the description, or the item repetition.\n" "the\nend time, the description, or the item repetition.\n"
"Once you have chosen the property you want to modify, you will be shown\n" "Once you have chosen the property you want to modify, you will be shown"
"its actual value, and you will be able to change it as you like.\n" "\nits actual value, and you will be able to change it as you like.\n"
"\nNotes:\n" "\nNotes:\n"
" o if you choose to edit the item repetition properties, you will\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" " be asked to re-enter all of the repetition characteristics\n"
@ -428,8 +432,8 @@ help_screen(void)
" o if none of the above environment variables is set, then\n" " o if none of the above environment variables is set, then\n"
" '/usr/bin/vi' will be used.\n" " '/usr/bin/vi' will be used.\n"
"\nOnce the item note is edited and saved, quit your favorite editor.\n" "\nOnce the item note is edited and saved, quit your favorite editor.\n"
"You will then go back to Calcurse, and the '>' sign will appear in front\n" "You will then go back to Calcurse, and the '>' sign will appear in front"
"of the highlighted item, meaning there is a note attached to it."); "\nof the highlighted item, meaning there is a note attached to it.");
hscr[HELP_VNOTE].title = _("ViewNote:\n"); hscr[HELP_VNOTE].title = _("ViewNote:\n");
hscr[HELP_VNOTE].text = hscr[HELP_VNOTE].text =
@ -437,8 +441,9 @@ help_screen(void)
"attached to an item (an item which owns a note has a '>' sign in front\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" "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" "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" "Once you highlighted an item with a note attached to it, and the 'N' key"
"was pressed, you will be driven to an external pager to view that note.\n" "\nwas pressed, you will be driven to an external pager to view that "
"note.\n"
"The default pager is chosen the following way:\n" "The default pager is chosen the following way:\n"
" o if the 'PAGER' environment variable is set, then this will be\n" " o if the 'PAGER' environment variable is set, then this will be\n"
" the default viewer to be called.\n" " the default viewer to be called.\n"
@ -450,22 +455,25 @@ help_screen(void)
hscr[HELP_PRIORITY].title = _("Priority:\n"); hscr[HELP_PRIORITY].title = _("Priority:\n");
hscr[HELP_PRIORITY].text = hscr[HELP_PRIORITY].text =
_("Pressing '+' or '-' allows you to change the priority of the currently\n" _("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" "selected item in the ToDo list. Priorities are represented by the "
"appearing in front of the todo description. This number goes from 9 for\n" "number\nappearing in front of the todo description. This number goes "
"the lowest priority to 1 for the highest priority. Todo having higher\n" "from 9 for\nthe lowest priority to 1 for the highest priority. "
"priorities are placed first (at the top) inside the todo panel.\n\n" "Todo having higher\npriorities are placed first (at the top) inside the "
"If you want to raise the priority of a todo item, you need to press '+'.\n" "todo panel.\n\n"
"In doing so, the number in front of this item will decrease, meaning its\n" "If you want to raise the priority of a todo item, you need to press "
"priority increases. The item position inside the todo panel may change,\n" "'+'.\n"
"depending on the priority of the items above it.\n\n" "In doing so, the number in front of this item will decrease, "
"At the opposite, to lower a todo priority, press '-'. The todo position\n" "meaning its\npriority increases. The item position inside the todo "
"may also change depending on the priority of the items below."); "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].title = _("Repeat:\n");
hscr[HELP_REPEAT].text = hscr[HELP_REPEAT].text =
_("Pressing 'R' allows you to repeat an event or an appointment. You must\n" _("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" "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" "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" "which you will be able to specify the repetition characteristics:\n\n"
" o type: you can choose between a daily, weekly, monthly or\n" " o type: you can choose between a daily, weekly, monthly or\n"
" yearly repetition by pressing 'D', 'W', 'M' or 'Y'\n" " yearly repetition by pressing 'D', 'W', 'M' or 'Y'\n"
@ -479,8 +487,7 @@ help_screen(void)
" o ending date: this specifies when to stop repeating the selected\n" " o ending date: this specifies when to stop repeating the selected\n"
" event or appointment. To indicate an endless \n" " event or appointment. To indicate an endless \n"
" repetition, enter '0' and the item will be repeated\n" " repetition, enter '0' and the item will be repeated\n"
" forever.\n" " forever.\n" "\nNotes:\n"
"\nNotes:\n"
" o repeated items are marked with an '*' inside the appointment\n" " o repeated items are marked with an '*' inside the appointment\n"
" panel, to be easily recognizable from non-repeated ones.\n" " panel, to be easily recognizable from non-repeated ones.\n"
" o the 'Repeat' and 'Delete' command can be mixed to create\n" " o the 'Repeat' and 'Delete' command can be mixed to create\n"
@ -490,25 +497,25 @@ help_screen(void)
hscr[HELP_FLAG].title = _("Flag Item:\n"); hscr[HELP_FLAG].title = _("Flag Item:\n");
hscr[HELP_FLAG].text = hscr[HELP_FLAG].text =
_("Pressing '!' toggles an appointment's 'important' flag.\n\n" _("Pressing '!' toggles an appointment's 'important' flag.\n\n"
"If an item is flagged as important, an exclamation mark appears in front\n" "If an item is flagged as important, an exclamation mark appears in front"
"of it, and you will be warned if time gets closed to the appointment\n" "\nof it, and you will be warned if time gets closed to the appointment\n"
"start time.\n" "start time.\n"
"To customize the way one gets notified, the configuration submenu lets\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" "you choose the command launched to warn user of an upcoming appointment,"
"and how long before it he gets notified."); "\nand how long before it he gets notified.");
hscr[HELP_CONFIG].title = _("Config:\n"); hscr[HELP_CONFIG].title = _("Config:\n");
hscr[HELP_CONFIG].text = hscr[HELP_CONFIG].text =
_("Pressing 'C' leads to the configuration submenu, from which you can\n" _("Pressing 'C' leads to the configuration submenu, from which you can\n"
"select between color, layout, and general options.\n" "select between color, layout, and general options.\n"
"\nThe color submenu lets you choose the color theme.\n" "\nThe color submenu lets you choose the color theme.\n"
"\nThe layout submenu lets you choose the Calcurse screen layout, in other\n" "\nThe layout submenu lets you choose the Calcurse screen layout, in other"
"words where to place the three different panels on the screen.\n" "\nwords where to place the three different panels on the screen.\n"
"\nThe general options submenu brings a screen with the different options\n" "\nThe general options submenu brings a screen with the different options"
"which modifies the way Calcurse interacts with the user.\n" "\nwhich modifies the way Calcurse interacts with the user.\n"
"\nThe notify submenu allows you to change the notify-bar settings.\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" "\nDo not forget to save the calendar data to retrieve your configuration"
"next time you launch Calcurse."); "\nnext time you launch Calcurse.");
hscr[HELP_GENERAL].title = _("General keybindings:\n"); hscr[HELP_GENERAL].title = _("General keybindings:\n");
hscr[HELP_GENERAL].text = hscr[HELP_GENERAL].text =
@ -539,7 +546,7 @@ help_screen(void)
hscr[HELP_CREDITS].title = _("Calcurse - text-based organizer"); hscr[HELP_CREDITS].title = _("Calcurse - text-based organizer");
hscr[HELP_CREDITS].text = hscr[HELP_CREDITS].text =
_("Copyright (c) 2004-2007 Frederic Culot\n" _("Copyright (c) 2004-2008 Frederic Culot\n"
"\n" "\n"
"This program is free software; you can redistribute it and/or modify\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" "it under the terms of the GNU General Public License as published by\n"
@ -555,36 +562,38 @@ help_screen(void)
need_resize = 0; need_resize = 0;
page = oldpage = HELP_MAIN; page = oldpage = HELP_MAIN;
help_wins_init(&hwin, &hpad, PADOFFSET); help_wins_init (&hwin, &hpad, PADOFFSET);
/* Display the help screen related to user input. */ /* Display the help screen related to user input. */
while ( ch != 'q' ) { while (ch != 'q')
erase_window_part(hwin.p, 1, TITLELINES, col - 2, hwin.h - 2); {
erase_window_part (hwin.p, 1, TITLELINES, col - 2, hwin.h - 2);
switch (ch) {
switch (ch)
{
case KEY_RESIZE: case KEY_RESIZE:
help_wins_reset(&hwin, &hpad, PADOFFSET); help_wins_reset (&hwin, &hpad, PADOFFSET);
first_line = 0; first_line = 0;
nl = write_help_pad(&hpad, &hscr[oldpage]); nl = write_help_pad (&hpad, &hscr[oldpage]);
need_resize = 1; need_resize = 1;
break; break;
case CTRL('n') : case CTRL ('n'):
if (nl > (first_line + hwin.h - (PADOFFSET + 1))) if (nl > (first_line + hwin.h - (PADOFFSET + 1)))
first_line++; first_line++;
break; break;
case CTRL('p') : case CTRL ('p'):
if (first_line > 0) if (first_line > 0)
first_line--; first_line--;
break; break;
default: default:
page = wanted_page(ch); page = wanted_page (ch);
if (page != NOPAGE) { if (page != NOPAGE)
{
first_line = 0; first_line = 0;
nl = write_help_pad(&hpad, &hscr[page]); nl = write_help_pad (&hpad, &hscr[page]);
oldpage = page; oldpage = page;
} }
break; break;
@ -592,7 +601,8 @@ help_screen(void)
/* Draw the scrollbar if necessary. */ /* Draw the scrollbar if necessary. */
text_lines = hwin.h - (PADOFFSET + 1); text_lines = hwin.h - (PADOFFSET + 1);
if (nl > text_lines) { if (nl > text_lines)
{
float ratio = ((float) text_lines + 1) / ((float) nl); float ratio = ((float) text_lines + 1) / ((float) nl);
int sbar_length = (int) (ratio * text_lines); int sbar_length = (int) (ratio * text_lines);
int highend = (int) (ratio * first_line); int highend = (int) (ratio * first_line);
@ -600,21 +610,21 @@ help_screen(void)
if ((sbar_top + sbar_length) > hwin.h - 1) if ((sbar_top + sbar_length) > hwin.h - 1)
sbar_length = hwin.h - 1 - sbar_top; sbar_length = hwin.h - 1 - sbar_top;
draw_scrollbar(hwin.p, sbar_top, col - 2, draw_scrollbar (hwin.p, sbar_top, col - 2,
sbar_length, TITLELINES + 1, hwin.h - 1, true); sbar_length, TITLELINES + 1, hwin.h - 1, true);
} }
wmove(win[STA].p, 0, 0); wmove (win[STA].p, 0, 0);
wnoutrefresh(hwin.p); wnoutrefresh (hwin.p);
pnoutrefresh(hpad.p, first_line, 0, PADOFFSET, PADOFFSET, pnoutrefresh (hpad.p, first_line, 0, PADOFFSET, PADOFFSET,
hwin.h - 2, col - PADOFFSET); hwin.h - 2, col - PADOFFSET);
doupdate(); doupdate ();
ch = wgetch(win[STA].p); ch = wgetch (win[STA].p);
ch = tolower(ch); ch = tolower (ch);
} }
delwin(hpad.p); delwin (hpad.p);
delwin(hwin.p); delwin (hwin.p);
if (need_resize) if (need_resize)
wins_reset(); wins_reset ();
} }

View File

@ -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 * Calcurse - text-based organizer
@ -27,11 +27,13 @@
#ifndef CALCURSE_HELP_H #ifndef CALCURSE_HELP_H
#define CALCURSE_HELP_H #define CALCURSE_HELP_H
typedef struct { typedef struct
{
char *title; char *title;
char *text; char *text;
} help_page_t; }
help_page_t;
void help_screen(void); void help_screen (void);
#endif /* CALCURSE_HELP_H */ #endif /* CALCURSE_HELP_H */

View File

@ -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 * Calcurse - text-based organizer
@ -32,23 +32,23 @@
#endif /* HAVE_CONFIG_H */ #endif /* HAVE_CONFIG_H */
#if ENABLE_NLS #if ENABLE_NLS
#include <libintl.h> #include <libintl.h>
#undef _ #undef _
#define _(String) gettext(String) #define _(String) gettext(String)
#ifdef gettext_noop #ifdef gettext_noop
#define N_(String) gettext_noop(String) #define N_(String) gettext_noop(String)
#else #else
#define N_(String) (String) #define N_(String) (String)
#endif #endif
#else /* NLS disabled */ #else /* NLS disabled */
#define _(String) (String) #define _(String) (String)
#define N_(String) (String) #define N_(String) (String)
#define textdomain(String) (String) #define textdomain(String) (String)
#define gettext(String) (String) #define gettext(String) (String)
#define dgettext(String) (String) #define dgettext(String) (String)
#define dcgettext(String) (String) #define dcgettext(String) (String)
#define bindtextdomain(String) (String) #define bindtextdomain(String) (String)
#define bind_textdomain_codeset(Domain,Codeset) (Codeset) #define bind_textdomain_codeset(Domain,Codeset) (Codeset)
#endif /* ENABLE_NLS */ #endif /* ENABLE_NLS */
#endif /* CALCURSE_I18N_H */ #endif /* CALCURSE_I18N_H */

908
src/io.c

File diff suppressed because it is too large Load Diff

View File

@ -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 * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -29,19 +29,21 @@
#include "vars.h" #include "vars.h"
typedef enum { typedef enum
{
IO_EXPORT_NONINTERACTIVE, IO_EXPORT_NONINTERACTIVE,
IO_EXPORT_INTERACTIVE, IO_EXPORT_INTERACTIVE,
IO_EXPORT_NBMODES IO_EXPORT_NBMODES
} export_mode_t; }
export_mode_t;
void io_init(char *); void io_init (char *);
void io_extract_data(char *, const char *, int); void io_extract_data (char *, const char *, int);
void io_save_cal(conf_t *); void io_save_cal (conf_t *);
void io_load_app(void); void io_load_app (void);
void io_load_todo(void); void io_load_todo (void);
int io_check_data_files(void); int io_check_data_files (void);
void io_startup_screen(bool, int); void io_startup_screen (bool, int);
void io_export_data(export_mode_t, conf_t *); void io_export_data (export_mode_t, conf_t *);
#endif /* CALCURSE_IO_H */ #endif /* CALCURSE_IO_H */

View File

@ -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 * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -40,47 +40,48 @@ static pthread_t notify_t_main;
/* Return 1 if we need to display the notify-bar, else 0. */ /* Return 1 if we need to display the notify-bar, else 0. */
int int
notify_bar(void) notify_bar (void)
{ {
int display_bar = 0; int display_bar = 0;
pthread_mutex_lock(&nbar->mutex); pthread_mutex_lock (&nbar->mutex);
display_bar = (nbar->show) ? 1 : 0; display_bar = (nbar->show) ? 1 : 0;
pthread_mutex_unlock(&nbar->mutex); pthread_mutex_unlock (&nbar->mutex);
return display_bar; return (display_bar);
} }
/* Initialize the nbar variable used to store notification options. */ /* Initialize the nbar variable used to store notification options. */
void void
notify_init_vars(void) notify_init_vars (void)
{ {
char *time_format = "%T"; char *time_format = "%T";
char *date_format = "%a %F"; char *date_format = "%a %F";
char *cmd = "printf '\\a'"; char *cmd = "printf '\\a'";
nbar = (struct nbar_s *) malloc(sizeof(struct nbar_s)); nbar = (struct nbar_s *) malloc (sizeof (struct nbar_s));
pthread_mutex_init(&nbar->mutex, NULL); pthread_mutex_init (&nbar->mutex, NULL);
nbar->show = 1; nbar->show = 1;
nbar->cntdwn = 300; nbar->cntdwn = 300;
strncpy(nbar->datefmt, date_format, strlen(date_format) + 1); strncpy (nbar->datefmt, date_format, strlen (date_format) + 1);
strncpy(nbar->timefmt, time_format, strlen(time_format) + 1); strncpy (nbar->timefmt, time_format, strlen (time_format) + 1);
strncpy(nbar->cmd, cmd, strlen(cmd) + 1); strncpy (nbar->cmd, cmd, strlen (cmd) + 1);
if ((nbar->shell = getenv("SHELL")) == NULL) if ((nbar->shell = getenv ("SHELL")) == NULL)
nbar->shell = "/bin/sh"; nbar->shell = "/bin/sh";
} }
/* Extract the appointment file name from the complete file path. */ /* Extract the appointment file name from the complete file path. */
static void static void
extract_aptsfile(void) extract_aptsfile (void)
{ {
char *file; char *file;
file = strrchr(path_apts, '/'); file = strrchr (path_apts, '/');
if (!file) if (!file)
notify->apts_file = path_apts; notify->apts_file = path_apts;
else { else
{
notify->apts_file = file; notify->apts_file = file;
notify->apts_file++; notify->apts_file++;
} }
@ -92,23 +93,22 @@ extract_aptsfile(void)
* number of columns, y and x are its coordinates). * number of columns, y and x are its coordinates).
*/ */
void void
notify_init_bar(void) notify_init_bar (void)
{ {
notify = (struct notify_vars_s *) malloc(sizeof(struct notify_vars_s)); notify = (struct notify_vars_s *) malloc (sizeof (struct notify_vars_s));
notify_app = (struct notify_app_s *) notify_app = (struct notify_app_s *) malloc (sizeof (struct notify_app_s));
malloc(sizeof(struct notify_app_s)); pthread_mutex_init (&notify->mutex, NULL);
pthread_mutex_init(&notify->mutex, NULL); pthread_mutex_init (&notify_app->mutex, NULL);
pthread_mutex_init(&notify_app->mutex, NULL);
notify_app->got_app = 0; notify_app->got_app = 0;
notify->win = newwin(win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x); notify->win = newwin (win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x);
extract_aptsfile(); extract_aptsfile ();
} }
/* Stop the notify-bar main thread. */ /* Stop the notify-bar main thread. */
void void
notify_stop_main_thread(void) notify_stop_main_thread (void)
{ {
pthread_cancel(notify_t_main); pthread_cancel (notify_t_main);
return; return;
} }
@ -117,28 +117,26 @@ notify_stop_main_thread(void)
* notification window. * notification window.
*/ */
void void
notify_reinit_bar(int l, int c, int y, int x) notify_reinit_bar (int l, int c, int y, int x)
{ {
delwin(notify->win); delwin (notify->win);
notify->win = newwin(l, c, y, x); notify->win = newwin (l, c, y, x);
} }
/* Launch user defined command as a notification. */ /* Launch user defined command as a notification. */
static void static void
launch_cmd(char *cmd, char *shell) launch_cmd (char *cmd, char *shell)
{ {
int pid; int pid;
pid = fork(); pid = fork ();
if (pid < 0) if (pid < 0)
ierror(_("FATAL ERROR in launch_cmd: could not fork"), ierror (_("FATAL ERROR in launch_cmd: could not fork"), IERROR_WARN);
IERROR_WARN);
else if (pid == 0) /* Child: launch user defined command */ else if (pid == 0) /* Child: launch user defined command */
if (execlp(shell, shell, "-c", cmd, (char *)NULL) < 0) if (execlp (shell, shell, "-c", cmd, (char *) NULL) < 0)
ierror(_("FATAL ERROR in launch_cmd: could not " ierror (_("FATAL ERROR in launch_cmd: could not "
"launch user command"), "launch user command"), IERROR_WARN);
IERROR_WARN);
} }
/* /*
@ -146,7 +144,7 @@ launch_cmd(char *cmd, char *shell)
* for example. * for example.
*/ */
void void
notify_update_bar(void) notify_update_bar (void)
{ {
const int space = 3; const int space = 3;
int file_pos, date_pos, app_pos, txt_max_len, too_long = 0; int file_pos, date_pos, app_pos, txt_max_len, too_long = 0;
@ -155,272 +153,291 @@ notify_update_bar(void)
char buf[BUFSIZ]; char buf[BUFSIZ];
date_pos = space; date_pos = space;
pthread_mutex_lock(&notify->mutex); pthread_mutex_lock (&notify->mutex);
file_pos = strlen(notify->date) + strlen(notify->time) + 7 + 2*space; file_pos = strlen (notify->date) + strlen (notify->time) + 7 + 2 * space;
app_pos = file_pos + strlen(notify->apts_file) + 2 + space; app_pos = file_pos + strlen (notify->apts_file) + 2 + space;
txt_max_len = col - (app_pos + 12 + space); txt_max_len = col - (app_pos + 12 + space);
custom_apply_attr(notify->win, ATTR_HIGHEST); custom_apply_attr (notify->win, ATTR_HIGHEST);
wattron(notify->win, A_UNDERLINE | A_REVERSE); wattron (notify->win, A_UNDERLINE | A_REVERSE);
mvwhline(notify->win, 0, 0, ACS_HLINE, col); mvwhline (notify->win, 0, 0, ACS_HLINE, col);
mvwprintw(notify->win, 0, date_pos, "[ %s | %s ]", mvwprintw (notify->win, 0, date_pos, "[ %s | %s ]",
notify->date, notify->time); notify->date, notify->time);
mvwprintw(notify->win, 0, file_pos, "(%s)", notify->apts_file); mvwprintw (notify->win, 0, file_pos, "(%s)", notify->apts_file);
pthread_mutex_lock(&notify_app->mutex); pthread_mutex_lock (&notify_app->mutex);
if (notify_app->got_app) { if (notify_app->got_app)
if (strlen(notify_app->txt) > txt_max_len) { {
if (strlen (notify_app->txt) > txt_max_len)
{
too_long = 1; too_long = 1;
strncpy(buf, notify_app->txt, txt_max_len - 3); strncpy (buf, notify_app->txt, txt_max_len - 3);
buf[txt_max_len - 3] = '\0'; buf[txt_max_len - 3] = '\0';
} }
time_left = notify_app->time - notify->time_in_sec; time_left = notify_app->time - notify->time_in_sec;
if (time_left > 0) { if (time_left > 0)
{
hours_left = (time_left / HOURINSEC); hours_left = (time_left / HOURINSEC);
minutes_left = (time_left - hours_left * HOURINSEC) / minutes_left = (time_left - hours_left * HOURINSEC) / MININSEC;
MININSEC; pthread_mutex_lock (&nbar->mutex);
pthread_mutex_lock(&nbar->mutex);
if (time_left < nbar->cntdwn && if (time_left < nbar->cntdwn && (notify_app->state & APOINT_NOTIFY))
(notify_app->state & APOINT_NOTIFY))
blinking = 1; blinking = 1;
else else
blinking = 0; blinking = 0;
if (blinking) if (blinking)
wattron(notify->win, A_BLINK); wattron (notify->win, A_BLINK);
if (too_long) if (too_long)
mvwprintw(notify->win, 0, app_pos, mvwprintw (notify->win, 0, app_pos, "> %02d:%02d :: %s.. <",
"> %02d:%02d :: %s.. <",
hours_left, minutes_left, buf); hours_left, minutes_left, buf);
else else
mvwprintw(notify->win, 0, app_pos, mvwprintw (notify->win, 0, app_pos, "> %02d:%02d :: %s <",
"> %02d:%02d :: %s <", hours_left, minutes_left, notify_app->txt);
hours_left, minutes_left,
notify_app->txt);
if (blinking) if (blinking)
wattroff(notify->win, A_BLINK); wattroff (notify->win, A_BLINK);
if (blinking && if (blinking && !(notify_app->state & APOINT_NOTIFIED))
!(notify_app->state & APOINT_NOTIFIED)) { {
notify_app->state |= APOINT_NOTIFIED; notify_app->state |= APOINT_NOTIFIED;
launch_cmd(nbar->cmd, nbar->shell); launch_cmd (nbar->cmd, nbar->shell);
} }
pthread_mutex_unlock(&nbar->mutex); pthread_mutex_unlock (&nbar->mutex);
} else { }
else
{
notify_app->got_app = 0; notify_app->got_app = 0;
pthread_mutex_unlock(&notify_app->mutex); pthread_mutex_unlock (&notify_app->mutex);
pthread_mutex_unlock(&notify->mutex); pthread_mutex_unlock (&notify->mutex);
notify_check_next_app(); notify_check_next_app ();
return; return;
} }
} }
pthread_mutex_unlock(&notify_app->mutex); pthread_mutex_unlock (&notify_app->mutex);
wattroff(notify->win, A_UNDERLINE | A_REVERSE); wattroff (notify->win, A_UNDERLINE | A_REVERSE);
custom_remove_attr(notify->win, ATTR_HIGHEST); custom_remove_attr (notify->win, ATTR_HIGHEST);
wrefresh(notify->win); wrefresh (notify->win);
pthread_mutex_unlock(&notify->mutex); pthread_mutex_unlock (&notify->mutex);
} }
/* Update the notication bar content */ /* Update the notication bar content */
static void * static void *
notify_main_thread(void *arg) notify_main_thread (void *arg)
{ {
const unsigned thread_sleep = 1; const unsigned thread_sleep = 1;
const unsigned check_app = MININSEC; const unsigned check_app = MININSEC;
int elapse= 0, got_app = 0; int elapse = 0, got_app = 0;
struct tm *ntime; struct tm *ntime;
time_t ntimer; time_t ntimer;
elapse = 0; elapse = 0;
got_app = 0; got_app = 0;
for (;;) { for (;;)
ntimer = time(NULL); {
ntime = localtime(&ntimer); ntimer = time (NULL);
pthread_mutex_lock(&notify->mutex); ntime = localtime (&ntimer);
pthread_mutex_lock (&notify->mutex);
notify->time_in_sec = ntimer; notify->time_in_sec = ntimer;
pthread_mutex_lock(&nbar->mutex); pthread_mutex_lock (&nbar->mutex);
strftime(notify->time, NOTIFY_FIELD_LENGTH, nbar->timefmt, ntime); strftime (notify->time, NOTIFY_FIELD_LENGTH, nbar->timefmt, ntime);
strftime(notify->date, NOTIFY_FIELD_LENGTH, nbar->datefmt, ntime); strftime (notify->date, NOTIFY_FIELD_LENGTH, nbar->datefmt, ntime);
pthread_mutex_unlock(&nbar->mutex); pthread_mutex_unlock (&nbar->mutex);
pthread_mutex_unlock(&notify->mutex); pthread_mutex_unlock (&notify->mutex);
notify_update_bar(); notify_update_bar ();
sleep(thread_sleep); sleep (thread_sleep);
elapse += thread_sleep; elapse += thread_sleep;
if (elapse >= check_app) { if (elapse >= check_app)
{
elapse = 0; elapse = 0;
pthread_mutex_lock(&notify_app->mutex); pthread_mutex_lock (&notify_app->mutex);
got_app = notify_app->got_app; got_app = notify_app->got_app;
pthread_mutex_unlock(&notify_app->mutex); pthread_mutex_unlock (&notify_app->mutex);
if (!got_app) if (!got_app)
notify_check_next_app(); notify_check_next_app ();
} }
} }
pthread_exit((void*) 0); pthread_exit ((void *) 0);
} }
/* Look for the next appointment within the next 24 hours. */ /* Look for the next appointment within the next 24 hours. */
static void * static void *
notify_thread_app(void *arg) notify_thread_app (void *arg)
{ {
struct notify_app_s *tmp_app; struct notify_app_s *tmp_app;
time_t current_time; time_t current_time;
current_time = time(NULL); current_time = time (NULL);
/* Use a temporary structure not to lock the mutex for a too /* Use a temporary structure not to lock the mutex for a too
* long time while looking for next appointment. */ * long time while looking for next appointment. */
tmp_app = (struct notify_app_s *) malloc(sizeof(struct notify_app_s)); tmp_app = (struct notify_app_s *) malloc (sizeof (struct notify_app_s));
tmp_app->time = current_time + DAYINSEC; tmp_app->time = current_time + DAYINSEC;
tmp_app->got_app = 0; tmp_app->got_app = 0;
tmp_app->txt = NULL; tmp_app->txt = NULL;
tmp_app = recur_apoint_check_next(tmp_app, current_time, get_today()); tmp_app = recur_apoint_check_next (tmp_app, current_time, get_today ());
tmp_app = apoint_check_next(tmp_app, current_time); tmp_app = apoint_check_next (tmp_app, current_time);
pthread_mutex_lock(&notify_app->mutex); pthread_mutex_lock (&notify_app->mutex);
if (tmp_app->got_app) { if (tmp_app->got_app)
{
notify_app->got_app = 1; notify_app->got_app = 1;
notify_app->time = tmp_app->time; notify_app->time = tmp_app->time;
notify_app->txt = mycpy(tmp_app->txt); notify_app->txt = mycpy (tmp_app->txt);
notify_app->state = tmp_app->state; notify_app->state = tmp_app->state;
} else { }
else
{
notify_app->got_app = 0; notify_app->got_app = 0;
} }
pthread_mutex_unlock(&notify_app->mutex); pthread_mutex_unlock (&notify_app->mutex);
if (tmp_app->txt != NULL) if (tmp_app->txt != NULL)
free(tmp_app->txt); free (tmp_app->txt);
free(tmp_app); free (tmp_app);
notify_update_bar(); notify_update_bar ();
pthread_exit((void*) 0); pthread_exit ((void *) 0);
} }
/* Launch the thread notify_thread_app to look for next appointment. */ /* Launch the thread notify_thread_app to look for next appointment. */
void void
notify_check_next_app(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); pthread_create (&notify_t_app, NULL, notify_thread_app, NULL);
return; return;
} }
/* Check if the newly created appointment is to be notified. */ /* Check if the newly created appointment is to be notified. */
void void
notify_check_added(char *mesg, long start, char state) notify_check_added (char *mesg, long start, char state)
{ {
time_t current_time; time_t current_time;
int update_notify = 0; int update_notify = 0;
long gap; long gap;
current_time = time(NULL); current_time = time (NULL);
pthread_mutex_lock(&notify_app->mutex); pthread_mutex_lock (&notify_app->mutex);
if (!notify_app->got_app) { if (!notify_app->got_app)
{
gap = start - current_time; gap = start - current_time;
if (gap >= 0 && gap <= DAYINSEC) if (gap >= 0 && gap <= DAYINSEC)
update_notify = 1; update_notify = 1;
} else if (start < notify_app->time && start >= current_time) { }
else if (start < notify_app->time && start >= current_time)
{
update_notify = 1; update_notify = 1;
} else if (start == notify_app->time && state != notify_app->state) }
else if (start == notify_app->time && state != notify_app->state)
update_notify = 1; update_notify = 1;
if (update_notify) { if (update_notify)
{
notify_app->got_app = 1; notify_app->got_app = 1;
notify_app->time = start; notify_app->time = start;
notify_app->txt = mycpy(mesg); notify_app->txt = mycpy (mesg);
notify_app->state = state; notify_app->state = state;
} }
pthread_mutex_unlock(&notify_app->mutex); pthread_mutex_unlock (&notify_app->mutex);
notify_update_bar(); notify_update_bar ();
} }
/* Check if the newly repeated appointment is to be notified. */ /* Check if the newly repeated appointment is to be notified. */
void void
notify_check_repeated(recur_apoint_llist_node_t *i) notify_check_repeated (recur_apoint_llist_node_t *i)
{ {
long real_app_time; long real_app_time;
int update_notify = 0; int update_notify = 0;
time_t current_time; time_t current_time;
current_time = time(NULL); current_time = time (NULL);
pthread_mutex_lock(&notify_app->mutex); pthread_mutex_lock (&notify_app->mutex);
if ((real_app_time = recur_item_inday(i->start, i->exc, i->rpt->type, if ((real_app_time = recur_item_inday (i->start, i->exc, i->rpt->type,
i->rpt->freq, i->rpt->until, get_today()) > current_time)) { i->rpt->freq, i->rpt->until,
if (!notify_app->got_app) { get_today ()) > current_time))
{
if (!notify_app->got_app)
{
if (real_app_time - current_time <= DAYINSEC) if (real_app_time - current_time <= DAYINSEC)
update_notify = 1; update_notify = 1;
} else if (real_app_time < notify_app->time && }
real_app_time >= current_time) { else if (real_app_time < notify_app->time &&
real_app_time >= current_time)
{
update_notify = 1; update_notify = 1;
} else if (real_app_time == notify_app->time && }
else if (real_app_time == notify_app->time &&
i->state != notify_app->state) i->state != notify_app->state)
update_notify = 1; update_notify = 1;
} }
if (update_notify) { if (update_notify)
{
notify_app->got_app = 1; notify_app->got_app = 1;
notify_app->time = real_app_time; notify_app->time = real_app_time;
notify_app->txt = mycpy(i->mesg); notify_app->txt = mycpy (i->mesg);
notify_app->state = i->state; notify_app->state = i->state;
} }
pthread_mutex_unlock(&notify_app->mutex); pthread_mutex_unlock (&notify_app->mutex);
notify_update_bar(); notify_update_bar ();
} }
int int
notify_same_item(long time) notify_same_item (long time)
{ {
int same = 0; int same = 0;
pthread_mutex_lock(&(notify_app->mutex)); pthread_mutex_lock (&(notify_app->mutex));
if (notify_app->got_app && notify_app->time == time) if (notify_app->got_app && notify_app->time == time)
same = 1; same = 1;
pthread_mutex_unlock(&(notify_app->mutex)); pthread_mutex_unlock (&(notify_app->mutex));
return same; return (same);
} }
int int
notify_same_recur_item(recur_apoint_llist_node_t *i) notify_same_recur_item (recur_apoint_llist_node_t *i)
{ {
int same = 0; int same = 0;
long item_start = 0; long item_start = 0;
item_start = recur_item_inday(i->start, i->exc, i->rpt->type, item_start = recur_item_inday (i->start, i->exc, i->rpt->type,
i->rpt->freq, i->rpt->until, get_today()); i->rpt->freq, i->rpt->until, get_today ());
pthread_mutex_lock(&notify_app->mutex); pthread_mutex_lock (&notify_app->mutex);
if (notify_app->got_app && item_start == notify_app->time) if (notify_app->got_app && item_start == notify_app->time)
same = 1; same = 1;
pthread_mutex_unlock(&(notify_app->mutex)); pthread_mutex_unlock (&(notify_app->mutex));
return same; return (same);
} }
/* Launch the notify-bar main thread. */ /* Launch the notify-bar main thread. */
void void
notify_start_main_thread(void) notify_start_main_thread (void)
{ {
pthread_create(&notify_t_main, NULL, notify_main_thread, NULL); pthread_create (&notify_t_main, NULL, notify_main_thread, NULL);
notify_check_next_app(); notify_check_next_app ();
return; return;
} }
/* Print options related to the notify-bar. */ /* Print options related to the notify-bar. */
static void static void
notify_print_options(WINDOW *optwin, int col) notify_print_options (WINDOW *optwin, int col)
{ {
enum {SHOW, DATE, CLOCK, WARN, CMD, NB_OPT}; enum
{ SHOW, DATE, CLOCK, WARN, CMD, NB_OPT };
struct opt_s { struct opt_s
{
char name[BUFSIZ]; char name[BUFSIZ];
char desc[BUFSIZ]; char desc[BUFSIZ];
char value[BUFSIZ]; char value[BUFSIZ];
} opt[NB_OPT]; }
opt[NB_OPT];
int i, y, x, l, x_pos, y_pos, x_offset, y_offset, maxcol, maxlen; int i, y, x, l, x_pos, y_pos, x_offset, y_offset, maxcol, maxlen;
char buf[BUFSIZ]; char buf[BUFSIZ];
@ -431,72 +448,72 @@ notify_print_options(WINDOW *optwin, int col)
y_offset = 3; y_offset = 3;
maxcol = col - 2; maxcol = col - 2;
strncpy(opt[SHOW].name, _("notify-bar_show = "), BUFSIZ); strncpy (opt[SHOW].name, _("notify-bar_show = "), BUFSIZ);
strncpy(opt[DATE].name, _("notify-bar_date = "), BUFSIZ); strncpy (opt[DATE].name, _("notify-bar_date = "), BUFSIZ);
strncpy(opt[CLOCK].name, _("notify-bar_clock = "), BUFSIZ); strncpy (opt[CLOCK].name, _("notify-bar_clock = "), BUFSIZ);
strncpy(opt[WARN].name, _("notify-bar_warning = "), BUFSIZ); strncpy (opt[WARN].name, _("notify-bar_warning = "), BUFSIZ);
strncpy(opt[CMD].name, _("notify-bar_command = "), BUFSIZ); strncpy (opt[CMD].name, _("notify-bar_command = "), BUFSIZ);
strncpy(opt[SHOW].desc, strncpy (opt[SHOW].desc,
_("(if set to YES, notify-bar will be displayed)"), _("(if set to YES, notify-bar will be displayed)"), BUFSIZ);
BUFSIZ); strncpy (opt[DATE].desc,
strncpy(opt[DATE].desc,
_("(Format of the date to be displayed inside notify-bar)"), _("(Format of the date to be displayed inside notify-bar)"),
BUFSIZ); BUFSIZ);
strncpy(opt[CLOCK].desc, strncpy (opt[CLOCK].desc,
_("(Format of the time to be displayed inside notify-bar)"), _("(Format of the time to be displayed inside notify-bar)"),
BUFSIZ); BUFSIZ);
strncpy(opt[WARN].desc, strncpy (opt[WARN].desc,
_("(Warn user if an appointment is within next 'notify-bar_warning'" _("(Warn user if an appointment is within next 'notify-bar_warning'"
" seconds)"), " seconds)"), BUFSIZ);
BUFSIZ); strncpy (opt[CMD].desc,
strncpy(opt[CMD].desc,
_("(Command used to notify user of an upcoming appointment)"), _("(Command used to notify user of an upcoming appointment)"),
BUFSIZ); BUFSIZ);
pthread_mutex_lock(&nbar->mutex); pthread_mutex_lock (&nbar->mutex);
strncpy(opt[DATE].value, nbar->datefmt, BUFSIZ); strncpy (opt[DATE].value, nbar->datefmt, BUFSIZ);
strncpy(opt[CLOCK].value, nbar->timefmt, BUFSIZ); strncpy (opt[CLOCK].value, nbar->timefmt, BUFSIZ);
snprintf(opt[WARN].value, BUFSIZ, "%d", nbar->cntdwn); snprintf (opt[WARN].value, BUFSIZ, "%d", nbar->cntdwn);
strncpy(opt[CMD].value, nbar->cmd, BUFSIZ); strncpy (opt[CMD].value, nbar->cmd, BUFSIZ);
l = strlen(opt[SHOW].name); l = strlen (opt[SHOW].name);
x = x_pos + x_offset + l; x = x_pos + x_offset + l;
mvwprintw(optwin, y_pos, x_pos, "[1] %s", opt[SHOW].name); mvwprintw (optwin, y_pos, x_pos, "[1] %s", opt[SHOW].name);
erase_window_part(optwin, x, y_pos, maxcol, y_pos); erase_window_part (optwin, x, y_pos, maxcol, y_pos);
print_option_incolor(optwin, nbar->show, y_pos, x); print_option_incolor (optwin, nbar->show, y_pos, x);
mvwprintw(optwin, y_pos + 1, x_pos, opt[SHOW].desc); mvwprintw (optwin, y_pos + 1, x_pos, opt[SHOW].desc);
for (i = 1; i < NB_OPT; i++) { for (i = 1; i < NB_OPT; i++)
l = strlen(opt[i].name); {
l = strlen (opt[i].name);
y = y_pos + i * y_offset; y = y_pos + i * y_offset;
x = x_pos + x_offset + l; x = x_pos + x_offset + l;
maxlen = maxcol - x - 2; maxlen = maxcol - x - 2;
mvwprintw(optwin, y, x_pos, "[%d] %s", i + 1, opt[i].name); mvwprintw (optwin, y, x_pos, "[%d] %s", i + 1, opt[i].name);
erase_window_part(optwin, x, y, maxcol, y); erase_window_part (optwin, x, y, maxcol, y);
custom_apply_attr(optwin, ATTR_HIGHEST); custom_apply_attr (optwin, ATTR_HIGHEST);
if (strlen(opt[i].value) < maxlen) if (strlen (opt[i].value) < maxlen)
mvwprintw(optwin, y, x, "%s", opt[i].value); mvwprintw (optwin, y, x, "%s", opt[i].value);
else { else
strncpy(buf, opt[i].value, maxlen - 1); {
strncpy (buf, opt[i].value, maxlen - 1);
buf[maxlen - 1] = '\0'; buf[maxlen - 1] = '\0';
mvwprintw(optwin, y, x, "%s...", buf); mvwprintw (optwin, y, x, "%s...", buf);
} }
custom_remove_attr(optwin, ATTR_HIGHEST); custom_remove_attr (optwin, ATTR_HIGHEST);
mvwprintw(optwin, y + 1, x_pos, opt[i].desc); mvwprintw (optwin, y + 1, x_pos, opt[i].desc);
} }
pthread_mutex_unlock(&nbar->mutex); pthread_mutex_unlock (&nbar->mutex);
wmove(win[STA].p, 1, 0); wmove (win[STA].p, 1, 0);
wnoutrefresh(optwin); wnoutrefresh (optwin);
doupdate(); doupdate ();
} }
/* Notify-bar configuration. */ /* Notify-bar configuration. */
void void
notify_config_bar(void) notify_config_bar (void)
{ {
window_t conf_win; window_t conf_win;
char label[BUFSIZ]; char label[BUFSIZ];
@ -510,91 +527,96 @@ notify_config_bar(void)
char *count_str = char *count_str =
_("Enter the number of seconds (0 not to be warned before an appointment)"); _("Enter the number of seconds (0 not to be warned before an appointment)");
char *cmd_str = _("Enter the notification command "); char *cmd_str = _("Enter the notification command ");
int ch = 0 , change_win = 1; int ch = 0, change_win = 1;
buf = (char *)malloc(BUFSIZ); buf = (char *) malloc (BUFSIZ);
snprintf(label, BUFSIZ, _("CalCurse %s | notify-bar options"), VERSION); snprintf (label, BUFSIZ, _("CalCurse %s | notify-bar options"), VERSION);
custom_confwin_init(&conf_win, label); custom_confwin_init (&conf_win, label);
while (ch != 'q') { while (ch != 'q')
{
if (change_win) if (change_win)
custom_confwin_init(&conf_win, label); custom_confwin_init (&conf_win, label);
status_mesg(number_str, ""); status_mesg (number_str, "");
notify_print_options(conf_win.p, col); notify_print_options (conf_win.p, col);
*buf = '\0'; *buf = '\0';
ch = wgetch(win[STA].p); ch = wgetch (win[STA].p);
switch (ch) { switch (ch)
{
case KEY_RESIZE: case KEY_RESIZE:
endwin(); endwin ();
refresh(); refresh ();
curs_set(0); curs_set (0);
delwin(conf_win.p); delwin (conf_win.p);
custom_confwin_init(&conf_win, label); custom_confwin_init (&conf_win, label);
break; break;
case '1': case '1':
pthread_mutex_lock(&nbar->mutex); pthread_mutex_lock (&nbar->mutex);
nbar->show = !nbar->show; nbar->show = !nbar->show;
pthread_mutex_unlock(&nbar->mutex); pthread_mutex_unlock (&nbar->mutex);
if (notify_bar()) if (notify_bar ())
notify_start_main_thread(); notify_start_main_thread ();
else else
notify_stop_main_thread(); notify_stop_main_thread ();
delwin(conf_win.p); delwin (conf_win.p);
change_win = 1; change_win = 1;
break; break;
case '2': case '2':
status_mesg(date_str, ""); status_mesg (date_str, "");
pthread_mutex_lock(&nbar->mutex); pthread_mutex_lock (&nbar->mutex);
strncpy(buf, nbar->datefmt, strlen(nbar->datefmt) + 1); strncpy (buf, nbar->datefmt, strlen (nbar->datefmt) + 1);
pthread_mutex_unlock(&nbar->mutex); pthread_mutex_unlock (&nbar->mutex);
if (updatestring(win[STA].p, &buf, 0, 1) == 0) { if (updatestring (win[STA].p, &buf, 0, 1) == 0)
pthread_mutex_lock(&nbar->mutex); {
strncpy(nbar->datefmt, buf, strlen(buf) + 1); pthread_mutex_lock (&nbar->mutex);
pthread_mutex_unlock(&nbar->mutex); strncpy (nbar->datefmt, buf, strlen (buf) + 1);
pthread_mutex_unlock (&nbar->mutex);
} }
change_win = 0; change_win = 0;
break; break;
case '3': case '3':
status_mesg(time_str, ""); status_mesg (time_str, "");
pthread_mutex_lock(&nbar->mutex); pthread_mutex_lock (&nbar->mutex);
strncpy(buf, nbar->timefmt, strlen(nbar->timefmt) + 1); strncpy (buf, nbar->timefmt, strlen (nbar->timefmt) + 1);
pthread_mutex_unlock(&nbar->mutex); pthread_mutex_unlock (&nbar->mutex);
if (updatestring(win[STA].p, &buf, 0, 1) == 0) { if (updatestring (win[STA].p, &buf, 0, 1) == 0)
pthread_mutex_lock(&nbar->mutex); {
strncpy(nbar->timefmt, buf, strlen(buf) + 1); pthread_mutex_lock (&nbar->mutex);
pthread_mutex_unlock(&nbar->mutex); strncpy (nbar->timefmt, buf, strlen (buf) + 1);
pthread_mutex_unlock (&nbar->mutex);
} }
change_win = 0; change_win = 0;
break; break;
case '4': case '4':
status_mesg(count_str, ""); status_mesg (count_str, "");
pthread_mutex_lock(&nbar->mutex); pthread_mutex_lock (&nbar->mutex);
printf(buf, "%d", nbar->cntdwn); printf (buf, "%d", nbar->cntdwn);
pthread_mutex_unlock(&nbar->mutex); pthread_mutex_unlock (&nbar->mutex);
if (updatestring(win[STA].p, &buf, 0, 1) == 0 && if (updatestring (win[STA].p, &buf, 0, 1) == 0 &&
is_all_digit(buf) && is_all_digit (buf) && atoi (buf) >= 0 && atoi (buf) <= DAYINSEC)
atoi(buf) >= 0 && atoi(buf) <= DAYINSEC) { {
pthread_mutex_lock(&nbar->mutex); pthread_mutex_lock (&nbar->mutex);
nbar->cntdwn = atoi(buf); nbar->cntdwn = atoi (buf);
pthread_mutex_unlock(&nbar->mutex); pthread_mutex_unlock (&nbar->mutex);
} }
change_win = 0; change_win = 0;
break; break;
case '5': case '5':
status_mesg(cmd_str, ""); status_mesg (cmd_str, "");
pthread_mutex_lock(&nbar->mutex); pthread_mutex_lock (&nbar->mutex);
strncpy(buf, nbar->cmd, strlen(nbar->cmd) + 1); strncpy (buf, nbar->cmd, strlen (nbar->cmd) + 1);
pthread_mutex_unlock(&nbar->mutex); pthread_mutex_unlock (&nbar->mutex);
if (updatestring(win[STA].p, &buf, 0, 1) == 0) { if (updatestring (win[STA].p, &buf, 0, 1) == 0)
pthread_mutex_lock(&nbar->mutex); {
strncpy(nbar->cmd, buf, strlen(buf) + 1); pthread_mutex_lock (&nbar->mutex);
pthread_mutex_unlock(&nbar->mutex); strncpy (nbar->cmd, buf, strlen (buf) + 1);
pthread_mutex_unlock (&nbar->mutex);
} }
change_win = 0; change_win = 0;
break; break;
} }
} }
free(buf); free (buf);
delwin(conf_win.p); delwin (conf_win.p);
} }

View File

@ -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 * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -33,7 +33,8 @@
#define NOTIFY_FIELD_LENGTH 25 #define NOTIFY_FIELD_LENGTH 25
struct notify_vars_s { struct notify_vars_s
{
WINDOW *win; WINDOW *win;
long time_in_sec; long time_in_sec;
char *apts_file; char *apts_file;
@ -42,7 +43,8 @@ struct notify_vars_s {
pthread_mutex_t mutex; pthread_mutex_t mutex;
}; };
struct notify_app_s { struct notify_app_s
{
long time; long time;
int got_app; int got_app;
char *txt; char *txt;
@ -50,18 +52,18 @@ struct notify_app_s {
pthread_mutex_t mutex; pthread_mutex_t mutex;
}; };
int notify_bar(void); int notify_bar (void);
void notify_init_vars(void); void notify_init_vars (void);
void notify_init_bar(void); void notify_init_bar (void);
void notify_start_main_thread(void); void notify_start_main_thread (void);
void notify_stop_main_thread(void); void notify_stop_main_thread (void);
void notify_reinit_bar(int, int, int, int); void notify_reinit_bar (int, int, int, int);
void notify_update_bar(void); void notify_update_bar (void);
void notify_check_next_app(void); void notify_check_next_app (void);
void notify_check_added(char *, long, char); void notify_check_added (char *, long, char);
void notify_check_repeated(recur_apoint_llist_node_t *); void notify_check_repeated (recur_apoint_llist_node_t *);
int notify_same_item(long); int notify_same_item (long);
int notify_same_recur_item(recur_apoint_llist_node_t *); int notify_same_recur_item (recur_apoint_llist_node_t *);
void notify_config_bar(void); void notify_config_bar (void);
#endif /* CALCURSE_NOTIFY_H */ #endif /* CALCURSE_NOTIFY_H */

File diff suppressed because it is too large Load Diff

View File

@ -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 * Calcurse - text-based organizer
@ -27,26 +27,31 @@
#ifndef CALCURSE_RECUR_H #ifndef CALCURSE_RECUR_H
#define CALCURSE_RECUR_H #define CALCURSE_RECUR_H
typedef enum { RECUR_NO, typedef enum
{ RECUR_NO,
RECUR_DAILY, RECUR_DAILY,
RECUR_WEEKLY, RECUR_WEEKLY,
RECUR_MONTHLY, RECUR_MONTHLY,
RECUR_YEARLY, RECUR_YEARLY,
RECUR_TYPES RECUR_TYPES
} recur_types_t; }
recur_types_t;
struct days_s { struct days_s
{
struct days_s *next; struct days_s *next;
long st; /* beggining of the considered day, in seconds */ long st; /* beggining of the considered day, in seconds */
}; };
struct rpt_s { struct rpt_s
{
int type; /* repetition type, see RECUR_* defines */ int type; /* repetition type, see RECUR_* defines */
int freq; /* repetition frequence */ int freq; /* repetition frequence */
long until; /* ending date for repeated event */ long until; /* ending date for repeated event */
}; };
typedef struct recur_apoint_llist_node { typedef struct recur_apoint_llist_node
{
struct recur_apoint_llist_node *next; struct recur_apoint_llist_node *next;
struct rpt_s *rpt; /* information about repetition */ struct rpt_s *rpt; /* information about repetition */
struct days_s *exc; /* days when the item should not be repeated */ struct days_s *exc; /* days when the item should not be repeated */
@ -55,14 +60,18 @@ typedef struct recur_apoint_llist_node {
char state; /* 8 bits to store item state */ char state; /* 8 bits to store item state */
char *mesg; /* appointment description */ char *mesg; /* appointment description */
char *note; /* note attached to appointment */ char *note; /* note attached to appointment */
} recur_apoint_llist_node_t; }
recur_apoint_llist_node_t;
typedef struct recur_apoint_llist { typedef struct recur_apoint_llist
{
recur_apoint_llist_node_t *root; recur_apoint_llist_node_t *root;
pthread_mutex_t mutex; pthread_mutex_t mutex;
} recur_apoint_llist_t; }
recur_apoint_llist_t;
struct recur_event_s { struct recur_event_s
{
struct recur_event_s *next; struct recur_event_s *next;
struct rpt_s *rpt; /* information about repetition */ struct rpt_s *rpt; /* information about repetition */
struct days_s *exc; /* days when the item should not be repeated */ struct days_s *exc; /* days when the item should not be repeated */
@ -75,27 +84,28 @@ struct recur_event_s {
extern recur_apoint_llist_t *recur_alist_p; extern recur_apoint_llist_t *recur_alist_p;
extern struct recur_event_s *recur_elist; extern struct recur_event_s *recur_elist;
int recur_apoint_llist_init(void); int recur_apoint_llist_init (void);
char recur_def2char(recur_types_t); char recur_def2char (recur_types_t);
int recur_char2def(char); int recur_char2def (char);
recur_apoint_llist_node_t *recur_apoint_scan(FILE *, struct tm, struct tm, recur_apoint_llist_node_t *recur_apoint_scan (FILE *, struct tm, struct tm,
char, int, struct tm, char *, char, int, struct tm, char *,
struct days_s *, char); struct days_s *, char);
struct recur_event_s *recur_event_scan(FILE *, struct tm, int, char, struct recur_event_s *recur_event_scan (FILE *, struct tm, int, char,
int, struct tm, char *, struct days_s *); int, struct tm, char *,
void recur_save_data(FILE *); struct days_s *);
unsigned recur_item_inday(long, struct days_s *, int, void recur_save_data (FILE *);
int, long, long); unsigned recur_item_inday (long, struct days_s *, int, int,
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); long, long);
recur_apoint_llist_node_t *recur_get_apoint(long, int); void recur_event_erase (long, unsigned, unsigned,
struct recur_event_s *recur_get_event(long, int); erase_flag_e);
void recur_apoint_switch_notify(long, int); 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 */ #endif /* CALCURSE_RECUR_H */

View File

@ -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 * 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 * 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 * 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. * Also catch CTRL-C (SIGINT), and SIGWINCH to resize screen automatically.
*/ */
static void static void
signal_handler(int sig) signal_handler (int sig)
{ {
switch (sig) { switch (sig)
{
case SIGCHLD: case SIGCHLD:
while (waitpid(WAIT_MYPGRP, NULL, WNOHANG) > 0) while (waitpid (WAIT_MYPGRP, NULL, WNOHANG) > 0)
; ;
break; break;
case SIGWINCH: case SIGWINCH:
clearok(curscr, TRUE); clearok (curscr, TRUE);
ungetch(KEY_RESIZE); ungetch (KEY_RESIZE);
break; break;
} }
} }
/* Signal handling init. */ /* Signal handling init. */
void void
sigs_init(struct sigaction *sa) sigs_init (struct sigaction *sa)
{ {
sa->sa_handler = signal_handler; sa->sa_handler = signal_handler;
sa->sa_flags = 0; sa->sa_flags = 0;
sigemptyset(&sa->sa_mask); sigemptyset (&sa->sa_mask);
if (sigaction(SIGCHLD, sa, NULL) != 0) { if (sigaction (SIGCHLD, sa, NULL) != 0)
perror("sigaction"); {
exit(EXIT_FAILURE); perror ("sigaction");
exit (EXIT_FAILURE);
} }
sa->sa_handler = signal_handler; sa->sa_handler = signal_handler;
sa->sa_flags = 0; sa->sa_flags = 0;
sigemptyset(&sa->sa_mask); sigemptyset (&sa->sa_mask);
if (sigaction(SIGWINCH, sa, NULL) != 0) { if (sigaction (SIGWINCH, sa, NULL) != 0)
perror("sigaction"); {
exit(EXIT_FAILURE); perror ("sigaction");
exit (EXIT_FAILURE);
} }
sa->sa_handler = SIG_IGN; sa->sa_handler = SIG_IGN;
sa->sa_flags = 0; sa->sa_flags = 0;
sigemptyset(&(sa->sa_mask)); sigemptyset (&(sa->sa_mask));
if (sigaction(SIGINT, sa, NULL) != 0) { if (sigaction (SIGINT, sa, NULL) != 0)
perror("sigaction"); {
exit(EXIT_FAILURE); perror ("sigaction");
exit (EXIT_FAILURE);
} }
} }

View File

@ -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 * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -27,6 +27,6 @@
#ifndef CALCURSE_SIGS_H #ifndef CALCURSE_SIGS_H
#define CALCURSE_SIGS_H #define CALCURSE_SIGS_H
void sigs_init(struct sigaction *); void sigs_init (struct sigaction *);
#endif /* CALCURSE_SIGS_H */ #endif /* CALCURSE_SIGS_H */

View File

@ -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 * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -41,73 +41,74 @@ static char *msgsav;
/* Returns a structure containing the selected item. */ /* Returns a structure containing the selected item. */
static struct todo_s * static struct todo_s *
todo_get_item(int item_number) todo_get_item (int item_number)
{ {
struct todo_s *o; struct todo_s *o;
int i; int i;
o = todolist; o = todolist;
for (i = 1; i < item_number; i++) { for (i = 1; i < item_number; i++)
{
o = o->next; o = o->next;
} }
return o; return (o);
} }
/* Sets which todo is highlighted. */ /* Sets which todo is highlighted. */
void void
todo_hilt_set(int highlighted) todo_hilt_set (int highlighted)
{ {
hilt = highlighted; hilt = highlighted;
} }
void void
todo_hilt_decrease(void) todo_hilt_decrease (void)
{ {
hilt--; hilt--;
} }
void void
todo_hilt_increase(void) todo_hilt_increase (void)
{ {
hilt++; hilt++;
} }
/* Return which todo is highlighted. */ /* Return which todo is highlighted. */
int int
todo_hilt(void) todo_hilt (void)
{ {
return (hilt); return (hilt);
} }
/* Return the number of todos. */ /* Return the number of todos. */
int int
todo_nb(void) todo_nb (void)
{ {
return (todos); return (todos);
} }
/* Set the number of todos. */ /* Set the number of todos. */
void void
todo_set_nb(int nb) todo_set_nb (int nb)
{ {
todos = nb; todos = nb;
} }
/* Set which one is the first todo to be displayed. */ /* Set which one is the first todo to be displayed. */
void void
todo_set_first(int nb) todo_set_first (int nb)
{ {
first = nb; first = nb;
} }
void void
todo_first_increase(void) todo_first_increase (void)
{ {
first++; first++;
} }
void void
todo_first_decrease(void) todo_first_decrease (void)
{ {
first--; first--;
} }
@ -117,161 +118,172 @@ todo_first_decrease(void)
* displayed. * displayed.
*/ */
int int
todo_hilt_pos(void) todo_hilt_pos (void)
{ {
return (hilt - first); return (hilt - first);
} }
/* Return the last visited todo. */ /* Return the last visited todo. */
char * char *
todo_saved_mesg(void) todo_saved_mesg (void)
{ {
return (msgsav); return (msgsav);
} }
/* Request user to enter a new todo item. */ /* Request user to enter a new todo item. */
void void
todo_new_item(void) todo_new_item (void)
{ {
int ch = 0; int ch = 0;
char *mesg = _("Enter the new ToDo item : "); char *mesg = _("Enter the new ToDo item : ");
char *mesg_id = char *mesg_id = _("Enter the ToDo priority [1 (highest) - 9 (lowest)] :");
_("Enter the ToDo priority [1 (highest) - 9 (lowest)] :");
char todo_input[BUFSIZ] = ""; char todo_input[BUFSIZ] = "";
status_mesg(mesg, ""); status_mesg (mesg, "");
if (getstring(win[STA].p, todo_input, BUFSIZ, 0, 1) == if (getstring (win[STA].p, todo_input, BUFSIZ, 0, 1) == GETSTRING_VALID)
GETSTRING_VALID) { {
while ( (ch < '1') || (ch > '9') ) { while ((ch < '1') || (ch > '9'))
status_mesg(mesg_id, ""); {
ch = wgetch(win[STA].p); status_mesg (mesg_id, "");
ch = wgetch (win[STA].p);
} }
todo_add(todo_input, ch - '0', NULL); todo_add (todo_input, ch - '0', NULL);
todos++; todos++;
} }
} }
/* Add an item in the todo linked list. */ /* Add an item in the todo linked list. */
struct todo_s * struct todo_s *
todo_add(char *mesg, int id, char *note) todo_add (char *mesg, int id, char *note)
{ {
struct todo_s *o, **i; struct todo_s *o, **i;
o = (struct todo_s *) malloc(sizeof(struct todo_s)); o = (struct todo_s *) malloc (sizeof (struct todo_s));
o->mesg = (char *) malloc(strlen(mesg) + 1); o->mesg = (char *) malloc (strlen (mesg) + 1);
strncpy(o->mesg, mesg, strlen(mesg) + 1); strncpy (o->mesg, mesg, strlen (mesg) + 1);
o->id = id; o->id = id;
o->note = (note != NULL && note[0] != '\0') ? strdup(note) : NULL; o->note = (note != NULL && note[0] != '\0') ? strdup (note) : NULL;
i = &todolist; i = &todolist;
for (;;) { for (;;)
if (*i == 0 || (*i)->id > id) { {
if (*i == 0 || (*i)->id > id)
{
o->next = *i; o->next = *i;
*i = o; *i = o;
break; break;
} }
i = &(*i)->next; i = &(*i)->next;
} }
return o; return (o);
} }
/* Delete a note previously attached to a todo item. */ /* Delete a note previously attached to a todo item. */
static void static void
todo_delete_note_bynum(unsigned num) todo_delete_note_bynum (unsigned num)
{ {
unsigned n; unsigned n;
struct todo_s *i, **iptr; struct todo_s *i, **iptr;
n = 0; n = 0;
iptr = &todolist; iptr = &todolist;
for (i = todolist; i != 0; i = i->next) { for (i = todolist; i != 0; i = i->next)
if (n == num) { {
if (n == num)
{
if (i->note == NULL) if (i->note == NULL)
ierror( ierror (_("FATAL ERROR in todo_delete_note_bynum: "
_("FATAL ERROR in todo_delete_note_bynum: "
"no note attached\n"), IERROR_FATAL); "no note attached\n"), IERROR_FATAL);
erase_note(&i->note, ERASE_FORCE_ONLY_NOTE); erase_note (&i->note, ERASE_FORCE_ONLY_NOTE);
return; return;
} }
iptr = &i->next; iptr = &i->next;
n++; n++;
} }
/* NOTREACHED */ /* NOTREACHED */
ierror(_("FATAL ERROR in todo_delete_note_bynum: no such todo\n"), ierror (_("FATAL ERROR in todo_delete_note_bynum: no such todo\n"),
IERROR_FATAL); IERROR_FATAL);
exit(EXIT_FAILURE); exit (EXIT_FAILURE);
} }
/* Delete an item from the todo linked list. */ /* Delete an item from the todo linked list. */
static void static void
todo_delete_bynum(unsigned num, erase_flag_e flag) todo_delete_bynum (unsigned num, erase_flag_e flag)
{ {
unsigned n; unsigned n;
struct todo_s *i, **iptr; struct todo_s *i, **iptr;
n = 0; n = 0;
iptr = &todolist; iptr = &todolist;
for (i = todolist; i != 0; i = i->next) { for (i = todolist; i != 0; i = i->next)
if (n == num) { {
if (n == num)
{
*iptr = i->next; *iptr = i->next;
free(i->mesg); free (i->mesg);
if (i->note != NULL) if (i->note != NULL)
erase_note(&i->note, flag); erase_note (&i->note, flag);
free(i); free (i);
return; return;
} }
iptr = &i->next; iptr = &i->next;
n++; n++;
} }
/* NOTREACHED */ /* NOTREACHED */
ierror(_("FATAL ERROR in todo_delete_bynum: no such todo\n"), ierror (_("FATAL ERROR in todo_delete_bynum: no such todo\n"),
IERROR_FATAL); IERROR_FATAL);
exit(EXIT_FAILURE); exit (EXIT_FAILURE);
} }
/* Delete an item from the ToDo list. */ /* Delete an item from the ToDo list. */
void void
todo_delete(conf_t *conf) todo_delete (conf_t *conf)
{ {
char *choices = "[y/n] "; char *choices = "[y/n] ";
char *del_todo_str = _("Do you really want to delete this task ?"); char *del_todo_str = _("Do you really want to delete this task ?");
char *erase_warning = char *erase_warning =
_("This item has a note attached to it. " _("This item has a note attached to it. "
"Delete (t)odo or just its (n)ote ?"); "Delete (t)odo or just its (n)ote ?");
char *erase_choice = char *erase_choice = _("[t/n] ");
_("[t/n] ");
bool go_for_todo_del = false; bool go_for_todo_del = false;
int answer = 0, has_note; int answer = 0, has_note;
if (conf->confirm_delete) { if (conf->confirm_delete)
status_mesg(del_todo_str, choices); {
answer = wgetch(win[STA].p); status_mesg (del_todo_str, choices);
if ( (answer == 'y') && (todos > 0) ) { answer = wgetch (win[STA].p);
if ((answer == 'y') && (todos > 0))
{
go_for_todo_del = true; go_for_todo_del = true;
} else { }
erase_status_bar(); else
{
erase_status_bar ();
return; return;
} }
} else }
if (todos > 0) else if (todos > 0)
go_for_todo_del = true; go_for_todo_del = true;
if (go_for_todo_del == false) { if (go_for_todo_del == false)
erase_status_bar(); {
erase_status_bar ();
return; return;
} }
answer = 0; answer = 0;
has_note = (todo_get_item(hilt)->note != NULL) ? 1 : 0; has_note = (todo_get_item (hilt)->note != NULL) ? 1 : 0;
if (has_note == 0) if (has_note == 0)
answer = 't'; answer = 't';
while (answer != 't' && answer != 'n' && answer != ESCAPE) { while (answer != 't' && answer != 'n' && answer != ESCAPE)
status_mesg(erase_warning, erase_choice); {
answer = wgetch(win[STA].p); status_mesg (erase_warning, erase_choice);
answer = wgetch (win[STA].p);
} }
switch (answer) { switch (answer)
{
case 't': case 't':
todo_delete_bynum(hilt - 1, ERASE_FORCE); todo_delete_bynum (hilt - 1, ERASE_FORCE);
todos--; todos--;
if (hilt > 1) if (hilt > 1)
hilt--; hilt--;
@ -281,10 +293,10 @@ todo_delete(conf_t *conf)
first--; first--;
break; break;
case 'n': case 'n':
todo_delete_note_bynum(hilt - 1); todo_delete_note_bynum (hilt - 1);
break; break;
default: default:
erase_status_bar(); erase_status_bar ();
return; return;
} }
} }
@ -294,30 +306,34 @@ todo_delete(conf_t *conf)
* given todo_s item. * given todo_s item.
*/ */
static int static int
todo_get_position(struct todo_s *i) todo_get_position (struct todo_s *i)
{ {
struct todo_s *o; struct todo_s *o;
int n = 1, found = 0; int n = 1, found = 0;
for (o = todolist; o; o = o->next) { for (o = todolist; o; o = o->next)
if (o == i) { {
if (o == i)
{
found = 1; found = 1;
break; break;
} }
n++; n++;
} }
if (found) { if (found)
return n; {
} else { return (n);
fputs(_("FATAL ERROR in todo_get_position: todo not found\n"), }
stderr); else
exit(EXIT_FAILURE); {
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. */ /* Change an item priority by pressing '+' or '-' inside TODO panel. */
void void
todo_chg_priority(int action) todo_chg_priority (int action)
{ {
struct todo_s *backup; struct todo_s *backup;
char backup_mesg[BUFSIZ]; char backup_mesg[BUFSIZ];
@ -325,43 +341,48 @@ todo_chg_priority(int action)
char backup_note[NOTESIZ + 1]; char backup_note[NOTESIZ + 1];
int do_chg = 1; int do_chg = 1;
backup = todo_get_item(hilt); backup = todo_get_item (hilt);
strncpy(backup_mesg, backup->mesg, strlen(backup->mesg) + 1); strncpy (backup_mesg, backup->mesg, strlen (backup->mesg) + 1);
backup_id = backup->id; backup_id = backup->id;
if (backup->note) if (backup->note)
strncpy(backup_note, backup->note, NOTESIZ + 1); strncpy (backup_note, backup->note, NOTESIZ + 1);
else else
backup_note[0] = '\0'; backup_note[0] = '\0';
if (action == '+') { if (action == '+')
{
(backup_id > 1) ? backup_id-- : do_chg--; (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) { else if (action == '-')
todo_delete_bynum(hilt - 1, ERASE_FORCE_KEEP_NOTE); {
backup = todo_add(backup_mesg, backup_id, backup_note); (backup_id < 9) ? backup_id++ : do_chg--;
hilt = todo_get_position(backup); }
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. */ /* Edit the description of an already existing todo item. */
void void
todo_edit_item(void) todo_edit_item (void)
{ {
struct todo_s *i; struct todo_s *i;
char *mesg = _("Enter the new ToDo description :"); char *mesg = _("Enter the new ToDo description :");
status_mesg(mesg, ""); status_mesg (mesg, "");
i = todo_get_item(hilt); i = todo_get_item (hilt);
updatestring(win[STA].p, &i->mesg, 0, 1); updatestring (win[STA].p, &i->mesg, 0, 1);
} }
/* Display todo items in the corresponding panel. */ /* Display todo items in the corresponding panel. */
static void static void
display_todo_item(int incolor, char *msg, int prio, int note, int len, int y, display_todo_item (int incolor, char *msg, int prio, int note, int len, int y,
int x) int x)
{ {
WINDOW *w; WINDOW *w;
@ -371,21 +392,22 @@ display_todo_item(int incolor, char *msg, int prio, int note, int len, int y,
w = win[TOD].p; w = win[TOD].p;
ch_note = (note) ? '>' : '.'; ch_note = (note) ? '>' : '.';
if (incolor == 0) if (incolor == 0)
custom_apply_attr(w, ATTR_HIGHEST); custom_apply_attr (w, ATTR_HIGHEST);
if (strlen(msg) < len) if (strlen (msg) < len)
mvwprintw(w, y, x, "%d%c %s", prio, ch_note, msg); mvwprintw (w, y, x, "%d%c %s", prio, ch_note, msg);
else { else
strncpy(buf, msg, len - 1); {
strncpy (buf, msg, len - 1);
buf[len - 1] = '\0'; buf[len - 1] = '\0';
mvwprintw(w, y, x, "%d%c %s...", prio, ch_note, buf); mvwprintw (w, y, x, "%d%c %s...", prio, ch_note, buf);
} }
if (incolor == 0) if (incolor == 0)
custom_remove_attr(w, ATTR_HIGHEST); custom_remove_attr (w, ATTR_HIGHEST);
} }
/* Updates the ToDo panel. */ /* Updates the ToDo panel. */
void void
todo_update_panel(window_t *wintod, int which_pan) todo_update_panel (window_t *wintod, int which_pan)
{ {
struct todo_s *i; struct todo_s *i;
int len = wintod->w - 8; int len = wintod->w - 8;
@ -398,23 +420,26 @@ todo_update_panel(window_t *wintod, int which_pan)
int incolor = -1; int incolor = -1;
/* Print todo item in the panel. */ /* Print todo item in the panel. */
erase_window_part(win[TOD].p, 1, title_lines, wintod->w - 2, erase_window_part (win[TOD].p, 1, title_lines, wintod->w - 2, wintod->h - 2);
wintod->h - 2); for (i = todolist; i != 0; i = i->next)
for (i = todolist; i != 0; i = i->next) { {
num_todo++; num_todo++;
t_realpos = num_todo - first; t_realpos = num_todo - first;
incolor = num_todo - hilt; incolor = num_todo - hilt;
if (incolor == 0) if (incolor == 0)
msgsav = i->mesg; msgsav = i->mesg;
if (t_realpos >= 0 && t_realpos < max_items) { 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); display_todo_item (incolor, i->mesg, i->id,
(i->note != NULL) ? 1 : 0, len, y_offset,
x_offset);
y_offset = y_offset + todo_lines; y_offset = y_offset + todo_lines;
} }
} }
/* Draw the scrollbar if necessary. */ /* Draw the scrollbar if necessary. */
if (todos > max_items){ if (todos > max_items)
{
float ratio = ((float) max_items) / ((float) todos); float ratio = ((float) max_items) / ((float) todos);
int sbar_length = (int) (ratio * (max_items + 1)); int sbar_length = (int) (ratio * (max_items + 1));
int highend = (int) (ratio * first); int highend = (int) (ratio * first);
@ -423,43 +448,43 @@ todo_update_panel(window_t *wintod, int which_pan)
if ((sbar_top + sbar_length) > wintod->h - 1) if ((sbar_top + sbar_length) > wintod->h - 1)
sbar_length = wintod->h - 1 - sbar_top; sbar_length = wintod->h - 1 - sbar_top;
draw_scrollbar(win[TOD].p, sbar_top, wintod->w - 2, draw_scrollbar (win[TOD].p, sbar_top, wintod->w - 2,
sbar_length, title_lines, wintod->h - 1, hilt_bar); sbar_length, title_lines, wintod->h - 1, hilt_bar);
} }
wnoutrefresh(win[TOD].p); wnoutrefresh (win[TOD].p);
} }
/* Attach a note to a todo */ /* Attach a note to a todo */
void void
todo_edit_note(char *editor) todo_edit_note (char *editor)
{ {
struct todo_s *i; struct todo_s *i;
char fullname[BUFSIZ]; char fullname[BUFSIZ];
char *filename; char *filename;
i = todo_get_item(hilt); i = todo_get_item (hilt);
if (i->note == NULL) { if (i->note == NULL)
if ((filename = new_tempfile(path_notes, NOTESIZ)) {
!= NULL) if ((filename = new_tempfile (path_notes, NOTESIZ)) != NULL)
i->note = filename; i->note = filename;
else else
return; return;
} }
snprintf(fullname, BUFSIZ, "%s%s", path_notes, i->note); snprintf (fullname, BUFSIZ, "%s%s", path_notes, i->note);
wins_launch_external(fullname, editor); wins_launch_external (fullname, editor);
} }
/* View a note previously attached to a todo */ /* View a note previously attached to a todo */
void void
todo_view_note(char *pager) todo_view_note (char *pager)
{ {
struct todo_s *i; struct todo_s *i;
char fullname[BUFSIZ]; char fullname[BUFSIZ];
i = todo_get_item(hilt); i = todo_get_item (hilt);
if (i->note == NULL) if (i->note == NULL)
return; return;
snprintf(fullname, BUFSIZ, "%s%s", path_notes, i->note); snprintf (fullname, BUFSIZ, "%s%s", path_notes, i->note);
wins_launch_external(fullname, pager); wins_launch_external (fullname, pager);
} }

View File

@ -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 * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -29,7 +29,8 @@
#include "wins.h" #include "wins.h"
struct todo_s { struct todo_s
{
struct todo_s *next; struct todo_s *next;
char *mesg; char *mesg;
int id; int id;
@ -38,24 +39,24 @@ struct todo_s {
extern struct todo_s *todolist; extern struct todo_s *todolist;
void todo_hilt_set(int); void todo_hilt_set (int);
void todo_hilt_decrease(void); void todo_hilt_decrease (void);
void todo_hilt_increase(void); void todo_hilt_increase (void);
int todo_hilt(void); int todo_hilt (void);
int todo_nb(void); int todo_nb (void);
void todo_set_nb(int); void todo_set_nb (int);
void todo_set_first(int); void todo_set_first (int);
void todo_first_increase(void); void todo_first_increase (void);
void todo_first_decrease(void); void todo_first_decrease (void);
int todo_hilt_pos(void); int todo_hilt_pos (void);
char *todo_saved_mesg(void); char *todo_saved_mesg (void);
void todo_new_item(void); void todo_new_item (void);
struct todo_s *todo_add(char *, int, char *); struct todo_s *todo_add (char *, int, char *);
void todo_delete(conf_t *); void todo_delete (conf_t *);
void todo_chg_priority(int); void todo_chg_priority (int);
void todo_edit_item(void); void todo_edit_item (void);
void todo_update_panel(window_t *, int); void todo_update_panel (window_t *, int);
void todo_edit_note(char *); void todo_edit_note (char *);
void todo_view_note(char *); void todo_view_note (char *);
#endif /* CALCURSE_TODO_H */ #endif /* CALCURSE_TODO_H */

File diff suppressed because it is too large Load Diff

View File

@ -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 * Calcurse - text-based organizer
@ -51,55 +51,61 @@
#define GETSTRING_ESC 1 /* user pressed escape to cancel editing */ #define GETSTRING_ESC 1 /* user pressed escape to cancel editing */
#define GETSTRING_RET 2 /* return was pressed without entering any text */ #define GETSTRING_RET 2 /* return was pressed without entering any text */
typedef struct { /* structure defining a keybinding */ typedef struct
{ /* structure defining a keybinding */
char *key; char *key;
char *label; char *label;
} binding_t; }
binding_t;
typedef enum { typedef enum
{
IERROR_FATAL, IERROR_FATAL,
IERROR_WARN IERROR_WARN
} ierror_sev_e; }
ierror_sev_e;
typedef enum { typedef enum
{
ERASE_DONT_FORCE, ERASE_DONT_FORCE,
ERASE_FORCE, ERASE_FORCE,
ERASE_FORCE_KEEP_NOTE, ERASE_FORCE_KEEP_NOTE,
ERASE_FORCE_ONLY_NOTE ERASE_FORCE_ONLY_NOTE
} erase_flag_e; }
erase_flag_e;
void exit_calcurse(int); void exit_calcurse (int);
void ierror(const char *, ierror_sev_e); void ierror (const char *, ierror_sev_e);
void aerror(const char *, int, const char *); void aerror (const char *, int, const char *);
void status_mesg(char *, char *); void status_mesg (char *, char *);
void erase_status_bar(void); void erase_status_bar (void);
void erase_window_part(WINDOW *, int, int, int, int); void erase_window_part (WINDOW *, int, int, int, int);
WINDOW *popup(int, int, int, int, char *); WINDOW *popup (int, int, int, int, char *);
void print_in_middle(WINDOW *, int, int, int, char *); void print_in_middle (WINDOW *, int, int, int, char *);
int getstring(WINDOW *, char *, int, int, int); int getstring (WINDOW *, char *, int, int, int);
int updatestring(WINDOW *, char **, int, int); int updatestring (WINDOW *, char **, int, int);
int is_all_digit(char *); int is_all_digit (char *);
void status_bar(void); void status_bar (void);
long date2sec(date_t, unsigned, unsigned); long date2sec (date_t, unsigned, unsigned);
char *date_sec2hour_str(long); char *date_sec2hour_str (long);
char *date_sec2date_str(long, char *); char *date_sec2date_str (long, char *);
void date_sec2ical_date(long, char *); void date_sec2ical_date (long, char *);
void date_sec2ical_datetime(long, char *); void date_sec2ical_datetime (long, char *);
long update_time_in_date(long, unsigned, unsigned); long update_time_in_date (long, unsigned, unsigned);
long get_sec_date(date_t); long get_sec_date (date_t);
long min2sec(unsigned); long min2sec (unsigned);
int check_time(char *); int check_time (char *);
void draw_scrollbar(WINDOW *, int, int, int, int, int, bool); void draw_scrollbar (WINDOW *, int, int, int, int, int, bool);
void item_in_popup(char *, char *, char *, char *); void item_in_popup (char *, char *, char *, char *);
void reset_status_page(void); void reset_status_page (void);
void other_status_page(int); void other_status_page (int);
long get_today(void); long get_today (void);
long now(void); long now (void);
char *mycpy(const char *); char *mycpy (const char *);
long mystrtol(const char *); long mystrtol (const char *);
void print_option_incolor(WINDOW *, bool, int, int); void print_option_incolor (WINDOW *, bool, int, int);
char *new_tempfile(const char *, int); char *new_tempfile (const char *, int);
void erase_note(char **, erase_flag_e); void erase_note (char **, erase_flag_e);
int parse_date(char *, int, int *, int *, int *); int parse_date (char *, int, int *, int *, int *);
#endif /* CALCURSE_UTILS_H */ #endif /* CALCURSE_UTILS_H */

View File

@ -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 * Calcurse - text-based organizer
@ -45,8 +45,8 @@ bool colorize = false;
* variables to store calendar names * variables to store calendar names
*/ */
int days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
char *monthnames[12] = char *monthnames[12] = {
{ N_("January"), N_("January"),
N_("February"), N_("February"),
N_("March"), N_("March"),
N_("April"), N_("April"),
@ -57,17 +57,19 @@ char *monthnames[12] =
N_("September"), N_("September"),
N_("October"), N_("October"),
N_("November"), N_("November"),
N_("December") }; N_("December")
};
char *daynames[8] = char *daynames[8] = {
{ N_("Sun"), N_("Sun"),
N_("Mon"), N_("Mon"),
N_("Tue"), N_("Tue"),
N_("Wed"), N_("Wed"),
N_("Thu"), N_("Thu"),
N_("Fri"), N_("Fri"),
N_("Sat"), N_("Sat"),
N_("Sun") }; N_("Sun")
};
/* /*
* variables to store data path names, which are initialized in * variables to store data path names, which are initialized in
@ -85,12 +87,11 @@ struct pad_s *apad;
/* Variable to store notify-bar settings. */ /* Variable to store notify-bar settings. */
struct nbar_s *nbar; struct nbar_s *nbar;
/* /*
* Variables init * Variables init
*/ */
void void
vars_init(conf_t *conf) vars_init (conf_t *conf)
{ {
char *PATH_VI = "/usr/bin/vi"; char *PATH_VI = "/usr/bin/vi";
char *PATH_LESS = "/usr/bin/less"; char *PATH_LESS = "/usr/bin/less";
@ -102,34 +103,34 @@ vars_init(conf_t *conf)
conf->auto_save = true; conf->auto_save = true;
conf->skip_system_dialogs = false; conf->skip_system_dialogs = false;
conf->skip_progress_bar = false; conf->skip_progress_bar = false;
strncpy(conf->output_datefmt, "%D", 3); strncpy (conf->output_datefmt, "%D", 3);
conf->input_datefmt = 1; conf->input_datefmt = 1;
/* Default external editor and pager */ /* Default external editor and pager */
ed = getenv("VISUAL"); ed = getenv ("VISUAL");
if (ed == NULL || ed[0] == '\0') if (ed == NULL || ed[0] == '\0')
ed = getenv("EDITOR"); ed = getenv ("EDITOR");
if (ed == NULL || ed[0] == '\0') if (ed == NULL || ed[0] == '\0')
ed = PATH_VI; ed = PATH_VI;
conf->editor = ed; conf->editor = ed;
pg = getenv("PAGER"); pg = getenv ("PAGER");
if (pg == NULL || pg[0] == '\0') if (pg == NULL || pg[0] == '\0')
pg = PATH_LESS; pg = PATH_LESS;
conf->pager = pg; conf->pager = pg;
wins_set_layout(1); wins_set_layout (1);
calendar_set_first_day_of_week(MONDAY); calendar_set_first_day_of_week (MONDAY);
/* Pad structure to scroll text inside the appointment panel */ /* Pad structure to scroll text inside the appointment panel */
apad = (struct pad_s *) malloc(sizeof(struct pad_s)); apad = (struct pad_s *) malloc (sizeof (struct pad_s));
apad->length = 1; apad->length = 1;
apad->first_onscreen = 0; apad->first_onscreen = 0;
/* Attribute definitions for color and non-color terminals */ /* Attribute definitions for color and non-color terminals */
custom_init_attr(); custom_init_attr ();
/* Start at the current date */ /* Start at the current date */
calendar_init_slctd_day(); calendar_init_slctd_day ();
} }

View File

@ -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 * Calcurse - text-based organizer
@ -61,14 +61,16 @@
#define DATEFMT_DESC(datefmt) (datefmt == 1 ? _("mm/dd/yyyy") : \ #define DATEFMT_DESC(datefmt) (datefmt == 1 ? _("mm/dd/yyyy") : \
(datefmt == 2 ? _("dd/mm/yyyy") : _("yyyy/mm/dd"))) (datefmt == 2 ? _("dd/mm/yyyy") : _("yyyy/mm/dd")))
struct pad_s { struct pad_s
{
int width; int width;
int length; int length;
int first_onscreen; /* first line to be displayed inside window */ int first_onscreen; /* first line to be displayed inside window */
WINDOW *ptrwin; /* pointer to the pad window */ WINDOW *ptrwin; /* pointer to the pad window */
}; };
struct nbar_s { struct nbar_s
{
int show; /* display or hide the notify-bar */ int show; /* display or hide the notify-bar */
int cntdwn; /* warn when time left before next app int cntdwn; /* warn when time left before next app
* becomes lesser than cntdwn */ * becomes lesser than cntdwn */
@ -80,7 +82,8 @@ struct nbar_s {
}; };
/* General configuration variables */ /* General configuration variables */
typedef struct { typedef struct
{
bool auto_save; bool auto_save;
bool confirm_quit; bool confirm_quit;
bool confirm_delete; bool confirm_delete;
@ -90,7 +93,8 @@ typedef struct {
char *pager; char *pager;
char output_datefmt[BUFSIZ]; /* format for displaying date */ char output_datefmt[BUFSIZ]; /* format for displaying date */
int input_datefmt; /* format for reading date */ int input_datefmt; /* format for reading date */
} conf_t; }
conf_t;
extern int col, row; extern int col, row;
extern bool colorize; extern bool colorize;
@ -105,6 +109,6 @@ extern char path_notes[BUFSIZ];
extern struct pad_s *apad; extern struct pad_s *apad;
extern struct nbar_s *nbar; extern struct nbar_s *nbar;
void vars_init(conf_t *conf); void vars_init (conf_t *conf);
#endif /* CALCURSE_VARS_H */ #endif /* CALCURSE_VARS_H */

View File

@ -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 * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -42,42 +42,42 @@ static int layout;
/* Get the current layout. */ /* Get the current layout. */
int int
wins_layout(void) wins_layout (void)
{ {
return (layout); return (layout);
} }
/* Set the current layout. */ /* Set the current layout. */
void void
wins_set_layout(int nb) wins_set_layout (int nb)
{ {
layout = nb; layout = nb;
} }
/* Initialize the selected window in calcurse's interface. */ /* Initialize the selected window in calcurse's interface. */
void void
wins_slctd_init(void) wins_slctd_init (void)
{ {
wins_slctd_set(CAL); wins_slctd_set (CAL);
} }
/* Returns an enum which corresponds to the window which is selected. */ /* Returns an enum which corresponds to the window which is selected. */
window_e window_e
wins_slctd(void) wins_slctd (void)
{ {
return (slctd_win); return (slctd_win);
} }
/* Sets the selected window. */ /* Sets the selected window. */
void void
wins_slctd_set(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. */ /* TAB key was hit in the interface, need to select next window. */
void void
wins_slctd_next(void) wins_slctd_next (void)
{ {
if (slctd_win == TOD) if (slctd_win == TOD)
slctd_win = CAL; slctd_win = CAL;
@ -87,7 +87,7 @@ wins_slctd_next(void)
/* Create all the windows. */ /* Create all the windows. */
void void
wins_init(void) wins_init (void)
{ {
char label[BUFSIZ]; char label[BUFSIZ];
@ -95,27 +95,27 @@ wins_init(void)
* Create the three main windows plus the status bar and the pad used to * Create the three main windows plus the status bar and the pad used to
* display appointments and event. * display appointments and event.
*/ */
win[CAL].p = newwin(CALHEIGHT, CALWIDTH, win[CAL].y, win[CAL].x); win[CAL].p = newwin (CALHEIGHT, CALWIDTH, win[CAL].y, win[CAL].x);
snprintf(label, BUFSIZ, _("Calendar")); snprintf (label, BUFSIZ, _("Calendar"));
wins_show(win[CAL].p, label); wins_show (win[CAL].p, label);
win[APP].p = newwin(win[APP].h, win[APP].w, win[APP].y, win[APP].x); win[APP].p = newwin (win[APP].h, win[APP].w, win[APP].y, win[APP].x);
snprintf(label, BUFSIZ, _("Appointments")); snprintf (label, BUFSIZ, _("Appointments"));
wins_show(win[APP].p, label); wins_show (win[APP].p, label);
apad->width = win[APP].w - 3; apad->width = win[APP].w - 3;
apad->ptrwin = newpad(apad->length, apad->width); apad->ptrwin = newpad (apad->length, apad->width);
win[TOD].p = newwin(win[TOD].h, win[TOD].w, win[TOD].y, win[TOD].x); win[TOD].p = newwin (win[TOD].h, win[TOD].w, win[TOD].y, win[TOD].x);
snprintf(label, BUFSIZ, _("ToDo")); snprintf (label, BUFSIZ, _("ToDo"));
wins_show(win[TOD].p, label); wins_show (win[TOD].p, label);
win[STA].p = newwin(win[STA].h, win[STA].w, win[STA].y, win[STA].x); win[STA].p = newwin (win[STA].h, win[STA].w, win[STA].y, win[STA].x);
/* Enable function keys (i.e. arrow keys) in those windows */ /* Enable function keys (i.e. arrow keys) in those windows */
keypad(win[CAL].p, TRUE); keypad (win[CAL].p, TRUE);
keypad(win[APP].p, TRUE); keypad (win[APP].p, TRUE);
keypad(win[TOD].p, TRUE); keypad (win[TOD].p, TRUE);
keypad(win[STA].p, TRUE); keypad (win[STA].p, TRUE);
} }
/* /*
@ -123,45 +123,44 @@ wins_init(void)
* size and placement. * size and placement.
*/ */
void void
wins_reinit(void) wins_reinit (void)
{ {
delwin(win[STA].p); delwin (win[STA].p);
delwin(win[CAL].p); delwin (win[CAL].p);
delwin(win[APP].p); delwin (win[APP].p);
delwin(apad->ptrwin); delwin (apad->ptrwin);
delwin(win[TOD].p); delwin (win[TOD].p);
wins_get_config(); wins_get_config ();
wins_init(); wins_init ();
if (notify_bar()) if (notify_bar ())
notify_reinit_bar(win[NOT].h, win[NOT].w, win[NOT].y, notify_reinit_bar (win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x);
win[NOT].x);
} }
/* Show the window with a border and a label. */ /* Show the window with a border and a label. */
void void
wins_show(WINDOW * win, char *label) wins_show (WINDOW *win, char *label)
{ {
int startx, starty, height, width; int startx, starty, height, width;
getbegyx(win, starty, startx); getbegyx (win, starty, startx);
getmaxyx(win, height, width); getmaxyx (win, height, width);
box(win, 0, 0); box (win, 0, 0);
mvwaddch(win, 2, 0, ACS_LTEE); mvwaddch (win, 2, 0, ACS_LTEE);
mvwhline(win, 2, 1, ACS_HLINE, width - 2); mvwhline (win, 2, 1, ACS_HLINE, width - 2);
mvwaddch(win, 2, width - 1, ACS_RTEE); mvwaddch (win, 2, width - 1, ACS_RTEE);
print_in_middle(win, 1, 0, width, label); print_in_middle (win, 1, 0, width, label);
} }
/* /*
* Get the screen size and recalculate the windows configurations. * Get the screen size and recalculate the windows configurations.
*/ */
void void
wins_get_config(void) wins_get_config (void)
{ {
/* Get the screen configuration */ /* Get the screen configuration */
getmaxyx(stdscr, row, col); getmaxyx (stdscr, row, col);
/* fixed values for status, notification bars and calendar */ /* fixed values for status, notification bars and calendar */
win[STA].h = STATUSHEIGHT; win[STA].h = STATUSHEIGHT;
@ -169,24 +168,30 @@ wins_get_config(void)
win[STA].y = row - win[STA].h; win[STA].y = row - win[STA].h;
win[STA].x = 0; win[STA].x = 0;
if (notify_bar()) { if (notify_bar ())
{
win[NOT].h = 1; win[NOT].h = 1;
win[NOT].w = col; win[NOT].w = col;
win[NOT].y = win[STA].y - 1; win[NOT].y = win[STA].y - 1;
win[NOT].x = 0; win[NOT].x = 0;
} else { }
else
{
win[NOT].h = 0; win[NOT].h = 0;
win[NOT].w = 0; win[NOT].w = 0;
win[NOT].y = 0; win[NOT].y = 0;
win[NOT].x = 0; win[NOT].x = 0;
} }
if (layout <= 4) { /* APPOINTMENT is the biggest panel */ if (layout <= 4)
{ /* APPOINTMENT is the biggest panel */
win[APP].w = col - CALWIDTH; win[APP].w = col - CALWIDTH;
win[APP].h = row - (win[STA].h + win[NOT].h); win[APP].h = row - (win[STA].h + win[NOT].h);
win[TOD].w = CALWIDTH; win[TOD].w = CALWIDTH;
win[TOD].h = row - (CALHEIGHT + win[STA].h + win[NOT].h); win[TOD].h = row - (CALHEIGHT + win[STA].h + win[NOT].h);
} else { /* TODO is the biggest panel */ }
else
{ /* TODO is the biggest panel */
win[TOD].w = col - CALWIDTH; win[TOD].w = col - CALWIDTH;
win[TOD].h = row - (win[STA].h + win[NOT].h); win[TOD].h = row - (win[STA].h + win[NOT].h);
win[APP].w = CALWIDTH; win[APP].w = CALWIDTH;
@ -194,7 +199,8 @@ wins_get_config(void)
} }
/* defining the layout */ /* defining the layout */
switch (layout) { switch (layout)
{
case 1: case 1:
win[APP].y = 0; win[APP].y = 0;
win[APP].x = 0; win[APP].x = 0;
@ -264,50 +270,57 @@ wins_get_config(void)
/* draw panel border in color */ /* draw panel border in color */
static void static void
border_color(WINDOW *window) border_color (WINDOW *window)
{ {
int color_attr = A_BOLD; int color_attr = A_BOLD;
int no_color_attr = A_BOLD; int no_color_attr = A_BOLD;
if (colorize) { if (colorize)
wattron(window, color_attr | COLOR_PAIR(COLR_CUSTOM)); {
box(window, 0, 0); wattron (window, color_attr | COLOR_PAIR (COLR_CUSTOM));
} else { box (window, 0, 0);
wattron(window, no_color_attr);
box(window, 0, 0);
} }
else
if (colorize) { {
wattroff(window, color_attr | COLOR_PAIR(COLR_CUSTOM)); wattron (window, no_color_attr);
} else { box (window, 0, 0);
wattroff(window, no_color_attr);
} }
if (colorize)
wnoutrefresh(window); {
wattroff (window, color_attr | COLOR_PAIR (COLR_CUSTOM));
}
else
{
wattroff (window, no_color_attr);
}
wnoutrefresh (window);
} }
/* draw panel border without any color */ /* draw panel border without any color */
static void static void
border_nocolor(WINDOW *window) border_nocolor (WINDOW *window)
{ {
int color_attr = A_BOLD; int color_attr = A_BOLD;
int no_color_attr = A_DIM; int no_color_attr = A_DIM;
if (colorize) { if (colorize)
wattron(window, color_attr | COLOR_PAIR(COLR_DEFAULT)); {
} else { wattron (window, color_attr | COLOR_PAIR (COLR_DEFAULT));
wattron(window, no_color_attr);
} }
else
box(window, 0, 0); {
wattron (window, no_color_attr);
if (colorize) {
wattroff(window, color_attr | COLOR_PAIR(COLR_DEFAULT));
} else {
wattroff(window, no_color_attr);
} }
box (window, 0, 0);
wnoutrefresh(window); if (colorize)
{
wattroff (window, color_attr | COLOR_PAIR (COLR_DEFAULT));
}
else
{
wattroff (window, no_color_attr);
}
wnoutrefresh (window);
} }
/* /*
@ -315,53 +328,53 @@ border_nocolor(WINDOW *window)
* selected window. * selected window.
*/ */
void void
wins_update(void) wins_update (void)
{ {
switch (slctd_win) { switch (slctd_win)
{
case CAL: case CAL:
border_color(win[CAL].p); border_color (win[CAL].p);
border_nocolor(win[APP].p); border_nocolor (win[APP].p);
border_nocolor(win[TOD].p); border_nocolor (win[TOD].p);
break; break;
case APP: case APP:
border_color(win[APP].p); border_color (win[APP].p);
border_nocolor(win[CAL].p); border_nocolor (win[CAL].p);
border_nocolor(win[TOD].p); border_nocolor (win[TOD].p);
break; break;
case TOD: case TOD:
border_color(win[TOD].p); border_color (win[TOD].p);
border_nocolor(win[APP].p); border_nocolor (win[APP].p);
border_nocolor(win[CAL].p); border_nocolor (win[CAL].p);
break; break;
default: default:
ierror(_("FATAL ERROR in wins_update: no window selected\n"), ierror (_("FATAL ERROR in wins_update: no window selected\n"),
IERROR_FATAL); IERROR_FATAL);
/* NOTREACHED */ /* NOTREACHED */
} }
apoint_update_panel(&win[APP], slctd_win); apoint_update_panel (&win[APP], slctd_win);
todo_update_panel(&win[TOD], slctd_win); todo_update_panel (&win[TOD], slctd_win);
calendar_update_panel(win[CAL].p); calendar_update_panel (win[CAL].p);
status_bar(); status_bar ();
if (notify_bar()) if (notify_bar ())
notify_update_bar(); notify_update_bar ();
wmove(win[STA].p, 0, 0); wmove (win[STA].p, 0, 0);
doupdate(); doupdate ();
} }
/* Reset the screen, needed when resizing terminal for example. */ /* Reset the screen, needed when resizing terminal for example. */
void void
wins_reset(void) wins_reset (void)
{ {
endwin(); endwin ();
refresh(); refresh ();
curs_set(0); curs_set (0);
wins_reinit(); wins_reinit ();
wins_update(); wins_update ();
} }
/* /*
@ -369,30 +382,32 @@ wins_reset(void)
* file. * file.
*/ */
void void
wins_launch_external(const char *file, const char *cmd) wins_launch_external (const char *file, const char *cmd)
{ {
char *p; char *p;
int len; int len;
len = strlen(file) + strlen(cmd) + 2; /* Beware of space between cmd and /* Beware of space between cmd and file. */
file. */ len = strlen (file) + strlen (cmd) + 2;
p = (char *)malloc(sizeof(char) * len);
if (snprintf(p, len, "%s %s", cmd, file) == -1) { p = (char *) malloc (sizeof (char) * len);
free(p); if (snprintf (p, len, "%s %s", cmd, file) == -1)
{
free (p);
return; return;
} }
if (notify_bar()) if (notify_bar ())
notify_stop_main_thread(); notify_stop_main_thread ();
def_prog_mode(); def_prog_mode ();
endwin(); endwin ();
clear(); clear ();
refresh(); refresh ();
system(p); system (p);
reset_prog_mode(); reset_prog_mode ();
clearok(curscr, TRUE); clearok (curscr, TRUE);
curs_set(0); curs_set (0);
refresh(); refresh ();
if (notify_bar()) if (notify_bar ())
notify_start_main_thread(); notify_start_main_thread ();
free(p); free (p);
} }

View File

@ -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 * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -29,38 +29,42 @@
#include "vars.h" #include "vars.h"
typedef enum { typedef enum
{
CAL, CAL,
APP, APP,
TOD, TOD,
NOT, NOT,
STA, STA,
NBWINS NBWINS
} window_e; }
window_e;
/* Window properties */ /* Window properties */
typedef struct { typedef struct
{
WINDOW *p; /* pointer to window */ WINDOW *p; /* pointer to window */
unsigned w; /* width */ unsigned w; /* width */
unsigned h; /* height */ unsigned h; /* height */
int x; /* x position */ int x; /* x position */
int y; /* y position */ int y; /* y position */
} window_t; }
window_t;
extern window_t win[NBWINS]; extern window_t win[NBWINS];
int wins_layout(void); int wins_layout (void);
void wins_set_layout(int); void wins_set_layout (int);
void wins_slctd_init(void); void wins_slctd_init (void);
window_e wins_slctd(void); window_e wins_slctd (void);
void wins_slctd_set(window_e); void wins_slctd_set (window_e);
void wins_slctd_next(void); void wins_slctd_next (void);
void wins_init(void); void wins_init (void);
void wins_reinit(void); void wins_reinit (void);
void wins_show(WINDOW *, char *); void wins_show (WINDOW *, char *);
void wins_get_config(void); void wins_get_config (void);
void wins_update(void); void wins_update (void);
void wins_reset(void); void wins_reset (void);
void wins_launch_external(const char *, const char *); void wins_launch_external (const char *, const char *);
#endif /* CALCURSE_WINS_H */ #endif /* CALCURSE_WINS_H */