/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1982-2011 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Shell arithmetic - uses streval library
* David Korn
* AT&T Labs
*/
#include "defs.h"
#include "lexstates.h"
#include "name.h"
#include "streval.h"
#include "variables.h"
#ifndef LLONG_MAX
#endif
{
{ 0 },
"Inf",
};
{
{ 0 },
"NaN",
};
{
{ 0 },
"?",
};
{
{
int offset;
/* do binding to node now */
if((!(np = nv_open(cp,shp->var_tree,assign|NV_VARNAME|NV_NOADD|NV_NOFAIL)) || nv_isnull(np)) && sh_macfun(shp,cp, offset = staktell()))
{
return(&FunNode);
}
if(!np)
return(0);
flag++;
else
flag = 0;
}
if((lvalue->emode&ARITH_COMP) && dtvnext(root) && ((sdict && (mp=nv_search(cp,sdict,flags&~NV_ADD))) || (mp=nv_search(cp,root,flags&~(NV_ADD|HASH_NOSCOPE)))))
{
#if SHOPT_FIXEDARRAY
int n,dim;
n = nv_refindex(np);
#endif /* SHOPT_FIXEDARRAY */
#if SHOPT_FIXEDARRAY
if(n)
{
}
else
#endif /* SHOPT_FIXEDARRAY */
if(sub)
}
{
if(sub)
{
goto skip;
}
while(1)
{
if(c || *cp=='.')
{
c = '.';
while(*cp=='.')
{
cp++;
}
if(c=='[')
continue;
}
*cp = 0;
if(c)
{
}
if(c)
{
return(np);
}
#if SHOPT_FIXEDARRAY
#else
#endif /* SHOPT_FIXEDARRAY */
if(*cp!='[')
break;
skip:
else
{
}
}
}
else if(nosub>0)
return(np);
}
{
register Sfdouble_t r= 0;
register char *cp;
switch(type)
{
case ASSIGN:
{
break;
}
case LOOKUP:
{
register int c = *str;
if(c=='.')
str++;
if(isaletter(c))
{
int dot=0;
while(1)
{
{
c = *str;
}
if(c!='.')
break;
if((c = *++str) !='[')
continue;
str -=2;
}
if(c=='(')
{
c = **ptr;
{
break;
}
{
break;
{
break;
}
}
break;
else
return(r);
}
{
break;
}
*str = 0;
if(sh_isoption(SH_NOEXEC))
else
{
*str = c;
while(c=='[' || c=='.')
{
if(c=='[')
{
{
c = '[';
break;
}
}
else
{
str++;
}
}
*str = 0;
if ((cp[0] == 'i' || cp[0] == 'I') && (cp[1] == 'n' || cp[1] == 'N') && (cp[2] == 'f' || cp[2] == 'F') && cp[3] == 0)
{
}
else if ((cp[0] == 'n' || cp[0] == 'N') && (cp[1] == 'a' || cp[1] == 'A') && (cp[2] == 'n' || cp[2] == 'N') && cp[3] == 0)
{
}
{
}
else
}
*str = c;
break;
/* bind subscript later */
if(c=='[')
{
do
{
while(c=='.')
{
str++;
}
if(c=='[')
}
break;
}
}
else
{
errno = 0;
{
lastbase=10;
errno = 0;
}
if(lastbase<=1)
lastbase=10;
if(*val=='0')
{
while(*val=='0')
val++;
val--;
}
c='e';
else
c = *str;
16 && (c == 'p' || c == 'P'))
{
}
{
val += 3;
{
if(rr!=r)
{
r = rr;
}
}
}
}
break;
}
case VALUE:
{
if(sh_isoption(SH_NOEXEC))
return(0);
if(!np)
{
if(sh_isoption(SH_NOUNSET))
{
goto skip;
}
return(0);
}
{
}
if(((lvalue->emode&2) || lvalue->level>1 || sh_isoption(SH_NOUNSET)) && nv_isnull(np) && !nv_isattr(np,NV_INTEGER))
{
skip:
return(0);
}
return(r);
}
case MESSAGE:
#if 0
if(warn)
else
#endif
return(-1);
}
return(r);
}
/*
* convert number defined by string to a Sfdouble_t
* ptr is set to the last character processed
* if mode>0, an error will be fatal with value <mode>
*/
{
register Sfdouble_t d;
if(*str==0)
{
if(ptr)
return(0);
}
errno = 0;
{
}
else if (!d && *str=='-')
d = -0.0;
if(ptr)
return(d);
}
{
}
{
if(*ptr)
return((void*)ep);
}