#!/bin/sh
awk '
/^\.so/ {
system("cat " $2)
next
}
{
print
}
' $* | awk '
BEGIN {
endtag = ""
title = 0
}
/^\./ {
if(endtag != "" && $1 !~ "\.ft") {
print endtag
endtag = ""
}
if(title) {
print "
" titletext "
"
print "
"
title = 0
}
if($1 ~ "\.TL") {
print ""
endtag = ""
title = 1
} else if($1 ~ "\.\\\\\"") {
if($2 == "HTML") {
for(i=3; i <= NF; i++)
printf("%s ", $i)
printf "\n"
next
}
print $0
} else if($1 ~ "\.(sp|br)") {
print "
"
} else if($1 ~ "\.ce") {
print ""
endtag = ""
} else if($1 ~ "\.bp") {
print "
"
} else if($1 ~ "\.ft") {
if($2 == "I") {
print ""
endfont = ""
} else if($2 == "B") {
print ""
endfont = ""
} else if($2 == "") {
print endfont
if(endtag != "") {
print endtag
endtag = ""
}
}
} else if($1 ~ "\.PP") {
print ""
endtag = "
"
} else if($1 ~ "\.IP") {
print ""
endtag = "
"
} else if($1 ~ "\.SH") {
print ""
endtag = "
"
}
next
}
{
if(title)
titletext = $0
print
}'