124099Sjerry /* 224099Sjerry * Copyright (c) 1980 Regents of the University of California. 324099Sjerry * All rights reserved. The Berkeley software License Agreement 424099Sjerry * specifies the terms and conditions for redistribution. 524099Sjerry * 6*24258Sjerry * @(#)rsnmle.c 5.2 08/12/85 724099Sjerry */ 824099Sjerry 924099Sjerry /* 1024099Sjerry * name-list read 1124099Sjerry */ 1224099Sjerry 1324099Sjerry #include "fio.h" 1424099Sjerry #include "lio.h" 1524099Sjerry #include "nmlio.h" 1624099Sjerry #include <ctype.h> 1724099Sjerry 1824099Sjerry LOCAL char nml_rd[] = "namelist read"; 1924099Sjerry 2024099Sjerry static int ch; 21*24258Sjerry LOCAL nameflag; 22*24258Sjerry LOCAL char var_name[VL+1]; 2324099Sjerry 2424099Sjerry #define SP 1 2524099Sjerry #define B 2 2624099Sjerry #define AP 4 2724099Sjerry #define EX 8 28*24258Sjerry #define INTG 16 29*24258Sjerry #define RL 32 30*24258Sjerry #define LGC 64 31*24258Sjerry #define IRL (INTG | RL | LGC ) 3224099Sjerry #define isblnk(x) (ltab[x+1]&B) /* space, tab, newline */ 3324099Sjerry #define issep(x) (ltab[x+1]&SP) /* space, tab, newline, comma */ 3424099Sjerry #define isapos(x) (ltab[x+1]&AP) /* apost., quote mark */ 3524099Sjerry #define isexp(x) (ltab[x+1]&EX) /* d, e, D, E */ 36*24258Sjerry #define isint(x) (ltab[x+1]&INTG) /* 0-9, plus, minus */ 37*24258Sjerry #define isrl(x) (ltab[x+1]&RL) /* 0-9, plus, minus, period */ 38*24258Sjerry #define islgc(x) (ltab[x+1]&LGC) /* 0-9, period, t, f, T, F */ 3924099Sjerry 4024099Sjerry #define GETC(x) (x=t_getc()) 4124099Sjerry #define UNGETC() ungetc(ch,cf) 4224099Sjerry 4324099Sjerry LOCAL char *lchar; 4424099Sjerry LOCAL double lx,ly; 4524099Sjerry LOCAL int ltype; 4624099Sjerry int t_getc(), ungetc(); 4724099Sjerry 4824099Sjerry LOCAL char ltab[128+1] = 4924099Sjerry { 0, /* offset one for EOF */ 50*24258Sjerry /* 0- 15 */ 0,0,0,0,0,0,0,0,0,SP|B,SP|B,0,0,0,0,0, /* TAB,NEWLINE */ 51*24258Sjerry /* 16- 31 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 52*24258Sjerry /* 32- 47 */ SP|B,0,AP,0,0,0,0,AP,0,0,0,RL|INTG,SP,RL|INTG,RL|LGC,0, /* space,",',comma,., */ 53*24258Sjerry /* 48- 63 */ IRL,IRL,IRL,IRL,IRL,IRL,IRL,IRL,IRL,IRL,0,0,0,0,0,0, /* digits */ 54*24258Sjerry /* 64- 79 */ 0,0,0,0,EX,EX,LGC,0,0,0,0,0,0,0,0,0, /* D,E,F */ 55*24258Sjerry /* 80- 95 */ 0,0,0,0,LGC,0,0,0,0,0,0,0,0,0,0,0, /* T */ 56*24258Sjerry /* 96-111 */ 0,0,0,0,EX,EX,LGC,0,0,0,0,0,0,0,0,0, /* d,e,f */ 57*24258Sjerry /* 112-127 */ 0,0,0,0,LGC,0,0,0,0,0,0,0,0,0,0,0 /* t */ 5824099Sjerry }; 5924099Sjerry 6024099Sjerry s_rsne(a) namelist_arglist *a; 6124099Sjerry { 6224099Sjerry int n, first; 6324099Sjerry struct namelistentry *entry; 6424099Sjerry int nelem, vlen, vtype; 6524099Sjerry char *nmlist_nm, *addr; 6624099Sjerry 6724099Sjerry reading = YES; 6824099Sjerry formatted = NAMELIST; 6924099Sjerry fmtbuf = "ext namelist io"; 7024099Sjerry if(n=c_le(a,READ)) return(n); 7124099Sjerry getn = t_getc; 7224099Sjerry ungetn = ungetc; 7324099Sjerry leof = curunit->uend; 7424099Sjerry if(curunit->uwrt && ! nowreading(curunit)) err(errflag, errno, nml_rd) 7524099Sjerry 7624099Sjerry /* look for " &namelistname " */ 7724099Sjerry nmlist_nm = a->namelist->namelistname; 7824099Sjerry while(isblnk(GETC(ch))) ; 7924099Sjerry /* check for "&end" (like IBM) or "$end" (like DEC) */ 8024099Sjerry if(ch != '&' && ch != '$') goto rderr; 8124099Sjerry /* save it - write out using the same character as used on input */ 8224099Sjerry namelistkey_ = ch; 8324099Sjerry while( *nmlist_nm ) 8424099Sjerry if( GETC(ch) != *nmlist_nm++ ) goto rderr; 8524099Sjerry if(!isblnk(GETC(ch))) goto rderr; 8624099Sjerry while(isblnk(GETC(ch))) ; 8724099Sjerry if(leof) goto rderr; 8824099Sjerry UNGETC(); 8924099Sjerry 9024099Sjerry while( GETC(ch) != namelistkey_ ) 9124099Sjerry { 92*24258Sjerry UNGETC(); 9324099Sjerry /* get variable name */ 94*24258Sjerry if(!nameflag && rd_name(var_name)) goto rderr; 95*24258Sjerry 9624099Sjerry entry = a->namelist->names; 9724099Sjerry /* loop through namelist entries looking for this variable name */ 9824099Sjerry while( entry->varname[0] != 0 ) 9924099Sjerry { 10024099Sjerry if( strcmp(entry->varname, var_name) == 0 ) goto got_name; 10124099Sjerry entry++; 10224099Sjerry } 10324099Sjerry goto rderr; 10424099Sjerry got_name: 105*24258Sjerry if( n = get_pars( entry, &addr, &nelem, &vlen, &vtype )) 10624099Sjerry goto rderr_n; 10724099Sjerry while(isblnk(GETC(ch))) ; 10824099Sjerry if(ch != '=') goto rderr; 109*24258Sjerry 110*24258Sjerry nameflag = NO; 11124099Sjerry if(n = l_read( nelem, addr, vlen, vtype )) 11224099Sjerry { 11324099Sjerry rderr_n: 11424099Sjerry err(n<0?endflag:errflag,n,nml_rd) 11524099Sjerry } 11624099Sjerry while(isblnk(GETC(ch))); 11724099Sjerry if(ch == ',') while(isblnk(GETC(ch))); 11824099Sjerry UNGETC(); 11924099Sjerry if(leof) goto rderr; 12024099Sjerry } 12124099Sjerry /* check for 'end' after '&' or '$'*/ 12224099Sjerry if(GETC(ch)!='e' || GETC(ch)!='n' || GETC(ch)!='d' ) 12324099Sjerry goto rderr; 12424099Sjerry /* flush to next input record */ 12524099Sjerry flush: 12624099Sjerry while(GETC(ch) != '\n' && ch != EOF); 12724099Sjerry return(ch == EOF ? EOF : OK); 12824099Sjerry 12924099Sjerry rderr: 13024099Sjerry if(leof) 13124099Sjerry err(endflag,EOF,nml_rd) 13224099Sjerry else 13324099Sjerry err(errflag,F_ERNMLIST,nml_rd) 13424099Sjerry goto flush; 13524099Sjerry } 13624099Sjerry 13724099Sjerry #define MAXSUBS 7 13824099Sjerry 13924099Sjerry LOCAL 14024099Sjerry get_pars( entry, addr, nelem, vlen, vtype ) 14124099Sjerry struct namelistentry *entry; 14224099Sjerry char **addr; /* beginning address to read into */ 14324099Sjerry int *nelem, /* number of elements to read */ 14424099Sjerry *vlen, /* length of elements */ 14524099Sjerry *vtype; /* type of elements */ 14624099Sjerry { 14724099Sjerry int offset, i, n, 14824099Sjerry *dimptr, /* points to dimensioning info */ 14924099Sjerry ndim, /* number of dimensions */ 15024099Sjerry baseoffset, /* offset of corner element */ 15124099Sjerry *span, /* subscript span for each dimension */ 15224099Sjerry subs[MAXSUBS], /* actual subscripts */ 15324099Sjerry subcnt = -1; /* number of actual subscripts */ 15424099Sjerry 15524099Sjerry 15624099Sjerry /* get element size and base address */ 15724099Sjerry *vlen = entry->typelen; 15824099Sjerry *addr = entry->varaddr; 15924099Sjerry 16024099Sjerry /* get type */ 16124099Sjerry switch ( *vtype = entry->type ) { 16224099Sjerry case TYSHORT: 16324099Sjerry case TYLONG: 16424099Sjerry case TYREAL: 16524099Sjerry case TYDREAL: 16624099Sjerry case TYCOMPLEX: 16724099Sjerry case TYDCOMPLEX: 16824099Sjerry case TYLOGICAL: 16924099Sjerry case TYCHAR: 17024099Sjerry break; 17124099Sjerry default: 172*24258Sjerry fatal(F_ERSYS,"unknown type in rsnmle"); 17324099Sjerry } 17424099Sjerry 17524099Sjerry /* get number of elements */ 17624099Sjerry dimptr = entry->dimp; 17724099Sjerry if( dimptr==NULL ) 17824099Sjerry { /* scalar */ 17924099Sjerry *nelem = 1; 18024099Sjerry return(OK); 18124099Sjerry } 18224099Sjerry 18324099Sjerry if( GETC(ch) != '(' ) 18424099Sjerry { /* entire array */ 18524099Sjerry *nelem = dimptr[1]; 18624099Sjerry UNGETC(); 18724099Sjerry return(OK); 18824099Sjerry } 18924099Sjerry 19024099Sjerry /* get element length, number of dimensions, base, span vector */ 19124099Sjerry ndim = dimptr[0]; 19224099Sjerry if(ndim<=0 || ndim>MAXSUBS) fatal(F_ERSYS,"illegal dimensions"); 19324099Sjerry baseoffset = dimptr[2]; 19424099Sjerry span = dimptr+3; 19524099Sjerry 19624099Sjerry /* get subscripts from input data */ 19724099Sjerry while(ch!=')') { 19824099Sjerry if( ++subcnt > MAXSUBS-1 ) return F_ERNMLIST; 19924099Sjerry if(n=get_int(&subs[subcnt])) return n; 20024099Sjerry GETC(ch); 20124099Sjerry if(leof) return EOF; 20224099Sjerry if(ch != ',' && ch != ')') return F_ERNMLIST; 20324099Sjerry } 20424099Sjerry if( ++subcnt != ndim ) return F_ERNMLIST; 20524099Sjerry 20624099Sjerry offset = subs[ndim-1]; 20724099Sjerry for( i = ndim-2; i>=0; i-- ) 20824099Sjerry offset = subs[i] + span[i]*offset; 20924099Sjerry offset -= baseoffset; 21024099Sjerry *nelem = dimptr[1] - offset; 21124099Sjerry if( offset < 0 || offset >= dimptr[1] ) 21224099Sjerry return F_ERNMLIST; 21324099Sjerry *addr = *addr + (*vlen)*offset; 21424099Sjerry return OK; 21524099Sjerry } 21624099Sjerry 21724099Sjerry LOCAL 21824099Sjerry get_int(subval) 21924099Sjerry int *subval; 22024099Sjerry { 22124099Sjerry int sign=0, value=0, cnt=0; 22224099Sjerry 22324099Sjerry /* look for sign */ 22424099Sjerry if(GETC(ch) == '-') sign = -1; 22524099Sjerry else if(ch == '+') ; 22624099Sjerry else UNGETC(); 22724099Sjerry if(ch == EOF) return(EOF); 22824099Sjerry 22924099Sjerry while(isdigit(GETC(ch))) 23024099Sjerry { 23124099Sjerry value = 10*value + ch-'0'; 23224099Sjerry cnt++; 23324099Sjerry } 23424099Sjerry UNGETC(); 23524099Sjerry if(ch == 'EOF') return EOF; 23624099Sjerry if(cnt == 0 ) return F_ERNMLIST; 23724099Sjerry if(sign== -1) value = -value; 23824099Sjerry *subval = value; 23924099Sjerry return OK; 24024099Sjerry } 24124099Sjerry 24224099Sjerry LOCAL 24324099Sjerry rd_name(ptr) 24424099Sjerry char *ptr; 24524099Sjerry { 24624099Sjerry /* read a variable name from the input stream */ 24724099Sjerry char *init = ptr-1; 24824099Sjerry 249*24258Sjerry if(!isalpha(GETC(ch))) { 25024099Sjerry UNGETC(); 25124099Sjerry return(ERROR); 25224099Sjerry } 25324099Sjerry *ptr++ = ch; 25424099Sjerry while(isalnum(GETC(ch))) 25524099Sjerry { 25624099Sjerry if(ptr-init > VL ) return(ERROR); 25724099Sjerry *ptr++ = ch; 25824099Sjerry } 25924099Sjerry *ptr = '\0'; 26024099Sjerry UNGETC(); 26124099Sjerry return(OK); 26224099Sjerry } 26324099Sjerry 26424099Sjerry LOCAL 26524099Sjerry t_getc() 26624099Sjerry { int ch; 26724099Sjerry static newline = YES; 26824099Sjerry rd: 26924099Sjerry if(curunit->uend) { 27024099Sjerry leof = EOF; 27124099Sjerry return(EOF); 27224099Sjerry } 27324099Sjerry if((ch=getc(cf))!=EOF) 27424099Sjerry { 27524099Sjerry if(ch == '\n') newline = YES; 27624099Sjerry else if(newline==YES) 27724099Sjerry { /* skip first character on each line for namelist */ 27824099Sjerry newline = NO; 27924099Sjerry goto rd; 28024099Sjerry } 28124099Sjerry return(ch); 28224099Sjerry } 28324099Sjerry if(feof(cf)) 28424099Sjerry { curunit->uend = YES; 28524099Sjerry leof = EOF; 28624099Sjerry } 28724099Sjerry else clearerr(cf); 28824099Sjerry return(EOF); 28924099Sjerry } 29024099Sjerry 29124099Sjerry LOCAL 29224099Sjerry l_read(number,ptr,len,type) ftnint number,type; flex *ptr; ftnlen len; 29324099Sjerry { int i,n; 29424099Sjerry double *yy; 29524099Sjerry float *xx; 296*24258Sjerry 297*24258Sjerry lcount = 0; 29824099Sjerry for(i=0;i<number;i++) 29924099Sjerry { 30024099Sjerry if(leof) return EOF; 301*24258Sjerry if(lcount==0) 30224099Sjerry { 303*24258Sjerry ltype = NULL; 304*24258Sjerry if(i!=0) 305*24258Sjerry { /* skip to comma */ 306*24258Sjerry while(isblnk(GETC(ch))); 307*24258Sjerry if(leof) return(EOF); 308*24258Sjerry if(ch == namelistkey_) 309*24258Sjerry { UNGETC(); 310*24258Sjerry return(OK); 311*24258Sjerry } 312*24258Sjerry if(ch != ',' ) return(F_ERNMLIST); 313*24258Sjerry } 31424099Sjerry while(isblnk(GETC(ch))); 315*24258Sjerry if(leof) return(EOF); 31624099Sjerry UNGETC(); 317*24258Sjerry if(i!=0 && ch == namelistkey_) return(OK); 31824099Sjerry 31924099Sjerry switch((int)type) 32024099Sjerry { 32124099Sjerry case TYSHORT: 32224099Sjerry case TYLONG: 323*24258Sjerry if(!isint(ch)) return(OK); 324*24258Sjerry ERRNM(l_R(1)); 325*24258Sjerry break; 32624099Sjerry case TYREAL: 32724099Sjerry case TYDREAL: 328*24258Sjerry if(!isrl(ch)) return(OK); 32924099Sjerry ERRNM(l_R(1)); 33024099Sjerry break; 33124099Sjerry case TYCOMPLEX: 33224099Sjerry case TYDCOMPLEX: 333*24258Sjerry if(!isdigit(ch) && ch!='(') return(OK); 33424099Sjerry ERRNM(l_C()); 33524099Sjerry break; 33624099Sjerry case TYLOGICAL: 337*24258Sjerry if(!islgc(ch)) return(OK); 33824099Sjerry ERRNM(l_L()); 339*24258Sjerry if(nameflag) return(OK); 34024099Sjerry break; 34124099Sjerry case TYCHAR: 342*24258Sjerry if(!isdigit(ch) && !isapos(ch)) return(OK); 34324099Sjerry ERRNM(l_CHAR()); 34424099Sjerry break; 34524099Sjerry } 34624099Sjerry 347*24258Sjerry if(leof) return(EOF); 348*24258Sjerry /* peek at next character - 349*24258Sjerry should be separator or namelistkey_ */ 350*24258Sjerry GETC(ch); UNGETC(); 351*24258Sjerry if(!issep(ch) && (ch != namelistkey_)) 35224099Sjerry return( leof?EOF:F_ERNMLIST ); 353*24258Sjerry } 35424099Sjerry 355*24258Sjerry if(!ltype) return(F_ERNMLIST); 356*24258Sjerry switch((int)type) 35724099Sjerry { 35824099Sjerry case TYSHORT: 35924099Sjerry ptr->flshort=lx; 36024099Sjerry break; 36124099Sjerry case TYLOGICAL: 36224099Sjerry if(len == sizeof(short)) 36324099Sjerry ptr->flshort = lx; 36424099Sjerry else 36524099Sjerry ptr->flint = lx; 36624099Sjerry break; 36724099Sjerry case TYLONG: 36824099Sjerry ptr->flint=lx; 36924099Sjerry break; 37024099Sjerry case TYREAL: 37124099Sjerry ptr->flreal=lx; 37224099Sjerry break; 37324099Sjerry case TYDREAL: 37424099Sjerry ptr->fldouble=lx; 37524099Sjerry break; 37624099Sjerry case TYCOMPLEX: 37724099Sjerry xx=(float *)ptr; 37824099Sjerry *xx++ = ly; 37924099Sjerry *xx = lx; 38024099Sjerry break; 38124099Sjerry case TYDCOMPLEX: 38224099Sjerry yy=(double *)ptr; 38324099Sjerry *yy++ = ly; 38424099Sjerry *yy = lx; 38524099Sjerry break; 38624099Sjerry case TYCHAR: 38724099Sjerry b_char(lchar,(char *)ptr,len); 38824099Sjerry break; 38924099Sjerry } 39024099Sjerry if(lcount>0) lcount--; 39124099Sjerry ptr = (flex *)((char *)ptr + len); 39224099Sjerry } 39324099Sjerry if(lcount>0) return F_ERNMLIST; 39424099Sjerry return(OK); 39524099Sjerry } 39624099Sjerry 39724099Sjerry LOCAL 39824099Sjerry get_repet() 39924099Sjerry { char ch; 40024099Sjerry double lc; 40124099Sjerry if(isdigit(GETC(ch))) 40224099Sjerry { UNGETC(); 40324099Sjerry rd_int(&lc); 40424099Sjerry lcount = (int)lc; 40524099Sjerry if(GETC(ch)!='*') 40624099Sjerry if(leof) return(EOF); 40724099Sjerry else return(F_ERREPT); 40824099Sjerry } 40924099Sjerry else 41024099Sjerry { lcount = 1; 41124099Sjerry UNGETC(); 41224099Sjerry } 41324099Sjerry return(OK); 41424099Sjerry } 41524099Sjerry 41624099Sjerry LOCAL 41724099Sjerry l_R(flg) int flg; 41824099Sjerry { double a,b,c,d; 41924099Sjerry int da,db,dc,dd; 42024099Sjerry int i,ch,sign=0; 42124099Sjerry a=b=c=d=0; 42224099Sjerry da=db=dc=dd=0; 42324099Sjerry 42424099Sjerry if( flg ) /* real */ 42524099Sjerry { 42624099Sjerry da=rd_int(&a); /* repeat count ? */ 42724099Sjerry if(GETC(ch)=='*') 42824099Sjerry { 42924099Sjerry if (a <= 0.) return(F_ERNREP); 43024099Sjerry lcount=(int)a; 43124099Sjerry db=rd_int(&b); /* whole part of number */ 43224099Sjerry } 43324099Sjerry else 43424099Sjerry { UNGETC(); 43524099Sjerry db=da; 43624099Sjerry b=a; 43724099Sjerry lcount=1; 43824099Sjerry } 43924099Sjerry } 44024099Sjerry else /* complex */ 44124099Sjerry { 44224099Sjerry db=rd_int(&b); 44324099Sjerry } 44424099Sjerry 44524099Sjerry if(GETC(ch)=='.' && isdigit(GETC(ch))) 44624099Sjerry { UNGETC(); 44724099Sjerry dc=rd_int(&c); /* fractional part of number */ 44824099Sjerry } 44924099Sjerry else 45024099Sjerry { UNGETC(); 45124099Sjerry dc=0; 45224099Sjerry c=0.; 45324099Sjerry } 45424099Sjerry if(isexp(GETC(ch))) 45524099Sjerry dd=rd_int(&d); /* exponent */ 45624099Sjerry else if (ch == '+' || ch == '-') 45724099Sjerry { UNGETC(); 45824099Sjerry dd=rd_int(&d); 45924099Sjerry } 46024099Sjerry else 46124099Sjerry { UNGETC(); 46224099Sjerry dd=0; 46324099Sjerry } 46424099Sjerry if(db<0 || b<0) 46524099Sjerry { sign=1; 46624099Sjerry b = -b; 46724099Sjerry } 46824099Sjerry for(i=0;i<dc;i++) c/=10.; 46924099Sjerry b=b+c; 47024099Sjerry if (dd > 0) 47124099Sjerry { for(i=0;i<d;i++) b *= 10.; 47224099Sjerry for(i=0;i< -d;i++) b /= 10.; 47324099Sjerry } 47424099Sjerry lx=sign?-b:b; 47524099Sjerry ltype=TYLONG; 47624099Sjerry return(OK); 47724099Sjerry } 47824099Sjerry 47924099Sjerry LOCAL 48024099Sjerry rd_int(x) double *x; 48124099Sjerry { int ch,sign=0,i=0; 48224099Sjerry double y=0.0; 48324099Sjerry if(GETC(ch)=='-') sign = -1; 48424099Sjerry else if(ch=='+') sign=0; 48524099Sjerry else UNGETC(); 48624099Sjerry while(isdigit(GETC(ch))) 48724099Sjerry { i++; 48824099Sjerry y=10*y + ch-'0'; 48924099Sjerry } 49024099Sjerry UNGETC(); 49124099Sjerry if(sign) y = -y; 49224099Sjerry *x = y; 49324099Sjerry return(y==0.0?sign:i); /* 0:[+]&&y==0, -1:-&&y==0, >0:#digits&&y!=0 */ 49424099Sjerry } 49524099Sjerry 49624099Sjerry LOCAL 49724099Sjerry l_C() 49824099Sjerry { int ch,n; 49924099Sjerry if(n=get_repet()) return(n); /* get repeat count */ 50024099Sjerry if(GETC(ch)!='(') err(errflag,F_ERNMLIST,"no (") 50124099Sjerry while(isblnk(GETC(ch))); 50224099Sjerry UNGETC(); 50324099Sjerry l_R(0); /* get real part */ 50424099Sjerry ly = lx; 505*24258Sjerry while(isblnk(GETC(ch))); /* get comma */ 506*24258Sjerry if(leof) return(EOF); 507*24258Sjerry if(ch!=',') return(F_ERNMLIST); 508*24258Sjerry while(isblnk(GETC(ch))); 509*24258Sjerry UNGETC(); 510*24258Sjerry if(leof) return(EOF); 51124099Sjerry l_R(0); /* get imag part */ 51224099Sjerry while(isblnk(GETC(ch))); 51324099Sjerry if(ch!=')') err(errflag,F_ERNMLIST,"no )") 51424099Sjerry ltype = TYCOMPLEX; 51524099Sjerry return(OK); 51624099Sjerry } 51724099Sjerry 51824099Sjerry LOCAL 51924099Sjerry l_L() 52024099Sjerry { 521*24258Sjerry int n; 522*24258Sjerry if(!isdigit(ch) && ch != '.') 523*24258Sjerry { 524*24258Sjerry if(rd_name(var_name)) 525*24258Sjerry return(leof?EOF:F_ERNMLIST); 526*24258Sjerry while(isblnk(GETC(ch))); 527*24258Sjerry if(ch == '=' || ch == '(') 528*24258Sjerry { /* found a name, not a value */ 529*24258Sjerry UNGETC(); 530*24258Sjerry nameflag = YES; 531*24258Sjerry return(OK); 532*24258Sjerry } 533*24258Sjerry } 534*24258Sjerry else 535*24258Sjerry { 536*24258Sjerry if(n=get_repet()) return(n); /* get repeat count */ 537*24258Sjerry if(GETC(ch)=='.') GETC(ch); 538*24258Sjerry } 53924099Sjerry switch(ch) 54024099Sjerry { 54124099Sjerry case 't': 54224099Sjerry case 'T': 54324099Sjerry lx=1; 54424099Sjerry break; 54524099Sjerry case 'f': 54624099Sjerry case 'F': 54724099Sjerry lx=0; 54824099Sjerry break; 54924099Sjerry default: 550*24258Sjerry if(ch==EOF) return(EOF); 55124099Sjerry else err(errflag,F_ERNMLIST,"logical not T or F"); 55224099Sjerry } 55324099Sjerry ltype=TYLOGICAL; 55424099Sjerry while(!issep(GETC(ch)) && ch!=EOF) ; 55524099Sjerry UNGETC(); 55624099Sjerry if(ch == EOF ) return(EOF); 55724099Sjerry return(OK); 55824099Sjerry } 55924099Sjerry 56024099Sjerry #define BUFSIZE 128 56124099Sjerry LOCAL 56224099Sjerry l_CHAR() 56324099Sjerry { int ch,size,i,n; 56424099Sjerry char quote,*p; 56524099Sjerry if(n=get_repet()) return(n); /* get repeat count */ 56624099Sjerry if(isapos(GETC(ch))) quote=ch; 56724099Sjerry else if(ch == EOF) return EOF; 56824099Sjerry else return F_ERNMLIST; 56924099Sjerry ltype=TYCHAR; 57024099Sjerry if(lchar!=NULL) free(lchar); 57124099Sjerry size=BUFSIZE-1; 57224099Sjerry p=lchar=(char *)malloc(BUFSIZE); 57324099Sjerry if(lchar==NULL) return (F_ERSPACE); 57424099Sjerry for(i=0;;) 57524099Sjerry { while( GETC(ch)!=quote && ch!='\n' && ch!=EOF && ++i<size ) 57624099Sjerry *p++ = ch; 57724099Sjerry if(i==size) 57824099Sjerry { 57924099Sjerry newone: 58024099Sjerry size += BUFSIZE; 58124099Sjerry lchar=(char *)realloc(lchar, size+1); 58224099Sjerry if(lchar==NULL) return( F_ERSPACE ); 58324099Sjerry p=lchar+i-1; 58424099Sjerry *p++ = ch; 58524099Sjerry } 58624099Sjerry else if(ch==EOF) return(EOF); 58724099Sjerry else if(ch=='\n') 58824099Sjerry { if(*(p-1) == '\\') *(p-1) = ch; 58924099Sjerry } 59024099Sjerry else if(GETC(ch)==quote) 59124099Sjerry { if(++i<size) *p++ = ch; 59224099Sjerry else goto newone; 59324099Sjerry } 59424099Sjerry else 59524099Sjerry { UNGETC(); 59624099Sjerry *p = '\0'; 59724099Sjerry return(OK); 59824099Sjerry } 59924099Sjerry } 60024099Sjerry } 601