home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fs.zip / octave / f2c / libi77 / wsfe.c < prev    next >
C/C++ Source or Header  |  2000-01-15  |  2KB  |  80 lines

  1. /*write sequential formatted external*/
  2. #include "f2c.h"
  3. #include "fio.h"
  4. #include "fmt.h"
  5. extern int f__hiwater;
  6.  
  7. #ifdef KR_headers
  8. x_putc(c)
  9. #else
  10. x_putc(int c)
  11. #endif
  12. {
  13.     /* this uses \n as an indicator of record-end */
  14.     if(c == '\n' && f__recpos < f__hiwater) {    /* fseek calls fflush, a loss */
  15. #ifndef NON_UNIX_STDIO
  16.         if(f__cf->_ptr + f__hiwater - f__recpos < buf_end(f__cf))
  17.             f__cf->_ptr += f__hiwater - f__recpos;
  18.         else
  19. #endif
  20.             (void) fseek(f__cf, (long)(f__hiwater - f__recpos), SEEK_CUR);
  21.     }
  22.     f__recpos++;
  23.     return putc(c,f__cf);
  24. }
  25. x_wSL(Void)
  26. {
  27.     (*f__putn)('\n');
  28.     f__recpos=0;
  29.     f__cursor = 0;
  30.     f__hiwater = 0;
  31.     return(1);
  32. }
  33. xw_end(Void)
  34. {
  35.     if(f__nonl == 0)
  36.         (*f__putn)('\n');
  37.     f__hiwater = f__recpos = f__cursor = 0;
  38.     return(0);
  39. }
  40. xw_rev(Void)
  41. {
  42.     if(f__workdone) (*f__putn)('\n');
  43.     f__hiwater = f__recpos = f__cursor = 0;
  44.     return(f__workdone=0);
  45. }
  46.  
  47. #ifdef KR_headers
  48. integer s_wsfe(a) cilist *a;    /*start*/
  49. #else
  50. integer s_wsfe(cilist *a)    /*start*/
  51. #endif
  52. {    int n;
  53.     if(!f__init) f_init();
  54.     if(n=c_sfe(a)) return(n);
  55.     f__reading=0;
  56.     f__sequential=1;
  57.     f__formatted=1;
  58.     f__external=1;
  59.     f__elist=a;
  60.     f__hiwater = f__cursor=f__recpos=0;
  61.     f__nonl = 0;
  62.     f__scale=0;
  63.     f__fmtbuf=a->cifmt;
  64.     f__curunit = &f__units[a->ciunit];
  65.     f__cf=f__curunit->ufd;
  66.     if(pars_f(f__fmtbuf)<0) err(a->cierr,100,"startio");
  67.     f__putn= x_putc;
  68.     f__doed= w_ed;
  69.     f__doned= w_ned;
  70.     f__doend=xw_end;
  71.     f__dorevert=xw_rev;
  72.     f__donewrec=x_wSL;
  73.     fmt_bg();
  74.     f__cplus=0;
  75.     f__cblank=f__curunit->ublnk;
  76.     if(f__curunit->uwrt != 1 && f__nowwriting(f__curunit))
  77.         err(a->cierr,errno,"write start");
  78.     return(0);
  79. }
  80.