#! /bin/sh
# makeindex <dirname>			greid Fri Jun  3 19:21:46 1988
#
PATH=/usr/local/bin:/usr/ucb:/bin:/usr/bin

head=".head"
body=".body"
index=".index"
oldindex=".oldindex"
info=".info"

trap "rm -f .tmp* $body ; exit" 0 1 2 15

case "$1" in
    "") ;;
    *) cd $1 ;;
esac

if [ -f $index ]; then cp $index $oldindex; fi

line="init"
if [ -f .longnames ]; then
    ls -lL | awk '{printf "%30s %6s %s %2s %s\n",$8,$4,$5,$6,$7}' > .tmp
else
    ls -lL | awk '{printf "%-18s %6s %s %2s %s\n",$8,$4,$5,$6,$7}' > .tmp
fi

cp /dev/null $body
for filename in `awk '{print $1}' .tmp`
do
    egrep "$filename  " .tmp >> $body;
    if [ -f $info/$filename ]; then
	cat $info/$filename >> $body
	echo "" >> $body
    fi
done
cat $head $body > .index
exit

ls -l $* | \
  awk 'BEGIN { print ".TS"; print "l7 r.";
     print "Name	Bytes"
     print "\_	\_" }
     { printf "%s	%s\n", $8, $4}
   END { print ".TE" }' | \
   tbl | nroff -Tsu | egrep -v '^$'  | \
   sed -e "s/Bytes$/Bytes   Last Update: `date`/" -e '/^_/s/_/-/g' \
	> $body
cat $head $body > $index
