Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make make(1): migrate CondParser_String to Var_ParsePP



details:   https://anonhg.NetBSD.org/src/rev/6ea84c790b1d
branches:  trunk
changeset: 976090:6ea84c790b1d
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Sep 12 18:04:45 2020 +0000

description:
make(1): migrate CondParser_String to Var_ParsePP

diffstat:

 usr.bin/make/cond.c    |  37 ++++++++++++++++++++++---------------
 usr.bin/make/nonints.h |   3 +--
 usr.bin/make/var.c     |   8 ++++----
 3 files changed, 27 insertions(+), 21 deletions(-)

diffs (142 lines):

diff -r 2f94f682d808 -r 6ea84c790b1d usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Sat Sep 12 18:02:43 2020 +0000
+++ b/usr.bin/make/cond.c       Sat Sep 12 18:04:45 2020 +0000
@@ -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 @@
     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 @@
 {
     Buffer buf;
     const char *str;
-    int len;
+    Boolean atStart;
+    const char *nested_p;
     Boolean qt;
     const char *start;
     VarEvalFlags eflags;
@@ -450,10 +457,12 @@
            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 @@
                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) {
diff -r 2f94f682d808 -r 6ea84c790b1d usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h    Sat Sep 12 18:02:43 2020 +0000
+++ b/usr.bin/make/nonints.h    Sat Sep 12 18:04:45 2020 +0000
@@ -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_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);
diff -r 2f94f682d808 -r 6ea84c790b1d usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sat Sep 12 18:02:43 2020 +0000
+++ b/usr.bin/make/var.c        Sat Sep 12 18:04:45 2020 +0000
@@ -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 @@
  *-----------------------------------------------------------------------
  */
 /* coverity[+alloc : arg-*4] */
-const char *
+static const char *
 Var_Parse(const char * const str, GNode *ctxt, VarEvalFlags eflags,
          int *lengthPtr, void **freePtr)
 {



Home | Main Index | Thread Index | Old Index