Use POSIX tty semantics.

This commit is contained in:
mycroft 1995-04-29 00:44:03 +00:00
parent 30675b877b
commit eab5a76524
12 changed files with 78 additions and 111 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.3 1995/04/24 12:21:52 cgd Exp $ */
/* $NetBSD: main.c,v 1.4 1995/04/29 00:44:03 mycroft Exp $ */
/*
* Copyright (c) 1980, 1993
@ -43,7 +43,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93";
#else
static char rcsid[] = "$NetBSD: main.c,v 1.3 1995/04/24 12:21:52 cgd Exp $";
static char rcsid[] = "$NetBSD: main.c,v 1.4 1995/04/29 00:44:03 mycroft Exp $";
#endif
#endif /* not lint */
@ -55,7 +55,7 @@ static char rcsid[] = "$NetBSD: main.c,v 1.3 1995/04/24 12:21:52 cgd Exp $";
char *instr[]; /* text of instructions */
char *message[]; /* update message */
char ospeed; /* tty output speed */
speed_t ospeed; /* tty output speed */
char *helpm[] = { /* help message */
"Enter a space or newline to roll, or",
@ -111,16 +111,14 @@ char **argv;
/* initialization */
bflag = 2; /* default no board */
signal (2,getout); /* trap interrupts */
if (gtty (0,&tty) == -1) /* get old tty mode */
signal (2, getout); /* trap interrupts */
if (tcgetattr (0, &old) == -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
ospeed = tty.sg_ospeed; /* for termlib */
noech = old;
noech.c_lflag &= ~ECHO;
raw = noech;
raw.c_lflag &= ~ICANON; /* set up modes */
ospeed = cfgetospeed (&old); /* for termlib */
/* check user count */
# ifdef CORY
@ -152,11 +150,11 @@ char **argv;
getarg (&argv);
args[acnt] = '\0';
if (tflag) { /* clear screen */
noech &= ~(CRMOD|XTABS);
raw &= ~(CRMOD|XTABS);
noech.c_oflag &= ~(ONLCR|OXTABS);
raw.c_oflag &= ~(ONLCR|OXTABS);
clear();
}
fixtty (raw); /* go into raw mode */
fixtty (&raw); /* go into raw mode */
/* check if restored
* game and save flag
@ -179,7 +177,7 @@ char **argv;
writel (rules);
if (yorn(0)) {
fixtty (old); /* restore tty */
fixtty (&old); /* restore tty */
execl (TEACH,"teachgammon",args,0);
tflag = 0; /* error! */

View File

@ -1,4 +1,4 @@
/* $NetBSD: move.c,v 1.4 1995/03/21 15:05:10 cgd Exp $ */
/* $NetBSD: move.c,v 1.5 1995/04/29 00:44:05 mycroft Exp $ */
/*
* Copyright (c) 1980, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)move.c 8.1 (Berkeley) 5/31/93";
#else
static char rcsid[] = "$NetBSD: move.c,v 1.4 1995/03/21 15:05:10 cgd Exp $";
static char rcsid[] = "$NetBSD: move.c,v 1.5 1995/04/29 00:44:05 mycroft Exp $";
#endif
#endif /* not lint */
@ -131,14 +131,14 @@ int okay; /* zero if first move */
* while thinking */
if (tflag)
cline();
fixtty (noech);
fixtty (&noech);
/* find out how many moves */
mvlim = movallow();
if (mvlim == 0) {
writel (" but cannot use it.\n");
nexturn();
fixtty (raw);
fixtty (&raw);
return;
}
@ -176,7 +176,7 @@ int okay; /* zero if first move */
buflush();
sleep (3);
}
fixtty (raw); /* no more tty interrupt */
fixtty (&raw); /* no more tty interrupt */
}
trymove (mvnum,swapped)

View File

