"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/frontend/pgn.cc" between
gnuchess-6.2.4.tar.gz and gnuchess-6.2.5.tar.gz

About: GNU Chess is a chess-playing program.

pgn.cc  (gnuchess-6.2.4):pgn.cc  (gnuchess-6.2.5)
/* pgn.c /* pgn.c
GNU Chess frontend GNU Chess frontend
Copyright (C) 2001-2011 Free Software Foundation, Inc. Copyright (C) 2001-2017 Free Software Foundation, Inc.
GNU Chess is based on the two research programs GNU Chess is based on the two research programs
Cobalt by Chua Kong-Sian and Gazebo by Stuart Cracraft. Cobalt by Chua Kong-Sian and Gazebo by Stuart Cracraft.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
skipping to change at line 38 skipping to change at line 38
#include <stdio.h> #include <stdio.h>
#include <sys/time.h> #include <sys/time.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <time.h> #include <time.h>
#include <errno.h> #include <errno.h>
#include "common.h" #include "common.h"
#include "version.h" #include "version.h"
#include "lexpgn.h" #include "lexpgn.h"
#include "gettext.h"
#define _(str) gettext (str)
#define NULL2EMPTY(x) ( (x) ? (x) : "") #define NULL2EMPTY(x) ( (x) ? (x) : "")
extern FILE *yyin; extern FILE *yyin;
extern int yylex (void); extern int yylex (void);
void PGNSaveToFile (const char *file, const char *resultstr) void PGNSaveToFile (const char *file, const char *resultstr)
/**************************************************************************** /****************************************************************************
* *
* To save a game into PGN format to a file. If the file does not exist, * To save a game into PGN format to a file. If the file does not exist,
* it will create it. If the file exists, the game is appended to the file. * it will create it. If the file exists, the user will be asked for
* permission to overwrite the existing one.
* *
****************************************************************************/ ****************************************************************************/
{ {
FILE *fp; FILE *fp;
char s[100]; char s[100];
int len; int len;
char *p; char *p;
int i; int i;
char answer = '\0'; /* Default: invalid */
time_t secs; time_t secs;
struct tm *timestruct; struct tm *timestruct;
fp = fopen (file, "a"); /* Can we append to it? */ fp = fopen(file, "r");
if (fp) {
fclose(fp);
printf(_("File with name %s already exists.\n"), file);
do {
printf(_("Overwrite file? [y/n]: "));
answer = getchar();
if ( answer == '\n' ) {
printf(_("Invalid answer! "));
continue;
}
while( getchar() != '\n' );
if (tolower(answer) == 'n') {
printf(_("File not saved.\n"));
return;
}
else if (tolower(answer) == 'y') {
printf(_("File %s is overwritten.\n"), file);
}
else {
printf(_("Invalid answer!"));
}
} while (tolower(answer) != 'y' && tolower(answer) != 'n');
}
fp = fopen (file, "w");
if (fp == NULL) if (fp == NULL)
{ {
printf ("Cannot write to file %s\n", file); printf ("Cannot write to file %s\n", file);
return; return;
} }
/* Write the seven tags */ /* Write the seven tags */
fprintf (fp, "[Event \"%s\"]\n", NULL2EMPTY(pgn_event)); fprintf (fp, "[Event \"%s\"]\n", NULL2EMPTY(pgn_event));
fprintf (fp, "[Site \"%s\"]\n", NULL2EMPTY(pgn_site)); fprintf (fp, "[Site \"%s\"]\n", NULL2EMPTY(pgn_site));
secs=time(0); secs=time(0);
 End of changes. 5 change blocks. 
3 lines changed or deleted 36 lines changed or added

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