MCPcopy Index your code
hub / github.com/NetHack/NetHack / open_srcfile

Function open_srcfile

util/sfctool.c:455–512  ·  view source on GitHub ↗

open srcfile for reading */

Source from the content-addressed store, hash-verified

453
454/* open srcfile for reading */
455static NHFILE *
456open_srcfile(const char *fnam, enum saveformats mystyle)
457{
458 int fd;
459 const char *fq_name;
460 NHFILE *nhfp = (NHFILE *) 0;
461
462 nhfp = new_nhfile();
463 if (nhfp) {
464 nhfp->mode = READING;
465 nhfp->structlevel = (mystyle == historical);
466 nhfp->fieldlevel = (mystyle > historical);
467 nhfp->ftype = NHF_SAVEFILE;
468 nhfp->fnidx = mystyle;
469 nhfp->fd = -1;
470 nhfp->addinfo =
471 (nhfp->fieldlevel && (mystyle = exportascii))
472 ? TRUE
473 : FALSE;
474 (void) snprintf(srclogfilenm, sizeof srclogfilenm, "srcfile.%s.log",
475 (mystyle == historical) ? "historical" : "exportascii");
476 }
477
478 fq_name = fqname(fnam, SAVEPREFIX, 0);
479 nh_uncompress(fq_name);
480 if (nhfp && nhfp->structlevel) {
481 fd = open(fq_name, O_RDONLY | O_BINARY, 0);
482 if (fd < 0) {
483 free_nhfile(nhfp);
484 fprintf(stderr,
485 "\nsfctool error - unable to open historical-style "
486 "source file %s.\n",
487 fnam);
488 nhfp = (NHFILE *) 0;
489 nh_compress(fq_name);
490 } else {
491 nhfp->fd = fd;
492#if defined(MSDOS)
493 setmode(nhfp->fd, O_BINARY);
494#endif
495 }
496 }
497 if (nhfp && nhfp->fieldlevel) {
498 /* char savenamebuf[BUFSZ]; */
499
500 nhfp->fpdef = fopen(fnam, RDBMODE);
501 if (!nhfp->fpdef) {
502 free_nhfile(nhfp);
503 fprintf(stderr,
504 "\nsfctool error - unable to open fieldlevel-style "
505 "source file %s.\n",
506 fnam);
507 nhfp = (NHFILE *) 0;
508 nh_compress(fq_name);
509 }
510 }
511 return nhfp;
512}

Callers 1

process_savefileFunction · 0.85

Calls 7

new_nhfileFunction · 0.85
fqnameFunction · 0.85
nh_uncompressFunction · 0.85
openFunction · 0.85
free_nhfileFunction · 0.85
fprintfFunction · 0.85
nh_compressFunction · 0.85

Tested by

no test coverage detected