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