1: /* cpydgst.c - copy from one fd to another in encapsulating mode */
   2: 
   3: #include "../h/mh.h"
   4: #include <stdio.h>
   5: 
   6: 
   7: /* All we want to do is to perform the substitution
   8: 
   9: 	\n(-.*)\n	-->	\n- \1\n
  10: 
  11:     we could use
  12: 
  13: 	sed -e 's%^-%- -%' < ifile > ofile
  14: 
  15:     to do this, but the routine below is faster than the pipe, fork, and
  16:     exec.
  17:  */
  18: 
  19: #define S1  0
  20: #define S2  1
  21: 
  22: #define output(c)   if (bp >= dp) {flush(); *bp++ = c;} else *bp++ = c
  23: #define flush()     if ((j = bp - outbuf) && write (out, outbuf, j) != j) \
  24:             adios (ofile, "error writing"); \
  25:             else \
  26:             bp = outbuf
  27: 
  28: /*  */
  29: 
  30: void cpydgst (in, out, ifile, ofile)
  31: register int    in,
  32:                 out;
  33: register char  *ifile,
  34:                *ofile;
  35: {
  36:     register int    i,
  37:                     state;
  38:     register char  *cp,
  39:                    *ep;
  40:     char    buffer[BUFSIZ];
  41:     register int    j;
  42:     register char  *bp,
  43:                    *dp;
  44:     char    outbuf[BUFSIZ];
  45: 
  46:     dp = (bp = outbuf) + sizeof outbuf;
  47:     for (state = S1; (i = read (in, buffer, sizeof buffer)) > 0;)
  48:     for (ep = (cp = buffer) + i; cp < ep; cp++) {
  49:         if (*cp == NULL)
  50:         continue;
  51:         switch (state) {
  52:         case S1:
  53:             if (*cp == '-') {
  54:             output ('-');
  55:             output (' ');
  56:             }
  57:             state = S2; /* fall */
  58: 
  59:         case S2:
  60:             output (*cp);
  61:             if (*cp == '\n')
  62:             state = S1;
  63:             break;
  64:         }
  65:     }
  66: 
  67:     if (i == NOTOK)
  68:     adios (ifile, "error reading");
  69:     flush ();
  70: }

Defined functions

cpydgst defined in line 30; never used

Defined macros

S1 defined in line 19; used 2 times
S2 defined in line 20; used 1 times
  • in line 57
flush defined in line 23; used 2 times
output defined in line 22; used 3 times
Last modified: 1986-01-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 961
Valid CSS Valid XHTML 1.0 Strict