Subversion Repositories HelenOS-historic

Compare Revisions

Ignore whitespace Rev 1471 → Rev 1472

/uspace/trunk/tetris/screen.c
42,8 → 42,8
#include <sys/ioctl.h>
 
#include <err.h>
#include <setjmp.h>
#include <signal.h>
//#include <setjmp.h>
//#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
204,31 → 204,31
}
 
/* this foolery is needed to modify tty state `atomically' */
static jmp_buf scr_onstop;
//static jmp_buf scr_onstop;
 
static void
stopset(int sig)
{
sigset_t sigset;
/* 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);
}
/* (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;
// sigset_t sigset;
 
scr_end();
(void) kill(getpid(), sig);
sigemptyset(&sigset);
sigaddset(&sigset, sig);
(void) sigprocmask(SIG_UNBLOCK, &sigset, (sigset_t *)0);
/* (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 → 241,24
{
struct winsize ws;
struct termios newtt;
sigset_t sigset, osigset;
// 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);
/* 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 → 283,7
newtt.c_oflag &= ~OXTABS;
if (tcsetattr(0, TCSADRAIN, &newtt) < 0)
stop("tcsetattr() fails");
(void) sigprocmask(SIG_BLOCK, &sigset, &osigset);
/* (void) sigprocmask(SIG_BLOCK, &sigset, &osigset); */
 
/*
* We made it. We are now in screen mode, modulo TIstr
291,13 → 291,13
*/
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);
/* 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);
// (void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0);
scr_clear();
}
 
307,12 → 307,12
void
scr_end(void)
{
sigset_t sigset, osigset;
// sigset_t sigset, osigset;
 
sigemptyset(&sigset);
sigaddset(&sigset, SIGTSTP);
sigaddset(&sigset, SIGTTOU);
(void) sigprocmask(SIG_BLOCK, &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 */
321,12 → 321,12
/* exit screen mode */
if (TEstr)
putstr(TEstr); /* termcap(5) says this is not padded */
(void) fflush(stdout);
// (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) signal(SIGTSTP, tstp); */
/* (void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); */
}
 
void
365,12 → 365,12
cell *bp, *sp;
regcell so, cur_so = 0;
int i, ccol, j;
sigset_t sigset, osigset;
// sigset_t sigset, osigset;
static const struct shape *lastshape;
 
sigemptyset(&sigset);
sigaddset(&sigset, SIGTSTP);
(void) sigprocmask(SIG_BLOCK, &sigset, &osigset);
/* 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;
465,8 → 465,8
}
if (cur_so)
putpad(SEstr);
(void) fflush(stdout);
(void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0);
/* (void) fflush(stdout); */
/* (void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); */
}
 
/*
/uspace/trunk/tetris/tetris.c
45,7 → 45,7
* Tetris (or however it is spelled).
*/
 
#include <sys/param.h>
//#include <sys/param.h>
#include <sys/time.h>
#include <sys/types.h>
 
151,8 → 151,15
tmp = &shapes[classic? tmp->rotc : tmp->rot];
return (tmp);
}
 
static void srandomdev(void)
{
struct timeval tv;
 
gettimeofday(&tv, NULL);
srandom(tv.tv_sec + tv.tv_usec / 100000);
}
 
int
main(int argc, char *argv[])
{
216,7 → 223,7
errx(1, "duplicate command keys specified.");
}
if (keys[i] == ' ')
strlcpy(key_write[i], "<space>", sizeof key_write[i]);
strncpy(key_write[i], "<space>", sizeof key_write[i]);
else {
key_write[i][0] = keys[i];
key_write[i][1] = '\0';
291,7 → 298,7
scr_update();
scr_msg(key_msg, 0);
scr_msg(msg, 1);
(void) fflush(stdout);
// (void) fflush(stdout);
} while (rwait((struct timeval *)NULL) == -1);
scr_msg(msg, 0);
scr_msg(key_msg, 1);