From: Yann Dirson Date: Thu, 17 Oct 2013 20:46:54 +0000 (+0200) Subject: Convert more stuff from #ifdef to dspwrappers: GetString. X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=de68af0b286eb210b5a3fb4bf4deb44b1b7a727e;p=gnushogi.git Convert more stuff from #ifdef to dspwrappers: GetString. Thin function is the first non-void one and shows the limits of the current macro set. Let's consider this stuff to be temporary. At least it finally allows to drop #include from commondsp. --- diff --git a/gnushogi/commondsp.c b/gnushogi/commondsp.c index 7987307..53efa2b 100644 --- a/gnushogi/commondsp.c +++ b/gnushogi/commondsp.c @@ -42,7 +42,6 @@ #include #include -#include #include "gnushogi.h" char mvstr[4][6]; @@ -1641,23 +1640,12 @@ InputCommand(char *command) have_shown_prompt = false; #endif /* QUIETBACKGROUND */ - if (command == NULL) - { + if (command == NULL) { if (NOT_CURSES) - { - s[0] = sx[0] = '\0'; + s[0] = '\0'; - while(!eof && !sx[0]) - eof = (fgets(sx, 80, stdin) == NULL); - } - else - { - fflush(stdout); - eof = (getstr(sx) == ERR); - } - } - else - { + eof = GetString(sx); + } else { strcpy(sx, command); done = true; } diff --git a/gnushogi/cursesdsp.c b/gnushogi/cursesdsp.c index 0deb256..d71aa63 100644 --- a/gnushogi/cursesdsp.c +++ b/gnushogi/cursesdsp.c @@ -181,6 +181,14 @@ Curses_doRequestInputString(const char* fmt, char* buffer) } +int +Curses_GetString(char* sx) +{ + fflush(stdout); + return (getstr(sx) == ERR); +} + + void Curses_ShowNodeCnt(long NodeCnt) { diff --git a/gnushogi/cursesdsp.h b/gnushogi/cursesdsp.h index 4f9fd68..7031bd4 100644 --- a/gnushogi/cursesdsp.h +++ b/gnushogi/cursesdsp.h @@ -62,6 +62,7 @@ void Curses_ShowMessage(char *s); void Curses_AlwaysShowMessage(const char *format, ...); void Curses_Printf(const char *format, ...); void Curses_doRequestInputString(const char* fmt, char* buffer); +int Curses_GetString(char* sx); void Curses_ShowPatternCount(short side, short n); void Curses_ShowPostnValue(short sq); void Curses_ShowPostnValues(void); diff --git a/gnushogi/dspwrappers.c b/gnushogi/dspwrappers.c index 382c438..ebe0f05 100644 --- a/gnushogi/dspwrappers.c +++ b/gnushogi/dspwrappers.c @@ -126,3 +126,32 @@ void RequestInputString(char* buffer, unsigned bufsize) } doRequestInputString(fmt, buffer); } + +/*********/ + +#define CASE_DSPFUNC_RAW(func,args) \ + case DISPLAY_RAW: \ + case DISPLAY_X: \ + return (func args); \ + break + +#ifdef HAVE_LIBCURSES +#define CASE_DSPFUNC_CURSES(func,args) \ + case DISPLAY_CURSES: \ + return (func args); \ + break; +#else +#define CASE_DSPFUNC_CURSES(func,args) +#endif + +#define DISPLAY_INTFUNC(func,argsdecl,args) \ + int func argsdecl \ + { \ + switch (display_type) { \ + CASE_DSPFUNC_RAW(Raw_ ## func, args); \ + CASE_DSPFUNC_CURSES(Curses_ ## func, args); \ + } \ + assert(0); \ + } + +DISPLAY_INTFUNC(GetString, (char* sx), (sx)) diff --git a/gnushogi/dspwrappers.h b/gnushogi/dspwrappers.h index c1fe649..e563982 100644 --- a/gnushogi/dspwrappers.h +++ b/gnushogi/dspwrappers.h @@ -60,6 +60,7 @@ extern void ShowMessage(char *s); extern void AlwaysShowMessage(const char *format, ...); extern void Printf(const char *format, ...); extern void RequestInputString(char* buffer, unsigned bufsize); +extern int GetString(char* sx); extern void ShowPatternCount(short side, short n); extern void ShowPostnValue(short sq); extern void ShowPostnValues(void); diff --git a/gnushogi/rawdsp.c b/gnushogi/rawdsp.c index 328d80d..cbbfe52 100644 --- a/gnushogi/rawdsp.c +++ b/gnushogi/rawdsp.c @@ -148,6 +148,18 @@ Raw_doRequestInputString(const char* fmt, char* buffer) } +int +Raw_GetString(char* sx) +{ + int eof = 0; + sx[0] = '\0'; + + while(!eof && !sx[0]) + eof = (fgets(sx, 80, stdin) == NULL); + return eof; +} + + void Raw_ShowNodeCnt(long NodeCnt) { diff --git a/gnushogi/rawdsp.h b/gnushogi/rawdsp.h index 52915e4..758ee26 100644 --- a/gnushogi/rawdsp.h +++ b/gnushogi/rawdsp.h @@ -62,6 +62,7 @@ void Raw_ShowMessage(char *s); void Raw_AlwaysShowMessage(const char *format, ...); void Raw_Printf(const char *format, ...); void Raw_doRequestInputString(const char* fmt, char* buffer); +int Raw_GetString(char* sx); void Raw_ShowPatternCount(short side, short n); void Raw_ShowPostnValue(short sq); void Raw_ShowPostnValues(void);