xref: /original-bsd/usr.bin/f77/libI77/wdfe.c (revision 30ae0772)
1 /*
2 char id_wdfe[] = "@(#)wdfe.c	1.1";
3  *
4  * write direct formatted external i/o
5  */
6 
7 #include "fio.h"
8 
9 extern int w_ed(),w_ned();
10 int y_putc(),y_wnew(),y_tab();
11 
12 LOCAL char wdfe[] = "write dfe";
13 
14 s_wdfe(a) cilist *a;
15 {
16 	int n;
17 	reading = NO;
18 	if(n=c_dfe(a,WRITE,wdfe)) return(n);
19 	curunit->uend = NO;
20 	if(!curunit->uwrt && ! nowwriting(curunit)) err(errflag, errno, wdfe)
21 	putn = y_putc;
22 	doed = w_ed;
23 	doned = w_ned;
24 	dotab = y_tab;
25 	dorevert = doend = donewrec = y_wnew;
26 	if(pars_f()) err(errflag,F_ERFMT,wdfe)
27 	fmt_bg();
28 	return(OK);
29 }
30 
31 e_wdfe()
32 {
33 	en_fio();
34 	return(OK);
35 }
36 
37 LOCAL
38 y_putc(c)
39 {
40 	if(curunit->url!=1 && recpos++ >= curunit->url) err(errflag,F_EREREC,wdfe)
41 	putc(c,cf);
42 	return(OK);
43 }
44 
45 LOCAL
46 y_wnew()
47 {	if(curunit->url != 1)
48 	{	if(reclen > recpos)
49 		{	fseek(cf,(long)(reclen-recpos),1);
50 			recpos = reclen;
51 		}
52 		while(recpos < curunit->url) (*putn)(' ');
53 		recnum++;
54 		recpos = reclen = cursor = 0;
55 	}
56 	return(OK);
57 }
58