Subversion Repositories HelenOS-historic

Compare Revisions

Ignore whitespace Rev 1518 → Rev 1519

/uspace/trunk/libc/include/io/stream.h
37,3 → 37,4
typedef ssize_t (*preadfn_t)(void *, void *, size_t);
 
fd_t open(const char *fname, int flags);
int get_fd_phone(int fd);
/uspace/trunk/libc/generic/io/stream.c
39,6 → 39,7
#include <ipc/services.h>
#include <console.h>
#include <unistd.h>
#include <async.h>
 
#define FDS 32
 
46,12 → 47,12
pwritefn_t w;
preadfn_t r;
void * param;
int phone;
} stream_t;
 
int console_phone = -1;
static int console_phone = -1;
static stream_t streams[FDS] = {{0, 0, 0, -1}};
 
stream_t streams[FDS] = {{0, 0, 0}};
 
static ssize_t write_stderr(void *param, const void *buf, size_t count)
{
return count;
63,7 → 64,7
size_t i = 0;
 
while (i < count) {
if (ipc_call_sync_2(console_phone, CONSOLE_GETCHAR, 0, 0, &r0, &r1) < 0) {
if (sync_send_2(streams[0].phone, CONSOLE_GETCHAR, 0, 0, &r0, &r1) < 0) {
return -1;
}
((char *)buf)[i++] = r0;
77,7 → 78,7
ipcarg_t r0,r1;
 
for (i = 0; i < count; i++)
send_call(console_phone, CONSOLE_PUTCHAR, ((const char *)buf)[i]);
send_call(streams[1].phone, CONSOLE_PUTCHAR, ((const char *)buf)[i]);
return count;
}
98,6 → 99,8
stream.r = read_stdin;
stream.param = 0;
stream.phone = console_phone;
return stream;
}
 
105,7 → 108,7
{
stream_t stream;
int res;
 
if (console_phone < 0) {
while ((console_phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0)) < 0) {
usleep(10000);
138,8 → 141,6
}
if (!strcmp(fname, "stdout")) {
//streams[c].w = write_stdout;
//return c;
streams[c] = open_stdout();
return c;
}
171,3 → 172,9
return 0;
}
 
int get_fd_phone(int fd)
{
if (fd >= FDS || fd < 0)
return -1;
return streams[fd].phone;
}
/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;