X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/da5bab8233f2698f91a021aa951723a66fda731c..512d94ab57edbcbdbe7bf85e5b46d66339a28386:/atc/input.c?ds=inline diff --git a/atc/input.c b/atc/input.c index a5c75dec..3b44be09 100644 --- a/atc/input.c +++ b/atc/input.c @@ -1,4 +1,4 @@ -/* $NetBSD: input.c,v 1.13 1999/07/25 00:24:38 hubertf Exp $ */ +/* $NetBSD: input.c,v 1.29 2015/06/19 06:02:31 dholland Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -15,11 +15,7 @@ * 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 + * 3. 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. * @@ -50,12 +46,53 @@ #if 0 static char sccsid[] = "@(#)input.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: input.c,v 1.13 1999/07/25 00:24:38 hubertf Exp $"); +__RCSID("$NetBSD: input.c,v 1.29 2015/06/19 06:02:31 dholland Exp $"); #endif -#endif not lint +#endif /* not lint */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -#include "include.h" #include "pathnames.h" +#include "def.h" +#include "struct.h" +#include "extern.h" +#include "tunable.h" + +static void rezero(void); +static void noise(void); +static int gettoken(void); +static const char *setplane(int); +static const char *turn(int); +static const char *circle(int); +static const char *left(int); +static const char *right(int); +static const char *Left(int); +static const char *Right(int); +static const char *delayb(int); +static const char *beacon(int); +static const char *ex_it(int); +static const char *airport(int); +static const char *climb(int); +static const char *descend(int); +static const char *setalt(int); +static const char *setrelalt(int); +static const char *benum(int); +static const char *to_dir(int); +static const char *rel_dir(int); +static const char *mark(int); +static const char *unmark(int); +static const char *ignore(int); + + #define MAXRULES 6 #define MAXDEPTH 15 @@ -71,7 +108,7 @@ typedef struct { int token; int to_state; const char *str; - const char *(*func) __P((char)); + const char *(*func)(int); } RULE; typedef struct { @@ -97,7 +134,7 @@ typedef struct { #define NUMSTATES NUMELS(st) - +static RULE state0[] = { { ALPHATOKEN, 1, "%c:", setplane}, { RETTOKEN, -1, "", NULL }, { HELPTOKEN, 12, " [a-z]", NULL }}, @@ -164,7 +201,7 @@ RULE state0[] = { { ALPHATOKEN, 1, "%c:", setplane}, #define DEF_STATE(s) { NUMELS(s), (s) } -STATE st[] = { +static STATE st[] = { 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), @@ -172,14 +209,16 @@ STATE st[] = { DEF_STATE(state12) }; -PLANE p; -STACK stack[MAXDEPTH]; -int level; -int tval; -int dest_type, dest_no, dir; +static PLANE p; +static STACK stack[MAXDEPTH]; +static int level; +static int tval; +static int dir; +static enum places dest_type; +static unsigned dest_no; -int -pop() +static int +pop(void) { if (level == 0) return (-1); @@ -187,14 +226,14 @@ pop() ioclrtoeol(T_POS); - strcpy(T_STR, ""); + (void)strcpy(T_STR, ""); T_RULE = -1; T_CH = -1; return (0); } -void -rezero() +static void +rezero(void) { iomove(0); @@ -203,16 +242,17 @@ rezero() T_RULE = -1; T_CH = -1; T_POS = 0; - strcpy(T_STR, ""); + (void)strcpy(T_STR, ""); } -void -push(ruleno, ch) - int ruleno, ch; +static void +push(int ruleno, int ch) { int newstate, newpos; - (void)sprintf(T_STR, st[T_STATE].rule[ruleno].str, tval); + assert(level < (MAXDEPTH - 1)); + (void)snprintf(T_STR, sizeof(T_STR), + st[T_STATE].rule[ruleno].str, tval); T_RULE = ruleno; T_CH = ch; newstate = st[T_STATE].rule[ruleno].to_state; @@ -226,14 +266,14 @@ push(ruleno, ch) T_STATE = newstate; T_POS = newpos; T_RULE = -1; - strcpy(T_STR, ""); + (void)strcpy(T_STR, ""); } int -getcommand() +getcommand(void) { int c, i, done; - const char *s, *(*func) __P((char)); + const char *s, *(*func)(int); PLANE *pp; rezero(); @@ -270,7 +310,8 @@ getcommand() func = st[stack[i].state].rule[stack[i].rule].func; if (func != NULL) if ((s = (*func)(stack[i].ch)) != NULL) { - ioerror(stack[i].pos, strlen(stack[i].str), s); + ioerror(stack[i].pos, + (int)strlen(stack[i].str), s); return (-1); } } @@ -288,15 +329,15 @@ getcommand() return (0); } -void -noise() +static void +noise(void) { - putchar('\07'); - fflush(stdout); + (void)putchar('\07'); + (void)fflush(stdout); } -int -gettoken() +static int +gettoken(void) { while ((tval = getAChar()) == REDRAWTOKEN || tval == SHELLTOKEN) { @@ -306,7 +347,7 @@ gettoken() struct itimerval itv; itv.it_value.tv_sec = 0; itv.it_value.tv_usec = 0; - setitimer(ITIMER_REAL, &itv, NULL); + (void)setitimer(ITIMER_REAL, &itv, NULL); #endif #ifdef SYSV int aval; @@ -326,28 +367,29 @@ gettoken() base = shell; else base++; - execl(shell, base, 0); + (void)execl(shell, base, (char *) 0); } else - execl(_PATH_BSHELL, "sh", 0); + (void)execl(_PATH_BSHELL, "sh", + (char *) 0); exit(0); /* oops */ } - wait(0); - tcsetattr(fileno(stdin), TCSADRAIN, &tty_new); + (void)wait(0); + (void)tcsetattr(fileno(stdin), TCSADRAIN, &tty_new); #ifdef BSD itv.it_value.tv_sec = 0; 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); + (void)setitimer(ITIMER_REAL, &itv, NULL); #endif #ifdef SYSV alarm(aval); #endif } - redraw(); + (void)redraw(); } if (isdigit(tval)) @@ -358,32 +400,31 @@ gettoken() return (tval); } -const char * -setplane(c) - char c; +static const char * +setplane(int c) { PLANE *pp; pp = findplane(number(c)); if (pp == NULL) return ("Unknown Plane"); - memcpy(&p, pp, sizeof (p)); - p.delayd = 0; + (void)memcpy(&p, pp, sizeof (p)); + p.delayd = false; return (NULL); } -const char * -turn(c) - char c __attribute__((__unused__)); +/* ARGSUSED */ +static const char * +turn(int c __unused) { if (p.altitude == 0) return ("Planes at airports may not change direction"); return (NULL); } -const char * -circle(c) - char c __attribute__((__unused__)); +/* ARGSUSED */ +static const char * +circle(int c __unused) { if (p.altitude == 0) return ("Planes cannot circle on the ground"); @@ -391,9 +432,9 @@ circle(c) return (NULL); } -const char * -left(c) - char c __attribute__((__unused__)); +/* ARGSUSED */ +static const char * +left(int c __unused) { dir = D_LEFT; p.new_dir = p.dir - 1; @@ -402,9 +443,9 @@ left(c) return (NULL); } -const char * -right(c) - char c __attribute__((__unused__)); +/* ARGSUSED */ +static const char * +right(int c __unused) { dir = D_RIGHT; p.new_dir = p.dir + 1; @@ -413,9 +454,9 @@ right(c) return (NULL); } -const char * -Left(c) - char c __attribute__((__unused__)); +/* ARGSUSED */ +static const char * +Left(int c __unused) { p.new_dir = p.dir - 2; if (p.new_dir < 0) @@ -423,9 +464,9 @@ Left(c) return (NULL); } -const char * -Right(c) - char c __attribute__((__unused__)); +/* ARGSUSED */ +static const char * +Right(int c __unused) { p.new_dir = p.dir + 2; if (p.new_dir >= MAXDIR) @@ -433,42 +474,41 @@ Right(c) return (NULL); } -const char * -delayb(c) - char c; +static const char * +delayb(int ch) { int xdiff, ydiff; + unsigned bn; - c -= '0'; + bn = ch -= '0'; - if (c >= sp->num_beacons) + if (bn >= sp->num_beacons) return ("Unknown beacon"); - xdiff = sp->beacon[(int)c].x - p.xpos; + xdiff = sp->beacon[bn].x - p.xpos; xdiff = SGN(xdiff); - ydiff = sp->beacon[(int)c].y - p.ypos; + ydiff = sp->beacon[bn].y - p.ypos; ydiff = SGN(ydiff); if (xdiff != displacement[p.dir].dx || ydiff != displacement[p.dir].dy) return ("Beacon is not in flight path"); - p.delayd = 1; - p.delayd_no = c; + p.delayd = true; + p.delayd_no = bn; if (dest_type != T_NODEST) { switch (dest_type) { case T_BEACON: - xdiff = sp->beacon[dest_no].x - sp->beacon[(int)c].x; - ydiff = sp->beacon[dest_no].y - sp->beacon[(int)c].y; + xdiff = sp->beacon[dest_no].x - sp->beacon[bn].x; + ydiff = sp->beacon[dest_no].y - sp->beacon[bn].y; break; case T_EXIT: - xdiff = sp->exit[dest_no].x - sp->beacon[(int)c].x; - ydiff = sp->exit[dest_no].y - sp->beacon[(int)c].y; + xdiff = sp->exit[dest_no].x - sp->beacon[bn].x; + ydiff = sp->exit[dest_no].y - sp->beacon[bn].y; break; case T_AIRPORT: - xdiff = sp->airport[dest_no].x - sp->beacon[(int)c].x; - ydiff = sp->airport[dest_no].y - sp->beacon[(int)c].y; + xdiff = sp->airport[dest_no].x - sp->beacon[bn].x; + ydiff = sp->airport[dest_no].y - sp->beacon[bn].y; break; default: return ("Bad case in delayb! Get help!"); - break; } if (xdiff == 0 && ydiff == 0) return ("Would already be there"); @@ -479,74 +519,83 @@ delayb(c) return (NULL); } -const char * -beacon(c) - char c __attribute__((__unused__)); +/* ARGSUSED */ +static const char * +beacon(int c __unused) { dest_type = T_BEACON; return (NULL); } -const char * -ex_it(c) - char c __attribute__((__unused__)); +/* ARGSUSED */ +static const char * +ex_it(int c __unused) { dest_type = T_EXIT; return (NULL); } -const char * -airport(c) - char c __attribute__((__unused__)); +/* ARGSUSED */ +static const char * +airport(int c __unused) { dest_type = T_AIRPORT; return (NULL); } -const char * -climb(c) - char c __attribute__((__unused__)); +/* ARGSUSED */ +static const char * +climb(int c __unused) { dir = D_UP; return (NULL); } -const char * -descend(c) - char c __attribute__((__unused__)); +/* ARGSUSED */ +static const char * +descend(int c __unused) { dir = D_DOWN; return (NULL); } -const char * -setalt(c) - char c; +static const char * +setalt(int c) { - if ((p.altitude == c - '0') && (p.new_altitude == p.altitude)) + int newalt = c - '0'; + if ((p.altitude == newalt) && (p.new_altitude == p.altitude)) return ("Already at that altitude"); - p.new_altitude = c - '0'; + if (p.new_altitude == newalt) { + return ("Already going to that altitude"); + } + p.new_altitude = newalt; return (NULL); } -const char * -setrelalt(c) - char c; +static const char * +setrelalt(int c) { + int newalt; + if (c == 0) return ("altitude not changed"); switch (dir) { case D_UP: - p.new_altitude = p.altitude + c - '0'; + newalt = p.altitude + c - '0'; break; case D_DOWN: - p.new_altitude = p.altitude - (c - '0'); + newalt = p.altitude - (c - '0'); break; default: return ("Unknown case in setrelalt! Get help!"); - break; } + + if (p.new_altitude == newalt) + return ("Already going to that altitude"); + + p.new_altitude = newalt; + if (p.new_altitude < 0) return ("Altitude would be too low"); else if (p.new_altitude > 9) @@ -554,49 +603,48 @@ setrelalt(c) return (NULL); } -const char * -benum(c) - char c; +static const char * +benum(int ch) { - dest_no = c -= '0'; + unsigned n; + + n = ch - '0'; + dest_no = n; switch (dest_type) { case T_BEACON: - if (c >= sp->num_beacons) + if (n >= sp->num_beacons) return ("Unknown beacon"); - p.new_dir = DIR_FROM_DXDY(sp->beacon[(int)c].x - p.xpos, - sp->beacon[(int)c].y - p.ypos); + p.new_dir = DIR_FROM_DXDY(sp->beacon[n].x - p.xpos, + sp->beacon[n].y - p.ypos); break; case T_EXIT: - if (c >= sp->num_exits) + if (n >= sp->num_exits) return ("Unknown exit"); - p.new_dir = DIR_FROM_DXDY(sp->exit[(int)c].x - p.xpos, - sp->exit[(int)c].y - p.ypos); + p.new_dir = DIR_FROM_DXDY(sp->exit[n].x - p.xpos, + sp->exit[n].y - p.ypos); break; case T_AIRPORT: - if (c >= sp->num_airports) + if (n >= sp->num_airports) return ("Unknown airport"); - p.new_dir = DIR_FROM_DXDY(sp->airport[(int)c].x - p.xpos, - sp->airport[(int)c].y - p.ypos); + p.new_dir = DIR_FROM_DXDY(sp->airport[n].x - p.xpos, + sp->airport[n].y - p.ypos); break; default: return ("Unknown case in benum! Get help!"); - break; } return (NULL); } -const char * -to_dir(c) - char c; +static const char * +to_dir(int c) { p.new_dir = dir_no(c); return (NULL); } -const char * -rel_dir(c) - char c; +static const char * +rel_dir(int c) { int angle; @@ -614,14 +662,13 @@ rel_dir(c) break; default: return ("Bizarre direction in rel_dir! Get help!"); - break; } return (NULL); } -const char * -mark(c) - char c __attribute__((__unused__)); +/* ARGSUSED */ +static const char * +mark(int c __unused) { if (p.altitude == 0) return ("Cannot mark planes on the ground"); @@ -631,9 +678,9 @@ mark(c) return (NULL); } -const char * -unmark(c) - char c __attribute__((__unused__)); +/* ARGSUSED */ +static const char * +unmark(int c __unused) { if (p.altitude == 0) return ("Cannot unmark planes on the ground"); @@ -643,9 +690,9 @@ unmark(c) return (NULL); } -const char * -ignore(c) - char c __attribute__((__unused__)); +/* ARGSUSED */ +static const char * +ignore(int c __unused) { if (p.altitude == 0) return ("Cannot ignore planes on the ground"); @@ -656,24 +703,23 @@ ignore(c) } int -dir_no(ch) - char ch; +dir_no(int ch) { - int dir; + int dirno; - dir = -1; + dirno = -1; switch (ch) { - 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; + case 'w': dirno = 0; break; + case 'e': dirno = 1; break; + case 'd': dirno = 2; break; + case 'c': dirno = 3; break; + case 'x': dirno = 4; break; + case 'z': dirno = 5; break; + case 'a': dirno = 6; break; + case 'q': dirno = 7; break; default: - fprintf(stderr, "bad character in dir_no\n"); + (void)fprintf(stderr, "bad character in dir_no\n"); break; } - return (dir); + return (dirno); }