From 1be442641b610fa1b6172a38d9acffe2d22797b6 Mon Sep 17 00:00:00 2001 From: Yann Dirson Date: Tue, 15 Oct 2013 22:41:09 +0200 Subject: [PATCH] Convert more stuff from #ifdef to dspwrappers. --- gnushogi/commondsp.c | 84 +++++++---------------------------------------- gnushogi/cursesdsp.c | 19 +++++++++++ gnushogi/cursesdsp.h | 2 + gnushogi/dspwrappers.c | 16 +++++++++ gnushogi/dspwrappers.h | 2 + gnushogi/rawdsp.c | 17 ++++++++++ gnushogi/rawdsp.h | 2 + 7 files changed, 71 insertions(+), 71 deletions(-) diff --git a/gnushogi/commondsp.c b/gnushogi/commondsp.c index c00338a..36cc789 100644 --- a/gnushogi/commondsp.c +++ b/gnushogi/commondsp.c @@ -164,12 +164,8 @@ algbr(short f, short t, short flag) if ((f == t) && ((f != 0) || (t != 0))) { - if (!barebones) - { - if (NOT_CURSES) - printf("error in algbr: FROM=TO=%d, flag=0x%4x\n", t, flag); - else - printw("error in algbr: FROM=TO=%d, flag=0x%4x\n", t, flag); + if (!barebones) { + Printf("error in algbr: FROM=TO=%d, flag=0x%4x\n", t, flag); } mvstr[0][0] = mvstr[1][0] = mvstr[2][0] = mvstr[3][0] = '\0'; @@ -448,24 +444,12 @@ GetGame(void) short sq; short side, isp; - if (savefile[0]) - { + if (savefile[0]) { strcpy(fname, savefile); - } - else - { + } else { /* Enter file name */ ShowMessage(CP[63]); - - if (NOT_CURSES) - { - scanf("%s", fname); - } - else - { - fflush(stdout); - scanw("%s", fname); - } + RequestInputString(fname); } /* shogi.000 */ @@ -685,24 +669,12 @@ SaveGame(void) short side, piece; char empty[2] = "\n"; - if (savefile[0]) - { + if (savefile[0]) { strcpy(fname, savefile); - } - else - { + } else { /* Enter file name */ ShowMessage(CP[63]); - - if (NOT_CURSES) - { - scanf("%s", fname); - } - else - { - fflush(stdout); - scanw("%s", fname); - } + RequestInputString(fname); } if (fname[0] == '\0') /* shogi.000 */ @@ -846,16 +818,7 @@ GetXGame(void) /* Enter file name */ ShowMessage(CP[63]); - - if (NOT_CURSES) - { - scanf("%s", fname); - } - else - { - fflush(stdout); - scanw("%s", fname); - } + RequestInputString(fname); if (fname[0] == '\0') /* XSHOGI.position.read */ strcpy(fname, CP[205]); @@ -983,16 +946,7 @@ SaveXGame(void) /* Enter file name */ ShowMessage(CP[63]); - - if (NOT_CURSES) - { - scanf("%s", fname); - } - else - { - fflush(stdout); - scanw("%s", fname); - } + RequestInputString(fname); if (fname[0] == '\0') /* XSHOGI.position.read */ strcpy(fname, CP[205]); @@ -1065,24 +1019,12 @@ BookSave(void) char fname[256], sflags[4]; short i, j, f, t; - if (savefile[0]) - { + if (savefile[0]) { strcpy(fname, savefile); - } - else - { + } else { /* Enter file name */ ShowMessage(CP[63]); - - if (NOT_CURSES) - { - scanf("%s", fname); - } - else - { - fflush(stdout); - scanw("%s", fname); - } + RequestInputString(fname); } if (fname[0] == '\0') diff --git a/gnushogi/cursesdsp.c b/gnushogi/cursesdsp.c index f4c00ec..dd6b10f 100644 --- a/gnushogi/cursesdsp.c +++ b/gnushogi/cursesdsp.c @@ -150,6 +150,25 @@ Curses_ShowMessage(char *s) void +Curses_Printf(const char *format, ...) +{ + static char buffer[60]; + va_list ap; + va_start(ap, format); + vsnprintf(buffer, sizeof(buffer), format, ap); + printw("%s", buffer); + va_end(ap); +} + + +void +Curses_RequestInputString(char* buffer) +{ + FLUSH_SCANW("%s", buffer); +} + + +void ShowNodeCnt(long NodeCnt) { gotoXY(TAB, 22); diff --git a/gnushogi/cursesdsp.h b/gnushogi/cursesdsp.h index 83afbd8..a83338f 100644 --- a/gnushogi/cursesdsp.h +++ b/gnushogi/cursesdsp.h @@ -58,6 +58,8 @@ void Curses_ShowDepth(char ch); void Curses_ShowGameType(void); void Curses_ShowLine(unsigned short *bstline); void Curses_ShowMessage(char *s); +void Curses_Printf(const char *format, ...); +void Curses_RequestInputString(char* buffer); 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 7590dcb..10b06b4 100644 --- a/gnushogi/dspwrappers.c +++ b/gnushogi/dspwrappers.c @@ -37,6 +37,8 @@ #include "rawdsp.h" #include "cursesdsp.h" +#include + #define CASE_DSP_RAW(func,args) \ case DISPLAY_RAW: \ case DISPLAY_X: \ @@ -63,6 +65,18 @@ #define DISPLAY_VOIDFUNC(func) \ DISPLAY_FUNC(func,(void),()) +#define DISPLAY_STDARGFUNC(func,argsdecl,last,args) \ + void func argsdecl \ + { \ + va_list ap; \ + va_start(ap, last); \ + switch (display_type) { \ + CASE_DSP_RAW(Raw_ ## func, args); \ + CASE_DSP_CURSES(Curses_ ## func, args); \ + } \ + va_end(ap); \ + } + DISPLAY_VOIDFUNC(ChangeAlphaWindow) DISPLAY_VOIDFUNC(ChangeBetaWindow) DISPLAY_VOIDFUNC(ChangeHashDepth) @@ -84,6 +98,8 @@ DISPLAY_FUNC(ShowDepth, (char ch), (ch)) DISPLAY_VOIDFUNC(ShowGameType) DISPLAY_FUNC(ShowLine, (unsigned short *bstline), (bstline)) DISPLAY_FUNC(ShowMessage, (char *s), (s)) +DISPLAY_STDARGFUNC(Printf, (const char *format, ...), format, (format, ap)) +DISPLAY_FUNC(RequestInputString, (char* buffer), (buffer)) DISPLAY_FUNC(ShowPatternCount, (short side, short n), (side, n)) DISPLAY_FUNC(ShowPostnValue, (short sq), (sq)) DISPLAY_VOIDFUNC(ShowPostnValues) diff --git a/gnushogi/dspwrappers.h b/gnushogi/dspwrappers.h index b99c211..a1d4f17 100644 --- a/gnushogi/dspwrappers.h +++ b/gnushogi/dspwrappers.h @@ -56,6 +56,8 @@ extern void ShowDepth(char ch); extern void ShowGameType(void); extern void ShowLine(unsigned short *bstline); extern void ShowMessage(char *s); +extern void Printf(const char *format, ...); +extern void RequestInputString(char* buffer); 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 27e558c..e073bae 100644 --- a/gnushogi/rawdsp.c +++ b/gnushogi/rawdsp.c @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -123,6 +124,22 @@ Raw_ShowMessage(char *s) void +Raw_Printf(const char *format, ...) +{ + va_list ap; + va_start(ap, format); + vprintf(format, ap); + va_end(ap); +} + +void +Raw_RequestInputString(char* buffer) +{ + scanf("%s", buffer); +} + + +void Raw_ShowPatternCount(short side, short n) { if (flag.post) diff --git a/gnushogi/rawdsp.h b/gnushogi/rawdsp.h index 989c6fc..9f22a6b 100644 --- a/gnushogi/rawdsp.h +++ b/gnushogi/rawdsp.h @@ -58,6 +58,8 @@ void Raw_ShowDepth(char ch); void Raw_ShowGameType(void); void Raw_ShowLine(unsigned short *bstline); void Raw_ShowMessage(char *s); +void Raw_Printf(const char *format, ...); +void Raw_RequestInputString(char* buffer); void Raw_ShowPatternCount(short side, short n); void Raw_ShowPostnValue(short sq); void Raw_ShowPostnValues(void); -- 1.7.0.4