C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
Error Handling

Display Error messages. More...

Functions

int answer_yn (char *em0, char *em1, char *em2, char *em3)
 Accept a single letter answer.
int display_error (char *em0, char *em1, char *em2, char *em3)
 Display an error message window or print to stderr.
int Perror (char *emsg_str)
 Display a simple error message window or print to stderr.
Chyronwait_mk_chyron ()
 Create a Chyron struct for the waiting message.
WINDOW * wait_mk_win (Chyron *chyron, char *title)
 Display a popup waiting message.
bool wait_destroy (Chyron *chyron)
 Destroy the waiting message window and chyron.
int wait_continue (WINDOW *wait_win, Chyron *chyron, int remaining)
 Update the waiting message with remaining time and check for user input.
int nf_error (int ec, char *s)
 Display error message and wait for key press.
void abend (int ec, char *s)
 Abnormal program termination.

Detailed Description

Display Error messages.

Function Documentation

◆ abend()

void abend ( int ec,
char * s )

Abnormal program termination.

Parameters
ecExit code
sError message

Definition at line 1331 of file dwin.c.

1331 {
1334 sig_dfl_mode();
1335 fprintf(stderr, "\n\nABEND: %s (code: %d)\n", s, ec);
1336 exit(EXIT_FAILURE);
1337}
void destroy_curses()
Gracefully shut down NCurses and restore terminal settings.
Definition dwin.c:738
bool restore_shell_tioctl()
restore_shell_tioctl() - restore shell terminal settings
Definition scriou.c:56
void sig_dfl_mode()
Set signal handlers to default behavior.
Definition sig.c:42

References destroy_curses(), restore_shell_tioctl(), and sig_dfl_mode().

Referenced by answer_yn(), display_error(), form_parse_desc(), init_menu_files(), init_pick(), init_view_full_screen(), mapp_initialization(), menu_cmd_processor(), new_chyron(), new_form(), new_init(), new_menu(), new_pick(), new_view(), open_curses(), parse_menu_description(), Perror(), sig_prog_mode(), signal_handler(), view_init_input(), and wait_mk_win().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ answer_yn()

int answer_yn ( char * em0,
char * em1,
char * em2,
char * em3 )

Accept a single letter answer.

Parameters
em0First error message line
em1Second error message line
em2Third error message line
em3Fourth error message line
Returns
Key code of user command

Definition at line 994 of file dwin.c.

