CVS commit: src/bin/sh/USD.doc

2018-09-13 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Sep 14 05:59:10 UTC 2018

Modified Files:
src/bin/sh/USD.doc: Rv7man

Log Message:
Fix "every" typo in quote from The Mythical Man-Month


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/bin/sh/USD.doc/Rv7man

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

Modified files:

Index: src/bin/sh/USD.doc/Rv7man
diff -u src/bin/sh/USD.doc/Rv7man:1.1 src/bin/sh/USD.doc/Rv7man:1.2
--- src/bin/sh/USD.doc/Rv7man:1.1	Sun Aug 22 01:58:16 2010
+++ src/bin/sh/USD.doc/Rv7man	Fri Sep 14 05:59:10 2018
@@ -342,7 +342,7 @@ problems of large projects, from someone
 Required reading for any software engineer, even if conclusions may not
 always be agreed with.
 %br
-"The second is the most dangerous system a man every designs." p.55.
+"The second is the most dangerous system a man ever designs." p.55.
 %br
 "Hence plan to throw one away; you will, anyhow." p.116.
 %br



CVS commit: src/bin/sh

2018-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Oct  7 23:17:52 UTC 2018

Modified Files:
src/bin/sh: alias.c

Log Message:
When listing aliases, sort them alphabetically.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/bin/sh/alias.c

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

Modified files:

Index: src/bin/sh/alias.c
diff -u src/bin/sh/alias.c:1.16 src/bin/sh/alias.c:1.17
--- src/bin/sh/alias.c:1.16	Mon Jul 24 12:34:45 2017
+++ src/bin/sh/alias.c	Sun Oct  7 23:17:52 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: alias.c,v 1.16 2017/07/24 12:34:45 kre Exp $	*/
+/*	$NetBSD: alias.c,v 1.17 2018/10/07 23:17:52 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)alias.c	8.3 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: alias.c,v 1.16 2017/07/24 12:34:45 kre Exp $");
+__RCSID("$NetBSD: alias.c,v 1.17 2018/10/07 23:17:52 rillig Exp $");
 #endif
 #endif /* not lint */
 
