#!/bin/sh
# Count non-blank lines in all .rad files, skipping tests.

dir="${1:-.}"

if [ ! -d "$dir" ]; then
  echo "Error: Directory '$dir' does not exist"
  exit 1
fi

echo "Counting non-blank lines in .rad files in: $dir"
echo "-------------------------------------------"

total=0
for file in $(find "$dir" -name "*.rad" -type f -not -path "*/tests/*" -not -name "tests.rad" | sort); do
  if [ -f "$file" ]; then
    count=$(grep -v '^[[:space:]]*$' "$file" | wc -l)
    total=$((total + count))
    printf "%6d  %s\n" "$count" "$file"
  fi
done

echo "-------------------------------------------"
printf "%6d  TOTAL\n" "$total"
