mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-02 04:40:29 +02:00
newline. A bit faster, and definitely hairier. (scm_read_line): Count newlines here instead. * strings.c (scm_take_str): New function. (scm_take0str): Reimplement in terms of scm_take_str. * strings.h (scm_take_str): New declaration. * ioext.c (scm_read_line): Use scm_take_str, to avoid copying the string. Add some simple-minded support for line buffered ports. * ports.h (SCM_BUFLINE): New flag for ports. * init.c (scm_init_standard_ports): Request line-buffering on the standard output port. * * ports.c (scm_mode_bits): Recognize 'l' as a request for line buffering. (scm_putc, scm_puts, scm_lfwrite): If the port is line-buffered, and there's a newline to be written, flush the port. * ports.c: (scm_lseek): clear buffers even if just reading current position. * fports.c (local_fclose): call local_fflush unconditionally. (various): don't use the scm_must... memory procs. * ports.h (scm_port): make read_pos a pointer to const. strports.c: take care of rw_active and rw_randow. fports.c: scm_fport_drain_input: removed. do it all in ports.c. strports.c (scm_mkstrport): check that pos is reasonable. ioext.c (scm_ftell, scm_fseek): use lseek. (SCM_CLEAR_BUFFERS): macro deleted. ioext.c (redirect_port: use ptob fflush, read_flush. ports.h (scm_ptobfuns): add ftruncate. ports.c (scm_newptob): set ftruncate. adjust ptob tables. * ports.c (scm_ftruncate): new procedure. fports.c (local_ftrunate), strports.c (str_ftruncate): new procs. strports.c (st_seek, st_grow_port): new procs. fports.h (scm_port): change size types from int to off_t. ports.c (scm_init_ports): initialise the seek symbols here instead of in ioext.c. strports.c (scm_call_with_output_string): start with an empty string, so seek and ftruncate can be used. * ports.h (scm_ptobfuns): add a read_flush procedure which is the equivalent to fflush for the read buffer. * ports.c (scm_newptob): set read_flush. ports.c (void_port_ptob): set read_flush. fports.c (local_read_flush): new proc. add to ptob. strport.c (st_read_flush): likewise. vport.c (sf_read_flush): likewise. fports.h (struct scm_fport): remove random member. there's nothing left but fdes. leaving it as a struct to allow for future changes. fports.c: replace usage of scm_fport::random with scm_port::rw_random. ports.c: (scm_putc, scm_puts, scm_lfwrite): call the read_flush ptob proc if the read buffer is filled. * ports.h (scm_port): add a rw_random member and replace reading and writing members with rw_active member. SCM_PORT_READ/SCM_PORT_WRITE: new values. * ports.h (struct scm_port_table): add writing and reading members to replace write_needs_seek: it isn't good enough for non-fports. ports.c, ioext.c, fports.c: corresponding changes. (struct scm_port_table): give it a typedef and rename to scm_port. ports.c, fports.c, strports.c, vports.c, ioext.c, ports.h: corresponding changes. * ports.c (scm_newptob): bugfix: set seek member. * * (scm_lseek): new procedure, using code from ioext.c:scm_fseek and generalised to all port types. * scmsigs.c (scm_init_scmsigs): set the SA_RESTART flag for all signals (it was only being done for handlers installed from Scheme). Otherwise (for example) SIGSTOP followed by SIGCONT on an interpreter waiting for input caused an EINTR error from read. * ports.h (struct scm_port_table): make all the char members unsigned, so they convert to int without becoming negative if large. * fports.c (scm_fdes_wait_for_input): forgot to check compilation with threads enabled. rename this procedure to fport_wait_for_input and take a port instead of a fdes. use scm_fport_input_waiting_p instead of scm_fdes_waiting_p. * readline.c (scm_readline): Applied a patch from Greg Harvey to get readline support working again: use fdopen to get FILE objects. * gc.c (scm_init_storage): install an atexit proc to flush the ports. (cleanup): the new proc. it sets a global variable which can be checked by the ptob flush procs to avoid trying to throw exceptions during exit. not very pleasant but it seems more reliable. * fports.c (local_fflush): check terminating variable and if set don't throw exception. * CHECKME: that the atexit proc is installed if unexec used. * throw.c (scm_handle_by_message): don't flush all ports here. it still causes bus errors. * fports.h (SCM_FPORT_CLEAR_BUFFERS): rename to SCM_CLEAR_BUFFERS and move to ioext.c. * fports.c (scm_fdes_waiting_p): merged into fport_input_waiting_p. * ports.c (scm_char_ready_p): check the port buffer and call the ptob entry if needed. * ports.h (scm_ptobfuns): input_waiting_p added. change all the ptob initialisers. use it in char-ready * ioext.c (scm_do_read_line): moved from ports.c. make it static. * vports.c (sfflush): modified to write a char (since softports currently use shortbuf.) * fports.c (scm_standard_stream_to_port): moved to init.c and made static. * init.c (scm_init_standard_ports): make stdout and stderr unbuffered if connected to a terminal. with stdio they were line-buffered by default. * ports.h (scm_ptobfuns): change fflush return to void. change flush proc definitions. * strports.c (scm_call_with_output_string): get size from buffer instead of port stream. (scm_strprint_obj): likewise. (st_flush): new proc. * ports.h (struct scm_port_table): added write_end member, as an optimisation. set it where write_buf_size is set. * ports.h (struct scm_port_table): change stream from void * back to SCM. SCM presumably must be large enough to hold a pointer (and probably vice versa but who knows.) (SCM_SSTREAM): deleted. change users back to SCM_STREAM. (scm_puts): rewritten * fports.c (local_ffwrite, local_fputs): removed. * strports.c (stputc, stputs, stwrite): dyked out (FIXME) * vports.c (sfputc, sfputs, sfwrite) likewise. * ports.c (write_void_port, puts_void_port): removed. (putc_void_port, getc_void_port, fgets_void_port): likewise. * ports.c (scm_lfwrite): rewritten using fport.c version. * fports.c (local_fputc): deleted. * ports.c (scm_add_to_port_table): initialise write_needs_seek. * ports.h (scm_ptobfuns): add seek function pointer. * fports.c: set it to local_seek, new procedure. * fports.h (SCM_MAYBE_DRAIN_INPUT): moved to ports.c. use ptob for seek. take ptob instead of fport arg. * ports.h (struct scm_port_table): new member write_needs_seek, replaces reading member in fport struct. * vports.c (sfgetc): store the getted char into the buffer. rename to sf_fill_buffer and install it for fill-buffer in ptob. the Scheme interface is still a procedure that gets a char. (scm_make_soft_port): set up the port buffer (shortbuf). * fports.c (local_fgetc, local_fgets): deleted. * strports.c (stgetc): likewise. * ports.c: scm_generic_fgets: likewise. * ports.h (scm_ptobfuns): add fill_buffer. * ports.c (scm_newptob): assign it. * strports.c (scm_mkstrport): set up the buffer. put just the string into the stream, not cons (pos stream). (stfill_buffer): new proc. * ports.h: fport buffer moved into port table: to be used for all port types. * throw.c (scm_handle_by_message): flush ports at exit. * socket.c (scm_sock_fd_to_port): use scm_fdes_to_port. (scm_getsockopt, scm_setsockopt, scm_shutdown, scm_connect, scm_bind, scm_listen, scm_accept, scm_getsockname, scm_getpeername, scm_recv, scm_send, scm_recvfrom, scm_sendto, use SCM_FPORT_FDES. use SCM_OPFPORTP not SCM_FPORTP. * posix.c (scm_getgroups): use SCM_ALLOW/DEFER_INTS. (scm_ttyname): use SCM_FPORT_FDES. (scm_tcgetpgrp, scm_tcsetpgrp): likewise. * ioext.c (scm_isatty_p): use SCM_FPORT_FDES. (scm_fdes_to_ports): modified. (scm_fdopen): use scm_fdes_to_port. * ports.c (scm_init_ports): don't try to flush ports using atexit(). it's too late, errors will cause SEGV. * fports.c (scm_fport_buffer_add): new procedure. * fports.h (SCM_FDES_RANDOM_P): new macro. use it in scm_fdes_to_port and scm_redirect_port. * ioext.c (scm_redirect_port): use setvbuf to set buffers in the new port. reset fp->random. * fports.c (scm_fdes_to_port), ports.c (scm_void_port), filesys.c (scm_opendir): restore defer interrupts while the port is constructed. * (scm_setvbuf): if mode is _IOFBF and size is not supplied, derive buffer size from fdes or use a default. (scm_fdes_to_port): use setvbuf instead of creating the buffers directly. vports.c (various places): use SCM_SSTREAM. strports.c: likewise. * gdbint.c: likewise. * ports.h (SCM_SSTREAM): new macro. * fports.c (scm_input_waiting_p): use scm_return_first, since port may be removed from the stack by the tail call to scm_fdes_waiting_p. * fports.h (SCM_CLEAR_BUFFERS): new macro. * ports.c (scm_force_output): call scm_fflush. * print.c (scm_newline): don't check errno for EPIPE (it wouldn't * reach this point.) don't flush port (if scm_cur_outp). * fports.h (SCM_FPORT_FDES): new macro. * vports.c (sfflush): don't need to set errno. * ports.c: install scm_flush_all_ports to be run on exit. ports.c fports.c ioext.c posix.c socket.c net_db.c filesys.c: removed all uses of SCM_DEFER/ALLOW ints for now. they were mainly just protecting errno. some may need to be put back. * scmsigs.c (take_signal): save and restore errno while this proc runs. *fports.c (print_pipe_port, local_pclose, scm_pipob): deleted. * open-pipe, close-pipe are emulated in (ice-9 popen) ports.c (scm_ports_prehistory): don't init scm_pipob. ports.h (scm_tc16_pipe): deleted. posix.c (scm_open_pipe, scm_close_pipe): deleted. * ioext.c (scm_primitive_move_to_fdes): use fport. * fport.c (scm_fport_fill_buffer): flush write buffer if needed. change arg type from scm_fport to SCM port. fport.h (SCM_SETFDES): removed. (SCM_MAYBE_DRAIN_INPUT): new macro. * ioext.c (scm_dup_to_fdes): use SCM_FSTREAM. (scm_ftell): always use lseek and account for the buffer. (scm_fileno): use fport buffer. (scm_fseek): clear fport buffers. always use lseek. * posix.c (scm_pipe): use fport buffer. * unif.c: include fports.h instead of genio.h. * fports.c (scm_fdes_wait_for_input, scm_fport_fill_buffer): new procedures. (local_fgetc): use them. (local_ffwrite): use buffer. (local_fgets): use buffer. (scm_setbuf0): deleted. (scm_setvbuf): set the buffer. (scm_setfileno): deleted. (scm_evict_ports): set fdes directly. * (scm_freopen): deleted. doesn't seem useful in Guile. (scm_stdio_to_port): deleted. fports.h (struct scm_fport): add shortbuf member to avoid separate code for unbuffered ports. (SCM_FPORTP, SCM_OPFPORTP, SCM_OPINFPORTP, SCM_OPOUTFPORTP): moved from ports.h. * genio.c, genio.h: move contents into ports.c, ports.h. The division wasn't useful. * fports.c, fports.h (scm_fport_drain_input): new procedure. * ports.c (scm_drain_input): call scm_fport_drain_input. * scm_fdes_waiting_p: new procedure. * fports.c (scm_fdes_to_port): allocate read and/or write buffers. (scm_input_waiting_p): check the buffer. (local_fgetc, local_fflush, local_fputc): likewise. * fports.h (scm_fport): read/write_buf,_pos,_buf_end,,_buf_size: new members. * init.c (scm_init_standard_ports): pass fdes instead of FILE *. * * ports.c (scm_drain_input): new procedure. ports.h: prototype. * fports.c (FPORT_READ_SAFE, FPORT_WRITE_SAFE, FPORT_ALL_OKAY, pre_read, pre_write): removed. (local_fputc, local_fputs, local_ffwrite): use write, not stdio. (scm_standard_stream_to_port): change first arg from FILE * to int fdes. (local_fflush): flush fdes, not FILE *. * fports.h (SCM_NOFTELL): removed. * genio.c, ports.c: don't include filesys.h. * genio.c (scm_getc): don't use scm_internal_select if FPORT. do it in fports.c:local_fgetc. * genio.c: don't use SCM_SYSCALL when calling ptob procedures. do it where it's needed in the port smobs. * filesys.c (scm_input_waiting_p): moved to fports.c, stdio buffer support removed. take SCM arg, not FILE *. * filesys.h: prototype moved too. * fports.c (scm_fdes_to_port): new procedure. (local_fgetc): use read not fgetc. (local_fclose): use close, not fclose. (local_fgets): use read, not fgets * fports.h: prototype for scm_fdes_to_port. * fports.h (scm_fport): new struct. * fports.c (scm_open_file): use open, not fopen. #include fcntl.h * ports.h (struct scm_port_table): change stream from SCM to void *. * ports.c (scm_add_to_port_table): check for memory allocation error. (scm_prinport): remove MSDOS hair. (scm_void_port): set stream to 0 instead of SCM_BOOL_F. (scm_close_port): don't throw errors: do it in fports.c.
572 lines
16 KiB
C
572 lines
16 KiB
C
/* Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc.
|
||
*
|
||
* This program is free software; you can redistribute it and/or modify
|
||
* it under the terms of the GNU General Public License as published by
|
||
* the Free Software Foundation; either version 2, or (at your option)
|
||
* any later version.
|
||
*
|
||
* This program is distributed in the hope that it will be useful,
|
||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
* GNU General Public License for more details.
|
||
*
|
||
* You should have received a copy of the GNU General Public License
|
||
* along with this software; see the file COPYING. If not, write to
|
||
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
||
* Boston, MA 02111-1307 USA
|
||
*
|
||
* As a special exception, the Free Software Foundation gives permission
|
||
* for additional uses of the text contained in its release of GUILE.
|
||
*
|
||
* The exception is that, if you link the GUILE library with other files
|
||
* to produce an executable, this does not by itself cause the
|
||
* resulting executable to be covered by the GNU General Public License.
|
||
* Your use of that executable is in no way restricted on account of
|
||
* linking the GUILE library code into it.
|
||
*
|
||
* This exception does not however invalidate any other reasons why
|
||
* the executable file might be covered by the GNU General Public License.
|
||
*
|
||
* This exception applies only to the code released by the
|
||
* Free Software Foundation under the name GUILE. If you copy
|
||
* code from other Free Software Foundation releases into a copy of
|
||
* GUILE, as the General Public License permits, the exception does
|
||
* not apply to the code that you add in this way. To avoid misleading
|
||
* anyone as to the status of such modified files, you must delete
|
||
* this exception notice from them.
|
||
*
|
||
* If you write modifications of your own for GUILE, it is your choice
|
||
* whether to permit this exception to apply to your modifications.
|
||
* If you do not wish that, delete this exception notice. */
|
||
|
||
/* Include the headers for just about everything.
|
||
We call all their initialization functions. */
|
||
|
||
#include <stdio.h>
|
||
#include "_scm.h"
|
||
|
||
/* Everybody has an init function. */
|
||
#include "alist.h"
|
||
#include "arbiters.h"
|
||
#include "async.h"
|
||
#include "backtrace.h"
|
||
#include "boolean.h"
|
||
#include "chars.h"
|
||
#include "continuations.h"
|
||
#ifdef DEBUG_EXTENSIONS
|
||
#include "debug.h"
|
||
#endif
|
||
#include "dynl.h"
|
||
#include "dynwind.h"
|
||
#include "eq.h"
|
||
#include "error.h"
|
||
#include "eval.h"
|
||
#include "evalext.h"
|
||
#include "feature.h"
|
||
#include "filesys.h"
|
||
#include "fluids.h"
|
||
#include "fports.h"
|
||
#include "gc.h"
|
||
#include "gdbint.h"
|
||
#include "gsubr.h"
|
||
#include "hash.h"
|
||
#include "hashtab.h"
|
||
#ifdef GUILE_ISELECT
|
||
#include "iselect.h"
|
||
#endif
|
||
#include "ioext.h"
|
||
#include "keywords.h"
|
||
#include "list.h"
|
||
#include "load.h"
|
||
#include "macros.h"
|
||
#include "mallocs.h"
|
||
#include "modules.h"
|
||
#include "net_db.h"
|
||
#include "numbers.h"
|
||
#include "objects.h"
|
||
#include "objprop.h"
|
||
#include "options.h"
|
||
#include "pairs.h"
|
||
#include "ports.h"
|
||
#include "posix.h"
|
||
#ifdef HAVE_REGCOMP
|
||
#include "regex-posix.h"
|
||
#endif
|
||
#include "print.h"
|
||
#include "procprop.h"
|
||
#include "procs.h"
|
||
#include "ramap.h"
|
||
#include "random.h"
|
||
#include "read.h"
|
||
#include "scmsigs.h"
|
||
#include "script.h"
|
||
#include "simpos.h"
|
||
#include "smob.h"
|
||
#include "socket.h"
|
||
#include "sort.h"
|
||
#include "srcprop.h"
|
||
#include "stackchk.h"
|
||
#include "stacks.h"
|
||
#include "stime.h"
|
||
#include "strings.h"
|
||
#include "strop.h"
|
||
#include "strorder.h"
|
||
#include "strports.h"
|
||
#include "struct.h"
|
||
#include "symbols.h"
|
||
#include "tag.h"
|
||
#include "throw.h"
|
||
#include "unif.h"
|
||
#include "variable.h"
|
||
#include "vectors.h"
|
||
#include "version.h"
|
||
#include "vports.h"
|
||
#include "weaks.h"
|
||
#include "guardians.h"
|
||
|
||
#include "init.h"
|
||
|
||
#ifdef HAVE_STRING_H
|
||
#include <string.h>
|
||
#endif
|
||
#ifdef HAVE_UNISTD_H
|
||
#include <unistd.h>
|
||
#endif
|
||
|
||
/* Setting up the stack. */
|
||
|
||
static void start_stack SCM_P ((void *base));
|
||
static void restart_stack SCM_P ((void * base));
|
||
|
||
static void
|
||
start_stack (base)
|
||
void * base;
|
||
{
|
||
SCM root;
|
||
|
||
root = scm_permanent_object (scm_make_root (SCM_UNDEFINED));
|
||
scm_set_root (SCM_ROOT_STATE (root));
|
||
scm_stack_base = base;
|
||
|
||
scm_exitval = SCM_BOOL_F; /* vestigial */
|
||
|
||
scm_top_level_lookup_closure_var = SCM_BOOL_F;
|
||
scm_system_transformer = SCM_BOOL_F;
|
||
|
||
scm_root->fluids = scm_make_initial_fluids ();
|
||
|
||
/* Create an object to hold the root continuation.
|
||
*/
|
||
SCM_NEWCELL (scm_rootcont);
|
||
SCM_SETJMPBUF (scm_rootcont, scm_must_malloc ((long) sizeof (scm_contregs),
|
||
"continuation"));
|
||
SCM_SETCAR (scm_rootcont, scm_tc7_contin);
|
||
SCM_SEQ (scm_rootcont) = 0;
|
||
/* The root continuation if further initialized by restart_stack. */
|
||
|
||
/* Create the look-aside stack for variables that are shared between
|
||
* captured continuations.
|
||
*/
|
||
scm_continuation_stack = scm_make_vector (SCM_MAKINUM (512), SCM_UNDEFINED);
|
||
/* The continuation stack is further initialized by restart_stack. */
|
||
|
||
/* The remainder of stack initialization is factored out to another
|
||
* function so that if this stack is ever exitted, it can be
|
||
* re-entered using restart_stack. */
|
||
restart_stack (base);
|
||
}
|
||
|
||
|
||
static void
|
||
restart_stack (base)
|
||
void * base;
|
||
{
|
||
scm_dynwinds = SCM_EOL;
|
||
SCM_DYNENV (scm_rootcont) = SCM_EOL;
|
||
SCM_THROW_VALUE (scm_rootcont) = SCM_EOL;
|
||
#ifdef DEBUG_EXTENSIONS
|
||
SCM_DFRAME (scm_rootcont) = scm_last_debug_frame = 0;
|
||
#endif
|
||
SCM_BASE (scm_rootcont) = base;
|
||
scm_continuation_stack_ptr = SCM_MAKINUM (0);
|
||
}
|
||
|
||
#if 0
|
||
static char remsg[] = "remove\n#define ", addmsg[] = "add\n#define ";
|
||
|
||
|
||
static void fixconfig SCM_P ((char *s1, char *s2, int s));
|
||
|
||
static void
|
||
fixconfig (s1, s2, s)
|
||
char *s1;
|
||
char *s2;
|
||
int s;
|
||
{
|
||
fputs (s1, stderr);
|
||
fputs (s2, stderr);
|
||
fputs ("\nin ", stderr);
|
||
fputs (s ? "setjump" : "scmfig", stderr);
|
||
fputs (".h and recompile scm\n", stderr);
|
||
exit (1);
|
||
}
|
||
|
||
|
||
static void check_config SCM_P ((void));
|
||
|
||
static void
|
||
check_config ()
|
||
{
|
||
scm_sizet j;
|
||
|
||
j = HEAP_SEG_SIZE;
|
||
if (HEAP_SEG_SIZE != j)
|
||
fixconfig ("reduce", "size of HEAP_SEG_SIZE", 0);
|
||
|
||
#ifdef SCM_SINGLES
|
||
if (sizeof (float) != sizeof (long))
|
||
fixconfig (remsg, "SCM_SINGLES", 0);
|
||
#endif /* def SCM_SINGLES */
|
||
|
||
|
||
#ifdef SCM_BIGDIG
|
||
if (2 * SCM_BITSPERDIG / SCM_CHAR_BIT > sizeof (long))
|
||
fixconfig (remsg, "SCM_BIGDIG", 0);
|
||
#ifndef SCM_DIGSTOOBIG
|
||
if (SCM_DIGSPERLONG * sizeof (SCM_BIGDIG) > sizeof (long))
|
||
fixconfig (addmsg, "SCM_DIGSTOOBIG", 0);
|
||
#endif
|
||
#endif
|
||
|
||
#ifdef SCM_STACK_GROWS_UP
|
||
if (((SCM_STACKITEM *) & j - stack_start_ptr) < 0)
|
||
fixconfig (remsg, "SCM_STACK_GROWS_UP", 1);
|
||
#else
|
||
if ((stack_start_ptr - (SCM_STACKITEM *) & j) < 0)
|
||
fixconfig (addmsg, "SCM_STACK_GROWS_UP", 1);
|
||
#endif
|
||
}
|
||
#endif
|
||
|
||
|
||
|
||
/* initializing standard and current I/O ports */
|
||
|
||
/* Like scm_fdes_to_port, except that:
|
||
- NAME is a standard C string, not a Guile string
|
||
- we set the revealed count for FILE's file descriptor to 1, so
|
||
that fdes won't be closed when the port object is GC'd. */
|
||
static SCM
|
||
scm_standard_stream_to_port (int fdes, char *mode, char *name)
|
||
{
|
||
SCM port = scm_fdes_to_port (fdes, mode, scm_makfrom0str (name));
|
||
scm_set_port_revealed_x (port, SCM_MAKINUM (1));
|
||
return port;
|
||
}
|
||
|
||
/* Create standard ports from stdin, stdout, and stderr. */
|
||
static void
|
||
scm_init_standard_ports ()
|
||
{
|
||
/* From the SCSH manual:
|
||
|
||
It can be useful to turn I/O buffering off in some cases, for
|
||
example when an I/O stream is to be shared by multiple
|
||
subprocesses. For this reason, scsh allocates an unbuffered port
|
||
for file descriptor 0 at start-up time.
|
||
|
||
Because shells frequently share stdin with subprocesses, if the
|
||
shell does buffered reads, it might ``steal'' input intended for
|
||
a subprocess. For this reason, all shells, including sh, csh,
|
||
and scsh, read stdin unbuffered. Applications that can tolerate
|
||
buffered input on stdin can reset \ex{(current-input-port)} to
|
||
block buffering for higher performance. */
|
||
|
||
/* stdout and stderr are also now unbuffered if connected to
|
||
a terminal, since line buffered output is no longer available. */
|
||
scm_def_inp
|
||
= scm_standard_stream_to_port (0,
|
||
isatty (0) ? "r0" : "r",
|
||
"standard input");
|
||
scm_def_outp = scm_standard_stream_to_port (1,
|
||
isatty (1) ? "wl" : "w",
|
||
"standard output");
|
||
scm_def_errp = scm_standard_stream_to_port (2,
|
||
isatty (2) ? "w0" : "w",
|
||
"standard error");
|
||
|
||
scm_cur_inp = scm_def_inp;
|
||
scm_cur_outp = scm_def_outp;
|
||
scm_cur_errp = scm_def_errp;
|
||
scm_cur_loadp = SCM_BOOL_F;
|
||
}
|
||
|
||
|
||
|
||
/* Loading the startup Scheme files. */
|
||
|
||
/* The boot code "ice-9/boot-9" is only loaded by scm_boot_guile when
|
||
this is false. The unexec code uses this, to keep ice_9 from being
|
||
loaded into dumped guile executables. */
|
||
int scm_ice_9_already_loaded = 0;
|
||
|
||
void
|
||
scm_load_startup_files ()
|
||
{
|
||
/* We want a path only containing directories from GUILE_LOAD_PATH,
|
||
SCM_SITE_DIR and SCM_LIBRARY_DIR when searching for the site init
|
||
file, so we do this before loading Ice-9. */
|
||
SCM init_path = scm_sys_search_load_path (scm_makfrom0str ("init.scm"));
|
||
|
||
/* Load Ice-9. */
|
||
if (!scm_ice_9_already_loaded)
|
||
scm_primitive_load_path (scm_makfrom0str ("ice-9/boot-9.scm"));
|
||
|
||
/* Load the init.scm file. */
|
||
if (SCM_NFALSEP (init_path))
|
||
scm_primitive_load (init_path);
|
||
}
|
||
|
||
|
||
|
||
/* The main init code. */
|
||
|
||
#ifdef _UNICOS
|
||
typedef int setjmp_type;
|
||
#else
|
||
typedef long setjmp_type;
|
||
#endif
|
||
|
||
/* All the data needed to invoke the main function. */
|
||
struct main_func_closure
|
||
{
|
||
/* the function to call */
|
||
void (*main_func) SCM_P ((void *closure, int argc, char **argv));
|
||
void *closure; /* dummy data to pass it */
|
||
int argc;
|
||
char **argv; /* the argument list it should receive */
|
||
};
|
||
|
||
|
||
static void scm_boot_guile_1 SCM_P ((SCM_STACKITEM *base,
|
||
struct main_func_closure *closure));
|
||
static SCM invoke_main_func SCM_P ((void *body_data));
|
||
|
||
|
||
/* Fire up the Guile Scheme interpreter.
|
||
|
||
Call MAIN_FUNC, passing it CLOSURE, ARGC, and ARGV. MAIN_FUNC
|
||
should do all the work of the program (initializing other packages,
|
||
reading user input, etc.) before returning. When MAIN_FUNC
|
||
returns, call exit (0); this function never returns. If you want
|
||
some other exit value, MAIN_FUNC may call exit itself.
|
||
|
||
scm_boot_guile arranges for program-arguments to return the strings
|
||
given by ARGC and ARGV. If MAIN_FUNC modifies ARGC/ARGV, should
|
||
call scm_set_program_arguments with the final list, so Scheme code
|
||
will know which arguments have been processed.
|
||
|
||
scm_boot_guile establishes a catch-all catch handler which prints
|
||
an error message and exits the process. This means that Guile
|
||
exits in a coherent way when system errors occur and the user isn't
|
||
prepared to handle it. If the user doesn't like this behavior,
|
||
they can establish their own universal catcher to shadow this one.
|
||
|
||
Why must the caller do all the real work from MAIN_FUNC? The
|
||
garbage collector assumes that all local variables of type SCM will
|
||
be above scm_boot_guile's stack frame on the stack. If you try to
|
||
manipulate SCM values after this function returns, it's the luck of
|
||
the draw whether the GC will be able to find the objects you
|
||
allocate. So, scm_boot_guile function exits, rather than
|
||
returning, to discourage people from making that mistake. */
|
||
|
||
|
||
void
|
||
scm_boot_guile (argc, argv, main_func, closure)
|
||
int argc;
|
||
char ** argv;
|
||
void (*main_func) ();
|
||
void *closure;
|
||
{
|
||
/* The garbage collector uses the address of this variable as one
|
||
end of the stack, and the address of one of its own local
|
||
variables as the other end. */
|
||
SCM_STACKITEM dummy;
|
||
struct main_func_closure c;
|
||
|
||
c.main_func = main_func;
|
||
c.closure = closure;
|
||
c.argc = argc;
|
||
c.argv = argv;
|
||
|
||
scm_boot_guile_1 (&dummy, &c);
|
||
}
|
||
|
||
|
||
/* Record here whether SCM_BOOT_GUILE_1 has already been called. This
|
||
variable is now here and not inside SCM_BOOT_GUILE_1 so that one
|
||
can tweak it. This is necessary for unexec to work. (Hey, "1-live"
|
||
is the name of a local radiostation...) */
|
||
|
||
int scm_boot_guile_1_live = 0;
|
||
|
||
static void
|
||
scm_boot_guile_1 (base, closure)
|
||
SCM_STACKITEM *base;
|
||
struct main_func_closure *closure;
|
||
{
|
||
static int initialized = 0;
|
||
/* static int live = 0; */
|
||
setjmp_type setjmp_val;
|
||
|
||
/* This function is not re-entrant. */
|
||
if (scm_boot_guile_1_live)
|
||
abort ();
|
||
|
||
scm_boot_guile_1_live = 1;
|
||
|
||
scm_ints_disabled = 1;
|
||
scm_block_gc = 1;
|
||
|
||
if (initialized)
|
||
{
|
||
restart_stack (base);
|
||
}
|
||
else
|
||
{
|
||
scm_ports_prehistory ();
|
||
scm_smob_prehistory ();
|
||
scm_tables_prehistory ();
|
||
scm_init_storage (0);
|
||
scm_init_root ();
|
||
#ifdef USE_THREADS
|
||
scm_init_threads (base);
|
||
#endif
|
||
start_stack (base);
|
||
scm_init_gsubr ();
|
||
scm_init_feature ();
|
||
scm_init_alist ();
|
||
scm_init_arbiters ();
|
||
scm_init_async ();
|
||
scm_init_boolean ();
|
||
scm_init_chars ();
|
||
scm_init_continuations ();
|
||
scm_init_dynwind ();
|
||
scm_init_eq ();
|
||
scm_init_error ();
|
||
scm_init_fluids ();
|
||
scm_init_backtrace (); /* Requires fluids */
|
||
scm_init_fports ();
|
||
scm_init_filesys ();
|
||
scm_init_gc ();
|
||
scm_init_gdbint ();
|
||
scm_init_hash ();
|
||
scm_init_hashtab ();
|
||
#ifdef GUILE_ISELECT
|
||
scm_init_iselect ();
|
||
#endif
|
||
scm_init_ioext ();
|
||
scm_init_keywords ();
|
||
scm_init_list ();
|
||
scm_init_macros ();
|
||
scm_init_mallocs ();
|
||
scm_init_modules ();
|
||
scm_init_net_db ();
|
||
scm_init_numbers ();
|
||
scm_init_objprop ();
|
||
scm_init_options ();
|
||
scm_init_pairs ();
|
||
scm_init_ports ();
|
||
scm_init_posix ();
|
||
#ifdef HAVE_REGCOMP
|
||
scm_init_regex_posix ();
|
||
#endif
|
||
scm_init_procs ();
|
||
scm_init_procprop ();
|
||
scm_init_scmsigs ();
|
||
scm_init_socket ();
|
||
scm_init_sort ();
|
||
#ifdef DEBUG_EXTENSIONS
|
||
scm_init_srcprop ();
|
||
#endif
|
||
scm_init_stackchk ();
|
||
scm_init_struct (); /* Requires struct */
|
||
scm_init_stacks ();
|
||
scm_init_strports ();
|
||
scm_init_symbols ();
|
||
scm_init_tag ();
|
||
scm_init_load ();
|
||
scm_init_objects (); /* Requires struct */
|
||
scm_init_print (); /* Requires struct */
|
||
scm_init_read ();
|
||
scm_init_stime ();
|
||
scm_init_strings ();
|
||
scm_init_strorder ();
|
||
scm_init_strop ();
|
||
scm_init_throw ();
|
||
scm_init_variable ();
|
||
scm_init_vectors ();
|
||
scm_init_version ();
|
||
scm_init_weaks ();
|
||
scm_init_guardian ();
|
||
scm_init_vports ();
|
||
scm_init_eval ();
|
||
scm_init_evalext ();
|
||
#ifdef DEBUG_EXTENSIONS
|
||
scm_init_debug (); /* Requires macro smobs */
|
||
#endif
|
||
scm_init_ramap ();
|
||
scm_init_random ();
|
||
scm_init_unif ();
|
||
scm_init_simpos ();
|
||
scm_init_load_path ();
|
||
scm_init_standard_ports ();
|
||
scm_init_dynamic_linking ();
|
||
scm_init_script ();
|
||
initialized = 1;
|
||
}
|
||
|
||
scm_block_gc = 0; /* permit the gc to run */
|
||
/* ints still disabled */
|
||
|
||
#ifdef STACK_CHECKING
|
||
scm_stack_checking_enabled_p = SCM_STACK_CHECKING_P;
|
||
#endif
|
||
|
||
setjmp_val = setjmp (SCM_JMPBUF (scm_rootcont));
|
||
if (!setjmp_val)
|
||
{
|
||
scm_set_program_arguments (closure->argc, closure->argv, 0);
|
||
scm_internal_lazy_catch (SCM_BOOL_T, invoke_main_func, closure,
|
||
scm_handle_by_message, 0);
|
||
}
|
||
|
||
scm_restore_signals ();
|
||
|
||
/* This tick gives any pending
|
||
* asyncs a chance to run. This must be done after
|
||
* the call to scm_restore_signals.
|
||
*/
|
||
SCM_ASYNC_TICK;
|
||
|
||
/* If the caller doesn't want this, they should return from
|
||
main_func themselves. */
|
||
exit (0);
|
||
}
|
||
|
||
|
||
static SCM
|
||
invoke_main_func (body_data)
|
||
void *body_data;
|
||
{
|
||
struct main_func_closure *closure = (struct main_func_closure *) body_data;
|
||
|
||
scm_load_startup_files ();
|
||
|
||
scm_post_boot_init_modules ();
|
||
|
||
(*closure->main_func) (closure->closure, closure->argc, closure->argv);
|
||
|
||
/* never reached */
|
||
return SCM_UNDEFINED;
|
||
}
|