0
|
1 /* Generic stream implementation.
|
|
2 Copyright (C) 1995 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Sun Microsystems, Inc.
|
|
4 Copyright (C) 1996 Ben Wing.
|
|
5
|
|
6 This file is part of XEmacs.
|
|
7
|
|
8 XEmacs is free software; you can redistribute it and/or modify it
|
|
9 under the terms of the GNU General Public License as published by the
|
|
10 Free Software Foundation; either version 2, or (at your option) any
|
|
11 later version.
|
|
12
|
|
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
16 for more details.
|
|
17
|
|
18 You should have received a copy of the GNU General Public License
|
|
19 along with XEmacs; see the file COPYING. If not, write to
|
|
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
21 Boston, MA 02111-1307, USA. */
|
|
22
|
|
23 /* Synched up with: Not in FSF. */
|
|
24
|
|
25 /* Written by Ben Wing. */
|
|
26
|
|
27 #include <config.h>
|
|
28 #include "lisp.h"
|
|
29
|
|
30 #include "buffer.h"
|
|
31 #include "insdel.h"
|
|
32 #include "lstream.h"
|
|
33
|
|
34 #include "sysfile.h"
|
|
35 #include <errno.h>
|
|
36
|
|
37 /* This function provides a generic buffering stream implementation.
|
|
38 Conceptually, you send data to the stream or read data from the
|
|
39 stream, not caring what's on the other end of the stream. The
|
|
40 other end could be another stream, a file descriptor, a stdio
|
|
41 stream, a fixed block of memory, a reallocating block of memory,
|
|
42 etc. The main purpose of the stream is to provide a standard
|
|
43 interface and to do buffering. Macros are defined to read
|
|
44 or write characters, so the calling functions do not have to
|
|
45 worry about blocking data together in order to achieve efficiency.
|
|
46 */
|
|
47
|
|
48 /* Note that this object is called "stream" in Lisp but "lstream"
|
|
49 in C. The reason for this is that "stream" is too generic a name
|
|
50 for C; too much likelihood of conflict/confusion with C++, etc. */
|
|
51
|
|
52 /* Functions are as follows:
|
|
53
|
|
54 Lstream *Lstream_new (Lstream_implementation *imp, CONST char *mode)
|
|
55 Allocate and return a new Lstream. This function is not
|
|
56 really meant to be called directly; rather, each stream type
|
|
57 should provide its own stream creation function, which
|
|
58 creates the stream and does any other necessary creation
|
|
59 stuff (e.g. opening a file).
|
|
60
|
|
61 void Lstream_set_buffering (Lstream *lstr, Lstream_buffering buffering,
|
|
62 int buffering_size)
|
|
63 Change the buffering of a stream. See lstream.h. By default
|
|
64 the buffering is STREAM_BLOCK_BUFFERED.
|
|
65
|
|
66 int Lstream_flush (Lstream *lstr)
|
|
67 Flush out any pending unwritten data in the stream. Clear
|
|
68 any buffered input data. Returns 0 on success, -1 on error.
|
|
69
|
|
70 int Lstream_putc (Lstream *stream, int c)
|
|
71 Write out one byte to the stream. This is a macro and so
|
|
72 it is very efficient. The C argument is only evaluated once
|
|
73 but the STREAM argument is evaluated more than once. Returns
|
|
74 0 on success, -1 on error.
|
185
|
75
|
0
|
76 int Lstream_getc (Lstream *stream)
|
|
77 Read one byte from the stream. This is a macro and so it
|
|
78 is very efficient. The STREAM argument is evaluated more
|
|
79 than once. Return value is -1 for EOF or error.
|
|
80
|
|
81 void Lstream_ungetc (Lstream *stream, int c)
|
|
82 Push one byte back onto the input queue. This will be the
|
|
83 next byte read from the stream. Any number of bytes can be
|
|
84 pushed back and will be read in the reverse order they were
|
|
85 pushed back -- most recent first. (This is necessary for
|
|
86 consistency -- if there are a number of bytes that have been
|
|
87 unread and I read and unread a byte, it needs to be the first
|
|
88 to be read again.) This is a macro and so it is very
|
|
89 efficient. The C argument is only evaluated once but the
|
|
90 STREAM argument is evaluated more than once.
|
|
91
|
|
92 int Lstream_fputc (Lstream *stream, int c)
|
|
93 int Lstream_fgetc (Lstream *stream)
|
|
94 void Lstream_fungetc (Lstream *stream, int c)
|
185
|
95 Function equivalents of the above macros.
|
0
|
96
|
|
97 int Lstream_read (Lstream *stream, void *data, int size)
|
|
98 Read SIZE bytes of DATA from the stream. Return the number of
|
|
99 bytes read. 0 means EOF. -1 means an error occurred and no
|
|
100 bytes were read.
|
|
101
|
|
102 int Lstream_write (Lstream *stream, void *data, int size)
|
|
103 Write SIZE bytes of DATA to the stream. Return the number of
|
|
104 bytes written. -1 means an error occurred and no bytes were
|
|
105 written.
|
|
106
|
|
107 void Lstream_unread (Lstream *stream, void *data, int size)
|
|
108 Push back SIZE bytes of DATA onto the input queue. The
|
|
109 next call to Lstream_read() with the same size will read the
|
|
110 same bytes back. Note that this will be the case even if
|
|
111 there is other pending unread data.
|
|
112
|
185
|
113 int Lstream_delete (Lstream *stream)
|
|
114 Frees all memory associated with the stream is freed. Calling
|
|
115 this is not strictly necessary, but it is much more efficient
|
|
116 than having the Lstream be garbage-collected.
|
|
117
|
0
|
118 int Lstream_close (Lstream *stream)
|
|
119 Close the stream. All data will be flushed out.
|
|
120
|
|
121 void Lstream_reopen (Lstream *stream)
|
|
122 Reopen a closed stream. This enables I/O on it again.
|
|
123 This is not meant to be called except from a wrapper routine
|
|
124 that reinitializes variables and such -- the close routine
|
|
125 may well have freed some necessary storage structures, for
|
|
126 example.
|
|
127
|
|
128 void Lstream_rewind (Lstream *stream)
|
|
129 Rewind the stream to the beginning.
|
16
|
130 */
|
|
131
|
|
132 #ifdef MULE
|
|
133 MAC_DEFINE (Emchar, MTlstream_emchar)
|
|
134 MAC_DEFINE (int, MTlstream_emcint)
|
|
135 #endif
|
0
|
136
|
|
137 MAC_DEFINE (struct lstream *, MTlstream_data)
|
|
138
|
|
139 static Lisp_Object mark_lstream (Lisp_Object, void (*) (Lisp_Object));
|
|
140 static void print_lstream (Lisp_Object obj, Lisp_Object printcharfun,
|
|
141 int escapeflag);
|
|
142 static void finalize_lstream (void *header, int for_disksave);
|
|
143 static unsigned int sizeof_lstream (CONST void *header);
|
|
144 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION ("stream", lstream,
|
|
145 mark_lstream, print_lstream,
|
|
146 finalize_lstream, 0, 0,
|
|
147 sizeof_lstream, Lstream);
|
|
148
|
|
149 #define DEFAULT_BLOCK_BUFFERING_SIZE 512
|
|
150 #define MAX_READ_SIZE 512
|
|
151
|
|
152 static Lisp_Object
|
|
153 mark_lstream (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
154 {
|
|
155 Lstream *lstr = XLSTREAM (obj);
|
|
156 if (lstr->imp->marker)
|
|
157 return (lstr->imp->marker) (obj, markobj);
|
|
158 else
|
|
159 return Qnil;
|
|
160 }
|
|
161
|
|
162 static void
|
|
163 print_lstream (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
164 {
|
|
165 Lstream *lstr = XLSTREAM (obj);
|
|
166 char buf[200];
|
|
167
|
173
|
168 sprintf (buf, "#<INTERNAL EMACS BUG (%s lstream) 0x%p>",
|
|
169 lstr->imp->name, lstr);
|
0
|
170 write_c_string (buf, printcharfun);
|
|
171 }
|
|
172
|
|
173 static void
|
|
174 finalize_lstream (void *header, int for_disksave)
|
|
175 {
|
|
176 /* WARNING WARNING WARNING. This function (and all finalize functions)
|
|
177 may get called more than once on the same object, and may get called
|
|
178 (at dump time) on objects that are not being released. */
|
|
179 Lstream *lstr = (Lstream *) header;
|
|
180
|
|
181 #if 0 /* this may cause weird Broken Pipes? */
|
|
182 if (for_disksave)
|
|
183 {
|
|
184 Lstream_pseudo_close (lstr);
|
|
185 return;
|
|
186 }
|
|
187 #endif
|
|
188 if (lstr->flags & LSTREAM_FL_IS_OPEN)
|
|
189 Lstream_close (lstr);
|
|
190 }
|
|
191
|
|
192 static unsigned int
|
|
193 sizeof_lstream (CONST void *header)
|
|
194 {
|
|
195 CONST Lstream *lstr = (CONST Lstream *) header;
|
|
196 return sizeof (*lstr) + lstr->imp->size - 1;
|
|
197 }
|
|
198
|
|
199 void
|
|
200 Lstream_set_buffering (Lstream *lstr, Lstream_buffering buffering,
|
|
201 int buffering_size)
|
|
202 {
|
|
203 lstr->buffering = buffering;
|
|
204 switch (buffering)
|
|
205 {
|
|
206 case LSTREAM_UNBUFFERED:
|
|
207 lstr->buffering_size = 0; break;
|
|
208 case LSTREAM_BLOCK_BUFFERED:
|
|
209 lstr->buffering_size = DEFAULT_BLOCK_BUFFERING_SIZE; break;
|
|
210 case LSTREAM_BLOCKN_BUFFERED:
|
|
211 lstr->buffering_size = buffering_size; break;
|
|
212 case LSTREAM_LINE_BUFFERED:
|
|
213 case LSTREAM_UNLIMITED:
|
|
214 lstr->buffering_size = INT_MAX; break;
|
|
215 }
|
|
216 }
|
|
217
|
|
218 static CONST Lstream_implementation *lstream_types[32];
|
|
219 static Lisp_Object Vlstream_free_list[32];
|
|
220 static int lstream_type_count;
|
|
221
|
|
222 Lstream *
|
|
223 Lstream_new (CONST Lstream_implementation *imp, CONST char *mode)
|
|
224 {
|
|
225 Lstream *p;
|
|
226 int i;
|
|
227
|
|
228 for (i = 0; i < lstream_type_count; i++)
|
|
229 {
|
|
230 if (lstream_types[i] == imp)
|
|
231 break;
|
|
232 }
|
|
233
|
|
234 if (i == lstream_type_count)
|
|
235 {
|
|
236 assert (lstream_type_count < countof (lstream_types));
|
|
237 lstream_types[lstream_type_count] = imp;
|
|
238 Vlstream_free_list[lstream_type_count] =
|
|
239 make_lcrecord_list (sizeof (*p) + imp->size - 1,
|
|
240 lrecord_lstream);
|
|
241 lstream_type_count++;
|
|
242 }
|
|
243
|
|
244 p = XLSTREAM (allocate_managed_lcrecord (Vlstream_free_list[i]));
|
|
245 /* Zero it out, except the header. */
|
|
246 memset ((char *) p + sizeof (p->header), 0,
|
|
247 sizeof (*p) - sizeof (p->header) + imp->size - 1);
|
|
248 p->imp = imp;
|
|
249 Lstream_set_buffering (p, LSTREAM_BLOCK_BUFFERED, 0);
|
|
250 p->flags = LSTREAM_FL_IS_OPEN;
|
|
251
|
|
252 /* convert mode (one of "r", "w", "rc", "wc") to p->flags */
|
|
253 assert (mode[0] == 'r' || mode[0] == 'w');
|
|
254 assert (mode[1] == 'c' || mode[1] == '\0');
|
|
255 p->flags |= (mode[0] == 'r' ? LSTREAM_FL_READ : LSTREAM_FL_WRITE);
|
|
256 if (mode[1] == 'c')
|
|
257 p->flags |= LSTREAM_FL_NO_PARTIAL_CHARS;
|
|
258
|
|
259 return p;
|
|
260 }
|
|
261
|
|
262 void
|
|
263 Lstream_set_character_mode (Lstream *lstr)
|
|
264 {
|
|
265 lstr->flags |= LSTREAM_FL_NO_PARTIAL_CHARS;
|
|
266 }
|
|
267
|
|
268 void
|
|
269 Lstream_delete (Lstream *lstr)
|
|
270 {
|
|
271 int i;
|
|
272 Lisp_Object val = Qnil;
|
|
273
|
|
274 XSETLSTREAM (val, lstr);
|
|
275 for (i = 0; i < lstream_type_count; i++)
|
|
276 {
|
|
277 if (lstream_types[i] == lstr->imp)
|
|
278 {
|
|
279 free_managed_lcrecord (Vlstream_free_list[i], val);
|
|
280 return;
|
|
281 }
|
|
282 }
|
|
283
|
|
284 abort ();
|
|
285 }
|
|
286
|
|
287 static void
|
|
288 signal_simple_internal_error (CONST char *reason, Lisp_Object obj)
|
|
289 {
|
|
290 signal_simple_error (reason, obj);
|
|
291 }
|
|
292
|
|
293 void
|
|
294 Lstream_reopen (Lstream *lstr)
|
|
295 {
|
|
296 if (lstr->flags & LSTREAM_FL_IS_OPEN)
|
|
297 {
|
|
298 Lisp_Object obj = Qnil;
|
|
299 XSETLSTREAM (obj, lstr);
|
|
300 signal_simple_internal_error
|
|
301 ("Internal error: lstream already open", obj);
|
|
302 }
|
|
303 lstr->flags |= LSTREAM_FL_IS_OPEN;
|
|
304 }
|
|
305
|
|
306 /* Attempt to flush out all of the buffered data for writing. */
|
|
307
|
|
308 int
|
|
309 Lstream_flush_out (Lstream *lstr)
|
|
310 {
|
|
311 int num_written;
|
|
312
|
|
313 while (lstr->out_buffer_ind > 0)
|
|
314 {
|
|
315 int size = lstr->out_buffer_ind;
|
|
316 if (! (lstr->flags & LSTREAM_FL_IS_OPEN))
|
|
317 {
|
|
318 Lisp_Object obj = Qnil;
|
|
319 XSETLSTREAM (obj, lstr);
|
|
320 signal_simple_internal_error
|
|
321 ("Internal error: lstream not open", obj);
|
|
322 }
|
|
323 if (! (lstr->flags & LSTREAM_FL_WRITE))
|
|
324 {
|
|
325 Lisp_Object obj = Qnil;
|
|
326 XSETLSTREAM (obj, lstr);
|
|
327 signal_simple_internal_error
|
|
328 ("Internal error: lstream not open for writing", obj);
|
|
329 }
|
|
330 if (!lstr->imp->writer)
|
|
331 {
|
|
332 Lisp_Object obj = Qnil;
|
|
333 XSETLSTREAM (obj, lstr);
|
|
334 signal_simple_internal_error
|
|
335 ("Internal error: lstream has no writer", obj);
|
|
336 }
|
|
337
|
|
338 if (lstr->flags & LSTREAM_FL_NO_PARTIAL_CHARS)
|
|
339 /* It's quite possible for us to get passed an incomplete
|
|
340 character at the end. We need to spit back that
|
|
341 incomplete character. */
|
|
342 {
|
|
343 CONST unsigned char *data = lstr->out_buffer;
|
|
344 CONST unsigned char *dataend = data + size - 1;
|
|
345 assert (size > 0); /* safety check ... */
|
|
346 /* Optimize the most common case. */
|
|
347 if (!BYTE_ASCII_P (*dataend))
|
|
348 {
|
|
349 /* Go back to the beginning of the last (and possibly partial)
|
|
350 character, and bump forward to see if the character is
|
|
351 complete. */
|
|
352 VALIDATE_CHARPTR_BACKWARD (dataend);
|
|
353 if (dataend + REP_BYTES_BY_FIRST_BYTE (*dataend) != data + size)
|
|
354 /* If not, chop the size down to ignore the last char
|
|
355 and stash it away for next time. */
|
|
356 size = dataend - data;
|
|
357 /* If we don't even have one character to write, then just
|
|
358 skip out. */
|
|
359 if (size == 0)
|
|
360 break;
|
|
361 }
|
|
362 }
|
|
363
|
|
364 num_written =
|
|
365 (lstr->imp->writer) (lstr, lstr->out_buffer, size);
|
|
366 if (num_written == 0)
|
|
367 /* If nothing got written, then just hold the data. This may
|
|
368 occur, for example, if this stream does non-blocking I/O;
|
|
369 the attempt to write the data might have resulted in an
|
|
370 EWOULDBLOCK error. */
|
|
371 return 0;
|
|
372 else if (num_written >= lstr->out_buffer_ind)
|
|
373 lstr->out_buffer_ind = 0;
|
|
374 else if (num_written > 0)
|
|
375 {
|
|
376 memmove (lstr->out_buffer, lstr->out_buffer + num_written,
|
|
377 lstr->out_buffer_ind - num_written);
|
|
378 lstr->out_buffer_ind -= num_written;
|
|
379 }
|
|
380 else
|
|
381 /* If error, just hold the data, for similar reasons as above. */
|
|
382 return -1;
|
|
383 }
|
|
384
|
|
385 if (lstr->imp->flusher)
|
|
386 return (lstr->imp->flusher) (lstr);
|
|
387
|
|
388 return 0;
|
|
389 }
|
|
390
|
|
391 int
|
|
392 Lstream_flush (Lstream *lstr)
|
|
393 {
|
|
394 if (Lstream_flush_out (lstr) < 0)
|
|
395 return -1;
|
|
396
|
|
397 /* clear out buffered data */
|
|
398 lstr->in_buffer_current = lstr->in_buffer_ind = 0;
|
|
399 lstr->unget_buffer_ind = 0;
|
|
400
|
|
401 return 0;
|
|
402 }
|
|
403
|
|
404 /* We want to add NUM characters. This function ensures that the
|
|
405 buffer is large enough for this (per the buffering size specified
|
|
406 in the stream) and returns the number of characters we can
|
|
407 actually write. If FORCE is set, ignore the buffering size
|
|
408 and go ahead and make space for all the chars even if it exceeds
|
|
409 the buffering size. (This is used to deal with the possibility
|
|
410 that the stream writer might refuse to write any bytes now, e.g.
|
|
411 if it's getting EWOULDBLOCK errors. We have to keep stocking them
|
|
412 up until they can be written, so as to avoid losing data. */
|
|
413
|
|
414 static int
|
|
415 Lstream_adding (Lstream *lstr, int num, int force)
|
|
416 {
|
|
417 /* Compute the size that the outbuffer needs to be after the
|
|
418 chars are added. */
|
|
419 int size_needed = max (lstr->out_buffer_size,
|
|
420 num + lstr->out_buffer_ind);
|
|
421 /* Maybe chop it down so that we don't buffer more characters
|
|
422 than our advertised buffering size. */
|
|
423 if (!force)
|
|
424 size_needed = min (lstr->buffering_size, size_needed);
|
|
425 DO_REALLOC (lstr->out_buffer, lstr->out_buffer_size,
|
|
426 size_needed, unsigned char);
|
|
427 /* There might be more data buffered than the buffering size,
|
|
428 so make sure we don't return a negative number here. */
|
|
429 return max (0, min (num, size_needed - lstr->out_buffer_ind));
|
|
430 }
|
|
431
|
|
432 /* Like Lstream_write(), but does not handle line-buffering correctly. */
|
|
433
|
|
434 static int
|
|
435 Lstream_write_1 (Lstream *lstr, CONST void *data, int size)
|
|
436 {
|
185
|
437 CONST unsigned char *p = (CONST unsigned char *) data;
|
0
|
438 int off = 0;
|
|
439 if (! (lstr->flags & LSTREAM_FL_IS_OPEN))
|
|
440 {
|
|
441 Lisp_Object obj = Qnil;
|
|
442 XSETLSTREAM (obj, lstr);
|
|
443 signal_simple_internal_error
|
|
444 ("Internal error: lstream not open", obj);
|
|
445 }
|
|
446 if (! (lstr->flags & LSTREAM_FL_WRITE))
|
|
447 {
|
|
448 Lisp_Object obj = Qnil;
|
|
449 XSETLSTREAM (obj, lstr);
|
|
450 signal_simple_internal_error
|
|
451 ("Internal error: lstream not open for writing", obj);
|
|
452 }
|
|
453 {
|
|
454 int couldnt_write_last_time = 0;
|
|
455
|
|
456 while (1)
|
|
457 {
|
|
458 /* Figure out how much we can add to the buffer */
|
|
459 int chunk = Lstream_adding (lstr, size, 0);
|
|
460 if (chunk == 0)
|
|
461 {
|
|
462 if (couldnt_write_last_time)
|
|
463 /* Ung, we ran out of space and tried to flush
|
|
464 the buffer, but it didn't work because the stream
|
|
465 writer is refusing to accept any data. So we
|
|
466 just have to squirrel away all the rest of the
|
|
467 stuff. */
|
|
468 chunk = Lstream_adding (lstr, size, 1);
|
|
469 else
|
|
470 couldnt_write_last_time = 1;
|
|
471 }
|
|
472 /* Do it. */
|
|
473 if (chunk > 0)
|
|
474 {
|
|
475 memcpy (lstr->out_buffer + lstr->out_buffer_ind, p + off, chunk);
|
|
476 lstr->out_buffer_ind += chunk;
|
|
477 lstr->byte_count += chunk;
|
|
478 size -= chunk;
|
|
479 off += chunk;
|
|
480 }
|
|
481 /* If the buffer is full and we have more to add, flush it out. */
|
|
482 if (size > 0)
|
|
483 {
|
|
484 if (Lstream_flush_out (lstr) < 0)
|
|
485 {
|
|
486 if (off == 0)
|
|
487 return -1;
|
|
488 else
|
|
489 return off;
|
|
490 }
|
|
491 }
|
|
492 else
|
|
493 break;
|
|
494 }
|
|
495 }
|
|
496 return off;
|
|
497 }
|
|
498
|
|
499 /* If the stream is not line-buffered, then we can just call
|
|
500 Lstream_write_1(), which writes in chunks. Otherwise, we
|
|
501 repeatedly call Lstream_putc(), which knows how to handle
|
|
502 line buffering. */
|
|
503
|
|
504 int
|
|
505 Lstream_write (Lstream *lstr, CONST void *data, int size)
|
|
506 {
|
|
507 int i;
|
185
|
508 CONST unsigned char *p = (CONST unsigned char *) data;
|
0
|
509
|
|
510 assert (size >= 0);
|
|
511 if (size == 0)
|
|
512 return size;
|
|
513 if (lstr->buffering != LSTREAM_LINE_BUFFERED)
|
|
514 return Lstream_write_1 (lstr, data, size);
|
|
515 for (i = 0; i < size; i++)
|
|
516 {
|
|
517 if (Lstream_putc (lstr, p[i]) < 0)
|
|
518 break;
|
|
519 }
|
|
520 return i == 0 ? -1 : 0;
|
|
521 }
|
|
522
|
|
523 static int
|
|
524 Lstream_raw_read (Lstream *lstr, unsigned char *buffer, int size)
|
|
525 {
|
|
526 if (! (lstr->flags & LSTREAM_FL_IS_OPEN))
|
|
527 {
|
|
528 Lisp_Object obj = Qnil;
|
|
529 XSETLSTREAM (obj, lstr);
|
|
530 signal_simple_internal_error
|
|
531 ("Internal error: lstream not open", obj);
|
|
532 }
|
|
533 if (! (lstr->flags & LSTREAM_FL_READ))
|
|
534 {
|
|
535 Lisp_Object obj = Qnil;
|
|
536 XSETLSTREAM (obj, lstr);
|
|
537 signal_simple_internal_error
|
|
538 ("Internal error: lstream not open for reading", obj);
|
|
539 }
|
|
540 if (!lstr->imp->reader)
|
|
541 {
|
|
542 Lisp_Object obj = Qnil;
|
|
543 XSETLSTREAM (obj, lstr);
|
|
544 signal_simple_internal_error
|
|
545 ("Internal error: lstream has no reader", obj);
|
|
546 }
|
185
|
547
|
0
|
548 return (lstr->imp->reader) (lstr, buffer, size);
|
|
549 }
|
|
550
|
|
551 /* Assuming the buffer is empty, fill it up again. */
|
|
552
|
|
553 static int
|
|
554 Lstream_read_more (Lstream *lstr)
|
|
555 {
|
|
556 #if 0
|
|
557 int size_needed = max (1, min (MAX_READ_SIZE, lstr->buffering_size));
|
|
558 #else
|
|
559 /* If someone requested a larger buffer size, so be it! */
|
|
560 int size_needed = max (1, lstr->buffering_size);
|
|
561 #endif
|
|
562 int size_gotten;
|
|
563
|
|
564 DO_REALLOC (lstr->in_buffer, lstr->in_buffer_size,
|
|
565 size_needed, unsigned char);
|
|
566 size_gotten = Lstream_raw_read (lstr, lstr->in_buffer, size_needed);
|
|
567 lstr->in_buffer_current = max (0, size_gotten);
|
|
568 lstr->in_buffer_ind = 0;
|
|
569 return size_gotten < 0 ? -1 : size_gotten;
|
185
|
570 }
|
0
|
571
|
|
572 int
|
|
573 Lstream_read (Lstream *lstr, void *data, int size)
|
|
574 {
|
|
575 unsigned char *p = (unsigned char *) data;
|
|
576 int off = 0;
|
|
577 int chunk;
|
|
578 int error_occurred = 0;
|
|
579
|
|
580 assert (size >= 0);
|
|
581 if (size == 0)
|
|
582 return 0;
|
|
583
|
|
584 /* First try to get some data from the unget buffer */
|
|
585 chunk = min (size, lstr->unget_buffer_ind);
|
|
586 if (chunk > 0)
|
|
587 {
|
|
588 /* The bytes come back in reverse order. */
|
|
589 for (; off < chunk; off++)
|
|
590 p[off] = lstr->unget_buffer[--lstr->unget_buffer_ind];
|
|
591 lstr->byte_count += chunk;
|
|
592 size -= chunk;
|
|
593 }
|
|
594
|
|
595 while (size > 0)
|
|
596 {
|
|
597 /* Take whatever we can from the in buffer */
|
|
598 chunk = min (size, lstr->in_buffer_current - lstr->in_buffer_ind);
|
|
599 if (chunk > 0)
|
|
600 {
|
|
601 memcpy (p + off, lstr->in_buffer + lstr->in_buffer_ind, chunk);
|
|
602 lstr->in_buffer_ind += chunk;
|
|
603 lstr->byte_count += chunk;
|
|
604 size -= chunk;
|
|
605 off += chunk;
|
|
606 }
|
|
607
|
|
608 /* If we need some more, try to get some more from the stream's end */
|
|
609 if (size > 0)
|
|
610 {
|
|
611 int retval = Lstream_read_more (lstr);
|
|
612 if (retval < 0)
|
|
613 error_occurred = 1;
|
|
614 if (retval <= 0)
|
|
615 break;
|
|
616 }
|
|
617 }
|
|
618
|
|
619 /* #### Beware of OFF ending up 0. */
|
|
620 if ((lstr->flags & LSTREAM_FL_NO_PARTIAL_CHARS) && off > 0)
|
|
621 {
|
|
622 /* It's quite possible for us to get passed an incomplete
|
|
623 character at the end. We need to spit back that
|
|
624 incomplete character. */
|
|
625 CONST unsigned char *dataend = p + off - 1;
|
|
626 /* Optimize the most common case. */
|
|
627 if (!BYTE_ASCII_P (*dataend))
|
|
628 {
|
|
629 /* Go back to the beginning of the last (and possibly partial)
|
|
630 character, and bump forward to see if the character is
|
|
631 complete. */
|
|
632 VALIDATE_CHARPTR_BACKWARD (dataend);
|
|
633 if (dataend + REP_BYTES_BY_FIRST_BYTE (*dataend) != p + off)
|
|
634 {
|
|
635 int newoff = dataend - p;
|
|
636 /* If not, chop the size down to ignore the last char
|
|
637 and stash it away for next time. */
|
|
638 Lstream_unread (lstr, dataend, off - newoff);
|
|
639 off = newoff;
|
|
640 }
|
|
641 }
|
|
642 }
|
|
643
|
|
644 return ((off == 0 && error_occurred) ? -1 : off);
|
|
645 }
|
|
646
|
|
647 void
|
|
648 Lstream_unread (Lstream *lstr, CONST void *data, int size)
|
|
649 {
|
|
650 int i;
|
|
651 unsigned char *p = (unsigned char *) data;
|
|
652
|
|
653 /* Make sure buffer is big enough */
|
|
654
|
|
655 DO_REALLOC (lstr->unget_buffer, lstr->unget_buffer_size,
|
|
656 lstr->unget_buffer_ind + size, unsigned char);
|
|
657
|
|
658 /* Bytes have to go on in reverse order -- they are reversed
|
|
659 again when read back. */
|
|
660 for (i = size - 1; i >= 0; i--)
|
|
661 lstr->unget_buffer[lstr->unget_buffer_ind++] = p[i];
|
|
662 lstr->byte_count -= size;
|
|
663 }
|
|
664
|
|
665 int
|
|
666 Lstream_rewind (Lstream *lstr)
|
|
667 {
|
|
668 if (!lstr->imp->rewinder)
|
|
669 {
|
|
670 Lisp_Object obj = Qnil;
|
|
671 XSETLSTREAM (obj, lstr);
|
|
672 signal_simple_internal_error
|
|
673 ("Internal error: lstream has no rewinder", obj);
|
|
674 }
|
|
675 if (Lstream_flush (lstr) < 0)
|
|
676 return -1;
|
|
677 lstr->byte_count = 0;
|
|
678 return (lstr->imp->rewinder) (lstr);
|
|
679 }
|
185
|
680
|
0
|
681 int
|
|
682 Lstream_seekable_p (Lstream *lstr)
|
|
683 {
|
|
684 if (!lstr->imp->rewinder)
|
|
685 return 0;
|
|
686 if (!lstr->imp->seekable_p)
|
|
687 return 1;
|
|
688 return (lstr->imp->seekable_p) (lstr);
|
|
689 }
|
|
690
|
|
691 static int
|
|
692 Lstream_pseudo_close (Lstream *lstr)
|
|
693 {
|
74
|
694 int rc;
|
|
695
|
0
|
696 if (!lstr->flags & LSTREAM_FL_IS_OPEN)
|
|
697 {
|
|
698 Lisp_Object obj = Qnil;
|
|
699 XSETLSTREAM (obj, lstr);
|
|
700 signal_simple_internal_error
|
|
701 ("Internal error: lstream is not open", obj);
|
|
702 }
|
|
703
|
|
704 /* don't check errors here -- best not to risk file descriptor loss */
|
74
|
705 rc = Lstream_flush (lstr);
|
0
|
706
|
74
|
707 return rc;
|
0
|
708 }
|
|
709
|
|
710 int
|
|
711 Lstream_close (Lstream *lstr)
|
|
712 {
|
82
|
713 int rc = 0;
|
74
|
714
|
0
|
715 if (lstr->flags & LSTREAM_FL_IS_OPEN)
|
|
716 {
|
|
717 /* don't return here on error, or file descriptor leak will result. */
|
74
|
718 rc = Lstream_pseudo_close (lstr);
|
0
|
719 if (lstr->imp->closer)
|
|
720 {
|
|
721 if ((lstr->imp->closer) (lstr) < 0)
|
|
722 return -1;
|
|
723 }
|
|
724 }
|
|
725
|
|
726 lstr->flags &= ~LSTREAM_FL_IS_OPEN;
|
|
727 lstr->byte_count = 0;
|
|
728 /* Note that Lstream_flush() reset all the buffer indices. That way,
|
|
729 the next call to Lstream_putc(), Lstream_getc(), or Lstream_ungetc()
|
|
730 on a closed stream will call into the function equivalents, which will
|
|
731 cause an error. */
|
|
732
|
|
733 /* We set the pointers to 0 so that we don't lose when this function
|
|
734 is called more than once on the same object */
|
|
735 if (lstr->out_buffer)
|
|
736 {
|
|
737 xfree (lstr->out_buffer);
|
|
738 lstr->out_buffer = 0;
|
|
739 }
|
|
740 if (lstr->in_buffer)
|
|
741 {
|
|
742 xfree (lstr->in_buffer);
|
|
743 lstr->in_buffer = 0;
|
|
744 }
|
|
745 if (lstr->unget_buffer)
|
|
746 {
|
|
747 xfree (lstr->unget_buffer);
|
|
748 lstr->unget_buffer = 0;
|
|
749 }
|
|
750
|
74
|
751 return rc;
|
0
|
752 }
|
|
753
|
|
754 int
|
|
755 Lstream_fputc (Lstream *lstr, int c)
|
|
756 {
|
|
757 unsigned char ch = (unsigned char) c;
|
|
758 int retval = Lstream_write_1 (lstr, &ch, 1);
|
|
759 if (retval >= 0 && lstr->buffering == LSTREAM_LINE_BUFFERED && ch == '\n')
|
|
760 return Lstream_flush_out (lstr);
|
|
761 return retval < 0 ? -1 : 0;
|
|
762 }
|
|
763
|
|
764 int
|
|
765 Lstream_fgetc (Lstream *lstr)
|
|
766 {
|
|
767 unsigned char ch;
|
|
768 if (Lstream_read (lstr, &ch, 1) <= 0)
|
|
769 return -1;
|
|
770 return ch;
|
|
771 }
|
|
772
|
|
773 void
|
|
774 Lstream_fungetc (Lstream *lstr, int c)
|
|
775 {
|
|
776 unsigned char ch = (unsigned char) c;
|
|
777 Lstream_unread (lstr, &ch, 1);
|
|
778 }
|
|
779
|
|
780
|
|
781 /************************ some stream implementations *********************/
|
|
782
|
|
783 /*********** a stdio stream ***********/
|
|
784
|
|
785 struct stdio_stream
|
|
786 {
|
|
787 FILE *file;
|
|
788 int closing;
|
|
789 };
|
|
790
|
|
791 #define STDIO_STREAM_DATA(stream) LSTREAM_TYPE_DATA (stream, stdio)
|
|
792
|
|
793 DEFINE_LSTREAM_IMPLEMENTATION ("stdio", lstream_stdio,
|
|
794 sizeof (struct stdio_stream));
|
|
795
|
|
796 static Lisp_Object
|
|
797 make_stdio_stream_1 (FILE *stream, int flags, CONST char *mode)
|
|
798 {
|
|
799 Lisp_Object obj = Qnil;
|
|
800 Lstream *lstr = Lstream_new (lstream_stdio, mode);
|
|
801 struct stdio_stream *str = STDIO_STREAM_DATA (lstr);
|
|
802 str->file = stream;
|
|
803 str->closing = flags & LSTR_CLOSING;
|
|
804 XSETLSTREAM (obj, lstr);
|
|
805 return obj;
|
|
806 }
|
|
807
|
|
808 Lisp_Object
|
|
809 make_stdio_input_stream (FILE *stream, int flags)
|
|
810 {
|
|
811 return make_stdio_stream_1 (stream, flags, "r");
|
|
812 }
|
|
813
|
|
814 Lisp_Object
|
|
815 make_stdio_output_stream (FILE *stream, int flags)
|
|
816 {
|
|
817 return make_stdio_stream_1 (stream, flags, "w");
|
|
818 }
|
|
819
|
|
820 static int
|
|
821 stdio_reader (Lstream *stream, unsigned char *data, int size)
|
|
822 {
|
|
823 struct stdio_stream *str = STDIO_STREAM_DATA (stream);
|
|
824 size_t val = fread (data, 1, (size_t) size, str->file);
|
|
825 if (!val && ferror (str->file))
|
|
826 return -1;
|
|
827 return (int) val;
|
|
828 }
|
|
829
|
|
830 static int
|
|
831 stdio_writer (Lstream *stream, CONST unsigned char *data, int size)
|
|
832 {
|
|
833 struct stdio_stream *str = STDIO_STREAM_DATA (stream);
|
|
834 size_t val = fwrite (data, 1, (size_t) size, str->file);
|
|
835 if (!val && ferror (str->file))
|
|
836 return -1;
|
|
837 return (int) val;
|
|
838 }
|
|
839
|
|
840 static int
|
|
841 stdio_rewinder (Lstream *stream)
|
|
842 {
|
|
843 rewind (STDIO_STREAM_DATA (stream)->file);
|
|
844 return 0;
|
|
845 }
|
|
846
|
|
847 static int
|
|
848 stdio_seekable_p (Lstream *stream)
|
|
849 {
|
|
850 struct stdio_stream *str = STDIO_STREAM_DATA (stream);
|
|
851 {
|
|
852 struct stat lestat;
|
|
853
|
|
854 if (fstat (fileno (str->file), &lestat) < 0)
|
|
855 return 0;
|
|
856 return S_ISREG (lestat.st_mode);
|
|
857 }
|
|
858 }
|
|
859
|
|
860 static int
|
|
861 stdio_flusher (Lstream *stream)
|
|
862 {
|
|
863 struct stdio_stream *str = STDIO_STREAM_DATA (stream);
|
|
864 if (stream->flags & LSTREAM_FL_WRITE)
|
|
865 return fflush (str->file);
|
|
866 else
|
|
867 /* call fpurge? Only exists on some systems. */
|
|
868 return 0;
|
|
869 }
|
|
870
|
|
871 static int
|
|
872 stdio_closer (Lstream *stream)
|
|
873 {
|
|
874 struct stdio_stream *str = STDIO_STREAM_DATA (stream);
|
|
875 if (str->closing)
|
|
876 return fclose (str->file);
|
|
877 else
|
|
878 if (stream->flags & LSTREAM_FL_WRITE)
|
|
879 return fflush (str->file);
|
|
880 else
|
|
881 /* call fpurge? Only exists on some systems. */
|
|
882 return 0;
|
|
883 }
|
|
884
|
|
885 /*********** a file descriptor ***********/
|
|
886
|
|
887 struct filedesc_stream
|
|
888 {
|
|
889 int fd;
|
|
890 int pty_max_bytes;
|
|
891 Bufbyte eof_char;
|
|
892 int starting_pos;
|
|
893 int current_pos;
|
|
894 int end_pos;
|
|
895 int chars_sans_newline;
|
74
|
896 unsigned int closing :1;
|
|
897 unsigned int allow_quit :1;
|
|
898 unsigned int blocked_ok :1;
|
|
899 unsigned int pty_flushing :1;
|
|
900 unsigned int blocking_error_p :1;
|
0
|
901 };
|
|
902
|
|
903 #define FILEDESC_STREAM_DATA(stream) LSTREAM_TYPE_DATA (stream, filedesc)
|
|
904
|
|
905 DEFINE_LSTREAM_IMPLEMENTATION ("filedesc", lstream_filedesc,
|
|
906 sizeof (struct filedesc_stream));
|
|
907
|
|
908 /* Make a stream that reads from or writes to a file descriptor FILEDESC.
|
|
909 OFFSET is the offset from the *current* file pointer that the reading
|
|
910 should start at. COUNT is the number of bytes to be read (it is
|
|
911 ignored when writing); -1 for unlimited. */
|
|
912 static Lisp_Object
|
|
913 make_filedesc_stream_1 (int filedesc, int offset, int count, int flags,
|
|
914 CONST char *mode)
|
|
915 {
|
|
916 Lisp_Object obj = Qnil;
|
|
917 Lstream *lstr = Lstream_new (lstream_filedesc, mode);
|
|
918 struct filedesc_stream *fstr = FILEDESC_STREAM_DATA (lstr);
|
|
919 fstr->fd = filedesc;
|
|
920 fstr->closing = !!(flags & LSTR_CLOSING);
|
|
921 fstr->allow_quit = !!(flags & LSTR_ALLOW_QUIT);
|
|
922 fstr->blocked_ok = !!(flags & LSTR_BLOCKED_OK);
|
|
923 fstr->pty_flushing = !!(flags & LSTR_PTY_FLUSHING);
|
|
924 fstr->blocking_error_p = 0;
|
|
925 fstr->chars_sans_newline = 0;
|
|
926 fstr->starting_pos = lseek (filedesc, offset, SEEK_CUR);
|
|
927 if (fstr->starting_pos < 0)
|
|
928 fstr->current_pos = 0;
|
|
929 else
|
|
930 fstr->current_pos = fstr->starting_pos;
|
|
931 if (count < 0)
|
|
932 fstr->end_pos = -1;
|
|
933 else
|
|
934 fstr->end_pos = fstr->starting_pos + count;
|
|
935 XSETLSTREAM (obj, lstr);
|
|
936 return obj;
|
|
937 }
|
|
938
|
|
939 Lisp_Object
|
|
940 make_filedesc_input_stream (int filedesc, int offset, int count, int flags)
|
|
941 {
|
|
942 return make_filedesc_stream_1 (filedesc, offset, count, flags, "r");
|
|
943 }
|
|
944
|
|
945 Lisp_Object
|
|
946 make_filedesc_output_stream (int filedesc, int offset, int count, int flags)
|
|
947 {
|
|
948 return make_filedesc_stream_1 (filedesc, offset, count, flags, "w");
|
|
949 }
|
|
950
|
|
951 static int
|
|
952 filedesc_reader (Lstream *stream, unsigned char *data, int size)
|
|
953 {
|
|
954 struct filedesc_stream *str = FILEDESC_STREAM_DATA (stream);
|
|
955 if (str->end_pos >= 0)
|
|
956 size = min (size, str->end_pos - str->current_pos);
|
|
957 size = (str->allow_quit ? read_allowing_quit : read) (str->fd, data, size);
|
|
958 if (size > 0)
|
|
959 str->current_pos += size;
|
|
960 return size;
|
|
961 }
|
|
962
|
|
963 static int
|
|
964 errno_would_block_p (int val)
|
|
965 {
|
|
966 #ifdef EWOULDBLOCK
|
|
967 if (val == EWOULDBLOCK)
|
|
968 return 1;
|
|
969 #endif
|
|
970 #ifdef EAGAIN
|
|
971 if (val == EAGAIN)
|
|
972 return 1;
|
|
973 #endif
|
|
974 return 0;
|
|
975 }
|
|
976
|
|
977 static int
|
|
978 filedesc_writer (Lstream *stream, CONST unsigned char *data, int size)
|
|
979 {
|
|
980 struct filedesc_stream *str = FILEDESC_STREAM_DATA (stream);
|
|
981 int retval;
|
185
|
982 int need_newline = 0;
|
0
|
983
|
|
984 /* This function would be simple if it were not for the blasted
|
|
985 PTY max-bytes stuff. Why the hell can't they just have written
|
|
986 the PTY drivers right so this problem doesn't exist?
|
|
987
|
|
988 Maybe all the PTY crap here should be moved into another stream
|
|
989 that does nothing but periodically insert EOF's as necessary. */
|
|
990 if (str->pty_flushing)
|
|
991 {
|
|
992 /* To make life easy, only send out one line at the most. */
|
|
993 CONST unsigned char *ptr;
|
|
994
|
163
|
995 ptr = (CONST unsigned char *) memchr (data, '\n', size);
|
0
|
996 if (ptr)
|
|
997 need_newline = 1;
|
|
998 else
|
|
999 ptr = data + size;
|
|
1000 if (ptr - data >= str->pty_max_bytes - str->chars_sans_newline)
|
|
1001 {
|
|
1002 ptr = data + str->pty_max_bytes - str->chars_sans_newline;
|
|
1003 need_newline = 0;
|
|
1004 }
|
|
1005 size = ptr - data;
|
|
1006 }
|
|
1007
|
|
1008 /**** start of non-PTY-crap ****/
|
|
1009 if (size > 0)
|
|
1010 retval = ((str->allow_quit ? write_allowing_quit : write)
|
|
1011 (str->fd, data, size));
|
|
1012 else
|
|
1013 retval = 0;
|
|
1014 if (retval < 0 && errno_would_block_p (errno) && str->blocked_ok)
|
|
1015 {
|
|
1016 str->blocking_error_p = 1;
|
|
1017 return 0;
|
|
1018 }
|
|
1019 str->blocking_error_p = 0;
|
|
1020 if (retval < 0)
|
|
1021 return retval;
|
|
1022 /**** end non-PTY-crap ****/
|
|
1023
|
|
1024 if (str->pty_flushing)
|
|
1025 {
|
|
1026 str->chars_sans_newline += retval;
|
|
1027 /* Note that a newline was not among the bytes written out.
|
|
1028 Add to the number of non-newline bytes written out,
|
|
1029 and flush with an EOF if necessary. Be careful to
|
|
1030 keep track of write errors as we go along and look
|
|
1031 out for EWOULDBLOCK. */
|
|
1032 if (str->chars_sans_newline >= str->pty_max_bytes)
|
|
1033 {
|
|
1034 int retval2 = ((str->allow_quit ? write_allowing_quit : write)
|
|
1035 (str->fd, &str->eof_char, 1));
|
|
1036 if (retval2 > 0)
|
|
1037 str->chars_sans_newline = 0;
|
|
1038 else if (retval2 < 0)
|
|
1039 {
|
|
1040 /* Error writing the EOF char. If nothing got written,
|
|
1041 then treat this as an error -- either return an error
|
|
1042 condition or set the blocking-error flag. */
|
|
1043 if (retval == 0)
|
|
1044 {
|
|
1045 if (errno_would_block_p (errno) && str->blocked_ok)
|
|
1046 {
|
|
1047 str->blocking_error_p = 1;
|
|
1048 return 0;
|
|
1049 }
|
|
1050 else
|
|
1051 return retval2;
|
|
1052 }
|
|
1053 else
|
|
1054 return retval;
|
|
1055 }
|
|
1056 }
|
|
1057 }
|
|
1058
|
|
1059 /* The need_newline flag is necessary because otherwise when the
|
|
1060 first byte is a newline, we'd get stuck never writing anything
|
|
1061 in pty-flushing mode. */
|
|
1062 if (need_newline)
|
|
1063 {
|
|
1064 Bufbyte nl = '\n';
|
|
1065 int retval2 = ((str->allow_quit ? write_allowing_quit : write)
|
|
1066 (str->fd, &nl, 1));
|
|
1067 if (retval2 > 0)
|
|
1068 {
|
|
1069 str->chars_sans_newline = 0;
|
|
1070 retval++;
|
|
1071 }
|
|
1072 else if (retval2 < 0)
|
|
1073 {
|
|
1074 /* Error writing the newline char. If nothing got written,
|
|
1075 then treat this as an error -- either return an error
|
|
1076 condition or set the blocking-error flag. */
|
|
1077 if (retval == 0)
|
|
1078 {
|
|
1079 if (errno_would_block_p (errno) && str->blocked_ok)
|
|
1080 {
|
|
1081 str->blocking_error_p = 1;
|
|
1082 return 0;
|
|
1083 }
|
|
1084 else
|
|
1085 return retval2;
|
|
1086 }
|
|
1087 else
|
|
1088 return retval;
|
|
1089 }
|
|
1090 }
|
|
1091
|
|
1092 return retval;
|
|
1093 }
|
|
1094
|
|
1095 static int
|
|
1096 filedesc_rewinder (Lstream *stream)
|
|
1097 {
|
|
1098 struct filedesc_stream *str = FILEDESC_STREAM_DATA (stream);
|
|
1099 if (str->starting_pos < 0 ||
|
|
1100 lseek (FILEDESC_STREAM_DATA (stream)->fd, str->starting_pos,
|
|
1101 SEEK_SET) == -1)
|
|
1102 return -1;
|
|
1103 else
|
|
1104 {
|
|
1105 str->current_pos = str->starting_pos;
|
|
1106 return 0;
|
|
1107 }
|
|
1108 }
|
|
1109
|
|
1110 static int
|
|
1111 filedesc_seekable_p (Lstream *stream)
|
|
1112 {
|
|
1113 struct filedesc_stream *str = FILEDESC_STREAM_DATA (stream);
|
|
1114 if (str->starting_pos < 0)
|
|
1115 return 0;
|
|
1116 else
|
|
1117 {
|
|
1118 struct stat lestat;
|
|
1119
|
|
1120 if (fstat (str->fd, &lestat) < 0)
|
|
1121 return 0;
|
|
1122 return S_ISREG (lestat.st_mode);
|
|
1123 }
|
|
1124 }
|
|
1125
|
|
1126 static int
|
|
1127 filedesc_closer (Lstream *stream)
|
|
1128 {
|
|
1129 struct filedesc_stream *str = FILEDESC_STREAM_DATA (stream);
|
|
1130 if (str->closing)
|
|
1131 return close (str->fd);
|
|
1132 else
|
|
1133 return 0;
|
|
1134 }
|
|
1135
|
|
1136 void
|
|
1137 filedesc_stream_set_pty_flushing (Lstream *stream, int pty_max_bytes,
|
|
1138 Bufbyte eof_char)
|
|
1139 {
|
|
1140 struct filedesc_stream *str = FILEDESC_STREAM_DATA (stream);
|
|
1141 str->pty_max_bytes = pty_max_bytes;
|
|
1142 str->eof_char = eof_char;
|
|
1143 }
|
|
1144
|
|
1145 int
|
|
1146 filedesc_stream_was_blocked (Lstream *stream)
|
|
1147 {
|
|
1148 struct filedesc_stream *str = FILEDESC_STREAM_DATA (stream);
|
|
1149 return str->blocking_error_p;
|
|
1150 }
|
|
1151
|
|
1152 /*********** read from a Lisp string ***********/
|
|
1153
|
|
1154 #define LISP_STRING_STREAM_DATA(stream) LSTREAM_TYPE_DATA (stream, lisp_string)
|
|
1155
|
|
1156 struct lisp_string_stream
|
|
1157 {
|
|
1158 Lisp_Object obj;
|
|
1159 Bytecount init_offset;
|
|
1160 Bytecount offset, end;
|
|
1161 };
|
|
1162
|
|
1163 DEFINE_LSTREAM_IMPLEMENTATION ("lisp-string", lstream_lisp_string,
|
|
1164 sizeof (struct lisp_string_stream));
|
|
1165
|
|
1166 Lisp_Object
|
|
1167 make_lisp_string_input_stream (Lisp_Object string, Bytecount offset,
|
|
1168 Bytecount len)
|
|
1169 {
|
|
1170 Lisp_Object obj = Qnil;
|
|
1171 Lstream *lstr;
|
|
1172 struct lisp_string_stream *str;
|
|
1173
|
|
1174 CHECK_STRING (string);
|
|
1175 if (len < 0)
|
16
|
1176 len = XSTRING_LENGTH (string) - offset;
|
0
|
1177 assert (offset >= 0);
|
|
1178 assert (len >= 0);
|
16
|
1179 assert (offset + len <= XSTRING_LENGTH (string));
|
0
|
1180
|
|
1181 lstr = Lstream_new (lstream_lisp_string, "r");
|
|
1182 str = LISP_STRING_STREAM_DATA (lstr);
|
|
1183 str->offset = offset;
|
|
1184 str->end = offset + len;
|
|
1185 str->init_offset = offset;
|
|
1186 str->obj = string;
|
|
1187 XSETLSTREAM (obj, lstr);
|
|
1188 return obj;
|
|
1189 }
|
185
|
1190
|
0
|
1191 static int
|
|
1192 lisp_string_reader (Lstream *stream, unsigned char *data, int size)
|
|
1193 {
|
|
1194 struct lisp_string_stream *str = LISP_STRING_STREAM_DATA (stream);
|
|
1195 /* Don't lose if the string shrank past us ... */
|
16
|
1196 Bytecount offset = min (str->offset, XSTRING_LENGTH (str->obj));
|
|
1197 Bufbyte *strstart = XSTRING_DATA (str->obj);
|
0
|
1198 Bufbyte *start = strstart + offset;
|
|
1199
|
|
1200 /* ... or if someone changed the string and we ended up in the
|
|
1201 middle of a character. */
|
|
1202 /* Being in the middle of a character is `normal' unless
|
|
1203 LSTREAM_NO_PARTIAL_CHARS - mrb */
|
|
1204 if (stream->flags & LSTREAM_FL_NO_PARTIAL_CHARS)
|
|
1205 VALIDATE_CHARPTR_BACKWARD (start);
|
|
1206 offset = start - strstart;
|
|
1207 size = min (size, str->end - offset);
|
|
1208 assert (size >= 0); /* paranoia */
|
|
1209 memcpy (data, start, size);
|
|
1210 str->offset = offset + size;
|
|
1211 return size;
|
|
1212 }
|
|
1213
|
|
1214 static int
|
|
1215 lisp_string_rewinder (Lstream *stream)
|
|
1216 {
|
|
1217 struct lisp_string_stream *str = LISP_STRING_STREAM_DATA (stream);
|
|
1218 int pos = str->init_offset;
|
|
1219 if (pos > str->end)
|
|
1220 pos = str->end;
|
|
1221 /* Don't lose if the string shrank past us ... */
|
16
|
1222 pos = min (pos, XSTRING_LENGTH (str->obj));
|
0
|
1223 /* ... or if someone changed the string and we ended up in the
|
|
1224 middle of a character. */
|
|
1225 {
|
16
|
1226 Bufbyte *strstart = XSTRING_DATA (str->obj);
|
0
|
1227 Bufbyte *start = strstart + pos;
|
|
1228 VALIDATE_CHARPTR_BACKWARD (start);
|
|
1229 pos = start - strstart;
|
|
1230 }
|
|
1231 str->offset = pos;
|
|
1232 return 0;
|
|
1233 }
|
|
1234
|
|
1235 static Lisp_Object
|
|
1236 lisp_string_marker (Lisp_Object stream, void (*markobj) (Lisp_Object))
|
|
1237 {
|
|
1238 struct lisp_string_stream *str = LISP_STRING_STREAM_DATA (XLSTREAM (stream));
|
|
1239 return str->obj;
|
|
1240 }
|
|
1241
|
|
1242 /*********** a fixed buffer ***********/
|
|
1243
|
|
1244 #define FIXED_BUFFER_STREAM_DATA(stream) \
|
|
1245 LSTREAM_TYPE_DATA (stream, fixed_buffer)
|
|
1246
|
|
1247 struct fixed_buffer_stream
|
|
1248 {
|
|
1249 CONST unsigned char *inbuf;
|
|
1250 unsigned char *outbuf;
|
|
1251 int size;
|
|
1252 int offset;
|
|
1253 };
|
|
1254
|
|
1255 DEFINE_LSTREAM_IMPLEMENTATION ("fixed-buffer", lstream_fixed_buffer,
|
|
1256 sizeof (struct fixed_buffer_stream));
|
|
1257
|
|
1258 Lisp_Object
|
|
1259 make_fixed_buffer_input_stream (CONST unsigned char *buf, int size)
|
|
1260 {
|
|
1261 Lisp_Object obj = Qnil;
|
|
1262 Lstream *lstr;
|
|
1263 struct fixed_buffer_stream *str;
|
|
1264
|
|
1265 lstr = Lstream_new (lstream_fixed_buffer, "r");
|
|
1266 str = FIXED_BUFFER_STREAM_DATA (lstr);
|
|
1267 str->inbuf = buf;
|
|
1268 str->size = size;
|
|
1269 XSETLSTREAM (obj, lstr);
|
|
1270 return obj;
|
|
1271 }
|
185
|
1272
|
0
|
1273 Lisp_Object
|
|
1274 make_fixed_buffer_output_stream (unsigned char *buf, int size)
|
|
1275 {
|
|
1276 Lisp_Object obj = Qnil;
|
|
1277 Lstream *lstr;
|
|
1278 struct fixed_buffer_stream *str;
|
|
1279
|
|
1280 lstr = Lstream_new (lstream_fixed_buffer, "w");
|
|
1281 str = FIXED_BUFFER_STREAM_DATA (lstr);
|
|
1282 str->outbuf = buf;
|
|
1283 str->size = size;
|
|
1284 XSETLSTREAM (obj, lstr);
|
|
1285 return obj;
|
|
1286 }
|
|
1287
|
|
1288 static int
|
|
1289 fixed_buffer_reader (Lstream *stream, unsigned char *data, int size)
|
|
1290 {
|
|
1291 struct fixed_buffer_stream *str = FIXED_BUFFER_STREAM_DATA (stream);
|
|
1292 size = min (size, str->size - str->offset);
|
|
1293 memcpy (data, str->inbuf + str->offset, size);
|
|
1294 str->offset += size;
|
|
1295 return size;
|
|
1296 }
|
|
1297
|
|
1298 static int
|
|
1299 fixed_buffer_writer (Lstream *stream, CONST unsigned char *data, int size)
|
|
1300 {
|
|
1301 struct fixed_buffer_stream *str = FIXED_BUFFER_STREAM_DATA (stream);
|
|
1302 if (str->offset == str->size)
|
|
1303 {
|
|
1304 /* If we're at the end, just throw away the data and pretend
|
|
1305 we wrote all of it. If we return 0, then the lstream routines
|
|
1306 will try again and again to write it out. */
|
|
1307 return size;
|
|
1308 }
|
|
1309 size = min (size, str->size - str->offset);
|
|
1310 memcpy (str->outbuf + str->offset, data, size);
|
|
1311 str->offset += size;
|
|
1312 return size;
|
|
1313 }
|
|
1314
|
|
1315 static int
|
|
1316 fixed_buffer_rewinder (Lstream *stream)
|
|
1317 {
|
|
1318 FIXED_BUFFER_STREAM_DATA (stream)->offset = 0;
|
|
1319 return 0;
|
|
1320 }
|
|
1321
|
|
1322 CONST unsigned char *
|
|
1323 fixed_buffer_input_stream_ptr (Lstream *stream)
|
|
1324 {
|
|
1325 assert (stream->imp == lstream_fixed_buffer);
|
|
1326 return FIXED_BUFFER_STREAM_DATA (stream)->inbuf;
|
|
1327 }
|
|
1328
|
|
1329 unsigned char *
|
|
1330 fixed_buffer_output_stream_ptr (Lstream *stream)
|
|
1331 {
|
|
1332 assert (stream->imp == lstream_fixed_buffer);
|
|
1333 return FIXED_BUFFER_STREAM_DATA (stream)->outbuf;
|
|
1334 }
|
|
1335
|
|
1336 /*********** write to a resizing buffer ***********/
|
|
1337
|
|
1338 #define RESIZING_BUFFER_STREAM_DATA(stream) \
|
|
1339 LSTREAM_TYPE_DATA (stream, resizing_buffer)
|
|
1340
|
|
1341 struct resizing_buffer_stream
|
|
1342 {
|
|
1343 unsigned char *buf;
|
|
1344 int allocked;
|
|
1345 int max_stored;
|
|
1346 int stored;
|
|
1347 };
|
|
1348
|
|
1349 DEFINE_LSTREAM_IMPLEMENTATION ("resizing-buffer", lstream_resizing_buffer,
|
|
1350 sizeof (struct resizing_buffer_stream));
|
|
1351
|
|
1352 Lisp_Object
|
|
1353 make_resizing_buffer_output_stream (void)
|
|
1354 {
|
|
1355 Lisp_Object obj = Qnil;
|
|
1356 XSETLSTREAM (obj, Lstream_new (lstream_resizing_buffer, "w"));
|
|
1357 return obj;
|
|
1358 }
|
185
|
1359
|
0
|
1360 static int
|
|
1361 resizing_buffer_writer (Lstream *stream, CONST unsigned char *data, int size)
|
|
1362 {
|
|
1363 struct resizing_buffer_stream *str = RESIZING_BUFFER_STREAM_DATA (stream);
|
|
1364 DO_REALLOC (str->buf, str->allocked, str->stored + size, unsigned char);
|
|
1365 memcpy (str->buf + str->stored, data, size);
|
|
1366 str->stored += size;
|
|
1367 str->max_stored = max (str->max_stored, str->stored);
|
|
1368 return size;
|
|
1369 }
|
|
1370
|
|
1371 static int
|
|
1372 resizing_buffer_rewinder (Lstream *stream)
|
|
1373 {
|
|
1374 RESIZING_BUFFER_STREAM_DATA (stream)->stored = 0;
|
|
1375 return 0;
|
|
1376 }
|
|
1377
|
|
1378 static int
|
|
1379 resizing_buffer_closer (Lstream *stream)
|
|
1380 {
|
|
1381 struct resizing_buffer_stream *str = RESIZING_BUFFER_STREAM_DATA (stream);
|
|
1382 if (str->buf)
|
|
1383 {
|
|
1384 xfree (str->buf);
|
|
1385 str->buf = 0;
|
|
1386 }
|
|
1387 return 0;
|
|
1388 }
|
|
1389
|
|
1390 unsigned char *
|
|
1391 resizing_buffer_stream_ptr (Lstream *stream)
|
|
1392 {
|
|
1393 return RESIZING_BUFFER_STREAM_DATA (stream)->buf;
|
|
1394 }
|
|
1395
|
|
1396 /*********** write to an unsigned-char dynarr ***********/
|
|
1397
|
|
1398 /* Note: If you have a dynarr whose type is not unsigned_char_dynarr
|
|
1399 but which is really just an unsigned_char_dynarr (e.g. its type
|
|
1400 is Bufbyte or Extbyte), just cast to unsigned_char_dynarr. */
|
|
1401
|
|
1402 #define DYNARR_STREAM_DATA(stream) \
|
|
1403 LSTREAM_TYPE_DATA (stream, dynarr)
|
|
1404
|
|
1405 struct dynarr_stream
|
|
1406 {
|
|
1407 unsigned_char_dynarr *dyn;
|
|
1408 };
|
|
1409
|
|
1410 DEFINE_LSTREAM_IMPLEMENTATION ("dynarr", lstream_dynarr,
|
|
1411 sizeof (struct dynarr_stream));
|
|
1412
|
|
1413 Lisp_Object
|
|
1414 make_dynarr_output_stream (unsigned_char_dynarr *dyn)
|
|
1415 {
|
|
1416 Lisp_Object obj = Qnil;
|
|
1417 XSETLSTREAM (obj, Lstream_new (lstream_dynarr, "w"));
|
|
1418 DYNARR_STREAM_DATA (XLSTREAM (obj))->dyn = dyn;
|
|
1419 return obj;
|
|
1420 }
|
185
|
1421
|
0
|
1422 static int
|
|
1423 dynarr_writer (Lstream *stream, CONST unsigned char *data, int size)
|
|
1424 {
|
|
1425 struct dynarr_stream *str = DYNARR_STREAM_DATA (stream);
|
|
1426 Dynarr_add_many (str->dyn, data, size);
|
|
1427 return size;
|
|
1428 }
|
|
1429
|
|
1430 static int
|
|
1431 dynarr_rewinder (Lstream *stream)
|
|
1432 {
|
|
1433 Dynarr_reset (DYNARR_STREAM_DATA (stream)->dyn);
|
|
1434 return 0;
|
|
1435 }
|
|
1436
|
|
1437 static int
|
|
1438 dynarr_closer (Lstream *stream)
|
|
1439 {
|
|
1440 return 0;
|
|
1441 }
|
|
1442
|
|
1443 /************ read from or write to a Lisp buffer ************/
|
|
1444
|
|
1445 /* Note: Lisp-buffer read streams never return partial characters,
|
|
1446 and Lisp-buffer write streams expect to never get partial
|
|
1447 characters. */
|
|
1448
|
|
1449 #define LISP_BUFFER_STREAM_DATA(stream) \
|
|
1450 LSTREAM_TYPE_DATA (stream, lisp_buffer)
|
|
1451
|
|
1452 struct lisp_buffer_stream
|
|
1453 {
|
|
1454 Lisp_Object buffer;
|
|
1455 Lisp_Object orig_start;
|
|
1456 /* we use markers to properly deal with insertion/deletion */
|
|
1457 Lisp_Object start, end;
|
|
1458 int flags;
|
|
1459 };
|
|
1460
|
|
1461 DEFINE_LSTREAM_IMPLEMENTATION ("lisp-buffer", lstream_lisp_buffer,
|
|
1462 sizeof (struct lisp_buffer_stream));
|
|
1463
|
|
1464 static Lisp_Object
|
|
1465 make_lisp_buffer_stream_1 (struct buffer *buf, Bufpos start, Bufpos end,
|
|
1466 int flags, CONST char *mode)
|
|
1467 {
|
|
1468 Lisp_Object obj = Qnil;
|
|
1469 Lstream *lstr;
|
|
1470 struct lisp_buffer_stream *str;
|
|
1471 Bufpos bmin, bmax;
|
|
1472 int reading = !strcmp (mode, "r");
|
|
1473
|
|
1474 /* Make sure the luser didn't pass "w" in. */
|
|
1475 if (!strcmp (mode, "w"))
|
|
1476 abort ();
|
185
|
1477
|
0
|
1478 if (flags & LSTR_IGNORE_ACCESSIBLE)
|
|
1479 {
|
|
1480 bmin = BUF_BEG (buf);
|
|
1481 bmax = BUF_Z (buf);
|
|
1482 }
|
|
1483 else
|
|
1484 {
|
|
1485 bmin = BUF_BEGV (buf);
|
|
1486 bmax = BUF_ZV (buf);
|
|
1487 }
|
|
1488
|
|
1489 if (start == -1)
|
|
1490 start = bmin;
|
|
1491 if (end == -1)
|
|
1492 end = bmax;
|
|
1493 assert (bmin <= start);
|
|
1494 assert (start <= bmax);
|
|
1495 if (reading)
|
|
1496 {
|
|
1497 assert (bmin <= end);
|
|
1498 assert (end <= bmax);
|
|
1499 assert (start <= end);
|
|
1500 }
|
|
1501
|
|
1502 lstr = Lstream_new (lstream_lisp_buffer, mode);
|
|
1503 str = LISP_BUFFER_STREAM_DATA (lstr);
|
|
1504 {
|
|
1505 Lisp_Object marker;
|
|
1506 Lisp_Object buffer = Qnil;
|
|
1507
|
|
1508 XSETBUFFER (buffer, buf);
|
|
1509 marker = Fmake_marker ();
|
|
1510 Fset_marker (marker, make_int (start), buffer);
|
|
1511 str->start = marker;
|
|
1512 marker = Fmake_marker ();
|
|
1513 Fset_marker (marker, make_int (start), buffer);
|
|
1514 str->orig_start = marker;
|
|
1515 if (reading)
|
|
1516 {
|
|
1517 marker = Fmake_marker ();
|
|
1518 Fset_marker (marker, make_int (end), buffer);
|
|
1519 str->end = marker;
|
|
1520 }
|
|
1521 else
|
|
1522 str->end = Qnil;
|
|
1523 str->buffer = buffer;
|
|
1524 }
|
|
1525 str->flags = flags;
|
|
1526 XSETLSTREAM (obj, lstr);
|
|
1527 return obj;
|
|
1528 }
|
|
1529
|
|
1530 Lisp_Object
|
|
1531 make_lisp_buffer_input_stream (struct buffer *buf, Bufpos start, Bufpos end,
|
|
1532 int flags)
|
|
1533 {
|
|
1534 return make_lisp_buffer_stream_1 (buf, start, end, flags, "r");
|
|
1535 }
|
|
1536
|
|
1537 Lisp_Object
|
|
1538 make_lisp_buffer_output_stream (struct buffer *buf, Bufpos pos, int flags)
|
|
1539 {
|
2
|
1540 Lisp_Object lstr = make_lisp_buffer_stream_1 (buf, pos, 0, flags, "wc");
|
0
|
1541
|
|
1542 Lstream_set_character_mode (XLSTREAM (lstr));
|
|
1543 return lstr;
|
|
1544 }
|
|
1545
|
|
1546 static int
|
|
1547 lisp_buffer_reader (Lstream *stream, unsigned char *data, int size)
|
|
1548 {
|
|
1549 struct lisp_buffer_stream *str = LISP_BUFFER_STREAM_DATA (stream);
|
|
1550 unsigned char *orig_data = data;
|
|
1551 Bytind start;
|
|
1552 Bytind end;
|
|
1553 struct buffer *buf = XBUFFER (str->buffer);
|
|
1554
|
|
1555 if (!BUFFER_LIVE_P (buf))
|
|
1556 return 0; /* Fut. */
|
|
1557
|
|
1558 /* NOTE: We do all our operations in Bytind's.
|
|
1559 Keep in mind that SIZE is a value in bytes, not chars. */
|
|
1560
|
|
1561 start = bi_marker_position (str->start);
|
|
1562 end = bi_marker_position (str->end);
|
|
1563 if (!(str->flags & LSTR_IGNORE_ACCESSIBLE))
|
|
1564 {
|
|
1565 start = bytind_clip_to_bounds (BI_BUF_BEGV (buf), start,
|
|
1566 BI_BUF_ZV (buf));
|
|
1567 end = bytind_clip_to_bounds (BI_BUF_BEGV (buf), end,
|
|
1568 BI_BUF_ZV (buf));
|
|
1569 }
|
185
|
1570
|
0
|
1571 size = min (size, end - start);
|
|
1572 end = start + size;
|
|
1573 /* We cannot return a partial character. */
|
|
1574 VALIDATE_BYTIND_BACKWARD (buf, end);
|
|
1575
|
|
1576 while (start < end)
|
|
1577 {
|
|
1578 Bytind ceil;
|
|
1579 Bytecount chunk;
|
|
1580
|
|
1581 if (str->flags & LSTR_IGNORE_ACCESSIBLE)
|
|
1582 ceil = BI_BUF_CEILING_OF_IGNORE_ACCESSIBLE (buf, start);
|
|
1583 else
|
|
1584 ceil = BI_BUF_CEILING_OF (buf, start);
|
|
1585 chunk = min (ceil, end) - start;
|
|
1586 memcpy (data, BI_BUF_BYTE_ADDRESS (buf, start), chunk);
|
|
1587 data += chunk;
|
|
1588 start += chunk;
|
|
1589 }
|
|
1590
|
|
1591 if (EQ (buf->selective_display, Qt) && str->flags & LSTR_SELECTIVE)
|
|
1592 {
|
|
1593 /* What a kludge. What a kludge. What a kludge. */
|
|
1594 unsigned char *p;
|
|
1595 for (p = orig_data; p < data; p++)
|
|
1596 if (*p == '\r')
|
|
1597 *p = '\n';
|
|
1598 }
|
|
1599
|
|
1600 set_bi_marker_position (str->start, end);
|
|
1601 return data - orig_data;
|
|
1602 }
|
|
1603
|
|
1604 static int
|
|
1605 lisp_buffer_writer (Lstream *stream, CONST unsigned char *data, int size)
|
|
1606 {
|
|
1607 struct lisp_buffer_stream *str = LISP_BUFFER_STREAM_DATA (stream);
|
|
1608 Bufpos pos;
|
|
1609 struct buffer *buf = XBUFFER (str->buffer);
|
|
1610
|
|
1611 if (!BUFFER_LIVE_P (buf))
|
|
1612 return 0; /* Fut. */
|
|
1613
|
|
1614 pos = marker_position (str->start);
|
|
1615 pos += buffer_insert_raw_string_1 (buf, pos, data, size, 0);
|
|
1616 set_marker_position (str->start, pos);
|
|
1617 return size;
|
|
1618 }
|
|
1619
|
|
1620 static int
|
|
1621 lisp_buffer_rewinder (Lstream *stream)
|
|
1622 {
|
|
1623 struct lisp_buffer_stream *str =
|
|
1624 LISP_BUFFER_STREAM_DATA (stream);
|
|
1625 struct buffer *buf = XBUFFER (str->buffer);
|
|
1626 long pos = marker_position (str->orig_start);
|
|
1627 if (!BUFFER_LIVE_P (buf))
|
|
1628 return -1; /* Fut. */
|
|
1629 if (pos > BUF_ZV (buf))
|
|
1630 pos = BUF_ZV (buf);
|
|
1631 if (pos < marker_position (str->orig_start))
|
|
1632 pos = marker_position (str->orig_start);
|
|
1633 if (MARKERP (str->end) && pos > marker_position (str->end))
|
|
1634 pos = marker_position (str->end);
|
|
1635 set_marker_position (str->start, pos);
|
|
1636 return 0;
|
|
1637 }
|
|
1638
|
|
1639 static Lisp_Object
|
|
1640 lisp_buffer_marker (Lisp_Object stream, void (*markobj) (Lisp_Object))
|
|
1641 {
|
|
1642 struct lisp_buffer_stream *str =
|
|
1643 LISP_BUFFER_STREAM_DATA (XLSTREAM (stream));
|
|
1644
|
|
1645 (markobj) (str->start);
|
|
1646 (markobj) (str->end);
|
|
1647 return str->buffer;
|
|
1648 }
|
|
1649
|
|
1650 Bufpos
|
|
1651 lisp_buffer_stream_startpos (Lstream *stream)
|
|
1652 {
|
|
1653 return marker_position (LISP_BUFFER_STREAM_DATA (stream)->start);
|
|
1654 }
|
|
1655
|
|
1656
|
|
1657 /************************************************************************/
|
|
1658 /* initialization */
|
|
1659 /************************************************************************/
|
|
1660
|
|
1661 void
|
|
1662 lstream_type_create (void)
|
|
1663 {
|
|
1664 LSTREAM_HAS_METHOD (stdio, reader);
|
|
1665 LSTREAM_HAS_METHOD (stdio, writer);
|
|
1666 LSTREAM_HAS_METHOD (stdio, rewinder);
|
|
1667 LSTREAM_HAS_METHOD (stdio, seekable_p);
|
|
1668 LSTREAM_HAS_METHOD (stdio, flusher);
|
|
1669 LSTREAM_HAS_METHOD (stdio, closer);
|
|
1670
|
|
1671 LSTREAM_HAS_METHOD (filedesc, reader);
|
|
1672 LSTREAM_HAS_METHOD (filedesc, writer);
|
|
1673 LSTREAM_HAS_METHOD (filedesc, rewinder);
|
|
1674 LSTREAM_HAS_METHOD (filedesc, seekable_p);
|
|
1675 LSTREAM_HAS_METHOD (filedesc, closer);
|
|
1676
|
|
1677 LSTREAM_HAS_METHOD (lisp_string, reader);
|
|
1678 LSTREAM_HAS_METHOD (lisp_string, rewinder);
|
|
1679 LSTREAM_HAS_METHOD (lisp_string, marker);
|
|
1680
|
|
1681 LSTREAM_HAS_METHOD (fixed_buffer, reader);
|
|
1682 LSTREAM_HAS_METHOD (fixed_buffer, writer);
|
|
1683 LSTREAM_HAS_METHOD (fixed_buffer, rewinder);
|
|
1684
|
|
1685 LSTREAM_HAS_METHOD (resizing_buffer, writer);
|
|
1686 LSTREAM_HAS_METHOD (resizing_buffer, rewinder);
|
|
1687 LSTREAM_HAS_METHOD (resizing_buffer, closer);
|
|
1688
|
|
1689 LSTREAM_HAS_METHOD (dynarr, writer);
|
|
1690 LSTREAM_HAS_METHOD (dynarr, rewinder);
|
|
1691 LSTREAM_HAS_METHOD (dynarr, closer);
|
|
1692
|
|
1693 LSTREAM_HAS_METHOD (lisp_buffer, reader);
|
|
1694 LSTREAM_HAS_METHOD (lisp_buffer, writer);
|
|
1695 LSTREAM_HAS_METHOD (lisp_buffer, rewinder);
|
|
1696 LSTREAM_HAS_METHOD (lisp_buffer, marker);
|
|
1697 }
|
|
1698
|
|
1699 void
|
|
1700 vars_of_lstream (void)
|
|
1701 {
|
|
1702 int i;
|
|
1703
|
|
1704 for (i = 0; i < countof (Vlstream_free_list); i++)
|
|
1705 {
|
|
1706 Vlstream_free_list[i] = Qnil;
|
|
1707 staticpro (&Vlstream_free_list[i]);
|
|
1708 }
|
|
1709 }
|