#!/usr/bin/perl

require "jcode.pl";
$correct_default = 'euc';  # 'euc' or 'sjis' or 'jis'

if ($#ARGV < 2){
    die "Usage: kanjichecker.pl [euc|sjis|jis] dir filename\n";
}

$current = $ARGV[0] || $current_default;
$dir     = $ARGV[1];
$file    = $ARGV[2];

# if file was removed already, check isn't need.
unless (-f $file) {
    exit 0;
}

open(FILE, "<$file")
    || die "$file: cannot open for reading.";

while (<FILE>) {
    undef $code;
    $code = &jcode::getcode(\$_);
    if ($code eq 'binary') {
        exit 0;
    } elsif (! $code ) {
        next;
    } elsif ($code eq $current) {
        next;
    } else {
        die "$file include $code, current code is $current.\n";
    }
}

exit 0;
