diff options
author | harti <harti@FreeBSD.org> | 2005-02-07 07:49:16 +0000 |
---|---|---|
committer | harti <harti@FreeBSD.org> | 2005-02-07 07:49:16 +0000 |
commit | c45831f7c65accf983e86b1f1a883f20c27133e0 (patch) | |
tree | 66fb0e86c2921f8ecff474aa405874087d374906 /usr.bin | |
parent | d2bbb620e902ad472a90d5c5d1fc3286b192a0a2 (diff) | |
download | FreeBSD-src-c45831f7c65accf983e86b1f1a883f20c27133e0.zip FreeBSD-src-c45831f7c65accf983e86b1f1a883f20c27133e0.tar.gz |
Invent a Buf_Append function to append a NUL-terminated string
and use it thoughout the code.
Submitted by: Max Okumoto <okumoto@ucsd.edu>
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/make/buf.c | 10 | ||||
-rw-r--r-- | usr.bin/make/buf.h | 2 | ||||
-rw-r--r-- | usr.bin/make/cond.c | 8 | ||||
-rw-r--r-- | usr.bin/make/for.c | 2 | ||||
-rw-r--r-- | usr.bin/make/str.c | 2 | ||||
-rw-r--r-- | usr.bin/make/var.c | 38 | ||||
-rw-r--r-- | usr.bin/make/var_modify.c | 20 |
7 files changed, 43 insertions, 39 deletions
diff --git a/usr.bin/make/buf.c b/usr.bin/make/buf.c index 3327c7f..738f92a 100644 --- a/usr.bin/make/buf.c +++ b/usr.bin/make/buf.c @@ -194,6 +194,16 @@ Buf_ReplaceLastByte(Buffer *bp, Byte byte) } /** + * Append characters in str to Buffer object + */ +void +Buf_Append(Buffer *bp, const char str[]) +{ + + Buf_AddBytes(bp, strlen(str), str); +} + +/** * Clear the contents of the buffer. */ void diff --git a/usr.bin/make/buf.h b/usr.bin/make/buf.h index fc6c409..f209a65 100644 --- a/usr.bin/make/buf.h +++ b/usr.bin/make/buf.h @@ -83,4 +83,6 @@ Buffer *Buf_Init(size_t); void Buf_Destroy(Buffer *, Boolean); void Buf_ReplaceLastByte(Buffer *, Byte); +void Buf_Append(Buffer *, const char []); + #endif /* buf_h_a61a6812 */ diff --git a/usr.bin/make/cond.c b/usr.bin/make/cond.c index f188769..4f6f66a 100644 --- a/usr.bin/make/cond.c +++ b/usr.bin/make/cond.c @@ -239,7 +239,7 @@ CondGetArg(char **linePtr, char **argPtr, const char *func, Boolean parens) cp2 = Var_Parse(cp, VAR_CMD, TRUE, &len, &doFree); - Buf_AddBytes(buf, strlen(cp2), (Byte *)cp2); + Buf_Append(buf, cp2); if (doFree) { free(cp2); } @@ -540,12 +540,10 @@ CondToken(Boolean doEval) if (!isspace((unsigned char)*condExpr) && strchr("!=><", *condExpr) == NULL) { Buffer *buf; - char *cp; buf = Buf_Init(0); - for (cp = lhs; *cp; cp++) - Buf_AddByte(buf, (Byte)*cp); + Buf_Append(buf, lhs); if (doFree) free(lhs); @@ -637,7 +635,7 @@ do_string_compare: cp2 = Var_Parse(cp, VAR_CMD, doEval, &len, &freeIt); if (cp2 != var_Error) { - Buf_AddBytes(buf, strlen(cp2), (Byte *)cp2); + Buf_Append(buf, cp2); if (freeIt) { free(cp2); } diff --git a/usr.bin/make/for.c b/usr.bin/make/for.c index 2c0ec05..b389062 100644 --- a/usr.bin/make/for.c +++ b/usr.bin/make/for.c @@ -226,7 +226,7 @@ For_Eval(char *line) } if (forLevel != 0) { - Buf_AddBytes(forBuf, strlen(line), (Byte *)line); + Buf_Append(forBuf, line); Buf_AddByte(forBuf, (Byte)'\n'); return (1); } diff --git a/usr.bin/make/str.c b/usr.bin/make/str.c index c0eac138..52cb9cc 100644 --- a/usr.bin/make/str.c +++ b/usr.bin/make/str.c @@ -524,5 +524,5 @@ Str_SYSVSubst(Buffer *buf, const char *pat, const char *src, int len) Buf_AddBytes(buf, len, (const Byte *)src); /* append the rest */ - Buf_AddBytes(buf, strlen(pat), (const Byte *)pat); + Buf_Append(buf, pat); } diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c index 10680ae..d2f66a8 100644 --- a/usr.bin/make/var.c +++ b/usr.bin/make/var.c @@ -286,17 +286,13 @@ VarFind(const char *name, GNode *ctxt, int flags) char *env; if ((env = getenv(name)) != NULL) { - int len; - v = emalloc(sizeof(Var)); v->name = estrdup(name); + v->val = Buf_Init(0); + v->flags = VAR_FROM_ENV; - len = strlen(env); - - v->val = Buf_Init(len); - Buf_AddBytes(v->val, len, (Byte *)env); + Buf_Append(v->val, env); - v->flags = VAR_FROM_ENV; return (v); } else if ((checkEnvFirst || localCheckEnvFirst) && (flags & FIND_GLOBAL) && (ctxt != VAR_GLOBAL)) @@ -335,18 +331,16 @@ static void VarAdd(const char *name, const char *val, GNode *ctxt) { Var *v; - int len; v = emalloc(sizeof(Var)); - v->name = estrdup(name); - - len = val ? strlen(val) : 0; - v->val = Buf_Init(len+1); - Buf_AddBytes(v->val, len, (const Byte *)val); - + v->val = Buf_Init(0); v->flags = 0; + if (val != NULL) { + Buf_Append(v->val, val); + } + Lst_AtFront(&ctxt->context, v); DEBUGF(VAR, ("%s:%s = %s\n", ctxt->name, name, val)); } @@ -437,7 +431,7 @@ Var_Set(const char *name, const char *val, GNode *ctxt) VarAdd(n, val, ctxt); } else { Buf_Clear(v->val); - Buf_AddBytes(v->val, strlen(val), (const Byte *)val); + Buf_Append(v->val, val); DEBUGF(VAR, ("%s:%s = %s\n", ctxt->name, n, val)); } @@ -486,7 +480,7 @@ Var_Append(const char *name, const char *val, GNode *ctxt) VarAdd(n, val, ctxt); } else { Buf_AddByte(v->val, (Byte)' '); - Buf_AddBytes(v->val, strlen(val), (const Byte *)val); + Buf_Append(v->val, val); DEBUGF(VAR, ("%s:%s = %s\n", ctxt->name, n, (char *)Buf_GetAll(v->val, (size_t *)NULL))); @@ -642,7 +636,7 @@ VarSortWords(char *str, int (*cmp)(const void *, const void *)) av = brk_string(str, &ac, FALSE); qsort(av + 1, ac - 1, sizeof(char *), cmp); for (i = 1; i < ac; i++) { - Buf_AddBytes(buf, strlen(av[i]), (Byte *)av[i]); + Buf_Append(buf, av[i]); Buf_AddByte(buf, (Byte)((i < ac - 1) ? ' ' : '\0')); } str = (char *)Buf_GetAll(buf, (size_t *)NULL); @@ -726,7 +720,7 @@ VarGetPattern(GNode *ctxt, int err, char **tstr, int delim, int *flags, * substitution and recurse. */ cp2 = Var_Parse(cp, ctxt, err, &len, &freeIt); - Buf_AddBytes(buf, strlen(cp2), (Byte *)cp2); + Buf_Append(buf, cp2); if (freeIt) free(cp2); cp += len - 1; @@ -958,7 +952,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, size_t *lengthPtr, if (rval == var_Error) { Fatal("Error expanding embedded variable."); } else if (rval != NULL) { - Buf_AddBytes(buf, strlen(rval), (Byte *)rval); + Buf_Append(buf, rval); if (rfree) free(rval); } @@ -1266,7 +1260,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, size_t *lengthPtr, Boolean freeIt; cp2 = Var_Parse(cp, ctxt, err, &len, &freeIt); - Buf_AddBytes(buf, strlen(cp2), (Byte *)cp2); + Buf_Append(buf, cp2); if (freeIt) { free(cp2); } @@ -1330,7 +1324,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, size_t *lengthPtr, Boolean freeIt; cp2 = Var_Parse(cp, ctxt, err, &len, &freeIt); - Buf_AddBytes(buf, strlen(cp2), (Byte *)cp2); + Buf_Append(buf, cp2); cp += len - 1; if (freeIt) { free(cp2); @@ -1862,7 +1856,7 @@ Var_Subst(const char *var, char *str, GNode *ctxt, Boolean undefErr) * Copy all the characters from the variable value straight * into the new string. */ - Buf_AddBytes(buf, strlen(val), (Byte *)val); + Buf_Append(buf, val); if (doFree) { free(val); } diff --git a/usr.bin/make/var_modify.c b/usr.bin/make/var_modify.c index 7ed0e7a..2d35a0a 100644 --- a/usr.bin/make/var_modify.c +++ b/usr.bin/make/var_modify.c @@ -83,7 +83,7 @@ VarHead(const char *word, Boolean addSpace, Buffer *buf, void *dummy __unused) * If no directory part, give . (q.v. the POSIX standard) */ if (addSpace) { - Buf_AddBytes(buf, 2, (const Byte *)" ."); + Buf_Append(buf, " ."); } else { Buf_AddByte(buf, (Byte)'.'); } @@ -118,9 +118,9 @@ VarTail(const char *word, Boolean addSpace, Buffer *buf, void *dummy __unused) slash = strrchr(word, '/'); if (slash != NULL) { slash++; - Buf_AddBytes(buf, strlen(slash), (const Byte *)slash); + Buf_Append(buf, slash); } else { - Buf_AddBytes(buf, strlen(word), (const Byte *)word); + Buf_Append(buf, word); } return (TRUE); } @@ -150,7 +150,7 @@ VarSuffix(const char *word, Boolean addSpace, Buffer *buf, void *dummy __unused) Buf_AddByte(buf, (Byte)' '); } dot++; - Buf_AddBytes(buf, strlen(dot), (const Byte *)dot); + Buf_Append(buf, dot); addSpace = TRUE; } return (addSpace); @@ -184,7 +184,7 @@ VarRoot(const char *word, Boolean addSpace, Buffer *buf, void *dummy __unused) if (dot != NULL) { Buf_AddBytes(buf, dot - word, (const Byte *)word); } else { - Buf_AddBytes(buf, strlen(word), (const Byte *)word); + Buf_Append(buf, word); } return (TRUE); } @@ -215,7 +215,7 @@ VarMatch(const char *word, Boolean addSpace, Buffer *buf, void *pattern) Buf_AddByte(buf, (Byte)' '); } addSpace = TRUE; - Buf_AddBytes(buf, strlen(word), word); + Buf_Append(buf, word); } return (addSpace); } @@ -252,7 +252,7 @@ VarSYSVMatch(const char *word, Boolean addSpace, Buffer *buf, void *patp) if ((ptr = Str_SYSVMatch(word, pat->lhs, &len)) != NULL) Str_SYSVSubst(buf, pat->rhs, ptr, len); else - Buf_AddBytes(buf, strlen(word), (const Byte *)word); + Buf_Append(buf, word); return (addSpace); } @@ -284,7 +284,7 @@ VarNoMatch(const char *word, Boolean addSpace, Buffer *buf, void *pattern) Buf_AddByte(buf, (Byte)' '); } addSpace = TRUE; - Buf_AddBytes(buf, strlen(word), (const Byte *)word); + Buf_Append(buf, word); } return (addSpace); } @@ -564,7 +564,7 @@ VarRESubstitute(const char *word, Boolean addSpace, Buffer *buf, void *patternp) } if (*wp) { MAYBE_ADD_SPACE(); - Buf_AddBytes(buf, strlen(wp), (const Byte *)wp); + Buf_Append(buf, wp); } break; default: @@ -573,7 +573,7 @@ VarRESubstitute(const char *word, Boolean addSpace, Buffer *buf, void *patternp) case REG_NOMATCH: if (*wp) { MAYBE_ADD_SPACE(); - Buf_AddBytes(buf, strlen(wp), (const Byte *)wp); + Buf_Append(buf, wp); } break; } |