use explicit markers (comments) for the bsearch table checking, simplifies the scripts and makes them more robust too :)

This commit is contained in:
mrdudz
2025-06-09 21:48:20 +02:00
parent 717e32ba6a
commit aaa1058d32
22 changed files with 165 additions and 124 deletions

View File

@@ -1,42 +1,61 @@
#! /bin/bash
OLDCWD=`pwd`
SCRIPT_PATH=`dirname $0`
CHECK_FILE=../../src/cc65/codeopt.c
CHECK_DIR=../../src
SORT_OPT=-u
grep "^static OptFunc " $CHECK_FILE | \
sed -e 's:.*"\(.*\)",.*:\1:g' > .a.tmp
function checkarray
{
CHECK_FILE="$1"
START="\\/\\* BEGIN DECL SORTED_CODEOPT.SH \\*\\/"
END="\\/\\* END DECL SORTED_CODEOPT.SH \\*\\/"
if [[ -z $(grep '[^[:space:]]' .a.tmp) ]] ; then
echo "error: OptFunc table is empty"
exit -1
fi
awk '/'"$START"'/{flag=1; count++; next} /'"$END"'/{flag=0;} flag {print count,"##",$0}' "$CHECK_FILE" | \
sed -e 's:\(.*##\).*"\(.*\)",.*:\1\2:g' > .a.tmp
LC_COLLATE=C sort $SORT_OPT .a.tmp > .b.tmp
if [[ -z $(grep '[^[:space:]]' .a.tmp) ]] ; then
echo "error: "$1" table is empty"
rm -rf .a.tmp
exit -1
fi
if cmp --silent -- .a.tmp .b.tmp; then
echo "static OptFunc definitions OK"
else
echo "error: static OptFunc definitions are not sorted."
diff -y .a.tmp .b.tmp
exit -1
fi
LC_COLLATE=C sort $SORT_OPT .a.tmp > .b.tmp
awk '/static OptFunc\* OptFuncs\[\] = {/{flag=1;next}/}/{flag=0}flag' $CHECK_FILE | \
sed -e 's:.*&D\(.*\),:\1:g' > .a.tmp
if cmp --silent -- .a.tmp .b.tmp; then
echo ""$1" decls OK"
else
echo "error: "$1" decls are not sorted."
diff -y .a.tmp .b.tmp
rm -rf .a.tmp .b.tmp
exit -1
fi
if [[ -z $(grep '[^[:space:]]' .a.tmp) ]] ; then
echo "error: OptFuncs table is empty"
exit -1
fi
START="\\/\\* BEGIN SORTED_CODEOPT.SH \\*\\/"
END="\\/\\* END SORTED_CODEOPT.SH \\*\\/"
awk '/'"$START"'/{flag=1; count++; next} /'"$END"'/{flag=0;} flag {print count,"##",$0}' "$CHECK_FILE" | \
sed -e 's:\(.*##\).*&D\(.*\),.*:\1\2:g' > .a.tmp
if cmp --silent -- .a.tmp .b.tmp; then
echo "static OptFuncs* OptFuncs[] definitions OK"
else
echo "error: static OptFuncs* OptFuncs[] definitions are not sorted."
diff -y .a.tmp .b.tmp
exit -1
fi
if [[ -z $(grep '[^[:space:]]' .a.tmp) ]] ; then
echo "error: "$1" table is empty"
rm -rf .a.tmp
exit -1
fi
rm -rf .a.tmp .b.tmp
if cmp --silent -- .a.tmp .b.tmp; then
echo ""$1" tables OK"
else
echo "error: "$1" tables are not sorted."
diff -y .a.tmp .b.tmp
rm -rf .a.tmp .b.tmp
exit -1
fi
rm -rf .a.tmp .b.tmp
}
for N in `grep -rl "BEGIN DECL SORTED_CODEOPT.SH" "$CHECK_DIR"`; do
checkarray $N
done