| 1 | #include "f2c.h" |
| 2 | #include "fio.h" |
| 3 | #include "fmt.h" |
| 4 | |
| 5 | y_rsk(Void) |
| 6 | { |
| 7 | if(f__curunit->uend || f__curunit->url <= f__recpos |
| 8 | || f__curunit->url == 1) return 0; |
| 9 | do { |
| 10 | getc(f__cf); |
| 11 | } while(++f__recpos < f__curunit->url); |
| 12 | return 0; |
| 13 | } |
| 14 | y_getc(Void) |
| 15 | { |
| 16 | int ch; |
| 17 | if(f__curunit->uend) return(-1); |
| 18 | if((ch=getc(f__cf))!=EOF) |
| 19 | { |
| 20 | f__recpos++; |
| 21 | if(f__curunit->url>=f__recpos || |
| 22 | f__curunit->url==1) |
| 23 | return(ch); |
| 24 | else return(' '); |
| 25 | } |
| 26 | if(feof(f__cf)) |
| 27 | { |
| 28 | f__curunit->uend=1; |
| 29 | errno=0; |
| 30 | return(-1); |
| 31 | } |
| 32 | err(f__elist->cierr,errno,"readingd"); |
| 33 | #ifdef __cplusplus |
| 34 | return 0; |
| 35 | #endif |
| 36 | } |
| 37 | #ifdef KR_headers |
| 38 | y_putc(c) |
| 39 | #else |
| 40 | y_putc(int c) |
| 41 | #endif |
| 42 | { |
| 43 | f__recpos++; |
| 44 | if(f__recpos <= f__curunit->url || f__curunit->url==1) |
| 45 | putc(c,f__cf); |
| 46 | else |
| 47 | err(f__elist->cierr,110,"dout"); |
| 48 | return(0); |
| 49 | } |
| 50 | y_rev(Void) |
| 51 | { /*what about work done?*/ |
| 52 | if(f__curunit->url==1 || f__recpos==f__curunit->url) |
| 53 | return(0); |
| 54 | while(f__recpos<f__curunit->url) |
| 55 | (*f__putn)(' '); |
| 56 | f__recpos=0; |
| 57 | return(0); |
| 58 | } |
| 59 | y_err(Void) |
| 60 | { |
| 61 | err(f__elist->cierr, 110, "dfe"); |
| 62 | #ifdef __cplusplus |
| 63 | return 0; |
| 64 | #endif |
| 65 | } |
| 66 | |
| 67 | y_newrec(Void) |
| 68 | { |
| 69 | if(f__curunit->url == 1 || f__recpos == f__curunit->url) { |
| 70 | f__hiwater = f__recpos = f__cursor = 0; |
| 71 | return(1); |
| 72 | } |
| 73 | if(f__hiwater > f__recpos) |
| 74 | f__recpos = f__hiwater; |
| 75 | y_rev(); |
| 76 | f__hiwater = f__cursor = 0; |
| 77 | return(1); |
| 78 | } |
| 79 | |
| 80 | #ifdef KR_headers |
| 81 | c_dfe(a) cilist *a; |
| 82 | #else |
| 83 | c_dfe(cilist *a) |
| 84 | #endif |
| 85 | { |
| 86 | f__sequential=0; |
| 87 | f__formatted=f__external=1; |
| 88 | f__elist=a; |
| 89 | f__cursor=f__scale=f__recpos=0; |
| 90 | if(a->ciunit>MXUNIT || a->ciunit<0) |
| 91 | err(a->cierr,101,"startchk"); |
| 92 | f__curunit = &f__units[a->ciunit]; |
| 93 | if(f__curunit->ufd==NULL && fk_open(DIR,FMT,a->ciunit)) |
| 94 | err(a->cierr,104,"dfe"); |
| 95 | f__cf=f__curunit->ufd; |
| 96 | if(!f__curunit->ufmt) err(a->cierr,102,"dfe") |
| 97 | if(!f__curunit->useek) err(a->cierr,104,"dfe") |
| 98 | f__fmtbuf=a->cifmt; |
| 99 | (void) fseek(f__cf,(long)f__curunit->url * (a->cirec-1),SEEK_SET); |
| 100 | f__curunit->uend = 0; |
| 101 | return(0); |
| 102 | } |
| 103 | #ifdef KR_headers |
| 104 | integer s_rdfe(a) cilist *a; |
| 105 | #else |
| 106 | integer s_rdfe(cilist *a) |
| 107 | #endif |
| 108 | { |
| 109 | int n; |
| 110 | if(!f__init) f_init(); |
| 111 | if(n=c_dfe(a))return(n); |
| 112 | f__reading=1; |
| 113 | if(f__curunit->uwrt && f__nowreading(f__curunit)) |
| 114 | err(a->cierr,errno,"read start"); |
| 115 | f__getn = y_getc; |
| 116 | f__doed = rd_ed; |
| 117 | f__doned = rd_ned; |
| 118 | f__dorevert = f__donewrec = y_err; |
| 119 | f__doend = y_rsk; |
| 120 | if(pars_f(f__fmtbuf)<0) |
| 121 | err(a->cierr,100,"read start"); |
| 122 | fmt_bg(); |
| 123 | return(0); |
| 124 | } |
| 125 | #ifdef KR_headers |
| 126 | integer s_wdfe(a) cilist *a; |
| 127 | #else |
| 128 | integer s_wdfe(cilist *a) |
| 129 | #endif |
| 130 | { |
| 131 | int n; |
| 132 | if(!f__init) f_init(); |
| 133 | if(n=c_dfe(a)) return(n); |
| 134 | f__reading=0; |
| 135 | if(f__curunit->uwrt != 1 && f__nowwriting(f__curunit)) |
| 136 | err(a->cierr,errno,"startwrt"); |
| 137 | f__putn = y_putc; |
| 138 | f__doed = w_ed; |
| 139 | f__doned= w_ned; |
| 140 | f__dorevert = y_err; |
| 141 | f__donewrec = y_newrec; |
| 142 | f__doend = y_rev; |
| 143 | if(pars_f(f__fmtbuf)<0) |
| 144 | err(a->cierr,100,"startwrt"); |
| 145 | fmt_bg(); |
| 146 | return(0); |
| 147 | } |
| 148 | integer e_rdfe(Void) |
| 149 | { |
| 150 | (void) en_fio(); |
| 151 | return(0); |
| 152 | } |
| 153 | integer e_wdfe(Void) |
| 154 | { |
| 155 | (void) en_fio(); |
| 156 | return(0); |
| 157 | } |