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>
This commit is contained in:
harti 2005-02-07 07:54:23 +00:00
parent c9d99643c7
commit efc7c63e63
6 changed files with 22 additions and 12 deletions

View File

@ -203,6 +203,15 @@ Buf_Append(Buffer *bp, const char str[])
Buf_AddBytes(bp, strlen(str), 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.
*/

View File

@ -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 */

View File

@ -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);

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;