|
|
1.1 root 1: #include "fio.h"
2: #include "fmt.h"
3: extern int cursor;
4: rd_ed(p,ptr,len) char *ptr; struct syl *p; ftnlen len;
5: { int ch;
6: for(;cursor>0;cursor--) if((ch=(*getn)())<0) return(ch);
7: if(cursor<0)
8: { if(recpos+cursor < 0) err(elist->cierr,110,"fmt")
9: if(curunit->useek) (void) fseek(cf,(long) cursor,1);
10: else err(elist->cierr,106,"fmt");
11: cursor=0;
12: }
13: switch(p->op)
14: {
15: default: fprintf(stderr,"rd_ed, unexpected code: %d\n%s\n",
16: p->op,fmtbuf);
17: abort();
18: case I: ch = (rd_I((uint *)ptr,p->p1,len, 10));
19: break;
20: case IM: ch = (rd_I((uint *)ptr,p->p1,len, 10));
21: break;
22: case O: ch = (rd_I((uint *)ptr, p->p1, len, 8));
23: break;
24: case L: ch = (rd_L((ftnint *)ptr,p->p1));
25: break;
26: case A: ch = (rd_A(ptr,len));
27: break;
28: case AW:
29: ch = (rd_AW(ptr,p->p1,len));
30: break;
31: case E: case EE:
32: case D:
33: case G:
34: case GE:
35: case F: ch = (rd_F((ufloat *)ptr,p->p1,p->p2,len));
36: break;
37: }
38: if(ch == 0) return(ch);
39: else if(feof(cf)) return(EOF);
40: clearerr(cf);
41: return(errno);
42: }
43: rd_ned(p) struct syl *p;
44: {
45: switch(p->op)
46: {
47: default: fprintf(stderr,"rd_ned, unexpected code: %d\n%s\n",
48: p->op,fmtbuf);
49: abort();
50: case APOS:
51: return(rd_POS(p->p1));
52: case H: return(rd_H(p->p1,p->p2));
53: case SLASH: return((*donewrec)());
54: case TR:
55: case X: cursor += p->p1;
56: return(1);
57: case T: cursor=p->p1-recpos - 1;
58: return(1);
59: case TL: cursor -= p->p1;
60: return(1);
61: }
62: }
63: rd_I(n,w,len, base) ftnlen len; uint *n; register int base;
64: { long x=0;
65: int i,sign=0,ch;
66: for(i=0;i<w;i++)
67: {
68: if((ch=(*getn)())<0) return(ch);
69: switch(ch)
70: {
71: default:
72: return(errno=115);
73: case ',': goto done;
74: case '+': break;
75: case '-':
76: sign=1;
77: break;
78: case '\n':
79: case ' ':
80: if(cblank) x *= base;
81: break;
82: case '0': case '1': case '2': case '3': case '4':
83: case '5': case '6': case '7': case '8': case '9':
84: x=base*x+ch-'0';
85: break;
86: }
87: }
88: done:
89: if(sign) x = -x;
90: if(len==sizeof(short)) n->is=x;
91: else if(len == sizeof(char)) n->ic = x;
92: else n->il=x;
93: return(0);
94: }
95: rd_L(n,w) ftnint *n;
96: { int ch,i,v = -1;
97: for(i=0;i<w;i++)
98: { if((ch=(*getn)())<0) return(ch);
99: if(ch=='t' && v==-1) v=1;
100: else if(ch=='f' && v==-1) v=0;
101: else if(ch==',') return(0);
102: }
103: if(v==-1)
104: { errno=116;
105: return(1);
106: }
107: *n=v;
108: return(0);
109: }
110: rd_F(p,w,d,len) ftnlen len; ufloat *p;
111: { double x,y;
112: int i,sx,sz,ch,dot,ny,z,sawz;
113: x=y=0;
114: sawz=z=ny=dot=sx=sz=0;
115: for(i=0;i<w;)
116: { i++;
117: if((ch=(*getn)())<0) return(ch);
118: else if(ch == ' ' && !cblank || ch == '+' && x == 0
119: || ch == '\n' && !cblank) continue;
120: else if(ch=='-' && x==0) sx=1;
121: else if(ch == '+' || ch == '-') goto expon;
122: else if(ch<='9' && ch>='0')
123: x=10*x+ch-'0';
124: else if(ch=='e' || ch=='d' || ch=='.')
125: break;
126: else if(cblank && (ch==' ' || ch== '\n')) x*=10;
127: else if(ch==',')
128: { i=w;
129: break;
130: }
131: else return(errno = 115);
132: }
133: if(ch=='.') dot=1;
134: while(i<w && ch!='e' && ch!='d' && ch!='+' && ch!='-')
135: { i++;
136: if((ch=(*getn)())<0) return(ch);
137: else if(ch<='9' && ch>='0')
138: y=10*y+ch-'0';
139: else if(cblank && (ch==' ' || ch == '\n'))
140: y *= 10;
141: else if(ch==',') {i=w; break;}
142: else if(ch==' ') continue;
143: else continue;
144: ny++;
145: }
146: expon:
147: if(ch=='-') sz=1;
148: while(i<w)
149: { i++;
150: sawz=1;
151: if((ch=(*getn)())<0) return(ch);
152: else if(ch=='-') sz=1;
153: else if(ch<='9' && ch>='0')
154: z=10*z+ch-'0';
155: else if(cblank && (ch==' ' || ch == '\n'))
156: z *= 10;
157: else if(ch==',') break;
158: else if(ch==' ') continue;
159: else if(ch=='+') continue;
160: else if(ch!='\n') return(errno=115);
161: }
162: if(!dot)
163: for(i=0;i<d;i++) x /= 10;
164: for(i=0;i<ny;i++) y /= 10;
165: x=x+y;
166: if(sz)
167: for(i=0;i<z;i++) x /=10;
168: else for(i=0;i<z;i++) x *= 10;
169: if(sx) x = -x;
170: if(!sawz)
171: {
172: for(i=scale;i>0;i--) x /= 10;
173: for(i=scale;i<0;i++) x *= 10;
174: }
175: if(len==sizeof(float)) p->pf=x;
176: else p->pd=x;
177: return(0);
178: }
179: rd_A(p,len) char *p; ftnlen len;
180: { int i,ch;
181: for(i=0;i<len;i++)
182: { GET(ch);
183: *p++=VAL(ch);
184: }
185: return(0);
186: }
187: rd_AW(p,w,len) char *p; ftnlen len;
188: { int i,ch;
189: if(w>=len)
190: { for(i=0;i<w-len;i++)
191: GET(ch);
192: for(i=0;i<len;i++)
193: { GET(ch);
194: *p++=VAL(ch);
195: }
196: return(0);
197: }
198: for(i=0;i<w;i++)
199: { GET(ch);
200: *p++=VAL(ch);
201: }
202: for(i=0;i<len-w;i++) *p++=' ';
203: return(0);
204: }
205: rd_H(n,s) char *s;
206: { int i,ch;
207: for(i=0;i<n;i++)
208: if((ch=(*getn)())<0) return(ch);
209: else *s++ = ch=='\n'?' ':ch;
210: return(1);
211: }
212: rd_POS(s) char *s;
213: { char quote;
214: int ch;
215: quote= *s++;
216: for(;*s;s++)
217: if(*s==quote && *(s+1)!=quote) break;
218: else if((ch=(*getn)())<0) return(ch);
219: else *s = ch=='\n'?' ':ch;
220: return(1);
221: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.