#! /bin/csh -f
# emacs sort (version 1.2)
# modified by Kazushi (Jam) Marukawa <kazushi@kubota.co.jp>, 1993.9.30.
# change the sign of each byte in the file, sort it, and change the sign again.
# space (\40) and (\240) are not changed in the translation.
set F1 = /tmp/sorta$$
set F2 = /tmp/sortb$$
set F3 = /tmp/sortc$$
#tr '\21-\177\221-\377' '\221-\377\21-\177' < $2 > $F1
set `sort << EOF

a
EOF`
case $1 in
a) ;;
*) tr '\21-\37\41-\177\221-\237\241-\377' '\221-\237\241-\377\21-\37\41-\177' < $2 > $F1 ;;
esac

switch ($1)
case -n:
	sort +0 -1 $F1 > $F2
	breaksw
case -r:
	sort -r +0 -1 $F1 > $F2
	breaksw
endsw

#tr '\21-\177\221-\377' '\221-\377\21-\177' < $F2 > $F3
set `sort << EOF

a
EOF`
case $1 in
a) ;;
*) tr '\21-\37\41-\177\221-\237\241-\377' '\221-\237\241-\377\21-\37\41-\177' < $F2 > $F3 ;;
esac

/bin/mv $F3 $2
rm $F1 $F2
