new ARG_LIST flag for commands
authorEdward Wang <edward@ucbvax.Berkeley.EDU>
Fri, 13 Jul 1984 04:38:59 +0000 (20:38 -0800)
committerEdward Wang <edward@ucbvax.Berkeley.EDU>
Fri, 13 Jul 1984 04:38:59 +0000 (20:38 -0800)
SCCS-vsn: usr.bin/window/lcmd.c 3.21
SCCS-vsn: usr.bin/window/lcmd1.c 3.26
SCCS-vsn: usr.bin/window/var.c 3.7
SCCS-vsn: usr.bin/window/parser2.c 3.8
SCCS-vsn: usr.bin/window/lcmd.h 3.4
SCCS-vsn: usr.bin/window/lcmd2.c 3.7

usr/src/usr.bin/window/lcmd.c
usr/src/usr.bin/window/lcmd.h
usr/src/usr.bin/window/lcmd1.c
usr/src/usr.bin/window/lcmd2.c
usr/src/usr.bin/window/parser2.c
usr/src/usr.bin/window/var.c

index c766fc3..dc6fad3 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)lcmd.c     3.20 %G%";
+static char sccsid[] = "@(#)lcmd.c     3.21 %G%";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -34,6 +34,7 @@ struct lcmd_arg arg_escape[];
 struct lcmd_arg arg_foreground[];
 struct lcmd_arg arg_label[];
 struct lcmd_arg arg_nline[];
 struct lcmd_arg arg_foreground[];
 struct lcmd_arg arg_label[];
 struct lcmd_arg arg_nline[];
+struct lcmd_arg arg_close[];
 struct lcmd_arg arg_select[];
 struct lcmd_arg arg_shell[];
 struct lcmd_arg arg_source[];
 struct lcmd_arg arg_select[];
 struct lcmd_arg arg_shell[];
 struct lcmd_arg arg_source[];
@@ -42,13 +43,14 @@ struct lcmd_arg arg_time[];
 struct lcmd_arg arg_unalias[];
 struct lcmd_arg arg_unset[];
 struct lcmd_arg arg_window[];
 struct lcmd_arg arg_unalias[];
 struct lcmd_arg arg_unset[];
 struct lcmd_arg arg_window[];
