code cleanup

This commit is contained in:
Frederic Culot 2008-12-12 20:44:50 +00:00
parent bd286546f4
commit 53db22a380
11 changed files with 105 additions and 192 deletions

View File

@ -1,3 +1,16 @@
2008-12-12 Frederic Culot <frederic@culot.org>
* src/utils.c (mycpy): suppressed and replaced by strdup
* src/utils.c (aerror, ierror): suppressed
* src/utils.c (warnbox): moved to fatalbox
* src/utils.h (ERROR_MSG): file name and line number added to
displayed error message
* src/utils.h (ASSERT): suppressed
2008-12-09 Frederic Culot <frederic@culot.org> 2008-12-09 Frederic Culot <frederic@culot.org>
* src/calcurse.1: manpage update for 2.4 * src/calcurse.1: manpage update for 2.4

View File

@ -1,4 +1,4 @@
/* $calcurse: apoint.c,v 1.25 2008/12/07 09:20:38 culot Exp $ */ /* $calcurse: apoint.c,v 1.26 2008/12/12 20:44:50 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -229,7 +229,6 @@ apoint_delete (conf_t *conf, unsigned *nb_events, unsigned *nb_apoints)
{ {
char *choices = "[y/n] "; char *choices = "[y/n] ";
char *del_app_str = _("Do you really want to delete this item ?"); char *del_app_str = _("Do you really want to delete this item ?");
const char *errmsg = _("FATAL ERROR in apoint_delete: no such type\n");
long date; long date;
int nb_items = *nb_apoints + *nb_events; int nb_items = *nb_apoints + *nb_events;
bool go_for_deletion = false; bool go_for_deletion = false;
@ -274,7 +273,7 @@ apoint_delete (conf_t *conf, unsigned *nb_events, unsigned *nb_apoints)
to_be_removed = 0; to_be_removed = 0;
} }
else else
ierror (errmsg, IERROR_FATAL); EXIT (_("no such type"));
/* NOTREACHED */ /* NOTREACHED */
if (hilt > 1) if (hilt > 1)
@ -452,8 +451,7 @@ apoint_delete_bynum (long start, unsigned num, erase_flag_e flag)
pthread_mutex_unlock (&(alist_p->mutex)); pthread_mutex_unlock (&(alist_p->mutex));
/* NOTREACHED */ /* NOTREACHED */
ierror (_("FATAL ERROR in apoint_delete_bynum: no such appointment"), EXIT (_("no such appointment"));
IERROR_FATAL);
} }
/* /*
@ -533,7 +531,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 = mycpy (i->mesg); app->txt = strdup (i->mesg);
app->state = i->state; app->state = i->state;
app->got_app = 1; app->got_app = 1;
} }
@ -613,8 +611,7 @@ apoint_switch_notify (void)
pthread_mutex_unlock (&(alist_p->mutex)); pthread_mutex_unlock (&(alist_p->mutex));
/* NOTREACHED */ /* NOTREACHED */
ierror (_("FATAL ERROR in apoint_switch_notify: no such appointment"), EXIT (_("no such appointment"));
IERROR_FATAL);
} }
/* Updates the Appointment panel */ /* Updates the Appointment panel */

View File

@ -1,4 +1,4 @@
/* $calcurse: day.c,v 1.40 2008/12/08 19:17:07 culot Exp $ */ /* $calcurse: day.c,v 1.41 2008/12/12 20:44:50 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -454,15 +454,13 @@ day_write_pad (long date, int width, int length, int incolor)
void void
day_popup_item (void) day_popup_item (void)
{ {
char *error = _("FATAL ERROR in day_popup_item: unknown item type\n");
if (day_saved_item->type == EVNT || day_saved_item->type == RECUR_EVNT) if (day_saved_item->type == EVNT || day_saved_item->type == RECUR_EVNT)
item_in_popup (NULL, NULL, day_saved_item->mesg, _("Event :")); item_in_popup (NULL, NULL, day_saved_item->mesg, _("Event :"));
else if (day_saved_item->type == APPT || day_saved_item->type == RECUR_APPT) else if (day_saved_item->type == APPT || day_saved_item->type == RECUR_APPT)
item_in_popup (day_saved_item->start, day_saved_item->end, item_in_popup (day_saved_item->start, day_saved_item->end,
day_saved_item->mesg, _("Appointment :")); day_saved_item->mesg, _("Appointment :"));
else else
ierror (error, IERROR_FATAL); EXIT (_("unknown item type"));
/* NOTREACHED */ /* NOTREACHED */
} }

