henry@utzoo.UUCP (Henry Spencer) (06/24/85)
Here is a good candidate for the silliest troff preprocessor of the year. Tbl tells troff how to format tables. Eqn tells troff how to format equations. The following is a preprocessor, written in awk, that tells troff how to format... text!?! It's very simple, just doing vanilla filling and justification. Works all right, although as it stands it's just a silly and slow way of doing something troff does anyway. A fancier version actually might be useful if you wanted to do something radically unusual (e.g. fill/justify to non-rectangular boundaries). Don't expect me to write it! ----- BEGIN { print ".nf" print ".ds l \"" # partial output line print ".nr w 0" # width of partial output line print ".nr n 0" # number of words in partial output line print ".nr L 3i" # line length print ".ds s \"\\\\h'\\\\ngu'" # interword spacing sequence print ".de aw" # add word to accumulating line print ".if \\\\nwu+\\\\w'\\\\$1'u+\\\\w'\\\\ 'u>\\\\nLu .ff f" print ".ie '\\\\*l'' \\{\\" print ".ds l \\\\$1" print ".nr w \\\\w'\\\\$1'u\\}" print ".el \\{\\" print ".as l \"\\\\\\\\*s\\\\$1" print ".nr w \\\\nwu+\\\\w'\\\\$1'u+\\\\w'\\ 'u\\}" print ".nr n +1" print ".." print ".de ff" # flush accumulating line, arg is full or not print ".if !'\\\\*l'' \\{\\" print ".nr n -1" print ".ie '\\\\$1'f' .nr g \\\\nLu-\\\\nwu/\\\\nnu" print ".el .nr g 0" print ".nr g +\\\\w'\\\\ 'u" print "\\\\*l" print ".ds l \"" print ".nr n 0" print ".nr w 0 \\}" print ".." } /^$/ { print ".ff p" print } /^\./ { # All formatting requests cause break and are then passed through. print ".ff p" print } /^[^.]/ { for (n = 1; n <= NF; n++) print ".aw " $n } END { print ".ff p" } ----- -- Henry Spencer @ U of Toronto Zoology {allegra,ihnp4,linus,decvax}!utzoo!henry