+/* $NetBSD: input.c,v 1.10 1998/09/13 15:20:31 hubertf Exp $ */
+
/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Ed James.
* For more info on this and all of my stuff, mail edjames@berkeley.edu.
*/
+#include <sys/cdefs.h>
#ifndef lint
-static char sccsid[] = "@(#)input.c 5.4 (Berkeley) 4/30/90";
+#if 0
+static char sccsid[] = "@(#)input.c 8.1 (Berkeley) 5/31/93";
+#else
+__RCSID("$NetBSD: input.c,v 1.10 1998/09/13 15:20:31 hubertf Exp $");
+#endif
#endif not lint
#include "include.h"
#define MAXDEPTH 15
#define RETTOKEN '\n'
-#ifdef SYSV
-#define CRTOKEN '\r'
-#endif
#define REDRAWTOKEN '\014' /* CTRL(L) */
#define SHELLTOKEN '!'
#define HELPTOKEN '?'
int token;
int to_state;
char *str;
- char *(*func)();
+ char *(*func) __P((char));
} RULE;
typedef struct {
#define NUMSTATES NUMELS(st)
-char *setplane(), *circle(), *left(), *right(), *Left(), *Right(),
- *beacon(), *ex_it(), *climb(), *descend(), *setalt(), *setrelalt(),
- *benum(), *to_dir(), *rel_dir(), *delayb(), *mark(), *unmark(),
- *airport(), *turn(), *ignore();
RULE state0[] = { { ALPHATOKEN, 1, "%c:", setplane},
{ RETTOKEN, -1, "", NULL },
-#ifdef SYSV
- { CRTOKEN, -1, "", NULL },
-#endif
{ HELPTOKEN, 12, " [a-z]<ret>", NULL }},
state1[] = { { 't', 2, " turn", turn },
{ 'a', 3, " altitude:", NULL },
state4[] = { { '@', 9, " at", NULL },
{ 'a', 9, " at", NULL },
{ RETTOKEN, -1, "", NULL },
-#ifdef SYSV
- { CRTOKEN, -1, "", NULL },
-#endif
{ HELPTOKEN, 12, " @a<ret>", NULL }},
state5[] = { { NUMTOKEN, 7, "%c", delayb },
{ HELPTOKEN, 12, " [0-9]", NULL }},
{ 'a', 4, " 270", rel_dir },
{ 'q', 4, " 315", rel_dir },
{ RETTOKEN, -1, "", NULL },
-#ifdef SYSV
- { CRTOKEN, -1, "", NULL },
-#endif
{ HELPTOKEN, 12, " @a<dir><ret>",NULL }},
state7[] = { { RETTOKEN, -1, "", NULL },
-#ifdef SYSV
- { CRTOKEN, -1, "", NULL },
-#endif
{ HELPTOKEN, 12, " <ret>", NULL }},
state8[] = { { NUMTOKEN, 4, "%c", benum },
{ HELPTOKEN, 12, " [0-9]", NULL }},
int tval;
int dest_type, dest_no, dir;
+int
pop()
{
if (level == 0)
return (0);
}
+void
rezero()
{
iomove(0);
strcpy(T_STR, "");
}
+void
push(ruleno, ch)
+ int ruleno, ch;
{
int newstate, newpos;
strcpy(T_STR, "");
}
+int
getcommand()
{
int c, i, done;
- char *s, *(*func)();
+ char *s, *(*func) __P((char));
PLANE *pp;
rezero();
do {
c = gettoken();
- if (c == tty_new.sg_erase) {
+ if (c == tty_new.c_cc[VERASE]) {
if (pop() < 0)
noise();
- } else if (c == tty_new.sg_kill) {
+ } else if (c == tty_new.c_cc[VKILL]) {
while (pop() >= 0)
;
} else {
return (0);
}
+void
noise()
{
putchar('\07');
fflush(stdout);
}
+int
gettoken()
{
while ((tval = getAChar()) == REDRAWTOKEN || tval == SHELLTOKEN)
#endif
if (fork() == 0) /* child */
{
- char *shell, *base, *getenv(), *strrchr();
+ char *shell, *base;
setuid(getuid()); /* turn off setuid bit */
done_screen();
}
wait(0);
+ tcsetattr(fileno(stdin), TCSADRAIN, &tty_new);
#ifdef BSD
- ioctl(fileno(stdin), TIOCSETP, &tty_new);
itv.it_value.tv_sec = 0;
itv.it_value.tv_usec = 1;
itv.it_interval.tv_sec = sp->update_secs;
setitimer(ITIMER_REAL, &itv, NULL);
#endif
#ifdef SYSV
- ioctl(fileno(stdin), TCSETAW, &tty_new);
alarm(aval);
#endif
}
char *
setplane(c)
+ char c;
{
PLANE *pp;
pp = findplane(number(c));
if (pp == NULL)
return ("Unknown Plane");
- bcopy(pp, &p, sizeof (p));
+ memcpy(&p, pp, sizeof (p));
p.delayd = 0;
return (NULL);
}
char *
turn(c)
+ char c;
{
if (p.altitude == 0)
return ("Planes at airports may not change direction");
char *
circle(c)
+ char c;
{
if (p.altitude == 0)
return ("Planes cannot circle on the ground");
char *
left(c)
+ char c;
{
dir = D_LEFT;
p.new_dir = p.dir - 1;
char *
right(c)
+ char c;
{
dir = D_RIGHT;
p.new_dir = p.dir + 1;
- if (p.new_dir > MAXDIR)
+ if (p.new_dir >= MAXDIR)
p.new_dir -= MAXDIR;
return (NULL);
}
char *
Left(c)
+ char c;
{
p.new_dir = p.dir - 2;
if (p.new_dir < 0)
char *
Right(c)
+ char c;
{
p.new_dir = p.dir + 2;
- if (p.new_dir > MAXDIR)
+ if (p.new_dir >= MAXDIR)
p.new_dir -= MAXDIR;
return (NULL);
}
char *
delayb(c)
+ char c;
{
int xdiff, ydiff;
if (c >= sp->num_beacons)
return ("Unknown beacon");
- xdiff = sp->beacon[c].x - p.xpos;
+ xdiff = sp->beacon[(int)c].x - p.xpos;
xdiff = SGN(xdiff);
- ydiff = sp->beacon[c].y - p.ypos;
+ ydiff = sp->beacon[(int)c].y - p.ypos;
ydiff = SGN(ydiff);
if (xdiff != displacement[p.dir].dx || ydiff != displacement[p.dir].dy)
return ("Beacon is not in flight path");
if (dest_type != T_NODEST) {
switch (dest_type) {
case T_BEACON:
- xdiff = sp->beacon[dest_no].x - sp->beacon[c].x;
- ydiff = sp->beacon[dest_no].y - sp->beacon[c].y;
+ xdiff = sp->beacon[dest_no].x - sp->beacon[(int)c].x;
+ ydiff = sp->beacon[dest_no].y - sp->beacon[(int)c].y;
break;
case T_EXIT:
- xdiff = sp->exit[dest_no].x - sp->beacon[c].x;
- ydiff = sp->exit[dest_no].y - sp->beacon[c].y;
+ xdiff = sp->exit[dest_no].x - sp->beacon[(int)c].x;
+ ydiff = sp->exit[dest_no].y - sp->beacon[(int)c].y;
break;
case T_AIRPORT:
- xdiff = sp->airport[dest_no].x - sp->beacon[c].x;
- ydiff = sp->airport[dest_no].y - sp->beacon[c].y;
+ xdiff = sp->airport[dest_no].x - sp->beacon[(int)c].x;
+ ydiff = sp->airport[dest_no].y - sp->beacon[(int)c].y;
break;
default:
return ("Bad case in delayb! Get help!");
char *
beacon(c)
+ char c;
{
dest_type = T_BEACON;
return (NULL);
char *
ex_it(c)
+ char c;
{
dest_type = T_EXIT;
return (NULL);
char *
airport(c)
+ char c;
{
dest_type = T_AIRPORT;
return (NULL);
char *
climb(c)
+ char c;
{
dir = D_UP;
return (NULL);
char *
descend(c)
+ char c;
{
dir = D_DOWN;
return (NULL);
char *
setalt(c)
+ char c;
{
if ((p.altitude == c - '0') && (p.new_altitude == p.altitude))
return ("Already at that altitude");
char *
setrelalt(c)
+ char c;
{
if (c == 0)
return ("altitude not changed");
char *
benum(c)
+ char c;
{
dest_no = c -= '0';
case T_BEACON:
if (c >= sp->num_beacons)
return ("Unknown beacon");
- p.new_dir = DIR_FROM_DXDY(sp->beacon[c].x - p.xpos,
- sp->beacon[c].y - p.ypos);
+ p.new_dir = DIR_FROM_DXDY(sp->beacon[(int)c].x - p.xpos,
+ sp->beacon[(int)c].y - p.ypos);
break;
case T_EXIT:
if (c >= sp->num_exits)
return ("Unknown exit");
- p.new_dir = DIR_FROM_DXDY(sp->exit[c].x - p.xpos,
- sp->exit[c].y - p.ypos);
+ p.new_dir = DIR_FROM_DXDY(sp->exit[(int)c].x - p.xpos,
+ sp->exit[(int)c].y - p.ypos);
break;
case T_AIRPORT:
if (c >= sp->num_airports)
return ("Unknown airport");
- p.new_dir = DIR_FROM_DXDY(sp->airport[c].x - p.xpos,
- sp->airport[c].y - p.ypos);
+ p.new_dir = DIR_FROM_DXDY(sp->airport[(int)c].x - p.xpos,
+ sp->airport[(int)c].y - p.ypos);
break;
default:
return ("Unknown case in benum! Get help!");
char *
to_dir(c)
+ char c;
{
p.new_dir = dir_no(c);
return (NULL);
char *
rel_dir(c)
+ char c;
{
int angle;
char *
mark(c)
+ char c;
{
if (p.altitude == 0)
return ("Cannot mark planes on the ground");
char *
unmark(c)
+ char c;
{
if (p.altitude == 0)
return ("Cannot unmark planes on the ground");
char *
ignore(c)
+ char c;
{
if (p.altitude == 0)
return ("Cannot ignore planes on the ground");
return (NULL);
}
+int
dir_no(ch)
char ch;
{
int dir;
+ dir = -1;
switch (ch) {
case 'w': dir = 0; break;
case 'e': dir = 1; break;