home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V6 / usr / source / cref / src / put.c < prev    next >
Encoding:
C/C++ Source or Header  |  1975-05-13  |  800 b   |  60 lines

  1. int    bct[4];
  2. int    optr[4];
  3. char    bsp[2048];
  4.  
  5. char    *obuf[4]    {bsp,
  6.             bsp + 512,
  7.             bsp + 1024,
  8.             bsp + 1536
  9.             };
  10.  
  11. int    nflush;
  12.  
  13. put(fil,string,n)
  14.     char    *string;
  15. {
  16.     extern    utmp;
  17.     int    i;
  18.     char    *o;
  19.  
  20. /*printf("%d %c %d\n",fil,*string,n);/*DEBUG*/
  21.  
  22.     string--;
  23.  
  24.     if((i = optr[fil] + n - 512) >= 0) {
  25.         n =- i;
  26.         o = &obuf[fil][optr[fil]] -1;
  27.         while(--n >= 0)
  28.             *++o = *++string;
  29.         optr[fil] = 512;
  30.         flsh(fil);
  31.         n = i;
  32.     }
  33.  
  34.     o = &obuf[fil][optr[fil]] - 1;
  35.     optr[fil] =+ n;
  36.  
  37.     while(--n >= 0) {
  38.         *++o = *++string;
  39.     }
  40.     return(0);
  41. }
  42.  
  43. flsh(fil)
  44. {
  45.     extern    tp[],utmp;
  46.  
  47.     if(optr[fil] <= 0)    return(optr[fil]);
  48.  
  49.     if(bct[fil]++ >= 128 && utmp == 0) {
  50.         printf("Wraparound temp file %d\n",fil);
  51.         dexit();
  52.     }
  53.     nflush++;
  54.     if(write(tp[fil],obuf[fil],optr[fil]) != optr[fil])
  55.         return(-1);
  56.     optr[fil] = 0;
  57.     return(0);
  58. }
  59.  
  60.