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
@ -49,7 +49,7 @@ apoint_llist_init(void)
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. */
@ -93,8 +93,10 @@ apoint_new(char *mesg, char *note, long start, long dur, char state)
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;
@ -103,7 +105,7 @@ apoint_new(char *mesg, char *note, long start, long dur, char state)
} }
pthread_mutex_unlock (&(alist_p->mutex)); pthread_mutex_unlock (&(alist_p->mutex));
return o; return (o);
} }
/* /*
@ -114,11 +116,16 @@ 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, ""); status_mesg (mesg_1, "");
if (getstring(win[STA].p, item_time, LTIME, 0, 1) != if (getstring (win[STA].p, item_time, LTIME, 0, 1) != GETSTRING_ESC)
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) { }
else if (check_time (item_time) != 1)
{
status_mesg (format_message_1, enter_str); status_mesg (format_message_1, enter_str);
wgetch (win[STA].p); wgetch (win[STA].p);
} else }
else
sscanf (item_time, "%u:%u", &heures, &minutes); sscanf (item_time, "%u:%u", &heures, &minutes);
} else }
else
return; return;
} }
/* /*
@ -151,55 +164,58 @@ 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, ""); status_mesg (mesg_2, "");
if (getstring(win[STA].p, item_time, LTIME, 0, 1) != if (getstring (win[STA].p, item_time, LTIME, 0, 1) != GETSTRING_VALID)
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); status_mesg (format_message_2, enter_str);
wgetch (win[STA].p); wgetch (win[STA].p);
} else { }
else
{
if (check_time (item_time) == 2) if (check_time (item_time) == 2)
apoint_duration = atoi (item_time); apoint_duration = atoi (item_time);
else if (check_time(item_time) == 1) { else if (check_time (item_time) == 1)
sscanf(item_time, "%u:%u", {
&end_h, &end_m); sscanf (item_time, "%u:%u", &end_h, &end_m);
if (end_h < heures){ if (end_h < heures)
apoint_duration = {
MININSEC - minutes + end_m apoint_duration = MININSEC - minutes + end_m
+ + (24 + end_h - (heures + 1)) * MININSEC;
(24 + end_h - (heures + 1)) }
* MININSEC; else
} else { {
apoint_duration = apoint_duration = MININSEC - minutes
MININSEC - minutes + + end_m + (end_h - (heures + 1)) * 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++;
@ -223,43 +239,48 @@ apoint_delete(conf_t *conf, unsigned *nb_events, unsigned *nb_apoints)
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); status_mesg (del_app_str, choices);
answer = wgetch (win[STA].p); answer = wgetch (win[STA].p);
if ((answer == 'y') && (nb_items != 0)) 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 }
else
ierror (errmsg, IERROR_FATAL); 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;
} }
@ -269,10 +290,11 @@ 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
@ -282,21 +304,25 @@ apoint_sec2str(apoint_llist_node_t *o, int type, long day, char *start,
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); strncpy (start, "..:..", 6);
} else { }
else
{
t = o->start; t = o->start;
lt = localtime (&t); lt = localtime (&t);
snprintf(start, HRMIN_SIZE, "%02u:%02u", lt->tm_hour, snprintf (start, HRMIN_SIZE, "%02u:%02u", lt->tm_hour, lt->tm_min);
lt->tm_min);
} }
if (o->start + o->dur > day + DAYINSEC && type == APPT) { if (o->start + o->dur > day + DAYINSEC && type == APPT)
{
strncpy (end, "..:..", 6); strncpy (end, "..:..", 6);
} else { }
else
{
t = o->start + o->dur; t = o->start + o->dur;
lt = localtime (&t); lt = localtime (&t);
snprintf(end, HRMIN_SIZE, "%02u:%02u", lt->tm_hour, snprintf (end, HRMIN_SIZE, "%02u:%02u", lt->tm_hour, lt->tm_min);
lt->tm_min);
} }
} }
@ -309,14 +335,14 @@ apoint_write(apoint_llist_node_t *o, FILE * f)
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);
@ -342,7 +368,8 @@ apoint_scan(FILE * f, struct tm start, struct tm end, char state, char *note)
/* 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';
} }
@ -355,8 +382,10 @@ apoint_scan(FILE * f, struct tm start, struct tm end, char state, char *note)
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); {
fputs (_("FATAL ERROR in apoint_scan: date error in the appointment\n"),
stderr);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
return (apoint_new (buf, note, tstart, tend - tstart, state)); return (apoint_new (buf, note, tstart, tend - tstart, state));
@ -370,10 +399,12 @@ apoint_get(long day, int pos)
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++;
} }
} }
@ -392,15 +423,18 @@ apoint_delete_bynum(long start, unsigned num, erase_flag_e flag)
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 ()) if (notify_bar ())
need_check_notify = need_check_notify = notify_same_item (i->start);
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);
@ -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;
} }
@ -487,12 +521,17 @@ 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) { {
if (i->start > app->time)
{
pthread_mutex_unlock (&(alist_p->mutex)); pthread_mutex_unlock (&(alist_p->mutex));
return app; return (app);
} else { }
if (i->start > start) { 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;
@ -502,7 +541,7 @@ apoint_check_next(struct notify_app_s *app, long start)
} }
pthread_mutex_unlock (&(alist_p->mutex)); pthread_mutex_unlock (&(alist_p->mutex));
return app; return (app);
} }
/* /*
@ -519,7 +558,7 @@ apoint_recur_s2apoint_s(recur_apoint_llist_node_t *p)
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);
} }
/* /*
@ -539,25 +578,30 @@ apoint_switch_notify(void)
date = calendar_get_slctd_day_sec (); date = calendar_get_slctd_day_sec ();
if (p->type == RECUR_APPT) { if (p->type == RECUR_APPT)
{
recur_apoint_switch_notify (date, p->appt_pos); recur_apoint_switch_notify (date, p->appt_pos);
return; return;
} else if (p->type == APPT) }
else if (p->type == APPT)
apoint_nb = day_item_nb (date, hilt, APPT); apoint_nb = day_item_nb (date, hilt, APPT);
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, {
apoint->start, apoint->state); notify_check_added (apoint->mesg, apoint->start,
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 ();
@ -569,8 +613,7 @@ apoint_switch_notify(void)
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);
} }
@ -595,8 +638,7 @@ apoint_update_panel(window_t *winapp, int which_pan)
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]),
@ -604,7 +646,8 @@ apoint_update_panel(window_t *winapp, int which_pan)
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);
@ -620,5 +663,6 @@ apoint_update_panel(window_t *winapp, int which_pan)
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,19 +39,23 @@
#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;
@ -64,8 +68,8 @@ 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);

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
@ -48,17 +48,15 @@ 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);
} }
@ -70,11 +68,10 @@ 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);
} }
@ -121,8 +118,7 @@ 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);
@ -151,9 +147,12 @@ print_notefile(FILE *out, char *filename, int nbtab)
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)
{
if (printlinestarter)
{
fputs (linestarter, out); fputs (linestarter, out);
printlinestarter = 0; printlinestarter = 0;
} }
@ -163,7 +162,9 @@ print_notefile(FILE *out, char *filename, int nbtab)
} }
fputs ("\n", out); fputs ("\n", out);
fclose (notefile); fclose (notefile);
} else { }
else
{
fputs (linestarter, out); fputs (linestarter, out);
fputs (_("No note file found\n"), out); fputs (_("No note file found\n"), out);
} }
@ -181,9 +182,12 @@ todo_arg(int priority, int print_note)
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)
{
if (title)
{
fputs (_("to do:\n"), stdout); fputs (_("to do:\n"), stdout);
title = 0; title = 0;
} }
@ -210,17 +214,17 @@ 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);
} }
@ -271,33 +275,42 @@ 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;
} }
@ -311,21 +324,24 @@ app_arg(int add_line, date_t *day, long date, int print_note, conf_t *conf)
/* 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);
@ -340,19 +356,22 @@ app_arg(int add_line, date_t *day, long date, int print_note, conf_t *conf)
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);
@ -366,7 +385,7 @@ app_arg(int add_line, date_t *day, long date, int print_note, conf_t *conf)
} }
pthread_mutex_unlock (&(alist_p->mutex)); pthread_mutex_unlock (&(alist_p->mutex));
return app_found; return (app_found);
} }
/* /*
@ -388,8 +407,10 @@ date_arg(char *ddate, int add_line, int print_note, conf_t *conf)
* 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 */
for (i = 0; i <= arg_len - 1; i++)
{
if (isdigit (ddate[i])) if (isdigit (ddate[i]))
num_digit++; num_digit++;
} }
@ -404,7 +425,8 @@ date_arg(char *ddate, int add_line, int print_note, conf_t *conf)
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;
@ -414,22 +436,26 @@ date_arg(char *ddate, int add_line, int print_note, conf_t *conf)
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 */
if (parse_date (ddate, conf->input_datefmt, &day.yyyy, &day.mm, &day.dd))
{
app_found = app_arg (add_line, &day, 0, print_note, conf); app_found = app_arg (add_line, &day, 0, print_note, conf);
} else { }
fputs(_("Argument to the '-d' flag is not valid\n"), else
stdout); {
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,
"Possible argument format are: '%s' or 'n'\n",
DATEFMT_DESC (conf->input_datefmt)); DATEFMT_DESC (conf->input_datefmt));
fputs (_(outstr), stdout); fputs (_(outstr), stdout);
fputs(_("\nFor more information, type '?' from within Calcurse, or read the manpage.\n"), fputs (_("\nFor more information, type '?' from within Calcurse, "
stdout); "or read the manpage.\n"),
fputs
(_("Mail bug reports and suggestions to <calcurse@culot.org>.\n"),
stdout); stdout);
fputs (_("Mail bug reports and suggestions to "
"<calcurse@culot.org>.\n"), stdout);
} }
} }
} }
@ -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); tnum = atoi (optarg);
if (tnum < 1 || tnum > 9) { if (tnum < 1 || tnum > 9)
{
usage (); usage ();
usage_try (); usage_try ();
return EXIT_FAILURE; return (EXIT_FAILURE);
} }
} else }
else
tnum = 0; tnum = 0;
break; break;
case 'v': case 'v':
@ -538,48 +569,66 @@ 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 ();
usage_try (); usage_try ();
return EXIT_FAILURE; return (EXIT_FAILURE);
} else { /* Incorrect arguments */
if (unknown_flag) { }
else
{
if (unknown_flag)
{
non_interactive = 1; non_interactive = 1;
} else if (hflag) { }
else if (hflag)
{
help_arg (); help_arg ();
non_interactive = 1; non_interactive = 1;
} else if (vflag) { }
else if (vflag)
{
version_arg (); version_arg ();
non_interactive = 1; non_interactive = 1;
} else if (multiple_flag) { }
if (load_data) { else if (multiple_flag)
{
if (load_data)
{
io_init (cfile); io_init (cfile);
no_file = io_check_data_files (); no_file = io_check_data_files ();
if (dflag || aflag || nflag || xflag) if (dflag || aflag || nflag || xflag)
io_load_app (); io_load_app ();
} }
if (xflag) { if (xflag)
{
notify_init_vars (); notify_init_vars ();
custom_load_conf (conf, 0); custom_load_conf (conf, 0);
io_export_data (IO_EXPORT_NONINTERACTIVE, conf); 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 (); notify_init_vars ();
vars_init (conf); vars_init (conf);
custom_load_conf (conf, 0); custom_load_conf (conf, 0);
date_arg (ddate, add_line, Nflag, conf); 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 ();
@ -588,7 +637,9 @@ parse_args(int argc, char **argv, conf_t *conf)
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 ();

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

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
@ -99,14 +99,16 @@ main(int argc, char **argv)
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;
} }
@ -123,7 +125,9 @@ main(int argc, char **argv)
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;
} }
@ -145,7 +149,8 @@ main(int argc, char **argv)
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_start_main_thread ();
notify_check_next_app (); notify_check_next_app ();
} }
@ -157,13 +162,12 @@ main(int argc, char **argv)
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;
@ -177,7 +181,8 @@ main(int argc, char **argv)
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);
@ -192,7 +197,8 @@ main(int argc, char **argv)
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);
@ -200,8 +206,8 @@ main(int argc, char **argv)
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);
@ -230,25 +236,26 @@ main(int argc, char **argv)
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;
@ -287,7 +294,8 @@ main(int argc, char **argv)
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;
@ -314,8 +322,7 @@ main(int argc, char **argv)
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;
@ -336,13 +343,13 @@ main(int argc, char **argv)
case '+': case '+':
case '-': case '-':
if (wins_slctd() == TOD && todo_hilt() != 0) { if (wins_slctd () == TOD && todo_hilt () != 0)
{
todo_chg_priority (ch); todo_chg_priority (ch);
if (todo_hilt_pos () < 0) if (todo_hilt_pos () < 0)
todo_set_first (todo_hilt ()); todo_set_first (todo_hilt ());
else if (todo_hilt_pos () >= win[TOD].h - 4) else if (todo_hilt_pos () >= win[TOD].h - 4)
todo_set_first(todo_hilt() - todo_set_first (todo_hilt () - win[TOD].h + 5);
win[TOD].h + 5);
} }
break; break;
@ -383,7 +390,8 @@ main(int argc, char **argv)
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);
@ -394,7 +402,8 @@ main(int argc, char **argv)
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);
@ -405,17 +414,21 @@ main(int argc, char **argv)
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)) { {
if ((wins_slctd () == APP) && (apoint_hilt () > 1))
{
apoint_hilt_decrease (); apoint_hilt_decrease ();
apoint_scroll_pad_up (inday.nb_events); apoint_scroll_pad_up (inday.nb_events);
} else if ((wins_slctd() == TOD) && }
(todo_hilt() > 1)) { else if ((wins_slctd () == TOD) && (todo_hilt () > 1))
{
todo_hilt_decrease (); todo_hilt_decrease ();
if (todo_hilt_pos () < 0) if (todo_hilt_pos () < 0)
todo_first_decrease (); todo_first_decrease ();
@ -427,20 +440,22 @@ main(int argc, char **argv)
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())) { {
if ((wins_slctd () == APP) &&
(apoint_hilt () < inday.nb_events + inday.nb_apoints))
{
apoint_hilt_increase ();
apoint_scroll_pad_down (inday.nb_events, win[APP].h);
}
if ((wins_slctd () == TOD) && (todo_hilt () < todo_nb ()))
{
todo_hilt_increase (); todo_hilt_increase ();
if (todo_hilt_pos () == win[TOD].h - 4) if (todo_hilt_pos () == win[TOD].h - 4)
todo_first_increase (); todo_first_increase ();
@ -453,16 +468,19 @@ main(int argc, char **argv)
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); status_mesg (_(quit_message), choices);
ch = wgetch (win[STA].p); ch = wgetch (win[STA].p);
if (ch == 'y') if (ch == 'y')
exit_calcurse (EXIT_SUCCESS); exit_calcurse (EXIT_SUCCESS);
else { else
{
erase_status_bar (); erase_status_bar ();
break; break;
} }
} else }
else
exit_calcurse (EXIT_SUCCESS); exit_calcurse (EXIT_SUCCESS);
break; break;
@ -471,11 +489,13 @@ 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) &&

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
@ -67,10 +67,12 @@ 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);
} }
@ -118,7 +120,8 @@ calendar_set_current_date(void)
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;
@ -242,20 +245,19 @@ calendar_update_panel(WINDOW *cwin)
* 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]));
} }
@ -263,63 +265,64 @@ calendar_update_panel(WINDOW *cwin)
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 && else if (c_day == slctd_day.dd &&
( (current_day.dd != slctd_day.dd) || ((current_day.dd != slctd_day.dd)
(current_day.mm != slctd_day.mm) || (current_day.mm != slctd_day.mm)
|| (current_day.yyyy != slctd_day.yyyy))) { || (current_day.yyyy != slctd_day.yyyy)))
{
/* This is the selected day, print it in red. */ /* This is the selected day, print it in red. */
custom_apply_attr (cwin, ATTR_MIDDLE); custom_apply_attr (cwin, ATTR_MIDDLE);
mvwprintw(cwin, ofs_y + 1, mvwprintw (cwin, ofs_y + 1, ofs_x + day_1_sav + 4 * c_day + 1, "%2d",
ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day); c_day);
custom_remove_attr (cwin, ATTR_MIDDLE); custom_remove_attr (cwin, ATTR_MIDDLE);
}
} else if (c_day == slctd_day.dd && else if (c_day == slctd_day.dd && current_day.dd == slctd_day.dd
current_day.dd == slctd_day.dd && && current_day.mm == slctd_day.mm
current_day.mm == slctd_day.mm && && current_day.yyyy == slctd_day.yyyy)
current_day.yyyy == slctd_day.yyyy) { {
/* today is the selected day */ /* today is the selected day */
custom_apply_attr (cwin, ATTR_MIDDLE); custom_apply_attr (cwin, ATTR_MIDDLE);
mvwprintw(cwin, ofs_y + 1, mvwprintw (cwin, ofs_y + 1, ofs_x + day_1_sav + 4 * c_day + 1, "%2d",
ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day); c_day);
custom_remove_attr (cwin, ATTR_MIDDLE); custom_remove_attr (cwin, ATTR_MIDDLE);
}
} else if (item_this_day) { else if (item_this_day)
{
custom_apply_attr (cwin, ATTR_LOW); custom_apply_attr (cwin, ATTR_LOW);
mvwprintw(cwin, ofs_y + 1, mvwprintw (cwin, ofs_y + 1, ofs_x + day_1_sav + 4 * c_day + 1, "%2d",
ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day); c_day);
custom_remove_attr (cwin, ATTR_LOW); custom_remove_attr (cwin, ATTR_LOW);
} else }
else
/* otherwise, print normal days in black */ /* otherwise, print normal days in black */
mvwprintw(cwin, ofs_y + 1, mvwprintw (cwin, ofs_y + 1, ofs_x + day_1_sav + 4 * c_day + 1, "%2d",
ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day); c_day);
} }
wnoutrefresh (cwin); wnoutrefresh (cwin);
} }
@ -341,44 +344,42 @@ 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) { {
if (strlen (selected_day) == 0)
{
calendar_store_current_date (&today); 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);
} }
@ -403,7 +404,8 @@ date_change(struct tm *date, int delta_month, int delta_day)
if (mktime (&t) == -1) if (mktime (&t) == -1)
return (1); return (1);
else { else
{
*date = t; *date = t;
return (0); return (0);
} }
@ -420,10 +422,11 @@ calendar_move(move_t move)
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;
@ -434,14 +437,14 @@ calendar_move(move_t move)
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;
@ -449,8 +452,8 @@ calendar_move(move_t move)
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;
@ -577,8 +580,8 @@ pom(time_t tmpt)
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 */
@ -609,10 +612,9 @@ calendar_get_pom(time_t date)
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,30 +44,37 @@ 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);
@ -79,7 +87,7 @@ 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);

View File

