X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=gamelist.c;h=e7a2b4c2520fb49dac6fa4e6c6f37eb98a985183;hb=2b546bdf3126bdacdeb9d40f34cfbbc1cb163db5;hp=da123a47554b3f880eb7151b7ca9c1eb561d678e;hpb=08b22226292c25c7eba27a1ed4e7fb2edf580ec9;p=xboard.git diff --git a/gamelist.c b/gamelist.c index da123a4..e7a2b4c 100644 --- a/gamelist.c +++ b/gamelist.c @@ -56,6 +56,64 @@ static ListGame *GameListCreate P((void)); static void GameListFree P((List *)); static int GameListNewGame P((ListGame **)); +/* [AS] Wildcard pattern matching */ +Boolean +HasPattern( const char * text, const char * pattern ) +{ + while( *pattern != '\0' ) { + if( *pattern == '*' ) { + while( *pattern == '*' ) { + pattern++; + } + + if( *pattern == '\0' ) { + return TRUE; + } + + while( *text != '\0' ) { + if( HasPattern( text, pattern ) ) { + return TRUE; + } + text++; + } + } + else if( (*pattern == *text) || ((*pattern == '?') && (*text != '\0')) ) { + pattern++; + text++; + continue; + } + + return FALSE; + } + + return TRUE; +} + +Boolean +SearchPattern( const char * text, const char * pattern ) +{ + Boolean result = TRUE; + + if( pattern != NULL && *pattern != '\0' ) { + if( *pattern == '*' ) { + result = HasPattern( text, pattern ); + } + else { + result = FALSE; + + while( *text != '\0' ) { + if( HasPattern( text, pattern ) ) { + result = TRUE; + break; + } + text++; + } + } + } + + return result; +} + /* Delete a ListGame; implies removint it from a list. */ static void GameListDeleteGame(listGame)