stdio.h defines BUFSIZ
[unix-history] / usr / src / usr.bin / window / lcmd1.c
index a30c185..475d11d 100644 (file)
@@ -1,6 +1,16 @@
+/*
+ * 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 = "@(#)lcmd1.c     3.23 84/05/06";
-#endif
+static char sccsid[] = "@(#)lcmd1.c    3.36 (Berkeley) %G%";
+#endif /* not lint */
 
 #include "defs.h"
 #include "string.h"
 
 #include "defs.h"
 #include "string.h"
@@ -9,67 +19,124 @@ static      char *sccsid = "@(#)lcmd1.c     3.23 84/05/06";
 #include "var.h"
 
 struct lcmd_arg arg_window[] = {
 #include "var.h"
 
 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 },
-       { "shell",      1,      ARG_STR },
        { "pty",        1,      ARG_ANY },
        { "frame",      1,      ARG_ANY },
        { "pty",        1,      ARG_ANY },
        { "frame",      1,      ARG_ANY },
+       { "mapnl",      1,      ARG_ANY },
+       { "keepopen",   1,      ARG_ANY },
+       { "smooth",     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;
+       char haspty, hasframe, mapnl, keepopen, smooth;
        char *shf, **sh;
        char *shf, **sh;
-       char *argv[sizeof shell / sizeof *shell];
+       char *argv[sizeof default_shell / sizeof *default_shell];
+       register char **pp;
 
        if ((id = findid()) < 0)
                return;
 
        if ((id = findid()) < 0)
                return;
-       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)
+       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 ? default_nline : a->v_num;
+       a++;
+       label = a->v_type == V_ERR ? 0 : a->v_str;
+       if ((haspty = vtobool(++a, 1, -1)) < 0)
+               return;
+       if ((hasframe = vtobool(++a, 1, -1)) < 0)
+               return;
+       if ((mapnl = vtobool(++a, !haspty, -1)) < 0)
                return;
                return;
-       if ((hasframe = vtobool(a + 8, 1, -1)) < 0)
+       if ((keepopen = vtobool(++a, 0, -1)) < 0)
                return;
                return;
-       if (openwin(id, row, col, nrow, ncol, nline, label,
-                       haspty, hasframe, shf, sh) == 0)
+       if ((smooth = vtobool(++a, default_smooth, -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 = default_shell;
+               shf = default_shellfile;
+       }
+       if ((w = openwin(id, row, col, nrow, ncol, nline, label, haspty,
+           hasframe, shf, sh)) == 0)
                return;
                return;
+       w->ww_mapnl = mapnl;
+       w->ww_keepopen = keepopen;
+       w->ww_noupdate = !smooth;
        v->v_type = V_NUM;
        v->v_num = id + 1;
 }
 
        v->v_type = V_NUM;
        v->v_num = id + 1;
 }
 
-struct lcmd_arg arg_nline[] = {
+struct lcmd_arg arg_def_nline[] = {
        { "nlines",     1,      ARG_NUM },
        0
 };
 
        { "nlines",     1,      ARG_NUM },
        0
 };
 
-l_nline(v, a)
+l_def_nline(v, a)
 register struct value *v, *a;
 {
 register struct value *v, *a;
 {
-       v->v_num = nbufline;
+       v->v_num = default_nline;
        v->v_type = V_NUM;
        if (a->v_type != V_ERR)
        v->v_type = V_NUM;
        if (a->v_type != V_ERR)
-               nbufline = a->v_num;
+               default_nline = a->v_num;
+}
+
+struct lcmd_arg arg_smooth[] = {
+       { "window",     1,      ARG_NUM },
+       { "flag",       1,      ARG_ANY },
+       0
+};
+
+l_smooth(v, a)
+register struct value *v, *a;
+{
+       struct ww *w;
+
+       v->v_type = V_NUM;
+       v->v_num = 0;
+       if ((w = vtowin(a++, selwin)) == 0)
+               return;
+       v->v_num = !w->ww_noupdate;
+       w->ww_noupdate = !vtobool(a, v->v_num, v->v_num);
+}
+
+struct lcmd_arg arg_def_smooth[] = {
+       { "flag",       1,      ARG_ANY },
+       0
+};
+
+l_def_smooth(v, a)
+register struct value *v, *a;
+{
+       v->v_type = V_NUM;
+       v->v_num = default_smooth;
+       default_smooth = vtobool(a, v->v_num, v->v_num);
 }
 
 struct lcmd_arg arg_select[] = {
 }
 
 struct lcmd_arg arg_select[] = {
@@ -86,7 +153,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);
 }
@@ -101,7 +168,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[] = {
@@ -138,7 +205,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.");
@@ -157,11 +224,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);
@@ -179,7 +246,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[] = {
@@ -198,6 +265,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;
@@ -206,7 +279,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) {
@@ -219,6 +292,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;
@@ -226,12 +304,12 @@ register struct value *a;
 {
        struct ww *w;
 
 {
        struct ww *w;
 
-       if (a->v_type == V_STR && str_match(a->v_str, "all", 1))
-               c_close((struct ww *)0);
+       if (a->v_type == V_STR && str_match(a->v_str, "all", 3))
+               closewin((struct ww *)0);
        else
                for (; a->v_type != V_ERR; a++)
        else
                for (; a->v_type != V_ERR; a++)
-                       if ((w = vtowin(a)) != 0)
-                               c_close(w);
+                       if ((w = vtowin(a, (struct ww *)0)) != 0)
+                               closewin(w);
 }
 
 struct lcmd_arg arg_cursormodes[] = {
 }
 
 struct lcmd_arg arg_cursormodes[] = {
@@ -275,13 +353,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:
@@ -322,27 +401,3 @@ 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;
-}