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