1#ifndef __BUFFIO_H__
2#define __BUFFIO_H__
3
4/** @file buffio.h - Treat buffer as an I/O stream.
5
6  (c) 1998-2005 (W3C) MIT, ERCIM, Keio University
7  See tidy.h for the copyright notice.
8
9  CVS Info :
10
11    $Author: iccir $
12    $Date: 2007/01/30 23:46:51 $
13    $Revision: 1.3 $
14
15  Requires buffer to automatically grow as bytes are added.
16  Must keep track of current read and write points.
17
18*/
19
20#include "platform.h"
21#include "tidy.h"
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27/** TidyBuffer - A chunk of memory */
28TIDY_STRUCT
29struct _TidyBuffer
30{
31    byte* bp;           /**< Pointer to bytes */
32    uint  size;         /**< # bytes currently in use */
33    uint  allocated;    /**< # bytes allocated */
34    uint  next;         /**< Offset of current input position */
35};
36
37/** Zero out data structure */
38TIDY_EXPORT void TIDY_CALL tidyBufInit( TidyBuffer* buf );
39
40/** Free current buffer, allocate given amount, reset input pointer */
41TIDY_EXPORT void TIDY_CALL tidyBufAlloc( TidyBuffer* buf, uint allocSize );
42
43/** Expand buffer to given size.
44**  Chunk size is minimum growth. Pass 0 for default of 256 bytes.
45*/
46TIDY_EXPORT void TIDY_CALL tidyBufCheckAlloc( TidyBuffer* buf,
47                                             uint allocSize, uint chunkSize );
48
49/** Free current contents and zero out */
50TIDY_EXPORT void TIDY_CALL tidyBufFree( TidyBuffer* buf );
51
52/** Set buffer bytes to 0 */
53TIDY_EXPORT void TIDY_CALL tidyBufClear( TidyBuffer* buf );
54
55/** Attach to existing buffer */
56TIDY_EXPORT void TIDY_CALL tidyBufAttach( TidyBuffer* buf, byte* bp, uint size );
57
58/** Detach from buffer.  Caller must free. */
59TIDY_EXPORT void TIDY_CALL tidyBufDetach( TidyBuffer* buf );
60
61
62/** Append bytes to buffer.  Expand if necessary. */
63TIDY_EXPORT void TIDY_CALL tidyBufAppend( TidyBuffer* buf, void* vp, uint size );
64
65/** Append one byte to buffer.  Expand if necessary. */
66TIDY_EXPORT void TIDY_CALL tidyBufPutByte( TidyBuffer* buf, byte bv );
67
68/** Get byte from end of buffer */
69TIDY_EXPORT int TIDY_CALL  tidyBufPopByte( TidyBuffer* buf );
70
71
72/** Get byte from front of buffer.  Increment input offset. */
73TIDY_EXPORT int TIDY_CALL  tidyBufGetByte( TidyBuffer* buf );
74
75/** At end of buffer? */
76TIDY_EXPORT Bool TIDY_CALL tidyBufEndOfInput( TidyBuffer* buf );
77
78/** Put a byte back into the buffer.  Decrement input offset. */
79TIDY_EXPORT void TIDY_CALL tidyBufUngetByte( TidyBuffer* buf, byte bv );
80
81
82/**************
83   TIDY
84**************/
85
86/* Forward declarations
87*/
88
89/** Initialize a buffer input source */
90TIDY_EXPORT void TIDY_CALL tidyInitInputBuffer( TidyInputSource* inp, TidyBuffer* buf );
91
92/** Initialize a buffer output sink */
93TIDY_EXPORT void TIDY_CALL tidyInitOutputBuffer( TidyOutputSink* outp, TidyBuffer* buf );
94
95#ifdef __cplusplus
96}
97#endif
98#endif /* __BUFFIO_H__ */
99