From 8f4f9a650ab7dc7f054e41d65acd909d1afc4cd6 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Thu, 7 Dec 2023 05:26:52 -0800 Subject: [PATCH] Improve how to redefine size in 1985/shapiro Now one can just do: make clobber SIZE=5 alt for example. This is done through a Makefile variable. --- 1985/shapiro/Makefile | 7 +++++-- 1985/shapiro/README.md | 4 ++-- 1985/shapiro/try.alt.sh | 5 +++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/1985/shapiro/Makefile b/1985/shapiro/Makefile index b25f0e5b2..f2f18b470 100644 --- a/1985/shapiro/Makefile +++ b/1985/shapiro/Makefile @@ -58,7 +58,7 @@ ARCH= # Defines that are needed to compile # -CDEFINE= -DC=39 +CDEFINE= -DC=${SIZE} # Include files that are needed to compile # @@ -136,8 +136,11 @@ ${PROG}: ${PROG}.c alt: data ${ALT_TARGET} @${TRUE} +# variable to control size of maze for alt code +SIZE=39 + ${PROG}.alt: ${PROG}.alt.c - ${CC} ${CFLAGS} $< -o $@ ${LDFLAGS} + ${CC} ${CFLAGS} -DC=${SIZE} $< -o $@ ${LDFLAGS} # data files # diff --git a/1985/shapiro/README.md b/1985/shapiro/README.md index 2471841c0..ab23af709 100644 --- a/1985/shapiro/README.md +++ b/1985/shapiro/README.md @@ -5,7 +5,7 @@ make all ``` There is alternate code which allows one to change the size of the maze. See -[alternate code](#alternate-code) below. +[Alternate code](#alternate-code) below. ### To run: @@ -32,7 +32,7 @@ make alt If you wish to change the value you can do it like: ```sh -make clobber CDEFINE="-DC=5" alt +make clobber SIZE=5 alt ``` Note that if it is not a number then obviously there will be a compilation diff --git a/1985/shapiro/try.alt.sh b/1985/shapiro/try.alt.sh index b5cbfdc43..6ab48c125 100755 --- a/1985/shapiro/try.alt.sh +++ b/1985/shapiro/try.alt.sh @@ -25,7 +25,8 @@ while ((i < 5)); do fi read -r -n 1 -p "Press any key to set to $C: " - make clobber CC="$CC" CDEFINE="-DC=$C" alt >/dev/null + echo 1>&2 + make clobber CC="$CC" SIZE="$C" alt >/dev/null ./shapiro.alt ((i++)) done @@ -39,7 +40,7 @@ while :; do # ^-- SC2143 (style): Use grep -q instead of comparing output with [ -n .. ]. # shellcheck disable=SC2143 if [[ $(echo "$REPLY" | grep -E '\<[0-9]+\>') ]]; then - make clobber CC="$CC" CDEFINE="-DC=\"$REPLY\"" alt >/dev/null + make clobber CC="$CC" SIZE="$REPLY" alt >/dev/null ./shapiro.alt else exit 0