2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Edward Wang at The University of California, Berkeley.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 static char sccsid[] = "@(#)parser2.c 8.1 (Berkeley) 6/6/93";
39 static char rcsid[] = "@(#)$FreeBSD$";
48 * name == 0 means we don't have a function name but
49 * want to parse the arguments anyway. flag == 0 in this case.
51 p_function(name, v, flag)
53 register struct value *v;
56 register struct lcmd_tab *c = 0;
57 register struct alias *a = 0;
58 register struct lcmd_arg *ap; /* this arg */
59 struct lcmd_arg *lp = 0; /* list arg */
61 struct value av[LCMD_NARG + 1];
62 register struct value *vp;
65 if (c = lcmd_lookup(name))
67 else if (a = alias_lookup(name))
70 p_error("%s: No such command or alias.", name);
74 for (vp = av; vp < &av[LCMD_NARG + 1]; vp++)
83 if (token == T_COMMA) /* null argument */
86 if (p_expr0(&t, flag) < 0)
88 if (t.v_type == V_ERR)
91 if (token != T_ASSIGN) {
93 c != 0 && (ap = lp) == 0 &&
94 (ap = c->lc_arg + i)->arg_name == 0) {
95 p_error("%s: Too many arguments.", name);
101 if (p_convstr(&t) < 0)
103 tmp = t.v_type == V_STR ? t.v_str : 0;
105 if (p_expr(&t, flag) < 0) {
111 if (t.v_type == V_ERR)
116 p_error("%s: Bad alias syntax.", name);
119 for (ap = c->lc_arg, vp = av;
120 ap != 0 && ap->arg_name != 0 &&
121 (*ap->arg_name == '\0' ||
122 !str_match(tmp, ap->arg_name,
126 if (ap == 0 || ap->arg_name == 0) {
127 p_error("%s: Unknown argument \"%s\".",
138 if (ap->arg_flags & ARG_LIST) {
142 if (vp->v_type != V_ERR) {
144 p_error("%s: Argument %d (%s) duplicated.",
148 p_error("%s: Argument %d duplicated.",
152 } else if (t.v_type == V_ERR) {
154 } else if ((ap->arg_flags&ARG_TYPE) == ARG_NUM &&
156 (ap->arg_flags&ARG_TYPE) == ARG_STR &&
159 p_error("%s: Argument %d (%s) type mismatch.",
163 p_error("%s: Argument %d type mismatch.",
173 if (token == T_COMMA)
181 else if (token != T_EOL && token != T_EOF)
182 flag = 0; /* look for legal follow set */
186 (*c->lc_func)(v, av);
188 if (a->a_flags & A_INUSE)
189 p_error("%s: Recursive alias.", a->a_name);
191 a->a_flags |= A_INUSE;
192 if (dolongcmd(a->a_buf, av, i) < 0)
194 a->a_flags &= ~A_INUSE;
201 for (vp = av; vp < &av[LCMD_NARG]; vp++)
205 for (vp = av; vp < &av[LCMD_NARG]; vp++)
210 p_assign(name, v, flag)
217 if (p_expr(v, flag) < 0) {
224 if (flag && var_set(name, v) == 0) {