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)();
34 int (*f__lioproc)(ftnint*, char*, ftnlen, ftnint), (*l_getc)(void),
35 (*l_ungetc)(int,FILE*);
40 #define isblnk(x) (f__ltab[x+1]&B)
41 #define issep(x) (f__ltab[x+1]&SX)
42 #define isapos(x) (f__ltab[x+1]&AX)
43 #define isexp(x) (f__ltab[x+1]&EX)
44 #define issign(x) (f__ltab[x+1]&SG)
45 #define iswhit(x) (f__ltab[x+1]&WH)
52 char f__ltab[128+1] = { /* offset one for EOF */
54 0,0,AX,0,0,0,0,0,0,WH|B,SX|WH,0,0,0,0,0,
55 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
56 SX|B|WH,0,AX,0,0,0,0,AX,0,0,0,SG,SX,SG,0,SX,
57 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
58 0,0,0,0,EX,EX,0,0,0,0,0,0,0,0,0,0,
59 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
60 AX,0,0,0,EX,EX,0,0,0,0,0,0,0,0,0,0,
61 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
67 un_getc(x,f__cf) int x; FILE *f__cf;
69 un_getc(int x, FILE *f__cf)
71 { return ungetc(x,f__cf); }
73 #define un_getc ungetc
77 extern int ungetc(int, FILE*); /* for systems with a buggy stdio.h */
83 if(f__curunit->uend) return(EOF);
84 if((ch=getc(f__cf))!=EOF) return(ch);
86 f__curunit->uend = l_eof = 1;
93 if(f__curunit->uend) return(0);
94 while((ch=t_getc())!='\n')
97 f__curunit->uend = l_eof = 1;
104 int f__lcount,f__ltype,nml_read;
107 #define ERR(x) if(n=(x)) {f__init &= ~2; return(n);}
108 #define GETC(x) (x=(*l_getc)())
109 #define Ungetc(x,y) (*l_ungetc)(x,y)
113 l_R(poststar, reqint) int poststar, reqint;
115 l_R(int poststar, int reqint)
118 char s[FMAX+EXPMAXDIGS+4];
120 register char *sp, *spe, *sp1;
122 int havenum, havestar, se;
141 case '-': *sp++ = ch; sp1++; spe++;
150 if (sp < spe) *sp++ = ch;
154 if (ch == '*' && !poststar) {
155 if (sp == sp1 || exp || *s == '-') {
156 errfl(f__elist->cierr,112,"bad repetition count");
158 poststar = havestar = 1;
164 #ifndef ALLOW_FLOAT_IN_INTEGER_LIST_INPUT
166 errfl(f__elist->cierr,115,"invalid integer");
177 { *sp++ = ch; --exp; }
185 if (havenum && isexp(ch)) {
186 #ifndef ALLOW_FLOAT_IN_INTEGER_LIST_INPUT
188 errfl(f__elist->cierr,115,"invalid integer");
193 if (ch == '-') se = 1;
198 errfl(f__elist->cierr,112,"exponent field");
202 while(isdigit(GETC(ch))) {
212 (void) Ungetc(ch, f__cf);
218 sprintf(sp+1, "e%ld", exp);
223 if (reqint&2 && (se = sp - sp1 + exp) > 14 && se < 20) {
224 /* Assuming 64-bit longint and 32-bit long. */
230 f__llx = 10*f__llx + (*sp1 - '0');
249 if (havestar && ( ch == ' '
257 errfl(f__elist->cierr,112,"invalid number");
264 rd_count(ch) register int ch;
266 rd_count(register int ch)
269 if (ch < '0' || ch > '9')
271 f__lcount = ch - '0';
272 while(GETC(ch) >= '0' && ch <= '9')
273 f__lcount = 10*f__lcount + ch - '0';
275 return f__lcount <= 0;
282 if(f__lcount>0) return(0);
287 if (nml_read > 1 && (ch < '0' || ch > '9')) {
293 if(!f__cf || !feof(f__cf))
294 errfl(f__elist->cierr,112,"complex format");
296 err(f__elist->cierr,(EOF),"lread");
299 if(!f__cf || !feof(f__cf))
300 errfl(f__elist->cierr,112,"no star");
302 err(f__elist->cierr,(EOF),"lread");
311 while(iswhit(GETC(ch)));
318 errfl(f__elist->cierr,112,"no real part");
320 while(iswhit(GETC(ch)));
322 { (void) Ungetc(ch,f__cf);
323 errfl(f__elist->cierr,112,"no comma");
325 while(iswhit(GETC(ch)));
326 (void) Ungetc(ch,f__cf);
330 errfl(f__elist->cierr,112,"no imaginary part");
331 while(iswhit(GETC(ch)));
332 if(ch!=')') errfl(f__elist->cierr,112,"no )");
342 static char nmLbuf[256], *nmL_next;
343 static int (*nmL_getc_save)(Void);
345 static int (*nmL_ungetc_save)(/* int, FILE* */);
347 static int (*nmL_ungetc_save)(int, FILE*);
354 if (rv = *nmL_next++)
356 l_getc = nmL_getc_save;
357 l_ungetc = nmL_ungetc_save;
363 nmL_ungetc(x, f) int x; FILE *f;
365 nmL_ungetc(int x, FILE *f)
368 f = f; /* banish non-use warning */
369 return *--nmL_next = x;
374 Lfinish(ch, dot, rvp) int ch, dot, *rvp;
376 Lfinish(int ch, int dot, int *rvp)
380 static char what[] = "namelist input";
383 se = nmLbuf + sizeof(nmLbuf) - 1;
385 while(!issep(GETC(ch)) && ch!=EOF) {
388 return *rvp = err__fl(f__elist->cierr,131,what);
394 return *rvp = err__fl(f__elist->cierr,112,what);
397 nmL_getc_save = l_getc;
399 nmL_ungetc_save = l_ungetc;
400 l_ungetc = nmL_ungetc;
401 nmLbuf[1] = *(nmL_next = nmLbuf) = ',';
402 *rvp = f__lcount = 0;
436 if(!f__cf || !feof(f__cf))
437 errfl(f__elist->cierr,112,"no star");
439 err(f__elist->cierr,(EOF),"lread");
451 if (nml_read && Lfinish(ch, sawdot, &rv))
457 if (nml_read && Lfinish(ch, sawdot, &rv))
462 if(isblnk(ch) || issep(ch) || ch==EOF)
463 { (void) Ungetc(ch,f__cf);
471 errfl(f__elist->cierr,112,"logical");
474 while(!issep(GETC(ch)) && ch!=EOF);
475 (void) Ungetc(ch, f__cf);
484 static char rafail[] = "realloc failure";
486 if(f__lcount>0) return(0);
488 if(f__lchar!=NULL) free(f__lchar);
490 p=f__lchar = (char *)malloc((unsigned int)size);
492 errfl(f__elist->cierr,113,"no space");
496 /* allow Fortran 8x-style unquoted string... */
497 /* either find a repetition count or the string */
498 f__lcount = ch - '0';
503 if (f__lcount == 0) {
505 #ifndef F8X_NML_ELIDE_QUOTES
527 #ifndef F8X_NML_ELIDE_QUOTES
530 errfl(f__elist->cierr,112,
531 "undelimited character string");
537 f__lcount = 10*f__lcount + ch - '0';
539 f__lchar = (char *)realloc(f__lchar,
540 (unsigned int)(size += BUFSIZE));
542 errfl(f__elist->cierr,113,rafail);
547 else (void) Ungetc(ch,f__cf);
549 if(GETC(ch)=='\'' || ch=='"') quote=ch;
550 else if(isblnk(ch) || (issep(ch) && ch != '\n') || ch==EOF) {
554 #ifndef F8X_NML_ELIDE_QUOTES
555 else if (nml_read > 1) {
562 /* Fortran 8x-style unquoted string */
580 f__lchar = (char *)realloc(f__lchar,
581 (unsigned int)(size += BUFSIZE));
583 errfl(f__elist->cierr,113,rafail);
590 { while(GETC(ch)!=quote && ch!='\n'
591 && ch!=EOF && ++i<size) *p++ = ch;
595 f__lchar= (char *)realloc(f__lchar,
596 (unsigned int)(size += BUFSIZE));
598 errfl(f__elist->cierr,113,rafail);
602 else if(ch==EOF) return(EOF);
604 { if(*(p-1) != '\\') continue;
607 if(++i<size) *p++ = ch;
610 else if(GETC(ch)==quote)
611 { if(++i<size) *p++ = ch;
615 { (void) Ungetc(ch,f__cf);
627 if(f__init != 1) f_init();
630 f__curunit = &f__units[a->ciunit];
632 if(a->ciunit>=MXUNIT || a->ciunit<0)
633 err(a->cierr,101,"stler");
634 f__scale=f__recpos=0;
636 if(f__curunit->ufd==NULL && fk_open(SEQ,FMT,a->ciunit))
637 err(a->cierr,102,"lio");
638 f__cf=f__curunit->ufd;
639 if(!f__curunit->ufmt) err(a->cierr,103,"lio");
643 l_read(number,ptr,len,type) ftnint *number,type; char *ptr; ftnlen len;
645 l_read(ftnint *number, char *ptr, ftnlen len, ftnint type)
648 #define Ptr ((flex *)ptr)
652 for(i=0;i<*number;i++)
654 if(f__lquit) return(0);
656 err(f__elist->ciend, EOF, "list in");
663 err(f__elist->ciend,(EOF),"list in");
675 (void) Ungetc(ch, f__cf);
686 #ifndef ALLOW_FLOAT_IN_INTEGER_LIST_INPUT
714 while (GETC(ch) == ' ' || ch == '\t');
715 if (ch != ',' || f__lcount > 1)
718 if(f__lquit) return(0);
719 if(f__cf && ferror(f__cf)) {
721 errfl(f__elist->cierr,errno,"list in");
723 if(f__ltype==0) goto bump;
728 Ptr->flchar = (char)f__lx;
732 Ptr->flshort = (short)f__lx;
736 Ptr->flint = (ftnint)f__lx;
740 if (!(Ptr->fllongint = f__llx))
741 Ptr->fllongint = f__lx;
756 yy=(doublereal *)ptr;
761 b_char(f__lchar,ptr,len);
765 if(f__lcount>0) f__lcount--;
774 integer s_rsle(a) cilist *a;
776 integer s_rsle(cilist *a)
784 if(n=c_le(a)) return(n);
789 if(f__curunit->uwrt && f__nowreading(f__curunit))
790 err(a->cierr,errno,"read start");
792 err(f__elist->ciend,(EOF),"read start");