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[] = "@(#)c_sfe.c 5.4 (Berkeley) 04/12/91";
10 #endif /* not lint */
11
12 /*
13 * sequential formatted external I/O - common read & write routines
14 */
15
16 #include "fio.h"
17
c_sfe(a,flg,mode,str)18 c_sfe(a,flg,mode,str) cilist *a; char *str; /* check */
19 { unit *p;
20 int n;
21
22 external=YES;
23 formatted=FORMATTED;
24 fmtbuf=a->cifmt;
25 lfname = NULL;
26 elist = NO;
27 errflag = a->cierr;
28 endflag = a->ciend;
29 lunit = a->ciunit;
30 if(not_legal(lunit)) err(errflag,F_ERUNIT,str);
31 curunit = p = &units[lunit];
32 if(!p->ufd && (n=fk_open(flg,mode,FMT,(ftnint)lunit)) )
33 err(errflag,n,str)
34 cf = curunit->ufd;
35 elist = YES;
36 lfname = curunit->ufnm;
37 if(!p->ufmt) err(errflag,F_ERNOFIO,str)
38 cursor=recpos=scale=reclen=0;
39 radix = 10;
40 signit = YES;
41 cblank = curunit->ublnk;
42 cplus = NO;
43 return(OK);
44 }
45
x_tab()46 x_tab()
47 { int n;
48 if(reclen < recpos) reclen = recpos;
49 if(curunit->useek)
50 { if((recpos+cursor) < 0) cursor = -recpos; /* to BOR */
51 n = reclen - recpos; /* distance to eor, n>=0 */
52 if((cursor-n) > 0)
53 { fseek(cf,(long)n,1); /* find current eor */
54 recpos = reclen;
55 cursor -= n;
56 }
57 else
58 { fseek(cf,(long)cursor,1); /* do not pass go */
59 recpos += cursor;
60 return(cursor=0);
61 }
62 }
63 else
64 if(cursor < 0) return(F_ERSEEK); /* can't go back */
65 while(cursor--)
66 { if(reading)
67 { n = (*getn)();
68 if(n=='\n') return(cursor=0); /* be tolerant */
69 if(n==EOF) return(EOF);
70 }
71 else (*putn)(' '); /* fill in the empty record */
72 }
73 return(cursor=0);
74 }
75