#!/usr/new/bin/tclsh8.1
# eucjis
# Kazuro FURUKAWA <kazuro.furukawa@kek.jp>, apr.24.1999. 
#
# this script tests character-set conversions mentioned 
# in the  message from scott stanton

set usage "eucjis (-eucjjis|-jiseuc) (-read|-gets) {input-file} {output-file}"

foreach {eucjis read input output} $argv {}
if {$output == ""} { puts stderr $usage ; exit 1 }
set infile [open $input r]
set outfile [open $output w]
switch -- $eucjis {
    -eucjis {
	fconfigure $infile -encoding euc-jp
	fconfigure $outfile -encoding iso2022-jp
    } -jiseuc {
	fconfigure $infile -encoding iso2022-jp
	fconfigure $outfile -encoding euc-jp
    } default { puts stderr $usage ; exit 1 }
}
switch -- $read {
    -read {
	puts -nonewline $outfile [read $infile]
    } -gets {
	while {[gets $infile line] != -1} {
	    puts $outfile $line
	}
    } default { puts stderr $usage ; exit 1 }
}
close $infile ; close $outfile
