Mercurial > hg > xemacs-beta
comparison src/lstream.h @ 272:c5d627a313b1 r21-0b34
Import from CVS: tag r21-0b34
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:28:48 +0200 |
parents | 727739f917cb |
children | 74fd4e045ea6 |
comparison
equal
deleted
inserted
replaced
271:c7b7086b0a39 | 272:c5d627a313b1 |
---|---|
73 however -- e.g. on process output. */ | 73 however -- e.g. on process output. */ |
74 | 74 |
75 typedef struct lstream_implementation | 75 typedef struct lstream_implementation |
76 { | 76 { |
77 CONST char *name; | 77 CONST char *name; |
78 int size; /* Number of additional bytes to be allocated with this | 78 size_t size; /* Number of additional bytes to be allocated with this |
79 stream. Access this data using Lstream_data(). */ | 79 stream. Access this data using Lstream_data(). */ |
80 /* Read some data from the stream's end and store it into DATA, which | 80 /* Read some data from the stream's end and store it into DATA, which |
81 can hold SIZE bytes. Return the number of bytes read. A return | 81 can hold SIZE bytes. Return the number of bytes read. A return |
82 value of 0 means no bytes can be read at this time. This may | 82 value of 0 means no bytes can be read at this time. This may |
83 be because of an EOF, or because there is a granularity greater | 83 be because of an EOF, or because there is a granularity greater |
84 than one byte that the stream imposes on the returned data, and | 84 than one byte that the stream imposes on the returned data, and |
93 | 93 |
94 This function can be NULL if the stream is output-only. */ | 94 This function can be NULL if the stream is output-only. */ |
95 /* The omniscient mly, blinded by the irresistable thrall of Common | 95 /* The omniscient mly, blinded by the irresistable thrall of Common |
96 Lisp, thinks that it is bogus that the types and implementations | 96 Lisp, thinks that it is bogus that the types and implementations |
97 of input and output streams are the same. */ | 97 of input and output streams are the same. */ |
98 int (*reader) (Lstream *stream, unsigned char *data, int size); | 98 int (*reader) (Lstream *stream, unsigned char *data, size_t size); |
99 /* Send some data to the stream's end. Data to be sent is in DATA | 99 /* Send some data to the stream's end. Data to be sent is in DATA |
100 and is SIZE bytes. Return the number of bytes sent. This | 100 and is SIZE bytes. Return the number of bytes sent. This |
101 function can send and return fewer bytes than is passed in; in | 101 function can send and return fewer bytes than is passed in; in |
102 that case, the function will just be called again until there is | 102 that case, the function will just be called again until there is |
103 no data left or 0 is returned. A return value of 0 means that no | 103 no data left or 0 is returned. A return value of 0 means that no |
104 more data can be currently stored, but there is no error; the | 104 more data can be currently stored, but there is no error; the |
105 data will be squirrelled away until the writer can accept | 105 data will be squirrelled away until the writer can accept |
106 data. (This is useful, e.g., of you're dealing with a | 106 data. (This is useful, e.g., of you're dealing with a |
107 non-blocking file descriptor and are getting EWOULDBLOCK errors.) | 107 non-blocking file descriptor and are getting EWOULDBLOCK errors.) |
108 This function can be NULL if the stream is input-only. */ | 108 This function can be NULL if the stream is input-only. */ |
109 int (*writer) (Lstream *stream, CONST unsigned char *data, int size); | 109 int (*writer) (Lstream *stream, CONST unsigned char *data, size_t size); |
110 /* Return non-zero if the last write operation on the stream resulted | 110 /* Return non-zero if the last write operation on the stream resulted |
111 in an attempt to block (EWOULDBLOCK). If this method does not | 111 in an attempt to block (EWOULDBLOCK). If this method does not |
112 exists, the implementation returns 0 */ | 112 exists, the implementation returns 0 */ |
113 int (*was_blocked_p) (Lstream *stream); | 113 int (*was_blocked_p) (Lstream *stream); |
114 /* Rewind the stream. If this is NULL, the stream is not seekable. */ | 114 /* Rewind the stream. If this is NULL, the stream is not seekable. */ |
145 struct lstream | 145 struct lstream |
146 { | 146 { |
147 struct lcrecord_header header; | 147 struct lcrecord_header header; |
148 CONST Lstream_implementation *imp; /* methods for this stream */ | 148 CONST Lstream_implementation *imp; /* methods for this stream */ |
149 Lstream_buffering buffering; /* type of buffering in use */ | 149 Lstream_buffering buffering; /* type of buffering in use */ |
150 int buffering_size; /* number of bytes buffered */ | 150 size_t buffering_size; /* number of bytes buffered */ |
151 | 151 |
152 unsigned char *in_buffer; /* holds characters read from stream end */ | 152 unsigned char *in_buffer; /* holds characters read from stream end */ |
153 int in_buffer_size; /* allocated size of buffer */ | 153 size_t in_buffer_size; /* allocated size of buffer */ |
154 int in_buffer_current; /* number of characters in buffer */ | 154 size_t in_buffer_current; /* number of characters in buffer */ |
155 int in_buffer_ind; /* pointer to next character to take from buffer */ | 155 size_t in_buffer_ind; /* pointer to next character to take from buffer */ |
156 | 156 |
157 unsigned char *out_buffer; /* holds characters to write to stream end */ | 157 unsigned char *out_buffer; /* holds characters to write to stream end */ |
158 int out_buffer_size; /* allocated size of buffer */ | 158 size_t out_buffer_size; /* allocated size of buffer */ |
159 int out_buffer_ind; /* pointer to next buffer spot to write a character */ | 159 size_t out_buffer_ind; /* pointer to next buffer spot to write a character */ |
160 | 160 |
161 /* The unget buffer is more or less a stack -- things get pushed | 161 /* The unget buffer is more or less a stack -- things get pushed |
162 onto the end and read back from the end. Lstream_read() | 162 onto the end and read back from the end. Lstream_read() |
163 basically reads backwards from the end to get stuff; Lstream_unread() | 163 basically reads backwards from the end to get stuff; Lstream_unread() |
164 similarly has to push the data on backwards. */ | 164 similarly has to push the data on backwards. */ |
165 unsigned char *unget_buffer; /* holds characters pushed back onto input */ | 165 unsigned char *unget_buffer; /* holds characters pushed back onto input */ |
166 int unget_buffer_size; /* allocated size of buffer */ | 166 size_t unget_buffer_size; /* allocated size of buffer */ |
167 int unget_buffer_ind; /* pointer to next buffer spot to write a character */ | 167 size_t unget_buffer_ind; /* pointer to next buffer spot to write a character */ |
168 | 168 |
169 int byte_count; | 169 size_t byte_count; |
170 long flags; /* Align pointer for 64 bit machines (kny) */ | 170 long flags; /* Align pointer for 64 bit machines (kny) */ |
171 char data[1]; | 171 char data[1]; |
172 }; | 172 }; |
173 | 173 |
174 #define LSTREAM_TYPE_P(lstr, type) \ | 174 #define LSTREAM_TYPE_P(lstr, type) \ |
175 ((lstr)->imp == lstream_##type) | 175 ((lstr)->imp == lstream_##type) |
176 | 176 |
177 #ifdef ERROR_CHECK_TYPECHECK | 177 #ifdef ERROR_CHECK_TYPECHECK |
178 MAC_DECLARE_EXTERN (struct lstream *, MTlstream_data) | 178 INLINE struct lstream * |
179 # define LSTREAM_TYPE_DATA(lstr, type) \ | 179 error_check_lstream_type (struct lstream *stream, |
180 MAC_BEGIN \ | 180 CONST Lstream_implementation *imp); |
181 MAC_DECLARE (struct lstream *, MTlstream_data, lstr) \ | 181 INLINE struct lstream * |
182 assert (LSTREAM_TYPE_P (MTlstream_data, type)) \ | 182 error_check_lstream_type (struct lstream *stream, |
183 MAC_SEP \ | 183 CONST Lstream_implementation *imp) |
184 (struct type##_stream *) Lstream_data (MTlstream_data) \ | 184 { |
185 MAC_END | 185 assert (stream->imp == imp); |
186 return stream; | |
187 } | |
188 # define LSTREAM_TYPE_DATA(lstr, type) \ | |
189 ((struct type##_stream *) \ | |
190 Lstream_data (error_check_lstream_type(lstr, lstream_##type))) | |
186 #else | 191 #else |
187 # define LSTREAM_TYPE_DATA(lstr, type) \ | 192 # define LSTREAM_TYPE_DATA(lstr, type) \ |
188 ((struct type##_stream *) Lstream_data (lstr)) | 193 ((struct type##_stream *) Lstream_data (lstr)) |
189 #endif | 194 #endif |
190 | 195 |
202 int Lstream_flush (Lstream *lstr); | 207 int Lstream_flush (Lstream *lstr); |
203 int Lstream_flush_out (Lstream *lstr); | 208 int Lstream_flush_out (Lstream *lstr); |
204 int Lstream_fputc (Lstream *lstr, int c); | 209 int Lstream_fputc (Lstream *lstr, int c); |
205 int Lstream_fgetc (Lstream *lstr); | 210 int Lstream_fgetc (Lstream *lstr); |
206 void Lstream_fungetc (Lstream *lstr, int c); | 211 void Lstream_fungetc (Lstream *lstr, int c); |
207 int Lstream_read (Lstream *lstr, void *data, int size); | 212 int Lstream_read (Lstream *lstr, void *data, size_t size); |
208 int Lstream_write (Lstream *lstr, CONST void *data, int size); | 213 int Lstream_write (Lstream *lstr, CONST void *data, size_t size); |
209 int Lstream_was_blocked_p (Lstream *lstr); | 214 int Lstream_was_blocked_p (Lstream *lstr); |
210 void Lstream_unread (Lstream *lstr, CONST void *data, int size); | 215 void Lstream_unread (Lstream *lstr, CONST void *data, size_t size); |
211 int Lstream_rewind (Lstream *lstr); | 216 int Lstream_rewind (Lstream *lstr); |
212 int Lstream_seekable_p (Lstream *lstr); | 217 int Lstream_seekable_p (Lstream *lstr); |
213 int Lstream_close (Lstream *lstr); | 218 int Lstream_close (Lstream *lstr); |
214 void Lstream_delete (Lstream *lstr); | 219 void Lstream_delete (Lstream *lstr); |
215 void Lstream_set_character_mode (Lstream *str); | 220 void Lstream_set_character_mode (Lstream *str); |
250 (unsigned char) (c)))) | 255 (unsigned char) (c)))) |
251 | 256 |
252 #define Lstream_data(stream) ((void *) ((stream)->data)) | 257 #define Lstream_data(stream) ((void *) ((stream)->data)) |
253 #define Lstream_byte_count(stream) ((stream)->byte_count) | 258 #define Lstream_byte_count(stream) ((stream)->byte_count) |
254 | 259 |
255 | |
256 | 260 |
257 /************************************************************************/ | 261 /************************************************************************/ |
258 /* working with an Lstream as a stream of Emchars */ | 262 /* working with an Lstream as a stream of Emchars */ |
259 /************************************************************************/ | 263 /************************************************************************/ |
260 | 264 |
261 #ifdef MULE | 265 #ifdef MULE |
262 | 266 |
263 MAC_DECLARE_EXTERN (Emchar, MTlstream_emchar) | 267 #ifndef BYTE_ASCII_P |
264 MAC_DECLARE_EXTERN (int, MTlstream_emcint) | 268 #include "mule-charset.h" |
265 /* In mule-charset.c */ | 269 #endif |
266 Emchar Lstream_get_emchar_1 (Lstream *lstr, int first_char); | 270 |
267 int Lstream_fput_emchar (Lstream *lstr, Emchar ch); | 271 INLINE Emchar Lstream_get_emchar (Lstream *stream); |
268 void Lstream_funget_emchar (Lstream *lstr, Emchar ch); | 272 INLINE Emchar |
269 | 273 Lstream_get_emchar (Lstream *stream) |
270 # define Lstream_get_emchar(stream) \ | 274 { |
271 MAC_BEGIN \ | 275 int c = Lstream_getc (stream); |
272 MAC_DECLARE (int, MTlstream_emcint, Lstream_getc (stream)) \ | 276 return BYTE_ASCII_P (c) ? (Emchar) c : |
273 BYTE_ASCII_P (MTlstream_emcint) ? (Emchar) MTlstream_emcint : \ | 277 Lstream_get_emchar_1 (stream, c); |
274 Lstream_get_emchar_1 (stream, MTlstream_emcint) \ | 278 } |
275 MAC_END | 279 |
276 # define Lstream_put_emchar(stream, ch) \ | 280 INLINE int Lstream_put_emchar (Lstream *stream, Emchar ch); |
277 MAC_BEGIN \ | 281 INLINE int |
278 MAC_DECLARE (Emchar, MTlstream_emchar, ch) \ | 282 Lstream_put_emchar (Lstream *stream, Emchar ch) |
279 CHAR_ASCII_P (MTlstream_emchar) ? \ | 283 { |
280 Lstream_putc (stream, MTlstream_emchar) : \ | 284 return CHAR_ASCII_P (ch) ? |
281 Lstream_fput_emchar (stream, MTlstream_emchar) \ | 285 Lstream_putc (stream, ch) : |
282 MAC_END | 286 Lstream_fput_emchar (stream, ch); |
283 # define Lstream_unget_emchar(stream, ch) \ | 287 } |
284 MAC_BEGIN \ | 288 |
285 MAC_DECLARE (Emchar, MTlstream_emchar, ch) \ | 289 INLINE void Lstream_unget_emchar (Lstream *stream, Emchar ch); |
286 CHAR_ASCII_P (MTlstream_emchar) ? \ | 290 INLINE void |
287 Lstream_ungetc (stream, MTlstream_emchar) : \ | 291 Lstream_unget_emchar (Lstream *stream, Emchar ch) |
288 Lstream_funget_emchar (stream, MTlstream_emchar) \ | 292 { |
289 MAC_END | 293 if (CHAR_ASCII_P (ch)) |
290 | 294 Lstream_ungetc (stream, ch); |
295 else | |
296 Lstream_funget_emchar (stream, ch); | |
297 } | |
291 #else /* not MULE */ | 298 #else /* not MULE */ |
292 | 299 |
293 # define Lstream_get_emchar(stream) Lstream_getc (stream) | 300 # define Lstream_get_emchar(stream) Lstream_getc (stream) |
294 # define Lstream_put_emchar(stream, ch) Lstream_putc (stream, ch) | 301 # define Lstream_put_emchar(stream, ch) Lstream_putc (stream, ch) |
295 # define Lstream_unget_emchar(stream, ch) Lstream_ungetc (stream, ch) | 302 # define Lstream_unget_emchar(stream, ch) Lstream_ungetc (stream, ch) |
296 | 303 |
297 #endif /* not MULE */ | 304 #endif /* not MULE */ |
298 | |
299 | 305 |
300 | 306 |
301 /************************************************************************/ | 307 /************************************************************************/ |
302 /* Lstream implementations */ | 308 /* Lstream implementations */ |
303 /************************************************************************/ | 309 /************************************************************************/ |
332 int filedesc_stream_fd (Lstream *stream); | 338 int filedesc_stream_fd (Lstream *stream); |
333 Lisp_Object make_lisp_string_input_stream (Lisp_Object string, | 339 Lisp_Object make_lisp_string_input_stream (Lisp_Object string, |
334 Bytecount offset, | 340 Bytecount offset, |
335 Bytecount len); | 341 Bytecount len); |
336 Lisp_Object make_fixed_buffer_input_stream (CONST unsigned char *buf, | 342 Lisp_Object make_fixed_buffer_input_stream (CONST unsigned char *buf, |
337 int size); | 343 size_t size); |
338 Lisp_Object make_fixed_buffer_output_stream (unsigned char *buf, | 344 Lisp_Object make_fixed_buffer_output_stream (unsigned char *buf, |
339 int size); | 345 size_t size); |
340 CONST unsigned char *fixed_buffer_input_stream_ptr (Lstream *stream); | 346 CONST unsigned char *fixed_buffer_input_stream_ptr (Lstream *stream); |
341 unsigned char *fixed_buffer_output_stream_ptr (Lstream *stream); | 347 unsigned char *fixed_buffer_output_stream_ptr (Lstream *stream); |
342 Lisp_Object make_resizing_buffer_output_stream (void); | 348 Lisp_Object make_resizing_buffer_output_stream (void); |
343 unsigned char *resizing_buffer_stream_ptr (Lstream *stream); | 349 unsigned char *resizing_buffer_stream_ptr (Lstream *stream); |
344 Lisp_Object make_dynarr_output_stream (unsigned_char_dynarr *dyn); | 350 Lisp_Object make_dynarr_output_stream (unsigned_char_dynarr *dyn); |