Mercurial > hg > early-roguelike
changeset 279:d3968e9cb98d
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.
| author | John "Elwin" Edwards |
|---|---|
| date | Fri, 15 Sep 2017 19:57:54 -0400 |
| parents | c222f9d56776 |
| children | 70aa5808c782 |
| files | arogue5/main.c arogue5/mdport.c arogue5/options.c arogue5/rip.c arogue5/rogue.c arogue5/rogue.h arogue5/save.c arogue5/state.c arogue7/main.c arogue7/mdport.c arogue7/options.c arogue7/rip.c arogue7/rogue.c arogue7/rogue.h arogue7/save.c arogue7/state.c rogue4/extern.c rogue4/extern.h rogue4/mach_dep.c rogue4/mdport.c rogue4/rip.c rogue4/rogue.h rogue4/save.c rogue4/state.c srogue/global.c srogue/main.c srogue/rip.c srogue/rogue.ext srogue/save.c srogue/state.c xrogue/rogue.h xrogue/save.c xrogue/state.c |
| diffstat | 33 files changed, 427 insertions(+), 440 deletions(-) [+] |
line wrap: on
line diff
--- a/arogue5/main.c Sun Sep 10 17:30:13 2017 -0400 +++ b/arogue5/main.c Fri Sep 15 19:57:54 2017 -0400 @@ -20,6 +20,7 @@ #include <limits.h> #include <signal.h> #include <time.h> +#include <errno.h> #include "mach_dep.h" #include "network.h" #include "rogue.h" @@ -245,10 +246,22 @@ } void +reopen_score(void) +{ + if (scoreboard != NULL) + fclose(scoreboard); + scoreboard = fopen(score_file, "r+"); + if (scoreboard == NULL && errno == ENOENT) { + scoreboard = fopen(score_file, "w+"); + } +} + + +void open_records(void) { - if (scorefd == -1) - md_reopen_score(); + if (scoreboard == NULL) + reopen_score(); #ifdef LOGFILE if (logfile == NULL) logfile = fopen(LOGFILE, "a");
--- a/arogue5/mdport.c Sun Sep 10 17:30:13 2017 -0400 +++ b/arogue5/mdport.c Fri Sep 15 19:57:54 2017 -0400 @@ -696,17 +696,6 @@ #endif } -extern int scorefd; -extern char score_file[]; - -void -md_reopen_score(void) -{ - if (scorefd > 0) - close(scorefd); - scorefd = open(score_file, O_RDWR | O_CREAT, 0666); -} - /* Cursor/Keypad Support
--- a/arogue5/options.c Sun Sep 10 17:30:13 2017 -0400 +++ b/arogue5/options.c Fri Sep 15 19:57:54 2017 -0400 @@ -103,7 +103,7 @@ return status; if (strcmp(old_score_file, optstr)) { - md_reopen_score(); + reopen_score(); } return status; }
--- a/arogue5/rip.c Sun Sep 10 17:30:13 2017 -0400 +++ b/arogue5/rip.c Fri Sep 15 19:57:54 2017 -0400 @@ -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 @@ }; 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 @@ 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 @@ * 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 @@ #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 @@ errors++; if (errors) { - fclose(outf); + fclose(scoreboard); free(compatstr); return; } @@ -475,12 +469,12 @@ } } - 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 @@ * 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,
--- a/arogue5/rogue.c Sun Sep 10 17:30:13 2017 -0400 +++ b/arogue5/rogue.c Fri Sep 15 19:57:54 2017 -0400 @@ -64,7 +64,6 @@ int spell_power = 0; int turns = 0; /* Number of turns player has taken */ int quest_item = 0; /* Item player is looking for */ -int scorefd = -1; /* File descriptor for the scorefile */ char nfloors = -1; /* Number of floors in this dungeon */
