Annotation of researchv10dc/libI77/old/rdfmt.c, revision 1.1.1.1

1.1       root        1: /*     @(#)rdfmt.c     1.4     */
                      2: 
                      3: #include "fio.h"
                      4: #include "fmt.h"
                      5: extern int cursor;
                      6: rd_ed(p,ptr,len) char *ptr; struct syl *p; ftnlen len;
                      7: {      int ch;
                      8:        for(;cursor>0;cursor--) if((ch=(*getn)())<0) return(ch);
                      9:        if(cursor<0)
                     10:        {       if(recpos+cursor < 0) /*err(elist->cierr,110,"fmt")*/
                     11:                        cursor = -recpos;       /* is this in the standard? */
                     12:                if(external == 0) {
                     13:                        extern char *icptr;
                     14:                        icptr += cursor;
                     15:                }
                     16:                else if(curunit->useek) (void) fseek(cf,(long) cursor,1);
                     17:                else err(elist->cierr,106,"fmt");
                     18:                recpos += cursor;
                     19:                cursor=0;
                     20:        }
                     21:        switch(p->op)
                     22:        {
                     23:        default: fprintf(stderr,"rd_ed, unexpected code: %d\n%s\n",
                     24:                        p->op,fmtbuf);
                     25:                abort();
                     26:        case I: ch = (rd_I((uint *)ptr,p->p1,len, 10));
                     27:                break;
                     28:        case IM: ch = (rd_I((uint *)ptr,p->p1,len, 10));
                     29:                break;
                     30:        case O: ch = (rd_I((uint *)ptr, p->p1, len, 8));
                     31:                break;
                     32:        case L: ch = (rd_L((ftnint *)ptr,p->p1));
                     33:                break;
                     34:        case A: ch = (rd_A(ptr,len));
                     35:                break;
                     36:        case AW:
                     37:                ch = (rd_AW(ptr,p->p1,len));
                     38:                break;
                     39:        case E: case EE:
                     40:        case D:
                     41:        case G:
                     42:        case GE:
                     43:        case F: ch = (rd_F((ufloat *)ptr,p->p1,p->p2,len));
                     44:                break;
                     45:        }
                     46:        if(ch == 0) return(ch);
                     47:        else if(feof(cf)) return(EOF);
                     48:        clearerr(cf);
                     49:        return(errno);
                     50: }
                     51: rd_ned(p) struct syl *p;
                     52: {
                     53:        switch(p->op)
                     54:        {
                     55:        default: fprintf(stderr,"rd_ned, unexpected code: %d\n%s\n",
                     56:                        p->op,fmtbuf);
                     57:                abort();
                     58:        case APOS:
                     59:                return(rd_POS(p->p1));
                     60:        case H: return(rd_H(p->p1,p->p2));
                     61:        case SLASH: return((*donewrec)());
                     62:        case TR:
                     63:        case X: cursor += p->p1;
                     64:                return(1);
                     65:        case T: cursor=p->p1-recpos - 1;
                     66:                return(1);
                     67:        case TL: cursor -= p->p1;
                     68:                if(cursor < -recpos)    /* TL1000, 1X */
                     69:                        cursor = -recpos;
                     70:                return(1);
                     71:        }
                     72: }
                     73: rd_I(n,w,len, base) ftnlen len; uint *n; register int base;
                     74: {      long x;
                     75:        int sign,ch;
                     76:        char s[84], *ps, *qs;
                     77:        ps=s; x=0;
                     78:        while (w)
                     79:        {
                     80:                GET(ch);
                     81:                if (ch==',' || ch=='\n') break;
                     82:                *ps=ch; ps++; w--;
                     83:        }
                     84:        *ps='\0';
                     85:        ps=s;
                     86:        while (*ps==' ') ps++;
                     87:        if (*ps=='-') { sign=1; ps++; }
                     88:        else { sign=0; if (*ps=='+') ps++; }
                     89: loop:  while (*ps>='0' && *ps<='9') { x=x*base+(*ps-'0'); ps++; }
                     90:        if (*ps==' ') {if (cblank) x *= base; ps++; goto loop;}
                     91:        if(sign) x = -x;
                     92:        if(len==sizeof(short)) n->is=x;
                     93:        else if(len == sizeof(char)) n->ic = x;
                     94:        else n->il=x;
                     95:        if (*ps) return(errno=115); else return(0);
                     96: }
                     97: rd_L(n,w) ftnint *n;
                     98: {      int ch;
                     99:        char s[84], *ps;
                    100:        ps=s;
                    101:        while (w) {
                    102:                GET(ch);
                    103:                if (ch==','||ch=='\n') break;
                    104:                *ps=ch;
                    105:                ps++; w--;
                    106:                }
                    107:        *ps='\0';
                    108:        ps=s; while (*ps==' ') ps++;
                    109:        if (*ps=='.') ps++;
                    110:        if (*ps=='t' || *ps == 'T') { *n=1; return(0); }
                    111:        else if (*ps='f' || *ps == 'F') { *n=0; return(0); }
                    112:        else return(errno=116);
                    113: }
                    114: double ten_pow[]  = {1e1,1e2,1e3,1e4,1e5,1e6,1e7,1e8,1e9};
                    115: rd_F(p, w, d, len) 
                    116: ftnlen len; 
                    117: ufloat *p;
                    118: {      char    s[84], *sp;
                    119:        double  x;
                    120:        int     ch, nfrac, exp, dot, sx, se;
                    121:        sp = s;
                    122:        x = 0.0;
                    123:        dot = 1; /* no dot */
                    124:        while (w) {
                    125:                GET(ch); 
                    126:                w--;
                    127:                switch (ch) {
                    128:                case '\n':
                    129:                case ',':
                    130:                        w = 0; 
                    131:                        break;
                    132:                default:
                    133:                        *sp++ = ch;
                    134:                }
                    135:        }
                    136:        *sp = '\0'; 
                    137:        sp = s;
                    138:        while (*sp == ' ') 
                    139:                sp++;
                    140:        if (*sp == '-') { 
                    141:                sx = 1; 
                    142:                sp++; 
                    143:        } else { 
                    144:                sx = 0; 
                    145:                if (*sp == '+') 
                    146:                        sp++; 
                    147:        }
                    148: loop1:
                    149:        while (*sp >= '0' && *sp <= '9') {
                    150:                x = x * 10 + (*sp - '0');
                    151:                sp++;
                    152:        }
                    153:        if (*sp == ' ') { 
                    154:                if (cblank) 
                    155:                        x *= 10; 
                    156:                sp++; 
                    157:                goto loop1;
                    158:        }
                    159:        nfrac = 0;
                    160:        if (*sp == '.') {
                    161:                sp++; 
                    162:                dot = 0;
                    163: loop2:
                    164:                while (*sp >= '0' && *sp <= '9') {
                    165:                        x = x * 10 + (*sp - '0');
                    166:                        nfrac--;
                    167:                        sp++;
                    168:                }
                    169:                if (*sp == ' ') {
                    170:                        if (cblank) {
                    171:                                x *= 10; 
                    172:                                nfrac--;
                    173:                        } 
                    174:                        sp++; 
                    175:                        goto loop2;
                    176:                }
                    177:        }
                    178:        if (*sp == 'd' || *sp == 'e' || *sp == 'D' || *sp == 'E') { 
                    179:                sp++; 
                    180:        } else 
                    181:                nfrac -= scale;
                    182:        while (*sp == ' ') 
                    183:                sp++;
                    184:        if (*sp == '-') { 
                    185:                sp++; 
                    186:                se = 1; 
                    187:        } else { 
                    188:                se = 0; 
                    189:                if (*sp == '+') 
                    190:                        sp++; 
                    191:        }
                    192:        exp = 0;
                    193: loop3:
                    194:        while (*sp >= '0' && *sp <= '9') {
                    195:                exp = exp * 10 + (*sp - '0');
                    196:                sp++;
                    197:        }
                    198:        if (*sp == ' ') {
                    199:                if (cblank) 
                    200:                        exp *= 10; 
                    201:                sp++; 
                    202:                goto loop3;
                    203:        }
                    204:        if (se) 
                    205:                exp = nfrac - exp; 
                    206:        else 
                    207:                exp += nfrac;
                    208:        if (dot) 
                    209:                exp -= d;
                    210:        if (exp > 0) {
                    211:                while (exp > 9) { 
                    212:                        x *= 1e9; 
                    213:                        exp -= 9; 
                    214:                }
                    215:                x *= ten_pow[exp-1];
                    216:        } else if (exp < 0) {
                    217:                exp = -exp;
                    218:                while (exp > 9) { 
                    219:                        x *= 1e-9; 
                    220:                        exp -= 9; 
                    221:                }
                    222:                x /= ten_pow[exp-1];
                    223:        }
                    224:        if (sx)  
                    225:                x = -x;
                    226:        if (len == sizeof(float)) 
                    227:                p->pf = x; 
                    228:        else 
                    229:                p->pd = x;
                    230:        if (*sp) 
                    231:                return(errno = 115); 
                    232:        else 
                    233:                return(0);
                    234: }
                    235: 
                    236: 
                    237: rd_A(p,len) char *p; ftnlen len;
                    238: {      int i,ch;
                    239:        for(i=0;i<len;i++)
                    240:        {       GET(ch);
                    241:                *p++=VAL(ch);
                    242:        }
                    243:        return(0);
                    244: }
                    245: rd_AW(p,w,len) char *p; ftnlen len;
                    246: {      int i,ch;
                    247:        if(w>=len)
                    248:        {       for(i=0;i<w-len;i++)
                    249:                        GET(ch);
                    250:                for(i=0;i<len;i++)
                    251:                {       GET(ch);
                    252:                        *p++=VAL(ch);
                    253:                }
                    254:                return(0);
                    255:        }
                    256:        for(i=0;i<w;i++)
                    257:        {       GET(ch);
                    258:                *p++=VAL(ch);
                    259:        }
                    260:        for(i=0;i<len-w;i++) *p++=' ';
                    261:        return(0);
                    262: }
                    263: rd_H(n,s) char *s;
                    264: {      int i,ch;
                    265:        for(i=0;i<n;i++)
                    266:                if((ch=(*getn)())<0) return(ch);
                    267:                else *s++ = ch=='\n'?' ':ch;
                    268:        return(1);
                    269: }
                    270: rd_POS(s) char *s;
                    271: {      char quote;
                    272:        int ch;
                    273:        quote= *s++;
                    274:        for(;*s;s++)
                    275:                if(*s==quote && *(s+1)!=quote) break;
                    276:                else if((ch=(*getn)())<0) return(ch);
                    277:                else *s = ch=='\n'?' ':ch;
                    278:        return(1);
                    279: }

unix.superglobalmegacorp.com

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