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*24468Sjerry * @(#)rsnmle.c 5.3 08/28/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 18*24468Sjerry LOCAL char *nml_rd; 1924099Sjerry 2024099Sjerry static int ch; 2124258Sjerry LOCAL nameflag; 2224258Sjerry LOCAL char var_name[VL+1]; 2324099Sjerry 2424099Sjerry #define SP 1 2524099Sjerry #define B 2 2624099Sjerry #define AP 4 2724099Sjerry #define EX 8 2824258Sjerry #define INTG 16 2924258Sjerry #define RL 32 3024258Sjerry #define LGC 64 3124258Sjerry #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 */ 3624258Sjerry #define isint(x) (ltab[x+1]&INTG) /* 0-9, plus, minus */ 3724258Sjerry #define isrl(x) (ltab[x+1]&RL) /* 0-9, plus, minus, period */ 3824258Sjerry #define islgc(x) (ltab[x+1]&LGC) /* 0-9, period, t, f, T, F */ 3924099Sjerry 40*24468Sjerry #define GETC (ch=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 */ 5024258Sjerry /* 0- 15 */ 0,0,0,0,0,0,0,0,0,SP|B,SP|B,0,0,0,0,0, /* TAB,NEWLINE */ 5124258Sjerry /* 16- 31 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 5224258Sjerry /* 32- 47 */ SP|B,0,AP,0,0,0,0,AP,0,0,0,RL|INTG,SP,RL|INTG,RL|LGC,0, /* space,",',comma,., */ 5324258Sjerry /* 48- 63 */ IRL,IRL,IRL,IRL,IRL,IRL,IRL,IRL,IRL,IRL,0,0,0,0,0,0, /* digits */ 5424258Sjerry /* 64- 79 */ 0,0,0,0,EX,EX,LGC,0,0,0,0,0,0,0,0,0, /* D,E,F */ 5524258Sjerry /* 80- 95 */ 0,0,0,0,LGC,0,0,0,0,0,0,0,0,0,0,0, /* T */ 5624258Sjerry /* 96-111 */ 0,0,0,0,EX,EX,LGC,0,0,0,0,0,0,0,0,0, /* d,e,f */ 5724258Sjerry /* 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 { 62*24468Sjerry int n; 6324099Sjerry struct namelistentry *entry; 6424099Sjerry int nelem, vlen, vtype; 6524099Sjerry char *nmlist_nm, *addr; 6624099Sjerry 67*24468Sjerry nml_rd = "namelist read"; 6824099Sjerry reading = YES; 6924099Sjerry formatted = NAMELIST; 7024099Sjerry fmtbuf = "ext namelist io"; 7124099Sjerry if(n=c_le(a,READ)) return(n); 7224099Sjerry getn = t_getc; 7324099Sjerry ungetn = ungetc; 7424099Sjerry leof = curunit->uend; 7524099Sjerry if(curunit->uwrt && ! nowreading(curunit)) err(errflag, errno, nml_rd) 7624099Sjerry 7724099Sjerry /* look for " &namelistname " */ 7824099Sjerry nmlist_nm = a->namelist->namelistname; 79*24468Sjerry while(isblnk(GETC)) ; 8024099Sjerry /* check for "&end" (like IBM) or "$end" (like DEC) */ 8124099Sjerry if(ch != '&' && ch != '$') goto rderr; 8224099Sjerry /* save it - write out using the same character as used on input */ 8324099Sjerry namelistkey_ = ch; 8424099Sjerry while( *nmlist_nm ) 85*24468Sjerry if( GETC != *nmlist_nm++ ) 86*24468Sjerry { 87*24468Sjerry nml_rd = "incorrect namelist name"; 88*24468Sjerry goto rderr; 89*24468Sjerry } 90*24468Sjerry if(!isblnk(GETC)) goto rderr; 91*24468Sjerry while(isblnk(GETC)) ; 9224099Sjerry if(leof) goto rderr; 9324099Sjerry UNGETC(); 9424099Sjerry 95*24468Sjerry while( GETC != namelistkey_ ) 9624099Sjerry { 9724258Sjerry UNGETC(); 9824099Sjerry /* get variable name */ 9924258Sjerry if(!nameflag && rd_name(var_name)) goto rderr; 10024258Sjerry 10124099Sjerry entry = a->namelist->names; 10224099Sjerry /* loop through namelist entries looking for this variable name */ 10324099Sjerry while( entry->varname[0] != 0 ) 10424099Sjerry { 10524099Sjerry if( strcmp(entry->varname, var_name) == 0 ) goto got_name; 10624099Sjerry entry++; 10724099Sjerry } 108*24468Sjerry nml_rd = "incorrect variable name"; 10924099Sjerry goto rderr; 11024099Sjerry got_name: 11124258Sjerry if( n = get_pars( entry, &addr, &nelem, &vlen, &vtype )) 11224099Sjerry goto rderr_n; 113*24468Sjerry while(isblnk(GETC)) ; 11424099Sjerry if(ch != '=') goto rderr; 11524258Sjerry 11624258Sjerry nameflag = NO; 117*24468Sjerry if(n = l_read( nelem, addr, vlen, vtype )) goto rderr_n; 118*24468Sjerry while(isblnk(GETC)); 119*24468Sjerry if(ch == ',') while(isblnk(GETC)); 12024099Sjerry UNGETC(); 12124099Sjerry if(leof) goto rderr; 12224099Sjerry } 12324099Sjerry /* check for 'end' after '&' or '$'*/ 124*24468Sjerry if(GETC!='e' || GETC!='n' || GETC!='d' ) 12524099Sjerry goto rderr; 12624099Sjerry /* flush to next input record */ 12724099Sjerry flush: 128*24468Sjerry while(GETC != '\n' && ch != EOF); 12924099Sjerry return(ch == EOF ? EOF : OK); 13024099Sjerry 13124099Sjerry rderr: 13224099Sjerry if(leof) 133*24468Sjerry n = EOF; 13424099Sjerry else 135*24468Sjerry n = F_ERNMLIST; 136*24468Sjerry rderr_n: 137*24468Sjerry if(n == EOF ) err(endflag,EOF,nml_rd); 138*24468Sjerry /* flush after error in case restart I/O */ 139*24468Sjerry if(ch != '\n') while(GETC != '\n' && ch != EOF) ; 140*24468Sjerry err(errflag,n,nml_rd) 14124099Sjerry } 14224099Sjerry 14324099Sjerry #define MAXSUBS 7 14424099Sjerry 14524099Sjerry LOCAL 14624099Sjerry get_pars( entry, addr, nelem, vlen, vtype ) 14724099Sjerry struct namelistentry *entry; 14824099Sjerry char **addr; /* beginning address to read into */ 14924099Sjerry int *nelem, /* number of elements to read */ 15024099Sjerry *vlen, /* length of elements */ 15124099Sjerry *vtype; /* type of elements */ 15224099Sjerry { 15324099Sjerry int offset, i, n, 15424099Sjerry *dimptr, /* points to dimensioning info */ 15524099Sjerry ndim, /* number of dimensions */ 15624099Sjerry baseoffset, /* offset of corner element */ 15724099Sjerry *span, /* subscript span for each dimension */ 15824099Sjerry subs[MAXSUBS], /* actual subscripts */ 15924099Sjerry subcnt = -1; /* number of actual subscripts */ 16024099Sjerry 16124099Sjerry 16224099Sjerry /* get element size and base address */ 16324099Sjerry *vlen = entry->typelen; 16424099Sjerry *addr = entry->varaddr; 16524099Sjerry 16624099Sjerry /* get type */ 16724099Sjerry switch ( *vtype = entry->type ) { 16824099Sjerry case TYSHORT: 16924099Sjerry case TYLONG: 17024099Sjerry case TYREAL: 17124099Sjerry case TYDREAL: 17224099Sjerry case TYCOMPLEX: 17324099Sjerry case TYDCOMPLEX: 17424099Sjerry case TYLOGICAL: 17524099Sjerry case TYCHAR: 17624099Sjerry break; 17724099Sjerry default: 17824258Sjerry fatal(F_ERSYS,"unknown type in rsnmle"); 17924099Sjerry } 18024099Sjerry 18124099Sjerry /* get number of elements */ 18224099Sjerry dimptr = entry->dimp; 18324099Sjerry if( dimptr==NULL ) 18424099Sjerry { /* scalar */ 18524099Sjerry *nelem = 1; 18624099Sjerry return(OK); 18724099Sjerry } 18824099Sjerry 189*24468Sjerry if( GETC != '(' ) 19024099Sjerry { /* entire array */ 19124099Sjerry *nelem = dimptr[1]; 19224099Sjerry UNGETC(); 19324099Sjerry return(OK); 19424099Sjerry } 19524099Sjerry 19624099Sjerry /* get element length, number of dimensions, base, span vector */ 19724099Sjerry ndim = dimptr[0]; 19824099Sjerry if(ndim<=0 || ndim>MAXSUBS) fatal(F_ERSYS,"illegal dimensions"); 19924099Sjerry baseoffset = dimptr[2]; 20024099Sjerry span = dimptr+3; 20124099Sjerry 20224099Sjerry /* get subscripts from input data */ 20324099Sjerry while(ch!=')') { 20424099Sjerry if( ++subcnt > MAXSUBS-1 ) return F_ERNMLIST; 20524099Sjerry if(n=get_int(&subs[subcnt])) return n; 206*24468Sjerry GETC; 20724099Sjerry if(leof) return EOF; 20824099Sjerry if(ch != ',' && ch != ')') return F_ERNMLIST; 20924099Sjerry } 21024099Sjerry if( ++subcnt != ndim ) return F_ERNMLIST; 21124099Sjerry 21224099Sjerry offset = subs[ndim-1]; 21324099Sjerry for( i = ndim-2; i>=0; i-- ) 21424099Sjerry offset = subs[i] + span[i]*offset; 21524099Sjerry offset -= baseoffset; 21624099Sjerry *nelem = dimptr[1] - offset; 21724099Sjerry if( offset < 0 || offset >= dimptr[1] ) 21824099Sjerry return F_ERNMLIST; 21924099Sjerry *addr = *addr + (*vlen)*offset; 22024099Sjerry return OK; 22124099Sjerry } 22224099Sjerry 22324099Sjerry LOCAL 22424099Sjerry get_int(subval) 22524099Sjerry int *subval; 22624099Sjerry { 22724099Sjerry int sign=0, value=0, cnt=0; 22824099Sjerry 22924099Sjerry /* look for sign */ 230*24468Sjerry if(GETC == '-') sign = -1; 23124099Sjerry else if(ch == '+') ; 23224099Sjerry else UNGETC(); 23324099Sjerry if(ch == EOF) return(EOF); 23424099Sjerry 235*24468Sjerry while(isdigit(GETC)) 23624099Sjerry { 23724099Sjerry value = 10*value + ch-'0'; 23824099Sjerry cnt++; 23924099Sjerry } 24024099Sjerry UNGETC(); 24124099Sjerry if(ch == 'EOF') return EOF; 24224099Sjerry if(cnt == 0 ) return F_ERNMLIST; 24324099Sjerry if(sign== -1) value = -value; 24424099Sjerry *subval = value; 24524099Sjerry return OK; 24624099Sjerry } 24724099Sjerry 24824099Sjerry LOCAL 24924099Sjerry rd_name(ptr) 25024099Sjerry char *ptr; 25124099Sjerry { 25224099Sjerry /* read a variable name from the input stream */ 25324099Sjerry char *init = ptr-1; 25424099Sjerry 255*24468Sjerry if(!isalpha(GETC)) { 25624099Sjerry UNGETC(); 25724099Sjerry return(ERROR); 25824099Sjerry } 25924099Sjerry *ptr++ = ch; 260*24468Sjerry while(isalnum(GETC)) 26124099Sjerry { 26224099Sjerry if(ptr-init > VL ) return(ERROR); 26324099Sjerry *ptr++ = ch; 26424099Sjerry } 26524099Sjerry *ptr = '\0'; 26624099Sjerry UNGETC(); 26724099Sjerry return(OK); 26824099Sjerry } 26924099Sjerry 27024099Sjerry LOCAL 27124099Sjerry t_getc() 27224099Sjerry { int ch; 27324099Sjerry static newline = YES; 27424099Sjerry rd: 27524099Sjerry if(curunit->uend) { 27624099Sjerry leof = EOF; 27724099Sjerry return(EOF); 27824099Sjerry } 27924099Sjerry if((ch=getc(cf))!=EOF) 28024099Sjerry { 28124099Sjerry if(ch == '\n') newline = YES; 28224099Sjerry else if(newline==YES) 28324099Sjerry { /* skip first character on each line for namelist */ 28424099Sjerry newline = NO; 28524099Sjerry goto rd; 28624099Sjerry } 28724099Sjerry return(ch); 28824099Sjerry } 28924099Sjerry if(feof(cf)) 29024099Sjerry { curunit->uend = YES; 29124099Sjerry leof = EOF; 29224099Sjerry } 29324099Sjerry else clearerr(cf); 29424099Sjerry return(EOF); 29524099Sjerry } 29624099Sjerry 29724099Sjerry LOCAL 29824099Sjerry l_read(number,ptr,len,type) ftnint number,type; flex *ptr; ftnlen len; 29924099Sjerry { int i,n; 30024099Sjerry double *yy; 30124099Sjerry float *xx; 30224258Sjerry 30324258Sjerry lcount = 0; 30424099Sjerry for(i=0;i<number;i++) 30524099Sjerry { 30624099Sjerry if(leof) return EOF; 30724258Sjerry if(lcount==0) 30824099Sjerry { 30924258Sjerry ltype = NULL; 31024258Sjerry if(i!=0) 31124258Sjerry { /* skip to comma */ 312*24468Sjerry while(isblnk(GETC)); 31324258Sjerry if(leof) return(EOF); 31424258Sjerry if(ch == namelistkey_) 31524258Sjerry { UNGETC(); 31624258Sjerry return(OK); 31724258Sjerry } 31824258Sjerry if(ch != ',' ) return(F_ERNMLIST); 31924258Sjerry } 320*24468Sjerry while(isblnk(GETC)); 32124258Sjerry if(leof) return(EOF); 32224099Sjerry UNGETC(); 32324258Sjerry if(i!=0 && ch == namelistkey_) return(OK); 32424099Sjerry 32524099Sjerry switch((int)type) 32624099Sjerry { 32724099Sjerry case TYSHORT: 32824099Sjerry case TYLONG: 32924258Sjerry if(!isint(ch)) return(OK); 33024258Sjerry ERRNM(l_R(1)); 33124258Sjerry break; 33224099Sjerry case TYREAL: 33324099Sjerry case TYDREAL: 33424258Sjerry if(!isrl(ch)) return(OK); 33524099Sjerry ERRNM(l_R(1)); 33624099Sjerry break; 33724099Sjerry case TYCOMPLEX: 33824099Sjerry case TYDCOMPLEX: 33924258Sjerry if(!isdigit(ch) && ch!='(') return(OK); 34024099Sjerry ERRNM(l_C()); 34124099Sjerry break; 34224099Sjerry case TYLOGICAL: 34324258Sjerry if(!islgc(ch)) return(OK); 34424099Sjerry ERRNM(l_L()); 34524258Sjerry if(nameflag) return(OK); 34624099Sjerry break; 34724099Sjerry case TYCHAR: 34824258Sjerry if(!isdigit(ch) && !isapos(ch)) return(OK); 34924099Sjerry ERRNM(l_CHAR()); 35024099Sjerry break; 35124099Sjerry } 35224099Sjerry 35324258Sjerry if(leof) return(EOF); 35424258Sjerry /* peek at next character - 35524258Sjerry should be separator or namelistkey_ */ 356*24468Sjerry GETC; UNGETC(); 35724258Sjerry if(!issep(ch) && (ch != namelistkey_)) 35824099Sjerry return( leof?EOF:F_ERNMLIST ); 35924258Sjerry } 36024099Sjerry 36124258Sjerry if(!ltype) return(F_ERNMLIST); 36224258Sjerry switch((int)type) 36324099Sjerry { 36424099Sjerry case TYSHORT: 36524099Sjerry ptr->flshort=lx; 36624099Sjerry break; 36724099Sjerry case TYLOGICAL: 36824099Sjerry if(len == sizeof(short)) 36924099Sjerry ptr->flshort = lx; 37024099Sjerry else 37124099Sjerry ptr->flint = lx; 37224099Sjerry break; 37324099Sjerry case TYLONG: 37424099Sjerry ptr->flint=lx; 37524099Sjerry break; 37624099Sjerry case TYREAL: 37724099Sjerry ptr->flreal=lx; 37824099Sjerry break; 37924099Sjerry case TYDREAL: 38024099Sjerry ptr->fldouble=lx; 38124099Sjerry break; 38224099Sjerry case TYCOMPLEX: 38324099Sjerry xx=(float *)ptr; 38424099Sjerry *xx++ = ly; 38524099Sjerry *xx = lx; 38624099Sjerry break; 38724099Sjerry case TYDCOMPLEX: 38824099Sjerry yy=(double *)ptr; 38924099Sjerry *yy++ = ly; 39024099Sjerry *yy = lx; 39124099Sjerry break; 39224099Sjerry case TYCHAR: 39324099Sjerry b_char(lchar,(char *)ptr,len); 39424099Sjerry break; 39524099Sjerry } 39624099Sjerry if(lcount>0) lcount--; 39724099Sjerry ptr = (flex *)((char *)ptr + len); 39824099Sjerry } 39924099Sjerry if(lcount>0) return F_ERNMLIST; 40024099Sjerry return(OK); 40124099Sjerry } 40224099Sjerry 40324099Sjerry LOCAL 40424099Sjerry get_repet() 405*24468Sjerry { 40624099Sjerry double lc; 407*24468Sjerry if(isdigit(GETC)) 40824099Sjerry { UNGETC(); 40924099Sjerry rd_int(&lc); 41024099Sjerry lcount = (int)lc; 411*24468Sjerry if(GETC!='*') 41224099Sjerry if(leof) return(EOF); 41324099Sjerry else return(F_ERREPT); 41424099Sjerry } 41524099Sjerry else 41624099Sjerry { lcount = 1; 41724099Sjerry UNGETC(); 41824099Sjerry } 41924099Sjerry return(OK); 42024099Sjerry } 42124099Sjerry 42224099Sjerry LOCAL 42324099Sjerry l_R(flg) int flg; 42424099Sjerry { double a,b,c,d; 42524099Sjerry int da,db,dc,dd; 426*24468Sjerry int i,sign=0; 42724099Sjerry a=b=c=d=0; 42824099Sjerry da=db=dc=dd=0; 42924099Sjerry 43024099Sjerry if( flg ) /* real */ 43124099Sjerry { 43224099Sjerry da=rd_int(&a); /* repeat count ? */ 433*24468Sjerry if(GETC=='*') 43424099Sjerry { 43524099Sjerry if (a <= 0.) return(F_ERNREP); 43624099Sjerry lcount=(int)a; 43724099Sjerry db=rd_int(&b); /* whole part of number */ 43824099Sjerry } 43924099Sjerry else 44024099Sjerry { UNGETC(); 44124099Sjerry db=da; 44224099Sjerry b=a; 44324099Sjerry lcount=1; 44424099Sjerry } 44524099Sjerry } 44624099Sjerry else /* complex */ 44724099Sjerry { 44824099Sjerry db=rd_int(&b); 44924099Sjerry } 45024099Sjerry 451*24468Sjerry if(GETC=='.' && isdigit(GETC)) 45224099Sjerry { UNGETC(); 45324099Sjerry dc=rd_int(&c); /* fractional part of number */ 45424099Sjerry } 45524099Sjerry else 45624099Sjerry { UNGETC(); 45724099Sjerry dc=0; 45824099Sjerry c=0.; 45924099Sjerry } 460*24468Sjerry if(isexp(GETC)) 46124099Sjerry dd=rd_int(&d); /* exponent */ 46224099Sjerry else if (ch == '+' || ch == '-') 46324099Sjerry { UNGETC(); 46424099Sjerry dd=rd_int(&d); 46524099Sjerry } 46624099Sjerry else 46724099Sjerry { UNGETC(); 46824099Sjerry dd=0; 46924099Sjerry } 47024099Sjerry if(db<0 || b<0) 47124099Sjerry { sign=1; 47224099Sjerry b = -b; 47324099Sjerry } 47424099Sjerry for(i=0;i<dc;i++) c/=10.; 47524099Sjerry b=b+c; 47624099Sjerry if (dd > 0) 47724099Sjerry { for(i=0;i<d;i++) b *= 10.; 47824099Sjerry for(i=0;i< -d;i++) b /= 10.; 47924099Sjerry } 48024099Sjerry lx=sign?-b:b; 48124099Sjerry ltype=TYLONG; 48224099Sjerry return(OK); 48324099Sjerry } 48424099Sjerry 48524099Sjerry LOCAL 48624099Sjerry rd_int(x) double *x; 487*24468Sjerry { int sign=0,i=0; 48824099Sjerry double y=0.0; 489*24468Sjerry if(GETC=='-') sign = -1; 49024099Sjerry else if(ch=='+') sign=0; 49124099Sjerry else UNGETC(); 492*24468Sjerry while(isdigit(GETC)) 49324099Sjerry { i++; 49424099Sjerry y=10*y + ch-'0'; 49524099Sjerry } 49624099Sjerry UNGETC(); 49724099Sjerry if(sign) y = -y; 49824099Sjerry *x = y; 49924099Sjerry return(y==0.0?sign:i); /* 0:[+]&&y==0, -1:-&&y==0, >0:#digits&&y!=0 */ 50024099Sjerry } 50124099Sjerry 50224099Sjerry LOCAL 50324099Sjerry l_C() 504*24468Sjerry { int n; 50524099Sjerry if(n=get_repet()) return(n); /* get repeat count */ 506*24468Sjerry if(GETC!='(') err(errflag,F_ERNMLIST,"no (") 507*24468Sjerry while(isblnk(GETC)); 50824099Sjerry UNGETC(); 50924099Sjerry l_R(0); /* get real part */ 51024099Sjerry ly = lx; 511*24468Sjerry while(isblnk(GETC)); /* get comma */ 51224258Sjerry if(leof) return(EOF); 51324258Sjerry if(ch!=',') return(F_ERNMLIST); 514*24468Sjerry while(isblnk(GETC)); 51524258Sjerry UNGETC(); 51624258Sjerry if(leof) return(EOF); 51724099Sjerry l_R(0); /* get imag part */ 518*24468Sjerry while(isblnk(GETC)); 51924099Sjerry if(ch!=')') err(errflag,F_ERNMLIST,"no )") 52024099Sjerry ltype = TYCOMPLEX; 52124099Sjerry return(OK); 52224099Sjerry } 52324099Sjerry 52424099Sjerry LOCAL 52524099Sjerry l_L() 52624099Sjerry { 527*24468Sjerry int n, keychar=ch, scanned=NO; 528*24468Sjerry if(ch=='f' || ch=='F' || ch=='t' || ch=='T') 52924258Sjerry { 530*24468Sjerry scanned=YES; 53124258Sjerry if(rd_name(var_name)) 53224258Sjerry return(leof?EOF:F_ERNMLIST); 533*24468Sjerry while(isblnk(GETC)); 534*24468Sjerry UNGETC(); 53524258Sjerry if(ch == '=' || ch == '(') 53624258Sjerry { /* found a name, not a value */ 53724258Sjerry nameflag = YES; 53824258Sjerry return(OK); 53924258Sjerry } 54024258Sjerry } 54124258Sjerry else 54224258Sjerry { 54324258Sjerry if(n=get_repet()) return(n); /* get repeat count */ 544*24468Sjerry if(GETC=='.') GETC; 545*24468Sjerry keychar = ch; 54624258Sjerry } 547*24468Sjerry switch(keychar) 54824099Sjerry { 54924099Sjerry case 't': 55024099Sjerry case 'T': 55124099Sjerry lx=1; 55224099Sjerry break; 55324099Sjerry case 'f': 55424099Sjerry case 'F': 55524099Sjerry lx=0; 55624099Sjerry break; 55724099Sjerry default: 55824258Sjerry if(ch==EOF) return(EOF); 55924099Sjerry else err(errflag,F_ERNMLIST,"logical not T or F"); 56024099Sjerry } 56124099Sjerry ltype=TYLOGICAL; 562*24468Sjerry if(scanned==NO) 563*24468Sjerry { 564*24468Sjerry while(!issep(GETC) && ch!=EOF) ; 565*24468Sjerry UNGETC(); 566*24468Sjerry } 56724099Sjerry if(ch == EOF ) return(EOF); 56824099Sjerry return(OK); 56924099Sjerry } 57024099Sjerry 57124099Sjerry #define BUFSIZE 128 57224099Sjerry LOCAL 57324099Sjerry l_CHAR() 574*24468Sjerry { int size,i,n; 57524099Sjerry char quote,*p; 57624099Sjerry if(n=get_repet()) return(n); /* get repeat count */ 577*24468Sjerry if(isapos(GETC)) quote=ch; 57824099Sjerry else if(ch == EOF) return EOF; 57924099Sjerry else return F_ERNMLIST; 58024099Sjerry ltype=TYCHAR; 58124099Sjerry if(lchar!=NULL) free(lchar); 58224099Sjerry size=BUFSIZE-1; 58324099Sjerry p=lchar=(char *)malloc(BUFSIZE); 58424099Sjerry if(lchar==NULL) return (F_ERSPACE); 58524099Sjerry for(i=0;;) 586*24468Sjerry { while( GETC!=quote && ch!='\n' && ch!=EOF && ++i<size ) 58724099Sjerry *p++ = ch; 58824099Sjerry if(i==size) 58924099Sjerry { 59024099Sjerry newone: 59124099Sjerry size += BUFSIZE; 59224099Sjerry lchar=(char *)realloc(lchar, size+1); 59324099Sjerry if(lchar==NULL) return( F_ERSPACE ); 59424099Sjerry p=lchar+i-1; 59524099Sjerry *p++ = ch; 59624099Sjerry } 59724099Sjerry else if(ch==EOF) return(EOF); 59824099Sjerry else if(ch=='\n') 59924099Sjerry { if(*(p-1) == '\\') *(p-1) = ch; 60024099Sjerry } 601*24468Sjerry else if(GETC==quote) 60224099Sjerry { if(++i<size) *p++ = ch; 60324099Sjerry else goto newone; 60424099Sjerry } 60524099Sjerry else 60624099Sjerry { UNGETC(); 60724099Sjerry *p = '\0'; 60824099Sjerry return(OK); 60924099Sjerry } 61024099Sjerry } 61124099Sjerry } 612