Hiding pointer in typedefs is evil. 'Buffer *' -> 'Buffer'
[dragonfly.git] / usr.bin / make / buf.h
CommitLineData
9863ce62
MO
1#ifndef buf_h_a61a6812
2#define buf_h_a61a6812
984263bc 3/*
9a309bcc
MD
4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved.
984263bc
MD
6 * Copyright (c) 1988, 1989 by Adam de Boor
7 * Copyright (c) 1989 by Berkeley Softworks
8 * All rights reserved.
9 *
10 * This code is derived from software contributed to Berkeley by
11 * Adam de Boor.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. All advertising materials mentioning features or use of this software
22 * must display the following acknowledgement:
23 * This product includes software developed by the University of
24 * California, Berkeley and its contributors.
25 * 4. Neither the name of the University nor the names of its contributors
26 * may be used to endorse or promote products derived from this software
27 * without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 * SUCH DAMAGE.
40 *
41 * from: @(#)buf.h 8.1 (Berkeley) 6/6/93
42 * $FreeBSD: src/usr.bin/make/buf.h,v 1.9 1999/08/28 01:03:26 peter Exp $
6a3d9147 43 * $DragonFly: src/usr.bin/make/buf.h,v 1.10 2005/01/06 13:18:58 okumoto Exp $
984263bc
MD
44 */
45
46/*-
47 * buf.h --
48 * Header for users of the buf library.
49 */
50
9863ce62 51#include <sys/types.h>
984263bc 52
1e609a21 53#include "sprite.h"
984263bc 54
9863ce62
MO
55/*
56 * There are several places where expandable buffers are used (parse.c and
57 * var.c). This constant is merely the starting point for those buffers. If
58 * lines tend to be much shorter than this, it would be best to reduce BSIZE.
59 * If longer, it should be increased. Reducing it will cause more copying to
60 * be done for longer lines, but will save space for shorter ones. In any
61 * case, it ought to be a power of two simply because most storage allocation
62 * schemes allocate in powers of two.
63 */
64#define MAKE_BSIZE 256 /* starting size for expandable buffers */
65
66#define BUF_ERROR 256
67
984263bc
MD
68typedef char Byte;
69
70typedef struct Buffer {
4f762dd1
MO
71 size_t size; /* Current size of the buffer */
72 size_t left; /* Space left (== size - (inPtr - buffer)) */
73 Byte *buffer; /* The buffer itself */
74 Byte *inPtr; /* Place to write to */
75 Byte *outPtr; /* Place to read from */
6a3d9147 76} Buffer;
984263bc
MD
77
78/* Buf_AddByte adds a single byte to a buffer. */
79#define Buf_AddByte(bp, byte) \
4f762dd1 80 (void)(--(bp)->left <= 0 ? Buf_OvAddByte((bp), (byte)), 1 : \
984263bc
MD
81 (*(bp)->inPtr++ = (byte), *(bp)->inPtr = 0), 1)
82
6a3d9147
MO
83void Buf_OvAddByte(Buffer *, Byte);
84void Buf_AddBytes(Buffer *, size_t, const Byte *);
85void Buf_UngetByte(Buffer *, Byte);
86void Buf_UngetBytes(Buffer *, size_t, Byte *);
87int Buf_GetByte(Buffer *);
88int Buf_GetBytes(Buffer *, size_t, Byte *);
89Byte *Buf_GetAll(Buffer *, size_t *);
90void Buf_Discard(Buffer *, size_t);
91size_t Buf_Size(Buffer *);
92Buffer *Buf_Init(size_t);
93void Buf_Destroy(Buffer *, Boolean);
94void Buf_ReplaceLastByte(Buffer *, Byte);
984263bc 95
9863ce62 96#endif /* buf_h_a61a6812 */