add pathnames.h
[unix-history] / usr / src / usr.bin / window / lcmd1.c
index 8e46826..e67368a 100644 (file)
+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)lcmd1.c     3.13 84/01/12";
-#endif
+static char sccsid[] = "@(#)lcmd1.c    3.34 (Berkeley) %G%";
+#endif /* not lint */
 
 #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 },
-       { 0,            0,      0 }
+       { "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)
-register struct value *v;
+l_window(v, a)
+struct value *v;
+register struct value *a;
 {
 {
-       register struct lcmd_arg *a = arg_window;
+       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, keepopen, smooth;
+       char *shf, **sh;
+       char *argv[sizeof default_shell / sizeof *default_shell];
+       register char **pp;
 
        if ((id = findid()) < 0)
                return;
 
        if ((id = findid()) < 0)
                return;
-       row = a->arg_vtype != V_NUM ? 1 : a->arg_num;
-       col = (++a)->arg_vtype != V_NUM ? 0 : a->arg_num;
-       nrow = (++a)->arg_vtype != V_NUM ? wwnrow - row : a->arg_num;
-       ncol = (++a)->arg_vtype != V_NUM ? wwncol - col : a->arg_num;
-       nline = (++a)->arg_vtype == V_ERR ? nbufline : a->arg_num;
-       label =  (++a)->arg_vtype == V_ERR ? 0 : a->arg_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 ? default_nline : 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 ((keepopen = vtobool(++a, 0, -1)) < 0)
+               return;
+       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;
+       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_buffer[] = {
+struct lcmd_arg arg_def_nline[] = {
        { "nlines",     1,      ARG_NUM },
        { "nlines",     1,      ARG_NUM },
-       { 0,            0,      0 }
+       0
 };
 
 };
 
-l_buffer(v)
-struct value *v;
+l_def_nline(v, a)
+register struct value *v, *a;
 {
 {
-       v->v_num = nbufline;
+       v->v_num = default_nline;
        v->v_type = V_NUM;
        v->v_type = V_NUM;
-       if (arg_buffer[0].arg_vtype != V_ERR)
-               nbufline = arg_buffer[0].arg_num;
+       if (a->v_type != V_ERR)
+               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[] = {
        { "window",     1,      ARG_NUM },
 }
 
 struct lcmd_arg arg_select[] = {
        { "window",     1,      ARG_NUM },
-       { 0,            0,      0 }
+       0
 };
 
 };
 
-l_select(v)
-struct value *v;
+l_select(v, a)
+register struct value *v, *a;
 {
        struct ww *w;
 
        v->v_type = V_NUM;
        v->v_num = selwin ? selwin->ww_id + 1 : -1;
 {
        struct ww *w;
 
        v->v_type = V_NUM;
        v->v_num = selwin ? selwin->ww_id + 1 : -1;
-       if (arg_select[0].arg_vtype == V_ERR)
+       if (a->v_type == V_ERR)
                return;
                return;
-       if ((w = vtowin(&arg_select[0].arg_val)) == 0)
+       if ((w = vtowin(a, (struct ww *)0)) == 0)
                return;
        setselwin(w);
 }
 
 struct lcmd_arg arg_debug[] = {
        { "flag",       1,      ARG_ANY },
                return;
        setselwin(w);
 }
 
 struct lcmd_arg arg_debug[] = {
        { "flag",       1,      ARG_ANY },
-       { 0,            0,      0 }
+       0
 };
 
 };
 
-l_debug(v)
-struct value *v;
+l_debug(v, a)
+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(&arg_debug[0].arg_val, 1, debug);
+       debug = vtobool(a, debug, debug);
 }
 
 struct lcmd_arg arg_escape[] = {
 }
 
 struct lcmd_arg arg_escape[] = {
-       { "escapec",    1,      ARG_NUM },
-       { 0,            0,      0 }
+       { "escapec",    1,      ARG_STR },
+       0
 };
 
 };
 
-l_escape(v)
-struct value *v;
+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;
        }
        v->v_type = V_STR;
                error("Out of memory.");
                return;
        }
        v->v_type = V_STR;
