new options to "window": shell, pty, frame
authorEdward Wang <edward@ucbvax.Berkeley.EDU>
Mon, 9 Apr 1984 10:23:47 +0000 (02:23 -0800)
committerEdward Wang <edward@ucbvax.Berkeley.EDU>
Mon, 9 Apr 1984 10:23:47 +0000 (02:23 -0800)
and stuff to support them

SCCS-vsn: usr.bin/window/main.c 3.23
SCCS-vsn: usr.bin/window/wwopen.c 3.16
SCCS-vsn: usr.bin/window/ww.h 3.29
SCCS-vsn: usr.bin/window/cmd.c 3.29
SCCS-vsn: usr.bin/window/cmd1.c 3.25
SCCS-vsn: usr.bin/window/wwgets.c 3.6
SCCS-vsn: usr.bin/window/cmd2.c 3.29
SCCS-vsn: usr.bin/window/defs.h 3.14
SCCS-vsn: usr.bin/window/wwclose.c 3.10
SCCS-vsn: usr.bin/window/error.c 3.9
SCCS-vsn: usr.bin/window/:ww 1.9
SCCS-vsn: usr.bin/window/cmd6.c 3.11
SCCS-vsn: usr.bin/window/lcmd.c 3.18
SCCS-vsn: usr.bin/window/lcmd1.c 3.22
SCCS-vsn: usr.bin/window/wwenviron.c 3.10
SCCS-vsn: usr.bin/window/wwspawn.c 3.8
SCCS-vsn: usr.bin/window/wwiomux.c 3.10
SCCS-vsn: usr.bin/window/win.c 3.8
SCCS-vsn: usr.bin/window/lcmd2.c 3.3

19 files changed:
usr/src/usr.bin/window/:ww
usr/src/usr.bin/window/cmd.c
usr/src/usr.bin/window/cmd1.c
usr/src/usr.bin/window/cmd2.c
usr/src/usr.bin/window/cmd6.c
usr/src/usr.bin/window/defs.h
usr/src/usr.bin/window/error.c
usr/src/usr.bin/window/lcmd.c
usr/src/usr.bin/window/lcmd1.c
usr/src/usr.bin/window/lcmd2.c
usr/src/usr.bin/window/main.c
usr/src/usr.bin/window/win.c
usr/src/usr.bin/window/ww.h
usr/src/usr.bin/window/wwclose.c
usr/src/usr.bin/window/wwenviron.c
usr/src/usr.bin/window/wwgets.c
usr/src/usr.bin/window/wwiomux.c
usr/src/usr.bin/window/wwopen.c
usr/src/usr.bin/window/wwspawn.c

index 9c8825e..4f1b6ce 100644 (file)
@@ -8,8 +8,8 @@
 +/"cur.r"16t"cur.c"nDD
 +/"win"16t"buf"16t"fmap"16t"nvis"npppp
 +/"wstate"8t"modes"8t"insert"8t"mapnl"8t"noupd"n5b
 +/"cur.r"16t"cur.c"nDD
 +/"win"16t"buf"16t"fmap"16t"nvis"npppp
 +/"wstate"8t"modes"8t"insert"8t"mapnl"8t"noupd"n5b
-+/"unctrl"8t"nointr"8t"hascurs"8t"hasframe"n4b3+
-+/"pty"16t"pid"16t"ttyname"nDD11C+
-+/"ob"16t"obe"16t"obp"16t"obc"n3pD
-+/"stopped"nb3+
++/"unctrl"8t"nointr"8t"hascurs"8t"hasframe"n4b
++/"ispty"8t"stopped"8t"pty"16t"socket"16t"pid"nbb+3D
++/"ttyname"n11C+
++/"ob"16t"obe"16t"obp"16t"obq"n4p
 +/"center"8t"id"8t"label"16t"altpos.r"16t"altpos.c"n2b2+pDD
 +/"center"8t"id"8t"label"16t"altpos.r"16t"altpos.c"n2b2+pDD
index 6febd7f..e97d06e 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)cmd.c       3.28 84/04/08";
+static char *sccsid = "@(#)cmd.c       3.29 84/04/08";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -147,7 +147,7 @@ docmd()
                                        }
                                } else {
                                        if (!terse)
                                        }
                                } else {
                                        if (!terse)
-                                               wwputc(ctrl(g), cmdwin);
+                                               wwbell();
                                        error("Type ? for help.");
                                }
                        }
                                        error("Type ? for help.");
                                }
                        }
@@ -187,7 +187,7 @@ getwin()
        else if (c >= '1' && c < NWINDOW + '1')
                w = window[c - '1'];
        if (w == 0)
        else if (c >= '1' && c < NWINDOW + '1')
                w = window[c - '1'];
        if (w == 0)
-               wwputc(ctrl(g), cmdwin);
+               wwbell();
        if (!terse)
                wwputc('\n', cmdwin);
        return w;
        if (!terse)
                wwputc('\n', cmdwin);
        return w;
