From: Gwen Weinholt <git@weinholt.se>
Date: Sun, 22 Sep 2024 19:36:08 +0200
Subject: Fix numerous compilation errors

---
 crs.c     | 15 ++++++++++-----
 differ.c  |  6 +++---
 posix.c   |  2 +-
 repl.c    | 18 +++++++++---------
 scm.c     | 11 ++++++-----
 scm.h     |  6 +++---
 scmmain.c |  7 ++++---
 script.c  | 23 ++++++++++++-----------
 x.c       |  6 +++---
 x.h       |  3 ++-
 10 files changed, 53 insertions(+), 44 deletions(-)

diff --git a/crs.c b/crs.c
index 87197a7..1fdbb3f 100755
--- a/crs.c
+++ b/crs.c
@@ -69,9 +69,10 @@ static ptobfuns winptob = {
   bwaddch,
   bwaddstr,
   bwwrite,
-  wrefresh,
-  wgetch,
-  freewindow};
+  (int (*)(FILE *))wrefresh,
+  (int (*)(FILE *))wgetch,
+  freewindow,
+  0};
 
 SCM mkwindow(win)
      WINDOW *win;
@@ -100,6 +101,10 @@ SCM lendwin()
   if (IMP(*loc_stdscr)) return BOOL_F;
   return ERR==endwin() ? BOOL_F : BOOL_T;
 }
+void lendwin_void()
+{
+  (void)lendwin();
+}
 
 static char s_newwin[] = "newwin", s_subwin[] = "subwin", s_mvwin[] = "mvwin",
 	    s_overlay[] = "overlay", s_overwrite[] = "overwrite";
@@ -238,7 +243,7 @@ SCM lunctrl(c)
 {
   ASRTER(ICHRP(c), c, ARG1, s_unctrl);
   {
-    char *str = unctrl(ICHR(c));
+    const char *str = unctrl(ICHR(c));
     return makfrom0str(str);
   }
 }
@@ -387,5 +392,5 @@ void init_crs()
   make_subr(s_mvwin, tc7_subr_3, lmvwin);
   make_subr(s_box, tc7_subr_3, lbox);
   add_feature("curses");
-  add_final(lendwin);
+  add_final(lendwin_void);
 }
diff --git a/differ.c b/differ.c
index fcff12e..dcdb6c7 100755
--- a/differ.c
+++ b/differ.c
@@ -65,17 +65,17 @@ SCM_EXPORT SCM  diff2editlen P((SCM Fp, SCM A, SCM Args));
 #define MAX(a,b)		(a<b ? b : a)
 #define MIN(a,b)		(a>b ? b : a)
 
-I32 *long_subarray(ra, start, end)
+void *long_subarray(ra, start, end)
      I32 *ra; int start, end;
 {
   return &(ra[start]);
 }
-short *short_subarray(ra, start, end)
+void *short_subarray(ra, start, end)
      short *ra; int start, end;
 {
   return &(ra[start]);
 }
-char *char_subarray(ra, start, end)
+void *char_subarray(ra, start, end)
      char *ra; int start, end;
 {
   return &(ra[start]);
diff --git a/posix.c b/posix.c
index 159dba2..ecf597b 100644
--- a/posix.c
+++ b/posix.c
@@ -191,7 +191,7 @@ SCM l_grinfo(name)
   ve[ 0] = makfrom0str(entry->gr_name);
   ve[ 1] = makfrom0str(entry->gr_passwd);
   ve[ 2] = ulong2num((unsigned long)entry->gr_gid);
-  ve[ 3] = makfromstrs(-1, entry->gr_mem);
+  ve[ 3] = makfromstrs(-1, (const char * const*)entry->gr_mem);
   return ans;
 }
 SCM l_setgr(arg)
diff --git a/repl.c b/repl.c
index 8197e4a..ce0f770 100644
--- a/repl.c
+++ b/repl.c
@@ -1288,7 +1288,7 @@ int scm_verbose = 1;		/* Low so that monitor info won't be */
 static int errjmp_recursive = 0;
 static int errobj_codep;
 static SCM err_exp, err_env;
