Module Name:    src
Committed By:   rillig
Date:           Sat Sep 12 18:04:45 UTC 2020

Modified Files:
        src/usr.bin/make: cond.c nonints.h var.c

Log Message:
make(1): migrate CondParser_String to Var_ParsePP


To generate a diff of this commit:
cvs rdiff -u -r1.139 -r1.140 src/usr.bin/make/cond.c
cvs rdiff -u -r1.114 -r1.115 src/usr.bin/make/nonints.h
cvs rdiff -u -r1.494 -r1.495 src/usr.bin/make/var.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/cond.c
diff -u src/usr.bin/make/cond.c:1.139 src/usr.bin/make/cond.c:1.140
--- src/usr.bin/make/cond.c:1.139	Sat Sep 12 18:02:43 2020
+++ src/usr.bin/make/cond.c	Sat Sep 12 18:04:45 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.139 2020/09/12 18:02:43 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.140 2020/09/12 18:04:45 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: cond.c,v 1.139 2020/09/12 18:02:43 rillig Exp $";
+static char rcsid[] = "$NetBSD: cond.c,v 1.140 2020/09/12 18:04:45 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)cond.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: cond.c,v 1.139 2020/09/12 18:02:43 rillig Exp $");
+__RCSID("$NetBSD: cond.c,v 1.140 2020/09/12 18:04:45 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -392,6 +392,12 @@ TryParseNumber(const char *str, double *
     return TRUE;
 }
 
+static Boolean
+is_separator(char ch)
+{
+    return ch == '\0' || ch_isspace(ch) || strchr("!=><)", ch);
+}
+
 /*-
  * Parse a string from a variable reference or an optionally quoted
  * string.  This is called for the lhs and rhs of string comparisons.
@@ -408,7 +414,8 @@ CondParser_String(CondParser *par, Boole
 {
     Buffer buf;
     const char *str;
-    int len;
+    Boolean atStart;
+    const char *nested_p;
     Boolean qt;
     const char *start;
     VarEvalFlags eflags;
@@ -450,10 +457,12 @@ CondParser_String(CondParser *par, Boole
 	    par->p++;
 	    continue;
 	case '$':
-	    /* if we are in quotes, then an undefined variable is ok */
+	    /* if we are in quotes, an undefined variable is ok */
 	    eflags = ((!qt && doEval) ? VARE_UNDEFERR : 0) |
 		     (doEval ? VARE_WANTRES : 0);
-	    str = Var_Parse(par->p, VAR_CMD, eflags, &len, freeIt);
+	    nested_p = par->p;
+	    atStart = nested_p == start;
+	    str = Var_ParsePP(&nested_p, VAR_CMD, eflags, freeIt);
 	    if (str == var_Error) {
 		if (*freeIt) {
 		    free(*freeIt);
@@ -466,18 +475,16 @@ CondParser_String(CondParser *par, Boole
 		str = NULL;
 		goto cleanup;
 	    }
-	    par->p += len;
+	    par->p = nested_p;
+
 	    /*
-	     * If the '$' was first char (no quotes), and we are
-	     * followed by space, the operator or end of expression,
-	     * we are done.
+	     * If the '$' started the string literal (which means no quotes),
+	     * and the variable expression is followed by a space, looks like
+	     * a comparison operator or is the end of the expression, we are
+	     * done.
 	     */
-	    if ((par->p == start + len) &&
-		(par->p[0] == '\0' ||
-		 ch_isspace(par->p[0]) ||
-		 strchr("!=><)", par->p[0]))) {
+	    if (atStart && is_separator(par->p[0]))
 		goto cleanup;
-	    }
 
 	    Buf_AddStr(&buf, str);
 	    if (*freeIt) {

Index: src/usr.bin/make/nonints.h
diff -u src/usr.bin/make/nonints.h:1.114 src/usr.bin/make/nonints.h:1.115
--- src/usr.bin/make/nonints.h:1.114	Sat Sep 12 16:46:24 2020
+++ src/usr.bin/make/nonints.h	Sat Sep 12 18:04:45 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nonints.h,v 1.114 2020/09/12 16:46:24 rillig Exp $	*/
+/*	$NetBSD: nonints.h,v 1.115 2020/09/12 18:04:45 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -213,7 +213,6 @@ void Var_Set_with_flags(const char *, co
 void Var_Append(const char *, const char *, GNode *);
 Boolean Var_Exists(const char *, GNode *);
 const char *Var_Value(const char *, GNode *, char **);
-const char *Var_Parse(const char *, GNode *, VarEvalFlags, int *, void **);
 const char *Var_ParsePP(const char **, GNode *, VarEvalFlags, void **);
 char *Var_Subst(const char *, GNode *, VarEvalFlags);
 void Var_Init(void);

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.494 src/usr.bin/make/var.c:1.495
--- src/usr.bin/make/var.c:1.494	Sat Sep 12 14:41:00 2020
+++ src/usr.bin/make/var.c	Sat Sep 12 18:04:45 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.494 2020/09/12 14:41:00 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.495 2020/09/12 18:04:45 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.494 2020/09/12 14:41:00 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.495 2020/09/12 18:04:45 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)var.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: var.c,v 1.494 2020/09/12 14:41:00 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.495 2020/09/12 18:04:45 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -3344,7 +3344,7 @@ VarIsDynamic(GNode *ctxt, const char *va
  *-----------------------------------------------------------------------
  */
 /* coverity[+alloc : arg-*4] */
-const char *
+static const char *
 Var_Parse(const char * const str, GNode *ctxt, VarEvalFlags eflags,
 	  int *lengthPtr, void **freePtr)
 {

Reply via email to