minor improvements by using macros

Thu, 10 Apr 2014 12:10:09 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 10 Apr 2014 12:10:09 +0200
changeset 37
bcf624518909
parent 36
ebe0c961e9a6
child 38
75ee459ba941

minor improvements by using macros

src/game.c file | annotate | diff | comparison | revisions
src/input.h file | annotate | diff | comparison | revisions
--- 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...");
--- 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

mercurial