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

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
child 71
0bdb910478cc

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
--- 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 */
--- 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" {

mercurial