diff --git a/games/hack/Makefile b/games/hack/Makefile index 1bba258..93e5fec 100644 --- a/games/hack/Makefile +++ b/games/hack/Makefile @@ -18,7 +18,7 @@ SRCS= alloc.c hack.Decl.c hack.apply.c hack.bones.c hack.c hack.cmd.c \ MAN= hack.6 DPADD= ${LIBTERMCAP} LDADD= -ltermcap -CFLAGS+= -DBSD -I${.CURDIR} -I. +CFLAGS+=-I${.CURDIR} -I. BINGRP=games BINMODE=2555 FILES= rumors help hh data diff --git a/games/hack/config.h b/games/hack/config.h index c11fe34..28f589d 100644 --- a/games/hack/config.h +++ b/games/hack/config.h @@ -11,20 +11,6 @@ #define UNIX /* delete if no fork(), exec() available */ #define CHDIR /* delete if no chdir() available */ -/* - * Some include files are in a different place under SYSV - * BSD SYSV - * - * - * - * Some routines are called differently - * index strchr - * rindex strrchr - * Also, the code for suspend and various ioctls is only given for BSD4.2 - * (I do not have access to a SYSV system.) - */ -#define BSD /* delete this line on System V */ - /* #define STUPID */ /* avoid some complicated expressions if your C compiler chokes on them */ /* #define PYRAMID_BUG */ /* avoid a bug on the Pyramid */ @@ -63,10 +49,7 @@ #define SHELL /* do not delete the '!' command */ - -#ifdef BSD #define SUSPEND /* let ^Z suspend the game */ -#endif /* BSD */ #endif /* UNIX */ #ifdef CHDIR diff --git a/games/hack/hack.h b/games/hack/hack.h index 27cd816..df9f582 100644 --- a/games/hack/hack.h +++ b/games/hack/hack.h @@ -12,10 +12,9 @@ #include #include -#ifndef BSD +/* FIXME */ #define index strchr #define rindex strrchr -#endif /* BSD */ #include "def.objclass.h" diff --git a/games/hack/hack.ioctl.c b/games/hack/hack.ioctl.c index e63465c..7c9aa90 100644 --- a/games/hack/hack.ioctl.c +++ b/games/hack/hack.ioctl.c @@ -7,36 +7,22 @@ systems (e.g. MUNIX) the include files and define the same constants, and the C preprocessor complains. */ #include "hack.h" -#ifdef BSD -#include -struct ltchars ltchars, ltchars0; -#else -#include /* also includes part of */ -struct termio termio; -#endif /* BSD */ +#include +struct termios termio; void getioctls(void) { -#ifdef BSD - ioctl(fileno(stdin), (int) TIOCGLTC, (char *) <chars); - ioctl(fileno(stdin), (int) TIOCSLTC, (char *) <chars0); -#else - ioctl(fileno(stdin), (int) TCGETA, &termio); -#endif /* BSD */ + tcgetattr(fileno(stdin), &termio); } void setioctls(void) { -#ifdef BSD - ioctl(fileno(stdin), (int) TIOCSLTC, (char *) <chars); -#else - ioctl(fileno(stdin), (int) TCSETA, &termio); -#endif /* BSD */ + tcsetattr(fileno(stdin), TCSANOW, &termio); } -#ifdef SUSPEND /* implies BSD */ +#ifdef SUSPEND #include int dosuspend(void) diff --git a/games/hack/hack.pager.c b/games/hack/hack.pager.c index bb0eccb..b478bbd 100644 --- a/games/hack/hack.pager.c +++ b/games/hack/hack.pager.c @@ -370,12 +370,7 @@ union wait { /* used only for the cast (union wait *) 0 */ }; #else - -#ifdef BSD #include -#else -#include -#endif /* BSD */ #endif /* NOWAITINCLUDE */ bool diff --git a/games/hack/hack.termcap.c b/games/hack/hack.termcap.c index ca06296..baf06a5 100644 --- a/games/hack/hack.termcap.c +++ b/games/hack/hack.termcap.c @@ -38,7 +38,8 @@ startup(void) flags.nonull = 1; if((pc = tgetstr(__DECONST(char *, "pc"), &tbufptr))) tcPC = *pc; - if(!(tcBC = tgetstr(__DECONST(char *, "bc"), &tbufptr))) { + if(!(tcBC = tgetstr(__DECONST(char *, "bc"), &tbufptr)) + &&!(tcBC = tgetstr(__DECONST(char *, "le"), &tbufptr))) { if(!tgetflag(__DECONST(char *, "bs"))) error("Terminal must backspace."); tcBC = tbufptr; diff --git a/games/hack/hack.tty.c b/games/hack/hack.tty.c index a1ced1e..163f77a 100644 --- a/games/hack/hack.tty.c +++ b/games/hack/hack.tty.c @@ -40,64 +40,19 @@ /* With thanks to the people who sent code for SYSV - hpscdi!jon, arnold@ucsf-cgl, wcs@bo95b, cbcephus!pds and others. */ -#include "hack.h" - -/* - * The distinctions here are not BSD - rest but rather USG - rest, as - * BSD still has the old sgttyb structure, but SYSV has termio. Thus: - */ -#ifdef BSD -#define V7 -#else -#define USG -#endif /* BSD */ +#include +#include "hack.h" /* * Some systems may have getchar() return EOF for various reasons, and * we should not quit before seeing at least NR_OF_EOFS consecutive EOFs. + * FIXME: is this still valid nowadays? */ -#ifndef BSD #define NR_OF_EOFS 20 -#endif /* BSD */ - - -#ifdef USG - -#include -#define termstruct termio -#define kill_sym c_cc[VKILL] -#define erase_sym c_cc[VERASE] -#define EXTABS TAB3 -#define tabflgs c_oflag -#define echoflgs c_lflag -#define cbrkflgs c_lflag -#define CBRKMASK ICANON -#define CBRKON ! /* reverse condition */ -#define OSPEED(x) ((x).c_cflag & CBAUD) -#define GTTY(x) (ioctl(0, TCGETA, x)) -#define STTY(x) (ioctl(0, TCSETA, x)) /* TCSETAF? TCSETAW? */ - -#else /* V7 */ - -#include -#define termstruct sgttyb -#define kill_sym sg_kill -#define erase_sym sg_erase -#define EXTABS XTABS -#define tabflgs sg_flags -#define echoflgs sg_flags -#define cbrkflgs sg_flags -#define CBRKMASK CBREAK -#define CBRKON /* empty */ -#define OSPEED(x) (x).sg_ospeed -#define GTTY(x) (ioctl(0, TIOCGETP, x)) -#define STTY(x) (ioctl(0, TIOCSETP, x)) - -#endif /* USG */ static char erase_char, kill_char; static boolean settty_needed = FALSE; -struct termstruct inittyb, curttyb; +struct termios inittyb, curttyb; static void setctty(void); @@ -109,16 +64,16 @@ static void setctty(void); void gettty(void) { - if(GTTY(&inittyb) < 0) + if(tcgetattr(fileno(stdin),&inittyb) < 0) perror("Hack (gettty)"); curttyb = inittyb; - erase_char = inittyb.erase_sym; - kill_char = inittyb.kill_sym; + erase_char = inittyb.c_cc[VERASE]; + kill_char = inittyb.c_cc[VKILL]; getioctls(); /* do not expand tabs - they might be needed inside a cm sequence */ - if(curttyb.tabflgs & EXTABS) { - curttyb.tabflgs &= ~EXTABS; + if(curttyb.c_oflag & OXTABS) { + curttyb.c_oflag &= ~OXTABS; setctty(); } settty_needed = TRUE; @@ -132,17 +87,17 @@ settty(const char *s) end_screen(); if(s) printf("%s", s); fflush(stdout); - if(STTY(&inittyb) < 0) + if(tcsetattr(fileno(stdin),TCSANOW,&inittyb) < 0) perror("Hack (settty)"); - flags.echo = (inittyb.echoflgs & ECHO) ? ON : OFF; - flags.cbreak = (CBRKON(inittyb.cbrkflgs & CBRKMASK)) ? ON : OFF; + flags.echo = (inittyb.c_lflag & ECHO) ? ON : OFF; + flags.cbreak = (!(inittyb.c_lflag & ICANON)) ? ON : OFF; setioctls(); } static void setctty(void) { - if(STTY(&curttyb) < 0) + if(tcsetattr(fileno(stdin),TCSANOW,&curttyb) < 0) perror("Hack (setctty)"); } @@ -150,23 +105,21 @@ void setftty(void) { int ef = 0; /* desired value of flags & ECHO */ -int cf = CBRKON(CBRKMASK); /* desired value of flags & CBREAK */ +int cf = !(ICANON); /* desired value of flags & CBREAK */ int change = 0; flags.cbreak = ON; flags.echo = OFF; /* Should use (ECHO|CRMOD) here instead of ECHO */ - if((curttyb.echoflgs & ECHO) != ef){ - curttyb.echoflgs &= ~ECHO; + if((curttyb.c_lflag & ECHO) != ef){ + curttyb.c_lflag &= ~ECHO; change++; } - if((curttyb.cbrkflgs & CBRKMASK) != cf){ - curttyb.cbrkflgs &= ~CBRKMASK; - curttyb.cbrkflgs |= cf; -#ifdef USG + if((curttyb.c_lflag & ICANON) != cf){ + curttyb.c_lflag &= ~ICANON; + curttyb.c_lflag |= cf; /* be satisfied with one character; no timeout */ curttyb.c_cc[VMIN] = 1; /* was VEOF */ curttyb.c_cc[VTIME] = 0; /* was VEOL */ -#endif /* USG */ change++; } if(change){