|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1980 Regents of the University of California. ! 3: * All rights reserved. The Berkeley software License Agreement ! 4: * specifies the terms and conditions for redistribution. ! 5: * ! 6: * @(#)c_sfe.c 5.1 6/7/85 ! 7: */ ! 8: ! 9: /* ! 10: * sequential formatted external I/O - common read & write routines ! 11: */ ! 12: ! 13: #include "fio.h" ! 14: ! 15: c_sfe(a,parmflag,mode,str) cilist *a; char *str; /* check */ ! 16: { unit *p; ! 17: int n; ! 18: ! 19: external=formatted=FORMATTED; ! 20: fmtbuf=a->cifmt; ! 21: lfname = NULL; ! 22: elist = NO; ! 23: errflag = a->cierr; ! 24: endflag = a->ciend; ! 25: lunit = a->ciunit; ! 26: if(not_legal(lunit)) err(errflag,F_ERUNIT,str); ! 27: curunit = p = &units[lunit]; ! 28: if(!p->ufd && (n=fk_open(parmflag,mode,FMT,(ftnint)lunit)) ) ! 29: err(errflag,n,str) ! 30: cf = curunit->ufd; ! 31: elist = YES; ! 32: lfname = curunit->ufnm; ! 33: if(!p->ufmt) err(errflag,F_ERNOFIO,str) ! 34: cursor=recpos=scale=reclen=0; ! 35: radix = 10; ! 36: signit = YES; ! 37: cblank = curunit->ublnk; ! 38: cplus = NO; ! 39: return(OK); ! 40: } ! 41: ! 42: x_tab() ! 43: { int n; ! 44: if(reclen < recpos) reclen = recpos; ! 45: if(curunit->useek) ! 46: { if((recpos+cursor) < 0) cursor = -recpos; /* to BOR */ ! 47: n = reclen - recpos; /* distance to eor, n>=0 */ ! 48: if((cursor-n) > 0) ! 49: { fseek(cf,(long)n,1); /* find current eor */ ! 50: recpos = reclen; ! 51: cursor -= n; ! 52: } ! 53: else ! 54: { fseek(cf,(long)cursor,1); /* do not pass go */ ! 55: recpos += cursor; ! 56: return(cursor=0); ! 57: } ! 58: } ! 59: else ! 60: if(cursor < 0) return(F_ERSEEK); /* can't go back */ ! 61: while(cursor--) ! 62: { if(reading) ! 63: { n = (*getn)(); ! 64: if(n=='\n') return(cursor=0); /* be tolerant */ ! 65: if(n==EOF) return(EOF); ! 66: } ! 67: else (*putn)(' '); /* fill in the empty record */ ! 68: } ! 69: return(cursor=0); ! 70: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.