@ -1,4 +1,4 @@
/* $calcurse: custom.c,v 1.19 2008/04/09 20:38:29 culot Exp $ */ /* $calcurse: custom.c,v 1.20 2008/04/12 21:14:03 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -42,7 +42,8 @@ fill_config_var(char *string)
return (true); return (true);
else if (strncmp (string, "no", 2) == 0) else if (strncmp (string, "no", 2) == 0)
return (false); return (false);
else { else
{
fputs (_("FATAL ERROR in fill_config_var: " fputs (_("FATAL ERROR in fill_config_var: "
"wrong configuration variable format.\n"), stderr); "wrong configuration variable format.\n"), stderr);
return (EXIT_FAILURE); return (EXIT_FAILURE);
@ -72,16 +73,19 @@ custom_load_color(char *color, int background)
len = strlen (color); len = strlen (color);
if (len > 1) { if (len > 1)
{
/* New version configuration */ /* New version configuration */
if (sscanf(color, "%s on %s", c[0], c[1]) != AWAITED_COLORS) { if (sscanf (color, "%s on %s", c[0], c[1]) != AWAITED_COLORS)
{
fputs (_("FATAL ERROR in custom_load_color: " fputs (_("FATAL ERROR in custom_load_color: "
"missing colors in config file.\n"), stderr); "missing colors in config file.\n"), stderr);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
/* NOTREACHED */ /* NOTREACHED */
}; };
for (i = 0; i < AWAITED_COLORS; i++) { for (i = 0; i < AWAITED_COLORS; i++)
{
if (!strncmp (c[i], "black", 5)) if (!strncmp (c[i], "black", 5))
colr[i] = COLOR_BLACK; colr[i] = COLOR_BLACK;
else if (!strncmp (c[i], "red", 3)) else if (!strncmp (c[i], "red", 3))
@ -100,20 +104,22 @@ custom_load_color(char *color, int background)
colr[i] = COLOR_WHITE; colr[i] = COLOR_WHITE;
else if (!strncmp (c[i], "default", 7)) else if (!strncmp (c[i], "default", 7))
colr[i] = background; colr[i] = background;
else { else
{
fputs (wrong_color_name, stderr); fputs (wrong_color_name, stderr);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
/* NOTREACHED */ /* NOTREACHED */
} }
} }
init_pair (COLR_CUSTOM, colr[0], colr[1]); init_pair (COLR_CUSTOM, colr[0], colr[1]);
}
} else if (len > 0 && len < 2) { else if (len > 0 && len < 2)
{
/* Old version configuration */ /* Old version configuration */
color_num = atoi (color); color_num = atoi (color);
switch (color_num) { switch (color_num)
{
case 0: case 0:
colorize = false; colorize = false;
break; break;
@ -146,8 +152,9 @@ custom_load_color(char *color, int background)
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
/* NOTREACHED */ /* NOTREACHED */
} }
}
} else { else
{
fputs (wrong_variable_format, stderr); fputs (wrong_variable_format, stderr);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
/* NOTREACHED */ /* NOTREACHED */
@ -213,7 +220,8 @@ custom_load_conf(conf_t *conf, int background)
int var; int var;
data_file = fopen (path_conf, "r"); data_file = fopen (path_conf, "r");
if (data_file == NULL) { if (data_file == NULL)
{
status_mesg (mesg_line1, mesg_line2); status_mesg (mesg_line1, mesg_line2);
wnoutrefresh (win[STA].p); wnoutrefresh (win[STA].p);
doupdate (); doupdate ();
@ -221,13 +229,16 @@ custom_load_conf(conf_t *conf, int background)
} }
var = 0; var = 0;
pthread_mutex_lock (&nbar->mutex); pthread_mutex_lock (&nbar->mutex);
for (;;) { for (;;)
if (fgets(buf, 99, data_file) == NULL) { {
if (fgets (buf, 99, data_file) == NULL)
{
break; break;
} }
io_extract_data (e_conf, buf, strlen (buf)); io_extract_data (e_conf, buf, strlen (buf));
switch (var) { switch (var)
{
case CUSTOM_CONF_NOVARIABLE: case CUSTOM_CONF_NOVARIABLE:
break; break;
case CUSTOM_CONF_AUTOSAVE: case CUSTOM_CONF_AUTOSAVE:
@ -371,8 +382,10 @@ void
layout_config (void) layout_config (void)
{ {
int ch; int ch;
char *layout_mesg = _("Pick the desired layout on next screen [press ENTER]"); char *layout_mesg =
char *choice_mesg = _("('A'= Appointment panel, 'C'= calendar panel, 'T'= todo panel)"); _("Pick the desired layout on next screen [press ENTER]");
char *choice_mesg =
_("('A'= Appointment panel, 'C'= calendar panel, 'T'= todo panel)");
char *layout_up_mesg = char *layout_up_mesg =
_(" AC AT CA TA TC TA CT AT"); _(" AC AT CA TA TC TA CT AT");
char *layout_down_mesg = char *layout_down_mesg =
@ -383,8 +396,10 @@ layout_config(void)
status_mesg (layout_up_mesg, layout_down_mesg); status_mesg (layout_up_mesg, layout_down_mesg);
wnoutrefresh (win[STA].p); wnoutrefresh (win[STA].p);
doupdate (); doupdate ();
while ((ch = wgetch(win[STA].p)) != 'q') { while ((ch = wgetch (win[STA].p)) != 'q')
if ( ch <= '8' && ch >= '1' ) { {
if (ch <= '8' && ch >= '1')
{
wins_set_layout (ch - '0'); wins_set_layout (ch - '0');
return; return;
} }
@ -404,12 +419,11 @@ custom_confwin_init(window_t *confwin, char *label)
box (confwin->p, 0, 0); box (confwin->p, 0, 0);
wins_show (confwin->p, label); wins_show (confwin->p, label);
delwin (win[STA].p); delwin (win[STA].p);
win[STA].p = newwin(win[STA].h, win[STA].w, win[STA].y, win[STA].p = newwin (win[STA].h, win[STA].w, win[STA].y, win[STA].x);
win[STA].x);
keypad (win[STA].p, TRUE); keypad (win[STA].p, TRUE);
if (notify_bar()) { if (notify_bar ())
notify_reinit_bar(win[NOT].h, win[NOT].w, {
win[NOT].y, win[NOT].x); notify_reinit_bar (win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x);
notify_update_bar (); notify_update_bar ();
} }
} }
@ -446,7 +460,8 @@ display_color_config(window_t *cwin, int *mark_fore, int *mark_back,
const unsigned XSPC = (col - 2 * BARSIZ - 2 * BOXSIZ - 6) / 3; const unsigned XSPC = (col - 2 * BARSIZ - 2 * BOXSIZ - 6) / 3;
const unsigned XFORE = XSPC; const unsigned XFORE = XSPC;
const unsigned XBACK = 2 * XSPC + BOXSIZ + XOFST + BARSIZ; const unsigned XBACK = 2 * XSPC + BOXSIZ + XOFST + BARSIZ;
enum {YPOS, XPOS, NBPOS}; enum
{ YPOS, XPOS, NBPOS };
unsigned i; unsigned i;
int pos[SIZE][NBPOS]; int pos[SIZE][NBPOS];
short colr_fore, colr_back; short colr_fore, colr_back;
@ -457,23 +472,26 @@ display_color_config(window_t *cwin, int *mark_fore, int *mark_back,
COLR_MAGENTA, COLR_CYAN, COLR_DEFAULT COLR_MAGENTA, COLR_CYAN, COLR_DEFAULT
}; };
for (i = 0; i < NBUSERCOLORS + 1; i++) { for (i = 0; i < NBUSERCOLORS + 1; i++)
{
pos[i][YPOS] = Y + YSPC * (i + 1); pos[i][YPOS] = Y + YSPC * (i + 1);
pos[NBUSERCOLORS + i + 1][YPOS] = Y + YSPC * (i + 1); pos[NBUSERCOLORS + i + 1][YPOS] = Y + YSPC * (i + 1);
pos[i][XPOS] = XFORE; pos[i][XPOS] = XFORE;
pos[NBUSERCOLORS + i + 1][XPOS] = XBACK; pos[NBUSERCOLORS + i + 1][XPOS] = XBACK;
} }
if (need_reset) { if (need_reset)
{
if (cwin->p != NULL) if (cwin->p != NULL)
delwin (cwin->p); delwin (cwin->p);
snprintf(label, BUFSIZ, _("CalCurse %s | color theme"), snprintf (label, BUFSIZ, _("CalCurse %s | color theme"), VERSION);
VERSION);
custom_confwin_init (cwin, label); custom_confwin_init (cwin, label);
} }
if (colorize) { if (colorize)
if (theme_changed) { {
if (theme_changed)
{
pair_content (colr[*mark_fore], &colr_fore, 0L); pair_content (colr[*mark_fore], &colr_fore, 0L);
if (colr_fore == 255) if (colr_fore == 255)
colr_fore = -1; colr_fore = -1;
@ -481,32 +499,31 @@ display_color_config(window_t *cwin, int *mark_fore, int *mark_back,
if (colr_back == 255) if (colr_back == 255)
colr_back = -1; colr_back = -1;
init_pair (COLR_CUSTOM, colr_fore, colr_back); init_pair (COLR_CUSTOM, colr_fore, colr_back);
} else { }
else
{
/* Retrieve the actual color theme. */ /* Retrieve the actual color theme. */
pair_content (COLR_CUSTOM, &colr_fore, &colr_back); pair_content (COLR_CUSTOM, &colr_fore, &colr_back);
if ((colr_fore == DEFAULTCOLOR) || if ((colr_fore == DEFAULTCOLOR) || (colr_fore == DEFAULTCOLOR_EXT))
(colr_fore == DEFAULTCOLOR_EXT))
*mark_fore = NBUSERCOLORS; *mark_fore = NBUSERCOLORS;
else else
for (i = 0; i < NBUSERCOLORS + 1; i++) for (i = 0; i < NBUSERCOLORS + 1; i++)
if (colr_fore == colr[i]) if (colr_fore == colr[i])
*mark_fore = i; *mark_fore = i;
if ((colr_back == DEFAULTCOLOR) || if ((colr_back == DEFAULTCOLOR) || (colr_back == DEFAULTCOLOR_EXT))
(colr_back == DEFAULTCOLOR_EXT))
*mark_back = SIZE - 1; *mark_back = SIZE - 1;
else else
for (i = 0; i < NBUSERCOLORS + 1; i++) for (i = 0; i < NBUSERCOLORS + 1; i++)
if (colr_back == if (colr_back == colr[NBUSERCOLORS + 1 + i])
colr[NBUSERCOLORS + 1 + i]) *mark_back = NBUSERCOLORS + 1 + i;
*mark_back =
NBUSERCOLORS + 1 + i;
} }
} }
/* color boxes */ /* color boxes */
for (i = 0; i < SIZE - 1; i++) { for (i = 0; i < SIZE - 1; i++)
{
mvwprintw (cwin->p, pos[i][YPOS], pos[i][XPOS], box); mvwprintw (cwin->p, pos[i][YPOS], pos[i][XPOS], box);
wattron (cwin->p, COLOR_PAIR (colr[i]) | A_REVERSE); wattron (cwin->p, COLOR_PAIR (colr[i]) | A_REVERSE);
mvwprintw (cwin->p, pos[i][YPOS], pos[i][XPOS] + XOFST, bar); mvwprintw (cwin->p, pos[i][YPOS], pos[i][XPOS] + XOFST, bar);
@ -529,7 +546,8 @@ display_color_config(window_t *cwin, int *mark_fore, int *mark_back,
mvwprintw (cwin->p, Y, XBACK + XOFST, back_txt); mvwprintw (cwin->p, Y, XBACK + XOFST, back_txt);
custom_remove_attr (cwin->p, ATTR_HIGHEST); custom_remove_attr (cwin->p, ATTR_HIGHEST);
if (colorize) { if (colorize)
{
mvwaddch (cwin->p, pos[*mark_fore][YPOS], mvwaddch (cwin->p, pos[*mark_fore][YPOS],
pos[*mark_fore][XPOS] + 1, MARK); pos[*mark_fore][XPOS] + 1, MARK);
mvwaddch (cwin->p, pos[*mark_back][YPOS], mvwaddch (cwin->p, pos[*mark_back][YPOS],
@ -563,11 +581,13 @@ custom_color_config(void)
display_color_config (&conf_win, &mark_fore, &mark_back, cursor, display_color_config (&conf_win, &mark_fore, &mark_back, cursor,
need_reset, theme_changed); need_reset, theme_changed);
while ((ch = wgetch(win[STA].p)) != 'q') { while ((ch = wgetch (win[STA].p)) != 'q')
{
need_reset = 0; need_reset = 0;
theme_changed = 0; theme_changed = 0;
switch (ch) { switch (ch)
{
case KEY_RESIZE: case KEY_RESIZE:
endwin (); endwin ();
refresh (); refresh ();
@ -654,28 +674,30 @@ custom_color_theme_name(char *theme_name)
"blue", "blue",
"magenta", "magenta",
"cyan", "cyan",
"white"}; "white"
};
const char *error_txt = const char *error_txt =
_("FATAL ERROR in custom_color_theme_name: unknown color\n"); _("FATAL ERROR in custom_color_theme_name: unknown color\n");
if (!colorize) if (!colorize)
snprintf (theme_name, BUFSIZ, "0"); snprintf (theme_name, BUFSIZ, "0");
else { else
{
pair_content (COLR_CUSTOM, &color[0], &color[1]); pair_content (COLR_CUSTOM, &color[0], &color[1]);
for (i = 0; i < NBCOLORS; i++) { for (i = 0; i < NBCOLORS; i++)
if ((color[i] == DEFAULTCOLOR) || {
(color[i] == DEFAULTCOLOR_EXT)) if ((color[i] == DEFAULTCOLOR) || (color[i] == DEFAULTCOLOR_EXT))
color_name[i] = default_color; color_name[i] = default_color;
else if (color[i] >= 0 && color[i] <= MAXCOLORS) else if (color[i] >= 0 && color[i] <= MAXCOLORS)
color_name[i] = name[color[i]]; color_name[i] = name[color[i]];
else { else
{
fputs (error_txt, stderr); fputs (error_txt, stderr);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
/* NOTREACHED */ /* NOTREACHED */
} }
} }
snprintf(theme_name, BUFSIZ, "%s on %s", color_name[0], snprintf (theme_name, BUFSIZ, "%s on %s", color_name[0], color_name[1]);
color_name[1]);
} }
} }
@ -712,25 +734,29 @@ custom_print_general_options(WINDOW *optwin, conf_t *conf)
print_option_incolor (optwin, conf->confirm_delete, y_pos + 6, print_option_incolor (optwin, conf->confirm_delete, y_pos + 6,
x_pos + 4 + strlen (option3)); x_pos + 4 + strlen (option3));
mvwprintw (optwin, y_pos + 7, x_pos, mvwprintw (optwin, y_pos + 7, x_pos,
_("(if set to YES, confirmation is required before deleting an event)")); _("(if set to YES, confirmation is required "
"before deleting an event)"));
mvwprintw (optwin, y_pos + 9, x_pos, "[4] %s ", option4); mvwprintw (optwin, y_pos + 9, x_pos, "[4] %s ", option4);
print_option_incolor (optwin, conf->skip_system_dialogs, y_pos + 9, print_option_incolor (optwin, conf->skip_system_dialogs, y_pos + 9,
x_pos + 4 + strlen (option4)); x_pos + 4 + strlen (option4));
mvwprintw (optwin, y_pos + 10, x_pos, mvwprintw (optwin, y_pos + 10, x_pos,
_("(if set to YES, messages about loaded and saved data will not be displayed)")); _("(if set to YES, messages about loaded "
"and saved data will not be displayed)"));
mvwprintw (optwin, y_pos + 12, x_pos, "[5] %s ", option5); mvwprintw (optwin, y_pos + 12, x_pos, "[5] %s ", option5);
print_option_incolor (optwin, conf->skip_progress_bar, y_pos + 12, print_option_incolor (optwin, conf->skip_progress_bar, y_pos + 12,
x_pos + 4 + strlen (option5)); x_pos + 4 + strlen (option5));
mvwprintw (optwin, y_pos + 13, x_pos, mvwprintw (optwin, y_pos + 13, x_pos,
_("(if set to YES, progress bar will not be displayed when saving data)")); _("(if set to YES, progress bar will not be displayed "
"when saving data)"));
mvwprintw (optwin, y_pos + 15, x_pos, "[6] %s ", option6); mvwprintw (optwin, y_pos + 15, x_pos, "[6] %s ", option6);
print_option_incolor (optwin, calendar_week_begins_on_monday (), y_pos + 15, print_option_incolor (optwin, calendar_week_begins_on_monday (), y_pos + 15,
x_pos + 4 + strlen (option6)); x_pos + 4 + strlen (option6));
mvwprintw (optwin, y_pos + 16, x_pos, mvwprintw (optwin, y_pos + 16, x_pos,
_("(if set to YES, monday is the first day of the week, else it is sunday)")); _("(if set to YES, monday is the first day of the week, "
"else it is sunday)"));
mvwprintw (optwin, y_pos + 18, x_pos, "[7] %s ", option7); mvwprintw (optwin, y_pos + 18, x_pos, "[7] %s ", option7);
custom_apply_attr (optwin, ATTR_HIGHEST); custom_apply_attr (optwin, ATTR_HIGHEST);
@ -746,7 +772,8 @@ custom_print_general_options(WINDOW *optwin, conf_t *conf)
conf->input_datefmt); conf->input_datefmt);
custom_remove_attr (optwin, ATTR_HIGHEST); custom_remove_attr (optwin, ATTR_HIGHEST);
mvwprintw (optwin, y_pos + 22, x_pos, mvwprintw (optwin, y_pos + 22, x_pos,
_("(Format to be used when entering a date: 1-mm/dd/yyyy, 2-dd/mm/yyyy, 3-yyyy/mm/dd)")); _("(Format to be used when entering a date: "
"1-mm/dd/yyyy, 2-dd/mm/yyyy, 3-yyyy/mm/dd)"));
wmove (win[STA].p, 1, 0); wmove (win[STA].p, 1, 0);
wnoutrefresh (optwin); wnoutrefresh (optwin);
@ -758,7 +785,8 @@ void
custom_general_config (conf_t *conf) custom_general_config (conf_t *conf)
{ {
window_t conf_win; window_t conf_win;
char *number_str = _("Enter an option number to change its value [Q to quit] "); char *number_str =
_("Enter an option number to change its value [Q to quit] ");
char *output_datefmt_str = char *output_datefmt_str =
_("Enter the date format (see 'man 3 strftime' for possible formats) "); _("Enter the date format (see 'man 3 strftime' for possible formats) ");
char *input_datefmt_str = char *input_datefmt_str =
@ -772,8 +800,10 @@ custom_general_config(conf_t *conf)
custom_confwin_init (&conf_win, label); custom_confwin_init (&conf_win, label);
status_mesg (number_str, ""); status_mesg (number_str, "");
custom_print_general_options (conf_win.p, conf); custom_print_general_options (conf_win.p, conf);
while ((ch = wgetch(win[STA].p)) != 'q') { while ((ch = wgetch (win[STA].p)) != 'q')
switch (ch) { {
switch (ch)
{
case KEY_RESIZE: case KEY_RESIZE:
endwin (); endwin ();
refresh (); refresh ();
@ -784,9 +814,10 @@ custom_general_config(conf_t *conf)
win[STA].p = newwin (win[STA].h, win[STA].w, win[STA].y, win[STA].p = newwin (win[STA].h, win[STA].w, win[STA].y,
win[STA].x); win[STA].x);
keypad (win[STA].p, TRUE); keypad (win[STA].p, TRUE);
if (notify_bar()) { if (notify_bar ())
notify_reinit_bar(win[NOT].h, win[NOT].w, {
win[NOT].y, win[NOT].x); notify_reinit_bar (win[NOT].h, win[NOT].w, win[NOT].y,
win[NOT].x);
notify_update_bar (); notify_update_bar ();
} }
break; break;
@ -800,29 +831,31 @@ custom_general_config(conf_t *conf)
conf->confirm_delete = !conf->confirm_delete; conf->confirm_delete = !conf->confirm_delete;
break; break;
case '4': case '4':
conf->skip_system_dialogs = conf->skip_system_dialogs = !conf->skip_system_dialogs;
!conf->skip_system_dialogs;
break; break;
case '5': case '5':
conf->skip_progress_bar = conf->skip_progress_bar = !conf->skip_progress_bar;
!conf->skip_progress_bar;
break; break;
case '6': case '6':
calendar_change_first_day_of_week (); calendar_change_first_day_of_week ();
break; break;
case '7': case '7':
status_mesg (output_datefmt_str, ""); status_mesg (output_datefmt_str, "");
strncpy(buf, conf->output_datefmt, strlen(conf->output_datefmt) + 1); strncpy (buf, conf->output_datefmt,
if (updatestring(win[STA].p, &buf, 0, 1) == 0) { strlen (conf->output_datefmt) + 1);
if (updatestring (win[STA].p, &buf, 0, 1) == 0)
{
strncpy (conf->output_datefmt, buf, strlen (buf) + 1); strncpy (conf->output_datefmt, buf, strlen (buf) + 1);
} }
status_mesg (number_str, ""); status_mesg (number_str, "");
break; break;
case '8': case '8':
status_mesg (input_datefmt_str, ""); status_mesg (input_datefmt_str, "");
if (updatestring(win[STA].p, &buf, 0, 1) == 0) { if (updatestring (win[STA].p, &buf, 0, 1) == 0)
{
int val = atoi (buf); int val = atoi (buf);
if (val >= 1 && val <= 3) conf->input_datefmt = val; if (val >= 1 && val <= 3)
conf->input_datefmt = val;
} }
status_mesg (number_str, ""); status_mesg (number_str, "");
break; break;

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,7 +66,8 @@ 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];
}; };

342
src/day.c
View File

@ -1,4 +1,4 @@
/* $calcurse: day.c,v 1.35 2008/04/09 20:38:29 culot Exp $ */ /* $calcurse: day.c,v 1.36 2008/04/12 21:14:03 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -45,7 +45,8 @@ day_free_list(void)
{ {
struct day_item_s *p, *q; struct day_item_s *p, *q;
for (p = day_items_ptr; p != 0; p = q) { for (p = day_items_ptr; p != 0; p = q)
{
q = p->next; q = p->next;
free (p->mesg); free (p->mesg);
free (p); free (p);
@ -68,15 +69,17 @@ day_add_event(int type, char *mesg, char *note, long day, int id)
o->start = day; o->start = day;
o->evnt_id = id; o->evnt_id = id;
i = &day_items_ptr; i = &day_items_ptr;
for (;;) { for (;;)
if (*i == 0) { {
if (*i == 0)
{
o->next = *i; o->next = *i;
*i = o; *i = o;
break; break;
} }
i = &(*i)->next; i = &(*i)->next;
} }
return o; return (o);
} }
/* Add an appointment in the current day list. */ /* Add an appointment in the current day list. */
@ -98,21 +101,25 @@ day_add_apoint(int type, char *mesg, char *note, long start, long dur,
o->type = type; o->type = type;
o->evnt_id = 0; o->evnt_id = 0;
i = &day_items_ptr; i = &day_items_ptr;
for (;;) { for (;;)
if (*i == 0) { {
insert_item = 1; if (*i == 0)
} else if ( ((*i)->start > start) && {
((*i)->type > EVNT) ) {
insert_item = 1; insert_item = 1;
} }
if (insert_item) { else if (((*i)->start > start) && ((*i)->type > EVNT))
{
insert_item = 1;
}
if (insert_item)
{
o->next = *i; o->next = *i;
*i = o; *i = o;
break; break;
} }
i = &(*i)->next; i = &(*i)->next;
} }
return o; return (o);
} }
/* /*
@ -129,15 +136,16 @@ day_store_events(long date)
struct day_item_s *ptr; struct day_item_s *ptr;
int e_nb = 0; int e_nb = 0;
for (j = eventlist; j != 0; j = j->next) { for (j = eventlist; j != 0; j = j->next)
if (event_inday(j, date)) { {
if (event_inday (j, date))
{
e_nb++; e_nb++;
ptr = day_add_event(EVNT, j->mesg, j->note, j->day, ptr = day_add_event (EVNT, j->mesg, j->note, j->day, j->id);
j->id);
} }
} }
return e_nb; return (e_nb);
} }
/* /*
@ -154,16 +162,17 @@ day_store_recur_events(long date)
struct day_item_s *ptr; struct day_item_s *ptr;
int e_nb = 0; int e_nb = 0;
for (j = recur_elist; j != 0; j = j->next) { for (j = recur_elist; j != 0; j = j->next)
{
if (recur_item_inday (j->day, j->exc, j->rpt->type, j->rpt->freq, if (recur_item_inday (j->day, j->exc, j->rpt->type, j->rpt->freq,
j->rpt->until, date)) { j->rpt->until, date))
{
e_nb++; e_nb++;
ptr = day_add_event(RECUR_EVNT, j->mesg, j->note, ptr = day_add_event (RECUR_EVNT, j->mesg, j->note, j->day, j->id);
j->day, j->id);
} }
} }
return e_nb; return (e_nb);
} }
/* /*
@ -181,8 +190,10 @@ day_store_apoints(long date)
int a_nb = 0; int a_nb = 0;
pthread_mutex_lock (&(alist_p->mutex)); pthread_mutex_lock (&(alist_p->mutex));
for (j = alist_p->root; j != 0; j = j->next) { for (j = alist_p->root; j != 0; j = j->next)
if (apoint_inday(j, date)) { {
if (apoint_inday (j, date))
{
a_nb++; a_nb++;
ptr = day_add_apoint (APPT, j->mesg, j->note, j->start, ptr = day_add_apoint (APPT, j->mesg, j->note, j->start,
j->dur, j->state, 0); j->dur, j->state, 0);
@ -190,7 +201,7 @@ day_store_apoints(long date)
} }
pthread_mutex_unlock (&(alist_p->mutex)); pthread_mutex_unlock (&(alist_p->mutex));
return a_nb; return (a_nb);
} }
/* /*
@ -209,9 +220,12 @@ day_store_recur_apoints(long date)
int a_nb = 0, n = 0; int a_nb = 0, n = 0;
pthread_mutex_lock (&(recur_alist_p->mutex)); pthread_mutex_lock (&(recur_alist_p->mutex));
for (j = recur_alist_p->root; j != 0; j = j->next) { for (j = recur_alist_p->root; j != 0; j = j->next)
{
if ((real_start = recur_item_inday (j->start, j->exc, if ((real_start = recur_item_inday (j->start, j->exc,
j->rpt->type, j->rpt->freq, j->rpt->until, date)) ){ j->rpt->type, j->rpt->freq,
j->rpt->until, date)))
{
a_nb++; a_nb++;
ptr = day_add_apoint (RECUR_APPT, j->mesg, j->note, ptr = day_add_apoint (RECUR_APPT, j->mesg, j->note,
real_start, j->dur, j->state, n); real_start, j->dur, j->state, n);
@ -220,7 +234,7 @@ day_store_recur_apoints(long date)
} }
pthread_mutex_unlock (&(recur_alist_p->mutex)); pthread_mutex_unlock (&(recur_alist_p->mutex));
return a_nb; return (a_nb);
} }
/* /*
@ -249,12 +263,12 @@ day_store_items(long date, unsigned *pnb_events, unsigned *pnb_apoints)
nb_recur_apoints = day_store_recur_apoints (date); nb_recur_apoints = day_store_recur_apoints (date);
nb_apoints = day_store_apoints (date); nb_apoints = day_store_apoints (date);
*pnb_apoints = nb_apoints; *pnb_apoints = nb_apoints;
pad_length = nb_recur_events + nb_events + 1 + pad_length = (nb_recur_events + nb_events + 1 +
3*(nb_recur_apoints + nb_apoints); 3 * (nb_recur_apoints + nb_apoints));
*pnb_apoints += nb_recur_apoints; *pnb_apoints += nb_recur_apoints;
*pnb_events += nb_recur_events; *pnb_events += nb_recur_events;
return pad_length; return (pad_length);
} }
/* /*
@ -263,7 +277,8 @@ day_store_items(long date, unsigned *pnb_events, unsigned *pnb_apoints)
* day. This is useful to speed up the appointment panel update. * day. This is useful to speed up the appointment panel update.
*/ */
day_items_nb_t * day_items_nb_t *
day_process_storage(date_t *slctd_date, bool day_changed, day_items_nb_t *inday) day_process_storage (date_t *slctd_date, bool day_changed,
day_items_nb_t *inday)
{ {
long date; long date;
date_t day; date_t day;
@ -280,8 +295,7 @@ day_process_storage(date_t *slctd_date, bool day_changed, day_items_nb_t *inday)
delwin (apad->ptrwin); delwin (apad->ptrwin);
/* Store the events and appointments (recursive and normal items). */ /* Store the events and appointments (recursive and normal items). */
apad->length = day_store_items(date, apad->length = day_store_items (date, &inday->nb_events, &inday->nb_apoints);
&inday->nb_events, &inday->nb_apoints);
/* Create the new pad with its new length. */ /* Create the new pad with its new length. */
if (day_changed) if (day_changed)
@ -326,8 +340,7 @@ display_item_date(int incolor, apoint_llist_node_t *i, int type, long date,
mvwprintw (win, y, x, " *!%s -> %s", a_st, a_end); mvwprintw (win, y, x, " *!%s -> %s", a_st, a_end);
else else
mvwprintw (win, y, x, " * %s -> %s", a_st, a_end); mvwprintw (win, y, x, " * %s -> %s", a_st, a_end);
else else if (i->state & APOINT_NOTIFY)
if (i->state & APOINT_NOTIFY)
mvwprintw (win, y, x, " -!%s -> %s", a_st, a_end); mvwprintw (win, y, x, " -!%s -> %s", a_st, a_end);
else else
mvwprintw (win, y, x, " - %s -> %s", a_st, a_end); mvwprintw (win, y, x, " - %s -> %s", a_st, a_end);
@ -339,7 +352,8 @@ display_item_date(int incolor, apoint_llist_node_t *i, int type, long date,
* Print an item description in the corresponding panel window. * Print an item description in the corresponding panel window.
*/ */
static void static void
display_item(int incolor, char *msg, int recur, int note, int len, int y, int x) display_item (int incolor, char *msg, int recur, int note, int len, int y,
int x)
{ {
WINDOW *win; WINDOW *win;
int ch_recur, ch_note; int ch_recur, ch_note;
@ -352,7 +366,8 @@ display_item(int incolor, char *msg, int recur, int note, int len, int y, int x)
custom_apply_attr (win, ATTR_HIGHEST); custom_apply_attr (win, ATTR_HIGHEST);
if (strlen (msg) < len) if (strlen (msg) < len)
mvwprintw (win, y, x, " %c%c%s", ch_recur, ch_note, msg); mvwprintw (win, y, x, " %c%c%s", ch_recur, ch_note, msg);
else { else
{
strncpy (buf, msg, len - 1); strncpy (buf, msg, len - 1);
buf[len - 1] = '\0'; buf[len - 1] = '\0';
mvwprintw (win, y, x, " %c%c%s...", ch_recur, ch_note, buf); mvwprintw (win, y, x, " %c%c%s...", ch_recur, ch_note, buf);
@ -381,21 +396,25 @@ day_write_pad(long date, int width, int length, int incolor)
max_pos = length; max_pos = length;
/* Initialize the structure used to store highlited item. */ /* Initialize the structure used to store highlited item. */
if (day_saved_item == NULL) { if (day_saved_item == NULL)
{
day_saved_item = (struct day_saved_item_s *) day_saved_item = (struct day_saved_item_s *)
malloc (sizeof (struct day_saved_item_s)); malloc (sizeof (struct day_saved_item_s));
day_saved_item->mesg = (char *) malloc (sizeof (char)); day_saved_item->mesg = (char *) malloc (sizeof (char));
} }
for (p = day_items_ptr; p != 0; p = p->next) { for (p = day_items_ptr; p != 0; p = p->next)
{
if (p->type == RECUR_EVNT || p->type == RECUR_APPT) if (p->type == RECUR_EVNT || p->type == RECUR_APPT)
recur = 1; recur = 1;
else else
recur = 0; recur = 0;
/* First print the events for current day. */ /* First print the events for current day. */
if (p->type < RECUR_APPT) { if (p->type < RECUR_APPT)
{
item_number++; item_number++;
if (item_number - incolor == 0) { if (item_number - incolor == 0)
{
day_saved_item->type = p->type; day_saved_item->type = p->type;
day_saved_item->mesg = p->mesg; day_saved_item->mesg = p->mesg;
} }
@ -403,18 +422,21 @@ day_write_pad(long date, int width, int length, int incolor)
(p->note != NULL) ? 1 : 0, width - 7, line, x_pos); (p->note != NULL) ? 1 : 0, width - 7, line, x_pos);
line++; line++;
draw_line = true; draw_line = true;
} else { }
else
{
/* Draw a line between events and appointments. */ /* Draw a line between events and appointments. */
if (line > 0 && draw_line){ if (line > 0 && draw_line)
{
wmove (apad->ptrwin, line, 0); wmove (apad->ptrwin, line, 0);
whline (apad->ptrwin, 0, width); whline (apad->ptrwin, 0, width);
draw_line = false; draw_line = false;
} }
/* Last print the appointments for current day. */ /* Last print the appointments for current day. */
item_number++; item_number++;
day_item_s2apoint_s (&a, p); day_item_s2apoint_s (&a, p);
if (item_number - incolor == 0) { if (item_number - incolor == 0)
{
day_saved_item->type = p->type; day_saved_item->type = p->type;
day_saved_item->mesg = p->mesg; day_saved_item->mesg = p->mesg;
apoint_sec2str (&a, p->type, date, apoint_sec2str (&a, p->type, date,
@ -434,13 +456,11 @@ day_write_pad(long date, int width, int length, int incolor)
void void
day_popup_item (void) day_popup_item (void)
{ {
char *error = char *error = _("FATAL ERROR in day_popup_item: unknown item type\n");
_("FATAL ERROR in day_popup_item: unknown item type\n");
if (day_saved_item->type == EVNT || day_saved_item->type == RECUR_EVNT) if (day_saved_item->type == EVNT || day_saved_item->type == RECUR_EVNT)
item_in_popup (NULL, NULL, day_saved_item->mesg, _("Event :")); item_in_popup (NULL, NULL, day_saved_item->mesg, _("Event :"));
else if (day_saved_item->type == APPT || else if (day_saved_item->type == APPT || day_saved_item->type == RECUR_APPT)
day_saved_item->type == RECUR_APPT)
item_in_popup (day_saved_item->start, day_saved_item->end, item_in_popup (day_saved_item->start, day_saved_item->end,
day_saved_item->mesg, _("Appointment :")); day_saved_item->mesg, _("Appointment :"));
else else
@ -464,31 +484,32 @@ day_check_if_item(date_t day)
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, if (recur_item_inday (re->day, re->exc, re->rpt->type,
re->rpt->freq, re->rpt->until, date)) re->rpt->freq, re->rpt->until, date))
return 1; return (1);
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, if (recur_item_inday (ra->start, ra->exc, ra->rpt->type,
ra->rpt->freq, ra->rpt->until, date)) { ra->rpt->freq, ra->rpt->until, date))
pthread_mutex_unlock( {
&(recur_alist_p->mutex)); pthread_mutex_unlock (&(recur_alist_p->mutex));
return 1; return (1);
} }
pthread_mutex_unlock (&(recur_alist_p->mutex)); pthread_mutex_unlock (&(recur_alist_p->mutex));
for (e = eventlist; e != 0; e = e->next) for (e = eventlist; e != 0; e = e->next)
if (event_inday (e, date)) if (event_inday (e, date))
return 1; return (1);
pthread_mutex_lock (&(alist_p->mutex)); pthread_mutex_lock (&(alist_p->mutex));
for (a = alist_p->root; a != 0; a = a->next) for (a = alist_p->root; a != 0; a = a->next)
if (apoint_inday(a, date)) { if (apoint_inday (a, date))
{
pthread_mutex_unlock (&(alist_p->mutex)); pthread_mutex_unlock (&(alist_p->mutex));
return 1; return (1);
} }
pthread_mutex_unlock (&(alist_p->mutex)); pthread_mutex_unlock (&(alist_p->mutex));
return 0; return (0);
} }
/* Request the user to enter a new time. */ /* Request the user to enter a new time. */
@ -498,17 +519,19 @@ day_edit_time(long time)
char *timestr; char *timestr;
char *msg_time = _("Enter the new time ([hh:mm] or [h:mm]) : "); char *msg_time = _("Enter the new time ([hh:mm] or [h:mm]) : ");
char *enter_str = _("Press [Enter] to continue"); char *enter_str = _("Press [Enter] to continue");
char *fmt_msg = char *fmt_msg = _("You entered an invalid time, should be [h:mm] or [hh:mm]");
_("You entered an invalid time, should be [h:mm] or [hh:mm]");
while (1) { while (1)
{
status_mesg (msg_time, ""); status_mesg (msg_time, "");
timestr = date_sec2hour_str (time); timestr = date_sec2hour_str (time);
updatestring (win[STA].p, &timestr, 0, 1); updatestring (win[STA].p, &timestr, 0, 1);
if (check_time(timestr) != 1 || strlen(timestr) == 0) { if (check_time (timestr) != 1 || strlen (timestr) == 0)
{
status_mesg (fmt_msg, enter_str); status_mesg (fmt_msg, enter_str);
wgetch (win[STA].p); wgetch (win[STA].p);
} else }
else
return (timestr); return (timestr);
} }
} }
@ -520,25 +543,29 @@ update_start_time(long *start, long *dur)
unsigned hr, mn; unsigned hr, mn;
int valid_date; int valid_date;
char *timestr; char *timestr;
char *msg_wrong_time = char *msg_wrong_time = _("Invalid time: start time must be before end time!");
_("Invalid time: start time must be before end time!");
char *msg_enter = _("Press [Enter] to continue"); char *msg_enter = _("Press [Enter] to continue");
do { do
{
timestr = day_edit_time (*start); timestr = day_edit_time (*start);
sscanf (timestr, "%u:%u", &hr, &mn); sscanf (timestr, "%u:%u", &hr, &mn);
free (timestr); free (timestr);
newtime = update_time_in_date (*start, hr, mn); newtime = update_time_in_date (*start, hr, mn);
if (newtime < *start + *dur) { if (newtime < *start + *dur)
{
*dur -= (newtime - *start); *dur -= (newtime - *start);
*start = newtime; *start = newtime;
valid_date = 1; valid_date = 1;
} else { }
else
{
status_mesg (msg_wrong_time, msg_enter); status_mesg (msg_wrong_time, msg_enter);
wgetch (win[STA].p); wgetch (win[STA].p);
valid_date = 0; valid_date = 0;
} }
} while (valid_date == 0); }
while (valid_date == 0);
} }
static void static void
@ -552,8 +579,7 @@ update_duration(long *start, long *dur)
sscanf (timestr, "%u:%u", &hr, &mn); sscanf (timestr, "%u:%u", &hr, &mn);
free (timestr); free (timestr);
newtime = update_time_in_date (*start, hr, mn); newtime = update_time_in_date (*start, hr, mn);
*dur = (newtime > *start) ? newtime - *start : *dur = (newtime > *start) ? newtime - *start : DAYINSEC + newtime - *start;
DAYINSEC + newtime - *start;
} }
static void static void
@ -571,85 +597,104 @@ update_rept(struct rpt_s **rpt, const long start, conf_t *conf)
long newuntil; long newuntil;
char outstr[BUFSIZ]; char outstr[BUFSIZ];
char *typstr, *freqstr, *timstr; char *typstr, *freqstr, *timstr;
char *msg_rpt_type = char *msg_rpt_type = _("Enter the new repetition type: (D)aily, (W)eekly, "
_("Enter the new repetition type: (D)aily, (W)eekly, "
"(M)onthly, (Y)early"); "(M)onthly, (Y)early");
char *msg_rpt_ans = _("[D/W/M/Y] "); char *msg_rpt_ans = _("[D/W/M/Y] ");
char *msg_wrong_freq = _("The frequence you entered is not valid."); char *msg_wrong_freq = _("The frequence you entered is not valid.");
char *msg_wrong_time = char *msg_wrong_time = _("Invalid time: start time must be before end time!");
_("Invalid time: start time must be before end time!");
char *msg_wrong_date = _("The entered date is not valid."); char *msg_wrong_date = _("The entered date is not valid.");
char *msg_fmts = "Possible formats are [%s] or '0' " char *msg_fmts =
"for an endless repetetition"; "Possible formats are [%s] or '0' for an endless repetetition";
char *msg_enter = _("Press [Enter] to continue"); char *msg_enter = _("Press [Enter] to continue");
do { do
{
status_mesg (msg_rpt_type, msg_rpt_ans); status_mesg (msg_rpt_type, msg_rpt_ans);
typstr = (char *) malloc (sizeof (char) * SINGLECHAR); typstr = (char *) malloc (sizeof (char) * SINGLECHAR);
snprintf (typstr, SINGLECHAR, "%c", recur_def2char ((*rpt)->type)); snprintf (typstr, SINGLECHAR, "%c", recur_def2char ((*rpt)->type));
cancel = updatestring (win[STA].p, &typstr, 0, 1); cancel = updatestring (win[STA].p, &typstr, 0, 1);
if (cancel) { if (cancel)
{
free (typstr); free (typstr);
return; return;
} else { }
else
{
ch = toupper (*typstr); ch = toupper (*typstr);
free (typstr); free (typstr);
} }
} while ((ch != 'D') && (ch != 'W') && (ch != 'M') && (ch != 'Y')); }
while ((ch != 'D') && (ch != 'W') && (ch != 'M') && (ch != 'Y'));
do { do
{
status_mesg (_("Enter the new repetition frequence:"), ""); status_mesg (_("Enter the new repetition frequence:"), "");
freqstr = (char *) malloc (BUFSIZ); freqstr = (char *) malloc (BUFSIZ);
snprintf (freqstr, BUFSIZ, "%d", (*rpt)->freq); snprintf (freqstr, BUFSIZ, "%d", (*rpt)->freq);
cancel = updatestring (win[STA].p, &freqstr, 0, 1); cancel = updatestring (win[STA].p, &freqstr, 0, 1);
if (cancel) { if (cancel)
{
free (freqstr); free (freqstr);
return; return;
} else { }
else
{
newfreq = atoi (freqstr); newfreq = atoi (freqstr);
free (freqstr); free (freqstr);
if (newfreq == 0) { if (newfreq == 0)
{
status_mesg (msg_wrong_freq, msg_enter); status_mesg (msg_wrong_freq, msg_enter);
wgetch (win[STA].p); wgetch (win[STA].p);
} }
} }
} while (newfreq == 0); }
while (newfreq == 0);
do { do
{
snprintf (outstr, BUFSIZ, "Enter the new ending date: [%s] or '0'", snprintf (outstr, BUFSIZ, "Enter the new ending date: [%s] or '0'",
DATEFMT_DESC (conf->input_datefmt)); DATEFMT_DESC (conf->input_datefmt));
status_mesg (_(outstr), ""); status_mesg (_(outstr), "");
timstr = date_sec2date_str((*rpt)->until, DATEFMT(conf->input_datefmt)); timstr =
date_sec2date_str ((*rpt)->until, DATEFMT (conf->input_datefmt));
cancel = updatestring (win[STA].p, &timstr, 0, 1); cancel = updatestring (win[STA].p, &timstr, 0, 1);
if (cancel) { if (cancel)
{
free (timstr); free (timstr);
return; return;
} }
if (strcmp(timstr, "0") == 0) { if (strcmp (timstr, "0") == 0)
{
newuntil = 0; newuntil = 0;
date_entered = 1; date_entered = 1;
} else { }
else
{
struct tm *lt; struct tm *lt;
time_t t; time_t t;
date_t new_date; date_t new_date;
int newmonth, newday, newyear; int newmonth, newday, newyear;
if (parse_date (timstr, conf->input_datefmt, if (parse_date (timstr, conf->input_datefmt,
&newyear, &newmonth, &newday)) { &newyear, &newmonth, &newday))
{
t = start; t = start;
lt = localtime (&t); lt = localtime (&t);
new_date.dd = newday; new_date.dd = newday;
new_date.mm = newmonth; new_date.mm = newmonth;
new_date.yyyy = newyear; new_date.yyyy = newyear;
newuntil = date2sec(new_date, lt->tm_hour, newuntil = date2sec (new_date, lt->tm_hour, lt->tm_min);
lt->tm_min); if (newuntil < start)
if (newuntil < start) { {
status_mesg (msg_wrong_time, msg_enter); status_mesg (msg_wrong_time, msg_enter);
wgetch (win[STA].p); wgetch (win[STA].p);
date_entered = 0; date_entered = 0;
} else }
else
date_entered = 1; date_entered = 1;
} else { }
else
{
snprintf (outstr, BUFSIZ, msg_fmts, snprintf (outstr, BUFSIZ, msg_fmts,
DATEFMT_DESC (conf->input_datefmt)); DATEFMT_DESC (conf->input_datefmt));
status_mesg (msg_wrong_date, _(outstr)); status_mesg (msg_wrong_date, _(outstr));
@ -657,7 +702,8 @@ update_rept(struct rpt_s **rpt, const long start, conf_t *conf)
date_entered = 0; date_entered = 0;
} }
} }
} while (date_entered == 0); }
while (date_entered == 0);
free (timstr); free (timstr);
(*rpt)->type = recur_char2def (ch); (*rpt)->type = recur_char2def (ch);
@ -687,15 +733,15 @@ day_edit_item(conf_t *conf)
date = calendar_get_slctd_day_sec (); date = calendar_get_slctd_day_sec ();
ch = 0; ch = 0;
switch (p->type) { switch (p->type)
{
case RECUR_EVNT: case RECUR_EVNT:
re = recur_get_event(date, re = recur_get_event (date, day_item_nb (date, item_num, RECUR_EVNT));
day_item_nb(date, item_num, RECUR_EVNT)); status_mesg (_("Edit: (1)Description or (2)Repetition?"), "[1/2] ");
status_mesg(_("Edit: (1)Description or (2)Repetition?"),
"[1/2] ");
while (ch != '1' && ch != '2' && ch != ESCAPE) while (ch != '1' && ch != '2' && ch != ESCAPE)
ch = wgetch (win[STA].p); ch = wgetch (win[STA].p);
switch (ch) { switch (ch)
{
case '1': case '1':
update_desc (&re->mesg); update_desc (&re->mesg);
break; break;
@ -711,14 +757,14 @@ day_edit_item(conf_t *conf)
update_desc (&e->mesg); update_desc (&e->mesg);
break; break;
case RECUR_APPT: case RECUR_APPT:
ra = recur_get_apoint(date, ra = recur_get_apoint (date, day_item_nb (date, item_num, RECUR_APPT));
day_item_nb(date, item_num, RECUR_APPT));
status_mesg (_("Edit: (1)Start time, (2)End time, " status_mesg (_("Edit: (1)Start time, (2)End time, "
"(3)Description or (4)Repetition?"), "[1/2/3/4] "); "(3)Description or (4)Repetition?"), "[1/2/3/4] ");
while (ch != STRT && ch != END && ch != DESC && while (ch != STRT && ch != END && ch != DESC &&
ch != REPT && ch != ESCAPE) ch != REPT && ch != ESCAPE)
ch = wgetch (win[STA].p); ch = wgetch (win[STA].p);
switch (ch) { switch (ch)
{
case STRT: case STRT:
update_start_time (&ra->start, &ra->dur); update_start_time (&ra->start, &ra->dur);
break; break;
@ -741,7 +787,8 @@ day_edit_item(conf_t *conf)
"or (3)Description?"), "[1/2/3] "); "or (3)Description?"), "[1/2/3] ");
while (ch != STRT && ch != END && ch != DESC && ch != ESCAPE) while (ch != STRT && ch != END && ch != DESC && ch != ESCAPE)
ch = wgetch (win[STA].p); ch = wgetch (win[STA].p);
switch (ch) { switch (ch)
{
case STRT: case STRT:
update_start_time (&a->start, &a->dur); update_start_time (&a->start, &a->dur);
break; break;
@ -780,11 +827,13 @@ day_erase_item(long date, int item_number, erase_flag_e flag)
unsigned delete_whole; unsigned delete_whole;
p = day_get_item (item_number); p = day_get_item (item_number);
if (flag == ERASE_DONT_FORCE) { if (flag == ERASE_DONT_FORCE)
{
ans = 0; ans = 0;
if (p->note == NULL) if (p->note == NULL)
ans = 'i'; ans = 'i';
while (ans != 'i' && ans != 'n') { while (ans != 'i' && ans != 'n')
{
status_mesg (note_warning, note_choice); status_mesg (note_warning, note_choice);
ans = wgetch (win[STA].p); ans = wgetch (win[STA].p);
} }
@ -793,49 +842,61 @@ day_erase_item(long date, int item_number, erase_flag_e flag)
else else
flag = ERASE_FORCE_ONLY_NOTE; flag = ERASE_FORCE_ONLY_NOTE;
} }
if (p->type == EVNT) { if (p->type == EVNT)
event_delete_bynum(date, day_item_nb(date, item_number, EVNT), {
flag); event_delete_bynum (date, day_item_nb (date, item_number, EVNT), flag);
} else if (p->type == APPT) { }
apoint_delete_bynum(date, day_item_nb(date, item_number, APPT), else if (p->type == APPT)
flag); {
} else { apoint_delete_bynum (date, day_item_nb (date, item_number, APPT), flag);
}
else
{
if (flag == ERASE_FORCE_ONLY_NOTE) if (flag == ERASE_FORCE_ONLY_NOTE)
ch = 'a'; ch = 'a';
while ( (ch != 'a') && (ch != 'o') && (ch != ESCAPE)) { while ((ch != 'a') && (ch != 'o') && (ch != ESCAPE))
{
status_mesg (erase_warning, erase_choice); status_mesg (erase_warning, erase_choice);
ch = wgetch (win[STA].p); ch = wgetch (win[STA].p);
} }
if (ch == 'a') { if (ch == 'a')
{
delete_whole = 1; delete_whole = 1;
} else if (ch == 'o') {
delete_whole = 0;
} else {
return 0;
} }
if (p->type == RECUR_EVNT) { else if (ch == 'o')
recur_event_erase(date, {
day_item_nb(date, item_number, RECUR_EVNT), delete_whole = 0;
}
else
{
return (0);
}
if (p->type == RECUR_EVNT)
{
recur_event_erase (date, day_item_nb (date, item_number, RECUR_EVNT),
delete_whole, flag); delete_whole, flag);
} else { }
recur_apoint_erase(date, p->appt_pos, delete_whole, else
flag); {
recur_apoint_erase (date, p->appt_pos, delete_whole, flag);
} }
} }
return (p->type); return (p->type);
} }
/* Returns a structure containing the selected item. */ /* Returns a structure containing the selected item. */
struct day_item_s *day_get_item(int item_number) struct day_item_s *
day_get_item (int item_number)
{ {
struct day_item_s *o; struct day_item_s *o;
int i; int i;
o = day_items_ptr; o = day_items_ptr;
for (i = 1; i < item_number; i++) { for (i = 1; i < item_number; i++)
{
o = o->next; o = o->next;
} }
return o; return (o);
} }
/* Returns the real item number, given its type. */ /* Returns the real item number, given its type. */
@ -850,7 +911,8 @@ day_item_nb(long date, int day_num, int type)
p = day_items_ptr; p = day_items_ptr;
for (i = 1; i < day_num; i++) { for (i = 1; i < day_num; i++)
{
nb_item[p->type - 1]++; nb_item[p->type - 1]++;
p = p->next; p = p->next;
} }
@ -874,7 +936,8 @@ day_edit_note(char *editor)
item_num = apoint_hilt (); item_num = apoint_hilt ();
p = day_get_item (item_num); p = day_get_item (item_num);
if (p->note == NULL) { if (p->note == NULL)
{
if ((filename = new_tempfile (path_notes, NOTESIZ)) == NULL) if ((filename = new_tempfile (path_notes, NOTESIZ)) == NULL)
return; return;
else else
@ -884,10 +947,10 @@ day_edit_note(char *editor)
wins_launch_external (fullname, editor); wins_launch_external (fullname, editor);
date = calendar_get_slctd_day_sec (); date = calendar_get_slctd_day_sec ();
switch (p->type) { switch (p->type)
{
case RECUR_EVNT: case RECUR_EVNT:
re = recur_get_event(date, re = recur_get_event (date, day_item_nb (date, item_num, RECUR_EVNT));
day_item_nb(date, item_num, RECUR_EVNT));
re->note = p->note; re->note = p->note;
break; break;
case EVNT: case EVNT:
@ -895,8 +958,7 @@ day_edit_note(char *editor)
e->note = p->note; e->note = p->note;
break; break;
case RECUR_APPT: case RECUR_APPT:
ra = recur_get_apoint(date, ra = recur_get_apoint (date, day_item_nb (date, item_num, RECUR_APPT));
day_item_nb(date, item_num, RECUR_APPT));
ra->note = p->note; ra->note = p->note;
break; break;
case APPT: case APPT:

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,7 +58,8 @@ 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;

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
@ -47,25 +47,28 @@ event_new(char *mesg, char *note, long day, int id)
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 */
@ -77,8 +80,8 @@ event_write(struct event_s *o, FILE * f)
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);
@ -98,7 +101,8 @@ event_scan(FILE * f, struct tm start, int id, char *note)
/* 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;
@ -109,8 +113,10 @@ event_scan(FILE * f, struct tm start, int id, char *note)
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); {
fputs (_("FATAL ERROR in event_scan: date error in the event\n"),
stderr);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
return (event_new (buf, note, tstart, id)); return (event_new (buf, note, tstart, id));
@ -124,8 +130,10 @@ event_get(long day, int pos)
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++;
@ -145,12 +153,16 @@ event_delete_bynum(long start, unsigned num, erase_flag_e flag)
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);

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 */

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,7 +58,8 @@ 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
@ -66,10 +68,12 @@ 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);
} }
/* /*
@ -135,8 +139,7 @@ help_wins_reset(window_t *hwin, window_t *hpad, const int 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 ();
@ -148,7 +151,8 @@ wanted_page(int ch)
{ {
int page; int page;
switch (ch) { switch (ch)
{
case '?': case '?':
page = HELP_MAIN; page = HELP_MAIN;
@ -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"
@ -558,11 +565,12 @@ help_screen(void)
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;
@ -582,7 +590,8 @@ help_screen(void)
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;
@ -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);

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,10 +27,12 @@
#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);

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

330
src/io.c
View File

@ -1,4 +1,4 @@
/* $calcurse: io.c,v 1.28 2008/04/09 20:38:29 culot Exp $ */ /* $calcurse: io.c,v 1.29 2008/04/12 21:14:03 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -40,11 +40,13 @@
#include "apoint.h" #include "apoint.h"
#include "io.h" #include "io.h"
typedef enum { typedef enum
{
PROGRESS_BAR_SAVE, PROGRESS_BAR_SAVE,
PROGRESS_BAR_LOAD, PROGRESS_BAR_LOAD,
PROGRESS_BAR_EXPORT PROGRESS_BAR_EXPORT
} progress_bar_t; }
progress_bar_t;
/* Draw a progress bar while saving, loading or exporting data. */ /* Draw a progress bar while saving, loading or exporting data. */
@ -80,7 +82,8 @@ progress_bar(progress_bar_t type, int progress)
epos[i] = (i + 2) * step; epos[i] = (i + 2) * step;
epos[STEPS - 1] = col - 2; epos[STEPS - 1] = col - 2;
switch (type) { switch (type)
{
case PROGRESS_BAR_SAVE: case PROGRESS_BAR_SAVE:
status_mesg (mesg_sav, file[progress]); status_mesg (mesg_sav, file[progress]);
break; break;
@ -120,12 +123,10 @@ io_get_export_stream(void)
{ {
FILE *stream; FILE *stream;
char *home, *stream_name; char *home, *stream_name;
char *question = char *question = _("Choose the file used to export calcurse data:");
_("Choose the file used to export calcurse data:");
char *wrong_name = char *wrong_name =
_("The file cannot be accessed, please enter another file name."); _("The file cannot be accessed, please enter another file name.");
char *press_enter = char *press_enter = _("Press [ENTER] to continue.");
_("Press [ENTER] to continue.");
int cancel; int cancel;
stream = NULL; stream = NULL;
@ -135,15 +136,18 @@ io_get_export_stream(void)
else else
snprintf (stream_name, BUFSIZ, "/tmp/calcurse.ics"); snprintf (stream_name, BUFSIZ, "/tmp/calcurse.ics");
while (stream == NULL) { while (stream == NULL)
{
status_mesg (question, ""); status_mesg (question, "");
cancel = updatestring (win[STA].p, &stream_name, 0, 1); cancel = updatestring (win[STA].p, &stream_name, 0, 1);
if (cancel) { if (cancel)
{
free (stream_name); free (stream_name);
return (NULL); return (NULL);
} }
stream = fopen (stream_name, "w"); stream = fopen (stream_name, "w");
if (stream == NULL) { if (stream == NULL)
{
status_mesg (wrong_name, press_enter); status_mesg (wrong_name, press_enter);
wgetch (win[STA].p); wgetch (win[STA].p);
} }
@ -170,8 +174,7 @@ static void
io_export_header (FILE *stream) io_export_header (FILE *stream)
{ {
fprintf (stream, "BEGIN:VCALENDAR\n"); fprintf (stream, "BEGIN:VCALENDAR\n");
fprintf(stream, "PRODID:-//calcurse//NONSGML v%s//EN\n", fprintf (stream, "PRODID:-//calcurse//NONSGML v%s//EN\n", VERSION);
VERSION);
fprintf (stream, "VERSION:2.0\n"); fprintf (stream, "VERSION:2.0\n");
} }
@ -190,23 +193,28 @@ io_export_recur_events(FILE *stream)
struct days_s *day; struct days_s *day;
char ical_date[BUFSIZ]; char ical_date[BUFSIZ];
for (i = recur_elist; i != 0; i = i->next) { for (i = recur_elist; i != 0; i = i->next)
{
date_sec2ical_date (i->day, ical_date); date_sec2ical_date (i->day, ical_date);
fprintf (stream, "BEGIN:VEVENT\n"); fprintf (stream, "BEGIN:VEVENT\n");
fprintf (stream, "DTSTART:%s\n", ical_date); fprintf (stream, "DTSTART:%s\n", ical_date);
fprintf (stream, "RRULE:FREQ=%s;INTERVAL=%d", fprintf (stream, "RRULE:FREQ=%s;INTERVAL=%d",
io_recur_type (i->rpt->type), i->rpt->freq); io_recur_type (i->rpt->type), i->rpt->freq);
if (i->rpt->until != 0) { if (i->rpt->until != 0)
{
date_sec2ical_date (i->rpt->until, ical_date); date_sec2ical_date (i->rpt->until, ical_date);
fprintf (stream, ";UNTIL=%s\n", ical_date); fprintf (stream, ";UNTIL=%s\n", ical_date);
} else }
else
fprintf (stream, "\n"); fprintf (stream, "\n");
if (i->exc != NULL) { if (i->exc != NULL)
{
date_sec2ical_date (i->exc->st, ical_date); date_sec2ical_date (i->exc->st, ical_date);
fprintf (stream, "EXDATE:%s", ical_date); fprintf (stream, "EXDATE:%s", ical_date);
for (day = i->exc->next; day; day = day->next) { for (day = i->exc->next; day; day = day->next)
{
date_sec2ical_date (day->st, ical_date); date_sec2ical_date (day->st, ical_date);
fprintf (stream, ",%s", ical_date); fprintf (stream, ",%s", ical_date);
} }
@ -225,7 +233,8 @@ io_export_events(FILE *stream)
struct event_s *i; struct event_s *i;
char ical_date[BUFSIZ]; char ical_date[BUFSIZ];
for (i = eventlist; i != 0; i = i->next) { for (i = eventlist; i != 0; i = i->next)
{
date_sec2ical_date (i->day, ical_date); date_sec2ical_date (i->day, ical_date);
fprintf (stream, "BEGIN:VEVENT\n"); fprintf (stream, "BEGIN:VEVENT\n");
fprintf (stream, "DTSTART:%s\n", ical_date); fprintf (stream, "DTSTART:%s\n", ical_date);
@ -244,7 +253,8 @@ io_export_recur_apoints(FILE *stream)
char ical_date[BUFSIZ]; char ical_date[BUFSIZ];
pthread_mutex_lock (&(recur_alist_p->mutex)); pthread_mutex_lock (&(recur_alist_p->mutex));
for (i = recur_alist_p->root; i != 0; i = i->next) { for (i = recur_alist_p->root; i != 0; i = i->next)
{
date_sec2ical_datetime (i->start, ical_datetime); date_sec2ical_datetime (i->start, ical_datetime);
fprintf (stream, "BEGIN:VEVENT\n"); fprintf (stream, "BEGIN:VEVENT\n");
fprintf (stream, "DTSTART:%s\n", ical_datetime); fprintf (stream, "DTSTART:%s\n", ical_datetime);
@ -252,17 +262,20 @@ io_export_recur_apoints(FILE *stream)
fprintf (stream, "RRULE:FREQ=%s;INTERVAL=%d", fprintf (stream, "RRULE:FREQ=%s;INTERVAL=%d",
io_recur_type (i->rpt->type), i->rpt->freq); io_recur_type (i->rpt->type), i->rpt->freq);
if (i->rpt->until != 0) { if (i->rpt->until != 0)
date_sec2ical_date(i->rpt->until + HOURINSEC, {
ical_date); date_sec2ical_date (i->rpt->until + HOURINSEC, ical_date);
fprintf (stream, ";UNTIL=%s\n", ical_date); fprintf (stream, ";UNTIL=%s\n", ical_date);
} else }
else
fprintf (stream, "\n"); fprintf (stream, "\n");
if (i->exc != NULL) { if (i->exc != NULL)
{
date_sec2ical_date (i->exc->st, ical_date); date_sec2ical_date (i->exc->st, ical_date);
fprintf (stream, "EXDATE:%s", ical_date); fprintf (stream, "EXDATE:%s", ical_date);
for (day = i->exc->next; day; day = day->next) { for (day = i->exc->next; day; day = day->next)
{
date_sec2ical_date (day->st, ical_date); date_sec2ical_date (day->st, ical_date);
fprintf (stream, ",%s", ical_date); fprintf (stream, ",%s", ical_date);
} }
@ -285,7 +298,8 @@ io_export_apoints(FILE *stream)
char ical_datetime[BUFSIZ]; char ical_datetime[BUFSIZ];
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)
{
date_sec2ical_datetime (i->start, ical_datetime); date_sec2ical_datetime (i->start, ical_datetime);
fprintf (stream, "BEGIN:VEVENT\n"); fprintf (stream, "BEGIN:VEVENT\n");
fprintf (stream, "DTSTART:%s\n", ical_datetime); fprintf (stream, "DTSTART:%s\n", ical_datetime);
@ -304,7 +318,8 @@ io_export_todo(FILE *stream)
{ {
struct todo_s *i; struct todo_s *i;
for (i = todolist; i != 0; i = i->next) { for (i = todolist; i != 0; i = i->next)
{
fprintf (stream, "BEGIN:VTODO\n"); fprintf (stream, "BEGIN:VTODO\n");
fprintf (stream, "PRIORITY:%d\n", i->id); fprintf (stream, "PRIORITY:%d\n", i->id);
fprintf (stream, "SUMMARY:%s\n", i->mesg); fprintf (stream, "SUMMARY:%s\n", i->mesg);
@ -327,24 +342,30 @@ io_init(char *cfile)
int ch; int ch;
home = getenv ("HOME"); home = getenv ("HOME");
if (home == NULL) { if (home == NULL)
{
home = "."; home = ".";
} }
snprintf (path_dir, BUFSIZ, "%s/" DIR_NAME, home); snprintf (path_dir, BUFSIZ, "%s/" DIR_NAME, home);
snprintf (path_todo, BUFSIZ, "%s/" TODO_PATH, home); snprintf (path_todo, BUFSIZ, "%s/" TODO_PATH, home);
snprintf (path_conf, BUFSIZ, "%s/" CONF_PATH, home); snprintf (path_conf, BUFSIZ, "%s/" CONF_PATH, home);
snprintf (path_notes, BUFSIZ, "%s/" NOTES_DIR, home); snprintf (path_notes, BUFSIZ, "%s/" NOTES_DIR, home);
if (cfile == NULL) { if (cfile == NULL)
{
snprintf (path_apts, BUFSIZ, "%s/" APTS_PATH, home); snprintf (path_apts, BUFSIZ, "%s/" APTS_PATH, home);
} else { }
else
{
snprintf (apts_file, BUFSIZ, "%s", cfile); snprintf (apts_file, BUFSIZ, "%s", cfile);
strncpy (path_apts, apts_file, BUFSIZ); strncpy (path_apts, apts_file, BUFSIZ);
/* check if the file exists, otherwise create it */ /* check if the file exists, otherwise create it */
data_file = fopen (path_apts, "r"); data_file = fopen (path_apts, "r");
if (data_file == NULL) { if (data_file == NULL)
{
printf (_("%s does not exist, create it now [y or n] ? "), path_apts); printf (_("%s does not exist, create it now [y or n] ? "), path_apts);
ch = getchar (); ch = getchar ();
switch (ch) { switch (ch)
{
case 'N': case 'N':
case 'n': case 'n':
printf (_("aborting...\n")); printf (_("aborting...\n"));
@ -354,10 +375,13 @@ io_init(char *cfile)
case 'Y': case 'Y':
case 'y': case 'y':
data_file = fopen (path_apts, "w"); data_file = fopen (path_apts, "w");
if (data_file == NULL) { if (data_file == NULL)
{
perror (path_apts); perror (path_apts);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} else { }
else
{
printf (_("%s successfully created\n"), path_apts); printf (_("%s successfully created\n"), path_apts);
printf (_("starting interactive mode...\n")); printf (_("starting interactive mode...\n"));
} }
@ -377,7 +401,8 @@ io_init(char *cfile)
void void
io_extract_data (char *dst_data, const char *org, int len) io_extract_data (char *dst_data, const char *org, int len)
{ {
for (;;) { for (;;)
{
if (*org == '\n' || *org == '\0') if (*org == '\n' || *org == '\0')
break; break;
*dst_data++ = *org++; *dst_data++ = *org++;
@ -396,7 +421,15 @@ io_save_cal(conf_t *conf)
char theme_name[BUFSIZ]; char theme_name[BUFSIZ];
char *access_pb = _("Problems accessing data file ..."); char *access_pb = _("Problems accessing data file ...");
char *config_txt = char *config_txt =
"#\n# Calcurse configuration file\n#\n# This file sets the configuration options used by Calcurse. These\n# options are usually set from within Calcurse. A line beginning with \n# a space or tab is considered to be a continuation of the previous line.\n# For a variable to be unset its value must be blank.\n# To set a variable to the empty string its value should be \"\".\n# Lines beginning with \"#\" are comments, and ignored by Calcurse.\n"; "#\n"
"# Calcurse configuration file\n#\n"
"# This file sets the configuration options used by Calcurse. These\n"
"# options are usually set from within Calcurse. A line beginning with \n"
"# a space or tab is considered to be a continuation of the previous "
"line.\n"
"# For a variable to be unset its value must be blank.\n"
"# To set a variable to the empty string its value should be \"\".\n"
"# Lines beginning with \"#\" are comments, and ignored by Calcurse.\n";
char *save_success = _("The data files were successfully saved"); char *save_success = _("The data files were successfully saved");
char *enter = _("Press [ENTER] to continue"); char *enter = _("Press [ENTER] to continue");
bool show_bar = false; bool show_bar = false;
@ -411,58 +444,61 @@ io_save_cal(conf_t *conf)
data_file = fopen (path_conf, "w"); data_file = fopen (path_conf, "w");
if (data_file == (FILE *) 0) if (data_file == (FILE *) 0)
status_mesg (access_pb, ""); status_mesg (access_pb, "");
else { else
{
custom_color_theme_name (theme_name); custom_color_theme_name (theme_name);
fprintf (data_file, "%s\n", config_txt); fprintf (data_file, "%s\n", config_txt);
fprintf (data_file, fprintf (data_file,
"# If this option is set to yes, automatic save is done when quitting\n"); "# If this option is set to yes, "
"automatic save is done when quitting\n");
fprintf (data_file, "auto_save=\n"); fprintf (data_file, "auto_save=\n");
fprintf (data_file, "%s\n", (conf->auto_save) ? "yes" : "no"); fprintf (data_file, "%s\n", (conf->auto_save) ? "yes" : "no");
fprintf (data_file, fprintf (data_file,
"\n# If this option is set to yes, confirmation is required before quitting\n"); "\n# If this option is set to yes, "
"confirmation is required before quitting\n");
fprintf (data_file, "confirm_quit=\n"); fprintf (data_file, "confirm_quit=\n");
fprintf (data_file, "%s\n", (conf->confirm_quit) ? "yes" : "no"); fprintf (data_file, "%s\n", (conf->confirm_quit) ? "yes" : "no");
fprintf (data_file, fprintf (data_file,
"\n# If this option is set to yes, confirmation is required before deleting an event\n"); "\n# If this option is set to yes, "
"confirmation is required before deleting an event\n");
fprintf (data_file, "confirm_delete=\n"); fprintf (data_file, "confirm_delete=\n");
fprintf(data_file, "%s\n", fprintf (data_file, "%s\n", (conf->confirm_delete) ? "yes" : "no");
(conf->confirm_delete) ? "yes" : "no");
fprintf (data_file, fprintf (data_file,
"\n# If this option is set to yes, messages about loaded and saved data will not be displayed\n"); "\n# If this option is set to yes, "
"messages about loaded and saved data will not be displayed\n");
fprintf (data_file, "skip_system_dialogs=\n"); fprintf (data_file, "skip_system_dialogs=\n");
fprintf(data_file, "%s\n", fprintf (data_file, "%s\n", (conf->skip_system_dialogs) ? "yes" : "no");
(conf->skip_system_dialogs) ? "yes" : "no");
fprintf (data_file, fprintf (data_file,
"\n# If this option is set to yes, progress bar appearing when saving data will not be displayed\n"); "\n# If this option is set to yes, progress bar appearing "
"when saving data will not be displayed\n");
fprintf (data_file, "skip_progress_bar=\n"); fprintf (data_file, "skip_progress_bar=\n");
fprintf(data_file, "%s\n", fprintf (data_file, "%s\n", (conf->skip_progress_bar) ? "yes" : "no");
(conf->skip_progress_bar) ? "yes" : "no");
fprintf (data_file, fprintf (data_file,
"\n# If this option is set to yes, monday is the first day of the week, else it is sunday\n"); "\n# If this option is set to yes, "
"monday is the first day of the week, else it is sunday\n");
fprintf (data_file, "week_begins_on_monday=\n"); fprintf (data_file, "week_begins_on_monday=\n");
fprintf (data_file, "%s\n", fprintf (data_file, "%s\n",
(calendar_week_begins_on_monday ())? "yes" : "no"); (calendar_week_begins_on_monday ())? "yes" : "no");
fprintf(data_file, fprintf (data_file, "\n# This is the color theme used for menus :\n");
"\n# This is the color theme used for menus :\n");
fprintf (data_file, "color-theme=\n"); fprintf (data_file, "color-theme=\n");
fprintf (data_file, "%s\n", theme_name); fprintf (data_file, "%s\n", theme_name);
fprintf(data_file, fprintf (data_file, "\n# This is the layout of the calendar :\n");
"\n# This is the layout of the calendar :\n");
fprintf (data_file, "layout=\n"); fprintf (data_file, "layout=\n");
fprintf (data_file, "%d\n", wins_layout ()); fprintf (data_file, "%d\n", wins_layout ());
pthread_mutex_lock (&nbar->mutex); pthread_mutex_lock (&nbar->mutex);
fprintf (data_file, fprintf (data_file,
"\n# If this option is set to yes, notify-bar will be displayed :\n"); "\n# If this option is set to yes, "
"notify-bar will be displayed :\n");
fprintf (data_file, "notify-bar_show=\n"); fprintf (data_file, "notify-bar_show=\n");
fprintf (data_file, "%s\n", (nbar->show) ? "yes" : "no"); fprintf (data_file, "%s\n", (nbar->show) ? "yes" : "no");
@ -477,22 +513,26 @@ io_save_cal(conf_t *conf)
fprintf (data_file, "%s\n", nbar->timefmt); fprintf (data_file, "%s\n", nbar->timefmt);
fprintf (data_file, fprintf (data_file,
"\n# Warn user if he has an appointment within next 'notify-bar_warning' seconds :\n"); "\n# Warn user if he has an appointment within next "
"'notify-bar_warning' seconds :\n");
fprintf (data_file, "notify-bar_warning=\n"); fprintf (data_file, "notify-bar_warning=\n");
fprintf (data_file, "%d\n", nbar->cntdwn); fprintf (data_file, "%d\n", nbar->cntdwn);
fprintf (data_file, fprintf (data_file,
"\n# Command used to notify user of an upcoming appointment :\n"); "\n# Command used to notify user of "
"an upcoming appointment :\n");
fprintf (data_file, "notify-bar_command=\n"); fprintf (data_file, "notify-bar_command=\n");
fprintf (data_file, "%s\n", nbar->cmd); fprintf (data_file, "%s\n", nbar->cmd);
fprintf (data_file, fprintf (data_file,
"\n# Format of the date to be displayed in non-interactive mode :\n"); "\n# Format of the date to be displayed "
"in non-interactive mode :\n");
fprintf (data_file, "output_datefmt=\n"); fprintf (data_file, "output_datefmt=\n");
fprintf (data_file, "%s\n", conf->output_datefmt); fprintf (data_file, "%s\n", conf->output_datefmt);
fprintf (data_file, fprintf (data_file,
"\n# Format to be used when entering a date (1-mm/dd/yyyy, 2-dd/mm/yyyy, 3-yyyy/mm/dd) :\n"); "\n# Format to be used when entering a date "
"(1-mm/dd/yyyy, 2-dd/mm/yyyy, 3-yyyy/mm/dd) :\n");
fprintf (data_file, "input_datefmt=\n"); fprintf (data_file, "input_datefmt=\n");
fprintf (data_file, "%d\n", conf->input_datefmt); fprintf (data_file, "%d\n", conf->input_datefmt);
@ -507,11 +547,12 @@ io_save_cal(conf_t *conf)
data_file = fopen (path_todo, "w"); data_file = fopen (path_todo, "w");
if (data_file == (FILE *) 0) if (data_file == (FILE *) 0)
status_mesg (access_pb, ""); status_mesg (access_pb, "");
else { else
for (i = todolist; i != 0; i = i->next) { {
for (i = todolist; i != 0; i = i->next)
{
if (i->note != NULL) if (i->note != NULL)
fprintf(data_file, "[%d]>%s %s\n", i->id, fprintf (data_file, "[%d]>%s %s\n", i->id, i->note, i->mesg);
i->note, i->mesg);
else else
fprintf (data_file, "[%d] %s\n", i->id, i->mesg); fprintf (data_file, "[%d] %s\n", i->id, i->mesg);
} }
@ -528,7 +569,8 @@ io_save_cal(conf_t *conf)
data_file = fopen (path_apts, "w"); data_file = fopen (path_apts, "w");
if (data_file == (FILE *) 0) if (data_file == (FILE *) 0)
status_mesg (access_pb, ""); status_mesg (access_pb, "");
else { else
{
recur_save_data (data_file); recur_save_data (data_file);
pthread_mutex_lock (&(alist_p->mutex)); pthread_mutex_lock (&(alist_p->mutex));
@ -541,9 +583,9 @@ io_save_cal(conf_t *conf)
fclose (data_file); fclose (data_file);
} }
/* Print a message telling data were saved */ /* Print a message telling data were saved */
if (!conf->skip_system_dialogs) { if (!conf->skip_system_dialogs)
{
status_mesg (save_success, enter); status_mesg (save_success, enter);
wgetch (win[STA].p); wgetch (win[STA].p);
} }
@ -574,7 +616,8 @@ io_load_app(void)
start = end = until = *lt; start = end = until = *lt;
data_file = fopen (path_apts, "r"); data_file = fopen (path_apts, "r");
for (;;) { for (;;)
{
is_appointment = is_event = is_recursive = 0; is_appointment = is_event = is_recursive = 0;
c = getc (data_file); c = getc (data_file);
if (c == EOF) if (c == EOF)
@ -585,7 +628,8 @@ io_load_app(void)
* and appointments. * and appointments.
*/ */
if (fscanf (data_file, "%u / %u / %u ", if (fscanf (data_file, "%u / %u / %u ",
&start.tm_mon, &start.tm_mday, &start.tm_year) != 3) { &start.tm_mon, &start.tm_mday, &start.tm_year) != 3)
{
fputs (_("FATAL ERROR in io_load_app: " fputs (_("FATAL ERROR in io_load_app: "
"syntax error in the item date\n"), stderr); "syntax error in the item date\n"), stderr);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
@ -600,7 +644,8 @@ io_load_app(void)
is_appointment = 1; is_appointment = 1;
else if (c == '[') else if (c == '[')
is_event = 1; is_event = 1;
else { else
{
fputs (_("FATAL ERROR in io_load_app: " fputs (_("FATAL ERROR in io_load_app: "
"no event nor appointment found\n"), stderr); "no event nor appointment found\n"), stderr);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
@ -608,14 +653,19 @@ io_load_app(void)
ungetc (c, data_file); ungetc (c, data_file);
/* Read the remaining informations. */ /* Read the remaining informations. */
if (is_appointment) { if (is_appointment)
{
fscanf (data_file, "@ %u : %u -> %u / %u / %u @ %u : %u ", fscanf (data_file, "@ %u : %u -> %u / %u / %u @ %u : %u ",
&start.tm_hour, &start.tm_min, &start.tm_hour, &start.tm_min,
&end.tm_mon, &end.tm_mday, &end.tm_year, &end.tm_mon, &end.tm_mday, &end.tm_year,
&end.tm_hour, &end.tm_min); &end.tm_hour, &end.tm_min);
} else if (is_event) { }
else if (is_event)
{
fscanf (data_file, "[%d] ", &id); fscanf (data_file, "[%d] ", &id);
} else { /* NOT REACHED */ }
else
{ /* NOT REACHED */
fputs (error, stderr); fputs (error, stderr);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
@ -623,50 +673,64 @@ io_load_app(void)
/* Check if we have a recursive item. */ /* Check if we have a recursive item. */
c = getc (data_file); c = getc (data_file);
if (c == '{') { if (c == '{')
{
ungetc (c, data_file); ungetc (c, data_file);
is_recursive = 1; is_recursive = 1;
fscanf (data_file, "{ %d%c ", &freq, &type); fscanf (data_file, "{ %d%c ", &freq, &type);
c = getc (data_file); c = getc (data_file);
if (c == '}') { /* endless recurrent item */ if (c == '}')
{ /* endless recurrent item */
ungetc (c, data_file); ungetc (c, data_file);
fscanf (data_file, "} "); fscanf (data_file, "} ");
until.tm_year = 0; until.tm_year = 0;
} else if (c == '-') { }
else if (c == '-')
{
ungetc (c, data_file); ungetc (c, data_file);
fscanf (data_file, " -> %u / %u / %u ", fscanf (data_file, " -> %u / %u / %u ",
&until.tm_mon, &until.tm_mday, &until.tm_mon, &until.tm_mday, &until.tm_year);
&until.tm_year);
c = getc (data_file); c = getc (data_file);
if (c == '!') { if (c == '!')
{
ungetc (c, data_file); ungetc (c, data_file);
exc = recur_exc_scan (data_file); exc = recur_exc_scan (data_file);
c = getc (data_file); c = getc (data_file);
} else { }
else
{
ungetc (c, data_file); ungetc (c, data_file);
fscanf (data_file, "} "); fscanf (data_file, "} ");
} }
} else if (c == '!') { // endless item with exceptions }
else if (c == '!')
{ // endless item with exceptions
ungetc (c, data_file); ungetc (c, data_file);
exc = recur_exc_scan (data_file); exc = recur_exc_scan (data_file);
c = getc (data_file); c = getc (data_file);
until.tm_year = 0; until.tm_year = 0;
} else { /* NOT REACHED */ }
else
{ /* NOT REACHED */
fputs (error, stderr); fputs (error, stderr);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
} else }
else
ungetc (c, data_file); ungetc (c, data_file);
/* Check if a note is attached to the item. */ /* Check if a note is attached to the item. */
c = getc (data_file); c = getc (data_file);
if (c == '>') { if (c == '>')
{
fgets (note, NOTESIZ + 1, data_file); fgets (note, NOTESIZ + 1, data_file);
note[NOTESIZ] = '\0'; note[NOTESIZ] = '\0';
notep = note; notep = note;
getc (data_file); getc (data_file);
} else { }
else
{
notep = NULL; notep = NULL;
ungetc (c, data_file); ungetc (c, data_file);
} }
@ -675,32 +739,45 @@ io_load_app(void)
* Last: read the item description and load it into its * Last: read the item description and load it into its
* corresponding linked list, depending on the item type. * corresponding linked list, depending on the item type.
*/ */
if (is_appointment) { if (is_appointment)
{
c = getc (data_file); c = getc (data_file);
if (c == '!') { if (c == '!')
{
ungetc (c, data_file); ungetc (c, data_file);
fscanf (data_file, " ! "); fscanf (data_file, " ! ");
state |= APOINT_NOTIFY; state |= APOINT_NOTIFY;
} else { }
else
{
ungetc (c, data_file); ungetc (c, data_file);
fscanf (data_file, " | "); fscanf (data_file, " | ");
state = 0L; state = 0L;
} }
if (is_recursive) { if (is_recursive)
{
recur_apoint_scan (data_file, start, end, recur_apoint_scan (data_file, start, end,
type, freq, until, notep, exc, state); type, freq, until, notep, exc, state);
} else {
apoint_scan(data_file, start, end, state,
notep);
} }
} else if (is_event) { else
if (is_recursive) { {
apoint_scan (data_file, start, end, state, notep);
}
}
else if (is_event)
{
if (is_recursive)
{
recur_event_scan (data_file, start, id, type, recur_event_scan (data_file, start, id, type,
freq, until, notep, exc); freq, until, notep, exc);
} else { }
else
{
event_scan (data_file, start, id, notep); event_scan (data_file, start, id, notep);
} }
} else { /* NOT REACHED */ }
else
{ /* NOT REACHED */
fputs (error, stderr); fputs (error, stderr);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
@ -721,32 +798,42 @@ io_load_todo(void)
char buf[BUFSIZ], e_todo[BUFSIZ], note[NOTESIZ + 1]; char buf[BUFSIZ], e_todo[BUFSIZ], note[NOTESIZ + 1];
data_file = fopen (path_todo, "r"); data_file = fopen (path_todo, "r");
if (data_file == NULL) { if (data_file == NULL)
{
status_mesg (mesg_line1, mesg_line2); status_mesg (mesg_line1, mesg_line2);
wgetch (win[STA].p); wgetch (win[STA].p);
} }
for (;;) { for (;;)
{
c = getc (data_file); c = getc (data_file);
if (c == EOF) { if (c == EOF)
{
break; break;
} else if (c == '[') { /* new style with id */ }
else if (c == '[')
{ /* new style with id */
fscanf (data_file, "%d]", &id); fscanf (data_file, "%d]", &id);
} else { }
else
{
id = 9; id = 9;
ungetc (c, data_file); ungetc (c, data_file);
} }
/* Now read the attached note, if any. */ /* Now read the attached note, if any. */
c = getc (data_file); c = getc (data_file);
if (c == '>') { if (c == '>')
{
fgets (note, NOTESIZ + 1, data_file); fgets (note, NOTESIZ + 1, data_file);
note[NOTESIZ] = '\0'; note[NOTESIZ] = '\0';
getc (data_file); getc (data_file);
} else }
else
note[0] = '\0'; note[0] = '\0';
/* Then read todo description. */ /* Then read todo description. */
fgets (buf, BUFSIZ, data_file); fgets (buf, BUFSIZ, data_file);
nl = strchr (buf, '\n'); nl = strchr (buf, '\n');
if (nl) { if (nl)
{
*nl = '\0'; *nl = '\0';
} }
io_extract_data (e_todo, buf, strlen (buf)); io_extract_data (e_todo, buf, strlen (buf));
@ -761,14 +848,16 @@ static void
check_directory (char *dir, int *missing) check_directory (char *dir, int *missing)
{ {
errno = 0; errno = 0;
if (mkdir(dir, 0700) != 0) { if (mkdir (dir, 0700) != 0)
if (errno != EEXIST) { {
fprintf(stderr, if (errno != EEXIST)
_("FATAL ERROR: could not create %s: %s\n"), {
fprintf (stderr, _("FATAL ERROR: could not create %s: %s\n"),
dir, strerror (errno)); dir, strerror (errno));
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
} else }
else
(*missing)++; (*missing)++;
} }
@ -778,11 +867,12 @@ check_file(char *file, int *missing)
FILE *fd; FILE *fd;
errno = 0; errno = 0;
if ((fd = fopen(file, "r")) == NULL) { if ((fd = fopen (file, "r")) == NULL)
{
(*missing)++; (*missing)++;
if ((fd = fopen(file, "w")) == NULL) { if ((fd = fopen (file, "w")) == NULL)
fprintf(stderr, {
_("FATAL ERROR: could not create %s: %s\n"), fprintf (stderr, _("FATAL ERROR: could not create %s: %s\n"),
file, strerror (errno)); file, strerror (errno));
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
@ -825,10 +915,13 @@ io_startup_screen(bool skip_dialogs, int no_data_file)
char *data_mesg = _("Data files found. Data will be loaded now."); char *data_mesg = _("Data files found. Data will be loaded now.");
char *enter = _("Press [ENTER] to continue"); char *enter = _("Press [ENTER] to continue");
if (no_data_file != 0) { if (no_data_file != 0)
{
status_mesg (welcome_mesg, enter); status_mesg (welcome_mesg, enter);
wgetch (win[STA].p); wgetch (win[STA].p);
} else if (!skip_dialogs) { }
else if (!skip_dialogs)
{
status_mesg (data_mesg, enter); status_mesg (data_mesg, enter);
wgetch (win[STA].p); wgetch (win[STA].p);
} }
@ -839,12 +932,12 @@ void
io_export_data (export_mode_t mode, conf_t *conf) io_export_data (export_mode_t mode, conf_t *conf)
{ {
FILE *stream; FILE *stream;
char *wrong_mode = char *wrong_mode = _("FATAL ERROR in io_export_data: wrong export mode\n");
_("FATAL ERROR in io_export_data: wrong export mode\n");
char *success = _("The data were successfully exported"); char *success = _("The data were successfully exported");
char *enter = _("Press [ENTER] to continue"); char *enter = _("Press [ENTER] to continue");
switch (mode) { switch (mode)
{
case IO_EXPORT_NONINTERACTIVE: case IO_EXPORT_NONINTERACTIVE:
stream = stdout; stream = stdout;
break; break;
@ -881,7 +974,8 @@ io_export_data(export_mode_t mode, conf_t *conf)
if (stream != stdout) if (stream != stdout)
fclose (stream); fclose (stream);
if (!conf->skip_system_dialogs && mode == IO_EXPORT_INTERACTIVE) { if (!conf->skip_system_dialogs && mode == IO_EXPORT_INTERACTIVE)
{
status_mesg (success, enter); status_mesg (success, enter);
wgetch (win[STA].p); wgetch (win[STA].p);
} }

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,11 +29,13 @@
#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);

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
@ -48,7 +48,7 @@ notify_bar(void)
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. */
@ -80,7 +80,8 @@ extract_aptsfile(void)
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++;
} }
@ -95,8 +96,7 @@ 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;
@ -132,13 +132,11 @@ launch_cmd(char *cmd, char *shell)
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);
} }
/* /*
@ -169,22 +167,22 @@ notify_update_bar(void)
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;
@ -192,24 +190,23 @@ notify_update_bar(void)
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);
@ -239,7 +236,8 @@ notify_main_thread(void *arg)
elapse = 0; elapse = 0;
got_app = 0; got_app = 0;
for (;;) { for (;;)
{
ntimer = time (NULL); ntimer = time (NULL);
ntime = localtime (&ntimer); ntime = localtime (&ntimer);
pthread_mutex_lock (&notify->mutex); pthread_mutex_lock (&notify->mutex);
@ -252,7 +250,8 @@ notify_main_thread(void *arg)
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;
@ -283,12 +282,15 @@ notify_thread_app(void *arg)
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);
@ -321,16 +323,21 @@ notify_check_added(char *mesg, long start, char state)
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);
@ -351,18 +358,25 @@ notify_check_repeated(recur_apoint_llist_node_t *i)
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);
@ -382,7 +396,7 @@ notify_same_item(long time)
same = 1; same = 1;
pthread_mutex_unlock (&(notify_app->mutex)); pthread_mutex_unlock (&(notify_app->mutex));
return same; return (same);
} }
int int
@ -398,7 +412,7 @@ notify_same_recur_item(recur_apoint_llist_node_t *i)
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. */
@ -414,13 +428,16 @@ notify_start_main_thread(void)
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];
@ -438,8 +455,7 @@ notify_print_options(WINDOW *optwin, int col)
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);
@ -448,8 +464,7 @@ notify_print_options(WINDOW *optwin, int col)
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);
@ -468,7 +483,8 @@ notify_print_options(WINDOW *optwin, int col)
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;
@ -479,7 +495,8 @@ notify_print_options(WINDOW *optwin, int col)
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);
@ -516,7 +533,8 @@ notify_config_bar(void)
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, "");
@ -524,7 +542,8 @@ notify_config_bar(void)
*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 ();
@ -548,7 +567,8 @@ notify_config_bar(void)
pthread_mutex_lock (&nbar->mutex); pthread_mutex_lock (&nbar->mutex);
strncpy (buf, nbar->datefmt, strlen (nbar->datefmt) + 1); strncpy (buf, nbar->datefmt, strlen (nbar->datefmt) + 1);
pthread_mutex_unlock (&nbar->mutex); pthread_mutex_unlock (&nbar->mutex);
if (updatestring(win[STA].p, &buf, 0, 1) == 0) { if (updatestring (win[STA].p, &buf, 0, 1) == 0)
{
pthread_mutex_lock (&nbar->mutex); pthread_mutex_lock (&nbar->mutex);
strncpy (nbar->datefmt, buf, strlen (buf) + 1); strncpy (nbar->datefmt, buf, strlen (buf) + 1);
pthread_mutex_unlock (&nbar->mutex); pthread_mutex_unlock (&nbar->mutex);
@ -560,7 +580,8 @@ notify_config_bar(void)
pthread_mutex_lock (&nbar->mutex); pthread_mutex_lock (&nbar->mutex);
strncpy (buf, nbar->timefmt, strlen (nbar->timefmt) + 1); strncpy (buf, nbar->timefmt, strlen (nbar->timefmt) + 1);
pthread_mutex_unlock (&nbar->mutex); pthread_mutex_unlock (&nbar->mutex);
if (updatestring(win[STA].p, &buf, 0, 1) == 0) { if (updatestring (win[STA].p, &buf, 0, 1) == 0)
{
pthread_mutex_lock (&nbar->mutex); pthread_mutex_lock (&nbar->mutex);
strncpy (nbar->timefmt, buf, strlen (buf) + 1); strncpy (nbar->timefmt, buf, strlen (buf) + 1);
pthread_mutex_unlock (&nbar->mutex); pthread_mutex_unlock (&nbar->mutex);
@ -573,8 +594,8 @@ notify_config_bar(void)
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);
@ -586,7 +607,8 @@ notify_config_bar(void)
pthread_mutex_lock (&nbar->mutex); pthread_mutex_lock (&nbar->mutex);
strncpy (buf, nbar->cmd, strlen (nbar->cmd) + 1); strncpy (buf, nbar->cmd, strlen (nbar->cmd) + 1);
pthread_mutex_unlock (&nbar->mutex); pthread_mutex_unlock (&nbar->mutex);
if (updatestring(win[STA].p, &buf, 0, 1) == 0) { if (updatestring (win[STA].p, &buf, 0, 1) == 0)
{
pthread_mutex_lock (&nbar->mutex); pthread_mutex_lock (&nbar->mutex);
strncpy (nbar->cmd, buf, strlen (buf) + 1); strncpy (nbar->cmd, buf, strlen (buf) + 1);
pthread_mutex_unlock (&nbar->mutex); pthread_mutex_unlock (&nbar->mutex);

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;

View File

@ -1,4 +1,4 @@
/* $calcurse: recur.c,v 1.34 2008/04/09 20:38:29 culot Exp $ */ /* $calcurse: recur.c,v 1.35 2008/04/12 21:14:03 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -47,7 +47,7 @@ recur_apoint_llist_init(void)
recur_alist_p->root = NULL; recur_alist_p->root = NULL;
pthread_mutex_init (&(recur_alist_p->mutex), NULL); pthread_mutex_init (&(recur_alist_p->mutex), NULL);
return 0; return (0);
} }
/* Insert a new recursive appointment in the general linked list */ /* Insert a new recursive appointment in the general linked list */
@ -73,8 +73,10 @@ recur_apoint_new(char *mesg, char *note, long start, long dur, char state,
pthread_mutex_lock (&(recur_alist_p->mutex)); pthread_mutex_lock (&(recur_alist_p->mutex));
i = &recur_alist_p->root; i = &recur_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;
@ -83,7 +85,7 @@ recur_apoint_new(char *mesg, char *note, long start, long dur, char state,
} }
pthread_mutex_unlock (&(recur_alist_p->mutex)); pthread_mutex_unlock (&(recur_alist_p->mutex));
return o; return (o);
} }
/* Insert a new recursive event in the general linked list */ /* Insert a new recursive event in the general linked list */
@ -105,15 +107,17 @@ recur_event_new(char *mesg, char *note, long day, int id, int type, int freq,
o->rpt->until = until; o->rpt->until = until;
o->exc = except; o->exc = except;
i = &recur_elist; i = &recur_elist;
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);
} }
/* /*
@ -126,7 +130,8 @@ recur_def2char(recur_types_t define)
char recur_char; char recur_char;
char *error = _("FATAL ERROR in recur_def2char: unknown recur type\n"); char *error = _("FATAL ERROR in recur_def2char: unknown recur type\n");
switch (define) { switch (define)
{
case RECUR_DAILY: case RECUR_DAILY:
recur_char = 'D'; recur_char = 'D';
break; break;
@ -157,7 +162,8 @@ recur_char2def(char type)
int recur_def; int recur_def;
char *error = _("FATAL ERROR in recur_char2def: unknown char\n"); char *error = _("FATAL ERROR in recur_char2def: unknown char\n");
switch (type) { switch (type)
{
case 'D': case 'D':
recur_def = RECUR_DAILY; recur_def = RECUR_DAILY;
break; break;
@ -179,12 +185,14 @@ recur_char2def(char type)
/* Write days for which recurrent items should not be repeated. */ /* Write days for which recurrent items should not be repeated. */
static void static void
recur_write_exc(struct days_s *exc, FILE *f) { recur_write_exc (struct days_s *exc, FILE *f)
{
struct tm *lt; struct tm *lt;
time_t t; time_t t;
int st_mon, st_day, st_year; int st_mon, st_day, st_year;
while (exc) { while (exc)
{
t = exc->st; t = exc->st;
lt = localtime (&t); lt = localtime (&t);
st_mon = lt->tm_mon + 1; st_mon = lt->tm_mon + 1;
@ -198,7 +206,8 @@ recur_write_exc(struct days_s *exc, FILE *f) {
/* Load the recursive appointment description */ /* Load the recursive appointment description */
recur_apoint_llist_node_t * recur_apoint_llist_node_t *
recur_apoint_scan (FILE *f, struct tm start, struct tm end, char type, recur_apoint_scan (FILE *f, struct tm start, struct tm end, char type,
int freq, struct tm until, char *note, struct days_s *exc, char state) int freq, struct tm until, char *note, struct days_s *exc,
char state)
{ {
struct tm *lt; struct tm *lt;
char buf[MESG_MAXSIZE], *nl; char buf[MESG_MAXSIZE], *nl;
@ -210,10 +219,10 @@ recur_apoint_scan(FILE * f, struct tm start, struct tm end, char type,
/* 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';
} }
start.tm_sec = end.tm_sec = 0; start.tm_sec = end.tm_sec = 0;
start.tm_isdst = end.tm_isdst = -1; start.tm_isdst = end.tm_isdst = -1;
start.tm_year -= 1900; start.tm_year -= 1900;
@ -223,7 +232,8 @@ recur_apoint_scan(FILE * f, struct tm start, struct tm end, char type,
tstart = mktime (&start); tstart = mktime (&start);
tend = mktime (&end); tend = mktime (&end);
if (until.tm_year != 0) { if (until.tm_year != 0)
{
until.tm_hour = 23; until.tm_hour = 23;
until.tm_min = 59; until.tm_min = 59;
until.tm_sec = 0; until.tm_sec = 0;
@ -231,12 +241,16 @@ recur_apoint_scan(FILE * f, struct tm start, struct tm end, char type,
until.tm_year -= 1900; until.tm_year -= 1900;
until.tm_mon--; until.tm_mon--;
tuntil = mktime (&until); tuntil = mktime (&until);
} else { }
else
{
tuntil = 0; tuntil = 0;
} }
if (tstart == -1 || tend == -1 || tstart > tend || tuntil == -1) { if (tstart == -1 || tend == -1 || tstart > tend || tuntil == -1)
fputs(_("FATAL ERROR in apoint_scan: date error in the appointment\n"), stderr); {
fputs (_("FATAL ERROR in apoint_scan: date error in the appointment\n"),
stderr);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
@ -259,32 +273,36 @@ struct tm until, char *note, struct days_s *exc)
/* 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 = until.tm_hour = 12; start.tm_hour = until.tm_hour = 12;
start.tm_min = until.tm_min = 0; start.tm_min = until.tm_min = 0;
start.tm_sec = until.tm_sec = 0; start.tm_sec = until.tm_sec = 0;
start.tm_isdst = until.tm_isdst = -1; start.tm_isdst = until.tm_isdst = -1;
start.tm_year -= 1900; start.tm_year -= 1900;
start.tm_mon--; start.tm_mon--;
if (until.tm_year != 0) { if (until.tm_year != 0)
{
until.tm_year -= 1900; until.tm_year -= 1900;
until.tm_mon--; until.tm_mon--;
tuntil = mktime (&until); tuntil = mktime (&until);
} else { }
else
{
tuntil = 0; tuntil = 0;
} }
tstart = mktime (&start); tstart = mktime (&start);
if ( (tstart == -1) || (tuntil == -1) ) { if ((tstart == -1) || (tuntil == -1))
{
fputs (_("FATAL ERROR in recur_event_scan: " fputs (_("FATAL ERROR in recur_event_scan: "
"date error in the event\n"), stderr); "date error in the event\n"), stderr);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
return recur_event_new(buf, note, tstart, id, recur_char2def(type), return (recur_event_new (buf, note, tstart, id, recur_char2def (type),
freq, tuntil, exc); freq, tuntil, exc));
} }
/* Writting of a recursive appointment into file. */ /* Writting of a recursive appointment into file. */
@ -307,10 +325,12 @@ recur_apoint_write(recur_apoint_llist_node_t *o, FILE *f)
lt->tm_hour, lt->tm_min); lt->tm_hour, lt->tm_min);
t = o->rpt->until; t = o->rpt->until;
if (t == 0) { /* We have an endless recurrent appointment. */ if (t == 0)
fprintf(f, " {%d%c", o->rpt->freq, { /* We have an endless recurrent appointment. */
recur_def2char(o->rpt->type)); fprintf (f, " {%d%c", o->rpt->freq, recur_def2char (o->rpt->type));
} else { }
else
{
lt = localtime (&t); lt = localtime (&t);
fprintf (f, " {%d%c -> %02u/%02u/%04u", fprintf (f, " {%d%c -> %02u/%02u/%04u",
o->rpt->freq, recur_def2char (o->rpt->type), o->rpt->freq, recur_def2char (o->rpt->type),
@ -343,11 +363,14 @@ recur_event_write(struct recur_event_s *o, FILE *f)
st_day = lt->tm_mday; st_day = lt->tm_mday;
st_year = lt->tm_year + 1900; st_year = lt->tm_year + 1900;
t = o->rpt->until; t = o->rpt->until;
if (t == 0) { /* We have an endless recurrent event. */ if (t == 0)
{ /* We have an endless recurrent event. */
fprintf (f, "%02u/%02u/%04u [%d] {%d%c", fprintf (f, "%02u/%02u/%04u [%d] {%d%c",
st_mon, st_day, st_year, o->id, o->rpt->freq, st_mon, st_day, st_year, o->id, o->rpt->freq,
recur_def2char (o->rpt->type)); recur_def2char (o->rpt->type));
} else { }
else
{
lt = localtime (&t); lt = localtime (&t);
end_mon = lt->tm_mon + 1; end_mon = lt->tm_mon + 1;
end_day = lt->tm_mday; end_day = lt->tm_mday;
@ -395,8 +418,7 @@ recur_item_inday(long item_start, struct days_s *item_exc, int rpt_type,
struct tm lt_item, lt_day; struct tm lt_item, lt_day;
struct days_s *exc; struct days_s *exc;
time_t t; time_t t;
char *error = char *error = _("FATAL ERROR in recur_item_inday: unknown item type\n");
_("FATAL ERROR in recur_item_inday: unknown item type\n");
day_end = day_start + DAYINSEC; day_end = day_start + DAYINSEC;
t = day_start; t = day_start;
@ -404,13 +426,13 @@ recur_item_inday(long item_start, struct days_s *item_exc, int rpt_type,
for (exc = item_exc; exc != 0; exc = exc->next) for (exc = item_exc; exc != 0; exc = exc->next)
if (exc->st < day_end && exc->st >= day_start) if (exc->st < day_end && exc->st >= day_start)
return 0; return (0);
if (rpt_until == 0) /* we have an endless recurrent item */ if (rpt_until == 0) /* we have an endless recurrent item */
rpt_until = day_end; rpt_until = day_end;
if (item_start > day_end || rpt_until < day_start) if (item_start > day_end || rpt_until < day_start)
return 0; return (0);
t = item_start; t = item_start;
lt_item = *localtime (&t); lt_item = *localtime (&t);
@ -419,39 +441,41 @@ recur_item_inday(long item_start, struct days_s *item_exc, int rpt_type,
day_start += (lt_item.tm_hour * HOURINSEC + lt_item.tm_min * MININSEC + day_start += (lt_item.tm_hour * HOURINSEC + lt_item.tm_min * MININSEC +
lt_item.tm_sec); lt_item.tm_sec);
switch (rpt_type) { switch (rpt_type)
{
case RECUR_DAILY: case RECUR_DAILY:
diff = (long) difftime ((time_t) day_start, (time_t) item_start); diff = (long) difftime ((time_t) day_start, (time_t) item_start);
if (diff % (rpt_freq * DAYINSEC) != 0) if (diff % (rpt_freq * DAYINSEC) != 0)
return 0; return (0);
lt_item.tm_mday = lt_day.tm_mday; lt_item.tm_mday = lt_day.tm_mday;
lt_item.tm_mon = lt_day.tm_mon; lt_item.tm_mon = lt_day.tm_mon;
lt_item.tm_year = lt_day.tm_year; lt_item.tm_year = lt_day.tm_year;
break; break;
case RECUR_WEEKLY: case RECUR_WEEKLY:
if (lt_item.tm_wday != lt_day.tm_wday) if (lt_item.tm_wday != lt_day.tm_wday)
return 0; return (0);
else { else
{
diff = ((lt_day.tm_yday - lt_item.tm_yday) / WEEKINDAYS); diff = ((lt_day.tm_yday - lt_item.tm_yday) / WEEKINDAYS);
if (diff % rpt_freq != 0) if (diff % rpt_freq != 0)
return 0; return (0);
} }
lt_item.tm_mday = lt_day.tm_mday; lt_item.tm_mday = lt_day.tm_mday;
lt_item.tm_mon = lt_day.tm_mon; lt_item.tm_mon = lt_day.tm_mon;
lt_item.tm_year = lt_day.tm_year; lt_item.tm_year = lt_day.tm_year;
break; break;
case RECUR_MONTHLY: case RECUR_MONTHLY:
diff = ((lt_day.tm_year - lt_item.tm_year) * 12) + diff = (((lt_day.tm_year - lt_item.tm_year) * 12)
(lt_day.tm_mon - lt_item.tm_mon); + (lt_day.tm_mon - lt_item.tm_mon));
if (diff % rpt_freq != 0) if (diff % rpt_freq != 0)
return 0; return (0);
lt_item.tm_mon = lt_day.tm_mon; lt_item.tm_mon = lt_day.tm_mon;
lt_item.tm_year = lt_day.tm_year; lt_item.tm_year = lt_day.tm_year;
break; break;
case RECUR_YEARLY: case RECUR_YEARLY:
diff = lt_day.tm_year - lt_item.tm_year; diff = lt_day.tm_year - lt_item.tm_year;
if (diff % rpt_freq != 0) if (diff % rpt_freq != 0)
return 0; return (0);
lt_item.tm_year = lt_day.tm_year; lt_item.tm_year = lt_day.tm_year;
break; break;
default: default:
@ -464,9 +488,9 @@ recur_item_inday(long item_start, struct days_s *item_exc, int rpt_type,
item_start = date2sec (start_date, lt_item.tm_hour, lt_item.tm_min); item_start = date2sec (start_date, lt_item.tm_hour, lt_item.tm_min);
if (item_start < day_end && item_start >= day_start) if (item_start < day_end && item_start >= day_start)
return item_start; return (item_start);
else else
return 0; return (0);
} }
/* /*
@ -482,14 +506,19 @@ recur_event_erase(long start, unsigned num, unsigned delete_whole,
struct days_s *o, **j; struct days_s *o, **j;
iptr = &recur_elist; iptr = &recur_elist;
for (i = recur_elist; i != 0; i = i->next) { for (i = recur_elist; i != 0; i = i->next)
{
if (recur_item_inday (i->day, i->exc, i->rpt->type, if (recur_item_inday (i->day, i->exc, i->rpt->type,
i->rpt->freq, i->rpt->until, start)) { i->rpt->freq, i->rpt->until, start))
if (n == num) { {
if (delete_whole) { if (n == num)
{
if (delete_whole)
{
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);
free (i->rpt); free (i->rpt);
@ -498,13 +527,16 @@ recur_event_erase(long start, unsigned num, unsigned delete_whole,
free (i); free (i);
} }
return; return;
} else { }
o = (struct days_s *) else
malloc(sizeof(struct days_s)); {
o = (struct days_s *) malloc (sizeof (struct days_s));
o->st = start; o->st = start;
j = &i->exc; j = &i->exc;
for (;;) { for (;;)
if(*j==0 || (*j)->st > start) { {
if (*j == 0 || (*j)->st > start)
{
o->next = *j; o->next = *j;
*j = o; *j = o;
break; break;
@ -519,8 +551,7 @@ recur_event_erase(long start, unsigned num, unsigned delete_whole,
iptr = &i->next; iptr = &i->next;
} }
/* NOTREACHED */ /* NOTREACHED */
fputs(_("FATAL ERROR in recur_event_erase: no such event\n"), fputs (_("FATAL ERROR in recur_event_erase: no such event\n"), stderr);
stderr);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
@ -539,45 +570,49 @@ recur_apoint_erase(long start, unsigned num, unsigned delete_whole,
pthread_mutex_lock (&(recur_alist_p->mutex)); pthread_mutex_lock (&(recur_alist_p->mutex));
iptr = &recur_alist_p->root; iptr = &recur_alist_p->root;
for (i = recur_alist_p->root; i != 0; i = i->next) { for (i = recur_alist_p->root; i != 0; i = i->next)
{
if (recur_item_inday (i->start, i->exc, i->rpt->type, if (recur_item_inday (i->start, i->exc, i->rpt->type,
i->rpt->freq, i->rpt->until, start)) { i->rpt->freq, i->rpt->until, start))
if (n == num) { {
if (notify_bar() && if (n == num)
flag != ERASE_FORCE_ONLY_NOTE) {
need_check_notify = if (notify_bar () && flag != ERASE_FORCE_ONLY_NOTE)
notify_same_recur_item(i); need_check_notify = notify_same_recur_item (i);
if (delete_whole) { if (delete_whole)
{
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);
free (i->rpt); free (i->rpt);
free (i->exc); free (i->exc);
erase_note (&i->note, flag); erase_note (&i->note, flag);
free (i); free (i);
pthread_mutex_unlock( pthread_mutex_unlock (&(recur_alist_p->mutex));
&(recur_alist_p->mutex));
if (need_check_notify) if (need_check_notify)
notify_check_next_app (); notify_check_next_app ();
} }
return; return;
} else { }
o = (struct days_s *) else
malloc(sizeof(struct days_s)); {
o = (struct days_s *) malloc (sizeof (struct days_s));
o->st = start; o->st = start;
j = &i->exc; j = &i->exc;
for (;;) { for (;;)
if(*j==0 || (*j)->st > start) { {
if (*j == 0 || (*j)->st > start)
{
o->next = *j; o->next = *j;
*j = o; *j = o;
break; break;
} }
j = &(*j)->next; j = &(*j)->next;
} }
pthread_mutex_unlock( pthread_mutex_unlock (&(recur_alist_p->mutex));
&(recur_alist_p->mutex));
if (need_check_notify) if (need_check_notify)
notify_check_next_app (); notify_check_next_app ();
return; return;
@ -614,10 +649,8 @@ recur_repeat_item(conf_t *conf)
char *mesg_type_1 = char *mesg_type_1 =
_("Enter the repetition type: (D)aily, (W)eekly, (M)onthly, (Y)early"); _("Enter the repetition type: (D)aily, (W)eekly, (M)onthly, (Y)early");
char *mesg_type_2 = _("[D/W/M/Y] "); char *mesg_type_2 = _("[D/W/M/Y] ");
char *mesg_freq_1 = char *mesg_freq_1 = _("Enter the repetition frequence:");
_("Enter the repetition frequence:"); char *mesg_wrong_freq = _("The frequence you entered is not valid.");
char *mesg_wrong_freq =
_("The frequence you entered is not valid.");
char *mesg_until_1 = char *mesg_until_1 =
_("Enter the ending date: [%s] or '0' for an endless repetition"); _("Enter the ending date: [%s] or '0' for an endless repetition");
char *mesg_wrong_1 = _("The entered date is not valid."); char *mesg_wrong_1 = _("The entered date is not valid.");
@ -636,67 +669,83 @@ recur_repeat_item(conf_t *conf)
item_nb = apoint_hilt (); item_nb = apoint_hilt ();
p = day_get_item (item_nb); p = day_get_item (item_nb);
if (p->type != APPT && p->type != EVNT) { if (p->type != APPT && p->type != EVNT)
{
status_mesg (wrong_type_1, wrong_type_2); status_mesg (wrong_type_1, wrong_type_2);
ch = wgetch (win[STA].p); ch = wgetch (win[STA].p);
return; return;
} }
while ((ch != 'D') && (ch != 'W') && (ch != 'M') while ((ch != 'D') && (ch != 'W') && (ch != 'M')
&& (ch != 'Y') && (ch != ESCAPE) ) { && (ch != 'Y') && (ch != ESCAPE))
{
status_mesg (mesg_type_1, mesg_type_2); status_mesg (mesg_type_1, mesg_type_2);
ch = wgetch (win[STA].p); ch = wgetch (win[STA].p);
ch = toupper (ch); ch = toupper (ch);
} }
if (ch == ESCAPE) { if (ch == ESCAPE)
{
return; return;
} else { }
else
{
type = recur_char2def (ch); type = recur_char2def (ch);
ch = 0; ch = 0;
} }
while (freq == 0) { while (freq == 0)
{
status_mesg (mesg_freq_1, ""); status_mesg (mesg_freq_1, "");
if (getstring(win[STA].p, user_input, BUFSIZ, 0, 1) == if (getstring (win[STA].p, user_input, BUFSIZ, 0, 1) == GETSTRING_VALID)
GETSTRING_VALID) { {
freq = atoi (user_input); freq = atoi (user_input);
if (freq == 0) { if (freq == 0)
{
status_mesg (mesg_wrong_freq, wrong_type_2); status_mesg (mesg_wrong_freq, wrong_type_2);
wgetch (win[STA].p); wgetch (win[STA].p);
} }
user_input[0] = '\0'; user_input[0] = '\0';
} else }
else
return; return;
} }
while (!date_entered) { while (!date_entered)
{
snprintf (outstr, BUFSIZ, mesg_until_1, snprintf (outstr, BUFSIZ, mesg_until_1,
DATEFMT_DESC (conf->input_datefmt)); DATEFMT_DESC (conf->input_datefmt));
status_mesg (_(outstr), ""); status_mesg (_(outstr), "");
if (getstring(win[STA].p, user_input, BUFSIZ, 0, 1) == if (getstring (win[STA].p, user_input, BUFSIZ, 0, 1) == GETSTRING_VALID)
GETSTRING_VALID) { {
if (strlen(user_input) == 1 && if (strlen (user_input) == 1 && strncmp (user_input, "0", 1) == 0)
strncmp(user_input, "0", 1) == 0 ) { {
until = 0; until = 0;
date_entered = 1; date_entered = 1;
} else { }
else
{
if (parse_date (user_input, conf->input_datefmt, if (parse_date (user_input, conf->input_datefmt,
&year, &month, &day)) { &year, &month, &day))
t = p->start; lt = localtime(&t); {
t = p->start;
lt = localtime (&t);
until_date.dd = day; until_date.dd = day;
until_date.mm = month; until_date.mm = month;
until_date.yyyy = year; until_date.yyyy = year;
until = date2sec(until_date, until = date2sec (until_date, lt->tm_hour, lt->tm_min);
lt->tm_hour, lt->tm_min); if (until < p->start)
if (until < p->start) { {
status_mesg(mesg_older, status_mesg (mesg_older, wrong_type_2);
wrong_type_2);
wgetch (win[STA].p); wgetch (win[STA].p);
date_entered = 0; date_entered = 0;
} else { }
else
{
date_entered = 1; date_entered = 1;
} }
} else { }
else
{
snprintf (outstr, BUFSIZ, mesg_wrong_2, snprintf (outstr, BUFSIZ, mesg_wrong_2,
DATEFMT_DESC (conf->input_datefmt)); DATEFMT_DESC (conf->input_datefmt));
status_mesg (mesg_wrong_1, _(outstr)); status_mesg (mesg_wrong_1, _(outstr));
@ -704,20 +753,26 @@ recur_repeat_item(conf_t *conf)
date_entered = 0; date_entered = 0;
} }
} }
} else }
else
return; return;
} }
date = calendar_get_slctd_day_sec (); date = calendar_get_slctd_day_sec ();
if (p->type == EVNT) { if (p->type == EVNT)
{
re = recur_event_new (p->mesg, p->note, p->start, p->evnt_id, re = recur_event_new (p->mesg, p->note, p->start, p->evnt_id,
type, freq, until, NULL); type, freq, until, NULL);
} else if (p->type == APPT) { }
else if (p->type == APPT)
{
ra = recur_apoint_new (p->mesg, p->note, p->start, p->appt_dur, ra = recur_apoint_new (p->mesg, p->note, p->start, p->appt_dur,
p->state, type, freq, until, NULL); p->state, type, freq, until, NULL);
if (notify_bar ()) if (notify_bar ())
notify_check_repeated (ra); notify_check_repeated (ra);
} else { /* NOTREACHED */ }
else
{ /* NOTREACHED */
fputs (_("FATAL ERROR in recur_repeat_item: wrong item type\n"), fputs (_("FATAL ERROR in recur_repeat_item: wrong item type\n"),
stderr); stderr);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
@ -741,10 +796,12 @@ recur_exc_scan(FILE *data_file)
t = time (NULL); t = time (NULL);
lt = localtime (&t); lt = localtime (&t);
day = *lt; day = *lt;
while ((c = getc(data_file)) == '!') { while ((c = getc (data_file)) == '!')
{
ungetc (c, data_file); ungetc (c, data_file);
if (fscanf (data_file, "!%u / %u / %u ", if (fscanf (data_file, "!%u / %u / %u ",
&day.tm_mon, &day.tm_mday, &day.tm_year) != 3) { &day.tm_mon, &day.tm_mday, &day.tm_year) != 3)
{
fputs (_("FATAL ERROR in recur_exc_scan: " fputs (_("FATAL ERROR in recur_exc_scan: "
"syntax error in the item date\n"), stderr); "syntax error in the item date\n"), stderr);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
@ -758,7 +815,7 @@ recur_exc_scan(FILE *data_file)
exc->next = exc_head; exc->next = exc_head;
exc_head = exc; exc_head = exc;
} }
return exc_head; return (exc_head);
} }
/* /*
@ -772,15 +829,20 @@ recur_apoint_check_next(struct notify_app_s *app, long start, long day)
long real_recur_start_time; long real_recur_start_time;
pthread_mutex_lock (&(recur_alist_p->mutex)); pthread_mutex_lock (&(recur_alist_p->mutex));
for (i = recur_alist_p->root; i != 0; i = i->next) { for (i = recur_alist_p->root; i != 0; i = i->next)
if (i->start > app->time) { {
if (i->start > app->time)
{
pthread_mutex_unlock (&(recur_alist_p->mutex)); pthread_mutex_unlock (&(recur_alist_p->mutex));
return app; return (app);
} else { }
real_recur_start_time = recur_item_inday( else
i->start, i->exc, i->rpt->type, i->rpt->freq, {
real_recur_start_time =
recur_item_inday (i->start, i->exc, i->rpt->type, i->rpt->freq,
i->rpt->until, day); i->rpt->until, day);
if (real_recur_start_time > start) { if (real_recur_start_time > start)
{
app->time = real_recur_start_time; app->time = real_recur_start_time;
app->txt = mycpy (i->mesg); app->txt = mycpy (i->mesg);
app->state = i->state; app->state = i->state;
@ -790,7 +852,7 @@ recur_apoint_check_next(struct notify_app_s *app, long start, long day)
} }
pthread_mutex_unlock (&(recur_alist_p->mutex)); pthread_mutex_unlock (&(recur_alist_p->mutex));
return app; return (app);
} }
/* Returns a structure containing the selected recurrent appointment. */ /* Returns a structure containing the selected recurrent appointment. */
@ -801,12 +863,15 @@ recur_get_apoint(long date, int num)
int n = 0; int n = 0;
pthread_mutex_lock (&(recur_alist_p->mutex)); pthread_mutex_lock (&(recur_alist_p->mutex));
for (o = recur_alist_p->root; o != 0; o = o->next) { for (o = recur_alist_p->root; o != 0; o = o->next)
{
if (recur_item_inday (o->start, o->exc, o->rpt->type, if (recur_item_inday (o->start, o->exc, o->rpt->type,
o->rpt->freq, o->rpt->until, date)) { o->rpt->freq, o->rpt->until, date))
if (n == num) { {
if (n == num)
{
pthread_mutex_unlock (&(recur_alist_p->mutex)); pthread_mutex_unlock (&(recur_alist_p->mutex));
return o; return (o);
} }
n++; n++;
} }
@ -823,11 +888,14 @@ recur_get_event(long date, int num)
struct recur_event_s *o; struct recur_event_s *o;
int n = 0; int n = 0;
for (o = recur_elist; o != 0; o = o->next) { for (o = recur_elist; o != 0; o = o->next)
{
if (recur_item_inday (o->day, o->exc, o->rpt->type, if (recur_item_inday (o->day, o->exc, o->rpt->type,
o->rpt->freq, o->rpt->until, date)) { o->rpt->freq, o->rpt->until, date))
if (n == num) { {
return o; if (n == num)
{
return (o);
} }
n++; n++;
} }
@ -848,10 +916,13 @@ recur_apoint_switch_notify(long date, int recur_nb)
need_chk_notify = 0; need_chk_notify = 0;
pthread_mutex_lock (&(recur_alist_p->mutex)); pthread_mutex_lock (&(recur_alist_p->mutex));
for (o = recur_alist_p->root; o != 0; o = o->next) { for (o = recur_alist_p->root; o != 0; o = o->next)
{
if (recur_item_inday (o->start, o->exc, o->rpt->type, if (recur_item_inday (o->start, o->exc, o->rpt->type,
o->rpt->freq, o->rpt->until, date)) { o->rpt->freq, o->rpt->until, date))
if (n == recur_nb) { {
if (n == recur_nb)
{
o->state ^= APOINT_NOTIFY; o->state ^= APOINT_NOTIFY;
if (notify_bar ()) if (notify_bar ())

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 */
@ -82,10 +91,11 @@ 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 *,
struct days_s *);
void recur_save_data (FILE *); void recur_save_data (FILE *);
unsigned recur_item_inday(long, struct days_s *, int, unsigned recur_item_inday (long, struct days_s *, int, int,
int, long, long); long, long);
void recur_event_erase (long, unsigned, unsigned, void recur_event_erase (long, unsigned, unsigned,
erase_flag_e); erase_flag_e);
void recur_apoint_erase (long, unsigned, unsigned, void recur_apoint_erase (long, unsigned, unsigned,

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
@ -42,7 +42,8 @@
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)
; ;
@ -61,7 +62,8 @@ 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"); perror ("sigaction");
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
@ -69,7 +71,8 @@ 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(SIGWINCH, sa, NULL) != 0) { if (sigaction (SIGWINCH, sa, NULL) != 0)
{
perror ("sigaction"); perror ("sigaction");
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
@ -77,7 +80,8 @@ sigs_init(struct sigaction *sa)
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"); perror ("sigaction");
exit (EXIT_FAILURE); 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

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
@ -47,10 +47,11 @@ todo_get_item(int item_number)
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. */
@ -135,14 +136,14 @@ 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, ""); status_mesg (mesg_id, "");
ch = wgetch (win[STA].p); ch = wgetch (win[STA].p);
} }
@ -162,15 +163,17 @@ todo_add(char *mesg, int id, char *note)
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. */
@ -182,11 +185,12 @@ todo_delete_note_bynum(unsigned num)
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;
@ -209,8 +213,10 @@ todo_delete_bynum(unsigned num, erase_flag_e flag)
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)
@ -236,25 +242,29 @@ todo_delete(conf_t *conf)
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); status_mesg (del_todo_str, choices);
answer = wgetch (win[STA].p); answer = wgetch (win[STA].p);
if ( (answer == 'y') && (todos > 0) ) { if ((answer == 'y') && (todos > 0))
{
go_for_todo_del = true; go_for_todo_del = true;
} else { }
else
{
erase_status_bar (); 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;
} }
@ -264,12 +274,14 @@ todo_delete(conf_t *conf)
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); status_mesg (erase_warning, erase_choice);
answer = wgetch (win[STA].p); 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--;
@ -299,18 +311,22 @@ 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
{
fputs (_("FATAL ERROR in todo_get_position: todo not found\n"), stderr);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
} }
@ -332,15 +348,20 @@ todo_chg_priority(int action)
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 == '-')
{
(backup_id < 9) ? backup_id++ : do_chg--;
}
else
{ /* NOTREACHED */
fputs (_("FATAL ERROR in todo_chg_priority: no such action\n"), stderr);
}
if (do_chg)
{
todo_delete_bynum (hilt - 1, ERASE_FORCE_KEEP_NOTE); todo_delete_bynum (hilt - 1, ERASE_FORCE_KEEP_NOTE);
backup = todo_add (backup_mesg, backup_id, backup_note); backup = todo_add (backup_mesg, backup_id, backup_note);
hilt = todo_get_position (backup); hilt = todo_get_position (backup);
@ -374,7 +395,8 @@ display_todo_item(int incolor, char *msg, int prio, int note, int len, int y,
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);
@ -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, display_todo_item (incolor, i->mesg, i->id,
(i->note != NULL) ? 1 : 0, len, y_offset, x_offset); (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);
@ -439,9 +464,9 @@ todo_edit_note(char *editor)
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;

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;

View File

@ -1,4 +1,4 @@
/* $calcurse: utils.c,v 1.44 2008/04/09 20:38:29 culot Exp $ */ /* $calcurse: utils.c,v 1.45 2008/04/12 21:14:03 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -90,7 +90,8 @@ aerror(const char *file, int line, const char *assertion)
char errmsg[BUFSIZ]; char errmsg[BUFSIZ];
snprintf (errmsg, BUFSIZ, snprintf (errmsg, BUFSIZ,
"assert \"%s\" failed: file \"%s\", line %d", assertion, file, line); "assert \"%s\" failed: file \"%s\", line %d", assertion, file,
line);
ierror (errmsg, IERROR_FATAL); ierror (errmsg, IERROR_FATAL);
} }
@ -122,8 +123,10 @@ erase_window_part(WINDOW *win, int first_col, int first_row, int last_col,
{ {
int c, r; int c, r;
for (r = first_row; r <= last_row; r++){ for (r = first_row; r <= last_row; r++)
for (c = first_col; c <= last_col; c++){ {
for (c = first_col; c <= last_col; c++)
{
mvwprintw (win, r, c, " "); mvwprintw (win, r, c, " ");
} }
} }
@ -131,8 +134,8 @@ erase_window_part(WINDOW *win, int first_col, int first_row, int last_col,
} }
/* draws a popup window */ /* draws a popup window */
WINDOW * popup(int pop_row, int pop_col, WINDOW *
int pop_y, int pop_x, char *pop_lab) popup (int pop_row, int pop_col, int pop_y, int pop_x, char *pop_lab)
{ {
char *txt_pop = _("Press any key to continue..."); char *txt_pop = _("Press any key to continue...");
char label[BUFSIZ]; char label[BUFSIZ];
@ -149,7 +152,7 @@ WINDOW * popup(int pop_row, int pop_col,
custom_remove_attr (popup_win, ATTR_HIGHEST); custom_remove_attr (popup_win, ATTR_HIGHEST);
wnoutrefresh (popup_win); wnoutrefresh (popup_win);
doupdate (); doupdate ();
return popup_win; return (popup_win);
} }
/* prints in middle of a panel */ /* prints in middle of a panel */
@ -208,13 +211,19 @@ showstring(WINDOW *win, int y, int x, char *str, int len, int pos)
str += offset; str += offset;
mvwaddnstr (win, y, x, str, MIN (len, max_col)); mvwaddnstr (win, y, x, str, MIN (len, max_col));
wclrtoeol (win); wclrtoeol (win);
if (page > 0 && page < max_page) { if (page > 0 && page < max_page)
{
c = '*'; c = '*';
} else if (page > 0) { }
else if (page > 0)
{
c = '<'; c = '<';
} else if (page < max_page) { }
else if (page < max_page)
{
c = '>'; c = '>';
} else }
else
c = 0; c = 0;
mvwprintw (win, y, col - 1, "%c", c); mvwprintw (win, y, col - 1, "%c", c);
showcursor (win, y, pos, orig, len, offset); showcursor (win, y, pos, orig, len, offset);
@ -265,16 +274,18 @@ getstring(WINDOW *win, char *str, int l, int x, int y)
newpos = x + len; newpos = x + len;
showstring (win, y, x, orig, len, newpos); showstring (win, y, x, orig, len, newpos);
while ((ch = wgetch(win)) != '\n') { while ((ch = wgetch (win)) != '\n')
{
switch (ch) { switch (ch)
{
case KEY_BACKSPACE: /* delete one character */ case KEY_BACKSPACE: /* delete one character */
case 330: case 330:
case 127: case 127:
case CTRL ('H'): case CTRL ('H'):
if (len > 0) { if (len > 0)
--newpos; --len; {
--newpos;
--len;
if (newpos >= x + len) if (newpos >= x + len)
--str; --str;
else /* to be deleted inside string */ else /* to be deleted inside string */
@ -283,13 +294,15 @@ getstring(WINDOW *win, char *str, int l, int x, int y)
break; break;
case CTRL ('D'): /* delete next character */ case CTRL ('D'): /* delete next character */
if (newpos != (x + len)) { if (newpos != (x + len))
{
--len; --len;
if (newpos >= x + len) if (newpos >= x + len)
--str; --str;
else else
del_char (newpos, orig); del_char (newpos, orig);
} else }
else
printf ("\a"); printf ("\a");
break; break;
@ -324,14 +337,17 @@ getstring(WINDOW *win, char *str, int l, int x, int y)
break; break;
default: /* insert one character */ default: /* insert one character */
if (len < l - 1) { if (len < l - 1)
if (newpos >= len) { {
if (newpos >= len)
{
str = orig + newpos; str = orig + newpos;
*str++ = ch; *str++ = ch;
} }
else // char is to be inserted inside string else // char is to be inserted inside string
str = add_char (newpos, ch, orig); str = add_char (newpos, ch, orig);
++len; ++newpos; ++len;
++newpos;
} }
} }
@ -353,21 +369,25 @@ updatestring(WINDOW *win, char **str, int x, int y)
newstr = (char *) malloc (BUFSIZ); newstr = (char *) malloc (BUFSIZ);
(void) memcpy (newstr, *str, len); (void) memcpy (newstr, *str, len);
escape = getstring (win, newstr, BUFSIZ, x, y); escape = getstring (win, newstr, BUFSIZ, x, y);
if (!escape) { if (!escape)
{
len = strlen (newstr) + 1; len = strlen (newstr) + 1;
if ((*str = (char *) realloc(*str, len)) == NULL) { if ((*str = (char *) realloc (*str, len)) == NULL)
{
/* NOTREACHED */ /* NOTREACHED */
ierror (_("FATAL ERROR in updatestring: out of memory"), ierror (_("FATAL ERROR in updatestring: out of memory"),
IERROR_FATAL); IERROR_FATAL);
} else }
else
(void) memcpy (*str, newstr, len); (void) memcpy (*str, newstr, len);
} }
free (newstr); free (newstr);
return escape; return (escape);
} }
/* checks if a string is only made of digits */ /* checks if a string is only made of digits */
int is_all_digit(char *string) int
is_all_digit (char *string)
{ {
int digit, i; int digit, i;
int all_digit; int all_digit;
@ -380,7 +400,7 @@ int is_all_digit(char *string)
digit++; digit++;
if (digit == strlen (string)) if (digit == strlen (string))
all_digit = 1; all_digit = 1;
return all_digit; return (all_digit);
} }
/* /*
@ -447,12 +467,12 @@ status_bar(void)
which_pan = wins_slctd (); which_pan = wins_slctd ();
start = pos[which_pan] + 2 * CMDS_PER_LINE * (status_page - 1); start = pos[which_pan] + 2 * CMDS_PER_LINE * (status_page - 1);
end = MIN (start + 2 * CMDS_PER_LINE, pos[which_pan + 1]); end = MIN (start + 2 * CMDS_PER_LINE, pos[which_pan + 1]);
for (i = start; i < end; i += 2) { for (i = start; i < end; i += 2)
{
custom_apply_attr (win[STA].p, ATTR_HIGHEST); custom_apply_attr (win[STA].p, ATTR_HIGHEST);
mvwprintw (win[STA].p, 0, j * cmd_length, binding[i]->key); mvwprintw (win[STA].p, 0, j * cmd_length, binding[i]->key);
if (i + 1 != end) if (i + 1 != end)
mvwprintw(win[STA].p, 1, j * cmd_length, mvwprintw (win[STA].p, 1, j * cmd_length, binding[i + 1]->key);
binding[i+1]->key);
custom_remove_attr (win[STA].p, ATTR_HIGHEST); custom_remove_attr (win[STA].p, ATTR_HIGHEST);
mvwprintw (win[STA].p, 0, j * cmd_length + KEY_LENGTH, mvwprintw (win[STA].p, 0, j * cmd_length + KEY_LENGTH,
binding[i]->label); binding[i]->label);
@ -484,9 +504,9 @@ date2sec(date_t day, unsigned hour, unsigned min)
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 date2sec: failure in mktime\n"), {
stderr); fputs (_("FATAL ERROR in date2sec: failure in mktime\n"), stderr);
fprintf (stderr, "%u %u %u %u %u\n", day.yyyy, day.mm, day.dd, fprintf (stderr, "%u %u %u %u %u\n", day.yyyy, day.mm, day.dd,
hour, min); hour, min);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
@ -496,7 +516,8 @@ date2sec(date_t day, unsigned hour, unsigned min)
} }
/* Return a string containing the hour of a given date in seconds. */ /* Return a string containing the hour of a given date in seconds. */
char *date_sec2hour_str(long sec) char *
date_sec2hour_str (long sec)
{ {
const int TIME_LEN = 6; const int TIME_LEN = 6;
struct tm *lt; struct tm *lt;
@ -507,7 +528,7 @@ char *date_sec2hour_str(long sec)
lt = localtime (&t); lt = localtime (&t);
timestr = (char *) malloc (TIME_LEN); timestr = (char *) malloc (TIME_LEN);
snprintf (timestr, TIME_LEN, "%02u:%02u", lt->tm_hour, lt->tm_min); snprintf (timestr, TIME_LEN, "%02u:%02u", lt->tm_hour, lt->tm_min);
return timestr; return (timestr);
} }
/* Return a string containing the date, given a date in seconds. */ /* Return a string containing the date, given a date in seconds. */
@ -522,7 +543,8 @@ date_sec2date_str(long sec, char *datefmt)
if (sec == 0) if (sec == 0)
snprintf (datestr, BUFSIZ, "0"); snprintf (datestr, BUFSIZ, "0");
else { else
{
t = sec; t = sec;
lt = localtime (&t); lt = localtime (&t);
strftime (datestr, BUFSIZ, datefmt, lt); strftime (datestr, BUFSIZ, datefmt, lt);
@ -600,7 +622,8 @@ get_sec_date(date_t date)
char current_month[] = "mm "; char current_month[] = "mm ";
char current_year[] = "yyyy "; char current_year[] = "yyyy ";
if (date.yyyy == 0 && date.mm == 0 && date.dd == 0) { if (date.yyyy == 0 && date.mm == 0 && date.dd == 0)
{
timer = time (NULL); timer = time (NULL);
ptrtime = localtime (&timer); ptrtime = localtime (&timer);
strftime (current_day, strlen (current_day), "%d", ptrtime); strftime (current_day, strlen (current_day), "%d", ptrtime);
@ -611,7 +634,7 @@ get_sec_date(date_t date)
date.yyyy = atoi (current_year); date.yyyy = atoi (current_year);
} }
long_date = date2sec (date, 0, 0); long_date = date2sec (date, 0, 0);
return long_date; return (long_date);
} }
long long
@ -635,37 +658,33 @@ check_time(char *string)
char hour[] = " "; char hour[] = " ";
char minutes[] = " "; char minutes[] = " ";
if (((strlen(string) == 2) || (strlen(string) == 3)) && if (((strlen (string) == 2) || (strlen (string) == 3))
(isdigit(string[0]) != 0) && (isdigit(string[1]) != 0)) { && (isdigit (string[0]) != 0) && (isdigit (string[1]) != 0))
{
strncpy (minutes, string, 2); strncpy (minutes, string, 2);
if (atoi (minutes) >= 0) if (atoi (minutes) >= 0)
ok = 2; /* [MM] format */ ok = 2; /* [MM] format */
}
} else if ((strlen(string) == 4) && (isdigit(string[0]) != 0) && else if ((strlen (string) == 4) && (isdigit (string[0]) != 0)
(isdigit(string[2]) != 0) && (isdigit(string[3]) != 0) && && (isdigit (string[2]) != 0) && (isdigit (string[3]) != 0)
(string[1] == ':')) { && (string[1] == ':'))
{
strncpy (hour, string, 1); strncpy (hour, string, 1);
strncpy (minutes, string + 2, 2); strncpy (minutes, string + 2, 2);
if ((atoi(hour) <= 24) && (atoi(hour) >= 0) && if ((atoi (hour) <= 24) && (atoi (hour) >= 0)
(atoi(minutes) < MININSEC) && (atoi(minutes) >= 0)) && (atoi (minutes) < MININSEC) && (atoi (minutes) >= 0))
ok = 1; /* [H:MM] format */ ok = 1; /* [H:MM] format */
}
} else if ((strlen(string) == 5) && (isdigit(string[0]) != 0) && else if ((strlen (string) == 5) && (isdigit (string[0]) != 0)
(isdigit(string[1]) != 0) && (isdigit(string[3]) != 0) && && (isdigit (string[1]) != 0) && (isdigit (string[3]) != 0)
(isdigit(string[4]) != 0) && (string[2] == ':')) { && (isdigit (string[4]) != 0) && (string[2] == ':'))
{
strncpy (hour, string, 2); strncpy (hour, string, 2);
strncpy (minutes, string + 3, 2); strncpy (minutes, string + 3, 2);
if ((atoi(hour) <= 24) && (atoi(hour) >= 0) && if ((atoi (hour) <= 24) && (atoi (hour) >= 0)
(atoi(minutes) < MININSEC) && (atoi(minutes) >= 0)) && (atoi (minutes) < MININSEC) && (atoi (minutes) >= 0))
ok = 1; /* [HH:MM] format */ ok = 1; /* [HH:MM] format */
} }
return (ok); return (ok);
} }
@ -673,7 +692,8 @@ check_time(char *string)
* Display a scroll bar when there are so many items that they * Display a scroll bar when there are so many items that they
* can not be displayed inside the corresponding panel. * can not be displayed inside the corresponding panel.
*/ */
void draw_scrollbar(WINDOW *win, int y, int x, int length, void
draw_scrollbar (WINDOW *win, int y, int x, int length,
int bar_top, int bar_bottom, bool hilt) int bar_top, int bar_bottom, bool hilt)
{ {
mvwvline (win, bar_top, x, ACS_VLINE, bar_bottom - bar_top); mvwvline (win, bar_top, x, ACS_VLINE, bar_bottom - bar_top);
@ -691,7 +711,8 @@ void draw_scrollbar(WINDOW *win, int y, int x, int length,
* popup window. This is useful if an item description is too * popup window. This is useful if an item description is too
* long to fit in its corresponding panel window. * long to fit in its corresponding panel window.
*/ */
void item_in_popup(char *saved_a_start, char *saved_a_end, char *msg, void
item_in_popup (char *saved_a_start, char *saved_a_end, char *msg,
char *pop_title) char *pop_title)
{ {
WINDOW *popup_win, *pad; WINDOW *popup_win, *pad;
@ -701,7 +722,8 @@ void item_in_popup(char *saved_a_start, char *saved_a_end, char *msg,
pad = newpad (padl, padw); pad = newpad (padl, padw);
popup_win = popup (winl, winw, 1, 2, pop_title); popup_win = popup (winl, winw, 1, 2, pop_title);
if (strncmp(pop_title, _("Appointment"), 11) == 0) { if (strncmp (pop_title, _("Appointment"), 11) == 0)
{
mvwprintw (popup_win, margin_top, margin_left, "- %s -> %s", mvwprintw (popup_win, margin_top, margin_left, "- %s -> %s",
saved_a_start, saved_a_end); saved_a_start, saved_a_end);
} }
@ -715,18 +737,21 @@ void item_in_popup(char *saved_a_start, char *saved_a_end, char *msg,
} }
/* Reset the status bar page. */ /* Reset the status bar page. */
void reset_status_page(void) void
reset_status_page (void)
{ {
status_page = 1; status_page = 1;
} }
/* Update the status bar page number to display other commands. */ /* Update the status bar page number to display other commands. */
void other_status_page(int panel) void
other_status_page (int panel)
{ {
int nb_item = 0, max_page; int nb_item = 0, max_page;
char *error = _("FATAL ERROR in other_status_page: unknown panel\n"); char *error = _("FATAL ERROR in other_status_page: unknown panel\n");
switch (panel) { switch (panel)
{
case CAL: case CAL:
nb_item = NB_CAL_CMDS; nb_item = NB_CAL_CMDS;
break; break;
@ -740,9 +765,12 @@ void other_status_page(int panel)
ierror (error, IERROR_FATAL); ierror (error, IERROR_FATAL);
} }
max_page = ceil (nb_item / (2 * CMDS_PER_LINE)) + 1; max_page = ceil (nb_item / (2 * CMDS_PER_LINE)) + 1;
if (status_page < max_page) { if (status_page < max_page)
{
status_page++; status_page++;
} else { }
else
{
status_page = 1; status_page = 1;
} }
} }
@ -763,27 +791,29 @@ get_today(void)
day.yyyy = lt->tm_year + 1900; day.yyyy = lt->tm_year + 1900;
current_day = date2sec (day, 0, 0); current_day = date2sec (day, 0, 0);
return current_day; return (current_day);
} }
/* Returns the current time in seconds. */ /* Returns the current time in seconds. */
long now(void) long
now (void)
{ {
time_t current_time; time_t current_time;
current_time = time (NULL); current_time = time (NULL);
return current_time; return (current_time);
} }
/* Copy a string */ /* Copy a string */
char *mycpy(const char *src) char *
mycpy (const char *src)
{ {
char *string = malloc (strlen (src) + 1); char *string = malloc (strlen (src) + 1);
if (string != NULL) if (string != NULL)
return strncpy(string, src, strlen(src) + 1); return (strncpy (string, src, strlen (src) + 1));
else else
return NULL; return (NULL);
} }
long long
@ -813,15 +843,19 @@ print_option_incolor(WINDOW *win, bool option, int pos_y, int pos_x)
int color = 0; int color = 0;
char option_value[BUFSIZ] = ""; char option_value[BUFSIZ] = "";
if (option == true) { if (option == true)
{
color = ATTR_TRUE; color = ATTR_TRUE;
strncpy (option_value, _("yes"), BUFSIZ); strncpy (option_value, _("yes"), BUFSIZ);
} else if (option == false) { }
else if (option == false)
{
color = ATTR_FALSE; color = ATTR_FALSE;
strncpy (option_value, _("no"), BUFSIZ); strncpy (option_value, _("no"), BUFSIZ);
} else { }
ierror( else
_("option not defined - Problem in print_option_incolor()"), {
ierror (_("option not defined - Problem in print_option_incolor()"),
IERROR_FATAL); IERROR_FATAL);
} }
custom_apply_attr (win, color); custom_apply_attr (win, color);
@ -851,14 +885,14 @@ new_tempfile(const char *prefix, int trailing_len)
memcpy (fullname, prefix, prefix_len); memcpy (fullname, prefix, prefix_len);
memset (fullname + prefix_len, 'X', trailing_len); memset (fullname + prefix_len, 'X', trailing_len);
fullname[prefix_len + trailing_len] = '\0'; fullname[prefix_len + trailing_len] = '\0';
if ((fd = mkstemp(fullname)) == -1 || if ((fd = mkstemp (fullname)) == -1 || (file = fdopen (fd, "w+")) == NULL)
(file = fdopen(fd, "w+")) == NULL) { {
if (fd != -1) { if (fd != -1)
{
unlink (fullname); unlink (fullname);
close (fd); close (fd);
} }
ierror( ierror (_("FATAL ERROR: temporary file could not be created!"),
_("FATAL ERROR: temporary file could not be created!"),
IERROR_WARN); IERROR_WARN);
return (NULL); return (NULL);
} }
@ -876,7 +910,8 @@ erase_note(char **note, erase_flag_e flag)
if (*note == NULL) if (*note == NULL)
return; return;
if (flag != ERASE_FORCE_KEEP_NOTE) { if (flag != ERASE_FORCE_KEEP_NOTE)
{
snprintf (fullname, BUFSIZ, "%s%s", path_notes, *note); snprintf (fullname, BUFSIZ, "%s%s", path_notes, *note);
if (unlink (fullname) != 0) if (unlink (fullname) != 0)
ierror (errmsg, IERROR_FATAL); ierror (errmsg, IERROR_FATAL);
@ -884,20 +919,23 @@ erase_note(char **note, erase_flag_e flag)
free (*note); free (*note);
*note = NULL; *note = NULL;
} }
/* /*
* Convert a string containing a date into three integers containing the year, * Convert a string containing a date into three integers containing the year,
* month and day. * month and day.
* Returns 1 if sucessfully converted or 0 if the string is an invalid date. * Returns 1 if sucessfully converted or 0 if the string is an invalid date.
*/ */
int parse_date(char *date_string, int datefmt, int
int *year, int *month, int *day) { parse_date (char *date_string, int datefmt, int *year, int *month, int *day)
{
int in1, in2, in3; int in1, in2, in3;
int lyear, lmonth, lday; int lyear, lmonth, lday;
if (date_string == NULL) if (date_string == NULL)
return 0; return (0);
if (sscanf (date_string, "%d / %d / %d", &in1, &in2, &in3) < 3) if (sscanf (date_string, "%d / %d / %d", &in1, &in2, &in3) < 3)
return 0; return (0);
switch (datefmt) { switch (datefmt)
{
case 1: case 1:
lmonth = in1; lmonth = in1;
lday = in2; lday = in2;
@ -916,9 +954,9 @@ int parse_date(char *date_string, int datefmt,
default: default:
return (0); return (0);
} }
if (lyear < 1 || lyear > 9999 || lmonth < 1 || lmonth > 12 || if (lyear < 1 || lyear > 9999 || lmonth < 1 || lmonth > 12 || lday < 1
lday < 1 || lday > 31) || lday > 31)
return 0; return (0);
if (year != NULL) if (year != NULL)
*year = lyear; *year = lyear;
if (month != NULL) if (month != NULL)

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,22 +51,28 @@
#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);

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,7 +87,6 @@ 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
*/ */

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;

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
@ -133,8 +133,7 @@ wins_reinit(void)
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. */
@ -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;
@ -269,20 +275,24 @@ border_color(WINDOW *window)
int color_attr = A_BOLD; int color_attr = A_BOLD;
int no_color_attr = A_BOLD; int no_color_attr = A_BOLD;
if (colorize) { if (colorize)
{
wattron (window, color_attr | COLOR_PAIR (COLR_CUSTOM)); wattron (window, color_attr | COLOR_PAIR (COLR_CUSTOM));
box (window, 0, 0); box (window, 0, 0);
} else { }
else
{
wattron (window, no_color_attr); wattron (window, no_color_attr);
box (window, 0, 0); box (window, 0, 0);
} }
if (colorize)
if (colorize) { {
wattroff (window, color_attr | COLOR_PAIR (COLR_CUSTOM)); wattroff (window, color_attr | COLOR_PAIR (COLR_CUSTOM));
} else { }
else
{
wattroff (window, no_color_attr); wattroff (window, no_color_attr);
} }
wnoutrefresh (window); wnoutrefresh (window);
} }
@ -293,20 +303,23 @@ border_nocolor(WINDOW *window)
int color_attr = A_BOLD; int color_attr = A_BOLD;
int no_color_attr = A_DIM; int no_color_attr = A_DIM;
if (colorize) { if (colorize)
{
wattron (window, color_attr | COLOR_PAIR (COLR_DEFAULT)); wattron (window, color_attr | COLOR_PAIR (COLR_DEFAULT));
} else { }
else
{
wattron (window, no_color_attr); wattron (window, no_color_attr);
} }
box (window, 0, 0); box (window, 0, 0);
if (colorize)
if (colorize) { {
wattroff (window, color_attr | COLOR_PAIR (COLR_DEFAULT)); wattroff (window, color_attr | COLOR_PAIR (COLR_DEFAULT));
} else { }
else
{
wattroff (window, no_color_attr); wattroff (window, no_color_attr);
} }
wnoutrefresh (window); wnoutrefresh (window);
} }
@ -317,8 +330,8 @@ border_nocolor(WINDOW *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);
@ -374,10 +387,12 @@ 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); p = (char *) malloc (sizeof (char) * len);
if (snprintf(p, len, "%s %s", cmd, file) == -1) { if (snprintf (p, len, "%s %s", cmd, file) == -1)
{
free (p); free (p);
return; return;
} }

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,23 +29,27 @@
#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];