]> granicus.if.org Git - nethack/commitdiff
fix Unix build with DEF_PAGER defined
authorPatR <rankin@nethack.org>
Tue, 5 Oct 2021 08:11:24 +0000 (01:11 -0700)
committerPatR <rankin@nethack.org>
Tue, 5 Oct 2021 08:11:24 +0000 (01:11 -0700)
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.

include/decl.h
include/unixconf.h
sys/unix/unixmain.c
win/tty/wintty.c

index 5f3d2a825b136582723b7c1c300ab1d196954472..951e12811cc2e7883c77e00a584469177a143470 100644 (file)
@@ -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 */
index 303139e99909a86b36ab9143aeb2ae28c54359c0..9a9b77de6d7e13d3ea4b69ab18957cf432141a08 100644 (file)
 /*
  * 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.
index 24251c18a9bcae46265425d12f1e8cda69a433f0..9f99bb949620c4d1d24e1ea3dd290a3330240113 100644 (file)
@@ -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
index d8d4b846ee632cba5b16946eeb93a3d722847013..1ee060b5859a6c18b3c9c556004971fdc4338498 100644 (file)
@@ -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 <fcntl.h>
+#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)