Project

General

Profile

Bug #1505 ยป atc.diff

uqs, 09/14/2009 12:29 PM

View differences:

games/atc/Makefile
# $DragonFly: src/games/atc/Makefile,v 1.4 2006/10/08 16:22:35 pavalos Exp $
PROG= atc
CFLAGS+=-DBSD -I${.CURDIR} -I.
CFLAGS+=-I${.CURDIR} -I.
SRCS= extern.c grammar.y graphics.c input.c lex.l list.c log.c \
main.c tunable.c update.c y.tab.h
MAN= atc.6
DPADD= ${LIBL} ${LIBM} ${LIBCURSES} ${LIBTERMCAP}
LDADD= -ll -lm -lcurses -ltermcap
DPADD= ${LIBL} ${LIBM} ${LIBCURSES}
LDADD= -ll -lm -lcurses
FILES= Game_List Killer crossover default easy game_2
FILESDIR= ${SHAREDIR}/games/atc
HIDEGAME=hidegame
games/atc/extern.c
LIST air, ground;
struct sgttyb tty_start, tty_new;
struct termios tty_start, tty_new;
DISPLACEMENT displacement[MAXDIR] = {
{ 0, -1 },
games/atc/extern.h
extern LIST air, ground;
extern struct sgttyb tty_start, tty_new;
extern struct termios tty_start, tty_new;
extern DISPLACEMENT displacement[MAXDIR];
games/atc/graphics.c
* For more info on this and all of my stuff, mail edjames@berkeley.edu.
*/
#include <stdlib.h>
#include "include.h"
#ifdef SYSV
#include <errno.h>
#endif
#define C_TOPBOTTOM '-'
#define C_LEFTRIGHT '|'
......
int
getAChar(void)
{
#ifdef BSD
return (getchar());
#endif
#ifdef SYSV
int c;
while ((c = getchar()) == -1 && errno == EINTR) ;
errno = 0;
while ((c = getchar()) == -1 && errno == EINTR) {
errno = 0;
clearerr(stdin);
}
return(c);
#endif
}
void
......
quit(void)
{
int c, y, x;
#ifdef BSD
struct itimerval itv;
#endif
getyx(input, y, x);
wmove(input, 2, 0);
......
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();
......
PLANE *pp;
int warning = 0;
#ifdef BSD
wclear(planes);
#endif
wmove(planes, 0,0);
#ifdef SYSV
wclrtobot(planes);
#endif
wprintw(planes, "Time: %-4d Safe: %d", clck, 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) {
......
loser(const PLANE *p, const 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);
games/atc/include.h
* For more info on this and all of my stuff, mail edjames@berkeley.edu.
*/
#include <stdio.h>
#include <ctype.h>
#include <sys/types.h>
#include <pwd.h>
#ifdef BSD
#include <sgtty.h>
#include <sys/time.h>
#include <sys/file.h>
#endif
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#ifdef SYSV
#include <sys/types.h>
#include <sys/utsname.h>
#endif
#include <signal.h>
#include <math.h>
#include <ctype.h>
#include <curses.h>
#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
#define sg_erase c_cc[2]
#define sg_kill c_cc[3]
#endif
#include <fcntl.h>
#include <math.h>
#include <pwd.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include "def.h"
#include "struct.h"
games/atc/input.c
#include <sys/wait.h>
#include <stdlib.h>
#include <string.h>
#include "include.h"
#include "pathnames.h"
......
#define MAXDEPTH 15
#define RETTOKEN '\r'
#ifdef SYSV
#define CRTOKEN '\r'
#endif
#define REDRAWTOKEN '\014' /* CTRL(L) */
#define SHELLTOKEN '!'
#define HELPTOKEN '?'
......
RULE state0[] = { { ALPHATOKEN, 1, "%c:", setplane},
{ RETTOKEN, -1, "", NULL },
#ifdef SYSV
{ CRTOKEN, -1, "", NULL },
#endif
{ HELPTOKEN, 12, " [a-z]<ret>", NULL }},
state1[] = { { 't', 2, " turn", turn },
{ 'a', 3, " altitude:", NULL },
......
state4[] = { { '@', 9, " at", NULL },
{ 'a', 9, " at", NULL },
{ RETTOKEN, -1, "", NULL },
#ifdef SYSV
{ CRTOKEN, -1, "", NULL },
#endif
{ HELPTOKEN, 12, " @a<ret>", NULL }},
state5[] = { { NUMTOKEN, 7, "%c", delayb },
{ HELPTOKEN, 12, " [0-9]", NULL }},
......
{ 'a', 4, " 270", rel_dir },
{ 'q', 4, " 315", rel_dir },
{ RETTOKEN, -1, "", NULL },
#ifdef SYSV
{ CRTOKEN, -1, "", NULL },
#endif
{ HELPTOKEN, 12, " @a<dir><ret>",NULL }},
state7[] = { { RETTOKEN, -1, "", NULL },
#ifdef SYSV
{ CRTOKEN, -1, "", NULL },
#endif
{ HELPTOKEN, 12, " <ret>", NULL }},
state8[] = { { NUMTOKEN, 4, "%c", benum },
{ HELPTOKEN, 12, " [0-9]", NULL }},
......
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 {
......
{
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;
......
}
wait(0);
#ifdef BSD
ioctl(fileno(stdin), TIOCSETP, &tty_new);
tcsetattr(fileno(stdin), TCSANOW, &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();
}
games/atc/log.c
#include "include.h"
#include "pathnames.h"
#ifdef SYSV
#include <sys/utsname.h>
#endif
static FILE *score_fp;
......
struct passwd *pw;
char *cp;
SCORE score[100], thisscore;
#ifdef SYSV
struct utsname name;
#endif
if (score_fp == NULL) {
warnx("no score file available");
return (-1);
}
#ifdef BSD
if (flock(fileno(score_fp), LOCK_EX) < 0)
#endif
#ifdef SYSV
while (lockf(fileno(score_fp), F_LOCK, 1) < 0)
#endif
{
warn("flock %s", _PATH_SCORE);
return (-1);
......
return (-1);
}
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.nodename);
#endif
cp = rindex(filename, '/');
if (cp == NULL) {
......
}
putchar('\n');
}
#ifdef BSD
flock(fileno(score_fp), LOCK_UN);
#endif
#ifdef SYSV
/* lock will evaporate upon close */
#endif
fclose(score_fp);
printf("%2s: %-8s %-8s %-18s %4s %9s %4s\n", "#", "name", "host",
"game", "time", "real time", "planes safe");
games/atc/main.c
* For more info on this and all of my stuff, mail edjames@berkeley.edu.
*/
#include <stdlib.h>
#include "include.h"
#include "pathnames.h"
......
int f_printpath = 0;
const char *file = NULL;
char *p_name, *ptr;
#ifdef BSD
struct itimerval itv;
#endif
/* Open the score file then revoke setgid privileges */
open_score_file();
......
signal(SIGINT, (sig_t)quit);
signal(SIGQUIT, (sig_t)quit);
#ifdef BSD
signal(SIGTSTP, SIG_IGN);
signal(SIGSTOP, SIG_IGN);
#endif
signal(SIGHUP, (sig_t)log_score);
signal(SIGTERM, (sig_t)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);
tcgetattr(fileno(stdin), &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
tcsetattr(fileno(stdin), TCSANOW, &tty_new);
signal(SIGALRM, (sig_t)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
}
}
}
games/atc/update.c
int i, dir_diff, mask, unclean;
PLANE *pp, *p1, *p2;
#ifdef BSD
mask = sigblock(sigmask(SIGINT));
#endif
#ifdef SYSV
alarm(0);
signal(SIGALRM, update);
#endif
clck++;
......
if ((random() % sp->newplane_time) == 0)
addplane();
#ifdef BSD
sigsetmask(mask);
#endif
#ifdef SYSV
alarm(sp->update_secs);
#endif
}
const char *
    (1-1/1)