mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-28 16:43:09 +00:00
Simplify buffer access by using Buf_Data() and Buf_Peel() where
appropriate. Patch: 7.147-7.151 Submitted by: Max Okumoto <okumoto@ucsd.edu>
This commit is contained in:
parent
73d1906810
commit
4896df6314
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=143959
@ -189,11 +189,7 @@ Arch_ParseArchive(char **linePtr, Lst *nodeLst, GNode *ctxt)
|
||||
|
||||
*cp++ = '\0';
|
||||
if (subLibName) {
|
||||
Buffer *buf;
|
||||
|
||||
buf = Var_Subst(NULL, libName, ctxt, TRUE);
|
||||
libName = Buf_GetAll(buf, NULL);
|
||||
Buf_Destroy(buf, FALSE);
|
||||
libName = Buf_Peel(Var_Subst(NULL, libName, ctxt, TRUE));
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
@ -291,7 +287,7 @@ Arch_ParseArchive(char **linePtr, Lst *nodeLst, GNode *ctxt)
|
||||
* nodeLst we're returning.
|
||||
*/
|
||||
buf1 = Var_Subst(NULL, memName, ctxt, TRUE);
|
||||
memName = Buf_GetAll(buf1, NULL);
|
||||
memName = Buf_Data(buf1);
|
||||
|
||||
sz = strlen(memName) + strlen(libName) + 3;
|
||||
buf = emalloc(sz);
|
||||
|
@ -630,10 +630,7 @@ CondToken(Boolean doEval)
|
||||
}
|
||||
}
|
||||
|
||||
Buf_AddByte(buf, (Byte)0);
|
||||
|
||||
string = (char *)Buf_GetAll(buf, (size_t *)NULL);
|
||||
Buf_Destroy(buf, FALSE);
|
||||
string = Buf_Peel(buf);
|
||||
|
||||
DEBUGF(COND, ("lhs = \"%s\", rhs = \"%s\", op = %.2s\n",
|
||||
lhs, string, op));
|
||||
|
@ -273,7 +273,7 @@ For_Run(int lineno)
|
||||
Var_Set(var, val, VAR_GLOBAL);
|
||||
|
||||
DEBUGF(FOR, ("--- %s = %s\n", var, val));
|
||||
str = Buf_Peel(Var_Subst(var, (char *)Buf_GetAll(buf, NULL),
|
||||
str = Buf_Peel(Var_Subst(var, Buf_Data(buf),
|
||||
VAR_GLOBAL, FALSE));
|
||||
|
||||
Parse_FromString(str, lineno);
|
||||
|
@ -463,7 +463,6 @@ JobPrintCommand(void *cmdp, void *jobp)
|
||||
LstNode *cmdNode; /* Node for replacing the command */
|
||||
char *cmd = cmdp;
|
||||
Job *job = jobp;
|
||||
Buffer *buf;
|
||||
|
||||
noSpecials = (noExecute && !(job->node->type & OP_MAKE));
|
||||
|
||||
@ -489,9 +488,7 @@ JobPrintCommand(void *cmdp, void *jobp)
|
||||
*/
|
||||
cmdNode = Lst_Member(&job->node->commands, cmd);
|
||||
|
||||
buf = Var_Subst(NULL, cmd, job->node, FALSE);
|
||||
cmd = Buf_GetAll(buf, NULL);
|
||||
Buf_Destroy(buf, FALSE);
|
||||
cmd = Buf_Peel(Var_Subst(NULL, cmd, job->node, FALSE));
|
||||
cmdStart = cmd;
|
||||
|
||||
Lst_Replace(cmdNode, cmdStart);
|
||||
|
@ -824,7 +824,7 @@ main(int argc, char **argv)
|
||||
|
||||
buf = Var_Subst(NULL, VPATH, VAR_CMD, FALSE);
|
||||
|
||||
vpath = Buf_GetAll(buf, NULL);
|
||||
vpath = Buf_Data(buf);
|
||||
do {
|
||||
/* skip to end of directory */
|
||||
for (ptr = vpath; *ptr != ':' && *ptr != '\0'; ptr++)
|
||||
|
@ -1237,8 +1237,6 @@ Parse_DoVar(char *line, GNode *ctxt)
|
||||
} type; /* Type of assignment */
|
||||
char *opc; /* ptr to operator character to
|
||||
* null-terminate the variable name */
|
||||
Buffer *buf;
|
||||
|
||||
/*
|
||||
* Avoid clobbered variable warnings by forcing the compiler
|
||||
* to ``unregister'' variables
|
||||
@ -1344,9 +1342,7 @@ Parse_DoVar(char *line, GNode *ctxt)
|
||||
if (!Var_Exists(line, ctxt))
|
||||
Var_Set(line, "", ctxt);
|
||||
|
||||
buf = Var_Subst(NULL, cp, ctxt, FALSE);
|
||||
cp = Buf_GetAll(buf, NULL);
|
||||
Buf_Destroy(buf, FALSE);
|
||||
cp = Buf_Peel(Var_Subst(NULL, cp, ctxt, FALSE));
|
||||
|
||||
oldVars = oldOldVars;
|
||||
|
||||
@ -1364,14 +1360,12 @@ Parse_DoVar(char *line, GNode *ctxt)
|
||||
* expansion on the whole thing. The resulting string will need
|
||||
* freeing when we're done, so set freeCmd to TRUE.
|
||||
*/
|
||||
buf = Var_Subst(NULL, cp, VAR_CMD, TRUE);
|
||||
cp = Buf_GetAll(buf, NULL);
|
||||
Buf_Destroy(buf, FALSE);
|
||||
cp = Buf_Peel(Var_Subst(NULL, cp, VAR_CMD, TRUE));
|
||||
freeCmd = TRUE;
|
||||
}
|
||||
|
||||
buf = Cmd_Exec(cp, &error);
|
||||
Var_Set(line, Buf_GetAll(buf, NULL), ctxt);
|
||||
Var_Set(line, Buf_Data(buf), ctxt);
|
||||
Buf_Destroy(buf, TRUE);
|
||||
|
||||
if (error)
|
||||
@ -1458,9 +1452,7 @@ ParseDoError(char *errmsg)
|
||||
errmsg++;
|
||||
|
||||
buf = Var_Subst(NULL, errmsg, VAR_GLOBAL, FALSE);
|
||||
errmsg = Buf_GetAll(buf, NULL);
|
||||
|
||||
Parse_Error(PARSE_FATAL, "%s", errmsg);
|
||||
Parse_Error(PARSE_FATAL, "%s", Buf_Data(buf));
|
||||
Buf_Destroy(buf, TRUE);
|
||||
|
||||
/* Terminate immediately. */
|
||||
@ -1492,9 +1484,7 @@ ParseDoWarning(char *warnmsg)
|
||||
warnmsg++;
|
||||
|
||||
buf = Var_Subst(NULL, warnmsg, VAR_GLOBAL, FALSE);
|
||||
warnmsg = Buf_GetAll(buf, NULL);
|
||||
|
||||
Parse_Error(PARSE_WARNING, "%s", warnmsg);
|
||||
Parse_Error(PARSE_WARNING, "%s", Buf_Data(buf));
|
||||
Buf_Destroy(buf, TRUE);
|
||||
}
|
||||
|
||||
@ -1572,8 +1562,7 @@ ParseDoInclude(char *file)
|
||||
* find the thing.
|
||||
*/
|
||||
buf = Var_Subst(NULL, file, VAR_CMD, FALSE);
|
||||
file = Buf_GetAll(buf, NULL);
|
||||
Buf_Destroy(buf, FALSE);
|
||||
file = Buf_Peel(buf);
|
||||
|
||||
/*
|
||||
* Now we know the file's name and its search path, we attempt to
|
||||
@ -1764,8 +1753,7 @@ ParseTraditionalInclude(char *file)
|
||||
* find the thing.
|
||||
*/
|
||||
buf = Var_Subst(NULL, file, VAR_CMD, FALSE);
|
||||
file = Buf_GetAll(buf, NULL);
|
||||
Buf_Destroy(buf, FALSE);
|
||||
file = Buf_Peel(buf);
|
||||
|
||||
/*
|
||||
* Now we know the file's name, we attempt to find the durn thing.
|
||||
@ -1971,7 +1959,7 @@ ParseSkipLine(int skip, int keep_newline)
|
||||
|
||||
curFile.lineno++;
|
||||
Buf_AddByte(buf, (Byte)'\0');
|
||||
line = (char *)Buf_GetAll(buf, NULL);
|
||||
line = Buf_Data(buf);
|
||||
} while (skip == 1 && line[0] != '.');
|
||||
|
||||
Buf_Destroy(buf, FALSE);
|
||||
@ -2167,8 +2155,7 @@ ParseReadLine(void)
|
||||
Buf_AddByte(buf, (Byte)lastc);
|
||||
}
|
||||
Buf_AddByte(buf, (Byte)'\0');
|
||||
line = (char *)Buf_GetAll(buf, NULL);
|
||||
Buf_Destroy(buf, FALSE);
|
||||
line = Buf_Peel(buf);
|
||||
|
||||
/*
|
||||
* Strip trailing blanks and tabs from the line.
|
||||
@ -2336,8 +2323,7 @@ Parse_File(char *name, FILE *stream)
|
||||
*cp2 = '\0';
|
||||
|
||||
buf = Var_Subst(NULL, cp, VAR_CMD, FALSE);
|
||||
cp = Buf_GetAll(buf, NULL);
|
||||
Buf_Destroy(buf, FALSE);
|
||||
cp = Buf_Peel(buf);
|
||||
|
||||
Var_Delete(cp, VAR_GLOBAL);
|
||||
goto nextLine;
|
||||
@ -2420,8 +2406,7 @@ Parse_File(char *name, FILE *stream)
|
||||
ParseFinishLine();
|
||||
|
||||
buf = Var_Subst(NULL, line, VAR_CMD, TRUE);
|
||||
cp = Buf_GetAll(buf, NULL);
|
||||
Buf_Destroy(buf, FALSE);
|
||||
cp = Buf_Peel(buf);
|
||||
|
||||
free(line);
|
||||
line = cp;
|
||||
|
@ -1160,7 +1160,7 @@ SuffExpandVariables(GNode *parent, GNode *child, Lst *members)
|
||||
|
||||
DEBUGF(SUFF, ("Expanding \"%s\"...", child->name));
|
||||
buf = Var_Subst(NULL, child->name, parent, TRUE);
|
||||
cp = Buf_GetAll(buf, NULL);
|
||||
cp = Buf_Data(buf);
|
||||
|
||||
if (child->type & OP_ARCHV) {
|
||||
/*
|
||||
|
@ -229,14 +229,10 @@ static char *
|
||||
VarPossiblyExpand(const char *name, GNode *ctxt)
|
||||
{
|
||||
Buffer *buf;
|
||||
char *str;
|
||||
|
||||
if (strchr(name, '$') != NULL) {
|
||||
buf = Var_Subst(NULL, name, ctxt, 0);
|
||||
str = Buf_GetAll(buf, NULL);
|
||||
Buf_Destroy(buf, FALSE);
|
||||
|
||||
return (str);
|
||||
return (Buf_Peel(buf));
|
||||
} else {
|
||||
return estrdup(name);
|
||||
}
|
||||
@ -500,8 +496,7 @@ Var_Append(const char *name, const char *val, GNode *ctxt)
|
||||
Buf_AddByte(v->val, (Byte)' ');
|
||||
Buf_Append(v->val, val);
|
||||
|
||||
DEBUGF(VAR, ("%s:%s = %s\n", ctxt->name, n,
|
||||
(char *)Buf_GetAll(v->val, (size_t *)NULL)));
|
||||
DEBUGF(VAR, ("%s:%s = %s\n", ctxt->name, n, Buf_Data(v->val)));
|
||||
|
||||
if (v->flags & VAR_FROM_ENV) {
|
||||
/*
|
||||
@ -572,7 +567,7 @@ Var_Value(const char *name, GNode *ctxt, char **frp)
|
||||
free(n);
|
||||
*frp = NULL;
|
||||
if (v != NULL) {
|
||||
char *p = (char *)Buf_GetAll(v->val, (size_t *)NULL);
|
||||
char *p = Buf_Data(v->val);
|
||||
|
||||
if (v->flags & VAR_FROM_ENV) {
|
||||
VarDestroy(v, FALSE);
|
||||
@ -608,7 +603,6 @@ VarModify(const char *str, VarModifyProc *modProc, void *datum)
|
||||
Boolean addSpace; /* TRUE if need to add a space to the buffer
|
||||
* before adding the trimmed word */
|
||||
int i;
|
||||
char *result;
|
||||
|
||||
av = brk_string(str, &ac, FALSE);
|
||||
|
||||
@ -618,9 +612,7 @@ VarModify(const char *str, VarModifyProc *modProc, void *datum)
|
||||
for (i = 1; i < ac; i++)
|
||||
addSpace = (*modProc)(av[i], addSpace, buf, datum);
|
||||
|
||||
result = (char *)Buf_GetAll(buf, (size_t *)NULL);
|
||||
Buf_Destroy(buf, FALSE);
|
||||
return (result);
|
||||
return (Buf_Peel(buf));
|
||||
}
|
||||
|
||||
/*-
|
||||
@ -648,7 +640,6 @@ VarSortWords(const char *str, int (*cmp)(const void *, const void *))
|
||||
int ac;
|
||||
Buffer *buf;
|
||||
int i;
|
||||
char *result;
|
||||
|
||||
av = brk_string(str, &ac, FALSE);
|
||||
qsort(av + 1, ac - 1, sizeof(char *), cmp);
|
||||
@ -659,9 +650,7 @@ VarSortWords(const char *str, int (*cmp)(const void *, const void *))
|
||||
Buf_AddByte(buf, (Byte)((i < ac - 1) ? ' ' : '\0'));
|
||||
}
|
||||
|
||||
result = (char *)Buf_GetAll(buf, (size_t *)NULL);
|
||||
Buf_Destroy(buf, FALSE);
|
||||
return (result);
|
||||
return (Buf_Peel(buf));
|
||||
}
|
||||
|
||||
static int
|
||||
@ -788,7 +777,6 @@ Var_Quote(const char *str)
|
||||
Buffer *buf;
|
||||
/* This should cover most shells :-( */
|
||||
static char meta[] = "\n \t'`\";&<>()|*?{}[]\\$!#^~";
|
||||
char *ret;
|
||||
|
||||
buf = Buf_Init(MAKE_BSIZE);
|
||||
for (; *str; str++) {
|
||||
@ -796,10 +784,8 @@ Var_Quote(const char *str)
|
||||
Buf_AddByte(buf, (Byte)'\\');
|
||||
Buf_AddByte(buf, (Byte)*str);
|
||||
}
|
||||
Buf_AddByte(buf, (Byte)'\0');
|
||||
ret = Buf_GetAll(buf, NULL);
|
||||
Buf_Destroy(buf, FALSE);
|
||||
return (ret);
|
||||
|
||||
return (Buf_Peel(buf));
|
||||
}
|
||||
|
||||
/*-
|
||||
@ -854,15 +840,14 @@ VarExpand(Var *v, VarParser *vp)
|
||||
* dynamically-allocated, so it will need freeing when we
|
||||
* return.
|
||||
*/
|
||||
value = (char *)Buf_GetAll(v->val, (size_t *)NULL);
|
||||
value = Buf_Data(v->val);
|
||||
if (strchr(value, '$') == NULL) {
|
||||
result = strdup(value);
|
||||
} else {
|
||||
Buffer *buf;
|
||||
|
||||
buf = Var_Subst(NULL, value, vp->ctxt, vp->err);
|
||||
result = Buf_GetAll(buf, NULL);
|
||||
Buf_Destroy(buf, FALSE);
|
||||
result = Buf_Peel(buf);
|
||||
}
|
||||
|
||||
v->flags &= ~VAR_IN_USE;
|
||||
@ -1212,8 +1197,7 @@ ParseModifier(VarParser *vp, char startc, Var *v, Boolean *freeResult)
|
||||
Buffer *buf;
|
||||
|
||||
buf = Cmd_Exec(value, &error);
|
||||
newStr = Buf_GetAll(buf, NULL);
|
||||
Buf_Destroy(buf, FALSE);
|
||||
newStr = Buf_Peel(buf);
|
||||
|
||||
if (error)
|
||||
Error(error, value);
|
||||
@ -1235,8 +1219,7 @@ ParseModifier(VarParser *vp, char startc, Var *v, Boolean *freeResult)
|
||||
for (cp = value; *cp; cp++)
|
||||
Buf_AddByte(buf, (Byte)tolower(*cp));
|
||||
|
||||
newStr = (char *)Buf_GetAll(buf, NULL);
|
||||
Buf_Destroy(buf, FALSE);
|
||||
newStr = Buf_Peel(buf);
|
||||
|
||||
vp->ptr++;
|
||||
break;
|
||||
@ -1261,8 +1244,7 @@ ParseModifier(VarParser *vp, char startc, Var *v, Boolean *freeResult)
|
||||
for (cp = value; *cp; cp++)
|
||||
Buf_AddByte(buf, (Byte)toupper(*cp));
|
||||
|
||||
newStr = (char *)Buf_GetAll(buf, NULL);
|
||||
Buf_Destroy(buf, FALSE);
|
||||
newStr = Buf_Peel(buf);
|
||||
|
||||
vp->ptr++;
|
||||
break;
|
||||
@ -1479,7 +1461,7 @@ ParseRestEnd(VarParser *vp, Buffer *buf, Boolean *freeResult)
|
||||
* things and we sure don't put nested
|
||||
* invocations in them...
|
||||
*/
|
||||
val = (char *)Buf_GetAll(v->val, NULL);
|
||||
val = Buf_Data(v->val);
|
||||
|
||||
if (vname[1] == 'D') {
|
||||
val = VarModify(val, VarHead, NULL);
|
||||
@ -1943,7 +1925,6 @@ Var_Dump(const GNode *ctxt)
|
||||
|
||||
LST_FOREACH(ln, &ctxt->context) {
|
||||
v = Lst_Datum(ln);
|
||||
printf("%-16s = %s\n", v->name,
|
||||
(const char *)Buf_GetAll(v->val, NULL));
|
||||
printf("%-16s = %s\n", v->name, Buf_Data(v->val));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user