#! /bin/sh
# --------------------------------------------------------------------------- #
# poor man's quick&dirty outliner; uses indentation for visualization         #
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# .sh's map as numbered; .uh's takes precedence over .ip's; .Ox\ntext treated #
# as .sh x text; .pp\n<fontchange>text<fontchange> treated as .ip text        #
#                                                                             #
# -ms calls converted to -me where possible                                   #
#                                                                             #
# multiple sed's used for clarity                                             #
# --------------------------------------------------------------------------- #

cat $* | \
 sed -e 's/^\.ft .$/\\fZ/
         s/^\.ft ..$/\\fZ/
         s/^\.[RIBP] /\\fZ/
         s/^\.B[RIP] /\\fZ/' | \
 sed -e 's/\\f([A-Z][A-Z]/\\fZ/g' | \
 sed -e '/^\.O/N
         /^\.O/s/\n/ /
         /^\.O/s/\\f[A-Z]//g
         /^\.O/s/O/sh /' | \
 sed -e '/^\.[Pp][Pp]/N
         /^\.[Pp][Pp]/s/\n/ /
	 /^\.PP/s/PP/pp/' | \
 sed -e 's/^\.NH$/.NH 1/
         /^\.NH/N
         /^\.NH/s/\n/ /
	 /^\.NH/s/NH/sh/' | \
 sed -e '/^\.SH/s/SH/sh/' | \
 egrep '^\.[su]h |^\.ip |^\.pp \\f[A-Z].*\\f[A-Z]' | \
 sed -e 's/^\.sh 9/\.sh 8  /
         s/^\.sh 8/\.sh 7  /
         s/^\.sh 7/\.sh 6  /
         s/^\.sh 6/\.sh 5  /
         s/^\.sh 5/\.sh 4  /
         s/^\.sh 4/\.sh 3  /
         s/^\.sh 3/\.sh 2  /
         s/^\.sh 2/\.sh 1  /
         s/^\.sh 1 //
         s/^\.pp/\.ip/
         s/\\f.//
         s/\\f.*//
         s/^\.ip /\.uh   /
         s/^\.uh //
         s/"//g' 
