From bf73be6b3514236a084706491505ea55f78f36bc Mon Sep 17 00:00:00 2001 From: terminalforlife Date: Wed, 18 Nov 2020 14:26:50 +0000 Subject: [PATCH] Look instead for '# cheat.sh: ' on any line This is in regards to a request by Chubin on #134. I didn't use grep(1), because it wound up being a lot slower than my method. Relying on tools like that isn't always the best choice, which is why I often just write in pure-shell, and have done for a couple of years now. There's a time and a place for those external tools, but I feel this was not it. Tested and worked well. I've actually seen no noteworthy slowdowns, - despite pre-processing the files -- YMMV. --- tests/lenchk | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/tests/lenchk b/tests/lenchk index 24f3f2e..74a65f6 100755 --- a/tests/lenchk +++ b/tests/lenchk @@ -148,20 +148,31 @@ Main(){ for File in "${Dirs[@]}"; { [ -f "$File" ] || continue + # Per chubin's desire to have an "in-bound flag"; see #134. + if [ "$NoLenChkLine" != 'True' ]; then + SkipFile='False' + + readarray -t Buffer < "$File" + for BufferLine in "${Buffer[@]}"; { + if [[ $BufferLine == '# cheat.sh: '* ]]; then + CheatLine=${BufferLine#'# cheat.sh: '} + IFS=',' read -a Fields <<< "$CheatLine" + for Field in "${Fields[@]}"; { + [ "$Field" == "$Progrm=disable" ] && SkipFile='True' + } + fi + } + + [ "$SkipFile" == 'True' ] && continue + fi + # If the current file matches one which is whitelisted, skip it. for CurWL in "${Whitelisted[@]}"; { [ "$File" == "$CurWL" ] && continue 2 } - # Per chubin's desire to have an "in-bound flag"; see #134 for info. - if [ "$NoLenChkLine" != 'True' ]; then - read Buffer < "$File" - [ "$Buffer" == 'lenchk=disable' ] && continue - fi - - HaveBeenHit='False' LineNum=0 - + HaveBeenHit='False' while read; do let LineNum++