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

Function others_check

src/rumors.c:307–408  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

305
306/* 5.0: augments rumors_check(); test 'engrave' or 'epitaph' or 'bogusmon' */
307staticfn void
308others_check(
309 const char *ftype, /* header: "{Engravings|Epitaphs|Bogus monsters}:" */
310 const char *fname, /* filename: {ENGRAVEFILE|EPITAPHFILE|BOGUSMONFILE} */
311 winid *winptr) /* text window for output; created here if necessary */
312{
313 static const char errfmt[] = "others_check(\"%s\"): %s";
314 dlb *fh;
315 char line[BUFSZ], xbuf[BUFSZ], *endp;
316 winid tmpwin = *winptr;
317 int entrycount = 0;
318
319 fh = dlb_fopen(fname, "r");
320 if (fh) {
321 if (tmpwin == WIN_ERR) {
322 *winptr = tmpwin = create_nhwindow(NHW_TEXT);
323 if (tmpwin == WIN_ERR) {
324 /* should panic, but won't for wizard mode check operation */
325 impossible(errfmt, fname, "can't create temporary window");
326 goto closeit;
327 }
328 }
329 putstr(tmpwin, 0, "");
330 putstr(tmpwin, 0, ftype);
331 /* "don't edit" comment */
332 *line = '\0';
333 if (!dlb_fgets(line, sizeof line, fh)) {
334 Sprintf(xbuf, errfmt, fname, "error; can't read comment line");
335 putstr(tmpwin, 0, xbuf);
336 goto closeit;
337 }
338 if (*line != '#') {
339 Sprintf(xbuf, errfmt, fname,
340 "malformed; first line is not a comment line:");
341 putstr(tmpwin, 0, xbuf);
342 /* show the bad line; we don't know whether it has been
343 encrypted via xcrypt() so show it both ways */
344 if ((endp = strchr(line, '\n')) != 0)
345 *endp = 0;
346 putstr(tmpwin, 0, "- first line, as is");
347 putstr(tmpwin, 0, line);
348 putstr(tmpwin, 0, "- xcrypt of first line");
349 putstr(tmpwin, 0, xcrypt(line, xbuf));
350 goto closeit;
351 }
352 /* first line; should be default one inserted by makedefs when
353 building the file but we don't have the expected value so
354 can only require a line to exist */
355 *line = '\0';
356 if (!dlb_fgets(line, sizeof line, fh) || *line == '\n') {
357 Sprintf(xbuf, errfmt, fname,
358 !*line ? "can't read first non-comment line"
359 : "first non-comment line is empty");
360 putstr(tmpwin, 0, xbuf);
361 goto closeit;
362 }
363 ++entrycount;
364 if ((endp = strchr(line, '\n')) != 0)

Callers 1

rumor_checkFunction · 0.85

Calls 6

dlb_fopenFunction · 0.85
dlb_fgetsFunction · 0.85
xcryptFunction · 0.85
dlb_fcloseFunction · 0.85
couldnt_open_fileFunction · 0.85
impossibleFunction · 0.70

Tested by

no test coverage detected