static int e3(void) { int p1; register unsigned char *a; unsigned char *p2; long long ll_1, ll_2; a = nxtarg(0); if (eq(a, "(")) { p1 = sexp(); if (!eq(nxtarg(0), ")")) failed("test",") expected"); return(p1); } p2 = nxtarg(1); ap--; if ((p2 == 0) || (!eq(p2, "=") && !eq(p2, "!="))) { if (eq(a, "-r")) return(chk_access(nxtarg(0), S_IREAD, 0) == 0); if (eq(a, "-w")) return(chk_access(nxtarg(0), S_IWRITE, 0) == 0); if (eq(a, "-x")) return(chk_access(nxtarg(0), S_IEXEC, 0) == 0); #ifdef SUS if (eq(a, "-e")) return(access(nxtarg(0), F_OK) == 0); if (eq(a, "-S")) return(filtyp(nxtarg(0), S_IFSOCK)); if (eq(a, "!")) return(!e3()); #endif /* SUS */ if (eq(a, "-d")) return(filtyp(nxtarg(0), S_IFDIR)); if (eq(a, "-c")) return(filtyp(nxtarg(0), S_IFCHR)); if (eq(a, "-b")) return(filtyp(nxtarg(0), S_IFBLK)); if (eq(a, "-f")) if (ucb_builtins) { struct stat statb; return(stat((char *)nxtarg(0), &statb) >= 0 && (statb.st_mode & S_IFMT) != S_IFDIR); } else return(filtyp(nxtarg(0), S_IFREG)); if (eq(a, "-u")) return(ftype(nxtarg(0), S_ISUID)); if (eq(a, "-g")) return(ftype(nxtarg(0), S_ISGID)); if (eq(a, "-k")) return(ftype(nxtarg(0), S_ISVTX)); if (eq(a, "-p")) return(filtyp(nxtarg(0), S_IFIFO)); if (eq(a, "-h") || eq(a, "-L")) return(filtyp(nxtarg(0), S_IFLNK)); if (eq(a, "-s")) return(fsizep(nxtarg(0))); if (eq(a, "-t")) { if (ap >= ac) /* no args */ return(isatty(1)); else if (eq((a = nxtarg(0)), "-a") || eq(a, "-o")) { ap--; return(isatty(1)); } else return(isatty(atoi((char *)a))); } if (eq(a, "-n")) return(!eq(nxtarg(0), "")); if (eq(a, "-z")) return(eq(nxtarg(0), "")); } p2 = nxtarg(1); if (p2 == 0) return(!eq(a, "")); if (eq(p2, "-a") || eq(p2, "-o")) { ap--; return(!eq(a, "")); } if (eq(p2, "=")) return(eq(nxtarg(0), a)); if (eq(p2, "!=")) return(!eq(nxtarg(0), a)); ll_1 = stoifll(a); ll_2 = stoifll(nxtarg(0)); if (eq(p2, "-eq")) return (ll_1 == ll_2); if (eq(p2, "-ne")) return (ll_1 != ll_2); if (eq(p2, "-gt")) return (ll_1 > ll_2); if (eq(p2, "-lt")) return (ll_1 < ll_2); if (eq(p2, "-ge")) return (ll_1 >= ll_2); if (eq(p2, "-le")) return (ll_1 <= ll_2); bfailed(btest, badop, p2); /* NOTREACHED */ return 0; }
static int e3(void) { int p1; char *a; char *p2; int int1, int2; a = nxtarg(0); if (EQ(a, "(")) { p1 = exp(); if (!EQ(nxtarg(0), ")")) synbad(") expected", ""); return (p1); } p2 = nxtarg(1); ap--; if ((p2 == 0) || (!EQ(p2, "=") && !EQ(p2, "!="))) { if (EQ(a, "-r")) return (tio(nxtarg(0), 4)); if (EQ(a, "-w")) return (tio(nxtarg(0), 2)); if (EQ(a, "-x")) return (tio(nxtarg(0), 1)); if (EQ(a, "-d")) return (filtyp(nxtarg(0), S_IFDIR)); if (EQ(a, "-c")) return (filtyp(nxtarg(0), S_IFCHR)); if (EQ(a, "-b")) return (filtyp(nxtarg(0), S_IFBLK)); if (EQ(a, "-f")) { struct stat statb; return (stat(nxtarg(0), &statb) >= 0 && (statb.st_mode & S_IFMT) != S_IFDIR); } if (EQ(a, "-h")) return (filtyp(nxtarg(0), S_IFLNK)); if (EQ(a, "-u")) return (ftype(nxtarg(0), S_ISUID)); if (EQ(a, "-g")) return (ftype(nxtarg(0), S_ISGID)); if (EQ(a, "-k")) return (ftype(nxtarg(0), S_ISVTX)); if (EQ(a, "-p")) #ifdef S_IFIFO return (filtyp(nxtarg(0), S_IFIFO)); #else return (nxtarg(0), 0); #endif if (EQ(a, "-s")) return (fsizep(nxtarg(0))); if (EQ(a, "-t")) if (ap >= ac) return (isatty(1)); else if (EQ((a = nxtarg(0)), "-a") || EQ(a, "-o")) { ap--; return (isatty(1)); } else return (isatty(atoi(a))); if (EQ(a, "-n")) return (!EQ(nxtarg(0), "")); if (EQ(a, "-z")) return (EQ(nxtarg(0), "")); } p2 = nxtarg(1); if (p2 == 0) return (!EQ(a, "")); if (EQ(p2, "-a") || EQ(p2, "-o")) { ap--; return (!EQ(a, "")); } if (EQ(p2, "=")) return (EQ(nxtarg(0), a)); if (EQ(p2, "!=")) return (!EQ(nxtarg(0), a)); int1 = atoi(a); int2 = atoi(nxtarg(0)); if (EQ(p2, "-eq")) return (int1 == int2); if (EQ(p2, "-ne")) return (int1 != int2); if (EQ(p2, "-gt")) return (int1 > int2); if (EQ(p2, "-lt")) return (int1 < int2); if (EQ(p2, "-ge")) return (int1 >= int2); if (EQ(p2, "-le")) return (int1 <= int2); synbad("unknown operator ", p2); /* NOTREACHED */ return (0); }