From 4f9df5435fbdaaea9ce8363bc0133f60916f5518 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Thu, 2 Apr 2020 11:57:26 +0900 Subject: [PATCH] Add quick fixes for Bash scripts --- shellmetrics | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/shellmetrics b/shellmetrics index f3bc277..4b5604d 100755 --- a/shellmetrics +++ b/shellmetrics @@ -151,7 +151,12 @@ pretty() { while [ "$i" -lt "$1" ] && i=$((i + 1)); do echo 'shellmetrics_wrapper() {' done - sed "s/\([^\$'\"()]\)\( *()\)/\1_L$MARK\2/g" \ + sed " + s/\([^[:space:]\$'\"();&|<>=@!*?+]\)\( *()\)/\1_L$MARK\2/g + s/^[[:space:]]*function[[:space:]]\{1,\}[^[:space:]\$'\"();&|<>]\{1,\}/&_L$MARK/g + s/[;&|(][[:space:]]*function[[:space:]]\{1,\}[^[:space:]\$'\"();&|<>]\{1,\}/&_L$MARK/g + s/_L${MARK}_L${MARK}/_L${MARK}/g + " \ | awk "{i++; gsub(/$MARK/,i); print}" while [ "$i" -gt 0 ] && i=$((i - 1)); do echo '}' @@ -262,7 +267,8 @@ analyze() { case $mark in (*"f"*) func=${line%"()"*} && func=${func%" "} && func=${func##*[$SP]} - lineno=${func##*_L} && func=${func%_L*}:$lineno + lineno=${func##*_L} + [ "$lineno" != "$func" ] && func=${func%_L*}:$lineno push_array indent func ccn lloc ccn=1 lloc=0 esac