index c2934f1..eedd1e9 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)cmd1.c      3.24 84/04/08";
+static char *sccsid = "@(#)cmd1.c      3.25 84/04/08";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -70,7 +70,7 @@ c_window()
                wwputc('\n', cmdwin);
        wwcurtowin(cmdwin);
        (void) openwin(id, row, col, xrow-row+1, xcol-col+1, nbufline,
                wwputc('\n', cmdwin);
        wwcurtowin(cmdwin);
        (void) openwin(id, row, col, xrow-row+1, xcol-col+1, nbufline,
-               (char *) 0);
+               (char *) 0, 1, 1, shellfile, shell);
 }
 
 getpos(row, col, minrow, mincol, maxrow, maxcol)
 }
 
 getpos(row, col, minrow, mincol, maxrow, maxcol)
@@ -130,7 +130,7 @@ int maxrow, maxcol;
                default:
                        if (!terse)
                                wwputs("\nType [hjklHJKL] to move, return to enter position, escape to cancel.", cmdwin);
                default:
                        if (!terse)
                                wwputs("\nType [hjklHJKL] to move, return to enter position, escape to cancel.", cmdwin);
-                       wwputc(ctrl(g), cmdwin);
+                       wwbell();
                }
        }
        return oldrow != *row || oldcol != *col;
                }
        }
        return oldrow != *row || oldcol != *col;
index 09f3f33..6480112 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)cmd2.c      3.28 84/04/08";
+static char *sccsid = "@(#)cmd2.c      3.29 84/04/08";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -34,11 +34,12 @@ char *help_longcmd[] = {
        ":list                 List all windows.",
        ":nline lines          Set the default number of lines",
        "                      in window text buffers.",
        ":list                 List all windows.",
        ":nline lines          Set the default number of lines",
        "                      in window text buffers.",
-       ":source filename      Execute commands in ``filename''.",
+       ":shell string         Set default shell program to ``string.''",
+       ":source filename      Execute commands in ``filename.''",
        ":terse [off]          Turn on (or off) terse mode.",
        ":unset variable       Deallocate ``variable''.",
        ":variable             List all variables.",
        ":terse [off]          Turn on (or off) terse mode.",
        ":unset variable       Deallocate ``variable''.",
        ":variable             List all variables.",
-       ":window row col nrow ncol [nline label]",
+       ":window row col nrow ncol [nline label pty frame shell]",
        "                      Open a window at ``row'', ``col''",
        "                      of size ``nrow'', ``ncol'',",
        "                      with ``nline'', and ``label''.",
        "                      Open a window at ``row'', ``col''",
        "                      of size ``nrow'', ``ncol'',",
        "                      with ``nline'', and ``label''.",
index 7490cfb..6a4f14a 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)cmd6.c      3.10 84/04/08";
+static char *sccsid = "@(#)cmd6.c      3.11 84/04/08";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -43,7 +43,7 @@ c_debug()
                        wwdumpwin(w);
                break;
        default:
                        wwdumpwin(w);
                break;
        default:
-               wwputc(ctrl(g), cmdwin);
+               wwbell();
        }
 }
 
        }
 }
 
