Use C stdio functions for score files and save files.

Switching from Unix file descriptor operations to C standard FILE*
functions will reduce portability problems.
This commit is contained in:
John "Elwin" Edwards 2017-09-15 19:57:54 -04:00
parent f8d1f422c8
commit c661fd79d4
33 changed files with 426 additions and 439 deletions

View file

@ -36,9 +36,6 @@
* scoreout() and scorein() to reflect the change. Also update SCORELEN.
*/
extern int scorefd;
extern FILE *logfile;
struct sc_ent {
unsigned long sc_score;
char sc_name[LINELEN];
@ -72,7 +69,7 @@ static char *rip[] = {
};
char *killname(short monst);
void scorein(struct sc_ent scores[], int fd);
void scorein(struct sc_ent scores[], FILE *inf);
void scoreout(struct sc_ent scores[], FILE *outf);
void showpack(char *howso);
int update(struct sc_ent top_ten[], unsigned long amount, short quest,
@ -170,10 +167,8 @@ score(unsigned long amount, int flags, short monst)
register struct sc_ent *scp;
register int i;
register struct sc_ent *sc2;
register FILE *outf;
register char *killer;
register int prflags = 0;
register int fd;
short upquest = 0, wintype = 0, uplevel = 0, uptype = 0; /* For network updating */
char upsystem[SYSLEN], uplogin[LOGLEN];
char *thissys; /* Holds the name of this system */
@ -204,12 +199,11 @@ score(unsigned long amount, int flags, short monst)
* Open file and read list
*/
if ((fd = scorefd) < 0)
if (scoreboard == NULL)
{
printf("\nCannot open score_file.\n");
return;
}
outf = (FILE *) md_fdopen(fd, "w");
/* Get this system's name */
thissys = md_gethostname();
@ -257,7 +251,7 @@ score(unsigned long amount, int flags, short monst)
#endif
/* Read the score and convert it to a compatible format */
scorein(top_ten, fd); /* Convert it */
scorein(top_ten, scoreboard); /* Convert it */
/* Get some values if this is an update */
if (flags == UPDATE) {
@ -283,7 +277,7 @@ score(unsigned long amount, int flags, short monst)
errors++;
if (errors) {
fclose(outf);
fclose(scoreboard);
free(compatstr);
return;
}
@ -475,12 +469,12 @@ score(unsigned long amount, int flags, short monst)
}
}
fseek(outf, 0L, 0);
fseek(scoreboard, 0L, 0);
/*
* Update the list file
*/
scoreout(top_ten, outf);
fclose(outf);
scoreout(top_ten, scoreboard);
fclose(scoreboard);
/*
* SCOREIT -- rogue -s option. Never started curses if this option.
@ -627,17 +621,17 @@ void writelog(unsigned long amount, int flags, short monst) {
* score file by scoreout() back to a score file structure.
*/
void
scorein(struct sc_ent scores[], int fd)
scorein(struct sc_ent scores[], FILE *inf)
{
int i;
char scoreline[100];
for(i = 0; i < NUMSCORE; i++)
{
encread((char *) &scores[i].sc_name, LINELEN, fd);
encread((char *) &scores[i].sc_system, SYSLEN, fd);
encread((char *) &scores[i].sc_login, LINELEN, fd);
encread((char *) scoreline, 100, fd);
encread((char *) &scores[i].sc_name, LINELEN, inf);
encread((char *) &scores[i].sc_system, SYSLEN, inf);
encread((char *) &scores[i].sc_login, LINELEN, inf);
encread((char *) scoreline, 100, inf);
sscanf(scoreline, " %lu %d %d %d %d %d \n",
&scores[i].sc_score, &scores[i].sc_flgs,
&scores[i].sc_level, &scores[i].sc_ctype,