curses - change some panics to impossibles.

This commit is contained in:
Tangles
2018-07-25 22:06:33 +10:00
committed by nhmall
parent 4a4b3fb8f1
commit 1f94456e46
3 changed files with 45 additions and 27 deletions

View File

@@ -508,6 +508,12 @@ curses_add_nhmenu_item(winid wid, int glyph, const ANY_P * identifier,
nhmenu_item *new_item, *current_items, *menu_item_ptr;
nhmenu *current_menu = get_menu(wid);
if (current_menu == NULL) {
impossible
("curses_add_nhmenu_item: attempt to add item to nonexistent menu");
return;
}
if (str == NULL) {
return;
}
@@ -530,11 +536,6 @@ curses_add_nhmenu_item(winid wid, int glyph, const ANY_P * identifier,
new_item->count = -1;
new_item->next_item = NULL;
if (current_menu == NULL) {
panic
("curses_add_nhmenu_item: attempt to add item to nonexistant menu");
}
current_items = current_menu->entries;
menu_item_ptr = current_items;
@@ -559,12 +560,13 @@ curses_finalize_nhmenu(winid wid, const char *prompt)
{
int count = 0;
nhmenu *current_menu = get_menu(wid);
nhmenu_item *menu_item_ptr = current_menu->entries;
if (current_menu == NULL) {
panic("curses_finalize_nhmenu: attempt to finalize nonexistant menu");
impossible("curses_finalize_nhmenu: attempt to finalize nonexistent menu");
return;
}
nhmenu_item *menu_item_ptr = current_menu->entries;
while (menu_item_ptr != NULL) {
menu_item_ptr = menu_item_ptr->next_item;
count++;
@@ -590,13 +592,15 @@ curses_display_nhmenu(winid wid, int how, MENU_ITEM_P ** _selected)
*_selected = NULL;
if (current_menu == NULL) {
panic("curses_display_nhmenu: attempt to display nonexistant menu");
impossible("curses_display_nhmenu: attempt to display nonexistent menu");
return;
}
menu_item_ptr = current_menu->entries;
if (menu_item_ptr == NULL) {
panic("curses_display_nhmenu: attempt to display empty menu");
impossible("curses_display_nhmenu: attempt to display empty menu");
return;
}
/* Reset items to unselected to clear out selections from previous
@@ -631,8 +635,9 @@ curses_display_nhmenu(winid wid, int how, MENU_ITEM_P ** _selected)
while (menu_item_ptr != NULL) {
if (menu_item_ptr->selected) {
if (count == num_chosen) {
panic("curses_display_nhmenu: Selected items "
impossible("curses_display_nhmenu: Selected items "
"exceeds expected number");
break;
}
selected[count].item = menu_item_ptr->identifier;
selected[count].count = menu_item_ptr->count;
@@ -642,7 +647,7 @@ curses_display_nhmenu(winid wid, int how, MENU_ITEM_P ** _selected)
}
if (count != num_chosen) {
panic("curses_display_nhmenu: Selected items less than "
impossible("curses_display_nhmenu: Selected items less than "
"expected number");
}
}
@@ -949,7 +954,8 @@ menu_display_page(nhmenu *menu, WINDOW * win, int page_num)
}
if (menu_item_ptr == NULL) { /* Page not found */
panic("menu_display_page: attempt to display nonexistant page");
impossible("menu_display_page: attempt to display nonexistent page");
return;
}
werase(win);
@@ -1343,7 +1349,8 @@ menu_operation(WINDOW * win, nhmenu *menu, menu_op
}
if (menu_item_ptr == NULL) { /* Page not found */
panic("menu_display_page: attempt to display nonexistant page");
impossible("menu_display_page: attempt to display nonexistent page");
return 0;
}
while (menu_item_ptr != NULL) {

View File

@@ -188,8 +188,8 @@ curses_get_wid(int type)
ret = text_wid;
break;
default:
panic("curses_get_wid: unsupported window type");
ret = -1; /* Not reached */
impossible("curses_get_wid: unsupported window type");
ret = -1;
}
while (curses_window_exists(ret)) {

View File

@@ -78,9 +78,15 @@ curses_create_window(int width, int height, orient orientation)
width += 2; /* leave room for bounding box */
height += 2;
if ((width > term_cols) || (height > term_rows))
panic("curses_create_window: Terminal too small for dialog window");
if ((width > term_cols) || (height > term_rows)) {
impossible("curses_create_window: Terminal too small for dialog window");
width = term_cols;
height = term_rows;
}
switch (orientation) {
default:
impossible("curses_create_window: Bad orientation");
/* fall through to centre */
case CENTER:
startx = (term_cols / 2) - (width / 2);
starty = (term_rows / 2) - (height / 2);
@@ -119,9 +125,6 @@ curses_create_window(int width, int height, orient orientation)
starty = 0;
break;
default:
panic("curses_create_window: Bad orientation");
break;
}
if (startx < 0) {
@@ -190,7 +193,8 @@ WINDOW *
curses_get_nhwin(winid wid)
{
if (!is_main_window(wid)) {
panic("curses_get_nhwin: wid out of range. Not a main window.");
impossible("curses_get_nhwin: wid %d out of range. Not a main window.", wid);
return NULL;
}
return nhwins[wid].curwin;
@@ -208,7 +212,8 @@ curses_add_nhwin(winid wid, int height, int width, int y, int x,
int real_height = height;
if (!is_main_window(wid)) {
panic("curses_add_nhwin: wid out of range. Not a main window.");
impossible("curses_add_nhwin: wid %d out of range. Not a main window.", wid);
return;
}
nhwins[wid].nhwin = wid;
@@ -300,7 +305,8 @@ curses_del_nhwin(winid wid)
}
if (!is_main_window(wid)) {
panic("curses_del_nhwin: wid out of range. Not a main window.");
impossible("curses_del_nhwin: wid %d out of range. Not a main window.", wid);
return;
}
nhwins[wid].curwin = NULL;
@@ -390,7 +396,10 @@ void
curses_get_window_xy(winid wid, int *x, int *y)
{
if (!is_main_window(wid)) {
panic("curses_get_window_xy: wid out of range. Not a main window.");
impossible("curses_get_window_xy: wid %d out of range. Not a main window.", wid);
*x = 0;
*y = 0;
return;
}
*x = nhwins[wid].x;
@@ -442,8 +451,9 @@ int
curses_get_window_orientation(winid wid)
{
if (!is_main_window(wid)) {
panic
("curses_get_window_orientation: wid out of range. Not a main window.");
impossible
("curses_get_window_orientation: wid %d out of range. Not a main window.", wid);
return CENTER;
}
return nhwins[wid].orientation;
@@ -480,7 +490,8 @@ curses_puts(winid wid, int attr, const char *text)
if (curses_is_menu(wid) || curses_is_text(wid)) {
if (!curses_menu_exists(wid)) {
panic("curses_puts: Attempted write to nonexistant window!");
impossible("curses_puts: Attempted write to nonexistant window %d!", wid);
return;
}
identifier = malloc(sizeof (anything));
identifier->a_void = NULL;