Subject: v07i033: A .so filter for n/t/*roff files Newsgroups: mod.sources Approved: mirror!rs Submitted by: Davidsen Mod.sources: Volume 7, Issue 33 Archive-name: sop [ This seems to be pretty much the same as BSD 'soelim' program. --r$ ] #!/bin/sh # created from directory /usr2/davidsen/UNaXcess/uguide echo shar created 13:27 on Wed Aug 27, 1986 by davidsen echo 'x - readme.sop (text)' sed << 'E!O!F' 's/^X//' > readme.sop XI found out the hard way that I couldn't use tables and equations in Xfiles included in nroff documents via the ".so" mechanism. The tbl and Xeqn processors just don't know about ".so". Therefore I wrote a small Xprogram to preprocess the .so commands and allow use of tables anywhere. X E!O!F echo 'x - sop.1 (text)' sed << 'E!O!F' 's/^X//' > sop.1 X'\" @(#)skeleton 3.3 - 12/21/83 X'\" [c][e][t] (only if preprocessing by cw, eqn, and/or tbl required) X.TH sop 1 local X'\" Heading: name(sect) center (paren) name(sect) X.SH NAME Xsop - preprocess .so commands in nroff files X.SH SYNOPSIS Xsop filename X.SH DESCRIPTION XThe \fIsop\fR processor allows the use of tables and equations in files Xaccessed via the ".so" nroff command. Since the X.I tbl Xand X.I eqn Xprocessors don't handle .so commands, this simple preprocessor will Xcreate a single output file on stdout, starting with an nroff file which Xmay contain .so commands. X.SH EXAMPLES X sop myfile.n | tbl | nroff -mm -Thtm.12 | lp X.SH WARNINGS XNo attempt is made to handle .so commands contained in conditional Xexpressions. This program has not been tested with X.I troff X(although there is no reason to expect problems). X.SH SEE ALSO Xtbl(1), eqn(1), nroff(1). X.SH DIAGNOSTICS Xnone. X.SH LIMITATIONS XDoes not process conditional .so usage. X.SH AUTHOR XBill Davidsen, GE Corporate R&D Center. X(...ihnp4!chinet!crdos1!davidsen) X'\" For more details, see man(7), as well as man(1), manroff(1), and mmt(1) E!O!F echo 'x - sop.c (text)' sed << 'E!O!F' 's/^X//' > sop.c X/* X * SOP - process .so commands X * Bill Davidsen - 8/10/86 X * X * for those system in which the tbl and eqn processors don't X * process .so commands and the included files require pro- X * cessing. X * X * Use: X * sop firstfile | tbl | nroff ... X */ X X#include X#define LLEN 256 /* longest line to allow */ X XFILE *stack[10], /* file stack */ X *fp, /* current file pointer */ X *fopen (); Xint index = 0; /* index into file stack */ X Xchar line[LLEN]; /* line buffer */ X Xmain (argc, argv) X int argc; X char *argv[]; X{ X switch (argc) X { X case 1: /* use standard input */ X fp = stdin; /* read standard input */ X break; X case 2: /* got a file to use */ X fp = fopen (argv[1], "r"); X if (fp == NULL) X { /* bad filename */ X fprintf (stderr, "Can't open file %s\n", argv[1]); X exit (1); X } X break; X default: X fprintf (stderr, "Format\n sop\n -or-\n sop filename\n"); X exit (1); X } X X while (fp != NULL) X { /* read and scan for .so */ X if (fgets (line, LLEN, fp) == NULL) X { /* end of file on current file */ X if (index) X fp = stack[--index]; X else X fp = NULL; X continue; X } X X if (strncmp (line, ".so ", 4) == 0) X { /* include this file */ X stack[index++] = fp; X /* set newline to EOL */ X line[strlen (line) - 1] = 0; X /* open the next file */ X fp = fopen (line + 4, "r"); X if (fp == NULL) X { /* bad include file */ X fprintf (stderr, "Can't open include file %s\n", line + 4); X exit (1); X } X continue; X } X X fputs (line, stdout); X } X} E!O!F