#!/bin/sh awk 'BEGIN{ for (i=32; i<256; ++i) c[sprintf("%c",i)]=sprintf("%c",i) c["<"]="<" c[">"]=">" c["&"]="&" printf("\n") sgmlify=1 } /^\.H /{ gsub(/ \.\\"{{{.*$/,"") if (define==0 && troff==0) printf("%s\n",$2+1,substr($3,1,1)==sprintf("%c",34) ? substr($0,7,length($0)-7) : $3, $2+1) next } /^\.TL/{ if (define==0 && troff==0) { printf(""); title=1 } next } /^\.AU/{ if (define==0 && troff==0) { if (title) printf("%s\n\n

%s

\n",titlestr,titlestr) title=0 authorstr=substr($0,5) authorstr=(substr($0,5,1)==sprintf("%c",34) ? substr($0,6,length($0)-6) : substr($0,5)) } next } /^\.AF/{ if (define==0 && troff==0) { if (title) printf("\n\n

%s

\n",titlestr); title=0; } next } /^\.AS/{ if (define==0 && troff==0) { if (title) printf("\n\n

%s

\n",titlestr) printf("
\n") title=0 } next } /^\.AE/{ printf("
\n") } /^\.P$/{ if (define==0 && troff==0) printf("

\n") next } /^\.BL/{ if (define==0 && troff==0) printf("

\n"); --level } } next } /^\.DS/{ if ($2=="CB") centered=1; printf("
")
  display=1
  next
}
/^\.DE/{
  printf("
") if (centered) centered=0; display=0 next } /^\.FS/{ ++define next } /^\.FE/{ --define next } /^\.TS/{ sgmlify=0 if (display) printf("") if (centered) printf("
") getline if (match($0,"^[a-z,]*;$")>0) next } /^\.TE/{ sgmlify=1 if (centered) { printf("
") } if (display) printf("
")
  next
}
/^\.de/{
  define=1
  next
}
/^\.if t \\{/{
  troff=1
  next
}
/^\.if n \\{/{
  nroff=1
  next
}
/^\\}/{
  troff=0
  if (define==0 && nroff) nroff=0
  next
}
/^\.\./{
  define=0
  next
}
/^[^.]/{
  if (sgmlify) { s=""; for (i=1; i<=length($0); ++i) if (substr($0,i,1)=="\\") s=s "\\" substr($0,++i,1); else s=s c[substr($0,i,1)] } else s=$0
  if (define==0 && troff==0 && title==0) printf("%s\n",s)
  if (title) titlestr=titlestr s
# if (display) printf("\n") 
  next
}
END{
  printf("
%s
\n\n\n",authorstr) }'