From: Matthew Dillon Date: Mon, 14 Sep 2009 21:05:02 +0000 (-0700) Subject: games - atc - replace sgtty with termios, remove #ifdef madness, fix warnings. X-Git-Tag: v2.4.0~11 X-Git-Url: https://gitweb.dragonflybsd.org/~uqs/games.git/commitdiff_plain/5f206b3417ebd431772b43dad838fcdfae00f1f1 games - atc - replace sgtty with termios, remove #ifdef madness, fix warnings. Submitted-by: Ulrich Spoerlein --- diff --git a/games/atc/Makefile b/games/atc/Makefile index 597119d592..92dc57af3d 100644 --- a/games/atc/Makefile +++ b/games/atc/Makefile @@ -3,12 +3,12 @@ # $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 diff --git a/games/atc/extern.c b/games/atc/extern.c index 1cb5ee5329..abb3bb8973 100644 --- a/games/atc/extern.c +++ b/games/atc/extern.c @@ -61,7 +61,7 @@ C_SCREEN screen, *sp = &screen; LIST air, ground; -struct sgttyb tty_start, tty_new; +struct termios tty_start, tty_new; DISPLACEMENT displacement[MAXDIR] = { { 0, -1 }, diff --git a/games/atc/extern.h b/games/atc/extern.h index f1efc05d8a..dc368b3539 100644 --- a/games/atc/extern.h +++ b/games/atc/extern.h @@ -57,7 +57,7 @@ extern C_SCREEN screen, *sp; extern LIST air, ground; -extern struct sgttyb tty_start, tty_new; +extern struct termios tty_start, tty_new; extern DISPLACEMENT displacement[MAXDIR]; diff --git a/games/atc/graphics.c b/games/atc/graphics.c index 59199a9ec3..dfd04efde8 100644 --- a/games/atc/graphics.c +++ b/games/atc/graphics.c @@ -47,10 +47,9 @@ * For more info on this and all of my stuff, mail edjames@berkeley.edu. */ +#include #include "include.h" -#ifdef SYSV #include -#endif #define C_TOPBOTTOM '-' #define C_LEFTRIGHT '|' @@ -68,15 +67,14 @@ static void draw_line(WINDOW *, int, int, int, int, const char *); 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 @@ -288,9 +286,7 @@ void quit(void) { int c, y, x; -#ifdef BSD struct itimerval itv; -#endif getyx(input, y, x); wmove(input, 2, 0); @@ -302,14 +298,9 @@ quit(void) 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(); @@ -331,18 +322,10 @@ planewin(void) 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) { @@ -372,19 +355,12 @@ void 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); diff --git a/games/atc/include.h b/games/atc/include.h index c5887d25a7..2984ee1905 100644 --- a/games/atc/include.h +++ b/games/atc/include.h @@ -46,41 +46,20 @@ * For more info on this and all of my stuff, mail edjames@berkeley.edu. */ -#include -#include -#include -#include - -#ifdef BSD -#include #include -#include -#endif - -#include -#include -#include -#include -#ifdef SYSV +#include #include -#endif - -#include -#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 -#define sg_erase c_cc[2] -#define sg_kill c_cc[3] -#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "def.h" #include "struct.h" diff --git a/games/atc/input.c b/games/atc/input.c index 74fd13cebf..dbe85745e7 100644 --- a/games/atc/input.c +++ b/games/atc/input.c @@ -49,6 +49,8 @@ #include +#include +#include #include "include.h" #include "pathnames.h" @@ -56,9 +58,6 @@ #define MAXDEPTH 15 #define RETTOKEN '\r' -#ifdef SYSV -#define CRTOKEN '\r' -#endif #define REDRAWTOKEN '\014' /* CTRL(L) */ #define SHELLTOKEN '!' #define HELPTOKEN '?' @@ -124,9 +123,6 @@ static const char *ignore(int); RULE state0[] = { { ALPHATOKEN, 1, "%c:", setplane}, { RETTOKEN, -1, "", NULL }, -#ifdef SYSV - { CRTOKEN, -1, "", NULL }, -#endif { HELPTOKEN, 12, " [a-z]", NULL }}, state1[] = { { 't', 2, " turn", turn }, { 'a', 3, " altitude:", NULL }, @@ -158,9 +154,6 @@ RULE state0[] = { { ALPHATOKEN, 1, "%c:", setplane}, state4[] = { { '@', 9, " at", NULL }, { 'a', 9, " at", NULL }, { RETTOKEN, -1, "", NULL }, -#ifdef SYSV - { CRTOKEN, -1, "", NULL }, -#endif { HELPTOKEN, 12, " @a", NULL }}, state5[] = { { NUMTOKEN, 7, "%c", delayb }, { HELPTOKEN, 12, " [0-9]", NULL }}, @@ -175,14 +168,8 @@ RULE state0[] = { { ALPHATOKEN, 1, "%c:", setplane}, { 'a', 4, " 270", rel_dir }, { 'q', 4, " 315", rel_dir }, { RETTOKEN, -1, "", NULL }, -#ifdef SYSV - { CRTOKEN, -1, "", NULL }, -#endif { HELPTOKEN, 12, " @a",NULL }}, state7[] = { { RETTOKEN, -1, "", NULL }, -#ifdef SYSV - { CRTOKEN, -1, "", NULL }, -#endif { HELPTOKEN, 12, " ", NULL }}, state8[] = { { NUMTOKEN, 4, "%c", benum }, { HELPTOKEN, 12, " [0-9]", NULL }}, @@ -276,10 +263,10 @@ getcommand(void) 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 { @@ -338,16 +325,10 @@ gettoken(void) { 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; @@ -373,18 +354,12 @@ gettoken(void) } 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(); } diff --git a/games/atc/log.c b/games/atc/log.c index a6f971955d..40848d0dd4 100644 --- a/games/atc/log.c +++ b/games/atc/log.c @@ -53,9 +53,7 @@ #include "include.h" #include "pathnames.h" -#ifdef SYSV #include -#endif static FILE *score_fp; @@ -146,21 +144,14 @@ log_score(int list_em) struct passwd *pw; char *cp; SCORE score[100], thisscore; -#ifdef SYSV - struct utsname name; -#endif + struct utsname xname; 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); @@ -184,16 +175,9 @@ log_score(int list_em) 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 + + uname(&xname); + strcpy(thisscore.host, xname.nodename); cp = rindex(filename, '/'); if (cp == NULL) { @@ -273,12 +257,7 @@ log_score(int list_em) } 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"); diff --git a/games/atc/main.c b/games/atc/main.c index f992de126c..8ae48e38c2 100644 --- a/games/atc/main.c +++ b/games/atc/main.c @@ -48,6 +48,7 @@ * For more info on this and all of my stuff, mail edjames@berkeley.edu. */ +#include #include "include.h" #include "pathnames.h" @@ -66,9 +67,7 @@ main(__unused int ac, char **av) 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(); @@ -156,69 +155,41 @@ main(__unused int ac, char **av) 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 } } } diff --git a/games/atc/update.c b/games/atc/update.c index beebae126e..12d212a9e1 100644 --- a/games/atc/update.c +++ b/games/atc/update.c @@ -60,13 +60,7 @@ update(void) 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++; @@ -217,12 +211,7 @@ update(void) if ((random() % sp->newplane_time) == 0) addplane(); -#ifdef BSD sigsetmask(mask); -#endif -#ifdef SYSV - alarm(sp->update_secs); -#endif } const char *