comparison 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
comparison
equal deleted inserted replaced
278:c222f9d56776 279:d3968e9cb98d
33 33
34 /* 34 /*
35 * If you change this structure, change the compatibility routines 35 * If you change this structure, change the compatibility routines
36 * scoreout() and scorein() to reflect the change. Also update SCORELEN. 36 * scoreout() and scorein() to reflect the change. Also update SCORELEN.
37 */ 37 */
38
39 extern int scorefd;
40 extern FILE *logfile;
41 38
42 struct sc_ent { 39 struct sc_ent {
43 unsigned long sc_score; 40 unsigned long sc_score;
44 char sc_name[LINELEN]; 41 char sc_name[LINELEN];
45 char sc_system[SYSLEN]; 42 char sc_system[SYSLEN];
70 " ________)/\\\\_//(\\/(/\\)/\\//\\/|_)_______", 67 " ________)/\\\\_//(\\/(/\\)/\\//\\/|_)_______",
71 0 68 0
72 }; 69 };
73 70
74 char *killname(short monst); 71 char *killname(short monst);
75 void scorein(struct sc_ent scores[], int fd); 72 void scorein(struct sc_ent scores[], FILE *inf);
76 void scoreout(struct sc_ent scores[], FILE *outf); 73 void scoreout(struct sc_ent scores[], FILE *outf);
77 void showpack(char *howso); 74 void showpack(char *howso);
78 int update(struct sc_ent top_ten[], unsigned long amount, short quest, 75 int update(struct sc_ent top_ten[], unsigned long amount, short quest,
79 char *whoami, short flags, short level, short monst, short ctype, 76 char *whoami, short flags, short level, short monst, short ctype,
80 char *system, char *login); 77 char *system, char *login);
168 { 165 {
169 static struct sc_ent top_ten[NUMSCORE]; 166 static struct sc_ent top_ten[NUMSCORE];
170 register struct sc_ent *scp; 167 register struct sc_ent *scp;
171 register int i; 168 register int i;
172 register struct sc_ent *sc2; 169 register struct sc_ent *sc2;
173 register FILE *outf;
174 register char *killer; 170 register char *killer;
175 register int prflags = 0; 171 register int prflags = 0;
176 register int fd;
177 short upquest = 0, wintype = 0, uplevel = 0, uptype = 0; /* For network updating */ 172 short upquest = 0, wintype = 0, uplevel = 0, uptype = 0; /* For network updating */
178 char upsystem[SYSLEN], uplogin[LOGLEN]; 173 char upsystem[SYSLEN], uplogin[LOGLEN];
179 char *thissys; /* Holds the name of this system */ 174 char *thissys; /* Holds the name of this system */
180 char *compatstr=NULL; /* Holds scores for writing compatible score files */ 175 char *compatstr=NULL; /* Holds scores for writing compatible score files */
181 #define REASONLEN 3 176 #define REASONLEN 3
202 197
203 /* 198 /*
204 * Open file and read list 199 * Open file and read list
205 */ 200 */
206 201
207 if ((fd = scorefd) < 0) 202 if (scoreboard == NULL)
208 { 203 {
209 printf("\nCannot open score_file.\n"); 204 printf("\nCannot open score_file.\n");
210 return; 205 return;
211 } 206 }
212 outf = (FILE *) md_fdopen(fd, "w");
213 207
214 /* Get this system's name */ 208 /* Get this system's name */
215 thissys = md_gethostname(); 209 thissys = md_gethostname();
216 210
217 for (scp = top_ten; scp <= &top_ten[NUMSCORE-1]; scp++) 211 for (scp = top_ten; scp <= &top_ten[NUMSCORE-1]; scp++)
255 } 249 }
256 } 250 }
257 #endif 251 #endif
258 252
259 /* Read the score and convert it to a compatible format */ 253 /* Read the score and convert it to a compatible format */
260 scorein(top_ten, fd); /* Convert it */ 254 scorein(top_ten, scoreboard); /* Convert it */
261 255
262 /* Get some values if this is an update */ 256 /* Get some values if this is an update */
263 if (flags == UPDATE) { 257 if (flags == UPDATE) {
264 int errcheck, errors = 0; 258 int errcheck, errors = 0;
265 259
281 errors++; 275 errors++;
282 if (fread(uplogin, 1, LOGLEN, stdin) != LOGLEN) 276 if (fread(uplogin, 1, LOGLEN, stdin) != LOGLEN)
283 errors++; 277 errors++;
284 278
285 if (errors) { 279 if (errors) {
286 fclose(outf); 280 fclose(scoreboard);
287 free(compatstr); 281 free(compatstr);
288 return; 282 return;
289 } 283 }
290 } 284 }
291 285
473 #endif 467 #endif
474 } 468 }
475 } 469 }
476 } 470 }
477 471
478 fseek(outf, 0L, 0); 472 fseek(scoreboard, 0L, 0);
479 /* 473 /*
480 * Update the list file 474 * Update the list file
481 */ 475 */
482 scoreout(top_ten, outf); 476 scoreout(top_ten, scoreboard);
483 fclose(outf); 477 fclose(scoreboard);
484 478
485 /* 479 /*
486 * SCOREIT -- rogue -s option. Never started curses if this option. 480 * SCOREIT -- rogue -s option. Never started curses if this option.
487 * UPDATE -- network scoring update. Never started curses if this option. 481 * UPDATE -- network scoring update. Never started curses if this option.
488 * EDITSCORE -- want to delete or change a score. 482 * EDITSCORE -- want to delete or change a score.
625 * scorein: 619 * scorein:
626 * Convert a character string that has been translated from a 620 * Convert a character string that has been translated from a
627 * score file by scoreout() back to a score file structure. 621 * score file by scoreout() back to a score file structure.
628 */ 622 */
629 void 623 void
630 scorein(struct sc_ent scores[], int fd) 624 scorein(struct sc_ent scores[], FILE *inf)
631 { 625 {
632 int i; 626 int i;
633 char scoreline[100]; 627 char scoreline[100];
634 628
635 for(i = 0; i < NUMSCORE; i++) 629 for(i = 0; i < NUMSCORE; i++)
636 { 630 {
637 encread((char *) &scores[i].sc_name, LINELEN, fd); 631 encread((char *) &scores[i].sc_name, LINELEN, inf);
638 encread((char *) &scores[i].sc_system, SYSLEN, fd); 632 encread((char *) &scores[i].sc_system, SYSLEN, inf);
639 encread((char *) &scores[i].sc_login, LINELEN, fd); 633 encread((char *) &scores[i].sc_login, LINELEN, inf);
640 encread((char *) scoreline, 100, fd); 634 encread((char *) scoreline, 100, inf);
641 sscanf(scoreline, " %lu %d %d %d %d %d \n", 635 sscanf(scoreline, " %lu %d %d %d %d %d \n",
642 &scores[i].sc_score, &scores[i].sc_flgs, 636 &scores[i].sc_score, &scores[i].sc_flgs,
643 &scores[i].sc_level, &scores[i].sc_ctype, 637 &scores[i].sc_level, &scores[i].sc_ctype,
644 &scores[i].sc_monster, &scores[i].sc_quest); 638 &scores[i].sc_monster, &scores[i].sc_quest);
645 } 639 }