Mercurial > hg > xemacs-beta
diff src/emacs.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 | 461fdb92f3b6 |
children | ac6231e0c1df |
line wrap: on
line diff
--- a/src/emacs.c Sun Jan 20 13:09:58 2008 +0100 +++ b/src/emacs.c Sun Jan 20 19:53:54 2008 +0100 @@ -955,6 +955,42 @@ init_free_hook (); #endif +#define SHEBANG_PROGNAME_LENGTH \ + (int)((sizeof (WEXTSTRING (SHEBANG_PROGNAME)) - sizeof (WEXTSTRING ("")))) +#define SHEBANG_EXE_PROGNAME_LENGTH \ + (int)(sizeof (WEXTSTRING (SHEBANG_PROGNAME ".exe")) \ + - sizeof (WEXTSTRING (""))) + + { + int progname_len = wext_strlen (argv[0]); + if (progname_len >= SHEBANG_PROGNAME_LENGTH) + { + if (!wext_strcmp_ascii (argv[0] + + (progname_len - SHEBANG_PROGNAME_LENGTH), + SHEBANG_PROGNAME) + /* Allow trailing .exe. Don't check it, it could also be + .com. */ + || (progname_len >= SHEBANG_EXE_PROGNAME_LENGTH && + !wext_strncmp_ascii + (argv[0] + (progname_len - SHEBANG_EXE_PROGNAME_LENGTH), + SHEBANG_PROGNAME, + SHEBANG_PROGNAME_LENGTH))) + { + Wexttext **newarr = alloca_array (Wexttext *, argc + 2); + int j; + + newarr[0] = argv[0]; + newarr[1] = WEXTSTRING ("--script"); + for (j = 1; j < argc; ++j) + { + newarr[j + 1] = argv[j]; + } + argv = newarr; + argc++; + } + } + } + sort_args (argc, argv); #if 0 /* defined (_SCO_DS) @@ -1048,6 +1084,20 @@ noninteractive = 1; } + { + int count_before = skip_args; + /* Handle the -script switch, which implies batch and vanilla. The -l + part of its functionality is implemented in Lisp. */ + if (argmatch (argv, argc, "-script", "--script", 0, NULL, + &skip_args)) + { + noninteractive = 1; + vanilla_inhibiting = 1; + } + + /* Don't actually discard this argument. */ + skip_args = count_before; + } #ifdef WIN32_NATIVE { /* Since we aren't a console application, we can't easily be terminated @@ -2690,6 +2740,7 @@ { "-sd", "--show-dump-id", 105, 0 }, { "-nd", "--no-dump-file", 95, 0 }, { "-batch", "--batch", 88, 0 }, + { "-script", "--script", 89, 1 }, #ifdef WIN32_NATIVE { "-mswindows-termination-handle", 0, 84, 1 }, { "-nuni", "--no-unicode-lib-calls", 83, 0 },