[comp.sources.d] roff_bl

stephenf@softway.oz (Stephen Frede) (10/04/89)

In the README that came with roff_bl:

> the roff command line is basically a line of text that is passed to
> eval(1).  Its format is as follows:
> 
> \" exec tbl | pic | eroff -mm
> 
> the '\"' is a troff/nroff comment delimeter.  The 'exec' helps identify
> this line as a roff command line.
 ...
> If you look at the roff script you will notice that we strip off the
> first line of the document file (the roff command line) before we
> pipe the document through the rest of the filters.  At first glance
> one might think this isn't necessary, but the mm macros are in my
> opinion broke, or at least the ones we have are.  If the very first
> physical line of the document isn't .PH "''''" you get the header.
> Even if the first line is simply a comment, like the roff command line.

A common misconception. The sequence \" introduces a comment
through to the end of the line. It does not make the entire
line a comment. To do that use (as one possibility) .\" at
the start of a line. The .PH macro of mm will work on the
first page as long as you use it before anything which causes
output on the page, including a single blank line, such as
your commented first line.

In the Portability file:

> Portability Concerns:
> roff uses head(1).  I've heard some UNIXes don't have head. sigh...

I've heard that some UNIXes have head. sigh...
In fact, what you should be upset about is that some vendors
have unbundled "cut" into the document processing subpackage,
of all things.

To clean it up a little bit:

#----------------------------------------------------------------
# roff by Brian E. Litzinger (modified)
TROFF=eroff
for file
do
    case "$file" in
	-*)
	    args="$args $file"
	    ;;
	*)
	    command_line=`sed 1q "$file"`
	    command=`expr x"$command_line" : 'x\.\\\\" *exec *\(.*\)'` ||
	    if [ "$command" = "" ]
	    then
		echo "$file not roff format file!"
		exit 2
	    fi
	    command=`echo "$command" | sed -e "s/$TROFF/$TROFF $args/g"`
	    eval "$command" < "$file"
	    ;;
    esac
done
#----------------------------------------------------------------

And except for bugs in the BSD shell (works fine with
System V shell) the line with the echo could be replaced
with:
	    command=`sed -e "s/$TROFF/$TROFF $args/g" <<-!
		$command
	    !`
and we could use the exit status of expr.
This should work with metacharacters in filenames etc.
And if you really want the 1st line deleted, modify the eval
line.

Of course you have to remember the correct order of all those
filters and the options for your favourite troff backend etc.
What would be even better would be to have a line something
like .\"OPTIONS mm tbl lbl rotate:45
in your document, feed it to "lp -dtroff" (or whatever) and
have the print despooler do all the filtering in the correct
order, supplying the required options to the various
programs, running no more than some number of troff jobs in
parallel, and finally spooling the output on the correct
print queue. And of course, since your troff document may
consist of several modules, some of which require a
particular filter (and say so with an OPTIONS line) and others
that don't, potentially all brought together with .so
requests, the despooler had better get all that right too.
The script is left as an exercise for the reader, but isn't
very long.

			Regards,

				- Stephen Frede

Softway Pty Ltd, P.O. Box 305, Strawberry Hills, NSW 2012, AUSTRALIA
Phone: +61 2 698 2322; Fax: +61 2 699 9174; Telex: AA27987
ACSnet: stephenf@softway.oz	UUCP: ...!uunet!softway.oz!stephenf