From 3be279c440b3828ca1a19fe3ea49e663a4968804 Mon Sep 17 00:00:00 2001 From: Max Okumoto Date: Mon, 24 Jan 2005 05:12:58 +0000 Subject: [PATCH] - New function Buf_Append(), which is given a pointer to a string to append to the Buffer object. --- usr.bin/make/buf.c | 11 ++++++++++- usr.bin/make/buf.h | 4 +++- usr.bin/make/cond.c | 10 ++++------ usr.bin/make/for.c | 4 ++-- usr.bin/make/str.c | 4 ++-- usr.bin/make/var.c | 40 +++++++++++++++++---------------------- usr.bin/make/var_modify.c | 22 ++++++++++----------- 7 files changed, 49 insertions(+), 46 deletions(-) diff --git a/usr.bin/make/buf.c b/usr.bin/make/buf.c index b48f5a14d5..e66ccd97fe 100644 --- a/usr.bin/make/buf.c +++ b/usr.bin/make/buf.c @@ -38,7 +38,7 @@ * * @(#)buf.c 8.1 (Berkeley) 6/6/93 * $FreeBSD: src/usr.bin/make/buf.c,v 1.11 1999/09/11 13:08:01 hoek Exp $ - * $DragonFly: src/usr.bin/make/buf.c,v 1.21 2005/01/24 05:07:34 okumoto Exp $ + * $DragonFly: src/usr.bin/make/buf.c,v 1.22 2005/01/24 05:12:58 okumoto Exp $ */ /** @@ -193,3 +193,12 @@ Buf_Clear(Buffer *bp) *bp->inPtr = '\0'; } +/** + * Append characters in str to Buffer object + */ +void +Buf_Append(Buffer *bp, const char str[]) +{ + Buf_AddBytes(bp, strlen(str), str); +} + diff --git a/usr.bin/make/buf.h b/usr.bin/make/buf.h index cec325b0ab..69f074e35e 100644 --- a/usr.bin/make/buf.h +++ b/usr.bin/make/buf.h @@ -40,7 +40,7 @@ * * from: @(#)buf.h 8.1 (Berkeley) 6/6/93 * $FreeBSD: src/usr.bin/make/buf.h,v 1.9 1999/08/28 01:03:26 peter Exp $ - * $DragonFly: src/usr.bin/make/buf.h,v 1.17 2005/01/24 05:07:34 okumoto Exp $ + * $DragonFly: src/usr.bin/make/buf.h,v 1.18 2005/01/24 05:12:58 okumoto Exp $ */ /*- @@ -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 675bebf7e4..9769798ac6 100644 --- a/usr.bin/make/cond.c +++ b/usr.bin/make/cond.c @@ -38,7 +38,7 @@ * * @(#)cond.c 8.2 (Berkeley) 1/2/94 * $FreeBSD: src/usr.bin/make/cond.c,v 1.12.2.1 2003/07/22 08:03:13 ru Exp $ - * $DragonFly: src/usr.bin/make/cond.c,v 1.23 2005/01/24 05:09:30 okumoto Exp $ + * $DragonFly: src/usr.bin/make/cond.c,v 1.24 2005/01/24 05:12:58 okumoto Exp $ */ /*- @@ -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); } @@ -539,12 +539,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); @@ -635,7 +633,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 6e942b5bb5..2e1f70115c 100644 --- a/usr.bin/make/for.c +++ b/usr.bin/make/for.c @@ -35,7 +35,7 @@ * * @(#)for.c 8.1 (Berkeley) 6/6/93 * $FreeBSD: src/usr.bin/make/for.c,v 1.10 1999/09/11 13:08:01 hoek Exp $ - * $DragonFly: src/usr.bin/make/for.c,v 1.21 2005/01/24 05:11:01 okumoto Exp $ + * $DragonFly: src/usr.bin/make/for.c,v 1.22 2005/01/24 05:12:58 okumoto Exp $ */ /*- @@ -227,7 +227,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 18132b3b39..398f4bb706 100644 --- a/usr.bin/make/str.c +++ b/usr.bin/make/str.c @@ -37,7 +37,7 @@ * * @(#)str.c 5.8 (Berkeley) 6/1/90 * $FreeBSD: src/usr.bin/make/str.c,v 1.12.2.2 2004/02/23 12:10:57 ru Exp $ - * $DragonFly: src/usr.bin/make/str.c,v 1.16 2005/01/06 13:18:58 okumoto Exp $ + * $DragonFly: src/usr.bin/make/str.c,v 1.17 2005/01/24 05:12:58 okumoto Exp $ */ #include @@ -422,5 +422,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 1674a49b44..1e6763eb98 100644 --- a/usr.bin/make/var.c +++ b/usr.bin/make/var.c @@ -37,7 +37,7 @@ * * @(#)var.c 8.3 (Berkeley) 3/19/94 * $FreeBSD: src/usr.bin/make/var.c,v 1.16.2.3 2002/02/27 14:18:57 cjc Exp $ - * $DragonFly: src/usr.bin/make/var.c,v 1.41 2005/01/24 05:09:30 okumoto Exp $ + * $DragonFly: src/usr.bin/make/var.c,v 1.42 2005/01/24 05:12:58 okumoto Exp $ */ /*- @@ -277,17 +277,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)) @@ -326,18 +322,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)); } @@ -428,7 +422,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)); } @@ -496,7 +490,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))); @@ -650,7 +644,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); @@ -733,7 +727,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; @@ -961,7 +955,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, size_t *lengthPtr, Boolean *freeP 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); } @@ -1268,7 +1262,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, size_t *lengthPtr, Boolean *freeP 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 *freeP 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); @@ -1859,7 +1853,7 @@ Var_Subst(const char *var, const 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 e53c485b87..9c198cca01 100644 --- a/usr.bin/make/var_modify.c +++ b/usr.bin/make/var_modify.c @@ -37,7 +37,7 @@ * * @(#)var.c 8.3 (Berkeley) 3/19/94 * $FreeBSD: src/usr.bin/make/var.c,v 1.16.2.3 2002/02/27 14:18:57 cjc Exp $ - * $DragonFly: src/usr.bin/make/Attic/var_modify.c,v 1.14 2005/01/08 22:27:02 okumoto Exp $ + * $DragonFly: src/usr.bin/make/Attic/var_modify.c,v 1.15 2005/01/24 05:12:58 okumoto Exp $ */ #include @@ -81,7 +81,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)'.'); } @@ -116,9 +116,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); } @@ -148,7 +148,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); @@ -182,7 +182,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); } @@ -213,7 +213,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); } @@ -250,7 +250,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); } @@ -282,7 +282,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); } @@ -562,7 +562,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: @@ -571,7 +571,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; } -- 2.41.0