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

Function get_rnd_text

src/rumors.c:498–526  ·  view source on GitHub ↗

Gets a random line of text from file 'fname', and returns it. rng is the random number generator to use, and should act like rn2 does. */

Source from the content-addressed store, hash-verified

496/* Gets a random line of text from file 'fname', and returns it.
497 rng is the random number generator to use, and should act like rn2 does. */
498char *
499get_rnd_text(
500 const char *fname,
501 char *buf,
502 int (*rng)(int),
503 unsigned padlength)
504{
505 dlb *fh = dlb_fopen(fname, "r");
506
507 buf[0] = '\0';
508 if (fh) {
509 long starttxt = 0L;
510 char line[BUFSZ];
511
512 /* skip "don't edit" comment */
513 (void) dlb_fgets(line, sizeof line, fh);
514 /* obtain current file position */
515 (void) dlb_fseek(fh, 0L, SEEK_CUR);
516 starttxt = dlb_ftell(fh);
517
518 /* get a randomly chosen line; it comes back decrypted and unpadded */
519 Strcpy(buf, get_rnd_line(fh, line, (unsigned) sizeof line, rng,
520 starttxt, 0L, padlength));
521 (void) dlb_fclose(fh);
522 } else {
523 couldnt_open_file(fname);
524 }
525 return buf;
526}
527
528void
529outrumor(

Callers 3

bogusmonFunction · 0.85
random_engravingFunction · 0.85
make_graveFunction · 0.85

Calls 7

dlb_fopenFunction · 0.85
dlb_fgetsFunction · 0.85
dlb_fseekFunction · 0.85
dlb_ftellFunction · 0.85
get_rnd_lineFunction · 0.85
dlb_fcloseFunction · 0.85
couldnt_open_fileFunction · 0.85

Tested by

no test coverage detected