1141104Sharti/*-
294589Sobrien * Copyright (c) 1988, 1989, 1990, 1993
394589Sobrien *	The Regents of the University of California.  All rights reserved.
45814Sjkh * Copyright (c) 1988, 1989 by Adam de Boor
51590Srgrimes * Copyright (c) 1989 by Berkeley Softworks
61590Srgrimes * All rights reserved.
71590Srgrimes *
81590Srgrimes * This code is derived from software contributed to Berkeley by
91590Srgrimes * Adam de Boor.
101590Srgrimes *
111590Srgrimes * Redistribution and use in source and binary forms, with or without
121590Srgrimes * modification, are permitted provided that the following conditions
131590Srgrimes * are met:
141590Srgrimes * 1. Redistributions of source code must retain the above copyright
151590Srgrimes *    notice, this list of conditions and the following disclaimer.
161590Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
171590Srgrimes *    notice, this list of conditions and the following disclaimer in the
181590Srgrimes *    documentation and/or other materials provided with the distribution.
191590Srgrimes * 3. All advertising materials mentioning features or use of this software
201590Srgrimes *    must display the following acknowledgement:
211590Srgrimes *	This product includes software developed by the University of
221590Srgrimes *	California, Berkeley and its contributors.
231590Srgrimes * 4. Neither the name of the University nor the names of its contributors
241590Srgrimes *    may be used to endorse or promote products derived from this software
251590Srgrimes *    without specific prior written permission.
261590Srgrimes *
271590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
281590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
291590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
301590Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
311590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
321590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
331590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
341590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
351590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
361590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
371590Srgrimes * SUCH DAMAGE.
381590Srgrimes *
3994589Sobrien *	@(#)buf.h	8.2 (Berkeley) 4/28/95
4050477Speter * $FreeBSD: releng/10.3/usr.bin/make/buf.h 146177 2005-05-13 08:53:00Z harti $
411590Srgrimes */
421590Srgrimes
43141104Sharti#ifndef buf_h_a61a6812
44141104Sharti#define	buf_h_a61a6812
45141104Sharti
461590Srgrimes/*-
471590Srgrimes * buf.h --
481590Srgrimes *	Header for users of the buf library.
491590Srgrimes */
501590Srgrimes
51141104Sharti#include <sys/types.h>
521590Srgrimes
53146177Sharti#include "util.h"
541590Srgrimes
55141104Sharti/*
56141104Sharti * There are several places where expandable buffers are used (parse.c and
57141104Sharti * var.c). This constant is merely the starting point for those buffers. If
58141104Sharti * lines tend to be much shorter than this, it would be best to reduce BSIZE.
59141104Sharti * If longer, it should be increased. Reducing it will cause more copying to
60141104Sharti * be done for longer lines, but will save space for shorter ones. In any
61141104Sharti * case, it ought to be a power of two simply because most storage allocation
62141104Sharti * schemes allocate in powers of two.
63141104Sharti */
64141104Sharti#define	MAKE_BSIZE	256	/* starting size for expandable buffers */
65141104Sharti
66141290Sharti#define	BUF_DEF_SIZE	256	/* Default buffer size */
67141290Sharti#define	BUF_ADD_INC	256	/* Expansion increment when Adding */
68141104Sharti
695814Sjkhtypedef char Byte;
701590Srgrimes
711590Srgrimestypedef struct Buffer {
72141290Sharti	size_t	size;	/* Current size of the buffer */
73141290Sharti	Byte	*buf;	/* The buffer itself */
74141290Sharti	Byte	*end;	/* Place to write to */
75141133Sharti} Buffer;
761590Srgrimes
77141290Shartivoid Buf_AddByte(Buffer *, Byte);
78141133Shartivoid Buf_AddBytes(Buffer *, size_t, const Byte *);
79143957Shartivoid Buf_Append(Buffer *, const char []);
80143957Shartivoid Buf_AppendBuf(Buffer *, const Buffer *);
81143957Shartivoid Buf_AppendRange(Buffer *, const char [], const char *);
82143957Shartivoid Buf_Clear(Buffer *);
83143957Shartichar *Buf_Data(const Buffer *);
84143957Shartivoid Buf_Destroy(Buffer *, Boolean);
85141133ShartiByte *Buf_GetAll(Buffer *, size_t *);
86141133ShartiBuffer *Buf_Init(size_t);
87143957Shartichar *Buf_Peel(Buffer *);
88141133Shartivoid Buf_ReplaceLastByte(Buffer *, Byte);
89143957Shartisize_t Buf_Size(const Buffer *);
90141454Shartivoid Buf_StripNewlines(Buffer *);
91141436Sharti
92141104Sharti#endif /* buf_h_a61a6812 */
93