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