HTML Tidy  5.9.15
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 /**************************************************************************//**
5  * @file
6  * Treat buffer as a stream that Tidy can use for I/O operations. It offers
7  * the ability for the buffer to grow as bytes are added, and keeps track
8  * of current read and write points.
9  *
10  * @author
11  * HTACG, et al (consult git log)
12  *
13  * @copyright
14  * Copyright (c) 1998-2017 World Wide Web Consortium (Massachusetts
15  * Institute of Technology, European Research Consortium for Informatics
16  * and Mathematics, Keio University).
17  * @copyright
18  * See tidy.h for license.
19  *
20  * @date
21  * Consult git log.
22  ******************************************************************************/
23 
24 #include "tidyplatform.h"
25 #include "tidy.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 /** A TidyBuffer is chunk of memory that can be used for multiple I/O purposes
32  ** within Tidy.
33  ** @ingroup IO
34  */
36 struct _TidyBuffer
37 {
38  TidyAllocator* allocator; /**< Memory allocator */
39  byte* bp; /**< Pointer to bytes */
40  uint size; /**< Number of bytes currently in use */
41  uint allocated; /**< Number of bytes allocated */
42  uint next; /**< Offset of current input position */
43 };
44 
45 /** Initialize data structure using the default allocator */
46 TIDY_EXPORT void TIDY_CALL tidyBufInit( TidyBuffer* buf );
47 
48 /** Initialize data structure using the given custom allocator */
49 TIDY_EXPORT void TIDY_CALL tidyBufInitWithAllocator( TidyBuffer* buf, TidyAllocator* allocator );
50 
51 /** Free current buffer, allocate given amount, reset input pointer,
52  use the default allocator */
53 TIDY_EXPORT void TIDY_CALL tidyBufAlloc( TidyBuffer* buf, uint allocSize );
54 
55 /** Free current buffer, allocate given amount, reset input pointer,
56  use the given custom allocator */
57 TIDY_EXPORT void TIDY_CALL tidyBufAllocWithAllocator( TidyBuffer* buf,
58  TidyAllocator* allocator,
59  uint allocSize );
60 
61 /** Expand buffer to given size.
62 ** Chunk size is minimum growth. Pass 0 for default of 256 bytes.
63 */
64 TIDY_EXPORT void TIDY_CALL tidyBufCheckAlloc( TidyBuffer* buf,
65  uint allocSize, uint chunkSize );
66 
67 /** Free current contents and zero out */
68 TIDY_EXPORT void TIDY_CALL tidyBufFree( TidyBuffer* buf );
69 
70 /** Set buffer bytes to 0 */
71 TIDY_EXPORT void TIDY_CALL tidyBufClear( TidyBuffer* buf );
72 
73 /** Attach to existing buffer */
74 TIDY_EXPORT void TIDY_CALL tidyBufAttach( TidyBuffer* buf, byte* bp, uint size );
75 
76 /** Detach from buffer. Caller must free. */
77 TIDY_EXPORT void TIDY_CALL tidyBufDetach( TidyBuffer* buf );
78 
79 
80 /** Append bytes to buffer. Expand if necessary. */
81 TIDY_EXPORT void TIDY_CALL tidyBufAppend( TidyBuffer* buf, void* vp, uint size );
82 
83 /** Append one byte to buffer. Expand if necessary. */
84 TIDY_EXPORT void TIDY_CALL tidyBufPutByte( TidyBuffer* buf, byte bv );
85 
86 /** Get byte from end of buffer */
87 TIDY_EXPORT int TIDY_CALL tidyBufPopByte( TidyBuffer* buf );
88 
89 
90 /** Get byte from front of buffer. Increment input offset. */
91 TIDY_EXPORT int TIDY_CALL tidyBufGetByte( TidyBuffer* buf );
92 
93 /** At end of buffer? */
94 TIDY_EXPORT Bool TIDY_CALL tidyBufEndOfInput( TidyBuffer* buf );
95 
96 /** Put a byte back into the buffer. Decrement input offset. */
97 TIDY_EXPORT void TIDY_CALL tidyBufUngetByte( TidyBuffer* buf, byte bv );
98 
99 
100 /**************
101  TIDY
102 **************/
103 
104 /* Forward declarations
105 */
106 
107 /** Initialize a buffer input source */
108 TIDY_EXPORT void TIDY_CALL tidyInitInputBuffer( TidyInputSource* inp, TidyBuffer* buf );
109 
110 /** Initialize a buffer output sink */
111 TIDY_EXPORT void TIDY_CALL tidyInitOutputBuffer( TidyOutputSink* outp, TidyBuffer* buf );
112 
113 #ifdef __cplusplus
114 }
115 #endif
116 #endif /* __TIDY_BUFFIO_H__ */
117 
118 /*
119  * local variables:
120  * mode: c
121  * indent-tabs-mode: nil
122  * c-basic-offset: 4
123  * eval: (c-set-offset 'substatement-open 0)
124  * end:
125  */
uint size
Number of bytes currently in use.
Definition: tidybuffio.h:40
uint allocated
Number of bytes allocated.
Definition: tidybuffio.h:41
byte * bp
Pointer to bytes.
Definition: tidybuffio.h:39
TidyAllocator * allocator
Memory allocator.
Definition: tidybuffio.h:38
uint next
Offset of current input position.
Definition: tidybuffio.h:42
This type defines an input source capable of delivering raw bytes of input.
Definition: tidy.h:1079
This type defines an output destination capable of accepting raw bytes of output.
Definition: tidy.h:1129
A TidyBuffer is chunk of memory that can be used for multiple I/O purposes within Tidy.
Definition: tidybuffio.h:37
Defines HTML Tidy public API implemented by LibTidy.
void TIDY_CALL tidyBufUngetByte(TidyBuffer *buf, byte bv)
Put a byte back into the buffer.
void TIDY_CALL tidyBufInit(TidyBuffer *buf)
Initialize data structure using the default allocator.
void TIDY_CALL tidyBufAllocWithAllocator(TidyBuffer *buf, TidyAllocator *allocator, uint allocSize)
Free current buffer, allocate given amount, reset input pointer, use the given custom allocator.
int TIDY_CALL tidyBufGetByte(TidyBuffer *buf)
Get byte from front of buffer.
void TIDY_CALL tidyBufFree(TidyBuffer *buf)
Free current contents and zero out.
void TIDY_CALL tidyInitInputBuffer(TidyInputSource *inp, TidyBuffer *buf)
Initialize a buffer input source.
void TIDY_CALL tidyBufCheckAlloc(TidyBuffer *buf, uint allocSize, uint chunkSize)
Expand buffer to given size.
Bool TIDY_CALL tidyBufEndOfInput(TidyBuffer *buf)
At end of buffer?
void TIDY_CALL tidyInitOutputBuffer(TidyOutputSink *outp, TidyBuffer *buf)
Initialize a buffer output sink.
void TIDY_CALL tidyBufAlloc(TidyBuffer *buf, uint allocSize)
Free current buffer, allocate given amount, reset input pointer, use the default allocator.
void TIDY_CALL tidyBufDetach(TidyBuffer *buf)
Detach from buffer.
void TIDY_CALL tidyBufClear(TidyBuffer *buf)
Set buffer bytes to 0.
void TIDY_CALL tidyBufAttach(TidyBuffer *buf, byte *bp, uint size)
Attach to existing buffer.
void TIDY_CALL tidyBufAppend(TidyBuffer *buf, void *vp, uint size)
Append bytes to buffer.
void TIDY_CALL tidyBufPutByte(TidyBuffer *buf, byte bv)
Append one byte to buffer.
int TIDY_CALL tidyBufPopByte(TidyBuffer *buf)
Get byte from end of buffer.
void TIDY_CALL tidyBufInitWithAllocator(TidyBuffer *buf, TidyAllocator *allocator)
Initialize data structure using the given custom allocator.
Platform specific definitions, specifics, and headers.
Bool
Definition: tidyplatform.h:662
#define TIDY_STRUCT
Definition: tidyplatform.h:607
#define TIDY_CALL
Definition: tidyplatform.h:630
unsigned int uint
Definition: tidyplatform.h:576