Author: Dann Corbit
Date: 18:02:30 09/13/99
Go up one level in this thread
On September 13, 1999 at 20:01:45, James Robertson wrote:
>I have tried extract, and it chokes on large files. If you could send me the c
>utility, I would be happy with that.
?
I have run extract on 2 gig files! Never seen a problem. Try the one on my ftp
site, maybe. It's a 32 bit binary.
This program assumes that your PGN follows some of the PGN rules (a dangerous
assumption at times!). You will get files from 60-100K on average with 3000
line limit.
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
FILE *newfile(void);
char pgn[32000];
char line[1000];
static int fcount = 0;
static const limit = 3000; /* change this for bigger/smaller */
int
main(void)
{
int last_was_space = 0;
int count = 0;
FILE *fout = NULL;
fout = newfile();
while (fgets(line, sizeof line, stdin) != 0) {
if (line[0] == '[') {
if (last_was_space) {
if (count >= limit) {
count = 0;
fflush(fout);
fclose(fout);
fout = newfile();
}
last_was_space = 0;
}
} else
last_was_space = 1;
count++;
fputs(line, fout);
}
return 0;
}
FILE *
newfile()
{
char fname[FILENAME_MAX + 1];
sprintf(fname, "PGN%d.pgn", fcount++);
return fopen(fname, "w");
}
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.