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): split code for parsing the :U modifier...



details:   https://anonhg.NetBSD.org/src/rev/43e74a41bf30
branches:  trunk
changeset: 937706:43e74a41bf30
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Aug 23 20:57:02 2020 +0000

description:
make(1): split code for parsing the :U modifier into digestible parts

The comment about "unescaped $'s that aren't before the delimiter" was
wrong, as the code didn't contain the "aren't before the delimiter"
part.  By splitting the code into paragraphs, the larger structure
becomes easily visible.  Having a few short comments in the right place
is more helpful than a big block of text.

diffstat:

 usr.bin/make/var.c |  43 +++++++++++++++++++++----------------------
 1 files changed, 21 insertions(+), 22 deletions(-)

diffs (81 lines):

diff -r 3524fd2f16af -r 43e74a41bf30 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sun Aug 23 20:49:33 2020 +0000
+++ b/usr.bin/make/var.c        Sun Aug 23 20:57:02 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.465 2020/08/23 18:26:35 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.466 2020/08/23 20:57:02 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.465 2020/08/23 18:26:35 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.466 2020/08/23 20:57:02 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.465 2020/08/23 18:26:35 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.466 2020/08/23 20:57:02 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -2031,25 +2031,22 @@
            eflags |= VARE_WANTRES;
     }
 
-    /*
-     * Pass through mod looking for 1) escaped delimiters,
-     * '$'s and backslashes (place the escaped character in
-     * uninterpreted) and 2) unescaped $'s that aren't before
-     * the delimiter (expand the variable substitution).
-     * The result is left in the Buffer buf.
-     */
     Buf_Init(&buf, 0);
     p = *pp + 1;
     while (*p != st->endc && *p != ':' && *p != '\0') {
-       if (*p == '\\' &&
-           (p[1] == ':' || p[1] == '$' || p[1] == st->endc || p[1] == '\\')) {
-           Buf_AddByte(&buf, p[1]);
-           p += 2;
-       } else if (*p == '$') {
-           /*
-            * If unescaped dollar sign, assume it's a
-            * variable substitution and recurse.
-            */
+
+        /* Escaped delimiter or other special character */
+       if (*p == '\\') {
+           char c = p[1];
+           if (c == st->endc || c == ':' || c == '$' || c == '\\') {
+               Buf_AddByte(&buf, c);
+               p += 2;
+               continue;
+           }
+       }
+
+       /* Nested variable expressions */
+       if (*p == '$') {
            const char *cp2;
            int len;
            void *freeIt;
@@ -2058,10 +2055,12 @@
            Buf_AddStr(&buf, cp2);
            free(freeIt);
            p += len;
-       } else {
-           Buf_AddByte(&buf, *p);
-           p++;
+           continue;
        }
+
+       /* Ordinary text */
+       Buf_AddByte(&buf, *p);
+       p++;
     }
     *pp = p;
 



Home | Main Index | Thread Index | Old Index