Sync with NetBSD's revision 1.29 of this file.
Obtained from: NetBSD
This commit is contained in:
parent
f4eb55ba86
commit
96522b887c
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=25233
@ -33,7 +33,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id$
|
||||
* $Id: expand.c,v 1.16 1997/02/22 13:58:26 peter Exp $
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
@ -97,7 +97,7 @@ STATIC char *exptilde __P((char *, int));
|
||||
STATIC void expbackq __P((union node *, int, int));
|
||||
STATIC int subevalvar __P((char *, char *, int, int, int, int));
|
||||
STATIC char *evalvar __P((char *, int));
|
||||
STATIC int varisset __P((char *));
|
||||
STATIC int varisset __P((char *, int));
|
||||
STATIC void varvalue __P((char *, int, int));
|
||||
STATIC void recordregion __P((int, int, int));
|
||||
STATIC void ifsbreakup __P((char *, struct arglist *));
|
||||
@ -210,10 +210,10 @@ expandarg(arg, arglist, flag)
|
||||
|
||||
STATIC void
|
||||
argstr(p, flag)
|
||||
register char *p;
|
||||
char *p;
|
||||
int flag;
|
||||
{
|
||||
register char c;
|
||||
char c;
|
||||
int quotes = flag & (EXP_FULL | EXP_CASE); /* do CTLESC */
|
||||
int firsteq = 1;
|
||||
|
||||
@ -325,6 +325,16 @@ expari(flag)
|
||||
int result;
|
||||
int quotes = flag & (EXP_FULL | EXP_CASE);
|
||||
|
||||
while (ifsfirst.next != NULL) {
|
||||
struct ifsregion *ifsp;
|
||||
INTOFF;
|
||||
ifsp = ifsfirst.next->next;
|
||||
ckfree(ifsfirst.next);
|
||||
ifsfirst.next = ifsp;
|
||||
INTON;
|
||||
}
|
||||
ifslastp = NULL;
|
||||
|
||||
/*
|
||||
* This routine is slightly over-compilcated for
|
||||
* efficiency. First we make sure there is
|
||||
@ -487,7 +497,7 @@ subevalvar(p, str, strloc, subtype, startloc, varflags)
|
||||
return 0;
|
||||
|
||||
case VSTRIMLEFT:
|
||||
for (loc = startp; loc < str - 1; loc++) {
|
||||
for (loc = startp; loc < str; loc++) {
|
||||
c = *loc;
|
||||
*loc = '\0';
|
||||
if (patmatch(str, startp)) {
|
||||
@ -576,7 +586,7 @@ evalvar(p, flag)
|
||||
p = strchr(p, '=') + 1;
|
||||
again: /* jump here after setting a variable with ${var=text} */
|
||||
if (special) {
|
||||
set = varisset(var);
|
||||
set = varisset(var, varflags & VSNUL);
|
||||
val = NULL;
|
||||
} else {
|
||||
val = lookupvar(var);
|
||||
@ -591,12 +601,10 @@ evalvar(p, flag)
|
||||
if (set && subtype != VSPLUS) {
|
||||
/* insert the value of the variable */
|
||||
if (special) {
|
||||
char *exp, *oexpdest = expdest;
|
||||
varvalue(var, varflags & VSQUOTE, flag & EXP_FULL);
|
||||
if (subtype == VSLENGTH) {
|
||||
for (exp = oexpdest;exp != expdest; exp++)
|
||||
varlen++;
|
||||
expdest = oexpdest;
|
||||
varlen = expdest - stackblock() - startloc;
|
||||
STADJUST(-varlen, expdest);
|
||||
}
|
||||
} else {
|
||||
char const *syntax = (varflags & VSQUOTE) ? DQSYNTAX
|
||||
@ -662,6 +670,10 @@ evalvar(p, flag)
|
||||
if (subevalvar(p, NULL, expdest - stackblock(), subtype,
|
||||
startloc, varflags))
|
||||
goto record;
|
||||
else {
|
||||
int amount = (expdest - pat) + 1;
|
||||
STADJUST(-amount, expdest);
|
||||
}
|
||||
break;
|
||||
|
||||
case VSASSIGN:
|
||||
@ -708,23 +720,39 @@ evalvar(p, flag)
|
||||
*/
|
||||
|
||||
STATIC int
|
||||
varisset(name)
|
||||
varisset(name, nulok)
|
||||
char *name;
|
||||
{
|
||||
char **ap;
|
||||
int nulok;
|
||||
{
|
||||
|
||||
if (*name == '!') {
|
||||
if (backgndpid == -1)
|
||||
return 0;
|
||||
} else if (*name == '@' || *name == '*') {
|
||||
if (*name == '!')
|
||||
return backgndpid != -1;
|
||||
else if (*name == '@' || *name == '*') {
|
||||
if (*shellparam.p == NULL)
|
||||
return 0;
|
||||
|
||||
if (nulok) {
|
||||
char **av;
|
||||
|
||||
for (av = shellparam.p; *av; av++)
|
||||
if (**av != '\0')
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
} else if (is_digit(*name)) {
|
||||
char *ap;
|
||||
int num = atoi(name);
|
||||
ap = shellparam.p;
|
||||
while (--num >= 0)
|
||||
if (*ap++ == NULL)
|
||||
return 0;
|
||||
|
||||
if (num > shellparam.nparam)
|
||||
return 0;
|
||||
|
||||
if (num == 0)
|
||||
ap = arg0;
|
||||
else
|
||||
ap = shellparam.p[num - 1];
|
||||
|
||||
if (nulok && (ap == NULL || *ap == '\0'))
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@ -829,7 +857,7 @@ recordregion(start, end, nulonly)
|
||||
int end;
|
||||
int nulonly;
|
||||
{
|
||||
register struct ifsregion *ifsp;
|
||||
struct ifsregion *ifsp;
|
||||
|
||||
if (ifslastp == NULL) {
|
||||
ifsp = &ifsfirst;
|
||||
@ -859,7 +887,7 @@ ifsbreakup(string, arglist)
|
||||
struct ifsregion *ifsp;
|
||||
struct strlist *sp;
|
||||
char *start;
|
||||
register char *p;
|
||||
char *p;
|
||||
char *q;
|
||||
char *ifs;
|
||||
int ifsspc;
|
||||
@ -986,7 +1014,7 @@ expmeta(enddir, name)
|
||||
char *enddir;
|
||||
char *name;
|
||||
{
|
||||
register char *p;
|
||||
char *p;
|
||||
char *q;
|
||||
char *start;
|
||||
char *endname;
|
||||
@ -1202,8 +1230,8 @@ pmatch(pattern, string)
|
||||
char *pattern;
|
||||
char *string;
|
||||
{
|
||||
register char *p, *q;
|
||||
register char c;
|
||||
char *p, *q;
|
||||
char c;
|
||||
|
||||
p = pattern;
|
||||
q = string;
|
||||
@ -1302,7 +1330,7 @@ void
|
||||
rmescapes(str)
|
||||
char *str;
|
||||
{
|
||||
register char *p, *q;
|
||||
char *p, *q;
|
||||
|
||||
p = str;
|
||||
while (*p != CTLESC) {
|
||||
|
Loading…
Reference in New Issue
Block a user