HTML Tidy  5.4.0
The HTACG Tidy HTML Project
tidybuffio.h
Go to the documentation of this file.
1 #ifndef __TIDY_BUFFIO_H__
2 #define __TIDY_BUFFIO_H__
3 
4 /** @file tidybuffio.h - Treat buffer as an I/O stream.
5 
6  (c) 1998-2016 (W3C) MIT, ERCIM, Keio University
7  See tidy.h for the copyright notice.
8 
9  Requires buffer to automatically grow as bytes are added.
10  Must keep track of current read and write points.
11 
12 */
13 
14 #include "tidyplatform.h"
15 #include "tidy.h"
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 /** TidyBuffer - A chunk of memory */
23 struct _TidyBuffer
24 {
25  TidyAllocator* allocator; /**< Memory allocator */
26  byte* bp; /**< Pointer to bytes */
27  uint size; /**< # bytes currently in use */
28  uint allocated; /**< # bytes allocated */
29  uint next; /**< Offset of current input position */
30 };
31 
32 /** Initialize data structure using the default allocator */
33 TIDY_EXPORT void TIDY_CALL tidyBufInit( TidyBuffer* buf );
34 
35 /** Initialize data structure using the given custom allocator */
36 TIDY_EXPORT void TIDY_CALL tidyBufInitWithAllocator( TidyBuffer* buf, TidyAllocator* allocator );
37 
38 /** Free current buffer, allocate given amount, reset input pointer,
39  use the default allocator */
40 TIDY_EXPORT void TIDY_CALL tidyBufAlloc( TidyBuffer* buf, uint allocSize );
41 
42 /** Free current buffer, allocate given amount, reset input pointer,
43  use the given custom allocator */
44 TIDY_EXPORT void TIDY_CALL tidyBufAllocWithAllocator( TidyBuffer* buf,
45  TidyAllocator* allocator,
46  uint allocSize );
47 
48 /** Expand buffer to given size.
49 ** Chunk size is minimum growth. Pass 0 for default of 256 bytes.
50 */
51 TIDY_EXPORT void TIDY_CALL tidyBufCheckAlloc( TidyBuffer* buf,
52  uint allocSize, uint chunkSize );
53 
54 /** Free current contents and zero out */
55 TIDY_EXPORT void TIDY_CALL tidyBufFree( TidyBuffer* buf );
56 
57 /** Set buffer bytes to 0 */
58 TIDY_EXPORT void TIDY_CALL tidyBufClear( TidyBuffer* buf );
59 
60 /** Attach to existing buffer */
61 TIDY_EXPORT void TIDY_CALL tidyBufAttach( TidyBuffer* buf, byte* bp, uint size );
62 
63 /** Detach from buffer. Caller must free. */
64 TIDY_EXPORT void TIDY_CALL tidyBufDetach( TidyBuffer* buf );
65 
66 
67 /** Append bytes to buffer. Expand if necessary. */
68 TIDY_EXPORT void TIDY_CALL tidyBufAppend( TidyBuffer* buf, void* vp, uint size );
69 
70 /** Append one byte to buffer. Expand if necessary. */
71 TIDY_EXPORT void TIDY_CALL tidyBufPutByte( TidyBuffer* buf, byte bv );
72 
73 /** Get byte from end of buffer */
74 TIDY_EXPORT int TIDY_CALL tidyBufPopByte( TidyBuffer* buf );
75 
76 
77 /** Get byte from front of buffer. Increment input offset. */
78 TIDY_EXPORT int TIDY_CALL tidyBufGetByte( TidyBuffer* buf );
79 
80 /** At end of buffer? */
81 TIDY_EXPORT Bool TIDY_CALL tidyBufEndOfInput( TidyBuffer* buf );
82 
83 /** Put a byte back into the buffer. Decrement input offset. */
84 TIDY_EXPORT void TIDY_CALL tidyBufUngetByte( TidyBuffer* buf, byte bv );
85 
86 
87 /**************
88  TIDY
89 **************/
90 
91 /* Forward declarations
92 */
93 
94 /** Initialize a buffer input source */
95 TIDY_EXPORT void TIDY_CALL tidyInitInputBuffer( TidyInputSource* inp, TidyBuffer* buf );
96 
97 /** Initialize a buffer output sink */
98 TIDY_EXPORT void TIDY_CALL tidyInitOutputBuffer( TidyOutputSink* outp, TidyBuffer* buf );
99 
100 #ifdef __cplusplus
101 }
102 #endif
103 #endif /* __TIDY_BUFFIO_H__ */
104 
105 /*
106  * local variables:
107  * mode: c
108  * indent-tabs-mode: nil
109  * c-basic-offset: 4
110  * eval: (c-set-offset 'substatement-open 0)
111  * end:
112  */
void TIDY_CALL tidyBufAlloc(TidyBuffer *buf, uint allocSize)
Free current buffer, allocate given amount, reset input pointer, use the default allocator.
uint allocated
bytes allocated
Definition: tidybuffio.h:28
#define TIDY_CALL
Definition: tidyplatform.h:562
int TIDY_CALL tidyBufPopByte(TidyBuffer *buf)
Get byte from end of buffer.
void TIDY_CALL tidyBufAttach(TidyBuffer *buf, byte *bp, uint size)
Attach to existing buffer.
void TIDY_CALL tidyBufClear(TidyBuffer *buf)
Set buffer bytes to 0.
void TIDY_CALL tidyInitInputBuffer(TidyInputSource *inp, TidyBuffer *buf)
Initialize a buffer input source.
unsigned char byte
Definition: tidyplatform.h:550
int TIDY_CALL tidyBufGetByte(TidyBuffer *buf)
Get byte from front of buffer.
void TIDY_CALL tidyBufUngetByte(TidyBuffer *buf, byte bv)
Put a byte back into the buffer.
void TIDY_CALL tidyBufPutByte(TidyBuffer *buf, byte bv)
Append one byte to buffer.
Bool TIDY_CALL tidyBufEndOfInput(TidyBuffer *buf)
At end of buffer?
Bool
Definition: tidyplatform.h:593
Defines HTML Tidy API implemented by tidy library.
void TIDY_CALL tidyInitOutputBuffer(TidyOutputSink *outp, TidyBuffer *buf)
Initialize a buffer output sink.
Platform specifics
void TIDY_CALL tidyBufDetach(TidyBuffer *buf)
Detach from buffer.
uint next
Offset of current input position.
Definition: tidybuffio.h:29
An allocator.
Definition: tidy.h:225
byte * bp
Pointer to bytes.
Definition: tidybuffio.h:26
void TIDY_CALL tidyBufAppend(TidyBuffer *buf, void *vp, uint size)
Append bytes to buffer.
uint size
bytes currently in use
Definition: tidybuffio.h:27
unsigned int uint
Definition: tidyplatform.h:525
void TIDY_CALL tidyBufFree(TidyBuffer *buf)
Free current contents and zero out.
TidyAllocator * allocator
Memory allocator.
Definition: tidybuffio.h:25
void TIDY_CALL tidyBufInit(TidyBuffer *buf)
Initialize data structure using the default allocator.
TIDY_STRUCT struct _TidyInputSource TidyInputSource
TidyInputSource - Delivers raw bytes of input.
void TIDY_CALL tidyBufAllocWithAllocator(TidyBuffer *buf, TidyAllocator *allocator, uint allocSize)
Free current buffer, allocate given amount, reset input pointer, use the given custom allocator...
void TIDY_CALL tidyBufInitWithAllocator(TidyBuffer *buf, TidyAllocator *allocator)
Initialize data structure using the given custom allocator.
void TIDY_CALL tidyBufCheckAlloc(TidyBuffer *buf, uint allocSize, uint chunkSize)
Expand buffer to given size.
TidyBuffer - A chunk of memory.
Definition: tidybuffio.h:23
#define TIDY_STRUCT
Definition: tidyplatform.h:547
TIDY_STRUCT struct _TidyOutputSink TidyOutputSink
TidyOutputSink - accepts raw bytes of output.