#! /bin/bash
#------------------------------------------------------------------------------
#$Author: saulius $
#$Date: 2021-05-04 04:40:17 +0000 (Tue, 04 May 2021) $
#$Revision: 8927 $
#$URL: file:///home/saulius/svn-repositories/paskaitos/VU/software/assignment-evaluation/trunk/scripts/do-check--comments $
#------------------------------------------------------------------------------
#*
# Check that the project executable files have comments.
#**

set -ue
## set -x

DIRECTORY="$1"

ID='$Id: do-check--comments 8927 2021-05-04 04:40:17Z saulius $'

cd "${DIRECTORY}"

COUNT=0

find . \
     -name '*~' -prune -o \
     -name .svn -prune -o \
     -name .git -prune -o \
     -type f -perm /111 \
     -print \
| grep -ivE '(test|tests|testai)/.*\.sh$' \
| sort \
| while read FILE
do
    if head -1 "${FILE}" | grep -q '^#!' > /dev/null 2>&1
    then
        if [ $(grep -P '^\s*#' "${FILE}" | wc -l) -le 3 ]
        then
    
cat <<EOF
-- [AUTO;INTERFACE;$(echo $ID | sed 's/\$//g')]

   Jūsų projekto programoje '${FILE}' reikia daugiau komentarų
   (-5 balai);

EOF

        fi
    fi
done;

## echo $0: COUNT=$COUNT >&2
