1 /* 2 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. 3 * Copyright (c) 1988, 1989 by Adam de Boor 4 * Copyright (c) 1989 by Berkeley Softworks 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Adam de Boor. 9 * 10 * %sccs.include.redist.c% 11 * 12 * @(#)buf.h 5.4 (Berkeley) 12/28/90 13 */ 14 15 /*- 16 * buf.h -- 17 * Header for users of the buf library. 18 */ 19 20 #ifndef _BUF_H 21 #define _BUF_H 22 23 #include "sprite.h" 24 25 typedef unsigned char Byte; 26 27 typedef struct Buffer { 28 int size; /* Current size of the buffer */ 29 int left; /* Space left (== size - (inPtr - buffer)) */ 30 Byte *buffer; /* The buffer itself */ 31 Byte *inPtr; /* Place to write to */ 32 Byte *outPtr; /* Place to read from */ 33 } *Buffer; 34 35 Buffer Buf_Init(); /* Initialize a buffer */ 36 void Buf_Destroy(); /* Destroy a buffer */ 37 void Buf_AddBytes(); /* Add a range of bytes to a buffer */ 38 int Buf_GetByte(); /* Get a byte from a buffer */ 39 int Buf_GetBytes(); /* Get multiple bytes */ 40 void Buf_UngetByte(); /* Push a byte back into the buffer */ 41 void Buf_UngetBytes(); /* Push many bytes back into the buf */ 42 Byte *Buf_GetAll(); /* Get them all */ 43 void Buf_Discard(); /* Throw away some of the bytes */ 44 int Buf_Size(); /* See how many are there */ 45 46 /* Buf_AddByte adds a single byte to a buffer. */ 47 #define Buf_AddByte(bp, byte) \ 48 (--(bp)->left <= 0 ? Buf_OvAddByte(bp, byte) : \ 49 (void)(*(bp)->inPtr++ = (byte), *(bp)->inPtr = 0)) 50 51 void Buf_OvAddByte(); /* adds a byte when buffer overflows */ 52 53 #define BUF_ERROR 256 54 55 #endif _BUF_H 56