#!/usr/bin/perl

require "jcode.pl";

if ($#ARGV < 1){
    die "Usage: msgchecker.pl [ASCII|euc|sjis|jis] file\n";
}

$logcode = $ARGV[0];   # 'ASCII', 'euc', 'sjis', 'jis'.
$msg     = $ARGV[1];

if (!$logcode){
    $logcode = 'ASCII';
}

open(MSG, "<$msg")
        || die "$msg: cannot find log message.";

while (<MSG>) {
    undef $code;
    $code = &jcode::getcode(\$_);
    if ($code eq 'binary') {
        die "log message is $code , Please write log message ASCII.\n"
            if ($logcode eq 'ASCII');
        die "log message is $code , Please write log message ASCII or $logcode .\n";
    } elsif (! $code ) {
	next;
    } elsif ($code eq $logcode) {
	next;
    } else {
        die "log message is $code , Please write log message ASCII.\n"
            if ($logcode eq 'ASCII');
        die "log message is $code , Please write log message ASCII or $logcode .\n";
    }
}

close(MSG);

exit 0;
