MCPcopy Create free account
hub / github.com/NetHack/NetHack / do_dungeon

Function do_dungeon

util/makedefs.c:2055–2104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2053 */
2054
2055void
2056do_dungeon(void)
2057{
2058 char *line, greptmp[8 + 1 + 3 + 1];
2059
2060 Sprintf(greptmp, "grep-%.3s.tmp", "dun");
2061 Sprintf(filename, DATA_IN_TEMPLATE, DGN_I_FILE);
2062 if (!(ifp = fopen(filename, RDTMODE))) {
2063 perror(filename);
2064 makedefs_exit(EXIT_FAILURE);
2065 /*NOTREACHED*/
2066 }
2067 filename[0] = '\0';
2068#ifdef FILE_PREFIX
2069 Strcat(filename, file_prefix);
2070#endif
2071 Sprintf(eos(filename), DGN_TEMPLATE, DGN_O_FILE);
2072 if (!(ofp = fopen(filename, WRTMODE))) {
2073 perror(filename);
2074 makedefs_exit(EXIT_FAILURE);
2075 /*NOTREACHED*/
2076 }
2077 Fprintf(ofp, "%s", Dont_Edit_Data);
2078
2079 tfp = getfp(DATA_TEMPLATE, greptmp, WRTMODE, FLG_TEMPFILE);
2080 grep0(ifp, tfp, FLG_TEMPFILE);
2081#ifndef HAS_NO_MKSTEMP
2082 ifp = tfp;
2083#else
2084 ifp = getfp(DATA_TEMPLATE, greptmp, RDTMODE, 0);
2085#endif
2086 set_fgetline_context(NULL, FALSE, TRUE);
2087 while ((line = fgetline(ifp)) != 0) {
2088 SpinCursor(3);
2089
2090 if (line[0] == '#') {
2091 free((genericptr_t) line);
2092 continue; /* discard comments */
2093 }
2094 (void) fputs(line, ofp);
2095 free((genericptr_t) line);
2096 }
2097 Fclose(ifp);
2098 Fclose(ofp);
2099
2100#ifdef HAS_NO_MKSTEMP
2101 delete_file(DATA_TEMPLATE, greptmp);
2102#endif
2103 return;
2104}
2105
2106/* obsolete */
2107void

Callers 1

do_makedefsFunction · 0.85

Calls 7

makedefs_exitFunction · 0.85
eosFunction · 0.85
getfpFunction · 0.85
grep0Function · 0.85
set_fgetline_contextFunction · 0.85
delete_fileFunction · 0.85
fgetlineFunction · 0.70

Tested by

no test coverage detected