BSD 4_3_Tahoe development
authorCSRG <csrg@ucbvax.Berkeley.EDU>
Tue, 10 Mar 1987 12:05:15 +0000 (04:05 -0800)
committerCSRG <csrg@ucbvax.Berkeley.EDU>
Tue, 10 Mar 1987 12:05:15 +0000 (04:05 -0800)
Work on file usr/src/games/atc/def.h
Work on file usr/src/games/atc/BUGS
Work on file usr/src/games/atc/lex.l
Work on file usr/src/games/atc/grammar.y
Work on file usr/src/games/atc/graphics.c
Work on file usr/src/games/atc/list.c
Work on file usr/src/games/atc/main.c
Work on file usr/src/games/atc/extern.h
Work on file usr/src/games/atc/struct.h
Work on file usr/src/games/atc/tunable.h

Synthesized-from: CSRG/cd2/4.3tahoe

usr/src/games/atc/BUGS [new file with mode: 0644]
usr/src/games/atc/def.h [new file with mode: 0644]
usr/src/games/atc/extern.h [new file with mode: 0644]
usr/src/games/atc/grammar.y [new file with mode: 0644]
usr/src/games/atc/graphics.c [new file with mode: 0644]
usr/src/games/atc/lex.l [new file with mode: 0644]
usr/src/games/atc/list.c [new file with mode: 0644]
usr/src/games/atc/main.c [new file with mode: 0644]
usr/src/games/atc/struct.h [new file with mode: 0644]
usr/src/games/atc/tunable.h [new file with mode: 0644]

