Added wrappers around libc's memory management functions, to easily debug memory usage

This commit is contained in:
Frederic Culot 2008-12-28 13:13:58 +00:00
parent a63c748920
commit 5352496984
28 changed files with 869 additions and 647 deletions

View File

@ -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 ===

View File

@ -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
#-------------------------------------------------------------------------------

View File

@ -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@

View File

@ -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,
(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",
(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 ",
(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 */
pthread_mutex_unlock (&(alist_p->mutex));
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 */

View File

@ -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);

View File

@ -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,7 +245,7 @@ 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,
(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,7 +493,7 @@ 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,
(void)snprintf (outstr, BUFSIZ,
"Possible argument format are: '%s' or 'n'\n",
DATEFMT_DESC (conf->input_datefmt));
fputs (_(outstr), stdout);
@ -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,7 +556,7 @@ 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,
(void)snprintf (outstr, BUFSIZ,
"Argument format for -s and --startday is: '%s'\n",
DATEFMT_DESC (conf->input_datefmt));
fputs (_(outstr), stdout);

View File

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

View File

@ -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

View File

@ -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,7 +430,7 @@ 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"),
(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,
(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 ();

View File

@ -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,7 +663,7 @@ update_rept (struct rpt_s **rpt, const long start, conf_t *conf)
do
{
snprintf (outstr, BUFSIZ, "Enter the new ending date: [%s] or '0'",
(void)snprintf (outstr, BUFSIZ, "Enter the new ending date: [%s] or '0'",
DATEFMT_DESC (conf->input_datefmt));
status_mesg (_(outstr), "");
timstr =
@ -656,7 +671,7 @@ update_rept (struct rpt_s **rpt, const long start, conf_t *conf)
cancel = updatestring (win[STA].p, &timstr, 0, 1);
if (cancel)
{
free (timstr);
mem_free (timstr);
return;
}
if (strcmp (timstr, "0") == 0)
@ -691,7 +706,7 @@ update_rept (struct rpt_s **rpt, const long start, conf_t *conf)
}
else
{
snprintf (outstr, BUFSIZ, msg_fmts,
(void)snprintf (outstr, BUFSIZ, msg_fmts,
DATEFMT_DESC (conf->input_datefmt));
status_mesg (msg_wrong_date, _(outstr));
(void)wgetch (win[STA].p);
@ -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);
}

View File

@ -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);

View File

@ -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,
(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;
}

View File

@ -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"

436
src/io.c

File diff suppressed because it is too large Load Diff

View File

@ -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
@ -126,6 +127,28 @@ keys_init (void)
bzero (keys, NBKEYS);
}
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)
{
@ -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,13 +443,14 @@ 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),
(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

View File

@ -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);

View File

@ -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);
(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);
strncpy (opt[SHOW].desc,
(void)strncpy (opt[SHOW].desc,
_("(if set to YES, notify-bar will be displayed)"), BUFSIZ);
strncpy (opt[DATE].desc,
(void)strncpy (opt[DATE].desc,
_("(Format of the date to be displayed inside notify-bar)"),
BUFSIZ);
strncpy (opt[CLOCK].desc,
(void)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,
(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);
}

View File

@ -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);

View File

@ -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);
}
return (0);
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;
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",
(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",
(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",
(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,7 +386,7 @@ 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",
(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));
}
@ -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",
(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,7 +725,7 @@ recur_repeat_item (conf_t *conf)
while (!date_entered)
{
snprintf (outstr, BUFSIZ, mesg_until_1,
(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,7 +759,7 @@ recur_repeat_item (conf_t *conf)
}
else
{
snprintf (outstr, BUFSIZ, mesg_wrong_2,
(void)snprintf (outstr, BUFSIZ, mesg_wrong_2,
DATEFMT_DESC (conf->input_datefmt));
status_mesg (mesg_wrong_1, _(outstr));
(void)wgetch (win[STA].p);
@ -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;

View File

@ -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,

View File

@ -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);
}
}

View File

@ -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);
}

View File

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

View File

@ -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 */
@ -51,12 +59,25 @@ static unsigned status_page;
/* General routine to exit calcurse properly. */
void
exit_calcurse (int status)
{
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);
}

View File

@ -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,6 +78,10 @@
} \
} while (0)
#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 */
@ -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 */

View File

@ -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);
}

View File

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

View File

@ -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);
}