5 /* Compile with -DF8X_NML_ELIDE_QUOTES to permit eliding quotation */
6 /* marks in namelist input a la the Fortran 8X Draft published in */
7 /* the May 1989 issue of Fortran Forum. */
10 extern char *f__fmtbuf
;
14 static longint f__llx
;
20 extern char *malloc(), *realloc();
21 int (*f__lioproc
)(), (*l_getc
)(), (*l_ungetc
)();
27 int (*f__lioproc
)(ftnint
*, char*, ftnlen
, ftnint
), (*l_getc
)(void),
28 (*l_ungetc
)(int,FILE*);
37 #define isblnk(x) (f__ltab[x+1]&B)
38 #define issep(x) (f__ltab[x+1]&SX)
39 #define isapos(x) (f__ltab[x+1]&AX)
40 #define isexp(x) (f__ltab[x+1]&EX)
41 #define issign(x) (f__ltab[x+1]&SG)
42 #define iswhit(x) (f__ltab[x+1]&WH)
49 char f__ltab
[128+1] = { /* offset one for EOF */
51 0,0,AX
,0,0,0,0,0,0,WH
|B
,SX
|WH
,0,0,0,0,0,
52 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
53 SX
|B
|WH
,0,AX
,0,0,0,0,AX
,0,0,0,SG
,SX
,SG
,0,SX
,
54 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
55 0,0,0,0,EX
,EX
,0,0,0,0,0,0,0,0,0,0,
56 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
57 AX
,0,0,0,EX
,EX
,0,0,0,0,0,0,0,0,0,0,
58 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
64 un_getc(x
,f__cf
) int x
; FILE *f__cf
;
66 un_getc(int x
, FILE *f__cf
)
68 { return ungetc(x
,f__cf
); }
70 #define un_getc ungetc
74 extern int ungetc(int, FILE*); /* for systems with a buggy stdio.h */
80 if(f__curunit
->uend
) return(EOF
);
81 if((ch
=getc(f__cf
))!=EOF
) return(ch
);
83 f__curunit
->uend
= l_eof
= 1;
90 if(f__curunit
->uend
) return(0);
91 while((ch
=t_getc())!='\n')
94 f__curunit
->uend
= l_eof
= 1;
101 int f__lcount
,f__ltype
,nml_read
;
104 #define ERR(x) if(n=(x)) {f__init &= ~2; return(n);}
105 #define GETC(x) (x=(*l_getc)())
106 #define Ungetc(x,y) (*l_ungetc)(x,y)
110 l_R(poststar
, reqint
) int poststar
, reqint
;
112 l_R(int poststar
, int reqint
)
115 char s
[FMAX
+EXPMAXDIGS
+4];
117 register char *sp
, *spe
, *sp1
;
119 int havenum
, havestar
, se
;
138 case '-': *sp
++ = ch
; sp1
++; spe
++;
147 if (sp
< spe
) *sp
++ = ch
;
151 if (ch
== '*' && !poststar
) {
152 if (sp
== sp1
|| exp
|| *s
== '-') {
153 errfl(f__elist
->cierr
,112,"bad repetition count");
155 poststar
= havestar
= 1;
161 #ifndef ALLOW_FLOAT_IN_INTEGER_LIST_INPUT
163 errfl(f__elist
->cierr
,115,"invalid integer");
174 { *sp
++ = ch
; --exp
; }
182 if (havenum
&& isexp(ch
)) {
183 #ifndef ALLOW_FLOAT_IN_INTEGER_LIST_INPUT
185 errfl(f__elist
->cierr
,115,"invalid integer");
190 if (ch
== '-') se
= 1;
195 errfl(f__elist
->cierr
,112,"exponent field");
199 while(isdigit(GETC(ch
))) {
209 (void) Ungetc(ch
, f__cf
);
215 sprintf(sp
+1, "e%ld", exp
);
220 if (reqint
&2 && (se
= sp
- sp1
+ exp
) > 14 && se
< 20) {
221 /* Assuming 64-bit longint and 32-bit long. */
227 f__llx
= 10*f__llx
+ (*sp1
- '0');
246 if (havestar
&& ( ch
== ' '
254 errfl(f__elist
->cierr
,112,"invalid number");
261 rd_count(ch
) register int ch
;
263 rd_count(register int ch
)
266 if (ch
< '0' || ch
> '9')
268 f__lcount
= ch
- '0';
269 while(GETC(ch
) >= '0' && ch
<= '9')
270 f__lcount
= 10*f__lcount
+ ch
- '0';
272 return f__lcount
<= 0;
279 if(f__lcount
>0) return(0);
284 if (nml_read
> 1 && (ch
< '0' || ch
> '9')) {
290 if(!f__cf
|| !feof(f__cf
))
291 errfl(f__elist
->cierr
,112,"complex format");
293 err(f__elist
->cierr
,(EOF
),"lread");
296 if(!f__cf
|| !feof(f__cf
))
297 errfl(f__elist
->cierr
,112,"no star");
299 err(f__elist
->cierr
,(EOF
),"lread");
308 while(iswhit(GETC(ch
)));
315 errfl(f__elist
->cierr
,112,"no real part");
317 while(iswhit(GETC(ch
)));
319 { (void) Ungetc(ch
,f__cf
);
320 errfl(f__elist
->cierr
,112,"no comma");
322 while(iswhit(GETC(ch
)));
323 (void) Ungetc(ch
,f__cf
);
327 errfl(f__elist
->cierr
,112,"no imaginary part");
328 while(iswhit(GETC(ch
)));
329 if(ch
!=')') errfl(f__elist
->cierr
,112,"no )");
343 if(f__lcount
>0) return(0);
351 if(!f__cf
|| !feof(f__cf
))
352 errfl(f__elist
->cierr
,112,"no star");
354 err(f__elist
->cierr
,(EOF
),"lread");
357 if(ch
== '.') GETC(ch
);
369 if(isblnk(ch
) || issep(ch
) || ch
==EOF
)
370 { (void) Ungetc(ch
,f__cf
);
378 errfl(f__elist
->cierr
,112,"logical");
381 while(!issep(GETC(ch
)) && ch
!=EOF
);
382 (void) Ungetc(ch
, f__cf
);
391 static char rafail
[] = "realloc failure";
393 if(f__lcount
>0) return(0);
395 if(f__lchar
!=NULL
) free(f__lchar
);
397 p
=f__lchar
= (char *)malloc((unsigned int)size
);
399 errfl(f__elist
->cierr
,113,"no space");
403 /* allow Fortran 8x-style unquoted string... */
404 /* either find a repetition count or the string */
405 f__lcount
= ch
- '0';
410 if (f__lcount
== 0) {
412 #ifndef F8X_NML_ELIDE_QUOTES
434 #ifndef F8X_NML_ELIDE_QUOTES
437 errfl(f__elist
->cierr
,112,
438 "undelimited character string");
444 f__lcount
= 10*f__lcount
+ ch
- '0';
446 f__lchar
= (char *)realloc(f__lchar
,
447 (unsigned int)(size
+= BUFSIZE
));
449 errfl(f__elist
->cierr
,113,rafail
);
454 else (void) Ungetc(ch
,f__cf
);
456 if(GETC(ch
)=='\'' || ch
=='"') quote
=ch
;
457 else if(isblnk(ch
) || (issep(ch
) && ch
!= '\n') || ch
==EOF
) {
461 #ifndef F8X_NML_ELIDE_QUOTES
462 else if (nml_read
> 1) {
469 /* Fortran 8x-style unquoted string */
487 f__lchar
= (char *)realloc(f__lchar
,
488 (unsigned int)(size
+= BUFSIZE
));
490 errfl(f__elist
->cierr
,113,rafail
);
497 { while(GETC(ch
)!=quote
&& ch
!='\n'
498 && ch
!=EOF
&& ++i
<size
) *p
++ = ch
;
502 f__lchar
= (char *)realloc(f__lchar
,
503 (unsigned int)(size
+= BUFSIZE
));
505 errfl(f__elist
->cierr
,113,rafail
);
509 else if(ch
==EOF
) return(EOF
);
511 { if(*(p
-1) != '\\') continue;
514 if(++i
<size
) *p
++ = ch
;
517 else if(GETC(ch
)==quote
)
518 { if(++i
<size
) *p
++ = ch
;
522 { (void) Ungetc(ch
,f__cf
);
534 if(f__init
!= 1) f_init();
537 f__curunit
= &f__units
[a
->ciunit
];
539 if(a
->ciunit
>=MXUNIT
|| a
->ciunit
<0)
540 err(a
->cierr
,101,"stler");
541 f__scale
=f__recpos
=0;
543 if(f__curunit
->ufd
==NULL
&& fk_open(SEQ
,FMT
,a
->ciunit
))
544 err(a
->cierr
,102,"lio");
545 f__cf
=f__curunit
->ufd
;
546 if(!f__curunit
->ufmt
) err(a
->cierr
,103,"lio");
550 l_read(number
,ptr
,len
,type
) ftnint
*number
,type
; char *ptr
; ftnlen len
;
552 l_read(ftnint
*number
, char *ptr
, ftnlen len
, ftnint type
)
555 #define Ptr ((flex *)ptr)
559 for(i
=0;i
<*number
;i
++)
561 if(f__lquit
) return(0);
563 err(f__elist
->ciend
, EOF
, "list in");
570 err(f__elist
->ciend
,(EOF
),"list in");
582 (void) Ungetc(ch
, f__cf
);
593 #ifndef ALLOW_FLOAT_IN_INTEGER_LIST_INPUT
621 while (GETC(ch
) == ' ' || ch
== '\t');
622 if (ch
!= ',' || f__lcount
> 1)
625 if(f__lquit
) return(0);
626 if(f__cf
&& ferror(f__cf
)) {
628 errfl(f__elist
->cierr
,errno
,"list in");
630 if(f__ltype
==0) goto bump
;
635 Ptr
->flchar
= (char)f__lx
;
639 Ptr
->flshort
= (short)f__lx
;
643 Ptr
->flint
= (ftnint
)f__lx
;
647 if (!(Ptr
->fllongint
= f__llx
))
648 Ptr
->fllongint
= f__lx
;
663 yy
=(doublereal
*)ptr
;
668 b_char(f__lchar
,ptr
,len
);
672 if(f__lcount
>0) f__lcount
--;
681 integer
s_rsle(a
) cilist
*a
;
683 integer
s_rsle(cilist
*a
)
691 if(n
=c_le(a
)) return(n
);
696 if(f__curunit
->uwrt
&& f__nowreading(f__curunit
))
697 err(a
->cierr
,errno
,"read start");
699 err(f__elist
->ciend
,(EOF
),"read start");