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 *msg0, char *msg1, char *msg2, char *msg3)
 Accept a single letter answer.
int display_error (char *msg0, char *msg1, char *msg2, char *msg3)
 Display an error message window or print to stderr.
WINDOW * message_win (char *msg)
 Display a message in a window or print to stderr if curses is not available.
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 2018 of file dwin.c.

2018 {
2021 sig_dfl_mode();
2022 fprintf(stderr, "\n\nABEND: %s (code: %d)\n", s, ec);
2023 exit(EXIT_FAILURE);
2024}
void destroy_curses()
Gracefully shut down NCurses and restore terminal settings.
Definition dwin.c:670
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(), 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 1651 of file dwin.c.

1651 {
1652 int len;
1653 int line, col;
1654 WINDOW *action_disposition_win;
1655
1656 if (!f_curses_open) {
1657 fprintf(stderr, "\n%s\n", title);
1658 fprintf(stderr, "%s\n", action_str);
1659 return true;
1660 }
1661 Chyron *chyron = new_chyron();
1662 set_chyron_key(chyron, 10, "F10 Continue", KEY_F(10));
1663 compile_chyron(chyron);
1664 len = max(strlen(title), strlen(action_str));
1665 col = (COLS - len - 4) / 2;
1666 line = (LINES - 4) / 2;
1667 if (box_new(2, len + 2, line, col, title)) {
1668 ssnprintf(em0, MAXLEN - 1, "box_new(%d, %d, %d, %d, %s) failed", 4,
1669 line, line, col, title);
1670 Perror(em0);
1671 }
1672 action_disposition_win = win_win[win_ptr];
1673 mvwaddstr(action_disposition_win, 0, 1, action_str);
1674 display_chyron(action_disposition_win, chyron, 1, 0);
1675 wmove(action_disposition_win, 1, chyron->l);
1676 cmd_key = xwgetch(action_disposition_win, chyron, 1);
1677 win_del();
1678 destroy_chyron(chyron);
1679 return true;
1680}
WINDOW * win_win[MAXWIN]
Definition dwin.c:52
bool f_curses_open
Definition sig.c:33
int win_ptr
Definition dwin.c:164
char em0[MAXLEN]
Definition dwin.c:175
#define max(a, b)
max macro evaluates two expressions, returning greatest result.
Definition cm.h:82
#define MAXLEN
Definition curskeys.c:15
unsigned int cmd_key
Definition dwin.c:160
int xwgetch(WINDOW *, Chyron *, int)
Wrapper for wgetch that handles signals, mouse events, checks for clicks on the chyron line,...
Definition dwin.c:2094
void win_del()
Delete the current window and its associated box window.
Definition dwin.c:1179
int box_new(int, int, int, int, char *)
Create a new window with optional box and title.
Definition dwin.c:967
int Perror(char *)
Display a simple error message window or print to stderr.
Definition dwin.c:1526
void set_chyron_key(Chyron *, int, char *, int)
Set chyron key with default color pair (cp_nt_rev).
Definition dwin.c:1783
void display_chyron(WINDOW *win, Chyron *chyron, int line, int col)
Display chyron on window.
Definition dwin.c:1892
Chyron * destroy_chyron(Chyron *chyron)
Destroy Chyron structure.
Definition dwin.c:1722
void compile_chyron(Chyron *)
construct the chyron string from the chyron structure
Definition dwin.c:1848
Chyron * new_chyron()
Create and initialize Chyron structure.
Definition dwin.c:1701
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
Definition futil.c:420
Definition cm.h:344
int l
Definition cm.h:348

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 * msg0,
char * msg1,
char * msg2,
char * msg3 )

Accept a single letter answer.

answer_yn

Parameters
msg0First error message line
msg1Second error message line
msg2Third error message line
msg3Fourth error message line
Returns
Key code of user command

Definition at line 1406 of file dwin.c.

