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> 2008-12-27 Frederic Culot <frederic@culot.org>
* === Released 2.4 === * === 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 # Init
@ -57,6 +57,22 @@ AC_CHECK_HEADERS([math.h], [
# Compilation options # Compilation options
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
CFLAGS="$CFLAGS -Wall" 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 # 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 AUTOMAKE_OPTIONS= gnu
@ -21,7 +21,8 @@ calcurse_SOURCES= \
todo.c todo.h \ todo.c todo.h \
utils.c utils.h \ utils.c utils.h \
vars.c vars.h \ vars.c vars.h \
wins.c wins.h wins.c wins.h \
mem.c mem.h
LDADD= @LTLIBINTL@ 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 * Calcurse - text-based organizer
@ -38,19 +38,41 @@
#include "recur.h" #include "recur.h"
#include "keys.h" #include "keys.h"
#include "calendar.h" #include "calendar.h"
#include "mem.h"
#include "apoint.h" #include "apoint.h"
apoint_llist_t *alist_p; apoint_llist_t *alist_p;
static int hilt = 0; static int hilt = 0;
int void
apoint_llist_init (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; alist_p->root = NULL;
pthread_mutex_init (&(alist_p->mutex), 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. */ /* 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; apoint_llist_node_t *o, **i;
o = (apoint_llist_node_t *) malloc (sizeof (apoint_llist_node_t)); o = (apoint_llist_node_t *) mem_malloc (sizeof (apoint_llist_node_t));
o->mesg = strdup (mesg); o->mesg = mem_strdup (mesg);
o->note = (note != NULL) ? strdup (note) : NULL; o->note = (note != NULL) ? mem_strdup (note) : NULL;
o->state = state; o->state = state;
o->start = start; o->start = start;
o->dur = dur; o->dur = dur;
@ -131,8 +153,6 @@ apoint_add (void)
char item_time[LTIME] = ""; char item_time[LTIME] = "";
char item_mesg[BUFSIZ] = ""; char item_mesg[BUFSIZ] = "";
long apoint_duration = 0, apoint_start; long apoint_duration = 0, apoint_start;
apoint_llist_node_t *apoint_pointeur;
struct event_s *event_pointeur;
unsigned heures, minutes; unsigned heures, minutes;
unsigned end_h, end_m; unsigned end_h, end_m;
int is_appointment = 1; int is_appointment = 1;
@ -154,7 +174,7 @@ apoint_add (void)
(void)wgetch (win[STA].p); (void)wgetch (win[STA].p);
} }
else else
sscanf (item_time, "%u:%u", &heures, &minutes); (void)sscanf (item_time, "%u:%u", &heures, &minutes);
} }
else else
return; return;
@ -183,7 +203,7 @@ apoint_add (void)
apoint_duration = atoi (item_time); apoint_duration = atoi (item_time);
else if (check_time (item_time) == 1) 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) if (end_h < heures)
{ {
apoint_duration = MININSEC - minutes + end_m apoint_duration = MININSEC - minutes + end_m
@ -207,15 +227,14 @@ apoint_add (void)
if (is_appointment) if (is_appointment)
{ {
apoint_start = date2sec (*calendar_get_slctd_day (), heures, minutes); 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); min2sec (apoint_duration), 0L);
if (notify_bar ()) if (notify_bar ())
notify_check_added (item_mesg, apoint_start, 0L); notify_check_added (item_mesg, apoint_start, 0L);
} }
else else
event_pointeur = event_new (item_mesg, 0L, (void)event_new (item_mesg, 0L,
date2sec (*calendar_get_slctd_day (), 12, date2sec (*calendar_get_slctd_day (), 12, 0), Id);
0), Id);
if (hilt == 0) if (hilt == 0)
hilt++; hilt++;
@ -302,24 +321,20 @@ apoint_sec2str (apoint_llist_node_t *o, int type, long day, char *start,
time_t t; time_t t;
if (o->start < day && type == APPT) if (o->start < day && type == APPT)
{ (void)strncpy (start, "..:..", 6);
strncpy (start, "..:..", 6);
}
else else
{ {
t = o->start; t = o->start;
lt = localtime (&t); 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) if (o->start + o->dur > day + DAYINSEC && type == APPT)
{ (void)strncpy (end, "..:..", 6);
strncpy (end, "..:..", 6);
}
else else
{ {
t = o->start + o->dur; t = o->start + o->dur;
lt = localtime (&t); 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; t = o->start;
lt = localtime (&t); 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_mon + 1, lt->tm_mday, 1900 + lt->tm_year, lt->tm_hour,
lt->tm_min); lt->tm_min);
t = o->start + o->dur; t = o->start + o->dur;
lt = localtime (&t); 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_mon + 1, lt->tm_mday, 1900 + lt->tm_year, lt->tm_hour,
lt->tm_min); lt->tm_min);
if (o->note != NULL) if (o->note != NULL)
fprintf (f, ">%s ", o->note); (void)fprintf (f, ">%s ", o->note);
if (o->state & APOINT_NOTIFY) if (o->state & APOINT_NOTIFY)
fprintf (f, "!"); (void)fprintf (f, "!");
else else
fprintf (f, "|"); (void)fprintf (f, "|");
fprintf (f, "%s\n", o->mesg); (void)fprintf (f, "%s\n", o->mesg);
} }
apoint_llist_node_t * apoint_llist_node_t *
apoint_scan (FILE *f, struct tm start, struct tm end, char state, char *note) apoint_scan (FILE *f, struct tm start, struct tm end, char state, char *note)
{ {
struct tm *lt; char buf[MESG_MAXSIZE], *newline;
char buf[MESG_MAXSIZE], *nl;
time_t tstart, tend, t; time_t tstart, tend, t;
t = time (NULL); t = time (NULL);
lt = localtime (&t); (void)localtime (&t);
/* Read the appointment description */ /* Read the appointment description */
fgets (buf, MESG_MAXSIZE, f); (void)fgets (buf, MESG_MAXSIZE, f);
nl = strchr (buf, '\n'); newline = strchr (buf, '\n');
if (nl) if (newline)
{ *newline = '\0';
*nl = '\0';
}
start.tm_sec = end.tm_sec = 0; start.tm_sec = end.tm_sec = 0;
start.tm_isdst = end.tm_isdst = -1; 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 ()) if (notify_bar ())
need_check_notify = notify_same_item (i->start); need_check_notify = notify_same_item (i->start);
*iptr = i->next; *iptr = i->next;
free (i->mesg); mem_free (i->mesg);
erase_note (&i->note, flag); erase_note (&i->note, flag);
free (i); mem_free (i);
pthread_mutex_unlock (&(alist_p->mutex)); pthread_mutex_unlock (&(alist_p->mutex));
if (need_check_notify) if (need_check_notify)
notify_check_next_app (); notify_check_next_app ();
@ -445,10 +457,10 @@ apoint_delete_bynum (long start, unsigned num, erase_flag_e flag)
} }
iptr = &i->next; iptr = &i->next;
} }
pthread_mutex_unlock (&(alist_p->mutex)); pthread_mutex_unlock (&(alist_p->mutex));
/* NOTREACHED */
EXIT (_("no such appointment")); EXIT (_("no such appointment"));
/* NOTREACHED */
} }
/* /*
@ -528,7 +540,7 @@ apoint_check_next (struct notify_app_s *app, long start)
if (i->start > start) if (i->start > start)
{ {
app->time = i->start; app->time = i->start;
app->txt = strdup (i->mesg); app->txt = mem_strdup (i->mesg);
app->state = i->state; app->state = i->state;
app->got_app = 1; app->got_app = 1;
} }
@ -548,11 +560,10 @@ apoint_recur_s2apoint_s (recur_apoint_llist_node_t *p)
{ {
apoint_llist_node_t *a; apoint_llist_node_t *a;
a = (apoint_llist_node_t *) malloc (sizeof (apoint_llist_node_t)); a = (apoint_llist_node_t *) mem_malloc (sizeof (apoint_llist_node_t));
a->mesg = (char *) malloc (strlen (p->mesg) + 1); a->mesg = mem_strdup (p->mesg);
a->start = p->start; a->start = p->start;
a->dur = p->dur; a->dur = p->dur;
a->mesg = p->mesg;
return (a); return (a);
} }
@ -605,10 +616,10 @@ apoint_switch_notify (void)
n++; n++;
} }
} }
pthread_mutex_unlock (&(alist_p->mutex));
/* NOTREACHED */ pthread_mutex_unlock (&(alist_p->mutex));
EXIT (_("no such appointment")); EXIT (_("no such appointment"));
/* NOTREACHED */
} }
/* Updates the Appointment panel */ /* 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 * Calcurse - text-based organizer
@ -59,7 +59,8 @@ apoint_llist_t;
extern apoint_llist_t *alist_p; 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_set (int);
void apoint_hilt_decrease (void); void apoint_hilt_decrease (void);
void apoint_hilt_increase (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 * Calcurse - text-based organizer
@ -41,6 +41,10 @@
#include "todo.h" #include "todo.h"
#include "io.h" #include "io.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
/* /*
* Print Calcurse usage and exit. * Print Calcurse usage and exit.
*/ */
@ -72,7 +76,8 @@ version_arg ()
_("\nCopyright (c) 2004-2008 Frederic Culot.\n" _("\nCopyright (c) 2004-2008 Frederic Culot.\n"
"This is free software; see the source for copying conditions.\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 (vtitle, stdout);
fputs (vtext, stdout); fputs (vtext, stdout);
} }
@ -134,7 +139,8 @@ help_arg ()
"or read the manpage.\n" "or read the manpage.\n"
"Mail bug reports and suggestions to <calcurse@culot.org>.\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); fputs (htitle, stdout);
usage (); usage ();
fputs (htext, stdout); fputs (htext, stdout);
@ -159,13 +165,13 @@ print_notefile (FILE *out, char *filename, int nbtab)
int printlinestarter = 1; int printlinestarter = 1;
for (i = 0; i < nbtab; i++) 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"); notefile = fopen (path_to_notefile, "r");
if (notefile) if (notefile)
{ {
while (fgets (buffer, BUFSIZ, notefile) != NULL) while (fgets (buffer, BUFSIZ, notefile) != 0)
{ {
if (printlinestarter) if (printlinestarter)
{ {
@ -177,7 +183,7 @@ print_notefile (FILE *out, char *filename, int nbtab)
printlinestarter = 1; printlinestarter = 1;
} }
fputs ("\n", out); fputs ("\n", out);
fclose (notefile); file_close (notefile, __FILE_POS__);
} }
else else
{ {
@ -207,7 +213,7 @@ todo_arg (int priority, int print_note)
fputs (_("to do:\n"), stdout); fputs (_("to do:\n"), stdout);
title = 0; title = 0;
} }
snprintf (priority_str, BUFSIZ, "%d. ", i->id); (void)snprintf (priority_str, BUFSIZ, "%d. ", i->id);
fputs (priority_str, stdout); fputs (priority_str, stdout);
fputs (i->mesg, stdout); fputs (i->mesg, stdout);
fputs ("\n", stdout); fputs ("\n", stdout);
@ -239,8 +245,8 @@ next_arg (void)
hours_left = (time_left / HOURINSEC); hours_left = (time_left / HOURINSEC);
min_left = (time_left - hours_left * HOURINSEC) / MININSEC; min_left = (time_left - hours_left * HOURINSEC) / MININSEC;
fputs (_("next appointment:\n"), stdout); 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); next_app.txt);
fputs (mesg, stdout); fputs (mesg, stdout);
free (next_app.txt); free (next_app.txt);
} }
@ -434,7 +440,7 @@ display_app (struct tm *t, int numdays, int add_line, int print_note,
if (app_found) if (app_found)
add_line = 1; add_line = 1;
t->tm_mday++; 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]; char outstr[BUFSIZ];
fputs (_("Argument to the '-d' flag is not valid\n"), stderr); 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", "Possible argument format are: '%s' or 'n'\n",
DATEFMT_DESC (conf->input_datefmt)); DATEFMT_DESC (conf->input_datefmt));
fputs (_(outstr), stdout); fputs (_(outstr), stdout);
more_info (); 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_year -= 1900;
t.tm_mon--; t.tm_mon--;
mktime (&t); (void)mktime (&t);
} }
else else
{ {
@ -550,9 +556,9 @@ date_arg_extended (char *startday, char *range, int add_line, int print_note,
{ {
char outstr[BUFSIZ]; char outstr[BUFSIZ];
fputs (_("Argument is not valid\n"), stderr); fputs (_("Argument is not valid\n"), stderr);
snprintf (outstr, BUFSIZ, (void)snprintf (outstr, BUFSIZ,
"Argument format for -s and --startday is: '%s'\n", "Argument format for -s and --startday is: '%s'\n",
DATEFMT_DESC (conf->input_datefmt)); DATEFMT_DESC (conf->input_datefmt));
fputs (_(outstr), stdout); fputs (_(outstr), stdout);
fputs (_("Argument format for -r and --range is: 'n'\n"), stdout); fputs (_("Argument format for -r and --range is: 'n'\n"), stdout);
more_info (); more_info ();

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 * Calcurse - text-based organizer
@ -24,13 +24,13 @@
* *
*/ */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /* HAVE_CONFIG_H */
#include <stdlib.h> #include <stdlib.h>
#include <signal.h> #include <signal.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include "i18n.h" #include "i18n.h"
#include "io.h" #include "io.h"
#include "help.h" #include "help.h"
@ -86,7 +86,7 @@ main (int argc, char **argv)
*/ */
non_interactive = parse_args (argc, argv, &conf); non_interactive = parse_args (argc, argv, &conf);
if (non_interactive) if (non_interactive)
return (EXIT_SUCCESS); exit_calcurse (EXIT_SUCCESS);
/* Begin of interactive mode with ncurses interface. */ /* Begin of interactive mode with ncurses interface. */
sigs_init (&sigact); /* signal handling init */ 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 * Calcurse - text-based organizer
@ -63,25 +63,22 @@ static pthread_t calendar_t_date;
/* Thread needed to update current date in calendar. */ /* Thread needed to update current date in calendar. */
/* ARGSUSED0 */
static void * static void *
calendar_date_thread (void *arg) calendar_date_thread (void *arg)
{ {
time_t now, tomorrow; time_t actual, tomorrow;
for (;;) for (;;)
{ {
tomorrow = (time_t) (get_today () + DAYINSEC); tomorrow = (time_t) (get_today () + DAYINSEC);
while ((now = time (NULL)) < tomorrow) while ((actual = time (NULL)) < tomorrow)
{ (void)sleep (tomorrow - actual);
sleep (tomorrow - now);
}
calendar_set_current_date (); calendar_set_current_date ();
calendar_update_panel (win[CAL].p); calendar_update_panel (win[CAL].p);
} }
pthread_exit ((void *) 0);
} }
/* Launch the calendar date thread. */ /* Launch the calendar date thread. */
@ -362,7 +359,7 @@ calendar_change_day (int datefmt)
while (wrong_day) while (wrong_day)
{ {
snprintf (outstr, BUFSIZ, request_date, DATEFMT_DESC (datefmt)); (void)snprintf (outstr, BUFSIZ, request_date, DATEFMT_DESC (datefmt));
status_mesg (_(outstr), ""); status_mesg (_(outstr), "");
if (getstring (win[STA].p, selected_day, LDAY, 0, 1) == GETSTRING_ESC) if (getstring (win[STA].p, selected_day, LDAY, 0, 1) == GETSTRING_ESC)
return; return;
@ -424,7 +421,7 @@ calendar_move (move_t move)
int ret, days_to_remove, days_to_add; int ret, days_to_remove, days_to_add;
struct tm t; struct tm t;
memset (&t, 0, sizeof (struct tm)); (void)memset (&t, 0, sizeof (struct tm));
t.tm_mday = slctd_day.dd; t.tm_mday = slctd_day.dd;
t.tm_mon = slctd_day.mm - 1; t.tm_mon = slctd_day.mm - 1;
t.tm_year = slctd_day.yyyy - 1900; t.tm_year = slctd_day.yyyy - 1900;
@ -458,7 +455,7 @@ calendar_move (move_t move)
break; break;
case WEEK_START: case WEEK_START:
/* Normalize struct tm to get week day number. */ /* Normalize struct tm to get week day number. */
mktime (&t); (void)mktime (&t);
if (calendar_week_begins_on_monday ()) if (calendar_week_begins_on_monday ())
days_to_remove = ((t.tm_wday == 0) ? WEEKINDAYS - 1 : t.tm_wday - 1); days_to_remove = ((t.tm_wday == 0) ? WEEKINDAYS - 1 : t.tm_wday - 1);
else else
@ -466,7 +463,7 @@ calendar_move (move_t move)
ret = date_change (&t, 0, 0 - days_to_remove); ret = date_change (&t, 0, 0 - days_to_remove);
break; break;
case WEEK_END: case WEEK_END:
mktime (&t); (void)mktime (&t);
if (calendar_week_begins_on_monday ()) if (calendar_week_begins_on_monday ())
days_to_add = ((t.tm_wday == 0) ? 0 : WEEKINDAYS - t.tm_wday); days_to_add = ((t.tm_wday == 0) ? 0 : WEEKINDAYS - t.tm_wday);
else 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 * Calcurse - text-based organizer
@ -28,13 +28,18 @@
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include "custom.h" #ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include "i18n.h" #include "i18n.h"
#include "io.h" #include "io.h"
#include "utils.h" #include "utils.h"
#include "keys.h" #include "keys.h"
#include "apoint.h" #include "apoint.h"
#include "help.h" #include "help.h"
#include "mem.h"
#include "custom.h"
static struct attribute_s attr; static struct attribute_s attr;
@ -214,7 +219,7 @@ custom_load_conf (conf_t *conf, int background)
status_mesg (mesg_line1, mesg_line2); status_mesg (mesg_line1, mesg_line2);
wnoutrefresh (win[STA].p); wnoutrefresh (win[STA].p);
doupdate (); doupdate ();
keys_getch (win[STA].p); (void)keys_getch (win[STA].p);
} }
var = CUSTOM_CONF_NOVARIABLE; var = CUSTOM_CONF_NOVARIABLE;
pthread_mutex_lock (&nbar->mutex); pthread_mutex_lock (&nbar->mutex);
@ -270,11 +275,11 @@ custom_load_conf (conf_t *conf, int background)
var = 0; var = 0;
break; break;
case CUSTOM_CONF_NOTIFYBARDATE: 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; var = 0;
break; break;
case CUSTOM_CONF_NOTIFYBARCLOCK: 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; var = 0;
break; break;
case CUSTOM_CONF_NOTIFYBARWARNING: case CUSTOM_CONF_NOTIFYBARWARNING:
@ -282,12 +287,12 @@ custom_load_conf (conf_t *conf, int background)
var = 0; var = 0;
break; break;
case CUSTOM_CONF_NOTIFYBARCOMMAND: 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; var = 0;
break; break;
case CUSTOM_CONF_OUTPUTDATEFMT: case CUSTOM_CONF_OUTPUTDATEFMT:
if (e_conf[0] != '\0') 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; var = 0;
break; break;
case CUSTOM_CONF_INPUTDATEFMT: 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) else if (strncmp (e_conf, "input_datefmt=", 12) == 0)
var = CUSTOM_CONF_INPUTDATEFMT; var = CUSTOM_CONF_INPUTDATEFMT;
} }
fclose (data_file); file_close (data_file, __FILE_POS__);
pthread_mutex_unlock (&nbar->mutex); 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) if (lwin->p != NULL)
delwin (lwin->p); delwin (lwin->p);
snprintf (label, BUFSIZ, _("CalCurse %s | layout configuration"), (void)snprintf (label, BUFSIZ, _("CalCurse %s | layout configuration"),
VERSION); VERSION);
custom_confwin_init (lwin, label); 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) if (cwin->p != NULL)
delwin (cwin->p); 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); custom_confwin_init (cwin, label);
} }
@ -809,7 +814,7 @@ custom_color_theme_name (char *theme_name)
}; };
if (!colorize) if (!colorize)
snprintf (theme_name, BUFSIZ, "0"); (void)snprintf (theme_name, BUFSIZ, "0");
else else
{ {
pair_content (COLR_CUSTOM, &color[0], &color[1]); pair_content (COLR_CUSTOM, &color[0], &color[1]);
@ -825,7 +830,8 @@ custom_color_theme_name (char *theme_name)
/* NOTREACHED */ /* 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 = char *input_datefmt_str =
_("Enter the date format (1-mm/dd/yyyy, 2-dd/mm/yyyy, 3-yyyy/mm/dd) "); _("Enter the date format (1-mm/dd/yyyy, 2-dd/mm/yyyy, 3-yyyy/mm/dd) ");
int ch; int ch;
char *buf = (char *) malloc (BUFSIZ); char *buf = (char *) mem_malloc (BUFSIZ);
clear (); clear ();
conf_set_scrsize (&cwin); 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_scrollwin_init (&cwin);
wins_show (cwin.win.p, cwin.label); wins_show (cwin.win.p, cwin.label);
status_mesg (number_str, keys); status_mesg (number_str, keys);
@ -990,11 +997,11 @@ custom_general_config (conf_t *conf)
break; break;
case '7': case '7':
status_mesg (output_datefmt_str, ""); status_mesg (output_datefmt_str, "");
strncpy (buf, conf->output_datefmt, (void)strncpy (buf, conf->output_datefmt,
strlen (conf->output_datefmt) + 1); strlen (conf->output_datefmt) + 1);
if (updatestring (win[STA].p, &buf, 0, 1) == 0) 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); status_mesg (number_str, keys);
break; break;
@ -1013,7 +1020,7 @@ custom_general_config (conf_t *conf)
cwin.total_lines = print_general_options (cwin.pad.p, conf); cwin.total_lines = print_general_options (cwin.pad.p, conf);
wins_scrollwin_display (&cwin); wins_scrollwin_display (&cwin);
} }
free (buf); mem_free (buf);
wins_scrollwin_delete (&cwin); wins_scrollwin_delete (&cwin);
} }
@ -1045,7 +1052,7 @@ print_keys_bindings (WINDOW *win, int selected_row, int selected_elm, int yoff)
int nbkeys; int nbkeys;
nbkeys = keys_action_count_keys (action); 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) if (action == selected_row)
custom_apply_attr (win, ATTR_HIGHEST); custom_apply_attr (win, ATTR_HIGHEST);
mvwprintw (win, y, XPOS, "%s ", actionstr); mvwprintw (win, y, XPOS, "%s ", actionstr);
@ -1117,7 +1124,8 @@ custom_keys_config (void)
clear (); clear ();
conf_set_scrsize (&kwin); conf_set_scrsize (&kwin);
nbdisplayed = (kwin.win.h - LABELLINES) / LINESPERKEY; 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_scrollwin_init (&kwin);
wins_show (kwin.win.p, kwin.label); wins_show (kwin.win.p, kwin.label);
custom_keys_config_bar (); 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 * Calcurse - text-based organizer
@ -35,22 +35,40 @@
#include "event.h" #include "event.h"
#include "custom.h" #include "custom.h"
#include "keys.h" #include "keys.h"
#include "mem.h"
#include "day.h" #include "day.h"
static struct day_item_s *day_items_ptr; 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. */ /* Free the current day linked list containing the events and appointments. */
static void void
day_free_list (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; *i = o->next;
free (p->mesg); mem_free (o->mesg);
free (p); if (o->note)
mem_free (o->note);
mem_free (o);
i = &(*i)->next;
} }
day_items_ptr = NULL; 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) day_add_event (int type, char *mesg, char *note, long day, int id)
{ {
struct day_item_s *o, **i; struct day_item_s *o, **i;
o = (struct day_item_s *) malloc (sizeof (struct day_item_s)); o = (struct day_item_s *) mem_malloc (sizeof (struct day_item_s));
o->mesg = (char *) malloc (strlen (mesg) + 1); o->mesg = mem_strdup (mesg);
strncpy (o->mesg, mesg, strlen (mesg) + 1);
o->note = note; o->note = note;
o->type = type; o->type = type;
o->appt_dur = 0; 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; struct day_item_s *o, **i;
int insert_item = 0; int insert_item = 0;
o = (struct day_item_s *) malloc (sizeof (struct day_item_s)); o = (struct day_item_s *) mem_malloc (sizeof (struct day_item_s));
o->mesg = strdup (mesg); o->mesg = mem_strdup (mesg);
o->note = note; o->note = note;
o->start = start; o->start = start;
o->appt_dur = dur; 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); mvwprintw (win, y, x, " %c%c%s", ch_recur, ch_note, msg);
else else
{ {
strncpy (buf, msg, len - 1); (void)strncpy (buf, msg, len - 1);
buf[len - 1] = '\0'; buf[len - 1] = '\0';
mvwprintw (win, y, x, " %c%c%s...", ch_recur, ch_note, buf); 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; max_pos = length;
/* Initialize the structure used to store highlited item. */ /* Initialize the structure used to store highlited item. */
if (day_saved_item == NULL) if (day_saved_item == 0)
{ day_saved_item_init ();
day_saved_item = malloc (sizeof (struct day_saved_item_s));
}
for (p = day_items_ptr; p != 0; p = p->next) for (p = day_items_ptr; p != 0; p = p->next)
{ {
@ -545,8 +560,8 @@ update_start_time (long *start, long *dur)
do do
{ {
timestr = day_edit_time (*start); timestr = day_edit_time (*start);
sscanf (timestr, "%u:%u", &hr, &mn); (void)sscanf (timestr, "%u:%u", &hr, &mn);
free (timestr); mem_free (timestr);
newtime = update_time_in_date (*start, hr, mn); newtime = update_time_in_date (*start, hr, mn);
if (newtime < *start + *dur) if (newtime < *start + *dur)
{ {
@ -572,8 +587,8 @@ update_duration (long *start, long *dur)
char *timestr; char *timestr;
timestr = day_edit_time (*start + *dur); timestr = day_edit_time (*start + *dur);
sscanf (timestr, "%u:%u", &hr, &mn); (void)sscanf (timestr, "%u:%u", &hr, &mn);
free (timestr); mem_free (timestr);
newtime = update_time_in_date (*start, hr, mn); newtime = update_time_in_date (*start, hr, mn);
*dur = (newtime > *start) ? newtime - *start : DAYINSEC + newtime - *start; *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 do
{ {
status_mesg (msg_rpt_type, msg_rpt_ans); status_mesg (msg_rpt_type, msg_rpt_ans);
typstr = (char *) malloc (sizeof (char) * SINGLECHAR); typstr = (char *) mem_malloc (sizeof (char) * SINGLECHAR);
snprintf (typstr, SINGLECHAR, "%c", recur_def2char ((*rpt)->type)); (void)snprintf (typstr, SINGLECHAR, "%c", recur_def2char ((*rpt)->type));
cancel = updatestring (win[STA].p, &typstr, 0, 1); cancel = updatestring (win[STA].p, &typstr, 0, 1);
if (cancel) if (cancel)
{ {
free (typstr); mem_free (typstr);
return; return;
} }
else else
{ {
ch = toupper (*typstr); ch = toupper (*typstr);
free (typstr); mem_free (typstr);
} }
} }
while ((ch != 'D') && (ch != 'W') && (ch != 'M') && (ch != 'Y')); 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 do
{ {
status_mesg (_("Enter the new repetition frequence:"), ""); status_mesg (_("Enter the new repetition frequence:"), "");
freqstr = (char *) malloc (BUFSIZ); freqstr = (char *) mem_malloc (BUFSIZ);
snprintf (freqstr, BUFSIZ, "%d", (*rpt)->freq); (void)snprintf (freqstr, BUFSIZ, "%d", (*rpt)->freq);
cancel = updatestring (win[STA].p, &freqstr, 0, 1); cancel = updatestring (win[STA].p, &freqstr, 0, 1);
if (cancel) if (cancel)
{ {
free (freqstr); mem_free (freqstr);
return; return;
} }
else else
{ {
newfreq = atoi (freqstr); newfreq = atoi (freqstr);
free (freqstr); mem_free (freqstr);
if (newfreq == 0) if (newfreq == 0)
{ {
status_mesg (msg_wrong_freq, msg_enter); status_mesg (msg_wrong_freq, msg_enter);
@ -648,15 +663,15 @@ update_rept (struct rpt_s **rpt, const long start, conf_t *conf)
do 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)); DATEFMT_DESC (conf->input_datefmt));
status_mesg (_(outstr), ""); status_mesg (_(outstr), "");
timstr = timstr =
date_sec2date_str ((*rpt)->until, DATEFMT (conf->input_datefmt)); date_sec2date_str ((*rpt)->until, DATEFMT (conf->input_datefmt));
cancel = updatestring (win[STA].p, &timstr, 0, 1); cancel = updatestring (win[STA].p, &timstr, 0, 1);
if (cancel) if (cancel)
{ {
free (timstr); mem_free (timstr);
return; return;
} }
if (strcmp (timstr, "0") == 0) if (strcmp (timstr, "0") == 0)
@ -691,8 +706,8 @@ update_rept (struct rpt_s **rpt, const long start, conf_t *conf)
} }
else else
{ {
snprintf (outstr, BUFSIZ, msg_fmts, (void)snprintf (outstr, BUFSIZ, msg_fmts,
DATEFMT_DESC (conf->input_datefmt)); DATEFMT_DESC (conf->input_datefmt));
status_mesg (msg_wrong_date, _(outstr)); status_mesg (msg_wrong_date, _(outstr));
(void)wgetch (win[STA].p); (void)wgetch (win[STA].p);
date_entered = 0; date_entered = 0;
@ -701,7 +716,7 @@ update_rept (struct rpt_s **rpt, const long start, conf_t *conf)
} }
while (date_entered == 0); while (date_entered == 0);
free (timstr); mem_free (timstr);
(*rpt)->type = recur_char2def (ch); (*rpt)->type = recur_char2def (ch);
(*rpt)->freq = newfreq; (*rpt)->freq = newfreq;
(*rpt)->until = newuntil; (*rpt)->until = newuntil;
@ -943,7 +958,7 @@ day_edit_note (char *editor)
else else
p->note = filename; 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); wins_launch_external (fullname, editor);
date = calendar_get_slctd_day_sec (); date = calendar_get_slctd_day_sec ();
@ -978,6 +993,6 @@ day_view_note (char *pager)
p = day_get_item (apoint_hilt ()); p = day_get_item (apoint_hilt ());
if (p->note == NULL) if (p->note == NULL)
return; 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); 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 * Calcurse - text-based organizer
@ -67,6 +67,9 @@ struct day_saved_item_s
char *mesg; 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 *); day_items_nb_t *day_process_storage (date_t *, bool, day_items_nb_t *);
void day_write_pad (long, int, int, int); void day_write_pad (long, int, int, int);
void day_popup_item (void); 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 * Calcurse - text-based organizer
@ -31,6 +31,7 @@
#include "vars.h" #include "vars.h"
#include "i18n.h" #include "i18n.h"
#include "mem.h"
#include "event.h" #include "event.h"
struct event_s *eventlist; struct event_s *eventlist;
@ -40,9 +41,8 @@ struct event_s *
event_new (char *mesg, char *note, long day, int id) event_new (char *mesg, char *note, long day, int id)
{ {
struct event_s *o, **i; struct event_s *o, **i;
o = (struct event_s *) malloc (sizeof (struct event_s)); o = (struct event_s *) mem_malloc (sizeof (struct event_s));
o->mesg = (char *) malloc (strlen (mesg) + 1); o->mesg = mem_strdup (mesg);
strncpy (o->mesg, mesg, strlen (mesg) + 1);
o->day = day; o->day = day;
o->id = id; o->id = id;
o->note = (note != NULL) ? strdup (note) : NULL; o->note = (note != NULL) ? strdup (note) : NULL;
@ -80,26 +80,25 @@ event_write (struct event_s *o, FILE *f)
t = o->day; t = o->day;
lt = localtime (&t); 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); 1900 + lt->tm_year, o->id);
if (o->note != NULL) if (o->note != NULL)
fprintf (f, ">%s ", o->note); (void)fprintf (f, ">%s ", o->note);
fprintf (f, "%s\n", o->mesg); (void)fprintf (f, "%s\n", o->mesg);
} }
/* Load the events from file */ /* Load the events from file */
struct event_s * struct event_s *
event_scan (FILE *f, struct tm start, int id, char *note) event_scan (FILE *f, struct tm start, int id, char *note)
{ {
struct tm *lt;
char buf[MESG_MAXSIZE], *nl; char buf[MESG_MAXSIZE], *nl;
time_t tstart, t; time_t tstart, t;
t = time (NULL); t = time (NULL);
lt = localtime (&t); (void)localtime (&t);
/* Read the event description */ /* Read the event description */
fgets (buf, MESG_MAXSIZE, f); (void)fgets (buf, MESG_MAXSIZE, f);
nl = strchr (buf, '\n'); nl = strchr (buf, '\n');
if (nl) if (nl)
{ {
@ -160,9 +159,9 @@ event_delete_bynum (long start, unsigned num, erase_flag_e flag)
else else
{ {
*iptr = i->next; *iptr = i->next;
free (i->mesg); mem_free (i->mesg);
erase_note (&i->note, flag); erase_note (&i->note, flag);
free (i); mem_free (i);
} }
return; 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 * Calcurse - text-based organizer
@ -29,6 +29,10 @@
#include <ctype.h> #include <ctype.h>
#include <sys/types.h> #include <sys/types.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include "i18n.h" #include "i18n.h"
#include "custom.h" #include "custom.h"
#include "utils.h" #include "utils.h"
@ -67,15 +71,15 @@ help_pages_e;
static int static int
get_help_lines (char *text) get_help_lines (char *text)
{ {
int i; int i, newline;
int nl = 0;
newline = 0;
for (i = 0; text[i]; i++) for (i = 0; text[i]; i++)
{ {
if (text[i] == '\n') 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.h = BUFSIZ;
hwin->pad.w = hwin->win.w - 2 * PADOFFSET + 1; 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_scrollwin_init (hwin);
wins_show (hwin->win.p, hwin->label); wins_show (hwin->win.p, hwin->label);
} }
@ -311,7 +315,7 @@ help_screen (void)
hscr[HELP_MAIN].title = hscr[HELP_MAIN].title =
_(" Welcome to Calcurse. This is the main help screen.\n"); _(" 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" _("Moving around: Press '%s' or '%s' to scroll text upward or downward\n"
" inside help screens, if necessary.\n\n" " inside help screens, if necessary.\n\n"
" Exit help: When finished, press '%s' to exit help and go back to\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)); keys_action_firstkey (KEY_GENERIC_CREDITS));
hscr[HELP_SAVE].title = _("Save\n"); hscr[HELP_SAVE].title = _("Save\n");
snprintf (hscr[HELP_SAVE].text, HELPTEXTSIZ, (void)snprintf (hscr[HELP_SAVE].text, HELPTEXTSIZ,
_("Save calcurse data.\n" _("Save calcurse data.\n"
"Data are splitted into four different files which contain :" "Data are splitted into four different files which contain :"
"\n\n" "\n\n"
@ -345,7 +349,7 @@ help_screen (void)
"automatically before quitting.")); "automatically before quitting."));
hscr[HELP_IMPORT].title = _("Import\n"); 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" _("Import data from an icalendar file.\n"
"You will be asked to enter the file name from which to load ical\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" "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")); "the item could not be imported.\n"));
hscr[HELP_EXPORT].title = _("Export\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" _("Export calcurse data (appointments, events and todos).\n"
"This leads to the export submenu, from which you can choose between\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" "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" "Calcurse data are exported in the following order:\n"
" events, appointments, todos.\n")); " events, appointments, todos.\n"));
strncpy (keystr[MOVE_UP], keys_action_allkeys (KEY_MOVE_UP), BUFSIZ); (void)strncpy (keystr[MOVE_UP], keys_action_allkeys (KEY_MOVE_UP), BUFSIZ);
strncpy (keystr[MOVE_DOWN], keys_action_allkeys (KEY_MOVE_DOWN), BUFSIZ); (void)strncpy (keystr[MOVE_DOWN], keys_action_allkeys (KEY_MOVE_DOWN),
strncpy (keystr[MOVE_LEFT], keys_action_allkeys (KEY_MOVE_LEFT), BUFSIZ); BUFSIZ);
strncpy (keystr[MOVE_RIGHT], keys_action_allkeys (KEY_MOVE_RIGHT), 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"); 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" _("Move around inside calcurse screens.\n"
"The following scheme summarizes how to get around:\n\n" "The following scheme summarizes how to get around:\n\n"
" move up\n" " move up\n"
@ -410,7 +417,7 @@ help_screen (void)
keys_action_firstkey (KEY_END_OF_WEEK)); keys_action_firstkey (KEY_END_OF_WEEK));
hscr[HELP_VIEW].title = _("View\n"); 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" _("View the item you select in either the Todo or Appointment panel.\n"
"\nThis is usefull when an event description is longer than the " "\nThis is usefull when an event description is longer than the "
"available\nspace to display it. " "available\nspace to display it. "
@ -423,7 +430,7 @@ help_screen (void)
keys_action_firstkey (KEY_VIEW_ITEM)); keys_action_firstkey (KEY_VIEW_ITEM));
hscr[HELP_TAB].title = _("Tab\n"); hscr[HELP_TAB].title = _("Tab\n");
snprintf (hscr[HELP_TAB].text, HELPTEXTSIZ, (void)snprintf (hscr[HELP_TAB].text, HELPTEXTSIZ,
_("Switch between panels.\n" _("Switch between panels.\n"
"The panel currently in use has its border colorized.\n" "The panel currently in use has its border colorized.\n"
"\nSome actions are possible only if the right panel is selected.\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)); keys_action_firstkey (KEY_GENERIC_CHANGE_VIEW));
hscr[HELP_GOTO].title = _("Goto\n"); 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" _("Jump to a specific day in the calendar.\n"
"\nUsing this command, you do not need to travel to that day using\n" "\nUsing this command, you do not need to travel to that day using\n"
"the displacement keys inside the calendar panel.\n" "the displacement keys inside the calendar panel.\n"
@ -449,7 +456,7 @@ help_screen (void)
keys_action_firstkey (KEY_GENERIC_GOTO_TODAY)); keys_action_firstkey (KEY_GENERIC_GOTO_TODAY));
hscr[HELP_DELETE].title = _("Delete\n"); 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" _("Delete an element in the ToDo or Appointment list.\n"
"\nDepending on which panel is selected when you press the delete key,\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" "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.")); "next time you launch Calcurse."));
hscr[HELP_ADD].title = _("Add\n"); 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" _("Add an item in either the ToDo or Appointment list, depending on which\n"
"panel is selected when you press '%s'.\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" "\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)); keys_action_firstkey (KEY_ADD_ITEM));
hscr[HELP_EDIT].title = _("Edit Item\n"); 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" _("Edit the item which is currently selected.\n"
"Depending on the item type (appointment, event, or todo), and if it is\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" "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.")); " modified properties next time you launch Calcurse."));
hscr[HELP_ENOTE].title = _("EditNote\n"); 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" _("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" "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" "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)); keys_action_firstkey (KEY_EDIT_NOTE));
hscr[HELP_VNOTE].title = _("ViewNote\n"); 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" _("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" "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" "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)); keys_action_firstkey (KEY_VIEW_NOTE));
hscr[HELP_PRIORITY].title = _("Priority\n"); 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" _("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" "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" "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)); keys_action_firstkey (KEY_LOWER_PRIORITY));
hscr[HELP_REPEAT].title = _("Repeat\n"); 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" _("Repeat an event or an appointment.\n"
"You must first select the item to be repeated by moving inside the\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" "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)); keys_action_firstkey (KEY_REPEAT_ITEM));
hscr[HELP_FLAG].title = _("Flag Item\n"); 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" _("Toggle an appointment's 'important' flag.\n"
"If an item is flagged as important, an exclamation mark appears in front" "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" "\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.")); "\nand how long before it he gets notified."));
hscr[HELP_CONFIG].title = _("Config\n"); hscr[HELP_CONFIG].title = _("Config\n");
snprintf (hscr[HELP_CONFIG].text, HELPTEXTSIZ, (void)snprintf (hscr[HELP_CONFIG].text, HELPTEXTSIZ,
_("Open the configuration submenu.\n" _("Open the configuration submenu.\n"
"From this submenu, you can select between color, layout, notification\n" "From this submenu, you can select between color, layout, notification\n"
"and general options, and you can also configure your keybindings.\n" "and general options, and you can also configure your keybindings.\n"
@ -627,7 +634,7 @@ help_screen (void)
"\nnext time you launch Calcurse.")); "\nnext time you launch Calcurse."));
hscr[HELP_GENERAL].title = _("Generic keybindings\n"); 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" _("Some of the keybindings apply whatever panel is selected. They are\n"
"called generic keybinding.\n" "called generic keybinding.\n"
"Here is the list of all the generic key bindings, together with their\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)); keys_action_firstkey (KEY_GENERIC_GOTO_TODAY));
hscr[HELP_OTHER].title = _("OtherCmd\n"); 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" _("Switch between status bar help pages.\n"
"Because the terminal screen is too narrow to display all of the\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" "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)); keys_action_firstkey (KEY_GENERIC_OTHER_CMD));
hscr[HELP_CREDITS].title = _("Calcurse - text-based organizer"); 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" _("\nCopyright (c) 2004-2008 Frederic Culot\n"
"\n" "\n"
"This program is free software; you can redistribute it and/or modify\n" "This program is free software; you can redistribute it and/or modify\n"

