typeset.c revision 7c2fbfb345896881c631598ee3852ce9ce33fb07
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1982-2008 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
/*
* 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
{
char *prefix;
char *tname;
char *help;
short aflag;
short pflag;
int argnum;
int scanmask;
char **argnam;
};
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
{
const char *optstring = sh_opttypeset;
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 '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++;
if(error_info.errors)
if(isfloat)
if(shortint)
if(sflag)
{
}
flag |= NV_NOSCOPE;
{
}
}
{
char *name;
return;
return;
{
}
else
{
if(nv_isvtree(np))
if(!nv_isvtree(np))
}
}
{
register char *name;
char *last = 0;
{
nvflags |= NV_NOSCOPE;
}
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 */
}
np = 0;
{
if(flag==0)
{
continue;
}
sh_subfork();
}
else
r++;
{
}
continue;
}
/* tracked alias */
{
continue;
}
{
continue;
}
{
{
r++;
}
continue;
}
if(troot==shp->var_tree && ((tp->tp && !nv_isarray(np)) || !shp->st.real_fun && (nvflags&NV_STATIC)) && !strchr(name,'=') && !(shp->envlist && nv_onlist(shp->envlist,name)))
{
if(iarray)
{
else
}
{
if(comvar)
{
}
}
}
{
continue;
}
{
}
*last = 0;
{
#if SHOPT_BSH
#endif /* SHOPT_BSH */
if(flag&~NV_NOCHANGE)
newflag &= NV_NOCHANGE;
{
}
if(!(flag&NV_INTEGER))
{
}
}
else
{
}
{
else
{
char *oldname=0;
/* use reference name for export */
{
}
if(oldname)
}
}
{
}
if(last)
*last = '=';
/* set or unset references */
if(ref)
{
{
{
}
else
}
else
}
}
}
{
{
{
flag |= NV_FUNCTION;
}
{
}
}
else
}
return(r);
}
typedef void (*Iptr_t)(int,void*);
typedef int (*Fptr_t)(int, char*[], void*);
#define GROWLIB 4
static void **liblist;
static unsigned short *libattr;
static int nlib;
static int maxlib;
/*
* This allows external routines to load from the same library */
void **sh_getliblist(void)
{
return(liblist);
}
/*
* 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
*/
#if SHOPT_DYNAMIC
{
register int n;
register int r;
for (n = r = 0; n < nlib; n++)
{
if (r)
{
}
r++;
}
if (r)
nlib--;
{
if (liblist)
{
}
else
{
}
}
return !r;
}
#else
{
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;
{
case 's':
break;
case 'd':
dlete=1;
break;
case 'f':
#if SHOPT_DYNAMIC
#else
error_info.errors++;
#endif /* SHOPT_DYNAMIC */
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)
{
#if (_AST_VERSION>=20040404)
#else
#endif
{
return(1);
}
}
else
#endif /* SHOPT_DYNAMIC */
{
return(0);
}
r = 0;
{
errmsg = 0;
addr = 0;
{
/* (char*) added for some sgi-mips compilers */
#if SHOPT_DYNAMIC
#else
if(dlete)
#endif /* SHOPT_DYNAMIC */
{
{
errmsg = "restricted name";
else
}
break;
}
}
{
errmsg = "restricted name";
else if(!np)
errmsg = "not found";
}
if(errmsg)
{
r = 1;
}
argv++;
}
return(r);
}
{
if(argv[1])
{
return(2);
if(sh_isoption(SH_VERBOSE))
else
if(sh_isoption(SH_MONITOR))
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;
register 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)
{
{
if(is_abuiltin(np))
{
r = 1;
continue;
}
{
{
r=1;
continue;
}
}
if(troot==shp->var_tree && shp->st.real_fun && (dp=shp->var_tree->walk) && dp==shp->st.real_fun->sdict)
else if(isfun)
}
else
r = 1;
}
return(r);
}
/*
* print out the name and value of a name-value pair <np>
*/
{
register char *cp;
sh_sigcheck();
if(flag)
flag = '\n';
{
if(is_abuiltin(np))
return(0);
}
{
else
}
if(is_afunction(np))
{
char *fname=0;
else
flag = '\n';
if(flag)
{
else
}
else
{
{
fname = 0;
}
else if(fname)
else
flag = '\n';
if(fname)
}
}
if(nv_arrayptr(np))
{
return(0);
}
if(nv_isvtree(np))
{
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;
#if SHOPT_TYPEDEF
#endif /* SHOPT_TYPEDEF */
if(flag&NV_INTEGER)
if(mbcoll())
while(namec--)
{
if((np=nv_search(*argv++,root,0)) && np!=onp && (!nv_isnull(np) || np->nvfun || nv_isattr(np,~NV_NOFREE)))
{
{
{
continue;
}
continue;
}
}
}
}
/*
* add the name of the node to the argument list argnam
*/
{
}