# This script finds all files in the reviews directory, adds an
# appropriate icon file for them (either text reader or directory),
# and then attempts to layout the icons so that they need only minor
# manual touchups.
#
# Thus when the a new archive of reviews is received, they can be
# unpacked in this tree, this script can be run to do 90% of the
# work of updating the tree, and then some minor touchups can be
# done manually (such as adjusting the size of windows for
# directories that now have more files), with some changes folded
# back into this script so that they don't have to be done again
# next time.

# First get a list of all the files, then toss out some names
# that we know don't need icons or are icons.

find . -print | sort -f | sed "s:^./::" >/tmp/all.tmp
sed -e "/^\.$/d" -e "/\.info$/d" -e "/^AddIcons.sh/d" \
    -e "/\.jpg$/d" -e "/\.iff$/d" -e "/\.uu$/d" \
    -e "/\.gif$/d" -e "/Product-Info$/d" -e "/\.ps$/d" \
    </tmp/all.tmp >/tmp/all.tmp2

# For each of the remaining names, clone the current 00-README.info file
# for text files or the doc.info file for directories.

for name in `cat /tmp/all.tmp2`
do
	if test ! -f $name.info ; then
		if test -f $name ; then
			echo "cp 00-README.info $name.info"
			cp 00-README.info $name.info
		elif test -d $name ; then
			echo "cp doc.info $name.info"
			cp doc.info $name.info
		fi
	fi
done

# Now go reposition the icons.

find . -type d -print | sort -f | sed "s:^./::" >/tmp/dirlist

for dir in `cat /tmp/dirlist`
do
	# Supply a default layout.
	case "${dir}" in
		.)	layout="-y 40 -Y 22 -x 120 -X 40 -N 5" ;;
		*)	layout="-y 50 -Y 12 -x 200 -X 60 -N 3" ;;
	esac
	# Supply a geometry for the drawer window, and a custom
	# layout if necessary.
	case "${dir}" in
		.)			geometry="DXPOS 0 DYPOS 22 DWIDTH 654 DHEIGHT 123"
					layout="-y 40 -Y 22 -x 120 -X 40 -N 5" ;;
		doc)			geometry="DXPOS 0 DYPOS 33 DWIDTH 624 DHEIGHT 183" ;;
		hardware)		geometry="DXPOS 0 DYPOS 33 DWIDTH 654 DHEIGHT 243"
					layout="-y 40 -Y 22 -x 120 -X 40 -N 5" ;;
		hardware/accelerators)	geometry="DXPOS 0 DYPOS 11 DWIDTH 624 DHEIGHT 483" ;;
		hardware/audio)		geometry="DXPOS 0 DYPOS 11 DWIDTH 624 DHEIGHT 183" ;;
		hardware/cd-rom)	geometry="DXPOS 0 DYPOS 11 DWIDTH 624 DHEIGHT 233" ;;
		hardware/computers)	geometry="DXPOS 0 DYPOS 11 DWIDTH 624 DHEIGHT 233" ;;
		hardware/copiers)	geometry="DXPOS 0 DYPOS 11 DWIDTH 417 DHEIGHT 83" ;;
		hardware/datacomm)	geometry="DXPOS 0 DYPOS 11 DWIDTH 624 DHEIGHT 83" ;;
		hardware/debug)		geometry="DXPOS 0 DYPOS 11 DWIDTH 215 DHEIGHT 83" ;;
		hardware/emulation)	geometry="DXPOS 0 DYPOS 11 DWIDTH 624 DHEIGHT 233" ;;
		hardware/graphics)	geometry="DXPOS 0 DYPOS 11 DWIDTH 624 DHEIGHT 333" ;;
		hardware/ide)		geometry="DXPOS 0 DYPOS 11 DWIDTH 624 DHEIGHT 83" ;;
		hardware/input-devices)	geometry="DXPOS 0 DYPOS 11 DWIDTH 624 DHEIGHT 233" ;;
		hardware/memory)	geometry="DXPOS 0 DYPOS 11 DWIDTH 417 DHEIGHT 83" ;;
		hardware/monitors)	geometry="DXPOS 0 DYPOS 11 DWIDTH 624 DHEIGHT 83" ;;
		hardware/ports)		geometry="DXPOS 0 DYPOS 11 DWIDTH 624 DHEIGHT 183" ;;
		hardware/power)		geometry="DXPOS 0 DYPOS 11 DWIDTH 417 DHEIGHT 83" ;;
		hardware/projects)	geometry="DXPOS 0 DYPOS 11 DWIDTH 215 DHEIGHT 83" ;;
		hardware/rom-switchers)	geometry="DXPOS 0 DYPOS 11 DWIDTH 417 DHEIGHT 83" ;;
		hardware/scsi)		geometry="DXPOS 0 DYPOS 11 DWIDTH 624 DHEIGHT 133" ;;
		hardware/storage)	geometry="DXPOS 0 DYPOS 11 DWIDTH 624 DHEIGHT 233" ;;

		other-reviews)		geometry="DXPOS 0 DYPOS 33 DWIDTH 654 DHEIGHT 123"
					layout="-y 40 -Y 22 -x 120 -X 40 -N 5" ;;
		other-reviews/april-fools) geometry="DXPOS 0 DYPOS 11 DWIDTH 624 DHEIGHT 133" ;;
		other-reviews/books)	geometry="DXPOS 0 DYPOS 11 DWIDTH 624 DHEIGHT 133" ;;
		other-reviews/conferences) geometry="DXPOS 0 DYPOS 11 DWIDTH 215 DHEIGHT 83" ;;
		other-reviews/magazines) geometry="DXPOS 0 DYPOS 11 DWIDTH 624 DHEIGHT 133" ;;
		other-reviews/shows)	geometry="DXPOS 0 DYPOS 11 DWIDTH 624 DHEIGHT 83" ;;
		other-reviews/vendors)	geometry="DXPOS 0 DYPOS 11 DWIDTH 417 DHEIGHT 83" ;;

		software)		geometry="DXPOS 0 DYPOS 33 DWIDTH 654 DHEIGHT 203"
					layout="-y 40 -Y 22 -x 120 -X 40 -N 5" ;;
		software/amigados)	geometry="DXPOS 0 DYPOS 11 DWIDTH 624 DHEIGHT 133" ;;
		software/audio)		geometry="DXPOS 0 DYPOS 11 DWIDTH 624 DHEIGHT 183" ;;
		software/business)	geometry="DXPOS 0 DYPOS 11 DWIDTH 215 DHEIGHT 83" ;;
		software/calendar)	geometry="DXPOS 0 DYPOS 11 DWIDTH 624 DHEIGHT 83" ;;
		software/cd-rom)	geometry="DXPOS 0 DYPOS 11 DWIDTH 624 DHEIGHT 583" ;;
		software/database)	geometry="DXPOS 0 DYPOS 11 DWIDTH 417 DHEIGHT 83" ;;
		software/datacomm)	geometry="DXPOS 0 DYPOS 11 DWIDTH 624 DHEIGHT 183" ;;
		software/disk)		geometry="DXPOS 0 DYPOS 11 DWIDTH 624 DHEIGHT 333" ;;
		software/gag)		geometry="DXPOS 0 DYPOS 11 DWIDTH 417 DHEIGHT 83" ;;
		software/games)		geometry="DXPOS 0 DYPOS 11 DWIDTH 1037 DHEIGHT 889"
					layout="-y 50 -Y 12 -x 200 -X 60 -N 5" ;;
		software/graphics)	geometry="DXPOS 0 DYPOS 11 DWIDTH 624 DHEIGHT 483" ;;
		software/graphics/raist) geometry="DXPOS 0 DYPOS 11 DWIDTH 264 DHEIGHT 118"
					layout="-y 40 -Y 12 -x 120 -X 40 -N 5" ;;
		software/multimedia)	geometry="DXPOS 0 DYPOS 11 DWIDTH 417 DHEIGHT 83" ;;
		software/printing)	geometry="DXPOS 0 DYPOS 11 DWIDTH 624 DHEIGHT 133" ;;
		software/programmer)	geometry="DXPOS 0 DYPOS 11 DWIDTH 624 DHEIGHT 383" ;;
		software/science)	geometry="DXPOS 0 DYPOS 11 DWIDTH 624 DHEIGHT 133" ;;
		software/shell)		geometry="DXPOS 0 DYPOS 11 DWIDTH 417 DHEIGHT 83" ;;
		software/text)		geometry="DXPOS 0 DYPOS 11 DWIDTH 624 DHEIGHT 383" ;;
		software/text/hagen)	geometry="DXPOS 0 DYPOS 11 DWIDTH 215 DHEIGHT 83" ;;
		software/unix)		geometry="DXPOS 0 DYPOS 11 DWIDTH 417 DHEIGHT 83" ;;
	esac
	dirpath=`(cd $dir; pwd) | sed -e "s:^/::" -e "s@/@:@"`
	echo "======"
	iconpos "$dirpath" $geometry
	(cd $dir && pwd && \
	 ls *.info | sort -f | placeicons $layout >/tmp/runme && \
	 sh /tmp/runme)
done
