1 /* $Id: rdfmt.c,v 1.1.1.1 2008/08/24 05:34:48 gmcgarry Exp $ */
3 * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * Redistributions of source code and documentation must retain the above
10 * copyright notice, this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditionsand the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed or owned by Caldera
18 * Neither the name of Caldera International, Inc. nor the names of other
19 * contributors may be used to endorse or promote products derived from
20 * this software without specific prior written permission.
22 * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
23 * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE
27 * FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT,
31 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
41 int rd_I(unint
*n
, int w
, ftnlen len
);
42 int rd_L(ftnint
*n
, int w
);
43 int rd_A(char *p
, ftnlen len
);
44 int rd_AW(char *p
, int w
, ftnlen len
);
45 int rd_F(ufloat
*p
, int w
, int d
, ftnlen len
);
47 int rd_H(int n
, char *s
);
51 rd_ed(struct syl
*p
, void *ptr
, ftnlen len
)
54 for(;cursor
>0;cursor
--) if((ch
=(*getn
)())<0) return(ch
);
56 { if(recpos
+cursor
< 0) err(elist
->cierr
,110,"fmt")
57 if(curunit
->useek
) fseek(cf
,(long) cursor
,1);
58 else err(elist
->cierr
,106,"fmt");
63 default: fprintf(stderr
,"rd_ed, unexpected code: %d\n%s\n",
66 case I
: ch
= (rd_I(ptr
,p
->p1
,len
));
68 case IM
: ch
= (rd_I(ptr
,p
->p1
,len
));
70 case L
: ch
= (rd_L(ptr
,p
->p1
));
72 case A
: ch
= (rd_A(ptr
,len
));
75 ch
= (rd_AW(ptr
,p
->p1
,len
));
81 case F
: ch
= (rd_F(ptr
,p
->p1
,p
->p2
,len
));
84 if(ch
== 0) return(ch
);
85 else if(feof(cf
)) return(EOF
);
91 rd_ned(struct syl
*p
, char *ptr
)
95 default: fprintf(stderr
,"rd_ned, unexpected code: %d\n%s\n",
99 return(rd_POS((char /* XXX */ *)p
->p1
));
100 case H
: return(rd_H(p
->p1
,(char /* XXX */ *)p
->p2
));
101 case SLASH
: return((*donewrec
)());
103 case X
: cursor
+= p
->p1
;
105 case T
: cursor
=p
->p1
-recpos
;
107 case TL
: cursor
-= p
->p1
;
113 rd_I(unint
*n
, int w
, ftnlen len
)
119 if((ch
=(*getn
)())<0) return(ch
);
133 case '0': case '1': case '2': case '3': case '4':
134 case '5': case '6': case '7': case '8': case '9':
141 if(len
==sizeof(short)) n
->is
=x
;
147 rd_L(ftnint
*n
, int w
)
151 { if((ch
=(*getn
)())<0) return(ch
);
152 if(ch
=='t' && v
==-1) v
=1;
153 else if(ch
=='f' && v
==-1) v
=0;
154 else if(ch
==',') return(0);
165 rd_F(ufloat
*p
, int w
, int d
, ftnlen len
)
168 int i
,sx
,sz
,ch
,dot
,ny
,z
,sawz
;
172 sawz
=z
=ny
=dot
=sx
=sz
=0;
175 if((ch
=(*getn
)())<0) return(ch
);
176 else if((ch
==' ' && !cblank
) || ch
=='+') continue;
177 else if(ch
=='-') sx
=1;
178 else if(ch
<='9' && ch
>='0')
180 else if(ch
=='e' || ch
=='d' || ch
=='.')
182 else if(cblank
&& ch
==' ') x
*=10;
187 else if(ch
!='\n') return(errno
=115);
190 while(i
<w
&& ch
!='e' && ch
!='d' && ch
!='+' && ch
!='-')
192 if((ch
=(*getn
)())<0) return(ch
);
193 else if(ch
<='9' && ch
>='0')
195 else if(cblank
&& ch
==' ')
197 else if(ch
==',') {i
=w
; break;}
198 else if(ch
==' ') continue;
206 if((ch
=(*getn
)())<0) return(ch
);
207 else if(ch
=='-') sz
=1;
208 else if(ch
<='9' && ch
>='0')
210 else if(cblank
&& ch
==' ')
212 else if(ch
==',') break;
213 else if(ch
==' ') continue;
214 else if(ch
=='+') continue;
215 else if(ch
!='\n') return(errno
=115);
218 for(i
=0;i
<d
;i
++) x
/= 10;
219 for(i
=0;i
<ny
;i
++) y
/= 10;
222 for(i
=0;i
<z
;i
++) x
/=10;
223 else for(i
=0;i
<z
;i
++) x
*= 10;
227 for(i
=scale
;i
>0;i
--) x
/= 10;
228 for(i
=scale
;i
<0;i
++) x
*= 10;
230 if(len
==sizeof(float)) p
->pf
=x
;
236 rd_A(char *p
, ftnlen len
)
247 rd_AW(char *p
, int w
, ftnlen len
)
251 { for(i
=0;i
<w
-len
;i
++)
263 for(i
=0;i
<len
-w
;i
++) *p
++=' ';
271 if((ch
=(*getn
)())<0) return(ch
);
272 else if(ch
=='\n') *s
++ = ' ';
273 else *s
++ = ch
=='\n'?' ':ch
;
285 if(*s
==quote
&& *(s
+1)!=quote
) break;
286 else if((ch
=(*getn
)())<0) return(ch
);
287 else *s
= ch
=='\n'?' ':ch
;