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