Project

General

Profile

Bug #1493 ยป hack.diff

uqs, 09/08/2009 06:52 PM

View differences:

games/hack/Makefile
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
games/hack/config.h
#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
* <sys/wait.h> <wait.h>
* <sys/time.h> <time.h>
* <sgtty.h> <termio.h>
* 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 */
......
#define SHELL /* do not delete the '!' command */
#ifdef BSD
#define SUSPEND /* let ^Z suspend the game */
#endif /* BSD */
#endif /* UNIX */
#ifdef CHDIR
games/hack/hack.h
#include <string.h>
#include <unistd.h>
#ifndef BSD
/* FIXME */
#define index strchr
#define rindex strrchr
#endif /* BSD */
#include "def.objclass.h"
games/hack/hack.ioctl.c
systems (e.g. MUNIX) the include files <termio.h> and <sgtty.h>
define the same constants, and the C preprocessor complains. */
#include "hack.h"
#ifdef BSD
#include <sgtty.h>
struct ltchars ltchars, ltchars0;
#else
#include <termio.h> /* also includes part of <sgtty.h> */
struct termio termio;
#endif /* BSD */
#include <termios.h>
struct termios termio;
void
getioctls(void)
{
#ifdef BSD
ioctl(fileno(stdin), (int) TIOCGLTC, (char *) &ltchars);
ioctl(fileno(stdin), (int) TIOCSLTC, (char *) &ltchars0);
#else
ioctl(fileno(stdin), (int) TCGETA, &termio);
#endif /* BSD */
tcgetattr(fileno(stdin), &termio);
}
void
setioctls(void)
{
#ifdef BSD
ioctl(fileno(stdin), (int) TIOCSLTC, (char *) &ltchars);
#else
ioctl(fileno(stdin), (int) TCSETA, &termio);
#endif /* BSD */
tcsetattr(fileno(stdin), TCSANOW, &termio);
}
#ifdef SUSPEND /* implies BSD */
#ifdef SUSPEND
#include <signal.h>
int
dosuspend(void)
games/hack/hack.pager.c
};
#else
#ifdef BSD
#include <sys/wait.h>
#else
#include <wait.h>
#endif /* BSD */
#endif /* NOWAITINCLUDE */
bool
games/hack/hack.termcap.c
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;
games/hack/hack.tty.c
/* 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 <termios.h>
#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 <termio.h>
#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 <sgtty.h>
#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);
......
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;
......
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)");
}
......
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){
    (1-1/1)