topten: UPDATE_RECORD_IN_PLACE
'final_fpos' shouldn't have been moved to the 'g' struct. Even if a game went all the way through topten and was restarted as a new game that also went all the way through topten, 'final_fpos' would get a new value rather than being messed up by a stale old one.
This commit is contained in:
@@ -1153,10 +1153,6 @@ struct instance_globals {
|
|||||||
|
|
||||||
/* topten.c */
|
/* topten.c */
|
||||||
winid toptenwin;
|
winid toptenwin;
|
||||||
#ifdef UPDATE_RECORD_IN_PLACE
|
|
||||||
long final_fpos;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* trap.c */
|
/* trap.c */
|
||||||
int force_mintrap; /* mintrap() should take a flags argument, but for time
|
int force_mintrap; /* mintrap() should take a flags argument, but for time
|
||||||
|
|||||||
@@ -650,9 +650,6 @@ const struct instance_globals g_init = {
|
|||||||
|
|
||||||
/* topten.c */
|
/* topten.c */
|
||||||
WIN_ERR, /* topten */
|
WIN_ERR, /* topten */
|
||||||
#ifdef UPDATE_RECORD_IN_PLACE
|
|
||||||
UNDEFINED_VALUE, /* final_fpos */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* trap.c */
|
/* trap.c */
|
||||||
0, /* force_mintrap */
|
0, /* force_mintrap */
|
||||||
|
|||||||
+18
-12
@@ -6,13 +6,13 @@
|
|||||||
#include "hack.h"
|
#include "hack.h"
|
||||||
#include "dlb.h"
|
#include "dlb.h"
|
||||||
|
|
||||||
/* If UPDATE_RECORD_IN_PLACE is defined, we don't want to rewrite the
|
#if defined(VMS) && !defined(UPDATE_RECORD_IN_PLACE)
|
||||||
* whole file, because that entails creating a new version which
|
/* We don't want to rewrite the whole file, because that entails
|
||||||
* requires that the old one be deletable. UPDATE_RECORD_IN_PLACE
|
creating a new version which requires that the old one be deletable.
|
||||||
* had to be defined more centrally in 3.7 to ensure that the
|
[Write and Delete are separate permissions on VMS. 'record' should
|
||||||
* final_fpos field gets included in struct instance_globals aka 'g'.
|
be writable but not deletable there.] */
|
||||||
*/
|
#define UPDATE_RECORD_IN_PLACE
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Updating in place can leave junk at the end of the file in some
|
* Updating in place can leave junk at the end of the file in some
|
||||||
@@ -20,6 +20,9 @@
|
|||||||
* way to truncate it). The trailing junk is harmless and the code
|
* way to truncate it). The trailing junk is harmless and the code
|
||||||
* which reads the scores will ignore it.
|
* which reads the scores will ignore it.
|
||||||
*/
|
*/
|
||||||
|
#ifdef UPDATE_RECORD_IN_PLACE
|
||||||
|
static long final_fpos; /* [note: do not move this to the 'g' struct] */
|
||||||
|
#endif
|
||||||
|
|
||||||
#define done_stopprint g.program_state.stopprint
|
#define done_stopprint g.program_state.stopprint
|
||||||
|
|
||||||
@@ -145,7 +148,8 @@ formatkiller(
|
|||||||
|
|
||||||
if (incl_helpless && g.multi) {
|
if (incl_helpless && g.multi) {
|
||||||
/* X <= siz: 'sizeof "string"' includes 1 for '\0' terminator */
|
/* X <= siz: 'sizeof "string"' includes 1 for '\0' terminator */
|
||||||
if (g.multi_reason && strlen(g.multi_reason) + sizeof ", while " <= siz)
|
if (g.multi_reason
|
||||||
|
&& strlen(g.multi_reason) + sizeof ", while " <= siz)
|
||||||
Sprintf(buf, ", while %s", g.multi_reason);
|
Sprintf(buf, ", while %s", g.multi_reason);
|
||||||
/* either g.multi_reason wasn't specified or wouldn't fit */
|
/* either g.multi_reason wasn't specified or wouldn't fit */
|
||||||
else if (sizeof ", while helpless" <= siz)
|
else if (sizeof ", while helpless" <= siz)
|
||||||
@@ -227,7 +231,7 @@ readentry(FILE* rfile, struct toptenentry* tt)
|
|||||||
|
|
||||||
#ifdef UPDATE_RECORD_IN_PLACE
|
#ifdef UPDATE_RECORD_IN_PLACE
|
||||||
/* note: input below must read the record's terminating newline */
|
/* note: input below must read the record's terminating newline */
|
||||||
g.final_fpos = tt->fpos = ftell(rfile);
|
final_fpos = tt->fpos = ftell(rfile);
|
||||||
#endif
|
#endif
|
||||||
#define TTFIELDS 13
|
#define TTFIELDS 13
|
||||||
if (fscanf(rfile, fmt, &tt->ver_major, &tt->ver_minor, &tt->patchlevel,
|
if (fscanf(rfile, fmt, &tt->ver_major, &tt->ver_minor, &tt->patchlevel,
|
||||||
@@ -622,6 +626,9 @@ topten(int how, time_t when)
|
|||||||
int flg = 0;
|
int flg = 0;
|
||||||
boolean t0_used, skip_scores;
|
boolean t0_used, skip_scores;
|
||||||
|
|
||||||
|
#ifdef UPDATE_RECORD_IN_PLACE
|
||||||
|
final_fpos = 0L;
|
||||||
|
#endif
|
||||||
/* If we are in the midst of a panic, cut out topten entirely.
|
/* If we are in the midst of a panic, cut out topten entirely.
|
||||||
* topten uses alloc() several times, which will lead to
|
* topten uses alloc() several times, which will lead to
|
||||||
* problems if the panic was the result of an alloc() failure.
|
* problems if the panic was the result of an alloc() failure.
|
||||||
@@ -792,8 +799,7 @@ topten(int how, time_t when)
|
|||||||
}
|
}
|
||||||
if (flg) { /* rewrite record file */
|
if (flg) { /* rewrite record file */
|
||||||
#ifdef UPDATE_RECORD_IN_PLACE
|
#ifdef UPDATE_RECORD_IN_PLACE
|
||||||
(void) fseek(rfile, (t0->fpos >= 0 ? t0->fpos : g.final_fpos),
|
(void) fseek(rfile, (t0->fpos >= 0) ? t0->fpos : final_fpos, SEEK_SET);
|
||||||
SEEK_SET);
|
|
||||||
#else
|
#else
|
||||||
(void) fclose(rfile);
|
(void) fclose(rfile);
|
||||||
if (!(rfile = fopen_datafile(RECORD, "w", SCOREPREFIX))) {
|
if (!(rfile = fopen_datafile(RECORD, "w", SCOREPREFIX))) {
|
||||||
@@ -885,7 +891,7 @@ topten(int how, time_t when)
|
|||||||
|
|
||||||
showwin:
|
showwin:
|
||||||
if (iflags.toptenwin && !done_stopprint)
|
if (iflags.toptenwin && !done_stopprint)
|
||||||
display_nhwindow(g.toptenwin, 1);
|
display_nhwindow(g.toptenwin, TRUE);
|
||||||
destroywin:
|
destroywin:
|
||||||
if (!t0_used)
|
if (!t0_used)
|
||||||
dealloc_ttentry(t0);
|
dealloc_ttentry(t0);
|
||||||
|
|||||||
Reference in New Issue
Block a user