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_dfe.c 5.4 (Berkeley) 04/12/91";
10 #endif /* not lint */
11
12 /*
13 * direct formatted external i/o - common read/write routines
14 */
15
16 #include "fio.h"
17
c_dfe(a,flg,str)18 c_dfe(a,flg,str) cilist *a; char *str;
19 { int n;
20 sequential = NO;
21 external = YES;
22 formatted = FORMATTED;
23 lfname = NULL;
24 elist = NO;
25 cursor=scale=recpos=reclen=0;
26 radix = 10;
27 signit = YES;
28 fmtbuf = a->cifmt;
29 errflag = a->cierr;
30 endflag = a->ciend;
31 lunit = a->ciunit;
32 if(not_legal(lunit)) err(errflag,F_ERUNIT,str);
33 curunit = &units[lunit];
34 if(!curunit->ufd && (n=fk_open(flg,DIR,FMT,(ftnint)lunit)))
35 err(errflag,n,str)
36 cf = curunit->ufd;
37 elist = YES;
38 lfname = curunit->ufnm;
39 if(!curunit->ufmt) err(errflag,F_ERNOFIO,str)
40 if(!curunit->useek || !curunit->url) err(errflag,F_ERNODIO,str)
41 recnum = a->cirec - 1;
42 fseek(cf, (long)curunit->url * recnum, 0);
43 cblank = curunit->ublnk;
44 cplus = NO;
45 return(OK);
46 }
47
y_tab()48 y_tab()
49 { int n;
50 if(curunit->url==1)
51 {
52 if(cursor < 0 && -cursor > ftell(cf)) rewind(cf);
53 else fseek(cf,(long)cursor,1);
54 return(cursor=0);
55 }
56 else
57 { if(reclen < recpos) reclen = recpos;
58 if((recpos + cursor) < 0) cursor = -recpos; /* BOR */
59 n = reclen - recpos; /* n >= 0 */
60 if(!reading && (cursor-n) > 0)
61 { recpos = reclen;
62 cursor -= n;
63 fseek(cf,(long)n,1);
64 while(cursor--) if(n=(*putn)(' ')) return(n);
65 return(cursor=0);
66 }
67 recpos += cursor;
68 if(recpos >= curunit->url) err(errflag,F_EREREC,"dfe")
69 }
70 fseek(cf,(long)cursor,1);
71 return(cursor=0);
72 }
73