Module Name:    src
Committed By:   rillig
Date:           Sun Aug  2 10:49:53 UTC 2020

Modified Files:
        src/usr.bin/make: var.c

Log Message:
make(1): document almost duplicate code

ParseModifierPart and Var_Parse are very similar, but there might be
subtle differences.  Until these differences are documented in the form
of unit tests, merging these code pieces is too dangerous.


To generate a diff of this commit:
cvs rdiff -u -r1.395 -r1.396 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/var.c
diff -u src/usr.bin/make/var.c:1.395 src/usr.bin/make/var.c:1.396
--- src/usr.bin/make/var.c:1.395	Sun Aug  2 10:47:09 2020
+++ src/usr.bin/make/var.c	Sun Aug  2 10:49:53 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.395 2020/08/02 10:47:09 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.396 2020/08/02 10:49:53 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.395 2020/08/02 10:47:09 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.396 2020/08/02 10:49:53 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.395 2020/08/02 10:47:09 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.396 2020/08/02 10:49:53 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1746,7 +1746,6 @@ ParseModifierPart(
 				 * allow ampersands to be escaped and replace
 				 * unescaped ampersands with subst->lhs. */
 ) {
-    char *rstr;
     Buffer buf;
 
     Buf_InitZ(&buf, 0);
@@ -1798,6 +1797,15 @@ ParseModifierPart(
 	    continue;
 	}
 
+	/* XXX: This whole block is very similar to Var_Parse without
+	 * VARE_WANTRES.  There may be subtle edge cases though that are
+	 * not yet covered in the unit tests and that are parsed differently,
+	 * depending on whether they are evaluated or not.
+	 *
+	 * This subtle difference is not documented in the manual page,
+	 * neither is the difference between parsing :D and :M documented.
+	 * No code should ever depend on these details, but who knows. */
+
 	const char *varstart = p;	/* Nested variable, only parsed */
 	if (p[1] == PROPEN || p[1] == BROPEN) {
 	    /*
@@ -1832,7 +1840,8 @@ ParseModifierPart(
     *pp = ++p;
     if (out_length != NULL)
 	*out_length = Buf_Size(&buf);
-    rstr = Buf_Destroy(&buf, FALSE);
+
+    char *rstr = Buf_Destroy(&buf, FALSE);
     if (DEBUG(VAR))
 	fprintf(debug_file, "Modifier part: \"%s\"\n", rstr);
     return rstr;

Reply via email to