+struct lcmd_arg arg_write[];
 struct lcmd_arg arg_null[] = 0;
 
 struct lcmd_tab lcmd_tab[] = {
        "%",            1,      l_select,       arg_select,
        "alias",        1,      l_alias,        arg_alias,
        "buffer",       2,      l_nline,        arg_nline,
 struct lcmd_arg arg_null[] = 0;
 
 struct lcmd_tab lcmd_tab[] = {
        "%",            1,      l_select,       arg_select,
        "alias",        1,      l_alias,        arg_alias,
        "buffer",       2,      l_nline,        arg_nline,
-       "close",        2,      l_close,        0,
+       "close",        2,      l_close,        arg_close,
        "cursormodes",  2,      l_cursormodes,  arg_cursormodes,
        "debug",        1,      l_debug,        arg_debug,
        "escape",       1,      l_escape,       arg_escape,
        "cursormodes",  2,      l_cursormodes,  arg_cursormodes,
        "debug",        1,      l_debug,        arg_debug,
        "escape",       1,      l_escape,       arg_escape,
@@ -66,7 +68,7 @@ struct lcmd_tab lcmd_tab[] = {
        "unset",        3,      l_unset,        arg_unset,
        "variable",     1,      l_variable,     arg_null,
        "window",       2,      l_window,       arg_window,
        "unset",        3,      l_unset,        arg_unset,
        "variable",     1,      l_variable,     arg_null,
        "window",       2,      l_window,       arg_window,
-       "write",        2,      l_write,        0,
+       "write",        2,      l_write,        arg_write,
        0
 };
 
        0
 };
 
index d7681e3..b68080a 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * @(#)lcmd.h  3.3 %G%
+ * @(#)lcmd.h  3.4 %G%
  */
 
 #define LCMD_NARG 20                   /* maximum number of arguments */
  */
 
 #define LCMD_NARG 20                   /* maximum number of arguments */
@@ -14,11 +14,14 @@ struct lcmd_tab {
 struct lcmd_arg {
        char *arg_name;
        int arg_minlen;
 struct lcmd_arg {
        char *arg_name;
        int arg_minlen;
-       char arg_type;
+       int arg_flags;
 };
 
 };
 
-#define ARG_ANY 0
-#define ARG_NUM 1
-#define ARG_STR 2
+       /* arg_flags bits */
+#define ARG_TYPE       0x0f            /* type of arg */
+#define ARG_ANY                0x00            /* any type */
+#define ARG_NUM                0x01            /* must be a number */
+#define ARG_STR                0x02            /* must be a string */
+#define ARG_LIST       0x10            /* this arg can be a list */
 
 struct lcmd_tab *lcmd_lookup();
 
 struct lcmd_tab *lcmd_lookup();
index a03b91d..03f21d9 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)lcmd1.c    3.25 %G%";
+static char sccsid[] = "@(#)lcmd1.c    3.26 %G%";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -9,52 +9,69 @@ static char sccsid[] = "@(#)lcmd1.c   3.25 %G%";
 #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 },
        { "mapnl",      1,      ARG_ANY },
        { "pty",        1,      ARG_ANY },
        { "frame",      1,      ARG_ANY },
        { "mapnl",      1,      ARG_ANY },
+       { "shell",      1,      ARG_ANY|ARG_LIST },
        0
 };
 
 l_window(v, a)
        0
 };
 
 l_window(v, a)
-register struct value *v, *a;
+struct value *v;
+register struct value *a;
 {
 {
-       register struct ww *w;
+       struct ww *w;
        int col, row, ncol, nrow, id, nline;
        char *label;
        char haspty, hasframe, mapnl;
        char *shf, **sh;
        char *argv[sizeof shell / sizeof *shell];
        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[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;
+       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;
+       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++) {
+                       if (a->v_type == V_NUM && p_convstr(a->v_num) < 0) {
+                               p_memerror();
+                               return;
+                       }
+                       *pp = a->v_str;
+               }
+               *pp = 0;
+               shf = *(sh = argv);
+               if (*sh = rindex(shf, '/'))
+                       (*sh)++;
+               else
+                       *sh = shf;
        } else {
                sh = shell;
                shf = shellfile;
        }
        } else {
                sh = shell;
                shf = shellfile;
        }
-       if ((haspty = vtobool(a + 7, 1, -1)) < 0)
-               return;
-       if ((hasframe = vtobool(a + 8, 1, -1)) < 0)
-               return;
-       if ((mapnl = vtobool(a + 9, !haspty, -1)) < 0)
-               return;
        if ((w = openwin(id, row, col, nrow, ncol, nline, label, haspty,
            hasframe, shf, sh)) == 0)
                return;
        if ((w = openwin(id, row, col, nrow, ncol, nline, label, haspty,
            hasframe, shf, sh)) == 0)
                return;
@@ -203,6 +220,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;
@@ -224,6 +247,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;
index 4e002ed..909c88f 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)lcmd2.c    3.6 %G%";
+static char sccsid[] = "@(#)lcmd2.c    3.7 %G%";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -191,14 +191,15 @@ register struct var *r;
 }
 
 struct lcmd_arg arg_shell[] = {
 }
 
 struct lcmd_arg arg_shell[] = {
-       { "shell",      1,      ARG_STR },
+       { "",   0,              ARG_ANY|ARG_LIST },
        0
 };
 
 l_shell(v, a)
        0
 };
 
 l_shell(v, a)
