diff options
author | jkh <jkh@FreeBSD.org> | 1997-10-12 12:09:46 +0000 |
---|---|---|
committer | jkh <jkh@FreeBSD.org> | 1997-10-12 12:09:46 +0000 |
commit | 90cf2421d24934825ce5f0e92c7a47e2e3849c97 (patch) | |
tree | b2b6115cd7177409b78d8c744b18c14b5c759871 /gnu/lib/libdialog | |
parent | 74b4da4ea85757f48f5574d557af112e613fc76f (diff) | |
download | FreeBSD-src-90cf2421d24934825ce5f0e92c7a47e2e3849c97.zip FreeBSD-src-90cf2421d24934825ce5f0e92c7a47e2e3849c97.tar.gz |
Fix improperly re-entrant code which caused the menu spammage we've
been seeing since 2.2.1.
Pointed-in-the-right-direction by: phk
Diffstat (limited to 'gnu/lib/libdialog')
-rw-r--r-- | gnu/lib/libdialog/checklist.c | 31 | ||||
-rw-r--r-- | gnu/lib/libdialog/menubox.c | 31 |
2 files changed, 25 insertions, 37 deletions
diff --git a/gnu/lib/libdialog/checklist.c b/gnu/lib/libdialog/checklist.c index b83c3f3..e5f9ddd 100644 --- a/gnu/lib/libdialog/checklist.c +++ b/gnu/lib/libdialog/checklist.c @@ -25,14 +25,10 @@ #include "dialog.priv.h" -static void print_item(WINDOW *win, unsigned char *tag, unsigned char *item, int status, int choice, int selected, - dialogMenuItem *me); +static void print_item(WINDOW *win, unsigned char *tag, unsigned char *item, int status, int choice, int selected, dialogMenuItem *me, int list_width, int item_x, int check_x); #define DREF(di, item) ((di) ? &((di)[(item)]) : NULL) -static int list_width, check_x, item_x; - - /* * Display a dialog box with a list of options that can be turned on or off */ @@ -48,7 +44,8 @@ dialog_checklist(unsigned char *title, unsigned char *prompt, int height, int wi WINDOW *dialog, *list; unsigned char **items = NULL; dialogMenuItem *ditems; - + int list_width, check_x, item_x; + /* Allocate space for storing item on/off status */ if ((status = alloca(sizeof(int) * abs(cnt))) == NULL) { endwin(); @@ -172,7 +169,7 @@ draw: /* Print the list */ for (i = 0; i < max_choice; i++) - print_item(list, items[i * 3], items[i * 3 + 1], status[i], i, i == choice, DREF(ditems, i)); + print_item(list, items[i * 3], items[i * 3 + 1], status[i], i, i == choice, DREF(ditems, i), list_width, item_x, check_x); wnoutrefresh(list); print_arrows(dialog, scroll, list_height, item_no, box_x, box_y, check_x + 4, cur_x, cur_y); @@ -271,14 +268,14 @@ draw: if (list_height > 1) { /* De-highlight current first item before scrolling down */ print_item(list, items[scroll * 3], items[scroll * 3 + 1], status[scroll], 0, - FALSE, DREF(ditems, scroll)); + FALSE, DREF(ditems, scroll), list_width, item_x, check_x); scrollok(list, TRUE); wscrl(list, -1); scrollok(list, FALSE); } scroll--; print_item(list, items[scroll*3], items[scroll*3 + 1], status[scroll], 0, - TRUE, DREF(ditems, scroll)); + TRUE, DREF(ditems, scroll), list_width, item_x, check_x); wnoutrefresh(list); print_arrows(dialog, scroll, list_height, item_no, box_x, box_y, check_x + 4, cur_x, cur_y); wrefresh(dialog); @@ -298,7 +295,7 @@ draw: print_item(list, items[(scroll + max_choice - 1) * 3], items[(scroll + max_choice - 1) * 3 + 1], status[scroll + max_choice - 1], max_choice - 1, - FALSE, DREF(ditems, scroll + max_choice - 1)); + FALSE, DREF(ditems, scroll + max_choice - 1), list_width, item_x, check_x); scrollok(list, TRUE); scroll(list); scrollok(list, FALSE); @@ -307,7 +304,7 @@ draw: print_item(list, items[(scroll + max_choice - 1) * 3], items[(scroll + max_choice - 1) * 3 + 1], status[scroll + max_choice - 1], max_choice - 1, TRUE, - DREF(ditems, scroll + max_choice - 1)); + DREF(ditems, scroll + max_choice - 1), list_width, item_x, check_x); wnoutrefresh(list); print_arrows(dialog, scroll, list_height, item_no, box_x, box_y, check_x + 4, cur_x, cur_y); wrefresh(dialog); @@ -338,7 +335,7 @@ draw: status[i] = ditems[i].checked ? ditems[i].checked(&ditems[i]) : FALSE; for (i = 0; i < max_choice; i++) { print_item(list, items[(scroll + i) * 3], items[(scroll + i) * 3 + 1], - status[scroll + i], i, i == choice, DREF(ditems, scroll + i)); + status[scroll + i], i, i == choice, DREF(ditems, scroll + i), list_width, item_x, check_x); } wnoutrefresh(list); print_arrows(dialog, scroll, list_height, item_no, box_x, box_y, check_x + 4, @@ -386,12 +383,11 @@ draw: /* De-highlight current item */ getyx(dialog, cur_y, cur_x); /* Save cursor position */ print_item(list, items[(scroll + choice) * 3], items[(scroll + choice) * 3 + 1], - status[scroll + choice], choice, FALSE, DREF(ditems, scroll + choice)); + status[scroll + choice], choice, FALSE, DREF(ditems, scroll + choice), list_width, item_x, check_x); /* Highlight new item */ choice = i; - print_item(list, items[(scroll + choice) * 3], items[(scroll + choice) * 3 + 1], - status[scroll + choice], choice, TRUE, DREF(ditems, scroll + choice)); + print_item(list, items[(scroll + choice) * 3], items[(scroll + choice) * 3 + 1], status[scroll + choice], choice, TRUE, DREF(ditems, scroll + choice), list_width, item_x, check_x); wnoutrefresh(list); wmove(dialog, cur_y, cur_x); /* Restore cursor to previous position */ wrefresh(dialog); @@ -499,7 +495,7 @@ draw: wclear(list); for (i = 0; i < max_choice; i++) print_item(list, items[(scroll + i) * 3], items[(scroll + i) * 3 + 1], status[scroll + i], - i, i == choice, DREF(ditems, scroll + i)); + i, i == choice, DREF(ditems, scroll + i), list_width, item_x, check_x); wnoutrefresh(list); print_arrows(dialog, scroll, list_height, item_no, box_x, box_y, check_x + 4, cur_x, cur_y); wrefresh(dialog); @@ -516,8 +512,7 @@ draw: * Print list item */ static void -print_item(WINDOW *win, unsigned char *tag, unsigned char *item, int status, int choice, int selected, - dialogMenuItem *me) +print_item(WINDOW *win, unsigned char *tag, unsigned char *item, int status, int choice, int selected, dialogMenuItem *me, int list_width, int item_x, int check_x) { int i; diff --git a/gnu/lib/libdialog/menubox.c b/gnu/lib/libdialog/menubox.c index dbff38d..73d004a 100644 --- a/gnu/lib/libdialog/menubox.c +++ b/gnu/lib/libdialog/menubox.c @@ -25,19 +25,15 @@ #include "dialog.priv.h" #include <ncurses.h> -static void print_item(WINDOW *win, unsigned char *tag, unsigned char *item, int choice, int selected, - dialogMenuItem *me); +static void print_item(WINDOW *win, unsigned char *tag, unsigned char *item, int choice, int selected, dialogMenuItem *me, int menu_width, int tag_x, int item_x); #define DREF(di, item) ((di) ? &((di)[(item)]) : NULL) -static int menu_width, tag_x, item_x; - /* * Display a menu for choosing among a number of options */ int -dialog_menu(unsigned char *title, unsigned char *prompt, int height, int width, int menu_height, - int cnt, void *it, unsigned char *result, int *ch, int *sc) +dialog_menu(unsigned char *title, unsigned char *prompt, int height, int width, int menu_height, int cnt, void *it, unsigned char *result, int *ch, int *sc) { int i, j, x, y, cur_x, cur_y, box_x, box_y, key = 0, button, choice, l, k, scroll, max_choice, item_no, redraw_menu = FALSE; @@ -46,6 +42,7 @@ dialog_menu(unsigned char *title, unsigned char *prompt, int height, int width, WINDOW *dialog, *menu; unsigned char **items = NULL; dialogMenuItem *ditems; + int menu_width, tag_x, item_x; draw: choice = ch ? *ch : 0; @@ -161,8 +158,7 @@ draw: /* Print the menu */ for (i = 0; i < max_choice; i++) - print_item(menu, items[(scroll + i) * 2], items[(scroll + i) * 2 + 1], i, - i == choice, DREF(ditems, scroll + i)); + print_item(menu, items[(scroll + i) * 2], items[(scroll + i) * 2 + 1], i, i == choice, DREF(ditems, scroll + i), menu_width, tag_x, item_x); wnoutrefresh(menu); print_arrows(dialog, scroll, menu_height, item_no, box_x, box_y, tag_x, cur_x, cur_y); @@ -247,13 +243,13 @@ draw: getyx(dialog, cur_y, cur_x); /* Save cursor position */ if (menu_height > 1) { /* De-highlight current first item before scrolling down */ - print_item(menu, items[scroll * 2], items[scroll * 2 + 1], 0, FALSE, DREF(ditems, scroll)); + print_item(menu, items[scroll * 2], items[scroll * 2 + 1], 0, FALSE, DREF(ditems, scroll), menu_width, tag_x, item_x); scrollok(menu, TRUE); wscrl(menu, -1); scrollok(menu, FALSE); } scroll--; - print_item(menu, items[scroll * 2], items[scroll * 2 + 1], 0, TRUE, DREF(ditems, scroll)); + print_item(menu, items[scroll * 2], items[scroll * 2 + 1], 0, TRUE, DREF(ditems, scroll), menu_width, tag_x, item_x); wnoutrefresh(menu); print_arrows(dialog, scroll, menu_height, item_no, box_x, box_y, tag_x, cur_x, cur_y); wrefresh(dialog); @@ -272,7 +268,7 @@ draw: /* De-highlight current last item before scrolling up */ print_item(menu, items[(scroll + max_choice - 1) * 2], items[(scroll + max_choice - 1) * 2 + 1], - max_choice-1, FALSE, DREF(ditems, scroll + max_choice - 1)); + max_choice-1, FALSE, DREF(ditems, scroll + max_choice - 1), menu_width, tag_x, item_x); scrollok(menu, TRUE); scroll(menu); scrollok(menu, FALSE); @@ -280,7 +276,7 @@ draw: scroll++; print_item(menu, items[(scroll + max_choice - 1) * 2], items[(scroll + max_choice - 1) * 2 + 1], - max_choice - 1, TRUE, DREF(ditems, scroll + max_choice - 1)); + max_choice - 1, TRUE, DREF(ditems, scroll + max_choice - 1), menu_width, tag_x, item_x); wnoutrefresh(menu); print_arrows(dialog, scroll, menu_height, item_no, box_x, box_y, tag_x, cur_x, cur_y); wrefresh(dialog); @@ -293,13 +289,11 @@ draw: if (i != choice) { /* De-highlight current item */ getyx(dialog, cur_y, cur_x); /* Save cursor position */ - print_item(menu, items[(scroll + choice) * 2], items[(scroll + choice) * 2 + 1], choice, FALSE, - DREF(ditems, scroll + choice)); + print_item(menu, items[(scroll + choice) * 2], items[(scroll + choice) * 2 + 1], choice, FALSE, DREF(ditems, scroll + choice), menu_width, tag_x, item_x); /* Highlight new item */ choice = i; - print_item(menu, items[(scroll + choice) * 2], items[(scroll + choice) * 2 + 1], choice, TRUE, - DREF(ditems, scroll + choice)); + print_item(menu, items[(scroll + choice) * 2], items[(scroll + choice) * 2 + 1], choice, TRUE, DREF(ditems, scroll + choice), menu_width, tag_x, item_x); wnoutrefresh(menu); wmove(dialog, cur_y, cur_x); /* Restore cursor to previous position */ wrefresh(dialog); @@ -418,8 +412,7 @@ draw: if (redraw_menu) { for (i = 0; i < max_choice; i++) { - print_item(menu, items[(scroll + i) * 2], items[(scroll + i) * 2 + 1], i, i == choice, - DREF(ditems, scroll + i)); + print_item(menu, items[(scroll + i) * 2], items[(scroll + i) * 2 + 1], i, i == choice, DREF(ditems, scroll + i), menu_width, tag_x, item_x); } wnoutrefresh(menu); getyx(dialog, cur_y, cur_x); /* Save cursor position */ @@ -439,7 +432,7 @@ draw: * Print menu item */ static void -print_item(WINDOW *win, unsigned char *tag, unsigned char *item, int choice, int selected, dialogMenuItem *me) +print_item(WINDOW *win, unsigned char *tag, unsigned char *item, int choice, int selected, dialogMenuItem *me, int menu_width, int tag_x, int item_x) { int i; |