Add define for Kirk Smith's USR Courier driver. Change default baud
[unix-history] / usr / src / usr.bin / window / lcmd1.c
index 523199a..0d05789 100644 (file)
@@ -1,38 +1,82 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)lcmd1.c     3.20 84/04/06";
+static char sccsid[] = "@(#)lcmd1.c    3.30 %G%";
 #endif
 
 #endif
 
+/*
+ * Copyright (c) 1983 Regents of the University of California,
+ * All rights reserved.  Redistribution permitted subject to
+ * the terms of the Berkeley Software License Agreement.
+ */
+
 #include "defs.h"
 #include "string.h"
 #include "value.h"
 #include "lcmd.h"
 #include "defs.h"
 #include "string.h"
 #include "value.h"
 #include "lcmd.h"
+#include "var.h"
 
 struct lcmd_arg arg_window[] = {
 
 struct lcmd_arg arg_window[] = {
-       { "row",        1,      ARG_ANY },
-       { "column",     1,      ARG_ANY },
-       { "nrows",      2,      ARG_ANY },
-       { "ncols",      2,      ARG_ANY },
+       { "row",        1,      ARG_NUM },
+       { "column",     1,      ARG_NUM },
+       { "nrows",      2,      ARG_NUM },
+       { "ncols",      2,      ARG_NUM },
        { "nlines",     2,      ARG_NUM },
        { "label",      1,      ARG_STR },
        { "nlines",     2,      ARG_NUM },
        { "label",      1,      ARG_STR },
+       { "pty",        1,      ARG_ANY },
+       { "frame",      1,      ARG_ANY },
+       { "mapnl",      1,      ARG_ANY },
+       { "shell",      1,      ARG_STR|ARG_LIST },
        0
 };
 
 l_window(v, a)
        0
 };
 
 l_window(v, a)
-register struct value *v, *a;
+struct value *v;
+register struct value *a;
 {
 {
+       struct ww *w;
        int col, row, ncol, nrow, id, nline;
        char *label;
        int col, row, ncol, nrow, id, nline;
        char *label;
+       char haspty, hasframe, mapnl;
+       char *shf, **sh;
+       char *argv[sizeof shell / sizeof *shell];
+       register char **pp;
 
        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->v_type == V_ERR ? 1 : a->v_num;
+       a++;
+       col = a->v_type == V_ERR ? 0 : a->v_num;
+       a++;
+       nrow = a->v_type == V_ERR ? wwnrow - row : a->v_num;
+       a++;
+       ncol = a->v_type == V_ERR ? wwncol - col : a->v_num;
+       a++;
+       nline = a->v_type == V_ERR ? nbufline : a->v_num;
+       a++;
+       label = a->v_type == V_ERR ? 0 : a->v_str;
+       if ((haspty = vtobool(++a, 1, -1)) < 0)
                return;
                return;
+       if ((hasframe = vtobool(++a, 1, -1)) < 0)
+               return;
+       if ((mapnl = vtobool(++a, !haspty, -1)) < 0)
+               return;
+       if ((++a)->v_type != V_ERR) {
+               for (pp = argv; a->v_type != V_ERR &&
+                    pp < &argv[sizeof argv/sizeof *argv-1]; pp++, a++)
+                       *pp = a->v_str;
+               *pp = 0;
+               shf = *(sh = argv);
+               if (*sh = rindex(shf, '/'))
+                       (*sh)++;
+               else
+                       *sh = shf;
+       } else {
+               sh = shell;
+               shf = shellfile;
+       }
+       if ((w = openwin(id, row, col, nrow, ncol, nline, label, haspty,
+           hasframe, shf, sh)) == 0)
+               return;
+       w->ww_mapnl = mapnl;
        v->v_type = V_NUM;
        v->v_num = id + 1;
 }
        v->v_type = V_NUM;
        v->v_num = id + 1;
 }
@@ -65,7 +109,7 @@ register struct value *v, *a;
        v->v_num = selwin ? selwin->ww_id + 1 : -1;
        if (a->v_type == V_ERR)
                return;
        v->v_num = selwin ? selwin->ww_id + 1 : -1;
        if (a->v_type == V_ERR)
                return;
-       if ((w = vtowin(a)) == 0)
+       if ((w = vtowin(a, (struct ww *)0)) == 0)
                return;
        setselwin(w);
 }
                return;
        setselwin(w);
 }
