
# reads a file and outputs a count of how many times each byte
# value occurs - see bincopy for a way to generate a test.in file
# or for a good time (if you have *alot* of patience) try changing
# "test.in" on the line below to /unix, /vmunix, /xenix or
# whatever your kernel is called

set fd [bin_open test.in rb]

# Initialize the counts to zero
for {set i 0} {$i < 256} {incr i} {
	set count($i) 0
}

# read the file 1K at a time
while {![bin_eof $fd]} {
	set buf [bin_read $fd 1024]
	if ![string length $buf] continue
	bin_str2arr $buf arr
	# increment the distribution counts
	for {set i 0} {$i < [array size arr]} {incr i} {
		incr count([set arr($i)])
	}
	unset arr
}

close $fd

puts stdout ""

# output the results
for {set i 0} {$i < 256} {incr i} {
	puts -nonewline stdout [format "%03d = %5d \t" $i $count($i)]
	if {$i%4 == 3} { puts stdout "" }
}

puts stdout ""

