separate function to check a valid piece character - chess-puzzles - chess puzzle book generator
 (HTM) git clone git://git.codemadness.org/chess-puzzles
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 09a541233ed6f1abf9f4498b37d1281a78f65ce8
 (DIR) parent 5df80ee4eebb2000bcac5530f58e6c84e9b92818
 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Tue, 19 Dec 2023 00:31:34 +0100
       
       separate function to check a valid piece character
       
       Diffstat:
         M fen_to_svg.c                        |      12 ++++++++++--
       
       1 file changed, 10 insertions(+), 2 deletions(-)
       ---
 (DIR) diff --git a/fen_to_svg.c b/fen_to_svg.c
       @@ -184,11 +184,19 @@ showboard(void)
        }
        
        int
       +isvalidpiece(int c)
       +{
       +        static char pieces[] = "PNBRQKpnbrqk";
       +
       +        return strchr(pieces, c) ? 1 : 0;
       +}
       +
       +int
        main(int argc, char *argv[])
        {
                const char *fen, *moves, *s;
                int x, y, x2, y2, field, piece;
       -        char pieces[] = "PNBRQKpnbrqk", square[3];
       +        char square[3];
        
                if (argc != 3) {
                        fprintf(stderr, "usage: %s <FEN> <moves>\n", argv[0]);
       @@ -223,7 +231,7 @@ main(int argc, char *argv[])
                                        continue;
                                }
                                /* is piece? place it */
       -                        if (strchr(pieces, *s))
       +                        if (isvalidpiece(*s))
                                        place(*s, x++, y);
                                break;
                        case 1: /* active color */