home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / unix / volume08 / soelim < prev    next >
Encoding:
Text File  |  1988-09-11  |  7.1 KB  |  221 lines

  1. Subject:  v08i058:  A .so/.nx/.PS filter for *roff files
  2. Newsgroups: mod.sources
  3. Approved: mirror!rs
  4.  
  5. Submitted by: cbosgd!ho95e!wcs (Bill Stewart)
  6. Mod.sources: Volume 8, Issue 58
  7. Archive-name: soelim
  8.  
  9. I also needed an soelim a couple years ago, mainly to use troff in a
  10. distributed environment.  A program called "catso" was posted by J.
  11. Leth of Bell Labs, which handled .so and .nx ; I added support for .PS
  12. (pic).  I used Leth's code because Bill Joy's original soelim was ugly
  13. goto-code, but soelim was the right name to use.
  14.  
  15. [  I wrote the Makefile.  If you don't have strtok(), you should pick
  16.    up Henry Spencer's stringlib package from the archive, which has it.
  17.    --r$ ]
  18. echo "Unpacking Makefile"
  19. sed 's/^X//' >Makefile <<EOF
  20. X# Makefile for soelim.
  21. Xsoelim:        soelim.c
  22. X    $(CC) $(CFLAGS) -o soelim soelim.c
  23. Xinstall:    soelim
  24. X    @echo Copy soelim and soelim.1 to appropriate directories
  25. EOF
  26. echo "Unpacking soelim.1"
  27. sed 's/^X//' >soelim.1 <<EOF
  28. X.ad b
  29. X.de In        \" Space and indent
  30. X.sp
  31. X.in +4
  32. X..
  33. X.de Un        \" Space and undent
  34. X.sp
  35. X.in -4
  36. X..
  37. X.TH SOELIM 1 "LOCAL"
  38. X.SH NAME
  39. Xsoelim - Cats files, interpreting nroff/troff-style file inclusion
  40. X.SH SYNOPSIS
  41. X\fBsoelim\fR [ file or \fB-\fR ] ...
  42. X.SH DESCRIPTION
  43. X\fIsoelim\fR concatenates the files together, recursively inserting
  44. Xfiles referenced by the nroff/troff commands '.so', '.PS', and '.nx' in their
  45. Xproper positions.
  46. XWhen interpreting a '.so' command, the named file is itself \fIsoelim\fRd
  47. Xat that point, then processing resumes in the file that contained the '.so'
  48. Xcommand.
  49. XFiles referenced by '.nx' are treated the same, except that processing
  50. Xstops after the file referenced by the '.nx' command.
  51. X.P
  52. X\fISoelim\fR is useful for providing input to an \fInroff/troff\fR(1)
  53. Xpreprocessor, such as \fInrpp\fR(1), since normally the files referenced by
  54. Xthe .so and .nx commands will not be seen by the preprocessor.
  55. X.P
  56. XThe file name '-' means standard input.
  57. XStandard input will also be used if no arguments are given, unless
  58. Xthe input is connected to the terminal.
  59. XIn the latter case, \fIsoelim\fR will print its usage instructions.
  60. X.SH FILES
  61. X.SH AUTHOR
  62. XJ. Leth, IH 55414 6B-326, x6133 - His version was called "catso".
  63. X(Based on an earlier version by D. A. Spicer).
  64. X(Most recent version W. C. Stewart, HO 46133 2G218 x0705 - most of the
  65. Xcode is Leth's, with .PS stuff added.  Bill Joy wrote the original
  66. X"soelim" for Berkeley UNIX in 1977.)
  67. X.SH SEE ALSO
  68. Xnroff/troff(1), mm(1), pic(1)
  69. X.SH DIAGNOSTICS
  70. X"Can't open [ .nx | .so ] file '<filename>'." -- the argument file, .so
  71. Xfile, or .nx file can't be read or does not exist.
  72. X.SH BUGS
  73. XWill not interpret commands imbedded in macros or conditionals, or commands
  74. Xfollowing a ';'.  The .so, .PS, or .nx macro must be followed by at
  75. Xleast one tab or space.
  76. X(This is a "feature" to prevent trashing of lines like:
  77. X.br
  78. X    .something
  79. X.br
  80. X)
  81. EOF
  82. echo "Unpacking soelim.c"
  83. sed 's/^X//' >soelim.c <<EOF
  84. X#include <stdio.h>
  85. X#include <string.h>
  86. X
  87. X/* Renamed soelim and .PS support added - Bill Stewart
  88. X    AT&T Bell Labs 2G-218, Holmdel NJ 1-201-949-0705 ihnp4!ho95c!wcs*/
  89. X/* Catso will cat the standard input to the standard output, inserting
  90. X * all files referenced by the nroff commands '.so' or '.nx'.
  91. X *  J. Leth, IH 55414 6B-326, x6133.
  92. X *  (original program from: D. A. Spicer)
  93. X */
  94. X
  95. X#define SPACE " \t\n"
  96. X#define MAXLINE 511
  97. X
  98. Xchar buff[MAXLINE];
  99. X
  100. Xchar *MyName;
  101. Xint verbose=0;
  102. X
  103. Xmain(argc, argv)
  104. X    int argc;
  105. X    char *argv[];
  106. X{
  107. X    FILE *inp;
  108. X    int i;
  109. X    void exit();    /* Make lint quiet */
  110. X
  111. X#ifdef CTRACE
  112. Xctroff();
  113. X#endif
  114. X    if (isatty(0)  &&  argc == 1) {
  115. X        /* If input is from the terminal, and there are no args,
  116. X         * print usage instructions and exit.
  117. X         */
  118. X
  119. X        fprintf(stderr, "Usage:\t%s [ file or '-' ] ...\n\
  120. X    Cats the files (standard input, default) together, inserting\n\
  121. X    files referenced by the nroff commands '.so' and '.nx' in their\n\
  122. X    proper positions.  File name '-' means standard input\n", *argv[0]);
  123. X        exit(1);
  124. X    };
  125. X
  126. X    MyName = argv[0];
  127. X    if (strcmp(argv[1],"-v")==0) {verbose++; argc--; argv++; printf("Verbose!\n");}
  128. X    if (argc == 1) {
  129. X        fetch(stdin);
  130. X    } else {
  131. X        for (i=1; i < argc; ++i) {
  132. X            if (strcmp(argv[i], "-") == 0) {
  133. X                fetch(stdin);
  134. X            } else {
  135. X                inp = fopen(argv[i], "r");
  136. X                if (inp == NULL) {
  137. X                    fprintf(stderr,
  138. X                        "%s: can't open file '%s'.\n",
  139. X                        MyName,argv[i]);
  140. X                } else {
  141. X                    fetch(inp);
  142. X                }
  143. X            }
  144. X        }
  145. X    }
  146. X    return (0); /* If you get here, you're OK */
  147. X}
  148. X
  149. Xfetch(fdes)
  150. X    FILE *fdes;
  151. X{
  152. X    FILE *newdes;
  153. X    char *fname, *ptr;
  154. X    void exit();
  155. X
  156. X    while(fgets(buff,sizeof(buff),fdes) != NULL ) {
  157. X        /* strncpy(line, buff, sizeof(line)); */
  158. X        if (buff[0]=='.' &&
  159. X                (buff[3]==' '||buff[3]=='\t' || buff[3]=='<')) {
  160. X            if (strncmp(buff, ".so", 3) == 0) {
  161. X                fname = strtok(buff+3, SPACE);
  162. X                if((newdes = fopen(fname,"r")) != NULL) {
  163. X                    fetch(newdes);
  164. X                    fclose(newdes);
  165. X                } else {
  166. X                    fprintf(stderr, "%s: can't open .so file '%s'.\n",
  167. X                        MyName, fname);
  168. X                    exit(1);
  169. X                }
  170. X            } else if (strncmp(buff, ".nx", 3) == 0) {
  171. X                fname = strtok(buff+3, SPACE);
  172. X                if((newdes = fopen(fname,"r")) != NULL) {
  173. X                    fclose(fdes);
  174. X                    fetch(newdes);
  175. X                    fclose(newdes);
  176. X                } else {
  177. X                    fprintf(stderr, "%s: can't open .nx file '%s'.\n",
  178. X                            MyName, fname);
  179. X                    exit(1);
  180. X                }
  181. X                exit(0);
  182. X            } else if (strncmp(buff, ".PS", 3) == 0) {
  183. X#ifdef CTRACE
  184. Xctron();
  185. Xbuff;
  186. X#endif
  187. X                fname=NULL;
  188. X                for (ptr=buff+3; *ptr; ptr++){
  189. X                    if (*ptr=='<') {
  190. X            for (ptr++; *ptr==' '||*ptr=='\t'; ptr++) ;
  191. X                        fname=ptr;
  192. X                        while (*ptr++) {
  193. X                            if (*ptr=='\n'||*ptr==' ')
  194. X                                {*ptr='\0'; break;}
  195. X                        }
  196. X                        break;/*for loop*/
  197. X                    }
  198. X                }
  199. X                if (*fname) {
  200. X                    if((newdes = fopen(fname,"r")) != NULL) {
  201. X                        fetch(newdes);
  202. X                        fclose(newdes);
  203. X                    } else {
  204. X                        fprintf(stderr, "%s: can't open .PS file '%s'.\n",
  205. X                                MyName, fname);
  206. X                        exit(1);
  207. X#ifdef CTRACE
  208. Xctroff();
  209. X#endif
  210. X                    }
  211. X                } else fputs(buff,stdout); /* regular .PS */
  212. X            } else {
  213. X                fputs(buff, stdout); }  /* Starts with "." */
  214. X        } else fputs(buff, stdout); /* Doesn't start with "." */
  215. X    }
  216. X}
  217. EOF
  218. # Bill Stewart, AT&T Bell Labs 2G-202, Holmdel NJ 1-201-949-0705 ihnp4!ho95c!wcs
  219.  
  220.  
  221.