From 628379c6eca1a2ba7f9526abfec40a163f7c467d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net>
Date: Fri, 1 Sep 1995 09:02:08 +0200
Subject: [PATCH] committing

Rev: src/configure.in:1.8
Rev: src/interpret.c:1.4
Rev: src/machine.h.in:1.2
Rev: src/memory.c:1.2
Rev: src/modules/files/file.c:1.3
Rev: src/modules/files/file.h:1.2
Rev: src/modules/files/socket.c:1.4
Rev: src/port.c:1.8
Rev: src/program.c:1.3
---
 src/configure.in           |   2 +-
 src/interpret.c            |   2 +-
 src/machine.h.in           |   3 +
 src/memory.c               |   4 +-
 src/modules/files/file.c   |  58 ++--
 src/modules/files/file.h   |  13 +-
 src/modules/files/socket.c |  32 +-
 src/port.c                 | 626 -------------------------------------
 src/program.c              |   2 +-
 9 files changed, 64 insertions(+), 678 deletions(-)

diff --git a/src/configure.in b/src/configure.in
index 069e83cccd..c118219cd2 100644
--- a/src/configure.in
+++ b/src/configure.in
@@ -82,7 +82,7 @@ rm -rf conftest.y y.tab.c y.tab.h conftest.out
 
 AC_HAVE_HEADERS(sys/rusage.h sys/time.h unistd.h stdlib.h memory.h values.h \
  string.h fcntl.h sys/filio.h sys/sockio.h crypt.h locale.h sys/resource.h \
- sys/select.h)
+ sys/select.h netdb.h)
 AC_STDC_HEADERS
 
 AC_SIZEOF_TYPE(char *)
diff --git a/src/interpret.c b/src/interpret.c
index 57248f9b6a..393fc05ed8 100644
--- a/src/interpret.c
+++ b/src/interpret.c
@@ -790,7 +790,7 @@ static void eval_instruction(unsigned char *pc)
       if(instr >= fp->context.prog->num_constants)
       {
 	instr += F_MAX_OPCODE;
-	fatal("Strange instruction %ld\n",instr);
+	fatal("Strange instruction %ld\n",(long)instr);
       }
 #endif      
       strict_apply_svalue(fp->context.prog->constants + instr, sp - *--mark_sp );
diff --git a/src/machine.h.in b/src/machine.h.in
index cc4f98ffe0..e1555fd7ff 100644
--- a/src/machine.h.in
+++ b/src/machine.h.in
@@ -43,6 +43,9 @@
 /* Define if you have the <unistd.h> header file.  */
 #undef HAVE_UNISTD_H
 
+/* Define if you have the <netdb.h> header file.  */
+#undef HAVE_NETDB_H
+
 /* more header files */
 #undef HAVE_FCNTL_H
 #undef HAVE_SYS_FILIO_H
diff --git a/src/memory.c b/src/memory.c
index 53a616362e..ab1fb8b106 100644
--- a/src/memory.c
+++ b/src/memory.c
@@ -88,7 +88,9 @@ void reorder(char *memory, INT32 nitems, INT32 size,INT32 *order)
   {
     for(d=0;d<nitems;d++) if(order[d]==e) break;
     if(d==nitems)
-      fatal("Missing number %ld in reorder() (nitems = %ld)\n",e,nitems);
+      fatal("Missing number %ld in reorder() (nitems = %ld)\n",
+	    (long)e,
+	    (long)nitems);
   }
 #endif
 
diff --git a/src/modules/files/file.c b/src/modules/files/file.c
index be52cddb62..fa4cf8cfa9 100644
--- a/src/modules/files/file.c
+++ b/src/modules/files/file.c
@@ -34,18 +34,14 @@
 #include <sys/wait.h>
 #include <sys/socket.h>
 
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-
-#ifdef HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-
 #ifdef HAVE_SYS_SOCKETVAR_H
 #include <sys/socketvar.h>
 #endif
 
