summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFrederic Culot <calcurse@culot.org>2008-04-19 21:04:47 +0000
committerFrederic Culot <calcurse@culot.org>2008-04-19 21:04:47 +0000
commit2341c900035a5947fea7539c011ff6173ddc80ce (patch)
treee6dd95431f3797deb00aa178d0d60e61e01b3a17 /src
parent2e798df3cb498b0e2150a5c2ace47eb80281237e (diff)
downloadcalcurse-2341c900035a5947fea7539c011ff6173ddc80ce.zip
some memory leaks fixed using valgrind and some minor code cleanup
Diffstat (limited to 'src')
-rwxr-xr-xsrc/apoint.c30
-rwxr-xr-xsrc/apoint.h4
-rwxr-xr-xsrc/args.c5
-rwxr-xr-xsrc/custom.c7
-rwxr-xr-xsrc/day.c9
-rwxr-xr-xsrc/help.c61
-rwxr-xr-xsrc/notify.c6
-rwxr-xr-xsrc/notify.h4
-rwxr-xr-xsrc/todo.c22
-rwxr-xr-xsrc/todo.h6
-rwxr-xr-xsrc/wins.c8
11 files changed, 75 insertions, 87 deletions
diff --git a/src/apoint.c b/src/apoint.c
index c57f24c..1ca2e6f 100755
--- a/src/apoint.c
+++ b/src/apoint.c
@@ -1,4 +1,4 @@
-/* $calcurse: apoint.c,v 1.22 2008/04/12 21:14:03 culot Exp $ */
+/* $calcurse: apoint.c,v 1.23 2008/04/19 21:05:15 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -84,8 +84,7 @@ apoint_new (char *mesg, char *note, long start, long dur, char state)
apoint_llist_node_t *o, **i;
o = (apoint_llist_node_t *) malloc (sizeof (apoint_llist_node_t));
- o->mesg = (char *) malloc (strlen (mesg) + 1);
- strncpy (o->mesg, mesg, strlen (mesg) + 1);
+ o->mesg = strdup (mesg);
o->note = (note != NULL) ? strdup (note) : NULL;
o->state = state;
o->start = start;
@@ -619,26 +618,27 @@ apoint_switch_notify (void)
/* Updates the Appointment panel */
void
-apoint_update_panel (window_t *winapp, int which_pan)
+apoint_update_panel (int which_pan)
{
int title_xpos;
int bordr = 1;
int title_lines = 3;
- int app_width = winapp->w - bordr;
- int app_length = winapp->h - bordr - title_lines;
+ int app_width = win[APP].w - bordr;
+ int app_length = win[APP].h - bordr - title_lines;
long date;
date_t slctd_date;
/* variable inits */
slctd_date = *calendar_get_slctd_day ();
- title_xpos = winapp->w - (strlen (_(monthnames[slctd_date.mm - 1])) + 16);
+ title_xpos = win[APP].w - (strlen (_(monthnames[slctd_date.mm - 1])) + 16);
if (slctd_date.dd < 10)
title_xpos++;
date = date2sec (slctd_date, 0, 0);
day_write_pad (date, app_width, app_length, hilt);
/* Print current date in the top right window corner. */
- erase_window_part (win[APP].p, 1, title_lines, winapp->w - 2, winapp->h - 2);
+ erase_window_part (win[APP].p, 1, title_lines, win[APP].w - 2,
+ win[APP].h - 2);
custom_apply_attr (win[APP].p, ATTR_HIGHEST);
mvwprintw (win[APP].p, title_lines, title_xpos, "%s %s %d, %d",
calendar_get_pom (date), _(monthnames[slctd_date.mm - 1]),
@@ -654,15 +654,15 @@ apoint_update_panel (window_t *winapp, int which_pan)
bool hilt_bar = (which_pan == APP) ? true : false;
int sbar_top = highend + title_lines + 1;
- if ((sbar_top + sbar_length) > winapp->h - 1)
- sbar_length = winapp->h - 1 - sbar_top;
- draw_scrollbar (win[APP].p, sbar_top, winapp->w - 2, sbar_length,
- title_lines + 1, winapp->h - 1, hilt_bar);
+ if ((sbar_top + sbar_length) > win[APP].h - 1)
+ sbar_length = win[APP].h - 1 - sbar_top;
+ draw_scrollbar (win[APP].p, sbar_top, win[APP].w - 2, sbar_length,
+ title_lines + 1, win[APP].h - 1, hilt_bar);
}
wnoutrefresh (win[APP].p);
pnoutrefresh (apad->ptrwin, apad->first_onscreen, 0,
- winapp->y + title_lines + 1, winapp->x + bordr,
- winapp->y + winapp->h - 2 * bordr,
- winapp->x + winapp->w - 3 * bordr);
+ win[APP].y + title_lines + 1, win[APP].x + bordr,
+ win[APP].y + win[APP].h - 2 * bordr,
+ win[APP].x + win[APP].w - 3 * bordr);
}
diff --git a/src/apoint.h b/src/apoint.h
index ef09684..dc71e34 100755
--- a/src/apoint.h
+++ b/src/apoint.h
@@ -1,4 +1,4 @@
-/* $calcurse: apoint.h,v 1.13 2008/04/12 21:14:03 culot Exp $ */
+/* $calcurse: apoint.h,v 1.14 2008/04/19 21:05:15 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -79,6 +79,6 @@ void apoint_scroll_pad_up (int);
struct notify_app_s *apoint_check_next (struct notify_app_s *, long);
apoint_llist_node_t *apoint_recur_s2apoint_s (recur_apoint_llist_node_t *);
void apoint_switch_notify (void);
-void apoint_update_panel (window_t *, int);
+void apoint_update_panel (int);
#endif /* CALCURSE_APOINT_H */
diff --git a/src/args.c b/src/args.c
index bd42458..29e6bc2 100755
--- a/src/args.c
+++ b/src/args.c
@@ -1,4 +1,4 @@
-/* $calcurse: args.c,v 1.32 2008/04/12 21:14:03 culot Exp $ */
+/* $calcurse: args.c,v 1.33 2008/04/19 21:05:15 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -439,7 +439,8 @@ date_arg (char *ddate, int add_line, int print_note, conf_t *conf)
}
else
{ /* a date was entered */
- if (parse_date (ddate, conf->input_datefmt, &day.yyyy, &day.mm, &day.dd))
+ if (parse_date (ddate, conf->input_datefmt, (int *)&day.yyyy,
+ (int *)&day.mm, (int *)&day.dd))
{
app_found = app_arg (add_line, &day, 0, print_note, conf);
}
diff --git a/src/custom.c b/src/custom.c
index ea65fba..a0465de 100755
--- a/src/custom.c
+++ b/src/custom.c
@@ -1,4 +1,4 @@
-/* $calcurse: custom.c,v 1.21 2008/04/19 09:22:14 culot Exp $ */
+/* $calcurse: custom.c,v 1.22 2008/04/19 21:05:15 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -423,7 +423,7 @@ custom_confwin_init (window_t *confwin, char *label)
keypad (win[STA].p, TRUE);
if (notify_bar ())
{
- notify_reinit_bar (win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x);
+ notify_reinit_bar ();
notify_update_bar ();
}
}
@@ -827,8 +827,7 @@ custom_general_config (conf_t *conf)
keypad (win[STA].p, TRUE);
if (notify_bar ())
{
- notify_reinit_bar (win[NOT].h, win[NOT].w, win[NOT].y,
- win[NOT].x);
+ notify_reinit_bar ();
notify_update_bar ();
}
break;
diff --git a/src/day.c b/src/day.c
index fcb8d6c..5986bb2 100755
--- a/src/day.c
+++ b/src/day.c
@@ -1,4 +1,4 @@
-/* $calcurse: day.c,v 1.36 2008/04/12 21:14:03 culot Exp $ */
+/* $calcurse: day.c,v 1.37 2008/04/19 21:05:15 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -91,8 +91,7 @@ day_add_apoint (int type, char *mesg, char *note, long start, long dur,
int insert_item = 0;
o = (struct day_item_s *) malloc (sizeof (struct day_item_s));
- o->mesg = (char *) malloc (strlen (mesg) + 1);
- strncpy (o->mesg, mesg, strlen (mesg) + 1);
+ o->mesg = strdup (mesg);
o->note = note;
o->start = start;
o->appt_dur = dur;
@@ -398,9 +397,7 @@ day_write_pad (long date, int width, int length, int incolor)
/* Initialize the structure used to store highlited item. */
if (day_saved_item == NULL)
{
- day_saved_item = (struct day_saved_item_s *)
- malloc (sizeof (struct day_saved_item_s));
- day_saved_item->mesg = (char *) malloc (sizeof (char));
+ day_saved_item = malloc (sizeof (struct day_saved_item_s));
}
for (p = day_items_ptr; p != 0; p = p->next)
diff --git a/src/help.c b/src/help.c
index 4c36fec..f80f827 100755
--- a/src/help.c
+++ b/src/help.c
@@ -1,4 +1,4 @@
-/* $calcurse: help.c,v 1.24 2008/04/19 09:22:14 culot Exp $ */
+/* $calcurse: help.c,v 1.25 2008/04/19 21:05:15 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -101,17 +101,24 @@ write_help_pad (window_t *win, help_page_t *hpage)
* faster.
*/
static void
-help_wins_init (window_t *hwin, window_t *hpad, const int PADOFFSET)
+help_wins_init (scrollwin_t *hwin)
{
- char label[BUFSIZ];
-
- hwin->h = (notify_bar ())? row - 3 : row - 2;
- hwin->p = newwin (hwin->h, col, 0, 0);
- hpad->w = col - 2 * PADOFFSET + 1;
- hpad->p = newpad (BUFSIZ, hpad->w);
- box (hwin->p, 0, 0);
- snprintf (label, BUFSIZ, _("CalCurse %s | help"), VERSION);
- wins_show (hwin->p, label);
+ const int PADOFFSET = 4;
+ const int TITLELINES = 3;
+
+ hwin->win.x = 0;
+ hwin->win.y = 0;
+ hwin->win.h = (notify_bar ()) ? row - 3 : row - 2;
+ hwin->win.w = col;
+
+ hwin->pad.x = PADOFFSET;
+ hwin->pad.y = TITLELINES;
+ hwin->pad.h = BUFSIZ;
+ hwin->pad.w = col - 2 * PADOFFSET + 1;
+
+ snprintf (hwin->label, BUFSIZ, _("Calcurse %s | help"), VERSION);
+ wins_scrollwin_init (hwin);
+ wins_show (hwin->win.p, hwin->label);
}
/*
@@ -119,27 +126,26 @@ help_wins_init (window_t *hwin, window_t *hpad, const int PADOFFSET)
* size and placement.
*/
static void
-help_wins_reinit (window_t *hwin, window_t *hpad, const int PADOFFSET)
+help_wins_reinit (scrollwin_t *hwin)
{
- delwin (hpad->p);
- delwin (hwin->p);
+ wins_scrollwin_delete (hwin);
wins_get_config ();
- help_wins_init (hwin, hpad, PADOFFSET);
+ help_wins_init (hwin);
}
/* Reset the screen, needed when resizing terminal for example. */
static void
-help_wins_reset (window_t *hwin, window_t *hpad, const int PADOFFSET)
+help_wins_reset (scrollwin_t *hwin)
{
endwin ();
refresh ();
curs_set (0);
delwin (win[STA].p);
- help_wins_reinit (hwin, hpad, PADOFFSET);
+ help_wins_reinit (hwin);
win[STA].p = newwin (win[STA].h, win[STA].w, win[STA].y, win[STA].x);
keypad (win[STA].p, TRUE);
if (notify_bar ())
- notify_reinit_bar (win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x);
+ notify_reinit_bar ();
status_bar ();
if (notify_bar ())
notify_update_bar ();
@@ -257,8 +263,6 @@ void
help_screen (void)
{
scrollwin_t hwin;
- const int PADOFFSET = 4;
- const int TITLELINES = 3;
int need_resize;
int ch = '?';
int page, oldpage;
@@ -557,19 +561,7 @@ help_screen (void)
"Send your feedback or comments to : calcurse@culot.org\n"
"Calcurse home page : http://culot.org/calcurse");
- hwin.win.x = 0;
- hwin.win.y = 0;
- hwin.win.h = (notify_bar ()) ? row - 3 : row - 2;
- hwin.win.w = col;
-
- hwin.pad.x = PADOFFSET;
- hwin.pad.y = TITLELINES;
- hwin.pad.h = BUFSIZ;
- hwin.pad.w = col - 2 * PADOFFSET + 1;
-
- snprintf (hwin.label, BUFSIZ, _("Calcurse %s | help"), VERSION);
- wins_scrollwin_init (&hwin);
- wins_show (hwin.win.p, hwin.label);
+ help_wins_init (&hwin);
page = oldpage = HELP_MAIN;
need_resize = 0;
@@ -581,7 +573,8 @@ help_screen (void)
switch (ch)
{
case KEY_RESIZE:
- help_wins_reset (&hwin.win, &hwin.pad, PADOFFSET);
+ wins_get_config ();
+ help_wins_reset (&hwin);
hwin.first_visible_line = 0;
hwin.total_lines = write_help_pad (&hwin.pad, &hscr[oldpage]);
need_resize = 1;
diff --git a/src/notify.c b/src/notify.c
index 0634db1..6bc0ddf 100755
--- a/src/notify.c
+++ b/src/notify.c
@@ -1,4 +1,4 @@
-/* $calcurse: notify.c,v 1.25 2008/04/12 21:14:03 culot Exp $ */
+/* $calcurse: notify.c,v 1.26 2008/04/19 21:05:15 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -117,10 +117,10 @@ notify_stop_main_thread (void)
* notification window.
*/
void
-notify_reinit_bar (int l, int c, int y, int x)
+notify_reinit_bar (void)
{
delwin (notify->win);
- notify->win = newwin (l, c, y, x);
+ notify->win = newwin (win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x);
}
/* Launch user defined command as a notification. */
diff --git a/src/notify.h b/src/notify.h
index 32fcab2..e1b8f00 100755
--- a/src/notify.h
+++ b/src/notify.h
@@ -1,4 +1,4 @@
-/* $calcurse: notify.h,v 1.13 2008/04/12 21:14:03 culot Exp $ */
+/* $calcurse: notify.h,v 1.14 2008/04/19 21:05:15 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -57,7 +57,7 @@ void notify_init_vars (void);
void notify_init_bar (void);
void notify_start_main_thread (void);
void notify_stop_main_thread (void);
-void notify_reinit_bar (int, int, int, int);
+void notify_reinit_bar (void);
void notify_update_bar (void);
void notify_check_next_app (void);
void notify_check_added (char *, long, char);
diff --git a/src/todo.c b/src/todo.c
index bf3a43d..9b3d786 100755
--- a/src/todo.c
+++ b/src/todo.c
@@ -1,4 +1,4 @@
-/* $calcurse: todo.c,v 1.21 2008/04/12 21:14:03 culot Exp $ */
+/* $calcurse: todo.c,v 1.22 2008/04/19 21:05:15 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -158,8 +158,7 @@ todo_add (char *mesg, int id, char *note)
{
struct todo_s *o, **i;
o = (struct todo_s *) malloc (sizeof (struct todo_s));
- o->mesg = (char *) malloc (strlen (mesg) + 1);
- strncpy (o->mesg, mesg, strlen (mesg) + 1);
+ o->mesg = strdup (mesg);
o->id = id;
o->note = (note != NULL && note[0] != '\0') ? strdup (note) : NULL;
i = &todolist;
@@ -407,20 +406,21 @@ display_todo_item (int incolor, char *msg, int prio, int note, int len, int y,
/* Updates the ToDo panel. */
void
-todo_update_panel (window_t *wintod, int which_pan)
+todo_update_panel (int which_pan)
{
struct todo_s *i;
- int len = wintod->w - 8;
+ int len = win[TOD].w - 8;
int num_todo = 0;
int y_offset = 3, x_offset = 1;
int t_realpos = -1;
int title_lines = 3;
int todo_lines = 1;
- int max_items = wintod->h - 4;
+ int max_items = win[TOD].h - 4;
int incolor = -1;
/* Print todo item in the panel. */
- erase_window_part (win[TOD].p, 1, title_lines, wintod->w - 2, wintod->h - 2);
+ erase_window_part (win[TOD].p, 1, title_lines, win[TOD].w - 2,
+ win[TOD].h - 2);
for (i = todolist; i != 0; i = i->next)
{
num_todo++;
@@ -446,10 +446,10 @@ todo_update_panel (window_t *wintod, int which_pan)
bool hilt_bar = (which_pan == TOD) ? true : false;
int sbar_top = highend + title_lines;
- if ((sbar_top + sbar_length) > wintod->h - 1)
- sbar_length = wintod->h - 1 - sbar_top;
- draw_scrollbar (win[TOD].p, sbar_top, wintod->w - 2,
- sbar_length, title_lines, wintod->h - 1, hilt_bar);
+ if ((sbar_top + sbar_length) > win[TOD].h - 1)
+ sbar_length = win[TOD].h - 1 - sbar_top;
+ draw_scrollbar (win[TOD].p, sbar_top, win[TOD].w - 2,
+ sbar_length, title_lines, win[TOD].h - 1, hilt_bar);
}
wnoutrefresh (win[TOD].p);
diff --git a/src/todo.h b/src/todo.h
index e3e0f8e..9244f02 100755
--- a/src/todo.h
+++ b/src/todo.h
@@ -1,4 +1,4 @@
-/* $calcurse: todo.h,v 1.11 2008/04/12 21:14:03 culot Exp $ */
+/* $calcurse: todo.h,v 1.12 2008/04/19 21:05:15 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -27,8 +27,6 @@
#ifndef CALCURSE_TODO_H
#define CALCURSE_TODO_H
-#include "wins.h"
-
struct todo_s
{
struct todo_s *next;
@@ -55,7 +53,7 @@ struct todo_s *todo_add (char *, int, char *);
void todo_delete (conf_t *);
void todo_chg_priority (int);
void todo_edit_item (void);
-void todo_update_panel (window_t *, int);
+void todo_update_panel (int);
void todo_edit_note (char *);
void todo_view_note (char *);
diff --git a/src/wins.c b/src/wins.c
index 2d846fb..5cab994 100755
--- a/src/wins.c
+++ b/src/wins.c
@@ -1,4 +1,4 @@
-/* $calcurse: wins.c,v 1.15 2008/04/19 09:22:14 culot Exp $ */
+/* $calcurse: wins.c,v 1.16 2008/04/19 21:05:15 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -196,7 +196,7 @@ wins_reinit (void)
wins_get_config ();
wins_init ();
if (notify_bar ())
- notify_reinit_bar (win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x);
+ notify_reinit_bar ();
}
/* Show the window with a border and a label. */
@@ -419,8 +419,8 @@ wins_update (void)
/* NOTREACHED */
}
- apoint_update_panel (&win[APP], slctd_win);
- todo_update_panel (&win[TOD], slctd_win);
+ apoint_update_panel (slctd_win);
+ todo_update_panel (slctd_win);
calendar_update_panel (win[CAL].p);
status_bar ();
if (notify_bar ())