Courtesy of FreeBSD ports.
Also does some additional cleanup.
Submitted-by: Ulrich Spoerlein <uqs@spoerlein.net>
Dragonfly-bugs: <http://bugs.dragonflybsd.org/issue1491>
<http://bugs.dragonflybsd.org/issue1492>
<http://bugs.dragonflybsd.org/issue1493>
# $DragonFly: src/games/backgammon/backgammon/Makefile,v 1.4 2006/10/08 16:22:35 pavalos Exp $
PROG= backgammon
-CFLAGS+=-DV7 -I${.CURDIR}/../common_source
+CFLAGS+=-I${.CURDIR}/../common_source
SRCS= allow.c board.c check.c extra.c fancy.c init.c main.c move.c \
odds.c one.c save.c subs.c table.c text.c version.c
MAN= backgammon.6
*/
#include <stdio.h>
+#include <termcap.h>
+#include <unistd.h>
#include <string.h>
+#include <stdlib.h>
#include <signal.h>
#include "back.h"
};
static const char rules[] = "\nDo you want the rules of the game?";
-static const char noteach[] = "Teachgammon not available!\n\007";
+static const char noteach[] = "Teachgammon not available!\n\a";
static const char need[] = "Do you need instructions for this program?";
static const char askcol[] =
"Enter 'r' to play red, 'w' to play white, 'b' to play both:";
bflag = 2; /* default no board */
acnt = 1; /* Nuber of args */
signal (SIGINT,(sig_t)getout); /* trap interrupts */
- if (ioctl(0, TIOCGETP, &tty) == -1) /* get old tty mode */
- errexit ("backgammon(gtty)");
- old = tty.sg_flags;
-#ifdef V7
- raw = ((noech = old & ~ECHO) | CBREAK); /* set up modes */
-#else
- raw = ((noech = old & ~ECHO) | RAW); /* set up modes */
-#endif
+ if (tcgetattr (0,&tty) == -1) /* get old tty mode */
+ errexit ("backgammon(tcgetattr)");
+ old = tty.c_lflag;
+ raw = ((noech = old & ~ECHO) & ~ICANON); /* set up modes */
+ ospeed = cfgetospeed(&tty); /* for termlib */
/* get terminal
* capabilities, and
getarg (argc, argv);
args[acnt] = NULL;
if (tflag) { /* clear screen */
- noech &= ~(CRMOD|XTABS);
- raw &= ~(CRMOD|XTABS);
+ noech &= ~(ICRNL|OXTABS);
+ raw &= ~(ICRNL|OXTABS);
clear();
}
fixtty (raw); /* go into raw mode */
* $DragonFly: src/games/backgammon/common_source/back.h,v 1.2 2006/08/08 16:36:11 pavalos Exp $
*/
-#include <sgtty.h>
+#include <termios.h>
#include <stdlib.h>
#include <unistd.h>
extern const char *const *Colorptr; /* color of current player, capitalized */
extern int colen; /* length of color of current player */
-extern struct sgttyb tty; /* tty information buffer */
+extern struct termios tty; /* tty information buffer */
extern int old; /* original tty status */
extern int noech; /* original tty status without echo */
extern int raw; /* raw tty status, no echo */
writel (prompt);
fs = fname;
while ((*fs = readc()) != '\n') {
- if (*fs == tty.sg_erase) {
+ if (*fs == tty.c_cc[2]) {
if (fs > fname) {
fs--;
if (tflag)
*/
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "back.h"
if (tflag)
newpos();
buflush();
- tty.sg_flags = mode;
- if (ioctl(0, TIOCSETP, &tty) < 0)
+ tty.c_lflag = mode;
+ if (tcsetattr (0,TCSANOW,&tty) < 0)
errexit("fixtty");
}
}
}
- if (c == tty.sg_erase && ncin > 0) {
+ if (c == tty.c_cc[2] && ncin > 0) {
if (tflag)
curmove (curr,curc-1);
else {
- if (tty.sg_erase == '\010')
+ if (tty.c_cc[2] == '\010')
writel ("\010 \010");
else
writec (cin[ncin-1]);
goto domove;
}
- if (c == tty.sg_kill && ncin > 0) {
+ if (c == tty.c_cc[3] && ncin > 0) {
if (tflag) {
refresh();
curmove (curr,39);
ist = -1;
goto domove;
- } else if (tty.sg_erase == '\010') {
+ } else if (tty.c_cc[2] == '\010') {
for (j = 0; j < ncin; j++)
writel ("\010 \010");
ist = -1;
# $DragonFly: src/games/backgammon/teachgammon/Makefile,v 1.3 2006/10/08 16:22:35 pavalos Exp $
PROG= teachgammon
-CFLAGS+=-DTEACHGAMMON_TEXT -DV7 -I${.CURDIR}/../common_source
+CFLAGS+=-DTEACHGAMMON_TEXT -I${.CURDIR}/../common_source
SRCS= allow.c board.c check.c data.c fancy.c init.c odds.c one.c save.c \
subs.c table.c teach.c ttext1.c ttext2.c tutor.c
DPADD= ${LIBTERMCAP}
#include <string.h>
#include <sys/types.h>
+#include <termcap.h>
+#include <unistd.h>
#include <signal.h>
#include "back.h"
#include "tutor.h"
acnt = 1;
signal (SIGINT,(sig_t)getout);
- if (ioctl(0,TIOCGETP,&tty) == -1) /* get old tty mode */
- errexit ("teachgammon(gtty)");
- old = tty.sg_flags;
-#ifdef V7
- raw = ((noech = old & ~ECHO) | CBREAK); /* set up modes */
-#else
- raw = ((noech = old & ~ECHO) | RAW); /* set up modes */
-#endif
+ if (tcgetattr (0,&tty) == -1) /* get old tty mode */
+ errexit ("teachgammon(tcgetattr)");
+ old = tty.c_lflag;
+ raw = ((noech = old & ~ECHO) & ~ICANON); /* set up modes */
+ ospeed = cfgetospeed(&tty); /* for termlib */
tflag = getcaps (getenv ("TERM"));
getarg (argc, argv);
if (tflag) {
- noech &= ~(CRMOD|XTABS);
- raw &= ~(CRMOD|XTABS);
+ noech &= ~(ICRNL|OXTABS);
+ raw &= ~(ICRNL|OXTABS);
clear();
}
text (hello);
#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
#include <string.h>
#include <unistd.h>
-#ifndef BSD
+/* FIXME */
#define index strchr
#define rindex strrchr
-#endif /* BSD */
#include "def.objclass.h"
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 *) <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 <signal.h>
int
dosuspend(void)
};
#else
-
-#ifdef BSD
#include <sys/wait.h>
-#else
-#include <wait.h>
-#endif /* BSD */
#endif /* NOWAITINCLUDE */
bool
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;
/* 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)");
}
void
setftty(void)
{
-int ef = 0; /* desired value of flags & ECHO */
-int cf = CBRKON(CBRKMASK); /* desired value of flags & CBREAK */
+u_long ef = 0; /* desired value of flags & ECHO */
+u_long 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){
# EXTRA
# Incorporates code to gather additional performance statistics
-# SYSV
-# Use system III/V (instead of V7) type ioctl calls
-# BSD
-# Use BSD specific features (mostly timer and signal stuff)
-# BSD4.1
-# Use BSD4.1 to avoid some 4.2 dependencies (must be used with
-# BSD above; do not mix with SYSV)
# HIDEBYLINK
# If defined, the program attempts to hide from ps
# DOCHECKPOINTS
# This is the revision of the software, example: 1
# FLUSHNO=#
# Set the input queue excess flushing threshold (default 5)
-# NOVARARGS
-# Define for systems that don't have varargs (a default varargs will
-# be used).
# MACRORND
# Define to use macro version of rnd() and rund() (fast and big)
# UIDSCORE
PROG= larn
MAN= larn.6
-CFLAGS+=-DBSD -DVER=12 -DSUBVER=0 -DNONAP -DUIDSCORE
+CFLAGS+=-DVER=12 -DSUBVER=0 -DNONAP -DUIDSCORE
SRCS= main.c object.c create.c tok.c display.c global.c data.c io.c \
monster.c store.c diag.c help.c config.c nap.c bill.c scores.c \
signal.c moreobj.c movem.c regen.c fortune.c savelev.c
* Note: ** entries are available only in termcap mode.
*/
+#include <stdarg.h>
+#include <termios.h>
#include "header.h"
-#ifdef SYSV /* system III or system V */
-#include <termio.h>
-#define sgttyb termio
-#define stty(_a,_b) ioctl(_a,TCSETA,_b)
-#define gtty(_a,_b) ioctl(_a,TCGETA,_b)
static int rawflg = 0;
static char saveeof,saveeol;
-#define doraw(_a) if(!rawflg){++rawflg;saveeof=_a.c_cc[VMIN];saveeol=_a.c_cc[VTIME];}\
- _a.c_cc[VMIN]=1;_a.c_cc[VTIME]=1;_a.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL)
-#define unraw(_a) _a.c_cc[VMIN]=saveeof;_a.c_cc[VTIME]=saveeol;_a.c_lflag |= ICANON|ECHO|ECHOE|ECHOK|ECHONL
-
-#else /* not SYSV */
-
-#ifndef BSD
-#define CBREAK RAW /* V7 has no CBREAK */
-#endif
-
-#define doraw(_a) (_a.sg_flags |= CBREAK,_a.sg_flags &= ~ECHO)
-#define unraw(_a) (_a.sg_flags &= ~CBREAK,_a.sg_flags |= ECHO)
-#include <sgtty.h>
-#define stty(_a,_b) ioctl(_a,TIOCSETP,_b)
-#define gtty(_a,_b) ioctl(_a,TIOCGETP,_b)
-#endif /* not SYSV */
-
-#ifndef NOVARARGS /* if we have varargs */
-#include <stdarg.h>
-#else /* NOVARARGS */ /* if we don't have varargs */
-typedef char *va_list;
-#define va_dcl int va_alist;
-#define va_start(plist) plist = (char *) &va_alist
-#define va_end(plist)
-#define va_arg(plist,mode) ((mode *)(plist += sizeof(mode)))[-1]
-#endif /* NOVARARGS */
#define LINBUFSIZE 128 /* size of the lgetw() and lgetl() buffer */
int lfd; /* output file numbers */
int fd; /* input file numbers */
-static struct sgttyb ttx; /* storage for the tty modes */
+static struct termios ttx; /* storage for the tty modes */
static int ipoint=MAXIBUF,iepoint=MAXIBUF; /* input buffering pointers */
static char lgetwbuf[LINBUFSIZE]; /* get line (word) buffer */
void
scbr(void)
{
- gtty(0,&ttx); doraw(ttx); stty(0,&ttx);
+ tcgetattr(0,&ttx);
+ /* doraw */
+ if (!rawflg) {
+ ++rawflg;
+ saveeof=ttx.c_cc[VMIN];
+ saveeol=ttx.c_cc[VTIME];
+ }
+ ttx.c_cc[VMIN]=1;
+ ttx.c_cc[VTIME]=1;
+ ttx.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL);
+ tcsetattr(0,TCSANOW,&ttx);
}
/*
void
sncbr(void)
{
- gtty(0,&ttx); unraw(ttx); stty(0,&ttx);
+ tcgetattr(0,&ttx);
+ /* unraw */
+ ttx.c_cc[VMIN]=saveeof;
+ ttx.c_cc[VTIME]=saveeol;
+ ttx.c_lflag |= ICANON|ECHO|ECHOE|ECHOK|ECHONL;
+ tcsetattr(0,TCSANOW,&ttx);
}
/*
#endif /* SIGTSTP */
}
-#ifdef BSD /* for BSD UNIX? */
-
static const char *signame[NSIG] = { "",
"SIGHUP", /* 1 hangup */
"SIGINT", /* 2 interrupt */
"SIGXFSZ", /* 25 exceeded file size limit */
"SIGVTALRM",/* 26 virtual time alarm */
"SIGPROF", /* 27 profiling time alarm */
-"","","","" };
-
-#else /* for system V? */
-
-static const char *signame[NSIG] = { "",
-"SIGHUP", /* 1 hangup */
-"SIGINT", /* 2 interrupt */
-"SIGQUIT", /* 3 quit */
-"SIGILL", /* 4 illegal instruction (not reset when caught) */
-"SIGTRAP", /* 5 trace trap (not reset when caught) */
-"SIGIOT", /* 6 IOT instruction */
-"SIGEMT", /* 7 EMT instruction */
-"SIGFPE", /* 8 floating point exception */
-"SIGKILL", /* 9 kill (cannot be caught or ignored) */
-"SIGBUS", /* 10 bus error */
-"SIGSEGV", /* 11 segmentation violation */
-"SIGSYS", /* 12 bad argument to system call */
-"SIGPIPE", /* 13 write on a pipe with no one to read it */
-"SIGALRM", /* 14 alarm clock */
-"SIGTERM", /* 15 software termination signal from kill */
-"SIGUSR1", /* 16 user defines signal 1 */
-"SIGUSR2", /* 17 user defines signal 2 */
-"SIGCLD", /* 18 child death */
-"SIGPWR", /* 19 power fail */
-"","","","","","","","","","","","" };
-
-#endif /* BSD */
+"SIGWINCH",/* 28 window size changes */
+"SIGINFO",/* 29 information request */
+"SIGUSR1",/* 30 user defined signal 1 */
+"SIGUSR2",/* 31 user defined signal 2 */
+};
/*
* routine to process a fatal error signal