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