home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V7 / usr / src / libI77 / dfe.c < prev    next >
Encoding:
C/C++ Source or Header  |  1979-01-10  |  1.9 KB  |  111 lines

  1. #include "fio.h"
  2. #include "fmt.h"
  3. extern int rd_ed(),rd_ned(),y_getc(),y_putc(),y_err();
  4. extern int y_rev();
  5. extern int w_ed(),w_ned();
  6. s_rdfe(a) cilist *a;
  7. {
  8.     int n;
  9.     if(!init) f_init();
  10.     if(n=c_dfe(a,READ))return(n);
  11.     reading=1;
  12.     if(curunit->uwrt) nowreading(curunit);
  13.     getn = y_getc;
  14.     doed = rd_ed;
  15.     doned = rd_ned;
  16.     dorevert = donewrec = y_err;
  17.     doend = y_rev;
  18.     if(pars_f(fmtbuf)<0)
  19.         err(a->cierr,100,"startio");
  20.     fmt_bg();
  21.     return(0);
  22. }
  23. s_wdfe(a) cilist *a;
  24. {
  25.     int n;
  26.     if(!init) f_init();
  27.     if(n=c_dfe(a,WRITE)) return(n);
  28.     reading=0;
  29.     if(!curunit->uwrt) nowwriting(curunit);
  30.     putn = y_putc;
  31.     doed = w_ed;
  32.     doned= w_ned;
  33.     dorevert = donewrec = y_err;
  34.     doend = y_rev;
  35.     if(pars_f(fmtbuf)<0)
  36.         err(a->cierr,100,"startwrt");
  37.     fmt_bg();
  38.     return(0);
  39. }
  40. e_rdfe()
  41. {
  42.     en_fio();
  43.     return(0);
  44. }
  45. e_wdfe()
  46. {
  47.     en_fio();
  48.     return(0);
  49. }
  50. c_dfe(a,flag) cilist *a;
  51. {
  52.     sequential=0;
  53.     formatted=external=1;
  54.     elist=a;
  55.     cursor=scale=recpos=0;
  56.     if(a->ciunit>MXUNIT || a->ciunit<0)
  57.         err(a->cierr,101,"startchk");
  58.     curunit = &units[a->ciunit];
  59.     if(curunit->ufd==NULL && fk_open(flag,DIR,FMT,a->ciunit))
  60.         err(a->cierr,104,"dfe");
  61.     cf=curunit->ufd;
  62.     if(!curunit->ufmt) err(a->cierr,102,"dfe")
  63.     if(!curunit->useek) err(a->cierr,104,"dfe")
  64.     fmtbuf=a->cifmt;
  65.     fseek(cf,(long)curunit->url * (a->cirec-1),0);
  66.     curunit->uend = 0;
  67.     return(0);
  68. }
  69. y_getc()
  70. {
  71.     int ch;
  72.     if(curunit->uend) return(-1);
  73.     if((ch=getc(cf))!=EOF)
  74.     {
  75.         recpos++;
  76.         if(curunit->url>=recpos ||
  77.             curunit->url==1)
  78.             return(ch);
  79.         else    return(' ');
  80.     }
  81.     if(feof(cf))
  82.     {
  83.         curunit->uend=1;
  84.         errno=0;
  85.         return(-1);
  86.     }
  87.     err(elist->cierr,errno,"readingd");
  88. }
  89. y_putc(c)
  90. {
  91.     recpos++;
  92.     if(recpos <= curunit->url || curunit->url==1)
  93.         putc(c,cf);
  94.     else
  95.         err(elist->cierr,110,"dout");
  96.     return(0);
  97. }
  98. y_rev()
  99. {    /*what about work done?*/
  100.     if(curunit->url==1 || recpos==curunit->url)
  101.         return(0);
  102.     while(recpos<curunit->url)
  103.         (*putn)(' ');
  104.     recpos=0;
  105.     return(0);
  106. }
  107. y_err()
  108. {
  109.     err(elist->cierr, 110, "dfe");
  110. }
  111.