> Software Tools in Pascal by Brian W. Kernighan and P.J. Plauger
For what it's worth, some of the example code from the book "Software Tools" is available from Brian Kernighan's web page. It has a simple roff written in ratfor, which I've manually converted slapdash into Fortran-90. Some parts could be written more concisely (e.g., the command decoder), but overall the code is conveniently subdivided into short, easily understandable routines and thus makes an instructive teaching model of the internals of a text formatter. Text filling, underlining, centering, and pagination all work nicely, but this simple version of roff perforce lacks the single one feature that made the "new roff" so much more versatile than earlier roffs: programmability. However, this and the other niceties (traps, diversions) could easily double the amount of code required.