summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederic Culot <calcurse@culot.org>2009-01-03 21:32:10 +0000
committerFrederic Culot <calcurse@culot.org>2009-01-03 21:32:10 +0000
commit936b6fe3737c760657d82c50fa6b81c3011ffa27 (patch)
treecb909cd269419fdf31134ecc407315765804e7c1
parentbf3bce0ab2d6d5fc8448821fbfa29b48a1bb5994 (diff)
downloadcalcurse-936b6fe3737c760657d82c50fa6b81c3011ffa27.zip
more code cleanup
-rwxr-xr-xChangeLog12
-rwxr-xr-xsrc/apoint.c31
-rwxr-xr-xsrc/apoint.h8
-rwxr-xr-xsrc/args.c7
-rwxr-xr-xsrc/calcurse.c36
-rwxr-xr-xsrc/custom.c7
-rwxr-xr-xsrc/day.c85
-rwxr-xr-xsrc/day.h8
-rwxr-xr-xsrc/event.c19
-rwxr-xr-xsrc/event.h4
-rwxr-xr-xsrc/help.c4
-rwxr-xr-xsrc/io.c9
-rwxr-xr-xsrc/keys.c4
-rwxr-xr-xsrc/keys.h6
-rw-r--r--src/mem.c12
-rwxr-xr-xsrc/notify.c8
-rwxr-xr-xsrc/recur.c50
-rwxr-xr-xsrc/recur.h6
-rwxr-xr-xsrc/todo.c8
-rwxr-xr-xsrc/utils.c149
-rwxr-xr-xsrc/utils.h6
-rwxr-xr-xsrc/wins.c140
-rwxr-xr-xsrc/wins.h8
23 files changed, 330 insertions, 297 deletions
diff --git a/ChangeLog b/ChangeLog
index 3c9e8a0..6018830 100755
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2009-01-03 Frederic Culot <frederic@culot.org>
+
+ * src/day.c (day_saved_item_init, day_saved_item_free): suppressed
+
+ * src/utils.c (status_bar): moved to wins_status_bar
+ * src/utils.c (erase_status_bar): moved to wins_erase_status_bar
+ * src/utils.c (other_status_page): moved to wins_other_status_page
+ * src/utils.c (reset_status_page): moved to wins_reset_status_page
+
+ * src/mem.c (dbg_realloc): wrong copy from old memory area to
+ newly allocated one fixed + other fixes
+
2009-01-02 Frederic Culot <frederic@culot.org>
* src/io.c (io_stop_pthread_save): do not crash when canceling the
diff --git a/src/apoint.c b/src/apoint.c
index 81941ac..e0308c2 100755
--- a/src/apoint.c
+++ b/src/apoint.c
@@ -1,4 +1,4 @@
-/* $calcurse: apoint.c,v 1.32 2009/01/02 22:28:54 culot Exp $ */
+/* $calcurse: apoint.c,v 1.33 2009/01/03 21:32:11 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -46,7 +46,7 @@ static apoint_llist_node_t bkp_cut_apoint;
static int hilt;
void
-apoint_free_bkp (void)
+apoint_free_bkp (erase_flag_e flag)
{
if (bkp_cut_apoint.mesg)
{
@@ -55,8 +55,13 @@ apoint_free_bkp (void)
}
if (bkp_cut_apoint.note)
{
- mem_free (bkp_cut_apoint.note);
- bkp_cut_apoint.note = 0;
+ if (flag == ERASE_FORCE)
+ erase_note (&bkp_cut_apoint.note, ERASE_FORCE);
+ else
+ {
+ mem_free (bkp_cut_apoint.note);
+ bkp_cut_apoint.note = 0;
+ }
}
}
@@ -268,7 +273,7 @@ apoint_add (void)
if (hilt == 0)
hilt++;
}
- erase_status_bar ();
+ wins_erase_status_bar ();
}
/* Delete an item from the appointment list. */
@@ -294,7 +299,7 @@ apoint_delete (conf_t *conf, unsigned *nb_events, unsigned *nb_apoints)
go_for_deletion = true;
else
{
- erase_status_bar ();
+ wins_erase_status_bar ();
return;
}
}
@@ -333,7 +338,7 @@ apoint_delete (conf_t *conf, unsigned *nb_events, unsigned *nb_apoints)
}
/* Cut an item, so that it can be pasted somewhere else later. */
-void
+int
apoint_cut (unsigned *nb_events, unsigned *nb_apoints)
{
const int NBITEMS = *nb_apoints + *nb_events;
@@ -341,7 +346,7 @@ apoint_cut (unsigned *nb_events, unsigned *nb_apoints)
long date;
if (NBITEMS == 0)
- return;
+ return 0;
to_be_removed = 0;
date = calendar_get_slctd_day_sec ();
@@ -366,17 +371,19 @@ apoint_cut (unsigned *nb_events, unsigned *nb_apoints)
apad.first_onscreen = apad.first_onscreen - to_be_removed;
if (NBITEMS == 1)
hilt = 0;
+
+ return item_type;
}
/* Paste a previously cut item. */
void
-apoint_paste (unsigned *nb_events, unsigned *nb_apoints)
+apoint_paste (unsigned *nb_events, unsigned *nb_apoints, int cut_item_type)
{
int item_type;
long date;
date = calendar_get_slctd_day_sec ();
- item_type = day_paste_item (date);
+ item_type = day_paste_item (date, cut_item_type);
if (item_type == EVNT || item_type == RECUR_EVNT)
(*nb_events)++;
else if (item_type == APPT || item_type == RECUR_APPT)
@@ -526,7 +533,7 @@ apoint_delete_bynum (long start, unsigned num, erase_flag_e flag)
pthread_mutex_unlock (&(alist_p->mutex));
break;
case ERASE_CUT:
- apoint_free_bkp ();
+ apoint_free_bkp (ERASE_FORCE);
apoint_dup (i, &bkp_cut_apoint);
if (i->note)
mem_free (i->note);
@@ -776,5 +783,5 @@ apoint_paste_item (void)
(void)apoint_new (bkp_cut_apoint.mesg, bkp_cut_apoint.note,
bkp_start, bkp_cut_apoint.dur,
bkp_cut_apoint.state);
- apoint_free_bkp ();
+ apoint_free_bkp (ERASE_FORCE_KEEP_NOTE);
}
diff --git a/src/apoint.h b/src/apoint.h
index d51829c..d4d6da2 100755
--- a/src/apoint.h
+++ b/src/apoint.h
@@ -1,4 +1,4 @@
-/* $calcurse: apoint.h,v 1.16 2009/01/01 17:50:41 culot Exp $ */
+/* $calcurse: apoint.h,v 1.17 2009/01/03 21:32:11 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -59,7 +59,7 @@ apoint_llist_t;
extern apoint_llist_t *alist_p;
-void apoint_free_bkp (void);
+void apoint_free_bkp (erase_flag_e);
void apoint_llist_init (void);
void apoint_llist_free (void);
void apoint_hilt_set (int);
@@ -69,8 +69,8 @@ int apoint_hilt (void);
apoint_llist_node_t *apoint_new (char *, char *, long, long, char);
void apoint_add (void);
void apoint_delete (conf_t *, unsigned *, unsigned *);
-void apoint_cut (unsigned *, unsigned *);
-void apoint_paste (unsigned *, unsigned *);
+int apoint_cut (unsigned *, unsigned *);
+void apoint_paste (unsigned *, unsigned *, int);
unsigned apoint_inday (apoint_llist_node_t *, long);
void apoint_sec2str (apoint_llist_node_t *, int, long, char *,
char *);
diff --git a/src/args.c b/src/args.c
index 56a5ba2..e43323a 100755
--- a/src/args.c
+++ b/src/args.c
@@ -1,8 +1,8 @@
-/* $calcurse: args.c,v 1.43 2008/12/28 19:41:45 culot Exp $ */
+/* $calcurse: args.c,v 1.44 2009/01/03 21:32:11 culot Exp $ */
/*
* Calcurse - text-based organizer
- * Copyright (c) 2004-2008 Frederic Culot
+ * Copyright (c) 2004-2009 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -39,6 +39,7 @@
#include "apoint.h"
#include "day.h"
#include "todo.h"
+#include "mem.h"
#include "io.h"
#ifdef HAVE_CONFIG_H
@@ -248,7 +249,7 @@ next_arg (void)
(void)snprintf (mesg, BUFSIZ, " [%02d:%02d] %s\n", hours_left, min_left,
next_app.txt);
fputs (mesg, stdout);
- free (next_app.txt);
+ mem_free (next_app.txt);
}
}
diff --git a/src/calcurse.c b/src/calcurse.c
index e2d398b..841603a 100755
--- a/src/calcurse.c
+++ b/src/calcurse.c
@@ -1,8 +1,8 @@
-/* $calcurse: calcurse.c,v 1.76 2009/01/01 17:50:41 culot Exp $ */
+/* $calcurse: calcurse.c,v 1.77 2009/01/03 21:32:11 culot Exp $ */
/*
* Calcurse - text-based organizer
- * Copyright (c) 2004-2008 Frederic Culot
+ * Copyright (c) 2004-2009 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -60,6 +60,7 @@ main (int argc, char **argv)
int no_data_file = 1;
int sav_hilt_app = 0;
int sav_hilt_tod = 0;
+ int cut_item = 0;
struct sigaction sigact;
bool do_storage = false;
bool do_update = true;
@@ -137,7 +138,7 @@ main (int argc, char **argv)
wins_init ();
wins_slctd_init ();
notify_init_bar ();
- reset_status_page ();
+ wins_reset_status_page ();
/*
* Read the data from files : first the user
@@ -146,7 +147,7 @@ main (int argc, char **argv)
*/
no_data_file = io_check_data_files ();
custom_load_conf (&conf, background);
- erase_status_bar ();
+ wins_erase_status_bar ();
io_load_keys (conf.pager);
io_load_todo ();
io_load_app ();
@@ -182,7 +183,7 @@ main (int argc, char **argv)
break;
case KEY_GENERIC_CHANGE_VIEW:
- reset_status_page ();
+ wins_reset_status_page ();
/* Need to save the previously highlighted event. */
switch (wins_slctd ())
{
@@ -221,12 +222,12 @@ main (int argc, char **argv)
break;
case KEY_GENERIC_OTHER_CMD:
- other_status_page (wins_slctd ());
+ wins_other_status_page (wins_slctd ());
break;
case KEY_GENERIC_GOTO:
case KEY_GENERIC_GOTO_TODAY:
- erase_status_bar ();
+ wins_erase_status_bar ();
calendar_set_current_date ();
if (key == KEY_GENERIC_GOTO_TODAY)
calendar_goto_today ();
@@ -244,7 +245,7 @@ main (int argc, char **argv)
break;
case KEY_GENERIC_CONFIG_MENU:
- erase_status_bar ();
+ wins_erase_status_bar ();
custom_config_bar ();
while ((key = wgetch (win[STA].p)) != 'q')
{
@@ -257,7 +258,7 @@ main (int argc, char **argv)
else
{
colorize = false;
- erase_status_bar ();
+ wins_erase_status_bar ();
mvwprintw (win[STA].p, 0, 0, _(no_color_support));
wgetch (win[STA].p);
}
@@ -282,7 +283,7 @@ main (int argc, char **argv)
wins_reset ();
wins_update ();
do_storage = true;
- erase_status_bar ();
+ wins_erase_status_bar ();
custom_config_bar ();
}
wins_update ();
@@ -335,7 +336,7 @@ main (int argc, char **argv)
case KEY_GENERIC_CUT:
if (wins_slctd () == APP && apoint_hilt () != 0)
{
- apoint_cut (&inday.nb_events, &inday.nb_apoints);
+ cut_item = apoint_cut (&inday.nb_events, &inday.nb_apoints);
do_storage = true;
}
break;
@@ -343,7 +344,8 @@ main (int argc, char **argv)
case KEY_GENERIC_PASTE:
if (wins_slctd () == APP)
{
- apoint_paste (&inday.nb_events, &inday.nb_apoints);
+ apoint_paste (&inday.nb_events, &inday.nb_apoints, cut_item);
+ cut_item = 0;
do_storage = true;
}
break;
@@ -388,7 +390,7 @@ main (int argc, char **argv)
break;
case KEY_GENERIC_HELP:
- status_bar ();
+ wins_status_bar ();
help_screen ();
break;
@@ -397,13 +399,13 @@ main (int argc, char **argv)
break;
case KEY_GENERIC_IMPORT:
- erase_status_bar ();
+ wins_erase_status_bar ();
io_import_data (IO_IMPORT_ICAL, &conf, NULL);
do_storage = true;
break;
case KEY_GENERIC_EXPORT:
- erase_status_bar ();
+ wins_erase_status_bar ();
io_export_bar ();
while ((key = wgetch (win[STA].p)) != 'q')
{
@@ -421,7 +423,7 @@ main (int argc, char **argv)
wins_reset ();
wins_update ();
do_storage = true;
- erase_status_bar ();
+ wins_erase_status_bar ();
io_export_bar ();
}
wins_update ();
@@ -520,7 +522,7 @@ main (int argc, char **argv)
exit_calcurse (EXIT_SUCCESS);
else
{
- erase_status_bar ();
+ wins_erase_status_bar ();
break;
}
}
diff --git a/src/custom.c b/src/custom.c
index 038e252..1d29894 100755
--- a/src/custom.c
+++ b/src/custom.c
@@ -1,4 +1,4 @@
-/* $calcurse: custom.c,v 1.34 2009/01/02 22:28:54 culot Exp $ */
+/* $calcurse: custom.c,v 1.35 2009/01/03 21:32:11 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -976,7 +976,7 @@ custom_general_config (conf_t *conf)
char *periodic_save_str =
_("Enter the delay, in minutes, between automatic saves (0 to disable) ");
int ch;
- char *buf = (char *) mem_malloc (BUFSIZ);
+ char *buf;
clear ();
conf_set_scrsize (&cwin);
@@ -988,8 +988,11 @@ custom_general_config (conf_t *conf)
cwin.total_lines = print_general_options (cwin.pad.p, conf);
wins_scrollwin_display (&cwin);
+ buf = mem_malloc (BUFSIZ);
while ((ch = wgetch (win[STA].p)) != 'q')
{
+ buf[0] = '\0';
+
switch (ch)
{
case KEY_RESIZE:
diff --git a/src/day.c b/src/day.c
index 1b602dd..b5cc5ca 100755
--- a/src/day.c
+++ b/src/day.c
@@ -1,4 +1,4 @@
-/* $calcurse: day.c,v 1.47 2009/01/02 22:28:54 culot Exp $ */
+/* $calcurse: day.c,v 1.48 2009/01/03 21:32:11 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -39,23 +39,13 @@
#include "day.h"
static struct day_item_s *day_items_ptr;
-static struct day_saved_item_s *day_saved_item;
-static int cut_item_type;
+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.
+ * Must not free associated message and note, because their are not dynamically
+ * allocated (only pointers to real objects are stored in this structure).
+ */
void
day_free_list (void)
{
@@ -66,12 +56,9 @@ day_free_list (void)
{
o = *i;
*i = o->next;
- mem_free (o->mesg);
- if (o->note)
- mem_free (o->note);
mem_free (o);
}
- day_items_ptr = NULL;
+ day_items_ptr = 0;
}
/* Add an event in the current day list */
@@ -79,8 +66,9 @@ static struct day_item_s *
day_add_event (int type, char *mesg, char *note, long day, int id)
{
struct day_item_s *o, **i;
- o = (struct day_item_s *) mem_malloc (sizeof (struct day_item_s));
- o->mesg = mem_strdup (mesg);
+
+ o = mem_malloc (sizeof (struct day_item_s));
+ o->mesg = mesg;
o->note = note;
o->type = type;
o->appt_dur = 0;
@@ -109,8 +97,8 @@ day_add_apoint (int type, char *mesg, char *note, long start, long dur,
struct day_item_s *o, **i;
int insert_item = 0;
- o = (struct day_item_s *) mem_malloc (sizeof (struct day_item_s));
- o->mesg = mem_strdup (mesg);
+ o = mem_malloc (sizeof (struct day_item_s));
+ o->mesg = mesg;
o->note = note;
o->start = start;
o->appt_dur = dur;
@@ -137,7 +125,7 @@ day_add_apoint (int type, char *mesg, char *note, long start, long dur,
}
i = &(*i)->next;
}
- return (o);
+ return o;
}
/*
@@ -163,7 +151,7 @@ day_store_events (long date)
}
}
- return (e_nb);
+ return e_nb;
}
/*
@@ -190,7 +178,7 @@ day_store_recur_events (long date)
}
}
- return (e_nb);
+ return e_nb;
}
/*
@@ -219,7 +207,7 @@ day_store_apoints (long date)
}
pthread_mutex_unlock (&(alist_p->mutex));
- return (a_nb);
+ return a_nb;
}
/*
@@ -252,7 +240,7 @@ day_store_recur_apoints (long date)
}
pthread_mutex_unlock (&(recur_alist_p->mutex));
- return (a_nb);
+ return a_nb;
}
/*
@@ -286,7 +274,7 @@ day_store_items (long date, unsigned *pnb_events, unsigned *pnb_apoints)
*pnb_apoints += nb_recur_apoints;
*pnb_events += nb_recur_events;
- return (pad_length);
+ return pad_length;
}
/*
@@ -320,7 +308,7 @@ day_process_storage (date_t *slctd_date, bool day_changed,
apad.first_onscreen = 0;
apad.ptrwin = newpad (apad.length, apad.width);
- return (inday);
+ return inday;
}
/*
@@ -413,10 +401,6 @@ day_write_pad (long date, int width, int length, int incolor)
line = item_number = 0;
max_pos = length;
- /* Initialize the structure used to store highlited item. */
- if (day_saved_item == 0)
- day_saved_item_init ();
-
for (p = day_items_ptr; p != 0; p = p->next)
{
if (p->type == RECUR_EVNT || p->type == RECUR_APPT)
@@ -429,8 +413,8 @@ day_write_pad (long date, int width, int length, int incolor)
item_number++;
if (item_number - incolor == 0)
{
- day_saved_item->type = p->type;
- day_saved_item->mesg = p->mesg;
+ day_saved_item.type = p->type;
+ day_saved_item.mesg = p->mesg;
}
display_item (item_number - incolor, p->mesg, recur,
(p->note != NULL) ? 1 : 0, width - 7, line, x_pos);
@@ -451,10 +435,10 @@ day_write_pad (long date, int width, int length, int incolor)
day_item_s2apoint_s (&a, p);
if (item_number - incolor == 0)
{
- day_saved_item->type = p->type;
- day_saved_item->mesg = p->mesg;
+ day_saved_item.type = p->type;
+ day_saved_item.mesg = p->mesg;
apoint_sec2str (&a, p->type, date,
- day_saved_item->start, day_saved_item->end);
+ day_saved_item.start, day_saved_item.end);
}
display_item_date (item_number - incolor, &a, p->type,
date, line + 1, x_pos);
@@ -470,11 +454,11 @@ day_write_pad (long date, int width, int length, int incolor)
void
day_popup_item (void)
{
- if (day_saved_item->type == EVNT || day_saved_item->type == RECUR_EVNT)
- item_in_popup (NULL, NULL, day_saved_item->mesg, _("Event :"));
- else if (day_saved_item->type == APPT || day_saved_item->type == RECUR_APPT)
- item_in_popup (day_saved_item->start, day_saved_item->end,
- day_saved_item->mesg, _("Appointment :"));
+ if (day_saved_item.type == EVNT || day_saved_item.type == RECUR_EVNT)
+ item_in_popup (NULL, NULL, day_saved_item.mesg, _("Event :"));
+ else if (day_saved_item.type == APPT || day_saved_item.type == RECUR_APPT)
+ item_in_popup (day_saved_item.start, day_saved_item.end,
+ day_saved_item.mesg, _("Appointment :"));
else
EXIT (_("unknown item type"));
/* NOTREACHED */
@@ -906,7 +890,7 @@ day_cut_item (long date, int item_number)
{
const int DELETE_WHOLE = 1;
struct day_item_s *p;
-
+
p = day_get_item (item_number);
switch (p->type)
{
@@ -929,13 +913,13 @@ day_cut_item (long date, int item_number)
EXIT (_("unknwon type"));
/* NOTREACHED */
}
- cut_item_type = p->type;
- return cut_item_type;
+
+ return p->type;
}
/* Paste a previously cut item. */
int
-day_paste_item (long date)
+day_paste_item (long date, int cut_item_type)
{
int pasted_item_type;
@@ -960,7 +944,6 @@ day_paste_item (long date)
EXIT (_("unknwon type"));
/* NOTREACHED */
}
- cut_item_type = 0;
return pasted_item_type;
}
diff --git a/src/day.h b/src/day.h
index bb3fe37..46c83bf 100755
--- a/src/day.h
+++ b/src/day.h
@@ -1,8 +1,8 @@
-/* $calcurse: day.h,v 1.21 2009/01/01 17:50:41 culot Exp $ */
+/* $calcurse: day.h,v 1.22 2009/01/03 21:32:11 culot Exp $ */
/*
* Calcurse - text-based organizer
- * Copyright (c) 2004-2008 Frederic Culot
+ * Copyright (c) 2004-2009 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -67,8 +67,6 @@ struct day_saved_item_s
char *mesg;
};
-void day_saved_item_init (void);
-void day_saved_item_free (void);
void day_free_list (void);
day_items_nb_t *day_process_storage (date_t *, bool, day_items_nb_t *);
void day_write_pad (long, int, int, int);
@@ -77,7 +75,7 @@ int day_check_if_item (date_t);
void day_edit_item (conf_t *);
int day_erase_item (long, int, erase_flag_e);
int day_cut_item (long, int);
-int day_paste_item (long);
+int day_paste_item (long, int);
struct day_item_s *day_get_item (int);
int day_item_nb (long, int, int);
void day_edit_note (char *);
diff --git a/src/event.c b/src/event.c
index 7c86138..8009054 100755
--- a/src/event.c
+++ b/src/event.c
@@ -1,4 +1,4 @@
-/* $calcurse: event.c,v 1.11 2009/01/02 19:52:32 culot Exp $ */
+/* $calcurse: event.c,v 1.12 2009/01/03 21:32:11 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -38,7 +38,7 @@ struct event_s *eventlist;
static struct event_s bkp_cut_event;
void
-event_free_bkp (void)
+event_free_bkp (erase_flag_e flag)
{
if (bkp_cut_event.mesg)
{
@@ -47,8 +47,13 @@ event_free_bkp (void)
}
if (bkp_cut_event.note)
{
- mem_free (bkp_cut_event.note);
- bkp_cut_event.note = 0;
+ if (flag == ERASE_FORCE)
+ erase_note (&bkp_cut_event.note, ERASE_FORCE);
+ else
+ {
+ mem_free (bkp_cut_event.note);
+ bkp_cut_event.note = 0;
+ }
}
}
@@ -90,7 +95,7 @@ event_new (char *mesg, char *note, long day, int id)
o->mesg = mem_strdup (mesg);
o->day = day;
o->id = id;
- o->note = (note != NULL) ? strdup (note) : NULL;
+ o->note = (note != NULL) ? mem_strdup (note) : NULL;
i = &eventlist;
for (;;)
{
@@ -205,7 +210,7 @@ event_delete_bynum (long start, unsigned num, erase_flag_e flag)
erase_note (&i->note, flag);
break;
case ERASE_CUT:
- event_free_bkp ();
+ event_free_bkp (ERASE_FORCE);
event_dup (i, &bkp_cut_event);
if (i->note)
mem_free (i->note);
@@ -234,5 +239,5 @@ event_paste_item (void)
(void)event_new (bkp_cut_event.mesg, bkp_cut_event.note,
date2sec (*calendar_get_slctd_day (), 12, 0),
bkp_cut_event.id);
- event_free_bkp ();
+ event_free_bkp (ERASE_FORCE_KEEP_NOTE);
}
diff --git a/src/event.h b/src/event.h
index 9fcc7d7..457a577 100755
--- a/src/event.h
+++ b/src/event.h
@@ -1,4 +1,4 @@
-/* $calcurse: event.h,v 1.7 2009/01/01 17:50:41 culot Exp $ */
+/* $calcurse: event.h,v 1.8 2009/01/03 21:32:11 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -43,7 +43,7 @@ struct event_s
extern struct event_s *eventlist;
-void event_free_bkp (void);
+void event_free_bkp (erase_flag_e);
void event_llist_free (void);
struct event_s *event_new (char *, char *, long, int);
unsigned event_inday (struct event_s *, long);
diff --git a/src/help.c b/src/help.c
index b7a9dd1..75d3cd5 100755
--- a/src/help.c
+++ b/src/help.c
@@ -1,4 +1,4 @@
-/* $calcurse: help.c,v 1.36 2008/12/28 13:13:59 culot Exp $ */
+/* $calcurse: help.c,v 1.37 2009/01/03 21:32:11 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -180,7 +180,7 @@ help_wins_reset (scrollwin_t *hwin)
keypad (win[STA].p, TRUE);
if (notify_bar ())
notify_reinit_bar ();
- status_bar ();
+ wins_status_bar ();
if (notify_bar ())
notify_update_bar ();
}
diff --git a/src/io.c b/src/io.c
index 3926f7a..31130bb 100755
--- a/src/io.c
+++ b/src/io.c
@@ -1,4 +1,4 @@
-/* $calcurse: io.c,v 1.54 2009/01/02 22:28:54 culot Exp $ */
+/* $calcurse: io.c,v 1.55 2009/01/03 21:32:11 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -975,7 +975,8 @@ io_save_cal (conf_t *conf, io_save_display_t display)
}
/* Print a message telling data were saved */
- if (ui_mode == UI_CURSES && !conf->skip_system_dialogs)
+ if (ui_mode == UI_CURSES && !conf->skip_system_dialogs
+ && display != IO_SAVE_DISPLAY_MARK)
{
status_mesg (save_success, enter);
(void)wgetch (win[STA].p);
@@ -1693,7 +1694,7 @@ ical_unformat_line (char *line)
switch (*p)
{
case LINE_FEED:
- return strdup (uline);
+ return mem_strdup (uline);
case CARRIAGE_RETURN:
break;
case '\\':
@@ -2766,7 +2767,7 @@ io_log_display (io_file_t *log, char *msg, char *pager)
}
}
while (ans != 'y' && ans != 'n');
- erase_status_bar ();
+ wins_erase_status_bar ();
}
}
diff --git a/src/keys.c b/src/keys.c
index 96fd19f..f839ac8 100755
--- a/src/keys.c
+++ b/src/keys.c
@@ -1,4 +1,4 @@
-/* $calcurse: keys.c,v 1.13 2009/01/02 19:52:32 culot Exp $ */
+/* $calcurse: keys.c,v 1.14 2009/01/03 21:32:11 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -438,7 +438,7 @@ keys_display_bindings_bar (WINDOW *win, binding_t **binding, int first_key,
cmdlen += space_between_cmds;
j = 0;
- erase_status_bar ();
+ wins_erase_status_bar ();
for (i = first_key; i < last_key; i += 2)
{
char key[KEYS_KEYLEN + 1], *fmtkey;
diff --git a/src/keys.h b/src/keys.h
index 6e48016..7d108c8 100755
--- a/src/keys.h
+++ b/src/keys.h
@@ -1,8 +1,8 @@
-/* $calcurse: keys.h,v 1.8 2009/01/01 17:50:41 culot Exp $ */
+/* $calcurse: keys.h,v 1.9 2009/01/03 21:32:11 culot Exp $ */
/*
* Calcurse - text-based organizer
- * Copyright (c) 2008 Frederic Culot
+ * Copyright (c) 2008-2009 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -27,6 +27,8 @@
#ifndef CALCURSE_KEYS_H
#define CALCURSE_KEYS_H
+#include <ncurses.h>
+
#define CTRLVAL 0x1F
#define CTRL(x) ((x) & CTRLVAL)
#define ESCAPE 27
diff --git a/src/mem.c b/src/mem.c
index 503cd13..40236a2 100644
--- a/src/mem.c
+++ b/src/mem.c
@@ -1,4 +1,4 @@
-/* $calcurse: mem.c,v 1.2 2009/01/02 19:52:32 culot Exp $ */
+/* $calcurse: mem.c,v 1.3 2009/01/03 21:32:11 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -149,7 +149,7 @@ dbg_calloc (size_t nmemb, size_t size, const char *pos)
void *
dbg_realloc (void *ptr, size_t size, const char *pos)
{
- unsigned *buf, old_size;
+ unsigned *buf, old_size, cpy_size;
if (size == 0 || ptr == 0)
return (void *)0;
@@ -158,12 +158,12 @@ dbg_realloc (void *ptr, size_t size, const char *pos)
return (void *)0;
old_size = *((unsigned *)ptr - EXTRA_SPACE_START + BLK_SIZE);
- bcopy (ptr, buf + EXTRA_SPACE_START, old_size);
+ cpy_size = (old_size > size) ? size : old_size;
+ bcopy (ptr, buf, cpy_size);
+
mem_free (ptr);
- mstats.nalloc += size;
-
- return (void *)(buf + EXTRA_SPACE_START);
+ return (void *)buf;
}
char *
diff --git a/src/notify.c b/src/notify.c
index df42edc..f258fb8 100755
--- a/src/notify.c
+++ b/src/notify.c
@@ -1,4 +1,4 @@
-/* $calcurse: notify.c,v 1.34 2009/01/02 22:28:54 culot Exp $ */
+/* $calcurse: notify.c,v 1.35 2009/01/03 21:32:11 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -293,7 +293,7 @@ notify_thread_app (void *arg)
{
notify_app.got_app = 1;
notify_app.time = tmp_app.time;
- notify_app.txt = strdup (tmp_app.txt);
+ notify_app.txt = mem_strdup (tmp_app.txt);
notify_app.state = tmp_app.state;
}
else
@@ -347,7 +347,7 @@ notify_check_added (char *mesg, long start, char state)
{
notify_app.got_app = 1;
notify_app.time = start;
- notify_app.txt = strdup (mesg);
+ notify_app.txt = mem_strdup (mesg);
notify_app.state = state;
}
pthread_mutex_unlock (&notify_app.mutex);
@@ -386,7 +386,7 @@ notify_check_repeated (recur_apoint_llist_node_t *i)
{
notify_app.got_app = 1;
notify_app.time = real_app_time;
- notify_app.txt = strdup (i->mesg);
+ notify_app.txt = mem_strdup (i->mesg);
notify_app.state = i->state;
}
pthread_mutex_unlock (&notify_app.mutex);
diff --git a/src/recur.c b/src/recur.c
index b24d557..8e3552d 100755
--- a/src/recur.c
+++ b/src/recur.c
@@ -1,4 +1,4 @@
-/* $calcurse: recur.c,v 1.48 2009/01/02 19:52:32 culot Exp $ */
+/* $calcurse: recur.c,v 1.49 2009/01/03 21:32:11 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -87,18 +87,13 @@ exc_dup (struct days_s **in, struct days_s *exc)
}
void
-recur_event_free_bkp (void)
+recur_event_free_bkp (erase_flag_e flag)
{
if (bkp_cut_recur_event.mesg)
{
mem_free (bkp_cut_recur_event.mesg);
bkp_cut_recur_event.mesg = 0;
}
- if (bkp_cut_recur_event.note)
- {
- mem_free (bkp_cut_recur_event.note);
- bkp_cut_recur_event.note = 0;
- }
if (bkp_cut_recur_event.rpt)
{
mem_free (bkp_cut_recur_event.rpt);
@@ -109,21 +104,26 @@ recur_event_free_bkp (void)
free_exc (bkp_cut_recur_event.exc);
bkp_cut_recur_event.exc = 0;
}
+ if (bkp_cut_recur_event.note)
+ {
+ if (flag == ERASE_FORCE)
+ erase_note (&bkp_cut_recur_event.note, ERASE_FORCE);
+ else
+ {
+ mem_free (bkp_cut_recur_event.note);
+ bkp_cut_recur_event.note = 0;
+ }
+ }
}
void
-recur_apoint_free_bkp (void)
+recur_apoint_free_bkp (erase_flag_e flag)
{
if (bkp_cut_recur_apoint.mesg)
{
mem_free (bkp_cut_recur_apoint.mesg);
bkp_cut_recur_apoint.mesg = 0;
}
- if (bkp_cut_recur_apoint.note)
- {
- mem_free (bkp_cut_recur_apoint.note);
- bkp_cut_recur_apoint.note = 0;
- }
if (bkp_cut_recur_apoint.rpt)
{
mem_free (bkp_cut_recur_apoint.rpt);
@@ -134,6 +134,16 @@ recur_apoint_free_bkp (void)
free_exc (bkp_cut_recur_apoint.exc);
bkp_cut_recur_apoint.exc = 0;
}
+ if (bkp_cut_recur_apoint.note)
+ {
+ if (flag == ERASE_FORCE)
+ erase_note (&bkp_cut_recur_apoint.note, ERASE_FORCE);
+ else
+ {
+ mem_free (bkp_cut_recur_apoint.note);
+ bkp_cut_recur_apoint.note = 0;
+ }
+ }
}
static void
@@ -246,7 +256,7 @@ recur_apoint_new (char *mesg, char *note, long start, long dur, char state,
o = mem_malloc (sizeof (recur_apoint_llist_node_t));
o->rpt = mem_malloc (sizeof (struct rpt_s));
o->mesg = mem_strdup (mesg);
- o->note = (note != 0) ? strdup (note) : 0;
+ o->note = (note != 0) ? mem_strdup (note) : 0;
o->start = start;
o->state = state;
o->dur = dur;
@@ -288,7 +298,7 @@ recur_event_new (char *mesg, char *note, long day, int id, int type, int freq,
o = mem_malloc (sizeof (struct recur_event_s));
o->rpt = mem_malloc (sizeof (struct rpt_s));
o->mesg = mem_strdup (mesg);
- o->note = (note != 0) ? strdup (note) : 0;
+ o->note = (note != 0) ? mem_strdup (note) : 0;
o->day = day;
o->id = id;
o->rpt->type = type;
@@ -696,7 +706,7 @@ recur_event_erase (long start, unsigned num, unsigned delete_whole,
erase_note (&i->note, flag);
break;
case ERASE_CUT:
- recur_event_free_bkp ();
+ recur_event_free_bkp (ERASE_FORCE);
recur_event_dup (i, &bkp_cut_recur_event);
if (i->note)
mem_free (i->note);
@@ -759,7 +769,7 @@ recur_apoint_erase (long start, unsigned num, unsigned delete_whole,
erase_note (&i->note, flag);
break;
case ERASE_CUT:
- recur_apoint_free_bkp ();
+ recur_apoint_free_bkp (ERASE_FORCE);
recur_apoint_dup (i, &bkp_cut_recur_apoint);
if (i->note)
mem_free (i->note);
@@ -1007,7 +1017,7 @@ recur_apoint_check_next (struct notify_app_s *app, long start, long day)
if (real_recur_start_time > start)
{
app->time = real_recur_start_time;
- app->txt = strdup (i->mesg);
+ app->txt = mem_strdup (i->mesg);
app->state = i->state;
app->got_app = 1;
}
@@ -1128,7 +1138,7 @@ recur_event_paste_item (void)
bkp_cut_recur_event.rpt->freq,
bkp_cut_recur_event.rpt->until,
&bkp_cut_recur_event.exc);
- recur_event_free_bkp ();
+ recur_event_free_bkp (ERASE_FORCE_KEEP_NOTE);
}
void
@@ -1159,5 +1169,5 @@ recur_apoint_paste_item (void)
bkp_cut_recur_apoint.rpt->freq,
bkp_cut_recur_apoint.rpt->until,
&bkp_cut_recur_apoint.exc);
- recur_apoint_free_bkp ();
+ recur_apoint_free_bkp (ERASE_FORCE_KEEP_NOTE);
}
diff --git a/src/recur.h b/src/recur.h
index 60231f2..36d105f 100755
--- a/src/recur.h
+++ b/src/recur.h
@@ -1,4 +1,4 @@
-/* $calcurse: recur.h,v 1.25 2009/01/01 17:50:41 culot Exp $ */
+/* $calcurse: recur.h,v 1.26 2009/01/03 21:32:11 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -86,8 +86,8 @@ typedef void (*recur_cb_foreach_date_t)(FILE *, long, char *);
extern recur_apoint_llist_t *recur_alist_p;
extern struct recur_event_s *recur_elist;
-void recur_event_free_bkp (void);
-void recur_apoint_free_bkp (void);
+void recur_event_free_bkp (erase_flag_e);
+void recur_apoint_free_bkp (erase_flag_e);
void recur_apoint_llist_init (void);
void recur_apoint_llist_free (void);
void recur_event_llist_free (void);
diff --git a/src/todo.c b/src/todo.c
index 34bc8f2..a8c5ab5 100755
--- a/src/todo.c
+++ b/src/todo.c
@@ -1,4 +1,4 @@
-/* $calcurse: todo.c,v 1.30 2009/01/02 19:52:32 culot Exp $ */
+/* $calcurse: todo.c,v 1.31 2009/01/03 21:32:11 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -252,7 +252,7 @@ todo_delete (conf_t *conf)
}
else
{
- erase_status_bar ();
+ wins_erase_status_bar ();
return;
}
}
@@ -261,7 +261,7 @@ todo_delete (conf_t *conf)
if (go_for_todo_del == false)
{
- erase_status_bar ();
+ wins_erase_status_bar ();
return;
}
@@ -292,7 +292,7 @@ todo_delete (conf_t *conf)
todo_delete_note_bynum (hilt - 1);
break;
default:
- erase_status_bar ();
+ wins_erase_status_bar ();
return;
}
}
diff --git a/src/utils.c b/src/utils.c
index 517da04..d739e6c 100755
--- a/src/utils.c
+++ b/src/utils.c
@@ -1,4 +1,4 @@
-/* $calcurse: utils.c,v 1.65 2009/01/02 22:28:54 culot Exp $ */
+/* $calcurse: utils.c,v 1.66 2009/01/03 21:32:11 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -31,7 +31,6 @@
#include <unistd.h>
#include <ctype.h>
#include <sys/types.h>
-#include <math.h>
#include <errno.h>
#include "utils.h"
@@ -48,14 +47,6 @@
#include "keys.h"
#include "mem.h"
-#define NB_CAL_CMDS 24 /* number of commands while in cal view */
-#define NB_APP_CMDS 31 /* same thing while in appointment view */
-#define NB_TOD_CMDS 29 /* same thing while in todo view */
-#define TOTAL_CMDS NB_CAL_CMDS + NB_APP_CMDS + NB_TOD_CMDS
-#define CMDS_PER_LINE 6 /* max number of commands per line */
-
-static unsigned status_page;
-
/* General routine to exit calcurse properly. */
void
exit_calcurse (int status)
@@ -69,16 +60,15 @@ exit_calcurse (int status)
}
calendar_stop_date_thread ();
io_stop_psave_thread ();
- day_saved_item_free ();
day_free_list ();
event_llist_free ();
- event_free_bkp ();
+ event_free_bkp (ERASE_FORCE);
apoint_llist_free ();
- apoint_free_bkp ();
+ apoint_free_bkp (ERASE_FORCE);
recur_apoint_llist_free ();
recur_event_llist_free ();
- recur_apoint_free_bkp ();
- recur_event_free_bkp ();
+ recur_apoint_free_bkp (ERASE_FORCE);
+ recur_event_free_bkp (ERASE_FORCE);
todo_free_list ();
keys_free ();
mem_stats ();
@@ -118,20 +108,13 @@ fatalbox (const char *errmsg)
void
status_mesg (char *mesg_line1, char *mesg_line2)
{
- erase_status_bar ();
+ wins_erase_status_bar ();
custom_apply_attr (win[STA].p, ATTR_HIGHEST);
mvwprintw (win[STA].p, 0, 0, mesg_line1);
mvwprintw (win[STA].p, 1, 0, mesg_line2);
custom_remove_attr (win[STA].p, ATTR_HIGHEST);
}
-/* Erase status bar. */
-void
-erase_status_bar (void)
-{
- erase_window_part (win[STA].p, 0, 0, col, STATUSHEIGHT);
-}
-
/* Erase part of a window. */
void
erase_window_part (WINDOW *win, int first_col, int first_row, int last_col,
@@ -388,18 +371,20 @@ updatestring (WINDOW *win, char **str, int x, int y)
char *newstr;
int escape, len = strlen (*str) + 1;
- newstr = (char *) mem_malloc (BUFSIZ);
+ EXIT_IF (len > BUFSIZ, _("Internal error: line too long"));
+
+ newstr = mem_malloc (BUFSIZ);
(void) memcpy (newstr, *str, len);
escape = getstring (win, newstr, BUFSIZ, x, y);
if (!escape)
{
len = strlen (newstr) + 1;
- *str = (char *) realloc (*str, len);
+ *str = mem_realloc (*str, len);
EXIT_IF (*str == 0, _("out of memory"));
(void) memcpy (*str, newstr, len);
}
mem_free (newstr);
- return (escape);
+ return escape;
}
/* checks if a string is only made of digits */
@@ -420,81 +405,6 @@ is_all_digit (char *string)
return all_digit;
}
-/*
- * Draws the status bar.
- * To add a keybinding, insert a new binding_t item, add it in the *binding
- * table, and update the NB_CAL_CMDS, NB_APP_CMDS or NB_TOD_CMDS defines,
- * depending on which panel the added keybind is assigned to.
- */
-void
-status_bar (void)
-{
-#define NB_PANELS 3 /* 3 panels: CALENDAR, APPOINTMENT, TODO */
- window_e which_pan;
- int start, end;
- const int pos[NB_PANELS + 1] =
- { 0, NB_CAL_CMDS, NB_CAL_CMDS + NB_APP_CMDS, TOTAL_CMDS };
-
- binding_t help = {_("Help"), KEY_GENERIC_HELP};
- binding_t quit = {_("Quit"), KEY_GENERIC_QUIT};
- binding_t save = {_("Save"), KEY_GENERIC_SAVE};
- binding_t cut = {_("Cut"), KEY_GENERIC_CUT};
- binding_t paste = {_("Paste"), KEY_GENERIC_PASTE};
- binding_t chgvu = {_("Chg View"), KEY_GENERIC_CHANGE_VIEW};
- binding_t import = {_("Import"), KEY_GENERIC_IMPORT};
- binding_t export = {_("Export"), KEY_GENERIC_EXPORT};
- binding_t togo = {_("Go to"), KEY_GENERIC_GOTO};
- binding_t othr = {_("OtherCmd"), KEY_GENERIC_OTHER_CMD};
- binding_t conf = {_("Config"), KEY_GENERIC_CONFIG_MENU};
- binding_t draw = {_("Redraw"), KEY_GENERIC_REDRAW};
- binding_t appt = {_("Add Appt"), KEY_GENERIC_ADD_APPT};
- binding_t todo = {_("Add Todo"), KEY_GENERIC_ADD_TODO};
- binding_t gnday = {_("+1 Day"), KEY_GENERIC_NEXT_DAY};
- binding_t gpday = {_("-1 Day"), KEY_GENERIC_PREV_DAY};
- binding_t gnweek = {_("+1 Week"), KEY_GENERIC_NEXT_WEEK};
- binding_t gpweek = {_("-1 Week"), KEY_GENERIC_PREV_WEEK};
- binding_t today = {_("Today"), KEY_GENERIC_GOTO_TODAY};
- binding_t up = {_("Up"), KEY_MOVE_UP};
- binding_t down = {_("Down"), KEY_MOVE_DOWN};
- binding_t left = {_("Left"), KEY_MOVE_LEFT};
- binding_t right = {_("Right"), KEY_MOVE_RIGHT};
- binding_t weekb = {_("beg Week"), KEY_START_OF_WEEK};
- binding_t weeke = {_("end Week"), KEY_END_OF_WEEK};
- binding_t add = {_("Add Item"), KEY_ADD_ITEM};
- binding_t del = {_("Del Item"), KEY_DEL_ITEM};
- binding_t edit = {_("Edit Itm"), KEY_EDIT_ITEM};
- binding_t view = {_("View"), KEY_VIEW_ITEM};
- binding_t flag = {_("Flag Itm"), KEY_FLAG_ITEM};
- binding_t rept = {_("Repeat"), KEY_REPEAT_ITEM};
- binding_t enote = {_("EditNote"), KEY_EDIT_NOTE};
- binding_t vnote = {_("ViewNote"), KEY_VIEW_NOTE};
- binding_t rprio = {_("Prio.+"), KEY_RAISE_PRIORITY};
- binding_t lprio = {_("Prio.-"), KEY_LOWER_PRIORITY};
-
-
- binding_t *binding[TOTAL_CMDS] = {
- /* calendar keys */
- &help, &quit, &save, &chgvu, &import, &export, &up, &down, &left, &right,
- &togo, &othr, &weekb, &weeke, &conf, &draw, &appt, &todo, &gnday, &gpday,
- &gnweek, &gpweek, &today, &othr,
- /* appointment keys */
- &help, &quit, &save, &chgvu, &import, &export, &add, &del, &edit, &view,
- &draw, &othr, &rept, &flag, &enote, &vnote, &up, &down, &gnday, &gpday,
- &gnweek, &gpweek, &togo, &othr, &today, &conf, &appt, &todo, &cut, &paste,
- &othr,
- /* todo keys */
- &help, &quit, &save, &chgvu, &import, &export, &add, &del, &edit, &view,
- &draw, &othr, &rprio, &lprio, &enote, &vnote, &up, &down, &gnday, &gpday,
- &gnweek, &gpweek, &togo, &othr, &today, &conf, &appt, &todo, &othr
- };
-
- /* Drawing the keybinding with attribute and label without. */
- which_pan = wins_slctd ();
- start = pos[which_pan] + 2 * KEYS_CMDS_PER_LINE * (status_page - 1);
- end = MIN (start + 2 * KEYS_CMDS_PER_LINE, pos[which_pan + 1]);
- keys_display_bindings_bar (win[STA].p, binding, start, end);
-}
-
/* Given an item date expressed in seconds, return its start time in seconds. */
long
get_item_time (long date)
@@ -770,41 +680,6 @@ item_in_popup (char *saved_a_start, char *saved_a_end, char *msg,
delwin (popup_win);
}
-/* Reset the status bar page. */
-void
-reset_status_page (void)
-{
- status_page = 1;
-}
-
-/* Update the status bar page number to display other commands. */
-void
-other_status_page (int panel)
-{
- int nb_item = 0, max_page;
-
- switch (panel)
- {
- case CAL:
- nb_item = NB_CAL_CMDS;
- break;
- case APP:
- nb_item = NB_APP_CMDS;
- break;
- case TOD:
- nb_item = NB_TOD_CMDS;
- break;
- default:
- EXIT (_("unknown panel"));
- /* NOTREACHED */
- }
- max_page = ceil (nb_item / (2 * CMDS_PER_LINE + 1)) + 1;
- if (status_page < max_page)
- status_page++;
- else
- status_page = 1;
-}
-
/* Returns the beginning of current day in seconds from 1900. */
long
get_today (void)
@@ -909,7 +784,7 @@ new_tempfile (const char *prefix, int trailing_len)
}
fclose (file);
- return (mem_strdup (fullname + prefix_len));
+ return mem_strdup (fullname + prefix_len);
}
/* Erase a note previously attached to a todo, event or appointment. */
diff --git a/src/utils.h b/src/utils.h
index 6f4b13c..fcd9c0d 100755
--- a/src/utils.h
+++ b/src/utils.h
@@ -1,4 +1,4 @@
-/* $calcurse: utils.h,v 1.42 2009/01/01 17:50:41 culot Exp $ */
+/* $calcurse: utils.h,v 1.43 2009/01/03 21:32:11 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -104,14 +104,12 @@ erase_flag_e;
void exit_calcurse (int);
void fatalbox (const char *);
void status_mesg (char *, char *);
-void erase_status_bar (void);
void erase_window_part (WINDOW *, int, int, int, int);
WINDOW *popup (int, int, int, int, char *, char *, int);
void print_in_middle (WINDOW *, int, int, int, char *);
int getstring (WINDOW *, char *, int, int, int);
int updatestring (WINDOW *, char **, int, int);
int is_all_digit (char *);
-void status_bar (void);
long get_item_time (long);
int get_item_hour (long);
int get_item_min (long);
@@ -126,8 +124,6 @@ long min2sec (unsigned);
int check_time (char *);
void draw_scrollbar (WINDOW *, int, int, int, int, int, bool);
void item_in_popup (char *, char *, char *, char *);
-void reset_status_page (void);
-void other_status_page (int);
long get_today (void);
long now (void);
long mystrtol (const char *);
diff --git a/src/wins.c b/src/wins.c
index 2de2a18..a9c5cb3 100755
--- a/src/wins.c
+++ b/src/wins.c
@@ -1,8 +1,8 @@
-/* $calcurse: wins.c,v 1.22 2009/01/02 22:28:54 culot Exp $ */
+/* $calcurse: wins.c,v 1.23 2009/01/03 21:32:11 culot Exp $ */
/*
* Calcurse - text-based organizer
- * Copyright (c) 2007-2008 Frederic Culot
+ * Copyright (c) 2007-2009 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,8 +26,10 @@
#include <stdlib.h>
#include <string.h>
+#include <math.h>
#include "i18n.h"
+#include "keys.h"
#include "notify.h"
#include "utils.h"
#include "todo.h"
@@ -422,7 +424,7 @@ wins_update (void)
apoint_update_panel (slctd_win);
todo_update_panel (slctd_win);
calendar_update_panel (win[CAL].p);
- status_bar ();
+ wins_status_bar ();
if (notify_bar ())
notify_update_bar ();
wmove (win[STA].p, 0, 0);
@@ -476,3 +478,135 @@ wins_launch_external (const char *file, const char *cmd)
notify_start_main_thread ();
mem_free (p);
}
+
+#define NB_CAL_CMDS 24 /* number of commands while in cal view */
+#define NB_APP_CMDS 31 /* same thing while in appointment view */
+#define NB_TOD_CMDS 29 /* same thing while in todo view */
+#define TOTAL_CMDS NB_CAL_CMDS + NB_APP_CMDS + NB_TOD_CMDS
+#define CMDS_PER_LINE 6 /* max number of commands per line */
+
+static unsigned status_page;
+
+/*
+ * Draws the status bar.
+ * To add a keybinding, insert a new binding_t item, add it in the *binding
+ * table, and update the NB_CAL_CMDS, NB_APP_CMDS or NB_TOD_CMDS defines,
+ * depending on which panel the added keybind is assigned to.
+ */
+void
+wins_status_bar (void)
+{
+#define NB_PANELS 3 /* 3 panels: CALENDAR, APPOINTMENT, TODO */
+ window_e which_pan;
+ int start, end;
+ const int pos[NB_PANELS + 1] =
+ { 0, NB_CAL_CMDS, NB_CAL_CMDS + NB_APP_CMDS, TOTAL_CMDS };
+
+ binding_t help = {_("Help"), KEY_GENERIC_HELP};
+ binding_t quit = {_("Quit"), KEY_GENERIC_QUIT};
+ binding_t save = {_("Save"), KEY_GENERIC_SAVE};
+ binding_t cut = {_("Cut"), KEY_GENERIC_CUT};
+ binding_t paste = {_("Paste"), KEY_GENERIC_PASTE};
+ binding_t chgvu = {_("Chg View"), KEY_GENERIC_CHANGE_VIEW};
+ binding_t import = {_("Import"), KEY_GENERIC_IMPORT};
+ binding_t export = {_("Export"), KEY_GENERIC_EXPORT};
+ binding_t togo = {_("Go to"), KEY_GENERIC_GOTO};
+ binding_t othr = {_("OtherCmd"), KEY_GENERIC_OTHER_CMD};
+ binding_t conf = {_("Config"), KEY_GENERIC_CONFIG_MENU};
+ binding_t draw = {_("Redraw"), KEY_GENERIC_REDRAW};
+ binding_t appt = {_("Add Appt"), KEY_GENERIC_ADD_APPT};
+ binding_t todo = {_("Add Todo"), KEY_GENERIC_ADD_TODO};
+ binding_t gnday = {_("+1 Day"), KEY_GENERIC_NEXT_DAY};
+ binding_t gpday = {_("-1 Day"), KEY_GENERIC_PREV_DAY};
+ binding_t gnweek = {_("+1 Week"), KEY_GENERIC_NEXT_WEEK};
+ binding_t gpweek = {_("-1 Week"), KEY_GENERIC_PREV_WEEK};
+ binding_t today = {_("Today"), KEY_GENERIC_GOTO_TODAY};
+ binding_t up = {_("Up"), KEY_MOVE_UP};
+ binding_t down = {_("Down"), KEY_MOVE_DOWN};
+ binding_t left = {_("Left"), KEY_MOVE_LEFT};
+ binding_t right = {_("Right"), KEY_MOVE_RIGHT};
+ binding_t weekb = {_("beg Week"), KEY_START_OF_WEEK};
+ binding_t weeke = {_("end Week"), KEY_END_OF_WEEK};
+ binding_t add = {_("Add Item"), KEY_ADD_ITEM};
+ binding_t del = {_("Del Item"), KEY_DEL_ITEM};
+ binding_t edit = {_("Edit Itm"), KEY_EDIT_ITEM};
+ binding_t view = {_("View"), KEY_VIEW_ITEM};
+ binding_t flag = {_("Flag Itm"), KEY_FLAG_ITEM};
+ binding_t rept = {_("Repeat"), KEY_REPEAT_ITEM};
+ binding_t enote = {_("EditNote"), KEY_EDIT_NOTE};
+ binding_t vnote = {_("ViewNote"), KEY_VIEW_NOTE};
+ binding_t rprio = {_("Prio.+"), KEY_RAISE_PRIORITY};
+ binding_t lprio = {_("Prio.-"), KEY_LOWER_PRIORITY};
+
+
+ binding_t *binding[TOTAL_CMDS] = {
+ /* calendar keys */
+ &help, &quit, &save, &chgvu, &import, &export, &up, &down, &left, &right,
+ &togo, &othr, &weekb, &weeke, &conf, &draw, &appt, &todo, &gnday, &gpday,
+ &gnweek, &gpweek, &today, &othr,
+ /* appointment keys */
+ &help, &quit, &save, &chgvu, &import, &export, &add, &del, &edit, &view,
+ &draw, &othr, &rept, &flag, &enote, &vnote, &up, &down, &gnday, &gpday,
+ &gnweek, &gpweek, &togo, &othr, &today, &conf, &appt, &todo, &cut, &paste,
+ &othr,
+ /* todo keys */
+ &help, &quit, &save, &chgvu, &import, &export, &add, &del, &edit, &view,
+ &draw, &othr, &rprio, &lprio, &enote, &vnote, &up, &down, &gnday, &gpday,
+ &gnweek, &gpweek, &togo, &othr, &today, &conf, &appt, &todo, &othr
+ };
+
+ /* Drawing the keybinding with attribute and label without. */
+ which_pan = wins_slctd ();
+ start = pos[which_pan] + 2 * KEYS_CMDS_PER_LINE * (status_page - 1);
+ end = MIN (start + 2 * KEYS_CMDS_PER_LINE, pos[which_pan + 1]);
+ keys_display_bindings_bar (win[STA].p, binding, start, end);
+}
+
+/* Erase status bar. */
+void
+wins_erase_status_bar (void)
+{
+ erase_window_part (win[STA].p, 0, 0, col, STATUSHEIGHT);
+}
+
+/* Update the status bar page number to display other commands. */
+void
+wins_other_status_page (int panel)
+{
+ int nb_item, max_page;
+
+ nb_item = 0;
+ switch (panel)
+ {
+ case CAL:
+ nb_item = NB_CAL_CMDS;
+ break;
+ case APP:
+ nb_item = NB_APP_CMDS;
+ break;
+ case TOD:
+ nb_item = NB_TOD_CMDS;
+ break;
+ default:
+ EXIT (_("unknown panel"));
+ /* NOTREACHED */
+ }
+ max_page = ceil (nb_item / (2 * CMDS_PER_LINE + 1)) + 1;
+ if (status_page < max_page)
+ status_page++;
+ else
+ status_page = 1;
+}
+
+/* Reset the status bar page. */
+void
+wins_reset_status_page (void)
+{
+ status_page = 1;
+}
+
+#undef NB_CAL_CMDS
+#undef NB_APP_CMDS
+#undef NB_TOD_CMDS
+#undef TOTAL_CMDS
+#undef CMDS_PER_LINE
diff --git a/src/wins.h b/src/wins.h
index 415d479..678fa82 100755
--- a/src/wins.h
+++ b/src/wins.h
@@ -1,8 +1,8 @@
-/* $calcurse: wins.h,v 1.10 2008/11/23 20:38:56 culot Exp $ */
+/* $calcurse: wins.h,v 1.11 2009/01/03 21:32:11 culot Exp $ */
/*
* Calcurse - text-based organizer
- * Copyright (c) 2007-2008 Frederic Culot
+ * Copyright (c) 2007-2009 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -80,5 +80,9 @@ void wins_get_config (void);
void wins_update (void);
void wins_reset (void);
void wins_launch_external (const char *, const char *);
+void wins_status_bar (void);
+void wins_erase_status_bar (void);
+void wins_other_status_page (int);
+void wins_reset_status_page (void);
#endif /* CALCURSE_WINS_H */