Ejemplo n.º 1
0
struct ww *
getwin(void)
{
	int c;
	struct ww *w = 0;

	if (!terse)
		wwputs("Which window? ", cmdwin);
	wwcurtowin(cmdwin);
	while ((c = wwgetc()) < 0)
		wwiomux();
	if (debug && c == 'c')
		w = cmdwin;
	else if (debug && c == 'f')
		w = framewin;
	else if (debug && c == 'b')
		w = boxwin;
	else if (c >= '1' && c < NWINDOW + '1')
		w = window[c - '1'];
	else if (c == '+')
		w = selwin;
	else if (c == '-')
		w = lastselwin;
	if (w == 0)
		wwbell();
	if (!terse)
		wwputc('\n', cmdwin);
	return w;
}
Ejemplo n.º 2
0
c_colon()
{
	char oldterse = terse;
	char buf[512];

	setterse(0);
	wwputc(':', cmdwin);
	wwgets(buf, wwncol - 3, cmdwin);
	wwputc('\n', cmdwin);
	wwcurtowin(cmdwin);
	setterse(oldterse);
	if (dolongcmd(buf, (struct value *)0, 0) < 0)
		error("Out of memory.");
}
Ejemplo n.º 3
0
int
waitnl1(struct ww *w, const char *prompt)
{
	int uc = ISSET(w->ww_wflags, WWW_UNCTRL);

	CLR(w->ww_wflags, WWW_UNCTRL);
	front(w, 0);
	wwprintf(w, "\033Y%c%c\033sA%s\033rA ",
		w->ww_w.nr - 1 + ' ', ' ', prompt);	/* print on last line */
	wwcurtowin(w);
	while (wwpeekc() < 0)
		wwiomux();
	SET(w->ww_wflags, uc);
	return wwgetc();
}
Ejemplo n.º 4
0
void
c_quit(void)
{
	char oldterse = terse;

	setterse(0);
	wwputs("Really quit [yn]? ", cmdwin);
	wwcurtowin(cmdwin);
	while (wwpeekc() < 0)
		wwiomux();
	if (wwgetc() == 'y') {
		wwputs("Yes", cmdwin);
		quit++;
	} else
		wwputc('\n', cmdwin);
	setterse(!quit && oldterse);
}
Ejemplo n.º 5
0
/*
 * Window size.
 */
void
c_size(struct ww *w)
{
	int col, row;

	if (!terse)
		wwputs("New window size (lower right corner): ", cmdwin);
	col = MIN(w->ww_w.r, wwncol) - 1;
	row = MIN(w->ww_w.b, wwnrow) - 1;
	wwadd(boxwin, framewin->ww_back);
	for (;;) {
		wwbox(boxwin, w->ww_w.t - 1, w->ww_w.l - 1,
			row - w->ww_w.t + 3, col - w->ww_w.l + 3);
		wwsetcursor(row, col);
		while (wwpeekc() < 0)
			wwiomux();
		switch (getpos(&row, &col, w->ww_w.t, w->ww_w.l,
			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);
	sizewin(w, row - w->ww_w.t + 1, col - w->ww_w.l + 1);
}
Ejemplo n.º 6
0
c_debug()
{
	register struct ww *w;

	if (!terse)
		wwputs("[m(smap) n(ns) o(os) s(string) v(nvis) w(win)]? ", cmdwin);
	wwcurtowin(cmdwin);
	while (wwpeekc() < 0)
		wwiomux();
	if (!terse)
		wwputc('\n', cmdwin);
	switch (wwgetc()) {
	case 'm':
		wwdumpsmap();
		break;
	case 'n':
		wwdumpns();
		break;
	case 'o':
		wwdumpos();
		break;
	case 's':
		debug_str();
		break;
	case 'v':
		if ((w = getwin()) != 0)
			wwdumpnvis(w);
		break;
	case 'w':
		if ((w = getwin()) != 0)
			wwdumpwin(w);
		break;
	default:
		wwbell();
	}
}
Ejemplo n.º 7
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;
			}
	}
}
Ejemplo n.º 8
0
void
docmd(void)
{
	int c;
	struct ww *w;
	char out = 0;

	while (!out && !quit) {
		if ((c = wwgetc()) < 0) {
			if (terse)
				wwsetcursor(0, 0);
			else {
				wwputs("Command: ", cmdwin);
				wwcurtowin(cmdwin);
			}
			do
				wwiomux();
			while ((c = wwgetc()) < 0);
		}
		if (!terse)
			wwputc('\n', cmdwin);
		switch (c) {
		default:
			if (c != escapec)
				break;
		case 'h': case 'j': case 'k': case 'l':
		case 'y': case 'p':
		case ctrl('y'):
		case ctrl('e'):
		case ctrl('u'):
		case ctrl('d'):
		case ctrl('b'):
		case ctrl('f'):
		case ctrl('s'):
		case ctrl('q'):
		case ctrl('['):
			if (selwin == 0) {
				error("No window.");
				continue;
			}
		}
		switch (c) {
		case '1': case '2': case '3': case '4': case '5':
		case '6': case '7': case '8': case '9':
			if ((w = window[c - '1']) == 0) {
				error("%c: No such window.", c);
				break;
			}
			setselwin(w);
			if (checkproc(selwin) >= 0)
				 out = 1;
			break;
		case '%':
			if ((w = getwin()) != 0)
				setselwin(w);
			break;
		case ctrl('^'):
			if (lastselwin != 0) {
				setselwin(lastselwin);
				if (checkproc(selwin) >= 0)
					out = 1;
			} else
				error("No previous window.");
			break;
		case 'c':
			if ((w = getwin()) != 0)
				closewin(w);
			break;
		case 'w':
			c_window();
			break;
		case 'm':
			if ((w = getwin()) != 0)
				c_move(w);
			break;
		case 'M':
			if ((w = getwin()) != 0)
				movewin(w, w->ww_alt.t, w->ww_alt.l);
			break;
		case 's':
			if ((w = getwin()) != 0)
				c_size(w);
			break;
		case 'S':
			if ((w = getwin()) != 0)
				sizewin(w, w->ww_alt.nr, w->ww_alt.nc);
			break;
		case 'y':
			c_yank();
			break;
		case 'p':
			c_put();
			break;
		case ':':
			c_colon();
			break;
		case 'h':
			(void) wwwrite(selwin, "\b", 1);
			break;
		case 'j':
			(void) wwwrite(selwin, "\n", 1);
			break;
		case 'k':
			(void) wwwrite(selwin, "\033A", 2);
			break;
		case 'l':
			(void) wwwrite(selwin, "\033C", 2);
			break;
		case ctrl('e'):
			wwscroll(selwin, 1);
			break;
		case ctrl('y'):
			wwscroll(selwin, -1);
			break;
		case ctrl('d'):
			wwscroll(selwin, selwin->ww_w.nr / 2);
			break;
		case ctrl('u'):
			wwscroll(selwin, - selwin->ww_w.nr / 2);
			break;
		case ctrl('f'):
			wwscroll(selwin, selwin->ww_w.nr);
			break;
		case ctrl('b'):
			wwscroll(selwin, - selwin->ww_w.nr);
			break;
		case ctrl('s'):
			stopwin(selwin);
			break;
		case ctrl('q'):
			startwin(selwin);
			break;
		case ctrl('l'):
			wwredraw();
			break;
		case '?':
			c_help();
			break;
		case ctrl('['):
			if (checkproc(selwin) >= 0)
				out = 1;
			break;
		case ctrl('z'):
			wwsuspend();
			break;
		case 'q':
			c_quit();
			break;
		/* debugging stuff */
		case '&':
			if (debug) {
				c_debug();
				break;
			}
		default:
			if (c == escapec) {
				if (checkproc(selwin) >= 0) {
					(void) write(selwin->ww_pty,
						&escapec, 1);
					out = 1;
				}
			} else {
				if (!terse)
					wwbell();
				error("Type ? for help.");
			}
		}
	}
	if (!quit)
		setcmd(0);
}
Ejemplo n.º 9
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);
}
Ejemplo n.º 10
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;
}