index ff8730f..c21cd3c 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- *     @(#)defs.h      3.13 84/04/05   
+ *     @(#)defs.h      3.14 84/04/08   
  */
 
 #include "ww.h"
  */
 
 #include "ww.h"
@@ -19,8 +19,8 @@ struct ww *fgwin;             /* the last foreground window */
 
 #define isfg(w)                ((w)->ww_order <= fgwin->ww_order)
 
 
 #define isfg(w)                ((w)->ww_order <= fgwin->ww_order)
 
-char *shell;                   /* the shell program */
-char *shellname;               /* the shell program name (for argv[0]) */
+char *shell[128];              /* the shell argv */
+char *shellfile;               /* the shell program */
 int nbufline;                  /* default buffer size for new windows */
 char escapec;                  /* the escape character */
 
 int nbufline;                  /* default buffer size for new windows */
 char escapec;                  /* the escape character */
 
index 59731b2..7bf93e4 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)error.c     3.8 84/04/08";
+static char *sccsid = "@(#)error.c     3.9 84/04/08";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -17,7 +17,7 @@ char *fmt;
 
        if (cx.x_type != X_FILE) {
                if (terse)
 
        if (cx.x_type != X_FILE) {
                if (terse)
-                       wwputc(ctrl(g), cmdwin);
+                       wwbell();
                else {
                        wwprintf(cmdwin, fmt, a, b, c, d, e, f, g, h);
                        wwputs("  ", cmdwin);
                else {
                        wwprintf(cmdwin, fmt, a, b, c, d, e, f, g, h);
                        wwputs("  ", cmdwin);
index 8292c05..d158374 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)lcmd.c      3.17 84/04/07";
+static char *sccsid = "@(#)lcmd.c      3.18 84/04/08";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -16,6 +16,7 @@ int l_label();
 int l_list();
 int l_nline();
 int l_select();
 int l_list();
 int l_nline();
 int l_select();
+int l_shell();
 int l_source();
 int l_terse();
 int l_time();
 int l_source();
 int l_terse();
 int l_time();
@@ -31,6 +32,7 @@ struct lcmd_arg arg_foreground[];
 struct lcmd_arg arg_label[];
 struct lcmd_arg arg_nline[];
 struct lcmd_arg arg_select[];
 struct lcmd_arg arg_label[];
 struct lcmd_arg arg_nline[];
 struct lcmd_arg arg_select[];
+struct lcmd_arg arg_shell[];
 struct lcmd_arg arg_source[];
 struct lcmd_arg arg_terse[];
 struct lcmd_arg arg_time[];
 struct lcmd_arg arg_source[];
 struct lcmd_arg arg_terse[];
 struct lcmd_arg arg_time[];
@@ -51,6 +53,7 @@ struct lcmd_tab lcmd_tab[] = {
        "list",         2,      l_list,         arg_null,
        "nlines",       1,      l_nline,        arg_nline,
        "select",       2,      l_select,       arg_select,
        "list",         2,      l_list,         arg_null,
        "nlines",       1,      l_nline,        arg_nline,
        "select",       2,      l_select,       arg_select,
+       "shell",        2,      l_shell,        arg_shell,
        "source",       2,      l_source,       arg_source,
        "terse",        2,      l_terse,        arg_terse,
        "time",         2,      l_time,         arg_time,
        "source",       2,      l_source,       arg_source,
        "terse",        2,      l_terse,        arg_terse,
        "time",         2,      l_time,         arg_time,
index 2f34964..1550dfd 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)lcmd1.c     3.21 84/04/08";
+static char *sccsid = "@(#)lcmd1.c     3.22 84/04/08";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -14,6 +14,9 @@ struct lcmd_arg arg_window[] = {
        { "ncols",      2,      ARG_ANY },
        { "nlines",     2,      ARG_NUM },
        { "label",      1,      ARG_STR },
        { "ncols",      2,      ARG_ANY },
        { "nlines",     2,      ARG_NUM },
        { "label",      1,      ARG_STR },
+       { "shell",      1,      ARG_STR },
+       { "pty",        1,      ARG_ANY },
+       { "frame",      1,      ARG_ANY },
        0
 };
 
        0
 };
 
@@ -22,16 +25,33 @@ register struct value *v, *a;
 {
        int col, row, ncol, nrow, id, nline;
        char *label;
 {
        int col, row, ncol, nrow, id, nline;
        char *label;
+       char haspty, hasframe;
+       char *shf, **sh;
+       char *argv[sizeof shell / sizeof *shell];
 
        if ((id = findid()) < 0)
                return;
 
        if ((id = findid()) < 0)
                return;
-       row = a->v_type != V_NUM ? 1 : a->v_num;
-       col = (++a)->v_type != V_NUM ? 0 : a->v_num;
-       nrow = (++a)->v_type != V_NUM ? wwnrow - row : a->v_num;
-       ncol = (++a)->v_type != V_NUM ? wwncol - col : a->v_num;
-       nline = (++a)->v_type == V_ERR ? nbufline : a->v_num;
-       label =  (++a)->v_type == V_ERR ? 0 : a->v_str;
-       if (openwin(id, row, col, nrow, ncol, nline, label) == 0)
+       row = a[0].v_type != V_NUM ? 1 : a[0].v_num;
+       col = a[1].v_type != V_NUM ? 0 : a[1].v_num;
+       nrow = a[2].v_type != V_NUM ? wwnrow - row : a[2].v_num;
+       ncol = a[3].v_type != V_NUM ? wwncol - col : a[3].v_num;
+       nline = a[4].v_type == V_ERR ? nbufline : a[4].v_num;
+       label =  a[5].v_type == V_ERR ? 0 : a[5].v_str;
+       if (a[6].v_type == V_STR) {
+               if (mkargv(a[6].v_str, argv, sizeof argv / sizeof *argv) < 0)
+                       return;
+               sh = argv;
+               shf = *argv;
+       } else {
+               sh = shell;
+               shf = shellfile;
+       }
+       if ((haspty = vtobool(a + 7, 1, -1)) < 0)
+               return;
+       if ((hasframe = vtobool(a + 8, 1, -1)) < 0)
+               return;
+       if (openwin(id, row, col, nrow, ncol, nline, label,
+                       haspty, hasframe, shf, sh) == 0)
                return;
        v->v_type = V_NUM;
        v->v_num = id + 1;
                return;
        v->v_type = V_NUM;
        v->v_num = id + 1;
@@ -301,3 +321,27 @@ char def, err;
        }
        /*NOTREACHED*/
 }
        }
        /*NOTREACHED*/
 }
+
+mkargv(p, argv, n)
+register char *p;
+register char **argv;
+register n;
+{
+       while (--n > 0) {
+               for (; *p && (*p == ' ' || *p == '\t'); p++)
+                       ;
+               if (!*p)
+                       break;
+               *argv++ = p;
+               for (; *p && *p != ' ' && *p != '\t'; p++)
+                       ;
+               if (*p)
+                       *p++ = 0;
+       }
+       if (n == 0) {
+               error("Too many shell arguments.");
+               return -1;
+       }
+       *argv = 0;
+       return 0;
+}
index ee5e25c..a656a47 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)lcmd2.c     3.2 84/04/07";
+static char *sccsid = "@(#)lcmd2.c     3.3 84/04/08";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -43,7 +43,7 @@ struct value *v, *a;
 }
 
 struct lcmd_arg arg_time[] = {
 }
 
 struct lcmd_arg arg_time[] = {
-       { "who",        1,      V_STR },
+       { "who",        1,      ARG_STR },
        0
 };
 
        0
 };
 
