Page 1 of 1

Separate games in a pgn database

PostPosted: 26 Dec 2010, 12:41
by rigao
Hello everyone.

I'm trying to make an online database viewer in a mix of javascript and php (something like Chess Tempo, but open source). I want the database viewer to be able to load a .pgn database file and ask you which game do you want to browse (in a plain html select). Once you choose the game to view, it will display it in a board (I probably will use jspgnviewer, which is released under the apache license).

So, as I have the viewer, I just need to load the database and show the user the list of games.

Here I can use your help. I've been reading the pgn standard and I was starting to think how I will get the games from the database when I realised this has already been done many times in open source programs. In particular, xboard can load .pgn databases and shows you the list of games. So there is no point in reinventing the wheel. Can someone point me to the exact code which is responsible from the load of .pgn databases in xboard? I guess it will be in C, but I can then translate it to PHP. It is just that when someone else has thought of every little detail, there is no point for me to rethink it, I may as well copy it :D

Of course any other implementation would do, there is no need to be xboard implementation, but as I'm asking in xboard forum, well, it is kind of logical to ask for the xboard implementation, isn't it?

Thanks.

Re: Separate games in a pgn database

PostPosted: 27 Dec 2010, 06:09
by nevatre
have a look at GameListBuild(f) in gamelist.c

Re: Separate games in a pgn database

PostPosted: 27 Dec 2010, 09:53
by H.G.Muller
XBoard uses a parser for PGN that is automatically generated from the rules of the PGN grammar, by a utility called 'flex'. The rules (and required semantic actions to get move from and to-square) are defined in a file parser.l, which is fed to flex in the building process to produce a file parser.c. So it is parser.c (containing the low-level parser routine yylex) you would have to translate to PHP, but I am afraid it is not very suitable, as flex generates a table-driven parser, with a huge table of codes.

A source which does the parsing from scratch in C is the Lasker ICS code (the routine alg_parse_move, IIRC). Personally, I think re-inventing the wheel might not be such a bad idea. PGN is not that difficult to parse.

Re: Separate games in a pgn database

PostPosted: 28 Dec 2010, 07:48
by Ron Murawski
There's the SanKit code by Steven J. Edwards
http://cfajohnson.com/chess/SAN/
"PGN game notation encoding is found in file sanpgn.c. PGN decoding is the file sanrdr.c"

-Ron

Re: Separate games in a pgn database

PostPosted: 29 Apr 2011, 12:55
by moralefor
That is a good feature of the website for playing games. This is a good thing to do for choosing games to play on the list. Anyway, it might work like on the GameListBuild.

Re: Separate games in a pgn database

PostPosted: 29 Apr 2011, 16:59
by Pablo Vazquez
moralefor wrote:That is a good feature of the website for playing games. This is a good thing to do for choosing games to play on the list. Anyway, it might work like on the GameListBuild.

Turing test failed