Switch to Linux kernel coding style

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

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

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

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

View File

@ -45,27 +45,23 @@ llist_ts_t alist_p;
static struct apoint bkp_cut_apoint;
static int hilt;
void
apoint_free_bkp (void)
{
if (bkp_cut_apoint.mesg)
void apoint_free_bkp(void)
{
if (bkp_cut_apoint.mesg) {
mem_free(bkp_cut_apoint.mesg);
bkp_cut_apoint.mesg = 0;
}
erase_note(&bkp_cut_apoint.note);
}
static void
apoint_free (struct apoint *apt)
static void apoint_free(struct apoint *apt)
{
mem_free(apt->mesg);
erase_note(&apt->note);
mem_free(apt);
}
static void
apoint_dup (struct apoint *in, struct apoint *bkp)
static void apoint_dup(struct apoint *in, struct apoint *bkp)
{
EXIT_IF(!in || !bkp, _("null pointer"));
@ -77,8 +73,7 @@ apoint_dup (struct apoint *in, struct apoint *bkp)
bkp->note = mem_strdup(in->note);
}
void
apoint_llist_init (void)
void apoint_llist_init(void)
{
LLIST_TS_INIT(&alist_p);
}
@ -88,47 +83,41 @@ apoint_llist_init (void)
* list. No need to be thread safe, as only the main process remains when
* calling this function.
*/
void
apoint_llist_free (void)
void apoint_llist_free(void)
{
LLIST_TS_FREE_INNER(&alist_p, apoint_free);
LLIST_TS_FREE(&alist_p);
}
/* Sets which appointment is highlighted. */
void
apoint_hilt_set (int highlighted)
void apoint_hilt_set(int highlighted)
{
hilt = highlighted;
}
void
apoint_hilt_decrease (int n)
void apoint_hilt_decrease(int n)
{
hilt -= n;
}
void
apoint_hilt_increase (int n)
void apoint_hilt_increase(int n)
{
hilt += n;
}
/* Return which appointment is highlighted. */
int
apoint_hilt (void)
int apoint_hilt(void)
{
return hilt;
}
static int
apoint_cmp_start (struct apoint *a, struct apoint *b)
static int apoint_cmp_start(struct apoint *a, struct apoint *b)
{
return a->start < b->start ? -1 : (a->start == b->start ? 0 : 1);
}
struct apoint *
apoint_new (char *mesg, char *note, long start, long dur, char state)
struct apoint *apoint_new(char *mesg, char *note, long start, long dur,
char state)
{
struct apoint *apt;
@ -150,20 +139,21 @@ apoint_new (char *mesg, char *note, long start, long dur, char state)
* Add an item in either the appointment or the event list,
* depending if the start time is entered or not.
*/
void
apoint_add (void)
void apoint_add(void)
{
#define LTIME 6
#define LDUR 12
const char *mesg_1 =
_("Enter start time ([hh:mm]), leave blank for an all-day event : ");
const char *mesg_2 =
_("Enter end time ([hh:mm]) or duration ([+hh:mm], [+xxxdxxhxxm] or [+mm]) : ");
_
("Enter end time ([hh:mm]) or duration ([+hh:mm], [+xxxdxxhxxm] or [+mm]) : ");
const char *mesg_3 = _("Enter description :");
const char *format_message_1 =
_("You entered an invalid start time, should be [hh:mm]");
const char *format_message_2 =
_("Invalid end time/duration, should be [hh:mm], [+hh:mm], [+xxxdxxhxxm] or [+mm]");
_
("Invalid end time/duration, should be [hh:mm], [+hh:mm], [+xxxdxxhxxm] or [+mm]");
const char *enter_str = _("Press [Enter] to continue");
int Id = 1;
char item_time[LDUR] = "";
@ -175,26 +165,21 @@ apoint_add (void)
int is_appointment = 1;
/* Get the starting time */
for (;;)
{
for (;;) {
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;
}
if (parse_time(item_time, &heures, &minutes) == 1)
break;
else
{
else {
status_mesg(format_message_1, enter_str);
wgetch(win[STA].p);
}
}
else
} else
return;
}
@ -203,55 +188,41 @@ 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';
for (;;)
{
for (;;) {
status_mesg(mesg_2, "");
if (getstring (win[STA].p, item_time, LDUR, 0, 1) != GETSTRING_ESC)
{
if (getstring(win[STA].p, item_time, LDUR, 0, 1) != GETSTRING_ESC) {
if (*item_time == '+' && parse_duration(item_time + 1,
&apoint_duration) == 1)
break;
else if (parse_time (item_time, &end_h, &end_m) == 1)
{
if (end_h < heures || ((end_h == heures) && (end_m < minutes)))
{
else if (parse_time(item_time, &end_h, &end_m) == 1) {
if (end_h < heures || ((end_h == heures) && (end_m < minutes))) {
apoint_duration = MININSEC - minutes + end_m
+ (24 + end_h - (heures + 1)) * MININSEC;
}
else
{
} else {
apoint_duration = MININSEC - minutes
+ end_m + (end_h - (heures + 1)) * MININSEC;
}
break;
}
else
{
} else {
status_mesg(format_message_2, enter_str);
wgetch(win[STA].p);
}
}
else
} else
return;
}
}
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)
{
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_new(item_mesg, 0L, apoint_start, min2sec(apoint_duration), 0L);
if (notify_bar())
notify_check_added(item_mesg, apoint_start, 0L);
}
else
} else
event_new(item_mesg, 0L, date2sec(*calendar_get_slctd_day(), 0, 0), Id);
if (hilt == 0)
@ -261,8 +232,7 @@ apoint_add (void)
}
/* Delete an item from the appointment list. */
void
apoint_delete (unsigned *nb_events, unsigned *nb_apoints)
void apoint_delete(unsigned *nb_events, unsigned *nb_apoints)
{
const char *del_app_str = _("Do you really want to delete this item ?");
long date;
@ -274,19 +244,15 @@ apoint_delete (unsigned *nb_events, unsigned *nb_apoints)
if (nb_items == 0)
return;
if (conf.confirm_delete)
{
if (status_ask_bool (del_app_str) != 1)
{
if (conf.confirm_delete) {
if (status_ask_bool(del_app_str) != 1) {
wins_erase_status_bar();
return;
}
}
if (nb_items != 0)
{
switch (day_erase_item (date, hilt, ERASE_DONT_FORCE))
{
if (nb_items != 0) {
switch (day_erase_item(date, hilt, ERASE_DONT_FORCE)) {
case EVNT:
case RECUR_EVNT:
(*nb_events)--;
@ -314,8 +280,7 @@ apoint_delete (unsigned *nb_events, unsigned *nb_apoints)
}
/* Cut an item, so that it can be pasted somewhere else later. */
int
apoint_cut (unsigned *nb_events, unsigned *nb_apoints)
int apoint_cut(unsigned *nb_events, unsigned *nb_apoints)
{
const int NBITEMS = *nb_apoints + *nb_events;
int item_type, to_be_removed;
@ -326,17 +291,13 @@ apoint_cut (unsigned *nb_events, unsigned *nb_apoints)
date = calendar_get_slctd_day_sec();
item_type = day_cut_item(date, hilt);
if (item_type == EVNT || item_type == RECUR_EVNT)
{
if (item_type == EVNT || item_type == RECUR_EVNT) {
(*nb_events)--;
to_be_removed = 1;
}
else if (item_type == APPT || item_type == RECUR_APPT)
{
} else if (item_type == APPT || item_type == RECUR_APPT) {
(*nb_apoints)--;
to_be_removed = 3;
}
else
} else
EXIT(_("no such type"));
/* NOTREACHED */
@ -351,8 +312,7 @@ apoint_cut (unsigned *nb_events, unsigned *nb_apoints)
}
/* Paste a previously cut item. */
void
apoint_paste (unsigned *nb_events, unsigned *nb_apoints, int cut_item_type)
void apoint_paste(unsigned *nb_events, unsigned *nb_apoints, int cut_item_type)
{
int item_type;
long date;
@ -370,38 +330,33 @@ apoint_paste (unsigned *nb_events, unsigned *nb_apoints, int cut_item_type)
hilt++;
}
unsigned
apoint_inday (struct apoint *i, long start)
unsigned apoint_inday(struct apoint *i, long start)
{
return (i->start <= start + DAYINSEC && i->start + i->dur > start);
}
void
apoint_sec2str (struct apoint *o, long day, char *start, char *end)
void apoint_sec2str(struct apoint *o, long day, char *start, char *end)
{
struct tm *lt;
time_t t;
if (o->start < day)
strncpy(start, "..:..", 6);
else
{
else {
t = o->start;
lt = localtime(&t);
snprintf(start, HRMIN_SIZE, "%02u:%02u", lt->tm_hour, lt->tm_min);
}
if (o->start + o->dur > day + DAYINSEC)
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);
}
}
void
apoint_write (struct apoint *o, FILE *f)
void apoint_write(struct apoint *o, FILE * f)
{
struct tm *lt;
time_t t;
@ -427,8 +382,8 @@ apoint_write (struct apoint *o, FILE *f)
fprintf(f, "%s\n", o->mesg);
}
struct apoint *
apoint_scan (FILE *f, struct tm start, struct tm end, char state, char *note)
struct apoint *apoint_scan(FILE * f, struct tm start, struct tm end, char state,
char *note)
{
char buf[BUFSIZ], *newline;
time_t tstart, tend, t;
@ -459,8 +414,7 @@ apoint_scan (FILE *f, struct tm start, struct tm end, char state, char *note)
}
/* Retrieve an appointment from the list, given the day and item position. */
struct apoint *
apoint_get (long day, int pos)
struct apoint *apoint_get(long day, int pos)
{
llist_item_t *i = LLIST_TS_FIND_NTH(&alist_p, pos, day, apoint_inday);
@ -471,8 +425,7 @@ apoint_get (long day, int pos)
/* NOTREACHED */
}
void
apoint_delete_bynum (long start, unsigned num, enum eraseflg flag)
void apoint_delete_bynum(long start, unsigned num, enum eraseflg flag)
{
llist_item_t *i;
int need_check_notify = 0;
@ -484,8 +437,7 @@ apoint_delete_bynum (long start, unsigned num, enum eraseflg flag)
EXIT(_("no such appointment"));
struct apoint *apt = LLIST_TS_GET_DATA(i);
switch (flag)
{
switch (flag) {
case ERASE_FORCE_ONLY_NOTE:
erase_note(&apt->note);
break;
@ -513,8 +465,7 @@ apoint_delete_bynum (long start, unsigned num, enum eraseflg flag)
* the appointment panel. This is to help the appointment scroll function
* to place beggining of the pad correctly.
*/
static int
get_item_line (int item_nb, int nb_events_inday)
static int get_item_line(int item_nb, int nb_events_inday)
{
int separator = 2;
int line = 0;
@ -531,8 +482,7 @@ get_item_line (int item_nb, int nb_events_inday)
* Update (if necessary) the first displayed pad line to make the
* appointment panel scroll down next time pnoutrefresh is called.
*/
void
apoint_scroll_pad_down (int nb_events_inday, int win_length)
void apoint_scroll_pad_down(int nb_events_inday, int win_length)
{
int pad_last_line = 0;
int item_first_line = 0, item_last_line = 0;
@ -553,8 +503,7 @@ apoint_scroll_pad_down (int nb_events_inday, int win_length)
* Update (if necessary) the first displayed pad line to make the
* appointment panel scroll up next time pnoutrefresh is called.
*/
void
apoint_scroll_pad_up (int nb_events_inday)
void apoint_scroll_pad_up(int nb_events_inday)
{
int item_first_line = 0;
@ -563,8 +512,7 @@ apoint_scroll_pad_up (int nb_events_inday)
apad.first_onscreen = item_first_line;
}
static int
apoint_starts_after (struct apoint *apt, long time)
static int apoint_starts_after(struct apoint *apt, long time)
{
return apt->start > time;
}
@ -573,20 +521,17 @@ apoint_starts_after (struct apoint *apt, long time)
* Look in the appointment list if we have an item which starts before the item
* stored in the notify_app structure (which is the next item to be notified).
*/
struct notify_app *
apoint_check_next (struct notify_app *app, long start)
struct notify_app *apoint_check_next(struct notify_app *app, long start)
{
llist_item_t *i;
LLIST_TS_LOCK(&alist_p);
i = LLIST_TS_FIND_FIRST(&alist_p, start, apoint_starts_after);
if (i)
{
if (i) {
struct apoint *apt = LLIST_TS_GET_DATA(i);
if (apt->start <= app->time)
{
if (apt->start <= app->time) {
app->time = apt->start;
app->txt = mem_strdup(apt->mesg);
app->state = apt->state;
@ -602,8 +547,7 @@ apoint_check_next (struct notify_app *app, long start)
/*
* Switch notification state.
*/
void
apoint_switch_notify (void)
void apoint_switch_notify(void)
{
struct day_item *p;
long date;
@ -615,12 +559,10 @@ 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);
need_chk_notify = 0;
@ -638,8 +580,7 @@ apoint_switch_notify (void)
}
/* Updates the Appointment panel */
void
apoint_update_panel (int which_pan)
void apoint_update_panel(int which_pan)
{
int title_xpos;
int bordr = 1;
@ -658,8 +599,7 @@ apoint_update_panel (int which_pan)
day_write_pad(date, app_width, app_length, (which_pan == APP) ? hilt : 0);
/* Print current date in the top right window corner. */
erase_window_part (win[APP].p, 1, title_lines, win[APP].w - 2,
win[APP].h - 2);
erase_window_part(win[APP].p, 1, title_lines, win[APP].w - 2, win[APP].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]),
@ -667,8 +607,7 @@ apoint_update_panel (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);
@ -688,8 +627,7 @@ apoint_update_panel (int which_pan)
win[APP].x + win[APP].w - 3 * bordr);
}
void
apoint_paste_item (void)
void apoint_paste_item(void)
{
long bkp_time, bkp_start;

View File

@ -58,8 +58,7 @@ enum {
/*
* Print Calcurse usage and exit.
*/
static void
usage (void)
static void usage(void)
{
const char *arg_usage =
_("Usage: calcurse [-g|-h|-v] [-an] [-t[num]] [-i<file>] [-x[format]]\n"
@ -69,8 +68,7 @@ usage (void)
fputs(arg_usage, stdout);
}
static void
usage_try (void)
static void usage_try(void)
{
const char *arg_usage_try = _("Try 'calcurse -h' for more information.\n");
fputs(arg_usage_try, stdout);
@ -79,8 +77,7 @@ usage_try (void)
/*
* Print Calcurse version with a short copyright text and exit.
*/
static void
version_arg (void)
static void version_arg(void)
{
const char *vtext =
_("\nCopyright (c) 2004-2012 calcurse Development Team.\n"
@ -93,8 +90,7 @@ version_arg (void)
/*
* Print the command line options and exit.
*/
static void
help_arg (void)
static void help_arg(void)
{
const char *htext =
_("\nMiscellaneous:\n"
@ -170,8 +166,7 @@ help_arg (void)
* The status is obtained by looking at pid files in user data directory
* (.calcurse.pid and .daemon.pid).
*/
static void
status_arg (void)
static void status_arg(void)
{
int cpid, dpid;
@ -181,8 +176,7 @@ status_arg (void)
EXIT_IF(cpid && dpid,
_("Error: both calcurse (pid: %d) and its daemon (pid: %d)\n"
"seem to be running at the same time!\n"
"Please check manually and restart calcurse.\n"),
cpid, dpid);
"Please check manually and restart calcurse.\n"), cpid, dpid);
if (cpid)
fprintf(stdout, _("calcurse is running (pid %d)\n"), cpid);
@ -199,8 +193,7 @@ status_arg (void)
* If priority == 0, only completed tasks will be displayed.
* If regex is not null, only the matching todos are printed.
*/
static void
todo_arg (int priority, const char *format, regex_t *regex)
static void todo_arg(int priority, const char *format, regex_t * regex)
{
llist_item_t *i;
int title = 1;
@ -218,24 +211,18 @@ todo_arg (int priority, const char *format, regex_t *regex)
} \
} while (0)
LLIST_FOREACH (&todolist, i)
{
LLIST_FOREACH(&todolist, i) {
struct todo *todo = LLIST_TS_GET_DATA(i);
if (regex && regexec(regex, todo->mesg, 0, 0, 0) != 0)
continue;
if (todo->id < 0) /* completed task */
{
if (priority == 0)
{
if (todo->id < 0) { /* completed task */
if (priority == 0) {
DISPLAY_TITLE;
print_todo(format, todo);
}
}
else
{
if (priority < 0 || todo->id == priority)
{
} else {
if (priority < 0 || todo->id == priority) {
DISPLAY_TITLE;
print_todo(format, todo);
}
@ -246,8 +233,7 @@ todo_arg (int priority, const char *format, regex_t *regex)
}
/* Print the next appointment within the upcoming 24 hours. */
static void
next_arg (void)
static void next_arg(void)
{
struct notify_app next_app;
const long current_time = now();
@ -261,8 +247,7 @@ next_arg (void)
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;
@ -277,8 +262,7 @@ next_arg (void)
/*
* Print the date on stdout.
*/
static void
arg_print_date (long date)
static void arg_print_date(long date)
{
char date_str[BUFSIZ];
time_t t;
@ -317,40 +301,34 @@ app_arg (int add_line, struct date *day, long date, const char *fmt_apt,
* that date and it is the first one, and then print all the events for
* that date.
*/
LLIST_FIND_FOREACH (&recur_elist, today, recur_event_inday, i)
{
LLIST_FIND_FOREACH(&recur_elist, today, recur_event_inday, i) {
struct recur_event *re = LLIST_GET_DATA(i);
if (regex && regexec(regex, re->mesg, 0, 0, 0) != 0)
continue;
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);
print_date = 0;
}
print_recur_event(fmt_rev, today, re);
}
LLIST_FIND_FOREACH_CONT (&eventlist, today, event_inday, i)
{
LLIST_FIND_FOREACH_CONT(&eventlist, today, event_inday, i) {
struct event *ev = LLIST_TS_GET_DATA(i);
if (regex && regexec(regex, ev->mesg, 0, 0, 0) != 0)
continue;
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);
print_date = 0;
}
@ -367,26 +345,22 @@ app_arg (int add_line, struct date *day, long date, const char *fmt_apt,
*/
i = LLIST_TS_FIND_FIRST(&alist_p, today, apoint_inday);
j = LLIST_TS_FIND_FIRST(&recur_alist_p, today, recur_apoint_inday);
while (i || j)
{
while (i || j) {
struct apoint *apt = LLIST_TS_GET_DATA(i);
struct recur_apoint *ra = LLIST_TS_GET_DATA(j);
unsigned occurrence;
while (i && regex && regexec (regex, apt->mesg, 0, 0, 0) != 0)
{
while (i && regex && regexec(regex, apt->mesg, 0, 0, 0) != 0) {
i = LLIST_TS_FIND_NEXT(i, today, apoint_inday);
apt = LLIST_TS_GET_DATA(i);
}
while (j && regex && regexec (regex, ra->mesg, 0, 0, 0) != 0)
{
while (j && regex && regexec(regex, ra->mesg, 0, 0, 0) != 0) {
j = LLIST_TS_FIND_NEXT(j, today, recur_apoint_inday);
ra = LLIST_TS_GET_DATA(j);
}
if (apt && ra)
{
if (apt && ra) {
if (recur_apoint_find_occurrence(ra, today, &occurrence) &&
apt->start <= occurrence)
ra = NULL;
@ -394,32 +368,25 @@ app_arg (int add_line, struct date *day, long date, const char *fmt_apt,
apt = NULL;
}
if (apt)
{
if (apt) {
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);
print_date = 0;
}
print_apoint(fmt_apt, today, apt);
i = LLIST_TS_FIND_NEXT(i, today, apoint_inday);
}
else if (ra)
{
} else if (ra) {
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);
print_date = 0;
}
@ -436,8 +403,7 @@ app_arg (int add_line, struct date *day, long date, const char *fmt_apt,
return app_found;
}
static void
more_info (void)
static void more_info(void)
{
fputs(_("\nFor more information, type '?' from within Calcurse, "
"or read the manpage.\n"), stdout);
@ -458,8 +424,7 @@ display_app (struct tm *t, int numdays, int add_line, const char *fmt_apt,
int i, app_found;
struct date day;
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;
@ -493,10 +458,8 @@ date_arg (const char *ddate, int add_line, const char *fmt_apt,
* 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++;
}
@ -512,16 +475,11 @@ date_arg (const char *ddate, int add_line, const char *fmt_apt,
t = *localtime(&timer);
display_app(&t, numdays, add_line, fmt_apt, fmt_rapt, fmt_ev, fmt_rev,
regex);
}
else
{ /* a date was entered */
} else { /* a date was entered */
if (parse_date(ddate, conf.input_datefmt, (int *)&day.yyyy,
(int *)&day.mm, (int *)&day.dd, NULL))
{
(int *)&day.mm, (int *)&day.dd, NULL)) {
app_arg(add_line, &day, 0, fmt_apt, fmt_rapt, fmt_ev, fmt_rev, regex);
}
else
{
} else {
char outstr[BUFSIZ];
fputs(_("Argument to the '-d' flag is not valid\n"), stderr);
snprintf(outstr, BUFSIZ,
@ -553,11 +511,9 @@ date_arg_extended (const char *startday, const char *range, int add_line,
/*
* Check arguments and extract information
*/
if (range != NULL)
{
if (range != NULL) {
arg_len = strlen(range);
for (i = 0; i <= arg_len - 1; i++)
{
for (i = 0; i <= arg_len - 1; i++) {
if (!isdigit(range[i]))
error = 1;
}
@ -566,27 +522,20 @@ date_arg_extended (const char *startday, const char *range, int add_line,
}
timer = time(NULL);
t = *localtime(&timer);
if (startday != NULL)
{
if (startday != NULL) {
if (parse_date(startday, conf.input_datefmt, (int *)&t.tm_year,
(int *)&t.tm_mon, (int *)&t.tm_mday, NULL))
{
(int *)&t.tm_mon, (int *)&t.tm_mday, NULL)) {
t.tm_year -= 1900;
t.tm_mon--;
mktime(&t);
}
else
{
} else {
error = 1;
}
}
if (!error)
{
if (!error) {
display_app(&t, numdays, add_line, fmt_apt, fmt_rapt, fmt_ev, fmt_rev,
regex);
}
else
{
} else {
char outstr[BUFSIZ];
fputs(_("Argument is not valid\n"), stderr);
snprintf(outstr, BUFSIZ,
@ -598,13 +547,11 @@ date_arg_extended (const char *startday, const char *range, int add_line,
}
}
/*
* Parse the command-line arguments and call the appropriate
* routines to handle those arguments. Also initialize the data paths.
*/
int
parse_args (int argc, char **argv)
int parse_args(int argc, char **argv)
{
int ch, add_line = 0;
int unknown_flag = 0;
@ -637,8 +584,7 @@ parse_args (int argc, char **argv)
/* Long options only */
int statusflag = 0; /* --status: get the status of running instances */
enum
{
enum {
STATUS_OPT = CHAR_MAX + 1
};
@ -671,10 +617,8 @@ parse_args (int argc, char **argv)
{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 STATUS_OPT:
statusflag = 1;
break;
@ -729,8 +673,7 @@ parse_args (int argc, char **argv)
startday = optarg;
break;
case 'S':
EXIT_IF (Sflag > 0,
_("Can not handle more than one regular expression."));
EXIT_IF(Sflag > 0, _("Can not handle more than one regular expression."));
Sflag = 1;
if (regcomp(&reg, optarg, REG_EXTENDED))
EXIT(_("Could not compile regular expression."));
@ -741,17 +684,14 @@ parse_args (int argc, char **argv)
multiple_flag++;
load_data++;
add_line = 1;
if (optarg != NULL)
{
if (optarg != NULL) {
tnum = atoi(optarg);
if (tnum < 0 || tnum > 9)
{
if (tnum < 0 || tnum > 9) {
usage();
usage_try();
return EXIT_FAILURE;
}
}
else
} else
tnum = -1;
break;
case 'v':
@ -761,23 +701,19 @@ parse_args (int argc, char **argv)
xflag = 1;
multiple_flag++;
load_data++;
if (optarg != NULL)
{
if (optarg != NULL) {
if (strcmp(optarg, "ical") == 0)
xfmt = IO_EXPORT_ICAL;
else if (strcmp(optarg, "pcal") == 0)
xfmt = IO_EXPORT_PCAL;
else
{
else {
fputs(_("Argument for '-x' should be either "
"'ical' or 'pcal'\n"), stderr);
usage();
usage_try();
return EXIT_FAILURE;
}
}
else
{
} else {
xfmt = IO_EXPORT_ICAL;
}
break;
@ -809,53 +745,36 @@ parse_args (int argc, char **argv)
}
argc -= optind;
if (argc >= 1)
{
if (argc >= 1) {
usage();
usage_try();
return EXIT_FAILURE;
/* Incorrect arguments */
}
else if (Dflag && cflag)
{
fputs (_("Options '-D' and '-c' cannot be used at the same time\n"),
stderr);
} else if (Dflag && cflag) {
fputs(_("Options '-D' and '-c' cannot be used at the same time\n"), stderr);
usage();
usage_try();
return EXIT_FAILURE;
}
else if (Sflag && !(aflag || dflag || rflag || sflag || tflag))
{
} else if (Sflag && !(aflag || dflag || rflag || sflag || tflag)) {
fputs(_("Option '-S' must be used with either '-d', '-r', '-s', "
"'-a' or '-t'\n"), stderr);
usage();
usage_try();
return EXIT_FAILURE;
}
else
{
if (unknown_flag)
{
} 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 (statusflag)
{
} else if (statusflag) {
io_init(cfile, datadir);
status_arg();
non_interactive = 1;
}
else if (gflag)
{
} else if (gflag) {
io_init(cfile, datadir);
io_check_dir(path_dir, NULL);
io_check_dir(path_notes, NULL);
@ -865,17 +784,13 @@ parse_args (int argc, char **argv)
io_load_todo();
note_gc();
non_interactive = 1;
}
else if (multiple_flag)
{
if (load_data)
{
} else if (multiple_flag) {
if (load_data) {
io_init(cfile, datadir);
io_check_dir(path_dir, NULL);
io_check_dir(path_notes, NULL);
}
if (iflag)
{
if (iflag) {
io_check_file(path_apts, NULL);
io_check_file(path_todo, NULL);
/* Get default pager in case we need to show a log file. */
@ -887,8 +802,7 @@ parse_args (int argc, char **argv)
io_save_todo();
non_interactive = 1;
}
if (xflag)
{
if (xflag) {
io_check_file(path_apts, NULL);
io_check_file(path_todo, NULL);
io_load_app();
@ -897,36 +811,30 @@ parse_args (int argc, char **argv)
non_interactive = 1;
return non_interactive;
}
if (tflag)
{
if (tflag) {
io_check_file(path_todo, NULL);
io_load_todo();
todo_arg(tnum, fmt_todo, preg);
non_interactive = 1;
}
if (nflag)
{
if (nflag) {
io_check_file(path_apts, NULL);
io_load_app();
next_arg();
non_interactive = 1;
}
if (dflag || rflag || sflag)
{
if (dflag || rflag || sflag) {
io_check_file(path_apts, NULL);
io_check_file(path_conf, NULL);
io_load_app();
config_load(); /* To get output date format. */
if (dflag)
date_arg (ddate, add_line, fmt_apt, fmt_rapt, fmt_ev, fmt_rev,
preg);
date_arg(ddate, add_line, fmt_apt, fmt_rapt, fmt_ev, fmt_rev, preg);
if (rflag || sflag)
date_arg_extended(startday, range, add_line, fmt_apt,
fmt_rapt, fmt_ev, fmt_rev, preg);
non_interactive = 1;
}
else if (aflag)
{
} else if (aflag) {
struct date day;
io_check_file(path_apts, NULL);
@ -935,13 +843,10 @@ parse_args (int argc, char **argv)
config_load(); /* To get output date format. */
io_load_app();
day.dd = day.mm = day.yyyy = 0;
app_arg (add_line, &day, 0, fmt_apt, fmt_rapt, fmt_ev, fmt_rev,
preg);
app_arg(add_line, &day, 0, fmt_apt, fmt_rapt, fmt_ev, fmt_rev, preg);
non_interactive = 1;
}
}
else
{
} else {
non_interactive = 0;
io_init(cfile, datadir);
}

View File

@ -42,8 +42,7 @@
* Store the events and appointments for the selected day and reset the
* appointment highlight pointer if a new day was selected.
*/
static struct day_items_nb
do_storage (int day_changed)
static struct day_items_nb do_storage(int day_changed)
{
struct day_items_nb inday = *day_process_storage(calendar_get_slctd_day(),
day_changed, &inday);
@ -61,8 +60,7 @@ do_storage (int day_changed)
* and one can choose between different color schemes and layouts.
* All of the commands are documented within an online help system.
*/
int
main (int argc, char **argv)
int main(int argc, char **argv)
{
struct day_items_nb inday;
int no_data_file = 1;
@ -87,13 +85,10 @@ main (int argc, char **argv)
* Begin by parsing and handling command line arguments.
* The data path is also initialized here.
*/
if (parse_args (argc, argv))
{
if (parse_args(argc, argv)) {
/* Non-interactive mode. */
exit_calcurse(EXIT_SUCCESS);
}
else
{
} else {
no_data_file = io_check_data_files();
dmon_stop();
io_set_lock();
@ -110,16 +105,14 @@ main (int argc, char **argv)
wins_get_config();
/* Check if terminal supports color. */
if (has_colors ())
{
if (has_colors()) {
colorize = 1;
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;
}
@ -135,9 +128,7 @@ main (int argc, char **argv)
init_pair(COLR_DEFAULT, foreground, background);
init_pair(COLR_HIGH, COLOR_BLACK, COLOR_GREEN);
init_pair(COLR_CUSTOM, COLOR_RED, background);
}
else
{
} else {
colorize = 0;
background = COLOR_BLACK;
}
@ -159,8 +150,7 @@ main (int argc, char **argv)
io_load_todo();
io_load_app();
wins_reinit();
if (conf.system_dialogs)
{
if (conf.system_dialogs) {
wins_update(FLAG_ALL);
io_startup_screen(no_data_file);
}
@ -176,19 +166,16 @@ main (int argc, char **argv)
io_start_psave_thread();
/* User input */
for (;;)
{
for (;;) {
int key;
if (resize)
{
if (resize) {
resize = 0;
wins_reset();
}
key = keys_getch(win[STA].p, &count);
switch (key)
{
switch (key) {
case KEY_GENERIC_REDRAW:
resize = 1;
break;
@ -198,15 +185,13 @@ main (int argc, char **argv)
wins_slctd_next();
/* Select the event to highlight. */
switch (wins_slctd ())
{
switch (wins_slctd()) {
case TOD:
if ((todo_hilt() == 0) && (todo_nb() > 0))
todo_hilt_set(1);
break;
case APP:
if ((apoint_hilt () == 0) &&
((inday.nb_events + inday.nb_apoints) > 0))
if ((apoint_hilt() == 0) && ((inday.nb_events + inday.nb_apoints) > 0))
apoint_hilt_set(1);
break;
default:
@ -261,8 +246,7 @@ main (int argc, char **argv)
break;
case KEY_ADD_ITEM:
switch (wins_slctd ())
{
switch (wins_slctd()) {
case APP:
apoint_add();
inday = do_storage(0);
@ -280,36 +264,29 @@ main (int argc, char **argv)
break;
case KEY_EDIT_ITEM:
if (wins_slctd () == APP && apoint_hilt () != 0)
{
if (wins_slctd() == APP && apoint_hilt() != 0) {
day_edit_item();
inday = do_storage(0);
wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
}
else if (wins_slctd () == TOD && todo_hilt () != 0)
{
} else if (wins_slctd() == TOD && todo_hilt() != 0) {
todo_edit_item();
wins_update(FLAG_TOD | FLAG_STA);
}
break;
case KEY_DEL_ITEM:
if (wins_slctd () == APP && apoint_hilt () != 0)
{
if (wins_slctd() == APP && apoint_hilt() != 0) {
apoint_delete(&inday.nb_events, &inday.nb_apoints);
inday = do_storage(0);
wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
}
else if (wins_slctd () == TOD && todo_hilt () != 0)
{
} else if (wins_slctd() == TOD && todo_hilt() != 0) {
todo_delete();
wins_update(FLAG_TOD | FLAG_STA);
}
break;
case KEY_GENERIC_CUT:
if (wins_slctd () == APP && apoint_hilt () != 0)
{
if (wins_slctd() == APP && apoint_hilt() != 0) {
cut_item = apoint_cut(&inday.nb_events, &inday.nb_apoints);
inday = do_storage(0);
wins_update(FLAG_CAL | FLAG_APP);
@ -317,8 +294,7 @@ main (int argc, char **argv)
break;
case KEY_GENERIC_PASTE:
if (wins_slctd () == APP)
{
if (wins_slctd() == APP) {
apoint_paste(&inday.nb_events, &inday.nb_apoints, cut_item);
cut_item = 0;
inday = do_storage(0);
@ -334,14 +310,11 @@ main (int argc, char **argv)
break;
case KEY_FLAG_ITEM:
if (wins_slctd () == APP && apoint_hilt () != 0)
{
if (wins_slctd() == APP && apoint_hilt() != 0) {
apoint_switch_notify();
inday = do_storage(0);
wins_update(FLAG_APP);
}
else if (wins_slctd () == TOD && todo_hilt () != 0)
{
} else if (wins_slctd() == TOD && todo_hilt() != 0) {
todo_flag();
wins_update(FLAG_TOD);
}
@ -357,8 +330,7 @@ main (int argc, char **argv)
case KEY_RAISE_PRIORITY:
case KEY_LOWER_PRIORITY:
if (wins_slctd () == TOD && todo_hilt () != 0)
{
if (wins_slctd() == TOD && todo_hilt() != 0) {
todo_chg_priority(key);
if (todo_hilt_pos() < 0)
todo_set_first(todo_hilt());
@ -369,12 +341,10 @@ main (int argc, char **argv)
break;
case KEY_EDIT_NOTE:
if (wins_slctd () == APP && apoint_hilt () != 0)
{
if (wins_slctd() == APP && apoint_hilt() != 0) {
day_edit_note(conf.editor);
inday = do_storage(0);
}
else if (wins_slctd () == TOD && todo_hilt () != 0)
} else if (wins_slctd() == TOD && todo_hilt() != 0)
todo_edit_note(conf.editor);
wins_update(FLAG_ALL);
break;
@ -408,10 +378,8 @@ main (int argc, char **argv)
case KEY_GENERIC_EXPORT:
wins_erase_status_bar();
io_export_bar();
while ((key = wgetch (win[STA].p)) != 'q')
{
switch (key)
{
while ((key = wgetch(win[STA].p)) != 'q') {
switch (key) {
case 'I':
case 'i':
io_export_data(IO_EXPORT_ICAL);
@ -432,8 +400,7 @@ main (int argc, char **argv)
case KEY_GENERIC_NEXT_DAY:
case KEY_MOVE_RIGHT:
if (wins_slctd () == CAL || key == KEY_GENERIC_NEXT_DAY)
{
if (wins_slctd() == CAL || key == KEY_GENERIC_NEXT_DAY) {
calendar_move(RIGHT, count);
inday = do_storage(1);
wins_update(FLAG_CAL | FLAG_APP);
@ -442,8 +409,7 @@ main (int argc, char **argv)
case KEY_GENERIC_PREV_DAY:
case KEY_MOVE_LEFT:
if (wins_slctd () == CAL || key == KEY_GENERIC_PREV_DAY)
{
if (wins_slctd() == CAL || key == KEY_GENERIC_PREV_DAY) {
calendar_move(LEFT, count);
inday = do_storage(1);
wins_update(FLAG_CAL | FLAG_APP);
@ -452,22 +418,17 @@ main (int argc, char **argv)
case KEY_GENERIC_PREV_WEEK:
case KEY_MOVE_UP:
if (wins_slctd () == CAL || key == KEY_GENERIC_PREV_WEEK)
{
if (wins_slctd() == CAL || key == KEY_GENERIC_PREV_WEEK) {
calendar_move(UP, count);
inday = do_storage(1);
wins_update(FLAG_CAL | FLAG_APP);
}
else if (wins_slctd () == APP)
{
} else if (wins_slctd() == APP) {
if (count >= apoint_hilt())
count = apoint_hilt() - 1;
apoint_hilt_decrease(count);
apoint_scroll_pad_up(inday.nb_events);
wins_update(FLAG_APP);
}
else if (wins_slctd () == TOD)
{
} else if (wins_slctd() == TOD) {
if (count >= todo_hilt())
count = todo_hilt() - 1;
todo_hilt_decrease(count);
@ -479,22 +440,17 @@ main (int argc, char **argv)
case KEY_GENERIC_NEXT_WEEK:
case KEY_MOVE_DOWN:
if (wins_slctd () == CAL || key == KEY_GENERIC_NEXT_WEEK)
{
if (wins_slctd() == CAL || key == KEY_GENERIC_NEXT_WEEK) {
calendar_move(DOWN, count);
inday = do_storage(1);
wins_update(FLAG_CAL | FLAG_APP);
}
else if (wins_slctd () == APP)
{
} else if (wins_slctd() == APP) {
if (count > inday.nb_events + inday.nb_apoints - apoint_hilt())
count = inday.nb_events + inday.nb_apoints - apoint_hilt();
apoint_hilt_increase(count);
apoint_scroll_pad_down(inday.nb_events, win[APP].h);
wins_update(FLAG_APP);
}
else if (wins_slctd () == TOD)
{
} else if (wins_slctd() == TOD) {
if (count > todo_nb() - todo_hilt())
count = todo_nb() - todo_hilt();
todo_hilt_increase(count);
@ -505,8 +461,7 @@ main (int argc, char **argv)
break;
case KEY_START_OF_WEEK:
if (wins_slctd () == CAL)
{
if (wins_slctd() == CAL) {
calendar_move(WEEK_START, count);
inday = do_storage(1);
wins_update(FLAG_CAL | FLAG_APP);
@ -514,8 +469,7 @@ main (int argc, char **argv)
break;
case KEY_END_OF_WEEK:
if (wins_slctd () == CAL)
{
if (wins_slctd() == CAL) {
calendar_move(WEEK_END, count);
inday = do_storage(1);
wins_update(FLAG_CAL | FLAG_APP);
@ -523,16 +477,14 @@ main (int argc, char **argv)
break;
case KEY_GENERIC_SCROLL_UP:
if (wins_slctd () == CAL)
{
if (wins_slctd() == CAL) {
calendar_view_prev();
wins_update(FLAG_CAL | FLAG_APP);
}
break;
case KEY_GENERIC_SCROLL_DOWN:
if (wins_slctd () == CAL)
{
if (wins_slctd() == CAL) {
calendar_view_next();
wins_update(FLAG_CAL | FLAG_APP);
}
@ -544,18 +496,15 @@ main (int argc, char **argv)
if (conf.auto_gc)
note_gc();
if (conf.confirm_quit)
{
if (conf.confirm_quit) {
if (status_ask_bool(_("Do you really want to quit ?")) == 1)
exit_calcurse(EXIT_SUCCESS);
else
{
else {
wins_erase_status_bar();
wins_update(FLAG_STA);
break;
}
}
else
} else
exit_calcurse(EXIT_SUCCESS);
break;

View File

@ -270,8 +270,7 @@ struct date {
};
/* Appointment definition. */
struct apoint
{
struct apoint {
long start; /* seconds since 1 jan 1970 */
long dur; /* duration of the appointment in seconds */
@ -826,25 +825,19 @@ struct recur_apoint *recur_apoint_scan (FILE *, struct tm, struct tm,
char, int, struct tm, char *,
llist_t *, char);
struct recur_event *recur_event_scan(FILE *, struct tm, int, char,
int, struct tm, char *,
llist_t *);
int, struct tm, char *, llist_t *);
void recur_apoint_write(struct recur_apoint *, FILE *);
void recur_event_write(struct recur_event *, FILE *);
void recur_save_data(FILE *);
unsigned recur_item_find_occurrence(long, long, llist_t *, int,
int, long, long, unsigned *);
unsigned recur_apoint_find_occurrence (struct recur_apoint *,
long, unsigned *);
unsigned recur_event_find_occurrence (struct recur_event *, long,
unsigned *);
unsigned recur_item_inday (long, long, llist_t *, int, int, long,
long);
unsigned recur_apoint_find_occurrence(struct recur_apoint *, long, unsigned *);
unsigned recur_event_find_occurrence(struct recur_event *, long, unsigned *);
unsigned recur_item_inday(long, long, llist_t *, int, int, long, long);
unsigned recur_apoint_inday(struct recur_apoint *, long);
unsigned recur_event_inday(struct recur_event *, long);
void recur_event_erase (long, unsigned, unsigned,
enum eraseflg);
void recur_apoint_erase (long, unsigned, unsigned,
enum eraseflg);
void recur_event_erase(long, unsigned, unsigned, enum eraseflg);
void recur_apoint_erase(long, unsigned, unsigned, enum eraseflg);
void recur_repeat_item(void);
void recur_exc_scan(llist_t *, FILE *);
struct notify_app *recur_apoint_check_next(struct notify_app *, long, long);
@ -913,8 +906,7 @@ long update_time_in_date (long, unsigned, unsigned);
long get_sec_date(struct date);
long min2sec(unsigned);
void draw_scrollbar(WINDOW *, int, int, int, int, int, unsigned);
void item_in_popup (const char *, const char *, const char *,
const char *);
void item_in_popup(const char *, const char *, const char *, const char *);
long get_today(void);
long now(void);
char *nowstr(void);
@ -922,8 +914,7 @@ long mystrtol (const char *);
void print_bool_option_incolor(WINDOW *, unsigned, int, int);
const char *get_tempdir(void);
char *new_tempfile(const char *, int);
int parse_date (const char *, enum datefmt, int *, int *, int *,
struct date *);
int parse_date(const char *, enum datefmt, int *, int *, int *, struct date *);
int parse_time(const char *, unsigned *, unsigned *);
int parse_duration(const char *, unsigned *);
void str_toupper(char *);
@ -935,8 +926,7 @@ int child_wait (int *, int *, int);
void press_any_key(void);
void print_apoint(const char *, long, struct apoint *);
void print_event(const char *, long, struct event *);
void print_recur_apoint (const char *, long, unsigned,
struct recur_apoint *);
void print_recur_apoint(const char *, long, unsigned, struct recur_apoint *);
void print_recur_event(const char *, long, struct recur_event *);
void print_todo(const char *, struct todo *);

View File

@ -80,47 +80,41 @@ static pthread_t calendar_t_date;
static void draw_monthly_view(struct window *, struct date *, unsigned);
static void draw_weekly_view(struct window *, struct date *, unsigned);
static void (*draw_calendar[CAL_VIEWS]) (struct window *, struct date *,
unsigned) =
{draw_monthly_view, draw_weekly_view};
unsigned) = {
draw_monthly_view, draw_weekly_view};
/* Switch between calendar views (monthly view is selected by default). */
void
calendar_view_next (void)
void calendar_view_next(void)
{
calendar_view++;
if (calendar_view == CAL_VIEWS)
calendar_view = 0;
}
void
calendar_view_prev (void)
void calendar_view_prev(void)
{
if (calendar_view == 0)
calendar_view = CAL_VIEWS;
calendar_view--;
}
void
calendar_set_view (int view)
void calendar_set_view(int view)
{
calendar_view = (view < 0 || view >= CAL_VIEWS) ? CAL_MONTH_VIEW : view;
}
int
calendar_get_view (void)
int calendar_get_view(void)
{
return (int)calendar_view;
}
/* Thread needed to update current date in calendar. */
/* ARGSUSED0 */
static void *
calendar_date_thread (void *arg)
static void *calendar_date_thread(void *arg)
{
time_t actual, tomorrow;
for (;;)
{
for (;;) {
tomorrow = (time_t) (get_today() + DAYINSEC);
while ((actual = time(NULL)) < tomorrow)
@ -134,26 +128,22 @@ calendar_date_thread (void *arg)
}
/* Launch the calendar date thread. */
void
calendar_start_date_thread (void)
void calendar_start_date_thread(void)
{
pthread_create(&calendar_t_date, NULL, calendar_date_thread, NULL);
}
/* Stop the calendar date thread. */
void
calendar_stop_date_thread (void)
{
if (calendar_t_date)
void calendar_stop_date_thread(void)
{
if (calendar_t_date) {
pthread_cancel(calendar_t_date);
pthread_join(calendar_t_date, NULL);
}
}
/* Set static variable today to current date */
void
calendar_set_current_date (void)
void calendar_set_current_date(void)
{
time_t timer;
struct tm *tm;
@ -169,11 +159,9 @@ calendar_set_current_date (void)
}
/* Needed to display sunday or monday as the first day of week in calendar. */
void
calendar_set_first_day_of_week (enum wday first_day)
{
switch (first_day)
void calendar_set_first_day_of_week(enum wday first_day)
{
switch (first_day) {
case SUNDAY:
week_begins_on_monday = 0;
break;
@ -188,22 +176,19 @@ calendar_set_first_day_of_week (enum wday first_day)
}
/* Swap first day of week in calendar. */
void
calendar_change_first_day_of_week (void)
void calendar_change_first_day_of_week(void)
{
week_begins_on_monday = !week_begins_on_monday;
}
/* Return 1 if week begins on monday, 0 otherwise. */
unsigned
calendar_week_begins_on_monday (void)
unsigned calendar_week_begins_on_monday(void)
{
return week_begins_on_monday;
}
/* Fill in the given variable with the current date. */
void
calendar_store_current_date (struct date *date)
void calendar_store_current_date(struct date *date)
{
pthread_mutex_lock(&date_thread_mutex);
*date = today;
@ -211,28 +196,24 @@ calendar_store_current_date (struct date *date)
}
/* This is to start at the current date in calendar. */
void
calendar_init_slctd_day (void)
void calendar_init_slctd_day(void)
{
calendar_store_current_date(&slctd_day);
}
/* Return the selected day in calendar */
struct date *
calendar_get_slctd_day (void)
struct date *calendar_get_slctd_day(void)
{
return &slctd_day;
}
/* Returned value represents the selected day in calendar (in seconds) */
long
calendar_get_slctd_day_sec (void)
long calendar_get_slctd_day_sec(void)
{
return date2sec(slctd_day, 0, 0);
}
static int
calendar_get_wday (struct date *date)
static int calendar_get_wday(struct date *date)
{
struct tm t;
@ -246,21 +227,17 @@ calendar_get_wday (struct date *date)
return t.tm_wday;
}
static unsigned
months_to_days (unsigned month)
static unsigned months_to_days(unsigned month)
{
return (month * 3057 - 3007) / 100;
}
static long
years_to_days (unsigned year)
static long years_to_days(unsigned year)
{
return year * 365L + year / 4 - year / 100 + year / 400;
}
static long
ymd_to_scalar (unsigned year, unsigned month, unsigned day)
static long ymd_to_scalar(unsigned year, unsigned month, unsigned day)
{
long scalar;
@ -277,8 +254,7 @@ ymd_to_scalar (unsigned year, unsigned month, unsigned day)
* Used to change date by adding a certain amount of days or weeks.
* Returns 0 on success, 1 otherwise.
*/
static int
date_change (struct tm *date, int delta_month, int delta_day)
static int date_change(struct tm *date, int delta_month, int delta_day)
{
struct tm t;
@ -288,8 +264,7 @@ date_change (struct tm *date, int delta_month, int delta_day)
if (mktime(&t) == -1)
return 1;
else
{
else {
*date = t;
return 0;
}
@ -337,8 +312,7 @@ draw_monthly_view (struct window *cwin, struct date *current_day,
/* print the days, with regards to the first day of the week */
custom_apply_attr(cwin->p, ATTR_HIGHEST);
for (j = 0; j < WEEKINDAYS; j++)
{
for (j = 0; j < WEEKINDAYS; j++) {
mvwprintw(cwin->p, ofs_y, ofs_x + 4 * j, "%s",
_(daynames[1 + j - sunday_first]));
}
@ -346,8 +320,7 @@ draw_monthly_view (struct window *cwin, struct date *current_day,
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;
@ -356,8 +329,7 @@ draw_monthly_view (struct window *cwin, struct date *current_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 = OFFX - day_1_sav - 4 * c_day;
}
@ -366,46 +338,35 @@ draw_monthly_view (struct window *cwin, struct date *current_day,
if (c_day == current_day->dd
&& current_day->mm == slctd_day.mm
&& current_day->yyyy == slctd_day.yyyy
&& current_day->dd != slctd_day.dd)
{
&& current_day->dd != slctd_day.dd) {
custom_apply_attr(cwin->p, ATTR_LOWEST);
mvwprintw(cwin->p, ofs_y + 1,
ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day);
custom_remove_attr(cwin->p, ATTR_LOWEST);
}
else if (c_day == slctd_day.dd)
{
} else if (c_day == slctd_day.dd) {
/* This is the selected day, print it according to user's theme. */
custom_apply_attr(cwin->p, ATTR_HIGHEST);
mvwprintw(cwin->p, ofs_y + 1,
ofs_x + day_1_sav + 4 * c_day + 1, "%2d",
c_day);
ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day);
custom_remove_attr(cwin->p, ATTR_HIGHEST);
}
else if (item_this_day)
{
} else if (item_this_day) {
custom_apply_attr(cwin->p, ATTR_LOW);
mvwprintw(cwin->p, ofs_y + 1,
ofs_x + day_1_sav + 4 * c_day + 1, "%2d",
c_day);
ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day);
custom_remove_attr(cwin->p, ATTR_LOW);
}
else
} else
/* otherwise, print normal days in black */
mvwprintw(cwin->p, ofs_y + 1,
ofs_x + day_1_sav + 4 * c_day + 1, "%2d",
c_day);
ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day);
}
}
static int
weeknum (const struct tm *t, int firstweekday)
static int weeknum(const struct tm *t, int firstweekday)
{
int wday, wnum;
wday = t->tm_wday;
if (firstweekday == MONDAY)
{
if (firstweekday == MONDAY) {
if (wday == SUNDAY)
wday = 6;
else
@ -421,8 +382,7 @@ weeknum (const struct tm *t, int firstweekday)
/*
* Compute the week number according to ISO 8601.
*/
static int
ISO8601weeknum (const struct tm *t)
static int ISO8601weeknum(const struct tm *t)
{
int wnum, jan1day;
@ -432,8 +392,7 @@ ISO8601weeknum (const struct tm *t)
if (jan1day < 0)
jan1day += WEEKINDAYS;
switch (jan1day)
{
switch (jan1day) {
case MONDAY:
break;
case TUESDAY:
@ -444,8 +403,7 @@ ISO8601weeknum (const struct tm *t)
case FRIDAY:
case SATURDAY:
case SUNDAY:
if (wnum == 0)
{
if (wnum == 0) {
/* Get week number of last week of last year. */
struct tm dec31ly; /* 12/31 last year */
@ -460,8 +418,7 @@ ISO8601weeknum (const struct tm *t)
break;
}
if (t->tm_mon == 11)
{
if (t->tm_mon == 11) {
int wday, mday;
wday = t->tm_wday;
@ -509,8 +466,7 @@ draw_weekly_view (struct window *cwin, struct date *current_day,
custom_remove_attr(cwin->p, ATTR_HIGHEST);
/* Now draw calendar view. */
for (j = 0; j < WEEKINDAYS; j++)
{
for (j = 0; j < WEEKINDAYS; j++) {
struct date date;
unsigned attr, item_this_day;
int i, slices[DAYSLICESNO];
@ -548,14 +504,11 @@ draw_weekly_view (struct window *cwin, struct date *current_day,
/* Draw slices indicating appointment times. */
memset(slices, 0, DAYSLICESNO * sizeof *slices);
if (day_chk_busy_slices (date, DAYSLICESNO, slices))
{
for (i = 0; i < DAYSLICESNO; i++)
{
if (day_chk_busy_slices(date, DAYSLICESNO, slices)) {
for (i = 0; i < DAYSLICESNO; i++) {
if (j != WEEKINDAYS - 1 && i != DAYSLICESNO - 1)
mvwhline(cwin->p, OFFY + 2 + i, OFFX + 3 + 4 * j, ACS_S9, 2);
if (slices[i])
{
if (slices[i]) {
int highlight;
highlight = (t.tm_mday == slctd_day.dd) ? 1 : 0;
@ -586,8 +539,7 @@ draw_weekly_view (struct window *cwin, struct date *current_day,
}
/* Function used to display the calendar panel. */
void
calendar_update_panel (struct window *cwin)
void calendar_update_panel(struct window *cwin)
{
struct date current_day;
unsigned sunday_first;
@ -603,8 +555,7 @@ calendar_update_panel (struct window *cwin)
}
/* Set the selected day in calendar to current day. */
void
calendar_goto_today (void)
void calendar_goto_today(void)
{
struct date today;
@ -620,8 +571,7 @@ calendar_goto_today (void)
* If the entered date is empty, automatically jump to the current date.
* slctd_day is updated with the newly selected date.
*/
void
calendar_change_day (int datefmt)
void calendar_change_day(int datefmt)
{
#define LDAY 11
char selected_day[LDAY] = "";
@ -634,30 +584,24 @@ calendar_change_day (int datefmt)
const char *mesg_line2 = _("Press [ENTER] to continue");
const char *request_date = "Enter the day to go to [ENTER for today] : %s";
while (wrong_day)
{
while (wrong_day) {
snprintf(outstr, BUFSIZ, request_date, DATEFMT_DESC(datefmt));
status_mesg(_(outstr), "");
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) {
wrong_day = 0;
calendar_goto_today();
}
else if (parse_date (selected_day, datefmt, &dyear, &dmonth, &dday,
calendar_get_slctd_day ()))
{
} else if (parse_date(selected_day, datefmt, &dyear, &dmonth, &dday,
calendar_get_slctd_day())) {
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);
}
@ -667,8 +611,7 @@ calendar_change_day (int datefmt)
return;
}
void
calendar_move (enum move move, int count)
void calendar_move(enum move move, int count)
{
int ret, days_to_remove, days_to_add;
struct tm t;
@ -678,8 +621,7 @@ calendar_move (enum move move, int count)
t.tm_mon = slctd_day.mm - 1;
t.tm_year = slctd_day.yyyy - 1900;
switch (move)
{
switch (move) {
case UP:
ret = date_change(&t, 0, -count * WEEKINDAYS);
break;
@ -717,16 +659,12 @@ calendar_move (enum move move, int count)
/* NOTREACHED */
}
if (ret == 0)
{
if (t.tm_year < 2)
{
if (ret == 0) {
if (t.tm_year < 2) {
t.tm_mday = 1;
t.tm_mon = 0;
t.tm_year = 2;
}
else if (t.tm_year > 137)
{
} else if (t.tm_year > 137) {
t.tm_mday = 31;
t.tm_mon = 11;
t.tm_year = 137;
@ -739,8 +677,7 @@ calendar_move (enum move move, int count)
}
/* Returns the beginning of current year as a long. */
long
calendar_start_of_year (void)
long calendar_start_of_year(void)
{
time_t timer;
struct tm *tm;
@ -757,8 +694,7 @@ calendar_start_of_year (void)
return (long)timer;
}
long
calendar_end_of_year (void)
long calendar_end_of_year(void)
{
time_t timer;
struct tm *tm;
@ -817,8 +753,7 @@ calendar_end_of_year (void)
* dtor --
* convert degrees to radians
*/
static double
dtor (double deg)
static double dtor(double deg)
{
return deg * M_PI / 180;
}
@ -827,8 +762,7 @@ dtor (double deg)
* adj360 --
* adjust value so 0 <= deg <= 360
*/
static void
adj360 (double *deg)
static void adj360(double *deg)
{
for (;;)
if (*deg < 0.0)
@ -843,8 +777,7 @@ adj360 (double *deg)
* potm --
* return phase of the moon
*/
static double
potm (double days)
static double potm(double days)
{
double N, Msol, Ec, LambdaSol, l, Mm, Ev, Ac, A3, Mmprime;
double A4, lprime, V, ldprime, D, Nm;
@ -886,8 +819,7 @@ potm (double days)
* Updated to the Third Edition of Duffett-Smith's book, IX 1998
*
*/
static double
pom (time_t tmpt)
static double pom(time_t tmpt)
{
struct tm *GMT;
double days;
@ -910,8 +842,7 @@ pom (time_t tmpt)
* Careful: date is the selected day in calendar at 00:00, so it represents
* the phase of the moon for previous day.
*/
const char *
calendar_get_pom (time_t date)
const char *calendar_get_pom(time_t date)
{
const char *pom_pict[MOON_PHASES] = { " ", "|) ", "(|)", "(| ", " | " };
enum pom phase = NO_POM;

View File

@ -82,22 +82,28 @@ static int config_serialize_input_datefmt (char *, void *);
(config_fn_serialize_t) config_serialize_str, &(var)
static const struct confvar confmap[] = {
{ "appearance.calendarview", config_parse_calendar_view, config_serialize_calendar_view, NULL },
{"appearance.calendarview", config_parse_calendar_view,
config_serialize_calendar_view, NULL},
{"appearance.layout", config_parse_layout, config_serialize_layout, NULL},
{"appearance.notifybar", CONFIG_HANDLER_BOOL(nbar.show)},
{ "appearance.sidebarwidth", config_parse_sidebar_width, config_serialize_sidebar_width, NULL },
{ "appearance.theme", config_parse_color_theme, config_serialize_color_theme, NULL },
{"appearance.sidebarwidth", config_parse_sidebar_width,
config_serialize_sidebar_width, NULL},
{"appearance.theme", config_parse_color_theme, config_serialize_color_theme,
NULL},
{"daemon.enable", CONFIG_HANDLER_BOOL(dmon.enable)},
{"daemon.log", CONFIG_HANDLER_BOOL(dmon.log)},
{ "format.inputdate", config_parse_input_datefmt, config_serialize_input_datefmt, NULL },
{"format.inputdate", config_parse_input_datefmt,
config_serialize_input_datefmt, NULL},
{"format.notifydate", CONFIG_HANDLER_STR(nbar.datefmt)},
{"format.notifytime", CONFIG_HANDLER_STR(nbar.timefmt)},
{ "format.outputdate", config_parse_output_datefmt, config_serialize_output_datefmt, NULL },
{"format.outputdate", config_parse_output_datefmt,
config_serialize_output_datefmt, NULL},
{"general.autogc", CONFIG_HANDLER_BOOL(conf.auto_gc)},
{"general.autosave", CONFIG_HANDLER_BOOL(conf.auto_save)},
{"general.confirmdelete", CONFIG_HANDLER_BOOL(conf.confirm_delete)},
{"general.confirmquit", CONFIG_HANDLER_BOOL(conf.confirm_quit)},
{ "general.firstdayofweek", config_parse_first_day_of_week, config_serialize_first_day_of_week, NULL },
{"general.firstdayofweek", config_parse_first_day_of_week,
config_serialize_first_day_of_week, NULL},
{"general.periodicsave", CONFIG_HANDLER_UNSIGNED(conf.periodic_save)},
{"general.progressbar", CONFIG_HANDLER_BOOL(conf.progress_bar)},
{"general.systemdialogs", CONFIG_HANDLER_BOOL(conf.system_dialogs)},
@ -114,8 +120,7 @@ struct config_save_status {
typedef int (*config_fn_walk_cb_t) (const char *, const char *, void *);
typedef int (*config_fn_walk_junk_cb_t) (const char *, void *);
static int
config_parse_bool (unsigned *dest, const char *val)
static int config_parse_bool(unsigned *dest, const char *val)
{
if (strcmp(val, "yes") == 0)
*dest = 1;
@ -127,8 +132,7 @@ config_parse_bool (unsigned *dest, const char *val)
return 1;
}
static int
config_parse_unsigned (unsigned *dest, const char *val)
static int config_parse_unsigned(unsigned *dest, const char *val)
{
if (is_all_digit(val))
*dest = atoi(val);
@ -138,8 +142,7 @@ config_parse_unsigned (unsigned *dest, const char *val)
return 1;
}
static int
config_parse_int (int *dest, const char *val)
static int config_parse_int(int *dest, const char *val)
{
if ((*val == '+' || *val == '-' || isdigit(*val)) && is_all_digit(val + 1))
*dest = atoi(val);
@ -149,15 +152,13 @@ config_parse_int (int *dest, const char *val)
return 1;
}
static int
config_parse_str (char *dest, const char *val)
static int config_parse_str(char *dest, const char *val)
{
strncpy(dest, val, BUFSIZ);
return 1;
}
static int
config_parse_color (int *dest, const char *val)
static int config_parse_color(int *dest, const char *val)
{
if (!strcmp(val, "black"))
*dest = COLOR_BLACK;
@ -183,8 +184,7 @@ config_parse_color (int *dest, const char *val)
return 1;
}
static int
config_parse_color_pair (int *dest1, int *dest2, const char *val)
static int config_parse_color_pair(int *dest1, int *dest2, const char *val)
{
char s1[BUFSIZ], s2[BUFSIZ];
@ -194,15 +194,13 @@ config_parse_color_pair (int *dest1, int *dest2, const char *val)
return (config_parse_color(dest1, s1) && config_parse_color(dest2, s2));
}
static int
config_parse_calendar_view (void *dummy, const char *val)
static int config_parse_calendar_view(void *dummy, const char *val)
{
calendar_set_view(atoi(val));
return 1;
}
static int
config_parse_first_day_of_week (void *dummy, const char *val)
static int config_parse_first_day_of_week(void *dummy, const char *val)
{
if (!strcmp(val, "monday"))
calendar_set_first_day_of_week(MONDAY);
@ -214,8 +212,7 @@ config_parse_first_day_of_week (void *dummy, const char *val)
return 1;
}
static int
config_parse_color_theme (void *dummy, const char *val)
static int config_parse_color_theme(void *dummy, const char *val)
{
int color1, color2;
if (!config_parse_color_pair(&color1, &color2, val))
@ -224,51 +221,44 @@ config_parse_color_theme (void *dummy, const char *val)
return 1;
}
static int
config_parse_layout (void *dummy, const char *val)
static int config_parse_layout(void *dummy, const char *val)
{
wins_set_layout(atoi(val));
return 1;
}
static int
config_parse_sidebar_width (void *dummy, const char *val)
static int config_parse_sidebar_width(void *dummy, const char *val)
{
wins_set_sbar_width(atoi(val));
return 1;
}
static int
config_parse_output_datefmt (void *dummy, const char *val)
static int config_parse_output_datefmt(void *dummy, const char *val)
{
if (val[0] != '\0')
return config_parse_str(conf.output_datefmt, val);
return 1;
}
static int
config_parse_input_datefmt (void *dummy, const char *val)
static int config_parse_input_datefmt(void *dummy, const char *val)
{
if (config_parse_int(&conf.input_datefmt, val)) {
if (conf.input_datefmt <= 0 || conf.input_datefmt >= DATE_FORMATS)
conf.input_datefmt = 1;
return 1;
}
else
} else
return 0;
}
/* Set a configuration variable. */
static int
config_set_conf (const char *key, const char *value)
static int config_set_conf(const char *key, const char *value)
{
int i;
if (!key)
return -1;
for (i = 0; i < sizeof (confmap) / sizeof (confmap[0]); i++)
{
for (i = 0; i < sizeof(confmap) / sizeof(confmap[0]); i++) {
if (!strcmp(confmap[i].key, key))
return confmap[i].fn_parse(confmap[i].target, value);
}
@ -276,18 +266,14 @@ config_set_conf (const char *key, const char *value)
return -1;
}
static int
config_serialize_bool (char *dest, unsigned *val)
{
if (*val)
static int config_serialize_bool(char *dest, unsigned *val)
{
if (*val) {
dest[0] = 'y';
dest[1] = 'e';
dest[2] = 's';
dest[3] = '\0';
}
else
{
} else {
dest[0] = 'n';
dest[1] = 'o';
dest[2] = '\0';
@ -296,22 +282,19 @@ config_serialize_bool (char *dest, unsigned *val)
return 1;
}
static int
config_serialize_unsigned (char *dest, unsigned *val)
static int config_serialize_unsigned(char *dest, unsigned *val)
{
snprintf(dest, BUFSIZ, "%u", *val);
return 1;
}
static int
config_serialize_int (char *dest, int *val)
static int config_serialize_int(char *dest, int *val)
{
snprintf(dest, BUFSIZ, "%d", *val);
return 1;
}
static int
config_serialize_str (char *dest, const char *val)
static int config_serialize_str(char *dest, const char *val)
{
strncpy(dest, val, BUFSIZ);
return 1;
@ -325,8 +308,7 @@ config_serialize_str (char *dest, const char *val)
* If ncurses library was compiled with --enable-ext-funcs,
* then default color is -1.
*/
static void
config_color_theme_name (char *theme_name)
static void config_color_theme_name(char *theme_name)
{
#define MAXCOLORS 8
#define NBCOLORS 2
@ -350,17 +332,14 @@ config_color_theme_name (char *theme_name)
if (!colorize)
strncpy(theme_name, "0", BUFSIZ);
else
{
else {
pair_content(COLR_CUSTOM, &color[0], &color[1]);
for (i = 0; i < NBCOLORS; i++)
{
for (i = 0; i < NBCOLORS; i++) {
if ((color[i] == DEFAULTCOLOR) || (color[i] == DEFAULTCOLOR_EXT))
color_name[i] = default_color;
else if (color[i] >= 0 && color[i] <= MAXCOLORS)
color_name[i] = name[color[i]];
else
{
else {
EXIT(_("unknown color"));
/* NOTREACHED */
}
@ -369,15 +348,13 @@ config_color_theme_name (char *theme_name)
}
}
static int
config_serialize_calendar_view (char *buf, void *dummy)
static int config_serialize_calendar_view(char *buf, void *dummy)
{
int tmp = calendar_get_view();
return config_serialize_int(buf, &tmp);
}
static int
config_serialize_first_day_of_week (char *buf, void *dummy)
static int config_serialize_first_day_of_week(char *buf, void *dummy)
{
if (calendar_week_begins_on_monday())
strcpy(buf, "monday");
@ -387,35 +364,30 @@ config_serialize_first_day_of_week (char *buf, void *dummy)
return 1;
}
static int
config_serialize_color_theme (char *buf, void *dummy)
static int config_serialize_color_theme(char *buf, void *dummy)
{
config_color_theme_name(buf);
return 1;
}
static int
config_serialize_layout (char *buf, void *dummy)
static int config_serialize_layout(char *buf, void *dummy)
{
int tmp = wins_layout();
return config_serialize_int(buf, &tmp);
}
static int
config_serialize_sidebar_width (char *buf, void *dummy)
static int config_serialize_sidebar_width(char *buf, void *dummy)
{
int tmp = wins_sbar_wperc();
return config_serialize_int(buf, &tmp);
}
static int
config_serialize_output_datefmt (char *buf, void *dummy)
static int config_serialize_output_datefmt(char *buf, void *dummy)
{
return config_serialize_str(buf, conf.output_datefmt);
}
static int
config_serialize_input_datefmt (char *buf, void *dummy)
static int config_serialize_input_datefmt(char *buf, void *dummy)
{
return config_serialize_int(buf, &conf.input_datefmt);
}
@ -430,17 +402,13 @@ config_serialize_conf (char *buf, const char *key,
if (!key)
return -1;
for (i = 0; i < sizeof (confmap) / sizeof (confmap[0]); i++)
{
if (!strcmp (confmap[i].key, key))
{
if (confmap[i].fn_serialize (buf, confmap[i].target))
{
for (i = 0; i < sizeof(confmap) / sizeof(confmap[0]); i++) {
if (!strcmp(confmap[i].key, key)) {
if (confmap[i].fn_serialize(buf, confmap[i].target)) {
if (status)
status->done[i] = 1;
return 1;
}
else
} else
return 0;
}
}
@ -460,14 +428,12 @@ config_file_walk (config_fn_walk_cb_t fn_cb,
EXIT_IF(data_file == NULL, _("failed to open configuration file"));
pthread_mutex_lock(&nbar.mutex);
for (;;)
{
for (;;) {
if (fgets(buf, sizeof buf, data_file) == NULL)
break;
io_extract_data(e_conf, buf, sizeof buf);
if (*e_conf == '\0')
{
if (*e_conf == '\0') {
if (fn_junk_cb)
fn_junk_cb(buf, data);
continue;
@ -475,8 +441,7 @@ config_file_walk (config_fn_walk_cb_t fn_cb,
key = e_conf;
value = strchr(e_conf, '=');
if (value)
{
if (value) {
*value = '\0';
value++;
}
@ -502,14 +467,12 @@ config_file_walk (config_fn_walk_cb_t fn_cb,
strcmp(key, "output_datefmt") == 0 ||
strcmp(key, "input_datefmt") == 0 ||
strcmp(key, "notify-daemon_enable") == 0 ||
strcmp(key, "notify-daemon_log") == 0)
{
strcmp(key, "notify-daemon_log") == 0) {
WARN_MSG(_("Pre-3.0.0 configuration file format detected, "
"please upgrade running `calcurse-upgrade`."));
}
if (value && (*value == '\0' || *value == '\n'))
{
if (value && (*value == '\0' || *value == '\n')) {
/* Backward compatibility mode. */
if (fgets(buf, sizeof buf, data_file) == NULL)
break;
@ -523,8 +486,7 @@ config_file_walk (config_fn_walk_cb_t fn_cb,
pthread_mutex_unlock(&nbar.mutex);
}
static int
config_load_cb (const char *key, const char *value, void *dummy)
static int config_load_cb(const char *key, const char *value, void *dummy)
{
int result = config_set_conf(key, value);
@ -539,17 +501,16 @@ config_load_cb (const char *key, const char *value, void *dummy)
}
/* Load the user configuration. */
void
config_load (void)
void config_load(void)
{
config_file_walk(config_load_cb, NULL, NULL);
}
static int
config_save_cb (const char *key, const char *value, void *status)
static int config_save_cb(const char *key, const char *value, void *status)
{
char buf[BUFSIZ];
int result = config_serialize_conf (buf, key, (struct config_save_status *) status);
int result =
config_serialize_conf(buf, key, (struct config_save_status *)status);
if (result < 0)
EXIT(_("configuration variable unknown: \"%s\""), key);
@ -566,16 +527,14 @@ config_save_cb (const char *key, const char *value, void *status)
return 1;
}
static int
config_save_junk_cb (const char *data, void *status)
static int config_save_junk_cb(const char *data, void *status)
{
fputs(data, ((struct config_save_status *)status)->fp);
return 1;
}
/* Save the user configuration. */
unsigned
config_save (void)
unsigned config_save(void)
{
char tmppath[BUFSIZ];
char *tmpext;
@ -601,8 +560,7 @@ config_save (void)
config_file_walk(config_save_cb, config_save_junk_cb, (void *)&status);
/* Set variables that were missing from the configuration file. */
for (i = 0; i < sizeof (confmap) / sizeof (confmap[0]); i++)
{
for (i = 0; i < sizeof(confmap) / sizeof(confmap[0]); i++) {
if (!status.done[i])
config_save_cb(confmap[i].key, NULL, &status);
}

View File

@ -56,8 +56,7 @@ static struct attribute attr;
* ATTR_LOW are for days inside calendar panel which contains an event
* ATTR_LOWEST are for current day inside calendar panel
*/
void
custom_init_attr (void)
void custom_init_attr(void)
{
attr.color[ATTR_HIGHEST] = COLOR_PAIR(COLR_CUSTOM);
attr.color[ATTR_HIGH] = COLOR_PAIR(COLR_HIGH);
@ -77,8 +76,7 @@ custom_init_attr (void)
}
/* Apply window attribute */
void
custom_apply_attr (WINDOW *win, int attr_num)
void custom_apply_attr(WINDOW * win, int attr_num)
{
if (colorize)
wattron(win, attr.color[attr_num]);
@ -87,8 +85,7 @@ custom_apply_attr (WINDOW *win, int attr_num)
}
/* Remove window attribute */
void
custom_remove_attr (WINDOW *win, int attr_num)
void custom_remove_attr(WINDOW * win, int attr_num)
{
if (colorize)
wattroff(win, attr.color[attr_num]);
@ -97,8 +94,7 @@ custom_remove_attr (WINDOW *win, int attr_num)
}
/* Draws the configuration bar */
void
custom_config_bar (void)
void custom_config_bar(void)
{
const int SMLSPC = 2;
const int SPC = 15;
@ -126,8 +122,7 @@ custom_config_bar (void)
wins_doupdate();
}
static void
layout_selection_bar (void)
static void layout_selection_bar(void)
{
struct binding quit = { _("Exit"), KEY_GENERIC_QUIT };
struct binding select = { _("Select"), KEY_GENERIC_SELECT };
@ -150,8 +145,7 @@ layout_selection_bar (void)
#define LAYOUTSPERCOL 2
/* Used to display available layouts in layout configuration menu. */
static void
display_layout_config (struct window *lwin, int mark, int cursor)
static void display_layout_config(struct window *lwin, int mark, int cursor)
{
#define CURSOR (32 | A_REVERSE)
#define MARK 88
@ -163,34 +157,37 @@ display_layout_config (struct window *lwin, int mark, int cursor)
const int COLSIZ = LAYOUTW + BOXSIZ + 1;
const int XSPC = (lwin->w - NBCOLS * COLSIZ) / (NBCOLS + 1);
const int XOFST = (lwin->w - NBCOLS * (XSPC + COLSIZ)) / 2;
const int YSPC = (lwin->h - 8 - LAYOUTSPERCOL * LAYOUTH) / (LAYOUTSPERCOL + 1);
const int YSPC =
(lwin->h - 8 - LAYOUTSPERCOL * LAYOUTH) / (LAYOUTSPERCOL + 1);
const int YOFST = (lwin->h - LAYOUTSPERCOL * (YSPC + LAYOUTH)) / 2;
enum { YPOS, XPOS, NBPOS };
int pos[NBLAYOUTS][NBPOS];
const char *layouts[LAYOUTH][NBLAYOUTS] = {
{"+---+---+", "+---+---+", "+---+---+", "+---+---+", "+---+---+", "+---+---+", "+---+---+", "+---+---+"},
{"| | c |", "| | t |", "| c | |", "| t | |", "| | c |", "| | a |", "| c | |", "| a | |"},
{"| a +---+", "| a +---+", "+---+ a |", "|---+ a |", "| t +---+", "| t +---+", "+---+ t |", "+---+ t |"},
{"| | t |", "| | c |", "| t | |", "| c | |", "| | a |", "| | c |", "| a | |", "| c | |"},
{"+---+---+", "+---+---+", "+---+---+", "+---+---+", "+---+---+", "+---+---+", "+---+---+", "+---+---+"}
{"+---+---+", "+---+---+", "+---+---+", "+---+---+", "+---+---+",
"+---+---+", "+---+---+", "+---+---+"},
{"| | c |", "| | t |", "| c | |", "| t | |", "| | c |",
"| | a |", "| c | |", "| a | |"},
{"| a +---+", "| a +---+", "+---+ a |", "|---+ a |", "| t +---+",
"| t +---+", "+---+ t |", "+---+ t |"},
{"| | t |", "| | c |", "| t | |", "| c | |", "| | a |",
"| | c |", "| a | |", "| c | |"},
{"+---+---+", "+---+---+", "+---+---+", "+---+---+", "+---+---+",
"+---+---+", "+---+---+", "+---+---+"}
};
int i;
for (i = 0; i < NBLAYOUTS; i++)
{
for (i = 0; i < NBLAYOUTS; i++) {
pos[i][YPOS] = YOFST + (i % LAYOUTSPERCOL) * (YSPC + LAYOUTH);
pos[i][XPOS] = XOFST + (i / LAYOUTSPERCOL) * (XSPC + COLSIZ);
}
for (i = 0; i < NBLAYOUTS; i++)
{
for (i = 0; i < NBLAYOUTS; i++) {
int j;
mvwprintw(lwin->p, pos[i][YPOS] + 2, pos[i][XPOS], box);
if (i == mark)
custom_apply_attr(lwin->p, ATTR_HIGHEST);
for (j = 0; j < LAYOUTH; j++)
{
for (j = 0; j < LAYOUTH; j++) {
mvwprintw(lwin->p, pos[i][YPOS] + j, pos[i][XPOS] + BOXSIZ + 1,
layouts[j][i]);
}
@ -209,8 +206,7 @@ display_layout_config (struct window *lwin, int mark, int cursor)
}
/* Choose the layout */
void
custom_layout_config (void)
void custom_layout_config(void)
{
struct scrollwin hwin;
struct window conf_win;
@ -222,8 +218,7 @@ custom_layout_config (void)
"It is possible to choose between eight different configurations.\n"
"\nIn the configuration representations, letters correspond to:\n\n"
" 'c' -> calendar panel\n\n"
" 'a' -> appointment panel\n\n"
" 't' -> todo panel\n\n");
" 'a' -> appointment panel\n\n" " 't' -> todo panel\n\n");
conf_win.p = NULL;
custom_confwin_init(&conf_win, label);
@ -231,14 +226,11 @@ custom_layout_config (void)
display_layout_config(&conf_win, mark, cursor);
clear();
while ((ch = keys_getch (win[STA].p, NULL)) != KEY_GENERIC_QUIT)
{
while ((ch = keys_getch(win[STA].p, NULL)) != KEY_GENERIC_QUIT) {
need_reset = 0;
switch (ch)
{
switch (ch) {
case KEY_GENERIC_HELP:
help_wins_init (&hwin, 0, 0,
(notify_bar ()) ? row - 3 : row - 2, col);
help_wins_init(&hwin, 0, 0, (notify_bar())? row - 3 : row - 2, col);
mvwprintw(hwin.pad.p, 1, 0, "%s", help_text);
hwin.total_lines = 7;
wins_scrollwin_display(&hwin);
@ -270,8 +262,7 @@ custom_layout_config (void)
break;
}
if (resize)
{
if (resize) {
resize = 0;
endwin();
wins_refresh();
@ -292,8 +283,7 @@ custom_layout_config (void)
#undef LAYOUTSPERCOL
/* Sidebar configuration screen. */
void
custom_sidebar_config (void)
void custom_sidebar_config(void)
{
struct scrollwin hwin;
struct binding quit = { _("Exit"), KEY_GENERIC_QUIT };
@ -304,7 +294,8 @@ custom_sidebar_config (void)
&inc, &dec, &help, &quit
};
const char *help_text =
_("This configuration screen is used to change the width of the side bar.\n"
_
("This configuration screen is used to change the width of the side bar.\n"
"The side bar is the part of the screen which contains two panels:\n"
"the calendar and, depending on the chosen layout, either the todo list\n"
"or the appointment list.\n\n"
@ -318,10 +309,8 @@ custom_sidebar_config (void)
bindings_size, NULL);
wins_doupdate();
while ((ch = keys_getch (win[STA].p, NULL)) != KEY_GENERIC_QUIT)
{
switch (ch)
{
while ((ch = keys_getch(win[STA].p, NULL)) != KEY_GENERIC_QUIT) {
switch (ch) {
case KEY_MOVE_UP:
wins_sbar_winc();
break;
@ -329,8 +318,7 @@ custom_sidebar_config (void)
wins_sbar_wdec();
break;
case KEY_GENERIC_HELP:
help_wins_init (&hwin, 0, 0,
(notify_bar ()) ? row - 3 : row - 2, col);
help_wins_init(&hwin, 0, 0, (notify_bar())? row - 3 : row - 2, col);
mvwprintw(hwin.pad.p, 1, 0, "%s", help_text);
hwin.total_lines = 6;
wins_scrollwin_display(&hwin);
@ -343,13 +331,10 @@ custom_sidebar_config (void)
continue;
}
if (resize)
{
if (resize) {
resize = 0;
wins_reset();
}
else
{
} else {
wins_reinit_panels();
wins_update_border(FLAG_ALL);
wins_update_panels(FLAG_ALL);
@ -360,8 +345,7 @@ custom_sidebar_config (void)
}
}
static void
set_confwin_attr (struct window *cwin)
static void set_confwin_attr(struct window *cwin)
{
cwin->h = (notify_bar())? row - 3 : row - 2;
cwin->w = col;
@ -372,11 +356,9 @@ set_confwin_attr (struct window *cwin)
* Create a configuration window and initialize status and notification bar
* (useful in case of window resize).
*/
void
custom_confwin_init (struct window *confwin, const char *label)
{
if (confwin->p)
void custom_confwin_init(struct window *confwin, const char *label)
{
if (confwin->p) {
erase_window_part(confwin->p, confwin->x, confwin->y,
confwin->x + confwin->w, confwin->y + confwin->h);
delwin(confwin->p);
@ -390,15 +372,13 @@ custom_confwin_init (struct window *confwin, const char *label)
delwin(win[STA].p);
win[STA].p = newwin(win[STA].h, win[STA].w, win[STA].y, win[STA].x);
keypad(win[STA].p, TRUE);
if (notify_bar ())
{
if (notify_bar()) {
notify_reinit_bar();
notify_update_bar();
}
}
static void
color_selection_bar (void)
static void color_selection_bar(void)
{
struct binding quit = { _("Exit"), KEY_GENERIC_QUIT };
struct binding select = { _("Select"), KEY_GENERIC_SELECT };
@ -444,8 +424,7 @@ display_color_config (struct window *cwin, int *mark_fore, int *mark_back,
const unsigned XSPC = (cwin->w - 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;
@ -456,18 +435,15 @@ display_color_config (struct window *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 (colorize)
{
if (theme_changed)
{
if (colorize) {
if (theme_changed) {
pair_content(colr[*mark_fore], &colr_fore, 0L);
if (colr_fore == 255)
colr_fore = -1;
@ -475,9 +451,7 @@ display_color_config (struct window *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);
@ -498,8 +472,7 @@ display_color_config (struct window *cwin, int *mark_fore, int *mark_back,
}
/* 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);
@ -522,12 +495,9 @@ display_color_config (struct window *cwin, int *mark_fore, int *mark_back,
mvwprintw(cwin->p, Y, XBACK + XOFST, back_txt);
custom_remove_attr(cwin->p, ATTR_HIGHEST);
if (colorize)
{
mvwaddch (cwin->p, pos[*mark_fore][YPOS],
pos[*mark_fore][XPOS] + 1, MARK);
mvwaddch (cwin->p, pos[*mark_back][YPOS],
pos[*mark_back][XPOS] + 1, MARK);
if (colorize) {
mvwaddch(cwin->p, pos[*mark_fore][YPOS], pos[*mark_fore][XPOS] + 1, MARK);
mvwaddch(cwin->p, pos[*mark_back][YPOS], pos[*mark_back][XPOS] + 1, MARK);
}
mvwaddch(cwin->p, pos[cursor][YPOS], pos[cursor][XPOS] + 1, CURSOR);
@ -540,8 +510,7 @@ display_color_config (struct window *cwin, int *mark_fore, int *mark_back,
}
/* Color theme configuration. */
void
custom_color_config (void)
void custom_color_config(void)
{
struct window conf_win;
int ch, cursor, need_reset, theme_changed;
@ -554,16 +523,15 @@ custom_color_config (void)
mark_back = SIZE - 1;
cursor = 0;
theme_changed = 0;
display_color_config (&conf_win, &mark_fore, &mark_back, cursor, theme_changed);
display_color_config(&conf_win, &mark_fore, &mark_back, cursor,
theme_changed);
clear();
while ((ch = keys_getch (win[STA].p, NULL)) != KEY_GENERIC_QUIT)
{
while ((ch = keys_getch(win[STA].p, NULL)) != KEY_GENERIC_QUIT) {
need_reset = 0;
theme_changed = 0;
switch (ch)
{
switch (ch) {
case KEY_GENERIC_SELECT:
colorize = 1;
need_reset = 1;
@ -600,8 +568,7 @@ custom_color_config (void)
break;
}
if (resize)
{
if (resize) {
resize = 0;
endwin();
wins_refresh();
@ -619,8 +586,7 @@ custom_color_config (void)
}
/* Prints the general options. */
static int
print_general_options (WINDOW *win)
static int print_general_options(WINDOW * win)
{
enum {
AUTO_SAVE,
@ -661,8 +627,7 @@ print_general_options (WINDOW *win)
mvwprintw(win, y, XPOS, "[2] %s ", opt[AUTO_GC]);
print_bool_option_incolor(win, conf.auto_gc, y,
XPOS + 4 + strlen(opt[AUTO_GC]));
mvwprintw (win, y + 1, XPOS,
_("(run the garbage collector when quitting)"));
mvwprintw(win, y + 1, XPOS, _("(run the garbage collector when quitting)"));
y += YOFF;
mvwprintw(win, y, XPOS, "[3] %s ", opt[PERIODIC_SAVE]);
custom_apply_attr(win, ATTR_HIGHEST);
@ -728,8 +693,7 @@ print_general_options (WINDOW *win)
return y + YOFF;
}
void
custom_set_swsiz (struct scrollwin *sw)
void custom_set_swsiz(struct scrollwin *sw)
{
sw->win.x = 0;
sw->win.y = 0;
@ -743,14 +707,11 @@ custom_set_swsiz (struct scrollwin *sw)
}
/* General configuration. */
void
custom_general_config (void)
void custom_general_config(void)
{
struct scrollwin cwin;
const char *number_str =
_("Enter an option number to change its value");
const char *keys =
_("(Press '^P' or '^N' to move up or down, 'Q' to quit)");
const char *number_str = _("Enter an option number to change its value");
const char *keys = _("(Press '^P' or '^N' to move up or down, 'Q' to quit)");
const char *output_datefmt_str =
_("Enter the date format (see 'man 3 strftime' for possible formats) ");
const char *input_datefmt_str =
@ -771,12 +732,10 @@ custom_general_config (void)
wins_scrollwin_display(&cwin);
buf = mem_malloc(BUFSIZ);
while ((ch = wgetch (win[STA].p)) != 'q')
{
while ((ch = wgetch(win[STA].p)) != 'q') {
buf[0] = '\0';
switch (ch)
{
switch (ch) {
case CTRL('N'):
wins_scrollwin_down(&cwin, 1);
break;
@ -791,8 +750,7 @@ custom_general_config (void)
break;
case '3':
status_mesg(periodic_save_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 >= 0)
conf.periodic_save = val;
@ -820,18 +778,15 @@ custom_general_config (void)
break;
case '9':
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, keys);
break;
case '0':
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 > 0 && val <= DATE_FORMATS)
conf.input_datefmt = val;
@ -840,8 +795,7 @@ custom_general_config (void)
break;
}
if (resize)
{
if (resize) {
resize = 0;
wins_reset();
wins_scrollwin_delete(&cwin);
@ -850,11 +804,9 @@ custom_general_config (void)
wins_show(cwin.win.p, cwin.label);
cwin.first_visible_line = 0;
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 ())
{
if (notify_bar()) {
notify_reinit_bar();
notify_update_bar();
}
@ -868,7 +820,6 @@ custom_general_config (void)
wins_scrollwin_delete(&cwin);
}
static void
print_key_incolor(WINDOW * win, const char *option, int pos_y, int pos_x)
{
@ -889,8 +840,7 @@ print_keys_bindings (WINDOW *win, int selected_row, int selected_elm, int yoff)
int noelm, action, y;
noelm = y = 0;
for (action = 0; action < NBKEYS; action++)
{
for (action = 0; action < NBKEYS; action++) {
char actionstr[BUFSIZ];
int nbkeys;
@ -904,16 +854,13 @@ print_keys_bindings (WINDOW *win, int selected_row, int selected_elm, int yoff)
mvwprintw(win, y, KEYPOS, _("undefined"));
if (action == selected_row)
custom_remove_attr(win, ATTR_HIGHEST);
if (nbkeys > 0)
{
if (action == selected_row)
{
if (nbkeys > 0) {
if (action == selected_row) {
const char *key;
int pos;
pos = KEYPOS;
while ((key = keys_action_nkey (action, noelm)) != NULL)
{
while ((key = keys_action_nkey(action, noelm)) != NULL) {
if (noelm == selected_elm)
print_key_incolor(win, key, y, pos);
else
@ -921,9 +868,7 @@ print_keys_bindings (WINDOW *win, int selected_row, int selected_elm, int yoff)
noelm++;
pos += strlen(key) + 1;
}
}
else
{
} else {
mvwprintw(win, y, KEYPOS, "%s", keys_action_allkeys(action));
}
}
@ -933,8 +878,7 @@ print_keys_bindings (WINDOW *win, int selected_row, int selected_elm, int yoff)
return noelm;
}
static void
custom_keys_config_bar (void)
static void custom_keys_config_bar(void)
{
struct binding quit = { _("Exit"), KEY_GENERIC_QUIT };
struct binding info = { _("Key info"), KEY_GENERIC_HELP };
@ -954,8 +898,7 @@ custom_keys_config_bar (void)
bindings_size, NULL);
}
void
custom_keys_config (void)
void custom_keys_config(void)
{
struct scrollwin kwin;
int selrow, selelm, firstrow, lastrow, nbrowelm, nbdisplayed;
@ -978,20 +921,16 @@ custom_keys_config (void)
wins_scrollwin_display(&kwin);
firstrow = 0;
lastrow = firstrow + nbdisplayed - 1;
for (;;)
{
for (;;) {
int ch;
ch = keys_getch(win[STA].p, NULL);
switch (ch)
{
switch (ch) {
case KEY_MOVE_UP:
if (selrow > 0)
{
if (selrow > 0) {
selrow--;
selelm = 0;
if (selrow == firstrow)
{
if (selrow == firstrow) {
firstrow--;
lastrow--;
wins_scrollwin_up(&kwin, LINESPERKEY);
@ -999,12 +938,10 @@ custom_keys_config (void)
}
break;
case KEY_MOVE_DOWN:
if (selrow < NBKEYS - 1)
{
if (selrow < NBKEYS - 1) {
selrow++;
selelm = 0;
if (selrow == lastrow)
{
if (selrow == lastrow) {
firstrow++;
lastrow++;
wins_scrollwin_down(&kwin, LINESPERKEY);
@ -1025,8 +962,7 @@ custom_keys_config (void)
case KEY_ADD_ITEM:
#define WINROW 10
#define WINCOL 50
do
{
do {
used = 0;
grabwin = popup(WINROW, WINCOL, (row - WINROW) / 2,
(col - WINCOL) / 2,
@ -1035,8 +971,7 @@ custom_keys_config (void)
keyval = wgetch(grabwin);
/* First check if this key would be recognized by calcurse. */
if (keys_str2int (keys_int2str (keyval)) == -1)
{
if (keys_str2int(keys_int2str(keyval)) == -1) {
not_recognized = 1;
WARN_MSG(_("This key is not yet recognized by calcurse, "
"please choose another one."));
@ -1045,19 +980,16 @@ custom_keys_config (void)
LINESPERKEY);
wins_scrollwin_display(&kwin);
continue;
}
else
} else
not_recognized = 0;
used = keys_assign_binding(keyval, selrow);
if (used)
{
if (used) {
enum key action;
action = keys_get_action(keyval);
WARN_MSG(_("This key is already in use for %s, "
"please choose another one."),
keys_get_label (action));
"please choose another one."), keys_get_label(action));
werase(kwin.pad.p);
nbrowelm = print_keys_bindings(kwin.pad.p, selrow, selelm,
LINESPERKEY);
@ -1081,10 +1013,8 @@ custom_keys_config (void)
selelm--;
break;
case KEY_GENERIC_QUIT:
if (keys_check_missing_bindings () != 0)
{
WARN_MSG (_("Some actions do not have any associated "
"key bindings!"));
if (keys_check_missing_bindings() != 0) {
WARN_MSG(_("Some actions do not have any associated " "key bindings!"));
}
wins_scrollwin_delete(&kwin);
return;
@ -1096,8 +1026,7 @@ custom_keys_config (void)
}
}
void
custom_config_main (void)
void custom_config_main(void)
{
const char *no_color_support =
_("Sorry, colors are not supported by your terminal\n"
@ -1106,16 +1035,13 @@ custom_config_main (void)
int old_layout;
custom_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 = 0;
wins_erase_status_bar();
mvwprintw(win[STA].p, 0, 0, _(no_color_support));

350
src/day.c
View File

@ -53,14 +53,12 @@ struct day_saved_item {
static llist_t day_items;
static struct day_saved_item day_saved_item;
static void
day_free (struct day_item *day)
static void day_free(struct day_item *day)
{
mem_free(day);
}
static void
day_init_list (void)
static void day_init_list(void)
{
LLIST_INIT(&day_items);
}
@ -70,16 +68,15 @@ day_init_list (void)
* Must not free associated message and note, because their are not dynamically
* allocated (only pointers to real objects are stored in this structure).
*/
void
day_free_list (void)
void day_free_list(void)
{
LLIST_FREE_INNER(&day_items, day_free);
LLIST_FREE(&day_items);
}
/* Add an event in the current day list */
static struct day_item *
day_add_event (int type, char *mesg, char *note, long nday, int id)
static struct day_item *day_add_event(int type, char *mesg, char *note,
long nday, int id)
{
struct day_item *day;
@ -97,26 +94,23 @@ day_add_event (int type, char *mesg, char *note, long nday, int id)
return day;
}
static int
day_cmp_start (struct day_item *a, struct day_item *b)
{
if (a->type <= EVNT)
static int day_cmp_start(struct day_item *a, struct day_item *b)
{
if (a->type <= EVNT) {
if (b->type <= EVNT)
return 0;
else
return -1;
}
else if (b->type <= EVNT)
} else if (b->type <= EVNT)
return 1;
else
return a->start < b->start ? -1 : (a->start == b->start ? 0 : 1);
}
/* Add an appointment in the current day list. */
static struct day_item *
day_add_apoint (int type, char *mesg, char *note, long start, long dur,
char state, int real_pos)
static struct day_item *day_add_apoint(int type, char *mesg, char *note,
long start, long dur, char state,
int real_pos)
{
struct day_item *day;
@ -142,14 +136,12 @@ day_add_apoint (int type, char *mesg, char *note, long start, long dur,
* dedicated to the selected day.
* Returns the number of events for the selected day.
*/
static int
day_store_events (long date)
static int day_store_events(long date)
{
llist_item_t *i;
int e_nb = 0;
LLIST_FIND_FOREACH_CONT (&eventlist, date, event_inday, i)
{
LLIST_FIND_FOREACH_CONT(&eventlist, date, event_inday, i) {
struct event *ev = LLIST_TS_GET_DATA(i);
day_add_event(EVNT, ev->mesg, ev->note, ev->day, ev->id);
e_nb++;
@ -165,14 +157,12 @@ day_store_events (long date)
* dedicated to the selected day.
* Returns the number of recurrent events for the selected day.
*/
static int
day_store_recur_events (long date)
static int day_store_recur_events(long date)
{
llist_item_t *i;
int e_nb = 0;
LLIST_FIND_FOREACH (&recur_elist, date, recur_event_inday, i)
{
LLIST_FIND_FOREACH(&recur_elist, date, recur_event_inday, i) {
struct recur_event *rev = LLIST_TS_GET_DATA(i);
day_add_event(RECUR_EVNT, rev->mesg, rev->note, rev->day, rev->id);
e_nb++;
@ -188,15 +178,13 @@ day_store_recur_events (long date)
* structure dedicated to the selected day.
* Returns the number of appointments for the selected day.
*/
static int
day_store_apoints (long date)
static int day_store_apoints(long date)
{
llist_item_t *i;
int a_nb = 0;
LLIST_TS_LOCK(&alist_p);
LLIST_TS_FIND_FOREACH (&alist_p, date, apoint_inday, i)
{
LLIST_TS_FIND_FOREACH(&alist_p, date, apoint_inday, i) {
struct apoint *apt = LLIST_TS_GET_DATA(i);
if (apt->start >= date + DAYINSEC)
@ -218,19 +206,16 @@ day_store_apoints (long date)
* structure dedicated to the selected day.
* Returns the number of recurrent appointments for the selected day.
*/
static int
day_store_recur_apoints (long date)
static int day_store_recur_apoints(long date)
{
llist_item_t *i;
int a_nb = 0;
LLIST_TS_LOCK(&recur_alist_p);
LLIST_TS_FIND_FOREACH (&recur_alist_p, date, recur_apoint_inday, i)
{
LLIST_TS_FIND_FOREACH(&recur_alist_p, date, recur_apoint_inday, i) {
struct recur_apoint *rapt = LLIST_TS_GET_DATA(i);
unsigned real_start;
if (recur_apoint_find_occurrence (rapt, date, &real_start))
{
if (recur_apoint_find_occurrence(rapt, date, &real_start)) {
day_add_apoint(RECUR_APPT, rapt->mesg, rapt->note, real_start,
rapt->dur, rapt->state, a_nb);
a_nb++;
@ -277,8 +262,8 @@ day_store_items (long date, unsigned *pnb_events, unsigned *pnb_apoints)
* those items in a pad. If selected day is null, then store items for current
* day. This is useful to speed up the appointment panel update.
*/
struct day_items_nb *
day_process_storage (struct date *slctd_date, unsigned day_changed,
struct day_items_nb *day_process_storage(struct date *slctd_date,
unsigned day_changed,
struct day_items_nb *inday)
{
long date;
@ -310,8 +295,7 @@ day_process_storage (struct date *slctd_date, unsigned day_changed,
* Returns a structure of type apoint_llist_node_t given a structure of type
* day_item_s
*/
static void
day_item_s2apoint_s (struct apoint *a, struct day_item *p)
static void day_item_s2apoint_s(struct apoint *a, struct day_item *p)
{
a->state = p->state;
a->start = p->start;
@ -368,10 +352,8 @@ display_item (int incolor, char *msg, int recur, int note, int width, int y,
custom_apply_attr(win, ATTR_HIGHEST);
if (utf8_strwidth(msg) < width)
mvwprintw(win, y, x, " %c%c%s", ch_recur, ch_note, msg);
else
{
for (i = 0; msg[i] && width > 0; i++)
{
else {
for (i = 0; msg[i] && width > 0; i++) {
if (!UTF8_ISCONT(msg[i]))
width -= utf8_width(&msg[i]);
buf[i] = msg[i];
@ -393,8 +375,7 @@ display_item (int incolor, char *msg, int recur, int note, int width, int y,
* structure (pointed by day_saved_item), to be later displayed in a
* popup window if requested.
*/
void
day_write_pad (long date, int width, int length, int incolor)
void day_write_pad(long date, int width, int length, int incolor)
{
llist_item_t *i;
struct apoint a;
@ -404,19 +385,16 @@ day_write_pad (long date, int width, int length, int incolor)
line = item_number = 0;
LLIST_FOREACH (&day_items, i)
{
LLIST_FOREACH(&day_items, i) {
struct day_item *day = LLIST_TS_GET_DATA(i);
if (day->type == RECUR_EVNT || day->type == RECUR_APPT)
recur = 1;
else
recur = 0;
/* First print the events for current day. */
if (day->type < RECUR_APPT)
{
if (day->type < RECUR_APPT) {
item_number++;
if (item_number - incolor == 0)
{
if (item_number - incolor == 0) {
day_saved_item.type = day->type;
day_saved_item.mesg = day->mesg;
}
@ -424,12 +402,9 @@ day_write_pad (long date, int width, int length, int incolor)
(day->note != NULL) ? 1 : 0, width - 7, line, x_pos);
line++;
draw_line = 1;
}
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 = 0;
@ -437,26 +412,22 @@ day_write_pad (long date, int width, int length, int incolor)
/* Last print the appointments for current day. */
item_number++;
day_item_s2apoint_s(&a, day);
if (item_number - incolor == 0)
{
if (item_number - incolor == 0) {
day_saved_item.type = day->type;
day_saved_item.mesg = day->mesg;
apoint_sec2str (&a, date, day_saved_item.start,
day_saved_item.end);
apoint_sec2str(&a, date, day_saved_item.start, day_saved_item.end);
}
display_item_date(item_number - incolor, &a, day->type,
date, line + 1, x_pos);
display_item(item_number - incolor, day->mesg, 0,
(day->note != NULL) ? 1 : 0, width - 7, line + 2,
x_pos);
(day->note != NULL) ? 1 : 0, width - 7, line + 2, x_pos);
line += 3;
}
}
}
/* Display an item inside a popup window. */
void
day_popup_item (void)
void day_popup_item(void)
{
if (day_saved_item.type == EVNT || day_saved_item.type == RECUR_EVNT)
item_in_popup(NULL, NULL, day_saved_item.mesg, _("Event :"));
@ -472,8 +443,7 @@ day_popup_item (void)
* Need to know if there is an item for the current selected day inside
* calendar. This is used to put the correct colors inside calendar panel.
*/
int
day_check_if_item (struct date day)
int day_check_if_item(struct date day)
{
const long date = date2sec(day, 0, 0);
@ -481,8 +451,7 @@ day_check_if_item (struct date day)
return 1;
LLIST_TS_LOCK(&recur_alist_p);
if (LLIST_TS_FIND_FIRST (&recur_alist_p, date, recur_apoint_inday))
{
if (LLIST_TS_FIND_FIRST(&recur_alist_p, date, recur_apoint_inday)) {
LLIST_TS_UNLOCK(&recur_alist_p);
return 1;
}
@ -492,8 +461,7 @@ day_check_if_item (struct date day)
return 1;
LLIST_TS_LOCK(&alist_p);
if (LLIST_TS_FIND_FIRST (&alist_p, date, apoint_inday))
{
if (LLIST_TS_FIND_FIRST(&alist_p, date, apoint_inday)) {
LLIST_TS_UNLOCK(&alist_p);
return 1;
}
@ -502,8 +470,7 @@ day_check_if_item (struct date day)
return 0;
}
static unsigned
fill_slices (int *slices, int slicesno, int first, int last)
static unsigned fill_slices(int *slices, int slicesno, int first, int last)
{
int i;
@ -524,8 +491,7 @@ fill_slices (int *slices, int slicesno, int first, int last)
* appointment in the corresponding time slice, 0 otherwise.
* A 24 hours day is divided into 'slicesno' number of time slices.
*/
unsigned
day_chk_busy_slices (struct date day, int slicesno, int *slices)
unsigned day_chk_busy_slices(struct date day, int slicesno, int *slices)
{
llist_item_t *i;
int slicelen;
@ -536,14 +502,12 @@ day_chk_busy_slices (struct date day, int slicesno, int *slices)
#define SLICENUM(tsec) ((tsec) / slicelen % slicesno)
LLIST_TS_LOCK(&recur_alist_p);
LLIST_TS_FIND_FOREACH (&recur_alist_p, date, recur_apoint_inday, i)
{
LLIST_TS_FIND_FOREACH(&recur_alist_p, date, recur_apoint_inday, i) {
struct apoint *rapt = LLIST_TS_GET_DATA(i);
long start = get_item_time(rapt->start);
long end = get_item_time(rapt->start + rapt->dur);
if (!fill_slices (slices, slicesno, SLICENUM (start), SLICENUM (end)))
{
if (!fill_slices(slices, slicesno, SLICENUM(start), SLICENUM(end))) {
LLIST_TS_UNLOCK(&recur_alist_p);
return 0;
}
@ -551,8 +515,7 @@ day_chk_busy_slices (struct date day, int slicesno, int *slices)
LLIST_TS_UNLOCK(&recur_alist_p);
LLIST_TS_LOCK(&alist_p);
LLIST_TS_FIND_FOREACH (&alist_p, date, apoint_inday, i)
{
LLIST_TS_FIND_FOREACH(&alist_p, date, apoint_inday, i) {
struct apoint *apt = LLIST_TS_GET_DATA(i);
long start = get_item_time(apt->start);
long end = get_item_time(apt->start + apt->dur);
@ -560,8 +523,7 @@ day_chk_busy_slices (struct date day, int slicesno, int *slices)
if (apt->start >= date + DAYINSEC)
break;
if (!fill_slices (slices, slicesno, SLICENUM (start), SLICENUM (end)))
{
if (!fill_slices(slices, slicesno, SLICENUM(start), SLICENUM(end))) {
LLIST_TS_UNLOCK(&alist_p);
return 0;
}
@ -573,71 +535,56 @@ day_chk_busy_slices (struct date day, int slicesno, int *slices)
}
/* Request the user to enter a new time. */
static int
day_edit_time (int time, unsigned *new_hour, unsigned *new_minute)
static int day_edit_time(int time, unsigned *new_hour, unsigned *new_minute)
{
char *timestr = date_sec2date_str(time, "%H:%M");
const char *msg_time = _("Enter the new time ([hh:mm]) : ");
const char *enter_str = _("Press [Enter] to continue");
const char *fmt_msg = _("You entered an invalid time, should be [hh:mm]");
for (;;)
{
for (;;) {
status_mesg(msg_time, "");
if (updatestring (win[STA].p, &timestr, 0, 1) == GETSTRING_VALID)
{
if (parse_time (timestr, new_hour, new_minute) == 1)
{
if (updatestring(win[STA].p, &timestr, 0, 1) == GETSTRING_VALID) {
if (parse_time(timestr, new_hour, new_minute) == 1) {
mem_free(timestr);
return 1;
}
else
{
} else {
status_mesg(fmt_msg, enter_str);
wgetch(win[STA].p);
}
}
else
} else
return 0;
}
}
/* Request the user to enter a new time or duration. */
static int
day_edit_duration (int start, int dur, unsigned *new_duration)
static int day_edit_duration(int start, int dur, unsigned *new_duration)
{
char *timestr = date_sec2date_str(start + dur, "%H:%M");
const char *msg_time = _("Enter new end time ([hh:mm]) or duration ([+hh:mm], [+xxxdxxhxxm] or [+mm]) : ");
const char *msg_time =
_
("Enter new end time ([hh:mm]) or duration ([+hh:mm], [+xxxdxxhxxm] or [+mm]) : ");
const char *enter_str = _("Press [Enter] to continue");
const char *fmt_msg = _("You entered an invalid time, should be [hh:mm]");
long newtime;
unsigned hr, mn;
for (;;)
{
for (;;) {
status_mesg(msg_time, "");
if (updatestring (win[STA].p, &timestr, 0, 1) == GETSTRING_VALID)
{
if (*timestr == '+' && parse_duration (timestr + 1,
new_duration) == 1)
{
if (updatestring(win[STA].p, &timestr, 0, 1) == GETSTRING_VALID) {
if (*timestr == '+' && parse_duration(timestr + 1, new_duration) == 1) {
*new_duration *= MININSEC;
break;
}
else if (parse_time (timestr, &hr, &mn) == 1)
{
} else if (parse_time(timestr, &hr, &mn) == 1) {
newtime = update_time_in_date(start + dur, hr, mn);
*new_duration = (newtime > start) ? newtime - start :
DAYINSEC + newtime - start;
break;
}
else
{
} else {
status_mesg(fmt_msg, enter_str);
wgetch(win[STA].p);
}
}
else
} else
return 0;
}
@ -646,27 +593,23 @@ day_edit_duration (int start, int dur, unsigned *new_duration)
}
/* Request the user to enter a new end time or duration. */
static void
update_start_time (long *start, long *dur)
static void update_start_time(long *start, long *dur)
{
long newtime;
unsigned hr, mn;
int valid_date;
const char *msg_wrong_time = _("Invalid time: start time must be before end time!");
const char *msg_wrong_time =
_("Invalid time: start time must be before end time!");
const char *msg_enter = _("Press [Enter] to continue");
do
{
do {
day_edit_time(*start, &hr, &mn);
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;
@ -675,8 +618,7 @@ update_start_time (long *start, long *dur)
while (valid_date == 0);
}
static void
update_duration (long *start, long *dur)
static void update_duration(long *start, long *dur)
{
unsigned newdur;
@ -684,15 +626,13 @@ update_duration (long *start, long *dur)
*dur = newdur;
}
static void
update_desc (char **desc)
static void update_desc(char **desc)
{
status_mesg(_("Enter the new item description:"), "");
updatestring(win[STA].p, desc, 0, 1);
}
static void
update_rept (struct rpt **rpt, const long start)
static void update_rept(struct rpt **rpt, const long start)
{
int newtype, newfreq, date_entered;
long newuntil;
@ -707,8 +647,7 @@ update_rept (struct rpt **rpt, const long start)
/* Find the current repetition type. */
const char *rpt_current;
char msg_rpt_current[BUFSIZ];
switch (recur_def2char ((*rpt)->type))
{
switch (recur_def2char((*rpt)->type)) {
case 'D':
rpt_current = msg_rpt_daily;
break;
@ -732,21 +671,18 @@ update_rept (struct rpt **rpt, const long start)
snprintf(msg_rpt_asktype, BUFSIZ, "%s %s, %s, %s, %s ? %s",
msg_rpt_prefix,
msg_rpt_daily,
msg_rpt_weekly,
msg_rpt_monthly,
msg_rpt_yearly,
msg_rpt_current);
msg_rpt_weekly, msg_rpt_monthly, msg_rpt_yearly, msg_rpt_current);
const char *msg_rpt_choice = _("[dwmy]");
const char *msg_wrong_freq = _("The frequence you entered is not valid.");
const char *msg_wrong_time = _("Invalid time: start time must be before end time!");
const char *msg_wrong_time =
_("Invalid time: start time must be before end time!");
const char *msg_wrong_date = _("The entered date is not valid.");
const char *msg_fmts =
_("Possible formats are [%s] or '0' for an endless repetetition");
const char *msg_enter = _("Press [Enter] to continue");
switch (status_ask_choice (msg_rpt_asktype, msg_rpt_choice, 4))
{
switch (status_ask_choice(msg_rpt_asktype, msg_rpt_choice, 4)) {
case 1:
newtype = 'D';
break;
@ -763,75 +699,58 @@ update_rept (struct rpt **rpt, const long start)
return;
}
do
{
do {
status_mesg(_("Enter the new repetition frequence:"), "");
freqstr = mem_malloc(BUFSIZ);
snprintf(freqstr, BUFSIZ, "%d", (*rpt)->freq);
if (updatestring (win[STA].p, &freqstr, 0, 1) == GETSTRING_VALID)
{
if (updatestring(win[STA].p, &freqstr, 0, 1) == GETSTRING_VALID) {
newfreq = atoi(freqstr);
mem_free(freqstr);
if (newfreq == 0)
{
if (newfreq == 0) {
status_mesg(msg_wrong_freq, msg_enter);
wgetch(win[STA].p);
}
}
else
{
} else {
mem_free(freqstr);
return;
}
}
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));
if (updatestring (win[STA].p, &timstr, 0, 1) != GETSTRING_VALID)
{
timstr = date_sec2date_str((*rpt)->until, DATEFMT(conf.input_datefmt));
if (updatestring(win[STA].p, &timstr, 0, 1) != GETSTRING_VALID) {
mem_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;
struct date new_date;
int newmonth, newday, newyear;
if (parse_date(timstr, conf.input_datefmt, &newyear, &newmonth,
&newday, calendar_get_slctd_day ()))
{
&newday, calendar_get_slctd_day())) {
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)
{
if (newuntil < start) {
status_mesg(msg_wrong_time, msg_enter);
wgetch(win[STA].p);
date_entered = 0;
}
else
} else
date_entered = 1;
}
else
{
snprintf (outstr, BUFSIZ, msg_fmts,
DATEFMT_DESC (conf.input_datefmt));
} else {
snprintf(outstr, BUFSIZ, msg_fmts, DATEFMT_DESC(conf.input_datefmt));
status_mesg(msg_wrong_date, _(outstr));
wgetch(win[STA].p);
date_entered = 0;
@ -847,8 +766,7 @@ update_rept (struct rpt **rpt, const long start)
}
/* Edit an already existing item. */
void
day_edit_item (void)
void day_edit_item(void)
{
struct day_item *p;
struct recur_event *re;
@ -863,16 +781,14 @@ day_edit_item (void)
p = day_get_item(item_num);
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));
const char *choice_recur_evnt[2] = {
"Description",
"Repetition",
};
switch (status_ask_simplechoice (_("Edit: "), choice_recur_evnt, 2))
{
switch (status_ask_simplechoice(_("Edit: "), choice_recur_evnt, 2)) {
case 1:
update_desc(&re->mesg);
break;
@ -895,8 +811,7 @@ day_edit_item (void)
"Description",
"Repetition",
};
switch (status_ask_simplechoice (_("Edit: "), choice_recur_appt, 4))
{
switch (status_ask_simplechoice(_("Edit: "), choice_recur_appt, 4)) {
case 1:
need_check_notify = 1;
update_start_time(&ra->start, &ra->dur);
@ -924,8 +839,7 @@ day_edit_item (void)
"End time",
"Description",
};
switch (status_ask_simplechoice (_("Edit: "), choice_appt, 3))
{
switch (status_ask_simplechoice(_("Edit: "), choice_appt, 3)) {
case 1:
need_check_notify = 1;
update_start_time(&a->start, &a->dur);
@ -954,8 +868,7 @@ day_edit_item (void)
* recurrent appointments and appointments) and then to test the
* type of the item to be deleted.
*/
int
day_erase_item (long date, int item_number, enum eraseflg flag)
int day_erase_item(long date, int item_number, enum eraseflg flag)
{
struct day_item *p;
@ -974,15 +887,13 @@ day_erase_item (long date, int item_number, enum eraseflg flag)
unsigned delete_whole;
p = day_get_item(item_number);
if (flag == ERASE_DONT_FORCE)
{
if (flag == ERASE_DONT_FORCE) {
if (p->note == NULL)
ans = 1;
else
ans = status_ask_choice(note_warning, note_choices, nb_note_choices);
switch (ans)
{
switch (ans) {
case 1:
flag = ERASE_FORCE;
break;
@ -993,24 +904,17 @@ day_erase_item (long date, int item_number, enum eraseflg flag)
return 0;
}
}
if (p->type == EVNT)
{
if (p->type == EVNT) {
event_delete_bynum(date, day_item_nb(date, item_number, EVNT), flag);
}
else if (p->type == APPT)
{
} else if (p->type == APPT) {
apoint_delete_bynum(date, day_item_nb(date, item_number, APPT), flag);
}
else
{
} else {
if (flag == ERASE_FORCE_ONLY_NOTE)
ans = 1;
else
ans = status_ask_choice (erase_warning, erase_choices,
nb_erase_choices);
ans = status_ask_choice(erase_warning, erase_choices, nb_erase_choices);
switch (ans)
{
switch (ans) {
case 1:
delete_whole = 1;
break;
@ -1021,13 +925,10 @@ day_erase_item (long date, int item_number, enum eraseflg flag)
return 0;
}
if (p->type == RECUR_EVNT)
{
if (p->type == RECUR_EVNT) {
recur_event_erase(date, day_item_nb(date, item_number, RECUR_EVNT),
delete_whole, flag);
}
else
{
} else {
recur_apoint_erase(date, p->appt_pos, delete_whole, flag);
}
}
@ -1038,26 +939,22 @@ day_erase_item (long date, int item_number, enum eraseflg flag)
}
/* Cut an item so it can be pasted somewhere else later. */
int
day_cut_item (long date, int item_number)
int day_cut_item(long date, int item_number)
{
const int DELETE_WHOLE = 1;
struct day_item *p;
p = day_get_item(item_number);
switch (p->type)
{
switch (p->type) {
case EVNT:
event_delete_bynum (date, day_item_nb (date, item_number, EVNT),
ERASE_CUT);
event_delete_bynum(date, day_item_nb(date, item_number, EVNT), ERASE_CUT);
break;
case RECUR_EVNT:
recur_event_erase(date, day_item_nb(date, item_number, RECUR_EVNT),
DELETE_WHOLE, ERASE_CUT);
break;
case APPT:
apoint_delete_bynum (date, day_item_nb (date, item_number, APPT),
ERASE_CUT);
apoint_delete_bynum(date, day_item_nb(date, item_number, APPT), ERASE_CUT);
break;
case RECUR_APPT:
recur_apoint_erase(date, p->appt_pos, DELETE_WHOLE, ERASE_CUT);
@ -1071,14 +968,12 @@ day_cut_item (long date, int item_number)
}
/* Paste a previously cut item. */
int
day_paste_item (long date, int cut_item_type)
int day_paste_item(long date, int cut_item_type)
{
int pasted_item_type;
pasted_item_type = cut_item_type;
switch (cut_item_type)
{
switch (cut_item_type) {
case 0:
return 0;
case EVNT:
@ -1102,15 +997,13 @@ day_paste_item (long date, int cut_item_type)
}
/* Returns a structure containing the selected item. */
struct day_item *
day_get_item (int item_number)
struct day_item *day_get_item(int item_number)
{
return LLIST_GET_DATA(LLIST_NTH(&day_items, item_number - 1));
}
/* Returns the real item number, given its type. */
int
day_item_nb (long date, int day_num, int type)
int day_item_nb(long date, int day_num, int type)
{
int i, nb_item[MAX_TYPES];
llist_item_t *j;
@ -1119,8 +1012,7 @@ day_item_nb (long date, int day_num, int type)
nb_item[i] = 0;
j = LLIST_FIRST(&day_items);
for (i = 1; i < day_num; i++)
{
for (i = 1; i < day_num; i++) {
struct day_item *day = LLIST_TS_GET_DATA(j);
nb_item[day->type - 1]++;
j = LLIST_TS_NEXT(j);
@ -1130,8 +1022,7 @@ day_item_nb (long date, int day_num, int type)
}
/* Attach a note to an appointment or event. */
void
day_edit_note (const char *editor)
void day_edit_note(const char *editor)
{
struct day_item *p;
struct recur_apoint *ra;
@ -1146,8 +1037,7 @@ day_edit_note (const char *editor)
edit_note(&p->note, 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->note = p->note;
@ -1168,16 +1058,14 @@ day_edit_note (const char *editor)
}
/* View a note previously attached to an appointment or event */
void
day_view_note (const char *pager)
void day_view_note(const char *pager)
{
struct day_item *p = day_get_item(apoint_hilt());
view_note(p->note, pager);
}
/* Pipe an appointment or event to an external program. */
void
day_pipe_item (void)
void day_pipe_item(void)
{
char cmd[BUFSIZ] = "";
char const *arg[] = { cmd, NULL };
@ -1197,15 +1085,13 @@ day_pipe_item (void)
return;
wins_prepare_external();
if ((pid = shell_exec (NULL, &pout, *arg, arg)))
{
if ((pid = shell_exec(NULL, &pout, *arg, arg))) {
fpout = fdopen(pout, "w");
item_num = apoint_hilt();
p = day_get_item(item_num);
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));
recur_event_write(re, fpout);

View File

@ -64,26 +64,22 @@
static unsigned data_loaded;
static void
dmon_sigs_hdlr (int sig)
static void dmon_sigs_hdlr(int sig)
{
if (data_loaded)
free_user_data();
DMON_LOG(_("terminated at %s with signal %d\n"), nowstr(), sig);
if (unlink (path_dpid) != 0)
{
DMON_LOG (_("Could not remove daemon lock file: %s\n"),
strerror (errno));
if (unlink(path_dpid) != 0) {
DMON_LOG(_("Could not remove daemon lock file: %s\n"), strerror(errno));
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
}
static unsigned
daemonize (int status)
static unsigned daemonize(int status)
{
int fd;
@ -93,8 +89,7 @@ daemonize (int status)
* First need to fork in order to become a child of the init process,
* once the father exits.
*/
switch (fork ())
{
switch (fork()) {
case -1: /* fork error */
EXIT(_("Could not fork: %s\n"), strerror(errno));
break;
@ -110,8 +105,7 @@ daemonize (int status)
* Obtain a new process group and session in order to get detached from the
* controlling terminal.
*/
if (setsid () == -1)
{
if (setsid() == -1) {
DMON_LOG(_("Could not detach from the controlling terminal: %s\n"),
strerror(errno));
return 0;
@ -121,16 +115,13 @@ daemonize (int status)
* Change working directory to root directory,
* to prevent filesystem unmounts.
*/
if (chdir ("/") == -1)
{
DMON_LOG (_("Could not change working directory: %s\n"),
strerror (errno));
if (chdir("/") == -1) {
DMON_LOG(_("Could not change working directory: %s\n"), strerror(errno));
return 0;
}
/* Redirect standard file descriptors to /dev/null. */
if ((fd = open (_PATH_DEVNULL, O_RDWR, 0)) != -1)
{
if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
dup2(fd, STDIN_FILENO);
dup2(fd, STDOUT_FILENO);
dup2(fd, STDERR_FILENO);
@ -151,8 +142,7 @@ daemonize (int status)
return 1;
}
void
dmon_start (int parent_exit_status)
void dmon_start(int parent_exit_status)
{
if (!daemonize(parent_exit_status))
DMON_ABRT(_("Cannot daemonize, aborting\n"));
@ -161,13 +151,11 @@ dmon_start (int parent_exit_status)
DMON_ABRT(_("Could not set lock file\n"));
if (!io_file_exist(path_conf))
DMON_ABRT (_("Could not access \"%s\": %s\n"),
path_conf, strerror (errno));
DMON_ABRT(_("Could not access \"%s\": %s\n"), path_conf, strerror(errno));
config_load();
if (!io_file_exist(path_apts))
DMON_ABRT (_("Could not access \"%s\": %s\n"),
path_apts, strerror (errno));
DMON_ABRT(_("Could not access \"%s\": %s\n"), path_apts, strerror(errno));
apoint_llist_init();
recur_apoint_llist_init();
event_llist_init();
@ -176,16 +164,14 @@ dmon_start (int parent_exit_status)
data_loaded = 1;
DMON_LOG(_("started at %s\n"), nowstr());
for (;;)
{
for (;;) {
int left;
if (!notify_get_next_bkgd())
DMON_ABRT(_("error loading next appointment\n"));
left = notify_time_left();
if (left > 0 && left < nbar.cntdwn && notify_needs_reminder ())
{
if (left > 0 && left < nbar.cntdwn && notify_needs_reminder()) {
DMON_LOG(_("launching notification at %s for: \"%s\"\n"),
nowstr(), notify_app_txt());
if (!notify_launch_cmd())
@ -204,8 +190,7 @@ dmon_start (int parent_exit_status)
* Check if calcurse is running in background, and if yes, send a SIGINT
* signal to stop it.
*/
void
dmon_stop (void)
void dmon_stop(void)
{
int dpid;

View File

@ -44,27 +44,23 @@
llist_t eventlist;
static struct event bkp_cut_event;
void
event_free_bkp (void)
{
if (bkp_cut_event.mesg)
void event_free_bkp(void)
{
if (bkp_cut_event.mesg) {
mem_free(bkp_cut_event.mesg);
bkp_cut_event.mesg = 0;
}
erase_note(&bkp_cut_event.note);
}
static void
event_free (struct event *ev)
static void event_free(struct event *ev)
{
mem_free(ev->mesg);
erase_note(&ev->note);
mem_free(ev);
}
static void
event_dup (struct event *in, struct event *bkp)
static void event_dup(struct event *in, struct event *bkp)
{
EXIT_IF(!in || !bkp, _("null pointer"));
@ -75,28 +71,24 @@ event_dup (struct event *in, struct event *bkp)
bkp->note = mem_strdup(in->note);
}
void
event_llist_init (void)
void event_llist_init(void)
{
LLIST_INIT(&eventlist);
}
void
event_llist_free (void)
void event_llist_free(void)
{
LLIST_FREE_INNER(&eventlist, event_free);
LLIST_FREE(&eventlist);
}
static int
event_cmp_day (struct event *a, struct event *b)
static int event_cmp_day(struct event *a, struct event *b)
{
return a->day < b->day ? -1 : (a->day == b->day ? 0 : 1);
}
/* Create a new event */
struct event *
event_new (char *mesg, char *note, long day, int id)
struct event *event_new(char *mesg, char *note, long day, int id)
{
struct event *ev;
@ -112,15 +104,13 @@ event_new (char *mesg, char *note, long day, int id)
}
/* Check if the event belongs to the selected day */
unsigned
event_inday (struct event *i, long start)
unsigned event_inday(struct event *i, long start)
{
return (i->day < start + DAYINSEC && i->day >= start);
}
/* Write to file the event in user-friendly format */
void
event_write (struct event *o, FILE *f)
void event_write(struct event *o, FILE * f)
{
struct tm *lt;
time_t t;
@ -135,8 +125,7 @@ event_write (struct event *o, FILE *f)
}
/* Load the events from file */
struct event *
event_scan (FILE *f, struct tm start, int id, char *note)
struct event *event_scan(FILE * f, struct tm start, int id, char *note)
{
char buf[BUFSIZ], *nl;
time_t tstart, t;
@ -149,8 +138,7 @@ event_scan (FILE *f, struct tm start, int id, char *note)
return NULL;
nl = strchr(buf, '\n');
if (nl)
{
if (nl) {
*nl = '\0';
}
start.tm_hour = 0;
@ -167,8 +155,7 @@ event_scan (FILE *f, struct tm start, int id, char *note)
}
/* Retrieve an event from the list, given the day and item position. */
struct event *
event_get (long day, int pos)
struct event *event_get(long day, int pos)
{
llist_item_t *i = LLIST_FIND_NTH(&eventlist, pos, day, event_inday);
@ -180,8 +167,7 @@ event_get (long day, int pos)
}
/* Delete an event from the list. */
void
event_delete_bynum (long start, unsigned num, enum eraseflg flag)
void event_delete_bynum(long start, unsigned num, enum eraseflg flag)
{
llist_item_t *i = LLIST_FIND_NTH(&eventlist, num, start, event_inday);
@ -189,8 +175,7 @@ event_delete_bynum (long start, unsigned num, enum eraseflg flag)
EXIT(_("no such appointment"));
struct event *ev = LLIST_TS_GET_DATA(i);
switch (flag)
{
switch (flag) {
case ERASE_FORCE_ONLY_NOTE:
erase_note(&ev->note);
break;
@ -207,8 +192,7 @@ event_delete_bynum (long start, unsigned num, enum eraseflg flag)
}
}
void
event_paste_item (void)
void event_paste_item(void)
{
event_new(bkp_cut_event.mesg, bkp_cut_event.note,
date2sec(*calendar_get_slctd_day(), 0, 0), bkp_cut_event.id);

View File

@ -48,8 +48,7 @@ struct getstr_status {
};
/* Print the string at the desired position. */
static void
getstr_print (WINDOW *win, int x, int y, struct getstr_status *st)
static void getstr_print(WINDOW * win, int x, int y, struct getstr_status *st)
{
char c = 0;
@ -73,8 +72,7 @@ getstr_print (WINDOW *win, int x, int y, struct getstr_status *st)
}
/* Delete a character at the given position in string. */
static void
getstr_del_char (struct getstr_status *st)
static void getstr_del_char(struct getstr_status *st)
{
char *str = st->s + st->ci[st->pos].offset;
int cl = st->ci[st->pos + 1].offset - st->ci[st->pos].offset;
@ -84,16 +82,14 @@ getstr_del_char (struct getstr_status *st)
memmove(str, str + cl, strlen(str) + 1);
st->len--;
for (i = st->pos; i <= st->len; i++)
{
for (i = st->pos; i <= st->len; i++) {
st->ci[i].offset = st->ci[i + 1].offset - cl;
st->ci[i].dpyoff = st->ci[i + 1].dpyoff - cw;
}
}
/* Add a character at the given position in string. */
static void
getstr_ins_char (struct getstr_status *st, char *c)
static void getstr_ins_char(struct getstr_status *st, char *c)
{
char *str = st->s + st->ci[st->pos].offset;
int cl = UTF8_LENGTH(c[0]);
@ -104,16 +100,14 @@ getstr_ins_char (struct getstr_status *st, char *c)
for (i = 0; i < cl; i++, str++)
*str = c[i];
for (i = st->len; i >= st->pos; i--)
{
for (i = st->len; i >= st->pos; i--) {
st->ci[i + 1].offset = st->ci[i].offset + cl;
st->ci[i + 1].dpyoff = st->ci[i].dpyoff + cw;
}
st->len++;
}
static void
bell (void)
static void bell(void)
{
putchar('\a');
}
@ -128,8 +122,7 @@ getstr_init (struct getstr_status *st, char *str, struct getstr_charinfo *ci)
st->ci = ci;
st->len = width = 0;
while (*str)
{
while (*str) {
st->ci[st->len].offset = str - st->s;
st->ci[st->len].dpyoff = width;
@ -145,26 +138,21 @@ getstr_init (struct getstr_status *st, char *str, struct getstr_charinfo *ci)
}
/* Scroll left/right if the cursor moves outside the window range. */
static void
getstr_fixscr (struct getstr_status *st)
static void getstr_fixscr(struct getstr_status *st)
{
const int pgsize = col / 3;
int pgskip;
while (st->pos < st->scrpos)
{
while (st->pos < st->scrpos) {
pgskip = 0;
while (pgskip < pgsize && st->scrpos > 0)
{
while (pgskip < pgsize && st->scrpos > 0) {
st->scrpos--;
pgskip += st->ci[st->scrpos + 1].dpyoff - st->ci[st->scrpos].dpyoff;
}
}
while (st->ci[st->pos].dpyoff - st->ci[st->scrpos].dpyoff > col - 2)
{
while (st->ci[st->pos].dpyoff - st->ci[st->scrpos].dpyoff > col - 2) {
pgskip = 0;
while (pgskip < pgsize && st->scrpos < st->len)
{
while (pgskip < pgsize && st->scrpos < st->len) {
pgskip += st->ci[st->scrpos + 1].dpyoff - st->ci[st->scrpos].dpyoff;
st->scrpos++;
}
@ -179,8 +167,7 @@ getstr_fixscr (struct getstr_status *st)
* environment, otherwise the cursor would move from place to place without
* control.
*/
enum getstr
getstring (WINDOW *win, char *str, int l, int x, int y)
enum getstr getstring(WINDOW * win, char *str, int l, int x, int y)
{
struct getstr_status st;
struct getstr_charinfo ci[l + 1];
@ -196,19 +183,17 @@ getstring (WINDOW *win, char *str, int l, int x, int y)
getstr_print(win, x, y, &st);
wins_doupdate();
if ((ch = wgetch (win)) == '\n') break;
switch (ch)
{
if ((ch = wgetch(win)) == '\n')
break;
switch (ch) {
case KEY_BACKSPACE: /* delete one character */
case 330:
case 127:
case CTRL('H'):
if (st.pos > 0)
{
if (st.pos > 0) {
st.pos--;
getstr_del_char(&st);
}
else
} else
bell();
break;
case CTRL('D'): /* delete next character */
@ -219,18 +204,15 @@ getstring (WINDOW *win, char *str, int l, int x, int y)
break;
case CTRL('W'): /* delete a word */
if (st.pos > 0) {
while (st.pos && st.s[st.ci[st.pos - 1].offset] == ' ')
{
while (st.pos && st.s[st.ci[st.pos - 1].offset] == ' ') {
st.pos--;
getstr_del_char(&st);
}
while (st.pos && st.s[st.ci[st.pos - 1].offset] != ' ')
{
while (st.pos && st.s[st.ci[st.pos - 1].offset] != ' ') {
st.pos--;
getstr_del_char(&st);
}
}
else
} else
bell();
break;
case CTRL('K'): /* delete to end-of-line */
@ -245,11 +227,13 @@ getstring (WINDOW *win, char *str, int l, int x, int y)
break;
case KEY_LEFT: /* move one char backward */
case CTRL('B'):
if (st.pos > 0) st.pos--;
if (st.pos > 0)
st.pos--;
break;
case KEY_RIGHT: /* move one char forward */
case CTRL('F'):
if (st.pos < st.len) st.pos++;
if (st.pos < st.len)
st.pos++;
break;
case ESCAPE: /* cancel editing */
return GETSTRING_ESC;
@ -258,8 +242,7 @@ getstring (WINDOW *win, char *str, int l, int x, int y)
c[0] = ch;
for (k = 1; k < MIN(UTF8_LENGTH(c[0]), UTF8_MAXLEN); k++)
c[k] = (unsigned char)wgetch(win);
if (st.ci[st.len].offset + k < l)
{
if (st.ci[st.len].offset + k < l) {
getstr_ins_char(&st, c);
st.pos++;
}
@ -272,8 +255,7 @@ getstring (WINDOW *win, char *str, int l, int x, int y)
}
/* Update an already existing string. */
int
updatestring (WINDOW *win, char **str, int x, int y)
int updatestring(WINDOW * win, char **str, int x, int y)
{
int len = strlen(*str);
char *buf;
@ -286,8 +268,7 @@ updatestring (WINDOW *win, char **str, int x, int y)
ret = getstring(win, buf, BUFSIZ, x, y);
if (ret == GETSTRING_VALID)
{
if (ret == GETSTRING_VALID) {
len = strlen(buf);
*str = mem_realloc(*str, len + 1, 1);
EXIT_IF(*str == NULL, _("out of memory"));

View File

@ -48,8 +48,7 @@ typedef struct {
char text[HELPTEXTSIZ];
} help_page_t;
typedef enum
{
typedef enum {
HELP_MAIN,
HELP_SAVE,
HELP_IMPORT,
@ -74,18 +73,15 @@ typedef enum
HELP_CREDITS,
HELPSCREENS,
NOPAGE
}
help_pages_e;
} help_pages_e;
/* Returns the number of lines in an help text. */
static int
get_help_lines (char *text)
static int get_help_lines(char *text)
{
int i, newline;
newline = 0;
for (i = 0; text[i]; i++)
{
for (i = 0; text[i]; i++) {
if (text[i] == '\n')
newline++;
}
@ -109,8 +105,7 @@ help_write_pad (struct window *win, char *title, char *text, enum key action)
custom_apply_attr(win->p, ATTR_HIGHEST);
mvwprintw(win->p, rownum, colnum, "%s", title);
if ((int)action != KEY_RESIZE && action < NBKEYS) {
switch (action)
{
switch (action) {
case KEY_END_OF_WEEK:
case KEY_START_OF_WEEK:
case KEY_MOVE_UP:
@ -133,8 +128,7 @@ help_write_pad (struct window *win, char *title, char *text, enum key action)
default:
bindings = keys_action_allkeys(action);
if (bindings)
{
if (bindings) {
colnum = win->w - strlen(bindings_title) - strlen(bindings);
mvwprintw(win->p, rownum, colnum, bindings_title, bindings);
}
@ -152,8 +146,7 @@ help_write_pad (struct window *win, char *title, char *text, enum key action)
* Create and init help screen and its pad, which is used to make the scrolling
* faster.
*/
void
help_wins_init (struct scrollwin *hwin, int x, int y, int h, int w)
void help_wins_init(struct scrollwin *hwin, int x, int y, int h, int w)
{
const int PADOFFSET = 4;
const int TITLELINES = 3;
@ -177,8 +170,7 @@ help_wins_init (struct scrollwin *hwin, int x, int y, int h, int w)
* Delete the existing windows and recreate them with their new
* size and placement.
*/
static void
help_wins_reinit (struct scrollwin *hwin)
static void help_wins_reinit(struct scrollwin *hwin)
{
wins_scrollwin_delete(hwin);
wins_get_config();
@ -186,8 +178,7 @@ help_wins_reinit (struct scrollwin *hwin)
}
/* Reset the screen, needed when resizing terminal for example. */
static void
help_wins_reset (struct scrollwin *hwin)
static void help_wins_reset(struct scrollwin *hwin)
{
endwin();
wins_refresh();
@ -204,13 +195,11 @@ help_wins_reset (struct scrollwin *hwin)
}
/* Association between a key pressed and its corresponding help page. */
static int
wanted_page (int ch)
static int wanted_page(int ch)
{
int page;
switch (ch)
{
switch (ch) {
case KEY_GENERIC_HELP:
page = HELP_MAIN;
@ -323,8 +312,7 @@ wanted_page (int ch)
}
/* Draws the help screen */
void
help_screen (void)
void help_screen(void)
{
enum {
MOVE_UP,
@ -343,7 +331,8 @@ help_screen (void)
hscr[HELP_MAIN].title =
_(" Welcome to Calcurse. This is the main help screen.\n");
snprintf(hscr[HELP_MAIN].text, HELPTEXTSIZ,
_("Moving around: Press '%s' or '%s' to scroll text upward or downward\n"
_
("Moving around: Press '%s' or '%s' to scroll text upward or downward\n"
" inside help screens, if necessary.\n\n"
" Exit help: When finished, press '%s' to exit help and go back to\n"
" the main Calcurse screen.\n\n"
@ -410,12 +399,9 @@ help_screen (void)
" events, appointments, todos.\n"));
strncpy(keystr[MOVE_UP], keys_action_allkeys(KEY_MOVE_UP), BUFSIZ);
strncpy (keystr[MOVE_DOWN], keys_action_allkeys (KEY_MOVE_DOWN),
BUFSIZ);
strncpy (keystr[MOVE_LEFT], keys_action_allkeys (KEY_MOVE_LEFT),
BUFSIZ);
strncpy (keystr[MOVE_RIGHT], keys_action_allkeys (KEY_MOVE_RIGHT),
BUFSIZ);
strncpy(keystr[MOVE_DOWN], keys_action_allkeys(KEY_MOVE_DOWN), BUFSIZ);
strncpy(keystr[MOVE_LEFT], keys_action_allkeys(KEY_MOVE_LEFT), BUFSIZ);
strncpy(keystr[MOVE_RIGHT], keys_action_allkeys(KEY_MOVE_RIGHT), BUFSIZ);
hscr[HELP_DISPLACEMENT].title = _("Displacement keys\n");
snprintf(hscr[HELP_DISPLACEMENT].text, HELPTEXTSIZ,
_("Move around inside calcurse screens.\n"
@ -445,7 +431,8 @@ help_screen (void)
hscr[HELP_VIEW].title = _("View\n");
snprintf(hscr[HELP_VIEW].text, HELPTEXTSIZ,
_("View the item you select in either the Todo or Appointment panel.\n"
_
("View the item you select in either the Todo or Appointment panel.\n"
"\nThis is usefull when an event description is longer than the "
"available\nspace to display it. "
"If that is the case, the description will be\n"
@ -453,8 +440,7 @@ help_screen (void)
"description, just press '%s' and a popup window will appear, containing\n"
"the whole event.\n"
"\nPress any key to close the popup window and go back to the main\n"
"Calcurse screen."),
keys_action_firstkey (KEY_VIEW_ITEM));
"Calcurse screen."), keys_action_firstkey(KEY_VIEW_ITEM));
hscr[HELP_PIPE].title = _("Pipe\n");
snprintf(hscr[HELP_PIPE].text, HELPTEXTSIZ,
@ -506,7 +492,8 @@ help_screen (void)
hscr[HELP_ADD].title = _("Add\n");
snprintf(hscr[HELP_ADD].text, HELPTEXTSIZ,
_("Add an item in either the ToDo or Appointment list, depending on which\n"
_
("Add an item in either the ToDo or Appointment list, depending on which\n"
"panel is selected when you press '%s'.\n"
"\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 "
@ -543,7 +530,8 @@ help_screen (void)
hscr[HELP_CUT_PASTE].title = _("Cut and Paste\n");
snprintf(hscr[HELP_CUT_PASTE].text, HELPTEXTSIZ,
_("Cut and paste the currently selected item. This is useful to quickly\n"
_
("Cut and paste the currently selected item. This is useful to quickly\n"
"move an item from one date to another.\n"
"To do so, one must first highlight the item that needs to be moved,\n"
"then press '%s' to cut this item. It will be removed from the panel.\n"
@ -576,7 +564,8 @@ help_screen (void)
hscr[HELP_ENOTE].title = _("EditNote\n");
snprintf(hscr[HELP_ENOTE].text, HELPTEXTSIZ,
_("Attach a note to any type of item, or edit an already existing note.\n"
_
("Attach a note to any type of item, or edit an already existing note.\n"
"This feature is useful if you do not have enough space to store all\n"
"of your item description, or if you would like to add sub-tasks to an\n"
"already existing todo item for example.\n"
@ -597,26 +586,26 @@ help_screen (void)
hscr[HELP_VNOTE].title = _("ViewNote\n");
snprintf(hscr[HELP_VNOTE].text, HELPTEXTSIZ,
_("View a note which was previously attached to an item (an item which\n"
_
("View a note which was previously attached to an item (an item which\n"
"owns a note has a '>' sign in front of it).\n"
"This command only permits to view the note, not to edit it (to do so,\n"
"use the 'EditNote' command, by pressing the '%s' key).\n"
"Once you highlighted an item with a note attached to it, and the '%s' key"
"\nwas pressed, you will be driven to an external pager to view that "
"note.\n"
"The default pager is chosen the following way:\n"
"note.\n" "The default pager is chosen the following way:\n"
" o if the 'PAGER' environment variable is set, then this will be\n"
" the default viewer to be called.\n"
" o if the above environment variable is not set, then\n"
" '/usr/bin/less' will be used.\n"
"As for editing a note, quit the pager and you will be driven back to\n"
"Calcurse."),
keys_action_firstkey (KEY_EDIT_NOTE),
"Calcurse."), keys_action_firstkey(KEY_EDIT_NOTE),
keys_action_firstkey(KEY_VIEW_NOTE));
hscr[HELP_PRIORITY].title = _("Priority\n");
snprintf(hscr[HELP_PRIORITY].text, HELPTEXTSIZ,
_("Change the priority of the currently selected item in the ToDo list.\n"
_
("Change the priority of the currently selected item in the ToDo list.\n"
"Priorities are represented by the number appearing in front of the\n"
"todo description. This number goes from 9 for the lowest priority to\n"
"1 for the highest priority.\n"
@ -661,7 +650,8 @@ help_screen (void)
hscr[HELP_FLAG].title = _("Flag Item\n");
snprintf(hscr[HELP_FLAG].text, HELPTEXTSIZ,
_("Toggle an appointment's 'important' flag or a todo's 'completed' flag.\n"
_
("Toggle an appointment's 'important' flag or a todo's 'completed' flag.\n"
"If a todo is flagged as completed, its priority number will be replaced\n"
"by an 'X' sign. Completed tasks will no longer appear in exported data\n"
"or when using the '-t' command line flag (unless specifying '0' as the\n"
@ -690,7 +680,8 @@ help_screen (void)
hscr[HELP_GENERAL].title = _("Generic keybindings\n");
snprintf(hscr[HELP_GENERAL].text, HELPTEXTSIZ,
_("Some of the keybindings apply whatever panel is selected. They are\n"
_
("Some of the keybindings apply whatever panel is selected. They are\n"
"called generic keybinding.\n"
"Here is the list of all the generic key bindings, together with their\n"
"corresponding action:\n\n"
@ -756,10 +747,8 @@ help_screen (void)
need_resize = 0;
/* Display the help screen related to user input. */
while (ch != KEY_GENERIC_QUIT)
{
erase_window_part (hwin.win.p, 1, hwin.pad.y, col - 2,
hwin.win.h - 2);
while (ch != KEY_GENERIC_QUIT) {
erase_window_part(hwin.win.p, 1, hwin.pad.y, col - 2, hwin.win.h - 2);
switch (ch) {
case KEY_GENERIC_SCROLL_DOWN:
@ -780,8 +769,7 @@ help_screen (void)
}
}
if (resize)
{
if (resize) {
resize = 0;
wins_get_config();
help_wins_reset(&hwin);

View File

@ -72,8 +72,7 @@ static const char *ical_recur_type[RECUR_TYPES] =
{ "", "DAILY", "WEEKLY", "MONTHLY", "YEARLY" };
/* iCal alarm notification. */
static void
ical_export_valarm (FILE *stream)
static void ical_export_valarm(FILE * stream)
{
fputs("BEGIN:VALARM\n", stream);
pthread_mutex_lock(&nbar.mutex);
@ -84,8 +83,7 @@ ical_export_valarm (FILE *stream)
}
/* Export header. */
static void
ical_export_header (FILE *stream)
static void ical_export_header(FILE * stream)
{
fputs("BEGIN:VCALENDAR\n", stream);
fprintf(stream, "PRODID:-//calcurse//NONSGML v%s//EN\n", VERSION);
@ -93,21 +91,18 @@ ical_export_header (FILE *stream)
}
/* Export footer. */
static void
ical_export_footer (FILE *stream)
static void ical_export_footer(FILE * stream)
{
fputs("END:VCALENDAR\n", stream);
}
/* Export recurrent events. */
static void
ical_export_recur_events (FILE *stream)
static void ical_export_recur_events(FILE * stream)
{
llist_item_t *i, *j;
char ical_date[BUFSIZ];
LLIST_FOREACH (&recur_elist, i)
{
LLIST_FOREACH(&recur_elist, i) {
struct recur_event *rev = LLIST_GET_DATA(i);
date_sec2date_fmt(rev->day, ICALDATEFMT, ical_date);
fputs("BEGIN:VEVENT\n", stream);
@ -115,19 +110,15 @@ ical_export_recur_events (FILE *stream)
fprintf(stream, "RRULE:FREQ=%s;INTERVAL=%d",
ical_recur_type[rev->rpt->type], rev->rpt->freq);
if (rev->rpt->until != 0)
{
if (rev->rpt->until != 0) {
date_sec2date_fmt(rev->rpt->until, ICALDATEFMT, ical_date);
fprintf(stream, ";UNTIL=%s\n", ical_date);
}
else
} else
fputc('\n', stream);
if (LLIST_FIRST (&rev->exc))
{
if (LLIST_FIRST(&rev->exc)) {
fputs("EXDATE:", stream);
LLIST_FOREACH (&rev->exc, j)
{
LLIST_FOREACH(&rev->exc, j) {
struct excp *exc = LLIST_GET_DATA(j);
date_sec2date_fmt(exc->st, ICALDATEFMT, ical_date);
fprintf(stream, "%s", ical_date);
@ -144,14 +135,12 @@ ical_export_recur_events (FILE *stream)
}
/* Export events. */
static void
ical_export_events (FILE *stream)
static void ical_export_events(FILE * stream)
{
llist_item_t *i;
char ical_date[BUFSIZ];
LLIST_FOREACH (&eventlist, i)
{
LLIST_FOREACH(&eventlist, i) {
struct event *ev = LLIST_TS_GET_DATA(i);
date_sec2date_fmt(ev->day, ICALDATEFMT, ical_date);
fputs("BEGIN:VEVENT\n", stream);
@ -162,16 +151,14 @@ ical_export_events (FILE *stream)
}
/* Export recurrent appointments. */
static void
ical_export_recur_apoints (FILE *stream)
static void ical_export_recur_apoints(FILE * stream)
{
llist_item_t *i, *j;
char ical_datetime[BUFSIZ];
char ical_date[BUFSIZ];
LLIST_TS_LOCK(&recur_alist_p);
LLIST_TS_FOREACH (&recur_alist_p, i)
{
LLIST_TS_FOREACH(&recur_alist_p, i) {
struct recur_apoint *rapt = LLIST_TS_GET_DATA(i);
date_sec2date_fmt(rapt->start, ICALDATETIMEFMT, ical_datetime);
@ -181,20 +168,15 @@ ical_export_recur_apoints (FILE *stream)
fprintf(stream, "RRULE:FREQ=%s;INTERVAL=%d",
ical_recur_type[rapt->rpt->type], rapt->rpt->freq);
if (rapt->rpt->until != 0)
{
date_sec2date_fmt (rapt->rpt->until + HOURINSEC, ICALDATEFMT,
ical_date);
if (rapt->rpt->until != 0) {
date_sec2date_fmt(rapt->rpt->until + HOURINSEC, ICALDATEFMT, ical_date);
fprintf(stream, ";UNTIL=%s\n", ical_date);
}
else
} else
fputc('\n', stream);
if (LLIST_FIRST (&rapt->exc))
{
if (LLIST_FIRST(&rapt->exc)) {
fputs("EXDATE:", stream);
LLIST_FOREACH (&rapt->exc, j)
{
LLIST_FOREACH(&rapt->exc, j) {
struct excp *exc = LLIST_GET_DATA(j);
date_sec2date_fmt(exc->st, ICALDATEFMT, ical_date);
fprintf(stream, "%s", ical_date);
@ -214,15 +196,13 @@ ical_export_recur_apoints (FILE *stream)
}
/* Export appointments. */
static void
ical_export_apoints (FILE *stream)
static void ical_export_apoints(FILE * stream)
{
llist_item_t *i;
char ical_datetime[BUFSIZ];
LLIST_TS_LOCK(&alist_p);
LLIST_TS_FOREACH (&alist_p, i)
{
LLIST_TS_FOREACH(&alist_p, i) {
struct apoint *apt = LLIST_TS_GET_DATA(i);
date_sec2date_fmt(apt->start, ICALDATETIMEFMT, ical_datetime);
fputs("BEGIN:VEVENT\n", stream);
@ -230,8 +210,7 @@ ical_export_apoints (FILE *stream)
fprintf(stream, "DURATION:P%ldDT%ldH%ldM%ldS\n",
apt->dur / DAYINSEC,
(apt->dur / HOURINSEC) % DAYINHOURS,
(apt->dur / MININSEC) % HOURINMIN,
apt->dur % MININSEC);
(apt->dur / MININSEC) % HOURINMIN, apt->dur % MININSEC);
fprintf(stream, "SUMMARY:%s\n", apt->mesg);
if (apt->state & APOINT_NOTIFY)
ical_export_valarm(stream);
@ -241,13 +220,11 @@ ical_export_apoints (FILE *stream)
}
/* Export todo items. */
static void
ical_export_todo (FILE *stream)
static void ical_export_todo(FILE * stream)
{
llist_item_t *i;
LLIST_FOREACH (&todolist, i)
{
LLIST_FOREACH(&todolist, i) {
struct todo *todo = LLIST_TS_GET_DATA(i);
if (todo->id < 0) /* completed items */
continue;
@ -260,8 +237,7 @@ ical_export_todo (FILE *stream)
}
/* Print a header to describe import log report format. */
static void
ical_log_init (FILE *log, float version)
static void ical_log_init(FILE * log, float version)
{
const char *header =
"+-------------------------------------------------------------------+\n"
@ -289,8 +265,7 @@ ical_log_init (FILE *log, float version)
* first line inside the icalendar file), together with a message describing the
* problem.
*/
static void
ical_log (FILE *log, ical_types_e type, unsigned lineno, char *msg)
static void ical_log(FILE * log, ical_types_e type, unsigned lineno, char *msg)
{
const char *typestr[ICAL_TYPES] = { "VEVENT", "VTODO" };
@ -299,8 +274,7 @@ ical_log (FILE *log, ical_types_e type, unsigned lineno, char *msg)
fprintf(log, "%s [%d]: %s\n", typestr[type], lineno, msg);
}
static void
ical_store_todo (int priority, char *mesg, char *note)
static void ical_store_todo(int priority, char *mesg, char *note)
{
todo_add(mesg, priority, note);
mem_free(mesg);
@ -313,14 +287,11 @@ ical_store_event (char *mesg, char *note, long day, long end, ical_rpt_t *rpt,
{
const int EVENTID = 1;
if (rpt)
{
if (rpt) {
recur_event_new(mesg, note, day, EVENTID, rpt->type, rpt->freq,
rpt->until, exc);
mem_free(rpt);
}
else if (end && end != day)
{
} else if (end && end != day) {
/* Here we have an event that spans over several days. */
rpt = mem_malloc(sizeof(ical_rpt_t));
rpt->type = RECUR_DAILY;
@ -330,9 +301,7 @@ ical_store_event (char *mesg, char *note, long day, long end, ical_rpt_t *rpt,
recur_event_new(mesg, note, day, EVENTID, rpt->type, rpt->freq,
rpt->until, exc);
mem_free(rpt);
}
else
{
} else {
event_new(mesg, note, day, EVENTID);
}
mem_free(mesg);
@ -347,14 +316,11 @@ ical_store_apoint (char *mesg, char *note, long start, long dur,
if (has_alarm)
state |= APOINT_NOTIFY;
if (rpt)
{
if (rpt) {
recur_apoint_new(mesg, note, start, dur, state, rpt->type, rpt->freq,
rpt->until, exc);
mem_free(rpt);
}
else
{
} else {
apoint_new(mesg, note, start, dur, state);
}
mem_free(mesg);
@ -374,8 +340,7 @@ ical_store_apoint (char *mesg, char *note, long start, long dur,
* Lines of text SHOULD NOT be longer than 75 octets, excluding the line
* break.
*/
static char *
ical_unformat_line (char *line)
static char *ical_unformat_line(char *line)
{
char *p, uline[BUFSIZ];
int len;
@ -384,13 +349,10 @@ ical_unformat_line (char *line)
return NULL;
memset(uline, 0, BUFSIZ);
for (len = 0, p = line; *p; p++)
{
switch (*p)
{
for (len = 0, p = line; *p; p++) {
switch (*p) {
case '\\':
switch (*(p + 1))
{
switch (*(p + 1)) {
case 'n':
uline[len++] = '\n';
p++;
@ -425,24 +387,21 @@ ical_readline_init (FILE *fdi, char *buf, char *lstore, unsigned *ln)
char *eol;
*buf = *lstore = '\0';
if (fgets (lstore, BUFSIZ, fdi))
{
if (fgets(lstore, BUFSIZ, fdi)) {
if ((eol = strchr(lstore, '\n')) != NULL)
*eol = '\0';
(*ln)++;
}
}
static int
ical_readline (FILE *fdi, char *buf, char *lstore, unsigned *ln)
static int ical_readline(FILE * fdi, char *buf, char *lstore, unsigned *ln)
{
char *eol;
strncpy(buf, lstore, BUFSIZ);
(*ln)++;
while (fgets (lstore, BUFSIZ, fdi) != NULL)
{
while (fgets(lstore, BUFSIZ, fdi) != NULL) {
if ((eol = strchr(lstore, '\n')) != NULL)
*eol = '\0';
if (*lstore != SPACE && *lstore != TAB)
@ -451,8 +410,7 @@ ical_readline (FILE *fdi, char *buf, char *lstore, unsigned *ln)
(*ln)++;
}
if (feof (fdi))
{
if (feof(fdi)) {
*lstore = '\0';
if (*buf == '\0')
return 0;
@ -475,8 +433,7 @@ ical_chk_header (FILE *fd, char *buf, char *lstore, unsigned *lineno)
if (strncmp(buf, icalheader, sizeof(icalheader) - 1) != 0)
return HEADER_MALFORMED;
while (!sscanf (buf, "VERSION:%f", &version))
{
while (!sscanf(buf, "VERSION:%f", &version)) {
if (!ical_readline(fd, buf, lstore, lineno))
return HEADER_MALFORMED;
}
@ -495,8 +452,7 @@ ical_chk_header (FILE *fd, char *buf, char *lstore, unsigned *lineno)
*
* The timezone is not yet handled by calcurse.
*/
static long
ical_datetime2long (char *datestr, ical_vevent_e *type)
static long ical_datetime2long(char *datestr, ical_vevent_e * type)
{
const int NOTFOUND = 0, FORMAT_DATE = 3, FORMAT_DATETIME = 5;
struct date date;
@ -506,35 +462,28 @@ ical_datetime2long (char *datestr, ical_vevent_e *type)
format = sscanf(datestr, "%04u%02u%02uT%02u%02u",
&date.yyyy, &date.mm, &date.dd, &hour, &min);
if (format == FORMAT_DATE)
{
if (format == FORMAT_DATE) {
if (type)
*type = EVENT;
datelong = date2sec(date, 0, 0);
}
else if (format == FORMAT_DATETIME)
{
} else if (format == FORMAT_DATETIME) {
if (type)
*type = APPOINTMENT;
datelong = date2sec(date, hour, min);
}
else
{
} else {
datelong = NOTFOUND;
}
return datelong;
}
static long
ical_durtime2long (char *timestr)
static long ical_durtime2long(char *timestr)
{
long timelong;
char *p;
if ((p = strchr(timestr, 'T')) == NULL)
timelong = 0;
else
{
else {
int nbmatch;
struct {
unsigned hour, min, sec;
@ -576,8 +525,7 @@ ical_durtime2long (char *timestr)
* A duration of 7 weeks would be:
* P7W
*/
static long
ical_dur2long (char *durstr)
static long ical_dur2long(char *durstr)
{
const int NOTFOUND = -1;
long durlong;
@ -589,8 +537,7 @@ ical_dur2long (char *durstr)
memset(&date, 0, sizeof date);
if ((p = strchr(durstr, 'P')) == NULL)
durlong = NOTFOUND;
else
{
else {
p++;
if (*p == '-')
return NOTFOUND;
@ -599,26 +546,19 @@ ical_dur2long (char *durstr)
if (*p == 'T') /* dur-time */
durlong = ical_durtime2long(p);
else if (strchr (p, 'W')) /* dur-week */
{
else if (strchr(p, 'W')) { /* dur-week */
if (sscanf(p, "%u", &date.week) == 1)
durlong = date.week * WEEKINDAYS * DAYINSEC;
else
durlong = NOTFOUND;
}
else
{
if (strchr (p, 'D')) /* dur-date */
{
if (sscanf (p, "%uD", &date.day) == 1)
{
} else {
if (strchr(p, 'D')) { /* dur-date */
if (sscanf(p, "%uD", &date.day) == 1) {
durlong = date.day * DAYINSEC;
durlong += ical_durtime2long(p);
}
else
} else
durlong = NOTFOUND;
}
else
} else
durlong = NOTFOUND;
}
}
@ -633,13 +573,11 @@ ical_dur2long (char *durstr)
* range-bound the recurrence. The "DTSTART" property value, if specified,
* counts as the first occurrence.
*/
static long
ical_compute_rpt_until (long start, ical_rpt_t *rpt)
static long ical_compute_rpt_until(long start, ical_rpt_t * rpt)
{
long until;
switch (rpt->type)
{
switch (rpt->type) {
case RECUR_DAILY:
until = date_sec_change(start, 0, rpt->freq * (rpt->count - 1));
break;
@ -698,9 +636,8 @@ ical_compute_rpt_until (long start, ical_rpt_t *rpt)
* ( ";" x-name "=" text )
* )
*/
static ical_rpt_t *
ical_read_rrule (FILE *log, char *rrulestr, unsigned *noskipped,
const int itemline)
static ical_rpt_t *ical_read_rrule(FILE * log, char *rrulestr,
unsigned *noskipped, const int itemline)
{
const char daily[] = "DAILY";
const char weekly[] = "WEEKLY";
@ -713,23 +650,19 @@ ical_read_rrule (FILE *log, char *rrulestr, unsigned *noskipped,
char *p;
rpt = NULL;
if ((p = strchr (rrulestr, ':')) != NULL)
{
if ((p = strchr(rrulestr, ':')) != NULL) {
char freqstr[BUFSIZ];
p++;
rpt = mem_malloc(sizeof(ical_rpt_t));
memset(rpt, 0, sizeof(ical_rpt_t));
if (sscanf (p, "FREQ=%s", freqstr) != 1)
{
if (sscanf(p, "FREQ=%s", freqstr) != 1) {
ical_log(log, ICAL_VEVENT, itemline,
_("recurrence frequence not found."));
(*noskipped)++;
mem_free(rpt);
return NULL;
}
else
{
} else {
if (strncmp(freqstr, daily, sizeof(daily) - 1) == 0)
rpt->type = RECUR_DAILY;
else if (strncmp(freqstr, weekly, sizeof(weekly) - 1) == 0)
@ -738,8 +671,7 @@ ical_read_rrule (FILE *log, char *rrulestr, unsigned *noskipped,
rpt->type = RECUR_MONTHLY;
else if (strncmp(freqstr, yearly, sizeof(yearly) - 1) == 0)
rpt->type = RECUR_YEARLY;
else
{
else {
ical_log(log, ICAL_VEVENT, itemline,
_("recurrence frequence not recognized."));
(*noskipped)++;
@ -757,66 +689,48 @@ ical_read_rrule (FILE *log, char *rrulestr, unsigned *noskipped,
range-bound the recurrence. The "DTSTART" property value, if
specified, counts as the first occurrence.
*/
if ((p = strstr (rrulestr, "UNTIL")) != NULL)
{
if ((p = strstr(rrulestr, "UNTIL")) != NULL) {
char *untilstr;
untilstr = strchr(p, '=');
rpt->until = ical_datetime2long(++untilstr, NULL);
}
else
{
} else {
unsigned cnt;
char *countstr;
if ((countstr = strstr (rrulestr, count)) != NULL)
{
if ((countstr = strstr(rrulestr, count)) != NULL) {
countstr += sizeof(count) - 1;
if (sscanf (countstr, "%u", &cnt) != 1)
{
if (sscanf(countstr, "%u", &cnt) != 1) {
rpt->until = 0;
/* endless repetition */
}
else
{
} else {
rpt->count = cnt;
}
}
else
} else
rpt->until = 0;
}
if ((p = strstr (rrulestr, interv)) != NULL)
{
if ((p = strstr(rrulestr, interv)) != NULL) {
p += sizeof(interv) - 1;
if (sscanf (p, "%u", &interval) != 1)
{
if (sscanf(p, "%u", &interval) != 1) {
rpt->freq = 1;
/* default frequence if none specified */
}
else
{
} else {
rpt->freq = interval;
}
}
else
{
} else {
rpt->freq = 1;
}
}
else
{
} else {
ical_log(log, ICAL_VEVENT, itemline, _("recurrence rule malformed."));
(*noskipped)++;
}
return rpt;
}
static void
ical_add_exc (llist_t *exc_head, long date)
{
if (date != 0)
static void ical_add_exc(llist_t * exc_head, long date)
{
if (date != 0) {
struct excp *exc = mem_malloc(sizeof(struct excp));
exc->st = date;
@ -836,11 +750,9 @@ ical_read_exdate (llist_t *exc, FILE *log, char *exstr, unsigned *noskipped,
long date;
LLIST_INIT(exc);
if ((p = strchr (exstr, ':')) != NULL)
{
if ((p = strchr(exstr, ':')) != NULL) {
p++;
while ((q = strchr (p, ',')) != NULL)
{
while ((q = strchr(p, ',')) != NULL) {
char buf[BUFSIZ];
const int buflen = q - p;
@ -852,9 +764,7 @@ ical_read_exdate (llist_t *exc, FILE *log, char *exstr, unsigned *noskipped,
}
date = ical_datetime2long(p, NULL);
ical_add_exc(exc, date);
}
else
{
} else {
ical_log(log, ICAL_VEVENT, itemline,
_("recurrence exception dates malformed."));
(*noskipped)++;
@ -862,37 +772,29 @@ ical_read_exdate (llist_t *exc, FILE *log, char *exstr, unsigned *noskipped,
}
/* Return an allocated string containing the name of the newly created note. */
static char *
ical_read_note (char *line, unsigned *noskipped, ical_vevent_e item_type,
const int itemline, FILE *log)
static char *ical_read_note(char *line, unsigned *noskipped,
ical_vevent_e item_type, const int itemline,
FILE * log)
{
char *p, *notestr, *note;
if ((p = strchr (line, ':')) != NULL)
{
if ((p = strchr(line, ':')) != NULL) {
p++;
notestr = ical_unformat_line(p);
if (notestr == NULL)
{
if (notestr == NULL) {
ical_log(log, item_type, itemline,
_("could not get entire item description."));
(*noskipped)++;
return NULL;
}
else if (strlen (notestr) == 0)
{
} else if (strlen(notestr) == 0) {
mem_free(notestr);
return NULL;
}
else
{
} else {
note = generate_note(notestr);
mem_free(notestr);
return note;
}
}
else
{
} else {
ical_log(log, item_type, itemline, _("description malformed."));
(*noskipped)++;
return NULL;
@ -900,25 +802,21 @@ ical_read_note (char *line, unsigned *noskipped, ical_vevent_e item_type,
}
/* Returns an allocated string containing the ical item summary. */
static char *
ical_read_summary (char *line)
static char *ical_read_summary(char *line)
{
char *p, *summary;
if ((p = strchr (line, ':')) != NULL)
{
if ((p = strchr(line, ':')) != NULL) {
p++;
summary = ical_unformat_line(p);
return summary;
}
else
} else
return NULL;
}
static void
ical_read_event(FILE * fdi, FILE * log, unsigned *noevents, unsigned *noapoints,
unsigned *noskipped, char *buf, char *lstore,
unsigned *lineno)
unsigned *noskipped, char *buf, char *lstore, unsigned *lineno)
{
const int ITEMLINE = *lineno;
const char endevent[] = "END:VEVENT";
@ -945,48 +843,36 @@ ical_read_event (FILE *fdi, FILE *log, unsigned *noevents, unsigned *noapoints,
vevent_type = UNDEFINED;
memset(&vevent, 0, sizeof vevent);
skip_alarm = 0;
while (ical_readline (fdi, buf, lstore, lineno))
{
while (ical_readline(fdi, buf, lstore, lineno)) {
strncpy(buf_upper, buf, BUFSIZ);
buf_upper[BUFSIZ - 1] = '\0';
str_toupper(buf_upper);
if (skip_alarm)
{
if (skip_alarm) {
/* Need to skip VALARM properties because some keywords could
interfere, such as DURATION, SUMMARY,.. */
if (strncmp(buf_upper, endalarm, sizeof(endalarm) - 1) == 0)
skip_alarm = 0;
continue;
}
if (strncmp (buf_upper, endevent, sizeof (endevent) - 1) == 0)
{
if (vevent.mesg)
{
if (strncmp(buf_upper, endevent, sizeof(endevent) - 1) == 0) {
if (vevent.mesg) {
if (vevent.rpt && vevent.rpt->count)
vevent.rpt->until = ical_compute_rpt_until (vevent.start,
vevent.rpt);
vevent.rpt->until = ical_compute_rpt_until(vevent.start, vevent.rpt);
switch (vevent_type)
{
switch (vevent_type) {
case APPOINTMENT:
if (vevent.start == 0)
{
if (vevent.start == 0) {
ical_log(log, ICAL_VEVENT, ITEMLINE,
_("appointment has no start time."));
goto cleanup;
}
if (vevent.dur == 0)
{
if (vevent.end == 0)
{
if (vevent.dur == 0) {
if (vevent.end == 0) {
ical_log(log, ICAL_VEVENT, ITEMLINE,
_("could not compute duration "
"(no end time)."));
_("could not compute duration " "(no end time)."));
goto cleanup;
}
else if (vevent.start == vevent.end)
{
} else if (vevent.start == vevent.end) {
vevent_type = EVENT;
vevent.end = 0L;
ical_store_event(vevent.mesg, vevent.note,
@ -994,12 +880,9 @@ ical_read_event (FILE *fdi, FILE *log, unsigned *noevents, unsigned *noapoints,
vevent.rpt, &vevent.exc);
(*noevents)++;
return;
}
else
{
} else {
vevent.dur = vevent.end - vevent.start;
if (vevent.dur < 0)
{
if (vevent.dur < 0) {
ical_log(log, ICAL_VEVENT, ITEMLINE,
_("item has a negative duration."));
goto cleanup;
@ -1012,8 +895,7 @@ ical_read_event (FILE *fdi, FILE *log, unsigned *noevents, unsigned *noapoints,
(*noapoints)++;
break;
case EVENT:
if (vevent.start == 0)
{
if (vevent.start == 0) {
ical_log(log, ICAL_VEVENT, ITEMLINE,
_("event date is not defined."));
goto cleanup;
@ -1028,67 +910,44 @@ ical_read_event (FILE *fdi, FILE *log, unsigned *noevents, unsigned *noapoints,
goto cleanup;
break;
}
}
else
{
} else {
ical_log(log, ICAL_VEVENT, ITEMLINE,
_("could not retrieve item summary."));
goto cleanup;
}
return;
}
else
{
if (strncmp (buf_upper, dtstart, sizeof (dtstart) - 1) == 0)
{
} else {
if (strncmp(buf_upper, dtstart, sizeof(dtstart) - 1) == 0) {
if ((p = strchr(buf, ':')) != NULL)
vevent.start = ical_datetime2long(++p, &vevent_type);
if (!vevent.start)
{
if (!vevent.start) {
ical_log(log, ICAL_VEVENT, ITEMLINE,
_("could not retrieve event start time."));
goto cleanup;
}
}
else if (strncmp (buf_upper, dtend, sizeof (dtend) - 1) == 0)
{
} else if (strncmp(buf_upper, dtend, sizeof(dtend) - 1) == 0) {
if ((p = strchr(buf, ':')) != NULL)
vevent.end = ical_datetime2long(++p, &vevent_type);
if (!vevent.end)
{
if (!vevent.end) {
ical_log(log, ICAL_VEVENT, ITEMLINE,
_("could not retrieve event end time."));
goto cleanup;
}
}
else if (strncmp (buf_upper, duration, sizeof (duration) - 1) == 0)
{
if ((vevent.dur = ical_dur2long (buf)) <= 0)
{
ical_log (log, ICAL_VEVENT, ITEMLINE,
_("item duration malformed."));
} else if (strncmp(buf_upper, duration, sizeof(duration) - 1) == 0) {
if ((vevent.dur = ical_dur2long(buf)) <= 0) {
ical_log(log, ICAL_VEVENT, ITEMLINE, _("item duration malformed."));
goto cleanup;
}
}
else if (strncmp (buf_upper, rrule, sizeof (rrule) - 1) == 0)
{
} else if (strncmp(buf_upper, rrule, sizeof(rrule) - 1) == 0) {
vevent.rpt = ical_read_rrule(log, buf, noskipped, ITEMLINE);
}
else if (strncmp (buf_upper, exdate, sizeof (exdate) - 1) == 0)
{
} else if (strncmp(buf_upper, exdate, sizeof(exdate) - 1) == 0) {
ical_read_exdate(&vevent.exc, log, buf, noskipped, ITEMLINE);
}
else if (strncmp (buf_upper, summary, sizeof (summary) - 1) == 0)
{
} else if (strncmp(buf_upper, summary, sizeof(summary) - 1) == 0) {
vevent.mesg = ical_read_summary(buf);
}
else if (strncmp (buf_upper, alarm, sizeof (alarm) - 1) == 0)
{
} else if (strncmp(buf_upper, alarm, sizeof(alarm) - 1) == 0) {
skip_alarm = 1;
vevent.has_alarm = 1;
}
else if (strncmp (buf_upper, desc, sizeof (desc) - 1) == 0)
{
} else if (strncmp(buf_upper, desc, sizeof(desc) - 1) == 0) {
vevent.note = ical_read_note(buf, noskipped, ICAL_VEVENT,
ITEMLINE, log);
}
@ -1130,67 +989,48 @@ ical_read_todo (FILE *fdi, FILE *log, unsigned *notodos, unsigned *noskipped,
memset(&vtodo, 0, sizeof vtodo);
skip_alarm = 0;
while (ical_readline (fdi, buf, lstore, lineno))
{
while (ical_readline(fdi, buf, lstore, lineno)) {
strncpy(buf_upper, buf, BUFSIZ);
buf_upper[BUFSIZ - 1] = '\0';
str_toupper(buf_upper);
if (skip_alarm)
{
if (skip_alarm) {
/* Need to skip VALARM properties because some keywords could
interfere, such as DURATION, SUMMARY,.. */
if (strncmp(buf_upper, endalarm, sizeof(endalarm) - 1) == 0)
skip_alarm = 0;
continue;
}
if (strncmp (buf_upper, endtodo, sizeof (endtodo) - 1) == 0)
{
if (strncmp(buf_upper, endtodo, sizeof(endtodo) - 1) == 0) {
if (!vtodo.has_priority)
vtodo.priority = LOWEST;
if (vtodo.mesg)
{
if (vtodo.mesg) {
ical_store_todo(vtodo.priority, vtodo.mesg, vtodo.note);
(*notodos)++;
}
else
{
} else {
ical_log(log, ICAL_VTODO, ITEMLINE,
_("could not retrieve item summary."));
goto cleanup;
}
return;
}
else
{
} else {
int tmpint;
if (sscanf (buf_upper, "PRIORITY:%d", &tmpint) == 1)
{
if (tmpint <= 9 && tmpint >= 1)
{
if (sscanf(buf_upper, "PRIORITY:%d", &tmpint) == 1) {
if (tmpint <= 9 && tmpint >= 1) {
vtodo.priority = tmpint;
vtodo.has_priority = 1;
}
else
{
} else {
ical_log(log, ICAL_VTODO, ITEMLINE,
_("item priority is not acceptable "
"(must be between 1 and 9)."));
vtodo.priority = LOWEST;
}
}
else if (strncmp (buf_upper, summary, sizeof (summary) - 1) == 0)
{
} else if (strncmp(buf_upper, summary, sizeof(summary) - 1) == 0) {
vtodo.mesg = ical_read_summary(buf);
}
else if (strncmp (buf_upper, alarm, sizeof (alarm) - 1) == 0)
{
} else if (strncmp(buf_upper, alarm, sizeof(alarm) - 1) == 0) {
skip_alarm = 1;
}
else if (strncmp (buf_upper, desc, sizeof (desc) - 1) == 0)
{
vtodo.note = ical_read_note (buf, noskipped, ICAL_VTODO,
ITEMLINE, log);
} else if (strncmp(buf_upper, desc, sizeof(desc) - 1) == 0) {
vtodo.note = ical_read_note(buf, noskipped, ICAL_VTODO, ITEMLINE, log);
}
}
}
@ -1225,25 +1065,20 @@ ical_import_data (FILE *stream, FILE *log, unsigned *events, unsigned *apoints,
ical_log_init(log, ical_version);
while (ical_readline (stream, buf, lstore, lines))
{
while (ical_readline(stream, buf, lstore, lines)) {
(*lines)++;
str_toupper(buf);
if (strncmp (buf, vevent, sizeof (vevent) - 1) == 0)
{
if (strncmp(buf, vevent, sizeof(vevent) - 1) == 0) {
ical_read_event(stream, log, events, apoints, skipped, buf, lstore,
lines);
}
else if (strncmp (buf, vtodo, sizeof (vtodo) - 1) == 0)
{
} else if (strncmp(buf, vtodo, sizeof(vtodo) - 1) == 0) {
ical_read_todo(stream, log, todos, skipped, buf, lstore, lines);
}
}
}
/* Export calcurse data. */
void
ical_export_data (FILE *stream)
void ical_export_data(FILE * stream)
{
ical_export_header(stream);
ical_export_recur_events(stream);

425
src/io.c

File diff suppressed because it is too large Load Diff

View File

@ -94,8 +94,7 @@ static struct keydef_s keydef[NBKEYS] = {
{"lower-priority", "-"},
};
static void
dump_intro (FILE *fd)
static void dump_intro(FILE * fd)
{
const char *intro =
_("#\n"
@ -122,8 +121,7 @@ dump_intro (FILE *fd)
fprintf(fd, "%s\n", intro);
}
void
keys_init (void)
void keys_init(void)
{
int i;
@ -133,26 +131,22 @@ keys_init (void)
LLIST_INIT(&keys[i]);
}
static void
key_free (char *s)
static void key_free(char *s)
{
mem_free(s);
}
void
keys_free (void)
void keys_free(void)
{
int i;
for (i = 0; i < NBKEYS; i++)
{
for (i = 0; i < NBKEYS; i++) {
LLIST_FREE_INNER(&keys[i], key_free);
LLIST_FREE(&keys[i]);
}
}
void
keys_dump_defaults (char *file)
void keys_dump_defaults(char *file)
{
FILE *fd;
int i;
@ -166,17 +160,14 @@ keys_dump_defaults (char *file)
file_close(fd, __FILE_POS__);
}
const char *
keys_get_label (enum key key)
const char *keys_get_label(enum key key)
{
EXIT_IF (key < 0 || key > NBKEYS,
_("FATAL ERROR: key value out of bounds"));
EXIT_IF(key < 0 || key > NBKEYS, _("FATAL ERROR: key value out of bounds"));
return keydef[key].label;
}
enum key
keys_get_action (int pressed)
enum key keys_get_action(int pressed)
{
if (pressed < 0 || pressed > MAXKEYVAL)
return -1;
@ -184,16 +175,13 @@ keys_get_action (int pressed)
return actions[pressed];
}
enum key
keys_getch (WINDOW *win, int *count)
enum key keys_getch(WINDOW * win, int *count)
{
int ch = '0';
if (count)
{
if (count) {
*count = 0;
do
{
do {
*count = *count * 10 + ch - '0';
ch = wgetch(win);
}
@ -201,12 +189,10 @@ keys_getch (WINDOW *win, int *count)
if (*count == 0)
*count = 1;
}
else
} else
ch = wgetch(win);
switch (ch)
{
switch (ch) {
case KEY_RESIZE:
return KEY_RESIZE;
default:
@ -214,8 +200,7 @@ keys_getch (WINDOW *win, int *count)
}
}
static void
add_key_str (enum key action, int key)
static void add_key_str(enum key action, int key)
{
if (action < 0 || action > NBKEYS)
return;
@ -223,13 +208,11 @@ add_key_str (enum key action, int key)
LLIST_ADD(&keys[action], mem_strdup(keys_int2str(key)));
}
int
keys_assign_binding (int key, enum key action)
int keys_assign_binding(int key, enum key action)
{
if (key < 0 || key > MAXKEYVAL || actions[key] != KEY_UNDEF)
return 1;
else
{
else {
actions[key] = action;
add_key_str(action, key);
}
@ -237,8 +220,7 @@ keys_assign_binding (int key, enum key action)
return 0;
}
static void
del_key_str (enum key action, int key)
static void del_key_str(enum key action, int key)
{
llist_item_t *i;
char oldstr[BUFSIZ];
@ -248,28 +230,23 @@ del_key_str (enum key action, int key)
strncpy(oldstr, keys_int2str(key), BUFSIZ);
LLIST_FOREACH (&keys[action], i)
{
if (strcmp (LLIST_GET_DATA (i), oldstr) == 0)
{
LLIST_FOREACH(&keys[action], i) {
if (strcmp(LLIST_GET_DATA(i), oldstr) == 0) {
LLIST_REMOVE(&keys[action], i);
return;
}
}
}
void
keys_remove_binding (int key, enum key action)
{
if (key >= 0 && key <= MAXKEYVAL)
void keys_remove_binding(int key, enum key action)
{
if (key >= 0 && key <= MAXKEYVAL) {
actions[key] = KEY_UNDEF;
del_key_str(action, key);
}
}
int
keys_str2int (const char *key)
int keys_str2int(const char *key)
{
const char CONTROL_KEY[] = "C-";
const char TAB_KEY[] = "TAB";
@ -286,8 +263,7 @@ keys_str2int (const char *key)
return -1;
if (strlen(key) == 1)
return (int)key[0];
else
{
else {
if (key[0] == '^')
return CTRL((int)key[1]);
else if (!strncmp(key, CONTROL_KEY, sizeof(CONTROL_KEY) - 1))
@ -315,11 +291,9 @@ keys_str2int (const char *key)
}
}
const char *
keys_int2str (int key)
{
switch (key)
const char *keys_int2str(int key)
{
switch (key) {
case TAB:
return "TAB";
case SPACE:
@ -343,8 +317,7 @@ keys_int2str (int key)
}
}
int
keys_action_count_keys (enum key action)
int keys_action_count_keys(enum key action)
{
llist_item_t *i;
int n = 0;
@ -355,21 +328,18 @@ keys_action_count_keys (enum key action)
return n;
}
const char *
keys_action_firstkey (enum key action)
const char *keys_action_firstkey(enum key action)
{
const char *s = LLIST_GET_DATA(LLIST_FIRST(&keys[action]));
return (s != NULL) ? s : "XXX";
}
const char *
keys_action_nkey (enum key action, int keynum)
const char *keys_action_nkey(enum key action, int keynum)
{
return LLIST_GET_DATA(LLIST_NTH(&keys[action], keynum));
}
char *
keys_action_allkeys (enum key action)
char *keys_action_allkeys(enum key action)
{
llist_item_t *i;
static char keystr[BUFSIZ];
@ -379,8 +349,7 @@ keys_action_allkeys (enum key action)
return NULL;
keystr[0] = '\0';
LLIST_FOREACH (&keys[action], i)
{
LLIST_FOREACH(&keys[action], i) {
const int MAXLEN = sizeof(keystr) - 1 - strlen(keystr);
strncat(keystr, LLIST_GET_DATA(i), MAXLEN - 1);
strncat(keystr, CHAR_SPACE, 1);
@ -390,8 +359,7 @@ keys_action_allkeys (enum key action)
}
/* Need this to display keys properly inside status bar. */
static char *
keys_format_label (char *key, int keylen)
static char *keys_format_label(char *key, int keylen)
{
static char fmtkey[BUFSIZ];
const int len = strlen(key);
@ -404,14 +372,11 @@ keys_format_label (char *key, int keylen)
memset(fmtkey, 0, sizeof(fmtkey));
if (len == 0)
strncpy(fmtkey, "?", sizeof(fmtkey));
else if (len <= keylen)
{
else if (len <= keylen) {
for (i = 0; i < keylen - len; i++)
fmtkey[i] = ' ';
strncat(fmtkey, key, keylen);
}
else
{
} else {
for (i = 0; i < keylen - 1; i++)
fmtkey[i] = key[i];
fmtkey[keylen - 1] = dot;
@ -431,8 +396,7 @@ keys_display_bindings_bar (WINDOW *win, struct binding *bindings[], int count,
int i;
wins_erase_status_bar();
for (i = 0; i < page_size && page_base + i < count; i++)
{
for (i = 0; i < page_size && page_base + i < count; i++) {
/* Location of key and label. */
const int key_pos_x = (i / 2) * cmd_len;
const int key_pos_y = i % 2;
@ -463,42 +427,30 @@ keys_display_bindings_bar (WINDOW *win, struct binding *bindings[], int count,
* Display information about the given key.
* (could not add the keys descriptions to keydef variable, because of i18n).
*/
void
keys_popup_info (enum key key)
void keys_popup_info(enum key key)
{
char *info[NBKEYS];
WINDOW *infowin;
info[KEY_GENERIC_CANCEL] =
_("Cancel the ongoing action.");
info[KEY_GENERIC_SELECT] =
_("Select the highlighted item.");
info[KEY_GENERIC_CANCEL] = _("Cancel the ongoing action.");
info[KEY_GENERIC_SELECT] = _("Select the highlighted item.");
info[KEY_GENERIC_CREDITS] =
_("Print general information about calcurse's authors, license, etc.");
info[KEY_GENERIC_HELP] =
_("Display hints whenever some help screens are available.");
info[KEY_GENERIC_QUIT] =
_("Exit from the current menu, or quit calcurse.");
info[KEY_GENERIC_SAVE] =
_("Save calcurse data.");
info[KEY_GENERIC_CUT] =
_("Help for `generic-cut`.");
info[KEY_GENERIC_PASTE] =
_("Help for `generic-paste`.");
info[KEY_GENERIC_QUIT] = _("Exit from the current menu, or quit calcurse.");
info[KEY_GENERIC_SAVE] = _("Save calcurse data.");
info[KEY_GENERIC_CUT] = _("Help for `generic-cut`.");
info[KEY_GENERIC_PASTE] = _("Help for `generic-paste`.");
info[KEY_GENERIC_CHANGE_VIEW] =
_("Select next panel in calcurse main screen.");
info[KEY_GENERIC_IMPORT] =
_("Import data from an external file.");
info[KEY_GENERIC_EXPORT] =
_("Export data to a new file format.");
info[KEY_GENERIC_GOTO] =
_("Select the day to go to.");
info[KEY_GENERIC_IMPORT] = _("Import data from an external file.");
info[KEY_GENERIC_EXPORT] = _("Export data to a new file format.");
info[KEY_GENERIC_GOTO] = _("Select the day to go to.");
info[KEY_GENERIC_OTHER_CMD] =
_("Show next possible actions inside status bar.");
info[KEY_GENERIC_CONFIG_MENU] =
_("Enter the configuration menu.");
info[KEY_GENERIC_REDRAW] =
_("Redraw calcurse's screen.");
info[KEY_GENERIC_CONFIG_MENU] = _("Enter the configuration menu.");
info[KEY_GENERIC_REDRAW] = _("Redraw calcurse's screen.");
info[KEY_GENERIC_ADD_APPT] =
_("Add an appointment, whichever panel is currently selected.");
info[KEY_GENERIC_ADD_TODO] =
@ -509,52 +461,42 @@ keys_popup_info (enum key key)
_("Move to previous day in calendar, whichever panel is currently "
"selected.");
info[KEY_GENERIC_NEXT_WEEK] =
_("Move to next week in calendar, whichever panel is currently selected.");
_
("Move to next week in calendar, whichever panel is currently selected.");
info[KEY_GENERIC_PREV_WEEK] =
_("Move to previous week in calendar, whichever panel is currently "
"selected");
info[KEY_GENERIC_SCROLL_DOWN] =
_("Scroll window down (e.g. when displaying text inside a popup window).");
_
("Scroll window down (e.g. when displaying text inside a popup window).");
info[KEY_GENERIC_SCROLL_UP] =
_("Scroll window up (e.g. when displaying text inside a popup window).");
info[KEY_GENERIC_GOTO_TODAY] =
_("Go to today, whichever panel is selected.");
info[KEY_MOVE_RIGHT] =
_("Move to the right.");
info[KEY_MOVE_LEFT] =
_("Move to the left.");
info[KEY_MOVE_DOWN] =
_("Move down.");
info[KEY_MOVE_UP] =
_("Move up.");
info[KEY_GENERIC_GOTO_TODAY] = _("Go to today, whichever panel is selected.");
info[KEY_MOVE_RIGHT] = _("Move to the right.");
info[KEY_MOVE_LEFT] = _("Move to the left.");
info[KEY_MOVE_DOWN] = _("Move down.");
info[KEY_MOVE_UP] = _("Move up.");
info[KEY_START_OF_WEEK] =
_("Select the first day of the current week when inside the calendar "
"panel.");
info[KEY_END_OF_WEEK] =
_("Select the last day of the current week when inside the calendar "
"panel.");
info[KEY_ADD_ITEM] =
_("Add an item to the currently selected panel.");
info[KEY_DEL_ITEM] =
_("Delete the currently selected item.");
info[KEY_EDIT_ITEM] =
_("Edit the currently seleted item.");
info[KEY_ADD_ITEM] = _("Add an item to the currently selected panel.");
info[KEY_DEL_ITEM] = _("Delete the currently selected item.");
info[KEY_EDIT_ITEM] = _("Edit the currently seleted item.");
info[KEY_VIEW_ITEM] =
_("Display the currently selected item inside a popup window.");
info[KEY_FLAG_ITEM] =
_("Flag the currently selected item as important.");
info[KEY_REPEAT_ITEM] =
_("Repeat an item");
info[KEY_FLAG_ITEM] = _("Flag the currently selected item as important.");
info[KEY_REPEAT_ITEM] = _("Repeat an item");
info[KEY_PIPE_ITEM] =
_("Pipe the currently selected item to an external program.");
info[KEY_EDIT_NOTE] =
_("Attach (or edit if one exists) a note to the currently selected item");
info[KEY_VIEW_NOTE] =
_("View the note attached to the currently selected item.");
info[KEY_RAISE_PRIORITY] =
_("Raise a task priority inside the todo panel.");
info[KEY_LOWER_PRIORITY] =
_("Lower a task priority inside the todo panel.");
info[KEY_RAISE_PRIORITY] = _("Raise a task priority inside the todo panel.");
info[KEY_LOWER_PRIORITY] = _("Lower a task priority inside the todo panel.");
if (key < 0 || key > NBKEYS)
return;
@ -569,8 +511,7 @@ keys_popup_info (enum key key)
#undef WINCOL
}
void
keys_save_bindings (FILE *fd)
void keys_save_bindings(FILE * fd)
{
int i;
@ -580,40 +521,33 @@ keys_save_bindings (FILE *fd)
fprintf(fd, "%s %s\n", keydef[i].label, keys_action_allkeys(i));
}
int
keys_check_missing_bindings (void)
int keys_check_missing_bindings(void)
{
int i;
for (i = 0; i < NBKEYS; i++)
{
for (i = 0; i < NBKEYS; i++) {
if (!LLIST_FIRST(&keys[i]))
return 1;
}
return 0;
}
void
keys_fill_missing (void)
void keys_fill_missing(void)
{
int i;
for (i = 0; i < NBKEYS; i++)
{
if (!LLIST_FIRST (&keys[i]))
{
for (i = 0; i < NBKEYS; i++) {
if (!LLIST_FIRST(&keys[i])) {
char *p, tmpbuf[BUFSIZ];
strncpy(tmpbuf, keydef[i].binding, BUFSIZ);
p = tmpbuf;
for (;;)
{
for (;;) {
char key_ch[BUFSIZ];
while (*p == ' ')
p++;
if (sscanf (p, "%s", key_ch) == 1)
{
if (sscanf(p, "%s", key_ch) == 1) {
int ch, used;
ch = keys_str2int(key_ch);
@ -623,8 +557,7 @@ keys_fill_missing (void)
"\"%s\" was already assigned!"),
keydef[i].label, key_ch);
p += strlen(key_ch) + 1;
}
else
} else
break;
}
}

View File

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

View File

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

View File

@ -71,9 +71,7 @@ static struct mem_stats mstats;
#endif /* CALCURSE_MEMORY_DEBUG */
void *
xmalloc (size_t size)
void *xmalloc(size_t size)
{
void *p;
@ -84,8 +82,7 @@ xmalloc (size_t size)
return p;
}
void *
xcalloc (size_t nmemb, size_t size)
void *xcalloc(size_t nmemb, size_t size)
{
void *p;
@ -97,8 +94,7 @@ xcalloc (size_t nmemb, size_t size)
return p;
}
void *
xrealloc (void *ptr, size_t nmemb, size_t size)
void *xrealloc(void *ptr, size_t nmemb, size_t size)
{
void *new_ptr;
size_t new_size;
@ -112,8 +108,7 @@ xrealloc (void *ptr, size_t nmemb, size_t size)
return new_ptr;
}
char *
xstrdup (const char *str)
char *xstrdup(const char *str)
{
size_t len;
char *cp;
@ -124,8 +119,7 @@ xstrdup (const char *str)
return strncpy(cp, str, len);
}
void
xfree (void *p)
void xfree(void *p)
{
EXIT_IF(p == NULL, _("xfree: null pointer"));
free(p);
@ -133,8 +127,7 @@ xfree (void *p)
#ifdef CALCURSE_MEMORY_DEBUG
static unsigned
stats_add_blk (size_t size, const char *pos)
static unsigned stats_add_blk(size_t size, const char *pos)
{
struct mem_blk *o, **i;
@ -147,24 +140,20 @@ stats_add_blk (size_t size, const char *pos)
o->size = (unsigned)size;
o->next = 0;
for (i = &mstats.blk; *i; i = &(*i)->next)
;
for (i = &mstats.blk; *i; i = &(*i)->next) ;
o->id = mstats.ncall;
*i = o;
return o->id;
}
static void
stats_del_blk (unsigned id)
static void stats_del_blk(unsigned id)
{
struct mem_blk *o, **i;
i = &mstats.blk;
for (o = mstats.blk; o; o = o->next)
{
if (o->id == id)
{
for (o = mstats.blk; o; o = o->next) {
if (o->id == id) {
*i = o->next;
free(o);
return;
@ -176,8 +165,7 @@ stats_del_blk (unsigned id)
/* NOTREACHED */
}
void *
dbg_malloc (size_t size, const char *pos)
void *dbg_malloc(size_t size, const char *pos)
{
unsigned *buf;
@ -197,8 +185,7 @@ dbg_malloc (size_t size, const char *pos)
return (void *)(buf + EXTRA_SPACE_START);
}
void *
dbg_calloc (size_t nmemb, size_t size, const char *pos)
void *dbg_calloc(size_t nmemb, size_t size, const char *pos)
{
void *buf;
@ -216,8 +203,7 @@ dbg_calloc (size_t nmemb, size_t size, const char *pos)
return buf;
}
void *
dbg_realloc (void *ptr, size_t nmemb, size_t size, const char *pos)
void *dbg_realloc(void *ptr, size_t nmemb, size_t size, const char *pos)
{
unsigned *buf, old_size, new_size, cpy_size;
@ -242,8 +228,7 @@ dbg_realloc (void *ptr, size_t nmemb, size_t size, const char *pos)
return (void *)buf;
}
char *
dbg_strdup (const char *s, const char *pos)
char *dbg_strdup(const char *s, const char *pos)
{
size_t size;
char *buf;
@ -258,8 +243,7 @@ dbg_strdup (const char *s, const char *pos)
return strncpy(buf, s, size + 1);
}
void
dbg_free (void *ptr, const char *pos)
void dbg_free(void *ptr, const char *pos)
{
unsigned *buf, size;
@ -270,8 +254,7 @@ dbg_free (void *ptr, const char *pos)
EXIT_IF(buf[BLK_STATE] == MAGIC_FREE,
_("block seems already freed at %s"), pos);
EXIT_IF (buf[BLK_STATE] != MAGIC_ALLOC,
_("corrupt block header at %s"), pos);
EXIT_IF(buf[BLK_STATE] != MAGIC_ALLOC, _("corrupt block header at %s"), pos);
EXIT_IF(buf[size - 1] != buf[BLK_ID],
_("corrupt block end at %s, (end = %u, should be %d)"), pos,
buf[size - 1], buf[BLK_ID]);
@ -284,8 +267,7 @@ dbg_free (void *ptr, const char *pos)
mstats.nfree += size;
}
static void
dump_block_info (struct mem_blk *blk)
static void dump_block_info(struct mem_blk *blk)
{
if (blk == NULL)
return;
@ -297,8 +279,7 @@ dump_block_info (struct mem_blk *blk)
puts(_("-----------------------------------------\n"));
}
void
mem_stats (void)
void mem_stats(void)
{
putchar('\n');
puts(_("+------------------------------+\n"));
@ -309,8 +290,7 @@ mem_stats (void)
printf(_(" unfreed blocks: %u\n"), mstats.nalloc - mstats.nfree);
putchar('\n');
if (mstats.nfree < mstats.nalloc)
{
if (mstats.nfree < mstats.nalloc) {
struct mem_blk *blk;
for (blk = mstats.blk; blk; blk = blk->next)

View File

@ -55,8 +55,7 @@ HTABLE_GENERATE (htp, note_gc_hash, note_gc_extract_key, note_gc_cmp)
/* Create note file from a string and return a newly allocated string that
* contains its name. */
char *
generate_note (const char *str)
char *generate_note(const char *str)
{
char *sha1 = mem_malloc(SHA1_DIGESTLEN * 2 + 1);
char notepath[BUFSIZ];
@ -73,8 +72,7 @@ generate_note (const char *str)
}
/* Edit a note with an external editor. */
void
edit_note (char **note, const char *editor)
void edit_note(char **note, const char *editor)
{
char tmppath[BUFSIZ];
char *tmpext;
@ -89,8 +87,7 @@ edit_note (char **note, const char *editor)
strncat(tmppath, tmpext, BUFSIZ - strlen(tmppath) - 1);
mem_free(tmpext);
if (*note != NULL)
{
if (*note != NULL) {
snprintf(notepath, BUFSIZ, "%s%s", path_notes, *note);
io_file_cp(notepath, tmppath);
}
@ -99,8 +96,7 @@ edit_note (char **note, const char *editor)
if (io_file_is_empty(tmppath) > 0)
erase_note(note);
else if ((fp = fopen (tmppath, "r")))
{
else if ((fp = fopen(tmppath, "r"))) {
sha1_stream(fp, sha1);
fclose(fp);
*note = sha1;
@ -113,8 +109,7 @@ edit_note (char **note, const char *editor)
}
/* View a note in an external pager. */
void
view_note (const char *note, const char *pager)
void view_note(const char *note, const char *pager)
{
char fullname[BUFSIZ];
@ -125,8 +120,7 @@ view_note (const char *note, const char *pager)
}
/* Erase a note previously attached to an item. */
void
erase_note (char **note)
void erase_note(char **note)
{
if (*note == NULL)
return;
@ -135,16 +129,13 @@ erase_note (char **note)
}
/* Read a serialized note file name from a stream and deserialize it. */
void
note_read (char *buffer, FILE *fp)
void note_read(char *buffer, FILE * fp)
{
int i;
for (i = 0; i < MAX_NOTESIZ; i++)
{
for (i = 0; i < MAX_NOTESIZ; i++) {
buffer[i] = getc(fp);
if (buffer[i] == ' ')
{
if (buffer[i] == ' ') {
buffer[i] = '\0';
return;
}
@ -161,15 +152,13 @@ note_gc_extract_key (struct note_gc_hash *data, const char **key, int *len)
*len = strlen(data->hash);
}
static int
note_gc_cmp (struct note_gc_hash *a, struct note_gc_hash *b)
static int note_gc_cmp(struct note_gc_hash *a, struct note_gc_hash *b)
{
return strcmp(a->hash, b->hash);
}
/* Spot and unlink unused note files. */
void
note_gc (void)
void note_gc(void)
{
struct htp gc_htable = HTABLE_INITIALIZER(&gc_htable);
struct note_gc_hash *hp;
@ -183,10 +172,8 @@ note_gc (void)
return;
/* Insert all note file names into a hash table. */
do
{
if ((dp = readdir (dirp)) && *(dp->d_name) != '.')
{
do {
if ((dp = readdir(dirp)) && *(dp->d_name) != '.') {
hp = mem_malloc(sizeof(struct note_gc_hash));
strncpy(hp->buf, dp->d_name, MAX_NOTESIZ + 1);
@ -200,59 +187,48 @@ note_gc (void)
closedir(dirp);
/* Remove hashes that are actually in use. */
LLIST_TS_FOREACH (&alist_p, i)
{
LLIST_TS_FOREACH(&alist_p, i) {
struct apoint *apt = LLIST_GET_DATA(i);
if (apt->note)
{
if (apt->note) {
tmph.hash = apt->note;
free(HTABLE_REMOVE(htp, &gc_htable, &tmph));
}
}
LLIST_FOREACH (&eventlist, i)
{
LLIST_FOREACH(&eventlist, i) {
struct event *ev = LLIST_GET_DATA(i);
if (ev->note)
{
if (ev->note) {
tmph.hash = ev->note;
free(HTABLE_REMOVE(htp, &gc_htable, &tmph));
}
}
LLIST_TS_FOREACH (&recur_alist_p, i)
{
LLIST_TS_FOREACH(&recur_alist_p, i) {
struct recur_apoint *rapt = LLIST_GET_DATA(i);
if (rapt->note)
{
if (rapt->note) {
tmph.hash = rapt->note;
free(HTABLE_REMOVE(htp, &gc_htable, &tmph));
}
}
LLIST_FOREACH (&recur_elist, i)
{
LLIST_FOREACH(&recur_elist, i) {
struct recur_event *rev = LLIST_GET_DATA(i);
if (rev->note)
{
if (rev->note) {
tmph.hash = rev->note;
free(HTABLE_REMOVE(htp, &gc_htable, &tmph));
}
}
LLIST_FOREACH (&todolist, i)
{
LLIST_FOREACH(&todolist, i) {
struct todo *todo = LLIST_GET_DATA(i);
if (todo->note)
{
if (todo->note) {
tmph.hash = todo->note;
free(HTABLE_REMOVE(htp, &gc_htable, &tmph));
}
}
/* Unlink unused note files. */
HTABLE_FOREACH (hp, htp, &gc_htable)
{
HTABLE_FOREACH(hp, htp, &gc_htable) {
snprintf(notepath, BUFSIZ, "%s%s", path_notes, hp->hash);
unlink(notepath);
}

View File

@ -60,8 +60,7 @@ static pthread_t notify_t_main;
* Return the number of seconds before next appointment
* (0 if no upcoming appointment).
*/
int
notify_time_left (void)
int notify_time_left(void)
{
time_t ntimer;
int left;
@ -76,8 +75,7 @@ notify_time_left (void)
* Return 1 if the reminder was not sent already for the upcoming
* appointment.
*/
unsigned
notify_needs_reminder (void)
unsigned notify_needs_reminder(void)
{
if (notify_app.got_app
&& (((notify_app.state & APOINT_NOTIFY) && !nbar.notify_all) ||
@ -92,8 +90,7 @@ notify_needs_reminder (void)
* Note: the mutex associated with this structure must be locked by the
* caller!
*/
void
notify_update_app (long start, char state, char *msg)
void notify_update_app(long start, char state, char *msg)
{
notify_free_app();
notify_app.got_app = 1;
@ -103,8 +100,7 @@ notify_update_app (long start, char state, char *msg)
}
/* Return 1 if we need to display the notify-bar, else 0. */
int
notify_bar (void)
int notify_bar(void)
{
int display_bar = 0;
@ -116,8 +112,7 @@ notify_bar (void)
}
/* Initialize the nbar variable used to store notification options. */
void
notify_init_vars (void)
void notify_init_vars(void)
{
const char *time_format = "%T";
const char *date_format = "%a %F";
@ -140,16 +135,14 @@ notify_init_vars (void)
}
/* Extract the appointment file name from the complete file path. */
static void
extract_aptsfile (void)
static void extract_aptsfile(void)
{
char *file;
file = strrchr(path_apts, '/');
if (!file)
notify.apts_file = path_apts;
else
{
else {
notify.apts_file = file;
notify.apts_file++;
}
@ -160,8 +153,7 @@ extract_aptsfile (void)
* creating the notification window (l is the number of lines, c the
* number of columns, y and x are its coordinates).
*/
void
notify_init_bar (void)
void notify_init_bar(void)
{
pthread_mutex_init(&notify.mutex, NULL);
pthread_mutex_init(&notify_app.mutex, NULL);
@ -174,8 +166,7 @@ notify_init_bar (void)
/*
* Free memory associated with the notify_app structure.
*/
void
notify_free_app (void)
void notify_free_app(void)
{
notify_app.time = 0;
notify_app.got_app = 0;
@ -186,11 +177,9 @@ notify_free_app (void)
}
/* Stop the notify-bar main thread. */
void
notify_stop_main_thread (void)
{
if (notify_t_main)
void notify_stop_main_thread(void)
{
if (notify_t_main) {
pthread_cancel(notify_t_main);
pthread_join(notify_t_main, NULL);
}
@ -200,16 +189,14 @@ notify_stop_main_thread (void)
* The calcurse window geometry has changed so we need to reset the
* notification window.
*/
void
notify_reinit_bar (void)
void notify_reinit_bar(void)
{
delwin(notify.win);
notify.win = newwin(win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x);
}
/* Launch user defined command as a notification. */
unsigned
notify_launch_cmd (void)
unsigned notify_launch_cmd(void)
{
int pid;
@ -220,16 +207,12 @@ notify_launch_cmd (void)
pid = fork();
if (pid < 0)
{
if (pid < 0) {
ERROR_MSG(_("error while launching command: could not fork"));
return 0;
}
else if (pid == 0)
{
} else if (pid == 0) {
/* Child: launch user defined command */
if (execlp (nbar.shell, nbar.shell, "-c", nbar.cmd, NULL) < 0)
{
if (execlp(nbar.shell, nbar.shell, "-c", nbar.cmd, NULL) < 0) {
ERROR_MSG(_("error while launching command"));
_exit(1);
}
@ -243,8 +226,7 @@ notify_launch_cmd (void)
* Update the notification bar. This is useful when changing color theme
* for example.
*/
void
notify_update_bar (void)
void notify_update_bar(void)
{
const int space = 3;
int file_pos, date_pos, app_pos, txt_max_len, too_long = 0;
@ -261,15 +243,12 @@ notify_update_bar (void)
custom_apply_attr(notify.win, ATTR_HIGHEST);
wattron(notify.win, A_UNDERLINE | A_REVERSE);
mvwhline(notify.win, 0, 0, ACS_HLINE, col);
mvwprintw (notify.win, 0, date_pos, "[ %s | %s ]",
notify.date, notify.time);
mvwprintw(notify.win, 0, date_pos, "[ %s | %s ]", notify.date, notify.time);
mvwprintw(notify.win, 0, file_pos, "(%s)", notify.apts_file);
pthread_mutex_lock(&notify_app.mutex);
if (notify_app.got_app)
{
if (strlen (notify_app.txt) > txt_max_len)
{
if (notify_app.got_app) {
if (strlen(notify_app.txt) > txt_max_len) {
int shrink_len;
too_long = 1;
@ -278,8 +257,7 @@ notify_update_bar (void)
buf[shrink_len] = '\0';
}
time_left = notify_time_left();
if (time_left > 0)
{
if (time_left > 0) {
int hours_left, minutes_left;
hours_left = (time_left / HOURINSEC);
@ -307,9 +285,7 @@ notify_update_bar (void)
if (blinking)
notify_launch_cmd();
pthread_mutex_unlock(&nbar.mutex);
}
else
{
} else {
notify_app.got_app = 0;
pthread_mutex_unlock(&notify_app.mutex);
pthread_mutex_unlock(&notify.mutex);
@ -328,8 +304,7 @@ notify_update_bar (void)
/* Update the notication bar content */
/* ARGSUSED0 */
static void *
notify_main_thread (void *arg)
static void *notify_main_thread(void *arg)
{
const unsigned thread_sleep = 1;
const unsigned check_app = MININSEC;
@ -340,8 +315,7 @@ notify_main_thread (void *arg)
elapse = 0;
for (;;)
{
for (;;) {
ntimer = time(NULL);
ntime = localtime(&ntimer);
pthread_mutex_lock(&notify.mutex);
@ -353,8 +327,7 @@ notify_main_thread (void *arg)
notify_update_bar();
psleep(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;
@ -367,8 +340,7 @@ notify_main_thread (void *arg)
}
/* Fill the given structure with information about next appointment. */
unsigned
notify_get_next (struct notify_app *a)
unsigned notify_get_next(struct notify_app *a)
{
time_t current_time;
@ -391,8 +363,7 @@ notify_get_next (struct notify_app *a)
* This is used for the daemon to check if we have an upcoming appointment or
* not.
*/
unsigned
notify_get_next_bkgd (void)
unsigned notify_get_next_bkgd(void)
{
struct notify_app a;
@ -400,14 +371,11 @@ notify_get_next_bkgd (void)
if (!notify_get_next(&a))
return 0;
if (!a.got_app)
{
if (!a.got_app) {
/* No next appointment, reset the previous notified one. */
notify_app.got_app = 0;
return 1;
}
else
{
} else {
if (!notify_same_item(a.time))
notify_update_app(a.time, a.state, a.txt);
}
@ -419,8 +387,7 @@ notify_get_next_bkgd (void)
}
/* Return the description of next appointment to be notified. */
char *
notify_app_txt (void)
char *notify_app_txt(void)
{
if (notify_app.got_app)
return notify_app.txt;
@ -430,8 +397,7 @@ notify_app_txt (void)
/* Look for the next appointment within the next 24 hours. */
/* ARGSUSED0 */
static void *
notify_thread_app (void *arg)
static void *notify_thread_app(void *arg)
{
struct notify_app tmp_app;
int force = (arg ? 1 : 0);
@ -439,16 +405,12 @@ notify_thread_app (void *arg)
if (!notify_get_next(&tmp_app))
pthread_exit(NULL);
if (!tmp_app.got_app)
{
if (!tmp_app.got_app) {
pthread_mutex_lock(&notify_app.mutex);
notify_free_app();
pthread_mutex_unlock(&notify_app.mutex);
}
else
{
if (force || !notify_same_item (tmp_app.time))
{
} else {
if (force || !notify_same_item(tmp_app.time)) {
pthread_mutex_lock(&notify_app.mutex);
notify_update_app(tmp_app.time, tmp_app.state, tmp_app.txt);
pthread_mutex_unlock(&notify_app.mutex);
@ -463,20 +425,17 @@ notify_thread_app (void *arg)
}
/* Launch the thread notify_thread_app to look for next appointment. */
void
notify_check_next_app (int force)
void notify_check_next_app(int force)
{
pthread_t notify_t_app;
void *arg = (force ? (void *)1 : NULL);
pthread_create (&notify_t_app, &detached_thread_attr, notify_thread_app,
arg);
pthread_create(&notify_t_app, &detached_thread_attr, notify_thread_app, arg);
return;
}
/* Check if the newly created appointment is to be notified. */
void
notify_check_added (char *mesg, long start, char state)
void notify_check_added(char *mesg, long start, char state)
{
time_t current_time;
int update_notify = 0;
@ -484,21 +443,16 @@ 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_update_app(start, state, mesg);
}
pthread_mutex_unlock(&notify_app.mutex);
@ -506,8 +460,7 @@ notify_check_added (char *mesg, long start, char state)
}
/* Check if the newly repeated appointment is to be notified. */
void
notify_check_repeated (struct recur_apoint *i)
void notify_check_repeated(struct recur_apoint *i)
{
unsigned real_app_time;
int update_notify = 0;
@ -517,32 +470,23 @@ notify_check_repeated (struct recur_apoint *i)
pthread_mutex_lock(&notify_app.mutex);
if (recur_item_find_occurrence(i->start, i->dur, &i->exc, i->rpt->type,
i->rpt->freq, i->rpt->until, get_today(),
&real_app_time))
{
if (!notify_app.got_app)
{
&real_app_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 && i->state != notify_app.state)
update_notify = 1;
}
else if (real_app_time == notify_app.time &&
i->state != notify_app.state)
update_notify = 1;
}
if (update_notify)
{
if (update_notify) {
notify_update_app(real_app_time, i->state, i->mesg);
}
pthread_mutex_unlock(&notify_app.mutex);
notify_update_bar();
}
int
notify_same_item (long time)
int notify_same_item(long time)
{
int same = 0;
@ -554,8 +498,7 @@ notify_same_item (long time)
return same;
}
int
notify_same_recur_item (struct recur_apoint *i)
int notify_same_recur_item(struct recur_apoint *i)
{
int same = 0;
unsigned item_start = 0;
@ -572,8 +515,7 @@ notify_same_recur_item (struct recur_apoint *i)
}
/* Launch the notify-bar main thread. */
void
notify_start_main_thread (void)
void notify_start_main_thread(void)
{
pthread_create(&notify_t_main, NULL, notify_main_thread, NULL);
notify_check_next_app(0);
@ -595,16 +537,14 @@ print_option (WINDOW *win, unsigned x, unsigned y, char *name,
x_opt = x + XOFF + strlen(name);
mvwprintw(win, y, x, "[%u] %s", num, name);
erase_window_part(win, x_opt, y, MAXCOL, y);
if ((len = strlen (valstr)) != 0)
{
if ((len = strlen(valstr)) != 0) {
unsigned maxlen;
maxlen = MAXCOL - x_opt - 2;
custom_apply_attr(win, ATTR_HIGHEST);
if (len < maxlen)
mvwprintw(win, y, x_opt, "%s", valstr);
else
{
else {
char buf[BUFSIZ];
strncpy(buf, valstr, maxlen - 1);
@ -612,25 +552,21 @@ print_option (WINDOW *win, unsigned x, unsigned y, char *name,
mvwprintw(win, y, x_opt, "%s...", buf);
}
custom_remove_attr(win, ATTR_HIGHEST);
}
else
} else
print_bool_option_incolor(win, valbool, y, x_opt);
mvwprintw(win, y + 1, x, desc);
}
/* Print options related to the notify-bar. */
static unsigned
print_config_options (WINDOW *optwin)
static unsigned print_config_options(WINDOW * optwin)
{
const int XORIG = 3;
const int YORIG = 0;
const int YOFF = 3;
enum
{ SHOW, DATE, CLOCK, WARN, CMD, NOTIFY_ALL, DMON, DMON_LOG, NB_OPT };
enum { SHOW, DATE, CLOCK, WARN, CMD, NOTIFY_ALL, DMON, DMON_LOG, NB_OPT };
struct opt_s
{
struct opt_s {
char *name;
char *desc;
char valstr[BUFSIZ];
@ -656,7 +592,8 @@ print_config_options (WINDOW *optwin)
opt[CMD].desc = _("(Command used to notify user of an upcoming appointment)");
opt[NOTIFY_ALL].name = _("notification.notifyall = ");
opt[NOTIFY_ALL].desc = _("(Notify all appointments instead of flagged ones only)");
opt[NOTIFY_ALL].desc =
_("(Notify all appointments instead of flagged ones only)");
opt[DMON].name = _("daemon.enable = ");
opt[DMON].desc = _("(Run in background to get notifications after exiting)");
@ -683,8 +620,7 @@ print_config_options (WINDOW *optwin)
opt[SHOW].valstr[0] = opt[NOTIFY_ALL].valstr[0] = opt[DMON].valstr[0] =
opt[DMON_LOG].valstr[0] = '\0';
for (i = 0; i < NB_OPT; i++)
{
for (i = 0; i < NB_OPT; i++) {
int y;
y = YORIG + i * YOFF;
@ -695,8 +631,7 @@ print_config_options (WINDOW *optwin)
return YORIG + NB_OPT * YOFF;
}
static void
reinit_conf_win (struct scrollwin *win)
static void reinit_conf_win(struct scrollwin *win)
{
unsigned first_line;
@ -709,21 +644,19 @@ reinit_conf_win (struct scrollwin *win)
}
/* Notify-bar configuration. */
void
notify_config_bar (void)
void notify_config_bar(void)
{
struct scrollwin cwin;
char *buf;
const char *number_str =
_("Enter an option number to change its value");
const char *keys =
_("(Press '^P' or '^N' to move up or down, 'Q' to quit)");
const char *number_str = _("Enter an option number to change its value");
const char *keys = _("(Press '^P' or '^N' to move up or down, 'Q' to quit)");
const char *date_str =
_("Enter the date format (see 'man 3 strftime' for possible formats) ");
const char *time_str =
_("Enter the time format (see 'man 3 strftime' for possible formats) ");
const char *count_str =
_("Enter the number of seconds (0 not to be warned before an appointment)");
_
("Enter the number of seconds (0 not to be warned before an appointment)");
const char *cmd_str = _("Enter the notification command ");
int ch;
@ -737,12 +670,10 @@ notify_config_bar (void)
wins_scrollwin_display(&cwin);
buf = mem_malloc(BUFSIZ);
while ((ch = wgetch (win[STA].p)) != 'q')
{
while ((ch = wgetch(win[STA].p)) != 'q') {
buf[0] = '\0';
switch (ch)
{
switch (ch) {
case CTRL('N'):
wins_scrollwin_down(&cwin, 1);
break;
@ -765,8 +696,7 @@ 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);
@ -777,8 +707,7 @@ 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);
@ -790,8 +719,7 @@ 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);
@ -802,8 +730,7 @@ 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);
@ -823,18 +750,15 @@ notify_config_bar (void)
break;
}
if (resize)
{
if (resize) {
resize = 0;
wins_get_config();
wins_reset();
reinit_conf_win(&cwin);
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 ())
{
if (notify_bar()) {
notify_reinit_bar();
notify_update_bar();
}

View File

@ -70,15 +70,12 @@ foreach_date_dump (const long date_end, struct rpt *rpt, llist_t *exc,
date = mktime(&lt);
item_time = item_first_date - date;
while (date <= date_end && date <= rpt->until)
{
while (date <= date_end && date <= rpt->until) {
if (recur_item_inday(item_first_date, item_dur, exc, rpt->type,
rpt->freq, rpt->until, date))
{
rpt->freq, rpt->until, date)) {
(*cb_dump) (stream, date + item_time, item_dur, item_mesg);
}
switch (rpt->type)
{
switch (rpt->type) {
case RECUR_DAILY:
date = date_sec_change(date, 0, rpt->freq);
break;
@ -99,8 +96,7 @@ foreach_date_dump (const long date_end, struct rpt *rpt, llist_t *exc,
}
}
static void
pcal_export_header (FILE *stream)
static void pcal_export_header(FILE * stream)
{
fputs("# calcurse pcal export\n", stream);
fputs("\n# =======\n# options\n# =======\n", stream);
@ -111,8 +107,7 @@ pcal_export_header (FILE *stream)
fputc('\n', stream);
}
static void
pcal_export_footer (FILE *stream)
static void pcal_export_footer(FILE * stream)
{
}
@ -141,8 +136,7 @@ pcal_dump_apoint (FILE *stream, long apoint_date, long apoint_dur,
fprintf(stream, "(%s -> %s) %s\n", pcal_beg, pcal_end, apoint_mesg);
}
static void
pcal_export_recur_events (FILE *stream)
static void pcal_export_recur_events(FILE * stream)
{
llist_item_t *i;
char pcal_date[BUFSIZ];
@ -152,17 +146,13 @@ pcal_export_recur_events (FILE *stream)
fputs("\n# =============\n", stream);
fputs("# (pcal does not support from..until dates specification\n", stream);
LLIST_FOREACH (&recur_elist, i)
{
LLIST_FOREACH(&recur_elist, i) {
struct recur_event *rev = LLIST_GET_DATA(i);
if (rev->rpt->until == 0 && rev->rpt->freq == 1)
{
switch (rev->rpt->type)
{
if (rev->rpt->until == 0 && rev->rpt->freq == 1) {
switch (rev->rpt->type) {
case RECUR_DAILY:
date_sec2date_fmt(rev->day, "%b %d", pcal_date);
fprintf (stream, "all day on_or_after %s %s\n", pcal_date,
rev->mesg);
fprintf(stream, "all day on_or_after %s %s\n", pcal_date, rev->mesg);
break;
case RECUR_WEEKLY:
date_sec2date_fmt(rev->day, "%a", pcal_date);
@ -181,9 +171,7 @@ pcal_export_recur_events (FILE *stream)
default:
EXIT(_("incoherent repetition type"));
}
}
else
{
} else {
const long YEAR_START = calendar_start_of_year();
const long YEAR_END = calendar_end_of_year();
@ -194,22 +182,19 @@ pcal_export_recur_events (FILE *stream)
}
}
static void
pcal_export_events (FILE *stream)
static void pcal_export_events(FILE * stream)
{
llist_item_t *i;
fputs("\n# ======\n# Events\n# ======\n", stream);
LLIST_FOREACH (&eventlist, i)
{
LLIST_FOREACH(&eventlist, i) {
struct event *ev = LLIST_TS_GET_DATA(i);
pcal_dump_event(stream, ev->day, 0, ev->mesg);
}
fputc('\n', stream);
}
static void
pcal_export_recur_apoints (FILE *stream)
static void pcal_export_recur_apoints(FILE * stream)
{
llist_item_t *i;
char pcal_date[BUFSIZ], pcal_beg[BUFSIZ], pcal_end[BUFSIZ];
@ -219,16 +204,13 @@ pcal_export_recur_apoints (FILE *stream)
fputs("\n# ==============\n", stream);
fputs("# (pcal does not support from..until dates specification\n", stream);
LLIST_TS_FOREACH (&recur_alist_p, i)
{
LLIST_TS_FOREACH(&recur_alist_p, i) {
struct recur_apoint *rapt = LLIST_TS_GET_DATA(i);
if (rapt->rpt->until == 0 && rapt->rpt->freq == 1)
{
if (rapt->rpt->until == 0 && rapt->rpt->freq == 1) {
date_sec2date_fmt(rapt->start, "%R", pcal_beg);
date_sec2date_fmt(rapt->start + rapt->dur, "%R", pcal_end);
switch (rapt->rpt->type)
{
switch (rapt->rpt->type) {
case RECUR_DAILY:
date_sec2date_fmt(rapt->start, "%b %d", pcal_date);
fprintf(stream, "all day on_or_after %s (%s -> %s) %s\n",
@ -254,9 +236,7 @@ pcal_export_recur_apoints (FILE *stream)
default:
EXIT(_("incoherent repetition type"));
}
}
else
{
} else {
const long YEAR_START = calendar_start_of_year();
const long YEAR_END = calendar_end_of_year();
@ -268,15 +248,13 @@ pcal_export_recur_apoints (FILE *stream)
}
}
static void
pcal_export_apoints (FILE *stream)
static void pcal_export_apoints(FILE * stream)
{
llist_item_t *i;
fputs("\n# ============\n# Appointments\n# ============\n", stream);
LLIST_TS_LOCK(&alist_p);
LLIST_TS_FOREACH (&alist_p, i)
{
LLIST_TS_FOREACH(&alist_p, i) {
struct apoint *apt = LLIST_TS_GET_DATA(i);
pcal_dump_apoint(stream, apt->start, apt->dur, apt->mesg);
}
@ -284,14 +262,12 @@ pcal_export_apoints (FILE *stream)
fputc('\n', stream);
}
static void
pcal_export_todo (FILE *stream)
static void pcal_export_todo(FILE * stream)
{
llist_item_t *i;
fputs("#\n# Todos\n#\n", stream);
LLIST_FOREACH (&todolist, i)
{
LLIST_FOREACH(&todolist, i) {
struct todo *todo = LLIST_TS_GET_DATA(i);
if (todo->id < 0) /* completed items */
continue;
@ -303,8 +279,7 @@ pcal_export_todo (FILE *stream)
}
/* Export calcurse data. */
void
pcal_export_data (FILE *stream)
void pcal_export_data(FILE * stream)
{
pcal_export_header(stream);
pcal_export_recur_events(stream);
@ -314,4 +289,3 @@ pcal_export_data (FILE *stream)
pcal_export_todo(stream);
pcal_export_footer(stream);
}

View File

@ -47,27 +47,23 @@ llist_t recur_elist;
static struct recur_event bkp_cut_recur_event;
static struct recur_apoint bkp_cut_recur_apoint;
static void
free_exc (struct excp *exc)
static void free_exc(struct excp *exc)
{
mem_free(exc);
}
static void
free_exc_list (llist_t *exc)
static void free_exc_list(llist_t * exc)
{
LLIST_FREE_INNER(exc, free_exc);
LLIST_FREE(exc);
}
static int
exc_cmp_day (struct excp *a, struct excp *b)
static int exc_cmp_day(struct excp *a, struct excp *b)
{
return a->st < b->st ? -1 : (a->st == b->st ? 0 : 1);
}
static void
recur_add_exc (llist_t *exc, long day)
static void recur_add_exc(llist_t * exc, long day)
{
struct excp *o = mem_malloc(sizeof(struct excp));
o->st = day;
@ -75,33 +71,27 @@ recur_add_exc (llist_t *exc, long day)
LLIST_ADD_SORTED(exc, o, exc_cmp_day);
}
static void
exc_dup (llist_t *in, llist_t *exc)
static void exc_dup(llist_t * in, llist_t * exc)
{
llist_item_t *i;
LLIST_INIT(in);
if (exc)
{
LLIST_FOREACH (exc, i)
{
if (exc) {
LLIST_FOREACH(exc, i) {
struct excp *p = LLIST_GET_DATA(i);
recur_add_exc(in, p->st);
}
}
}
void
recur_event_free_bkp (void)
{
if (bkp_cut_recur_event.mesg)
void recur_event_free_bkp(void)
{
if (bkp_cut_recur_event.mesg) {
mem_free(bkp_cut_recur_event.mesg);
bkp_cut_recur_event.mesg = 0;
}
if (bkp_cut_recur_event.rpt)
{
if (bkp_cut_recur_event.rpt) {
mem_free(bkp_cut_recur_event.rpt);
bkp_cut_recur_event.rpt = 0;
}
@ -109,16 +99,13 @@ recur_event_free_bkp (void)
erase_note(&bkp_cut_recur_event.note);
}
void
recur_apoint_free_bkp (void)
{
if (bkp_cut_recur_apoint.mesg)
void recur_apoint_free_bkp(void)
{
if (bkp_cut_recur_apoint.mesg) {
mem_free(bkp_cut_recur_apoint.mesg);
bkp_cut_recur_apoint.mesg = 0;
}
if (bkp_cut_recur_apoint.rpt)
{
if (bkp_cut_recur_apoint.rpt) {
mem_free(bkp_cut_recur_apoint.rpt);
bkp_cut_recur_apoint.rpt = 0;
}
@ -126,8 +113,7 @@ recur_apoint_free_bkp (void)
erase_note(&bkp_cut_recur_apoint.note);
}
static void
recur_event_dup (struct recur_event *in, struct recur_event *bkp)
static void recur_event_dup(struct recur_event *in, struct recur_event *bkp)
{
EXIT_IF(!in || !bkp, _("null pointer"));
@ -146,8 +132,7 @@ recur_event_dup (struct recur_event *in, struct recur_event *bkp)
bkp->note = mem_strdup(in->note);
}
static void
recur_apoint_dup (struct recur_apoint *in, struct recur_apoint *bkp)
static void recur_apoint_dup(struct recur_apoint *in, struct recur_apoint *bkp)
{
EXIT_IF(!in || !bkp, _("null pointer"));
@ -167,14 +152,12 @@ recur_apoint_dup (struct recur_apoint *in, struct recur_apoint *bkp)
bkp->note = mem_strdup(in->note);
}
void
recur_apoint_llist_init (void)
void recur_apoint_llist_init(void)
{
LLIST_TS_INIT(&recur_alist_p);
}
static void
recur_apoint_free (struct recur_apoint *rapt)
static void recur_apoint_free(struct recur_apoint *rapt)
{
mem_free(rapt->mesg);
if (rapt->note)
@ -185,8 +168,7 @@ recur_apoint_free (struct recur_apoint *rapt)
mem_free(rapt);
}
static void
recur_event_free (struct recur_event *rev)
static void recur_event_free(struct recur_event *rev)
{
mem_free(rev->mesg);
if (rev->note)
@ -197,15 +179,13 @@ recur_event_free (struct recur_event *rev)
mem_free(rev);
}
void
recur_apoint_llist_free (void)
void recur_apoint_llist_free(void)
{
LLIST_TS_FREE_INNER(&recur_alist_p, recur_apoint_free);
LLIST_TS_FREE(&recur_alist_p);
}
void
recur_event_llist_free (void)
void recur_event_llist_free(void)
{
LLIST_FREE_INNER(&recur_elist, recur_event_free);
LLIST_FREE(&recur_elist);
@ -217,16 +197,15 @@ recur_apoint_cmp_start (struct recur_apoint *a, struct recur_apoint *b)
return a->start < b->start ? -1 : (a->start == b->start ? 0 : 1);
}
static int
recur_event_cmp_day (struct recur_event *a, struct recur_event *b)
static int recur_event_cmp_day(struct recur_event *a, struct recur_event *b)
{
return a->day < b->day ? -1 : (a->day == b->day ? 0 : 1);
}
/* Insert a new recursive appointment in the general linked list */
struct recur_apoint *
recur_apoint_new (char *mesg, char *note, long start, long dur, char state,
int type, int freq, long until, llist_t *except)
struct recur_apoint *recur_apoint_new(char *mesg, char *note, long start,
long dur, char state, int type, int freq,
long until, llist_t * except)
{
struct recur_apoint *rapt = mem_malloc(sizeof(struct recur_apoint));
@ -239,12 +218,10 @@ recur_apoint_new (char *mesg, char *note, long start, long dur, char state,
rapt->rpt->type = type;
rapt->rpt->freq = freq;
rapt->rpt->until = until;
if (except)
{
if (except) {
exc_dup(&rapt->exc, except);
free_exc_list(except);
}
else
} else
LLIST_INIT(&rapt->exc);
LLIST_TS_LOCK(&recur_alist_p);
@ -255,9 +232,9 @@ recur_apoint_new (char *mesg, char *note, long start, long dur, char state,
}
/* Insert a new recursive event in the general linked list */
struct recur_event *
recur_event_new (char *mesg, char *note, long day, int id, int type, int freq,
long until, llist_t *except)
struct recur_event *recur_event_new(char *mesg, char *note, long day, int id,
int type, int freq, long until,
llist_t * except)
{
struct recur_event *rev = mem_malloc(sizeof(struct recur_event));
@ -269,12 +246,10 @@ recur_event_new (char *mesg, char *note, long day, int id, int type, int freq,
rev->rpt->type = type;
rev->rpt->freq = freq;
rev->rpt->until = until;
if (except)
{
if (except) {
exc_dup(&rev->exc, except);
free_exc_list(except);
}
else
} else
LLIST_INIT(&rev->exc);
LLIST_ADD_SORTED(&recur_elist, rev, recur_event_cmp_day);
@ -286,13 +261,11 @@ recur_event_new (char *mesg, char *note, long day, int id, int type, int freq,
* Correspondance between the defines on recursive type,
* and the letter to be written in file.
*/
char
recur_def2char (enum recur_type define)
char recur_def2char(enum recur_type define)
{
char recur_char;
switch (define)
{
switch (define) {
case RECUR_DAILY:
recur_char = 'D';
break;
@ -317,13 +290,11 @@ recur_def2char (enum recur_type define)
* Correspondance between the letters written in file and the defines
* concerning the recursive type.
*/
int
recur_char2def (char type)
int recur_char2def(char type)
{
int recur_def;
switch (type)
{
switch (type) {
case 'D':
recur_def = RECUR_DAILY;
break;
@ -344,16 +315,14 @@ recur_char2def (char type)
}
/* Write days for which recurrent items should not be repeated. */
static void
recur_write_exc (llist_t *lexc, FILE *f)
static void recur_write_exc(llist_t * lexc, FILE * f)
{
llist_item_t *i;
struct tm *lt;
time_t t;
int st_mon, st_day, st_year;
LLIST_FOREACH (lexc, i)
{
LLIST_FOREACH(lexc, i) {
struct excp *exc = LLIST_GET_DATA(i);
t = exc->st;
lt = localtime(&t);
@ -365,10 +334,9 @@ recur_write_exc (llist_t *lexc, FILE *f)
}
/* Load the recursive appointment description */
struct recur_apoint *
recur_apoint_scan (FILE *f, struct tm start, struct tm end, char type,
int freq, struct tm until, char *note, llist_t *exc,
char state)
struct recur_apoint *recur_apoint_scan(FILE * f, struct tm start, struct tm end,
char type, int freq, struct tm until,
char *note, llist_t * exc, char state)
{
char buf[BUFSIZ], *nl;
time_t tstart, tend, tuntil;
@ -378,8 +346,7 @@ recur_apoint_scan (FILE *f, struct tm start, struct tm end, char type,
return NULL;
nl = strchr(buf, '\n');
if (nl)
{
if (nl) {
*nl = '\0';
}
start.tm_sec = end.tm_sec = 0;
@ -391,8 +358,7 @@ 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;
@ -400,9 +366,7 @@ 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;
}
EXIT_IF(tstart == -1 || tend == -1 || tstart > tend || tuntil == -1,
@ -413,9 +377,9 @@ recur_apoint_scan (FILE *f, struct tm start, struct tm end, char type,
}
/* Load the recursive events from file */
struct recur_event *
recur_event_scan (FILE *f, struct tm start, int id, char type, int freq,
struct tm until, char *note, llist_t *exc)
struct recur_event *recur_event_scan(FILE * f, struct tm start, int id,
char type, int freq, struct tm until,
char *note, llist_t * exc)
{
char buf[BUFSIZ], *nl;
time_t tstart, tuntil;
@ -425,8 +389,7 @@ recur_event_scan (FILE *f, struct tm start, int id, char type, int freq,
return NULL;
nl = strchr(buf, '\n');
if (nl)
{
if (nl) {
*nl = '\0';
}
start.tm_hour = until.tm_hour = 0;
@ -435,27 +398,22 @@ recur_event_scan (FILE *f, struct tm start, int id, char type, int freq,
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);
EXIT_IF (tstart == -1 || tuntil == -1,
_("date error in event"));
EXIT_IF(tstart == -1 || tuntil == -1, _("date error in event"));
return recur_event_new(buf, note, tstart, id, recur_char2def(type), freq,
tuntil, exc);
}
/* Writting of a recursive appointment into file. */
void
recur_apoint_write (struct recur_apoint *o, FILE *f)
void recur_apoint_write(struct recur_apoint *o, FILE * f)
{
struct tm *lt;
time_t t;
@ -471,12 +429,9 @@ recur_apoint_write (struct recur_apoint *o, FILE *f)
1900 + lt->tm_year, lt->tm_hour, lt->tm_min);
t = o->rpt->until;
if (t == 0)
{ /* We have an endless recurrent appointment. */
if (t == 0) { /* We have an endless recurrent appointment. */
fprintf(f, " {%d%c", o->rpt->freq, recur_def2char(o->rpt->type));
}
else
{
} else {
lt = localtime(&t);
fprintf(f, " {%d%c -> %02u/%02u/%04u", o->rpt->freq,
recur_def2char(o->rpt->type), lt->tm_mon + 1, lt->tm_mday,
@ -494,8 +449,7 @@ recur_apoint_write (struct recur_apoint *o, FILE *f)
}
/* Writting of a recursive event into file. */
void
recur_event_write (struct recur_event *o, FILE *f)
void recur_event_write(struct recur_event *o, FILE * f)
{
struct tm *lt;
time_t t;
@ -508,13 +462,10 @@ recur_event_write (struct recur_event *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;
@ -531,27 +482,23 @@ recur_event_write (struct recur_event *o, FILE *f)
}
/* Write recursive items to file. */
void
recur_save_data (FILE *f)
void recur_save_data(FILE * f)
{
llist_item_t *i;
LLIST_FOREACH (&recur_elist, i)
{
LLIST_FOREACH(&recur_elist, i) {
struct recur_event *rev = LLIST_GET_DATA(i);
recur_event_write(rev, f);
}
LLIST_TS_LOCK(&recur_alist_p);
LLIST_TS_FOREACH (&recur_alist_p, i)
{
LLIST_TS_FOREACH(&recur_alist_p, i) {
struct recur_apoint *rapt = LLIST_GET_DATA(i);
recur_apoint_write(rapt, f);
}
LLIST_TS_UNLOCK(&recur_alist_p);
}
/*
* The two following defines together with the diff_days, diff_months and
* diff_years functions were provided by Lukas Fleischer to correct the wrong
@ -564,10 +511,8 @@ recur_save_data (FILE *f)
#define LEAPCOUNT(start, end) \
(BC(start, end, 4) - BC(start, end, 100) + BC(start, end, 400))
/* Calculate the difference in days between two dates. */
static long
diff_days (struct tm lt_start, struct tm lt_end)
static long diff_days(struct tm lt_start, struct tm lt_end)
{
long diff;
@ -576,8 +521,7 @@ diff_days (struct tm lt_start, struct tm lt_end)
diff = lt_end.tm_yday - lt_start.tm_yday;
if (lt_end.tm_year > lt_start.tm_year)
{
if (lt_end.tm_year > lt_start.tm_year) {
diff += (lt_end.tm_year - lt_start.tm_year) * YEARINDAYS;
diff += LEAPCOUNT(lt_start.tm_year + TM_YEAR_BASE,
lt_end.tm_year + TM_YEAR_BASE - 1);
@ -587,8 +531,7 @@ diff_days (struct tm lt_start, struct tm lt_end)
}
/* Calculate the difference in months between two dates. */
static long
diff_months (struct tm lt_start, struct tm lt_end)
static long diff_months(struct tm lt_start, struct tm lt_end)
{
long diff;
@ -602,14 +545,12 @@ diff_months (struct tm lt_start, struct tm lt_end)
}
/* Calculate the difference in years between two dates. */
static long
diff_years (struct tm lt_start, struct tm lt_end)
static long diff_years(struct tm lt_start, struct tm lt_end)
{
return lt_end.tm_year - lt_start.tm_year;
}
static int
exc_inday (struct excp *exc, long day_start)
static int exc_inday(struct excp *exc, long day_start)
{
return (exc->st >= day_start && exc->st < day_start + DAYINSEC);
}
@ -650,8 +591,7 @@ recur_item_find_occurrence (long item_start, long item_dur, llist_t *item_exc,
span = (item_start - mktime(&lt_item_day) + item_dur - 1) / DAYINSEC;
switch (rpt_type)
{
switch (rpt_type) {
case RECUR_DAILY:
diff = diff_days(lt_item_day, lt_day) % rpt_freq;
lt_item_day.tm_mday = lt_day.tm_mday - diff;
@ -695,10 +635,8 @@ recur_item_find_occurrence (long item_start, long item_dur, llist_t *item_exc,
lt_item_day = *localtime(&t);
diff = diff_days(lt_item_day, lt_day);
if (diff <= span)
{
if (occurrence)
{
if (diff <= span) {
if (occurrence) {
start_date.dd = lt_item_day.tm_mday;
start_date.mm = lt_item_day.tm_mon + 1;
start_date.yyyy = lt_item_day.tm_year + 1900;
@ -707,8 +645,7 @@ recur_item_find_occurrence (long item_start, long item_dur, llist_t *item_exc,
}
return 1;
}
else
} else
return 0;
}
@ -741,15 +678,13 @@ recur_item_inday (long item_start, long item_dur, llist_t *item_exc,
rpt_freq, rpt_until, day_start, NULL);
}
unsigned
recur_apoint_inday(struct recur_apoint *rapt, long day_start)
unsigned recur_apoint_inday(struct recur_apoint *rapt, long day_start)
{
return recur_item_inday(rapt->start, rapt->dur, &rapt->exc, rapt->rpt->type,
rapt->rpt->freq, rapt->rpt->until, day_start);
}
unsigned
recur_event_inday(struct recur_event *rev, long day_start)
unsigned recur_event_inday(struct recur_event *rev, long day_start)
{
return recur_item_inday(rev->day, DAYINSEC, &rev->exc, rev->rpt->type,
rev->rpt->freq, rev->rpt->until, day_start);
@ -771,10 +706,8 @@ recur_event_erase (long start, unsigned num, unsigned delete_whole,
EXIT(_("event not found"));
struct recur_event *rev = LLIST_GET_DATA(i);
if (delete_whole)
{
switch (flag)
{
if (delete_whole) {
switch (flag) {
case ERASE_FORCE_ONLY_NOTE:
erase_note(&rev->note);
break;
@ -786,8 +719,7 @@ recur_event_erase (long start, unsigned num, unsigned delete_whole,
default:
LLIST_REMOVE(&recur_elist, i);
mem_free(rev->mesg);
if (rev->rpt)
{
if (rev->rpt) {
mem_free(rev->rpt);
rev->rpt = 0;
}
@ -795,8 +727,7 @@ recur_event_erase (long start, unsigned num, unsigned delete_whole,
mem_free(rev);
break;
}
}
else
} else
recur_add_exc(&rev->exc, start);
}
@ -820,10 +751,8 @@ recur_apoint_erase (long start, unsigned num, unsigned delete_whole,
LLIST_TS_LOCK(&recur_alist_p);
if (notify_bar() && flag != ERASE_FORCE_ONLY_NOTE)
need_check_notify = notify_same_recur_item(rapt);
if (delete_whole)
{
switch (flag)
{
if (delete_whole) {
switch (flag) {
case ERASE_FORCE_ONLY_NOTE:
erase_note(&rapt->note);
break;
@ -835,8 +764,7 @@ recur_apoint_erase (long start, unsigned num, unsigned delete_whole,
default:
LLIST_TS_REMOVE(&recur_alist_p, i);
mem_free(rapt->mesg);
if (rapt->rpt)
{
if (rapt->rpt) {
mem_free(rapt->rpt);
rapt->rpt = 0;
}
@ -846,9 +774,7 @@ recur_apoint_erase (long start, unsigned num, unsigned delete_whole,
notify_check_next_app(0);
break;
}
}
else
{
} else {
recur_add_exc(&rapt->exc, start);
if (need_check_notify)
notify_check_next_app(0);
@ -863,8 +789,7 @@ recur_apoint_erase (long start, unsigned num, unsigned delete_whole,
* o repetition end date
* and then delete the selected item to recreate it as a recurrent one
*/
void
recur_repeat_item (void)
void recur_repeat_item(void)
{
struct tm *lt;
time_t t;
@ -894,10 +819,7 @@ recur_repeat_item (void)
char msg_asktype[BUFSIZ];
snprintf(msg_asktype, BUFSIZ, "%s %s, %s, %s, %s",
msg_rpt_prefix,
msg_rpt_daily,
msg_rpt_weekly,
msg_rpt_monthly,
msg_rpt_yearly);
msg_rpt_daily, msg_rpt_weekly, msg_rpt_monthly, msg_rpt_yearly);
int type = 0, freq = 0;
int item_nb;
@ -907,15 +829,13 @@ recur_repeat_item (void)
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);
wgetch(win[STA].p);
return;
}
switch (status_ask_choice (msg_asktype, msg_type_choice, 4))
{
switch (status_ask_choice(msg_asktype, msg_type_choice, 4)) {
case 1:
type = RECUR_DAILY;
break;
@ -932,59 +852,43 @@ recur_repeat_item (void)
return;
}
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)
{
snprintf (outstr, BUFSIZ, mesg_until_1,
DATEFMT_DESC (conf.input_datefmt));
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 && strcmp (user_input, "0") == 0)
{
if (getstring(win[STA].p, user_input, BUFSIZ, 0, 1) == GETSTRING_VALID) {
if (strlen(user_input) == 1 && strcmp(user_input, "0") == 0) {
until = 0;
date_entered = 1;
}
else
{
} else {
if (parse_date(user_input, conf.input_datefmt,
&year, &month, &day, calendar_get_slctd_day ()))
{
&year, &month, &day, calendar_get_slctd_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)
{
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));
@ -992,26 +896,20 @@ recur_repeat_item (void)
date_entered = 0;
}
}
}
else
} else
return;
}
date = calendar_get_slctd_day_sec();
if (p->type == EVNT)
{
if (p->type == EVNT) {
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
{
} else {
EXIT(_("wrong item type"));
/* NOTREACHED */
}
@ -1022,19 +920,16 @@ recur_repeat_item (void)
* Read days for which recurrent items must not be repeated
* (such days are called exceptions).
*/
void
recur_exc_scan (llist_t *lexc, FILE *data_file)
void recur_exc_scan(llist_t * lexc, FILE * data_file)
{
int c = 0;
struct tm day;
LLIST_INIT(lexc);
while ((c = getc (data_file)) == '!')
{
while ((c = getc(data_file)) == '!') {
ungetc(c, data_file);
if (fscanf(data_file, "!%d / %d / %d ",
&day.tm_mon, &day.tm_mday, &day.tm_year) != 3)
{
&day.tm_mon, &day.tm_mday, &day.tm_year) != 3) {
EXIT(_("syntax error in item date"));
}
day.tm_hour = 0;
@ -1048,8 +943,7 @@ recur_exc_scan (llist_t *lexc, FILE *data_file)
}
}
static int
recur_apoint_starts_before (struct recur_apoint *rapt, long time)
static int recur_apoint_starts_before(struct recur_apoint *rapt, long time)
{
return rapt->start < time;
}
@ -1058,20 +952,19 @@ recur_apoint_starts_before (struct recur_apoint *rapt, long time)
* Look in the appointment list if we have an item which starts before the item
* stored in the notify_app structure (which is the next item to be notified).
*/
struct notify_app *
recur_apoint_check_next (struct notify_app *app, long start, long day)
struct notify_app *recur_apoint_check_next(struct notify_app *app, long start,
long day)
{
llist_item_t *i;
unsigned real_recur_start_time;
LLIST_TS_LOCK(&recur_alist_p);
LLIST_TS_FIND_FOREACH (&recur_alist_p, app->time, recur_apoint_starts_before, i)
{
LLIST_TS_FIND_FOREACH(&recur_alist_p, app->time, recur_apoint_starts_before,
i) {
struct recur_apoint *rapt = LLIST_TS_GET_DATA(i);
if (recur_apoint_find_occurrence(rapt, day, &real_recur_start_time) &&
real_recur_start_time > start)
{
real_recur_start_time > start) {
app->time = real_recur_start_time;
app->txt = mem_strdup(rapt->mesg);
app->state = rapt->state;
@ -1084,8 +977,7 @@ recur_apoint_check_next (struct notify_app *app, long start, long day)
}
/* Returns a structure containing the selected recurrent appointment. */
struct recur_apoint *
recur_get_apoint (long date, int num)
struct recur_apoint *recur_get_apoint(long date, int num)
{
llist_item_t *i = LLIST_TS_FIND_NTH(&recur_alist_p, num, date,
recur_apoint_inday);
@ -1098,8 +990,7 @@ recur_get_apoint (long date, int num)
}
/* Returns a structure containing the selected recurrent event. */
struct recur_event *
recur_get_event (long date, int num)
struct recur_event *recur_get_event(long date, int num)
{
llist_item_t *i = LLIST_FIND_NTH(&recur_elist, num, date,
recur_event_inday);
@ -1112,8 +1003,7 @@ recur_get_event (long date, int num)
}
/* Switch recurrent item notification state. */
void
recur_apoint_switch_notify (long date, int recur_nb)
void recur_apoint_switch_notify(long date, int recur_nb)
{
llist_item_t *i;
@ -1132,8 +1022,7 @@ recur_apoint_switch_notify (long date, int recur_nb)
LLIST_TS_UNLOCK(&recur_alist_p);
}
void
recur_event_paste_item (void)
void recur_event_paste_item(void)
{
long new_start, time_shift;
llist_item_t *i;
@ -1144,8 +1033,7 @@ recur_event_paste_item (void)
bkp_cut_recur_event.day += time_shift;
if (bkp_cut_recur_event.rpt->until != 0)
bkp_cut_recur_event.rpt->until += time_shift;
LLIST_FOREACH (&bkp_cut_recur_event.exc, i)
{
LLIST_FOREACH(&bkp_cut_recur_event.exc, i) {
struct excp *exc = LLIST_GET_DATA(i);
exc->st += time_shift;
}
@ -1158,8 +1046,7 @@ recur_event_paste_item (void)
recur_event_free_bkp();
}
void
recur_apoint_paste_item (void)
void recur_apoint_paste_item(void)
{
long new_start, time_shift;
llist_item_t *i;
@ -1172,8 +1059,7 @@ recur_apoint_paste_item (void)
bkp_cut_recur_apoint.start += time_shift;
if (bkp_cut_recur_apoint.rpt->until != 0)
bkp_cut_recur_apoint.rpt->until += time_shift;
LLIST_FOREACH (&bkp_cut_recur_event.exc, i)
{
LLIST_FOREACH(&bkp_cut_recur_event.exc, i) {
struct excp *exc = LLIST_GET_DATA(i);
exc->st += time_shift;
}
@ -1182,8 +1068,7 @@ recur_apoint_paste_item (void)
bkp_cut_recur_apoint.start, bkp_cut_recur_apoint.dur,
bkp_cut_recur_apoint.state, bkp_cut_recur_apoint.rpt->type,
bkp_cut_recur_apoint.rpt->freq,
bkp_cut_recur_apoint.rpt->until,
&bkp_cut_recur_apoint.exc);
bkp_cut_recur_apoint.rpt->until, &bkp_cut_recur_apoint.exc);
if (notify_bar())
notify_check_repeated(&bkp_cut_recur_apoint);

View File

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

View File

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

View File

@ -47,67 +47,57 @@ static int first = 1;
static char *msgsav;
/* Returns a structure containing the selected item. */
static struct todo *
todo_get_item (int item_number)
static struct todo *todo_get_item(int item_number)
{
return LLIST_GET_DATA(LLIST_NTH(&todolist, item_number - 1));
}
/* Sets which todo is highlighted. */
void
todo_hilt_set (int highlighted)
void todo_hilt_set(int highlighted)
{
hilt = highlighted;
}
void
todo_hilt_decrease (int n)
void todo_hilt_decrease(int n)
{
hilt -= n;
}
void
todo_hilt_increase (int n)
void todo_hilt_increase(int n)
{
hilt += n;
}
/* Return which todo is highlighted. */
int
todo_hilt (void)
int todo_hilt(void)
{
return hilt;
}
/* Return the number of todos. */
int
todo_nb (void)
int todo_nb(void)
{
return todos;
}
/* Set the number of todos. */
void
todo_set_nb (int nb)
void todo_set_nb(int nb)
{
todos = nb;
}
/* Set which one is the first todo to be displayed. */
void
todo_set_first (int nb)
void todo_set_first(int nb)
{
first = nb;
}
void
todo_first_increase (int n)
void todo_first_increase(int n)
{
first += n;
}
void
todo_first_decrease (int n)
void todo_first_decrease(int n)
{
first -= n;
}
@ -116,33 +106,29 @@ todo_first_decrease (int n)
* Return the position of the hilghlighted item, relative to the first one
* displayed.
*/
int
todo_hilt_pos (void)
int todo_hilt_pos(void)
{
return hilt - first;
}
/* Return the last visited todo. */
char *
todo_saved_mesg (void)
char *todo_saved_mesg(void)
{
return msgsav;
}
/* Request user to enter a new todo item. */
void
todo_new_item (void)
void todo_new_item(void)
{
int ch = 0;
const char *mesg = _("Enter the new ToDo item : ");
const char *mesg_id = _("Enter the ToDo priority [1 (highest) - 9 (lowest)] :");
const char *mesg_id =
_("Enter the ToDo priority [1 (highest) - 9 (lowest)] :");
char todo_input[BUFSIZ] = "";
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);
}
@ -151,8 +137,7 @@ todo_new_item (void)
}
}
static int
todo_cmp_id (struct todo *a, struct todo *b)
static int todo_cmp_id(struct todo *a, struct todo *b)
{
/*
* As of version 2.6, todo items can have a negative id, which means they
@ -168,8 +153,7 @@ todo_cmp_id (struct todo *a, struct todo *b)
/*
* Add an item in the todo linked list.
*/
struct todo *
todo_add (char *mesg, int id, char *note)
struct todo *todo_add(char *mesg, int id, char *note)
{
struct todo *todo;
@ -183,8 +167,7 @@ todo_add (char *mesg, int id, char *note)
return todo;
}
void
todo_write (struct todo *todo, FILE *f)
void todo_write(struct todo *todo, FILE * f)
{
if (todo->note)
fprintf(f, "[%d]>%s %s\n", todo->id, todo->note, todo->mesg);
@ -193,8 +176,7 @@ todo_write (struct todo *todo, FILE *f)
}
/* Delete a note previously attached to a todo item. */
static void
todo_delete_note_bynum (unsigned num)
static void todo_delete_note_bynum(unsigned num)
{
llist_item_t *i = LLIST_NTH(&todolist, num);
@ -208,8 +190,7 @@ todo_delete_note_bynum (unsigned num)
}
/* Delete an item from the todo linked list. */
static void
todo_delete_bynum (unsigned num)
static void todo_delete_bynum(unsigned num)
{
llist_item_t *i = LLIST_NTH(&todolist, num);
@ -229,8 +210,7 @@ todo_delete_bynum (unsigned num)
* This way, it is easy to retrive its original priority if the user decides
* that in fact it was not completed.
*/
void
todo_flag (void)
void todo_flag(void)
{
struct todo *t;
@ -239,8 +219,7 @@ todo_flag (void)
}
/* Delete an item from the ToDo list. */
void
todo_delete (void)
void todo_delete(void)
{
const char *del_todo_str = _("Do you really want to delete this task ?");
const char *erase_warning =
@ -251,8 +230,7 @@ todo_delete (void)
int answer;
if ((todos <= 0) ||
(conf.confirm_delete && (status_ask_bool (del_todo_str) != 1)))
{
(conf.confirm_delete && (status_ask_bool(del_todo_str) != 1))) {
wins_erase_status_bar();
return;
}
@ -263,8 +241,7 @@ todo_delete (void)
else
answer = status_ask_choice(erase_warning, erase_choice, nb_erase_choice);
switch (answer)
{
switch (answer) {
case 1:
todo_delete_bynum(hilt - 1);
todos--;
@ -288,14 +265,12 @@ todo_delete (void)
* Returns the position into the linked list corresponding to the
* given todo item.
*/
static int
todo_get_position (struct todo *needle)
static int todo_get_position(struct todo *needle)
{
llist_item_t *i;
int n = 0;
LLIST_FOREACH (&todolist, i)
{
LLIST_FOREACH(&todolist, i) {
n++;
if (LLIST_TS_GET_DATA(i) == needle)
return n;
@ -306,8 +281,7 @@ todo_get_position (struct todo *needle)
}
/* Change an item priority by pressing '+' or '-' inside TODO panel. */
void
todo_chg_priority (int action)
void todo_chg_priority(int action)
{
struct todo *backup;
char backup_mesg[BUFSIZ];
@ -321,8 +295,7 @@ todo_chg_priority (int action)
strncpy(backup_note, backup->note, MAX_NOTESIZ + 1);
else
backup_note[0] = '\0';
switch (action)
{
switch (action) {
case KEY_RAISE_PRIORITY:
if (backup_id > 1)
backup_id--;
@ -346,8 +319,7 @@ todo_chg_priority (int action)
}
/* Edit the description of an already existing todo item. */
void
todo_edit_item (void)
void todo_edit_item(void)
{
struct todo *i;
const char *mesg = _("Enter the new ToDo description :");
@ -378,10 +350,8 @@ display_todo_item (int incolor, char *msg, int prio, int note, int width, int y,
custom_apply_attr(w, ATTR_HIGHEST);
if (utf8_strwidth(msg) < width)
mvwprintw(w, y, x, "%s%c %s", priostr, ch_note, msg);
else
{
for (i = 0; msg[i] && width > 0; i++)
{
else {
for (i = 0; msg[i] && width > 0; i++) {
if (!UTF8_ISCONT(msg[i]))
width -= utf8_width(&msg[i]);
buf[i] = msg[i];
@ -397,8 +367,7 @@ display_todo_item (int incolor, char *msg, int prio, int note, int width, int y,
}
/* Updates the ToDo panel. */
void
todo_update_panel (int which_pan)
void todo_update_panel(int which_pan)
{
llist_item_t *i;
int len = win[TOD].w - 8;
@ -411,28 +380,23 @@ todo_update_panel (int which_pan)
int incolor = -1;
/* Print todo item in the panel. */
erase_window_part (win[TOD].p, 1, title_lines, win[TOD].w - 2,
win[TOD].h - 2);
LLIST_FOREACH (&todolist, i)
{
erase_window_part(win[TOD].p, 1, title_lines, win[TOD].w - 2, win[TOD].h - 2);
LLIST_FOREACH(&todolist, i) {
struct todo *todo = LLIST_TS_GET_DATA(i);
num_todo++;
t_realpos = num_todo - first;
incolor = (which_pan == TOD) ? num_todo - hilt : num_todo;
if (incolor == 0)
msgsav = todo->mesg;
if (t_realpos >= 0 && t_realpos < max_items)
{
if (t_realpos >= 0 && t_realpos < max_items) {
display_todo_item(incolor, todo->mesg, todo->id,
(todo->note != NULL) ? 1 : 0, len, y_offset,
x_offset);
(todo->note != NULL) ? 1 : 0, len, y_offset, x_offset);
y_offset = y_offset + todo_lines;
}
}
/* 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);
@ -449,24 +413,21 @@ todo_update_panel (int which_pan)
}
/* Attach a note to a todo */
void
todo_edit_note (const char *editor)
void todo_edit_note(const char *editor)
{
struct todo *i = todo_get_item(hilt);
edit_note(&i->note, editor);
}
/* View a note previously attached to a todo */
void
todo_view_note (const char *pager)
void todo_view_note(const char *pager)
{
struct todo *i = todo_get_item(hilt);
view_note(i->note, pager);
}
/* Pipe a todo item to an external program. */
void
todo_pipe_item (void)
void todo_pipe_item(void)
{
char cmd[BUFSIZ] = "";
char const *arg[] = { cmd, NULL };
@ -480,8 +441,7 @@ todo_pipe_item (void)
return;
wins_prepare_external();
if ((pid = shell_exec (NULL, &pout, *arg, arg)))
{
if ((pid = shell_exec(NULL, &pout, *arg, arg))) {
fpout = fdopen(pout, "w");
todo = todo_get_item(hilt);
@ -494,22 +454,19 @@ todo_pipe_item (void)
wins_unprepare_external();
}
static void
todo_free (struct todo *todo)
static void todo_free(struct todo *todo)
{
mem_free(todo->mesg);
erase_note(&todo->note);
mem_free(todo);
}
void
todo_init_list (void)
void todo_init_list(void)
{
LLIST_INIT(&todolist);
}
void
todo_free_list (void)
void todo_free_list(void)
{
LLIST_FREE_INNER(&todolist, todo_free);
LLIST_FREE(&todolist);

View File

@ -270,16 +270,14 @@ static const struct utf8_range utf8_widthtab[] = {
};
/* Get the width of a UTF-8 character. */
int
utf8_width (char *s)
int utf8_width(char *s)
{
int val, low, high, cur;
if (UTF8_ISCONT(*s))
return 0;
switch (UTF8_LENGTH (*s))
{
switch (UTF8_LENGTH(*s)) {
case 1:
val = s[0];
break;
@ -287,8 +285,7 @@ utf8_width (char *s)
val = (s[1] & 0x3f) | (s[0] & 0x1f) << 6;
break;
case 3:
val = ((s[2] & 0x3f) | (s[1] & 0x3f) << 6) |
(s[0] & 0x0f) << 12;
val = ((s[2] & 0x3f) | (s[1] & 0x3f) << 6) | (s[0] & 0x0f) << 12;
break;
case 4:
val = (((s[3] & 0x3f) | (s[2] & 0x3f) << 6) |
@ -296,8 +293,7 @@ utf8_width (char *s)
break;
case 5:
val = ((((s[4] & 0x3f) | (s[3] & 0x3f) << 6) |
(s[2] & 0x3f) << 12) | (s[1] & 0x3f) << 18) |
(s[0] & 0x3f) << 24;
(s[2] & 0x3f) << 12) | (s[1] & 0x3f) << 18) | (s[0] & 0x3f) << 24;
break;
case 6:
val = (((((s[5] & 0x3f) | (s[4] & 0x3f) << 6) |
@ -310,17 +306,14 @@ utf8_width (char *s)
low = 0;
high = sizeof(utf8_widthtab) / sizeof(utf8_widthtab[0]);
do
{
do {
cur = (low + high) / 2;
if (val >= utf8_widthtab[cur].min)
{
if (val >= utf8_widthtab[cur].min) {
if (val <= utf8_widthtab[cur].max)
return utf8_widthtab[cur].width;
else
low = cur + 1;
}
else
} else
high = cur - 1;
}
while (low <= high);
@ -329,13 +322,11 @@ utf8_width (char *s)
}
/* Get the width of a UTF-8 string. */
int
utf8_strwidth (char *s)
int utf8_strwidth(char *s)
{
int width = 0;
for (; s && *s; s++)
{
for (; s && *s; s++) {
if (!UTF8_ISCONT(*s))
width += utf8_width(s);
}

View File

@ -66,21 +66,18 @@ enum format_specifier {
};
/* General routine to exit calcurse properly. */
void
exit_calcurse (int status)
void exit_calcurse(int status)
{
int was_interactive;
if (ui_mode == UI_CURSES)
{
if (ui_mode == UI_CURSES) {
notify_stop_main_thread();
clear();
wins_refresh();
endwin();
ui_mode = UI_CMDLINE;
was_interactive = 1;
}
else
} else
was_interactive = 0;
calendar_stop_date_thread();
@ -88,11 +85,9 @@ exit_calcurse (int status)
free_user_data();
keys_free();
mem_stats();
if (was_interactive)
{
if (was_interactive) {
if (unlink(path_cpid) != 0)
EXIT (_("Could not remove calcurse lock file: %s\n"),
strerror (errno));
EXIT(_("Could not remove calcurse lock file: %s\n"), strerror(errno));
if (dmon.enable)
dmon_start(status);
}
@ -100,8 +95,7 @@ exit_calcurse (int status)
exit(status);
}
void
free_user_data (void)
void free_user_data(void)
{
day_free_list();
event_llist_free();
@ -117,8 +111,7 @@ free_user_data (void)
}
/* Function to exit on internal error. */
void
fatalbox (const char *errmsg)
void fatalbox(const char *errmsg)
{
WINDOW *errwin;
const char *label = _("/!\\ INTERNAL ERROR /!\\");
@ -145,8 +138,7 @@ fatalbox (const char *errmsg)
wins_doupdate();
}
void
warnbox (const char *msg)
void warnbox(const char *msg)
{
WINDOW *warnwin;
const char *label = "/!\\";
@ -175,8 +167,7 @@ warnbox (const char *msg)
* Print a message in the status bar.
* Message texts for first line and second line are to be provided.
*/
void
status_mesg (const char *msg1, const char *msg2)
void status_mesg(const char *msg1, const char *msg2)
{
wins_erase_status_bar();
custom_apply_attr(win[STA].p, ATTR_HIGHEST);
@ -196,8 +187,7 @@ status_mesg (const char *msg1, const char *msg2)
* Returns the index of the key pressed by the user (starting from 1),
* or -1 if the user doesn't want to answer (e.g. by escaping).
*/
int
status_ask_choice(const char *message, const char choice[], int nb_choice)
int status_ask_choice(const char *message, const char choice[], int nb_choice)
{
int i, ch;
char tmp[BUFSIZ];
@ -207,24 +197,21 @@ status_ask_choice(const char *message, const char choice[], int nb_choice)
avail_choice[0] = '[';
avail_choice[1] = '\0';
for (i = 1; i <= nb_choice; i++)
{
for (i = 1; i <= nb_choice; i++) {
snprintf(tmp, BUFSIZ, (i == nb_choice) ? "%c] " : "%c/", choice[i]);
strcat(avail_choice, tmp);
}
status_mesg(message, avail_choice);
for (;;)
{
for (;;) {
ch = wgetch(win[STA].p);
for (i = 1; i <= nb_choice; i++)
if (ch == choice[i])
return i;
if (ch == ESCAPE)
return (-1);
if (resize)
{
if (resize) {
resize = 0;
wins_reset();
status_mesg(message, avail_choice);
@ -237,8 +224,7 @@ status_ask_choice(const char *message, const char choice[], int nb_choice)
*
* Returns 1 if yes, 2 if no, and -1 otherwise
*/
int
status_ask_bool (const char *msg)
int status_ask_bool(const char *msg)
{
return (status_ask_choice(msg, _("[yn]"), 2));
}
@ -250,8 +236,7 @@ status_ask_bool (const char *msg)
* the user doesn't want to answer.
*/
int
status_ask_simplechoice (const char *prefix, const char *choice[],
int nb_choice)
status_ask_simplechoice(const char *prefix, const char *choice[], int nb_choice)
{
int i;
char tmp[BUFSIZ];
@ -266,8 +251,7 @@ status_ask_simplechoice (const char *prefix, const char *choice[],
strcpy(choicestr, prefix);
for (i = 0; i < nb_choice; i++)
{
for (i = 0; i < nb_choice; i++) {
snprintf(tmp, BUFSIZ, ((i + 1) == nb_choice) ? "(%d) %s?" : "(%d) %s, ",
(i + 1), _(choice[i]));
strcat(choicestr, tmp);
@ -283,16 +267,14 @@ 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 (r = first_row; r <= last_row; r++) {
for (c = first_col; c <= last_col; c++)
mvwprintw(win, r, c, " ");
}
}
/* draws a popup window */
WINDOW *
popup (int pop_row, int pop_col, int pop_y, int pop_x, const char *title,
WINDOW *popup(int pop_row, int pop_col, int pop_y, int pop_x, const char *title,
const char *msg, int hint)
{
const char *any_key = _("Press any key to continue...");
@ -339,11 +321,9 @@ print_in_middle (WINDOW *win, int starty, int startx, int width,
}
/* checks if a string is only made of digits */
int
is_all_digit (const char *string)
{
for (; *string; string++)
int is_all_digit(const char *string)
{
for (; *string; string++) {
if (!isdigit((int)*string))
return 0;
}
@ -352,27 +332,23 @@ is_all_digit (const char *string)
}
/* Given an item date expressed in seconds, return its start time in seconds. */
long
get_item_time (long date)
long get_item_time(long date)
{
return (long)(get_item_hour(date) * HOURINSEC +
get_item_min(date) * MININSEC);
}
int
get_item_hour (long date)
int get_item_hour(long date)
{
return (localtime((time_t *) & date))->tm_hour;
}
int
get_item_min (long date)
int get_item_min(long date)
{
return (localtime((time_t *) & date))->tm_min;
}
long
date2sec (struct date day, unsigned hour, unsigned min)
long date2sec(struct date day, unsigned hour, unsigned min)
{
time_t t = now();
struct tm start = *(localtime(&t));
@ -392,16 +368,14 @@ date2sec (struct date day, unsigned hour, unsigned min)
}
/* Return a string containing the date, given a date in seconds. */
char *
date_sec2date_str (long sec, const char *datefmt)
char *date_sec2date_str(long sec, const char *datefmt)
{
struct tm *lt;
char *datestr = (char *)mem_calloc(BUFSIZ, sizeof(char));
if (sec == 0)
strncpy(datestr, "0", BUFSIZ);
else
{
else {
lt = localtime((time_t *) & sec);
strftime(datestr, BUFSIZ, datefmt, lt);
}
@ -410,8 +384,7 @@ date_sec2date_str (long sec, const char *datefmt)
}
/* Generic function to format date. */
void
date_sec2date_fmt (long sec, const char *fmt, char *datef)
void date_sec2date_fmt(long sec, const char *fmt, char *datef)
{
struct tm *lt = localtime((time_t *) & sec);
strftime(datef, BUFSIZ, fmt, lt);
@ -420,8 +393,7 @@ date_sec2date_fmt (long sec, const char *fmt, char *datef)
/*
* Used to change date by adding a certain amount of days or weeks.
*/
long
date_sec_change (long date, int delta_month, int delta_day)
long date_sec_change(long date, int delta_month, int delta_day)
{
struct tm *lt;
time_t t;
@ -441,8 +413,7 @@ date_sec_change (long date, int delta_month, int delta_day)
* Return a long containing the date which is updated taking into account
* the new time and date entered by the user.
*/
long
update_time_in_date (long date, unsigned hr, unsigned mn)
long update_time_in_date(long date, unsigned hr, unsigned mn)
{
struct tm *lt;
time_t t, new_date;
@ -461,8 +432,7 @@ update_time_in_date (long date, unsigned hr, unsigned mn)
* Returns the date in seconds from year 1900.
* If no date is entered, current date is chosen.
*/
long
get_sec_date (struct date date)
long get_sec_date(struct date date)
{
struct tm *ptrtime;
time_t timer;
@ -471,8 +441,7 @@ get_sec_date (struct date 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);
@ -486,8 +455,7 @@ get_sec_date (struct date date)
return long_date;
}
long
min2sec (unsigned minutes)
long min2sec(unsigned minutes)
{
return minutes * MININSEC;
}
@ -526,8 +494,7 @@ item_in_popup (const char *saved_a_start, const char *saved_a_end,
pad = newpad(padl, padw);
popup_win = popup(winl, winw, 1, 2, pop_title, NULL, 1);
if (strcmp (pop_title, _("Appointment")) == 0)
{
if (strcmp(pop_title, _("Appointment")) == 0) {
mvwprintw(popup_win, margin_top, margin_left, "- %s -> %s",
saved_a_start, saved_a_end);
}
@ -541,8 +508,7 @@ item_in_popup (const char *saved_a_start, const char *saved_a_end,
}
/* Returns the beginning of current day in seconds from 1900. */
long
get_today (void)
long get_today(void)
{
struct tm *lt;
time_t current_time;
@ -560,14 +526,12 @@ get_today (void)
}
/* Returns the current time in seconds. */
long
now (void)
long now(void)
{
return (long)time(NULL);
}
char *
nowstr (void)
char *nowstr(void)
{
static char buf[BUFSIZ];
time_t t = now();
@ -577,8 +541,7 @@ nowstr (void)
return buf;
}
long
mystrtol (const char *str)
long mystrtol(const char *str)
{
char *ep;
long lval;
@ -600,17 +563,13 @@ print_bool_option_incolor (WINDOW *win, unsigned option, int pos_y, int pos_x)
int color = 0;
const char *option_value;
if (option == 1)
{
if (option == 1) {
color = ATTR_TRUE;
option_value = _("yes");
}
else if (option == 0)
{
} else if (option == 0) {
color = ATTR_FALSE;
option_value = _("no");
}
else
} else
EXIT(_("option not defined"));
custom_apply_attr(win, color);
@ -620,12 +579,10 @@ print_bool_option_incolor (WINDOW *win, unsigned option, int pos_y, int pos_x)
wins_doupdate();
}
/*
* Get the name of the default directory for temporary files.
*/
const char *
get_tempdir (void)
const char *get_tempdir(void)
{
if (getenv("TMPDIR"))
return getenv("TMPDIR");
@ -641,8 +598,7 @@ get_tempdir (void)
* Create a new unique file, and return a newly allocated string which contains
* the random part of the file name.
*/
char *
new_tempfile (const char *prefix, int trailing_len)
char *new_tempfile(const char *prefix, int trailing_len)
{
char fullname[BUFSIZ];
int prefix_len, fd;
@ -657,10 +613,8 @@ 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);
}
@ -697,14 +651,11 @@ parse_date (const char *date_string, enum datefmt datefmt, int *year,
return 0;
/* parse string into in[], read up to three integers */
for (p = date_string; *p; p++)
{
if (*p == sep)
{
for (p = date_string; *p; p++) {
if (*p == sep) {
if ((++n) > 2)
return 0;
}
else if ((*p >= '0') && (*p <= '9'))
} else if ((*p >= '0') && (*p <= '9'))
in[n] = in[n] * 10 + (int)(*p - '0');
else
return 0;
@ -714,8 +665,7 @@ parse_date (const char *date_string, enum datefmt datefmt, int *year,
return 0;
/* convert into day, month and year, depending on the date format */
switch (datefmt)
{
switch (datefmt) {
case DATEFMT_MMDDYYYY:
m = (n >= 1) ? in[0] : 0;
d = (n >= 1) ? in[1] : in[0];
@ -736,18 +686,15 @@ parse_date (const char *date_string, enum datefmt datefmt, int *year,
return 0;
}
if (slctd_date)
{
if (y > 0 && y < 100)
{
if (slctd_date) {
if (y > 0 && y < 100) {
/* convert "YY" format into "YYYY" */
y += slctd_date->yyyy - slctd_date->yyyy % 100;
}
else if (n < 2)
{
} else if (n < 2) {
/* set year and, optionally, month if short from is used */
y = slctd_date->yyyy;
if (n < 1) m = slctd_date->mm;
if (n < 1)
m = slctd_date->mm;
}
}
@ -772,8 +719,7 @@ parse_date (const char *date_string, enum datefmt datefmt, int *year,
*
* Returns 1 on success and 0 on failure.
*/
int
parse_time (const char *string, unsigned *hour, unsigned *minute)
int parse_time(const char *string, unsigned *hour, unsigned *minute)
{
const char *p;
unsigned in[2] = { 0, 0 }, n = 0;
@ -782,14 +728,11 @@ parse_time (const char *string, unsigned *hour, unsigned *minute)
return 0;
/* parse string into in[], read up to two integers */
for (p = string; *p; p++)
{
if (*p == ':')
{
for (p = string; *p; p++) {
if (*p == ':') {
if ((++n) > 1)
return 0;
}
else if ((*p >= '0') && (*p <= '9'))
} else if ((*p >= '0') && (*p <= '9'))
in[n] = in[n] * 10 + (int)(*p - '0');
else
return 0;
@ -816,8 +759,7 @@ parse_time (const char *string, unsigned *hour, unsigned *minute)
*
* Returns 1 on success and 0 on failure.
*/
int
parse_duration (const char *string, unsigned *duration)
int parse_duration(const char *string, unsigned *duration)
{
enum {
STATE_INITIAL,
@ -835,64 +777,45 @@ parse_duration (const char *string, unsigned *duration)
return 0;
/* parse string using a simple state machine */
for (p = string; *p; p++)
{
if ((*p >= '0') && (*p <= '9'))
{
for (p = string; *p; p++) {
if ((*p >= '0') && (*p <= '9')) {
if (state == STATE_DONE)
return 0;
else
in = in * 10 + (int)(*p - '0');
}
else
{
switch (state)
{
} else {
switch (state) {
case STATE_INITIAL:
if (*p == ':')
{
if (*p == ':') {
dur += in * HOURINMIN;
state = STATE_HHMM_MM;
}
else if (*p == 'd')
{
} else if (*p == 'd') {
dur += in * DAYINMIN;
state = STATE_DDHHMM_HH;
}
else if (*p == 'h')
{
} else if (*p == 'h') {
dur += in * HOURINMIN;
state = STATE_DDHHMM_MM;
}
else if (*p == 'm')
{
} else if (*p == 'm') {
dur += in;
state = STATE_DONE;
}
else
} else
return 0;
break;
case STATE_DDHHMM_HH:
if (*p == 'h')
{
if (*p == 'h') {
dur += in * HOURINMIN;
state = STATE_DDHHMM_MM;
}
else if (*p == 'm')
{
} else if (*p == 'm') {
dur += in;
state = STATE_DONE;
}
else
} else
return 0;
break;
case STATE_DDHHMM_MM:
if (*p == 'm')
{
if (*p == 'm') {
dur += in;
state = STATE_DONE;
}
else
} else
return 0;
break;
case STATE_HHMM_MM:
@ -915,8 +838,7 @@ parse_duration (const char *string, unsigned *duration)
return 1;
}
void
str_toupper (char *s)
void str_toupper(char *s)
{
if (!s)
return;
@ -924,8 +846,7 @@ str_toupper (char *s)
*s = toupper(*s);
}
void
file_close (FILE *f, const char *pos)
void file_close(FILE * f, const char *pos)
{
EXIT_IF((fclose(f)) != 0, _("Error when closing file at %s"), pos);
}
@ -935,13 +856,11 @@ file_close (FILE *f, const char *pos)
* (hence the 'p') in a way that even if a signal is caught during the sleep
* process, this function will return to sleep afterwards.
*/
void
psleep (unsigned secs)
void psleep(unsigned secs)
{
unsigned unslept;
for (unslept = sleep (secs); unslept; unslept = sleep (unslept))
;
for (unslept = sleep(secs); unslept; unslept = sleep(unslept)) ;
}
/*
@ -950,8 +869,7 @@ psleep (unsigned secs)
* If pfdin and/or pfdout point to a valid address, a pipe is created and the
* appropriate file descriptors are written to pfdin/pfdout.
*/
int
fork_exec (int *pfdin, int *pfdout, const char *path, const char *const *arg)
int fork_exec(int *pfdin, int *pfdout, const char *path, const char *const *arg)
{
int pin[2], pout[2];
int pid;
@ -961,18 +879,15 @@ fork_exec (int *pfdin, int *pfdout, const char *path, const char *const *arg)
if (pfdout && (pipe(pout) == -1))
return 0;
if ((pid = fork ()) == 0)
{
if (pfdout)
{
if ((pid = fork()) == 0) {
if (pfdout) {
if (dup2(pout[0], STDIN_FILENO) < 0)
_exit(127);
close(pout[0]);
close(pout[1]);
}
if (pfdin)
{
if (pfdin) {
if (dup2(pin[1], STDOUT_FILENO) < 0)
_exit(127);
close(pin[0]);
@ -981,29 +896,22 @@ fork_exec (int *pfdin, int *pfdout, const char *path, const char *const *arg)
execvp(path, (char *const *)arg);
_exit(127);
}
else
{
} else {
if (pfdin)
close(pin[1]);
if (pfdout)
close(pout[0]);
if (pid > 0)
{
if (pfdin)
{
if (pid > 0) {
if (pfdin) {
fcntl(pin[0], F_SETFD, FD_CLOEXEC);
*pfdin = pin[0];
}
if (pfdout)
{
if (pfdout) {
fcntl(pout[1], F_SETFD, FD_CLOEXEC);
*pfdout = pout[1];
}
}
else
{
} else {
if (pfdin)
close(pin[0]);
if (pfdout)
@ -1023,8 +931,7 @@ shell_exec (int *pfdin, int *pfdout, const char *path, const char *const *arg)
char *arg0 = NULL;
int ret;
for (argc = 0; arg[argc]; argc++)
;
for (argc = 0; arg[argc]; argc++) ;
if (argc < 1)
return -1;
@ -1034,8 +941,7 @@ shell_exec (int *pfdin, int *pfdout, const char *path, const char *const *arg)
narg[0] = "sh";
narg[1] = "-c";
if (argc > 1)
{
if (argc > 1) {
arg0 = mem_malloc(strlen(path) + 6);
sprintf(arg0, "%s \"$@\"", path);
narg[2] = arg0;
@ -1043,9 +949,7 @@ shell_exec (int *pfdin, int *pfdout, const char *path, const char *const *arg)
for (i = 0; i < argc; i++)
narg[i + 3] = arg[i];
narg[argc + 3] = NULL;
}
else
{
} else {
narg[2] = path;
narg[3] = NULL;
}
@ -1060,8 +964,7 @@ shell_exec (int *pfdin, int *pfdout, const char *path, const char *const *arg)
}
/* Wait for a child process to terminate. */
int
child_wait (int *pfdin, int *pfdout, int pid)
int child_wait(int *pfdin, int *pfdout, int pid)
{
int stat;
@ -1075,8 +978,7 @@ child_wait (int *pfdin, int *pfdout, int pid)
}
/* Display "Press any key to continue..." and wait for a key press. */
void
press_any_key (void)
void press_any_key(void)
{
struct termios t_attr_old, t_attr;
@ -1103,8 +1005,7 @@ press_any_key (void)
*
* (patch submitted by Erik Saule).
*/
static void
print_notefile (FILE *out, const char *filename, int nbtab)
static void print_notefile(FILE * out, const char *filename, int nbtab)
{
char path_to_notefile[BUFSIZ];
FILE *notefile;
@ -1113,23 +1014,18 @@ print_notefile (FILE *out, const char *filename, int nbtab)
int i;
int printlinestarter = 1;
if (nbtab < BUFSIZ)
{
if (nbtab < BUFSIZ) {
for (i = 0; i < nbtab; i++)
linestarter[i] = '\t';
linestarter[nbtab] = '\0';
}
else
} else
linestarter[0] = '\0';
snprintf(path_to_notefile, BUFSIZ, "%s/%s", path_notes, filename);
notefile = fopen(path_to_notefile, "r");
if (notefile)
{
while (fgets (buffer, BUFSIZ, notefile) != 0)
{
if (printlinestarter)
{
if (notefile) {
while (fgets(buffer, BUFSIZ, notefile) != 0) {
if (printlinestarter) {
fputs(linestarter, out);
printlinestarter = 0;
}
@ -1139,20 +1035,16 @@ print_notefile (FILE *out, const char *filename, int nbtab)
}
fputs("\n", out);
file_close(notefile, __FILE_POS__);
}
else
{
} else {
fputs(linestarter, out);
fputs(_("No note file found\n"), out);
}
}
/* Print an escape sequence and return its length. */
static int
print_escape (const char *s)
{
switch (*(s + 1))
static int print_escape(const char *s)
{
switch (*(s + 1)) {
case 'a':
putchar('\a');
return 1;
@ -1197,16 +1089,14 @@ print_escape (const char *s)
}
/* Parse a format specifier. */
static enum format_specifier
parse_fs (const char **s, char *extformat)
static enum format_specifier parse_fs(const char **s, char *extformat)
{
char buf[FS_EXT_MAXLEN];
int i;
extformat[0] = '\0';
switch (**s)
{
switch (**s) {
case 's':
strcpy(extformat, "epoch");
return FS_STARTDATE;
@ -1229,8 +1119,7 @@ parse_fs (const char **s, char *extformat)
return FS_PRIORITY;
case '(':
/* Long format specifier. */
for ((*s)++, i = 0; **s != ':' && **s != ')'; (*s)++, i++)
{
for ((*s)++, i = 0; **s != ':' && **s != ')'; (*s)++, i++) {
if (**s == '\0')
return FS_EOF;
@ -1240,10 +1129,8 @@ parse_fs (const char **s, char *extformat)
buf[(i < FS_EXT_MAXLEN) ? i : FS_EXT_MAXLEN - 1] = '\0';
if (**s == ':')
{
for ((*s)++, i = 0; **s != ')'; (*s)++, i++)
{
if (**s == ':') {
for ((*s)++, i = 0; **s != ')'; (*s)++, i++) {
if (**s == '\0')
return FS_EOF;
@ -1280,15 +1167,13 @@ parse_fs (const char **s, char *extformat)
}
/* Print a formatted date to stdout. */
static void
print_date (long date, const char *extformat)
static void print_date(long date, const char *extformat)
{
char buf[BUFSIZ];
if (!strcmp(extformat, "epoch"))
printf("%ld", date);
else
{
else {
time_t t = date;
struct tm *lt = localtime((time_t *) & t);
@ -1302,18 +1187,15 @@ print_date (long date, const char *extformat)
}
/* Print a formatted appointment to stdout. */
void
print_apoint (const char *format, long day, struct apoint *apt)
void print_apoint(const char *format, long day, struct apoint *apt)
{
const char *p;
char extformat[FS_EXT_MAXLEN];
for (p = format; *p; p++)
{
for (p = format; *p; p++) {
if (*p == '%') {
p++;
switch (parse_fs (&p, extformat))
{
switch (parse_fs(&p, extformat)) {
case FS_STARTDATE:
print_date(apt->start, extformat);
break;
@ -1342,8 +1224,7 @@ print_apoint (const char *format, long day, struct apoint *apt)
putchar('?');
break;
}
}
else if (*p == '\\')
} else if (*p == '\\')
p += print_escape(p);
else
putchar(*p);
@ -1351,18 +1232,15 @@ print_apoint (const char *format, long day, struct apoint *apt)
}
/* Print a formatted event to stdout. */
void
print_event (const char *format, long day, struct event *ev)
void print_event(const char *format, long day, struct event *ev)
{
const char *p;
char extformat[FS_EXT_MAXLEN];
for (p = format; *p; p++)
{
for (p = format; *p; p++) {
if (*p == '%') {
p++;
switch (parse_fs (&p, extformat))
{
switch (parse_fs(&p, extformat)) {
case FS_MESSAGE:
printf("%s", ev->mesg);
break;
@ -1382,8 +1260,7 @@ print_event (const char *format, long day, struct event *ev)
putchar('?');
break;
}
}
else if (*p == '\\')
} else if (*p == '\\')
p += print_escape(p);
else
putchar(*p);
@ -1406,8 +1283,7 @@ print_recur_apoint (const char *format, long day, unsigned occurrence,
}
/* Print a formatted recurrent event to stdout. */
void
print_recur_event (const char *format, long day, struct recur_event *rev)
void print_recur_event(const char *format, long day, struct recur_event *rev)
{
struct event ev;
@ -1418,18 +1294,15 @@ print_recur_event (const char *format, long day, struct recur_event *rev)
}
/* Print a formatted todo item to stdout. */
void
print_todo (const char *format, struct todo *todo)
void print_todo(const char *format, struct todo *todo)
{
const char *p;
char extformat[FS_EXT_MAXLEN];
for (p = format; *p; p++)
{
for (p = format; *p; p++) {
if (*p == '%') {
p++;
switch (parse_fs (&p, extformat))
{
switch (parse_fs(&p, extformat)) {
case FS_PRIORITY:
printf("%d", abs(todo->id));
break;
@ -1452,8 +1325,7 @@ print_todo (const char *format, struct todo *todo)
putchar('?');
break;
}
}
else if (*p == '\\')
} else if (*p == '\\')
p += print_escape(p);
else
putchar(*p);

View File

@ -65,6 +65,7 @@ int read_only = 0;
* variables to store calendar names
*/
int days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
const char *monthnames[12] = {
N_("January"),
N_("February"),
@ -120,8 +121,7 @@ struct dmon_conf dmon;
/*
* Variables init
*/
void
vars_init (void)
void vars_init(void)
{
const char *ed, *pg;

View File

@ -63,8 +63,7 @@ static int layout;
*/
static pthread_mutex_t screen_mutex = PTHREAD_MUTEX_INITIALIZER;
static unsigned
screen_acquire (void)
static unsigned screen_acquire(void)
{
if (pthread_mutex_lock(&screen_mutex) != 0)
return 0;
@ -72,14 +71,12 @@ screen_acquire (void)
return 1;
}
static void
screen_release (void)
static void screen_release(void)
{
pthread_mutex_unlock(&screen_mutex);
}
int
wins_refresh (void)
int wins_refresh(void)
{
int rc;
@ -91,8 +88,7 @@ wins_refresh (void)
return rc;
}
int
wins_wrefresh (WINDOW *win)
int wins_wrefresh(WINDOW * win)
{
int rc;
@ -104,8 +100,7 @@ wins_wrefresh (WINDOW *win)
return rc;
}
int
wins_doupdate (void)
int wins_doupdate(void)
{
int rc;
@ -118,27 +113,23 @@ wins_doupdate (void)
}
/* Get the current layout. */
int
wins_layout (void)
int wins_layout(void)
{
return layout;
}
/* Set the current layout. */
void
wins_set_layout (int nb)
void wins_set_layout(int nb)
{
layout = nb;
}
/* Get the current side bar width. */
unsigned
wins_sbar_width (void)
unsigned wins_sbar_width(void)
{
if (sbarwidth_perc > SBARMAXWIDTHPERC)
return col * SBARMAXWIDTHPERC / 100;
else
{
else {
unsigned sbarwidth = (unsigned)(col * sbarwidth_perc / 100);
return (sbarwidth < SBARMINWIDTH) ? SBARMINWIDTH : sbarwidth;
}
@ -148,8 +139,7 @@ wins_sbar_width (void)
* Return the side bar width in percentage of the total number of columns
* available in calcurse's screen.
*/
unsigned
wins_sbar_wperc (void)
unsigned wins_sbar_wperc(void)
{
return sbarwidth_perc > SBARMAXWIDTHPERC ? SBARMAXWIDTHPERC : sbarwidth_perc;
}
@ -160,51 +150,44 @@ wins_sbar_wperc (void)
* The side bar could not have a width representing more than 50% of the screen,
* and could not be less than SBARMINWIDTH characters.
*/
void
wins_set_sbar_width (unsigned perc)
void wins_set_sbar_width(unsigned perc)
{
sbarwidth_perc = perc;
}
/* Change the width of the side bar within acceptable boundaries. */
void
wins_sbar_winc (void)
void wins_sbar_winc(void)
{
if (sbarwidth_perc < SBARMAXWIDTHPERC)
sbarwidth_perc++;
}
void
wins_sbar_wdec (void)
void wins_sbar_wdec(void)
{
if (sbarwidth_perc > 0)
sbarwidth_perc--;
}
/* Initialize the selected window in calcurse's interface. */
void
wins_slctd_init (void)
void wins_slctd_init(void)
{
wins_slctd_set(CAL);
}
/* Returns an enum which corresponds to the window which is selected. */
enum win
wins_slctd (void)
enum win wins_slctd(void)
{
return slctd_win;
}
/* Sets the selected window. */
void
wins_slctd_set (enum win window)
void wins_slctd_set(enum win window)
{
slctd_win = window;
}
/* TAB key was hit in the interface, need to select next window. */
void
wins_slctd_next (void)
void wins_slctd_next(void)
{
if (slctd_win == TOD)
slctd_win = CAL;
@ -212,8 +195,7 @@ wins_slctd_next (void)
slctd_win++;
}
static void
wins_init_panels (void)
static void wins_init_panels(void)
{
win[CAL].p = newwin(CALHEIGHT, wins_sbar_width(), win[CAL].y, win[CAL].x);
wins_show(win[CAL].p, _("Calendar"));
@ -233,8 +215,7 @@ wins_init_panels (void)
}
/* Create all the windows. */
void
wins_init (void)
void wins_init(void)
{
wins_init_panels();
win[STA].p = newwin(win[STA].h, win[STA].w, win[STA].y, win[STA].x);
@ -249,8 +230,7 @@ wins_init (void)
* Create a new window and its associated pad, which is used to make the
* scrolling faster.
*/
void
wins_scrollwin_init (struct scrollwin *sw)
void wins_scrollwin_init(struct scrollwin *sw)
{
EXIT_IF(sw == NULL, "null pointer");
sw->win.p = newwin(sw->win.h, sw->win.w, sw->win.y, sw->win.x);
@ -260,8 +240,7 @@ wins_scrollwin_init (struct scrollwin *sw)
}
/* Free an already created scrollwin. */
void
wins_scrollwin_delete (struct scrollwin *sw)
void wins_scrollwin_delete(struct scrollwin *sw)
{
EXIT_IF(sw == NULL, "null pointer");
delwin(sw->win.p);
@ -269,13 +248,11 @@ wins_scrollwin_delete (struct scrollwin *sw)
}
/* Display a scrolling window. */
void
wins_scrollwin_display (struct scrollwin *sw)
void wins_scrollwin_display(struct scrollwin *sw)
{
const int visible_lines = sw->win.h - sw->pad.y - 1;
if (sw->total_lines > visible_lines)
{
if (sw->total_lines > visible_lines) {
float ratio = ((float)visible_lines) / ((float)sw->total_lines);
int sbar_length = (int)(ratio * visible_lines);
int highend = (int)(ratio * sw->first_visible_line);
@ -293,23 +270,19 @@ wins_scrollwin_display (struct scrollwin *sw)
wins_doupdate();
}
void
wins_scrollwin_up (struct scrollwin *sw, int amount)
void wins_scrollwin_up(struct scrollwin *sw, int amount)
{
if (sw->first_visible_line > 0)
sw->first_visible_line -= amount;
}
void
wins_scrollwin_down (struct scrollwin *sw, int amount)
void wins_scrollwin_down(struct scrollwin *sw, int amount)
{
if (sw->total_lines
> (sw->first_visible_line + sw->win.h - sw->pad.y - 1))
if (sw->total_lines > (sw->first_visible_line + sw->win.h - sw->pad.y - 1))
sw->first_visible_line += amount;
}
void
wins_reinit_panels (void)
void wins_reinit_panels(void)
{
delwin(win[CAL].p);
delwin(win[APP].p);
@ -323,8 +296,7 @@ wins_reinit_panels (void)
* Delete the existing windows and recreate them with their new
* size and placement.
*/
void
wins_reinit (void)
void wins_reinit(void)
{
delwin(win[CAL].p);
delwin(win[APP].p);
@ -338,8 +310,7 @@ wins_reinit (void)
}
/* Show the window with a border and a label. */
void
wins_show (WINDOW *win, const char *label)
void wins_show(WINDOW * win, const char *label)
{
int width = getmaxx(win);
@ -354,8 +325,7 @@ wins_show (WINDOW *win, const char *label)
/*
* Get the screen size and recalculate the windows configurations.
*/
void
wins_get_config (void)
void wins_get_config(void)
{
/* Get the screen configuration */
getmaxyx(stdscr, row, col);
@ -366,15 +336,12 @@ 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;
@ -384,15 +351,12 @@ wins_get_config (void)
win[CAL].w = wins_sbar_width();
win[CAL].h = CALHEIGHT;
if (layout <= 4)
{ /* APPOINTMENT is the biggest panel */
if (layout <= 4) { /* APPOINTMENT is the biggest panel */
win[APP].w = col - win[CAL].w;
win[APP].h = row - (win[STA].h + win[NOT].h);
win[TOD].w = win[CAL].w;
win[TOD].h = row - (win[CAL].h + win[STA].h + win[NOT].h);
}
else
{ /* TODO is the biggest panel */
} else { /* TODO is the biggest panel */
win[TOD].w = col - win[CAL].w;
win[TOD].h = row - (win[STA].h + win[NOT].h);
win[APP].w = win[CAL].w;
@ -400,8 +364,7 @@ wins_get_config (void)
}
/* defining the layout */
switch (layout)
{
switch (layout) {
case 1:
win[APP].y = 0;
win[APP].x = 0;
@ -470,79 +433,61 @@ wins_get_config (void)
}
/* draw panel border in color */
static void
border_color (WINDOW *window)
static void border_color(WINDOW * window)
{
int color_attr = A_BOLD;
int no_color_attr = A_BOLD;
if (colorize)
{
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);
}
/* draw panel border without any color */
static void
border_nocolor (WINDOW *window)
static void border_nocolor(WINDOW * window)
{
int color_attr = A_BOLD;
int no_color_attr = A_DIM;
if (colorize)
{
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);
}
void
wins_update_border (int flags)
{
if (flags & FLAG_CAL)
void wins_update_border(int flags)
{
if (flags & FLAG_CAL) {
if (slctd_win == CAL)
border_color(win[CAL].p);
else
border_nocolor(win[CAL].p);
}
if (flags & FLAG_APP)
{
if (flags & FLAG_APP) {
if (slctd_win == APP)
border_color(win[APP].p);
else
border_nocolor(win[APP].p);
}
if (flags & FLAG_TOD)
{
if (flags & FLAG_TOD) {
if (slctd_win == TOD)
border_color(win[TOD].p);
else
@ -550,8 +495,7 @@ wins_update_border (int flags)
}
}
void
wins_update_panels (int flags)
void wins_update_panels(int flags)
{
if (flags & FLAG_APP)
apoint_update_panel(slctd_win);
@ -565,8 +509,7 @@ wins_update_panels (int flags)
* Update all of the three windows and put a border around the
* selected window.
*/
void
wins_update (int flags)
void wins_update(int flags)
{
wins_update_border(flags);
wins_update_panels(flags);
@ -579,8 +522,7 @@ wins_update (int flags)
}
/* Reset the screen, needed when resizing terminal for example. */
void
wins_reset (void)
void wins_reset(void)
{
endwin();
wins_refresh();
@ -590,8 +532,7 @@ wins_reset (void)
}
/* Prepare windows for the execution of an external command. */
void
wins_prepare_external (void)
void wins_prepare_external(void)
{
if (notify_bar())
notify_stop_main_thread();
@ -603,8 +544,7 @@ wins_prepare_external (void)
}
/* Restore windows when returning from an external command. */
void
wins_unprepare_external (void)
void wins_unprepare_external(void)
{
reset_prog_mode();
clearok(curscr, TRUE);
@ -619,8 +559,7 @@ wins_unprepare_external (void)
* While inside interactive mode, launch the external command cmd on the given
* file.
*/
void
wins_launch_external (const char *file, const char *cmd)
void wins_launch_external(const char *file, const char *cmd)
{
const char *arg[] = { cmd, file, NULL };
int pid;
@ -643,8 +582,7 @@ static unsigned status_page;
* table, and update the NB_CAL_CMDS, NB_APP_CMDS or NB_TOD_CMDS defines,
* depending on which panel the added keybind is assigned to.
*/
void
wins_status_bar (void)
void wins_status_bar(void)
{
struct binding help = { _("Help"), KEY_GENERIC_HELP };
struct binding quit = { _("Quit"), KEY_GENERIC_QUIT };
@ -708,8 +646,7 @@ wins_status_bar (void)
struct binding **bindings;
int bindings_size;
switch (active_panel)
{
switch (active_panel) {
case CAL:
bindings = bindings_cal;
bindings_size = sizeof(bindings_cal) / sizeof(bindings_cal[0]);
@ -733,20 +670,17 @@ wins_status_bar (void)
}
/* Erase status bar. */
void
wins_erase_status_bar (void)
void wins_erase_status_bar(void)
{
erase_window_part(win[STA].p, 0, 0, col, STATUSHEIGHT);
}
/* Update the status bar page number to display other commands. */
void
wins_other_status_page (int panel)
void wins_other_status_page(int panel)
{
int nb_item, max_page;
switch (panel)
{
switch (panel) {
case CAL:
nb_item = NB_CAL_CMDS;
break;
@ -765,8 +699,7 @@ wins_other_status_page (int panel)
}
/* Reset the status bar page. */
void
wins_reset_status_page (void)
void wins_reset_status_page(void)
{
status_page = 1;
}

View File

@ -60,18 +60,15 @@ fork_exec (int *pfdin, int *pfdout, const char *path, char *const *arg)
if (pfdout && (pipe(pout) == -1))
return 0;
if ((pid = fork ()) == 0)
{
if (pfdout)
{
if ((pid = fork()) == 0) {
if (pfdout) {
if (dup2(pout[0], STDIN_FILENO) < 0)
_exit(127);
close(pout[0]);
close(pout[1]);
}
if (pfdin)
{
if (pfdin) {
if (dup2(pin[1], STDOUT_FILENO) < 0)
_exit(127);
close(pin[0]);
@ -80,29 +77,22 @@ fork_exec (int *pfdin, int *pfdout, const char *path, char *const *arg)
execvp(path, arg);
_exit(127);
}
else
{
} else {
if (pfdin)
close(pin[1]);
if (pfdout)
close(pout[0]);
if (pid > 0)
{
if (pfdin)
{
if (pid > 0) {
if (pfdin) {
fcntl(pin[0], F_SETFD, FD_CLOEXEC);
*pfdin = pin[0];
}
if (pfdout)
{
if (pfdout) {
fcntl(pout[1], F_SETFD, FD_CLOEXEC);
*pfdout = pout[1];
}
}
else
{
} else {
if (pfdin)
close(pin[0]);
if (pfdout)
@ -114,8 +104,7 @@ fork_exec (int *pfdin, int *pfdout, const char *path, char *const *arg)
}
/* Wait for a child process to terminate. */
static int
child_wait (int *pfdin, int *pfdout, int pid)
static int child_wait(int *pfdin, int *pfdout, int pid)
{
int stat;
@ -129,8 +118,7 @@ child_wait (int *pfdin, int *pfdout, int pid)
}
/* Print error message and bail out. */
static void
die (const char *format, ...)
static void die(const char *format, ...)
{
va_list arg;
@ -143,15 +131,13 @@ die (const char *format, ...)
}
/* Print usage message. */
static void
usage (void)
static void usage(void)
{
printf("usage: run-test [-h|--help] <test>...\n");
}
/* Run test with a specific name. */
static int
run_test (const char *name, int expect_failure)
static int run_test(const char *name, int expect_failure)
{
char filename[BUFSIZ];
char *arg1[3], *arg2[3];
@ -163,8 +149,7 @@ run_test (const char *name, int expect_failure)
if (snprintf(filename, BUFSIZ, "./%s", name) >= BUFSIZ)
die("file name too long\n");
if (access (filename, F_OK) != 0)
{
if (access(filename, F_OK) != 0) {
if (snprintf(filename, BUFSIZ, "./%s.sh", name) >= BUFSIZ)
die("file name too long\n");
@ -191,10 +176,8 @@ run_test (const char *name, int expect_failure)
fpin1 = fdopen(pin1, "r");
fpin2 = fdopen(pin2, "r");
while (fgets (buf1, BUFSIZ, fpin1))
{
if (!fgets (buf2, BUFSIZ, fpin2) || strcmp (buf1, buf2) != 0)
{
while (fgets(buf1, BUFSIZ, fpin1)) {
if (!fgets(buf2, BUFSIZ, fpin2) || strcmp(buf1, buf2) != 0) {
ret = 0;
break;
}
@ -221,28 +204,22 @@ run_test (const char *name, int expect_failure)
return ret;
}
int
main (int argc, char **argv)
int main(int argc, char **argv)
{
int i;
if (!argv[1])
die("no tests specified, bailing out\n");
else if (strcmp (argv[1], "-h") == 0 || strcmp (argv[1], "--help") == 0)
{
else if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) {
usage();
return 0;
}
for (i = 1; i < argc; i++)
{
if (*argv[i] == '!')
{
for (i = 1; i < argc; i++) {
if (*argv[i] == '!') {
if (!run_test(argv[i] + 1, 1))
return 1;
}
else
{
} else {
if (!run_test(argv[i], 0))
return 1;
}