diff options
author | harti <harti@FreeBSD.org> | 2005-03-21 12:40:27 +0000 |
---|---|---|
committer | harti <harti@FreeBSD.org> | 2005-03-21 12:40:27 +0000 |
commit | e023a7de704760d22e3c6a6dc8139788f8ebac72 (patch) | |
tree | 1c25da72c1d10937971ce10a03425cf2f39f6fa8 /usr.bin/make/var.c | |
parent | 347aea443e9637e90244dcaf833faf0e60475c29 (diff) | |
download | FreeBSD-src-e023a7de704760d22e3c6a6dc8139788f8ebac72.zip FreeBSD-src-e023a7de704760d22e3c6a6dc8139788f8ebac72.tar.gz |
Remove unneeded temporary variables in modifier_S() and modifier_C().
Change the parsing of the C modifier flags so that specifying both
'1' and 'g' gives an error.
Patch: 7.141,7.142
Submitted by: Max Okumoto <okumoto@ucsd.edu>
Diffstat (limited to 'usr.bin/make/var.c')
-rw-r--r-- | usr.bin/make/var.c | 132 |
1 files changed, 63 insertions, 69 deletions
diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c index 21d77dd..c791da4 100644 --- a/usr.bin/make/var.c +++ b/usr.bin/make/var.c @@ -951,27 +951,26 @@ modifier_M(VarParser *vp, const char value[], char endc) static char * modifier_S(VarParser *vp, const char value[], Var *v) { - const char *mod = vp->ptr; VarPattern pattern; Buffer *buf; /* Buffer for patterns */ char delim; - const char *cur; char *newValue; pattern.flags = 0; buf = Buf_Init(0); - delim = mod[1]; /* used to find end of pattern */ + vp->ptr++; /* consume 'S' */ + + delim = *vp->ptr; /* used to find end of pattern */ + vp->ptr++; /* consume 1st delim */ /* * If pattern begins with '^', it is anchored to the start of the * word -- skip over it and flag pattern. */ - if (mod[2] == '^') { + if (*vp->ptr == '^') { pattern.flags |= VAR_MATCH_START; - cur = mod + 3; - } else { - cur = mod + 2; + vp->ptr++; } /* @@ -980,30 +979,30 @@ modifier_S(VarParser *vp, const char value[], Var *v) * unescaped $'s that aren't before the delimiter (expand the * variable substitution). The result is left in the Buffer buf. */ - while (cur[0] != delim) { - if (cur[0] == '\0') { + while (vp->ptr[0] != delim) { + if (vp->ptr[0] == '\0') { /* * LHS didn't end with the delim, complain and exit. */ Fatal("Unclosed substitution for %s (%c missing)", v->name, delim); - } else if ((cur[0] == '\\') && - ((cur[1] == delim) || - (cur[1] == '$') || - (cur[1] == '\\'))) { - cur++; /* skip backslash */ - Buf_AddByte(buf, (Byte)cur[0]); - cur++; + } else if ((vp->ptr[0] == '\\') && + ((vp->ptr[1] == delim) || + (vp->ptr[1] == '$') || + (vp->ptr[1] == '\\'))) { + vp->ptr++; /* consume backslash */ + Buf_AddByte(buf, (Byte)vp->ptr[0]); + vp->ptr++; - } else if (cur[0] == '$') { - if (cur[1] == delim) { + } else if (vp->ptr[0] == '$') { + if (vp->ptr[1] == delim) { /* * Unescaped $ at end of pattern => anchor * pattern at end. */ pattern.flags |= VAR_MATCH_END; - cur++; + vp->ptr++; } else { /* * If unescaped dollar sign not before the @@ -1015,19 +1014,19 @@ modifier_S(VarParser *vp, const char value[], Var *v) Boolean freeIt; len = 0; - cp2 = Var_Parse(cur, vp->ctxt, vp->err, &len, &freeIt); - cur += len; + cp2 = Var_Parse(vp->ptr, vp->ctxt, vp->err, &len, &freeIt); + vp->ptr += len; Buf_Append(buf, cp2); if (freeIt) { free(cp2); } } } else { - Buf_AddByte(buf, (Byte)cur[0]); - cur++; + Buf_AddByte(buf, (Byte)vp->ptr[0]); + vp->ptr++; } } - cur++; /* skip over delim */ + vp->ptr++; /* consume 2nd delim */ /* * Fetch pattern and destroy buffer, but preserve the data in it, @@ -1045,49 +1044,49 @@ modifier_S(VarParser *vp, const char value[], Var *v) */ buf = Buf_Init(0); - while (cur[0] != delim) { - if (cur[0] == '\0') { + while (vp->ptr[0] != delim) { + if (vp->ptr[0] == '\0') { /* * Didn't end with delim character, complain */ Fatal("Unclosed substitution for %s (%c missing)", v->name, delim); - } else if ((cur[0] == '\\') && - ((cur[1] == delim) || - (cur[1] == '&') || - (cur[1] == '\\') || - (cur[1] == '$'))) { - cur++; /* skip backslash */ - Buf_AddByte(buf, (Byte)cur[0]); - cur++; - - } else if (cur[0] == '$') { - if (cur[1] == delim) { - Buf_AddByte(buf, (Byte)cur[0]); - cur++; + } else if ((vp->ptr[0] == '\\') && + ((vp->ptr[1] == delim) || + (vp->ptr[1] == '&') || + (vp->ptr[1] == '\\') || + (vp->ptr[1] == '$'))) { + vp->ptr++; /* skip backslash */ + Buf_AddByte(buf, (Byte)vp->ptr[0]); + vp->ptr++; + + } else if (vp->ptr[0] == '$') { + if (vp->ptr[1] == delim) { + Buf_AddByte(buf, (Byte)vp->ptr[0]); + vp->ptr++; } else { char *cp2; size_t len; Boolean freeIt; len = 0; - cp2 = Var_Parse(cur, vp->ctxt, vp->err, &len, &freeIt); - cur += len; + cp2 = Var_Parse(vp->ptr, vp->ctxt, vp->err, &len, &freeIt); + vp->ptr += len; Buf_Append(buf, cp2); if (freeIt) { free(cp2); } } - } else if (cur[0] == '&') { + } else if (vp->ptr[0] == '&') { Buf_AddBytes(buf, pattern.leftLen, (Byte *)pattern.lhs); - cur++; + vp->ptr++; } else { - Buf_AddByte(buf, (Byte)cur[0]); - cur++; + Buf_AddByte(buf, (Byte)vp->ptr[0]); + vp->ptr++; } } - cur++; /* skip over delim */ + vp->ptr++; /* consume last delim */ pattern.rhs = (char *)Buf_GetAll(buf, &pattern.rightLen); Buf_Destroy(buf, FALSE); @@ -1096,13 +1095,11 @@ modifier_S(VarParser *vp, const char value[], Var *v) * Check for global substitution. If 'g' after the final delimiter, * substitution is global and is marked that way. */ - if (cur[0] == 'g') { + if (vp->ptr[0] == 'g') { pattern.flags |= VAR_SUB_GLOBAL; - cur++; + vp->ptr++; } - vp->ptr += (cur - mod); - /* * Global substitution of the empty string causes an infinite number * of matches, unless anchored by '^' (start of string) or '$' (end @@ -1127,48 +1124,45 @@ modifier_S(VarParser *vp, const char value[], Var *v) static char * modifier_C(VarParser *vp, char value[], Var *v) { - const char *mod = vp->ptr; VarREPattern patt; char delim; char *re; - const char *cur; int error; char *newValue; patt.flags = 0; - delim = mod[1]; /* delimiter between sections */ + vp->ptr++; /* consume 'C' */ - cur = mod + 2; + delim = *vp->ptr; /* delimiter between sections */ - re = VarGetPattern(vp, &cur, delim, NULL, NULL, NULL); + vp->ptr++; /* consume 1st delim */ + + re = VarGetPattern(vp, &vp->ptr, delim, NULL, NULL, NULL); if (re == NULL) { Fatal("Unclosed substitution for %s (%c missing)", v->name, delim); } - patt.replace = VarGetPattern(vp, &cur, delim, NULL, NULL, NULL); + patt.replace = VarGetPattern(vp, &vp->ptr, delim, NULL, NULL, NULL); if (patt.replace == NULL) { Fatal("Unclosed substitution for %s (%c missing)", v->name, delim); } - for (;; cur++) { - switch (*cur) { - case 'g': - patt.flags |= VAR_SUB_GLOBAL; - continue; - case '1': - patt.flags |= VAR_SUB_ONE; - continue; - default: - break; - } + switch (*vp->ptr) { + case 'g': + patt.flags |= VAR_SUB_GLOBAL; + vp->ptr++; /* consume 'g' */ + break; + case '1': + patt.flags |= VAR_SUB_ONE; + vp->ptr++; /* consume '1' */ + break; + default: break; } - vp->ptr += (cur - mod); - error = regcomp(&patt.re, re, REG_EXTENDED); if (error) { VarREError(error, &patt.re, "RE substitution error"); |