X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/43c1dd564f44c84d3fe58d33c349f843f42140e6..af359dea2e5ab3e937b62107ecd6a51d78189ed7:/usr/src/usr.bin/window/main.c diff --git a/usr/src/usr.bin/window/main.c b/usr/src/usr.bin/window/main.c index cc0fc58d1e..2dc0714903 100644 --- a/usr/src/usr.bin/window/main.c +++ b/usr/src/usr.bin/window/main.c @@ -1,10 +1,49 @@ +/* + * Copyright (c) 1983 Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + #ifndef lint -static char *sccsid = "@(#)main.c 3.3 83/08/18"; -#endif +static char sccsid[] = "@(#)main.c 3.42 (Berkeley) 8/12/90"; +#endif /* not lint */ #include "defs.h" - -char escapec = CTRL(p); +#include +#include +#include "string.h" +#include "char.h" +#include "local.h" #define next(a) (*++*(a) ? *(a) : (*++(a) ? *(a) : (char *)usage())) @@ -12,13 +51,14 @@ char escapec = CTRL(p); main(argc, argv) char **argv; { - register n; register char *p; char fflag = 0; char dflag = 0; - int imask; - struct timezone timezone; + char xflag = 0; + char *cmd = 0; + char tflag = 0; + escapec = ESCAPEC; if (p = rindex(*argv, '/')) p++; else @@ -30,17 +70,28 @@ char **argv; case 'f': fflag++; break; + case 'c': + if (cmd != 0) { + (void) fprintf(stderr, + "Only one -c allowed.\n"); + (void) usage(); + } + cmd = next(argv); + break; case 'e': setescape(next(argv)); break; case 't': - terse++; + tflag++; break; case 'd': dflag++; break; case 'D': - debug++; + debug = !debug; + break; + case 'x': + xflag++; break; default: (void) usage(); @@ -48,114 +99,90 @@ char **argv; } else (void) usage(); } - if ((shell = getenv("SHELL")) == 0) - shell = "/bin/csh"; - if (shellname = rindex(shell, '/')) - shellname++; + if ((p = getenv("SHELL")) == 0) + p = _PATH_BSHELL; + if ((default_shellfile = str_cpy(p)) == 0) { + (void) fprintf(stderr, "Out of memory.\n"); + exit(1); + } + if (p = rindex(default_shellfile, '/')) + p++; else - shellname = shell; - (void) gettimeofday(&starttime, &timezone); + p = default_shellfile; + default_shell[0] = p; + default_shell[1] = 0; + default_nline = NLINE; + default_smooth = 1; + (void) gettimeofday(&starttime, (struct timezone *)0); if (wwinit() < 0) { - (void) fflush(stdout); - (void) fprintf(stderr, "Can't do windows on this terminal.\n"); + (void) fprintf(stderr, "%s.\n", wwerror()); exit(1); } - if (debug) { + +#ifdef OLD_TTY + if (debug) wwnewtty.ww_tchars.t_quitc = wwoldtty.ww_tchars.t_quitc; - (void) wwsettty(0, &wwnewtty); + if (xflag) { + wwnewtty.ww_tchars.t_stopc = wwoldtty.ww_tchars.t_stopc; + wwnewtty.ww_tchars.t_startc = wwoldtty.ww_tchars.t_startc; + } +#else + if (debug) { + wwnewtty.ww_termios.c_cc[VQUIT] = + wwoldtty.ww_termios.c_cc[VQUIT]; + wwnewtty.ww_termios.c_lflag |= ISIG; } + if (xflag) { + wwnewtty.ww_termios.c_cc[VSTOP] = + wwoldtty.ww_termios.c_cc[VSTOP]; + wwnewtty.ww_termios.c_cc[VSTART] = + wwoldtty.ww_termios.c_cc[VSTART]; + wwnewtty.ww_termios.c_iflag |= IXON; + } +#endif + if (debug || xflag) + (void) wwsettty(0, &wwnewtty); - if ((cmdwin = wwopen(WWO_REVERSE, 1, wwncol, 0, 0, 0)) == 0) { - (void) wwflush(); - (void) fprintf(stderr, "Can't open command window.\r\n"); + if ((cmdwin = wwopen(wwbaud > 2400 ? WWO_REVERSE : 0, 1, wwncol, + 0, 0, 0)) == 0) { + wwflush(); + (void) fprintf(stderr, "%s.\r\n", wwerror()); goto bad; } - if ((framewin = wwopen(WWO_GLASS, wwnrow, wwncol, 0, 0, 0)) == 0) { - (void) wwflush(); - (void) fprintf(stderr, "Can't open frame window.\r\n"); + cmdwin->ww_mapnl = 1; + cmdwin->ww_nointr = 1; + cmdwin->ww_noupdate = 1; + cmdwin->ww_unctrl = 1; + if ((framewin = wwopen(WWO_GLASS|WWO_FRAME, wwnrow, wwncol, 0, 0, 0)) + == 0) { + wwflush(); + (void) fprintf(stderr, "%s.\r\n", wwerror()); goto bad; } wwadd(framewin, &wwhead); if ((boxwin = wwopen(WWO_GLASS, wwnrow, wwncol, 0, 0, 0)) == 0) { - (void) wwflush(); - (void) fprintf(stderr, "Can't open box window.\r\n"); + wwflush(); + (void) fprintf(stderr, "%s.\r\n", wwerror()); goto bad; } + fgwin = framewin; - curwin = cmdwin; wwupdate(); wwflush(); - (void) signal(SIGCHLD, wwchild); - if (!fflag) { - if (!terse) - wwadd(cmdwin, &wwhead); + setvars(); + + setterse(tflag); + setcmd(1); + if (cmd != 0) + (void) dolongcmd(cmd, (struct value *)0, 0); + if (!fflag) if (dflag || doconfig() < 0) dodefault(); - if (selwin != 0) { - curwin = selwin; - /* - Woncursor(selwin->ww_win, 0); - */ - } - if (!terse) { - wwdelete(cmdwin); - reframe(); - } - } - while (!quit) { - if (curwin == cmdwin) { - docmd(); - continue; - } - /* - * Loop until we get some keyboard input. - */ - while (ibufc == 0) { - wwcurtowin(curwin); - wwupdate(); - wwflush(); - imask = 1 << 0; - while (wwforce(&imask) < 0) - ; - if ((imask & 1 << 0) == 0) - continue; - /* NOTE: ibufc == 0 */ - ibufp = ibuf; - if ((ibufc = read(0, ibuf, sizeof ibuf)) < 0) { - ibufc = 0; - nreade++; - } else if (ibufc == 0) - nreadz++; - else - nreadc += ibufc; - nread++; - } - /* - * Weird loop. Copy the buffer to the pty - * and stopping on the escape character - * in a hopefully efficient way. - * Probably a good thing to make ibufc == 1 a special - * case. - */ - for (p = ibufp, n = ibufc;;) { - if (--n < 0) { - (void) write(curwin->ww_pty, ibufp, ibufc); - ibufp = ibuf; - ibufc = 0; - break; - } else if (*p++ == escapec) { - if ((n = p - ibufp) > 1) - (void) write(curwin->ww_pty, - ibufp, n - 1); - ibufp = p; - ibufc -= n; - curwin = cmdwin; - break; - } - } - } - wwupdate(); - wwflush(); + if (selwin != 0) + setcmd(0); + + mloop(); + bad: wwend(); return 0; @@ -163,7 +190,7 @@ bad: usage() { - (void) fprintf(stderr, "window: [-e escape-char] [-t] [-f] [-d]\n"); + (void) fprintf(stderr, "Usage: window [-e escape-char] [-c command] [-t] [-f] [-d]\n"); exit(1); return 0; /* for lint */ }