xref: /original-bsd/usr.bin/f77/libI77/rsfe.c (revision 6e73d10f)
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[] = "@(#)rsfe.c	5.3 (Berkeley) 04/12/91";
10 #endif /* not lint */
11 
12 /*
13  * read sequential formatted external
14  */
15 
16 #include "fio.h"
17 
18 extern int rd_ed(),rd_ned();
19 int x_rnew(),x_getc(),x_tab();
20 
21 LOCAL char rsfe[] = "read sfe";
22 
23 s_rsfe(a) cilist *a; /* start */
24 {	int n;
25 	reading = YES;
26 	sequential = YES;
27 	if(n=c_sfe(a,READ,SEQ,rsfe)) return (n);
28 	if(curunit->url) err(errflag,F_ERNOSIO,rsfe)
29 	if(curunit->uwrt && ! nowreading(curunit)) err(errflag, errno, rsfe)
30 	getn= x_getc;
31 	doed= rd_ed;
32 	doned= rd_ned;
33 	donewrec = dorevert = doend = x_rnew;
34 	dotab = x_tab;
35 	if(pars_f()) err(errflag,F_ERFMT,rsfe)
36 	fmt_bg();
37 	return(OK);
38 }
39 
40 LOCAL
41 x_rnew()			/* find next record */
42 {	int ch;
43 	if(curunit->uend)
44 		return(EOF);
45 	while((ch=getc(cf))!='\n' && ch!=EOF);
46 	if(feof(cf))
47 	{	curunit->uend = YES;
48 		if (recpos==0) return(EOF);
49 	}
50 	cursor=recpos=reclen=0;
51 	return(OK);
52 }
53 
54 LOCAL
55 x_getc()
56 {	int ch;
57 	if(curunit->uend) return(EOF);
58 	if((ch=getc(cf))!=EOF && ch!='\n')
59 	{	recpos++;
60 		return(ch);
61 	}
62 	if(ch=='\n')
63 	{	ungetc(ch,cf);
64 		return(ch);
65 	}
66 	if(feof(cf)) curunit->uend = YES;
67 	return(EOF);
68 }
69 
70 e_rsfe()
71 {	int n;
72 	n=en_fio();
73 	fmtbuf=NULL;
74 	return(n);
75 }
76