diff src/lread.c @ 4448:fd8a9a4d81d9

Support #!, to allow XEmacs to be called as a script interpreter. ChangeLog addition: 2008-01-20 Aidan Kehoe <kehoea@parhasard.net> * Makefile.in.in (SHEBANG_PROGNAME): New variable; a symbol link to the XEmacs binary to tell it it should read a script from stdin. * configure.ac (XE_EXPAND_VARIABLE): Set SHEBANG_PROGNAME. * configure: Regenerate. src/ChangeLog addition: 2008-01-20 Aidan Kehoe <kehoea@parhasard.net> * config.h.in: Add SHEBANG_PROGNAME. * emacs.c (main_1): If we've been called using SHEBANG_PROGNAME, rewrite our arguments to add a --script argument. Also, handle the --script argument by setting noninteractive and vanilla. * lread.c (Fload_internal): If the first two characters of a file are #!, replace them with ;! before they get to the Lisp reader. lisp/ChangeLog addition: 2008-01-20 Aidan Kehoe <kehoea@parhasard.net> * startup.el (command-line-do-script): New. (command-switch-alist): Use command-line-do-script. New argument, compatible with GNU; --script or -script says "treat the following argument as a file to load in batch mode". man/ChangeLog addition: 2008-01-20 Aidan Kehoe <kehoea@parhasard.net> * xemacs/cmdargs.texi (Command Switches): Describe --script, -script.
author Aidan Kehoe <kehoea@parhasard.net>
date Sun, 20 Jan 2008 19:53:54 +0100
parents d9eb5ea14f65
children ac6231e0c1df
line wrap: on
line diff
--- a/src/lread.c	Sun Jan 20 13:09:58 2008 +0100
+++ b/src/lread.c	Sun Jan 20 19:53:54 2008 +0100
@@ -744,6 +744,25 @@
     internal_bind_lisp_object (&Vfile_domain, Qnil);
 #endif
 
+    /* Is there a #!? If so, read it, and unread ;!.
+
+       GNU implement this by treating any #! anywhere in the source text as
+       commenting out the whole line. */
+    {
+      char shebangp[2];
+      int num_read;
+
+      num_read = Lstream_read (XLSTREAM (lispstream), shebangp,
+                               sizeof(shebangp));
+      if (sizeof(shebangp) == num_read
+	  && 0 == strncmp("#!", shebangp, sizeof(shebangp)))
+	{
+          shebangp[0] = ';';
+	}
+
+      Lstream_unread (XLSTREAM (lispstream), shebangp, num_read);
+    }
+
     /* Now determine what sort of ELC file we're reading in. */
     internal_bind_int (&load_byte_code_version, load_byte_code_version);
     if (reading_elc)