src/chess/pgn.c

changeset 70
5427beba96d1
parent 65
dcc5bd2c56c0
equal deleted inserted replaced
69:c8f2c280cff7 70:5427beba96d1
33 #include <string.h> 33 #include <string.h>
34 34
35 enum { 35 enum {
36 pgn_error_missing_quote = 1, 36 pgn_error_missing_quote = 1,
37 pgn_error_missing_bracket, 37 pgn_error_missing_bracket,
38 pgn_error_missing_brace,
38 pgn_error_missing_dot, 39 pgn_error_missing_dot,
39 pgn_error_move_syntax, 40 pgn_error_move_syntax,
40 pgn_error_move_semantics 41 pgn_error_move_semantics
41 }; 42 };
42 43
43 static const char* pgn_error_strings[] = { 44 static const char* pgn_error_strings[] = {
44 "No Error.", 45 "No Error.",
45 "Tag values must be enclosed in double-quotes.", 46 "Tag values must be enclosed in double-quotes.",
47 "Missing closing brace '}' for comment.",
46 "Tags must be enclosed in square brackets: '[Key \"Value\"]'.", 48 "Tags must be enclosed in square brackets: '[Key \"Value\"]'.",
47 "Move numbers must be terminated with a dot (e.g. '13.' - not '13').", 49 "Move numbers must be terminated with a dot (e.g. '13.' - not '13').",
48 "Move is syntactically incorrect.", 50 "Move is syntactically incorrect.",
49 "Move is not valid according to chess rules." 51 "Move is not valid according to chess rules."
50 }; 52 };
126 if (validate_move(gamestate, &move) != VALID_MOVE_SEMANTICS) { 128 if (validate_move(gamestate, &move) != VALID_MOVE_SEMANTICS) {
127 return pgn_error_move_semantics; 129 return pgn_error_move_semantics;
128 } 130 }
129 apply_move(gamestate, &move); 131 apply_move(gamestate, &move);
130 132
131 // TODO: parse comments 133 /* skip spaces */
134 while (isspace(c = fgetc(stream)));
135
136 /* parse possible comment */
137 if (c == '{') {
138 // TODO: interpret comment (may contain clock info)
139 do {
140 c = fgetc(stream);
141 } while (c != '}' && c != EOF);
142 if (c == EOF) {
143 return pgn_error_missing_brace;
144 }
145 }
146
147 /* skip spaces */
132 while (isspace(c = fgetc(stream))); 148 while (isspace(c = fgetc(stream)));
133 149
134 /* end of game data encountered */ 150 /* end of game data encountered */
135 if (c == EOF) { 151 if (c == EOF) {
136 break; 152 break;

mercurial