@@ -80,7 +124,7 @@ register struct value *v, *a;
 {
        v->v_type = V_NUM;
        v->v_num = debug;
 {
        v->v_type = V_NUM;
        v->v_num = debug;
-       debug = vtobool(a, 1, debug);
+       debug = vtobool(a, debug, debug);
 }
 
 struct lcmd_arg arg_escape[] = {
 }
 
 struct lcmd_arg arg_escape[] = {
@@ -91,7 +135,11 @@ struct lcmd_arg arg_escape[] = {
 l_escape(v, a)
 register struct value *v, *a;
 {
 l_escape(v, a)
 register struct value *v, *a;
 {
-       if ((v->v_str = str_cpy(unctrl(escapec))) == 0) {
+       char buf[2];
+
+       buf[0] = escapec;
+       buf[1] = 0;
+       if ((v->v_str = str_cpy(buf)) == 0) {
                error("Out of memory.");
                return;
        }
                error("Out of memory.");
                return;
        }
@@ -113,7 +161,7 @@ register struct value *a;
 {
        struct ww *w;
 
 {
        struct ww *w;
 
-       if ((w = vtowin(a)) == 0)
+       if ((w = vtowin(a, selwin)) == 0)
                return;
        if ((++a)->v_type != V_ERR && setlabel(w, a->v_str) < 0)
                error("Out of memory.");
                return;
        if ((++a)->v_type != V_ERR && setlabel(w, a->v_str) < 0)
                error("Out of memory.");
@@ -132,11 +180,11 @@ register struct value *v, *a;
        struct ww *w;
        char flag;
 
        struct ww *w;
        char flag;
 
-       if ((w = vtowin(a)) == 0)
+       if ((w = vtowin(a, selwin)) == 0)
                return;
        v->v_type = V_NUM;
        v->v_num = isfg(w);
                return;
        v->v_type = V_NUM;
        v->v_num = isfg(w);
-       flag = vtobool(++a, 1, v->v_num);
+       flag = vtobool(++a, v->v_num, v->v_num);
        if (flag == v->v_num)
                return;
        deletewin(w);
        if (flag == v->v_num)
                return;
        deletewin(w);
@@ -154,7 +202,7 @@ register struct value *v, *a;
 {
        v->v_type = V_NUM;
        v->v_num = terse;
 {
        v->v_type = V_NUM;
        v->v_num = terse;
-       setterse(vtobool(a, 1, terse));
+       setterse(vtobool(a, terse, terse));
 }
 
 struct lcmd_arg arg_source[] = {
 }
 
 struct lcmd_arg arg_source[] = {
@@ -173,6 +221,12 @@ register struct value *v, *a;
                v->v_num = 0;
 }
 
                v->v_num = 0;
 }
 
+struct lcmd_arg arg_write[] = {
+       { "window",     1,      ARG_NUM },
+       { "",           0,      ARG_ANY|ARG_LIST },
+       0
+};
+
 /*ARGSUSED*/
 l_write(v, a)
 struct value *v;
 /*ARGSUSED*/
 l_write(v, a)
 struct value *v;
@@ -181,7 +235,7 @@ register struct value *a;
        char buf[20];
        struct ww *w;
 
        char buf[20];
        struct ww *w;
 
-       if ((w = vtowin(a++)) == 0)
+       if ((w = vtowin(a++, selwin)) == 0)
                return;
        while (a->v_type != V_ERR) {
                if (a->v_type == V_NUM) {
                return;
        while (a->v_type != V_ERR) {
                if (a->v_type == V_NUM) {
@@ -194,6 +248,11 @@ register struct value *a;
        }
 }
 
        }
 }
 
+struct lcmd_arg arg_close[] = {
+       { "window",     1,      ARG_ANY|ARG_LIST },
+       0
+};
+
 /*ARGSUSED*/
 l_close(v, a)
 struct value *v;
 /*ARGSUSED*/
 l_close(v, a)
 struct value *v;
@@ -201,11 +260,11 @@ register struct value *a;
 {
        struct ww *w;
 
 {
        struct ww *w;
 
-       if (a->v_type == V_STR && str_match(a->v_str, "all", 1))
+       if (a->v_type == V_STR && str_match(a->v_str, "all", 3))
                c_close((struct ww *)0);
        else
                for (; a->v_type != V_ERR; a++)
                c_close((struct ww *)0);
        else
                for (; a->v_type != V_ERR; a++)
-                       if ((w = vtowin(a)) != 0)
+                       if ((w = vtowin(a, (struct ww *)0)) != 0)
                                c_close(w);
 }
 
                                c_close(w);
 }
 
@@ -250,13 +309,14 @@ register struct value *v, *a;
 }
 
 struct ww *
 }
 
 struct ww *
-vtowin(v)
+vtowin(v, w)
 register struct value *v;
 register struct value *v;
+struct ww *w;
 {
 {
-       struct ww *w;
-
        switch (v->v_type) {
        case V_ERR:
        switch (v->v_type) {
        case V_ERR:
+               if (w != 0)
+                       return w;
                error("No window specified.");
                return 0;
        case V_STR:
                error("No window specified.");
                return 0;
        case V_STR: