1 /*- 2 * Copyright (c) 1980 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.proprietary.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)wsfe.c 5.4 (Berkeley) 04/12/91"; 10 #endif /* not lint */ 11 12 /* 13 * write sequential formatted external 14 */ 15 16 #include "fio.h" 17 18 LOCAL char wsfe[] = "write sfe"; 19 20 extern int w_ed(),w_ned(); 21 int x_putc(),pr_put(),x_wend(),x_wnew(),x_tab(); 22 LOCAL ioflag new; 23 24 s_wsfe(a) cilist *a; /*start*/ 25 { int n; 26 reading = NO; 27 sequential = YES; 28 if(n=c_sfe(a,WRITE,SEQ,wsfe)) return(n); 29 if(curunit->url) err(errflag,F_ERNOSIO,wsfe) 30 if(!curunit->uwrt && ! nowwriting(curunit)) err(errflag, errno, wsfe) 31 curunit->uend = NO; 32 if (curunit->uprnt) putn = pr_put; 33 else putn = x_putc; 34 new = YES; 35 doed= w_ed; 36 doned= w_ned; 37 doend = x_wend; 38 dorevert = donewrec = x_wnew; 39 dotab = x_tab; 40 if(pars_f()) err(errflag,F_ERFMT,wsfe) 41 fmt_bg(); 42 return(OK); 43 } 44 45 LOCAL 46 x_putc(c) 47 { 48 if(c=='\n') recpos = reclen = cursor = 0; 49 else recpos++; 50 putc(c,cf); 51 return(OK); 52 } 53 54 LOCAL 55 pr_put(c) 56 { 57 if(c=='\n') 58 { new = YES; 59 recpos = reclen = cursor = 0; 60 } 61 else if(new) 62 { new = NO; 63 if(c=='0') c = '\n'; 64 else if(c=='1') c = '\f'; 65 else return(OK); 66 } 67 else recpos++; 68 putc(c,cf); 69 return(OK); 70 } 71 72 LOCAL 73 x_wnew() 74 { 75 if(reclen>recpos) fseek(cf,(long)(reclen-recpos),1); 76 return((*putn)('\n')); 77 } 78 79 LOCAL 80 x_wend(last) char last; 81 { 82 if(reclen>recpos) fseek(cf,(long)(reclen-recpos),1); 83 if(last) 84 return((*putn)(last)); 85 else 86 return(OK); 87 } 88 89 e_wsfe() 90 { int n; 91 n=en_fio(); 92 fmtbuf=NULL; 93 return(n); 94 } 95