home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume7 / sop < prev    next >
Text File  |  1986-10-15  |  4KB  |  137 lines

  1. Subject:  v07i033:  A .so filter for n/t/*roff files
  2. Newsgroups: mod.sources
  3. Approved: mirror!rs
  4.  
  5. Submitted by: Davidsen <seismo!rochester!steinmetz!davidsen>
  6. Mod.sources: Volume 7, Issue 33
  7. Archive-name: sop
  8.  
  9.  
  10. [ This seems to be pretty much the same as BSD 'soelim' program. --r$ ]
  11.  
  12.  
  13. #!/bin/sh
  14. # created from directory /usr2/davidsen/UNaXcess/uguide
  15. echo shar created 13:27 on Wed Aug 27, 1986 by davidsen
  16. echo 'x - readme.sop (text)'
  17. sed << 'E!O!F' 's/^X//' > readme.sop
  18. XI found out the hard way that I couldn't use tables and equations in
  19. Xfiles included in nroff documents via the ".so" mechanism. The tbl and
  20. Xeqn processors just don't know about ".so". Therefore I wrote a small
  21. Xprogram to preprocess the .so commands and allow use of tables anywhere.
  22. X
  23. E!O!F
  24. echo 'x - sop.1 (text)'
  25. sed << 'E!O!F' 's/^X//' > sop.1
  26. X'\" @(#)skeleton    3.3 - 12/21/83
  27. X'\" [c][e][t] (only if preprocessing by cw, eqn, and/or tbl required)
  28. X.TH sop 1 local
  29. X'\" Heading: name(sect)    center (paren)    name(sect)
  30. X.SH NAME
  31. Xsop - preprocess .so commands in nroff files
  32. X.SH SYNOPSIS
  33. Xsop filename
  34. X.SH DESCRIPTION
  35. XThe \fIsop\fR processor allows the use of tables and equations in files
  36. Xaccessed via the ".so" nroff command. Since the
  37. X.I tbl
  38. Xand
  39. X.I eqn
  40. Xprocessors don't handle .so commands, this simple preprocessor will
  41. Xcreate a single output file on stdout, starting with an nroff file which
  42. Xmay contain .so commands.
  43. X.SH EXAMPLES
  44. X  sop myfile.n | tbl | nroff -mm -Thtm.12 | lp
  45. X.SH WARNINGS
  46. XNo attempt is made to handle .so commands contained in conditional
  47. Xexpressions. This program has not been tested with
  48. X.I troff
  49. X(although there is no reason to expect problems).
  50. X.SH SEE ALSO
  51. Xtbl(1), eqn(1), nroff(1).
  52. X.SH DIAGNOSTICS
  53. Xnone.
  54. X.SH LIMITATIONS
  55. XDoes not process conditional .so usage.
  56. X.SH AUTHOR
  57. XBill Davidsen, GE Corporate R&D Center.
  58. X(...ihnp4!chinet!crdos1!davidsen)
  59. X'\" For more details, see man(7), as well as man(1), manroff(1), and mmt(1)
  60. E!O!F
  61. echo 'x - sop.c (text)'
  62. sed << 'E!O!F' 's/^X//' > sop.c
  63. X/*
  64. X *  SOP - process .so commands
  65. X *  Bill Davidsen - 8/10/86
  66. X *
  67. X *  for those system in which the tbl and eqn processors don't
  68. X *  process .so commands and the included files require pro-
  69. X *  cessing.
  70. X *
  71. X *  Use:
  72. X *   sop firstfile | tbl | nroff ...
  73. X */
  74. X
  75. X#include <stdio.h>
  76. X#define LLEN    256        /* longest line to allow */
  77. X
  78. XFILE *stack[10],        /* file stack */
  79. X     *fp,            /* current file pointer */
  80. X     *fopen ();
  81. Xint  index = 0;            /* index into file stack */
  82. X
  83. Xchar  line[LLEN];        /* line buffer */
  84. X
  85. Xmain (argc, argv)
  86. X    int  argc;
  87. X    char *argv[];
  88. X{
  89. X    switch (argc)
  90. X    {
  91. X    case 1: /* use standard input */
  92. X    fp = stdin; /* read standard input */
  93. X    break;
  94. X    case 2: /* got a file to use */
  95. X    fp = fopen (argv[1], "r");
  96. X    if (fp == NULL)
  97. X    { /* bad filename */
  98. X        fprintf (stderr, "Can't open file %s\n", argv[1]);
  99. X        exit (1);
  100. X    }
  101. X    break;
  102. X    default: 
  103. X    fprintf (stderr, "Format\n  sop\n  -or-\n  sop filename\n");
  104. X    exit (1);
  105. X    }
  106. X
  107. X    while (fp != NULL)
  108. X    { /* read and scan for .so */
  109. X    if (fgets (line, LLEN, fp) == NULL)
  110. X    { /* end of file on current file */
  111. X        if (index)
  112. X        fp = stack[--index];
  113. X        else
  114. X        fp = NULL;
  115. X        continue;
  116. X    }
  117. X
  118. X    if (strncmp (line, ".so ", 4) == 0)
  119. X    { /* include this file */
  120. X        stack[index++] = fp;
  121. X    /* set newline to EOL */
  122. X        line[strlen (line) - 1] = 0;
  123. X    /* open the next file */
  124. X        fp = fopen (line + 4, "r");
  125. X        if (fp == NULL)
  126. X        { /* bad include file */
  127. X        fprintf (stderr, "Can't open include file %s\n", line + 4);
  128. X        exit (1);
  129. X        }
  130. X        continue;
  131. X    }
  132. X
  133. X    fputs (line, stdout);
  134. X    }
  135. X}
  136. E!O!F
  137.