-       if (arg_escape[0].arg_type != V_ERR)
-               setescape(arg_escape[0].arg_str);
+       if (a->v_type != V_ERR)
+               setescape(a->v_str);
 }
 
 struct lcmd_arg arg_label[] = {
        { "window",     1,      ARG_NUM },
        { "label",      1,      ARG_STR },
 }
 
 struct lcmd_arg arg_label[] = {
        { "window",     1,      ARG_NUM },
        { "label",      1,      ARG_STR },
-       { 0,            0,      0 }
+       0
 };
 
 /*ARGSUSED*/
 };
 
 /*ARGSUSED*/
-l_label(v)
+l_label(v, a)
 struct value *v;
 struct value *v;
+register struct value *a;
 {
        struct ww *w;
 {
        struct ww *w;
-       register struct lcmd_arg *a = arg_label;
 
 
-       if ((w = vtowin(&a->arg_val)) == 0)
+       if ((w = vtowin(a, selwin)) == 0)
                return;
                return;
-       if ((++a)->arg_vtype != V_ERR && setlabel(w, a->arg_str) < 0)
+       if ((++a)->v_type != V_ERR && setlabel(w, a->v_str) < 0)
                error("Out of memory.");
        reframe();
 }
 
                error("Out of memory.");
        reframe();
 }
 
+struct lcmd_arg arg_foreground[] = {
+       { "window",     1,      ARG_NUM },
+       { "flag",       1,      ARG_ANY },
+       0
+};
+
+l_foreground(v, a)
+register struct value *v, *a;
+{
+       struct ww *w;
+       char flag;
+
+       if ((w = vtowin(a, selwin)) == 0)
+               return;
+       v->v_type = V_NUM;
+       v->v_num = isfg(w);
+       flag = vtobool(++a, v->v_num, v->v_num);
+       if (flag == v->v_num)
+               return;
+       deletewin(w);
+       addwin(w, flag);
+       reframe();
+}
+
 struct lcmd_arg arg_terse[] = {
        { "flag",       1,      ARG_ANY },
 struct lcmd_arg arg_terse[] = {
        { "flag",       1,      ARG_ANY },
-       { 0,            0,      0 }
+       0
 };
 
 };
 
-l_terse(v)
-struct value *v;
+l_terse(v, a)
+register struct value *v, *a;
 {
        v->v_type = V_NUM;
        v->v_num = terse;
 {
        v->v_type = V_NUM;
        v->v_num = terse;
-       terse = vtobool(&arg_terse[0].arg_val, 1, terse);
-       if (!terse && v->v_num)
-               wwadd(cmdwin, &wwhead);
-       else if (!v->v_num && terse)
-               wwdelete(cmdwin);
-       reframe();
+       setterse(vtobool(a, terse, terse));
 }
 
 struct lcmd_arg arg_source[] = {
        { "filename",   1,      ARG_STR },
 }
 
 struct lcmd_arg arg_source[] = {
        { "filename",   1,      ARG_STR },
-       { 0,            0,      0 }
+       0
 };
 
 };
 
-/*ARGSUSED*/
-l_source(v)
-struct value *v;
+l_source(v, a)
+register struct value *v, *a;
 {
 {
-       if (arg_source[0].arg_vtype != V_ERR
-           && dosource(arg_source[0].arg_str) < 0) {
-               error("Can't open %s.", arg_source[0].arg_str);
+       v->v_type = V_NUM;
+       if (a->v_type != V_ERR && dosource(a->v_str) < 0) {
+               error("Can't open %s.", a->v_str);
                v->v_num = -1;
        } else
                v->v_num = 0;
                v->v_num = -1;
        } else
                v->v_num = 0;
-       v->v_type = V_NUM;
 }
 
 struct lcmd_arg arg_write[] = {
        { "window",     1,      ARG_NUM },
 }
 
 struct lcmd_arg arg_write[] = {
        { "window",     1,      ARG_NUM },
-       { "string",     1,      ARG_STR },
-       { 0,            0,      0 }
+       { "",           0,      ARG_ANY|ARG_LIST },
+       0
 };
 
 /*ARGSUSED*/
 };
 
 /*ARGSUSED*/
-l_write(v)
+l_write(v, a)
 struct value *v;
 struct value *v;
