Cleanup handling of colons in variable substitutions.
Patch: 7.126 Submitted by: Max Okumoto <okumoto@ucsd.edu>
This commit is contained in:
parent
5572ca61c8
commit
5b55d8aa02
@ -1239,7 +1239,6 @@ ParseModifier(const char input[], const char tstr[],
|
|||||||
VarParser *vp, size_t *lengthPtr, Boolean *freePtr)
|
VarParser *vp, size_t *lengthPtr, Boolean *freePtr)
|
||||||
{
|
{
|
||||||
char *value;
|
char *value;
|
||||||
const char *cp;
|
|
||||||
size_t used;
|
size_t used;
|
||||||
|
|
||||||
value = VarExpand(v, vp);
|
value = VarExpand(v, vp);
|
||||||
@ -1267,11 +1266,11 @@ ParseModifier(const char input[], const char tstr[],
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (tstr[1] == endc || tstr[1] == ':') {
|
if (tstr[1] == endc || tstr[1] == ':') {
|
||||||
char termc;
|
switch (tstr[0]) {
|
||||||
Buffer *buf;
|
|
||||||
|
|
||||||
switch (*tstr) {
|
|
||||||
case 'L':
|
case 'L':
|
||||||
|
{
|
||||||
|
const char *cp;
|
||||||
|
Buffer *buf;
|
||||||
buf = Buf_Init(MAKE_BSIZE);
|
buf = Buf_Init(MAKE_BSIZE);
|
||||||
for (cp = value; *cp; cp++)
|
for (cp = value; *cp; cp++)
|
||||||
Buf_AddByte(buf, (Byte)tolower(*cp));
|
Buf_AddByte(buf, (Byte)tolower(*cp));
|
||||||
@ -1279,25 +1278,25 @@ ParseModifier(const char input[], const char tstr[],
|
|||||||
newStr = (char *)Buf_GetAll(buf, (size_t *)NULL);
|
newStr = (char *)Buf_GetAll(buf, (size_t *)NULL);
|
||||||
Buf_Destroy(buf, FALSE);
|
Buf_Destroy(buf, FALSE);
|
||||||
|
|
||||||
cp = tstr + 1;
|
tstr += (tstr[1] == ':') ? 2 : 1;
|
||||||
termc = *cp;
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case 'O':
|
case 'O':
|
||||||
newStr = VarSortWords(value, SortIncreasing);
|
newStr = VarSortWords(value, SortIncreasing);
|
||||||
cp = tstr + 1;
|
tstr += (tstr[1] == ':') ? 2 : 1;
|
||||||
termc = *cp;
|
|
||||||
break;
|
break;
|
||||||
case 'Q':
|
case 'Q':
|
||||||
newStr = Var_Quote(value);
|
newStr = Var_Quote(value);
|
||||||
cp = tstr + 1;
|
tstr += (tstr[1] == ':') ? 2 : 1;
|
||||||
termc = *cp;
|
|
||||||
break;
|
break;
|
||||||
case 'T':
|
case 'T':
|
||||||
newStr = VarModify(value, VarTail, (void *)NULL);
|
newStr = VarModify(value, VarTail, (void *)NULL);
|
||||||
cp = tstr + 1;
|
tstr += (tstr[1] == ':') ? 2 : 1;
|
||||||
termc = *cp;
|
|
||||||
break;
|
break;
|
||||||
case 'U':
|
case 'U':
|
||||||
|
{
|
||||||
|
const char *cp;
|
||||||
|
Buffer *buf;
|
||||||
buf = Buf_Init(MAKE_BSIZE);
|
buf = Buf_Init(MAKE_BSIZE);
|
||||||
for (cp = value; *cp; cp++)
|
for (cp = value; *cp; cp++)
|
||||||
Buf_AddByte(buf, (Byte)toupper(*cp));
|
Buf_AddByte(buf, (Byte)toupper(*cp));
|
||||||
@ -1305,26 +1304,24 @@ ParseModifier(const char input[], const char tstr[],
|
|||||||
newStr = (char *)Buf_GetAll(buf, (size_t *)NULL);
|
newStr = (char *)Buf_GetAll(buf, (size_t *)NULL);
|
||||||
Buf_Destroy(buf, FALSE);
|
Buf_Destroy(buf, FALSE);
|
||||||
|
|
||||||
cp = tstr + 1;
|
tstr += (tstr[1] == ':') ? 2 : 1;
|
||||||
termc = *cp;
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case 'H':
|
case 'H':
|
||||||
newStr = VarModify(value, VarHead, (void *)NULL);
|
newStr = VarModify(value, VarHead, (void *)NULL);
|
||||||
cp = tstr + 1;
|
tstr += (tstr[1] == ':') ? 2 : 1;
|
||||||
termc = *cp;
|
|
||||||
break;
|
break;
|
||||||
case 'E':
|
case 'E':
|
||||||
newStr = VarModify(value, VarSuffix, (void *)NULL);
|
newStr = VarModify(value, VarSuffix, (void *)NULL);
|
||||||
cp = tstr + 1;
|
tstr += (tstr[1] == ':') ? 2 : 1;
|
||||||
termc = *cp;
|
|
||||||
break;
|
break;
|
||||||
case 'R':
|
case 'R':
|
||||||
newStr = VarModify(value, VarRoot, (void *)NULL);
|
newStr = VarModify(value, VarRoot, (void *)NULL);
|
||||||
cp = tstr + 1;
|
tstr += (tstr[1] == ':') ? 2 : 1;
|
||||||
termc = *cp;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
|
const char *cp;
|
||||||
#ifdef SYSVVARSUB
|
#ifdef SYSVVARSUB
|
||||||
/*
|
/*
|
||||||
* This can either be a bogus modifier or a
|
* This can either be a bogus modifier or a
|
||||||
@ -1392,41 +1389,37 @@ ParseModifier(const char input[], const char tstr[],
|
|||||||
* the whole string. Note the pattern
|
* the whole string. Note the pattern
|
||||||
* is anchored at the end.
|
* is anchored at the end.
|
||||||
*/
|
*/
|
||||||
termc = *--cp;
|
--cp;
|
||||||
delim = '\0';
|
delim = '\0';
|
||||||
newStr = VarModify(value, VarSYSVMatch, &pattern);
|
newStr = VarModify(value, VarSYSVMatch, &pattern);
|
||||||
|
|
||||||
free(pattern.lhs);
|
free(pattern.lhs);
|
||||||
free(pattern.rhs);
|
free(pattern.rhs);
|
||||||
|
|
||||||
termc = endc;
|
tstr = (endc == ':') ? (cp + 1) : cp;
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
Error("Unknown modifier '%c'\n", *tstr);
|
Error("Unknown modifier '%c'\n", *tstr);
|
||||||
for (cp = tstr + 1;
|
for (cp = tstr + 1; *cp != '\0'; cp++) {
|
||||||
*cp != ':' && *cp != endc && *cp != '\0';
|
if (*cp == ':' && *cp == endc) {
|
||||||
cp++)
|
break;
|
||||||
continue;
|
}
|
||||||
termc = *cp;
|
}
|
||||||
|
tstr = (*cp == ':') ? (cp + 1) : cp;
|
||||||
newStr = var_Error;
|
newStr = var_Error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (termc == '\0') {
|
|
||||||
Error("Unclosed variable specification for %s",
|
|
||||||
v->name);
|
|
||||||
}
|
|
||||||
tstr = (termc == ':') ? (cp + 1) : cp;
|
|
||||||
} else {
|
} else {
|
||||||
char termc;
|
|
||||||
#ifdef SUNSHCMD
|
#ifdef SUNSHCMD
|
||||||
if ((tstr[0] == 's') &&
|
if ((tstr[0] == 's') &&
|
||||||
(tstr[1] == 'h') &&
|
(tstr[1] == 'h') &&
|
||||||
(tstr[2] == endc || tstr[2] == ':')) {
|
(tstr[2] == endc || tstr[2] == ':')) {
|
||||||
const char *error;
|
const char *error;
|
||||||
Buffer *buf;
|
Buffer *buf;
|
||||||
|
|
||||||
buf = Cmd_Exec(value, &error);
|
buf = Cmd_Exec(value, &error);
|
||||||
newStr = Buf_GetAll(buf, NULL);
|
newStr = Buf_GetAll(buf, NULL);
|
||||||
@ -1434,11 +1427,11 @@ ParseModifier(const char input[], const char tstr[],
|
|||||||
|
|
||||||
if (error)
|
if (error)
|
||||||
Error(error, value);
|
Error(error, value);
|
||||||
cp = tstr + 2;
|
tstr = (tstr[2] == ':') ? (tstr + 2 + 1) : tstr + 2;
|
||||||
termc = *cp;
|
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
const char *cp;
|
||||||
#ifdef SYSVVARSUB
|
#ifdef SYSVVARSUB
|
||||||
/*
|
/*
|
||||||
* This can either be a bogus modifier or a
|
* This can either be a bogus modifier or a
|
||||||
@ -1506,31 +1499,29 @@ ParseModifier(const char input[], const char tstr[],
|
|||||||
* the whole string. Note the pattern
|
* the whole string. Note the pattern
|
||||||
* is anchored at the end.
|
* is anchored at the end.
|
||||||
*/
|
*/
|
||||||
termc = *--cp;
|
--cp;
|
||||||
delim = '\0';
|
delim = '\0';
|
||||||
newStr = VarModify(value, VarSYSVMatch, &pattern);
|
newStr = VarModify(value, VarSYSVMatch, &pattern);
|
||||||
|
|
||||||
free(pattern.lhs);
|
free(pattern.lhs);
|
||||||
free(pattern.rhs);
|
free(pattern.rhs);
|
||||||
|
|
||||||
termc = endc;
|
tstr = (endc == ':') ? (cp + 1) : cp;
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
Error("Unknown modifier '%c'\n", *tstr);
|
Error("Unknown modifier '%c'\n", *tstr);
|
||||||
for (cp = tstr + 1;
|
for (cp = tstr + 1; *cp != '\0'; cp++) {
|
||||||
*cp != ':' && *cp != endc && *cp != '\0';
|
if (*cp == ':' || *cp == endc) {
|
||||||
cp++)
|
break;
|
||||||
continue;
|
}
|
||||||
termc = *cp;
|
}
|
||||||
newStr = var_Error;
|
newStr = var_Error;
|
||||||
|
tstr = (*cp == ':') ? (cp + 1) : cp;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (termc == '\0') {
|
|
||||||
Error("Unclosed variable specification for %s",
|
|
||||||
v->name);
|
|
||||||
}
|
|
||||||
tstr = (termc == ':') ? (cp + 1) : cp;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user