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