#!/bin/bash FILES=(`find . -name "*.hs" -o -name "*.lhs" -o -name "*.hsc"`) if [ "$1" = "-v" ] then VERBOSE=1 else VERBOSE=0 fi TAB=`printf '\t'` SPACES4=" " SPACES8=" " NUM_FILES=0 FILES_SOME_LINES_START_TAB=0 FILES_SOME_LINES_START_4SPACES=0 FILES_SOME_LINES_START_8SPACES=0 for F in ${FILES[@]} do if [ "$VERBOSE" = 1 ] then echo $F fi NUM_FILES=$(($NUM_FILES + 1)) if grep -q "^$TAB" $F then FILES_SOME_LINES_START_TAB=$(($FILES_SOME_LINES_START_TAB + 1)) fi if grep -q "^$SPACES4" $F then FILES_SOME_LINES_START_4SPACES=$(($FILES_SOME_LINES_START_4SPACES + 1)) fi if grep -q "^$SPACES8" $F then FILES_SOME_LINES_START_8SPACES=$(($FILES_SOME_LINES_START_8SPACES + 1)) fi done LINES_NOT_BLANK=`grep "." ${FILES[@]} | wc -l` # LINES_START_WHITE=`grep -c "^\\($TAB\\| \\)" ${FILES[@]}` LINES_START_WHITE=`grep "^[[:space:]]" ${FILES[@]} | wc -l` LINES_START_TAB=`grep "^$TAB" ${FILES[@]} | wc -l` LINES_START_4SPACES=`grep "^$SPACES4" ${FILES[@]} | wc -l` LINES_START_8SPACES=`grep "^$SPACES8" ${FILES[@]} | wc -l` LINES_TAB_AFTER_SPACE=`grep "^[[:space:]]* $TAB" ${FILES[@]} | wc -l` LINES_TAB_AFTER_NONWHITE=`grep "^.*[^[:space:]].*$TAB" ${FILES[@]} | wc -l` echo "Total files: "\ $NUM_FILES echo "Files where some lines start tab: "\ $FILES_SOME_LINES_START_TAB echo "Files where some lines start 4 spaces: "\ $FILES_SOME_LINES_START_4SPACES echo "Files where some lines start 8 spaces: "\ $FILES_SOME_LINES_START_8SPACES echo "Percentage files where some lines start tab: "\ $((100 * $FILES_SOME_LINES_START_TAB / $NUM_FILES))% echo "Percentage files where some lines start 4 spaces: "\ $((100 * $FILES_SOME_LINES_START_4SPACES / $NUM_FILES))% echo "Percentage files where some lines start 8 spaces: "\ $((100 * $FILES_SOME_LINES_START_8SPACES / $NUM_FILES))% echo echo "Non-blank lines: "\ $LINES_NOT_BLANK echo "Lines that start white (white lines): "\ $LINES_START_WHITE echo "Lines that start tab: "\ $LINES_START_TAB echo "Lines that start 4 spaces: "\ $LINES_START_4SPACES echo "Lines that start 8 spaces: "\ $LINES_START_8SPACES echo "Percentage non-blank lines start tab: "\ $((100 * $LINES_START_TAB / $LINES_NOT_BLANK))% echo "Percentage non-blank lines start 4 spaces: "\ $((100 * $LINES_START_4SPACES / $LINES_NOT_BLANK))% echo "Percentage non-blank lines start 8 spaces: "\ $((100 * $LINES_START_8SPACES / $LINES_NOT_BLANK))% echo "Percentage white lines start tab: "\ $((100 * $LINES_START_TAB / $LINES_START_WHITE))% echo "Percentage white lines start 4 spaces: "\ $((100 * $LINES_START_4SPACES / $LINES_START_WHITE))% echo "Percentage white lines start 8 spaces: "\ $((100 * $LINES_START_8SPACES / $LINES_START_WHITE))% echo echo "Lines that have a tab after a space: "\ $LINES_TAB_AFTER_SPACE echo "Lines that have a tab after a non-white character: "\ $LINES_TAB_AFTER_NONWHITE echo "Percentage non-blank lines have a tab after a space: "\ $((100 * $LINES_TAB_AFTER_SPACE / $LINES_NOT_BLANK))% echo "Percentage non-blank lines have a tab after a non-white character: "\ $((100 * $LINES_TAB_AFTER_NONWHITE / $LINES_NOT_BLANK))%