/***********************************************************************
* *
* 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
/*
* UNIX shell
*
* S. R. Bourne
* Rewritten by David Korn
* AT&T Labs
*
*/
/*
*/
#include "defs.h"
#include "path.h"
#include "builtins.h"
#include "terminal.h"
#include "edit.h"
#if SHOPT_KIA
# include "shlex.h"
# include "io.h"
#endif /* SHOPT_KIA */
#if SHOPT_PFSH
#else
# define PFSHOPT
#endif
#if SHOPT_BASH
#else
# define BASHOPT
#endif
#if SHOPT_HISTEXPAND
#else
#endif
static char *null;
/* The following order is determined by sh_optset */
static const int flagval[] =
{
#if SHOPT_PFSH
#endif
#if SHOPT_BASH
#endif
#if SHOPT_HISTEXPAND
#endif
0
};
typedef struct _arg_
{
#if SHOPT_KIA
char *kiafile;
#endif /* SHOPT_KIA */
} Arg_t;
/* ======== option handling ======== */
{
return(addr);
}
{
#if SHOPT_BASH
if(strcmp(s,"bash1")==0)
{
if(sh_isoption(SH_BASH))
}
else if(strcmp(s,"bash2")==0)
{
if(sh_isoption(SH_BASH))
}
else
#endif
if(*s!=':')
return(1);
}
/*
* This routine turns options on and off
* The options "PDicr" are illegal from set command.
* The -o option is used to set option by name
* This routine returns the number of non-option arguments
*/
{
register int n,o;
const char *cp;
int verbose,f;
if(argc>0)
setflag = 4;
else
{
o=0;
switch(n)
{
case 'A':
if(f)
continue;
#if SHOPT_BASH
case 'O': /* shopt options, only in bash mode */
if(!sh_isoption(SH_BASH))
#endif
case 'o': /* set options */
{
/* print style: -O => shopt options
* bash => print unset options also, no heading
*/
(n=='O'?PRINT_SHOPT:0)|
continue;
}
if(o<=0
|| (setflag && (o&SH_COMMANDLINE)))
{
error_info.errors++;
}
o &= 0xff;
break;
#if SHOPT_BASH
case -1: /* --rcfile */
continue;
case -2: /* --noediting */
if (!f)
{
}
continue;
case -3: /* --profile */
n = 'l';
goto skip;
case -4: /* --posix */
/* mask lower 8 bits to find char in optksh string */
n&=0xff;
goto skip;
case -5: /* --version */
sh_exit(0);
#endif
case -6: /* --default */
{
}
continue;
case -7:
f = 0;
goto byname;
case 'D':
goto skip;
case 'T':
else
continue;
case 's':
if(setflag)
{
continue;
}
#if SHOPT_KIA
goto skip;
case 'R':
if(setflag)
n = ':';
else
{
n = 'n';
}
/*FALLTHROUGH*/
#endif /* SHOPT_KIA */
#if SHOPT_REGRESS
goto skip;
case 'I':
continue;
#endif /* SHOPT_REGRESS */
skip:
default:
break;
case ':':
{
f = 1;
goto byname;
}
continue;
case '?':
return(-1);
}
if(f)
{
{
}
}
else
{
if ((o == SH_RESTRICTED) &&
e_restricted, "r");
}
if(o==SH_XTRACE)
trace = 0;
off_option(&newflags,o);
if(setflag==0)
}
}
if(error_info.errors)
/* check for '-' or '+' argument */
{
trace = 0;
}
if(trace)
if(setflag)
{
{
if(argc>0)
else
}
if(np)
{
}
}
{
{
}
argc--;
}
/* handling SH_INTERACTIVE and SH_PRIVILEGED has been moved to
* sh_applyopts(), so that the code can be reused from b_shopt(), too
*/
#if SHOPT_KIA
{
if(!argv[0])
}
#endif /* SHOPT_KIA */
return(argc);
}
/* apply new options */
{
/* cannot set -n for interactive shells since there is no way out */
if(!sh_isstate(SH_INIT) && is_option(&newflags,SH_PRIVILEGED) != sh_isoption(SH_PRIVILEGED) || sh_isstate(SH_INIT) && is_option(&((Arg_t*)shp->arg_context)->sh->offoptions,SH_PRIVILEGED) && shp->gd->userid!=shp->gd->euserid)
{
{
{
}
}
}
#if SHOPT_BASH
{
}
{
}
#endif
}
/*
* returns the value of $-
*/
{
{
if(sh_isoption(n))
cp++;
}
*flagp = 0;
}
/*
* set up positional parameters
*/
{
/* link into chain */
}
/*
* free the argument list if the use count is 1
* If count is greater than 1 decrement count and return same blk
* Free the argument list if the use count is 1 and return next blk
* Delete the blk from the argfor chain
* If flag is set, then the block dolh is not freed
*/
{
{
{
else
{
/* delete from chain */
else
{
break;
if(!argr)
}
}
}
}
return(argr);
}
/*
* grab space for arglist and copy args
* The strings are copied after the argment vector
*/
{
register int size=0,n;
/* count args and number of bytes of arglist */
while(n--)
{
}
return(dp);
}
/*
* used to set new arguments for functions
*/
{
return(olddolh);
}
/*
* reset arguments as they were before function
*/
{
{
}
}
/*
* increase the use count so that an sh_argset will not make it go away
*/
{
return(dh);
}
/*
* Print option settings on standard output
* if mode is inclusive or of PRINT_*
* if <mask> is set, only options with this mask value are displayed
*/
{
const char *name;
int on;
int value;
if(!(mode&PRINT_NO_HEADER))
if(mode&PRINT_TABLE)
{
int w;
int c;
int r;
int i;
c = 0;
{
continue;
name += 2;
c = w;
}
c += 4;
if((w = ed_window()) < (2*c))
w = 2*c;
r = w / c;
i = 0;
{
continue;
value &= 0xff;
{
name += 2;
}
if(++i>=r)
{
i = 0;
}
else
}
if(i)
return;
}
#if SHOPT_RAWONLY
#endif
{
if(mode&PRINT_SHOPT)
else
}
{
continue;
if(sh_isoption(SH_BASH))
{
continue;
}
continue;
{
name += 2;
}
if(mode&PRINT_VERBOSE)
{
}
{
if(mode&PRINT_SHOPT)
name);
else
name);
}
}
}
/*
* build an argument list
*/
{
{
register int n;
/* see if the arguments have already been expanded */
{
*nargs = 0;
return(&null);
}
{
}
*nargs = 0;
if(ac)
{
while(argp)
{
if(n>1)
{
}
*nargs += n;
}
}
}
{
register char **comargn;
register int argn;
register char **comargm;
/* allow room to prepend args */
argn += 1;
if(!argp)
{
/* reserve an extra null pointer */
*--comargn = 0;
return(comargn);
}
while(argp)
{
{
}
}
shp->last_table = 0;
return(comargn);
}
}
#if _pipe_socketpair && !_socketpair_devfd
/*
* create a real pipe (not a socket) and print message on failure
*/
{
sh_subsavefd(pv[0]);
return(0);
}
#endif
{
/* argument of the form <(cmd) or >(cmd) */
pv[2] = 0;
if(fd)
{
}
else
{
}
if(monitor)
return(ap);
}
/* Argument expansion */
{
register int count = 0;
#if SHOPT_DEVFD
{
count++;
}
else
#endif /* SHOPT_DEVFD */
{
#if SHOPT_OPTIMIZE
if(flag&ARG_OPTIMIZE)
{
count = 1;
}
else
#endif /* SHOPT_OPTIMIZE */
}
else
{
count++;
}
return(count);
}