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