diff options
Diffstat (limited to 'libguile/script.c')
-rw-r--r-- | libguile/script.c | 177 |
1 files changed, 37 insertions, 140 deletions
diff --git a/libguile/script.c b/libguile/script.c index 63fbb0f3f..6430484a3 100644 --- a/libguile/script.c +++ b/libguile/script.c @@ -1,20 +1,21 @@ -/* Copyright (C) 1994-1998, 2000-2011, 2013, 2014 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 3 of - * the License, or (at your option) any later version. - * - * 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. - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ +/* Copyright 1994-1998,2000-2011,2013-2014,2018 + Free Software Foundation, Inc. + + This file is part of Guile. + + Guile 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 3 of the License, or + (at your option) any later version. + + Guile 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. + + You should have received a copy of the GNU Lesser General Public + License along with Guile. If not, see + <https://www.gnu.org/licenses/>. */ /* "script.c" argv tricks for `#!' scripts. Authors: Aubrey Jaffer and Jim Blandy */ @@ -23,92 +24,36 @@ # include <config.h> #endif +#include <ctype.h> +#include <errno.h> #include <localcharset.h> -#include <stdlib.h> #include <stdio.h> -#include <errno.h> -#include <ctype.h> -#include <uniconv.h> - -#include "libguile/_scm.h" -#include "libguile/eval.h" -#include "libguile/feature.h" -#include "libguile/load.h" -#include "libguile/read.h" -#include "libguile/script.h" -#include "libguile/strings.h" -#include "libguile/strports.h" -#include "libguile/validate.h" -#include "libguile/version.h" -#include "libguile/vm.h" - -#ifdef HAVE_STRING_H +#include <stdlib.h> #include <string.h> -#endif - +#include <uniconv.h> #include <unistd.h> /* for X_OK define */ #ifdef HAVE_IO_H #include <io.h> #endif -/* Concatentate str2 onto str1 at position n and return concatenated - string if file exists; 0 otherwise. */ - -static char * -scm_cat_path (char *str1, const char *str2, long n) -{ - if (!n) - n = strlen (str2); - if (str1) - { - size_t len = strlen (str1); - str1 = (char *) realloc (str1, (size_t) (len + n + 1)); - if (!str1) - return 0L; - strncat (str1 + len, str2, n); - return str1; - } - str1 = (char *) scm_malloc ((size_t) (n + 1)); - if (!str1) - return 0L; - str1[0] = 0; - strncat (str1, str2, n); - return str1; -} +#include "eval.h" +#include "feature.h" +#include "fluids.h" +#include "load.h" +#include "modules.h" +#include "pairs.h" +#include "read.h" +#include "strings.h" +#include "strports.h" +#include "throw.h" +#include "version.h" +#include "vm.h" -#if 0 -static char * -scm_try_path (char *path) -{ - FILE *f; - /* fprintf(stderr, "Trying %s\n", path);fflush(stderr); */ - if (!path) - return 0L; - SCM_SYSCALL (f = fopen (path, "r"); - ); - if (f) - { - fclose (f); - return path; - } - free (path); - return 0L; -} +#include "script.h" -static char * -scm_sep_init_try (char *path, const char *sep, const char *initname) -{ - if (path) - path = scm_cat_path (path, sep, 0L); - if (path) - path = scm_cat_path (path, initname, 0L); - return scm_try_path (path); -} -#endif -#ifndef LINE_INCREMENTORS -#define LINE_INCREMENTORS '\n' +#ifndef WHITE_SPACES #ifdef MSDOS #define WHITE_SPACES ' ':case '\t':case '\r':case '\f':case 26 #else @@ -116,48 +61,6 @@ scm_sep_init_try (char *path, const char *sep, const char *initname) #endif /* def MSDOS */ #endif /* ndef LINE_INCREMENTORS */ -#ifndef MAXPATHLEN -#define MAXPATHLEN 80 -#endif /* ndef MAXPATHLEN */ -#ifndef X_OK -#define X_OK 1 -#endif /* ndef X_OK */ - -char * -scm_find_executable (const char *name) -{ - char tbuf[MAXPATHLEN]; - int i = 0, c; - FILE *f; - - /* fprintf(stderr, "s_f_e checking access %s ->%d\n", name, access(name, X_OK)); fflush(stderr); */ - if (access (name, X_OK)) - return 0L; - f = fopen (name, "r"); - if (!f) - return 0L; - if ((fgetc (f) == '#') && (fgetc (f) == '!')) - { - while (1) - switch (c = fgetc (f)) - { - case /*WHITE_SPACES */ ' ': - case '\t': - case '\r': - case '\f': - case EOF: - tbuf[i] = 0; - fclose (f); - return scm_cat_path (0L, tbuf, 0L); - default: - tbuf[i++] = c; - break; - } - } - fclose (f); - return scm_cat_path (0L, name, 0L); -} - /* Read a \nnn-style escape. We've just read the backslash. */ static int @@ -459,11 +362,5 @@ scm_shell (int argc, char **argv) void scm_init_script () { -#include "libguile/script.x" +#include "script.x" } - -/* - Local Variables: - c-file-style: "gnu" - End: -*/ |