summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrederic Culot <calcurse@culot.org>2008-12-28 13:13:58 +0000
committerFrederic Culot <calcurse@culot.org>2008-12-28 13:13:58 +0000
commit5352496984d550bd441b12a082d5a382c168cbe2 (patch)
tree8a61b0785ba0d2f9edde566bef372360244949e3
parenta63c74892085e6bd5ea8b88712f44d1567ce7ed3 (diff)
downloadcalcurse-5352496984d550bd441b12a082d5a382c168cbe2.tar.gz
calcurse-5352496984d550bd441b12a082d5a382c168cbe2.zip
Added wrappers around libc's memory management functions, to easily debug memory usage
-rwxr-xr-xChangeLog22
-rwxr-xr-xconfigure.ac18
-rwxr-xr-xsrc/Makefile.am5
-rwxr-xr-xsrc/apoint.c117
-rwxr-xr-xsrc/apoint.h5
-rwxr-xr-xsrc/args.c42
-rwxr-xr-xsrc/calcurse.c12
-rwxr-xr-xsrc/calendar.c21
-rwxr-xr-xsrc/custom.c50
-rwxr-xr-xsrc/day.c91
-rwxr-xr-xsrc/day.h5
-rwxr-xr-xsrc/event.c25
-rwxr-xr-xsrc/help.c67
-rwxr-xr-xsrc/io.c540
-rwxr-xr-xsrc/keys.c67
-rwxr-xr-xsrc/keys.h3
-rwxr-xr-xsrc/notify.c109
-rwxr-xr-xsrc/notify.h4
-rwxr-xr-xsrc/recur.c149
-rwxr-xr-xsrc/recur.h5
-rwxr-xr-xsrc/sigs.c20
-rwxr-xr-xsrc/todo.c42
-rwxr-xr-xsrc/todo.h3
-rwxr-xr-xsrc/utils.c71
-rwxr-xr-xsrc/utils.h18
-rwxr-xr-xsrc/vars.c13
-rwxr-xr-xsrc/vars.h3
-rwxr-xr-xsrc/wins.c17
28 files changed, 883 insertions, 661 deletions
diff --git a/ChangeLog b/ChangeLog
index 2e78a91..1062c3b 100755
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2008-12-28 Frederic Culot <frederic@culot.org>
+
+ * mem.[ch]: new files to build wrappers around libc's memory
+ management functions
+
+ * configure.c: enable-memory-debug compilation option added
+
+ * src/utils.c (mem_free): function removed
+
+ * src/apoint.c (apoint_llist_free): new function
+
+ * src/day.c (day_saved_item_init, day_saved_item_free): new
+ functions
+
+ * src/todo.c (todo_free_list): new_function
+
+ * src/recur.c (recur_apoint_llist_free, free_exc): new functions
+
+ * src/notify.c (notify_free_vars, notify_free_bar): new functions
+
+ * src/vars.c (vars_free): new function
+
2008-12-27 Frederic Culot <frederic@culot.org>
* === Released 2.4 ===
diff --git a/configure.ac b/configure.ac
index 05ccb4a..678b25e 100755
--- a/configure.ac
+++ b/configure.ac
@@ -1,4 +1,4 @@
-# $calcurse: configure.ac,v 1.27 2008/12/27 10:27:53 culot Exp $
+# $calcurse: configure.ac,v 1.28 2008/12/28 13:13:59 culot Exp $
#-------------------------------------------------------------------------------
# Init
@@ -57,6 +57,22 @@ AC_CHECK_HEADERS([math.h], [
# Compilation options
#-------------------------------------------------------------------------------
CFLAGS="$CFLAGS -Wall"
+
+AC_ARG_ENABLE(memory_debug,
+ AS_HELP_STRING([--enable-memory-debug],
+ [use memory debug functions]),
+ memdebug=$enableval)
+if test "$memdebug" != "yes"; then
+ memdebug=no
+ AC_DEFINE(CALCURSE_MEMORY_DEBUG_DISABLED, 1,
+ [Define to 1 if you do not want memory debug.])
+else
+ AC_DEFINE(CALCURSE_MEMORY_DEBUG, 1,
+ [Define to 1 if you want memory debug.])
+fi
+AC_MSG_CHECKING([if memory debug should be used])
+AC_MSG_RESULT($memdebug)
+AM_CONDITIONAL(CALCURSE_MEMORY_DEBUG, test x$memdebug = xyes)
#-------------------------------------------------------------------------------
# Create Makefiles
#-------------------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index 272f3db..ff9b9a2 100755
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,4 @@
-# $calcurse: Makefile.am,v 1.7 2008/11/08 19:05:15 culot Exp $
+# $calcurse: Makefile.am,v 1.8 2008/12/28 13:13:59 culot Exp $
AUTOMAKE_OPTIONS= gnu
@@ -21,7 +21,8 @@ calcurse_SOURCES= \
todo.c todo.h \
utils.c utils.h \
vars.c vars.h \
- wins.c wins.h
+ wins.c wins.h \
+ mem.c mem.h
LDADD= @LTLIBINTL@
diff --git a/src/apoint.c b/src/apoint.c
index 75b2235..30ecbc7 100755
--- a/src/apoint.c
+++ b/src/apoint.c
@@ -1,4 +1,4 @@
-/* $calcurse: apoint.c,v 1.28 2008/12/15 20:02:00 culot Exp $ */
+/* $calcurse: apoint.c,v 1.29 2008/12/28 13:13:59 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -38,19 +38,41 @@
#include "recur.h"
#include "keys.h"
#include "calendar.h"
+#include "mem.h"
#include "apoint.h"
apoint_llist_t *alist_p;
static int hilt = 0;
-int
+void
apoint_llist_init (void)
{
- alist_p = (apoint_llist_t *) malloc (sizeof (apoint_llist_t));
+ alist_p = (apoint_llist_t *) mem_malloc (sizeof (apoint_llist_t));
alist_p->root = NULL;
pthread_mutex_init (&(alist_p->mutex), NULL);
+}
- return (0);
+/*
+ * Called before exit to free memory associated with the appointments linked
+ * list. No need to be thread safe, as only the main process remains when
+ * calling this function.
+ */
+void
+apoint_llist_free (void)
+{
+ apoint_llist_node_t *o, **i;
+
+ i = &alist_p->root;
+ for (o = alist_p->root; o; o = o->next)
+ {
+ *i = o->next;
+ mem_free (o->mesg);
+ if (o->note)
+ mem_free (o->note);
+ mem_free (o);
+ i = &(*i)->next;
+ }
+ mem_free (alist_p);
}
/* Sets which appointment is highlighted. */
@@ -84,9 +106,9 @@ apoint_new (char *mesg, char *note, long start, long dur, char state)
{
apoint_llist_node_t *o, **i;
- o = (apoint_llist_node_t *) malloc (sizeof (apoint_llist_node_t));
- o->mesg = strdup (mesg);
- o->note = (note != NULL) ? strdup (note) : NULL;
+ o = (apoint_llist_node_t *) mem_malloc (sizeof (apoint_llist_node_t));
+ o->mesg = mem_strdup (mesg);
+ o->note = (note != NULL) ? mem_strdup (note) : NULL;
o->state = state;
o->start = start;
o->dur = dur;
@@ -131,8 +153,6 @@ apoint_add (void)
char item_time[LTIME] = "";
char item_mesg[BUFSIZ] = "";
long apoint_duration = 0, apoint_start;
- apoint_llist_node_t *apoint_pointeur;
- struct event_s *event_pointeur;
unsigned heures, minutes;
unsigned end_h, end_m;
int is_appointment = 1;
@@ -154,7 +174,7 @@ apoint_add (void)
(void)wgetch (win[STA].p);
}
else
- sscanf (item_time, "%u:%u", &heures, &minutes);
+ (void)sscanf (item_time, "%u:%u", &heures, &minutes);
}
else
return;
@@ -183,7 +203,7 @@ apoint_add (void)
apoint_duration = atoi (item_time);
else if (check_time (item_time) == 1)
{
- sscanf (item_time, "%u:%u", &end_h, &end_m);
+ (void)sscanf (item_time, "%u:%u", &end_h, &end_m);
if (end_h < heures)
{
apoint_duration = MININSEC - minutes + end_m
@@ -207,15 +227,14 @@ apoint_add (void)
if (is_appointment)
{
apoint_start = date2sec (*calendar_get_slctd_day (), heures, minutes);
- apoint_pointeur = apoint_new (item_mesg, 0L, apoint_start,
- min2sec (apoint_duration), 0L);
+ (void)apoint_new (item_mesg, 0L, apoint_start,
+ min2sec (apoint_duration), 0L);
if (notify_bar ())
notify_check_added (item_mesg, apoint_start, 0L);
}
else
- event_pointeur = event_new (item_mesg, 0L,
- date2sec (*calendar_get_slctd_day (), 12,
- 0), Id);
+ (void)event_new (item_mesg, 0L,
+ date2sec (*calendar_get_slctd_day (), 12, 0), Id);
if (hilt == 0)
hilt++;
@@ -302,24 +321,20 @@ apoint_sec2str (apoint_llist_node_t *o, int type, long day, char *start,
time_t t;
if (o->start < day && type == APPT)
- {
- strncpy (start, "..:..", 6);
- }
+ (void)strncpy (start, "..:..", 6);
else
{
t = o->start;
lt = localtime (&t);
- snprintf (start, HRMIN_SIZE, "%02u:%02u", lt->tm_hour, lt->tm_min);
+ (void)snprintf (start, HRMIN_SIZE, "%02u:%02u", lt->tm_hour, lt->tm_min);
}
if (o->start + o->dur > day + DAYINSEC && type == APPT)
- {
- strncpy (end, "..:..", 6);
- }
+ (void)strncpy (end, "..:..", 6);
else
{
t = o->start + o->dur;
lt = localtime (&t);
- snprintf (end, HRMIN_SIZE, "%02u:%02u", lt->tm_hour, lt->tm_min);
+ (void)snprintf (end, HRMIN_SIZE, "%02u:%02u", lt->tm_hour, lt->tm_min);
}
}
@@ -331,44 +346,41 @@ apoint_write (apoint_llist_node_t *o, FILE *f)
t = o->start;
lt = localtime (&t);
- fprintf (f, "%02u/%02u/%04u @ %02u:%02u",
- lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year, lt->tm_hour,
- lt->tm_min);
+ (void)fprintf (f, "%02u/%02u/%04u @ %02u:%02u",
+ lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year, lt->tm_hour,
+ lt->tm_min);
t = o->start + o->dur;
lt = localtime (&t);
- fprintf (f, " -> %02u/%02u/%04u @ %02u:%02u ",
- lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year, lt->tm_hour,
- lt->tm_min);
+ (void)fprintf (f, " -> %02u/%02u/%04u @ %02u:%02u ",
+ lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year, lt->tm_hour,
+ lt->tm_min);
if (o->note != NULL)
- fprintf (f, ">%s ", o->note);
+ (void)fprintf (f, ">%s ", o->note);
if (o->state & APOINT_NOTIFY)
- fprintf (f, "!");
+ (void)fprintf (f, "!");
else
- fprintf (f, "|");
+ (void)fprintf (f, "|");
- fprintf (f, "%s\n", o->mesg);
+ (void)fprintf (f, "%s\n", o->mesg);
}
apoint_llist_node_t *
apoint_scan (FILE *f, struct tm start, struct tm end, char state, char *note)
{
- struct tm *lt;
- char buf[MESG_MAXSIZE], *nl;
+ char buf[MESG_MAXSIZE], *newline;
time_t tstart, tend, t;
t = time (NULL);
- lt = localtime (&t);
+ (void)localtime (&t);
/* Read the appointment description */
- fgets (buf, MESG_MAXSIZE, f);
- nl = strchr (buf, '\n');
- if (nl)
- {
- *nl = '\0';
- }
+ (void)fgets (buf, MESG_MAXSIZE, f);
+ newline = strchr (buf, '\n');
+ if (newline)
+ *newline = '\0';
start.tm_sec = end.tm_sec = 0;
start.tm_isdst = end.tm_isdst = -1;
@@ -432,9 +444,9 @@ apoint_delete_bynum (long start, unsigned num, erase_flag_e flag)
if (notify_bar ())
need_check_notify = notify_same_item (i->start);
*iptr = i->next;
- free (i->mesg);
+ mem_free (i->mesg);
erase_note (&i->note, flag);
- free (i);
+ mem_free (i);
pthread_mutex_unlock (&(alist_p->mutex));
if (need_check_notify)
notify_check_next_app ();
@@ -445,10 +457,10 @@ apoint_delete_bynum (long start, unsigned num, erase_flag_e flag)
}
iptr = &i->next;
}
+
pthread_mutex_unlock (&(alist_p->mutex));
-
- /* NOTREACHED */
EXIT (_("no such appointment"));
+ /* NOTREACHED */
}
/*
@@ -528,7 +540,7 @@ apoint_check_next (struct notify_app_s *app, long start)
if (i->start > start)
{
app->time = i->start;
- app->txt = strdup (i->mesg);
+ app->txt = mem_strdup (i->mesg);
app->state = i->state;
app->got_app = 1;
}
@@ -548,11 +560,10 @@ apoint_recur_s2apoint_s (recur_apoint_llist_node_t *p)
{
apoint_llist_node_t *a;
- a = (apoint_llist_node_t *) malloc (sizeof (apoint_llist_node_t));
- a->mesg = (char *) malloc (strlen (p->mesg) + 1);
+ a = (apoint_llist_node_t *) mem_malloc (sizeof (apoint_llist_node_t));
+ a->mesg = mem_strdup (p->mesg);
a->start = p->start;
a->dur = p->dur;
- a->mesg = p->mesg;
return (a);
}
@@ -605,10 +616,10 @@ apoint_switch_notify (void)
n++;
}
}
- pthread_mutex_unlock (&(alist_p->mutex));
- /* NOTREACHED */
+ pthread_mutex_unlock (&(alist_p->mutex));
EXIT (_("no such appointment"));
+ /* NOTREACHED */
}
/* Updates the Appointment panel */
diff --git a/src/apoint.h b/src/apoint.h
index dc71e34..ca3b4b3 100755
--- a/src/apoint.h
+++ b/src/apoint.h
@@ -1,4 +1,4 @@
-/* $calcurse: apoint.h,v 1.14 2008/04/19 21:05:15 culot Exp $ */
+/* $calcurse: apoint.h,v 1.15 2008/12/28 13:13:59 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -59,7 +59,8 @@ apoint_llist_t;
extern apoint_llist_t *alist_p;
-int apoint_llist_init (void);
+void apoint_llist_init (void);
+void apoint_llist_free (void);
void apoint_hilt_set (int);
void apoint_hilt_decrease (void);
void apoint_hilt_increase (void);
diff --git a/src/args.c b/src/args.c
index 812c572..c45cb7d 100755
--- a/src/args.c
+++ b/src/args.c
@@ -1,4 +1,4 @@
-/* $calcurse: args.c,v 1.41 2008/12/07 09:20:38 culot Exp $ */
+/* $calcurse: args.c,v 1.42 2008/12/28 13:13:59 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -41,6 +41,10 @@
#include "todo.h"
#include "io.h"
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
/*
* Print Calcurse usage and exit.
*/
@@ -72,7 +76,8 @@ version_arg ()
_("\nCopyright (c) 2004-2008 Frederic Culot.\n"
"This is free software; see the source for copying conditions.\n");
- snprintf (vtitle, BUFSIZ, _("Calcurse %s - text-based organizer\n"), VERSION);
+ (void)snprintf (vtitle, BUFSIZ, _("Calcurse %s - text-based organizer\n"),
+ VERSION);
fputs (vtitle, stdout);
fputs (vtext, stdout);
}
@@ -134,7 +139,8 @@ help_arg ()
"or read the manpage.\n"
"Mail bug reports and suggestions to <calcurse@culot.org>.\n");
- snprintf (htitle, BUFSIZ, _("Calcurse %s - text-based organizer\n"), VERSION);
+ (void)snprintf (htitle, BUFSIZ, _("Calcurse %s - text-based organizer\n"),
+ VERSION);
fputs (htitle, stdout);
usage ();
fputs (htext, stdout);
@@ -159,13 +165,13 @@ print_notefile (FILE *out, char *filename, int nbtab)
int printlinestarter = 1;
for (i = 0; i < nbtab; i++)
- snprintf(linestarter, BUFSIZ, "%s\t", linestarter);
+ (void)snprintf(linestarter, BUFSIZ, "%s\t", linestarter);
- snprintf (path_to_notefile, BUFSIZ, "%s/%s", path_notes, filename);
+ (void)snprintf (path_to_notefile, BUFSIZ, "%s/%s", path_notes, filename);
notefile = fopen (path_to_notefile, "r");
if (notefile)
{
- while (fgets (buffer, BUFSIZ, notefile) != NULL)
+ while (fgets (buffer, BUFSIZ, notefile) != 0)
{
if (printlinestarter)
{
@@ -177,7 +183,7 @@ print_notefile (FILE *out, char *filename, int nbtab)
printlinestarter = 1;
}
fputs ("\n", out);
- fclose (notefile);
+ file_close (notefile, __FILE_POS__);
}
else
{
@@ -207,7 +213,7 @@ todo_arg (int priority, int print_note)
fputs (_("to do:\n"), stdout);
title = 0;
}
- snprintf (priority_str, BUFSIZ, "%d. ", i->id);
+ (void)snprintf (priority_str, BUFSIZ, "%d. ", i->id);
fputs (priority_str, stdout);
fputs (i->mesg, stdout);
fputs ("\n", stdout);
@@ -239,8 +245,8 @@ next_arg (void)
hours_left = (time_left / HOURINSEC);
min_left = (time_left - hours_left * HOURINSEC) / MININSEC;
fputs (_("next appointment:\n"), stdout);
- snprintf (mesg, BUFSIZ, " [%02d:%02d] %s\n", hours_left, min_left,
- next_app.txt);
+ (void)snprintf (mesg, BUFSIZ, " [%02d:%02d] %s\n", hours_left, min_left,
+ next_app.txt);
fputs (mesg, stdout);
free (next_app.txt);
}
@@ -434,7 +440,7 @@ display_app (struct tm *t, int numdays, int add_line, int print_note,
if (app_found)
add_line = 1;
t->tm_mday++;
- mktime (t);
+ (void)mktime (t);
}
}
@@ -487,9 +493,9 @@ date_arg (char *ddate, int add_line, int print_note, conf_t *conf)
{
char outstr[BUFSIZ];
fputs (_("Argument to the '-d' flag is not valid\n"), stderr);
- snprintf (outstr, BUFSIZ,
- "Possible argument format are: '%s' or 'n'\n",
- DATEFMT_DESC (conf->input_datefmt));
+ (void)snprintf (outstr, BUFSIZ,
+ "Possible argument format are: '%s' or 'n'\n",
+ DATEFMT_DESC (conf->input_datefmt));
fputs (_(outstr), stdout);
more_info ();
}
@@ -535,7 +541,7 @@ date_arg_extended (char *startday, char *range, int add_line, int print_note,
{
t.tm_year -= 1900;
t.tm_mon--;
- mktime (&t);
+ (void)mktime (&t);
}
else
{
@@ -550,9 +556,9 @@ date_arg_extended (char *startday, char *range, int add_line, int print_note,
{
char outstr[BUFSIZ];
fputs (_("Argument is not valid\n"), stderr);
- snprintf (outstr, BUFSIZ,
- "Argument format for -s and --startday is: '%s'\n",
- DATEFMT_DESC (conf->input_datefmt));
+ (void)snprintf (outstr, BUFSIZ,
+ "Argument format for -s and --startday is: '%s'\n",
+ DATEFMT_DESC (conf->input_datefmt));
fputs (_(outstr), stdout);
fputs (_("Argument format for -r and --range is: 'n'\n"), stdout);
more_info ();
diff --git a/src/calcurse.c b/src/calcurse.c
index 451d616..67253b9 100755
--- a/src/calcurse.c
+++ b/src/calcurse.c
@@ -1,4 +1,4 @@
-/* $calcurse: calcurse.c,v 1.73 2008/12/20 19:27:31 culot Exp $ */
+/* $calcurse: calcurse.c,v 1.74 2008/12/28 13:13:59 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -24,13 +24,13 @@
*
*/
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif /* HAVE_CONFIG_H */
-
#include <stdlib.h>
#include <signal.h>
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
#include "i18n.h"
#include "io.h"
#include "help.h"
@@ -86,7 +86,7 @@ main (int argc, char **argv)
*/
non_interactive = parse_args (argc, argv, &conf);
if (non_interactive)
- return (EXIT_SUCCESS);
+ exit_calcurse (EXIT_SUCCESS);
/* Begin of interactive mode with ncurses interface. */
sigs_init (&sigact); /* signal handling init */
diff --git a/src/calendar.c b/src/calendar.c
index e6f8feb..12551ab 100755
--- a/src/calendar.c
+++ b/src/calendar.c
@@ -1,4 +1,4 @@
-/* $calcurse: calendar.c,v 1.20 2008/12/14 15:54:51 culot Exp $ */
+/* $calcurse: calendar.c,v 1.21 2008/12/28 13:13:59 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -63,25 +63,22 @@ static pthread_t calendar_t_date;
/* Thread needed to update current date in calendar. */
+/* ARGSUSED0 */
static void *
calendar_date_thread (void *arg)
{
- time_t now, tomorrow;
+ time_t actual, tomorrow;
for (;;)
{
tomorrow = (time_t) (get_today () + DAYINSEC);
- while ((now = time (NULL)) < tomorrow)
- {
- sleep (tomorrow - now);
- }
+ while ((actual = time (NULL)) < tomorrow)
+ (void)sleep (tomorrow - actual);
calendar_set_current_date ();
calendar_update_panel (win[CAL].p);
}
-
- pthread_exit ((void *) 0);
}
/* Launch the calendar date thread. */
@@ -362,7 +359,7 @@ calendar_change_day (int datefmt)
while (wrong_day)
{
- snprintf (outstr, BUFSIZ, request_date, DATEFMT_DESC (datefmt));
+ (void)snprintf (outstr, BUFSIZ, request_date, DATEFMT_DESC (datefmt));
status_mesg (_(outstr), "");
if (getstring (win[STA].p, selected_day, LDAY, 0, 1) == GETSTRING_ESC)
return;
@@ -424,7 +421,7 @@ calendar_move (move_t move)
int ret, days_to_remove, days_to_add;
struct tm t;
- memset (&t, 0, sizeof (struct tm));
+ (void)memset (&t, 0, sizeof (struct tm));
t.tm_mday = slctd_day.dd;
t.tm_mon = slctd_day.mm - 1;
t.tm_year = slctd_day.yyyy - 1900;
@@ -458,7 +455,7 @@ calendar_move (move_t move)
break;
case WEEK_START:
/* Normalize struct tm to get week day number. */
- mktime (&t);
+ (void)mktime (&t);
if (calendar_week_begins_on_monday ())
days_to_remove = ((t.tm_wday == 0) ? WEEKINDAYS - 1 : t.tm_wday - 1);
else
@@ -466,7 +463,7 @@ calendar_move (move_t move)
ret = date_change (&t, 0, 0 - days_to_remove);
break;
case WEEK_END:
- mktime (&t);
+ (void)mktime (&t);
if (calendar_week_begins_on_monday ())
days_to_add = ((t.tm_wday == 0) ? 0 : WEEKINDAYS - t.tm_wday);
else
diff --git a/src/custom.c b/src/custom.c
index a7b4eae..cc37c9c 100755
--- a/src/custom.c
+++ b/src/custom.c
@@ -1,4 +1,4 @@
-/* $calcurse: custom.c,v 1.31 2008/12/20 19:27:31 culot Exp $ */
+/* $calcurse: custom.c,v 1.32 2008/12/28 13:13:59 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -28,13 +28,18 @@
#include <stdlib.h>
#include <math.h>
-#include "custom.h"
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
#include "i18n.h"
#include "io.h"
#include "utils.h"
#include "keys.h"
#include "apoint.h"
#include "help.h"
+#include "mem.h"
+#include "custom.h"
static struct attribute_s attr;
@@ -214,7 +219,7 @@ custom_load_conf (conf_t *conf, int background)
status_mesg (mesg_line1, mesg_line2);
wnoutrefresh (win[STA].p);
doupdate ();
- keys_getch (win[STA].p);
+ (void)keys_getch (win[STA].p);
}
var = CUSTOM_CONF_NOVARIABLE;
pthread_mutex_lock (&nbar->mutex);
@@ -270,11 +275,11 @@ custom_load_conf (conf_t *conf, int background)
var = 0;
break;
case CUSTOM_CONF_NOTIFYBARDATE:
- strncpy (nbar->datefmt, e_conf, strlen (e_conf) + 1);
+ (void)strncpy (nbar->datefmt, e_conf, strlen (e_conf) + 1);
var = 0;
break;
case CUSTOM_CONF_NOTIFYBARCLOCK:
- strncpy (nbar->timefmt, e_conf, strlen (e_conf) + 1);
+ (void)strncpy (nbar->timefmt, e_conf, strlen (e_conf) + 1);
var = 0;
break;
case CUSTOM_CONF_NOTIFYBARWARNING:
@@ -282,12 +287,12 @@ custom_load_conf (conf_t *conf, int background)
var = 0;
break;
case CUSTOM_CONF_NOTIFYBARCOMMAND:
- strncpy (nbar->cmd, e_conf, strlen (e_conf) + 1);
+ (void)strncpy (nbar->cmd, e_conf, strlen (e_conf) + 1);
var = 0;
break;
case CUSTOM_CONF_OUTPUTDATEFMT:
if (e_conf[0] != '\0')
- strncpy (conf->output_datefmt, e_conf, strlen (e_conf) + 1);
+ (void)strncpy (conf->output_datefmt, e_conf, strlen (e_conf) + 1);
var = 0;
break;
case CUSTOM_CONF_INPUTDATEFMT:
@@ -332,7 +337,7 @@ custom_load_conf (conf_t *conf, int background)
else if (strncmp (e_conf, "input_datefmt=", 12) == 0)
var = CUSTOM_CONF_INPUTDATEFMT;
}
- fclose (data_file);
+ file_close (data_file, __FILE_POS__);
pthread_mutex_unlock (&nbar->mutex);
}
@@ -425,8 +430,8 @@ display_layout_config (window_t *lwin, int mark, int cursor, int need_reset)
if (lwin->p != NULL)
delwin (lwin->p);
- snprintf (label, BUFSIZ, _("CalCurse %s | layout configuration"),
- VERSION);
+ (void)snprintf (label, BUFSIZ, _("CalCurse %s | layout configuration"),
+ VERSION);
custom_confwin_init (lwin, label);
}
@@ -625,7 +630,7 @@ display_color_config (window_t *cwin, int *mark_fore, int *mark_back,
{
if (cwin->p != NULL)
delwin (cwin->p);
- snprintf (label, BUFSIZ, _("CalCurse %s | color theme"), VERSION);
+ (void)snprintf (label, BUFSIZ, _("CalCurse %s | color theme"), VERSION);
custom_confwin_init (cwin, label);
}
@@ -809,7 +814,7 @@ custom_color_theme_name (char *theme_name)
};
if (!colorize)
- snprintf (theme_name, BUFSIZ, "0");
+ (void)snprintf (theme_name, BUFSIZ, "0");
else
{
pair_content (COLR_CUSTOM, &color[0], &color[1]);
@@ -825,7 +830,8 @@ custom_color_theme_name (char *theme_name)
/* NOTREACHED */
}
}
- snprintf (theme_name, BUFSIZ, "%s on %s", color_name[0], color_name[1]);
+ (void)snprintf (theme_name, BUFSIZ, "%s on %s", color_name[0],
+ color_name[1]);
}
}
@@ -931,11 +937,12 @@ custom_general_config (conf_t *conf)
char *input_datefmt_str =
_("Enter the date format (1-mm/dd/yyyy, 2-dd/mm/yyyy, 3-yyyy/mm/dd) ");
int ch;
- char *buf = (char *) malloc (BUFSIZ);
+ char *buf = (char *) mem_malloc (BUFSIZ);
clear ();
conf_set_scrsize (&cwin);
- snprintf (cwin.label, BUFSIZ, _("CalCurse %s | general options"), VERSION);
+ (void)snprintf (cwin.label, BUFSIZ, _("CalCurse %s | general options"),
+ VERSION);
wins_scrollwin_init (&cwin);
wins_show (cwin.win.p, cwin.label);
status_mesg (number_str, keys);
@@ -990,11 +997,11 @@ custom_general_config (conf_t *conf)
break;
case '7':
status_mesg (output_datefmt_str, "");
- strncpy (buf, conf->output_datefmt,
- strlen (conf->output_datefmt) + 1);
+ (void)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);
+ (void)strncpy (conf->output_datefmt, buf, strlen (buf) + 1);
}
status_mesg (number_str, keys);
break;
@@ -1013,7 +1020,7 @@ custom_general_config (conf_t *conf)
cwin.total_lines = print_general_options (cwin.pad.p, conf);
wins_scrollwin_display (&cwin);
}
- free (buf);
+ mem_free (buf);
wins_scrollwin_delete (&cwin);
}
@@ -1045,7 +1052,7 @@ print_keys_bindings (WINDOW *win, int selected_row, int selected_elm, int yoff)
int nbkeys;
nbkeys = keys_action_count_keys (action);
- snprintf (actionstr, BUFSIZ, "%s", keys_get_label (action));
+ (void)snprintf (actionstr, BUFSIZ, "%s", keys_get_label (action));
if (action == selected_row)
custom_apply_attr (win, ATTR_HIGHEST);
mvwprintw (win, y, XPOS, "%s ", actionstr);
@@ -1117,7 +1124,8 @@ custom_keys_config (void)
clear ();
conf_set_scrsize (&kwin);
nbdisplayed = (kwin.win.h - LABELLINES) / LINESPERKEY;
- snprintf (kwin.label, BUFSIZ, _("CalCurse %s | keys configuration"), VERSION);
+ (void)snprintf (kwin.label, BUFSIZ, _("CalCurse %s | keys configuration"),
+ VERSION);
wins_scrollwin_init (&kwin);
wins_show (kwin.win.p, kwin.label);
custom_keys_config_bar ();
diff --git a/src/day.c b/src/day.c
index 884fd3b..3c29c16 100755
--- a/src/day.c
+++ b/src/day.c
@@ -1,4 +1,4 @@
-/* $calcurse: day.c,v 1.42 2008/12/15 20:02:00 culot Exp $ */
+/* $calcurse: day.c,v 1.43 2008/12/28 13:13:59 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -35,22 +35,40 @@
#include "event.h"
#include "custom.h"
#include "keys.h"
+#include "mem.h"
#include "day.h"
static struct day_item_s *day_items_ptr;
-static struct day_saved_item_s *day_saved_item = NULL;
+static struct day_saved_item_s *day_saved_item;
+
+void
+day_saved_item_init (void)
+{
+ day_saved_item = mem_malloc (sizeof (struct day_saved_item_s));
+}
+
+void
+day_saved_item_free (void)
+{
+ if (day_saved_item)
+ mem_free (day_saved_item);
+}
/* Free the current day linked list containing the events and appointments. */
-static void
+void
day_free_list (void)
{
- struct day_item_s *p, *q;
+ struct day_item_s *o, **i;
- for (p = day_items_ptr; p != 0; p = q)
+ i = &day_items_ptr;
+ for (o = day_items_ptr; o; o = o->next)
{
- q = p->next;
- free (p->mesg);
- free (p);
+ *i = o->next;
+ mem_free (o->mesg);
+ if (o->note)
+ mem_free (o->note);
+ mem_free (o);
+ i = &(*i)->next;
}
day_items_ptr = NULL;
}
@@ -60,9 +78,8 @@ static struct day_item_s *
day_add_event (int type, char *mesg, char *note, long day, int id)
{
struct day_item_s *o, **i;
- o = (struct day_item_s *) malloc (sizeof (struct day_item_s));
- o->mesg = (char *) malloc (strlen (mesg) + 1);
- strncpy (o->mesg, mesg, strlen (mesg) + 1);
+ o = (struct day_item_s *) mem_malloc (sizeof (struct day_item_s));
+ o->mesg = mem_strdup (mesg);
o->note = note;
o->type = type;
o->appt_dur = 0;
@@ -91,8 +108,8 @@ day_add_apoint (int type, char *mesg, char *note, long start, long dur,
struct day_item_s *o, **i;
int insert_item = 0;
- o = (struct day_item_s *) malloc (sizeof (struct day_item_s));
- o->mesg = strdup (mesg);
+ o = (struct day_item_s *) mem_malloc (sizeof (struct day_item_s));
+ o->mesg = mem_strdup (mesg);
o->note = note;
o->start = start;
o->appt_dur = dur;
@@ -368,7 +385,7 @@ display_item (int incolor, char *msg, int recur, int note, int len, int y,
mvwprintw (win, y, x, " %c%c%s", ch_recur, ch_note, msg);
else
{
- strncpy (buf, msg, len - 1);
+ (void)strncpy (buf, msg, len - 1);
buf[len - 1] = '\0';
mvwprintw (win, y, x, " %c%c%s...", ch_recur, ch_note, buf);
}
@@ -396,10 +413,8 @@ day_write_pad (long date, int width, int length, int incolor)
max_pos = length;
/* Initialize the structure used to store highlited item. */
- if (day_saved_item == NULL)
- {
- day_saved_item = malloc (sizeof (struct day_saved_item_s));
- }
+ if (day_saved_item == 0)
+ day_saved_item_init ();
for (p = day_items_ptr; p != 0; p = p->next)
{
@@ -545,8 +560,8 @@ update_start_time (long *start, long *dur)
do
{
timestr = day_edit_time (*start);
- sscanf (timestr, "%u:%u", &hr, &mn);
- free (timestr);
+ (void)sscanf (timestr, "%u:%u", &hr, &mn);
+ mem_free (timestr);
newtime = update_time_in_date (*start, hr, mn);
if (newtime < *start + *dur)
{
@@ -572,8 +587,8 @@ update_duration (long *start, long *dur)
char *timestr;
timestr = day_edit_time (*start + *dur);
- sscanf (timestr, "%u:%u", &hr, &mn);
- free (timestr);
+ (void)sscanf (timestr, "%u:%u", &hr, &mn);
+ mem_free (timestr);
newtime = update_time_in_date (*start, hr, mn);
*dur = (newtime > *start) ? newtime - *start : DAYINSEC + newtime - *start;
}
@@ -606,18 +621,18 @@ update_rept (struct rpt_s **rpt, const long start, conf_t *conf)
do
{
status_mesg (msg_rpt_type, msg_rpt_ans);
- typstr = (char *) malloc (sizeof (char) * SINGLECHAR);
- snprintf (typstr, SINGLECHAR, "%c", recur_def2char ((*rpt)->type));
+ typstr = (char *) mem_malloc (sizeof (char) * SINGLECHAR);
+ (void)snprintf (typstr, SINGLECHAR, "%c", recur_def2char ((*rpt)->type));
cancel = updatestring (win[STA].p, &typstr, 0, 1);
if (cancel)
{
- free (typstr);
+ mem_free (typstr);
return;
}
else
{
ch = toupper (*typstr);
- free (typstr);
+ mem_free (typstr);
}
}
while ((ch != 'D') && (ch != 'W') && (ch != 'M') && (ch != 'Y'));
@@ -625,18 +640,18 @@ update_rept (struct rpt_s **rpt, const long start, conf_t *conf)
do
{
status_mesg (_("Enter the new repetition frequence:"), "");
- freqstr = (char *) malloc (BUFSIZ);
- snprintf (freqstr, BUFSIZ, "%d", (*rpt)->freq);
+ freqstr = (char *) mem_malloc (BUFSIZ);
+ (void)snprintf (freqstr, BUFSIZ, "%d", (*rpt)->freq);
cancel = updatestring (win[STA].p, &freqstr, 0, 1);
if (cancel)
{
- free (freqstr);
+ mem_free (freqstr);
return;
}
else
{
newfreq = atoi (freqstr);
- free (freqstr);
+ mem_free (freqstr);
if (newfreq == 0)
{
status_mesg (msg_wrong_freq, msg_enter);
@@ -648,15 +663,15 @@ update_rept (struct rpt_s **rpt, const long start, conf_t *conf)
do
{
- snprintf (outstr, BUFSIZ, "Enter the new ending date: [%s] or '0'",
- DATEFMT_DESC (conf->input_datefmt));
+ (void)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));
cancel = updatestring (win[STA].p, &timstr, 0, 1);
if (cancel)
{
- free (timstr);
+ mem_free (timstr);
return;
}
if (strcmp (timstr, "0") == 0)
@@ -691,8 +706,8 @@ update_rept (struct rpt_s **rpt, const long start, conf_t *conf)
}
else
{
- snprintf (outstr, BUFSIZ, msg_fmts,
- DATEFMT_DESC (conf->input_datefmt));
+ (void)snprintf (outstr, BUFSIZ, msg_fmts,
+ DATEFMT_DESC (conf->input_datefmt));
status_mesg (msg_wrong_date, _(outstr));
(void)wgetch (win[STA].p);
date_entered = 0;
@@ -701,7 +716,7 @@ update_rept (struct rpt_s **rpt, const long start, conf_t *conf)
}
while (date_entered == 0);
- free (timstr);
+ mem_free (timstr);
(*rpt)->type = recur_char2def (ch);
(*rpt)->freq = newfreq;
(*rpt)->until = newuntil;
@@ -943,7 +958,7 @@ day_edit_note (char *editor)
else
p->note = filename;
}
- snprintf (fullname, BUFSIZ, "%s%s", path_notes, p->note);
+ (void)snprintf (fullname, BUFSIZ, "%s%s", path_notes, p->note);
wins_launch_external (fullname, editor);
date = calendar_get_slctd_day_sec ();
@@ -978,6 +993,6 @@ day_view_note (char *pager)
p = day_get_item (apoint_hilt ());
if (p->note == NULL)
return;
- snprintf (fullname, BUFSIZ, "%s%s", path_notes, p->note);
+ (void)snprintf (fullname, BUFSIZ, "%s%s", path_notes, p->note);
wins_launch_external (fullname, pager);
}
diff --git a/src/day.h b/src/day.h
index 380d64c..c053833 100755
--- a/src/day.h
+++ b/src/day.h
@@ -1,4 +1,4 @@
-/* $calcurse: day.h,v 1.19 2008/04/12 21:14:03 culot Exp $ */
+/* $calcurse: day.h,v 1.20 2008/12/28 13:13:59 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -67,6 +67,9 @@ struct day_saved_item_s
char *mesg;
};
+void day_saved_item_init (void);
+void day_saved_item_free (void);
+void day_free_list (void);
day_items_nb_t *day_process_storage (date_t *, bool, day_items_nb_t *);
void day_write_pad (long, int, int, int);
void day_popup_item (void);
diff --git a/src/event.c b/src/event.c
index 8464a77..f366b6d 100755
--- a/src/event.c
+++ b/src/event.c
@@ -1,4 +1,4 @@
-/* $calcurse: event.c,v 1.8 2008/12/14 15:54:51 culot Exp $ */
+/* $calcurse: event.c,v 1.9 2008/12/28 13:13:59 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -31,6 +31,7 @@
#include "vars.h"
#include "i18n.h"
+#include "mem.h"
#include "event.h"
struct event_s *eventlist;
@@ -40,9 +41,8 @@ struct event_s *
event_new (char *mesg, char *note, long day, int id)
{
struct event_s *o, **i;
- o = (struct event_s *) malloc (sizeof (struct event_s));
- o->mesg = (char *) malloc (strlen (mesg) + 1);
- strncpy (o->mesg, mesg, strlen (mesg) + 1);
+ o = (struct event_s *) mem_malloc (sizeof (struct event_s));
+ o->mesg = mem_strdup (mesg);
o->day = day;
o->id = id;
o->note = (note != NULL) ? strdup (note) : NULL;
@@ -80,26 +80,25 @@ event_write (struct event_s *o, FILE *f)
t = o->day;
lt = localtime (&t);
- fprintf (f, "%02u/%02u/%04u [%d] ", lt->tm_mon + 1, lt->tm_mday,
- 1900 + lt->tm_year, o->id);
+ (void)fprintf (f, "%02u/%02u/%04u [%d] ", lt->tm_mon + 1, lt->tm_mday,
+ 1900 + lt->tm_year, o->id);
if (o->note != NULL)
- fprintf (f, ">%s ", o->note);
- fprintf (f, "%s\n", o->mesg);
+ (void)fprintf (f, ">%s ", o->note);
+ (void)fprintf (f, "%s\n", o->mesg);
}
/* Load the events from file */
struct event_s *
event_scan (FILE *f, struct tm start, int id, char *note)
{
- struct tm *lt;
char buf[MESG_MAXSIZE], *nl;
time_t tstart, t;
t = time (NULL);
- lt = localtime (&t);
+ (void)localtime (&t);
/* Read the event description */
- fgets (buf, MESG_MAXSIZE, f);
+ (void)fgets (buf, MESG_MAXSIZE, f);
nl = strchr (buf, '\n');
if (nl)
{
@@ -160,9 +159,9 @@ event_delete_bynum (long start, unsigned num, erase_flag_e flag)
else
{
*iptr = i->next;
- free (i->mesg);
+ mem_free (i->mesg);
erase_note (&i->note, flag);
- free (i);
+ mem_free (i);
}
return;
}
diff --git a/src/help.c b/src/help.c
index a8fa336..b7a9dd1 100755
--- a/src/help.c
+++ b/src/help.c
@@ -1,4 +1,4 @@
-/* $calcurse: help.c,v 1.35 2008/12/20 19:27:31 culot Exp $ */
+/* $calcurse: help.c,v 1.36 2008/12/28 13:13:59 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -29,6 +29,10 @@
#include <ctype.h>
#include <sys/types.h>
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
#include "i18n.h"
#include "custom.h"
#include "utils.h"
@@ -67,15 +71,15 @@ help_pages_e;
static int
get_help_lines (char *text)
{
- int i;
- int nl = 0;
+ int i, newline;
+ newline = 0;
for (i = 0; text[i]; i++)
{
if (text[i] == '\n')
- nl++;
+ newline++;
}
- return (nl + 1);
+ return newline + 1;
}
/*
@@ -146,7 +150,7 @@ help_wins_init (scrollwin_t *hwin, int x, int y, int h, int w)
hwin->pad.h = BUFSIZ;
hwin->pad.w = hwin->win.w - 2 * PADOFFSET + 1;
- snprintf (hwin->label, BUFSIZ, _("Calcurse %s | help"), VERSION);
+ (void)snprintf (hwin->label, BUFSIZ, _("Calcurse %s | help"), VERSION);
wins_scrollwin_init (hwin);
wins_show (hwin->win.p, hwin->label);
}
@@ -311,7 +315,7 @@ help_screen (void)
hscr[HELP_MAIN].title =
_(" Welcome to Calcurse. This is the main help screen.\n");
- snprintf (hscr[HELP_MAIN].text, HELPTEXTSIZ,
+ (void)snprintf (hscr[HELP_MAIN].text, HELPTEXTSIZ,
_("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"
@@ -332,7 +336,7 @@ help_screen (void)
keys_action_firstkey (KEY_GENERIC_CREDITS));
hscr[HELP_SAVE].title = _("Save\n");
- snprintf (hscr[HELP_SAVE].text, HELPTEXTSIZ,
+ (void)snprintf (hscr[HELP_SAVE].text, HELPTEXTSIZ,
_("Save calcurse data.\n"
"Data are splitted into four different files which contain :"
"\n\n"
@@ -345,7 +349,7 @@ help_screen (void)
"automatically before quitting."));
hscr[HELP_IMPORT].title = _("Import\n");
- snprintf (hscr[HELP_IMPORT].text, HELPTEXTSIZ,
+ (void)snprintf (hscr[HELP_IMPORT].text, HELPTEXTSIZ,
_("Import data from an icalendar file.\n"
"You will be asked to enter the file name from which to load ical\n"
"items. At the end of the import process, and if the general option\n"
@@ -363,7 +367,7 @@ help_screen (void)
"the item could not be imported.\n"));
hscr[HELP_EXPORT].title = _("Export\n");
- snprintf (hscr[HELP_EXPORT].text, HELPTEXTSIZ,
+ (void)snprintf (hscr[HELP_EXPORT].text, HELPTEXTSIZ,
_("Export calcurse data (appointments, events and todos).\n"
"This leads to the export submenu, from which you can choose between\n"
"two different export formats: 'ical' and 'pcal'. Choosing one of\n"
@@ -378,12 +382,15 @@ help_screen (void)
"Calcurse data are exported in the following order:\n"
" 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);
+ (void)strncpy (keystr[MOVE_UP], keys_action_allkeys (KEY_MOVE_UP), BUFSIZ);
+ (void)strncpy (keystr[MOVE_DOWN], keys_action_allkeys (KEY_MOVE_DOWN),
+ BUFSIZ);
+ (void)strncpy (keystr[MOVE_LEFT], keys_action_allkeys (KEY_MOVE_LEFT),
+ BUFSIZ);
+ (void)strncpy (keystr[MOVE_RIGHT], keys_action_allkeys (KEY_MOVE_RIGHT),
+ BUFSIZ);
hscr[HELP_DISPLACEMENT].title = _("Displacement keys\n");
- snprintf (hscr[HELP_DISPLACEMENT].text, HELPTEXTSIZ,
+ (void)snprintf (hscr[HELP_DISPLACEMENT].text, HELPTEXTSIZ,
_("Move around inside calcurse screens.\n"
"The following scheme summarizes how to get around:\n\n"
" move up\n"
@@ -410,7 +417,7 @@ help_screen (void)
keys_action_firstkey (KEY_END_OF_WEEK));
hscr[HELP_VIEW].title = _("View\n");
- snprintf (hscr[HELP_VIEW].text, HELPTEXTSIZ,
+ (void)snprintf (hscr[HELP_VIEW].text, HELPTEXTSIZ,
_("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. "
@@ -423,7 +430,7 @@ help_screen (void)
keys_action_firstkey (KEY_VIEW_ITEM));
hscr[HELP_TAB].title = _("Tab\n");
- snprintf (hscr[HELP_TAB].text, HELPTEXTSIZ,
+ (void)snprintf (hscr[HELP_TAB].text, HELPTEXTSIZ,
_("Switch between panels.\n"
"The panel currently in use has its border colorized.\n"
"\nSome actions are possible only if the right panel is selected.\n"
@@ -438,7 +445,7 @@ help_screen (void)
keys_action_firstkey (KEY_GENERIC_CHANGE_VIEW));
hscr[HELP_GOTO].title = _("Goto\n");
- snprintf (hscr[HELP_GOTO].text, HELPTEXTSIZ,
+ (void)snprintf (hscr[HELP_GOTO].text, HELPTEXTSIZ,
_("Jump to a specific day in the calendar.\n"
"\nUsing this command, you do not need to travel to that day using\n"
"the displacement keys inside the calendar panel.\n"
@@ -449,7 +456,7 @@ help_screen (void)
keys_action_firstkey (KEY_GENERIC_GOTO_TODAY));
hscr[HELP_DELETE].title = _("Delete\n");
- snprintf (hscr[HELP_DELETE].text, HELPTEXTSIZ,
+ (void)snprintf (hscr[HELP_DELETE].text, HELPTEXTSIZ,
_("Delete an element in the ToDo or Appointment list.\n"
"\nDepending on which panel is selected when you press the delete key,\n"
"the hilighted item of either the ToDo or Appointment list will be \n"
@@ -463,7 +470,7 @@ help_screen (void)
"next time you launch Calcurse."));
hscr[HELP_ADD].title = _("Add\n");
- snprintf (hscr[HELP_ADD].text, HELPTEXTSIZ,
+ (void)snprintf (hscr[HELP_ADD].text, HELPTEXTSIZ,
_("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"
@@ -500,7 +507,7 @@ help_screen (void)
keys_action_firstkey (KEY_ADD_ITEM));
hscr[HELP_EDIT].title = _("Edit Item\n");
- snprintf (hscr[HELP_EDIT].text, HELPTEXTSIZ,
+ (void)snprintf (hscr[HELP_EDIT].text, HELPTEXTSIZ,
_("Edit the item which is currently selected.\n"
"Depending on the item type (appointment, event, or todo), and if it is\n"
"repeated or not, you will be asked to choose one of the item properties"
@@ -517,7 +524,7 @@ help_screen (void)
" modified properties next time you launch Calcurse."));
hscr[HELP_ENOTE].title = _("EditNote\n");
- snprintf (hscr[HELP_ENOTE].text, HELPTEXTSIZ,
+ (void)snprintf (hscr[HELP_ENOTE].text, HELPTEXTSIZ,
_("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"
@@ -538,7 +545,7 @@ help_screen (void)
keys_action_firstkey (KEY_EDIT_NOTE));
hscr[HELP_VNOTE].title = _("ViewNote\n");
- snprintf (hscr[HELP_VNOTE].text, HELPTEXTSIZ,
+ (void)snprintf (hscr[HELP_VNOTE].text, HELPTEXTSIZ,
_("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"
@@ -557,7 +564,7 @@ help_screen (void)
keys_action_firstkey (KEY_VIEW_NOTE));
hscr[HELP_PRIORITY].title = _("Priority\n");
- snprintf (hscr[HELP_PRIORITY].text, HELPTEXTSIZ,
+ (void)snprintf (hscr[HELP_PRIORITY].text, HELPTEXTSIZ,
_("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"
@@ -575,7 +582,7 @@ help_screen (void)
keys_action_firstkey (KEY_LOWER_PRIORITY));
hscr[HELP_REPEAT].title = _("Repeat\n");
- snprintf (hscr[HELP_REPEAT].text, HELPTEXTSIZ,
+ (void)snprintf (hscr[HELP_REPEAT].text, HELPTEXTSIZ,
_("Repeat an event or an appointment.\n"
"You must first select the item to be repeated by moving inside the\n"
"appointment panel. Then pressing '%s' will lead you to a set of three\n"
@@ -602,7 +609,7 @@ help_screen (void)
keys_action_firstkey (KEY_REPEAT_ITEM));
hscr[HELP_FLAG].title = _("Flag Item\n");
- snprintf (hscr[HELP_FLAG].text, HELPTEXTSIZ,
+ (void)snprintf (hscr[HELP_FLAG].text, HELPTEXTSIZ,
_("Toggle an appointment's 'important' flag.\n"
"If an item is flagged as important, an exclamation mark appears in front"
"\nof it, and you will be warned if time gets closed to the appointment\n"
@@ -612,7 +619,7 @@ help_screen (void)
"\nand how long before it he gets notified."));
hscr[HELP_CONFIG].title = _("Config\n");
- snprintf (hscr[HELP_CONFIG].text, HELPTEXTSIZ,
+ (void)snprintf (hscr[HELP_CONFIG].text, HELPTEXTSIZ,
_("Open the configuration submenu.\n"
"From this submenu, you can select between color, layout, notification\n"
"and general options, and you can also configure your keybindings.\n"
@@ -627,7 +634,7 @@ help_screen (void)
"\nnext time you launch Calcurse."));
hscr[HELP_GENERAL].title = _("Generic keybindings\n");
- snprintf (hscr[HELP_GENERAL].text, HELPTEXTSIZ,
+ (void)snprintf (hscr[HELP_GENERAL].text, HELPTEXTSIZ,
_("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"
@@ -652,7 +659,7 @@ help_screen (void)
keys_action_firstkey (KEY_GENERIC_GOTO_TODAY));
hscr[HELP_OTHER].title = _("OtherCmd\n");
- snprintf (hscr[HELP_OTHER].text, HELPTEXTSIZ,
+ (void)snprintf (hscr[HELP_OTHER].text, HELPTEXTSIZ,
_("Switch between status bar help pages.\n"
"Because the terminal screen is too narrow to display all of the\n"
"available commands, you need to press '%s' to see the next set of\n"
@@ -663,7 +670,7 @@ help_screen (void)
keys_action_firstkey (KEY_GENERIC_OTHER_CMD));
hscr[HELP_CREDITS].title = _("Calcurse - text-based organizer");
- snprintf (hscr[HELP_CREDITS].text, HELPTEXTSIZ,
+ (void)snprintf (hscr[HELP_CREDITS].text, HELPTEXTSIZ,
_("\nCopyright (c) 2004-2008 Frederic Culot\n"
"\n"
"This program is free software; you can redistribute it and/or modify\n"
diff --git a/src/io.c b/src/io.c
index 303bf8b..280be0d 100755
--- a/src/io.c
+++ b/src/io.c
@@ -1,4 +1,4 @@
-/* $calcurse: io.c,v 1.49 2008/12/14 15:54:51 culot Exp $ */
+/* $calcurse: io.c,v 1.50 2008/12/28 13:13:59 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -32,6 +32,10 @@
#include <unistd.h>
#include <errno.h>
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
#include "i18n.h"
#include "utils.h"
#include "custom.h"
@@ -41,6 +45,7 @@
#include "recur.h"
#include "keys.h"
#include "htable.h"
+#include "mem.h"
#include "io.h"
#define ICALDATEFMT "%Y%m%d"
@@ -190,7 +195,7 @@ progress_bar (progress_bar_t type, int progress)
custom_remove_attr (win[STA].p, ATTR_HIGHEST);
wmove (win[STA].p, 0, 0);
wrefresh (win[STA].p);
- usleep (SLEEPTIME);
+ (void)usleep (SLEEPTIME);
#undef SLEEPTIME
#undef NBFILES
#undef NBEXPORTED
@@ -211,11 +216,12 @@ get_export_stream (export_type_t type)
const char *file_ext[IO_EXPORT_NBTYPES] = {"ical", "txt"};
stream = NULL;
- stream_name = (char *) malloc (BUFSIZ);
+ stream_name = (char *) mem_malloc (BUFSIZ);
if ((home = getenv ("HOME")) != NULL)
- snprintf (stream_name, BUFSIZ, "%s/calcurse.%s", home, file_ext[type]);
+ (void)snprintf (stream_name, BUFSIZ, "%s/calcurse.%s", home,
+ file_ext[type]);
else
- snprintf (stream_name, BUFSIZ, "/tmp/calcurse.%s", file_ext[type]);
+ (void)snprintf (stream_name, BUFSIZ, "/tmp/calcurse.%s", file_ext[type]);
while (stream == NULL)
{
@@ -223,7 +229,7 @@ get_export_stream (export_type_t type)
cancel = updatestring (win[STA].p, &stream_name, 0, 1);
if (cancel)
{
- free (stream_name);
+ mem_free (stream_name);
return (NULL);
}
stream = fopen (stream_name, "w");
@@ -233,7 +239,7 @@ get_export_stream (export_type_t type)
(void)wgetch (win[STA].p);
}
}
- free (stream_name);
+ mem_free (stream_name);
return (stream);
}
@@ -291,41 +297,41 @@ foreach_date_dump (const long date_end, struct rpt_s *rpt, struct days_s *exc,
static void
ical_export_valarm (FILE *stream)
{
- fprintf (stream, "BEGIN:VALARM\n");
+ (void)fprintf (stream, "BEGIN:VALARM\n");
pthread_mutex_lock (&nbar->mutex);
- fprintf (stream, "TRIGGER:-P%dS\n", nbar->cntdwn);
+ (void)fprintf (stream, "TRIGGER:-P%dS\n", nbar->cntdwn);
pthread_mutex_unlock (&nbar->mutex);
- fprintf (stream, "ACTION:DISPLAY\n");
- fprintf (stream, "END:VALARM\n");
+ (void)fprintf (stream, "ACTION:DISPLAY\n");
+ (void)fprintf (stream, "END:VALARM\n");
}
/* Export header. */
static void
ical_export_header (FILE *stream)
{
- fprintf (stream, "BEGIN:VCALENDAR\n");
- fprintf (stream, "PRODID:-//calcurse//NONSGML v%s//EN\n", VERSION);
- fprintf (stream, "VERSION:2.0\n");
+ (void)fprintf (stream, "BEGIN:VCALENDAR\n");
+ (void)fprintf (stream, "PRODID:-//calcurse//NONSGML v%s//EN\n", VERSION);
+ (void)fprintf (stream, "VERSION:2.0\n");
}
static void
pcal_export_header (FILE *stream)
{
- fprintf (stream, "# calcurse pcal export\n");
- fprintf (stream, "\n# =======\n# options\n# =======\n");
- fprintf (stream, "opt -A -K -l -m -F %s\n",
- calendar_week_begins_on_monday () ?
- "Monday" : "Sunday");
- fprintf (stream, "# Display week number (i.e. 1-52) on every Monday\n");
- fprintf (stream, "all monday in all %s %%w\n", _("Week"));
- fprintf (stream, "\n");
+ (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");
}
/* Export footer. */
static void
ical_export_footer (FILE *stream)
{
- fprintf (stream, "END:VCALENDAR\n");
+ (void)fprintf (stream, "END:VCALENDAR\n");
}
static void
@@ -344,33 +350,33 @@ ical_export_recur_events (FILE *stream)
for (i = recur_elist; i != 0; i = i->next)
{
date_sec2date_fmt (i->day, ICALDATEFMT, ical_date);
- fprintf (stream, "BEGIN:VEVENT\n");
- fprintf (stream, "DTSTART:%s\n", ical_date);
- fprintf (stream, "RRULE:FREQ=%s;INTERVAL=%d",
- ical_recur_type[i->rpt->type], i->rpt->freq);
+ (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[i->rpt->type], i->rpt->freq);
if (i->rpt->until != 0)
{
date_sec2date_fmt (i->rpt->until, ICALDATEFMT, ical_date);
- fprintf (stream, ";UNTIL=%s\n", ical_date);
+ (void)fprintf (stream, ";UNTIL=%s\n", ical_date);
}
else
- fprintf (stream, "\n");
+ (void)fprintf (stream, "\n");
if (i->exc != NULL)
{
date_sec2date_fmt (i->exc->st, ICALDATEFMT, ical_date);
- fprintf (stream, "EXDATE:%s", ical_date);
+ (void)fprintf (stream, "EXDATE:%s", ical_date);
for (day = i->exc->next; day; day = day->next)
{
date_sec2date_fmt (day->st, ICALDATEFMT, ical_date);
- fprintf (stream, ",%s", ical_date);
+ (void)fprintf (stream, ",%s", ical_date);
}
- fprintf (stream, "\n");
+ (void)fprintf (stream, "\n");
}
- fprintf (stream, "SUMMARY:%s\n", i->mesg);
- fprintf (stream, "END:VEVENT\n");
+ (void)fprintf (stream, "SUMMARY:%s\n", i->mesg);
+ (void)fprintf (stream, "END:VEVENT\n");
}
}
@@ -382,7 +388,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);
- fprintf (stream, "%s %s\n", pcal_date, event_mesg);
+ (void)fprintf (stream, "%s %s\n", pcal_date, event_mesg);
}
/* Format and dump appointment data to a pcal formatted file. */
@@ -395,8 +401,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);
- fprintf (stream, "%s ", pcal_date);
- fprintf (stream, "(%s -> %s) %s\n", pcal_beg, pcal_end, apoint_mesg);
+ (void)fprintf (stream, "%s ", pcal_date);
+ (void)fprintf (stream, "(%s -> %s) %s\n", pcal_beg, pcal_end, apoint_mesg);
}
static void
@@ -405,11 +411,11 @@ pcal_export_recur_events (FILE *stream)
struct recur_event_s *i;
char pcal_date[BUFSIZ];
- fprintf (stream, "\n# =============");
- fprintf (stream, "\n# Recur. Events");
- fprintf (stream, "\n# =============\n");
- fprintf (stream,
- "# (pcal does not support from..until dates specification\n");
+ (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");
for (i = recur_elist; i != 0; i = i->next)
{
@@ -419,22 +425,22 @@ pcal_export_recur_events (FILE *stream)
{
case RECUR_DAILY:
date_sec2date_fmt (i->day, "%b %d", pcal_date);
- fprintf (stream, "all day on_or_after %s %s\n",
- pcal_date, i->mesg);
+ (void)fprintf (stream, "all day on_or_after %s %s\n",
+ pcal_date, i->mesg);
break;
case RECUR_WEEKLY:
date_sec2date_fmt (i->day, "%a", pcal_date);
- fprintf (stream, "all %s on_or_after ", pcal_date);
+ (void)fprintf (stream, "all %s on_or_after ", pcal_date);
date_sec2date_fmt (i->day, "%b %d", pcal_date);
- fprintf (stream, "%s %s\n", pcal_date, i->mesg);
+ (void)fprintf (stream, "%s %s\n", pcal_date, i->mesg);
break;
case RECUR_MONTHLY:
date_sec2date_fmt (i->day, "%d", pcal_date);
- fprintf (stream, "day on all %s %s\n", pcal_date, i->mesg);
+ (void)fprintf (stream, "day on all %s %s\n", pcal_date, i->mesg);
break;
case RECUR_YEARLY:
date_sec2date_fmt (i->day, "%b %d", pcal_date);
- fprintf (stream, "%s %s\n", pcal_date, i->mesg);
+ (void)fprintf (stream, "%s %s\n", pcal_date, i->mesg);
break;
default:
EXIT (_("incoherent repetition type"));
@@ -462,10 +468,10 @@ ical_export_events (FILE *stream)
for (i = eventlist; i != 0; i = i->next)
{
date_sec2date_fmt (i->day, ICALDATEFMT, ical_date);
- fprintf (stream, "BEGIN:VEVENT\n");
- fprintf (stream, "DTSTART:%s\n", ical_date);
- fprintf (stream, "SUMMARY:%s\n", i->mesg);
- fprintf (stream, "END:VEVENT\n");
+ (void)fprintf (stream, "BEGIN:VEVENT\n");
+ (void)fprintf (stream, "DTSTART:%s\n", ical_date);
+ (void)fprintf (stream, "SUMMARY:%s\n", i->mesg);
+ (void)fprintf (stream, "END:VEVENT\n");
}
}
@@ -474,10 +480,10 @@ pcal_export_events (FILE *stream)
{
struct event_s *i;
- fprintf (stream, "\n# ======\n# Events\n# ======\n");
+ (void)fprintf (stream, "\n# ======\n# Events\n# ======\n");
for (i = eventlist; i != 0; i = i->next)
pcal_dump_event (stream, i->day, 0, i->mesg);
- fprintf (stream, "\n");
+ (void)fprintf (stream, "\n");
}
/* Export recurrent appointments. */
@@ -493,36 +499,36 @@ ical_export_recur_apoints (FILE *stream)
for (i = recur_alist_p->root; i != 0; i = i->next)
{
date_sec2date_fmt (i->start, ICALDATETIMEFMT, ical_datetime);
- fprintf (stream, "BEGIN:VEVENT\n");
- fprintf (stream, "DTSTART:%s\n", ical_datetime);
- fprintf (stream, "DURATION:P%ldS\n", i->dur);
- fprintf (stream, "RRULE:FREQ=%s;INTERVAL=%d",
- ical_recur_type[i->rpt->type], i->rpt->freq);
+ (void)fprintf (stream, "BEGIN:VEVENT\n");
+ (void)fprintf (stream, "DTSTART:%s\n", ical_datetime);
+ (void)fprintf (stream, "DURATION:P%ldS\n", i->dur);
+ (void)fprintf (stream, "RRULE:FREQ=%s;INTERVAL=%d",
+ ical_recur_type[i->rpt->type], i->rpt->freq);
if (i->rpt->until != 0)
{
date_sec2date_fmt (i->rpt->until + HOURINSEC, ICALDATEFMT, ical_date);
- fprintf (stream, ";UNTIL=%s\n", ical_date);
+ (void)fprintf (stream, ";UNTIL=%s\n", ical_date);
}
else
- fprintf (stream, "\n");
+ (void)fprintf (stream, "\n");
if (i->exc != NULL)
{
date_sec2date_fmt (i->exc->st, ICALDATEFMT, ical_date);
- fprintf (stream, "EXDATE:%s", ical_date);
+ (void)fprintf (stream, "EXDATE:%s", ical_date);
for (day = i->exc->next; day; day = day->next)
{
date_sec2date_fmt (day->st, ICALDATEFMT, ical_date);
- fprintf (stream, ",%s", ical_date);
+ (void)fprintf (stream, ",%s", ical_date);
}
- fprintf (stream, "\n");
+ (void)fprintf (stream, "\n");
}
- fprintf (stream, "SUMMARY:%s\n", i->mesg);
+ (void)fprintf (stream, "SUMMARY:%s\n", i->mesg);
if (i->state & APOINT_NOTIFY)
ical_export_valarm (stream);
- fprintf (stream, "END:VEVENT\n");
+ (void)fprintf (stream, "END:VEVENT\n");
}
pthread_mutex_unlock (&(recur_alist_p->mutex));
}
@@ -533,11 +539,11 @@ pcal_export_recur_apoints (FILE *stream)
recur_apoint_llist_node_t *i;
char pcal_date[BUFSIZ], pcal_beg[BUFSIZ], pcal_end[BUFSIZ];
- fprintf (stream, "\n# ==============");
- fprintf (stream, "\n# Recur. Apoints");
- fprintf (stream, "\n# ==============\n");
- fprintf (stream,
- "# (pcal does not support from..until dates specification\n");
+ (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");
for (i = recur_alist_p->root; i != 0; i = i->next)
{
@@ -549,25 +555,25 @@ pcal_export_recur_apoints (FILE *stream)
{
case RECUR_DAILY:
date_sec2date_fmt (i->start, "%b %d", pcal_date);
- fprintf (stream, "all day on_or_after %s (%s -> %s) %s\n",
- pcal_date, pcal_beg, pcal_end, i->mesg);
+ (void)fprintf (stream, "all day on_or_after %s (%s -> %s) %s\n",
+ pcal_date, pcal_beg, pcal_end, i->mesg);
break;
case RECUR_WEEKLY:
date_sec2date_fmt (i->start, "%a", pcal_date);
- fprintf (stream, "all %s on_or_after ", pcal_date);
+ (void)fprintf (stream, "all %s on_or_after ", pcal_date);
date_sec2date_fmt (i->start, "%b %d", pcal_date);
- fprintf (stream, "%s (%s -> %s) %s\n", pcal_date,
- pcal_beg, pcal_end, i->mesg);
+ (void)fprintf (stream, "%s (%s -> %s) %s\n", pcal_date,
+ pcal_beg, pcal_end, i->mesg);
break;
case RECUR_MONTHLY:
date_sec2date_fmt (i->start, "%d", pcal_date);
- fprintf (stream, "day on all %s (%s -> %s) %s\n", pcal_date,
- pcal_beg, pcal_end, i->mesg);
+ (void)fprintf (stream, "day on all %s (%s -> %s) %s\n",
+ pcal_date, pcal_beg, pcal_end, i->mesg);
break;
case RECUR_YEARLY:
date_sec2date_fmt (i->start, "%b %d", pcal_date);
- fprintf (stream, "%s (%s -> %s) %s\n", pcal_date,
- pcal_beg, pcal_end, i->mesg);
+ (void)fprintf (stream, "%s (%s -> %s) %s\n", pcal_date,
+ pcal_beg, pcal_end, i->mesg);
break;
default:
EXIT (_("incoherent repetition type"));
@@ -596,13 +602,13 @@ ical_export_apoints (FILE *stream)
for (i = alist_p->root; i != 0; i = i->next)
{
date_sec2date_fmt (i->start, ICALDATETIMEFMT, ical_datetime);
- fprintf (stream, "BEGIN:VEVENT\n");
- fprintf (stream, "DTSTART:%s\n", ical_datetime);
- fprintf (stream, "DURATION:P%ldS\n", i->dur);
- fprintf (stream, "SUMMARY:%s\n", i->mesg);
+ (void)fprintf (stream, "BEGIN:VEVENT\n");
+ (void)fprintf (stream, "DTSTART:%s\n", ical_datetime);
+ (void)fprintf (stream, "DURATION:P%ldS\n", i->dur);
+ (void)fprintf (stream, "SUMMARY:%s\n", i->mesg);
if (i->state & APOINT_NOTIFY)
ical_export_valarm (stream);
- fprintf (stream, "END:VEVENT\n");
+ (void)fprintf (stream, "END:VEVENT\n");
}
pthread_mutex_unlock (&(alist_p->mutex));
}
@@ -610,14 +616,14 @@ ical_export_apoints (FILE *stream)
static void
pcal_export_apoints (FILE *stream)
{
- fprintf (stream, "\n# ============\n# Appointments\n# ============\n");
apoint_llist_node_t *i;
+ (void)fprintf (stream, "\n# ============\n# Appointments\n# ============\n");
pthread_mutex_lock (&(alist_p->mutex));
for (i = alist_p->root; i != 0; i = i->next)
pcal_dump_apoint (stream, i->start, i->dur, i->mesg);
pthread_mutex_unlock (&(alist_p->mutex));
- fprintf (stream, "\n");
+ (void)fprintf (stream, "\n");
}
/* Export todo items. */
@@ -628,10 +634,10 @@ ical_export_todo (FILE *stream)
for (i = todolist; i != 0; i = i->next)
{
- fprintf (stream, "BEGIN:VTODO\n");
- fprintf (stream, "PRIORITY:%d\n", i->id);
- fprintf (stream, "SUMMARY:%s\n", i->mesg);
- fprintf (stream, "END:VTODO\n");
+ (void)fprintf (stream, "BEGIN:VTODO\n");
+ (void)fprintf (stream, "PRIORITY:%d\n", i->id);
+ (void)fprintf (stream, "SUMMARY:%s\n", i->mesg);
+ (void)fprintf (stream, "END:VTODO\n");
}
}
@@ -640,13 +646,13 @@ pcal_export_todo (FILE *stream)
{
struct todo_s *i;
- fprintf (stream, "#\n# Todos\n#\n");
+ (void)fprintf (stream, "#\n# Todos\n#\n");
for (i = todolist; i != 0; i = i->next)
{
- fprintf (stream, "note all ");
- fprintf (stream, "%d. %s\n", i->id, i->mesg);
+ (void)fprintf (stream, "note all ");
+ (void)fprintf (stream, "%d. %s\n", i->id, i->mesg);
}
- fprintf (stream, "\n");
+ (void)fprintf (stream, "\n");
}
/*
@@ -667,12 +673,12 @@ io_init (char *cfile, char *datadir)
if (datadir != NULL)
{
home = datadir;
- 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);
+ (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);
}
else
{
@@ -681,19 +687,19 @@ io_init (char *cfile, char *datadir)
{
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_notes, BUFSIZ, "%s/" NOTES_DIR, 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_notes, BUFSIZ, "%s/" NOTES_DIR, home);
if (cfile == NULL)
{
- snprintf (path_apts, BUFSIZ, "%s/" APTS_PATH, home);
+ (void)snprintf (path_apts, BUFSIZ, "%s/" APTS_PATH, home);
}
else
{
- snprintf (apts_file, BUFSIZ, "%s", cfile);
- strncpy (path_apts, apts_file, BUFSIZ);
+ (void)snprintf (apts_file, BUFSIZ, "%s", cfile);
+ (void)strncpy (path_apts, apts_file, BUFSIZ);
/* check if the file exists, otherwise create it */
data_file = fopen (path_apts, "r");
if (data_file == NULL)
@@ -706,7 +712,7 @@ io_init (char *cfile, char *datadir)
case 'N':
case 'n':
printf (_("aborting...\n"));
- exit (EXIT_FAILURE);
+ exit_calcurse (EXIT_FAILURE);
break;
case 'Y':
@@ -715,7 +721,7 @@ io_init (char *cfile, char *datadir)
if (data_file == NULL)
{
perror (path_apts);
- exit (EXIT_FAILURE);
+ exit_calcurse (EXIT_FAILURE);
}
else
{
@@ -726,11 +732,11 @@ io_init (char *cfile, char *datadir)
default:
printf (_("aborting...\n"));
- exit (EXIT_FAILURE);
+ exit_calcurse (EXIT_FAILURE);
break;
}
}
- fclose (data_file);
+ file_close (data_file, __FILE_POS__);
}
}
}
@@ -785,99 +791,99 @@ io_save_cal (conf_t *conf)
{
custom_color_theme_name (theme_name);
- fprintf (data_file, "%s\n", config_txt);
-
- fprintf (data_file,
- "# If this option is set to yes, "
- "automatic save is done when quitting\n");
- fprintf (data_file, "auto_save=\n");
- fprintf (data_file, "%s\n", (conf->auto_save) ? "yes" : "no");
-
- fprintf (data_file,
- "\n# If this option is set to yes, "
- "confirmation is required before quitting\n");
- fprintf (data_file, "confirm_quit=\n");
- fprintf (data_file, "%s\n", (conf->confirm_quit) ? "yes" : "no");
-
- fprintf (data_file,
- "\n# If this option is set to yes, "
- "confirmation is required before deleting an event\n");
- fprintf (data_file, "confirm_delete=\n");
- fprintf (data_file, "%s\n", (conf->confirm_delete) ? "yes" : "no");
-
- fprintf (data_file,
- "\n# If this option is set to yes, "
- "messages about loaded and saved data will not be displayed\n");
- fprintf (data_file, "skip_system_dialogs=\n");
- fprintf (data_file, "%s\n", (conf->skip_system_dialogs) ? "yes" : "no");
-
- fprintf (data_file,
- "\n# If this option is set to yes, progress bar appearing "
- "when saving data will not be displayed\n");
- fprintf (data_file, "skip_progress_bar=\n");
- fprintf (data_file, "%s\n", (conf->skip_progress_bar) ? "yes" : "no");
-
- fprintf (data_file,
- "\n# If this option is set to yes, "
- "monday is the first day of the week, else it is sunday\n");
- fprintf (data_file, "week_begins_on_monday=\n");
- fprintf (data_file, "%s\n",
- (calendar_week_begins_on_monday ())? "yes" : "no");
-
- fprintf (data_file, "\n# This is the color theme used for menus :\n");
- fprintf (data_file, "color-theme=\n");
- fprintf (data_file, "%s\n", theme_name);
-
- fprintf (data_file, "\n# This is the layout of the calendar :\n");
- fprintf (data_file, "layout=\n");
- fprintf (data_file, "%d\n", wins_layout ());
+ (void)fprintf (data_file, "%s\n", config_txt);
+
+ (void)fprintf (data_file,
+ "# If this option is set to yes, "
+ "automatic save is done when quitting\n");
+ (void)fprintf (data_file, "auto_save=\n");
+ (void)fprintf (data_file, "%s\n", (conf->auto_save) ? "yes" : "no");
+
+ (void)fprintf (data_file,
+ "\n# If this option is set to yes, "
+ "confirmation is required before quitting\n");
+ (void)fprintf (data_file, "confirm_quit=\n");
+ (void)fprintf (data_file, "%s\n", (conf->confirm_quit) ? "yes" : "no");
+
+ (void)fprintf (data_file,
+ "\n# If this option is set to yes, "
+ "confirmation is required before deleting an event\n");
+ (void)fprintf (data_file, "confirm_delete=\n");
+ (void)fprintf (data_file, "%s\n", (conf->confirm_delete) ? "yes" : "no");
+
+ (void)fprintf (data_file,
+ "\n# If this option is set to yes, "
+ "messages about loaded and saved data will not be displayed\n");
+ (void)fprintf (data_file, "skip_system_dialogs=\n");
+ (void)fprintf (data_file, "%s\n", (conf->skip_system_dialogs) ? "yes" : "no");
+
+ (void)fprintf (data_file,
+ "\n# If this option is set to yes, progress bar appearing "
+ "when saving data will not be displayed\n");
+ (void)fprintf (data_file, "skip_progress_bar=\n");
+ (void)fprintf (data_file, "%s\n", (conf->skip_progress_bar) ? "yes" : "no");
+
+ (void)fprintf (data_file,
+ "\n# If this option is set to yes, "
+ "monday is the first day of the week, else it is sunday\n");
+ (void)fprintf (data_file, "week_begins_on_monday=\n");
+ (void)fprintf (data_file, "%s\n",
+ (calendar_week_begins_on_monday ())? "yes" : "no");
+
+ (void)fprintf (data_file, "\n# This is the color theme used for menus :\n");
+ (void)fprintf (data_file, "color-theme=\n");
+ (void)fprintf (data_file, "%s\n", theme_name);
+
+ (void)fprintf (data_file, "\n# This is the layout of the calendar :\n");
+ (void)fprintf (data_file, "layout=\n");
+ (void)fprintf (data_file, "%d\n", wins_layout ());
if (ui_mode == UI_CURSES)
pthread_mutex_lock (&nbar->mutex);
- fprintf (data_file,
- "\n# If this option is set to yes, "
- "notify-bar will be displayed :\n");
- fprintf (data_file, "notify-bar_show=\n");
- fprintf (data_file, "%s\n", (nbar->show) ? "yes" : "no");
-
- fprintf (data_file,
- "\n# Format of the date to be displayed inside notify-bar :\n");
- fprintf (data_file, "notify-bar_date=\n");
- fprintf (data_file, "%s\n", nbar->datefmt);
-
- fprintf (data_file,
- "\n# Format of the time to be displayed inside notify-bar :\n");
- fprintf (data_file, "notify-bar_clock=\n");
- fprintf (data_file, "%s\n", nbar->timefmt);
-
- fprintf (data_file,
- "\n# Warn user if he has an appointment within next "
- "'notify-bar_warning' seconds :\n");
- fprintf (data_file, "notify-bar_warning=\n");
- fprintf (data_file, "%d\n", nbar->cntdwn);
-
- fprintf (data_file,
- "\n# Command used to notify user of "
- "an upcoming appointment :\n");
- fprintf (data_file, "notify-bar_command=\n");
- fprintf (data_file, "%s\n", nbar->cmd);
-
- fprintf (data_file,
- "\n# Format of the date to be displayed "
- "in non-interactive mode :\n");
- fprintf (data_file, "output_datefmt=\n");
- fprintf (data_file, "%s\n", conf->output_datefmt);
-
- fprintf (data_file,
- "\n# Format to be used when entering a date "
- "(1-mm/dd/yyyy, 2-dd/mm/yyyy, 3-yyyy/mm/dd) :\n");
- fprintf (data_file, "input_datefmt=\n");
- fprintf (data_file, "%d\n", conf->input_datefmt);
+ (void)fprintf (data_file,
+ "\n# If this option is set to yes, "
+ "notify-bar will be displayed :\n");
+ (void)fprintf (data_file, "notify-bar_show=\n");
+ (void)fprintf (data_file, "%s\n", (nbar->show) ? "yes" : "no");
+
+ (void)fprintf (data_file,
+ "\n# Format of the date to be displayed inside notify-bar :\n");
+ (void)fprintf (data_file, "notify-bar_date=\n");
+ (void)fprintf (data_file, "%s\n", nbar->datefmt);
+
+ (void)fprintf (data_file,
+ "\n# Format of the time to be displayed inside notify-bar :\n");
+ (void)fprintf (data_file, "notify-bar_clock=\n");
+ (void)fprintf (data_file, "%s\n", nbar->timefmt);
+
+ (void)fprintf (data_file,
+ "\n# Warn user if he has an appointment within next "
+ "'notify-bar_warning' seconds :\n");
+ (void)fprintf (data_file, "notify-bar_warning=\n");
+ (void)fprintf (data_file, "%d\n", nbar->cntdwn);
+
+ (void)fprintf (data_file,
+ "\n# Command used to notify user of "
+ "an upcoming appointment :\n");
+ (void)fprintf (data_file, "notify-bar_command=\n");
+ (void)fprintf (data_file, "%s\n", nbar->cmd);
+
+ (void)fprintf (data_file,
+ "\n# Format of the date to be displayed "
+ "in non-interactive mode :\n");
+ (void)fprintf (data_file, "output_datefmt=\n");
+ (void)fprintf (data_file, "%s\n", conf->output_datefmt);
+
+ (void)fprintf (data_file,
+ "\n# Format to be used when entering a date "
+ "(1-mm/dd/yyyy, 2-dd/mm/yyyy, 3-yyyy/mm/dd) :\n");
+ (void)fprintf (data_file, "input_datefmt=\n");
+ (void)fprintf (data_file, "%d\n", conf->input_datefmt);
if (ui_mode == UI_CURSES)
pthread_mutex_unlock (&nbar->mutex);
- fclose (data_file);
+ file_close (data_file, __FILE_POS__);
}
/* Save the todo data file. */
@@ -891,11 +897,11 @@ io_save_cal (conf_t *conf)
for (i = todolist; i != 0; i = i->next)
{
if (i->note != NULL)
- fprintf (data_file, "[%d]>%s %s\n", i->id, i->note, i->mesg);
+ (void)fprintf (data_file, "[%d]>%s %s\n", i->id, i->note, i->mesg);
else
- fprintf (data_file, "[%d] %s\n", i->id, i->mesg);
+ (void)fprintf (data_file, "[%d] %s\n", i->id, i->mesg);
}
- fclose (data_file);
+ file_close (data_file, __FILE_POS__);
}
/*
@@ -921,7 +927,7 @@ io_save_cal (conf_t *conf)
for (k = eventlist; k != 0; k = k->next)
event_write (k, data_file);
- fclose (data_file);
+ file_close (data_file, __FILE_POS__);
}
/* Save user-defined keys */
@@ -933,7 +939,7 @@ io_save_cal (conf_t *conf)
else
{
keys_save_bindings (data_file);
- fclose (data_file);
+ file_close (data_file, __FILE_POS__);
}
/* Print a message telling data were saved */
@@ -973,7 +979,7 @@ io_load_app (void)
c = getc (data_file);
if (c == EOF)
break;
- ungetc (c, data_file);
+ (void)ungetc (c, data_file);
/* Read the date first: it is common to both events
* and appointments.
@@ -997,7 +1003,7 @@ io_load_app (void)
{
EXIT (_("no event nor appointment found"));
}
- ungetc (c, data_file);
+ (void)ungetc (c, data_file);
/* Read the remaining informations. */
if (is_appointment)
@@ -1022,38 +1028,38 @@ io_load_app (void)
if (c == '{')
{
- ungetc (c, data_file);
+ (void)ungetc (c, data_file);
is_recursive = 1;
fscanf (data_file, "{ %d%c ", &freq, &type);
c = getc (data_file);
if (c == '}')
{ /* endless recurrent item */
- ungetc (c, data_file);
+ (void)ungetc (c, data_file);
fscanf (data_file, "} ");
until.tm_year = 0;
}
else if (c == '-')
{
- ungetc (c, data_file);
+ (void)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 == '!')
{
- ungetc (c, data_file);
+ (void)ungetc (c, data_file);
exc = recur_exc_scan (data_file);
c = getc (data_file);
}
else
{
- ungetc (c, data_file);
+ (void)ungetc (c, data_file);
fscanf (data_file, "} ");
}
}
else if (c == '!')
{ // endless item with exceptions
- ungetc (c, data_file);
+ (void)ungetc (c, data_file);
exc = recur_exc_scan (data_file);
c = getc (data_file);
until.tm_year = 0;
@@ -1065,13 +1071,13 @@ io_load_app (void)
}
}
else
- ungetc (c, data_file);
+ (void)ungetc (c, data_file);
/* Check if a note is attached to the item. */
c = getc (data_file);
if (c == '>')
{
- fgets (note, NOTESIZ + 1, data_file);
+ (void)fgets (note, NOTESIZ + 1, data_file);
note[NOTESIZ] = '\0';
notep = note;
getc (data_file);
@@ -1079,7 +1085,7 @@ io_load_app (void)
else
{
notep = NULL;
- ungetc (c, data_file);
+ (void)ungetc (c, data_file);
}
/*
@@ -1091,13 +1097,13 @@ io_load_app (void)
c = getc (data_file);
if (c == '!')
{
- ungetc (c, data_file);
+ (void)ungetc (c, data_file);
fscanf (data_file, " ! ");
state |= APOINT_NOTIFY;
}
else
{
- ungetc (c, data_file);
+ (void)ungetc (c, data_file);
fscanf (data_file, " | ");
state = 0L;
}
@@ -1129,7 +1135,7 @@ io_load_app (void)
/* NOTREACHED */
}
}
- fclose (data_file);
+ file_close (data_file, __FILE_POS__);
}
/* Load the todo data */
@@ -1139,7 +1145,7 @@ io_load_todo (void)
FILE *data_file;
char *mesg_line1 = _("Failed to open todo file");
char *mesg_line2 = _("Press [ENTER] to continue");
- char *nl;
+ char *newline;
int nb_tod = 0;
int c, id;
char buf[BUFSIZ], e_todo[BUFSIZ], note[NOTESIZ + 1];
@@ -1164,30 +1170,28 @@ io_load_todo (void)
else
{
id = 9;
- ungetc (c, data_file);
+ (void)ungetc (c, data_file);
}
/* Now read the attached note, if any. */
c = getc (data_file);
if (c == '>')
{
- fgets (note, NOTESIZ + 1, data_file);
+ (void)fgets (note, NOTESIZ + 1, data_file);
note[NOTESIZ] = '\0';
getc (data_file);
}
else
note[0] = '\0';
/* Then read todo description. */
- fgets (buf, BUFSIZ, data_file);
- nl = strchr (buf, '\n');
- if (nl)
- {
- *nl = '\0';
- }
+ (void)fgets (buf, BUFSIZ, data_file);
+ newline = strchr (buf, '\n');
+ if (newline)
+ *newline = '\0';
io_extract_data (e_todo, buf, strlen (buf));
todo_add (e_todo, id, note);
++nb_tod;
}
- fclose (data_file);
+ file_close (data_file, __FILE_POS__);
todo_set_nb (nb_tod);
}
@@ -1303,7 +1307,7 @@ io_load_keys (char *pager)
while (*p == ' ')
p++;
- strncpy (tmpbuf, p, BUFSIZ);
+ (void)strncpy (tmpbuf, p, BUFSIZ);
if (sscanf (tmpbuf, "%s", key_ch) == AWAITED)
{
int ch;
@@ -1313,8 +1317,8 @@ io_load_keys (char *pager)
char unknown_key[BUFSIZ];
skipped++;
- snprintf (unknown_key, BUFSIZ, _("Error reading key: \"%s\""),
- key_ch);
+ (void)snprintf (unknown_key, BUFSIZ,
+ _("Error reading key: \"%s\""), key_ch);
io_log_print (log, line, unknown_key);
}
else
@@ -1327,7 +1331,7 @@ io_load_keys (char *pager)
char already_assigned[BUFSIZ];
skipped++;
- snprintf (already_assigned, BUFSIZ,
+ (void)snprintf (already_assigned, BUFSIZ,
_("\"%s\" assigned multiple times!"), key_ch);
io_log_print (log, line, already_assigned);
}
@@ -1344,8 +1348,8 @@ io_load_keys (char *pager)
}
}
}
- fclose (keyfp);
- fclose (log->fd);
+ file_close (keyfp, __FILE_POS__);
+ file_close (log->fd, __FILE_POS__);
if (skipped > 0)
{
char *view_log =
@@ -1369,9 +1373,9 @@ check_directory (char *dir, int *missing)
{
if (errno != EEXIST)
{
- fprintf (stderr, _("FATAL ERROR: could not create %s: %s\n"),
- dir, strerror (errno));
- exit (EXIT_FAILURE);
+ (void)fprintf (stderr, _("FATAL ERROR: could not create %s: %s\n"),
+ dir, strerror (errno));
+ exit_calcurse (EXIT_FAILURE);
}
}
else
@@ -1389,12 +1393,12 @@ check_file (char *file, int *missing)
(*missing)++;
if ((fd = fopen (file, "w")) == NULL)
{
- fprintf (stderr, _("FATAL ERROR: could not create %s: %s\n"),
- file, strerror (errno));
- exit (EXIT_FAILURE);
+ (void)fprintf (stderr, _("FATAL ERROR: could not create %s: %s\n"),
+ file, strerror (errno));
+ exit_calcurse (EXIT_FAILURE);
}
}
- fclose (fd);
+ file_close (fd, __FILE_POS__);
}
/*
@@ -1499,7 +1503,7 @@ io_export_data (export_type_t type, conf_t *conf)
cb_export_footer[type] (stream);
if (stream != stdout)
- fclose (stream);
+ file_close (stream, __FILE_POS__);
if (!conf->skip_system_dialogs && ui_mode == UI_CURSES)
{
@@ -1553,7 +1557,7 @@ ical_log_init (FILE *log, float version)
"+-------------------------------------------------------------------+\n\n";
if (log)
- fprintf (log, header, version);
+ (void)fprintf (log, header, version);
}
/*
@@ -1569,7 +1573,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)
- fprintf (log, "%s [%d]: %s\n", typestr[type], lineno, msg);
+ (void)fprintf (log, "%s [%d]: %s\n", typestr[type], lineno, msg);
}
static void
@@ -1724,14 +1728,14 @@ ical_unfold_content (FILE *fd, char *line, unsigned *lineno)
return NULL;
}
newsize = strlen (content) + strlen (tmpline) + 1;
- if ((rline = realloc (content, newsize)) == NULL)
+ if ((rline = mem_realloc (content, newsize)) == NULL)
{
mem_free (content);
mem_free (tmpline);
return NULL;
}
content = rline;
- strncat (content, tmpline, BUFSIZ);
+ (void)strncat (content, tmpline, BUFSIZ);
mem_free (tmpline);
}
else
@@ -1743,7 +1747,7 @@ ical_unfold_content (FILE *fd, char *line, unsigned *lineno)
}
else
{
- ungetc (c, fd);
+ (void)ungetc (c, fd);
return content;
}
}
@@ -1756,7 +1760,7 @@ ical_chk_header (FILE *fd, unsigned *lineno)
const string_t icalheader = STRING_BUILD ("BEGIN:VCALENDAR");
char buf[BUFSIZ];
- fgets (buf, BUFSIZ, fd);
+ (void)fgets (buf, BUFSIZ, fd);
(*lineno)++;
if (buf == NULL
|| strncmp (str_toupper (buf), icalheader.str, icalheader.len) != 0)
@@ -2021,7 +2025,7 @@ ical_read_rrule (FILE *log, char *rrulestr, unsigned *noskipped,
char freqstr[BUFSIZ];
p++;
- rpt = malloc (sizeof (ical_rpt_t));
+ rpt = mem_malloc (sizeof (ical_rpt_t));
bzero (rpt, sizeof (ical_rpt_t));
if (sscanf (p, "FREQ=%s", freqstr) != 1)
{
@@ -2124,7 +2128,7 @@ ical_add_exc (days_t **exc_head, long date)
{
struct days_s *exc;
- exc = malloc (sizeof (struct days_s));
+ exc = mem_malloc (sizeof (struct days_s));
exc->st = date;
exc->next = *exc_head;
*exc_head = exc;
@@ -2152,7 +2156,7 @@ ical_read_exdate (FILE *log, char *exstr, unsigned *noskipped,
char buf[BUFSIZ];
const int buflen = q - p;
- strncpy (buf, p, buflen);
+ (void)strncpy (buf, p, buflen);
buf[buflen] = '\0';
date = ical_datetime2long (buf, NULL);
ical_add_exc (&exc, date);
@@ -2185,7 +2189,7 @@ ical_read_note (char *first_line, FILE *fdi, unsigned *noskipped,
EXIT_IF (notename == NULL,
_("Warning: could not create new note file to store "
"description. Aborting...\n"));
- snprintf (fullnotename, BUFSIZ, "%s%s", path_notes, notename);
+ (void)snprintf (fullnotename, BUFSIZ, "%s%s", path_notes, notename);
fdo = fopen (fullnotename, "w");
EXIT_IF (fdo == NULL, _("Warning: could not open %s, Aborting..."),
fullnotename);
@@ -2195,21 +2199,21 @@ ical_read_note (char *first_line, FILE *fdi, unsigned *noskipped,
{
ical_log (log, item_type, itemline,
_("could not get entire item description."));
- fclose (fdo);
+ file_close (fdo, __FILE_POS__);
erase_note (&notename, ERASE_FORCE);
(*noskipped)++;
return NULL;
}
else if (strlen (notestr) == 0)
{
- fclose (fdo);
+ file_close (fdo, __FILE_POS__);
erase_note (&notename, ERASE_FORCE);
return NULL;
}
else
{
- fprintf (fdo, "%s", notestr);
- fclose (fdo);
+ (void)fprintf (fdo, "%s", notestr);
+ file_close (fdo, __FILE_POS__);
mem_free (notestr);
return notename;
}
@@ -2529,7 +2533,7 @@ get_import_stream (export_type_t type)
int cancel;
stream = NULL;
- stream_name = malloc (BUFSIZ);
+ stream_name = mem_malloc (BUFSIZ);
bzero (stream_name, BUFSIZ);
while (stream == NULL)
{
@@ -2606,7 +2610,7 @@ io_import_data (import_type_t type, conf_t *conf, char *stream_name)
if (log == 0)
{
if (stream != stdin)
- fclose (stream);
+ file_close (stream, __FILE_POS__);
return;
}
ical_log_init (log->fd, ical_version);
@@ -2627,15 +2631,15 @@ io_import_data (import_type_t type, conf_t *conf, char *stream_name)
}
}
if (stream != stdin)
- fclose (stream);
+ file_close (stream, __FILE_POS__);
if (ui_mode == UI_CURSES && !conf->skip_system_dialogs)
{
char read[BUFSIZ], stat[BUFSIZ];
- snprintf (read, BUFSIZ, proc_report, stats.lines);
- snprintf (stat, BUFSIZ, lines_stats_interactive, stats.apoints,
- stats.events, stats.todos, stats.skipped);
+ (void)snprintf (read, BUFSIZ, proc_report, stats.lines);
+ (void)snprintf (stat, BUFSIZ, lines_stats_interactive, stats.apoints,
+ stats.events, stats.todos, stats.skipped);
status_mesg (read, stat);
(void)wgetch (win[STA].p);
}
@@ -2651,7 +2655,7 @@ io_import_data (import_type_t type, conf_t *conf, char *stream_name)
/* User has the choice to look at the log file if some items could not be
imported.
*/
- fclose (log->fd);
+ file_close (log->fd, __FILE_POS__);
if (stats.skipped > 0)
{
char *view_log = _("Some items could not be imported, see log file ?");
@@ -2671,10 +2675,10 @@ io_log_init (void)
logname = new_tempfile (logprefix, NOTESIZ);
RETVAL_IF (logname == 0, 0,
_("Warning: could not create temporary log file, Aborting..."));
- log = malloc (sizeof (io_file_t));
+ log = mem_malloc (sizeof (io_file_t));
RETVAL_IF (log == 0, 0,
_("Warning: could not open temporary log file, Aborting..."));
- snprintf (log->name, sizeof (log->name), "%s%s", logprefix, logname);
+ (void)snprintf (log->name, sizeof (log->name), "%s%s", logprefix, logname);
mem_free (logname);
log->fd = fopen (log->name, "w");
if (log->fd == 0)
@@ -2691,7 +2695,7 @@ void
io_log_print (io_file_t *log, int line, char *msg)
{
if (log && log->fd)
- fprintf (log->fd, "line %d: %s\n", line, msg);
+ (void)fprintf (log->fd, "line %d: %s\n", line, msg);
}
void
@@ -2709,8 +2713,8 @@ io_log_display (io_file_t *log, char *msg, char *pager)
{
char cmd[BUFSIZ];
- snprintf (cmd, BUFSIZ, "%s %s", pager, log->name);
- system (cmd);
+ (void)snprintf (cmd, BUFSIZ, "%s %s", pager, log->name);
+ (void)system (cmd);
}
}
else
diff --git a/src/keys.c b/src/keys.c
index 790a03a..bfebe24 100755
--- a/src/keys.c
+++ b/src/keys.c
@@ -1,4 +1,4 @@
-/* $calcurse: keys.c,v 1.10 2008/12/15 20:02:00 culot Exp $ */
+/* $calcurse: keys.c,v 1.11 2008/12/28 13:13:59 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -30,6 +30,7 @@
#include "i18n.h"
#include "utils.h"
#include "custom.h"
+#include "mem.h"
#include "keys.h"
#define MAXKEYVAL KEY_MAX /* ncurses defines KEY_MAX as maximum key value */
@@ -113,7 +114,7 @@ dump_intro (FILE *fd)
"# A description of what each ACTION keyword is used for is available\n"
"# from calcurse online configuration menu.\n");
- fprintf (fd, "%s\n", intro);
+ (void)fprintf (fd, "%s\n", intro);
}
void
@@ -127,6 +128,28 @@ keys_init (void)
}
void
+keys_free (void)
+{
+ struct key_str_s *o, **i;
+ int key;
+
+ for (key = 0; key < NBKEYS; key++)
+ {
+ if (keys[key] == 0)
+ continue;
+
+ i = &keys[key];
+ for (o = keys[key]; o; o = o->next)
+ {
+ *i = o->next;
+ mem_free (o->str);
+ mem_free (o);
+ i = &o->next;
+ }
+ }
+}
+
+void
keys_dump_defaults (char *file)
{
FILE *fd;
@@ -137,8 +160,8 @@ keys_dump_defaults (char *file)
dump_intro (fd);
for (i = 0; i < NBKEYS; i++)
- fprintf (fd, "%s %s\n", keydef[i].label, keydef[i].binding);
- fclose (fd);
+ (void)fprintf (fd, "%s %s\n", keydef[i].label, keydef[i].binding);
+ file_close (fd, __FILE_POS__);
}
char *
@@ -182,8 +205,8 @@ add_key_str (keys_e action, int key)
if (action < 0 || action > NBKEYS)
return;
- new = malloc (sizeof (struct key_str_s));
- new->str = strdup (keys_int2str (key));
+ new = mem_malloc (sizeof (struct key_str_s));
+ new->str = mem_strdup (keys_int2str (key));
new->next = NULL;
i = &keys[action];
for (;;)
@@ -221,20 +244,17 @@ del_key_str (keys_e action, int key)
{
struct key_str_s *old, **i;
char oldstr[BUFSIZ];
- int oldstrlen;
if (action < 0 || action > NBKEYS)
return;
- strncpy (oldstr, keys_int2str (key), BUFSIZ);
- oldstrlen = strlen (oldstr);
+ (void)strncpy (oldstr, keys_int2str (key), BUFSIZ);
for (i = &keys[action]; *i; i = &(*i)->next)
{
- if (strlen ((*i)->str) == oldstrlen
- && !(strncmp ((*i)->str, oldstr, oldstrlen)))
+ if (!strcmp ((*i)->str, oldstr))
{
- old = (*i);
- (*i) = old->next;
+ old = *i;
+ *i = old->next;
mem_free (old->str);
mem_free (old);
break;
@@ -367,8 +387,8 @@ keys_action_allkeys (keys_e action)
for (i = keys[action]; i; i = i->next)
{
const int MAXLEN = sizeof (keystr) - 1 - strlen (keystr);
- strncat (keystr, i->str, MAXLEN - 1);
- strncat (keystr, CHAR_SPACE, 1);
+ (void)strncat (keystr, i->str, MAXLEN - 1);
+ (void)strncat (keystr, CHAR_SPACE, 1);
}
return keystr;
@@ -388,18 +408,18 @@ keys_format_label (char *key, int keylen)
bzero (fmtkey, sizeof (fmtkey));
if (len == 0)
- snprintf (fmtkey, sizeof (fmtkey), "?");
+ (void)snprintf (fmtkey, sizeof (fmtkey), "?");
else if (len <= keylen)
{
for (i = 0; i < keylen - len; i++)
fmtkey[i] = ' ';
- strncat (fmtkey, key, keylen);
+ (void)strncat (fmtkey, key, keylen);
}
else
{
for (i = 0; i < keylen - 1; i++)
fmtkey[i] = key[i];
- strncat (fmtkey, dot, strlen (dot));
+ (void)strncat (fmtkey, dot, strlen (dot));
}
return fmtkey;
}
@@ -423,14 +443,15 @@ keys_display_bindings_bar (WINDOW *win, binding_t **binding, int first_key,
const int KEY_POS = j * cmdlen;
const int LABEL_POS = j * cmdlen + KEYS_KEYLEN + 1;
- strncpy (key, keys_action_firstkey (binding[i]->action), KEYS_KEYLEN);
+ (void)strncpy (key, keys_action_firstkey (binding[i]->action),
+ KEYS_KEYLEN);
fmtkey = keys_format_label (key, KEYS_KEYLEN);
custom_apply_attr (win, ATTR_HIGHEST);
mvwprintw (win, 0, KEY_POS, fmtkey);
if (i + 1 != last_key)
{
- strncpy (key, keys_action_firstkey (binding[i + 1]->action),
- KEYS_KEYLEN);
+ (void)strncpy (key, keys_action_firstkey (binding[i + 1]->action),
+ KEYS_KEYLEN);
fmtkey = keys_format_label (key, KEYS_KEYLEN);
mvwprintw (win, 1, KEY_POS, fmtkey);
}
@@ -541,7 +562,7 @@ keys_popup_info (keys_e key)
#define WINCOL (col - 4)
infowin = popup (WINROW, WINCOL, (row - WINROW) / 2, (col - WINCOL) / 2,
keydef[key].label, info[key], 1);
- keys_getch (infowin);
+ (void)keys_getch (infowin);
delwin (infowin);
#undef WINROW
#undef WINCOL
@@ -555,7 +576,7 @@ keys_save_bindings (FILE *fd)
EXIT_IF (fd == NULL, _("FATAL ERROR: null file pointer."));
dump_intro (fd);
for (i = 0; i < NBKEYS; i++)
- fprintf (fd, "%s %s\n", keydef[i].label, keys_action_allkeys (i));
+ (void)fprintf (fd, "%s %s\n", keydef[i].label, keys_action_allkeys (i));
}
int
diff --git a/src/keys.h b/src/keys.h
index 1ed24a4..6c4e020 100755
--- a/src/keys.h
+++ b/src/keys.h
@@ -1,4 +1,4 @@
-/* $calcurse: keys.h,v 1.6 2008/12/08 19:17:07 culot Exp $ */
+/* $calcurse: keys.h,v 1.7 2008/12/28 13:13:59 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -90,6 +90,7 @@ typedef struct {
} binding_t;
void keys_init (void);
+void keys_free (void);
void keys_dump_defaults (char *);
char *keys_get_label (keys_e);
keys_e keys_get_action (int);
diff --git a/src/notify.c b/src/notify.c
index 49c589e..5f03a6d 100755
--- a/src/notify.c
+++ b/src/notify.c
@@ -1,4 +1,4 @@
-/* $calcurse: notify.c,v 1.32 2008/12/18 20:38:52 culot Exp $ */
+/* $calcurse: notify.c,v 1.33 2008/12/28 13:13:59 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -29,10 +29,15 @@
#include <string.h>
#include <unistd.h>
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
#include "i18n.h"
#include "utils.h"
#include "custom.h"
#include "keys.h"
+#include "mem.h"
#include "notify.h"
static struct notify_vars_s *notify = NULL;
@@ -61,13 +66,13 @@ notify_init_vars (void)
char *date_format = "%a %F";
char *cmd = "printf '\\a'";
- nbar = (struct nbar_s *) malloc (sizeof (struct nbar_s));
+ nbar = (struct nbar_s *) mem_malloc (sizeof (struct nbar_s));
pthread_mutex_init (&nbar->mutex, NULL);
nbar->show = 1;
nbar->cntdwn = 300;
- strncpy (nbar->datefmt, date_format, strlen (date_format) + 1);
- strncpy (nbar->timefmt, time_format, strlen (time_format) + 1);
- strncpy (nbar->cmd, cmd, strlen (cmd) + 1);
+ (void)strncpy (nbar->datefmt, date_format, strlen (date_format) + 1);
+ (void)strncpy (nbar->timefmt, time_format, strlen (time_format) + 1);
+ (void)strncpy (nbar->cmd, cmd, strlen (cmd) + 1);
if ((nbar->shell = getenv ("SHELL")) == NULL)
nbar->shell = "/bin/sh";
@@ -77,6 +82,12 @@ notify_init_vars (void)
PTHREAD_CREATE_DETACHED);
}
+void
+notify_free_vars (void)
+{
+ mem_free (nbar);
+}
+
/* Extract the appointment file name from the complete file path. */
static void
extract_aptsfile (void)
@@ -101,8 +112,8 @@ extract_aptsfile (void)
void
notify_init_bar (void)
{
- notify = (struct notify_vars_s *) malloc (sizeof (struct notify_vars_s));
- notify_app = (struct notify_app_s *) malloc (sizeof (struct notify_app_s));
+ notify = (struct notify_vars_s *) mem_malloc (sizeof (struct notify_vars_s));
+ notify_app = (struct notify_app_s *) mem_malloc (sizeof (struct notify_app_s));
pthread_mutex_init (&notify->mutex, NULL);
pthread_mutex_init (&notify_app->mutex, NULL);
notify_app->got_app = 0;
@@ -110,6 +121,13 @@ notify_init_bar (void)
extract_aptsfile ();
}
+void
+notify_free_bar (void)
+{
+ mem_free (notify_app);
+ mem_free (notify);
+}
+
/* Stop the notify-bar main thread. */
void
notify_stop_main_thread (void)
@@ -177,7 +195,7 @@ notify_update_bar (void)
if (strlen (notify_app->txt) > txt_max_len)
{
too_long = 1;
- strncpy (buf, notify_app->txt, txt_max_len - 3);
+ (void)strncpy (buf, notify_app->txt, txt_max_len - 3);
buf[txt_max_len - 3] = '\0';
}
time_left = notify_app->time - notify->time_in_sec;
@@ -229,6 +247,7 @@ notify_update_bar (void)
}
/* Update the notication bar content */
+/* ARGSUSED0 */
static void *
notify_main_thread (void *arg)
{
@@ -253,7 +272,7 @@ notify_main_thread (void *arg)
pthread_mutex_unlock (&nbar->mutex);
pthread_mutex_unlock (&notify->mutex);
notify_update_bar ();
- sleep (thread_sleep);
+ (void)sleep (thread_sleep);
elapse += thread_sleep;
if (elapse >= check_app)
{
@@ -269,6 +288,7 @@ notify_main_thread (void *arg)
}
/* Look for the next appointment within the next 24 hours. */
+/* ARGSUSED0 */
static void *
notify_thread_app (void *arg)
{
@@ -300,7 +320,7 @@ notify_thread_app (void *arg)
pthread_mutex_unlock (&notify_app->mutex);
if (tmp_app.txt != NULL)
- free (tmp_app.txt);
+ mem_free (tmp_app.txt);
notify_update_bar ();
pthread_exit ((void *) 0);
@@ -452,33 +472,33 @@ notify_print_options (WINDOW *optwin, int col)
y_offset = 3;
maxcol = col - 2;
- strncpy (opt[SHOW].name, _("notify-bar_show = "), BUFSIZ);
- strncpy (opt[DATE].name, _("notify-bar_date = "), BUFSIZ);
- strncpy (opt[CLOCK].name, _("notify-bar_clock = "), BUFSIZ);
- strncpy (opt[WARN].name, _("notify-bar_warning = "), BUFSIZ);
- strncpy (opt[CMD].name, _("notify-bar_command = "), BUFSIZ);
-
- strncpy (opt[SHOW].desc,
- _("(if set to YES, notify-bar will be displayed)"), BUFSIZ);
- strncpy (opt[DATE].desc,
- _("(Format of the date to be displayed inside notify-bar)"),
- BUFSIZ);
- strncpy (opt[CLOCK].desc,
- _("(Format of the time to be displayed inside notify-bar)"),
- BUFSIZ);
- strncpy (opt[WARN].desc,
- _("(Warn user if an appointment is within next 'notify-bar_warning'"
- " seconds)"), BUFSIZ);
- strncpy (opt[CMD].desc,
- _("(Command used to notify user of an upcoming appointment)"),
- BUFSIZ);
+ (void)strncpy (opt[SHOW].name, _("notify-bar_show = "), BUFSIZ);
+ (void)strncpy (opt[DATE].name, _("notify-bar_date = "), BUFSIZ);
+ (void)strncpy (opt[CLOCK].name, _("notify-bar_clock = "), BUFSIZ);
+ (void)strncpy (opt[WARN].name, _("notify-bar_warning = "), BUFSIZ);
+ (void)strncpy (opt[CMD].name, _("notify-bar_command = "), BUFSIZ);
+
+ (void)strncpy (opt[SHOW].desc,
+ _("(if set to YES, notify-bar will be displayed)"), BUFSIZ);
+ (void)strncpy (opt[DATE].desc,
+ _("(Format of the date to be displayed inside notify-bar)"),
+ BUFSIZ);
+ (void)strncpy (opt[CLOCK].desc,
+ _("(Format of the time to be displayed inside notify-bar)"),
+ BUFSIZ);
+ (void)strncpy (opt[WARN].desc,
+ _("(Warn user if an appointment is within next "
+ "'notify-bar_warning' seconds)"), BUFSIZ);
+ (void)strncpy (opt[CMD].desc,
+ _("(Command used to notify user of an upcoming appointment)"),
+ BUFSIZ);
pthread_mutex_lock (&nbar->mutex);
- strncpy (opt[DATE].value, nbar->datefmt, BUFSIZ);
- strncpy (opt[CLOCK].value, nbar->timefmt, BUFSIZ);
- snprintf (opt[WARN].value, BUFSIZ, "%d", nbar->cntdwn);
- strncpy (opt[CMD].value, nbar->cmd, BUFSIZ);
+ (void)strncpy (opt[DATE].value, nbar->datefmt, BUFSIZ);
+ (void)strncpy (opt[CLOCK].value, nbar->timefmt, BUFSIZ);
+ (void)snprintf (opt[WARN].value, BUFSIZ, "%d", nbar->cntdwn);
+ (void)strncpy (opt[CMD].value, nbar->cmd, BUFSIZ);
l = strlen (opt[SHOW].name);
x = x_pos + x_offset + l;
@@ -501,7 +521,7 @@ notify_print_options (WINDOW *optwin, int col)
mvwprintw (optwin, y, x, "%s", opt[i].value);
else
{
- strncpy (buf, opt[i].value, maxlen - 1);
+ (void)strncpy (buf, opt[i].value, maxlen - 1);
buf[maxlen - 1] = '\0';
mvwprintw (optwin, y, x, "%s...", buf);
}
@@ -533,8 +553,9 @@ notify_config_bar (void)
char *cmd_str = _("Enter the notification command ");
int ch = 0, change_win = 1;
- buf = (char *) malloc (BUFSIZ);
- snprintf (label, BUFSIZ, _("CalCurse %s | notify-bar options"), VERSION);
+ buf = (char *) mem_malloc (BUFSIZ);
+ (void)snprintf (label, BUFSIZ, _("CalCurse %s | notify-bar options"),
+ VERSION);
custom_confwin_init (&conf_win, label);
while (ch != 'q')
@@ -569,12 +590,12 @@ notify_config_bar (void)
case '2':
status_mesg (date_str, "");
pthread_mutex_lock (&nbar->mutex);
- strncpy (buf, nbar->datefmt, strlen (nbar->datefmt) + 1);
+ (void)strncpy (buf, nbar->datefmt, strlen (nbar->datefmt) + 1);
pthread_mutex_unlock (&nbar->mutex);
if (updatestring (win[STA].p, &buf, 0, 1) == 0)
{
pthread_mutex_lock (&nbar->mutex);
- strncpy (nbar->datefmt, buf, strlen (buf) + 1);
+ (void)strncpy (nbar->datefmt, buf, strlen (buf) + 1);
pthread_mutex_unlock (&nbar->mutex);
}
change_win = 0;
@@ -582,12 +603,12 @@ notify_config_bar (void)
case '3':
status_mesg (time_str, "");
pthread_mutex_lock (&nbar->mutex);
- strncpy (buf, nbar->timefmt, strlen (nbar->timefmt) + 1);
+ (void)strncpy (buf, nbar->timefmt, strlen (nbar->timefmt) + 1);
pthread_mutex_unlock (&nbar->mutex);
if (updatestring (win[STA].p, &buf, 0, 1) == 0)
{
pthread_mutex_lock (&nbar->mutex);
- strncpy (nbar->timefmt, buf, strlen (buf) + 1);
+ (void)strncpy (nbar->timefmt, buf, strlen (buf) + 1);
pthread_mutex_unlock (&nbar->mutex);
}
change_win = 0;
@@ -609,18 +630,18 @@ notify_config_bar (void)
case '5':
status_mesg (cmd_str, "");
pthread_mutex_lock (&nbar->mutex);
- strncpy (buf, nbar->cmd, strlen (nbar->cmd) + 1);
+ (void)strncpy (buf, nbar->cmd, strlen (nbar->cmd) + 1);
pthread_mutex_unlock (&nbar->mutex);
if (updatestring (win[STA].p, &buf, 0, 1) == 0)
{
pthread_mutex_lock (&nbar->mutex);
- strncpy (nbar->cmd, buf, strlen (buf) + 1);
+ (void)strncpy (nbar->cmd, buf, strlen (buf) + 1);
pthread_mutex_unlock (&nbar->mutex);
}
change_win = 0;
break;
}
}
- free (buf);
+ mem_free (buf);
delwin (conf_win.p);
}
diff --git a/src/notify.h b/src/notify.h
index e1b8f00..957ec36 100755
--- a/src/notify.h
+++ b/src/notify.h
@@ -1,4 +1,4 @@
-/* $calcurse: notify.h,v 1.14 2008/04/19 21:05:15 culot Exp $ */
+/* $calcurse: notify.h,v 1.15 2008/12/28 13:13:59 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -54,7 +54,9 @@ struct notify_app_s
int notify_bar (void);
void notify_init_vars (void);
+void notify_free_vars (void);
void notify_init_bar (void);
+void notify_free_bar (void);
void notify_start_main_thread (void);
void notify_stop_main_thread (void);
void notify_reinit_bar (void);
diff --git a/src/recur.c b/src/recur.c
index 140bec5..cfc2ff3 100755
--- a/src/recur.c
+++ b/src/recur.c
@@ -1,4 +1,4 @@
-/* $calcurse: recur.c,v 1.45 2008/12/14 15:54:51 culot Exp $ */
+/* $calcurse: recur.c,v 1.46 2008/12/28 13:13:59 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -35,20 +35,55 @@
#include "notify.h"
#include "day.h"
#include "keys.h"
+#include "mem.h"
#include "recur.h"
recur_apoint_llist_t *recur_alist_p;
struct recur_event_s *recur_elist;
-int
+void
recur_apoint_llist_init (void)
{
- recur_alist_p = (recur_apoint_llist_t *)
- malloc (sizeof (recur_apoint_llist_t));
+ recur_alist_p = mem_malloc (sizeof (recur_apoint_llist_t));
recur_alist_p->root = NULL;
pthread_mutex_init (&(recur_alist_p->mutex), NULL);
+}
+
+static void
+free_exc (struct days_s *exc)
+{
+ struct days_s *o, **i;
+
+ i = &exc;
+ for (o = exc; o; o = o->next)
+ {
+ *i = o->next;
+ mem_free (o);
+ i = &(*i)->next;
+ }
+ mem_free (exc);
+}
+
+void
+recur_apoint_llist_free (void)
+{
+ recur_apoint_llist_node_t *o, **i;
- return (0);
+ i = &recur_alist_p->root;
+ for (o = recur_alist_p->root; o; o = o->next)
+ {
+ *i = o->next;
+ mem_free (o->mesg);
+ if (o->note)
+ mem_free (o->note);
+ if (o->rpt)
+ mem_free (o->rpt);
+ if (o->exc)
+ free_exc (o->exc);
+ mem_free (o);
+ i = &(*i)->next;
+ }
+ mem_free (recur_alist_p);
}
/* Insert a new recursive appointment in the general linked list */
@@ -58,10 +93,9 @@ recur_apoint_new (char *mesg, char *note, long start, long dur, char state,
{
recur_apoint_llist_node_t *o, **i;
o = (recur_apoint_llist_node_t *)
- malloc (sizeof (recur_apoint_llist_node_t));
- o->rpt = (struct rpt_s *) malloc (sizeof (struct rpt_s));
- o->mesg = (char *) malloc (strlen (mesg) + 1);
- strncpy (o->mesg, mesg, strlen (mesg) + 1);
+ mem_malloc (sizeof (recur_apoint_llist_node_t));
+ o->rpt = (struct rpt_s *) mem_malloc (sizeof (struct rpt_s));
+ o->mesg = mem_strdup (mesg);
o->note = (note != NULL) ? strdup (note) : NULL;
o->start = start;
o->state = state;
@@ -94,11 +128,10 @@ recur_event_new (char *mesg, char *note, long day, int id, int type, int freq,
long until, struct days_s *except)
{
struct recur_event_s *o, **i;
- o = (struct recur_event_s *) malloc (sizeof (struct recur_event_s));
- o->rpt = (struct rpt_s *) malloc (sizeof (struct rpt_s));
- o->mesg = (char *) malloc (strlen (mesg) + 1);
- o->note = (note != NULL) ? strdup (note) : NULL;
- strncpy (o->mesg, mesg, strlen (mesg) + 1);
+ o = (struct recur_event_s *) mem_malloc (sizeof (struct recur_event_s));
+ o->rpt = (struct rpt_s *) mem_malloc (sizeof (struct rpt_s));
+ o->mesg = mem_strdup (mesg);
+ (void)strncpy (o->mesg, mesg, strlen (mesg) + 1);
o->day = day;
o->id = id;
o->rpt->type = type;
@@ -195,7 +228,7 @@ recur_write_exc (struct days_s *exc, FILE *f)
st_mon = lt->tm_mon + 1;
st_day = lt->tm_mday;
st_year = lt->tm_year + 1900;
- fprintf (f, " !%02u/%02u/%04u", st_mon, st_day, st_year);
+ (void)fprintf (f, " !%02u/%02u/%04u", st_mon, st_day, st_year);
exc = exc->next;
}
}
@@ -214,7 +247,7 @@ recur_apoint_scan (FILE *f, struct tm start, struct tm end, char type,
lt = localtime (&t);
/* Read the appointment description */
- fgets (buf, MESG_MAXSIZE, f);
+ (void)fgets (buf, MESG_MAXSIZE, f);
nl = strchr (buf, '\n');
if (nl)
{
@@ -263,7 +296,7 @@ recur_event_scan (FILE *f, struct tm start, int id, char type, int freq,
lt = localtime (&t);
/* Read the event description */
- fgets (buf, MESG_MAXSIZE, f);
+ (void)fgets (buf, MESG_MAXSIZE, f);
nl = strchr (buf, '\n');
if (nl)
{
@@ -302,38 +335,38 @@ recur_apoint_write (recur_apoint_llist_node_t *o, FILE *f)
t = o->start;
lt = localtime (&t);
- fprintf (f, "%02u/%02u/%04u @ %02u:%02u",
- lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year,
- lt->tm_hour, lt->tm_min);
+ (void)fprintf (f, "%02u/%02u/%04u @ %02u:%02u",
+ lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year,
+ lt->tm_hour, lt->tm_min);
t = o->start + o->dur;
lt = localtime (&t);
- fprintf (f, " -> %02u/%02u/%04u @ %02u:%02u",
- lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year,
- lt->tm_hour, lt->tm_min);
+ (void)fprintf (f, " -> %02u/%02u/%04u @ %02u:%02u",
+ lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year,
+ lt->tm_hour, lt->tm_min);
t = o->rpt->until;
if (t == 0)
{ /* We have an endless recurrent appointment. */
- fprintf (f, " {%d%c", o->rpt->freq, recur_def2char (o->rpt->type));
+ (void)fprintf (f, " {%d%c", o->rpt->freq, recur_def2char (o->rpt->type));
}
else
{
lt = localtime (&t);
- fprintf (f, " {%d%c -> %02u/%02u/%04u",
- o->rpt->freq, recur_def2char (o->rpt->type),
- lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year);
+ (void)fprintf (f, " {%d%c -> %02u/%02u/%04u",
+ o->rpt->freq, recur_def2char (o->rpt->type),
+ lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year);
}
if (o->exc != 0)
recur_write_exc (o->exc, f);
- fprintf (f, "} ");
+ (void)fprintf (f, "} ");
if (o->note != NULL)
- fprintf (f, ">%s ", o->note);
+ (void)fprintf (f, ">%s ", o->note);
if (o->state & APOINT_NOTIFY)
- fprintf (f, "!");
+ (void)fprintf (f, "!");
else
- fprintf (f, "|");
- fprintf (f, "%s\n", o->mesg);
+ (void)fprintf (f, "|");
+ (void)fprintf (f, "%s\n", o->mesg);
}
/* Writting of a recursive event into file. */
@@ -353,9 +386,9 @@ recur_event_write (struct recur_event_s *o, FILE *f)
t = o->rpt->until;
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));
+ (void)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
{
@@ -363,17 +396,17 @@ recur_event_write (struct recur_event_s *o, FILE *f)
end_mon = lt->tm_mon + 1;
end_day = lt->tm_mday;
end_year = lt->tm_year + 1900;
- fprintf (f, "%02u/%02u/%04u [%d] {%d%c -> %02u/%02u/%04u",
- st_mon, st_day, st_year, o->id,
- o->rpt->freq, recur_def2char (o->rpt->type),
- end_mon, end_day, end_year);
+ (void)fprintf (f, "%02u/%02u/%04u [%d] {%d%c -> %02u/%02u/%04u",
+ st_mon, st_day, st_year, o->id,
+ o->rpt->freq, recur_def2char (o->rpt->type),
+ end_mon, end_day, end_year);
}
if (o->exc != 0)
recur_write_exc (o->exc, f);
- fprintf (f, "} ");
+ (void)fprintf (f, "} ");
if (o->note != NULL)
- fprintf (f, ">%s ", o->note);
- fprintf (f, "%s\n", o->mesg);
+ (void)fprintf (f, ">%s ", o->note);
+ (void)fprintf (f, "%s\n", o->mesg);
}
/* Write recursive items to file. */
@@ -503,17 +536,17 @@ recur_event_erase (long start, unsigned num, unsigned delete_whole,
else
{
*iptr = i->next;
- free (i->mesg);
- free (i->rpt);
- free (i->exc);
+ mem_free (i->mesg);
+ mem_free (i->rpt);
+ mem_free (i->exc);
erase_note (&i->note, flag);
- free (i);
+ mem_free (i);
}
return;
}
else
{
- o = (struct days_s *) malloc (sizeof (struct days_s));
+ o = (struct days_s *) mem_malloc (sizeof (struct days_s));
o->st = start;
j = &i->exc;
for (;;)
@@ -568,11 +601,11 @@ recur_apoint_erase (long start, unsigned num, unsigned delete_whole,
else
{
*iptr = i->next;
- free (i->mesg);
- free (i->rpt);
- free (i->exc);
+ mem_free (i->mesg);
+ mem_free (i->rpt);
+ mem_free (i->exc);
erase_note (&i->note, flag);
- free (i);
+ mem_free (i);
pthread_mutex_unlock (&(recur_alist_p->mutex));
if (need_check_notify)
notify_check_next_app ();
@@ -581,7 +614,7 @@ recur_apoint_erase (long start, unsigned num, unsigned delete_whole,
}
else
{
- o = (struct days_s *) malloc (sizeof (struct days_s));
+ o = (struct days_s *) mem_malloc (sizeof (struct days_s));
o->st = start;
j = &i->exc;
for (;;)
@@ -692,8 +725,8 @@ recur_repeat_item (conf_t *conf)
while (!date_entered)
{
- snprintf (outstr, BUFSIZ, mesg_until_1,
- DATEFMT_DESC (conf->input_datefmt));
+ (void)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)
{
@@ -726,8 +759,8 @@ recur_repeat_item (conf_t *conf)
}
else
{
- snprintf (outstr, BUFSIZ, mesg_wrong_2,
- DATEFMT_DESC (conf->input_datefmt));
+ (void)snprintf (outstr, BUFSIZ, mesg_wrong_2,
+ DATEFMT_DESC (conf->input_datefmt));
status_mesg (mesg_wrong_1, _(outstr));
(void)wgetch (win[STA].p);
date_entered = 0;
@@ -777,7 +810,7 @@ recur_exc_scan (FILE *data_file)
day = *lt;
while ((c = getc (data_file)) == '!')
{
- ungetc (c, data_file);
+ (void)ungetc (c, data_file);
if (fscanf (data_file, "!%u / %u / %u ",
&day.tm_mon, &day.tm_mday, &day.tm_year) != 3)
{
@@ -787,7 +820,7 @@ recur_exc_scan (FILE *data_file)
day.tm_isdst = -1;
day.tm_year -= 1900;
day.tm_mon--;
- exc = (struct days_s *) malloc (sizeof (struct days_s));
+ exc = (struct days_s *) mem_malloc (sizeof (struct days_s));
exc->st = mktime (&day);
exc->next = exc_head;
exc_head = exc;
diff --git a/src/recur.h b/src/recur.h
index 286b1ee..84f5226 100755
--- a/src/recur.h
+++ b/src/recur.h
@@ -1,4 +1,4 @@
-/* $calcurse: recur.h,v 1.23 2008/12/14 11:24:19 culot Exp $ */
+/* $calcurse: recur.h,v 1.24 2008/12/28 13:13:59 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -86,7 +86,8 @@ typedef void (*recur_cb_foreach_date_t)(FILE *, long, char *);
extern recur_apoint_llist_t *recur_alist_p;
extern struct recur_event_s *recur_elist;
-int recur_apoint_llist_init (void);
+void recur_apoint_llist_init (void);
+void recur_apoint_llist_free (void);
recur_apoint_llist_node_t *recur_apoint_new (char *, char *, long, long, char,
int, int, long, struct days_s *);
struct recur_event_s *recur_event_new (char *, char *, long, int, int, int,
diff --git a/src/sigs.c b/src/sigs.c
index 00ec30f..2fa1d41 100755
--- a/src/sigs.c
+++ b/src/sigs.c
@@ -1,4 +1,4 @@
-/* $calcurse: sigs.c,v 1.6 2008/04/12 21:14:03 culot Exp $ */
+/* $calcurse: sigs.c,v 1.7 2008/12/28 13:13:59 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -26,12 +26,10 @@
#include <sys/types.h>
#include <sys/wait.h>
-#include <stdlib.h>
#include <signal.h>
#include "i18n.h"
-#include "vars.h"
-#include "wins.h"
+#include "utils.h"
/*
* General signal handling routine.
@@ -50,7 +48,7 @@ signal_handler (int sig)
break;
case SIGWINCH:
clearok (curscr, TRUE);
- ungetch (KEY_RESIZE);
+ (void)ungetch (KEY_RESIZE);
break;
}
}
@@ -64,8 +62,8 @@ sigs_init (struct sigaction *sa)
sigemptyset (&sa->sa_mask);
if (sigaction (SIGCHLD, sa, NULL) != 0)
{
- perror ("sigaction");
- exit (EXIT_FAILURE);
+ ERROR_MSG (_("Error handling SIGCHLD signal"));
+ exit_calcurse (1);
}
sa->sa_handler = signal_handler;
@@ -73,8 +71,8 @@ sigs_init (struct sigaction *sa)
sigemptyset (&sa->sa_mask);
if (sigaction (SIGWINCH, sa, NULL) != 0)
{
- perror ("sigaction");
- exit (EXIT_FAILURE);
+ ERROR_MSG (_("Error handling SIGWINCH signal"));
+ exit_calcurse (1);
}
sa->sa_handler = SIG_IGN;
@@ -82,7 +80,7 @@ sigs_init (struct sigaction *sa)
sigemptyset (&(sa->sa_mask));
if (sigaction (SIGINT, sa, NULL) != 0)
{
- perror ("sigaction");
- exit (EXIT_FAILURE);
+ ERROR_MSG (_("Error handling SIGINT signal"));
+ exit_calcurse (1);
}
}
diff --git a/src/todo.c b/src/todo.c
index 68d5eb5..68601f6 100755
--- a/src/todo.c
+++ b/src/todo.c
@@ -1,4 +1,4 @@
-/* $calcurse: todo.c,v 1.28 2008/12/15 20:02:00 culot Exp $ */
+/* $calcurse: todo.c,v 1.29 2008/12/28 13:13:59 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -32,6 +32,7 @@
#include "custom.h"
#include "keys.h"
#include "i18n.h"
+#include "mem.h"
#include "todo.h"
struct todo_s *todolist;
@@ -158,10 +159,10 @@ struct todo_s *
todo_add (char *mesg, int id, char *note)
{
struct todo_s *o, **i;
- o = (struct todo_s *) malloc (sizeof (struct todo_s));
- o->mesg = strdup (mesg);
+ o = (struct todo_s *) mem_malloc (sizeof (struct todo_s));
+ o->mesg = mem_strdup (mesg);
o->id = id;
- o->note = (note != NULL && note[0] != '\0') ? strdup (note) : NULL;
+ o->note = (note != NULL && note[0] != '\0') ? mem_strdup (note) : NULL;
i = &todolist;
for (;;)
{
@@ -215,10 +216,10 @@ todo_delete_bynum (unsigned num, erase_flag_e flag)
if (n == num)
{
*iptr = i->next;
- free (i->mesg);
+ mem_free (i->mesg);
if (i->note != NULL)
erase_note (&i->note, flag);
- free (i);
+ mem_free (i);
return;
}
iptr = &i->next;
@@ -337,10 +338,10 @@ todo_chg_priority (int action)
int do_chg = 1;
backup = todo_get_item (hilt);
- strncpy (backup_mesg, backup->mesg, strlen (backup->mesg) + 1);
+ (void)strncpy (backup_mesg, backup->mesg, strlen (backup->mesg) + 1);
backup_id = backup->id;
if (backup->note)
- strncpy (backup_note, backup->note, NOTESIZ + 1);
+ (void)strncpy (backup_note, backup->note, NOTESIZ + 1);
else
backup_note[0] = '\0';
switch (action)
@@ -392,7 +393,7 @@ display_todo_item (int incolor, char *msg, int prio, int note, int len, int y,
mvwprintw (w, y, x, "%d%c %s", prio, ch_note, msg);
else
{
- strncpy (buf, msg, len - 1);
+ (void)strncpy (buf, msg, len - 1);
buf[len - 1] = '\0';
mvwprintw (w, y, x, "%d%c %s...", prio, ch_note, buf);
}
@@ -467,7 +468,7 @@ todo_edit_note (char *editor)
else
return;
}
- snprintf (fullname, BUFSIZ, "%s%s", path_notes, i->note);
+ (void)snprintf (fullname, BUFSIZ, "%s%s", path_notes, i->note);
wins_launch_external (fullname, editor);
}
@@ -481,6 +482,25 @@ todo_view_note (char *pager)
i = todo_get_item (hilt);
if (i->note == NULL)
return;
- snprintf (fullname, BUFSIZ, "%s%s", path_notes, i->note);
+ (void)snprintf (fullname, BUFSIZ, "%s%s", path_notes, i->note);
wins_launch_external (fullname, pager);
}
+
+void
+todo_free_list (void)
+{
+ struct todo_s *o, **i;
+
+ i = &todolist;
+ for (o = todolist; o != 0; o = o->next)
+ {
+ *i = o->next;
+ mem_free (o->mesg);
+ if (o->note != 0)
+ erase_note (&o->note, ERASE_FORCE_KEEP_NOTE);
+ mem_free (o);
+ i = &(*i)->next;
+ }
+ if (todolist)
+ mem_free (todolist);
+}
diff --git a/src/todo.h b/src/todo.h
index 9244f02..42a4da8 100755
--- a/src/todo.h
+++ b/src/todo.h
@@ -1,4 +1,4 @@
-/* $calcurse: todo.h,v 1.12 2008/04/19 21:05:15 culot Exp $ */
+/* $calcurse: todo.h,v 1.13 2008/12/28 13:13:59 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -56,5 +56,6 @@ void todo_edit_item (void);
void todo_update_panel (int);
void todo_edit_note (char *);
void todo_view_note (char *);
+void todo_free_list (void);
#endif /* CALCURSE_TODO_H */
diff --git a/src/utils.c b/src/utils.c
index 4779a4f..23cd32d 100755
--- a/src/utils.c
+++ b/src/utils.c
@@ -1,4 +1,4 @@
-/* $calcurse: utils.c,v 1.61 2008/12/20 19:27:31 culot Exp $ */
+/* $calcurse: utils.c,v 1.62 2008/12/28 13:13:59 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -34,11 +34,19 @@
#include <math.h>
#include <errno.h>
+#include "utils.h"
#include "i18n.h"
+#include "notify.h"
#include "wins.h"
#include "custom.h"
#include "keys.h"
-#include "utils.h"
+#include "recur.h"
+#include "apoint.h"
+#include "todo.h"
+#include "day.h"
+#include "keys.h"
+#include "vars.h"
+#include "mem.h"
#define NB_CAL_CMDS 24 /* number of commands while in cal view */
#define NB_APP_CMDS 29 /* same thing while in appointment view */
@@ -52,11 +60,24 @@ static unsigned status_page;
void
exit_calcurse (int status)
{
- clear ();
- refresh ();
- endwin ();
- ui_mode = UI_CMDLINE;
+ if (ui_mode == UI_CURSES)
+ {
+ clear ();
+ refresh ();
+ endwin ();
+ ui_mode = UI_CMDLINE;
+ }
calendar_stop_date_thread ();
+ vars_free ();
+ notify_free_vars ();
+ notify_free_bar ();
+ day_saved_item_free ();
+ day_free_list ();
+ apoint_llist_free ();
+ recur_apoint_llist_free ();
+ todo_free_list ();
+ keys_free ();
+ mem_stats ();
exit (status);
}
@@ -72,7 +93,7 @@ fatalbox (const char *errmsg)
const int MSGLEN = WINCOL - 2;
char msg[MSGLEN];
- strncpy (msg, errmsg, MSGLEN);
+ (void)strncpy (msg, errmsg, MSGLEN);
errwin = newwin (WINROW, WINCOL, (row - WINROW) / 2, (col - WINCOL) / 2);
custom_apply_attr (errwin, ATTR_HIGHEST);
box (errwin, 0, 0);
@@ -140,7 +161,7 @@ popup (int pop_row, int pop_col, int pop_y, int pop_x, char *title, char *msg,
mvwprintw (popup_win, MSGXPOS, (pop_col - strlen (msg)) / 2, "%s", msg);
custom_apply_attr (popup_win, ATTR_HIGHEST);
box (popup_win, 0, 0);
- snprintf (label, BUFSIZ, "%s", title);
+ (void)snprintf (label, BUFSIZ, "%s", title);
wins_show (popup_win, label);
if (hint)
mvwprintw (popup_win, pop_row - 2, pop_col - (strlen (any_key) + 1), "%s",
@@ -363,7 +384,7 @@ updatestring (WINDOW *win, char **str, int x, int y)
char *newstr;
int escape, len = strlen (*str) + 1;
- newstr = (char *) malloc (BUFSIZ);
+ newstr = (char *) mem_malloc (BUFSIZ);
(void) memcpy (newstr, *str, len);
escape = getstring (win, newstr, BUFSIZ, x, y);
if (!escape)
@@ -373,7 +394,7 @@ updatestring (WINDOW *win, char **str, int x, int y)
EXIT_IF (*str == 0, _("out of memory"));
(void) memcpy (*str, newstr, len);
}
- free (newstr);
+ mem_free (newstr);
return (escape);
}
@@ -502,8 +523,8 @@ date_sec2hour_str (long sec)
t = sec;
lt = localtime (&t);
- timestr = (char *) malloc (TIME_LEN);
- snprintf (timestr, TIME_LEN, "%02u:%02u", lt->tm_hour, lt->tm_min);
+ timestr = (char *) mem_malloc (TIME_LEN);
+ (void)snprintf (timestr, TIME_LEN, "%02u:%02u", lt->tm_hour, lt->tm_min);
return (timestr);
}
@@ -515,10 +536,10 @@ date_sec2date_str (long sec, char *datefmt)
time_t t;
char *datestr;
- datestr = (char *) malloc (sizeof (char) * BUFSIZ);
+ datestr = (char *) mem_malloc (sizeof (char) * BUFSIZ);
if (sec == 0)
- snprintf (datestr, BUFSIZ, "0");
+ (void)snprintf (datestr, BUFSIZ, "0");
else
{
t = sec;
@@ -634,7 +655,7 @@ check_time (char *string)
if (((strlen (string) == 2) || (strlen (string) == 3))
&& (isdigit (string[0]) != 0) && (isdigit (string[1]) != 0))
{
- strncpy (minutes, string, 2);
+ (void)strncpy (minutes, string, 2);
if (atoi (minutes) >= 0)
ok = 2; /* [MM] format */
}
@@ -642,7 +663,7 @@ check_time (char *string)
&& (isdigit (string[2]) != 0) && (isdigit (string[3]) != 0)
&& (string[1] == ':'))
{
- strncpy (hour, string, 1);
+ (void)strncpy (hour, string, 1);
strncpy (minutes, string + 2, 2);
if ((atoi (hour) <= 24) && (atoi (hour) >= 0)
&& (atoi (minutes) < MININSEC) && (atoi (minutes) >= 0))
@@ -834,7 +855,7 @@ new_tempfile (const char *prefix, int trailing_len)
if (prefix_len + trailing_len >= BUFSIZ)
return (NULL);
memcpy (fullname, prefix, prefix_len);
- memset (fullname + prefix_len, 'X', trailing_len);
+ (void)memset (fullname + prefix_len, 'X', trailing_len);
fullname[prefix_len + trailing_len] = '\0';
if ((fd = mkstemp (fullname)) == -1 || (file = fdopen (fd, "w+")) == NULL)
{
@@ -848,7 +869,7 @@ new_tempfile (const char *prefix, int trailing_len)
}
fclose (file);
- return (strdup (fullname + prefix_len));
+ return (mem_strdup (fullname + prefix_len));
}
/* Erase a note previously attached to a todo, event or appointment. */
@@ -861,11 +882,11 @@ erase_note (char **note, erase_flag_e flag)
return;
if (flag != ERASE_FORCE_KEEP_NOTE)
{
- snprintf (fullname, BUFSIZ, "%s%s", path_notes, *note);
+ (void)snprintf (fullname, BUFSIZ, "%s%s", path_notes, *note);
if (unlink (fullname) != 0)
EXIT (_("could not remove note"));
}
- free (*note);
+ mem_free (*note);
*note = NULL;
}
@@ -926,10 +947,10 @@ str_toupper (char *s)
}
void
-mem_free (void *ptr)
+file_close (FILE *f, const char *pos)
{
- if (!ptr)
- return;
- free (ptr);
- ptr = NULL;
+ int ret;
+
+ ret = fclose (f);
+ EXIT_IF (ret != 0, _("Error when closing file at %s"), pos);
}
diff --git a/src/utils.h b/src/utils.h
index d076c06..0be7d85 100755
--- a/src/utils.h
+++ b/src/utils.h
@@ -1,4 +1,4 @@
-/* $calcurse: utils.h,v 1.40 2008/12/12 20:44:50 culot Exp $ */
+/* $calcurse: utils.h,v 1.41 2008/12/28 13:13:59 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -42,11 +42,11 @@
int len; \
\
len = snprintf (msg, BUFSIZ, "%s: %d: ", __FILE__, __LINE__); \
- snprintf (msg + len, BUFSIZ - len, __VA_ARGS__); \
+ (void)snprintf (msg + len, BUFSIZ - len, __VA_ARGS__); \
if (ui_mode == UI_CURSES) \
fatalbox (msg); \
else \
- fprintf (stderr, "%s\n", msg); \
+ (void)fprintf (stderr, "%s\n", msg); \
} while (0)
#define EXIT(...) do { \
@@ -78,9 +78,13 @@
} \
} while (0)
-#define GETSTRING_VALID 0 /* value returned by getstring() if text is valid */
-#define GETSTRING_ESC 1 /* user pressed escape to cancel editing */
-#define GETSTRING_RET 2 /* return was pressed without entering any text */
+#define STRINGIFY(x) #x
+#define TOSTRING(x) STRINGIFY(x)
+#define __FILE_POS__ __FILE__ ":" TOSTRING(__LINE__)
+
+#define GETSTRING_VALID 0 /* value returned by getstring() if text is valid */
+#define GETSTRING_ESC 1 /* user pressed escape to cancel editing */
+#define GETSTRING_RET 2 /* return was pressed without entering any text */
typedef struct {
const char *str;
@@ -128,6 +132,6 @@ char *new_tempfile (const char *, int);
void erase_note (char **, erase_flag_e);
int parse_date (char *, int, int *, int *, int *);
char *str_toupper (char *);
-void mem_free (void *ptr);
+void file_close (FILE *, const char *);
#endif /* CALCURSE_UTILS_H */
diff --git a/src/vars.c b/src/vars.c
index 3931729..8a80e09 100755
--- a/src/vars.c
+++ b/src/vars.c
@@ -1,4 +1,4 @@
-/* $calcurse: vars.c,v 1.11 2008/11/16 17:42:53 culot Exp $ */
+/* $calcurse: vars.c,v 1.12 2008/12/28 13:13:59 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -32,6 +32,7 @@
#include "custom.h"
#include "wins.h"
#include "keys.h"
+#include "mem.h"
#include "vars.h"
/*
@@ -112,7 +113,7 @@ vars_init (conf_t *conf)
conf->auto_save = true;
conf->skip_system_dialogs = false;
conf->skip_progress_bar = false;
- strncpy (conf->output_datefmt, "%D", 3);
+ (void)strncpy (conf->output_datefmt, "%D", 3);
conf->input_datefmt = 1;
/* Default external editor and pager */
@@ -133,7 +134,7 @@ vars_init (conf_t *conf)
calendar_set_first_day_of_week (MONDAY);
/* Pad structure to scroll text inside the appointment panel */
- apad = (struct pad_s *) malloc (sizeof (struct pad_s));
+ apad = (struct pad_s *) mem_malloc (sizeof (struct pad_s));
apad->length = 1;
apad->first_onscreen = 0;
@@ -143,3 +144,9 @@ vars_init (conf_t *conf)
/* Start at the current date */
calendar_init_slctd_day ();
}
+
+void
+vars_free (void)
+{
+ mem_free (apad);
+}
diff --git a/src/vars.h b/src/vars.h
index 9b0dc06..d0a1d3c 100755
--- a/src/vars.h
+++ b/src/vars.h
@@ -1,4 +1,4 @@
-/* $calcurse: vars.h,v 1.26 2008/11/16 17:42:53 culot Exp $ */
+/* $calcurse: vars.h,v 1.27 2008/12/28 13:13:59 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -122,5 +122,6 @@ extern struct pad_s *apad;
extern struct nbar_s *nbar;
void vars_init (conf_t *conf);
+void vars_free (void);
#endif /* CALCURSE_VARS_H */
diff --git a/src/wins.c b/src/wins.c
index fb0db32..8dde1f7 100755
--- a/src/wins.c
+++ b/src/wins.c
@@ -1,4 +1,4 @@
-/* $calcurse: wins.c,v 1.19 2008/12/12 20:44:50 culot Exp $ */
+/* $calcurse: wins.c,v 1.20 2008/12/28 13:13:59 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -32,6 +32,7 @@
#include "utils.h"
#include "todo.h"
#include "custom.h"
+#include "mem.h"
#include "wins.h"
/* Variables to handle calcurse windows. */
@@ -96,17 +97,17 @@ wins_init (void)
* display appointments and event.
*/
win[CAL].p = newwin (CALHEIGHT, CALWIDTH, win[CAL].y, win[CAL].x);
- snprintf (label, BUFSIZ, _("Calendar"));
+ (void)snprintf (label, BUFSIZ, _("Calendar"));
wins_show (win[CAL].p, label);
win[APP].p = newwin (win[APP].h, win[APP].w, win[APP].y, win[APP].x);
- snprintf (label, BUFSIZ, _("Appointments"));
+ (void)snprintf (label, BUFSIZ, _("Appointments"));
wins_show (win[APP].p, label);
apad->width = win[APP].w - 3;
apad->ptrwin = newpad (apad->length, apad->width);
win[TOD].p = newwin (win[TOD].h, win[TOD].w, win[TOD].y, win[TOD].x);
- snprintf (label, BUFSIZ, _("ToDo"));
+ (void)snprintf (label, BUFSIZ, _("ToDo"));
wins_show (win[TOD].p, label);
win[STA].p = newwin (win[STA].h, win[STA].w, win[STA].y, win[STA].x);
@@ -452,10 +453,10 @@ wins_launch_external (const char *file, const char *cmd)
/* Beware of space between cmd and file. */
len = strlen (file) + strlen (cmd) + 2;
- p = (char *) malloc (sizeof (char) * len);
+ p = (char *) mem_malloc (sizeof (char) * len);
if (snprintf (p, len, "%s %s", cmd, file) == -1)
{
- free (p);
+ mem_free (p);
return;
}
if (notify_bar ())
@@ -465,7 +466,7 @@ wins_launch_external (const char *file, const char *cmd)
ui_mode = UI_CMDLINE;
clear ();
refresh ();
- system (p);
+ (void)system (p);
reset_prog_mode ();
clearok (curscr, TRUE);
curs_set (0);
@@ -473,5 +474,5 @@ wins_launch_external (const char *file, const char *cmd)
refresh ();
if (notify_bar ())
notify_start_main_thread ();
- free (p);
+ mem_free (p);
}