From: PatR Date: Tue, 5 Oct 2021 08:11:24 +0000 (-0700) Subject: fix Unix build with DEF_PAGER defined X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ccfddd47de81f160acec3c9ceca729c65fdafded;p=nethack fix Unix build with DEF_PAGER defined Eliminate a couple of compile warnings produced when DEF_PAGER is defined: unixmain.c: g.catmore=DEF_PAGER; wintty.c: fd=open(...). Override its use when DLB is also defined since an external pager could access 'license' but not 'history', 'opthelp', &c when those are in the dlb container file. In the commented out value for DEF_PAGER, show a viable value for the default configuration these days. --- diff --git a/include/decl.h b/include/decl.h index 5f3d2a825..951e12811 100644 --- a/include/decl.h +++ b/include/decl.h @@ -838,7 +838,7 @@ struct instance_globals { int locknum; /* max num of simultaneous users */ #endif #ifdef DEF_PAGER - char *catmore; /* default pager */ + const char *catmore; /* external pager; from getenv() or DEF_PAGER */ #endif #ifdef MICRO char levels[PATHLEN]; /* where levels are */ diff --git a/include/unixconf.h b/include/unixconf.h index 303139e99..9a9b77de6 100644 --- a/include/unixconf.h +++ b/include/unixconf.h @@ -93,10 +93,12 @@ /* * Define DEF_PAGER as your default pager, e.g. "/bin/cat" or "/usr/ucb/more" * If defined, it can be overridden by the environment variable PAGER. - * Hack will use its internal pager if DEF_PAGER is not defined. - * (This might be preferable for security reasons.) + * NetHack will use its internal pager if DEF_PAGER is not defined _or_ + * if DLB is defined since an external pager won't know how to access the + * contents of the dlb container file. + * (Note: leaving DEF_PAGER undefined is preferable for security reasons.) */ -/* #define DEF_PAGER ".../mydir/mypager" */ +/* #define DEF_PAGER "/usr/bin/less" */ /* * Define PORT_HELP to be the name of the port-specfic help file. diff --git a/sys/unix/unixmain.c b/sys/unix/unixmain.c index 24251c18a..9f99bb949 100644 --- a/sys/unix/unixmain.c +++ b/sys/unix/unixmain.c @@ -220,7 +220,8 @@ main(int argc, char *argv[]) #endif #ifdef DEF_PAGER - if (!(g.catmore = nh_getenv("HACKPAGER")) + if (!(g.catmore = nh_getenv("NETHACKPAGER")) + && !(g.catmore = nh_getenv("HACKPAGER")) && !(g.catmore = nh_getenv("PAGER"))) g.catmore = DEF_PAGER; #endif diff --git a/win/tty/wintty.c b/win/tty/wintty.c index d8d4b846e..1ee060b58 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -36,6 +36,20 @@ extern void msmsg(const char *, ...); #endif #endif +#ifdef DEF_PAGER + /* DEF_PAGER implies UNIX; when dlb is in use, the only file accessible + to an external pager is 'license'; override 'DEF_PAGER' for that + situation rather than using code to fallback to DLB plus internal + pager after open() failure */ +#ifdef DLB +#undef DEF_PAGER +#else +#ifndef O_RDONLY /* (same logic as unixmain.c) */ +#include +#endif +#endif /* DLB */ +#endif /* DEF_PAGER */ + #if defined(TTY_TILES_ESCCODES) || defined(TTY_SOUND_ESCCODES) #define VT_ANSI_COMMAND 'z' #endif @@ -2791,7 +2805,7 @@ tty_display_file(const char *fname, boolean complain) #ifdef DEF_PAGER /* this implies that UNIX is defined */ { /* use external pager; this may give security problems */ - register int fd = open(fname, 0); + int fd = open(fname, O_RDONLY); if (fd < 0) { if (complain)