Article View: net.text
Article #537silly preprocessor of the year
From: Henry Spencer
Date: Mon, 24 Jun 1985 20:12
Date: Mon, 24 Jun 1985 20:12
62 lines
2319 bytes
2319 bytes
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
Technical Details
Message-ID:
<5725@utzoo.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!henryShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!henry From: henry@utzoo.UUCP (Henry Spencer) Newsgroups: net.text Subject: silly preprocessor of the year Message-ID: <5725@utzoo.UUCP> Date: Mon, 24-Jun-85 16:12:20 EDT Article-I.D.: utzoo.5725 Posted: Mon Jun 24 16:12:20 1985 Date-Received: Mon, 24-Jun-85 16:12:20 EDT Organization: U of Toronto Zoology Lines: 62