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