#! /bin/bash -e

# Run this on a cleaned source to verify that no characters anywhere appear
# but these: ascii graphables; space; unix newline.  Allow however a
# few appropriate exceptions such as leading tabs in Makefiles.

D="$( dirname $0 )"
cd "$D/../.."
STATUS=0
for A in $( find . ); do
    if [ "$A" != './debian/helper/dict' ] && [ "$A" != './debian/changelog' ]; then
        B="$( basename $A )";
        IS_MAKEFILE=0
        if { echo "$B" | sed -nre '/^(Makefile(-.*)?|rules)$/q0;q1'; }; then
            IS_MAKEFILE=1
        fi
        A="$A" IS_MAKEFILE="$IS_MAKEFILE" perl <"$A" \
            -e 'use warnings;' \
            -e 'use strict;' \
            -e 'use integer;' \
            -e 'my $status = 0;' \
            -e 'while (<>) {' \
            -e '    chomp;' \
            -e '    s/^\t// if $ENV{IS_MAKEFILE};' \
            -e '    if (/[^\040-\176\n]/) {' \
            -e '        $status = 1;' \
            -e '        warn "$ENV{A}:$.:$_\n";' \
            -e '    }' \
            -e '}' \
            -e 'exit $status;' \
            || STATUS=1
    fi
done
exit $STATUS

