示例#1
0
c_window()
{
    int col, row, xcol, xrow;
    int id;

    if ((id = findid()) < 0)
        return;
    if (!terse)
        wwputs("New window (upper left corner): ", cmdwin);
    col = 0;
    row = 1;
    wwadd(boxwin, framewin->ww_back);
    for (;;) {
        wwbox(boxwin, row - 1, col - 1, 3, 3);
        wwsetcursor(row, col);
        while (wwpeekc() < 0)
            wwiomux();
        switch (getpos(&row, &col, row > 1, 0,
                       wwnrow - 1, wwncol - 1)) {
        case 3:
            wwunbox(boxwin);
            wwdelete(boxwin);
            return;
        case 2:
            wwunbox(boxwin);
            break;
        case 1:
            wwunbox(boxwin);
        case 0:
            continue;
        }
        break;
    }
    if (!terse)
        wwputs("\nNew window (lower right corner): ", cmdwin);
    xcol = col;
    xrow = row;
    for (;;) {
        wwbox(boxwin, row - 1, col - 1,
              xrow - row + 3, xcol - col + 3);
        wwsetcursor(xrow, xcol);
        wwflush();
        while (wwpeekc() < 0)
            wwiomux();
        switch (getpos(&xrow, &xcol, row, col, wwnrow - 1, wwncol - 1))
        {
        case 3:
            wwunbox(boxwin);
            wwdelete(boxwin);
            return;
        case 2:
            wwunbox(boxwin);
            break;
        case 1:
            wwunbox(boxwin);
        case 0:
            continue;
        }
        break;
    }
    wwdelete(boxwin);
    if (!terse)
        wwputc('\n', cmdwin);
    wwcurtowin(cmdwin);
    (void) openwin(id, row, col, xrow-row+1, xcol-col+1, nbufline,
                   (char *) 0, 1, 1, shellfile, shell);
}
示例#2
0
/*
 * Multiple window output handler.
 * The idea is to copy window outputs to the terminal, via the
 * display package.  We try to give wwcurwin highest priority.
 * The only return conditions are when there is keyboard input
 * and when a child process dies.
 * When there's nothing to do, we sleep in a select().
 * The history of this routine is interesting.
 */
void
wwiomux(void)
{
	struct ww *w;
	nfds_t nfd;
	int i;
	int volatile dostdin;	/* avoid longjmp clobbering */
	char volatile c;	/* avoid longjmp clobbering */
	char *p;
	int millis;
	char noblock = 0;
	static struct pollfd *pfd = NULL;
	static nfds_t maxfds = 0;

	c = 0; 	/* XXXGCC -Wuninitialized */

	for (;;) {
		if (wwinterrupt()) {
			wwclrintr();
			return;
		}

		nfd = 0;
		for (w = wwhead.ww_forw; w != &wwhead; w = w->ww_forw) {
			if (w->ww_pty < 0 || w->ww_obq >= w->ww_obe)
				continue;
			nfd++;
		}

		if (maxfds <= ++nfd) {	/* One more for the fd=0 case below */
			struct pollfd *npfd = pfd == NULL ?
			    malloc(sizeof(*pfd) * nfd) :
			   realloc(pfd, sizeof(*pfd) * nfd);
			if (npfd == NULL) {
				warn("will retry");
				if (pfd)
					free(pfd);
				pfd = NULL;
				maxfds = 0;
				return;
			}
			pfd = npfd;
			maxfds = nfd;
		}

		nfd = 0;
		for (w = wwhead.ww_forw; w != &wwhead; w = w->ww_forw) {
			if (w->ww_pty < 0)
				continue;
			if (w->ww_obq < w->ww_obe) {
				pfd[nfd].fd = w->ww_pty;
				pfd[nfd++].events = POLLIN;
			}
			if (w->ww_obq > w->ww_obp &&
			    !ISSET(w->ww_pflags, WWP_STOPPED))
				noblock = 1;
		}
		if (wwibq < wwibe) {
			dostdin = nfd;
			pfd[nfd].fd = 0;
			pfd[nfd++].events = POLLIN;
		} else {
			dostdin = -1;
		}

		if (!noblock) {
			if (wwcurwin != 0)
				wwcurtowin(wwcurwin);
			wwupdate();
			wwflush();
			(void) setjmp(wwjmpbuf);
			wwsetjmp = 1;
			if (wwinterrupt()) {
				wwsetjmp = 0;
				wwclrintr();
				return;
			}
			/* XXXX */
			millis = 30000;
		} else {
			millis = 10;
		}
		wwnselect++;
		i = poll(pfd, nfd, millis);
		wwsetjmp = 0;
		noblock = 0;

		if (i < 0)
			wwnselecte++;
		else if (i == 0)
			wwnselectz++;
		else {
			if (dostdin != -1 && (pfd[dostdin].revents & POLLIN) != 0)
				wwrint();

			nfd = 0;
			for (w = wwhead.ww_forw; w != &wwhead; w = w->ww_forw) {
				int n;

				if (w->ww_pty < 0)
					continue;
				if (w->ww_pty != pfd[nfd].fd)
					continue;
				if ((pfd[nfd++].revents & POLLIN) == 0)
					continue;
				wwnwread++;
				p = w->ww_obq;
				if (w->ww_type == WWT_PTY) {
					if (p == w->ww_ob) {
						w->ww_obp++;
						w->ww_obq++;
					} else
						p--;
					c = *p;
				}
				n = read(w->ww_pty, p, w->ww_obe - p);
				if (n < 0) {
					wwnwreade++;
					(void) close(w->ww_pty);
					w->ww_pty = -1;
				} else if (n == 0) {
					wwnwreadz++;
					(void) close(w->ww_pty);
					w->ww_pty = -1;
				} else if (w->ww_type != WWT_PTY) {
					wwnwreadd++;
					wwnwreadc += n;
					w->ww_obq += n;
				} else if (*p == TIOCPKT_DATA) {
					n--;
					wwnwreadd++;
					wwnwreadc += n;
					w->ww_obq += n;
				} else {
					wwnwreadp++;
					if (*p & TIOCPKT_STOP)
						SET(w->ww_pflags, WWP_STOPPED);
					if (*p & TIOCPKT_START)
						CLR(w->ww_pflags, WWP_STOPPED);
					if (*p & TIOCPKT_FLUSHWRITE) {
						CLR(w->ww_pflags, WWP_STOPPED);
						w->ww_obq = w->ww_obp =
							w->ww_ob;
					}
				}
				if (w->ww_type == WWT_PTY)
					*p = c;
			}
		}
		/*
		 * Try the current window first, if there is output
		 * then process it and go back to the top to try again.
		 * This can lead to starvation of the other windows,
		 * but presumably that what we want.
		 * Update will eventually happen when output from wwcurwin
		 * dies down.
		 */
		if ((w = wwcurwin) != NULL && w->ww_pty >= 0 &&
		    w->ww_obq > w->ww_obp &&
		    !ISSET(w->ww_pflags, WWP_STOPPED)) {
			int n = wwwrite(w, w->ww_obp, w->ww_obq - w->ww_obp);
			if ((w->ww_obp += n) == w->ww_obq)
				w->ww_obq = w->ww_obp = w->ww_ob;
			noblock = 1;
			continue;
		}
		for (w = wwhead.ww_forw; w != &wwhead; w = w->ww_forw)
			if (w->ww_pty >= 0 && w->ww_obq > w->ww_obp &&
			    !ISSET(w->ww_pflags, WWP_STOPPED)) {
				int n = wwwrite(w, w->ww_obp,
					w->ww_obq - w->ww_obp);
				if ((w->ww_obp += n) == w->ww_obq)
					w->ww_obq = w->ww_obp = w->ww_ob;
				if (wwinterrupt())
					break;
			}
	}
}
示例#3
0
/*
 * Multiple window output handler.
 * The idea is to copy window outputs to the terminal, via the
 * display package.  We try to give the top most window highest
 * priority.  The only return condition is when there is keyboard
 * input, which is serviced asynchronously by wwrint().
 * When there's nothing to do, we sleep in a select().
 * This can be done better with interrupt driven io.  But that's
 * not supported on ptys, yet.
 * The history of this routine is interesting.
 */
