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