Mercurial > hg > xemacs-beta
comparison src/lstream.h @ 442:abe6d1db359e r21-2-36
Import from CVS: tag r21-2-36
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:35:02 +0200 |
parents | 8de8e3f6228a |
children | 576fb035e263 |
comparison
equal
deleted
inserted
replaced
441:72a7cfa4a488 | 442:abe6d1db359e |
---|---|
72 a rewind method. Even rewind() may not be available on a stream, | 72 a rewind method. Even rewind() may not be available on a stream, |
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 size_t 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 |
90 anything special; however, the calling function will interpret | 90 anything special; however, the calling function will interpret |
91 any 0 it gets back as EOF. This will normally not happen unless | 91 any 0 it gets back as EOF. This will normally not happen unless |
92 the caller calls Lstream_read() with a very small size. | 92 the caller calls Lstream_read() with a very small size. |
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 irresistible 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 ssize_t (*reader) (Lstream *stream, unsigned char *data, size_t size); | 98 ssize_t (*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 |
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 ssize_t (*writer) (Lstream *stream, CONST unsigned char *data, size_t size); | 109 ssize_t (*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. */ |
143 #define LSTREAM_FL_CLOSE_AT_DISKSAVE 16 | 143 #define LSTREAM_FL_CLOSE_AT_DISKSAVE 16 |
144 | 144 |
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 size_t 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 size_t in_buffer_size; /* allocated size of buffer */ | 153 size_t in_buffer_size; /* allocated size of buffer */ |
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 INLINE struct lstream * | 178 INLINE_HEADER struct lstream * |
179 error_check_lstream_type (struct lstream *stream, | 179 error_check_lstream_type (struct lstream *stream, |
180 CONST Lstream_implementation *imp); | 180 const Lstream_implementation *imp); |
181 INLINE struct lstream * | 181 INLINE_HEADER struct lstream * |
182 error_check_lstream_type (struct lstream *stream, | 182 error_check_lstream_type (struct lstream *stream, |
183 CONST Lstream_implementation *imp) | 183 const Lstream_implementation *imp) |
184 { | 184 { |
185 assert (stream->imp == imp); | 185 assert (stream->imp == imp); |
186 return stream; | 186 return stream; |
187 } | 187 } |
188 # define LSTREAM_TYPE_DATA(lstr, type) \ | 188 # define LSTREAM_TYPE_DATA(lstr, type) \ |
197 initialization routines */ | 197 initialization routines */ |
198 #define LSTREAM_HAS_METHOD(type, m) \ | 198 #define LSTREAM_HAS_METHOD(type, m) \ |
199 (lstream_##type->m = type##_##m) | 199 (lstream_##type->m = type##_##m) |
200 | 200 |
201 | 201 |
202 Lstream *Lstream_new (CONST Lstream_implementation *imp, | 202 Lstream *Lstream_new (const Lstream_implementation *imp, |
203 CONST char *mode); | 203 const char *mode); |
204 void Lstream_reopen (Lstream *lstr); | 204 void Lstream_reopen (Lstream *lstr); |
205 void Lstream_set_buffering (Lstream *lstr, Lstream_buffering buffering, | 205 void Lstream_set_buffering (Lstream *lstr, Lstream_buffering buffering, |
206 int buffering_size); | 206 int buffering_size); |
207 int Lstream_flush (Lstream *lstr); | 207 int Lstream_flush (Lstream *lstr); |
208 int Lstream_flush_out (Lstream *lstr); | 208 int Lstream_flush_out (Lstream *lstr); |
209 int Lstream_fputc (Lstream *lstr, int c); | 209 int Lstream_fputc (Lstream *lstr, int c); |
210 int Lstream_fgetc (Lstream *lstr); | 210 int Lstream_fgetc (Lstream *lstr); |
211 void Lstream_fungetc (Lstream *lstr, int c); | 211 void Lstream_fungetc (Lstream *lstr, int c); |
212 ssize_t Lstream_read (Lstream *lstr, void *data, size_t size); | 212 ssize_t Lstream_read (Lstream *lstr, void *data, size_t size); |
213 ssize_t Lstream_write (Lstream *lstr, CONST void *data, size_t size); | 213 ssize_t Lstream_write (Lstream *lstr, const void *data, size_t size); |
214 int Lstream_was_blocked_p (Lstream *lstr); | 214 int Lstream_was_blocked_p (Lstream *lstr); |
215 void Lstream_unread (Lstream *lstr, CONST void *data, size_t size); | 215 void Lstream_unread (Lstream *lstr, const void *data, size_t size); |
216 int Lstream_rewind (Lstream *lstr); | 216 int Lstream_rewind (Lstream *lstr); |
217 int Lstream_seekable_p (Lstream *lstr); | 217 int Lstream_seekable_p (Lstream *lstr); |
218 int Lstream_close (Lstream *lstr); | 218 int Lstream_close (Lstream *lstr); |
219 void Lstream_delete (Lstream *lstr); | 219 void Lstream_delete (Lstream *lstr); |
220 void Lstream_set_character_mode (Lstream *str); | 220 void Lstream_set_character_mode (Lstream *str); |
266 | 266 |
267 #ifndef BYTE_ASCII_P | 267 #ifndef BYTE_ASCII_P |
268 #include "mule-charset.h" | 268 #include "mule-charset.h" |
269 #endif | 269 #endif |
270 | 270 |
271 INLINE Emchar Lstream_get_emchar (Lstream *stream); | 271 INLINE_HEADER Emchar Lstream_get_emchar (Lstream *stream); |
272 INLINE Emchar | 272 INLINE_HEADER Emchar |
273 Lstream_get_emchar (Lstream *stream) | 273 Lstream_get_emchar (Lstream *stream) |
274 { | 274 { |
275 int c = Lstream_getc (stream); | 275 int c = Lstream_getc (stream); |
276 return BYTE_ASCII_P (c) ? (Emchar) c : | 276 return BYTE_ASCII_P (c) ? (Emchar) c : |
277 Lstream_get_emchar_1 (stream, c); | 277 Lstream_get_emchar_1 (stream, c); |
278 } | 278 } |
279 | 279 |
280 INLINE int Lstream_put_emchar (Lstream *stream, Emchar ch); | 280 INLINE_HEADER int Lstream_put_emchar (Lstream *stream, Emchar ch); |
281 INLINE int | 281 INLINE_HEADER int |
282 Lstream_put_emchar (Lstream *stream, Emchar ch) | 282 Lstream_put_emchar (Lstream *stream, Emchar ch) |
283 { | 283 { |
284 return CHAR_ASCII_P (ch) ? | 284 return CHAR_ASCII_P (ch) ? |
285 Lstream_putc (stream, ch) : | 285 Lstream_putc (stream, ch) : |
286 Lstream_fput_emchar (stream, ch); | 286 Lstream_fput_emchar (stream, ch); |
287 } | 287 } |
288 | 288 |
289 INLINE void Lstream_unget_emchar (Lstream *stream, Emchar ch); | 289 INLINE_HEADER void Lstream_unget_emchar (Lstream *stream, Emchar ch); |
290 INLINE void | 290 INLINE_HEADER void |
291 Lstream_unget_emchar (Lstream *stream, Emchar ch) | 291 Lstream_unget_emchar (Lstream *stream, Emchar ch) |
292 { | 292 { |
293 if (CHAR_ASCII_P (ch)) | 293 if (CHAR_ASCII_P (ch)) |
294 Lstream_ungetc (stream, ch); | 294 Lstream_ungetc (stream, ch); |
295 else | 295 else |
337 Bufbyte eof_char); | 337 Bufbyte eof_char); |
338 int filedesc_stream_fd (Lstream *stream); | 338 int filedesc_stream_fd (Lstream *stream); |
339 Lisp_Object make_lisp_string_input_stream (Lisp_Object string, | 339 Lisp_Object make_lisp_string_input_stream (Lisp_Object string, |
340 Bytecount offset, | 340 Bytecount offset, |
341 Bytecount len); | 341 Bytecount len); |
342 Lisp_Object make_fixed_buffer_input_stream (CONST void *buf, size_t size); | 342 Lisp_Object make_fixed_buffer_input_stream (const void *buf, size_t size); |
343 Lisp_Object make_fixed_buffer_output_stream (void *buf, size_t size); | 343 Lisp_Object make_fixed_buffer_output_stream (void *buf, size_t size); |
344 CONST unsigned char *fixed_buffer_input_stream_ptr (Lstream *stream); | 344 const unsigned char *fixed_buffer_input_stream_ptr (Lstream *stream); |
345 unsigned char *fixed_buffer_output_stream_ptr (Lstream *stream); | 345 unsigned char *fixed_buffer_output_stream_ptr (Lstream *stream); |
346 Lisp_Object make_resizing_buffer_output_stream (void); | 346 Lisp_Object make_resizing_buffer_output_stream (void); |
347 unsigned char *resizing_buffer_stream_ptr (Lstream *stream); | 347 unsigned char *resizing_buffer_stream_ptr (Lstream *stream); |
348 Lisp_Object make_dynarr_output_stream (unsigned_char_dynarr *dyn); | 348 Lisp_Object make_dynarr_output_stream (unsigned_char_dynarr *dyn); |
349 #define LSTR_SELECTIVE 1 | 349 #define LSTR_SELECTIVE 1 |