summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFrederic Culot <calcurse@culot.org>2008-12-14 15:54:50 +0000
committerFrederic Culot <calcurse@culot.org>2008-12-14 15:54:50 +0000
commit65ec1bb0fa126748a84555406c22de3588f47b9b (patch)
treebc732b49d769b75a6e56ac15e29deeda8af2f03f /src
parent8900d0f8f267c5508aa2c940c57e879baf0a25af (diff)
downloadcalcurse-65ec1bb0fa126748a84555406c22de3588f47b9b.tar.gz
calcurse-65ec1bb0fa126748a84555406c22de3588f47b9b.zip
small bugfixes and code cleanup
Diffstat (limited to 'src')
-rwxr-xr-xsrc/apoint.c16
-rwxr-xr-xsrc/calendar.c4
-rwxr-xr-xsrc/custom.c55
-rwxr-xr-xsrc/event.c23
-rwxr-xr-xsrc/io.c54
-rwxr-xr-xsrc/recur.c65
-rwxr-xr-xsrc/utils.c29
7 files changed, 86 insertions, 160 deletions
diff --git a/src/apoint.c b/src/apoint.c
index 3928b7e..1b067ba 100755
--- a/src/apoint.c
+++ b/src/apoint.c
@@ -1,4 +1,4 @@
-/* $calcurse: apoint.c,v 1.26 2008/12/12 20:44:50 culot Exp $ */
+/* $calcurse: apoint.c,v 1.27 2008/12/14 15:54:51 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -381,12 +381,8 @@ apoint_scan (FILE *f, struct tm start, struct tm end, char state, char *note)
tstart = mktime (&start);
tend = mktime (&end);
- if (tstart == -1 || tend == -1 || tstart > tend)
- {
- fputs (_("FATAL ERROR in apoint_scan: date error in the appointment\n"),
- stderr);
- exit (EXIT_FAILURE);
- }
+ EXIT_IF (tstart == -1 || tend == -1 || tstart > tend,
+ _("date error in appointment"));
return (apoint_new (buf, note, tstart, tend - tstart, state));
}
@@ -407,9 +403,9 @@ apoint_get (long day, int pos)
n++;
}
}
- /* NOTREACHED */
- fputs (_("FATAL ERROR in apoint_get: no such item\n"), stderr);
- exit (EXIT_FAILURE);
+ EXIT (_("item not found"));
+ return 0;
+ /* NOTREACHED */
}
void
diff --git a/src/calendar.c b/src/calendar.c
index 31403d1..e6f8feb 100755
--- a/src/calendar.c
+++ b/src/calendar.c
@@ -1,4 +1,4 @@
-/* $calcurse: calendar.c,v 1.19 2008/12/07 09:20:38 culot Exp $ */
+/* $calcurse: calendar.c,v 1.20 2008/12/14 15:54:51 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -130,7 +130,7 @@ calendar_set_first_day_of_week (wday_e first_day)
week_begins_on_monday = true;
break;
default:
- fputs (_("ERROR in calendar_set_first_day_of_week\n"), stderr);
+ ERROR_MSG (_("ERROR setting first day of week"));
week_begins_on_monday = false;
/* NOTREACHED */
}
diff --git a/src/custom.c b/src/custom.c
index 6263008..5a7477c 100755
--- a/src/custom.c
+++ b/src/custom.c
@@ -1,4 +1,4 @@
-/* $calcurse: custom.c,v 1.29 2008/12/08 19:17:07 culot Exp $ */
+/* $calcurse: custom.c,v 1.30 2008/12/14 15:54:51 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -46,9 +46,8 @@ fill_config_var (char *string)
return (false);
else
{
- fputs (_("FATAL ERROR in fill_config_var: "
- "wrong configuration variable format.\n"), stderr);
- return (EXIT_FAILURE);
+ EXIT (_("wrong configuration variable format."));
+ return false;
}
}
@@ -65,26 +64,16 @@ custom_load_color (char *color, int background)
int i, len, color_num;
char c[AWAITED_COLORS][BUFSIZ];
int colr[AWAITED_COLORS];
- const char *wrong_color_number =
- _("FATAL ERROR in custom_load_color: wrong color number.\n");
- const char *wrong_color_name =
- _("FATAL ERROR in custom_load_color: wrong color name.\n");
- const char *wrong_variable_format =
- _("FATAL ERROR in custom_load_color: "
- "wrong configuration variable format.\n");
len = strlen (color);
-
if (len > 1)
{
/* New version configuration */
if (sscanf (color, "%s on %s", c[0], c[1]) != AWAITED_COLORS)
{
- fputs (_("FATAL ERROR in custom_load_color: "
- "missing colors in config file.\n"), stderr);
- exit (EXIT_FAILURE);
+ EXIT (_("missing colors in config file"));
/* NOTREACHED */
- };
+ }
for (i = 0; i < AWAITED_COLORS; i++)
{
@@ -108,8 +97,7 @@ custom_load_color (char *color, int background)
colr[i] = background;
else
{
- fputs (wrong_color_name, stderr);
- exit (EXIT_FAILURE);
+ EXIT (_("wrong color name"));
/* NOTREACHED */
}
}
@@ -150,15 +138,13 @@ custom_load_color (char *color, int background)
init_pair (COLR_CUSTOM, COLOR_RED, COLR_BLUE);
break;
default:
- fputs (wrong_color_number, stderr);
- exit (EXIT_FAILURE);
+ EXIT (_("wrong color number"));
/* NOTREACHED */
}
}
else
{
- fputs (wrong_variable_format, stderr);
- exit (EXIT_FAILURE);
+ EXIT (_("wrong configuration variable format"));
/* NOTREACHED */
}
}
@@ -310,9 +296,7 @@ custom_load_conf (conf_t *conf, int background)
var = 0;
break;
default:
- fputs (_("FATAL ERROR in custom_load_conf: "
- "configuration variable unknown.\n"), stderr);
- exit (EXIT_FAILURE);
+ EXIT (_("configuration variable unknown"));
/* NOTREACHED */
}
@@ -686,8 +670,6 @@ custom_color_theme_name (char *theme_name)
"cyan",
"white"
};
- const char *error_txt =
- _("FATAL ERROR in custom_color_theme_name: unknown color\n");
if (!colorize)
snprintf (theme_name, BUFSIZ, "0");
@@ -702,8 +684,7 @@ custom_color_theme_name (char *theme_name)
color_name[i] = name[color[i]];
else
{
- fputs (error_txt, stderr);
- exit (EXIT_FAILURE);
+ EXIT (_("unknown color"));
/* NOTREACHED */
}
}
@@ -805,7 +786,9 @@ custom_general_config (conf_t *conf)
{
scrollwin_t cwin;
char *number_str =
- _("Enter an option number to change its value [Q to quit] ");
+ _("Enter an option number to change its value");
+ char *keys =
+ _("(Press '^P' or '^N' to move up or down, 'Q' to quit)");
char *output_datefmt_str =
_("Enter the date format (see 'man 3 strftime' for possible formats) ");
char *input_datefmt_str =
@@ -818,7 +801,7 @@ custom_general_config (conf_t *conf)
snprintf (cwin.label, BUFSIZ, _("CalCurse %s | general options"), VERSION);
wins_scrollwin_init (&cwin);
wins_show (cwin.win.p, cwin.label);
- status_mesg (number_str, "");
+ status_mesg (number_str, keys);
cwin.total_lines = print_general_options (cwin.pad.p, conf);
wins_scrollwin_display (&cwin);
@@ -844,10 +827,10 @@ custom_general_config (conf_t *conf)
notify_update_bar ();
}
break;
- case KEY_MOVE_DOWN:
+ case CTRL ('N'):
wins_scrollwin_down (&cwin, 1);
break;
- case KEY_MOVE_UP:
+ case CTRL ('P'):
wins_scrollwin_up (&cwin, 1);
break;
case '1':
@@ -876,7 +859,7 @@ custom_general_config (conf_t *conf)
{
strncpy (conf->output_datefmt, buf, strlen (buf) + 1);
}
- status_mesg (number_str, "");
+ status_mesg (number_str, keys);
break;
case '8':
status_mesg (input_datefmt_str, "");
@@ -886,10 +869,10 @@ custom_general_config (conf_t *conf)
if (val >= 1 && val <= 3)
conf->input_datefmt = val;
}
- status_mesg (number_str, "");
+ status_mesg (number_str, keys);
break;
}
- status_mesg (number_str, "");
+ status_mesg (number_str, keys);
cwin.total_lines = print_general_options (cwin.pad.p, conf);
wins_scrollwin_display (&cwin);
}
diff --git a/src/event.c b/src/event.c
index f865868..8464a77 100755
--- a/src/event.c
+++ b/src/event.c
@@ -1,4 +1,4 @@
-/* $calcurse: event.c,v 1.7 2008/04/12 21:14:03 culot Exp $ */
+/* $calcurse: event.c,v 1.8 2008/12/14 15:54:51 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -113,13 +113,9 @@ event_scan (FILE *f, struct tm start, int id, char *note)
start.tm_mon--;
tstart = mktime (&start);
- if (tstart == -1)
- {
- fputs (_("FATAL ERROR in event_scan: date error in the event\n"),
- stderr);
- exit (EXIT_FAILURE);
- }
- return (event_new (buf, note, tstart, id));
+ EXIT_IF (tstart == -1, _("date error in the event\n"));
+
+ return event_new (buf, note, tstart, id);
}
/* Retrieve an event from the list, given the day and item position. */
@@ -139,9 +135,9 @@ event_get (long day, int pos)
n++;
}
}
- /* NOTREACHED */
- fputs (_("FATAL ERROR in event_get: no such item\n"), stderr);
- exit (EXIT_FAILURE);
+ EXIT (_("event not found"));
+ return 0;
+ /* NOTREACHED */
}
/* Delete an event from the list. */
@@ -174,7 +170,6 @@ event_delete_bynum (long start, unsigned num, erase_flag_e flag)
}
iptr = &i->next;
}
- /* NOTREACHED */
- fputs (_("FATAL ERROR in event_delete_bynum: no such event\n"), stderr);
- exit (EXIT_FAILURE);
+ EXIT (_("event not found"));
+ /* NOTREACHED */
}
diff --git a/src/io.c b/src/io.c
index 253db1d..303bf8b 100755
--- a/src/io.c
+++ b/src/io.c
@@ -1,4 +1,4 @@
-/* $calcurse: io.c,v 1.48 2008/12/14 11:24:19 culot Exp $ */
+/* $calcurse: io.c,v 1.49 2008/12/14 15:54:51 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -437,10 +437,7 @@ pcal_export_recur_events (FILE *stream)
fprintf (stream, "%s %s\n", pcal_date, i->mesg);
break;
default:
- fputs (_("FATAL ERROR in pcal_export_recur_events: "
- "incoherent repetition type\n"), stderr);
- exit (EXIT_FAILURE);
- break;
+ EXIT (_("incoherent repetition type"));
}
}
else
@@ -573,10 +570,7 @@ pcal_export_recur_apoints (FILE *stream)
pcal_beg, pcal_end, i->mesg);
break;
default:
- fputs (_("FATAL ERROR in pcal_export_recur_apoints: "
- "incoherent repetition type\n"), stderr);
- exit (EXIT_FAILURE);
- break;
+ EXIT (_("incoherent repetition type"));
}
}
else
@@ -967,8 +961,6 @@ io_load_app (void)
int freq;
char type, state = 0L;
char note[NOTESIZ + 1], *notep;
- char *error =
- _("FATAL ERROR in io_load_app: wrong format in the appointment or event\n");
t = time (NULL);
lt = localtime (&t);
@@ -989,9 +981,7 @@ io_load_app (void)
if (fscanf (data_file, "%u / %u / %u ",
&start.tm_mon, &start.tm_mday, &start.tm_year) != 3)
{
- fputs (_("FATAL ERROR in io_load_app: "
- "syntax error in the item date\n"), stderr);
- exit (EXIT_FAILURE);
+ EXIT (_("syntax error in the item date"));
}
/* Read the next character : if it is an '@' then we have
@@ -1005,9 +995,7 @@ io_load_app (void)
is_event = 1;
else
{
- fputs (_("FATAL ERROR in io_load_app: "
- "no event nor appointment found\n"), stderr);
- exit (EXIT_FAILURE);
+ EXIT (_("no event nor appointment found"));
}
ungetc (c, data_file);
@@ -1024,9 +1012,9 @@ io_load_app (void)
fscanf (data_file, "[%d] ", &id);
}
else
- { /* NOT REACHED */
- fputs (error, stderr);
- exit (EXIT_FAILURE);
+ {
+ EXIT (_("wrong format in the appointment or event"));
+ /* NOTREACHED */
}
/* Check if we have a recursive item. */
@@ -1071,9 +1059,9 @@ io_load_app (void)
until.tm_year = 0;
}
else
- { /* NOT REACHED */
- fputs (error, stderr);
- exit (EXIT_FAILURE);
+ {
+ EXIT (_("wrong format in the appointment or event"));
+ /* NOTREACHED */
}
}
else
@@ -1136,9 +1124,9 @@ io_load_app (void)
}
}
else
- { /* NOT REACHED */
- fputs (error, stderr);
- exit (EXIT_FAILURE);
+ {
+ EXIT (_("wrong format in the appointment or event"));
+ /* NOTREACHED */
}
}
fclose (data_file);
@@ -1469,16 +1457,13 @@ void
io_export_data (export_type_t type, conf_t *conf)
{
FILE *stream;
- char *wrong_mode = _("FATAL ERROR in io_export_data: wrong export mode\n");
- char *wrong_type = _("FATAL ERROR in io_export_data: unknown export type\n");
char *success = _("The data were successfully exported");
char *enter = _("Press [ENTER] to continue");
if (type < IO_EXPORT_ICAL || type >= IO_EXPORT_NBTYPES)
- {
- fputs (wrong_type, stderr);
- exit (EXIT_FAILURE);
- }
+ EXIT (_("unknown export type"));
+
+ stream = 0;
switch (ui_mode)
{
case UI_CMDLINE:
@@ -1488,12 +1473,11 @@ io_export_data (export_type_t type, conf_t *conf)
stream = get_export_stream (type);
break;
default:
- fputs (wrong_mode, stderr);
- exit (EXIT_FAILURE);
+ EXIT (_("wrong export mode"));
/* NOTREACHED */
}
- if (stream == NULL)
+ if (stream == 0)
return;
cb_export_header[type] (stream);
diff --git a/src/recur.c b/src/recur.c
index 339f282..140bec5 100755
--- a/src/recur.c
+++ b/src/recur.c
@@ -1,4 +1,4 @@
-/* $calcurse: recur.c,v 1.44 2008/12/14 11:24:19 culot Exp $ */
+/* $calcurse: recur.c,v 1.45 2008/12/14 15:54:51 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -127,7 +127,6 @@ char
recur_def2char (recur_types_t define)
{
char recur_char;
- char *error = _("FATAL ERROR in recur_def2char: unknown recur type\n");
switch (define)
{
@@ -144,8 +143,8 @@ recur_def2char (recur_types_t define)
recur_char = 'Y';
break;
default:
- fputs (error, stderr);
- exit (EXIT_FAILURE);
+ EXIT (_("unknown repetition type"));
+ return 0;
}
return (recur_char);
@@ -159,7 +158,6 @@ int
recur_char2def (char type)
{
int recur_def;
- char *error = _("FATAL ERROR in recur_char2def: unknown char\n");
switch (type)
{
@@ -176,8 +174,8 @@ recur_char2def (char type)
recur_def = RECUR_YEARLY;
break;
default:
- fputs (error, stderr);
- exit (EXIT_FAILURE);
+ EXIT (_("unknown character"));
+ return 0;
}
return (recur_def);
}
@@ -245,13 +243,8 @@ recur_apoint_scan (FILE *f, struct tm start, struct tm end, char type,
{
tuntil = 0;
}
-
- if (tstart == -1 || tend == -1 || tstart > tend || tuntil == -1)
- {
- fputs (_("FATAL ERROR in apoint_scan: date error in the appointment\n"),
- stderr);
- exit (EXIT_FAILURE);
- }
+ EXIT_IF (tstart == -1 || tend == -1 || tstart > tend || tuntil == -1,
+ _("date error in appointment"));
return (recur_apoint_new (buf, note, tstart, tend - tstart, state,
recur_char2def (type), freq, tuntil, exc));
@@ -293,12 +286,8 @@ recur_event_scan (FILE *f, struct tm start, int id, char type, int freq,
tuntil = 0;
}
tstart = mktime (&start);
- if ((tstart == -1) || (tuntil == -1))
- {
- fputs (_("FATAL ERROR in recur_event_scan: "
- "date error in the event\n"), stderr);
- exit (EXIT_FAILURE);
- }
+ EXIT_IF (tstart == -1 || tuntil == -1,
+ _("date error in event"));
return (recur_event_new (buf, note, tstart, id, recur_char2def (type),
freq, tuntil, exc));
@@ -418,7 +407,6 @@ recur_item_inday (long item_start, struct days_s *item_exc, int rpt_type,
struct tm lt_item, lt_day;
struct days_s *exc;
time_t t;
- char *error = _("FATAL ERROR in recur_item_inday: unknown item type\n");
day_end = day_start + DAYINSEC;
t = day_start;
@@ -475,8 +463,7 @@ recur_item_inday (long item_start, struct days_s *item_exc, int rpt_type,
lt_item.tm_year = lt_day.tm_year;
break;
default:
- fputs (error, stderr);
- exit (EXIT_FAILURE);
+ EXIT (_("unknown item type"));
}
start_date.dd = lt_item.tm_mday;
start_date.mm = lt_item.tm_mon + 1;
@@ -546,9 +533,8 @@ recur_event_erase (long start, unsigned num, unsigned delete_whole,
}
iptr = &i->next;
}
- /* NOTREACHED */
- fputs (_("FATAL ERROR in recur_event_erase: no such event\n"), stderr);
- exit (EXIT_FAILURE);
+ EXIT (_("event not found"));
+ /* NOTREACHED */
}
/*
@@ -618,10 +604,8 @@ recur_apoint_erase (long start, unsigned num, unsigned delete_whole,
}
iptr = &i->next;
}
+ EXIT (_("appointment not found"));
/* NOTREACHED */
- fputs (_("FATAL ERROR in recur_apoint_erase: no such appointment\n"),
- stderr);
- exit (EXIT_FAILURE);
}
/*
@@ -768,10 +752,9 @@ recur_repeat_item (conf_t *conf)
notify_check_repeated (ra);
}
else
- { /* NOTREACHED */
- fputs (_("FATAL ERROR in recur_repeat_item: wrong item type\n"),
- stderr);
- exit (EXIT_FAILURE);
+ {
+ EXIT (_("wrong item type"));
+ /* NOTREACHED */
}
day_erase_item (date, item_nb, ERASE_FORCE_KEEP_NOTE);
}
@@ -798,9 +781,7 @@ recur_exc_scan (FILE *data_file)
if (fscanf (data_file, "!%u / %u / %u ",
&day.tm_mon, &day.tm_mday, &day.tm_year) != 3)
{
- fputs (_("FATAL ERROR in recur_exc_scan: "
- "syntax error in the item date\n"), stderr);
- exit (EXIT_FAILURE);
+ EXIT (_("syntax error in item date"));
}
day.tm_sec = 0;
day.tm_isdst = -1;
@@ -872,9 +853,9 @@ recur_get_apoint (long date, int num)
n++;
}
}
+ EXIT (_("item not found"));
+ return 0;
/* NOTREACHED */
- fputs (_("FATAL ERROR in recur_get_apoint: no such item\n"), stderr);
- exit (EXIT_FAILURE);
}
/* Returns a structure containing the selected recurrent event. */
@@ -896,9 +877,9 @@ recur_get_event (long date, int num)
n++;
}
}
+ EXIT (_("item not found"));
+ return 0;
/* NOTREACHED */
- fputs (_("FATAL ERROR in recur_get_event: no such item\n"), stderr);
- exit (EXIT_FAILURE);
}
/* Switch recurrent item notification state. */
@@ -932,9 +913,7 @@ recur_apoint_switch_notify (long date, int recur_nb)
n++;
}
}
+ EXIT (_("item not found"));
/* NOTREACHED */
- fputs (_("FATAL ERROR in recur_apoint_switch_notify: no such item\n"),
- stderr);
- exit (EXIT_FAILURE);
}
diff --git a/src/utils.c b/src/utils.c
index 90c2e60..147229e 100755
--- a/src/utils.c
+++ b/src/utils.c
@@ -1,4 +1,4 @@
-/* $calcurse: utils.c,v 1.58 2008/12/13 21:41:25 culot Exp $ */
+/* $calcurse: utils.c,v 1.59 2008/12/14 15:54:51 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -40,9 +40,9 @@
#include "keys.h"
#include "utils.h"
-#define NB_CAL_CMDS 26 /* number of commands while in cal view */
-#define NB_APP_CMDS 30 /* same thing while in appointment view */
-#define NB_TOD_CMDS 30 /* same thing while in todo 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_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 */
@@ -410,7 +410,6 @@ status_bar (void)
const int pos[NB_PANELS + 1] =
{ 0, NB_CAL_CMDS, NB_CAL_CMDS + NB_APP_CMDS, TOTAL_CMDS };
- binding_t crdts = {_("Credits"), KEY_GENERIC_CREDITS};
binding_t help = {_("Help"), KEY_GENERIC_HELP};
binding_t quit = {_("Quit"), KEY_GENERIC_QUIT};
binding_t save = {_("Save"), KEY_GENERIC_SAVE};
@@ -449,15 +448,15 @@ status_bar (void)
/* 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, &crdts, &othr,
+ &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, &crdts, &othr,
+ &gnweek, &gpweek, &togo, &othr, &today, &conf, &appt, &todo, &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, &crdts, &othr
+ &gnweek, &gpweek, &togo, &othr, &today, &conf, &appt, &todo, &othr
};
/* Drawing the keybinding with attribute and label without. */
@@ -487,13 +486,7 @@ date2sec (date_t day, unsigned hour, unsigned min)
start.tm_year -= 1900;
start.tm_mon--;
tstart = mktime (&start);
- if (tstart == -1)
- {
- fputs (_("FATAL ERROR in date2sec: failure in mktime\n"), stderr);
- fprintf (stderr, "%u %u %u %u %u\n", day.yyyy, day.mm, day.dd,
- hour, min);
- exit (EXIT_FAILURE);
- }
+ EXIT_IF (tstart == -1, _("failure in mktime"));
return (tstart);
}
@@ -563,11 +556,7 @@ date_sec_change (long date, int delta_month, int delta_day)
lt->tm_mday += delta_day;
lt->tm_isdst = -1;
t = mktime (lt);
- if (t == -1)
- {
- fputs (_("FATAL ERROR in date_sec_change: failure in mktime\n"), stderr);
- exit (EXIT_FAILURE);
- }
+ EXIT_IF (t == -1, _("failure in mktime"));
return t;
}