@@ -188,3 +188,37 @@ register struct var *r;
        }
        return 0;
 }
        }
        return 0;
 }
+
+struct lcmd_arg arg_shell[] = {
+       { "shell",      1,      ARG_STR },
+       0
+};
+
+l_shell(v, a)
+struct value *v, *a;
+{
+       register char **pp;
+
+       if (a->v_type == V_ERR) {
+               if ((v->v_str = str_cpy(shellfile)) != 0)
+                       v->v_type = V_STR;
+               return;
+       }
+       if (v->v_str = shellfile) {
+               v->v_type = V_STR;
+               for (pp = shell + 1; *pp; pp++)
+                       str_free(*pp);
+       }
+       if (mkargv(a->v_str, shell, sizeof shell / sizeof *shell) < 0)
+               *shell = 0;
+       for (pp = shell; *pp; pp++)
+               if ((*pp = str_cpy(*pp)) == 0) {
+                       /* just leave shell[] the way it is */
+                       p_memerror();
+               }
+       if (shellfile = *shell)
+               if (*shell = rindex(shellfile, '/'))
+                       (*shell)++;
+               else
+                       *shell = shellfile;
+}
index cb84d16..b12196c 100644 (file)
@@ -1,10 +1,11 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)main.c      3.22 84/04/08";
+static char *sccsid = "@(#)main.c      3.23 84/04/08";
 #endif
 
 #include "defs.h"
 #include <sys/signal.h>
 #include <stdio.h>
 #endif
 
 #include "defs.h"
 #include <sys/signal.h>
 #include <stdio.h>
+#include "string.h"
 #include "char.h"
 
 #define next(a) (*++*(a) ? *(a) : (*++(a) ? *(a) : (char *)usage()))
 #include "char.h"
 
 #define next(a) (*++*(a) ? *(a) : (*++(a) ? *(a) : (char *)usage()))
@@ -62,12 +63,16 @@ char **argv;
        }
        nbufline = 48;                          /* compatible */
        escapec = ctrl(p);      
        }
        nbufline = 48;                          /* compatible */
        escapec = ctrl(p);      
-       if ((shell = getenv("SHELL")) == 0)
-               shell = "/bin/csh";
-       if (shellname = rindex(shell, '/'))
-               shellname++;
+       if ((p = getenv("SHELL")) == 0)
+               p = "/bin/csh";
+       if ((shellfile = str_cpy(p)) == 0)
+               nomem();
+       if (p = rindex(shellfile, '/'))
+               p++;
        else
        else
-               shellname = shell;
+               p = shellfile;
+       shell[0] = p;
+       shell[1] = 0;
 #ifndef O_4_1A
        (void) gettimeofday(&starttime, (struct timezone *)0);
 #endif
 #ifndef O_4_1A
        (void) gettimeofday(&starttime, (struct timezone *)0);
 #endif
@@ -92,6 +97,7 @@ char **argv;
        cmdwin->ww_mapnl = 1;
        cmdwin->ww_nointr = 1;
        cmdwin->ww_noupdate = 1;
        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) {
                (void) wwflush();
        if ((framewin = wwopen(WWO_GLASS|WWO_FRAME, wwnrow, wwncol, 0, 0, 0))
            == 0) {
                (void) wwflush();
@@ -133,7 +139,13 @@ 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 */
 }
+
+nomem()
+{
+       (void) fprintf(stderr, "Out of memory.\n");
+       exit(1);
+}
index fc51997..43365c3 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)win.c       3.7 84/04/08";
+static char *sccsid = "@(#)win.c       3.8 84/04/08";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -25,8 +25,10 @@ static       char *sccsid = "@(#)win.c       3.7 84/04/08";
  * Open a user window.
  */
 struct ww *
  * Open a user window.
  */
 struct ww *
-openwin(id, row, col, nrow, ncol, nline, label)
+openwin(id, row, col, nrow, ncol, nline, label, haspty, hasframe, shf, sh)
 char *label;
 char *label;
