Annotation of 3BSD/new/libI77uc/sfe.c, revision 1.1.1.1

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,lunit)) ) err(errflag,n,"sfe")
                     72:        cf = curunit->ufd;
                     73:        elist = YES;
                     74:        lfname = curunit->ufnm;
                     75:        if(!p->ufmt) err(errflag,102,"sfe")
                     76:        if(p->url) err(errflag,105,"sfe")
                     77:        cursor=recpos=scale=reclen=0;
                     78:        radix = 10;
                     79:        signit = YES;
                     80:        cblank = curunit->ublnk;
                     81:        cplus = NO;
                     82:        return(OK);
                     83: }
                     84: 
                     85: /*
                     86:  * write sequential formatted external
                     87:  */
                     88: 
                     89: extern int w_ed(),w_ned();
                     90: int x_putc(),pr_put(),x_wend(),x_wnew();
                     91: ioflag new;
                     92: 
                     93: s_wsfe(a) cilist *a;   /*start*/
                     94: {      int n;
                     95:        reading = NO;
                     96:        if(n=c_sfe(a,WRITE)) return(n);
                     97:        if(!curunit->uwrt) nowwriting(curunit);
                     98:        curunit->uend = NO;
                     99:        if (curunit->uprnt) putn = pr_put;
                    100:        else putn = x_putc;
                    101:        new = YES;
                    102:        doed= w_ed;
                    103:        doned= w_ned;
                    104:        doend = x_wend;
                    105:        dorevert = donewrec = x_wnew;
                    106:        dotab = x_tab;
                    107:        if(pars_f(fmtbuf)) err(errflag,100,"write sfe")
                    108:        fmt_bg();
                    109:        return(OK);
                    110: }
                    111: 
                    112: x_putc(c)
                    113: {
                    114:        if(c=='\n') recpos = reclen = cursor = 0;
                    115:        else recpos++;
                    116:        putc(c,cf);
                    117:        return(OK);
                    118: }
                    119: 
                    120: pr_put(c)
                    121: {
                    122:        if(c=='\n')
                    123:        {       new = YES;
                    124:                recpos = reclen = cursor = 0;
                    125:        }
                    126:        else if(new)
                    127:        {       new = NO;
                    128:                if(c=='0') c = '\n';
                    129:                else if(c=='1') c = '\f';
                    130:                else return(OK);
                    131:        }
                    132:        else recpos++;
                    133:        putc(c,cf);
                    134:        return(OK);
                    135: }
                    136: 
                    137: x_tab()
                    138: {      int n;
                    139:        if(reclen < recpos) reclen = recpos;
                    140:        if(curunit->useek)
                    141:        {       if((recpos+cursor) < 0) return(107);
                    142:                n = reclen - recpos;    /* distance to eor, n>=0 */
                    143:                if((cursor-n) > 0)
                    144:                {       fseek(cf,(long)n,1);  /* find current eor */
                    145:                        recpos = reclen;
                    146:                        cursor -= n;
                    147:                }
                    148:                else
                    149:                {       fseek(cf,(long)cursor,1);  /* do not pass go */
                    150:                        recpos += cursor;
                    151:                        return(cursor=0);
                    152:                }
                    153:        }
                    154:        else
                    155:                if(cursor < 0) return(120);     /* cant go back */
                    156:        while(cursor--)
                    157:        {       if(reading)
                    158:                {       n = (*getn)();
                    159:                        if(n=='\n')
                    160:                        {       (*ungetn)(n,cf);
                    161:                                return(110);
                    162:                        }
                    163:                        if(n==EOF) return(EOF);
                    164:                }
                    165:                else    (*putn)(' ');   /* fill in the empty record */
                    166:        }
                    167:        return(cursor=0);
                    168: }
                    169: 
                    170: x_wnew()
                    171: {
                    172:        if(reclen>recpos) fseek(cf,(long)(reclen-recpos),1);
                    173:        return((*putn)('\n'));
                    174: }
                    175: 
                    176: x_wend(last) char last;
                    177: {
                    178:        if(reclen>recpos) fseek(cf,(long)(reclen-recpos),1);
                    179:        return((*putn)(last));
                    180: }
                    181: 
                    182: /*
                    183: /*xw_rev()
                    184: /*{
                    185: /*     if(workdone) x_wSL();
                    186: /*     return(workdone=0);
                    187: /*}
                    188: /*
                    189: */
                    190: e_wsfe()
                    191: {      return(e_rsfe()); }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.