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

Function read_tribute

src/files.c:3473–3645  ·  view source on GitHub ↗

Returns True if you were able to read something. */

Source from the content-addressed store, hash-verified

3471
3472/* Returns True if you were able to read something. */
3473boolean
3474read_tribute(const char *tribsection, const char *tribtitle,
3475 int tribpassage, char *nowin_buf, int bufsz,
3476 unsigned oid) /* book identifier */
3477{
3478 dlb *fp;
3479 char line[BUFSZ], lastline[BUFSZ];
3480
3481 int scope = 0;
3482 int linect = 0, passagecnt = 0, targetpassage = 0;
3483 const char *badtranslation = "an incomprehensible foreign translation";
3484 boolean matchedsection = FALSE, matchedtitle = FALSE;
3485 winid tribwin = WIN_ERR;
3486 boolean grasped = FALSE;
3487 boolean foundpassage = FALSE;
3488
3489 if (nowin_buf)
3490 *nowin_buf = '\0';
3491
3492 /* check for mandatories */
3493 if (!tribsection || !tribtitle) {
3494 if (!nowin_buf)
3495 pline("It's %s of \"%s\"!", badtranslation, tribtitle);
3496 return grasped;
3497 }
3498
3499 debugpline3("read_tribute %s, %s, %d.", tribsection, tribtitle,
3500 tribpassage);
3501
3502 fp = dlb_fopen(TRIBUTEFILE, "r");
3503 if (!fp) {
3504 /* this is actually an error - cannot open tribute file! */
3505 if (!nowin_buf)
3506 You_feel("too overwhelmed to continue!");
3507 return grasped;
3508 }
3509
3510 /*
3511 * Syntax (not case-sensitive):
3512 * %section books
3513 *
3514 * In the books section:
3515 * %title booktitle (n)
3516 * where booktitle=book title without quotes
3517 * (n)= total number of passages present for this title
3518 * %passage k
3519 * where k=sequential passage number
3520 *
3521 * %e ends the passage/book/section
3522 * If in a passage, it marks the end of that passage.
3523 * If in a book, it marks the end of that book.
3524 * If in a section, it marks the end of that section.
3525 *
3526 * %section death
3527 */
3528
3529 *line = *lastline = '\0';
3530 while (dlb_fgets(line, sizeof line, fp) != 0) {

Callers 2

Death_quoteFunction · 0.85
study_bookFunction · 0.85

Calls 11

dlb_fopenFunction · 0.85
You_feelFunction · 0.85
dlb_fgetsFunction · 0.85
strip_newlineFunction · 0.85
mungspacesFunction · 0.85
choose_passageFunction · 0.85
copyncharsFunction · 0.85
dlb_fcloseFunction · 0.85
strrchrFunction · 0.85
plineFunction · 0.70
strncmpiFunction · 0.70

Tested by

no test coverage detected