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

Function do_data

util/makedefs.c:1245–1368  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1243}
1244
1245RESTORE_WARNING_FORMAT_NONLITERAL
1246void
1247do_data(void)
1248{
1249 char infile[60], tempfile[60];
1250 boolean ok;
1251 long txt_offset;
1252 int entry_cnt, line_cnt;
1253 char *line;
1254
1255 Sprintf(tempfile, DATA_TEMPLATE, "database.tmp");
1256 filename[0] = '\0';
1257#ifdef FILE_PREFIX
1258 Strcat(filename, file_prefix);
1259#endif
1260 Sprintf(eos(filename), DATA_TEMPLATE, DATA_FILE);
1261 Sprintf(infile, DATA_IN_TEMPLATE, DATA_FILE);
1262#ifdef SHORT_FILENAMES
1263 Strcat(infile, ".bas");
1264#else
1265 Strcat(infile, ".base");
1266#endif
1267 if (!(ifp = fopen(infile, RDTMODE))) { /* data.base */
1268 perror(infile);
1269 makedefs_exit(EXIT_FAILURE);
1270 /*NOTREACHED*/
1271 }
1272 if (!(ofp = fopen(filename, WRTMODE))) { /* data */
1273 perror(filename);
1274 Fclose(ifp);
1275 makedefs_exit(EXIT_FAILURE);
1276 /*NOTREACHED*/
1277 }
1278 if (!(tfp = fopen(tempfile, WRTMODE))) { /* database.tmp */
1279 perror(tempfile);
1280 Fclose(ifp);
1281 Fclose(ofp);
1282 Unlink(filename);
1283 makedefs_exit(EXIT_FAILURE);
1284 /*NOTREACHED*/
1285 }
1286
1287 /* output a dummy header record; we'll rewind and overwrite it later */
1288 Fprintf(ofp, "%s%08lx\n", Dont_Edit_Data, 0L);
1289
1290 entry_cnt = line_cnt = 0;
1291 set_fgetline_context(infile, TRUE, TRUE);
1292 /* read through the input file and split it into two sections */
1293 while ((line = fgetline(ifp)) != 0) {
1294 if (d_filter(line)) {
1295 free((genericptr_t) line);
1296 continue;
1297 }
1298 if (*line > ' ') { /* got an entry name */
1299 /* first finish previous entry */
1300 if (line_cnt)
1301 Fprintf(ofp, "%d\n", line_cnt), line_cnt = 0;
1302 /* output the entry name */

Callers 1

do_makedefsFunction · 0.85

Calls 8

eosFunction · 0.85
makedefs_exitFunction · 0.85
set_fgetline_contextFunction · 0.85
d_filterFunction · 0.85
ftellFunction · 0.85
fprintfFunction · 0.85
fgetlineFunction · 0.70
allocFunction · 0.50

Tested by

no test coverage detected