# HG changeset patch # User Mike Becker # Date 1397124609 -7200 # Node ID bcf624518909d9392bf440fd4177e2a67b6cb007 # Parent ebe0c961e9a68ca1018353f2f024f689c3414f99 minor improvements by using macros diff -r ebe0c961e9a6 -r bcf624518909 src/game.c --- a/src/game.c Thu Apr 10 11:44:55 2014 +0200 +++ b/src/game.c Thu Apr 10 12:10:09 2014 +0200 @@ -172,11 +172,12 @@ } } +#define MOVESTR_BUFLEN 8 static int domove_singlemachine(GameState *gamestate, GameInfo *gameinfo) { - const size_t buflen = 8; + size_t bufpos = 0; - char movestr[buflen]; + char movestr[MOVESTR_BUFLEN]; flushinp(); while (1) { @@ -191,14 +192,14 @@ "Type your move: "); clrtoeol(); - if (asyncgetnstr(movestr, &bufpos, buflen)) { - if (strncmp(movestr, "surr", buflen) == 0) { + if (asyncgetnstr(movestr, &bufpos, MOVESTR_BUFLEN)) { + if (strncmp(movestr, "surr", MOVESTR_BUFLEN) == 0) { printw("%s surrendered!", gamestate->mycolor==WHITE?"White":"Black"); clrtoeol(); refresh(); return 1; - } else if (strncmp(movestr, "remis", buflen) == 0) { + } else if (strncmp(movestr, "remis", MOVESTR_BUFLEN) == 0) { printw("Game ends remis."); clrtoeol(); refresh(); @@ -236,9 +237,8 @@ static int sendmove(GameState *gamestate, GameInfo *gameinfo, int opponent) { - const size_t buflen = 8; size_t bufpos = 0; - char movestr[buflen]; + char movestr[MOVESTR_BUFLEN]; _Bool remisrejected = FALSE; uint8_t code; @@ -263,14 +263,14 @@ } clrtoeol(); - if (asyncgetnstr(movestr, &bufpos, buflen)) { - if (strncmp(movestr, "surr", buflen) == 0) { + if (asyncgetnstr(movestr, &bufpos, MOVESTR_BUFLEN)) { + if (strncmp(movestr, "surr", MOVESTR_BUFLEN) == 0) { printw("You surrendered!"); clrtoeol(); refresh(); net_send_code(opponent, NETCODE_SURRENDER); return 1; - } else if (strncmp(movestr, "remis", buflen) == 0) { + } else if (strncmp(movestr, "remis", MOVESTR_BUFLEN) == 0) { if (!remisrejected) { net_send_code(opponent, NETCODE_REMIS); printw("Remis offer sent - waiting for acceptance..."); diff -r ebe0c961e9a6 -r bcf624518909 src/input.h --- a/src/input.h Thu Apr 10 11:44:55 2014 +0200 +++ b/src/input.h Thu Apr 10 12:10:09 2014 +0200 @@ -79,8 +79,8 @@ * @param len the length of the buffer * @return 0 if reading is in progress and 1 when a complete line is read */ -#define asyncgetnstr(str,pos,len) mvwasyncgetnstr(stdscr, stdscr->_cury, \ - stdscr->_curx, str, pos, len) +#define asyncgetnstr(str,pos,len) mvwasyncgetnstr(stdscr, getcury(stdscr), \ + getcurx(stdscr), str, pos, len) #ifdef __cplusplus