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.
This commit is contained in:
Eric S. Raymond 2017-05-18 17:18:16 -04:00
parent bd0487acc5
commit 23f2dbe814
6 changed files with 5 additions and 69 deletions

View file

@ -1,6 +1,6 @@
# Makefile for the open-source release of adventure 2.5 # 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 SOURCES=$(OBJS:.o=.c) COPYING NEWS README advent.text control
.c.o: .c.o:

View file

@ -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

4
init.c
View file

@ -641,14 +641,10 @@ static void quick_item(long*);
static void quick_array(long*, long); static void quick_array(long*, long);
static bool quick_init(void) { static bool quick_init(void) {
#ifdef AMIGA
f = fopen("ram:adventure.data", READ_MODE);
#else
extern char *getenv(); extern char *getenv();
char *adv = getenv("ADVENTURE"); char *adv = getenv("ADVENTURE");
f = NULL; f = NULL;
if(adv)f = fopen(adv,READ_MODE); if(adv)f = fopen(adv,READ_MODE);
#endif
if(f == NULL)f = fopen("adventure.data",READ_MODE); if(f == NULL)f = fopen("adventure.data",READ_MODE);
if(f == NULL)return(FALSE); if(f == NULL)return(FALSE);
init_reading = TRUE; init_reading = TRUE;

3
main.c
View file

@ -8,9 +8,6 @@
#include "main.h" #include "main.h"
#include "misc.h" #include "misc.h"
#ifdef __MSDOS__
#include "alloc.h"
#endif
#define TRUE (0==0) #define TRUE (0==0)
#define FALSE (0!=0) #define FALSE (0!=0)

4
misc.c
View file

@ -898,10 +898,6 @@ long I, VAL; static FILE *OPENED = NULL;
goto L20; goto L20;
L15: if(!OPENED){ L15: if(!OPENED){
#ifdef AMIGA
OPENED=fopen("ram:adventure.text","r" /* NOT binary */);
if(!OPENED)
#endif
OPENED=fopen("adventure.text","r" /* NOT binary */); OPENED=fopen("adventure.text","r" /* NOT binary */);
if(!OPENED){printf("Can't read adventure.text!\n"); exit(FALSE);} if(!OPENED){printf("Can't read adventure.text!\n"); exit(FALSE);}
} }

11
misc.h
View file

@ -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 READ_MODE "rb"
#define WRITE_MODE "wb" #define WRITE_MODE "wb"
#else
#define READ_MODE "r"
#define WRITE_MODE "w"
#endif
extern void fSPEAK(long); extern void fSPEAK(long);
#define SPEAK(N) fSPEAK(N) #define SPEAK(N) fSPEAK(N)
@ -70,8 +68,7 @@ extern void fMPINIT();
#define MPINIT() fMPINIT() #define MPINIT() fMPINIT()
extern void fSAVEIO(long,long,long*); extern void fSAVEIO(long,long,long*);
#define SAVEIO(OP,IN,ARR) fSAVEIO(OP,IN,ARR) #define SAVEIO(OP,IN,ARR) fSAVEIO(OP,IN,ARR)
extern void fDATIME(long*,long*); #define DATIME(D,T) do {struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts); D=ts.tv_sec, T=ts.tv_nsec;} while (0)
#define DATIME(D,T) fDATIME(&D,&T)
extern long fIABS(long); extern long fIABS(long);
#define IABS(N) fIABS(N) #define IABS(N) fIABS(N)
extern long fMOD(long,long); extern long fMOD(long,long);