# HG changeset patch # User John "Elwin" Edwards # Date 1438456331 14400 # Node ID 78fa1d0e5d251eb3d3fc0de8d9fcb1bb60fd0c03 # Parent c199a15a2c70ca8c48e5d39388fd086956014b5a srogue: open the score and log files when the program starts. Super-Rogue can now use the same privilege-dropping scheme as the other games. diff -r c199a15a2c70 -r 78fa1d0e5d25 srogue/global.c --- a/srogue/global.c Thu Jul 23 19:28:12 2015 -0400 +++ b/srogue/global.c Sat Aug 01 15:12:11 2015 -0400 @@ -54,6 +54,7 @@ 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 */ @@ -101,6 +102,8 @@ char callit[] = { "Call it: " }; char starlist[] = { " (* for a list)" }; +FILE *logfile = NULL; + struct coord oldpos; /* Pos before last look() call */ struct coord delta; /* Change indicated to get_dir() */ struct coord stairs; /* where the stairs are put */ diff -r c199a15a2c70 -r 78fa1d0e5d25 srogue/main.c --- a/srogue/main.c Thu Jul 23 19:28:12 2015 -0400 +++ b/srogue/main.c Sat Aug 01 15:12:11 2015 -0400 @@ -34,6 +34,11 @@ #include "rogue.ext" +void open_records(void); + +extern int scorefd; +extern FILE *logfile; + main(argc, argv, envp) char **argv; char **envp; @@ -70,6 +75,7 @@ strcat(scorefile,"/"); strcat(scorefile, "srogue.scr"); #endif + open_records(); if(argc >= 2 && strcmp(argv[1], "-s") == 0) { @@ -472,3 +478,14 @@ return(NULL); } +void +open_records(void) +{ + if (scorefd < 0) + scorefd = open(scorefile, O_RDWR | O_CREAT, 0666); +#ifdef LOGFILE + if (logfile == NULL) + logfile = fopen(LOGFILE, "a"); +#endif +} + diff -r c199a15a2c70 -r 78fa1d0e5d25 srogue/rip.c --- a/srogue/rip.c Thu Jul 23 19:28:12 2015 -0400 +++ b/srogue/rip.c Sat Aug 01 15:12:11 2015 -0400 @@ -47,6 +47,9 @@ #define RIP_LINES (sizeof rip / (sizeof (char *))) +extern int scorefd; +extern FILE *logfile; + char *killname(); void writelog(int amount, int aflag, char monst); @@ -140,7 +143,7 @@ /* * Open file and read list */ - if ((fd = open(scorefile, O_RDWR | O_CREAT, 0666)) < 0) + if ((fd = scorefd) < 0) return; outf = (FILE *) fdopen(fd, "w"); for (scp = top_ten; scp <= &top_ten[9]; scp++) { @@ -221,11 +224,12 @@ { char logmessage[220], ltemp[80], mlev[40]; char *killer; - FILE *logfi; if (waswizard) return; #ifdef LOGFILE + if (logfile == NULL) + return; sprintf(logmessage, "%d %d %s %d ", time(NULL), amount, whoami, him->s_lvl); if (amulet) @@ -247,11 +251,8 @@ else return; strcat(logmessage, ltemp); - logfi = fopen(LOGFILE, "a"); - if (logfi == NULL) - return; - fprintf(logfi, "%s", logmessage); - fclose(logfi); + fprintf(logfile, "%s", logmessage); + fclose(logfile); #endif return; }