xref: /csrg-svn/contrib/dungeon/rtim.c (revision 35973)
1*35973Sbostic /*
2*35973Sbostic  * Interface routines for dungeon.
3*35973Sbostic  * These routines are for functions expected by the game
4*35973Sbostic  * that are not available in the Unix/f77 library.
5*35973Sbostic  */
6*35973Sbostic 
7*35973Sbostic #ifdef SYSV
8*35973Sbostic #include <stdio.h>
9*35973Sbostic #endif
10*35973Sbostic 
11*35973Sbostic #include <sys/types.h>
12*35973Sbostic 
13*35973Sbostic #ifdef SYSV
14*35973Sbostic #include <time.h>
15*35973Sbostic #else
16*35973Sbostic #include <sys/timeb.h>
17*35973Sbostic #include <sys/time.h>
18*35973Sbostic #endif
19*35973Sbostic 
20*35973Sbostic /* routine to get time in hours minutes and seconds */
21*35973Sbostic 
22*35973Sbostic long time();
23*35973Sbostic struct tm *localtime();
24*35973Sbostic struct tm *tmptr;
25*35973Sbostic long timebuf;
26*35973Sbostic 
itime_(hrptr,minptr,secptr)27*35973Sbostic itime_(hrptr,minptr,secptr)
28*35973Sbostic 
29*35973Sbostic int *hrptr,*minptr,*secptr;
30*35973Sbostic {
31*35973Sbostic 
32*35973Sbostic 	time(&timebuf);
33*35973Sbostic 	tmptr = localtime(&timebuf);
34*35973Sbostic 
35*35973Sbostic 	*hrptr  = tmptr->tm_hour;
36*35973Sbostic 	*minptr = tmptr->tm_min;
37*35973Sbostic 	*secptr = tmptr->tm_sec;
38*35973Sbostic 
39*35973Sbostic 	return;
40*35973Sbostic }
41*35973Sbostic 
42*35973Sbostic #ifdef SYSV
43*35973Sbostic /* idate - return day (1-31), month (1-12) and year (AD) */
44*35973Sbostic /*	by Dave Newkirk, ihnp4!ihlpm!dcn */
45*35973Sbostic 
idate_(date)46*35973Sbostic idate_( date )
47*35973Sbostic long date[];
48*35973Sbostic {
49*35973Sbostic 	struct tm *t, *localtime();
50*35973Sbostic 	long time(), *tloc, loc;
51*35973Sbostic 
52*35973Sbostic 	tloc = &loc;			/* get pointer to time in seconds */
53*35973Sbostic 	time(tloc);
54*35973Sbostic 	t = localtime(tloc);		/* get time structure filled in */
55*35973Sbostic 	date[0] = t->tm_mday;
56*35973Sbostic 	date[1] = t->tm_mon + 1;
57*35973Sbostic 	date[2] = t->tm_year + 1900;
58*35973Sbostic 
59*35973Sbostic } /* end idate */
60*35973Sbostic #endif
61*35973Sbostic 
62*35973Sbostic /* random number initializer */
inirnd_(seedptr)63*35973Sbostic inirnd_(seedptr)
64*35973Sbostic 
65*35973Sbostic int *seedptr;
66*35973Sbostic {
67*35973Sbostic int seed;
68*35973Sbostic 
69*35973Sbostic 	seed = *seedptr;
70*35973Sbostic 	srand(seed);
71*35973Sbostic 	return;
72*35973Sbostic }
73*35973Sbostic 
74*35973Sbostic /*  random number generator */
rnd_(maxval)75*35973Sbostic rnd_(maxval)
76*35973Sbostic 
77*35973Sbostic int *maxval;
78*35973Sbostic {
79*35973Sbostic /* note: returned random number ranges from 0 to maxval */
80*35973Sbostic 
81*35973Sbostic int rndval;
82*35973Sbostic 
83*35973Sbostic 	rndval = rand();
84*35973Sbostic 
85*35973Sbostic 	rndval = rndval % *maxval;
86*35973Sbostic 
87*35973Sbostic 	return(rndval);
88*35973Sbostic }
89*35973Sbostic 
90*35973Sbostic #ifdef SYSV
91*35973Sbostic /* thanks to Dave Newkirk, ihnp4!ihlpm!dcn for the following routines */
92*35973Sbostic 
93*35973Sbostic /* getuid - fortran callable getuid */
94*35973Sbostic 
95*35973Sbostic int
getuid_()96*35973Sbostic getuid_()
97*35973Sbostic {
98*35973Sbostic 	return (int)getuid();
99*35973Sbostic }
100*35973Sbostic 
101*35973Sbostic /* unbuf - make output completely unbuffered */
102*35973Sbostic 
unbuf_()103*35973Sbostic unbuf_()
104*35973Sbostic {
105*35973Sbostic 	void setbuf();
106*35973Sbostic 
107*35973Sbostic 	setbuf(stdout, NULL);
108*35973Sbostic }
109*35973Sbostic #endif
110