xref: /original-bsd/usr.bin/make/buf.h (revision 6849621a)
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.5 (Berkeley) 05/24/93
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 /* 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_AddBytes __P((Buffer, int, Byte *));
43 void	 Buf_Destroy __P((Buffer, Boolean));
44 void	 Buf_Discard __P((Buffer, int));
45 Byte	*Buf_GetAll __P((Buffer, int *));
46 int	 Buf_GetByte __P((Buffer));
47 int	 Buf_GetBytes __P((Buffer, int, Byte *));
48 Buffer	 Buf_Init __P((int));
49 void	 Buf_OvAddByte __P((Buffer, int));
50 int	 Buf_Size __P((Buffer));
51 void	 Buf_UngetByte __P((Buffer, int));
52 void	 Buf_UngetBytes __P((Buffer, int, Byte *));
53 
54 #endif /* _BUF_H */
55