/***********************************************************************
* *
* 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
/*
* export [-p] [arg...]
* readonly [-p] [arg...]
* typeset [options] [arg...]
* alias [-ptx] [arg...]
* unalias [arg...]
* builtin [-sd] [-f file] [name...]
* set [options] [name...]
* unset [-fnv] [name...]
*
* David Korn
* AT&T Labs
*
*/
#include "defs.h"
#include <error.h>
#include "path.h"
#include "name.h"
#include "history.h"
#include "builtins.h"
#include "variables.h"
struct tdata
{
const char *wctname;
char *prefix;
char *tname;
char *help;
short aflag;
short pflag;
int argnum;
int scanmask;
char **argnam;
int indent;
int noref;
};
static void print_attribute(Namval_t*,void*);
{
return(0);
}
/*
* Note export and readonly are the same
*/
#if 0
/* for the dictionary generator */
#endif
{
register int flag;
{
case 'p':
break;
case ':':
break;
case '?':
return(2);
}
if(error_info.errors)
if(*command=='r')
#ifdef _ENV_H
else if(!argv[1])
{
{
}
return(0);
}
#endif
else
{
}
}
{
register int n;
if(*argv[0]=='h')
if(argv[1])
{
{
case 'p':
break;
case 't':
break;
case 'x':
break;
case ':':
break;
case '?':
return(2);
}
if(error_info.errors)
{
/* hacks to handle hash -r | -- */
{
{
argv++;
if(!argv[1])
return(0);
}
{
argv++;
else
}
}
}
}
}
#if 0
/* for the dictionary generator */
#endif
{
if(ntp)
{
}
{
switch(n)
{
case 'a':
{
goto endargs;
}
break;
case 'A':
break;
case 'C':
break;
case 'E':
/* The following is for ksh88 compatibility */
{
break;
}
case 'F':
case 'X':
isfloat = 1;
if(n=='E')
{
flag &= ~NV_HEXFLOAT;
flag |= NV_EXPNOTE;
}
else if(n=='X')
{
flag &= ~NV_EXPNOTE;
flag |= NV_HEXFLOAT;
}
break;
case 'b':
break;
case 'm':
break;
case 'n':
flag &= ~NV_VARNAME;
break;
case 'H':
break;
case 'T':
break;
case 'L': case 'Z': case 'R':
if(n=='Z')
else
{
}
break;
case 'M':
else
break;
case 'f':
break;
case 'i':
flag |= NV_INTEGER;
break;
case 'l':
break;
case 'p':
break;
case 'r':
break;
#ifdef SHOPT_TYPEDEF
case 'S':
sflag=1;
break;
case 'h':
break;
#endif /*SHOPT_TYPEDEF*/
case 's':
shortint=1;
break;
case 't':
break;
case 'u':
break;
case 'x':
flag &= ~NV_VARNAME;
break;
case ':':
break;
case '?':
return(2);
}
}
/* handle argument of + and - specially */
else
argv--;
error_info.errors++;
error_info.errors++;
error_info.errors++;
error_info.errors++;
error_info.errors++;
error_info.errors++;
{
/* static function */
sflag = 0;
flag |= NV_STATICF;
}
if(error_info.errors)
if(isfloat)
if(shortint)
{
}
if(sflag)
{
}
flag |= NV_NOSCOPE;
{
#if SHOPT_NAMESPACE
{
}
else
#endif /* SHOPT_NAMESPACE */
#if SHOPT_NAMESPACE
{
}
#endif /* SHOPT_NAMESPACE */
{
return(0);
}
}
}
{
char *name;
{
return;
aflag = '+';
}
else if(nv_istable(np))
{
char *cp;
return;
if(*name=='.')
name++;
/* output types from namespace */
/* output variables from namespace */
/* output functions from namespace */
return;
}
if(aflag=='+')
return;
{
}
else
{
if(nv_isvtree(np))
if(!nv_isvtree(np))
}
}
{
register char *name;
char *last = 0;
{
nvflags |= NV_NOSCOPE;
}
if(*argv[0]=='+')
if(argv[1])
{
{
ref=1;
}
{
register unsigned newflag;
unsigned curflag;
{
/*
*functions can be exported or
* traced but not set
*/
{
/* Function names cannot be special builtin */
#if SHOPT_NAMESPACE
else
#endif /* SHOPT_NAMESPACE */
}
else
{
{
}
#if SHOPT_NAMESPACE
np = 0;
if(!np)
#endif /* SHOPT_NAMESPACE */
{
if(!is_afunction(np))
np = 0;
}
continue;
}
{
{
continue;
}
sh_subfork();
}
else
r++;
{
if(!np)
{
}
}
continue;
}
/* tracked alias */
{
continue;
}
np = nv_open(name,troot,nvflags|((nvflags&NV_ASSIGN)?0:NV_ARRAY)|((iarray|(nvflags&(NV_REF|NV_NOADD)==NV_REF))?NV_FARRAY:0));
if(!np)
continue;
else if(tp->tp && !nv_isattr(np,NV_MINIMAL|NV_EXPORT) && (mp=(Namval_t*)np->nvenv) && (ap=nv_arrayptr(mp)) && (ap->nelem&ARRAY_TREE))
{
}
{
if(!nv_istable(np))
continue;
}
{
{
r++;
}
continue;
}
{
if(comvar || (shp->last_root==shp->var_tree && (tp->tp || (!shp->st.real_fun && (nvflags&NV_STATIC)) || (!(flag&(NV_EXPORT|NV_RDONLY)) && nv_isattr(np,(NV_EXPORT|NV_IMPORT))==(NV_EXPORT|NV_IMPORT)))))
{
}
}
{
if(iarray)
{
else
{
}
}
{
if(comvar)
{
if(ap)
else
{
}
}
}
}
{
continue;
}
{
}
*last = 0;
continue;
{
char *cp;
{
{
{
}
}
{
}
}
}
{
#if SHOPT_BSH
#endif /* SHOPT_BSH */
if(flag&~NV_NOCHANGE)
newflag &= NV_NOCHANGE;
{
}
}
else
{
}
{
else
{
char *oldname=0;
if(oldname)
}
}
{
}
if(last)
*last = '=';
/* set or unset references */
if(ref)
{
{
{
}
else
}
else
}
}
}
else
{
{
{
flag |= NV_FUNCTION;
}
{
if(iarray)
if(comvar)
}
{
}
{
}
}
else
}
return(r);
}
#if SHOPT_DYNAMIC
typedef void (*Libinit_f)(int,void*);
typedef struct Libcomp_s
{
void* dll;
char* lib;
unsigned int attr;
} Libcomp_t;
static int nlib;
static int maxlib;
/*
* add library to loaded list
* call (*lib_init)() on first load if defined
* always move to head of search list
* return: 0: already loaded 1: first load
*/
{
register int n;
register int r;
for (n = r = 0; n < nlib; n++)
{
if (r)
r++;
}
if (r)
nlib--;
{
}
if (name)
if (pp)
{
}
nlib++;
return !r;
}
{
register int n;
for (n = 0; n < nlib; n++)
return 0;
}
#else
{
return 0;
}
{
return 0;
}
#endif /* SHOPT_DYNAMIC */
/*
* add change or list built-ins
* adding builtins requires dlopen() interface
*/
{
register int n, r=0, flag=0;
long dlete=0;
void *library=0;
char *errmsg;
#ifdef SH_PLUGIN_VERSION
unsigned long ver;
int list = 0;
#endif
{
case 's':
break;
case 'd':
dlete=1;
break;
case 'f':
#if SHOPT_DYNAMIC
#else
error_info.errors++;
#endif /* SHOPT_DYNAMIC */
break;
case 'l':
#ifdef SH_PLUGIN_VERSION
list = 1;
#endif
break;
case ':':
break;
case '?':
break;
}
if(error_info.errors)
{
if(sh_isoption(SH_RESTRICTED))
if(sh_isoption(SH_PFSH))
sh_subfork();
}
#if SHOPT_DYNAMIC
if(arg)
{
#ifdef SH_PLUGIN_VERSION
{
return(1);
}
if(list)
#else
#if (_AST_VERSION>=20040404)
#else
#endif
{
return(1);
}
#endif
}
else
#endif /* SHOPT_DYNAMIC */
{
return(0);
}
r = 0;
{
errmsg = 0;
addr = 0;
{
#if SHOPT_DYNAMIC
continue;
#else
if(dlete)
#endif /* SHOPT_DYNAMIC */
{
{
errmsg = "restricted name";
#if SHOPT_DYNAMIC
else
#endif /* SHOPT_DYNAMIC */
}
break;
}
}
{
errmsg = "restricted name";
}
errmsg = "not found";
if(errmsg)
{
r = 1;
}
argv++;
}
return(r);
}
{
if(argv[1])
{
return(2);
if(sh_isoption(SH_VERBOSE))
else
}
else
/*scan name chain and print*/
return(0);
}
/*
* The removing of Shell variable names, aliases, and functions
* is performed here.
* Unset functions with unset -f
* Non-existent items being deleted give non-zero exit status
*/
{
}
{
}
{
register const char *name;
volatile int r;
{
troot = sh_subaliastree(0);
}
else
name = sh_optunset;
{
case 'f':
break;
case 'a':
all=1;
break;
case 'n':
case 'v':
break;
case ':':
break;
case '?':
return(2);
}
if(!troot)
return(1);
r = 0;
nflag |= NV_VARNAME;
else
nflag = NV_NOSCOPE;
if(all)
{
return(r);
}
{
np = 0;
if(jmpval==0)
{
#if SHOPT_NAMESPACE
if(!np)
#endif /* SHOPT_NAMESPACE */
}
else
{
r = 1;
continue;
}
if(np)
{
{
r = 1;
continue;
}
{
#if SHOPT_FIXEDARRAY
#else
#endif /* SHOPT_FIXEDARRAY */
{
r=1;
continue;
}
}
if(troot==shp->var_tree && shp->st.real_fun && (dp=shp->var_tree->walk) && dp==shp->st.real_fun->sdict)
#if 0
/* causes unsetting local variable to expose global */
else if(shp->var_tree==troot && shp->var_tree!=shp->var_base && nv_search((char*)np,shp->var_tree,HASH_BUCKET|HASH_NOSCOPE))
#endif
else
}
r = 1;
}
return(r);
}
/*
* print out the name and value of a name-value pair <np>
*/
{
register char *cp;
if(flag)
flag = '\n';
return(0);
{
return(0);
}
if(nv_istable(np))
{
return(0);
}
{
outname = (*tp->prefix=='t' && (!nv_isnull(np) || nv_isattr(np,NV_FLOAT|NV_RDONLY|NV_BINARY|NV_RJUST|NV_NOPRINT)));
{
indent = 0;
}
if(!isfun)
{
else
}
}
if(isfun)
{
char *fname=0;
return(0);
else
flag = '\n';
if(flag)
{
else
}
else
{
{
fname = 0;
}
else if(fname)
else
flag = '\n';
if(fname)
}
}
if(nv_arrayptr(np))
{
if(indent)
return(0);
}
if(nv_isvtree(np))
{
if(indent)
if(!flag)
flag = '=';
if(flag != '\n')
{
{
}
else
#if SHOPT_TYPEDEF
#else
#endif /* SHOPT_TYPEDEF */
}
return(1);
}
return(0);
}
/*
* print attributes at all nodes
*/
{
}
/*
* print the attributes of name value pair give by <np>
*/
{
}
/*
* print the nodes in tree <root> which have attributes <flag> set
* of <option> is non-zero, no subscript or value is printed.
*/
{
register char **argv;
register int namec;
char *name=0;
int len;
#if SHOPT_TYPEDEF
#endif /* SHOPT_TYPEDEF */
if(flag&NV_INTEGER)
if(mbcoll())
{
}
else while(namec--)
{
if((np=nv_search(*argv++,root,0)) && np!=onp && (!nv_isnull(np) || np->nvfun || nv_isattr(np,~NV_NOFREE)))
{
if(name)
{
continue;
name = 0;
}
{
{
continue;
}
continue;
}
{
}
}
}
}
/*
* add the name of the node to the argument list argnam
*/
{
}