summaryrefslogtreecommitdiffstats
path: root/script.c
diff options
context:
space:
mode:
Diffstat (limited to 'script.c')
-rw-r--r--script.c49
1 files changed, 37 insertions, 12 deletions
diff --git a/script.c b/script.c
index e1a63f1..efeaf5b 100644
--- a/script.c
+++ b/script.c
@@ -1,18 +1,18 @@
-/* Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
- *
+/* Copyright (C) 1994-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
* 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, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * the Free Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111, USA.
*
* As a special exception, the Free Software Foundation gives permission
* for additional uses of the text contained in its release of GUILE.
@@ -36,7 +36,7 @@
*
* 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.
+ * If you do not wish that, delete this exception notice.
*/
/* "script.c" argv tricks for `#!' scripts.
@@ -140,10 +140,13 @@ char *script_find_executable(name)
if (!f) return 0L;
if ((fgetc(f)=='#') && (fgetc(f)=='!')) {
while (1) switch (tbuf[i++] = fgetc(f)) {
- case /*WHITE_SPACES*/ ' ':case '\t':case '\r':case '\f':
+ case ' ':
+ if (1==i) {i--; break;}
+ case '\t':case '\r':case '\f':
case EOF:
tbuf[--i] = 0;
fclose(f);
+ if (0==i) return 0L;
return scm_cat_path(0L, tbuf, 0L);
}
}
@@ -172,7 +175,7 @@ char *dld_find_executable(file)
implementation-vicinity of this program. Returns a newly allocated
string if successful, 0 if not */
-char *scm_find_impl_file(exec_path, generic_name, initname, sep)
+char *find_impl_file(exec_path, generic_name, initname, sep)
char *exec_path;
const char *generic_name, *initname, *sep;
{
@@ -234,13 +237,35 @@ char *scm_find_impl_file(exec_path, generic_name, initname, sep)
for(peer="lib";!0;peer="src") {
path = scm_cat_path(0L, exec_path, sepind);
if (path) {
- strncpy(path + sepind - 4, "lib", 3);
+ strncpy(path + sepind - 4, peer, 3);
path = scm_cat_path(path, generic_name, 0L);
path = scm_sep_init_try(path, sep, initname);
if (path) return path;
}
if (!strcmp(peer,"src")) break;
- }}}
+ }}
+
+ /* Look for initname in executable-name peer directory. */
+ path = scm_cat_path(0L, exec_path, sepind);
+ if (path) {
+ path[sepind - 4] = 0;
+ path = scm_cat_path(path, &exec_path[sepind], 0L);
+ path = scm_sep_init_try(path, sep, initname);
+ if (path) return path;
+ }
+
+ if (generic_name) {
+
+ /* Look for initname in generic peer directory. */
+ path = scm_cat_path(0L, exec_path, sepind);
+ if (path) {
+ path[sepind - 4] = 0;
+ path = scm_cat_path(path, generic_name, 0L);
+ path = scm_sep_init_try(path, sep, initname);
+ if (path) return path;
+ }
+ }
+ }
#ifdef MSDOS
if (strlen(extptr)) {
@@ -367,8 +392,8 @@ char **script_process_argv(argc, argv)
if (!(nargv = (char **)realloc(nargv, (1 + ++nargc) * sizeof(char*))))
return 0L;
else nargv[nargi++] = narg;
- fclose(f);
- nargv[nargi++] = argv[argi++];
+ fclose(f);
+ nargv[nargi++] = argv[argi++];
}
}
while (argi <= argc) nargv[nargi++] = argv[argi++];