X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/77e3814f0c0e3dea4d0032e25666f77e6f83bfff..8d2dd1244517d9cf4b4e1fd9a4914c5496e8dfac:/atc/input.c diff --git a/atc/input.c b/atc/input.c index 693a7a3a..95ada133 100644 --- a/atc/input.c +++ b/atc/input.c @@ -1,6 +1,8 @@ +/* $NetBSD: input.c,v 1.6 1997/10/10 02:07:18 lukem 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. @@ -43,8 +45,13 @@ * For more info on this and all of my stuff, mail edjames@berkeley.edu. */ +#include #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.6 1997/10/10 02:07:18 lukem Exp $"); +#endif #endif not lint #include "include.h" @@ -67,7 +74,7 @@ typedef struct { int token; int to_state; char *str; - char *(*func)(); + char *(*func) __P((char)); } RULE; typedef struct { @@ -93,10 +100,6 @@ 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 }, @@ -190,6 +193,7 @@ int level; int tval; int dest_type, dest_no, dir; +int pop() { if (level == 0) @@ -204,6 +208,7 @@ pop() return (0); } +void rezero() { iomove(0); @@ -216,7 +221,9 @@ rezero() strcpy(T_STR, ""); } +void push(ruleno, ch) + int ruleno, ch; { int newstate, newpos; @@ -237,20 +244,21 @@ push(ruleno, ch) 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 { @@ -295,12 +303,14 @@ getcommand() return (0); } +void noise() { putchar('\07'); fflush(stdout); } +int gettoken() { while ((tval = getAChar()) == REDRAWTOKEN || tval == SHELLTOKEN) @@ -319,7 +329,7 @@ gettoken() #endif if (fork() == 0) /* child */ { - char *shell, *base, *getenv(), *strrchr(); + char *shell, *base; setuid(getuid()); /* turn off setuid bit */ done_screen(); @@ -341,8 +351,8 @@ gettoken() } 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; @@ -350,7 +360,6 @@ gettoken() setitimer(ITIMER_REAL, &itv, NULL); #endif #ifdef SYSV - ioctl(fileno(stdin), TCSETAW, &tty_new); alarm(aval); #endif } @@ -367,19 +376,21 @@ gettoken() 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"); @@ -388,6 +399,7 @@ turn(c) char * circle(c) + char c; { if (p.altitude == 0) return ("Planes cannot circle on the ground"); @@ -397,6 +409,7 @@ circle(c) char * left(c) + char c; { dir = D_LEFT; p.new_dir = p.dir - 1; @@ -407,6 +420,7 @@ left(c) char * right(c) + char c; { dir = D_RIGHT; p.new_dir = p.dir + 1; @@ -417,6 +431,7 @@ right(c) char * Left(c) + char c; { p.new_dir = p.dir - 2; if (p.new_dir < 0) @@ -426,6 +441,7 @@ Left(c) char * Right(c) + char c; { p.new_dir = p.dir + 2; if (p.new_dir > MAXDIR) @@ -435,6 +451,7 @@ Right(c) char * delayb(c) + char c; { int xdiff, ydiff; @@ -480,6 +497,7 @@ delayb(c) char * beacon(c) + char c; { dest_type = T_BEACON; return (NULL); @@ -487,6 +505,7 @@ beacon(c) char * ex_it(c) + char c; { dest_type = T_EXIT; return (NULL); @@ -494,6 +513,7 @@ ex_it(c) char * airport(c) + char c; { dest_type = T_AIRPORT; return (NULL); @@ -501,6 +521,7 @@ airport(c) char * climb(c) + char c; { dir = D_UP; return (NULL); @@ -508,6 +529,7 @@ climb(c) char * descend(c) + char c; { dir = D_DOWN; return (NULL); @@ -515,6 +537,7 @@ descend(c) char * setalt(c) + char c; { if ((p.altitude == c - '0') && (p.new_altitude == p.altitude)) return ("Already at that altitude"); @@ -524,6 +547,7 @@ setalt(c) char * setrelalt(c) + char c; { if (c == 0) return ("altitude not changed"); @@ -548,6 +572,7 @@ setrelalt(c) char * benum(c) + char c; { dest_no = c -= '0'; @@ -579,6 +604,7 @@ benum(c) char * to_dir(c) + char c; { p.new_dir = dir_no(c); return (NULL); @@ -586,6 +612,7 @@ to_dir(c) char * rel_dir(c) + char c; { int angle; @@ -610,6 +637,7 @@ rel_dir(c) char * mark(c) + char c; { if (p.altitude == 0) return ("Cannot mark planes on the ground"); @@ -621,6 +649,7 @@ mark(c) char * unmark(c) + char c; { if (p.altitude == 0) return ("Cannot unmark planes on the ground"); @@ -632,6 +661,7 @@ unmark(c) char * ignore(c) + char c; { if (p.altitude == 0) return ("Cannot ignore planes on the ground"); @@ -641,11 +671,13 @@ ignore(c) return (NULL); } +int dir_no(ch) char ch; { int dir; + dir = -1; switch (ch) { case 'w': dir = 0; break; case 'e': dir = 1; break;