24
24
#include <libnex/char32.h>
25
25
#include <libnex/decls.h>
26
26
#include <libnex/object.h>
27
+ #include <libnex/unicode.h>
27
28
#include <stdbool.h>
28
29
#include <stddef.h>
29
30
#include <stdint.h>
@@ -66,15 +67,15 @@ __DECL_START
66
67
*/
67
68
typedef struct _TextStream
68
69
{
69
- Object_t obj ; ///< The object for this stream
70
- FILE * file ; ///< Pointer to underlying file object
71
- char * fileName ; ///< The original file name
72
- uint8_t * buf ; ///< Buffer to use for staging
73
- size_t bufSize ; ///< Size of above buffer (defaults to 512 bytes)
74
- char encoding ; ///< Underlying encoding of the stream
75
- char order ; ///< Order of bytes for multi byte character sets
76
- char maxEncSize ; ///< Max size of one char in the encoding
77
- char minEncSize ; ///< Minimum size of one char in the encoding
70
+ Object_t obj ; // The object for this stream
71
+ FILE * file ; // Pointer to underlying file object
72
+ const char * fileName ; // The original file name
73
+ uint8_t * buf ; // Buffer to use for staging
74
+ size_t bufSize ; // Size of above buffer
75
+ size_t bufPos ; // Read position within buffer. Used only for reading
76
+ char encoding ; // Underlying encoding of the stream
77
+ char order ; // Order of bytes for multi byte character sets
78
+ char mode ; // Mode used to open text stream
78
79
} TextStream_t ;
79
80
80
81
/**
@@ -91,7 +92,7 @@ typedef struct _TextStream
91
92
* @param[out] stream result variable to put the stream in
92
93
* @return TEXT_SUCCESS, otherwise, an error code
93
94
*/
94
- PUBLIC short TextOpen (char * file , TextStream_t * * stream , char mode , char encoding , bool hasBom , char order );
95
+ PUBLIC short TextOpen (const char * file , TextStream_t * * stream , char mode , char encoding , bool hasBom , char order );
95
96
96
97
/**
97
98
* @brief Closes a text stream
@@ -101,7 +102,7 @@ PUBLIC short TextOpen (char* file, TextStream_t** stream, char mode, char encodi
101
102
*
102
103
* @param[in] stream the stream to close
103
104
*/
104
- PUBLIC void TextClose (TextStream_t * stream );
105
+ PUBLIC short TextClose (TextStream_t * stream );
105
106
106
107
/**
107
108
* @brief Reads data from a text stream
@@ -160,20 +161,6 @@ PUBLIC short TextWrite (TextStream_t* stream, const char32_t* buf, const size_t
160
161
*/
161
162
PUBLIC long TextSize (TextStream_t * stream );
162
163
163
- /**
164
- * @brief Sets the size of the staging buffer
165
- *
166
- * TextSetBufSz resizes the staging buffer to the size specified by sz
167
- * This could used to help optimize performance by selecting a large buffer
168
- * size, or optimizing memory usage by selecting a small buffer size This
169
- * function has a potential exit point. It may call exit(3) in an error
170
- * condition
171
- *
172
- * @param[in] stream the stream to operate on
173
- * @param[in] sz the new buffer size
174
- */
175
- PUBLIC void TextSetBufSz (TextStream_t * stream , size_t sz );
176
-
177
164
/**
178
165
* @brief Returns a textual representation of a textstream error code
179
166
* @param code the error code turn into a string
@@ -184,21 +171,26 @@ PUBLIC const char* TextError (int code);
184
171
/**
185
172
* @brief Takes a libchardet charset name, and returns a textsream encoding and byte order
186
173
* @param encName the name of the encoding
187
- * @param enc the numeric encoding ID to write to
188
- * @param order the byte order to write to
174
+ * @param enc the numeric encoding ID pointer to write to
175
+ * @param order the byte order pointer to write to
189
176
*/
190
177
PUBLIC void TextGetEncId (const char * encName , char * enc , char * order );
191
178
179
+ /**
180
+ * @brief Flushes the contents of a text stream when the stream in a writing mode
181
+ * @param stream the stream to flush
182
+ * @return an error code, or TEXT_SUCCESS
183
+ */
184
+ PUBLIC short TextFlush (TextStream_t * stream );
185
+
192
186
__DECL_END
193
187
194
188
// Helper macros
195
189
#define TextGetEncoding (stream ) ((stream)->encoding) ///< Grabs the character encoding of stream
196
190
#define TextGetOrder (stream ) ((stream)->order) ///< Grabs the byte order of stream
197
- #define TextGetBufSz (stream ) ((stream)->bufSize) ///< Grabs the size of the staging buffer in stream
198
191
#define TextRef (item ) ((TextStream_t*) ObjRef (&(item)->obj)) ///< References the underlying the object
199
192
#define TextLock (item ) (ObjLock (&(item)->obj)) ///< Locks this stream
200
193
#define TextUnlock (item ) (ObjUnlock (&(item)->obj)) ///< Unlocks the stream
201
194
#define TextDeRef (item ) (ObjDestroy (&(item)->obj)) ///< Dereferences this stream
202
- #define TextGetFile (stream ) ((stream)->file) ///< Obtains the file handle of this stream
203
195
204
196
#endif
0 commit comments