Subversion Repositories HelenOS-historic

Compare Revisions

Ignore whitespace Rev 1518 → Rev 1519

/uspace/trunk/tetris/screen.c
39,17 → 39,12
* Tetris screen control.
*/
 
#include <sys/ioctl.h>
 
#include <err.h>
//#include <setjmp.h>
//#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <term.h>
#include <termios.h>
#include <unistd.h>
#include <io/stream.h>
 
#include "screen.h"
#include "tetris.h"
134,6 → 129,8
#define putstr(s) (void)fputs(s, stdout)
#define moveto(r, c) putpad(tgoto(CMstr, c, r))
 
static int con_phone;
 
/*
* Set up from termcap.
*/
140,95 → 137,15
void
scr_init(void)
{
static int bsflag, xsflag, sgnum;
#ifdef unneeded
static int ncflag;
#endif
char *term, *fill;
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}
};
if ((term = getenv("TERM")) == NULL)
stop("you must set the TERM environment variable");
if (tgetent(tbuf, term) <= 0)
stop("cannot find your termcap");
fill = combuf;
{
struct tcsinfo *p;
 
for (p = tcstrings; p->tcaddr; p++)
*p->tcaddr = tgetstr(p->tcname, &fill);
}
if (classic)
SOstr = SEstr = NULL;
{
struct tcninfo *p;
 
for (p = tcflags; p->tcaddr; p++)
*p->tcaddr = tgetflag(p->tcname);
for (p = tcnums; p->tcaddr; p++)
*p->tcaddr = tgetnum(p->tcname);
}
if (bsflag)
BC = "\b";
else if (BC == NULL && bcstr != NULL)
BC = bcstr;
if (CLstr == 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
con_phone = get_fd_phone(1);
}
 
/* this foolery is needed to modify tty state `atomically' */
//static jmp_buf scr_onstop;
 
/* static void */
/* stopset(int sig) */
/* { */
/* sigset_t sigset; */
 
/* (void) signal(sig, SIG_DFL); */
/* (void) kill(getpid(), sig); */
/* sigemptyset(&sigset); */
/* sigaddset(&sigset, sig); */
/* (void) sigprocmask(SIG_UNBLOCK, &sigset, (sigset_t *)0); */
/* longjmp(scr_onstop, 1); */
/* } */
 
static void
scr_stop(int sig)
{
// sigset_t sigset;
 
scr_end();
/* (void) kill(getpid(), sig); */
/* sigemptyset(&sigset); */
/* sigaddset(&sigset, sig); */
/* (void) sigprocmask(SIG_UNBLOCK, &sigset, (sigset_t *)0); */
scr_set();
scr_msg(key_msg, 1);
}
241,24 → 158,8
{
struct winsize ws;
struct termios newtt;
// sigset_t sigset, osigset;
void (*ttou)(int);
 
/* sigemptyset(&sigset); */
/* sigaddset(&sigset, SIGTSTP); */
/* sigaddset(&sigset, SIGTTOU); */
/* (void) sigprocmask(SIG_BLOCK, &sigset, &osigset); */
/* if ((tstp = signal(SIGTSTP, stopset)) == SIG_IGN) */
/* (void) signal(SIGTSTP, SIG_IGN); */
/* if ((ttou = signal(SIGTTOU, stopset)) == SIG_IGN) */
/* (void) signal(SIGTTOU, SIG_IGN); */
/* /\* */
/* * At last, we are ready to modify the tty state. If */
/* * we stop while at it, stopset() above will longjmp back */
/* * to the setjmp here and we will start over. */
/* *\/ */
/* (void) setjmp(scr_onstop); */
/* (void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); */
Rows = 0, Cols = 0;
if (ioctl(0, TIOCGWINSZ, &ws) == 0) {
Rows = ws.ws_row;
283,7 → 184,6
newtt.c_oflag &= ~OXTABS;
if (tcsetattr(0, TCSADRAIN, &newtt) < 0)
stop("tcsetattr() fails");
/* (void) sigprocmask(SIG_BLOCK, &sigset, &osigset); */
 
/*
* We made it. We are now in screen mode, modulo TIstr
291,13 → 191,9
*/
if (TIstr)
putstr(TIstr); /* termcap(5) says this is not padded */
/* if (tstp != SIG_IGN) */
/* (void) signal(SIGTSTP, scr_stop); */
/* if (ttou != SIG_IGN) */
/* (void) signal(SIGTTOU, ttou); */
 
isset = 1;
// (void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0);
 
scr_clear();
}
 
307,26 → 203,6
void
scr_end(void)
{
// sigset_t sigset, osigset;
 
/* sigemptyset(&sigset); */
/* sigaddset(&sigset, SIGTSTP); */
/* sigaddset(&sigset, SIGTTOU); */
/* (void) sigprocmask(SIG_BLOCK, &sigset, &osigset); */
/* move cursor to last line */
if (LLstr)
putstr(LLstr); /* termcap(5) says this is not padded */
else
moveto(Rows - 1, 0);
/* exit screen mode */
if (TEstr)
putstr(TEstr); /* termcap(5) says this is not padded */
// (void) fflush(stdout);
(void) tcsetattr(0, TCSADRAIN, &oldtt);
isset = 0;
/* restore signals */
/* (void) signal(SIGTSTP, tstp); */
/* (void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); */
}
 
void
365,13 → 241,8
cell *bp, *sp;
regcell so, cur_so = 0;
int i, ccol, j;
// sigset_t sigset, osigset;
static const struct shape *lastshape;
 
/* sigemptyset(&sigset); */
/* sigaddset(&sigset, SIGTSTP); */
/* (void) sigprocmask(SIG_BLOCK, &sigset, &osigset); */
 
/* always leave cursor after last displayed point */
curscreen[D_LAST * B_COLS - 1] = -1;