[comp.text] Making binary-only troff distributions user-customizable

dns@sq.com (David Slocombe) (03/16/89)

In article <5@unmvax.unm.edu> brainerd@unmvax.unm.edu (Walt Brainerd)
describes several interesting new features which his product,
Profficient, provides to initialize it for specific applications.

We at SoftQuad offer an enhanced version of troff.  Most of our customers
purchase binary-only copies of the software, so we ran into the same
kinds of problem, as have many other vendors of binary-only software.

In fact, several years ago, the plethora of new features and device-
dependent adjustments that we wanted to provide our customers meant
that command-line options were becoming excessive.  Furthermore, we
needed to enable customers to install the whole package *anywhere*
on their system:  it was no longer acceptable to have wired-in paths
like /usr/lib/tmac or /usr/lib/macros or /usr/lib/font, or even
/usr/tmp.

So we took a deep breath and created an initialization system
reminiscent of Berkeley Mail's .mailrc or rn's .rninit file.
*One* directory is assumed from the start ("/usr/sqps"), but even
this can be redefined with an environment variable SQDIR.  By
default, all the files in our product are assumed to be installed
in a directory-tree beginning there.

In that directory all our programs look for a file called "sqrc" (but
the path for *that* can be redefined with an environment variable SQRCBASE)
which contains a combination of keyword=value pairs and command-option
prototypes (like "sqtroff -w3 -e").

This file is transparently merged with another similar file (if it exists)
called ".sqrc" in the user's home directory (and the location for *that*
can be redefined with an environment variable SQRC).  And the user's
command-line options may in turn override those from the (combined)
sqrc files.

Here's an edited version of the "sqrcbase" file here at SoftQuad R&D in
Toronto (the full version is currently 51 lines long including comments):

   # Default options for sqtroff - lotsa warnings, enable hyphenation-exception.
   sqtroff -w3 -e
   
   # Default spooler, used only by "ts" script.
   SPOOLER=lpr
   
   # Global default device.
   TYPESETTER=ps

   # If FONTDIR and TMACDIR are relative paths, they are relative to SQDIR.
   FONTDIR=font
   TMACDIR=lib/tmac
   
   # Output image types (device-specific):
   # biases and printable-areas on a machine-by-machine basis if necessary
   PAPER.ps.default =	letter 21u 17u 56u 25u 8i 10.7i
   PAPER.ps.legal   =	legal  21u 17u .75i .6i 6.75i 12.64i
   
   # Standard North American paper sizes:
   PSIZE.letter = 8.5i 11i
   PSIZE.legal  = 8.5i 14i
   
Each program uses a special version of getopt(), called getrcopt(),
which picks up any "default" options from any command-option prototype
in the (combined) sqrc file before processing the user's actual command-line
options a la getopt().  Other functions provide ways to get the value
for any keyword in the sqrc file.

To make the whole system independent of where it is installed, it
had to be possible for sqtroff to construct ".so" filenames, so
we added the escape sequence \Q to get values for sqrc keywords from
within troff (macro-package) text.  A good example of the use of this
is the little file "tmac.m" (the file corresponding to "-mm", read
when troff starts up), where we do, essentially:

   .\" locate and source-in the mm macro package:
   .ie '\Q[MMDIR]'' \{\
   .	so \Q[SQDIR]/lib/macros/mmt
   .el \{\
   .	so \Q[MMDIR]/mmt
   .\}

The "\Q[MMDIR]" and "\Q[SQDIR]" expand analogously to the shell-constructs
"$MMDIR" and "$SQDIR" except that they read sqrc-file variables instead
of environment variables.  The square brackets are used in sqtroff to
delimit long-names of all sorts (and may also be used in place of paired
delimiters for \h and similar escape sequences).

There is, of course, a trivial utility program, sqrcget, which will
fetch any of the keyword variables for use in shell scripts.

This system not only allows the system administrator (if there is one!)
and each individual user great flexibility, but provides the means to
cope with a great variety of printers, papers, font-collections, and 
other site- (or even user-) peculiarities.

I recommend the approach to any software developer.  It's sure saved
us a lot of installation and support headaches.

----------------------------------------------------------------
David Slocombe				(416) 963-8337
SoftQuad Inc.				(800) 387-2777 (from U.S. only)
720 Spadina Ave.			uucp: {uunet!attcan!utzoo, utai}!sq!dns
Toronto, Ontario, Canada M5S 2T9	Internet: dns@sq.com