994 {
995 char title[MAXLEN];
996 int line, pos, em_l, em0_l, em1_l, em2_l, em3_l;
997 WINDOW *error_win;
998
999 if (!f_curses_open) {
1000 fprintf(stderr, "\n\n%s\n%s\n%s\n%s\n\n", em0, em1, em2, em3);
1001 return (1);
1002 }
1003
1004 Chyron *chyron = new_chyron();
1005 set_chyron_key(chyron, 1, "F1 Help", KEY_F(1));
1006 set_chyron_key(chyron, 2, "N - No", 'n');
1007 set_chyron_key(chyron, 3, "Y - Yes", 'y');
1008 compile_chyron(chyron);
1009
1010 em0_l = strnz(em0, COLS - 4);
1011 em1_l = strnz(em1, COLS - 4);
1012 em2_l = strnz(em2, COLS - 4);
1013 em3_l = strnz(em1, COLS - 4);
1014 em_l = max(em0_l, em1_l);
1015 em_l = max(em_l, em2_l);
1016 em_l = max(em_l, em3_l);
1017 em_l = max(em_l, chyron->l);
1018 em_l = min(em_l, COLS - 4);
1019
1020 pos = ((COLS - em_l) - 4) / 2;
1021 line = (LINES - 6) / 2;
1022 strnz__cpy(title, "Notification", MAXLEN - 1);
1023 if (win_new(5, em_l + 2, line, pos, title, 0)) {
1024 ssnprintf(title, MAXLEN - 1, "win_new(%d, %d, %d, %d, %s, %b) failed",
1025 5, em_l + 2, line, pos, title, 0);
1026 destroy_chyron(chyron);
1027 abend(-1, title);
1028 }
1029 error_win = win_win[win_ptr];
1030 mvwaddstr(error_win, 0, 1, em0);
1031 mvwaddstr(error_win, 1, 1, em1);
1032 mvwaddstr(error_win, 2, 1, em2);
1033 mvwaddstr(error_win, 3, 1, em3);
1034 display_chyron(error_win, chyron, 4, chyron->l + 1);
1035 do {
1036 curs_set(1);
1037 cmd_key = xwgetch(error_win, chyron, -1);
1038 curs_set(0);
1039 if (cmd_key == KEY_F(1) || cmd_key == 'N' || cmd_key == 'n' ||
1040 cmd_key == 'Y' || cmd_key == 'y')
1041 break;
1042 } while (1);
1043 win_del();
1044 destroy_chyron(chyron);
1045 return (cmd_key);
1046}
bool f_curses_open
Definition sig.c:33
#define min(x, y)
min macro evaluates two expressions, returning least result
Definition cm.h:55
#define max(a, b)
max macro evaluates two expressions, returning greatest result.
Definition cm.h:48
#define MAXLEN
Definition curskeys.c:15
unsigned int cmd_key
Definition dwin.c:117
WINDOW * win_win[MAXWIN]
Definition dwin.c:114
char em1[MAXLEN]
Definition dwin.c:133
void display_chyron(WINDOW *win, Chyron *chyron, int line, int col)
Definition dwin.c:297
int win_ptr
Definition dwin.c:121
char em0[MAXLEN]
Definition dwin.c:132
char em3[MAXLEN]
Definition dwin.c:135
void set_chyron_key(Chyron *, int, char *, int)
Definition dwin.c:245
char em2[MAXLEN]
Definition dwin.c:134
int xwgetch(WINDOW *, Chyron *, int)
Wrapper for wgetch that handles signals, mouse events, checks for clicks on the chyron line,...
Definition dwin.c:1359
int win_new(int, int, int, int, char *, int)
Create a new window with optional box and title.
Definition dwin.c:783
WINDOW * win_del()
Delete the current window and its associated box window.
Definition dwin.c:902
Chyron * destroy_chyron(Chyron *chyron)
Destroy Chyron structure.
Definition dwin.c:198
void compile_chyron(Chyron *)
construct the chyron string from the chyron structure
Definition dwin.c:268
Chyron * new_chyron()
Create and initialize Chyron structure.
Definition dwin.c:183
void abend(int, char *)
Abnormal program termination.
Definition dwin.c:1331
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
Definition futil.c:269
size_t strnz(char *, size_t)
terminates string at New Line, Carriage Return, or max_len
Definition futil.c:340
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
Definition futil.c:147
Definition cm.h:240
int l
Definition cm.h:244

References abend(), cmd_key, compile_chyron(), destroy_chyron(), display_chyron(), f_curses_open, Chyron::l, new_chyron(), set_chyron_key(), ssnprintf(), strnz(), strnz__cpy(), win_del(), win_new(), win_ptr, win_win, and xwgetch().

Referenced by write_view_buffer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ display_error()

int display_error ( char * em0,
char * em1,
char * em2,
char * em3 )

Display an error message window or print to stderr.

Parameters
em0First error message line
em1Second error message line
em2Third error message line
em3Fourth error message line
Returns
Key code of user command

Definition at line 1054 of file dwin.c.

1054 {
1055 char title[MAXLEN];
1056 int line, pos, em_l, em0_l, em1_l, em2_l, em3_l;
1057 WINDOW *error_win;
1058
1059 if (!f_curses_open) {
1060 fprintf(stderr, "\n\n%s\n%s\n%s\n%s\n\n", em0, em1, em2, em3);
1061 return (1);
1062 }
1063
1064 Chyron *chyron = new_chyron();
1065 set_chyron_key(chyron, 1, "F1 Help", KEY_F(1));
1066 set_chyron_key(chyron, 9, "F9 Cancel", KEY_F(9));
1067 set_chyron_key(chyron, 10, "F10 Continue", KEY_F(10));
1068 compile_chyron(chyron);
1069
1070 em0_l = strnz(em0, COLS - 4);
1071 em1_l = strnz(em1, COLS - 4);
1072 em2_l = strnz(em2, COLS - 4);
1073 em3_l = strnz(em1, COLS - 4);
1074 em_l = max(em0_l, em1_l);
1075 em_l = max(em_l, em2_l);
1076 em_l = max(em_l, em3_l);
1077 em_l = max(em_l, chyron->l);
1078 em_l = min(em_l, COLS - 4);
1079
1080 pos = ((COLS - em_l) - 4) / 2;
1081 line = (LINES - 6) / 2;
1082 strnz__cpy(title, "Notification", MAXLEN - 1);
1083 if (win_new(5, em_l + 2, line, pos, title, 0)) {
1084 ssnprintf(title, MAXLEN - 1, "win_new(%d, %d, %d, %d, %s, %b) failed",
1085 5, em_l + 2, line, pos, title, 0);
1086 destroy_chyron(chyron);
1087 abend(-1, title);
1088 }
1089 error_win = win_win[win_ptr];
1090 mvwaddstr(error_win, 0, 1, em0);
1091 mvwaddstr(error_win, 1, 1, em1);
1092 mvwaddstr(error_win, 2, 1, em2);
1093 mvwaddstr(error_win, 3, 1, em3);
1094 display_chyron(error_win, chyron, 4, chyron->l + 1);
1095 do {
1096 cmd_key = xwgetch(error_win, chyron, -1);
1097 if (cmd_key == KEY_F(9) || cmd_key == KEY_F(10) || cmd_key == 'q' ||
1098 cmd_key == 'Q')
1099 break;
1100 } while (1);
1101 win_del();
1102 destroy_chyron(chyron);
1103 return (cmd_key);
1104}