1406 {
1407 char title[MAXLEN];
1408 int line, pos, msg_l, msg0_l, msg1_l, msg2_l, msg3_l;
1409 WINDOW *error_win;
1410
1411 if (!f_curses_open) {
1412 fprintf(stderr, "\n\n%s\n%s\n%s\n%s\n\n", msg0, msg1, msg2, msg3);
1413 return 1;
1414 }
1415
1416 Chyron *chyron = new_chyron();
1417 set_chyron_key(chyron, 1, "F1 Help", KEY_F(1));
1418 set_chyron_key(chyron, 2, "N - No", 'n');
1419 set_chyron_key(chyron, 3, "Y - Yes", 'y');
1420 compile_chyron(chyron);
1421
1422 msg0_l = strnz(msg0, COLS - 4);
1423 msg1_l = strnz(msg1, COLS - 4);
1424 msg2_l = strnz(msg2, COLS - 4);
1425 msg3_l = strnz(msg1, COLS - 4);
1426 msg_l = max(msg0_l, msg1_l);
1427 msg_l = max(msg_l, msg2_l);
1428 msg_l = max(msg_l, msg3_l);
1429 msg_l = max(msg_l, chyron->l);
1430 msg_l = min(msg_l, COLS - 4);
1431
1432 pos = ((COLS - msg_l) - 4) / 2;
1433 line = (LINES - 6) / 2;
1434 strnz__cpy(title, "Notification", MAXLEN - 1);
1435 if (box_new(5, msg_l + 2, line, pos, title)) {
1436 ssnprintf(title, MAXLEN - 1, "box_new(%d, %d, %d, %d, %s) failed", 5,
1437 msg_l + 2, line, pos, title);
1438 destroy_chyron(chyron);
1439 abend(-1, title);
1440 }
1441 error_win = win_win[win_ptr];
1442 mvwaddstr(error_win, 0, 1, msg0);
1443 mvwaddstr(error_win, 1, 1, msg1);
1444 mvwaddstr(error_win, 2, 1, msg2);
1445 mvwaddstr(error_win, 3, 1, msg3);
1446 display_chyron(error_win, chyron, 4, chyron->l + 1);
1447
1448 do {
1449 curs_set(1);
1450 cmd_key = xwgetch(error_win, chyron, -1);
1451 curs_set(0);
1452 if (cmd_key == KEY_F(1) || cmd_key == 'N' || cmd_key == 'n' || cmd_key == 'Y' || cmd_key == 'y')
1453 break;
1454 } while (1);
1455 win_del();
1456 destroy_chyron(chyron);
1457 return (cmd_key);
1458}
#define min(x, y)
min macro evaluates two expressions, returning least result
Definition cm.h:89
void abend(int, char *)
Abnormal program termination.
Definition dwin.c:2018
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
Definition futil.c:544
size_t strnz(char *, size_t)
terminates string at New Line, Carriage Return, or max_len
Definition futil.c:615

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 * msg0,
char * msg1,
char * msg2,
char * msg3 )

Display an error message window or print to stderr.

display_error

Parameters
msg0First error message line
msg1Second error message line
msg2Third error message line
msg3Fourth error message line
Returns
Key code of user command

Definition at line 1467 of file dwin.c.

1467 {
1468 char title[MAXLEN];
1469 int line, pos, msg_l, msg0_l, msg1_l, msg2_l, msg3_l;
1470 WINDOW *error_win;
1471
1472 if (!f_curses_open) {
1473 fprintf(stderr, "\n\n%s\n", msg0);
1474 fprintf(stderr, "%s\n", msg1);
1475 fprintf(stderr, "%s\n", msg2);
1476 fprintf(stderr, "%s\n\n", msg3);
1477 return 1;
1478 }
1479
1480 Chyron *chyron = new_chyron();
1481 set_chyron_key(chyron, 1, "F1 Help", KEY_F(1));
1482 set_chyron_key(chyron, 9, "F9 Cancel", KEY_F(9));
1483 set_chyron_key(chyron, 10, "F10 Continue", KEY_F(10));
1484 compile_chyron(chyron);
1485
1486 msg0_l = strnz(msg0, COLS - 4);
1487 msg1_l = strnz(msg1, COLS - 4);
1488 msg2_l = strnz(msg2, COLS - 4);
1489 msg3_l = strnz(msg1, COLS - 4);
1490 msg_l = max(msg0_l, msg1_l);
1491 msg_l = max(msg_l, msg2_l);
1492 msg_l = max(msg_l, msg3_l);
1493 msg_l = max(msg_l, chyron->l);
1494 msg_l = min(msg_l, COLS - 4);
1495
1496 pos = ((COLS - msg_l) - 4) / 2;
1497 line = (LINES - 6) / 2;
1498 strnz__cpy(title, "Notification", MAXLEN - 1);
1499 if (box_new(5, msg_l + 2, line, pos, title)) {
1500 ssnprintf(title, MAXLEN - 1, "box_new(%d, %d, %d, %d, %s) failed", 5,
1501 msg_l + 2, line, pos, title);
1502 destroy_chyron(chyron);
1503 abend(-1, title);
1504 }
1505 error_win = win_win[win_ptr];
1506 mvwaddstr(error_win, 0, 1, msg0);
1507 mvwaddstr(error_win, 1, 1, msg1);
1508 mvwaddstr(error_win, 2, 1, msg2);
1509 mvwaddstr(error_win, 3, 1, msg3);
1510 display_chyron(error_win, chyron, 4, chyron->l + 1);
1511 do {
1512 cmd_key = xwgetch(error_win, chyron, -1);
1513 if (cmd_key == KEY_F(9) || cmd_key == KEY_F(10) || cmd_key == 'q' || cmd_key == 'Q')
1514 break;
1515 } while (1);
1516 win_del();
1517 destroy_chyron(chyron);
1518 return (cmd_key);
1519}

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(), 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:

