Tue, 28 Aug 2018 14:16:30 +0200
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 |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Fischer-Spassky-1992.pgn Tue Aug 28 14:16:30 2018 +0200 @@ -0,0 +1,17 @@ +[Event "F/S Return Match"] +[Site "Belgrade, Serbia JUG"] +[Date "1992.11.04"] +[Round "29"] +[White "Fischer, Robert J."] +[Black "Spassky, Boris V."] +[Result "1/2-1/2"] + +1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 +4. Ba4 Nf6 5. O-O Be7 6. Re1 b5 7. Bb3 d6 8. c3 O-O 9. h3 Nb8 10. d4 Nbd7 +11. c4 c6 12. cxb5 axb5 13. Nc3 Bb7 14. Bg5 b4 15. Nb1 h6 16. Bh4 c5 17. dxe5 +Nxe4 18. Bxe7 Qxe7 19. exd6 Qf6 20. Nbd2 Nxd6 21. Nc4 Nxc4 22. Bxc4 Nb6 +23. Ne5 Rae8 24. Bxf7+ Rxf7 25. Nxf7 Rxe1+ 26. Qxe1 Kxf7 27. Qe3 Qg5 28. Qxg5 +hxg5 29. b3 Ke6 30. a3 Kd6 31. axb4 cxb4 32. Ra5 Nd5 33. f3 Bc8 34. Kf2 Bf5 +35. Ra7 g6 36. Ra6+ Kc5 37. Ke1 Nf4 38. g3 Nxh3 39. Kd2 Kb5 40. Rd6 Kc5 41. Ra6 +Nf2 42. g4 Bd3 43. Re6 1/2-1/2 +
--- a/src/chess/pgn.c Tue Aug 28 14:03:09 2018 +0200 +++ b/src/chess/pgn.c Tue Aug 28 14:16:30 2018 +0200 @@ -49,7 +49,7 @@ break; } if (c != '[') { - return EXIT_FAILURE; + return 1; } while (isspace(c = fgetc(stream))); i = 0; @@ -59,18 +59,18 @@ tagkey[i] = '\0'; while (isspace(c = fgetc(stream))); if (c != '"') { - return EXIT_FAILURE; + return 1; } i = 0; while ((c = fgetc(stream)) != '"') { if (c == '\n') { - return EXIT_FAILURE; + return 1; } tagvalue[i++] = c; } tagvalue[i] = '\0'; if (fgetc(stream) != ']') { - return EXIT_FAILURE; + return 1; } if (strcmp("Result", tagkey) == 0) { @@ -80,7 +80,7 @@ // read moves if (fgetc(stream) != '.') { - return EXIT_FAILURE; + return 1; } char movestr[10]; @@ -94,16 +94,16 @@ do { movestr[i++] = c; if (i >= 10) { - return EXIT_FAILURE; + return 1; } } while (!isspace(c = fgetc(stream))); movestr[i] = '\0'; if (eval_move(gamestate, movestr, &move, curcol) != VALID_MOVE_SYNTAX) { - return EXIT_FAILURE; + return 1; } if (validate_move(gamestate, &move) != VALID_MOVE_SEMANTICS) { - return EXIT_FAILURE; + return 1; } apply_move(gamestate, &move); @@ -135,13 +135,13 @@ if (curcol == BLACK) { while (isdigit(c = fgetc(stream))); if (c != '.') { - return EXIT_FAILURE; + return 1; } } curcol = opponent_color(curcol); } - return EXIT_SUCCESS; + return 0; } size_t write_pgn(FILE* stream, GameState *gamestate, GameInfo *gameinfo) {
--- a/src/chess/pgn.h Tue Aug 28 14:03:09 2018 +0200 +++ b/src/chess/pgn.h Tue Aug 28 14:16:30 2018 +0200 @@ -37,7 +37,7 @@ #ifdef __cplusplus extern "C" { #endif - + int read_pgn(FILE *stream, GameState *gamestate, GameInfo *gameinfo); size_t write_pgn(FILE* stream, GameState *gamestate, GameInfo *gameinfo); void compute_fen(char *str, GameState *gamestate);
--- a/src/client.c Tue Aug 28 14:03:09 2018 +0200 +++ b/src/client.c Tue Aug 28 14:16:30 2018 +0200 @@ -65,12 +65,12 @@ if (client_connect(&server, settings->serverhost, settings->port)) { net_destroy(&server); - return EXIT_FAILURE; + return 1; } if (client_handshake(&server)) { net_destroy(&server); - return EXIT_FAILURE; + return 1; } uint8_t code = net_recieve_code(server.fd); @@ -109,9 +109,9 @@ } else { addstr("Server sent invalid gameinfo."); net_destroy(&server); - return EXIT_FAILURE; + return 1; } net_destroy(&server); - return EXIT_SUCCESS; + return 0; }
--- a/src/game.c Tue Aug 28 14:03:09 2018 +0200 +++ b/src/game.c Tue Aug 28 14:16:30 2018 +0200 @@ -499,7 +499,7 @@ if (pgnfile) { int result = read_pgn(pgnfile, &gamestate, &(settings->gameinfo)); fclose(pgnfile); - if (result != EXIT_SUCCESS) { + if (result) { addstr("Invalid PGN file content.\n"); return; }
--- a/src/network.c Tue Aug 28 14:03:09 2018 +0200 +++ b/src/network.c Tue Aug 28 14:16:30 2018 +0200 @@ -111,7 +111,7 @@ return shutdown(server->fd, SHUT_RDWR); } - return EXIT_SUCCESS; + return 0; } void net_send_code(int socket, uint8_t code) {
--- a/src/server.c Tue Aug 28 14:03:09 2018 +0200 +++ b/src/server.c Tue Aug 28 14:16:30 2018 +0200 @@ -75,31 +75,31 @@ int result = read_pgn(pgnfile, &continuegame, &(settings->gameinfo)); fclose(pgnfile); - if (result != EXIT_SUCCESS) { + if (result) { addstr("Invalid PGN file content.\n"); - return EXIT_FAILURE; + return 1; } if (!is_game_running(&continuegame)) { addstr("Game has ended. Use -S to analyze it.\n"); - return EXIT_FAILURE; + return 1; } addch('\n'); dump_moveinfo(&continuegame); addch('\n'); } else { printw("Can't read PGN file (%s)\n", strerror(errno)); - return EXIT_FAILURE; + return 1; } } if (server_open(&server, settings->port)) { net_destroy(&server); - return EXIT_FAILURE; + return 1; } if (server_handshake(server.client)) { net_destroy(&server); - return EXIT_FAILURE; + return 1; } int fd = server.client->fd; @@ -157,9 +157,9 @@ clrtoeol(); net_destroy(&server); - return EXIT_FAILURE; + return 1; } net_destroy(&server); - return EXIT_SUCCESS; + return 0; }