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

Display Error messages. More...

Functions

void abend (int ec, char *s)
 Abnormal program termination.
bool action_disposition (char *title, char *action_str)
 Display a simple action disposition message window or print to stderr.
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 nf_error (int ec, char *s)
 Display error message and wait for key press.
int Perror (char *emsg_str)
 Display a simple error message window or print to stderr.
int wait_continue (WINDOW *wait_win, Chyron *chyron, int remaining)
 Update the waiting message with remaining time and check for user input.
bool wait_destroy (Chyron *chyron)
 Destroy the waiting message window and chyron.
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 waitpid_with_timeout (pid_t pid, int timeout)
 Wait for a process to finish with a timeout and optional user cancellation.

Detailed Description

Display Error messages.

Function Documentation

◆ abend()

void abend ( int ec,
char * s )

Abnormal program termination.

abend

Parameters
ecExit code
sError message

Definition at line 1588 of file dwin.c.

1588 {
1591 sig_dfl_mode();
1592 fprintf(stderr, "\n\nABEND: %s (code: %d)\n", s, ec);
1593 exit(EXIT_FAILURE);
1594}
void destroy_curses()
Gracefully shut down NCurses and restore terminal settings.
Definition dwin.c:540
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(), box2_new(), box_new(), display_error(), form_parse_desc(), init_menu_files(), init_pick(), init_view_full_screen(), mapp_initialization(), 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:

◆ action_disposition()

bool action_disposition ( char * title,
char * action_str )

Display a simple action disposition message window or print to stderr.

action_disposition

Parameters
titleWindow title
action_strAction description string
Returns
true if successful

Definition at line 1286 of file dwin.c.

1286 {
1287 int len;
1288 int line, col;
1289 WINDOW *action_disposition_win;
1290
1291 if (!f_curses_open) {
1292 fprintf(stderr, "\n%s\n", title);
1293 fprintf(stderr, "%s\n", action_str);
1294 return true;
1295 }
1296 Chyron *chyron = new_chyron();
1297 set_chyron_key(chyron, 10, "F10 Continue", KEY_F(10));
1298 compile_chyron(chyron);
1299 len = max(strlen(title), strlen(action_str));
1300 col = (COLS - len - 4) / 2;
1301 line = (LINES - 4) / 2;
1302 if (box_new(2, len + 2, line, col, title, true)) {
1303 ssnprintf(em0, MAXLEN - 1, "box_new(%d, %d, %d, %d, %s) failed", 4,
1304 line, line, col, title);
1305 Perror(em0);
1306 }
1307 action_disposition_win = win_win[win_ptr];
1308 mvwaddstr(action_disposition_win, 0, 1, action_str);
1309 display_chyron(action_disposition_win, chyron, 1, 0);
1310 wmove(action_disposition_win, 1, chyron->l);
1311 cmd_key = xwgetch(action_disposition_win, chyron, 1);
1312 win_del();
1313 destroy_chyron(chyron);
1314 return true;
1315}
bool f_curses_open
Definition sig.c:33
#define max(a, b)
max macro evaluates two expressions, returning greatest result.
Definition cm.h:49
#define MAXLEN
Definition curskeys.c:15
unsigned int cmd_key
Definition dwin.c:126
WINDOW * win_win[MAXWIN]
Definition dwin.c:122
int win_ptr
Definition dwin.c:130
char em0[MAXLEN]
Definition dwin.c:141
int xwgetch(WINDOW *, Chyron *, int)
Wrapper for wgetch that handles signals, mouse events, checks for clicks on the chyron line,...
Definition dwin.c:1651
int box_new(int, int, int, int, char *, bool)
Create a new window with optional box and title.
Definition dwin.c:745
WINDOW * win_del()
Delete the current window and its associated box window.
Definition dwin.c:893
int Perror(char *)
Display a simple error message window or print to stderr.
Definition dwin.c:1162
void set_chyron_key(Chyron *, int, char *, int)
Set chyron key with default color pair (cp_nt_rev).
Definition dwin.c:1411
void display_chyron(WINDOW *win, Chyron *chyron, int line, int col)
Display chyron on window.
Definition dwin.c:1476
Chyron * destroy_chyron(Chyron *chyron)
Destroy Chyron structure.
Definition dwin.c:1352
void compile_chyron(Chyron *)
construct the chyron string from the chyron structure
Definition dwin.c:1436
Chyron * new_chyron()
Create and initialize Chyron structure.
Definition dwin.c:1336
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
Definition futil.c:311
Definition cm.h:276
int l
Definition cm.h:280