View File

@ -1,4 +1,4 @@
/* $calcurse: io.c,v 1.46 2008/12/08 19:17:07 culot Exp $ */ /* $calcurse: io.c,v 1.47 2008/12/12 20:44:50 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -1257,8 +1257,7 @@ io_load_keys (char *pager)
} }
keyfp = fopen (path_keys, "r"); keyfp = fopen (path_keys, "r");
EXIT_IF (keyfp == NULL, EXIT_IF (keyfp == NULL, _("could not find any key file."));
_("FATAL ERROR in io_load_keys: could not find any key file."));
log = io_log_init (); log = io_log_init ();
skipped = loaded = line = 0; skipped = loaded = line = 0;
while (fgets (buf, BUFSIZ, keyfp) != NULL) while (fgets (buf, BUFSIZ, keyfp) != NULL)
@ -1576,8 +1575,7 @@ ical_log (FILE *log, ical_types_e type, unsigned lineno, char *msg)
{ {
const char *typestr[ICAL_TYPES] = {"VEVENT", "VTODO"}; const char *typestr[ICAL_TYPES] = {"VEVENT", "VTODO"};
RETURN_IF (type < 0 || type >= ICAL_TYPES, RETURN_IF (type < 0 || type >= ICAL_TYPES, _("unknown ical type"));
_("ERROR in ical_log: unknown ical type"));
if (log) if (log)
fprintf (log, "%s [%d]: %s\n", typestr[type], lineno, msg); fprintf (log, "%s [%d]: %s\n", typestr[type], lineno, msg);
} }
@ -2586,8 +2584,7 @@ io_import_data (import_type_t type, conf_t *conf, char *stream_name)
unsigned events, apoints, todos, lines, skipped; unsigned events, apoints, todos, lines, skipped;
} stats; } stats;
EXIT_IF (type < 0 || type >= IO_IMPORT_NBTYPES, EXIT_IF (type < 0 || type >= IO_IMPORT_NBTYPES, _("unknown import type"));
_("FATAL ERROR in io_import_data: unknown import type"));
switch (ui_mode) switch (ui_mode)
{ {
case UI_CMDLINE: case UI_CMDLINE:
@ -2600,7 +2597,7 @@ io_import_data (import_type_t type, conf_t *conf, char *stream_name)
stream = get_import_stream (type); stream = get_import_stream (type);
break; break;
default: default:
EXIT (_("FATAL ERROR in io_import_data: wrong import mode")); EXIT (_("FATAL ERROR: wrong import mode"));
/* NOTREACHED */ /* NOTREACHED */
} }

View File

