Module Name:    src
Committed By:   rillig
Date:           Thu Jan 19 22:48:42 UTC 2023

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

Log Message:
tests/make: remove dependency on expr(1) from a test

This saves 124 calls to the shell.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/hanoi-include.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/hanoi-include.mk
diff -u src/usr.bin/make/unit-tests/hanoi-include.mk:1.3 src/usr.bin/make/unit-tests/hanoi-include.mk:1.4
--- src/usr.bin/make/unit-tests/hanoi-include.mk:1.3	Sun May  8 07:27:50 2022
+++ src/usr.bin/make/unit-tests/hanoi-include.mk	Thu Jan 19 22:48:42 2023
@@ -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 @@ FROM?=	A			# ... from this stack ...
 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

Reply via email to