summaryrefslogtreecommitdiffstats
path: root/usr.bin/make
diff options
context:
space:
mode:
authorharti <harti@FreeBSD.org>2005-02-07 07:54:23 +0000
committerharti <harti@FreeBSD.org>2005-02-07 07:54:23 +0000
commit92a5e4fdd6e689f9a8570f20066b1db264ded799 (patch)
tree5139321e24b73eb766d0d1666c28d2d79a8abd00 /usr.bin/make
parentc45831f7c65accf983e86b1f1a883f20c27133e0 (diff)
downloadFreeBSD-src-92a5e4fdd6e689f9a8570f20066b1db264ded799.zip
FreeBSD-src-92a5e4fdd6e689f9a8570f20066b1db264ded799.tar.gz
Invent a Buf_AppendRange function that appends a non-NUL-terminated string
given by a pointer to the start of the string and a pointer one behind the end. Submitted by: Max Okumoto <okumoto@ucsd.edu>
Diffstat (limited to 'usr.bin/make')
-rw-r--r--usr.bin/make/buf.c9
-rw-r--r--usr.bin/make/buf.h1
-rw-r--r--usr.bin/make/for.c6
-rw-r--r--usr.bin/make/str.c2
-rw-r--r--usr.bin/make/var.c8
-rw-r--r--usr.bin/make/var_modify.c8
6 files changed, 22 insertions, 12 deletions
diff --git a/usr.bin/make/buf.c b/usr.bin/make/buf.c
index 738f92a..b3748f0 100644
--- a/usr.bin/make/buf.c
+++ b/usr.bin/make/buf.c
@@ -204,6 +204,15 @@ Buf_Append(Buffer *bp, const char str[])
}
/**
+ * Append characters between str and end to Buffer object.
+ */
+void
+Buf_AppendRange(Buffer *bp, const char str[], const char *end)
+{
+ Buf_AddBytes(bp, end - str, str);
+}
+
+/**
* Clear the contents of the buffer.
*/
void
diff --git a/usr.bin/make/buf.h b/usr.bin/make/buf.h
index f209a65..bc669ed 100644
--- a/usr.bin/make/buf.h
+++ b/usr.bin/make/buf.h
@@ -84,5 +84,6 @@ void Buf_Destroy(Buffer *, Boolean);
void Buf_ReplaceLastByte(Buffer *, Byte);
void Buf_Append(Buffer *, const char []);
+void Buf_AppendRange(Buffer *, const char [], const char *);
#endif /* buf_h_a61a6812 */
diff --git a/usr.bin/make/for.c b/usr.bin/make/for.c
index b389062..d254e2e 100644
--- a/usr.bin/make/for.c
+++ b/usr.bin/make/for.c
@@ -143,7 +143,7 @@ For_Eval(char *line)
buf = Buf_Init(0);
for (wrd = ptr; *ptr && !isspace((unsigned char)*ptr); ptr++)
continue;
- Buf_AddBytes(buf, ptr - wrd, (Byte *)wrd);
+ Buf_AppendRange(buf, wrd, ptr);
forVar = (char *)Buf_GetAll(buf, &varlen);
if (varlen == 0) {
@@ -181,7 +181,7 @@ For_Eval(char *line)
for (wrd = ptr; *ptr; ptr++)
if (isspace((unsigned char)*ptr)) {
- Buf_AddBytes(buf, ptr - wrd, (Byte *)wrd);
+ Buf_AppendRange(buf, wrd, ptr);
Buf_AddByte(buf, (Byte)'\0');
Lst_AtFront(&forLst, Buf_GetAll(buf, &varlen));
Buf_Destroy(buf, FALSE);
@@ -192,7 +192,7 @@ For_Eval(char *line)
}
DEBUGF(FOR, ("For: Iterator %s List %s\n", forVar, sub));
if (ptr - wrd > 0) {
- Buf_AddBytes(buf, ptr - wrd, (Byte *)wrd);
+ Buf_AppendRange(buf, wrd, ptr);
Buf_AddByte(buf, (Byte)'\0');
Lst_AtFront(&forLst, Buf_GetAll(buf, &varlen));
Buf_Destroy(buf, FALSE);
diff --git a/usr.bin/make/str.c b/usr.bin/make/str.c
index 52cb9cc..68cec0c 100644
--- a/usr.bin/make/str.c
+++ b/usr.bin/make/str.c
@@ -515,7 +515,7 @@ Str_SYSVSubst(Buffer *buf, const char *pat, const char *src, int len)
if ((m = strchr(pat, '%')) != NULL) {
/* Copy the prefix */
- Buf_AddBytes(buf, m - pat, (const Byte *)pat);
+ Buf_AppendRange(buf, pat, m);
/* skip the % */
pat = m + 1;
}
diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c
index d2f66a8..c9b1d7a 100644
--- a/usr.bin/make/var.c
+++ b/usr.bin/make/var.c
@@ -745,7 +745,7 @@ VarGetPattern(GNode *ctxt, int err, char **tstr, int delim, int *flags,
--depth;
}
}
- Buf_AddBytes(buf, cp2 - cp, (Byte *)cp);
+ Buf_AppendRange(buf, cp, cp2);
cp = --cp2;
} else
Buf_AddByte(buf, (Byte)*cp);
@@ -1757,7 +1757,7 @@ Var_Subst(const char *var, char *str, GNode *ctxt, Boolean undefErr)
for (cp = str++; *str != '$' && *str != '\0'; str++)
continue;
- Buf_AddBytes(buf, str - cp, (const Byte *)cp);
+ Buf_AppendRange(buf, cp, str);
} else {
if (var != NULL) {
int expand;
@@ -1786,7 +1786,7 @@ Var_Subst(const char *var, char *str, GNode *ctxt, Boolean undefErr)
* the nested one
*/
if (*p == '$') {
- Buf_AddBytes(buf, p - str, (const Byte *)str);
+ Buf_AppendRange(buf, str, p);
str = p;
continue;
}
@@ -1799,7 +1799,7 @@ Var_Subst(const char *var, char *str, GNode *ctxt, Boolean undefErr)
*/
for (;*p != '$' && *p != '\0'; p++)
continue;
- Buf_AddBytes(buf, p - str, (Byte *)str);
+ Buf_AppendRange(buf, str, p);
str = p;
expand = FALSE;
}
diff --git a/usr.bin/make/var_modify.c b/usr.bin/make/var_modify.c
index 2d35a0a..2920ada 100644
--- a/usr.bin/make/var_modify.c
+++ b/usr.bin/make/var_modify.c
@@ -77,7 +77,7 @@ VarHead(const char *word, Boolean addSpace, Buffer *buf, void *dummy __unused)
if (addSpace) {
Buf_AddByte(buf, (Byte)' ');
}
- Buf_AddBytes(buf, slash - word, (const Byte *)word);
+ Buf_AppendRange(buf, word, slash);
} else {
/*
* If no directory part, give . (q.v. the POSIX standard)
@@ -182,7 +182,7 @@ VarRoot(const char *word, Boolean addSpace, Buffer *buf, void *dummy __unused)
dot = strrchr(word, '.');
if (dot != NULL) {
- Buf_AddBytes(buf, dot - word, (const Byte *)word);
+ Buf_AppendRange(buf, word, dot);
} else {
Buf_Append(buf, word);
}
@@ -383,7 +383,7 @@ VarSubstitute(const char *word, Boolean addSpace, Buffer *buf, void *patternp)
}
addSpace = TRUE;
}
- Buf_AddBytes(buf, cp - word, (const Byte *)word);
+ Buf_AppendRange(buf, word, cp);
Buf_AddBytes(buf, pattern->rightLen, (Byte *)pattern->rhs);
} else {
/*
@@ -415,7 +415,7 @@ VarSubstitute(const char *word, Boolean addSpace, Buffer *buf, void *patternp)
Buf_AddByte(buf, (Byte)' ');
addSpace = FALSE;
}
- Buf_AddBytes(buf, cp-word, (const Byte *)word);
+ Buf_AppendRange(buf, word, cp);
Buf_AddBytes(buf, pattern->rightLen, (Byte *)pattern->rhs);
wordLen -= (cp - word) + pattern->leftLen;
word = cp + pattern->leftLen;
OpenPOWER on IntegriCloud