1 /* $Id: lread.c,v 1.1.1.1 2008/08/24 05:34:47 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.
43 int (*lioproc
)(ftnint
*number
,flex
*ptr
,ftnlen len
,ftnint type
);
45 static int rd_int(double *x
);
53 #define isblnk(x) (ltab[x+1]&B)
54 #define issep(x) (ltab[x+1]&SX)
55 #define isapos(x) (ltab[x+1]&AX)
56 #define isexp(x) (ltab[x+1]&EX)
61 char ltab
[128+1] = /* offset one for EOF */
63 0,0,AX
,0,0,0,0,0,0,0,B
,0,0,0,0,0,
64 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
65 SX
|B
,0,AX
,0,0,0,0,0,0,0,0,0,SX
,0,0,SX
,
66 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
67 0,0,0,0,EX
,EX
,0,0,0,0,0,0,0,0,0,0,
68 AX
,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
69 0,0,0,0,EX
,EX
,0,0,0,0,0,0,0,0,0,0,
70 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
78 if(curunit
->uend
) return(EOF
);
79 if((ch
=getc(cf
))!=EOF
) return(ch
);
80 if(feof(cf
)) curunit
->uend
= 1;
88 if(curunit
->uend
) return(0);
89 while((ch
=t_getc())!='\n' && ch
!=EOF
);
97 #define ERR(x) if((n=(x))) return(n)
98 #define GETC(x) ((x=t_getc()))
101 l_read(ftnint
*number
,flex
*ptr
,ftnlen len
,ftnint type
)
105 for(i
=0;i
<*number
;i
++)
107 if(curunit
->uend
) err(elist
->ciend
, EOF
, "list in")
110 for(GETC(ch
);isblnk(ch
);GETC(ch
));
137 if(feof(cf
)) err(elist
->ciend
,(EOF
),"list in")
140 err(elist
->cierr
,errno
,"list in")
142 if(ltype
==0) goto bump
;
169 b_char(lchar
,(char *)ptr
,len
);
173 if(lcount
>0) lcount
--;
174 ptr
= (flex
*)((char *)ptr
+ len
);
182 int i
,ch
,sign
=0,da
,db
,dc
;
185 if(lcount
>0) return(0);
187 for(GETC(ch
);isblnk(ch
);GETC(ch
));
212 if(isexp(GETC(ch
))) db
=rd_int(&d
);
224 for(i
=0;i
<dc
;i
++) c
/=10;
226 for(i
=0;i
<d
;i
++) b
*= 10;
227 for(i
=0;i
< -d
;i
++) b
/= 10;
240 if(GETC(ch
)=='-') sign
= -1;
241 else if(ch
=='+') sign
=0;
243 while(isdigit(GETC(ch
)))
256 if(lcount
>0) return(0);
258 for(GETC(ch
);isblnk(ch
);GETC(ch
));
268 { if(fscanf(cf
,"%d",&lcount
)!=1) {
269 if(!feof(cf
)) err(elist
->cierr
,112,"no rep")
270 else err(elist
->cierr
,(EOF
),"lread");
274 if(!feof(cf
)) err(elist
->cierr
,112,"no star")
275 else err(elist
->cierr
,(EOF
),"lread");
284 fscanf(cf
,"%lf",&lx
);
285 while(isblnk(GETC(ch
)));
288 err(elist
->cierr
,112,"no comma");
290 while(isblnk(GETC(ch
)));
292 fscanf(cf
,"%lf",&ly
);
293 while(isblnk(GETC(ch
)));
294 if(ch
!=')') err(elist
->cierr
,112,"no )");
295 while(isblnk(GETC(ch
)));
304 if(lcount
>0) return(0);
306 while(isblnk(GETC(ch
)));
317 fscanf(cf
,"%d",&lcount
);
319 if(!feof(cf
)) err(elist
->cierr
,112,"no star")
320 else err(elist
->cierr
,(EOF
),"lread");
324 if(GETC(ch
)=='.') GETC(ch
);
336 if(isblnk(ch
) || issep(ch
) || ch
==EOF
)
340 else err(elist
->cierr
,112,"logical");
343 while(!issep(GETC(ch
)) && ch
!='\n' && ch
!=EOF
);
352 if(lcount
>0) return(0);
355 while(isblnk(GETC(ch
)));
366 fscanf(cf
,"%d",&lcount
);
367 if(GETC(ch
)!='*') err(elist
->cierr
,112,"no star");
370 if(GETC(ch
)=='\'' || ch
=='"') quote
=ch
;
371 else if(isblnk(ch
) || issep(ch
) || ch
==EOF
)
375 else err(elist
->cierr
,112,"no quote");
377 if(lchar
!=NULL
) free(lchar
);
379 p
=lchar
=(char *)malloc(size
);
380 if(lchar
==NULL
) err(elist
->cierr
,113,"no space");
382 { while(GETC(ch
)!=quote
&& ch
!='\n'
383 && ch
!=EOF
&& ++i
<size
) *p
++ = ch
;
387 lchar
=(char *)realloc(lchar
, size
+= BUFSIZE
);
391 else if(ch
==EOF
) return(EOF
);
393 { if(*(p
-1) != '\\') continue;
396 if(++i
<size
) *p
++ = ch
;
399 else if(GETC(ch
)==quote
)
400 { if(++i
<size
) *p
++ = ch
;
416 if((n
=c_le(a
,READ
))) return(n
);
424 return(nowreading(curunit
));
432 for(GETC(ch
);isblnk(ch
);GETC(ch
));
434 if(feof(cf
)) return(EOF
);
441 if(ch
==',') for(GETC(ch
);isblnk(ch
);GETC(ch
));
447 c_le(cilist
*a
, int flag
)
450 if(a
->ciunit
>=MXUNIT
|| a
->ciunit
<0)
451 err(a
->cierr
,101,"stler");
454 curunit
= &units
[a
->ciunit
];
455 if(curunit
->ufd
==NULL
&& fk_open(flag
,SEQ
,FMT
,a
->ciunit
))
456 err(a
->cierr
,102,"lio");
458 if(!curunit
->ufmt
) err(a
->cierr
,103,"lio")
463 do_lio(ftnint
*type
,ftnint
*number
,flex
*ptr
,ftnlen len
)
465 return((*lioproc
)(number
,ptr
,len
,*type
));