+char haspty, hasframe;
+char *shf, **sh;
 {
        register struct ww *w;
 
 {
        register struct ww *w;
 
@@ -37,15 +39,18 @@ char *label;
                error("Illegal window position.");
                return 0;
        }
                error("Illegal window position.");
                return 0;
        }
-       if ((w = wwopen(WWO_PTY, nrow, ncol, row, col, nline)) == 0) {
-               error("%s.", wwerror());
+       w = wwopen(haspty ? WWO_PTY : WWO_SOCKET, nrow, ncol, row, col, nline);
+       if (w == 0) {
+               error("Can't open window: %s.", wwerror());
                return 0;
        }
        w->ww_id = id;
        window[id] = w;
                return 0;
        }
        w->ww_id = id;
        window[id] = w;
-       w->ww_hasframe = 1;
+       w->ww_hasframe = hasframe;
        w->ww_altpos.r = 1;
        w->ww_altpos.c = 0;
        w->ww_altpos.r = 1;
        w->ww_altpos.c = 0;
+       if (!haspty)
+               w->ww_mapnl = 1;
        if (label != 0 && setlabel(w, label) < 0)
                error("No memory for label.");
        wwcursor(w, 1);
        if (label != 0 && setlabel(w, label) < 0)
                error("No memory for label.");
        wwcursor(w, 1);
@@ -59,9 +64,9 @@ char *label;
        setselwin(w);
        wwupdate();
        wwflush();
        setselwin(w);
        wwupdate();
        wwflush();
-       if (wwspawn(w, shell, shellname, (char *)0) < 0) {
+       if (wwspawn(w, shf, sh) < 0) {
+               error("Can't execute %s: %s.", shf, wwerror());
                c_close(w);
                c_close(w);
-               error("%s: %s.", shell, wwerror());
                return 0;
        }
        return w;
                return 0;
        }
        return w;
