1 /* $NetBSD: tok.c,v 1.9 2008/02/03 20:11:05 dholland Exp $ */
3 /* tok.c Larn is copyrighted 1986 by Noah Morgan. */
6 __RCSID("$NetBSD: tok.c,v 1.9 2008/02/03 20:11:05 dholland Exp $");
11 #include <sys/ioctl.h>
19 /* Keystrokes (roughly) between checkpoints */
20 #define CHECKPOINT_INTERVAL 400
22 static char lastok
= 0;
27 static int flushno
= FLUSHNO
; /* input queue flushing threshold */
28 #define MAXUM 52 /* maximum number of user re-named monsters */
29 #define MAXMNAME 40 /* max length of a monster re-name */
30 static char usermonster
[MAXUM
][MAXMNAME
]; /* the user named monster
32 static u_char usermpoint
= 0; /* the user monster pointer */
35 lexical analyzer for larn
55 } /* show where the player is */
59 /* check for periodic checkpointing */
61 if ((c
[BYTESIN
] % CHECKPOINT_INTERVAL
) == 0) {
65 wait(0); /* wait for other forks to
73 do { /* if keyboard input buffer is too big, flush
75 ioctl(0, FIONREAD
, &ic
);
81 if (read(0, &cc
, 1) != 1)
84 if (cc
== 'Y' - 64) { /* control Y -- shell escape */
86 clear();/* scrolling region, home, clear, no
88 if ((ic
= fork()) == 0) { /* child */
89 execl("/bin/csh", "/bin/csh", NULL
);
93 if (ic
< 0) { /* error */
94 write(2, "Can't fork off a shell!\n", 25);
98 return (lastok
= 'L' - 64); /* redisplay screen */
100 if ((cc
<= '9') && (cc
>= '0')) {
101 yrepcount
= yrepcount
* 10 + cc
- '0';
105 return (lastok
= cc
);
111 * flushall() Function to flush all type-ahead in the input buffer
118 for (;;) { /* if keyboard input buffer is too big, flush
120 ioctl(0, FIONREAD
, &ic
);
126 } /* gobble up the byte */
131 function to set the desired hardness
132 enter with hard= -1 for default hardness, else any desired hardness
143 if (restorflag
== 0) { /* don't set c[HARDGAME] if restoring game */
147 c
[HARDGAME
] = j
;/* set c[HARDGAME] to proper value if
150 if ((k
= c
[HARDGAME
]) != 0)
151 for (j
= 0; j
<= MAXMONST
+ 8; j
++) {
153 i
= ((6 + k
) * mp
->hitpoints
+ 1) / 6;
154 mp
->hitpoints
= (i
< 0) ? 32767 : i
;
155 i
= ((6 + k
) * mp
->damage
+ 1) / 5;
156 mp
->damage
= (i
> 127) ? 127 : i
;
157 i
= (10 * mp
->gold
) / (10 + k
);
158 mp
->gold
= (i
> 32767) ? 32767 : i
;
159 i
= mp
->armorclass
- k
;
160 mp
->armorclass
= (i
< -127) ? -127 : i
;
161 i
= (7 * mp
->experience
) / (7 + k
) + 1;
162 mp
->experience
= (i
<= 0) ? 1 : i
;
167 function to read and process the larn options file
176 flag
= 1; /* set to 0 if a name is specified */
178 if (lopen(optsfile
) < 0) {
179 strcpy(logname
, loginname
);
180 return; /* user name if no character name */
184 if ((i
= lgetw()) == NULL
)
185 break; /* check for EOF */
186 while ((*i
== ' ') || (*i
== '\t'))
187 i
++; /* eat leading whitespace */
189 if (strcmp(i
, "bold-objects") == 0)
191 else if (strcmp(i
, "enable-checkpointing") == 0)
193 else if (strcmp(i
, "inverse-objects") == 0)
195 else if (strcmp(i
, "female") == 0)
196 sex
= 0; /* male or female */
197 else if (strcmp(i
, "monster:") == 0) { /* name favorite monster */
198 if ((i
= lgetw()) == 0)
200 strlcpy(usermonster
[usermpoint
], i
, MAXMNAME
);
201 if (usermpoint
>= MAXUM
)
202 continue; /* defined all of em */
203 if (isalpha(j
= usermonster
[usermpoint
][0])) {
204 for (k
= 1; k
< MAXMONST
+ 8; k
++) /* find monster */
205 if (monstnamelist
[k
] == j
) {
206 monster
[k
].name
= &usermonster
[usermpoint
++][0];
210 } else if (strcmp(i
, "male") == 0)
212 else if (strcmp(i
, "name:") == 0) { /* defining players name */
213 if ((i
= lgetw()) == 0)
215 strlcpy(logname
, i
, LOGNAMESIZE
);
217 } else if (strcmp(i
, "no-introduction") == 0)
219 else if (strcmp(i
, "no-beep") == 0)
221 else if (strcmp(i
, "process-name:") == 0) {
222 if ((i
= lgetw()) == 0)
224 strlcpy(psname
, i
, PSNAMESIZE
);
225 } else if (strcmp(i
, "play-day-play") == 0) {
226 /* bypass time restrictions: ignored */
227 } else if (strcmp(i
, "savefile:") == 0) { /* defining savefilename */
228 if ((i
= lgetw()) == 0)
230 strcpy(savefilename
, i
);
235 strcpy(logname
, loginname
);