-/* $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
#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 */
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",
/* 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
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
writel (rules);
if (yorn(0)) {
- fixtty (old); /* restore tty */
+ fixtty (&old); /* restore tty */
execl (TEACH,"teachgammon",args,0);
tflag = 0; /* error! */
-/* $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
#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 */
* 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;
}
buflush();
sleep (3);
}
- fixtty (raw); /* no more tty interrupt */
+ fixtty (&raw); /* no more tty interrupt */
}
\f
trymove (mvnum,swapped)
-/* $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
#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 */
register int i;
register char *s, *a;
- fixtty (noech);
+ fixtty (&noech);
while (*t != 0) {
s = a = *t;
for (i = 0; *a != '\0'; i--)
writec ('\n');
} else {
writel ("-->");
- fixtty (raw);
+ fixtty (&raw);
while ((i = readc()) != ' ' && i != '\n');
- fixtty (noech);
+ fixtty (&noech);
clear();
}
t++;
}
- fixtty (raw);
+ fixtty (&raw);
}
-/* $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
* @(#)back.h 8.1 (Berkeley) 5/31/93
*/
-#include <sgtty.h>
+#include <termios.h>
#include <stdlib.h>
#include <string.h>
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 */
-/* $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
#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 */
static char sv[] =
"| | | | \n";
- fixtty (noech);
+ fixtty (&noech);
clear();
if (tflag) {
writec ('\n');
writec ('\n');
}
- fixtty(raw);
+ fixtty(&raw);
}
\f
wrbsub () {
-/* $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
#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.
-/* $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
#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 */
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)
-/* $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
#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 */
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");
}
writec ('\n');
/* fix terminal status */
- fixtty (old);
+ fixtty (&old);
exit(0);
}
roll () {
-/* $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
#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 */
}
}
- 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]);
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;
-/* $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
#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 */
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",
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)
#endif
getarg (&argv);
if (tflag) {
- noech &= ~(CRMOD|XTABS);
- raw &= ~(CRMOD|XTABS);
+ noech.c_oflag &= ~(ONLCR|OXTABS);
+ raw.c_oflag &= ~(ONLCR|OXTABS);
clear();
}
text (hello);
clear();
else
writec ('\n');
- fixtty(old);
+ fixtty(&old);
execl (EXEC,"backgammon",args,"n",0);
writel ("Help! Backgammon program is missing\007!!\n");
exit (-1);
-/* $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
#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 */
char *c;
int i;
- fixtty (noech);
+ fixtty (&noech);
begin = txt;
while (*txt) {
a = *(txt++);
writel (a);
writec ('\n');
} else {
- fixtty (raw);
+ fixtty (&raw);
writel (prompt);
for (;;) {
if ((b = readc()) == '?') {
writec ('\n');
if (i)
return(i);
- fixtty (noech);
+ fixtty (&noech);
if (tflag)
curmove (curr,0);
begin = txt;
}
}
- fixtty (raw);
+ fixtty (&raw);
return (0);
}
-/* $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
#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 */
#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();
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;
}
(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);
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);
}