Add 1999 to copyright years.
[bpt/guile.git] / libguile / init.c
index f4707da..73315e5 100644 (file)
@@ -1,4 +1,4 @@
-/*     Copyright (C) 1995,1996,1997 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1997,1998,1999 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
@@ -39,6 +39,8 @@
  * whether to permit this exception to apply to your modifications.
  * If you do not wish that, delete this exception notice.  */
 \f
+/* Include the headers for just about everything.
+   We call all their initialization functions.  */
 
 #include <stdio.h>
 #include "_scm.h"
@@ -59,6 +61,7 @@
 #include "eq.h"
 #include "error.h"
 #include "eval.h"
+#include "evalext.h"
 #include "feature.h"
 #include "filesys.h"
 #include "fluids.h"
 #include "iselect.h"
 #endif
 #include "ioext.h"
-#include "kw.h"
+#include "keywords.h"
+#include "lang.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 "procprop.h"
 #include "procs.h"
 #include "ramap.h"
+#include "random.h"
 #include "read.h"
-#include "readline.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 "version.h"
 #include "vports.h"
 #include "weaks.h"
+#include "guardians.h"
 
 #include "init.h"
 
 #include <unistd.h>
 #endif
 \f
+/* Setting up the stack.  */
 
 static void start_stack SCM_P ((void *base));
 static void restart_stack SCM_P ((void * base));
@@ -159,8 +168,7 @@ start_stack (base)
   /* Create the look-aside stack for variables that are shared between
    * captured continuations.
    */
-  scm_continuation_stack = scm_make_vector (SCM_MAKINUM (512),
-                                           SCM_UNDEFINED, SCM_UNDEFINED);
+  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
@@ -245,7 +253,19 @@ check_config ()
 \f
 /* initializing standard and current I/O ports */
 
-/* Create standard ports from stdio stdin, stdout, and stderr.  */
+/* 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 ()
 {
@@ -262,19 +282,58 @@ scm_init_standard_ports ()
      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.  */
-  scm_def_inp = scm_stdio_to_port (stdin, 
-                                  (isatty (fileno (stdin)) ? "r0" : "r"),
+
+  scm_def_inp
+    = scm_standard_stream_to_port (0, 
+                                  isatty (0) ? "r0" : "r",
                                   "standard input");
-  scm_def_outp = scm_stdio_to_port (stdout, "w", "standard output");
-  scm_def_errp = scm_stdio_to_port (stderr, "w", "standard error");
+  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;
+}
+
+
+\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);
+  
+      scm_post_boot_init_modules ();
+    }
 }
 
 
 \f
+/* The main init code.  */
+
 #ifdef _UNICOS
 typedef int setjmp_type;
 #else
@@ -382,6 +441,7 @@ scm_boot_guile_1 (base, closure)
       scm_smob_prehistory ();
       scm_tables_prehistory ();
       scm_init_storage (0);
+      scm_init_subr_table ();
       scm_init_root ();
 #ifdef USE_THREADS
       scm_init_threads (base);
@@ -410,17 +470,15 @@ scm_boot_guile_1 (base, closure)
       scm_init_iselect ();
 #endif
       scm_init_ioext ();
-      scm_init_kw ();
+      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 ();
-#if DEBUG_EXTENSIONS
-      /* Excluding this until it's really needed makes the binary
-       * smaller after linking.  */
       scm_init_options ();
-#endif
       scm_init_pairs ();
       scm_init_ports ();
       scm_init_posix ();
@@ -431,6 +489,7 @@ scm_boot_guile_1 (base, closure)
       scm_init_procprop ();
       scm_init_scmsigs ();
       scm_init_socket ();
+      scm_init_sort ();
 #ifdef DEBUG_EXTENSIONS
       scm_init_srcprop ();
 #endif
@@ -453,20 +512,21 @@ scm_boot_guile_1 (base, closure)
       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 ();
-#ifdef HAVE_RL_GETC_FUNCTION
-      scm_init_readline ();
-#endif
       scm_init_standard_ports ();
       scm_init_dynamic_linking ();
+      scm_init_lang ();
       scm_init_script ();
       initialized = 1;
     }
@@ -482,8 +542,8 @@ scm_boot_guile_1 (base, closure)
   if (!setjmp_val)
     {
       scm_set_program_arguments (closure->argc, closure->argv, 0);
-      scm_internal_catch (SCM_BOOL_T, invoke_main_func, closure,
-                         scm_handle_by_message, 0);
+      scm_internal_lazy_catch (SCM_BOOL_T, invoke_main_func, closure,
+                              scm_handle_by_message, 0);
     }
 
   scm_restore_signals ();
@@ -506,6 +566,8 @@ invoke_main_func (body_data)
 {
   struct main_func_closure *closure = (struct main_func_closure *) body_data;
 
+  scm_load_startup_files ();
+
   (*closure->main_func) (closure->closure, closure->argc, closure->argv);
 
   /* never reached */