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

@ -20,6 +20,7 @@
#include <limits.h> #include <limits.h>
#include <signal.h> #include <signal.h>
#include <time.h> #include <time.h>
#include <errno.h>
#include "mach_dep.h" #include "mach_dep.h"
#include "network.h" #include "network.h"
#include "rogue.h" #include "rogue.h"
@ -244,11 +245,23 @@ main(int argc, char *argv[], char *envp[])
playit(); playit();
} }
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 void
open_records(void) open_records(void)
{ {
if (scorefd == -1) if (scoreboard == NULL)
md_reopen_score(); reopen_score();
#ifdef LOGFILE #ifdef LOGFILE
if (logfile == NULL) if (logfile == NULL)
logfile = fopen(LOGFILE, "a"); logfile = fopen(LOGFILE, "a");

View file

@ -696,17 +696,6 @@ md_flushinp(void)
#endif #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 Cursor/Keypad Support

View file

@ -103,7 +103,7 @@ int get_score(char *optstr, WINDOW *win)
return status; return status;
if (strcmp(old_score_file, optstr)) if (strcmp(old_score_file, optstr))
{ {
md_reopen_score(); reopen_score();
} }
return status; return status;
} }

View file

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

View file

@ -64,7 +64,6 @@ int pray_time = 0;
int spell_power = 0; int spell_power = 0;
int turns = 0; /* Number of turns player has taken */ int turns = 0; /* Number of turns player has taken */
int quest_item = 0; /* Item player is looking for */ 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 */ char nfloors = -1; /* Number of floors in this dungeon */
char curpurch[LINELEN*2]; /* name of item ready to buy */ char curpurch[LINELEN*2]; /* name of item ready to buy */
char PLAYER = VPLAYER; /* what the player looks like */ char PLAYER = VPLAYER; /* what the player looks like */
@ -124,6 +123,7 @@ char *spacemsg = "--Press space to continue--";
char *morestr = "-- More --"; char *morestr = "-- More --";
char *retstr = "[Press return to continue]"; char *retstr = "[Press return to continue]";
FILE *scoreboard = NULL; /* The scorefile */
FILE *logfile = NULL; FILE *logfile = NULL;
/* /*

View file

@ -1009,7 +1009,7 @@ bool drop(struct linked_list *item);
bool dropcheck(struct object *op); bool dropcheck(struct object *op);
void dust_appear(void); void dust_appear(void);
void eat(void); void eat(void);
int encread(char *start, unsigned int size, int inf); int encread(char *start, unsigned int size, FILE *inf);
int encwrite(char *start, unsigned int size, FILE *outf); int encwrite(char *start, unsigned int size, FILE *outf);
void endit(int sig); void endit(int sig);
void endmsg(void); void endmsg(void);
@ -1097,6 +1097,7 @@ void raise_level(bool get_spells);
short randmonster(bool wander, bool no_unique); short randmonster(bool wander, bool no_unique);
void read_scroll(int which, int flag, bool is_scroll); void read_scroll(int which, int flag, bool is_scroll);
int readchar(void); int readchar(void);
void reopen_score(void);
void res_dexterity(int howmuch); void res_dexterity(int howmuch);
void res_strength(void); void res_strength(void);
bool restore(char *file, char **envp); bool restore(char *file, char **envp);
@ -1114,7 +1115,7 @@ coord *rndmove(struct thing *who);
int roll(int number, int sides); int roll(int number, int sides);
void rollwand(void); void rollwand(void);
struct room *roomin(coord *cp); struct room *roomin(coord *cp);
int rs_restore_file(int inf); int rs_restore_file(FILE *inf);
int rs_save_file(FILE *savef); int rs_save_file(FILE *savef);
void runners(void); void runners(void);
void runto(struct thing *runner, coord *spot); void runto(struct thing *runner, coord *spot);
@ -1191,7 +1192,6 @@ extern int md_unlink(char *file);
extern int md_normaluser(void); extern int md_normaluser(void);
extern int md_getuid(void); extern int md_getuid(void);
extern long md_memused(void); extern long md_memused(void);
extern void md_reopen_score(void);
extern int md_readchar(WINDOW *win); extern int md_readchar(WINDOW *win);
extern int md_shellescape(void); extern int md_shellescape(void);
extern int md_srand(int seed); extern int md_srand(int seed);
@ -1266,7 +1266,6 @@ extern int pray_time; /* Number of prayer points/exp level */
extern int spell_power; /* Spell power left at this level */ extern int spell_power; /* Spell power left at this level */
extern int turns; /* Number of turns player has taken */ extern int turns; /* Number of turns player has taken */
extern int quest_item; /* Item hero is looking for */ extern int quest_item; /* Item hero is looking for */
extern int scorefd; /* File descriptor for the scorefile */
extern int cur_relic[]; /* Current relics */ extern int cur_relic[]; /* Current relics */
extern char take; /* Thing the rogue is taking */ extern char take; /* Thing the rogue is taking */
extern char prbuf[]; /* Buffer for sprintfs */ extern char prbuf[]; /* Buffer for sprintfs */
@ -1338,4 +1337,5 @@ extern char *stones[NSTONES];
extern char *metal[NMETAL]; extern char *metal[NMETAL];
extern char *wood[NWOOD]; extern char *wood[NWOOD];
extern coord ch_ret; extern coord ch_ret;
extern FILE *scoreboard; /* The scorefile */
extern FILE *logfile; extern FILE *logfile;

View file

