From 70036333d91fdea9c7fcfcb498de3f40bb4ac18a Mon Sep 17 00:00:00 2001
From: Carl Drougge <bearded@longhaired.org>
Date: Fri, 25 Feb 2022 23:53:07 +0100
Subject: warnings: Building with DEBUG

caused a lot of warnings if pointers were bigger than ints.

This will still cause warnings if pointers are bigger than longs, but I'm
thinking that's better than breaking it for someone who wants to use a
compiler that doesn't support %p (or long long).

(Also snuck in an include only needed when building with DEBUG.)
---
 src/display.c     |  3 ++-
 src/layer.c       | 10 +++++-----
 src/layer.h       |  2 +-
 src/list_window.c |  2 +-
 src/process.c     |  4 ++--
 src/sched.c       |  8 ++++----
 src/screen.c      | 12 ++++++------
 src/socket.c      |  2 +-
 src/utmp.c        |  8 ++++----
 src/window.c      |  4 ++--
 10 files changed, 28 insertions(+), 27 deletions(-)

diff --git a/src/display.c b/src/display.c
index b475a80..8172b0f 100644
--- a/src/display.c
+++ b/src/display.c
@@ -27,6 +27,7 @@
  */
 
 #include <sys/types.h>
+#include <sys/stat.h>
 #include <signal.h>
 #include <fcntl.h>
 #ifndef sun
@@ -3774,7 +3775,7 @@ struct event *ev;
 char *data;
 {
   display = (struct display *)data;
-  debug1("disp_status_fn for display %x\n", (int)display);
+  debug1("disp_status_fn for display %lx\n", (long)display);
   if (D_status)
     RemoveStatus();
 }
diff --git a/src/layer.c b/src/layer.c
index f505349..c28f4ef 100644
--- a/src/layer.c
+++ b/src/layer.c
@@ -892,7 +892,7 @@ VA_DECL
     buf[sizeof(buf) - 1] = 0;
   }
 
