* ports.c: Doc patches from Richard Kim. Pasted from MIT Scheme.
[bpt/guile.git] / libguile / ports.c
1 /* Copyright (C) 1995,1996,1997,1998,1999 Free Software Foundation, Inc.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2, or (at your option)
6 * any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; see the file COPYING. If not, write to
15 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
16 * Boston, MA 02111-1307 USA
17 *
18 * As a special exception, the Free Software Foundation gives permission
19 * for additional uses of the text contained in its release of GUILE.
20 *
21 * The exception is that, if you link the GUILE library with other files
22 * to produce an executable, this does not by itself cause the
23 * resulting executable to be covered by the GNU General Public License.
24 * Your use of that executable is in no way restricted on account of
25 * linking the GUILE library code into it.
26 *
27 * This exception does not however invalidate any other reasons why
28 * the executable file might be covered by the GNU General Public License.
29 *
30 * This exception applies only to the code released by the
31 * Free Software Foundation under the name GUILE. If you copy
32 * code from other Free Software Foundation releases into a copy of
33 * GUILE, as the General Public License permits, the exception does
34 * not apply to the code that you add in this way. To avoid misleading
35 * anyone as to the status of such modified files, you must delete
36 * this exception notice from them.
37 *
38 * If you write modifications of your own for GUILE, it is your choice
39 * whether to permit this exception to apply to your modifications.
40 * If you do not wish that, delete this exception notice. */
41
42 /* Software engineering face-lift by Greg J. Badros, 11-Dec-1999,
43 gjb@cs.washington.edu, http://www.cs.washington.edu/homes/gjb */
44
45 \f
46 /* Headers. */
47
48 #include <stdio.h>
49 #include "_scm.h"
50 #include "objects.h"
51 #include "smob.h"
52 #include "chars.h"
53
54 #include "keywords.h"
55
56 #include "scm_validate.h"
57 #include "ports.h"
58
59 #ifdef HAVE_STRING_H
60 #include <string.h>
61 #endif
62
63 #ifdef HAVE_MALLOC_H
64 #include <malloc.h>
65 #endif
66
67 #ifdef HAVE_UNISTD_H
68 #include <unistd.h>
69 #endif
70
71 #ifdef HAVE_SYS_IOCTL_H
72 #include <sys/ioctl.h>
73 #endif
74
75 \f
76 /* The port kind table --- a dynamically resized array of port types. */
77
78
79 /* scm_ptobs scm_numptob
80 * implement a dynamicly resized array of ptob records.
81 * Indexes into this table are used when generating type
82 * tags for smobjects (if you know a tag you can get an index and conversely).
83 */
84 scm_ptob_descriptor *scm_ptobs;
85 int scm_numptob;
86
87 /* GC marker for a port with stream of SCM type. */
88 SCM
89 scm_markstream (SCM ptr)
90 {
91 int openp;
92 openp = SCM_CAR (ptr) & SCM_OPN;
93 if (openp)
94 return SCM_STREAM (ptr);
95 else
96 return SCM_BOOL_F;
97 }
98
99 /*
100 * We choose to use an interface similar to the smob interface with
101 * fill_input and write as standard fields, passed to the port
102 * type constructor, and optional fields set by setters.
103 */
104
105 static void flush_void_port (SCM port);
106 static void end_input_void_port (SCM port, int offset);
107 static void write_void_port (SCM port, const void *data, size_t size);
108
109 long
110 scm_make_port_type (char *name,
111 int (*fill_input) (SCM port),
112 void (*write) (SCM port, const void *data, size_t size))
113 {
114 char *tmp;
115 if (255 <= scm_numptob)
116 goto ptoberr;
117 SCM_DEFER_INTS;
118 SCM_SYSCALL (tmp = (char *) realloc ((char *) scm_ptobs,
119 (1 + scm_numptob)
120 * sizeof (scm_ptob_descriptor)));
121 if (tmp)
122 {
123 scm_ptobs = (scm_ptob_descriptor *) tmp;
124
125 scm_ptobs[scm_numptob].name = name;
126 scm_ptobs[scm_numptob].mark = 0;
127 scm_ptobs[scm_numptob].free = scm_free0;
128 scm_ptobs[scm_numptob].print = scm_port_print;
129 scm_ptobs[scm_numptob].equalp = 0;
130 scm_ptobs[scm_numptob].close = 0;
131
132 scm_ptobs[scm_numptob].write = write;
133 scm_ptobs[scm_numptob].flush = flush_void_port;
134
135 scm_ptobs[scm_numptob].end_input = end_input_void_port;
136 scm_ptobs[scm_numptob].fill_input = fill_input;
137 scm_ptobs[scm_numptob].input_waiting = 0;
138
139 scm_ptobs[scm_numptob].seek = 0;
140 scm_ptobs[scm_numptob].truncate = 0;
141
142 scm_numptob++;
143 }
144 SCM_ALLOW_INTS;
145 if (!tmp)
146 ptoberr:scm_wta (SCM_MAKINUM ((long) scm_numptob),
147 (char *) SCM_NALLOC, "scm_make_port_type");
148 /* Make a class object if Goops is present */
149 if (scm_port_class)
150 scm_make_port_classes (scm_numptob - 1, SCM_PTOBNAME (scm_numptob - 1));
151 return scm_tc7_port + (scm_numptob - 1) * 256;
152 }
153
154 void
155 scm_set_port_mark (long tc, SCM (*mark) (SCM))
156 {
157 scm_ptobs[SCM_TC2PTOBNUM (tc)].mark = mark;
158 }
159
160 void
161 scm_set_port_free (long tc, scm_sizet (*free) (SCM))
162 {
163 scm_ptobs[SCM_TC2PTOBNUM (tc)].free = free;
164 }
165
166 void
167 scm_set_port_print (long tc, int (*print) (SCM exp, SCM port,
168 scm_print_state *pstate))
169 {
170 scm_ptobs[SCM_TC2PTOBNUM (tc)].print = print;
171 }
172
173 void
174 scm_set_port_equalp (long tc, SCM (*equalp) (SCM, SCM))
175 {
176 scm_ptobs[SCM_TC2PTOBNUM (tc)].equalp = equalp;
177 }
178
179 void
180 scm_set_port_flush (long tc, void (*flush) (SCM port))
181 {
182 scm_ptobs[SCM_TC2PTOBNUM (tc)].flush = flush;
183 }
184
185 void
186 scm_set_port_end_input (long tc, void (*end_input) (SCM port, int offset))
187 {
188 scm_ptobs[SCM_TC2PTOBNUM (tc)].end_input = end_input;
189 }
190
191 void
192 scm_set_port_close (long tc, int (*close) (SCM))
193 {
194 scm_ptobs[SCM_TC2PTOBNUM (tc)].close = close;
195 }
196
197 void
198 scm_set_port_seek (long tc, off_t (*seek) (SCM port,
199 off_t OFFSET,
200 int WHENCE))
201 {
202 scm_ptobs[SCM_TC2PTOBNUM (tc)].seek = seek;
203 }
204
205 void
206 scm_set_port_truncate (long tc, void (*truncate) (SCM port, off_t length))
207 {
208 scm_ptobs[SCM_TC2PTOBNUM (tc)].truncate = truncate;
209 }
210
211 void
212 scm_set_port_input_waiting (long tc, int (*input_waiting) (SCM))
213 {
214 scm_ptobs[SCM_TC2PTOBNUM (tc)].input_waiting = input_waiting;
215 }
216
217 \f
218
219 SCM_DEFINE (scm_char_ready_p, "char-ready?", 0, 1, 0,
220 (SCM port),
221 "Returns @code{#t} if a character is ready on input @var{port} and\n"
222 "returns @code{#f} otherwise. If @code{char-ready?} returns @code{#t}\n"
223 "then the next @code{read-char} operation on @var{port} is\n"
224 "guaranteed not to hang. If @var{port} is a file port at end of\n"
225 "file then @code{char-ready?} returns @code{#t}.\n"
226 "@footnote{@code{char-ready?} exists to make it possible for a\n"
227 "program to accept characters from interactive ports without getting\n"
228 "stuck waiting for input. Any input editors associated with such ports\n"
229 "must make sure that characters whose existence has been asserted by\n"
230 "@code{char-ready?} cannot be rubbed out. If @code{char-ready?} were to\n"
231 "return @code{#f} at end of file, a port at end of file would be\n"
232 "indistinguishable from an interactive port that has no ready\n"
233 "characters.}")
234 #define FUNC_NAME s_scm_char_ready_p
235 {
236 scm_port *pt;
237
238 if (SCM_UNBNDP (port))
239 port = scm_cur_inp;
240 else
241 SCM_VALIDATE_OPINPORT (1,port);
242
243 pt = SCM_PTAB_ENTRY (port);
244
245 /* if the current read buffer is filled, or the
246 last pushed-back char has been read and the saved buffer is
247 filled, result is true. */
248 if (pt->read_pos < pt->read_end
249 || (pt->read_buf == pt->putback_buf
250 && pt->saved_read_pos < pt->saved_read_end))
251 return SCM_BOOL_T;
252 else
253 {
254 scm_ptob_descriptor *ptob = &scm_ptobs[SCM_PTOBNUM (port)];
255
256 if (ptob->input_waiting)
257 return SCM_BOOL(ptob->input_waiting (port));
258 else
259 return SCM_BOOL_T;
260 }
261 }
262 #undef FUNC_NAME
263
264 /* Clear a port's read buffers, returning the contents. */
265 SCM_DEFINE (scm_drain_input, "drain-input", 1, 0, 0,
266 (SCM port),
267 "Drains @var{PORT}'s read buffers (including any pushed-back characters)\n"
268 "and returns the contents as a single string.")
269 #define FUNC_NAME s_scm_drain_input
270 {
271 SCM result;
272 scm_port *pt = SCM_PTAB_ENTRY (port);
273 int count;
274 char *dst;
275
276 SCM_VALIDATE_OPINPORT (1,port);
277
278 count = pt->read_end - pt->read_pos;
279 if (pt->read_buf == pt->putback_buf)
280 count += pt->saved_read_end - pt->saved_read_pos;
281
282 result = scm_makstr (count, 0);
283 dst = SCM_CHARS (result);
284
285 while (pt->read_pos < pt->read_end)
286 *dst++ = *(pt->read_pos++);
287
288 if (pt->read_buf == pt->putback_buf)
289 {
290 while (pt->saved_read_pos < pt->saved_read_end)
291 *dst++ = *(pt->saved_read_pos++);
292 }
293
294 return result;
295 }
296 #undef FUNC_NAME
297
298 \f
299 /* Standard ports --- current input, output, error, and more(!). */
300
301 SCM_DEFINE (scm_current_input_port, "current-input-port", 0, 0, 0,
302 (),
303 "Returns the current input port. This is the default port used by many\n"
304 "input procedures. Initially, @code{current-input-port} returns the\n"
305 "value of @code{???}.")
306 #define FUNC_NAME s_scm_current_input_port
307 {
308 return scm_cur_inp;
309 }
310 #undef FUNC_NAME
311
312 SCM_DEFINE (scm_current_output_port, "current-output-port", 0, 0, 0,
313 (),
314 "Returns the current output port. This is the default port used by many\n"
315 "output procedures. Initially, @code{current-output-port} returns the\n"
316 "value of @code{???}.")
317 #define FUNC_NAME s_scm_current_output_port
318 {
319 return scm_cur_outp;
320 }
321 #undef FUNC_NAME
322
323 SCM_DEFINE (scm_current_error_port, "current-error-port", 0, 0, 0,
324 (),
325 "Return the port to which errors and warnings should be sent (the\n"
326 "@dfn{standard error} in Unix and C terminology).")
327 #define FUNC_NAME s_scm_current_error_port
328 {
329 return scm_cur_errp;
330 }
331 #undef FUNC_NAME
332
333 SCM_DEFINE (scm_current_load_port, "current-load-port", 0, 0, 0,
334 (),
335 "")
336 #define FUNC_NAME s_scm_current_load_port
337 {
338 return scm_cur_loadp;
339 }
340 #undef FUNC_NAME
341
342 SCM_DEFINE (scm_set_current_input_port, "set-current-input-port", 1, 0, 0,
343 (SCM port),
344 "@deffnx primitive set-current-output-port port\n"
345 "@deffnx primitive set-current-error-port port\n"
346 "Change the ports returned by @code{current-input-port},\n"
347 "@code{current-output-port} and @code{current-error-port}, respectively,\n"
348 "so that they use the supplied @var{port} for input or output.")
349 #define FUNC_NAME s_scm_set_current_input_port
350 {
351 SCM oinp = scm_cur_inp;
352 SCM_VALIDATE_OPINPORT (1,port);
353 scm_cur_inp = port;
354 return oinp;
355 }
356 #undef FUNC_NAME
357
358
359 SCM_DEFINE (scm_set_current_output_port, "set-current-output-port", 1, 0, 0,
360 (SCM port),
361 "")
362 #define FUNC_NAME s_scm_set_current_output_port
363 {
364 SCM ooutp = scm_cur_outp;
365 port = SCM_COERCE_OUTPORT (port);
366 SCM_VALIDATE_OPOUTPORT (1,port);
367 scm_cur_outp = port;
368 return ooutp;
369 }
370 #undef FUNC_NAME
371
372
373 SCM_DEFINE (scm_set_current_error_port, "set-current-error-port", 1, 0, 0,
374 (SCM port),
375 "")
376 #define FUNC_NAME s_scm_set_current_error_port
377 {
378 SCM oerrp = scm_cur_errp;
379 port = SCM_COERCE_OUTPORT (port);
380 SCM_VALIDATE_OPOUTPORT (1,port);
381 scm_cur_errp = port;
382 return oerrp;
383 }
384 #undef FUNC_NAME
385
386 \f
387 /* The port table --- an array of pointers to ports. */
388
389 scm_port **scm_port_table;
390
391 int scm_port_table_size = 0; /* Number of ports in scm_port_table. */
392 int scm_port_table_room = 20; /* Size of the array. */
393
394 /* Add a port to the table. */
395
396 scm_port *
397 scm_add_to_port_table (SCM port)
398 {
399 scm_port *entry;
400
401 if (scm_port_table_size == scm_port_table_room)
402 {
403 void *newt = realloc ((char *) scm_port_table,
404 (scm_sizet) (sizeof (scm_port *)
405 * scm_port_table_room * 2));
406 if (newt == NULL)
407 scm_memory_error ("scm_add_to_port_table");
408 scm_port_table = (scm_port **) newt;
409 scm_port_table_room *= 2;
410 }
411 entry = (scm_port *) malloc (sizeof (scm_port));
412 if (entry == NULL)
413 scm_memory_error ("scm_add_to_port_table");
414
415 entry->port = port;
416 entry->entry = scm_port_table_size;
417 entry->revealed = 0;
418 entry->stream = 0;
419 entry->file_name = SCM_BOOL_F;
420 entry->line_number = 0;
421 entry->column_number = 0;
422 entry->putback_buf = 0;
423 entry->putback_buf_size = 0;
424 entry->rw_active = SCM_PORT_NEITHER;
425 entry->rw_random = 0;
426
427 scm_port_table[scm_port_table_size] = entry;
428 scm_port_table_size++;
429
430 return entry;
431 }
432
433 /* Remove a port from the table and destroy it. */
434
435 void
436 scm_remove_from_port_table (SCM port)
437 {
438 scm_port *p = SCM_PTAB_ENTRY (port);
439 int i = p->entry;
440
441 if (i >= scm_port_table_size)
442 scm_wta (port, "Port not in table", "scm_remove_from_port_table");
443 if (p->putback_buf)
444 free (p->putback_buf);
445 free (p);
446 /* Since we have just freed slot i we can shrink the table by moving
447 the last entry to that slot... */
448 if (i < scm_port_table_size - 1)
449 {
450 scm_port_table[i] = scm_port_table[scm_port_table_size - 1];
451 scm_port_table[i]->entry = i;
452 }
453 SCM_SETPTAB_ENTRY (port, 0);
454 scm_port_table_size--;
455 }
456
457 #ifdef GUILE_DEBUG
458 /* Undocumented functions for debugging. */
459 /* Return the number of ports in the table. */
460
461 SCM_DEFINE (scm_pt_size, "pt-size", 0, 0, 0,
462 (),
463 "")
464 #define FUNC_NAME s_scm_pt_size
465 {
466 return SCM_MAKINUM (scm_port_table_size);
467 }
468 #undef FUNC_NAME
469
470 /* Return the ith member of the port table. */
471 SCM_DEFINE (scm_pt_member, "pt-member", 1, 0, 0,
472 (SCM member),
473 "")
474 #define FUNC_NAME s_scm_pt_member
475 {
476 int i;
477 SCM_VALIDATE_INUM_COPY (1,member,i);
478 if (i < 0 || i >= scm_port_table_size)
479 return SCM_BOOL_F;
480 else
481 return scm_port_table[i]->port;
482 }
483 #undef FUNC_NAME
484 #endif
485
486
487 \f
488 /* Revealed counts --- an oddity inherited from SCSH. */
489
490 /* Find a port in the table and return its revealed count.
491 Also used by the garbage collector.
492 */
493
494 int
495 scm_revealed_count (SCM port)
496 {
497 return SCM_REVEALED(port);
498 }
499
500
501
502 /* Return the revealed count for a port. */
503
504 SCM_DEFINE (scm_port_revealed, "port-revealed", 1, 0, 0,
505 (SCM port),
506 "Returns the revealed count for @var{port}.")
507 #define FUNC_NAME s_scm_port_revealed
508 {
509 port = SCM_COERCE_OUTPORT (port);
510 SCM_VALIDATE_PORT (1,port);
511 return SCM_MAKINUM (scm_revealed_count (port));
512 }
513 #undef FUNC_NAME
514
515 /* Set the revealed count for a port. */
516 SCM_DEFINE (scm_set_port_revealed_x, "set-port-revealed!", 2, 0, 0,
517 (SCM port, SCM rcount),
518 "Sets the revealed count for a port to a given value. \n"
519 "The return value is unspecified.")
520 #define FUNC_NAME s_scm_set_port_revealed_x
521 {
522 port = SCM_COERCE_OUTPORT (port);
523 SCM_VALIDATE_PORT (1,port);
524 SCM_VALIDATE_INUM (2,rcount);
525 SCM_REVEALED (port) = SCM_INUM (rcount);
526 return SCM_UNSPECIFIED;
527 }
528 #undef FUNC_NAME
529
530
531 \f
532 /* Retrieving a port's mode. */
533
534 /* Return the flags that characterize a port based on the mode
535 * string used to open a file for that port.
536 *
537 * See PORT FLAGS in scm.h
538 */
539
540 long
541 scm_mode_bits (char *modes)
542 {
543 return (SCM_OPN
544 | (strchr (modes, 'r') || strchr (modes, '+') ? SCM_RDNG : 0)
545 | ( strchr (modes, 'w')
546 || strchr (modes, 'a')
547 || strchr (modes, '+') ? SCM_WRTNG : 0)
548 | (strchr (modes, '0') ? SCM_BUF0 : 0)
549 | (strchr (modes, 'l') ? SCM_BUFLINE : 0));
550 }
551
552
553 /* Return the mode flags from an open port.
554 * Some modes such as "append" are only used when opening
555 * a file and are not returned here. */
556
557 SCM_DEFINE (scm_port_mode, "port-mode", 1, 0, 0,
558 (SCM port),
559 "Returns the port modes associated with the open port @var{port}. These\n"
560 "will not necessarily be identical to the modes used when the port was\n"
561 "opened, since modes such as \"append\" which are used only during\n"
562 "port creation are not retained.")
563 #define FUNC_NAME s_scm_port_mode
564 {
565 char modes[3];
566 modes[0] = '\0';
567
568 port = SCM_COERCE_OUTPORT (port);
569 SCM_VALIDATE_OPPORT (1,port);
570 if (SCM_CAR (port) & SCM_RDNG) {
571 if (SCM_CAR (port) & SCM_WRTNG)
572 strcpy (modes, "r+");
573 else
574 strcpy (modes, "r");
575 }
576 else if (SCM_CAR (port) & SCM_WRTNG)
577 strcpy (modes, "w");
578 if (SCM_CAR (port) & SCM_BUF0)
579 strcat (modes, "0");
580 return scm_makfromstr (modes, strlen (modes), 0);
581 }
582 #undef FUNC_NAME
583
584
585 \f
586 /* Closing ports. */
587
588 /* scm_close_port
589 * Call the close operation on a port object.
590 * see also scm_close.
591 */
592 SCM_DEFINE (scm_close_port, "close-port", 1, 0, 0,
593 (SCM port),
594 "Close the specified port object. Returns @code{#t} if it successfully\n"
595 "closes a port or @code{#f} if it was already\n"
596 "closed. An exception may be raised if an error occurs, for example\n"
597 "when flushing buffered output.\n"
598 "See also @ref{Ports and File Descriptors, close}, for a procedure\n"
599 "which can close file descriptors.")
600 #define FUNC_NAME s_scm_close_port
601 {
602 scm_sizet i;
603 int rv;
604
605 port = SCM_COERCE_OUTPORT (port);
606
607 SCM_VALIDATE_PORT (1,port);
608 if (SCM_CLOSEDP (port))
609 return SCM_BOOL_F;
610 i = SCM_PTOBNUM (port);
611 if (scm_ptobs[i].close)
612 rv = (scm_ptobs[i].close) (port);
613 else
614 rv = 0;
615 scm_remove_from_port_table (port);
616 SCM_SETAND_CAR (port, ~SCM_OPN);
617 return SCM_NEGATE_BOOL(rv < 0);
618 }
619 #undef FUNC_NAME
620
621 SCM_DEFINE (scm_close_all_ports_except, "close-all-ports-except", 0, 0, 1,
622 (SCM ports),
623 "Close all open file ports used by the interpreter\n"
624 "except for those supplied as arguments. This procedure\n"
625 "is intended to be used before an exec call to close file descriptors\n"
626 "which are not needed in the new process.Close all open file ports used by the interpreter\n"
627 "except for those supplied as arguments. This procedure\n"
628 "is intended to be used before an exec call to close file descriptors\n"
629 "which are not needed in the new process.")
630 #define FUNC_NAME s_scm_close_all_ports_except
631 {
632 int i = 0;
633 SCM_VALIDATE_CONS (1,ports);
634 while (i < scm_port_table_size)
635 {
636 SCM thisport = scm_port_table[i]->port;
637 int found = 0;
638 SCM ports_ptr = ports;
639
640 while (SCM_NNULLP (ports_ptr))
641 {
642 SCM port = SCM_COERCE_OUTPORT (SCM_CAR (ports_ptr));
643 if (i == 0)
644 SCM_VALIDATE_OPPORT (SCM_ARG1,port);
645 if (port == thisport)
646 found = 1;
647 ports_ptr = SCM_CDR (ports_ptr);
648 }
649 if (found)
650 i++;
651 else
652 /* i is not to be incremented here. */
653 scm_close_port (thisport);
654 }
655 return SCM_UNSPECIFIED;
656 }
657 #undef FUNC_NAME
658
659
660 \f
661 /* Utter miscellany. Gosh, we should clean this up some time. */
662
663 SCM_DEFINE (scm_input_port_p, "input-port?", 1, 0, 0,
664 (SCM x),
665 "Returns @code{#t} if @var{x} is an input port, otherwise returns\n"
666 "@code{#f}. Any object satisfying this predicate also satisfies\n"
667 "@code{port?}.")
668 #define FUNC_NAME s_scm_input_port_p
669 {
670 if (SCM_IMP (x))
671 return SCM_BOOL_F;
672 return SCM_BOOL(SCM_INPORTP (x));
673 }
674 #undef FUNC_NAME
675
676 SCM_DEFINE (scm_output_port_p, "output-port?", 1, 0, 0,
677 (SCM x),
678 "Returns @code{#t} if @var{x} is an output port, otherwise returns\n"
679 "@code{#f}. Any object satisfying this predicate also satisfies\n"
680 "@code{port?}.")
681 #define FUNC_NAME s_scm_output_port_p
682 {
683 if (SCM_IMP (x))
684 return SCM_BOOL_F;
685 if (SCM_PORT_WITH_PS_P (x))
686 x = SCM_PORT_WITH_PS_PORT (x);
687 return SCM_BOOL(SCM_OUTPORTP (x));
688 }
689 #undef FUNC_NAME
690
691 SCM_DEFINE (scm_port_closed_p, "port-closed?", 1, 0, 0,
692 (SCM port),
693 "Returns @code{#t} if @var{port} is closed or @code{#f} if it is open.")
694 #define FUNC_NAME s_scm_port_closed_p
695 {
696 SCM_VALIDATE_PORT (1,port);
697 return SCM_NEGATE_BOOL(SCM_OPPORTP (port));
698 }
699 #undef FUNC_NAME
700
701 SCM_DEFINE (scm_eof_object_p, "eof-object?", 1, 0, 0,
702 (SCM x),
703 "Returns @code{#t} if @var{x} is an end-of-file object; otherwise\n"
704 "returns @code{#f}.")
705 #define FUNC_NAME s_scm_eof_object_p
706 {
707 return SCM_BOOL(SCM_EOF_OBJECT_P (x));
708 }
709 #undef FUNC_NAME
710
711 SCM_DEFINE (scm_force_output, "force-output", 0, 1, 0,
712 (SCM port),
713 "Flush the specified output port, or the current output port if @var{port}\n"
714 "is omitted. The current output buffer contents are passed to the \n"
715 "underlying port implementation (e.g., in the case of fports, the\n"
716 "data will be written to the file and the output buffer will be cleared.)\n"
717 "It has no effect on an unbuffered port.\n\n"
718 "The return value is unspecified.")
719 #define FUNC_NAME s_scm_force_output
720 {
721 if (SCM_UNBNDP (port))
722 port = scm_cur_outp;
723 else
724 {
725 port = SCM_COERCE_OUTPORT (port);
726 SCM_VALIDATE_OPOUTPORT (1,port);
727 }
728 scm_flush (port);
729 return SCM_UNSPECIFIED;
730 }
731 #undef FUNC_NAME
732
733 SCM_DEFINE (scm_flush_all_ports, "flush-all-ports", 0, 0, 0,
734 (),
735 "Equivalent to calling @code{force-output} on\n"
736 "all open output ports. The return value is unspecified.")
737 #define FUNC_NAME s_scm_flush_all_ports
738 {
739 int i;
740
741 for (i = 0; i < scm_port_table_size; i++)
742 {
743 if (SCM_OPOUTPORTP (scm_port_table[i]->port))
744 scm_flush (scm_port_table[i]->port);
745 }
746 return SCM_UNSPECIFIED;
747 }
748 #undef FUNC_NAME
749
750 SCM_DEFINE (scm_read_char, "read-char", 0, 1, 0,
751 (SCM port),
752 "Returns the next character available from @var{port}, updating\n"
753 "@var{port} to point to the following character. If no more\n"
754 "characters are available, an end-of-file object is returned.")
755 #define FUNC_NAME s_scm_read_char
756 {
757 int c;
758 if (SCM_UNBNDP (port))
759 port = scm_cur_inp;
760 SCM_VALIDATE_OPINPORT (1,port);
761 c = scm_getc (port);
762 if (EOF == c)
763 return SCM_EOF_VAL;
764 return SCM_MAKICHR (c);
765 }
766 #undef FUNC_NAME
767
768 /* this should only be called when the read buffer is empty. it
769 tries to refill the read buffer. it returns the first char from
770 the port, which is either EOF or *(pt->read_pos). */
771 int
772 scm_fill_input (SCM port)
773 {
774 scm_port *pt = SCM_PTAB_ENTRY (port);
775
776 if (pt->read_buf == pt->putback_buf)
777 {
778 /* finished reading put-back chars. */
779 pt->read_buf = pt->saved_read_buf;
780 pt->read_pos = pt->saved_read_pos;
781 pt->read_end = pt->saved_read_end;
782 pt->read_buf_size = pt->saved_read_buf_size;
783 if (pt->read_pos < pt->read_end)
784 return *(pt->read_pos);
785 }
786 return scm_ptobs[SCM_PTOBNUM (port)].fill_input (port);
787 }
788
789 int
790 scm_getc (SCM port)
791 {
792 int c;
793 scm_port *pt = SCM_PTAB_ENTRY (port);
794
795 if (pt->rw_active == SCM_PORT_WRITE)
796 {
797 /* may be marginally faster than calling scm_flush. */
798 scm_ptobs[SCM_PTOBNUM (port)].flush (port);
799 }
800
801 if (pt->rw_random)
802 pt->rw_active = SCM_PORT_READ;
803
804 if (pt->read_pos >= pt->read_end)
805 {
806 if (scm_fill_input (port) == EOF)
807 return EOF;
808 }
809
810 c = *(pt->read_pos++);
811
812 if (c == '\n')
813 {
814 SCM_INCLINE (port);
815 }
816 else if (c == '\t')
817 {
818 SCM_TABCOL (port);
819 }
820 else
821 {
822 SCM_INCCOL (port);
823 }
824
825 return c;
826 }
827
828 void
829 scm_putc (char c, SCM port)
830 {
831 scm_lfwrite (&c, 1, port);
832 }
833
834 void
835 scm_puts (const char *s, SCM port)
836 {
837 scm_lfwrite (s, strlen (s), port);
838 }
839
840 void
841 scm_lfwrite (const char *ptr, scm_sizet size, SCM port)
842 {
843 scm_port *pt = SCM_PTAB_ENTRY (port);
844 scm_ptob_descriptor *ptob = &scm_ptobs[SCM_PTOBNUM (port)];
845
846 if (pt->rw_active == SCM_PORT_READ)
847 scm_end_input (port);
848
849 ptob->write (port, ptr, size);
850
851 if (pt->rw_random)
852 pt->rw_active = SCM_PORT_WRITE;
853 }
854
855
856 void
857 scm_flush (SCM port)
858 {
859 scm_sizet i = SCM_PTOBNUM (port);
860 (scm_ptobs[i].flush) (port);
861 }
862
863 void
864 scm_end_input (SCM port)
865 {
866 int offset;
867 scm_port *pt = SCM_PTAB_ENTRY (port);
868
869 if (pt->read_buf == pt->putback_buf)
870 {
871 offset = pt->read_end - pt->read_pos;
872 pt->read_buf = pt->saved_read_buf;
873 pt->read_pos = pt->saved_read_pos;
874 pt->read_end = pt->saved_read_end;
875 pt->read_buf_size = pt->saved_read_buf_size;
876 }
877 else
878 offset = 0;
879
880 scm_ptobs[SCM_PTOBNUM (port)].end_input (port, offset);
881 }
882
883 \f
884
885
886 void
887 scm_ungetc (int c, SCM port)
888 {
889 scm_port *pt = SCM_PTAB_ENTRY (port);
890
891 if (pt->read_buf == pt->putback_buf)
892 /* already using the put-back buffer. */
893 {
894 /* enlarge putback_buf if necessary. */
895 if (pt->read_end == pt->read_buf + pt->read_buf_size
896 && pt->read_buf == pt->read_pos)
897 {
898 int new_size = pt->read_buf_size * 2;
899 unsigned char *tmp =
900 (unsigned char *) realloc (pt->putback_buf, new_size);
901
902 if (tmp == NULL)
903 scm_memory_error ("scm_ungetc");
904 pt->read_pos = pt->read_buf = pt->putback_buf = tmp;
905 pt->read_end = pt->read_buf + pt->read_buf_size;
906 pt->read_buf_size = pt->putback_buf_size = new_size;
907 }
908
909 /* shift any existing bytes to buffer + 1. */
910 if (pt->read_pos == pt->read_end)
911 pt->read_end = pt->read_buf + 1;
912 else if (pt->read_pos != pt->read_buf + 1)
913 {
914 int count = pt->read_end - pt->read_pos;
915
916 memmove (pt->read_buf + 1, pt->read_pos, count);
917 pt->read_end = pt->read_buf + 1 + count;
918 }
919
920 pt->read_pos = pt->read_buf;
921 }
922 else
923 /* switch to the put-back buffer. */
924 {
925 if (pt->putback_buf == NULL)
926 {
927 pt->putback_buf = (char *) malloc (SCM_INITIAL_PUTBACK_BUF_SIZE);
928 if (pt->putback_buf == NULL)
929 scm_memory_error ("scm_ungetc");
930 pt->putback_buf_size = SCM_INITIAL_PUTBACK_BUF_SIZE;
931 }
932
933 pt->saved_read_buf = pt->read_buf;
934 pt->saved_read_pos = pt->read_pos;
935 pt->saved_read_end = pt->read_end;
936 pt->saved_read_buf_size = pt->read_buf_size;
937
938 pt->read_pos = pt->read_buf = pt->putback_buf;
939 pt->read_end = pt->read_buf + 1;
940 pt->read_buf_size = pt->putback_buf_size;
941 }
942
943 *pt->read_buf = c;
944
945 if (pt->rw_random)
946 pt->rw_active = SCM_PORT_READ;
947
948 if (c == '\n')
949 {
950 /* What should col be in this case?
951 * We'll leave it at -1.
952 */
953 SCM_LINUM (port) -= 1;
954 }
955 else
956 SCM_COL(port) -= 1;
957 }
958
959
960 void
961 scm_ungets (const char *s, int n, SCM port)
962 {
963 /* This is simple minded and inefficient, but unreading strings is
964 * probably not a common operation, and remember that line and
965 * column numbers have to be handled...
966 *
967 * Please feel free to write an optimized version!
968 */
969 while (n--)
970 scm_ungetc (s[n], port);
971 }
972
973
974 SCM_DEFINE (scm_peek_char, "peek-char", 0, 1, 0,
975 (SCM port),
976 "Returns the next character available from @var{port},\n"
977 "@emph{without} updating @var{port} to point to the following\n"
978 "character. If no more characters are available, an end-of-file object\n"
979 "is returned.@footnote{The value returned by a call to @code{peek-char}\n"
980 "is the same as the value that would have been returned by a call to\n"
981 "@code{read-char} on the same port. The only difference is that the very\n"
982 "next call to @code{read-char} or @code{peek-char} on that\n"
983 "@var{port} will return the value returned by the preceding call to\n"
984 "@code{peek-char}. In particular, a call to @code{peek-char} on an\n"
985 "interactive port will hang waiting for input whenever a call to\n"
986 "@code{read-char} would have hung.}")
987 #define FUNC_NAME s_scm_peek_char
988 {
989 int c;
990 if (SCM_UNBNDP (port))
991 port = scm_cur_inp;
992 else
993 SCM_VALIDATE_OPINPORT (1,port);
994 c = scm_getc (port);
995 if (EOF == c)
996 return SCM_EOF_VAL;
997 scm_ungetc (c, port);
998 return SCM_MAKICHR (c);
999 }
1000 #undef FUNC_NAME
1001
1002 SCM_DEFINE (scm_unread_char, "unread-char", 2, 0, 0,
1003 (SCM cobj, SCM port),
1004 "Place @var{char} in @var{port} so that it will be read by the\n"
1005 "next read operation. If called multiple times, the unread characters\n"
1006 "will be read again in last-in first-out order. If @var{port} is\n"
1007 "not supplied, the current input port is used.")
1008 #define FUNC_NAME s_scm_unread_char
1009 {
1010 int c;
1011
1012 SCM_VALIDATE_ICHR (1,cobj);
1013 if (SCM_UNBNDP (port))
1014 port = scm_cur_inp;
1015 else
1016 SCM_VALIDATE_OPINPORT (2,port);
1017
1018 c = SCM_ICHR (cobj);
1019
1020 scm_ungetc (c, port);
1021 return cobj;
1022 }
1023 #undef FUNC_NAME
1024
1025 SCM_DEFINE (scm_unread_string, "unread-string", 2, 0, 0,
1026 (SCM str, SCM port),
1027 "Place the string @var{str} in @var{port} so that its characters will be\n"
1028 "read in subsequent read operations. If called multiple times, the\n"
1029 "unread characters will be read again in last-in first-out order. If\n"
1030 "@var{port} is not supplied, the current-input-port is used.")
1031 #define FUNC_NAME s_scm_unread_string
1032 {
1033 SCM_VALIDATE_STRING (1,str);
1034 if (SCM_UNBNDP (port))
1035 port = scm_cur_inp;
1036 else
1037 SCM_VALIDATE_OPINPORT (2,port);
1038
1039 scm_ungets (SCM_ROUCHARS (str), SCM_LENGTH (str), port);
1040
1041 return str;
1042 }
1043 #undef FUNC_NAME
1044
1045 SCM_DEFINE (scm_seek, "seek", 3, 0, 0,
1046 (SCM object, SCM offset, SCM whence),
1047 "Sets the current position of @var{fd/port} to the integer @var{offset},\n"
1048 "which is interpreted according to the value of @var{whence}.\n\n"
1049 "One of the following variables should be supplied\n"
1050 "for @var{whence}:\n"
1051 "@defvar SEEK_SET\n"
1052 "Seek from the beginning of the file.\n"
1053 "@end defvar\n"
1054 "@defvar SEEK_CUR\n"
1055 "Seek from the current position.\n"
1056 "@end defvar\n"
1057 "@defvar SEEK_END\n"
1058 "Seek from the end of the file.\n"
1059 "@end defvar\n\n"
1060 "If @var{fd/port} is a file descriptor, the underlying system call is\n"
1061 "@code{lseek}. @var{port} may be a string port.\n\n"
1062 "The value returned is the new position in the file. This means that\n"
1063 "the current position of a port can be obtained using:\n"
1064 "@smalllisp\n"
1065 "(seek port 0 SEEK_CUR)\n"
1066 "@end smalllisp")
1067 #define FUNC_NAME s_scm_seek
1068 {
1069 off_t off;
1070 off_t rv;
1071 int how;
1072
1073 object = SCM_COERCE_OUTPORT (object);
1074
1075 off = SCM_NUM2LONG (2,offset);
1076 SCM_VALIDATE_INUM_COPY (3,whence,how);
1077 if (how != SEEK_SET && how != SEEK_CUR && how != SEEK_END)
1078 SCM_OUT_OF_RANGE (3, whence);
1079 if (SCM_OPPORTP (object))
1080 {
1081 scm_ptob_descriptor *ptob = scm_ptobs + SCM_PTOBNUM (object);
1082
1083 if (!ptob->seek)
1084 SCM_MISC_ERROR ("port is not seekable",
1085 scm_cons (object, SCM_EOL));
1086 else
1087 rv = ptob->seek (object, off, how);
1088 }
1089 else /* file descriptor?. */
1090 {
1091 SCM_VALIDATE_INUM (1,object);
1092 rv = lseek (SCM_INUM (object), off, how);
1093 if (rv == -1)
1094 SCM_SYSERROR;
1095 }
1096 return scm_long2num (rv);
1097 }
1098 #undef FUNC_NAME
1099
1100 SCM_DEFINE (scm_truncate_file, "truncate-file", 1, 1, 0,
1101 (SCM object, SCM length),
1102 "Truncates the object referred to by @var{obj} to at most @var{size} bytes.\n"
1103 "@var{obj} can be a string containing a file name or an integer file\n"
1104 "descriptor or a port. @var{size} may be omitted if @var{obj} is not\n"
1105 "a file name, in which case the truncation occurs at the current port.\n"
1106 "position.\n\n"
1107 "The return value is unspecified.")
1108 #define FUNC_NAME s_scm_truncate_file
1109 {
1110 int rv;
1111 off_t c_length;
1112
1113 /* object can be a port, fdes or filename. */
1114
1115 if (SCM_UNBNDP (length))
1116 {
1117 /* must supply length if object is a filename. */
1118 if (SCM_ROSTRINGP (object))
1119 SCM_MISC_ERROR("must supply length if OBJECT is a filename",SCM_EOL);
1120
1121 length = scm_seek (object, SCM_INUM0, SCM_MAKINUM (SEEK_CUR));
1122 }
1123 c_length = SCM_NUM2LONG (2,length);
1124 if (c_length < 0)
1125 SCM_MISC_ERROR ("negative offset", SCM_EOL);
1126
1127 object = SCM_COERCE_OUTPORT (object);
1128 if (SCM_INUMP (object))
1129 {
1130 SCM_SYSCALL (rv = ftruncate (SCM_INUM (object), c_length));
1131 }
1132 else if (SCM_OPOUTPORTP (object))
1133 {
1134 scm_port *pt = SCM_PTAB_ENTRY (object);
1135 scm_ptob_descriptor *ptob = scm_ptobs + SCM_PTOBNUM (object);
1136
1137 if (!ptob->truncate)
1138 SCM_MISC_ERROR ("port is not truncatable", SCM_EOL);
1139 if (pt->rw_active == SCM_PORT_READ)
1140 scm_end_input (object);
1141 else if (pt->rw_active == SCM_PORT_WRITE)
1142 ptob->flush (object);
1143
1144 ptob->truncate (object, c_length);
1145 rv = 0;
1146 }
1147 else
1148 {
1149 SCM_VALIDATE_ROSTRING (1,object);
1150 SCM_COERCE_SUBSTR (object);
1151 SCM_SYSCALL (rv = truncate (SCM_ROCHARS (object), c_length));
1152 }
1153 if (rv == -1)
1154 SCM_SYSERROR;
1155 return SCM_UNSPECIFIED;
1156 }
1157 #undef FUNC_NAME
1158
1159 SCM_DEFINE (scm_port_line, "port-line", 1, 0, 0,
1160 (SCM port),
1161 "")
1162 #define FUNC_NAME s_scm_port_line
1163 {
1164 port = SCM_COERCE_OUTPORT (port);
1165 SCM_VALIDATE_OPENPORT (1,port);
1166 return SCM_MAKINUM (SCM_LINUM (port));
1167 }
1168 #undef FUNC_NAME
1169
1170 SCM_DEFINE (scm_set_port_line_x, "set-port-line!", 2, 0, 0,
1171 (SCM port, SCM line),
1172 "")
1173 #define FUNC_NAME s_scm_set_port_line_x
1174 {
1175 port = SCM_COERCE_OUTPORT (port);
1176 SCM_VALIDATE_OPENPORT (1,port);
1177 SCM_VALIDATE_INUM (2,line);
1178 return SCM_PTAB_ENTRY (port)->line_number = SCM_INUM (line);
1179 }
1180 #undef FUNC_NAME
1181
1182 SCM_DEFINE (scm_port_column, "port-column", 1, 0, 0,
1183 (SCM port),
1184 "@deffnx primitive port-line [input-port]\n"
1185 "Return the current column number or line number of @var{input-port},\n"
1186 "using the current input port if none is specified. If the number is\n"
1187 "unknown, the result is #f. Otherwise, the result is a 0-origin integer\n"
1188 "- i.e. the first character of the first line is line 0, column 0.\n"
1189 "(However, when you display a file position, for example in an error\n"
1190 "message, we recommand you add 1 to get 1-origin integers. This is\n"
1191 "because lines and column numbers traditionally start with 1, and that is\n"
1192 "what non-programmers will find most natural.)")
1193 #define FUNC_NAME s_scm_port_column
1194 {
1195 port = SCM_COERCE_OUTPORT (port);
1196 SCM_VALIDATE_OPENPORT (1,port);
1197 return SCM_MAKINUM (SCM_COL (port));
1198 }
1199 #undef FUNC_NAME
1200
1201 SCM_DEFINE (scm_set_port_column_x, "set-port-column!", 2, 0, 0,
1202 (SCM port, SCM column),
1203 "@deffnx primitive set-port-line! [input-port] line\n"
1204 "Set the current column or line number of @var{input-port}, using the\n"
1205 "current input port if none is specified.")
1206 #define FUNC_NAME s_scm_set_port_column_x
1207 {
1208 port = SCM_COERCE_OUTPORT (port);
1209 SCM_VALIDATE_OPENPORT (1,port);
1210 SCM_VALIDATE_INUM (2,column);
1211 return SCM_PTAB_ENTRY (port)->column_number = SCM_INUM (column);
1212 }
1213 #undef FUNC_NAME
1214
1215 SCM_DEFINE (scm_port_filename, "port-filename", 1, 0, 0,
1216 (SCM port),
1217 "Return the filename associated with @var{port}. This function returns\n"
1218 "the strings \"standard input\", \"standard output\" and \"standard error\""
1219 "when called on the current input, output and error ports respectively.")
1220 #define FUNC_NAME s_scm_port_filename
1221 {
1222 port = SCM_COERCE_OUTPORT (port);
1223 SCM_VALIDATE_OPENPORT (1,port);
1224 return SCM_PTAB_ENTRY (port)->file_name;
1225 }
1226 #undef FUNC_NAME
1227
1228 SCM_DEFINE (scm_set_port_filename_x, "set-port-filename!", 2, 0, 0,
1229 (SCM port, SCM filename),
1230 "Change the filename associated with @var{port}, using the current input\n"
1231 "port if none is specified. Note that this does not change the port's\n"
1232 "source of data, but only the value that is returned by\n"
1233 "@code{port-filename} and reported in diagnostic output.")
1234 #define FUNC_NAME s_scm_set_port_filename_x
1235 {
1236 port = SCM_COERCE_OUTPORT (port);
1237 SCM_VALIDATE_OPENPORT (1,port);
1238 /* We allow the user to set the filename to whatever he likes. */
1239 return SCM_PTAB_ENTRY (port)->file_name = filename;
1240 }
1241 #undef FUNC_NAME
1242
1243 #ifndef ttyname
1244 extern char * ttyname();
1245 #endif
1246
1247 void
1248 scm_print_port_mode (SCM exp, SCM port)
1249 {
1250 scm_puts (SCM_CLOSEDP (exp)
1251 ? "closed: "
1252 : (SCM_RDNG & SCM_CAR (exp)
1253 ? (SCM_WRTNG & SCM_CAR (exp)
1254 ? "input-output: "
1255 : "input: ")
1256 : (SCM_WRTNG & SCM_CAR (exp)
1257 ? "output: "
1258 : "bogus: ")),
1259 port);
1260 }
1261
1262 int
1263 scm_port_print (SCM exp, SCM port, scm_print_state *pstate)
1264 {
1265 char *type = SCM_PTOBNAME (SCM_PTOBNUM (exp));
1266 if (!type)
1267 type = "port";
1268 scm_puts ("#<", port);
1269 scm_print_port_mode (exp, port);
1270 scm_puts (type, port);
1271 scm_putc (' ', port);
1272 scm_intprint (SCM_CDR (exp), 16, port);
1273 scm_putc ('>', port);
1274 return 1;
1275 }
1276
1277 extern void scm_make_fptob ();
1278 extern void scm_make_stptob ();
1279 extern void scm_make_sfptob ();
1280
1281 void
1282 scm_ports_prehistory ()
1283 {
1284 scm_numptob = 0;
1285 scm_ptobs = (scm_ptob_descriptor *) malloc (sizeof (scm_ptob_descriptor));
1286
1287 /* WARNING: These scm_newptob calls must be done in this order.
1288 * They must agree with the port declarations in tags.h.
1289 */
1290 /* scm_tc16_fport = */ scm_make_fptob ();
1291 /* scm_tc16_pipe was here */ scm_make_fptob (); /* dummy. */
1292 /* scm_tc16_strport = */ scm_make_stptob ();
1293 /* scm_tc16_sfport = */ scm_make_sfptob ();
1294 }
1295
1296 \f
1297
1298 /* Void ports. */
1299
1300 long scm_tc16_void_port = 0;
1301
1302 static void
1303 flush_void_port (SCM port)
1304 {
1305 }
1306
1307 static void
1308 end_input_void_port (SCM port, int offset)
1309 {
1310 }
1311
1312 static void
1313 write_void_port (SCM port, const void *data, size_t size)
1314 {
1315 }
1316
1317 SCM
1318 scm_void_port (char *mode_str)
1319 {
1320 int mode_bits;
1321 SCM answer;
1322 scm_port * pt;
1323
1324 SCM_NEWCELL (answer);
1325 SCM_DEFER_INTS;
1326 mode_bits = scm_mode_bits (mode_str);
1327 pt = scm_add_to_port_table (answer);
1328 SCM_SETPTAB_ENTRY (answer, pt);
1329 SCM_SETSTREAM (answer, 0);
1330 SCM_SETCAR (answer, scm_tc16_void_port | mode_bits);
1331 SCM_ALLOW_INTS;
1332 return answer;
1333 }
1334
1335
1336 SCM_DEFINE (scm_sys_make_void_port, "%make-void-port", 1, 0, 0,
1337 (SCM mode),
1338 "Create and return a new void port. The @var{mode} argument describes\n"
1339 "the input/output modes for this port; for a description, see the\n"
1340 "documentation for @code{open-file} in @ref{File Ports}.")
1341 #define FUNC_NAME s_scm_sys_make_void_port
1342 {
1343 SCM_VALIDATE_ROSTRING (1,mode);
1344 SCM_COERCE_SUBSTR (mode);
1345 return scm_void_port (SCM_ROCHARS (mode));
1346 }
1347 #undef FUNC_NAME
1348
1349 \f
1350 /* Initialization. */
1351
1352 void
1353 scm_init_ports ()
1354 {
1355 /* lseek() symbols. */
1356 scm_sysintern ("SEEK_SET", SCM_MAKINUM (SEEK_SET));
1357 scm_sysintern ("SEEK_CUR", SCM_MAKINUM (SEEK_CUR));
1358 scm_sysintern ("SEEK_END", SCM_MAKINUM (SEEK_END));
1359
1360 scm_tc16_void_port = scm_make_port_type ("void", 0, write_void_port);
1361 #include "ports.x"
1362 }