From 2b546bdf3126bdacdeb9d40f34cfbbc1cb163db5 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Sat, 23 Jan 2010 21:42:38 +0100 Subject: [PATCH] Move duplicat gamelist code to backend The filtering routines are moved from xgamelist.c and wgamelist.c to gamelist.c, and a prototype for them is placed in backend.h. --- backend.h | 2 + gamelist.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ winboard/wgamelist.c | 56 ------------------------------------------------ xgamelist.c | 56 ------------------------------------------------ 4 files changed, 60 insertions(+), 112 deletions(-) diff --git a/backend.h b/backend.h index 18f5c58..6899eef 100644 --- a/backend.h +++ b/backend.h @@ -121,6 +121,8 @@ int PieceForSquare P((int x, int y)); int OKToStartUserMove P((int x, int y)); void Reset P((int redraw, int init)); void ResetGameEvent P((void)); +Boolean HasPattern P(( const char * text, const char * pattern )); +Boolean SearchPattern P(( const char * text, const char * pattern )); int LoadGame P((FILE *f, int n, char *title, int useList)); int LoadGameFromFile P((char *filename, int n, char *title, int useList)); int CmailLoadGame P((FILE *f, int n, char *title, int useList)); 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) diff --git a/winboard/wgamelist.c b/winboard/wgamelist.c index 31d36ff..c9ae1b5 100644 --- a/winboard/wgamelist.c +++ b/winboard/wgamelist.c @@ -54,62 +54,6 @@ struct GameListStats int unfinished; }; -/* [AS] Wildcard pattern matching */ -static BOOL 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; -} - -static BOOL SearchPattern( const char * text, const char * pattern ) -{ - BOOL 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; -} - /* [AS] Setup the game list according to the specified filter */ static int GameListToListBox( HWND hDlg, BOOL boReset, char * pszFilter, struct GameListStats * stats ) { diff --git a/xgamelist.c b/xgamelist.c index f92a473..258eb39 100644 --- a/xgamelist.c +++ b/xgamelist.c @@ -123,62 +123,6 @@ static Arg layoutArgs[] = { { XtNdefaultDistance, 0 } }; -/* [AS] Wildcard pattern matching */ -static 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; -} - -static 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; -} - Widget GameListCreate(name, callback, client_data) char *name; -- 1.7.0.4