◆ message_win()

WINDOW * message_win ( char * msg)

Display a message in a window or print to stderr if curses is not available.

Parameters
msgMessage to display
Returns
Pointer to the created window, or nullptr if curses is not available or screen is too small

Definition at line 1377 of file dwin.c.

1377 {
1378 if (!f_curses_open) {
1379 fprintf(stderr, "\n\n%s\n\n", msg);
1380 return nullptr;
1381 }
1382 if (LINES < 4 || COLS < 42)
1383 return nullptr;
1384 int wlines = 3, wcols = 40;
1385 int wbegy = 0;
1386 int wbegx = COLS - wcols - 2;
1387 WINDOW *win = subwin(stdscr, wlines, wcols, wbegy, wbegx);
1388 if (win == nullptr)
1389 return win;
1390 wbkgrndset(win, &CC_BOX);
1391 wborder_set(win, &ls, &rs, &ts, &bs, &tl, &tr, &bl, &br);
1392 strnz(msg, 40);
1393 mvwaddstr(win, 0, 1, msg);
1394 update_panels();
1395 doupdate();
1396 return win;
1397}
cchar_t tl
Definition cm.h:501
cchar_t br
Definition cm.h:501
cchar_t rs
Definition cm.h:501
cchar_t CC_BOX
Definition dwin.c:199
cchar_t bl
Definition cm.h:501
cchar_t ts
Definition cm.h:501
cchar_t tr
Definition cm.h:501
cchar_t ls
Definition cm.h:631
cchar_t bs
Definition cm.h:501

References bl, br, bs, CC_BOX, f_curses_open, ls, rs, strnz(), tl, tr, and ts.

Here is the call 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 2006 of file dwin.c.

2006 {
2007 fprintf(stderr, "ERROR: %s code: %d\n", s, ec);
2008 fprintf(stderr, "Press a key to continue");
2009 di_getch();
2010 fprintf(stderr, "\n");
2011 return ec;
2012}
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 1526 of file dwin.c.

1526 {
1527 char emsg[MAXLEN];
1528 unsigned in_key;
1529 WINDOW *error_win;
1530 int len, line, pos;
1531 char title[MAXLEN];
1532 bool f_xwgetch = true;
1533 if (emsg_str[0] == '␛' && emsg_str[1] == 'w') {
1534 emsg_str += 2;
1535 f_xwgetch = false;
1536 }
1537 strnz__cpy(emsg, emsg_str, 79);
1538 if (!f_curses_open) {
1539 fprintf(stderr, "\n%s\n", emsg);
1540 return 1;
1541 }
1542 Chyron *chyron = new_chyron();
1543 set_chyron_key(chyron, 1, "F1 Help", KEY_F(1));
1544 set_chyron_key(chyron, 9, "F9 Cancel", KEY_F(9));
1545 set_chyron_key(chyron, 10, "F10 Continue", KEY_F(10));
1546 compile_chyron(chyron);
1547 len = strnz(emsg, COLS - 4);
1548 pos = (COLS - len - 4) / 2;
1549 line = (LINES - 4) / 2;
1550 strnz__cpy(title, "Notification", MAXLEN - 1);
1551 if (box_new(2, len + 2, line, pos, title)) {
1552 ssnprintf(title, MAXLEN - 1, "box_new(%d, %d, %d, %d, %s, %b) failed",
1553 4, line, line, pos, title);
1554 destroy_chyron(chyron);
1555 abend(-1, title);
1556 }
1557 error_win = win_win[win_ptr];
1558 mvwaddstr(error_win, 0, 1, emsg);
1559 display_chyron(error_win, chyron, 1, chyron->l + 1);
1560 if (f_xwgetch) {
1561 curs_set(1);
1562 in_key = xwgetch(error_win, chyron, -1);
1563 curs_set(0);
1564 } else {
1565 in_key = KEY_F(10);
1566 }
1567 destroy_chyron(chyron);
1568 win_del();
1569 return (in_key);
1570}

