static arith_t primary(enum token n) { arith_t res; if (n == EOI) { syntax(NULL, "argument expected"); } if (n == LPAREN) { res = oexpr(t_lex(*++t_wp)); if (t_lex(*++t_wp) != RPAREN) syntax(NULL, "closing paren expected"); return res; } if (t_wp_op && t_wp_op->op_type == UNOP) { /* unary expression */ if (*++t_wp == NULL) syntax(t_wp_op->op_text, "argument expected"); if (n == STREZ) return t_wp[0][0] == '\0'; if (n == STRNZ) return t_wp[0][0] != '\0'; if (n == FILTT) return isatty(getn(*t_wp)); return filstat(*t_wp, n); } t_lex(t_wp[1]); if (t_wp_op && t_wp_op->op_type == BINOP) { return binop(); } return t_wp[0][0] != '\0'; }
static arith_t primary(enum token n) { arith_t res; if (n == EOI) { syntax(NULL, "argument expected"); } if (n == LPAREN) { res = oexpr(t_lex(*++t_wp)); if (t_lex(*++t_wp) != RPAREN) syntax(NULL, "closing paren expected"); return res; } if (t_wp_op && t_wp_op->op_type == UNOP) { /* unary expression */ if (*++t_wp == NULL) syntax(t_wp_op->op_text, "argument expected"); switch (n) { case STREZ: return strlen(*t_wp) == 0; case STRNZ: return strlen(*t_wp) != 0; case FILTT: return isatty(getn(*t_wp)); default: return filstat(*t_wp, n); } } if (t_lex(t_wp[1]), t_wp_op && t_wp_op->op_type == BINOP) { return binop(); } return strlen(*t_wp) > 0; }
static int primary(enum token n) { enum token nn; int res; if (n == EOI) return 0; /* missing expression */ if (n == LPAREN) { if ((nn = t_lex(++t_wp)) == RPAREN) return 0; /* missing expression */ res = oexpr(nn); if (t_lex(++t_wp) != RPAREN) syntax(NULL, "closing paren expected"); return res; } if (t_wp_op && t_wp_op->op_type == UNOP) { /* unary expression */ if (*++t_wp == NULL) syntax(t_wp_op->op_text, "argument expected"); switch (n) { case STREZ: return strlen(*t_wp) == 0; case STRNZ: return strlen(*t_wp) != 0; case FILTT: return isatty(getn(*t_wp)); #ifdef HAVE_FACCESSAT case FILRD: return test_file_access(*t_wp, R_OK); case FILWR: return test_file_access(*t_wp, W_OK); case FILEX: return test_file_access(*t_wp, X_OK); #endif default: return filstat(*t_wp, n); } } if (t_lex(t_wp + 1), t_wp_op && t_wp_op->op_type == BINOP) { return binop(); } return strlen(*t_wp) > 0; }
static int primary(enum token n) { enum token nn; int res; if (n == EOI) return 0; /* missing expression */ if (n == LPAREN) { parenlevel++; if ((nn = t_lex(nargc > 0 ? (--nargc, *++t_wp) : NULL)) == RPAREN) { parenlevel--; return 0; /* missing expression */ } res = oexpr(nn); if (t_lex(nargc > 0 ? (--nargc, *++t_wp) : NULL) != RPAREN) syntax(NULL, "closing paren expected"); parenlevel--; return res; } if (t_wp_op && t_wp_op->op_type == UNOP) { /* unary expression */ if (--nargc == 0) syntax(t_wp_op->op_text, "argument expected"); switch (n) { case STREZ: return strlen(*++t_wp) == 0; case STRNZ: return strlen(*++t_wp) != 0; case FILTT: return isatty(getn(*++t_wp)); default: return filstat(*++t_wp, n); } } if (t_lex(nargc > 0 ? t_wp[1] : NULL), t_wp_op && t_wp_op->op_type == BINOP) { return binop(); } return strlen(*t_wp) > 0; }
static int primary(enum token n) { int res; if (n == EOI) syntax(NULL, "argument expected"); if (n == LPAREN) { res = oexpr(t_lex(*++t_wp)); if (t_lex(*++t_wp) != RPAREN) syntax(NULL, "closing paren expected"); return res; } /* * We need this, if not binary operations with more than 4 * arguments will always fall into unary. */ if(t_lex_type(t_wp[1]) == BINOP) { t_lex(t_wp[1]); if (t_wp_op && t_wp_op->op_type == BINOP) return binop(); } if (t_wp_op && t_wp_op->op_type == UNOP) { /* unary expression */ if (*++t_wp == NULL) syntax(t_wp_op->op_text, "argument expected"); switch (n) { case STREZ: return strlen(*t_wp) == 0; case STRNZ: return strlen(*t_wp) != 0; case FILTT: return isatty(getn(*t_wp)); default: return filstat(*t_wp, n); } } return strlen(*t_wp) > 0; }
static int primary(shinstance *psh, enum token n) { enum token nn; int res; if (n == EOI) return 0; /* missing expression */ if (n == LPAREN) { if ((nn = t_lex(psh, *++psh->t_wp)) == RPAREN) return 0; /* missing expression */ res = oexpr(psh, nn); if (t_lex(psh, *++psh->t_wp) != RPAREN) syntax(psh, NULL, "closing paren expected"); return res; } if (psh->t_wp_op && psh->t_wp_op->op_type == UNOP) { /* unary expression */ if (*++psh->t_wp == NULL) syntax(psh, psh->t_wp_op->op_text, "argument expected"); switch (n) { case STREZ: return strlen(*psh->t_wp) == 0; case STRNZ: return strlen(*psh->t_wp) != 0; case FILTT: return shfile_isatty(&psh->fdtab, getn(psh, *psh->t_wp)); default: return filstat(psh, *psh->t_wp, n); } } if (t_lex(psh, psh->t_wp[1]), psh->t_wp_op && psh->t_wp_op->op_type == BINOP) { return binop(psh); } return strlen(*psh->t_wp) > 0; }