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
     1.1 --- a/src/game.c	Thu Apr 10 11:44:55 2014 +0200
     1.2 +++ b/src/game.c	Thu Apr 10 12:10:09 2014 +0200
     1.3 @@ -172,11 +172,12 @@
     1.4      }
     1.5  }
     1.6  
     1.7 +#define MOVESTR_BUFLEN 8
     1.8  static int domove_singlemachine(GameState *gamestate, GameInfo *gameinfo) {
     1.9      
    1.10 -    const size_t buflen = 8;
    1.11 +
    1.12      size_t bufpos = 0;
    1.13 -    char movestr[buflen];
    1.14 +    char movestr[MOVESTR_BUFLEN];
    1.15      
    1.16      flushinp();
    1.17      while (1) {
    1.18 @@ -191,14 +192,14 @@
    1.19              "Type your move: ");
    1.20          clrtoeol();
    1.21          
    1.22 -        if (asyncgetnstr(movestr, &bufpos, buflen)) {
    1.23 -            if (strncmp(movestr, "surr", buflen) == 0) {
    1.24 +        if (asyncgetnstr(movestr, &bufpos, MOVESTR_BUFLEN)) {
    1.25 +            if (strncmp(movestr, "surr", MOVESTR_BUFLEN) == 0) {
    1.26                  printw("%s surrendered!",
    1.27                      gamestate->mycolor==WHITE?"White":"Black");
    1.28                  clrtoeol();
    1.29                  refresh();
    1.30                  return 1;
    1.31 -            } else if (strncmp(movestr, "remis", buflen) == 0) {
    1.32 +            } else if (strncmp(movestr, "remis", MOVESTR_BUFLEN) == 0) {
    1.33                  printw("Game ends remis.");
    1.34                  clrtoeol();
    1.35                  refresh();
    1.36 @@ -236,9 +237,8 @@
    1.37  
    1.38  static int sendmove(GameState *gamestate, GameInfo *gameinfo, int opponent) {
    1.39      
    1.40 -    const size_t buflen = 8;
    1.41      size_t bufpos = 0;
    1.42 -    char movestr[buflen];
    1.43 +    char movestr[MOVESTR_BUFLEN];
    1.44      _Bool remisrejected = FALSE;
    1.45      uint8_t code;
    1.46      
    1.47 @@ -263,14 +263,14 @@
    1.48          }
    1.49          clrtoeol();
    1.50          
    1.51 -        if (asyncgetnstr(movestr, &bufpos, buflen)) {
    1.52 -            if (strncmp(movestr, "surr", buflen) == 0) {
    1.53 +        if (asyncgetnstr(movestr, &bufpos, MOVESTR_BUFLEN)) {
    1.54 +            if (strncmp(movestr, "surr", MOVESTR_BUFLEN) == 0) {
    1.55                  printw("You surrendered!");
    1.56                  clrtoeol();
    1.57                  refresh();
    1.58                  net_send_code(opponent, NETCODE_SURRENDER);
    1.59                  return 1;
    1.60 -            } else if (strncmp(movestr, "remis", buflen) == 0) {
    1.61 +            } else if (strncmp(movestr, "remis", MOVESTR_BUFLEN) == 0) {
    1.62                  if (!remisrejected) {
    1.63                      net_send_code(opponent, NETCODE_REMIS);
    1.64                      printw("Remis offer sent - waiting for acceptance...");
     2.1 --- a/src/input.h	Thu Apr 10 11:44:55 2014 +0200
     2.2 +++ b/src/input.h	Thu Apr 10 12:10:09 2014 +0200
     2.3 @@ -79,8 +79,8 @@
     2.4   * @param len the length of the buffer
     2.5   * @return 0 if reading is in progress and 1 when a complete line is read
     2.6   */
     2.7 -#define asyncgetnstr(str,pos,len) mvwasyncgetnstr(stdscr, stdscr->_cury, \
     2.8 -    stdscr->_curx, str, pos, len)
     2.9 +#define asyncgetnstr(str,pos,len) mvwasyncgetnstr(stdscr, getcury(stdscr), \
    2.10 +    getcurx(stdscr), str, pos, len)
    2.11  
    2.12  
    2.13  #ifdef	__cplusplus

mercurial