@ -1,4 +1,4 @@
/* $calcurse: keys.c,v 1.8 2008/12/08 19:17:07 culot Exp $ */ /* $calcurse: keys.c,v 1.9 2008/12/12 20:44:50 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -133,8 +133,7 @@ keys_dump_defaults (char *file)
int i; int i;
fd = fopen (file, "w"); fd = fopen (file, "w");
EXIT_IF (fd == NULL, _("FATAL ERROR in keys_dump_defaults: " EXIT_IF (fd == NULL, _("FATAL ERROR: could not create default keys file."));
"could not create default keys file."));
dump_intro (fd); dump_intro (fd);
for (i = 0; i < NBKEYS; i++) for (i = 0; i < NBKEYS; i++)
@ -146,7 +145,7 @@ char *
keys_get_label (keys_e key) keys_get_label (keys_e key)
{ {
EXIT_IF (key < 0 || key > NBKEYS, EXIT_IF (key < 0 || key > NBKEYS,
_("FATAL ERROR in keys_get_label: key value out of bounds")); _("FATAL ERROR: key value out of bounds"));
return keydef[key].label; return keydef[key].label;
} }
@ -553,8 +552,7 @@ keys_save_bindings (FILE *fd)
{ {
int i; int i;
EXIT_IF (fd == NULL, _("FATAL ERROR in keys_save_bindings: " EXIT_IF (fd == NULL, _("FATAL ERROR: null file pointer."));
"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)); fprintf (fd, "%s %s\n", keydef[i].label, keys_action_allkeys (i));

View File

@ -1,4 +1,4 @@
/* $calcurse: notify.c,v 1.30 2008/12/07 09:20:38 culot Exp $ */ /* $calcurse: notify.c,v 1.31 2008/12/12 20:44:50 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -133,11 +133,10 @@ launch_cmd (char *cmd, char *shell)
pid = fork (); pid = fork ();
if (pid < 0) if (pid < 0)
ierror (_("FATAL ERROR in launch_cmd: could not fork"), IERROR_WARN); ERROR_MSG (_("error while launching command: could not fork"));
else if (pid == 0) /* Child: launch user defined command */ else if (pid == 0) /* Child: launch user defined command */
if (execlp (shell, shell, "-c", cmd, (char *) NULL) < 0) if (execlp (shell, shell, "-c", cmd, (char *)0) < 0)
ierror (_("FATAL ERROR in launch_cmd: could not " ERROR_MSG (_("error while launching command"));
"launch user command"), IERROR_WARN);
} }
/* /*
@ -286,7 +285,7 @@ notify_thread_app (void *arg)
{ {
notify_app->got_app = 1; notify_app->got_app = 1;
notify_app->time = tmp_app.time; notify_app->time = tmp_app.time;
notify_app->txt = mycpy (tmp_app.txt); notify_app->txt = strdup (tmp_app.txt);
notify_app->state = tmp_app.state; notify_app->state = tmp_app.state;
} }
else else
@ -339,7 +338,7 @@ notify_check_added (char *mesg, long start, char state)
{ {
notify_app->got_app = 1; notify_app->got_app = 1;
notify_app->time = start; notify_app->time = start;
notify_app->txt = mycpy (mesg); notify_app->txt = strdup (mesg);
notify_app->state = state; notify_app->state = state;
} }
pthread_mutex_unlock (&notify_app->mutex); pthread_mutex_unlock (&notify_app->mutex);
@ -378,7 +377,7 @@ notify_check_repeated (recur_apoint_llist_node_t *i)
{ {
notify_app->got_app = 1; notify_app->got_app = 1;
notify_app->time = real_app_time; notify_app->time = real_app_time;
notify_app->txt = mycpy (i->mesg); notify_app->txt = strdup (i->mesg);
notify_app->state = i->state; notify_app->state = i->state;
} }
pthread_mutex_unlock (&notify_app->mutex); pthread_mutex_unlock (&notify_app->mutex);

View File

@ -1,4 +1,4 @@
/* $calcurse: recur.c,v 1.41 2008/12/08 19:17:07 culot Exp $ */ /* $calcurse: recur.c,v 1.42 2008/12/12 20:44:50 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -694,7 +694,7 @@ recur_repeat_item (conf_t *conf)
} }
while ((ch != 'D') && (ch != 'W') && (ch != 'M') while ((ch != 'D') && (ch != 'W') && (ch != 'M')
&& (ch != 'Y') && (ch != KEY_GENERIC_CANCEL)) && (ch != 'Y') && (ch != ESCAPE))
{ {
status_mesg (mesg_type_1, mesg_type_2); status_mesg (mesg_type_1, mesg_type_2);
ch = wgetch (win[STA].p); ch = wgetch (win[STA].p);
@ -861,7 +861,7 @@ recur_apoint_check_next (struct notify_app_s *app, long start, long day)
if (real_recur_start_time > start) if (real_recur_start_time > start)
{ {
app->time = real_recur_start_time; app->time = real_recur_start_time;
app->txt = mycpy (i->mesg); app->txt = strdup (i->mesg);
app->state = i->state; app->state = i->state;
app->got_app = 1; app->got_app = 1;
} }

View File

@ -1,4 +1,4 @@
/* $calcurse: todo.c,v 1.26 2008/12/08 19:17:07 culot Exp $ */ /* $calcurse: todo.c,v 1.27 2008/12/12 20:44:50 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -190,8 +190,7 @@ todo_delete_note_bynum (unsigned num)
if (n == num) if (n == num)
{ {
if (i->note == NULL) if (i->note == NULL)
ierror (_("FATAL ERROR in todo_delete_note_bynum: " EXIT (_("no note attached"));
"no note attached\n"), IERROR_FATAL);
erase_note (&i->note, ERASE_FORCE_ONLY_NOTE); erase_note (&i->note, ERASE_FORCE_ONLY_NOTE);
return; return;
} }
@ -199,9 +198,7 @@ todo_delete_note_bynum (unsigned num)
n++; n++;
} }
/* NOTREACHED */ /* NOTREACHED */
ierror (_("FATAL ERROR in todo_delete_note_bynum: no such todo\n"), EXIT (_("no such todo"));
IERROR_FATAL);
exit (EXIT_FAILURE);
} }
/* Delete an item from the todo linked list. */ /* Delete an item from the todo linked list. */
@ -228,9 +225,7 @@ todo_delete_bynum (unsigned num, erase_flag_e flag)
n++; n++;
} }
/* NOTREACHED */ /* NOTREACHED */
ierror (_("FATAL ERROR in todo_delete_bynum: no such todo\n"), EXIT (_("no such todo"));
IERROR_FATAL);
exit (EXIT_FAILURE);
} }
/* Delete an item from the ToDo list. */ /* Delete an item from the ToDo list. */
@ -326,8 +321,8 @@ todo_get_position (struct todo_s *i)
} }
else else
{ {
fputs (_("FATAL ERROR in todo_get_position: todo not found\n"), stderr); EXIT (_("todo not found"));
exit (EXIT_FAILURE); return -1; /* avoid compiler warnings */
} }
} }
@ -348,17 +343,17 @@ todo_chg_priority (int action)
strncpy (backup_note, backup->note, NOTESIZ + 1); strncpy (backup_note, backup->note, NOTESIZ + 1);
else else
backup_note[0] = '\0'; backup_note[0] = '\0';
if (action == KEY_RAISE_PRIORITY) switch (action)
{ {
case KEY_RAISE_PRIORITY:
(backup_id > 1) ? backup_id-- : do_chg--; (backup_id > 1) ? backup_id-- : do_chg--;
} break;
else if (action == KEY_LOWER_PRIORITY) case KEY_LOWER_PRIORITY:
{
(backup_id < 9) ? backup_id++ : do_chg--; (backup_id < 9) ? backup_id++ : do_chg--;
} break;
else default:
{ /* NOTREACHED */ EXIT (_("no such action"));
fputs (_("FATAL ERROR in todo_chg_priority: no such action\n"), stderr); /* NOTREACHED */
} }
if (do_chg) if (do_chg)
{ {

View File

@ -1,4 +1,4 @@
/* $calcurse: utils.c,v 1.56 2008/12/08 19:17:07 culot Exp $ */ /* $calcurse: utils.c,v 1.57 2008/12/12 20:44:50 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -62,64 +62,27 @@ exit_calcurse (int status)
/* Function to exit on internal error. */ /* Function to exit on internal error. */
void void
ierror (const char *errmsg, ierror_sev_e sev) fatalbox (const char *errmsg)
{ {
WINDOW *errwin; WINDOW *errwin;
char *label = _("INTERNAL ERROR"); char *label = _("/!\\ INTERNAL ERROR /!\\");
char *exitmsg = _("calcurse will now exit..."); char *reportmsg = _("Please report the following bug:");
char *reportmsg = _("Please report the following bug:"); const int WINROW = 10;
const int winrow = 10; const int WINCOL = col - 2;
const int wincol = col - 2; const int MSGLEN = WINCOL - 2;
const int msglen = wincol - 2; char msg[MSGLEN];
char msg[msglen];
strncpy (msg, errmsg, msglen); 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);
wins_show (errwin, label); wins_show (errwin, label);
if (sev == IERROR_FATAL) mvwprintw (errwin, 3, 1, reportmsg);
mvwprintw (errwin, 3, 1, reportmsg); mvwprintw (errwin, 5, (WINCOL - strlen (msg)) / 2, "%s", msg);
mvwprintw (errwin, 5, (wincol - strlen (msg)) / 2, "%s", msg);
if (sev == IERROR_FATAL)
mvwprintw (errwin, winrow - 2, wincol - strlen (exitmsg) - 1, "%s",
exitmsg);
custom_remove_attr (errwin, ATTR_HIGHEST); custom_remove_attr (errwin, ATTR_HIGHEST);
wrefresh (errwin); wrefresh (errwin);
(void)wgetch (errwin); (void)wgetch (errwin);
if (sev == IERROR_FATAL) delwin (errwin);
exit_calcurse (EXIT_FAILURE);
}
/* Function to handle an assertion failure. */
void
aerror (const char *file, int line, const char *assertion)
{
char errmsg[BUFSIZ];
snprintf (errmsg, BUFSIZ,
"assert \"%s\" failed: file \"%s\", line %d", assertion, file,
line);
ierror (errmsg, IERROR_FATAL);
}
void
warnbox (const char *msg)
{
const int WINCOL = col - 2;
const int WINROW = 10;
const int MSGLEN = WINCOL - 2;
WINDOW *warnwin;
char displmsg[MSGLEN];
if (msg == NULL)
return;
strncpy (displmsg, msg, MSGLEN);
warnwin = popup (WINROW, WINCOL, (row - WINROW) / 2, (col - WINCOL) / 2,
"/!\\", displmsg, 1);
wrefresh (warnwin);
(void)wgetch (warnwin);
delwin (warnwin);
doupdate (); doupdate ();
} }
@ -406,14 +369,9 @@ updatestring (WINDOW *win, char **str, int x, int y)
if (!escape) if (!escape)
{ {
len = strlen (newstr) + 1; len = strlen (newstr) + 1;
if ((*str = (char *) realloc (*str, len)) == NULL) *str = (char *) realloc (*str, len);
{ EXIT_IF (*str == 0, _("out of memory"));
/* NOTREACHED */ (void) memcpy (*str, newstr, len);
ierror (_("FATAL ERROR in updatestring: out of memory"),
IERROR_FATAL);
}
else
(void) memcpy (*str, newstr, len);
} }
free (newstr); free (newstr);
return (escape); return (escape);
@ -628,7 +586,7 @@ update_time_in_date (long date, unsigned hr, unsigned mn)
lt->tm_hour = hr; lt->tm_hour = hr;
lt->tm_min = mn; lt->tm_min = mn;
new_date = mktime (lt); new_date = mktime (lt);
ASSERT (new_date != -1); EXIT_IF (new_date == -1, _("error in mktime"));
return (new_date); return (new_date);
} }
@ -773,7 +731,6 @@ void
other_status_page (int panel) other_status_page (int panel)
{ {
int nb_item = 0, max_page; int nb_item = 0, max_page;
char *error = _("FATAL ERROR in other_status_page: unknown panel\n");
switch (panel) switch (panel)
{ {
@ -787,7 +744,8 @@ other_status_page (int panel)
nb_item = NB_TOD_CMDS; nb_item = NB_TOD_CMDS;
break; break;
default: default:
ierror (error, IERROR_FATAL); EXIT (_("unknown panel"));
/* NOTREACHED */
} }
max_page = ceil (nb_item / (2 * CMDS_PER_LINE + 1)) + 1; max_page = ceil (nb_item / (2 * CMDS_PER_LINE + 1)) + 1;
if (status_page < max_page) if (status_page < max_page)
@ -825,34 +783,18 @@ now (void)
return (current_time); return (current_time);
} }
/* Copy a string */
char *
mycpy (const char *src)
{
char *string = malloc (strlen (src) + 1);
if (string != NULL)
return (strncpy (string, src, strlen (src) + 1));
else
return (NULL);
}
long long
mystrtol (const char *str) mystrtol (const char *str)
{ {
char *ep; char *ep;
long lval; long lval;
const char *not_a_number =
_("FATAL ERROR in mystrtol: could not convert string");
const char *out_of_range =
_("FATAL ERROR in mystrtol: number is out of range");
errno = 0; errno = 0;
lval = strtol (str, &ep, 10); lval = strtol (str, &ep, 10);
if (str[0] == '\0' || *ep != '\0') if (str[0] == '\0' || *ep != '\0')
ierror (not_a_number, IERROR_FATAL); EXIT (_("could not convert string"));
if (errno == ERANGE && (lval == LONG_MAX || lval == LONG_MIN)) if (errno == ERANGE && (lval == LONG_MAX || lval == LONG_MIN))
ierror (out_of_range, IERROR_FATAL); EXIT (_("out of range"));
return (lval); return (lval);
} }
@ -875,10 +817,8 @@ print_bool_option_incolor (WINDOW *win, bool option, int pos_y, int pos_x)
strncpy (option_value, _("no"), BUFSIZ); strncpy (option_value, _("no"), BUFSIZ);
} }
else else
{ EXIT (_("option not defined"));
ierror (_("option not defined - Problem in print_option_incolor()"),
IERROR_FATAL);
}
custom_apply_attr (win, color); custom_apply_attr (win, color);
mvwprintw (win, pos_y, pos_x, "%s", option_value); mvwprintw (win, pos_y, pos_x, "%s", option_value);
custom_remove_attr (win, color); custom_remove_attr (win, color);
@ -913,9 +853,8 @@ new_tempfile (const char *prefix, int trailing_len)
unlink (fullname); unlink (fullname);
close (fd); close (fd);
} }
ierror (_("FATAL ERROR: temporary file could not be created!"), ERROR_MSG (_("temporary file could not be created"));
IERROR_WARN); return (char *)0;
return (NULL);
} }
fclose (file); fclose (file);
@ -927,7 +866,6 @@ void
erase_note (char **note, erase_flag_e flag) erase_note (char **note, erase_flag_e flag)
{ {
char fullname[BUFSIZ]; char fullname[BUFSIZ];
char *errmsg = _("FATAL ERROR in erase_note: could not remove note\n");
if (*note == NULL) if (*note == NULL)
return; return;
@ -935,7 +873,7 @@ erase_note (char **note, erase_flag_e flag)
{ {
snprintf (fullname, BUFSIZ, "%s%s", path_notes, *note); snprintf (fullname, BUFSIZ, "%s%s", path_notes, *note);
if (unlink (fullname) != 0) if (unlink (fullname) != 0)
ierror (errmsg, IERROR_FATAL); EXIT (_("could not remove note"));
} }
free (*note); free (*note);
*note = NULL; *note = NULL;

View File

@ -1,4 +1,4 @@
/* $calcurse: utils.h,v 1.39 2008/11/23 20:38:56 culot Exp $ */ /* $calcurse: utils.h,v 1.40 2008/12/12 20:44:50 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -38,13 +38,15 @@
#define STRING_BUILD(str) {str, sizeof (str) - 1} #define STRING_BUILD(str) {str, sizeof (str) - 1}
#define ERROR_MSG(...) do { \ #define ERROR_MSG(...) do { \
char msg[BUFSIZ]; \ char msg[BUFSIZ]; \
int len; \
\ \
snprintf (msg, BUFSIZ, __VA_ARGS__); \ len = snprintf (msg, BUFSIZ, "%s: %d: ", __FILE__, __LINE__); \
if (ui_mode == UI_CURSES) \ snprintf (msg + len, BUFSIZ - len, __VA_ARGS__); \
warnbox (msg); \ if (ui_mode == UI_CURSES) \
else \ fatalbox (msg); \
fprintf (stderr, "%s\n", msg); \ else \
fprintf (stderr, "%s\n", msg); \
} while (0) } while (0)
#define EXIT(...) do { \ #define EXIT(...) do { \
@ -56,34 +58,24 @@
} while (0) } while (0)
#define EXIT_IF(cond, ...) do { \ #define EXIT_IF(cond, ...) do { \
if ((cond)) \ if ((cond)) \
{ \ EXIT(__VA_ARGS__); \
ERROR_MSG(__VA_ARGS__); \
if (ui_mode == UI_CURSES) \
exit_calcurse (EXIT_FAILURE); \
else \
exit (EXIT_FAILURE); \
} \
} while (0) } while (0)
#define RETURN_IF(cond, ...) do { \ #define RETURN_IF(cond, ...) do { \
if ((cond)) \ if ((cond)) \
{ \ { \
ERROR_MSG(__VA_ARGS__); \ ERROR_MSG(__VA_ARGS__); \
return; \ return; \
} \ } \
} while (0) } while (0)
#define RETVAL_IF(cond, val, ...) do { \ #define RETVAL_IF(cond, val, ...) do { \
if ((cond)) \ if ((cond)) \
{ \ { \
ERROR_MSG(__VA_ARGS__); \ ERROR_MSG(__VA_ARGS__); \
return (val); \ return (val); \
} \ } \
} while (0)
#define ASSERT(e) do { \
((e) ? (void)0 : aerror(__FILE__, __LINE__, #e)); \
} while (0) } while (0)
#define GETSTRING_VALID 0 /* value returned by getstring() if text is valid */ #define GETSTRING_VALID 0 /* value returned by getstring() if text is valid */
@ -95,13 +87,6 @@ typedef struct {
const int len; const int len;
} string_t; } string_t;
typedef enum
{
IERROR_FATAL,
IERROR_WARN
}
ierror_sev_e;
typedef enum typedef enum
{ {
ERASE_DONT_FORCE, ERASE_DONT_FORCE,
@ -112,9 +97,7 @@ typedef enum
erase_flag_e; erase_flag_e;
void exit_calcurse (int); void exit_calcurse (int);
void ierror (const char *, ierror_sev_e); void fatalbox (const char *);
void aerror (const char *, int, const char *);
void warnbox (const char *);
void status_mesg (char *, char *); void status_mesg (char *, char *);
void erase_status_bar (void); void erase_status_bar (void);
void erase_window_part (WINDOW *, int, int, int, int); void erase_window_part (WINDOW *, int, int, int, int);
@ -139,7 +122,6 @@ void reset_status_page (void);
void other_status_page (int); void other_status_page (int);
long get_today (void); long get_today (void);
long now (void); long now (void);
char *mycpy (const char *);
long mystrtol (const char *); long mystrtol (const char *);
void print_bool_option_incolor (WINDOW *, bool, int, int); void print_bool_option_incolor (WINDOW *, bool, int, int);
char *new_tempfile (const char *, int); char *new_tempfile (const char *, int);

View File

@ -1,4 +1,4 @@
/* $calcurse: wins.c,v 1.18 2008/11/23 20:38:56 culot Exp $ */ /* $calcurse: wins.c,v 1.19 2008/12/12 20:44:50 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -128,7 +128,7 @@ wins_init (void)
void void
wins_scrollwin_init (scrollwin_t *sw) wins_scrollwin_init (scrollwin_t *sw)
{ {
ASSERT (sw != NULL); EXIT_IF (sw == 0, "null pointer");
sw->win.p = newwin (sw->win.h, sw->win.w, sw->win.y, sw->win.x); sw->win.p = newwin (sw->win.h, sw->win.w, sw->win.y, sw->win.x);
sw->pad.p = newpad (sw->pad.h, sw->pad.w); sw->pad.p = newpad (sw->pad.h, sw->pad.w);
sw->first_visible_line = 0; sw->first_visible_line = 0;
@ -139,7 +139,7 @@ wins_scrollwin_init (scrollwin_t *sw)
void void
wins_scrollwin_delete (scrollwin_t *sw) wins_scrollwin_delete (scrollwin_t *sw)
{ {
ASSERT (sw != NULL); EXIT_IF (sw == 0, "null pointer");
delwin(sw->win.p); delwin(sw->win.p);
delwin(sw->pad.p); delwin(sw->pad.p);
} }
@ -403,22 +403,18 @@ wins_update (void)
border_nocolor (win[APP].p); border_nocolor (win[APP].p);
border_nocolor (win[TOD].p); border_nocolor (win[TOD].p);
break; break;
case APP: case APP:
border_color (win[APP].p); border_color (win[APP].p);
border_nocolor (win[CAL].p); border_nocolor (win[CAL].p);
border_nocolor (win[TOD].p); border_nocolor (win[TOD].p);
break; break;
case TOD: case TOD:
border_color (win[TOD].p); border_color (win[TOD].p);
border_nocolor (win[APP].p); border_nocolor (win[APP].p);
border_nocolor (win[CAL].p); border_nocolor (win[CAL].p);
break; break;
default: default:
ierror (_("FATAL ERROR in wins_update: no window selected\n"), EXIT (_("no window selected"));
IERROR_FATAL);
/* NOTREACHED */ /* NOTREACHED */
} }