Mercurial > hg > xemacs-beta
comparison src/lstream.h @ 398:74fd4e045ea6 r21-2-29
Import from CVS: tag r21-2-29
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:13:30 +0200 |
parents | c5d627a313b1 |
children | 2f8bb876ab1d |
comparison
equal
deleted
inserted
replaced
397:f4aeb21a5bad | 398:74fd4e045ea6 |
---|---|
21 | 21 |
22 /* Synched up with: Not in FSF. */ | 22 /* Synched up with: Not in FSF. */ |
23 | 23 |
24 /* Written by Ben Wing. */ | 24 /* Written by Ben Wing. */ |
25 | 25 |
26 #ifndef _XEMACS_LSTREAM_H_ | 26 #ifndef INCLUDED_lstream_h_ |
27 #define _XEMACS_LSTREAM_H_ | 27 #define INCLUDED_lstream_h_ |
28 | 28 |
29 /************************************************************************/ | 29 /************************************************************************/ |
30 /* definition of Lstream object */ | 30 /* definition of Lstream object */ |
31 /************************************************************************/ | 31 /************************************************************************/ |
32 | 32 |
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 |
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, 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 |
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, 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. */ |
127 collected. When this function is called, all pending data | 127 collected. When this function is called, all pending data |
128 in the stream will already have been written out. */ | 128 in the stream will already have been written out. */ |
129 int (*closer) (Lstream *stream); | 129 int (*closer) (Lstream *stream); |
130 /* Mark this object for garbage collection. Same semantics as | 130 /* Mark this object for garbage collection. Same semantics as |
131 a standard Lisp_Object marker. This function can be NULL. */ | 131 a standard Lisp_Object marker. This function can be NULL. */ |
132 Lisp_Object (*marker) (Lisp_Object lstream, void (*markfun) (Lisp_Object)); | 132 Lisp_Object (*marker) (Lisp_Object lstream); |
133 } Lstream_implementation; | 133 } Lstream_implementation; |
134 | 134 |
135 #define DEFINE_LSTREAM_IMPLEMENTATION(name,c_name,size) \ | 135 #define DEFINE_LSTREAM_IMPLEMENTATION(name,c_name,size) \ |
136 Lstream_implementation c_name[1] = \ | 136 Lstream_implementation c_name[1] = \ |
137 { { (name), (size) } } | 137 { { (name), (size) } } |
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 */ |
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 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 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 int Lstream_read (Lstream *lstr, void *data, size_t size); | 212 ssize_t Lstream_read (Lstream *lstr, void *data, size_t size); |
213 int 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); |
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 unsigned char *buf, | 342 Lisp_Object make_fixed_buffer_input_stream (const void *buf, size_t size); |
343 size_t size); | 343 Lisp_Object make_fixed_buffer_output_stream (void *buf, size_t size); |
344 Lisp_Object make_fixed_buffer_output_stream (unsigned char *buf, | 344 const unsigned char *fixed_buffer_input_stream_ptr (Lstream *stream); |
345 size_t size); | |
346 CONST unsigned char *fixed_buffer_input_stream_ptr (Lstream *stream); | |
347 unsigned char *fixed_buffer_output_stream_ptr (Lstream *stream); | 345 unsigned char *fixed_buffer_output_stream_ptr (Lstream *stream); |
348 Lisp_Object make_resizing_buffer_output_stream (void); | 346 Lisp_Object make_resizing_buffer_output_stream (void); |
349 unsigned char *resizing_buffer_stream_ptr (Lstream *stream); | 347 unsigned char *resizing_buffer_stream_ptr (Lstream *stream); |
350 Lisp_Object make_dynarr_output_stream (unsigned_char_dynarr *dyn); | 348 Lisp_Object make_dynarr_output_stream (unsigned_char_dynarr *dyn); |
351 #define LSTR_SELECTIVE 1 | 349 #define LSTR_SELECTIVE 1 |
354 Bufpos end, int flags); | 352 Bufpos end, int flags); |
355 Lisp_Object make_lisp_buffer_output_stream (struct buffer *buf, Bufpos pos, | 353 Lisp_Object make_lisp_buffer_output_stream (struct buffer *buf, Bufpos pos, |
356 int flags); | 354 int flags); |
357 Bufpos lisp_buffer_stream_startpos (Lstream *stream); | 355 Bufpos lisp_buffer_stream_startpos (Lstream *stream); |
358 | 356 |
359 #endif /* _XEMACS_LSTREAM_H_ */ | 357 #endif /* INCLUDED_lstream_h_ */ |