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

Function do_rumors

util/makedefs.c:1143–1243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1141}
1142
1143DISABLE_WARNING_FORMAT_NONLITERAL
1144
1145void
1146do_rumors(void)
1147{
1148 char *line;
1149 static const char rumors_header[] =
1150 "%s%04d,%06ld,%06lx;%04d,%06ld,%06lx;0,0,%06lx\n";
1151 char tempfile[MAXFNAMELEN];
1152 int true_rumor_count, false_rumor_count;
1153 long true_rumor_size, false_rumor_size;
1154 unsigned long true_rumor_offset, false_rumor_offset, eof_offset;
1155
1156 Sprintf(tempfile, DATA_TEMPLATE, "rumors.tmp");
1157 filename[0] = '\0';
1158#ifdef FILE_PREFIX
1159 Strcat(filename, file_prefix);
1160#endif
1161 Sprintf(eos(filename), DATA_TEMPLATE, RUMOR_FILE);
1162 if (!(ofp = fopen(filename, WRTMODE))) {
1163 perror(filename);
1164 makedefs_exit(EXIT_FAILURE);
1165 /*NOTREACHED*/
1166 }
1167 if (!(tfp = fopen(tempfile, WRTMODE))) {
1168 perror(tempfile);
1169 Fclose(ofp);
1170 makedefs_exit(EXIT_FAILURE);
1171 /*NOTREACHED*/
1172 }
1173
1174 true_rumor_count = false_rumor_count = 0;
1175 true_rumor_size = false_rumor_size = 0L;
1176 true_rumor_offset = false_rumor_offset = eof_offset = 0L;
1177
1178 /* output a dummy header record; we'll replace it in final output */
1179 Fprintf(tfp, rumors_header, Dont_Edit_Data, true_rumor_count,
1180 true_rumor_size, true_rumor_offset, false_rumor_count,
1181 false_rumor_size, false_rumor_offset, eof_offset);
1182 /* record the current position; true rumors will start here */
1183 true_rumor_offset = (unsigned long) ftell(tfp);
1184
1185 false_rumor_offset
1186 = (unsigned long) read_rumors_file(".tru", &true_rumor_count,
1187 &true_rumor_size, true_rumor_offset,
1188 MD_PAD_RUMORS);
1189 if (!false_rumor_offset)
1190 goto rumors_failure;
1191
1192 eof_offset = read_rumors_file(".fal", &false_rumor_count,
1193 &false_rumor_size, false_rumor_offset,
1194 MD_PAD_RUMORS);
1195 if (!eof_offset)
1196 goto rumors_failure;
1197
1198 /* get ready to transfer the contents of temp file to output file */
1199 line = (char *) alloc(BUFSZ + MAXFNAMELEN);
1200 Sprintf(line, "rewind of \"%s\"", tempfile);

Callers 1

do_makedefsFunction · 0.85

Calls 7

eosFunction · 0.85
makedefs_exitFunction · 0.85
ftellFunction · 0.85
read_rumors_fileFunction · 0.85
set_fgetline_contextFunction · 0.85
fgetlineFunction · 0.70
allocFunction · 0.50

Tested by

no test coverage detected