
# This script copies the contents of the file "test.in" to
# the file "test.out"
#
# Good test.in files can be generated using the pbmplus package:
#
#    pgmramp -rect 640 480 | pnmdepth 255 > test.in
#    pgmramp -tb   256 16  | pnmdepth 255 > test.in
#
# these will have all 256 possible character values in them
#


# save typing "bin_" before each command
source binrename.tcl

# open the files in binary i/o mode
set fdi [open test.in rb]
set fdo [open test.out wb]

# copy the file a line at a time
while {[gets $fdi line] != -1} {
# to test the str2arr and arr2str commands, uncomment the next 6 lines
#	if [string length $line] {
#		set ltmp $line
#		bin_str2arr $ltmp arr
#		set line [bin_arr2str arr]
#		unset arr ltmp
#	}
	if { [eof $fdi] } {
		puts -nonewline $fdo $line
	} else {
		puts $fdo $line
	}
}

# close them, and compare
close $fdi
close $fdo

if [catch {exec cmp test.in test.out} result] {
	puts "Copy failed: $result"
} else {
	puts "Copy succeeded"
}

