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. */
| 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. */ |
| 498 | char * |
| 499 | get_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 | |
| 528 | void |
| 529 | outrumor( |
no test coverage detected