1#ifndef __TIDY_BUFFIO_H__
2#define __TIDY_BUFFIO_H__
3
4/** @file buffio.h - Treat buffer as an I/O stream.
5
6 (c) 1998-2007 (W3C) MIT, ERCIM, Keio University
7 See tidy.h for the copyright notice.
8
9 CVS Info :
10
11 $Author: arnaud02 $
12 $Date: 2007/01/23 11:17:45 $
13 $Revision: 1.9 $
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 TidyAllocator* allocator; /**< Memory allocator */
32 byte* bp; /**< Pointer to bytes */
33 uint size; /**< # bytes currently in use */
34 uint allocated; /**< # bytes allocated */
35 uint next; /**< Offset of current input position */
36};
37
38/** Initialize data structure using the default allocator */
39TIDY_EXPORT void TIDY_CALL tidyBufInit( TidyBuffer* buf );
40
41/** Initialize data structure using the given custom allocator */
42TIDY_EXPORT void TIDY_CALL tidyBufInitWithAllocator( TidyBuffer* buf, TidyAllocator* allocator );
43
44/** Free current buffer, allocate given amount, reset input pointer,
45 use the default allocator */
46TIDY_EXPORT void TIDY_CALL tidyBufAlloc( TidyBuffer* buf, uint allocSize );
47
48/** Free current buffer, allocate given amount, reset input pointer,
49 use the given custom allocator */
50TIDY_EXPORT void TIDY_CALL tidyBufAllocWithAllocator( TidyBuffer* buf,
51 TidyAllocator* allocator,
52 uint allocSize );
53
54/** Expand buffer to given size.
55** Chunk size is minimum growth. Pass 0 for default of 256 bytes.
56*/
57TIDY_EXPORT void TIDY_CALL tidyBufCheckAlloc( TidyBuffer* buf,
58 uint allocSize, uint chunkSize );
59
60/** Free current contents and zero out */
61TIDY_EXPORT void TIDY_CALL tidyBufFree( TidyBuffer* buf );
62
63/** Set buffer bytes to 0 */
64TIDY_EXPORT void TIDY_CALL tidyBufClear( TidyBuffer* buf );
65
66/** Attach to existing buffer */
67TIDY_EXPORT void TIDY_CALL tidyBufAttach( TidyBuffer* buf, byte* bp, uint size );
68
69/** Detach from buffer. Caller must free. */
70TIDY_EXPORT void TIDY_CALL tidyBufDetach( TidyBuffer* buf );
71
72
73/** Append bytes to buffer. Expand if necessary. */
74TIDY_EXPORT void TIDY_CALL tidyBufAppend( TidyBuffer* buf, void* vp, uint size );
75
76/** Append one byte to buffer. Expand if necessary. */
77TIDY_EXPORT void TIDY_CALL tidyBufPutByte( TidyBuffer* buf, byte bv );
78
79/** Get byte from end of buffer */
80TIDY_EXPORT int TIDY_CALL tidyBufPopByte( TidyBuffer* buf );
81
82
83/** Get byte from front of buffer. Increment input offset. */
84TIDY_EXPORT int TIDY_CALL tidyBufGetByte( TidyBuffer* buf );
85
86/** At end of buffer? */
87TIDY_EXPORT Bool TIDY_CALL tidyBufEndOfInput( TidyBuffer* buf );
88
89/** Put a byte back into the buffer. Decrement input offset. */
90TIDY_EXPORT void TIDY_CALL tidyBufUngetByte( TidyBuffer* buf, byte bv );
91
92
93/**************
94 TIDY
95**************/
96
97/* Forward declarations
98*/
99
100/** Initialize a buffer input source */
101TIDY_EXPORT void TIDY_CALL tidyInitInputBuffer( TidyInputSource* inp, TidyBuffer* buf );
102
103/** Initialize a buffer output sink */
104TIDY_EXPORT void TIDY_CALL tidyInitOutputBuffer( TidyOutputSink* outp, TidyBuffer* buf );
105
106#ifdef __cplusplus
107}
108#endif
109#endif /* __TIDY_BUFFIO_H__ */
110
111/*
112 * local variables:
113 * mode: c
114 * indent-tabs-mode: nil
115 * c-basic-offset: 4
116 * eval: (c-set-offset 'substatement-open 0)
117 * end:
118 */
119