* Copyright (c) 1990 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* Copyright (c) 1987 by Ed James, UC Berkeley. All rights reserved.
* Copy permission is hereby granted provided that this notice is
* retained on all partial or complete copies.
* For more info on this and all of my stuff, mail edjames@berkeley.edu.
static char sccsid
[] = "@(#)input.c 5.4 (Berkeley) 4/30/90";
#define REDRAWTOKEN '\014' /* CTRL(L) */
#define T_RULE stack[level].rule
#define T_STATE stack[level].state
#define T_STR stack[level].str
#define T_POS stack[level].pos
#define T_CH stack[level].ch
#define NUMELS(a) (sizeof (a) / sizeof (*(a)))
#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
},
{ CRTOKEN
, -1, "", NULL
},
{ HELPTOKEN
, 12, " [a-z]<ret>", NULL
}},
state1
[] = { { 't', 2, " turn", turn
},
{ 'a', 3, " altitude:", NULL
},
{ 'c', 4, " circle", circle
},
{ 'm', 7, " mark", mark
},
{ 'u', 7, " unmark", unmark
},
{ 'i', 7, " ignore", ignore
},
{ HELPTOKEN
, 12, " tacmui", NULL
}},
state2
[] = { { 'l', 6, " left", left
},
{ 'r', 6, " right", right
},
{ 'L', 4, " left 90", Left
},
{ 'R', 4, " right 90", Right
},
{ 't', 11, " towards", NULL
},
{ 'w', 4, " to 0", to_dir
},
{ 'e', 4, " to 45", to_dir
},
{ 'd', 4, " to 90", to_dir
},
{ 'c', 4, " to 135", to_dir
},
{ 'x', 4, " to 180", to_dir
},
{ 'z', 4, " to 225", to_dir
},
{ 'a', 4, " to 270", to_dir
},
{ 'q', 4, " to 315", to_dir
},
{ HELPTOKEN
, 12, " lrLRt<dir>", NULL
}},
state3
[] = { { '+', 10, " climb", climb
},
{ 'c', 10, " climb", climb
},
{ '-', 10, " descend", descend
},
{ 'd', 10, " descend", descend
},
{ NUMTOKEN
, 7, " %c000 feet", setalt
},
{ HELPTOKEN
, 12, " +-cd[0-9]", NULL
}},
state4
[] = { { '@', 9, " at", NULL
},
{ RETTOKEN
, -1, "", NULL
},
{ CRTOKEN
, -1, "", NULL
},
{ HELPTOKEN
, 12, " @a<ret>", NULL
}},
state5
[] = { { NUMTOKEN
, 7, "%c", delayb
},
{ HELPTOKEN
, 12, " [0-9]", NULL
}},
state6
[] = { { '@', 9, " at", NULL
},
{ 'w', 4, " 0", rel_dir
},
{ 'e', 4, " 45", rel_dir
},
{ 'd', 4, " 90", rel_dir
},
{ 'c', 4, " 135", rel_dir
},
{ 'x', 4, " 180", rel_dir
},
{ 'z', 4, " 225", rel_dir
},
{ 'a', 4, " 270", rel_dir
},
{ 'q', 4, " 315", rel_dir
},
{ RETTOKEN
, -1, "", NULL
},
{ CRTOKEN
, -1, "", NULL
},
{ HELPTOKEN
, 12, " @a<dir><ret>",NULL
}},
state7
[] = { { RETTOKEN
, -1, "", NULL
},
{ CRTOKEN
, -1, "", NULL
},
{ HELPTOKEN
, 12, " <ret>", NULL
}},
state8
[] = { { NUMTOKEN
, 4, "%c", benum
},
{ HELPTOKEN
, 12, " [0-9]", NULL
}},
state9
[] = { { 'b', 5, " beacon #", NULL
},
{ '*', 5, " beacon #", NULL
},
{ HELPTOKEN
, 12, " b*", NULL
}},
state10
[] = { { NUMTOKEN
, 7, " %c000 ft", setrelalt
},
{ HELPTOKEN
, 12, " [0-9]", NULL
}},
state11
[] = { { 'b', 8, " beacon #", beacon
},
{ '*', 8, " beacon #", beacon
},
{ 'e', 8, " exit #", ex_it
},
{ 'a', 8, " airport #", airport
},
{ HELPTOKEN
, 12, " b*ea", NULL
}},
state12
[] = { { -1, -1, "", NULL
}};
#define DEF_STATE(s) { NUMELS(s), (s) }
DEF_STATE(state0
), DEF_STATE(state1
), DEF_STATE(state2
),
DEF_STATE(state3
), DEF_STATE(state4
), DEF_STATE(state5
),
DEF_STATE(state6
), DEF_STATE(state7
), DEF_STATE(state8
),
DEF_STATE(state9
), DEF_STATE(state10
), DEF_STATE(state11
),
int dest_type
, dest_no
, dir
;
(void)sprintf(T_STR
, st
[T_STATE
].rule
[ruleno
].str
, tval
);
newstate
= st
[T_STATE
].rule
[ruleno
].to_state
;
newpos
= T_POS
+ strlen(T_STR
);
if (c
== tty_new
.sg_erase
) {
} else if (c
== tty_new
.sg_kill
) {
for (i
= 0; i
< st
[T_STATE
].num_rules
; i
++) {
if (st
[T_STATE
].rule
[i
].token
== c
||
st
[T_STATE
].rule
[i
].token
== tval
) {
push(i
, (c
>= ALPHATOKEN
) ? tval
: c
);
return (1); /* forced update */
for (i
= 0; i
< level
; i
++) {
func
= st
[stack
[i
].state
].rule
[stack
[i
].rule
].func
;
if ((s
= (*func
)(stack
[i
].ch
)) != NULL
) {
ioerror(stack
[i
].pos
, strlen(stack
[i
].str
), s
);
pp
= findplane(p
.plane_no
);
if (pp
->new_altitude
!= p
.new_altitude
)
pp
->new_altitude
= p
.new_altitude
;
else if (pp
->status
!= p
.status
)
pp
->delayd_no
= p
.delayd_no
;
while ((tval
= getAChar()) == REDRAWTOKEN
|| tval
== SHELLTOKEN
)
itv
.it_value
.tv_usec
= 0;
setitimer(ITIMER_REAL
, &itv
, NULL
);
if (fork() == 0) /* child */
char *shell
, *base
, *getenv(), *strrchr();
setuid(getuid()); /* turn off setuid bit */
/* run user's favorite shell */
if ((shell
= getenv("SHELL")) != NULL
)
base
= strrchr(shell
, '/');
execl(_PATH_BSHELL
, "sh", 0);
ioctl(fileno(stdin
), TIOCSETP
, &tty_new
);
itv
.it_value
.tv_usec
= 1;
itv
.it_interval
.tv_sec
= sp
->update_secs
;
itv
.it_interval
.tv_usec
= 0;
setitimer(ITIMER_REAL
, &itv
, NULL
);
ioctl(fileno(stdin
), TCSETAW
, &tty_new
);
pp
= findplane(number(c
));
return ("Unknown Plane");
bcopy(pp
, &p
, sizeof (p
));
return ("Planes at airports may not change direction");
return ("Planes cannot circle on the ground");
if (c
>= sp
->num_beacons
)
return ("Unknown beacon");
xdiff
= sp
->beacon
[c
].x
- p
.xpos
;
ydiff
= sp
->beacon
[c
].y
- p
.ypos
;
if (xdiff
!= displacement
[p
.dir
].dx
|| ydiff
!= displacement
[p
.dir
].dy
)
return ("Beacon is not in flight path");
if (dest_type
!= T_NODEST
) {
xdiff
= sp
->beacon
[dest_no
].x
- sp
->beacon
[c
].x
;
ydiff
= sp
->beacon
[dest_no
].y
- sp
->beacon
[c
].y
;
xdiff
= sp
->exit
[dest_no
].x
- sp
->beacon
[c
].x
;
ydiff
= sp
->exit
[dest_no
].y
- sp
->beacon
[c
].y
;
xdiff
= sp
->airport
[dest_no
].x
- sp
->beacon
[c
].x
;
ydiff
= sp
->airport
[dest_no
].y
- sp
->beacon
[c
].y
;
return ("Bad case in delayb! Get help!");
if (xdiff
== 0 && ydiff
== 0)
return ("Would already be there");
p
.new_dir
= DIR_FROM_DXDY(xdiff
, ydiff
);
return ("Already going in that direction");
if ((p
.altitude
== c
- '0') && (p
.new_altitude
== p
.altitude
))
return ("Already at that altitude");
p
.new_altitude
= c
- '0';
return ("altitude not changed");
p
.new_altitude
= p
.altitude
+ c
- '0';
p
.new_altitude
= p
.altitude
- (c
- '0');
return ("Unknown case in setrelalt! Get help!");
return ("Altitude would be too low");
else if (p
.new_altitude
> 9)
return ("Altitude would be too high");
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
->exit
[c
].x
- p
.xpos
,
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
);
return ("Unknown case in benum! Get help!");
p
.new_dir
= p
.dir
- angle
;
p
.new_dir
= p
.dir
+ angle
;
return ("Bizarre direction in rel_dir! Get help!");
return ("Cannot mark planes on the ground");
if (p
.status
== S_MARKED
)
return ("Already marked");
return ("Cannot unmark planes on the ground");
if (p
.status
== S_UNMARKED
)
return ("Already unmarked");
return ("Cannot ignore planes on the ground");
if (p
.status
== S_IGNORED
)
return ("Already ignored");
case 'w': dir
= 0; break;
case 'e': dir
= 1; break;
case 'd': dir
= 2; break;
case 'c': dir
= 3; break;
case 'x': dir
= 4; break;
case 'z': dir
= 5; break;
case 'a': dir
= 6; break;
case 'q': dir
= 7; break;
fprintf(stderr
, "bad character in dir_no\n");