#!/usr/bin/gawk
# defining macros - eat them
/^\.de.*/ {
getline
while ( $0 !~ "^\.\.$" )
{
getline
}
getline
}
# eat [nt]roff comments
$0 ~ /['.][\/\\]"/ || $1 == "'" { next }
# remove sidebar macros
$1 == ".VS" || $1 == ".VE" || $1 == ".AS" { next }
# handle first .SH as special case - .SH NAME
/^.SH *NAME */ {
getline
while ( $0 ~ /\.[a-zA-Z].*/ ) # eat dot-cmd following title
{
getline
}
print "
" $0 ""
print "" $0 "
\n"
next
#-e 's/^.SH *NAME */{N;s#.*\n\(.*\)#\1
#;}' \
}
# Convert .IP Paragraphs upto next .cmd to hanging indents
# using
pairs without intervening
/^\.IP */ {
if ( inIP > 0 )
{
print ""
}
inIP = 1
startIP = 1
print ""
match($0, /".*"/ )
if ( RSTART > 0 )
{
arg = substr( $0, RSTART+1, RLENGTH-2)
print "- " arg
}
else if ( length( $2 ) > 0 )
{
print "
- " $2
}
next
}
$0 ~ /^\.[a-zA-Z]*/ && inIP > 0 {
inIP = 0
print "
"
}
# Convert
# .TP
# Line1
# line 2 - n
# .Any
#
# to
#
# - Line1
#
- lines 2 - n
#
-
/^\.TP */ {
if ( inTP > 0 )
{
print "
"
}
inTP = 1
print ""
next
}
inTP == 1 && $1 !~ /\.[a-zA-Z]*/ {
print "- " $0
inTP = 2
next
}
inTP == 2 && $1 !~ /\.[a-zA-Z]*/{
print "" # Belt and suspenders
print "
- " $0
inTP = 3
next
}
$0 ~ /^\.[a-zA-Z]*/ && inTP > 0 {
inTP = 0
print "
"
}
$1 == ".AP" {
$1=""
print ""
print "- " $2 "\t\t" $3 "\t\t("$4")"
inTP = 2
next
}
# make a blank line
$1 == ".sp" {
print "
"
next # print "
"
}
$1 == ".ta" { next }
# just pass everything else on
{
if ( startIP > 0 )
{
print " - " $0
startIP = 0
}
else
{
print $0
}
}