1 /****************************************************************************
2 * Copyright 2020,2021 Thomas E. Dickey *
3 * Copyright 1998-2006,2010 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************/
30 /****************************************************************************
31 * Author: Juergen Pfeifer, 1995,1997 *
32 ****************************************************************************/
34 /***************************************************************************
36 * Pattern matching handling *
37 ***************************************************************************/
39 #include "menu.priv.h"
41 MODULE_ID("$Id: m_pattern.c,v 1.20 2021/06/17 21:20:30 tom Exp $")
43 /*---------------------------------------------------------------------------
45 | Function : char *menu_pattern(const MENU *menu)
47 | Description : Return the value of the pattern buffer.
49 | Return Values : NULL - if there is no pattern buffer allocated
50 | EmptyString - if there is a pattern buffer but no
52 | PatternString - as expected
53 +--------------------------------------------------------------------------*/
55 menu_pattern(const MENU *menu)
57 static char empty[] = "";
59 T((T_CALLED("menu_pattern(%p)"), (const void *)menu));
60 returnPtr(menu ? (menu->pattern ? menu->pattern : empty) : 0);
63 /*---------------------------------------------------------------------------
65 | Function : int set_menu_pattern(MENU *menu, const char *p)
67 | Description : Set the match pattern for a menu and position to the
68 | first item that matches.
70 | Return Values : E_OK - success
71 | E_BAD_ARGUMENT - invalid menu or pattern pointer
72 | E_BAD_STATE - menu in user hook routine
73 | E_NOT_CONNECTED - no items connected to menu
74 | E_NO_MATCH - no item matches pattern
75 +--------------------------------------------------------------------------*/
77 set_menu_pattern(MENU *menu, const char *p)
82 T((T_CALLED("set_menu_pattern(%p,%s)"), (void *)menu, _nc_visbuf(p)));
85 RETURN(E_BAD_ARGUMENT);
88 RETURN(E_NOT_CONNECTED);
90 if (menu->status & _IN_DRIVER)
97 pos_menu_cursor(menu);
101 if (menu->status & _LINK_NEEDED)
102 _nc_Link_Items(menu);
104 matchpos = menu->toprow;
105 matchitem = menu->curitem;
110 if (!isprint(UChar(*p)) ||
111 (_nc_Match_Next_Character_In_Item_Name(menu, *p, &matchitem) != E_OK))
114 pos_menu_cursor(menu);
120 /* This is reached if there was a match. So we position to the new item */
121 Adjust_Current_Item(menu, matchpos, matchitem);
125 /* m_pattern.c ends here */