summary |
tags |
clone url |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
63e3f3c)
SCCS-vsn: usr.bin/f77/libI77/rsnmle.c 5.3
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*
#include "nmlio.h"
#include <ctype.h>
#include "nmlio.h"
#include <ctype.h>
-LOCAL char nml_rd[] = "namelist read";
static int ch;
LOCAL nameflag;
static int ch;
LOCAL nameflag;
#define isrl(x) (ltab[x+1]&RL) /* 0-9, plus, minus, period */
#define islgc(x) (ltab[x+1]&LGC) /* 0-9, period, t, f, T, F */
#define isrl(x) (ltab[x+1]&RL) /* 0-9, plus, minus, period */
#define islgc(x) (ltab[x+1]&LGC) /* 0-9, period, t, f, T, F */
-#define GETC(x) (x=t_getc())
+#define GETC (ch=t_getc())
#define UNGETC() ungetc(ch,cf)
LOCAL char *lchar;
#define UNGETC() ungetc(ch,cf)
LOCAL char *lchar;
s_rsne(a) namelist_arglist *a;
{
s_rsne(a) namelist_arglist *a;
{
struct namelistentry *entry;
int nelem, vlen, vtype;
char *nmlist_nm, *addr;
struct namelistentry *entry;
int nelem, vlen, vtype;
char *nmlist_nm, *addr;
+ nml_rd = "namelist read";
reading = YES;
formatted = NAMELIST;
fmtbuf = "ext namelist io";
reading = YES;
formatted = NAMELIST;
fmtbuf = "ext namelist io";
/* look for " &namelistname " */
nmlist_nm = a->namelist->namelistname;
/* look for " &namelistname " */
nmlist_nm = a->namelist->namelistname;
- while(isblnk(GETC(ch))) ;
/* check for "&end" (like IBM) or "$end" (like DEC) */
if(ch != '&' && ch != '$') goto rderr;
/* save it - write out using the same character as used on input */
namelistkey_ = ch;
while( *nmlist_nm )
/* check for "&end" (like IBM) or "$end" (like DEC) */
if(ch != '&' && ch != '$') goto rderr;
/* save it - write out using the same character as used on input */
namelistkey_ = ch;
while( *nmlist_nm )
- if( GETC(ch) != *nmlist_nm++ ) goto rderr;
- if(!isblnk(GETC(ch))) goto rderr;
- while(isblnk(GETC(ch))) ;
+ if( GETC != *nmlist_nm++ )
+ {
+ nml_rd = "incorrect namelist name";
+ goto rderr;
+ }
+ if(!isblnk(GETC)) goto rderr;
+ while(isblnk(GETC)) ;
if(leof) goto rderr;
UNGETC();
if(leof) goto rderr;
UNGETC();
- while( GETC(ch) != namelistkey_ )
+ while( GETC != namelistkey_ )
{
UNGETC();
/* get variable name */
{
UNGETC();
/* get variable name */
if( strcmp(entry->varname, var_name) == 0 ) goto got_name;
entry++;
}
if( strcmp(entry->varname, var_name) == 0 ) goto got_name;
entry++;
}
+ nml_rd = "incorrect variable name";
goto rderr;
got_name:
if( n = get_pars( entry, &addr, &nelem, &vlen, &vtype ))
goto rderr_n;
goto rderr;
got_name:
if( n = get_pars( entry, &addr, &nelem, &vlen, &vtype ))
goto rderr_n;
- while(isblnk(GETC(ch))) ;
if(ch != '=') goto rderr;
nameflag = NO;
if(ch != '=') goto rderr;
nameflag = NO;
- if(n = l_read( nelem, addr, vlen, vtype ))
- {
-rderr_n:
- err(n<0?endflag:errflag,n,nml_rd)
- }
- while(isblnk(GETC(ch)));
- if(ch == ',') while(isblnk(GETC(ch)));
+ if(n = l_read( nelem, addr, vlen, vtype )) goto rderr_n;
+ while(isblnk(GETC));
+ if(ch == ',') while(isblnk(GETC));
UNGETC();
if(leof) goto rderr;
}
/* check for 'end' after '&' or '$'*/
UNGETC();
if(leof) goto rderr;
}
/* check for 'end' after '&' or '$'*/
- if(GETC(ch)!='e' || GETC(ch)!='n' || GETC(ch)!='d' )
+ if(GETC!='e' || GETC!='n' || GETC!='d' )
goto rderr;
/* flush to next input record */
flush:
goto rderr;
/* flush to next input record */
flush:
- while(GETC(ch) != '\n' && ch != EOF);
+ while(GETC != '\n' && ch != EOF);
return(ch == EOF ? EOF : OK);
rderr:
if(leof)
return(ch == EOF ? EOF : OK);
rderr:
if(leof)
- err(endflag,EOF,nml_rd)
- err(errflag,F_ERNMLIST,nml_rd)
- goto flush;
+ n = F_ERNMLIST;
+rderr_n:
+ if(n == EOF ) err(endflag,EOF,nml_rd);
+ /* flush after error in case restart I/O */
+ if(ch != '\n') while(GETC != '\n' && ch != EOF) ;
+ err(errflag,n,nml_rd)
{ /* entire array */
*nelem = dimptr[1];
UNGETC();
{ /* entire array */
*nelem = dimptr[1];
UNGETC();
while(ch!=')') {
if( ++subcnt > MAXSUBS-1 ) return F_ERNMLIST;
if(n=get_int(&subs[subcnt])) return n;
while(ch!=')') {
if( ++subcnt > MAXSUBS-1 ) return F_ERNMLIST;
if(n=get_int(&subs[subcnt])) return n;
if(leof) return EOF;
if(ch != ',' && ch != ')') return F_ERNMLIST;
}
if(leof) return EOF;
if(ch != ',' && ch != ')') return F_ERNMLIST;
}
int sign=0, value=0, cnt=0;
/* look for sign */
int sign=0, value=0, cnt=0;
/* look for sign */
- if(GETC(ch) == '-') sign = -1;
+ if(GETC == '-') sign = -1;
else if(ch == '+') ;
else UNGETC();
if(ch == EOF) return(EOF);
else if(ch == '+') ;
else UNGETC();
if(ch == EOF) return(EOF);
- while(isdigit(GETC(ch)))
{
value = 10*value + ch-'0';
cnt++;
{
value = 10*value + ch-'0';
cnt++;
/* read a variable name from the input stream */
char *init = ptr-1;
/* read a variable name from the input stream */
char *init = ptr-1;
- if(!isalpha(GETC(ch))) {
UNGETC();
return(ERROR);
}
*ptr++ = ch;
UNGETC();
return(ERROR);
}
*ptr++ = ch;
- while(isalnum(GETC(ch)))
{
if(ptr-init > VL ) return(ERROR);
*ptr++ = ch;
{
if(ptr-init > VL ) return(ERROR);
*ptr++ = ch;
ltype = NULL;
if(i!=0)
{ /* skip to comma */
ltype = NULL;
if(i!=0)
{ /* skip to comma */
- while(isblnk(GETC(ch)));
if(leof) return(EOF);
if(ch == namelistkey_)
{ UNGETC();
if(leof) return(EOF);
if(ch == namelistkey_)
{ UNGETC();
}
if(ch != ',' ) return(F_ERNMLIST);
}
}
if(ch != ',' ) return(F_ERNMLIST);
}
- while(isblnk(GETC(ch)));
if(leof) return(EOF);
UNGETC();
if(i!=0 && ch == namelistkey_) return(OK);
if(leof) return(EOF);
UNGETC();
if(i!=0 && ch == namelistkey_) return(OK);
if(leof) return(EOF);
/* peek at next character -
should be separator or namelistkey_ */
if(leof) return(EOF);
/* peek at next character -
should be separator or namelistkey_ */
if(!issep(ch) && (ch != namelistkey_))
return( leof?EOF:F_ERNMLIST );
}
if(!issep(ch) && (ch != namelistkey_))
return( leof?EOF:F_ERNMLIST );
}
{ UNGETC();
rd_int(&lc);
lcount = (int)lc;
{ UNGETC();
rd_int(&lc);
lcount = (int)lc;
if(leof) return(EOF);
else return(F_ERREPT);
}
if(leof) return(EOF);
else return(F_ERREPT);
}
l_R(flg) int flg;
{ double a,b,c,d;
int da,db,dc,dd;
l_R(flg) int flg;
{ double a,b,c,d;
int da,db,dc,dd;
a=b=c=d=0;
da=db=dc=dd=0;
if( flg ) /* real */
{
da=rd_int(&a); /* repeat count ? */
a=b=c=d=0;
da=db=dc=dd=0;
if( flg ) /* real */
{
da=rd_int(&a); /* repeat count ? */
{
if (a <= 0.) return(F_ERNREP);
lcount=(int)a;
{
if (a <= 0.) return(F_ERNREP);
lcount=(int)a;
- if(GETC(ch)=='.' && isdigit(GETC(ch)))
+ if(GETC=='.' && isdigit(GETC))
{ UNGETC();
dc=rd_int(&c); /* fractional part of number */
}
{ UNGETC();
dc=rd_int(&c); /* fractional part of number */
}
dd=rd_int(&d); /* exponent */
else if (ch == '+' || ch == '-')
{ UNGETC();
dd=rd_int(&d); /* exponent */
else if (ch == '+' || ch == '-')
{ UNGETC();
LOCAL
rd_int(x) double *x;
LOCAL
rd_int(x) double *x;
- if(GETC(ch)=='-') sign = -1;
+ if(GETC=='-') sign = -1;
else if(ch=='+') sign=0;
else UNGETC();
else if(ch=='+') sign=0;
else UNGETC();
- while(isdigit(GETC(ch)))
{ i++;
y=10*y + ch-'0';
}
{ i++;
y=10*y + ch-'0';
}
if(n=get_repet()) return(n); /* get repeat count */
if(n=get_repet()) return(n); /* get repeat count */
- if(GETC(ch)!='(') err(errflag,F_ERNMLIST,"no (")
- while(isblnk(GETC(ch)));
+ if(GETC!='(') err(errflag,F_ERNMLIST,"no (")
+ while(isblnk(GETC));
UNGETC();
l_R(0); /* get real part */
ly = lx;
UNGETC();
l_R(0); /* get real part */
ly = lx;
- while(isblnk(GETC(ch))); /* get comma */
+ while(isblnk(GETC)); /* get comma */
if(leof) return(EOF);
if(ch!=',') return(F_ERNMLIST);
if(leof) return(EOF);
if(ch!=',') return(F_ERNMLIST);
- while(isblnk(GETC(ch)));
UNGETC();
if(leof) return(EOF);
l_R(0); /* get imag part */
UNGETC();
if(leof) return(EOF);
l_R(0); /* get imag part */
- while(isblnk(GETC(ch)));
if(ch!=')') err(errflag,F_ERNMLIST,"no )")
ltype = TYCOMPLEX;
return(OK);
if(ch!=')') err(errflag,F_ERNMLIST,"no )")
ltype = TYCOMPLEX;
return(OK);
- int n;
- if(!isdigit(ch) && ch != '.')
+ int n, keychar=ch, scanned=NO;
+ if(ch=='f' || ch=='F' || ch=='t' || ch=='T')
if(rd_name(var_name))
return(leof?EOF:F_ERNMLIST);
if(rd_name(var_name))
return(leof?EOF:F_ERNMLIST);
- while(isblnk(GETC(ch)));
+ while(isblnk(GETC));
+ UNGETC();
if(ch == '=' || ch == '(')
{ /* found a name, not a value */
if(ch == '=' || ch == '(')
{ /* found a name, not a value */
nameflag = YES;
return(OK);
}
nameflag = YES;
return(OK);
}
else
{
if(n=get_repet()) return(n); /* get repeat count */
else
{
if(n=get_repet()) return(n); /* get repeat count */
- if(GETC(ch)=='.') GETC(ch);
+ if(GETC=='.') GETC;
+ keychar = ch;
else err(errflag,F_ERNMLIST,"logical not T or F");
}
ltype=TYLOGICAL;
else err(errflag,F_ERNMLIST,"logical not T or F");
}
ltype=TYLOGICAL;
- while(!issep(GETC(ch)) && ch!=EOF) ;
- UNGETC();
+ if(scanned==NO)
+ {
+ while(!issep(GETC) && ch!=EOF) ;
+ UNGETC();
+ }
if(ch == EOF ) return(EOF);
return(OK);
}
if(ch == EOF ) return(EOF);
return(OK);
}
#define BUFSIZE 128
LOCAL
l_CHAR()
#define BUFSIZE 128
LOCAL
l_CHAR()
char quote,*p;
if(n=get_repet()) return(n); /* get repeat count */
char quote,*p;
if(n=get_repet()) return(n); /* get repeat count */
- if(isapos(GETC(ch))) quote=ch;
+ if(isapos(GETC)) quote=ch;
else if(ch == EOF) return EOF;
else return F_ERNMLIST;
ltype=TYCHAR;
else if(ch == EOF) return EOF;
else return F_ERNMLIST;
ltype=TYCHAR;
p=lchar=(char *)malloc(BUFSIZE);
if(lchar==NULL) return (F_ERSPACE);
for(i=0;;)
p=lchar=(char *)malloc(BUFSIZE);
if(lchar==NULL) return (F_ERSPACE);
for(i=0;;)
- { while( GETC(ch)!=quote && ch!='\n' && ch!=EOF && ++i<size )
+ { while( GETC!=quote && ch!='\n' && ch!=EOF && ++i<size )
else if(ch=='\n')
{ if(*(p-1) == '\\') *(p-1) = ch;
}
else if(ch=='\n')
{ if(*(p-1) == '\\') *(p-1) = ch;
}
- else if(GETC(ch)==quote)
{ if(++i<size) *p++ = ch;
else goto newone;
}
{ if(++i<size) *p++ = ch;
else goto newone;
}