Advanced Rogue family: fix the "score" option.

Changing the score file (when permitted) now works again, closing the
old score file and opening the new one.
This commit is contained in:
John "Elwin" Edwards 2015-05-20 08:42:17 -04:00
parent ea4244de91
commit e3620a3781
14 changed files with 105 additions and 14 deletions

View file

@ -16,8 +16,6 @@
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <sys/types.h>
#include <fcntl.h>
#ifdef BSD
#include <sys/time.h>
#else
@ -33,8 +31,6 @@ extern struct uwdata wdata, oldwin;
extern char oldtext[WTXTNUM][WTXTLEN];
#endif
int scorefd = -1;
FILE *logfile = NULL;
void open_records(void);
main(argc, argv, envp)
@ -553,7 +549,7 @@ void
open_records(void)
{
if (scorefd == -1)
scorefd = open(score_file, O_RDWR | O_CREAT, 0666);
md_reopen_score();
#ifdef LOGFILE
if (logfile == NULL)
logfile = fopen(LOGFILE, "a");

View file

@ -677,6 +677,17 @@ md_flushinp()
#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

View file

@ -50,6 +50,7 @@ int put_bool(),
put_quest();
int get_str_prot(char *opt, WINDOW *win);
int get_score(char *opt, WINDOW *win);
bool allowchange(OPTION *op);
OPTION optlist[] = {
@ -72,7 +73,7 @@ OPTION optlist[] = {
{"file", "Save file: ",
(int *) file_name, put_str, get_str_prot },
{"score", "Score file: ",
(int *) score_file, put_str, get_str_prot },
(int *) score_file, put_str, get_score },
{"class", "Character class: ",
(int *)&char_type, put_abil, get_abil },
{"quest", "Quest item: ",
@ -486,6 +487,25 @@ get_str_prot(char *opt, WINDOW *win)
}
}
/* When getting the scorefile, the new file must be opened. */
int
get_score(char *optstr, WINDOW *win)
{
char old_score_file[LINELEN];
int status;
if (use_savedir)
return get_str_prot(optstr, win);
strcpy(old_score_file, optstr);
status = get_str(optstr, win);
if (status == NORM && strcmp(old_score_file, optstr))
{
md_reopen_score();
}
return status;
}
bool
allowchange(OPTION *op)
{

View file

@ -80,6 +80,7 @@ int pray_time = 0;
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 */
@ -133,6 +134,7 @@ bool askme = FALSE;
bool in_shell = FALSE;
bool daytime = TRUE;
bool use_savedir = FALSE;
FILE *logfile = NULL;
LEVTYPE levtype; /* type of level i'm on */
char *nothing = "Nothing seems to happen.";

View file

@ -1227,6 +1227,7 @@ extern int pray_time; /* Number of prayer points/exp level */
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 */
@ -1286,6 +1287,7 @@ extern char *nothing; /* "nothing happens" msg */
extern char *spacemsg;
extern char *morestr;
extern char *retstr;
extern FILE *logfile;
extern LEVTYPE levtype;
extern void (*add_abil[NUMABILITIES])(); /* Functions to change abilities */
extern void (*res_abil[NUMABILITIES])(); /* Functions to change abilities */