boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

count-lines.sh (818B)


      1 #!/bin/sh
      2 ## count-lines.sh — line counts for the core sources.
      3 ##
      4 ## Skips ZERO/comment/blank lines per the existing cloc convention.
      5 ## Pass file paths as arguments, or pass none to read from stdin
      6 ## (one path per line). Prints `<count>  <path>` per file plus a
      7 ## trailing total.
      8 ##
      9 ## Usage:
     10 ##   sh tools/count-lines.sh file1 file2 …
     11 ##   printf '%s\n' file1 file2 | sh tools/count-lines.sh
     12 
     13 set -eu
     14 
     15 if [ "$#" -gt 0 ]; then
     16     FILES="$*"
     17 else
     18     FILES=$(cat)
     19 fi
     20 
     21 total=0
     22 for f in $FILES; do
     23     [ -e "$f" ] || { echo "count-lines: missing $f" >&2; exit 1; }
     24     n=$(grep -v "^ZERO.*" "$f" \
     25         | grep -v "^[[:space:]]*#.*" \
     26         | grep -v "^[[:space:]]*;.*" \
     27         | grep -v "^$" \
     28         | wc -l)
     29     printf '%6d  %s\n' "$n" "$f"
     30     total=$((total + n))
     31 done
     32 printf '%6d  total\n' "$total"