-  debug2("LMsg('%s') (%#x);\n", buf, (unsigned int)flayer);
+  debug2("LMsg('%s') (%#lx);\n", buf, (long)flayer);
   for (display = displays; display; display = display->d_next) {
     for (cv = D_cvlist; cv; cv = cv->c_next)
       if (cv->c_layer == flayer)
@@ -935,11 +935,11 @@ void KillLayerChain(struct layer *lay)
   struct layer *l, *oldflayer;
 
   oldflayer = flayer;
-  debug1("KillLayerChain %#x\n", lay);
+  debug1("KillLayerChain %#lx\n", (long)lay);
   for (l = lay; l; l = l->l_next) {
     if (l->l_layfn == &WinLf || l->l_layfn == &BlankLf)
       break;
-    debug1("- killing %#x\n", l);
+    debug1("- killing %#lx\n", (long)l);
     if (oldflayer == l)
       oldflayer = 0;
     for (cv = l->l_cvlist; cv; cv = ncv) {
@@ -973,7 +973,7 @@ int InitOverlayPage(int datasize, struct LayFuncs *lf, int block)
     Msg(0, "No memory for layer struct");
       return -1;
   }
-  debug2("Entering new layer on top of %#x: %#x\n", (unsigned int)flayer, newlay);
+  debug2("Entering new layer on top of %#lx: %#lx\n", (long)flayer, (long)newlay);
   data = 0;
   if (datasize) {
     if ((data = calloc(1, datasize)) == 0) {
@@ -1049,7 +1049,7 @@ void ExitOverlayPage()
   struct layout *lay;
 
   ASSERT(flayer);
-  debug1("Exiting layer %#x\n", (unsigned int)flayer);
+  debug1("Exiting layer %#lx\n", (long)flayer);
   oldlay = flayer;
   if (oldlay->l_data) {
     if (oldlay->l_layfn->lf_LayFree)
diff --git a/src/layer.h b/src/layer.h
index ca18bea..0e17ae3 100644
--- a/src/layer.h
+++ b/src/layer.h
@@ -106,7 +106,7 @@ struct layer
 	  debug("LayCallUp\n");				\
 	  flayer = flayer->l_next;			\
 	  oldcvlist = flayer->l_cvlist;			\
-	  debug1("oldcvlist: %x\n", oldcvlist);		\
+	  debug1("oldcvlist: %lx\n", (long)oldcvlist);	\
 	  flayer->l_cvlist = oldlay->l_cvlist;		\
 	  for (cv = flayer->l_cvlist; cv; cv = cv->c_lnext)	\
 		cv->c_layer = flayer;			\
diff --git a/src/list_window.c b/src/list_window.c
index 83c9036..e230cec 100644
--- a/src/list_window.c
+++ b/src/list_window.c
@@ -515,7 +515,7 @@ display_windows(int onblank, int order, struct win *group)
 
   if (onblank)
     {
-      debug3("flayer %x %d %x\n", flayer, flayer->l_width, flayer->l_height);
+      debug3("flayer %lx %d %x\n", (long)flayer, flayer->l_width, flayer->l_height);
       if (!display)
 	{
 	  LMsg(0, "windowlist -b: display required");
diff --git a/src/process.c b/src/process.c
index b1777d3..efbd705 100644
--- a/src/process.c
+++ b/src/process.c
@@ -770,14 +770,14 @@ int ilen;
 	}
       for (;;)
 	{
-	  debug3("cmp %c %c[%d]\n", ch, *D_seqp, D_seqp - D_kmaps);
+	  debug3("cmp %c %c[%ld]\n", ch, *D_seqp, (long)(D_seqp - D_kmaps));
 	  if (*D_seqp != ch)
 	    {
 	      l = D_seqp[D_seqp[-D_seql-1] + 1];
 	      if (l)
 		{
 		  D_seqp += l * 2 + 4;
-		  debug1("miss %d\n", D_seqp - D_kmaps);
+		  debug1("miss %ld\n", (long)(D_seqp - D_kmaps));
 		  continue;
 		}
 	      debug("complete miss\n");
diff --git a/src/sched.c b/src/sched.c
index fa2be8f..0e4282d 100644
--- a/src/sched.c
+++ b/src/sched.c
@@ -139,15 +139,15 @@ sched()
 #ifdef DEBUG
 		debug("waiting for events");
 		if (timeoutev)
-			debug2(" timeout %d secs %d usecs", timeout.tv_sec, timeout.tv_usec);
+			debug2(" timeout %ld secs %ld usecs", (long)timeout.tv_sec, (long)timeout.tv_usec);
 		debug(":\n");
 		for (ev = evs; ev; ev = ev->next)
 			debug3(" - fd %d type %d pri %d\n", ev->fd, ev->type, ev->pri);
 		if (tevs)
 			debug("timed events:\n");
 		for (ev = tevs; ev; ev = ev->next)
-			debug3(" - pri %d sec %d usec %d\n", ev->pri,
-			    ev->timeout.tv_sec, ev->timeout.tv_usec);
+			debug3(" - pri %d sec %ld usec %ld\n", ev->pri,
+			    (long)ev->timeout.tv_sec, (long)ev->timeout.tv_usec);
 #endif
 
 		FD_ZERO(&r);
@@ -228,7 +228,7 @@ void
 SetTimeout(struct event *ev, int timo)
 {
 	ASSERT(ev->type == EV_TIMEOUT);
-	debug2("event %x new timeout %d ms\n", ev, timo);
+	debug2("event %lx new timeout %d ms\n", (long)ev, timo);
 	gettimeofday(&ev->timeout, NULL);
 	ev->timeout.tv_sec += timo / 1000;
 	ev->timeout.tv_usec += (timo % 1000) * 1000;
diff --git a/src/screen.c b/src/screen.c
index 9af51c6..35b5b4b 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -1878,7 +1878,7 @@ void Hangup()
 {
   if (display == 0)
     return;
-  debug1("Hangup %x\n", display);
+  debug1("Hangup %lx\n", (long)display);
   if (D_userfd >= 0) {
     close(D_userfd);
     D_userfd = -1;
@@ -2022,7 +2022,7 @@ void Detach(int mode)
   }
 
   pid = D_userpid;
-  debug2("display: %#x displays: %#x\n", (unsigned int)display, (unsigned int)displays);
+  debug2("display: %#lx displays: %#lx\n", (long)display, (long)displays);
   FreeDisplay();
 
   if (displays == 0) /* Flag detached-ness */
@@ -2112,7 +2112,7 @@ DEFINE_VARARGS_FN(Msg)
   int ignore;
   PROCESS_MESSAGE(buf);
 
-  debug2("Msg('%s') (%#x);\n", buf, (unsigned int)display);
+  debug2("Msg('%s') (%#lx);\n", buf, (long)display);
 
   if (display && displays)
     MakeStatus(buf);
@@ -2147,7 +2147,7 @@ DEFINE_VARARGS_FN(Panic)
   int ignore;
   PROCESS_MESSAGE(buf);
 
-  debug3("Panic('%s'); display=%x displays=%x\n", buf, display, displays);
+  debug3("Panic('%s'); display=%lx displays=%lx\n", buf, (long)display, (long)displays);
   if (displays == 0 && display == 0) {
     printf("%s\r\n", buf);
     if (PanicPid)
@@ -3048,7 +3048,7 @@ char *MakeWinMsgEv(char *str, struct win *win, int esc, int padlen, struct event
     else
       now.tv_sec += tick - (now.tv_sec % tick);
     ev->timeout = now;
-    debug2("NEW timeout %d %d\n", ev->timeout.tv_sec, tick);
+    debug2("NEW timeout %ld %d\n", (long)ev->timeout.tv_sec, tick);
   }
   return winmsg_buf;
 }
@@ -3338,7 +3338,7 @@ static void serv_select_fn(struct event *ev, char *data)
   for (display = displays; display; display = display->d_next) {
     if (D_status == STATUS_ON_WIN || D_cvlist == 0 || D_cvlist->c_next == 0)
       continue;
-    debug1("serv_select_fn: Restore on cv %#x\n", (int)D_forecv);
+    debug1("serv_select_fn: Restore on cv %#lx\n", (long)D_forecv);
     CV_CALL(D_forecv, LayRestore();LaySetCursor());
   }
 }
diff --git a/src/socket.c b/src/socket.c
index 6336770..42c3b14 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -1882,7 +1882,7 @@ struct msg *mp;
     {
       char *oldrcname = rc_name;
       rc_name = "-X";
-      debug3("Running command on display %x window %x (%d)\n", display, fore, fore ? fore->w_number : -1);
+      debug3("Running command on display %lx window %lx (%d)\n", (long)display, (long)fore, fore ? fore->w_number : -1);
       flayer = fore ? &fore->w_layer : 0;
       if (fore && fore->w_savelayer && (fore->w_blocked || fore->w_savelayer->l_cvlist == 0))
 	flayer = fore->w_savelayer;
diff --git a/src/utmp.c b/src/utmp.c
index 02a6ae2..1fb3603 100644
--- a/src/utmp.c
+++ b/src/utmp.c
@@ -353,7 +353,7 @@ RemoveLoginSlot()
 	}
       UT_CLOSE;
     }
-  debug1(" slot %d zapped\n", (int)D_loginslot);
+  debug1(" slot %ld zapped\n", (long)D_loginslot);
   if (D_loginslot == (slot_t)0)
     {
       /* couldn't remove slot, do a 'mesg n' at least. */
@@ -381,7 +381,7 @@ RestoreLoginSlot()
   ASSERT(display);
   if (utmpok && D_loginslot != (slot_t)0 && D_loginslot != (slot_t)-1)
     {
-      debug1(" logging you in again (slot %#x)\n", (int)D_loginslot);
+      debug1(" logging you in again (slot %#lx)\n", (long)D_loginslot);
       if (pututslot(D_loginslot, &D_utmp_logintty, D_loginhost, (struct win *)0) == 0)
         Msg(errno,"Could not write %s", UtmpName);
     }
@@ -424,7 +424,7 @@ struct win *wi;
       debug1("SetUtmp failed (tty %s).\n",wi->w_tty);
       return -1;
     }
-  debug2("SetUtmp %d will get slot %d...\n", wi->w_number, (int)slot);
+  debug2("SetUtmp %d will get slot %ld...\n", wi->w_number, (long)slot);
 
   bzero((char *)&u, sizeof(u));
   if ((saved_ut = bcmp((char *) &wi->w_savut, (char *)&u, sizeof(u))))
@@ -505,7 +505,7 @@ struct win *wi;
   slot_t slot;
 
   slot = wi->w_slot;
-  debug1("RemoveUtmp slot=%#x\n", slot);
+  debug1("RemoveUtmp slot=%#lx\n", (long)slot);
   if (!utmpok)
     return -1;
   if (slot == (slot_t)0 || slot == (slot_t)-1)
diff --git a/src/window.c b/src/window.c
index e890725..eb66a0b 100644
--- a/src/window.c
+++ b/src/window.c
@@ -494,7 +494,7 @@ WinRestore()
 {
   struct canvas *cv;
   fore = (struct win *)flayer->l_data;
-  debug1("WinRestore: win %p\n", fore);
+  debug1("WinRestore: win %lx\n", (long)fore);
   for (cv = flayer->l_cvlist; cv; cv = cv->c_next)
     {
       display = cv->c_display;
@@ -1825,7 +1825,7 @@ struct event *ev;
 	  return 1;
 	}
       debug2("muchpending %s %d: ", D_usertty, D_blocked);
-      debug3("%d %d %d\n", D_obufp - D_obuf, D_obufmax, D_blocked_fuzz);
+      debug3("%ld %d %d\n", (long)(D_obufp - D_obuf), D_obufmax, D_blocked_fuzz);
       if (D_blocked)
 	continue;
       if (D_obufp - D_obuf > D_obufmax + D_blocked_fuzz)
-- 
2.30.2

