xref: /original-bsd/usr.bin/f77/libI77/rdfe.c (revision 37acaaf2)
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[] = "@(#)rdfe.c	5.2 (Berkeley) 04/12/91";
10 #endif /* not lint */
11 
12 /*
13  * read direct formatted external i/o
14  */
15 
16 #include "fio.h"
17 
18 extern int rd_ed(),rd_ned();
19 int y_getc(),y_rnew(),y_tab();
20 
21 LOCAL char rdfe[] = "read dfe";
22 
23 s_rdfe(a) cilist *a;
24 {
25 	int n;
26 	reading = YES;
27 	if(n=c_dfe(a,READ,rdfe)) return(n);
28 	if(curunit->uwrt && ! nowreading(curunit)) err(errflag, errno, rdfe)
29 	getn = y_getc;
30 	doed = rd_ed;
31 	doned = rd_ned;
32 	dotab = y_tab;
33 	dorevert = doend = donewrec = y_rnew;
34 	if(pars_f()) err(errflag,F_ERFMT,rdfe)
35 	fmt_bg();
36 	return(OK);
37 }
38 
39 e_rdfe()
40 {
41 	en_fio();
42 	return(OK);
43 }
44 
45 LOCAL
46 y_getc()
47 {
48 	int ch;
49 	if(curunit->uend) return(EOF);
50 	if(curunit->url==1 || recpos++ < curunit->url)
51 	{
52 		if((ch=getc(cf))!=EOF)
53 		{
54 				return(ch);
55 		}
56 		if(feof(cf))
57 		{
58 			curunit->uend = YES;
59 			return(EOF);
60 		}
61 		err(errflag,errno,rdfe);
62 	}
63 	else return(' ');
64 }
65 
66 /*
67 /*y_rev()
68 /*{	/*what about work done?*/
69 /*	if(curunit->url==1) return(0);
70 /*	while(recpos<curunit->url) (*putn)(' ');
71 /*	recpos=0;
72 /*	return(0);
73 /*}
74 /*
75 /*y_err()
76 /*{
77 /*	err(errflag, F_EREREC, rdfe+5);
78 /*}
79 */
80 
81 LOCAL
82 y_rnew()
83 {	if(curunit->url != 1)
84 	{	fseek(cf,(long)curunit->url*(++recnum),0);
85 		recpos = reclen = cursor = 0;
86 	}
87 	return(OK);
88 }
89