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:
parent
f8d1f422c8
commit
c661fd79d4
33 changed files with 426 additions and 439 deletions
31
srogue/rip.c
31
srogue/rip.c
|
|
@ -47,7 +47,7 @@ static char *rip[] = {
|
|||
|
||||
#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 @@ void
|
|||
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 @@ score(int amount, int aflag, char monst)
|
|||
/*
|
||||
* 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 @@ score(int amount, int aflag, char monst)
|
|||
{
|
||||
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 @@ score(int amount, int aflag, char monst)
|
|||
}
|
||||
}
|
||||
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 @@ void writelog(int amount, int aflag, char monst)
|
|||
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 @@ showtop(int showname)
|
|||
&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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue