#!/bin/sh

more=${PAGER-more}
show=`pwd`/bin/show

cd info.t
echo "Searching troff files"
files=`find . -name '*.t' -print`
echo "Found: " `ls -1 $files | wc -l` " files"

echo
echo
echo Documentation
echo
echo "1: Print   info files (dip)"
echo "2: Print   info files (lpr)"
echo "3: View    info files (xtroff)"
echo "4: View    info files (more)"
echo "5: Install info files"
echo "6: Help on compiling tcemp"
echo "7: Help on compiling xemp"
echo
echo -n "Command: "

read ans

case ${ans}
in
	1)
		${show} -t -d ${files}
		exit
		;;
			
	2)
		echo "Print command (eg: lpr -Pp01)"
		echo -n "Command: "
		read com
		exit
		;;

	3)
		${show} -t -x ${files}
		exit
		;;
	
	4)
		${show} -t ${files}
		exit
		;;
	
	5)
		for file in ${files}
		do
			dir=`dirname $file`
			if test ! -d ../info/${dir}
			then
				mkdir ../info/${dir}
			fi
			tbl ${file} | nroff -ms crt.mac - | awk -f Blank.awk |
				sed -e 's/8//g' \
				    -e 's/_//g' \
				    -e 's/o+/*/g' > \
				../info/${dir}/`basename ${file} .t`
			echo ${file} done
		done
		exit
		;;
	
	6)
		show tcemp/help.t
		files="tcemp/compiling.t tcemp/xemprc.t tcemp/startup.t \
		       tcemp/pager.t"
		
		echo
		echo "1: Print those info-files (dip)"
		echo "2: Print those info-files (lpr)"
		echo "3: Show  those info-files (xtroff)"
		echo "4: Show  those info-files (more)"
		echo
		echo -n "Command: "
		read ans

		case ${ans}
		in
			1)
				echo "Print command (eg: dip -Pp01)"
				echo -n "Dip-Command: "
				read com
				tbl ${files} | troff -ms troff.mac - > XXX
				eval $com XXX
				rm XXX
				exit
				;;

			2)
				echo "Print command (eg: lpr -Pp01)"
				echo -n "Print-Command: "
				read com
				tbl ${files} | nroff -ms lp.mac - > XXX
				eval $com XXX
				rm XXX
				exit
				;;
			
			3)
				xtroff -command \
					"tbl ${files} | troff -ms troff.mac -"
				exit
				;;
			
			4)
				${show} ${files}
				exit
				;;

			*)
				echo "Illegal choice"
				exit
				;;
		esac
		;;

	7)
		echo "No documentation on installing xemp, look at tcemp"
		exit
		;;

	*)
		echo "Invalid input"
		exit
		;;
esac
