Mercurial > hg > early-roguelike
comparison arogue7/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 | f9ef86cf22b2 |
children | 0250220d8cdd |
comparison
equal
deleted
inserted
replaced
278:c222f9d56776 | 279:d3968e9cb98d |
---|---|
43 #ifdef PC7300 | 43 #ifdef PC7300 |
44 #include "sys/window.h" | 44 #include "sys/window.h" |
45 extern struct uwdata wdata, oldwin; | 45 extern struct uwdata wdata, oldwin; |
46 extern char oldtext[WTXTNUM][WTXTLEN]; | 46 extern char oldtext[WTXTNUM][WTXTLEN]; |
47 #endif | 47 #endif |
48 | |
49 extern int scorefd; | |
50 extern FILE *logfile; | |
51 | 48 |
52 #ifdef NUMNET | 49 #ifdef NUMNET |
53 /* Network machines (for mutual score keeping) */ | 50 /* Network machines (for mutual score keeping) */ |
54 static struct network Network[NUMNET] = { | 51 static struct network Network[NUMNET] = { |
55 { "ihwpt", "/t1/michael/bin/rg" }, | 52 { "ihwpt", "/t1/michael/bin/rg" }, |
254 { | 251 { |
255 static struct sc_ent top_ten[NUMSCORE]; | 252 static struct sc_ent top_ten[NUMSCORE]; |
256 register struct sc_ent *scp; | 253 register struct sc_ent *scp; |
257 register int i; | 254 register int i; |
258 register struct sc_ent *sc2; | 255 register struct sc_ent *sc2; |
259 register int outfd; | |
260 register char *killer; | 256 register char *killer; |
261 register int prflags = 0; | 257 register int prflags = 0; |
262 register int fd; | |
263 short upquest, wintype, uplevel, uptype; /* For network updating */ | 258 short upquest, wintype, uplevel, uptype; /* For network updating */ |
264 char upsystem[SYSLEN], uplogin[LOGLEN]; | 259 char upsystem[SYSLEN], uplogin[LOGLEN]; |
265 char *thissys; /* Holds the name of this system */ | 260 char *thissys; /* Holds the name of this system */ |
266 char *compatstr=NULL; /* Holds scores for writing compatible score files */ | 261 char *compatstr=NULL; /* Holds scores for writing compatible score files */ |
267 char scoreline[100]; | 262 char scoreline[100]; |
288 showpack(packend); | 283 showpack(packend); |
289 } | 284 } |
290 purse = 0; /* Steal all the gold */ | 285 purse = 0; /* Steal all the gold */ |
291 | 286 |
292 /* | 287 /* |
293 * Open file and read list | 288 * Read list |
294 */ | 289 */ |
295 | 290 |
296 if ((fd = scorefd) < 0) return; | 291 if (scoreboard == NULL) return; |
297 outfd = fd; | |
298 | 292 |
299 #ifndef SYSTEM | 293 #ifndef SYSTEM |
300 thissys = md_gethostname(); | 294 thissys = md_gethostname(); |
301 #else | 295 #else |
302 thissys = SYSTEM; | 296 thissys = SYSTEM; |
345 #endif | 339 #endif |
346 | 340 |
347 /* Read the score and convert it to a compatible format */ | 341 /* Read the score and convert it to a compatible format */ |
348 for(i = 0; i < NUMSCORE; i++) | 342 for(i = 0; i < NUMSCORE; i++) |
349 { | 343 { |
350 encread(top_ten[i].sc_name, NAMELEN, fd); | 344 encread(top_ten[i].sc_name, NAMELEN, scoreboard); |
351 encread(top_ten[i].sc_system, SYSLEN, fd); | 345 encread(top_ten[i].sc_system, SYSLEN, scoreboard); |
352 encread(top_ten[i].sc_login, LOGLEN, fd); | 346 encread(top_ten[i].sc_login, LOGLEN, scoreboard); |
353 encread(scoreline, 100, fd); | 347 encread(scoreline, 100, scoreboard); |
354 sscanf(scoreline, " %lu %hd %hd %hd %hd %hd \n", | 348 sscanf(scoreline, " %lu %hd %hd %hd %hd %hd \n", |
355 &top_ten[i].sc_score, &top_ten[i].sc_flags, | 349 &top_ten[i].sc_score, &top_ten[i].sc_flags, |
356 &top_ten[i].sc_level, &top_ten[i].sc_ctype, | 350 &top_ten[i].sc_level, &top_ten[i].sc_ctype, |
357 &top_ten[i].sc_monster, &top_ten[i].sc_quest | 351 &top_ten[i].sc_monster, &top_ten[i].sc_quest |
358 ); | 352 ); |
381 errors++; | 375 errors++; |
382 if (fread(uplogin, 1, LOGLEN, stdin) != LOGLEN) | 376 if (fread(uplogin, 1, LOGLEN, stdin) != LOGLEN) |
383 errors++; | 377 errors++; |
384 | 378 |
385 if (errors) { | 379 if (errors) { |
386 close(outfd); | 380 fclose(scoreboard); |
387 free(compatstr); | 381 free(compatstr); |
388 return; | 382 return; |
389 } | 383 } |
390 } | 384 } |
391 | 385 |
644 fflush(stdout); | 638 fflush(stdout); |
645 fgets(prbuf,80,stdin); | 639 fgets(prbuf,80,stdin); |
646 } | 640 } |
647 /* if (prflags == EDITSCORE) endwin();*/ /* End editing windowing */ | 641 /* if (prflags == EDITSCORE) endwin();*/ /* End editing windowing */ |
648 } | 642 } |
649 lseek(outfd, 0L, 0); | 643 fseek(scoreboard, 0L, SEEK_SET); |
650 /* | 644 /* |
651 * Update the list file | 645 * Update the list file |
652 */ | 646 */ |
653 | 647 |
654 for(i = 0; i < NUMSCORE; i++) | 648 for(i = 0; i < NUMSCORE; i++) |
655 { | 649 { |
656 memset(scoreline,0,100); | 650 memset(scoreline,0,100); |
657 encwrite(top_ten[i].sc_name, NAMELEN, outfd); | 651 encwrite(top_ten[i].sc_name, NAMELEN, scoreboard); |
658 encwrite(top_ten[i].sc_system, SYSLEN, outfd); | 652 encwrite(top_ten[i].sc_system, SYSLEN, scoreboard); |
659 encwrite(top_ten[i].sc_login, LOGLEN, outfd); | 653 encwrite(top_ten[i].sc_login, LOGLEN, scoreboard); |
660 sprintf(scoreline, " %lu %hd %hd %hd %hd %hd \n", | 654 sprintf(scoreline, " %lu %hd %hd %hd %hd %hd \n", |
661 top_ten[i].sc_score, top_ten[i].sc_flags, | 655 top_ten[i].sc_score, top_ten[i].sc_flags, |
662 top_ten[i].sc_level, top_ten[i].sc_ctype, | 656 top_ten[i].sc_level, top_ten[i].sc_ctype, |
663 top_ten[i].sc_monster, top_ten[i].sc_quest); | 657 top_ten[i].sc_monster, top_ten[i].sc_quest); |
664 encwrite(scoreline,100,outfd); | 658 encwrite(scoreline,100,scoreboard); |
665 } | 659 } |
666 | 660 |
667 close(outfd); | 661 fclose(scoreboard); |
668 } | 662 } |
669 | 663 |
670 /* | 664 /* |
671 * scorein: | 665 * scorein: |
672 * Convert a character string that has been translated from a | 666 * Convert a character string that has been translated from a |