@ -1,4 +1,4 @@
/* $NetBSD: text.c,v 1.3 1995/03/21 15:05:13 cgd Exp $ */
/* $NetBSD: text.c,v 1.4 1995/04/29 00:44:06 mycroft Exp $ */
/*
* Copyright (c) 1980, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)text.c 8.1 (Berkeley) 5/31/93";
#else
static char rcsid[] = "$NetBSD: text.c,v 1.3 1995/03/21 15:05:13 cgd Exp $";
static char rcsid[] = "$NetBSD: text.c,v 1.4 1995/04/29 00:44:06 mycroft Exp $";
#endif
#endif /* not lint */
@ -117,7 +117,7 @@ char **t;
register int i;
register char *s, *a;
fixtty (noech);
fixtty (&noech);
while (*t != 0) {
s = a = *t;
for (i = 0; *a != '\0'; i--)
@ -127,12 +127,12 @@ char **t;
writec ('\n');
} else {
writel ("-->");
fixtty (raw);
fixtty (&raw);
while ((i = readc()) != ' ' && i != '\n');
fixtty (noech);
fixtty (&noech);
clear();
}
t++;
}
fixtty (raw);
fixtty (&raw);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: back.h,v 1.4 1995/04/24 12:22:06 cgd Exp $ */
/* $NetBSD: back.h,v 1.5 1995/04/29 00:44:10 mycroft Exp $ */
/*
* Copyright (c) 1980, 1993
@ -35,7 +35,7 @@
* @(#)back.h 8.1 (Berkeley) 5/31/93
*/
#include <sgtty.h>
#include <termios.h>
#include <stdlib.h>
#include <string.h>
@ -118,10 +118,7 @@ char **colorptr; /* color of current player */
char **Colorptr; /* color of current player, capitalized */
int colen; /* length of color of current player */
struct sgttyb tty; /* tty information buffer */
int old; /* original tty status */
int noech; /* original tty status without echo */
int raw; /* raw tty status, no echo */
struct termios old, noech, raw;/* original tty status */
int curr; /* row position of cursor */
int curc; /* column position of cursor */

View File