index 6164ee2..99ea7b1 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- *     @(#)ww.h        3.28 84/04/08   
+ *     @(#)ww.h        3.29 84/04/08   
  */
 
 #include <sgtty.h>
  */
 
 #include <sgtty.h>
@@ -54,14 +54,16 @@ struct ww {
        char ww_hasframe;       /* frame it */
 
                /* things for the window process and io */
        char ww_hasframe;       /* frame it */
 
                /* things for the window process and io */
-       int ww_pty;             /* file descriptor of pty */
+       char ww_ispty;          /* ww_pty is really a pty, not socket pair */
+       char ww_stopped;        /* output stopped */
+       int ww_pty;             /* file descriptor of pty or socket pair */
+       int ww_socket;          /* other end of socket pair */
        int ww_pid;             /* pid of process, if WWS_HASPROC true */
        char ww_ttyname[11];    /* "/dev/ttyp?" */
        char *ww_ob;            /* output buffer */
        char *ww_obe;           /* end of ww_ob */
        int ww_pid;             /* pid of process, if WWS_HASPROC true */
        char ww_ttyname[11];    /* "/dev/ttyp?" */
        char *ww_ob;            /* output buffer */
        char *ww_obe;           /* end of ww_ob */
-       char *ww_obp;           /* current position in ww_ob */
-       int ww_obc;             /* character count */
-       char ww_stopped;        /* output stopped */
+       char *ww_obp;           /* current read position in ww_ob */
+       char *ww_obq;           /* current write position in ww_ob */
 
                /* things for the user, they really don't belong here */
        char ww_center;         /* center the label */
 
                /* things for the user, they really don't belong here */
        char ww_center;         /* center the label */
@@ -123,9 +125,10 @@ union ww_char {
 
        /* flags to wwopen() */
 #define WWO_PTY                0x01            /* want pty */
 
        /* flags to wwopen() */
 #define WWO_PTY                0x01            /* want pty */
-#define WWO_REVERSE    0x02            /* make it all reverse video */
-#define WWO_GLASS      0x04            /* make it all glass */
-#define WWO_FRAME      0x08            /* this is a frame window */
+#define WWO_SOCKET     0x02            /* want socket pair */
+#define WWO_REVERSE    0x04            /* make it all reverse video */
+#define WWO_GLASS      0x08            /* make it all glass */
+#define WWO_FRAME      0x10            /* this is a frame window */
 
        /* special ww_index value */
 #define WWX_NOBODY     NWW
 
        /* special ww_index value */
 #define WWX_NOBODY     NWW
@@ -182,6 +185,7 @@ int wwnwread, wwnwreade, wwnwreadz, wwnwreadd, wwnwreadc, wwnwreadp;
 int wwnselect, wwnselecte, wwnselectz;
 
        /* quicky macros */
 int wwnselect, wwnselecte, wwnselectz;
 
        /* quicky macros */
+#define wwbell()       write(1, "\7", 1)
 #define wwsetcursor(r,c) (wwcursorrow = (r), wwcursorcol = (c))
 #define wwcurtowin(w)  wwsetcursor((w)->ww_cur.r, (w)->ww_cur.c)
 #define wwunbox(w)     wwunframe(w)
 #define wwsetcursor(r,c) (wwcursorrow = (r), wwcursorcol = (c))
 #define wwcurtowin(w)  wwsetcursor((w)->ww_cur.r, (w)->ww_cur.c)
 #define wwunbox(w)     wwunframe(w)
index 6ad38ce..242feac 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)wwclose.c   3.9 84/03/02";
+static char *sccsid = "@(#)wwclose.c   3.10 84/04/08";
 #endif
 
 #include "ww.h"
 #endif
 
 #include "ww.h"
@@ -9,7 +9,10 @@ wwclose(w)
 register struct ww *w;
 {
        wwindex[w->ww_index] = 0;
 register struct ww *w;
 {
        wwindex[w->ww_index] = 0;
-       (void) close(w->ww_pty);
+       if (w->ww_pty >= 0)
+               (void) close(w->ww_pty);
+       if (w->ww_socket >= 0)
+               (void) close(w->ww_socket);
        wwfree((char **)w->ww_win, w->ww_w.t);
        wwfree((char **)w->ww_buf, w->ww_w.t);
        if (w->ww_fmap != 0)
        wwfree((char **)w->ww_win, w->ww_w.t);
        wwfree((char **)w->ww_buf, w->ww_w.t);
        if (w->ww_fmap != 0)
index 6e1217a..02a3821 100644 (file)
@@ -1,14 +1,11 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)wwenviron.c 3.9 84/03/23";
+static char *sccsid = "@(#)wwenviron.c 3.10 84/04/08";
 #endif
 
 #include "ww.h"
 
 /*
  * Set up the environment of this process to run in window 'wp'.
 #endif
 
 #include "ww.h"
 
 /*
  * Set up the environment of this process to run in window 'wp'.
- * Can't report errors in any intelligent way, because the parent
- * hangs in vfork() until we die, but we can't die until output
- * drains (i.e. deadlock).  So don't say anything.
  */
 wwenviron(wp)
 register struct ww *wp;
  */
 wwenviron(wp)
 register struct ww *wp;
@@ -16,21 +13,19 @@ register struct ww *wp;
        register i;
        int pgrp = getpid();
 
        register i;
        int pgrp = getpid();
 
-       i = open("/dev/tty", 0);
-       if (i < 0)
-               return;
+       if ((i = open("/dev/tty", 0)) < 0)
+               goto bad;
        if (ioctl(i, (int)TIOCNOTTY, (char *)0) < 0)
        if (ioctl(i, (int)TIOCNOTTY, (char *)0) < 0)
-               return;
+               goto bad;
        (void) close(i);
        (void) close(i);
-       if ((i = open(wp->ww_ttyname, 2)) < 0)
-               return;
+       if ((i = wp->ww_socket) < 0 && (i = open(wp->ww_ttyname, 2)) < 0)
+               goto bad;
        (void) dup2(i, 0);
        (void) dup2(i, 1);
        (void) dup2(i, 2);
        for (i = wwdtablesize - 1; i > 2; i--)
                (void) close(i);
        (void) dup2(i, 0);
        (void) dup2(i, 1);
        (void) dup2(i, 2);
        for (i = wwdtablesize - 1; i > 2; i--)
                (void) close(i);
-       if (ioctl(0, (int)TIOCSPGRP, (char *)&pgrp) < 0)
-               return;
+       (void) ioctl(0, (int)TIOCSPGRP, (char *)&pgrp);
        (void) setpgrp(pgrp, pgrp);
 
        (void) sprintf(wwwintermcap, "TERMCAP=%sco#%d:li#%d:%s%s%s%s",
        (void) setpgrp(pgrp, pgrp);
 
        (void) sprintf(wwwintermcap, "TERMCAP=%sco#%d:li#%d:%s%s%s%s",
@@ -39,4 +34,8 @@ register struct ww *wp;
                wwavailmodes & WWM_UL ? WWT_UL : "",
                wwavailmodes & WWM_GRP ? WWT_GRP : "",
                wwkeys);
                wwavailmodes & WWM_UL ? WWT_UL : "",
                wwavailmodes & WWM_GRP ? WWT_GRP : "",
                wwkeys);
+       return 0;
+bad:
+       wwerrno = WWE_SYS;
+       return -1;
 }
 }
index 122095c..021d26e 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)wwgets.c    3.5 84/04/08";
+static char *sccsid = "@(#)wwgets.c    3.6 84/04/08";
 #endif
 
 #include "ww.h"
 #endif
 
 #include "ww.h"
@@ -12,7 +12,9 @@ register struct ww *w;
 {
        register char *p = buf;
        register char c;
 {
        register char *p = buf;
        register char c;
+       char uc = w->ww_unctrl;
 
 
+       w->ww_unctrl = 0;
        for (;;) {
                wwcurtowin(w);
                while ((c = wwgetc()) < 0)
        for (;;) {
                wwcurtowin(w);
                while ((c = wwgetc()) < 0)
@@ -20,8 +22,6 @@ register struct ww *w;
                if (c == wwoldtty.ww_sgttyb.sg_erase) {
                        if (p > buf)
                                rub(*--p, w);
                if (c == wwoldtty.ww_sgttyb.sg_erase) {
                        if (p > buf)
                                rub(*--p, w);
-                       else
-                               wwputc(ctrl(g), w);
                } else if (c == wwoldtty.ww_sgttyb.sg_kill) {
                        while (p > buf)
                                rub(*--p, w);
                } else if (c == wwoldtty.ww_sgttyb.sg_kill) {
                        while (p > buf)
                                rub(*--p, w);
@@ -41,6 +41,7 @@ register struct ww *w;
                }
        }
        *p = 0;
                }
        }
        *p = 0;
+       w->ww_unctrl = uc;
 }
 
 static
 }
 
 static
index 6b1f8e8..0713503 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)wwiomux.c   3.9 84/03/06";
+static char *sccsid = "@(#)wwiomux.c   3.10 84/04/08";
 #endif
 
 #include "ww.h"
 #endif
 
 #include "ww.h"
