home *** CD-ROM | disk | FTP | other *** search
- Subject: v08i058: A .so/.nx/.PS filter for *roff files
- Newsgroups: mod.sources
- Approved: mirror!rs
-
- Submitted by: cbosgd!ho95e!wcs (Bill Stewart)
- Mod.sources: Volume 8, Issue 58
- Archive-name: soelim
-
- I also needed an soelim a couple years ago, mainly to use troff in a
- distributed environment. A program called "catso" was posted by J.
- Leth of Bell Labs, which handled .so and .nx ; I added support for .PS
- (pic). I used Leth's code because Bill Joy's original soelim was ugly
- goto-code, but soelim was the right name to use.
-
- [ I wrote the Makefile. If you don't have strtok(), you should pick
- up Henry Spencer's stringlib package from the archive, which has it.
- --r$ ]
- echo "Unpacking Makefile"
- sed 's/^X//' >Makefile <<EOF
- X# Makefile for soelim.
- Xsoelim: soelim.c
- X $(CC) $(CFLAGS) -o soelim soelim.c
- Xinstall: soelim
- X @echo Copy soelim and soelim.1 to appropriate directories
- EOF
- echo "Unpacking soelim.1"
- sed 's/^X//' >soelim.1 <<EOF
- X.ad b
- X.de In \" Space and indent
- X.sp
- X.in +4
- X..
- X.de Un \" Space and undent
- X.sp
- X.in -4
- X..
- X.TH SOELIM 1 "LOCAL"
- X.SH NAME
- Xsoelim - Cats files, interpreting nroff/troff-style file inclusion
- X.SH SYNOPSIS
- X\fBsoelim\fR [ file or \fB-\fR ] ...
- X.SH DESCRIPTION
- X\fIsoelim\fR concatenates the files together, recursively inserting
- Xfiles referenced by the nroff/troff commands '.so', '.PS', and '.nx' in their
- Xproper positions.
- XWhen interpreting a '.so' command, the named file is itself \fIsoelim\fRd
- Xat that point, then processing resumes in the file that contained the '.so'
- Xcommand.
- XFiles referenced by '.nx' are treated the same, except that processing
- Xstops after the file referenced by the '.nx' command.
- X.P
- X\fISoelim\fR is useful for providing input to an \fInroff/troff\fR(1)
- Xpreprocessor, such as \fInrpp\fR(1), since normally the files referenced by
- Xthe .so and .nx commands will not be seen by the preprocessor.
- X.P
- XThe file name '-' means standard input.
- XStandard input will also be used if no arguments are given, unless
- Xthe input is connected to the terminal.
- XIn the latter case, \fIsoelim\fR will print its usage instructions.
- X.SH FILES
- X.SH AUTHOR
- XJ. Leth, IH 55414 6B-326, x6133 - His version was called "catso".
- X(Based on an earlier version by D. A. Spicer).
- X(Most recent version W. C. Stewart, HO 46133 2G218 x0705 - most of the
- Xcode is Leth's, with .PS stuff added. Bill Joy wrote the original
- X"soelim" for Berkeley UNIX in 1977.)
- X.SH SEE ALSO
- Xnroff/troff(1), mm(1), pic(1)
- X.SH DIAGNOSTICS
- X"Can't open [ .nx | .so ] file '<filename>'." -- the argument file, .so
- Xfile, or .nx file can't be read or does not exist.
- X.SH BUGS
- XWill not interpret commands imbedded in macros or conditionals, or commands
- Xfollowing a ';'. The .so, .PS, or .nx macro must be followed by at
- Xleast one tab or space.
- X(This is a "feature" to prevent trashing of lines like:
- X.br
- X .something
- X.br
- X)
- EOF
- echo "Unpacking soelim.c"
- sed 's/^X//' >soelim.c <<EOF
- X#include <stdio.h>
- X#include <string.h>
- X
- X/* Renamed soelim and .PS support added - Bill Stewart
- X AT&T Bell Labs 2G-218, Holmdel NJ 1-201-949-0705 ihnp4!ho95c!wcs*/
- X/* Catso will cat the standard input to the standard output, inserting
- X * all files referenced by the nroff commands '.so' or '.nx'.
- X * J. Leth, IH 55414 6B-326, x6133.
- X * (original program from: D. A. Spicer)
- X */
- X
- X#define SPACE " \t\n"
- X#define MAXLINE 511
- X
- Xchar buff[MAXLINE];
- X
- Xchar *MyName;
- Xint verbose=0;
- X
- Xmain(argc, argv)
- X int argc;
- X char *argv[];
- X{
- X FILE *inp;
- X int i;
- X void exit(); /* Make lint quiet */
- X
- X#ifdef CTRACE
- Xctroff();
- X#endif
- X if (isatty(0) && argc == 1) {
- X /* If input is from the terminal, and there are no args,
- X * print usage instructions and exit.
- X */
- X
- X fprintf(stderr, "Usage:\t%s [ file or '-' ] ...\n\
- X Cats the files (standard input, default) together, inserting\n\
- X files referenced by the nroff commands '.so' and '.nx' in their\n\
- X proper positions. File name '-' means standard input\n", *argv[0]);
- X exit(1);
- X };
- X
- X MyName = argv[0];
- X if (strcmp(argv[1],"-v")==0) {verbose++; argc--; argv++; printf("Verbose!\n");}
- X if (argc == 1) {
- X fetch(stdin);
- X } else {
- X for (i=1; i < argc; ++i) {
- X if (strcmp(argv[i], "-") == 0) {
- X fetch(stdin);
- X } else {
- X inp = fopen(argv[i], "r");
- X if (inp == NULL) {
- X fprintf(stderr,
- X "%s: can't open file '%s'.\n",
- X MyName,argv[i]);
- X } else {
- X fetch(inp);
- X }
- X }
- X }
- X }
- X return (0); /* If you get here, you're OK */
- X}
- X
- Xfetch(fdes)
- X FILE *fdes;
- X{
- X FILE *newdes;
- X char *fname, *ptr;
- X void exit();
- X
- X while(fgets(buff,sizeof(buff),fdes) != NULL ) {
- X /* strncpy(line, buff, sizeof(line)); */
- X if (buff[0]=='.' &&
- X (buff[3]==' '||buff[3]=='\t' || buff[3]=='<')) {
- X if (strncmp(buff, ".so", 3) == 0) {
- X fname = strtok(buff+3, SPACE);
- X if((newdes = fopen(fname,"r")) != NULL) {
- X fetch(newdes);
- X fclose(newdes);
- X } else {
- X fprintf(stderr, "%s: can't open .so file '%s'.\n",
- X MyName, fname);
- X exit(1);
- X }
- X } else if (strncmp(buff, ".nx", 3) == 0) {
- X fname = strtok(buff+3, SPACE);
- X if((newdes = fopen(fname,"r")) != NULL) {
- X fclose(fdes);
- X fetch(newdes);
- X fclose(newdes);
- X } else {
- X fprintf(stderr, "%s: can't open .nx file '%s'.\n",
- X MyName, fname);
- X exit(1);
- X }
- X exit(0);
- X } else if (strncmp(buff, ".PS", 3) == 0) {
- X#ifdef CTRACE
- Xctron();
- Xbuff;
- X#endif
- X fname=NULL;
- X for (ptr=buff+3; *ptr; ptr++){
- X if (*ptr=='<') {
- X for (ptr++; *ptr==' '||*ptr=='\t'; ptr++) ;
- X fname=ptr;
- X while (*ptr++) {
- X if (*ptr=='\n'||*ptr==' ')
- X {*ptr='\0'; break;}
- X }
- X break;/*for loop*/
- X }
- X }
- X if (*fname) {
- X if((newdes = fopen(fname,"r")) != NULL) {
- X fetch(newdes);
- X fclose(newdes);
- X } else {
- X fprintf(stderr, "%s: can't open .PS file '%s'.\n",
- X MyName, fname);
- X exit(1);
- X#ifdef CTRACE
- Xctroff();
- X#endif
- X }
- X } else fputs(buff,stdout); /* regular .PS */
- X } else {
- X fputs(buff, stdout); } /* Starts with "." */
- X } else fputs(buff, stdout); /* Doesn't start with "." */
- X }
- X}
- EOF
- # Bill Stewart, AT&T Bell Labs 2G-202, Holmdel NJ 1-201-949-0705 ihnp4!ho95c!wcs
-
-
-