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.
int Perror (char *emsg_str)
 Display a simple error message window or print to stderr.

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

1204 {
1207 sig_dfl_mode();
1208 fprintf(stderr, "\n\nABEND: %s (code: %d)\n", s, ec);
1209 exit(EXIT_FAILURE);
1210}
void destroy_curses()
Gracefully shut down NCurses and restore terminal settings.
Definition dwin.c:384
bool restore_shell_tioctl()
restore_shell_tioctl() - restore shell terminal settings
Definition scriou.c:57
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(), parse_menu_description(), Perror(), sig_prog_mode(), signal_handler(), and view_init_input().

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

895 {
896 uint len;
897 uint line, col;
898
899 if (!f_curses_open) {
900 fprintf(stderr, "\n%s\n", title);
901 fprintf(stderr, "%s\n", action_str);
902 return true;
903 }
904 Chyron *chyron = new_chyron();
905 set_chyron_key(chyron, 10, "F10 Continue", KEY_F10);
906 compile_chyron(chyron);
907 len = max(strlen(title), strlen(action_str));
908 uint maxy, maxx;
909 ui_get_screen_size(&maxy, &maxx);
910 col = (maxx - len - 4) / 2;
911 line = (maxy - 4) / 2;
912 if (surface_box_win_new(2, len + 2, line, col, title)) {
913 ssnprintf(em0, MAXLEN - 1, "surface_box_win_new(%d, %d, %d, %d, %s) failed", 4,
914 line, line, col, title);
915 Perror(em0);
916 }
918 UiEvent event;
919 ui_draw_text(sfc, WIN, 0, 1, action_str);
920 display_chyron(sfc, WIN, chyron, 1, 0);
921 event.y = event.x = -1;
922 cmd_key = ui_get_event(sfc, WIN, &event, -1);
924 destroy_chyron(chyron);
925 return true;
926}
bool f_curses_open
Definition sig.c:33
#define max(a, b)
max macro evaluates two expressions, returning greatest result.
Definition cm.h:84
int ui_get_event(UiSurface *s, uint w, UiEvent *ev, int timeout_ms)
Wait for an input event on target (or stdscr if NULL).
int ui_draw_text(UiSurface *s, uint w, uint y, uint x, const char *text)
UiSurface * ui_surface[UI_SFC_MAX]
Definition ui_ncurses.c:28
void ui_get_screen_size(uint *lines, uint *cols)
Definition ui_ncurses.c:692
int sfc_ptr
Definition nckeys.c:47
#define KEY_F10
#define MAXLEN
Definition curskeys.c:15
unsigned int cmd_key
Definition dwin.c:128
int surface_box_win_new(uint wlines, uint wcols, uint wbegy, uint wbegx, char *wtitle)
Definition dwin.c:521
char em0[MAXLEN]
Definition dwin.c:142
int cm_surface_destroy(UiSurface *sfc)
Destroy the most recently created surface.
Definition dwin.c:576
int Perror(char *emsg_str)
Display a simple error message window or print to stderr.
Definition dwin.c:841
Chyron * destroy_chyron(Chyron *chyron)
Destroy Chyron structure.
Definition dwin.c:984
void compile_chyron(Chyron *chyron)
construct the chyron string from the chyron structure
Definition dwin.c:1110
Chyron * new_chyron()
Create and initialize Chyron structure.
Definition dwin.c:947
void display_chyron(UiSurface *sfc, uint w, Chyron *chyron, uint line, uint col)
Display chyron on the specified line and column of the surface.
Definition dwin.c:1163
void set_chyron_key(Chyron *chyron, uint k, char *s, uint kc)
Set chyron key with default color pair (cp_nt_rev).
Definition dwin.c:1045
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
Definition futil.c:413
A drawable surface in the NotCurses backend.
Definition cm.h:386

References cm_surface_destroy(), cmd_key, compile_chyron(), destroy_chyron(), display_chyron(), em0, f_curses_open, new_chyron(), Perror(), set_chyron_key(), sfc_ptr, ssnprintf(), surface_box_win_new(), ui_draw_text(), ui_get_event(), ui_get_screen_size(), ui_surface, WIN, UiEvent::x, and UiEvent::y.

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

