src/chess/pgn.c

changeset 70
5427beba96d1
parent 65
dcc5bd2c56c0
     1.1 --- a/src/chess/pgn.c	Tue Sep 18 15:02:08 2018 +0200
     1.2 +++ b/src/chess/pgn.c	Tue Aug 13 00:33:59 2019 +0200
     1.3 @@ -35,6 +35,7 @@
     1.4  enum {
     1.5      pgn_error_missing_quote = 1,
     1.6      pgn_error_missing_bracket,
     1.7 +    pgn_error_missing_brace,
     1.8      pgn_error_missing_dot,
     1.9      pgn_error_move_syntax,
    1.10      pgn_error_move_semantics
    1.11 @@ -43,6 +44,7 @@
    1.12  static const char* pgn_error_strings[] = {
    1.13      "No Error.",
    1.14      "Tag values must be enclosed in double-quotes.",
    1.15 +    "Missing closing brace '}' for comment.",
    1.16      "Tags must be enclosed in square brackets: '[Key \"Value\"]'.",
    1.17      "Move numbers must be terminated with a dot (e.g. '13.' - not '13').",
    1.18      "Move is syntactically incorrect.",
    1.19 @@ -128,7 +130,21 @@
    1.20          }
    1.21          apply_move(gamestate, &move);
    1.22          
    1.23 -        // TODO: parse comments
    1.24 +        /* skip spaces */
    1.25 +        while (isspace(c = fgetc(stream)));
    1.26 +        
    1.27 +        /* parse possible comment */
    1.28 +        if (c == '{') {
    1.29 +            // TODO: interpret comment (may contain clock info)
    1.30 +            do {
    1.31 +                c = fgetc(stream);
    1.32 +            } while (c != '}' && c != EOF);
    1.33 +            if (c == EOF) {
    1.34 +                return pgn_error_missing_brace;
    1.35 +            }
    1.36 +        }
    1.37 +        
    1.38 +        /* skip spaces */
    1.39          while (isspace(c = fgetc(stream)));
    1.40          
    1.41          /* end of game data encountered */

mercurial