xref: /original-bsd/usr.bin/make/buf.h (revision 27393bdf)
1 /*
2  * Copyright (c) 1988, 1989, 1990, 1993
3  *	The Regents of the University of California.  All rights reserved.
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	8.2 (Berkeley) 04/28/95
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 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 /* Buf_AddByte adds a single byte to a buffer. */
36 #define	Buf_AddByte(bp, byte) \
37 	(void) (--(bp)->left <= 0 ? Buf_OvAddByte(bp, byte), 1 : \
38 		(*(bp)->inPtr++ = (byte), *(bp)->inPtr = 0), 1)
39 
40 #define BUF_ERROR 256
41 
42 void Buf_OvAddByte __P((Buffer, int));
43 void Buf_AddBytes __P((Buffer, int, Byte *));
44 void Buf_UngetByte __P((Buffer, int));
45 void Buf_UngetBytes __P((Buffer, int, Byte *));
46 int Buf_GetByte __P((Buffer));
47 int Buf_GetBytes __P((Buffer, int, Byte *));
48 Byte *Buf_GetAll __P((Buffer, int *));
49 void Buf_Discard __P((Buffer, int));
50 int Buf_Size __P((Buffer));
51 Buffer Buf_Init __P((int));
52 void Buf_Destroy __P((Buffer, Boolean));
53 
54 #endif /* _BUF_H */
55