tech-toolchain archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

make: allow > in :? expressions



In an expression like:
CFLAGS += ${${MAX_FOO:U0} > 0:?-max-foo ${MAX_FOO}:}
${MAX_FOO:U0} has already been expanded by the time we get to
CondToken(), so we just blow by the check for '"' or '$'.
This lets us step back there... and also print a parse error if we get
it wrong.
Index: cond.c
===================================================================
RCS file: /cvsroot/src/usr.bin/make/cond.c,v
retrieving revision 1.41
diff -u -p -r1.41 cond.c
--- cond.c 15 Feb 2008 21:29:50 -0000 1.41
+++ cond.c 21 Oct 2008 18:46:41 -0000
@@ -710,6 +710,8 @@ CondToken(Boolean doEval)
 Boolean lhsQuoted;
 Boolean rhsQuoted;
 
+do_compare_setup:
+
 rhs = NULL;
 lhsFree = rhsFree = FALSE;
 lhsQuoted = rhsQuoted = FALSE;
@@ -985,6 +987,13 @@ error:
 * binary operator) and set to invert the evaluation
 * function if condInvert is TRUE.
 */
+ if (isdigit((unsigned char)condExpr[0])) {
+ /*
+ * Variables may already be substituted
+ * by the time we get here.
+ */
+ goto do_compare_setup;
+ }
 use_default:
 invert = condInvert;
 evalProc = condDefProc;
Index: parse.c
===================================================================
RCS file: /cvsroot/src/usr.bin/make/parse.c,v
retrieving revision 1.147
diff -u -p -r1.147 parse.c
--- parse.c 6 Oct 2008 22:09:21 -0000 1.147
+++ parse.c 21 Oct 2008 18:46:42 -0000
@@ -392,7 +392,7 @@ ParseVErrorInternal(FILE *f, const char 
 
 (void)fprintf(f, "%s: \"", progname);
 
- if (*cfname != '/' && strcmp(cfname, "(stdin)") != 0) {
+ if (*cfname != '/' && *cfname != '(') {
 char *cp;
 const char *dir;
 
@@ -471,6 +471,15 @@ Parse_Error(int type, const char *fmt, .
 va_list ap;
 
 va_start(ap, fmt);
+ if (curFile == (IFile *)NIL) {
+ /* avoid segfault */
+ static IFile intFile = {
+ .fname = "(unknown)",
+ .lineno = 0,
+ .fd = -1,
+ };
+ curFile = &intFile;
+ }
 ParseVErrorInternal(stderr, curFile->fname, curFile->lineno,
 type, fmt, ap);
 va_end(ap);
Index: unit-tests/cond1
===================================================================
RCS file: /cvsroot/src/usr.bin/make/unit-tests/cond1,v
retrieving revision 1.3
diff -u -p -r1.3 cond1
--- unit-tests/cond1 13 Apr 2004 16:06:23 -0000 1.3
+++ unit-tests/cond1 21 Oct 2008 18:46:42 -0000
@@ -100,3 +100,5 @@ all:
 @echo "A='$A' B='$B' C='$C' o='$o,${o2}'"
 @echo "Passed:${.newline} ${Ok:S/,/${.newline}/}"
 @echo "${NUMBERS:@n@$n is ${("${PRIMES:M$n}" == ""):?not:} 
prime${.newline}@}"
+ @echo "${"${DoNotQuoteHere:U0}" > 0:?OK:No}"
+ @echo "${${NoSuchNumber:U42} > 0:?OK:No}"
Index: unit-tests/test.exp
===================================================================
RCS file: /cvsroot/src/usr.bin/make/unit-tests/test.exp,v
retrieving revision 1.25
diff -u -p -r1.25 test.exp
--- unit-tests/test.exp 15 May 2008 21:05:55 -0000 1.25
+++ unit-tests/test.exp 21 Oct 2008 18:46:42 -0000
@@ -20,6 +20,10 @@ Passed:
 4 is not prime
 5 is prime
 
+make: "(unknown)" line 0: warning: String comparison operator should be either 
== or !=
+make: Bad conditional expression `"0" > 0' in "0" > 0?OK:No
+
+OK
 UT_DOLLAR=This is $UT_FU
 UT_FOO=foobar is fubar
 UT_FU=fubar


Home | Main Index | Thread Index | Old Index

AltStyle によって変換されたページ (->オリジナル) /