fix shellcheck error in 2018/burton2/unob.sh

This commit is contained in:
Landon Curt Noll committed 2024-03-10 23:09:14 -07:00
1 parent b7ee3e8686
commit 610a4135e5
1 file changed
+21 -14
+21 -14
View File
@@ -8,9 +8,9 @@
# an automated process. Or just enjoy a significant help in # an automated process. Or just enjoy a significant help in
# reading obfuscated C code! # reading obfuscated C code!
: ${PROG:=./prog} # PROG=tac ./unob.sh prog.c : "${PROG:=./prog}" # PROG=tac ./unob.sh prog.c
: ${KW:=c11} # KW=ioccc.kw.freq ./unob.sh prog.c : "${KW:=c11}" # KW=ioccc.kw.freq ./unob.sh prog.c
: ${DEF:=} # DEF="-DW=\\\"kandr2\\\" -DU=\\\"usage\ string\\\"" ./unob.sh -p prog.c : "${DEF:=}" # DEF="-DW=\\\"kandr2\\\" -DU=\\\"usage\ string\\\"" ./unob.sh -p prog.c
# optionally preprocess up to 3 times to handle #ifdef X #define Y # optionally preprocess up to 3 times to handle #ifdef X #define Y
# unob prog.c # nonce # unob prog.c # nonce
@@ -20,34 +20,41 @@
# unob -p -p -p -p prog.c # yer out # unob -p -p -p -p prog.c # yer out
function pp { function pp {
cpp2=cat cpp2="cat"
cpp3=cat cpp3="cat"
if [ "x$1" == "x-p" ]; then if [[ "$1" == "-p" ]]; then
shift shift
if [ "x$1" == "x-p" ]; then if [[ "$1" == "-p" ]]; then
cpp2="cpp -E" cpp2="cpp -E"
shift shift
fi fi
if [ "x$1" == "x-p" ]; then if [[ "$1" == "-p" ]]; then
cpp3="cpp -E" cpp3="cpp -E"
shift shift
fi fi
cat $* | cat "$@" |
sed 's/# *include/##include/' | sed 's/# *include/##include/' |
eval cpp -E "$DEF" | eval cpp -E "$DEF" |
eval $cpp2 | eval "$cpp2" |
eval $cpp3 | eval "$cpp3" |
sed 's/^#[^#].*$//' | sed 's/^#[^#].*$//' |
sed 's/##inc/#inc/' sed 's/##inc/#inc/'
else else
cat $* cat "$@"
fi fi
} }
# For SC2016, we do want to single quote the leading part of the script,
# and we want $KW to be double quoted within the awk script.
# Unfortunately, shellcheck does not understand the "'"-ing.
#
# SC2016 (info): Expressions don't expand in single quotes, use double quotes for that.
# https://www.shellcheck.net/wiki/SC2016
# shellcheck disable=SC2016
script=' script='
BEGIN { BEGIN {
last=nl="\n"; last=nl="\n";
f="'$KW'"; while(getline <f > 0) ++kw[$0]; close(f); f="'"$KW"'"; while(getline <f > 0) ++kw[$0]; close(f);
if (length(kw) == 0) { if (length(kw) == 0) {
print "cannot find",f "; check KW environment variable" | "cat 1>&2" print "cannot find",f "; check KW environment variable" | "cat 1>&2"
exit exit
@@ -108,4 +115,4 @@ tern && /^:/ { newline(); show($0); --tern; --n; next }
{ show($0) } { show($0) }
' '
pp $* | $PROG -t | ./tokenfix.sh | awk "$script" # sed 's/""//g' pp "$@" | "$PROG" -t | ./tokenfix.sh | awk "$script" # sed 's/""//g'