diff options
author | roy <roy@NetBSD.org> | 2010-02-03 15:34:37 +0000 |
---|---|---|
committer | roy <roy@NetBSD.org> | 2010-02-03 15:34:37 +0000 |
commit | 164f814056645ef1910d5bf4c9147929e07c3a7c (patch) | |
tree | 69388c3d125835723e2b47ab72df148e22abe10b /tetris | |
parent | bd6c81dd776fddd0e7853f2cfb907dc91723f8c3 (diff) | |
download | bsdgames-darwin-164f814056645ef1910d5bf4c9147929e07c3a7c.tar.gz bsdgames-darwin-164f814056645ef1910d5bf4c9147929e07c3a7c.tar.zst bsdgames-darwin-164f814056645ef1910d5bf4c9147929e07c3a7c.zip |
Userland now builds and uses terminfo instead of termcap.
OK: core@, jdc@
Diffstat (limited to 'tetris')
-rw-r--r-- | tetris/Makefile | 6 | ||||
-rw-r--r-- | tetris/scores.c | 10 | ||||
-rw-r--r-- | tetris/screen.c | 178 |
3 files changed, 44 insertions, 150 deletions
diff --git a/tetris/Makefile b/tetris/Makefile index 19122c16..25a3639a 100644 --- a/tetris/Makefile +++ b/tetris/Makefile @@ -1,11 +1,11 @@ -# $NetBSD: Makefile,v 1.6 2008/01/28 07:03:59 dholland Exp $ +# $NetBSD: Makefile,v 1.7 2010/02/03 15:34:39 roy Exp $ # @(#)Makefile 8.1 (Berkeley) 5/31/93 PROG= tetris SRCS= input.c screen.c shapes.c scores.c tetris.c MAN= tetris.6 -DPADD= ${LIBTERM} -LDADD= -ltermcap +DPADD= ${LIBTERMINFO} +LDADD= -lterminfo HIDEGAME=hidegame SETGIDGAME=yes diff --git a/tetris/scores.c b/tetris/scores.c index eaf2618c..42c427e0 100644 --- a/tetris/scores.c +++ b/tetris/scores.c @@ -1,4 +1,4 @@ -/* $NetBSD: scores.c,v 1.18 2009/09/08 13:38:01 dholland Exp $ */ +/* $NetBSD: scores.c,v 1.19 2010/02/03 15:34:39 roy Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -50,7 +50,7 @@ #include <string.h> #include <sys/stat.h> #include <time.h> -#include <termcap.h> +#include <term.h> #include <unistd.h> #include "pathnames.h" @@ -861,7 +861,7 @@ showscores(int level) * the high scores; we do not need to check for printing in highlight * mode. If SOstr is null, we can't do highlighting anyway. */ - me = level && SOstr ? thisuser() : NULL; + me = level && enter_standout_mode ? thisuser() : NULL; /* * Set times to 0 except for high score on each level. @@ -939,12 +939,12 @@ printem(int level, int offset, struct highscore *hs, int n, const char *me) sp->hs_level == level && sp->hs_score == score && strcmp(sp->hs_name, me) == 0) { - putpad(SOstr); + putpad(enter_standout_mode); highlight = 1; } (void)printf("%s", buf); if (highlight) { - putpad(SEstr); + putpad(exit_standout_mode); highlight = 0; } diff --git a/tetris/screen.c b/tetris/screen.c index cb9d2023..ed9e849b 100644 --- a/tetris/screen.c +++ b/tetris/screen.c @@ -1,4 +1,4 @@ -/* $NetBSD: screen.c,v 1.25 2009/12/19 19:27:53 ahoka Exp $ */ +/* $NetBSD: screen.c,v 1.26 2010/02/03 15:34:39 roy Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -46,7 +46,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <termcap.h> +#include <term.h> #include <termios.h> #include <unistd.h> @@ -68,62 +68,6 @@ static void stopset(int) __dead; /* - * Capabilities from TERMCAP. - */ -extern short ospeed; - -static char - *bcstr, /* backspace char */ - *CEstr, /* clear to end of line */ - *CLstr, /* clear screen */ - *CMstr, /* cursor motion string */ -#ifdef unneeded - *CRstr, /* "\r" equivalent */ -#endif - *HOstr, /* cursor home */ - *LLstr, /* last line, first column */ - *pcstr, /* pad character */ - *TEstr, /* end cursor motion mode */ - *TIstr, /* begin cursor motion mode */ - *VIstr, /* make cursor invisible */ - *VEstr; /* make cursor appear normal */ -char - *SEstr, /* end standout mode */ - *SOstr; /* begin standout mode */ -static int - COnum, /* co# value */ - LInum, /* li# value */ - MSflag; /* can move in standout mode */ - - -static struct tcsinfo { /* termcap string info; some abbrevs above */ - char tcname[3]; - char **tcaddr; -} tcstrings[] = { - {"bc", &bcstr}, - {"ce", &CEstr}, - {"cl", &CLstr}, - {"cm", &CMstr}, -#ifdef unneeded - {"cr", &CRstr}, -#endif - {"le", &BC}, /* move cursor left one space */ - {"pc", &pcstr}, - {"se", &SEstr}, - {"so", &SOstr}, - {"te", &TEstr}, - {"ti", &TIstr}, - {"vi", &VIstr}, - {"ve", &VEstr}, - {"up", &UP}, /* cursor up */ - { {0}, NULL} -}; - -/* This is where we will actually stuff the information */ - -static struct tinfo *info; - -/* * Routine used by tputs(). */ int @@ -143,9 +87,10 @@ put(int c) static void moveto(int r, int c) { - char buf[256]; + char *buf; - if (t_goto(info, CMstr, c, r, buf, 255) == 0) + buf = vtparm(cursor_address, r, c); + if (buf != NULL) putpad(buf); } @@ -155,65 +100,12 @@ moveto(int r, int c) void scr_init(void) { - static int bsflag, xsflag, sgnum; -#ifdef unneeded - static int ncflag; -#endif - char *term; - static struct tcninfo { /* termcap numeric and flag info */ - char tcname[3]; - int *tcaddr; - } tcflags[] = { - {"bs", &bsflag}, - {"ms", &MSflag}, -#ifdef unneeded - {"nc", &ncflag}, -#endif - {"xs", &xsflag}, - { {0}, NULL} - }, tcnums[] = { - {"co", &COnum}, - {"li", &LInum}, - {"sg", &sgnum}, - { {0}, NULL} - }; - static char backspace[] = "\b"; - - if ((term = getenv("TERM")) == NULL) - stop("you must set the TERM environment variable"); - if (t_getent(&info, term) <= 0) - stop("cannot find your termcap"); - { - struct tcsinfo *p; - - for (p = tcstrings; p->tcaddr; p++) - *p->tcaddr = t_agetstr(info, p->tcname); - } - { - struct tcninfo *p; - for (p = tcflags; p->tcaddr; p++) - *p->tcaddr = t_getflag(info, p->tcname); - for (p = tcnums; p->tcaddr; p++) - *p->tcaddr = t_getnum(info, p->tcname); - } - if (bsflag) - BC = backspace; - else if (BC == NULL && bcstr != NULL) - BC = bcstr; - if (CLstr == NULL) + setupterm(NULL, 0, NULL); + if (clear_screen == NULL) stop("cannot clear screen"); - if (CMstr == NULL || UP == NULL || BC == NULL) - stop("cannot do random cursor positioning via tgoto()"); - PC = pcstr ? *pcstr : 0; - if (sgnum >= 0 || xsflag) - SOstr = SEstr = NULL; -#ifdef unneeded - if (ncflag) - CRstr = NULL; - else if (CRstr == NULL) - CRstr = "\r"; -#endif + if (cursor_address == NULL || cursor_up == NULL) + stop("cannot do random cursor positioning"); } /* this foolery is needed to modify tty state `atomically' */ @@ -278,9 +170,9 @@ scr_set(void) Cols = ws.ws_col; } if (Rows == 0) - Rows = LInum; + Rows = lines; if (Cols == 0) - Cols = COnum; + Cols = columns; if (Rows < MINROWS || Cols < MINCOLS) { (void) fprintf(stderr, "the screen is too small: must be at least %dx%d, ", @@ -301,10 +193,10 @@ scr_set(void) * We made it. We are now in screen mode, modulo TIstr * (which we will fix immediately). */ - if (TIstr) - putstr(TIstr); /* termcap(5) says this is not padded */ - if (VIstr) - putstr(VIstr); /* termcap(5) says this is not padded */ + if (enter_ca_mode) + putstr(enter_ca_mode); + if (cursor_invisible) + putstr(cursor_invisible); if (tstp != SIG_IGN) (void) signal(SIGTSTP, scr_stop); if (ttou != SIG_IGN) @@ -328,15 +220,15 @@ scr_end(void) sigaddset(&nsigset, SIGTTOU); (void) sigprocmask(SIG_BLOCK, &nsigset, &osigset); /* move cursor to last line */ - if (LLstr) - putstr(LLstr); /* termcap(5) says this is not padded */ + if (cursor_to_ll) + putstr(cursor_to_ll); else moveto(Rows - 1, 0); /* exit screen mode */ - if (TEstr) - putstr(TEstr); /* termcap(5) says this is not padded */ - if (VEstr) - putstr(VEstr); /* termcap(5) says this is not padded */ + if (exit_ca_mode) + putstr(exit_ca_mode); + if (cursor_normal) + putstr(cursor_normal); (void) fflush(stdout); (void) tcsetattr(0, TCSADRAIN, &oldtt); isset = 0; @@ -362,7 +254,7 @@ void scr_clear(void) { - putpad(CLstr); + putpad(clear_screen); curscore = -1; memset((char *)curscreen, 0, sizeof(curscreen)); } @@ -393,8 +285,8 @@ scr_update(void) curscreen[D_LAST * B_COLS - 1] = -1; if (score != curscore) { - if (HOstr) - putpad(HOstr); + if (cursor_home) + putpad(cursor_home); else moveto(0, 0); (void) printf("Score: %d", score); @@ -409,7 +301,7 @@ scr_update(void) lastshape = nextshape; /* clean */ - putpad(SEstr); + putpad(exit_standout_mode); moveto(r-1, c-1); putstr(" "); moveto(r, c-1); putstr(" "); moveto(r+1, c-1); putstr(" "); @@ -419,7 +311,7 @@ scr_update(void) putstr("Next shape:"); /* draw */ - putpad(SOstr); + putpad(enter_standout_mode); moveto(r, 2*c); putstr(" "); for(i=0; i<3; i++) { @@ -432,7 +324,7 @@ scr_update(void) moveto(tr, 2*tc); putstr(" "); } - putpad(SEstr); + putpad(exit_standout_mode); } bp = &board[D_FIRST * B_COLS]; @@ -444,15 +336,17 @@ scr_update(void) continue; *sp = so; if (i != ccol) { - if (cur_so && MSflag) { - putpad(SEstr); + if (cur_so && move_standout_mode) { + putpad(exit_standout_mode); cur_so = 0; } moveto(RTOD(j), CTOD(i)); } - if (SOstr) { + if (enter_standout_mode) { if (so != cur_so) { - putpad(so ? SOstr : SEstr); + putpad(so ? + enter_standout_mode : + exit_standout_mode); cur_so = so; } putstr(" "); @@ -479,7 +373,7 @@ scr_update(void) } } if (cur_so) - putpad(SEstr); + putpad(exit_standout_mode); (void) fflush(stdout); (void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); } @@ -492,7 +386,7 @@ void scr_msg(char *s, int set) { - if (set || CEstr == NULL) { + if (set || clr_eol == NULL) { int l = strlen(s); moveto(Rows - 2, ((Cols - l) >> 1) - 1); @@ -503,6 +397,6 @@ scr_msg(char *s, int set) (void) putchar(' '); } else { moveto(Rows - 2, 0); - putpad(CEstr); + putpad(clr_eol); } } |