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