version 1.9, 1999/12/16 16:41:41 |
version 1.10, 1999/12/16 16:46:38 |
|
|
#include "sprite.h" |
#include "sprite.h" |
|
|
typedef struct Buffer { |
typedef struct Buffer { |
size_t size; /* Current size of the buffer */ |
char *buffer; /* The buffer itself. */ |
size_t left; /* Space left (== size - (inPtr - buffer)) */ |
char *inPtr; /* Place to write to. */ |
char *buffer; /* The buffer itself */ |
char *endPtr; /* End of allocated space. */ |
char *inPtr; /* Place to write to */ |
|
char *outPtr; /* Place to read from */ |
|
} *Buffer; |
} *Buffer; |
|
|
/* Internal support for Buf_AddChar. */ |
/* Internal support for Buf_AddChar. */ |
void BufOverflow __P((Buffer)); |
void BufOverflow __P((Buffer)); |
|
|
/* Buf_AddChar -- Add a single char to a buffer. */ |
/* User interface */ |
|
|
|
/* Buf_AddChar -- Add a single char to buffer. */ |
#define Buf_AddChar(bp, byte) \ |
#define Buf_AddChar(bp, byte) \ |
do { \ |
do { \ |
if (--(bp)->left == 0) \ |
if ((bp)->endPtr - (bp)->inPtr <= 1) \ |
BufOverflow(bp); \ |
BufOverflow(bp); \ |
*(bp)->inPtr++ = (byte); \ |
*(bp)->inPtr++ = (byte); \ |
} while (0) |
} while (0) |
|
|
|
|
/* Buf_AddChars -- Add a number of chars to the buffer. */ |
/* Buf_AddChars -- Add a number of chars to the buffer. */ |
void Buf_AddChars __P((Buffer, size_t, const char *)); |
void Buf_AddChars __P((Buffer, size_t, const char *)); |
|
/* Buf_Reset -- Remove all chars from a buffer. */ |
|
#define Buf_Reset(bp) ((void)((bp)->inPtr = (bp)->buffer)) |
/* Buf_AddSpace -- Add a space to buffer. */ |
/* Buf_AddSpace -- Add a space to buffer. */ |
#define Buf_AddSpace(b) Buf_AddChar((b), ' ') |
#define Buf_AddSpace(b) Buf_AddChar((b), ' ') |
/* Buf_AddString -- Add the contents of a NULL terminated string to buffer. */ |
/* Buf_AddString -- Add the contents of a NULL terminated string to buffer. */ |
|
|
#define Buf_AddInterval(b, s, e) Buf_AddChars((b), (e) - (s), (s)) |
#define Buf_AddInterval(b, s, e) Buf_AddChars((b), (e) - (s), (s)) |
|
|
/* Buf_Retrieve -- Retrieve data from a buffer, as a NULL terminated string. */ |
/* Buf_Retrieve -- Retrieve data from a buffer, as a NULL terminated string. */ |
#define Buf_Retrieve(bp) (*(bp)->inPtr = '\0', (bp)->outPtr) |
#define Buf_Retrieve(bp) (*(bp)->inPtr = '\0', (bp)->buffer) |
|
|
/* Buf_Size -- Return the number of chars in the given buffer. |
/* Buf_Size -- Return the number of chars in the given buffer. |
* Doesn't include the null-terminating char. */ |
* Doesn't include the null-terminating char. */ |
#define Buf_Size(bp) ((size_t)((bp)->inPtr - (bp)->outPtr)) |
#define Buf_Size(bp) ((size_t)((bp)->inPtr - (bp)->buffer)) |
|
|
void Buf_Reset __P((Buffer)); |
/* Buf_Init -- Initialize a buffer. If no initial size is given, |
|
* a reasonable default is used. */ |
Buffer Buf_Init __P((size_t)); |
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_Destroy __P((Buffer, Boolean)); |
|
/* Buf_ReplaceLastChar -- Replace the last char in a buffer. */ |
void Buf_ReplaceLastChar __P((Buffer, char)); |
void Buf_ReplaceLastChar __P((Buffer, char)); |
|
|
#endif /* _BUF_H */ |
#endif /* _BUF_H */ |