Replace fDATIME with ANSI/POSIX clock_gettime(). Rip out DOS/AMIGA shims.
authorEric S. Raymond <esr@thyrsus.com>
Thu, 18 May 2017 21:18:16 +0000 (17:18 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 18 May 2017 21:18:16 +0000 (17:18 -0400)
The thinking here is that we simplify life by going pure ANSI/POSIX.
This is a text game.  If it ever runs on anything but Unix again it's
almost certain to be on something like WSL that supplies a
POSIX-conformant text console.

Makefile
datime.c [deleted file]
init.c
main.c
misc.c
misc.h

index efd039fac2598340845e715b296692ffcbdf317e..856575580fcd0898df9d09706bb90800047f62dc 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 # Makefile for the open-source release of adventure 2.5
 
-OBJS=main.o init.o actions1.o actions2.o score.o misc.o datime.o
+OBJS=main.o init.o actions1.o actions2.o score.o misc.o
 SOURCES=$(OBJS:.o=.c) COPYING NEWS README advent.text control
 
 .c.o:
diff --git a/datime.c b/datime.c
deleted file mode 100644 (file)
index c0090e9..0000000
--- a/datime.c
+++ /dev/null
@@ -1,50 +0,0 @@
-#ifdef AMIGA
-#define _TIME_
-#include "exec/types.h"
-#include "intuition/intuition.h"
-
-#define INTUITIONREV 1
-
-struct IntuitionBase *IntuitionBase = NULL;
-
-fDATIME(X,Y)int *X, *Y; {
-static int GOTX = 0, GOTY;
-       if(GOTX == 0) {
-               IntuitionBase = (struct IntuitionBase *)
-                       OpenLibrary("intuition.library", INTUITIONREV);
-               if (IntuitionBase == NULL) {
-                       printf("Can't open library.\n");
-                       exit(FALSE);
-                       }
-               CurrentTime(&GOTX, &GOTY);
-               CloseLibrary(IntuitionBase);
-               }
-       GOTY += 654321;
-       if(GOTY >= 1000000) {GOTX += 1; GOTY -= 1000000;}
-       *X = GOTX;
-       *Y = GOTY;
-}
-#endif
-
-#ifdef __MSDOS__
-#define _TIME_
-#include "time.h"
-
-fDATIME(long *X,long *Y) {
-       time(X); time(Y);
-       *Y /= 2;
-       /* it would be even better if the two numbers were totally
-        * unrelated, like if 'time' returned 64 bits of data */
-}
-#endif
-
-#ifndef _TIME_
-#include "sys/time.h"
-
-void fDATIME(long *X, long *Y) {
-       struct timeval now;
-       gettimeofday(&now, 0);
-       *X = now.tv_sec;
-       *Y = now.tv_usec;
-}
-#endif
diff --git a/init.c b/init.c
index 50a21b1d935a7ac6bdc2580f9eec80c127e0ac1e..f8d8726e6bd7f55cdb30142cfbd39c331cd481f2 100644 (file)
--- a/init.c
+++ b/init.c
@@ -641,14 +641,10 @@ static void quick_item(long*);
 static void quick_array(long*, long);
 
 static bool quick_init(void) {
-#ifdef AMIGA
-       f = fopen("ram:adventure.data", READ_MODE);
-#else
        extern char *getenv();
        char *adv = getenv("ADVENTURE");
        f = NULL;
        if(adv)f = fopen(adv,READ_MODE);
-#endif
        if(f == NULL)f = fopen("adventure.data",READ_MODE);
        if(f == NULL)return(FALSE);
        init_reading = TRUE;
diff --git a/main.c b/main.c
index e0887e94c953b407232755f5640ad78fb9139dd9..54b33da625cc88a63c8085b4c0a27518fe3b538b 100644 (file)
--- a/main.c
+++ b/main.c
@@ -8,9 +8,6 @@
 #include "main.h"
 
 #include "misc.h"
-#ifdef __MSDOS__
-#include "alloc.h"
-#endif
 
 #define TRUE  (0==0)
 #define FALSE (0!=0)
diff --git a/misc.c b/misc.c
index 626bd40d926b8f5b3a0716a366539b80332f6500..18b0e6c20fa41a023991f4c3ff50a68c1c26508d 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -898,10 +898,6 @@ long I, VAL; static FILE *OPENED = NULL;
         goto L20;
 
 L15:   if(!OPENED){
-#ifdef AMIGA
-               OPENED=fopen("ram:adventure.text","r" /* NOT binary */);
-               if(!OPENED)
-#endif
                OPENED=fopen("adventure.text","r" /* NOT binary */);
                if(!OPENED){printf("Can't read adventure.text!\n"); exit(FALSE);}
                }
diff --git a/misc.h b/misc.h
index 6654ea95983b09f2a05ebcee8183ddd1e12ef948..7d7958da64930e0860dd08c73d8f788fd3119504 100644 (file)
--- a/misc.h
+++ b/misc.h
@@ -1,10 +1,8 @@
-#ifdef __MSDOS__       /* define fopen modes for binary files */
+#include <time.h>
+
+/* b is not needed for POSIX but harmless */
 #define READ_MODE "rb"
 #define WRITE_MODE "wb"
-#else
-#define READ_MODE "r"
-#define WRITE_MODE "w"
-#endif
 
 extern void fSPEAK(long);
 #define SPEAK(N) fSPEAK(N)
@@ -70,8 +68,7 @@ extern void fMPINIT();
 #define MPINIT() fMPINIT()
 extern void fSAVEIO(long,long,long*);
 #define SAVEIO(OP,IN,ARR) fSAVEIO(OP,IN,ARR)
-extern void fDATIME(long*,long*);
-#define DATIME(D,T) fDATIME(&D,&T)
+#define DATIME(D,T) do {struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts); D=ts.tv_sec, T=ts.tv_nsec;} while (0)
 extern long fIABS(long);
 #define IABS(N) fIABS(N)
 extern long fMOD(long,long);