@ -151,7 +151,7 @@ save_file(FILE *savef)
bool bool
restore(char *file, char **envp) restore(char *file, char **envp)
{ {
register int inf; FILE *inf;
#ifndef _AIX #ifndef _AIX
extern char **environ; extern char **environ;
#endif #endif
@ -162,7 +162,7 @@ restore(char *file, char **envp)
if (strcmp(file, "-r") == 0) if (strcmp(file, "-r") == 0)
file = file_name; file = file_name;
if ((inf = open(file, O_RDONLY)) < 0) if ((inf = fopen(file, "r")) == NULL)
{ {
if (use_savedir && errno == ENOENT) if (use_savedir && errno == ENOENT)
{ {
@ -189,7 +189,7 @@ restore(char *file, char **envp)
encread(buf, 80, inf); encread(buf, 80, inf);
sscanf(buf, "%d x %d\n", &oldline, &oldcol); sscanf(buf, "%d x %d\n", &oldline, &oldcol);
fstat(inf, &sbuf2); stat(file, &sbuf2);
fflush(stdout); fflush(stdout);
/* /*
@ -235,7 +235,7 @@ restore(char *file, char **envp)
if (!wizard) if (!wizard)
{ {
if (md_unlink(file) < 0) { if (md_unlink(file) < 0) {
close(inf); /* only close if system insists */ fclose(inf); /* only close if system insists */
if (md_unlink(file) < 0) { if (md_unlink(file) < 0) {
endwin(); endwin();
printf("\nCannot unlink file\n"); printf("\nCannot unlink file\n");
@ -287,12 +287,12 @@ encwrite(char *start, unsigned int size, FILE *outf)
* perform an encrypted read * perform an encrypted read
*/ */
int int
encread(char *start, unsigned int size, int inf) encread(char *start, unsigned int size, FILE *inf)
{ {
register char *ep; register char *ep;
register int read_size; register int read_size;
if ((read_size = read(inf, start, size)) == -1 || read_size == 0) if ((read_size = fread(start, 1, size, inf)) == 0)
return read_size; return read_size;
ep = encstr; ep = encstr;

View file

@ -64,11 +64,11 @@
#include <string.h> #include <string.h>
#include "rogue.h" #include "rogue.h"
int rs_read_int(int inf, int *i); int rs_read_int(FILE *inf, int *i);
int rs_write_int(FILE *savef, int c); int rs_write_int(FILE *savef, int c);
int list_size(struct linked_list *l); int list_size(struct linked_list *l);
int rs_write_object_list(FILE *savef, struct linked_list *l); int rs_write_object_list(FILE *savef, struct linked_list *l);
int rs_read_object_list(int inf, struct linked_list **list); int rs_read_object_list(FILE *inf, struct linked_list **list);
#define READSTAT (format_error || read_error ) #define READSTAT (format_error || read_error )
#define WRITESTAT (write_error) #define WRITESTAT (write_error)
@ -92,7 +92,7 @@ rs_write(FILE *savef, void *ptr, size_t size)
} }
int int
rs_read(int inf, void *ptr, size_t size) rs_read(FILE *inf, void *ptr, size_t size)
{ {
if (read_error || format_error) if (read_error || format_error)
return(READSTAT); return(READSTAT);
@ -115,7 +115,7 @@ rs_write_uchar(FILE *savef, unsigned char c)
} }
int int
rs_read_uchar(int inf, unsigned char *c) rs_read_uchar(FILE *inf, unsigned char *c)
{ {
if (read_error || format_error) if (read_error || format_error)
return(READSTAT); return(READSTAT);
@ -137,7 +137,7 @@ rs_write_char(FILE *savef, char c)
} }
int int
rs_read_char(int inf, char *c) rs_read_char(FILE *inf, char *c)
{ {
if (read_error || format_error) if (read_error || format_error)
return(READSTAT); return(READSTAT);
@ -160,7 +160,7 @@ rs_write_chars(FILE *savef, char *c, int count)
} }
int int
rs_read_chars(int inf, char *i, int count) rs_read_chars(FILE *inf, char *i, int count)
{ {
int value = 0; int value = 0;
@ -201,7 +201,7 @@ rs_write_int(FILE *savef, int c)
} }
int int
rs_read_int(int inf, int *i) rs_read_int(FILE *inf, int *i)
{ {
unsigned char bytes[4]; unsigned char bytes[4];
int input = 0; int input = 0;
@ -244,7 +244,7 @@ rs_write_ints(FILE *savef, int *c, int count)
} }
int int
rs_read_ints(int inf, int *i, int count) rs_read_ints(FILE *inf, int *i, int count)
{ {
int n, value; int n, value;
@ -277,7 +277,7 @@ rs_write_boolean(FILE *savef, bool c)
} }
int int
rs_read_boolean(int inf, bool *i) rs_read_boolean(FILE *inf, bool *i)
{ {
unsigned char buf = 0; unsigned char buf = 0;
@ -309,7 +309,7 @@ rs_write_booleans(FILE *savef, bool *c, int count)
} }
int int
rs_read_booleans(int inf, bool *i, int count) rs_read_booleans(FILE *inf, bool *i, int count)
{ {
int n = 0, value = 0; int n = 0, value = 0;
@ -350,7 +350,7 @@ rs_write_short(FILE *savef, short c)
} }
int int
rs_read_short(int inf, short *i) rs_read_short(FILE *inf, short *i)
{ {
unsigned char bytes[2]; unsigned char bytes[2];
short input; short input;
@ -391,7 +391,7 @@ rs_write_shorts(FILE *savef, short *c, int count)
} }
int int
rs_read_shorts(int inf, short *i, int count) rs_read_shorts(FILE *inf, short *i, int count)
{ {
int n = 0, value = 0; int n = 0, value = 0;
@ -432,7 +432,7 @@ rs_write_ushort(FILE *savef, unsigned short c)
} }
int int
rs_read_ushort(int inf, unsigned short *i) rs_read_ushort(FILE *inf, unsigned short *i)
{ {
unsigned char bytes[2]; unsigned char bytes[2];
unsigned short input; unsigned short input;
@ -479,7 +479,7 @@ rs_write_uint(FILE *savef, unsigned int c)
} }
int int
rs_read_uint(int inf, unsigned int *i) rs_read_uint(FILE *inf, unsigned int *i)
{ {
unsigned char bytes[4]; unsigned char bytes[4];
int input; int input;
@ -535,7 +535,7 @@ rs_write_long(FILE *savef, long c)
} }
int int
rs_read_long(int inf, long *i) rs_read_long(FILE *inf, long *i)
{ {
unsigned char bytes[4]; unsigned char bytes[4];
long input; long input;
@ -577,7 +577,7 @@ rs_write_longs(FILE *savef, long *c, int count)
} }
int int
rs_read_longs(int inf, long *i, int count) rs_read_longs(FILE *inf, long *i, int count)
{ {
int n = 0, value = 0; int n = 0, value = 0;
@ -627,7 +627,7 @@ rs_write_ulong(FILE *savef, unsigned long c)
} }
int int
rs_read_ulong(int inf, unsigned long *i) rs_read_ulong(FILE *inf, unsigned long *i)
{ {
unsigned char bytes[4]; unsigned char bytes[4];
unsigned long input; unsigned long input;
@ -673,7 +673,7 @@ rs_write_ulongs(FILE *savef, unsigned long *c, int count)
} }
int int
rs_read_ulongs(int inf, unsigned long *i, int count) rs_read_ulongs(FILE *inf, unsigned long *i, int count)
{ {
int n = 0, value = 0; int n = 0, value = 0;
@ -704,7 +704,7 @@ rs_write_marker(FILE *savef, int id)
} }
int int
rs_read_marker(int inf, int id) rs_read_marker(FILE *inf, int id)
{ {
int nid; int nid;
@ -739,7 +739,7 @@ rs_write_string(FILE *savef, char *s)
} }
int int
rs_read_string(int inf, char *s, int max) rs_read_string(FILE *inf, char *s, int max)
{ {
int len = 0; int len = 0;
@ -757,7 +757,7 @@ rs_read_string(int inf, char *s, int max)
} }
int int
rs_read_new_string(int inf, char **s) rs_read_new_string(FILE *inf, char **s)
{ {
int len=0; int len=0;
char *buf=0; char *buf=0;
@ -802,7 +802,7 @@ rs_write_strings(FILE *savef, char *s[], int count)
} }
int int
rs_read_strings(int inf, char **s, int count, int max) rs_read_strings(FILE *inf, char **s, int count, int max)
{ {
int n = 0; int n = 0;
int value = 0; int value = 0;
@ -823,7 +823,7 @@ rs_read_strings(int inf, char **s, int count, int max)
} }
int int
rs_read_new_strings(int inf, char **s, int count) rs_read_new_strings(FILE *inf, char **s, int count)
{ {
int n = 0; int n = 0;
int value = 0; int value = 0;
@ -859,7 +859,7 @@ rs_write_string_index(FILE *savef, char *master[], int max, const char *str)
} }
int int
rs_read_string_index(int inf, char *master[], int maxindex, char **str) rs_read_string_index(FILE *inf, char *master[], int maxindex, char **str)
{ {
int i; int i;
@ -891,7 +891,7 @@ rs_write_coord(FILE *savef, coord c)
} }
int int
rs_read_coord(int inf, coord *c) rs_read_coord(FILE *inf, coord *c)
{ {
coord in; coord in;
@ -926,7 +926,7 @@ rs_write_coord_list(FILE *savef, struct linked_list *l)
} }
int int
rs_read_coord_list(int inf, struct linked_list **list) rs_read_coord_list(FILE *inf, struct linked_list **list)
{ {
int i, cnt; int i, cnt;
struct linked_list *l = NULL, *previous = NULL, *head = NULL; struct linked_list *l = NULL, *previous = NULL, *head = NULL;
@ -984,7 +984,7 @@ rs_write_window(FILE *savef, WINDOW *win)
} }
int int
rs_read_window(int inf, WINDOW *win) rs_read_window(FILE *inf, WINDOW *win)
{ {
int row,col,maxlines,maxcols,value,width,height; int row,col,maxlines,maxcols,value,width,height;
@ -1071,7 +1071,7 @@ rs_write_levtype(FILE *savef, LEVTYPE c)
} }
int int
rs_read_levtype(int inf, LEVTYPE *l) rs_read_levtype(FILE *inf, LEVTYPE *l)
{ {
int lt; int lt;
@ -1114,7 +1114,7 @@ rs_write_stats(FILE *savef, struct stats *s)
} }
int int
rs_read_stats(int inf, struct stats *s) rs_read_stats(FILE *inf, struct stats *s)
{ {
if (read_error || format_error) if (read_error || format_error)
return(READSTAT); return(READSTAT);
@ -1155,7 +1155,7 @@ rs_write_magic_items(FILE *savef, struct magic_item *i, int count)
} }
int int
rs_read_magic_items(int inf, struct magic_item *mi, int count) rs_read_magic_items(FILE *inf, struct magic_item *mi, int count)
{ {
int n; int n;
int value; int value;
@ -1196,7 +1196,7 @@ rs_write_scrolls(FILE *savef)
} }
int int
rs_read_scrolls(int inf) rs_read_scrolls(FILE *inf)
{ {
int i; int i;
@ -1232,7 +1232,7 @@ rs_write_potions(FILE *savef)
} }
int int
rs_read_potions(int inf) rs_read_potions(FILE *inf)
{ {
int i; int i;
@ -1268,7 +1268,7 @@ rs_write_rings(FILE *savef)
} }
int int
rs_read_rings(int inf) rs_read_rings(FILE *inf)
{ {
int i; int i;
@ -1316,7 +1316,7 @@ rs_write_sticks(FILE *savef)
} }
int int
rs_read_sticks(int inf) rs_read_sticks(FILE *inf)
{ {
int i = 0, j = 0, list = 0; int i = 0, j = 0, list = 0;
@ -1501,7 +1501,7 @@ rs_write_daemons(FILE *savef, struct delayed_action *d_list, int count)
} }
int int
rs_read_daemons(int inf, struct delayed_action *d_list, int count) rs_read_daemons(FILE *inf, struct delayed_action *d_list, int count)
{ {
int i = 0; int i = 0;
int func = 0; int func = 0;
@ -1643,7 +1643,7 @@ rs_write_room(FILE *savef, struct room *r)
} }
int int
rs_read_room(int inf, struct room *r) rs_read_room(FILE *inf, struct room *r)
{ {
int value = 0, n = 0, i = 0, index = 0, id = 0; int value = 0, n = 0, i = 0, index = 0, id = 0;
struct linked_list *fires=NULL, *item = NULL; struct linked_list *fires=NULL, *item = NULL;
@ -1700,7 +1700,7 @@ rs_write_rooms(FILE *savef, struct room r[], int count)
} }
int int
rs_read_rooms(int inf, struct room *r, int count) rs_read_rooms(FILE *inf, struct room *r, int count)
{ {
int value = 0, n = 0; int value = 0, n = 0;
@ -1736,7 +1736,7 @@ rs_write_room_reference(FILE *savef, struct room *rp)
} }
int int
rs_read_room_reference(int inf, struct room **rp) rs_read_room_reference(FILE *inf, struct room **rp)
{ {
int i; int i;
@ -1783,7 +1783,7 @@ rs_write_door_reference(FILE *savef, coord *exit)
} }
int int
rs_read_door_reference(int inf, coord **exit) rs_read_door_reference(FILE *inf, coord **exit)
{ {
int i, idx; int i, idx;
@ -1818,7 +1818,7 @@ rs_write_traps(FILE *savef, struct trap *trap,int count)
} }
int int
rs_read_traps(int inf, struct trap *trap, int count) rs_read_traps(FILE *inf, struct trap *trap, int count)
{ {
int id = 0, value = 0, n = 0; int id = 0, value = 0, n = 0;
@ -1865,7 +1865,7 @@ rs_write_monsters(FILE *savef, struct monster *m, int count)
} }
int int
rs_read_monsters(int inf, struct monster *m, int count) rs_read_monsters(FILE *inf, struct monster *m, int count)
{ {
int value = 0, n = 0; int value = 0, n = 0;
@ -1917,7 +1917,7 @@ rs_write_object(FILE *savef, struct object *o)
} }
int int
rs_read_object(int inf, struct object *o) rs_read_object(FILE *inf, struct object *o)
{ {
if (read_error || format_error) if (read_error || format_error)
return(READSTAT); return(READSTAT);
@ -1958,7 +1958,7 @@ rs_write_object_list(FILE *savef, struct linked_list *l)
} }
int int
rs_read_object_list(int inf, struct linked_list **list) rs_read_object_list(FILE *inf, struct linked_list **list)
{ {
int i, cnt; int i, cnt;
struct linked_list *l = NULL, *previous = NULL, *head = NULL; struct linked_list *l = NULL, *previous = NULL, *head = NULL;
@ -2010,7 +2010,7 @@ rs_write_object_reference(FILE *savef, struct linked_list *list, struct object *
} }
int int
rs_read_object_reference(int inf, struct linked_list *list, struct object **item) rs_read_object_reference(FILE *inf, struct linked_list *list, struct object **item)
{ {
int i; int i;
@ -2156,7 +2156,7 @@ rs_write_thing(FILE *savef, struct thing *t)
} }
int int
rs_read_thing(int inf, struct thing *t) rs_read_thing(FILE *inf, struct thing *t)
{ {
int listid = 0, index = -1; int listid = 0, index = -1;
@ -2275,7 +2275,7 @@ rs_write_thing_list(FILE *savef, struct linked_list *l)
} }
int int
rs_read_thing_list(int inf, struct linked_list **list) rs_read_thing_list(FILE *inf, struct linked_list **list)
{ {
int i, cnt; int i, cnt;
struct linked_list *l = NULL, *previous = NULL, *head = NULL; struct linked_list *l = NULL, *previous = NULL, *head = NULL;
@ -2444,7 +2444,7 @@ rs_save_file(FILE *savef)
} }
int int
rs_restore_file(int inf) rs_restore_file(FILE *inf)
{ {
int i; int i;

View file

@ -16,6 +16,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <signal.h> #include <signal.h>
#include <errno.h>
#ifdef BSD #ifdef BSD
#include <sys/time.h> #include <sys/time.h>
#else #else
@ -550,11 +551,21 @@ setup(void)
nonl(); nonl();
} }
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 void
open_records(void) open_records(void)
{ {
if (scorefd == -1) if (scoreboard == NULL)
md_reopen_score(); reopen_score();
#ifdef LOGFILE #ifdef LOGFILE
if (logfile == NULL) if (logfile == NULL)
logfile = fopen(LOGFILE, "a"); logfile = fopen(LOGFILE, "a");

View file

@ -155,10 +155,10 @@ md_raw_standend(void)
} }
int int
md_unlink_open_file(char *file, int inf) md_unlink_open_file(char *file, FILE *inf)
{ {
#ifdef _WIN32 #ifdef _WIN32
close(inf); fclose(inf);
chmod(file, 0600); chmod(file, 0600);
return( _unlink(file) ); return( _unlink(file) );
#else #else
@ -677,17 +677,6 @@ md_flushinp(void)
#endif #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 Cursor/Keypad Support

View file

@ -497,7 +497,7 @@ get_score(char *optstr, WINDOW *win)
status = get_str(optstr, win); status = get_str(optstr, win);
if (status == NORM && strcmp(old_score_file, optstr)) if (status == NORM && strcmp(old_score_file, optstr))
{ {
md_reopen_score(); reopen_score();
} }
return status; return status;
} }

View file

@ -46,9 +46,6 @@ extern struct uwdata wdata, oldwin;
extern char oldtext[WTXTNUM][WTXTLEN]; extern char oldtext[WTXTNUM][WTXTLEN];
#endif #endif
extern int scorefd;
extern FILE *logfile;
#ifdef NUMNET #ifdef NUMNET
/* Network machines (for mutual score keeping) */ /* Network machines (for mutual score keeping) */
static struct network Network[NUMNET] = { static struct network Network[NUMNET] = {
@ -256,10 +253,8 @@ score(unsigned long amount, int flags, short monst)
register struct sc_ent *scp; register struct sc_ent *scp;
register int i; register int i;
register struct sc_ent *sc2; register struct sc_ent *sc2;
register int outfd;
register char *killer; register char *killer;
register int prflags = 0; register int prflags = 0;
register int fd;
short upquest, wintype, uplevel, uptype; /* For network updating */ short upquest, wintype, uplevel, uptype; /* For network updating */
char upsystem[SYSLEN], uplogin[LOGLEN]; char upsystem[SYSLEN], uplogin[LOGLEN];
char *thissys; /* Holds the name of this system */ char *thissys; /* Holds the name of this system */
@ -290,11 +285,10 @@ score(unsigned long amount, int flags, short monst)
purse = 0; /* Steal all the gold */ purse = 0; /* Steal all the gold */
/* /*
* Open file and read list * Read list
*/ */
if ((fd = scorefd) < 0) return; if (scoreboard == NULL) return;
outfd = fd;
#ifndef SYSTEM #ifndef SYSTEM
thissys = md_gethostname(); thissys = md_gethostname();
@ -347,10 +341,10 @@ score(unsigned long amount, int flags, short monst)
/* Read the score and convert it to a compatible format */ /* Read the score and convert it to a compatible format */
for(i = 0; i < NUMSCORE; i++) for(i = 0; i < NUMSCORE; i++)
{ {
encread(top_ten[i].sc_name, NAMELEN, fd); encread(top_ten[i].sc_name, NAMELEN, scoreboard);
encread(top_ten[i].sc_system, SYSLEN, fd); encread(top_ten[i].sc_system, SYSLEN, scoreboard);
encread(top_ten[i].sc_login, LOGLEN, fd); encread(top_ten[i].sc_login, LOGLEN, scoreboard);
encread(scoreline, 100, fd); encread(scoreline, 100, scoreboard);
sscanf(scoreline, " %lu %hd %hd %hd %hd %hd \n", sscanf(scoreline, " %lu %hd %hd %hd %hd %hd \n",
&top_ten[i].sc_score, &top_ten[i].sc_flags, &top_ten[i].sc_score, &top_ten[i].sc_flags,
&top_ten[i].sc_level, &top_ten[i].sc_ctype, &top_ten[i].sc_level, &top_ten[i].sc_ctype,
@ -383,7 +377,7 @@ score(unsigned long amount, int flags, short monst)
errors++; errors++;
if (errors) { if (errors) {
close(outfd); fclose(scoreboard);
free(compatstr); free(compatstr);
return; return;
} }
@ -646,7 +640,7 @@ score(unsigned long amount, int flags, short monst)
} }
/* if (prflags == EDITSCORE) endwin();*/ /* End editing windowing */ /* if (prflags == EDITSCORE) endwin();*/ /* End editing windowing */
} }
lseek(outfd, 0L, 0); fseek(scoreboard, 0L, SEEK_SET);
/* /*
* Update the list file * Update the list file
*/ */
@ -654,17 +648,17 @@ score(unsigned long amount, int flags, short monst)
for(i = 0; i < NUMSCORE; i++) for(i = 0; i < NUMSCORE; i++)
{ {
memset(scoreline,0,100); memset(scoreline,0,100);
encwrite(top_ten[i].sc_name, NAMELEN, outfd); encwrite(top_ten[i].sc_name, NAMELEN, scoreboard);
encwrite(top_ten[i].sc_system, SYSLEN, outfd); encwrite(top_ten[i].sc_system, SYSLEN, scoreboard);
encwrite(top_ten[i].sc_login, LOGLEN, outfd); encwrite(top_ten[i].sc_login, LOGLEN, scoreboard);
sprintf(scoreline, " %lu %hd %hd %hd %hd %hd \n", sprintf(scoreline, " %lu %hd %hd %hd %hd %hd \n",
top_ten[i].sc_score, top_ten[i].sc_flags, top_ten[i].sc_score, top_ten[i].sc_flags,
top_ten[i].sc_level, top_ten[i].sc_ctype, top_ten[i].sc_level, top_ten[i].sc_ctype,
top_ten[i].sc_monster, top_ten[i].sc_quest); top_ten[i].sc_monster, top_ten[i].sc_quest);
encwrite(scoreline,100,outfd); encwrite(scoreline,100,scoreboard);
} }
close(outfd); fclose(scoreboard);
} }
/* /*

View file

@ -80,7 +80,6 @@ int pray_time = 0;
int spell_power = 0; int spell_power = 0;
int turns = 0; /* Number of turns player has taken */ int turns = 0; /* Number of turns player has taken */
int quest_item = 0; /* Item player is looking for */ int quest_item = 0; /* Item player is looking for */
int scorefd = -1; /* File descriptor for score file */
int cols = 0; /* number of columns in terminal */ int cols = 0; /* number of columns in terminal */
int lines = 0; /* number of lines on the terminal */ int lines = 0; /* number of lines on the terminal */
char nfloors = -1; /* Number of floors in this dungeon */ char nfloors = -1; /* Number of floors in this dungeon */
@ -134,6 +133,7 @@ bool askme = TRUE;
bool in_shell = FALSE; bool in_shell = FALSE;
bool daytime = TRUE; bool daytime = TRUE;
bool use_savedir = FALSE; bool use_savedir = FALSE;
FILE *scoreboard = NULL; /* Score file */
FILE *logfile = NULL; FILE *logfile = NULL;
LEVTYPE levtype; /* type of level i'm on */ LEVTYPE levtype; /* type of level i'm on */

View file

@ -1208,8 +1208,8 @@ void eat(void);
void eat_gold(struct object *obj); void eat_gold(struct object *obj);
int effect(struct thing *att, struct thing *def, struct object *weap, int effect(struct thing *att, struct thing *def, struct object *weap,
bool thrown, bool see_att, bool see_def); bool thrown, bool see_att, bool see_def);
int encread(char *start, unsigned int size, int inf); int encread(char *start, unsigned int size, FILE *inf);
int encwrite(char *start, unsigned int size, int outf); int encwrite(char *start, unsigned int size, FILE *outf);
void endmsg(void); void endmsg(void);
void explode(struct thing *tp); void explode(struct thing *tp);
void extinguish(void (*func)()); void extinguish(void (*func)());
@ -1314,6 +1314,7 @@ void raise_level(void);
short randmonster(bool wander, bool no_unique); short randmonster(bool wander, bool no_unique);
void read_scroll(int which, int flag, bool is_scroll); void read_scroll(int which, int flag, bool is_scroll);
int readchar(void); int readchar(void);
void reopen_score(void);
void res_charisma(int howmuch); void res_charisma(int howmuch);
void res_constitution(int howmuch); void res_constitution(int howmuch);
void res_dexterity(int howmuch); void res_dexterity(int howmuch);
@ -1335,7 +1336,7 @@ coord *rndmove(struct thing *who);
int roll(int number, int sides); int roll(int number, int sides);
void rollwand(void); void rollwand(void);
struct room *roomin(coord *cp); struct room *roomin(coord *cp);
int rs_restore_file(int inf); int rs_restore_file(FILE *inf);
int rs_save_file(FILE *savef); int rs_save_file(FILE *savef);
int runners(int segments); int runners(int segments);
void runto(struct thing *runner, coord *spot); void runto(struct thing *runner, coord *spot);
@ -1419,12 +1420,11 @@ long md_memused(void);
int md_normaluser(void); int md_normaluser(void);
int md_rand(void); int md_rand(void);
unsigned int md_random_seed(void); unsigned int md_random_seed(void);
void md_reopen_score(void);
int md_readchar(WINDOW *win); int md_readchar(WINDOW *win);
int md_shellescape(void); int md_shellescape(void);
int md_srand(int seed); int md_srand(int seed);
int md_unlink(char *file); int md_unlink(char *file);
int md_unlink_open_file(char *file, int inf); int md_unlink_open_file(char *file, FILE *inf);
#ifdef CHECKTIME #ifdef CHECKTIME
int checkout(); int checkout();
@ -1504,7 +1504,6 @@ extern int pray_time; /* Number of prayer points/exp level */
extern int spell_power; /* Spell power left at this level */ extern int spell_power; /* Spell power left at this level */
extern int turns; /* Number of turns player has taken */ extern int turns; /* Number of turns player has taken */
extern int quest_item; /* Item hero is looking for */ extern int quest_item; /* Item hero is looking for */
extern int scorefd; /* File descriptor for score file */
extern int cur_relic[]; /* Current relics */ extern int cur_relic[]; /* Current relics */
extern char take; /* Thing the rogue is taking */ extern char take; /* Thing the rogue is taking */
extern char prbuf[]; /* Buffer for sprintfs */ extern char prbuf[]; /* Buffer for sprintfs */
@ -1565,6 +1564,7 @@ extern char *spacemsg;
extern char *morestr; extern char *morestr;
extern char *retstr; extern char *retstr;
extern FILE *logfile; extern FILE *logfile;
extern FILE *scoreboard; /* Score file */
extern LEVTYPE levtype; extern LEVTYPE levtype;
extern void (*add_abil[NUMABILITIES])(); /* Functions to change abilities */ extern void (*add_abil[NUMABILITIES])(); /* Functions to change abilities */
extern void (*res_abil[NUMABILITIES])(); /* Functions to change abilities */ extern void (*res_abil[NUMABILITIES])(); /* Functions to change abilities */

View file

@ -34,15 +34,15 @@ extern struct uwdata wdata;
#endif #endif
#if u370 || uts #if u370 || uts
#define ENCREAD(b,n,fd) read(fd,b,n) #define ENCREAD(b,n,f) read(md_fileno(f),b,n)
#define ENCWRITE(b,n,fd) write(fd,b,n) #define ENCWRITE(b,n,f) write(md_fileno(f),b,n)
#endif #endif
#ifndef ENCREAD #ifndef ENCREAD
#define ENCREAD encread #define ENCREAD encread
#define ENCWRITE encwrite #define ENCWRITE encwrite
#endif #endif
bool save_file(int savefd); bool save_file(FILE *savef);
typedef struct stat STAT; typedef struct stat STAT;
@ -55,7 +55,7 @@ STAT sbuf;
bool bool
save_game(void) save_game(void)
{ {
register int savefd; FILE *savefi = NULL;
register int c; register int c;
char buf[LINELEN]; char buf[LINELEN];
@ -100,18 +100,18 @@ save_game(void)
} }
strcpy(file_name, buf); strcpy(file_name, buf);
gotfile: gotfile:
if ((savefd = open(file_name, O_WRONLY|O_CREAT|O_TRUNC,0666)) < 0) if ((savefi = fopen(file_name, "w")) == NULL)
{ {
msg(strerror(errno)); /* fake perror() */ msg(strerror(errno)); /* fake perror() */
if (use_savedir) if (use_savedir)
return FALSE; return FALSE;
} }
} while (savefd < 0); } while (savefi == NULL);
/* /*
* write out encrpyted file (after a stat) * write out encrpyted file (after a stat)
*/ */
if (save_file(savefd) == FALSE) { if (save_file(savefi) == FALSE) {
msg("Cannot create save file."); msg("Cannot create save file.");
md_unlink(file_name); md_unlink(file_name);
return(FALSE); return(FALSE);
@ -126,15 +126,15 @@ gotfile:
void void
auto_save(int sig) auto_save(int sig)
{ {
register int savefd; FILE *savefi;
register int i; register int i;
for (i = 0; i < NSIG; i++) for (i = 0; i < NSIG; i++)
signal(i, SIG_IGN); signal(i, SIG_IGN);
if (file_name[0] != '\0' && if (file_name[0] != '\0' &&
pstats.s_hpt > 0 && pstats.s_hpt > 0 &&
(savefd = open(file_name, O_WRONLY|O_CREAT|O_TRUNC, 0600)) >= 0) (savefi = fopen(file_name, "w")) != NULL)
save_file(savefd); save_file(savefi);
endwin(); endwin();
#ifdef PC7300 #ifdef PC7300
endhardwin(); endhardwin();
@ -146,21 +146,19 @@ auto_save(int sig)
* write the saved game on the file * write the saved game on the file
*/ */
bool bool
save_file(int savefd) save_file(FILE *savef)
{ {
register unsigned num_to_write, num_written; register unsigned num_to_write, num_written;
FILE *savef;
int ret; int ret;
wmove(cw, lines-1, 0); wmove(cw, lines-1, 0);
draw(cw); draw(cw);
lseek(savefd, 0L, 0); fseek(savef, 0L, SEEK_SET);
fstat(savefd, &sbuf); stat(file_name, &sbuf);
num_to_write = strlen(version) + 1; num_to_write = strlen(version) + 1;
num_written = ENCWRITE(version, num_to_write, savefd); num_written = ENCWRITE(version, num_to_write, savef);
sprintf(prbuf,"%d x %d\n", LINES, COLS); sprintf(prbuf,"%d x %d\n", LINES, COLS);
ENCWRITE(prbuf,80,savefd); ENCWRITE(prbuf,80,savef);
savef = (FILE *) md_fdopen(savefd,"wb");
ret = rs_save_file(savef); ret = rs_save_file(savef);
fclose(savef); fclose(savef);
if (num_to_write == num_written && ret == 0) return(TRUE); if (num_to_write == num_written && ret == 0) return(TRUE);
@ -170,7 +168,7 @@ save_file(int savefd)
bool bool
restore(char *file, char *envp[]) restore(char *file, char *envp[])
{ {
register int inf; FILE *inf;
extern char **environ; extern char **environ;
char buf[LINELEN]; char buf[LINELEN];
STAT sbuf2; STAT sbuf2;
@ -178,7 +176,7 @@ restore(char *file, char *envp[])
if (strcmp(file, "-r") == 0) if (strcmp(file, "-r") == 0)
file = file_name; file = file_name;
if ((inf = open(file, 0)) < 0) if ((inf = fopen(file, "r")) == NULL)
{ {
if (use_savedir && errno == ENOENT) if (use_savedir && errno == ENOENT)
{ {
@ -202,7 +200,7 @@ restore(char *file, char *envp[])
ENCREAD(buf, 80, inf); ENCREAD(buf, 80, inf);
sscanf(buf, "%d x %d\n", &oldline, &oldcol); sscanf(buf, "%d x %d\n", &oldline, &oldcol);
fstat(inf, &sbuf2); stat(file, &sbuf2);
fflush(stdout); fflush(stdout);
initscr(); initscr();
@ -228,7 +226,7 @@ restore(char *file, char *envp[])
if (rs_restore_file(inf) != 0) if (rs_restore_file(inf) != 0)
{ {
printf("Cannot restore file\n"); printf("Cannot restore file\n");
close(inf); fclose(inf);
return(FALSE); return(FALSE);
} }
@ -265,7 +263,7 @@ restore(char *file, char *envp[])
* perform an encrypted write * perform an encrypted write
*/ */
int int
encwrite(char *start, unsigned int size, int outf) encwrite(char *start, unsigned int size, FILE *outf)
{ {
register char *ep; register char *ep;
register int i = 0; register int i = 0;
@ -281,7 +279,7 @@ encwrite(char *start, unsigned int size, int outf)
ep = encstr; ep = encstr;
if (i == ENCWBSIZ || size == 0) { if (i == ENCWBSIZ || size == 0) {
if (write(outf, buf, (unsigned)i) < i) if (fwrite(buf, 1, (unsigned)i, outf) < i)
return(num_written); return(num_written);
else { else {
num_written += i; num_written += i;
@ -296,12 +294,12 @@ encwrite(char *start, unsigned int size, int outf)
* perform an encrypted read * perform an encrypted read
*/ */
int int
encread(char *start, unsigned int size, int inf) encread(char *start, unsigned int size, FILE *inf)
{ {
register char *ep; register char *ep;
register int read_size; register int read_size;
if ((read_size = read(inf, start, size)) == -1 || read_size == 0) if ((read_size = fread(start, 1, size, inf)) == 0)
return read_size; return read_size;
ep = encstr; ep = encstr;

View file

@ -75,9 +75,9 @@ static int endian = 0x01020304;
int list_size(struct linked_list *l); int list_size(struct linked_list *l);
int rs_write_int(FILE *savef, int c); int rs_write_int(FILE *savef, int c);
int rs_read_int(int inf, int *i); int rs_read_int(FILE *inf, int *i);
int rs_write_object_list(FILE *savef, struct linked_list *l); int rs_write_object_list(FILE *savef, struct linked_list *l);
int rs_read_object_list(int inf, struct linked_list **list); int rs_read_object_list(FILE *inf, struct linked_list **list);
int int
rs_write(FILE *savef, void *ptr, size_t size) rs_write(FILE *savef, void *ptr, size_t size)
@ -85,14 +85,14 @@ rs_write(FILE *savef, void *ptr, size_t size)
if (write_error) if (write_error)
return(WRITESTAT); return(WRITESTAT);
if (encwrite(ptr, size, md_fileno(savef)) != size) if (encwrite(ptr, size, savef) != size)
write_error = 1; write_error = 1;
return(WRITESTAT); return(WRITESTAT);
} }
int int
rs_read(int inf, void *ptr, size_t size) rs_read(FILE *inf, void *ptr, size_t size)
{ {
if (read_error || format_error) if (read_error || format_error)
return(READSTAT); return(READSTAT);
@ -115,7 +115,7 @@ rs_write_uchar(FILE *savef, unsigned char c)
} }
int int
rs_read_uchar(int inf, unsigned char *c) rs_read_uchar(FILE *inf, unsigned char *c)
{ {
if (read_error || format_error) if (read_error || format_error)
return(READSTAT); return(READSTAT);
@ -137,7 +137,7 @@ rs_write_char(FILE *savef, char c)
} }
int int
rs_read_char(int inf, char *c) rs_read_char(FILE *inf, char *c)
{ {
if (read_error || format_error) if (read_error || format_error)
return(READSTAT); return(READSTAT);
@ -160,7 +160,7 @@ rs_write_chars(FILE *savef, char *c, int count)
} }
int int
rs_read_chars(int inf, char *i, int count) rs_read_chars(FILE *inf, char *i, int count)
{ {
int value = 0; int value = 0;
@ -201,7 +201,7 @@ rs_write_int(FILE *savef, int c)
} }
int int
rs_read_int(int inf, int *i) rs_read_int(FILE *inf, int *i)
{ {
unsigned char bytes[4]; unsigned char bytes[4];
int input = 0; int input = 0;
@ -244,7 +244,7 @@ rs_write_ints(FILE *savef, int *c, int count)
} }
int int
rs_read_ints(int inf, int *i, int count) rs_read_ints(FILE *inf, int *i, int count)
{ {
int n, value; int n, value;
@ -277,7 +277,7 @@ rs_write_boolean(FILE *savef, bool c)
} }
int int
rs_read_boolean(int inf, bool *i) rs_read_boolean(FILE *inf, bool *i)
{ {
unsigned char buf = 0; unsigned char buf = 0;
@ -309,7 +309,7 @@ rs_write_booleans(FILE *savef, bool *c, int count)
} }
int int
rs_read_booleans(int inf, bool *i, int count) rs_read_booleans(FILE *inf, bool *i, int count)
{ {
int n = 0, value = 0; int n = 0, value = 0;
@ -350,7 +350,7 @@ rs_write_short(FILE *savef, short c)
} }
int int
rs_read_short(int inf, short *i) rs_read_short(FILE *inf, short *i)
{ {
unsigned char bytes[2]; unsigned char bytes[2];
short input; short input;
@ -391,7 +391,7 @@ rs_write_shorts(FILE *savef, short *c, int count)
} }
int int
rs_read_shorts(int inf, short *i, int count) rs_read_shorts(FILE *inf, short *i, int count)
{ {
int n = 0, value = 0; int n = 0, value = 0;
@ -432,7 +432,7 @@ rs_write_ushort(FILE *savef, unsigned short c)
} }
int int
rs_read_ushort(int inf, unsigned short *i) rs_read_ushort(FILE *inf, unsigned short *i)
{ {
unsigned char bytes[2]; unsigned char bytes[2];
unsigned short input; unsigned short input;
@ -479,7 +479,7 @@ rs_write_uint(FILE *savef, unsigned int c)
} }
int int
rs_read_uint(int inf, unsigned int *i) rs_read_uint(FILE *inf, unsigned int *i)
{ {
unsigned char bytes[4]; unsigned char bytes[4];
int input; int input;
@ -535,7 +535,7 @@ rs_write_long(FILE *savef, long c)
} }
int int
rs_read_long(int inf, long *i) rs_read_long(FILE *inf, long *i)
{ {
unsigned char bytes[4]; unsigned char bytes[4];
long input; long input;
@ -580,7 +580,7 @@ rs_write_longs(FILE *savef, long *c, int count)
} }
int int
rs_read_longs(int inf, long *i, int count) rs_read_longs(FILE *inf, long *i, int count)
{ {
int n = 0, value = 0; int n = 0, value = 0;
@ -630,7 +630,7 @@ rs_write_ulong(FILE *savef, unsigned long c)
} }
int int
rs_read_ulong(int inf, unsigned long *i) rs_read_ulong(FILE *inf, unsigned long *i)
{ {
unsigned char bytes[4]; unsigned char bytes[4];
unsigned long input; unsigned long input;
@ -676,7 +676,7 @@ rs_write_ulongs(FILE *savef, unsigned long *c, int count)
} }
int int
rs_read_ulongs(int inf, unsigned long *i, int count) rs_read_ulongs(FILE *inf, unsigned long *i, int count)
{ {
int n = 0, value = 0; int n = 0, value = 0;
@ -707,7 +707,7 @@ rs_write_marker(FILE *savef, int id)
} }
int int
rs_read_marker(int inf, int id) rs_read_marker(FILE *inf, int id)
{ {
int nid; int nid;
@ -742,7 +742,7 @@ rs_write_string(FILE *savef, char *s)
} }
int int
rs_read_string(int inf, char *s, int max) rs_read_string(FILE *inf, char *s, int max)
{ {
int len = 0; int len = 0;
@ -760,7 +760,7 @@ rs_read_string(int inf, char *s, int max)
} }
int int
rs_read_new_string(int inf, char **s) rs_read_new_string(FILE *inf, char **s)
{ {
int len=0; int len=0;
char *buf=0; char *buf=0;
@ -805,7 +805,7 @@ rs_write_strings(FILE *savef, char *s[], int count)
} }
int int
rs_read_strings(int inf, char **s, int count, int max) rs_read_strings(FILE *inf, char **s, int count, int max)
{ {
int n = 0; int n = 0;
int value = 0; int value = 0;
@ -826,7 +826,7 @@ rs_read_strings(int inf, char **s, int count, int max)
} }
int int
rs_read_new_strings(int inf, char **s, int count) rs_read_new_strings(FILE *inf, char **s, int count)
{ {
int n = 0; int n = 0;
int value = 0; int value = 0;
@ -862,7 +862,7 @@ rs_write_string_index(FILE *savef, char *master[], int max, const char *str)
} }
int int
rs_read_string_index(int inf, char *master[], int maxindex, char **str) rs_read_string_index(FILE *inf, char *master[], int maxindex, char **str)
{ {
int i; int i;
@ -894,7 +894,7 @@ rs_write_coord(FILE *savef, coord c)
} }
int int
rs_read_coord(int inf, coord *c) rs_read_coord(FILE *inf, coord *c)
{ {
coord in; coord in;
@ -929,7 +929,7 @@ rs_write_coord_list(FILE *savef, struct linked_list *l)
} }
int int
rs_read_coord_list(int inf, struct linked_list **list) rs_read_coord_list(FILE *inf, struct linked_list **list)
{ {
int i, cnt; int i, cnt;
struct linked_list *l = NULL, *previous = NULL, *head = NULL; struct linked_list *l = NULL, *previous = NULL, *head = NULL;
@ -987,7 +987,7 @@ rs_write_window(FILE *savef, WINDOW *win)
} }
int int
rs_read_window(int inf, WINDOW *win) rs_read_window(FILE *inf, WINDOW *win)
{ {
int row,col,maxlines,maxcols,value,width,height; int row,col,maxlines,maxcols,value,width,height;
@ -1075,7 +1075,7 @@ rs_write_levtype(FILE *savef, LEVTYPE c)
} }
int int
rs_read_levtype(int inf, LEVTYPE *l) rs_read_levtype(FILE *inf, LEVTYPE *l)
{ {
int lt; int lt;
@ -1120,7 +1120,7 @@ rs_write_stats(FILE *savef, struct stats *s)
} }
int int
rs_read_stats(int inf, struct stats *s) rs_read_stats(FILE *inf, struct stats *s)
{ {
if (read_error || format_error) if (read_error || format_error)
return(READSTAT); return(READSTAT);
@ -1165,7 +1165,7 @@ rs_write_magic_items(FILE *savef, struct magic_item *i, int count)
} }
int int
rs_read_magic_items(int inf, struct magic_item *mi, int count) rs_read_magic_items(FILE *inf, struct magic_item *mi, int count)
{ {
int n; int n;
int value; int value;
@ -1210,7 +1210,7 @@ rs_write_scrolls(FILE *savef)
} }
int int
rs_read_scrolls(int inf) rs_read_scrolls(FILE *inf)
{ {
int i; int i;
@ -1246,7 +1246,7 @@ rs_write_potions(FILE *savef)
} }
int int
rs_read_potions(int inf) rs_read_potions(FILE *inf)
{ {
int i; int i;
@ -1282,7 +1282,7 @@ rs_write_rings(FILE *savef)
} }
int int
rs_read_rings(int inf) rs_read_rings(FILE *inf)
{ {
int i; int i;
@ -1317,7 +1317,7 @@ rs_write_misc(FILE *savef)
} }
int int
rs_read_misc(int inf) rs_read_misc(FILE *inf)
{ {
int i; int i;
@ -1364,7 +1364,7 @@ rs_write_sticks(FILE *savef)
} }
int int
rs_read_sticks(int inf) rs_read_sticks(FILE *inf)
{ {
int i = 0, j = 0, list = 0; int i = 0, j = 0, list = 0;
@ -1588,7 +1588,7 @@ rs_write_daemons(FILE *savef, struct delayed_action *d_list, int count)
} }
int int
rs_read_daemons(int inf, struct delayed_action *d_list, int count) rs_read_daemons(FILE *inf, struct delayed_action *d_list, int count)
{ {
int i = 0; int i = 0;
int func = 0; int func = 0;
@ -1774,7 +1774,7 @@ rs_write_room(FILE *savef, struct room *r)
} }
int int
rs_read_room(int inf, struct room *r) rs_read_room(FILE *inf, struct room *r)
{ {
int value = 0, n = 0, i = 0, index = 0, id = 0; int value = 0, n = 0, i = 0, index = 0, id = 0;
struct linked_list *fires=NULL, *item = NULL; struct linked_list *fires=NULL, *item = NULL;
@ -1831,7 +1831,7 @@ rs_write_rooms(FILE *savef, struct room r[], int count)
} }
int int
rs_read_rooms(int inf, struct room *r, int count) rs_read_rooms(FILE *inf, struct room *r, int count)
{ {
int value = 0, n = 0; int value = 0, n = 0;
@ -1867,7 +1867,7 @@ rs_write_room_reference(FILE *savef, struct room *rp)
} }
int int
rs_read_room_reference(int inf, struct room **rp) rs_read_room_reference(FILE *inf, struct room **rp)
{ {
int i; int i;
@ -1911,7 +1911,7 @@ rs_write_door_reference(FILE *savef, coord *exit)
} }
int int
rs_read_door_reference(int inf, coord **exit) rs_read_door_reference(FILE *inf, coord **exit)
{ {
int i, idx; int i, idx;
@ -1945,7 +1945,7 @@ rs_write_traps(FILE *savef, struct trap *trap,int count)
} }
int int
rs_read_traps(int inf, struct trap *trap, int count) rs_read_traps(FILE *inf, struct trap *trap, int count)
{ {
int id = 0, value = 0, n = 0; int id = 0, value = 0, n = 0;
@ -1992,7 +1992,7 @@ rs_write_monsters(FILE *savef, struct monster *m, int count)
} }
int int
rs_read_monsters(int inf, struct monster *m, int count) rs_read_monsters(FILE *inf, struct monster *m, int count)
{ {
int value = 0, n = 0; int value = 0, n = 0;
@ -2044,7 +2044,7 @@ rs_write_object(FILE *savef, struct object *o)
} }
int int
rs_read_object(int inf, struct object *o) rs_read_object(FILE *inf, struct object *o)
{ {
if (read_error || format_error) if (read_error || format_error)
return(READSTAT); return(READSTAT);
@ -2085,7 +2085,7 @@ rs_write_object_list(FILE *savef, struct linked_list *l)
} }
int int
rs_read_object_list(int inf, struct linked_list **list) rs_read_object_list(FILE *inf, struct linked_list **list)
{ {
int i, cnt; int i, cnt;
struct linked_list *l = NULL, *previous = NULL, *head = NULL; struct linked_list *l = NULL, *previous = NULL, *head = NULL;
@ -2137,7 +2137,7 @@ rs_write_object_reference(FILE *savef, struct linked_list *list, struct object *
} }
int int
rs_read_object_reference(int inf, struct linked_list *list, struct object **item) rs_read_object_reference(FILE *inf, struct linked_list *list, struct object **item)
{ {
int i; int i;
@ -2280,7 +2280,7 @@ rs_write_thing(FILE *savef, struct thing *t)
} }
int int
rs_read_thing(int inf, struct thing *t) rs_read_thing(FILE *inf, struct thing *t)
{ {
int listid = 0, index = -1; int listid = 0, index = -1;
@ -2395,7 +2395,7 @@ rs_write_thing_list(FILE *savef, struct linked_list *l)
} }
int int
rs_read_thing_list(int inf, struct linked_list **list) rs_read_thing_list(FILE *inf, struct linked_list **list)
{ {
int i, cnt; int i, cnt;
struct linked_list *l = NULL, *previous = NULL, *head = NULL; struct linked_list *l = NULL, *previous = NULL, *head = NULL;
@ -2462,7 +2462,7 @@ rs_write_thing_reference(FILE *savef, struct linked_list *list, struct thing *it
} }
int int
rs_read_thing_reference(int inf, struct linked_list *list, struct thing **item) rs_read_thing_reference(FILE *inf, struct linked_list *list, struct thing **item)
{ {
int i; int i;
@ -2494,7 +2494,7 @@ rs_write_thing_references(FILE *savef, struct linked_list *list, struct thing *i
} }
int int
rs_read_thing_references(int inf, struct linked_list *list, struct thing *items[], int count) rs_read_thing_references(FILE *inf, struct linked_list *list, struct thing *items[], int count)
{ {
int i; int i;
@ -2635,7 +2635,7 @@ rs_save_file(FILE *savef)
} }
int int
rs_restore_file(int inf) rs_restore_file(FILE *inf)
{ {
int i; int i;

View file

@ -100,8 +100,6 @@ int quiet = 0; /* Number of quiet turns */
int food_left; /* Amount of food in hero's stomach */ int food_left; /* Amount of food in hero's stomach */
int group = 2; /* Current group number */ int group = 2; /* Current group number */
int hungry_state = 0; /* How hungry is he */ int hungry_state = 0; /* How hungry is he */
int fd; /* File descriptor for score file */
int lfd; /* File descriptor for log file */
int a_chances[MAXARMORS] = { /* Chance for each armor type */ int a_chances[MAXARMORS] = { /* Chance for each armor type */
20, 20,
35, 35,
@ -136,6 +134,9 @@ THING *lvl_obj = NULL; /* List of objects on this level */
THING *mlist = NULL; /* List of monsters on the level */ THING *mlist = NULL; /* List of monsters on the level */
THING *_monst[MAXLINES*MAXCOLS]; /* Pointers for monsters at each spot */ THING *_monst[MAXLINES*MAXCOLS]; /* Pointers for monsters at each spot */
FILE *score_file = NULL; /* Scoreboard */
FILE *log_file = NULL; /* Log file */
WINDOW *hw; /* Used as a scratch window */ WINDOW *hw; /* Used as a scratch window */
#define INIT_STATS { 16, 0, 1, 10, 12, "1d4", 12 } #define INIT_STATS { 16, 0, 1, 10, 12, "1d4", 12 }

View file

@ -40,12 +40,14 @@ extern char _flags[], _level[], file_name[], fruit[],
*ws_guess[], *ws_type[]; *ws_guess[], *ws_type[];
extern int a_chances[], a_class[], count, dnum, food_left, extern int a_chances[], a_class[], count, dnum, food_left,
fung_hit, fd, group, hungry_state, inpack, lastscore, fung_hit, group, hungry_state, inpack, lastscore,
level, lfd, max_level, mpos, no_command, no_food, no_move, level, max_level, mpos, no_command, no_food, no_move,
ntraps, purse, quiet, total; ntraps, purse, quiet, total;
extern long seed; extern long seed;
extern FILE *score_file, *log_file;
extern WINDOW *hw; extern WINDOW *hw;
/* /*
@ -92,5 +94,5 @@ extern int md_readchar(WINDOW *win);
extern int md_shellescape(void); extern int md_shellescape(void);
extern void md_sleep(int s); extern void md_sleep(int s);
extern int md_unlink(char *file); extern int md_unlink(char *file);
extern int md_unlink_open_file(char *file, int inf); extern int md_unlink_open_file(char *file, FILE *inf);
extern unsigned int md_random_seed(void); extern unsigned int md_random_seed(void);

View file

@ -37,6 +37,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <string.h> #include <string.h>
#include <errno.h>
#include "rogue.h" #include "rogue.h"
int num_checks; /* times we've gone over in checkout() */ int num_checks; /* times we've gone over in checkout() */
@ -80,9 +81,12 @@ void
open_score(void) open_score(void)
{ {
#ifdef SCOREFILE #ifdef SCOREFILE
fd = open(SCOREFILE, O_RDWR | O_CREAT, 0666 ); score_file = fopen(SCOREFILE, "r+");
if ((score_file == NULL) && (errno == ENOENT)) {
score_file = fopen(SCOREFILE, "w+");
}
#else #else
fd = -1; score_file = NULL;
#endif #endif
if (!use_savedir) if (!use_savedir)
md_normaluser(); md_normaluser();
@ -93,9 +97,9 @@ void
open_log(void) open_log(void)
{ {
#ifdef LOGFILE #ifdef LOGFILE
lfd = open(LOGFILE, O_WRONLY | O_APPEND | O_CREAT, 0666); log_file = fopen(LOGFILE, "a");
#else #else
lfd = -1; log_file = NULL;
#endif #endif
return; return;
} }

View file

@ -174,10 +174,10 @@ md_raw_standend(void)
} }
int int
md_unlink_open_file(char *file, int inf) md_unlink_open_file(char *file, FILE *inf)
{ {
#ifdef _WIN32 #ifdef _WIN32
_close(inf); fclose(inf);
_chmod(file, 0600); _chmod(file, 0600);
return( _unlink(file) ); return( _unlink(file) );
#else #else

View file

@ -49,7 +49,6 @@ score(int amount, int flags, char monst)
register struct sc_ent *scp; register struct sc_ent *scp;
register int i; register int i;
register struct sc_ent *sc2; register struct sc_ent *sc2;
register FILE *outf;
register int prflags = 0; register int prflags = 0;
register void (*fp)(int); register void (*fp)(int);
register int uid; register int uid;
@ -72,11 +71,6 @@ score(int amount, int flags, char monst)
start_score(); start_score();
if (fd >= 0)
outf = md_fdopen(fd, "wb");
else
return;
for (scp = top_ten; scp <= &top_ten[9]; scp++) for (scp = top_ten; scp <= &top_ten[9]; scp++)
{ {
scp->sc_score = 0; scp->sc_score = 0;
@ -112,9 +106,9 @@ score(int amount, int flags, char monst)
#endif #endif
for(i=0; i<10; i++) for(i=0; i<10; i++)
{ {
encread((char *) &top_ten[i].sc_name, MAXSTR, fd); encread((char *) &top_ten[i].sc_name, MAXSTR, score_file);
scoreline[0] = '\0'; scoreline[0] = '\0';
encread((char *) scoreline, 100, fd); encread((char *) scoreline, 100, score_file);
sscanf(scoreline, "%d %d %hd %hd %hd", &top_ten[i].sc_flags, sscanf(scoreline, "%d %d %hd %hd %hd", &top_ten[i].sc_flags,
&top_ten[i].sc_uid, &top_ten[i].sc_monster, &top_ten[i].sc_score, &top_ten[i].sc_uid, &top_ten[i].sc_monster, &top_ten[i].sc_score,
&top_ten[i].sc_level); &top_ten[i].sc_level);
@ -209,7 +203,7 @@ score(int amount, int flags, char monst)
else else
break; break;
} }
fseek(outf, 0L, 0); fseek(score_file, 0L, 0);
/* /*
* Update the list file * Update the list file
*/ */
@ -223,33 +217,28 @@ score(int amount, int flags, char monst)
for(i=0; i<10; i++) for(i=0; i<10; i++)
{ {
encwrite((char *) &top_ten[i].sc_name, MAXSTR, outf); encwrite((char *) &top_ten[i].sc_name, MAXSTR, score_file);
sprintf(scoreline," %d %d %hd %hd %hd \n", sprintf(scoreline," %d %d %hd %hd %hd \n",
top_ten[i].sc_flags, top_ten[i].sc_uid, top_ten[i].sc_flags, top_ten[i].sc_uid,
top_ten[i].sc_monster, top_ten[i].sc_score, top_ten[i].sc_monster, top_ten[i].sc_score,
top_ten[i].sc_level); top_ten[i].sc_level);
encwrite((char *) scoreline, 100, outf); encwrite((char *) scoreline, 100, score_file);
} }
unlock_sc(); unlock_sc();
signal(SIGINT, fp); signal(SIGINT, fp);
} }
} }
fclose(outf); fclose(score_file);
} }
void writelog(int amount, int flags, char monst) void writelog(int amount, int flags, char monst)
{ {
FILE *logfi;
char logmessage[220], ltemp[80]; char logmessage[220], ltemp[80];
char *killer; char *killer;
if (noscore) if (noscore)
return; return;
#ifdef LOGFILE #ifdef LOGFILE
if (lfd >= 0) if (log_file == NULL)
logfi = md_fdopen(lfd, "a");
else
return;
if (logfi == NULL)
return; return;
/* otherwise writing should work */ /* otherwise writing should work */
sprintf(logmessage, "%d %d %s %d ", time(NULL), amount, whoami, sprintf(logmessage, "%d %d %s %d ", time(NULL), amount, whoami,
@ -283,13 +272,13 @@ void writelog(int amount, int flags, char monst)
} }
else else
{ {
fclose(logfi); fclose(log_file);
return; return;
} }
/* then write */ /* then write */
fprintf(logfi, "%s", logmessage); fprintf(log_file, "%s", logmessage);
fclose(logfi); fclose(log_file);
#endif #endif
return; return;
} }

View file

@ -514,7 +514,7 @@ void door_open(struct room *rp);
void drop(void); void drop(void);
bool dropcheck(THING *op); bool dropcheck(THING *op);
void eat(void); void eat(void);
int encread(void *starta, int size, int inf); int encread(void *starta, int size, FILE *inf);
void encwrite(void *starta, int size, FILE *outf); void encwrite(void *starta, int size, FILE *outf);
void end_line(void); void end_line(void);
void endmsg(void); void endmsg(void);

View file

@ -23,7 +23,7 @@
void save_file(FILE *savef); void save_file(FILE *savef);
extern int rs_save_file(FILE *savef); extern int rs_save_file(FILE *savef);
extern int rs_restore_file(int inf); extern int rs_restore_file(FILE *inf);
typedef struct stat STAT; typedef struct stat STAT;
@ -165,9 +165,9 @@ save_file(FILE *savef)
/* /*
* close any open score file * close any open score file
*/ */
if (fd >= 0) { if (score_file != NULL) {
close(fd); fclose(score_file);
fd = -1; score_file = NULL;
} }
move(LINES-1, 0); move(LINES-1, 0);
refresh(); refresh();
@ -197,7 +197,7 @@ save_file(FILE *savef)
bool bool
restore(char *file, char **envp) restore(char *file, char **envp)
{ {
register int inf; FILE *inf;
register bool syml; register bool syml;
extern char **environ; extern char **environ;
char buf[MAXSTR]; char buf[MAXSTR];
@ -214,7 +214,7 @@ restore(char *file, char **envp)
signal(SIGTSTP, SIG_IGN); signal(SIGTSTP, SIG_IGN);
#endif #endif
if ((inf = open(file, 0)) < 0) if ((inf = fopen(file, "r")) == NULL)
{ {
if (use_savedir && errno == ENOENT) if (use_savedir && errno == ENOENT)
{ {
@ -234,7 +234,7 @@ restore(char *file, char **envp)
return FALSE; return FALSE;
} }
fstat(inf, &sbuf2); stat(file, &sbuf2);
fflush(stdout); fflush(stdout);
syml = issymlink(file); syml = issymlink(file);
@ -348,13 +348,13 @@ encwrite(void *starta, int size, FILE *outf)
* Perform an encrypted read * Perform an encrypted read
*/ */
int int
encread(void *starta, int size, int inf) encread(void *starta, int size, FILE *inf)
{ {
register char *ep; register char *ep;
register int read_size; register int read_size;
register char *start = (char *) starta; register char *start = (char *) starta;
if ((read_size = read(inf, start, size)) == -1 || read_size == 0) if ((read_size = fread(start, 1, size, inf)) == 0)
return read_size; return read_size;
ep = encstr; ep = encstr;

View file

@ -71,7 +71,7 @@
#define WRITESTAT (write_error == 0) #define WRITESTAT (write_error == 0)
int rs_write_int(FILE *savef, int c); int rs_write_int(FILE *savef, int c);
int rs_read_int(int inf, int *i); int rs_read_int(FILE *inf, int *i);
int read_error = FALSE; int read_error = FALSE;
int write_error = FALSE; int write_error = FALSE;
@ -421,7 +421,7 @@ rs_write_strings(FILE *savef, char *s[], int count)
} }
int int
rs_read(int inf, void *ptr, int size) rs_read(FILE *inf, void *ptr, int size)
{ {
int actual; int actual;
@ -451,14 +451,14 @@ rs_read(int inf, void *ptr, int size)
} }
int int
rs_read_char(int inf, char *c) rs_read_char(FILE *inf, char *c)
{ {
rs_read(inf, c, 1); rs_read(inf, c, 1);
return(READSTAT); return(READSTAT);
} }
int int
rs_read_uchar(int inf, unsigned char *c) rs_read_uchar(FILE *inf, unsigned char *c)
{ {
rs_read(inf, c, 1); rs_read(inf, c, 1);
@ -466,7 +466,7 @@ rs_read_uchar(int inf, unsigned char *c)
} }
int int
rs_read_boolean(int inf, bool *i) rs_read_boolean(FILE *inf, bool *i)
{ {
unsigned char buf; unsigned char buf;
@ -478,7 +478,7 @@ rs_read_boolean(int inf, bool *i)
} }
int int
rs_read_booleans(int inf, bool *i, int count) rs_read_booleans(FILE *inf, bool *i, int count)
{ {
int n = 0, value = 0; int n = 0, value = 0;
@ -500,7 +500,7 @@ rs_read_booleans(int inf, bool *i, int count)
} }
int int
rs_read_shint(int inf, shint *i) rs_read_shint(FILE *inf, shint *i)
{ {
unsigned char buf; unsigned char buf;
@ -512,7 +512,7 @@ rs_read_shint(int inf, shint *i)
} }
int int
rs_read_short(int inf, short *i) rs_read_short(FILE *inf, short *i)
{ {
unsigned char bytes[2]; unsigned char bytes[2];
short input; short input;
@ -533,7 +533,7 @@ rs_read_short(int inf, short *i)
} }
int int
rs_read_shorts(int inf, short *i, int count) rs_read_shorts(FILE *inf, short *i, int count)
{ {
int n = 0, value = 0; int n = 0, value = 0;
@ -552,7 +552,7 @@ rs_read_shorts(int inf, short *i, int count)
} }
int int
rs_read_ushort(int inf, unsigned short *i) rs_read_ushort(FILE *inf, unsigned short *i)
{ {
unsigned char bytes[2]; unsigned char bytes[2];
unsigned short input; unsigned short input;
@ -573,7 +573,7 @@ rs_read_ushort(int inf, unsigned short *i)
} }
int int
rs_read_int(int inf, int *i) rs_read_int(FILE *inf, int *i)
{ {
unsigned char bytes[4]; unsigned char bytes[4];
int input; int input;
@ -596,7 +596,7 @@ rs_read_int(int inf, int *i)
} }
int int
rs_read_ints(int inf, int *i, int count) rs_read_ints(FILE *inf, int *i, int count)
{ {
int n = 0, value = 0; int n = 0, value = 0;
@ -615,7 +615,7 @@ rs_read_ints(int inf, int *i, int count)
} }
int int
rs_read_uint(int inf, unsigned int *i) rs_read_uint(FILE *inf, unsigned int *i)
{ {
unsigned char bytes[4]; unsigned char bytes[4];
int input; int input;
@ -638,7 +638,7 @@ rs_read_uint(int inf, unsigned int *i)
} }
int int
rs_read_long(int inf, long *i) rs_read_long(FILE *inf, long *i)
{ {
unsigned char bytes[4]; unsigned char bytes[4];
long input; long input;
@ -661,7 +661,7 @@ rs_read_long(int inf, long *i)
} }
int int
rs_read_longs(int inf, long *i, int count) rs_read_longs(FILE *inf, long *i, int count)
{ {
int n = 0, value = 0; int n = 0, value = 0;
@ -680,7 +680,7 @@ rs_read_longs(int inf, long *i, int count)
} }
int int
rs_read_ulong(int inf, unsigned long *i) rs_read_ulong(FILE *inf, unsigned long *i)
{ {
unsigned char bytes[4]; unsigned char bytes[4];
unsigned long input; unsigned long input;
@ -703,7 +703,7 @@ rs_read_ulong(int inf, unsigned long *i)
} }
int int
rs_read_ulongs(int inf, unsigned long *i, int count) rs_read_ulongs(FILE *inf, unsigned long *i, int count)
{ {
int n = 0, value = 0; int n = 0, value = 0;
@ -722,7 +722,7 @@ rs_read_ulongs(int inf, unsigned long *i, int count)
} }
int int
rs_read_string(int inf, char *s, int max) rs_read_string(FILE *inf, char *s, int max)
{ {
int len = 0; int len = 0;
@ -742,7 +742,7 @@ rs_read_string(int inf, char *s, int max)
} }
int int
rs_read_new_string(int inf, char **s) rs_read_new_string(FILE *inf, char **s)
{ {
int len=0; int len=0;
char *buf=0; char *buf=0;
@ -769,7 +769,7 @@ rs_read_new_string(int inf, char **s)
} }
int int
rs_read_string_index(int inf, const char *master[], int maxindex, rs_read_string_index(FILE *inf, const char *master[], int maxindex,
const char **str) const char **str)
{ {
int i; int i;
@ -792,7 +792,7 @@ rs_read_string_index(int inf, const char *master[], int maxindex,
} }
int int
rs_read_strings(int inf, char **s, int count, int max) rs_read_strings(FILE *inf, char **s, int count, int max)
{ {
int n = 0; int n = 0;
int value = 0; int value = 0;
@ -819,7 +819,7 @@ rs_read_strings(int inf, char **s, int count, int max)
} }
int int
rs_read_new_strings(int inf, char **s, int count) rs_read_new_strings(FILE *inf, char **s, int count)
{ {
int len = 0; int len = 0;
int n = 0; int n = 0;
@ -863,7 +863,7 @@ rs_write_str_t(FILE *savef, str_t st)
} }
int int
rs_read_str_t(int inf, str_t *st) rs_read_str_t(FILE *inf, str_t *st)
{ {
rs_read_uint(inf,st); rs_read_uint(inf,st);
@ -880,7 +880,7 @@ rs_write_coord(FILE *savef, coord c)
} }
int int
rs_read_coord(int inf, coord *c) rs_read_coord(FILE *inf, coord *c)
{ {
rs_read_shint(inf,&c->x); rs_read_shint(inf,&c->x);
rs_read_shint(inf,&c->y); rs_read_shint(inf,&c->y);
@ -907,7 +907,7 @@ rs_write_window(FILE *savef, WINDOW *win)
} }
int int
rs_read_window(int inf, WINDOW *win) rs_read_window(FILE *inf, WINDOW *win)
{ {
int id,row,col,maxlines,maxcols,value,width,height; int id,row,col,maxlines,maxcols,value,width,height;
@ -987,7 +987,7 @@ rs_write_daemons(FILE *savef, struct delayed_action *d_list, int count)
} }
int int
rs_read_daemons(int inf, struct delayed_action *d_list, int count) rs_read_daemons(FILE *inf, struct delayed_action *d_list, int count)
{ {
int i = 0; int i = 0;
int func = 0; int func = 0;
@ -1083,7 +1083,7 @@ rs_write_magic_items(FILE *savef, struct magic_item *i, int count)
} }
int int
rs_read_magic_items(int inf, struct magic_item *mi, int count) rs_read_magic_items(FILE *inf, struct magic_item *mi, int count)
{ {
int id; int id;
int n; int n;
@ -1161,7 +1161,7 @@ rs_write_rooms(FILE *savef, struct room r[], int count)
} }
int int
rs_read_room(int inf, struct room *r) rs_read_room(FILE *inf, struct room *r)
{ {
rs_read_coord(inf,&r->r_pos); rs_read_coord(inf,&r->r_pos);
rs_read_coord(inf,&r->r_max); rs_read_coord(inf,&r->r_max);
@ -1186,7 +1186,7 @@ rs_read_room(int inf, struct room *r)
} }
int int
rs_read_rooms(int inf, struct room *r, int count) rs_read_rooms(FILE *inf, struct room *r, int count)
{ {
int value = 0, n = 0; int value = 0, n = 0;
@ -1222,7 +1222,7 @@ rs_write_room_reference(FILE *savef, struct room *rp)
} }
int int
rs_read_room_reference(int inf, struct room **rp) rs_read_room_reference(FILE *inf, struct room **rp)
{ {
int i; int i;
@ -1252,7 +1252,7 @@ rs_write_stats(FILE *savef, struct stats *s)
} }
int int
rs_read_stats(int inf, struct stats *s) rs_read_stats(FILE *inf, struct stats *s)
{ {
int id; int id;
@ -1290,7 +1290,7 @@ rs_write_object(FILE *savef, THING *o)
} }
int int
rs_read_object(int inf, THING *o) rs_read_object(FILE *inf, THING *o)
{ {
int id; int id;
@ -1339,7 +1339,7 @@ rs_write_object_list(FILE *savef, THING *l)
} }
int int
rs_read_object_list(int inf, THING **list) rs_read_object_list(FILE *inf, THING **list)
{ {
int id; int id;
int i, cnt; int i, cnt;
@ -1390,7 +1390,7 @@ rs_write_object_reference(FILE *savef, THING *list, THING *item)
} }
int int
rs_read_object_reference(int inf, THING *list, THING **item) rs_read_object_reference(FILE *inf, THING *list, THING **item)
{ {
int i; int i;
@ -1566,7 +1566,7 @@ rs_fix_thing_list(THING *list)
} }
int int
rs_read_thing(int inf, THING *t) rs_read_thing(FILE *inf, THING *t)
{ {
int id; int id;
int listid = 0, index = -1; int listid = 0, index = -1;
@ -1666,7 +1666,7 @@ rs_write_thing_list(FILE *savef, THING *l)
} }
int int
rs_read_thing_list(int inf, THING **list) rs_read_thing_list(FILE *inf, THING **list)
{ {
int id; int id;
int i, cnt; int i, cnt;
@ -1730,7 +1730,7 @@ rs_write_monsters(FILE *savef, struct monster *m, int count)
} }
int int
rs_read_monsters(int inf, struct monster *m, int count) rs_read_monsters(FILE *inf, struct monster *m, int count)
{ {
int id = 0, value = 0, n = 0; int id = 0, value = 0, n = 0;
@ -1774,11 +1774,11 @@ rs_write_scrolls(FILE *savef)
rs_write_string(savef,s_guess[i]); rs_write_string(savef,s_guess[i]);
} }
return(READSTAT); return(WRITESTAT);
} }
int int
rs_read_scrolls(int inf) rs_read_scrolls(FILE *inf)
{ {
int i; int i;
@ -1808,7 +1808,7 @@ rs_write_potions(FILE *savef)
} }
int int
rs_read_potions(int inf) rs_read_potions(FILE *inf)
{ {
int i; int i;
@ -1843,7 +1843,7 @@ rs_write_rings(FILE *savef)
} }
int int
rs_read_rings(int inf) rs_read_rings(FILE *inf)
{ {
int i; int i;
const char *stones_list[NSTONES]; const char *stones_list[NSTONES];
@ -1886,7 +1886,7 @@ rs_write_sticks(FILE *savef)
} }
int int
rs_read_sticks(int inf) rs_read_sticks(FILE *inf)
{ {
int i = 0, list = 0; int i = 0, list = 0;
@ -1931,7 +1931,7 @@ rs_write_thing_reference(FILE *savef, THING *list, THING *item)
} }
int int
rs_read_thing_reference(int inf, THING *list, THING **item) rs_read_thing_reference(FILE *inf, THING *list, THING **item)
{ {
int i; int i;
@ -1961,7 +1961,7 @@ rs_write_thing_references(FILE *savef, THING *list, THING *items[], int count)
} }
int int
rs_read_thing_references(int inf, THING *list, THING *items[], int count) rs_read_thing_references(FILE *inf, THING *list, THING *items[], int count)
{ {
int i; int i;
@ -2076,7 +2076,7 @@ rs_save_file(FILE *savef)
} }
int int
rs_restore_file(int inf) rs_restore_file(FILE *inf)
{ {
bool junk; bool junk;
THING *mitem; THING *mitem;

View file

@ -54,7 +54,6 @@ int group = NEWGROUP; /* Current group number */
int hungry_state = F_OKAY; /* How hungry is he */ int hungry_state = F_OKAY; /* How hungry is he */
int foodlev = 1; /* how fast he eats food */ int foodlev = 1; /* how fast he eats food */
int ringfood = 0; /* rings affect on food consumption */ int ringfood = 0; /* rings affect on food consumption */
int scorefd = -1; /* Scoreboard file descriptor */
char take; /* Thing the rogue is taking */ char take; /* Thing the rogue is taking */
char runch; /* Direction player is running */ char runch; /* Direction player is running */
char curpurch[15]; /* name of item ready to buy */ char curpurch[15]; /* name of item ready to buy */
@ -102,6 +101,7 @@ char illegal[] = { "Illegal command '%s'." };
char callit[] = { "Call it: " }; char callit[] = { "Call it: " };
char starlist[] = { " (* for a list)" }; char starlist[] = { " (* for a list)" };
FILE *scoreboard = NULL; /* Scoreboard file */
FILE *logfile = NULL; FILE *logfile = NULL;
struct coord oldpos; /* Pos before last look() call */ struct coord oldpos; /* Pos before last look() call */

View file

@ -21,6 +21,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <limits.h> #include <limits.h>
#include <errno.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "rogue.h" #include "rogue.h"
@ -37,7 +38,7 @@
char *roguehome(void); char *roguehome(void);
void open_records(void); void open_records(void);
extern int scorefd; extern FILE *scoreboard;
extern FILE *logfile; extern FILE *logfile;
int int
@ -480,8 +481,11 @@ roguehome(void)
void void
open_records(void) open_records(void)
{ {
if (scorefd < 0) if (scoreboard == NULL)
scorefd = open(scorefile, O_RDWR | O_CREAT, 0666); scoreboard = fopen(scorefile, "r+");
if (scoreboard == NULL && errno == ENOENT) {
scoreboard = fopen(scorefile, "w+");
}
#ifdef LOGFILE #ifdef LOGFILE
if (logfile == NULL) if (logfile == NULL)
logfile = fopen(LOGFILE, "a"); logfile = fopen(LOGFILE, "a");

View file

@ -47,7 +47,7 @@ static char *rip[] = {
#define RIP_LINES (sizeof rip / (sizeof (char *))) #define RIP_LINES (sizeof rip / (sizeof (char *)))
extern int scorefd; extern FILE *scoreboard;
extern FILE *logfile; extern FILE *logfile;
char *killname(unsigned char monst); char *killname(unsigned char monst);
@ -123,8 +123,7 @@ void
score(int amount, int aflag, char monst) score(int amount, int aflag, char monst)
{ {
reg struct sc_ent *scp, *sc2; reg struct sc_ent *scp, *sc2;
reg int i, fd, prflags = 0; reg int i, prflags = 0;
reg FILE *outf;
char *packend; char *packend;
md_onsignal_exit(); md_onsignal_exit();
@ -142,9 +141,8 @@ score(int amount, int aflag, char monst)
/* /*
* Open file and read list * Open file and read list
*/ */
if ((fd = scorefd) < 0) if (scoreboard == NULL)
return; return;
outf = (FILE *) md_fdopen(fd, "w");
for (scp = top_ten; scp <= &top_ten[9]; scp++) { for (scp = top_ten; scp <= &top_ten[9]; scp++) {
scp->sc_score = 0; scp->sc_score = 0;
for (i = 0; i < 80; i++) for (i = 0; i < 80; i++)
@ -165,8 +163,8 @@ score(int amount, int aflag, char monst)
{ {
unsigned int mon; unsigned int mon;
encread((char *) &top_ten[i].sc_name, LINLEN, fd); encread((char *) &top_ten[i].sc_name, LINLEN, scoreboard);
encread((char *) scoreline, 100, fd); encread((char *) scoreline, 100, scoreboard);
sscanf(scoreline, " %d %d %d %d %u %d %ld %lx \n", sscanf(scoreline, " %d %d %d %d %u %d %ld %lx \n",
&top_ten[i].sc_score, &top_ten[i].sc_flags, &top_ten[i].sc_score, &top_ten[i].sc_flags,
&top_ten[i].sc_level, &top_ten[i].sc_uid, &top_ten[i].sc_level, &top_ten[i].sc_uid,
@ -199,19 +197,19 @@ score(int amount, int aflag, char monst)
} }
} }
ignore(); ignore();
fseek(outf, 0L, 0); fseek(scoreboard, 0L, 0);
for(i = 0; i < 10; i++) for(i = 0; i < 10; i++)
{ {
memset(scoreline,0,100); memset(scoreline,0,100);
encwrite((char *) top_ten[i].sc_name, LINLEN, outf); encwrite((char *) top_ten[i].sc_name, LINLEN, scoreboard);
sprintf(scoreline, " %d %d %d %d %u %d %ld %lx \n", sprintf(scoreline, " %d %d %d %d %u %d %ld %lx \n",
top_ten[i].sc_score, top_ten[i].sc_flags, top_ten[i].sc_score, top_ten[i].sc_flags,
top_ten[i].sc_level, top_ten[i].sc_uid, top_ten[i].sc_level, top_ten[i].sc_uid,
top_ten[i].sc_monster, top_ten[i].sc_explvl, top_ten[i].sc_monster, top_ten[i].sc_explvl,
top_ten[i].sc_exppts, top_ten[i].sc_date); top_ten[i].sc_exppts, top_ten[i].sc_date);
encwrite((char *) scoreline, 100, outf); encwrite((char *) scoreline, 100, scoreboard);
} }
fclose(outf); fclose(scoreboard);
md_onsignal_exit(); md_onsignal_exit();
clear(); clear();
refresh(); refresh();
@ -263,18 +261,19 @@ void writelog(int amount, int aflag, char monst)
bool bool
showtop(int showname) showtop(int showname)
{ {
reg int fd, i; reg int i;
char *killer; char *killer;
struct sc_ent *scp; struct sc_ent *scp;
FILE *score_rdonly;
if ((fd = open(scorefile, O_RDONLY)) < 0) if ((score_rdonly = fopen(scorefile, "r")) == NULL)
return FALSE; return FALSE;
for(i = 0; i < 10; i++) for(i = 0; i < 10; i++)
{ {
unsigned int mon; unsigned int mon;
encread((char *) &top_ten[i].sc_name, LINLEN, fd); encread((char *) &top_ten[i].sc_name, LINLEN, score_rdonly);
encread((char *) scoreline, 100, fd); encread((char *) scoreline, 100, score_rdonly);
sscanf(scoreline, " %d %d %d %d %u %d %ld %lx \n", sscanf(scoreline, " %d %d %d %d %u %d %ld %lx \n",
&top_ten[i].sc_score, &top_ten[i].sc_flags, &top_ten[i].sc_score, &top_ten[i].sc_flags,
&top_ten[i].sc_level, &top_ten[i].sc_uid, &top_ten[i].sc_level, &top_ten[i].sc_uid,
@ -282,7 +281,7 @@ showtop(int showname)
&top_ten[i].sc_exppts, &top_ten[i].sc_date); &top_ten[i].sc_exppts, &top_ten[i].sc_date);
top_ten[i].sc_monster = mon; top_ten[i].sc_monster = mon;
} }
close(fd); fclose(score_rdonly);
printf("Top Ten Adventurers:\nRank\tScore\tName\n"); printf("Top Ten Adventurers:\nRank\tScore\tName\n");
for (scp = top_ten; scp <= &top_ten[9]; scp++) { for (scp = top_ten; scp <= &top_ten[9]; scp++) {
if (scp->sc_score > 0) { if (scp->sc_score > 0) {

View file

@ -92,7 +92,7 @@ void draw_room(struct room *rp);
int drop(struct linked_list *item); int drop(struct linked_list *item);
bool dropcheck(struct object *op); bool dropcheck(struct object *op);
void eat(void); void eat(void);
int encread(void *starta, unsigned int size, int inf); int encread(void *starta, unsigned int size, FILE *inf);
void encwrite(void *starta, unsigned int size, FILE *outf); void encwrite(void *starta, unsigned int size, FILE *outf);
void endit(int a); void endit(int a);
void endmsg(void); void endmsg(void);
@ -200,7 +200,7 @@ struct coord *rndmove(struct thing *who);
int roll(int number, int sides); int roll(int number, int sides);
void rollwand(int fromfuse); void rollwand(int fromfuse);
struct room *roomin(struct coord *cp); struct room *roomin(struct coord *cp);
int rs_restore_file(int inf); int rs_restore_file(FILE *inf);
int rs_save_file(FILE *savef); int rs_save_file(FILE *savef);
void runners(void); void runners(void);
void runto(struct coord *runner, struct coord *spot); void runto(struct coord *runner, struct coord *spot);

View file

@ -191,7 +191,7 @@ save_file(FILE *savef)
bool bool
restore(char *file, char **envp) restore(char *file, char **envp)
{ {
register int inf, pid; register int pid;
int ret_status; int ret_status;
#ifndef _AIX #ifndef _AIX
extern char **environ; extern char **environ;
@ -199,11 +199,12 @@ restore(char *file, char **envp)
#ifdef __DJGPP__ /* st_ino w/ DJGPP under WinXP broken */ #ifdef __DJGPP__ /* st_ino w/ DJGPP under WinXP broken */
_djstat_flags |= _STAT_INODE; /* so turn off computing it for now */ _djstat_flags |= _STAT_INODE; /* so turn off computing it for now */
#endif #endif
FILE *inf;
char buf[LINLEN]; char buf[LINLEN];
STAT sbuf2; STAT sbuf2;
int slines, scols; int slines, scols;
if ((inf = open(file, O_RDONLY)) < 0) { if ((inf = fopen(file, "r")) == NULL) {
if (use_savedir && errno == ENOENT) if (use_savedir && errno == ENOENT)
return TRUE; return TRUE;
else { else {
@ -219,7 +220,7 @@ restore(char *file, char **envp)
return FALSE; return FALSE;
} }
fstat(inf, &sbuf2); stat(file, &sbuf2);
encread(&slines,sizeof(slines),inf); encread(&slines,sizeof(slines),inf);
encread(&scols,sizeof(scols),inf); encread(&scols,sizeof(scols),inf);
@ -279,11 +280,11 @@ restore(char *file, char **envp)
} }
#if defined(__CYGWIN__) || defined(__DJGPP__) #if defined(__CYGWIN__) || defined(__DJGPP__)
close(inf); fclose(inf);
#endif #endif
if (!wizard) if (!wizard)
{ {
if (md_unlink_open_file(file, md_fdopen(inf, "r")) < 0) if (md_unlink_open_file(file, inf) < 0)
{ {
endwin(); endwin();
printf("Cannot unlink file\n"); printf("Cannot unlink file\n");

View file

@ -70,7 +70,7 @@
#define READSTAT ((format_error == 0) && (read_error == 0)) #define READSTAT ((format_error == 0) && (read_error == 0))
#define WRITESTAT (write_error == 0) #define WRITESTAT (write_error == 0)
int rs_read_int(int inf, int *i); int rs_read_int(FILE *inf, int *i);
int rs_write_int(FILE *savef, int c); int rs_write_int(FILE *savef, int c);
int read_error = FALSE; int read_error = FALSE;
@ -105,13 +105,13 @@ encwrite(void *starta, unsigned int size, FILE *outf)
* perform an encrypted read * perform an encrypted read
*/ */
int int
encread(void *starta, unsigned int size, int inf) encread(void *starta, unsigned int size, FILE *inf)
{ {
register char *ep; register char *ep;
register int read_size; register int read_size;
register char *start = starta; register char *start = starta;
if ((read_size = read(inf, start, size)) == -1 || read_size == 0) if ((read_size = fread(start, 1, size, inf)) == 0)
return read_size; return read_size;
ep = encstr; ep = encstr;
@ -466,7 +466,7 @@ rs_write_strings(FILE *savef, char *s[], int count)
} }
int int
rs_read(int inf, void *ptr, int size) rs_read(FILE *inf, void *ptr, int size)
{ {
int actual; int actual;
@ -497,7 +497,7 @@ rs_read(int inf, void *ptr, int size)
} }
int int
rs_read_char(int inf, char *c) rs_read_char(FILE *inf, char *c)
{ {
rs_read(inf, c, 1); rs_read(inf, c, 1);
@ -505,7 +505,7 @@ rs_read_char(int inf, char *c)
} }
int int
rs_read_boolean(int inf, bool *i) rs_read_boolean(FILE *inf, bool *i)
{ {
unsigned char buf; unsigned char buf;
@ -517,7 +517,7 @@ rs_read_boolean(int inf, bool *i)
} }
int int
rs_read_booleans(int inf, bool *i, int count) rs_read_booleans(FILE *inf, bool *i, int count)
{ {
int n = 0, value = 0; int n = 0, value = 0;
@ -539,7 +539,7 @@ rs_read_booleans(int inf, bool *i, int count)
} }
int int
rs_read_shint(int inf, unsigned char *i) rs_read_shint(FILE *inf, unsigned char *i)
{ {
unsigned char buf; unsigned char buf;
@ -551,7 +551,7 @@ rs_read_shint(int inf, unsigned char *i)
} }
int int
rs_read_short(int inf, short *i) rs_read_short(FILE *inf, short *i)
{ {
unsigned char bytes[2]; unsigned char bytes[2];
short input; short input;
@ -572,7 +572,7 @@ rs_read_short(int inf, short *i)
} }
int int
rs_read_shorts(int inf, short *i, int count) rs_read_shorts(FILE *inf, short *i, int count)
{ {
int n = 0, value = 0; int n = 0, value = 0;
@ -591,7 +591,7 @@ rs_read_shorts(int inf, short *i, int count)
} }
int int
rs_read_ushort(int inf, unsigned short *i) rs_read_ushort(FILE *inf, unsigned short *i)
{ {
unsigned char bytes[2]; unsigned char bytes[2];
unsigned short input; unsigned short input;
@ -612,7 +612,7 @@ rs_read_ushort(int inf, unsigned short *i)
} }
int int
rs_read_int(int inf, int *i) rs_read_int(FILE *inf, int *i)
{ {
unsigned char bytes[4]; unsigned char bytes[4];
int input; int input;
@ -635,7 +635,7 @@ rs_read_int(int inf, int *i)
} }
int int
rs_read_ints(int inf, int *i, int count) rs_read_ints(FILE *inf, int *i, int count)
{ {
int n = 0, value = 0; int n = 0, value = 0;
@ -654,7 +654,7 @@ rs_read_ints(int inf, int *i, int count)
} }
int int
rs_read_uint(int inf, unsigned int *i) rs_read_uint(FILE *inf, unsigned int *i)
{ {
unsigned char bytes[4]; unsigned char bytes[4];
int input; int input;
@ -677,7 +677,7 @@ rs_read_uint(int inf, unsigned int *i)
} }
int int
rs_read_long(int inf, long *i) rs_read_long(FILE *inf, long *i)
{ {
unsigned char bytes[4]; unsigned char bytes[4];
long input; long input;
@ -700,7 +700,7 @@ rs_read_long(int inf, long *i)
} }
int int
rs_read_longs(int inf, long *i, int count) rs_read_longs(FILE *inf, long *i, int count)
{ {
int n = 0, value = 0; int n = 0, value = 0;
@ -719,7 +719,7 @@ rs_read_longs(int inf, long *i, int count)
} }
int int
rs_read_ulong(int inf, unsigned long *i) rs_read_ulong(FILE *inf, unsigned long *i)
{ {
unsigned char bytes[4]; unsigned char bytes[4];
unsigned long input; unsigned long input;
@ -742,7 +742,7 @@ rs_read_ulong(int inf, unsigned long *i)
} }
int int
rs_read_ulongs(int inf, unsigned long *i, int count) rs_read_ulongs(FILE *inf, unsigned long *i, int count)
{ {
int n = 0, value = 0; int n = 0, value = 0;
@ -761,7 +761,7 @@ rs_read_ulongs(int inf, unsigned long *i, int count)
} }
int int
rs_read_string(int inf, char *s, int max) rs_read_string(FILE *inf, char *s, int max)
{ {
int len = 0; int len = 0;
@ -781,7 +781,7 @@ rs_read_string(int inf, char *s, int max)
} }
int int
rs_read_new_string(int inf, char **s) rs_read_new_string(FILE *inf, char **s)
{ {
int len=0; int len=0;
char *buf=0; char *buf=0;
@ -808,7 +808,7 @@ rs_read_new_string(int inf, char **s)
} }
int int
rs_read_string_index(int inf, char *master[], int maxindex, char **str) rs_read_string_index(FILE *inf, char *master[], int maxindex, char **str)
{ {
int i; int i;
@ -830,7 +830,7 @@ rs_read_string_index(int inf, char *master[], int maxindex, char **str)
} }
int int
rs_read_strings(int inf, char **s, int count, int max) rs_read_strings(FILE *inf, char **s, int count, int max)
{ {
int len = 0; int len = 0;
int n = 0; int n = 0;
@ -858,7 +858,7 @@ rs_read_strings(int inf, char **s, int count, int max)
} }
int int
rs_read_new_strings(int inf, char **s, int count) rs_read_new_strings(FILE *inf, char **s, int count)
{ {
int len = 0; int len = 0;
int n = 0; int n = 0;
@ -903,7 +903,7 @@ rs_write_coord(FILE *savef, struct coord c)
} }
int int
rs_read_coord(int inf, struct coord *c) rs_read_coord(FILE *inf, struct coord *c)
{ {
rs_read_int(inf,&c->x); rs_read_int(inf,&c->x);
rs_read_int(inf,&c->y); rs_read_int(inf,&c->y);
@ -930,7 +930,7 @@ rs_write_window(FILE *savef, WINDOW *win)
} }
int int
rs_read_window(int inf, WINDOW *win) rs_read_window(FILE *inf, WINDOW *win)
{ {
int id,row,col,maxlines,maxcols,value,width,height; int id,row,col,maxlines,maxcols,value,width,height;
@ -1024,7 +1024,7 @@ rs_write_daemons(FILE *savef, struct delayed_action *d_list, int count)
} }
int int
rs_read_daemons(int inf, struct delayed_action *d_list, int count) rs_read_daemons(FILE *inf, struct delayed_action *d_list, int count)
{ {
int i = 0; int i = 0;
int func = 0; int func = 0;
@ -1130,7 +1130,7 @@ rs_write_room_reference(FILE *savef, struct room *rp)
} }
int int
rs_read_room_reference(int inf, struct room **rp) rs_read_room_reference(FILE *inf, struct room **rp)
{ {
int i; int i;
@ -1173,7 +1173,7 @@ rs_write_rooms(FILE *savef, struct room r[], int count)
} }
int int
rs_read_rooms(int inf, struct room *r, int count) rs_read_rooms(FILE *inf, struct room *r, int count)
{ {
int value = 0, n = 0; int value = 0, n = 0;
@ -1220,7 +1220,7 @@ rs_write_monlev(FILE *savef, struct monlev m)
} }
int int
rs_read_monlev(int inf, struct monlev *m) rs_read_monlev(FILE *inf, struct monlev *m)
{ {
rs_read_int(inf, &m->l_lev); rs_read_int(inf, &m->l_lev);
rs_read_int(inf, &m->h_lev); rs_read_int(inf, &m->h_lev);
@ -1247,7 +1247,7 @@ rs_write_magic_items(FILE *savef, struct magic_item *i, int count)
} }
int int
rs_read_magic_items(int inf, struct magic_item *mi, int count) rs_read_magic_items(FILE *inf, struct magic_item *mi, int count)
{ {
int id; int id;
int n; int n;
@ -1297,7 +1297,7 @@ rs_write_real(FILE *savef, struct real r)
} }
int int
rs_read_real(int inf, struct real *r) rs_read_real(FILE *inf, struct real *r)
{ {
rs_read_int(inf,&r->a_str); rs_read_int(inf,&r->a_str);
rs_read_int(inf,&r->a_dex); rs_read_int(inf,&r->a_dex);
@ -1326,7 +1326,7 @@ rs_write_stats(FILE *savef, struct stats *s)
} }
int int
rs_read_stats(int inf, struct stats *s) rs_read_stats(FILE *inf, struct stats *s)
{ {
int id; int id;
@ -1362,7 +1362,7 @@ rs_write_monster_reference(FILE *savef, struct monster *m)
} }
int int
rs_read_monster_reference(int inf, struct monster **mp) rs_read_monster_reference(FILE *inf, struct monster **mp)
{ {
int i; int i;
@ -1388,7 +1388,7 @@ rs_write_monster_references(FILE *savef, struct monster *marray[], int count)
} }
int int
rs_read_monster_references(int inf, struct monster *marray[], int count) rs_read_monster_references(FILE *inf, struct monster *marray[], int count)
{ {
int i; int i;
@ -1442,7 +1442,7 @@ rs_write_object(FILE *savef, struct object *o)
} }
int int
rs_read_object(int inf, struct object *o) rs_read_object(FILE *inf, struct object *o)
{ {
int id; int id;
@ -1498,7 +1498,7 @@ rs_read_object(int inf, struct object *o)
} }
int int
rs_read_object_list(int inf, struct linked_list **list) rs_read_object_list(FILE *inf, struct linked_list **list)
{ {
int id; int id;
int i, cnt; int i, cnt;
@ -1570,7 +1570,7 @@ rs_write_traps(FILE *savef, struct trap *trap,int count)
} }
int int
rs_read_traps(int inf, struct trap *trap, int count) rs_read_traps(FILE *inf, struct trap *trap, int count)
{ {
int id = 0, value = 0, n = 0; int id = 0, value = 0, n = 0;
@ -1628,7 +1628,7 @@ rs_write_monsters(FILE * savef, struct monster * m, int count)
} }
int int
rs_read_monsters(int inf, struct monster *m, int count) rs_read_monsters(FILE *inf, struct monster *m, int count)
{ {
int id = 0, value = 0, n = 0; int id = 0, value = 0, n = 0;
@ -1813,7 +1813,7 @@ rs_write_thing(FILE *savef, struct thing *t)
} }
int int
rs_read_thing(int inf, struct thing *t) rs_read_thing(FILE *inf, struct thing *t)
{ {
int id; int id;
int listid = 0, index = -1; int listid = 0, index = -1;
@ -1931,7 +1931,7 @@ rs_write_monster_list(FILE *savef, struct linked_list *l)
} }
int int
rs_read_monster_list(int inf, struct linked_list **list) rs_read_monster_list(FILE *inf, struct linked_list **list)
{ {
int id; int id;
int i, cnt; int i, cnt;
@ -1985,7 +1985,7 @@ rs_write_object_reference(FILE *savef, struct linked_list *list,
} }
int int
rs_read_object_reference(int inf, struct linked_list *list, rs_read_object_reference(FILE *inf, struct linked_list *list,
struct object **item) struct object **item)
{ {
int i; int i;
@ -1999,7 +1999,7 @@ rs_read_object_reference(int inf, struct linked_list *list,
int int
rs_read_scrolls(int inf) rs_read_scrolls(FILE *inf)
{ {
int i; int i;
@ -2028,7 +2028,7 @@ rs_write_scrolls(FILE *savef)
} }
int int
rs_read_potions(int inf) rs_read_potions(FILE *inf)
{ {
int i; int i;
@ -2058,7 +2058,7 @@ rs_write_potions(FILE *savef)
} }
int int
rs_read_rings(int inf) rs_read_rings(FILE *inf)
{ {
int i; int i;
@ -2114,7 +2114,7 @@ rs_write_sticks(FILE *savef)
} }
int int
rs_read_sticks(int inf) rs_read_sticks(FILE *inf)
{ {
int i = 0, list = 0; int i = 0, list = 0;
@ -2241,7 +2241,7 @@ rs_save_file(FILE *savef)
} }
int int
rs_restore_file(int inf) rs_restore_file(FILE *inf)
{ {
bool junk; bool junk;
int endian = 0x01020304; int endian = 0x01020304;

View file

@ -1300,7 +1300,7 @@ void eat(void);
void eat_gold(struct object *obj); void eat_gold(struct object *obj);
int effect(struct thing *att, struct thing *def, struct object *weap, int effect(struct thing *att, struct thing *def, struct object *weap,
bool thrown, bool see_att, bool see_def); bool thrown, bool see_att, bool see_def);
long encread(char *start, unsigned long size, int inf); long encread(char *start, unsigned long size, FILE *inf);
long encwrite(char *start, unsigned long size, FILE *outf); long encwrite(char *start, unsigned long size, FILE *outf);
void endit(int sig); void endit(int sig);
void endmsg(void); void endmsg(void);

View file

@ -32,9 +32,9 @@ extern unsigned char encstr[];
extern int big_endian; extern int big_endian;
bool rs_write_int(FILE *savef, int c); bool rs_write_int(FILE *savef, int c);
bool rs_read_int(int inf, int *i); bool rs_read_int(FILE *inf, int *i);
bool rs_save_file(FILE *savef); bool rs_save_file(FILE *savef);
bool rs_restore_file(int inf); bool rs_restore_file(FILE *inf);
int md_unlink(char *file); int md_unlink(char *file);
bool save_file(FILE *savef); bool save_file(FILE *savef);
@ -158,7 +158,7 @@ save_file(FILE *savef)
bool bool
restore(char *file, char *envp[]) restore(char *file, char *envp[])
{ {
register int inf; FILE *inf;
extern char **environ; extern char **environ;
char buf[LINELEN]; char buf[LINELEN];
int endian = 0x01020304; int endian = 0x01020304;
@ -167,7 +167,7 @@ restore(char *file, char *envp[])
if (strcmp(file, "-r") == 0) if (strcmp(file, "-r") == 0)
file = file_name; file = file_name;
if ((inf = open(file, O_RDONLY)) < 0) if ((inf = fopen(file, "r")) == NULL)
{ {
if (use_savedir && errno == ENOENT) if (use_savedir && errno == ENOENT)
{ {
@ -224,11 +224,11 @@ restore(char *file, char *envp[])
{ {
endwin(); endwin();
printf("Cannot restore file\n"); printf("Cannot restore file\n");
close(inf); fclose(inf);
return(FALSE); return(FALSE);
} }
close(inf); fclose(inf);
if (!wizard) if (!wizard)
md_unlink(file); md_unlink(file);
@ -293,7 +293,7 @@ encwrite(char *start, unsigned long size, FILE *outf)
*/ */
long long
encread(char *start, unsigned long size, int inf) encread(char *start, unsigned long size, FILE *inf)
{ {
register unsigned char *ep; register unsigned char *ep;
register int rd_siz; register int rd_siz;
@ -303,8 +303,8 @@ encread(char *start, unsigned long size, int inf)
while (total_read < size) { while (total_read < size) {
rd_siz = ENCRBSIZ; rd_siz = ENCRBSIZ;
rd_siz = ((size-total_read) > ENCRBSIZ) ? ENCRBSIZ : (size-total_read); rd_siz = ((size-total_read) > ENCRBSIZ) ? ENCRBSIZ : (size-total_read);
rd_siz = read(inf,&start[total_read],rd_siz); rd_siz = fread(&start[total_read], 1, rd_siz, inf);
if(rd_siz==-1 || rd_siz==0) if(rd_siz==0)
break; break;
total_read += rd_siz; total_read += rd_siz;
} }

View file

@ -96,13 +96,13 @@ int format_error = FALSE;
int save_debug = FALSE; int save_debug = FALSE;
#define DBG(x) {if (save_debug) rsPrintf x;} #define DBG(x) {if (save_debug) rsPrintf x;}
bool rs_read_new_string(int inf, char **s); bool rs_read_new_string(FILE *inf, char **s);
int find_list_ptr(struct linked_list *l, void *ptr); int find_list_ptr(struct linked_list *l, void *ptr);
bool rs_write_coord_list(FILE *savef, struct linked_list *l); bool rs_write_coord_list(FILE *savef, struct linked_list *l);
bool rs_read_coord_list(int inf, struct linked_list **list); bool rs_read_coord_list(FILE *inf, struct linked_list **list);
int list_size(struct linked_list *l); int list_size(struct linked_list *l);
bool rs_write_object_list(FILE *savef, struct linked_list *l); bool rs_write_object_list(FILE *savef, struct linked_list *l);
bool rs_read_object_list(int inf, struct linked_list **list); bool rs_read_object_list(FILE *inf, struct linked_list **list);
int int
rsPrintf(char *fmt, ...) rsPrintf(char *fmt, ...)
@ -152,7 +152,7 @@ rs_write(FILE *savef, void *ptr, size_t size)
int end_of_file = FALSE; int end_of_file = FALSE;
bool bool
rs_read(int inf, void *ptr, size_t size) rs_read(FILE *inf, void *ptr, size_t size)
{ {
int actual; int actual;
end_of_file =FALSE; end_of_file =FALSE;
@ -284,7 +284,7 @@ rs_write_boolean(FILE *savef, bool c)
} }
bool bool
rs_read_int(int inf, int *i) rs_read_int(FILE *inf, int *i)
{ {
char bytes[4]; char bytes[4];
int input; int input;
@ -307,7 +307,7 @@ rs_read_int(int inf, int *i)
} }
bool bool
rs_read_uint(int inf, unsigned int *i) rs_read_uint(FILE *inf, unsigned int *i)
{ {
char bytes[4]; char bytes[4];
int input; int input;
@ -330,7 +330,7 @@ rs_read_uint(int inf, unsigned int *i)
} }
bool bool
rs_read_ulong(int inf, unsigned long *i) rs_read_ulong(FILE *inf, unsigned long *i)
{ {
char bytes[4]; char bytes[4];
unsigned long input; unsigned long input;
@ -355,7 +355,7 @@ rs_read_ulong(int inf, unsigned long *i)
} }
bool bool
rs_read_long(int inf, long *i) rs_read_long(FILE *inf, long *i)
{ {
char bytes[4]; char bytes[4];
long input; long input;
@ -380,7 +380,7 @@ rs_read_long(int inf, long *i)
} }
bool bool
rs_read_boolean(int inf, bool *i) rs_read_boolean(FILE *inf, bool *i)
{ {
char buf; char buf;
@ -423,7 +423,7 @@ rs_write_short(FILE *savef, short c)
} }
bool bool
rs_read_short(int inf, short *s) rs_read_short(FILE *inf, short *s)
{ {
char bytes[2]; char bytes[2];
short input; short input;
@ -496,7 +496,7 @@ rs_write_booleans(FILE *savef, bool *c, int count)
} }
bool bool
rs_read_ints(int inf, int *i, int count) rs_read_ints(FILE *inf, int *i, int count)
{ {
int n=0,value=0; int n=0,value=0;
@ -515,7 +515,7 @@ rs_read_ints(int inf, int *i, int count)
} }
bool bool
rs_read_shorts(int inf, short *i, int count) rs_read_shorts(FILE *inf, short *i, int count)
{ {
int n=0,value=0; int n=0,value=0;
@ -534,7 +534,7 @@ rs_read_shorts(int inf, short *i, int count)
} }
bool bool
rs_read_longs(int inf, long *i, int count) rs_read_longs(FILE *inf, long *i, int count)
{ {
int n=0,value=0; int n=0,value=0;
@ -553,7 +553,7 @@ rs_read_longs(int inf, long *i, int count)
} }
bool bool
rs_read_ulongs(int inf, unsigned long *i, int count) rs_read_ulongs(FILE *inf, unsigned long *i, int count)
{ {
int n=0,value=0; int n=0,value=0;
@ -572,7 +572,7 @@ rs_read_ulongs(int inf, unsigned long *i, int count)
} }
bool bool
rs_read_booleans(int inf, bool *i, int count) rs_read_booleans(FILE *inf, bool *i, int count)
{ {
int n=0,value=0; int n=0,value=0;
@ -611,7 +611,7 @@ rs_write_levtype(FILE *savef, LEVTYPE c)
} }
bool bool
rs_read_levtype(int inf, LEVTYPE *l) rs_read_levtype(FILE *inf, LEVTYPE *l)
{ {
int lt; int lt;
@ -640,7 +640,7 @@ rs_write_char(FILE *savef, char c)
} }
bool bool
rs_read_char(int inf, char *c) rs_read_char(FILE *inf, char *c)
{ {
rs_read(inf, c, 1); rs_read(inf, c, 1);
@ -657,7 +657,7 @@ rs_write_uchar(FILE *savef, unsigned char c)
} }
bool bool
rs_read_uchar(int inf, unsigned char *c) rs_read_uchar(FILE *inf, unsigned char *c)
{ {
rs_read(inf, c, 1); rs_read(inf, c, 1);
@ -678,7 +678,7 @@ rs_write_string(FILE *savef, char *s)
} }
bool bool
rs_read_string_index(int inf, struct words master[], int maxindex, char **str) rs_read_string_index(FILE *inf, struct words master[], int maxindex, char **str)
{ {
int i; int i;
@ -718,7 +718,7 @@ rs_write_string_index(FILE *savef, struct words master[], int maxindex, char *st
} }
bool bool
rs_read_scrolls(int inf) rs_read_scrolls(FILE *inf)
{ {
int i; int i;
@ -747,7 +747,7 @@ rs_write_scrolls(FILE *savef)
} }
bool bool
rs_read_potions(int inf) rs_read_potions(FILE *inf)
{ {
int i; int i;
@ -777,7 +777,7 @@ rs_write_potions(FILE *savef)
} }
bool bool
rs_read_rings(int inf) rs_read_rings(FILE *inf)
{ {
int i; int i;
@ -807,7 +807,7 @@ rs_write_rings(FILE *savef)
} }
bool bool
rs_read_misc(int inf) rs_read_misc(FILE *inf)
{ {
int i; int i;
@ -859,7 +859,7 @@ rs_write_sticks(FILE *savef)
} }
bool bool
rs_read_sticks(int inf) rs_read_sticks(FILE *inf)
{ {
int i = 0, list = 0; int i = 0, list = 0;
@ -884,7 +884,7 @@ rs_read_sticks(int inf)
} }
bool bool
rs_read_string(int inf, char *s, int max) rs_read_string(FILE *inf, char *s, int max)
{ {
int len = 0; int len = 0;
@ -904,7 +904,7 @@ rs_read_string(int inf, char *s, int max)
} }
bool bool
rs_read_new_string(int inf, char **s) rs_read_new_string(FILE *inf, char **s)
{ {
int len=0; int len=0;
char *buf=0; char *buf=0;
@ -966,7 +966,7 @@ rs_write_words(FILE *savef, struct words *w, int count)
} }
bool bool
rs_read_words(int inf, struct words *w, int count) rs_read_words(FILE *inf, struct words *w, int count)
{ {
int n = 0; int n = 0;
int value = 0; int value = 0;
@ -989,7 +989,7 @@ rs_read_words(int inf, struct words *w, int count)
} }
bool bool
rs_read_new_strings(int inf, char **s, int count) rs_read_new_strings(FILE *inf, char **s, int count)
{ {
int len = 0; int len = 0;
int n = 0; int n = 0;
@ -1034,7 +1034,7 @@ rs_write_coord(FILE *savef, coord *c)
} }
bool bool
rs_read_coord(int inf, coord *c) rs_read_coord(FILE *inf, coord *c)
{ {
rs_read_int(inf,&c->x); rs_read_int(inf,&c->x);
rs_read_int(inf,&c->y); rs_read_int(inf,&c->y);
@ -1233,7 +1233,7 @@ rs_write_daemons(FILE *savef, struct delayed_action *d_list,int count)
} }
bool bool
rs_read_daemons(int inf, struct delayed_action *d_list, int count) rs_read_daemons(FILE *inf, struct delayed_action *d_list, int count)
{ {
int i = 0; int i = 0;
int func = 0; int func = 0;
@ -1438,7 +1438,7 @@ rs_write_rooms(FILE *savef, struct room r[], int count)
} }
bool bool
rs_read_rooms(int inf, struct room *r, int count) rs_read_rooms(FILE *inf, struct room *r, int count)
{ {
int value = 0, n = 0, i = 0, index = 0, id = 0; int value = 0, n = 0, i = 0, index = 0, id = 0;
struct linked_list *fires=NULL, *item = NULL; struct linked_list *fires=NULL, *item = NULL;
@ -1551,7 +1551,7 @@ rs_write_object(FILE *savef, struct object *o)
} }
bool bool
rs_read_object(int inf, struct object *o) rs_read_object(FILE *inf, struct object *o)
{ {
int id; int id;
@ -1612,7 +1612,7 @@ rs_write_stats(FILE *savef, struct stats *s)
} }
bool bool
rs_read_stats(int inf, struct stats *s) rs_read_stats(FILE *inf, struct stats *s)
{ {
int id; int id;
@ -1666,7 +1666,7 @@ rs_write_mstats(FILE *savef, struct mstats *s)
} }
bool bool
rs_read_mstats(int inf, struct mstats *s) rs_read_mstats(FILE *inf, struct mstats *s)
{ {
int id; int id;
@ -1726,7 +1726,7 @@ rs_write_init_weps(FILE *savef, struct init_weps *w, int count)
} }
bool bool
rs_read_init_weps(int inf, struct init_weps *w,int count) rs_read_init_weps(FILE *inf, struct init_weps *w,int count)
{ {
int id,value,i; int id,value,i;
@ -1773,7 +1773,7 @@ rs_write_init_armor(FILE *savef, struct init_armor *a, int count)
} }
bool bool
rs_read_init_armor(int inf, struct init_armor *a,int count) rs_read_init_armor(FILE *inf, struct init_armor *a,int count)
{ {
int id,value,i; int id,value,i;
@ -1810,7 +1810,7 @@ rs_write_spells(FILE *savef, struct spells *s, int count)
} }
bool bool
rs_read_spells(int inf, struct spells *s,int count) rs_read_spells(FILE *inf, struct spells *s,int count)
{ {
int id,value,i; int id,value,i;
@ -1838,7 +1838,7 @@ rs_write_item_list(FILE *savef, struct item_list *i)
} }
bool bool
rs_read_item_list(int inf, struct item_list *i) rs_read_item_list(FILE *inf, struct item_list *i)
{ {
int id; int id;
@ -1860,7 +1860,7 @@ rs_write_h_list(FILE *savef, struct h_list *h)
} }
bool bool
rs_read_h_list(int inf, struct h_list *h) rs_read_h_list(FILE *inf, struct h_list *h)
{ {
int id; int id;
@ -1889,7 +1889,7 @@ rs_write_death_types(FILE *savef, struct death_type *d,int count)
} }
bool bool
rs_read_death_types(int inf, struct death_type *d, int count) rs_read_death_types(FILE *inf, struct death_type *d, int count)
{ {
int id,value,i; int id,value,i;
@ -1935,7 +1935,7 @@ rs_write_character_types(FILE *savef, struct character_types *c, int count)
} }
bool bool
rs_read_character_types(int inf, struct character_types *c,int count) rs_read_character_types(FILE *inf, struct character_types *c,int count)
{ {
int id,value,i; int id,value,i;
@ -1984,7 +1984,7 @@ rs_write_traps(FILE *savef, struct trap *trap,int count)
} }
bool bool
rs_read_traps(int inf, struct trap *trap, int count) rs_read_traps(FILE *inf, struct trap *trap, int count)
{ {
int id = 0, value = 0, n = 0; int id = 0, value = 0, n = 0;
@ -2054,7 +2054,7 @@ rs_write_monsters(FILE * savef, struct monster * m, int count)
} }
bool bool
rs_read_monsters(int inf, struct monster *m, int count) rs_read_monsters(FILE *inf, struct monster *m, int count)
{ {
int id = 0, value = 0, n = 0; int id = 0, value = 0, n = 0;
char buffer[1024]; char buffer[1024];
@ -2130,7 +2130,7 @@ rs_write_coord_list(FILE *savef, struct linked_list *l)
} }
bool bool
rs_read_coord_list(int inf, struct linked_list **list) rs_read_coord_list(FILE *inf, struct linked_list **list)
{ {
int id; int id;
int i, cnt; int i, cnt;
@ -2190,7 +2190,7 @@ rs_write_object_list(FILE *savef, struct linked_list *l)
} }
bool bool
rs_read_object_list(int inf, struct linked_list **list) rs_read_object_list(FILE *inf, struct linked_list **list)
{ {
int id; int id;
int i, cnt; int i, cnt;
@ -2398,7 +2398,7 @@ rs_fix_thing(struct thing *t)
} }
bool bool
rs_read_thing(int inf, struct thing *t) rs_read_thing(FILE *inf, struct thing *t)
{ {
int id; int id;
int listid = 0, index = -1; int listid = 0, index = -1;
@ -2542,7 +2542,7 @@ rs_fix_monster_list(struct linked_list *list)
} }
bool bool
rs_read_monster_list(int inf, struct linked_list **list) rs_read_monster_list(FILE *inf, struct linked_list **list)
{ {
int id; int id;
int i, cnt; int i, cnt;
@ -2605,7 +2605,7 @@ rs_write_magic_items(FILE *savef, struct magic_item *i, int count)
} }
bool bool
rs_read_magic_items(int inf, struct magic_item *mi, int count) rs_read_magic_items(FILE *inf, struct magic_item *mi, int count)
{ {
int id; int id;
int n; int n;
@ -2664,7 +2664,7 @@ rs_write_window(FILE *savef, WINDOW *win)
} }
bool bool
rs_read_window(int inf, WINDOW *win) rs_read_window(FILE *inf, WINDOW *win)
{ {
int row,col,maxlines,maxcols,value,width,height; int row,col,maxlines,maxcols,value,width,height;
@ -2849,7 +2849,7 @@ rs_save_file(FILE *savef)
} }
bool bool
rs_restore_file(int inf) rs_restore_file(FILE *inf)
{ {
int weapon, armor, ring, misc, room = -1,i,checkpoint; int weapon, armor, ring, misc, room = -1,i,checkpoint;
int endian = 0x01020304; int endian = 0x01020304;
@ -3034,9 +3034,8 @@ int
rs_read_scorefile(FILE *savef, struct sc_ent *entries, int count) rs_read_scorefile(FILE *savef, struct sc_ent *entries, int count)
{ {
int i,available = 0; int i,available = 0;
int sfd = md_fileno(savef);
rs_read_int(sfd, &available); rs_read_int(savef, &available);
if (end_of_file) if (end_of_file)
return(-1); return(-1);
@ -3046,15 +3045,15 @@ rs_read_scorefile(FILE *savef, struct sc_ent *entries, int count)
for(i = 0; i < count; i++) for(i = 0; i < count; i++)
{ {
rs_read_ulong(sfd, &entries[i].sc_score); rs_read_ulong(savef, &entries[i].sc_score);
rs_read(sfd, entries[i].sc_name, sizeof(entries[i].sc_name)); rs_read(savef, entries[i].sc_name, sizeof(entries[i].sc_name));
rs_read(sfd, entries[i].sc_system, sizeof(entries[i].sc_system)); rs_read(savef, entries[i].sc_system, sizeof(entries[i].sc_system));
rs_read(sfd, entries[i].sc_login, sizeof(entries[i].sc_login)); rs_read(savef, entries[i].sc_login, sizeof(entries[i].sc_login));
rs_read_short(sfd, &entries[i].sc_flags); rs_read_short(savef, &entries[i].sc_flags);
rs_read_short(sfd, &entries[i].sc_level); rs_read_short(savef, &entries[i].sc_level);
rs_read_short(sfd, &entries[i].sc_ctype); rs_read_short(savef, &entries[i].sc_ctype);
rs_read_short(sfd, &entries[i].sc_monster); rs_read_short(savef, &entries[i].sc_monster);
rs_read_short(sfd, &entries[i].sc_quest); rs_read_short(savef, &entries[i].sc_quest);
} }
return(0); return(0);