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)
|
||||
{
|
||||
char *value;
|
||||
const char *cp;
|
||||
size_t used;
|
||||
|
||||
value = VarExpand(v, vp);
|
||||
@ -1267,11 +1266,11 @@ ParseModifier(const char input[], const char tstr[],
|
||||
break;
|
||||
default:
|
||||
if (tstr[1] == endc || tstr[1] == ':') {
|
||||
char termc;
|
||||
Buffer *buf;
|
||||
|
||||
switch (*tstr) {
|
||||
switch (tstr[0]) {
|
||||
case 'L':
|
||||
{
|
||||
const char *cp;
|
||||
Buffer *buf;
|
||||
buf = Buf_Init(MAKE_BSIZE);
|
||||
for (cp = value; *cp; 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);
|
||||
Buf_Destroy(buf, FALSE);
|
||||
|
||||
cp = tstr + 1;
|
||||
termc = *cp;
|
||||
tstr += (tstr[1] == ':') ? 2 : 1;
|
||||
break;
|
||||
}
|
||||
case 'O':
|
||||
newStr = VarSortWords(value, SortIncreasing);
|
||||
cp = tstr + 1;
|
||||
termc = *cp;
|
||||
tstr += (tstr[1] == ':') ? 2 : 1;
|
||||
break;
|
||||
case 'Q':
|
||||
newStr = Var_Quote(value);
|
||||
cp = tstr + 1;
|
||||
termc = *cp;
|
||||
tstr += (tstr[1] == ':') ? 2 : 1;
|
||||
break;
|
||||
case 'T':
|
||||
newStr = VarModify(value, VarTail, (void *)NULL);
|
||||
cp = tstr + 1;
|
||||
termc = *cp;
|
||||
tstr += (tstr[1] == ':') ? 2 : 1;
|
||||
break;
|
||||
case 'U':
|
||||
{
|
||||
const char *cp;
|
||||
Buffer *buf;
|
||||
buf = Buf_Init(MAKE_BSIZE);
|
||||
for (cp = value; *cp; 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);
|
||||
Buf_Destroy(buf, FALSE);
|
||||
|
||||
cp = tstr + 1;
|
||||
termc = *cp;
|
||||
tstr += (tstr[1] == ':') ? 2 : 1;
|
||||
break;
|
||||
}
|
||||
case 'H':
|
||||
newStr = VarModify(value, VarHead, (void *)NULL);
|
||||
cp = tstr + 1;
|
||||
termc = *cp;
|
||||
tstr += (tstr[1] == ':') ? 2 : 1;
|
||||
break;
|
||||
case 'E':
|
||||
newStr = VarModify(value, VarSuffix, (void *)NULL);
|
||||
cp = tstr + 1;
|
||||
termc = *cp;
|
||||
tstr += (tstr[1] == ':') ? 2 : 1;
|
||||
break;
|
||||
case 'R':
|
||||
newStr = VarModify(value, VarRoot, (void *)NULL);
|
||||
cp = tstr + 1;
|
||||
termc = *cp;
|
||||
tstr += (tstr[1] == ':') ? 2 : 1;
|
||||
break;
|
||||
default:
|
||||
{
|
||||
const char *cp;
|
||||
#ifdef SYSVVARSUB
|
||||
/*
|
||||
* 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
|
||||
* is anchored at the end.
|
||||
*/
|
||||
termc = *--cp;
|
||||
--cp;
|
||||
delim = '\0';
|
||||
newStr = VarModify(value, VarSYSVMatch, &pattern);
|
||||
|
||||
free(pattern.lhs);
|
||||
free(pattern.rhs);
|
||||
|
||||
termc = endc;
|
||||
tstr = (endc == ':') ? (cp + 1) : cp;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
Error("Unknown modifier '%c'\n", *tstr);
|
||||
for (cp = tstr + 1;
|
||||
*cp != ':' && *cp != endc && *cp != '\0';
|
||||
cp++)
|
||||
continue;
|
||||
termc = *cp;
|
||||
for (cp = tstr + 1; *cp != '\0'; cp++) {
|
||||
if (*cp == ':' && *cp == endc) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
tstr = (*cp == ':') ? (cp + 1) : cp;
|
||||
newStr = var_Error;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (termc == '\0') {
|
||||
Error("Unclosed variable specification for %s",
|
||||
v->name);
|
||||
}
|
||||
tstr = (termc == ':') ? (cp + 1) : cp;
|
||||
|
||||
} else {
|
||||
char termc;
|
||||
#ifdef SUNSHCMD
|
||||
if ((tstr[0] == 's') &&
|
||||
(tstr[1] == 'h') &&
|
||||
(tstr[2] == endc || tstr[2] == ':')) {
|
||||
const char *error;
|
||||
Buffer *buf;
|
||||
const char *error;
|
||||
Buffer *buf;
|
||||
|
||||
buf = Cmd_Exec(value, &error);
|
||||
newStr = Buf_GetAll(buf, NULL);
|
||||
@ -1434,11 +1427,11 @@ ParseModifier(const char input[], const char tstr[],
|
||||
|
||||
if (error)
|
||||
Error(error, value);
|
||||
cp = tstr + 2;
|
||||
termc = *cp;
|
||||
tstr = (tstr[2] == ':') ? (tstr + 2 + 1) : tstr + 2;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
const char *cp;
|
||||
#ifdef SYSVVARSUB
|
||||
/*
|
||||
* 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
|
||||
* is anchored at the end.
|
||||
*/
|
||||
termc = *--cp;
|
||||
--cp;
|
||||
delim = '\0';
|
||||
newStr = VarModify(value, VarSYSVMatch, &pattern);
|
||||
|
||||
free(pattern.lhs);
|
||||
free(pattern.rhs);
|
||||
|
||||
termc = endc;
|
||||
tstr = (endc == ':') ? (cp + 1) : cp;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
Error("Unknown modifier '%c'\n", *tstr);
|
||||
for (cp = tstr + 1;
|
||||
*cp != ':' && *cp != endc && *cp != '\0';
|
||||
cp++)
|
||||
continue;
|
||||
termc = *cp;
|
||||
for (cp = tstr + 1; *cp != '\0'; cp++) {
|
||||
if (*cp == ':' || *cp == endc) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user