"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/frontend/cmd.cc" between
gnuchess-6.2.6.tar.gz and gnuchess-6.2.7.tar.gz

About: GNU Chess is a chess-playing program.

cmd.cc  (gnuchess-6.2.6):cmd.cc  (gnuchess-6.2.7)
skipping to change at line 94 skipping to change at line 94
* are separated by whitespace. * are separated by whitespace.
*/ */
static int tokeneq(const char *s, const char *t) static int tokeneq(const char *s, const char *t)
{ {
while (*s && *t && !isspace(*s) && !isspace(*t)) { while (*s && *t && !isspace(*s) && !isspace(*t)) {
if (*s++ != *t++) return 0; if (*s++ != *t++) return 0;
} }
return (!*s || isspace(*s)) && (!*t || isspace(*t)); return (!*s || isspace(*s)) && (!*t || isspace(*t));
} }
/*
* Reads a PGN file and returns the equivalent EPD content
*
* The conversion relies on a temporary file in EPD format,
* which is removed afterwards.
*/
static char *load_pgn_as_epd( const char *pgn_filename, char *epdline, int showh
eading )
{
FILE *epdfile=NULL;
char tmp_epd[]=".tmp.epd";
PGNReadFromFile (pgn_filename, showheading);
SaveEPD( tmp_epd );
epdfile = fopen( tmp_epd, "r" );
char *s = fgets( epdline, MAXSTR, epdfile );
fclose( epdfile );
remove( tmp_epd );
return s;
}
void cmd_accepted(void) void cmd_accepted(void)
{ {
SetDataToEngine( token[0] ); SetDataToEngine( token[0] );
} }
void cmd_activate(void) void cmd_activate(void)
{ {
printf( _("Command 'activate' is currently not supported.\n") ); printf( _("Command 'activate' is currently not supported.\n") );
} }
skipping to change at line 439 skipping to change at line 460
} else { } else {
printf( _("Null-move heuristic is off.\n") ); printf( _("Null-move heuristic is off.\n") );
} }
} }
void cmd_otim(void) void cmd_otim(void)
{ {
SetDataToEngine( token[0] ); SetDataToEngine( token[0] );
} }
/*
* Load a file containing a game in PGN format.
*
* The file contents will be passed on to the adapter
* in EPD notation (the adapter expectes FEN actually,
* but EPD and FEN are similar (possible issue here?),
* hence a PGN -> EPD conversion in done first.
*/
void cmd_pgnload(void) void cmd_pgnload(void)
{ {
char tmp_epd[]=".tmp.epd";
char data[MAXSTR]=""; char data[MAXSTR]="";
FILE *epdfile=NULL;
char epdline[MAXSTR]=""; char epdline[MAXSTR]="";
PGNReadFromFile (token[1],0); char *s = load_pgn_as_epd( token[1], epdline, 0 );
SaveEPD( tmp_epd ); if ( s == NULL ) {
epdfile = fopen( tmp_epd, "r" );
if ( fgets( epdline, MAXSTR, epdfile ) == NULL ) {
printf( _("Incorrect epd file.\n") ); printf( _("Incorrect epd file.\n") );
return; return;
} }
strcpy( data, "setboard " ); strcpy( data, "setboard " );
int i=0; int i=0;
while ( epdline[i] != '\n' ) { while ( epdline[i] != '\n' ) {
data[i+9] = epdline[i]; data[i+9] = epdline[i];
++i; ++i;
} }
data[i+9] = '\0'; data[i+9] = '\0';
SetDataToEngine( data ); SetDataToEngine( data );
SetAutoGo( true ); SetAutoGo( true );
pgnloaded = 0; pgnloaded = 0;
} }
/* See comment above in cmd_pgnload about PGN -> EPD conversion. */
void cmd_pgnreplay(void) void cmd_pgnreplay(void)
{ {
char tmp_epd[]=".tmp.epd";
char data[MAXSTR]=""; char data[MAXSTR]="";
FILE *epdfile=NULL;
char epdline[MAXSTR]=""; char epdline[MAXSTR]="";
PGNReadFromFile (token[1],1); char *s = load_pgn_as_epd( token[1], epdline, 1 );
if ( s == NULL ) {
SaveEPD( tmp_epd );
epdfile = fopen( tmp_epd, "r" );
if ( fgets( epdline, MAXSTR, epdfile ) == NULL ) {
printf( _("Incorrect epd file.\n") ); printf( _("Incorrect epd file.\n") );
return; return;
} }
strcpy( data, "setboard " ); strcpy( data, "setboard " );
int i=0; int i=0;
while ( epdline[i] != '\n' ) { while ( epdline[i] != '\n' ) {
data[i+9] = epdline[i]; data[i+9] = epdline[i];
++i; ++i;
} }
 End of changes. 10 change blocks. 
13 lines changed or deleted 36 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)