References box_new(), cmd_key, compile_chyron(), destroy_chyron(), display_chyron(), em0, f_curses_open, Chyron::l, new_chyron(), Perror(), set_chyron_key(), ssnprintf(), win_del(), win_ptr, win_win, and xwgetch().

Here is the call graph for this function:

◆ answer_yn()

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

Accept a single letter answer.

answer_yn

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 1041 of file dwin.c.

1041 {
1042 char title[MAXLEN];
1043 int line, pos, em_l, em0_l, em1_l, em2_l, em3_l;
1044 WINDOW *error_win;
1045
1046 if (!f_curses_open) {
1047 fprintf(stderr, "\n\n%s\n%s\n%s\n%s\n\n", em0, em1, em2, em3);
1048 return 1;
1049 }
1050
1051 Chyron *chyron = new_chyron();
1052 set_chyron_key(chyron, 1, "F1 Help", KEY_F(1));
1053 set_chyron_key(chyron, 2, "N - No", 'n');
1054 set_chyron_key(chyron, 3, "Y - Yes", 'y');
1055 compile_chyron(chyron);
1056
1057 em0_l = strnz(em0, COLS - 4);
1058 em1_l = strnz(em1, COLS - 4);
1059 em2_l = strnz(em2, COLS - 4);
1060 em3_l = strnz(em1, COLS - 4);
1061 em_l = max(em0_l, em1_l);
1062 em_l = max(em_l, em2_l);
1063 em_l = max(em_l, em3_l);
1064 em_l = max(em_l, chyron->l);
1065 em_l = min(em_l, COLS - 4);
1066
1067 pos = ((COLS - em_l) - 4) / 2;
1068 line = (LINES - 6) / 2;
1069 strnz__cpy(title, "Notification", MAXLEN - 1);
1070 if (box_new(5, em_l + 2, line, pos, title, true)) {
1071 ssnprintf(title, MAXLEN - 1, "box_new(%d, %d, %d, %d, %s) failed", 5,
1072 em_l + 2, line, pos, title);
1073 destroy_chyron(chyron);
1074 abend(-1, title);
1075 }
1076 error_win = win_win[win_ptr];
1077 mvwaddstr(error_win, 0, 1, em0);
1078 mvwaddstr(error_win, 1, 1, em1);
1079 mvwaddstr(error_win, 2, 1, em2);
1080 mvwaddstr(error_win, 3, 1, em3);
1081 display_chyron(error_win, chyron, 4, chyron->l + 1);
1082 do {
1083 curs_set(1);
1084 cmd_key = xwgetch(error_win, chyron, -1);
1085 curs_set(0);
1086 if (cmd_key == KEY_F(1) || cmd_key == 'N' || cmd_key == 'n' ||
1087 cmd_key == 'Y' || cmd_key == 'y')
1088 break;
1089 } while (1);
1090 win_del();
1091 destroy_chyron(chyron);
1092 return (cmd_key);
1093}
#define min(x, y)
min macro evaluates two expressions, returning least result
Definition cm.h:56
char em1[MAXLEN]
Definition dwin.c:142
char em3[MAXLEN]
Definition dwin.c:144
char em2[MAXLEN]
Definition dwin.c:143
void abend(int, char *)
Abnormal program termination.
Definition dwin.c:1588
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
Definition futil.c:435
size_t strnz(char *, size_t)
terminates string at New Line, Carriage Return, or max_len
Definition futil.c:506

References abend(), box_new(), 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_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.

display_error

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 1102 of file dwin.c.

