Author: Steven J. Edwards
Date: 22:37:23 06/14/98
Fellow Programmers:
I have been using Bob Hyatt's large.pgn and wall.pgn as test inputs to
the OCD toolkit book position library constructor. The wall.pgn file is
222,086,290 bytes long and has over 300,000 games. It breaks several
text editors due to its size.
To help cope with this, I wrote a quick hack to split a big PGN file.
The code follows; I hope it will be useful to others.
-- Steven (sje@mv.mv.com)
/* pgnsplit.c: read PGN text (standard input); split into 1000 game
chunks */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef char *charPtrT;
#define splitL 1000
#define tL 1024
#define fnL 32
static int IsGameStart(charPtrT sPtr)
{
int result;
if (strncmp(sPtr, "[Event", 6) == 0)
result = 1;
else
result = 0;
return (result);
}
int main(void)
{
FILE *fpIn, *fpOut;
char tV[tL];
char fnV[fnL];
long int fileCount;
long int gameCount;
int done;
/* init */
fileCount = gameCount = 0;
done = 0;
fpOut = NULL;
/* preload */
fpIn = stdin;
if (fgets(tV, tL, fpIn) == NULL)
done = 1;
while (!done)
{
/* check for open */
if (fpOut == NULL)
{
sprintf(fnV, "gs%04ld.pgn", fileCount);
fpOut = fopen(fnV, "w");
if (fpOut == NULL)
{
fprintf(stderr, "Can't open %s for output\n", fnV);
exit(1);
};
fileCount++;
printf("Writing file %s\n", fnV);
};
/* write */
fputs(tV, fpOut);
/* read */
if (fgets(tV, tL, fpIn) == NULL)
done = 1;
/* bump */
if (done || IsGameStart(tV))
{
gameCount++;
if (((gameCount % splitL) == 0))
{
fclose(fpOut);
fpOut = NULL;
};
};
};
printf("games: %ld files: %ld\n", gameCount, fileCount);
return (0)
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.