#!/bin/sh
#
#NAME
#  Man - man page to editable plain text
#
#SYNOPSIS
#  Man [section] title
#
#DESCRIPTION
#  This calls "man" with the given parameters, and feeds  the  output
#  to a filter to strip out junk such as underlining, etc. The result
#  is put into the file ~/man/title, and $EDITOR is run on this file.
#
#  The formatted file is put into $HOME/man/title.section.  If it  is
#  already  there,  we don't rerun the man command, but just edit it,
#  so if you make changes, they will persist in your own copy.
#
#FILES
#  $HOME/man/title.section - where the formatted page is put.
#
#BUGS
#  There doesn't seem to be any reliable way to  determine  that  the
#  man command has failed.  If a man page doesn't exist, what usually
#  happens is that you end up with an empty man page.
#
#  We don't create the $HOME/man directory.
#  We don't set the EDITOR environment variable.
#
#AUTHOR
#  John Chambers <jc@trillian.mit.edu>

if [ $# -eq 2 ];then
	S=$1
	T=$2
	F=$HOME/man/$T.$S
elif [ $# -eq 1 ];then 
	T=$1
	F=$HOME/man/$T
else
	echo "Usage: $0 [section] title"
	exit 1
fi
echo F="$F"

if [ ! -f $F ];then
#	man $S $T | stripman >$F
	man $S $T  >$F
fi
echo Editing ${F}*
sleep 1
$EDITOR ${F}*
