*** empty log message ***
[bpt/guile.git] / libguile / script.c
index 948662a..a5f9e5f 100644 (file)
@@ -1,46 +1,25 @@
-/* Copyright (C) 1994, 1995, 1996, 1997, 1998, 2000, 2001 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.
+/* Copyright (C) 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
  *
- * 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.
+ * This library 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
+ * Lesser General Public License for more details.
  *
- * 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.  */
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
 
 /* "script.c" argv tricks for `#!' scripts.
    Authors: Aubrey Jaffer and Jim Blandy */
 
+#if HAVE_CONFIG_H
+#  include <config.h>
+#endif
 
 #include <stdio.h>
 #include <errno.h>
@@ -83,7 +62,7 @@ scm_cat_path (char *str1, const char *str2, long n)
       strncat (str1 + len, str2, n);
       return str1;
     }
-  str1 = (char *) malloc ((size_t) (n + 1));
+  str1 = (char *) scm_malloc ((size_t) (n + 1));
   if (!str1)
     return 0L;
   str1[0] = 0;
@@ -236,7 +215,7 @@ script_read_arg (FILE *f)
 #define FUNC_NAME "script_read_arg"
 {
   size_t size = 7;
-  char *buf = malloc (size + 1);
+  char *buf = scm_malloc (size + 1);
   size_t len = 0;
 
   if (! buf)
@@ -315,7 +294,7 @@ scm_get_meta_args (int argc, char **argv)
   char *narg, **nargv;
   if (!(argc > 2 && script_meta_arg_P (argv[1])))
     return 0L;
-  if (!(nargv = (char **) malloc ((1 + nargc) * sizeof (char *))))
+  if (!(nargv = (char **) scm_malloc ((1 + nargc) * sizeof (char *))))
       return 0L;
   nargv[0] = argv[0];
   while (((argi + 1) < argc) && (script_meta_arg_P (argv[argi])))
@@ -366,18 +345,21 @@ char *scm_usage_name = 0;
 void
 scm_shell_usage (int fatal, char *message)
 {
+  FILE  *fp = (fatal ? stderr : stdout);
+
   if (message)
-    fprintf (stderr, "%s\n", message);
+    fprintf (fp, "%s\n", message);
 
-  fprintf (stderr
+  fprintf (fp
            "Usage: %s OPTION ...\n"
            "Evaluate Scheme code, interactively or from a script.\n"
            "\n"
-           "  -s SCRIPT      load Scheme source code from FILE, and exit\n"
+           "  [-s] FILE      load Scheme source code from FILE, and exit\n"
            "  -c EXPR        evalute Scheme expression EXPR, and exit\n"
            "  --             stop scanning arguments; run interactively\n"
            "The above switches stop argument processing, and pass all\n"
            "remaining arguments as the value of (command-line).\n"
+           "If FILE begins with `-' the -s switch is mandatory.\n"
            "\n"
            "  -l FILE        load Scheme source code from FILE\n"
            "  -e FUNCTION    after reading script, apply FUNCTION to\n"
@@ -393,7 +375,9 @@ scm_shell_usage (int fatal, char *message)
           "                 which is a list of numbers like \"2,13,14\"\n"
            "  -h, --help     display this help and exit\n"
            "  -v, --version  display version information and exit\n"
-          "  \\              read arguments from following script lines\n",
+          "  \\              read arguments from following script lines\n"
+           "\n"
+          "Report bugs to bug-guile@gnu.org\n",
            scm_usage_name);
 
   if (fatal)
@@ -457,9 +441,9 @@ scm_compile_shell_switches (int argc, char **argv)
   
   for (i = 1; i < argc; i++)
     {
-      if (! strcmp (argv[i], "-s")) /* load script */
+      if ((! strcmp (argv[i], "-s")) || (argv[i][0] != '-')) /* load script */
        {
-         if (++i >= argc)
+         if ((argv[i][0] == '-') && (++i >= argc))
            scm_shell_usage (1, "missing argument to `-s' switch");
 
          /* If we specified the -ds option, do_script points to the
@@ -515,7 +499,7 @@ scm_compile_shell_switches (int argc, char **argv)
       else if (! strcmp (argv[i], "-e")) /* entry point */
        {
          if (++i < argc)
-           entry_point = gh_symbol2scm (argv[i]);
+           entry_point = scm_c_read_string (argv[i]);
          else
            scm_shell_usage (1, "missing argument to `-e' switch");
        }
@@ -595,7 +579,7 @@ scm_compile_shell_switches (int argc, char **argv)
        {
          /* Print version number.  */
          printf ("Guile %s\n"
-                 "Copyright (c) 1995, 1996, 1997, 2000, 2001 Free Software Foundation\n"
+                 "Copyright (c) 1995, 1996, 1997, 2000, 2001, 2002 Free Software Foundation\n"
                  "Guile may be distributed under the terms of the GNU General Public Licence;\n"
                  "certain other uses are permitted as well.  For details, see the file\n"
                  "`COPYING', which is included in the Guile distribution.\n"
@@ -641,8 +625,6 @@ scm_compile_shell_switches (int argc, char **argv)
         quit.  */
       tail = scm_cons (scm_cons (sym_quit, SCM_EOL),
                       tail);
-      /* Allow asyncs (signal handlers etc.) to be run.  */
-      scm_mask_ints = 0;
     }
 
   /* After the following line, actions will be added to the front. */
@@ -656,8 +638,8 @@ scm_compile_shell_switches (int argc, char **argv)
     }
 
   /* If debugging was requested, or we are interactive and debugging
-     was not explicitely turned off, turn on debugging. */
-  if (turn_on_debugging || (interactive  && !dont_turn_on_debugging))
+     was not explicitly turned off, turn on debugging. */
+  if (turn_on_debugging || (interactive && !dont_turn_on_debugging))
     {
       tail = scm_cons (scm_cons (sym_turn_on_debugging, SCM_EOL), tail);
     }
@@ -665,7 +647,7 @@ scm_compile_shell_switches (int argc, char **argv)
   {
     SCM val = scm_cons (sym_begin, tail);
 
-#if 1
+#if 0
     scm_write (val, SCM_UNDEFINED);
     scm_newline (SCM_UNDEFINED);
 #endif
@@ -699,9 +681,7 @@ scm_shell (int argc, char **argv)
 void
 scm_init_script ()
 {
-#ifndef SCM_MAGIC_SNARFER
 #include "libguile/script.x"
-#endif
 }
 
 /*