1102 {
1103 char title[MAXLEN];
1104 int line, pos, em_l, em0_l, em1_l, em2_l, em3_l;
1105 WINDOW *error_win;
1106
1107 if (!f_curses_open) {
1108 fprintf(stderr, "\n\n%s\n", em0);
1109 fprintf(stderr, "%s\n", em1);
1110 fprintf(stderr, "%s\n", em2);
1111 fprintf(stderr, "%s\n\n", em3);
1112 return 1;
1113 }
1114
1115 Chyron *chyron = new_chyron();
1116 set_chyron_key(chyron, 1, "F1 Help", KEY_F(1));
1117 set_chyron_key(chyron, 9, "F9 Cancel", KEY_F(9));
1118 set_chyron_key(chyron, 10, "F10 Continue", KEY_F(10));
1119 compile_chyron(chyron);
1120
1121 em0_l = strnz(em0, COLS - 4);
1122 em1_l = strnz(em1, COLS - 4);
1123 em2_l = strnz(em2, COLS - 4);
1124 em3_l = strnz(em1, COLS - 4);
1125 em_l = max(em0_l, em1_l);
1126 em_l = max(em_l, em2_l);
1127 em_l = max(em_l, em3_l);
1128 em_l = max(em_l, chyron->l);
1129 em_l = min(em_l, COLS - 4);
1130
1131 pos = ((COLS - em_l) - 4) / 2;
1132 line = (LINES - 6) / 2;
1133 strnz__cpy(title, "Notification", MAXLEN - 1);
1134 if (box_new(5, em_l + 2, line, pos, title, true)) {
1135 ssnprintf(title, MAXLEN - 1, "box_new(%d, %d, %d, %d, %s) failed", 5,
1136 em_l + 2, line, pos, title);
1137 destroy_chyron(chyron);
1138 abend(-1, title);
1139 }
1140 error_win = win_win[win_ptr];
1141 mvwaddstr(error_win, 0, 1, em0);
1142 mvwaddstr(error_win, 1, 1, em1);
1143 mvwaddstr(error_win, 2, 1, em2);
1144 mvwaddstr(error_win, 3, 1, em3);
1145 display_chyron(error_win, chyron, 4, chyron->l + 1);
1146 do {
1147 cmd_key = xwgetch(error_win, chyron, -1);
1148 if (cmd_key == KEY_F(9) || cmd_key == KEY_F(10) || cmd_key == 'q' ||
1149 cmd_key == 'Q')
1150 break;
1151 } while (1);
1152 win_del();
1153 destroy_chyron(chyron);
1154 return (cmd_key);
1155}

References abend(), box_new(), 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_ptr, win_win, and xwgetch().

Referenced by dxwgetch(), 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(), 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.

nf_error

Parameters
ecError code
sError message

Definition at line 1576 of file dwin.c.

1576 {
1577 fprintf(stderr, "ERROR: %s code: %d\n", s, ec);
1578 fprintf(stderr, "Press a key to continue");
1579 di_getch();
1580 fprintf(stderr, "\n");
1581 return ec;
1582}
char di_getch()
get single character from terminal in raw mode
Definition scriou.c:148

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.

Perror

Parameters
emsg_strError message string
Returns
Key code of user command

Definition at line 1162 of file dwin.c.

1162 {
1163 char emsg[80];
1164 int emsg_max_len = 80;
1165 unsigned cmd_key;
1166 WINDOW *error_win;
1167 int len, line, pos;
1168 char title[MAXLEN];
1169 bool f_xwgetch = true;
1170 if (emsg_str[0] == '␛' && emsg_str[1] == 'w') {
1171 emsg_str += 2;
1172 f_xwgetch = false;
1173 }
1174 strnz__cpy(emsg, emsg_str, emsg_max_len - 1);
1175 if (!f_curses_open) {
1176 fprintf(stderr, "\n%s\n", emsg);
1177 return 1;
1178 }
1179 Chyron *chyron = new_chyron();
1180 set_chyron_key(chyron, 1, "F1 Help", KEY_F(1));
1181 set_chyron_key(chyron, 9, "F9 Cancel", KEY_F(9));
1182 set_chyron_key(chyron, 10, "F10 Continue", KEY_F(10));
1183 compile_chyron(chyron);
1184 len = max(strlen(title), strlen(emsg));
1185 len = max(len, chyron->l);
1186 len = max(len, 40);
1187 pos = (COLS - len - 4) / 2;
1188 line = (LINES - 4) / 2;
1189 strnz__cpy(title, "Notification", MAXLEN - 1);
1190 if (box_new(2, len + 2, line, pos, title, true)) {
1191 ssnprintf(title, MAXLEN - 1, "box_new(%d, %d, %d, %d, %s, %b) failed",
1192 4, line, line, pos, title);
1193 destroy_chyron(chyron);
1194 abend(-1, title);
1195 }
1196 error_win = win_win[win_ptr];
1197 mvwaddstr(error_win, 0, 1, emsg);
1198 display_chyron(error_win, chyron, 1, chyron->l + 1);
1199 if (f_xwgetch) {
1200 curs_set(1);
1201 cmd_key = xwgetch(error_win, chyron, -1);
1202 curs_set(0);
1203 win_del();
1204 } else {
1205 cmd_key = KEY_F(10);
1206 }
1207 destroy_chyron(chyron);
1208 return (cmd_key);
1209}

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

Referenced by action_disposition(), display_form(), exec_objects(), field_editor(), fork_exec(), form_engine(), form_exec_receiver(), form_fmt_field(), form_process(), form_validate_field(), go_to_mark(), go_to_percent(), increment_ln(), init_form(), init_pick(), initialize_line_table(), menu_engine(), new_init(), new_pick(), open_pick_win(), pad_refresh(), parse_menu_description(), popup_ckeys(), search(), view_cmd_processor(), view_init_input(), 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.