wwiomux()
{
	register struct ww *w;
	fd_set imask;
	register n;
	register char *p;
	char c;
	static struct timeval tv = { 0, 0 };
	char noblock;

loop:
	if (wwinterrupt())
		return;

	FD_ZERO(&imask);
	noblock = 0;
	for (w = wwhead.ww_forw; w != &wwhead; w = w->ww_forw) {
		if (w->ww_pty < 0)
			continue;
		if (w->ww_obq < w->ww_obe)
			FD_SET(w->ww_pty, &imask);
		if (w->ww_obq > w->ww_obp && !w->ww_stopped)
			noblock = 1;
	}

	if (!noblock) {
		if (wwcurwin != 0)
			wwcurtowin(wwcurwin);
		wwupdate();
		wwflush();
		if (setjmp(wwjmpbuf))
			return;
		wwsetjmp = 1;
		if (wwinterrupt()) {
			wwsetjmp = 0;
			return;
		}
	}
	wwnselect++;
	n = select(wwdtablesize, &imask, (fd_set *)0, (fd_set *)0,
		noblock ? &tv : (struct timeval *)0);
	wwsetjmp = 0;

	if (n < 0)
		wwnselecte++;
	else if (n == 0)
		wwnselectz++;
	else
		for (w = wwhead.ww_forw; w != &wwhead; w = w->ww_forw) {
			if (w->ww_pty < 0 || !FD_ISSET(w->ww_pty, &imask))
				continue;
			wwnwread++;
			p = w->ww_obq;
			if (w->ww_ispty) {
				if (p == w->ww_ob) {
					w->ww_obp++;
					w->ww_obq++;
				} else
					p--;
				c = *p;
			}
			n = read(w->ww_pty, p, w->ww_obe - p);
			if (n < 0) {
				wwnwreade++;
				(void) close(w->ww_pty);
				w->ww_pty = -1;
			} else if (n == 0) {
				wwnwreadz++;
				(void) close(w->ww_pty);
				w->ww_pty = -1;
			} else if (!w->ww_ispty) {
				wwnwreadd++;
				wwnwreadc += n;
				w->ww_obq += n;
			} else if (*p == TIOCPKT_DATA) {
				n--;
				wwnwreadd++;
				wwnwreadc += n;
				w->ww_obq += n;
			} else {
				wwnwreadp++;
				if (*p & TIOCPKT_STOP)
					w->ww_stopped = 1;
				if (*p & TIOCPKT_START)
					w->ww_stopped = 0;
				if (*p & TIOCPKT_FLUSHWRITE) {
					w->ww_stopped = 0;
					w->ww_obq = w->ww_obp = w->ww_ob;
				}
			}
			if (w->ww_ispty)
				*p = c;
		}
	for (w = wwhead.ww_forw; w != &wwhead; w = w->ww_forw)
		if (w->ww_pty >= 0 && w->ww_obq > w->ww_obp && !w->ww_stopped) {
			n = wwwrite(w, w->ww_obp, w->ww_obq - w->ww_obp);
			if ((w->ww_obp += n) == w->ww_obq)
				w->ww_obq = w->ww_obp = w->ww_ob;
			if (wwinterrupt())
				return;
			break;
		}
	goto loop;
}