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:
Tony's patch concerning date format configuration imported, many
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
@ -49,7 +49,7 @@ apoint_llist_init(void)
alist_p->root = NULL;
pthread_mutex_init (&(alist_p->mutex), NULL);
return 0;
return (0);
}
/* 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));
i = &alist_p->root;
for (;;) {
if (*i == 0 || (*i)->start > start) {
for (;;)
{
if (*i == 0 || (*i)->start > start)
{
o->next = *i;
*i = o;
break;
@ -103,7 +105,7 @@ apoint_new(char *mesg, char *note, long start, long dur, char state)
}
pthread_mutex_unlock (&(alist_p->mutex));
return o;
return (o);
}
/*
@ -114,11 +116,16 @@ void
apoint_add (void)
{
#define LTIME 6
char *mesg_1 = _("Enter start time ([hh:mm] or [h:mm]), leave blank for an all-day event : ");
char *mesg_2 = _("Enter end time ([hh:mm] or [h:mm]) or duration (in minutes) : ");
char *mesg_1 =
_("Enter start time ([hh:mm] or [h:mm]), "
"leave blank for an all-day event : ");
char *mesg_2 =
_("Enter end time ([hh:mm] or [h:mm]) or duration (in minutes) : ");
char *mesg_3 = _("Enter description :");
char *format_message_1 = _("You entered an invalid start time, should be [h:mm] or [hh:mm]");
char *format_message_2 = _("You entered an invalid end time, should be [h:mm] or [hh:mm] or [mm]");
char *format_message_1 =
_("You entered an invalid start time, should be [h:mm] or [hh:mm]");
char *format_message_2 =
_("You entered an invalid end time, should be [h:mm] or [hh:mm] or [mm]");
char *enter_str = _("Press [Enter] to continue");
int Id = 1;
char item_time[LTIME] = "";
@ -131,19 +138,25 @@ apoint_add(void)
int is_appointment = 1;
/* Get the starting time */
while (check_time(item_time) != 1) {
while (check_time (item_time) != 1)
{
status_mesg (mesg_1, "");
if (getstring(win[STA].p, item_time, LTIME, 0, 1) !=
GETSTRING_ESC) {
if (strlen(item_time) == 0){
if (getstring (win[STA].p, item_time, LTIME, 0, 1) != GETSTRING_ESC)
{
if (strlen (item_time) == 0)
{
is_appointment = 0;
break;
} else if (check_time(item_time) != 1) {
}
else if (check_time (item_time) != 1)
{
status_mesg (format_message_1, enter_str);
wgetch (win[STA].p);
} else
}
else
sscanf (item_time, "%u:%u", &heures, &minutes);
} else
}
else
return;
}
/*
@ -151,55 +164,58 @@ apoint_add(void)
* depending on the starting time, and record the
* corresponding item.
*/
if (is_appointment){ /* Get the appointment duration */
if (is_appointment)
{ /* Get the appointment duration */
item_time[0] = '\0';
while (check_time(item_time) == 0) {
while (check_time (item_time) == 0)
{
status_mesg (mesg_2, "");
if (getstring(win[STA].p, item_time, LTIME, 0, 1) !=
GETSTRING_VALID)
if (getstring (win[STA].p, item_time, LTIME, 0, 1) != GETSTRING_VALID)
return; //nothing entered, cancel adding of event
else if (check_time(item_time) == 0) {
else if (check_time (item_time) == 0)
{
status_mesg (format_message_2, enter_str);
wgetch (win[STA].p);
} else {
}
else
{
if (check_time (item_time) == 2)
apoint_duration = atoi (item_time);
else if (check_time(item_time) == 1) {
sscanf(item_time, "%u:%u",
&end_h, &end_m);
if (end_h < heures){
apoint_duration =
MININSEC - minutes + end_m
+
(24 + end_h - (heures + 1))
* MININSEC;
} else {
apoint_duration =
MININSEC - minutes +
end_m +
(end_h - (heures + 1)) *
MININSEC;
else if (check_time (item_time) == 1)
{
sscanf (item_time, "%u:%u", &end_h, &end_m);
if (end_h < heures)
{
apoint_duration = MININSEC - minutes + end_m
+ (24 + end_h - (heures + 1)) * MININSEC;
}
else
{
apoint_duration = MININSEC - minutes
+ end_m + (end_h - (heures + 1)) * MININSEC;
}
}
}
}
} else /* Insert the event Id */
}
else /* Insert the event Id */
Id = 1;
status_mesg (mesg_3, "");
if (getstring(win[STA].p, item_mesg, BUFSIZ, 0, 1) ==
GETSTRING_VALID) {
if (is_appointment) {
apoint_start =
date2sec(*calendar_get_slctd_day(), heures,
minutes);
if (getstring (win[STA].p, item_mesg, BUFSIZ, 0, 1) == GETSTRING_VALID)
{
if (is_appointment)
{
apoint_start = date2sec (*calendar_get_slctd_day (), heures, minutes);
apoint_pointeur = apoint_new (item_mesg, 0L, apoint_start,
min2sec (apoint_duration), 0L);
if (notify_bar ())
notify_check_added (item_mesg, apoint_start, 0L);
} else
}
else
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)
hilt++;
@ -223,43 +239,48 @@ apoint_delete(conf_t *conf, unsigned *nb_events, unsigned *nb_apoints)
date = calendar_get_slctd_day_sec ();
if (conf->confirm_delete) {
if (conf->confirm_delete)
{
status_mesg (del_app_str, choices);
answer = wgetch (win[STA].p);
if ((answer == 'y') && (nb_items != 0))
go_for_deletion = true;
else {
else
{
erase_status_bar ();
return;
}
} else
if (nb_items != 0)
}
else if (nb_items != 0)
go_for_deletion = true;
if (go_for_deletion) {
if (nb_items != 0) {
deleted_item_type =
day_erase_item(date, hilt, ERASE_DONT_FORCE);
if (deleted_item_type == EVNT ||
deleted_item_type == RECUR_EVNT) {
if (go_for_deletion)
{
if (nb_items != 0)
{
deleted_item_type = day_erase_item (date, hilt, ERASE_DONT_FORCE);
if (deleted_item_type == EVNT || deleted_item_type == RECUR_EVNT)
{
(*nb_events)--;
to_be_removed = 1;
} else if (deleted_item_type == APPT ||
deleted_item_type == RECUR_APPT) {
}
else if (deleted_item_type == APPT || deleted_item_type == RECUR_APPT)
{
(*nb_apoints)--;
to_be_removed = 3;
} else if (deleted_item_type == 0) {
}
else if (deleted_item_type == 0)
{
to_be_removed = 0;
} else
}
else
ierror (errmsg, IERROR_FATAL);
/* NOTREACHED */
if (hilt > 1)
hilt--;
if (apad->first_onscreen >= to_be_removed)
apad->first_onscreen =
apad->first_onscreen -
to_be_removed;
apad->first_onscreen = apad->first_onscreen - to_be_removed;
if (nb_items == 1)
hilt = 0;
}
@ -269,10 +290,11 @@ apoint_delete(conf_t *conf, unsigned *nb_events, unsigned *nb_apoints)
unsigned
apoint_inday (apoint_llist_node_t *i, long start)
{
if (i->start <= start + DAYINSEC && i->start + i->dur > start) {
return 1;
if (i->start <= start + DAYINSEC && i->start + i->dur > start)
{
return (1);
}
return 0;
return (0);
}
void
@ -282,21 +304,25 @@ apoint_sec2str(apoint_llist_node_t *o, int type, long day, char *start,
struct tm *lt;
time_t t;
if (o->start < day && type == APPT) {
if (o->start < day && type == APPT)
{
strncpy (start, "..:..", 6);
} else {
}
else
{
t = o->start;
lt = localtime (&t);
snprintf(start, HRMIN_SIZE, "%02u:%02u", lt->tm_hour,
lt->tm_min);
snprintf (start, HRMIN_SIZE, "%02u:%02u", lt->tm_hour, lt->tm_min);
}
if (o->start + o->dur > day + DAYINSEC && type == APPT) {
if (o->start + o->dur > day + DAYINSEC && type == APPT)
{
strncpy (end, "..:..", 6);
} else {
}
else
{
t = o->start + o->dur;
lt = localtime (&t);
snprintf(end, HRMIN_SIZE, "%02u:%02u", lt->tm_hour,
lt->tm_min);
snprintf (end, HRMIN_SIZE, "%02u:%02u", lt->tm_hour, lt->tm_min);
}
}
@ -309,14 +335,14 @@ apoint_write(apoint_llist_node_t *o, FILE * f)
t = o->start;
lt = localtime (&t);
fprintf (f, "%02u/%02u/%04u @ %02u:%02u",
lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year,
lt->tm_hour, lt->tm_min);
lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year, lt->tm_hour,
lt->tm_min);
t = o->start + o->dur;
lt = localtime (&t);
fprintf (f, " -> %02u/%02u/%04u @ %02u:%02u ",
lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year,
lt->tm_hour, lt->tm_min);
lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year, lt->tm_hour,
lt->tm_min);
if (o->note != NULL)
fprintf (f, ">%s ", o->note);
@ -342,7 +368,8 @@ apoint_scan(FILE * f, struct tm start, struct tm end, char state, char *note)
/* Read the appointment description */
fgets (buf, MESG_MAXSIZE, f);
nl = strchr (buf, '\n');
if (nl) {
if (nl)
{
*nl = '\0';
}
@ -355,8 +382,10 @@ apoint_scan(FILE * f, struct tm start, struct tm end, char state, char *note)
tstart = mktime (&start);
tend = mktime (&end);
if (tstart == -1 || tend == -1 || tstart > tend) {
fputs(_("FATAL ERROR in apoint_scan: date error in the appointment\n"), stderr);
if (tstart == -1 || tend == -1 || tstart > tend)
{
fputs (_("FATAL ERROR in apoint_scan: date error in the appointment\n"),
stderr);
exit (EXIT_FAILURE);
}
return (apoint_new (buf, note, tstart, tend - tstart, state));
@ -370,10 +399,12 @@ apoint_get(long day, int pos)
int n;
n = 0;
for (o = alist_p->root; o; o = o->next) {
if (apoint_inday(o, day)) {
for (o = alist_p->root; o; o = o->next)
{
if (apoint_inday (o, day))
{
if (n == pos)
return o;
return (o);
n++;
}
}
@ -392,15 +423,18 @@ apoint_delete_bynum(long start, unsigned num, erase_flag_e flag)
n = 0;
pthread_mutex_lock (&(alist_p->mutex));
iptr = &alist_p->root;
for (i = alist_p->root; i != 0; i = i->next) {
if (apoint_inday(i, start)) {
if (n == num) {
for (i = alist_p->root; i != 0; i = i->next)
{
if (apoint_inday (i, start))
{
if (n == num)
{
if (flag == ERASE_FORCE_ONLY_NOTE)
erase_note (&i->note, flag);
else {
else
{
if (notify_bar ())
need_check_notify =
notify_same_item(i->start);
need_check_notify = notify_same_item (i->start);
*iptr = i->next;
free (i->mesg);
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)
line = item_nb - 1;
else
line = nb_events_inday + separator +
(item_nb - (nb_events_inday + 1))*3 - 1;
line = nb_events_inday + separator
+ (item_nb - (nb_events_inday + 1)) * 3 - 1;
return line;
}
@ -487,12 +521,17 @@ apoint_check_next(struct notify_app_s *app, long start)
apoint_llist_node_t *i;
pthread_mutex_lock (&(alist_p->mutex));
for (i = alist_p->root; i != 0; i = i->next) {
if (i->start > app->time) {
for (i = alist_p->root; i != 0; i = i->next)
{
if (i->start > app->time)
{
pthread_mutex_unlock (&(alist_p->mutex));
return app;
} else {
if (i->start > start) {
return (app);
}
else
{
if (i->start > start)
{
app->time = i->start;
app->txt = mycpy (i->mesg);
app->state = i->state;
@ -502,7 +541,7 @@ apoint_check_next(struct notify_app_s *app, long start)
}
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->dur = p->dur;
a->mesg = p->mesg;
return a;
return (a);
}
/*
@ -539,25 +578,30 @@ apoint_switch_notify(void)
date = calendar_get_slctd_day_sec ();
if (p->type == RECUR_APPT) {
if (p->type == RECUR_APPT)
{
recur_apoint_switch_notify (date, p->appt_pos);
return;
} else if (p->type == APPT)
}
else if (p->type == APPT)
apoint_nb = day_item_nb (date, hilt, APPT);
n = 0;
need_chk_notify = 0;
pthread_mutex_lock (&(alist_p->mutex));
for (apoint = alist_p->root; apoint != 0; apoint = apoint->next) {
if (apoint_inday(apoint, date)) {
if (n == apoint_nb) {
for (apoint = alist_p->root; apoint != 0; apoint = apoint->next)
{
if (apoint_inday (apoint, date))
{
if (n == apoint_nb)
{
apoint->state ^= APOINT_NOTIFY;
if (notify_bar ())
notify_check_added(apoint->mesg,
apoint->start, apoint->state);
{
notify_check_added (apoint->mesg, apoint->start,
apoint->state);
}
pthread_mutex_unlock (&(alist_p->mutex));
if (need_chk_notify)
notify_check_next_app ();
@ -569,8 +613,7 @@ apoint_switch_notify(void)
pthread_mutex_unlock (&(alist_p->mutex));
/* NOTREACHED */
ierror(
_("FATAL ERROR in apoint_switch_notify: no such appointment"),
ierror (_("FATAL ERROR in apoint_switch_notify: no such appointment"),
IERROR_FATAL);
}
@ -595,8 +638,7 @@ apoint_update_panel(window_t *winapp, int which_pan)
day_write_pad (date, app_width, app_length, hilt);
/* Print current date in the top right window corner. */
erase_window_part(win[APP].p, 1, title_lines, winapp->w - 2,
winapp->h - 2);
erase_window_part (win[APP].p, 1, title_lines, winapp->w - 2, winapp->h - 2);
custom_apply_attr (win[APP].p, ATTR_HIGHEST);
mvwprintw (win[APP].p, title_lines, title_xpos, "%s %s %d, %d",
calendar_get_pom (date), _(monthnames[slctd_date.mm - 1]),
@ -604,7 +646,8 @@ apoint_update_panel(window_t *winapp, int which_pan)
custom_remove_attr (win[APP].p, ATTR_HIGHEST);
/* 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);
int sbar_length = (int) (ratio * app_length);
int highend = (int) (ratio * apad->first_onscreen);
@ -620,5 +663,6 @@ apoint_update_panel(window_t *winapp, int which_pan)
wnoutrefresh (win[APP].p);
pnoutrefresh (apad->ptrwin, apad->first_onscreen, 0,
winapp->y + title_lines + 1, winapp->x + bordr,
winapp->y + winapp->h - 2*bordr, winapp->x + winapp->w - 3*bordr);
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
@ -39,19 +39,23 @@
#define APOINT_NOTIFY 0x1 /* Item needs to be notified */
#define APOINT_NOTIFIED 0x2 /* Item was already notified */
typedef struct apoint_llist_node {
typedef struct apoint_llist_node
{
struct apoint_llist_node *next;
long start; /* seconds since 1 jan 1970 */
long dur; /* duration of the appointment in seconds */
char state; /* 8 bits to store item state */
char *mesg;
char *note;
} apoint_llist_node_t;
}
apoint_llist_node_t;
typedef struct apoint_llist {
typedef struct apoint_llist
{
apoint_llist_node_t *root;
pthread_mutex_t mutex;
} apoint_llist_t;
}
apoint_llist_t;
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_delete (conf_t *, unsigned *, unsigned *);
unsigned apoint_inday (apoint_llist_node_t *, long);
void apoint_sec2str(apoint_llist_node_t *, int, long,
char *, char *);
void apoint_sec2str (apoint_llist_node_t *, int, long, char *,
char *);
void apoint_write (apoint_llist_node_t *, FILE *);
apoint_llist_node_t *apoint_scan (FILE *, struct tm, struct tm, char, char *);
apoint_llist_node_t *apoint_get (long, int);

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
@ -48,17 +48,15 @@ static void
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);
}
static void
usage_try ()
{
char *arg_usage_try =
_("Try 'calcurse -h' for more information.\n");
char *arg_usage_try = _("Try 'calcurse -h' for more information.\n");
fputs (arg_usage_try, stdout);
}
@ -70,11 +68,10 @@ version_arg()
{
char vtitle[BUFSIZ];
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");
snprintf(vtitle, BUFSIZ,
_("Calcurse %s - text-based organizer\n"), VERSION);
snprintf (vtitle, BUFSIZ, _("Calcurse %s - text-based organizer\n"), VERSION);
fputs (vtitle, stdout);
fputs (vtext, stdout);
}
@ -121,8 +118,7 @@ help_arg()
"or read the manpage.\n"
"Mail bug reports and suggestions to <calcurse@culot.org>.\n");
snprintf(htitle, BUFSIZ,
_("Calcurse %s - text-based organizer\n"), VERSION);
snprintf (htitle, BUFSIZ, _("Calcurse %s - text-based organizer\n"), VERSION);
fputs (htitle, stdout);
usage ();
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);
notefile = fopen (path_to_notefile, "r");
if (notefile) {
while (fgets(buffer, BUFSIZ, notefile) != NULL) {
if (printlinestarter) {
if (notefile)
{
while (fgets (buffer, BUFSIZ, notefile) != NULL)
{
if (printlinestarter)
{
fputs (linestarter, out);
printlinestarter = 0;
}
@ -163,7 +162,9 @@ print_notefile(FILE *out, char *filename, int nbtab)
}
fputs ("\n", out);
fclose (notefile);
} else {
}
else
{
fputs (linestarter, out);
fputs (_("No note file found\n"), out);
}
@ -181,9 +182,12 @@ todo_arg(int priority, int print_note)
char priority_str[BUFSIZ] = "";
io_load_todo ();
for (i = todolist; i != 0; i = i->next) {
if (priority == 0 || i->id == priority) {
if (title) {
for (i = todolist; i != 0; i = i->next)
{
if (priority == 0 || i->id == priority)
{
if (title)
{
fputs (_("to do:\n"), stdout);
title = 0;
}
@ -210,17 +214,17 @@ next_arg(void)
next_app.got_app = 0;
next_app.txt = NULL;
next_app = *recur_apoint_check_next(&next_app, current_time,
get_today());
next_app = *recur_apoint_check_next (&next_app, current_time, get_today ());
next_app = *apoint_check_next (&next_app, current_time);
if (next_app.got_app) {
if (next_app.got_app)
{
time_left = next_app.time - current_time;
hours_left = (time_left / HOURINSEC);
min_left = (time_left - hours_left * HOURINSEC) / MININSEC;
fputs (_("next appointment:\n"), stdout);
snprintf(mesg, BUFSIZ, " [%02d:%02d] %s\n",
hours_left, min_left, next_app.txt);
snprintf (mesg, BUFSIZ, " [%02d:%02d] %s\n", hours_left, min_left,
next_app.txt);
fputs (mesg, stdout);
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.
*/
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)) {
for (re = recur_elist; re != 0; re = re->next)
{
if (recur_item_inday (re->day, re->exc, re->rpt->type, re->rpt->freq,
re->rpt->until, today))
{
app_found = 1;
if (add_line) {
if (add_line)
{
fputs ("\n", stdout);
add_line = 0;
}
if (print_date) {
if (print_date)
{
arg_print_date (today, conf);
print_date = false;
}
fputs (" * ", stdout);
fputs(re->mesg, stdout); fputs("\n", stdout);
fputs (re->mesg, stdout);
fputs ("\n", stdout);
if (print_note && re->note)
print_notefile (stdout, re->note, 2);
}
}
for (j = eventlist; j != 0; j = j->next) {
if (event_inday(j, today)) {
for (j = eventlist; j != 0; j = j->next)
{
if (event_inday (j, today))
{
app_found = 1;
if (add_line) {
if (add_line)
{
fputs ("\n", stdout);
add_line = 0;
}
if (print_date) {
if (print_date)
{
arg_print_date (today, conf);
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. */
pthread_mutex_lock (&(recur_alist_p->mutex));
for (ra = recur_alist_p->root; ra != 0; ra = ra->next) {
if (recur_item_inday(ra->start, ra->exc, ra->rpt->type,
ra->rpt->freq, ra->rpt->until, today)) {
for (ra = recur_alist_p->root; ra != 0; ra = ra->next)
{
if (recur_item_inday (ra->start, ra->exc, ra->rpt->type, ra->rpt->freq,
ra->rpt->until, today))
{
app_found = 1;
if (add_line) {
if (add_line)
{
fputs ("\n", stdout);
add_line = 0;
}
if (print_date) {
if (print_date)
{
arg_print_date (today, conf);
print_date = false;
}
apoint_sec2str(apoint_recur_s2apoint_s(ra),
RECUR_APPT, today, apoint_start_time,
apoint_end_time);
apoint_sec2str (apoint_recur_s2apoint_s (ra), RECUR_APPT, today,
apoint_start_time, apoint_end_time);
fputs (" - ", stdout);
fputs (apoint_start_time, stdout);
fputs (" -> ", stdout);
@ -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_lock (&(alist_p->mutex));
for (i = alist_p->root; i != 0; i = i->next) {
if (apoint_inday(i, today)) {
for (i = alist_p->root; i != 0; i = i->next)
{
if (apoint_inday (i, today))
{
app_found = 1;
if (add_line) {
if (add_line)
{
fputs ("\n", stdout);
add_line = 0;
}
if (print_date) {
if (print_date)
{
arg_print_date (today, conf);
print_date = false;
}
apoint_sec2str(i, APPT, today, apoint_start_time,
apoint_end_time);
apoint_sec2str (i, APPT, today, apoint_start_time, apoint_end_time);
fputs (" - ", stdout);
fputs (apoint_start_time, 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));
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
*/
arg_len = strlen (ddate);
if (arg_len <= 4) { /* a number of days was entered */
for (i = 0; i <= arg_len-1; i++) {
if (arg_len <= 4)
{ /* a number of days was entered */
for (i = 0; i <= arg_len - 1; i++)
{
if (isdigit (ddate[i]))
num_digit++;
}
@ -404,7 +425,8 @@ date_arg(char *ddate, int add_line, int print_note, conf_t *conf)
timer = time (NULL);
t = *localtime (&timer);
for (i = 0; i < numdays; i++) {
for (i = 0; i < numdays; i++)
{
day.dd = t.tm_mday;
day.mm = t.tm_mon + 1;
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++;
mktime (&t);
}
} else { /* a date was entered */
if (parse_date(ddate, conf->input_datefmt,
&day.yyyy, &day.mm, &day.dd)) {
}
else
{ /* a date was entered */
if (parse_date (ddate, conf->input_datefmt, &day.yyyy, &day.mm, &day.dd))
{
app_found = app_arg (add_line, &day, 0, print_note, conf);
} else {
fputs(_("Argument to the '-d' flag is not valid\n"),
stdout);
}
else
{
fputs (_("Argument to the '-d' flag is not valid\n"), stdout);
char outstr[BUFSIZ];
snprintf(outstr, BUFSIZ, "Possible argument format are: '%s' or 'n'\n",
snprintf (outstr, BUFSIZ,
"Possible argument format are: '%s' or 'n'\n",
DATEFMT_DESC (conf->input_datefmt));
fputs (_(outstr), stdout);
fputs(_("\nFor more information, type '?' from within Calcurse, or read the manpage.\n"),
stdout);
fputs
(_("Mail bug reports and suggestions to <calcurse@culot.org>.\n"),
fputs (_("\nFor more information, type '?' from within Calcurse, "
"or read the manpage.\n"),
stdout);
fputs (_("Mail bug reports and suggestions to "
"<calcurse@culot.org>.\n"), stdout);
}
}
}
@ -474,8 +500,10 @@ parse_args(int argc, char **argv, conf_t *conf)
{NULL, no_argument, NULL, 0}
};
while ((ch = getopt_long(argc, argv, optstr, longopts, NULL)) != -1) {
switch (ch) {
while ((ch = getopt_long (argc, argv, optstr, longopts, NULL)) != -1)
{
switch (ch)
{
case 'a':
aflag = 1;
multiple_flag++;
@ -509,14 +537,17 @@ parse_args(int argc, char **argv, conf_t *conf)
multiple_flag++;
load_data++;
add_line = 1;
if (optarg != NULL) {
if (optarg != NULL)
{
tnum = atoi (optarg);
if (tnum < 1 || tnum > 9) {
if (tnum < 1 || tnum > 9)
{
usage ();
usage_try ();
return EXIT_FAILURE;
return (EXIT_FAILURE);
}
} else
}
else
tnum = 0;
break;
case 'v':
@ -538,48 +569,66 @@ parse_args(int argc, char **argv, conf_t *conf)
argc -= optind;
argv += optind;
if (argc >= 1) { /* incorrect arguments */
if (argc >= 1)
{
usage ();
usage_try ();
return EXIT_FAILURE;
} else {
if (unknown_flag) {
return (EXIT_FAILURE);
/* Incorrect arguments */
}
else
{
if (unknown_flag)
{
non_interactive = 1;
} else if (hflag) {
}
else if (hflag)
{
help_arg ();
non_interactive = 1;
} else if (vflag) {
}
else if (vflag)
{
version_arg ();
non_interactive = 1;
} else if (multiple_flag) {
if (load_data) {
}
else if (multiple_flag)
{
if (load_data)
{
io_init (cfile);
no_file = io_check_data_files ();
if (dflag || aflag || nflag || xflag)
io_load_app ();
}
if (xflag) {
if (xflag)
{
notify_init_vars ();
custom_load_conf (conf, 0);
io_export_data (IO_EXPORT_NONINTERACTIVE, conf);
non_interactive = 1;
return (non_interactive);
}
if (tflag) {
if (tflag)
{
todo_arg (tnum, Nflag);
non_interactive = 1;
}
if (nflag) {
if (nflag)
{
next_arg ();
non_interactive = 1;
}
if (dflag) {
if (dflag)
{
notify_init_vars ();
vars_init (conf);
custom_load_conf (conf, 0);
date_arg (ddate, add_line, Nflag, conf);
non_interactive = 1;
} else if (aflag) {
}
else if (aflag)
{
date_t day;
day.dd = day.mm = day.yyyy = 0;
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);
non_interactive = 1;
}
} else {
}
else
{
non_interactive = 0;
io_init (cfile);
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

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
@ -99,14 +99,16 @@ main(int argc, char **argv)
wins_get_config ();
/* Check if terminal supports color. */
if (has_colors()) {
if (has_colors ())
{
colorize = true;
background = COLOR_BLACK;
foreground = COLOR_WHITE;
start_color ();
#ifdef NCURSES_VERSION
if (use_default_colors() != ERR) {
if (use_default_colors () != ERR)
{
background = -1;
foreground = -1;
}
@ -123,7 +125,9 @@ main(int argc, char **argv)
init_pair (COLR_HIGH, COLOR_BLACK, COLOR_GREEN);
init_pair (COLR_CUSTOM, COLOR_RED, background);
} else {
}
else
{
colorize = false;
background = COLOR_BLACK;
}
@ -145,7 +149,8 @@ main(int argc, char **argv)
io_load_todo ();
io_load_app ();
wins_reinit ();
if (notify_bar()) {
if (notify_bar ())
{
notify_start_main_thread ();
notify_check_next_app ();
}
@ -157,13 +162,12 @@ main(int argc, char **argv)
calendar_start_date_thread ();
/* User input */
for (;;) {
for (;;)
{
do_update = true;
ch = wgetch (win[STA].p);
switch (ch) {
switch (ch)
{
case ERR:
do_update = false;
break;
@ -177,7 +181,8 @@ main(int argc, char **argv)
case 9: /* The TAB key was hit. */
reset_status_page ();
/* Save previously highlighted event. */
switch (wins_slctd()) {
switch (wins_slctd ())
{
case TOD:
sav_hilt_tod = todo_hilt ();
todo_hilt_set (0);
@ -192,7 +197,8 @@ main(int argc, char **argv)
wins_slctd_next ();
/* Select the event to highlight. */
switch (wins_slctd()) {
switch (wins_slctd ())
{
case TOD:
if ((sav_hilt_tod == 0) && (todo_nb () != 0))
todo_hilt_set (1);
@ -200,8 +206,8 @@ main(int argc, char **argv)
todo_hilt_set (sav_hilt_tod);
break;
case APP:
if ((sav_hilt_app == 0) &&
((inday.nb_events + inday.nb_apoints) != 0))
if ((sav_hilt_app == 0)
&& ((inday.nb_events + inday.nb_apoints) != 0))
apoint_hilt_set (1);
else
apoint_hilt_set (sav_hilt_app);
@ -230,25 +236,26 @@ main(int argc, char **argv)
if ((wins_slctd () == APP) && (apoint_hilt () != 0))
day_popup_item ();
else if ((wins_slctd () == TOD) && (todo_hilt () != 0))
item_in_popup(NULL, NULL, todo_saved_mesg(),
_("To do :"));
item_in_popup (NULL, NULL, todo_saved_mesg (), _("To do :"));
break;
case 'C':
case 'c': /* Configuration menu */
erase_status_bar ();
config_bar ();
while ((ch = wgetch(win[STA].p)) != 'q') {
switch (ch) {
while ((ch = wgetch (win[STA].p)) != 'q')
{
switch (ch)
{
case 'C':
case 'c':
if (has_colors ())
custom_color_config ();
else {
else
{
colorize = false;
erase_status_bar ();
mvwprintw(win[STA].p, 0, 0,
_(no_color_support));
mvwprintw (win[STA].p, 0, 0, _(no_color_support));
wgetch (win[STA].p);
}
break;
@ -287,7 +294,8 @@ main(int argc, char **argv)
case 'A':
case 'a': /* Add an item */
switch (wins_slctd()) {
switch (wins_slctd ())
{
case APP:
apoint_add ();
do_storage = true;
@ -314,8 +322,7 @@ main(int argc, char **argv)
case 'D':
case 'd': /* Delete an item */
if (wins_slctd () == APP && apoint_hilt () != 0)
apoint_delete(&conf, &inday.nb_events,
&inday.nb_apoints);
apoint_delete (&conf, &inday.nb_events, &inday.nb_apoints);
else if (wins_slctd () == TOD && todo_hilt () != 0)
todo_delete (&conf);
do_storage = true;
@ -336,13 +343,13 @@ main(int argc, char **argv)
case '+':
case '-':
if (wins_slctd() == TOD && todo_hilt() != 0) {
if (wins_slctd () == TOD && todo_hilt () != 0)
{
todo_chg_priority (ch);
if (todo_hilt_pos () < 0)
todo_set_first (todo_hilt ());
else if (todo_hilt_pos () >= win[TOD].h - 4)
todo_set_first(todo_hilt() -
win[TOD].h + 5);
todo_set_first (todo_hilt () - win[TOD].h + 5);
}
break;
@ -383,7 +390,8 @@ main(int argc, char **argv)
case ('L'):
case ('l'):
case CTRL ('L'):
if (wins_slctd() == CAL || ch == CTRL('L')) {
if (wins_slctd () == CAL || ch == CTRL ('L'))
{
do_storage = true;
day_changed = true;
calendar_move (RIGHT);
@ -394,7 +402,8 @@ main(int argc, char **argv)
case ('H'):
case ('h'):
case CTRL ('H'):
if (wins_slctd() == CAL || ch == CTRL('H')) {
if (wins_slctd () == CAL || ch == CTRL ('H'))
{
do_storage = true;
day_changed = true;
calendar_move (LEFT);
@ -405,17 +414,21 @@ main(int argc, char **argv)
case ('K'):
case ('k'):
case CTRL ('K'):
if (wins_slctd() == CAL || ch == CTRL('K')) {
if (wins_slctd () == CAL || ch == CTRL ('K'))
{
do_storage = true;
day_changed = true;
calendar_move (UP);
} else {
if ((wins_slctd() == APP) &&
(apoint_hilt() > 1)) {
}
else
{
if ((wins_slctd () == APP) && (apoint_hilt () > 1))
{
apoint_hilt_decrease ();
apoint_scroll_pad_up (inday.nb_events);
} else if ((wins_slctd() == TOD) &&
(todo_hilt() > 1)) {
}
else if ((wins_slctd () == TOD) && (todo_hilt () > 1))
{
todo_hilt_decrease ();
if (todo_hilt_pos () < 0)
todo_first_decrease ();
@ -427,20 +440,22 @@ main(int argc, char **argv)
case ('J'):
case ('j'):
case CTRL ('J'):
if (wins_slctd() == CAL || ch == CTRL('J')) {
if (wins_slctd () == CAL || ch == CTRL ('J'))
{
do_storage = true;
day_changed = true;
calendar_move (DOWN);
} else {
if ((wins_slctd() == APP) &&
(apoint_hilt() < inday.nb_events +
inday.nb_apoints)) {
apoint_hilt_increase();
apoint_scroll_pad_down(inday.nb_events,
win[APP].h);
}
if ((wins_slctd() == TOD) &&
(todo_hilt() < todo_nb())) {
else
{
if ((wins_slctd () == APP) &&
(apoint_hilt () < inday.nb_events + inday.nb_apoints))
{
apoint_hilt_increase ();
apoint_scroll_pad_down (inday.nb_events, win[APP].h);
}
if ((wins_slctd () == TOD) && (todo_hilt () < todo_nb ()))
{
todo_hilt_increase ();
if (todo_hilt_pos () == win[TOD].h - 4)
todo_first_increase ();
@ -453,16 +468,19 @@ main(int argc, char **argv)
if (conf.auto_save)
io_save_cal (&conf);
if (conf.confirm_quit) {
if (conf.confirm_quit)
{
status_mesg (_(quit_message), choices);
ch = wgetch (win[STA].p);
if (ch == 'y')
exit_calcurse (EXIT_SUCCESS);
else {
else
{
erase_status_bar ();
break;
}
} else
}
else
exit_calcurse (EXIT_SUCCESS);
break;
@ -471,11 +489,13 @@ main(int argc, char **argv)
break;
}
if (do_storage) {
if (do_storage)
{
inday = *day_process_storage (calendar_get_slctd_day (),
day_changed, &inday);
do_storage = !do_storage;
if (day_changed) {
if (day_changed)
{
sav_hilt_app = 0;
day_changed = !day_changed;
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
@ -67,10 +67,12 @@ calendar_date_thread(void *arg)
{
time_t now, tomorrow;
for (;;) {
for (;;)
{
tomorrow = (time_t) (get_today () + DAYINSEC);
while ((now = time(NULL)) < tomorrow) {
while ((now = time (NULL)) < tomorrow)
{
sleep (tomorrow - now);
}
@ -118,7 +120,8 @@ calendar_set_current_date(void)
void
calendar_set_first_day_of_week (wday_e first_day)
{
switch (first_day) {
switch (first_day)
{
case SUNDAY:
week_begins_on_monday = false;
break;
@ -242,20 +245,19 @@ calendar_update_panel(WINDOW *cwin)
* the first calendar day will be monday or sunday, depending on
* 'week_begins_on_monday' value
*/
c_day_1 =
(int)((ymd_to_scalar(yr, mo, 1 + sunday_first) - (long)1) % 7L);
c_day_1 = (int) ((ymd_to_scalar (yr, mo, 1 + sunday_first) - (long) 1) % 7L);
/* Write the current month and year on top of the calendar */
custom_apply_attr (cwin, ATTR_HIGH);
mvwprintw(cwin, ofs_y,
(CALWIDTH - (strlen(_(monthnames[mo - 1])) + 5)) / 2,
mvwprintw (cwin, ofs_y, (CALWIDTH - (strlen (_(monthnames[mo - 1])) + 5)) / 2,
"%s %d", _(monthnames[mo - 1]), slctd_day.yyyy);
custom_remove_attr (cwin, ATTR_HIGH);
++ofs_y;
/* print the days, with regards to the first day of the week */
custom_apply_attr (cwin, ATTR_HIGH);
for (j = 0; j < 7; j++) {
for (j = 0; j < 7; j++)
{
mvwprintw (cwin, ofs_y, ofs_x + 4 * j, "%s",
_(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;
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.mm = slctd_day.mm;
check_day.yyyy = slctd_day.yyyy;
/* check if the day contains an event or an appointment */
item_this_day =
day_check_if_item(check_day);
item_this_day = day_check_if_item (check_day);
/* 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_x = 2 - day_1_sav - 4 * c_day - 1;
}
/* This is today, so print it in yellow. */
if (c_day == current_day.dd && current_day.mm == slctd_day.mm
&& current_day.yyyy == slctd_day.yyyy &&
current_day.dd != slctd_day.dd) {
&& current_day.yyyy == slctd_day.yyyy
&& current_day.dd != slctd_day.dd)
{
custom_apply_attr (cwin, ATTR_LOWEST);
mvwprintw (cwin, ofs_y + 1,
ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day);
custom_remove_attr (cwin, ATTR_LOWEST);
} else if (c_day == slctd_day.dd &&
( (current_day.dd != slctd_day.dd) ||
(current_day.mm != slctd_day.mm)
|| (current_day.yyyy != slctd_day.yyyy))) {
}
else if (c_day == slctd_day.dd &&
((current_day.dd != slctd_day.dd)
|| (current_day.mm != slctd_day.mm)
|| (current_day.yyyy != slctd_day.yyyy)))
{
/* This is the selected day, print it in red. */
custom_apply_attr (cwin, ATTR_MIDDLE);
mvwprintw(cwin, ofs_y + 1,
ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day);
mvwprintw (cwin, ofs_y + 1, ofs_x + day_1_sav + 4 * c_day + 1, "%2d",
c_day);
custom_remove_attr (cwin, ATTR_MIDDLE);
} else if (c_day == slctd_day.dd &&
current_day.dd == slctd_day.dd &&
current_day.mm == slctd_day.mm &&
current_day.yyyy == slctd_day.yyyy) {
}
else if (c_day == slctd_day.dd && current_day.dd == slctd_day.dd
&& current_day.mm == slctd_day.mm
&& current_day.yyyy == slctd_day.yyyy)
{
/* today is the selected day */
custom_apply_attr (cwin, ATTR_MIDDLE);
mvwprintw(cwin, ofs_y + 1,
ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day);
mvwprintw (cwin, ofs_y + 1, ofs_x + day_1_sav + 4 * c_day + 1, "%2d",
c_day);
custom_remove_attr (cwin, ATTR_MIDDLE);
} else if (item_this_day) {
}
else if (item_this_day)
{
custom_apply_attr (cwin, ATTR_LOW);
mvwprintw(cwin, ofs_y + 1,
ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day);
mvwprintw (cwin, ofs_y + 1, ofs_x + day_1_sav + 4 * c_day + 1, "%2d",
c_day);
custom_remove_attr (cwin, ATTR_LOW);
} else
}
else
/* otherwise, print normal days in black */
mvwprintw(cwin, ofs_y + 1,
ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day);
mvwprintw (cwin, ofs_y + 1, ofs_x + day_1_sav + 4 * c_day + 1, "%2d",
c_day);
}
wnoutrefresh (cwin);
}
@ -341,44 +344,42 @@ calendar_change_day(int datefmt)
int dday, dmonth, dyear;
int wrong_day = 1;
char *mesg_line1 =
_("The day you entered is not valid (should be between 01/01/1902 and 12/31/2037)");
_("The day you entered is not valid "
"(should be between 01/01/1902 and 12/31/2037)");
char *mesg_line2 = _("Press [ENTER] to continue");
char *request_date =
"Enter the day to go to [ENTER for today] : %s";
char *request_date = "Enter the day to go to [ENTER for today] : %s";
while (wrong_day) {
snprintf(outstr, BUFSIZ, request_date,
DATEFMT_DESC(datefmt));
while (wrong_day)
{
snprintf (outstr, BUFSIZ, request_date, DATEFMT_DESC (datefmt));
status_mesg (_(outstr), "");
if (getstring(win[STA].p, selected_day, LDAY, 0, 1) ==
GETSTRING_ESC)
if (getstring (win[STA].p, selected_day, LDAY, 0, 1) == GETSTRING_ESC)
return;
else {
if (strlen(selected_day) == 0) {
else
{
if (strlen (selected_day) == 0)
{
calendar_store_current_date (&today);
/* go to today */
wrong_day = 0;
slctd_day.dd = today.dd;
slctd_day.mm = today.mm;
slctd_day.yyyy = today.yyyy;
} else if (strlen(selected_day) != LDAY - 1) {
}
else if (strlen (selected_day) != LDAY - 1)
{
wrong_day = 1;
} else if (parse_date(selected_day, datefmt,
&dyear, &dmonth, &dday)) {
}
else if (parse_date (selected_day, datefmt, &dyear, &dmonth, &dday))
{
wrong_day = 0;
/* go to chosen day */
slctd_day.dd = dday;
slctd_day.mm = dmonth;
slctd_day.yyyy = dyear;
}
if (wrong_day) {
if (wrong_day)
{
status_mesg (mesg_line1, mesg_line2);
wgetch (win[STA].p);
}
@ -403,7 +404,8 @@ date_change(struct tm *date, int delta_month, int delta_day)
if (mktime (&t) == -1)
return (1);
else {
else
{
*date = t;
return (0);
}
@ -420,10 +422,11 @@ calendar_move(move_t move)
t.tm_mon = slctd_day.mm - 1;
t.tm_year = slctd_day.yyyy - 1900;
switch (move) {
switch (move)
{
case UP:
if ((slctd_day.dd <= 7) && (slctd_day.mm == 1) &&
(slctd_day.yyyy == 1902))
if ((slctd_day.dd <= 7) && (slctd_day.mm == 1)
&& (slctd_day.yyyy == 1902))
return;
ret = date_change (&t, 0, -WEEKINDAYS);
break;
@ -434,14 +437,14 @@ calendar_move(move_t move)
ret = date_change (&t, 0, WEEKINDAYS);
break;
case LEFT:
if ((slctd_day.dd == 1) && (slctd_day.mm == 1) &&
(slctd_day.yyyy == 1902))
if ((slctd_day.dd == 1) && (slctd_day.mm == 1)
&& (slctd_day.yyyy == 1902))
return;
ret = date_change (&t, 0, -1);
break;
case RIGHT:
if ((slctd_day.dd == 31) && (slctd_day.mm == 12) &&
(slctd_day.yyyy == 2037))
if ((slctd_day.dd == 31) && (slctd_day.mm == 12)
&& (slctd_day.yyyy == 2037))
return;
ret = date_change (&t, 0, 1);
break;
@ -449,8 +452,8 @@ calendar_move(move_t move)
ret = 1;
/* NOTREACHED */
}
if (ret == 0) {
if (ret == 0)
{
slctd_day.dd = t.tm_mday;
slctd_day.mm = t.tm_mon + 1;
slctd_day.yyyy = t.tm_year + 1900;
@ -577,8 +580,8 @@ pom(time_t tmpt)
pom = NO_POM;
GMT = gmtime (&tmpt);
days = (GMT->tm_yday + 1) + ((GMT->tm_hour +
(GMT->tm_min / 60.0) + (GMT->tm_sec / 3600.0)) / 24.0);
days = (GMT->tm_yday + 1) + ((GMT->tm_hour + (GMT->tm_min / 60.0) +
(GMT->tm_sec / 3600.0)) / 24.0);
for (cnt = EPOCH; cnt < GMT->tm_year; ++cnt)
days += isleap (cnt + TM_YEAR_BASE) ? 366 : 365;
/* Selected time could be before EPOCH */
@ -609,10 +612,9 @@ calendar_get_pom(time_t date)
phase = FULL_MOON;
else if (pom_today < pom_yesterday && pom_today < pom_tomorrow)
phase = NEW_MOON;
else if (relative_pom < abs(pom_yesterday - half) &&
relative_pom < abs(pom_tomorrow - half))
phase = (pom_tomorrow > pom_today) ?
FIRST_QUARTER : LAST_QUARTER;
else if (relative_pom < abs (pom_yesterday - half)
&& relative_pom < abs (pom_tomorrow - half))
phase = (pom_tomorrow > pom_today) ? FIRST_QUARTER : LAST_QUARTER;
return (pom_pict[phase]);
}

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
@ -34,7 +34,8 @@
#define CALHEIGHT 12
#define CALWIDTH 30
typedef enum { /* days of week */
typedef enum
{ /* days of week */
SUNDAY,
MONDAY,
TUESDAY,
@ -43,30 +44,37 @@ typedef enum { /* days of week */
FRIDAY,
SATURDAY,
WDAYS
} wday_e;
}
wday_e;
typedef struct {
typedef struct
{
unsigned dd;
unsigned mm;
unsigned yyyy;
} date_t;
}
date_t;
typedef enum {
typedef enum
{
NO_POM,
FIRST_QUARTER,
FULL_MOON,
LAST_QUARTER,
NEW_MOON,
MOON_PHASES
} pom_e;
}
pom_e;
typedef enum {
typedef enum
{
UP,
DOWN,
LEFT,
RIGHT,
MOVES
} move_t;
}
move_t;
void calendar_start_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);
long calendar_get_slctd_day_sec (void);
void calendar_update_panel (WINDOW *);
void calendar_change_day(int datefmt);
void calendar_change_day (int);
void calendar_move (move_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
@ -42,7 +42,8 @@ fill_config_var(char *string)
return (true);
else if (strncmp (string, "no", 2) == 0)
return (false);
else {
else
{
fputs (_("FATAL ERROR in fill_config_var: "
"wrong configuration variable format.\n"), stderr);
return (EXIT_FAILURE);
@ -72,16 +73,19 @@ custom_load_color(char *color, int background)
len = strlen (color);
if (len > 1) {
if (len > 1)
{
/* 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: "
"missing colors in config file.\n"), stderr);
exit (EXIT_FAILURE);
/* NOTREACHED */
};
for (i = 0; i < AWAITED_COLORS; i++) {
for (i = 0; i < AWAITED_COLORS; i++)
{
if (!strncmp (c[i], "black", 5))
colr[i] = COLOR_BLACK;
else if (!strncmp (c[i], "red", 3))
@ -100,20 +104,22 @@ custom_load_color(char *color, int background)
colr[i] = COLOR_WHITE;
else if (!strncmp (c[i], "default", 7))
colr[i] = background;
else {
else
{
fputs (wrong_color_name, stderr);
exit (EXIT_FAILURE);
/* NOTREACHED */
}
}
init_pair (COLR_CUSTOM, colr[0], colr[1]);
} else if (len > 0 && len < 2) {
}
else if (len > 0 && len < 2)
{
/* Old version configuration */
color_num = atoi (color);
switch (color_num) {
switch (color_num)
{
case 0:
colorize = false;
break;
@ -146,8 +152,9 @@ custom_load_color(char *color, int background)
exit (EXIT_FAILURE);
/* NOTREACHED */
}
} else {
}
else
{
fputs (wrong_variable_format, stderr);
exit (EXIT_FAILURE);
/* NOTREACHED */
@ -213,7 +220,8 @@ custom_load_conf(conf_t *conf, int background)
int var;
data_file = fopen (path_conf, "r");
if (data_file == NULL) {
if (data_file == NULL)
{
status_mesg (mesg_line1, mesg_line2);
wnoutrefresh (win[STA].p);
doupdate ();
@ -221,13 +229,16 @@ custom_load_conf(conf_t *conf, int background)
}
var = 0;
pthread_mutex_lock (&nbar->mutex);
for (;;) {
if (fgets(buf, 99, data_file) == NULL) {
for (;;)
{
if (fgets (buf, 99, data_file) == NULL)
{
break;
}
io_extract_data (e_conf, buf, strlen (buf));
switch (var) {
switch (var)
{
case CUSTOM_CONF_NOVARIABLE:
break;
case CUSTOM_CONF_AUTOSAVE:
@ -371,8 +382,10 @@ void
layout_config (void)
{
int ch;
char *layout_mesg = _("Pick the desired layout on next screen [press ENTER]");
char *choice_mesg = _("('A'= Appointment panel, 'C'= calendar panel, 'T'= todo panel)");
char *layout_mesg =
_("Pick the desired layout on next screen [press ENTER]");
char *choice_mesg =
_("('A'= Appointment panel, 'C'= calendar panel, 'T'= todo panel)");
char *layout_up_mesg =
_(" AC AT CA TA TC TA CT AT");
char *layout_down_mesg =
@ -383,8 +396,10 @@ layout_config(void)
status_mesg (layout_up_mesg, layout_down_mesg);
wnoutrefresh (win[STA].p);
doupdate ();
while ((ch = wgetch(win[STA].p)) != 'q') {
if ( ch <= '8' && ch >= '1' ) {
while ((ch = wgetch (win[STA].p)) != 'q')
{
if (ch <= '8' && ch >= '1')
{
wins_set_layout (ch - '0');
return;
}
@ -404,12 +419,11 @@ custom_confwin_init(window_t *confwin, char *label)
box (confwin->p, 0, 0);
wins_show (confwin->p, label);
delwin (win[STA].p);
win[STA].p = newwin(win[STA].h, win[STA].w, win[STA].y,
win[STA].x);
win[STA].p = newwin (win[STA].h, win[STA].w, win[STA].y, win[STA].x);
keypad (win[STA].p, TRUE);
if (notify_bar()) {
notify_reinit_bar(win[NOT].h, win[NOT].w,
win[NOT].y, win[NOT].x);
if (notify_bar ())
{
notify_reinit_bar (win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x);
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 XFORE = XSPC;
const unsigned XBACK = 2 * XSPC + BOXSIZ + XOFST + BARSIZ;
enum {YPOS, XPOS, NBPOS};
enum
{ YPOS, XPOS, NBPOS };
unsigned i;
int pos[SIZE][NBPOS];
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
};
for (i = 0; i < NBUSERCOLORS + 1; i++) {
for (i = 0; i < NBUSERCOLORS + 1; i++)
{
pos[i][YPOS] = Y + YSPC * (i + 1);
pos[NBUSERCOLORS + i + 1][YPOS] = Y + YSPC * (i + 1);
pos[i][XPOS] = XFORE;
pos[NBUSERCOLORS + i + 1][XPOS] = XBACK;
}
if (need_reset) {
if (need_reset)
{
if (cwin->p != NULL)
delwin (cwin->p);
snprintf(label, BUFSIZ, _("CalCurse %s | color theme"),
VERSION);
snprintf (label, BUFSIZ, _("CalCurse %s | color theme"), VERSION);
custom_confwin_init (cwin, label);
}
if (colorize) {
if (theme_changed) {
if (colorize)
{
if (theme_changed)
{
pair_content (colr[*mark_fore], &colr_fore, 0L);
if (colr_fore == 255)
colr_fore = -1;
@ -481,32 +499,31 @@ display_color_config(window_t *cwin, int *mark_fore, int *mark_back,
if (colr_back == 255)
colr_back = -1;
init_pair (COLR_CUSTOM, colr_fore, colr_back);
} else {
}
else
{
/* Retrieve the actual color theme. */
pair_content (COLR_CUSTOM, &colr_fore, &colr_back);
if ((colr_fore == DEFAULTCOLOR) ||
(colr_fore == DEFAULTCOLOR_EXT))
if ((colr_fore == DEFAULTCOLOR) || (colr_fore == DEFAULTCOLOR_EXT))
*mark_fore = NBUSERCOLORS;
else
for (i = 0; i < NBUSERCOLORS + 1; i++)
if (colr_fore == colr[i])
*mark_fore = i;
if ((colr_back == DEFAULTCOLOR) ||
(colr_back == DEFAULTCOLOR_EXT))
if ((colr_back == DEFAULTCOLOR) || (colr_back == DEFAULTCOLOR_EXT))
*mark_back = SIZE - 1;
else
for (i = 0; i < NBUSERCOLORS + 1; i++)
if (colr_back ==
colr[NBUSERCOLORS + 1 + i])
*mark_back =
NBUSERCOLORS + 1 + i;
if (colr_back == colr[NBUSERCOLORS + 1 + i])
*mark_back = NBUSERCOLORS + 1 + i;
}
}
/* 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);
wattron (cwin->p, COLOR_PAIR (colr[i]) | A_REVERSE);
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);
custom_remove_attr (cwin->p, ATTR_HIGHEST);
if (colorize) {
if (colorize)
{
mvwaddch (cwin->p, pos[*mark_fore][YPOS],
pos[*mark_fore][XPOS] + 1, MARK);
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,
need_reset, theme_changed);
while ((ch = wgetch(win[STA].p)) != 'q') {
while ((ch = wgetch (win[STA].p)) != 'q')
{
need_reset = 0;
theme_changed = 0;
switch (ch) {
switch (ch)
{
case KEY_RESIZE:
endwin ();
refresh ();
@ -654,28 +674,30 @@ custom_color_theme_name(char *theme_name)
"blue",
"magenta",
"cyan",
"white"};
"white"
};
const char *error_txt =
_("FATAL ERROR in custom_color_theme_name: unknown color\n");
if (!colorize)
snprintf (theme_name, BUFSIZ, "0");
else {
else
{
pair_content (COLR_CUSTOM, &color[0], &color[1]);
for (i = 0; i < NBCOLORS; i++) {
if ((color[i] == DEFAULTCOLOR) ||
(color[i] == DEFAULTCOLOR_EXT))
for (i = 0; i < NBCOLORS; i++)
{
if ((color[i] == DEFAULTCOLOR) || (color[i] == DEFAULTCOLOR_EXT))
color_name[i] = default_color;
else if (color[i] >= 0 && color[i] <= MAXCOLORS)
color_name[i] = name[color[i]];
else {
else
{
fputs (error_txt, stderr);
exit (EXIT_FAILURE);
/* NOTREACHED */
}
}
snprintf(theme_name, BUFSIZ, "%s on %s", color_name[0],
color_name[1]);
snprintf (theme_name, BUFSIZ, "%s on %s", color_name[0], color_name[1]);
}
}
@ -712,25 +734,29 @@ custom_print_general_options(WINDOW *optwin, conf_t *conf)
print_option_incolor (optwin, conf->confirm_delete, y_pos + 6,
x_pos + 4 + strlen (option3));
mvwprintw (optwin, y_pos + 7, x_pos,
_("(if set to YES, confirmation is required before deleting an event)"));
_("(if set to YES, confirmation is required "
"before deleting an event)"));
mvwprintw (optwin, y_pos + 9, x_pos, "[4] %s ", option4);
print_option_incolor (optwin, conf->skip_system_dialogs, y_pos + 9,
x_pos + 4 + strlen (option4));
mvwprintw (optwin, y_pos + 10, x_pos,
_("(if set to YES, messages about loaded and saved data will not be displayed)"));
_("(if set to YES, messages about loaded "
"and saved data will not be displayed)"));
mvwprintw (optwin, y_pos + 12, x_pos, "[5] %s ", option5);
print_option_incolor (optwin, conf->skip_progress_bar, y_pos + 12,
x_pos + 4 + strlen (option5));
mvwprintw (optwin, y_pos + 13, x_pos,
_("(if set to YES, progress bar will not be displayed when saving data)"));
_("(if set to YES, progress bar will not be displayed "
"when saving data)"));
mvwprintw (optwin, y_pos + 15, x_pos, "[6] %s ", option6);
print_option_incolor (optwin, calendar_week_begins_on_monday (), y_pos + 15,
x_pos + 4 + strlen (option6));
mvwprintw (optwin, y_pos + 16, x_pos,
_("(if set to YES, monday is the first day of the week, else it is sunday)"));
_("(if set to YES, monday is the first day of the week, "
"else it is sunday)"));
mvwprintw (optwin, y_pos + 18, x_pos, "[7] %s ", option7);
custom_apply_attr (optwin, ATTR_HIGHEST);
@ -746,7 +772,8 @@ custom_print_general_options(WINDOW *optwin, conf_t *conf)
conf->input_datefmt);
custom_remove_attr (optwin, ATTR_HIGHEST);
mvwprintw (optwin, y_pos + 22, x_pos,
_("(Format to be used when entering a date: 1-mm/dd/yyyy, 2-dd/mm/yyyy, 3-yyyy/mm/dd)"));
_("(Format to be used when entering a date: "
"1-mm/dd/yyyy, 2-dd/mm/yyyy, 3-yyyy/mm/dd)"));
wmove (win[STA].p, 1, 0);
wnoutrefresh (optwin);
@ -758,7 +785,8 @@ void
custom_general_config (conf_t *conf)
{
window_t conf_win;
char *number_str = _("Enter an option number to change its value [Q to quit] ");
char *number_str =
_("Enter an option number to change its value [Q to quit] ");
char *output_datefmt_str =
_("Enter the date format (see 'man 3 strftime' for possible formats) ");
char *input_datefmt_str =
@ -772,8 +800,10 @@ custom_general_config(conf_t *conf)
custom_confwin_init (&conf_win, label);
status_mesg (number_str, "");
custom_print_general_options (conf_win.p, conf);
while ((ch = wgetch(win[STA].p)) != 'q') {
switch (ch) {
while ((ch = wgetch (win[STA].p)) != 'q')
{
switch (ch)
{
case KEY_RESIZE:
endwin ();
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].x);
keypad (win[STA].p, TRUE);
if (notify_bar()) {
notify_reinit_bar(win[NOT].h, win[NOT].w,
win[NOT].y, win[NOT].x);
if (notify_bar ())
{
notify_reinit_bar (win[NOT].h, win[NOT].w, win[NOT].y,
win[NOT].x);
notify_update_bar ();
}
break;
@ -800,29 +831,31 @@ custom_general_config(conf_t *conf)
conf->confirm_delete = !conf->confirm_delete;
break;
case '4':
conf->skip_system_dialogs =
!conf->skip_system_dialogs;
conf->skip_system_dialogs = !conf->skip_system_dialogs;
break;
case '5':
conf->skip_progress_bar =
!conf->skip_progress_bar;
conf->skip_progress_bar = !conf->skip_progress_bar;
break;
case '6':
calendar_change_first_day_of_week ();
break;
case '7':
status_mesg (output_datefmt_str, "");
strncpy(buf, conf->output_datefmt, strlen(conf->output_datefmt) + 1);
if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
strncpy (buf, conf->output_datefmt,
strlen (conf->output_datefmt) + 1);
if (updatestring (win[STA].p, &buf, 0, 1) == 0)
{
strncpy (conf->output_datefmt, buf, strlen (buf) + 1);
}
status_mesg (number_str, "");
break;
case '8':
status_mesg (input_datefmt_str, "");
if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
if (updatestring (win[STA].p, &buf, 0, 1) == 0)
{
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, "");
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
@ -32,7 +32,8 @@
#define NBUSERCOLORS 6
enum { /* Color pairs */
enum
{ /* Color pairs */
COLR_RED = 1,
COLR_GREEN,
COLR_YELLOW,
@ -44,7 +45,8 @@ enum { /* Color pairs */
COLR_CUSTOM
};
enum { /* Configuration variables */
enum
{ /* Configuration variables */
CUSTOM_CONF_NOVARIABLE,
CUSTOM_CONF_AUTOSAVE,
CUSTOM_CONF_CONFIRMQUIT,
@ -64,7 +66,8 @@ enum { /* Configuration variables */
CUSTOM_CONF_VARIABLES
};
struct attribute_s {
struct attribute_s
{
int color[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
@ -45,7 +45,8 @@ day_free_list(void)
{
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;
free (p->mesg);
free (p);
@ -68,15 +69,17 @@ day_add_event(int type, char *mesg, char *note, long day, int id)
o->start = day;
o->evnt_id = id;
i = &day_items_ptr;
for (;;) {
if (*i == 0) {
for (;;)
{
if (*i == 0)
{
o->next = *i;
*i = o;
break;
}
i = &(*i)->next;
}
return o;
return (o);
}
/* 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->evnt_id = 0;
i = &day_items_ptr;
for (;;) {
if (*i == 0) {
insert_item = 1;
} else if ( ((*i)->start > start) &&
((*i)->type > EVNT) ) {
for (;;)
{
if (*i == 0)
{
insert_item = 1;
}
if (insert_item) {
else if (((*i)->start > start) && ((*i)->type > EVNT))
{
insert_item = 1;
}
if (insert_item)
{
o->next = *i;
*i = o;
break;
}
i = &(*i)->next;
}
return o;
return (o);
}
/*
@ -129,15 +136,16 @@ day_store_events(long date)
struct day_item_s *ptr;
int e_nb = 0;
for (j = eventlist; j != 0; j = j->next) {
if (event_inday(j, date)) {
for (j = eventlist; j != 0; j = j->next)
{
if (event_inday (j, date))
{
e_nb++;
ptr = day_add_event(EVNT, j->mesg, j->note, j->day,
j->id);
ptr = day_add_event (EVNT, j->mesg, j->note, j->day, j->id);
}
}
return e_nb;
return (e_nb);
}
/*
@ -154,16 +162,17 @@ day_store_recur_events(long date)
struct day_item_s *ptr;
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,
j->rpt->until, date)) {
j->rpt->until, date))
{
e_nb++;
ptr = day_add_event(RECUR_EVNT, j->mesg, j->note,
j->day, j->id);
ptr = day_add_event (RECUR_EVNT, j->mesg, j->note, j->day, j->id);
}
}
return e_nb;
return (e_nb);
}
/*
@ -181,8 +190,10 @@ day_store_apoints(long date)
int a_nb = 0;
pthread_mutex_lock (&(alist_p->mutex));
for (j = alist_p->root; j != 0; j = j->next) {
if (apoint_inday(j, date)) {
for (j = alist_p->root; j != 0; j = j->next)
{
if (apoint_inday (j, date))
{
a_nb++;
ptr = day_add_apoint (APPT, j->mesg, j->note, j->start,
j->dur, j->state, 0);
@ -190,7 +201,7 @@ day_store_apoints(long date)
}
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;
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,
j->rpt->type, j->rpt->freq, j->rpt->until, date)) ){
j->rpt->type, j->rpt->freq,
j->rpt->until, date)))
{
a_nb++;
ptr = day_add_apoint (RECUR_APPT, j->mesg, j->note,
real_start, j->dur, j->state, n);
@ -220,7 +234,7 @@ day_store_recur_apoints(long date)
}
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_apoints = day_store_apoints (date);
*pnb_apoints = nb_apoints;
pad_length = nb_recur_events + nb_events + 1 +
3*(nb_recur_apoints + nb_apoints);
pad_length = (nb_recur_events + nb_events + 1 +
3 * (nb_recur_apoints + nb_apoints));
*pnb_apoints += nb_recur_apoints;
*pnb_events += nb_recur_events;
return pad_length;
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_items_nb_t *
day_process_storage(date_t *slctd_date, bool day_changed, day_items_nb_t *inday)
day_process_storage (date_t *slctd_date, bool day_changed,
day_items_nb_t *inday)
{
long date;
date_t day;
@ -280,8 +295,7 @@ day_process_storage(date_t *slctd_date, bool day_changed, day_items_nb_t *inday)
delwin (apad->ptrwin);
/* Store the events and appointments (recursive and normal items). */
apad->length = day_store_items(date,
&inday->nb_events, &inday->nb_apoints);
apad->length = day_store_items (date, &inday->nb_events, &inday->nb_apoints);
/* Create the new pad with its new length. */
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);
else
mvwprintw (win, y, x, " * %s -> %s", a_st, a_end);
else
if (i->state & APOINT_NOTIFY)
else if (i->state & APOINT_NOTIFY)
mvwprintw (win, y, x, " -!%s -> %s", a_st, a_end);
else
mvwprintw (win, y, x, " - %s -> %s", a_st, a_end);
@ -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.
*/
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;
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);
if (strlen (msg) < len)
mvwprintw (win, y, x, " %c%c%s", ch_recur, ch_note, msg);
else {
else
{
strncpy (buf, msg, len - 1);
buf[len - 1] = '\0';
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;
/* 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 *)
malloc (sizeof (struct day_saved_item_s));
day_saved_item->mesg = (char *) malloc (sizeof (char));
}
for (p = day_items_ptr; p != 0; p = p->next) {
for (p = day_items_ptr; p != 0; p = p->next)
{
if (p->type == RECUR_EVNT || p->type == RECUR_APPT)
recur = 1;
else
recur = 0;
/* First print the events for current day. */
if (p->type < RECUR_APPT) {
if (p->type < RECUR_APPT)
{
item_number++;
if (item_number - incolor == 0) {
if (item_number - incolor == 0)
{
day_saved_item->type = p->type;
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);
line++;
draw_line = true;
} else {
}
else
{
/* Draw a line between events and appointments. */
if (line > 0 && draw_line){
if (line > 0 && draw_line)
{
wmove (apad->ptrwin, line, 0);
whline (apad->ptrwin, 0, width);
draw_line = false;
}
/* Last print the appointments for current day. */
item_number++;
day_item_s2apoint_s (&a, p);
if (item_number - incolor == 0) {
if (item_number - incolor == 0)
{
day_saved_item->type = p->type;
day_saved_item->mesg = p->mesg;
apoint_sec2str (&a, p->type, date,
@ -434,13 +456,11 @@ day_write_pad(long date, int width, int length, int incolor)
void
day_popup_item (void)
{
char *error =
_("FATAL ERROR in day_popup_item: unknown item type\n");
char *error = _("FATAL ERROR in day_popup_item: unknown item type\n");
if (day_saved_item->type == EVNT || day_saved_item->type == RECUR_EVNT)
item_in_popup (NULL, NULL, day_saved_item->mesg, _("Event :"));
else if (day_saved_item->type == APPT ||
day_saved_item->type == RECUR_APPT)
else if (day_saved_item->type == APPT || day_saved_item->type == RECUR_APPT)
item_in_popup (day_saved_item->start, day_saved_item->end,
day_saved_item->mesg, _("Appointment :"));
else
@ -464,31 +484,32 @@ day_check_if_item(date_t day)
for (re = recur_elist; re != 0; re = re->next)
if (recur_item_inday (re->day, re->exc, re->rpt->type,
re->rpt->freq, re->rpt->until, date))
return 1;
return (1);
pthread_mutex_lock (&(recur_alist_p->mutex));
for (ra = recur_alist_p->root; ra != 0; ra = ra->next)
if (recur_item_inday (ra->start, ra->exc, ra->rpt->type,
ra->rpt->freq, ra->rpt->until, date)) {
pthread_mutex_unlock(
&(recur_alist_p->mutex));
return 1;
ra->rpt->freq, ra->rpt->until, date))
{
pthread_mutex_unlock (&(recur_alist_p->mutex));
return (1);
}
pthread_mutex_unlock (&(recur_alist_p->mutex));
for (e = eventlist; e != 0; e = e->next)
if (event_inday (e, date))
return 1;
return (1);
pthread_mutex_lock (&(alist_p->mutex));
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));
return 1;
return (1);
}
pthread_mutex_unlock (&(alist_p->mutex));
return 0;
return (0);
}
/* Request the user to enter a new time. */
@ -498,17 +519,19 @@ day_edit_time(long time)
char *timestr;
char *msg_time = _("Enter the new time ([hh:mm] or [h:mm]) : ");
char *enter_str = _("Press [Enter] to continue");
char *fmt_msg =
_("You entered an invalid time, should be [h:mm] or [hh:mm]");
char *fmt_msg = _("You entered an invalid time, should be [h:mm] or [hh:mm]");
while (1) {
while (1)
{
status_mesg (msg_time, "");
timestr = date_sec2hour_str (time);
updatestring (win[STA].p, &timestr, 0, 1);
if (check_time(timestr) != 1 || strlen(timestr) == 0) {
if (check_time (timestr) != 1 || strlen (timestr) == 0)
{
status_mesg (fmt_msg, enter_str);
wgetch (win[STA].p);
} else
}
else
return (timestr);
}
}
@ -520,25 +543,29 @@ update_start_time(long *start, long *dur)
unsigned hr, mn;
int valid_date;
char *timestr;
char *msg_wrong_time =
_("Invalid time: start time must be before end time!");
char *msg_wrong_time = _("Invalid time: start time must be before end time!");
char *msg_enter = _("Press [Enter] to continue");
do {
do
{
timestr = day_edit_time (*start);
sscanf (timestr, "%u:%u", &hr, &mn);
free (timestr);
newtime = update_time_in_date (*start, hr, mn);
if (newtime < *start + *dur) {
if (newtime < *start + *dur)
{
*dur -= (newtime - *start);
*start = newtime;
valid_date = 1;
} else {
}
else
{
status_mesg (msg_wrong_time, msg_enter);
wgetch (win[STA].p);
valid_date = 0;
}
} while (valid_date == 0);
}
while (valid_date == 0);
}
static void
@ -552,8 +579,7 @@ update_duration(long *start, long *dur)
sscanf (timestr, "%u:%u", &hr, &mn);
free (timestr);
newtime = update_time_in_date (*start, hr, mn);
*dur = (newtime > *start) ? newtime - *start :
DAYINSEC + newtime - *start;
*dur = (newtime > *start) ? newtime - *start : DAYINSEC + newtime - *start;
}
static void
@ -571,85 +597,104 @@ update_rept(struct rpt_s **rpt, const long start, conf_t *conf)
long newuntil;
char outstr[BUFSIZ];
char *typstr, *freqstr, *timstr;
char *msg_rpt_type =
_("Enter the new repetition type: (D)aily, (W)eekly, "
char *msg_rpt_type = _("Enter the new repetition type: (D)aily, (W)eekly, "
"(M)onthly, (Y)early");
char *msg_rpt_ans = _("[D/W/M/Y] ");
char *msg_wrong_freq = _("The frequence you entered is not valid.");
char *msg_wrong_time =
_("Invalid time: start time must be before end time!");
char *msg_wrong_time = _("Invalid time: start time must be before end time!");
char *msg_wrong_date = _("The entered date is not valid.");
char *msg_fmts = "Possible formats are [%s] or '0' "
"for an endless repetetition";
char *msg_fmts =
"Possible formats are [%s] or '0' for an endless repetetition";
char *msg_enter = _("Press [Enter] to continue");
do {
do
{
status_mesg (msg_rpt_type, msg_rpt_ans);
typstr = (char *) malloc (sizeof (char) * SINGLECHAR);
snprintf (typstr, SINGLECHAR, "%c", recur_def2char ((*rpt)->type));
cancel = updatestring (win[STA].p, &typstr, 0, 1);
if (cancel) {
if (cancel)
{
free (typstr);
return;
} else {
}
else
{
ch = toupper (*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:"), "");
freqstr = (char *) malloc (BUFSIZ);
snprintf (freqstr, BUFSIZ, "%d", (*rpt)->freq);
cancel = updatestring (win[STA].p, &freqstr, 0, 1);
if (cancel) {
if (cancel)
{
free (freqstr);
return;
} else {
}
else
{
newfreq = atoi (freqstr);
free (freqstr);
if (newfreq == 0) {
if (newfreq == 0)
{
status_mesg (msg_wrong_freq, msg_enter);
wgetch (win[STA].p);
}
}
} while (newfreq == 0);
}
while (newfreq == 0);
do {
do
{
snprintf (outstr, BUFSIZ, "Enter the new ending date: [%s] or '0'",
DATEFMT_DESC (conf->input_datefmt));
status_mesg (_(outstr), "");
timstr = date_sec2date_str((*rpt)->until, DATEFMT(conf->input_datefmt));
timstr =
date_sec2date_str ((*rpt)->until, DATEFMT (conf->input_datefmt));
cancel = updatestring (win[STA].p, &timstr, 0, 1);
if (cancel) {
if (cancel)
{
free (timstr);
return;
}
if (strcmp(timstr, "0") == 0) {
if (strcmp (timstr, "0") == 0)
{
newuntil = 0;
date_entered = 1;
} else {
}
else
{
struct tm *lt;
time_t t;
date_t new_date;
int newmonth, newday, newyear;
if (parse_date (timstr, conf->input_datefmt,
&newyear, &newmonth, &newday)) {
&newyear, &newmonth, &newday))
{
t = start;
lt = localtime (&t);
new_date.dd = newday;
new_date.mm = newmonth;
new_date.yyyy = newyear;
newuntil = date2sec(new_date, lt->tm_hour,
lt->tm_min);
if (newuntil < start) {
newuntil = date2sec (new_date, lt->tm_hour, lt->tm_min);
if (newuntil < start)
{
status_mesg (msg_wrong_time, msg_enter);
wgetch (win[STA].p);
date_entered = 0;
} else
}
else
date_entered = 1;
} else {
}
else
{
snprintf (outstr, BUFSIZ, msg_fmts,
DATEFMT_DESC (conf->input_datefmt));
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;
}
}
} while (date_entered == 0);
}
while (date_entered == 0);
free (timstr);
(*rpt)->type = recur_char2def (ch);
@ -687,15 +733,15 @@ day_edit_item(conf_t *conf)
date = calendar_get_slctd_day_sec ();
ch = 0;
switch (p->type) {
switch (p->type)
{
case RECUR_EVNT:
re = recur_get_event(date,
day_item_nb(date, item_num, RECUR_EVNT));
status_mesg(_("Edit: (1)Description or (2)Repetition?"),
"[1/2] ");
re = recur_get_event (date, day_item_nb (date, item_num, RECUR_EVNT));
status_mesg (_("Edit: (1)Description or (2)Repetition?"), "[1/2] ");
while (ch != '1' && ch != '2' && ch != ESCAPE)
ch = wgetch (win[STA].p);
switch (ch) {
switch (ch)
{
case '1':
update_desc (&re->mesg);
break;
@ -711,14 +757,14 @@ day_edit_item(conf_t *conf)
update_desc (&e->mesg);
break;
case RECUR_APPT:
ra = recur_get_apoint(date,
day_item_nb(date, item_num, RECUR_APPT));
ra = recur_get_apoint (date, day_item_nb (date, item_num, RECUR_APPT));
status_mesg (_("Edit: (1)Start time, (2)End time, "
"(3)Description or (4)Repetition?"), "[1/2/3/4] ");
while (ch != STRT && ch != END && ch != DESC &&
ch != REPT && ch != ESCAPE)
ch = wgetch (win[STA].p);
switch (ch) {
switch (ch)
{
case STRT:
update_start_time (&ra->start, &ra->dur);
break;
@ -741,7 +787,8 @@ day_edit_item(conf_t *conf)
"or (3)Description?"), "[1/2/3] ");
while (ch != STRT && ch != END && ch != DESC && ch != ESCAPE)
ch = wgetch (win[STA].p);
switch (ch) {
switch (ch)
{
case STRT:
update_start_time (&a->start, &a->dur);
break;
@ -780,11 +827,13 @@ day_erase_item(long date, int item_number, erase_flag_e flag)
unsigned delete_whole;
p = day_get_item (item_number);
if (flag == ERASE_DONT_FORCE) {
if (flag == ERASE_DONT_FORCE)
{
ans = 0;
if (p->note == NULL)
ans = 'i';
while (ans != 'i' && ans != 'n') {
while (ans != 'i' && ans != 'n')
{
status_mesg (note_warning, note_choice);
ans = wgetch (win[STA].p);
}
@ -793,49 +842,61 @@ day_erase_item(long date, int item_number, erase_flag_e flag)
else
flag = ERASE_FORCE_ONLY_NOTE;
}
if (p->type == EVNT) {
event_delete_bynum(date, day_item_nb(date, item_number, EVNT),
flag);
} else if (p->type == APPT) {
apoint_delete_bynum(date, day_item_nb(date, item_number, APPT),
flag);
} else {
if (p->type == EVNT)
{
event_delete_bynum (date, day_item_nb (date, item_number, EVNT), flag);
}
else if (p->type == APPT)
{
apoint_delete_bynum (date, day_item_nb (date, item_number, APPT), flag);
}
else
{
if (flag == ERASE_FORCE_ONLY_NOTE)
ch = 'a';
while ( (ch != 'a') && (ch != 'o') && (ch != ESCAPE)) {
while ((ch != 'a') && (ch != 'o') && (ch != ESCAPE))
{
status_mesg (erase_warning, erase_choice);
ch = wgetch (win[STA].p);
}
if (ch == 'a') {
if (ch == 'a')
{
delete_whole = 1;
} else if (ch == 'o') {
delete_whole = 0;
} else {
return 0;
}
if (p->type == RECUR_EVNT) {
recur_event_erase(date,
day_item_nb(date, item_number, RECUR_EVNT),
else if (ch == 'o')
{
delete_whole = 0;
}
else
{
return (0);
}
if (p->type == RECUR_EVNT)
{
recur_event_erase (date, day_item_nb (date, item_number, RECUR_EVNT),
delete_whole, flag);
} else {
recur_apoint_erase(date, p->appt_pos, delete_whole,
flag);
}
else
{
recur_apoint_erase (date, p->appt_pos, delete_whole, flag);
}
}
return (p->type);
}
/* Returns a structure containing the selected item. */
struct day_item_s *day_get_item(int item_number)
struct day_item_s *
day_get_item (int item_number)
{
struct day_item_s *o;
int i;
o = day_items_ptr;
for (i = 1; i < item_number; i++) {
for (i = 1; i < item_number; i++)
{
o = o->next;
}
return o;
return (o);
}
/* 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;
for (i = 1; i < day_num; i++) {
for (i = 1; i < day_num; i++)
{
nb_item[p->type - 1]++;
p = p->next;
}
@ -874,7 +936,8 @@ day_edit_note(char *editor)
item_num = apoint_hilt ();
p = day_get_item (item_num);
if (p->note == NULL) {
if (p->note == NULL)
{
if ((filename = new_tempfile (path_notes, NOTESIZ)) == NULL)
return;
else
@ -884,10 +947,10 @@ day_edit_note(char *editor)
wins_launch_external (fullname, editor);
date = calendar_get_slctd_day_sec ();
switch (p->type) {
switch (p->type)
{
case RECUR_EVNT:
re = recur_get_event(date,
day_item_nb(date, item_num, RECUR_EVNT));
re = recur_get_event (date, day_item_nb (date, item_num, RECUR_EVNT));
re->note = p->note;
break;
case EVNT:
@ -895,8 +958,7 @@ day_edit_note(char *editor)
e->note = p->note;
break;
case RECUR_APPT:
ra = recur_get_apoint(date,
day_item_nb(date, item_num, RECUR_APPT));
ra = recur_get_apoint (date, day_item_nb (date, item_num, RECUR_APPT));
ra->note = p->note;
break;
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
@ -38,12 +38,15 @@
#define RECUR_APPT 3
#define APPT 4
typedef struct {
typedef struct
{
unsigned nb_events;
unsigned nb_apoints;
} day_items_nb_t;
}
day_items_nb_t;
struct day_item_s {
struct day_item_s
{
struct day_item_s *next;
long start; /* seconds since 1 jan 1970 */
long appt_dur; /* appointment duration in seconds */
@ -55,7 +58,8 @@ struct day_item_s {
char *note; /* note attached to item */
};
struct day_saved_item_s {
struct day_saved_item_s
{
char start[BUFSIZ];
char end[BUFSIZ];
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
@ -47,25 +47,28 @@ event_new(char *mesg, char *note, long day, int id)
o->id = id;
o->note = (note != NULL) ? strdup (note) : NULL;
i = &eventlist;
for (;;) {
if (*i == 0 || (*i)->day > day) {
for (;;)
{
if (*i == 0 || (*i)->day > day)
{
o->next = *i;
*i = o;
break;
}
i = &(*i)->next;
}
return o;
return (o);
}
/* Check if the event belongs to the selected day */
unsigned
event_inday (struct event_s *i, long start)
{
if (i->day <= start + DAYINSEC && i->day > start) {
return 1;
if (i->day <= start + DAYINSEC && i->day > start)
{
return (1);
}
return 0;
return (0);
}
/* Write to file the event in user-friendly format */
@ -77,8 +80,8 @@ event_write(struct event_s *o, FILE * f)
t = o->day;
lt = localtime (&t);
fprintf(f, "%02u/%02u/%04u [%d] ",
lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year, o->id);
fprintf (f, "%02u/%02u/%04u [%d] ", lt->tm_mon + 1, lt->tm_mday,
1900 + lt->tm_year, o->id);
if (o->note != NULL)
fprintf (f, ">%s ", o->note);
fprintf (f, "%s\n", o->mesg);
@ -98,7 +101,8 @@ event_scan(FILE * f, struct tm start, int id, char *note)
/* Read the event description */
fgets (buf, MESG_MAXSIZE, f);
nl = strchr (buf, '\n');
if (nl) {
if (nl)
{
*nl = '\0';
}
start.tm_hour = 12;
@ -109,8 +113,10 @@ event_scan(FILE * f, struct tm start, int id, char *note)
start.tm_mon--;
tstart = mktime (&start);
if (tstart == -1) {
fputs(_("FATAL ERROR in event_scan: date error in the event\n"), stderr);
if (tstart == -1)
{
fputs (_("FATAL ERROR in event_scan: date error in the event\n"),
stderr);
exit (EXIT_FAILURE);
}
return (event_new (buf, note, tstart, id));
@ -124,8 +130,10 @@ event_get(long day, int pos)
int n;
n = 0;
for (o = eventlist; o; o = o->next) {
if (event_inday(o, day)) {
for (o = eventlist; o; o = o->next)
{
if (event_inday (o, day))
{
if (n == pos)
return o;
n++;
@ -145,12 +153,16 @@ event_delete_bynum(long start, unsigned num, erase_flag_e flag)
n = 0;
iptr = &eventlist;
for (i = eventlist; i != 0; i = i->next) {
if (event_inday(i, start)) {
if (n == num) {
for (i = eventlist; i != 0; i = i->next)
{
if (event_inday (i, start))
{
if (n == num)
{
if (flag == ERASE_FORCE_ONLY_NOTE)
erase_note (&i->note, flag);
else {
else
{
*iptr = i->next;
free (i->mesg);
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
@ -32,7 +32,8 @@
#define HRMIN_SIZE 6
#define MESG_MAXSIZE 256
struct event_s {
struct event_s
{
struct event_s *next;
int id; /* event identifier */
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
* Copyright (c) 2004-2007 Frederic Culot
* Copyright (c) 2004-2008 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -35,7 +35,8 @@
#include "utils.h"
#include "notify.h"
typedef enum {
typedef enum
{
HELP_MAIN,
HELP_SAVE,
HELP_EXPORT,
@ -57,7 +58,8 @@ typedef enum {
HELP_CREDITS,
HELPSCREENS,
NOPAGE
} help_pages_e;
}
help_pages_e;
/* Returns the number of lines in an help text. */
static int
@ -66,10 +68,12 @@ get_help_lines(char *text)
int i;
int nl = 0;
for (i = 0; text[i]; i++) {
if (text[i] == '\n') nl++;
for (i = 0; text[i]; i++)
{
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);
keypad (win[STA].p, TRUE);
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);
status_bar ();
if (notify_bar ())
notify_update_bar ();
@ -148,7 +151,8 @@ wanted_page(int ch)
{
int page;
switch (ch) {
switch (ch)
{
case '?':
page = HELP_MAIN;
@ -318,8 +322,9 @@ help_screen(void)
hscr[HELP_VIEW].text =
_("Pressing 'V' allows you to view the item you select in either the ToDo\n"
"or Appointment panel.\n"
"\nThis is usefull when an event description is longer than the available\n"
"space to display it. If that is the case, the description will be\n"
"\nThis is usefull when an event description is longer than the "
"available\n space to display it. "
"If that is the case, the description will be\n"
"shortened and its end replaced by '...'. To be able to read the entire\n"
"description, just press 'V' and a popup window will appear, containing\n"
"the whole event.\n"
@ -331,8 +336,8 @@ help_screen(void)
_("Pressing 'Tab' allows you to switch between panels.\n"
"The panel currently in use has its border colorized.\n"
"\nSome actions are possible only if the right panel is selected.\n"
"For example, if you want to add a task in the TODO list, you need first\n"
"to press the 'Tab' key to get the TODO panel selected. Then you can\n"
"For example, if you want to add a task in the TODO list, you need first"
"\nto press the 'Tab' key to get the TODO panel selected. Then you can\n"
"press 'A' to add your item.\n"
"\nNotice that at the bottom of the screen the list of possible actions\n"
"change while pressing 'Tab', so you always know what action can be\n"
@ -355,34 +360,33 @@ help_screen(void)
"\nIf the item to be deleted is recurrent, you will be asked if you\n"
"wish to suppress all of the item occurences or just the one you\n"
"selected.\n"
"\nIf the general option 'confirm_delete' is set to 'YES', then you will\n"
"be asked for confirmation before deleting the selected event.\n"
"\nIf the general option 'confirm_delete' is set to 'YES', then you will"
"\nbe asked for confirmation before deleting the selected event.\n"
"Do not forget to save the calendar data to retrieve the modifications\n"
"next time you launch Calcurse.");
hscr[HELP_ADD].title = _("Add:\n");
hscr[HELP_ADD].text =
_("Pressing 'A' allows you to add an item in either the ToDo or Appointment\n"
"list, depending on which panel is selected when you press 'A'.\n"
"\nTo enter a new item in the TODO list, you will need first to enter the\n"
"description of this new item. Then you will be asked to specify the todo\n"
"priority. This priority is represented by a number going from 9 for the\n"
"lowest priority, to 1 for the highest one. It is still possible to\n"
"change the item priority afterwards, by using the '+/-' keys inside the\n"
"todo panel.\n"
_("Pressing 'A' allows you to add an item in either the ToDo or Appointment"
"\nlist, depending on which panel is selected when you press 'A'.\n"
"\nTo enter a new item in the TODO list, you will need first to enter the"
"\ndescription of this new item. Then you will be asked to specify the "
"todo\npriority. This priority is represented by a number going from 9 "
"for the\nlowest priority, to 1 for the highest one. It is still "
"possible to\nchange the item priority afterwards, by using the '+/-' "
"keys inside the\ntodo panel.\n"
"\nIf the APPOINTMENT panel is selected while pressing 'A', you will be\n"
"able to enter either a new appointment or a new all-day long event.\n"
"To enter a new event, press [ENTER] instead of the item start time, and\n"
"just fill in the event description.\n"
"To enter a new event, press [ENTER] instead of the item start time, "
"and\njust fill in the event description.\n"
"To enter a new appointment to be added in the APPOINTMENT list, you\n"
"will need to enter successively the time at which the appointment\n"
"begins, the appointment length (either by specifying the duration in\n"
"minutes, or the end time in [hh:mm] or [h:mm] format), and the\n"
"description of the event.\n"
"\nThe day at which occurs the event or appointment is the day currently\n"
"selected in the calendar, so you need to move to the desired day before\n"
"pressing 'A'.\n"
"\nNotes:\n"
"\nThe day at which occurs the event or appointment is the day currently"
"\nselected in the calendar, so you need to move to the desired day "
"before\npressing 'A'.\n" "\nNotes:\n"
" o if an appointment lasts for such a long time that it continues\n"
" on the next days, this event will be indicated on all the\n"
" corresponding days, and the beginning or ending hour will be\n"
@ -397,11 +401,11 @@ help_screen(void)
hscr[HELP_EDIT].text =
_("Pressing 'E' allows you to edit the item which is currently selected.\n"
"Depending on the item type (appointment, event, or todo), and if it is\n"
"repeated or not, you will be asked to choose one of the item properties\n"
"to modify. An item property is one of the following: the start time, the\n"
"end time, the description, or the item repetition.\n"
"Once you have chosen the property you want to modify, you will be shown\n"
"its actual value, and you will be able to change it as you like.\n"
"repeated or not, you will be asked to choose one of the item properties"
"\nto modify. An item property is one of the following: the start time, "
"the\nend time, the description, or the item repetition.\n"
"Once you have chosen the property you want to modify, you will be shown"
"\nits actual value, and you will be able to change it as you like.\n"
"\nNotes:\n"
" o if you choose to edit the item repetition properties, you will\n"
" be asked to re-enter all of the repetition characteristics\n"
@ -428,8 +432,8 @@ help_screen(void)
" o if none of the above environment variables is set, then\n"
" '/usr/bin/vi' will be used.\n"
"\nOnce the item note is edited and saved, quit your favorite editor.\n"
"You will then go back to Calcurse, and the '>' sign will appear in front\n"
"of the highlighted item, meaning there is a note attached to it.");
"You will then go back to Calcurse, and the '>' sign will appear in front"
"\nof the highlighted item, meaning there is a note attached to it.");
hscr[HELP_VNOTE].title = _("ViewNote:\n");
hscr[HELP_VNOTE].text =
@ -437,8 +441,9 @@ help_screen(void)
"attached to an item (an item which owns a note has a '>' sign in front\n"
"of it). This command only permits to view the note, not to\n"
"edit it (to do so, use the 'EditNote' command, using the 'N' key).\n"
"Once you highlighted an item with a note attached to it, and the 'N' key\n"
"was pressed, you will be driven to an external pager to view that note.\n"
"Once you highlighted an item with a note attached to it, and the 'N' key"
"\nwas pressed, you will be driven to an external pager to view that "
"note.\n"
"The default pager is chosen the following way:\n"
" o if the 'PAGER' environment variable is set, then this will be\n"
" the default viewer to be called.\n"
@ -450,22 +455,25 @@ help_screen(void)
hscr[HELP_PRIORITY].title = _("Priority:\n");
hscr[HELP_PRIORITY].text =
_("Pressing '+' or '-' allows you to change the priority of the currently\n"
"selected item in the ToDo list. Priorities are represented by the number\n"
"appearing in front of the todo description. This number goes from 9 for\n"
"the lowest priority to 1 for the highest priority. Todo having higher\n"
"priorities are placed first (at the top) inside the todo panel.\n\n"
"If you want to raise the priority of a todo item, you need to press '+'.\n"
"In doing so, the number in front of this item will decrease, meaning its\n"
"priority increases. The item position inside the todo panel may change,\n"
"depending on the priority of the items above it.\n\n"
"At the opposite, to lower a todo priority, press '-'. The todo position\n"
"may also change depending on the priority of the items below.");
"selected item in the ToDo list. Priorities are represented by the "
"number\nappearing in front of the todo description. This number goes "
"from 9 for\nthe lowest priority to 1 for the highest priority. "
"Todo having higher\npriorities are placed first (at the top) inside the "
"todo panel.\n\n"
"If you want to raise the priority of a todo item, you need to press "
"'+'.\n"
"In doing so, the number in front of this item will decrease, "
"meaning its\npriority increases. The item position inside the todo "
"panel may change,\ndepending on the priority of the items above it.\n\n"
"At the opposite, to lower a todo priority, press '-'. The todo position"
"\nmay also change depending on the priority of the items below.");
hscr[HELP_REPEAT].title = _("Repeat:\n");
hscr[HELP_REPEAT].text =
_("Pressing 'R' allows you to repeat an event or an appointment. You must\n"
"first select the item to be repeated by moving inside the appointment\n"
"panel. Then pressing 'R' will lead you to a set of three questions, with\n"
"panel. "
"Then pressing 'R' will lead you to a set of three questions, with\n"
"which you will be able to specify the repetition characteristics:\n\n"
" o type: you can choose between a daily, weekly, monthly or\n"
" yearly repetition by pressing 'D', 'W', 'M' or 'Y'\n"
@ -479,8 +487,7 @@ help_screen(void)
" o ending date: this specifies when to stop repeating the selected\n"
" event or appointment. To indicate an endless \n"
" repetition, enter '0' and the item will be repeated\n"
" forever.\n"
"\nNotes:\n"
" forever.\n" "\nNotes:\n"
" o repeated items are marked with an '*' inside the appointment\n"
" panel, to be easily recognizable from non-repeated ones.\n"
" o the 'Repeat' and 'Delete' command can be mixed to create\n"
@ -490,25 +497,25 @@ help_screen(void)
hscr[HELP_FLAG].title = _("Flag Item:\n");
hscr[HELP_FLAG].text =
_("Pressing '!' toggles an appointment's 'important' flag.\n\n"
"If an item is flagged as important, an exclamation mark appears in front\n"
"of it, and you will be warned if time gets closed to the appointment\n"
"If an item is flagged as important, an exclamation mark appears in front"
"\nof it, and you will be warned if time gets closed to the appointment\n"
"start time.\n"
"To customize the way one gets notified, the configuration submenu lets\n"
"you choose the command launched to warn user of an upcoming appointment,\n"
"and how long before it he gets notified.");
"you choose the command launched to warn user of an upcoming appointment,"
"\nand how long before it he gets notified.");
hscr[HELP_CONFIG].title = _("Config:\n");
hscr[HELP_CONFIG].text =
_("Pressing 'C' leads to the configuration submenu, from which you can\n"
"select between color, layout, and general options.\n"
"\nThe color submenu lets you choose the color theme.\n"
"\nThe layout submenu lets you choose the Calcurse screen layout, in other\n"
"words where to place the three different panels on the screen.\n"
"\nThe general options submenu brings a screen with the different options\n"
"which modifies the way Calcurse interacts with the user.\n"
"\nThe layout submenu lets you choose the Calcurse screen layout, in other"
"\nwords where to place the three different panels on the screen.\n"
"\nThe general options submenu brings a screen with the different options"
"\nwhich modifies the way Calcurse interacts with the user.\n"
"\nThe notify submenu allows you to change the notify-bar settings.\n"
"\nDo not forget to save the calendar data to retrieve your configuration\n"
"next time you launch Calcurse.");
"\nDo not forget to save the calendar data to retrieve your configuration"
"\nnext time you launch Calcurse.");
hscr[HELP_GENERAL].title = _("General keybindings:\n");
hscr[HELP_GENERAL].text =
@ -539,7 +546,7 @@ help_screen(void)
hscr[HELP_CREDITS].title = _("Calcurse - text-based organizer");
hscr[HELP_CREDITS].text =
_("Copyright (c) 2004-2007 Frederic Culot\n"
_("Copyright (c) 2004-2008 Frederic Culot\n"
"\n"
"This program is free software; you can redistribute it and/or modify\n"
"it under the terms of the GNU General Public License as published by\n"
@ -558,11 +565,12 @@ help_screen(void)
help_wins_init (&hwin, &hpad, PADOFFSET);
/* 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);
switch (ch) {
switch (ch)
{
case KEY_RESIZE:
help_wins_reset (&hwin, &hpad, PADOFFSET);
first_line = 0;
@ -582,7 +590,8 @@ help_screen(void)
default:
page = wanted_page (ch);
if (page != NOPAGE) {
if (page != NOPAGE)
{
first_line = 0;
nl = write_help_pad (&hpad, &hscr[page]);
oldpage = page;
@ -592,7 +601,8 @@ help_screen(void)
/* Draw the scrollbar if necessary. */
text_lines = hwin.h - (PADOFFSET + 1);
if (nl > text_lines) {
if (nl > text_lines)
{
float ratio = ((float) text_lines + 1) / ((float) nl);
int sbar_length = (int) (ratio * text_lines);
int highend = (int) (ratio * first_line);

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
@ -27,10 +27,12 @@
#ifndef CALCURSE_HELP_H
#define CALCURSE_HELP_H
typedef struct {
typedef struct
{
char *title;
char *text;
} help_page_t;
}
help_page_t;
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

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
@ -40,11 +40,13 @@
#include "apoint.h"
#include "io.h"
typedef enum {
typedef enum
{
PROGRESS_BAR_SAVE,
PROGRESS_BAR_LOAD,
PROGRESS_BAR_EXPORT
} progress_bar_t;
}
progress_bar_t;
/* 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[STEPS - 1] = col - 2;
switch (type) {
switch (type)
{
case PROGRESS_BAR_SAVE:
status_mesg (mesg_sav, file[progress]);
break;
@ -120,12 +123,10 @@ io_get_export_stream(void)
{
FILE *stream;
char *home, *stream_name;
char *question =
_("Choose the file used to export calcurse data:");
char *question = _("Choose the file used to export calcurse data:");
char *wrong_name =
_("The file cannot be accessed, please enter another file name.");
char *press_enter =
_("Press [ENTER] to continue.");
char *press_enter = _("Press [ENTER] to continue.");
int cancel;
stream = NULL;
@ -135,15 +136,18 @@ io_get_export_stream(void)
else
snprintf (stream_name, BUFSIZ, "/tmp/calcurse.ics");
while (stream == NULL) {
while (stream == NULL)
{
status_mesg (question, "");
cancel = updatestring (win[STA].p, &stream_name, 0, 1);
if (cancel) {
if (cancel)
{
free (stream_name);
return (NULL);
}
stream = fopen (stream_name, "w");
if (stream == NULL) {
if (stream == NULL)
{
status_mesg (wrong_name, press_enter);
wgetch (win[STA].p);
}
@ -170,8 +174,7 @@ static void
io_export_header (FILE *stream)
{
fprintf (stream, "BEGIN:VCALENDAR\n");
fprintf(stream, "PRODID:-//calcurse//NONSGML v%s//EN\n",
VERSION);
fprintf (stream, "PRODID:-//calcurse//NONSGML v%s//EN\n", VERSION);
fprintf (stream, "VERSION:2.0\n");
}
@ -190,23 +193,28 @@ io_export_recur_events(FILE *stream)
struct days_s *day;
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);
fprintf (stream, "BEGIN:VEVENT\n");
fprintf (stream, "DTSTART:%s\n", ical_date);
fprintf (stream, "RRULE:FREQ=%s;INTERVAL=%d",
io_recur_type (i->rpt->type), i->rpt->freq);
if (i->rpt->until != 0) {
if (i->rpt->until != 0)
{
date_sec2ical_date (i->rpt->until, ical_date);
fprintf (stream, ";UNTIL=%s\n", ical_date);
} else
}
else
fprintf (stream, "\n");
if (i->exc != NULL) {
if (i->exc != NULL)
{
date_sec2ical_date (i->exc->st, ical_date);
fprintf (stream, "EXDATE:%s", ical_date);
for (day = i->exc->next; day; day = day->next) {
for (day = i->exc->next; day; day = day->next)
{
date_sec2ical_date (day->st, ical_date);
fprintf (stream, ",%s", ical_date);
}
@ -225,7 +233,8 @@ io_export_events(FILE *stream)
struct event_s *i;
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);
fprintf (stream, "BEGIN:VEVENT\n");
fprintf (stream, "DTSTART:%s\n", ical_date);
@ -244,7 +253,8 @@ io_export_recur_apoints(FILE *stream)
char ical_date[BUFSIZ];
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);
fprintf (stream, "BEGIN:VEVENT\n");
fprintf (stream, "DTSTART:%s\n", ical_datetime);
@ -252,17 +262,20 @@ io_export_recur_apoints(FILE *stream)
fprintf (stream, "RRULE:FREQ=%s;INTERVAL=%d",
io_recur_type (i->rpt->type), i->rpt->freq);
if (i->rpt->until != 0) {
date_sec2ical_date(i->rpt->until + HOURINSEC,
ical_date);
if (i->rpt->until != 0)
{
date_sec2ical_date (i->rpt->until + HOURINSEC, ical_date);
fprintf (stream, ";UNTIL=%s\n", ical_date);
} else
}
else
fprintf (stream, "\n");
if (i->exc != NULL) {
if (i->exc != NULL)
{
date_sec2ical_date (i->exc->st, ical_date);
fprintf (stream, "EXDATE:%s", ical_date);
for (day = i->exc->next; day; day = day->next) {
for (day = i->exc->next; day; day = day->next)
{
date_sec2ical_date (day->st, ical_date);
fprintf (stream, ",%s", ical_date);
}
@ -285,7 +298,8 @@ io_export_apoints(FILE *stream)
char ical_datetime[BUFSIZ];
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);
fprintf (stream, "BEGIN:VEVENT\n");
fprintf (stream, "DTSTART:%s\n", ical_datetime);
@ -304,7 +318,8 @@ io_export_todo(FILE *stream)
{
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, "PRIORITY:%d\n", i->id);
fprintf (stream, "SUMMARY:%s\n", i->mesg);
@ -327,24 +342,30 @@ io_init(char *cfile)
int ch;
home = getenv ("HOME");
if (home == NULL) {
if (home == NULL)
{
home = ".";
}
snprintf (path_dir, BUFSIZ, "%s/" DIR_NAME, home);
snprintf (path_todo, BUFSIZ, "%s/" TODO_PATH, home);
snprintf (path_conf, BUFSIZ, "%s/" CONF_PATH, home);
snprintf (path_notes, BUFSIZ, "%s/" NOTES_DIR, home);
if (cfile == NULL) {
if (cfile == NULL)
{
snprintf (path_apts, BUFSIZ, "%s/" APTS_PATH, home);
} else {
}
else
{
snprintf (apts_file, BUFSIZ, "%s", cfile);
strncpy (path_apts, apts_file, BUFSIZ);
/* check if the file exists, otherwise create it */
data_file = fopen (path_apts, "r");
if (data_file == NULL) {
if (data_file == NULL)
{
printf (_("%s does not exist, create it now [y or n] ? "), path_apts);
ch = getchar ();
switch (ch) {
switch (ch)
{
case 'N':
case 'n':
printf (_("aborting...\n"));
@ -354,10 +375,13 @@ io_init(char *cfile)
case 'Y':
case 'y':
data_file = fopen (path_apts, "w");
if (data_file == NULL) {
if (data_file == NULL)
{
perror (path_apts);
exit (EXIT_FAILURE);
} else {
}
else
{
printf (_("%s successfully created\n"), path_apts);
printf (_("starting interactive mode...\n"));
}
@ -377,7 +401,8 @@ io_init(char *cfile)
void
io_extract_data (char *dst_data, const char *org, int len)
{
for (;;) {
for (;;)
{
if (*org == '\n' || *org == '\0')
break;
*dst_data++ = *org++;
@ -396,7 +421,15 @@ io_save_cal(conf_t *conf)
char theme_name[BUFSIZ];
char *access_pb = _("Problems accessing data file ...");
char *config_txt =
"#\n# Calcurse configuration file\n#\n# This file sets the configuration options used by Calcurse. These\n# options are usually set from within Calcurse. A line beginning with \n# a space or tab is considered to be a continuation of the previous line.\n# For a variable to be unset its value must be blank.\n# To set a variable to the empty string its value should be \"\".\n# Lines beginning with \"#\" are comments, and ignored by Calcurse.\n";
"#\n"
"# Calcurse configuration file\n#\n"
"# This file sets the configuration options used by Calcurse. These\n"
"# options are usually set from within Calcurse. A line beginning with \n"
"# a space or tab is considered to be a continuation of the previous "
"line.\n"
"# For a variable to be unset its value must be blank.\n"
"# To set a variable to the empty string its value should be \"\".\n"
"# Lines beginning with \"#\" are comments, and ignored by Calcurse.\n";
char *save_success = _("The data files were successfully saved");
char *enter = _("Press [ENTER] to continue");
bool show_bar = false;
@ -411,58 +444,61 @@ io_save_cal(conf_t *conf)
data_file = fopen (path_conf, "w");
if (data_file == (FILE *) 0)
status_mesg (access_pb, "");
else {
else
{
custom_color_theme_name (theme_name);
fprintf (data_file, "%s\n", config_txt);
fprintf (data_file,
"# If this option is set to yes, automatic save is done when quitting\n");
"# If this option is set to yes, "
"automatic save is done when quitting\n");
fprintf (data_file, "auto_save=\n");
fprintf (data_file, "%s\n", (conf->auto_save) ? "yes" : "no");
fprintf (data_file,
"\n# If this option is set to yes, confirmation is required before quitting\n");
"\n# If this option is set to yes, "
"confirmation is required before quitting\n");
fprintf (data_file, "confirm_quit=\n");
fprintf (data_file, "%s\n", (conf->confirm_quit) ? "yes" : "no");
fprintf (data_file,
"\n# If this option is set to yes, confirmation is required before deleting an event\n");
"\n# If this option is set to yes, "
"confirmation is required before deleting an event\n");
fprintf (data_file, "confirm_delete=\n");
fprintf(data_file, "%s\n",
(conf->confirm_delete) ? "yes" : "no");
fprintf (data_file, "%s\n", (conf->confirm_delete) ? "yes" : "no");
fprintf (data_file,
"\n# If this option is set to yes, messages about loaded and saved data will not be displayed\n");
"\n# If this option is set to yes, "
"messages about loaded and saved data will not be displayed\n");
fprintf (data_file, "skip_system_dialogs=\n");
fprintf(data_file, "%s\n",
(conf->skip_system_dialogs) ? "yes" : "no");
fprintf (data_file, "%s\n", (conf->skip_system_dialogs) ? "yes" : "no");
fprintf (data_file,
"\n# If this option is set to yes, progress bar appearing when saving data will not be displayed\n");
"\n# If this option is set to yes, progress bar appearing "
"when saving data will not be displayed\n");
fprintf (data_file, "skip_progress_bar=\n");
fprintf(data_file, "%s\n",
(conf->skip_progress_bar) ? "yes" : "no");
fprintf (data_file, "%s\n", (conf->skip_progress_bar) ? "yes" : "no");
fprintf (data_file,
"\n# If this option is set to yes, monday is the first day of the week, else it is sunday\n");
"\n# If this option is set to yes, "
"monday is the first day of the week, else it is sunday\n");
fprintf (data_file, "week_begins_on_monday=\n");
fprintf (data_file, "%s\n",
(calendar_week_begins_on_monday ())? "yes" : "no");
fprintf(data_file,
"\n# This is the color theme used for menus :\n");
fprintf (data_file, "\n# This is the color theme used for menus :\n");
fprintf (data_file, "color-theme=\n");
fprintf (data_file, "%s\n", theme_name);
fprintf(data_file,
"\n# This is the layout of the calendar :\n");
fprintf (data_file, "\n# This is the layout of the calendar :\n");
fprintf (data_file, "layout=\n");
fprintf (data_file, "%d\n", wins_layout ());
pthread_mutex_lock (&nbar->mutex);
fprintf (data_file,
"\n# If this option is set to yes, notify-bar will be displayed :\n");
"\n# If this option is set to yes, "
"notify-bar will be displayed :\n");
fprintf (data_file, "notify-bar_show=\n");
fprintf (data_file, "%s\n", (nbar->show) ? "yes" : "no");
@ -477,22 +513,26 @@ io_save_cal(conf_t *conf)
fprintf (data_file, "%s\n", nbar->timefmt);
fprintf (data_file,
"\n# Warn user if he has an appointment within next 'notify-bar_warning' seconds :\n");
"\n# Warn user if he has an appointment within next "
"'notify-bar_warning' seconds :\n");
fprintf (data_file, "notify-bar_warning=\n");
fprintf (data_file, "%d\n", nbar->cntdwn);
fprintf (data_file,
"\n# Command used to notify user of an upcoming appointment :\n");
"\n# Command used to notify user of "
"an upcoming appointment :\n");
fprintf (data_file, "notify-bar_command=\n");
fprintf (data_file, "%s\n", nbar->cmd);
fprintf (data_file,
"\n# Format of the date to be displayed in non-interactive mode :\n");
"\n# Format of the date to be displayed "
"in non-interactive mode :\n");
fprintf (data_file, "output_datefmt=\n");
fprintf (data_file, "%s\n", conf->output_datefmt);
fprintf (data_file,
"\n# Format to be used when entering a date (1-mm/dd/yyyy, 2-dd/mm/yyyy, 3-yyyy/mm/dd) :\n");
"\n# Format to be used when entering a date "
"(1-mm/dd/yyyy, 2-dd/mm/yyyy, 3-yyyy/mm/dd) :\n");
fprintf (data_file, "input_datefmt=\n");
fprintf (data_file, "%d\n", conf->input_datefmt);
@ -507,11 +547,12 @@ io_save_cal(conf_t *conf)
data_file = fopen (path_todo, "w");
if (data_file == (FILE *) 0)
status_mesg (access_pb, "");
else {
for (i = todolist; i != 0; i = i->next) {
else
{
for (i = todolist; i != 0; i = i->next)
{
if (i->note != NULL)
fprintf(data_file, "[%d]>%s %s\n", i->id,
i->note, i->mesg);
fprintf (data_file, "[%d]>%s %s\n", i->id, i->note, i->mesg);
else
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");
if (data_file == (FILE *) 0)
status_mesg (access_pb, "");
else {
else
{
recur_save_data (data_file);
pthread_mutex_lock (&(alist_p->mutex));
@ -541,9 +583,9 @@ io_save_cal(conf_t *conf)
fclose (data_file);
}
/* Print a message telling data were saved */
if (!conf->skip_system_dialogs) {
if (!conf->skip_system_dialogs)
{
status_mesg (save_success, enter);
wgetch (win[STA].p);
}
@ -574,7 +616,8 @@ io_load_app(void)
start = end = until = *lt;
data_file = fopen (path_apts, "r");
for (;;) {
for (;;)
{
is_appointment = is_event = is_recursive = 0;
c = getc (data_file);
if (c == EOF)
@ -585,7 +628,8 @@ io_load_app(void)
* and appointments.
*/
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: "
"syntax error in the item date\n"), stderr);
exit (EXIT_FAILURE);
@ -600,7 +644,8 @@ io_load_app(void)
is_appointment = 1;
else if (c == '[')
is_event = 1;
else {
else
{
fputs (_("FATAL ERROR in io_load_app: "
"no event nor appointment found\n"), stderr);
exit (EXIT_FAILURE);
@ -608,14 +653,19 @@ io_load_app(void)
ungetc (c, data_file);
/* Read the remaining informations. */
if (is_appointment) {
if (is_appointment)
{
fscanf (data_file, "@ %u : %u -> %u / %u / %u @ %u : %u ",
&start.tm_hour, &start.tm_min,
&end.tm_mon, &end.tm_mday, &end.tm_year,
&end.tm_hour, &end.tm_min);
} else if (is_event) {
}
else if (is_event)
{
fscanf (data_file, "[%d] ", &id);
} else { /* NOT REACHED */
}
else
{ /* NOT REACHED */
fputs (error, stderr);
exit (EXIT_FAILURE);
}
@ -623,50 +673,64 @@ io_load_app(void)
/* Check if we have a recursive item. */
c = getc (data_file);
if (c == '{') {
if (c == '{')
{
ungetc (c, data_file);
is_recursive = 1;
fscanf (data_file, "{ %d%c ", &freq, &type);
c = getc (data_file);
if (c == '}') { /* endless recurrent item */
if (c == '}')
{ /* endless recurrent item */
ungetc (c, data_file);
fscanf (data_file, "} ");
until.tm_year = 0;
} else if (c == '-') {
}
else if (c == '-')
{
ungetc (c, data_file);
fscanf (data_file, " -> %u / %u / %u ",
&until.tm_mon, &until.tm_mday,
&until.tm_year);
&until.tm_mon, &until.tm_mday, &until.tm_year);
c = getc (data_file);
if (c == '!') {
if (c == '!')
{
ungetc (c, data_file);
exc = recur_exc_scan (data_file);
c = getc (data_file);
} else {
}
else
{
ungetc (c, data_file);
fscanf (data_file, "} ");
}
} else if (c == '!') { // endless item with exceptions
}
else if (c == '!')
{ // endless item with exceptions
ungetc (c, data_file);
exc = recur_exc_scan (data_file);
c = getc (data_file);
until.tm_year = 0;
} else { /* NOT REACHED */
}
else
{ /* NOT REACHED */
fputs (error, stderr);
exit (EXIT_FAILURE);
}
} else
}
else
ungetc (c, data_file);
/* Check if a note is attached to the item. */
c = getc (data_file);
if (c == '>') {
if (c == '>')
{
fgets (note, NOTESIZ + 1, data_file);
note[NOTESIZ] = '\0';
notep = note;
getc (data_file);
} else {
}
else
{
notep = NULL;
ungetc (c, data_file);
}
@ -675,32 +739,45 @@ io_load_app(void)
* Last: read the item description and load it into its
* corresponding linked list, depending on the item type.
*/
if (is_appointment) {
if (is_appointment)
{
c = getc (data_file);
if (c == '!') {
if (c == '!')
{
ungetc (c, data_file);
fscanf (data_file, " ! ");
state |= APOINT_NOTIFY;
} else {
}
else
{
ungetc (c, data_file);
fscanf (data_file, " | ");
state = 0L;
}
if (is_recursive) {
if (is_recursive)
{
recur_apoint_scan (data_file, start, end,
type, freq, until, notep, exc, state);
} else {
apoint_scan(data_file, start, end, state,
notep);
}
} else if (is_event) {
if (is_recursive) {
else
{
apoint_scan (data_file, start, end, state, notep);
}
}
else if (is_event)
{
if (is_recursive)
{
recur_event_scan (data_file, start, id, type,
freq, until, notep, exc);
} else {
}
else
{
event_scan (data_file, start, id, notep);
}
} else { /* NOT REACHED */
}
else
{ /* NOT REACHED */
fputs (error, stderr);
exit (EXIT_FAILURE);
}
@ -721,32 +798,42 @@ io_load_todo(void)
char buf[BUFSIZ], e_todo[BUFSIZ], note[NOTESIZ + 1];
data_file = fopen (path_todo, "r");
if (data_file == NULL) {
if (data_file == NULL)
{
status_mesg (mesg_line1, mesg_line2);
wgetch (win[STA].p);
}
for (;;) {
for (;;)
{
c = getc (data_file);
if (c == EOF) {
if (c == EOF)
{
break;
} else if (c == '[') { /* new style with id */
}
else if (c == '[')
{ /* new style with id */
fscanf (data_file, "%d]", &id);
} else {
}
else
{
id = 9;
ungetc (c, data_file);
}
/* Now read the attached note, if any. */
c = getc (data_file);
if (c == '>') {
if (c == '>')
{
fgets (note, NOTESIZ + 1, data_file);
note[NOTESIZ] = '\0';
getc (data_file);
} else
}
else
note[0] = '\0';
/* Then read todo description. */
fgets (buf, BUFSIZ, data_file);
nl = strchr (buf, '\n');
if (nl) {
if (nl)
{
*nl = '\0';
}
io_extract_data (e_todo, buf, strlen (buf));
@ -761,14 +848,16 @@ static void
check_directory (char *dir, int *missing)
{
errno = 0;
if (mkdir(dir, 0700) != 0) {
if (errno != EEXIST) {
fprintf(stderr,
_("FATAL ERROR: could not create %s: %s\n"),
if (mkdir (dir, 0700) != 0)
{
if (errno != EEXIST)
{
fprintf (stderr, _("FATAL ERROR: could not create %s: %s\n"),
dir, strerror (errno));
exit (EXIT_FAILURE);
}
} else
}
else
(*missing)++;
}
@ -778,11 +867,12 @@ check_file(char *file, int *missing)
FILE *fd;
errno = 0;
if ((fd = fopen(file, "r")) == NULL) {
if ((fd = fopen (file, "r")) == NULL)
{
(*missing)++;
if ((fd = fopen(file, "w")) == NULL) {
fprintf(stderr,
_("FATAL ERROR: could not create %s: %s\n"),
if ((fd = fopen (file, "w")) == NULL)
{
fprintf (stderr, _("FATAL ERROR: could not create %s: %s\n"),
file, strerror (errno));
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 *enter = _("Press [ENTER] to continue");
if (no_data_file != 0) {
if (no_data_file != 0)
{
status_mesg (welcome_mesg, enter);
wgetch (win[STA].p);
} else if (!skip_dialogs) {
}
else if (!skip_dialogs)
{
status_mesg (data_mesg, enter);
wgetch (win[STA].p);
}
@ -839,12 +932,12 @@ void
io_export_data (export_mode_t mode, conf_t *conf)
{
FILE *stream;
char *wrong_mode =
_("FATAL ERROR in io_export_data: wrong export mode\n");
char *wrong_mode = _("FATAL ERROR in io_export_data: wrong export mode\n");
char *success = _("The data were successfully exported");
char *enter = _("Press [ENTER] to continue");
switch (mode) {
switch (mode)
{
case IO_EXPORT_NONINTERACTIVE:
stream = stdout;
break;
@ -881,7 +974,8 @@ io_export_data(export_mode_t mode, conf_t *conf)
if (stream != stdout)
fclose (stream);
if (!conf->skip_system_dialogs && mode == IO_EXPORT_INTERACTIVE) {
if (!conf->skip_system_dialogs && mode == IO_EXPORT_INTERACTIVE)
{
status_mesg (success, enter);
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
* Copyright (c) 2004-2007 Frederic Culot
* Copyright (c) 2004-2008 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -29,11 +29,13 @@
#include "vars.h"
typedef enum {
typedef enum
{
IO_EXPORT_NONINTERACTIVE,
IO_EXPORT_INTERACTIVE,
IO_EXPORT_NBMODES
} export_mode_t;
}
export_mode_t;
void io_init (char *);
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
* Copyright (c) 2004-2007 Frederic Culot
* Copyright (c) 2004-2008 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -48,7 +48,7 @@ notify_bar(void)
display_bar = (nbar->show) ? 1 : 0;
pthread_mutex_unlock (&nbar->mutex);
return display_bar;
return (display_bar);
}
/* Initialize the nbar variable used to store notification options. */
@ -80,7 +80,8 @@ extract_aptsfile(void)
file = strrchr (path_apts, '/');
if (!file)
notify->apts_file = path_apts;
else {
else
{
notify->apts_file = file;
notify->apts_file++;
}
@ -95,8 +96,7 @@ void
notify_init_bar (void)
{
notify = (struct notify_vars_s *) malloc (sizeof (struct notify_vars_s));
notify_app = (struct notify_app_s *)
malloc(sizeof(struct notify_app_s));
notify_app = (struct notify_app_s *) malloc (sizeof (struct notify_app_s));
pthread_mutex_init (&notify->mutex, NULL);
pthread_mutex_init (&notify_app->mutex, NULL);
notify_app->got_app = 0;
@ -132,13 +132,11 @@ launch_cmd(char *cmd, char *shell)
pid = fork ();
if (pid < 0)
ierror(_("FATAL ERROR in launch_cmd: could not fork"),
IERROR_WARN);
ierror (_("FATAL ERROR in launch_cmd: could not fork"), IERROR_WARN);
else if (pid == 0) /* Child: launch user defined command */
if (execlp (shell, shell, "-c", cmd, (char *) NULL) < 0)
ierror (_("FATAL ERROR in launch_cmd: could not "
"launch user command"),
IERROR_WARN);
"launch user command"), IERROR_WARN);
}
/*
@ -169,22 +167,22 @@ notify_update_bar(void)
mvwprintw (notify->win, 0, file_pos, "(%s)", notify->apts_file);
pthread_mutex_lock (&notify_app->mutex);
if (notify_app->got_app) {
if (strlen(notify_app->txt) > txt_max_len) {
if (notify_app->got_app)
{
if (strlen (notify_app->txt) > txt_max_len)
{
too_long = 1;
strncpy (buf, notify_app->txt, txt_max_len - 3);
buf[txt_max_len - 3] = '\0';
}
time_left = notify_app->time - notify->time_in_sec;
if (time_left > 0) {
if (time_left > 0)
{
hours_left = (time_left / HOURINSEC);
minutes_left = (time_left - hours_left * HOURINSEC) /
MININSEC;
minutes_left = (time_left - hours_left * HOURINSEC) / MININSEC;
pthread_mutex_lock (&nbar->mutex);
if (time_left < nbar->cntdwn &&
(notify_app->state & APOINT_NOTIFY))
if (time_left < nbar->cntdwn && (notify_app->state & APOINT_NOTIFY))
blinking = 1;
else
blinking = 0;
@ -192,24 +190,23 @@ notify_update_bar(void)
if (blinking)
wattron (notify->win, A_BLINK);
if (too_long)
mvwprintw(notify->win, 0, app_pos,
"> %02d:%02d :: %s.. <",
mvwprintw (notify->win, 0, app_pos, "> %02d:%02d :: %s.. <",
hours_left, minutes_left, buf);
else
mvwprintw(notify->win, 0, app_pos,
"> %02d:%02d :: %s <",
hours_left, minutes_left,
notify_app->txt);
mvwprintw (notify->win, 0, app_pos, "> %02d:%02d :: %s <",
hours_left, minutes_left, notify_app->txt);
if (blinking)
wattroff (notify->win, A_BLINK);
if (blinking &&
!(notify_app->state & APOINT_NOTIFIED)) {
if (blinking && !(notify_app->state & APOINT_NOTIFIED))
{
notify_app->state |= APOINT_NOTIFIED;
launch_cmd (nbar->cmd, nbar->shell);
}
pthread_mutex_unlock (&nbar->mutex);
} else {
}
else
{
notify_app->got_app = 0;
pthread_mutex_unlock (&notify_app->mutex);
pthread_mutex_unlock (&notify->mutex);
@ -239,7 +236,8 @@ notify_main_thread(void *arg)
elapse = 0;
got_app = 0;
for (;;) {
for (;;)
{
ntimer = time (NULL);
ntime = localtime (&ntimer);
pthread_mutex_lock (&notify->mutex);
@ -252,7 +250,8 @@ notify_main_thread(void *arg)
notify_update_bar ();
sleep (thread_sleep);
elapse += thread_sleep;
if (elapse >= check_app) {
if (elapse >= check_app)
{
elapse = 0;
pthread_mutex_lock (&notify_app->mutex);
got_app = notify_app->got_app;
@ -283,12 +282,15 @@ notify_thread_app(void *arg)
tmp_app = apoint_check_next (tmp_app, current_time);
pthread_mutex_lock (&notify_app->mutex);
if (tmp_app->got_app) {
if (tmp_app->got_app)
{
notify_app->got_app = 1;
notify_app->time = tmp_app->time;
notify_app->txt = mycpy (tmp_app->txt);
notify_app->state = tmp_app->state;
} else {
}
else
{
notify_app->got_app = 0;
}
pthread_mutex_unlock (&notify_app->mutex);
@ -321,16 +323,21 @@ notify_check_added(char *mesg, long start, char state)
current_time = time (NULL);
pthread_mutex_lock (&notify_app->mutex);
if (!notify_app->got_app) {
if (!notify_app->got_app)
{
gap = start - current_time;
if (gap >= 0 && gap <= DAYINSEC)
update_notify = 1;
} else if (start < notify_app->time && start >= current_time) {
}
else if (start < notify_app->time && start >= current_time)
{
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;
if (update_notify) {
if (update_notify)
{
notify_app->got_app = 1;
notify_app->time = start;
notify_app->txt = mycpy (mesg);
@ -351,18 +358,25 @@ notify_check_repeated(recur_apoint_llist_node_t *i)
current_time = time (NULL);
pthread_mutex_lock (&notify_app->mutex);
if ((real_app_time = recur_item_inday (i->start, i->exc, i->rpt->type,
i->rpt->freq, i->rpt->until, get_today()) > current_time)) {
if (!notify_app->got_app) {
i->rpt->freq, i->rpt->until,
get_today ()) > current_time))
{
if (!notify_app->got_app)
{
if (real_app_time - current_time <= DAYINSEC)
update_notify = 1;
} else if (real_app_time < notify_app->time &&
real_app_time >= current_time) {
}
else if (real_app_time < notify_app->time &&
real_app_time >= current_time)
{
update_notify = 1;
} else if (real_app_time == notify_app->time &&
}
else if (real_app_time == notify_app->time &&
i->state != notify_app->state)
update_notify = 1;
}
if (update_notify) {
if (update_notify)
{
notify_app->got_app = 1;
notify_app->time = real_app_time;
notify_app->txt = mycpy (i->mesg);
@ -382,7 +396,7 @@ notify_same_item(long time)
same = 1;
pthread_mutex_unlock (&(notify_app->mutex));
return same;
return (same);
}
int
@ -398,7 +412,7 @@ notify_same_recur_item(recur_apoint_llist_node_t *i)
same = 1;
pthread_mutex_unlock (&(notify_app->mutex));
return same;
return (same);
}
/* Launch the notify-bar main thread. */
@ -414,13 +428,16 @@ notify_start_main_thread(void)
static void
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 desc[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;
char buf[BUFSIZ];
@ -438,8 +455,7 @@ notify_print_options(WINDOW *optwin, int col)
strncpy (opt[CMD].name, _("notify-bar_command = "), BUFSIZ);
strncpy (opt[SHOW].desc,
_("(if set to YES, notify-bar will be displayed)"),
BUFSIZ);
_("(if set to YES, notify-bar will be displayed)"), BUFSIZ);
strncpy (opt[DATE].desc,
_("(Format of the date to be displayed inside notify-bar)"),
BUFSIZ);
@ -448,8 +464,7 @@ notify_print_options(WINDOW *optwin, int col)
BUFSIZ);
strncpy (opt[WARN].desc,
_("(Warn user if an appointment is within next 'notify-bar_warning'"
" seconds)"),
BUFSIZ);
" seconds)"), BUFSIZ);
strncpy (opt[CMD].desc,
_("(Command used to notify user of an upcoming appointment)"),
BUFSIZ);
@ -468,7 +483,8 @@ notify_print_options(WINDOW *optwin, int col)
print_option_incolor (optwin, nbar->show, y_pos, x);
mvwprintw (optwin, y_pos + 1, x_pos, opt[SHOW].desc);
for (i = 1; i < NB_OPT; i++) {
for (i = 1; i < NB_OPT; i++)
{
l = strlen (opt[i].name);
y = y_pos + i * y_offset;
x = x_pos + x_offset + l;
@ -479,7 +495,8 @@ notify_print_options(WINDOW *optwin, int col)
custom_apply_attr (optwin, ATTR_HIGHEST);
if (strlen (opt[i].value) < maxlen)
mvwprintw (optwin, y, x, "%s", opt[i].value);
else {
else
{
strncpy (buf, opt[i].value, maxlen - 1);
buf[maxlen - 1] = '\0';
mvwprintw (optwin, y, x, "%s...", buf);
@ -516,7 +533,8 @@ notify_config_bar(void)
snprintf (label, BUFSIZ, _("CalCurse %s | notify-bar options"), VERSION);
custom_confwin_init (&conf_win, label);
while (ch != 'q') {
while (ch != 'q')
{
if (change_win)
custom_confwin_init (&conf_win, label);
status_mesg (number_str, "");
@ -524,7 +542,8 @@ notify_config_bar(void)
*buf = '\0';
ch = wgetch (win[STA].p);
switch (ch) {
switch (ch)
{
case KEY_RESIZE:
endwin ();
refresh ();
@ -548,7 +567,8 @@ notify_config_bar(void)
pthread_mutex_lock (&nbar->mutex);
strncpy (buf, nbar->datefmt, strlen (nbar->datefmt) + 1);
pthread_mutex_unlock (&nbar->mutex);
if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
if (updatestring (win[STA].p, &buf, 0, 1) == 0)
{
pthread_mutex_lock (&nbar->mutex);
strncpy (nbar->datefmt, buf, strlen (buf) + 1);
pthread_mutex_unlock (&nbar->mutex);
@ -560,7 +580,8 @@ notify_config_bar(void)
pthread_mutex_lock (&nbar->mutex);
strncpy (buf, nbar->timefmt, strlen (nbar->timefmt) + 1);
pthread_mutex_unlock (&nbar->mutex);
if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
if (updatestring (win[STA].p, &buf, 0, 1) == 0)
{
pthread_mutex_lock (&nbar->mutex);
strncpy (nbar->timefmt, buf, strlen (buf) + 1);
pthread_mutex_unlock (&nbar->mutex);
@ -573,8 +594,8 @@ notify_config_bar(void)
printf (buf, "%d", nbar->cntdwn);
pthread_mutex_unlock (&nbar->mutex);
if (updatestring (win[STA].p, &buf, 0, 1) == 0 &&
is_all_digit(buf) &&
atoi(buf) >= 0 && atoi(buf) <= DAYINSEC) {
is_all_digit (buf) && atoi (buf) >= 0 && atoi (buf) <= DAYINSEC)
{
pthread_mutex_lock (&nbar->mutex);
nbar->cntdwn = atoi (buf);
pthread_mutex_unlock (&nbar->mutex);
@ -586,7 +607,8 @@ notify_config_bar(void)
pthread_mutex_lock (&nbar->mutex);
strncpy (buf, nbar->cmd, strlen (nbar->cmd) + 1);
pthread_mutex_unlock (&nbar->mutex);
if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
if (updatestring (win[STA].p, &buf, 0, 1) == 0)
{
pthread_mutex_lock (&nbar->mutex);
strncpy (nbar->cmd, buf, strlen (buf) + 1);
pthread_mutex_unlock (&nbar->mutex);

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
* Copyright (c) 2004-2007 Frederic Culot
* Copyright (c) 2004-2008 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -33,7 +33,8 @@
#define NOTIFY_FIELD_LENGTH 25
struct notify_vars_s {
struct notify_vars_s
{
WINDOW *win;
long time_in_sec;
char *apts_file;
@ -42,7 +43,8 @@ struct notify_vars_s {
pthread_mutex_t mutex;
};
struct notify_app_s {
struct notify_app_s
{
long time;
int got_app;
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
@ -47,7 +47,7 @@ recur_apoint_llist_init(void)
recur_alist_p->root = NULL;
pthread_mutex_init (&(recur_alist_p->mutex), NULL);
return 0;
return (0);
}
/* Insert a new recursive appointment in the general linked list */
@ -73,8 +73,10 @@ recur_apoint_new(char *mesg, char *note, long start, long dur, char state,
pthread_mutex_lock (&(recur_alist_p->mutex));
i = &recur_alist_p->root;
for (;;) {
if (*i == 0 || (*i)->start > start) {
for (;;)
{
if (*i == 0 || (*i)->start > start)
{
o->next = *i;
*i = o;
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));
return o;
return (o);
}
/* 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->exc = except;
i = &recur_elist;
for (;;) {
if (*i == 0 || (*i)->day > day) {
for (;;)
{
if (*i == 0 || (*i)->day > day)
{
o->next = *i;
*i = o;
break;
}
i = &(*i)->next;
}
return o;
return (o);
}
/*
@ -126,7 +130,8 @@ recur_def2char(recur_types_t define)
char recur_char;
char *error = _("FATAL ERROR in recur_def2char: unknown recur type\n");
switch (define) {
switch (define)
{
case RECUR_DAILY:
recur_char = 'D';
break;
@ -157,7 +162,8 @@ recur_char2def(char type)
int recur_def;
char *error = _("FATAL ERROR in recur_char2def: unknown char\n");
switch (type) {
switch (type)
{
case 'D':
recur_def = RECUR_DAILY;
break;
@ -179,12 +185,14 @@ recur_char2def(char type)
/* Write days for which recurrent items should not be repeated. */
static void
recur_write_exc(struct days_s *exc, FILE *f) {
recur_write_exc (struct days_s *exc, FILE *f)
{
struct tm *lt;
time_t t;
int st_mon, st_day, st_year;
while (exc) {
while (exc)
{
t = exc->st;
lt = localtime (&t);
st_mon = lt->tm_mon + 1;
@ -198,7 +206,8 @@ recur_write_exc(struct days_s *exc, FILE *f) {
/* Load the recursive appointment description */
recur_apoint_llist_node_t *
recur_apoint_scan (FILE *f, struct tm start, struct tm end, char type,
int freq, struct tm until, char *note, struct days_s *exc, char state)
int freq, struct tm until, char *note, struct days_s *exc,
char state)
{
struct tm *lt;
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 */
fgets (buf, MESG_MAXSIZE, f);
nl = strchr (buf, '\n');
if (nl) {
if (nl)
{
*nl = '\0';
}
start.tm_sec = end.tm_sec = 0;
start.tm_isdst = end.tm_isdst = -1;
start.tm_year -= 1900;
@ -223,7 +232,8 @@ recur_apoint_scan(FILE * f, struct tm start, struct tm end, char type,
tstart = mktime (&start);
tend = mktime (&end);
if (until.tm_year != 0) {
if (until.tm_year != 0)
{
until.tm_hour = 23;
until.tm_min = 59;
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_mon--;
tuntil = mktime (&until);
} else {
}
else
{
tuntil = 0;
}
if (tstart == -1 || tend == -1 || tstart > tend || tuntil == -1) {
fputs(_("FATAL ERROR in apoint_scan: date error in the appointment\n"), stderr);
if (tstart == -1 || tend == -1 || tstart > tend || tuntil == -1)
{
fputs (_("FATAL ERROR in apoint_scan: date error in the appointment\n"),
stderr);
exit (EXIT_FAILURE);
}
@ -259,32 +273,36 @@ struct tm until, char *note, struct days_s *exc)
/* Read the event description */
fgets (buf, MESG_MAXSIZE, f);
nl = strchr (buf, '\n');
if (nl) {
if (nl)
{
*nl = '\0';
}
start.tm_hour = until.tm_hour = 12;
start.tm_min = until.tm_min = 0;
start.tm_sec = until.tm_sec = 0;
start.tm_isdst = until.tm_isdst = -1;
start.tm_year -= 1900;
start.tm_mon--;
if (until.tm_year != 0) {
if (until.tm_year != 0)
{
until.tm_year -= 1900;
until.tm_mon--;
tuntil = mktime (&until);
} else {
}
else
{
tuntil = 0;
}
tstart = mktime (&start);
if ( (tstart == -1) || (tuntil == -1) ) {
if ((tstart == -1) || (tuntil == -1))
{
fputs (_("FATAL ERROR in recur_event_scan: "
"date error in the event\n"), stderr);
exit (EXIT_FAILURE);
}
return recur_event_new(buf, note, tstart, id, recur_char2def(type),
freq, tuntil, exc);
return (recur_event_new (buf, note, tstart, id, recur_char2def (type),
freq, tuntil, exc));
}
/* 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);
t = o->rpt->until;
if (t == 0) { /* We have an endless recurrent appointment. */
fprintf(f, " {%d%c", o->rpt->freq,
recur_def2char(o->rpt->type));
} else {
if (t == 0)
{ /* We have an endless recurrent appointment. */
fprintf (f, " {%d%c", o->rpt->freq, recur_def2char (o->rpt->type));
}
else
{
lt = localtime (&t);
fprintf (f, " {%d%c -> %02u/%02u/%04u",
o->rpt->freq, recur_def2char (o->rpt->type),
@ -343,11 +363,14 @@ recur_event_write(struct recur_event_s *o, FILE *f)
st_day = lt->tm_mday;
st_year = lt->tm_year + 1900;
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",
st_mon, st_day, st_year, o->id, o->rpt->freq,
recur_def2char (o->rpt->type));
} else {
}
else
{
lt = localtime (&t);
end_mon = lt->tm_mon + 1;
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 days_s *exc;
time_t t;
char *error =
_("FATAL ERROR in recur_item_inday: unknown item type\n");
char *error = _("FATAL ERROR in recur_item_inday: unknown item type\n");
day_end = day_start + DAYINSEC;
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)
if (exc->st < day_end && exc->st >= day_start)
return 0;
return (0);
if (rpt_until == 0) /* we have an endless recurrent item */
rpt_until = day_end;
if (item_start > day_end || rpt_until < day_start)
return 0;
return (0);
t = item_start;
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 +
lt_item.tm_sec);
switch (rpt_type) {
switch (rpt_type)
{
case RECUR_DAILY:
diff = (long) difftime ((time_t) day_start, (time_t) item_start);
if (diff % (rpt_freq * DAYINSEC) != 0)
return 0;
return (0);
lt_item.tm_mday = lt_day.tm_mday;
lt_item.tm_mon = lt_day.tm_mon;
lt_item.tm_year = lt_day.tm_year;
break;
case RECUR_WEEKLY:
if (lt_item.tm_wday != lt_day.tm_wday)
return 0;
else {
return (0);
else
{
diff = ((lt_day.tm_yday - lt_item.tm_yday) / WEEKINDAYS);
if (diff % rpt_freq != 0)
return 0;
return (0);
}
lt_item.tm_mday = lt_day.tm_mday;
lt_item.tm_mon = lt_day.tm_mon;
lt_item.tm_year = lt_day.tm_year;
break;
case RECUR_MONTHLY:
diff = ((lt_day.tm_year - lt_item.tm_year) * 12) +
(lt_day.tm_mon - lt_item.tm_mon);
diff = (((lt_day.tm_year - lt_item.tm_year) * 12)
+ (lt_day.tm_mon - lt_item.tm_mon));
if (diff % rpt_freq != 0)
return 0;
return (0);
lt_item.tm_mon = lt_day.tm_mon;
lt_item.tm_year = lt_day.tm_year;
break;
case RECUR_YEARLY:
diff = lt_day.tm_year - lt_item.tm_year;
if (diff % rpt_freq != 0)
return 0;
return (0);
lt_item.tm_year = lt_day.tm_year;
break;
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);
if (item_start < day_end && item_start >= day_start)
return item_start;
return (item_start);
else
return 0;
return (0);
}
/*
@ -482,14 +506,19 @@ recur_event_erase(long start, unsigned num, unsigned delete_whole,
struct days_s *o, **j;
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,
i->rpt->freq, i->rpt->until, start)) {
if (n == num) {
if (delete_whole) {
i->rpt->freq, i->rpt->until, start))
{
if (n == num)
{
if (delete_whole)
{
if (flag == ERASE_FORCE_ONLY_NOTE)
erase_note (&i->note, flag);
else {
else
{
*iptr = i->next;
free (i->mesg);
free (i->rpt);
@ -498,13 +527,16 @@ recur_event_erase(long start, unsigned num, unsigned delete_whole,
free (i);
}
return;
} else {
o = (struct days_s *)
malloc(sizeof(struct days_s));
}
else
{
o = (struct days_s *) malloc (sizeof (struct days_s));
o->st = start;
j = &i->exc;
for (;;) {
if(*j==0 || (*j)->st > start) {
for (;;)
{
if (*j == 0 || (*j)->st > start)
{
o->next = *j;
*j = o;
break;
@ -519,8 +551,7 @@ recur_event_erase(long start, unsigned num, unsigned delete_whole,
iptr = &i->next;
}
/* NOTREACHED */
fputs(_("FATAL ERROR in recur_event_erase: no such event\n"),
stderr);
fputs (_("FATAL ERROR in recur_event_erase: no such event\n"), stderr);
exit (EXIT_FAILURE);
}
@ -539,45 +570,49 @@ recur_apoint_erase(long start, unsigned num, unsigned delete_whole,
pthread_mutex_lock (&(recur_alist_p->mutex));
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,
i->rpt->freq, i->rpt->until, start)) {
if (n == num) {
if (notify_bar() &&
flag != ERASE_FORCE_ONLY_NOTE)
need_check_notify =
notify_same_recur_item(i);
if (delete_whole) {
i->rpt->freq, i->rpt->until, start))
{
if (n == num)
{
if (notify_bar () && flag != ERASE_FORCE_ONLY_NOTE)
need_check_notify = notify_same_recur_item (i);
if (delete_whole)
{
if (flag == ERASE_FORCE_ONLY_NOTE)
erase_note (&i->note, flag);
else {
else
{
*iptr = i->next;
free (i->mesg);
free (i->rpt);
free (i->exc);
erase_note (&i->note, flag);
free (i);
pthread_mutex_unlock(
&(recur_alist_p->mutex));
pthread_mutex_unlock (&(recur_alist_p->mutex));
if (need_check_notify)
notify_check_next_app ();
}
return;
} else {
o = (struct days_s *)
malloc(sizeof(struct days_s));
}
else
{
o = (struct days_s *) malloc (sizeof (struct days_s));
o->st = start;
j = &i->exc;
for (;;) {
if(*j==0 || (*j)->st > start) {
for (;;)
{
if (*j == 0 || (*j)->st > start)
{
o->next = *j;
*j = o;
break;
}
j = &(*j)->next;
}
pthread_mutex_unlock(
&(recur_alist_p->mutex));
pthread_mutex_unlock (&(recur_alist_p->mutex));
if (need_check_notify)
notify_check_next_app ();
return;
@ -614,10 +649,8 @@ recur_repeat_item(conf_t *conf)
char *mesg_type_1 =
_("Enter the repetition type: (D)aily, (W)eekly, (M)onthly, (Y)early");
char *mesg_type_2 = _("[D/W/M/Y] ");
char *mesg_freq_1 =
_("Enter the repetition frequence:");
char *mesg_wrong_freq =
_("The frequence you entered is not valid.");
char *mesg_freq_1 = _("Enter the repetition frequence:");
char *mesg_wrong_freq = _("The frequence you entered is not valid.");
char *mesg_until_1 =
_("Enter the ending date: [%s] or '0' for an endless repetition");
char *mesg_wrong_1 = _("The entered date is not valid.");
@ -636,67 +669,83 @@ recur_repeat_item(conf_t *conf)
item_nb = apoint_hilt ();
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);
ch = wgetch (win[STA].p);
return;
}
while ((ch != 'D') && (ch != 'W') && (ch != 'M')
&& (ch != 'Y') && (ch != ESCAPE) ) {
&& (ch != 'Y') && (ch != ESCAPE))
{
status_mesg (mesg_type_1, mesg_type_2);
ch = wgetch (win[STA].p);
ch = toupper (ch);
}
if (ch == ESCAPE) {
if (ch == ESCAPE)
{
return;
} else {
}
else
{
type = recur_char2def (ch);
ch = 0;
}
while (freq == 0) {
while (freq == 0)
{
status_mesg (mesg_freq_1, "");
if (getstring(win[STA].p, user_input, BUFSIZ, 0, 1) ==
GETSTRING_VALID) {
if (getstring (win[STA].p, user_input, BUFSIZ, 0, 1) == GETSTRING_VALID)
{
freq = atoi (user_input);
if (freq == 0) {
if (freq == 0)
{
status_mesg (mesg_wrong_freq, wrong_type_2);
wgetch (win[STA].p);
}
user_input[0] = '\0';
} else
}
else
return;
}
while (!date_entered) {
while (!date_entered)
{
snprintf (outstr, BUFSIZ, mesg_until_1,
DATEFMT_DESC (conf->input_datefmt));
status_mesg (_(outstr), "");
if (getstring(win[STA].p, user_input, BUFSIZ, 0, 1) ==
GETSTRING_VALID) {
if (strlen(user_input) == 1 &&
strncmp(user_input, "0", 1) == 0 ) {
if (getstring (win[STA].p, user_input, BUFSIZ, 0, 1) == GETSTRING_VALID)
{
if (strlen (user_input) == 1 && strncmp (user_input, "0", 1) == 0)
{
until = 0;
date_entered = 1;
} else {
}
else
{
if (parse_date (user_input, conf->input_datefmt,
&year, &month, &day)) {
t = p->start; lt = localtime(&t);
&year, &month, &day))
{
t = p->start;
lt = localtime (&t);
until_date.dd = day;
until_date.mm = month;
until_date.yyyy = year;
until = date2sec(until_date,
lt->tm_hour, lt->tm_min);
if (until < p->start) {
status_mesg(mesg_older,
wrong_type_2);
until = date2sec (until_date, lt->tm_hour, lt->tm_min);
if (until < p->start)
{
status_mesg (mesg_older, wrong_type_2);
wgetch (win[STA].p);
date_entered = 0;
} else {
}
else
{
date_entered = 1;
}
} else {
}
else
{
snprintf (outstr, BUFSIZ, mesg_wrong_2,
DATEFMT_DESC (conf->input_datefmt));
status_mesg (mesg_wrong_1, _(outstr));
@ -704,20 +753,26 @@ recur_repeat_item(conf_t *conf)
date_entered = 0;
}
}
} else
}
else
return;
}
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,
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,
p->state, type, freq, until, NULL);
if (notify_bar ())
notify_check_repeated (ra);
} else { /* NOTREACHED */
}
else
{ /* NOTREACHED */
fputs (_("FATAL ERROR in recur_repeat_item: wrong item type\n"),
stderr);
exit (EXIT_FAILURE);
@ -741,10 +796,12 @@ recur_exc_scan(FILE *data_file)
t = time (NULL);
lt = localtime (&t);
day = *lt;
while ((c = getc(data_file)) == '!') {
while ((c = getc (data_file)) == '!')
{
ungetc (c, data_file);
if (fscanf (data_file, "!%u / %u / %u ",
&day.tm_mon, &day.tm_mday, &day.tm_year) != 3) {
&day.tm_mon, &day.tm_mday, &day.tm_year) != 3)
{
fputs (_("FATAL ERROR in recur_exc_scan: "
"syntax error in the item date\n"), stderr);
exit (EXIT_FAILURE);
@ -758,7 +815,7 @@ recur_exc_scan(FILE *data_file)
exc->next = exc_head;
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;
pthread_mutex_lock (&(recur_alist_p->mutex));
for (i = recur_alist_p->root; i != 0; i = i->next) {
if (i->start > app->time) {
for (i = recur_alist_p->root; i != 0; i = i->next)
{
if (i->start > app->time)
{
pthread_mutex_unlock (&(recur_alist_p->mutex));
return app;
} else {
real_recur_start_time = recur_item_inday(
i->start, i->exc, i->rpt->type, i->rpt->freq,
return (app);
}
else
{
real_recur_start_time =
recur_item_inday (i->start, i->exc, i->rpt->type, i->rpt->freq,
i->rpt->until, day);
if (real_recur_start_time > start) {
if (real_recur_start_time > start)
{
app->time = real_recur_start_time;
app->txt = mycpy (i->mesg);
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));
return app;
return (app);
}
/* Returns a structure containing the selected recurrent appointment. */
@ -801,12 +863,15 @@ recur_get_apoint(long date, int num)
int n = 0;
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,
o->rpt->freq, o->rpt->until, date)) {
if (n == num) {
o->rpt->freq, o->rpt->until, date))
{
if (n == num)
{
pthread_mutex_unlock (&(recur_alist_p->mutex));
return o;
return (o);
}
n++;
}
@ -823,11 +888,14 @@ recur_get_event(long date, int num)
struct recur_event_s *o;
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,
o->rpt->freq, o->rpt->until, date)) {
if (n == num) {
return o;
o->rpt->freq, o->rpt->until, date))
{
if (n == num)
{
return (o);
}
n++;
}
@ -848,10 +916,13 @@ recur_apoint_switch_notify(long date, int recur_nb)
need_chk_notify = 0;
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,
o->rpt->freq, o->rpt->until, date)) {
if (n == recur_nb) {
o->rpt->freq, o->rpt->until, date))
{
if (n == recur_nb)
{
o->state ^= APOINT_NOTIFY;
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
@ -27,26 +27,31 @@
#ifndef CALCURSE_RECUR_H
#define CALCURSE_RECUR_H
typedef enum { RECUR_NO,
typedef enum
{ RECUR_NO,
RECUR_DAILY,
RECUR_WEEKLY,
RECUR_MONTHLY,
RECUR_YEARLY,
RECUR_TYPES
} recur_types_t;
}
recur_types_t;
struct days_s {
struct days_s
{
struct days_s *next;
long st; /* beggining of the considered day, in seconds */
};
struct rpt_s {
struct rpt_s
{
int type; /* repetition type, see RECUR_* defines */
int freq; /* repetition frequence */
long until; /* ending date for repeated event */
};
typedef struct recur_apoint_llist_node {
typedef struct recur_apoint_llist_node
{
struct recur_apoint_llist_node *next;
struct rpt_s *rpt; /* information about repetition */
struct days_s *exc; /* days when the item should not be repeated */
@ -55,14 +60,18 @@ typedef struct recur_apoint_llist_node {
char state; /* 8 bits to store item state */
char *mesg; /* appointment description */
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;
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 rpt_s *rpt; /* information about repetition */
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 *,
struct days_s *, 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 *);
unsigned recur_item_inday(long, struct days_s *, int,
int, long, long);
unsigned recur_item_inday (long, struct days_s *, int, int,
long, long);
void recur_event_erase (long, unsigned, unsigned,
erase_flag_e);
void recur_apoint_erase (long, unsigned, unsigned,

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
* Copyright (c) 2007 Frederic Culot
* Copyright (c) 2007-2008 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -42,7 +42,8 @@
static void
signal_handler (int sig)
{
switch (sig) {
switch (sig)
{
case SIGCHLD:
while (waitpid (WAIT_MYPGRP, NULL, WNOHANG) > 0)
;
@ -61,7 +62,8 @@ sigs_init(struct sigaction *sa)
sa->sa_handler = signal_handler;
sa->sa_flags = 0;
sigemptyset (&sa->sa_mask);
if (sigaction(SIGCHLD, sa, NULL) != 0) {
if (sigaction (SIGCHLD, sa, NULL) != 0)
{
perror ("sigaction");
exit (EXIT_FAILURE);
}
@ -69,7 +71,8 @@ sigs_init(struct sigaction *sa)
sa->sa_handler = signal_handler;
sa->sa_flags = 0;
sigemptyset (&sa->sa_mask);
if (sigaction(SIGWINCH, sa, NULL) != 0) {
if (sigaction (SIGWINCH, sa, NULL) != 0)
{
perror ("sigaction");
exit (EXIT_FAILURE);
}
@ -77,7 +80,8 @@ sigs_init(struct sigaction *sa)
sa->sa_handler = SIG_IGN;
sa->sa_flags = 0;
sigemptyset (&(sa->sa_mask));
if (sigaction(SIGINT, sa, NULL) != 0) {
if (sigaction (SIGINT, sa, NULL) != 0)
{
perror ("sigaction");
exit (EXIT_FAILURE);
}

View File

@ -1,8 +1,8 @@
/* $calcurse: sigs.h,v 1.2 2008/02/14 20:20:23 culot Exp $ */
/* $calcurse: sigs.h,v 1.3 2008/04/12 21:14:03 culot Exp $ */
/*
* Calcurse - text-based organizer
* Copyright (c) 2007 Frederic Culot
* Copyright (c) 2007-2008 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

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
* Copyright (c) 2004-2007 Frederic Culot
* Copyright (c) 2004-2008 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -47,10 +47,11 @@ todo_get_item(int item_number)
int i;
o = todolist;
for (i = 1; i < item_number; i++) {
for (i = 1; i < item_number; i++)
{
o = o->next;
}
return o;
return (o);
}
/* Sets which todo is highlighted. */
@ -135,14 +136,14 @@ todo_new_item(void)
{
int ch = 0;
char *mesg = _("Enter the new ToDo item : ");
char *mesg_id =
_("Enter the ToDo priority [1 (highest) - 9 (lowest)] :");
char *mesg_id = _("Enter the ToDo priority [1 (highest) - 9 (lowest)] :");
char todo_input[BUFSIZ] = "";
status_mesg (mesg, "");
if (getstring(win[STA].p, todo_input, BUFSIZ, 0, 1) ==
GETSTRING_VALID) {
while ( (ch < '1') || (ch > '9') ) {
if (getstring (win[STA].p, todo_input, BUFSIZ, 0, 1) == GETSTRING_VALID)
{
while ((ch < '1') || (ch > '9'))
{
status_mesg (mesg_id, "");
ch = wgetch (win[STA].p);
}
@ -162,15 +163,17 @@ todo_add(char *mesg, int id, char *note)
o->id = id;
o->note = (note != NULL && note[0] != '\0') ? strdup (note) : NULL;
i = &todolist;
for (;;) {
if (*i == 0 || (*i)->id > id) {
for (;;)
{
if (*i == 0 || (*i)->id > id)
{
o->next = *i;
*i = o;
break;
}
i = &(*i)->next;
}
return o;
return (o);
}
/* Delete a note previously attached to a todo item. */
@ -182,11 +185,12 @@ todo_delete_note_bynum(unsigned num)
n = 0;
iptr = &todolist;
for (i = todolist; i != 0; i = i->next) {
if (n == num) {
for (i = todolist; i != 0; i = i->next)
{
if (n == num)
{
if (i->note == NULL)
ierror(
_("FATAL ERROR in todo_delete_note_bynum: "
ierror (_("FATAL ERROR in todo_delete_note_bynum: "
"no note attached\n"), IERROR_FATAL);
erase_note (&i->note, ERASE_FORCE_ONLY_NOTE);
return;
@ -209,8 +213,10 @@ todo_delete_bynum(unsigned num, erase_flag_e flag)
n = 0;
iptr = &todolist;
for (i = todolist; i != 0; i = i->next) {
if (n == num) {
for (i = todolist; i != 0; i = i->next)
{
if (n == num)
{
*iptr = i->next;
free (i->mesg);
if (i->note != NULL)
@ -236,25 +242,29 @@ todo_delete(conf_t *conf)
char *erase_warning =
_("This item has a note attached to it. "
"Delete (t)odo or just its (n)ote ?");
char *erase_choice =
_("[t/n] ");
char *erase_choice = _("[t/n] ");
bool go_for_todo_del = false;
int answer = 0, has_note;
if (conf->confirm_delete) {
if (conf->confirm_delete)
{
status_mesg (del_todo_str, choices);
answer = wgetch (win[STA].p);
if ( (answer == 'y') && (todos > 0) ) {
if ((answer == 'y') && (todos > 0))
{
go_for_todo_del = true;
} else {
}
else
{
erase_status_bar ();
return;
}
} else
if (todos > 0)
}
else if (todos > 0)
go_for_todo_del = true;
if (go_for_todo_del == false) {
if (go_for_todo_del == false)
{
erase_status_bar ();
return;
}
@ -264,12 +274,14 @@ todo_delete(conf_t *conf)
if (has_note == 0)
answer = 't';
while (answer != 't' && answer != 'n' && answer != ESCAPE) {
while (answer != 't' && answer != 'n' && answer != ESCAPE)
{
status_mesg (erase_warning, erase_choice);
answer = wgetch (win[STA].p);
}
switch (answer) {
switch (answer)
{
case 't':
todo_delete_bynum (hilt - 1, ERASE_FORCE);
todos--;
@ -299,18 +311,22 @@ todo_get_position(struct todo_s *i)
struct todo_s *o;
int n = 1, found = 0;
for (o = todolist; o; o = o->next) {
if (o == i) {
for (o = todolist; o; o = o->next)
{
if (o == i)
{
found = 1;
break;
}
n++;
}
if (found) {
return n;
} else {
fputs(_("FATAL ERROR in todo_get_position: todo not found\n"),
stderr);
if (found)
{
return (n);
}
else
{
fputs (_("FATAL ERROR in todo_get_position: todo not found\n"), stderr);
exit (EXIT_FAILURE);
}
}
@ -332,15 +348,20 @@ todo_chg_priority(int action)
strncpy (backup_note, backup->note, NOTESIZ + 1);
else
backup_note[0] = '\0';
if (action == '+') {
if (action == '+')
{
(backup_id > 1) ? backup_id-- : do_chg--;
} else if (action == '-') {
(backup_id < 9) ? backup_id++ : do_chg--;
} else { /* NOTREACHED */
fputs(_("FATAL ERROR in todo_chg_priority: no such action\n"),
stderr);
}
if (do_chg) {
else if (action == '-')
{
(backup_id < 9) ? backup_id++ : do_chg--;
}
else
{ /* NOTREACHED */
fputs (_("FATAL ERROR in todo_chg_priority: no such action\n"), stderr);
}
if (do_chg)
{
todo_delete_bynum (hilt - 1, ERASE_FORCE_KEEP_NOTE);
backup = todo_add (backup_mesg, backup_id, backup_note);
hilt = todo_get_position (backup);
@ -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);
if (strlen (msg) < len)
mvwprintw (w, y, x, "%d%c %s", prio, ch_note, msg);
else {
else
{
strncpy (buf, msg, len - 1);
buf[len - 1] = '\0';
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;
/* Print todo item in the panel. */
erase_window_part(win[TOD].p, 1, title_lines, wintod->w - 2,
wintod->h - 2);
for (i = todolist; i != 0; i = i->next) {
erase_window_part (win[TOD].p, 1, title_lines, wintod->w - 2, wintod->h - 2);
for (i = todolist; i != 0; i = i->next)
{
num_todo++;
t_realpos = num_todo - first;
incolor = num_todo - hilt;
if (incolor == 0)
msgsav = i->mesg;
if (t_realpos >= 0 && t_realpos < max_items) {
if (t_realpos >= 0 && t_realpos < max_items)
{
display_todo_item (incolor, i->mesg, i->id,
(i->note != NULL) ? 1 : 0, len, y_offset, x_offset);
(i->note != NULL) ? 1 : 0, len, y_offset,
x_offset);
y_offset = y_offset + todo_lines;
}
}
/* Draw the scrollbar if necessary. */
if (todos > max_items){
if (todos > max_items)
{
float ratio = ((float) max_items) / ((float) todos);
int sbar_length = (int) (ratio * (max_items + 1));
int highend = (int) (ratio * first);
@ -439,9 +464,9 @@ todo_edit_note(char *editor)
char *filename;
i = todo_get_item (hilt);
if (i->note == NULL) {
if ((filename = new_tempfile(path_notes, NOTESIZ))
!= NULL)
if (i->note == NULL)
{
if ((filename = new_tempfile (path_notes, NOTESIZ)) != NULL)
i->note = filename;
else
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
* Copyright (c) 2004-2007 Frederic Culot
* Copyright (c) 2004-2008 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -29,7 +29,8 @@
#include "wins.h"
struct todo_s {
struct todo_s
{
struct todo_s *next;
char *mesg;
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
@ -90,7 +90,8 @@ aerror(const char *file, int line, const char *assertion)
char 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);
}
@ -122,8 +123,10 @@ erase_window_part(WINDOW *win, int first_col, int first_row, int last_col,
{
int c, r;
for (r = first_row; r <= last_row; r++){
for (c = first_col; c <= last_col; c++){
for (r = first_row; r <= last_row; r++)
{
for (c = first_col; c <= last_col; 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 */
WINDOW * popup(int pop_row, int pop_col,
int pop_y, int pop_x, char *pop_lab)
WINDOW *
popup (int pop_row, int pop_col, int pop_y, int pop_x, char *pop_lab)
{
char *txt_pop = _("Press any key to continue...");
char label[BUFSIZ];
@ -149,7 +152,7 @@ WINDOW * popup(int pop_row, int pop_col,
custom_remove_attr (popup_win, ATTR_HIGHEST);
wnoutrefresh (popup_win);
doupdate ();
return popup_win;
return (popup_win);
}
/* 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;
mvwaddnstr (win, y, x, str, MIN (len, max_col));
wclrtoeol (win);
if (page > 0 && page < max_page) {
if (page > 0 && page < max_page)
{
c = '*';
} else if (page > 0) {
}
else if (page > 0)
{
c = '<';
} else if (page < max_page) {
}
else if (page < max_page)
{
c = '>';
} else
}
else
c = 0;
mvwprintw (win, y, col - 1, "%c", c);
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;
showstring (win, y, x, orig, len, newpos);
while ((ch = wgetch(win)) != '\n') {
switch (ch) {
while ((ch = wgetch (win)) != '\n')
{
switch (ch)
{
case KEY_BACKSPACE: /* delete one character */
case 330:
case 127:
case CTRL ('H'):
if (len > 0) {
--newpos; --len;
if (len > 0)
{
--newpos;
--len;
if (newpos >= x + len)
--str;
else /* to be deleted inside string */
@ -283,13 +294,15 @@ getstring(WINDOW *win, char *str, int l, int x, int y)
break;
case CTRL ('D'): /* delete next character */
if (newpos != (x + len)) {
if (newpos != (x + len))
{
--len;
if (newpos >= x + len)
--str;
else
del_char (newpos, orig);
} else
}
else
printf ("\a");
break;
@ -324,14 +337,17 @@ getstring(WINDOW *win, char *str, int l, int x, int y)
break;
default: /* insert one character */
if (len < l - 1) {
if (newpos >= len) {
if (len < l - 1)
{
if (newpos >= len)
{
str = orig + newpos;
*str++ = ch;
}
else // char is to be inserted inside string
str = add_char (newpos, ch, orig);
++len; ++newpos;
++len;
++newpos;
}
}
@ -353,21 +369,25 @@ updatestring(WINDOW *win, char **str, int x, int y)
newstr = (char *) malloc (BUFSIZ);
(void) memcpy (newstr, *str, len);
escape = getstring (win, newstr, BUFSIZ, x, y);
if (!escape) {
if (!escape)
{
len = strlen (newstr) + 1;
if ((*str = (char *) realloc(*str, len)) == NULL) {
if ((*str = (char *) realloc (*str, len)) == NULL)
{
/* NOTREACHED */
ierror (_("FATAL ERROR in updatestring: out of memory"),
IERROR_FATAL);
} else
}
else
(void) memcpy (*str, newstr, len);
}
free (newstr);
return escape;
return (escape);
}
/* checks if a string is only made of digits */
int is_all_digit(char *string)
int
is_all_digit (char *string)
{
int digit, i;
int all_digit;
@ -380,7 +400,7 @@ int is_all_digit(char *string)
digit++;
if (digit == strlen (string))
all_digit = 1;
return all_digit;
return (all_digit);
}
/*
@ -447,12 +467,12 @@ status_bar(void)
which_pan = wins_slctd ();
start = pos[which_pan] + 2 * CMDS_PER_LINE * (status_page - 1);
end = MIN (start + 2 * CMDS_PER_LINE, pos[which_pan + 1]);
for (i = start; i < end; i += 2) {
for (i = start; i < end; i += 2)
{
custom_apply_attr (win[STA].p, ATTR_HIGHEST);
mvwprintw (win[STA].p, 0, j * cmd_length, binding[i]->key);
if (i + 1 != end)
mvwprintw(win[STA].p, 1, j * cmd_length,
binding[i+1]->key);
mvwprintw (win[STA].p, 1, j * cmd_length, binding[i + 1]->key);
custom_remove_attr (win[STA].p, ATTR_HIGHEST);
mvwprintw (win[STA].p, 0, j * cmd_length + KEY_LENGTH,
binding[i]->label);
@ -484,9 +504,9 @@ date2sec(date_t day, unsigned hour, unsigned min)
start.tm_year -= 1900;
start.tm_mon--;
tstart = mktime (&start);
if (tstart == -1) {
fputs(_("FATAL ERROR in date2sec: failure in mktime\n"),
stderr);
if (tstart == -1)
{
fputs (_("FATAL ERROR in date2sec: failure in mktime\n"), stderr);
fprintf (stderr, "%u %u %u %u %u\n", day.yyyy, day.mm, day.dd,
hour, min);
exit (EXIT_FAILURE);
@ -496,7 +516,8 @@ date2sec(date_t day, unsigned hour, unsigned min)
}
/* Return a string containing the hour of a given date in seconds. */
char *date_sec2hour_str(long sec)
char *
date_sec2hour_str (long sec)
{
const int TIME_LEN = 6;
struct tm *lt;
@ -507,7 +528,7 @@ char *date_sec2hour_str(long sec)
lt = localtime (&t);
timestr = (char *) malloc (TIME_LEN);
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. */
@ -522,7 +543,8 @@ date_sec2date_str(long sec, char *datefmt)
if (sec == 0)
snprintf (datestr, BUFSIZ, "0");
else {
else
{
t = sec;
lt = localtime (&t);
strftime (datestr, BUFSIZ, datefmt, lt);
@ -600,7 +622,8 @@ get_sec_date(date_t date)
char current_month[] = "mm ";
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);
ptrtime = localtime (&timer);
strftime (current_day, strlen (current_day), "%d", ptrtime);
@ -611,7 +634,7 @@ get_sec_date(date_t date)
date.yyyy = atoi (current_year);
}
long_date = date2sec (date, 0, 0);
return long_date;
return (long_date);
}
long
@ -635,37 +658,33 @@ check_time(char *string)
char hour[] = " ";
char minutes[] = " ";
if (((strlen(string) == 2) || (strlen(string) == 3)) &&
(isdigit(string[0]) != 0) && (isdigit(string[1]) != 0)) {
if (((strlen (string) == 2) || (strlen (string) == 3))
&& (isdigit (string[0]) != 0) && (isdigit (string[1]) != 0))
{
strncpy (minutes, string, 2);
if (atoi (minutes) >= 0)
ok = 2; /* [MM] format */
} else if ((strlen(string) == 4) && (isdigit(string[0]) != 0) &&
(isdigit(string[2]) != 0) && (isdigit(string[3]) != 0) &&
(string[1] == ':')) {
}
else if ((strlen (string) == 4) && (isdigit (string[0]) != 0)
&& (isdigit (string[2]) != 0) && (isdigit (string[3]) != 0)
&& (string[1] == ':'))
{
strncpy (hour, string, 1);
strncpy (minutes, string + 2, 2);
if ((atoi(hour) <= 24) && (atoi(hour) >= 0) &&
(atoi(minutes) < MININSEC) && (atoi(minutes) >= 0))
if ((atoi (hour) <= 24) && (atoi (hour) >= 0)
&& (atoi (minutes) < MININSEC) && (atoi (minutes) >= 0))
ok = 1; /* [H:MM] format */
} else if ((strlen(string) == 5) && (isdigit(string[0]) != 0) &&
(isdigit(string[1]) != 0) && (isdigit(string[3]) != 0) &&
(isdigit(string[4]) != 0) && (string[2] == ':')) {
}
else if ((strlen (string) == 5) && (isdigit (string[0]) != 0)
&& (isdigit (string[1]) != 0) && (isdigit (string[3]) != 0)
&& (isdigit (string[4]) != 0) && (string[2] == ':'))
{
strncpy (hour, string, 2);
strncpy (minutes, string + 3, 2);
if ((atoi(hour) <= 24) && (atoi(hour) >= 0) &&
(atoi(minutes) < MININSEC) && (atoi(minutes) >= 0))
if ((atoi (hour) <= 24) && (atoi (hour) >= 0)
&& (atoi (minutes) < MININSEC) && (atoi (minutes) >= 0))
ok = 1; /* [HH:MM] format */
}
return (ok);
}
@ -673,7 +692,8 @@ check_time(char *string)
* Display a scroll bar when there are so many items that they
* can not be displayed inside the corresponding panel.
*/
void draw_scrollbar(WINDOW *win, int y, int x, int length,
void
draw_scrollbar (WINDOW *win, int y, int x, int length,
int bar_top, int bar_bottom, bool hilt)
{
mvwvline (win, bar_top, x, ACS_VLINE, bar_bottom - bar_top);
@ -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
* 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)
{
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);
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",
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. */
void reset_status_page(void)
void
reset_status_page (void)
{
status_page = 1;
}
/* 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;
char *error = _("FATAL ERROR in other_status_page: unknown panel\n");
switch (panel) {
switch (panel)
{
case CAL:
nb_item = NB_CAL_CMDS;
break;
@ -740,9 +765,12 @@ void other_status_page(int panel)
ierror (error, IERROR_FATAL);
}
max_page = ceil (nb_item / (2 * CMDS_PER_LINE)) + 1;
if (status_page < max_page) {
if (status_page < max_page)
{
status_page++;
} else {
}
else
{
status_page = 1;
}
}
@ -763,27 +791,29 @@ get_today(void)
day.yyyy = lt->tm_year + 1900;
current_day = date2sec (day, 0, 0);
return current_day;
return (current_day);
}
/* Returns the current time in seconds. */
long now(void)
long
now (void)
{
time_t current_time;
current_time = time (NULL);
return current_time;
return (current_time);
}
/* Copy a string */
char *mycpy(const char *src)
char *
mycpy (const char *src)
{
char *string = malloc (strlen (src) + 1);
if (string != NULL)
return strncpy(string, src, strlen(src) + 1);
return (strncpy (string, src, strlen (src) + 1));
else
return NULL;
return (NULL);
}
long
@ -813,15 +843,19 @@ print_option_incolor(WINDOW *win, bool option, int pos_y, int pos_x)
int color = 0;
char option_value[BUFSIZ] = "";
if (option == true) {
if (option == true)
{
color = ATTR_TRUE;
strncpy (option_value, _("yes"), BUFSIZ);
} else if (option == false) {
}
else if (option == false)
{
color = ATTR_FALSE;
strncpy (option_value, _("no"), BUFSIZ);
} else {
ierror(
_("option not defined - Problem in print_option_incolor()"),
}
else
{
ierror (_("option not defined - Problem in print_option_incolor()"),
IERROR_FATAL);
}
custom_apply_attr (win, color);
@ -851,14 +885,14 @@ new_tempfile(const char *prefix, int trailing_len)
memcpy (fullname, prefix, prefix_len);
memset (fullname + prefix_len, 'X', trailing_len);
fullname[prefix_len + trailing_len] = '\0';
if ((fd = mkstemp(fullname)) == -1 ||
(file = fdopen(fd, "w+")) == NULL) {
if (fd != -1) {
if ((fd = mkstemp (fullname)) == -1 || (file = fdopen (fd, "w+")) == NULL)
{
if (fd != -1)
{
unlink (fullname);
close (fd);
}
ierror(
_("FATAL ERROR: temporary file could not be created!"),
ierror (_("FATAL ERROR: temporary file could not be created!"),
IERROR_WARN);
return (NULL);
}
@ -876,7 +910,8 @@ erase_note(char **note, erase_flag_e flag)
if (*note == NULL)
return;
if (flag != ERASE_FORCE_KEEP_NOTE) {
if (flag != ERASE_FORCE_KEEP_NOTE)
{
snprintf (fullname, BUFSIZ, "%s%s", path_notes, *note);
if (unlink (fullname) != 0)
ierror (errmsg, IERROR_FATAL);
@ -884,20 +919,23 @@ erase_note(char **note, erase_flag_e flag)
free (*note);
*note = NULL;
}
/*
* Convert a string containing a date into three integers containing the year,
* month and day.
* Returns 1 if sucessfully converted or 0 if the string is an invalid date.
*/
int parse_date(char *date_string, int datefmt,
int *year, int *month, int *day) {
int
parse_date (char *date_string, int datefmt, int *year, int *month, int *day)
{
int in1, in2, in3;
int lyear, lmonth, lday;
if (date_string == NULL)
return 0;
return (0);
if (sscanf (date_string, "%d / %d / %d", &in1, &in2, &in3) < 3)
return 0;
switch (datefmt) {
return (0);
switch (datefmt)
{
case 1:
lmonth = in1;
lday = in2;
@ -916,9 +954,9 @@ int parse_date(char *date_string, int datefmt,
default:
return (0);
}
if (lyear < 1 || lyear > 9999 || lmonth < 1 || lmonth > 12 ||
lday < 1 || lday > 31)
return 0;
if (lyear < 1 || lyear > 9999 || lmonth < 1 || lmonth > 12 || lday < 1
|| lday > 31)
return (0);
if (year != NULL)
*year = lyear;
if (month != NULL)

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
@ -51,22 +51,28 @@
#define GETSTRING_ESC 1 /* user pressed escape to cancel editing */
#define GETSTRING_RET 2 /* return was pressed without entering any text */
typedef struct { /* structure defining a keybinding */
typedef struct
{ /* structure defining a keybinding */
char *key;
char *label;
} binding_t;
}
binding_t;
typedef enum {
typedef enum
{
IERROR_FATAL,
IERROR_WARN
} ierror_sev_e;
}
ierror_sev_e;
typedef enum {
typedef enum
{
ERASE_DONT_FORCE,
ERASE_FORCE,
ERASE_FORCE_KEEP_NOTE,
ERASE_FORCE_ONLY_NOTE
} erase_flag_e;
}
erase_flag_e;
void exit_calcurse (int);
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
@ -45,8 +45,8 @@ bool colorize = false;
* variables to store calendar names
*/
int days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
char *monthnames[12] =
{ N_("January"),
char *monthnames[12] = {
N_("January"),
N_("February"),
N_("March"),
N_("April"),
@ -57,17 +57,19 @@ char *monthnames[12] =
N_("September"),
N_("October"),
N_("November"),
N_("December") };
N_("December")
};
char *daynames[8] =
{ N_("Sun"),
char *daynames[8] = {
N_("Sun"),
N_("Mon"),
N_("Tue"),
N_("Wed"),
N_("Thu"),
N_("Fri"),
N_("Sat"),
N_("Sun") };
N_("Sun")
};
/*
* variables to store data path names, which are initialized in
@ -85,7 +87,6 @@ struct pad_s *apad;
/* Variable to store notify-bar settings. */
struct nbar_s *nbar;
/*
* 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
@ -61,14 +61,16 @@
#define DATEFMT_DESC(datefmt) (datefmt == 1 ? _("mm/dd/yyyy") : \
(datefmt == 2 ? _("dd/mm/yyyy") : _("yyyy/mm/dd")))
struct pad_s {
struct pad_s
{
int width;
int length;
int first_onscreen; /* first line to be displayed inside window */
WINDOW *ptrwin; /* pointer to the pad window */
};
struct nbar_s {
struct nbar_s
{
int show; /* display or hide the notify-bar */
int cntdwn; /* warn when time left before next app
* becomes lesser than cntdwn */
@ -80,7 +82,8 @@ struct nbar_s {
};
/* General configuration variables */
typedef struct {
typedef struct
{
bool auto_save;
bool confirm_quit;
bool confirm_delete;
@ -90,7 +93,8 @@ typedef struct {
char *pager;
char output_datefmt[BUFSIZ]; /* format for displaying date */
int input_datefmt; /* format for reading date */
} conf_t;
}
conf_t;
extern int col, row;
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
* Copyright (c) 2007 Frederic Culot
* Copyright (c) 2007-2008 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -133,8 +133,7 @@ wins_reinit(void)
wins_get_config ();
wins_init ();
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);
}
/* 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].x = 0;
if (notify_bar()) {
if (notify_bar ())
{
win[NOT].h = 1;
win[NOT].w = col;
win[NOT].y = win[STA].y - 1;
win[NOT].x = 0;
} else {
}
else
{
win[NOT].h = 0;
win[NOT].w = 0;
win[NOT].y = 0;
win[NOT].x = 0;
}
if (layout <= 4) { /* APPOINTMENT is the biggest panel */
if (layout <= 4)
{ /* APPOINTMENT is the biggest panel */
win[APP].w = col - CALWIDTH;
win[APP].h = row - (win[STA].h + win[NOT].h);
win[TOD].w = CALWIDTH;
win[TOD].h = row - (CALHEIGHT + win[STA].h + win[NOT].h);
} else { /* TODO is the biggest panel */
}
else
{ /* TODO is the biggest panel */
win[TOD].w = col - CALWIDTH;
win[TOD].h = row - (win[STA].h + win[NOT].h);
win[APP].w = CALWIDTH;
@ -194,7 +199,8 @@ wins_get_config(void)
}
/* defining the layout */
switch (layout) {
switch (layout)
{
case 1:
win[APP].y = 0;
win[APP].x = 0;
@ -269,20 +275,24 @@ border_color(WINDOW *window)
int color_attr = A_BOLD;
int no_color_attr = A_BOLD;
if (colorize) {
if (colorize)
{
wattron (window, color_attr | COLOR_PAIR (COLR_CUSTOM));
box (window, 0, 0);
} else {
}
else
{
wattron (window, no_color_attr);
box (window, 0, 0);
}
if (colorize) {
if (colorize)
{
wattroff (window, color_attr | COLOR_PAIR (COLR_CUSTOM));
} else {
}
else
{
wattroff (window, no_color_attr);
}
wnoutrefresh (window);
}
@ -293,20 +303,23 @@ border_nocolor(WINDOW *window)
int color_attr = A_BOLD;
int no_color_attr = A_DIM;
if (colorize) {
if (colorize)
{
wattron (window, color_attr | COLOR_PAIR (COLR_DEFAULT));
} else {
}
else
{
wattron (window, no_color_attr);
}
box (window, 0, 0);
if (colorize) {
if (colorize)
{
wattroff (window, color_attr | COLOR_PAIR (COLR_DEFAULT));
} else {
}
else
{
wattroff (window, no_color_attr);
}
wnoutrefresh (window);
}
@ -317,8 +330,8 @@ border_nocolor(WINDOW *window)
void
wins_update (void)
{
switch (slctd_win) {
switch (slctd_win)
{
case CAL:
border_color (win[CAL].p);
border_nocolor (win[APP].p);
@ -374,10 +387,12 @@ wins_launch_external(const char *file, const char *cmd)
char *p;
int len;
len = strlen(file) + strlen(cmd) + 2; /* Beware of space between cmd and
file. */
/* Beware of space between cmd and file. */
len = strlen (file) + strlen (cmd) + 2;
p = (char *) malloc (sizeof (char) * len);
if (snprintf(p, len, "%s %s", cmd, file) == -1) {
if (snprintf (p, len, "%s %s", cmd, file) == -1)
{
free (p);
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
* Copyright (c) 2007 Frederic Culot
* Copyright (c) 2007-2008 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -29,23 +29,27 @@
#include "vars.h"
typedef enum {
typedef enum
{
CAL,
APP,
TOD,
NOT,
STA,
NBWINS
} window_e;
}
window_e;
/* Window properties */
typedef struct {
typedef struct
{
WINDOW *p; /* pointer to window */
unsigned w; /* width */
unsigned h; /* height */
int x; /* x position */
int y; /* y position */
} window_t;
}
window_t;
extern window_t win[NBWINS];