wait_continue

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 1271 of file dwin.c.

1271 {
1272 char time_str[10];
1273 ssnprintf(time_str, 9, "%-4d", remaining);
1274 mvwaddstr(wait_win, 0, 21, time_str);
1275 display_chyron(wait_win, chyron, 1, 0);
1276 wmove(wait_win, 1, chyron->l);
1277 cmd_key = xwgetch(wait_win, chyron, 1);
1278 return cmd_key;
1279}

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.

wait_destroy

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

Definition at line 1258 of file dwin.c.

1258 {
1259 win_del();
1260 destroy_chyron(chyron);
1261 return true;
1262}

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.

wait_mk_chyron

Returns
Pointer to the chyron struct

Definition at line 1214 of file dwin.c.

1214 {
1215 Chyron *chyron = new_chyron();
1216 set_chyron_key(chyron, 9, "F9 Cancel", KEY_F(9));
1217 compile_chyron(chyron);
1218 return chyron;
1219}

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.

wait_mk_win

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

Definition at line 1226 of file dwin.c.

1226 {
1227 char wm1[] = "Seconds remaining:";
1228 int len;
1229 int line, col;
1230 WINDOW *wait_win;
1231
1232 if (!f_curses_open) {
1233 fprintf(stderr, "\n%s\n", title);
1234 fprintf(stderr, "%s\n", wm1);
1235 return NULL;
1236 }
1237 len = max(strlen(title), strlen(wm1));
1238 len = max(len, chyron->l);
1239 len = max(len, 40);
1240 col = (COLS - len - 4) / 2;
1241 line = (LINES - 4) / 2;
1242 if (box_new(2, len + 2, line, col, title, true)) {
1243 ssnprintf(title, MAXLEN - 1, "box_new(%d, %d, %d, %d, %s) failed", 4,
1244 line, line, col, title);
1245 abend(-1, title);
1246 }
1247 wait_win = win_win[win_ptr];
1248 mvwaddstr(wait_win, 0, 1, wm1);
1249 display_chyron(wait_win, chyron, 1, 0);
1250 wmove(wait_win, 1, chyron->l);
1251 return wait_win;
1252}

References abend(), box_new(), display_chyron(), f_curses_open, Chyron::l, ssnprintf(), 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:

◆ waitpid_with_timeout()

bool waitpid_with_timeout ( pid_t pid,
int timeout )

Wait for a process to finish with a timeout and optional user cancellation.

waitpid_with_timeout

Parameters
pidProcess ID to wait for
timeoutTime in seconds to wait before timing out
Returns
true if the process finished, false if it timed out or was cancelled

Definition at line 1603 of file dwin.c.

1603 {
1604 int status;
1605 Chyron *wait_chyron;
1606 WINDOW *wait_win;
1607 int remaining = timeout;
1608
1609 waitpid(pid, &status, WNOHANG);
1610 if (WIFEXITED(status) || WIFSIGNALED(status))
1611 return true;
1612 usleep(100000); // Sleep for 200ms */
1613 wait_chyron = wait_mk_chyron();
1614 ssnprintf(em0, MAXLEN - 1, "Waiting for process %d to finish...", pid);
1615 wait_win = wait_mk_win(wait_chyron, em0);
1616 cmd_key = 0;
1617 while (remaining > 0 && cmd_key != KEY_F(9)) {
1618 cmd_key = wait_continue(wait_win, wait_chyron, remaining);
1619 if (cmd_key == KEY_F(9))
1620 break;
1621 remaining--;
1622 waitpid(pid, &status, WNOHANG);
1623 if (WIFEXITED(status) || WIFSIGNALED(status)) {
1624 wait_destroy(wait_chyron);
1625 return true;
1626 }
1627 }
1628 wait_destroy(wait_chyron);
1629 return false;
1630}
bool wait_destroy(Chyron *)
Destroy the waiting message window and chyron.
Definition dwin.c:1258
int wait_continue(WINDOW *, Chyron *, int)
Update the waiting message with remaining time and check for user input.
Definition dwin.c:1271
WINDOW * wait_mk_win(Chyron *, char *)
Display a popup waiting message.
Definition dwin.c:1226
Chyron * wait_mk_chyron()
Create a Chyron struct for the waiting message.
Definition dwin.c:1214

References cmd_key, em0, ssnprintf(), wait_continue(), wait_destroy(), wait_mk_chyron(), and wait_mk_win().

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

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