# HG changeset patch # User Mike Becker # Date 1565649239 -7200 # Node ID 5427beba96d1f310077bf20911146b5d5b21a4e3 # Parent c8f2c280cff757b1c10eab2193e60f253264748b pgn parser can now handle comments (although it ignores them for now) diff -r c8f2c280cff7 -r 5427beba96d1 src/chess/pgn.c --- a/src/chess/pgn.c Tue Sep 18 15:02:08 2018 +0200 +++ b/src/chess/pgn.c Tue Aug 13 00:33:59 2019 +0200 @@ -35,6 +35,7 @@ enum { pgn_error_missing_quote = 1, pgn_error_missing_bracket, + pgn_error_missing_brace, pgn_error_missing_dot, pgn_error_move_syntax, pgn_error_move_semantics @@ -43,6 +44,7 @@ static const char* pgn_error_strings[] = { "No Error.", "Tag values must be enclosed in double-quotes.", + "Missing closing brace '}' for comment.", "Tags must be enclosed in square brackets: '[Key \"Value\"]'.", "Move numbers must be terminated with a dot (e.g. '13.' - not '13').", "Move is syntactically incorrect.", @@ -128,7 +130,21 @@ } apply_move(gamestate, &move); - // TODO: parse comments + /* skip spaces */ + while (isspace(c = fgetc(stream))); + + /* parse possible comment */ + if (c == '{') { + // TODO: interpret comment (may contain clock info) + do { + c = fgetc(stream); + } while (c != '}' && c != EOF); + if (c == EOF) { + return pgn_error_missing_brace; + } + } + + /* skip spaces */ while (isspace(c = fgetc(stream))); /* end of game data encountered */ diff -r c8f2c280cff7 -r 5427beba96d1 src/terminal-chess.h --- a/src/terminal-chess.h Tue Sep 18 15:02:08 2018 +0200 +++ b/src/terminal-chess.h Tue Aug 13 00:33:59 2019 +0200 @@ -36,7 +36,7 @@ #ifndef TERMINAL_CHESS_H #define TERMINAL_CHESS_H -#define PROGRAM_VERSION "0.9-r69" +#define PROGRAM_VERSION "0.9-r70" #ifdef __cplusplus extern "C" {