diff arogue5/rip.c @ 279:d3968e9cb98d

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.
author John "Elwin" Edwards
date Fri, 15 Sep 2017 19:57:54 -0400
parents 56e748983fa8
children 0250220d8cdd
line wrap: on
line diff
--- 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,