From f41efac821a90600bcf7536f8a348ad27508625b Mon Sep 17 00:00:00 2001 From: harti Date: Wed, 2 Feb 2005 11:21:26 +0000 Subject: Remove a couple of unused buffer functions. Submitted by: Max Okumoto --- usr.bin/make/buf.c | 154 ----------------------------------------------------- usr.bin/make/buf.h | 4 -- 2 files changed, 158 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/make/buf.c b/usr.bin/make/buf.c index ae02ca2..b9a4a43 100644 --- a/usr.bin/make/buf.c +++ b/usr.bin/make/buf.c @@ -142,160 +142,6 @@ Buf_AddBytes(Buffer *bp, size_t numBytes, const Byte *bytesPtr) /*- *----------------------------------------------------------------------- - * Buf_UngetByte -- - * Place the byte back at the beginning of the buffer. - * - * Results: - * SUCCESS if the byte was added ok. FAILURE if not. - * - * Side Effects: - * The byte is stuffed in the buffer and outPtr is decremented. - * - *----------------------------------------------------------------------- - */ -void -Buf_UngetByte(Buffer *bp, Byte byte) -{ - - if (bp->outPtr != bp->buffer) { - bp->outPtr--; - *bp->outPtr = byte; - - } else if (bp->outPtr == bp->inPtr) { - *bp->inPtr = byte; - bp->inPtr++; - bp->left--; - *bp->inPtr = 0; - - } else { - /* - * Yech. have to expand the buffer to stuff this thing in. - * We use a different expansion constant because people don't - * usually push back many bytes when they're doing it a byte at - * a time... - */ - size_t numBytes = bp->inPtr - bp->outPtr; - Byte *newBuf; - - newBuf = emalloc(bp->size + BUF_UNGET_INC); - memcpy(newBuf + BUF_UNGET_INC, bp->outPtr, numBytes + 1); - bp->outPtr = newBuf + BUF_UNGET_INC; - bp->inPtr = bp->outPtr + numBytes; - free(bp->buffer); - bp->buffer = newBuf; - bp->size += BUF_UNGET_INC; - bp->left = bp->size - (bp->inPtr - bp->buffer); - bp->outPtr -= 1; - *bp->outPtr = byte; - } -} - -/*- - *----------------------------------------------------------------------- - * Buf_UngetBytes -- - * Push back a series of bytes at the beginning of the buffer. - * - * Results: - * None. - * - * Side Effects: - * outPtr is decremented and the bytes copied into the buffer. - * - *----------------------------------------------------------------------- - */ -void -Buf_UngetBytes(Buffer *bp, size_t numBytes, Byte *bytesPtr) -{ - - if ((size_t)(bp->outPtr - bp->buffer) >= numBytes) { - bp->outPtr -= numBytes; - memcpy(bp->outPtr, bytesPtr, numBytes); - } else if (bp->outPtr == bp->inPtr) { - Buf_AddBytes(bp, numBytes, bytesPtr); - } else { - size_t curNumBytes = bp->inPtr - bp->outPtr; - Byte *newBuf; - size_t newBytes = max(numBytes, BUF_UNGET_INC); - - newBuf = emalloc(bp->size + newBytes); - memcpy(newBuf + newBytes, bp->outPtr, curNumBytes + 1); - bp->outPtr = newBuf + newBytes; - bp->inPtr = bp->outPtr + curNumBytes; - free(bp->buffer); - bp->buffer = newBuf; - bp->size += newBytes; - bp->left = bp->size - (bp->inPtr - bp->buffer); - bp->outPtr -= numBytes; - memcpy(bp->outPtr, bytesPtr, numBytes); - } -} - -/*- - *----------------------------------------------------------------------- - * Buf_GetByte -- - * Return the next byte from the buffer. Actually returns an integer. - * - * Results: - * Returns BUF_ERROR if there's no byte in the buffer, or the byte - * itself if there is one. - * - * Side Effects: - * outPtr is incremented and both outPtr and inPtr will be reset if - * the buffer is emptied. - * - *----------------------------------------------------------------------- - */ -int -Buf_GetByte(Buffer *bp) -{ - int res; - - if (bp->inPtr == bp->outPtr) - return (BUF_ERROR); - - res = (int)*bp->outPtr; - bp->outPtr += 1; - if (bp->outPtr == bp->inPtr) { - bp->outPtr = bp->inPtr = bp->buffer; - bp->left = bp->size; - *bp->inPtr = 0; - } - return (res); -} - -/*- - *----------------------------------------------------------------------- - * Buf_GetBytes -- - * Extract a number of bytes from the buffer. - * - * Results: - * The number of bytes gotten. - * - * Side Effects: - * The passed array is overwritten. - * - *----------------------------------------------------------------------- - */ -int -Buf_GetBytes(Buffer *bp, size_t numBytes, Byte *bytesPtr) -{ - - if ((size_t)(bp->inPtr - bp->outPtr) < numBytes) - numBytes = bp->inPtr - bp->outPtr; - - memcpy(bytesPtr, bp->outPtr, numBytes); - bp->outPtr += numBytes; - - if (bp->outPtr == bp->inPtr) { - bp->outPtr = bp->inPtr = bp->buffer; - bp->left = bp->size; - *bp->inPtr = 0; - } - return (numBytes); -} - -/*- - *----------------------------------------------------------------------- * Buf_GetAll -- * Get all the available data at once. * diff --git a/usr.bin/make/buf.h b/usr.bin/make/buf.h index da761ae..db25f70 100644 --- a/usr.bin/make/buf.h +++ b/usr.bin/make/buf.h @@ -82,10 +82,6 @@ typedef struct Buffer { void Buf_OvAddByte(Buffer *, Byte); void Buf_AddBytes(Buffer *, size_t, const Byte *); -void Buf_UngetByte(Buffer *, Byte); -void Buf_UngetBytes(Buffer *, size_t, Byte *); -int Buf_GetByte(Buffer *); -int Buf_GetBytes(Buffer *, size_t, Byte *); Byte *Buf_GetAll(Buffer *, size_t *); void Buf_Discard(Buffer *, size_t); size_t Buf_Size(Buffer *); -- cgit v1.1