From 760ee403fec8ab01deb9b6cad3ce3d84fd2ee85f Mon Sep 17 00:00:00 2001 From: Andrew Wood Date: Mon, 24 Jul 2023 22:29:18 +0100 Subject: [PATCH] Variable name modernisation, and shellcheck corrections. --- autoconf/scripts/index.sh | 131 +++++++++++++++++++++----------------- 1 file changed, 74 insertions(+), 57 deletions(-) diff --git a/autoconf/scripts/index.sh b/autoconf/scripts/index.sh index 6a9845f..b4164b6 100755 --- a/autoconf/scripts/index.sh +++ b/autoconf/scripts/index.sh @@ -15,11 +15,15 @@ # Requires ctags and cproto. # -command -v "ctags" || { echo "${0##*/}: ctags: command not found" 1>&2; exit 1; } -command -v "cproto" || { echo "${0##*/}: cproto: command not found" 1>&2; exit 1; } +command -v "ctags" >/dev/null 2>&1 || { echo "${0##*/}: ctags: command not found" 1>&2; exit 1; } +command -v "cproto" >/dev/null 2>&1 || { echo "${0##*/}: cproto: command not found" 1>&2; exit 1; } -OFFS=$1 +linkPrefix=$1 +test -n "${linkPrefix}" || linkPrefix="." +# Add "/" to the link prefix, and empty it entirely if it ends up just "./". +linkPrefix=$(echo "${linkPrefix}" | sed 's,/*$,,') +test "$linkPrefix" = "." && linkPrefix="" || linkPrefix="${linkPrefix}/" # Convert the given string to HTML-escaped values (<, >, & escaped) on # stdout. @@ -38,14 +42,18 @@ html_safebr () { | sed -e 's|&|\&|g;s|<|\<|g;s|>|\>|g;s/$/
/' } -ALLFILES=$(find . -name '*~' -prune -o -type f -name '*.c' \ - -exec grep -FL '!NOINDEX' /dev/null '{}' ';') +allEligibleFiles=$( + find . -name '*~' -prune -o -type f -name '*.c' \ + -exec grep -FL '!NOINDEX' /dev/null '{}' ';' +) -CTAGDATA=$(echo "$ALLFILES" \ - | ctags -nRf- -L- --c-types=f \ - | sed 's/ .\// /;s/;" .*$//') +ctagsOutput=$( + echo "${allEligibleFiles}" \ + | ctags -nRf- -L- --c-types=f \ + | sed 's/ .\// /;s/;" .*$//' +) -FILELIST=$(echo "$CTAGDATA" | cut -d ' ' -f 2 | sort | uniq) +sourceFiles=$(echo "${ctagsOutput}" | cut -d ' ' -f 2 | sort | uniq) echo '' echo 'Source Code Index' @@ -59,39 +67,43 @@ echo '

' echo '

File Listing

' echo '