-struct value *v, *a;
+       struct value *v, *a;
 {
 {
-       register char **pp;
+       register char **pp, *p;
+       register struct value *vp;
 
        if (a->v_type == V_ERR) {
                if ((v->v_str = str_cpy(shellfile)) != 0)
 
        if (a->v_type == V_ERR) {
                if ((v->v_str = str_cpy(shellfile)) != 0)
@@ -207,15 +208,19 @@ struct value *v, *a;
        }
        if (v->v_str = shellfile) {
                v->v_type = V_STR;
        }
        if (v->v_str = shellfile) {
                v->v_type = V_STR;
-               for (pp = shell + 1; *pp; pp++)
+               for (pp = shell + 1; *pp; pp++) {
                        str_free(*pp);
                        str_free(*pp);
+                       *pp = 0;
+               }
        }
        }
-       if (mkargv(a->v_str, shell, sizeof shell / sizeof *shell) < 0)
-               *shell = 0;
-       for (pp = shell; *pp; pp++)
-               if ((*pp = str_cpy(*pp)) == 0) {
+       for (pp = shell, vp = a;
+            vp->v_type != V_ERR && pp < &shell[sizeof shell/sizeof *shell-1];
+            pp++, vp++)
+               if ((*pp = vp->v_type == V_STR ?
+                    str_cpy(vp->v_str) : str_itoa(vp->v_num)) == 0) {
                        /* just leave shell[] the way it is */
                        p_memerror();
                        /* just leave shell[] the way it is */
                        p_memerror();
+                       break;
                }
        if (shellfile = *shell)
                if (*shell = rindex(shellfile, '/'))
                }
        if (shellfile = *shell)
                if (*shell = rindex(shellfile, '/'))
@@ -225,13 +230,13 @@ struct value *v, *a;
 }
 
 struct lcmd_arg arg_alias[] = {
 }
 
 struct lcmd_arg arg_alias[] = {
-       { "name",       1,      ARG_STR },
-       { "string",     1,      ARG_STR },
+       { "",   0,              ARG_STR },
+       { "",   0,              ARG_STR|ARG_LIST },
        0
 };
 
 l_alias(v, a)
        0
 };
 
 l_alias(v, a)
-struct value *v, *a;
+       struct value *v, *a;
 {
        if (a->v_type == V_ERR) {
                register struct ww *w;
 {
        if (a->v_type == V_ERR) {
                register struct ww *w;
@@ -254,10 +259,29 @@ struct value *v, *a;
                        }
                        v->v_type = V_STR;
                }
                        }
                        v->v_type = V_STR;
                }
-               if (a[1].v_type == V_STR &&
-                   alias_set(a[0].v_str, a[1].v_str) == 0) {
-                       p_memerror();
-                       return;
+               if (a[1].v_type == V_STR) {
+                       register struct value *vp;
+                       register char *p, *q;
+                       char *str;
+                       register n;
+
+                       for (n = 0, vp = a + 1; vp->v_type != V_ERR; vp++, n++)
+                               for (p = vp->v_str; *p; p++, n++)
+                                       ;
+                       if ((str = str_alloc(n)) == 0) {
+                               p_memerror();
+                               return;
+                       }
+                       for (q = str, vp = a + 1; vp->v_type != V_ERR;
+                            vp++, q[-1] = ' ')
+                               for (p = vp->v_str; *q++ = *p++;)
+                                       ;
+                       q[-1] = 0;
+                       if ((ap = alias_set(a[0].v_str, 0)) == 0) {
+                               p_memerror();
+                               return;
+                       }
+                       ap->a_buf = str;
                }
        }
 }
                }
        }
 }
index a9e14fd..cc1a42b 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)parser2.c  3.7 %G%";
+static char sccsid[] = "@(#)parser2.c  3.8 %G%";
 #endif
 
 #include "parser.h"
 #endif
 
 #include "parser.h"
@@ -18,7 +18,8 @@ register struct value *v;
        struct value t;
        register struct lcmd_tab *c = 0;
        register struct alias *a = 0;
        struct value t;
        register struct lcmd_tab *c = 0;
        register struct alias *a = 0;
-       register struct lcmd_arg *ap;
+       register struct lcmd_arg *ap;           /* this arg */
+       struct lcmd_arg *lp = 0;                /* list arg */
        register i;
        struct value av[LCMD_NARG + 1];
        register struct value *vp;
        register i;
        struct value av[LCMD_NARG + 1];
        register struct value *vp;
@@ -36,25 +37,15 @@ register struct value *v;
        for (vp = av; vp < &av[LCMD_NARG + 1]; vp++)
                vp->v_type = V_ERR;
 
        for (vp = av; vp < &av[LCMD_NARG + 1]; vp++)
                vp->v_type = V_ERR;
 
