aboutsummaryrefslogtreecommitdiffstats
path: root/src/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/io.c')
-rw-r--r--src/io.c650
1 files changed, 335 insertions, 315 deletions
diff --git a/src/io.c b/src/io.c
index 22f8719..7b54632 100644
--- a/src/io.c
+++ b/src/io.c
@@ -45,6 +45,7 @@
#include <errno.h>
#include "calcurse.h"
+#include "sha1.h"
#define ICALDATEFMT "%Y%m%d"
#define ICALDATETIMEFMT "%Y%m%dT%H%M%S"
@@ -136,7 +137,6 @@ static char *ical_recur_type[RECUR_TYPES] =
static void
progress_bar (progress_bar_t type, int progress)
{
-#define SLEEPTIME 125000
#define NBFILES 4
#define NBEXPORTED 3
#define LABELENGTH 15
@@ -194,8 +194,6 @@ progress_bar (progress_bar_t type, int progress)
custom_remove_attr (win[STA].p, ATTR_HIGHEST);
wmove (win[STA].p, 0, 0);
wins_wrefresh (win[STA].p);
- (void)usleep (SLEEPTIME);
-#undef SLEEPTIME
#undef NBFILES
#undef NBEXPORTED
#undef LABELENGTH
@@ -217,11 +215,10 @@ get_export_stream (enum export_type type)
stream = NULL;
stream_name = (char *) mem_malloc (BUFSIZ);
if ((home = getenv ("HOME")) != NULL)
- (void)snprintf (stream_name, BUFSIZ, "%s/calcurse.%s", home,
- file_ext[type]);
+ snprintf (stream_name, BUFSIZ, "%s/calcurse.%s", home, file_ext[type]);
else
- (void)snprintf (stream_name, BUFSIZ, "%s/calcurse.%s", get_tempdir (),
- file_ext[type]);
+ snprintf (stream_name, BUFSIZ, "%s/calcurse.%s", get_tempdir (),
+ file_ext[type]);
while (stream == NULL)
{
@@ -230,18 +227,18 @@ get_export_stream (enum export_type type)
if (cancel)
{
mem_free (stream_name);
- return (NULL);
+ return NULL;
}
stream = fopen (stream_name, "w");
if (stream == NULL)
{
status_mesg (wrong_name, press_enter);
- (void)wgetch (win[STA].p);
+ wgetch (win[STA].p);
}
}
mem_free (stream_name);
- return (stream);
+ return stream;
}
/*
@@ -266,8 +263,8 @@ foreach_date_dump (const long date_end, struct rpt *rpt, llist_t *exc,
while (date <= date_end && date <= rpt->until)
{
- if (recur_item_inday (item_first_date, exc, rpt->type, rpt->freq,
- rpt->until, date))
+ if (recur_item_inday (item_first_date, item_dur, exc, rpt->type,
+ rpt->freq, rpt->until, date))
{
(*cb_dump)(stream, date + item_time, item_dur, item_mesg);
}
@@ -297,41 +294,40 @@ foreach_date_dump (const long date_end, struct rpt *rpt, llist_t *exc,
static void
ical_export_valarm (FILE *stream)
{
- (void)fprintf (stream, "BEGIN:VALARM\n");
+ fputs ("BEGIN:VALARM\n", stream);
pthread_mutex_lock (&nbar.mutex);
- (void)fprintf (stream, "TRIGGER:-P%dS\n", nbar.cntdwn);
+ fprintf (stream, "TRIGGER:-P%dS\n", nbar.cntdwn);
pthread_mutex_unlock (&nbar.mutex);
- (void)fprintf (stream, "ACTION:DISPLAY\n");
- (void)fprintf (stream, "END:VALARM\n");
+ fputs ("ACTION:DISPLAY\n", stream);
+ fputs ("END:VALARM\n", stream);
}
/* Export header. */
static void
ical_export_header (FILE *stream)
{
- (void)fprintf (stream, "BEGIN:VCALENDAR\n");
- (void)fprintf (stream, "PRODID:-//calcurse//NONSGML v%s//EN\n", VERSION);
- (void)fprintf (stream, "VERSION:2.0\n");
+ fputs ("BEGIN:VCALENDAR\n", stream);
+ fprintf (stream, "PRODID:-//calcurse//NONSGML v%s//EN\n", VERSION);
+ fputs ("VERSION:2.0\n", stream);
}
static void
pcal_export_header (FILE *stream)
{
- (void)fprintf (stream, "# calcurse pcal export\n");
- (void)fprintf (stream, "\n# =======\n# options\n# =======\n");
- (void)fprintf (stream, "opt -A -K -l -m -F %s\n",
- calendar_week_begins_on_monday () ?
- "Monday" : "Sunday");
- (void)fprintf (stream, "# Display week number (i.e. 1-52) on every Monday\n");
- (void)fprintf (stream, "all monday in all %s %%w\n", _("Week"));
- (void)fprintf (stream, "\n");
+ fputs ("# calcurse pcal export\n", stream);
+ fputs ("\n# =======\n# options\n# =======\n", stream);
+ fprintf (stream, "opt -A -K -l -m -F %s\n",
+ calendar_week_begins_on_monday () ? "Monday" : "Sunday");
+ fputs ("# Display week number (i.e. 1-52) on every Monday\n", stream);
+ fprintf (stream, "all monday in all %s %%w\n", _("Week"));
+ fputc ('\n', stream);
}
/* Export footer. */
static void
ical_export_footer (FILE *stream)
{
- (void)fprintf (stream, "END:VCALENDAR\n");
+ fputs ("END:VCALENDAR\n", stream);
}
static void
@@ -350,36 +346,36 @@ ical_export_recur_events (FILE *stream)
{
struct recur_event *rev = LLIST_GET_DATA (i);
date_sec2date_fmt (rev->day, ICALDATEFMT, ical_date);
- (void)fprintf (stream, "BEGIN:VEVENT\n");
- (void)fprintf (stream, "DTSTART:%s\n", ical_date);
- (void)fprintf (stream, "RRULE:FREQ=%s;INTERVAL=%d",
- ical_recur_type[rev->rpt->type], rev->rpt->freq);
+ fputs ("BEGIN:VEVENT\n", stream);
+ fprintf (stream, "DTSTART:%s\n", ical_date);
+ fprintf (stream, "RRULE:FREQ=%s;INTERVAL=%d",
+ ical_recur_type[rev->rpt->type], rev->rpt->freq);
if (rev->rpt->until != 0)
{
date_sec2date_fmt (rev->rpt->until, ICALDATEFMT, ical_date);
- (void)fprintf (stream, ";UNTIL=%s\n", ical_date);
+ fprintf (stream, ";UNTIL=%s\n", ical_date);
}
else
- (void)fprintf (stream, "\n");
+ fputc ('\n', stream);
if (LLIST_FIRST (&rev->exc))
{
- (void)fprintf (stream, "EXDATE:");
+ fputs ("EXDATE:", stream);
LLIST_FOREACH (&rev->exc, j)
{
struct excp *exc = LLIST_GET_DATA (j);
date_sec2date_fmt (exc->st, ICALDATEFMT, ical_date);
- (void)fprintf (stream, "%s", ical_date);
+ fprintf (stream, "%s", ical_date);
if (LLIST_NEXT (j))
- (void)fprintf (stream, ",");
+ fputc (',', stream);
else
- (void)fprintf (stream, "\n");
+ fputc ('\n', stream);
}
}
- (void)fprintf (stream, "SUMMARY:%s\n", rev->mesg);
- (void)fprintf (stream, "END:VEVENT\n");
+ fprintf (stream, "SUMMARY:%s\n", rev->mesg);
+ fputs ("END:VEVENT\n", stream);
}
}
@@ -391,7 +387,7 @@ pcal_dump_event (FILE *stream, long event_date, long event_dur,
char pcal_date[BUFSIZ];
date_sec2date_fmt (event_date, "%b %d", pcal_date);
- (void)fprintf (stream, "%s %s\n", pcal_date, event_mesg);
+ fprintf (stream, "%s %s\n", pcal_date, event_mesg);
}
/* Format and dump appointment data to a pcal formatted file. */
@@ -404,8 +400,8 @@ pcal_dump_apoint (FILE *stream, long apoint_date, long apoint_dur,
date_sec2date_fmt (apoint_date, "%b %d", pcal_date);
date_sec2date_fmt (apoint_date, "%R", pcal_beg);
date_sec2date_fmt (apoint_date + apoint_dur, "%R", pcal_end);
- (void)fprintf (stream, "%s ", pcal_date);
- (void)fprintf (stream, "(%s -> %s) %s\n", pcal_beg, pcal_end, apoint_mesg);
+ fprintf (stream, "%s ", pcal_date);
+ fprintf (stream, "(%s -> %s) %s\n", pcal_beg, pcal_end, apoint_mesg);
}
static void
@@ -414,11 +410,10 @@ pcal_export_recur_events (FILE *stream)
llist_item_t *i;
char pcal_date[BUFSIZ];
- (void)fprintf (stream, "\n# =============");
- (void)fprintf (stream, "\n# Recur. Events");
- (void)fprintf (stream, "\n# =============\n");
- (void)fprintf (stream,
- "# (pcal does not support from..until dates specification\n");
+ fputs ("\n# =============", stream);
+ fputs ("\n# Recur. Events", stream);
+ fputs ("\n# =============\n", stream);
+ fputs ("# (pcal does not support from..until dates specification\n", stream);
LLIST_FOREACH (&recur_elist, i)
{
@@ -429,23 +424,22 @@ pcal_export_recur_events (FILE *stream)
{
case RECUR_DAILY:
date_sec2date_fmt (rev->day, "%b %d", pcal_date);
- (void)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);
- (void)fprintf (stream, "all %s on_or_after ", pcal_date);
+ fprintf (stream, "all %s on_or_after ", pcal_date);
date_sec2date_fmt (rev->day, "%b %d", pcal_date);
- (void)fprintf (stream, "%s %s\n", pcal_date, rev->mesg);
+ fprintf (stream, "%s %s\n", pcal_date, rev->mesg);
break;
case RECUR_MONTHLY:
date_sec2date_fmt (rev->day, "%d", pcal_date);
- (void)fprintf (stream, "day on all %s %s\n", pcal_date,
- rev->mesg);
+ fprintf (stream, "day on all %s %s\n", pcal_date, rev->mesg);
break;
case RECUR_YEARLY:
date_sec2date_fmt (rev->day, "%b %d", pcal_date);
- (void)fprintf (stream, "%s %s\n", pcal_date, rev->mesg);
+ fprintf (stream, "%s %s\n", pcal_date, rev->mesg);
break;
default:
EXIT (_("incoherent repetition type"));
@@ -474,10 +468,10 @@ ical_export_events (FILE *stream)
{
struct event *ev = LLIST_TS_GET_DATA (i);
date_sec2date_fmt (ev->day, ICALDATEFMT, ical_date);
- (void)fprintf (stream, "BEGIN:VEVENT\n");
- (void)fprintf (stream, "DTSTART:%s\n", ical_date);
- (void)fprintf (stream, "SUMMARY:%s\n", ev->mesg);
- (void)fprintf (stream, "END:VEVENT\n");
+ fputs ("BEGIN:VEVENT\n", stream);
+ fprintf (stream, "DTSTART:%s\n", ical_date);
+ fprintf (stream, "SUMMARY:%s\n", ev->mesg);
+ fputs ("END:VEVENT\n", stream);
}
}
@@ -486,13 +480,13 @@ pcal_export_events (FILE *stream)
{
llist_item_t *i;
- (void)fprintf (stream, "\n# ======\n# Events\n# ======\n");
+ fputs ("\n# ======\n# Events\n# ======\n", stream);
LLIST_FOREACH (&eventlist, i)
{
struct event *ev = LLIST_TS_GET_DATA (i);
pcal_dump_event (stream, ev->day, 0, ev->mesg);
}
- (void)fprintf (stream, "\n");
+ fputc ('\n', stream);
}
/* Export recurrent appointments. */
@@ -509,40 +503,40 @@ ical_export_recur_apoints (FILE *stream)
struct recur_apoint *rapt = LLIST_TS_GET_DATA (i);
date_sec2date_fmt (rapt->start, ICALDATETIMEFMT, ical_datetime);
- (void)fprintf (stream, "BEGIN:VEVENT\n");
- (void)fprintf (stream, "DTSTART:%s\n", ical_datetime);
- (void)fprintf (stream, "DURATION:PT0H0M%ldS\n", rapt->dur);
- (void)fprintf (stream, "RRULE:FREQ=%s;INTERVAL=%d",
- ical_recur_type[rapt->rpt->type], rapt->rpt->freq);
+ fputs ("BEGIN:VEVENT\n", stream);
+ fprintf (stream, "DTSTART:%s\n", ical_datetime);
+ fprintf (stream, "DURATION:PT0H0M%ldS\n", rapt->dur);
+ 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);
- (void)fprintf (stream, ";UNTIL=%s\n", ical_date);
+ fprintf (stream, ";UNTIL=%s\n", ical_date);
}
else
- (void)fprintf (stream, "\n");
+ fputc ('\n', stream);
if (LLIST_FIRST (&rapt->exc))
{
- (void)fprintf (stream, "EXDATE:");
+ fputs ("EXDATE:", stream);
LLIST_FOREACH (&rapt->exc, j)
{
struct excp *exc = LLIST_GET_DATA (j);
date_sec2date_fmt (exc->st, ICALDATEFMT, ical_date);
- (void)fprintf (stream, "%s", ical_date);
+ fprintf (stream, "%s", ical_date);
if (LLIST_NEXT (j))
- (void)fprintf (stream, ",");
+ fputc (',', stream);
else
- (void)fprintf (stream, "\n");
+ fputc ('\n', stream);
}
}
- (void)fprintf (stream, "SUMMARY:%s\n", rapt->mesg);
+ fprintf (stream, "SUMMARY:%s\n", rapt->mesg);
if (rapt->state & APOINT_NOTIFY)
ical_export_valarm (stream);
- (void)fprintf (stream, "END:VEVENT\n");
+ fputs ("END:VEVENT\n", stream);
}
LLIST_TS_UNLOCK (&recur_alist_p);
}
@@ -553,11 +547,10 @@ pcal_export_recur_apoints (FILE *stream)
llist_item_t *i;
char pcal_date[BUFSIZ], pcal_beg[BUFSIZ], pcal_end[BUFSIZ];
- (void)fprintf (stream, "\n# ==============");
- (void)fprintf (stream, "\n# Recur. Apoints");
- (void)fprintf (stream, "\n# ==============\n");
- (void)fprintf (stream,
- "# (pcal does not support from..until dates specification\n");
+ fputs ("\n# ==============", stream);
+ fputs ("\n# Recur. Apoints", stream);
+ fputs ("\n# ==============\n", stream);
+ fputs ("# (pcal does not support from..until dates specification\n", stream);
LLIST_TS_FOREACH (&recur_alist_p, i)
{
@@ -571,25 +564,25 @@ pcal_export_recur_apoints (FILE *stream)
{
case RECUR_DAILY:
date_sec2date_fmt (rapt->start, "%b %d", pcal_date);
- (void)fprintf (stream, "all day on_or_after %s (%s -> %s) %s\n",
- pcal_date, pcal_beg, pcal_end, rapt->mesg);
+ fprintf (stream, "all day on_or_after %s (%s -> %s) %s\n",
+ pcal_date, pcal_beg, pcal_end, rapt->mesg);
break;
case RECUR_WEEKLY:
date_sec2date_fmt (rapt->start, "%a", pcal_date);
- (void)fprintf (stream, "all %s on_or_after ", pcal_date);
+ fprintf (stream, "all %s on_or_after ", pcal_date);
date_sec2date_fmt (rapt->start, "%b %d", pcal_date);
- (void)fprintf (stream, "%s (%s -> %s) %s\n", pcal_date,
- pcal_beg, pcal_end, rapt->mesg);
+ fprintf (stream, "%s (%s -> %s) %s\n", pcal_date, pcal_beg,
+ pcal_end, rapt->mesg);
break;
case RECUR_MONTHLY:
date_sec2date_fmt (rapt->start, "%d", pcal_date);
- (void)fprintf (stream, "day on all %s (%s -> %s) %s\n",
- pcal_date, pcal_beg, pcal_end, rapt->mesg);
+ fprintf (stream, "day on all %s (%s -> %s) %s\n", pcal_date,
+ pcal_beg, pcal_end, rapt->mesg);
break;
case RECUR_YEARLY:
date_sec2date_fmt (rapt->start, "%b %d", pcal_date);
- (void)fprintf (stream, "%s (%s -> %s) %s\n", pcal_date,
- pcal_beg, pcal_end, rapt->mesg);
+ fprintf (stream, "%s (%s -> %s) %s\n", pcal_date, pcal_beg,
+ pcal_end, rapt->mesg);
break;
default:
EXIT (_("incoherent repetition type"));
@@ -620,13 +613,13 @@ ical_export_apoints (FILE *stream)
{
struct apoint *apt = LLIST_TS_GET_DATA (i);
date_sec2date_fmt (apt->start, ICALDATETIMEFMT, ical_datetime);
- (void)fprintf (stream, "BEGIN:VEVENT\n");
- (void)fprintf (stream, "DTSTART:%s\n", ical_datetime);
- (void)fprintf (stream, "DURATION:PT0H0M%ldS\n", apt->dur);
- (void)fprintf (stream, "SUMMARY:%s\n", apt->mesg);
+ fputs ("BEGIN:VEVENT\n", stream);
+ fprintf (stream, "DTSTART:%s\n", ical_datetime);
+ fprintf (stream, "DURATION:PT0H0M%ldS\n", apt->dur);
+ fprintf (stream, "SUMMARY:%s\n", apt->mesg);
if (apt->state & APOINT_NOTIFY)
ical_export_valarm (stream);
- (void)fprintf (stream, "END:VEVENT\n");
+ fputs ("END:VEVENT\n", stream);
}
LLIST_TS_UNLOCK (&alist_p);
}
@@ -636,7 +629,7 @@ pcal_export_apoints (FILE *stream)
{
llist_item_t *i;
- (void)fprintf (stream, "\n# ============\n# Appointments\n# ============\n");
+ fputs ("\n# ============\n# Appointments\n# ============\n", stream);
LLIST_TS_LOCK (&alist_p);
LLIST_TS_FOREACH (&alist_p, i)
{
@@ -644,7 +637,7 @@ pcal_export_apoints (FILE *stream)
pcal_dump_apoint (stream, apt->start, apt->dur, apt->mesg);
}
LLIST_TS_UNLOCK (&alist_p);
- (void)fprintf (stream, "\n");
+ fputc ('\n', stream);
}
/* Export todo items. */
@@ -659,10 +652,10 @@ ical_export_todo (FILE *stream)
if (todo->id < 0) /* completed items */
continue;
- (void)fprintf (stream, "BEGIN:VTODO\n");
- (void)fprintf (stream, "PRIORITY:%d\n", todo->id);
- (void)fprintf (stream, "SUMMARY:%s\n", todo->mesg);
- (void)fprintf (stream, "END:VTODO\n");
+ fputs ("BEGIN:VTODO\n", stream);
+ fprintf (stream, "PRIORITY:%d\n", todo->id);
+ fprintf (stream, "SUMMARY:%s\n", todo->mesg);
+ fputs ("END:VTODO\n", stream);
}
}
@@ -671,17 +664,17 @@ pcal_export_todo (FILE *stream)
{
llist_item_t *i;
- (void)fprintf (stream, "#\n# Todos\n#\n");
+ fputs ("#\n# Todos\n#\n", stream);
LLIST_FOREACH (&todolist, i)
{
struct todo *todo = LLIST_TS_GET_DATA (i);
if (todo->id < 0) /* completed items */
continue;
- (void)fprintf (stream, "note all ");
- (void)fprintf (stream, "%d. %s\n", todo->id, todo->mesg);
+ fputs ("note all ", stream);
+ fprintf (stream, "%d. %s\n", todo->id, todo->mesg);
}
- (void)fprintf (stream, "\n");
+ fputc ('\n', stream);
}
/* Append a line to a file. */
@@ -730,15 +723,15 @@ io_init (char *cfile, char *datadir)
if (datadir != NULL)
{
home = datadir;
- (void)snprintf (path_dir, BUFSIZ, "%s", home);
- (void)snprintf (path_todo, BUFSIZ, "%s/" TODO_PATH_NAME, home);
- (void)snprintf (path_conf, BUFSIZ, "%s/" CONF_PATH_NAME, home);
- (void)snprintf (path_notes, BUFSIZ, "%s/" NOTES_DIR_NAME, home);
- (void)snprintf (path_apts, BUFSIZ, "%s/" APTS_PATH_NAME, home);
- (void)snprintf (path_keys, BUFSIZ, "%s/" KEYS_PATH_NAME, home);
- (void)snprintf (path_cpid, BUFSIZ, "%s/" CPID_PATH_NAME, home);
- (void)snprintf (path_dpid, BUFSIZ, "%s/" DPID_PATH_NAME, home);
- (void)snprintf (path_dmon_log, BUFSIZ, "%s/" DLOG_PATH_NAME, home);
+ snprintf (path_dir, BUFSIZ, "%s", home);
+ snprintf (path_todo, BUFSIZ, "%s/" TODO_PATH_NAME, home);
+ snprintf (path_conf, BUFSIZ, "%s/" CONF_PATH_NAME, home);
+ snprintf (path_notes, BUFSIZ, "%s/" NOTES_DIR_NAME, home);
+ snprintf (path_apts, BUFSIZ, "%s/" APTS_PATH_NAME, home);
+ snprintf (path_keys, BUFSIZ, "%s/" KEYS_PATH_NAME, home);
+ snprintf (path_cpid, BUFSIZ, "%s/" CPID_PATH_NAME, home);
+ snprintf (path_dpid, BUFSIZ, "%s/" DPID_PATH_NAME, home);
+ snprintf (path_dmon_log, BUFSIZ, "%s/" DLOG_PATH_NAME, home);
}
else
{
@@ -747,22 +740,22 @@ io_init (char *cfile, char *datadir)
{
home = ".";
}
- (void)snprintf (path_dir, BUFSIZ, "%s/" DIR_NAME, home);
- (void)snprintf (path_todo, BUFSIZ, "%s/" TODO_PATH, home);
- (void)snprintf (path_conf, BUFSIZ, "%s/" CONF_PATH, home);
- (void)snprintf (path_keys, BUFSIZ, "%s/" KEYS_PATH, home);
- (void)snprintf (path_cpid, BUFSIZ, "%s/" CPID_PATH, home);
- (void)snprintf (path_dpid, BUFSIZ, "%s/" DPID_PATH, home);
- (void)snprintf (path_dmon_log, BUFSIZ, "%s/" DLOG_PATH, home);
- (void)snprintf (path_notes, BUFSIZ, "%s/" NOTES_DIR, home);
+ snprintf (path_dir, BUFSIZ, "%s/" DIR_NAME, home);
+ snprintf (path_todo, BUFSIZ, "%s/" TODO_PATH, home);
+ snprintf (path_conf, BUFSIZ, "%s/" CONF_PATH, home);
+ snprintf (path_keys, BUFSIZ, "%s/" KEYS_PATH, home);
+ snprintf (path_cpid, BUFSIZ, "%s/" CPID_PATH, home);
+ snprintf (path_dpid, BUFSIZ, "%s/" DPID_PATH, home);
+ snprintf (path_dmon_log, BUFSIZ, "%s/" DLOG_PATH, home);
+ snprintf (path_notes, BUFSIZ, "%s/" NOTES_DIR, home);
if (cfile == NULL)
{
- (void)snprintf (path_apts, BUFSIZ, "%s/" APTS_PATH, home);
+ snprintf (path_apts, BUFSIZ, "%s/" APTS_PATH, home);
}
else
{
- (void)snprintf (apts_file, BUFSIZ, "%s", cfile);
- (void)strncpy (path_apts, apts_file, BUFSIZ);
+ snprintf (apts_file, BUFSIZ, "%s", cfile);
+ strncpy (path_apts, apts_file, BUFSIZ);
/* check if the file exists, otherwise create it */
data_file = fopen (path_apts, "r");
if (data_file == NULL)
@@ -774,7 +767,7 @@ io_init (char *cfile, char *datadir)
{
case 'N':
case 'n':
- printf (_("aborting...\n"));
+ puts (_("aborting...\n"));
exit_calcurse (EXIT_FAILURE);
break;
@@ -789,12 +782,12 @@ io_init (char *cfile, char *datadir)
else
{
printf (_("%s successfully created\n"), path_apts);
- printf (_("starting interactive mode...\n"));
+ puts (_("starting interactive mode...\n"));
}
break;
default:
- printf (_("aborting...\n"));
+ puts (_("aborting...\n"));
exit_calcurse (EXIT_FAILURE);
break;
}
@@ -809,9 +802,10 @@ io_extract_data (char *dst_data, const char *org, int len)
{
int i;
+ for (; *org == ' ' || *org == '\t'; org++);
for (i = 0; i < len - 1; i++)
{
- if (*org == '\n' || *org == '\0')
+ if (*org == '\n' || *org == '\0' || *org == '#')
break;
*dst_data++ = *org++;
}
@@ -849,8 +843,9 @@ io_save_conf (struct conf *conf)
"# options are usually set from within Calcurse. A line beginning with \n"
"# a space or tab is considered to be a continuation of the previous "
"line.\n"
- "# For a variable to be unset its value must be blank.\n"
- "# To set a variable to the empty string its value should be \"\".\n"
+ "# For a variable to be unset its value must be blank, followed by an\n"
+ "# empty line. To set a variable to the empty string its value should be "
+ "\"\".\n"
"# Lines beginning with \"#\" are comments, and ignored by Calcurse.\n";
char theme_name[BUFSIZ];
FILE *fp;
@@ -860,115 +855,118 @@ io_save_conf (struct conf *conf)
custom_color_theme_name (theme_name);
- (void)fprintf (fp, "%s\n", config_txt);
-
- (void)fprintf (fp, "# If this option is set to yes, "
- "automatic save is done when quitting\n");
- (void)fprintf (fp, "auto_save=\n");
- (void)fprintf (fp, "%s\n", (conf->auto_save) ? "yes" : "no");
-
- (void)fprintf (fp, "\n# If not null, perform automatic saves every "
- "'periodic_save' minutes\n");
- (void)fprintf (fp, "periodic_save=\n");
- (void)fprintf (fp, "%d\n", conf->periodic_save);
-
- (void)fprintf (fp, "\n# If this option is set to yes, "
- "confirmation is required before quitting\n");
- (void)fprintf (fp, "confirm_quit=\n");
- (void)fprintf (fp, "%s\n", (conf->confirm_quit) ? "yes" : "no");
-
- (void)fprintf (fp, "\n# If this option is set to yes, "
- "confirmation is required before deleting an event\n");
- (void)fprintf (fp, "confirm_delete=\n");
- (void)fprintf (fp, "%s\n", (conf->confirm_delete) ? "yes" : "no");
-
- (void)fprintf (fp, "\n# If this option is set to yes, "
- "messages about loaded and saved data will not be displayed\n");
- (void)fprintf (fp, "skip_system_dialogs=\n");
- (void)fprintf (fp, "%s\n", (conf->skip_system_dialogs) ? "yes" : "no");
-
- (void)fprintf (fp,
- "\n# If this option is set to yes, progress bar appearing "
- "when saving data will not be displayed\n");
- (void)fprintf (fp, "skip_progress_bar=\n");
- (void)fprintf (fp, "%s\n", (conf->skip_progress_bar) ? "yes" : "no");
-
- (void)fprintf (fp, "\n# Default calendar view (0)monthly (1)weekly:\n");
- (void)fprintf (fp, "calendar_default_view=\n");
- (void)fprintf (fp, "%d\n", calendar_get_view ());
-
- (void)fprintf (fp, "\n# If this option is set to yes, "
- "monday is the first day of the week, else it is sunday\n");
- (void)fprintf (fp, "week_begins_on_monday=\n");
- (void)fprintf (fp, "%s\n",
- (calendar_week_begins_on_monday ())? "yes" : "no");
-
- (void)fprintf (fp, "\n# This is the color theme used for menus :\n");
- (void)fprintf (fp, "color-theme=\n");
- (void)fprintf (fp, "%s\n", theme_name);
-
- (void)fprintf (fp, "\n# This is the layout of the calendar :\n");
- (void)fprintf (fp, "layout=\n");
- (void)fprintf (fp, "%d\n", wins_layout ());
-
- (void)fprintf (fp, "\n# Width (in percentage, 0 being minimun width) "
- "of the side bar :\n");
- (void)fprintf (fp, "side-bar_width=\n");
- (void)fprintf (fp, "%d\n", wins_sbar_wperc ());
+ fprintf (fp, "%s\n", config_txt);
+
+ fputs ("# If this option is set to yes, "
+ "automatic save is done when quitting\n", fp);
+ fputs ("auto_save=", fp);
+ fprintf (fp, "%s\n", (conf->auto_save) ? "yes" : "no");
+
+ fputs ("\n# If this option is set to yes, "
+ "the GC is run automatically when quitting\n", fp);
+ fputs ("auto_gc=", fp);
+ fprintf (fp, "%s\n", (conf->auto_gc) ? "yes" : "no");
+
+ fputs ("\n# If not null, perform automatic saves every "
+ "'periodic_save' minutes\n", fp);
+ fputs ("periodic_save=", fp);
+ fprintf (fp, "%d\n", conf->periodic_save);
+
+ fputs ("\n# If this option is set to yes, "
+ "confirmation is required before quitting\n", fp);
+ fputs ("confirm_quit=", fp);
+ fprintf (fp, "%s\n", (conf->confirm_quit) ? "yes" : "no");
+
+ fputs ("\n# If this option is set to yes, "
+ "confirmation is required before deleting an event\n", fp);
+ fputs ("confirm_delete=", fp);
+ fprintf (fp, "%s\n", (conf->confirm_delete) ? "yes" : "no");
+
+ fputs ("\n# If this option is set to yes, messages about loaded and "
+ "saved data will not be displayed\n", fp);
+ fputs ("skip_system_dialogs=", fp);
+ fprintf (fp, "%s\n", (conf->skip_system_dialogs) ? "yes" : "no");
+
+ fputs ("\n# If this option is set to yes, progress bar appearing "
+ "when saving data will not be displayed\n", fp);
+ fputs ("skip_progress_bar=", fp);
+ fprintf (fp, "%s\n", (conf->skip_progress_bar) ? "yes" : "no");
+
+ fputs ("\n# Default calendar view (0)monthly (1)weekly:\n", fp);
+ fputs ("calendar_default_view=", fp);
+ fprintf (fp, "%d\n", calendar_get_view ());
+
+ fputs ("\n# If this option is set to yes, "
+ "monday is the first day of the week, else it is sunday\n", fp);
+ fputs ("week_begins_on_monday=", fp);
+ fprintf (fp, "%s\n", (calendar_week_begins_on_monday ())? "yes" : "no");
+
+ fputs ("\n# This is the color theme used for menus :\n", fp);
+ fputs ("color-theme=", fp);
+ fprintf (fp, "%s\n", theme_name);
+
+ fputs ("\n# This is the layout of the calendar :\n", fp);
+ fputs ("layout=", fp);
+ fprintf (fp, "%d\n", wins_layout ());
+
+ fputs ("\n# Width ( percentage, 0 being minimun width, fp) "
+ "of the side bar :\n", fp);
+ fputs ("side-bar_width=", fp);
+ fprintf (fp, "%d\n", wins_sbar_wperc ());
if (ui_mode == UI_CURSES)
pthread_mutex_lock (&nbar.mutex);
- (void)fprintf (fp,
- "\n# If this option is set to yes, "
- "notify-bar will be displayed :\n");
- (void)fprintf (fp, "notify-bar_show=\n");
- (void)fprintf (fp, "%s\n", (nbar.show) ? "yes" : "no");
-
- (void)fprintf (fp,
- "\n# Format of the date to be displayed inside notify-bar :\n");
- (void)fprintf (fp, "notify-bar_date=\n");
- (void)fprintf (fp, "%s\n", nbar.datefmt);
-
- (void)fprintf (fp,
- "\n# Format of the time to be displayed inside notify-bar :\n");
- (void)fprintf (fp, "notify-bar_clock=\n");
- (void)fprintf (fp, "%s\n", nbar.timefmt);
-
- (void)fprintf (fp,
- "\n# Warn user if he has an appointment within next "
- "'notify-bar_warning' seconds :\n");
- (void)fprintf (fp, "notify-bar_warning=\n");
- (void)fprintf (fp, "%d\n", nbar.cntdwn);
-
- (void)fprintf (fp, "\n# Command used to notify user of "
- "an upcoming appointment :\n");
- (void)fprintf (fp, "notify-bar_command=\n");
- (void)fprintf (fp, "%s\n", nbar.cmd);
-
- (void)fprintf (fp, "\n# Format of the date to be displayed "
- "in non-interactive mode :\n");
- (void)fprintf (fp, "output_datefmt=\n");
- (void)fprintf (fp, "%s\n", conf->output_datefmt);
-
- (void)fprintf (fp, "\n# Format to be used when entering a date "
- "(1)mm/dd/yyyy (2)dd/mm/yyyy (3)yyyy/mm/dd) "
- "(4)yyyy-mm-dd:\n");
- (void)fprintf (fp, "input_datefmt=\n");
- (void)fprintf (fp, "%d\n", conf->input_datefmt);
+ fputs ("\n# If this option is set to yes, "
+ "notify-bar will be displayed :\n", fp);
+ fputs ("notify-bar_show=", fp);
+ fprintf (fp, "%s\n", (nbar.show) ? "yes" : "no");
+
+ fputs ("\n# Format of the date to be displayed inside notify-bar :\n", fp);
+ fputs ("notify-bar_date=", fp);
+ fprintf (fp, "%s\n", nbar.datefmt);
+
+ fputs ("\n# Format of the time to be displayed inside notify-bar :\n", fp);
+ fputs ("notify-bar_clock=", fp);
+ fprintf (fp, "%s\n", nbar.timefmt);
+
+ fputs ("\n# Warn user if he has an appointment within next "
+ "'notify-bar_warning' seconds :\n", fp);
+ fputs ("notify-bar_warning=", fp);
+ fprintf (fp, "%d\n", nbar.cntdwn);
+
+ fputs ("\n# Command used to notify user of "
+ "an upcoming appointment :\n", fp);
+ fputs ("notify-bar_command=", fp);
+ fprintf (fp, "%s\n", nbar.cmd);
+
+ fputs ("\n# Notify all appointments instead of flagged ones only\n", fp);
+ fputs ("notify-all=", fp);
+ fprintf (fp, "%s\n", (nbar.notify_all) ? "yes" : "no");
+
+ fputs ("\n# Format of the date to be displayed "
+ "in non-interactive mode :\n", fp);
+ fputs ("output_datefmt=", fp);
+ fprintf (fp, "%s\n", conf->output_datefmt);
+
+ fputs ("\n# Format to be used when entering a date "
+ "(1)mm/dd/yyyy (2)dd/mm/yyyy (3)yyyy/mm/dd) "
+ "(4)yyyy-mm-dd:\n", fp);
+ fputs ("input_datefmt=", fp);
+ fprintf (fp, "%d\n", conf->input_datefmt);
if (ui_mode == UI_CURSES)
pthread_mutex_unlock (&nbar.mutex);
- (void)fprintf (fp, "\n# If this option is set to yes, "
- "calcurse will run in background to get notifications "
- "after exiting\n");
- (void)fprintf (fp, "notify-daemon_enable=\n");
- (void)fprintf (fp, "%s\n", dmon.enable ? "yes" : "no");
+ fputs ("\n# If this option is set to yes, "
+ "calcurse will run in background to get notifications "
+ "after exiting\n", fp);
+ fputs ("notify-daemon_enable=", fp);
+ fprintf (fp, "%s\n", dmon.enable ? "yes" : "no");
- (void)fprintf (fp, "\n# If this option is set to yes, "
- "activity will be logged when running in background\n");
- (void)fprintf (fp, "notify-daemon_log=\n");
- (void)fprintf (fp, "%s\n", dmon.log ? "yes" : "no");
+ fputs ("\n# If this option is set to yes, "
+ "activity will be logged when running in background\n", fp);
+ fputs ("notify-daemon_log=", fp);
+ fprintf (fp, "%s\n", dmon.log ? "yes" : "no");
file_close (fp, __FILE_POS__);
@@ -1024,10 +1022,7 @@ io_save_todo (void)
LLIST_FOREACH (&todolist, i)
{
struct todo *todo = LLIST_TS_GET_DATA (i);
- if (todo->note)
- (void)fprintf (fp, "[%d]>%s %s\n", todo->id, todo->note, todo->mesg);
- else
- (void)fprintf (fp, "[%d] %s\n", todo->id, todo->mesg);
+ todo_write (todo, fp);
}
file_close (fp, __FILE_POS__);
@@ -1092,7 +1087,7 @@ io_save_cal (struct conf *conf, enum save_display display)
&& display != IO_SAVE_DISPLAY_MARK)
{
status_mesg (save_success, enter);
- (void)wgetch (win[STA].p);
+ wgetch (win[STA].p);
}
pthread_mutex_unlock (&io_save_mutex);
@@ -1114,7 +1109,7 @@ io_load_app (void)
int id = 0;
int freq;
char type, state = 0L;
- char note[NOTESIZ + 1], *notep;
+ char note[MAX_NOTESIZ + 1], *notep;
t = time (NULL);
lt = localtime (&t);
@@ -1128,7 +1123,7 @@ io_load_app (void)
c = getc (data_file);
if (c == EOF)
break;
- (void)ungetc (c, data_file);
+ ungetc (c, data_file);
/* Read the date first: it is common to both events
* and appointments.
@@ -1152,7 +1147,7 @@ io_load_app (void)
{
EXIT (_("no event nor appointment found"));
}
- (void)ungetc (c, data_file);
+ ungetc (c, data_file);
/* Read the remaining informations. */
if (is_appointment)
@@ -1177,38 +1172,38 @@ io_load_app (void)
if (c == '{')
{
- (void)ungetc (c, data_file);
+ ungetc (c, data_file);
is_recursive = 1;
fscanf (data_file, "{ %d%c ", &freq, &type);
c = getc (data_file);
if (c == '}')
{ /* endless recurrent item */
- (void)ungetc (c, data_file);
+ ungetc (c, data_file);
fscanf (data_file, "} ");
until.tm_year = 0;
}
else if (c == '-')
{
- (void)ungetc (c, data_file);
+ ungetc (c, data_file);
fscanf (data_file, " -> %u / %u / %u ",
&until.tm_mon, &until.tm_mday, &until.tm_year);
c = getc (data_file);
if (c == '!')
{
- (void)ungetc (c, data_file);
+ ungetc (c, data_file);
recur_exc_scan (&exc, data_file);
c = getc (data_file);
}
else
{
- (void)ungetc (c, data_file);
+ ungetc (c, data_file);
fscanf (data_file, "} ");
}
}
else if (c == '!')
{ // endless item with exceptions
- (void)ungetc (c, data_file);
+ ungetc (c, data_file);
recur_exc_scan (&exc, data_file);
c = getc (data_file);
until.tm_year = 0;
@@ -1220,21 +1215,19 @@ io_load_app (void)
}
}
else
- (void)ungetc (c, data_file);
+ ungetc (c, data_file);
/* Check if a note is attached to the item. */
c = getc (data_file);
if (c == '>')
{
- (void)fgets (note, NOTESIZ + 1, data_file);
- note[NOTESIZ] = '\0';
+ note_read (note, data_file);
notep = note;
- getc (data_file);
}
else
{
notep = NULL;
- (void)ungetc (c, data_file);
+ ungetc (c, data_file);
}
/*
@@ -1246,13 +1239,13 @@ io_load_app (void)
c = getc (data_file);
if (c == '!')
{
- (void)ungetc (c, data_file);
+ ungetc (c, data_file);
fscanf (data_file, " ! ");
state |= APOINT_NOTIFY;
}
else
{
- (void)ungetc (c, data_file);
+ ungetc (c, data_file);
fscanf (data_file, " | ");
state = 0L;
}
@@ -1297,13 +1290,13 @@ io_load_todo (void)
char *newline;
int nb_tod = 0;
int c, id;
- char buf[BUFSIZ], e_todo[BUFSIZ], note[NOTESIZ + 1];
+ char buf[BUFSIZ], e_todo[BUFSIZ], note[MAX_NOTESIZ + 1];
data_file = fopen (path_todo, "r");
if (data_file == NULL)
{
status_mesg (mesg_line1, mesg_line2);
- (void)wgetch (win[STA].p);
+ wgetch (win[STA].p);
}
for (;;)
{
@@ -1319,20 +1312,16 @@ io_load_todo (void)
else
{
id = 9;
- (void)ungetc (c, data_file);
+ ungetc (c, data_file);
}
/* Now read the attached note, if any. */
c = getc (data_file);
if (c == '>')
- {
- (void)fgets (note, NOTESIZ + 1, data_file);
- note[NOTESIZ] = '\0';
- getc (data_file);
- }
+ note_read (note, data_file);
else
note[0] = '\0';
/* Then read todo description. */
- (void)fgets (buf, sizeof buf, data_file);
+ fgets (buf, sizeof buf, data_file);
newline = strchr (buf, '\n');
if (newline)
*newline = '\0';
@@ -1526,8 +1515,8 @@ io_check_dir (char *dir, int *missing)
{
if (errno != EEXIST)
{
- (void)fprintf (stderr, _("FATAL ERROR: could not create %s: %s\n"),
- dir, strerror (errno));
+ fprintf (stderr, _("FATAL ERROR: could not create %s: %s\n"), dir,
+ strerror (errno));
exit_calcurse (EXIT_FAILURE);
}
}
@@ -1549,7 +1538,7 @@ io_file_exist (char *file)
if ((fd = fopen (file, "r")) == NULL)
return 0;
- (void)fclose (fd);
+ fclose (fd);
return 1;
}
@@ -1566,8 +1555,8 @@ io_check_file (char *file, int *missing)
(*missing)++;
if ((fd = fopen (file, "w")) == NULL)
{
- (void)fprintf (stderr, _("FATAL ERROR: could not create %s: %s\n"),
- file, strerror (errno));
+ fprintf (stderr, _("FATAL ERROR: could not create %s: %s\n"), file,
+ strerror (errno));
exit_calcurse (EXIT_FAILURE);
}
file_close (fd, __FILE_POS__);
@@ -1620,12 +1609,12 @@ io_startup_screen (unsigned skip_dialogs, int no_data_file)
if (no_data_file != 0)
{
status_mesg (welcome_mesg, enter);
- (void)wgetch (win[STA].p);
+ wgetch (win[STA].p);
}
else if (!skip_dialogs)
{
status_mesg (data_mesg, enter);
- (void)wgetch (win[STA].p);
+ wgetch (win[STA].p);
}
}
@@ -1681,7 +1670,7 @@ io_export_data (enum export_type type, struct conf *conf)
if (!conf->skip_system_dialogs && ui_mode == UI_CURSES)
{
status_mesg (success, enter);
- (void)wgetch (win[STA].p);
+ wgetch (win[STA].p);
}
}
@@ -1730,7 +1719,7 @@ ical_log_init (FILE *log, float version)
"+-------------------------------------------------------------------+\n\n";
if (log)
- (void)fprintf (log, header, version);
+ fprintf (log, header, version);
}
/*
@@ -1746,7 +1735,7 @@ ical_log (FILE *log, ical_types_e type, unsigned lineno, char *msg)
RETURN_IF (type < 0 || type >= ICAL_TYPES, _("unknown ical type"));
if (log)
- (void)fprintf (log, "%s [%d]: %s\n", typestr[type], lineno, msg);
+ fprintf (log, "%s [%d]: %s\n", typestr[type], lineno, msg);
}
static void
@@ -1754,7 +1743,7 @@ ical_store_todo (int priority, char *mesg, char *note)
{
todo_add (mesg, priority, note);
mem_free (mesg);
- erase_note (&note, ERASE_FORCE_KEEP_NOTE);
+ erase_note (&note);
}
static void
@@ -1786,7 +1775,7 @@ ical_store_event (char *mesg, char *note, long day, long end, ical_rpt_t *rpt,
event_new (mesg, note, day, EVENTID);
}
mem_free (mesg);
- erase_note (&note, ERASE_FORCE_KEEP_NOTE);
+ erase_note (&note);
}
static void
@@ -1808,7 +1797,7 @@ ical_store_apoint (char *mesg, char *note, long start, long dur,
apoint_new (mesg, note, start, dur, state);
}
mem_free (mesg);
- erase_note (&note, ERASE_FORCE_KEEP_NOTE);
+ erase_note (&note);
}
/*
@@ -2292,7 +2281,7 @@ ical_read_exdate (llist_t *exc, FILE *log, char *exstr, unsigned *noskipped,
char buf[BUFSIZ];
const int buflen = q - p;
- (void)strncpy (buf, p, buflen);
+ strncpy (buf, p, buflen);
buf[buflen] = '\0';
date = ical_datetime2long (buf, NULL);
ical_add_exc (exc, date);
@@ -2314,43 +2303,37 @@ static char *
ical_read_note (char *line, unsigned *noskipped, ical_vevent_e item_type,
const int itemline, FILE *log)
{
- char *p, *notestr, *notename, fullnotename[BUFSIZ];
+ char *sha1 = mem_malloc (SHA1_DIGESTLEN * 2 + 1);
+ char *p, *notestr, fullnotename[BUFSIZ];
FILE *fdo;
if ((p = strchr (line, ':')) != NULL)
{
- notename = new_tempfile (path_notes, NOTESIZ);
- EXIT_IF (notename == NULL,
- _("Warning: could not create new note file to store "
- "description. Aborting...\n"));
- (void)snprintf (fullnotename, BUFSIZ, "%s%s", path_notes, notename);
- fdo = fopen (fullnotename, "w");
- EXIT_IF (fdo == NULL, _("Warning: could not open %s, Aborting..."),
- fullnotename);
p++;
notestr = ical_unformat_line (p);
if (notestr == NULL)
{
ical_log (log, item_type, itemline,
_("could not get entire item description."));
- file_close (fdo, __FILE_POS__);
- erase_note (&notename, ERASE_FORCE);
(*noskipped)++;
return NULL;
}
else if (strlen (notestr) == 0)
{
- file_close (fdo, __FILE_POS__);
- erase_note (&notename, ERASE_FORCE);
mem_free (notestr);
return NULL;
}
else
{
- (void)fprintf (fdo, "%s", notestr);
+ sha1_digest (notestr, sha1);
+ snprintf (fullnotename, BUFSIZ, "%s%s", path_notes, sha1);
+ fdo = fopen (fullnotename, "w");
+ EXIT_IF (fdo == NULL, _("Warning: could not open %s, Aborting..."),
+ fullnotename);
+ fprintf (fdo, "%s", notestr);
file_close (fdo, __FILE_POS__);
mem_free (notestr);
- return notename;
+ return sha1;
}
}
else
@@ -2694,7 +2677,7 @@ get_import_stream (enum export_type type)
if (stream == NULL)
{
status_mesg (wrong_file, press_enter);
- (void)wgetch (win[STA].p);
+ wgetch (win[STA].p);
}
}
mem_free (stream_name);
@@ -2714,10 +2697,7 @@ io_import_data (enum import_type type, struct conf *conf, char *stream_name)
const struct string vevent = STRING_BUILD ("BEGIN:VEVENT");
const struct string vtodo = STRING_BUILD ("BEGIN:VTODO");
char *proc_report = _("Import process report: %04d lines read ");
- char *lines_stats =
- _("%d apps / %d events / %d todos / %d skipped ");
- char *lines_stats_interactive =
- _("%d apps / %d events / %d todos / %d skipped ([ENTER] to continue)");
+ char stats_str[4][BUFSIZ];
char buf[BUFSIZ], lstore[BUFSIZ];
FILE *stream = NULL;
struct io_file *log;
@@ -2780,6 +2760,14 @@ io_import_data (enum import_type type, struct conf *conf, char *stream_name)
if (stream != stdin)
file_close (stream, __FILE_POS__);
+ snprintf (stats_str[0], BUFSIZ,
+ ngettext ("%d app", "%d apps", stats.apoints), stats.apoints);
+ snprintf (stats_str[1], BUFSIZ,
+ ngettext ("%d event", "%d events", stats.events), stats.events);
+ snprintf (stats_str[2], BUFSIZ,
+ ngettext ("%d todo", "%d todos", stats.todos), stats.todos);
+ snprintf (stats_str[3], BUFSIZ, _("%d skipped"), stats.skipped);
+
/* Update the number of todo items. */
todo_set_nb (todo_nb () + stats.todos);
@@ -2787,19 +2775,18 @@ io_import_data (enum import_type type, struct conf *conf, char *stream_name)
{
char read[BUFSIZ], stat[BUFSIZ];
- (void)snprintf (read, BUFSIZ, proc_report, stats.lines);
- (void)snprintf (stat, BUFSIZ, lines_stats_interactive, stats.apoints,
- stats.events, stats.todos, stats.skipped);
+ snprintf (read, BUFSIZ, proc_report, stats.lines);
+ snprintf (stat, BUFSIZ, "%s / %s / %s / %s (%s)", stats_str[0],
+ stats_str[1], stats_str[2], stats_str[3],
+ _("Press [ENTER] to continue"));
status_mesg (read, stat);
- (void)wgetch (win[STA].p);
+ wgetch (win[STA].p);
}
else if (ui_mode == UI_CMDLINE)
{
printf (proc_report, stats.lines);
- printf ("\n");
- printf (lines_stats, stats.apoints, stats.events, stats.todos,
- stats.skipped);
- printf ("\n");
+ printf ("\n%s / %s / %s / %s\n", stats_str[0], stats_str[1],
+ stats_str[2], stats_str[3]);
}
/* User has the choice to look at the log file if some items could not be
@@ -2823,13 +2810,13 @@ io_log_init (void)
struct io_file *log;
snprintf (logprefix, BUFSIZ, "%s/calcurse_log.", get_tempdir ());
- logname = new_tempfile (logprefix, NOTESIZ);
+ logname = new_tempfile (logprefix, TMPEXTSIZ);
RETVAL_IF (logname == NULL, 0,
_("Warning: could not create temporary log file, Aborting..."));
log = mem_malloc (sizeof (struct io_file));
RETVAL_IF (log == NULL, 0,
_("Warning: could not open temporary log file, Aborting..."));
- (void)snprintf (log->name, sizeof (log->name), "%s%s", logprefix, logname);
+ snprintf (log->name, sizeof (log->name), "%s%s", logprefix, logname);
mem_free (logname);
log->fd = fopen (log->name, "w");
if (log->fd == NULL)
@@ -2846,7 +2833,7 @@ void
io_log_print (struct io_file *log, int line, char *msg)
{
if (log && log->fd)
- (void)fprintf (log->fd, "line %d: %s\n", line, msg);
+ fprintf (log->fd, "line %d: %s\n", line, msg);
}
void
@@ -2864,8 +2851,8 @@ io_log_display (struct io_file *log, char *msg, char *pager)
{
char cmd[BUFSIZ];
- (void)snprintf (cmd, BUFSIZ, "%s %s", pager, log->name);
- (void)system (cmd);
+ snprintf (cmd, BUFSIZ, "%s %s", pager, log->name);
+ system (cmd);
}
}
else
@@ -2910,7 +2897,7 @@ io_psave_thread (void *arg)
for (;;)
{
- (void)sleep (delay * MININSEC);
+ sleep (delay * MININSEC);
io_save_cal (config, IO_SAVE_DISPLAY_MARK);
}
}
@@ -2965,12 +2952,12 @@ io_set_lock (void)
if (lock != NULL)
{
- (void)fprintf (stderr,
- _("\nWARNING: it seems that another calcurse instance is "
- "already running.\n"
- "If this is not the case, please remove the following "
- "lock file: \n\"%s\"\n"
- "and restart calcurse.\n"), path_cpid);
+ fprintf (stderr,
+ _("\nWARNING: it seems that another calcurse instance is "
+ "already running.\n"
+ "If this is not the case, please remove the following "
+ "lock file: \n\"%s\"\n"
+ "and restart calcurse.\n"), path_cpid);
exit (EXIT_FAILURE);
}
else
@@ -3023,7 +3010,7 @@ io_get_pid (char *file)
if (fscanf (fp, "%u", &pid) != 1)
return 0;
- (void)fclose (fp);
+ fclose (fp);
return pid;
}
@@ -3052,3 +3039,36 @@ io_file_is_empty (char *file)
return -1;
}
+
+/*
+ * Copy an existing file to a new location.
+ */
+int
+io_file_cp (const char *src, const char *dst)
+{
+ FILE *fp_src, *fp_dst;
+ char *buffer[BUFSIZ];
+ unsigned int bytes_read;
+
+ if (!(fp_src = fopen (src, "rb")))
+ return 0;
+ if (!(fp_dst = fopen (dst, "wb")))
+ return 0;
+
+ while (!feof (fp_src))
+ {
+ bytes_read = fread (buffer, 1, BUFSIZ, fp_src);
+ if (bytes_read > 0)
+ {
+ if (fwrite (buffer, 1, bytes_read, fp_dst) != bytes_read)
+ return 0;
+ }
+ else
+ return 0;
+ }
+
+ fclose (fp_dst);
+ fclose (fp_src);
+
+ return 1;
+}