diff --git a/usr/src/games/atc/BUGS b/usr/src/games/atc/BUGS
new file mode 100644 (file)
index 0000000..7d2af29
--- /dev/null
@@ -0,0 +1,4 @@
+log restarts if interrupted
+Still refreshes after exit
+Should ^Z be disabled?
+does not exit after hup
diff --git a/usr/src/games/atc/def.h b/usr/src/games/atc/def.h
new file mode 100644 (file)
index 0000000..9cc2749
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+
+#define AUTHOR_STR             "ATC - by Ed James"
+
+#define PI                     3.14159654
+
+#define LOWFUEL                        15
+
+#define REALLOC                        10
+
+#define SGN(x)                 ((x < 0) ? -1 : ((x > 0) ? 1 : 0))
+#define ABS(x)                 ((x < 0) ? -(x) : (x))
+#define DIR_FROM_DXDY(dx,dy)   ((int) (atan2((double)(dy), (double)(dx)) \
+                               * MAXDIR / (2 * PI) + 2.5 + MAXDIR) % MAXDIR)
+
+#define MAXDIR         8
+
+#define D_LEFT         1
+#define D_RIGHT                2
+#define D_UP           3
+#define D_DOWN         4
+
+#define T_NODEST       0
+#define T_BEACON       1
+#define T_EXIT         2
+#define T_AIRPORT      3
+
+#define S_NONE         0
+#define S_GONE         1
+#define S_MARKED       2
+#define S_UNMARKED     3
+#define S_IGNORED      4
+
+#define INPUT_LINES    3
+#define PLANE_COLS     20
diff --git a/usr/src/games/atc/extern.h b/usr/src/games/atc/extern.h
new file mode 100644 (file)
index 0000000..c4ef642
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+
+extern char            GAMES[], LOG[], *file;
+
+extern int             clock, safe_planes, start_time, test_mode;
+
+extern FILE            *filein, *fileout;
+
+extern C_SCREEN                screen, *sp;
+
+extern LIST            air, ground;
+
+extern struct sgttyb   tty_start, tty_new;
+
+extern DISPLACEMENT    displacement[MAXDIR];
+
+extern PLANE           *findplane(), *newplane();
diff --git a/usr/src/games/atc/grammar.y b/usr/src/games/atc/grammar.y
new file mode 100644 (file)
index 0000000..519bfd7
--- /dev/null
@@ -0,0 +1,349 @@
+/*
+ * 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.
+ */
+
+%token <ival>  HeightOp
+%token <ival>  WidthOp
+%token <ival>  UpdateOp
+%token <ival>  NewplaneOp
+%token <cval>  DirOp
+%token <ival>  ConstOp
+%token <ival>  LineOp
+%token <ival>  AirportOp
+%token <ival>  BeaconOp
+%token <ival>  ExitOp
+%union {
+       int     ival;
+       char    cval;
+}
+
+%{
+#include "include.h"
+
+int    errors = 0;
+int    line = 1;
+%}
+
+%%
+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);
+               }
+       ;
+
+bunch_of_defs:
+       def bunch_of_defs
+       | def
+       ;
+
+def:
+       udef
+       | ndef
+       | wdef
+       | hdef
+       ;
+
+udef:
+       UpdateOp '=' ConstOp ';'
+               {
+               if (sp->update_secs != 0)
+                       return (yyerror("Redefinition of 'update'."));
+               else if ($3 < 1)
+                       return (yyerror("'update' is too small."));
+               else
+                       sp->update_secs = $3;
+               }
+       ;
+
+ndef:
+       NewplaneOp '=' ConstOp ';'
+               {
+               if (sp->newplane_time != 0)
+                       return (yyerror("Redefinition of 'newplane'."));
+               else if ($3 < 1)
+                       return (yyerror("'newplane' is too small."));
+               else
+                       sp->newplane_time = $3;
+               }
+       ;
+
+hdef:
+       HeightOp '=' ConstOp ';'
+               {
+               if (sp->height != 0)
+                       return (yyerror("Redefinition of 'height'."));
+               else if ($3 < 3)
+                       return (yyerror("'height' is too small."));
+               else
+                       sp->height = $3; 
+               }
+       ;
+
+wdef:
+       WidthOp '=' ConstOp ';'
+               {
+               if (sp->height != 0)
+                       return (yyerror("Redefinition of 'width'."));
+               else if ($3 < 3)
+                       return (yyerror("'width' is too small."));
+               else
+                       sp->width = $3; 
+               }
+       ;
+
+bunch_of_lines:
+       line bunch_of_lines
+               {}
+       | line
+               {}
+       ;
+
+line:
+       BeaconOp ':' Bpoint_list ';'
+               {}
+       | ExitOp ':' Epoint_list ';'
+               {}
+       | LineOp ':' Lline_list ';'
+               {}
+       | AirportOp ':' Apoint_list ';'
+               {}
+       ;
+
+Bpoint_list:
+       Bpoint Bpoint_list
+               {}
+       | Bpoint
+               {}
+       ;
+
+Bpoint:
+       '(' ConstOp ConstOp ')'
+               {
+               if (sp->num_beacons % REALLOC == 0) {
+                       if (sp->beacon == NULL)
+                               sp->beacon = (BEACON *) malloc((sp->num_beacons
+                                       + REALLOC) * sizeof (BEACON));
+                       else
+                               sp->beacon = (BEACON *) realloc(sp->beacon,
+                                       (sp->num_beacons + REALLOC) * 
+                                       sizeof (BEACON));
+                       if (sp->beacon == NULL)
+                               return (yyerror("No memory available."));
+               }
+               sp->beacon[sp->num_beacons].x = $2;
+               sp->beacon[sp->num_beacons].y = $3;
+               check_point($2, $3);
+               sp->num_beacons++;
+               }
+       ;
+
+Epoint_list:
+       Epoint Epoint_list
+               {}
+       | Epoint
+               {}
+       ;
+
+Epoint:
+       '(' ConstOp ConstOp DirOp ')'
+               {
+               int     dir;
+
+               if (sp->num_exits % REALLOC == 0) {
+                       if (sp->exit == NULL)
+                               sp->exit = (EXIT *) malloc((sp->num_exits + 
+                                       REALLOC) * sizeof (EXIT));
+                       else
+                               sp->exit = (EXIT *) realloc(sp->exit,
+                                       (sp->num_exits + REALLOC) * 
+                                       sizeof (EXIT));
+                       if (sp->exit == NULL)
+                               return (yyerror("No memory available."));
+               }
+               dir = dir_no($4);
+               sp->exit[sp->num_exits].x = $2;
+               sp->exit[sp->num_exits].y = $3;
+               sp->exit[sp->num_exits].dir = dir;
+               check_edge($2, $3);
+               check_edir($2, $3, dir);
+               sp->num_exits++;
+               }
+       ;
+
+Apoint_list:
+       Apoint Apoint_list
+               {}
+       | Apoint
+               {}
+       ;
+
+Apoint:
+       '(' ConstOp ConstOp DirOp ')'
+               {
+               int     dir;
+
+               if (sp->num_airports % REALLOC == 0) {
+                       if (sp->airport == NULL)
+                               sp->airport=(AIRPORT *)malloc((sp->num_airports
+                                       + REALLOC) * sizeof(AIRPORT));
+                       else
+                               sp->airport = (AIRPORT *) realloc(sp->airport,
+                                       (sp->num_airports + REALLOC) * 
+                                       sizeof(AIRPORT));
+                       if (sp->airport == NULL)
+                               return (yyerror("No memory available."));
+               }
+               dir = dir_no($4);
+               sp->airport[sp->num_airports].x = $2;
+               sp->airport[sp->num_airports].y = $3;
+               sp->airport[sp->num_airports].dir = dir;
+               check_point($2, $3);
+               check_adir($2, $3, dir);
+               sp->num_airports++;
+               }
+       ;
+
+Lline_list:
+       Lline Lline_list
+               {}
+       | Lline
+               {}
+       ;
+
+Lline:
+       '[' '(' ConstOp ConstOp ')' '(' ConstOp ConstOp ')' ']'
+               {
+               if (sp->num_lines % REALLOC == 0) {
+                       if (sp->line == NULL)
+                               sp->line = (LINE *) malloc((sp->num_lines + 
+                                       REALLOC) * sizeof (LINE));
+                       else
+                               sp->line = (LINE *) realloc(sp->line,
+                                       (sp->num_lines + REALLOC) *
+                                       sizeof (LINE));
+                       if (sp->line == NULL)
+                               return (yyerror("No memory available."));
+               }
+               sp->line[sp->num_lines].p1.x = $3;
+               sp->line[sp->num_lines].p1.y = $4;
+               sp->line[sp->num_lines].p2.x = $7;
+               sp->line[sp->num_lines].p2.y = $8;
+               check_line($3, $4, $7, $8);
+               sp->num_lines++;
+               }
+       ;
+%%
+
+check_edge(x, y)
+{
+       if (!(x == 0) && !(x == sp->width - 1) && 
+           !(y == 0) && !(y == sp->height - 1))
+               yyerror("edge value not on edge.");
+}
+
+check_point(x, y)
+{
+       if (x < 1 || x >= sp->width - 1)
+               yyerror("X value out of range.");
+       if (y < 1 || y >= sp->height - 1)
+               yyerror("Y value out of range.");
+}
+
+check_linepoint(x, y)
+{
+       if (x < 0 || x >= sp->width)
+               yyerror("X value out of range.");
+       if (y < 0 || y >= sp->height)
+               yyerror("Y value out of range.");
+}
+
+check_line(x1, y1, x2, y2)
+{
+       int     d1, d2;
+
+       check_linepoint(x1, y1);
+       check_linepoint(x2, y2);
+
+       d1 = ABS(x2 - x1);
+       d2 = ABS(y2 - y1);
+
+       if (!(d1 == d2) && !(d1 == 0) && !(d2 == 0))
+               yyerror("Bad line endpoints.");
+}
+
+yyerror(s)
+{
+       fprintf(stderr, "\"%s\": line %d: %s\n", file, line, s);
+       errors++;
+
+       return (errors);
+}
+
+check_edir(x, y, dir)
+{
+       int     bad = 0;
+
+       if (x == sp->width - 1)
+               x = 2;
+       else if (x != 0)
+               x = 1;
+       if (y == sp->height - 1)
+               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;
+       case 02: if (dir != 1) bad++; break;
+       case 10: if (dir < 3 || dir > 5) bad++; break;
+       case 11: break;
+       case 12: if (dir > 1 && dir < 7) bad++; break;
+       case 20: if (dir != 5) bad++; break;
+       case 21: if (dir < 5) bad++; break;
+       case 22: if (dir != 7) bad++; break;
+       default:
+               yyerror("Unknown value in checkdir!  Get help!");
+               break;
+       }
+       if (bad)
+               yyerror("Bad direction for entrance at exit.");
+}
+
+check_adir(x, y, dir)
+{
+}
+
+checkdefs()
+{
+       int     err = 0;
+
+       if (sp->width == 0) {
+               yyerror("'width' undefined.");
+               err++;
+       }
+       if (sp->height == 0) {
+               yyerror("'height' undefined.");
+               err++;
+       }
+       if (sp->update_secs == 0) {
+               yyerror("'update' undefined.");
+               err++;
+       }
+       if (sp->newplane_time == 0) {
+               yyerror("'newplane' undefined.");
+               err++;
+       }
+       if (err)
+               return (-1);
+       else
+               return (0);
+}
diff --git a/usr/src/games/atc/graphics.c b/usr/src/games/atc/graphics.c
new file mode 100644 (file)
index 0000000..f655f89
--- /dev/null
@@ -0,0 +1,378 @@
+/*
+ * 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.
+ */
+
+#include "include.h"
+#ifdef SYSV
+#include <errno.h>
+#endif
+
+#define C_TOPBOTTOM            '-'
+#define C_LEFTRIGHT            '|'
+#define C_AIRPORT              '='
+#define C_LINE                 '+'
+#define C_BACKROUND            '.'
+#define C_BEACON               '*'
+#define C_CREDIT               '*'
+
+WINDOW *radar, *cleanradar, *credit, *input, *planes;
+
+getAChar()
+{
+#ifdef BSD
+       return (getchar());
+#endif
+#ifdef SYSV
+       int c;
+
+       while ((c = getchar()) == -1 && errno == EINTR) ;
+       return(c);
+#endif
+}
+
+erase_all()
+{
+       PLANE   *pp;
+
+       for (pp = air.head; pp != NULL; pp = pp->next) {
+               wmove(cleanradar, pp->ypos, pp->xpos * 2);
+               wmove(radar, pp->ypos, pp->xpos * 2);
+               waddch(radar, winch(cleanradar));
+               wmove(cleanradar, pp->ypos, pp->xpos * 2 + 1);
+               wmove(radar, pp->ypos, pp->xpos * 2 + 1);
+               waddch(radar, winch(cleanradar));
+       }
+}
+
+draw_all()
+{
+       PLANE   *pp;
+
+       for (pp = air.head; pp != NULL; pp = pp->next) {
+               if (pp->status == S_MARKED)
+                       wstandout(radar);
+               wmove(radar, pp->ypos, pp->xpos * 2);
+               waddch(radar, name(pp));
+               waddch(radar, '0' + pp->altitude);
+               if (pp->status == S_MARKED)
+                       wstandend(radar);
+       }
+       wrefresh(radar);
+       planewin();
+       wrefresh(input);                /* return cursor */
+       fflush(stdout);
+}
+
+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, 
+               COLS - PLANE_COLS);
+       planes = newwin(LINES - INPUT_LINES, PLANE_COLS, 0, COLS - PLANE_COLS);
+}
+
+setup_screen(scp)
+       C_SCREEN        *scp;
+{
+       register int    i, j;
+       char            str[3], *airstr;
+
+       str[2] = '\0';
+
+       if (radar != NULL)
+               delwin(radar);
+       radar = newwin(scp->height, scp->width * 2, 0, 0);
+
+       if (cleanradar != NULL)
+               delwin(cleanradar);
+       cleanradar = newwin(scp->height, scp->width * 2, 0, 0);
+
+       /* minus one here to prevent a scroll */
+       for (i = 0; i < PLANE_COLS - 1; i++) {
+               wmove(credit, 0, i);
+               waddch(credit, C_CREDIT);
+               wmove(credit, INPUT_LINES - 1, i);
+               waddch(credit, C_CREDIT);
+       }
+       wmove(credit, INPUT_LINES / 2, 1);
+       waddstr(credit, AUTHOR_STR);
+
+       for (i = 1; i < scp->height - 1; i++) {
+               for (j = 1; j < scp->width - 1; j++) {
+                       wmove(radar, i, j * 2);
+                       waddch(radar, C_BACKROUND);
+               }
+       }
+
+       /*
+        * Draw the lines first, since people like to draw lines
+        * through beacons and exit points.
+        */
+       str[0] = C_LINE;
+       for (i = 0; i < scp->num_lines; i++) {
+               str[1] = ' ';
+               draw_line(radar, scp->line[i].p1.x, scp->line[i].p1.y,
+                       scp->line[i].p2.x, scp->line[i].p2.y, str);
+       }
+
+       str[0] = C_TOPBOTTOM;
+       str[1] = C_TOPBOTTOM;
+       wmove(radar, 0, 0);
+       for (i = 0; i < scp->width - 1; i++)
+               waddstr(radar, str);
+       waddch(radar, C_TOPBOTTOM);
+
+       str[0] = C_TOPBOTTOM;
+       str[1] = C_TOPBOTTOM;
+       wmove(radar, scp->height - 1, 0);
+       for (i = 0; i < scp->width - 1; i++)
+               waddstr(radar, str);
+       waddch(radar, C_TOPBOTTOM);
+
+       for (i = 1; i < scp->height - 1; i++) {
+               wmove(radar, i, 0);
+               waddch(radar, C_LEFTRIGHT);
+               wmove(radar, i, (scp->width - 1) * 2);
+               waddch(radar, C_LEFTRIGHT);
+       }
+
+       str[0] = C_BEACON;
+       for (i = 0; i < scp->num_beacons; i++) {
+               str[1] = '0' + i;
+               wmove(radar, scp->beacon[i].y, scp->beacon[i].x * 2);
+               waddstr(radar, str);
+       }
+
+       for (i = 0; i < scp->num_exits; i++) {
+               wmove(radar, scp->exit[i].y, scp->exit[i].x * 2);
+               waddch(radar, '0' + i);
+       }
+
+       airstr = "^?>?v?<?";
+       for (i = 0; i < scp->num_airports; i++) {
+               str[0] = airstr[scp->airport[i].dir];
+               str[1] = '0' + i;
+               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)
+{
+       wmove(input, 0, pos);
+       wclrtoeol(input);
+       wrefresh(input);
+       fflush(stdout);
+}
+
+iomove(pos)
+{
+       wmove(input, 0, pos);
+       wrefresh(input);
+       fflush(stdout);
+}
+
+ioaddstr(pos, str)
+       char    *str;
+{
+       wmove(input, 0, pos);
+       waddstr(input, str);
+       wrefresh(input);
+       fflush(stdout);
+}
+
+ioclrtobot()
+{
+       wclrtobot(input);
+       wrefresh(input);
+       fflush(stdout);
+}
+
+ioerror(pos, len, str)
+       char    *str;
+{
+       int     i;
+
+       wmove(input, 1, pos);
+       for (i = 0; i < len; i++)
+               waddch(input, '^');
+       wmove(input, 2, 0);
+       waddstr(input, str);
+       wrefresh(input);
+       fflush(stdout);
+}
+
+quit()
+{
+       int                     c, y, x;
+#ifdef BSD
+       struct itimerval        itv;
+#endif
+
+       getyx(input, y, x);
+       wmove(input, 2, 0);
+       waddstr(input, "Really quit? (y/n) ");
+       wclrtobot(input);
+       wrefresh(input);
+       fflush(stdout);
+
+       c = getchar();
+       if (c == EOF || c == 'y') {
+               /* disable timer */
+#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
+               fflush(stdout);
+               clear();
+               refresh();
+               endwin();
+               log_score(0);
+               exit(0);
+       }
+       wmove(input, 2, 0);
+       wclrtobot(input);
+       wmove(input, y, x);
+       wrefresh(input);
+       fflush(stdout);
+       return;
+}
+
+planewin()
+{
+       PLANE   *pp;
+       char    *command();
+       int     warning = 0;
+
+#ifdef BSD
+       wclear(planes);
+#endif
+
+       wmove(planes, 0,0);
+
+#ifdef SYSV
+       wclrtobot(planes);
+#endif
+       wprintw(planes, "Time: %-4d Safe: %d", clock, safe_planes);
+       wmove(planes, 2, 0);
+
+       waddstr(planes, "pl dt  comm");
+       for (pp = air.head; pp != NULL; pp = pp->next) {
+               if (waddch(planes, '\n') == ERR) {
+                       warning++;
+                       break;
+               }
+               waddstr(planes, command(pp));
+       }
+       waddch(planes, '\n');
+       for (pp = ground.head; pp != NULL; pp = pp->next) {
+               if (waddch(planes, '\n') == ERR) {
+                       warning++;
+                       break;
+               }
+               waddstr(planes, command(pp));
+       }
+       if (warning) {
+               wmove(planes, LINES - INPUT_LINES - 1, 0);
+               waddstr(planes, "---- more ----");
+               wclrtoeol(planes);
+       }
+       wrefresh(planes);
+       fflush(stdout);
+}
+
+loser(p, s)
+       PLANE   *p;
+       char    *s;
+{
+       int                     c;
+#ifdef BSD
+       struct itimerval        itv;
+#endif
+
+       /* disable timer */
+#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
+
+       wmove(input, 0, 0);
+       wclrtobot(input);
+       wprintw(input, "Plane '%c' %s\n\nHit space for top players list...",
+               name(p), s);
+       wrefresh(input);
+       fflush(stdout);
+       while ((c = getchar()) != EOF && c != ' ')
+               ;
+       clear();        /* move to top of screen */
+       refresh();
+       endwin();
+       log_score(0);
+       exit(0);
+}
+
+redraw()
+{
+       clear();
+       refresh();
+
+       touchwin(radar);
+       wrefresh(radar);
+       touchwin(planes);
+       wrefresh(planes);
+       touchwin(credit);
+       wrefresh(credit);
+
+       /* refresh input last to get cursor in right place */
+       touchwin(input);
+       wrefresh(input);
+       fflush(stdout);
+}
+
+
+done_screen()
+{
+       clear();
+       refresh();
+       endwin();         /* clean up curses */
+}
diff --git a/usr/src/games/atc/lex.l b/usr/src/games/atc/lex.l
new file mode 100644 (file)
index 0000000..dde6315
--- /dev/null
@@ -0,0 +1,28 @@
+%{
+/*
+ * 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.
+ */
+
+#include "y.tab.h"
+extern int     line;
+%}
+%%
+[0-9]+                 { yylval.ival = atoi(yytext);  return(ConstOp); }
+height                 { return(HeightOp); }
+width                  { return(WidthOp); }
+newplane               { return(NewplaneOp); }
+update                 { return(UpdateOp); }
+airport                        { return(AirportOp); }
+line                   { return(LineOp); }
+exit                   { return(ExitOp); }
+beacon                 { return(BeaconOp); }
+[wedcxzaq]             { yylval.cval = *yytext; return (DirOp); }
+[ \t]+                 { }
+#[^\n]*\n              { line++; }
+\n                     { line++; }
+.                      { return *yytext; }
diff --git a/usr/src/games/atc/list.c b/usr/src/games/atc/list.c
new file mode 100644 (file)
index 0000000..5498e59
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * 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.
+ */
+
+#include "include.h"
+
+PLANE  *
+newplane()
+{
+       return ((PLANE *) calloc(1, sizeof (PLANE)));
+}
+
+append(l, p)
+       LIST    *l;
+       PLANE   *p;
+{
+       PLANE   *q = NULL, *r = NULL;
+
+       if (l->head == NULL) {
+               p->next = p->prev = NULL;
+               l->head = l->tail = p;
+       } else {
+               q = l -> head;
+
+               while (q != NULL && q->plane_no < p->plane_no) {
+                       r = q;
+                       q = q -> next;
+               }
+
+               if (q) {
+                       if (r) {
+                               p->prev = r;
+                               r->next = p;
+                               p->next = q;
+                               q->prev = p;
+                       } else {
+                               p->next = q;
+                               p->prev = NULL;
+                               q->prev = p;
+                               l->head = p;
+                       }
+               } else {
+                       l->tail->next = p;
+                       p->next = NULL;
+                       p->prev = l->tail;
+                       l->tail = p;
+               }
+       }
+}
+
+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) {
+               l->head = p->next;
+               l->head->prev = NULL;
+       } else if (l->tail == p) {
+               l->tail = p->prev;
+               l->tail->next = NULL;
+       } else {
+               p->prev->next = p->next;
+               p->next->prev = p->prev;
+       }
+}
diff --git a/usr/src/games/atc/main.c b/usr/src/games/atc/main.c
new file mode 100644 (file)
index 0000000..24218d7
--- /dev/null
@@ -0,0 +1,279 @@
+/*
+ * 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.
+ */
+
+#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)
+       char    *s;
+{
+       extern FILE     *yyin;
+       int             retval;
+
+       file = s;
+       yyin = fopen(s, "r");
+       if (yyin == NULL) {
+               perror(s);
+               return (-1);
+       }
+       retval = yyparse();
+       fclose(yyin);
+
+       if (retval != 0)
+               return (-1);
+       else
+               return (0);
+}
+
+char   *
+default_game()
+{
+       FILE            *fp;
+       static char     file[256];
+       char            line[256], games[256];
+
+       strcpy(games, SPECIAL_DIR);
+       strcat(games, GAMES);
+
+       if ((fp = fopen(games, "r")) == NULL) {
+               perror(games);
+               return (NULL);
+       }
+       if (fgets(line, sizeof(line), fp) == NULL) {
+               fprintf(stderr, "%s: no default game available\n", games);
+               return (NULL);
+       }
+       fclose(fp);
+       line[strlen(line) - 1] = '\0';
+       strcpy(file, SPECIAL_DIR);
+       strcat(file, line);
+       return (file);
+}
+
+char   *
+okay_game(s)
+       char    *s;
+{
+       FILE            *fp;
+       static char     file[256];
+       char            *ret = NULL, line[256], games[256];
+
+       strcpy(games, SPECIAL_DIR);
+       strcat(games, GAMES);
+
+       if ((fp = fopen(games, "r")) == NULL) {
+               perror(games);
+               return (NULL);
+       }
+       while (fgets(line, sizeof(line), fp) != NULL) {
+               line[strlen(line) - 1] = '\0';
+               if (strcmp(s, line) == 0) {
+                       strcpy(file, SPECIAL_DIR);
+                       strcat(file, line);
+                       ret = file;
+                       break;
+               }
+       }
+       fclose(fp);
+       if (ret == NULL) {
+               test_mode = 1;
+               ret = s;
+               fprintf(stderr, "%s: %s: game not found\n", games, s);
+               fprintf(stderr, "Your score will not be logged.\n");
+               sleep(2);       /* give the guy time to read it */
+       }
+       return (ret);
+}
+
+list_games()
+{
+       FILE            *fp;
+       char            line[256], games[256];
+       int             num_games = 0;
+
+       strcpy(games, SPECIAL_DIR);
+       strcat(games, GAMES);
+
+       if ((fp = fopen(games, "r")) == NULL) {
+               perror(games);
+               return (-1);
+       }
+       puts("available games:");
+       while (fgets(line, sizeof(line), fp) != NULL) {
+               printf("        %s", line);
+               num_games++;
+       }
+       fclose(fp);
+       if (num_games == 0) {
+               fprintf(stderr, "%s: no games available\n", games);
+               return (-1);
+       }
+       return (0);
+}
diff --git a/usr/src/games/atc/struct.h b/usr/src/games/atc/struct.h
new file mode 100644 (file)
index 0000000..1a02e08
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * 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.
+ */
+
+typedef struct {
+       int     x, y;
+       int     dir;    /* used only sometimes */
+} SCREEN_POS;
+
+typedef struct {
+       SCREEN_POS      p1, p2;
+} LINE;
+
+typedef SCREEN_POS     EXIT;
+typedef SCREEN_POS     BEACON;
+typedef SCREEN_POS     AIRPORT;
+
+typedef struct {
+       int     width, height;
+       int     update_secs;
+       int     newplane_time;
+       int     num_exits;
+       int     num_lines;
+       int     num_beacons;
+       int     num_airports;
+       EXIT    *exit;
+       LINE    *line;
+       BEACON  *beacon;
+       AIRPORT *airport;
+} C_SCREEN;
+
+typedef struct plane {
+       struct plane    *next, *prev;
+       int             status;
+       int             plane_no;
+       int             plane_type;
+       int             orig_no;
+       int             orig_type;
+       int             dest_no;
+       int             dest_type;
+       int             altitude;
+       int             new_altitude;
+       int             dir;
+       int             new_dir;
+       int             fuel;
+       int             xpos;
+       int             ypos;
+       int             delayd;
+       int             delayd_no;
+} PLANE;
+
+typedef struct {
+       PLANE   *head, *tail;
+} LIST;
+
+typedef struct {
+       char    name[10];
+       char    host[256];
+       char    game[256];
+       int     planes;
+       int     time;
+       int     real_time;
+} SCORE;
+
+typedef struct displacement {
+       int     dx;
+       int     dy;
+} DISPLACEMENT;
diff --git a/usr/src/games/atc/tunable.h b/usr/src/games/atc/tunable.h
new file mode 100644 (file)
index 0000000..685da72
--- /dev/null
@@ -0,0 +1,12 @@
+/*
+ * 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.
+ */
+
+extern char    SPECIAL_DIR[];
+
+extern int     NUM_SCORES;