summaryrefslogtreecommitdiff
path: root/usr.bin/make
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>1999-12-16 17:02:46 +0000
committerMarc Espie <espie@cvs.openbsd.org>1999-12-16 17:02:46 +0000
commit9dfc59cc94e1b9ffcaba4f9673a06ce91dd963ae (patch)
treed2d812c590470d006a86b3e8706e54a4d4b69099 /usr.bin/make
parent539b72feadc3d1c6edbcf5e137407d0432b899b1 (diff)
Allocate buffers as static data structures.
This cuts down quite a lot of malloc, since in actual use, buffer usage is mostly static.
Diffstat (limited to 'usr.bin/make')
-rw-r--r--usr.bin/make/buf.c24
-rw-r--r--usr.bin/make/buf.h14
-rw-r--r--usr.bin/make/cond.c43
-rw-r--r--usr.bin/make/for.c19
-rw-r--r--usr.bin/make/main.c15
-rw-r--r--usr.bin/make/parse.c32
-rw-r--r--usr.bin/make/var.c113
7 files changed, 119 insertions, 141 deletions
diff --git a/usr.bin/make/buf.c b/usr.bin/make/buf.c
index 58b1c9af29d..4f9f0fce2af 100644
--- a/usr.bin/make/buf.c
+++ b/usr.bin/make/buf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: buf.c,v 1.11 1999/12/16 16:46:38 espie Exp $ */
+/* $OpenBSD: buf.c,v 1.12 1999/12/16 17:02:45 espie Exp $ */
/* $NetBSD: buf.c,v 1.9 1996/12/31 17:53:21 christos Exp $ */
/*
@@ -70,7 +70,7 @@
#if 0
static char sccsid[] = "@(#)buf.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$OpenBSD: buf.c,v 1.11 1999/12/16 16:46:38 espie Exp $";
+static char rcsid[] = "$OpenBSD: buf.c,v 1.12 1999/12/16 17:02:45 espie Exp $";
#endif
#endif /* not lint */
@@ -127,33 +127,23 @@ Buf_AddChars(bp, numBytes, bytesPtr)
bp->inPtr += numBytes;
}
-Buffer
-Buf_Init(size)
+void
+Buf_Init(bp, size)
+ Buffer bp; /* New Buffer */
size_t size; /* Initial size for the buffer */
{
- Buffer bp; /* New Buffer */
-
- bp = (Buffer)emalloc(sizeof(*bp));
-
if (size == 0) {
size = BUF_DEF_SIZE;
}
bp->inPtr = bp->endPtr = bp->buffer = emalloc(size);
bp->endPtr += size;
-
- return (bp);
}
void
-Buf_Destroy(buf, freeData)
+Buf_Destroy(buf)
Buffer buf; /* Buffer to destroy */
- Boolean freeData; /* TRUE if the data should be destroyed as well */
{
-
- if (freeData) {
- free(buf->buffer);
- }
- free ((char *)buf);
+ free(buf->buffer);
}
void
diff --git a/usr.bin/make/buf.h b/usr.bin/make/buf.h
index 14a6889e2d6..42ad72beed4 100644
--- a/usr.bin/make/buf.h
+++ b/usr.bin/make/buf.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: buf.h,v 1.10 1999/12/16 16:46:38 espie Exp $ */
+/* $OpenBSD: buf.h,v 1.11 1999/12/16 17:02:45 espie Exp $ */
/* $NetBSD: buf.h,v 1.7 1996/12/31 17:53:22 christos Exp $ */
/*
@@ -51,11 +51,13 @@
#include "sprite.h"
-typedef struct Buffer {
+typedef struct Buffer_ {
char *buffer; /* The buffer itself. */
char *inPtr; /* Place to write to. */
char *endPtr; /* End of allocated space. */
-} *Buffer;
+} BUFFER;
+
+typedef BUFFER *Buffer;
/* Internal support for Buf_AddChar. */
void BufOverflow __P((Buffer));
@@ -92,9 +94,9 @@ void Buf_AddChars __P((Buffer, size_t, const char *));
/* Buf_Init -- Initialize a buffer. If no initial size is given,
* a reasonable default is used. */
-Buffer Buf_Init __P((size_t));
-/* Buf_Destroy -- Nuke a buffer and all its resources if Boolean is TRUE. */
-void Buf_Destroy __P((Buffer, Boolean));
+void Buf_Init __P((Buffer, size_t));
+/* Buf_Destroy -- Nuke a buffer and all its resources. */
+void Buf_Destroy __P((Buffer));
/* Buf_ReplaceLastChar -- Replace the last char in a buffer. */
void Buf_ReplaceLastChar __P((Buffer, char));
diff --git a/usr.bin/make/cond.c b/usr.bin/make/cond.c
index 525ec2db3a8..a5d96425cb4 100644
--- a/usr.bin/make/cond.c
+++ b/usr.bin/make/cond.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cond.c,v 1.10 1999/12/16 16:58:15 espie Exp $ */
+/* $OpenBSD: cond.c,v 1.11 1999/12/16 17:02:45 espie Exp $ */
/* $NetBSD: cond.c,v 1.7 1996/11/06 17:59:02 christos Exp $ */
/*
@@ -43,7 +43,7 @@
#if 0
static char sccsid[] = "@(#)cond.c 8.2 (Berkeley) 1/2/94";
#else
-static char rcsid[] = "$OpenBSD: cond.c,v 1.10 1999/12/16 16:58:15 espie Exp $";
+static char rcsid[] = "$OpenBSD: cond.c,v 1.11 1999/12/16 17:02:45 espie Exp $";
#endif
#endif /* not lint */
@@ -186,7 +186,7 @@ CondGetArg(linePtr, argPtr, argLen, func, parens)
Boolean parens; /* TRUE if arg should be bounded by parens */
{
register char *cp;
- register Buffer buf;
+ BUFFER buf;
cp = *linePtr;
if (parens) {
@@ -217,7 +217,7 @@ CondGetArg(linePtr, argPtr, argLen, func, parens)
* Create a buffer for the argument and start it out at 16 characters
* long. Why 16? Why not?
*/
- buf = Buf_Init(16);
+ Buf_Init(&buf, 16);
while ((strchr(" \t)&|", *cp) == (char *)NULL) && (*cp != '\0')) {
if (*cp == '$') {
@@ -233,20 +233,19 @@ CondGetArg(linePtr, argPtr, argLen, func, parens)
cp2 = Var_Parse(cp, VAR_CMD, TRUE, &len, &doFree);
- Buf_AddString(buf, cp2);
+ Buf_AddString(&buf, cp2);
if (doFree) {
free(cp2);
}
cp += len;
} else {
- Buf_AddChar(buf, *cp);
+ Buf_AddChar(&buf, *cp);
cp++;
}
}
- *argPtr = Buf_Retrieve(buf);
- *argLen = Buf_Size(buf);
- Buf_Destroy(buf, FALSE);
+ *argPtr = Buf_Retrieve(&buf);
+ *argLen = Buf_Size(&buf);
while (*cp == ' ' || *cp == '\t') {
cp++;
@@ -541,21 +540,20 @@ CondToken(doEval)
if (!isspace((unsigned char) *condExpr) &&
strchr("!=><", *condExpr) == NULL) {
- Buffer buf;
+ BUFFER buf;
- buf = Buf_Init(0);
+ Buf_Init(&buf, 0);
- Buf_AddString(buf, lhs);
+ Buf_AddString(&buf, lhs);
if (doFree)
free(lhs);
for (;*condExpr && !isspace((unsigned char) *condExpr);
condExpr++)
- Buf_AddChar(buf, *condExpr);
+ Buf_AddChar(&buf, *condExpr);
- lhs = Buf_Retrieve(buf);
- Buf_Destroy(buf, FALSE);
+ lhs = Buf_Retrieve(&buf);
doFree = TRUE;
}
@@ -607,7 +605,7 @@ do_compare:
char *string;
char *cp, *cp2;
int qt;
- Buffer buf;
+ BUFFER buf;
do_string_compare:
if (((*op != '!') && (*op != '=')) || (op[1] != '=')) {
@@ -616,7 +614,7 @@ do_string_compare:
goto error;
}
- buf = Buf_Init(0);
+ Buf_Init(&buf, 0);
qt = *rhs == '"' ? 1 : 0;
for (cp = &rhs[qt];
@@ -629,28 +627,27 @@ do_string_compare:
* character, if it exists.
*/
cp++;
- Buf_AddChar(buf, *cp);
+ Buf_AddChar(&buf, *cp);
} else if (*cp == '$') {
int len;
Boolean freeIt;
cp2 = Var_Parse(cp, VAR_CMD, doEval,&len, &freeIt);
if (cp2 != var_Error) {
- Buf_AddString(buf, cp2);
+ Buf_AddString(&buf, cp2);
if (freeIt) {
free(cp2);
}
cp += len - 1;
} else {
- Buf_AddChar(buf, *cp);
+ Buf_AddChar(&buf, *cp);
}
} else {
- Buf_AddChar(buf, *cp);
+ Buf_AddChar(&buf, *cp);
}
}
- string = Buf_Retrieve(buf);
- Buf_Destroy(buf, FALSE);
+ string = Buf_Retrieve(&buf);
if (DEBUG(COND)) {
printf("lhs = \"%s\", rhs = \"%s\", op = %.2s\n",
diff --git a/usr.bin/make/for.c b/usr.bin/make/for.c
index f2541465003..ff1cab7099b 100644
--- a/usr.bin/make/for.c
+++ b/usr.bin/make/for.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: for.c,v 1.9 1999/12/16 16:41:41 espie Exp $ */
+/* $OpenBSD: for.c,v 1.10 1999/12/16 17:02:45 espie Exp $ */
/* $NetBSD: for.c,v 1.4 1996/11/06 17:59:05 christos Exp $ */
/*
@@ -65,7 +65,7 @@
#if 0
static char sccsid[] = "@(#)for.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$OpenBSD: for.c,v 1.9 1999/12/16 16:41:41 espie Exp $";
+static char rcsid[] = "$OpenBSD: for.c,v 1.10 1999/12/16 17:02:45 espie Exp $";
#endif
#endif /* not lint */
@@ -101,7 +101,7 @@ static char rcsid[] = "$OpenBSD: for.c,v 1.9 1999/12/16 16:41:41 espie Exp $";
static int forLevel = 0; /* Nesting level */
static char *forVar; /* Iteration variable */
-static Buffer forBuf; /* Commands in loop */
+static BUFFER forBuf; /* Commands in loop */
static Lst forLst; /* List of items */
static unsigned long forLineno; /* Line at beginning of loop */
@@ -219,7 +219,7 @@ For_Eval (line)
build_words_list(forLst, sub);
free(sub);
forLineno = Parse_Getlineno();
- forBuf = Buf_Init(0);
+ Buf_Init(&forBuf, 0);
forLevel++;
return 1;
}
@@ -246,8 +246,8 @@ For_Eval (line)
}
if (forLevel != 0) {
- Buf_AddString(forBuf, line);
- Buf_AddChar(forBuf, '\n');
+ Buf_AddString(&forBuf, line);
+ Buf_AddChar(&forBuf, '\n');
return 1;
}
else {
@@ -304,19 +304,18 @@ For_Run()
{
For arg;
- if (forVar == NULL || forBuf == NULL || forLst == NULL)
+ if (forVar == NULL || forLst == NULL)
return;
arg.var = forVar;
- arg.buf = forBuf;
+ arg.buf = &forBuf;
arg.lst = forLst;
arg.lineno = forLineno;
forVar = NULL;
- forBuf = NULL;
forLst = NULL;
Lst_ForEach(arg.lst, ForExec, (ClientData) &arg);
free((Address)arg.var);
Lst_Destroy(arg.lst, (void (*) __P((ClientData))) free);
- Buf_Destroy(arg.buf, TRUE);
+ Buf_Destroy(arg.buf);
}
diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c
index fdb8d9710b1..a9da5cc828d 100644
--- a/usr.bin/make/main.c
+++ b/usr.bin/make/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.21 1999/12/16 16:41:41 espie Exp $ */
+/* $OpenBSD: main.c,v 1.22 1999/12/16 17:02:45 espie Exp $ */
/* $NetBSD: main.c,v 1.34 1997/03/24 20:56:36 gwr Exp $ */
/*
@@ -49,7 +49,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94";
#else
-static char rcsid[] = "$OpenBSD: main.c,v 1.21 1999/12/16 16:41:41 espie Exp $";
+static char rcsid[] = "$OpenBSD: main.c,v 1.22 1999/12/16 17:02:45 espie Exp $";
#endif
#endif /* not lint */
@@ -927,7 +927,7 @@ Cmd_Exec(cmd, err)
int pid; /* PID from wait() */
char *res; /* result */
int status; /* command exit status */
- Buffer buf; /* buffer to store the result */
+ BUFFER buf; /* buffer to store the result */
char *cp;
ssize_t cc;
size_t length;
@@ -983,13 +983,13 @@ Cmd_Exec(cmd, err)
*/
(void) close(fds[1]);
- buf = Buf_Init(MAKE_BSIZE);
+ Buf_Init(&buf, MAKE_BSIZE);
do {
char result[BUFSIZ];
cc = read(fds[0], result, sizeof(result));
if (cc > 0)
- Buf_AddChars(buf, cc, result);
+ Buf_AddChars(&buf, cc, result);
}
while (cc > 0 || (cc == -1 && errno == EINTR));
@@ -1004,9 +1004,8 @@ Cmd_Exec(cmd, err)
while(((pid = wait(&status)) != cpid) && (pid >= 0))
continue;
- res = Buf_Retrieve(buf);
- length = Buf_Size(buf);
- Buf_Destroy(buf, FALSE);
+ res = Buf_Retrieve(&buf);
+ length = Buf_Size(&buf);
if (cc == -1)
*err = "Couldn't read shell's output for \"%s\"";
diff --git a/usr.bin/make/parse.c b/usr.bin/make/parse.c
index ff03a7a99f9..1320485b794 100644
--- a/usr.bin/make/parse.c
+++ b/usr.bin/make/parse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.c,v 1.28 1999/12/16 16:52:11 espie Exp $ */
+/* $OpenBSD: parse.c,v 1.29 1999/12/16 17:02:45 espie Exp $ */
/* $NetBSD: parse.c,v 1.29 1997/03/10 21:20:04 christos Exp $ */
/*
@@ -43,7 +43,7 @@
#if 0
static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94";
#else
-static char rcsid[] = "$OpenBSD: parse.c,v 1.28 1999/12/16 16:52:11 espie Exp $";
+static char rcsid[] = "$OpenBSD: parse.c,v 1.29 1999/12/16 17:02:45 espie Exp $";
#endif
#endif /* not lint */
@@ -2106,18 +2106,18 @@ ParseSkipLine(skip)
{
char *line;
int c, lastc;
- Buffer buf;
+ BUFFER buf;
- buf = Buf_Init(MAKE_BSIZE);
+ Buf_Init(&buf, MAKE_BSIZE);
for (;;) {
- Buf_Reset(buf);
+ Buf_Reset(&buf);
lastc = '\0';
while (((c = ParseReadc()) != '\n' || lastc == '\\')
&& c != EOF) {
if (c == '\n') {
- Buf_ReplaceLastChar(buf, ' ');
+ Buf_ReplaceLastChar(&buf, ' ');
lineno++;
while ((c = ParseReadc()) == ' ' || c == '\t');
@@ -2126,11 +2126,11 @@ ParseSkipLine(skip)
break;
}
- Buf_AddChar(buf, c);
+ Buf_AddChar(&buf, c);
lastc = c;
}
- line = Buf_Retrieve(buf);
+ line = Buf_Retrieve(&buf);
lineno++;
/* allow for non-newline terminated lines while skipping */
if (line[0] == '.')
@@ -2138,15 +2138,14 @@ ParseSkipLine(skip)
if (c == EOF) {
Parse_Error(PARSE_FATAL, "Unclosed conditional/for loop");
- Buf_Destroy(buf, TRUE);
- return((char *)NULL);
+ Buf_Destroy(&buf);
+ return NULL;
}
if (skip == 0)
break;
}
- Buf_Destroy(buf, FALSE);
return line;
}
@@ -2171,7 +2170,7 @@ ParseSkipLine(skip)
static char *
ParseReadLine ()
{
- Buffer buf; /* Buffer for current line */
+ BUFFER buf; /* Buffer for current line */
register int c; /* the current character */
register int lastc; /* The most-recent character */
Boolean semiNL; /* treat semi-colons as newlines */
@@ -2214,7 +2213,7 @@ ParseReadLine ()
if (c != EOF) {
lastc = c;
- buf = Buf_Init(MAKE_BSIZE);
+ Buf_Init(&buf, MAKE_BSIZE);
while (((c = ParseReadc ()) != '\n' || (lastc == '\\')) &&
(c != EOF))
@@ -2328,7 +2327,7 @@ test_char:
/*
* Copy in the previous character and save this one in lastc.
*/
- Buf_AddChar(buf, lastc);
+ Buf_AddChar(&buf, lastc);
lastc = c;
}
@@ -2336,9 +2335,8 @@ test_char:
lineno++;
if (lastc != '\0')
- Buf_AddChar(buf, lastc);
- line = Buf_Retrieve(buf);
- Buf_Destroy(buf, FALSE);
+ Buf_AddChar(&buf, lastc);
+ line = Buf_Retrieve(&buf);
/*
* Strip trailing blanks and tabs from the line.
diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c
index afad7b4f554..7e94c74872f 100644
--- a/usr.bin/make/var.c
+++ b/usr.bin/make/var.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: var.c,v 1.22 1999/12/16 16:52:11 espie Exp $ */
+/* $OpenBSD: var.c,v 1.23 1999/12/16 17:02:45 espie Exp $ */
/* $NetBSD: var.c,v 1.18 1997/03/18 19:24:46 christos Exp $ */
/*
@@ -70,7 +70,7 @@
#if 0
static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94";
#else
-static char rcsid[] = "$OpenBSD: var.c,v 1.22 1999/12/16 16:52:11 espie Exp $";
+static char rcsid[] = "$OpenBSD: var.c,v 1.23 1999/12/16 17:02:45 espie Exp $";
#endif
#endif /* not lint */
@@ -167,7 +167,7 @@ static Lst allVars; /* List of all variables */
typedef struct Var {
char *name; /* the variable's name */
- Buffer val; /* its value */
+ BUFFER val; /* its value */
int flags; /* miscellaneous status flags */
#define VAR_IN_USE 1 /* Variable's value currently being used.
* Used to avoid recursion */
@@ -202,6 +202,7 @@ typedef struct {
} VarREPattern;
#endif
+#define VarValue(v) Buf_Retrieve(&((v)->val))
static int VarCmp __P((ClientData, ClientData));
static Var *VarFind __P((char *, GNode *, int));
static Var *VarAdd __P((char *, char *, GNode *));
@@ -373,8 +374,8 @@ VarAdd(name, val, ctxt)
v->name = estrdup (name);
len = val ? strlen(val) : 0;
- v->val = Buf_Init(len+1);
- Buf_AddChars(v->val, len, val);
+ Buf_Init(&(v->val), len+1);
+ Buf_AddChars(&(v->val), len, val);
v->flags = 0;
@@ -405,8 +406,8 @@ VarDelete(vp)
{
Var *v = (Var *) vp;
free(v->name);
- Buf_Destroy(v->val, TRUE);
- free((Address) v);
+ Buf_Destroy(&(v->val));
+ free(v);
}
@@ -484,8 +485,8 @@ Var_Set (name, val, ctxt)
if (v == (Var *) NIL) {
(void)VarAdd(name, val, ctxt);
} else {
- Buf_Reset(v->val);
- Buf_AddString(v->val, val);
+ Buf_Reset(&(v->val));
+ Buf_AddString(&(v->val), val);
if (DEBUG(VAR)) {
printf("%s:%s = %s\n", ctxt->name, name, val);
@@ -539,12 +540,11 @@ Var_Append (name, val, ctxt)
if (v == (Var *) NIL) {
(void)VarAdd(name, val, ctxt);
} else {
- Buf_AddSpace(v->val);
- Buf_AddString(v->val, val);
+ Buf_AddSpace(&(v->val));
+ Buf_AddString(&(v->val), val);
if (DEBUG(VAR)) {
- printf("%s:%s = %s\n", ctxt->name, name,
- Buf_Retrieve(v->val));
+ printf("%s:%s = %s\n", ctxt->name, name, VarValue(v));
}
}
@@ -598,8 +598,8 @@ Var_Value(name, ctxt)
Var *v;
v = VarFind(name, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD);
- if (v != NULL)
- return Buf_Retrieve(v->val);
+ if (v != (Var *)NIL)
+ return VarValue(v);
else
return NULL;
}
@@ -1260,7 +1260,7 @@ VarModify (str, modProc, datum)
Boolean (*modProc) __P((char *, Boolean, Buffer, ClientData));
ClientData datum; /* Datum to pass it */
{
- Buffer buf; /* Buffer for the new string */
+ BUFFER buf; /* Buffer for the new string */
Boolean addSpace; /* TRUE if need to add a space to the
* buffer before adding the trimmed
* word */
@@ -1268,19 +1268,17 @@ VarModify (str, modProc, datum)
char *as; /* word list memory */
int ac, i;
- buf = Buf_Init(0);
+ Buf_Init(&buf, 0);
addSpace = FALSE;
av = brk_string(str, &ac, FALSE, &as);
for (i = 0; i < ac; i++)
- addSpace = (*modProc)(av[i], addSpace, buf, datum);
+ addSpace = (*modProc)(av[i], addSpace, &buf, datum);
free(as);
free(av);
- str = Buf_Retrieve(buf);
- Buf_Destroy(buf, FALSE);
- return (str);
+ return Buf_Retrieve(&buf);
}
/*-
@@ -1315,8 +1313,10 @@ VarGetPattern(ctxt, err, tstr, delim, flags, length, pattern)
VarPattern *pattern;
{
char *cp;
- Buffer buf = Buf_Init(0);
+ BUFFER buf;
int junk;
+
+ Buf_Init(&buf, 0);
if (length == NULL)
length = &junk;
@@ -1332,12 +1332,12 @@ VarGetPattern(ctxt, err, tstr, delim, flags, length, pattern)
*/
for (cp = *tstr; *cp && (*cp != delim); cp++) {
if (IS_A_MATCH(cp, delim)) {
- Buf_AddChar(buf, cp[1]);
+ Buf_AddChar(&buf, cp[1]);
cp++;
} else if (*cp == '$') {
if (cp[1] == delim) {
if (flags == NULL)
- Buf_AddChar(buf, *cp);
+ Buf_AddChar(&buf, *cp);
else
/*
* Unescaped $ at end of pattern => anchor
@@ -1356,16 +1356,16 @@ VarGetPattern(ctxt, err, tstr, delim, flags, length, pattern)
* substitution and recurse.
*/
cp2 = Var_Parse(cp, ctxt, err, &len, &freeIt);
- Buf_AddString(buf, cp2);
+ Buf_AddString(&buf, cp2);
if (freeIt)
free(cp2);
cp += len - 1;
}
}
else if (pattern && *cp == '&')
- Buf_AddChars(buf, pattern->leftLen, pattern->lhs);
+ Buf_AddChars(&buf, pattern->leftLen, pattern->lhs);
else
- Buf_AddChar(buf, *cp);
+ Buf_AddChar(&buf, *cp);
}
if (*cp != delim) {
@@ -1375,10 +1375,8 @@ VarGetPattern(ctxt, err, tstr, delim, flags, length, pattern)
}
else {
*tstr = ++cp;
- cp = Buf_Retrieve(buf);
- *length = Buf_Size(buf);
- Buf_Destroy(buf, FALSE);
- return cp;
+ *length = Buf_Size(&buf);
+ return Buf_Retrieve(&buf);
}
}
@@ -1400,19 +1398,17 @@ VarQuote(str)
char *str;
{
- Buffer buf;
+ BUFFER buf;
/* This should cover most shells :-( */
static char meta[] = "\n \t'`\";&<>()|*?{}[]\\$!#^~";
- buf = Buf_Init(MAKE_BSIZE);
+ Buf_Init(&buf, MAKE_BSIZE);
for (; *str; str++) {
if (strchr(meta, *str) != NULL)
- Buf_AddChar(buf, '\\');
- Buf_AddChar(buf, *str);
+ Buf_AddChar(&buf, '\\');
+ Buf_AddChar(&buf, *str);
}
- str = Buf_Retrieve(buf);
- Buf_Destroy(buf, FALSE);
- return str;
+ return Buf_Retrieve(&buf);
}
/*-
@@ -1570,7 +1566,7 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr)
* the only one who sets these things and we sure don't
* but nested invocations in them...
*/
- val = Buf_Retrieve(v->val);
+ val = VarValue(v);
if (str[3] == 'D') {
val = VarModify(val, VarHead, (ClientData)0);
@@ -1653,7 +1649,7 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr)
*/
v = (Var *) emalloc(sizeof(Var));
v->name = &str[1];
- v->val = Buf_Init(1);
+ Buf_Init(&(v->val), 1);
v->flags = VAR_JUNK;
}
}
@@ -1674,7 +1670,7 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr)
* been dynamically-allocated, so it will need freeing when we
* return.
*/
- str = Buf_Retrieve(v->val);
+ str = VarValue(v);
if (strchr (str, '$') != (char *)NULL) {
str = Var_Subst(NULL, str, ctxt, err);
*freePtr = TRUE;
@@ -2070,8 +2066,8 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr)
free(str);
}
*freePtr = FALSE;
- Buf_Destroy(v->val, TRUE);
- free((Address)v);
+ Buf_Destroy(&(v->val));
+ free(v);
if (dynamic) {
str = emalloc(*lengthPtr + 1);
strncpy(str, start, *lengthPtr);
@@ -2113,7 +2109,7 @@ Var_Subst (var, str, ctxt, undefErr)
GNode *ctxt; /* the context wherein to find variables */
Boolean undefErr; /* TRUE if undefineds are an error */
{
- Buffer buf; /* Buffer for forming things */
+ BUFFER buf; /* Buffer for forming things */
char *val; /* Value to substitute for a variable */
int length; /* Length of the variable invocation */
Boolean doFree; /* Set true if val should be freed */
@@ -2121,7 +2117,7 @@ Var_Subst (var, str, ctxt, undefErr)
* been reported to prevent a plethora
* of messages when recursing */
- buf = Buf_Init(MAKE_BSIZE);
+ Buf_Init(&buf, MAKE_BSIZE);
errorReported = FALSE;
while (*str) {
@@ -2132,7 +2128,7 @@ Var_Subst (var, str, ctxt, undefErr)
* dollar sign into the buffer directly.
*/
str++;
- Buf_AddChar(buf, *str);
+ Buf_AddChar(&buf, *str);
str++;
} else if (*str != '$') {
/*
@@ -2143,14 +2139,14 @@ Var_Subst (var, str, ctxt, undefErr)
for (cp = str++; *str != '$' && *str != '\0'; str++)
continue;
- Buf_AddInterval(buf, cp, str);
+ Buf_AddInterval(&buf, cp, str);
} else {
if (var != NULL) {
int expand;
for (;;) {
if (str[1] != '(' && str[1] != '{') {
if (str[1] != *var || var[1] != '\0') {
- Buf_AddChars(buf, 2, str);
+ Buf_AddChars(&buf, 2, str);
str += 2;
expand = FALSE;
}
@@ -2174,7 +2170,7 @@ Var_Subst (var, str, ctxt, undefErr)
* the nested one
*/
if (*p == '$') {
- Buf_AddInterval(buf, str, p);
+ Buf_AddInterval(&buf, str, p);
str = p;
continue;
}
@@ -2187,7 +2183,7 @@ Var_Subst (var, str, ctxt, undefErr)
*/
for (;*p != '$' && *p != '\0'; p++)
continue;
- Buf_AddInterval(buf, str, p);
+ Buf_AddInterval(&buf, str, p);
str = p;
expand = FALSE;
}
@@ -2230,7 +2226,7 @@ Var_Subst (var, str, ctxt, undefErr)
str += length;
errorReported = TRUE;
} else {
- Buf_AddChar(buf, *str);
+ Buf_AddChar(&buf, *str);
str += 1;
}
} else {
@@ -2244,17 +2240,14 @@ Var_Subst (var, str, ctxt, undefErr)
* Copy all the characters from the variable value straight
* into the new string.
*/
- Buf_AddString(buf, val);
- if (doFree) {
- free ((Address)val);
- }
+ Buf_AddString(&buf, val);
+ if (doFree)
+ free(val);
}
}
}
- str = Buf_Retrieve(buf);
- Buf_Destroy(buf, FALSE);
- return (str);
+ return Buf_Retrieve(&buf);
}
/*-
@@ -2332,12 +2325,12 @@ Var_End ()
/****************** PRINT DEBUGGING INFO *****************/
static int
-VarPrintVar (vp, dummy)
+VarPrintVar(vp, dummy)
ClientData vp;
ClientData dummy;
{
Var *v = (Var *) vp;
- printf ("%-16s = %s\n", v->name, Buf_Retrieve(v->val));
+ printf("%-16s = %s\n", v->name, VarValue(v));
return (dummy ? 0 : 0);
}