+#ifdef HAVE_NETDB_H
+#include "netdb.h"
+#endif
+
 #define THIS ((struct file *)(fp->current_storage))
 
 static int fd_references[MAX_OPEN_FILEDESCRIPTORS];
@@ -844,7 +840,7 @@ static void file_dup2(INT32 args)
 
 static void file_open_socket(INT32 args)
 {
-  int fd, tmp;
+  int fd,tmp;
 
   do_close(THIS, FILE_READ | FILE_WRITE);
   fd=socket(AF_INET, SOCK_STREAM, 0);
@@ -890,20 +886,9 @@ static void file_connect(INT32 args)
   if(THIS->fd < 0)
     error("file->connect(): File not open for connect()\n");
 
-  addr.sin_family = AF_INET;
-  addr.sin_port = htons(((u_short)sp[1-args].u.integer));
 
-  if (inet_addr(sp[-args].u.string->str) == -1)
-     error("Malformed ip number.\n");
-  addr.sin_addr.s_addr = inet_addr(sp[-args].u.string->str);
-
-  if((long)addr.sin_addr.s_addr == -1)
-  {
-    THIS->errno=EINVAL;
-    pop_n_elems(args);
-    push_int(0);
-    return;
-  }
+  get_inet_addr(&addr, sp[-args].u.string->str);
+  addr.sin_port = htons(((u_short)sp[1-args].u.integer));
 
   if(connect(THIS->fd, (struct sockaddr *)&addr, sizeof(addr)) < 0)
   {
@@ -919,6 +904,35 @@ static void file_connect(INT32 args)
   }
 }
 
