#! /bin/csh -f
# emacs sort
# 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
tr '\21-\37\41-\177\221-\237\241-\377' '\221-\237\241-\377\21-\37\41-\177' < $2 > $F1
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
tr '\21-\37\41-\177\221-\237\241-\377' '\221-\237\241-\377\21-\37\41-\177' < $F2 > $F3
/bin/mv $F3 $2
rm $F1 $F2
