X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=menu%2Fm_pattern.c;h=6fbef236f2e6aa67c858f8f07ccea3789d8957cd;hp=3d50cf42c1f9b5ca5507ef00a70b85e8bdbfc838;hb=c0e5fbfcce224693b3effdd295ee49b6b761b754;hpb=a8987e73ec254703634802b4f7ee30d3a485524d diff --git a/menu/m_pattern.c b/menu/m_pattern.c index 3d50cf42..6fbef236 100644 --- a/menu/m_pattern.c +++ b/menu/m_pattern.c @@ -1,5 +1,6 @@ /**************************************************************************** - * Copyright (c) 1998-2002,2003 Free Software Foundation, Inc. * + * Copyright 2020,2021 Thomas E. Dickey * + * Copyright 1998-2006,2010 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -37,12 +38,12 @@ #include "menu.priv.h" -MODULE_ID("$Id: m_pattern.c,v 1.9 2003/12/06 17:22:10 tom Exp $") +MODULE_ID("$Id: m_pattern.c,v 1.20 2021/06/17 21:20:30 tom Exp $") /*--------------------------------------------------------------------------- -| Facility : libnmenu +| Facility : libnmenu | Function : char *menu_pattern(const MENU *menu) -| +| | Description : Return the value of the pattern buffer. | | Return Values : NULL - if there is no pattern buffer allocated @@ -50,69 +51,74 @@ MODULE_ID("$Id: m_pattern.c,v 1.9 2003/12/06 17:22:10 tom Exp $") | pattern is stored | PatternString - as expected +--------------------------------------------------------------------------*/ -NCURSES_EXPORT(char *) -menu_pattern (const MENU * menu) +MENU_EXPORT(char *) +menu_pattern(const MENU *menu) { - return (char *)(menu ? (menu->pattern ? menu->pattern : "") : 0); + static char empty[] = ""; + + T((T_CALLED("menu_pattern(%p)"), (const void *)menu)); + returnPtr(menu ? (menu->pattern ? menu->pattern : empty) : 0); } /*--------------------------------------------------------------------------- -| Facility : libnmenu +| Facility : libnmenu | Function : int set_menu_pattern(MENU *menu, const char *p) -| +| | Description : Set the match pattern for a menu and position to the | first item that matches. | | Return Values : E_OK - success | E_BAD_ARGUMENT - invalid menu or pattern pointer -| E_NOT_CONNECTED - no items connected to menu | E_BAD_STATE - menu in user hook routine +| E_NOT_CONNECTED - no items connected to menu | E_NO_MATCH - no item matches pattern +--------------------------------------------------------------------------*/ -NCURSES_EXPORT(int) -set_menu_pattern (MENU *menu, const char *p) +MENU_EXPORT(int) +set_menu_pattern(MENU *menu, const char *p) { ITEM *matchitem; - int matchpos; - - if (!menu || !p) + int matchpos; + + T((T_CALLED("set_menu_pattern(%p,%s)"), (void *)menu, _nc_visbuf(p))); + + if (!menu || !p) RETURN(E_BAD_ARGUMENT); - + if (!(menu->items)) RETURN(E_NOT_CONNECTED); - - if ( menu->status & _IN_DRIVER ) + + if (menu->status & _IN_DRIVER) RETURN(E_BAD_STATE); - + Reset_Pattern(menu); - + if (!(*p)) { pos_menu_cursor(menu); RETURN(E_OK); } - - if (menu->status & _LINK_NEEDED) + + if (menu->status & _LINK_NEEDED) _nc_Link_Items(menu); - - matchpos = menu->toprow; + + matchpos = menu->toprow; matchitem = menu->curitem; assert(matchitem); - - while(*p) + + while (*p) { - if ( !isprint((unsigned char)(*p)) || - (_nc_Match_Next_Character_In_Item_Name(menu,*p,&matchitem) != E_OK) ) + if (!isprint(UChar(*p)) || + (_nc_Match_Next_Character_In_Item_Name(menu, *p, &matchitem) != E_OK)) { Reset_Pattern(menu); pos_menu_cursor(menu); RETURN(E_NO_MATCH); } p++; - } - + } + /* This is reached if there was a match. So we position to the new item */ - Adjust_Current_Item(menu,matchpos,matchitem); + Adjust_Current_Item(menu, matchpos, matchitem); RETURN(E_OK); }