# HG changeset patch # User John "Elwin" Edwards # Date 1505519874 14400 # Node ID d3968e9cb98d2fd9413ed94d23138e4f15e41c04 # Parent c222f9d567765c9a68f861406b0854c168363bc5 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. diff -r c222f9d56776 -r d3968e9cb98d arogue5/main.c --- a/arogue5/main.c Sun Sep 10 17:30:13 2017 -0400 +++ b/arogue5/main.c Fri Sep 15 19:57:54 2017 -0400 @@ -20,6 +20,7 @@ #include #include #include +#include #include "mach_dep.h" #include "network.h" #include "rogue.h" @@ -245,10 +246,22 @@ } void +reopen_score(void) +{ + if (scoreboard != NULL) + fclose(scoreboard); + scoreboard = fopen(score_file, "r+"); + if (scoreboard == NULL && errno == ENOENT) { + scoreboard = fopen(score_file, "w+"); + } +} + + +void open_records(void) { - if (scorefd == -1) - md_reopen_score(); + if (scoreboard == NULL) + reopen_score(); #ifdef LOGFILE if (logfile == NULL) logfile = fopen(LOGFILE, "a"); diff -r c222f9d56776 -r d3968e9cb98d arogue5/mdport.c --- a/arogue5/mdport.c Sun Sep 10 17:30:13 2017 -0400 +++ b/arogue5/mdport.c Fri Sep 15 19:57:54 2017 -0400 @@ -696,17 +696,6 @@ #endif } -extern int scorefd; -extern char score_file[]; - -void -md_reopen_score(void) -{ - if (scorefd > 0) - close(scorefd); - scorefd = open(score_file, O_RDWR | O_CREAT, 0666); -} - /* Cursor/Keypad Support diff -r c222f9d56776 -r d3968e9cb98d arogue5/options.c --- a/arogue5/options.c Sun Sep 10 17:30:13 2017 -0400 +++ b/arogue5/options.c Fri Sep 15 19:57:54 2017 -0400 @@ -103,7 +103,7 @@ return status; if (strcmp(old_score_file, optstr)) { - md_reopen_score(); + reopen_score(); } return status; } diff -r c222f9d56776 -r d3968e9cb98d arogue5/rip.c --- a/arogue5/rip.c Sun Sep 10 17:30:13 2017 -0400 +++ b/arogue5/rip.c Fri Sep 15 19:57:54 2017 -0400 @@ -36,9 +36,6 @@ * scoreout() and scorein() to reflect the change. Also update SCORELEN. */ -extern int scorefd; -extern FILE *logfile; - struct sc_ent { unsigned long sc_score; char sc_name[LINELEN]; @@ -72,7 +69,7 @@ }; char *killname(short monst); -void scorein(struct sc_ent scores[], int fd); +void scorein(struct sc_ent scores[], FILE *inf); void scoreout(struct sc_ent scores[], FILE *outf); void showpack(char *howso); int update(struct sc_ent top_ten[], unsigned long amount, short quest, @@ -170,10 +167,8 @@ register struct sc_ent *scp; register int i; register struct sc_ent *sc2; - register FILE *outf; register char *killer; register int prflags = 0; - register int fd; short upquest = 0, wintype = 0, uplevel = 0, uptype = 0; /* For network updating */ char upsystem[SYSLEN], uplogin[LOGLEN]; char *thissys; /* Holds the name of this system */ @@ -204,12 +199,11 @@ * Open file and read list */ - if ((fd = scorefd) < 0) + if (scoreboard == NULL) { printf("\nCannot open score_file.\n"); return; } - outf = (FILE *) md_fdopen(fd, "w"); /* Get this system's name */ thissys = md_gethostname(); @@ -257,7 +251,7 @@ #endif /* Read the score and convert it to a compatible format */ - scorein(top_ten, fd); /* Convert it */ + scorein(top_ten, scoreboard); /* Convert it */ /* Get some values if this is an update */ if (flags == UPDATE) { @@ -283,7 +277,7 @@ errors++; if (errors) { - fclose(outf); + fclose(scoreboard); free(compatstr); return; } @@ -475,12 +469,12 @@ } } - fseek(outf, 0L, 0); + fseek(scoreboard, 0L, 0); /* * Update the list file */ - scoreout(top_ten, outf); - fclose(outf); + scoreout(top_ten, scoreboard); + fclose(scoreboard); /* * SCOREIT -- rogue -s option. Never started curses if this option. @@ -627,17 +621,17 @@ * score file by scoreout() back to a score file structure. */ void -scorein(struct sc_ent scores[], int fd) +scorein(struct sc_ent scores[], FILE *inf) { int i; char scoreline[100]; for(i = 0; i < NUMSCORE; i++) { - encread((char *) &scores[i].sc_name, LINELEN, fd); - encread((char *) &scores[i].sc_system, SYSLEN, fd); - encread((char *) &scores[i].sc_login, LINELEN, fd); - encread((char *) scoreline, 100, fd); + encread((char *) &scores[i].sc_name, LINELEN, inf); + encread((char *) &scores[i].sc_system, SYSLEN, inf); + encread((char *) &scores[i].sc_login, LINELEN, inf); + encread((char *) scoreline, 100, inf); sscanf(scoreline, " %lu %d %d %d %d %d \n", &scores[i].sc_score, &scores[i].sc_flgs, &scores[i].sc_level, &scores[i].sc_ctype, diff -r c222f9d56776 -r d3968e9cb98d arogue5/rogue.c --- a/arogue5/rogue.c Sun Sep 10 17:30:13 2017 -0400 +++ b/arogue5/rogue.c Fri Sep 15 19:57:54 2017 -0400 @@ -64,7 +64,6 @@ int spell_power = 0; int turns = 0; /* Number of turns player has taken */ int quest_item = 0; /* Item player is looking for */ -int scorefd = -1; /* File descriptor for the scorefile */ char nfloors = -1; /* Number of floors in this dungeon */ char curpurch[LINELEN*2]; /* name of item ready to buy */ char PLAYER = VPLAYER; /* what the player looks like */ @@ -124,6 +123,7 @@ char *morestr = "-- More --"; char *retstr = "[Press return to continue]"; +FILE *scoreboard = NULL; /* The scorefile */ FILE *logfile = NULL; /* diff -r c222f9d56776 -r d3968e9cb98d arogue5/rogue.h --- a/arogue5/rogue.h Sun Sep 10 17:30:13 2017 -0400 +++ b/arogue5/rogue.h Fri Sep 15 19:57:54 2017 -0400 @@ -1009,7 +1009,7 @@ bool dropcheck(struct object *op); void dust_appear(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); void endit(int sig); void endmsg(void); @@ -1097,6 +1097,7 @@ short randmonster(bool wander, bool no_unique); void read_scroll(int which, int flag, bool is_scroll); int readchar(void); +void reopen_score(void); void res_dexterity(int howmuch); void res_strength(void); bool restore(char *file, char **envp); @@ -1114,7 +1115,7 @@ int roll(int number, int sides); void rollwand(void); struct room *roomin(coord *cp); -int rs_restore_file(int inf); +int rs_restore_file(FILE *inf); int rs_save_file(FILE *savef); void runners(void); void runto(struct thing *runner, coord *spot); @@ -1191,7 +1192,6 @@ extern int md_normaluser(void); extern int md_getuid(void); extern long md_memused(void); -extern void md_reopen_score(void); extern int md_readchar(WINDOW *win); extern int md_shellescape(void); extern int md_srand(int seed); @@ -1266,7 +1266,6 @@ extern int spell_power; /* Spell power left at this level */ extern int turns; /* Number of turns player has taken */ extern int quest_item; /* Item hero is looking for */ -extern int scorefd; /* File descriptor for the scorefile */ extern int cur_relic[]; /* Current relics */ extern char take; /* Thing the rogue is taking */ extern char prbuf[]; /* Buffer for sprintfs */ @@ -1338,4 +1337,5 @@ extern char *metal[NMETAL]; extern char *wood[NWOOD]; extern coord ch_ret; +extern FILE *scoreboard; /* The scorefile */ extern FILE *logfile; diff -r c222f9d56776 -r d3968e9cb98d arogue5/save.c --- a/arogue5/save.c Sun Sep 10 17:30:13 2017 -0400 +++ b/arogue5/save.c Fri Sep 15 19:57:54 2017 -0400 @@ -151,7 +151,7 @@ bool restore(char *file, char **envp) { - register int inf; + FILE *inf; #ifndef _AIX extern char **environ; #endif @@ -162,7 +162,7 @@ if (strcmp(file, "-r") == 0) file = file_name; - if ((inf = open(file, O_RDONLY)) < 0) + if ((inf = fopen(file, "r")) == NULL) { if (use_savedir && errno == ENOENT) { @@ -189,7 +189,7 @@ encread(buf, 80, inf); sscanf(buf, "%d x %d\n", &oldline, &oldcol); - fstat(inf, &sbuf2); + stat(file, &sbuf2); fflush(stdout); /* @@ -235,7 +235,7 @@ if (!wizard) { if (md_unlink(file) < 0) { - close(inf); /* only close if system insists */ + fclose(inf); /* only close if system insists */ if (md_unlink(file) < 0) { endwin(); printf("\nCannot unlink file\n"); @@ -287,12 +287,12 @@ * perform an encrypted read */ int -encread(char *start, unsigned int size, int inf) +encread(char *start, unsigned int size, FILE *inf) { register char *ep; 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; ep = encstr; diff -r c222f9d56776 -r d3968e9cb98d arogue5/state.c --- a/arogue5/state.c Sun Sep 10 17:30:13 2017 -0400 +++ b/arogue5/state.c Fri Sep 15 19:57:54 2017 -0400 @@ -64,11 +64,11 @@ #include #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 list_size(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 WRITESTAT (write_error) @@ -92,7 +92,7 @@ } int -rs_read(int inf, void *ptr, size_t size) +rs_read(FILE *inf, void *ptr, size_t size) { if (read_error || format_error) return(READSTAT); @@ -115,7 +115,7 @@ } int -rs_read_uchar(int inf, unsigned char *c) +rs_read_uchar(FILE *inf, unsigned char *c) { if (read_error || format_error) return(READSTAT); @@ -137,7 +137,7 @@ } int -rs_read_char(int inf, char *c) +rs_read_char(FILE *inf, char *c) { if (read_error || format_error) return(READSTAT); @@ -160,7 +160,7 @@ } int -rs_read_chars(int inf, char *i, int count) +rs_read_chars(FILE *inf, char *i, int count) { int value = 0; @@ -201,7 +201,7 @@ } int -rs_read_int(int inf, int *i) +rs_read_int(FILE *inf, int *i) { unsigned char bytes[4]; int input = 0; @@ -244,7 +244,7 @@ } int -rs_read_ints(int inf, int *i, int count) +rs_read_ints(FILE *inf, int *i, int count) { int n, value; @@ -277,7 +277,7 @@ } int -rs_read_boolean(int inf, bool *i) +rs_read_boolean(FILE *inf, bool *i) { unsigned char buf = 0; @@ -309,7 +309,7 @@ } int -rs_read_booleans(int inf, bool *i, int count) +rs_read_booleans(FILE *inf, bool *i, int count) { int n = 0, value = 0; @@ -350,7 +350,7 @@ } int -rs_read_short(int inf, short *i) +rs_read_short(FILE *inf, short *i) { unsigned char bytes[2]; short input; @@ -391,7 +391,7 @@ } int -rs_read_shorts(int inf, short *i, int count) +rs_read_shorts(FILE *inf, short *i, int count) { int n = 0, value = 0; @@ -432,7 +432,7 @@ } int -rs_read_ushort(int inf, unsigned short *i) +rs_read_ushort(FILE *inf, unsigned short *i) { unsigned char bytes[2]; unsigned short input; @@ -479,7 +479,7 @@ } int -rs_read_uint(int inf, unsigned int *i) +rs_read_uint(FILE *inf, unsigned int *i) { unsigned char bytes[4]; int input; @@ -535,7 +535,7 @@ } int -rs_read_long(int inf, long *i) +rs_read_long(FILE *inf, long *i) { unsigned char bytes[4]; long input; @@ -577,7 +577,7 @@ } int -rs_read_longs(int inf, long *i, int count) +rs_read_longs(FILE *inf, long *i, int count) { int n = 0, value = 0; @@ -627,7 +627,7 @@ } int -rs_read_ulong(int inf, unsigned long *i) +rs_read_ulong(FILE *inf, unsigned long *i) { unsigned char bytes[4]; unsigned long input; @@ -673,7 +673,7 @@ } 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; @@ -704,7 +704,7 @@ } int -rs_read_marker(int inf, int id) +rs_read_marker(FILE *inf, int id) { int nid; @@ -739,7 +739,7 @@ } int -rs_read_string(int inf, char *s, int max) +rs_read_string(FILE *inf, char *s, int max) { int len = 0; @@ -757,7 +757,7 @@ } int -rs_read_new_string(int inf, char **s) +rs_read_new_string(FILE *inf, char **s) { int len=0; char *buf=0; @@ -802,7 +802,7 @@ } 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 value = 0; @@ -823,7 +823,7 @@ } 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 value = 0; @@ -859,7 +859,7 @@ } 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; @@ -891,7 +891,7 @@ } int -rs_read_coord(int inf, coord *c) +rs_read_coord(FILE *inf, coord *c) { coord in; @@ -926,7 +926,7 @@ } int -rs_read_coord_list(int inf, struct linked_list **list) +rs_read_coord_list(FILE *inf, struct linked_list **list) { int i, cnt; struct linked_list *l = NULL, *previous = NULL, *head = NULL; @@ -984,7 +984,7 @@ } int -rs_read_window(int inf, WINDOW *win) +rs_read_window(FILE *inf, WINDOW *win) { int row,col,maxlines,maxcols,value,width,height; @@ -1071,7 +1071,7 @@ } int -rs_read_levtype(int inf, LEVTYPE *l) +rs_read_levtype(FILE *inf, LEVTYPE *l) { int lt; @@ -1114,7 +1114,7 @@ } int -rs_read_stats(int inf, struct stats *s) +rs_read_stats(FILE *inf, struct stats *s) { if (read_error || format_error) return(READSTAT); @@ -1155,7 +1155,7 @@ } 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 value; @@ -1196,7 +1196,7 @@ } int -rs_read_scrolls(int inf) +rs_read_scrolls(FILE *inf) { int i; @@ -1232,7 +1232,7 @@ } int -rs_read_potions(int inf) +rs_read_potions(FILE *inf) { int i; @@ -1268,7 +1268,7 @@ } int -rs_read_rings(int inf) +rs_read_rings(FILE *inf) { int i; @@ -1316,7 +1316,7 @@ } int -rs_read_sticks(int inf) +rs_read_sticks(FILE *inf) { int i = 0, j = 0, list = 0; @@ -1501,7 +1501,7 @@ } 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 func = 0; @@ -1643,7 +1643,7 @@ } 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; struct linked_list *fires=NULL, *item = NULL; @@ -1700,7 +1700,7 @@ } 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; @@ -1736,7 +1736,7 @@ } int -rs_read_room_reference(int inf, struct room **rp) +rs_read_room_reference(FILE *inf, struct room **rp) { int i; @@ -1783,7 +1783,7 @@ } int -rs_read_door_reference(int inf, coord **exit) +rs_read_door_reference(FILE *inf, coord **exit) { int i, idx; @@ -1818,7 +1818,7 @@ } 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; @@ -1865,7 +1865,7 @@ } 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; @@ -1917,7 +1917,7 @@ } int -rs_read_object(int inf, struct object *o) +rs_read_object(FILE *inf, struct object *o) { if (read_error || format_error) return(READSTAT); @@ -1958,7 +1958,7 @@ } int -rs_read_object_list(int inf, struct linked_list **list) +rs_read_object_list(FILE *inf, struct linked_list **list) { int i, cnt; struct linked_list *l = NULL, *previous = NULL, *head = NULL; @@ -2010,7 +2010,7 @@ } 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; @@ -2156,7 +2156,7 @@ } int -rs_read_thing(int inf, struct thing *t) +rs_read_thing(FILE *inf, struct thing *t) { int listid = 0, index = -1; @@ -2275,7 +2275,7 @@ } int -rs_read_thing_list(int inf, struct linked_list **list) +rs_read_thing_list(FILE *inf, struct linked_list **list) { int i, cnt; struct linked_list *l = NULL, *previous = NULL, *head = NULL; @@ -2444,7 +2444,7 @@ } int -rs_restore_file(int inf) +rs_restore_file(FILE *inf) { int i; diff -r c222f9d56776 -r d3968e9cb98d arogue7/main.c --- a/arogue7/main.c Sun Sep 10 17:30:13 2017 -0400 +++ b/arogue7/main.c Fri Sep 15 19:57:54 2017 -0400 @@ -16,6 +16,7 @@ #include #include #include +#include #ifdef BSD #include #else @@ -551,10 +552,20 @@ } void +reopen_score(void) +{ + if (scoreboard != NULL) + fclose(scoreboard); + scoreboard = fopen(score_file, "r+"); + if (scoreboard == NULL && errno == ENOENT) + scoreboard = fopen(score_file, "w+"); +} + +void open_records(void) { - if (scorefd == -1) - md_reopen_score(); + if (scoreboard == NULL) + reopen_score(); #ifdef LOGFILE if (logfile == NULL) logfile = fopen(LOGFILE, "a"); diff -r c222f9d56776 -r d3968e9cb98d arogue7/mdport.c --- a/arogue7/mdport.c Sun Sep 10 17:30:13 2017 -0400 +++ b/arogue7/mdport.c Fri Sep 15 19:57:54 2017 -0400 @@ -155,10 +155,10 @@ } int -md_unlink_open_file(char *file, int inf) +md_unlink_open_file(char *file, FILE *inf) { #ifdef _WIN32 - close(inf); + fclose(inf); chmod(file, 0600); return( _unlink(file) ); #else @@ -677,17 +677,6 @@ #endif } -extern int scorefd; -extern char score_file[]; - -void -md_reopen_score(void) -{ - if (scorefd > 0) - close(scorefd); - scorefd = open(score_file, O_RDWR | O_CREAT, 0666); -} - /* Cursor/Keypad Support diff -r c222f9d56776 -r d3968e9cb98d arogue7/options.c --- a/arogue7/options.c Sun Sep 10 17:30:13 2017 -0400 +++ b/arogue7/options.c Fri Sep 15 19:57:54 2017 -0400 @@ -497,7 +497,7 @@ status = get_str(optstr, win); if (status == NORM && strcmp(old_score_file, optstr)) { - md_reopen_score(); + reopen_score(); } return status; } diff -r c222f9d56776 -r d3968e9cb98d arogue7/rip.c --- a/arogue7/rip.c Sun Sep 10 17:30:13 2017 -0400 +++ b/arogue7/rip.c Fri Sep 15 19:57:54 2017 -0400 @@ -46,9 +46,6 @@ extern char oldtext[WTXTNUM][WTXTLEN]; #endif -extern int scorefd; -extern FILE *logfile; - #ifdef NUMNET /* Network machines (for mutual score keeping) */ static struct network Network[NUMNET] = { @@ -256,10 +253,8 @@ register struct sc_ent *scp; register int i; register struct sc_ent *sc2; - register int outfd; register char *killer; register int prflags = 0; - register int fd; short upquest, wintype, uplevel, uptype; /* For network updating */ char upsystem[SYSLEN], uplogin[LOGLEN]; char *thissys; /* Holds the name of this system */ @@ -290,11 +285,10 @@ purse = 0; /* Steal all the gold */ /* - * Open file and read list + * Read list */ - if ((fd = scorefd) < 0) return; - outfd = fd; + if (scoreboard == NULL) return; #ifndef SYSTEM thissys = md_gethostname(); @@ -347,10 +341,10 @@ /* Read the score and convert it to a compatible format */ for(i = 0; i < NUMSCORE; i++) { - encread(top_ten[i].sc_name, NAMELEN, fd); - encread(top_ten[i].sc_system, SYSLEN, fd); - encread(top_ten[i].sc_login, LOGLEN, fd); - encread(scoreline, 100, fd); + encread(top_ten[i].sc_name, NAMELEN, scoreboard); + encread(top_ten[i].sc_system, SYSLEN, scoreboard); + encread(top_ten[i].sc_login, LOGLEN, scoreboard); + encread(scoreline, 100, scoreboard); sscanf(scoreline, " %lu %hd %hd %hd %hd %hd \n", &top_ten[i].sc_score, &top_ten[i].sc_flags, &top_ten[i].sc_level, &top_ten[i].sc_ctype, @@ -383,7 +377,7 @@ errors++; if (errors) { - close(outfd); + fclose(scoreboard); free(compatstr); return; } @@ -646,7 +640,7 @@ } /* if (prflags == EDITSCORE) endwin();*/ /* End editing windowing */ } - lseek(outfd, 0L, 0); + fseek(scoreboard, 0L, SEEK_SET); /* * Update the list file */ @@ -654,17 +648,17 @@ for(i = 0; i < NUMSCORE; i++) { memset(scoreline,0,100); - encwrite(top_ten[i].sc_name, NAMELEN, outfd); - encwrite(top_ten[i].sc_system, SYSLEN, outfd); - encwrite(top_ten[i].sc_login, LOGLEN, outfd); + encwrite(top_ten[i].sc_name, NAMELEN, scoreboard); + encwrite(top_ten[i].sc_system, SYSLEN, scoreboard); + encwrite(top_ten[i].sc_login, LOGLEN, scoreboard); sprintf(scoreline, " %lu %hd %hd %hd %hd %hd \n", top_ten[i].sc_score, top_ten[i].sc_flags, top_ten[i].sc_level, top_ten[i].sc_ctype, top_ten[i].sc_monster, top_ten[i].sc_quest); - encwrite(scoreline,100,outfd); + encwrite(scoreline,100,scoreboard); } - close(outfd); + fclose(scoreboard); } /* diff -r c222f9d56776 -r d3968e9cb98d arogue7/rogue.c --- a/arogue7/rogue.c Sun Sep 10 17:30:13 2017 -0400 +++ b/arogue7/rogue.c Fri Sep 15 19:57:54 2017 -0400 @@ -80,7 +80,6 @@ int spell_power = 0; int turns = 0; /* Number of turns player has taken */ int quest_item = 0; /* Item player is looking for */ -int scorefd = -1; /* File descriptor for score file */ int cols = 0; /* number of columns in terminal */ int lines = 0; /* number of lines on the terminal */ char nfloors = -1; /* Number of floors in this dungeon */ @@ -134,6 +133,7 @@ bool in_shell = FALSE; bool daytime = TRUE; bool use_savedir = FALSE; +FILE *scoreboard = NULL; /* Score file */ FILE *logfile = NULL; LEVTYPE levtype; /* type of level i'm on */ diff -r c222f9d56776 -r d3968e9cb98d arogue7/rogue.h --- a/arogue7/rogue.h Sun Sep 10 17:30:13 2017 -0400 +++ b/arogue7/rogue.h Fri Sep 15 19:57:54 2017 -0400 @@ -1208,8 +1208,8 @@ void eat_gold(struct object *obj); int effect(struct thing *att, struct thing *def, struct object *weap, bool thrown, bool see_att, bool see_def); -int encread(char *start, unsigned int size, int inf); -int encwrite(char *start, unsigned int size, int outf); +int encread(char *start, unsigned int size, FILE *inf); +int encwrite(char *start, unsigned int size, FILE *outf); void endmsg(void); void explode(struct thing *tp); void extinguish(void (*func)()); @@ -1314,6 +1314,7 @@ short randmonster(bool wander, bool no_unique); void read_scroll(int which, int flag, bool is_scroll); int readchar(void); +void reopen_score(void); void res_charisma(int howmuch); void res_constitution(int howmuch); void res_dexterity(int howmuch); @@ -1335,7 +1336,7 @@ int roll(int number, int sides); void rollwand(void); struct room *roomin(coord *cp); -int rs_restore_file(int inf); +int rs_restore_file(FILE *inf); int rs_save_file(FILE *savef); int runners(int segments); void runto(struct thing *runner, coord *spot); @@ -1419,12 +1420,11 @@ int md_normaluser(void); int md_rand(void); unsigned int md_random_seed(void); -void md_reopen_score(void); int md_readchar(WINDOW *win); int md_shellescape(void); int md_srand(int seed); 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 int checkout(); @@ -1504,7 +1504,6 @@ extern int spell_power; /* Spell power left at this level */ extern int turns; /* Number of turns player has taken */ extern int quest_item; /* Item hero is looking for */ -extern int scorefd; /* File descriptor for score file */ extern int cur_relic[]; /* Current relics */ extern char take; /* Thing the rogue is taking */ extern char prbuf[]; /* Buffer for sprintfs */ @@ -1565,6 +1564,7 @@ extern char *morestr; extern char *retstr; extern FILE *logfile; +extern FILE *scoreboard; /* Score file */ extern LEVTYPE levtype; extern void (*add_abil[NUMABILITIES])(); /* Functions to change abilities */ extern void (*res_abil[NUMABILITIES])(); /* Functions to change abilities */ diff -r c222f9d56776 -r d3968e9cb98d arogue7/save.c --- a/arogue7/save.c Sun Sep 10 17:30:13 2017 -0400 +++ b/arogue7/save.c Fri Sep 15 19:57:54 2017 -0400 @@ -34,15 +34,15 @@ #endif #if u370 || uts -#define ENCREAD(b,n,fd) read(fd,b,n) -#define ENCWRITE(b,n,fd) write(fd,b,n) +#define ENCREAD(b,n,f) read(md_fileno(f),b,n) +#define ENCWRITE(b,n,f) write(md_fileno(f),b,n) #endif #ifndef ENCREAD #define ENCREAD encread #define ENCWRITE encwrite #endif -bool save_file(int savefd); +bool save_file(FILE *savef); typedef struct stat STAT; @@ -55,7 +55,7 @@ bool save_game(void) { - register int savefd; + FILE *savefi = NULL; register int c; char buf[LINELEN]; @@ -100,18 +100,18 @@ } strcpy(file_name, buf); 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() */ if (use_savedir) return FALSE; } - } while (savefd < 0); + } while (savefi == NULL); /* * write out encrpyted file (after a stat) */ - if (save_file(savefd) == FALSE) { + if (save_file(savefi) == FALSE) { msg("Cannot create save file."); md_unlink(file_name); return(FALSE); @@ -126,15 +126,15 @@ void auto_save(int sig) { - register int savefd; + FILE *savefi; register int i; for (i = 0; i < NSIG; i++) signal(i, SIG_IGN); if (file_name[0] != '\0' && pstats.s_hpt > 0 && - (savefd = open(file_name, O_WRONLY|O_CREAT|O_TRUNC, 0600)) >= 0) - save_file(savefd); + (savefi = fopen(file_name, "w")) != NULL) + save_file(savefi); endwin(); #ifdef PC7300 endhardwin(); @@ -146,21 +146,19 @@ * write the saved game on the file */ bool -save_file(int savefd) +save_file(FILE *savef) { register unsigned num_to_write, num_written; - FILE *savef; int ret; wmove(cw, lines-1, 0); draw(cw); - lseek(savefd, 0L, 0); - fstat(savefd, &sbuf); + fseek(savef, 0L, SEEK_SET); + stat(file_name, &sbuf); 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); - ENCWRITE(prbuf,80,savefd); - savef = (FILE *) md_fdopen(savefd,"wb"); + ENCWRITE(prbuf,80,savef); ret = rs_save_file(savef); fclose(savef); if (num_to_write == num_written && ret == 0) return(TRUE); @@ -170,7 +168,7 @@ bool restore(char *file, char *envp[]) { - register int inf; + FILE *inf; extern char **environ; char buf[LINELEN]; STAT sbuf2; @@ -178,7 +176,7 @@ if (strcmp(file, "-r") == 0) file = file_name; - if ((inf = open(file, 0)) < 0) + if ((inf = fopen(file, "r")) == NULL) { if (use_savedir && errno == ENOENT) { @@ -202,7 +200,7 @@ ENCREAD(buf, 80, inf); sscanf(buf, "%d x %d\n", &oldline, &oldcol); - fstat(inf, &sbuf2); + stat(file, &sbuf2); fflush(stdout); initscr(); @@ -228,7 +226,7 @@ if (rs_restore_file(inf) != 0) { printf("Cannot restore file\n"); - close(inf); + fclose(inf); return(FALSE); } @@ -265,7 +263,7 @@ * perform an encrypted write */ int -encwrite(char *start, unsigned int size, int outf) +encwrite(char *start, unsigned int size, FILE *outf) { register char *ep; register int i = 0; @@ -281,7 +279,7 @@ ep = encstr; if (i == ENCWBSIZ || size == 0) { - if (write(outf, buf, (unsigned)i) < i) + if (fwrite(buf, 1, (unsigned)i, outf) < i) return(num_written); else { num_written += i; @@ -296,12 +294,12 @@ * perform an encrypted read */ int -encread(char *start, unsigned int size, int inf) +encread(char *start, unsigned int size, FILE *inf) { register char *ep; 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; ep = encstr; diff -r c222f9d56776 -r d3968e9cb98d arogue7/state.c --- a/arogue7/state.c Sun Sep 10 17:30:13 2017 -0400 +++ b/arogue7/state.c Fri Sep 15 19:57:54 2017 -0400 @@ -75,9 +75,9 @@ int list_size(struct linked_list *l); 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_read_object_list(int inf, struct linked_list **list); +int rs_read_object_list(FILE *inf, struct linked_list **list); int rs_write(FILE *savef, void *ptr, size_t size) @@ -85,14 +85,14 @@ if (write_error) return(WRITESTAT); - if (encwrite(ptr, size, md_fileno(savef)) != size) + if (encwrite(ptr, size, savef) != size) write_error = 1; return(WRITESTAT); } int -rs_read(int inf, void *ptr, size_t size) +rs_read(FILE *inf, void *ptr, size_t size) { if (read_error || format_error) return(READSTAT); @@ -115,7 +115,7 @@ } int -rs_read_uchar(int inf, unsigned char *c) +rs_read_uchar(FILE *inf, unsigned char *c) { if (read_error || format_error) return(READSTAT); @@ -137,7 +137,7 @@ } int -rs_read_char(int inf, char *c) +rs_read_char(FILE *inf, char *c) { if (read_error || format_error) return(READSTAT); @@ -160,7 +160,7 @@ } int -rs_read_chars(int inf, char *i, int count) +rs_read_chars(FILE *inf, char *i, int count) { int value = 0; @@ -201,7 +201,7 @@ } int -rs_read_int(int inf, int *i) +rs_read_int(FILE *inf, int *i) { unsigned char bytes[4]; int input = 0; @@ -244,7 +244,7 @@ } int -rs_read_ints(int inf, int *i, int count) +rs_read_ints(FILE *inf, int *i, int count) { int n, value; @@ -277,7 +277,7 @@ } int -rs_read_boolean(int inf, bool *i) +rs_read_boolean(FILE *inf, bool *i) { unsigned char buf = 0; @@ -309,7 +309,7 @@ } int -rs_read_booleans(int inf, bool *i, int count) +rs_read_booleans(FILE *inf, bool *i, int count) { int n = 0, value = 0; @@ -350,7 +350,7 @@ } int -rs_read_short(int inf, short *i) +rs_read_short(FILE *inf, short *i) { unsigned char bytes[2]; short input; @@ -391,7 +391,7 @@ } int -rs_read_shorts(int inf, short *i, int count) +rs_read_shorts(FILE *inf, short *i, int count) { int n = 0, value = 0; @@ -432,7 +432,7 @@ } int -rs_read_ushort(int inf, unsigned short *i) +rs_read_ushort(FILE *inf, unsigned short *i) { unsigned char bytes[2]; unsigned short input; @@ -479,7 +479,7 @@ } int -rs_read_uint(int inf, unsigned int *i) +rs_read_uint(FILE *inf, unsigned int *i) { unsigned char bytes[4]; int input; @@ -535,7 +535,7 @@ } int -rs_read_long(int inf, long *i) +rs_read_long(FILE *inf, long *i) { unsigned char bytes[4]; long input; @@ -580,7 +580,7 @@ } int -rs_read_longs(int inf, long *i, int count) +rs_read_longs(FILE *inf, long *i, int count) { int n = 0, value = 0; @@ -630,7 +630,7 @@ } int -rs_read_ulong(int inf, unsigned long *i) +rs_read_ulong(FILE *inf, unsigned long *i) { unsigned char bytes[4]; unsigned long input; @@ -676,7 +676,7 @@ } 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; @@ -707,7 +707,7 @@ } int -rs_read_marker(int inf, int id) +rs_read_marker(FILE *inf, int id) { int nid; @@ -742,7 +742,7 @@ } int -rs_read_string(int inf, char *s, int max) +rs_read_string(FILE *inf, char *s, int max) { int len = 0; @@ -760,7 +760,7 @@ } int -rs_read_new_string(int inf, char **s) +rs_read_new_string(FILE *inf, char **s) { int len=0; char *buf=0; @@ -805,7 +805,7 @@ } 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 value = 0; @@ -826,7 +826,7 @@ } 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 value = 0; @@ -862,7 +862,7 @@ } 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; @@ -894,7 +894,7 @@ } int -rs_read_coord(int inf, coord *c) +rs_read_coord(FILE *inf, coord *c) { coord in; @@ -929,7 +929,7 @@ } int -rs_read_coord_list(int inf, struct linked_list **list) +rs_read_coord_list(FILE *inf, struct linked_list **list) { int i, cnt; struct linked_list *l = NULL, *previous = NULL, *head = NULL; @@ -987,7 +987,7 @@ } int -rs_read_window(int inf, WINDOW *win) +rs_read_window(FILE *inf, WINDOW *win) { int row,col,maxlines,maxcols,value,width,height; @@ -1075,7 +1075,7 @@ } int -rs_read_levtype(int inf, LEVTYPE *l) +rs_read_levtype(FILE *inf, LEVTYPE *l) { int lt; @@ -1120,7 +1120,7 @@ } int -rs_read_stats(int inf, struct stats *s) +rs_read_stats(FILE *inf, struct stats *s) { if (read_error || format_error) return(READSTAT); @@ -1165,7 +1165,7 @@ } 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 value; @@ -1210,7 +1210,7 @@ } int -rs_read_scrolls(int inf) +rs_read_scrolls(FILE *inf) { int i; @@ -1246,7 +1246,7 @@ } int -rs_read_potions(int inf) +rs_read_potions(FILE *inf) { int i; @@ -1282,7 +1282,7 @@ } int -rs_read_rings(int inf) +rs_read_rings(FILE *inf) { int i; @@ -1317,7 +1317,7 @@ } int -rs_read_misc(int inf) +rs_read_misc(FILE *inf) { int i; @@ -1364,7 +1364,7 @@ } int -rs_read_sticks(int inf) +rs_read_sticks(FILE *inf) { int i = 0, j = 0, list = 0; @@ -1588,7 +1588,7 @@ } 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 func = 0; @@ -1774,7 +1774,7 @@ } 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; struct linked_list *fires=NULL, *item = NULL; @@ -1831,7 +1831,7 @@ } 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; @@ -1867,7 +1867,7 @@ } int -rs_read_room_reference(int inf, struct room **rp) +rs_read_room_reference(FILE *inf, struct room **rp) { int i; @@ -1911,7 +1911,7 @@ } int -rs_read_door_reference(int inf, coord **exit) +rs_read_door_reference(FILE *inf, coord **exit) { int i, idx; @@ -1945,7 +1945,7 @@ } 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; @@ -1992,7 +1992,7 @@ } 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; @@ -2044,7 +2044,7 @@ } int -rs_read_object(int inf, struct object *o) +rs_read_object(FILE *inf, struct object *o) { if (read_error || format_error) return(READSTAT); @@ -2085,7 +2085,7 @@ } int -rs_read_object_list(int inf, struct linked_list **list) +rs_read_object_list(FILE *inf, struct linked_list **list) { int i, cnt; struct linked_list *l = NULL, *previous = NULL, *head = NULL; @@ -2137,7 +2137,7 @@ } 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; @@ -2280,7 +2280,7 @@ } int -rs_read_thing(int inf, struct thing *t) +rs_read_thing(FILE *inf, struct thing *t) { int listid = 0, index = -1; @@ -2395,7 +2395,7 @@ } int -rs_read_thing_list(int inf, struct linked_list **list) +rs_read_thing_list(FILE *inf, struct linked_list **list) { int i, cnt; struct linked_list *l = NULL, *previous = NULL, *head = NULL; @@ -2462,7 +2462,7 @@ } 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; @@ -2494,7 +2494,7 @@ } 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; @@ -2635,7 +2635,7 @@ } int -rs_restore_file(int inf) +rs_restore_file(FILE *inf) { int i; diff -r c222f9d56776 -r d3968e9cb98d rogue4/extern.c --- a/rogue4/extern.c Sun Sep 10 17:30:13 2017 -0400 +++ b/rogue4/extern.c Fri Sep 15 19:57:54 2017 -0400 @@ -100,8 +100,6 @@ int food_left; /* Amount of food in hero's stomach */ int group = 2; /* Current group number */ 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 */ 20, 35, @@ -136,6 +134,9 @@ THING *mlist = NULL; /* List of monsters on the level */ 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 */ #define INIT_STATS { 16, 0, 1, 10, 12, "1d4", 12 } diff -r c222f9d56776 -r d3968e9cb98d rogue4/extern.h --- a/rogue4/extern.h Sun Sep 10 17:30:13 2017 -0400 +++ b/rogue4/extern.h Fri Sep 15 19:57:54 2017 -0400 @@ -40,12 +40,14 @@ *ws_guess[], *ws_type[]; extern int a_chances[], a_class[], count, dnum, food_left, - fung_hit, fd, group, hungry_state, inpack, lastscore, - level, lfd, max_level, mpos, no_command, no_food, no_move, + fung_hit, group, hungry_state, inpack, lastscore, + level, max_level, mpos, no_command, no_food, no_move, ntraps, purse, quiet, total; extern long seed; +extern FILE *score_file, *log_file; + extern WINDOW *hw; /* @@ -92,5 +94,5 @@ extern int md_shellescape(void); extern void md_sleep(int s); 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); diff -r c222f9d56776 -r d3968e9cb98d rogue4/mach_dep.c --- a/rogue4/mach_dep.c Sun Sep 10 17:30:13 2017 -0400 +++ b/rogue4/mach_dep.c Fri Sep 15 19:57:54 2017 -0400 @@ -37,6 +37,7 @@ #include #include #include +#include #include "rogue.h" int num_checks; /* times we've gone over in checkout() */ @@ -80,9 +81,12 @@ open_score(void) { #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 - fd = -1; + score_file = NULL; #endif if (!use_savedir) md_normaluser(); @@ -93,9 +97,9 @@ open_log(void) { #ifdef LOGFILE - lfd = open(LOGFILE, O_WRONLY | O_APPEND | O_CREAT, 0666); + log_file = fopen(LOGFILE, "a"); #else - lfd = -1; + log_file = NULL; #endif return; } diff -r c222f9d56776 -r d3968e9cb98d rogue4/mdport.c --- a/rogue4/mdport.c Sun Sep 10 17:30:13 2017 -0400 +++ b/rogue4/mdport.c Fri Sep 15 19:57:54 2017 -0400 @@ -174,10 +174,10 @@ } int -md_unlink_open_file(char *file, int inf) +md_unlink_open_file(char *file, FILE *inf) { #ifdef _WIN32 - _close(inf); + fclose(inf); _chmod(file, 0600); return( _unlink(file) ); #else diff -r c222f9d56776 -r d3968e9cb98d rogue4/rip.c --- a/rogue4/rip.c Sun Sep 10 17:30:13 2017 -0400 +++ b/rogue4/rip.c Fri Sep 15 19:57:54 2017 -0400 @@ -49,7 +49,6 @@ register struct sc_ent *scp; register int i; register struct sc_ent *sc2; - register FILE *outf; register int prflags = 0; register void (*fp)(int); register int uid; @@ -72,11 +71,6 @@ start_score(); - if (fd >= 0) - outf = md_fdopen(fd, "wb"); - else - return; - for (scp = top_ten; scp <= &top_ten[9]; scp++) { scp->sc_score = 0; @@ -112,9 +106,9 @@ #endif 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'; - encread((char *) scoreline, 100, fd); + encread((char *) scoreline, 100, score_file); 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_level); @@ -209,7 +203,7 @@ else break; } - fseek(outf, 0L, 0); + fseek(score_file, 0L, 0); /* * Update the list file */ @@ -223,33 +217,28 @@ 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", top_ten[i].sc_flags, top_ten[i].sc_uid, top_ten[i].sc_monster, top_ten[i].sc_score, top_ten[i].sc_level); - encwrite((char *) scoreline, 100, outf); + encwrite((char *) scoreline, 100, score_file); } unlock_sc(); signal(SIGINT, fp); } } - fclose(outf); + fclose(score_file); } void writelog(int amount, int flags, char monst) { - FILE *logfi; char logmessage[220], ltemp[80]; char *killer; if (noscore) return; #ifdef LOGFILE - if (lfd >= 0) - logfi = md_fdopen(lfd, "a"); - else - return; - if (logfi == NULL) + if (log_file == NULL) return; /* otherwise writing should work */ sprintf(logmessage, "%d %d %s %d ", time(NULL), amount, whoami, @@ -283,13 +272,13 @@ } else { - fclose(logfi); + fclose(log_file); return; } /* then write */ - fprintf(logfi, "%s", logmessage); - fclose(logfi); + fprintf(log_file, "%s", logmessage); + fclose(log_file); #endif return; } diff -r c222f9d56776 -r d3968e9cb98d rogue4/rogue.h --- a/rogue4/rogue.h Sun Sep 10 17:30:13 2017 -0400 +++ b/rogue4/rogue.h Fri Sep 15 19:57:54 2017 -0400 @@ -514,7 +514,7 @@ void drop(void); bool dropcheck(THING *op); 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 end_line(void); void endmsg(void); diff -r c222f9d56776 -r d3968e9cb98d rogue4/save.c --- a/rogue4/save.c Sun Sep 10 17:30:13 2017 -0400 +++ b/rogue4/save.c Fri Sep 15 19:57:54 2017 -0400 @@ -23,7 +23,7 @@ void 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; @@ -165,9 +165,9 @@ /* * close any open score file */ - if (fd >= 0) { - close(fd); - fd = -1; + if (score_file != NULL) { + fclose(score_file); + score_file = NULL; } move(LINES-1, 0); refresh(); @@ -197,7 +197,7 @@ bool restore(char *file, char **envp) { - register int inf; + FILE *inf; register bool syml; extern char **environ; char buf[MAXSTR]; @@ -214,7 +214,7 @@ signal(SIGTSTP, SIG_IGN); #endif - if ((inf = open(file, 0)) < 0) + if ((inf = fopen(file, "r")) == NULL) { if (use_savedir && errno == ENOENT) { @@ -234,7 +234,7 @@ return FALSE; } - fstat(inf, &sbuf2); + stat(file, &sbuf2); fflush(stdout); syml = issymlink(file); @@ -348,13 +348,13 @@ * Perform an encrypted read */ int -encread(void *starta, int size, int inf) +encread(void *starta, int size, FILE *inf) { register char *ep; register int read_size; 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; ep = encstr; diff -r c222f9d56776 -r d3968e9cb98d rogue4/state.c --- a/rogue4/state.c Sun Sep 10 17:30:13 2017 -0400 +++ b/rogue4/state.c Fri Sep 15 19:57:54 2017 -0400 @@ -71,7 +71,7 @@ #define WRITESTAT (write_error == 0) 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 write_error = FALSE; @@ -421,7 +421,7 @@ } int -rs_read(int inf, void *ptr, int size) +rs_read(FILE *inf, void *ptr, int size) { int actual; @@ -451,14 +451,14 @@ } int -rs_read_char(int inf, char *c) +rs_read_char(FILE *inf, char *c) { rs_read(inf, c, 1); return(READSTAT); } int -rs_read_uchar(int inf, unsigned char *c) +rs_read_uchar(FILE *inf, unsigned char *c) { rs_read(inf, c, 1); @@ -466,7 +466,7 @@ } int -rs_read_boolean(int inf, bool *i) +rs_read_boolean(FILE *inf, bool *i) { unsigned char buf; @@ -478,7 +478,7 @@ } int -rs_read_booleans(int inf, bool *i, int count) +rs_read_booleans(FILE *inf, bool *i, int count) { int n = 0, value = 0; @@ -500,7 +500,7 @@ } int -rs_read_shint(int inf, shint *i) +rs_read_shint(FILE *inf, shint *i) { unsigned char buf; @@ -512,7 +512,7 @@ } int -rs_read_short(int inf, short *i) +rs_read_short(FILE *inf, short *i) { unsigned char bytes[2]; short input; @@ -533,7 +533,7 @@ } int -rs_read_shorts(int inf, short *i, int count) +rs_read_shorts(FILE *inf, short *i, int count) { int n = 0, value = 0; @@ -552,7 +552,7 @@ } int -rs_read_ushort(int inf, unsigned short *i) +rs_read_ushort(FILE *inf, unsigned short *i) { unsigned char bytes[2]; unsigned short input; @@ -573,7 +573,7 @@ } int -rs_read_int(int inf, int *i) +rs_read_int(FILE *inf, int *i) { unsigned char bytes[4]; int input; @@ -596,7 +596,7 @@ } int -rs_read_ints(int inf, int *i, int count) +rs_read_ints(FILE *inf, int *i, int count) { int n = 0, value = 0; @@ -615,7 +615,7 @@ } int -rs_read_uint(int inf, unsigned int *i) +rs_read_uint(FILE *inf, unsigned int *i) { unsigned char bytes[4]; int input; @@ -638,7 +638,7 @@ } int -rs_read_long(int inf, long *i) +rs_read_long(FILE *inf, long *i) { unsigned char bytes[4]; long input; @@ -661,7 +661,7 @@ } int -rs_read_longs(int inf, long *i, int count) +rs_read_longs(FILE *inf, long *i, int count) { int n = 0, value = 0; @@ -680,7 +680,7 @@ } int -rs_read_ulong(int inf, unsigned long *i) +rs_read_ulong(FILE *inf, unsigned long *i) { unsigned char bytes[4]; unsigned long input; @@ -703,7 +703,7 @@ } 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; @@ -722,7 +722,7 @@ } int -rs_read_string(int inf, char *s, int max) +rs_read_string(FILE *inf, char *s, int max) { int len = 0; @@ -742,7 +742,7 @@ } int -rs_read_new_string(int inf, char **s) +rs_read_new_string(FILE *inf, char **s) { int len=0; char *buf=0; @@ -769,7 +769,7 @@ } 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) { int i; @@ -792,7 +792,7 @@ } 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 value = 0; @@ -819,7 +819,7 @@ } 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 n = 0; @@ -863,7 +863,7 @@ } int -rs_read_str_t(int inf, str_t *st) +rs_read_str_t(FILE *inf, str_t *st) { rs_read_uint(inf,st); @@ -880,7 +880,7 @@ } 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->y); @@ -907,7 +907,7 @@ } int -rs_read_window(int inf, WINDOW *win) +rs_read_window(FILE *inf, WINDOW *win) { int id,row,col,maxlines,maxcols,value,width,height; @@ -987,7 +987,7 @@ } 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 func = 0; @@ -1083,7 +1083,7 @@ } 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 n; @@ -1161,7 +1161,7 @@ } 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_max); @@ -1186,7 +1186,7 @@ } 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; @@ -1222,7 +1222,7 @@ } int -rs_read_room_reference(int inf, struct room **rp) +rs_read_room_reference(FILE *inf, struct room **rp) { int i; @@ -1252,7 +1252,7 @@ } int -rs_read_stats(int inf, struct stats *s) +rs_read_stats(FILE *inf, struct stats *s) { int id; @@ -1290,7 +1290,7 @@ } int -rs_read_object(int inf, THING *o) +rs_read_object(FILE *inf, THING *o) { int id; @@ -1339,7 +1339,7 @@ } int -rs_read_object_list(int inf, THING **list) +rs_read_object_list(FILE *inf, THING **list) { int id; int i, cnt; @@ -1390,7 +1390,7 @@ } int -rs_read_object_reference(int inf, THING *list, THING **item) +rs_read_object_reference(FILE *inf, THING *list, THING **item) { int i; @@ -1566,7 +1566,7 @@ } int -rs_read_thing(int inf, THING *t) +rs_read_thing(FILE *inf, THING *t) { int id; int listid = 0, index = -1; @@ -1666,7 +1666,7 @@ } int -rs_read_thing_list(int inf, THING **list) +rs_read_thing_list(FILE *inf, THING **list) { int id; int i, cnt; @@ -1730,7 +1730,7 @@ } 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; @@ -1774,11 +1774,11 @@ rs_write_string(savef,s_guess[i]); } - return(READSTAT); + return(WRITESTAT); } int -rs_read_scrolls(int inf) +rs_read_scrolls(FILE *inf) { int i; @@ -1808,7 +1808,7 @@ } int -rs_read_potions(int inf) +rs_read_potions(FILE *inf) { int i; @@ -1843,7 +1843,7 @@ } int -rs_read_rings(int inf) +rs_read_rings(FILE *inf) { int i; const char *stones_list[NSTONES]; @@ -1886,7 +1886,7 @@ } int -rs_read_sticks(int inf) +rs_read_sticks(FILE *inf) { int i = 0, list = 0; @@ -1931,7 +1931,7 @@ } int -rs_read_thing_reference(int inf, THING *list, THING **item) +rs_read_thing_reference(FILE *inf, THING *list, THING **item) { int i; @@ -1961,7 +1961,7 @@ } 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; @@ -2076,7 +2076,7 @@ } int -rs_restore_file(int inf) +rs_restore_file(FILE *inf) { bool junk; THING *mitem; diff -r c222f9d56776 -r d3968e9cb98d srogue/global.c --- a/srogue/global.c Sun Sep 10 17:30:13 2017 -0400 +++ b/srogue/global.c Fri Sep 15 19:57:54 2017 -0400 @@ -54,7 +54,6 @@ int hungry_state = F_OKAY; /* How hungry is he */ int foodlev = 1; /* how fast he eats food */ int ringfood = 0; /* rings affect on food consumption */ -int scorefd = -1; /* Scoreboard file descriptor */ char take; /* Thing the rogue is taking */ char runch; /* Direction player is running */ char curpurch[15]; /* name of item ready to buy */ @@ -102,6 +101,7 @@ char callit[] = { "Call it: " }; char starlist[] = { " (* for a list)" }; +FILE *scoreboard = NULL; /* Scoreboard file */ FILE *logfile = NULL; struct coord oldpos; /* Pos before last look() call */ diff -r c222f9d56776 -r d3968e9cb98d srogue/main.c --- a/srogue/main.c Sun Sep 10 17:30:13 2017 -0400 +++ b/srogue/main.c Fri Sep 15 19:57:54 2017 -0400 @@ -21,6 +21,7 @@ #include #include #include +#include #include #include "rogue.h" @@ -37,7 +38,7 @@ char *roguehome(void); void open_records(void); -extern int scorefd; +extern FILE *scoreboard; extern FILE *logfile; int @@ -480,8 +481,11 @@ void open_records(void) { - if (scorefd < 0) - scorefd = open(scorefile, O_RDWR | O_CREAT, 0666); + if (scoreboard == NULL) + scoreboard = fopen(scorefile, "r+"); + if (scoreboard == NULL && errno == ENOENT) { + scoreboard = fopen(scorefile, "w+"); + } #ifdef LOGFILE if (logfile == NULL) logfile = fopen(LOGFILE, "a"); diff -r c222f9d56776 -r d3968e9cb98d srogue/rip.c --- a/srogue/rip.c Sun Sep 10 17:30:13 2017 -0400 +++ b/srogue/rip.c Fri Sep 15 19:57:54 2017 -0400 @@ -47,7 +47,7 @@ #define RIP_LINES (sizeof rip / (sizeof (char *))) -extern int scorefd; +extern FILE *scoreboard; extern FILE *logfile; char *killname(unsigned char monst); @@ -123,8 +123,7 @@ score(int amount, int aflag, char monst) { reg struct sc_ent *scp, *sc2; - reg int i, fd, prflags = 0; - reg FILE *outf; + reg int i, prflags = 0; char *packend; md_onsignal_exit(); @@ -142,9 +141,8 @@ /* * Open file and read list */ - if ((fd = scorefd) < 0) + if (scoreboard == NULL) return; - outf = (FILE *) md_fdopen(fd, "w"); for (scp = top_ten; scp <= &top_ten[9]; scp++) { scp->sc_score = 0; for (i = 0; i < 80; i++) @@ -165,8 +163,8 @@ { unsigned int mon; - encread((char *) &top_ten[i].sc_name, LINLEN, fd); - encread((char *) scoreline, 100, fd); + encread((char *) &top_ten[i].sc_name, LINLEN, scoreboard); + encread((char *) scoreline, 100, scoreboard); 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_level, &top_ten[i].sc_uid, @@ -199,19 +197,19 @@ } } ignore(); - fseek(outf, 0L, 0); + fseek(scoreboard, 0L, 0); for(i = 0; i < 10; i++) { 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", top_ten[i].sc_score, top_ten[i].sc_flags, top_ten[i].sc_level, top_ten[i].sc_uid, top_ten[i].sc_monster, top_ten[i].sc_explvl, 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(); clear(); refresh(); @@ -263,18 +261,19 @@ bool showtop(int showname) { - reg int fd, i; + reg int i; char *killer; struct sc_ent *scp; + FILE *score_rdonly; - if ((fd = open(scorefile, O_RDONLY)) < 0) + if ((score_rdonly = fopen(scorefile, "r")) == NULL) return FALSE; for(i = 0; i < 10; i++) { unsigned int mon; - encread((char *) &top_ten[i].sc_name, LINLEN, fd); - encread((char *) scoreline, 100, fd); + encread((char *) &top_ten[i].sc_name, LINLEN, score_rdonly); + encread((char *) scoreline, 100, score_rdonly); 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_level, &top_ten[i].sc_uid, @@ -282,7 +281,7 @@ &top_ten[i].sc_exppts, &top_ten[i].sc_date); top_ten[i].sc_monster = mon; } - close(fd); + fclose(score_rdonly); printf("Top Ten Adventurers:\nRank\tScore\tName\n"); for (scp = top_ten; scp <= &top_ten[9]; scp++) { if (scp->sc_score > 0) { diff -r c222f9d56776 -r d3968e9cb98d srogue/rogue.ext --- a/srogue/rogue.ext Sun Sep 10 17:30:13 2017 -0400 +++ b/srogue/rogue.ext Fri Sep 15 19:57:54 2017 -0400 @@ -92,7 +92,7 @@ int drop(struct linked_list *item); bool dropcheck(struct object *op); 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 endit(int a); void endmsg(void); @@ -200,7 +200,7 @@ int roll(int number, int sides); void rollwand(int fromfuse); struct room *roomin(struct coord *cp); -int rs_restore_file(int inf); +int rs_restore_file(FILE *inf); int rs_save_file(FILE *savef); void runners(void); void runto(struct coord *runner, struct coord *spot); diff -r c222f9d56776 -r d3968e9cb98d srogue/save.c --- a/srogue/save.c Sun Sep 10 17:30:13 2017 -0400 +++ b/srogue/save.c Fri Sep 15 19:57:54 2017 -0400 @@ -191,7 +191,7 @@ bool restore(char *file, char **envp) { - register int inf, pid; + register int pid; int ret_status; #ifndef _AIX extern char **environ; @@ -199,11 +199,12 @@ #ifdef __DJGPP__ /* st_ino w/ DJGPP under WinXP broken */ _djstat_flags |= _STAT_INODE; /* so turn off computing it for now */ #endif + FILE *inf; char buf[LINLEN]; STAT sbuf2; int slines, scols; - if ((inf = open(file, O_RDONLY)) < 0) { + if ((inf = fopen(file, "r")) == NULL) { if (use_savedir && errno == ENOENT) return TRUE; else { @@ -219,7 +220,7 @@ return FALSE; } - fstat(inf, &sbuf2); + stat(file, &sbuf2); encread(&slines,sizeof(slines),inf); encread(&scols,sizeof(scols),inf); @@ -279,11 +280,11 @@ } #if defined(__CYGWIN__) || defined(__DJGPP__) - close(inf); + fclose(inf); #endif if (!wizard) { - if (md_unlink_open_file(file, md_fdopen(inf, "r")) < 0) + if (md_unlink_open_file(file, inf) < 0) { endwin(); printf("Cannot unlink file\n"); diff -r c222f9d56776 -r d3968e9cb98d srogue/state.c --- a/srogue/state.c Sun Sep 10 17:30:13 2017 -0400 +++ b/srogue/state.c Fri Sep 15 19:57:54 2017 -0400 @@ -70,7 +70,7 @@ #define READSTAT ((format_error == 0) && (read_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 read_error = FALSE; @@ -105,13 +105,13 @@ * perform an encrypted read */ int -encread(void *starta, unsigned int size, int inf) +encread(void *starta, unsigned int size, FILE *inf) { register char *ep; register int read_size; 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; ep = encstr; @@ -466,7 +466,7 @@ } int -rs_read(int inf, void *ptr, int size) +rs_read(FILE *inf, void *ptr, int size) { int actual; @@ -497,7 +497,7 @@ } int -rs_read_char(int inf, char *c) +rs_read_char(FILE *inf, char *c) { rs_read(inf, c, 1); @@ -505,7 +505,7 @@ } int -rs_read_boolean(int inf, bool *i) +rs_read_boolean(FILE *inf, bool *i) { unsigned char buf; @@ -517,7 +517,7 @@ } int -rs_read_booleans(int inf, bool *i, int count) +rs_read_booleans(FILE *inf, bool *i, int count) { int n = 0, value = 0; @@ -539,7 +539,7 @@ } int -rs_read_shint(int inf, unsigned char *i) +rs_read_shint(FILE *inf, unsigned char *i) { unsigned char buf; @@ -551,7 +551,7 @@ } int -rs_read_short(int inf, short *i) +rs_read_short(FILE *inf, short *i) { unsigned char bytes[2]; short input; @@ -572,7 +572,7 @@ } int -rs_read_shorts(int inf, short *i, int count) +rs_read_shorts(FILE *inf, short *i, int count) { int n = 0, value = 0; @@ -591,7 +591,7 @@ } int -rs_read_ushort(int inf, unsigned short *i) +rs_read_ushort(FILE *inf, unsigned short *i) { unsigned char bytes[2]; unsigned short input; @@ -612,7 +612,7 @@ } int -rs_read_int(int inf, int *i) +rs_read_int(FILE *inf, int *i) { unsigned char bytes[4]; int input; @@ -635,7 +635,7 @@ } int -rs_read_ints(int inf, int *i, int count) +rs_read_ints(FILE *inf, int *i, int count) { int n = 0, value = 0; @@ -654,7 +654,7 @@ } int -rs_read_uint(int inf, unsigned int *i) +rs_read_uint(FILE *inf, unsigned int *i) { unsigned char bytes[4]; int input; @@ -677,7 +677,7 @@ } int -rs_read_long(int inf, long *i) +rs_read_long(FILE *inf, long *i) { unsigned char bytes[4]; long input; @@ -700,7 +700,7 @@ } int -rs_read_longs(int inf, long *i, int count) +rs_read_longs(FILE *inf, long *i, int count) { int n = 0, value = 0; @@ -719,7 +719,7 @@ } int -rs_read_ulong(int inf, unsigned long *i) +rs_read_ulong(FILE *inf, unsigned long *i) { unsigned char bytes[4]; unsigned long input; @@ -742,7 +742,7 @@ } 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; @@ -761,7 +761,7 @@ } int -rs_read_string(int inf, char *s, int max) +rs_read_string(FILE *inf, char *s, int max) { int len = 0; @@ -781,7 +781,7 @@ } int -rs_read_new_string(int inf, char **s) +rs_read_new_string(FILE *inf, char **s) { int len=0; char *buf=0; @@ -808,7 +808,7 @@ } 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; @@ -830,7 +830,7 @@ } 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 n = 0; @@ -858,7 +858,7 @@ } 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 n = 0; @@ -903,7 +903,7 @@ } 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->y); @@ -930,7 +930,7 @@ } int -rs_read_window(int inf, WINDOW *win) +rs_read_window(FILE *inf, WINDOW *win) { int id,row,col,maxlines,maxcols,value,width,height; @@ -1024,7 +1024,7 @@ } 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 func = 0; @@ -1130,7 +1130,7 @@ } int -rs_read_room_reference(int inf, struct room **rp) +rs_read_room_reference(FILE *inf, struct room **rp) { int i; @@ -1173,7 +1173,7 @@ } 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; @@ -1220,7 +1220,7 @@ } 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->h_lev); @@ -1247,7 +1247,7 @@ } int