147823Sbostic /*-
2*60765Sbostic * Copyright (c) 1980, 1991, 1993
3*60765Sbostic * The Regents of the University of California. All rights reserved.
447823Sbostic *
547823Sbostic * %sccs.include.redist.c%
621931Sdist */
721931Sdist
817510Sedward #ifndef lint
9*60765Sbostic static char sccsid[] = "@(#)exp.c 8.1 (Berkeley) 05/31/93";
1047823Sbostic #endif /* not lint */
111293Sbill
1250028Sbostic #include <sys/types.h>
1350028Sbostic #include <sys/stat.h>
1450028Sbostic #include <stdlib.h>
1550028Sbostic #include <unistd.h>
1650463Schristos #ifndef SHORT_STRINGS
1750463Schristos #include <string.h>
1850463Schristos #endif /* SHORT_STRINGS */
1950033Schristos #if __STDC__
2050033Schristos # include <stdarg.h>
2150033Schristos #else
2250033Schristos # include <varargs.h>
2350033Schristos #endif
2450033Schristos
2550023Sbostic #include "csh.h"
2650023Sbostic #include "extern.h"
271293Sbill
281293Sbill #define IGNORE 1 /* in ignore, it means to ignore value, just parse */
291293Sbill #define NOGLOB 2 /* in ignore, it means not to globone */
301293Sbill
311293Sbill #define ADDOP 1
321293Sbill #define MULOP 2
331293Sbill #define EQOP 4
341293Sbill #define RELOP 8
351293Sbill #define RESTOP 16
361293Sbill #define ANYOP 31
371293Sbill
381293Sbill #define EQEQ 1
391293Sbill #define GTR 2
401293Sbill #define LSS 4
411293Sbill #define NOTEQ 6
421293Sbill #define EQMATCH 7
431293Sbill #define NOTEQMATCH 8
441293Sbill
4550024Schristos static int exp1 __P((Char ***, bool));
4650024Schristos static int exp2 __P((Char ***, bool));
4750024Schristos static int exp2a __P((Char ***, bool));
4850024Schristos static int exp2b __P((Char ***, bool));
4950024Schristos static int exp2c __P((Char ***, bool));
5050024Schristos static Char * exp3 __P((Char ***, bool));
5150024Schristos static Char * exp3a __P((Char ***, bool));
5250024Schristos static Char * exp4 __P((Char ***, bool));
5350024Schristos static Char * exp5 __P((Char ***, bool));
5450024Schristos static Char * exp6 __P((Char ***, bool));
5550024Schristos static void evalav __P((Char **));
5650024Schristos static int isa __P((Char *, int));
5750024Schristos static int egetn __P((Char *));
5849992Sbostic
5949992Sbostic #ifdef EDEBUG
6050024Schristos static void etracc __P((char *, Char *, Char ***));
6150024Schristos static void etraci __P((char *, int, Char ***));
6249992Sbostic #endif
6349992Sbostic
6449992Sbostic int
expr(vp)6551009Schristos expr(vp)
6649992Sbostic register Char ***vp;
671293Sbill {
6849992Sbostic return (exp0(vp, 0));
691293Sbill }
701293Sbill
7149992Sbostic int
exp0(vp,ignore)721293Sbill exp0(vp, ignore)
7349992Sbostic register Char ***vp;
7449992Sbostic bool ignore;
751293Sbill {
7649992Sbostic register int p1 = exp1(vp, ignore);
7749992Sbostic
781293Sbill #ifdef EDEBUG
7949992Sbostic etraci("exp0 p1", p1, vp);
801293Sbill #endif
8149992Sbostic if (**vp && eq(**vp, STRor2)) {
8249992Sbostic register int p2;
831293Sbill
8449992Sbostic (*vp)++;
8549992Sbostic p2 = exp0(vp, (ignore & IGNORE) || p1);
861293Sbill #ifdef EDEBUG
8749992Sbostic etraci("exp0 p2", p2, vp);
881293Sbill #endif
8949992Sbostic return (p1 || p2);
9049992Sbostic }
9149992Sbostic return (p1);
921293Sbill }
931293Sbill
9449992Sbostic static int
exp1(vp,ignore)951293Sbill exp1(vp, ignore)
9649992Sbostic register Char ***vp;
9749992Sbostic bool ignore;
981293Sbill {
9949992Sbostic register int p1 = exp2(vp, ignore);
1001293Sbill
1011293Sbill #ifdef EDEBUG
10249992Sbostic etraci("exp1 p1", p1, vp);
1031293Sbill #endif
10449992Sbostic if (**vp && eq(**vp, STRand2)) {
10549992Sbostic register int p2;
1061293Sbill
10749992Sbostic (*vp)++;
10849992Sbostic p2 = exp1(vp, (ignore & IGNORE) || !p1);
1091293Sbill #ifdef EDEBUG
11049992Sbostic etraci("exp1 p2", p2, vp);
1111293Sbill #endif
11249992Sbostic return (p1 && p2);
11349992Sbostic }
11449992Sbostic return (p1);
1151293Sbill }
1161293Sbill
11749992Sbostic static int
exp2(vp,ignore)1181293Sbill exp2(vp, ignore)
11949992Sbostic register Char ***vp;
12049992Sbostic bool ignore;
1211293Sbill {
12249992Sbostic register int p1 = exp2a(vp, ignore);
1231293Sbill
1241293Sbill #ifdef EDEBUG
12549992Sbostic etraci("exp3 p1", p1, vp);
1261293Sbill #endif
12749992Sbostic if (**vp && eq(**vp, STRor)) {
12849992Sbostic register int p2;
1291293Sbill
13049992Sbostic (*vp)++;
13149992Sbostic p2 = exp2(vp, ignore);
1321293Sbill #ifdef EDEBUG
13349992Sbostic etraci("exp3 p2", p2, vp);
1341293Sbill #endif
13549992Sbostic return (p1 | p2);
13649992Sbostic }
13749992Sbostic return (p1);
1381293Sbill }
1391293Sbill
14049992Sbostic static int
exp2a(vp,ignore)1411293Sbill exp2a(vp, ignore)
14249992Sbostic register Char ***vp;
14349992Sbostic bool ignore;
1441293Sbill {
14549992Sbostic register int p1 = exp2b(vp, ignore);
1461293Sbill
1471293Sbill #ifdef EDEBUG
14849992Sbostic etraci("exp2a p1", p1, vp);
1491293Sbill #endif
15049992Sbostic if (**vp && eq(**vp, STRcaret)) {
15149992Sbostic register int p2;
1521293Sbill
15349992Sbostic (*vp)++;
15449992Sbostic p2 = exp2a(vp, ignore);
1551293Sbill #ifdef EDEBUG
15649992Sbostic etraci("exp2a p2", p2, vp);
1571293Sbill #endif
15849992Sbostic return (p1 ^ p2);
15949992Sbostic }
16049992Sbostic return (p1);
1611293Sbill }
1621293Sbill
16349992Sbostic static int
exp2b(vp,ignore)1641293Sbill exp2b(vp, ignore)
16549992Sbostic register Char ***vp;
16649992Sbostic bool ignore;
1671293Sbill {
16849992Sbostic register int p1 = exp2c(vp, ignore);
1691293Sbill
1701293Sbill #ifdef EDEBUG
17149992Sbostic etraci("exp2b p1", p1, vp);
1721293Sbill #endif
17349992Sbostic if (**vp && eq(**vp, STRand)) {
17449992Sbostic register int p2;
1751293Sbill
17649992Sbostic (*vp)++;
17749992Sbostic p2 = exp2b(vp, ignore);
1781293Sbill #ifdef EDEBUG
17949992Sbostic etraci("exp2b p2", p2, vp);
1801293Sbill #endif
18149992Sbostic return (p1 & p2);
18249992Sbostic }
18349992Sbostic return (p1);
1841293Sbill }
1851293Sbill
18649992Sbostic static int
exp2c(vp,ignore)1871293Sbill exp2c(vp, ignore)
18849992Sbostic register Char ***vp;
18949992Sbostic bool ignore;
1901293Sbill {
19149992Sbostic register Char *p1 = exp3(vp, ignore);
19249992Sbostic register Char *p2;
19349992Sbostic register int i;
1941293Sbill
1951293Sbill #ifdef EDEBUG
19649992Sbostic etracc("exp2c p1", p1, vp);
1971293Sbill #endif
19860237Schristos if ((i = isa(**vp, EQOP)) != 0) {
19949992Sbostic (*vp)++;
20049992Sbostic if (i == EQMATCH || i == NOTEQMATCH)
20149992Sbostic ignore |= NOGLOB;
20249992Sbostic p2 = exp3(vp, ignore);
2031293Sbill #ifdef EDEBUG
20449992Sbostic etracc("exp2c p2", p2, vp);
2051293Sbill #endif
20649992Sbostic if (!(ignore & IGNORE))
20749992Sbostic switch (i) {
2081293Sbill
20949992Sbostic case EQEQ:
21049992Sbostic i = eq(p1, p2);
21149992Sbostic break;
2121293Sbill
21349992Sbostic case NOTEQ:
21449992Sbostic i = !eq(p1, p2);
21549992Sbostic break;
2161293Sbill
21749992Sbostic case EQMATCH:
21849992Sbostic i = Gmatch(p1, p2);
21949992Sbostic break;
2201293Sbill
22149992Sbostic case NOTEQMATCH:
22249992Sbostic i = !Gmatch(p1, p2);
22349992Sbostic break;
22449992Sbostic }
22549992Sbostic xfree((ptr_t) p1);
22649992Sbostic xfree((ptr_t) p2);
2271293Sbill return (i);
22849992Sbostic }
22949992Sbostic i = egetn(p1);
23049992Sbostic xfree((ptr_t) p1);
23149992Sbostic return (i);
2321293Sbill }
2331293Sbill
23449992Sbostic static Char *
exp3(vp,ignore)2351293Sbill exp3(vp, ignore)
23649992Sbostic register Char ***vp;
23749992Sbostic bool ignore;
2381293Sbill {
23949992Sbostic register Char *p1, *p2;
24049992Sbostic register int i;
2411293Sbill
24249992Sbostic p1 = exp3a(vp, ignore);
2431293Sbill #ifdef EDEBUG
24449992Sbostic etracc("exp3 p1", p1, vp);
2451293Sbill #endif
24660237Schristos if ((i = isa(**vp, RELOP)) != 0) {
24749992Sbostic (*vp)++;
24849992Sbostic if (**vp && eq(**vp, STRequal))
24949992Sbostic i |= 1, (*vp)++;
25049992Sbostic p2 = exp3(vp, ignore);
2511293Sbill #ifdef EDEBUG
25249992Sbostic etracc("exp3 p2", p2, vp);
2531293Sbill #endif
25449992Sbostic if (!(ignore & IGNORE))
25549992Sbostic switch (i) {
2561293Sbill
25749992Sbostic case GTR:
25849992Sbostic i = egetn(p1) > egetn(p2);
25949992Sbostic break;
2601293Sbill
26149992Sbostic case GTR | 1:
26249992Sbostic i = egetn(p1) >= egetn(p2);
26349992Sbostic break;
2641293Sbill
26549992Sbostic case LSS:
26649992Sbostic i = egetn(p1) < egetn(p2);
26749992Sbostic break;
2681293Sbill
26949992Sbostic case LSS | 1:
27049992Sbostic i = egetn(p1) <= egetn(p2);
27149992Sbostic break;
27249992Sbostic }
27349992Sbostic xfree((ptr_t) p1);
27449992Sbostic xfree((ptr_t) p2);
27549992Sbostic return (putn(i));
27649992Sbostic }
27749992Sbostic return (p1);
2781293Sbill }
2791293Sbill
28049992Sbostic static Char *
exp3a(vp,ignore)2811293Sbill exp3a(vp, ignore)
28249992Sbostic register Char ***vp;
28349992Sbostic bool ignore;
2841293Sbill {
28549992Sbostic register Char *p1, *p2, *op;
28649992Sbostic register int i;
2871293Sbill
28849992Sbostic p1 = exp4(vp, ignore);
2891293Sbill #ifdef EDEBUG
29049992Sbostic etracc("exp3a p1", p1, vp);
2911293Sbill #endif
29249992Sbostic op = **vp;
29349992Sbostic if (op && any("<>", op[0]) && op[0] == op[1]) {
29449992Sbostic (*vp)++;
29549992Sbostic p2 = exp3a(vp, ignore);
2961293Sbill #ifdef EDEBUG
29749992Sbostic etracc("exp3a p2", p2, vp);
2981293Sbill #endif
29949992Sbostic if (op[0] == '<')
30049992Sbostic i = egetn(p1) << egetn(p2);
30149992Sbostic else
30249992Sbostic i = egetn(p1) >> egetn(p2);
30349992Sbostic xfree((ptr_t) p1);
30449992Sbostic xfree((ptr_t) p2);
30549992Sbostic return (putn(i));
30649992Sbostic }
30749992Sbostic return (p1);
3081293Sbill }
3091293Sbill
31049992Sbostic static Char *
exp4(vp,ignore)3111293Sbill exp4(vp, ignore)
31249992Sbostic register Char ***vp;
31349992Sbostic bool ignore;
3141293Sbill {
31549992Sbostic register Char *p1, *p2;
31649992Sbostic register int i = 0;
3171293Sbill
31849992Sbostic p1 = exp5(vp, ignore);
3191293Sbill #ifdef EDEBUG
32049992Sbostic etracc("exp4 p1", p1, vp);
3211293Sbill #endif
32249992Sbostic if (isa(**vp, ADDOP)) {
32349992Sbostic register Char *op = *(*vp)++;
3241293Sbill
32549992Sbostic p2 = exp4(vp, ignore);
3261293Sbill #ifdef EDEBUG
32749992Sbostic etracc("exp4 p2", p2, vp);
3281293Sbill #endif
32949992Sbostic if (!(ignore & IGNORE))
33049992Sbostic switch (op[0]) {
3311293Sbill
33249992Sbostic case '+':
33349992Sbostic i = egetn(p1) + egetn(p2);
33449992Sbostic break;
3351293Sbill
33649992Sbostic case '-':
33749992Sbostic i = egetn(p1) - egetn(p2);
33849992Sbostic break;
33949992Sbostic }
34049992Sbostic xfree((ptr_t) p1);
34149992Sbostic xfree((ptr_t) p2);
34249992Sbostic return (putn(i));
34349992Sbostic }
34449992Sbostic return (p1);
3451293Sbill }
3461293Sbill
34749992Sbostic static Char *
exp5(vp,ignore)3481293Sbill exp5(vp, ignore)
34949992Sbostic register Char ***vp;
35049992Sbostic bool ignore;
3511293Sbill {
35249992Sbostic register Char *p1, *p2;
35349992Sbostic register int i = 0;
3541293Sbill
35549992Sbostic p1 = exp6(vp, ignore);
3561293Sbill #ifdef EDEBUG
35749992Sbostic etracc("exp5 p1", p1, vp);
3581293Sbill #endif
35949992Sbostic if (isa(**vp, MULOP)) {
36049992Sbostic register Char *op = *(*vp)++;
3611293Sbill
36249992Sbostic p2 = exp5(vp, ignore);
3631293Sbill #ifdef EDEBUG
36449992Sbostic etracc("exp5 p2", p2, vp);
3651293Sbill #endif
36649992Sbostic if (!(ignore & IGNORE))
36749992Sbostic switch (op[0]) {
3681293Sbill
36949992Sbostic case '*':
37049992Sbostic i = egetn(p1) * egetn(p2);
37149992Sbostic break;
3721293Sbill
37349992Sbostic case '/':
37449992Sbostic i = egetn(p2);
37549992Sbostic if (i == 0)
37649992Sbostic stderror(ERR_DIV0);
37749992Sbostic i = egetn(p1) / i;
37849992Sbostic break;
3791293Sbill
38049992Sbostic case '%':
38149992Sbostic i = egetn(p2);
38249992Sbostic if (i == 0)
38349992Sbostic stderror(ERR_MOD0);
38449992Sbostic i = egetn(p1) % i;
38549992Sbostic break;
38649992Sbostic }
38749992Sbostic xfree((ptr_t) p1);
38849992Sbostic xfree((ptr_t) p2);
38949992Sbostic return (putn(i));
39049992Sbostic }
39149992Sbostic return (p1);
3921293Sbill }
3931293Sbill
39449992Sbostic static Char *
exp6(vp,ignore)3951293Sbill exp6(vp, ignore)
39649992Sbostic register Char ***vp;
39749992Sbostic bool ignore;
3981293Sbill {
39949992Sbostic int ccode, i = 0;
40049992Sbostic register Char *cp, *dp, *ep;
4011293Sbill
40249992Sbostic if (**vp == 0)
40349992Sbostic stderror(ERR_NAME | ERR_EXPRESSION);
40449992Sbostic if (eq(**vp, STRbang)) {
40549992Sbostic (*vp)++;
40649992Sbostic cp = exp6(vp, ignore);
4071293Sbill #ifdef EDEBUG
40849992Sbostic etracc("exp6 ! cp", cp, vp);
4091293Sbill #endif
41049992Sbostic i = egetn(cp);
41149992Sbostic xfree((ptr_t) cp);
41249992Sbostic return (putn(!i));
41349992Sbostic }
41449992Sbostic if (eq(**vp, STRtilde)) {
41549992Sbostic (*vp)++;
41649992Sbostic cp = exp6(vp, ignore);
4171293Sbill #ifdef EDEBUG
41849992Sbostic etracc("exp6 ~ cp", cp, vp);
4191293Sbill #endif
42049992Sbostic i = egetn(cp);
42149992Sbostic xfree((ptr_t) cp);
42249992Sbostic return (putn(~i));
42349992Sbostic }
42449992Sbostic if (eq(**vp, STRLparen)) {
42549992Sbostic (*vp)++;
42649992Sbostic ccode = exp0(vp, ignore);
4271293Sbill #ifdef EDEBUG
42849992Sbostic etraci("exp6 () ccode", ccode, vp);
4291293Sbill #endif
43049992Sbostic if (*vp == 0 || **vp == 0 || ***vp != ')')
43149992Sbostic stderror(ERR_NAME | ERR_EXPRESSION);
43249992Sbostic (*vp)++;
43349992Sbostic return (putn(ccode));
43449992Sbostic }
43549992Sbostic if (eq(**vp, STRLbrace)) {
43649992Sbostic register Char **v;
43749992Sbostic struct command faket;
43849992Sbostic Char *fakecom[2];
43949992Sbostic
44049992Sbostic faket.t_dtyp = NODE_COMMAND;
44149992Sbostic faket.t_dflg = 0;
44250024Schristos faket.t_dcar = faket.t_dcdr = faket.t_dspr = NULL;
44349992Sbostic faket.t_dcom = fakecom;
44449992Sbostic fakecom[0] = STRfakecom;
44549992Sbostic fakecom[1] = NULL;
44649992Sbostic (*vp)++;
44749992Sbostic v = *vp;
44849992Sbostic for (;;) {
44949992Sbostic if (!**vp)
45049992Sbostic stderror(ERR_NAME | ERR_MISSING, '}');
45149992Sbostic if (eq(*(*vp)++, STRRbrace))
45249992Sbostic break;
4531293Sbill }
45449992Sbostic if (ignore & IGNORE)
45549992Sbostic return (Strsave(STRNULL));
45649992Sbostic psavejob();
45749992Sbostic if (pfork(&faket, -1) == 0) {
45849992Sbostic *--(*vp) = 0;
45949992Sbostic evalav(v);
46049992Sbostic exitstat();
46149992Sbostic }
46249992Sbostic pwait();
46349992Sbostic prestjob();
4641293Sbill #ifdef EDEBUG
46549992Sbostic etraci("exp6 {} status", egetn(value(STRstatus)), vp);
4661293Sbill #endif
46749992Sbostic return (putn(egetn(value(STRstatus)) == 0));
46849992Sbostic }
46949992Sbostic if (isa(**vp, ANYOP))
47049992Sbostic return (Strsave(STRNULL));
47149992Sbostic cp = *(*vp)++;
47249992Sbostic if (*cp == '-' && any("erwxfdzopls", cp[1])) {
47349992Sbostic struct stat stb;
4741293Sbill
47549992Sbostic if (cp[2] != '\0')
47649992Sbostic stderror(ERR_NAME | ERR_FILEINQ);
47749992Sbostic /*
47849992Sbostic * Detect missing file names by checking for operator in the file name
47949992Sbostic * position. However, if an operator name appears there, we must make
48049992Sbostic * sure that there's no file by that name (e.g., "/") before announcing
48149992Sbostic * an error. Even this check isn't quite right, since it doesn't take
48249992Sbostic * globbing into account.
48349992Sbostic */
48449992Sbostic if (isa(**vp, ANYOP) && stat(short2str(**vp), &stb))
48549992Sbostic stderror(ERR_NAME | ERR_FILENAME);
4861293Sbill
48749992Sbostic dp = *(*vp)++;
48849992Sbostic if (ignore & IGNORE)
48949992Sbostic return (Strsave(STRNULL));
49049992Sbostic ep = globone(dp, G_ERROR);
49149992Sbostic switch (cp[1]) {
4921293Sbill
49349992Sbostic case 'r':
49449992Sbostic i = !access(short2str(ep), R_OK);
49549992Sbostic break;
4961293Sbill
49749992Sbostic case 'w':
49849992Sbostic i = !access(short2str(ep), W_OK);
49949992Sbostic break;
5001293Sbill
50149992Sbostic case 'x':
50249992Sbostic i = !access(short2str(ep), X_OK);
50349992Sbostic break;
5041293Sbill
50549992Sbostic default:
50649992Sbostic if (
50749992Sbostic #ifdef S_IFLNK
50849992Sbostic cp[1] == 'l' ? lstat(short2str(ep), &stb) :
50949992Sbostic #endif
51049992Sbostic stat(short2str(ep), &stb)) {
51149992Sbostic xfree((ptr_t) ep);
51249992Sbostic return (Strsave(STR0));
51349992Sbostic }
51449992Sbostic switch (cp[1]) {
5151293Sbill
51649992Sbostic case 'f':
51749992Sbostic i = S_ISREG(stb.st_mode);
51849992Sbostic break;
5191293Sbill
52049992Sbostic case 'd':
52149992Sbostic i = S_ISDIR(stb.st_mode);
52249992Sbostic break;
5231293Sbill
52449992Sbostic case 'p':
52549992Sbostic #ifdef S_ISFIFO
52649992Sbostic i = S_ISFIFO(stb.st_mode);
52749992Sbostic #else
52849992Sbostic i = 0;
52949992Sbostic #endif
53049992Sbostic break;
5311293Sbill
53249992Sbostic case 'l':
53349992Sbostic #ifdef S_ISLNK
53449992Sbostic i = S_ISLNK(stb.st_mode);
53549992Sbostic #else
53649992Sbostic i = 0;
5371293Sbill #endif
53849992Sbostic break;
53949992Sbostic
54049992Sbostic case 's':
54149992Sbostic #ifdef S_ISSOCK
54249992Sbostic i = S_ISSOCK(stb.st_mode);
54349992Sbostic #else
54449992Sbostic i = 0;
54549992Sbostic #endif
54649992Sbostic break;
54749992Sbostic
54849992Sbostic case 'z':
54949992Sbostic i = stb.st_size == 0;
55049992Sbostic break;
55149992Sbostic
55249992Sbostic case 'e':
55349992Sbostic i = 1;
55449992Sbostic break;
55549992Sbostic
55649992Sbostic case 'o':
55749992Sbostic i = stb.st_uid == uid;
55849992Sbostic break;
55949992Sbostic }
5601293Sbill }
5611293Sbill #ifdef EDEBUG
56249992Sbostic etraci("exp6 -? i", i, vp);
5631293Sbill #endif
56449992Sbostic xfree((ptr_t) ep);
56549992Sbostic return (putn(i));
56649992Sbostic }
56749992Sbostic #ifdef EDEBUG
56849992Sbostic etracc("exp6 default", cp, vp);
56949992Sbostic #endif
57049992Sbostic return (ignore & NOGLOB ? Strsave(cp) : globone(cp, G_ERROR));
5711293Sbill }
5721293Sbill
57349992Sbostic static void
evalav(v)5741293Sbill evalav(v)
57549992Sbostic register Char **v;
5761293Sbill {
57749992Sbostic struct wordent paraml1;
57849992Sbostic register struct wordent *hp = ¶ml1;
57949992Sbostic struct command *t;
58049992Sbostic register struct wordent *wdp = hp;
5811293Sbill
58249992Sbostic set(STRstatus, Strsave(STR0));
58349992Sbostic hp->prev = hp->next = hp;
58449992Sbostic hp->word = STRNULL;
58549992Sbostic while (*v) {
58649992Sbostic register struct wordent *new =
58749992Sbostic (struct wordent *) xcalloc(1, sizeof *wdp);
58849992Sbostic
58949992Sbostic new->prev = wdp;
59049992Sbostic new->next = hp;
59149992Sbostic wdp->next = new;
59249992Sbostic wdp = new;
59349992Sbostic wdp->word = Strsave(*v++);
59449992Sbostic }
59549992Sbostic hp->prev = wdp;
59649992Sbostic alias(¶ml1);
59749992Sbostic t = syntax(paraml1.next, ¶ml1, 0);
59849992Sbostic if (seterr)
59949992Sbostic stderror(ERR_OLD);
60050023Sbostic execute(t, -1, NULL, NULL);
60149992Sbostic freelex(¶ml1), freesyn(t);
6021293Sbill }
6031293Sbill
60449992Sbostic static int
isa(cp,what)6051293Sbill isa(cp, what)
60649992Sbostic register Char *cp;
60749992Sbostic register int what;
6081293Sbill {
60949992Sbostic if (cp == 0)
61049992Sbostic return ((what & RESTOP) != 0);
61149992Sbostic if (cp[1] == 0) {
61249992Sbostic if (what & ADDOP && (*cp == '+' || *cp == '-'))
61349992Sbostic return (1);
61449992Sbostic if (what & MULOP && (*cp == '*' || *cp == '/' || *cp == '%'))
61549992Sbostic return (1);
61649992Sbostic if (what & RESTOP && (*cp == '(' || *cp == ')' || *cp == '!' ||
61749992Sbostic *cp == '~' || *cp == '^' || *cp == '"'))
61849992Sbostic return (1);
61949992Sbostic }
62049992Sbostic else if (cp[2] == 0) {
62149992Sbostic if (what & RESTOP) {
62249992Sbostic if (cp[0] == '|' && cp[1] == '&')
62349992Sbostic return (1);
62449992Sbostic if (cp[0] == '<' && cp[1] == '<')
62549992Sbostic return (1);
62649992Sbostic if (cp[0] == '>' && cp[1] == '>')
62749992Sbostic return (1);
6281293Sbill }
62949992Sbostic if (what & EQOP) {
63049992Sbostic if (cp[0] == '=') {
63149992Sbostic if (cp[1] == '=')
63249992Sbostic return (EQEQ);
63349992Sbostic if (cp[1] == '~')
63449992Sbostic return (EQMATCH);
63549992Sbostic }
63649992Sbostic else if (cp[0] == '!') {
63749992Sbostic if (cp[1] == '=')
63849992Sbostic return (NOTEQ);
63949992Sbostic if (cp[1] == '~')
64049992Sbostic return (NOTEQMATCH);
64149992Sbostic }
6421293Sbill }
64349992Sbostic }
64449992Sbostic if (what & RELOP) {
64549992Sbostic if (*cp == '<')
64649992Sbostic return (LSS);
64749992Sbostic if (*cp == '>')
64849992Sbostic return (GTR);
64949992Sbostic }
65049992Sbostic return (0);
6511293Sbill }
6521293Sbill
65349992Sbostic static int
egetn(cp)6541293Sbill egetn(cp)
65549992Sbostic register Char *cp;
6561293Sbill {
65749992Sbostic if (*cp && *cp != '-' && !Isdigit(*cp))
65849992Sbostic stderror(ERR_NAME | ERR_EXPRESSION);
65949992Sbostic return (getn(cp));
6601293Sbill }
6611293Sbill
6621293Sbill /* Phew! */
6631293Sbill
6641293Sbill #ifdef EDEBUG
66549992Sbostic static void
etraci(str,i,vp)6661293Sbill etraci(str, i, vp)
66749992Sbostic char *str;
66849992Sbostic int i;
66949992Sbostic Char ***vp;
6701293Sbill {
67150439Schristos (void) fprintf(csherr, "%s=%d\t", str, i);
67250439Schristos blkpr(csherr, *vp);
67350439Schristos (void) fprintf(csherr, "\n");
6741293Sbill }
67549992Sbostic static void
etracc(str,cp,vp)6761293Sbill etracc(str, cp, vp)
67749992Sbostic char *str;
67849992Sbostic Char *cp;
67949992Sbostic Char ***vp;
6801293Sbill {
68151589Schristos (void) fprintf(csherr, "%s=%s\t", str, vis_str(cp));
68250439Schristos blkpr(csherr, *vp);
68350439Schristos (void) fprintf(csherr, "\n");
6841293Sbill }
6851293Sbill #endif
686