From 23f2dbe81467d28e2f45d14bd5c4ce19229f69e3 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Thu, 18 May 2017 17:18:16 -0400 Subject: [PATCH] Replace fDATIME with ANSI/POSIX clock_gettime(). Rip out DOS/AMIGA shims. 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 | 2 +- datime.c | 50 -------------------------------------------------- init.c | 4 ---- main.c | 3 --- misc.c | 4 ---- misc.h | 11 ++++------- 6 files changed, 5 insertions(+), 69 deletions(-) delete mode 100644 datime.c diff --git a/Makefile b/Makefile index efd039f..8565755 100644 --- 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 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 50a21b1..f8d8726 100644 --- 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 e0887e9..54b33da 100644 --- 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 626bd40..18b0e6c 100644 --- 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 6654ea9..7d7958d 100644 --- a/misc.h +++ b/misc.h @@ -1,10 +1,8 @@ -#ifdef __MSDOS__ /* define fopen modes for binary files */ +#include + +/* 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); -- 2.31.1