715 {
716 char title[MAXLEN];
717 uint line, pos, msg_l, msg0_l, msg1_l, msg2_l, msg3_l;
718
719 if (!f_curses_open) {
720 fprintf(stderr, "\n\n%s\n%s\n%s\n%s\n\n", msg0, msg1, msg2, msg3);
721 return 1;
722 }
723
724 Chyron *chyron = new_chyron();
725 set_chyron_key(chyron, 1, "F1 Help", KEY_F01);
726 set_chyron_key(chyron, 2, "N - No", 'n');
727 set_chyron_key(chyron, 3, "Y - Yes", 'y');
728 compile_chyron(chyron);
729
730 uint maxy, maxx;
731 ui_get_screen_size(&maxy, &maxx);
732 msg0_l = strnz(msg0, maxx - 4);
733 msg1_l = strnz(msg1, maxx - 4);
734 msg2_l = strnz(msg2, maxx - 4);
735 msg3_l = strnz(msg1, maxx - 4);
736 msg_l = max(msg0_l, msg1_l);
737 msg_l = max(msg_l, msg2_l);
738 msg_l = max(msg_l, msg3_l);
739 msg_l = max(msg_l, chyron->l);
740 msg_l = min(msg_l, maxx - 4);
741
742 pos = ((maxx - msg_l) - 4) / 2;
743 line = (maxy - 6) / 2;
744 strnz__cpy(title, "Notification", MAXLEN - 1);
745 if (surface_box_win_new(5, msg_l + 2, line, pos, title)) {
746 ssnprintf(title, MAXLEN - 1, "surface_box_win_new(%d, %d, %d, %d, %s) failed", 5,
747 msg_l + 2, line, pos, title);
748 destroy_chyron(chyron);
749 abend(-1, title);
750 }
752 UiEvent event;
753 ui_draw_text(sfc, WIN, 0, 1, msg0);
754 ui_draw_text(sfc, WIN, 1, 1, msg1);
755 ui_draw_text(sfc, WIN, 2, 1, msg2);
756 ui_draw_text(sfc, WIN, 3, 1, msg3);
757 display_chyron(sfc, WIN, chyron, 4, chyron->l + 1);
758
759 do {
760 ui_curs_set(1);
761 event.y = event.x = -1;
762 cmd_key = ui_get_event(sfc, WIN, &event, -1);
763 if (cmd_key == KEY_F01 || cmd_key == 'N' || cmd_key == 'n' || cmd_key == 'Y' || cmd_key == 'y')
764 break;
765 } while (1);
767 destroy_chyron(chyron);
768 return (cmd_key);
769}
#define min(x, y)
min macro evaluates two expressions, returning least result
Definition cm.h:91
int ui_curs_set(int visibility)
Definition ui_ncurses.c:737
#define KEY_F01
void abend(int ec, char *s)
Abnormal program termination.
Definition dwin.c:1204
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
Definition futil.c:537
size_t strnz(char *, size_t)
terminates string at New Line, Carriage Return, or max_len
Definition futil.c:608
uint l
Definition cm.h:391

References abend(), cm_surface_destroy(), cmd_key, compile_chyron(), destroy_chyron(), display_chyron(), f_curses_open, Chyron::l, new_chyron(), set_chyron_key(), sfc_ptr, ssnprintf(), strnz(), strnz__cpy(), surface_box_win_new(), ui_curs_set(), ui_draw_text(), ui_get_event(), ui_get_screen_size(), ui_surface, WIN, UiEvent::x, and UiEvent::y.

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

778 {
779 char title[MAXLEN];
780 uint line, pos, msg_l, msg0_l, msg1_l, msg2_l, msg3_l;
781
782 if (!f_curses_open) {
783 fprintf(stderr, "\n\n%s\n", msg0);
784 fprintf(stderr, "%s\n", msg1);
785 fprintf(stderr, "%s\n", msg2);
786 fprintf(stderr, "%s\n\n", msg3);
787 return 1;
788 }
789
790 Chyron *chyron = new_chyron();
791 set_chyron_key(chyron, 1, "F1 Help", KEY_F01);
792 set_chyron_key(chyron, 9, "F9 Cancel", KEY_F09);
793 set_chyron_key(chyron, 10, "F10 Continue", KEY_F10);
794 compile_chyron(chyron);
795
796 uint maxy, maxx;
797 ui_get_screen_size(&maxy, &maxx);
798 msg0_l = strnz(msg0, maxx - 4);
799 msg1_l = strnz(msg1, maxx - 4);
800 msg2_l = strnz(msg2, maxx - 4);
801 msg3_l = strnz(msg1, maxx - 4);
802 msg_l = max(msg0_l, msg1_l);
803 msg_l = max(msg_l, msg2_l);
804 msg_l = max(msg_l, msg3_l);
805 msg_l = max(msg_l, chyron->l);
806 msg_l = min(msg_l, maxx - 4);
807
808 pos = ((maxx - msg_l) - 4) / 2;
809 line = (maxy - 6) / 2;
810 strnz__cpy(title, "Notification", MAXLEN - 1);
811 if (surface_box_win_new(5, msg_l + 2, line, pos, title)) {
812 ssnprintf(title, MAXLEN - 1, "box_win_new(%d, %d, %d, %d, %s) failed", 5,
813 msg_l + 2, line, pos, title);
814 destroy_chyron(chyron);
815 abend(-1, title);
816 }
818 UiEvent event;
819 ui_draw_text(sfc, WIN, 0, 1, msg0);
820 ui_draw_text(sfc, WIN, 1, 1, msg1);
821 ui_draw_text(sfc, WIN, 2, 1, msg2);
822 ui_draw_text(sfc, WIN, 3, 1, msg3);
823
824 display_chyron(sfc, WIN, chyron, 4, chyron->l + 1);
825 do {
826 event.y = event.x = -1;
827 cmd_key = ui_get_event(sfc, WIN, &event, -1);
828 if (cmd_key == KEY_F09 || cmd_key == KEY_F10 || cmd_key == 'q' || cmd_key == 'Q')
829 break;
830 } while (1);
832 destroy_chyron(chyron);
833 return (cmd_key);
834}
#define KEY_F09