-static char *err_pos, *err_s_subr;
+static const char *err_pos, *err_s_subr;
 static cell tmp_errobj = {(SCM)UNDEFINED, (SCM)EOL};
 static cell tmp_loadpath = {(SCM)BOOL_F, (SCM)EOL};
 SCM *loc_errobj = (SCM *)&tmp_errobj;
@@ -1308,7 +1308,7 @@ int handle_it(i)
   SCM proc;
   char *name = errmsgs[i-WNA].s_response;
   if (errjmp_bad || errjmp_recursive)
-    wta(UNDEFINED, (char *)i, ""); /* sends it to def_err_response */
+    wta(UNDEFINED, (char *)(intptr_t)i, ""); /* sends it to def_err_response */
   /* NEWCELL does not defer interrupts; so be careful to maintain the
      freelist integrity. */
   if (name) {
@@ -2112,14 +2112,14 @@ static void def_err_response()
     lputc((short)err_pos <= ARGn ? ' ' : '1' + (short)err_pos - ARG1, cur_errp);
   }
 #else
-  if ((~0x1fL) & (long)err_pos) lputs(err_pos, cur_errp);
-  else if (WNA > (long)err_pos) {
+  if ((~0x1fL) & (intptr_t)err_pos) lputs(err_pos, cur_errp);
+  else if (WNA > (intptr_t)err_pos) {
     lputs("Wrong type in arg", cur_errp);
-    lputc((long)err_pos <= ARGn ? ' ' : '1' + (int)err_pos - ARG1, cur_errp);
+    lputc((intptr_t)err_pos <= ARGn ? ' ' : '1' + (intptr_t)err_pos - ARG1, cur_errp);
   }
 #endif
-  else lputs(errmsgs[((int)err_pos)-WNA].msg, cur_errp);
-  lputs(((long)err_pos==WNA)?" given ":" ", cur_errp);
+  else lputs(errmsgs[((intptr_t)err_pos)-WNA].msg, cur_errp);
+  lputs(((intptr_t)err_pos==WNA)?" given ":" ", cur_errp);
   err_pos = 0;
   if (!UNBNDP(obj))
     if (reset_safeport(sys_safep, 55, cur_errp))
@@ -2176,8 +2176,8 @@ void everr(exp, env, arg, pos, s_subr, codep)
   errobj_codep = codep;
   if (errjmp_bad || errjmp_recursive) def_err_response();
   longjump(CONT(rootcont)->jmpbuf,
-	   (~0x1fL) & (long)pos || (WNA > (long)pos) ?
-	   COOKIE(1) : COOKIE((int)pos));
+	   (~0x1fL) & (intptr_t)pos || (WNA > (intptr_t)pos) ?
+	   COOKIE(1) : COOKIE((intptr_t)pos));
   /* will do error processing at stack base */
 }
 void wta(arg, pos, s_subr)
diff --git a/scm.c b/scm.c
index f6766d6..20c4355 100644
--- a/scm.c
+++ b/scm.c
@@ -165,7 +165,8 @@ static struct {
 
 void process_signals()
 {
-  int i, n;
+  int i;
+  size_t n;
   unsigned long mask = 1L;
   /* printf("process_signals; output_deferred=%d\n", output_deferred); fflush(stdout); */
   if (output_deferred) {
@@ -177,7 +178,7 @@ void process_signals()
       i = n + SIGNAL_BASE;
       SIG_deferred &= ~mask;
       if (i != handle_it(i))
-	wta(UNDEFINED, (char *)i, "");
+       wta(UNDEFINED, (char *)(intptr_t)i, "");
     }
     mask <<= 1;
   }
@@ -260,7 +261,7 @@ static SIGRETTYPE err_signal(sig)
   signal(sig, err_signal);
   while (i--)
     if (sig == sigdesc[i].signo) break;
-  wta(MAKINUM(sig), (i < 0 ? s_unksig : (char *)(i + SIGNAL_BASE)), "");
+  wta(MAKINUM(sig), (i < 0 ? s_unksig : (char *)(intptr_t)(i + SIGNAL_BASE)), "");
 }
 
 static SIGRETTYPE scmable_signal(sig)
@@ -291,7 +292,7 @@ static SIGRETTYPE scmable_signal(sig)
     i += SIGNAL_BASE;
     if (i != handle_it(i)) {
       errno = oerr;
-      wta(UNDEFINED, (char *)i, "");
+      wta(UNDEFINED, (char *)(intptr_t)i, "");
     }
   }
   errno = oerr;
@@ -669,7 +670,7 @@ void restore_signals()
 void scm_init_from_argv(argc, argv, script_arg, iverbose, buf0stdin)
      int argc;
      const char * const *argv;
-     char *script_arg;
+     const char *script_arg;
      int iverbose;
      int buf0stdin;
 {
diff --git a/scm.h b/scm.h
index 870c369..834c9ce 100644
--- a/scm.h
+++ b/scm.h
@@ -784,7 +784,7 @@ SCM_EXPORT void init_iprocs P((iproc *subra, int type));
 SCM_EXPORT void final_scm P((int));
 SCM_EXPORT void init_sbrk P((void));
 SCM_EXPORT int  init_buf0 P((FILE *inport));
-SCM_EXPORT void scm_init_from_argv P((int argc, const char * const *argv, char *script_arg,
+SCM_EXPORT void scm_init_from_argv P((int argc, const char * const *argv, const char *script_arg,
                               int iverbose, int buf0stdin));
 SCM_EXPORT void init_signals P((void));
 SCM_EXPORT SCM  scm_top_level P((char *initpath, SCM (*toplvl_fun)()));
@@ -1095,8 +1095,8 @@ SCM_EXPORT int  scm_bigdblcomp P((SCM b, double d));
 SCM_EXPORT char *       scm_cat_path P((char *str1, const char *str2, long n));
 SCM_EXPORT char *       scm_try_path P((char *path));
 SCM_EXPORT char *       script_find_executable P((const char *command));
-SCM_EXPORT char **      script_process_argv P((int argc, const char **argv));
-SCM_EXPORT int  script_count_argv P((const char **argv));
+SCM_EXPORT const char *const *script_process_argv P((int argc, const char *const *argv));
+SCM_EXPORT int  script_count_argv P((const char *const *argv));
 SCM_EXPORT char *       find_impl_file P((const char *exec_path, const char *generic_name,
                           const char *initname, const char *sep));
 
diff --git a/scmmain.c b/scmmain.c
index ace196d..ec75229 100755
--- a/scmmain.c
+++ b/scmmain.c
@@ -83,10 +83,11 @@ void scmmain_init_user_scm();
 
 int main(argc, argv)
      int argc;
-     const char **argv;
+     const char *const *argv;
 {
-  char *script_arg = 0;		/* location of SCSH style script file or 0. */
-  char *implpath = 0, **nargv;
+  const char *script_arg = 0; /* location of SCSH style script file or 0. */
+  char *implpath = 0;
+  const char *const *nargv;
   int nargc, iverbose = 0, buf0stdin;
   SCM retval;
 /* added by Dai Inukai 2001-03-21 */
diff --git a/script.c b/script.c
index 5a80186..910d213 100755
--- a/script.c
+++ b/script.c
@@ -146,7 +146,7 @@ char *find_impl_file(exec_path, generic_name, initname, sep)
      const char *generic_name, *initname, *sep;
 {
   char *sepptr = strrchr(exec_path, sep[0]);
-  char *extptr = exec_path + strlen(exec_path);
+  const char *extptr = exec_path + strlen(exec_path);
   char *path = 0;
 
 #ifdef _WIN32
@@ -192,7 +192,7 @@ char *find_impl_file(exec_path, generic_name, initname, sep)
 
       /* Look for initname in peer directory "lib". */
       if (path) {
-	strncpy(sepptr, "lib", 3);
+	strncpy(sepptr, "lib", 4);
 	path = scm_sep_init_try(path, sep, initname);
 	if (path) return path;
       }
@@ -351,15 +351,16 @@ int script_meta_arg_P(arg)
 #endif
 }
 
-char **script_process_argv(argc, argv)
+const char *const *script_process_argv(argc, argv)
      int argc;
-     const char **argv;
+     const char *const *argv;
 {
   int nargc = argc, argi = 1, nargi = 1;
-  char *narg, **nargv;
+  char *narg;
+  const char **nargv;
   if (!(argc > 2 && script_meta_arg_P(argv[1]))) return 0L;
-  if (!(nargv = (char **)malloc((1 + nargc) * sizeof(char *)))) return 0L;
-  nargv[0] = argv[0];
+  if (!(nargv = malloc((1 + nargc) * sizeof(char *)))) return 0L;
+  nargv[0] = (char *)argv[0];
   while (((argi+1) < argc) && (script_meta_arg_P(argv[argi]))) {
     FILE *f = fopen(argv[++argi], "r");
     if (f) {
@@ -370,19 +371,19 @@ char **script_process_argv(argc, argv)
       case '\n': goto found_args;
       }
     found_args: while ((narg = script_read_arg(f)))
-      if (!(nargv = (char **)realloc(nargv, (1 + ++nargc) * sizeof(char *))))
+      if (!(nargv = realloc(nargv, (1 + ++nargc) * sizeof(char *))))
 	return 0L;
       else nargv[nargi++] = narg;
       fclose(f);
-      nargv[nargi++] = argv[argi++];
+      nargv[nargi++] = (char *)argv[argi++];
     }
   }
-  while (argi <= argc) nargv[nargi++] = argv[argi++];
+  while (argi <= argc) nargv[nargi++] = (char *)argv[argi++];
   return nargv;
 }
 
 int script_count_argv(argv)
-     const char **argv;
+     const char *const *argv;
 {
   int argc = 0;
   while (argv[argc]) argc++;
diff --git a/x.c b/x.c
index e6db874..3b6584c 100755
--- a/x.c
+++ b/x.c
@@ -334,7 +334,7 @@ SCM make_xcolormap(sdpy, cmp)
   xcm->display = sdpy;
   xcm->dpy = DISPLAY(xcm->display)->dpy;
   xcm->cm = cmp;
-  XSaveContext(XDISPLAY(sdpy), (XID)cmp, xtc_cmp, z);
+  XSaveContext(XDISPLAY(sdpy), (XID)cmp, xtc_cmp, (void*)(intptr_t)z);
   ALLOW_INTS;
   return z;
 }
@@ -582,7 +582,7 @@ SCM CCC2SCM(ccc)
     DEFER_INTS;
     CAR(s_ccc) = tc16_xccc;
     SETCDR(s_ccc, ccc);
-    XSaveContext(ccc->dpy, (XID)ccc, xtc_ccc, s_ccc);
+    XSaveContext(ccc->dpy, (XID)ccc, xtc_ccc, (void*)(intptr_t)s_ccc);
     ALLOW_INTS;
   }
   return s_ccc;
@@ -2050,7 +2050,7 @@ SCM x_fill_rectangle(swin, sgc, sargs)
 
 void xldraw_string(sdbl, sgc, sargs, proc, s_caller)
      SCM sdbl, sgc, sargs;
-     int (*proc)();
+     XDrawStringFunc proc;
      char *s_caller;
 {
   XPoint position;
diff --git a/x.h b/x.h
index 4423211..6c52a9f 100755
--- a/x.h
+++ b/x.h
@@ -82,7 +82,8 @@ SCM x_get_window_property(SCM swin, SCM sprop, SCM sargs);
 SCM x_list_properties(SCM swin);
 SCM x_clear_area(SCM swin, SCM spos, SCM sargs);
 SCM x_fill_rectangle(SCM swin, SCM sgc, SCM sargs);
-void xldraw_string(SCM sdbl, SCM sgc, SCM sargs, int (*proc)(void), char *s_caller);
+typedef int (*XDrawStringFunc)(Display *, Drawable, GC, int, int, const char *, int);
+void xldraw_string(SCM sdbl, SCM sgc, SCM sargs, XDrawStringFunc proc, char *s_caller);
 SCM x_draw_string(SCM sdbl, SCM sgc, SCM sargs);
 SCM x_image_string(SCM sdbl, SCM sgc, SCM sargs);
 SCM x_draw_points(SCM sdbl, SCM sgc, SCM sargs);
