Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!ima!mirror!sources-request From: sources-request@mirror.UUCP Newsgroups: mod.sources Subject: v08i058: A .so/.nx/.PS filter for *roff files Message-ID: <1710@mirror.TMC.COM> Date: Thu, 12-Feb-87 13:01:25 EST Article-I.D.: mirror.1710 Posted: Thu Feb 12 13:01:25 1987 Date-Received: Fri, 13-Feb-87 06:18:14 EST Sender: rs@mirror.TMC.COM Lines: 214 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 <soelim.1 <'." -- 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 < X#include 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