diff options
Diffstat (limited to 'usr.bin/make/buf.c')
-rw-r--r-- | usr.bin/make/buf.c | 79 |
1 files changed, 40 insertions, 39 deletions
diff --git a/usr.bin/make/buf.c b/usr.bin/make/buf.c index 49523af..c344738 100644 --- a/usr.bin/make/buf.c +++ b/usr.bin/make/buf.c @@ -64,8 +64,8 @@ __FBSDID("$FreeBSD$"); */ #define BufExpand(bp,nb) \ if (bp->left < (nb)+1) {\ - int newSize = (bp)->size + max((nb)+1,BUF_ADD_INC); \ - Byte *newBuf = (Byte *) erealloc((bp)->buffer, newSize); \ + int newSize = (bp)->size + max((nb) + 1, BUF_ADD_INC); \ + Byte *newBuf = (Byte *)erealloc((bp)->buffer, newSize); \ \ (bp)->inPtr = newBuf + ((bp)->inPtr - (bp)->buffer); \ (bp)->outPtr = newBuf + ((bp)->outPtr - (bp)->buffer);\ @@ -92,10 +92,10 @@ __FBSDID("$FreeBSD$"); *----------------------------------------------------------------------- */ void -Buf_OvAddByte (Buffer bp, int byte) +Buf_OvAddByte(Buffer bp, int byte) { bp->left = 0; - BufExpand (bp, 1); + BufExpand(bp, 1); *bp->inPtr++ = byte; bp->left--; @@ -105,7 +105,7 @@ Buf_OvAddByte (Buffer bp, int byte) */ *bp->inPtr = 0; } - + /*- *----------------------------------------------------------------------- * Buf_AddBytes -- @@ -120,12 +120,12 @@ Buf_OvAddByte (Buffer bp, int byte) *----------------------------------------------------------------------- */ void -Buf_AddBytes (Buffer bp, int numBytes, const Byte *bytesPtr) +Buf_AddBytes(Buffer bp, int numBytes, const Byte *bytesPtr) { - BufExpand (bp, numBytes); + BufExpand(bp, numBytes); - memcpy (bp->inPtr, bytesPtr, numBytes); + memcpy(bp->inPtr, bytesPtr, numBytes); bp->inPtr += numBytes; bp->left -= numBytes; @@ -134,7 +134,7 @@ Buf_AddBytes (Buffer bp, int numBytes, const Byte *bytesPtr) */ *bp->inPtr = 0; } - + /*- *----------------------------------------------------------------------- * Buf_UngetByte -- @@ -149,7 +149,7 @@ Buf_AddBytes (Buffer bp, int numBytes, const Byte *bytesPtr) *----------------------------------------------------------------------- */ void -Buf_UngetByte (Buffer bp, int byte) +Buf_UngetByte(Buffer bp, int byte) { if (bp->outPtr != bp->buffer) { @@ -171,10 +171,11 @@ Buf_UngetByte (Buffer bp, int byte) Byte *newBuf; newBuf = (Byte *)emalloc(bp->size + BUF_UNGET_INC); - memcpy ((char *)(newBuf+BUF_UNGET_INC), (char *)bp->outPtr, numBytes+1); + memcpy((char *)(newBuf+BUF_UNGET_INC), (char *)bp->outPtr, + numBytes + 1); bp->outPtr = newBuf + BUF_UNGET_INC; bp->inPtr = bp->outPtr + numBytes; - free ((char *)bp->buffer); + free((char *)bp->buffer); bp->buffer = newBuf; bp->size += BUF_UNGET_INC; bp->left = bp->size - (bp->inPtr - bp->buffer); @@ -182,7 +183,7 @@ Buf_UngetByte (Buffer bp, int byte) *bp->outPtr = byte; } } - + /*- *----------------------------------------------------------------------- * Buf_UngetBytes -- @@ -197,32 +198,32 @@ Buf_UngetByte (Buffer bp, int byte) *----------------------------------------------------------------------- */ void -Buf_UngetBytes (Buffer bp, int numBytes, Byte *bytesPtr) +Buf_UngetBytes(Buffer bp, int numBytes, Byte *bytesPtr) { if (bp->outPtr - bp->buffer >= numBytes) { bp->outPtr -= numBytes; - memcpy (bp->outPtr, bytesPtr, numBytes); + memcpy(bp->outPtr, bytesPtr, numBytes); } else if (bp->outPtr == bp->inPtr) { - Buf_AddBytes (bp, numBytes, bytesPtr); + Buf_AddBytes(bp, numBytes, bytesPtr); } else { int curNumBytes = bp->inPtr - bp->outPtr; Byte *newBuf; int newBytes = max(numBytes,BUF_UNGET_INC); newBuf = (Byte *)emalloc (bp->size + newBytes); - memcpy((char *)(newBuf+newBytes), (char *)bp->outPtr, curNumBytes+1); + memcpy((char *)(newBuf+newBytes), (char *)bp->outPtr, curNumBytes + 1); bp->outPtr = newBuf + newBytes; bp->inPtr = bp->outPtr + curNumBytes; - free ((char *)bp->buffer); + free((char *)bp->buffer); bp->buffer = newBuf; bp->size += newBytes; bp->left = bp->size - (bp->inPtr - bp->buffer); bp->outPtr -= numBytes; - memcpy ((char *)bp->outPtr, (char *)bytesPtr, numBytes); + memcpy((char *)bp->outPtr, (char *)bytesPtr, numBytes); } } - + /*- *----------------------------------------------------------------------- * Buf_GetByte -- @@ -239,14 +240,14 @@ Buf_UngetBytes (Buffer bp, int numBytes, Byte *bytesPtr) *----------------------------------------------------------------------- */ int -Buf_GetByte (Buffer bp) +Buf_GetByte(Buffer bp) { int res; if (bp->inPtr == bp->outPtr) { return (BUF_ERROR); } else { - res = (int) *bp->outPtr; + res = (int)*bp->outPtr; bp->outPtr += 1; if (bp->outPtr == bp->inPtr) { bp->outPtr = bp->inPtr = bp->buffer; @@ -256,7 +257,7 @@ Buf_GetByte (Buffer bp) return (res); } } - + /*- *----------------------------------------------------------------------- * Buf_GetBytes -- @@ -271,13 +272,13 @@ Buf_GetByte (Buffer bp) *----------------------------------------------------------------------- */ int -Buf_GetBytes (Buffer bp, int numBytes, Byte *bytesPtr) +Buf_GetBytes(Buffer bp, int numBytes, Byte *bytesPtr) { if (bp->inPtr - bp->outPtr < numBytes) { numBytes = bp->inPtr - bp->outPtr; } - memcpy (bytesPtr, bp->outPtr, numBytes); + memcpy(bytesPtr, bp->outPtr, numBytes); bp->outPtr += numBytes; if (bp->outPtr == bp->inPtr) { @@ -287,7 +288,7 @@ Buf_GetBytes (Buffer bp, int numBytes, Byte *bytesPtr) } return (numBytes); } - + /*- *----------------------------------------------------------------------- * Buf_GetAll -- @@ -302,7 +303,7 @@ Buf_GetBytes (Buffer bp, int numBytes, Byte *bytesPtr) *----------------------------------------------------------------------- */ Byte * -Buf_GetAll (Buffer bp, int *numBytesPtr) +Buf_GetAll(Buffer bp, int *numBytesPtr) { if (numBytesPtr != (int *)NULL) { @@ -311,7 +312,7 @@ Buf_GetAll (Buffer bp, int *numBytesPtr) return (bp->outPtr); } - + /*- *----------------------------------------------------------------------- * Buf_Discard -- @@ -326,7 +327,7 @@ Buf_GetAll (Buffer bp, int *numBytesPtr) *----------------------------------------------------------------------- */ void -Buf_Discard (Buffer bp, int numBytes) +Buf_Discard(Buffer bp, int numBytes) { if (bp->inPtr - bp->outPtr <= numBytes) { @@ -337,7 +338,7 @@ Buf_Discard (Buffer bp, int numBytes) bp->outPtr += numBytes; } } - + /*- *----------------------------------------------------------------------- * Buf_Size -- @@ -353,11 +354,11 @@ Buf_Discard (Buffer bp, int numBytes) *----------------------------------------------------------------------- */ int -Buf_Size (Buffer buf) +Buf_Size(Buffer buf) { return (buf->inPtr - buf->outPtr); } - + /*- *----------------------------------------------------------------------- * Buf_Init -- @@ -374,7 +375,7 @@ Buf_Size (Buffer buf) *----------------------------------------------------------------------- */ Buffer -Buf_Init (int size) +Buf_Init(int size) { Buffer bp; /* New Buffer */ @@ -390,7 +391,7 @@ Buf_Init (int size) return (bp); } - + /*- *----------------------------------------------------------------------- * Buf_Destroy -- @@ -405,15 +406,15 @@ Buf_Init (int size) *----------------------------------------------------------------------- */ void -Buf_Destroy (Buffer buf, Boolean freeData) +Buf_Destroy(Buffer buf, Boolean freeData) { if (freeData) { - free ((char *)buf->buffer); + free((char *)buf->buffer); } - free ((char *)buf); + free((char *)buf); } - + /*- *----------------------------------------------------------------------- * Buf_ReplaceLastByte -- @@ -429,7 +430,7 @@ Buf_Destroy (Buffer buf, Boolean freeData) *----------------------------------------------------------------------- */ void -Buf_ReplaceLastByte (Buffer buf, int byte) +Buf_ReplaceLastByte(Buffer buf, int byte) { if (buf->inPtr == buf->outPtr) Buf_AddByte(buf, byte); |