summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/make/buf.c87
-rw-r--r--usr.bin/make/buf.h20
-rw-r--r--usr.bin/make/parse.c9
-rw-r--r--usr.bin/make/var.c6
4 files changed, 49 insertions, 73 deletions
diff --git a/usr.bin/make/buf.c b/usr.bin/make/buf.c
index 263e4968460..3daef93fd1a 100644
--- a/usr.bin/make/buf.c
+++ b/usr.bin/make/buf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: buf.c,v 1.8 1999/12/06 22:24:31 espie Exp $ */
+/* $OpenBSD: buf.c,v 1.9 1999/12/16 16:27:12 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.8 1999/12/06 22:24:31 espie Exp $";
+static char rcsid[] = "$OpenBSD: buf.c,v 1.9 1999/12/16 16:27:12 espie Exp $";
#endif
#endif /* not lint */
@@ -94,49 +94,32 @@ static char rcsid[] = "$OpenBSD: buf.c,v 1.8 1999/12/06 22:24:31 espie Exp $";
* Makes sure there's room for an extra NULL char at the end of the
* buffer in case it holds a string.
*/
-#define BufExpand(bp,nb) \
- if (bp->left < (nb)+1) { \
- char *newBuf; \
- size_t newSize = (bp)->size; \
- \
- do { \
- newSize *= 2 ; \
- (bp)->left = newSize - ((bp)->inPtr - (bp)->buffer); \
- } while ((bp)->left < (nb)+1+BUF_MARGIN); \
- newBuf = erealloc((bp)->buffer, newSize); \
- (bp)->inPtr = newBuf + ((bp)->inPtr - (bp)->buffer); \
- (bp)->outPtr = newBuf + ((bp)->outPtr - (bp)->buffer); \
- (bp)->buffer = newBuf; \
- (bp)->size = newSize; \
- }
+#define BufExpand(bp,nb) \
+do { \
+ char *newBuf; \
+ size_t newSize = (bp)->size; \
+ \
+ do { \
+ newSize *= 2 ; \
+ (bp)->left = newSize - ((bp)->inPtr - (bp)->buffer); \
+ } while ((bp)->left < (nb)+1+BUF_MARGIN); \
+ newBuf = erealloc((bp)->buffer, newSize); \
+ (bp)->inPtr = newBuf + ((bp)->inPtr - (bp)->buffer); \
+ (bp)->outPtr = newBuf + ((bp)->outPtr - (bp)->buffer); \
+ (bp)->buffer = newBuf; \
+ (bp)->size = newSize; \
+} while (0)
#define BUF_DEF_SIZE 256 /* Default buffer size */
#define BUF_MARGIN 256 /* Make sure we are comfortable */
-/*-
- *-----------------------------------------------------------------------
- * Buf_OvAddChar --
- * Add a single char to the buffer.
- *
- * Side Effects:
- * The buffer may be expanded.
- *
- *-----------------------------------------------------------------------
- */
+/* Buf_AddChar hard case: buffer must be expanded to accommodate
+ * one more char. */
void
-Buf_OvAddChar(bp, byte)
- Buffer bp;
- char byte;
+BufOverflow(bp)
+ Buffer bp;
{
BufExpand(bp, 1);
-
- *bp->inPtr++ = byte;
- bp->left--;
-
- /*
- * Null-terminate
- */
- *bp->inPtr = 0;
}
/*-
@@ -156,16 +139,12 @@ Buf_AddChars(bp, numBytes, bytesPtr)
const char *bytesPtr;
{
- BufExpand(bp, numBytes);
+ if (bp->left < numBytes+1)
+ BufExpand(bp, numBytes);
memcpy(bp->inPtr, bytesPtr, numBytes);
bp->inPtr += numBytes;
bp->left -= numBytes;
-
- /*
- * Null-terminate
- */
- *bp->inPtr = 0;
}
/*-
@@ -188,13 +167,14 @@ Buf_GetAll(bp, numBytesPtr)
*numBytesPtr = bp->inPtr - bp->outPtr;
}
+ *bp->inPtr = 0;
return (bp->outPtr);
}
/*-
*-----------------------------------------------------------------------
- * Buf_Discard --
- * Throw away chars in a buffer.
+ * Buf_Reset -
+ * Throw away all chars in a buffer.
*
* Side Effects:
* The chars are discarded.
@@ -202,18 +182,12 @@ Buf_GetAll(bp, numBytesPtr)
*-----------------------------------------------------------------------
*/
void
-Buf_Discard(bp, numBytes)
+Buf_Reset(bp)
Buffer bp;
- size_t numBytes;
{
- if (bp->inPtr - bp->outPtr <= numBytes) {
- bp->inPtr = bp->outPtr = bp->buffer;
- bp->left = bp->size;
- *bp->inPtr = 0;
- } else {
- bp->outPtr += numBytes;
- }
+ bp->inPtr = bp->outPtr = bp->buffer;
+ bp->left = bp->size;
}
/*-
@@ -228,7 +202,7 @@ Buf_Discard(bp, numBytes)
*-----------------------------------------------------------------------
*/
int
-Buf_Size (buf)
+Buf_Size(buf)
Buffer buf;
{
return (buf->inPtr - buf->outPtr);
@@ -263,7 +237,6 @@ Buf_Init(size)
bp->left = bp->size = size;
bp->buffer = emalloc(size);
bp->inPtr = bp->outPtr = bp->buffer;
- *bp->inPtr = 0;
return (bp);
}
diff --git a/usr.bin/make/buf.h b/usr.bin/make/buf.h
index 643bb4f5cbe..37c74321430 100644
--- a/usr.bin/make/buf.h
+++ b/usr.bin/make/buf.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: buf.h,v 1.7 1999/12/09 18:18:24 espie Exp $ */
+/* $OpenBSD: buf.h,v 1.8 1999/12/16 16:27:12 espie Exp $ */
/* $NetBSD: buf.h,v 1.7 1996/12/31 17:53:22 christos Exp $ */
/*
@@ -59,14 +59,18 @@ typedef struct Buffer {
char *outPtr; /* Place to read from */
} *Buffer;
-/* Buf_AddChar adds a single char to a buffer. */
-#define Buf_AddChar(bp, byte) \
- (void) (--(bp)->left == 0 ? Buf_OvAddChar(bp, byte), 1 : \
- (*(bp)->inPtr++ = (byte), *(bp)->inPtr = 0), 1)
+/* Internal support for Buf_AddChar. */
+void BufOverflow __P((Buffer));
-#define BUF_ERROR 256
+/* Buf_AddChar -- Add a single char to a buffer. */
+#define Buf_AddChar(bp, byte) \
+do { \
+ if (--(bp)->left == 0) \
+ BufOverflow(bp); \
+ *(bp)->inPtr++ = (byte); \
+} while (0)
-void Buf_OvAddChar __P((Buffer, char));
+#define BUF_ERROR 256
/* Buf_AddChars -- Add a number of chars to the buffer. */
void Buf_AddChars __P((Buffer, size_t, const char *));
@@ -79,7 +83,7 @@ void Buf_AddChars __P((Buffer, size_t, const char *));
char *Buf_GetAll __P((Buffer, size_t *));
-void Buf_Discard __P((Buffer, size_t));
+void Buf_Reset __P((Buffer));
int Buf_Size __P((Buffer));
Buffer Buf_Init __P((size_t));
void Buf_Destroy __P((Buffer, Boolean));
diff --git a/usr.bin/make/parse.c b/usr.bin/make/parse.c
index 96198715688..379efa743fb 100644
--- a/usr.bin/make/parse.c
+++ b/usr.bin/make/parse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.c,v 1.25 1999/12/06 22:24:31 espie Exp $ */
+/* $OpenBSD: parse.c,v 1.26 1999/12/16 16:27:12 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.25 1999/12/06 22:24:31 espie Exp $";
+static char rcsid[] = "$OpenBSD: parse.c,v 1.26 1999/12/16 16:27:12 espie Exp $";
#endif
#endif /* not lint */
@@ -2106,13 +2106,12 @@ ParseSkipLine(skip)
{
char *line;
int c, lastc;
- size_t lineLength = 0;
Buffer buf;
buf = Buf_Init(MAKE_BSIZE);
for (;;) {
- Buf_Discard(buf, lineLength);
+ Buf_Reset(buf);
lastc = '\0';
while (((c = ParseReadc()) != '\n' || lastc == '\\')
@@ -2132,7 +2131,7 @@ ParseSkipLine(skip)
}
Buf_AddChar(buf, '\0');
- line = Buf_GetAll(buf, &lineLength);
+ line = Buf_GetAll(buf, NULL);
lineno++;
/* allow for non-newline terminated lines while skipping */
if (line[0] == '.')
diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c
index 04c56938c97..bdaaec45622 100644
--- a/usr.bin/make/var.c
+++ b/usr.bin/make/var.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: var.c,v 1.19 1999/12/09 18:18:24 espie Exp $ */
+/* $OpenBSD: var.c,v 1.20 1999/12/16 16:27:13 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.19 1999/12/09 18:18:24 espie Exp $";
+static char rcsid[] = "$OpenBSD: var.c,v 1.20 1999/12/16 16:27:13 espie Exp $";
#endif
#endif /* not lint */
@@ -484,7 +484,7 @@ Var_Set (name, val, ctxt)
if (v == (Var *) NIL) {
(void)VarAdd(name, val, ctxt);
} else {
- Buf_Discard(v->val, Buf_Size(v->val));
+ Buf_Reset(v->val);
Buf_AddString(v->val, val);
if (DEBUG(VAR)) {