#!/usr/bin/perl
#
# msgchecker.pl by Morikawa Yasuhiro, 2004

use Jcode;

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

$logcode = $ARGV[0];   # 'ascii', 'utf8', '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;
    } elsif ($code eq 'ascii') {
   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;
