Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make/unit-tests tests/make: remove dependency on exp...
details: https://anonhg.NetBSD.org/src/rev/f2a3ff1a2afa
branches: trunk
changeset: 373128:f2a3ff1a2afa
user: rillig <rillig%NetBSD.org@localhost>
date: Thu Jan 19 22:48:42 2023 +0000
description:
tests/make: remove dependency on expr(1) from a test
This saves 124 calls to the shell.
diffstat:
usr.bin/make/unit-tests/hanoi-include.mk | 18 ++++++++++++------
1 files changed, 12 insertions(+), 6 deletions(-)
diffs (43 lines):
diff -r a00be4d7ba9d -r f2a3ff1a2afa usr.bin/make/unit-tests/hanoi-include.mk
--- a/usr.bin/make/unit-tests/hanoi-include.mk Thu Jan 19 21:33:06 2023 +0000
+++ b/usr.bin/make/unit-tests/hanoi-include.mk Thu Jan 19 22:48:42 2023 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: hanoi-include.mk,v 1.3 2022/05/08 07:27:50 rillig Exp $
+# $NetBSD: hanoi-include.mk,v 1.4 2023/01/19 22:48:42 rillig Exp $
#
# Implements the Towers of Hanoi puzzle, demonstrating a bunch of more or less
# useful programming techniques:
@@ -21,22 +21,28 @@
VIA?= B # ... via this stack ...
TO?= C # ... to this stack.
-.if $N == 1
+# Since make has no built-in arithmetic functions, convert N to a list of
+# words and use the built-in word counting instead.
+.if ${N:[#]} == 1
+N:= count ${:U:${:Urange=$N}} # 'count' + one word for every disk
+.endif
+
+.if ${N:[#]} == 2
. for from to in ${FROM} ${TO}
all::
@echo "Move the upper disk from stack ${from} to stack ${to}."
. endfor
.else
-_:= ${N::!=expr $N - 1} ${TMP::=${VIA}} ${VIA::=${TO}} ${TO::=${TMP}}
+_:= ${N::=${N:[1..-2]}} ${TMP::=${VIA}} ${VIA::=${TO}} ${TO::=${TMP}}
. include "${.PARSEDIR}/${.PARSEFILE}"
-_:= ${N::!=expr $N + 1} ${TMP::=${VIA}} ${VIA::=${TO}} ${TO::=${TMP}}
+_:= ${N::+=D} ${TMP::=${VIA}} ${VIA::=${TO}} ${TO::=${TMP}}
. for from to in ${FROM} ${TO}
all::
@echo "Move the upper disk from stack ${from} to stack ${to}."
. endfor
-_:= ${N::!=expr $N - 1} ${TMP::=${VIA}} ${VIA::=${FROM}} ${FROM::=${TMP}}
+_:= ${N::=${N:[1..-2]}} ${TMP::=${VIA}} ${VIA::=${FROM}} ${FROM::=${TMP}}
. include "${.PARSEDIR}/${.PARSEFILE}"
-_:= ${N::!=expr $N + 1} ${TMP::=${VIA}} ${VIA::=${FROM}} ${FROM::=${TMP}}
+_:= ${N::+=D} ${TMP::=${VIA}} ${VIA::=${FROM}} ${FROM::=${TMP}}
.endif
Home |
Main Index |
Thread Index |
Old Index