@@ -36,7 +36,7 @@ loop:
                if (w->ww_pty < 0)
                        continue;
                imask |= 1 << w->ww_pty;
                if (w->ww_pty < 0)
                        continue;
                imask |= 1 << w->ww_pty;
-               if (w->ww_obc > 0 && !w->ww_stopped)
+               if (w->ww_obq > w->ww_obp && !w->ww_stopped)
                        noblock = 1;
        }
 
                        noblock = 1;
        }
 
@@ -60,53 +60,58 @@ loop:
 
        if (n < 0)
                wwnselecte++;
 
        if (n < 0)
                wwnselecte++;
-       else {
-               if (n == 0)
-                       wwnselectz++;
-               for (w = wwhead.ww_forw; w != &wwhead; w = w->ww_forw)
-                       if (w->ww_pty >= 0 && imask & 1 << w->ww_pty) {
-                               wwnwread++;
-                               p = w->ww_obp + w->ww_obc;
-                               if (p == w->ww_ob)
+       else if (n == 0)
+               wwnselectz++;
+       else
+               for (w = wwhead.ww_forw; w != &wwhead; w = w->ww_forw) {
+                       if (w->ww_pty < 0 || (imask & 1 << w->ww_pty) == 0)
+                               continue;
+                       wwnwread++;
+                       p = w->ww_obq;
+                       if (w->ww_ispty) {
+                               if (p == w->ww_ob) {
                                        w->ww_obp++;
                                        w->ww_obp++;
-                               else
+                                       w->ww_obq++;
+                               } else
                                        p--;
                                c = *p;
                                        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;
-                                       continue;
-                               } else if (n == 0) {
-                                       wwnwreadz++;
-                               } else if (*p == TIOCPKT_DATA) {
-                                       n--;
-                                       wwnwreadd++;
-                                       wwnwreadc += n;
-                                       w->ww_obc += 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_obp = w->ww_ob;
-                                               w->ww_obc = 0;
-                                       }
+                       }
+                       n = read(w->ww_pty, p, w->ww_obe - p);
+                       if (n < 0) {
+                               wwnwreade++;
+                               (void) close(w->ww_pty);
+                               w->ww_pty = -1;
+                               continue;
+                       } else if (n == 0) {
+                               wwnwreadz++;
+                       } 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;
                                }
                                }
-                               *p = c;
                        }
                        }
-       }
+                       if (w->ww_ispty)
+                               *p = c;
+               }
        for (w = wwhead.ww_forw; w != &wwhead; w = w->ww_forw)
        for (w = wwhead.ww_forw; w != &wwhead; w = w->ww_forw)
-               if (w->ww_pty >= 0 && w->ww_obc != 0 && !w->ww_stopped) {
-                       n = wwwrite(w, w->ww_obp, w->ww_obc);
-                       if (w->ww_obc -= n)
-                               w->ww_obp += n;
-                       else
-                               w->ww_obp = w->ww_ob;
+               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;
                        if (wwinterrupt())
                                return;
                        break;
index 7ff4446..c41eb26 100644 (file)
@@ -1,8 +1,10 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)wwopen.c    3.15 84/01/16";
+static char *sccsid = "@(#)wwopen.c    3.16 84/04/08";
 #endif
 
 #include "ww.h"
 #endif
 
 #include "ww.h"
+#include <sys/types.h>
+#include <sys/socket.h>
 
 struct ww *
 wwopen(flags, nrow, ncol, row, col, nline)
 
 struct ww *
 wwopen(flags, nrow, ncol, row, col, nline)