+register struct value *a;
 {
 {
-       register struct lcmd_arg *a = arg_write;
+       char buf[20];
        struct ww *w;
 
        struct ww *w;
 
-       if ((w = vtowin(&a->arg_val)) == 0)
+       if ((w = vtowin(a++, selwin)) == 0)
                return;
                return;
-       a++;
-       (void) write(w->ww_pty, a->arg_str, strlen(a->arg_str));
+       while (a->v_type != V_ERR) {
+               if (a->v_type == V_NUM) {
+                       (void) sprintf(buf, "%d", a->v_num);
+                       (void) write(w->ww_pty, buf, strlen(buf));
+               } else
+                       (void) write(w->ww_pty, a->v_str, strlen(a->v_str));
+               if ((++a)->v_type != V_ERR)
+                       (void) write(w->ww_pty, " ", 1);
+       }
 }
 
 struct lcmd_arg arg_close[] = {
 }
 
 struct lcmd_arg arg_close[] = {
-       { "window",     1,      ARG_NUM },
-       { 0,            0,      0 }
+       { "window",     1,      ARG_ANY|ARG_LIST },
+       0
 };
 
 /*ARGSUSED*/
 };
 
 /*ARGSUSED*/
-l_close(v)
+l_close(v, a)
 struct value *v;
 struct value *v;
+register struct value *a;
 {
 {
-       register struct lcmd_arg *a = arg_close;
        struct ww *w;
 
        struct ww *w;
 
-       if (a->arg_vtype == V_ERR)
-               c_close((struct ww *)0);
-       else if ((w = vtowin(&a->arg_val)) != 0)
-               c_close(w);
+       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++)
+                       if ((w = vtowin(a, (struct ww *)0)) != 0)
+                               closewin(w);
 }
 
 struct lcmd_arg arg_cursormodes[] = {
        { "modes",      1,      ARG_NUM },
 }
 
 struct lcmd_arg arg_cursormodes[] = {
        { "modes",      1,      ARG_NUM },
-       { 0,            0,      0 }
+       0
 };
 
 };
 
-l_cursormodes(v)
-register struct value *v;
+l_cursormodes(v, a)
+register struct value *v, *a;
 {
 {
-       register struct lcmd_arg *a = arg_cursormodes;
 
        v->v_type = V_NUM;
        v->v_num = wwcursormodes;
 
        v->v_type = V_NUM;
        v->v_num = wwcursormodes;
-       if (a->arg_vtype != V_ERR)
-               wwsetcursormodes(a->arg_num);
+       if (a->v_type != V_ERR)
+               wwsetcursormodes(a->v_num);
 }
 
 struct lcmd_arg arg_unset[] = {
        { "variable",   1,      ARG_ANY },
 }
 
 struct lcmd_arg arg_unset[] = {
        { "variable",   1,      ARG_ANY },
-       { 0,            0,      0 }
+       0
 };
 
 };
 
-l_unset(v)
-register struct value *v;
+l_unset(v, a)
+register struct value *v, *a;
 {
 {
-       register struct lcmd_arg *a = arg_unset;
-
        v->v_type = V_NUM;
        v->v_type = V_NUM;
-       switch (a->arg_vtype) {
+       switch (a->v_type) {
        case V_ERR:
                v->v_num = -1;
                return;
        case V_NUM:
        case V_ERR:
                v->v_num = -1;
                return;
        case V_NUM:
-               if ((a->arg_str = str_cpy(a->arg_num)) == 0) {
+               if ((a->v_str = str_itoa(a->v_num)) == 0) {
                        error("Out of memory.");
                        v->v_num = -1;
                        return;
                }
                        error("Out of memory.");
                        v->v_num = -1;
                        return;
                }
-               a->arg_vtype = V_STR;
+               a->v_type = V_STR;
                break;
        }
                break;
        }
-       v->v_num = var_unset(a->arg_str);
+       v->v_num = var_unset(a->v_str);
 }
 
 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:
-               error("Window identifier required.");
+               if (w != 0)
+                       return w;
+               error("No window specified.");
                return 0;
        case V_STR:
                return 0;
        case V_STR:
-               error("Number required for window identifier.");
+               error("%s: No such window.", v->v_str);
                return 0;
        }
        if (v->v_num < 1 || v->v_num > NWINDOW
                return 0;
        }
        if (v->v_num < 1 || v->v_num > NWINDOW