@@ -58,6 +58,8 @@ __RCSID("$NetBSD: alias.c,v 1.16 2017/07
 struct alias *atab[ATABSIZE];
 
 STATIC void setalias(char *, char *);
+STATIC int by_name(const void *, const void *);
+STATIC void list_aliases(void);
 STATIC int unalias(char *);
 STATIC struct alias **hashalias(const char *);
 
@@ -204,9 +206,47 @@ alias_text(void *dummy __unused, const c
 	return ap->val;
 }
 
-/*
- * TODO - sort output
- */
+STATIC int
+by_name(const void *a, const void *b)
+{
+
+	return strcmp(
+		(*(const struct alias * const *)a)->name,
+		(*(const struct alias * const *)b)->name);
+}
+
+STATIC void
+list_aliases(void)
+{
+	size_t i, j, n;
+	const struct alias **aliases;
+	const struct alias *ap;
+
+	n = 0;
+	for (i = 0; i < ATABSIZE; i++)
+		for (ap = atab[i]; ap != NULL; ap = ap->next)
+			if (ap->name[0] != '\0')
+n++;
+
+	aliases = ckmalloc(n * sizeof aliases[0]);
+
+	j = 0;
+	for (i = 0; i < ATABSIZE; i++)
+		for (ap = atab[i]; ap != NULL; ap = ap->next)
+			if (ap->name[0] != '\0')
+aliases[j++] = ap;
+
+	qsort(aliases, n, sizeof aliases[0], by_name);
+
+	for (i = 0; i < n; i++) {
+		out1fmt("alias %s=", aliases[i]->name);
+		print_quoted(aliases[i]->val);
+		out1c('\n');
+	}
+
+	ckfree(aliases);
+}
+
 int
 aliascmd(int argc, char **argv)
 {
@@ -215,18 +255,10 @@ aliascmd(int argc, char **argv)
 	struct alias *ap;
 
 	if (argc == 1) {
-		int i;
-
-		for (i = 0; i < ATABSIZE; i++)
-			for (ap = atab[i]; ap; ap = ap->next) {
-if (*ap->name != '\0') {
-	out1fmt("alias %s=", ap->name);
-	print_quoted(ap->val);
-	out1c('\n');
-}
-			}
+		list_aliases();
 		return (0);
 	}
+
 	while ((n = *++argv) != NULL) {
 		if ((v = strchr(n+1, '=')) == NULL) { /* n+1: funny ksh stuff */
 			if ((ap = lookupalias(n, 0)) == NULL) {



CVS commit: src/usr.bin/make

2019-12-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec  1 23:53:49 UTC 2019

Modified Files:
src/usr.bin/make: str.c
src/usr.bin/make/unit-tests: varmod-edge.mk

Log Message:
Fix out-of-bounds read in Str_Match.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/usr.bin/make/str.c
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/varmod-edge.mk

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/str.c
diff -u src/usr.bin/make/str.c:1.38 src/usr.bin/make/str.c:1.39
--- src/usr.bin/make/str.c:1.38	Fri Apr 21 22:15:44 2017
+++ src/usr.bin/make/str.c	Sun Dec  1 23:53:49 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: str.c,v 1.38 2017/04/21 22:15:44 sjg Exp $	*/
+/*	$NetBSD: str.c,v 1.39 2019/12/01 23:53:49 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: str.c,v 1.38 2017/04/21 22:15:44 sjg Exp $";
+static char rcsid[] = "$NetBSD: str.c,v 1.39 2019/12/01 23:53:49 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)str.c	5.8 (Berkeley) 6/1/90";
 #else
-__RCSID("$NetBSD: str.c,v 1.38 2017/04/21 22:15:44 sjg Exp $");
+__RCSID("$NetBSD: str.c,v 1.39 2019/12/01 23:53:49 rillig Exp $");
 #endif
 #endif/* not lint */
 #endif
@@ -407,6 +407,8 @@ Str_Match(const char *string, const char
 return 0;
 			while ((*pattern != ']') && (*pattern != 0))
 ++pattern;
+			if (*pattern == 0)
+--pattern;
 			goto thisCharOK;
 		}
 		/*

Index: src/usr.bin/make/unit-tests/varmod-edge.mk
diff -u src/usr.bin/make/unit-tests/varmod-edge.mk:1.4 src/usr.bin/make/unit-tests/varmod-edge.mk:1.5
--- src/usr.bin/make/unit-tests/varmod-edge.mk:1.4	Sat Nov 30 03:53:45 2019
+++ src/usr.bin/make/unit-tests/varmod-edge.mk	Sun Dec  1 23:53:49 2019
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-edge.mk,v 1.4 2019/11/30 03:53:45 rillig Exp $
+# $NetBSD: varmod-edge.mk,v 1.5 2019/12/01 23:53:49 rillig Exp $
 #
 # Tests for edge cases in variable modifiers.
 #
@@ -67,6 +67,9 @@ EXP.M-nest-brk=	[
 #
 # XXX: It is unexpected that no error is reported.
 # See str.c, function Str_Match.
+#
+# Before 2019-12-02, this test case triggered an out-of-bounds read
+# in Str_Match.
 TESTS+=		M-pat-err
 INP.M-pat-err=	[ [[ [[[
 MOD.M-pat-err=	${INP.M-pat-err:M${:U[[}}



CVS commit: src/usr.bin/make/unit-tests

2019-12-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Dec  2 01:01:08 UTC 2019

Modified Files:
src/usr.bin/make/unit-tests: varmod-edge.exp varmod-edge.mk

Log Message:
Add more tests for variable modifiers in make.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/varmod-edge.exp
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/varmod-edge.mk

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/unit-tests/varmod-edge.exp
diff -u src/usr.bin/make/unit-tests/varmod-edge.exp:1.3 src/usr.bin/make/unit-tests/varmod-edge.exp:1.4
--- src/usr.bin/make/unit-tests/varmod-edge.exp:1.3	Sat Nov 30 03:53:45 2019
+++ src/usr.bin/make/unit-tests/varmod-edge.exp	Mon Dec  2 01:01:08 2019
@@ -1,4 +1,5 @@
 make: Unclosed variable specification (expecting '}') for "" (value "*)") modifier U
+make: Unclosed substitution for INP.eq-esc (= missing)
 ok M-paren
 ok M-mixed
 ok M-unescape
@@ -8,4 +9,9 @@ ok M-pat-err
 ok M-bsbs
 ok M-bs1-par
 ok M-bs2-par
+ok M-128
+ok eq-ext
+ok eq-q
+ok eq-bs
+ok eq-esc
 exit status 0

Index: src/usr.bin/make/unit-tests/varmod-edge.mk
diff -u src/usr.bin/make/unit-tests/varmod-edge.mk:1.5 src/usr.bin/make/unit-tests/varmod-edge.mk:1.6
--- src/usr.bin/make/unit-tests/varmod-edge.mk:1.5	Sun Dec  1 23:53:49 2019
+++ src/usr.bin/make/unit-tests/varmod-edge.mk	Mon Dec  2 01:01:08 2019
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-edge.mk,v 1.5 2019/12/01 23:53:49 rillig Exp $
+# $NetBSD: varmod-edge.mk,v 1.6 2019/12/02 01:01:08 rillig Exp $
 #
 # Tests for edge cases in variable modifiers.
 #
@@ -51,6 +51,7 @@ TESTS+=		M-nest-mix
 INP.M-nest-mix=	(parentheses)
 MOD.M-nest-mix=	${INP.M-nest-mix:M${:U*)}}
 EXP.M-nest-mix=	(parentheses)}
+# make: Unclosed variable specification (expecting '}') for "" (value "*)") modifier U
 
 # In contrast to parentheses and braces, the brackets are not counted
 # when the :M modifier is parsed since Makefile variables only take the
@@ -112,6 +113,44 @@ INP.M-bs2-par=	( (:M (:M} \( \(:M \(:M}
 MOD.M-bs2-par=	${INP.M-bs2-par:M\\(:M*}}}
 EXP.M-bs2-par=	\(:M}}
 
+# Str_Match uses a recursive algorithm for matching the * patterns.
+# Make sure that it survives patterns with 128 asterisks.
+# That should be enough for all practical purposes.
+# To produce a stack overflow, just add more :Qs below.
+TESTS+=		M-128
+INP.M-128=	${:U\\:Q:Q:Q:Q:Q:Q:Q:S,\\,x,g}
+PAT.M-128=	${:U\\:Q:Q:Q:Q:Q:Q:Q:S,\\,*,g}
+MOD.M-128=	${INP.M-128:M${PAT.M-128}}
+EXP.M-128=	${INP.M-128}
+
+# This is the normal SysV substitution. Nothing surprising here.
+TESTS+=		eq-ext
+INP.eq-ext=	file.c file.cc
+MOD.eq-ext=	${INP.eq-ext:%.c=%.o}
+EXP.eq-ext=	file.o file.cc
+
+# The SysV := modifier is greedy and consumes all the modifier text
+# up until the closing brace or parenthesis. The :Q may look like a
+# modifier, but it really isn't, that's why it appears in the output.
+TESTS+=		eq-q
+INP.eq-q=	file.c file.cc
+MOD.eq-q=	${INP.eq-q:%.c=%.o:Q}
+EXP.eq-q=	file.o:Q file.cc
+
+# The = in the := modifier can be escaped.
+TESTS+=		eq-bs
+INP.eq-bs=	file.c file.c=%.o
+MOD.eq-bs=	${INP.eq-bs:%.c\=%.o=.ext}
+EXP.eq-bs=	file.c file.ext
+
+# Having only an escaped = results in a parse error.
+# The call to "pattern.lhs = VarGetPattern" fails.
+TESTS+=		eq-esc
+INP.eq-esc=	file.c file...
+MOD.eq-esc=	${INP.eq-esc:a\=b}
+EXP.eq-esc=	# empty
+# make: Unclosed substitution for INP.eq-esc (= missing)
+
 all:
 .for test in ${TESTS}
 .  if ${MOD.${test}} == ${EXP.${test}}



CVS commit: src/usr.bin/make/unit-tests

2020-01-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Jan  7 20:50:12 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: escape.mk

Log Message:
usr.bin/make: fix typos in comment


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/make/unit-tests/escape.mk

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/unit-tests/escape.mk
diff -u src/usr.bin/make/unit-tests/escape.mk:1.10 src/usr.bin/make/unit-tests/escape.mk:1.11
--- src/usr.bin/make/unit-tests/escape.mk:1.10	Tue Sep  9 10:22:27 2014
+++ src/usr.bin/make/unit-tests/escape.mk	Tue Jan  7 20:50:12 2020
@@ -1,4 +1,4 @@
-# $Id: escape.mk,v 1.10 2014/09/09 10:22:27 apb Exp $
+# $Id: escape.mk,v 1.11 2020/01/07 20:50:12 rillig Exp $
 #
 # Test backslash escaping.
 
@@ -35,8 +35,8 @@
 # Also, our practice is that an even number of backslashes before a
 # newline in a variable assignment simply stores the backslashes as part
 # of the value, and treats the newline as though it was not escaped.
-# Similarly, ann even number of backslashes before a newline in a
-# command simply uses the backslashes as part of the command test, but
+# Similarly, an even number of backslashes before a newline in a
+# command simply uses the backslashes as part of the command, but
 # does not escape the newline.  This is compatible with GNU make.
 
 all: .PHONY



CVS commit: src/usr.bin/make

2020-01-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Jan  7 21:24:16 UTC 2020

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

Log Message:
usr.bin/make: remove dead code

The preprocessor conditions contradicted each other: __hpux__ or __hpux
would need to be defined, and at the same time none of them would need to
be defined.


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/usr.bin/make/util.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/util.c
diff -u src/usr.bin/make/util.c:1.54 src/usr.bin/make/util.c:1.55
--- src/usr.bin/make/util.c:1.54	Tue Nov 26 13:44:41 2013
+++ src/usr.bin/make/util.c	Tue Jan  7 21:24:16 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: util.c,v 1.54 2013/11/26 13:44:41 joerg Exp $	*/
+/*	$NetBSD: util.c,v 1.55 2020/01/07 21:24:16 rillig Exp $	*/
 
 /*
  * Missing stuff from OS's
@@ -8,11 +8,11 @@
 #endif
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: util.c,v 1.54 2013/11/26 13:44:41 joerg Exp $";
+static char rcsid[] = "$NetBSD: util.c,v 1.55 2020/01/07 21:24:16 rillig Exp $";
 #else
 #include 
 #ifndef lint
-__RCSID("$NetBSD: util.c,v 1.54 2013/11/26 13:44:41 joerg Exp $");
+__RCSID("$NetBSD: util.c,v 1.55 2020/01/07 21:24:16 rillig Exp $");
 #endif
 #endif
 
@@ -229,32 +229,6 @@ killpg(int pid, int sig)
 return kill(-pid, sig);
 }
 
-#if !defined(__hpux__) && !defined(__hpux)
-void
-srandom(long seed)
-{
-srand48(seed);
-}
-
-long
-random(void)
-{
-return lrand48();
-}
-#endif
-
-#if !defined(__hpux__) && !defined(__hpux)
-int
-utimes(char *file, struct timeval tvp[2])
-{
-struct utimbuf t;
-
-t.actime  = tvp[0].tv_sec;
-t.modtime = tvp[1].tv_sec;
-return(utime(file, ));
-}
-#endif
-
 #if !defined(BSD) && !defined(d_fileno)
 # define d_fileno d_ino
 #endif



CVS commit: src/usr.bin/make/unit-tests

2020-01-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Jan  7 22:42:14 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: modorder.mk

Log Message:
usr.bin/make: document probabilities for random test failures

Side node: this test will never fail between 2024-04-15 and 2024-07-06.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/modorder.mk

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/unit-tests/modorder.mk
diff -u src/usr.bin/make/unit-tests/modorder.mk:1.1 src/usr.bin/make/unit-tests/modorder.mk:1.2
--- src/usr.bin/make/unit-tests/modorder.mk:1.1	Thu Aug 21 13:44:51 2014
+++ src/usr.bin/make/unit-tests/modorder.mk	Tue Jan  7 22:42:14 2020
@@ -1,4 +1,4 @@
-# $NetBSD: modorder.mk,v 1.1 2014/08/21 13:44:51 apb Exp $
+# $NetBSD: modorder.mk,v 1.2 2020/01/07 22:42:14 rillig Exp $
 
 LIST=		one two three four five six seven eight nine ten
 LISTX=		${LIST:Ox}
@@ -12,8 +12,9 @@ all:
 	@echo "LIST:O= ${LIST:O}"
 	# Note that 1 in every 10! trials two independently generated
 	# randomized orderings will be the same.  The test framework doesn't
-	# support checking probabilistic output, so we accept that the test
-	# will incorrectly fail with probability 2.8E-7.
+	# support checking probabilistic output, so we accept that each of the
+	# 3 :Ox tests will incorrectly fail with probability 2.756E-7, which
+	# lets the whole test fail once in 1.209.600 runs, on average.
 	@echo "LIST:Ox   = `test '${LIST:Ox}' != '${LIST:Ox}' ${TEST_RESULT}`"
 	@echo "LIST:O:Ox = `test '${LIST:O:Ox}' != '${LIST:O:Ox}' ${TEST_RESULT}`"
 	@echo "LISTX = `test '${LISTX}' != '${LISTX}' ${TEST_RESULT}`"



CVS commit: src/tests/lib/libc/gen

2020-03-13 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar 13 21:44:25 UTC 2020

Modified Files:
src/tests/lib/libc/gen: t_glob.c

Log Message:
t_glob.c: use distinct names for test structures

Before, the structures and functions defined by the test used the same
prefix as the code to be tested. This made it difficult to draw a line
between these parts.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/lib/libc/gen/t_glob.c

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

Modified files:

Index: src/tests/lib/libc/gen/t_glob.c
diff -u src/tests/lib/libc/gen/t_glob.c:1.7 src/tests/lib/libc/gen/t_glob.c:1.8
--- src/tests/lib/libc/gen/t_glob.c:1.7	Fri Mar 13 20:48:33 2020
+++ src/tests/lib/libc/gen/t_glob.c	Fri Mar 13 21:44:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_glob.c,v 1.7 2020/03/13 20:48:33 rillig Exp $	*/
+/*	$NetBSD: t_glob.c,v 1.8 2020/03/13 21:44:25 rillig Exp $	*/
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_glob.c,v 1.7 2020/03/13 20:48:33 rillig Exp $");
+__RCSID("$NetBSD: t_glob.c,v 1.8 2020/03/13 21:44:25 rillig Exp $");
 
 #include 
 
@@ -56,32 +56,32 @@ __RCSID("$NetBSD: t_glob.c,v 1.7 2020/03
 #define DPRINTF(a)
 #endif
 
-struct gl_file {
+struct vfs_file {
 	const char *name;
 	int dir;
 };
 
-static struct gl_file a[] = {
+static struct vfs_file a[] = {
 	{ "1", 0 },
 	{ "b", 1 },
 	{ "3", 0 },
 	{ "4", 0 },
 };
 
-static struct gl_file b[] = {
+static struct vfs_file b[] = {
 	{ "x", 0 },
 	{ "y", 0 },
 	{ "z", 0 },
 	{ "w", 0 },
 };
 
-struct gl_dir {
+struct vfs_dir {
 	const char *name;	/* directory name */
-	const struct gl_file *dir;
+	const struct vfs_file *dir;
 	size_t len, pos;
 };
 
-static struct gl_dir d[] = {
+static struct vfs_dir d[] = {
 	{ "a", a, __arraycount(a), 0 },
 	{ "a/b", b, __arraycount(b), 0 },
 };
@@ -98,7 +98,7 @@ trim(char *buf, size_t len, const char *
 }
 
 static void *
-gl_opendir(const char *dir)
+vfs_opendir(const char *dir)
 {
 	size_t i;
 	char buf[MAXPATHLEN];
@@ -114,12 +114,12 @@ gl_opendir(const char *dir)
 }
 
 static struct dirent *
-gl_readdir(void *v)
+vfs_readdir(void *v)
 {
 	static struct dirent dir;
-	struct gl_dir *dd = v;
+	struct vfs_dir *dd = v;
 	if (dd->pos < dd->len) {
-		const struct gl_file *f = >dir[dd->pos++];
+		const struct vfs_file *f = >dir[dd->pos++];
 		strcpy(dir.d_name, f->name);
 		dir.d_namlen = strlen(f->name);
 		dir.d_ino = dd->pos;
@@ -132,7 +132,7 @@ gl_readdir(void *v)
 }
 
 static int
-gl_stat(const char *name , __gl_stat_t *st)
+vfs_stat(const char *name , __gl_stat_t *st)
 {
 	char buf[MAXPATHLEN];
 	trim(buf, sizeof(buf), name);
@@ -144,7 +144,7 @@ gl_stat(const char *name , __gl_stat_t *
 	}
 
 	if (buf[0] == 'a' && buf[1] == '/') {
-		struct gl_file *f;
+		struct vfs_file *f;
 		size_t offs, count;
 
 		if (buf[2] == 'b' && buf[3] == '/') {
@@ -167,15 +167,15 @@ gl_stat(const char *name , __gl_stat_t *
 }
 
 static int
-gl_lstat(const char *name , __gl_stat_t *st)
+vfs_lstat(const char *name , __gl_stat_t *st)
 {
-	return gl_stat(name, st);
+	return vfs_stat(name, st);
 }
 
 static void
-gl_closedir(void *v)
+vfs_closedir(void *v)
 {
-	struct gl_dir *dd = v;
+	struct vfs_dir *dd = v;
 	dd->pos = 0;
 	DPRINTF(("closedir %p\n", dd));
 }
@@ -189,11 +189,11 @@ run(const char *p, int flags, /* const c
 
 	DPRINTF(("pattern %s\n", p));
 	memset(, 0, sizeof(gl));
-	gl.gl_opendir = gl_opendir;
-	gl.gl_readdir = gl_readdir;
-	gl.gl_closedir = gl_closedir;
-	gl.gl_stat = gl_stat;
-	gl.gl_lstat = gl_lstat;
+	gl.gl_opendir = vfs_opendir;
+	gl.gl_readdir = vfs_readdir;
+	gl.gl_closedir = vfs_closedir;
+	gl.gl_stat = vfs_stat;
+	gl.gl_lstat = vfs_lstat;
 
 	switch ((e = glob(p, GLOB_ALTDIRFUNC | flags, NULL, ))) {
 	case 0:



CVS commit: src/tests/lib/libc/gen

2020-03-13 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar 13 20:48:33 UTC 2020

Modified Files:
src/tests/lib/libc/gen: t_glob.c

Log Message:
t_glob.c: move expected globbing result directly into the test cases

This makes the tests more self-contained. The example directory tree that
is common to all the tests is still defined elsewhere, but in the same
file. Setting up the example directory structure in each test would make
the tests even more independent and read.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libc/gen/t_glob.c

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

Modified files:

Index: src/tests/lib/libc/gen/t_glob.c
diff -u src/tests/lib/libc/gen/t_glob.c:1.6 src/tests/lib/libc/gen/t_glob.c:1.7
--- src/tests/lib/libc/gen/t_glob.c:1.6	Wed Apr 26 14:52:57 2017
+++ src/tests/lib/libc/gen/t_glob.c	Fri Mar 13 20:48:33 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_glob.c,v 1.6 2017/04/26 14:52:57 christos Exp $	*/
+/*	$NetBSD: t_glob.c,v 1.7 2020/03/13 20:48:33 rillig Exp $	*/
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_glob.c,v 1.6 2017/04/26 14:52:57 christos Exp $");
+__RCSID("$NetBSD: t_glob.c,v 1.7 2020/03/13 20:48:33 rillig Exp $");
 
 #include 
 
@@ -41,6 +41,7 @@ __RCSID("$NetBSD: t_glob.c,v 1.6 2017/04
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -85,22 +86,6 @@ static struct gl_dir d[] = {
 	{ "a/b", b, __arraycount(b), 0 },
 };
 
-static const char *glob_range[] = {
-	"a/b/x", "a/b/y", "a/b/z",
-};
-
-static const char *glob_range_not[] = {
-	"a/b/w",
-};
-
-static const char *glob_star[] = {
-	"a/1", "a/3", "a/4", "a/b", "a/b/w", "a/b/x", "a/b/y", "a/b/z",
-};
-
-static const char *glob_star_not[] = {
-	"a/1", "a/3", "a/4", "a/b",
-};
-
 static void
 trim(char *buf, size_t len, const char *name)
 {
@@ -171,7 +156,7 @@ gl_stat(const char *name , __gl_stat_t *
 			count = __arraycount(a);
 			f = a;
 		}
-		
+
 		for (size_t i = 0; i < count; i++)
 			if (strcmp(f[i].name, buf + offs) == 0)
 return 0;
@@ -196,7 +181,7 @@ gl_closedir(void *v)
 }
 
 static void
-run(const char *p, int flags, const char **res, size_t len)
+run(const char *p, int flags, /* const char *res */ ...)
 {
 	glob_t gl;
 	size_t i;
@@ -233,9 +218,14 @@ run(const char *p, int flags, const char
 	for (i = 0; i < gl.gl_pathc; i++)
 		DPRINTF(("%s\n", gl.gl_pathv[i]));
 
-	ATF_CHECK(len == gl.gl_pathc);
-	for (i = 0; i < gl.gl_pathc && i < len; i++)
-		ATF_CHECK_STREQ(gl.gl_pathv[i], res[i]);
+	va_list res;
+	va_start(res, flags);
+	const char *expected = NULL;
+	for (i = 0; (expected = va_arg(res, const char *)) != NULL && i < gl.gl_pathc; i++)
+		ATF_CHECK_STREQ(gl.gl_pathv[i], expected);
+	va_end(res);
+	ATF_CHECK_EQ(i, gl.gl_pathc);
+	ATF_CHECK_MSG(expected == NULL, "expected \"%s\" to be matched", expected);
 
 	globfree();
 	return;
@@ -243,6 +233,7 @@ bad:
 	ATF_REQUIRE_MSG(e == 0, "No match for `%s'", p);
 }
 
+#define run(p, flags, ...) (run)(p, flags, __VA_ARGS__, (const char *) 0)
 
 ATF_TC(glob_range);
 ATF_TC_HEAD(glob_range, tc)
@@ -253,7 +244,8 @@ ATF_TC_HEAD(glob_range, tc)
 
 ATF_TC_BODY(glob_range, tc)
 {
-	run("a/b/[x-z]", 0, glob_range, __arraycount(glob_range));
+	run("a/b/[x-z]", 0,
+	"a/b/x", "a/b/y", "a/b/z");
 }
 
 ATF_TC(glob_range_not);
@@ -265,7 +257,8 @@ ATF_TC_HEAD(glob_range_not, tc)
 
 ATF_TC_BODY(glob_range_not, tc)
 {
-	run("a/b/[!x-z]", 0, glob_range_not, __arraycount(glob_range_not));
+	run("a/b/[!x-z]", 0,
+	"a/b/w");
 }
 
 ATF_TC(glob_star);
@@ -277,7 +270,8 @@ ATF_TC_HEAD(glob_star, tc)
 
 ATF_TC_BODY(glob_star, tc)
 {
-	run("a/**", GLOB_STAR, glob_star, __arraycount(glob_star));
+	run("a/**", GLOB_STAR,
+	"a/1", "a/3", "a/4", "a/b", "a/b/w", "a/b/x", "a/b/y", "a/b/z");
 }
 
 ATF_TC(glob_star_not);
@@ -287,10 +281,10 @@ ATF_TC_HEAD(glob_star_not, tc)
 	"Test glob(3) ** without GLOB_STAR");
 }
 
-
 ATF_TC_BODY(glob_star_not, tc)
 {
-	run("a/**", 0, glob_star_not, __arraycount(glob_star_not));
+	run("a/**", 0,
+	"a/1", "a/3", "a/4", "a/b");
 }
 
 #if 0



CVS commit: src/tests/lib/libc/gen

2020-03-13 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar 13 22:58:31 UTC 2020

Modified Files:
src/tests/lib/libc/gen: t_glob.c

Log Message:
t_glob.c: add test cases for hidden directory and file

The existing test code was geared towards every little bit of
performance. It even duplicated the file definitions in vfs_stat in order
to avoid a few strcmp calls. This made the test code fragile. Therefore,
vfs_stat has been rewritten completely to not duplicate any information
from the vfs.

In vfs_stat, the returned st_mode is now more realistic. It had been 0
before. The file mode is only logged when it makes sense. In the ENOENT
case it is not logged anymore.

The debug logging for opendir/closedir now logs the same pointer, so that
the corresponding calls can be matched easily. Failed vfs_opendir calls
are logged as well, to get a more complete picture of which callbacks are
called.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/lib/libc/gen/t_glob.c

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

Modified files:

Index: src/tests/lib/libc/gen/t_glob.c
diff -u src/tests/lib/libc/gen/t_glob.c:1.8 src/tests/lib/libc/gen/t_glob.c:1.9
--- src/tests/lib/libc/gen/t_glob.c:1.8	Fri Mar 13 21:44:25 2020
+++ src/tests/lib/libc/gen/t_glob.c	Fri Mar 13 22:58:31 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_glob.c,v 1.8 2020/03/13 21:44:25 rillig Exp $	*/
+/*	$NetBSD: t_glob.c,v 1.9 2020/03/13 22:58:31 rillig Exp $	*/
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_glob.c,v 1.8 2020/03/13 21:44:25 rillig Exp $");
+__RCSID("$NetBSD: t_glob.c,v 1.9 2020/03/13 22:58:31 rillig Exp $");
 
 #include 
 
@@ -75,15 +75,30 @@ static struct vfs_file b[] = {
 	{ "w", 0 },
 };
 
+static struct vfs_file hidden_dir[] = {
+	{ "visible-file", 0 },
+	{ ".hidden-file", 0 },
+};
+
+static struct vfs_file dot[] = {
+	{ "a", 1 },
+	{ ".hidden-dir", 1 },
+};
+
 struct vfs_dir {
 	const char *name;	/* directory name */
 	const struct vfs_file *dir;
 	size_t len, pos;
 };
 
+#define VFS_DIR_INIT(name, entries) \
+{ name, entries, __arraycount(entries), 0 }
+
 static struct vfs_dir d[] = {
-	{ "a", a, __arraycount(a), 0 },
-	{ "a/b", b, __arraycount(b), 0 },
+	VFS_DIR_INIT("a", a),
+	VFS_DIR_INIT("a/b", b),
+	VFS_DIR_INIT(".", dot),
+	VFS_DIR_INIT(".hidden-dir", hidden_dir),
 };
 
 static void
@@ -106,9 +121,10 @@ vfs_opendir(const char *dir)
 
 	for (i = 0; i < __arraycount(d); i++)
 		if (strcmp(buf, d[i].name) == 0) {
-			DPRINTF(("opendir %s %zu\n", buf, i));
+			DPRINTF(("opendir %s %p\n", buf, [i]));
 			return [i];
 		}
+	DPRINTF(("opendir %s ENOENT\n", buf));
 	errno = ENOENT;
 	return NULL;
 }
@@ -138,32 +154,36 @@ vfs_stat(const char *name , __gl_stat_t 
 	trim(buf, sizeof(buf), name);
 	memset(st, 0, sizeof(*st));
 
-	if (strcmp(buf, "a") == 0 || strcmp(buf, "a/b") == 0) {
-		st->st_mode |= S_IFDIR;
-		return 0;
-	}
-
-	if (buf[0] == 'a' && buf[1] == '/') {
-		struct vfs_file *f;
-		size_t offs, count;
-
-		if (buf[2] == 'b' && buf[3] == '/') {
-			offs = 4;
-			count = __arraycount(b);
-			f = b;
-		} else {
-			offs = 2;
-			count = __arraycount(a);
-			f = a;
+	for (size_t i = 0; i < __arraycount(d); i++)
+		if (strcmp(buf, d[i].name) == 0) {
+			st->st_mode = S_IFDIR | 0755;
+			goto out;
 		}
 
-		for (size_t i = 0; i < count; i++)
-			if (strcmp(f[i].name, buf + offs) == 0)
-return 0;
+	for (size_t i = 0; i < __arraycount(d); i++) {
+		size_t dir_len = strlen(d[i].name);
+		if (strncmp(buf, d[i].name, dir_len) != 0)
+			continue;
+		if (buf[dir_len] != '/')
+			continue;
+		const char *base = buf + dir_len + 1;
+		if (strcspn(base, "/") != strlen(base))
+			continue;
+
+		for (size_t j = 0; j < d[i].len; j++)
+			if (strcmp(d[i].dir[j].name, base) == 0) {
+st->st_mode = d[i].dir[j].dir
+? S_IFDIR | 0755
+: S_IFREG | 0644;
+goto out;
+			}
 	}
-	DPRINTF(("stat %s %d\n", buf, st->st_mode));
+	DPRINTF(("stat %s ENOENT\n", buf));
 	errno = ENOENT;
 	return -1;
+out:
+	DPRINTF(("stat %s %06o\n", buf, st->st_mode));
+	return 0;
 }
 
 static int
@@ -216,16 +236,21 @@ run(const char *p, int flags, /* const c
 	}
 
 	for (i = 0; i < gl.gl_pathc; i++)
-		DPRINTF(("%s\n", gl.gl_pathv[i]));
+		DPRINTF(("glob result %zu: %s\n", i, gl.gl_pathv[i]));
 
 	va_list res;
 	va_start(res, flags);
-	const char *expected = NULL;
-	for (i = 0; (expected = va_arg(res, const char *)) != NULL && i < gl.gl_pathc; i++)
-		ATF_CHECK_STREQ(gl.gl_pathv[i], expected);
+	i = 0;
+	const char *name;
+	while ((name = va_arg(res, const char *)) != NULL && i < gl.gl_pathc) {
+		ATF_CHECK_STREQ(gl.gl_pathv[i], name);
+		i++;
+	}
 	va_end(res);
-	ATF_CHECK_EQ(i, gl.gl_pathc);
-	ATF_CHECK_MSG(expected == NULL, "expected \"%s\" to be matched", expected);
+	ATF_CHECK_EQ_MSG(i, gl.gl_pathc,
+	"expected %zu results, got %zu", i, gl.gl_pathc);
+	

CVS commit: src/tests/lib/libc/gen

2020-03-13 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar 13 23:27:55 UTC 2020

Modified Files:
src/tests/lib/libc/gen: t_glob.c

Log Message:
t_glob.c: clean up test code

In struct vfs_file, using an int as a boolean is an anachronism and has
been replaced with a single-character file type, like in ls(1).

Some other redundant test code has been removed as well since it was
either unreachable or existed only for performance reasons.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/lib/libc/gen/t_glob.c

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

Modified files:

Index: src/tests/lib/libc/gen/t_glob.c
diff -u src/tests/lib/libc/gen/t_glob.c:1.9 src/tests/lib/libc/gen/t_glob.c:1.10
--- src/tests/lib/libc/gen/t_glob.c:1.9	Fri Mar 13 22:58:31 2020
+++ src/tests/lib/libc/gen/t_glob.c	Fri Mar 13 23:27:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_glob.c,v 1.9 2020/03/13 22:58:31 rillig Exp $	*/
+/*	$NetBSD: t_glob.c,v 1.10 2020/03/13 23:27:54 rillig Exp $	*/
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_glob.c,v 1.9 2020/03/13 22:58:31 rillig Exp $");
+__RCSID("$NetBSD: t_glob.c,v 1.10 2020/03/13 23:27:54 rillig Exp $");
 
 #include 
 
@@ -57,38 +57,39 @@ __RCSID("$NetBSD: t_glob.c,v 1.9 2020/03
 #endif
 
 struct vfs_file {
+	char type;		/* 'd' or '-', like in ls(1) */
 	const char *name;
-	int dir;
 };
 
 static struct vfs_file a[] = {
-	{ "1", 0 },
-	{ "b", 1 },
-	{ "3", 0 },
-	{ "4", 0 },
+	{ '-', "1" },
+	{ 'd', "b" },
+	{ '-', "3" },
+	{ '-', "4" },
 };
 
 static struct vfs_file b[] = {
-	{ "x", 0 },
-	{ "y", 0 },
-	{ "z", 0 },
-	{ "w", 0 },
+	{ '-', "x" },
+	{ '-', "y" },
+	{ '-', "z" },
+	{ '-', "w" },
 };
 
 static struct vfs_file hidden_dir[] = {
-	{ "visible-file", 0 },
-	{ ".hidden-file", 0 },
+	{ '-', "visible-file" },
+	{ '-', ".hidden-file" },
 };
 
 static struct vfs_file dot[] = {
-	{ "a", 1 },
-	{ ".hidden-dir", 1 },
+	{ 'd', "a" },
+	{ 'd', ".hidden-dir" },
 };
 
 struct vfs_dir {
-	const char *name;	/* directory name */
-	const struct vfs_file *dir;
-	size_t len, pos;
+	const char *name;	/* full directory name */
+	const struct vfs_file *entries;
+	size_t entries_len;
+	size_t pos;		/* only between opendir/closedir */
 };
 
 #define VFS_DIR_INIT(name, entries) \
@@ -134,12 +135,12 @@ vfs_readdir(void *v)
 {
 	static struct dirent dir;
 	struct vfs_dir *dd = v;
-	if (dd->pos < dd->len) {
-		const struct vfs_file *f = >dir[dd->pos++];
+	if (dd->pos < dd->entries_len) {
+		const struct vfs_file *f = >entries[dd->pos++];
 		strcpy(dir.d_name, f->name);
 		dir.d_namlen = strlen(f->name);
 		dir.d_ino = dd->pos;
-		dir.d_type = f->dir ? DT_DIR : DT_REG;
+		dir.d_type = f->type == 'd' ? DT_DIR : DT_REG;
 		DPRINTF(("readdir %s %d\n", dir.d_name, dir.d_type));
 		dir.d_reclen = _DIRENT_RECLEN(, dir.d_namlen);
 		return 
@@ -167,16 +168,15 @@ vfs_stat(const char *name , __gl_stat_t 
 		if (buf[dir_len] != '/')
 			continue;
 		const char *base = buf + dir_len + 1;
-		if (strcspn(base, "/") != strlen(base))
-			continue;
 
-		for (size_t j = 0; j < d[i].len; j++)
-			if (strcmp(d[i].dir[j].name, base) == 0) {
-st->st_mode = d[i].dir[j].dir
-? S_IFDIR | 0755
-: S_IFREG | 0644;
-goto out;
-			}
+		for (size_t j = 0; j < d[i].entries_len; j++) {
+			const struct vfs_file *f = [i].entries[j];
+			if (strcmp(f->name, base) != 0)
+continue;
+			ATF_CHECK(f->type != 'd'); // handled above
+			st->st_mode = S_IFREG | 0644;
+			goto out;
+		}
 	}
 	DPRINTF(("stat %s ENOENT\n", buf));
 	errno = ENOENT;



CVS commit: src

2020-04-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Apr 29 23:15:22 UTC 2020

Modified Files:
src/distrib/sets/lists/tests: mi
src/usr.bin/make/unit-tests: Makefile
Added Files:
src/usr.bin/make/unit-tests: cond-late.exp cond-late.mk

Log Message:
usr.bin/make: add test case for lazy conditions


To generate a diff of this commit:
cvs rdiff -u -r1.837 -r1.838 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.54 -r1.55 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r0 -r1.1 src/usr.bin/make/unit-tests/cond-late.exp \
src/usr.bin/make/unit-tests/cond-late.mk

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

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.837 src/distrib/sets/lists/tests/mi:1.838
--- src/distrib/sets/lists/tests/mi:1.837	Sun Apr 26 18:53:32 2020
+++ src/distrib/sets/lists/tests/mi	Wed Apr 29 23:15:22 2020
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.837 2020/04/26 18:53:32 thorpej Exp $
+# $NetBSD: mi,v 1.838 2020/04/29 23:15:22 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -4462,6 +4462,8 @@
 ./usr/tests/usr.bin/make/unit-tests/Makefile	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/comment.exp	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/comment.mk	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-late.exp	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-late.mk	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond1.exp	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond1.mk	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond2.exp	tests-usr.bin-tests	compattestfile,atf

Index: src/usr.bin/make/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.54 src/usr.bin/make/unit-tests/Makefile:1.55
--- src/usr.bin/make/unit-tests/Makefile:1.54	Sat Nov 30 00:38:51 2019
+++ src/usr.bin/make/unit-tests/Makefile	Wed Apr 29 23:15:21 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.54 2019/11/30 00:38:51 rillig Exp $
+# $NetBSD: Makefile,v 1.55 2020/04/29 23:15:21 rillig Exp $
 #
 # Unit tests for make(1)
 # The main targets are:
@@ -22,6 +22,7 @@ UNIT_TESTS:= ${.PARSEDIR}
 # Keep the list sorted.
 TESTNAMES= \
 	comment \
+	cond-late \
 	cond1 \
 	cond2 \
 	error \

Added files:

Index: src/usr.bin/make/unit-tests/cond-late.exp
diff -u /dev/null src/usr.bin/make/unit-tests/cond-late.exp:1.1
--- /dev/null	Wed Apr 29 23:15:22 2020
+++ src/usr.bin/make/unit-tests/cond-late.exp	Wed Apr 29 23:15:21 2020
@@ -0,0 +1,2 @@
+yes
+no
Index: src/usr.bin/make/unit-tests/cond-late.mk
diff -u /dev/null src/usr.bin/make/unit-tests/cond-late.mk:1.1
--- /dev/null	Wed Apr 29 23:15:22 2020
+++ src/usr.bin/make/unit-tests/cond-late.mk	Wed Apr 29 23:15:21 2020
@@ -0,0 +1,23 @@
+# $NetBSD: cond-late.mk,v 1.1 2020/04/29 23:15:21 rillig Exp $
+#
+# Using the :? modifier, variable expressions can contain conditional
+# expressions that are evaluated late.  Any variables appearing in these
+# conditions are expanded before parsing the condition.  This is
+# different from many other places.
+#
+# Because of this, variables that are used in these lazy conditions
+# should not contain double-quotes, or the parser will probably fail.
+#
+# They should also not contain operators like == or <, since these are
+# actually interpreted as these operators. This is demonstrated below.
+#
+# If the order of evaluation were to change to first parse the condition
+# and then expand the variables, the output would change from the
+# current "yes no" to "yes yes", since both variables are non-empty.
+
+COND.true=	"yes" == "yes"
+COND.false=	"yes" != "yes"
+
+all:
+	@echo ${ ${COND.true} :?yes:no}
+	@echo ${ ${COND.false} :?yes:no}



CVS commit: src/usr.bin/make/unit-tests

2020-05-17 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 17 09:37:48 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: dollar.exp dollar.mk

Log Message:
usr.bin/make: fix test for dollar and backslash at eol

The previous version of this test relied on the way how the shell
interprets a lonely backslash at the end of the line.  The NetBSD and
FreeBSD shells print the backslash, while Bash doesn't.

While here, make the escaping a bit simpler and align the test
descriptions with the actual test data.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/dollar.exp \
src/usr.bin/make/unit-tests/dollar.mk

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/unit-tests/dollar.exp
diff -u src/usr.bin/make/unit-tests/dollar.exp:1.2 src/usr.bin/make/unit-tests/dollar.exp:1.3
--- src/usr.bin/make/unit-tests/dollar.exp:1.2	Sun May 10 13:03:40 2020
+++ src/usr.bin/make/unit-tests/dollar.exp	Sun May 17 09:37:48 2020
@@ -2,7 +2,8 @@
 Printing dollar from literals and variables
 
 To survive the parser, a dollar character must be doubled.
-   1 dollar literal => <\>
+   1 dollar literal => 
+   1 dollar literal eol => <>
2 dollar literal => <$>
4 dollar literal => <$$>
 Some hungry part of make eats all the dollars after a :U modifier.
@@ -33,13 +34,13 @@ Dollar in :C character class
 The A is replaced because the $$ is reduced to a single $,
 which is then resolved to the variable X with the value VAR_X.
 The effective character class becomes [VAR_XY].
-  C,[$XY],<&>,g => <$>
+ C,[$$XY],<&>,g => <$>
 
 Dollar in :C pattern
 
 For some reason, multiple dollars are folded into one.
-  C,$,word, => <>
- C,$$,word, => <>
+   C,$,dollar,g => <>
+  C,$$,dollar,g => <>
 
 Dollar in :S replacement
 
Index: src/usr.bin/make/unit-tests/dollar.mk
diff -u src/usr.bin/make/unit-tests/dollar.mk:1.2 src/usr.bin/make/unit-tests/dollar.mk:1.3
--- src/usr.bin/make/unit-tests/dollar.mk:1.2	Sun May 10 13:03:40 2020
+++ src/usr.bin/make/unit-tests/dollar.mk	Sun May 17 09:37:48 2020
@@ -1,4 +1,4 @@
-# $NetBSD: dollar.mk,v 1.2 2020/05/10 13:03:40 rillig Exp $
+# $NetBSD: dollar.mk,v 1.3 2020/05/17 09:37:48 rillig Exp $
 #
 # Test the various places where a dollar character can appear and
 # see what happens.  There are lots of surprises here.
@@ -19,13 +19,22 @@ H=	@header()	{ printf '\n%s\n\n' "$$*"; 
 T=	@testcase()	{ printf '%23s => <%s>\n' "$$@"; }; testcase
 C=	@comment()	{ printf '%s\n' "$$*"; }; comment
 
+# These variable values are not accessed.
+# The trailing dollar in the '1 dollar literal eol' test case accesses
+# the empty variable instead, which is always guaranteed to be empty.
+${:U }=			space-var-value
+${:U${.newline}}=	newline-var-value
+# But this one is accessed.
+${:U'}=			single-quote-var-value'
+
 all:
 	$H 'Printing dollar from literals and variables'
 
 	$C 'To survive the parser, a dollar character must be doubled.'
-	$T	'1 dollar literal'	''\$
-	$T	'2 dollar literal'	''\$$
-	$T	'4 dollar literal'	''\$$\$$
+	$T	'1 dollar literal'	'$'
+	$T	'1 dollar literal eol'	''$
+	$T	'2 dollar literal'	'$$'
+	$T	'4 dollar literal'	''
 
 	$C 'Some hungry part of make eats all the dollars after a :U modifier.'
 	$T	'1 dollar default'	''${:U$:Q}
@@ -58,12 +67,12 @@ all:
 	$C 'The A is replaced because the  is reduced to a single $$,'
 	$C 'which is then resolved to the variable X with the value VAR_X.'
 	$C 'The effective character class becomes [VAR_XY].'
-	$T	'C,[$$XY],<&>,g'	''${DOLLAR_AXY:C,[$$XY],<&>,g:Q}
+	$T	'C,[XY],<&>,g'	''${DOLLAR_AXY:C,[$$XY],<&>,g:Q}
 
 	$H 'Dollar in :C pattern'
 	$C 'For some reason, multiple dollars are folded into one.'
-	$T	'C,$$,word,'		''${DOLLAR:C,$,dollar,g:Q}
-	$T	'C,,word,'		''${DOLLAR:C,$$,dollar,g:Q}
+	$T	'C,$$,dollar,g'		''${DOLLAR:C,$,dollar,g:Q}
+	$T	'C,,dollar,g'	''${DOLLAR:C,$$,dollar,g:Q}
 
 	$H 'Dollar in :S replacement'
 	$C 'For some reason, multiple dollars are folded into one.'



CVS commit: src

2020-05-17 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 17 12:36:26 UTC 2020

Modified Files:
src/distrib/sets/lists/tests: mi
src/usr.bin/make/unit-tests: Makefile
Added Files:
src/usr.bin/make/unit-tests: include-main.exp include-main.mk
include-sub.mk include-subsub.mk

Log Message:
usr.bin/make: demonstrate actual behavior of .INCLUDEDFROMFILE


To generate a diff of this commit:
cvs rdiff -u -r1.840 -r1.841 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.57 -r1.58 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r0 -r1.1 src/usr.bin/make/unit-tests/include-main.exp \
src/usr.bin/make/unit-tests/include-main.mk \
src/usr.bin/make/unit-tests/include-sub.mk \
src/usr.bin/make/unit-tests/include-subsub.mk

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

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.840 src/distrib/sets/lists/tests/mi:1.841
--- src/distrib/sets/lists/tests/mi:1.840	Sun May 10 12:34:01 2020
+++ src/distrib/sets/lists/tests/mi	Sun May 17 12:36:26 2020
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.840 2020/05/10 12:34:01 rillig Exp $
+# $NetBSD: mi,v 1.841 2020/05/17 12:36:26 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -4493,6 +4493,10 @@
 ./usr/tests/usr.bin/make/unit-tests/hash.mk	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/impsrc.exp	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/impsrc.mk	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/include-main.exp	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/include-main.mk	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/include-sub.mk	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/include-subsub.mk	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/misc.exp	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/misc.mk	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/moderrs.exp	tests-usr.bin-tests	compattestfile,atf

Index: src/usr.bin/make/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.57 src/usr.bin/make/unit-tests/Makefile:1.58
--- src/usr.bin/make/unit-tests/Makefile:1.57	Sun May 10 12:42:11 2020
+++ src/usr.bin/make/unit-tests/Makefile	Sun May 17 12:36:26 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.57 2020/05/10 12:42:11 rillig Exp $
+# $NetBSD: Makefile,v 1.58 2020/05/17 12:36:26 rillig Exp $
 #
 # Unit tests for make(1)
 # The main targets are:
@@ -35,6 +35,7 @@ TESTNAMES= \
 	forloop \
 	forsubst \
 	hash \
+	include-main \
 	misc \
 	moderrs \
 	modmatch \

Added files:

Index: src/usr.bin/make/unit-tests/include-main.exp
diff -u /dev/null src/usr.bin/make/unit-tests/include-main.exp:1.1
--- /dev/null	Sun May 17 12:36:26 2020
+++ src/usr.bin/make/unit-tests/include-main.exp	Sun May 17 12:36:26 2020
@@ -0,0 +1,6 @@
+main-before-ok
+sub-before-ok
+subsub-ok
+sub-after-fail(include-sub.mk)
+main-after-fail(include-sub.mk)
+exit status 0
Index: src/usr.bin/make/unit-tests/include-main.mk
diff -u /dev/null src/usr.bin/make/unit-tests/include-main.mk:1.1
--- /dev/null	Sun May 17 12:36:26 2020
+++ src/usr.bin/make/unit-tests/include-main.mk	Sun May 17 12:36:26 2020
@@ -0,0 +1,30 @@
+# $NetBSD: include-main.mk,v 1.1 2020/05/17 12:36:26 rillig Exp $
+#
+# Demonstrates that the .INCLUDEDFROMFILE magic variable does not behave
+# as described in the manual page.
+#
+# The manual page says that it is the "filename of the file this Makefile
+# was included from", while in reality it is the "filename in which the
+# latest .include happened".
+#
+
+.if !defined(.INCLUDEDFROMFILE)
+LOG+=		main-before-ok
+.else
+.  for f in ${.INCLUDEDFROMFILE}
+LOG+=		main-before-fail\(${f:Q}\)
+.  endfor
+.endif
+
+.include "include-sub.mk"
+
+.if !defined(.INCLUDEDFROMFILE)
+LOG+=		main-after-ok
+.else
+.  for f in ${.INCLUDEDFROMFILE}
+LOG+=		main-after-fail\(${f:Q}\)
+.  endfor
+.endif
+
+all:
+	@printf '%s\n' ${LOG}
Index: src/usr.bin/make/unit-tests/include-sub.mk
diff -u /dev/null src/usr.bin/make/unit-tests/include-sub.mk:1.1
--- /dev/null	Sun May 17 12:36:26 2020
+++ src/usr.bin/make/unit-tests/include-sub.mk	Sun May 17 12:36:26 2020
@@ -0,0 +1,17 @@
+# $NetBSD: include-sub.mk,v 1.1 2020/05/17 12:36:26 rillig Exp $
+
+.if ${.INCLUDEDFROMFILE} == "include-main.mk"
+LOG+=		sub-before-ok
+.else
+LOG+=		sub-before-fail
+.endif
+
+.include "include-subsub.mk"
+
+.if ${.INCLUDEDFROMFILE} == "include-main.mk"
+LOG+=		sub-after-ok
+.else
+.  for f in ${.INCLUDEDFROMFILE}
+LOG+=		sub-after-fail\(${f:Q}\)
+.  endfor
+.endif
Index: src/usr.bin/make/unit-tests/include-subsub.mk
diff -u /dev/null src/usr.bin/make/unit-tests/include-subsub.mk:1.1
--- /dev/null	Sun May 17 12:36:26 2020
+++ 

CVS commit: src/usr.bin/make/unit-tests

2020-05-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 10 12:42:11 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: Makefile

Log Message:
usr.bin/make: sort test cases alphabetically


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/usr.bin/make/unit-tests/Makefile

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/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.56 src/usr.bin/make/unit-tests/Makefile:1.57
--- src/usr.bin/make/unit-tests/Makefile:1.56	Sun May 10 12:34:01 2020
+++ src/usr.bin/make/unit-tests/Makefile	Sun May 10 12:42:11 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.56 2020/05/10 12:34:01 rillig Exp $
+# $NetBSD: Makefile,v 1.57 2020/05/10 12:42:11 rillig Exp $
 #
 # Unit tests for make(1)
 # The main targets are:
@@ -26,12 +26,12 @@ TESTNAMES= \
 	cond1 \
 	cond2 \
 	dollar \
+	doterror \
+	dotwait \
 	error \
 	export \
 	export-all \
 	export-env \
-	doterror \
-	dotwait \
 	forloop \
 	forsubst \
 	hash \



CVS commit: src

2020-05-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 10 12:34:01 UTC 2020

Modified Files:
src/distrib/sets/lists/tests: mi
src/usr.bin/make/unit-tests: Makefile
Added Files:
src/usr.bin/make/unit-tests: dollar.exp dollar.mk

Log Message:
usr.bin/make: add tests for surprising dollar removal


To generate a diff of this commit:
cvs rdiff -u -r1.839 -r1.840 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.55 -r1.56 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r0 -r1.1 src/usr.bin/make/unit-tests/dollar.exp \
src/usr.bin/make/unit-tests/dollar.mk

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

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.839 src/distrib/sets/lists/tests/mi:1.840
--- src/distrib/sets/lists/tests/mi:1.839	Thu Apr 30 11:03:29 2020
+++ src/distrib/sets/lists/tests/mi	Sun May 10 12:34:01 2020
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.839 2020/04/30 11:03:29 ryo Exp $
+# $NetBSD: mi,v 1.840 2020/05/10 12:34:01 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -4469,6 +4469,8 @@
 ./usr/tests/usr.bin/make/unit-tests/cond1.mk	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond2.exp	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond2.mk	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/dollar.exp	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/dollar.mk	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/doterror.exp	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/doterror.mk	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/dotwait.exp	tests-usr.bin-tests	compattestfile,atf

Index: src/usr.bin/make/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.55 src/usr.bin/make/unit-tests/Makefile:1.56
--- src/usr.bin/make/unit-tests/Makefile:1.55	Wed Apr 29 23:15:21 2020
+++ src/usr.bin/make/unit-tests/Makefile	Sun May 10 12:34:01 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.55 2020/04/29 23:15:21 rillig Exp $
+# $NetBSD: Makefile,v 1.56 2020/05/10 12:34:01 rillig Exp $
 #
 # Unit tests for make(1)
 # The main targets are:
@@ -25,6 +25,7 @@ TESTNAMES= \
 	cond-late \
 	cond1 \
 	cond2 \
+	dollar \
 	error \
 	export \
 	export-all \

Added files:

Index: src/usr.bin/make/unit-tests/dollar.exp
diff -u /dev/null src/usr.bin/make/unit-tests/dollar.exp:1.1
--- /dev/null	Sun May 10 12:34:01 2020
+++ src/usr.bin/make/unit-tests/dollar.exp	Sun May 10 12:34:01 2020
@@ -0,0 +1,50 @@
+
+Printing dollar from literals and variables
+
+To survive the parser, a dollar character must be doubled.
+   1 dollar literal => <\>
+   2 dollar literal => <$>
+   4 dollar literal => <$$>
+Some hungry part of make eats all the dollars after a :U modifier.
+   1 dollar default => <>
+   2 dollar default => <>
+   4 dollar default => <>
+This works as expected.
+  1 dollar variable => <>
+  2 dollar variable => <$>
+  4 dollar variable => <$$>
+Some hungry part of make eats all the dollars after a :U modifier.
+   1 dollar var-default => <>
+   2 dollar var-default => <>
+   4 dollar var-default => <>
+
+Dollar in :S pattern
+
+  S,$,word, => <$XYword>
+ S,$X,word, => <$XY>
+S,$$X,word, => <$XY>
+   S,$$$X,word, => <$XY>
+ S,$X,replaced, => 
+S,$$X,replaced, => 
+   S,$$$X,replaced, => 
+
+Dollar in :C character class
+
+The A is replaced because the $$ is reduced to a single $,
+which is then resolved to the variable X with the value VAR_X.
+The effective character class becomes [VAR_XY].
+  C,[$XY],<&>,g => <$>
+
+Dollar in :C pattern
+
+For some reason, multiple dollars are folded into one.
+  C,$,word, => <>
+ C,$$,word, => <>
+
+Dollar in :S replacement
+
+For some reason, multiple dollars are folded into one.
+   S,word,a$Xo, => 
+  S,word,a$$Xo, => 
+ S,word,a$$$Xo, => 
+exit status 0
Index: src/usr.bin/make/unit-tests/dollar.mk
diff -u /dev/null src/usr.bin/make/unit-tests/dollar.mk:1.1
--- /dev/null	Sun May 10 12:34:01 2020
+++ src/usr.bin/make/unit-tests/dollar.mk	Sun May 10 12:34:01 2020
@@ -0,0 +1,72 @@
+# $NetBSD: dollar.mk,v 1.1 2020/05/10 12:34:01 rillig Exp $
+#
+# Test the various places where a dollar character can appear and
+# see what happens.  There are lots of surprises here.
+#
+
+LIST=		plain 'single' "double" 'mix'"ed" back\ slashed
+WORD=		word
+
+DOLLAR1=	$
+DOLLAR2=	$$
+DOLLAR4=	
+
+X=		VAR_X
+DOLLAR_XY=	$$XY
+DOLLAR_AXY=	$$AXY
+
+H=	@header()	{ printf '\n%s\n\n' "$$*"; }; header
+T=	@testcase()	{ printf '%23s => <%s>\n' "$$@"; }; testcase
+C=	@comment()	{ printf '%s\n' "$$*"; }; comment
+
+all:
+	$H 'Printing dollar from literals and 

CVS commit: src/usr.bin/make/unit-tests

2020-05-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 10 13:03:40 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: dollar.exp dollar.mk

Log Message:
usr.bin/make: fix typo in dollar test


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/dollar.exp \
src/usr.bin/make/unit-tests/dollar.mk

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/unit-tests/dollar.exp
diff -u src/usr.bin/make/unit-tests/dollar.exp:1.1 src/usr.bin/make/unit-tests/dollar.exp:1.2
--- src/usr.bin/make/unit-tests/dollar.exp:1.1	Sun May 10 12:34:01 2020
+++ src/usr.bin/make/unit-tests/dollar.exp	Sun May 10 13:03:40 2020
@@ -15,8 +15,8 @@ This works as expected.
   4 dollar variable => <$$>
 Some hungry part of make eats all the dollars after a :U modifier.
1 dollar var-default => <>
-   2 dollar var-default => <>
-   4 dollar var-default => <>
+   2 dollar var-default => <$>
+   4 dollar var-default => <$$>
 
 Dollar in :S pattern
 
Index: src/usr.bin/make/unit-tests/dollar.mk
diff -u src/usr.bin/make/unit-tests/dollar.mk:1.1 src/usr.bin/make/unit-tests/dollar.mk:1.2
--- src/usr.bin/make/unit-tests/dollar.mk:1.1	Sun May 10 12:34:01 2020
+++ src/usr.bin/make/unit-tests/dollar.mk	Sun May 10 13:03:40 2020
@@ -1,4 +1,4 @@
-# $NetBSD: dollar.mk,v 1.1 2020/05/10 12:34:01 rillig Exp $
+# $NetBSD: dollar.mk,v 1.2 2020/05/10 13:03:40 rillig Exp $
 #
 # Test the various places where a dollar character can appear and
 # see what happens.  There are lots of surprises here.
@@ -38,9 +38,9 @@ all:
 	$T	'4 dollar variable'	''${DOLLAR4:Q}
 
 	$C 'Some hungry part of make eats all the dollars after a :U modifier.'
-	$T	'1 dollar var-default'	''${U:${DOLLAR1}:Q}
-	$T	'2 dollar var-default'	''${U:${DOLLAR2}:Q}
-	$T	'4 dollar var-default'	''${U:${DOLLAR4}:Q}
+	$T	'1 dollar var-default'	''${:U${DOLLAR1}:Q}
+	$T	'2 dollar var-default'	''${:U${DOLLAR2}:Q}
+	$T	'4 dollar var-default'	''${:U${DOLLAR4}:Q}
 
 	$H 'Dollar in :S pattern'
 



CVS commit: src/usr.bin/make

2020-05-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May  3 12:10:28 UTC 2020

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

Log Message:
usr.bin/make: refactor brk_string

The variables are renamed to reflect to which memory region each pointer
belongs.

The variable "curlen" was always zero.

The type of "ch" has changed to char, and its scope is now limited to
its actual use.

Comparisons of pointers are now consistently written as p != NULL
instead of !p, like character comparisons are written as ch != '\0'.

The "store_words_buf" is updated when the function returns, not before.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/usr.bin/make/str.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/str.c
diff -u src/usr.bin/make/str.c:1.40 src/usr.bin/make/str.c:1.41
--- src/usr.bin/make/str.c:1.40	Sat Apr 25 18:20:57 2020
+++ src/usr.bin/make/str.c	Sun May  3 12:10:28 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: str.c,v 1.40 2020/04/25 18:20:57 christos Exp $	*/
+/*	$NetBSD: str.c,v 1.41 2020/05/03 12:10:28 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: str.c,v 1.40 2020/04/25 18:20:57 christos Exp $";
+static char rcsid[] = "$NetBSD: str.c,v 1.41 2020/05/03 12:10:28 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)str.c	5.8 (Berkeley) 6/1/90";
 #else
-__RCSID("$NetBSD: str.c,v 1.40 2020/04/25 18:20:57 christos Exp $");
+__RCSID("$NetBSD: str.c,v 1.41 2020/05/03 12:10:28 rillig Exp $");
 #endif
 #endif/* not lint */
 #endif
@@ -133,42 +133,43 @@ str_concat(const char *s1, const char *s
  *
  * returns --
  *	Pointer to the array of pointers to the words.
- *  Memory containing the actual words in *buffer.
+ *  Memory containing the actual words in *store_words_buf.
  *		Both of these must be free'd by the caller.
- *  Number of words in *store_argc.
+ *  Number of words in *store_words_len.
  */
 char **
-brk_string(const char *str, int *store_argc, Boolean expand, char **buffer)
+brk_string(const char *str, int *store_words_len, Boolean expand,
+	char **store_words_buf)
 {
-	int argc, ch;
-	char inquote, *start, *t;
-	const char *p;
-	int len;
-	int argmax = 50, curlen = 0;
-	char **argv;
+	char inquote;
+	const char *str_p;
+	size_t str_len;
+	char **words;
+	int words_len;
+	int words_cap = 50;
+	char *words_buf, *word_start, *word_end;
 
 	/* skip leading space chars. */
 	for (; *str == ' ' || *str == '\t'; ++str)
 		continue;
 
-	/* allocate room for a copy of the string */
-	if ((len = strlen(str) + 1) > curlen)
-		*buffer = bmake_malloc(curlen = len);
+	/* words_buf holds the words, separated by '\0'. */
+	str_len = strlen(str);
+	words_buf = bmake_malloc(strlen(str) + 1);
 
-	/*
-	 * initial argmax based on len
-	 */
-	argmax = MAX((len / 5), 50);
-	argv = bmake_malloc((argmax + 1) * sizeof(char *));
+	words_cap = MAX((str_len / 5), 50);
+	words = bmake_malloc((words_cap + 1) * sizeof(char *));
 
 	/*
 	 * copy the string; at the same time, parse backslashes,
-	 * quotes and build the argument list.
+	 * quotes and build the word list.
 	 */
-	argc = 0;
+	words_len = 0;
 	inquote = '\0';
-	for (p = str, start = t = *buffer;; ++p) {
-		switch(ch = *p) {
+	word_start = word_end = words_buf;
+	for (str_p = str;; ++str_p) {
+		char ch = *str_p;
+		switch(ch) {
 		case '"':
 		case '\'':
 			if (inquote) {
@@ -180,21 +181,21 @@ brk_string(const char *str, int *store_a
 			else {
 inquote = (char) ch;
 /* Don't miss "" or '' */
-if (start == NULL && p[1] == inquote) {
+if (word_start == NULL && str_p[1] == inquote) {
 	if (!expand) {
-		start = t;
-		*t++ = ch;
+		word_start = word_end;
+		*word_end++ = ch;
 	} else
-		start = t + 1;
-	p++;
+		word_start = word_end + 1;
+	str_p++;
 	inquote = '\0';
 	break;
 }
 			}
 			if (!expand) {
-if (!start)
-	start = t;
-*t++ = ch;
+if (word_start == NULL)
+	word_start = word_end;
+*word_end++ = ch;
 			}
 			continue;
 		case ' ':
@@ -202,30 +203,30 @@ brk_string(const char *str, int *store_a
 		case '\n':
 			if (inquote)
 break;
-			if (!start)
+			if (word_start == NULL)
 continue;
 			/* FALLTHROUGH */
 		case '\0':
 			/*
-			 * end of a token -- make sure there's enough argv
+			 * end of a token -- make sure there's enough words
 			 * space and save off a pointer.
 			 */
-			if (!start)
+			if (word_start == NULL)
 			goto done;
 
-			*t++ = '\0';
-			if (argc == argmax) {
-argmax *= 2;		/* ramp up fast */
-argv = (char **)bmake_realloc(argv,
-(argmax + 1) * sizeof(char *));
+			*word_end++ = '\0';
+			if (words_len == words_cap) {
+words_cap *= 2;		/* ramp up fast */
+words = (char **)bmake_realloc(words,
+(words_cap + 1) * 

CVS commit: src/usr.bin/make/unit-tests

2020-05-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri May  1 16:26:41 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: cond-late.exp

Log Message:
usr.bin/make: fix test for late evaluated condition


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/cond-late.exp

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/unit-tests/cond-late.exp
diff -u src/usr.bin/make/unit-tests/cond-late.exp:1.1 src/usr.bin/make/unit-tests/cond-late.exp:1.2
--- src/usr.bin/make/unit-tests/cond-late.exp:1.1	Wed Apr 29 23:15:21 2020
+++ src/usr.bin/make/unit-tests/cond-late.exp	Fri May  1 16:26:41 2020
@@ -1,2 +1,3 @@
 yes
 no
+exit status 0



CVS commit: src/usr.bin/make/unit-tests

2020-05-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri May  1 16:29:34 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: forloop.exp forloop.mk

Log Message:
usr.bin/make: add test demonstrating that .for stops at newline


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/forloop.exp \
src/usr.bin/make/unit-tests/forloop.mk

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/unit-tests/forloop.exp
diff -u src/usr.bin/make/unit-tests/forloop.exp:1.1 src/usr.bin/make/unit-tests/forloop.exp:1.2
--- src/usr.bin/make/unit-tests/forloop.exp:1.1	Thu Aug 21 13:44:51 2014
+++ src/usr.bin/make/unit-tests/forloop.exp	Fri May  1 16:29:34 2020
@@ -7,12 +7,13 @@ x=-I"This or that"
 x=-Ithat
 x="-DTHIS=\"this and that\""
 cfl=-I/this -I"This or that" -Ithat "-DTHIS=\"this and that\""
+newline-item=(a)
 a=one b="two and three"
 a=four b="five"
 a=ONE b="TWO AND THREE"
 a=FOUR b="FIVE"
 We expect an error next:
-make: "forloop.mk" line 38: Wrong number of words (9) in .for substitution list with 2 vars
+make: "forloop.mk" line 46: Wrong number of words (9) in .for substitution list with 2 vars
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 OK
Index: src/usr.bin/make/unit-tests/forloop.mk
diff -u src/usr.bin/make/unit-tests/forloop.mk:1.1 src/usr.bin/make/unit-tests/forloop.mk:1.2
--- src/usr.bin/make/unit-tests/forloop.mk:1.1	Thu Aug 21 13:44:51 2014
+++ src/usr.bin/make/unit-tests/forloop.mk	Fri May  1 16:29:34 2020
@@ -1,4 +1,4 @@
-# $Id: forloop.mk,v 1.1 2014/08/21 13:44:51 apb Exp $
+# $Id: forloop.mk,v 1.2 2020/05/01 16:29:34 rillig Exp $
 
 all: for-loop
 
@@ -33,7 +33,15 @@ X!= echo 'cfl=${cfl}' >&2; echo
 .for a b in ${EMPTY}
 X!= echo 'a=$a b=$b' >&2; echo
 .endfor
-.endif
+
+# Since at least 1993, iteration stops at the first newline.
+# Back then, the .newline variable didn't exist, therefore it was unlikely
+# that a newline ever occured.
+.for var in a${.newline}b${.newline}c
+X!= echo 'newline-item=('${var:Q}')' 1>&2; echo
+.endfor
+
+.endif	# for-fail
 
 .for a b in ${LIST} ${LIST:tu} ${XTRA_LIST}
 X!= echo 'a=$a b=$b' >&2; echo



CVS commit: src/usr.bin/make

2020-08-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Aug 30 13:53:02 UTC 2020

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

Log Message:
make(1): remove ineffective malloc_options variable

According to jemalloc(3), the variable must be called _malloc_options,
with a leading underscore, to have an effect.

Renaming the variable indeed enables the option.  There's not much point
having this variable around though, since it neither detects a trivial
double-free nor freeing an invalid pointer in the following code
snippet:

char *asdf = bmake_malloc(10);
fprintf(stderr, "%c\n", *asdf);
free(asdf + 8);
free(asdf);
free(asdf);
exit(1);

Instead, it just crashes with a segmentation fault.


To generate a diff of this commit:
cvs rdiff -u -r1.225 -r1.226 src/usr.bin/make/job.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/job.c
diff -u src/usr.bin/make/job.c:1.225 src/usr.bin/make/job.c:1.226
--- src/usr.bin/make/job.c:1.225	Sun Aug 30 11:12:05 2020
+++ src/usr.bin/make/job.c	Sun Aug 30 13:53:02 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.225 2020/08/30 11:12:05 rillig Exp $	*/
+/*	$NetBSD: job.c,v 1.226 2020/08/30 13:53:02 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: job.c,v 1.225 2020/08/30 11:12:05 rillig Exp $";
+static char rcsid[] = "$NetBSD: job.c,v 1.226 2020/08/30 13:53:02 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)job.c	8.2 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: job.c,v 1.225 2020/08/30 11:12:05 rillig Exp $");
+__RCSID("$NetBSD: job.c,v 1.226 2020/08/30 13:53:02 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -352,8 +352,6 @@ static void JobSigLock(sigset_t *);
 static void JobSigUnlock(sigset_t *);
 static void JobSigReset(void);
 
-const char *malloc_options MAKE_ATTR_UNUSED = "A"; /* see jemalloc(3) */
-
 static unsigned
 nfds_per_job(void)
 {



CVS commit: src/usr.bin/make

2020-08-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Aug 30 11:12:06 UTC 2020

Modified Files:
src/usr.bin/make: compat.c dir.c job.c lst.c lst.h make.c suff.c

Log Message:
make(1): rename Lst_Memeber to Lst_FindDatum

The new name nicely aligns with Lst_Find and Lst_FindFrom.


To generate a diff of this commit:
cvs rdiff -u -r1.135 -r1.136 src/usr.bin/make/compat.c
cvs rdiff -u -r1.124 -r1.125 src/usr.bin/make/dir.c
cvs rdiff -u -r1.224 -r1.225 src/usr.bin/make/job.c
cvs rdiff -u -r1.56 -r1.57 src/usr.bin/make/lst.c
cvs rdiff -u -r1.57 -r1.58 src/usr.bin/make/lst.h
cvs rdiff -u -r1.130 -r1.131 src/usr.bin/make/make.c
cvs rdiff -u -r1.136 -r1.137 src/usr.bin/make/suff.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/compat.c
diff -u src/usr.bin/make/compat.c:1.135 src/usr.bin/make/compat.c:1.136
--- src/usr.bin/make/compat.c:1.135	Sat Aug 29 14:47:26 2020
+++ src/usr.bin/make/compat.c	Sun Aug 30 11:12:05 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat.c,v 1.135 2020/08/29 14:47:26 rillig Exp $	*/
+/*	$NetBSD: compat.c,v 1.136 2020/08/30 11:12:05 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: compat.c,v 1.135 2020/08/29 14:47:26 rillig Exp $";
+static char rcsid[] = "$NetBSD: compat.c,v 1.136 2020/08/30 11:12:05 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)compat.c	8.2 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: compat.c,v 1.135 2020/08/29 14:47:26 rillig Exp $");
+__RCSID("$NetBSD: compat.c,v 1.136 2020/08/30 11:12:05 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -220,7 +220,7 @@ CompatRunCommand(void *cmdp, void *gnp)
 errCheck = !(gn->type & OP_IGNORE);
 doIt = FALSE;
 
-cmdNode = Lst_Member(gn->commands, cmd);
+cmdNode = Lst_FindDatum(gn->commands, cmd);
 cmdStart = Var_Subst(cmd, gn, VARE_WANTRES);
 
 /*
@@ -529,7 +529,7 @@ Compat_Make(void *gnp, void *pgnp)
 	goto cohorts;
 	}
 
-	if (Lst_Member(gn->iParents, pgn) != NULL) {
+	if (Lst_FindDatum(gn->iParents, pgn) != NULL) {
 	char *p1;
 	Var_Set(IMPSRC, Var_Value(TARGET, gn, ), pgn);
 	bmake_free(p1);
@@ -633,7 +633,7 @@ Compat_Make(void *gnp, void *pgnp)
 	 */
 	pgn->flags &= ~(unsigned)REMAKE;
 } else {
-	if (Lst_Member(gn->iParents, pgn) != NULL) {
+	if (Lst_FindDatum(gn->iParents, pgn) != NULL) {
 	char *p1;
 	const char *target = Var_Value(TARGET, gn, );
 	Var_Set(IMPSRC, target != NULL ? target : "", pgn);

Index: src/usr.bin/make/dir.c
diff -u src/usr.bin/make/dir.c:1.124 src/usr.bin/make/dir.c:1.125
--- src/usr.bin/make/dir.c:1.124	Sat Aug 29 12:39:32 2020
+++ src/usr.bin/make/dir.c	Sun Aug 30 11:12:05 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.c,v 1.124 2020/08/29 12:39:32 rillig Exp $	*/
+/*	$NetBSD: dir.c,v 1.125 2020/08/30 11:12:05 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: dir.c,v 1.124 2020/08/29 12:39:32 rillig Exp $";
+static char rcsid[] = "$NetBSD: dir.c,v 1.125 2020/08/30 11:12:05 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)dir.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: dir.c,v 1.124 2020/08/29 12:39:32 rillig Exp $");
+__RCSID("$NetBSD: dir.c,v 1.125 2020/08/30 11:12:05 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -406,7 +406,7 @@ Dir_InitDot(void)
 	LstNode ln;
 
 	/* Remove old entry from openDirectories, but do not destroy. */
-	ln = Lst_Member(openDirectories, dot);
+	ln = Lst_FindDatum(openDirectories, dot);
 	Lst_Remove(openDirectories, ln);
 }
 
@@ -1533,7 +1533,7 @@ Dir_AddDir(Lst path, const char *name)
 	ln = Lst_Find(openDirectories, DirFindName, name);
 if (ln != NULL) {
 	p = Lst_Datum(ln);
-	if (Lst_Member(path, p) == NULL) {
+	if (Lst_FindDatum(path, p) == NULL) {
 	p->refCount += 1;
 	Lst_Append(path, p);
 	}
@@ -1659,7 +1659,7 @@ Dir_Destroy(void *pp)
 if (p->refCount == 0) {
 	LstNode ln;
 
-	ln = Lst_Member(openDirectories, p);
+	ln = Lst_FindDatum(openDirectories, p);
 	Lst_Remove(openDirectories, ln);
 
 	Hash_DeleteTable(>files);
@@ -1721,7 +1721,7 @@ Dir_Concat(Lst path1, Lst path2)
 
 for (ln = Lst_First(path2); ln != NULL; ln = LstNode_Next(ln)) {
 	p = Lst_Datum(ln);
-	if (Lst_Member(path1, p) == NULL) {
+	if (Lst_FindDatum(path1, p) == NULL) {
 	p->refCount += 1;
 	Lst_Append(path1, p);
 	}

Index: src/usr.bin/make/job.c
diff -u src/usr.bin/make/job.c:1.224 src/usr.bin/make/job.c:1.225
--- src/usr.bin/make/job.c:1.224	Sat Aug 29 12:20:17 2020
+++ src/usr.bin/make/job.c	Sun Aug 30 11:12:05 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.224 2020/08/29 12:20:17 rillig Exp $	*/
+/*	$NetBSD: job.c,v 1.225 2020/08/30 11:12:05 

CVS commit: src/usr.bin/make

2020-08-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Aug 30 11:15:05 UTC 2020

Modified Files:
src/usr.bin/make: arch.c dir.c lst.c lst.h main.c make.c meta.c parse.c
suff.c targ.c

Log Message:
make(1): rename Lst_Datum to LstNode_Datum


To generate a diff of this commit:
cvs rdiff -u -r1.106 -r1.107 src/usr.bin/make/arch.c
cvs rdiff -u -r1.125 -r1.126 src/usr.bin/make/dir.c
cvs rdiff -u -r1.57 -r1.58 src/usr.bin/make/lst.c
cvs rdiff -u -r1.58 -r1.59 src/usr.bin/make/lst.h
cvs rdiff -u -r1.329 -r1.330 src/usr.bin/make/main.c
cvs rdiff -u -r1.131 -r1.132 src/usr.bin/make/make.c
cvs rdiff -u -r1.111 -r1.112 src/usr.bin/make/meta.c
cvs rdiff -u -r1.273 -r1.274 src/usr.bin/make/parse.c
cvs rdiff -u -r1.137 -r1.138 src/usr.bin/make/suff.c
cvs rdiff -u -r1.78 -r1.79 src/usr.bin/make/targ.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/arch.c
diff -u src/usr.bin/make/arch.c:1.106 src/usr.bin/make/arch.c:1.107
--- src/usr.bin/make/arch.c:1.106	Sat Aug 29 13:38:48 2020
+++ src/usr.bin/make/arch.c	Sun Aug 30 11:15:05 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: arch.c,v 1.106 2020/08/29 13:38:48 rillig Exp $	*/
+/*	$NetBSD: arch.c,v 1.107 2020/08/30 11:15:05 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: arch.c,v 1.106 2020/08/29 13:38:48 rillig Exp $";
+static char rcsid[] = "$NetBSD: arch.c,v 1.107 2020/08/30 11:15:05 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)arch.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: arch.c,v 1.106 2020/08/29 13:38:48 rillig Exp $");
+__RCSID("$NetBSD: arch.c,v 1.107 2020/08/30 11:15:05 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -508,7 +508,7 @@ ArchStatMember(const char *archive, cons
 
 ln = Lst_Find(archives, ArchFindArchive, archive);
 if (ln != NULL) {
-	ar = Lst_Datum(ln);
+	ar = LstNode_Datum(ln);
 
 	he = Hash_FindEntry(>members, member);
 
@@ -1046,7 +1046,7 @@ Arch_MemMTime(GNode *gn)
 
 Lst_Open(gn->parents);
 while ((ln = Lst_Next(gn->parents)) != NULL) {
-	pgn = Lst_Datum(ln);
+	pgn = LstNode_Datum(ln);
 
 	if (pgn->type & OP_ARCHV) {
 	/*

Index: src/usr.bin/make/dir.c
diff -u src/usr.bin/make/dir.c:1.125 src/usr.bin/make/dir.c:1.126
--- src/usr.bin/make/dir.c:1.125	Sun Aug 30 11:12:05 2020
+++ src/usr.bin/make/dir.c	Sun Aug 30 11:15:05 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.c,v 1.125 2020/08/30 11:12:05 rillig Exp $	*/
+/*	$NetBSD: dir.c,v 1.126 2020/08/30 11:15:05 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: dir.c,v 1.125 2020/08/30 11:12:05 rillig Exp $";
+static char rcsid[] = "$NetBSD: dir.c,v 1.126 2020/08/30 11:15:05 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)dir.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: dir.c,v 1.125 2020/08/30 11:12:05 rillig Exp $");
+__RCSID("$NetBSD: dir.c,v 1.126 2020/08/30 11:15:05 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -462,7 +462,7 @@ Dir_SetPATH(void)
 
 Lst_Open(dirSearchPath);
 if ((ln = Lst_First(dirSearchPath)) != NULL) {
-	p = Lst_Datum(ln);
+	p = LstNode_Datum(ln);
 	if (p == dotLast) {
 	hasLastDot = TRUE;
 	Var_Append(".PATH", dotLast->name, VAR_GLOBAL);
@@ -477,7 +477,7 @@ Dir_SetPATH(void)
 }
 
 while ((ln = Lst_Next(dirSearchPath)) != NULL) {
-	p = Lst_Datum(ln);
+	p = LstNode_Datum(ln);
 	if (p == dotLast)
 	continue;
 	if (p == dot && hasLastDot)
@@ -753,7 +753,7 @@ DirExpandInt(const char *word, Lst path,
 
 Lst_Open(path);
 while ((ln = Lst_Next(path)) != NULL) {
-	Path *p = Lst_Datum(ln);
+	Path *p = LstNode_Datum(ln);
 	DirMatchFiles(word, p, expansions);
 }
 Lst_Close(path);
@@ -1094,7 +1094,7 @@ Dir_FindFile(const char *name, Lst path)
 
 Lst_Open(path);
 if ((ln = Lst_First(path)) != NULL) {
-	p = Lst_Datum(ln);
+	p = LstNode_Datum(ln);
 	if (p == dotLast) {
 	hasLastDot = TRUE;
 	DIR_DEBUG0("[dot last]...");
@@ -1128,7 +1128,7 @@ Dir_FindFile(const char *name, Lst path)
 	}
 
 	while ((ln = Lst_Next(path)) != NULL) {
-	p = Lst_Datum(ln);
+	p = LstNode_Datum(ln);
 	if (p == dotLast)
 		continue;
 	if ((file = DirLookup(p, name, cp, hasSlash)) != NULL) {
@@ -1186,7 +1186,7 @@ Dir_FindFile(const char *name, Lst path)
 
 	Lst_Open(path);
 	while ((ln = Lst_Next(path)) != NULL) {
-	p = Lst_Datum(ln);
+	p = LstNode_Datum(ln);
 	if (p == dotLast)
 		continue;
 	if (p == dot) {
@@ -1244,7 +1244,7 @@ Dir_FindFile(const char *name, Lst path)
 
 	Lst_Open(path);
 	while ((ln = Lst_Next(path)) != NULL) {
-	p = Lst_Datum(ln);
+	p = LstNode_Datum(ln);
 	if (p == dotLast)
 		continue;
 	if ((file = DirLookupAbs(p, name, cp)) 

CVS commit: src/usr.bin/make

2020-08-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Aug 30 14:11:42 UTC 2020

Modified Files:
src/usr.bin/make: compat.c dir.c make.c make.h suff.c targ.c

Log Message:
make(1): rename GNode.iParents to implicitParents

The i alone was too ambiguous.  It could have meant ignore, implicit,
interactive, and probably many more.


To generate a diff of this commit:
cvs rdiff -u -r1.136 -r1.137 src/usr.bin/make/compat.c
cvs rdiff -u -r1.126 -r1.127 src/usr.bin/make/dir.c
cvs rdiff -u -r1.132 -r1.133 src/usr.bin/make/make.c src/usr.bin/make/make.h
cvs rdiff -u -r1.138 -r1.139 src/usr.bin/make/suff.c
cvs rdiff -u -r1.79 -r1.80 src/usr.bin/make/targ.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/compat.c
diff -u src/usr.bin/make/compat.c:1.136 src/usr.bin/make/compat.c:1.137
--- src/usr.bin/make/compat.c:1.136	Sun Aug 30 11:12:05 2020
+++ src/usr.bin/make/compat.c	Sun Aug 30 14:11:42 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat.c,v 1.136 2020/08/30 11:12:05 rillig Exp $	*/
+/*	$NetBSD: compat.c,v 1.137 2020/08/30 14:11:42 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: compat.c,v 1.136 2020/08/30 11:12:05 rillig Exp $";
+static char rcsid[] = "$NetBSD: compat.c,v 1.137 2020/08/30 14:11:42 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)compat.c	8.2 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: compat.c,v 1.136 2020/08/30 11:12:05 rillig Exp $");
+__RCSID("$NetBSD: compat.c,v 1.137 2020/08/30 14:11:42 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -529,7 +529,7 @@ Compat_Make(void *gnp, void *pgnp)
 	goto cohorts;
 	}
 
-	if (Lst_FindDatum(gn->iParents, pgn) != NULL) {
+	if (Lst_FindDatum(gn->implicitParents, pgn) != NULL) {
 	char *p1;
 	Var_Set(IMPSRC, Var_Value(TARGET, gn, ), pgn);
 	bmake_free(p1);
@@ -633,7 +633,7 @@ Compat_Make(void *gnp, void *pgnp)
 	 */
 	pgn->flags &= ~(unsigned)REMAKE;
 } else {
-	if (Lst_FindDatum(gn->iParents, pgn) != NULL) {
+	if (Lst_FindDatum(gn->implicitParents, pgn) != NULL) {
 	char *p1;
 	const char *target = Var_Value(TARGET, gn, );
 	Var_Set(IMPSRC, target != NULL ? target : "", pgn);

Index: src/usr.bin/make/dir.c
diff -u src/usr.bin/make/dir.c:1.126 src/usr.bin/make/dir.c:1.127
--- src/usr.bin/make/dir.c:1.126	Sun Aug 30 11:15:05 2020
+++ src/usr.bin/make/dir.c	Sun Aug 30 14:11:42 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.c,v 1.126 2020/08/30 11:15:05 rillig Exp $	*/
+/*	$NetBSD: dir.c,v 1.127 2020/08/30 14:11:42 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: dir.c,v 1.126 2020/08/30 11:15:05 rillig Exp $";
+static char rcsid[] = "$NetBSD: dir.c,v 1.127 2020/08/30 14:11:42 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)dir.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: dir.c,v 1.126 2020/08/30 11:15:05 rillig Exp $");
+__RCSID("$NetBSD: dir.c,v 1.127 2020/08/30 14:11:42 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1434,7 +1434,7 @@ Dir_MTime(GNode *gn, Boolean recheck)
 	else {
 	fullName = Dir_FindFile(gn->name, Suff_FindPath(gn));
 	if (fullName == NULL && gn->flags & FROM_DEPEND &&
-		!Lst_IsEmpty(gn->iParents)) {
+		!Lst_IsEmpty(gn->implicitParents)) {
 		char *cp;
 
 		cp = strrchr(gn->name, '/');

Index: src/usr.bin/make/make.c
diff -u src/usr.bin/make/make.c:1.132 src/usr.bin/make/make.c:1.133
--- src/usr.bin/make/make.c:1.132	Sun Aug 30 11:15:05 2020
+++ src/usr.bin/make/make.c	Sun Aug 30 14:11:42 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.c,v 1.132 2020/08/30 11:15:05 rillig Exp $	*/
+/*	$NetBSD: make.c,v 1.133 2020/08/30 14:11:42 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: make.c,v 1.132 2020/08/30 11:15:05 rillig Exp $";
+static char rcsid[] = "$NetBSD: make.c,v 1.133 2020/08/30 14:11:42 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)make.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: make.c,v 1.132 2020/08/30 11:15:05 rillig Exp $");
+__RCSID("$NetBSD: make.c,v 1.133 2020/08/30 14:11:42 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -695,7 +695,7 @@ Make_Update(GNode *cgn)
 {
 GNode 	*pgn;	/* the parent node */
 const char	*cname;	/* the child's name */
-LstNode	ln; 	/* Element in parents and iParents lists */
+LstNode	ln; 	/* Element in parents and implicitParents lists */
 time_t	mtime = -1;
 char	*p1;
 Lst		parents;
@@ -838,11 +838,11 @@ Make_Update(GNode *cgn)
  * Set the .PREFIX and .IMPSRC variables for all the implied parents
  * of this node.
  */

CVS commit: src/usr.bin/make

2020-09-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep  5 14:58:07 UTC 2020

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

Log Message:
make(1): remove redundant prototypes for local functions from parse.c


To generate a diff of this commit:
cvs rdiff -u -r1.276 -r1.277 src/usr.bin/make/parse.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/parse.c
diff -u src/usr.bin/make/parse.c:1.276 src/usr.bin/make/parse.c:1.277
--- src/usr.bin/make/parse.c:1.276	Fri Sep  4 17:59:36 2020
+++ src/usr.bin/make/parse.c	Sat Sep  5 14:58:07 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.276 2020/09/04 17:59:36 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.277 2020/09/05 14:58:07 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: parse.c,v 1.276 2020/09/04 17:59:36 rillig Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.277 2020/09/05 14:58:07 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)parse.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: parse.c,v 1.276 2020/09/04 17:59:36 rillig Exp $");
+__RCSID("$NetBSD: parse.c,v 1.277 2020/09/05 14:58:07 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -339,30 +339,7 @@ static const struct {
 
 /* local functions */
 
-static int ParseIsEscaped(const char *, const char *);
-static void ParseErrorInternal(const char *, size_t, int, const char *, ...)
-MAKE_ATTR_PRINTFLIKE(4,5);
-static void ParseVErrorInternal(FILE *, const char *, size_t, int, const char *, va_list)
-MAKE_ATTR_PRINTFLIKE(5, 0);
-static int ParseFindKeyword(const char *);
-static int ParseLinkSrc(void *, void *);
-static int ParseDoOp(void *, void *);
-static void ParseDoSrc(int, const char *);
-static int ParseFindMain(void *, void *);
-static int ParseAddDir(void *, void *);
-static int ParseClearPath(void *, void *);
-static void ParseDoDependency(char *);
-static int ParseAddCmd(void *, void *);
-static void ParseHasCommands(void *);
-static void ParseDoInclude(char *);
-static void ParseSetParseFile(const char *);
 static void ParseSetIncludedFile(void);
-#ifdef GMAKEEXPORT
-static void ParseGmakeExport(char *);
-#endif
-static int ParseEOF(void);
-static char *ParseReadLine(void);
-static void ParseFinishLine(void);
 static void ParseMark(GNode *);
 
 /* file loader */



CVS commit: src/usr.bin/make/unit-tests

2020-09-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep  5 16:59:20 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: include-main.exp include-main.mk
include-sub.mk include-subsub.mk

Log Message:
make(1): make test for .INCLUDEDFROMDIR simpler

The .info and .warning directives provide exactly the early expansion
that this test needs.  No more .for for getting a snapshot of a
variable.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/include-main.exp \
src/usr.bin/make/unit-tests/include-sub.mk \
src/usr.bin/make/unit-tests/include-subsub.mk
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/include-main.mk

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/unit-tests/include-main.exp
diff -u src/usr.bin/make/unit-tests/include-main.exp:1.1 src/usr.bin/make/unit-tests/include-main.exp:1.2
--- src/usr.bin/make/unit-tests/include-main.exp:1.1	Sun May 17 12:36:26 2020
+++ src/usr.bin/make/unit-tests/include-main.exp	Sat Sep  5 16:59:19 2020
@@ -1,6 +1,6 @@
-main-before-ok
-sub-before-ok
-subsub-ok
-sub-after-fail(include-sub.mk)
-main-after-fail(include-sub.mk)
+make: "include-main.mk" line 12: main-before-ok
+make: "include-sub.mk" line 4: sub-before-ok
+make: "include-subsub.mk" line 4: subsub-ok
+make: "include-sub.mk" line 14: warning: sub-after-fail(include-sub.mk)
+make: "include-main.mk" line 22: warning: main-after-fail(include-sub.mk)
 exit status 0
Index: src/usr.bin/make/unit-tests/include-sub.mk
diff -u src/usr.bin/make/unit-tests/include-sub.mk:1.1 src/usr.bin/make/unit-tests/include-sub.mk:1.2
--- src/usr.bin/make/unit-tests/include-sub.mk:1.1	Sun May 17 12:36:26 2020
+++ src/usr.bin/make/unit-tests/include-sub.mk	Sat Sep  5 16:59:19 2020
@@ -1,17 +1,15 @@
-# $NetBSD: include-sub.mk,v 1.1 2020/05/17 12:36:26 rillig Exp $
+# $NetBSD: include-sub.mk,v 1.2 2020/09/05 16:59:19 rillig Exp $
 
 .if ${.INCLUDEDFROMFILE} == "include-main.mk"
-LOG+=		sub-before-ok
+.  info sub-before-ok
 .else
-LOG+=		sub-before-fail
+.  warning sub-before-fail
 .endif
 
 .include "include-subsub.mk"
 
 .if ${.INCLUDEDFROMFILE} == "include-main.mk"
-LOG+=		sub-after-ok
+.  info sub-after-ok
 .else
-.  for f in ${.INCLUDEDFROMFILE}
-LOG+=		sub-after-fail\(${f:Q}\)
-.  endfor
+.  warning sub-after-fail(${.INCLUDEDFROMFILE})
 .endif
Index: src/usr.bin/make/unit-tests/include-subsub.mk
diff -u src/usr.bin/make/unit-tests/include-subsub.mk:1.1 src/usr.bin/make/unit-tests/include-subsub.mk:1.2
--- src/usr.bin/make/unit-tests/include-subsub.mk:1.1	Sun May 17 12:36:26 2020
+++ src/usr.bin/make/unit-tests/include-subsub.mk	Sat Sep  5 16:59:19 2020
@@ -1,7 +1,7 @@
-# $NetBSD: include-subsub.mk,v 1.1 2020/05/17 12:36:26 rillig Exp $
+# $NetBSD: include-subsub.mk,v 1.2 2020/09/05 16:59:19 rillig Exp $
 
 .if ${.INCLUDEDFROMFILE:T} == "include-sub.mk"
-LOG+=		subsub-ok
+.  info subsub-ok
 .else
-LOG+=		subsub-fail
+.  warning subsub-fail
 .endif

Index: src/usr.bin/make/unit-tests/include-main.mk
diff -u src/usr.bin/make/unit-tests/include-main.mk:1.2 src/usr.bin/make/unit-tests/include-main.mk:1.3
--- src/usr.bin/make/unit-tests/include-main.mk:1.2	Mon Jul 27 20:55:59 2020
+++ src/usr.bin/make/unit-tests/include-main.mk	Sat Sep  5 16:59:19 2020
@@ -1,4 +1,4 @@
-# $NetBSD: include-main.mk,v 1.2 2020/07/27 20:55:59 rillig Exp $
+# $NetBSD: include-main.mk,v 1.3 2020/09/05 16:59:19 rillig Exp $
 #
 # Demonstrates that the .INCLUDEDFROMFILE magic variable does not behave
 # as described in the manual page.
@@ -9,22 +9,17 @@
 #
 
 .if !defined(.INCLUDEDFROMFILE)
-LOG+=		main-before-ok
+.  info main-before-ok
 .else
-.  for f in ${.INCLUDEDFROMFILE}
-LOG+=		main-before-fail\(${f:Q}\)
-.  endfor
+.  warning main-before-fail(${.INCLUDEDFROMFILE})
 .endif
 
 .include "include-sub.mk"
 
 .if !defined(.INCLUDEDFROMFILE)
-LOG+=		main-after-ok
+.  info main-after-ok
 .else
-.  for f in ${.INCLUDEDFROMFILE}
-LOG+=		main-after-fail\(${f:Q}\)
-.  endfor
+.  warning main-after-fail(${.INCLUDEDFROMFILE})
 .endif
 
-all:
-	@printf '%s\n' ${LOG}
+all:	# nothing



CVS commit: src/usr.bin/make

2020-09-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep  5 19:11:16 UTC 2020

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

Log Message:
make(1): replay the changes from v1.283

I accidentally reverted them in v1.284.


To generate a diff of this commit:
cvs rdiff -u -r1.284 -r1.285 src/usr.bin/make/parse.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/parse.c
diff -u src/usr.bin/make/parse.c:1.284 src/usr.bin/make/parse.c:1.285
--- src/usr.bin/make/parse.c:1.284	Sat Sep  5 19:07:25 2020
+++ src/usr.bin/make/parse.c	Sat Sep  5 19:11:16 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.284 2020/09/05 19:07:25 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.285 2020/09/05 19:11:16 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: parse.c,v 1.284 2020/09/05 19:07:25 rillig Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.285 2020/09/05 19:11:16 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)parse.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: parse.c,v 1.284 2020/09/05 19:07:25 rillig Exp $");
+__RCSID("$NetBSD: parse.c,v 1.285 2020/09/05 19:11:16 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -2312,8 +2312,7 @@ GetActuallyIncludingFile(void)
 return NULL;
 }
 
-/* Set .PARSEDIR/.PARSEFILE to the given filename, as well as
- * .INCLUDEDFROMDIR/.INCLUDEDFROMFILE. */
+/* Set .PARSEDIR, .PARSEFILE, .INCLUDEDFROMDIR and .INCLUDEDFROMFILE. */
 static void
 ParseSetParseFile(const char *filename)
 {
@@ -2605,7 +2604,6 @@ ParseEOF(void)
 	fprintf(debug_file, "ParseEOF: returning to file %s, line %d\n",
 	curFile->fname, curFile->lineno);
 
-/* Restore the PARSEDIR/PARSEFILE variables */
 ParseSetParseFile(curFile->fname);
 return CONTINUE;
 }



CVS commit: src/usr.bin/make

2020-09-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep  5 15:04:09 UTC 2020

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

Log Message:
make(1): remove redundant prototype for ParseMark


To generate a diff of this commit:
cvs rdiff -u -r1.277 -r1.278 src/usr.bin/make/parse.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/parse.c
diff -u src/usr.bin/make/parse.c:1.277 src/usr.bin/make/parse.c:1.278
--- src/usr.bin/make/parse.c:1.277	Sat Sep  5 14:58:07 2020
+++ src/usr.bin/make/parse.c	Sat Sep  5 15:04:09 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.277 2020/09/05 14:58:07 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.278 2020/09/05 15:04:09 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: parse.c,v 1.277 2020/09/05 14:58:07 rillig Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.278 2020/09/05 15:04:09 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)parse.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: parse.c,v 1.277 2020/09/05 14:58:07 rillig Exp $");
+__RCSID("$NetBSD: parse.c,v 1.278 2020/09/05 15:04:09 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -580,6 +580,15 @@ ParseIsEscaped(const char *line, const c
 }
 }
 
+/* Add the filename and lineno to the GNode so that we remember where it
+ * was first defined. */
+static void
+ParseMark(GNode *gn)
+{
+gn->fname = curFile->fname;
+gn->lineno = curFile->lineno;
+}
+
 /*-
  *--
  * ParseFindKeyword --
@@ -3311,21 +3320,3 @@ Parse_MainName(void)
 Var_Append(".TARGETS", mainNode->name, VAR_GLOBAL);
 return mainList;
 }
-
-/*-
- *---
- * ParseMark --
- *	Add the filename and lineno to the GNode so that we remember
- *	where it was first defined.
- *
- * Side Effects:
- *	None.
- *
- *---
- */
-static void
-ParseMark(GNode *gn)
-{
-gn->fname = curFile->fname;
-gn->lineno = curFile->lineno;
-}



CVS commit: src/usr.bin/make

2020-09-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep  5 15:05:08 UTC 2020

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

Log Message:
make(1): fix return type of ParseIsEscaped


To generate a diff of this commit:
cvs rdiff -u -r1.278 -r1.279 src/usr.bin/make/parse.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/parse.c
diff -u src/usr.bin/make/parse.c:1.278 src/usr.bin/make/parse.c:1.279
--- src/usr.bin/make/parse.c:1.278	Sat Sep  5 15:04:09 2020
+++ src/usr.bin/make/parse.c	Sat Sep  5 15:05:08 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.278 2020/09/05 15:04:09 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.279 2020/09/05 15:05:08 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: parse.c,v 1.278 2020/09/05 15:04:09 rillig Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.279 2020/09/05 15:05:08 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)parse.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: parse.c,v 1.278 2020/09/05 15:04:09 rillig Exp $");
+__RCSID("$NetBSD: parse.c,v 1.279 2020/09/05 15:05:08 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -340,7 +340,6 @@ static const struct {
 /* local functions */
 
 static void ParseSetIncludedFile(void);
-static void ParseMark(GNode *);
 
 /* file loader */
 
@@ -555,19 +554,8 @@ done:
 
 /* old code */
 
-/*-
- *--
- * ParseIsEscaped --
- *	Check if the current character is escaped on the current line
- *
- * Results:
- *	0 if the character is not backslash escaped, 1 otherwise
- *
- * Side Effects:
- *	None
- *--
- */
-static int
+/* Check if the current character is escaped on the current line. */
+static Boolean
 ParseIsEscaped(const char *line, const char *c)
 {
 int active = 0;



CVS commit: src/usr.bin/make

2020-09-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep  5 18:18:05 UTC 2020

Modified Files:
src/usr.bin/make: parse.c
src/usr.bin/make/unit-tests: include-main.exp include-main.mk

Log Message:
make(1): fix .INCLUDEDFROMDIR/.INCLUDEDFROMFILE


To generate a diff of this commit:
cvs rdiff -u -r1.280 -r1.281 src/usr.bin/make/parse.c
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/include-main.exp
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/include-main.mk

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/parse.c
diff -u src/usr.bin/make/parse.c:1.280 src/usr.bin/make/parse.c:1.281
--- src/usr.bin/make/parse.c:1.280	Sat Sep  5 15:12:03 2020
+++ src/usr.bin/make/parse.c	Sat Sep  5 18:18:05 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.280 2020/09/05 15:12:03 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.281 2020/09/05 18:18:05 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: parse.c,v 1.280 2020/09/05 15:12:03 rillig Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.281 2020/09/05 18:18:05 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)parse.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: parse.c,v 1.280 2020/09/05 15:12:03 rillig Exp $");
+__RCSID("$NetBSD: parse.c,v 1.281 2020/09/05 18:18:05 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -150,6 +150,7 @@ __RCSID("$NetBSD: parse.c,v 1.280 2020/0
  */
 typedef struct IFile {
 char  	*fname; /* name of file */
+Boolean fromForLoop;/* simulated .include by the .for loop */
 int lineno; /* current line number in file */
 int first_lineno;   /* line number of start of text */
 int cond_depth; /* 'if' nesting when file opened */
@@ -269,7 +270,7 @@ static IFile *curFile;
 
 /* The current file from the command line (at the bottom of the stack) and
  * further up all the files that are currently being read due to nested
- * .include directives. */
+ * .include or .for directives. */
 static Stack /* of *IFile */ includes;
 
 /* include paths (lists of directories) */
@@ -337,10 +338,6 @@ static const struct {
 { ".WAIT",	  Wait, 	0 },
 };
 
-/* local functions */
-
-static void ParseSetIncludedFile(void);
-
 /* file loader */
 
 struct loadedfile {
@@ -2254,7 +2251,6 @@ Parse_include_file(char *file, Boolean i
 /* load it */
 lf = loadfile(fullname, fd);
 
-ParseSetIncludedFile();
 /* Start reading from this file next */
 Parse_SetInput(fullname, 0, -1, loadedfile_nextbuf, lf);
 curFile->lf = lf;
@@ -2313,74 +2309,70 @@ ParseDoInclude(char *line)
 free(file);
 }
 
-
-/*-
- *-
- * ParseSetIncludedFile  --
- *	Set the .INCLUDEDFROMFILE variable to the contents of .PARSEFILE
- *	and the .INCLUDEDFROMDIR variable to the contents of .PARSEDIR
- *
- * Results:
- *	None
- *
- * Side Effects:
- *	The .INCLUDEDFROMFILE variable is overwritten by the contents
- *	of .PARSEFILE and the .INCLUDEDFROMDIR variable is overwriten
- *	by the contents of .PARSEDIR
- *-
- */
+/* Split filename into dirname + basename, then assign these to the
+ * given variables. */
 static void
-ParseSetIncludedFile(void)
+SetFilenameVars(const char *filename, const char *dirvar, const char *filevar)
 {
-const char *pf, *pd;
-char *pf_freeIt, *pd_freeIt;
+const char *slash, *dirname, *basename;
+void *freeIt;
+
+slash = strrchr(filename, '/');
+if (slash == NULL) {
+	dirname = curdir;
+	basename = filename;
+	freeIt = NULL;
+} else {
+	dirname = freeIt = bmake_strsedup(filename, slash);
+	basename = slash + 1;
+}
 
-pf = Var_Value(".PARSEFILE", VAR_GLOBAL, _freeIt);
-Var_Set(".INCLUDEDFROMFILE", pf, VAR_GLOBAL);
-pd = Var_Value(".PARSEDIR", VAR_GLOBAL, _freeIt);
-Var_Set(".INCLUDEDFROMDIR", pd, VAR_GLOBAL);
+Var_Set(dirvar, dirname, VAR_GLOBAL);
+Var_Set(filevar, basename, VAR_GLOBAL);
 
 if (DEBUG(PARSE))
-	fprintf(debug_file, "%s: ${.INCLUDEDFROMDIR} = `%s' "
-	"${.INCLUDEDFROMFILE} = `%s'\n", __func__, pd, pf);
-
-bmake_free(pf_freeIt);
-bmake_free(pd_freeIt);
+	fprintf(debug_file, "%s: ${%s} = `%s' ${%s} = `%s'\n",
+		__func__, dirvar, dirname, filevar, basename);
+free(freeIt);
 }
-/*-
- *-
- * ParseSetParseFile  --
- *	Set the .PARSEDIR and .PARSEFILE variables to the dirname and
- *	basename of the given filename
- *
- * Results:
- *	None
+
+/* Return the immediately including file.
  *
- * Side Effects:
- *	The .PARSEDIR and .PARSEFILE variables are overwritten by the
- *	dirname and basename of the given 

CVS commit: src/usr.bin/make

2020-09-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep  5 19:07:25 UTC 2020

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

Log Message:
make(1): clean up comments about parsing


To generate a diff of this commit:
cvs rdiff -u -r1.283 -r1.284 src/usr.bin/make/parse.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/parse.c
diff -u src/usr.bin/make/parse.c:1.283 src/usr.bin/make/parse.c:1.284
--- src/usr.bin/make/parse.c:1.283	Sat Sep  5 18:41:59 2020
+++ src/usr.bin/make/parse.c	Sat Sep  5 19:07:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.283 2020/09/05 18:41:59 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.284 2020/09/05 19:07:25 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: parse.c,v 1.283 2020/09/05 18:41:59 rillig Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.284 2020/09/05 19:07:25 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)parse.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: parse.c,v 1.283 2020/09/05 18:41:59 rillig Exp $");
+__RCSID("$NetBSD: parse.c,v 1.284 2020/09/05 19:07:25 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -2084,25 +2084,9 @@ ParseAddCmd(void *gnp, void *cmd)
 return 0;
 }
 
-/*-
- *---
- * ParseHasCommands --
- *	Callback procedure for Parse_File when destroying the list of
- *	targets on the last dependency line. Marks a target as already
- *	having commands if it does, to keep from having shell commands
- *	on multiple dependency lines.
- *
- * Input:
- *	gnp		Node to examine
- *
- * Results:
- *	None
- *
- * Side Effects:
- *	OP_HAS_COMMANDS may be set for the target.
- *
- *---
- */
+/* Callback procedure for Parse_File when destroying the list of targets on
+ * the last dependency line. Marks a target as already having commands if it
+ * does, to keep from having shell commands on multiple dependency lines. */
 static void
 ParseHasCommands(void *gnp)
 {
@@ -2112,48 +2096,21 @@ ParseHasCommands(void *gnp)
 }
 }
 
-/*-
- *---
- * Parse_AddIncludeDir --
- *	Add a directory to the path searched for included makefiles
- *	bracketed by double-quotes. Used by functions in main.c
- *
- * Input:
- *	dir		The name of the directory to add
- *
- * Results:
- *	None.
- *
- * Side Effects:
- *	The directory is appended to the list.
- *
- *---
- */
+/* Add a directory to the path searched for included makefiles bracketed
+ * by double-quotes. */
 void
 Parse_AddIncludeDir(char *dir)
 {
 (void)Dir_AddDir(parseIncPath, dir);
 }
 
-/*-
- *-
- * ParseDoInclude  --
- *	Push to another file.
- *
- *	The input is the line minus the `.'. A file spec is a string
- *	enclosed in <> or "". The former is looked for only in sysIncPath.
- *	The latter in . and the directories specified by -I command line
- *	options
- *
- * Results:
- *	None
+/* Push to another file.
  *
- * Side Effects:
- *	A structure is added to the includes Lst and readProc, lineno,
- *	fname and curFILE are altered for the new file
- *-
+ * The input is the line minus the '.'. A file spec is a string enclosed in
+ * <> or "". The <> file is looked for only in sysIncPath. The "" file is
+ * first searched in the parsedir and then in the directories specified by
+ * the -I command line options.
  */
-
 static void
 Parse_include_file(char *file, Boolean isSystem, Boolean depinc, int silent)
 {
@@ -2348,14 +2305,15 @@ GetActuallyIncludingFile(void)
 /* XXX: Stack was supposed to be an opaque data structure. */
 for (i = includes.len; i > 0; i--) {
 	IFile *parent = includes.items[i - 1];
-	IFile *child = (i < includes.len) ? includes.items[i] : curFile;
+	IFile *child = i < includes.len ? includes.items[i] : curFile;
 	if (!child->fromForLoop)
 	return parent->fname;
 }
 return NULL;
 }
 
-/* Set .PARSEDIR, .PARSEFILE, .INCLUDEDFROMDIR and .INCLUDEDFROMFILE. */
+/* Set .PARSEDIR/.PARSEFILE to the given filename, as well as
+ * .INCLUDEDFROMDIR/.INCLUDEDFROMFILE. */
 static void
 ParseSetParseFile(const char *filename)
 {
@@ -2373,10 +2331,8 @@ ParseSetParseFile(const char *filename)
 }
 }
 
-/*
- * Track the makefiles we read - so makefiles can set dependencies on them.
- * Avoid adding anything more than once.
- */
+/* Track the makefiles we read - so makefiles can set dependencies on them.
+ * Avoid adding anything more than once. */
 static void
 ParseTrackInput(const char *name)
 {
@@ -2468,19 +2424,7 @@ 

CVS commit: src/usr.bin/make

2020-09-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep  5 15:12:04 UTC 2020

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

Log Message:
make(1): fix local variable type in ParseIsEscaped


To generate a diff of this commit:
cvs rdiff -u -r1.279 -r1.280 src/usr.bin/make/parse.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/parse.c
diff -u src/usr.bin/make/parse.c:1.279 src/usr.bin/make/parse.c:1.280
--- src/usr.bin/make/parse.c:1.279	Sat Sep  5 15:05:08 2020
+++ src/usr.bin/make/parse.c	Sat Sep  5 15:12:03 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.279 2020/09/05 15:05:08 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.280 2020/09/05 15:12:03 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: parse.c,v 1.279 2020/09/05 15:05:08 rillig Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.280 2020/09/05 15:12:03 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)parse.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: parse.c,v 1.279 2020/09/05 15:05:08 rillig Exp $");
+__RCSID("$NetBSD: parse.c,v 1.280 2020/09/05 15:12:03 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -351,9 +351,6 @@ struct loadedfile {
 	Boolean used;			/* XXX: have we used the data yet */
 };
 
-/*
- * Constructor/destructor for loadedfile
- */
 static struct loadedfile *
 loadedfile_create(const char *path)
 {
@@ -558,7 +555,7 @@ done:
 static Boolean
 ParseIsEscaped(const char *line, const char *c)
 {
-int active = 0;
+Boolean active = FALSE;
 for (;;) {
 	if (line == c)
 	return active;



CVS commit: src/distrib/sets/lists/base

2020-09-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep  5 19:17:42 UTC 2020

Modified Files:
src/distrib/sets/lists/base: mi

Log Message:
lists/base/mi: fix lines with 4 fields

ok mrg


To generate a diff of this commit:
cvs rdiff -u -r1.1258 -r1.1259 src/distrib/sets/lists/base/mi

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

Modified files:

Index: src/distrib/sets/lists/base/mi
diff -u src/distrib/sets/lists/base/mi:1.1258 src/distrib/sets/lists/base/mi:1.1259
--- src/distrib/sets/lists/base/mi:1.1258	Thu Aug 27 15:31:59 2020
+++ src/distrib/sets/lists/base/mi	Sat Sep  5 19:17:42 2020
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1258 2020/08/27 15:31:59 riastradh Exp $
+# $NetBSD: mi,v 1.1259 2020/09/05 19:17:42 rillig Exp $
 #
 # Note:	Don't delete entries from here - mark them as "obsolete" instead,
 #	unless otherwise stated below.
@@ -258,11 +258,11 @@
 ./libdata/firmware/if_urtwn/rtl8192cfwU.bin	base-firmware-root	firmware
 ./libdata/firmware/if_urtwn/rtl8192eefw.bin	base-firmware-root	firmware
 ./libdata/firmware/if_wpi			base-firmware-root
-./libdata/firmware/if_wpi/LICENSE.ipw3945-ucode	base-obsolete	obsolete	firmware
+./libdata/firmware/if_wpi/LICENSE.ipw3945-ucode	base-obsolete	obsolete,firmware
 ./libdata/firmware/if_wpi/LICENSE.iwlwifi-3945-ucode	base-firmware-root	firmware
-./libdata/firmware/if_wpi/README.ipw3945-ucode	base-obsolete	obsolete	firmware
+./libdata/firmware/if_wpi/README.ipw3945-ucode	base-obsolete	obsolete,firmware
 ./libdata/firmware/if_wpi/README.iwlwifi-3945-ucode	base-firmware-root	firmware
-./libdata/firmware/if_wpi/ipw3945.ucode		base-obsolete	obsolete	firmware
+./libdata/firmware/if_wpi/ipw3945.ucode		base-obsolete	obsolete,firmware
 ./libdata/firmware/if_wpi/iwlwifi-3945.ucode		base-firmware-root	firmware
 ./libdata/firmware/nouveau			base-firmware-usr
 ./libdata/firmware/nouveau/nvidia			base-firmware-usr
@@ -457,8 +457,8 @@
 ./libdata/firmware/rumbase-firmware-root
 ./libdata/firmware/rum/rum-license		base-firmware-root	firmware
 ./libdata/firmware/rum/rum-rt2573		base-firmware-root	firmware
-./libdata/firmware/rum/run-rt2870		base-obsolete	obsolete	firmware
-./libdata/firmware/rum/run-rt3071		base-obsolete	obsolete	firmware
+./libdata/firmware/rum/run-rt2870		base-obsolete	obsolete,firmware
+./libdata/firmware/rum/run-rt3071		base-obsolete	obsolete,firmware
 ./libdata/firmware/runbase-firmware-root
 ./libdata/firmware/run/run-license		base-firmware-root	firmware
 ./libdata/firmware/run/run-rt2870		base-firmware-root	firmware



CVS commit: src/usr.bin/make/unit-tests

2020-09-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep  5 18:13:47 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: include-main.exp include-main.mk
include-sub.mk include-subsub.mk

Log Message:
make(1): add test for .INCLUDEDFILE combined with .for loops

The .for loops are implemented as a special kind of .include, therefore
they affect the .INCLUDEDFROM variable.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/include-main.exp \
src/usr.bin/make/unit-tests/include-sub.mk \
src/usr.bin/make/unit-tests/include-subsub.mk
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/include-main.mk

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/unit-tests/include-main.exp
diff -u src/usr.bin/make/unit-tests/include-main.exp:1.2 src/usr.bin/make/unit-tests/include-main.exp:1.3
--- src/usr.bin/make/unit-tests/include-main.exp:1.2	Sat Sep  5 16:59:19 2020
+++ src/usr.bin/make/unit-tests/include-main.exp	Sat Sep  5 18:13:47 2020
@@ -1,6 +1,10 @@
 make: "include-main.mk" line 12: main-before-ok
+make: "include-main.mk" line 19: main-before-for-ok
 make: "include-sub.mk" line 4: sub-before-ok
+make: "include-sub.mk" line 14: sub-before-for-ok
 make: "include-subsub.mk" line 4: subsub-ok
-make: "include-sub.mk" line 14: warning: sub-after-fail(include-sub.mk)
-make: "include-main.mk" line 22: warning: main-after-fail(include-sub.mk)
+make: "include-sub.mk" line 25: warning: sub-after-fail(include-sub.mk)
+make: "include-sub.mk" line 32: warning: sub-after-for-fail(include-sub.mk)
+make: "include-main.mk" line 30: warning: main-after-fail(include-sub.mk)
+make: "include-main.mk" line 35: main-after-for-ok
 exit status 0
Index: src/usr.bin/make/unit-tests/include-sub.mk
diff -u src/usr.bin/make/unit-tests/include-sub.mk:1.2 src/usr.bin/make/unit-tests/include-sub.mk:1.3
--- src/usr.bin/make/unit-tests/include-sub.mk:1.2	Sat Sep  5 16:59:19 2020
+++ src/usr.bin/make/unit-tests/include-sub.mk	Sat Sep  5 18:13:47 2020
@@ -1,11 +1,22 @@
-# $NetBSD: include-sub.mk,v 1.2 2020/09/05 16:59:19 rillig Exp $
+# $NetBSD: include-sub.mk,v 1.3 2020/09/05 18:13:47 rillig Exp $
 
 .if ${.INCLUDEDFROMFILE} == "include-main.mk"
 .  info sub-before-ok
 .else
-.  warning sub-before-fail
+.  warning sub-before-fail(${.INCLUDEDFROMFILE})
 .endif
 
+# As of 2020-09-05, the .for loop is implemented as "including a file"
+# with a custom buffer.  Therefore this loop has side effects on these
+# variables.
+.for i in once
+.  if ${.INCLUDEDFROMFILE} == "include-main.mk"
+.info sub-before-for-ok
+.  else
+.warning sub-before-for-fail(${.INCLUDEDFROMFILE})
+.  endif
+.endfor
+
 .include "include-subsub.mk"
 
 .if ${.INCLUDEDFROMFILE} == "include-main.mk"
@@ -13,3 +24,11 @@
 .else
 .  warning sub-after-fail(${.INCLUDEDFROMFILE})
 .endif
+
+.for i in once
+.  if ${.INCLUDEDFROMFILE} == "include-main.mk"
+.info sub-after-for-ok
+.  else
+.warning sub-after-for-fail(${.INCLUDEDFROMFILE})
+.  endif
+.endfor
Index: src/usr.bin/make/unit-tests/include-subsub.mk
diff -u src/usr.bin/make/unit-tests/include-subsub.mk:1.2 src/usr.bin/make/unit-tests/include-subsub.mk:1.3
--- src/usr.bin/make/unit-tests/include-subsub.mk:1.2	Sat Sep  5 16:59:19 2020
+++ src/usr.bin/make/unit-tests/include-subsub.mk	Sat Sep  5 18:13:47 2020
@@ -1,7 +1,7 @@
-# $NetBSD: include-subsub.mk,v 1.2 2020/09/05 16:59:19 rillig Exp $
+# $NetBSD: include-subsub.mk,v 1.3 2020/09/05 18:13:47 rillig Exp $
 
-.if ${.INCLUDEDFROMFILE:T} == "include-sub.mk"
+.if ${.INCLUDEDFROMFILE} == "include-sub.mk"
 .  info subsub-ok
 .else
-.  warning subsub-fail
+.  warning subsub-fail(${.INCLUDEDFROMFILE})
 .endif

Index: src/usr.bin/make/unit-tests/include-main.mk
diff -u src/usr.bin/make/unit-tests/include-main.mk:1.3 src/usr.bin/make/unit-tests/include-main.mk:1.4
--- src/usr.bin/make/unit-tests/include-main.mk:1.3	Sat Sep  5 16:59:19 2020
+++ src/usr.bin/make/unit-tests/include-main.mk	Sat Sep  5 18:13:47 2020
@@ -1,4 +1,4 @@
-# $NetBSD: include-main.mk,v 1.3 2020/09/05 16:59:19 rillig Exp $
+# $NetBSD: include-main.mk,v 1.4 2020/09/05 18:13:47 rillig Exp $
 #
 # Demonstrates that the .INCLUDEDFROMFILE magic variable does not behave
 # as described in the manual page.
@@ -14,6 +14,14 @@
 .  warning main-before-fail(${.INCLUDEDFROMFILE})
 .endif
 
+.for i in once
+.  if !defined(${.INCLUDEDFROMFILE})
+.info main-before-for-ok
+.  else
+.warning main-before-for-fail(${.INCLUDEDFROMFILE})
+.  endif
+.endfor
+
 .include "include-sub.mk"
 
 .if !defined(.INCLUDEDFROMFILE)
@@ -22,4 +30,12 @@
 .  warning main-after-fail(${.INCLUDEDFROMFILE})
 .endif
 
+.for i in once
+.  if !defined(${.INCLUDEDFROMFILE})
+.info main-after-for-ok
+.  else
+.warning main-after-for-fail(${.INCLUDEDFROMFILE})
+.  endif
+.endfor
+
 all:	# nothing



CVS commit: src/usr.bin/make/unit-tests

2020-09-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep  5 15:57:13 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: depsrc-exec.exp depsrc-exec.mk
depsrc-made.exp depsrc-made.mk depsrc-make.exp depsrc-make.mk
depsrc-notmain.exp depsrc-notmain.mk depsrc-optional.exp
depsrc-optional.mk depsrc-phony.exp depsrc-phony.mk
depsrc-recursive.exp depsrc-recursive.mk

Log Message:
make(1): add tests for some of the special sources


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/depsrc-exec.exp \
src/usr.bin/make/unit-tests/depsrc-made.exp \
src/usr.bin/make/unit-tests/depsrc-make.exp \
src/usr.bin/make/unit-tests/depsrc-notmain.exp \
src/usr.bin/make/unit-tests/depsrc-optional.exp \
src/usr.bin/make/unit-tests/depsrc-phony.exp \
src/usr.bin/make/unit-tests/depsrc-recursive.exp
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/depsrc-exec.mk \
src/usr.bin/make/unit-tests/depsrc-made.mk \
src/usr.bin/make/unit-tests/depsrc-make.mk \
src/usr.bin/make/unit-tests/depsrc-notmain.mk \
src/usr.bin/make/unit-tests/depsrc-optional.mk \
src/usr.bin/make/unit-tests/depsrc-phony.mk \
src/usr.bin/make/unit-tests/depsrc-recursive.mk

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/unit-tests/depsrc-exec.exp
diff -u src/usr.bin/make/unit-tests/depsrc-exec.exp:1.1 src/usr.bin/make/unit-tests/depsrc-exec.exp:1.2
--- src/usr.bin/make/unit-tests/depsrc-exec.exp:1.1	Sun Aug 16 12:07:51 2020
+++ src/usr.bin/make/unit-tests/depsrc-exec.exp	Sat Sep  5 15:57:12 2020
@@ -1 +1,2 @@
+: depsrc-exec.mk: This is always executed.
 exit status 0
Index: src/usr.bin/make/unit-tests/depsrc-made.exp
diff -u src/usr.bin/make/unit-tests/depsrc-made.exp:1.1 src/usr.bin/make/unit-tests/depsrc-made.exp:1.2
--- src/usr.bin/make/unit-tests/depsrc-made.exp:1.1	Sun Aug 16 12:07:51 2020
+++ src/usr.bin/make/unit-tests/depsrc-made.exp	Sat Sep  5 15:57:12 2020
@@ -1 +1,3 @@
+: Making chapter21
+: Making chapter22
 exit status 0
Index: src/usr.bin/make/unit-tests/depsrc-make.exp
diff -u src/usr.bin/make/unit-tests/depsrc-make.exp:1.1 src/usr.bin/make/unit-tests/depsrc-make.exp:1.2
--- src/usr.bin/make/unit-tests/depsrc-make.exp:1.1	Sun Aug 16 12:07:51 2020
+++ src/usr.bin/make/unit-tests/depsrc-make.exp	Sat Sep  5 15:57:12 2020
@@ -1 +1,3 @@
+this-is-made is made.
+echo this-is-not-made is just echoed.
 exit status 0
Index: src/usr.bin/make/unit-tests/depsrc-notmain.exp
diff -u src/usr.bin/make/unit-tests/depsrc-notmain.exp:1.1 src/usr.bin/make/unit-tests/depsrc-notmain.exp:1.2
--- src/usr.bin/make/unit-tests/depsrc-notmain.exp:1.1	Sun Aug 16 12:07:51 2020
+++ src/usr.bin/make/unit-tests/depsrc-notmain.exp	Sat Sep  5 15:57:12 2020
@@ -1 +1,2 @@
+: all
 exit status 0
Index: src/usr.bin/make/unit-tests/depsrc-optional.exp
diff -u src/usr.bin/make/unit-tests/depsrc-optional.exp:1.1 src/usr.bin/make/unit-tests/depsrc-optional.exp:1.2
--- src/usr.bin/make/unit-tests/depsrc-optional.exp:1.1	Sun Aug 16 12:07:51 2020
+++ src/usr.bin/make/unit-tests/depsrc-optional.exp	Sat Sep  5 15:57:12 2020
@@ -1 +1,2 @@
+`all' is up to date.
 exit status 0
Index: src/usr.bin/make/unit-tests/depsrc-phony.exp
diff -u src/usr.bin/make/unit-tests/depsrc-phony.exp:1.1 src/usr.bin/make/unit-tests/depsrc-phony.exp:1.2
--- src/usr.bin/make/unit-tests/depsrc-phony.exp:1.1	Sun Aug 16 12:07:51 2020
+++ src/usr.bin/make/unit-tests/depsrc-phony.exp	Sat Sep  5 15:57:12 2020
@@ -1 +1,2 @@
+: depsrc-phony.mk is made.
 exit status 0
Index: src/usr.bin/make/unit-tests/depsrc-recursive.exp
diff -u src/usr.bin/make/unit-tests/depsrc-recursive.exp:1.1 src/usr.bin/make/unit-tests/depsrc-recursive.exp:1.2
--- src/usr.bin/make/unit-tests/depsrc-recursive.exp:1.1	Sun Aug 16 12:07:51 2020
+++ src/usr.bin/make/unit-tests/depsrc-recursive.exp	Sat Sep  5 15:57:12 2020
@@ -1 +1,3 @@
+this-is-made is made.
+echo this-is-not-made is just echoed.
 exit status 0

Index: src/usr.bin/make/unit-tests/depsrc-exec.mk
diff -u src/usr.bin/make/unit-tests/depsrc-exec.mk:1.2 src/usr.bin/make/unit-tests/depsrc-exec.mk:1.3
--- src/usr.bin/make/unit-tests/depsrc-exec.mk:1.2	Sun Aug 16 14:25:16 2020
+++ src/usr.bin/make/unit-tests/depsrc-exec.mk	Sat Sep  5 15:57:12 2020
@@ -1,8 +1,16 @@
-# $NetBSD: depsrc-exec.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: depsrc-exec.mk,v 1.3 2020/09/05 15:57:12 rillig Exp $
 #
-# Tests for the special source .EXEC in dependency declarations.
+# Tests for the special source .EXEC in dependency declarations,
+# which always executes the commands, even if the target is up to date.
+# The target itself is considered up to date.
+#
+# TODO: Describe possible use cases for .EXEC.
+
+all: ${MAKEFILE} ${MAKEFILE:H}/depsrc.mk
 
-# TODO: Implementation
+${MAKEFILE}: .EXEC
+	: ${.TARGET:T}: This is always executed.
 
-all:
-	@:;

CVS commit: src/usr.bin/make

2020-09-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep  5 18:31:03 UTC 2020

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

Log Message:
make(1): make GetActuallyIncludingFile faster

In deeply nested includes, starting the search from the inner end is
faster since it needs fewer comparisons.


To generate a diff of this commit:
cvs rdiff -u -r1.281 -r1.282 src/usr.bin/make/parse.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/parse.c
diff -u src/usr.bin/make/parse.c:1.281 src/usr.bin/make/parse.c:1.282
--- src/usr.bin/make/parse.c:1.281	Sat Sep  5 18:18:05 2020
+++ src/usr.bin/make/parse.c	Sat Sep  5 18:31:03 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.281 2020/09/05 18:18:05 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.282 2020/09/05 18:31:03 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: parse.c,v 1.281 2020/09/05 18:18:05 rillig Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.282 2020/09/05 18:31:03 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)parse.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: parse.c,v 1.281 2020/09/05 18:18:05 rillig Exp $");
+__RCSID("$NetBSD: parse.c,v 1.282 2020/09/05 18:31:03 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -2343,17 +2343,16 @@ SetFilenameVars(const char *filename, co
 static const char *
 GetActuallyIncludingFile(void)
 {
-const char *filename = NULL;
 size_t i;
 
 /* XXX: Stack was supposed to be an opaque data structure. */
-for (i = 0; i < includes.len; i++) {
-	IFile *parent = includes.items[i];
-	IFile *child = (i + 1 < includes.len) ? includes.items[i + 1] : curFile;
+for (i = includes.len; i > 0; i--) {
+	IFile *parent = includes.items[i - 1];
+	IFile *child = (i < includes.len) ? includes.items[i] : curFile;
 	if (!child->fromForLoop)
-	filename = parent->fname;
+	return parent->fname;
 }
-return filename;
+return NULL;
 }
 
 /* Set .PARSEDIR/.PARSEFILE to the given filename, as well as



CVS commit: src/usr.bin/make

2020-09-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep  5 18:41:59 UTC 2020

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

Log Message:
make(1): fix comments about setting .PARSEDIR and .PARSEFILE


To generate a diff of this commit:
cvs rdiff -u -r1.282 -r1.283 src/usr.bin/make/parse.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/parse.c
diff -u src/usr.bin/make/parse.c:1.282 src/usr.bin/make/parse.c:1.283
--- src/usr.bin/make/parse.c:1.282	Sat Sep  5 18:31:03 2020
+++ src/usr.bin/make/parse.c	Sat Sep  5 18:41:59 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.282 2020/09/05 18:31:03 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.283 2020/09/05 18:41:59 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: parse.c,v 1.282 2020/09/05 18:31:03 rillig Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.283 2020/09/05 18:41:59 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)parse.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: parse.c,v 1.282 2020/09/05 18:31:03 rillig Exp $");
+__RCSID("$NetBSD: parse.c,v 1.283 2020/09/05 18:41:59 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -2355,8 +2355,7 @@ GetActuallyIncludingFile(void)
 return NULL;
 }
 
-/* Set .PARSEDIR/.PARSEFILE to the given filename, as well as
- * .INCLUDEDFROMDIR/.INCLUDEDFROMFILE. */
+/* Set .PARSEDIR, .PARSEFILE, .INCLUDEDFROMDIR and .INCLUDEDFROMFILE. */
 static void
 ParseSetParseFile(const char *filename)
 {
@@ -2375,11 +2374,9 @@ ParseSetParseFile(const char *filename)
 }
 
 /*
- * Track the makefiles we read - so makefiles can
- * set dependencies on them.
+ * Track the makefiles we read - so makefiles can set dependencies on them.
  * Avoid adding anything more than once.
  */
-
 static void
 ParseTrackInput(const char *name)
 {
@@ -2714,7 +2711,6 @@ ParseEOF(void)
 	fprintf(debug_file, "ParseEOF: returning to file %s, line %d\n",
 	curFile->fname, curFile->lineno);
 
-/* Restore the PARSEDIR/PARSEFILE variables */
 ParseSetParseFile(curFile->fname);
 return CONTINUE;
 }



CVS commit: src/usr.bin/make/unit-tests

2020-09-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep  5 13:34:19 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: varname.exp

Log Message:
make(1): add expected test result for hashing variable names


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/varname.exp

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/unit-tests/varname.exp
diff -u src/usr.bin/make/unit-tests/varname.exp:1.1 src/usr.bin/make/unit-tests/varname.exp:1.2
--- src/usr.bin/make/unit-tests/varname.exp:1.1	Sun Aug 16 12:07:52 2020
+++ src/usr.bin/make/unit-tests/varname.exp	Sat Sep  5 13:34:19 2020
@@ -1 +1,19 @@
+MAGIC1B1B1B  = 1
+MAGIC1B1B0a  = 2
+MAGIC1B0a1B  = 3
+MAGIC1B0a0a  = 4
+MAGIC0a1B1B  = 5
+MAGIC0a1B0a  = 6
+MAGIC0a0a1B  = 7
+MAGIC0a0a0a  = 8
+ORDER_01 = yes
+MAGIC0a0a0a  = 1
+MAGIC0a0a1B  = 2
+MAGIC0a1B0a  = 3
+MAGIC0a1B1B  = 4
+MAGIC1B0a0a  = 5
+MAGIC1B0a1B  = 6
+MAGIC1B1B0a  = 7
+MAGIC1B1B1B  = 8
+ORDER_10 = yes
 exit status 0



CVS commit: src/usr.bin/make/unit-tests

2020-09-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep  5 12:59:07 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: Makefile varname.mk

Log Message:
make(1): add test for intentional hash collision for variable names

Hash collisions may slow down make in certain special situations.  There
is no point though in maliciously triggering such a situation since
anyone who can inject values into makefiles can easily run shell
commands using the :!cmd! modifier or similar mechanisms.  Crafting
variable names just to slow down make is thus not an attack vector.


To generate a diff of this commit:
cvs rdiff -u -r1.135 -r1.136 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/varname.mk

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/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.135 src/usr.bin/make/unit-tests/Makefile:1.136
--- src/usr.bin/make/unit-tests/Makefile:1.135	Sat Sep  5 06:36:40 2020
+++ src/usr.bin/make/unit-tests/Makefile	Sat Sep  5 12:59:07 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.135 2020/09/05 06:36:40 rillig Exp $
+# $NetBSD: Makefile,v 1.136 2020/09/05 12:59:07 rillig Exp $
 #
 # Unit tests for make(1)
 #
@@ -393,6 +393,7 @@ POSTPROC.deptgt-suffixes= \
 			${TOOL_SED} -n -e '/^\#\*\*\* Suffixes/,/^\#\*/p'
 POSTPROC.vardebug=	${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
 POSTPROC.varmod-match-escape= ${TOOL_SED} -n -e '/^Pattern/p'
+POSTPROC.varname=	${TOOL_SED} -n -e '/^MAGIC/p' -e '/^ORDER_/p'
 POSTPROC.varname-dot-shell= \
 			awk '/\.SHELL/ || /^ParseReadLine/'
 POSTPROC.varname-empty=	${TOOL_SED} -n -e '/^Var_Set/p' -e '/^out:/p'

Index: src/usr.bin/make/unit-tests/varname.mk
diff -u src/usr.bin/make/unit-tests/varname.mk:1.2 src/usr.bin/make/unit-tests/varname.mk:1.3
--- src/usr.bin/make/unit-tests/varname.mk:1.2	Sun Aug 16 14:25:16 2020
+++ src/usr.bin/make/unit-tests/varname.mk	Sat Sep  5 12:59:07 2020
@@ -1,8 +1,43 @@
-# $NetBSD: varname.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: varname.mk,v 1.3 2020/09/05 12:59:07 rillig Exp $
 #
 # Tests for special variables, such as .MAKE or .PARSEDIR.
 
-# TODO: Implementation
+# These following MAGIC variables have the same hash code, at least with
+# the default hashing algorithm, which is the same as in Java.  The order
+# in which these variables are defined determines the order in which they
+# appear in the Hash_Table.  New entries are prepended to the bucket lists,
+# therefore this test numbers the values in descending order.
+
+.if defined(ORDER_01)
+
+MAGIC0a0a0a=	8
+MAGIC0a0a1B=	7
+MAGIC0a1B0a=	6
+MAGIC0a1B1B=	5
+MAGIC1B0a0a=	4
+MAGIC1B0a1B=	3
+MAGIC1B1B0a=	2
+MAGIC1B1B1B=	1
+
+all: # nothing
+
+.elif defined(ORDER_10)
+
+MAGIC1B1B1B=	8
+MAGIC1B1B0a=	7
+MAGIC1B0a1B=	6
+MAGIC1B0a0a=	5
+MAGIC0a1B1B=	4
+MAGIC0a1B0a=	3
+MAGIC0a0a1B=	2
+MAGIC0a0a0a=	1
+
+all: # nothing
+
+.else
 
 all:
-	@:;
+	@${.MAKE} -f ${MAKEFILE} -dg1 ORDER_01=yes
+	@${.MAKE} -f ${MAKEFILE} -dg1 ORDER_10=yes
+
+.endif



CVS commit: src/usr.bin/make

2020-09-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep  5 06:46:13 UTC 2020

Modified Files:
src/usr.bin/make: suff.c targ.c
src/usr.bin/make/unit-tests: opt-debug-graph1.exp opt-debug-graph1.mk

Log Message:
make(1): remove trailing whitespace in -dg1 debug output


To generate a diff of this commit:
cvs rdiff -u -r1.142 -r1.143 src/usr.bin/make/suff.c
cvs rdiff -u -r1.81 -r1.82 src/usr.bin/make/targ.c
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/opt-debug-graph1.exp \
src/usr.bin/make/unit-tests/opt-debug-graph1.mk

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/suff.c
diff -u src/usr.bin/make/suff.c:1.142 src/usr.bin/make/suff.c:1.143
--- src/usr.bin/make/suff.c:1.142	Mon Aug 31 16:44:25 2020
+++ src/usr.bin/make/suff.c	Sat Sep  5 06:46:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: suff.c,v 1.142 2020/08/31 16:44:25 rillig Exp $	*/
+/*	$NetBSD: suff.c,v 1.143 2020/09/05 06:46:12 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: suff.c,v 1.142 2020/08/31 16:44:25 rillig Exp $";
+static char rcsid[] = "$NetBSD: suff.c,v 1.143 2020/09/05 06:46:12 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)suff.c	8.4 (Berkeley) 3/21/94";
 #else
-__RCSID("$NetBSD: suff.c,v 1.142 2020/08/31 16:44:25 rillig Exp $");
+__RCSID("$NetBSD: suff.c,v 1.143 2020/09/05 06:46:12 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -2234,7 +2234,7 @@ SuffPrintTrans(void *tp, void *dummy MAK
 {
 GNode   *t = (GNode *)tp;
 
-fprintf(debug_file, "%-16s: ", t->name);
+fprintf(debug_file, "%-16s:", t->name);
 Targ_PrintType(t->type);
 fputc('\n', debug_file);
 Lst_ForEach(t->commands, Targ_PrintCmd, NULL);

Index: src/usr.bin/make/targ.c
diff -u src/usr.bin/make/targ.c:1.81 src/usr.bin/make/targ.c:1.82
--- src/usr.bin/make/targ.c:1.81	Tue Sep  1 20:54:00 2020
+++ src/usr.bin/make/targ.c	Sat Sep  5 06:46:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: targ.c,v 1.81 2020/09/01 20:54:00 rillig Exp $	*/
+/*	$NetBSD: targ.c,v 1.82 2020/09/05 06:46:12 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: targ.c,v 1.81 2020/09/01 20:54:00 rillig Exp $";
+static char rcsid[] = "$NetBSD: targ.c,v 1.82 2020/09/05 06:46:12 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)targ.c	8.2 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: targ.c,v 1.81 2020/09/01 20:54:00 rillig Exp $");
+__RCSID("$NetBSD: targ.c,v 1.82 2020/09/05 06:46:12 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -406,8 +406,8 @@ Targ_PrintType(int type)
 {
 inttbit;
 
-#define PRINTBIT(attr)	case CONCAT(OP_,attr): fprintf(debug_file, "." #attr " "); break
-#define PRINTDBIT(attr) case CONCAT(OP_,attr): if (DEBUG(TARG))fprintf(debug_file, "." #attr " "); break
+#define PRINTBIT(attr)	case CONCAT(OP_,attr): fprintf(debug_file, " ." #attr); break
+#define PRINTDBIT(attr) case CONCAT(OP_,attr): if (DEBUG(TARG))fprintf(debug_file, " ." #attr); break
 
 type &= ~OP_OPMASK;
 
@@ -428,7 +428,7 @@ Targ_PrintType(int type)
 	PRINTBIT(NOTMAIN);
 	PRINTDBIT(LIB);
 	/*XXX: MEMBER is defined, so CONCAT(OP_,MEMBER) gives OP_"%" */
-	case OP_MEMBER: if (DEBUG(TARG))fprintf(debug_file, ".MEMBER "); break;
+	case OP_MEMBER: if (DEBUG(TARG))fprintf(debug_file, " .MEMBER"); break;
 	PRINTDBIT(ARCHV);
 	PRINTDBIT(MADE);
 	PRINTDBIT(PHONY);
@@ -515,11 +515,11 @@ Targ_PrintNode(void *gnp, void *passp)
 	fprintf(debug_file, "%-16s", gn->name);
 	switch (gn->type & OP_OPMASK) {
 	case OP_DEPENDS:
-		fprintf(debug_file, ": "); break;
+		fprintf(debug_file, ":"); break;
 	case OP_FORCE:
-		fprintf(debug_file, "! "); break;
+		fprintf(debug_file, "!"); break;
 	case OP_DOUBLEDEP:
-		fprintf(debug_file, ":: "); break;
+		fprintf(debug_file, "::"); break;
 	}
 	Targ_PrintType(gn->type);
 	Lst_ForEach(gn->children, TargPrintName, NULL);
@@ -542,7 +542,7 @@ TargPrintOnlySrc(void *gnp, void *dummy 
 if (!OP_NOP(gn->type))
 	return 0;
 
-fprintf(debug_file, "#\t%s [%s] ",
+fprintf(debug_file, "#\t%s [%s]",
 	gn->name, gn->path ? gn->path : gn->name);
 Targ_PrintType(gn->type);
 fprintf(debug_file, "\n");

Index: src/usr.bin/make/unit-tests/opt-debug-graph1.exp
diff -u src/usr.bin/make/unit-tests/opt-debug-graph1.exp:1.2 src/usr.bin/make/unit-tests/opt-debug-graph1.exp:1.3
--- src/usr.bin/make/unit-tests/opt-debug-graph1.exp:1.2	Sat Sep  5 06:36:40 2020
+++ src/usr.bin/make/unit-tests/opt-debug-graph1.exp	Sat Sep  5 06:46:12 2020
@@ -5,11 +5,13 @@
 # made-source, made UNMADE, type OP_DEPENDS, flags none
 # unmade-target, made UNMADE, type OP_DEPENDS, flags none
 # unmade-sources, made UNMADE, type none, flags none
+# 

CVS commit: src/distrib/sets/lists/comp

2020-09-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep  5 11:00:18 UTC 2020

Modified Files:
src/distrib/sets/lists/comp: ad.sh3

Log Message:
fix alignment in ad.sh3


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/distrib/sets/lists/comp/ad.sh3

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

Modified files:

Index: src/distrib/sets/lists/comp/ad.sh3
diff -u src/distrib/sets/lists/comp/ad.sh3:1.43 src/distrib/sets/lists/comp/ad.sh3:1.44
--- src/distrib/sets/lists/comp/ad.sh3:1.43	Thu Oct  3 00:59:50 2019
+++ src/distrib/sets/lists/comp/ad.sh3	Sat Sep  5 11:00:18 2020
@@ -1,4 +1,4 @@
-# $NetBSD: ad.sh3,v 1.43 2019/10/03 00:59:50 mrg Exp $
+# $NetBSD: ad.sh3,v 1.44 2020/09/05 11:00:18 rillig Exp $
 ./usr/include/gcc-4.5/tgmath.h			comp-obsolete		obsolete
 ./usr/include/gcc-4.8/tgmath.h			comp-obsolete		obsolete
 ./usr/include/gcc-5/tgmath.h			comp-obsolete		obsolete
@@ -56,7 +56,7 @@
 ./usr/include/sh3/stdarg.h			comp-obsolete		obsolete
 ./usr/include/sh3/sysarch.h			comp-c-include
 ./usr/include/sh3/types.h			comp-c-include
-./usr/include/sh3/va-sh.h			comp-obsolete	obsolete
+./usr/include/sh3/va-sh.h			comp-obsolete		obsolete
 ./usr/include/sh3/varargs.h			comp-obsolete		obsolete
 ./usr/include/sh3/vmparam.h			comp-c-include
 ./usr/include/sh3/wchar_limits.h		comp-c-include



CVS commit: src/usr.bin/make

2020-09-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep  5 13:55:08 UTC 2020

Modified Files:
src/usr.bin/make: arch.c dir.c hash.c hash.h targ.c

Log Message:
make(1): remove initial size argument from Hash_InitTable

In all but one case this argument was set to auto-detect anyway.  The
one case where it was set was not worth keeping this complicated API.


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 src/usr.bin/make/arch.c
cvs rdiff -u -r1.135 -r1.136 src/usr.bin/make/dir.c
cvs rdiff -u -r1.30 -r1.31 src/usr.bin/make/hash.c
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/make/hash.h
cvs rdiff -u -r1.82 -r1.83 src/usr.bin/make/targ.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/arch.c
diff -u src/usr.bin/make/arch.c:1.107 src/usr.bin/make/arch.c:1.108
--- src/usr.bin/make/arch.c:1.107	Sun Aug 30 11:15:05 2020
+++ src/usr.bin/make/arch.c	Sat Sep  5 13:55:08 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: arch.c,v 1.107 2020/08/30 11:15:05 rillig Exp $	*/
+/*	$NetBSD: arch.c,v 1.108 2020/09/05 13:55:08 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: arch.c,v 1.107 2020/08/30 11:15:05 rillig Exp $";
+static char rcsid[] = "$NetBSD: arch.c,v 1.108 2020/09/05 13:55:08 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)arch.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: arch.c,v 1.107 2020/08/30 11:15:05 rillig Exp $");
+__RCSID("$NetBSD: arch.c,v 1.108 2020/09/05 13:55:08 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -572,7 +572,7 @@ ArchStatMember(const char *archive, cons
 ar->name = bmake_strdup(archive);
 ar->fnametab = NULL;
 ar->fnamesize = 0;
-Hash_InitTable(>members, -1);
+Hash_InitTable(>members);
 memName[AR_MAX_NAME_LEN] = '\0';
 
 while (fread((char *), sizeof(struct ar_hdr), 1, arch) == 1) {

Index: src/usr.bin/make/dir.c
diff -u src/usr.bin/make/dir.c:1.135 src/usr.bin/make/dir.c:1.136
--- src/usr.bin/make/dir.c:1.135	Wed Sep  2 04:32:13 2020
+++ src/usr.bin/make/dir.c	Sat Sep  5 13:55:08 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.c,v 1.135 2020/09/02 04:32:13 rillig Exp $	*/
+/*	$NetBSD: dir.c,v 1.136 2020/09/05 13:55:08 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: dir.c,v 1.135 2020/09/02 04:32:13 rillig Exp $";
+static char rcsid[] = "$NetBSD: dir.c,v 1.136 2020/09/05 13:55:08 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)dir.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: dir.c,v 1.135 2020/09/02 04:32:13 rillig Exp $");
+__RCSID("$NetBSD: dir.c,v 1.136 2020/09/05 13:55:08 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -358,8 +358,8 @@ Dir_Init(void)
 {
 dirSearchPath = Lst_Init();
 openDirectories = Lst_Init();
-Hash_InitTable(, 0);
-Hash_InitTable(, 0);
+Hash_InitTable();
+Hash_InitTable();
 }
 
 void
@@ -371,7 +371,7 @@ Dir_InitDir(const char *cdname)
 dotLast->refCount = 1;
 dotLast->hits = 0;
 dotLast->name = bmake_strdup(".DOTLAST");
-Hash_InitTable(>files, -1);
+Hash_InitTable(>files);
 }
 
 /*
@@ -1547,7 +1547,7 @@ Dir_AddDir(Lst path, const char *name)
 	p->name = bmake_strdup(name);
 	p->hits = 0;
 	p->refCount = 1;
-	Hash_InitTable(>files, -1);
+	Hash_InitTable(>files);
 
 	while ((dp = readdir(d)) != NULL) {
 #if defined(sun) && defined(d_ino) /* d_ino is a sunos4 #define for d_fileno */

Index: src/usr.bin/make/hash.c
diff -u src/usr.bin/make/hash.c:1.30 src/usr.bin/make/hash.c:1.31
--- src/usr.bin/make/hash.c:1.30	Sat Sep  5 13:36:25 2020
+++ src/usr.bin/make/hash.c	Sat Sep  5 13:55:08 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: hash.c,v 1.30 2020/09/05 13:36:25 rillig Exp $	*/
+/*	$NetBSD: hash.c,v 1.31 2020/09/05 13:55:08 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: hash.c,v 1.30 2020/09/05 13:36:25 rillig Exp $";
+static char rcsid[] = "$NetBSD: hash.c,v 1.31 2020/09/05 13:55:08 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)hash.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: hash.c,v 1.30 2020/09/05 13:36:25 rillig Exp $");
+__RCSID("$NetBSD: hash.c,v 1.31 2020/09/05 13:55:08 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -120,33 +120,20 @@ static void RebuildTable(Hash_Table *);
  *
  * Input:
  *	t		Structure to to hold the table.
- *	numBuckets	How many buckets to create for starters. This
- *			number is rounded up to a power of two.   If
- *			<= 0, a reasonable default is chosen. The
- *			table will grow in size later as needed.
  */
 void
-Hash_InitTable(Hash_Table *t, int 

CVS commit: src/usr.bin/make/unit-tests

2020-09-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep  5 06:25:38 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: varname-makefile.mk

Log Message:
make(1): fix test for the MAKEFILE variable

That test had assumed that it would always be run with CURDIR ==
PARSEDIR, which is not the case for ./build.sh.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/varname-makefile.mk

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/unit-tests/varname-makefile.mk
diff -u src/usr.bin/make/unit-tests/varname-makefile.mk:1.1 src/usr.bin/make/unit-tests/varname-makefile.mk:1.2
--- src/usr.bin/make/unit-tests/varname-makefile.mk:1.1	Fri Sep  4 17:05:39 2020
+++ src/usr.bin/make/unit-tests/varname-makefile.mk	Sat Sep  5 06:25:38 2020
@@ -1,4 +1,4 @@
-# $NetBSD: varname-makefile.mk,v 1.1 2020/09/04 17:05:39 rillig Exp $
+# $NetBSD: varname-makefile.mk,v 1.2 2020/09/05 06:25:38 rillig Exp $
 #
 # Tests for the special MAKEFILE variable, which contains the current
 # makefile from the -f command line option.
@@ -8,7 +8,7 @@
 # Including a file via .include does not influence the MAKEFILE
 # variable though.
 
-.if ${MAKEFILE} != "varname-makefile.mk"
+.if ${MAKEFILE:T} != "varname-makefile.mk"
 .  error
 .endif
 
@@ -20,7 +20,7 @@
 # namespace.
 #
 .undef MAKEFILE
-.if ${MAKEFILE} != "varname-makefile.mk"
+.if ${MAKEFILE:T} != "varname-makefile.mk"
 .  error
 .endif
 
@@ -28,7 +28,7 @@
 # serves as a fallback for the "Global" namespace (see VarFind).
 #
 MAKEFILE=	overwritten
-.if ${MAKEFILE} != "overwritten"
+.if ${MAKEFILE:T} != "overwritten"
 .  error
 .endif
 
@@ -36,7 +36,7 @@ MAKEFILE=	overwritten
 # visible again.
 #
 .undef MAKEFILE
-.if ${MAKEFILE} != "varname-makefile.mk"
+.if ${MAKEFILE:T} != "varname-makefile.mk"
 .  error
 .endif
 



CVS commit: src/usr.bin/make

2020-09-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep  5 13:36:25 UTC 2020

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

Log Message:
make(1): make Hash_Table independent from -funsigned-char

This only makes a difference for Hash_Table keys outside the ASCII
character set, and these are barely used in practice, if at all.

The effects of this change can only be seen in debug mode, when printing
the full contents of the variable namespaces.  In this output, the order
of the entries might change.

All other use cases stay the same as before.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/usr.bin/make/hash.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/hash.c
diff -u src/usr.bin/make/hash.c:1.29 src/usr.bin/make/hash.c:1.30
--- src/usr.bin/make/hash.c:1.29	Tue Sep  1 21:11:31 2020
+++ src/usr.bin/make/hash.c	Sat Sep  5 13:36:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: hash.c,v 1.29 2020/09/01 21:11:31 rillig Exp $	*/
+/*	$NetBSD: hash.c,v 1.30 2020/09/05 13:36:25 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: hash.c,v 1.29 2020/09/01 21:11:31 rillig Exp $";
+static char rcsid[] = "$NetBSD: hash.c,v 1.30 2020/09/05 13:36:25 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)hash.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: hash.c,v 1.29 2020/09/01 21:11:31 rillig Exp $");
+__RCSID("$NetBSD: hash.c,v 1.30 2020/09/05 13:36:25 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -111,7 +111,7 @@ static void RebuildTable(Hash_Table *);
 /* The default: this one matches Gosling's emacs */
 #define HASH(h, key, p) do { \
 	for (h = 0, p = key; *p;) \
-		h = (h << 5) - h + *p++; \
+		h = (h << 5) - h + (unsigned char)*p++; \
 	} while (0)
 
 #endif



CVS commit: src

2020-09-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep  5 06:36:40 UTC 2020

Modified Files:
src/distrib/sets/lists/tests: mi
src/usr.bin/make/unit-tests: Makefile opt-debug-graph1.exp
opt-debug-graph1.mk
Removed Files:
src/usr.bin/make/unit-tests: opt-debug-g1.exp opt-debug-g1.mk

Log Message:
make(1): move test for -dg1 from opt-debug-g1 to opt-debug-graph1


To generate a diff of this commit:
cvs rdiff -u -r1.919 -r1.920 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.134 -r1.135 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r1.2 -r0 src/usr.bin/make/unit-tests/opt-debug-g1.exp
cvs rdiff -u -r1.1 -r0 src/usr.bin/make/unit-tests/opt-debug-g1.mk
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/opt-debug-graph1.exp \
src/usr.bin/make/unit-tests/opt-debug-graph1.mk

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

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.919 src/distrib/sets/lists/tests/mi:1.920
--- src/distrib/sets/lists/tests/mi:1.919	Sat Sep  5 06:20:50 2020
+++ src/distrib/sets/lists/tests/mi	Sat Sep  5 06:36:40 2020
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.919 2020/09/05 06:20:50 rillig Exp $
+# $NetBSD: mi,v 1.920 2020/09/05 06:36:40 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -4828,8 +4828,8 @@
 ./usr/tests/usr.bin/make/unit-tests/opt-debug-file.mktests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/opt-debug-for.exptests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/opt-debug-for.mktests-usr.bin-tests	compattestfile,atf
-./usr/tests/usr.bin/make/unit-tests/opt-debug-g1.exptests-usr.bin-tests	compattestfile,atf
-./usr/tests/usr.bin/make/unit-tests/opt-debug-g1.mktests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/opt-debug-g1.exptests-obsolete		obsolete
+./usr/tests/usr.bin/make/unit-tests/opt-debug-g1.mktests-obsolete		obsolete
 ./usr/tests/usr.bin/make/unit-tests/opt-debug-graph1.exp			tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/opt-debug-graph1.mktests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/opt-debug-graph2.exp			tests-usr.bin-tests	compattestfile,atf

Index: src/usr.bin/make/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.134 src/usr.bin/make/unit-tests/Makefile:1.135
--- src/usr.bin/make/unit-tests/Makefile:1.134	Sat Sep  5 06:20:51 2020
+++ src/usr.bin/make/unit-tests/Makefile	Sat Sep  5 06:36:40 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.134 2020/09/05 06:20:51 rillig Exp $
+# $NetBSD: Makefile,v 1.135 2020/09/05 06:36:40 rillig Exp $
 #
 # Unit tests for make(1)
 #
@@ -179,7 +179,6 @@ TESTS+=		opt-debug-dir
 TESTS+=		opt-debug-errors
 TESTS+=		opt-debug-file
 TESTS+=		opt-debug-for
-TESTS+=		opt-debug-g1
 TESTS+=		opt-debug-graph1
 TESTS+=		opt-debug-graph2
 TESTS+=		opt-debug-graph3
@@ -358,7 +357,6 @@ FLAGS.doterror=		# none
 FLAGS.envfirst=		-e
 FLAGS.export=		# none
 FLAGS.lint=		-dL -k
-FLAGS.opt-debug-g1=	-dg1
 FLAGS.opt-ignore=	-i
 FLAGS.opt-keep-going=	-k
 FLAGS.opt-no-action=	-n
@@ -375,8 +373,10 @@ FLAGS.varname-dot-shell= -dpv
 FLAGS.varname-empty=	-dv '$${:U}=cmdline-u' '=cmline-plain'
 
 # Some tests need extra post-processing.
-SED_CMDS.opt-debug-g1=	-e 's,${.CURDIR},CURDIR,'
-SED_CMDS.opt-debug-g1+=	-e '/Global Variables:/,/Suffixes:/d'
+SED_CMDS.opt-debug-graph1= \
+			-e 's,${.CURDIR},CURDIR,'
+SED_CMDS.opt-debug-graph1+= \
+			-e '/Global Variables:/,/Suffixes:/d'
 SED_CMDS.sh-dots=	-e 's,^.*\.\.\.:.*,,'
 SED_CMDS.varmod-subst-regex+= \
 			-e 's,\(Regex compilation error:\).*,\1 (details omitted),'

Index: src/usr.bin/make/unit-tests/opt-debug-graph1.exp
diff -u src/usr.bin/make/unit-tests/opt-debug-graph1.exp:1.1 src/usr.bin/make/unit-tests/opt-debug-graph1.exp:1.2
--- src/usr.bin/make/unit-tests/opt-debug-graph1.exp:1.1	Sat Sep  5 06:20:51 2020
+++ src/usr.bin/make/unit-tests/opt-debug-graph1.exp	Sat Sep  5 06:36:40 2020
@@ -1 +1,15 @@
+#*** Input graph:
+# all, made UNMADE, type OP_DEPENDS, flags none
+# made-target, made UNMADE, type OP_DEPENDS, flags none
+# made-target-no-sources, made UNMADE, type OP_DEPENDS, flags none
+# made-source, made UNMADE, type OP_DEPENDS, flags none
+# unmade-target, made UNMADE, type OP_DEPENDS, flags none
+# unmade-sources, made UNMADE, type none, flags none
+# unmade-target-no-sources, made UNMADE, type OP_DEPENDS, flags none
+
+
+#
+#   Files that are only sources:
+#	unmade-sources [unmade-sources] 
+#*** Transformations:
 exit status 0
Index: src/usr.bin/make/unit-tests/opt-debug-graph1.mk
diff -u src/usr.bin/make/unit-tests/opt-debug-graph1.mk:1.1 src/usr.bin/make/unit-tests/opt-debug-graph1.mk:1.2
--- src/usr.bin/make/unit-tests/opt-debug-graph1.mk:1.1	Sat Sep  5 06:20:51 2020
+++ 

CVS commit: src

2020-09-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep  5 06:20:51 UTC 2020

Modified Files:
src/distrib/sets/lists/tests: mi
src/usr.bin/make/unit-tests: Makefile archive.mk
Added Files:
src/usr.bin/make/unit-tests: opt-debug-all.exp opt-debug-all.mk
opt-debug-archive.exp opt-debug-archive.mk opt-debug-cond.exp
opt-debug-cond.mk opt-debug-curdir.exp opt-debug-curdir.mk
opt-debug-dir.exp opt-debug-dir.mk opt-debug-errors.exp
opt-debug-errors.mk opt-debug-file.exp opt-debug-file.mk
opt-debug-for.exp opt-debug-for.mk opt-debug-graph1.exp
opt-debug-graph1.mk opt-debug-graph2.exp opt-debug-graph2.mk
opt-debug-graph3.exp opt-debug-graph3.mk opt-debug-hash.exp
opt-debug-hash.mk opt-debug-jobs.exp opt-debug-jobs.mk
opt-debug-lint.exp opt-debug-lint.mk opt-debug-loud.exp
opt-debug-loud.mk opt-debug-making.exp opt-debug-making.mk
opt-debug-meta.exp opt-debug-meta.mk opt-debug-no-rm.exp
opt-debug-no-rm.mk opt-debug-parse.exp opt-debug-parse.mk
opt-debug-suff.exp opt-debug-suff.mk opt-debug-targets.exp
opt-debug-targets.mk opt-debug-var.exp opt-debug-var.mk
opt-debug-varraw.exp opt-debug-varraw.mk opt-debug-x-trace.exp
opt-debug-x-trace.mk

Log Message:
make(1): add tests for each debug option


To generate a diff of this commit:
cvs rdiff -u -r1.918 -r1.919 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.133 -r1.134 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/archive.mk
cvs rdiff -u -r0 -r1.1 src/usr.bin/make/unit-tests/opt-debug-all.exp \
src/usr.bin/make/unit-tests/opt-debug-all.mk \
src/usr.bin/make/unit-tests/opt-debug-archive.exp \
src/usr.bin/make/unit-tests/opt-debug-archive.mk \
src/usr.bin/make/unit-tests/opt-debug-cond.exp \
src/usr.bin/make/unit-tests/opt-debug-cond.mk \
src/usr.bin/make/unit-tests/opt-debug-curdir.exp \
src/usr.bin/make/unit-tests/opt-debug-curdir.mk \
src/usr.bin/make/unit-tests/opt-debug-dir.exp \
src/usr.bin/make/unit-tests/opt-debug-dir.mk \
src/usr.bin/make/unit-tests/opt-debug-errors.exp \
src/usr.bin/make/unit-tests/opt-debug-errors.mk \
src/usr.bin/make/unit-tests/opt-debug-file.exp \
src/usr.bin/make/unit-tests/opt-debug-file.mk \
src/usr.bin/make/unit-tests/opt-debug-for.exp \
src/usr.bin/make/unit-tests/opt-debug-for.mk \
src/usr.bin/make/unit-tests/opt-debug-graph1.exp \
src/usr.bin/make/unit-tests/opt-debug-graph1.mk \
src/usr.bin/make/unit-tests/opt-debug-graph2.exp \
src/usr.bin/make/unit-tests/opt-debug-graph2.mk \
src/usr.bin/make/unit-tests/opt-debug-graph3.exp \
src/usr.bin/make/unit-tests/opt-debug-graph3.mk \
src/usr.bin/make/unit-tests/opt-debug-hash.exp \
src/usr.bin/make/unit-tests/opt-debug-hash.mk \
src/usr.bin/make/unit-tests/opt-debug-jobs.exp \
src/usr.bin/make/unit-tests/opt-debug-jobs.mk \
src/usr.bin/make/unit-tests/opt-debug-lint.exp \
src/usr.bin/make/unit-tests/opt-debug-lint.mk \
src/usr.bin/make/unit-tests/opt-debug-loud.exp \
src/usr.bin/make/unit-tests/opt-debug-loud.mk \
src/usr.bin/make/unit-tests/opt-debug-making.exp \
src/usr.bin/make/unit-tests/opt-debug-making.mk \
src/usr.bin/make/unit-tests/opt-debug-meta.exp \
src/usr.bin/make/unit-tests/opt-debug-meta.mk \
src/usr.bin/make/unit-tests/opt-debug-no-rm.exp \
src/usr.bin/make/unit-tests/opt-debug-no-rm.mk \
src/usr.bin/make/unit-tests/opt-debug-parse.exp \
src/usr.bin/make/unit-tests/opt-debug-parse.mk \
src/usr.bin/make/unit-tests/opt-debug-suff.exp \
src/usr.bin/make/unit-tests/opt-debug-suff.mk \
src/usr.bin/make/unit-tests/opt-debug-targets.exp \
src/usr.bin/make/unit-tests/opt-debug-targets.mk \
src/usr.bin/make/unit-tests/opt-debug-var.exp \
src/usr.bin/make/unit-tests/opt-debug-var.mk \
src/usr.bin/make/unit-tests/opt-debug-varraw.exp \
src/usr.bin/make/unit-tests/opt-debug-varraw.mk \
src/usr.bin/make/unit-tests/opt-debug-x-trace.exp \
src/usr.bin/make/unit-tests/opt-debug-x-trace.mk

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

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.918 src/distrib/sets/lists/tests/mi:1.919
--- src/distrib/sets/lists/tests/mi:1.918	Fri Sep  4 17:05:39 2020
+++ src/distrib/sets/lists/tests/mi	Sat Sep  5 06:20:50 2020
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.918 2020/09/04 17:05:39 rillig Exp $
+# $NetBSD: mi,v 1.919 2020/09/05 06:20:50 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -4812,8 +4812,56 @@
 ./usr/tests/usr.bin/make/unit-tests/opt-backwards.mktests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/opt-chdir.exp			

CVS commit: src/distrib/sets

2020-09-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep  5 11:13:07 UTC 2020

Added Files:
src/distrib/sets: fmt-list

Log Message:
add distrib/sets/fmt-list to format the file lists consistently

This program is much more complicated than sort-list in the same
directory.  It takes care of aligning the fields of the lines so that
lines from the same directory are aligned to each other.  This reduces
horizontal jumps for the category and flags fields.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/distrib/sets/fmt-list

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

Added files:

Index: src/distrib/sets/fmt-list
diff -u /dev/null src/distrib/sets/fmt-list:1.1
--- /dev/null	Sat Sep  5 11:13:07 2020
+++ src/distrib/sets/fmt-list	Sat Sep  5 11:13:07 2020
@@ -0,0 +1,424 @@
+#! /usr/bin/lua
+-- $NetBSD: fmt-list,v 1.1 2020/09/05 11:13:07 rillig Exp $
+
+--[[
+
+Align the lines of a file list so that all lines from the same directory
+have the other fields at the same indentation.
+
+Sort the lines and remove duplicate lines.
+
+usage: ./fmt-list */*/{mi,ad.*,md.*}
+
+]]
+
+local function test(func)
+  func()
+end
+
+local function assert_equals(got, expected)
+  if got ~= expected then
+assert(false, string.format("got %q, expected %q", got, expected))
+  end
+end
+
+
+-- Calculate the width of the given string on the screen, assuming that
+-- the tab width is 8 and that the string starts at a tabstop.
+local function tabwidth(str)
+  local width = 0
+  for i = 1, #str do
+if string.sub(str, i, i) == "\t" then
+  width = width // 8 * 8 + 8
+else
+  width = width + 1
+end
+  end
+  return width
+end
+
+test(function()
+  assert_equals(tabwidth(""), 0)
+  assert_equals(tabwidth("1234"), 4)
+  assert_equals(tabwidth("\t"), 8)
+  assert_equals(tabwidth("1234567\t"), 8)
+  assert_equals(tabwidth("\t1234\t"), 16)
+  assert_equals(tabwidth("\t1234\t1"), 17)
+end)
+
+
+-- Calculate the tab characters that are necessary to set the width
+-- of the string to the desired width.
+local function tabs(str, width)
+  local strwidth = tabwidth(str)
+  local tabs = string.rep("\t", (width - strwidth + 7) // 8)
+  if tabs == "" then
+error(string.format("%q\t%d\t%d", str, strwidth, width))
+  end
+  assert(tabs ~= "")
+  return tabs
+end
+
+test(function()
+  assert_equals(tabs("", 8), "\t")
+  assert_equals(tabs("1234567", 8), "\t")
+  assert_equals(tabs("", 64), "\t\t\t\t\t\t\t\t")
+end)
+
+
+-- Group the items by a key and then execute the action on each of the
+-- groups.
+local function foreach_group(items, get_key, action)
+  local key
+  local group = {}
+  for _, item in ipairs(items) do
+local item_key = assert(get_key(item))
+if item_key ~= key then
+  if #group > 0 then action(group, key) end
+  key = item_key
+  group = {}
+end
+table.insert(group, item)
+  end
+  if #group > 0 then action(group, key) end
+end
+
+test(function()
+  local items = {
+{"prime", 2},
+{"prime", 3},
+{"not prime", 4},
+{"prime", 5},
+{"prime", 7}
+  }
+  local result = ""
+  foreach_group(
+items,
+function(item) return item[1] end,
+function(group, key)
+  result = result .. string.format("%d %s\n", #group, key)
+end)
+  assert_equals(result, "2 prime\n1 not prime\n2 prime\n")
+end)
+
+
+-- Parse a line from a file list and split it into its meaningful parts.
+local function parse_entry(line)
+
+  local category_align, prefix, fullname, flags_align, category, flags =
+line:match("^((%-?)(%.%S*)%s+)((%S+)%s+)(%S+)$")
+  if fullname == nil then
+category_align, prefix, fullname, category =
+  line:match("^((%-?)(%.%S*)%s+)(%S+)$")
+  end
+  if fullname == nil then
+prefix, fullname = line:match("^(%-)(%.%S*)$")
+  end
+  if fullname == nil then
+return
+  end
+
+  local dirname, basename = fullname:match("^(.+)/([^/]+)$")
+  if dirname == nil then
+dirname, basename = "", fullname
+  end
+
+  local category_col, flags_col
+  if category_align ~= nil then
+category_col = tabwidth(category_align)
+  end
+  if flags_align ~= nil then
+flags_col = tabwidth(flags_align)
+  end
+
+  return {
+prefix = prefix,
+fullname = fullname,
+dirname = dirname,
+basename = basename,
+category_col = category_col,
+category = category,
+flags_col = flags_col,
+flags = flags
+  }
+end
+
+test(function()
+  local entry = parse_entry("./dirname/filename\t\t\tcategory\tflags")
+  assert_equals(entry.prefix, "")
+  assert_equals(entry.fullname, "./dirname/filename")
+  assert_equals(entry.dirname, "./dirname")
+  assert_equals(entry.basename, "filename")
+  assert_equals(entry.category_col, 40)
+  assert_equals(entry.category, "category")
+  assert_equals(entry.flags_col, 16)
+  assert_equals(entry.flags, "flags")
+end)
+
+
+-- Return the smaller of the given values, ignoring nil.
+local function min(curr, 

CVS commit: src/usr.bin/make

2020-09-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Sep  3 17:16:01 UTC 2020

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

Log Message:
make(1): document use of magic values in CondDoEmpty


To generate a diff of this commit:
cvs rdiff -u -r1.108 -r1.109 src/usr.bin/make/cond.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.108 src/usr.bin/make/cond.c:1.109
--- src/usr.bin/make/cond.c:1.108	Thu Sep  3 16:14:58 2020
+++ src/usr.bin/make/cond.c	Thu Sep  3 17:16:01 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.108 2020/09/03 16:14:58 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.109 2020/09/03 17:16:01 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.108 2020/09/03 16:14:58 rillig Exp $";
+static char rcsid[] = "$NetBSD: cond.c,v 1.109 2020/09/03 17:16:01 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)cond.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: cond.c,v 1.108 2020/09/03 16:14:58 rillig Exp $");
+__RCSID("$NetBSD: cond.c,v 1.109 2020/09/03 17:16:01 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -719,6 +719,7 @@ get_mpt_arg(Boolean doEval, const char *
 static Boolean
 CondDoEmpty(int arglen, const char *arg MAKE_ATTR_UNUSED)
 {
+/* Magic values ahead, see get_mpt_arg. */
 return arglen == 1;
 }
 
@@ -1232,7 +1233,7 @@ Cond_Eval(const char *line)
 	}
 }
 
-/* And evaluate the conditional expresssion */
+/* And evaluate the conditional expression */
 if (Cond_EvalExpression(ifp, line, , 1, TRUE) == COND_INVALID) {
 	/* Syntax error in conditional, error message already output. */
 	/* Skip everything to matching .endif */



CVS commit: src/usr.bin/make/unit-tests

2020-09-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Sep  3 18:52:37 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: varmod-defined.mk varmod-undefined.mk

Log Message:
make(1): add tests for the :D and :U modifiers

This prepares a refactoring for ApplyModifier_Defined.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/varmod-defined.mk \
src/usr.bin/make/unit-tests/varmod-undefined.mk

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/unit-tests/varmod-defined.mk
diff -u src/usr.bin/make/unit-tests/varmod-defined.mk:1.3 src/usr.bin/make/unit-tests/varmod-defined.mk:1.4
--- src/usr.bin/make/unit-tests/varmod-defined.mk:1.3	Tue Aug 25 21:58:08 2020
+++ src/usr.bin/make/unit-tests/varmod-defined.mk	Thu Sep  3 18:52:36 2020
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-defined.mk,v 1.3 2020/08/25 21:58:08 rillig Exp $
+# $NetBSD: varmod-defined.mk,v 1.4 2020/09/03 18:52:36 rillig Exp $
 #
 # Tests for the :D variable modifier, which returns the given string
 # if the variable is defined.  It is closely related to the :U modifier.
@@ -24,5 +24,44 @@ DEF=	defined
 .error
 .endif
 
+# The modifier text may contain plain text as well as expressions.
+#
+.if ${DEF:D<${DEF}>} != ""
+.  error
+.endif
+
+# Special characters that would be interpreted differently can be escaped.
+# These are '}' (the closing character of the expression), ':', '$' and '\'.
+# Any other backslash sequences are preserved.
+#
+# The escaping rules for string literals in conditions are completely
+# different though. There, any character may be escaped using a backslash.
+#
+.if ${DEF:D \} \: \$ \\ \) \n } != " } : \$ \\ \\) \\n "
+.  error
+.endif
+
+# Like in several other places in variable expressions, when
+# ApplyModifier_Defined calls Var_Parse, double dollars lead to a parse
+# error that is silently ignored.  This makes all dollar signs disappear,
+# except for the last, which is a well-formed variable expression.
+#
+.if ${DEF:D$${DEF}} != "defined"
+.  error
+.endif
+
+# Any other text is written without any further escaping.  In contrast
+# to the :M modifier, parentheses and braces do not need to be nested.
+# Instead, the :D modifier is implemented sanely by parsing nested
+# expressions as such, without trying any shortcuts. See ApplyModifier_Match
+# for an inferior variant.
+#
+.if ${DEF:D!&} != "!&"
+.  error
+.endif
+
+# TODO: Add more tests for parsing the plain text part, to cover each branch
+# of ApplyModifier_Defined.
+
 all:
 	@:;
Index: src/usr.bin/make/unit-tests/varmod-undefined.mk
diff -u src/usr.bin/make/unit-tests/varmod-undefined.mk:1.3 src/usr.bin/make/unit-tests/varmod-undefined.mk:1.4
--- src/usr.bin/make/unit-tests/varmod-undefined.mk:1.3	Sun Aug 23 20:49:33 2020
+++ src/usr.bin/make/unit-tests/varmod-undefined.mk	Thu Sep  3 18:52:36 2020
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-undefined.mk,v 1.3 2020/08/23 20:49:33 rillig Exp $
+# $NetBSD: varmod-undefined.mk,v 1.4 2020/09/03 18:52:36 rillig Exp $
 #
 # Tests for the :U variable modifier, which returns the given string
 # if the variable is undefined.
@@ -46,10 +46,20 @@
 # the .newline variable is for.
 #
 # Whitespace at the edges is preserved, on both sides of the comparison.
-
+#
 .if ${:U \: \} \$ \\ \a \b \n } != " : } \$ \\ \\a \\b \\n "
 .error
 .endif
 
+# Even after the :U modifier has been applied, the expression still remembers
+# that it originated from an undefined variable, and the :U modifier can
+# be used to overwrite the value of the expression.
+#
+.if ${UNDEF:Uvalue:S,a,X,} != "vXlue"
+.  error
+.elif ${UNDEF:Uvalue:S,a,X,:Uwas undefined} != "was undefined"
+.  error
+.endif
+
 all:
 	@:;



CVS commit: src/usr.bin/make

2020-09-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Sep  3 18:53:46 UTC 2020

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

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


To generate a diff of this commit:
cvs rdiff -u -r1.485 -r1.486 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.485 src/usr.bin/make/var.c:1.486
--- src/usr.bin/make/var.c:1.485	Thu Sep  3 18:19:15 2020
+++ src/usr.bin/make/var.c	Thu Sep  3 18:53:46 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.485 2020/09/03 18:19:15 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.486 2020/09/03 18:53:46 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.485 2020/09/03 18:19:15 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.486 2020/09/03 18:53:46 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)var.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: var.c,v 1.485 2020/09/03 18:19:15 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.486 2020/09/03 18:53:46 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -2029,14 +2029,12 @@ ApplyModifier_Defined(const char **pp, A
 
 	/* Nested variable expression */
 	if (*p == '$') {
-	const char *cp2;
-	int len;
-	void *freeIt;
+	const char *nested_val;
+	void *nested_val_freeIt;
 
-	cp2 = Var_Parse(p, st->ctxt, eflags, , );
-	Buf_AddStr(, cp2);
-	free(freeIt);
-	p += len;
+	nested_val = Var_ParsePP(, st->ctxt, eflags, _val_freeIt);
+	Buf_AddStr(, nested_val);
+	free(nested_val_freeIt);
 	continue;
 	}
 



CVS commit: src/usr.bin/make

2020-09-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Sep  3 16:02:03 UTC 2020

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

Log Message:
make(1): make parameter of Cond_Eval and Cond_EvalExpression const


To generate a diff of this commit:
cvs rdiff -u -r1.106 -r1.107 src/usr.bin/make/cond.c
cvs rdiff -u -r1.102 -r1.103 src/usr.bin/make/nonints.h

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.106 src/usr.bin/make/cond.c:1.107
--- src/usr.bin/make/cond.c:1.106	Sat Aug 29 13:38:48 2020
+++ src/usr.bin/make/cond.c	Thu Sep  3 16:02:02 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.106 2020/08/29 13:38:48 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.107 2020/09/03 16:02:02 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.106 2020/08/29 13:38:48 rillig Exp $";
+static char rcsid[] = "$NetBSD: cond.c,v 1.107 2020/09/03 16:02:02 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)cond.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: cond.c,v 1.106 2020/08/29 13:38:48 rillig Exp $");
+__RCSID("$NetBSD: cond.c,v 1.107 2020/09/03 16:02:02 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1043,7 +1043,7 @@ do_Cond_EvalExpression(Boolean *value)
  *---
  */
 CondEvalResult
-Cond_EvalExpression(const struct If *info, char *line, Boolean *value,
+Cond_EvalExpression(const struct If *info, const char *line, Boolean *value,
 		int eprint, Boolean strictLHS)
 {
 static const struct If *dflt_info;
@@ -1108,7 +1108,7 @@ Cond_EvalExpression(const struct If *inf
  *---
  */
 CondEvalResult
-Cond_Eval(char *line)
+Cond_Eval(const char *line)
 {
 enum { MAXIF = 128 };	/* maximum depth of .if'ing */
 enum { MAXIF_BUMP = 32 };	/* how much to grow by */

Index: src/usr.bin/make/nonints.h
diff -u src/usr.bin/make/nonints.h:1.102 src/usr.bin/make/nonints.h:1.103
--- src/usr.bin/make/nonints.h:1.102	Sun Aug 30 19:56:02 2020
+++ src/usr.bin/make/nonints.h	Thu Sep  3 16:02:02 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nonints.h,v 1.102 2020/08/30 19:56:02 rillig Exp $	*/
+/*	$NetBSD: nonints.h,v 1.103 2020/09/03 16:02:02 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -91,8 +91,9 @@ int Compat_Make(void *, void *);
 
 /* cond.c */
 struct If;
-CondEvalResult Cond_EvalExpression(const struct If *, char *, Boolean *, int, Boolean);
-CondEvalResult Cond_Eval(char *);
+CondEvalResult Cond_EvalExpression(const struct If *, const char *,
+   Boolean *, int, Boolean);
+CondEvalResult Cond_Eval(const char *);
 void Cond_restore_depth(unsigned int);
 unsigned int Cond_save_depth(void);
 



CVS commit: src/usr.bin/make/unit-tests

2020-09-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Sep  3 17:13:42 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: cond-func-empty.mk

Log Message:
make(1): add test for the empty function in conditionals


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/cond-func-empty.mk

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/unit-tests/cond-func-empty.mk
diff -u src/usr.bin/make/unit-tests/cond-func-empty.mk:1.2 src/usr.bin/make/unit-tests/cond-func-empty.mk:1.3
--- src/usr.bin/make/unit-tests/cond-func-empty.mk:1.2	Sun Aug 16 14:25:16 2020
+++ src/usr.bin/make/unit-tests/cond-func-empty.mk	Thu Sep  3 17:13:42 2020
@@ -1,8 +1,122 @@
-# $NetBSD: cond-func-empty.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: cond-func-empty.mk,v 1.3 2020/09/03 17:13:42 rillig Exp $
 #
-# Tests for the empty() function in .if conditions.
+# Tests for the empty() function in .if conditions, which tests a variable
+# expression for emptiness.
+#
+# Note that the argument in the parentheses is indeed a variable name,
+# optionally followed by variable modifiers.  This is like the defined()
+# function.
+#
+
+.undef UNDEF
+EMPTY=	# empty
+SPACE=	${:U }
+WORD=	word
+
+# An undefined variable is empty.
+.if !empty(UNDEF)
+.  error
+.endif
+
+# An undefined variable has the empty string as the value, and the :M
+# variable modifier does not change that.
+#
+.if !empty(UNDEF:M*)
+.  error
+.endif
+
+# The :S modifier replaces the empty value with an actual word, and
+# after that the expression is no longer empty.  Because the variable
+# was undefined in the first place, the expression has the flag VAR_JUNK
+# but not VAR_KEEP, therefore it is still considered undefined.
+#
+# XXX: This is hard to explain to someone who doesn't know these
+# implementation details.
+#
+.if !empty(UNDEF:S,^$,value,W)
+.  error
+.endif
+
+# The :U modifier modifies expressions based on undefined variables
+# (VAR_JUNK) by adding the VAR_KEEP flag, which marks the expression
+# as "being interesting enough to be further processed".
+#
+.if empty(UNDEF:S,^$,value,W:Ufallback)
+.  error
+.endif
+
+# And now to the surprising part.  Applying the following :S modifier to the
+# undefined variable makes it non-empty, but the marker VAR_JUNK is preserved
+# nevertheless.  The :U modifier that follows only looks at VAR_JUNK to decide
+# whether the variable is defined or not.  This kind of makes sense since the
+# :U modifier tests the _variable_, not the _expression_.
+#
+# But since the variable was undefined to begin with, the fallback value is
+# used in this expression.
+#
+.if ${UNDEF:S,^$,value,W:Ufallback} != "fallback"
+.  error
+.endif
+
+# The variable EMPTY is completely empty (0 characters).
+.if !empty(EMPTY)
+.  error
+.endif
+
+# The variable SPACE has a single space, which counts as being empty.
+.if !empty(SPACE)
+.  error
+.endif
+
+# The variable .newline has a single newline, which counts as being empty.
+.if !empty(.newline)
+.  error
+.endif
+
+# The empty variable named "" gets a fallback value of " ", which counts as
+# empty.
+#
+# Contrary to the other functions in conditionals, the trailing space is not
+# stripped off, as can be seen in the -dv debug log.  If the space had been
+# stripped, it wouldn't make a difference in this case.
+#
+.if !empty(:U )
+.  error
+.endif
+
+# Now the variable named " " gets a non-empty value, which demonstrates that
+# neither leading nor trailing spaces are trimmed in the argument of the
+# function.  If the spaces were trimmed, the variable name would be "" and
+# that variable is indeed undefined.  Since get_mpt_arg calls Var_Parse
+# without VARE_UNDEFERR, the value of the undefined variable is returned as
+# an empty string.
+${:U }=	space
+.if empty( )
+.  error
+.endif
+
+# The value of the following expression is " word", which is not empty.
+.if empty(:U word)
+.  error
+.endif
+
+# The :L modifier creates a variable expression that has the same value as
+# its name, which both are "VAR" in this case.  The value is therefore not
+# empty.
+.if empty(VAR:L)
+.  error
+.endif
+
+# The variable WORD has the value "word", which does not count as empty.
+.if empty(WORD)
+.  error
+.endif
 
-# TODO: Implementation
+# The expression ${} for a variable with the empty name always evaluates
+# to an empty string (see Var_Parse, varNoError).
+.if !empty()
+.  error
+.endif
 
 all:
 	@:;



CVS commit: src/usr.bin/make

2020-09-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Sep  3 16:14:58 UTC 2020

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

Log Message:
make(1): update documentation for Cond_EvalExpression and Cond_Eval


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 src/usr.bin/make/cond.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.107 src/usr.bin/make/cond.c:1.108
--- src/usr.bin/make/cond.c:1.107	Thu Sep  3 16:02:02 2020
+++ src/usr.bin/make/cond.c	Thu Sep  3 16:14:58 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.107 2020/09/03 16:02:02 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.108 2020/09/03 16:14:58 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.107 2020/09/03 16:02:02 rillig Exp $";
+static char rcsid[] = "$NetBSD: cond.c,v 1.108 2020/09/03 16:14:58 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)cond.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: cond.c,v 1.107 2020/09/03 16:02:02 rillig Exp $");
+__RCSID("$NetBSD: cond.c,v 1.108 2020/09/03 16:14:58 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1025,22 +1025,15 @@ do_Cond_EvalExpression(Boolean *value)
 return COND_INVALID;
 }
 
-/*-
- *---
- * Cond_EvalExpression --
- *	Evaluate an expression in the passed line. The expression
- *	consists of &&, ||, !, make(target), defined(variable)
- *	and parenthetical groupings thereof.
+/* Evaluate the condition in the passed line, including any side effects from
+ * the variable expressions in the condition. The condition consists of &&,
+ * ||, !, function(arg), comparisons and parenthetical groupings thereof.
  *
  * Results:
  *	COND_PARSE	if the condition was valid grammatically
  *	COND_INVALID  	if not a valid conditional.
  *
  *	(*value) is set to the boolean value of the condition
- *
- * Side Effects:
- *	Any effects from evaluating the variables.
- *---
  */
 CondEvalResult
 Cond_EvalExpression(const struct If *info, const char *line, Boolean *value,
@@ -1083,29 +1076,26 @@ Cond_EvalExpression(const struct If *inf
 }
 
 
-/*-
- *---
- * Cond_Eval --
- *	Evaluate the conditional in the passed line. The line
- *	looks like this:
- *	. 
- *	where  is any of if, ifmake, ifnmake, ifdef,
- *	ifndef, elif, elifmake, elifnmake, elifdef, elifndef
- *	and  consists of &&, ||, !, make(target), defined(variable)
- *	and parenthetical groupings thereof.
- *
- * Input:
- *	line		Line to parse
- *
- * Results:
- *	COND_PARSE	if should parse lines after the conditional
- *	COND_SKIP	if should skip lines after the conditional
- *	COND_INVALID  	if not a valid conditional.
+/* Evaluate the conditional in the passed line. The line looks like this:
+ *	. 
+ * In this line,  is any of if, ifmake, ifnmake, ifdef, ifndef,
+ * elif, elifmake, elifnmake, elifdef, elifndef.
+ * In this line,  consists of &&, ||, !, function(arg), comparisons
+ * and parenthetical groupings thereof.
  *
  * Note that the states IF_ACTIVE and ELSE_ACTIVE are only different in order
  * to detect spurious .else lines (as are SKIP_TO_ELSE and SKIP_TO_ENDIF),
  * otherwise .else could be treated as '.elif 1'.
- *---
+ *
+ * Results:
+ *	COND_PARSE	to continue parsing the lines after the conditional
+ *			(when .if or .else returns TRUE)
+ *	COND_SKIP	to skip the lines after the conditional
+ *			(when .if or .elif returns FALSE, or when a previous
+ *			branch has already been taken)
+ *	COND_INVALID  	if the conditional was not valid, either because of
+ *			a syntax error or because some variable was undefined
+ *			or because the condition could not be evaluated
  */
 CondEvalResult
 Cond_Eval(const char *line)



CVS commit: src/usr.bin/make/unit-tests

2020-09-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Sep  3 19:50:15 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: dep-var.exp dep-var.mk

Log Message:
make(1): add test for expansion of indirect variables in dependencies


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/dep-var.exp \
src/usr.bin/make/unit-tests/dep-var.mk

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/unit-tests/dep-var.exp
diff -u src/usr.bin/make/unit-tests/dep-var.exp:1.2 src/usr.bin/make/unit-tests/dep-var.exp:1.3
--- src/usr.bin/make/unit-tests/dep-var.exp:1.2	Thu Sep  3 19:10:56 2020
+++ src/usr.bin/make/unit-tests/dep-var.exp	Thu Sep  3 19:50:14 2020
@@ -1,3 +1,4 @@
 def2
 a-def2-b
+1-2-NDIRECT_2-2-1
 exit status 0
Index: src/usr.bin/make/unit-tests/dep-var.mk
diff -u src/usr.bin/make/unit-tests/dep-var.mk:1.2 src/usr.bin/make/unit-tests/dep-var.mk:1.3
--- src/usr.bin/make/unit-tests/dep-var.mk:1.2	Thu Sep  3 19:10:56 2020
+++ src/usr.bin/make/unit-tests/dep-var.mk	Thu Sep  3 19:50:14 2020
@@ -1,4 +1,4 @@
-# $NetBSD: dep-var.mk,v 1.2 2020/09/03 19:10:56 rillig Exp $
+# $NetBSD: dep-var.mk,v 1.3 2020/09/03 19:50:14 rillig Exp $
 #
 # Tests for variable references in dependency declarations.
 #
@@ -26,8 +26,40 @@ all: $${DEF2} a-$${DEF2}-b
 # The variable expression ${UNDEF3} simply expands to an empty string.
 all: $${UNDEF3}
 
+# Try out how many levels of indirection are really expanded in dependency
+# lines.
+#
+# The first level of indirection is the $$ in the dependency line.
+# When the dependency line is parsed, it is resolved to the string
+# "${INDIRECT_1}".  At this point, the dollar is just an ordinary character,
+# waiting to be expanded at some later point.
+#
+# Later, in SuffExpandChildren, that expression is expanded again by calling
+# Var_Parse, and this time, the result is the string "1-2-${INDIRECT_2}-2-1".
+#
+# This string is not expanded anymore by Var_Parse.  But there is another
+# effect.  Now DirExpandCurly comes into play and expands the curly braces
+# in this filename pattern, resulting in the string "1-2-$INDIRECT_2-2-1".
+# As of 2020-09-03, the test dir.mk contains further details on this topic.
+#
+# Finally, this string is assigned to the local ${.TARGET} variable.  This
+# variable is expanded when the shell command is generated.  At that point,
+# the $I is expanded.  Since the variable I is not defined, it expands to
+# the empty string.  This way, the final output is the string
+# "1-2-NDIRECT_2-2-1", which differs from the actual name of the target.
+# For exactly this reason, it is not recommended to use dollar signs in
+# target names.
+#
+# The number of actual expansions is way more than one might expect,
+# therefore this feature is probably not widely used.
+#
+all: 1-$${INDIRECT_1}-1
+INDIRECT_1=	2-$${INDIRECT_2}-2
+INDIRECT_2=	3-$${INDIRECT_3}-3
+INDIRECT_3=	indirect
+
 UNDEF1=	undef1
 DEF2=	def2
 
-undef1 def2 a-def2-b:
-	@echo ${.TARGET}
+undef1 def2 a-def2-b 1-2-$$INDIRECT_2-2-1:
+	@echo ${.TARGET:Q}



CVS commit: src/usr.bin/make

2020-09-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Sep  3 18:19:15 UTC 2020

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

Log Message:
make(1): migrate Var_Parse API to parsing position

The ApplyModifier functions already use this pattern.  For simplicity
and consistency Var_Parse should do the same.  This saves a parameter to
be passed.

The migration takes place step by step, just like for the Lst functions
a few days ago.


To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 src/usr.bin/make/nonints.h
cvs rdiff -u -r1.484 -r1.485 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/nonints.h
diff -u src/usr.bin/make/nonints.h:1.103 src/usr.bin/make/nonints.h:1.104
--- src/usr.bin/make/nonints.h:1.103	Thu Sep  3 16:02:02 2020
+++ src/usr.bin/make/nonints.h	Thu Sep  3 18:19:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nonints.h,v 1.103 2020/09/03 16:02:02 rillig Exp $	*/
+/*	$NetBSD: nonints.h,v 1.104 2020/09/03 18:19:15 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -214,6 +214,7 @@ void Var_Append(const char *, const char
 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);
 void Var_End(void);

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.484 src/usr.bin/make/var.c:1.485
--- src/usr.bin/make/var.c:1.484	Wed Sep  2 06:25:48 2020
+++ src/usr.bin/make/var.c	Thu Sep  3 18:19:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.484 2020/09/02 06:25:48 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.485 2020/09/03 18:19:15 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.484 2020/09/02 06:25:48 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.485 2020/09/03 18:19:15 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)var.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: var.c,v 1.484 2020/09/02 06:25:48 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.485 2020/09/03 18:19:15 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1679,15 +1679,16 @@ ParseModifierPart(
 	}
 
 	if (eflags & VARE_WANTRES) {	/* Nested variable, evaluated */
-	const char *cp2;
-	int len;
-	void *freeIt;
+	const char *nested_p = p;
+	const char *nested_val;
+	void *nested_val_freeIt;
 	VarEvalFlags nested_eflags = eflags & ~(unsigned)VARE_ASSIGN;
 
-	cp2 = Var_Parse(p, ctxt, nested_eflags, , );
-	Buf_AddStr(, cp2);
-	free(freeIt);
-	p += len;
+	nested_val = Var_ParsePP(_p, ctxt, nested_eflags,
+ _val_freeIt);
+	Buf_AddStr(, nested_val);
+	free(nested_val_freeIt);
+	p += nested_p - p;
 	continue;
 	}
 
@@ -3624,6 +3625,15 @@ Var_Parse(const char * const str, GNode 
 return nstr;
 }
 
+const char *
+Var_ParsePP(const char **pp, GNode *ctxt, VarEvalFlags eflags, void **freePtr)
+{
+int len;
+const char *val = Var_Parse(*pp, ctxt, eflags, , freePtr);
+*pp += len;
+return val;
+}
+
 /* Substitute for all variables in the given string in the given context.
  *
  * If eflags & VARE_UNDEFERR, Parse_Error will be called when an undefined



CVS commit: src/usr.bin/make/unit-tests

2020-09-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Sep  3 19:10:56 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: dep-var.exp dep-var.mk

Log Message:
make: extend test for unresolved variables in dependencies

This is to ensure that the upcoming refactoring of Var_Parse in
SuffExpandChildren does not break anything.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/dep-var.exp \
src/usr.bin/make/unit-tests/dep-var.mk

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/unit-tests/dep-var.exp
diff -u src/usr.bin/make/unit-tests/dep-var.exp:1.1 src/usr.bin/make/unit-tests/dep-var.exp:1.2
--- src/usr.bin/make/unit-tests/dep-var.exp:1.1	Sat Aug 22 16:51:26 2020
+++ src/usr.bin/make/unit-tests/dep-var.exp	Thu Sep  3 19:10:56 2020
@@ -1,2 +1,3 @@
 def2
+a-def2-b
 exit status 0
Index: src/usr.bin/make/unit-tests/dep-var.mk
diff -u src/usr.bin/make/unit-tests/dep-var.mk:1.1 src/usr.bin/make/unit-tests/dep-var.mk:1.2
--- src/usr.bin/make/unit-tests/dep-var.mk:1.1	Sat Aug 22 16:51:26 2020
+++ src/usr.bin/make/unit-tests/dep-var.mk	Thu Sep  3 19:10:56 2020
@@ -1,4 +1,4 @@
-# $NetBSD: dep-var.mk,v 1.1 2020/08/22 16:51:26 rillig Exp $
+# $NetBSD: dep-var.mk,v 1.2 2020/09/03 19:10:56 rillig Exp $
 #
 # Tests for variable references in dependency declarations.
 #
@@ -17,7 +17,7 @@ all: ${UNDEF1}
 #
 # At the point where the expression ${DEF2} is expanded, the variable DEF2
 # is defined, so everything's fine.
-all: $${DEF2}
+all: $${DEF2} a-$${DEF2}-b
 
 # This variable is not defined at all.
 # XXX: The -dv log says:
@@ -29,5 +29,5 @@ all: $${UNDEF3}
 UNDEF1=	undef1
 DEF2=	def2
 
-undef1 def2:
+undef1 def2 a-def2-b:
 	@echo ${.TARGET}



CVS commit: src/usr.bin/make/unit-tests

2020-09-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Sep  6 04:35:03 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: opt-debug-errors.exp opt-debug-errors.mk

Log Message:
make(1): add test for the -de option


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/opt-debug-errors.exp \
src/usr.bin/make/unit-tests/opt-debug-errors.mk

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/unit-tests/opt-debug-errors.exp
diff -u src/usr.bin/make/unit-tests/opt-debug-errors.exp:1.1 src/usr.bin/make/unit-tests/opt-debug-errors.exp:1.2
--- src/usr.bin/make/unit-tests/opt-debug-errors.exp:1.1	Sat Sep  5 06:20:51 2020
+++ src/usr.bin/make/unit-tests/opt-debug-errors.exp	Sun Sep  6 04:35:03 2020
@@ -1 +1,34 @@
+echo '3   spaces'; false
+3   spaces
+
+*** Failed target:  fail-spaces
+*** Failed command: echo '3 spaces'; false
+*** Error code 1 (continuing)
+echo \  indented; false
+  indented
+
+*** Failed target:  fail-escaped-space
+*** Failed command: echo \ indented; false
+*** Error code 1 (continuing)
+echo 'line1
+line2'; false
+line1
+line2
+
+*** Failed target:  fail-newline
+*** Failed command: echo 'line1 line2'; false
+*** Error code 1 (continuing)
+echo 'line1 line2'; false
+line1 line2
+
+*** Failed target:  fail-multiline
+*** Failed command: echo 'line1 line2'; false
+*** Error code 1 (continuing)
+echo	'word1'			 'word2'; false
+word1 word2
+
+*** Failed target:  fail-multiline-intention
+*** Failed command: echo 'word1' 'word2'; false
+*** Error code 1 (continuing)
+`all' not remade because of errors.
 exit status 0
Index: src/usr.bin/make/unit-tests/opt-debug-errors.mk
diff -u src/usr.bin/make/unit-tests/opt-debug-errors.mk:1.1 src/usr.bin/make/unit-tests/opt-debug-errors.mk:1.2
--- src/usr.bin/make/unit-tests/opt-debug-errors.mk:1.1	Sat Sep  5 06:20:51 2020
+++ src/usr.bin/make/unit-tests/opt-debug-errors.mk	Sun Sep  6 04:35:03 2020
@@ -1,9 +1,42 @@
-# $NetBSD: opt-debug-errors.mk,v 1.1 2020/09/05 06:20:51 rillig Exp $
+# $NetBSD: opt-debug-errors.mk,v 1.2 2020/09/06 04:35:03 rillig Exp $
 #
 # Tests for the -de command line option, which adds debug logging for
 # failed commands and targets.
 
-# TODO: Implementation
+.MAKEFLAGS: -de
 
-all:
-	@:;
+all: fail-spaces
+all: fail-escaped-space
+all: fail-newline
+all: fail-multiline
+all: fail-multiline-intention
+
+# XXX: The debug output folds the spaces, showing '3 spaces' instead of
+# the correct '3   spaces'.
+fail-spaces:
+	echo '3   spaces'; false
+
+# XXX: The debug output folds the spaces, showing 'echo \ indented' instead
+# of the correct 'echo \  indented'.
+fail-escaped-space:
+	echo \  indented; false
+
+# XXX: A newline is turned into an ordinary space in the debug log.
+fail-newline:
+	echo 'line1${.newline}line2'; false
+
+# The line continuations in multiline commands are turned into an ordinary
+# space before the command is actually run.
+fail-multiline:
+	echo 'line1\
+		line2'; false
+
+# It is a common style to align the continuation backslashes at the right
+# of the lines, usually at column 73.  All spaces before the continuation
+# backslash are preserved and are usually outside a shell word and thus
+# irrelevant.  Having these spaces collapsed makes sense to show the command
+# in its condensed form.
+#
+fail-multiline-intention:
+	echo	'word1'			\
+		'word2'; false



CVS commit: src/usr.bin/make

2020-09-06 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Sep  7 05:32:12 UTC 2020

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

Log Message:
make(1): clean up comments in job.c


To generate a diff of this commit:
cvs rdiff -u -r1.227 -r1.228 src/usr.bin/make/job.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/job.c
diff -u src/usr.bin/make/job.c:1.227 src/usr.bin/make/job.c:1.228
--- src/usr.bin/make/job.c:1.227	Sun Aug 30 19:56:02 2020
+++ src/usr.bin/make/job.c	Mon Sep  7 05:32:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.227 2020/08/30 19:56:02 rillig Exp $	*/
+/*	$NetBSD: job.c,v 1.228 2020/09/07 05:32:12 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: job.c,v 1.227 2020/08/30 19:56:02 rillig Exp $";
+static char rcsid[] = "$NetBSD: job.c,v 1.228 2020/09/07 05:32:12 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)job.c	8.2 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: job.c,v 1.227 2020/08/30 19:56:02 rillig Exp $");
+__RCSID("$NetBSD: job.c,v 1.228 2020/09/07 05:32:12 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1255,7 +1255,7 @@ Job_CheckCommands(GNode *gn, void (*abor
 	bmake_free(p1);
 	} else if (Dir_MTime(gn, 0) == 0 && (gn->type & OP_SPECIAL) == 0) {
 	/*
-	 * The node wasn't the target of an operator we have no .DEFAULT
+	 * The node wasn't the target of an operator.  We have no .DEFAULT
 	 * rule to go on and the target doesn't already exist. There's
 	 * nothing more we can do for this branch. If the -k flag wasn't
 	 * given, we stop in our tracks, otherwise we just don't update
@@ -1289,22 +1289,10 @@ Job_CheckCommands(GNode *gn, void (*abor
 return TRUE;
 }
 
-/*-
- *---
- * JobExec --
- *	Execute the shell for the given job. Called from JobStart
- *
- * Input:
- *	job		Job to execute
- *
- * Results:
- *	None.
+/* Execute the shell for the given job. Called from JobStart
  *
- * Side Effects:
- *	A shell is executed, outputs is altered and the Job structure added
- *	to the job table.
- *
- *---
+ * A shell is executed, its output is altered and the Job structure added
+ * to the job table.
  */
 static void
 JobExec(Job *job, char **argv)
@@ -1476,18 +1464,7 @@ JobExec(Job *job, char **argv)
 JobSigUnlock();
 }
 
-/*-
- *---
- * JobMakeArgv --
- *	Create the argv needed to execute the shell for a given job.
- *
- *
- * Results:
- *
- * Side Effects:
- *
- *---
- */
+/* Create the argv needed to execute the shell for a given job. */
 static void
 JobMakeArgv(Job *job, char **argv)
 {



CVS commit: src/usr.bin/make

2020-09-06 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Sep  7 05:58:08 UTC 2020

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

Log Message:
make(1): add local variable for escapes to for_substitute

Just for debugging.  No change in code size.


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/usr.bin/make/for.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/for.c
diff -u src/usr.bin/make/for.c:1.73 src/usr.bin/make/for.c:1.74
--- src/usr.bin/make/for.c:1.73	Sun Sep  6 19:30:53 2020
+++ src/usr.bin/make/for.c	Mon Sep  7 05:58:08 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: for.c,v 1.73 2020/09/06 19:30:53 rillig Exp $	*/
+/*	$NetBSD: for.c,v 1.74 2020/09/07 05:58:08 rillig Exp $	*/
 
 /*
  * Copyright (c) 1992, The Regents of the University of California.
@@ -30,14 +30,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: for.c,v 1.73 2020/09/06 19:30:53 rillig Exp $";
+static char rcsid[] = "$NetBSD: for.c,v 1.74 2020/09/07 05:58:08 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)for.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: for.c,v 1.73 2020/09/06 19:30:53 rillig Exp $");
+__RCSID("$NetBSD: for.c,v 1.74 2020/09/07 05:58:08 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -333,19 +333,20 @@ for_var_len(const char *var)
 static void
 for_substitute(Buffer *cmds, strlist_t *items, unsigned int item_no, char ech)
 {
-char ch;
-
 const char *item = strlist_str(items, item_no);
+unsigned int escapes = strlist_info(items, item_no);
+char ch;
 
 /* If there were no escapes, or the only escape is the other variable
  * terminator, then just substitute the full string */
-if (!(strlist_info(items, item_no) &
+if (!(escapes &
 	  (ech == ')' ? ~FOR_SUB_ESCAPE_BRACE : ~FOR_SUB_ESCAPE_PAREN))) {
 	Buf_AddStr(cmds, item);
 	return;
 }
 
-/* Escape ':', '$', '\\' and 'ech' - removed by :U processing */
+/* Escape ':', '$', '\\' and 'ech' - these will be removed later by
+ * :U processing, see ApplyModifier_Defined. */
 while ((ch = *item++) != 0) {
 	if (ch == '$') {
 	size_t len = for_var_len(item);
@@ -390,7 +391,7 @@ ForIterate(void *v_arg, size_t *ret_len)
  * syntax, and that the later parsing will still see a variable.
  * We assume that the null variable will never be defined.
  *
- * The detection of substitions of the loop control variable is naive.
+ * The detection of substitutions of the loop control variable is naive.
  * Many of the modifiers use \ to escape $ (not $) so it is possible
  * to contrive a makefile where an unwanted substitution happens.
  */



CVS commit: src/usr.bin/make

2020-09-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Sep  7 06:20:07 UTC 2020

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

Log Message:
make(1): remove redundant includes


To generate a diff of this commit:
cvs rdiff -u -r1.133 -r1.134 src/usr.bin/make/make.c
cvs rdiff -u -r1.487 -r1.488 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/make.c
diff -u src/usr.bin/make/make.c:1.133 src/usr.bin/make/make.c:1.134
--- src/usr.bin/make/make.c:1.133	Sun Aug 30 14:11:42 2020
+++ src/usr.bin/make/make.c	Mon Sep  7 06:20:07 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.c,v 1.133 2020/08/30 14:11:42 rillig Exp $	*/
+/*	$NetBSD: make.c,v 1.134 2020/09/07 06:20:07 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: make.c,v 1.133 2020/08/30 14:11:42 rillig Exp $";
+static char rcsid[] = "$NetBSD: make.c,v 1.134 2020/09/07 06:20:07 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)make.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: make.c,v 1.133 2020/08/30 14:11:42 rillig Exp $");
+__RCSID("$NetBSD: make.c,v 1.134 2020/09/07 06:20:07 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -116,7 +116,6 @@ __RCSID("$NetBSD: make.c,v 1.133 2020/08
  */
 
 #include"make.h"
-#include"enum.h"
 #include"dir.h"
 #include"job.h"
 

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.487 src/usr.bin/make/var.c:1.488
--- src/usr.bin/make/var.c:1.487	Fri Sep  4 20:28:15 2020
+++ src/usr.bin/make/var.c	Mon Sep  7 06:20:07 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.487 2020/09/04 20:28:15 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.488 2020/09/07 06:20:07 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.487 2020/09/04 20:28:15 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.488 2020/09/07 06:20:07 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)var.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: var.c,v 1.487 2020/09/04 20:28:15 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.488 2020/09/07 06:20:07 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -129,7 +129,6 @@ __RCSID("$NetBSD: var.c,v 1.487 2020/09/
 #include
 
 #include"make.h"
-#include"enum.h"
 #include"dir.h"
 #include"job.h"
 #include"metachar.h"



CVS commit: src/usr.bin/make

2020-09-06 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Sep  6 19:19:49 UTC 2020

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

Log Message:
make(1): improve documentation in For_Eval


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/usr.bin/make/for.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/for.c
diff -u src/usr.bin/make/for.c:1.69 src/usr.bin/make/for.c:1.70
--- src/usr.bin/make/for.c:1.69	Sun Sep  6 19:18:16 2020
+++ src/usr.bin/make/for.c	Sun Sep  6 19:19:49 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: for.c,v 1.69 2020/09/06 19:18:16 rillig Exp $	*/
+/*	$NetBSD: for.c,v 1.70 2020/09/06 19:19:49 rillig Exp $	*/
 
 /*
  * Copyright (c) 1992, The Regents of the University of California.
@@ -30,14 +30,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: for.c,v 1.69 2020/09/06 19:18:16 rillig Exp $";
+static char rcsid[] = "$NetBSD: for.c,v 1.70 2020/09/06 19:19:49 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)for.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: for.c,v 1.69 2020/09/06 19:18:16 rillig Exp $");
+__RCSID("$NetBSD: for.c,v 1.70 2020/09/06 19:19:49 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -108,12 +108,8 @@ For_Free(For *arg)
 free(arg);
 }
 
-/*-
- *---
- * For_Eval --
- *	Evaluate the for loop in the passed line. The line
- *	looks like this:
- *	.for  in 
+/* Evaluate the for loop in the passed line. The line looks like this:
+ *	.for  in 
  *
  * Input:
  *	line		Line to parse
@@ -122,11 +118,6 @@ For_Free(For *arg)
  *  0: Not a .for statement, parse the line
  *	1: We found a for loop
  * -1: A .for statement with a bad syntax error, discard.
- *
- * Side Effects:
- *	None.
- *
- *---
  */
 int
 For_Eval(char *line)
@@ -194,12 +185,12 @@ For_Eval(char *line)
 	ptr++;
 
 /*
- * Make a list with the remaining words
- * The values are substituted as ${:U...} so we must \ escape
- * characters that break that syntax.
+ * Make a list with the remaining words.
+ * The values are later substituted as ${:U...} so we must
+ * backslash-escape characters that break that syntax.
  * Variables are fully expanded - so it is safe for escape $.
  * We can't do the escapes here - because we don't know whether
- * we are substuting into ${...} or $(...).
+ * we will be substituting into ${...} or $(...).
  */
 sub = Var_Subst(ptr, VAR_GLOBAL, VARE_WANTRES);
 



CVS commit: src/usr.bin/make

2020-09-06 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Sep  6 19:18:16 UTC 2020

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

Log Message:
make(1): fix type of For.short_var


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/usr.bin/make/for.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/for.c
diff -u src/usr.bin/make/for.c:1.68 src/usr.bin/make/for.c:1.69
--- src/usr.bin/make/for.c:1.68	Fri Sep  4 17:35:00 2020
+++ src/usr.bin/make/for.c	Sun Sep  6 19:18:16 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: for.c,v 1.68 2020/09/04 17:35:00 rillig Exp $	*/
+/*	$NetBSD: for.c,v 1.69 2020/09/06 19:18:16 rillig Exp $	*/
 
 /*
  * Copyright (c) 1992, The Regents of the University of California.
@@ -30,14 +30,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: for.c,v 1.68 2020/09/04 17:35:00 rillig Exp $";
+static char rcsid[] = "$NetBSD: for.c,v 1.69 2020/09/06 19:18:16 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)for.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: for.c,v 1.68 2020/09/04 17:35:00 rillig Exp $");
+__RCSID("$NetBSD: for.c,v 1.69 2020/09/06 19:18:16 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -87,7 +87,10 @@ typedef struct {
 strlist_t vars;		/* Iteration variables */
 strlist_t items;		/* Substitution items */
 char *parse_buf;
-int short_var;
+/* Is any of the names 1 character long? If so, when the variable values
+ * are substituted, the parser must handle $V expressions as well, not
+ * only ${V} and $(V). */
+Boolean short_var;
 int sub_next;
 } For;
 
@@ -176,7 +179,8 @@ For_Eval(char *line)
 	break;
 	}
 	if (len == 1)
-	new_for->short_var = 1;
+	new_for->short_var = TRUE;
+
 	strlist_add_str(_for->vars, bmake_strldup(ptr, len), len);
 }
 



CVS commit: src/usr.bin/make

2020-09-06 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Sep  6 19:34:36 UTC 2020

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

Log Message:
make(1): add const for Parse_IsVar


To generate a diff of this commit:
cvs rdiff -u -r1.105 -r1.106 src/usr.bin/make/nonints.h
cvs rdiff -u -r1.285 -r1.286 src/usr.bin/make/parse.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/nonints.h
diff -u src/usr.bin/make/nonints.h:1.105 src/usr.bin/make/nonints.h:1.106
--- src/usr.bin/make/nonints.h:1.105	Sun Sep  6 19:30:53 2020
+++ src/usr.bin/make/nonints.h	Sun Sep  6 19:34:36 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nonints.h,v 1.105 2020/09/06 19:30:53 rillig Exp $	*/
+/*	$NetBSD: nonints.h,v 1.106 2020/09/06 19:34:36 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -124,7 +124,7 @@ char *cached_realpath(const char *, char
 
 /* parse.c */
 void Parse_Error(int, const char *, ...) MAKE_ATTR_PRINTFLIKE(2, 3);
-Boolean Parse_IsVar(char *);
+Boolean Parse_IsVar(const char *);
 void Parse_DoVar(char *, GNode *);
 void Parse_AddIncludeDir(char *);
 void Parse_File(const char *, int);

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.285 src/usr.bin/make/parse.c:1.286
--- src/usr.bin/make/parse.c:1.285	Sat Sep  5 19:11:16 2020
+++ src/usr.bin/make/parse.c	Sun Sep  6 19:34:36 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.285 2020/09/05 19:11:16 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.286 2020/09/06 19:34:36 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: parse.c,v 1.285 2020/09/05 19:11:16 rillig Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.286 2020/09/06 19:34:36 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)parse.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: parse.c,v 1.285 2020/09/05 19:11:16 rillig Exp $");
+__RCSID("$NetBSD: parse.c,v 1.286 2020/09/06 19:34:36 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1751,7 +1751,7 @@ out:
  *-
  */
 Boolean
-Parse_IsVar(char *line)
+Parse_IsVar(const char *line)
 {
 Boolean wasSpace = FALSE;	/* set TRUE if found a space */
 char ch;



CVS commit: src/usr.bin/make/unit-tests

2020-09-06 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Sep  7 05:16:32 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: archive.mk

Log Message:
make(1): fix archive test when .CURDIR != .PARSEDIR


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/archive.mk

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/unit-tests/archive.mk
diff -u src/usr.bin/make/unit-tests/archive.mk:1.7 src/usr.bin/make/unit-tests/archive.mk:1.8
--- src/usr.bin/make/unit-tests/archive.mk:1.7	Sat Sep  5 06:20:51 2020
+++ src/usr.bin/make/unit-tests/archive.mk	Mon Sep  7 05:16:32 2020
@@ -1,4 +1,4 @@
-# $NetBSD: archive.mk,v 1.7 2020/09/05 06:20:51 rillig Exp $
+# $NetBSD: archive.mk,v 1.8 2020/09/07 05:16:32 rillig Exp $
 #
 # Very basic demonstration of handling archives, based on the description
 # in PSD.doc/tutorial.ms.
@@ -15,7 +15,7 @@ RUN?=		@set -eu;
 
 all:
 .if ${.PARSEDIR:tA} != ${.CURDIR:tA}
-	@cd ${MAKEFILE:H} && cp ${FILES} t*.mk ${.CURDIR}
+	@cd ${MAKEFILE:H} && cp ${FILES} [at]*.mk ${.CURDIR}
 .endif
 # The following targets are run in sub-makes to ensure that they get the
 # current state of the filesystem right, since they creating and removing



CVS commit: src/usr.bin/make

2020-09-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Sep  7 06:01:11 UTC 2020

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

Log Message:
make(1): convert ForEscapes from #define to enum


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 src/usr.bin/make/for.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/for.c
diff -u src/usr.bin/make/for.c:1.74 src/usr.bin/make/for.c:1.75
--- src/usr.bin/make/for.c:1.74	Mon Sep  7 05:58:08 2020
+++ src/usr.bin/make/for.c	Mon Sep  7 06:01:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: for.c,v 1.74 2020/09/07 05:58:08 rillig Exp $	*/
+/*	$NetBSD: for.c,v 1.75 2020/09/07 06:01:11 rillig Exp $	*/
 
 /*
  * Copyright (c) 1992, The Regents of the University of California.
@@ -30,14 +30,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: for.c,v 1.74 2020/09/07 05:58:08 rillig Exp $";
+static char rcsid[] = "$NetBSD: for.c,v 1.75 2020/09/07 06:01:11 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)for.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: for.c,v 1.74 2020/09/07 05:58:08 rillig Exp $");
+__RCSID("$NetBSD: for.c,v 1.75 2020/09/07 06:01:11 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -55,9 +55,11 @@ __RCSID("$NetBSD: for.c,v 1.74 2020/09/0
 #include"make.h"
 #include"strlist.h"
 
-#define FOR_SUB_ESCAPE_CHAR  1
-#define FOR_SUB_ESCAPE_BRACE 2
-#define FOR_SUB_ESCAPE_PAREN 4
+typedef enum {
+FOR_SUB_ESCAPE_CHAR = 0x0001,
+FOR_SUB_ESCAPE_BRACE = 0x0002,
+FOR_SUB_ESCAPE_PAREN = 0x0004
+} ForEscapes;
 
 /*
  * For statements are of the form:
@@ -208,7 +210,7 @@ For_Eval(const char *line)
 	size_t n;
 
 	for (n = 0; n < words.len; n++) {
-	int escapes;
+	ForEscapes escapes;
 	char ch;
 
 	ptr = words.words[n];
@@ -334,7 +336,7 @@ static void
 for_substitute(Buffer *cmds, strlist_t *items, unsigned int item_no, char ech)
 {
 const char *item = strlist_str(items, item_no);
-unsigned int escapes = strlist_info(items, item_no);
+ForEscapes escapes = strlist_info(items, item_no);
 char ch;
 
 /* If there were no escapes, or the only escape is the other variable



CVS commit: src

2020-09-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Sep  4 05:23:25 UTC 2020

Modified Files:
src/distrib/sets/lists/tests: mi
src/usr.bin/make/unit-tests: Makefile varmod-hash.mk
Removed Files:
src/usr.bin/make/unit-tests: hash.exp hash.mk

Log Message:
make(1): extend tests for the :hash variable modifier

The previous test vectors didn't contain any hash with a leading zero.
This could have been a simple programming mistake by using %8x instead
of the intended %08x.  Using snprintf wouldn't have been possible anyway
since the hex digits are printed in little-endian order, but without
reversing the bits of each digit.  Kind of unusual, but doesn't affect
the distribution of the hashes.


To generate a diff of this commit:
cvs rdiff -u -r1.915 -r1.916 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.130 -r1.131 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r1.1 -r0 src/usr.bin/make/unit-tests/hash.exp \
src/usr.bin/make/unit-tests/hash.mk
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/varmod-hash.mk

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

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.915 src/distrib/sets/lists/tests/mi:1.916
--- src/distrib/sets/lists/tests/mi:1.915	Wed Sep  2 05:33:57 2020
+++ src/distrib/sets/lists/tests/mi	Fri Sep  4 05:23:25 2020
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.915 2020/09/02 05:33:57 rillig Exp $
+# $NetBSD: mi,v 1.916 2020/09/04 05:23:25 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -4782,8 +4782,8 @@
 ./usr/tests/usr.bin/make/unit-tests/forloop.mk	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/forsubst.exp	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/forsubst.mk	tests-usr.bin-tests	compattestfile,atf
-./usr/tests/usr.bin/make/unit-tests/hash.exp	tests-usr.bin-tests	compattestfile,atf
-./usr/tests/usr.bin/make/unit-tests/hash.mk	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/hash.exp	tests-obsolete	obsolete
+./usr/tests/usr.bin/make/unit-tests/hash.mk	tests-obsolete	obsolete
 ./usr/tests/usr.bin/make/unit-tests/impsrc.exp	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/impsrc.mk	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/include-main.exp	tests-usr.bin-tests	compattestfile,atf

Index: src/usr.bin/make/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.130 src/usr.bin/make/unit-tests/Makefile:1.131
--- src/usr.bin/make/unit-tests/Makefile:1.130	Wed Sep  2 05:33:57 2020
+++ src/usr.bin/make/unit-tests/Makefile	Fri Sep  4 05:23:25 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.130 2020/09/02 05:33:57 rillig Exp $
+# $NetBSD: Makefile,v 1.131 2020/09/04 05:23:25 rillig Exp $
 #
 # Unit tests for make(1)
 #
@@ -157,7 +157,6 @@ TESTS+=		export-env
 TESTS+=		export-variants
 TESTS+=		forloop
 TESTS+=		forsubst
-TESTS+=		hash
 TESTS+=		impsrc
 TESTS+=		include-main
 TESTS+=		lint

Index: src/usr.bin/make/unit-tests/varmod-hash.mk
diff -u src/usr.bin/make/unit-tests/varmod-hash.mk:1.3 src/usr.bin/make/unit-tests/varmod-hash.mk:1.4
--- src/usr.bin/make/unit-tests/varmod-hash.mk:1.3	Sun Aug 23 15:13:21 2020
+++ src/usr.bin/make/unit-tests/varmod-hash.mk	Fri Sep  4 05:23:25 2020
@@ -1,6 +1,59 @@
-# $NetBSD: varmod-hash.mk,v 1.3 2020/08/23 15:13:21 rillig Exp $
+# $NetBSD: varmod-hash.mk,v 1.4 2020/09/04 05:23:25 rillig Exp $
 #
-# Tests for the :hash variable modifier.
+# Tests for the :hash variable modifier, which computes a 32-bit hash from
+# the value of the expression.
+
+# Test vectors for generating certain hashes.  Found by a brute force
+# search over [a-z]{8}.
+#
+VECTORS+=	 adjbuqnt
+VECTORS+=	0001 beiiyxdp
+VECTORS+=	0002 ajriwzqe
+VECTORS+=	0004 aimszzcb
+VECTORS+=	0008 afffvsgz
+VECTORS+=	0010 alkksbun
+VECTORS+=	0020 arqeianj
+VECTORS+=	0040 acgaltwv
+VECTORS+=	0080 addsjxec
+VECTORS+=	0100 acbozubm
+VECTORS+=	0200 acnbugtp
+VECTORS+=	0400 ajyfkpcl
+VECTORS+=	0800 akobyelz
+VECTORS+=	1000 aclmaggk
+VECTORS+=	2000 aauwlqiq
+VECTORS+=	4000 ankfvoqf
+VECTORS+=	8000 airtytts
+VECTORS+=	0001 bfwwrqfi
+VECTORS+=	0002 actwkzix
+VECTORS+=	0004 alsfbgvo
+VECTORS+=	0008 aioiauem
+VECTORS+=	0010 bxexhpji
+VECTORS+=	0020 awtxcwch
+VECTORS+=	0040 aoqpmqam
+VECTORS+=	0080 akgtvjhz
+VECTORS+=	0100 bcmsuvrm
+VECTORS+=	0200 aqnktorm
+VECTORS+=	0400 aweqylny
+VECTORS+=	0800 crvkuyze
+VECTORS+=	1000 alxiatjv
+VECTORS+=	2000 aezwuukx
+VECTORS+=	4000 abdpnifu
+VECTORS+=	8000 auusgoii
+
+VECTORS+=	b2af338b ""
+VECTORS+=	3360ac65 a
+VECTORS+=	7747f046 ab
+VECTORS+=	9ca87054 abc
+VECTORS+=	880fe816 abcd
+VECTORS+=	208fcbd3 abcde
+VECTORS+=	d5d376eb abcdef
+VECTORS+=	de41416c 

CVS commit: src/usr.bin/make/unit-tests

2020-09-04 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Sep  4 06:54:07 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: varmod-hash.mk

Log Message:
make(1): add test for :hash returning 

In the previous brute force search, it seemed there was no string with
that hash code.  That was probably an oversight or a little programming
mistake.  Anyway, it's possible to get that hash value, so keep the
example.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/varmod-hash.mk

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/unit-tests/varmod-hash.mk
diff -u src/usr.bin/make/unit-tests/varmod-hash.mk:1.4 src/usr.bin/make/unit-tests/varmod-hash.mk:1.5
--- src/usr.bin/make/unit-tests/varmod-hash.mk:1.4	Fri Sep  4 05:23:25 2020
+++ src/usr.bin/make/unit-tests/varmod-hash.mk	Fri Sep  4 06:54:07 2020
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-hash.mk,v 1.4 2020/09/04 05:23:25 rillig Exp $
+# $NetBSD: varmod-hash.mk,v 1.5 2020/09/04 06:54:07 rillig Exp $
 #
 # Tests for the :hash variable modifier, which computes a 32-bit hash from
 # the value of the expression.
@@ -39,6 +39,7 @@ VECTORS+=	1000 alxiatjv
 VECTORS+=	2000 aezwuukx
 VECTORS+=	4000 abdpnifu
 VECTORS+=	8000 auusgoii
+VECTORS+=	 ahnvmfdw
 
 VECTORS+=	b2af338b ""
 VECTORS+=	3360ac65 a



CVS commit: src/usr.bin/make

2020-09-06 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Sep  6 19:24:12 UTC 2020

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

Log Message:
make(1): properly initialize For structure in For_Eval

Initializing a Buffer or a strlist_t with zero-valued bytes only works
by conincidence, but because it would be the correct way.  In the code
path "missing `in' in for", that zero-filled Buffer is freed using
Buf_Destroy, which could have invoked undefined behavior.


To generate a diff of this commit:
cvs rdiff -u -r1.70 -r1.71 src/usr.bin/make/for.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/for.c
diff -u src/usr.bin/make/for.c:1.70 src/usr.bin/make/for.c:1.71
--- src/usr.bin/make/for.c:1.70	Sun Sep  6 19:19:49 2020
+++ src/usr.bin/make/for.c	Sun Sep  6 19:24:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: for.c,v 1.70 2020/09/06 19:19:49 rillig Exp $	*/
+/*	$NetBSD: for.c,v 1.71 2020/09/06 19:24:12 rillig Exp $	*/
 
 /*
  * Copyright (c) 1992, The Regents of the University of California.
@@ -30,14 +30,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: for.c,v 1.70 2020/09/06 19:19:49 rillig Exp $";
+static char rcsid[] = "$NetBSD: for.c,v 1.71 2020/09/06 19:24:12 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)for.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: for.c,v 1.70 2020/09/06 19:19:49 rillig Exp $");
+__RCSID("$NetBSD: for.c,v 1.71 2020/09/06 19:24:12 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -152,7 +152,12 @@ For_Eval(char *line)
  */
 
 new_for = bmake_malloc(sizeof *new_for);
-memset(new_for, 0, sizeof *new_for);
+Buf_Init(_for->buf, 0);
+strlist_init(_for->vars);
+strlist_init(_for->items);
+new_for->parse_buf = NULL;
+new_for->short_var = FALSE;
+new_for->sub_next = 0;
 
 /* Grab the variables. Terminate on "in". */
 for (;; ptr += len) {
@@ -248,7 +253,6 @@ For_Eval(char *line)
 	}
 }
 
-Buf_Init(_for->buf, 0);
 accumFor = new_for;
 forLevel = 1;
 return 1;



CVS commit: src/usr.bin/make

2020-09-06 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Sep  6 19:30:54 UTC 2020

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

Log Message:
make(1): add const to For_Eval and For_Accum


To generate a diff of this commit:
cvs rdiff -u -r1.72 -r1.73 src/usr.bin/make/for.c
cvs rdiff -u -r1.104 -r1.105 src/usr.bin/make/nonints.h

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/for.c
diff -u src/usr.bin/make/for.c:1.72 src/usr.bin/make/for.c:1.73
--- src/usr.bin/make/for.c:1.72	Sun Sep  6 19:28:49 2020
+++ src/usr.bin/make/for.c	Sun Sep  6 19:30:53 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: for.c,v 1.72 2020/09/06 19:28:49 rillig Exp $	*/
+/*	$NetBSD: for.c,v 1.73 2020/09/06 19:30:53 rillig Exp $	*/
 
 /*
  * Copyright (c) 1992, The Regents of the University of California.
@@ -30,14 +30,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: for.c,v 1.72 2020/09/06 19:28:49 rillig Exp $";
+static char rcsid[] = "$NetBSD: for.c,v 1.73 2020/09/06 19:30:53 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)for.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: for.c,v 1.72 2020/09/06 19:28:49 rillig Exp $");
+__RCSID("$NetBSD: for.c,v 1.73 2020/09/06 19:30:53 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -120,7 +120,7 @@ For_Free(For *arg)
  * -1: A .for statement with a bad syntax error, discard.
  */
 int
-For_Eval(char *line)
+For_Eval(const char *line)
 {
 For *new_for;
 const char *ptr;
@@ -269,9 +269,9 @@ For_Eval(char *line)
  */
 
 int
-For_Accum(char *line)
+For_Accum(const char *line)
 {
-char *ptr = line;
+const char *ptr = line;
 
 if (*ptr == '.') {
 

Index: src/usr.bin/make/nonints.h
diff -u src/usr.bin/make/nonints.h:1.104 src/usr.bin/make/nonints.h:1.105
--- src/usr.bin/make/nonints.h:1.104	Thu Sep  3 18:19:15 2020
+++ src/usr.bin/make/nonints.h	Sun Sep  6 19:30:53 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nonints.h,v 1.104 2020/09/03 18:19:15 rillig Exp $	*/
+/*	$NetBSD: nonints.h,v 1.105 2020/09/06 19:30:53 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -98,8 +98,8 @@ void Cond_restore_depth(unsigned int);
 unsigned int Cond_save_depth(void);
 
 /* for.c */
-int For_Eval(char *);
-int For_Accum(char *);
+int For_Eval(const char *);
+int For_Accum(const char *);
 void For_Run(int);
 
 /* job.c */



CVS commit: src/usr.bin/make

2020-09-06 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Sep  6 19:28:49 UTC 2020

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

Log Message:
make(1): clean up For_Eval

* Reduce scope of local variables.
* Remove unnecessary null character test before positive isspace call.


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/usr.bin/make/for.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/for.c
diff -u src/usr.bin/make/for.c:1.71 src/usr.bin/make/for.c:1.72
--- src/usr.bin/make/for.c:1.71	Sun Sep  6 19:24:12 2020
+++ src/usr.bin/make/for.c	Sun Sep  6 19:28:49 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: for.c,v 1.71 2020/09/06 19:24:12 rillig Exp $	*/
+/*	$NetBSD: for.c,v 1.72 2020/09/06 19:28:49 rillig Exp $	*/
 
 /*
  * Copyright (c) 1992, The Regents of the University of California.
@@ -30,14 +30,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: for.c,v 1.71 2020/09/06 19:24:12 rillig Exp $";
+static char rcsid[] = "$NetBSD: for.c,v 1.72 2020/09/06 19:28:49 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)for.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: for.c,v 1.71 2020/09/06 19:24:12 rillig Exp $");
+__RCSID("$NetBSD: for.c,v 1.72 2020/09/06 19:28:49 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -123,14 +123,11 @@ int
 For_Eval(char *line)
 {
 For *new_for;
-char *ptr = line, *sub;
-size_t len;
-int escapes;
-unsigned char ch;
+const char *ptr;
 Words words;
 
 /* Skip the '.' and any following whitespace */
-for (ptr++; *ptr && isspace((unsigned char)*ptr); ptr++)
+for (ptr = line + 1; isspace((unsigned char)*ptr); ptr++)
 	continue;
 
 /*
@@ -160,14 +157,17 @@ For_Eval(char *line)
 new_for->sub_next = 0;
 
 /* Grab the variables. Terminate on "in". */
-for (;; ptr += len) {
-	while (*ptr && isspace((unsigned char)*ptr))
+while (TRUE) {
+	size_t len;
+
+	while (isspace((unsigned char)*ptr))
 	ptr++;
 	if (*ptr == '\0') {
 	Parse_Error(PARSE_FATAL, "missing `in' in for");
 	For_Free(new_for);
 	return -1;
 	}
+
 	for (len = 1; ptr[len] && !isspace((unsigned char)ptr[len]); len++)
 	continue;
 	if (len == 2 && ptr[0] == 'i' && ptr[1] == 'n') {
@@ -178,6 +178,7 @@ For_Eval(char *line)
 	new_for->short_var = TRUE;
 
 	strlist_add_str(_for->vars, bmake_strldup(ptr, len), len);
+	ptr += len;
 }
 
 if (strlist_num(_for->vars) == 0) {
@@ -186,7 +187,7 @@ For_Eval(char *line)
 	return -1;
 }
 
-while (*ptr && isspace((unsigned char)*ptr))
+while (isspace((unsigned char)*ptr))
 	ptr++;
 
 /*
@@ -197,21 +198,21 @@ For_Eval(char *line)
  * We can't do the escapes here - because we don't know whether
  * we will be substituting into ${...} or $(...).
  */
-sub = Var_Subst(ptr, VAR_GLOBAL, VARE_WANTRES);
-
-/*
- * Split into words allowing for quoted strings.
- */
-words = Str_Words(sub, FALSE);
-
-free(sub);
+{
+	char *items = Var_Subst(ptr, VAR_GLOBAL, VARE_WANTRES);
+	words = Str_Words(items, FALSE);
+	free(items);
+}
 
 {
-size_t n;
+	size_t n;
 
 	for (n = 0; n < words.len; n++) {
+	int escapes;
+	char ch;
+
 	ptr = words.words[n];
-	if (!*ptr)
+	if (ptr[0] == '\0')
 		continue;
 	escapes = 0;
 	while ((ch = *ptr++)) {
@@ -224,7 +225,7 @@ For_Eval(char *line)
 		case ')':
 		escapes |= FOR_SUB_ESCAPE_PAREN;
 		break;
-		case /*{*/ '}':
+		case '}':
 		escapes |= FOR_SUB_ESCAPE_BRACE;
 		break;
 		}
@@ -236,8 +237,12 @@ For_Eval(char *line)
 	strlist_add_str(_for->items, bmake_strdup(words.words[n]),
 			escapes);
 	}
+}
+
+Words_Free(words);
 
-	Words_Free(words);
+{
+size_t len, n;
 
 	if ((len = strlist_num(_for->items)) > 0 &&
 	len % (n = strlist_num(_for->vars))) {



CVS commit: src/usr.bin/make/unit-tests

2020-08-31 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Aug 31 19:58:21 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: modts.exp modts.mk varmod-to-separator.exp
varmod-to-separator.mk

Log Message:
make(1): move some of the :ts tests into a separate file

The successful cases can be easily tested in the .if conditions.  Around
these conditions, there is enough space for explaining the test cases
and their purpose.

The failure cases have been left in the file for now since they still
produce unwanted characters in the output.  These characters are not
produced when the parse error occurs in a conditional.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/modts.exp \
src/usr.bin/make/unit-tests/modts.mk
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/varmod-to-separator.exp
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/varmod-to-separator.mk

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/unit-tests/modts.exp
diff -u src/usr.bin/make/unit-tests/modts.exp:1.4 src/usr.bin/make/unit-tests/modts.exp:1.5
--- src/usr.bin/make/unit-tests/modts.exp:1.4	Sun Jul 19 09:13:22 2020
+++ src/usr.bin/make/unit-tests/modts.exp	Mon Aug 31 19:58:21 2020
@@ -1,34 +1,3 @@
-LIST="one two three four five six"
-LIST:ts,="one,two,three,four,five,six"
-LIST:ts/:tu="ONE/TWO/THREE/FOUR/FIVE/SIX"
-LIST:ts::tu="ONE:TWO:THREE:FOUR:FIVE:SIX"
-LIST:ts:tu="ONETWOTHREEFOURFIVESIX"
-LIST:tu:ts/="ONE/TWO/THREE/FOUR/FIVE/SIX"
-LIST:ts:="one:two:three:four:five:six"
-LIST:ts="onetwothreefourfivesix"
-LIST:ts:S/two/2/="one2threefourfivesix"
-LIST:S/two/2/:ts="one2threefourfivesix"
-LIST:ts/:S/two/2/="one/2/three/four/five/six"
-Pretend the '/' in '/n' etc. below are back-slashes.
-LIST:ts/n="one
-two
-three
-four
-five
-six"
-LIST:ts/t="one	two	three	four	five	six"
-LIST:ts/012:tu="ONE
-TWO
-THREE
-FOUR
-FIVE
-SIX"
-LIST:ts/xa:tu="ONE
-TWO
-THREE
-FOUR
-FIVE
-SIX"
 make: Bad modifier `:tx' for LIST
 LIST:tx="}"
 make: Bad modifier `:ts\X' for LIST
Index: src/usr.bin/make/unit-tests/modts.mk
diff -u src/usr.bin/make/unit-tests/modts.mk:1.4 src/usr.bin/make/unit-tests/modts.mk:1.5
--- src/usr.bin/make/unit-tests/modts.mk:1.4	Sun Jul 19 09:13:22 2020
+++ src/usr.bin/make/unit-tests/modts.mk	Mon Aug 31 19:58:21 2020
@@ -21,22 +21,6 @@ PRINT= echo
 .endif
 
 mod-ts:
-	@echo 'LIST="${LIST}"'
-	@echo 'LIST:ts,="${LIST:ts,}"'
-	@echo 'LIST:ts/:tu="${LIST:ts/:tu}"'
-	@echo 'LIST:ts::tu="${LIST:ts::tu}"'
-	@echo 'LIST:ts:tu="${LIST:ts:tu}"'
-	@echo 'LIST:tu:ts/="${LIST:tu:ts/}"'
-	@echo 'LIST:ts:="${LIST:ts:}"'
-	@echo 'LIST:ts="${LIST:ts}"'
-	@echo 'LIST:ts:S/two/2/="${LIST:ts:S/two/2/}"'
-	@echo 'LIST:S/two/2/:ts="${LIST:S/two/2/:ts}"'
-	@echo 'LIST:ts/:S/two/2/="${LIST:ts/:S/two/2/}"'
-	@echo "Pretend the '/' in '/n' etc. below are back-slashes."
-	@${PRINT} 'LIST:ts/n="${LIST:ts\n}"'
-	@${PRINT} 'LIST:ts/t="${LIST:ts\t}"'
-	@${PRINT} 'LIST:ts/012:tu="${LIST:ts\012:tu}"'
-	@${PRINT} 'LIST:ts/xa:tu="${LIST:ts\xa:tu}"'
 	@${PRINT} 'LIST:tx="${LIST:tx}"'
 	@${PRINT} 'LIST:ts/x:tu="${LIST:ts\X:tu}"'
 	@${PRINT} 'FU_$@="${FU_${@:ts}:ts}"'

Index: src/usr.bin/make/unit-tests/varmod-to-separator.exp
diff -u src/usr.bin/make/unit-tests/varmod-to-separator.exp:1.1 src/usr.bin/make/unit-tests/varmod-to-separator.exp:1.2
--- src/usr.bin/make/unit-tests/varmod-to-separator.exp:1.1	Sun Aug 16 12:07:51 2020
+++ src/usr.bin/make/unit-tests/varmod-to-separator.exp	Mon Aug 31 19:58:21 2020
@@ -1 +1,9 @@
-exit status 0
+make: Bad modifier `:tx' for WORDS
+make: "varmod-to-separator.mk" line 104: Malformed conditional (${WORDS:tx} != "anything")
+make: "varmod-to-separator.mk" line 108: Parsing continues here.
+make: Bad modifier `:t\X' for WORDS
+make: "varmod-to-separator.mk" line 112: Malformed conditional (${WORDS:t\X} != "anything")
+make: "varmod-to-separator.mk" line 115: Parsing continues here.
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1

Index: src/usr.bin/make/unit-tests/varmod-to-separator.mk
diff -u src/usr.bin/make/unit-tests/varmod-to-separator.mk:1.2 src/usr.bin/make/unit-tests/varmod-to-separator.mk:1.3
--- src/usr.bin/make/unit-tests/varmod-to-separator.mk:1.2	Sun Aug 16 14:25:16 2020
+++ src/usr.bin/make/unit-tests/varmod-to-separator.mk	Mon Aug 31 19:58:21 2020
@@ -1,9 +1,118 @@
-# $NetBSD: varmod-to-separator.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: varmod-to-separator.mk,v 1.3 2020/08/31 19:58:21 rillig Exp $
 #
 # Tests for the :ts variable modifier, which joins the words of the variable
 # using an arbitrary character as word separator.
 
-# TODO: Implementation
+WORDS=	one two three four five six
+
+# The words are separated by a single space, just as usual.
+.if ${WORDS:ts } != "one two three four five six"
+.  warning Space as separator does not work.
+.endif
+
+# The separator can be an 

CVS commit: src/usr.bin/make

2020-08-31 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Aug 31 06:21:07 UTC 2020

Modified Files:
src/usr.bin/make: make.h

Log Message:
make(1): parenthesize macro arguments

Just in case anyone wants to use them for copy-and-paste.

The invocations of these macros are left cautious since the
system-provided definition of these macros may have forgotten the
parentheses as well.


To generate a diff of this commit:
cvs rdiff -u -r1.133 -r1.134 src/usr.bin/make/make.h

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/make.h
diff -u src/usr.bin/make/make.h:1.133 src/usr.bin/make/make.h:1.134
--- src/usr.bin/make/make.h:1.133	Sun Aug 30 14:11:42 2020
+++ src/usr.bin/make/make.h	Mon Aug 31 06:21:07 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.h,v 1.133 2020/08/30 14:11:42 rillig Exp $	*/
+/*	$NetBSD: make.h,v 1.134 2020/08/31 06:21:07 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -552,10 +552,10 @@ void GNode_FprintDetails(FILE *, const c
 #endif
 
 #ifndef MIN
-#define MIN(a, b) ((a < b) ? a : b)
+#define MIN(a, b) (((a) < (b)) ? (a) : (b))
 #endif
 #ifndef MAX
-#define MAX(a, b) ((a > b) ? a : b)
+#define MAX(a, b) (((a) > (b)) ? (a) : (b))
 #endif
 
 /* At least GNU/Hurd systems lack hardcoded MAXPATHLEN/PATH_MAX */



CVS commit: src/usr.bin/make

2020-08-31 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Aug 31 06:44:12 UTC 2020

Modified Files:
src/usr.bin/make: Makefile

Log Message:
make(1): fix copy-and-paste mistake for compiling with GCC10


To generate a diff of this commit:
cvs rdiff -u -r1.96 -r1.97 src/usr.bin/make/Makefile

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/Makefile
diff -u src/usr.bin/make/Makefile:1.96 src/usr.bin/make/Makefile:1.97
--- src/usr.bin/make/Makefile:1.96	Fri Aug 28 20:57:54 2020
+++ src/usr.bin/make/Makefile	Mon Aug 31 06:44:12 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.96 2020/08/28 20:57:54 rillig Exp $
+#	$NetBSD: Makefile,v 1.97 2020/08/31 06:44:12 rillig Exp $
 #	@(#)Makefile	5.2 (Berkeley) 12/28/90
 
 PROG=	make
@@ -131,7 +131,7 @@ COPTS.parse.c+=	-Wno-format-nonliteral
 COPTS.var.c+=	-Wno-format-nonliteral
 
 .if ${USE_GCC10} == "yes"
-GCC9BASE?=	/usr/pkg/gcc10
+GCC10BASE?=	/usr/pkg/gcc10
 CC=		${GCC10BASE}/bin/gcc
 GCOV=		${GCC10BASE}/bin/gcov
 .endif



CVS commit: src/usr.bin/make

2020-08-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Aug 31 05:56:02 UTC 2020

Modified Files:
src/usr.bin/make: lst.c suff.c

Log Message:
make(1): fix unbalanced Lst_Open/Lst_Close in SuffFindCmds

This bug had been there since the initial import of make, on 1993-03-21.
It just never broke the build because of the missing assertion.

https://mail-index.netbsd.org/tech-toolchain/2020/08/30/msg003847.html

The error message "cd: can't cd to include" that I got when I first
applied the fix was unrelated.  It was caused by an extra directory
"include" in src/tools/compat that didn't belong there.  With that
directory removed, running "./build.sh -j8 tools" succeeds as expected.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/usr.bin/make/lst.c
cvs rdiff -u -r1.140 -r1.141 src/usr.bin/make/suff.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/lst.c
diff -u src/usr.bin/make/lst.c:1.59 src/usr.bin/make/lst.c:1.60
--- src/usr.bin/make/lst.c:1.59	Sun Aug 30 21:20:06 2020
+++ src/usr.bin/make/lst.c	Mon Aug 31 05:56:02 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.59 2020/08/30 21:20:06 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.60 2020/08/31 05:56:02 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -37,11 +37,11 @@
 #include "make.h"
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: lst.c,v 1.59 2020/08/30 21:20:06 rillig Exp $";
+static char rcsid[] = "$NetBSD: lst.c,v 1.60 2020/08/31 05:56:02 rillig Exp $";
 #else
 #include 
 #ifndef lint
-__RCSID("$NetBSD: lst.c,v 1.59 2020/08/30 21:20:06 rillig Exp $");
+__RCSID("$NetBSD: lst.c,v 1.60 2020/08/31 05:56:02 rillig Exp $");
 #endif /* not lint */
 #endif
 
@@ -542,12 +542,7 @@ void
 Lst_Open(Lst list)
 {
 assert(list != NULL);
-
-/* XXX: This assertion fails for NetBSD's "build.sh -j1 tools", somewhere
- * between "dependall ===> compat" and "dependall ===> binstall".
- * Building without the "-j1" succeeds though. */
-if (DEBUG(LINT) && list->isOpen)
-	Parse_Error(PARSE_WARNING, "Internal inconsistency: list opened twice");
+assert(!list->isOpen);
 
 list->isOpen = TRUE;
 list->lastAccess = LstIsEmpty(list) ? Head : Unknown;

Index: src/usr.bin/make/suff.c
diff -u src/usr.bin/make/suff.c:1.140 src/usr.bin/make/suff.c:1.141
--- src/usr.bin/make/suff.c:1.140	Sun Aug 30 18:26:41 2020
+++ src/usr.bin/make/suff.c	Mon Aug 31 05:56:02 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: suff.c,v 1.140 2020/08/30 18:26:41 rillig Exp $	*/
+/*	$NetBSD: suff.c,v 1.141 2020/08/31 05:56:02 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: suff.c,v 1.140 2020/08/30 18:26:41 rillig Exp $";
+static char rcsid[] = "$NetBSD: suff.c,v 1.141 2020/08/31 05:56:02 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)suff.c	8.4 (Berkeley) 3/21/94";
 #else
-__RCSID("$NetBSD: suff.c,v 1.140 2020/08/30 18:26:41 rillig Exp $");
+__RCSID("$NetBSD: suff.c,v 1.141 2020/08/31 05:56:02 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -230,7 +230,6 @@ static int SuffRebuildGraph(void *, void
 static int SuffScanTargets(void *, void *);
 static int SuffAddSrc(void *, void *);
 static void SuffAddLevel(Lst, Src *);
-static Src *SuffFindCmds(Src *, Lst);
 static void SuffExpandChildren(LstNode, GNode *);
 static void SuffExpandWildcards(LstNode, GNode *);
 static Boolean SuffApplyTransform(GNode *, GNode *, Suff *, Suff *);
@@ -1232,6 +1231,7 @@ SuffFindCmds(Src *targ, Lst slst)
 #endif
 Lst_Append(slst, ret);
 SUFF_DEBUG1("\tusing existing source %s\n", s->name);
+Lst_Close(t->children);
 return ret;
 }
 



CVS commit: src/usr.bin/make

2020-09-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Sep  2 03:28:12 UTC 2020

Modified Files:
src/usr.bin/make: dir.c make.h

Log Message:
make(1): use proper types in API of cached_stat and cached_lstat


To generate a diff of this commit:
cvs rdiff -u -r1.131 -r1.132 src/usr.bin/make/dir.c
cvs rdiff -u -r1.134 -r1.135 src/usr.bin/make/make.h

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/dir.c
diff -u src/usr.bin/make/dir.c:1.131 src/usr.bin/make/dir.c:1.132
--- src/usr.bin/make/dir.c:1.131	Wed Sep  2 03:15:21 2020
+++ src/usr.bin/make/dir.c	Wed Sep  2 03:28:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.c,v 1.131 2020/09/02 03:15:21 rillig Exp $	*/
+/*	$NetBSD: dir.c,v 1.132 2020/09/02 03:28:12 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: dir.c,v 1.131 2020/09/02 03:15:21 rillig Exp $";
+static char rcsid[] = "$NetBSD: dir.c,v 1.132 2020/09/02 03:28:12 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)dir.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: dir.c,v 1.131 2020/09/02 03:15:21 rillig Exp $");
+__RCSID("$NetBSD: dir.c,v 1.132 2020/09/02 03:28:12 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -337,13 +337,13 @@ cached_stats(Hash_Table *htp, const char
 }
 
 int
-cached_stat(const char *pathname, void *st)
+cached_stat(const char *pathname, struct stat *st)
 {
 return cached_stats(, pathname, st, 0);
 }
 
 int
-cached_lstat(const char *pathname, void *st)
+cached_lstat(const char *pathname, struct stat *st)
 {
 return cached_stats(, pathname, st, CST_LSTAT);
 }

Index: src/usr.bin/make/make.h
diff -u src/usr.bin/make/make.h:1.134 src/usr.bin/make/make.h:1.135
--- src/usr.bin/make/make.h:1.134	Mon Aug 31 06:21:07 2020
+++ src/usr.bin/make/make.h	Wed Sep  2 03:28:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.h,v 1.134 2020/08/31 06:21:07 rillig Exp $	*/
+/*	$NetBSD: make.h,v 1.135 2020/09/02 03:28:12 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -82,6 +82,7 @@
 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -536,8 +537,8 @@ void Main_ExportMAKEFLAGS(Boolean);
 Boolean Main_SetObjdir(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2);
 int mkTempFile(const char *, char **);
 int str2Lst_Append(Lst, char *, const char *);
-int cached_lstat(const char *, void *);
-int cached_stat(const char *, void *);
+int cached_lstat(const char *, struct stat *);
+int cached_stat(const char *, struct stat *);
 void GNode_FprintDetails(FILE *, const char *, const GNode *, const char *);
 
 #ifdef __GNUC__



CVS commit: src/usr.bin/make

2020-09-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Sep  2 04:08:54 UTC 2020

Modified Files:
src/usr.bin/make: dir.c dir.h make.h meta.c

Log Message:
make(1): reduce number of stat fields returned by cached_stat

Only st_mtime and st_mode are actually filled, the remaining fields had
been set to zero.  To prevent these from ever being accessed, a custom
struct make_stat replaces the previously used struct stat.

The fields in struct make_stat are intentionally named different from
the fields in struct stat because NetBSD and some other operating
systems define st_mtime as a macro, and that would not work in a field
declaration.


To generate a diff of this commit:
cvs rdiff -u -r1.132 -r1.133 src/usr.bin/make/dir.c
cvs rdiff -u -r1.22 -r1.23 src/usr.bin/make/dir.h
cvs rdiff -u -r1.135 -r1.136 src/usr.bin/make/make.h
cvs rdiff -u -r1.112 -r1.113 src/usr.bin/make/meta.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/dir.c
diff -u src/usr.bin/make/dir.c:1.132 src/usr.bin/make/dir.c:1.133
--- src/usr.bin/make/dir.c:1.132	Wed Sep  2 03:28:12 2020
+++ src/usr.bin/make/dir.c	Wed Sep  2 04:08:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.c,v 1.132 2020/09/02 03:28:12 rillig Exp $	*/
+/*	$NetBSD: dir.c,v 1.133 2020/09/02 04:08:54 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: dir.c,v 1.132 2020/09/02 03:28:12 rillig Exp $";
+static char rcsid[] = "$NetBSD: dir.c,v 1.133 2020/09/02 04:08:54 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)dir.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: dir.c,v 1.132 2020/09/02 03:28:12 rillig Exp $");
+__RCSID("$NetBSD: dir.c,v 1.133 2020/09/02 04:08:54 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -282,13 +282,13 @@ typedef enum {
 CST_UPDATE = 0x02		/* ignore existing cached entry */
 } CachedStatsFlags;
 
-/* Returns 0 and the result of stat(2) or lstat(2) in *st, or -1 on error.
- * Only st->st_mode and st->st_mtime are filled. */
+/* Returns 0 and the result of stat(2) or lstat(2) in *mst, or -1 on error. */
 static int
-cached_stats(Hash_Table *htp, const char *pathname, struct stat *st,
+cached_stats(Hash_Table *htp, const char *pathname, struct make_stat *mst,
 	 CachedStatsFlags flags)
 {
 Hash_Entry *entry;
+struct stat sys_st;
 struct cache_st *cst;
 int rc;
 
@@ -300,22 +300,23 @@ cached_stats(Hash_Table *htp, const char
 if (entry && !(flags & CST_UPDATE)) {
 	cst = Hash_GetValue(entry);
 
-	memset(st, 0, sizeof(*st));
-	st->st_mode = cst->mode;
-	st->st_mtime = (flags & CST_LSTAT) ? cst->lmtime : cst->mtime;
-	if (st->st_mtime) {
+	mst->mst_mode = cst->mode;
+	mst->mst_mtime = (flags & CST_LSTAT) ? cst->lmtime : cst->mtime;
+	if (mst->mst_mtime) {
 	DIR_DEBUG2("Using cached time %s for %s\n",
-		   Targ_FmtTime(st->st_mtime), pathname);
+		   Targ_FmtTime(mst->mst_mtime), pathname);
 	return 0;
 	}
 }
 
-rc = (flags & CST_LSTAT) ? lstat(pathname, st) : stat(pathname, st);
+rc = (flags & CST_LSTAT)
+	 ? lstat(pathname, _st)
+	 : stat(pathname, _st);
 if (rc == -1)
 	return -1;
 
-if (st->st_mtime == 0)
-	st->st_mtime = 1;	/* avoid confusion with missing file */
+if (sys_st.st_mtime == 0)
+	sys_st.st_mtime = 1;	/* avoid confusion with missing file */
 
 if (entry == NULL)
 	entry = Hash_CreateEntry(htp, pathname, NULL);
@@ -325,25 +326,25 @@ cached_stats(Hash_Table *htp, const char
 }
 cst = Hash_GetValue(entry);
 if (flags & CST_LSTAT) {
-	cst->lmtime = st->st_mtime;
+	cst->lmtime = sys_st.st_mtime;
 } else {
-	cst->mtime = st->st_mtime;
+	cst->mtime = sys_st.st_mtime;
 }
-cst->mode = st->st_mode;
+cst->mode = sys_st.st_mode;
 DIR_DEBUG2("   Caching %s for %s\n",
-	   Targ_FmtTime(st->st_mtime), pathname);
+	   Targ_FmtTime(sys_st.st_mtime), pathname);
 
 return 0;
 }
 
 int
-cached_stat(const char *pathname, struct stat *st)
+cached_stat(const char *pathname, struct make_stat *st)
 {
 return cached_stats(, pathname, st, 0);
 }
 
 int
-cached_lstat(const char *pathname, struct stat *st)
+cached_lstat(const char *pathname, struct make_stat *st)
 {
 return cached_stats(, pathname, st, CST_LSTAT);
 }
@@ -935,7 +936,7 @@ DirLookup(Path *p, const char *name MAKE
 static char *
 DirLookupSubdir(Path *p, const char *name)
 {
-struct stat stb;		/* Buffer for stat, if necessary */
+struct make_stat mst;
 char *file;			/* the current filename to check */
 
 if (p != dot) {
@@ -949,7 +950,7 @@ DirLookupSubdir(Path *p, const char *nam
 
 DIR_DEBUG1("checking %s ...\n", file);
 
-if (cached_stat(file, ) == 0) {
+if (cached_stat(file, ) == 0) {
 	nearmisses += 1;
 	return file;
 }
@@ -1069,7 +1070,7 @@ Dir_FindFile(const 

CVS commit: src

2020-09-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Sep  2 05:33:58 UTC 2020

Modified Files:
src/distrib/sets/lists/tests: mi
src/usr.bin/make/unit-tests: Makefile
Added Files:
src/usr.bin/make/unit-tests: directive-for.exp directive-for.mk

Log Message:
make(1): add test for the .for directive

For a long time, I had assumed that the iteration variables of a .for
loop are just normal global variables.  This assumption was wrong but
didn't have any consequences.

The iteration variables of a .for loop can just be accessed like global
variables, therefore it is not obvious that they are implemented in a
completely different way.

There are some edge cases in conditions used inside .for loops, in which
the iteration variables cannot be used like normal variables.  An
example is brought up in https://gnats.netbsd.org/47888, which observes
that the defined() and empty() functions in conditions only work with
variables but ignore the iteration "variables", simply because these are
not variables but only expressions.


To generate a diff of this commit:
cvs rdiff -u -r1.914 -r1.915 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.129 -r1.130 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r0 -r1.1 src/usr.bin/make/unit-tests/directive-for.exp \
src/usr.bin/make/unit-tests/directive-for.mk

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

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.914 src/distrib/sets/lists/tests/mi:1.915
--- src/distrib/sets/lists/tests/mi:1.914	Sat Aug 29 18:50:25 2020
+++ src/distrib/sets/lists/tests/mi	Wed Sep  2 05:33:57 2020
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.914 2020/08/29 18:50:25 rillig Exp $
+# $NetBSD: mi,v 1.915 2020/09/02 05:33:57 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -4730,6 +4730,8 @@
 ./usr/tests/usr.bin/make/unit-tests/directive-export-literal.mk	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/directive-export.exp	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/directive-export.mk	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/directive-for.exp			tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/directive-for.mk			tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/directive-for-generating-endif.exp	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/directive-for-generating-endif.mk	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/directive-if.exp	tests-usr.bin-tests	compattestfile,atf

Index: src/usr.bin/make/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.129 src/usr.bin/make/unit-tests/Makefile:1.130
--- src/usr.bin/make/unit-tests/Makefile:1.129	Sat Aug 29 19:35:38 2020
+++ src/usr.bin/make/unit-tests/Makefile	Wed Sep  2 05:33:57 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.129 2020/08/29 19:35:38 rillig Exp $
+# $NetBSD: Makefile,v 1.130 2020/09/02 05:33:57 rillig Exp $
 #
 # Unit tests for make(1)
 #
@@ -132,6 +132,7 @@ TESTS+=		directive-error
 TESTS+=		directive-export
 TESTS+=		directive-export-env
 TESTS+=		directive-export-literal
+TESTS+=		directive-for
 TESTS+=		directive-for-generating-endif
 TESTS+=		directive-if
 TESTS+=		directive-ifdef

Added files:

Index: src/usr.bin/make/unit-tests/directive-for.exp
diff -u /dev/null src/usr.bin/make/unit-tests/directive-for.exp:1.1
--- /dev/null	Wed Sep  2 05:33:58 2020
+++ src/usr.bin/make/unit-tests/directive-for.exp	Wed Sep  2 05:33:57 2020
@@ -0,0 +1 @@
+exit status 0
Index: src/usr.bin/make/unit-tests/directive-for.mk
diff -u /dev/null src/usr.bin/make/unit-tests/directive-for.mk:1.1
--- /dev/null	Wed Sep  2 05:33:58 2020
+++ src/usr.bin/make/unit-tests/directive-for.mk	Wed Sep  2 05:33:57 2020
@@ -0,0 +1,97 @@
+# $NetBSD: directive-for.mk,v 1.1 2020/09/02 05:33:57 rillig Exp $
+#
+# Tests for the .for directive.
+
+# Using the .for loop, lists of values can be produced.
+# In simple cases, the :@var@${var}@ variable modifier can be used to
+# reach the same effects.
+#
+.undef NUMBERS
+.for num in 1 2 3
+NUMBERS+=	${num}
+.endfor
+.if ${NUMBERS} != "1 2 3"
+.  error
+.endif
+
+# The .for loop also works for multiple iteration variables.
+.for name value in VARNAME value NAME2 value2
+${name}=	${value}
+.endfor
+.if ${VARNAME} != "value" || ${NAME2} != "value2"
+.  error
+.endif
+
+# The .for loop splits the items at whitespace, taking quotes into account,
+# just like the :M or :S variable modifiers.
+#
+# Until 2012-06-03, it had split the items exactly at whitespace, without
+# taking the quotes into account.
+#
+.undef WORDS
+.for var in one t\ w\ o "three three" 'four four' `five six`
+WORDS+=	counted
+.endfor
+.if ${WORDS:[#]} != 6
+.  error
+.endif
+
+# In the body of the .for loop, the 

CVS commit: src/usr.bin/make

2020-09-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Sep  2 04:32:13 UTC 2020

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

Log Message:
make(1): fix cached_stat for files with st_mtime 0


To generate a diff of this commit:
cvs rdiff -u -r1.134 -r1.135 src/usr.bin/make/dir.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/dir.c
diff -u src/usr.bin/make/dir.c:1.134 src/usr.bin/make/dir.c:1.135
--- src/usr.bin/make/dir.c:1.134	Wed Sep  2 04:19:52 2020
+++ src/usr.bin/make/dir.c	Wed Sep  2 04:32:13 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.c,v 1.134 2020/09/02 04:19:52 rillig Exp $	*/
+/*	$NetBSD: dir.c,v 1.135 2020/09/02 04:32:13 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: dir.c,v 1.134 2020/09/02 04:19:52 rillig Exp $";
+static char rcsid[] = "$NetBSD: dir.c,v 1.135 2020/09/02 04:32:13 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)dir.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: dir.c,v 1.134 2020/09/02 04:19:52 rillig Exp $");
+__RCSID("$NetBSD: dir.c,v 1.135 2020/09/02 04:32:13 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -315,12 +315,12 @@ cached_stats(Hash_Table *htp, const char
 if (rc == -1)
 	return -1;
 
-mst->mst_mode = sys_st.st_mode;
-mst->mst_mtime = sys_st.st_mtime;
-
 if (sys_st.st_mtime == 0)
 	sys_st.st_mtime = 1;	/* avoid confusion with missing file */
 
+mst->mst_mode = sys_st.st_mode;
+mst->mst_mtime = sys_st.st_mtime;
+
 if (entry == NULL)
 	entry = Hash_CreateEntry(htp, pathname, NULL);
 if (Hash_GetValue(entry) == NULL) {



CVS commit: src/usr.bin/make

2020-09-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Sep  2 06:19:11 UTC 2020

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

Log Message:
make(1): clean up comments in var.c, make VarQuote const-correct


To generate a diff of this commit:
cvs rdiff -u -r1.482 -r1.483 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.482 src/usr.bin/make/var.c:1.483
--- src/usr.bin/make/var.c:1.482	Mon Aug 31 19:09:19 2020
+++ src/usr.bin/make/var.c	Wed Sep  2 06:19:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.482 2020/08/31 19:09:19 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.483 2020/09/02 06:19:11 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.482 2020/08/31 19:09:19 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.483 2020/09/02 06:19:11 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)var.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: var.c,v 1.482 2020/08/31 19:09:19 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.483 2020/09/02 06:19:11 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -294,9 +294,6 @@ typedef enum {
  * Results:
  *	A pointer to the structure describing the desired variable or
  *	NULL if the variable does not exist.
- *
- * Side Effects:
- *	None
  *---
  */
 static Var *
@@ -856,15 +853,14 @@ out:
  * Var_Set --
  *	Set the variable name to the value val in the given context.
  *
+ *	If the variable doesn't yet exist, it is created.
+ *	Otherwise the new value overwrites and replaces the old value.
+ *
  * Input:
  *	name		name of variable to set
  *	val		value to give to the variable
  *	ctxt		context in which to set it
  *
- * Side Effects:
- *	If the variable doesn't yet exist, it is created.
- *	Otherwise the new value overwrites and replaces the old value.
- *
  * Notes:
  *	The variable is searched for only in its context before being
  *	created in that context. I.e. if the context is VAR_GLOBAL,
@@ -888,15 +884,14 @@ Var_Set(const char *name, const char *va
  *	The variable of the given name has the given value appended to it in
  *	the given context.
  *
+ *	If the variable doesn't exist, it is created. Otherwise the strings
+ *	are concatenated, with a space in between.
+ *
  * Input:
  *	name		name of variable to modify
  *	val		string to append to it
  *	ctxt		context in which this should occur
  *
- * Side Effects:
- *	If the variable doesn't exist, it is created. Otherwise the strings
- *	are concatenated, with a space in between.
- *
  * Notes:
  *	Only if the variable is being sought in the global context is the
  *	environment searched.
@@ -954,22 +949,12 @@ Var_Append(const char *name, const char 
 free(name_freeIt);
 }
 
-/*-
- *---
- * Var_Exists --
- *	See if the given variable exists.
+/* See if the given variable exists, in the given context or in other
+ * fallback contexts.
  *
  * Input:
  *	name		Variable to find
  *	ctxt		Context in which to start search
- *
- * Results:
- *	TRUE if it does, FALSE if it doesn't
- *
- * Side Effects:
- *	None.
- *
- *---
  */
 Boolean
 Var_Exists(const char *name, GNode *ctxt)
@@ -1755,23 +1740,12 @@ ParseModifierPart(
 return rstr;
 }
 
-/*-
- *---
- * VarQuote --
- *	Quote shell meta-characters and space characters in the string
- *	if quoteDollar is set, also quote and double any '$' characters.
- *
- * Results:
- *	The quoted string
- *
- * Side Effects:
- *	None.
- *
- *---
- */
+/* Quote shell meta-characters and space characters in the string.
+ * If quoteDollar is set, also quote and double any '$' characters. */
 static char *
-VarQuote(char *str, Boolean quoteDollar)
+VarQuote(const char *str, Boolean quoteDollar)
 {
+char *res;
 Buffer buf;
 Buf_Init(, 0);
 
@@ -1790,9 +1764,9 @@ VarQuote(char *str, Boolean quoteDollar)
 	Buf_AddStr(, "\\$");
 }
 
-str = Buf_Destroy(, FALSE);
-VAR_DEBUG("QuoteMeta: [%s]\n", str);
-return str;
+res = Buf_Destroy(, FALSE);
+VAR_DEBUG("QuoteMeta: [%s]\n", res);
+return res;
 }
 
 /* Compute the 32-bit hash of the given string, using the MurmurHash3



CVS commit: src/usr.bin/make

2020-09-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Sep  2 04:19:52 UTC 2020

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

Log Message:
make(1): fix aliasing problem in cached_stat from the previous commit

When the struct stat was used for both calling the actual stat and for
returning the result, no copying was needed.  This also had the side
effect that for the first call of cached_stat, the returned struct stat
included all the fields properly filled in, and on later calls, these
fields were all zeroed out.

These two variables are separate now, thus the fields need to be copied
explicitly.  There are no existing unit tests for this, but ./build.sh
failed reliably.


To generate a diff of this commit:
cvs rdiff -u -r1.133 -r1.134 src/usr.bin/make/dir.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/dir.c
diff -u src/usr.bin/make/dir.c:1.133 src/usr.bin/make/dir.c:1.134
--- src/usr.bin/make/dir.c:1.133	Wed Sep  2 04:08:54 2020
+++ src/usr.bin/make/dir.c	Wed Sep  2 04:19:52 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.c,v 1.133 2020/09/02 04:08:54 rillig Exp $	*/
+/*	$NetBSD: dir.c,v 1.134 2020/09/02 04:19:52 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: dir.c,v 1.133 2020/09/02 04:08:54 rillig Exp $";
+static char rcsid[] = "$NetBSD: dir.c,v 1.134 2020/09/02 04:19:52 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)dir.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: dir.c,v 1.133 2020/09/02 04:08:54 rillig Exp $");
+__RCSID("$NetBSD: dir.c,v 1.134 2020/09/02 04:19:52 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -315,6 +315,9 @@ cached_stats(Hash_Table *htp, const char
 if (rc == -1)
 	return -1;
 
+mst->mst_mode = sys_st.st_mode;
+mst->mst_mtime = sys_st.st_mtime;
+
 if (sys_st.st_mtime == 0)
 	sys_st.st_mtime = 1;	/* avoid confusion with missing file */
 



CVS commit: src/usr.bin/make/unit-tests

2020-09-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Sep  2 05:36:58 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: forloop.mk

Log Message:
make(1): fix typo in unit test for the .for loop


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/forloop.mk

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/unit-tests/forloop.mk
diff -u src/usr.bin/make/unit-tests/forloop.mk:1.2 src/usr.bin/make/unit-tests/forloop.mk:1.3
--- src/usr.bin/make/unit-tests/forloop.mk:1.2	Fri May  1 16:29:34 2020
+++ src/usr.bin/make/unit-tests/forloop.mk	Wed Sep  2 05:36:58 2020
@@ -1,4 +1,4 @@
-# $Id: forloop.mk,v 1.2 2020/05/01 16:29:34 rillig Exp $
+# $Id: forloop.mk,v 1.3 2020/09/02 05:36:58 rillig Exp $
 
 all: for-loop
 
@@ -36,7 +36,7 @@ X!= echo 'a=$a b=$b' >&2; echo
 
 # Since at least 1993, iteration stops at the first newline.
 # Back then, the .newline variable didn't exist, therefore it was unlikely
-# that a newline ever occured.
+# that a newline ever occurred.
 .for var in a${.newline}b${.newline}c
 X!= echo 'newline-item=('${var:Q}')' 1>&2; echo
 .endfor



CVS commit: src/usr.bin/make

2020-09-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Sep  2 03:15:21 UTC 2020

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

Log Message:
make(1): use Hash API from dir.c

When the Hash struct fields are renamed the next time, this should not
influence any code outside hash.h and hash.c.


To generate a diff of this commit:
cvs rdiff -u -r1.130 -r1.131 src/usr.bin/make/dir.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/dir.c
diff -u src/usr.bin/make/dir.c:1.130 src/usr.bin/make/dir.c:1.131
--- src/usr.bin/make/dir.c:1.130	Tue Sep  1 21:11:31 2020
+++ src/usr.bin/make/dir.c	Wed Sep  2 03:15:21 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.c,v 1.130 2020/09/01 21:11:31 rillig Exp $	*/
+/*	$NetBSD: dir.c,v 1.131 2020/09/02 03:15:21 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: dir.c,v 1.130 2020/09/01 21:11:31 rillig Exp $";
+static char rcsid[] = "$NetBSD: dir.c,v 1.131 2020/09/02 03:15:21 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)dir.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: dir.c,v 1.130 2020/09/01 21:11:31 rillig Exp $");
+__RCSID("$NetBSD: dir.c,v 1.131 2020/09/02 03:15:21 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -298,7 +298,7 @@ cached_stats(Hash_Table *htp, const char
 entry = Hash_FindEntry(htp, pathname);
 
 if (entry && !(flags & CST_UPDATE)) {
-	cst = entry->value;
+	cst = Hash_GetValue(entry);
 
 	memset(st, 0, sizeof(*st));
 	st->st_mode = cst->mode;
@@ -317,13 +317,13 @@ cached_stats(Hash_Table *htp, const char
 if (st->st_mtime == 0)
 	st->st_mtime = 1;	/* avoid confusion with missing file */
 
-if (!entry)
+if (entry == NULL)
 	entry = Hash_CreateEntry(htp, pathname, NULL);
-if (!entry->value) {
-	entry->value = bmake_malloc(sizeof(*cst));
-	memset(entry->value, 0, sizeof(*cst));
+if (Hash_GetValue(entry) == NULL) {
+	Hash_SetValue(entry, bmake_malloc(sizeof(*cst)));
+	memset(Hash_GetValue(entry), 0, sizeof(*cst));
 }
-cst = entry->value;
+cst = Hash_GetValue(entry);
 if (flags & CST_LSTAT) {
 	cst->lmtime = st->st_mtime;
 } else {



CVS commit: src/usr.bin/make

2020-09-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Sep  2 06:10:44 UTC 2020

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

Log Message:
make(1): remove redundancy from comments in make_malloc.c


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/make/make_malloc.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/make_malloc.c
diff -u src/usr.bin/make/make_malloc.c:1.17 src/usr.bin/make/make_malloc.c:1.18
--- src/usr.bin/make/make_malloc.c:1.17	Sat Aug 29 16:47:45 2020
+++ src/usr.bin/make/make_malloc.c	Wed Sep  2 06:10:44 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: make_malloc.c,v 1.17 2020/08/29 16:47:45 rillig Exp $	*/
+/*	$NetBSD: make_malloc.c,v 1.18 2020/09/02 06:10:44 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
 
 #ifdef MAKE_NATIVE
 #include 
-__RCSID("$NetBSD: make_malloc.c,v 1.17 2020/08/29 16:47:45 rillig Exp $");
+__RCSID("$NetBSD: make_malloc.c,v 1.18 2020/09/02 06:10:44 rillig Exp $");
 #endif
 
 #include 
@@ -41,10 +41,7 @@ __RCSID("$NetBSD: make_malloc.c,v 1.17 2
 #ifndef USE_EMALLOC
 static MAKE_ATTR_DEAD void enomem(void);
 
-/*
- * enomem --
- *	die when out of memory.
- */
+/* die when out of memory. */
 static MAKE_ATTR_DEAD void
 enomem(void)
 {
@@ -52,10 +49,7 @@ enomem(void)
 	exit(2);
 }
 
-/*
- * bmake_malloc --
- *	malloc, but die on error.
- */
+/* malloc, but die on error. */
 void *
 bmake_malloc(size_t len)
 {
@@ -66,10 +60,7 @@ bmake_malloc(size_t len)
 	return p;
 }
 
-/*
- * bmake_strdup --
- *	strdup, but die on error.
- */
+/* strdup, but die on error. */
 char *
 bmake_strdup(const char *str)
 {
@@ -92,10 +83,7 @@ bmake_strldup(const char *str, size_t le
 	return p;
 }
 
-/*
- * bmake_realloc --
- *	realloc, but die on error.
- */
+/* realloc, but die on error. */
 void *
 bmake_realloc(void *ptr, size_t size)
 {
@@ -109,5 +97,5 @@ bmake_realloc(void *ptr, size_t size)
 char *
 bmake_strsedup(const char *start, const char *end)
 {
-return bmake_strldup(start, (size_t)(end - start));
+	return bmake_strldup(start, (size_t)(end - start));
 }



CVS commit: src/usr.bin/make

2020-09-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Sep  2 06:25:48 UTC 2020

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

Log Message:
make(1): fix documentation of Var_Subst

The "var" parameter does not exist anymore.


To generate a diff of this commit:
cvs rdiff -u -r1.483 -r1.484 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.483 src/usr.bin/make/var.c:1.484
--- src/usr.bin/make/var.c:1.483	Wed Sep  2 06:19:11 2020
+++ src/usr.bin/make/var.c	Wed Sep  2 06:25:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.483 2020/09/02 06:19:11 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.484 2020/09/02 06:25:48 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.483 2020/09/02 06:19:11 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.484 2020/09/02 06:25:48 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)var.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: var.c,v 1.483 2020/09/02 06:19:11 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.484 2020/09/02 06:25:48 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -3624,15 +3624,15 @@ Var_Parse(const char * const str, GNode 
 return nstr;
 }
 
-/*-
- *---
- * Var_Subst  --
- *	Substitute for all variables in the given string in the given context.
- *	If eflags & VARE_UNDEFERR, Parse_Error will be called when an undefined
- *	variable is encountered.
+/* Substitute for all variables in the given string in the given context.
+ *
+ * If eflags & VARE_UNDEFERR, Parse_Error will be called when an undefined
+ * variable is encountered.
+ *
+ * If eflags & VARE_WANTRES, any effects from the modifiers, such as ::=,
+ * :sh or !cmd! take place.
  *
  * Input:
- *	var		Named variable || NULL for all
  *	str		the string which to substitute
  *	ctxt		the context wherein to find variables
  *	eflags		VARE_UNDEFERR	if undefineds are an error
@@ -3641,11 +3641,6 @@ Var_Parse(const char * const str, GNode 
  *
  * Results:
  *	The resulting string.
- *
- * Side Effects:
- *	Any effects from the modifiers, such as ::=, :sh or !cmd!,
- *	if eflags contains VARE_WANTRES.
- *---
  */
 char *
 Var_Subst(const char *str, GNode *ctxt, VarEvalFlags eflags)



CVS commit: src/usr.bin/make

2020-09-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Sep  7 18:37:09 UTC 2020

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

Log Message:
make(1): with -dp, print name of the function instead of its address

This makes the output a bit more reproducible.  There are still the file
descriptors, which may differ between different runs, but at least the
nextbuf function is printed using a symbolic name instead of a meaningless 
address.
Besides loadedfile_nextbuf, the only other function is ForIterate.


To generate a diff of this commit:
cvs rdiff -u -r1.287 -r1.288 src/usr.bin/make/parse.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/parse.c
diff -u src/usr.bin/make/parse.c:1.287 src/usr.bin/make/parse.c:1.288
--- src/usr.bin/make/parse.c:1.287	Mon Sep  7 06:58:02 2020
+++ src/usr.bin/make/parse.c	Mon Sep  7 18:37:09 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.287 2020/09/07 06:58:02 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.288 2020/09/07 18:37:09 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: parse.c,v 1.287 2020/09/07 06:58:02 rillig Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.288 2020/09/07 18:37:09 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)parse.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: parse.c,v 1.287 2020/09/07 06:58:02 rillig Exp $");
+__RCSID("$NetBSD: parse.c,v 1.288 2020/09/07 18:37:09 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -2375,8 +2375,9 @@ Parse_SetInput(const char *name, int lin
 	ParseTrackInput(name);
 
 if (DEBUG(PARSE))
-	fprintf(debug_file, "%s: file %s, line %d, fd %d, nextbuf %p, arg %p\n",
-	__func__, name, line, fd, nextbuf, arg);
+	fprintf(debug_file, "%s: file %s, line %d, fd %d, nextbuf %s, arg %p\n",
+		__func__, name, line, fd,
+		nextbuf == loadedfile_nextbuf ? "loadedfile" : "other", arg);
 
 if (fd == -1 && nextbuf == NULL)
 	/* sanity */



CVS commit: src/usr.bin/make

2020-09-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Sep  7 19:48:09 UTC 2020

Modified Files:
src/usr.bin/make: dir.c
src/usr.bin/make/unit-tests: dir.mk

Log Message:
make(1): document that nested braces work as expected now


To generate a diff of this commit:
cvs rdiff -u -r1.136 -r1.137 src/usr.bin/make/dir.c
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/dir.mk

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/dir.c
diff -u src/usr.bin/make/dir.c:1.136 src/usr.bin/make/dir.c:1.137
--- src/usr.bin/make/dir.c:1.136	Sat Sep  5 13:55:08 2020
+++ src/usr.bin/make/dir.c	Mon Sep  7 19:48:08 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.c,v 1.136 2020/09/05 13:55:08 rillig Exp $	*/
+/*	$NetBSD: dir.c,v 1.137 2020/09/07 19:48:08 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: dir.c,v 1.136 2020/09/05 13:55:08 rillig Exp $";
+static char rcsid[] = "$NetBSD: dir.c,v 1.137 2020/09/07 19:48:08 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)dir.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: dir.c,v 1.136 2020/09/05 13:55:08 rillig Exp $");
+__RCSID("$NetBSD: dir.c,v 1.137 2020/09/07 19:48:08 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -256,7 +256,6 @@ static Hash_Table mtimes;
 
 static Hash_Table lmtimes;	/* same as mtimes but for lstat */
 
-static void DirExpandCurly(const char *, const char *, Lst, Lst);
 static void DirExpandInt(const char *, Lst, Lst);
 static int DirPrintWord(void *, void *);
 static int DirPrintDir(void *, void *);

Index: src/usr.bin/make/unit-tests/dir.mk
diff -u src/usr.bin/make/unit-tests/dir.mk:1.4 src/usr.bin/make/unit-tests/dir.mk:1.5
--- src/usr.bin/make/unit-tests/dir.mk:1.4	Fri Jul 31 20:16:21 2020
+++ src/usr.bin/make/unit-tests/dir.mk	Mon Sep  7 19:48:08 2020
@@ -1,8 +1,9 @@
-# $NetBSD: dir.mk,v 1.4 2020/07/31 20:16:21 rillig Exp $
+# $NetBSD: dir.mk,v 1.5 2020/09/07 19:48:08 rillig Exp $
 #
 # Tests for dir.c.
 
 # Dependency lines may use braces for expansion.
+# See DirExpandCurly for the implementation.
 all: {one,two,three}
 
 one:
@@ -22,7 +23,8 @@ five:
 six:
 	@echo 6
 
-# But nested braces don't work.
+# Nested braces work as expected since 2020-07-31 19:06 UTC.
+# They had been broken at least since 2003-01-01, probably even longer.
 all: {{thi,fou}r,fif}teen
 
 thirteen:



CVS commit: src/usr.bin/make/unit-tests

2020-09-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Sep  7 19:17:36 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: comment.exp comment.mk

Log Message:
make(1): extend and explain the test for comments


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/comment.exp \
src/usr.bin/make/unit-tests/comment.mk

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/unit-tests/comment.exp
diff -u src/usr.bin/make/unit-tests/comment.exp:1.1 src/usr.bin/make/unit-tests/comment.exp:1.2
--- src/usr.bin/make/unit-tests/comment.exp:1.1	Thu Aug 21 13:44:51 2014
+++ src/usr.bin/make/unit-tests/comment.exp	Mon Sep  7 19:17:36 2020
@@ -1,5 +1,6 @@
-comment testing start
-this is foo
-This is how a comment looks: # comment
-comment testing done
+echo This is a shell comment: # comment
+This is a shell comment:
+echo This is not a shell comment: '# comment'
+This is not a shell comment: # comment
+A shell comment can#not start in the middle of a word.
 exit status 0
Index: src/usr.bin/make/unit-tests/comment.mk
diff -u src/usr.bin/make/unit-tests/comment.mk:1.1 src/usr.bin/make/unit-tests/comment.mk:1.2
--- src/usr.bin/make/unit-tests/comment.mk:1.1	Thu Aug 21 13:44:51 2014
+++ src/usr.bin/make/unit-tests/comment.mk	Mon Sep  7 19:17:36 2020
@@ -1,31 +1,74 @@
-# This is a comment
-.if ${MACHINE_ARCH} == something
-FOO=bar
-.endif
-
-#\
-	Multiline comment
+# $NetBSD: comment.mk,v 1.2 2020/09/07 19:17:36 rillig Exp $
+#
+# Demonstrate how comments are written in makefiles.
 
-BAR=# defined
-FOOBAR= # defined 
+# This is a comment.
 
-# This is an escaped comment \
-that keeps going until the end of this line
+#\
+This is a multiline comment.
 
-# Another escaped comment \
+# Another multiline comment \
 that \
 goes \
-on
+on and on.
+
+ # Comments can be indented, but that is rather unusual.
+
+	# Comments can be indented with a tab.
+	# These are not shell commands, they are just makefile comments.
+
+.if 1			# There can be comments after conditions.
+.endif			# And after the closing directive.
+
+VAR=			# This comment makes the variable value empty.
+.if ${VAR} != ""
+.  error
+.endif
+
+# The comment does not need to start at the beginning of a word (as in the
+# shell), it can start anywhere.
+VAR=# defined but empty
+
+# The space before the comment is always trimmed.
+VAR=	value
+.if ${VAR} != "value"
+.  error
+.endif
 
 # This is NOT an escaped comment due to the double backslashes \\
-all: hi foo bar
-	@echo comment testing done
+VAR=	not part of the comment
+.if ${VAR} != "not part of the comment"
+.  error
+.endif
 
-hi:
-	@echo comment testing start
+# To escape a comment sign, precede it with a backslash.
+VAR=	\#		# Both in the assignment.
+.if ${VAR} != "\#"	# And in the comparison.
+.  error
+.endif
+
+# Since 2012-03-24 the variable modifier :[#] does not need to be escaped.
+# To keep the parsing code simple, any "[#" does not start a comment, even
+# outside of a variable expression.
+WORDS=	${VAR:[#]} [#
+.if ${WORDS} != "1 [#"
+.  error
+.endif
 
-foo:
-	@echo this is $@
+# An odd number of comment signs makes a line continuation, \\\
+no matter if it is 3 or 5 \
+or 9 backslashes. \
+This is the last line of the comment.
+VAR=	no comment anymore
+.if ${VAR} != "no comment anymore"
+.  error
+.endif
 
-bar:
-	@echo This is how a comment looks: '# comment'
+all:
+# In the commands associated with a target, the '#' does not start a makefile
+# comment.  The '#' is just passed to the shell, like any ordinary character.
+	echo This is a shell comment: # comment
+# If the '#' were to start a makefile comment, the following shell command
+# would have unbalanced quotes.
+	echo This is not a shell comment: '# comment'
+	@echo A shell comment can#not start in the middle of a word.



CVS commit: src/usr.bin/make/unit-tests

2020-09-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Sep  7 18:43:59 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: Makefile

Log Message:
make(1): use consistent spelling for postprocessing


To generate a diff of this commit:
cvs rdiff -u -r1.136 -r1.137 src/usr.bin/make/unit-tests/Makefile

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/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.136 src/usr.bin/make/unit-tests/Makefile:1.137
--- src/usr.bin/make/unit-tests/Makefile:1.136	Sat Sep  5 12:59:07 2020
+++ src/usr.bin/make/unit-tests/Makefile	Mon Sep  7 18:43:59 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.136 2020/09/05 12:59:07 rillig Exp $
+# $NetBSD: Makefile,v 1.137 2020/09/07 18:43:59 rillig Exp $
 #
 # Unit tests for make(1)
 #
@@ -372,7 +372,7 @@ FLAGS.varmod-match-escape= -dv
 FLAGS.varname-dot-shell= -dpv
 FLAGS.varname-empty=	-dv '$${:U}=cmdline-u' '=cmline-plain'
 
-# Some tests need extra post-processing.
+# Some tests need extra postprocessing.
 SED_CMDS.opt-debug-graph1= \
 			-e 's,${.CURDIR},CURDIR,'
 SED_CMDS.opt-debug-graph1+= \
@@ -446,7 +446,7 @@ LANG=		C
 	echo $$status > ${.TARGET:R}.status
 	@mv ${.TARGET}.tmp ${.TARGET}
 
-# Post-process the test output so that the results can be compared.
+# Postprocess the test output so that the results can be compared.
 #
 # always pretend .MAKE was called 'make'
 _SED_CMDS+=	-e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,'



CVS commit: src/usr.bin/make/unit-tests

2020-09-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Sep  7 18:40:32 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: depsrc-wait.exp depsrc-wait.mk

Log Message:
make(1): add test for the .WAIT dependency source


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/depsrc-wait.exp
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/depsrc-wait.mk

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/unit-tests/depsrc-wait.exp
diff -u src/usr.bin/make/unit-tests/depsrc-wait.exp:1.1 src/usr.bin/make/unit-tests/depsrc-wait.exp:1.2
--- src/usr.bin/make/unit-tests/depsrc-wait.exp:1.1	Sun Aug 16 12:07:51 2020
+++ src/usr.bin/make/unit-tests/depsrc-wait.exp	Mon Sep  7 18:40:32 2020
@@ -1 +1,13 @@
+--- a ---
+echo a
+a
+--- b1 ---
+echo b1
+b1
+--- b ---
+echo b
+b
+--- x ---
+echo x
+x
 exit status 0

Index: src/usr.bin/make/unit-tests/depsrc-wait.mk
diff -u src/usr.bin/make/unit-tests/depsrc-wait.mk:1.2 src/usr.bin/make/unit-tests/depsrc-wait.mk:1.3
--- src/usr.bin/make/unit-tests/depsrc-wait.mk:1.2	Sun Aug 16 14:25:16 2020
+++ src/usr.bin/make/unit-tests/depsrc-wait.mk	Mon Sep  7 18:40:32 2020
@@ -1,8 +1,21 @@
-# $NetBSD: depsrc-wait.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: depsrc-wait.mk,v 1.3 2020/09/07 18:40:32 rillig Exp $
 #
-# Tests for the special source .WAIT in dependency declarations.
+# Tests for the special source .WAIT in dependency declarations,
+# which adds a sequence point between the nodes to its left and the nodes
+# to its right.
 
-# TODO: Implementation
+# Even though the build could run massively parallel, the .WAIT imposes a
+# strict ordering in this example, which forces the targets to be made in
+# exactly this order.
+.MAKEFLAGS: -j8
 
-all:
-	@:;
+# This is the example from the manual page.
+.PHONY: x a b b1
+x: a .WAIT b
+	echo x
+a:
+	echo a
+b: b1
+	echo b
+b1:
+	echo b1



CVS commit: src/usr.bin/make/unit-tests

2020-09-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Sep  7 18:49:15 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: Makefile

Log Message:
make(1): explain why each test is run in a sub-make


To generate a diff of this commit:
cvs rdiff -u -r1.137 -r1.138 src/usr.bin/make/unit-tests/Makefile

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/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.137 src/usr.bin/make/unit-tests/Makefile:1.138
--- src/usr.bin/make/unit-tests/Makefile:1.137	Mon Sep  7 18:43:59 2020
+++ src/usr.bin/make/unit-tests/Makefile	Mon Sep  7 18:49:15 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.137 2020/09/07 18:43:59 rillig Exp $
+# $NetBSD: Makefile,v 1.138 2020/09/07 18:49:15 rillig Exp $
 #
 # Unit tests for make(1)
 #
@@ -431,7 +431,9 @@ LC_ALL=		C
 LANG=		C
 .export LANG LC_ALL
 
-# the tests are actually done with sub-makes.
+# Each test is run in a sub-make, to keep the tests for interfering with
+# each other, and because they use different environment variables and
+# command line options.
 .SUFFIXES: .mk .rawout .out
 .mk.rawout:
 	@${_MKMSG_TEST:Uecho '#  test '} ${.PREFIX}



CVS commit: src/usr.bin/make/unit-tests

2020-09-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Sep 10 21:22:08 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: deptgt-makeflags.mk

Log Message:
make(1): add test for .MAKEFLAGS


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/deptgt-makeflags.mk

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/unit-tests/deptgt-makeflags.mk
diff -u src/usr.bin/make/unit-tests/deptgt-makeflags.mk:1.2 src/usr.bin/make/unit-tests/deptgt-makeflags.mk:1.3
--- src/usr.bin/make/unit-tests/deptgt-makeflags.mk:1.2	Sun Aug 16 14:25:16 2020
+++ src/usr.bin/make/unit-tests/deptgt-makeflags.mk	Thu Sep 10 21:22:07 2020
@@ -1,8 +1,41 @@
-# $NetBSD: deptgt-makeflags.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: deptgt-makeflags.mk,v 1.3 2020/09/10 21:22:07 rillig Exp $
 #
-# Tests for the special target .MAKEFLAGS in dependency declarations.
+# Tests for the special target .MAKEFLAGS in dependency declarations,
+# which adds command line options later, at parse time.
 
-# TODO: Implementation
+# The -D option sets a variable in the "Global" scope and thus can be
+# undefined later.
+.MAKEFLAGS: -D VAR
+
+.if ${VAR} != 1
+.  error
+.endif
+
+.undef VAR
+
+.if defined(VAR)
+.  error
+.endif
+
+.MAKEFLAGS: -D VAR
+
+.if ${VAR} != 1
+.  error
+.endif
+
+.MAKEFLAGS: VAR="value"' with'\ spaces
+
+.if ${VAR} != "value with spaces"
+.  error
+.endif
+
+# Variables set on the command line as VAR=value are placed in the
+# "Command" scope and thus cannot be undefined.
+.undef VAR
+
+.if ${VAR} != "value with spaces"
+.  error
+.endif
 
 all:
 	@:;



CVS commit: src/usr.bin/make/unit-tests

2020-09-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Sep 10 22:44:08 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: cond-op-or.exp cond-op-or.mk

Log Message:
make(1): add tests for the |, ||, ||| operators


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/cond-op-or.exp
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/cond-op-or.mk

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/unit-tests/cond-op-or.exp
diff -u src/usr.bin/make/unit-tests/cond-op-or.exp:1.1 src/usr.bin/make/unit-tests/cond-op-or.exp:1.2
--- src/usr.bin/make/unit-tests/cond-op-or.exp:1.1	Sun Aug 16 12:07:51 2020
+++ src/usr.bin/make/unit-tests/cond-op-or.exp	Thu Sep 10 22:44:08 2020
@@ -1 +1,4 @@
-exit status 0
+make: "cond-op-or.mk" line 43: Malformed conditional (0 ||| 0)
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1

Index: src/usr.bin/make/unit-tests/cond-op-or.mk
diff -u src/usr.bin/make/unit-tests/cond-op-or.mk:1.3 src/usr.bin/make/unit-tests/cond-op-or.mk:1.4
--- src/usr.bin/make/unit-tests/cond-op-or.mk:1.3	Fri Aug 28 14:48:37 2020
+++ src/usr.bin/make/unit-tests/cond-op-or.mk	Thu Sep 10 22:44:08 2020
@@ -1,4 +1,4 @@
-# $NetBSD: cond-op-or.mk,v 1.3 2020/08/28 14:48:37 rillig Exp $
+# $NetBSD: cond-op-or.mk,v 1.4 2020/09/10 22:44:08 rillig Exp $
 #
 # Tests for the || operator in .if conditions.
 
@@ -23,5 +23,26 @@
 .if 1 || ${UNDEF}
 .endif
 
+# The && operator may be abbreviated as &.  This is not widely known though
+# and is also not documented in the manual page.
+
+.if 0 | 0
+.  error
+.endif
+.if !(1 | 0)
+.  error
+.endif
+.if !(0 | 1)
+.  error
+.endif
+.if !(1 | 1)
+.  error
+.endif
+
+# There is no operator |||.
+.if 0 ||| 0
+.  error
+.endif
+
 all:
 	@:;



CVS commit: src/usr.bin/make/unit-tests

2020-09-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Sep 10 22:38:58 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: cond-op-and.exp cond-op-and.mk

Log Message:
make(1): add test for the &, && and &&& operators


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/cond-op-and.exp
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/cond-op-and.mk

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/unit-tests/cond-op-and.exp
diff -u src/usr.bin/make/unit-tests/cond-op-and.exp:1.1 src/usr.bin/make/unit-tests/cond-op-and.exp:1.2
--- src/usr.bin/make/unit-tests/cond-op-and.exp:1.1	Sun Aug 16 12:07:51 2020
+++ src/usr.bin/make/unit-tests/cond-op-and.exp	Thu Sep 10 22:38:57 2020
@@ -1 +1,4 @@
-exit status 0
+make: "cond-op-and.mk" line 43: Malformed conditional (0 &&& 0)
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1

Index: src/usr.bin/make/unit-tests/cond-op-and.mk
diff -u src/usr.bin/make/unit-tests/cond-op-and.mk:1.3 src/usr.bin/make/unit-tests/cond-op-and.mk:1.4
--- src/usr.bin/make/unit-tests/cond-op-and.mk:1.3	Fri Aug 28 14:48:37 2020
+++ src/usr.bin/make/unit-tests/cond-op-and.mk	Thu Sep 10 22:38:57 2020
@@ -1,4 +1,4 @@
-# $NetBSD: cond-op-and.mk,v 1.3 2020/08/28 14:48:37 rillig Exp $
+# $NetBSD: cond-op-and.mk,v 1.4 2020/09/10 22:38:57 rillig Exp $
 #
 # Tests for the && operator in .if conditions.
 
@@ -23,5 +23,26 @@
 .if 0 && ${UNDEF}
 .endif
 
+# The && operator may be abbreviated as &.  This is not widely known though
+# and is also not documented in the manual page.
+
+.if 0 & 0
+.  error
+.endif
+.if 1 & 0
+.  error
+.endif
+.if 0 & 1
+.  error
+.endif
+.if !(1 & 1)
+.  error
+.endif
+
+# There is no operator &&&.
+.if 0 &&& 0
+.  error
+.endif
+
 all:
 	@:;



CVS commit: src/usr.bin/make

2020-09-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Sep 10 23:27:27 UTC 2020

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

Log Message:
make(1): skip redundant condExpr-- in CondGetString


To generate a diff of this commit:
cvs rdiff -u -r1.118 -r1.119 src/usr.bin/make/cond.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.118 src/usr.bin/make/cond.c:1.119
--- src/usr.bin/make/cond.c:1.118	Thu Sep 10 22:47:22 2020
+++ src/usr.bin/make/cond.c	Thu Sep 10 23:27:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.118 2020/09/10 22:47:22 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.119 2020/09/10 23:27:27 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.118 2020/09/10 22:47:22 rillig Exp $";
+static char rcsid[] = "$NetBSD: cond.c,v 1.119 2020/09/10 23:27:27 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)cond.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: cond.c,v 1.118 2020/09/10 22:47:22 rillig Exp $");
+__RCSID("$NetBSD: cond.c,v 1.119 2020/09/10 23:27:27 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -415,22 +415,23 @@ CondGetString(CondLexer *lex, Boolean do
 *quoted = qt = *lex->condExpr == '"' ? 1 : 0;
 if (qt)
 	lex->condExpr++;
-for (start = lex->condExpr;
-	 *lex->condExpr && str == NULL; lex->condExpr++) {
+for (start = lex->condExpr; *lex->condExpr && str == NULL;) {
 	switch (*lex->condExpr) {
 	case '\\':
 	if (lex->condExpr[1] != '\0') {
 		lex->condExpr++;
 		Buf_AddByte(, *lex->condExpr);
 	}
-	break;
+	lex->condExpr++;
+	continue;
 	case '"':
 	if (qt) {
 		lex->condExpr++;	/* we don't want the quotes */
 		goto got_str;
 	} else
 		Buf_AddByte(, *lex->condExpr); /* likely? */
-	break;
+	lex->condExpr++;
+	continue;
 	case ')':
 	case '!':
 	case '=':
@@ -442,7 +443,8 @@ CondGetString(CondLexer *lex, Boolean do
 		goto got_str;
 	else
 		Buf_AddByte(, *lex->condExpr);
-	break;
+	lex->condExpr++;
+	continue;
 	case '$':
 	/* if we are in quotes, then an undefined variable is ok */
 	eflags = ((!qt && doEval) ? VARE_UNDEFERR : 0) |
@@ -479,8 +481,7 @@ CondGetString(CondLexer *lex, Boolean do
 		*freeIt = NULL;
 	}
 	str = NULL;		/* not finished yet */
-	lex->condExpr--;	/* don't skip over next char */
-	break;
+	continue;
 	default:
 	if (strictLHS && !qt && *start != '$' &&
 		!isdigit((unsigned char)*start)) {
@@ -493,7 +494,8 @@ CondGetString(CondLexer *lex, Boolean do
 		goto cleanup;
 	}
 	Buf_AddByte(, *lex->condExpr);
-	break;
+	lex->condExpr++;
+	continue;
 	}
 }
 got_str:



CVS commit: src/usr.bin/make/unit-tests

2020-09-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Sep 10 21:40:50 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: deptgt-silent.exp deptgt-silent.mk

Log Message:
make(1): add test for .SILENT


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/deptgt-silent.exp
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/deptgt-silent.mk

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/unit-tests/deptgt-silent.exp
diff -u src/usr.bin/make/unit-tests/deptgt-silent.exp:1.1 src/usr.bin/make/unit-tests/deptgt-silent.exp:1.2
--- src/usr.bin/make/unit-tests/deptgt-silent.exp:1.1	Sun Aug 16 12:07:51 2020
+++ src/usr.bin/make/unit-tests/deptgt-silent.exp	Thu Sep 10 21:40:50 2020
@@ -1 +1,3 @@
+This is not echoed because of the @.
+This is not echoed because of the .SILENT.
 exit status 0

Index: src/usr.bin/make/unit-tests/deptgt-silent.mk
diff -u src/usr.bin/make/unit-tests/deptgt-silent.mk:1.2 src/usr.bin/make/unit-tests/deptgt-silent.mk:1.3
--- src/usr.bin/make/unit-tests/deptgt-silent.mk:1.2	Sun Aug 16 14:25:16 2020
+++ src/usr.bin/make/unit-tests/deptgt-silent.mk	Thu Sep 10 21:40:50 2020
@@ -1,8 +1,10 @@
-# $NetBSD: deptgt-silent.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: deptgt-silent.mk,v 1.3 2020/09/10 21:40:50 rillig Exp $
 #
 # Tests for the special target .SILENT in dependency declarations.
 
-# TODO: Implementation
+.SILENT: all
 
 all:
-	@:;
+	@echo 'This is not echoed because of the @.'
+	# Without the .SILENT, the following command would be echoed.
+	echo 'This is not echoed because of the .SILENT.'



CVS commit: src/usr.bin/make

2020-09-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Sep 10 22:47:22 UTC 2020

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

Log Message:
make(1): reduce code size for parsing the || or && operators

On x86_64, accessing [0] generates less code than [1].


To generate a diff of this commit:
cvs rdiff -u -r1.117 -r1.118 src/usr.bin/make/cond.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.117 src/usr.bin/make/cond.c:1.118
--- src/usr.bin/make/cond.c:1.117	Tue Sep  8 18:51:23 2020
+++ src/usr.bin/make/cond.c	Thu Sep 10 22:47:22 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.117 2020/09/08 18:51:23 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.118 2020/09/10 22:47:22 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.117 2020/09/08 18:51:23 rillig Exp $";
+static char rcsid[] = "$NetBSD: cond.c,v 1.118 2020/09/10 22:47:22 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)cond.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: cond.c,v 1.117 2020/09/08 18:51:23 rillig Exp $");
+__RCSID("$NetBSD: cond.c,v 1.118 2020/09/10 22:47:22 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -809,11 +809,11 @@ CondToken(CondLexer *lex, Boolean doEval
 	return t;
 }
 
-while (*lex->condExpr == ' ' || *lex->condExpr == '\t') {
+while (lex->condExpr[0] == ' ' || lex->condExpr[0] == '\t') {
 	lex->condExpr++;
 }
 
-switch (*lex->condExpr) {
+switch (lex->condExpr[0]) {
 
 case '(':
 	lex->condExpr++;
@@ -824,17 +824,17 @@ CondToken(CondLexer *lex, Boolean doEval
 	return TOK_RPAREN;
 
 case '|':
-	if (lex->condExpr[1] == '|') {
+	lex->condExpr++;
+	if (lex->condExpr[0] == '|') {
 	lex->condExpr++;
 	}
-	lex->condExpr++;
 	return TOK_OR;
 
 case '&':
-	if (lex->condExpr[1] == '&') {
+	lex->condExpr++;
+	if (lex->condExpr[0] == '&') {
 	lex->condExpr++;
 	}
-	lex->condExpr++;
 	return TOK_AND;
 
 case '!':



CVS commit: src/usr.bin/make

2020-09-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Sep 10 23:37:55 UTC 2020

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

Log Message:
make(1): reduce code size in CondGetString

The pattern is now the usual "test the character, then increment the
pointer", throughout the whole function.


To generate a diff of this commit:
cvs rdiff -u -r1.119 -r1.120 src/usr.bin/make/cond.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.119 src/usr.bin/make/cond.c:1.120
--- src/usr.bin/make/cond.c:1.119	Thu Sep 10 23:27:27 2020
+++ src/usr.bin/make/cond.c	Thu Sep 10 23:37:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.119 2020/09/10 23:27:27 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.120 2020/09/10 23:37:54 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.119 2020/09/10 23:27:27 rillig Exp $";
+static char rcsid[] = "$NetBSD: cond.c,v 1.120 2020/09/10 23:37:54 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)cond.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: cond.c,v 1.119 2020/09/10 23:27:27 rillig Exp $");
+__RCSID("$NetBSD: cond.c,v 1.120 2020/09/10 23:37:54 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -418,18 +418,18 @@ CondGetString(CondLexer *lex, Boolean do
 for (start = lex->condExpr; *lex->condExpr && str == NULL;) {
 	switch (*lex->condExpr) {
 	case '\\':
-	if (lex->condExpr[1] != '\0') {
-		lex->condExpr++;
+	lex->condExpr++;
+	if (lex->condExpr[0] != '\0') {
 		Buf_AddByte(, *lex->condExpr);
+		lex->condExpr++;
 	}
-	lex->condExpr++;
 	continue;
 	case '"':
 	if (qt) {
 		lex->condExpr++;	/* we don't want the quotes */
 		goto got_str;
-	} else
-		Buf_AddByte(, *lex->condExpr); /* likely? */
+	}
+	Buf_AddByte(, *lex->condExpr); /* likely? */
 	lex->condExpr++;
 	continue;
 	case ')':
@@ -441,8 +441,7 @@ CondGetString(CondLexer *lex, Boolean do
 	case '\t':
 	if (!qt)
 		goto got_str;
-	else
-		Buf_AddByte(, *lex->condExpr);
+	Buf_AddByte(, *lex->condExpr);
 	lex->condExpr++;
 	continue;
 	case '$':



CVS commit: src/usr.bin/make

2020-09-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Sep 11 04:22:23 UTC 2020

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

Log Message:
make(1): replace *par->p with par->p[0]

It's a few characters more code than before but can be read strictly
from left to right, which was not possible before.


To generate a diff of this commit:
cvs rdiff -u -r1.122 -r1.123 src/usr.bin/make/cond.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.122 src/usr.bin/make/cond.c:1.123
--- src/usr.bin/make/cond.c:1.122	Fri Sep 11 04:18:44 2020
+++ src/usr.bin/make/cond.c	Fri Sep 11 04:22:22 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.122 2020/09/11 04:18:44 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.123 2020/09/11 04:22:22 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.122 2020/09/11 04:18:44 rillig Exp $";
+static char rcsid[] = "$NetBSD: cond.c,v 1.123 2020/09/11 04:22:22 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)cond.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: cond.c,v 1.122 2020/09/11 04:18:44 rillig Exp $");
+__RCSID("$NetBSD: cond.c,v 1.123 2020/09/11 04:22:22 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -415,15 +415,15 @@ CondGetString(CondParser *par, Boolean d
 Buf_Init(, 0);
 str = NULL;
 *freeIt = NULL;
-*quoted = qt = *par->p == '"' ? 1 : 0;
+*quoted = qt = par->p[0] == '"' ? 1 : 0;
 if (qt)
 	par->p++;
-for (start = par->p; *par->p && str == NULL;) {
-	switch (*par->p) {
+for (start = par->p; par->p[0] && str == NULL;) {
+	switch (par->p[0]) {
 	case '\\':
 	par->p++;
 	if (par->p[0] != '\0') {
-		Buf_AddByte(, *par->p);
+		Buf_AddByte(, par->p[0]);
 		par->p++;
 	}
 	continue;
@@ -432,7 +432,7 @@ CondGetString(CondParser *par, Boolean d
 		par->p++;	/* we don't want the quotes */
 		goto got_str;
 	}
-	Buf_AddByte(, *par->p); /* likely? */
+	Buf_AddByte(, par->p[0]); /* likely? */
 	par->p++;
 	continue;
 	case ')':
@@ -444,7 +444,7 @@ CondGetString(CondParser *par, Boolean d
 	case '\t':
 	if (!qt)
 		goto got_str;
-	Buf_AddByte(, *par->p);
+	Buf_AddByte(, par->p[0]);
 	par->p++;
 	continue;
 	case '$':
@@ -471,9 +471,9 @@ CondGetString(CondParser *par, Boolean d
 	 * we are done.
 	 */
 	if ((par->p == start + len) &&
-		(*par->p == '\0' ||
-		 isspace((unsigned char)*par->p) ||
-		 strchr("!=><)", *par->p))) {
+		(par->p[0] == '\0' ||
+		 isspace((unsigned char)par->p[0]) ||
+		 strchr("!=><)", par->p[0]))) {
 		goto cleanup;
 	}
 
@@ -495,7 +495,7 @@ CondGetString(CondParser *par, Boolean d
 		str = NULL;
 		goto cleanup;
 	}
-	Buf_AddByte(, *par->p);
+	Buf_AddByte(, par->p[0]);
 	par->p++;
 	continue;
 	}
@@ -557,7 +557,7 @@ compare_expression(CondParser *par, Bool
  * != 0 comparison.
  */
 op = par->p;
-switch (*par->p) {
+switch (par->p[0]) {
 case '!':
 case '=':
 case '<':
@@ -595,7 +595,7 @@ compare_expression(CondParser *par, Bool
 
 CondParser_SkipWhitespace(par);
 
-if (*par->p == '\0') {
+if (par->p[0] == '\0') {
 	Parse_Error(PARSE_WARNING,
 		"Missing right-hand-side of operator");
 	goto done;



CVS commit: src/usr.bin/make

2020-09-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Sep 11 04:40:26 UTC 2020

Modified Files:
src/usr.bin/make: cond.c
src/usr.bin/make/unit-tests: cond-op.mk

Log Message:
make(1): rename CondGetString to CondParser_String

This describes the function's effect more accurately.  The verb "get" is
not commonly associated to having side effects.


To generate a diff of this commit:
cvs rdiff -u -r1.123 -r1.124 src/usr.bin/make/cond.c
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/cond-op.mk

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.123 src/usr.bin/make/cond.c:1.124
--- src/usr.bin/make/cond.c:1.123	Fri Sep 11 04:22:22 2020
+++ src/usr.bin/make/cond.c	Fri Sep 11 04:40:26 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.123 2020/09/11 04:22:22 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.124 2020/09/11 04:40:26 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.123 2020/09/11 04:22:22 rillig Exp $";
+static char rcsid[] = "$NetBSD: cond.c,v 1.124 2020/09/11 04:40:26 rillig Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)cond.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: cond.c,v 1.123 2020/09/11 04:22:22 rillig Exp $");
+__RCSID("$NetBSD: cond.c,v 1.124 2020/09/11 04:40:26 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -393,7 +393,7 @@ CondCvtArg(const char *str, double *valu
 
 /*-
  * Parse a string from a variable reference or an optionally quoted
- * string.  This is called for the lhs and rhs of string compares.
+ * string.  This is called for the lhs and rhs of string comparisons.
  *
  * Results:
  *	Returns the string, absent any quotes, or NULL on error.
@@ -402,8 +402,8 @@ CondCvtArg(const char *str, double *valu
  */
 /* coverity:[+alloc : arg-*3] */
 static const char *
-CondGetString(CondParser *par, Boolean doEval, Boolean *quoted, void **freeIt,
-	  Boolean strictLHS)
+CondParser_String(CondParser *par, Boolean doEval, Boolean strictLHS,
+		  Boolean *quoted, void **freeIt)
 {
 Buffer buf;
 const char *str;
@@ -545,7 +545,7 @@ compare_expression(CondParser *par, Bool
  * Parse the variable spec and skip over it, saving its
  * value in lhs.
  */
-lhs = CondGetString(par, doEval, , , lhsStrict);
+lhs = CondParser_String(par, doEval, lhsStrict, , );
 if (!lhs)
 	goto done;
 
@@ -601,7 +601,7 @@ compare_expression(CondParser *par, Bool
 	goto done;
 }
 
-rhs = CondGetString(par, doEval, , , FALSE);
+rhs = CondParser_String(par, doEval, FALSE, , );
 if (!rhs)
 	goto done;
 

Index: src/usr.bin/make/unit-tests/cond-op.mk
diff -u src/usr.bin/make/unit-tests/cond-op.mk:1.4 src/usr.bin/make/unit-tests/cond-op.mk:1.5
--- src/usr.bin/make/unit-tests/cond-op.mk:1.4	Fri Aug 28 14:07:51 2020
+++ src/usr.bin/make/unit-tests/cond-op.mk	Fri Sep 11 04:40:26 2020
@@ -1,4 +1,4 @@
-# $NetBSD: cond-op.mk,v 1.4 2020/08/28 14:07:51 rillig Exp $
+# $NetBSD: cond-op.mk,v 1.5 2020/09/11 04:40:26 rillig Exp $
 #
 # Tests for operators like &&, ||, ! in .if conditions.
 #
@@ -48,7 +48,7 @@
 
 # Surprisingly, the ampersand and pipe are allowed in bare strings.
 # That's another opportunity for writing confusing code.
-# See CondGetString, which only has '!' in the list of stop characters.
+# See CondParser_String, which only has '!' in the list of stop characters.
 .if "a&||c" != a&||c
 .error
 .endif



CVS commit: src/usr.bin/make/unit-tests

2020-09-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Sep 11 05:14:21 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: cond-op.exp

Log Message:
make(1): fix line numbers from test result of the previous commit


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/cond-op.exp

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/unit-tests/cond-op.exp
diff -u src/usr.bin/make/unit-tests/cond-op.exp:1.3 src/usr.bin/make/unit-tests/cond-op.exp:1.4
--- src/usr.bin/make/unit-tests/cond-op.exp:1.3	Fri Sep 11 05:12:08 2020
+++ src/usr.bin/make/unit-tests/cond-op.exp	Fri Sep 11 05:14:21 2020
@@ -1,7 +1,7 @@
 make: "cond-op.mk" line 45: Malformed conditional ("!word" == !word)
-make: "cond-op.mk" line 56: Malformed conditional (0 ${ERR::=evaluated})
-make: "cond-op.mk" line 60: warning: After detecting a parse error, the rest is evaluated.
-make: "cond-op.mk" line 64: Parsing continues until here.
+make: "cond-op.mk" line 59: Malformed conditional (0 ${ERR::=evaluated})
+make: "cond-op.mk" line 63: warning: After detecting a parse error, the rest is evaluated.
+make: "cond-op.mk" line 67: Parsing continues until here.
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1



  1   2   3   4   5   6   7   8   9   10   >