-       for (i = 0;;) {
-               ap = 0;
-               vp = 0;
-               if (p_expr0(&t, flag) < 0)
-                       if (!p_synerred() && token == T_MUL) {
-                               if (c != 0)
-                                       if (c->lc_arg[i].arg_name == 0)
-                                               p_error("%s: Too many arguments.", name);
-                                       else
-                                               i++;
-                               (void) s_gettok();
-                               continue;
-                       } else
-                               break;
+       for (i = 0; p_expr0(&t, flag) >= 0;) {
                if (t.v_type == V_ERR)
                        flag = 0;
                if (t.v_type == V_ERR)
                        flag = 0;
+               ap = 0;
+               vp = 0;
                if (token != T_ASSIGN) {
                if (token != T_ASSIGN) {
-                       if (i >= LCMD_NARG || c != 0 && c->lc_arg != 0
-                           && (ap = c->lc_arg + i)->arg_name == 0) {
+                       if (i >= LCMD_NARG ||
+                           c != 0 && (ap = lp) == 0 &&
+                           (ap = c->lc_arg + i)->arg_name == 0) {
                                p_error("%s: Too many arguments.", name);
                                flag = 0;
                        } else
                                p_error("%s: Too many arguments.", name);
                                flag = 0;
                        } else
@@ -81,8 +72,9 @@ register struct value *v;
                                } else {
                                        for (ap = c->lc_arg, vp = av;
                                             ap != 0 && ap->arg_name != 0 &&
                                } else {
                                        for (ap = c->lc_arg, vp = av;
                                             ap != 0 && ap->arg_name != 0 &&
-                                               !str_match(tmp, ap->arg_name,
-                                                       ap->arg_minlen);
+                                            (*ap->arg_name == '\0' ||
+                                             !str_match(tmp, ap->arg_name,
+                                                       ap->arg_minlen));
                                             ap++, vp++)
                                                ;
                                        if (ap == 0 || ap->arg_name == 0) {
                                             ap++, vp++)
                                                ;
                                        if (ap == 0 || ap->arg_name == 0) {
@@ -97,19 +89,33 @@ register struct value *v;
                        }
                }
                if (ap != 0) {
                        }
                }
                if (ap != 0) {
+                       if (ap->arg_flags & ARG_LIST) {
+                               i = vp - av + 1;
+                               lp = ap;
+                       }
                        if (vp->v_type != V_ERR) {
                        if (vp->v_type != V_ERR) {
-                               p_error("%s: Argument %d (%s) duplicated.",
-                                       name, ap - c->lc_arg + 1,
-                                       ap->arg_name);
+                               if (*ap->arg_name)
+                                       p_error("%s: Argument %d (%s) duplicated.",
+                                               name, vp - av + 1,
+                                               ap->arg_name);
+                               else
+                                       p_error("%s: Argument %d duplicated.",
+                                               name, vp - av + 1);
                                flag = 0;
                                vp = 0;
                        } else if (t.v_type == V_ERR) {
                                /* do nothing */
                                flag = 0;
                                vp = 0;
                        } else if (t.v_type == V_ERR) {
                                /* do nothing */
-                       } else if (ap->arg_type == ARG_NUM && t.v_type != V_NUM
-                           || ap->arg_type == ARG_STR && t.v_type != V_STR) {
-                               p_error("%s: Argument %d (%s) type mismatch.",
-                                       name, ap - c->lc_arg + 1,
-                                       ap->arg_name);
+                       } else if ((ap->arg_flags&ARG_TYPE) == ARG_NUM &&
+                                  t.v_type != V_NUM ||
+                                  (ap->arg_flags&ARG_TYPE) == ARG_STR &&
+                                  t.v_type != V_STR) {
+                               if (*ap->arg_name)
+                                       p_error("%s: Argument %d (%s) type mismatch.",
+                                               name, vp - av + 1,
+                                               ap->arg_name);
+                               else
+                                       p_error("%s: Argument %d type mismatch.",
+                                               name, vp - av + 1);
                                flag = 0;
                                vp = 0;
                        }
                                flag = 0;
                                vp = 0;
                        }
index 21a85d4..b5f99d6 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)var.c      3.6 %G%";
+static char sccsid[] = "@(#)var.c      3.7 %G%";
 #endif
 
 #include "value.h"
 #endif
 
 #include "value.h"
@@ -20,7 +20,8 @@ struct value *v;
 
        /* do this first, easier to recover */
        val = *v;
 
        /* do this first, easier to recover */
        val = *v;
-       if (val.v_type == V_STR && (val.v_str = str_cpy(val.v_str)) == 0)
+       if (val.v_type == V_STR && val.v_str != 0 &&
+           (val.v_str = str_cpy(val.v_str)) == 0)
                return 0;
        if (*(p = var_lookup1(head, name)) == 0) {
                r = (struct var *) malloc(sizeof (struct var));
                return 0;
        if (*(p = var_lookup1(head, name)) == 0) {
                r = (struct var *) malloc(sizeof (struct var));