pgn parser can now handle comments (although it ignores them for now) default tip

Tue, 13 Aug 2019 00:33:59 +0200

author
Mike Becker <universe@uap-core.de>
date
Tue, 13 Aug 2019 00:33:59 +0200
changeset 70
5427beba96d1
parent 69
c8f2c280cff7

pgn parser can now handle comments (although it ignores them for now)

src/chess/pgn.c file | annotate | diff | comparison | revisions
src/terminal-chess.h file | annotate | diff | comparison | revisions
     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 */
     2.1 --- a/src/terminal-chess.h	Tue Sep 18 15:02:08 2018 +0200
     2.2 +++ b/src/terminal-chess.h	Tue Aug 13 00:33:59 2019 +0200
     2.3 @@ -36,7 +36,7 @@
     2.4  #ifndef TERMINAL_CHESS_H
     2.5  #define	TERMINAL_CHESS_H
     2.6  
     2.7 -#define PROGRAM_VERSION "0.9-r69"
     2.8 +#define PROGRAM_VERSION "0.9-r70"
     2.9  
    2.10  #ifdef	__cplusplus
    2.11  extern "C" {

mercurial