Introduction
Introduction Statistics Contact Development Disclaimer Help
improve move number parsing - chess-puzzles - chess puzzle book generator
git clone git://git.codemadness.org/chess-puzzles
Log
Files
Refs
README
LICENSE
---
commit dab21427a28e5561843d56cb4de324cddd4c53c7
parent 30a2ab3dd2979115341beaedc6d4a4918541036a
Author: Hiltjo Posthuma <[email protected]>
Date: Wed, 20 Dec 2023 19:26:23 +0100
improve move number parsing
Diffstat:
M fen_to_svg.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
---
diff --git a/fen_to_svg.c b/fen_to_svg.c
@@ -1,3 +1,4 @@
+/* TODO: write some test-cases for parsing and output FEN */
/* TODO: option to flip board? */
#include <ctype.h>
@@ -420,7 +421,7 @@ main(int argc, char *argv[])
/* initial board state, FEN format */
x = y = field = 0;
- for (s = fen; *s; s++) {
+ for (s = fen; *s && field < 6; s++) {
switch (field) {
case 0: /* piece placement data */
/* skip square */
@@ -478,7 +479,9 @@ main(int argc, char *argv[])
l = strtol(s, NULL, 10);
if (l >= 0 && l < 32767) {
halfmove = l;
- s += strspn(s, "0123456789");
+
+ for (; *s && isdigit((unsigned char)*s); s++)
+ ;
}
break;
case 5: /* move number */
@@ -487,11 +490,15 @@ main(int argc, char *argv[])
l = strtol(s, NULL, 10);
if (l >= 0 && l < 32767) {
- movenumber = l;
- s += strspn(s, "0123456789");
+ movenumber = (int)l;
+ for (; *s && isdigit((unsigned char)*s); s++)
+ ;
}
break;
}
+ if (!*s)
+ break;
+
/* TODO: parse which side to move, en-passant, etc */
/* next field, fields are: piece placement data, active color,
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.