Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/games Converted games to use the new termcap interface.
details: https://anonhg.NetBSD.org/src/rev/ee175aac68f9
branches: trunk
changeset: 486439:ee175aac68f9
user: blymn <blymn%NetBSD.org@localhost>
date: Mon May 22 12:42:46 2000 +0000
description:
Converted games to use the new termcap interface.
diffstat:
games/larn/io.c | 66 ++++++++++++++++++++++++++++++++++++--------------
games/larn/main.c | 5 ++-
games/tetris/screen.c | 28 +++++++++++++-------
games/tetris/screen.h | 3 +-
4 files changed, 70 insertions(+), 32 deletions(-)
diffs (247 lines):
diff -r 8abcbcc23b7c -r ee175aac68f9 games/larn/io.c
--- a/games/larn/io.c Mon May 22 12:08:43 2000 +0000
+++ b/games/larn/io.c Mon May 22 12:42:46 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: io.c,v 1.8 1999/10/04 23:27:02 lukem Exp $ */
+/* $NetBSD: io.c,v 1.9 2000/05/22 12:42:46 blymn Exp $ */
/*
* io.c Larn is copyrighted 1986 by Noah Morgan.
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: io.c,v 1.8 1999/10/04 23:27:02 lukem Exp $");
+__RCSID("$NetBSD: io.c,v 1.9 2000/05/22 12:42:46 blymn Exp $");
#endif /* not lint */
#include "header.h"
@@ -763,7 +763,8 @@
* obvious meanings.
*/
-static char cap[256];
+static char *cap;
+struct tinfo *info;
char *CM, *CE, *CD, *CL, *SO, *SE, *AL, *DL; /* Termcap capabilities */
static char *outbuf = 0; /* translated output buffer */
@@ -773,11 +774,11 @@
void
init_term()
{
- char termbuf[1024];
- char *capptr = cap + 10;
+ char *capptr;
char *term;
- switch (tgetent(termbuf, term = getenv("TERM"))) {
+ *cap = NULL;
+ switch (t_getent(&info, term = getenv("TERM"))) {
case -1:
write(2, "Cannot open termcap file.\n", 26);
exit(1);
@@ -788,16 +789,16 @@
exit(1);
};
- CM = tgetstr("cm", &capptr); /* Cursor motion */
- CE = tgetstr("ce", &capptr); /* Clear to eoln */
- CL = tgetstr("cl", &capptr); /* Clear screen */
+ CM = t_agetstr(info, "cm", &cap, &capptr); /* Cursor motion */
+ CE = t_agetstr(info, "ce", &cap, &capptr); /* Clear to eoln */
+ CL = t_agetstr(info, "cl", &cap, &capptr); /* Clear screen */
/* OPTIONAL */
- AL = tgetstr("al", &capptr); /* Insert line */
- DL = tgetstr("dl", &capptr); /* Delete line */
- SO = tgetstr("so", &capptr); /* Begin standout mode */
- SE = tgetstr("se", &capptr); /* End standout mode */
- CD = tgetstr("cd", &capptr); /* Clear to end of display */
+ AL = t_agetstr(info, "al", &cap, &capptr); /* Insert line */
+ DL = t_agetstr(info, "dl", &cap, &capptr); /* Delete line */
+ SO = t_agetstr(info, "so", &cap, &capptr); /* Begin standout mode */
+ SE = t_agetstr(info, "se", &cap, &capptr); /* End standout mode */
+ CD = t_agetstr(info, "cd", &cap, &capptr); /* Clear to end of display */
if (!CM) { /* can't find cursor motion entry */
write(2, "Sorry, for a ", 13);
@@ -936,6 +937,7 @@
u_char *str;
static int curx = 0;
static int cury = 0;
+ char tgoto_buf[256];
if ((lpoint = lpnt - lpbuf) > 0) {
#ifdef EXTRA
@@ -978,7 +980,9 @@
case CURSOR:
curx = *++str - 1;
cury = *++str - 1;
- tputs(tgoto(CM, curx, cury), 0, xputchar);
+ if (t_goto(info, CM, curx, cury,
+ tgoto_buf, 255) == 0)
+ tputs(tgoto_buf, 0, xputchar);
break;
case '\n':
@@ -989,17 +993,41 @@
if (++scrline > 23)
scrline = 19;
- tputs(tgoto(CM, 0, scrline), 0, xputchar);
+ if (t_goto(info, CM, 0,
+ scrline,
+ tgoto_buf,
+ 255) == 0)
+ tputs(tgoto_buf,
+ 0,
+ xputchar);
tputs(CE, 0, xputchar);
if (--scrline < 19)
scrline = 23;
- tputs(tgoto(CM, 0, scrline), 0, xputchar);
+ if (t_goto(info, CM, 0,
+ scrline,
+ tgoto_buf,
+ 255) == 0)
+ tputs(tgoto_buf,
+ 0,
+ xputchar);
tputs(CE, 0, xputchar);
} else {
- tputs(tgoto(CM, 0, 19), 0, xputchar);
+ if (t_goto(info, CM, 0,
+ 19,
+ tgoto_buf,
+ 255) == 0)
+ tputs(tgoto_buf,
+ 0,
+ xputchar);
tputs(DL, 0, xputchar);
- tputs(tgoto(CM, 0, 23), 0, xputchar);
+ if (t_goto(info, CM, 0,
+ 23,
+ tgoto_buf,
+ 255) == 0)
+ tputs(tgoto_buf,
+ 0,
+ xputchar);
/*
* tputs (AL, 0,
* xputchar);
diff -r 8abcbcc23b7c -r ee175aac68f9 games/larn/main.c
--- a/games/larn/main.c Mon May 22 12:08:43 2000 +0000
+++ b/games/larn/main.c Mon May 22 12:42:46 2000 +0000
@@ -1,9 +1,9 @@
-/* $NetBSD: main.c,v 1.14 1998/08/30 09:19:38 veego Exp $ */
+/* $NetBSD: main.c,v 1.15 2000/05/22 12:42:46 blymn Exp $ */
/* main.c */
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: main.c,v 1.14 1998/08/30 09:19:38 veego Exp $");
+__RCSID("$NetBSD: main.c,v 1.15 2000/05/22 12:42:46 blymn Exp $");
#endif /* not lint */
#include <sys/types.h>
@@ -62,6 +62,7 @@
const char *ptr = 0;
struct passwd *pwe;
+ i = 0;
euid = geteuid();
uid = getuid();
seteuid(uid); /* give up "games" if we have it */
diff -r 8abcbcc23b7c -r ee175aac68f9 games/tetris/screen.c
--- a/games/tetris/screen.c Mon May 22 12:08:43 2000 +0000
+++ b/games/tetris/screen.c Mon May 22 12:42:46 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: screen.c,v 1.13 1999/10/04 23:27:03 lukem Exp $ */
+/* $NetBSD: screen.c,v 1.14 2000/05/22 12:42:47 blymn Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -73,7 +73,6 @@
/*
* Capabilities from TERMCAP.
*/
-char PC, *BC, *UP; /* tgoto requires globals: ugh! */
short ospeed;
static char
@@ -121,8 +120,8 @@
/* This is where we will actually stuff the information */
-static char combuf[1024], tbuf[1024];
-
+static char *combuf;
+static struct tinfo *info;
/*
* Routine used by tputs().
@@ -141,7 +140,15 @@
* count=1. (See screen.h for putpad().)
*/
#define putstr(s) (void)fputs(s, stdout)
-#define moveto(r, c) putpad(tgoto(CMstr, c, r))
+
+void
+moveto(int r, int c)
+{
+ char buf[256];
+
+ if (t_goto(info, CMstr, c, r, buf, 255) == 0)
+ putpad(buf);
+}
/*
* Set up from termcap.
@@ -174,22 +181,23 @@
if ((term = getenv("TERM")) == NULL)
stop("you must set the TERM environment variable");
- if (tgetent(tbuf, term) <= 0)
+ if (t_getent(&info, term) <= 0)
stop("cannot find your termcap");
- fill = combuf;
+ *combuf = NULL;
{
register struct tcsinfo *p;
for (p = tcstrings; p->tcaddr; p++)
- *p->tcaddr = tgetstr(p->tcname, &fill);
+ *p->tcaddr = t_agetstr(info, p->tcname, &combuf,
+ &fill);
}
{
register struct tcninfo *p;
for (p = tcflags; p->tcaddr; p++)
- *p->tcaddr = tgetflag(p->tcname);
+ *p->tcaddr = t_getflag(info, p->tcname);
for (p = tcnums; p->tcaddr; p++)
- *p->tcaddr = tgetnum(p->tcname);
+ *p->tcaddr = t_getnum(info, p->tcname);
}
if (bsflag)
BC = "\b";
diff -r 8abcbcc23b7c -r ee175aac68f9 games/tetris/screen.h
--- a/games/tetris/screen.h Mon May 22 12:08:43 2000 +0000
+++ b/games/tetris/screen.h Mon May 22 12:42:46 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: screen.h,v 1.5 2000/01/01 10:15:17 jsm Exp $ */
+/* $NetBSD: screen.h,v 1.6 2000/05/22 12:42:48 blymn Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -49,6 +49,7 @@
*/
#define putpad(s) tputs(s, 1, put)
+void moveto(int, int);
int put __P((int)); /* just calls putchar; for tputs */
void scr_clear __P((void));
void scr_end __P((void));
Home |
Main Index |
Thread Index |
Old Index