#!/bin/ash
# rustic `od` (C) by M. Andreoli
# [ with `cmp`, very nice ]

#set -x

#Syntax
usage()
{
cat <<END
mu-od: rustic octal-dump

	Usage		od file
	Output-->	offset: octal char-with-escape-code

END
}
f="$1"

case "Z$f" in
Z|Z-h) usage ; exit ;;
*)
esac

# Main

set -- `ls -l $f`
n=$5

[ $n -gt 1024 ] && n=1024
dd if=/dev/zero of=/tmp/zero.od bs=1c count=$n
cmp -c -l $f /tmp/zero.od 2>/dev/null | \
while read line 
do
set -- $line
offset=$1; octal=$2
value=$3

echo -e "$offset:\t$octal\t $value"
done

rm /tmp/*.od
