X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=gnushogi%2Frawdsp.c;h=54bb7a1e16fee4205959e6e899a903252edde1cb;hb=55f7af8b6f1e57eaf349a52ccde05e5f86c61905;hp=e8e7b9809bd026c793f6a1fc6b639989401c8a4d;hpb=829c253a7cc2d3e1a9ed643485c1b1a92967b5df;p=gnushogi.git diff --git a/gnushogi/rawdsp.c b/gnushogi/rawdsp.c index e8e7b98..54bb7a1 100644 --- a/gnushogi/rawdsp.c +++ b/gnushogi/rawdsp.c @@ -4,6 +4,7 @@ * ---------------------------------------------------------------------- * Copyright (c) 1993, 1994, 1995 Matthias Mutz * Copyright (c) 1999 Michael Vanier and the Free Software Foundation + * Copyright (c) 2008, 2013, 2014 Yann Dirson and the Free Software Foundation * * GNU SHOGI is based on GNU CHESS * @@ -35,8 +36,10 @@ #include #include #include +#ifndef WIN32 #include #include +#endif #include "gnushogi.h" #include "rawdsp.h" @@ -217,15 +220,20 @@ Raw_Initialize(void) if (XSHOGI) { -#ifdef HAVE_SETLINEBUF - setlinebuf(stdout); +#ifdef WIN32 + /* needed because of inconsistency between MSVC run-time system and gcc includes */ + setbuf(stdout, NULL); #else -# ifdef HAVE_SETVBUF +#ifdef HAVE_SETVBUF setvbuf(stdout, NULL, _IOLBF, BUFSIZ); +#else +# ifdef HAVE_SETLINEBUF + setlinebuf(stdout); # else -# error "Need setlinebuf() or setvbuf() to compile gnushogi!" +# error "Need setvbuf() or setlinebuf() to compile gnushogi!" # endif #endif +#endif printf("GNU Shogi %s\n", PACKAGE_VERSION); } @@ -334,18 +342,21 @@ Raw_EditBoard(void) Book = BOOKFAIL; Raw_ClearScreen(); Raw_UpdateDisplay(0, 0, 1, 0); - fputs(". Exit to main\n", stdout); - fputs("# Clear board\n", stdout); - fputs("c Change sides\n", stdout); - fputs("enter piece & location: \n", stdout); + printf(". Exit to main\n"); + printf("# Clear board\n"); + printf("c Change sides\n"); + printf("enter piece & location:\n"); a = black; - do + while(1) { scanf("%s", s); found = 0; + if (s[0] == '.') + break; + if (s[0] == '#') { for (sq = 0; sq < NO_SQUARES; sq++) @@ -355,10 +366,13 @@ Raw_EditBoard(void) } ClearCaptured(); + continue; } - if (s[0] == 'c') + if (s[0] == 'c') { a = otherside[a]; + continue; + } if (s[1] == '*') { @@ -371,41 +385,39 @@ Raw_EditBoard(void) break; } } - - c = -1; - r = -1; + if (!found) + printf("# Invalid piece type '%c'\n", s[0]); + continue; } - else - { - c = COL_NAME(s[1]); - r = ROW_NAME(s[2]); + + c = COL_NUM(s[1]); + r = ROW_NUM(s[2]); + + if ((c < 0) || (c >= NO_COLS) || (r < 0) || (r >= NO_ROWS)) { + printf("# Out-of-board position '%c%c'\n", s[1], s[2]); + continue; } - if ((c >= 0) && (c < NO_COLS) && (r >= 0) && (r < NO_ROWS)) - { - sq = locn(r, c); - color[sq] = a; - board[sq] = no_piece; + sq = locn(r, c); - for (i = no_piece; i <= king; i++) + for (i = no_piece; i <= king; i++) + { + if ((s[0] == pxx[i]) || (s[0] == qxx[i])) { - if ((s[0] == pxx[i]) || (s[0] == qxx[i])) - { - if (s[3] == '+') - board[sq] = promoted[i]; - else - board[sq] = i; + color[sq] = a; + if (s[3] == '+') + board[sq] = promoted[i]; + else + board[sq] = i; - found = 1; - break; - } + found = 1; + break; } - - if (found == 0) - color[sq] = neutral; } + + if (!found) + printf("# Invalid piece type '%c'\n", s[0]); } - while (s[0] != '.'); for (sq = 0; sq < NO_SQUARES; sq++) Mvboard[sq] = ((board[sq] != Stboard[sq]) ? 10 : 0); @@ -944,6 +956,11 @@ Raw_ShowPostnValues(void) void Raw_PollForInput(void) { +#ifdef WIN32 + DWORD cnt; + if (!PeekNamedPipe(GetStdHandle(STD_INPUT_HANDLE), NULL, 0, NULL, &cnt, NULL)) + cnt = 1; +#else static struct pollfd pollfds[1] = { /* [0] = */ { /* .fd = */ STDIN_FILENO, /* .events = */ POLLIN } }; int cnt = poll(pollfds, sizeof(pollfds)/sizeof(pollfds[0]), 0); @@ -951,6 +968,7 @@ Raw_PollForInput(void) perror("polling standard input"); ExitShogi(); } +#endif if (cnt) { /* if anything to read, or error occured */ if (!flag.timeout) flag.back = true; /* previous: flag.timeout = true; */