@ -1,4 +1,4 @@
/* $NetBSD: board.c,v 1.3 1995/03/21 15:05:34 cgd Exp $ */
/* $NetBSD: board.c,v 1.4 1995/04/29 00:44:11 mycroft Exp $ */
/*
* Copyright (c) 1980, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)board.c 8.1 (Berkeley) 5/31/93";
#else
static char rcsid[] = "$NetBSD: board.c,v 1.3 1995/03/21 15:05:34 cgd Exp $";
static char rcsid[] = "$NetBSD: board.c,v 1.4 1995/04/29 00:44:11 mycroft Exp $";
#endif
#endif /* not lint */
@ -53,7 +53,7 @@ wrboard () {
static char sv[] =
"| | | | \n";
fixtty (noech);
fixtty (&noech);
clear();
if (tflag) {
@ -159,7 +159,7 @@ lastline:
writec ('\n');
writec ('\n');
}
fixtty(raw);
fixtty(&raw);
}
wrbsub () {

View File

@ -1,4 +1,4 @@
/* $NetBSD: init.c,v 1.3 1995/03/21 15:05:44 cgd Exp $ */
/* $NetBSD: init.c,v 1.4 1995/04/29 00:44:12 mycroft Exp $ */
/*
* Copyright (c) 1980, 1993
@ -37,11 +37,11 @@
#if 0
static char sccsid[] = "@(#)init.c 8.1 (Berkeley) 5/31/93";
#else
static char rcsid[] = "$NetBSD: init.c,v 1.3 1995/03/21 15:05:44 cgd Exp $";
static char rcsid[] = "$NetBSD: init.c,v 1.4 1995/04/29 00:44:12 mycroft Exp $";
#endif
#endif /* not lint */
#include <sgtty.h>
#include <termios.h>
/*
* variable initialization.

View File

@ -1,4 +1,4 @@
/* $NetBSD: save.c,v 1.3 1995/03/21 15:05:52 cgd Exp $ */
/* $NetBSD: save.c,v 1.4 1995/04/29 00:44:13 mycroft Exp $ */
/*
* Copyright (c) 1980, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)save.c 8.1 (Berkeley) 5/31/93";
#else
static char rcsid[] = "$NetBSD: save.c,v 1.3 1995/03/21 15:05:52 cgd Exp $";
static char rcsid[] = "$NetBSD: save.c,v 1.4 1995/04/29 00:44:13 mycroft Exp $";
#endif
#endif /* not lint */
@ -79,7 +79,7 @@ register int n;
writel (prompt);
fs = fname;
while ((*fs = readc()) != '\n') {
if (*fs == tty.sg_erase) {
if (*fs == old.c_cc[VERASE]) {
if (fs > fname) {
fs--;
if (tflag)

View File

@ -1,4 +1,4 @@
/* $NetBSD: subs.c,v 1.4 1995/04/24 12:22:12 cgd Exp $ */
/* $NetBSD: subs.c,v 1.5 1995/04/29 00:44:15 mycroft Exp $ */
/*
* Copyright (c) 1980, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)subs.c 8.1 (Berkeley) 5/31/93";
#else
static char rcsid[] = "$NetBSD: subs.c,v 1.4 1995/04/24 12:22:12 cgd Exp $";
static char rcsid[] = "$NetBSD: subs.c,v 1.5 1995/04/29 00:44:15 mycroft Exp $";
#endif
#endif /* not lint */
@ -413,14 +413,13 @@ wrscore () {
wrint (wscore);
}
fixtty (mode)
int mode;
fixtty (t)
struct termios *t;
{
if (tflag)
newpos();
buflush();
tty.sg_flags = mode;
if (stty (0,&tty) < 0)
if (tcsetattr (0, TCSADRAIN, t) < 0)
errexit("fixtty");
}
@ -433,7 +432,7 @@ getout () {
writec ('\n');
/* fix terminal status */
fixtty (old);
fixtty (&old);
exit(0);
}
roll () {

View File

@ -1,4 +1,4 @@
/* $NetBSD: table.c,v 1.3 1995/03/21 15:05:58 cgd Exp $ */
/* $NetBSD: table.c,v 1.4 1995/04/29 00:44:16 mycroft Exp $ */
/*
* Copyright (c) 1980, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)table.c 8.1 (Berkeley) 5/31/93";
#else
static char rcsid[] = "$NetBSD: table.c,v 1.3 1995/03/21 15:05:58 cgd Exp $";
static char rcsid[] = "$NetBSD: table.c,v 1.4 1995/04/29 00:44:16 mycroft Exp $";
#endif
#endif /* not lint */
@ -118,11 +118,11 @@ dochar:
}
}
if (c == tty.sg_erase && ncin > 0) {
if (c == old.c_cc[VERASE] && ncin > 0) {
if (tflag)
curmove (curr,curc-1);
else {
if (tty.sg_erase == '\010')
if (old.c_cc[VERASE] == '\010')
writel ("\010 \010");
else
writec (cin[ncin-1]);
@ -139,13 +139,13 @@ dochar:
goto domove;
}
if (c == tty.sg_kill && ncin > 0) {
if (c == old.c_cc[VKILL] && ncin > 0) {
if (tflag) {
refresh();
curmove (curr,39);
ist = -1;
goto domove;
} else if (tty.sg_erase == '\010') {
} else if (old.c_cc[VERASE] == '\010') {
for (j = 0; j < ncin; j++)
writel ("\010 \010");
ist = -1;

View File

@ -1,4 +1,4 @@
/* $NetBSD: teach.c,v 1.3 1995/03/21 15:06:13 cgd Exp $ */
/* $NetBSD: teach.c,v 1.4 1995/04/29 00:44:18 mycroft Exp $ */
/*
* Copyright (c) 1980, 1993
@ -43,7 +43,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)teach.c 8.1 (Berkeley) 5/31/93";
#else
static char rcsid[] = "$NetBSD: teach.c,v 1.3 1995/03/21 15:06:13 cgd Exp $";
static char rcsid[] = "$NetBSD: teach.c,v 1.4 1995/04/29 00:44:18 mycroft Exp $";
#endif
#endif /* not lint */
@ -62,7 +62,7 @@ char *stragy[];
char *prog[];
char *lastch[];
extern char ospeed; /* tty output speed for termlib */
extern speed_t ospeed; /* tty output speed for termlib */
char *helpm[] = {
"\nEnter a space or newline to roll, or",
@ -85,15 +85,13 @@ char **argv;
register int i;
signal (2,getout);
if (gtty (0,&tty) == -1) /* get old tty mode */
if (tcgetattr (0, &old) == -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
ospeed = tty.sg_ospeed; /* for termlib */
noech = old;
noech.c_lflag &= ~ECHO;
raw = noech;
raw.c_lflag &= ~ICANON; /* set up modes */
ospeed = cfgetospeed (&old); /* for termlib */
tflag = getcaps (getenv ("TERM"));
#ifdef V7
while (*++argv != 0)
@ -102,8 +100,8 @@ char **argv;
#endif
getarg (&argv);
if (tflag) {
noech &= ~(CRMOD|XTABS);
raw &= ~(CRMOD|XTABS);
noech.c_oflag &= ~(ONLCR|OXTABS);
raw.c_oflag &= ~(ONLCR|OXTABS);
clear();
}
text (hello);
@ -165,7 +163,7 @@ leave() {
clear();
else
writec ('\n');
fixtty(old);
fixtty(&old);
execl (EXEC,"backgammon",args,"n",0);
writel ("Help! Backgammon program is missing\007!!\n");
exit (-1);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ttext2.c,v 1.3 1995/03/21 15:06:22 cgd Exp $ */
/* $NetBSD: ttext2.c,v 1.4 1995/04/29 00:44:20 mycroft Exp $ */
/*
* Copyright (c) 1980, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)ttext2.c 8.1 (Berkeley) 5/31/93";
#else
static char rcsid[] = "$NetBSD: ttext2.c,v 1.3 1995/03/21 15:06:22 cgd Exp $";
static char rcsid[] = "$NetBSD: ttext2.c,v 1.4 1995/04/29 00:44:20 mycroft Exp $";
#endif
#endif /* not lint */
@ -139,7 +139,7 @@ char **txt;
char *c;
int i;
fixtty (noech);
fixtty (&noech);
begin = txt;
while (*txt) {
a = *(txt++);
@ -149,7 +149,7 @@ char **txt;
writel (a);
writec ('\n');
} else {
fixtty (raw);
fixtty (&raw);
writel (prompt);
for (;;) {
if ((b = readc()) == '?') {
@ -188,12 +188,12 @@ char **txt;
writec ('\n');
if (i)
return(i);
fixtty (noech);
fixtty (&noech);
if (tflag)
curmove (curr,0);
begin = txt;
}
}
fixtty (raw);
fixtty (&raw);
return (0);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: rain.c,v 1.6 1995/04/22 10:26:09 cgd Exp $ */
/* $NetBSD: rain.c,v 1.7 1995/04/29 00:51:04 mycroft Exp $ */
/*
* Copyright (c) 1980, 1993
@ -43,7 +43,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)rain.c 8.1 (Berkeley) 5/31/93";
#else
static char rcsid[] = "$NetBSD: rain.c,v 1.6 1995/04/22 10:26:09 cgd Exp $";
static char rcsid[] = "$NetBSD: rain.c,v 1.7 1995/04/29 00:51:04 mycroft Exp $";
#endif
#endif /* not lint */
@ -54,20 +54,12 @@ static char rcsid[] = "$NetBSD: rain.c,v 1.6 1995/04/22 10:26:09 cgd Exp $";
#include <sys/types.h>
#include <stdio.h>
#ifdef USG
#include <termio.h>
#else
#include <sgtty.h>
#endif
#include <termios.h>
#include <signal.h>
#define cursor(c, r) tputs(tgoto(CM, c, r), 1, fputchar)
#ifdef USG
static struct termio sg, old_tty;
#else
static struct sgttyb sg, old_tty;
#endif
static struct termios sg, old_tty;
void fputchar __P((int));
char *LL, *TE, *tgoto();
@ -76,7 +68,7 @@ main(argc, argv)
int argc;
char **argv;
{
extern short ospeed;
extern speed_t ospeed;
extern char *UP;
register int x, y, j;
register char *CM, *BC, *DN, *ND, *term;
@ -137,32 +129,19 @@ main(argc, argv)
}
(void)strcpy(LL, tgoto(CM, 0, 23));
}
#ifdef USG
ioctl(1, TCGETA, &sg);
ospeed = sg.c_cflag&CBAUD;
#else
gtty(1, &sg);
ospeed = sg.sg_ospeed;
#endif
(void)signal(SIGHUP, onsig);
(void)signal(SIGINT, onsig);
(void)signal(SIGQUIT, onsig);
(void)signal(SIGSTOP, onsig);
(void)signal(SIGTSTP, onsig);
(void)signal(SIGTERM, onsig);
#ifdef USG
ioctl(1, TCGETA, &old_tty); /* save tty bits for exit */
ioctl(1, TCGETA, &sg);
tcgetattr(1, &sg);
old_tty = sg;
ospeed = cfgetospeed(&sg);
sg.c_iflag &= ~ICRNL;
sg.c_oflag &= ~ONLCR;
sg.c_lflag &= ~ECHO;
ioctl(1, TCSETAW, &sg);
#else
gtty(1, &old_tty); /* save tty bits for exit */
gtty(1, &sg);
sg.sg_flags &= ~(CRMOD|ECHO);
stty(1, &sg);
#endif
tcsetattr(1, TCSADRAIN, &sg);
if (TI)
tputs(TI, 1, fputchar);
tputs(tgetstr("cl", &tcp), 1, fputchar);
@ -247,11 +226,7 @@ onsig()
if (TE)
tputs(TE, 1, fputchar);
(void)fflush(stdout);
#ifdef USG
ioctl(1, TCSETAW, &old_tty);
#else
stty(1, &old_tty);
#endif
tcsetattr(1, TCSADRAIN, &old_tty);
exit(0);
}