References abend(), cmd_key, compile_chyron(), destroy_chyron(), display_chyron(), f_curses_open, Chyron::l, new_chyron(), set_chyron_key(), ssnprintf(), strnz(), strnz__cpy(), win_del(), win_new(), win_ptr, win_win, and xwgetch().

Referenced by enter_file_spec(), form_desc_error(), form_parse_desc(), form_process(), form_read_data(), form_write(), get_clr_pair(), init_view_boxwin(), init_view_full_screen(), lf_find(), mk_dir(), new_init(), new_pick(), new_view(), parse_menu_description(), popup_ckeys(), verify_dir(), verify_file(), view_cmd_processor(), view_init_input(), write_view_buffer(), and xwgetch().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nf_error()

int nf_error ( int ec,
char * s )

Display error message and wait for key press.

Parameters
ecError code
sError message

Definition at line 1320 of file dwin.c.

1320 {
1321 fprintf(stderr, "ERROR: %s code: %d\n", s, ec);
1322 fprintf(stderr, "Press a key to continue");
1323 di_getch();
1324 fprintf(stderr, "\n");
1325 return ec;
1326}
char di_getch()
sget single character from terminal in raw mode
Definition scriou.c:139

References di_getch().

Here is the call graph for this function:

◆ Perror()

int Perror ( char * emsg_str)

Display a simple error message window or print to stderr.

Parameters
emsg_strError message string
Returns
Key code of user command

Definition at line 1110 of file dwin.c.

1110 {
1111 char emsg[80];
1112 int emsg_max_len = 80;
1113 unsigned cmd_key;
1114 WINDOW *error_win;
1115 int len, line, pos;
1116 char title[MAXLEN];
1117 bool f_xwgetch = true;
1118 if (emsg_str[0] == '␛' && emsg_str[1] == 'w') {
1119 emsg_str += 2;
1120 f_xwgetch = false;
1121 }
1122 strnz__cpy(emsg, emsg_str, emsg_max_len - 1);
1123 if (!f_curses_open) {
1124 fprintf(stderr, "\n%s\n", emsg);
1125 return (1);
1126 }
1127 Chyron *chyron = new_chyron();
1128 set_chyron_key(chyron, 1, "F1 Help", KEY_F(1));
1129 set_chyron_key(chyron, 9, "F9 Cancel", KEY_F(9));
1130 set_chyron_key(chyron, 10, "F10 Continue", KEY_F(10));
1131 compile_chyron(chyron);
1132 len = max(strlen(title), strlen(emsg));
1133 len = max(len, chyron->l);
1134 len = max(len, 40);
1135 pos = (COLS - len - 4) / 2;
1136 line = (LINES - 4) / 2;
1137 strnz__cpy(title, "Notification", MAXLEN - 1);
1138 if (win_new(2, len + 2, line, pos, title, 0)) {
1139 ssnprintf(title, MAXLEN - 1, "win_new(%d, %d, %d, %d, %s, %b) failed",
1140 4, line, line, pos, title, 0);
1141 destroy_chyron(chyron);
1142 abend(-1, title);
1143 }
1144 error_win = win_win[win_ptr];
1145 mvwaddstr(error_win, 0, 1, emsg);
1146 display_chyron(error_win, chyron, 1, chyron->l + 1);
1147 if (f_xwgetch) {
1148 curs_set(1);
1149 cmd_key = xwgetch(error_win, chyron, -1);
1150 curs_set(0);
1151 win_del();
1152 } else {
1153 cmd_key = KEY_F(10);
1154 }
1155 destroy_chyron(chyron);
1156 return (cmd_key);
1157}