+void get_inet_addr(struct sockaddr_in *addr,char *name)
+{
+  MEMSET((char *)addr,0,sizeof(struct sockaddr_in));
+
+  addr->sin_family = AF_INET;
+  if(!strcmp(name,"*"))
+  {
+    addr->sin_addr.s_addr=htonl(INADDR_ANY);
+  }
+  else if(name[0]>='0' && name[0]<='9')
+  {
+    if (inet_addr(name) == -1)
+      error("Malformed ip number.\n");
+
+    addr->sin_addr.s_addr = inet_addr(name);
+  }
+  else
+  {
+    struct hostent *ret;
+    ret=gethostbyname(name);
+    if(!ret)
+      error("Invalid address '%s'\n",name);
+
+    MEMCPY((char *)&(addr->sin_addr),
+	   (char *)ret->h_addr_list[0],
+	   ret->h_length);
+  }
+}
+
 static void file_query_address(INT32 args)
 {
   struct sockaddr_in addr;
diff --git a/src/modules/files/file.h b/src/modules/files/file.h
index 0bf159ecef..2fda74eb79 100644
--- a/src/modules/files/file.h
+++ b/src/modules/files/file.h
@@ -1,6 +1,17 @@
 #ifndef FILE_H
 #define FILE_H
 
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+
+#ifdef HAVE_ARPA_INET_H
+#ifndef ARPA_INET_H
+#include <arpa/inet.h>
+#define ARPA_INET_H
+#endif
+#endif
+
 struct file
 {
   int fd;
@@ -13,7 +24,7 @@ struct file
 
 /* Prototypes begin here */
 struct object *file_make_object_from_fd(int fd, int mode);
-void file_setbuf(int fd, int bufcmd);
+void get_inet_addr(struct sockaddr_in *addr,char *name);
 void exit_files();
 void init_files_programs();
 /* Prototypes end here */
diff --git a/src/modules/files/socket.c b/src/modules/files/socket.c
index 7f9ddd1542..fd396d552a 100644
--- a/src/modules/files/socket.c
+++ b/src/modules/files/socket.c
@@ -20,15 +20,6 @@
 #include <sys/wait.h>
 #include <sys/socket.h>
 
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-
-#ifndef ARPA_INET_H
-#include <arpa/inet.h>
-#define ARPA_INET_H
-#endif
-
 #ifdef HAVE_SYS_SOCKETVAR_H
 #include <sys/socketvar.h>
 #endif
@@ -172,30 +163,21 @@ static void port_bind(INT32 args)
     push_int(0);
     return;
   }
-
   set_close_on_exec(fd,1);
-
-
-  MEMSET((char *)&addr,0,sizeof(addr));
-
-  addr.sin_family = AF_INET;
-  addr.sin_port = htons( ((u_short)sp[-args].u.integer) );
-
+  
   if(args > 2 && sp[2-args].type==T_STRING)
   {
-    if (inet_addr(sp[2-args].u.string->str) == -1)
-      error("Malformed ip number.\n");
-
-    addr.sin_addr.s_addr = inet_addr(sp[2-args].u.string->str);
+    get_inet_addr(&addr, sp[2-args].u.string->str);
   }else{
     addr.sin_addr.s_addr = htonl(INADDR_ANY);
   }
-  
+
+  addr.sin_port = htons( ((u_short)sp[-args].u.integer) );
+
   if(bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0 ||
      listen(fd, 16384) < 0 )
   {
     THIS->errno=errno;
-    printf("Error opening socket: %s\n", strerror(errno));
     close(fd);
     pop_n_elems(args);
     push_int(0);
@@ -254,7 +236,7 @@ extern struct program *file_program;
 
 static void port_accept(INT32 args)
 {
-  int fd, tmp;
+  int fd,tmp;
   int len=0;
   struct object *o;
 
@@ -277,7 +259,7 @@ static void port_accept(INT32 args)
     close(fd);
     return;
   }
-  
+
   tmp=1;
   setsockopt(fd,SOL_SOCKET, SO_KEEPALIVE, (char *)&tmp, sizeof(tmp));
 
diff --git a/src/port.c b/src/port.c
index d1cc4c628b..5d4ae22ddc 100644
--- a/src/port.c
+++ b/src/port.c
@@ -596,629 +596,3 @@ INT32 EXTRACT_INT(unsigned char *p)
   return a;
 }
 #endif
-#if 0
-#include "global.h"
-#include "macros.h"
-#include <ctype.h>
-#include <math.h>
-#include <sys/types.h>
-#include <errno.h>
-#include <float.h>
-#include <string.h>
-
-#ifdef sun
-time_t time PROT((time_t *));
-#endif
-
-/*
- * This file defines things that may have to be changem when porting
- * LPmud to new environments. Hopefully, there are #ifdef's that will take
- * care of everything.
- */
-
-static unsigned long RandSeed1 = 0x5c2582a4;
-static unsigned long RandSeed2 = 0x64dff8ca;
-
-unsigned long my_rand(void)
-{
-  RandSeed1 = ((RandSeed1 * 13 + 1) ^ (RandSeed1 >> 9)) + RandSeed2;
-  RandSeed2 = (RandSeed2 * RandSeed1 + 13) ^ (RandSeed2 >> 13);
-  return RandSeed1;
-}
-
-void my_srand(int seed)
-{
-  RandSeed1 = (seed - 1) ^ 0xA5B96384;
-  RandSeed2 = (seed + 1) ^ 0x56F04021;
-  my_rand();
-  my_rand();
-  my_rand();
-}
-
-long get_current_time(void) { return (long)time(0L); }
-
-
-
-#ifndef HAVE_STRTOL
-#define DIGIT(x)	(isdigit(x) ? (x) - '0' : \
-			islower(x) ? (x) + 10 - 'a' : (x) + 10 - 'A')
-#define MBASE	('z' - 'a' + 1 + 10)
-
-long STRTOL(char *str,char **ptr,int base)
-{
-  register long val;
-  register int c;
-  int xx, neg = 0;
-
-  if (ptr != (char **)0)
-    *ptr = str;			/* in case no number is formed */
-  if (base < 0 || base > MBASE)
-    return (0);			/* base is invalid -- should be a fatal error */
-  if (!isalnum(c = *str)) {
-    while (isspace(c))
-      c = *++str;
-    switch (c) {
-    case '-':
-      neg++;
-    case '+':			/* fall-through */
-      c = *++str;
-    }
-  }
-  if (base == 0)
-    if (c != '0')
-      base = 10;
-    else if (str[1] == 'x' || str[1] == 'X')
-      base = 16;
-    else
-      base = 8;
-  /*
-   * for any base > 10, the digits incrementally following
-   *	9 are assumed to be "abc...z" or "ABC...Z"
-   */
-  if (!isalnum(c) || (xx = DIGIT(c)) >= base)
-    return (0);			/* no number formed */
-  if (base == 16 && c == '0' && isxdigit(str[2]) &&
-      (str[1] == 'x' || str[1] == 'X'))
-    c = *(str += 2);		/* skip over leading "0x" or "0X" */
-  for (val = -DIGIT(c); isalnum(c = *++str) && (xx = DIGIT(c)) < base; )
-    /* accumulate neg avoids surprises near MAXLONG */
-    val = base * val - xx;
-  if (ptr != (char **)0)
-    *ptr = str;
-  return (neg ? val : -val);
-}
-#endif
-
-#ifndef HAVE_MEMSET
-char *MEMSET(char *s,int c,int n)
-{
-  char *t;
-  for(t=s;n;n--) *(s++)=c;
-  return s;
-}
-#endif
-
-#if !defined(HAVE_MEMCPY) && !defined(HAVE_BCOPY)
-char *MEMCPY(char *b,const char *a,int s)
-{
-  char *t;
-  for(t=b;s;s--) *(t++)=*(a++);
-  return b;
-}
-#endif
-
-#ifndef HAVE_MEMMOVE
-char *MEMMOVE(char *b,const char *a,int s)
-{
-  char *t;
-  if(a>b) for(t=b;s;s--) *(t++)=*(a++);
-  if(a<b) for(t=b+s,a+=s;s;s--) *(--t)=*(--a);
-  return b;
-}
-#endif
-
-
-#ifndef HAVE_MEMCMP
-int MEMCMP(const char *b,const char *a,int s)
-{
-  for(;s;s--,b++,a++)
-  {
-    if(*b!=*a)
-    {
-      if(*b<*a) return -1;
-      if(*b>*a) return 1;
-    }
-  }
-  return 0;
-}
-
-#endif
-
-#ifndef HAVE_MEMCHR
-char *MEMCHR(char *p,char c,int e)
-{
-  e++;
-  while(--e >= 0) if(*(p++)==c) return p-1;
-  return (char *)0;
-}
-#endif
-
-#ifndef HAVE_MEMMEM
-#if 1
-char *MEMMEM(char *needle, SIZE_T needlelen, char *haystack,
-	     SIZE_T haystacklen)
-{
-  if(needlelen>haystacklen)
-    return 0;
-  switch(needlelen)
-  {
-  case 0: return haystack;
-  case 1: return MEMCHR(haystack,needle[0],haystacklen);
-  default:
-  {
-    SIZE_T i, j;
-    for(i=0; i <= haystacklen-needlelen; i++)
-    {
-      for(j=0; j<needlelen; j++)
-	if(haystack[i + j] != needle[j])
-	  break;
-      if(j==needlelen)
-	return haystack+i;
-    }
-    return 0;
-  }
- }
-}
-#else 
-/*
- * a quick memmem
- * Written by Fredrik Hubinette (hubbe@lysator.liu.se)
- */
-
-#define LINKS 1024
-
-typedef struct link2_s
-{
-  struct link2_s *next;
-  INT32 key, offset;
-} link2;
-
-char *MEMMEM(char *needle, SIZE_T needlelen, char *haystack, 
-	     SIZE_T haystacklen)
-{
-  if(needlelen > haystacklen) return 0;
-
-  switch(needlelen)
-  {
-  case 0: return haystack;
-  case 1: return MEMCHR(haystack,needle[0],haystacklen);
-
-  default:
-  {
-    if(haystacklen > needlelen + 64)
-    {
-      static link2 links[LINKS], *set[LINKS];
-
-      INT32 tmp, h;
-      unsigned INT32 hsize, e, max;
-      char *q, *end;
-      link2 *ptr;
-
-      hsize=52+(haystacklen >> 7)  - (needlelen >> 8);
-      max  =13+(haystacklen >> 4)  - (needlelen >> 5);
-
-      if(hsize > NELEM(set))
-      {
-	hsize=NELEM(set);
-      }else{
-	for(e=8;e<hsize;e+=e);
-	hsize=e;
-      }
-    
-      for(e=0;e<hsize;e++) set[e]=0;
-      hsize--;
-
-      if(max > needlelen) max=needlelen;
-      max=(max-sizeof(INT32)+1) & -sizeof(INT32);
-      if(max > LINKS) max=LINKS;
-
-      ptr=&links[0];
-
-      q=needle;
-
-#if BYTEORDER == 4321
-      for(tmp=e=0;e<sizeof(INT32)-1;e++)
-      {
-	tmp<<=8;
-	tmp|=*(q++);
-      }
-#endif
-
-      for(e=0;e<max;e++)
-      {
-#if BYTEORDER == 4321
-	tmp<<=8;
-	tmp|=*(q++);
-#else
-	tmp=EXTRACT_INT((unsigned char *)q);
-	q++;
-#endif
-	h=tmp;
-	h+=h>>7;
-	h+=h>>17;
-	h&=hsize;
-
-	ptr->offset=e;
-	ptr->key=tmp;
-	ptr->next=set[h];
-	set[h]=ptr;
-	ptr++;
-      }
-
-      end=haystack+haystacklen+1;
-    
-      q=haystack+max-sizeof(INT32);
-      q=(char *)( ((long)q) & -sizeof(INT32));
-      for(;q<end-sizeof(INT32)+1;q+=max)
-      {
-	h=tmp=*(INT32 *)q;
-
-	h+=h>>7;
-	h+=h>>17;
-	h&=hsize;
-      
-	for(ptr=set[h];ptr;ptr=ptr->next)
-	{
-	  char *where;
-
-	  if(ptr->key != tmp) continue;
-
-	  where=q-ptr->offset;
-	  if(where<haystack) continue;
-	  if(where+needlelen>end) return 0;
-
-	  if(!MEMCMP(where,needle,needlelen))
-	    return where;
-	}
-      }
-      return 0;
-    }
-  }
-
-  case 2:
-  case 3:
-  case 4:
-  case 5:
-  case 6: 
-  {
-    char *end,c;
-  
-    end=haystack+haystacklen-needlelen+1;
-    c=needle[0];
-    needle++;
-    needlelen--;
-    while((haystack=MEMCHR(haystack,c,end-haystack)))
-      if(!MEMCMP(++haystack,needle,needlelen))
-	return haystack-1;
-
-    return 0;
-  }
-    
-  }
-}
-#endif
-#endif
-
-#if !defined(HAVE_INDEX) && !defined(HAVE_STRCHR)
-char *STRCHR(char *s,char c)
-{
-  for(;*s;s++) if(*s==c) return s;
-  return NULL;
-}
-#endif
-
-#if !defined(HAVE_RINDEX) && !defined(HAVE_STRRCHR)
-char *STRRCHR(char *s,int c)
-{
-  char *p;
-  for(p=NULL;*s;s++) if(*s==c) p=s;
-  return p;
-}
-#endif
-
-#ifndef HAVE_STRSTR
-char *STRSTR(char *s1,const char *s2)
-{
-  for(;*s1;s1++)
-  {
-    const char *p1,*p2;
-    for(p1=s1,p2=s2;*p1==*p2;p1++,p2++) if(!*p2) return s1;
-  }
-  return NULL;
-}
-#endif
-
-#ifndef HAVE_STRTOK
-static char *temporary_for_strtok;
-char *STRTOK(char *s1,char *s2)
-{
-  if(s1!=NULL) temporary_for_strtok=s1;
-  for(s1=temporary_for_strtok;*s1;s1++)
-  {
-    char *p1,*p2;
-    for(p1=s1,p2=s2;*p1==*p2;p1++,p2++)
-    {
-      if(!*(p2+1))
-      {
-        char *retval;
-        *s1=0;
-        retval=temporary_for_strtok;
-        temporary_for_strtok=p1+1;
-        return(retval);
-      }
-    }
-  }
-  return NULL;
-}
-#endif
-
-#ifndef HAVE_STRTOD
-/* Convert NPTR to a double.  If ENDPTR is not NULL, a pointer to the
-   character after the last one used in the number is put in *ENDPTR.  */
-double STRTOD(char * nptr, char **endptr)
-{
-  register char *s;
-  short int sign;
-
-  /* The number so far.  */
-  double num;
-
-  int got_dot;      /* Found a decimal point.  */
-  int got_digit;    /* Seen any digits.  */
-
-  /* The exponent of the number.  */
-  long int exponent;
-
-  if (nptr == NULL)
-  {
-    errno = EINVAL;
-    goto noconv;
-  }
-
-  s = nptr;
-
-  /* Eat whitespace.  */
-  while (isspace(*s)) ++s;
-
-  /* Get the sign.  */
-  sign = *s == '-' ? -1 : 1;
-  if (*s == '-' || *s == '+')
-    ++s;
-
-  /* Get the sign.  */
-  sign = *s == '-' ? -1 : 1;
-  if (*s == '-' || *s == '+')
-    ++s;
-
-  num = 0.0;
-  got_dot = 0;
-  got_digit = 0;
-  exponent = 0;
-  for (;; ++s)
-  {
-    if (isdigit (*s))
-    {
-      got_digit = 1;
-
-      /* Make sure that multiplication by 10 will not overflow.  */
-      if (num > DBL_MAX * 0.1)
-	/* The value of the digit doesn't matter, since we have already
-	   gotten as many digits as can be represented in a `double'.
-	   This doesn't necessarily mean the result will overflow.
-	   The exponent may reduce it to within range.
-	   
-	   We just need to record that there was another
-	   digit so that we can multiply by 10 later.  */
-	++exponent;
-      else
-	num = (num * 10.0) + (*s - '0');
-
-      /* Keep track of the number of digits after the decimal point.
-	 If we just divided by 10 here, we would lose precision.  */
-      if (got_dot)
-	--exponent;
-    }
-    else if (!got_dot && (char) *s == '.')
-      /* Record that we have found the decimal point.  */
-      got_dot = 1;
-    else
-      /* Any other character terminates the number.  */
-      break;
-  }
-
-  if (!got_digit)
-    goto noconv;
-
-  if (tolower(*s) == 'e')
-    {
-      /* Get the exponent specified after the `e' or `E'.  */
-      int save = errno;
-      char *end;
-      long int exp;
-
-      errno = 0;
-      ++s;
-      exp = STRTOL(s, &end, 10);
-      if (errno == ERANGE)
-      {
-	/* The exponent overflowed a `long int'.  It is probably a safe
-	   assumption that an exponent that cannot be represented by
-	   a `long int' exceeds the limits of a `double'.  */
-	if (endptr != NULL)
-	  *endptr = end;
-	if (exp < 0)
-	  goto underflow;
-	else
-	  goto overflow;
-      }
-      else if (end == s)
-	/* There was no exponent.  Reset END to point to
-	   the 'e' or 'E', so *ENDPTR will be set there.  */
-	end = (char *) s - 1;
-      errno = save;
-      s = end;
-      exponent += exp;
-    }
-
-  if (endptr != NULL)
-    *endptr = (char *) s;
-
-  if (num == 0.0)
-    return 0.0;
-
-  /* Multiply NUM by 10 to the EXPONENT power,
-     checking for overflow and underflow.  */
-
-  if (exponent < 0)
-  {
-    if (num < DBL_MIN * pow(10.0, (double) -exponent))
-      goto underflow;
-  }
-  else if (exponent > 0)
-  {
-    if (num > DBL_MAX * pow(10.0, (double) -exponent))
-      goto overflow;
-  }
-
-  num *= pow(10.0, (double) exponent);
-
-  return num * sign;
-
- overflow:
-  /* Return an overflow error.  */
-  errno = ERANGE;
-  return HUGE * sign;
-
- underflow:
-  /* Return an underflow error.  */
-  if (endptr != NULL)
-    *endptr = (char *) nptr;
-  errno = ERANGE;
-  return 0.0;
-  
- noconv:
-  /* There was no number.  */
-  if (endptr != NULL)
-    *endptr = (char *) nptr;
-  return 0.0;
-}
-#endif
-
-#ifndef HAVE_VSPRINTF
-int VSPRINTF(char *buf,char *fmt,va_list args)
-{
-  char *b=buf;
-  char *s;
-
-  int tmpA;
-  char fmt2[120];
-  char *fmt2p;
-
-  fmt2[0]='%';
-  for(;(s=STRCHR(fmt,'%'));fmt=s)
-  {
-    MEMCPY(buf,fmt,s-fmt);
-    buf+=s-fmt;
-    fmt=s;
-    fmt2p=fmt2+1;
-    s++;
-  unknown_character:
-    switch((*(fmt2p++)=*(s++)))
-    {
-    default:
-      goto unknown_character;
-
-    case '*':
-      fmt2p--;
-      sprintf(fmt2p,"%d",va_arg(args,int));
-      fmt2p+=strlen(fmt2p);
-      goto unknown_character;
-
-    case 0:
-      fatal("Error in vsprintf format.\n");
-      return 0;
-
-    case '%':
-      *(buf++)='%';
-      break;
-
-    case 'p':
-    case 's':
-      *fmt2p=0;
-      sprintf(buf,fmt2,va_arg(args,char *));
-      buf+=strlen(buf);
-      break;
-
-    case 'd':
-    case 'c':
-    case 'x':
-    case 'X':
-      *fmt2p=0;
-      sprintf(buf,fmt2,va_arg(args,int));
-      buf+=strlen(buf);
-      break;
-
-    case 'f':
-    case 'e':
-    case 'E':
-    case 'g':
-      *fmt2p=0;
-      sprintf(buf,fmt2,va_arg(args,FLOAT_TYPE));
-      buf+=strlen(buf);
-      break;
-    }
-  }
-  tmpA=strlen(fmt);
-  MEMCPY(buf,fmt,tmpA);
-  buf+=tmpA;
-  *buf=0;
-  return buf-b;
-}
-#endif
-
-#ifndef HAVE_VFPRINTF
-int VFPRINTF(FILE *f,char *s,va_list args)
-{
-  int i;
-  char buffer[10000];
-  VSPRINTF(buffer,s,args);
-  i=strlen(buffer);
-  if(i+1>sizeof(buffer))
-    fatal("Buffer overflow.\n");
-  return fwrite(buffer,i,1,f);
-}
-#endif
-
-#if defined(DEBUG) && !defined(HANDLES_UNALIGNED_MEMORY_ACCESS)
-unsigned INT16 EXTRACT_UWORD(unsigned char *p)
-{
-  unsigned INT16 a;
-  MEMCPY((char *)&a,p,sizeof(a));
-  return a;
-}
-
-INT16 EXTRACT_WORD(unsigned char *p)
-{
-  INT16 a;
-  MEMCPY((char *)&a,p,sizeof(a));
-  return a;
-}
-
-INT32 EXTRACT_INT(unsigned char *p)
-{
-  INT32 a;
-  MEMCPY((char *)&a,p,sizeof(a));
-  return a;
-}
-#endif
-#endif
diff --git a/src/program.c b/src/program.c
index b103d1e505..22106185b2 100644
--- a/src/program.c
+++ b/src/program.c
@@ -965,7 +965,7 @@ char *get_line(unsigned char *pc,struct program *prog,INT32 *linep)
 
 #ifdef DEBUG
   if (offset > (INT32)prog->program_size || offset<0)
-    fatal("Illegal offset %ld in program.\n", offset);
+    fatal("Illegal offset %ld in program.\n", (long)offset);
 #endif
 
   cnt=prog->linenumbers;
-- 
GitLab