References abend(), box_new(), 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 action_disposition(), bare_box_new(), box_hsplit_new(), 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(), init_view_boxwin(), init_view_full_screen(), initialize_line_table(), menu_engine(), new_init(), new_pick(), open_pick_win(), pad_refresh(), parse_menu_description(), pick_engine(), popup_ckeys(), search(), ui_init(), view_cmd_processor(), view_init_input(), win2_new(), win_del(), win_new(), 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 1636 of file dwin.c.

1636 {
1637 char time_str[10];
1638 ssnprintf(time_str, 9, "%-4d", remaining);
1639 mvwaddstr(wait_win, 0, 21, time_str);
1640 display_chyron(wait_win, chyron, 1, 0);
1641 wmove(wait_win, 1, chyron->l);
1642 cmd_key = xwgetch(wait_win, chyron, 1);
1643 return cmd_key;
1644}

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

Referenced by 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 1621 of file dwin.c.

1621 {
1622 win_del();
1623 destroy_chyron(chyron);
1624 update_panels();
1625 doupdate();
1626 return true;
1627}

References destroy_chyron(), and win_del().

Here is the call 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 1576 of file dwin.c.

1576 {
1577 Chyron *chyron = new_chyron();
1578 set_chyron_key(chyron, 9, "F9 Cancel", KEY_F(9));
1579 compile_chyron(chyron);
1580 return chyron;
1581}

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

Referenced by 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 1589 of file dwin.c.

1589 {
1590 char wm1[] = "Seconds remaining:";
1591 int len;
1592 int line, col;
1593 WINDOW *wait_win;
1594
1595 if (!f_curses_open) {
1596 fprintf(stderr, "\n%s\n", title);
1597 fprintf(stderr, "%s\n", wm1);
1598 return NULL;
1599 }
1600 len = max(strlen(title), strlen(wm1));
1601 len = max(len, chyron->l);
1602 len = max(len, 40);
1603 col = (COLS - len - 4) / 2;
1604 line = (LINES - 4) / 2;
1605 if (box_new(2, len + 2, line, col, title)) {
1606 ssnprintf(title, MAXLEN - 1, "box_new(%d, %d, %d, %d, %s) failed", 4,
1607 line, line, col, title);
1608 abend(-1, title);
1609 }
1610 wait_win = win_win[win_ptr];
1611 mvwaddstr(wait_win, 0, 1, wm1);
1612 display_chyron(wait_win, chyron, 1, 0);
1613 wmove(wait_win, 1, chyron->l);
1614 return wait_win;
1615}

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

Referenced by 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 2033 of file dwin.c.

2033 {
2034 int status;
2035 Chyron *wait_chyron;
2036 WINDOW *wait_win;
2037 int remaining = timeout;
2038 bool rc = false;
2039
2040 waitpid(pid, &status, WNOHANG);
2041 if (WIFEXITED(status) || WIFSIGNALED(status)) {
2042 kill(pid, SIGKILL);
2043 waitpid(pid, &status, 0);
2044 return true;
2045 }
2046 usleep(100000); // Sleep for 200ms */
2047 wait_chyron = wait_mk_chyron();
2048 ssnprintf(em0, MAXLEN - 1, "Waiting for process %d to finish...", pid);
2049 wait_win = wait_mk_win(wait_chyron, em0);
2050 cmd_key = 0;
2051 while (remaining > 0 && cmd_key != KEY_F(9)) {
2052 cmd_key = wait_continue(wait_win, wait_chyron, remaining);
2053 if (cmd_key == KEY_F(9))
2054 break;
2055 if (cmd_key == KEY_F(10)) {
2056 remaining = timeout;
2057 continue;
2058 }
2059 remaining--;
2060 waitpid(pid, &status, WNOHANG);
2061 if (WIFEXITED(status) || WIFSIGNALED(status)) {
2062 rc = true;
2063 break;
2064 }
2065 }
2066 kill(pid, SIGKILL);
2067 waitpid(pid, &status, 0);
2068 win_del();
2069 destroy_chyron(wait_chyron);
2070 update_panels();
2071 doupdate();
2072 return rc;
2073}
int wait_continue(WINDOW *, Chyron *, int)
Update the waiting message with remaining time and check for user input.
Definition dwin.c:1636
WINDOW * wait_mk_win(Chyron *, char *)
Display a popup waiting message.
Definition dwin.c:1589
Chyron * wait_mk_chyron()
Create a Chyron struct for the waiting message.
Definition dwin.c:1576

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

Referenced by form_process().

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