-/* $OpenBSD: exp.c,v 1.13 2015/10/26 15:01:15 naddy Exp $ */
+/* $OpenBSD: exp.c,v 1.14 2015/10/26 21:57:42 naddy Exp $ */
/* $NetBSD: exp.c,v 1.6 1995/03/21 09:02:51 cgd Exp $ */
/*-
static int isa(Char *, int);
static int egetn(Char *);
-#ifdef EDEBUG
-static void etracc(char *, Char *, Char ***);
-static void etraci(char *, int, Char ***);
-#endif
-
int
expr(Char ***vp)
{
{
int p1 = exp1(vp, ignore);
-#ifdef EDEBUG
- etraci("exp0 p1", p1, vp);
-#endif
if (**vp && eq(**vp, STRor2)) {
int p2;
(*vp)++;
p2 = exp0(vp, (ignore & IGNORE) || p1);
-#ifdef EDEBUG
- etraci("exp0 p2", p2, vp);
-#endif
return (p1 || p2);
}
return (p1);
{
int p1 = exp2_(vp, ignore);
-#ifdef EDEBUG
- etraci("exp1 p1", p1, vp);
-#endif
if (**vp && eq(**vp, STRand2)) {
int p2;
(*vp)++;
p2 = exp1(vp, (ignore & IGNORE) || !p1);
-#ifdef EDEBUG
- etraci("exp1 p2", p2, vp);
-#endif
return (p1 && p2);
}
return (p1);
{
int p1 = exp2a(vp, ignore);
-#ifdef EDEBUG
- etraci("exp3 p1", p1, vp);
-#endif
if (**vp && eq(**vp, STRor)) {
int p2;
(*vp)++;
p2 = exp2_(vp, ignore);
-#ifdef EDEBUG
- etraci("exp3 p2", p2, vp);
-#endif
return (p1 | p2);
}
return (p1);
{
int p1 = exp2b(vp, ignore);
-#ifdef EDEBUG
- etraci("exp2a p1", p1, vp);
-#endif
if (**vp && eq(**vp, STRcaret)) {
int p2;
(*vp)++;
p2 = exp2a(vp, ignore);
-#ifdef EDEBUG
- etraci("exp2a p2", p2, vp);
-#endif
return (p1 ^ p2);
}
return (p1);
{
int p1 = exp2c(vp, ignore);
-#ifdef EDEBUG
- etraci("exp2b p1", p1, vp);
-#endif
if (**vp && eq(**vp, STRand)) {
int p2;
(*vp)++;
p2 = exp2b(vp, ignore);
-#ifdef EDEBUG
- etraci("exp2b p2", p2, vp);
-#endif
return (p1 & p2);
}
return (p1);
Char *p2;
int i;
-#ifdef EDEBUG
- etracc("exp2c p1", p1, vp);
-#endif
if ((i = isa(**vp, EQOP)) != 0) {
(*vp)++;
if (i == EQMATCH || i == NOTEQMATCH)
ignore |= NOGLOB;
p2 = exp3(vp, ignore);
-#ifdef EDEBUG
- etracc("exp2c p2", p2, vp);
-#endif
if (!(ignore & IGNORE))
switch (i) {
int i;
p1 = exp3a(vp, ignore);
-#ifdef EDEBUG
- etracc("exp3 p1", p1, vp);
-#endif
if ((i = isa(**vp, RELOP)) != 0) {
(*vp)++;
if (**vp && eq(**vp, STRequal))
i |= 1, (*vp)++;
p2 = exp3(vp, ignore);
-#ifdef EDEBUG
- etracc("exp3 p2", p2, vp);
-#endif
if (!(ignore & IGNORE))
switch (i) {
int i;
p1 = exp4(vp, ignore);
-#ifdef EDEBUG
- etracc("exp3a p1", p1, vp);
-#endif
op = **vp;
if (op && any("<>", op[0]) && op[0] == op[1]) {
(*vp)++;
p2 = exp3a(vp, ignore);
-#ifdef EDEBUG
- etracc("exp3a p2", p2, vp);
-#endif
if (op[0] == '<')
i = egetn(p1) << egetn(p2);
else
int i = 0;
p1 = exp5(vp, ignore);
-#ifdef EDEBUG
- etracc("exp4 p1", p1, vp);
-#endif
if (isa(**vp, ADDOP)) {
Char *op = *(*vp)++;
p2 = exp4(vp, ignore);
-#ifdef EDEBUG
- etracc("exp4 p2", p2, vp);
-#endif
if (!(ignore & IGNORE))
switch (op[0]) {
int i = 0, l;
p1 = exp6(vp, ignore);
-#ifdef EDEBUG
- etracc("exp5 p1", p1, vp);
-#endif
if (isa(**vp, MULOP)) {
Char *op = *(*vp)++;
p2 = exp5(vp, ignore);
-#ifdef EDEBUG
- etracc("exp5 p2", p2, vp);
-#endif
if (!(ignore & IGNORE))
switch (op[0]) {
if (eq(**vp, STRbang)) {
(*vp)++;
cp = exp6(vp, ignore);
-#ifdef EDEBUG
- etracc("exp6 ! cp", cp, vp);
-#endif
i = egetn(cp);
xfree(cp);
return (putn(!i));
if (eq(**vp, STRtilde)) {
(*vp)++;
cp = exp6(vp, ignore);
-#ifdef EDEBUG
- etracc("exp6 ~ cp", cp, vp);
-#endif
i = egetn(cp);
xfree(cp);
return (putn(~i));
if (eq(**vp, STRLparen)) {
(*vp)++;
ccode = exp0(vp, ignore);
-#ifdef EDEBUG
- etraci("exp6 () ccode", ccode, vp);
-#endif
if (*vp == 0 || **vp == 0 || ***vp != ')')
stderror(ERR_NAME | ERR_EXPRESSION);
(*vp)++;
}
pwait();
prestjob();
-#ifdef EDEBUG
- etraci("exp6 {} status", egetn(value(STRstatus)), vp);
-#endif
return (putn(egetn(value(STRstatus)) == 0));
}
if (isa(**vp, ANYOP))
break;
}
}
-#ifdef EDEBUG
- etraci("exp6 -? i", i, vp);
-#endif
xfree(ep);
return (putn(i));
}
-#ifdef EDEBUG
- etracc("exp6 default", cp, vp);
-#endif
return (ignore & NOGLOB ? Strsave(cp) : globone(cp, G_ERROR));
}
}
/* Phew! */
-
-#ifdef EDEBUG
-static void
-etraci(char *str, int i, Char ***vp)
-{
- (void) fprintf(csherr, "%s=%d\t", str, i);
- blkpr(csherr, *vp);
- (void) fprintf(csherr, "\n");
-}
-static void
-etracc(char *str, Char *cp, Char ***vp)
-{
- (void) fprintf(csherr, "%s=%s\t", str, vis_str(cp));
- blkpr(csherr, *vp);
- (void) fprintf(csherr, "\n");
-}
-#endif