References abend(), compile_chyron(), destroy_chyron(), display_chyron(), f_curses_open, Chyron::l, new_chyron(), set_chyron_key(), ssnprintf(), strnz__cpy(), win_del(), win_new(), win_ptr, win_win, and xwgetch().

Referenced by action_disposition(), exec_objects(), field_editor(), fork_exec(), form_display_screen(), form_engine(), form_fmt_field(), form_process(), form_validate_field(), go_to_mark(), go_to_percent(), increment_ln(), init_form(), init_pick(), initialize_line_table(), lf_process(), menu_engine(), new_init(), new_pick(), open_pick_win(), pad_refresh(), parse_menu_description(), popup_ckeys(), search(), view_cmd_processor(), view_init_input(), waitpid_with_timeout(), and write_config().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wait_continue()

int wait_continue ( WINDOW * wait_win,
Chyron * chyron,
int remaining )

Update the waiting message with remaining time and check for user input.

Parameters
chyronPointer to Chyron struct for displaying key options
wait_winPointer to the waiting message window
remainingTime remaining for the wait in seconds
Returns
true if the wait should continue, false if it should be cancelled

Definition at line 1215 of file dwin.c.

1215 {
1216 char time_str[10];
1217 ssnprintf(time_str, 9, "%-4d", remaining);
1218 mvwaddstr(wait_win, 0, 21, time_str);
1219 display_chyron(wait_win, chyron, 1, 0);
1220 wmove(wait_win, 1, chyron->l);
1221 cmd_key = xwgetch(wait_win, chyron, 1);
1222 return cmd_key;
1223}

References cmd_key, display_chyron(), Chyron::l, ssnprintf(), and xwgetch().

Referenced by init_pick(), view_init_input(), and waitpid_with_timeout().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wait_destroy()

bool wait_destroy ( Chyron * chyron)

Destroy the waiting message window and chyron.

Parameters
chyronPointer to Chyron struct for displaying key options
Returns
true if successful

Definition at line 1203 of file dwin.c.

1203 {
1204 win_del();
1205 destroy_chyron(chyron);
1206 return true;
1207}

References destroy_chyron(), and win_del().

Referenced by init_pick(), view_init_input(), and waitpid_with_timeout().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wait_mk_chyron()

Chyron * wait_mk_chyron ( )

Create a Chyron struct for the waiting message.

Returns
Pointer to the chyron struct

Definition at line 1161 of file dwin.c.

1161 {
1162 Chyron *chyron = new_chyron();
1163 set_chyron_key(chyron, 9, "F9 Cancel", KEY_F(9));
1164 compile_chyron(chyron);
1165 return chyron;
1166}

References compile_chyron(), new_chyron(), and set_chyron_key().

Referenced by init_pick(), view_init_input(), and waitpid_with_timeout().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wait_mk_win()

WINDOW * wait_mk_win ( Chyron * chyron,
char * title )

Display a popup waiting message.

Parameters
chyronPointer to Chyron struct for displaying key options
titlewindow title
Returns
WINDOW * struct

Definition at line 1172 of file dwin.c.

1172 {
1173 char wm1[] = "Seconds remaining:";
1174 int len;
1175 int line, col;
1176 WINDOW *wait_win;
1177
1178 if (!f_curses_open) {
1179 fprintf(stderr, "\n%s\n", title);
1180 fprintf(stderr, "%s\n", wm1);
1181 return NULL;
1182 }
1183 len = max(strlen(title), strlen(wm1));
1184 len = max(len, chyron->l);
1185 len = max(len, 40);
1186 col = (COLS - len - 4) / 2;
1187 line = (LINES - 4) / 2;
1188 if (win_new(2, len + 2, line, col, title, 0)) {
1189 ssnprintf(title, MAXLEN - 1, "win_new(%d, %d, %d, %d, %s, %b) failed",
1190 4, line, line, col, title, 0);
1191 abend(-1, title);
1192 }
1193 wait_win = win_win[win_ptr];
1194 mvwaddstr(wait_win, 0, 1, wm1);
1195 display_chyron(wait_win, chyron, 1, 0);
1196 wmove(wait_win, 1, chyron->l);
1197 return wait_win;
1198}

References abend(), display_chyron(), f_curses_open, Chyron::l, ssnprintf(), win_new(), win_ptr, and win_win.

Referenced by init_pick(), view_init_input(), and waitpid_with_timeout().

Here is the call graph for this function:
Here is the caller graph for this function: