#! /usr/bin/perl -w # # Determines if a file is encoded in US-ASCII # (c) 2000 Hugo Haas # # License: GPL Version 2. See: http://www.gnu.org/copyleft/gpl.html use strict; if ($#ARGV < 0) { print STDERR "Usage: $0 [-q] files\n"; print STDERR "\t-q stops the program as soon as the result is known\n"; } my $quick_test = 0; if ($ARGV[0] eq '-q') { shift(@ARGV); $quick_test = 1; } foreach (@ARGV) { print($_.': '); if (! open(FILE, $_)) { print "ERROR $!\n"; next; } my $c; my $l = 1; my $us_ascii = 1; while (sysread(FILE, $c, 1)) { my $o = ord($c); if ($o == 10) { $l++; next; } if ($o > 127) { $us_ascii = 0; last if ($quick_test); print "$c-$o/$l "; } } close(FILE); if ($us_ascii) { print 'OK'; } else { print 'FAILED'; } print "\n"; }