diff --git a/Makefile b/Makefile index 7a82752..91b5fc4 100644 --- a/Makefile +++ b/Makefile @@ -94,7 +94,7 @@ ALLDIRS = games/ sbin/ bin/ dev/ etc/ tmp/ lib/ libexec/ share/ include/ var/run/ var/log/ var/lock/ games/ games/lib/ include/sys/ \ include/machine/ include/arpa/ include/smallc/ \ include/smallc/sys/ share/misc/ share/smallc/ include/sys/ \ - games/lib/ + games/lib/ games/lib/atc/ BDEVS = dev/rd0!b0:0 dev/rd0a!b0:1 dev/rd0b!b0:2 dev/rd0c!b0:3 dev/rd0d!b0:4 BDEVS += dev/rd1!b1:0 dev/rd1a!b1:1 dev/rd1b!b1:2 dev/rd1c!b1:3 dev/rd1d!b1:4 BDEVS += dev/rd2!b2:0 dev/rd2a!b2:1 dev/rd2b!b2:2 dev/rd2c!b2:3 dev/rd2d!b2:4 @@ -194,11 +194,11 @@ else endif # TODO: make it relative to Target -installflash: +installflash: sudo pic32prog sys/pic32/fubarino/unix.hex # TODO: make it relative to Target -installboot: +installboot: sudo pic32prog sys/pic32/fubarino/bootloader.hex .profile: etc/root/dot.profile diff --git a/include/curses.h b/include/curses.h index 0370865..ba1e5e3 100644 --- a/include/curses.h +++ b/include/curses.h @@ -181,6 +181,8 @@ int waddstr (WINDOW *, char *); int wgetstr (WINDOW *, char *); int wdeleteln (WINDOW *); void mvcur(int ly, int lx, int y, int x); +void overwrite(WINDOW *win1, WINDOW *win2); +void wclrtobot(WINDOW *win); /* * Used to be in unctrl.h. diff --git a/src/games/Makefile b/src/games/Makefile index e20f0dc..130d803 100644 --- a/src/games/Makefile +++ b/src/games/Makefile @@ -11,8 +11,8 @@ CFLAGS += -Werror -Wall -Os # Programs that live in subdirectories, and have makefiles of their own. # -SUBDIR = adventure backgammon battlestar rogue sail trek -# TODO: atc boggle btlgammon cribbage +SUBDIR = adventure atc backgammon battlestar rogue sail trek +# TODO: boggle btlgammon cribbage # fortune hangman hunt mille monop phantasia quiz robots # sail snake warp diff --git a/src/games/atc/.gitignore b/src/games/atc/.gitignore new file mode 100644 index 0000000..8130118 --- /dev/null +++ b/src/games/atc/.gitignore @@ -0,0 +1,2 @@ +atc +y.tab.h diff --git a/src/games/atc/Makefile b/src/games/atc/Makefile index 285e11c..95e5999 100644 --- a/src/games/atc/Makefile +++ b/src/games/atc/Makefile @@ -5,26 +5,31 @@ # # @(#)Makefile 5.1.2 (2.11BSD) 1999/10/25 # +TOPSRC = $(shell cd ../../..; pwd) +include $(TOPSRC)/target.mk +#include $(TOPSRC)/cross.mk -DESTDIR = -CFLAGS = -O -DSYSV -DDEST=\"${DESTDIR}/usr/games/lib/atc/\" -YFLAGS = -d -LIBS = -ll -lm -lcurses -ltermcap -OBJS = extern.o grammar.o input.o lex.o list.o log.o main.o tunable.o \ - graphics.o update.o +CFLAGS = -Os -g -Werror -Wall +CFLAGS += -DBSD -DDEST=\"/games/lib/atc/\" +#CFLAGS += -DSYSV -DDEST=\"games/\" +YFLAGS = -d +LEX = lex +LIBS = -lm -lcurses -ltermcap +OBJS = extern.o grammar.o input.o lex.o list.o log.o main.o tunable.o \ + graphics.o update.o -all: atc +all: atc -atc: ${OBJS} - ${CC} ${OBJS} ${LIBS} -o $@ +atc: $(OBJS) + $(CC) $(LDFLAGS) -o atc.elf $(OBJS) $(LIBS) + $(OBJDUMP) -S atc.elf > atc.dis + $(SIZE) atc.elf + $(ELF2AOUT) atc.elf $@ && rm atc.elf clean: - rm -f *.o core atc grammar.c y.tab.h y.tab.c lex.yy.c lex.c + rm -f *.o *.0 *.elf atc *.elf *.dis tags *~ grammar.c lex.c y.tab.h -install: - -[ -d ${DESTDIR}/usr/games/lib/atc ] || mkdir ${DESTDIR}/usr/games/lib/atc - chmod 700 ${DESTDIR}/usr/games/lib/atc - chown games.bin ${DESTDIR}/usr/games/lib/atc - (cd games; install -c -o games -g bin -m 600 * ${DESTDIR}/usr/games/lib/atc) - install -s -o games -g bin -m 4700 atc ${DESTDIR}/usr/games/hide/atc - (cd ${DESTDIR}/usr/games; rm -f atc; ln -s dm atc; chown games.bin atc) +install: all + install atc $(DESTDIR)/games/ + mkdir -p ${DESTDIR}/games/lib/atc + cp -p games/* ${DESTDIR}/games/lib/atc diff --git a/src/games/atc/extern.c b/src/games/atc/extern.c index 203ee8b..94376e2 100644 --- a/src/games/atc/extern.c +++ b/src/games/atc/extern.c @@ -12,7 +12,7 @@ char GAMES[] = "Game_List", LOG[] = "ATC_scores"; -int clock, safe_planes, start_time, test_mode; +int clocktick, safe_planes, start_time, test_mode; char *file; diff --git a/src/games/atc/extern.h b/src/games/atc/extern.h index c4ef642..3590f1c 100644 --- a/src/games/atc/extern.h +++ b/src/games/atc/extern.h @@ -9,7 +9,7 @@ extern char GAMES[], LOG[], *file; -extern int clock, safe_planes, start_time, test_mode; +extern int clocktick, safe_planes, start_time, test_mode; extern FILE *filein, *fileout; @@ -22,3 +22,29 @@ extern struct sgttyb tty_start, tty_new; extern DISPLACEMENT displacement[MAXDIR]; extern PLANE *findplane(), *newplane(); + +int dir_no(int ch); +void ioclrtoeol(int pos); +void iomove(int pos); +void ioaddstr(int pos, char *str); +void ioclrtobot(void); +int getAChar(void); +void done_screen(void); +void redraw(void); +void ioerror(int pos, int len, char *str); +int number(int l); +void loser(PLANE *p, char *s); +void init_gr(void); +int yyparse(void); +void setup_screen(C_SCREEN *scp); +int addplane(void); +void log_score(int list_em); +void quit(int sig); +void update(int sig); +int getcommand(void); +void planewin(void); +int name(PLANE *p); +void erase_all(void); +void append(LIST *l, PLANE *p); +void delete(LIST *l, PLANE *p); +void draw_all(void); diff --git a/src/games/atc/grammar.y b/src/games/atc/grammar.y index 519bfd7..5290f5e 100644 --- a/src/games/atc/grammar.y +++ b/src/games/atc/grammar.y @@ -27,12 +27,15 @@ int errors = 0; int line = 1; + +int yylex(void); +int yyerror(char *s); %} %% file: bunch_of_defs { if (checkdefs() < 0) return (errors); } bunch_of_lines - { + { if (sp->num_exits + sp->num_airports < 2) yyerror("Need at least 2 airports and/or exits."); return (errors); @@ -83,7 +86,7 @@ hdef: else if ($3 < 3) return (yyerror("'height' is too small.")); else - sp->height = $3; + sp->height = $3; } ; @@ -95,7 +98,7 @@ wdef: else if ($3 < 3) return (yyerror("'width' is too small.")); else - sp->width = $3; + sp->width = $3; } ; @@ -133,7 +136,7 @@ Bpoint: + REALLOC) * sizeof (BEACON)); else sp->beacon = (BEACON *) realloc(sp->beacon, - (sp->num_beacons + REALLOC) * + (sp->num_beacons + REALLOC) * sizeof (BEACON)); if (sp->beacon == NULL) return (yyerror("No memory available.")); @@ -159,11 +162,11 @@ Epoint: if (sp->num_exits % REALLOC == 0) { if (sp->exit == NULL) - sp->exit = (EXIT *) malloc((sp->num_exits + + sp->exit = (EXIT *) malloc((sp->num_exits + REALLOC) * sizeof (EXIT)); else sp->exit = (EXIT *) realloc(sp->exit, - (sp->num_exits + REALLOC) * + (sp->num_exits + REALLOC) * sizeof (EXIT)); if (sp->exit == NULL) return (yyerror("No memory available.")); @@ -196,7 +199,7 @@ Apoint: + REALLOC) * sizeof(AIRPORT)); else sp->airport = (AIRPORT *) realloc(sp->airport, - (sp->num_airports + REALLOC) * + (sp->num_airports + REALLOC) * sizeof(AIRPORT)); if (sp->airport == NULL) return (yyerror("No memory available.")); @@ -223,7 +226,7 @@ Lline: { if (sp->num_lines % REALLOC == 0) { if (sp->line == NULL) - sp->line = (LINE *) malloc((sp->num_lines + + sp->line = (LINE *) malloc((sp->num_lines + REALLOC) * sizeof (LINE)); else sp->line = (LINE *) realloc(sp->line, @@ -242,14 +245,14 @@ Lline: ; %% -check_edge(x, y) +void check_edge(x, y) { - if (!(x == 0) && !(x == sp->width - 1) && + if (!(x == 0) && !(x == sp->width - 1) && !(y == 0) && !(y == sp->height - 1)) yyerror("edge value not on edge."); } -check_point(x, y) +void check_point(x, y) { if (x < 1 || x >= sp->width - 1) yyerror("X value out of range."); @@ -257,7 +260,7 @@ check_point(x, y) yyerror("Y value out of range."); } -check_linepoint(x, y) +void check_linepoint(x, y) { if (x < 0 || x >= sp->width) yyerror("X value out of range."); @@ -265,7 +268,7 @@ check_linepoint(x, y) yyerror("Y value out of range."); } -check_line(x1, y1, x2, y2) +void check_line(x1, y1, x2, y2) { int d1, d2; @@ -279,7 +282,7 @@ check_line(x1, y1, x2, y2) yyerror("Bad line endpoints."); } -yyerror(s) +int yyerror(char *s) { fprintf(stderr, "\"%s\": line %d: %s\n", file, line, s); errors++; @@ -287,7 +290,7 @@ yyerror(s) return (errors); } -check_edir(x, y, dir) +void check_edir(x, y, dir) { int bad = 0; @@ -299,7 +302,7 @@ check_edir(x, y, dir) y = 2; else if (y != 0) y = 1; - + switch (x * 10 + y) { case 00: if (dir != 3) bad++; break; case 01: if (dir < 1 || dir > 3) bad++; break; @@ -318,11 +321,11 @@ check_edir(x, y, dir) yyerror("Bad direction for entrance at exit."); } -check_adir(x, y, dir) +void check_adir(x, y, dir) { } -checkdefs() +int checkdefs() { int err = 0; diff --git a/src/games/atc/graphics.c b/src/games/atc/graphics.c index f655f89..d72a0b9 100644 --- a/src/games/atc/graphics.c +++ b/src/games/atc/graphics.c @@ -22,7 +22,7 @@ WINDOW *radar, *cleanradar, *credit, *input, *planes; -getAChar() +int getAChar() { #ifdef BSD return (getchar()); @@ -35,7 +35,7 @@ getAChar() #endif } -erase_all() +void erase_all() { PLANE *pp; @@ -49,7 +49,7 @@ erase_all() } } -draw_all() +void draw_all() { PLANE *pp; @@ -68,19 +68,37 @@ draw_all() fflush(stdout); } -init_gr() +void init_gr() { static char buffer[BUFSIZ]; initscr(); setbuf(stdout, buffer); input = newwin(INPUT_LINES, COLS - PLANE_COLS, LINES - INPUT_LINES, 0); - credit = newwin(INPUT_LINES, PLANE_COLS, LINES - INPUT_LINES, + credit = newwin(INPUT_LINES, PLANE_COLS, LINES - INPUT_LINES, COLS - PLANE_COLS); planes = newwin(LINES - INPUT_LINES, PLANE_COLS, 0, COLS - PLANE_COLS); } -setup_screen(scp) +void draw_line(w, x, y, lx, ly, s) + WINDOW *w; + char *s; +{ + int dx, dy; + + dx = SGN(lx - x); + dy = SGN(ly - y); + for (;;) { + wmove(w, y, x * 2); + waddstr(w, s); + if (x == lx && y == ly) + break; + x += dx; + y += dy; + } +} + +void setup_screen(scp) C_SCREEN *scp; { register int i, j; @@ -164,32 +182,14 @@ setup_screen(scp) wmove(radar, scp->airport[i].y, scp->airport[i].x * 2); waddstr(radar, str); } - + overwrite(radar, cleanradar); wrefresh(radar); wrefresh(credit); fflush(stdout); } -draw_line(w, x, y, lx, ly, s) - WINDOW *w; - char *s; -{ - int dx, dy; - - dx = SGN(lx - x); - dy = SGN(ly - y); - for (;;) { - wmove(w, y, x * 2); - waddstr(w, s); - if (x == lx && y == ly) - break; - x += dx; - y += dy; - } -} - -ioclrtoeol(pos) +void ioclrtoeol(pos) { wmove(input, 0, pos); wclrtoeol(input); @@ -197,14 +197,14 @@ ioclrtoeol(pos) fflush(stdout); } -iomove(pos) +void iomove(pos) { wmove(input, 0, pos); wrefresh(input); fflush(stdout); } -ioaddstr(pos, str) +void ioaddstr(pos, str) char *str; { wmove(input, 0, pos); @@ -213,14 +213,14 @@ ioaddstr(pos, str) fflush(stdout); } -ioclrtobot() +void ioclrtobot() { wclrtobot(input); wrefresh(input); fflush(stdout); } -ioerror(pos, len, str) +void ioerror(pos, len, str) char *str; { int i; @@ -234,7 +234,7 @@ ioerror(pos, len, str) fflush(stdout); } -quit() +void quit(int sig) { int c, y, x; #ifdef BSD @@ -271,10 +271,9 @@ quit() wmove(input, y, x); wrefresh(input); fflush(stdout); - return; } -planewin() +void planewin() { PLANE *pp; char *command(); @@ -289,7 +288,7 @@ planewin() #ifdef SYSV wclrtobot(planes); #endif - wprintw(planes, "Time: %-4d Safe: %d", clock, safe_planes); + wprintw(planes, "Time: %-4d Safe: %d", clocktick, safe_planes); wmove(planes, 2, 0); waddstr(planes, "pl dt comm"); @@ -317,7 +316,7 @@ planewin() fflush(stdout); } -loser(p, s) +void loser(p, s) PLANE *p; char *s; { @@ -351,7 +350,7 @@ loser(p, s) exit(0); } -redraw() +void redraw() { clear(); refresh(); @@ -370,7 +369,7 @@ redraw() } -done_screen() +void done_screen() { clear(); refresh(); diff --git a/src/games/atc/include.h b/src/games/atc/include.h index 084a3e5..66e3858 100644 --- a/src/games/atc/include.h +++ b/src/games/atc/include.h @@ -8,11 +8,20 @@ */ #include +#include #include -#ifdef SYSV +#include +#include +#include #include +#include +#include +#include +#ifdef SYSV +#include #endif #include +#include #ifdef BSD #include @@ -21,25 +30,17 @@ #endif #ifdef SYSV -#include -#include -#include -#include +#include #endif #include #include - #include -#ifdef SYSV -#define index strchr -#define rindex strrchr #define bcopy(a,b,c) memcpy((b), (a), (c)) #define bzero(a,b) memset((a), '\0', (b)) -#define srandom srand -#define random rand -#define sgttyb termio +#ifdef SYSV +#define sgttyb termios #define sg_erase c_cc[2] #define sg_kill c_cc[3] #endif diff --git a/src/games/atc/input.c b/src/games/atc/input.c index 7a31b54..6965900 100644 --- a/src/games/atc/input.c +++ b/src/games/atc/input.c @@ -6,11 +6,6 @@ * * For more info on this and all of my stuff, mail edjames@berkeley.edu. */ - -#ifndef lint -static char sccsid[] = "@(#)input.c 1.2 (Berkeley) 10/22/87"; -#endif not lint - #include "include.h" #define MAXRULES 6 @@ -56,8 +51,8 @@ typedef struct { #define NUMSTATES NUMELS(st) -char *setplane(), *circle(), *left(), *right(), *Left(), *Right(), - *beacon(), *ex_it(), *climb(), *descend(), *setalt(), *setrelalt(), +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(); @@ -67,17 +62,17 @@ RULE state0[] = { { ALPHATOKEN, 1, "%c:", setplane}, { CRTOKEN, -1, "", NULL }, #endif { HELPTOKEN, 12, " [a-z]", NULL }}, - state1[] = { { 't', 2, " turn", turn }, - { 'a', 3, " altitude:", 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 }, + state2[] = { { 'l', 6, " left", left }, + { 'r', 6, " right", right }, { 'L', 4, " left 90", Left }, - { 'R', 4, " right 90", Right }, + { 'R', 4, " right 90", Right }, { 't', 11, " towards", NULL }, { 'w', 4, " to 0", to_dir }, { 'e', 4, " to 45", to_dir }, @@ -88,14 +83,14 @@ RULE state0[] = { { ALPHATOKEN, 1, "%c:", setplane}, { 'a', 4, " to 270", to_dir }, { 'q', 4, " to 315", to_dir }, { HELPTOKEN, 12, " lrLRt", NULL }}, - state3[] = { { '+', 10, " climb", climb }, - { 'c', 10, " climb", climb }, - { '-', 10, " descend", descend }, - { 'd', 10, " descend", descend }, + 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 }, - { 'a', 9, " at", NULL }, + state4[] = { { '@', 9, " at", NULL }, + { 'a', 9, " at", NULL }, { RETTOKEN, -1, "", NULL }, #ifdef SYSV { CRTOKEN, -1, "", NULL }, @@ -113,9 +108,9 @@ RULE state0[] = { { ALPHATOKEN, 1, "%c:", setplane}, { 'z', 4, " 225", rel_dir }, { 'a', 4, " 270", rel_dir }, { 'q', 4, " 315", rel_dir }, - { RETTOKEN, -1, "", NULL }, + { RETTOKEN, -1, "", NULL }, #ifdef SYSV - { CRTOKEN, -1, "", NULL }, + { CRTOKEN, -1, "", NULL }, #endif { HELPTOKEN, 12, " @a",NULL }}, state7[] = { { RETTOKEN, -1, "", NULL }, @@ -130,7 +125,7 @@ RULE state0[] = { { ALPHATOKEN, 1, "%c:", setplane}, { HELPTOKEN, 12, " b*", NULL }}, state10[] = { { NUMTOKEN, 7, " %c000 ft", setrelalt}, { HELPTOKEN, 12, " [0-9]", NULL }}, - state11[] = { { 'b', 8, " beacon #", beacon }, + state11[] = { { 'b', 8, " beacon #", beacon }, { '*', 8, " beacon #", beacon }, { 'e', 8, " exit #", ex_it }, { 'a', 8, " airport #", airport }, @@ -153,7 +148,7 @@ int level; int tval; int dest_type, dest_no, dir; -pop() +int pop() { if (level == 0) return (-1); @@ -167,7 +162,7 @@ pop() return (0); } -rezero() +void rezero() { iomove(0); @@ -179,7 +174,7 @@ rezero() strcpy(T_STR, ""); } -push(ruleno, ch) +void push(ruleno, ch) { int newstate, newpos; @@ -200,7 +195,77 @@ push(ruleno, ch) strcpy(T_STR, ""); } -getcommand() +int gettoken() +{ + while ((tval = getAChar()) == REDRAWTOKEN || tval == SHELLTOKEN) + { + if (tval == SHELLTOKEN) + { +#ifdef BSD + struct itimerval itv; + itv.it_value.tv_sec = 0; + itv.it_value.tv_usec = 0; + setitimer(ITIMER_REAL, &itv, NULL); +#endif +#ifdef SYSV + int aval; + aval = alarm(0); +#endif + if (fork() == 0) /* child */ + { + char *shell, *base, *getenv(), *strrchr(); + + setuid(getuid()); /* turn off setuid bit */ + done_screen(); + + /* run user's favorite shell */ + if ((shell = getenv("SHELL")) != NULL) + { + base = strrchr(shell, '/'); + if (base == NULL) + base = shell; + else + base++; + execl(shell, base, (char*)0); + } + else + execl("/bin/sh", "sh", (char*)0); + + exit(0); /* oops */ + } + + wait(0); +#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; + itv.it_interval.tv_usec = 0; + setitimer(ITIMER_REAL, &itv, NULL); +#endif +#ifdef SYSV + ioctl(fileno(stdin), TCSETAW, &tty_new); + alarm(aval); +#endif + } + redraw(); + } + + if (isdigit(tval)) + return (NUMTOKEN); + else if (isalpha(tval)) + return (ALPHATOKEN); + else + return (tval); +} + +void noise() +{ + putchar('\07'); + fflush(stdout); +} + +int getcommand() { int c, i, done; char *s, *(*func)(); @@ -235,7 +300,7 @@ getcommand() return (1); /* forced update */ dest_type = T_NODEST; - + for (i = 0; i < level; i++) { func = st[stack[i].state].rule[stack[i].rule].func; if (func != NULL) @@ -258,76 +323,6 @@ getcommand() return (0); } -noise() -{ - putchar('\07'); - fflush(stdout); -} - -gettoken() -{ - while ((tval = getAChar()) == REDRAWTOKEN || tval == SHELLTOKEN) - { - if (tval == SHELLTOKEN) - { -#ifdef BSD - struct itimerval itv; - itv.it_value.tv_sec = 0; - itv.it_value.tv_usec = 0; - setitimer(ITIMER_REAL, &itv, NULL); -#endif -#ifdef SYSV - int aval; - aval = alarm(0); -#endif - if (fork() == 0) /* child */ - { - char *shell, *base, *getenv(), *strrchr(); - - setuid(getuid()); /* turn off setuid bit */ - done_screen(); - - /* run user's favorite shell */ - if ((shell = getenv("SHELL")) != NULL) - { - base = strrchr(shell, '/'); - if (base == NULL) - base = shell; - else - base++; - execl(shell, base, 0); - } - else - execl("/bin/sh", "sh", 0); - - exit(0); /* oops */ - } - - wait(0); -#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; - itv.it_interval.tv_usec = 0; - setitimer(ITIMER_REAL, &itv, NULL); -#endif -#ifdef SYSV - ioctl(fileno(stdin), TCSETAW, &tty_new); - alarm(aval); -#endif - } - redraw(); - } - - if (isdigit(tval)) - return (NUMTOKEN); - else if (isalpha(tval)) - return (ALPHATOKEN); - else - return (tval); -} - char * setplane(c) { @@ -604,10 +599,9 @@ ignore(c) return (NULL); } -dir_no(ch) - char ch; +int dir_no(ch) { - int dir; + int dir = 0; switch (ch) { case 'w': dir = 0; break; diff --git a/src/games/atc/lex.l b/src/games/atc/lex.l index dde6315..d0b0520 100644 --- a/src/games/atc/lex.l +++ b/src/games/atc/lex.l @@ -8,9 +8,13 @@ * For more info on this and all of my stuff, mail edjames@berkeley.edu. */ +#define YY_NO_INPUT +#define YY_SKIP_YYWRAP #include "y.tab.h" +#define yywrap() 0 extern int line; %} +%option nounput %% [0-9]+ { yylval.ival = atoi(yytext); return(ConstOp); } height { return(HeightOp); } diff --git a/src/games/atc/list.c b/src/games/atc/list.c index 5498e59..d9d6f4f 100644 --- a/src/games/atc/list.c +++ b/src/games/atc/list.c @@ -15,7 +15,7 @@ newplane() return ((PLANE *) calloc(1, sizeof (PLANE))); } -append(l, p) +void append(l, p) LIST *l; PLANE *p; { @@ -53,13 +53,13 @@ append(l, p) } } -delete(l, p) +void delete(l, p) LIST *l; PLANE *p; { if (l->head == NULL) loser(p, "deleted a non-existant plane! Get help!"); - + if (l->head == p && l->tail == p) l->head = l->tail = NULL; else if (l->head == p) { diff --git a/src/games/atc/log.c b/src/games/atc/log.c index cf92d85..9f96c4e 100644 --- a/src/games/atc/log.c +++ b/src/games/atc/log.c @@ -6,14 +6,9 @@ * * For more info on this and all of my stuff, mail edjames@berkeley.edu. */ - -#ifndef lint -static char sccsid[] = "@(#)log.c 1.4 (Berkeley) 12/26/87"; -#endif not lint - #include "include.h" -compar(a, b) +int compar(a, b) SCORE *a, *b; { if (b->planes == a->planes) @@ -51,16 +46,14 @@ timestr(t) return (s); } -log_score(list_em) +void log_score(list_em) { register int i, fd, num_scores = 0, good, changed = 0, found = 0; struct passwd *pw; FILE *fp; - char *cp, logstr[BUFSIZ], *index(), *rindex(); + char *cp, logstr[BUFSIZ]; SCORE score[100], thisscore; -#ifdef SYSV struct utsname name; -#endif strcpy(logstr, SPECIAL_DIR); strcat(logstr, LOG); @@ -69,16 +62,16 @@ log_score(list_em) fd = open(logstr, O_CREAT|O_RDWR, 0644); if (fd < 0) { perror(logstr); - return (-1); + return; } /* - * This is done to take advantage of stdio, while still + * This is done to take advantage of stdio, while still * allowing a O_CREAT during the open(2) of the log file. */ fp = fdopen(fd, "r+"); if (fp == NULL) { perror(logstr); - return (-1); + return; } #ifdef BSD if (flock(fileno(fp), LOCK_EX) < 0) @@ -88,14 +81,14 @@ log_score(list_em) #endif { perror("flock"); - return (-1); + return; } for (;;) { good = fscanf(fp, "%s %s %s %d %d %d", - score[num_scores].name, - score[num_scores].host, + score[num_scores].name, + score[num_scores].host, score[num_scores].game, - &score[num_scores].planes, + &score[num_scores].planes, &score[num_scores].time, &score[num_scores].real_time); if (good != 6 || ++num_scores >= NUM_SCORES) @@ -103,32 +96,24 @@ log_score(list_em) } if (!test_mode && !list_em) { if ((pw = (struct passwd *) getpwuid(getuid())) == NULL) { - fprintf(stderr, + fprintf(stderr, "getpwuid failed for uid %d. Who are you?\n", getuid()); - return (-1); + return; } strcpy(thisscore.name, pw->pw_name); -#ifdef BSD - if (gethostname(thisscore.host, sizeof (thisscore.host)) < 0) { - perror("gethostname"); - return (-1); - } -#endif -#ifdef SYSV uname(&name); strcpy(thisscore.host, name.sysname); -#endif - cp = rindex(file, '/'); + cp = strrchr(file, '/'); if (cp == NULL) { fprintf(stderr, "log: where's the '/' in %s?\n", file); - return (-1); + return; } cp++; strcpy(thisscore.game, cp); - thisscore.time = clock; + thisscore.time = clocktick; thisscore.planes = safe_planes; thisscore.real_time = time(0) - start_time; @@ -153,7 +138,7 @@ log_score(list_em) if (num_scores < NUM_SCORES) num_scores++; bcopy(&score[i], - &score[num_scores - 1], + &score[num_scores - 1], sizeof (score[i])); bcopy(&thisscore, &score[i], sizeof (score[i])); @@ -163,7 +148,7 @@ log_score(list_em) } } if (!found && !changed && num_scores < NUM_SCORES) { - bcopy(&thisscore, &score[num_scores], + bcopy(&thisscore, &score[num_scores], sizeof (score[num_scores])); num_scores++; changed++; @@ -178,7 +163,7 @@ log_score(list_em) rewind(fp); for (i = 0; i < num_scores; i++) fprintf(fp, "%s %s %s %d %d %d\n", - score[i].name, score[i].host, + score[i].name, score[i].host, score[i].game, score[i].planes, score[i].time, score[i].real_time); } else { @@ -196,11 +181,11 @@ log_score(list_em) /* lock will evaporate upon close */ #endif fclose(fp); - printf("%2s: %-8s %-8s %-18s %4s %9s %4s\n", "#", "name", "host", + printf("%2s: %-8s %-8s %-18s %4s %9s %4s\n", "#", "name", "host", "game", "time", "real time", "planes safe"); puts("-------------------------------------------------------------------------------"); for (i = 0; i < num_scores; i++) { - cp = index(score[i].host, '.'); + cp = strchr(score[i].host, '.'); if (cp != NULL) *cp = '\0'; printf("%2d: %-8s %-8s %-18s %4d %9s %4d\n", i + 1, @@ -209,5 +194,4 @@ log_score(list_em) score[i].planes); } putchar('\n'); - return (0); } diff --git a/src/games/atc/main.c b/src/games/atc/main.c index 24218d7..a104595 100644 --- a/src/games/atc/main.c +++ b/src/games/atc/main.c @@ -9,169 +9,7 @@ #include "include.h" -main(ac, av) - char *av[]; -{ - int seed; - int f_usage = 0, f_list = 0, f_showscore = 0; - int f_printpath = 0; - char *file = NULL; - char *name, *ptr; -#ifdef BSD - struct itimerval itv; -#endif - extern int update(), quit(), log_score(); - extern char *default_game(), *okay_game(); - - start_time = seed = time(0); - - name = *av++; - while (*av) { -#ifndef SAVEDASH - if (**av == '-') - *++*av; - else - break; -#endif - ptr = *av++; - while (*ptr) { - switch (*ptr) { - case '?': - case 'u': - f_usage++; - break; - case 'l': - f_list++; - break; - case 's': - case 't': - f_showscore++; - break; - case 'p': - f_printpath++; - break; - case 'r': - seed = atoi(*av); - av++; - break; - case 'f': - case 'g': - file = *av; - av++; - break; - default: - fprintf(stderr, "Unknown option '%c'\n", *ptr, - name); - f_usage++; - break; - } - ptr++; - } - } - srandom(seed); - - if (f_usage) - fprintf(stderr, - "Usage: %s -[u?lstp] [-[gf] game_name] [-r random seed]\n", - name); - if (f_showscore) - log_score(1); - if (f_list) - list_games(); - if (f_printpath) { - char buf[100]; - - strcpy(buf, SPECIAL_DIR); - buf[strlen(buf) - 1] = '\0'; - puts(buf); - } - - if (f_usage || f_showscore || f_list || f_printpath) - exit(0); - - if (file == NULL) - file = default_game(); - else - file = okay_game(file); - - if (file == NULL || read_file(file) < 0) - exit(1); - - init_gr(); - setup_screen(sp); - - addplane(); - - signal(SIGINT, quit); - signal(SIGQUIT, quit); -#ifdef BSD - signal(SIGTSTP, SIG_IGN); - signal(SIGSTOP, SIG_IGN); -#endif - signal(SIGHUP, log_score); - signal(SIGTERM, log_score); - -#ifdef BSD - ioctl(fileno(stdin), TIOCGETP, &tty_start); - bcopy(&tty_start, &tty_new, sizeof(tty_new)); - tty_new.sg_flags |= CBREAK; - tty_new.sg_flags &= ~ECHO; - ioctl(fileno(stdin), TIOCSETP, &tty_new); -#endif - -#ifdef SYSV - ioctl(fileno(stdin), TCGETA, &tty_start); - bcopy(&tty_start, &tty_new, sizeof(tty_new)); - tty_new.c_lflag &= ~ICANON; - tty_new.c_lflag &= ~ECHO; - tty_new.c_cc[VMIN] = 1; - tty_new.c_cc[VTIME] = 0; - ioctl(fileno(stdin), TCSETAW, &tty_new); -#endif - - signal(SIGALRM, update); - -#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); -#endif -#ifdef SYSV - alarm(sp->update_secs); -#endif - - for (;;) { - if (getcommand() != 1) - planewin(); - else { -#ifdef BSD - itv.it_value.tv_sec = 0; - itv.it_value.tv_usec = 0; - setitimer(ITIMER_REAL, &itv, NULL); -#endif -#ifdef SYSV - alarm(0); -#endif - - update(); - -#ifdef BSD - itv.it_value.tv_sec = sp->update_secs; - itv.it_value.tv_usec = 0; - itv.it_interval.tv_sec = sp->update_secs; - itv.it_interval.tv_usec = 0; - setitimer(ITIMER_REAL, &itv, NULL); -#endif -#ifdef SYSV - alarm(sp->update_secs); -#endif - } - } -} - -read_file(s) +int read_file(s) char *s; { extern FILE *yyin; @@ -252,7 +90,7 @@ okay_game(s) return (ret); } -list_games() +int list_games() { FILE *fp; char line[256], games[256]; @@ -277,3 +115,162 @@ list_games() } return (0); } + +int main(ac, av) + char *av[]; +{ + int seed; + int f_usage = 0, f_list = 0, f_showscore = 0; + int f_printpath = 0; + char *file = NULL; + char *name, *ptr; +#ifdef BSD + struct itimerval itv; +#endif + + start_time = seed = time(0); + + name = *av++; + while (*av) { +#ifndef SAVEDASH + if (**av == '-') + (*av)++; + else + break; +#endif + ptr = *av++; + while (*ptr) { + switch (*ptr) { + case '?': + case 'u': + f_usage++; + break; + case 'l': + f_list++; + break; + case 's': + case 't': + f_showscore++; + break; + case 'p': + f_printpath++; + break; + case 'r': + seed = atoi(*av); + av++; + break; + case 'f': + case 'g': + file = *av; + av++; + break; + default: + fprintf(stderr, "Unknown option '%c'\n", *ptr); + f_usage++; + break; + } + ptr++; + } + } + srandom(seed); + + if (f_usage) + fprintf(stderr, + "Usage: %s -[u?lstp] [-[gf] game_name] [-r random seed]\n", + name); + if (f_showscore) + log_score(1); + if (f_list) + list_games(); + if (f_printpath) { + char buf[100]; + + strcpy(buf, SPECIAL_DIR); + buf[strlen(buf) - 1] = '\0'; + puts(buf); + } + + if (f_usage || f_showscore || f_list || f_printpath) + exit(0); + + if (file == NULL) + file = default_game(); + else + file = okay_game(file); + + if (file == NULL || read_file(file) < 0) + exit(1); + + init_gr(); + setup_screen(sp); + + addplane(); + + signal(SIGINT, quit); + signal(SIGQUIT, quit); +#ifdef BSD + signal(SIGTSTP, SIG_IGN); + signal(SIGSTOP, SIG_IGN); +#endif + signal(SIGHUP, log_score); + signal(SIGTERM, log_score); + +#ifdef BSD + ioctl(fileno(stdin), TIOCGETP, &tty_start); + bcopy(&tty_start, &tty_new, sizeof(tty_new)); + tty_new.sg_flags |= CBREAK; + tty_new.sg_flags &= ~ECHO; + ioctl(fileno(stdin), TIOCSETP, &tty_new); +#endif + +#ifdef SYSV + ioctl(fileno(stdin), TCGETA, &tty_start); + bcopy(&tty_start, &tty_new, sizeof(tty_new)); + tty_new.c_lflag &= ~ICANON; + tty_new.c_lflag &= ~ECHO; + tty_new.c_cc[VMIN] = 1; + tty_new.c_cc[VTIME] = 0; + ioctl(fileno(stdin), TCSETAW, &tty_new); +#endif + + signal(SIGALRM, update); + +#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); +#endif +#ifdef SYSV + alarm(sp->update_secs); +#endif + + for (;;) { + if (getcommand() != 1) + planewin(); + else { +#ifdef BSD + itv.it_value.tv_sec = 0; + itv.it_value.tv_usec = 0; + setitimer(ITIMER_REAL, &itv, NULL); +#endif +#ifdef SYSV + alarm(0); +#endif + + update(0); + +#ifdef BSD + itv.it_value.tv_sec = sp->update_secs; + itv.it_value.tv_usec = 0; + itv.it_interval.tv_sec = sp->update_secs; + itv.it_interval.tv_usec = 0; + setitimer(ITIMER_REAL, &itv, NULL); +#endif +#ifdef SYSV + alarm(sp->update_secs); +#endif + } + } +} diff --git a/src/games/atc/update.c b/src/games/atc/update.c index cd8713a..9d9d84b 100644 --- a/src/games/atc/update.c +++ b/src/games/atc/update.c @@ -6,24 +6,29 @@ * * For more info on this and all of my stuff, mail edjames@berkeley.edu. */ - -#if !defined(lint) && defined(DOSCCS) -static char sccsid[] = "@(#)update.c 1.3.1 (2.11BSD) 1999/10/25"; -#endif - #include "include.h" -update() +int too_close(p1, p2, dist) + PLANE *p1, *p2; +{ + if (ABS(p1->altitude - p2->altitude) <= dist && + ABS(p1->xpos - p2->xpos) <= dist && ABS(p1->ypos - p2->ypos) <= dist) + return (1); + else + return (0); +} + +void update(int sig) { int i, dir_diff, unclean; - PLANE *pp, *p1, *p2, *p; + PLANE *pp, *p1, *p2; sigset_t set, oset; sigemptyset(&set); sigaddset(&set, SIGINT); (void)sigprocmask(SIG_BLOCK, &set, &oset); - clock++; + clocktick++; erase_all(); /* put some planes in the air */ @@ -42,7 +47,7 @@ update() /* do altitude change and basic movement */ for (pp = air.head; pp != NULL; pp = pp->next) { /* type 0 only move every other turn */ - if (pp->plane_type == 0 && clock & 1) + if (pp->plane_type == 0 && clocktick & 1) continue; pp->fuel--; @@ -117,10 +122,10 @@ update() if (pp->xpos == sp->airport[i].x && pp->ypos == sp->airport[i].y) { if (pp->dest_type == T_AIRPORT) - loser(pp, + loser(pp, "landed at the wrong airport."); else - loser(pp, + loser(pp, "landed instead of exited."); } loser(pp, "crashed on the ground."); @@ -131,10 +136,10 @@ update() if (pp->xpos == sp->exit[i].x && pp->ypos == sp->exit[i].y) { if (pp->dest_type == T_EXIT) - loser(pp, + loser(pp, "exited via the wrong exit."); else - loser(pp, + loser(pp, "exited instead of landed."); } loser(pp, "illegally left the flight arena."); @@ -174,20 +179,35 @@ update() (void)sigprocmask(SIG_SETMASK, &oset, NULL); } +int dir_deg(d) +{ + switch (d) { + case 0: return (0); + case 1: return (45); + case 2: return (90); + case 3: return (135); + case 4: return (180); + case 5: return (225); + case 6: return (270); + case 7: return (315); + default: + return (-1); + } +} + char * command(pp) PLANE *pp; { static char buf[50], *bp, *comm_start; - char *index(); buf[0] = '\0'; bp = buf; - (void)sprintf(bp, "%c%d%c%c%d: ", name(pp), pp->altitude, + (void)sprintf(bp, "%c%d%c%c%d: ", name(pp), pp->altitude, (pp->fuel < LOWFUEL) ? '*' : ' ', (pp->dest_type == T_AIRPORT) ? 'A' : 'E', pp->dest_no); - comm_start = bp = index(buf, '\0'); + comm_start = bp = strchr(buf, '\0'); if (pp->altitude == 0) (void)sprintf(bp, "Holding @ A%d", pp->orig_no); else if (pp->new_dir >= MAXDIR || pp->new_dir < 0) @@ -195,19 +215,19 @@ command(pp) else if (pp->new_dir != pp->dir) (void)sprintf(bp, "%d", dir_deg(pp->new_dir)); - bp = index(buf, '\0'); + bp = strchr(buf, '\0'); if (pp->delayd) (void)sprintf(bp, " @ B%d", pp->delayd_no); - bp = index(buf, '\0'); - if (*comm_start == '\0' && + bp = strchr(buf, '\0'); + if (*comm_start == '\0' && (pp->status == S_UNMARKED || pp->status == S_IGNORED)) strcpy(bp, "---------"); return (buf); } /* char */ -name(p) +int name(p) PLANE *p; { if (p->plane_type == 0) @@ -216,17 +236,17 @@ name(p) return ('a' + p->plane_no); } -number(l) +int number(l) { if (l < 'a' && l > 'z' && l < 'A' && l > 'Z') return (-1); else if (l >= 'a' && l <= 'z') return (l - 'a'); - else + else return (l - 'A'); } -next_plane() +int next_plane() { static int last_plane = -1; PLANE *pp; @@ -254,7 +274,7 @@ next_plane() return (last_plane); } -addplane() +int addplane() { PLANE p, *pp, *p1; int i, num_starts, close, rnd, rnd2, pnum; @@ -337,29 +357,3 @@ findplane(n) return (pp); return (NULL); } - -too_close(p1, p2, dist) - PLANE *p1, *p2; -{ - if (ABS(p1->altitude - p2->altitude) <= dist && - ABS(p1->xpos - p2->xpos) <= dist && ABS(p1->ypos - p2->ypos) <= dist) - return (1); - else - return (0); -} - -dir_deg(d) -{ - switch (d) { - case 0: return (0); - case 1: return (45); - case 2: return (90); - case 3: return (135); - case 4: return (180); - case 5: return (225); - case 6: return (270); - case 7: return (315); - default: - return (-1); - } -}