' -for FILE in $FILELIST; do +for sourceFile in ${sourceFiles}; do - DIR=$(dirname $FILE) - FUNCDEFS=$(cproto -f1 -I. -Isrc/include -I$DIR $FILE 2>/dev/null \ - | sed -n 's/^.*[ *]\([^ *(]*\)(.*$/\1/p') - FILEHEAD="$(sed -n -e \ - '1,/\*\//{/\/\*/,/\*\//{s/^[\/ *]//;s/^\*[\/]*//;p;};}' \ - < $FILE)" - FILESHORTDESC=$(echo "$FILEHEAD" | sed -n '1,/^ *$/{/^ *[^ ]*/p;}') - FILELONGDESC=$(echo "$FILEHEAD" | sed '1,/^ *$/d') + sourceDir="${sourceFile##*/}" + test "${sourceDir}" = "${sourceFile}" && sourceDir="." + functionPrototypes=$( + cproto -f1 -I. -Isrc/include -I"${sourceDir}" "${sourceFile}" 2>/dev/null \ + | sed -n 's/^.*[ *]\([^ *(]*\)(.*$/\1/p' + ) + fileHeaderComment=$( + sed -n -e '1,/\*\//{/\/\*/,/\*\//{s/^[\/ *]//;s/^\*[\/]*//;p;};}' \ + < "${sourceFile}" + ) + fileShortDescription=$(echo "${fileHeaderComment}" | sed -n '1,/^ *$/{/^ *[^ ]*/p;}') + fileLongDescription=$(echo "${fileHeaderComment}" | sed '1,/^ *$/d') echo '


' echo '

' echo '' + echo ''"${sourceFile}"'' echo '' - echo '' + echo '' echo '
' - echo ''"$FILE"' - '$(html_safe "$FILESHORTDESC")''"$(html_safe "${fileShortDescription}")"'

' - echo '

[View File]

' + echo '

[View File]

' echo '

' - echo "$(html_safebr "$FILELONGDESC")" + html_safebr "${fileLongDescription}" echo '

' - if [ -n "$FUNCDEFS" ]; then + if [ -n "${functionPrototypes}" ]; then echo '

Functions defined:

' echo '

' fi @@ -104,40 +116,45 @@ done echo '

Function Listing

' echo '

' -echo "$CTAGDATA" | while read FUNC FILE LINENUM REST; do +# shellcheck disable=SC2034 +echo "${ctagsOutput}" | while read -r functionName sourceFile sourceLineNo restOfLine; do - FUNCDEF=$(sed -n "$LINENUM,/{/p" < $FILE \ - | tr '\n' ' ' \ - | tr -d '{') + functionPrototype=$( + sed -n "${sourceLineNo},/{/p" < "${sourceFile}" \ + | tr '\n' ' ' \ + | tr -d '{' + ) - LASTCOMLINE=$(sed -n '1,'"$LINENUM"'{/\/\*/=;}' < $FILE | sed -n '$p') - [ -z "$LASTCOMLINE" ] && LASTCOMLINE=1 - LASTENDFUNCLINE=$(sed -n '1,'"$LINENUM"'{/}/=;}' < $FILE | sed -n '$p') - [ -z "$LASTENDFUNCLINE" ] && LASTENDFUNCLINE=1 - FUNCHEAD="$(sed -n -e \ - "$LASTCOMLINE,"'/\*\//{h;s/^[\/ *]//;s/^\*[\/]*//;p;x;/\*\//q;}' \ - < $FILE)" - [ "$LASTCOMLINE" -le "$LASTENDFUNCLINE" ] && FUNCHEAD="" + lastCommentOpenLineNo=$(sed -n '1,'"${sourceLineNo}"'{/\/\*/=;}' < "${sourceFile}" | sed -n '$p') + test -n "${lastCommentOpenLineNo}" || lastCommentOpenLineNo=1 + lastCommentCloseLineNo=$(sed -n '1,'"${sourceLineNo}"'{/}/=;}' < "${sourceFile}" | sed -n '$p') + test -n "${lastCommentCloseLineNo}" || lastCommentCloseLineNo=1 + functionHeaderComment=$( + sed -n -e \ + "${lastCommentOpenLineNo},"'/\*\//{h;s/^[\/ *]//;s/^\*[\/]*//;p;x;/\*\//q;}' \ + < "${sourceFile}" + ) + test "${lastCommentOpenLineNo}" -le "${lastCommentCloseLineNo}" && functionHeaderComment="" echo '


' echo '

' - echo -n '' - echo -n "$FUNC"' ' - echo -n '[' - echo "$FILE"']' + echo ''"${functionName}"'' \ + '['"${sourceFile}"']' echo '

' - echo '

'"$(html_safe "$FUNCDEF")"'

' + echo '

'"$(html_safe "${functionPrototype}")"'

' echo '

' - echo "$(html_safebr "$FUNCHEAD")" + html_safebr "${functionHeaderComment}" echo '

' echo '

[' @@ -148,22 +165,22 @@ done echo '

To Do Listing

' echo '