#!/usr/bin/awk -f # @(#) toroff.awk 92/05/21 # 1989 john h. dubois iii (john@armory.com) # 92/05/21 converted to a #!awk script # # Converts text with normal paragraphs (left justified, with the first line # indented at least three spaces and all others less than three spaces) to # troff/nroff source, preserving the paragraphs by preceding each with .PP # # Sentences are put on individual lines, split over multiple lines if they will # not fit on one line. The maximum length a line is allowed to reach is 79 # characters. Sentences are delimited by words ending in '.', '?', and '!', # or the same followed by a close parentheses. # Note that this is not a perfect algorithm. BEGIN { LineLen = 0 } # Do for the first line of a paragraph /^ / { if (LineLen == 0) print ".PP" else { print "\n.PP" LineLen = 0 } } # Do for all lines { for (f = 1; f <= NF; f++) { WordLen = length($f) if (LineLen == 0) { LineLen = WordLen printf "%s",$f } else { LineLen += 1 + WordLen; if (LineLen <= 79) printf " %s",$f else { LineLen = WordLen printf "\n%s",$f } } lchar = substr($f,WordLen,1) if (lchar == ")") lchar = substr($f,WordLen - 1,1); if (lchar == "." || lchar == "?" || lchar == "!") { print "" LineLen = 0 } } }