Merge struct VarREPattern into struct VarPattern. This will help sorting

out common code.

Patch:		7.156

Submitted by:	Max Okumoto <okumoto@ucsd.edu>
This commit is contained in:
harti 2005-03-22 08:03:42 +00:00
parent 5865566c6d
commit 6218a3c3c1
3 changed files with 12 additions and 15 deletions

View File

@ -982,7 +982,7 @@ modifier_S(VarParser *vp, const char value[], Var *v)
static char *
modifier_C(VarParser *vp, char value[], Var *v)
{
VarREPattern patt;
VarPattern patt;
char delim;
char *re;
int error;
@ -1004,8 +1004,8 @@ modifier_C(VarParser *vp, char value[], Var *v)
vp->ptr++; /* consume 2st delim */
patt.replace = VarGetPattern(vp, delim, NULL, NULL, NULL);
if (patt.replace == NULL) {
patt.rhs = VarGetPattern(vp, delim, NULL, NULL, NULL);
if (patt.rhs == NULL) {
Fatal("Unclosed substitution for %s (%c missing)",
v->name, delim);
}
@ -1028,7 +1028,7 @@ modifier_C(VarParser *vp, char value[], Var *v)
error = regcomp(&patt.re, re, REG_EXTENDED);
if (error) {
VarREError(error, &patt.re, "RE substitution error");
free(patt.replace);
free(patt.rhs);
free(re);
return (var_Error);
}
@ -1044,7 +1044,7 @@ modifier_C(VarParser *vp, char value[], Var *v)
regfree(&patt.re);
free(patt.matches);
free(patt.replace);
free(patt.rhs);
free(re);
return (newValue);

View File

@ -77,17 +77,14 @@ typedef struct {
size_t leftLen; /* Length of string */
char *rhs; /* Replacement string (w/ &'s removed) */
size_t rightLen; /* Length of replacement */
regex_t re;
int nsub;
regmatch_t *matches;
int flags;
} VarPattern;
typedef struct {
regex_t re;
int nsub;
regmatch_t *matches;
char *replace;
int flags;
} VarREPattern;
typedef Boolean VarModifyProc(const char *, Boolean, struct Buffer *, void *);
/*

View File

@ -470,7 +470,7 @@ VarSubstitute(const char *word, Boolean addSpace, Buffer *buf, void *patternp)
Boolean
VarRESubstitute(const char *word, Boolean addSpace, Buffer *buf, void *patternp)
{
VarREPattern *pat;
VarPattern *pat;
int xrv;
const char *wp;
char *rp;
@ -502,7 +502,7 @@ VarRESubstitute(const char *word, Boolean addSpace, Buffer *buf, void *patternp)
Buf_AddBytes(buf, pat->matches[0].rm_so, (const Byte *)wp);
}
for (rp = pat->replace; *rp; rp++) {
for (rp = pat->rhs; *rp; rp++) {
if ((*rp == '\\') && ((rp[1] == '&') || (rp[1] == '\\'))) {
MAYBE_ADD_SPACE();
Buf_AddByte(buf, (Byte)rp[1]);