home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
High Voltage Shareware
/
high1.zip
/
high1
/
DIR2
/
CBUFF09.ZIP
/
SRC.ZIP
/
PGN.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-11-16
|
2KB
|
113 lines
/* $Id$
*
* File pgn.c
* Part of ChessBase utilities file format (CBUFF)
* Author Anjo Anjewierden, anjo@swi.psy.uva.nl
* Purpose Portable Game Notation (PGN) utility
* Works with GNU CC 2.4.5
*
* Notice Copyright (c) 1993 Anjo Anjewierden
*
* History 15/10/93 (Created)
* 15/10/93 (Last modified)
*/
/*------------------------------------------------------------
* Directives
*------------------------------------------------------------*/
#include "cbuff.h"
char * UTILITY_NAME = "PGN utility";
char * UTILITY_VERSION = "1.1.0";
void helpUtility(FILE *fd);
/*------------------------------------------------------------
* PGN utility
*------------------------------------------------------------*/
void
pgnUtility(Option opt)
{ Game g = newGame();
CBase cb = opt->database;
long from = opt->from;
long to = (opt->to < getNoGamesCBase(cb) ? opt->to : getNoGamesCBase(cb));
long n;
reportCBase(cb, stderr);
n = to-from+1;
if (n < 0)
return;
for (n=from; n<=to; n++)
{ environmentError(cb, g, n);
initialiseGame(g, n, cb);
if (foundError())
{ reportError(stderr);
continue;
}
pgnGame(g, opt->output, opt->notation);
if (foundError())
reportError(stderr);
}
freeGame(g);
}
/*------------------------------------------------------------
* Main
*------------------------------------------------------------*/
int
main(int argc, char *argv[])
{ int i;
Option options = newOption();
initChessSymbols();
for (i=1; i<argc; i++)
{
if (strhead(argv[i], "-"))
{ int n;
n = genericOption(options, argv, argc, i);
if (n == 0)
{ fprintf(stderr, "Fatal: Unknown command %s\n", argv[i]);
fprintf(stderr, "Do ``%s -help'' or see the documentation\n", argv[0]);
exit(1);
}
i = n;
continue;
}
setCurrentCBase(argv[i], "-database", argc, i);
options->database = CurrentBase;
pgnUtility(options);
freeCBase(options->database);
options->database = (CBase) NULL;
}
if (options->database)
{ pgnUtility(options);
freeCBase(options->database);
}
exit(0);
}
/*------------------------------------------------------------
* Help
*------------------------------------------------------------*/
void
helpUtility(FILE *fd)
{ helpCBUFF(fd);
fprintf(fd, "%s options:\n", UTILITY_NAME);
}