revised menu searching
Convert search in tty menus from pmatch to case-insensitive pmatchi; convert search in X11 menus from substring strstri to wildcard pmatchi. tty bug: if the menu is full screen, the search prompt and subsequent user input clobbers the menu header.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.5 winmenu.c $NHDT-Date: 1427881480 2015/04/01 09:44:40 $ $NHDT-Branch: master $:$NHDT-Revision: 1.5 $ */
|
||||
/* NetHack 3.5 winmenu.c $NHDT-Date: 1428828477 2015/04/12 08:47:57 $ $NHDT-Branch: master $:$NHDT-Revision: 1.7 $ */
|
||||
/* NetHack 3.5 winmenu.c $Date: 2009/05/06 10:55:53 $ $Revision: 1.5 $ */
|
||||
/* SCCS Id: @(#)winmenu.c 3.5 1996/08/15 */
|
||||
/* Copyright (c) Dean Luick, 1992 */
|
||||
@@ -249,9 +249,13 @@ menu_key(w, event, params, num_params)
|
||||
return;
|
||||
} else if (ch == MENU_SEARCH) { /* search */
|
||||
if (menu_info->how == PICK_ANY || menu_info->how == PICK_ONE) {
|
||||
char buf[BUFSZ];
|
||||
X11_getlin("Search for:", buf);
|
||||
if (!*buf || *buf == '\033') return;
|
||||
char buf[BUFSZ+2], tmpbuf[BUFSZ];
|
||||
|
||||
X11_getlin("Search for:", tmpbuf);
|
||||
if (!*tmpbuf || *tmpbuf == '\033') return;
|
||||
/* convert "string" into "*string*" for use with pmatch() */
|
||||
Sprintf(buf, "*%s*", tmpbuf);
|
||||
|
||||
if (menu_info->how == PICK_ANY) {
|
||||
invert_match(wp, buf);
|
||||
return;
|
||||
@@ -395,10 +399,12 @@ menu_search(w, client_data, call_data)
|
||||
{
|
||||
struct xwindow *wp = (struct xwindow *) client_data;
|
||||
struct menu_info_t *menu_info = wp->menu_information;
|
||||
char buf[BUFSZ+2], tmpbuf[BUFSZ];
|
||||
|
||||
char buf[BUFSZ];
|
||||
X11_getlin("Search for:", buf);
|
||||
if (!*buf || *buf == '\033') return;
|
||||
X11_getlin("Search for:", tmpbuf);
|
||||
if (!*tmpbuf || *tmpbuf == '\033') return;
|
||||
/* convert "string" into "*string*" for use with pmatch() */
|
||||
Sprintf(buf, "*%s*", tmpbuf);
|
||||
|
||||
if (menu_info->how == PICK_ANY)
|
||||
invert_match(wp, buf);
|
||||
@@ -479,7 +485,7 @@ invert_all(wp)
|
||||
static void
|
||||
invert_match(wp, match)
|
||||
struct xwindow *wp;
|
||||
char *match;
|
||||
char *match; /* wildcard pattern for pmatch() */
|
||||
{
|
||||
x11_menu_item *curr;
|
||||
int count;
|
||||
@@ -488,7 +494,7 @@ invert_match(wp, match)
|
||||
reset_menu_count(wp->menu_information);
|
||||
for (count = 0, curr = wp->menu_information->curr_menu.base; curr;
|
||||
curr = curr->next, count++)
|
||||
if (curr->identifier.a_void != 0 && strstri(curr->str, match)) {
|
||||
if (curr->identifier.a_void != 0 && pmatchi(match, curr->str)) {
|
||||
invert_line(wp, curr, count, -1L);
|
||||
changed = TRUE;
|
||||
}
|
||||
@@ -503,7 +509,7 @@ invert_match(wp, match)
|
||||
static void
|
||||
select_match(wp, match)
|
||||
struct xwindow *wp;
|
||||
char *match;
|
||||
char *match; /* wildcard pattern for pmatch() */
|
||||
{
|
||||
x11_menu_item *curr;
|
||||
int count;
|
||||
@@ -511,11 +517,12 @@ select_match(wp, match)
|
||||
reset_menu_count(wp->menu_information);
|
||||
for (count = 0, curr = wp->menu_information->curr_menu.base; curr;
|
||||
curr = curr->next, count++)
|
||||
if (curr->identifier.a_void != 0 && strstri(curr->str, match)) {
|
||||
if (curr->identifier.a_void != 0 && pmatchi(match, curr->str)) {
|
||||
if (!curr->selected) {
|
||||
invert_line(wp, curr, count, -1L);
|
||||
#ifndef USE_FWF
|
||||
XawListChange(wp->w, wp->menu_information->curr_menu.list_pointer,
|
||||
XawListChange(wp->w,
|
||||
wp->menu_information->curr_menu.list_pointer,
|
||||
0, 0, True);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.5 wintty.c $NHDT-Date: 1428394244 2015/04/07 08:10:44 $ $NHDT-Branch: master $:$NHDT-Revision: 1.84 $ */
|
||||
/* NetHack 3.5 wintty.c $NHDT-Date: 1428828474 2015/04/12 08:47:54 $ $NHDT-Branch: master $:$NHDT-Revision: 1.85 $ */
|
||||
/* NetHack 3.5 wintty.c $Date: 2012/01/22 06:27:09 $ $Revision: 1.66 $ */
|
||||
/* Copyright (c) David Cohrs, 1991 */
|
||||
/* NetHack may be freely redistributed. See license for details. */
|
||||
@@ -1664,20 +1664,24 @@ struct WinDesc *cw;
|
||||
tty_nhbell();
|
||||
break;
|
||||
} else {
|
||||
char searchbuf[BUFSZ], tmpbuf[BUFSZ];
|
||||
char searchbuf[BUFSZ+2], tmpbuf[BUFSZ];
|
||||
boolean on_curr_page = FALSE;
|
||||
int lineno = 0;
|
||||
|
||||
tty_getlin("Search for:", tmpbuf);
|
||||
if (!tmpbuf[0] || tmpbuf[0] == '\033') break;
|
||||
Sprintf(searchbuf, "*%s*", tmpbuf);
|
||||
|
||||
for (curr = cw->mlist; curr; curr = curr->next) {
|
||||
if (on_curr_page) lineno++;
|
||||
if (curr == page_start)
|
||||
on_curr_page = TRUE;
|
||||
else if (curr == page_end)
|
||||
on_curr_page = FALSE;
|
||||
if (curr->identifier.a_void && pmatch(searchbuf, curr->str)) {
|
||||
toggle_menu_curr(window, curr, lineno, on_curr_page, counting, count);
|
||||
if (curr->identifier.a_void
|
||||
&& pmatchi(searchbuf, curr->str)) {
|
||||
toggle_menu_curr(window, curr, lineno,
|
||||
on_curr_page, counting, count);
|
||||
if (cw->how == PICK_ONE) {
|
||||
finished = TRUE;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user