fixes inappropriate use of EXIT_ macros + adds a sample PGN file

Tue, 28 Aug 2018 14:16:30 +0200

author
Mike Becker <universe@uap-core.de>
date
Tue, 28 Aug 2018 14:16:30 +0200
changeset 59
3fa1de896666
parent 58
7ba8a97a8b6e
child 60
0c50aac49e55

fixes inappropriate use of EXIT_ macros + adds a sample PGN file

Fischer-Spassky-1992.pgn file | annotate | diff | comparison | revisions
src/chess/pgn.c file | annotate | diff | comparison | revisions
src/chess/pgn.h file | annotate | diff | comparison | revisions
src/client.c file | annotate | diff | comparison | revisions
src/game.c file | annotate | diff | comparison | revisions
src/network.c file | annotate | diff | comparison | revisions
src/server.c file | annotate | diff | comparison | revisions
src/terminal-chess.h file | annotate | diff | comparison | revisions
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Fischer-Spassky-1992.pgn	Tue Aug 28 14:16:30 2018 +0200
     1.3 @@ -0,0 +1,17 @@
     1.4 +[Event "F/S Return Match"]
     1.5 +[Site "Belgrade, Serbia JUG"]
     1.6 +[Date "1992.11.04"]
     1.7 +[Round "29"]
     1.8 +[White "Fischer, Robert J."]
     1.9 +[Black "Spassky, Boris V."]
    1.10 +[Result "1/2-1/2"]
    1.11 +
    1.12 +1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 
    1.13 +4. Ba4 Nf6 5. O-O Be7 6. Re1 b5 7. Bb3 d6 8. c3 O-O 9. h3 Nb8 10. d4 Nbd7
    1.14 +11. c4 c6 12. cxb5 axb5 13. Nc3 Bb7 14. Bg5 b4 15. Nb1 h6 16. Bh4 c5 17. dxe5
    1.15 +Nxe4 18. Bxe7 Qxe7 19. exd6 Qf6 20. Nbd2 Nxd6 21. Nc4 Nxc4 22. Bxc4 Nb6
    1.16 +23. Ne5 Rae8 24. Bxf7+ Rxf7 25. Nxf7 Rxe1+ 26. Qxe1 Kxf7 27. Qe3 Qg5 28. Qxg5
    1.17 +hxg5 29. b3 Ke6 30. a3 Kd6 31. axb4 cxb4 32. Ra5 Nd5 33. f3 Bc8 34. Kf2 Bf5
    1.18 +35. Ra7 g6 36. Ra6+ Kc5 37. Ke1 Nf4 38. g3 Nxh3 39. Kd2 Kb5 40. Rd6 Kc5 41. Ra6
    1.19 +Nf2 42. g4 Bd3 43. Re6 1/2-1/2
    1.20 +
     2.1 --- a/src/chess/pgn.c	Tue Aug 28 14:03:09 2018 +0200
     2.2 +++ b/src/chess/pgn.c	Tue Aug 28 14:16:30 2018 +0200
     2.3 @@ -49,7 +49,7 @@
     2.4              break;
     2.5          }
     2.6          if (c != '[') {
     2.7 -            return EXIT_FAILURE;
     2.8 +            return 1;
     2.9          }
    2.10          while (isspace(c = fgetc(stream)));
    2.11          i = 0;
    2.12 @@ -59,18 +59,18 @@
    2.13          tagkey[i] = '\0';
    2.14          while (isspace(c = fgetc(stream)));
    2.15          if (c != '"') {
    2.16 -            return EXIT_FAILURE;
    2.17 +            return 1;
    2.18          }
    2.19          i = 0;
    2.20          while ((c = fgetc(stream)) != '"') {
    2.21              if (c == '\n') {
    2.22 -                return EXIT_FAILURE;
    2.23 +                return 1;
    2.24              }
    2.25              tagvalue[i++] = c;
    2.26          }
    2.27          tagvalue[i] = '\0';
    2.28          if (fgetc(stream) != ']') {
    2.29 -            return EXIT_FAILURE;
    2.30 +            return 1;
    2.31          }
    2.32  
    2.33          if (strcmp("Result", tagkey) == 0) {
    2.34 @@ -80,7 +80,7 @@
    2.35      
    2.36      // read moves
    2.37      if (fgetc(stream) != '.') {
    2.38 -        return EXIT_FAILURE;
    2.39 +        return 1;
    2.40      }
    2.41      
    2.42      char movestr[10];
    2.43 @@ -94,16 +94,16 @@
    2.44          do {
    2.45              movestr[i++] = c;
    2.46              if (i >= 10) {
    2.47 -                return EXIT_FAILURE;
    2.48 +                return 1;
    2.49              }
    2.50          } while (!isspace(c = fgetc(stream)));
    2.51          movestr[i] = '\0';
    2.52          if (eval_move(gamestate, movestr, &move, curcol)
    2.53                  != VALID_MOVE_SYNTAX) {
    2.54 -            return EXIT_FAILURE;
    2.55 +            return 1;
    2.56          }
    2.57          if (validate_move(gamestate, &move) != VALID_MOVE_SEMANTICS) {
    2.58 -            return EXIT_FAILURE;
    2.59 +            return 1;
    2.60          }
    2.61          apply_move(gamestate, &move);
    2.62          
    2.63 @@ -135,13 +135,13 @@
    2.64          if (curcol == BLACK) {
    2.65              while (isdigit(c = fgetc(stream)));
    2.66              if (c != '.') {
    2.67 -                return EXIT_FAILURE;
    2.68 +                return 1;
    2.69              }
    2.70          }
    2.71          curcol = opponent_color(curcol);
    2.72      }
    2.73      
    2.74 -    return EXIT_SUCCESS;
    2.75 +    return 0;
    2.76  }
    2.77  
    2.78  size_t write_pgn(FILE* stream, GameState *gamestate, GameInfo *gameinfo) {
     3.1 --- a/src/chess/pgn.h	Tue Aug 28 14:03:09 2018 +0200
     3.2 +++ b/src/chess/pgn.h	Tue Aug 28 14:16:30 2018 +0200
     3.3 @@ -37,7 +37,7 @@
     3.4  #ifdef	__cplusplus
     3.5  extern "C" {
     3.6  #endif
     3.7 -
     3.8 +    
     3.9  int read_pgn(FILE *stream, GameState *gamestate, GameInfo *gameinfo);
    3.10  size_t write_pgn(FILE* stream, GameState *gamestate, GameInfo *gameinfo);
    3.11  void compute_fen(char *str, GameState *gamestate);
     4.1 --- a/src/client.c	Tue Aug 28 14:03:09 2018 +0200
     4.2 +++ b/src/client.c	Tue Aug 28 14:16:30 2018 +0200
     4.3 @@ -65,12 +65,12 @@
     4.4  
     4.5      if (client_connect(&server, settings->serverhost, settings->port)) {
     4.6          net_destroy(&server);
     4.7 -        return EXIT_FAILURE;
     4.8 +        return 1;
     4.9      }
    4.10  
    4.11      if (client_handshake(&server)) {
    4.12          net_destroy(&server);
    4.13 -        return EXIT_FAILURE;
    4.14 +        return 1;
    4.15      }
    4.16  
    4.17      uint8_t code = net_recieve_code(server.fd);
    4.18 @@ -109,9 +109,9 @@
    4.19      } else {
    4.20          addstr("Server sent invalid gameinfo.");
    4.21          net_destroy(&server);
    4.22 -        return EXIT_FAILURE;
    4.23 +        return 1;
    4.24      }
    4.25      
    4.26      net_destroy(&server);
    4.27 -    return EXIT_SUCCESS;
    4.28 +    return 0;
    4.29  }
     5.1 --- a/src/game.c	Tue Aug 28 14:03:09 2018 +0200
     5.2 +++ b/src/game.c	Tue Aug 28 14:16:30 2018 +0200
     5.3 @@ -499,7 +499,7 @@
     5.4          if (pgnfile) {
     5.5              int result = read_pgn(pgnfile, &gamestate, &(settings->gameinfo));
     5.6              fclose(pgnfile);
     5.7 -            if (result != EXIT_SUCCESS) {
     5.8 +            if (result) {
     5.9                  addstr("Invalid PGN file content.\n");
    5.10                  return;
    5.11              }
     6.1 --- a/src/network.c	Tue Aug 28 14:03:09 2018 +0200
     6.2 +++ b/src/network.c	Tue Aug 28 14:16:30 2018 +0200
     6.3 @@ -111,7 +111,7 @@
     6.4          return shutdown(server->fd, SHUT_RDWR);
     6.5      }
     6.6      
     6.7 -    return EXIT_SUCCESS;
     6.8 +    return 0;
     6.9  }
    6.10  
    6.11  void net_send_code(int socket, uint8_t code) {
     7.1 --- a/src/server.c	Tue Aug 28 14:03:09 2018 +0200
     7.2 +++ b/src/server.c	Tue Aug 28 14:16:30 2018 +0200
     7.3 @@ -75,31 +75,31 @@
     7.4              int result = read_pgn(pgnfile, &continuegame,
     7.5                  &(settings->gameinfo));
     7.6              fclose(pgnfile);
     7.7 -            if (result != EXIT_SUCCESS) {
     7.8 +            if (result) {
     7.9                  addstr("Invalid PGN file content.\n");
    7.10 -                return EXIT_FAILURE;
    7.11 +                return 1;
    7.12              }
    7.13              if (!is_game_running(&continuegame)) {
    7.14                  addstr("Game has ended. Use -S to analyze it.\n");
    7.15 -                return EXIT_FAILURE;
    7.16 +                return 1;
    7.17              }
    7.18              addch('\n');
    7.19              dump_moveinfo(&continuegame);
    7.20              addch('\n');
    7.21          } else {
    7.22              printw("Can't read PGN file (%s)\n", strerror(errno));
    7.23 -            return EXIT_FAILURE;
    7.24 +            return 1;
    7.25          }
    7.26      }
    7.27      
    7.28      if (server_open(&server, settings->port)) {
    7.29          net_destroy(&server);
    7.30 -        return EXIT_FAILURE;
    7.31 +        return 1;
    7.32      }
    7.33      
    7.34      if (server_handshake(server.client)) {
    7.35          net_destroy(&server);
    7.36 -        return EXIT_FAILURE;
    7.37 +        return 1;
    7.38      }
    7.39  
    7.40      int fd = server.client->fd;
    7.41 @@ -157,9 +157,9 @@
    7.42          clrtoeol();
    7.43          
    7.44          net_destroy(&server);
    7.45 -        return EXIT_FAILURE;
    7.46 +        return 1;
    7.47      }
    7.48      
    7.49      net_destroy(&server);
    7.50 -    return EXIT_SUCCESS;
    7.51 +    return 0;
    7.52  }
     8.1 --- a/src/terminal-chess.h	Tue Aug 28 14:03:09 2018 +0200
     8.2 +++ b/src/terminal-chess.h	Tue Aug 28 14:16:30 2018 +0200
     8.3 @@ -36,7 +36,7 @@
     8.4  #ifndef TERMINAL_CHESS_H
     8.5  #define	TERMINAL_CHESS_H
     8.6  
     8.7 -#define PROGRAM_VERSION "0.9-r56"
     8.8 +#define PROGRAM_VERSION "0.9-r59"
     8.9  
    8.10  #ifdef	__cplusplus
    8.11  extern "C" {

mercurial