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

Function com_pager_core

src/questpgr.c:467–621  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

465}
466
467staticfn boolean
468com_pager_core(
469 const char *section,
470 const char *msgid,
471 boolean showerror,
472 char **rawtext)
473{
474 static const char *const howtoput[] = {
475 "pline", "window", "text", "menu", "default", NULL
476 };
477 static const int howtoput2i[] = { 1, 2, 2, 3, 0, 0 };
478 int output;
479 lua_State *L;
480 char *text = NULL, *synopsis = NULL, *fallback_msgid = NULL;
481 boolean res = FALSE;
482 nhl_sandbox_info sbi = {NHL_SB_SAFE, 1*1024*1024, 0, 1*1024*1024};
483
484 if (skip_pager(TRUE))
485 return FALSE;
486
487 L = nhl_init(&sbi);
488 if (!L) {
489 if (showerror)
490 impossible("com_pager: nhl_init() failed");
491 goto compagerdone;
492 }
493
494 if (!nhl_loadlua(L, QTEXT_FILE)) {
495 if (showerror)
496 impossible("com_pager: %s not found.", QTEXT_FILE);
497 goto compagerdone;
498 }
499
500 lua_settop(L, 0);
501 lua_getglobal(L, "questtext");
502 if (!lua_istable(L, -1)) {
503 if (showerror)
504 impossible("com_pager: questtext in %s is not a lua table",
505 QTEXT_FILE);
506 goto compagerdone;
507 }
508
509 lua_getfield(L, -1, section);
510 if (!lua_istable(L, -1)) {
511 if (showerror)
512 impossible("com_pager: questtext[%s] in %s is not a lua table",
513 section, QTEXT_FILE);
514 goto compagerdone;
515 }
516
517 tryagain:
518 lua_getfield(L, -1, fallback_msgid ? fallback_msgid : msgid);
519 if (!lua_istable(L, -1)) {
520 if (!fallback_msgid) {
521 /* Do we have questtxt[msg_fallbacks][<msgid>]? */
522 lua_getfield(L, -3, "msg_fallbacks");
523 if (lua_istable(L, -1)) {
524 fallback_msgid = get_table_str_opt(L, msgid, NULL);

Callers 3

stinky_nemesisFunction · 0.85
com_pagerFunction · 0.85
qt_pagerFunction · 0.85

Calls 13

skip_pagerFunction · 0.85
nhl_initFunction · 0.85
nhl_loadluaFunction · 0.85
get_table_str_optFunction · 0.85
dupstrFunction · 0.85
get_table_optionFunction · 0.85
rn2Function · 0.85
strNsubstFunction · 0.85
deliver_by_plineFunction · 0.85
deliver_by_windowFunction · 0.85
convert_lineFunction · 0.85
nhl_doneFunction · 0.85

Tested by

no test coverage detected