1*47943Sbostic /*-
2*47943Sbostic * Copyright (c) 1980 The Regents of the University of California.
3*47943Sbostic * All rights reserved.
424099Sjerry *
5*47943Sbostic * %sccs.include.proprietary.c%
624099Sjerry */
724099Sjerry
8*47943Sbostic #ifndef lint
9*47943Sbostic static char sccsid[] = "@(#)rsnmle.c 5.5 (Berkeley) 04/12/91";
10*47943Sbostic #endif /* not lint */
11*47943Sbostic
1224099Sjerry /*
1324099Sjerry * name-list read
1424099Sjerry */
1524099Sjerry
1624099Sjerry #include "fio.h"
1724099Sjerry #include "lio.h"
1824099Sjerry #include "nmlio.h"
1924099Sjerry #include <ctype.h>
2024099Sjerry
2124468Sjerry LOCAL char *nml_rd;
2224099Sjerry
2324099Sjerry static int ch;
2424258Sjerry LOCAL nameflag;
2524258Sjerry LOCAL char var_name[VL+1];
2624099Sjerry
2724099Sjerry #define SP 1
2824099Sjerry #define B 2
2924099Sjerry #define AP 4
3024099Sjerry #define EX 8
3124258Sjerry #define INTG 16
3224258Sjerry #define RL 32
3324258Sjerry #define LGC 64
3424258Sjerry #define IRL (INTG | RL | LGC )
3524099Sjerry #define isblnk(x) (ltab[x+1]&B) /* space, tab, newline */
3624099Sjerry #define issep(x) (ltab[x+1]&SP) /* space, tab, newline, comma */
3724099Sjerry #define isapos(x) (ltab[x+1]&AP) /* apost., quote mark */
3824099Sjerry #define isexp(x) (ltab[x+1]&EX) /* d, e, D, E */
3924258Sjerry #define isint(x) (ltab[x+1]&INTG) /* 0-9, plus, minus */
4024258Sjerry #define isrl(x) (ltab[x+1]&RL) /* 0-9, plus, minus, period */
4124258Sjerry #define islgc(x) (ltab[x+1]&LGC) /* 0-9, period, t, f, T, F */
4224099Sjerry
4324468Sjerry #define GETC (ch=t_getc())
4424099Sjerry #define UNGETC() ungetc(ch,cf)
4524099Sjerry
4624099Sjerry LOCAL char *lchar;
4724099Sjerry LOCAL double lx,ly;
4824099Sjerry LOCAL int ltype;
4924099Sjerry int t_getc(), ungetc();
5024099Sjerry
5124099Sjerry LOCAL char ltab[128+1] =
5224099Sjerry { 0, /* offset one for EOF */
5324258Sjerry /* 0- 15 */ 0,0,0,0,0,0,0,0,0,SP|B,SP|B,0,0,0,0,0, /* TAB,NEWLINE */
5424258Sjerry /* 16- 31 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
5524258Sjerry /* 32- 47 */ SP|B,0,AP,0,0,0,0,AP,0,0,0,RL|INTG,SP,RL|INTG,RL|LGC,0, /* space,",',comma,., */
5624258Sjerry /* 48- 63 */ IRL,IRL,IRL,IRL,IRL,IRL,IRL,IRL,IRL,IRL,0,0,0,0,0,0, /* digits */
5724258Sjerry /* 64- 79 */ 0,0,0,0,EX,EX,LGC,0,0,0,0,0,0,0,0,0, /* D,E,F */
5824258Sjerry /* 80- 95 */ 0,0,0,0,LGC,0,0,0,0,0,0,0,0,0,0,0, /* T */
5924258Sjerry /* 96-111 */ 0,0,0,0,EX,EX,LGC,0,0,0,0,0,0,0,0,0, /* d,e,f */
6024258Sjerry /* 112-127 */ 0,0,0,0,LGC,0,0,0,0,0,0,0,0,0,0,0 /* t */
6124099Sjerry };
6224099Sjerry
s_rsne(a)6324099Sjerry s_rsne(a) namelist_arglist *a;
6424099Sjerry {
6524468Sjerry int n;
6624099Sjerry struct namelistentry *entry;
6724099Sjerry int nelem, vlen, vtype;
6824099Sjerry char *nmlist_nm, *addr;
6924099Sjerry
7024468Sjerry nml_rd = "namelist read";
7124099Sjerry reading = YES;
7224099Sjerry formatted = NAMELIST;
7324099Sjerry fmtbuf = "ext namelist io";
7424099Sjerry if(n=c_le(a,READ)) return(n);
7524099Sjerry getn = t_getc;
7624099Sjerry ungetn = ungetc;
7724099Sjerry leof = curunit->uend;
7824099Sjerry if(curunit->uwrt && ! nowreading(curunit)) err(errflag, errno, nml_rd)
7924099Sjerry
8024099Sjerry /* look for " &namelistname " */
8124099Sjerry nmlist_nm = a->namelist->namelistname;
8224468Sjerry while(isblnk(GETC)) ;
8324099Sjerry /* check for "&end" (like IBM) or "$end" (like DEC) */
8424099Sjerry if(ch != '&' && ch != '$') goto rderr;
8524099Sjerry /* save it - write out using the same character as used on input */
8624099Sjerry namelistkey_ = ch;
8724099Sjerry while( *nmlist_nm )
8824468Sjerry if( GETC != *nmlist_nm++ )
8924468Sjerry {
9024468Sjerry nml_rd = "incorrect namelist name";
9124468Sjerry goto rderr;
9224468Sjerry }
9324468Sjerry if(!isblnk(GETC)) goto rderr;
9424468Sjerry while(isblnk(GETC)) ;
9524099Sjerry if(leof) goto rderr;
9624099Sjerry UNGETC();
9724099Sjerry
9824468Sjerry while( GETC != namelistkey_ )
9924099Sjerry {
10024258Sjerry UNGETC();
10124099Sjerry /* get variable name */
10224258Sjerry if(!nameflag && rd_name(var_name)) goto rderr;
10324258Sjerry
10424099Sjerry entry = a->namelist->names;
10524099Sjerry /* loop through namelist entries looking for this variable name */
10624099Sjerry while( entry->varname[0] != 0 )
10724099Sjerry {
10824099Sjerry if( strcmp(entry->varname, var_name) == 0 ) goto got_name;
10924099Sjerry entry++;
11024099Sjerry }
11124468Sjerry nml_rd = "incorrect variable name";
11224099Sjerry goto rderr;
11324099Sjerry got_name:
11424258Sjerry if( n = get_pars( entry, &addr, &nelem, &vlen, &vtype ))
11524099Sjerry goto rderr_n;
11624468Sjerry while(isblnk(GETC)) ;
11724099Sjerry if(ch != '=') goto rderr;
11824258Sjerry
11924258Sjerry nameflag = NO;
12024468Sjerry if(n = l_read( nelem, addr, vlen, vtype )) goto rderr_n;
12124468Sjerry while(isblnk(GETC));
12224468Sjerry if(ch == ',') while(isblnk(GETC));
12324099Sjerry UNGETC();
12424099Sjerry if(leof) goto rderr;
12524099Sjerry }
12624099Sjerry /* check for 'end' after '&' or '$'*/
12724468Sjerry if(GETC!='e' || GETC!='n' || GETC!='d' )
12824099Sjerry goto rderr;
12924099Sjerry /* flush to next input record */
13024099Sjerry flush:
13124468Sjerry while(GETC != '\n' && ch != EOF);
13224099Sjerry return(ch == EOF ? EOF : OK);
13324099Sjerry
13424099Sjerry rderr:
13524099Sjerry if(leof)
13624468Sjerry n = EOF;
13724099Sjerry else
13824468Sjerry n = F_ERNMLIST;
13924468Sjerry rderr_n:
14024468Sjerry if(n == EOF ) err(endflag,EOF,nml_rd);
14124468Sjerry /* flush after error in case restart I/O */
14224468Sjerry if(ch != '\n') while(GETC != '\n' && ch != EOF) ;
14324468Sjerry err(errflag,n,nml_rd)
14424099Sjerry }
14524099Sjerry
14624099Sjerry #define MAXSUBS 7
14724099Sjerry
14824099Sjerry LOCAL
get_pars(entry,addr,nelem,vlen,vtype)14924099Sjerry get_pars( entry, addr, nelem, vlen, vtype )
15024099Sjerry struct namelistentry *entry;
15124099Sjerry char **addr; /* beginning address to read into */
15224099Sjerry int *nelem, /* number of elements to read */
15324099Sjerry *vlen, /* length of elements */
15424099Sjerry *vtype; /* type of elements */
15524099Sjerry {
15624099Sjerry int offset, i, n,
15724099Sjerry *dimptr, /* points to dimensioning info */
15824099Sjerry ndim, /* number of dimensions */
15924099Sjerry baseoffset, /* offset of corner element */
16024099Sjerry *span, /* subscript span for each dimension */
16124099Sjerry subs[MAXSUBS], /* actual subscripts */
16224099Sjerry subcnt = -1; /* number of actual subscripts */
16324099Sjerry
16424099Sjerry
16524099Sjerry /* get element size and base address */
16624099Sjerry *vlen = entry->typelen;
16724099Sjerry *addr = entry->varaddr;
16824099Sjerry
16924099Sjerry /* get type */
17024099Sjerry switch ( *vtype = entry->type ) {
17124099Sjerry case TYSHORT:
17224099Sjerry case TYLONG:
17324099Sjerry case TYREAL:
17424099Sjerry case TYDREAL:
17524099Sjerry case TYCOMPLEX:
17624099Sjerry case TYDCOMPLEX:
17724099Sjerry case TYLOGICAL:
17824099Sjerry case TYCHAR:
17924099Sjerry break;
18024099Sjerry default:
18124258Sjerry fatal(F_ERSYS,"unknown type in rsnmle");
18224099Sjerry }
18324099Sjerry
18424099Sjerry /* get number of elements */
18524099Sjerry dimptr = entry->dimp;
18624099Sjerry if( dimptr==NULL )
18724099Sjerry { /* scalar */
18824099Sjerry *nelem = 1;
18924099Sjerry return(OK);
19024099Sjerry }
19124099Sjerry
19224468Sjerry if( GETC != '(' )
19324099Sjerry { /* entire array */
19424099Sjerry *nelem = dimptr[1];
19524099Sjerry UNGETC();
19624099Sjerry return(OK);
19724099Sjerry }
19824099Sjerry
19924099Sjerry /* get element length, number of dimensions, base, span vector */
20024099Sjerry ndim = dimptr[0];
20124099Sjerry if(ndim<=0 || ndim>MAXSUBS) fatal(F_ERSYS,"illegal dimensions");
20224099Sjerry baseoffset = dimptr[2];
20324099Sjerry span = dimptr+3;
20424099Sjerry
20524099Sjerry /* get subscripts from input data */
20624099Sjerry while(ch!=')') {
20724099Sjerry if( ++subcnt > MAXSUBS-1 ) return F_ERNMLIST;
20824099Sjerry if(n=get_int(&subs[subcnt])) return n;
20924468Sjerry GETC;
21024099Sjerry if(leof) return EOF;
21124099Sjerry if(ch != ',' && ch != ')') return F_ERNMLIST;
21224099Sjerry }
21324099Sjerry if( ++subcnt != ndim ) return F_ERNMLIST;
21424099Sjerry
21524099Sjerry offset = subs[ndim-1];
21624099Sjerry for( i = ndim-2; i>=0; i-- )
21724099Sjerry offset = subs[i] + span[i]*offset;
21824099Sjerry offset -= baseoffset;
21924099Sjerry *nelem = dimptr[1] - offset;
22024099Sjerry if( offset < 0 || offset >= dimptr[1] )
22124099Sjerry return F_ERNMLIST;
22224099Sjerry *addr = *addr + (*vlen)*offset;
22324099Sjerry return OK;
22424099Sjerry }
22524099Sjerry
22624099Sjerry LOCAL
get_int(subval)22724099Sjerry get_int(subval)
22824099Sjerry int *subval;
22924099Sjerry {
23024099Sjerry int sign=0, value=0, cnt=0;
23124099Sjerry
23224099Sjerry /* look for sign */
23324468Sjerry if(GETC == '-') sign = -1;
23424099Sjerry else if(ch == '+') ;
23524099Sjerry else UNGETC();
23624099Sjerry if(ch == EOF) return(EOF);
23724099Sjerry
23824468Sjerry while(isdigit(GETC))
23924099Sjerry {
24024099Sjerry value = 10*value + ch-'0';
24124099Sjerry cnt++;
24224099Sjerry }
24324099Sjerry UNGETC();
24433067Sbostic if(ch == EOF) return EOF;
24524099Sjerry if(cnt == 0 ) return F_ERNMLIST;
24624099Sjerry if(sign== -1) value = -value;
24724099Sjerry *subval = value;
24824099Sjerry return OK;
24924099Sjerry }
25024099Sjerry
25124099Sjerry LOCAL
rd_name(ptr)25224099Sjerry rd_name(ptr)
25324099Sjerry char *ptr;
25424099Sjerry {
25524099Sjerry /* read a variable name from the input stream */
25624099Sjerry char *init = ptr-1;
25724099Sjerry
25824468Sjerry if(!isalpha(GETC)) {
25924099Sjerry UNGETC();
26024099Sjerry return(ERROR);
26124099Sjerry }
26224099Sjerry *ptr++ = ch;
26324468Sjerry while(isalnum(GETC))
26424099Sjerry {
26524099Sjerry if(ptr-init > VL ) return(ERROR);
26624099Sjerry *ptr++ = ch;
26724099Sjerry }
26824099Sjerry *ptr = '\0';
26924099Sjerry UNGETC();
27024099Sjerry return(OK);
27124099Sjerry }
27224099Sjerry
27324099Sjerry LOCAL
t_getc()27424099Sjerry t_getc()
27524099Sjerry { int ch;
27624099Sjerry static newline = YES;
27724099Sjerry rd:
27824099Sjerry if(curunit->uend) {
27924099Sjerry leof = EOF;
28024099Sjerry return(EOF);
28124099Sjerry }
28224099Sjerry if((ch=getc(cf))!=EOF)
28324099Sjerry {
28424099Sjerry if(ch == '\n') newline = YES;
28524099Sjerry else if(newline==YES)
28624099Sjerry { /* skip first character on each line for namelist */
28724099Sjerry newline = NO;
28824099Sjerry goto rd;
28924099Sjerry }
29024099Sjerry return(ch);
29124099Sjerry }
29224099Sjerry if(feof(cf))
29324099Sjerry { curunit->uend = YES;
29424099Sjerry leof = EOF;
29524099Sjerry }
29624099Sjerry else clearerr(cf);
29724099Sjerry return(EOF);
29824099Sjerry }
29924099Sjerry
30024099Sjerry LOCAL
l_read(number,ptr,len,type)30124099Sjerry l_read(number,ptr,len,type) ftnint number,type; flex *ptr; ftnlen len;
30224099Sjerry { int i,n;
30324099Sjerry double *yy;
30424099Sjerry float *xx;
30524258Sjerry
30624258Sjerry lcount = 0;
30724099Sjerry for(i=0;i<number;i++)
30824099Sjerry {
30924099Sjerry if(leof) return EOF;
31024258Sjerry if(lcount==0)
31124099Sjerry {
31224258Sjerry ltype = NULL;
31324258Sjerry if(i!=0)
31424258Sjerry { /* skip to comma */
31524468Sjerry while(isblnk(GETC));
31624258Sjerry if(leof) return(EOF);
31724258Sjerry if(ch == namelistkey_)
31824258Sjerry { UNGETC();
31924258Sjerry return(OK);
32024258Sjerry }
32124258Sjerry if(ch != ',' ) return(F_ERNMLIST);
32224258Sjerry }
32324468Sjerry while(isblnk(GETC));
32424258Sjerry if(leof) return(EOF);
32524099Sjerry UNGETC();
32624258Sjerry if(i!=0 && ch == namelistkey_) return(OK);
32724099Sjerry
32824099Sjerry switch((int)type)
32924099Sjerry {
33024099Sjerry case TYSHORT:
33124099Sjerry case TYLONG:
33224258Sjerry if(!isint(ch)) return(OK);
33324258Sjerry ERRNM(l_R(1));
33424258Sjerry break;
33524099Sjerry case TYREAL:
33624099Sjerry case TYDREAL:
33724258Sjerry if(!isrl(ch)) return(OK);
33824099Sjerry ERRNM(l_R(1));
33924099Sjerry break;
34024099Sjerry case TYCOMPLEX:
34124099Sjerry case TYDCOMPLEX:
34224258Sjerry if(!isdigit(ch) && ch!='(') return(OK);
34324099Sjerry ERRNM(l_C());
34424099Sjerry break;
34524099Sjerry case TYLOGICAL:
34624258Sjerry if(!islgc(ch)) return(OK);
34724099Sjerry ERRNM(l_L());
34824258Sjerry if(nameflag) return(OK);
34924099Sjerry break;
35024099Sjerry case TYCHAR:
35124258Sjerry if(!isdigit(ch) && !isapos(ch)) return(OK);
35224099Sjerry ERRNM(l_CHAR());
35324099Sjerry break;
35424099Sjerry }
35524099Sjerry
35624258Sjerry if(leof) return(EOF);
35724258Sjerry /* peek at next character -
35824258Sjerry should be separator or namelistkey_ */
35924468Sjerry GETC; UNGETC();
36024258Sjerry if(!issep(ch) && (ch != namelistkey_))
36124099Sjerry return( leof?EOF:F_ERNMLIST );
36224258Sjerry }
36324099Sjerry
36424258Sjerry if(!ltype) return(F_ERNMLIST);
36524258Sjerry switch((int)type)
36624099Sjerry {
36724099Sjerry case TYSHORT:
36824099Sjerry ptr->flshort=lx;
36924099Sjerry break;
37024099Sjerry case TYLOGICAL:
37124099Sjerry if(len == sizeof(short))
37224099Sjerry ptr->flshort = lx;
37324099Sjerry else
37424099Sjerry ptr->flint = lx;
37524099Sjerry break;
37624099Sjerry case TYLONG:
37724099Sjerry ptr->flint=lx;
37824099Sjerry break;
37924099Sjerry case TYREAL:
38024099Sjerry ptr->flreal=lx;
38124099Sjerry break;
38224099Sjerry case TYDREAL:
38324099Sjerry ptr->fldouble=lx;
38424099Sjerry break;
38524099Sjerry case TYCOMPLEX:
38624099Sjerry xx=(float *)ptr;
38724099Sjerry *xx++ = ly;
38824099Sjerry *xx = lx;
38924099Sjerry break;
39024099Sjerry case TYDCOMPLEX:
39124099Sjerry yy=(double *)ptr;
39224099Sjerry *yy++ = ly;
39324099Sjerry *yy = lx;
39424099Sjerry break;
39524099Sjerry case TYCHAR:
39624099Sjerry b_char(lchar,(char *)ptr,len);
39724099Sjerry break;
39824099Sjerry }
39924099Sjerry if(lcount>0) lcount--;
40024099Sjerry ptr = (flex *)((char *)ptr + len);
40124099Sjerry }
40224099Sjerry if(lcount>0) return F_ERNMLIST;
40324099Sjerry return(OK);
40424099Sjerry }
40524099Sjerry
40624099Sjerry LOCAL
get_repet()40724099Sjerry get_repet()
40824468Sjerry {
40924099Sjerry double lc;
41024468Sjerry if(isdigit(GETC))
41124099Sjerry { UNGETC();
41224099Sjerry rd_int(&lc);
41324099Sjerry lcount = (int)lc;
41424468Sjerry if(GETC!='*')
41524099Sjerry if(leof) return(EOF);
41624099Sjerry else return(F_ERREPT);
41724099Sjerry }
41824099Sjerry else
41924099Sjerry { lcount = 1;
42024099Sjerry UNGETC();
42124099Sjerry }
42224099Sjerry return(OK);
42324099Sjerry }
42424099Sjerry
42524099Sjerry LOCAL
l_R(flg)42624099Sjerry l_R(flg) int flg;
42724099Sjerry { double a,b,c,d;
42824099Sjerry int da,db,dc,dd;
42924468Sjerry int i,sign=0;
43024099Sjerry a=b=c=d=0;
43124099Sjerry da=db=dc=dd=0;
43224099Sjerry
43324099Sjerry if( flg ) /* real */
43424099Sjerry {
43524099Sjerry da=rd_int(&a); /* repeat count ? */
43624468Sjerry if(GETC=='*')
43724099Sjerry {
43824099Sjerry if (a <= 0.) return(F_ERNREP);
43924099Sjerry lcount=(int)a;
44024099Sjerry db=rd_int(&b); /* whole part of number */
44124099Sjerry }
44224099Sjerry else
44324099Sjerry { UNGETC();
44424099Sjerry db=da;
44524099Sjerry b=a;
44624099Sjerry lcount=1;
44724099Sjerry }
44824099Sjerry }
44924099Sjerry else /* complex */
45024099Sjerry {
45124099Sjerry db=rd_int(&b);
45224099Sjerry }
45324099Sjerry
45424468Sjerry if(GETC=='.' && isdigit(GETC))
45524099Sjerry { UNGETC();
45624099Sjerry dc=rd_int(&c); /* fractional part of number */
45724099Sjerry }
45824099Sjerry else
45924099Sjerry { UNGETC();
46024099Sjerry dc=0;
46124099Sjerry c=0.;
46224099Sjerry }
46324468Sjerry if(isexp(GETC))
46424099Sjerry dd=rd_int(&d); /* exponent */
46524099Sjerry else if (ch == '+' || ch == '-')
46624099Sjerry { UNGETC();
46724099Sjerry dd=rd_int(&d);
46824099Sjerry }
46924099Sjerry else
47024099Sjerry { UNGETC();
47124099Sjerry dd=0;
47224099Sjerry }
47324099Sjerry if(db<0 || b<0)
47424099Sjerry { sign=1;
47524099Sjerry b = -b;
47624099Sjerry }
47724099Sjerry for(i=0;i<dc;i++) c/=10.;
47824099Sjerry b=b+c;
47924099Sjerry if (dd > 0)
48024099Sjerry { for(i=0;i<d;i++) b *= 10.;
48124099Sjerry for(i=0;i< -d;i++) b /= 10.;
48224099Sjerry }
48324099Sjerry lx=sign?-b:b;
48424099Sjerry ltype=TYLONG;
48524099Sjerry return(OK);
48624099Sjerry }
48724099Sjerry
48824099Sjerry LOCAL
rd_int(x)48924099Sjerry rd_int(x) double *x;
49024468Sjerry { int sign=0,i=0;
49124099Sjerry double y=0.0;
49224468Sjerry if(GETC=='-') sign = -1;
49324099Sjerry else if(ch=='+') sign=0;
49424099Sjerry else UNGETC();
49524468Sjerry while(isdigit(GETC))
49624099Sjerry { i++;
49724099Sjerry y=10*y + ch-'0';
49824099Sjerry }
49924099Sjerry UNGETC();
50024099Sjerry if(sign) y = -y;
50124099Sjerry *x = y;
50224099Sjerry return(y==0.0?sign:i); /* 0:[+]&&y==0, -1:-&&y==0, >0:#digits&&y!=0 */
50324099Sjerry }
50424099Sjerry
50524099Sjerry LOCAL
l_C()50624099Sjerry l_C()
50724468Sjerry { int n;
50824099Sjerry if(n=get_repet()) return(n); /* get repeat count */
50924468Sjerry if(GETC!='(') err(errflag,F_ERNMLIST,"no (")
51024468Sjerry while(isblnk(GETC));
51124099Sjerry UNGETC();
51224099Sjerry l_R(0); /* get real part */
51324099Sjerry ly = lx;
51424468Sjerry while(isblnk(GETC)); /* get comma */
51524258Sjerry if(leof) return(EOF);
51624258Sjerry if(ch!=',') return(F_ERNMLIST);
51724468Sjerry while(isblnk(GETC));
51824258Sjerry UNGETC();
51924258Sjerry if(leof) return(EOF);
52024099Sjerry l_R(0); /* get imag part */
52124468Sjerry while(isblnk(GETC));
52224099Sjerry if(ch!=')') err(errflag,F_ERNMLIST,"no )")
52324099Sjerry ltype = TYCOMPLEX;
52424099Sjerry return(OK);
52524099Sjerry }
52624099Sjerry
52724099Sjerry LOCAL
l_L()52824099Sjerry l_L()
52924099Sjerry {
53024468Sjerry int n, keychar=ch, scanned=NO;
53124468Sjerry if(ch=='f' || ch=='F' || ch=='t' || ch=='T')
53224258Sjerry {
53324468Sjerry scanned=YES;
53424258Sjerry if(rd_name(var_name))
53524258Sjerry return(leof?EOF:F_ERNMLIST);
53624468Sjerry while(isblnk(GETC));
53724468Sjerry UNGETC();
53824258Sjerry if(ch == '=' || ch == '(')
53924258Sjerry { /* found a name, not a value */
54024258Sjerry nameflag = YES;
54124258Sjerry return(OK);
54224258Sjerry }
54324258Sjerry }
54424258Sjerry else
54524258Sjerry {
54624258Sjerry if(n=get_repet()) return(n); /* get repeat count */
54724468Sjerry if(GETC=='.') GETC;
54824468Sjerry keychar = ch;
54924258Sjerry }
55024468Sjerry switch(keychar)
55124099Sjerry {
55224099Sjerry case 't':
55324099Sjerry case 'T':
55424099Sjerry lx=1;
55524099Sjerry break;
55624099Sjerry case 'f':
55724099Sjerry case 'F':
55824099Sjerry lx=0;
55924099Sjerry break;
56024099Sjerry default:
56124258Sjerry if(ch==EOF) return(EOF);
56224099Sjerry else err(errflag,F_ERNMLIST,"logical not T or F");
56324099Sjerry }
56424099Sjerry ltype=TYLOGICAL;
56524468Sjerry if(scanned==NO)
56624468Sjerry {
56724468Sjerry while(!issep(GETC) && ch!=EOF) ;
56824468Sjerry UNGETC();
56924468Sjerry }
57024099Sjerry if(ch == EOF ) return(EOF);
57124099Sjerry return(OK);
57224099Sjerry }
57324099Sjerry
57424099Sjerry #define BUFSIZE 128
57524099Sjerry LOCAL
l_CHAR()57624099Sjerry l_CHAR()
57724468Sjerry { int size,i,n;
57824099Sjerry char quote,*p;
57924099Sjerry if(n=get_repet()) return(n); /* get repeat count */
58024468Sjerry if(isapos(GETC)) quote=ch;
58124099Sjerry else if(ch == EOF) return EOF;
58224099Sjerry else return F_ERNMLIST;
58324099Sjerry ltype=TYCHAR;
58424099Sjerry if(lchar!=NULL) free(lchar);
58524099Sjerry size=BUFSIZE-1;
58624099Sjerry p=lchar=(char *)malloc(BUFSIZE);
58724099Sjerry if(lchar==NULL) return (F_ERSPACE);
58824099Sjerry for(i=0;;)
58924468Sjerry { while( GETC!=quote && ch!='\n' && ch!=EOF && ++i<size )
59024099Sjerry *p++ = ch;
59124099Sjerry if(i==size)
59224099Sjerry {
59324099Sjerry newone:
59424099Sjerry size += BUFSIZE;
59524099Sjerry lchar=(char *)realloc(lchar, size+1);
59624099Sjerry if(lchar==NULL) return( F_ERSPACE );
59724099Sjerry p=lchar+i-1;
59824099Sjerry *p++ = ch;
59924099Sjerry }
60024099Sjerry else if(ch==EOF) return(EOF);
60124099Sjerry else if(ch=='\n')
60224099Sjerry { if(*(p-1) == '\\') *(p-1) = ch;
60324099Sjerry }
60424468Sjerry else if(GETC==quote)
60524099Sjerry { if(++i<size) *p++ = ch;
60624099Sjerry else goto newone;
60724099Sjerry }
60824099Sjerry else
60924099Sjerry { UNGETC();
61024099Sjerry *p = '\0';
61124099Sjerry return(OK);
61224099Sjerry }
61324099Sjerry }
61424099Sjerry }
615