Mercurial > hg > xemacs-beta
comparison 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 |
comparison
equal
deleted
inserted
replaced
4408:8bbabcab2c42 | 4448:fd8a9a4d81d9 |
---|---|
953 /* prevent a very annoying problem where GCC will attempt to free (3) */ | 953 /* prevent a very annoying problem where GCC will attempt to free (3) */ |
954 /* memory at exit() and cause a coredump. */ | 954 /* memory at exit() and cause a coredump. */ |
955 init_free_hook (); | 955 init_free_hook (); |
956 #endif | 956 #endif |
957 | 957 |
958 #define SHEBANG_PROGNAME_LENGTH \ | |
959 (int)((sizeof (WEXTSTRING (SHEBANG_PROGNAME)) - sizeof (WEXTSTRING ("")))) | |
960 #define SHEBANG_EXE_PROGNAME_LENGTH \ | |
961 (int)(sizeof (WEXTSTRING (SHEBANG_PROGNAME ".exe")) \ | |
962 - sizeof (WEXTSTRING (""))) | |
963 | |
964 { | |
965 int progname_len = wext_strlen (argv[0]); | |
966 if (progname_len >= SHEBANG_PROGNAME_LENGTH) | |
967 { | |
968 if (!wext_strcmp_ascii (argv[0] + | |
969 (progname_len - SHEBANG_PROGNAME_LENGTH), | |
970 SHEBANG_PROGNAME) | |
971 /* Allow trailing .exe. Don't check it, it could also be | |
972 .com. */ | |
973 || (progname_len >= SHEBANG_EXE_PROGNAME_LENGTH && | |
974 !wext_strncmp_ascii | |
975 (argv[0] + (progname_len - SHEBANG_EXE_PROGNAME_LENGTH), | |
976 SHEBANG_PROGNAME, | |
977 SHEBANG_PROGNAME_LENGTH))) | |
978 { | |
979 Wexttext **newarr = alloca_array (Wexttext *, argc + 2); | |
980 int j; | |
981 | |
982 newarr[0] = argv[0]; | |
983 newarr[1] = WEXTSTRING ("--script"); | |
984 for (j = 1; j < argc; ++j) | |
985 { | |
986 newarr[j + 1] = argv[j]; | |
987 } | |
988 argv = newarr; | |
989 argc++; | |
990 } | |
991 } | |
992 } | |
993 | |
958 sort_args (argc, argv); | 994 sort_args (argc, argv); |
959 | 995 |
960 #if 0 /* defined (_SCO_DS) | 996 #if 0 /* defined (_SCO_DS) |
961 #### Turn this off, we already have another SCO_DS hack in main(). | 997 #### Turn this off, we already have another SCO_DS hack in main(). |
962 */ | 998 */ |
1046 inhibit_autoloads = 1; | 1082 inhibit_autoloads = 1; |
1047 #endif | 1083 #endif |
1048 noninteractive = 1; | 1084 noninteractive = 1; |
1049 } | 1085 } |
1050 | 1086 |
1087 { | |
1088 int count_before = skip_args; | |
1089 /* Handle the -script switch, which implies batch and vanilla. The -l | |
1090 part of its functionality is implemented in Lisp. */ | |
1091 if (argmatch (argv, argc, "-script", "--script", 0, NULL, | |
1092 &skip_args)) | |
1093 { | |
1094 noninteractive = 1; | |
1095 vanilla_inhibiting = 1; | |
1096 } | |
1097 | |
1098 /* Don't actually discard this argument. */ | |
1099 skip_args = count_before; | |
1100 } | |
1051 #ifdef WIN32_NATIVE | 1101 #ifdef WIN32_NATIVE |
1052 { | 1102 { |
1053 /* Since we aren't a console application, we can't easily be terminated | 1103 /* Since we aren't a console application, we can't easily be terminated |
1054 using ^C. (We aren't a console application to avoid Windows from | 1104 using ^C. (We aren't a console application to avoid Windows from |
1055 automatically and unwantedly creating a console window for us. If | 1105 automatically and unwantedly creating a console window for us. If |
2688 /* Handled by main_1 above: Each must have its own priority and must be | 2738 /* Handled by main_1 above: Each must have its own priority and must be |
2689 in the order mentioned in main_1. */ | 2739 in the order mentioned in main_1. */ |
2690 { "-sd", "--show-dump-id", 105, 0 }, | 2740 { "-sd", "--show-dump-id", 105, 0 }, |
2691 { "-nd", "--no-dump-file", 95, 0 }, | 2741 { "-nd", "--no-dump-file", 95, 0 }, |
2692 { "-batch", "--batch", 88, 0 }, | 2742 { "-batch", "--batch", 88, 0 }, |
2743 { "-script", "--script", 89, 1 }, | |
2693 #ifdef WIN32_NATIVE | 2744 #ifdef WIN32_NATIVE |
2694 { "-mswindows-termination-handle", 0, 84, 1 }, | 2745 { "-mswindows-termination-handle", 0, 84, 1 }, |
2695 { "-nuni", "--no-unicode-lib-calls", 83, 0 }, | 2746 { "-nuni", "--no-unicode-lib-calls", 83, 0 }, |
2696 #endif /* WIN32_NATIVE */ | 2747 #endif /* WIN32_NATIVE */ |
2697 { "-debug-paths", "--debug-paths", 82, 0 }, | 2748 { "-debug-paths", "--debug-paths", 82, 0 }, |