References abend(), cm_surface_destroy(), cmd_key, compile_chyron(), destroy_chyron(), display_chyron(), f_curses_open, Chyron::l, new_chyron(), set_chyron_key(), sfc_ptr, ssnprintf(), strnz(), strnz__cpy(), surface_box_win_new(), ui_draw_text(), ui_get_event(), ui_get_screen_size(), ui_surface, WIN, UiEvent::x, and UiEvent::y.

Referenced by enter_file_spec(), form_desc_error(), form_parse_desc(), form_process(), form_read_data(), form_write(), mk_dir(), new_init(), new_pick(), new_view(), notcurses_input(), parse_menu_description(), ui_add_pair(), verify_dir(), verify_file(), view_cmd_processor(), view_init_input(), and write_view_buffer().

Here is the call graph for this function:
Here is the caller 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 841 of file dwin.c.

841 {
842 char emsg[MAXLEN];
843 unsigned in_key;
844 uint line, pos, cols;
845 char title[MAXLEN];
846 bool f_xwgetch = true;
847 if (emsg_str[0] == '␛' && emsg_str[1] == 'w') {
848 emsg_str += 2;
849 f_xwgetch = false;
850 }
851 strnz__cpy(emsg, emsg_str, 79);
852 if (!f_curses_open) {
853 fprintf(stderr, "\n%s\n", emsg);
854 return 1;
855 }
856 Chyron *chyron = new_chyron();
857 set_chyron_key(chyron, 1, "F1 Help", KEY_F01);
858 set_chyron_key(chyron, 9, "F9 Cancel", KEY_F09);
859 set_chyron_key(chyron, 10, "F10 Continue", KEY_F10);
860 compile_chyron(chyron);
861 uint maxy, maxx;
862 ui_get_screen_size(&maxy, &maxx);
863 cols = strnz(emsg, maxx - 4);
864 cols = max(cols, chyron->l);
865 ui_get_screen_size(&maxy, &maxx);
866 pos = (maxx - cols - 4) / 2;
867 line = (maxy - 4) / 2;
868 strnz__cpy(title, "Notification", MAXLEN - 1);
869 if (surface_box_win_new(2, cols + 2, line, pos, title)) {
870 ssnprintf(title, MAXLEN - 1, "surface_box_win_new(%d, %d, %d, %d, %s, %b) failed",
871 4, line, line, pos, title);
872 destroy_chyron(chyron);
873 abend(-1, title);
874 }
876 UiEvent event;
877 ui_draw_text(sfc, WIN, 0, 1, emsg_str);
878 display_chyron(sfc, WIN, chyron, 1, chyron->l + 1);
879 if (f_xwgetch) {
880 event.y = event.x = -1;
881 in_key = ui_get_event(sfc, WIN, &event, -1);
882 } else {
883 in_key = KEY_F10;
884 }
885 destroy_chyron(chyron);
887 return (in_key);
888}

References abend(), cm_surface_destroy(), compile_chyron(), destroy_chyron(), display_chyron(), f_curses_open, Chyron::l, new_chyron(), set_chyron_key(), sfc_ptr, ssnprintf(), strnz(), strnz__cpy(), surface_box_win_new(), ui_draw_text(), ui_get_event(), ui_get_screen_size(), ui_surface, WIN, UiEvent::x, and UiEvent::y.

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_line(), go_to_mark(), go_to_percent(), increment_ln(), init_form(), init_pick(), init_view_full_screen(), initialize_line_table(), menu_engine(), new_init(), new_pick(), open_pick_win(), parse_menu_description(), pick_engine(), popup_ckeys(), search(), surface_box_win_new(), surface_split_box_win_new(), ui_init(), 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: