switch to POSIX tty, old code still supported under OLD_TTY
[unix-history] / usr / src / usr.bin / window / main.c
index 12f6274..152da77 100644 (file)
@@ -1,11 +1,23 @@
+/*
+ * 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.
+ *
+ * %sccs.include.redist.c%
+ */
+
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)main.c      3.10 83/09/02";
-#endif
+static char sccsid[] = "@(#)main.c     3.42 (Berkeley) %G%";
+#endif /* not lint */
 
 #include "defs.h"
 
 #include "defs.h"
-
-char escapec = CTRL(p);
-int nbufline = 48;                     /* compatible */
+#include <paths.h>
+#include <stdio.h>
+#include "string.h"
+#include "char.h"
+#include "local.h"
 
 #define next(a) (*++*(a) ? *(a) : (*++(a) ? *(a) : (char *)usage()))
 
 
 #define next(a) (*++*(a) ? *(a) : (*++(a) ? *(a) : (char *)usage()))
 
@@ -13,13 +25,14 @@ int nbufline = 48;                  /* compatible */
 main(argc, argv)
 char **argv;
 {
 main(argc, argv)
 char **argv;
 {
-       register n;
        register char *p;
        char fflag = 0;
        char dflag = 0;
        char xflag = 0;
        register char *p;
        char fflag = 0;
        char dflag = 0;
        char xflag = 0;
-       struct timezone timezone;
+       char *cmd = 0;
+       char tflag = 0;
 
 
+       escapec = ESCAPEC;      
        if (p = rindex(*argv, '/'))
                p++;
        else
        if (p = rindex(*argv, '/'))
                p++;
        else
@@ -31,17 +44,25 @@ char **argv;
                        case 'f':
                                fflag++;
                                break;
                        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':
                        case 'e':
                                setescape(next(argv));
                                break;
                        case 't':
-                               terse++;
+                               tflag++;
                                break;
                        case 'd':
                                dflag++;
                                break;
                        case 'D':
                                break;
                        case 'd':
                                dflag++;
                                break;
                        case 'D':
-                               debug++;
+                               debug = !debug;
                                break;
                        case 'x':
                                xflag++;
                                break;
                        case 'x':
                                xflag++;
@@ -52,69 +73,90 @@ char **argv;
                } else
                        (void) usage();
        }
                } 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
        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) {
        if (wwinit() < 0) {
-               (void) fflush(stdout);
                (void) fprintf(stderr, "%s.\n", wwerror());
                exit(1);
        }
                (void) fprintf(stderr, "%s.\n", wwerror());
                exit(1);
        }
+
+#ifdef OLD_TTY
        if (debug)
                wwnewtty.ww_tchars.t_quitc = wwoldtty.ww_tchars.t_quitc;
        if (xflag) {
                wwnewtty.ww_tchars.t_stopc = wwoldtty.ww_tchars.t_stopc;
                wwnewtty.ww_tchars.t_startc = wwoldtty.ww_tchars.t_startc;
        }
        if (debug)
                wwnewtty.ww_tchars.t_quitc = wwoldtty.ww_tchars.t_quitc;
        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 (debug || xflag)
                (void) wwsettty(0, &wwnewtty);
 
-       if ((cmdwin = wwopen(WWO_REVERSE, 1, wwncol, 0, 0, 0)) == 0) {
-               (void) wwflush();
+       if ((cmdwin = wwopen(wwbaud > 2400 ? WWO_REVERSE : 0, 1, wwncol,
+                            0, 0, 0)) == 0) {
+               wwflush();
                (void) fprintf(stderr, "%s.\r\n", wwerror());
                goto bad;
        }
                (void) fprintf(stderr, "%s.\r\n", wwerror());
                goto bad;
        }
+       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) {
        if ((framewin = wwopen(WWO_GLASS|WWO_FRAME, wwnrow, wwncol, 0, 0, 0))
            == 0) {
-               (void) wwflush();
+               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) fprintf(stderr, "%s.\r\n", wwerror());
                goto bad;
        }
        wwadd(framewin, &wwhead);
        if ((boxwin = wwopen(WWO_GLASS, wwnrow, wwncol, 0, 0, 0)) == 0) {
-               (void) wwflush();
+               wwflush();
                (void) fprintf(stderr, "%s.\r\n", wwerror());
                goto bad;
        }
                (void) fprintf(stderr, "%s.\r\n", wwerror());
                goto bad;
        }
+       fgwin = framewin;
 
        wwupdate();
        wwflush();
 
        wwupdate();
        wwflush();
-       (void) signal(SIGCHLD, wwchild);
-       if (fflag)
-               incmd = 1;
-       else {
-               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 (dflag || doconfig() < 0)
                        dodefault();
-               if (selwin != 0) {
-                       incmd = 0;
-                       wwcursor(selwin, 0);
-               }
-               if (!terse) {
-                       wwdelete(cmdwin);
-                       reframe();
-               }
-       }
+       if (selwin != 0)
+               setcmd(0);
 
        mloop();
 
 
        mloop();
 
-       wwupdate();
-       wwflush();
 bad:
        wwend();
        return 0;
 bad:
        wwend();
        return 0;
@@ -122,7 +164,7 @@ bad:
 
 usage()
 {
 
 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 */
 }
        exit(1);
        return 0;                       /* for lint */
 }