Remove a couple of unused buffer functions.

Submitted by:	Max Okumoto <okumoto@ucsd.edu>
This commit is contained in:
harti 2005-02-02 11:21:26 +00:00
parent d2c9006fb5
commit f41efac821
2 changed files with 0 additions and 158 deletions

View File

@ -140,160 +140,6 @@ Buf_AddBytes(Buffer *bp, size_t numBytes, const Byte *bytesPtr)
*bp->inPtr = 0;
}
/*-
*-----------------------------------------------------------------------
* 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 --

View File

@ -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 *);