summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2007-01-04 18:01:33 +0000
committerMarc Espie <espie@cvs.openbsd.org>2007-01-04 18:01:33 +0000
commit6fee7f6e54df9a9f80f61bf6563417e63e2881d0 (patch)
tree60114070151c4a26d011b085bd3383a647413e10
parent45fb3a386813e8f12d372141747d24ba09a32657 (diff)
extend make grammar slightly:
- make it possible to have constructs like .if $A$B == "value" instead of simpler .if $A == "value" - make it possible to have explicit strings comparisons like: .if "string" == "string2" this comes in handy in .for loops, where the variable is expanded, and thus there is no longer any variable for make to look at. So in the end, the "" can sometimes be removed, but not always... small price to pay to get `better' expressions. okay otto@
-rw-r--r--usr.bin/make/cond.c49
1 files changed, 42 insertions, 7 deletions
diff --git a/usr.bin/make/cond.c b/usr.bin/make/cond.c
index 62944e6c519..9eafb5c5d87 100644
--- a/usr.bin/make/cond.c
+++ b/usr.bin/make/cond.c
@@ -1,5 +1,5 @@
/* $OpenPackages$ */
-/* $OpenBSD: cond.c,v 1.31 2006/01/20 23:10:19 espie Exp $ */
+/* $OpenBSD: cond.c,v 1.32 2007/01/04 18:01:32 espie Exp $ */
/* $NetBSD: cond.c,v 1.7 1996/11/06 17:59:02 christos Exp $ */
/*
@@ -75,6 +75,8 @@
* T -> $(varspec) op value
* T -> $(varspec) == "string"
* T -> $(varspec) != "string"
+ * T -> "string" == "string"
+ * T -> "string" != "string"
* T -> ( E )
* T -> ! T
* op -> == | != | > | < | >= | <=
@@ -110,6 +112,8 @@ static Token CondF(bool);
static Token CondE(bool);
static Token CondHandleVarSpec(bool);
static Token CondHandleDefault(bool);
+static Token CondHandleComparison(char *, bool, bool);
+static Token CondHandleString(bool);
static const char *find_cond(const char *);
@@ -365,16 +369,12 @@ CondCvtArg(const char *str, double *value)
static Token
CondHandleVarSpec(bool doEval)
{
- Token t;
char *lhs;
- const char *rhs;
- const char *op;
size_t varSpecLen;
bool doFree;
/* Parse the variable spec and skip over it, saving its
* value in lhs. */
- t = Err;
lhs = Var_Parse(condExpr, NULL, doEval,&varSpecLen,&doFree);
if (lhs == var_Error)
/* Even if !doEval, we still report syntax errors, which
@@ -396,11 +396,44 @@ CondHandleVarSpec(bool doEval)
for (;*condExpr && !isspace(*condExpr); condExpr++)
Buf_AddChar(&buf, *condExpr);
- lhs = Buf_Retrieve(&buf);
-
+ lhs = Var_Subst(Buf_Retrieve(&buf), NULL, doEval);
+ Buf_Destroy(&buf);
doFree = true;
}
+ return CondHandleComparison(lhs, doFree, doEval);
+}
+
+static Token
+CondHandleString(bool doEval)
+{
+ char *lhs;
+ const char *begin;
+ BUFFER buf;
+
+ /* find the extent of the string */
+ begin = ++condExpr;
+ while (*condExpr && *condExpr != '"') {
+ condExpr++;
+ }
+
+ Buf_Init(&buf, 0);
+ Buf_Addi(&buf, begin, condExpr);
+ if (*condExpr == '"')
+ condExpr++;
+ lhs = Var_Subst(Buf_Retrieve(&buf), NULL, doEval);
+ Buf_Destroy(&buf);
+ return CondHandleComparison(lhs, true, doEval);
+}
+
+static Token
+CondHandleComparison(char *lhs, bool doFree, bool doEval)
+{
+ Token t;
+ const char *rhs;
+ const char *op;
+
+ t = Err;
/* Skip whitespace to get to the operator. */
while (isspace(*condExpr))
condExpr++;
@@ -707,6 +740,8 @@ CondToken(bool doEval)
case '\n':
case '\0':
return EndOfFile;
+ case '"':
+ return CondHandleString(doEval);
case '$':
return CondHandleVarSpec(doEval);
default: