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)
109 l_R(poststar) int poststar;
114 char s[FMAX+EXPMAXDIGS+4];
116 register char *sp, *spe, *sp1;
118 int havenum, havestar, se;
137 case '-': *sp++ = ch; sp1++; spe++;
146 if (sp < spe) *sp++ = ch;
150 if (ch == '*' && !poststar) {
151 if (sp == sp1 || exp || *s == '-') {
152 errfl(f__elist->cierr,112,"bad repetition count");
154 poststar = havestar = 1;
169 { *sp++ = ch; --exp; }
177 if (havenum && isexp(ch)) {
181 if (ch == '-') se = 1;
186 errfl(f__elist->cierr,112,"exponent field");
190 while(isdigit(GETC(ch))) {
200 (void) Ungetc(ch, f__cf);
206 sprintf(sp+1, "e%ld", exp);
211 if (quad_read && (se = sp - sp1 + exp) > 14 && se < 20) {
212 /* Assuming 64-bit longint and 32-bit long. */
218 f__llx = 10*f__llx + (*sp1 - '0');
237 if (havestar && ( ch == ' '
245 errfl(f__elist->cierr,112,"invalid number");
252 rd_count(ch) register int ch;
254 rd_count(register int ch)
257 if (ch < '0' || ch > '9')
259 f__lcount = ch - '0';
260 while(GETC(ch) >= '0' && ch <= '9')
261 f__lcount = 10*f__lcount + ch - '0';
263 return f__lcount <= 0;
269 if(f__lcount>0) return(0);
274 if (nml_read > 1 && (ch < '0' || ch > '9')) {
280 if(!f__cf || !feof(f__cf))
281 errfl(f__elist->cierr,112,"complex format");
283 err(f__elist->cierr,(EOF),"lread");
286 if(!f__cf || !feof(f__cf))
287 errfl(f__elist->cierr,112,"no star");
289 err(f__elist->cierr,(EOF),"lread");
298 while(iswhit(GETC(ch)));
305 errfl(f__elist->cierr,112,"no real part");
307 while(iswhit(GETC(ch)));
309 { (void) Ungetc(ch,f__cf);
310 errfl(f__elist->cierr,112,"no comma");
312 while(iswhit(GETC(ch)));
313 (void) Ungetc(ch,f__cf);
317 errfl(f__elist->cierr,112,"no imaginary part");
318 while(iswhit(GETC(ch)));
319 if(ch!=')') errfl(f__elist->cierr,112,"no )");
331 if(f__lcount>0) return(0);
339 if(!f__cf || !feof(f__cf))
340 errfl(f__elist->cierr,112,"no star");
342 err(f__elist->cierr,(EOF),"lread");
345 if(ch == '.') GETC(ch);
357 if(isblnk(ch) || issep(ch) || ch==EOF)
358 { (void) Ungetc(ch,f__cf);
366 errfl(f__elist->cierr,112,"logical");
369 while(!issep(GETC(ch)) && ch!=EOF);
370 (void) Ungetc(ch, f__cf);
376 static char rafail[] = "realloc failure";
378 if(f__lcount>0) return(0);
380 if(f__lchar!=NULL) free(f__lchar);
382 p=f__lchar = (char *)malloc((unsigned int)size);
384 errfl(f__elist->cierr,113,"no space");
388 /* allow Fortran 8x-style unquoted string... */
389 /* either find a repetition count or the string */
390 f__lcount = ch - '0';
395 if (f__lcount == 0) {
397 #ifndef F8X_NML_ELIDE_QUOTES
419 #ifndef F8X_NML_ELIDE_QUOTES
422 errfl(f__elist->cierr,112,
423 "undelimited character string");
429 f__lcount = 10*f__lcount + ch - '0';
431 f__lchar = (char *)realloc(f__lchar,
432 (unsigned int)(size += BUFSIZE));
434 errfl(f__elist->cierr,113,rafail);
439 else (void) Ungetc(ch,f__cf);
441 if(GETC(ch)=='\'' || ch=='"') quote=ch;
442 else if(isblnk(ch) || (issep(ch) && ch != '\n') || ch==EOF) {
446 #ifndef F8X_NML_ELIDE_QUOTES
447 else if (nml_read > 1) {
454 /* Fortran 8x-style unquoted string */
472 f__lchar = (char *)realloc(f__lchar,
473 (unsigned int)(size += BUFSIZE));
475 errfl(f__elist->cierr,113,rafail);
482 { while(GETC(ch)!=quote && ch!='\n'
483 && ch!=EOF && ++i<size) *p++ = ch;
487 f__lchar= (char *)realloc(f__lchar,
488 (unsigned int)(size += BUFSIZE));
490 errfl(f__elist->cierr,113,rafail);
494 else if(ch==EOF) return(EOF);
496 { if(*(p-1) != '\\') continue;
499 if(++i<size) *p++ = ch;
502 else if(GETC(ch)==quote)
503 { if(++i<size) *p++ = ch;
507 { (void) Ungetc(ch,f__cf);
519 if(f__init != 1) f_init();
523 if(a->ciunit>=MXUNIT || a->ciunit<0)
524 err(a->cierr,101,"stler");
525 f__scale=f__recpos=0;
527 f__curunit = &f__units[a->ciunit];
528 if(f__curunit->ufd==NULL && fk_open(SEQ,FMT,a->ciunit))
529 err(a->cierr,102,"lio");
530 f__cf=f__curunit->ufd;
531 if(!f__curunit->ufmt) err(a->cierr,103,"lio");
535 l_read(number,ptr,len,type) ftnint *number,type; char *ptr; ftnlen len;
537 l_read(ftnint *number, char *ptr, ftnlen len, ftnint type)
540 #define Ptr ((flex *)ptr)
544 for(i=0;i<*number;i++)
546 if(f__lquit) return(0);
548 err(f__elist->ciend, EOF, "list in");
555 err(f__elist->ciend,(EOF),"list in");
567 (void) Ungetc(ch, f__cf);
603 while (GETC(ch) == ' ' || ch == '\t');
604 if (ch != ',' || f__lcount > 1)
607 if(f__lquit) return(0);
608 if(f__cf && ferror(f__cf)) {
610 errfl(f__elist->cierr,errno,"list in");
612 if(f__ltype==0) goto bump;
617 Ptr->flchar = (char)f__lx;
621 Ptr->flshort = (short)f__lx;
629 if (!(Ptr->fllongint = f__llx))
630 Ptr->fllongint = f__lx;
645 yy=(doublereal *)ptr;
650 b_char(f__lchar,ptr,len);
654 if(f__lcount>0) f__lcount--;
663 integer s_rsle(a) cilist *a;
665 integer s_rsle(cilist *a)
670 if(n=c_le(a)) return(n);
678 if(f__curunit->uwrt && f__nowreading(f__curunit))
679 err(a->cierr,errno,"read start");
681 err(f__elist->ciend,(EOF),"read start");