514
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 * Calcurse - text-based organizer
@ -30,6 +30,7 @@
#include "i18n.h" #include "i18n.h"
#include "utils.h" #include "utils.h"
#include "custom.h" #include "custom.h"
#include "mem.h"
#include "keys.h" #include "keys.h"
#define MAXKEYVAL KEY_MAX /* ncurses defines KEY_MAX as maximum key value */ #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" "# A description of what each ACTION keyword is used for is available\n"
"# from calcurse online configuration menu.\n"); "# from calcurse online configuration menu.\n");
fprintf (fd, "%s\n", intro); (void)fprintf (fd, "%s\n", intro);
} }
void void
@ -126,6 +127,28 @@ keys_init (void)
bzero (keys, NBKEYS); 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 void
keys_dump_defaults (char *file) keys_dump_defaults (char *file)
{ {
@ -137,8 +160,8 @@ keys_dump_defaults (char *file)
dump_intro (fd); dump_intro (fd);
for (i = 0; i < NBKEYS; i++) for (i = 0; i < NBKEYS; i++)
fprintf (fd, "%s %s\n", keydef[i].label, keydef[i].binding); (void)fprintf (fd, "%s %s\n", keydef[i].label, keydef[i].binding);
fclose (fd); file_close (fd, __FILE_POS__);
} }
char * char *
@ -182,8 +205,8 @@ add_key_str (keys_e action, int key)
if (action < 0 || action > NBKEYS) if (action < 0 || action > NBKEYS)
return; return;
new = malloc (sizeof (struct key_str_s)); new = mem_malloc (sizeof (struct key_str_s));
new->str = strdup (keys_int2str (key)); new->str = mem_strdup (keys_int2str (key));
new->next = NULL; new->next = NULL;
i = &keys[action]; i = &keys[action];
for (;;) for (;;)
@ -221,20 +244,17 @@ del_key_str (keys_e action, int key)
{ {
struct key_str_s *old, **i; struct key_str_s *old, **i;
char oldstr[BUFSIZ]; char oldstr[BUFSIZ];
int oldstrlen;
if (action < 0 || action > NBKEYS) if (action < 0 || action > NBKEYS)
return; return;
strncpy (oldstr, keys_int2str (key), BUFSIZ); (void)strncpy (oldstr, keys_int2str (key), BUFSIZ);
oldstrlen = strlen (oldstr);
for (i = &keys[action]; *i; i = &(*i)->next) for (i = &keys[action]; *i; i = &(*i)->next)
{ {
if (strlen ((*i)->str) == oldstrlen if (!strcmp ((*i)->str, oldstr))
&& !(strncmp ((*i)->str, oldstr, oldstrlen)))
{ {
old = (*i); old = *i;
(*i) = old->next; *i = old->next;
mem_free (old->str); mem_free (old->str);
mem_free (old); mem_free (old);
break; break;
@ -367,8 +387,8 @@ keys_action_allkeys (keys_e action)
for (i = keys[action]; i; i = i->next) for (i = keys[action]; i; i = i->next)
{ {
const int MAXLEN = sizeof (keystr) - 1 - strlen (keystr); const int MAXLEN = sizeof (keystr) - 1 - strlen (keystr);
strncat (keystr, i->str, MAXLEN - 1); (void)strncat (keystr, i->str, MAXLEN - 1);
strncat (keystr, CHAR_SPACE, 1); (void)strncat (keystr, CHAR_SPACE, 1);
} }
return keystr; return keystr;
@ -388,18 +408,18 @@ keys_format_label (char *key, int keylen)
bzero (fmtkey, sizeof (fmtkey)); bzero (fmtkey, sizeof (fmtkey));
if (len == 0) if (len == 0)
snprintf (fmtkey, sizeof (fmtkey), "?"); (void)snprintf (fmtkey, sizeof (fmtkey), "?");
else if (len <= keylen) else if (len <= keylen)
{ {
for (i = 0; i < keylen - len; i++) for (i = 0; i < keylen - len; i++)
fmtkey[i] = ' '; fmtkey[i] = ' ';
strncat (fmtkey, key, keylen); (void)strncat (fmtkey, key, keylen);
} }
else else
{ {
for (i = 0; i < keylen - 1; i++) for (i = 0; i < keylen - 1; i++)
fmtkey[i] = key[i]; fmtkey[i] = key[i];
strncat (fmtkey, dot, strlen (dot)); (void)strncat (fmtkey, dot, strlen (dot));
} }
return fmtkey; 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 KEY_POS = j * cmdlen;
const int LABEL_POS = j * cmdlen + KEYS_KEYLEN + 1; 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); fmtkey = keys_format_label (key, KEYS_KEYLEN);
custom_apply_attr (win, ATTR_HIGHEST); custom_apply_attr (win, ATTR_HIGHEST);
mvwprintw (win, 0, KEY_POS, fmtkey); mvwprintw (win, 0, KEY_POS, fmtkey);
if (i + 1 != last_key) 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); KEYS_KEYLEN);
fmtkey = keys_format_label (key, KEYS_KEYLEN); fmtkey = keys_format_label (key, KEYS_KEYLEN);
mvwprintw (win, 1, KEY_POS, fmtkey); mvwprintw (win, 1, KEY_POS, fmtkey);
} }
@ -541,7 +562,7 @@ keys_popup_info (keys_e key)
#define WINCOL (col - 4) #define WINCOL (col - 4)
infowin = popup (WINROW, WINCOL, (row - WINROW) / 2, (col - WINCOL) / 2, infowin = popup (WINROW, WINCOL, (row - WINROW) / 2, (col - WINCOL) / 2,
keydef[key].label, info[key], 1); keydef[key].label, info[key], 1);
keys_getch (infowin); (void)keys_getch (infowin);
delwin (infowin); delwin (infowin);
#undef WINROW #undef WINROW
#undef WINCOL #undef WINCOL
@ -555,7 +576,7 @@ keys_save_bindings (FILE *fd)
EXIT_IF (fd == NULL, _("FATAL ERROR: null file pointer.")); EXIT_IF (fd == NULL, _("FATAL ERROR: null file pointer."));
dump_intro (fd); dump_intro (fd);
for (i = 0; i < NBKEYS; i++) 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 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 * Calcurse - text-based organizer
@ -90,6 +90,7 @@ typedef struct {
} binding_t; } binding_t;
void keys_init (void); void keys_init (void);
void keys_free (void);
void keys_dump_defaults (char *); void keys_dump_defaults (char *);
char *keys_get_label (keys_e); char *keys_get_label (keys_e);
keys_e keys_get_action (int); 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 * Calcurse - text-based organizer
@ -29,10 +29,15 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include "i18n.h" #include "i18n.h"
#include "utils.h" #include "utils.h"
#include "custom.h" #include "custom.h"
#include "keys.h" #include "keys.h"
#include "mem.h"
#include "notify.h" #include "notify.h"
static struct notify_vars_s *notify = NULL; static struct notify_vars_s *notify = NULL;
@ -61,13 +66,13 @@ notify_init_vars (void)
char *date_format = "%a %F"; char *date_format = "%a %F";
char *cmd = "printf '\\a'"; 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); pthread_mutex_init (&nbar->mutex, NULL);
nbar->show = 1; nbar->show = 1;
nbar->cntdwn = 300; nbar->cntdwn = 300;
strncpy (nbar->datefmt, date_format, strlen (date_format) + 1); (void)strncpy (nbar->datefmt, date_format, strlen (date_format) + 1);
strncpy (nbar->timefmt, time_format, strlen (time_format) + 1); (void)strncpy (nbar->timefmt, time_format, strlen (time_format) + 1);
strncpy (nbar->cmd, cmd, strlen (cmd) + 1); (void)strncpy (nbar->cmd, cmd, strlen (cmd) + 1);
if ((nbar->shell = getenv ("SHELL")) == NULL) if ((nbar->shell = getenv ("SHELL")) == NULL)
nbar->shell = "/bin/sh"; nbar->shell = "/bin/sh";
@ -77,6 +82,12 @@ notify_init_vars (void)
PTHREAD_CREATE_DETACHED); PTHREAD_CREATE_DETACHED);
} }
void
notify_free_vars (void)
{
mem_free (nbar);
}
/* Extract the appointment file name from the complete file path. */ /* Extract the appointment file name from the complete file path. */
static void static void
extract_aptsfile (void) extract_aptsfile (void)
@ -101,8 +112,8 @@ extract_aptsfile (void)
void void
notify_init_bar (void) notify_init_bar (void)
{ {
notify = (struct notify_vars_s *) malloc (sizeof (struct notify_vars_s)); notify = (struct notify_vars_s *) mem_malloc (sizeof (struct notify_vars_s));
notify_app = (struct notify_app_s *) malloc (sizeof (struct notify_app_s)); notify_app = (struct notify_app_s *) mem_malloc (sizeof (struct notify_app_s));
pthread_mutex_init (&notify->mutex, NULL); pthread_mutex_init (&notify->mutex, NULL);
pthread_mutex_init (&notify_app->mutex, NULL); pthread_mutex_init (&notify_app->mutex, NULL);
notify_app->got_app = 0; notify_app->got_app = 0;
@ -110,6 +121,13 @@ notify_init_bar (void)
extract_aptsfile (); extract_aptsfile ();
} }
void
notify_free_bar (void)
{
mem_free (notify_app);
mem_free (notify);
}
/* Stop the notify-bar main thread. */ /* Stop the notify-bar main thread. */
void void
notify_stop_main_thread (void) notify_stop_main_thread (void)
@ -177,7 +195,7 @@ notify_update_bar (void)
if (strlen (notify_app->txt) > txt_max_len) if (strlen (notify_app->txt) > txt_max_len)
{ {
too_long = 1; 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'; buf[txt_max_len - 3] = '\0';
} }
time_left = notify_app->time - notify->time_in_sec; time_left = notify_app->time - notify->time_in_sec;
@ -229,6 +247,7 @@ notify_update_bar (void)
} }
/* Update the notication bar content */ /* Update the notication bar content */
/* ARGSUSED0 */
static void * static void *
notify_main_thread (void *arg) notify_main_thread (void *arg)
{ {
@ -253,7 +272,7 @@ notify_main_thread (void *arg)
pthread_mutex_unlock (&nbar->mutex); pthread_mutex_unlock (&nbar->mutex);
pthread_mutex_unlock (&notify->mutex); pthread_mutex_unlock (&notify->mutex);
notify_update_bar (); notify_update_bar ();
sleep (thread_sleep); (void)sleep (thread_sleep);
elapse += thread_sleep; elapse += thread_sleep;
if (elapse >= check_app) if (elapse >= check_app)
{ {
@ -269,6 +288,7 @@ notify_main_thread (void *arg)
} }
/* Look for the next appointment within the next 24 hours. */ /* Look for the next appointment within the next 24 hours. */
/* ARGSUSED0 */
static void * static void *
notify_thread_app (void *arg) notify_thread_app (void *arg)
{ {
@ -300,7 +320,7 @@ notify_thread_app (void *arg)
pthread_mutex_unlock (&notify_app->mutex); pthread_mutex_unlock (&notify_app->mutex);
if (tmp_app.txt != NULL) if (tmp_app.txt != NULL)
free (tmp_app.txt); mem_free (tmp_app.txt);
notify_update_bar (); notify_update_bar ();
pthread_exit ((void *) 0); pthread_exit ((void *) 0);
@ -452,33 +472,33 @@ notify_print_options (WINDOW *optwin, int col)
y_offset = 3; y_offset = 3;
maxcol = col - 2; maxcol = col - 2;
strncpy (opt[SHOW].name, _("notify-bar_show = "), BUFSIZ); (void)strncpy (opt[SHOW].name, _("notify-bar_show = "), BUFSIZ);
strncpy (opt[DATE].name, _("notify-bar_date = "), BUFSIZ); (void)strncpy (opt[DATE].name, _("notify-bar_date = "), BUFSIZ);
strncpy (opt[CLOCK].name, _("notify-bar_clock = "), BUFSIZ); (void)strncpy (opt[CLOCK].name, _("notify-bar_clock = "), BUFSIZ);
strncpy (opt[WARN].name, _("notify-bar_warning = "), BUFSIZ); (void)strncpy (opt[WARN].name, _("notify-bar_warning = "), BUFSIZ);
strncpy (opt[CMD].name, _("notify-bar_command = "), 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); _("(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)"), _("(Format of the date to be displayed inside notify-bar)"),
BUFSIZ); BUFSIZ);
strncpy (opt[CLOCK].desc, (void)strncpy (opt[CLOCK].desc,
_("(Format of the time to be displayed inside notify-bar)"), _("(Format of the time to be displayed inside notify-bar)"),
BUFSIZ); BUFSIZ);
strncpy (opt[WARN].desc, (void)strncpy (opt[WARN].desc,
_("(Warn user if an appointment is within next 'notify-bar_warning'" _("(Warn user if an appointment is within next "
" seconds)"), BUFSIZ); "'notify-bar_warning' seconds)"), BUFSIZ);
strncpy (opt[CMD].desc, (void)strncpy (opt[CMD].desc,
_("(Command used to notify user of an upcoming appointment)"), _("(Command used to notify user of an upcoming appointment)"),
BUFSIZ); BUFSIZ);
pthread_mutex_lock (&nbar->mutex); pthread_mutex_lock (&nbar->mutex);
strncpy (opt[DATE].value, nbar->datefmt, BUFSIZ); (void)strncpy (opt[DATE].value, nbar->datefmt, BUFSIZ);
strncpy (opt[CLOCK].value, nbar->timefmt, BUFSIZ); (void)strncpy (opt[CLOCK].value, nbar->timefmt, BUFSIZ);
snprintf (opt[WARN].value, BUFSIZ, "%d", nbar->cntdwn); (void)snprintf (opt[WARN].value, BUFSIZ, "%d", nbar->cntdwn);
strncpy (opt[CMD].value, nbar->cmd, BUFSIZ); (void)strncpy (opt[CMD].value, nbar->cmd, BUFSIZ);
l = strlen (opt[SHOW].name); l = strlen (opt[SHOW].name);
x = x_pos + x_offset + l; 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); mvwprintw (optwin, y, x, "%s", opt[i].value);
else else
{ {
strncpy (buf, opt[i].value, maxlen - 1); (void)strncpy (buf, opt[i].value, maxlen - 1);
buf[maxlen - 1] = '\0'; buf[maxlen - 1] = '\0';
mvwprintw (optwin, y, x, "%s...", buf); mvwprintw (optwin, y, x, "%s...", buf);
} }
@ -533,8 +553,9 @@ notify_config_bar (void)
char *cmd_str = _("Enter the notification command "); char *cmd_str = _("Enter the notification command ");
int ch = 0, change_win = 1; int ch = 0, change_win = 1;
buf = (char *) malloc (BUFSIZ); buf = (char *) mem_malloc (BUFSIZ);
snprintf (label, BUFSIZ, _("CalCurse %s | notify-bar options"), VERSION); (void)snprintf (label, BUFSIZ, _("CalCurse %s | notify-bar options"),
VERSION);
custom_confwin_init (&conf_win, label); custom_confwin_init (&conf_win, label);
while (ch != 'q') while (ch != 'q')
@ -569,12 +590,12 @@ notify_config_bar (void)
case '2': case '2':
status_mesg (date_str, ""); status_mesg (date_str, "");
pthread_mutex_lock (&nbar->mutex); 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); pthread_mutex_unlock (&nbar->mutex);
if (updatestring (win[STA].p, &buf, 0, 1) == 0) if (updatestring (win[STA].p, &buf, 0, 1) == 0)
{ {
pthread_mutex_lock (&nbar->mutex); 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); pthread_mutex_unlock (&nbar->mutex);
} }
change_win = 0; change_win = 0;
@ -582,12 +603,12 @@ notify_config_bar (void)
case '3': case '3':
status_mesg (time_str, ""); status_mesg (time_str, "");
pthread_mutex_lock (&nbar->mutex); 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); pthread_mutex_unlock (&nbar->mutex);
if (updatestring (win[STA].p, &buf, 0, 1) == 0) if (updatestring (win[STA].p, &buf, 0, 1) == 0)
{ {
pthread_mutex_lock (&nbar->mutex); 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); pthread_mutex_unlock (&nbar->mutex);
} }
change_win = 0; change_win = 0;
@ -609,18 +630,18 @@ notify_config_bar (void)
case '5': case '5':
status_mesg (cmd_str, ""); status_mesg (cmd_str, "");
pthread_mutex_lock (&nbar->mutex); 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); pthread_mutex_unlock (&nbar->mutex);
if (updatestring (win[STA].p, &buf, 0, 1) == 0) if (updatestring (win[STA].p, &buf, 0, 1) == 0)
{ {
pthread_mutex_lock (&nbar->mutex); 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); pthread_mutex_unlock (&nbar->mutex);
} }
change_win = 0; change_win = 0;
break; break;
} }
} }
free (buf); mem_free (buf);
delwin (conf_win.p); 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 * Calcurse - text-based organizer
@ -54,7 +54,9 @@ struct notify_app_s
int notify_bar (void); int notify_bar (void);
void notify_init_vars (void); void notify_init_vars (void);
void notify_free_vars (void);
void notify_init_bar (void); void notify_init_bar (void);
void notify_free_bar (void);
void notify_start_main_thread (void); void notify_start_main_thread (void);
void notify_stop_main_thread (void); void notify_stop_main_thread (void);
void notify_reinit_bar (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 * Calcurse - text-based organizer
@ -35,20 +35,55 @@
#include "notify.h" #include "notify.h"
#include "day.h" #include "day.h"
#include "keys.h" #include "keys.h"
#include "mem.h"
#include "recur.h" #include "recur.h"
recur_apoint_llist_t *recur_alist_p; recur_apoint_llist_t *recur_alist_p;
struct recur_event_s *recur_elist; struct recur_event_s *recur_elist;
int void
recur_apoint_llist_init (void) recur_apoint_llist_init (void)
{ {
recur_alist_p = (recur_apoint_llist_t *) recur_alist_p = mem_malloc (sizeof (recur_apoint_llist_t));
malloc (sizeof (recur_apoint_llist_t));
recur_alist_p->root = NULL; recur_alist_p->root = NULL;
pthread_mutex_init (&(recur_alist_p->mutex), 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 */ /* 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; recur_apoint_llist_node_t *o, **i;
o = (recur_apoint_llist_node_t *) o = (recur_apoint_llist_node_t *)
malloc (sizeof (recur_apoint_llist_node_t)); mem_malloc (sizeof (recur_apoint_llist_node_t));
o->rpt = (struct rpt_s *) malloc (sizeof (struct rpt_s)); o->rpt = (struct rpt_s *) mem_malloc (sizeof (struct rpt_s));
o->mesg = (char *) malloc (strlen (mesg) + 1); o->mesg = mem_strdup (mesg);
strncpy (o->mesg, mesg, strlen (mesg) + 1);
o->note = (note != NULL) ? strdup (note) : NULL; o->note = (note != NULL) ? strdup (note) : NULL;
o->start = start; o->start = start;
o->state = state; 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) long until, struct days_s *except)
{ {
struct recur_event_s *o, **i; struct recur_event_s *o, **i;
o = (struct recur_event_s *) malloc (sizeof (struct recur_event_s)); o = (struct recur_event_s *) mem_malloc (sizeof (struct recur_event_s));
o->rpt = (struct rpt_s *) malloc (sizeof (struct rpt_s)); o->rpt = (struct rpt_s *) mem_malloc (sizeof (struct rpt_s));
o->mesg = (char *) malloc (strlen (mesg) + 1); o->mesg = mem_strdup (mesg);
o->note = (note != NULL) ? strdup (note) : NULL; (void)strncpy (o->mesg, mesg, strlen (mesg) + 1);
strncpy (o->mesg, mesg, strlen (mesg) + 1);
o->day = day; o->day = day;
o->id = id; o->id = id;
o->rpt->type = type; o->rpt->type = type;
@ -195,7 +228,7 @@ recur_write_exc (struct days_s *exc, FILE *f)
st_mon = lt->tm_mon + 1; st_mon = lt->tm_mon + 1;
st_day = lt->tm_mday; st_day = lt->tm_mday;
st_year = lt->tm_year + 1900; 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; exc = exc->next;
} }
} }
@ -214,7 +247,7 @@ recur_apoint_scan (FILE *f, struct tm start, struct tm end, char type,
lt = localtime (&t); lt = localtime (&t);
/* Read the appointment description */ /* Read the appointment description */
fgets (buf, MESG_MAXSIZE, f); (void)fgets (buf, MESG_MAXSIZE, f);
nl = strchr (buf, '\n'); nl = strchr (buf, '\n');
if (nl) if (nl)
{ {
@ -263,7 +296,7 @@ recur_event_scan (FILE *f, struct tm start, int id, char type, int freq,
lt = localtime (&t); lt = localtime (&t);
/* Read the event description */ /* Read the event description */
fgets (buf, MESG_MAXSIZE, f); (void)fgets (buf, MESG_MAXSIZE, f);
nl = strchr (buf, '\n'); nl = strchr (buf, '\n');
if (nl) if (nl)
{ {
@ -302,38 +335,38 @@ recur_apoint_write (recur_apoint_llist_node_t *o, FILE *f)
t = o->start; t = o->start;
lt = localtime (&t); 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_mon + 1, lt->tm_mday, 1900 + lt->tm_year,
lt->tm_hour, lt->tm_min); lt->tm_hour, lt->tm_min);
t = o->start + o->dur; t = o->start + o->dur;
lt = localtime (&t); 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_mon + 1, lt->tm_mday, 1900 + lt->tm_year,
lt->tm_hour, lt->tm_min); lt->tm_hour, lt->tm_min);
t = o->rpt->until; t = o->rpt->until;
if (t == 0) if (t == 0)
{ /* We have an endless recurrent appointment. */ { /* 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 else
{ {
lt = localtime (&t); 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), o->rpt->freq, recur_def2char (o->rpt->type),
lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year); lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year);
} }
if (o->exc != 0) if (o->exc != 0)
recur_write_exc (o->exc, f); recur_write_exc (o->exc, f);
fprintf (f, "} "); (void)fprintf (f, "} ");
if (o->note != NULL) if (o->note != NULL)
fprintf (f, ">%s ", o->note); (void)fprintf (f, ">%s ", o->note);
if (o->state & APOINT_NOTIFY) if (o->state & APOINT_NOTIFY)
fprintf (f, "!"); (void)fprintf (f, "!");
else else
fprintf (f, "|"); (void)fprintf (f, "|");
fprintf (f, "%s\n", o->mesg); (void)fprintf (f, "%s\n", o->mesg);
} }
/* Writting of a recursive event into file. */ /* 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; t = o->rpt->until;
if (t == 0) if (t == 0)
{ /* We have an endless recurrent event. */ { /* 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, st_mon, st_day, st_year, o->id, o->rpt->freq,
recur_def2char (o->rpt->type)); recur_def2char (o->rpt->type));
} }
else else
{ {
@ -363,17 +396,17 @@ recur_event_write (struct recur_event_s *o, FILE *f)
end_mon = lt->tm_mon + 1; end_mon = lt->tm_mon + 1;
end_day = lt->tm_mday; end_day = lt->tm_mday;
end_year = lt->tm_year + 1900; 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, st_mon, st_day, st_year, o->id,
o->rpt->freq, recur_def2char (o->rpt->type), o->rpt->freq, recur_def2char (o->rpt->type),
end_mon, end_day, end_year); end_mon, end_day, end_year);
} }
if (o->exc != 0) if (o->exc != 0)
recur_write_exc (o->exc, f); recur_write_exc (o->exc, f);
fprintf (f, "} "); (void)fprintf (f, "} ");
if (o->note != NULL) if (o->note != NULL)
fprintf (f, ">%s ", o->note); (void)fprintf (f, ">%s ", o->note);
fprintf (f, "%s\n", o->mesg); (void)fprintf (f, "%s\n", o->mesg);
} }
/* Write recursive items to file. */ /* Write recursive items to file. */
@ -503,17 +536,17 @@ recur_event_erase (long start, unsigned num, unsigned delete_whole,
else else
{ {
*iptr = i->next; *iptr = i->next;
free (i->mesg); mem_free (i->mesg);
free (i->rpt); mem_free (i->rpt);
free (i->exc); mem_free (i->exc);
erase_note (&i->note, flag); erase_note (&i->note, flag);
free (i); mem_free (i);
} }
return; return;
} }
else else
{ {
o = (struct days_s *) malloc (sizeof (struct days_s)); o = (struct days_s *) mem_malloc (sizeof (struct days_s));
o->st = start; o->st = start;
j = &i->exc; j = &i->exc;
for (;;) for (;;)
@ -568,11 +601,11 @@ recur_apoint_erase (long start, unsigned num, unsigned delete_whole,
else else
{ {
*iptr = i->next; *iptr = i->next;
free (i->mesg); mem_free (i->mesg);
free (i->rpt); mem_free (i->rpt);
free (i->exc); mem_free (i->exc);
erase_note (&i->note, flag); erase_note (&i->note, flag);
free (i); mem_free (i);
pthread_mutex_unlock (&(recur_alist_p->mutex)); pthread_mutex_unlock (&(recur_alist_p->mutex));
if (need_check_notify) if (need_check_notify)
notify_check_next_app (); notify_check_next_app ();
@ -581,7 +614,7 @@ recur_apoint_erase (long start, unsigned num, unsigned delete_whole,
} }
else else
{ {
o = (struct days_s *) malloc (sizeof (struct days_s)); o = (struct days_s *) mem_malloc (sizeof (struct days_s));
o->st = start; o->st = start;
j = &i->exc; j = &i->exc;
for (;;) for (;;)
@ -692,8 +725,8 @@ recur_repeat_item (conf_t *conf)
while (!date_entered) while (!date_entered)
{ {
snprintf (outstr, BUFSIZ, mesg_until_1, (void)snprintf (outstr, BUFSIZ, mesg_until_1,
DATEFMT_DESC (conf->input_datefmt)); DATEFMT_DESC (conf->input_datefmt));
status_mesg (_(outstr), ""); status_mesg (_(outstr), "");
if (getstring (win[STA].p, user_input, BUFSIZ, 0, 1) == GETSTRING_VALID) if (getstring (win[STA].p, user_input, BUFSIZ, 0, 1) == GETSTRING_VALID)
{ {
@ -726,8 +759,8 @@ recur_repeat_item (conf_t *conf)
} }
else else
{ {
snprintf (outstr, BUFSIZ, mesg_wrong_2, (void)snprintf (outstr, BUFSIZ, mesg_wrong_2,
DATEFMT_DESC (conf->input_datefmt)); DATEFMT_DESC (conf->input_datefmt));
status_mesg (mesg_wrong_1, _(outstr)); status_mesg (mesg_wrong_1, _(outstr));
(void)wgetch (win[STA].p); (void)wgetch (win[STA].p);
date_entered = 0; date_entered = 0;
@ -777,7 +810,7 @@ recur_exc_scan (FILE *data_file)
day = *lt; day = *lt;
while ((c = getc (data_file)) == '!') while ((c = getc (data_file)) == '!')
{ {
ungetc (c, data_file); (void)ungetc (c, data_file);
if (fscanf (data_file, "!%u / %u / %u ", if (fscanf (data_file, "!%u / %u / %u ",
&day.tm_mon, &day.tm_mday, &day.tm_year) != 3) &day.tm_mon, &day.tm_mday, &day.tm_year) != 3)
{ {
@ -787,7 +820,7 @@ recur_exc_scan (FILE *data_file)
day.tm_isdst = -1; day.tm_isdst = -1;
day.tm_year -= 1900; day.tm_year -= 1900;
day.tm_mon--; 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->st = mktime (&day);
exc->next = exc_head; exc->next = exc_head;
exc_head = exc; 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 * 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 recur_apoint_llist_t *recur_alist_p;
extern struct recur_event_s *recur_elist; 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, recur_apoint_llist_node_t *recur_apoint_new (char *, char *, long, long, char,
int, int, long, struct days_s *); int, int, long, struct days_s *);
struct recur_event_s *recur_event_new (char *, char *, long, int, int, int, 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 * Calcurse - text-based organizer
@ -26,12 +26,10 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <stdlib.h>
#include <signal.h> #include <signal.h>
#include "i18n.h" #include "i18n.h"
#include "vars.h" #include "utils.h"
#include "wins.h"
/* /*
* General signal handling routine. * General signal handling routine.
@ -50,7 +48,7 @@ signal_handler (int sig)
break; break;
case SIGWINCH: case SIGWINCH:
clearok (curscr, TRUE); clearok (curscr, TRUE);
ungetch (KEY_RESIZE); (void)ungetch (KEY_RESIZE);
break; break;
} }
} }
@ -64,8 +62,8 @@ sigs_init (struct sigaction *sa)
sigemptyset (&sa->sa_mask); sigemptyset (&sa->sa_mask);
if (sigaction (SIGCHLD, sa, NULL) != 0) if (sigaction (SIGCHLD, sa, NULL) != 0)
{ {
perror ("sigaction"); ERROR_MSG (_("Error handling SIGCHLD signal"));
exit (EXIT_FAILURE); exit_calcurse (1);
} }
sa->sa_handler = signal_handler; sa->sa_handler = signal_handler;
@ -73,8 +71,8 @@ sigs_init (struct sigaction *sa)
sigemptyset (&sa->sa_mask); sigemptyset (&sa->sa_mask);
if (sigaction (SIGWINCH, sa, NULL) != 0) if (sigaction (SIGWINCH, sa, NULL) != 0)
{ {
perror ("sigaction"); ERROR_MSG (_("Error handling SIGWINCH signal"));
exit (EXIT_FAILURE); exit_calcurse (1);
} }
sa->sa_handler = SIG_IGN; sa->sa_handler = SIG_IGN;
@ -82,7 +80,7 @@ sigs_init (struct sigaction *sa)
sigemptyset (&(sa->sa_mask)); sigemptyset (&(sa->sa_mask));
if (sigaction (SIGINT, sa, NULL) != 0) if (sigaction (SIGINT, sa, NULL) != 0)
{ {
perror ("sigaction"); ERROR_MSG (_("Error handling SIGINT signal"));
exit (EXIT_FAILURE); 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 * Calcurse - text-based organizer
@ -32,6 +32,7 @@
#include "custom.h" #include "custom.h"
#include "keys.h" #include "keys.h"
#include "i18n.h" #include "i18n.h"
#include "mem.h"
#include "todo.h" #include "todo.h"
struct todo_s *todolist; struct todo_s *todolist;
@ -158,10 +159,10 @@ struct todo_s *
todo_add (char *mesg, int id, char *note) todo_add (char *mesg, int id, char *note)
{ {
struct todo_s *o, **i; struct todo_s *o, **i;
o = (struct todo_s *) malloc (sizeof (struct todo_s)); o = (struct todo_s *) mem_malloc (sizeof (struct todo_s));
o->mesg = strdup (mesg); o->mesg = mem_strdup (mesg);
o->id = id; 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; i = &todolist;
for (;;) for (;;)
{ {
@ -215,10 +216,10 @@ todo_delete_bynum (unsigned num, erase_flag_e flag)
if (n == num) if (n == num)
{ {
*iptr = i->next; *iptr = i->next;
free (i->mesg); mem_free (i->mesg);
if (i->note != NULL) if (i->note != NULL)
erase_note (&i->note, flag); erase_note (&i->note, flag);
free (i); mem_free (i);
return; return;
} }
iptr = &i->next; iptr = &i->next;
@ -337,10 +338,10 @@ todo_chg_priority (int action)
int do_chg = 1; int do_chg = 1;
backup = todo_get_item (hilt); 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; backup_id = backup->id;
if (backup->note) if (backup->note)
strncpy (backup_note, backup->note, NOTESIZ + 1); (void)strncpy (backup_note, backup->note, NOTESIZ + 1);
else else
backup_note[0] = '\0'; backup_note[0] = '\0';
switch (action) 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); mvwprintw (w, y, x, "%d%c %s", prio, ch_note, msg);
else else
{ {
strncpy (buf, msg, len - 1); (void)strncpy (buf, msg, len - 1);
buf[len - 1] = '\0'; buf[len - 1] = '\0';
mvwprintw (w, y, x, "%d%c %s...", prio, ch_note, buf); mvwprintw (w, y, x, "%d%c %s...", prio, ch_note, buf);
} }
@ -467,7 +468,7 @@ todo_edit_note (char *editor)
else else
return; 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); wins_launch_external (fullname, editor);
} }
@ -481,6 +482,25 @@ todo_view_note (char *pager)
i = todo_get_item (hilt); i = todo_get_item (hilt);
if (i->note == NULL) if (i->note == NULL)
return; 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); 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 * Calcurse - text-based organizer
@ -56,5 +56,6 @@ void todo_edit_item (void);
void todo_update_panel (int); void todo_update_panel (int);
void todo_edit_note (char *); void todo_edit_note (char *);
void todo_view_note (char *); void todo_view_note (char *);
void todo_free_list (void);
#endif /* CALCURSE_TODO_H */ #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 * Calcurse - text-based organizer
@ -34,11 +34,19 @@
#include <math.h> #include <math.h>
#include <errno.h> #include <errno.h>
#include "utils.h"
#include "i18n.h" #include "i18n.h"
#include "notify.h"
#include "wins.h" #include "wins.h"
#include "custom.h" #include "custom.h"
#include "keys.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_CAL_CMDS 24 /* number of commands while in cal view */
#define NB_APP_CMDS 29 /* same thing while in appointment view */ #define NB_APP_CMDS 29 /* same thing while in appointment view */
@ -52,11 +60,24 @@ static unsigned status_page;
void void
exit_calcurse (int status) exit_calcurse (int status)
{ {
clear (); if (ui_mode == UI_CURSES)
refresh (); {
endwin (); clear ();
ui_mode = UI_CMDLINE; refresh ();
endwin ();
ui_mode = UI_CMDLINE;
}
calendar_stop_date_thread (); 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); exit (status);
} }
@ -72,7 +93,7 @@ fatalbox (const char *errmsg)
const int MSGLEN = WINCOL - 2; const int MSGLEN = WINCOL - 2;
char msg[MSGLEN]; char msg[MSGLEN];
strncpy (msg, errmsg, MSGLEN); (void)strncpy (msg, errmsg, MSGLEN);
errwin = newwin (WINROW, WINCOL, (row - WINROW) / 2, (col - WINCOL) / 2); errwin = newwin (WINROW, WINCOL, (row - WINROW) / 2, (col - WINCOL) / 2);
custom_apply_attr (errwin, ATTR_HIGHEST); custom_apply_attr (errwin, ATTR_HIGHEST);
box (errwin, 0, 0); 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); mvwprintw (popup_win, MSGXPOS, (pop_col - strlen (msg)) / 2, "%s", msg);
custom_apply_attr (popup_win, ATTR_HIGHEST); custom_apply_attr (popup_win, ATTR_HIGHEST);
box (popup_win, 0, 0); box (popup_win, 0, 0);
snprintf (label, BUFSIZ, "%s", title); (void)snprintf (label, BUFSIZ, "%s", title);
wins_show (popup_win, label); wins_show (popup_win, label);
if (hint) if (hint)
mvwprintw (popup_win, pop_row - 2, pop_col - (strlen (any_key) + 1), "%s", 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; char *newstr;
int escape, len = strlen (*str) + 1; int escape, len = strlen (*str) + 1;
newstr = (char *) malloc (BUFSIZ); newstr = (char *) mem_malloc (BUFSIZ);
(void) memcpy (newstr, *str, len); (void) memcpy (newstr, *str, len);
escape = getstring (win, newstr, BUFSIZ, x, y); escape = getstring (win, newstr, BUFSIZ, x, y);
if (!escape) if (!escape)
@ -373,7 +394,7 @@ updatestring (WINDOW *win, char **str, int x, int y)
EXIT_IF (*str == 0, _("out of memory")); EXIT_IF (*str == 0, _("out of memory"));
(void) memcpy (*str, newstr, len); (void) memcpy (*str, newstr, len);
} }
free (newstr); mem_free (newstr);
return (escape); return (escape);
} }
@ -502,8 +523,8 @@ date_sec2hour_str (long sec)
t = sec; t = sec;
lt = localtime (&t); lt = localtime (&t);
timestr = (char *) malloc (TIME_LEN); timestr = (char *) mem_malloc (TIME_LEN);
snprintf (timestr, TIME_LEN, "%02u:%02u", lt->tm_hour, lt->tm_min); (void)snprintf (timestr, TIME_LEN, "%02u:%02u", lt->tm_hour, lt->tm_min);
return (timestr); return (timestr);
} }
@ -515,10 +536,10 @@ date_sec2date_str (long sec, char *datefmt)
time_t t; time_t t;
char *datestr; char *datestr;
datestr = (char *) malloc (sizeof (char) * BUFSIZ); datestr = (char *) mem_malloc (sizeof (char) * BUFSIZ);
if (sec == 0) if (sec == 0)
snprintf (datestr, BUFSIZ, "0"); (void)snprintf (datestr, BUFSIZ, "0");
else else
{ {
t = sec; t = sec;
@ -634,7 +655,7 @@ check_time (char *string)
if (((strlen (string) == 2) || (strlen (string) == 3)) if (((strlen (string) == 2) || (strlen (string) == 3))
&& (isdigit (string[0]) != 0) && (isdigit (string[1]) != 0)) && (isdigit (string[0]) != 0) && (isdigit (string[1]) != 0))
{ {
strncpy (minutes, string, 2); (void)strncpy (minutes, string, 2);
if (atoi (minutes) >= 0) if (atoi (minutes) >= 0)
ok = 2; /* [MM] format */ ok = 2; /* [MM] format */
} }
@ -642,7 +663,7 @@ check_time (char *string)
&& (isdigit (string[2]) != 0) && (isdigit (string[3]) != 0) && (isdigit (string[2]) != 0) && (isdigit (string[3]) != 0)
&& (string[1] == ':')) && (string[1] == ':'))
{ {
strncpy (hour, string, 1); (void)strncpy (hour, string, 1);
strncpy (minutes, string + 2, 2); strncpy (minutes, string + 2, 2);
if ((atoi (hour) <= 24) && (atoi (hour) >= 0) if ((atoi (hour) <= 24) && (atoi (hour) >= 0)
&& (atoi (minutes) < MININSEC) && (atoi (minutes) >= 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) if (prefix_len + trailing_len >= BUFSIZ)
return (NULL); return (NULL);
memcpy (fullname, prefix, prefix_len); 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'; fullname[prefix_len + trailing_len] = '\0';
if ((fd = mkstemp (fullname)) == -1 || (file = fdopen (fd, "w+")) == NULL) if ((fd = mkstemp (fullname)) == -1 || (file = fdopen (fd, "w+")) == NULL)
{ {
@ -848,7 +869,7 @@ new_tempfile (const char *prefix, int trailing_len)
} }
fclose (file); fclose (file);
return (strdup (fullname + prefix_len)); return (mem_strdup (fullname + prefix_len));
} }
/* Erase a note previously attached to a todo, event or appointment. */ /* Erase a note previously attached to a todo, event or appointment. */
@ -861,11 +882,11 @@ erase_note (char **note, erase_flag_e flag)
return; return;
if (flag != ERASE_FORCE_KEEP_NOTE) 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) if (unlink (fullname) != 0)
EXIT (_("could not remove note")); EXIT (_("could not remove note"));
} }
free (*note); mem_free (*note);
*note = NULL; *note = NULL;
} }
@ -926,10 +947,10 @@ str_toupper (char *s)
} }
void void
mem_free (void *ptr) file_close (FILE *f, const char *pos)
{ {
if (!ptr) int ret;
return;
free (ptr); ret = fclose (f);
ptr = NULL; 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 * Calcurse - text-based organizer
@ -42,11 +42,11 @@
int len; \ int len; \
\ \
len = snprintf (msg, BUFSIZ, "%s: %d: ", __FILE__, __LINE__); \ 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) \ if (ui_mode == UI_CURSES) \
fatalbox (msg); \ fatalbox (msg); \
else \ else \
fprintf (stderr, "%s\n", msg); \ (void)fprintf (stderr, "%s\n", msg); \
} while (0) } while (0)
#define EXIT(...) do { \ #define EXIT(...) do { \
@ -78,9 +78,13 @@
} \ } \
} while (0) } while (0)
#define GETSTRING_VALID 0 /* value returned by getstring() if text is valid */ #define STRINGIFY(x) #x
#define GETSTRING_ESC 1 /* user pressed escape to cancel editing */ #define TOSTRING(x) STRINGIFY(x)
#define GETSTRING_RET 2 /* return was pressed without entering any text */ #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 { typedef struct {
const char *str; const char *str;
@ -128,6 +132,6 @@ char *new_tempfile (const char *, int);
void erase_note (char **, erase_flag_e); void erase_note (char **, erase_flag_e);
int parse_date (char *, int, int *, int *, int *); int parse_date (char *, int, int *, int *, int *);
char *str_toupper (char *); char *str_toupper (char *);
void mem_free (void *ptr); void file_close (FILE *, const char *);
#endif /* CALCURSE_UTILS_H */ #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 * Calcurse - text-based organizer
@ -32,6 +32,7 @@
#include "custom.h" #include "custom.h"
#include "wins.h" #include "wins.h"
#include "keys.h" #include "keys.h"
#include "mem.h"
#include "vars.h" #include "vars.h"
/* /*
@ -112,7 +113,7 @@ vars_init (conf_t *conf)
conf->auto_save = true; conf->auto_save = true;
conf->skip_system_dialogs = false; conf->skip_system_dialogs = false;
conf->skip_progress_bar = false; conf->skip_progress_bar = false;
strncpy (conf->output_datefmt, "%D", 3); (void)strncpy (conf->output_datefmt, "%D", 3);
conf->input_datefmt = 1; conf->input_datefmt = 1;
/* Default external editor and pager */ /* Default external editor and pager */
@ -133,7 +134,7 @@ vars_init (conf_t *conf)
calendar_set_first_day_of_week (MONDAY); calendar_set_first_day_of_week (MONDAY);
/* Pad structure to scroll text inside the appointment panel */ /* 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->length = 1;
apad->first_onscreen = 0; apad->first_onscreen = 0;
@ -143,3 +144,9 @@ vars_init (conf_t *conf)
/* Start at the current date */ /* Start at the current date */
calendar_init_slctd_day (); 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 * Calcurse - text-based organizer
@ -122,5 +122,6 @@ extern struct pad_s *apad;
extern struct nbar_s *nbar; extern struct nbar_s *nbar;
void vars_init (conf_t *conf); void vars_init (conf_t *conf);
void vars_free (void);
#endif /* CALCURSE_VARS_H */ #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 * Calcurse - text-based organizer
@ -32,6 +32,7 @@
#include "utils.h" #include "utils.h"
#include "todo.h" #include "todo.h"
#include "custom.h" #include "custom.h"
#include "mem.h"
#include "wins.h" #include "wins.h"
/* Variables to handle calcurse windows. */ /* Variables to handle calcurse windows. */
@ -96,17 +97,17 @@ wins_init (void)
* display appointments and event. * display appointments and event.
*/ */
win[CAL].p = newwin (CALHEIGHT, CALWIDTH, win[CAL].y, win[CAL].x); 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); wins_show (win[CAL].p, label);
win[APP].p = newwin (win[APP].h, win[APP].w, win[APP].y, win[APP].x); 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); wins_show (win[APP].p, label);
apad->width = win[APP].w - 3; apad->width = win[APP].w - 3;
apad->ptrwin = newpad (apad->length, apad->width); apad->ptrwin = newpad (apad->length, apad->width);
win[TOD].p = newwin (win[TOD].h, win[TOD].w, win[TOD].y, win[TOD].x); 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); wins_show (win[TOD].p, label);
win[STA].p = newwin (win[STA].h, win[STA].w, win[STA].y, win[STA].x); win[STA].p = newwin (win[STA].h, win[STA].w, win[STA].y, win[STA].x);
@ -452,10 +453,10 @@ wins_launch_external (const char *file, const char *cmd)
/* Beware of space between cmd and file. */ /* Beware of space between cmd and file. */
len = strlen (file) + strlen (cmd) + 2; 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) if (snprintf (p, len, "%s %s", cmd, file) == -1)
{ {
free (p); mem_free (p);
return; return;
} }
if (notify_bar ()) if (notify_bar ())
@ -465,7 +466,7 @@ wins_launch_external (const char *file, const char *cmd)
ui_mode = UI_CMDLINE; ui_mode = UI_CMDLINE;
clear (); clear ();
refresh (); refresh ();
system (p); (void)system (p);
reset_prog_mode (); reset_prog_mode ();
clearok (curscr, TRUE); clearok (curscr, TRUE);
curs_set (0); curs_set (0);
@ -473,5 +474,5 @@ wins_launch_external (const char *file, const char *cmd)
refresh (); refresh ();
if (notify_bar ()) if (notify_bar ())
notify_start_main_thread (); notify_start_main_thread ();
free (p); mem_free (p);
} }