@@ -18,6 +20,7 @@ wwopen(flags, nrow, ncol, row, col, nline)
                goto bad;
        }
        w->ww_pty = -1;
                goto bad;
        }
        w->ww_pty = -1;
+       w->ww_socket = -1;
 
        for (i = 0; i < NWW && wwindex[i] != 0; i++)
                ;
 
        for (i = 0; i < NWW && wwindex[i] != 0; i++)
                ;
@@ -59,10 +62,23 @@ wwopen(flags, nrow, ncol, row, col, nline)
                        goto bad;
                if (wwsettty(w->ww_pty, &wwwintty) < 0)
                        goto bad;
                        goto bad;
                if (wwsettty(w->ww_pty, &wwwintty) < 0)
                        goto bad;
-               if ((w->ww_ob = malloc(512)) == 0)
+               w->ww_ispty = 1;
+       } else if (flags & WWO_SOCKET) {
+               int d[2];
+               if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, d) < 0) {
+                       wwerrno = WWE_SYS;
                        goto bad;
                        goto bad;
+               }
+               w->ww_pty = d[0];
+               w->ww_socket = d[1];
+       }
+       if (flags & (WWO_PTY|WWO_SOCKET)) {
+               if ((w->ww_ob = malloc(512)) == 0) {
+                       wwerrno = WWE_NOMEM;
+                       goto bad;
+               }
                w->ww_obe = w->ww_ob + 512;
                w->ww_obe = w->ww_ob + 512;
-               w->ww_obp = w->ww_ob;
+               w->ww_obp = w->ww_obq = w->ww_ob;
        }
 
        w->ww_win = wwalloc(w->ww_w.t, w->ww_w.l,
        }
 
        w->ww_win = wwalloc(w->ww_w.t, w->ww_w.l,
@@ -121,7 +137,10 @@ bad:
                        free((char *)(w->ww_nvis + w->ww_w.t));
                if (w->ww_ob != 0)
                        free(w->ww_ob);
                        free((char *)(w->ww_nvis + w->ww_w.t));
                if (w->ww_ob != 0)
                        free(w->ww_ob);
-               (void) close(w->ww_pty);
+               if (w->ww_pty >= 0)
+                       (void) close(w->ww_pty);
+               if (w->ww_socket >= 0)
+                       (void) close(w->ww_socket);
                free((char *)w);
        }
        return 0;
                free((char *)w);
        }
        return 0;
index bfe4898..b0073a9 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)wwspawn.c   3.7 84/01/13";
+static char *sccsid = "@(#)wwspawn.c   3.8 84/04/08";
 #endif
 
 #include "ww.h"
 #endif
 
 #include "ww.h"
@@ -7,38 +7,44 @@ static        char *sccsid = "@(#)wwspawn.c   3.7 84/01/13";
 
 /*
  * There is a dead lock with vfork and closing of pseudo-ports.
 
 /*
  * There is a dead lock with vfork and closing of pseudo-ports.
- * So we have to be sneaky.
+ * So we have to be sneaky about error reporting.
  */
  */
-/*VARARGS3*/
-wwspawn(wp, file, argv0)
+wwspawn(wp, file, argv)
 register struct ww *wp;
 register struct ww *wp;
-char *file, *argv0;
+char *file;
+char **argv;
 {
 {
-       extern int errno;
-       extern char *sys_errlist[];
        int pid;
        int pid;
+       int ret;
+       char erred = 0;
 
        (void) sighold(SIGCHLD);
        switch (pid = vfork()) {
        case -1:
                wwerrno = WWE_SYS;
 
        (void) sighold(SIGCHLD);
        switch (pid = vfork()) {
        case -1:
                wwerrno = WWE_SYS;
-               (void) sigrelse(SIGCHLD);
-               return -1;
+               ret = -1;
+               break;
        case 0:
        case 0:
-               wwenviron(wp);
-               errno = 0;
-               execv(file, &argv0);
+               if (wwenviron(wp) >= 0)
+                       execvp(file, argv);
+               erred = 1;
                _exit(1);
        default:
                _exit(1);
        default:
-               if (errno != 0) {
+               if (erred) {
                        wwerrno = WWE_SYS;
                        wwerrno = WWE_SYS;
-                       (void) sigrelse(SIGCHLD);
-                       return -1;
+                       ret = -1;
                } else {
                        wp->ww_pid = pid;
                        wp->ww_state = WWS_HASPROC;
                } else {
                        wp->ww_pid = pid;
                        wp->ww_state = WWS_HASPROC;
-                       (void) sigrelse(SIGCHLD);
-                       return pid;
+                       ret = pid;
                }
        }
                }
        }
+       (void) sigrelse(SIGCHLD);
+       /*
+       if (wp->ww_socket >= 0) {
+               (void) close(wp->ww_socket);
+               wp->ww_socket = -1;
+       }
+       */
+       return ret;
 }
 }