-
Notifications
You must be signed in to change notification settings - Fork 2
/
SUPP.C
230 lines (177 loc) · 4.57 KB
/
SUPP.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/* supp.c -- support routines for dungeon */
#include <stdio.h>
#ifdef unix
#include <sys/types.h>
#endif
#ifdef BSD4_2
#include <sys/time.h>
#else /* ! BSD4_2 */
#include <time.h>
#endif /* ! BSD4_2 */
#include "funcs.h"
/* Define these here to avoid using <stdlib.h> */
extern void exit P((int));
extern int rand P((void));
/* We should have a definition for time_t and struct tm by now. Make
* sure we have definitions for the functions we want to call.
* The argument to localtime should be P((const time_t *)), but Ultrix
* 4.0 leaves out the const in their prototype. Damn them.
*/
extern time_t time P((time_t *));
extern struct tm *localtime ();
/* Terminate the game */
void exit_()
{
fprintf(stderr, "The game is over.\n");
exit(0);
}
/* Get time in hours, minutes and seconds */
void itime_(hrptr, minptr, secptr)
integer *hrptr;
integer *minptr;
integer *secptr;
{
time_t timebuf;
struct tm *tmptr;
time(&timebuf);
tmptr = localtime(&timebuf);
*hrptr = tmptr->tm_hour;
*minptr = tmptr->tm_min;
*secptr = tmptr->tm_sec;
}
/* Random number generator */
integer rnd_(maxval)
integer maxval;
{
return rand() % maxval;
}
/* Terminal support routines for dungeon */
/* By Ian Lance Taylor [email protected] or uunet!airs!ian */
/* The dungeon game can often output long strings, more than enough
* to overwhelm a typical 24 row terminal (I assume that back when
* dungeon was written people generally used paper terminals (I know
* I did) so this was not a problem). The functions in this file
* provide a very simplistic ``more'' facility. They are necessarily
* somewhat operating system dependent, although I have tried to
* minimize it as much as I could.
*/
/* The following macro definitions may be used to control how these
* functions work:
*
* MORE_NONE Don't use the more facility at all
* MORE_24 Always assume a 24 row terminal
* MORE_TERMCAP Use termcap routines to get rows of terminal
* MORE_TERMINFO Use terminfo routines to get rows of terminal
* MORE_AMOS Use AMOS monitor calls to get rows of terminal
*
* If none of these are defined then this will use termcap routines on
* unix and AMOS routines on AMOS.
*/
#ifndef MORE_NONE
#ifndef MORE_24
#ifndef MORE_TERMCAP
#ifndef MORE_TERMINFO
#ifndef MORE_AMOS
#ifdef __AMOS__
#define MORE_AMOS
#else /* ! __AMOS__ */
#ifdef unix
#define MORE_TERMCAP
#else /* ! unix */
#define MORE_NONE
#endif /* ! unix */
#endif /* ! __AMOS__ */
#endif /* ! MORE_AMOS */
#endif /* ! MORE_TERMINFO */
#endif /* ! MORE_TERMCAP */
#endif /* ! MORE_24 */
#endif /* ! MORE_NONE */
#ifdef MORE_TERMCAP
extern char *getenv P((const char *));
extern void tgetent P((char *, const char *));
extern int tgetnum P((const char *));
#else /* ! MORE_TERMCAP */
#ifdef MORE_TERMINFO
#include <cursesX.h>
#include <term.h>
extern void setupterm P((const char *, int, int));
#else /* ! MORE_TERMINFO */
#ifdef MORE_AMOS
#include <moncal.h>
#include <unistd.h>
#endif /* MORE_AMOS */
#endif /* ! MORE_TERMINFO */
#endif /* ! MORE_TERMCAP */
/* Initialize the more waiting facility (determine how many rows the
* terminal has).
*/
static integer crows;
static integer coutput;
void more_init()
{
#ifdef MORE_NONE
crows = 0;
#else /* ! MORE_NONE */
#ifdef MORE_24
crows = 24;
#else /* ! MORE_24 */
#ifdef MORE_TERMCAP
char buf[2048];
char *term;
term = getenv("TERM");
if (term == NULL)
crows = 0;
else {
tgetent(buf, term);
crows = tgetnum("li");
}
#else /* ! MORE_TERMCAP */
#ifdef MORE_TERMINFO
int i;
setupterm(NULL, 1, &i);
if (i != 1)
crows = 0;
else
crows = lines;
#else /* ! MORE_TERMINFO */
#ifdef MORE_AMOS
trm_char st;
if (isatty(fileno(stdin)) == 0)
crows = 0;
else {
trmchr(&st, 0);
crows = st.row;
}
#else /* ! MORE_AMOS */
This should be impossible
#endif /* ! MORE_AMOS */
#endif /* ! MORE_TERMINFO */
#endif /* ! MORE_TERMCAP */
#endif /* ! MORE_24 */
#endif /* ! MORE_NONE */
}
/* The program wants to output a line to the terminal. If z is not
* NULL it is a simple string which is output here; otherwise it
* needs some sort of formatting, and is output after this function
* returns (if all computers had vprintf I would just it, but they
* probably don't).
*/
void more_output(z)
const char *z;
{
if (crows > 0 && coutput > crows - 2) {
printf("Press return to continue: ");
(void) fflush(stdout);
while (getchar() != '\n')
;
coutput = 0;
}
if (z != NULL)
printf("%s\n", z);
coutput++;
}
/* The terminal is waiting for input (clear the number of output lines) */
void more_input()
{
coutput = 0;
}