#!/usr/bin/perl
#
# force-euc.pl by Ishiwatari Masaki, 2004
#   original is forcesjis.pl by TOYODA Eizi, ????


$BinaryPattern = '\.(BMP|CHM|CUR|DAT|DLL|DOC|EXE|GIF|ICO|JPG|LIB|PNG|WAV)$';

for $arg (@ARGV) {
	if (-d $arg) {
	#	chdir($arg) || warn("cannot chdir to $arg ($!)\n");
		next;
	}
	if ($arg =~ m/$BinaryPattern/i) {
		warn("filename $arg seems to be binary: check skipped\n");
		next;
	}
	open(FILE, $arg) || (warn("cannot open $arg ($!)\n"), next);
	$ARGV = $arg;
	while (<FILE>) {
		for ($i = 0; $i < length($_); $i++) {
			$c = substr($_, $i, 1);
			if ($c =~ /[\t\n\r\x20-\x7E\xA1-\xFE]/) {
				next;
			}
			&barf('Broken EUC', $_);
		}
	}
}
exit 0;

sub barf {
	print STDERR "$ARGV: " if $ARGV ne '-';
	warn @_, ". Only EUC-JP or ASCII allowed.\n";
	exit 1;
}
