|
|
1.1 ! root 1: /* ! 2: char id_sfe[] = "@(#)sfe.c 1.7"; ! 3: * ! 4: * sequential formatted external routines ! 5: */ ! 6: ! 7: #include "fio.h" ! 8: ! 9: /* ! 10: * read sequential formatted external ! 11: */ ! 12: ! 13: extern int rd_ed(),rd_ned(); ! 14: int x_rnew(),x_getc(),x_tab(); ! 15: ! 16: char rsfe[] = "read sfe"; ! 17: char wsfe[] = "write sfe"; ! 18: ! 19: s_rsfe(a) cilist *a; /* start */ ! 20: { int n; ! 21: reading = YES; ! 22: if(n=c_sfe(a,READ)) return(n); ! 23: if(curunit->uwrt && ! nowreading(curunit)) err(errflag, errno, rsfe) ! 24: getn= x_getc; ! 25: doed= rd_ed; ! 26: doned= rd_ned; ! 27: donewrec = dorevert = doend = x_rnew; ! 28: dotab = x_tab; ! 29: if(pars_f(fmtbuf)) err(errflag,F_ERFMT,rsfe) ! 30: fmt_bg(); ! 31: return(OK); ! 32: } ! 33: ! 34: x_rnew() /* find next record */ ! 35: { int ch; ! 36: if(curunit->uend) ! 37: return(EOF); ! 38: while((ch=getc(cf))!='\n' && ch!=EOF); ! 39: if(feof(cf)) ! 40: { curunit->uend = YES; ! 41: if (recpos==0) return(EOF); ! 42: } ! 43: cursor=recpos=reclen=0; ! 44: return(OK); ! 45: } ! 46: ! 47: x_getc() ! 48: { int ch; ! 49: if(curunit->uend) return(EOF); ! 50: if((ch=getc(cf))!=EOF && ch!='\n') ! 51: { recpos++; ! 52: return(ch); ! 53: } ! 54: if(ch=='\n') ! 55: { ungetc(ch,cf); ! 56: return(ch); ! 57: } ! 58: if(feof(cf)) curunit->uend = YES; ! 59: return(EOF); ! 60: } ! 61: ! 62: e_rsfe() ! 63: { int n; ! 64: n=en_fio(); ! 65: fmtbuf=NULL; ! 66: return(n); ! 67: } ! 68: ! 69: c_sfe(a,flag) cilist *a; /* check */ ! 70: { unit *p; ! 71: int n; ! 72: external=sequential=formatted=FORMATTED; ! 73: fmtbuf=a->cifmt; ! 74: lfname = NULL; ! 75: elist = NO; ! 76: errflag = a->cierr; ! 77: endflag = a->ciend; ! 78: lunit = a->ciunit; ! 79: if(not_legal(lunit)) err(errflag,F_ERUNIT,rsfe+5); ! 80: curunit = p = &units[lunit]; ! 81: if(!p->ufd && (n=fk_open(flag,SEQ,FMT,(ftnint)lunit)) ) ! 82: err(errflag,n,rsfe+5) ! 83: cf = curunit->ufd; ! 84: elist = YES; ! 85: lfname = curunit->ufnm; ! 86: if(!p->ufmt) err(errflag,F_ERNOFIO,rsfe+5) ! 87: if(p->url) err(errflag,F_ERNOSIO,rsfe+5) ! 88: cursor=recpos=scale=reclen=0; ! 89: radix = 10; ! 90: signit = YES; ! 91: cblank = curunit->ublnk; ! 92: cplus = NO; ! 93: return(OK); ! 94: } ! 95: ! 96: /* ! 97: * write sequential formatted external ! 98: */ ! 99: ! 100: extern int w_ed(),w_ned(); ! 101: int x_putc(),pr_put(),x_wend(),x_wnew(); ! 102: ioflag new; ! 103: ! 104: s_wsfe(a) cilist *a; /*start*/ ! 105: { int n; ! 106: reading = NO; ! 107: if(n=c_sfe(a,WRITE)) return(n); ! 108: if(!curunit->uwrt && ! nowwriting(curunit)) err(errflag, errno, wsfe) ! 109: curunit->uend = NO; ! 110: if (curunit->uprnt) putn = pr_put; ! 111: else putn = x_putc; ! 112: new = YES; ! 113: doed= w_ed; ! 114: doned= w_ned; ! 115: doend = x_wend; ! 116: dorevert = donewrec = x_wnew; ! 117: dotab = x_tab; ! 118: if(pars_f(fmtbuf)) err(errflag,F_ERFMT,wsfe) ! 119: fmt_bg(); ! 120: return(OK); ! 121: } ! 122: ! 123: x_putc(c) ! 124: { ! 125: if(c=='\n') recpos = reclen = cursor = 0; ! 126: else recpos++; ! 127: if (c) putc(c,cf); ! 128: return(OK); ! 129: } ! 130: ! 131: pr_put(c) ! 132: { ! 133: if(c=='\n') ! 134: { new = YES; ! 135: recpos = reclen = cursor = 0; ! 136: } ! 137: else if(new) ! 138: { new = NO; ! 139: if(c=='0') c = '\n'; ! 140: else if(c=='1') c = '\f'; ! 141: else return(OK); ! 142: } ! 143: else recpos++; ! 144: if (c) putc(c,cf); ! 145: return(OK); ! 146: } ! 147: ! 148: x_tab() ! 149: { int n; ! 150: if(reclen < recpos) reclen = recpos; ! 151: if(curunit->useek) ! 152: { if((recpos+cursor) < 0) cursor = -recpos; /* to BOR */ ! 153: n = reclen - recpos; /* distance to eor, n>=0 */ ! 154: if((cursor-n) > 0) ! 155: { fseek(cf,(long)n,1); /* find current eor */ ! 156: recpos = reclen; ! 157: cursor -= n; ! 158: } ! 159: else ! 160: { fseek(cf,(long)cursor,1); /* do not pass go */ ! 161: recpos += cursor; ! 162: return(cursor=0); ! 163: } ! 164: } ! 165: else ! 166: if(cursor < 0) return(F_ERSEEK); /* can't go back */ ! 167: while(cursor--) ! 168: { if(reading) ! 169: { n = (*getn)(); ! 170: if(n=='\n') return(F_EREREC); ! 171: if(n==EOF) return(EOF); ! 172: } ! 173: else (*putn)(' '); /* fill in the empty record */ ! 174: } ! 175: return(cursor=0); ! 176: } ! 177: ! 178: x_wnew() ! 179: { ! 180: if(reclen>recpos) fseek(cf,(long)(reclen-recpos),1); ! 181: return((*putn)('\n')); ! 182: } ! 183: ! 184: x_wend(last) char last; ! 185: { ! 186: if(reclen>recpos) fseek(cf,(long)(reclen-recpos),1); ! 187: return((*putn)(last)); ! 188: } ! 189: ! 190: /* ! 191: /*xw_rev() ! 192: /*{ ! 193: /* if(workdone) x_wSL(); ! 194: /* return(workdone=0); ! 195: /*} ! 196: /* ! 197: */ ! 198: e_wsfe() ! 199: { return(e_rsfe()); }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.