Annotation of 41BSD/lib/libI77uc/dfe.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * direct formatted external i/o
                      3:  */
                      4: 
                      5: #include "fio.h"
                      6: 
                      7: extern int rd_ed(),rd_ned(),w_ed(),w_ned();
                      8: int y_getc(),y_putc(),y_rnew(),y_wnew(),y_tab();
                      9: 
                     10: char *dfe = "dfe";
                     11: char *rdfe = "read dfe";
                     12: char *wdfe = "write dfe";
                     13: 
                     14: s_rdfe(a) cilist *a;
                     15: {
                     16:        int n;
                     17:        reading = YES;
                     18:        if(n=c_dfe(a,READ)) return(n);
                     19:        if(curunit->uwrt) nowreading(curunit);
                     20:        getn = y_getc;
                     21:        doed = rd_ed;
                     22:        doned = rd_ned;
                     23:        dotab = y_tab;
                     24:        dorevert = doend = donewrec = y_rnew;
                     25:        if(pars_f(fmtbuf)) err(errflag,100,rdfe)
                     26:        fmt_bg();
                     27:        return(OK);
                     28: }
                     29: 
                     30: s_wdfe(a) cilist *a;
                     31: {
                     32:        int n;
                     33:        reading = NO;
                     34:        if(n=c_dfe(a,WRITE)) return(n);
                     35:        curunit->uend = NO;
                     36:        if(!curunit->uwrt) nowwriting(curunit);
                     37:        putn = y_putc;
                     38:        doed = w_ed;
                     39:        doned = w_ned;
                     40:        dotab = y_tab;
                     41:        dorevert = doend = donewrec = y_wnew;
                     42:        if(pars_f(fmtbuf)) err(errflag,100,wdfe)
                     43:        fmt_bg();
                     44:        return(OK);
                     45: }
                     46: 
                     47: e_rdfe()
                     48: {
                     49:        en_fio();
                     50:        return(OK);
                     51: }
                     52: 
                     53: e_wdfe()
                     54: {
                     55:        en_fio();
                     56:        return(OK);
                     57: }
                     58: 
                     59: c_dfe(a,flag) cilist *a;
                     60: {      int n;
                     61:        sequential = NO;
                     62:        external = formatted = FORMATTED;
                     63:        lfname = NULL;
                     64:        elist = NO;
                     65:        cursor=scale=recpos=reclen=0;
                     66:        radix = 10;
                     67:        signit = YES;
                     68:        fmtbuf = a->cifmt;
                     69:        errflag = a->cierr;
                     70:        endflag = a->ciend;
                     71:        lunit = a->ciunit;
                     72:        if(not_legal(lunit)) err(errflag,101,dfe);
                     73:        curunit = &units[lunit];
                     74:        if(!curunit->ufd && (n=fk_open(flag,DIR,FMT,(ftnint)lunit)))
                     75:                err(errflag,n,dfe)
                     76:        cf = curunit->ufd;
                     77:        elist = YES;
                     78:        lfname = curunit->ufnm;
                     79:        if(!curunit->ufmt) err(errflag,102,dfe)
                     80:        if(!curunit->useek || !curunit->url) err(errflag,104,dfe)
                     81:        recnum = a->cirec - 1;
                     82:        fseek(cf, (long)curunit->url * recnum, 0);
                     83:        cblank = curunit->ublnk;
                     84:        cplus = NO;
                     85:        return(OK);
                     86: }
                     87: 
                     88: y_getc()
                     89: {
                     90:        int ch;
                     91:        if(curunit->uend) return(EOF);
                     92:        if(curunit->url==1 || recpos++ < curunit->url)
                     93:        {
                     94:                if((ch=getc(cf))!=EOF)
                     95:                {
                     96:                                return(ch);
                     97:                }
                     98:                if(feof(cf))
                     99:                {
                    100:                        curunit->uend = YES;
                    101:                        return(EOF);
                    102:                }
                    103:                err(errflag,errno,rdfe);
                    104:        }
                    105:        else return(' ');
                    106: }
                    107: 
                    108: y_putc(c)
                    109: {
                    110:        if(curunit->url!=1 && recpos++ >= curunit->url) err(errflag,110,wdfe)
                    111:        putc(c,cf);
                    112:        return(OK);
                    113: }
                    114: 
                    115: y_tab()
                    116: {      int n;
                    117:        if(curunit->url==1)
                    118:        {
                    119:                if(cursor < 0 && -cursor > ftell(cf)) return(107);
                    120:        }
                    121:        else
                    122:        {       if(reclen < recpos) reclen = recpos;
                    123:                if((recpos + cursor) < 0) return(107);
                    124:                n = reclen - recpos;            /* n >= 0 */
                    125:                if(!reading && (cursor-n) > 0)
                    126:                {       recpos = reclen;
                    127:                        cursor -= n;
                    128:                        fseek(cf,(long)n,1);
                    129:                        while(cursor--) if(n=(*putn)(' ')) return(n);
                    130:                        return(cursor=0);
                    131:                }
                    132:                recpos += cursor;
                    133:                if(recpos >= curunit->url) err(errflag,110,dfe)
                    134:        }
                    135:        fseek(cf,(long)cursor,1);
                    136:        return(cursor=0);
                    137: }
                    138: 
                    139: /*
                    140: /*y_rev()
                    141: /*{    /*what about work done?*/
                    142: /*     if(curunit->url==1) return(0);
                    143: /*     while(recpos<curunit->url) (*putn)(' ');
                    144: /*     recpos=0;
                    145: /*     return(0);
                    146: /*}
                    147: /*
                    148: /*y_err()
                    149: /*{
                    150: /*     err(errflag, 110, dfe);
                    151: /*}
                    152: */
                    153: 
                    154: y_rnew()
                    155: {      if(curunit->url != 1)
                    156:        {       fseek(cf,(long)curunit->url*(++recnum),0);
                    157:                recpos = reclen = cursor = 0;
                    158:        }
                    159:        return(OK);
                    160: }
                    161: 
                    162: y_wnew()
                    163: {      if(curunit->url != 1)
                    164:        {       if(reclen > recpos)
                    165:                {       fseek(cf,(long)(reclen-recpos),1);
                    166:                        recpos = reclen;
                    167:                }
                    168:                while(recpos < curunit->url) (*putn)(' ');
                    169:                recnum++;
                    170:                recpos = reclen = cursor = 0;
                    171:        }
                    172:        return(OK);
                    173: }
                    174: 
                    175: y_rend()
                    176: {
                    177:        return(OK);
                    178: }
                    179: 
                    180: y_wend()
                    181: {
                    182:        return(y_wnew());
                    183: }

unix.superglobalmegacorp.com

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