/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1982-2012 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* AT&T Labs
*
*/
#include "defs.h"
#include "variables.h"
#include "path.h"
#include "lexstates.h"
#include "timeout.h"
#include "streval.h"
static char *savesub = 0;
{
};
#if !_lib_pathnative && _lib_uwin_path
extern int uwin_path(const char*, char*, int);
{
}
#endif /* _lib_pathnative */
#ifndef _ENV_H
#endif
static void rightjust(char*, int, int);
static char *lastdot(char*, int);
struct adata
{
char *mapname;
char **argnam;
int attsize;
char *attval;
};
#if SHOPT_TYPEDEF
struct sh_type
{
void *previous;
short numnodes;
short maxnodes;
};
#endif /*SHOPT_TYPEDEF */
#if NVCACHE
struct Namcache
{
struct Cache_entry
{
char *name;
int flags;
short size;
short len;
short index;
short ok;
};
#endif
char nv_local = 0;
#ifndef _ENV_H
#endif
#if ( SFIO_VERSION <= 20010201L )
#endif
#if !SHOPT_MULTIBYTE
# define mbchar(p) (*(unsigned char*)p++)
#endif /* SHOPT_MULTIBYTE */
/* ======== name value pair routines ======== */
#include "shnodes.h"
#include "builtins.h"
{
static char *buf;
{
if(buflen==0)
else
}
return(buf);
}
#ifdef _ENV_H
{
char *val;
if(ap)
{
return;
}
return;
stakputc('=');
}
#endif
/*
* output variable name in format for re-input
*/
{
{
break;
while(c= *sp++)
{
if(c==']')
break;
else if(c=='\\')
{
c = *sp++;
}
stakputc(c);
}
stakputc(0);
if(len>0)
{
return;
}
}
if(*cp)
{
if(len>0)
else
}
}
#if SHOPT_TYPEDEF
{
register int i;
register char *name=0;
{
/* could be an redefine */
}
{
return(np);
}
{
/* check for a redefine */
else
{
}
}
{
{
if(remove)
{
}
return(np);
}
}
if(remove)
return(np);
{
}
return(np);
}
#endif /* SHOPT_TYPEDEF */
/*
* given a list of assignments, determine <name> is on the list
returns a pointer to the argnod on the list or NULL
*/
{
char *cp;
{
else
return(arg);
}
return(0);
}
/*
* Perform parameter assignment for a linked list of parameters
* <flags> contains attributes for the parameters
*/
{
register char *cp;
#if SHOPT_TYPEDEF
if(maketype)
{
}
#endif /* SHOPT_TYPEDEF*/
#if SHOPT_NAMESPACE
flags |= NV_NOSCOPE;
#endif /* SHOPT_NAMESPACE */
if(sh_isoption(SH_ALLEXPORT))
{
flags |= NV_VARNAME;
}
else
{
{
}
else
{
stakseek(0);
{
int sub=0;
else
if(!array && tp->tre.tretyp!=TLST && tp->com.comset && !tp->com.comarg && tp->com.comset->argval[0]==0 && tp->com.comset->argval[1]=='[')
{
if(np)
{
{
stakputc('.');
}
}
}
if((arg->argflag&ARG_APPEND) && (tp->tre.tretyp&COMMSK)==TCOM && tp->com.comset && !nv_isvtree(np) && (((ap=nv_arrayptr(np)) && !ap->fun && !nv_opensub(np)) || (!ap && nv_isarray(np) && tp->com.comarg && !((mp=nv_search(tp->com.comarg->argval,shp->fun_tree,0)) && nv_isattr(mp,BLT_DCL)))))
{
{
}
}
if(nv_istable(np))
{
}
#if SHOPT_TYPEDEF
goto check_type;
#else
continue;
#endif /* SHOPT_TYPEDEF */
#if SHOPT_FIXEDARRAY
#endif /* SHOPT_FIXEDARRAY */
{
#if SHOPT_FIXEDARRAY
#else
#endif /* SHOPT_FIXEDARRAY */
{
}
else
{
}
}
{
#if SHOPT_TYPEDEF
goto check_type;
#else
continue;
#endif /* SHOPT_TYPEDEF */
}
/* check for array assignment */
if(tp->tre.tretyp!=TLST && tp->com.comarg && !tp->com.comset && ((array&NV_IARRAY) || !((mp=tp->com.comnamp) && nv_isattr(mp,BLT_DCL))))
{
int argc;
#if SHOPT_TYPEDEF
{
}
#endif /* SHOPT_TYPEDEF */
{
#if SHOPT_FIXEDARRAY
#else
#endif /* SHOPT_FIXEDARRAY */
{
if(ap)
}
}
{
int n = -1;
n = '+';
if(trap)
if(traceon)
{
}
}
#if SHOPT_TYPEDEF
goto check_type;
#else
continue;
#endif /* SHOPT_TYPEDEF */
}
goto skip;
{
if(!(arg->argflag&ARG_APPEND) && nv_isattr(np,NV_BINARY|NV_NOFREE|NV_RAW)!=(NV_BINARY|NV_NOFREE|NV_RAW))
goto skip;
}
{
if(tp->tre.tretyp!=TLST && !tp->com.comnamp && tp->com.comset && tp->com.comset->argval[0]==0 && tp->com.comset->argchn.ap)
{
{
}
#if SHOPT_TYPEDEF
goto check_type;
#else
continue;
#endif /* SHOPT_TYPEDEF */
}
{
}
{
if(nv_isarray(np))
{
if(sub>=0)
sub++;
}
sub=1;
}
else if(((np->nvalue.cp && np->nvalue.cp!=Empty)||nv_isvtree(np)|| nv_arrayptr(np)) && !nv_type(np))
{
}
}
else
{
}
skip:
if(sub>0)
{
}
else if(prefix)
else
shp->last_table = 0;
{
{
}
}
#if SHOPT_TYPEDEF
#endif
{
}
{
if(!tp->lst.lstlef || !tp->lst.lstlef->tre.tretyp==TCOM || tp->lst.lstlef->com.comarg || tp->lst.lstlef->com.comset && tp->lst.lstlef->com.comset->argval[0]!='[')
break;
}
if(!nv_isarray(np) && !typ && (tp->com.comarg || !tp->com.comset || tp->com.comset->argval[0]!='['))
{
}
#if SHOPT_TYPEDEF
goto check_type;
#else
continue;
#endif /* SHOPT_TYPEDEF */
}
mp = 0;
}
{
else
}
{
char *sub=0;
int append = 0;
if(nv_isarray(np))
{
append = ARG_APPEND;
cp++;
}
if(traceon)
{
if(sub)
if(cp)
{
if(append)
}
}
if(trap)
{
av[1] = 0;
}
}
#if SHOPT_TYPEDEF
if(maketype)
{
maketype = 0;
{
}
}
#endif /* SHOPT_TYPEDEF */
}
}
/*
* copy the subscript onto the stack
*/
{
register int c;
stakputc('[');
while(c= *sub++)
{
if(c=='[' || c==']' || c=='\\')
stakputc('\\');
stakputc(c);
}
}
/*
* construct a new name from a prefix and base name on the stack
*/
{
if(prefix)
{
stakputc('.');
stakputc('.');
}
if(last)
{
}
if(sub)
if(!last)
stakputc(0);
}
/*
* grow this stack string <name> by <n> bytes and move from cp-1 to end
* right by <n>. Returns beginning of string on the stack
*/
{
while(m-->0)
return((char*)name);
}
{
register int c;
#if SHOPT_FIXEDARRAY
#endif /* SHOPT_FIXEDARRAY */
{
top = 1;
else
flags &= ~NV_NOSCOPE;
}
if(*cp=='.')
cp++;
while(1)
{
{
case '[':
if(flags&NV_NOARRAY)
{
return(np);
}
goto skip;
case '.':
return(0);
{
c = '.';
}
skip:
case '+':
case '=':
*sp = 0;
case 0:
isref = 0;
mode |= HASH_NOSCOPE;
np=0;
if(top)
{
{
}
{
#if SHOPT_NAMESPACE
if(shp->var_tree->walk==shp->var_base || (shp->var_tree->walk!=shp->var_tree && shp->namespace && nv_dict(shp->namespace)==shp->var_tree->walk))
#else
#endif /* SHOPT_NAMESPACE */
{
#if SHOPT_NAMESPACE
#endif /* SHOPT_NAMESPACE */
{
if(mode==0)
else
{
np = 0;
}
}
}
else
{
flags |= NV_NOSCOPE;
noscope = 1;
}
}
{
{
np = 0;
}
}
}
#if SHOPT_NAMESPACE
#endif /* SHOPT_NAMESPACE */
{
if(top)
{
{
flags &= ~NV_NOSCOPE;
}
else if(nq)
{
{
#if SHOPT_NAMESPACE
#endif /* SHOPT_NAMESPACE */
{
}
}
flags |= NV_NOSCOPE;
}
}
#if SHOPT_NAMESPACE
{
flags |= NV_NOSCOPE;
}
#endif /* SHOPT_NAMESPACE */
}
if(c)
*sp = c;
top = 0;
if(isref)
{
#if SHOPT_FIXEDARRAY
int n=0,dim;
#endif /* SHOPT_FIXEDARRAY */
#if NVCACHE
#endif
if(c=='.') /* don't optimize */
{
return(np);
}
{
#if SHOPT_FIXEDARRAY
n = nv_refindex(np);
#endif /* SHOPT_FIXEDARRAY */
#if SHOPT_FIXEDARRAY
if(n)
{
}
else
#endif /* SHOPT_FIXEDARRAY */
if(sub && c!='.')
flags |= NV_NOSCOPE;
noscope = 1;
}
if(sub && c==0)
{
{
if(!nq)
goto addsub;
else
}
return(np);
}
#if SHOPT_FIXEDARRAY
else if(c || n)
#else
else if(c)
#endif /* SHOPT_FIXEDARRAY */
{
#if SHOPT_FIXEDARRAY
#endif /* SHOPT_FIXEDARRAY */
#if SHOPT_FIXEDARRAY
if(*sp==0)
else
#endif /* SHOPT_FIXEDARRAY */
c = *sp;
if(!noscope)
flags &= ~NV_NOSCOPE;
#if SHOPT_FIXEDARRAY
if(c==0)
#endif /* SHOPT_FIXEDARRAY */
}
}
cp++;
{
nv_local = 1;
if(np)
return(np);
}
cp--;
do
{
#if SHOPT_FIXEDARRAY
int fixed;
#endif /* SHOPT_FIXEDARRAY */
if(!np)
{
{
/*
* for backward compatibility
* evaluate subscript for
* possible side effects
*/
cp[-1] = 0;
}
return(np);
}
#if SHOPT_FIXEDARRAY
fixed = 0;
fixed = 1;
#endif /* SHOPT_FIXEDARRAY */
{
int n = 0;
sub = 0;
mode &= ~HASH_NOSCOPE;
if(c=='[')
{
#if SHOPT_FIXEDARRAY
#endif /* SHOPT_FIXEDARRAY */
#if 0
#endif
{
/* not implemented yet */
return(np);
}
#if SHOPT_FIXEDARRAY
if(fixed)
else
#endif /* SHOPT_FIXEDARRAY */
n |= ARRAY_FILL;
n |= NV_ADD;
#if SHOPT_FIXEDARRAY
if(fixed)
#endif /* SHOPT_FIXEDARRAY */
#if 0
if(scan)
#endif
}
else
if((c = *cp)=='.' || (c=='[' && nv_isarray(np)) || (n&ARRAY_FILL) || ((ap || (flags&NV_ASSIGN)) && (flags&NV_ARRAY)))
{
if(!sub)
{
if(m && !(n&NV_ADD))
return(0);
sub = "0";
}
if(!copy)
{
}
if(n <= m)
{
if(n)
{
}
if(n < m)
{
}
}
else
{
int r = n-m;
*sp = '[';
}
}
#if SHOPT_FIXEDARRAY
#else
#endif /* SHOPT_FIXEDARRAY */
{
/* subscript must be 0*/
cp[-1] = 0;
if(n)
return(0);
if(c)
}
{
{
return(0);
{
}
}
if(nq)
{
{
return(0);
}
nofree = 0;
}
return(nq);
else
{
/* ignore [0] */
c = *cp;
}
}
}
#if SHOPT_FIXEDARRAY
#else
else if(nv_isarray(np))
#endif /* SHOPT_FIXEDARRAY */
{
return(np);
}
nofree = 0;
{
{
break;
}
if(fp)
{
{
shp->last_table = 0;
break;
}
{
{
return(np);
}
}
}
}
}
while(c=='[');
return(np);
cp++;
break;
default:
return(np);
}
}
return(np);
}
/*
* delete the node <np> from the dictionary <root> and clear from the cache
* if <root> is NULL, only the cache is cleared
* if flags does not contain NV_NOFREE, the node is freed
* if np==0 && !root && flags==0, delete the Refdict dictionary
*/
{
#if NVCACHE
register int c;
{
}
#endif
{
if(Refdict)
Refdict = 0;
return;
}
{
{
{
}
}
}
if(root)
{
{
}
#if 0
else
{
}
#endif
}
}
/*
* Put <arg> into associative memory.
* If <flags> & NV_ARRAY then follow array to next subscript
* If <flags> & NV_NOARRAY then subscript is not allowed
* If <flags> & NV_NOSCOPE then use the current scope only
* If <flags> & NV_ASSIGN then assignment is allowed
* If <flags> & NV_IDENT then name must be an identifier
* If <flags> & NV_VARNAME then name must be a valid variable name
* If <flags> & NV_NOADD then node will not be added if not found
* If <flags> & NV_NOREF then don't follow reference
* If <flags> & NV_NOFAIL then don't generate an error message on failure
* If <flags> & NV_STATIC then unset before an assignment
* If <flags> & NV_UNJUST then unset attributes before assignment
* SH_INIT is only set while initializing the environment
*/
{
register int c;
int append=0;
char *fname = 0;
#if NVCACHE
#endif
shp->last_table = 0;
if(!root)
{
{
*fname = 0;
}
}
{
if(flags&NV_NOSCOPE)
{
{
}
}
return(np);
}
{
}
c = *(unsigned char*)cp;
{
if(c= *--cp)
*cp = 0;
if(c)
*cp = c;
goto skip;
}
else if(c=='.')
{
c = *++cp;
shp->last_table = 0;
}
if(c= !isaletter(c))
goto skip;
#if NVCACHE
{
continue;
if(*name==*xp->name && xp->namespace==shp->namespace && (flags&(NV_ARRAY|NV_NOSCOPE))==xp->flags && memcmp(xp->name,name,xp->len)==0 && (name[xp->len]==0 || name[xp->len]=='=' || name[xp->len]=='+'))
{
goto nocache;
}
}
#endif
#if NVCACHE
{
if(*cp)
{
if(!sp)
goto nocache;
}
else
{
else
}
}
#endif
if(fname)
{
*fname = '.';
*fname = 0;
}
else
{
{
cp+=2;
}
{
cp++;
}
}
c = *cp;
skip:
#if SHOPT_TYPEDEF
#endif /* SHOPT_TYPEDEF */
{
cp++;
if(sh_isstate(SH_INIT))
{
}
else
{
int isref;
{
{
return(np);
}
}
#if SHOPT_FIXEDARRAY
#else
#endif /* SHOPT_FIXEDARRAY */
if(isref)
{
}
{
{
else if(!array_assoc(ap) && (mp = nv_open(cp,shp->var_tree,NV_NOFAIL|NV_VARNAME|NV_NOARRAY|NV_NOASSIGN|NV_NOADD)) && nv_isvtree(np))
{
}
}
}
if(isref)
{
}
}
}
else if(c)
{
return(0);
if(c=='.')
msg = e_noparent;
else if(c=='[')
}
return(np);
}
#if SHOPT_MULTIBYTE
static int ja_size(char*, int, int);
static void ja_restore(void);
static char *savep;
#endif /* SHOPT_MULTIBYTE */
/*
* put value <string> into name-value node <np>.
* If <np> is an array, then the element given by the
* current index is assigned to.
* If <flags> contains NV_RDONLY, readonly attribute is ignored
* If <flags> contains NV_INTEGER, string is a pointer to a number
* If <flags> contains NV_NOFREE, previous value is freed, and <string>
* becomes value of node and <flags> becomes attributes
*/
{
register char *cp;
register int size = 0;
register int dot;
union Value u;
#if SHOPT_FIXEDARRAY
#endif /* SHOPT_FIXEDARRAY */
/* The following could cause the shell to fork if assignment
* would cause a side effect
*/
{
/* This function contains disc */
if(!nv_local)
{
nv_local=1;
return;
}
/* called from disc, assign the actual value */
}
nv_local=0;
{
return;
}
{
{
up = &u;
}
}
#if SHOPT_FIXEDARRAY
#else
#endif /* SHOPT_FIXEDARRAY */
{
{
{
if(flags&NV_INTEGER)
{
else
}
else
}
else
{
double d,od=0;
if(flags&NV_INTEGER)
{
d = (double)(*(Sfdouble_t*)sp);
d = (double)(*(float*)sp);
else
d = *(double*)sp;
}
else
}
}
else
{
{
if(flags&NV_INTEGER)
{
{
else
}
{
else
}
else
{
else
}
}
else if(sp)
}
else
{
if(flags&NV_INTEGER)
{
{
else
}
{
else
}
else
{
else
}
}
else if(sp)
{
if(ld<0)
else
}
{
int16_t s=0;
}
else
{
}
}
}
}
else
{
const char *tofree=0;
#if _lib_pathnative
#endif /* _lib_pathnative */
if(flags&NV_INTEGER)
{
{
else
}
{
else
}
else
{
else
}
}
{
#ifdef _lib_pathnative
/*
* return the host file name given the UNIX name
*/
{
}
#else
;
#endif /* _lib_pathnative */
}
{
#if SHOPT_MULTIBYTE
if(size)
#endif /* SHOPT_MULTIBYTE */
}
{
/* delay free in case <sp> points into free region */
}
tofree = 0;
tofree = 0;
if (sp)
{
append=0;
return;
#if (_AST_VERSION>=20030127L)
{
{
if(tofree)
{
}
return;
}
size = 0;
if(size==0)
if(oldsize)
return;
return;
}
else
#endif
{
{
if(dot==0)
return;
{
stakputc(0);
append = 0;
}
else
{
}
}
}
{
{
}
else
{
{
tofree = 0;
}
else
}
}
}
else
cp = 0;
if(sp)
{
{
register char *dp;
}
#if SHOPT_MULTIBYTE
/* restore original string */
if(savep)
ja_restore();
#endif /* SHOPT_MULTIBYTE */
}
}
return;
}
/*
*
* Right-justify <str> so that it contains no more than
* <size> characters. If <str> contains fewer than <size>
* characters, left-pad with <fill>. Trailing blanks
* in <str> will be ignored.
*
* If the leftmost digit in <str> is not a digit, <fill>
* will default to a blank.
*/
{
register int n;
/* ignore trailing blanks */
if (n == size)
return;
if(n > size)
{
*(str+n) = 0;
return;
}
if (n == 0)
{
*--sp = ' ';
return;
}
while(n--)
{
sp--;
}
fill = ' ';
return;
}
#if SHOPT_MULTIBYTE
/*
* handle left and right justified fields for multi-byte chars
* given physical size, return a logical size which reflects the
* screen width of multi-byte characters
* Multi-width characters replaced by spaces if they cross the boundary
* <type> is non-zero for right justified fields
*/
{
register int c, n=size;
register int outsize;
int oldn;
wchar_t w;
while(*cp)
{
oldn = n;
outsize = 0;
n += (c-outsize);
break;
}
/* check for right justified fields that need truncating */
if(size <0)
{
if(type==0)
{
/* left justified and character crosses field boundary */
n = oldn;
/* save boundary char and replace with spaces */
size = c;
while(size--)
{
}
}
if(type)
}
return(n);
}
static void ja_restore(void)
{
while(*cp)
savep = 0;
}
#endif /* SHOPT_MULTIBYTE */
#ifndef _ENV_H
{
register char *p,*q;
if(value)
{
*p++ = '=';
}
return(q);
}
#endif
/*
* put the name and attribute into value of attributes variable
*/
#ifdef _ENV_H
{
return;
stakputc('=');
{
/* export doubles as integers for ksh88 compatibility */
}
else
{
if(flag&NV_INTEGER)
}
stakputc(c);
}
#else
{
return;
{
return;
}
{
/* export doubles as integers for ksh88 compatibility */
}
else
{
if(flag&NV_INTEGER)
else
}
}
#endif
#ifndef _ENV_H
{
register char *value;
}
#endif
/*
* Generate the environment list for the child.
*/
#ifdef _ENV_H
char **sh_envgen(void)
{
register char **er;
nv_scan(shp->var_tree, attstore,(void*)0,0,(NV_RDONLY|NV_UTOL|NV_LTOU|NV_RJUST|NV_LJUST|NV_ZFILL|NV_INTEGER));
else
return(er);
}
#else
char **sh_envgen(void)
{
register char **er;
register int namec;
register char *cp;
/* L_ARGNOD gets generated automatically as full path name of command */
nv_scan(shp->var_tree, attstore,&data,0,(NV_RDONLY|NV_UTOL|NV_LTOU|NV_RJUST|NV_LJUST|NV_ZFILL|NV_INTEGER));
return(er);
}
#endif
struct scan
{
int scanmask;
int scanflags;
int scancount;
void *scandata;
};
{
char *cp;
#if SHOPT_TYPEDEF
return(0);
#endif /*SHOPT_TYPEDEF */
k = NV_TABLE;
{
{
{
return(0);
}
else if((sp->scanflags==NV_UTOL||sp->scanflags==NV_LTOU) && (cp=(char*)nv_mapchar(np,0)) && strcmp(cp,tp->mapname))
return(0);
}
return(0);
{
if(nv_isarray(np))
}
}
return(0);
}
/*
* Walk through the name-value pairs
* if <mask> is non-zero, then only nodes with (nvflags&mask)==flags
* are visited
* If <mask> is zero, and <flags> non-zero, then nodes with one or
* more of <flags> is visited
* If <mask> and <flags> are zero, then all nodes are visted
*/
{
hashfn = scanfilter;
if(flags&NV_NOSCOPE)
if(base)
}
/*
* create a new environment scope
*/
{
#if SHOPT_NAMESPACE
#endif /* SHOPT_NAMESPACE */
if(envlist)
{
if(!fun)
return;
}
{
}
}
/*
* Remove freeable local space associated with the nvalue field
* of nnod. This includes any strings representing the value(s) of the
* node, as well as its dope vector, if it is an array.
*/
{
char *cp=0;
return;
return;
return;
{
}
{
{
}
if(!cp)
return;
}
if(nv_isarray(np))
nv_setattr(np,0);
if(cp)
{
}
}
/*
* Currently this is a dummy, but someday will be needed
* for reference counting
*/
{
}
{
{
{
{
{
}
else
}
}
shp->last_table = 0;
if(nv_isvtree(np))
{
{
}
}
}
}
/*
*
* Set the value of <np> to 0, and nullify any attributes
* that <np> may have had. Free any freeable space occupied
* by the value of <np>. If <np> denotes an array member, it
* will retain its attributes.
* <flags> can contain NV_RDONLY to override the readonly attribute
* being cleared.
* <flags> can contain NV_EXPORT to override preserve nvenv
*/
{
#if SHOPT_FIXEDARRAY
#endif /* SHOPT_FIXEDARRAY */
{
{
return;
}
{
/* free function definition */
if(cp)
{
*cp = 0;
*cp++ = '.';
}
{
do
{
continue;
break;
}
}
{
{
}
}
}
goto done;
}
{
/* This function contains disc */
if(!nv_local)
{
nv_local=1;
nv_local=0;
return;
}
/* called from disc, assign the actual value */
nv_local=0;
}
{
goto done;
}
#if SHOPT_FIXEDARRAY
#else
#endif /* SHOPT_FIXEDARRAY */
{
up = 0;
}
else
{
}
done:
{
nv_setsize(np,0);
{
nv_setattr(np,0);
}
else
{
}
}
}
/*
* return the node pointer in the highest level scope
*/
{
return(np);
}
#if 1
/*
* return space separated list of names of variables in given tree
*/
{
if(out)
else
{
{
if(!first)
else
first = 0;
}
}
if(base)
}
#endif
#if SHOPT_OPTIMIZE
struct optimize
{
char **ptr;
};
{
{
{
}
}
}
{
}
{
return((Namfun_t*)0);
}
static const Namdisc_t optimize_disc = {sizeof(struct optimize),put_optimize,0,0,0,0,clone_optimize};
{
{
{
return;
}
{
{
return;
}
break;
}
return;
else
if(xp)
{
}
else
{
}
}
}
{
{
{
}
}
}
#else
#endif /* SHOPT_OPTIMIZE */
/*
* Return a pointer to a character string that denotes the value
* of <np>. If <np> refers to an array, return a pointer to
* the value associated with the current index.
*
* If the value of <np> is an integer, the string returned will
* be overwritten by the next call to nv_getval.
*
* If <np> has no value, 0 is returned.
*/
{
register int numeric;
#if SHOPT_OPTIMIZE
#endif /* SHOPT_OPTIMIZE */
goto done;
{
char *sub;
return(0);
if(sub)
{
}
}
{
if(!nv_local)
{
nv_local=1;
}
nv_local=0;
}
if(numeric)
{
return("0");
{
double d;
char *format;
{
format = "%.*Lg";
format = "%.*La";
else
format = "%.*Lf";
}
else
{
format = "%.*g";
format = "%.*a";
else
format = "%.*f";
}
}
{
{
else
}
else
}
{
else
}
else
{
{
}
numeric = 0;
}
}
done:
#if (_AST_VERSION>=20030127L)
/*
* if NV_RAW flag is on, return pointer to binary data
* otherwise, base64 encode the data and return this string
*/
{
char *cp;
char *ep;
*ep = 0;
return(cp);
}
#endif
{
return(cp);
}
}
{
register Sfdouble_t r=0;
register char *str;
#if SHOPT_OPTIMIZE
#endif /* SHOPT_OPTIMIZE */
if(nv_istable(np))
{
if(!nv_local)
{
nv_local=1;
}
nv_local=0;
}
{
if(str)
}
{
r = 0;
{
else
}
{
{
else
}
else
}
else
{
{
else
r = up->s;
}
else
}
}
{
{
while(*str=='0')
str++;
}
}
return(r);
}
/*
* Give <np> the attributes <newatts,> and change its current
* value to conform to <newatts>. The <size> of left and right
* justified fields may be given.
*/
{
register char *sp;
register char *cp = 0;
register unsigned int n;
/* check for restrictions */
if(sh_isoption(SH_RESTRICTED) && ((sp=nv_name(np))==nv_name(PATHNOD) || sp==nv_name(SHELLNOD) || sp==nv_name(ENVNOD) || sp==nv_name(FPATHNOD)))
/* handle attributes that do not change data separately */
{
/* record changes to the environment */
if(n&NV_EXPORT)
{
}
else
{
}
return;
}
{
if(size)
return;
}
/* for an array, change all the elements */
if(fp)
if(ap) /* add element to prevent array deletion */
{
#if SHOPT_FIXEDARRAY
{
goto skip;
}
#endif /* SHOPT_TYPEDEF */
}
do
{
{
{
if(trans)
{
}
}
if(!mp)
{
if(ap)
if(!trans)
if(ap)
}
size = n;
}
else if(!trans)
if (cp)
{
if(!mp)
}
}
#if SHOPT_FIXEDARRAY
skip:
#endif /* SHOPT_TYPEDEF */
if(fp)
if(ap)
return;
}
{
return(0);
c1= '=';
{
continue;
return((char*)(cp+1));
}
return(0);
}
/*
* This version of getenv uses the hash storage to access environment values
*/
{
{
#if 0
if(name[0] == 'P' && name[1] == 'A' && name[2] == 'T' && name[3] == 'H' && name[4] == 0 || name[0] == 'L' && ((name[1] == 'C' || name[1] == 'D') && name[2] == '_' || name[1] == 'A' && name[1] == 'N') || name[0] == 'V' && name[1] == 'P' && name[2] == 'A' && name[3] == 'T' && name[4] == 'H' && name[5] == 0 || name[0] == '_' && name[1] == 'R' && name[2] == 'L' && name[3] == 'D' || name[0] == '_' && name[1] == 'A' && name[2] == 'S' && name[3] == 'T' && name[4] == '_')
#endif
}
return(0);
}
#ifndef _NEXT_SOURCE
/*
* Some dynamic linkers will make this file see the libc getenv(),
* so sh_getenv() is used for the astintercept() callback. Plain
* getenv() is provided for static links.
*/
{
}
#endif /* _NEXT_SOURCE */
/*
* This version of putenv uses the hash storage to assign environment values
*/
{
if(name)
{
}
return(0);
}
/*
* Override libast setenviron().
*/
{
if(name)
{
}
return("");
}
/*
* Same linker dance as with getenv() above.
*/
{
return sh_setenviron(name);
}
/*
* normalize <cp> and return pointer to subscript if any
* if <eq> is specified, return pointer to first = not in a subscript
*/
{
register char *ep=0;
register int c;
if(eq)
cp++;
{
if(c=='[')
{
if(*cp==']')
cp++;
else
}
else if(c=='.')
{
if(*cp=='[')
{
}
ep = 0;
}
else if(eq && c == '=')
return(cp-1);
}
}
{
register char *cp;
{
}
arraynp = 1;
{
return(0);
}
if(!hp)
{
#if SHOPT_NAMESPACE
else
#endif /* SHOPT_NAMESPACE */
}
if(!nr)
if(!nr)
{
if(!nv_isvtree(np))
return(0);
}
{
/* create a virtual node */
{
}
}
if(mp)
{
}
{
if(index<0)
return(0);
}
{
return(1);
}
{
}
{
{
}
else
{
{
}
}
}
else
{
{
}
}
return(1);
}
/*
* Create a reference node from <np> to $np in dictionary <hp>
*/
{
return;
if(nv_isarray(np))
{
return;
}
if(hp)
else if(hpnext && dtvnext(hpnext)==shp->var_base && (nr=nv_open(cp,hpnext,flags|NV_NOSCOPE|NV_NOADD|NV_NOFAIL)))
else if((openmatch=shp->openmatch) && hpnext==shp->var_base && (nr=nv_open(cp,hpnext,flags|NV_NOSCOPE|NV_NOADD|NV_NOFAIL)))
if(nq)
else
{
/* bind to earlier scope, or add to global scope */
if(nv_isarray(nq))
}
#if SHOPT_FIXEDARRAY
#else
#endif /* SHOPT_FIXEDARRAY */
{
if(!nv_arrayptr(nq))
{
}
}
if(!nr)
{
}
{
}
#if SHOPT_FIXEDARRAY
#else
if(ep)
#endif /* SHOPT_FIXEDARRAY */
{
/* cause subscript evaluation and return result */
if(nv_isarray(nq))
else
{
int n;
ep[n] = ']';
ep = 0;
else
}
}
if(ep)
{
#if SHOPT_FIXEDARRAY
else
#endif /* SHOPT_FIXEDARRAY */
}
if(!Refdict)
{
}
}
/*
* get the scope corresponding to <index>
* whence uses the same values as lseeek()
*/
{
else
{
else
{
int n =0;
n++;
}
}
if(index < 0)
return((Shscope_t*)0);
}
/*
* make <scoped> the top scope and return previous scope
*/
{
return(old);
}
{
if(dp)
{
{
}
}
}
/*
* The inverse of creating a reference node
*/
{
return;
return;
if(Refdict)
{
}
#if SHOPT_OPTIMIZE
{
{
{
return;
}
}
}
#endif
}
/*
* These following are for binary compatibility with the old hash library
* They will be removed someday
*/
#if defined(__IMPORT__) && defined(__EXPORT__)
# define extern __EXPORT__
#endif
{
}
{
return(dp);
}
{
}
{
}
{
#if SHOPT_FIXEDARRAY
#endif /* SHOPT_FIXEDARRAY */
char *cp;
{
#if SHOPT_NAMESPACE
{
}
#endif /* SHOPT_NAMESPACE */
}
#if SHOPT_FIXEDARRAY
#endif /* SHOPT_FIXEDARRAY */
{
shp->last_table = 0;
if(nv_isarray(mp))
else
}
if(nv_istable(np))
#if 1
#else
#endif
{
{
shp->last_table = 0;
}
}
{
#if SHOPT_FIXEDARRAY
table = 0;
#else
#endif /* SHOPT_FIXEDARRAY */
}
if(table)
{
}
else
#if SHOPT_FIXEDARRAY
#endif /* SHOPT_FIXEDARRAY */
}
{
return(shp->last_table);
}
/*
* returns the data context for a builtin
*/
{
}
{
}
{
if(size>=0)
return(oldsize);
}
{
{
}
return(0);
}
{
return;
}