Commit | Line | Data |
---|---|---|
f2c9fcb0 | 1 | /* Copyright (C) 1995,1996,1998,1999, 2000 Free Software Foundation, Inc. |
0f2d19dd JB |
2 | * |
3 | * This program is free software; you can redistribute it and/or modify | |
4 | * it under the terms of the GNU General Public License as published by | |
5 | * the Free Software Foundation; either version 2, or (at your option) | |
6 | * any later version. | |
7 | * | |
8 | * This program is distributed in the hope that it will be useful, | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | * GNU General Public License for more details. | |
12 | * | |
13 | * You should have received a copy of the GNU General Public License | |
14 | * along with this software; see the file COPYING. If not, write to | |
82892bed JB |
15 | * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
16 | * Boston, MA 02111-1307 USA | |
0f2d19dd JB |
17 | * |
18 | * As a special exception, the Free Software Foundation gives permission | |
19 | * for additional uses of the text contained in its release of GUILE. | |
20 | * | |
21 | * The exception is that, if you link the GUILE library with other files | |
22 | * to produce an executable, this does not by itself cause the | |
23 | * resulting executable to be covered by the GNU General Public License. | |
24 | * Your use of that executable is in no way restricted on account of | |
25 | * linking the GUILE library code into it. | |
26 | * | |
27 | * This exception does not however invalidate any other reasons why | |
28 | * the executable file might be covered by the GNU General Public License. | |
29 | * | |
30 | * This exception applies only to the code released by the | |
31 | * Free Software Foundation under the name GUILE. If you copy | |
32 | * code from other Free Software Foundation releases into a copy of | |
33 | * GUILE, as the General Public License permits, the exception does | |
34 | * not apply to the code that you add in this way. To avoid misleading | |
35 | * anyone as to the status of such modified files, you must delete | |
36 | * this exception notice from them. | |
37 | * | |
38 | * If you write modifications of your own for GUILE, it is your choice | |
39 | * whether to permit this exception to apply to your modifications. | |
82892bed | 40 | * If you do not wish that, delete this exception notice. */ |
1bbd0b84 GB |
41 | |
42 | /* Software engineering face-lift by Greg J. Badros, 11-Dec-1999, | |
43 | gjb@cs.washington.edu, http://www.cs.washington.edu/homes/gjb */ | |
44 | ||
0f2d19dd JB |
45 | \f |
46 | ||
47 | #include <stdio.h> | |
a0599745 MD |
48 | #include "libguile/_scm.h" |
49 | #include "libguile/libpath.h" | |
50 | #include "libguile/fports.h" | |
51 | #include "libguile/read.h" | |
52 | #include "libguile/eval.h" | |
53 | #include "libguile/throw.h" | |
54 | #include "libguile/alist.h" | |
55 | #include "libguile/dynwind.h" | |
56 | #include "libguile/root.h" | |
57 | #include "libguile/strings.h" | |
f33b174d | 58 | #include "libguile/modules.h" |
a0599745 MD |
59 | |
60 | #include "libguile/validate.h" | |
61 | #include "libguile/load.h" | |
06721500 JB |
62 | |
63 | #include <sys/types.h> | |
64 | #include <sys/stat.h> | |
65 | ||
66 | #ifdef HAVE_UNISTD_H | |
67 | #include <unistd.h> | |
68 | #endif /* HAVE_UNISTD_H */ | |
69 | ||
70 | #ifndef R_OK | |
71 | #define R_OK 4 | |
72 | #endif | |
0f2d19dd JB |
73 | |
74 | \f | |
06721500 | 75 | /* Loading a file, given an absolute filename. */ |
0f2d19dd | 76 | |
26544b96 JB |
77 | /* Hook to run when we load a file, perhaps to announce the fact somewhere. |
78 | Applied to the full name of the file. */ | |
79 | static SCM *scm_loc_load_hook; | |
80 | ||
c7023c69 | 81 | static void |
d7834b91 MD |
82 | swap_port (void *data) |
83 | { | |
84 | SCM *save_port = data, tmp = scm_cur_loadp; | |
85 | scm_cur_loadp = *save_port; | |
86 | *save_port = tmp; | |
87 | } | |
88 | ||
89 | static SCM | |
90 | load (void *data) | |
91 | { | |
54778cd3 | 92 | SCM port = SCM_PACK (data); |
d7834b91 MD |
93 | while (1) |
94 | { | |
54778cd3 | 95 | SCM form = scm_read (port); |
d7834b91 MD |
96 | if (SCM_EOF_OBJECT_P (form)) |
97 | break; | |
f33b174d MD |
98 | /* Ugh! We need to re-check the environment for every form. |
99 | * We should change this in the new module system. | |
100 | */ | |
101 | scm_i_eval_x (form, | |
102 | scm_module_system_booted_p | |
103 | ? (scm_top_level_env | |
104 | (SCM_MODULE_EVAL_CLOSURE (scm_selected_module ()))) | |
105 | : SCM_EOL); | |
d7834b91 MD |
106 | } |
107 | return SCM_UNSPECIFIED; | |
108 | } | |
109 | ||
3b3b36dd | 110 | SCM_DEFINE (scm_primitive_load, "primitive-load", 1, 0, 0, |
1bbd0b84 | 111 | (SCM filename), |
b380b885 MD |
112 | "Load @var{file} and evaluate its contents in the top-level environment.\n" |
113 | "The load paths are not searched; @var{file} must either be a full\n" | |
114 | "pathname or be a pathname relative to the current directory. If the\n" | |
115 | "variable @code{%load-hook} is defined, it should be bound to a procedure\n" | |
116 | "that will be called before any code is loaded. See documentation for\n" | |
117 | "@code{%load-hook} later in this section.") | |
1bbd0b84 | 118 | #define FUNC_NAME s_scm_primitive_load |
0f2d19dd | 119 | { |
26544b96 | 120 | SCM hook = *scm_loc_load_hook; |
3b3b36dd | 121 | SCM_VALIDATE_ROSTRING (1,filename); |
9a09deb1 | 122 | SCM_ASSERT (SCM_FALSEP (hook) || (SCM_EQ_P (scm_procedure_p (hook), SCM_BOOL_T)), |
26544b96 | 123 | hook, "value of %load-hook is neither a procedure nor #f", |
1bbd0b84 | 124 | FUNC_NAME); |
26544b96 | 125 | |
54778cd3 | 126 | if (! SCM_FALSEP (hook)) |
26544b96 JB |
127 | scm_apply (hook, scm_listify (filename, SCM_UNDEFINED), SCM_EOL); |
128 | ||
1bbd0b84 | 129 | { /* scope */ |
d7834b91 | 130 | SCM port, save_port; |
0f2d19dd JB |
131 | port = scm_open_file (filename, |
132 | scm_makfromstr ("r", (scm_sizet) sizeof (char), 0)); | |
d7834b91 MD |
133 | save_port = port; |
134 | scm_internal_dynamic_wind (swap_port, | |
135 | load, | |
136 | swap_port, | |
54778cd3 | 137 | (void *) SCM_UNPACK (port), |
d7834b91 | 138 | &save_port); |
0f2d19dd JB |
139 | scm_close_port (port); |
140 | } | |
b59b97ba | 141 | return SCM_UNSPECIFIED; |
0f2d19dd | 142 | } |
1bbd0b84 | 143 | #undef FUNC_NAME |
0f2d19dd JB |
144 | |
145 | \f | |
3feedb00 MD |
146 | /* Builtin path to scheme library files. */ |
147 | #ifdef SCM_PKGDATA_DIR | |
a1ec6916 | 148 | SCM_DEFINE (scm_sys_package_data_dir, "%package-data-dir", 0, 0, 0, |
1bbd0b84 | 149 | (), |
b380b885 MD |
150 | "Return the name of the directory where Scheme packages, modules and\n" |
151 | "libraries are kept. On most Unix systems, this will be\n" | |
152 | "@samp{/usr/local/share/guile}.") | |
1bbd0b84 | 153 | #define FUNC_NAME s_scm_sys_package_data_dir |
3feedb00 MD |
154 | { |
155 | return scm_makfrom0str (SCM_PKGDATA_DIR); | |
156 | } | |
1bbd0b84 | 157 | #undef FUNC_NAME |
3feedb00 MD |
158 | #endif /* SCM_PKGDATA_DIR */ |
159 | ||
e8e9b690 | 160 | #ifdef SCM_LIBRARY_DIR |
a1ec6916 | 161 | SCM_DEFINE (scm_sys_library_dir, "%library-dir", 0,0,0, |
e8e9b690 | 162 | (), |
b380b885 MD |
163 | "Return the directory where the Guile Scheme library files are installed.\n" |
164 | "E.g., may return \"/usr/share/guile/1.3.5\".") | |
e8e9b690 GB |
165 | #define FUNC_NAME s_scm_sys_library_dir |
166 | { | |
167 | return scm_makfrom0str(SCM_LIBRARY_DIR); | |
168 | } | |
169 | #undef FUNC_NAME | |
170 | #endif /* SCM_LIBRARY_DIR */ | |
171 | ||
172 | #ifdef SCM_SITE_DIR | |
a1ec6916 | 173 | SCM_DEFINE (scm_sys_site_dir, "%site-dir", 0,0,0, |
e8e9b690 | 174 | (), |
b380b885 MD |
175 | "Return the directory where the Guile site files are installed.\n" |
176 | "E.g., may return \"/usr/share/guile/site\".") | |
e8e9b690 GB |
177 | #define FUNC_NAME s_scm_sys_site_dir |
178 | { | |
179 | return scm_makfrom0str(SCM_SITE_DIR); | |
180 | } | |
181 | #undef FUNC_NAME | |
182 | #endif /* SCM_SITE_DIR */ | |
183 | ||
184 | ||
185 | ||
3feedb00 | 186 | \f |
06721500 | 187 | /* Initializing the load path, and searching it. */ |
0f2d19dd | 188 | |
26544b96 | 189 | /* List of names of directories we search for files to load. */ |
06721500 JB |
190 | static SCM *scm_loc_load_path; |
191 | ||
26544b96 JB |
192 | /* List of extensions we try adding to the filenames. */ |
193 | static SCM *scm_loc_load_extensions; | |
194 | ||
01cddfc1 JB |
195 | |
196 | /* Parse the null-terminated string PATH as if it were a standard path | |
197 | environment variable (i.e. a colon-separated list of strings), and | |
198 | prepend the elements to TAIL. */ | |
199 | SCM | |
04e8fb0a | 200 | scm_internal_parse_path (char *path, SCM tail) |
01cddfc1 JB |
201 | { |
202 | if (path && path[0] != '\0') | |
203 | { | |
204 | char *scan, *elt_end; | |
205 | ||
206 | /* Scan backwards from the end of the string, to help | |
207 | construct the list in the right order. */ | |
208 | scan = elt_end = path + strlen (path); | |
209 | do { | |
210 | /* Scan back to the beginning of the current element. */ | |
211 | do scan--; | |
212 | while (scan >= path && *scan != ':'); | |
213 | tail = scm_cons (scm_makfromstr (scan + 1, elt_end - (scan + 1), 0), | |
214 | tail); | |
215 | elt_end = scan; | |
216 | } while (scan >= path); | |
217 | } | |
218 | ||
219 | return tail; | |
220 | } | |
221 | ||
222 | ||
a1ec6916 | 223 | SCM_DEFINE (scm_parse_path, "parse-path", 1, 1, 0, |
1bbd0b84 | 224 | (SCM path, SCM tail), |
b380b885 | 225 | "") |
1bbd0b84 | 226 | #define FUNC_NAME s_scm_parse_path |
04e8fb0a | 227 | { |
0c95b57d | 228 | SCM_ASSERT (SCM_FALSEP (path) || (SCM_ROSTRINGP (path)), |
04e8fb0a | 229 | path, |
1bbd0b84 | 230 | SCM_ARG1, FUNC_NAME); |
04e8fb0a MD |
231 | if (SCM_UNBNDP (tail)) |
232 | tail = SCM_EOL; | |
233 | return (SCM_FALSEP (path) | |
234 | ? tail | |
235 | : scm_internal_parse_path (SCM_ROCHARS (path), tail)); | |
236 | } | |
1bbd0b84 | 237 | #undef FUNC_NAME |
04e8fb0a MD |
238 | |
239 | ||
06721500 | 240 | /* Initialize the global variable %load-path, given the value of the |
3feedb00 | 241 | SCM_SITE_DIR and SCM_LIBRARY_DIR preprocessor symbols and the |
01cddfc1 | 242 | GUILE_LOAD_PATH environment variable. */ |
0f2d19dd | 243 | void |
06721500 JB |
244 | scm_init_load_path () |
245 | { | |
246 | SCM path = SCM_EOL; | |
247 | ||
3feedb00 | 248 | #ifdef SCM_LIBRARY_DIR |
55407879 TP |
249 | path = scm_listify (scm_makfrom0str (SCM_SITE_DIR), |
250 | scm_makfrom0str (SCM_LIBRARY_DIR), | |
251 | scm_makfrom0str (SCM_PKGDATA_DIR), | |
252 | SCM_UNDEFINED); | |
3feedb00 | 253 | #endif /* SCM_LIBRARY_DIR */ |
06721500 | 254 | |
04e8fb0a | 255 | path = scm_internal_parse_path (getenv ("GUILE_LOAD_PATH"), path); |
01cddfc1 | 256 | |
06721500 JB |
257 | *scm_loc_load_path = path; |
258 | } | |
259 | ||
04e8fb0a | 260 | SCM scm_listofnullstr; |
06721500 | 261 | |
04e8fb0a | 262 | /* Search PATH for a directory containing a file named FILENAME. |
06721500 | 263 | The file must be readable, and not a directory. |
26544b96 | 264 | If we find one, return its full filename; otherwise, return #f. |
56384176 JB |
265 | If FILENAME is absolute, return it unchanged. |
266 | If given, EXTENSIONS is a list of strings; for each directory | |
267 | in PATH, we search for FILENAME concatenated with each EXTENSION. */ | |
3b3b36dd | 268 | SCM_DEFINE (scm_search_path, "search-path", 2, 1, 0, |
1bbd0b84 | 269 | (SCM path, SCM filename, SCM extensions), |
b380b885 | 270 | "") |
1bbd0b84 | 271 | #define FUNC_NAME s_scm_search_path |
06721500 | 272 | { |
56384176 | 273 | char *filename_chars; |
06721500 | 274 | int filename_len; |
56384176 JB |
275 | size_t max_path_len; /* maximum length of any PATH element */ |
276 | size_t max_ext_len; /* maximum length of any EXTENSIONS element */ | |
06721500 | 277 | |
3b3b36dd GB |
278 | SCM_VALIDATE_LIST (1,path); |
279 | SCM_VALIDATE_ROSTRING (2,filename); | |
04e8fb0a | 280 | if (SCM_UNBNDP (extensions)) |
56384176 | 281 | extensions = SCM_EOL; |
04e8fb0a | 282 | else |
3b3b36dd | 283 | SCM_VALIDATE_LIST (3,extensions); |
56384176 JB |
284 | |
285 | filename_chars = SCM_ROCHARS (filename); | |
06721500 JB |
286 | filename_len = SCM_ROLENGTH (filename); |
287 | ||
26544b96 | 288 | /* If FILENAME is absolute, return it unchanged. */ |
56384176 | 289 | if (filename_len >= 1 && filename_chars[0] == '/') |
26544b96 JB |
290 | return filename; |
291 | ||
292 | /* Find the length of the longest element of path. */ | |
293 | { | |
294 | SCM walk; | |
295 | ||
296 | max_path_len = 0; | |
2de14ecd | 297 | for (walk = path; SCM_NNULLP (walk); walk = SCM_CDR (walk)) |
26544b96 JB |
298 | { |
299 | SCM elt = SCM_CAR (walk); | |
0c95b57d | 300 | SCM_ASSERT (SCM_ROSTRINGP (elt), elt, |
04e8fb0a | 301 | "path is not a list of strings", |
1bbd0b84 | 302 | FUNC_NAME); |
0a74e31d MD |
303 | if (SCM_ROLENGTH (elt) > max_path_len) |
304 | max_path_len = SCM_ROLENGTH (elt); | |
26544b96 JB |
305 | } |
306 | } | |
307 | ||
56384176 JB |
308 | /* If FILENAME has an extension, don't try to add EXTENSIONS to it. */ |
309 | { | |
310 | char *endp; | |
311 | ||
312 | for (endp = filename_chars + filename_len - 1; | |
313 | endp >= filename_chars; | |
314 | endp--) | |
315 | { | |
316 | if (*endp == '.') | |
317 | { | |
318 | /* This filename already has an extension, so cancel the | |
319 | list of extensions. */ | |
320 | extensions = SCM_EOL; | |
321 | break; | |
322 | } | |
323 | else if (*endp == '/') | |
324 | /* This filename has no extension, so keep the current list | |
325 | of extensions. */ | |
326 | break; | |
327 | } | |
328 | } | |
329 | ||
26544b96 JB |
330 | /* Find the length of the longest element of the load extensions |
331 | list. */ | |
1bbd0b84 | 332 | { /* scope */ |
26544b96 JB |
333 | SCM walk; |
334 | ||
335 | max_ext_len = 0; | |
2de14ecd | 336 | for (walk = extensions; SCM_NNULLP (walk); walk = SCM_CDR (walk)) |
26544b96 JB |
337 | { |
338 | SCM elt = SCM_CAR (walk); | |
0c95b57d | 339 | SCM_ASSERT (SCM_ROSTRINGP (elt), elt, |
04e8fb0a | 340 | "extension list is not a list of strings", |
1bbd0b84 | 341 | FUNC_NAME); |
0a74e31d MD |
342 | if (SCM_ROLENGTH (elt) > max_ext_len) |
343 | max_ext_len = SCM_ROLENGTH (elt); | |
26544b96 JB |
344 | } |
345 | } | |
346 | ||
06721500 JB |
347 | SCM_DEFER_INTS; |
348 | ||
1bbd0b84 | 349 | { /* scope */ |
56384176 JB |
350 | SCM result = SCM_BOOL_F; |
351 | int buf_size = max_path_len + 1 + filename_len + max_ext_len + 1; | |
1bbd0b84 | 352 | char *buf = SCM_MUST_MALLOC (buf_size); |
06721500 | 353 | |
56384176 JB |
354 | /* This simplifies the loop below a bit. */ |
355 | if (SCM_NULLP (extensions)) | |
356 | extensions = scm_listofnullstr; | |
0a74e31d | 357 | |
56384176 JB |
358 | /* Try every path element. At this point, we know the path is a |
359 | proper list of strings. */ | |
2de14ecd | 360 | for (; SCM_NNULLP (path); path = SCM_CDR (path)) |
56384176 JB |
361 | { |
362 | int len; | |
363 | SCM dir = SCM_CAR (path); | |
364 | SCM exts; | |
365 | ||
366 | /* Concatenate the path name and the filename. */ | |
367 | len = SCM_ROLENGTH (dir); | |
368 | memcpy (buf, SCM_ROCHARS (dir), len); | |
369 | if (len >= 1 && buf[len - 1] != '/') | |
370 | buf[len++] = '/'; | |
371 | memcpy (buf + len, filename_chars, filename_len); | |
372 | len += filename_len; | |
373 | ||
374 | /* Try every extension. At this point, we know the extension | |
375 | list is a proper, nonempty list of strings. */ | |
2de14ecd | 376 | for (exts = extensions; SCM_NNULLP (exts); exts = SCM_CDR (exts)) |
56384176 JB |
377 | { |
378 | SCM ext = SCM_CAR (exts); | |
379 | int ext_len = SCM_ROLENGTH (ext); | |
380 | struct stat mode; | |
381 | ||
382 | /* Concatenate the extension. */ | |
383 | memcpy (buf + len, SCM_ROCHARS (ext), ext_len); | |
384 | buf[len + ext_len] = '\0'; | |
385 | ||
386 | /* If the file exists at all, we should return it. If the | |
387 | file is inaccessible, then that's an error. */ | |
388 | if (stat (buf, &mode) == 0 | |
389 | && ! (mode.st_mode & S_IFDIR)) | |
390 | { | |
391 | result = scm_makfromstr (buf, len + ext_len, 0); | |
392 | goto end; | |
393 | } | |
394 | } | |
395 | } | |
396 | ||
397 | end: | |
398 | scm_must_free (buf); | |
399 | scm_done_malloc (- buf_size); | |
400 | SCM_ALLOW_INTS; | |
401 | return result; | |
402 | } | |
06721500 | 403 | } |
1bbd0b84 | 404 | #undef FUNC_NAME |
06721500 JB |
405 | |
406 | ||
04e8fb0a MD |
407 | /* Search %load-path for a directory containing a file named FILENAME. |
408 | The file must be readable, and not a directory. | |
409 | If we find one, return its full filename; otherwise, return #f. | |
410 | If FILENAME is absolute, return it unchanged. */ | |
3b3b36dd | 411 | SCM_DEFINE (scm_sys_search_load_path, "%search-load-path", 1, 0, 0, |
1bbd0b84 | 412 | (SCM filename), |
b380b885 MD |
413 | "Search @var{%load-path} for @var{file}, which must be readable by the\n" |
414 | "current user. If @var{file} is found in the list of paths to search or\n" | |
415 | "is an absolute pathname, return its full pathname. Otherwise, return\n" | |
416 | "@code{#f}. Filenames may have any of the optional extensions in the\n" | |
417 | "@code{%load-extensions} list; @code{%search-load-path} will try each\n" | |
418 | "extension automatically.") | |
1bbd0b84 | 419 | #define FUNC_NAME s_scm_sys_search_load_path |
04e8fb0a MD |
420 | { |
421 | SCM path = *scm_loc_load_path; | |
422 | SCM exts = *scm_loc_load_extensions; | |
3b3b36dd | 423 | SCM_VALIDATE_ROSTRING (1,filename); |
1bbd0b84 | 424 | |
04e8fb0a | 425 | SCM_ASSERT (scm_ilength (path) >= 0, path, "load path is not a proper list", |
1bbd0b84 | 426 | FUNC_NAME); |
04e8fb0a MD |
427 | SCM_ASSERT (scm_ilength (exts) >= 0, exts, |
428 | "load extension list is not a proper list", | |
1bbd0b84 GB |
429 | FUNC_NAME); |
430 | return scm_search_path (path, filename, exts); | |
04e8fb0a | 431 | } |
1bbd0b84 | 432 | #undef FUNC_NAME |
04e8fb0a MD |
433 | |
434 | ||
3b3b36dd | 435 | SCM_DEFINE (scm_primitive_load_path, "primitive-load-path", 1, 0, 0, |
1bbd0b84 | 436 | (SCM filename), |
b380b885 MD |
437 | "Search @var{%load-path} for @var{file} and load it into the top-level\n" |
438 | "environment. If @var{file} is a relative pathname and is not found in\n" | |
439 | "the list of search paths, an error is signalled.") | |
1bbd0b84 | 440 | #define FUNC_NAME s_scm_primitive_load_path |
06721500 | 441 | { |
26544b96 JB |
442 | SCM full_filename; |
443 | ||
3b3b36dd | 444 | SCM_VALIDATE_ROSTRING (1,filename); |
26544b96 JB |
445 | |
446 | full_filename = scm_sys_search_load_path (filename); | |
447 | ||
dbece3a2 GH |
448 | if (SCM_FALSEP (full_filename)) |
449 | { | |
0a74e31d | 450 | int absolute = (SCM_ROLENGTH (filename) >= 1 |
26544b96 | 451 | && SCM_ROCHARS (filename)[0] == '/'); |
5d2d2ffc | 452 | SCM_MISC_ERROR ((absolute |
70d63753 GB |
453 | ? "Unable to load file ~S" |
454 | : "Unable to find file ~S in load path"), | |
26544b96 | 455 | scm_listify (filename, SCM_UNDEFINED)); |
dbece3a2 | 456 | } |
26544b96 | 457 | |
deca31e1 | 458 | return scm_primitive_load (full_filename); |
06721500 | 459 | } |
1bbd0b84 | 460 | #undef FUNC_NAME |
06721500 | 461 | |
f33b174d MD |
462 | #if SCM_DEBUG_DEPRECATED == 0 |
463 | ||
464 | /* Eval now copies source properties, so this function is no longer required. | |
b35d06a4 MD |
465 | */ |
466 | ||
467 | SCM_SYMBOL (scm_end_of_file_key, "end-of-file"); | |
468 | ||
a1ec6916 | 469 | SCM_DEFINE (scm_read_and_eval_x, "read-and-eval!", 0, 1, 0, |
1bbd0b84 | 470 | (SCM port), |
b380b885 MD |
471 | "Read a form from @var{port} (standard input by default), and evaluate it\n" |
472 | "(memoizing it in the process) in the top-level environment. If no data\n" | |
473 | "is left to be read from @var{port}, an @code{end-of-file} error is\n" | |
474 | "signalled.") | |
1bbd0b84 | 475 | #define FUNC_NAME s_scm_read_and_eval_x |
b35d06a4 | 476 | { |
deca31e1 | 477 | SCM form = scm_read (port); |
0c32d76c | 478 | if (SCM_EOF_OBJECT_P (form)) |
b35d06a4 | 479 | scm_ithrow (scm_end_of_file_key, SCM_EOL, 1); |
f33b174d | 480 | return scm_eval_x (form, scm_selected_module ()); |
b35d06a4 | 481 | } |
1bbd0b84 | 482 | #undef FUNC_NAME |
b35d06a4 | 483 | |
f33b174d MD |
484 | #endif |
485 | ||
06721500 | 486 | \f |
e151bee6 | 487 | /* Information about the build environment. */ |
06721500 | 488 | |
e151bee6 JB |
489 | /* Initialize the scheme variable %guile-build-info, based on data |
490 | provided by the Makefile, via libpath.h. */ | |
491 | static void | |
492 | init_build_info () | |
493 | { | |
494 | static struct { char *name; char *value; } info[] = SCM_BUILD_INFO; | |
495 | SCM *loc = SCM_CDRLOC (scm_sysintern ("%guile-build-info", SCM_EOL)); | |
c7023c69 | 496 | unsigned int i; |
e151bee6 JB |
497 | |
498 | for (i = 0; i < (sizeof (info) / sizeof (info[0])); i++) | |
499 | *loc = scm_acons (SCM_CAR (scm_intern0 (info[i].name)), | |
500 | scm_makfrom0str (info[i].value), | |
501 | *loc); | |
502 | } | |
503 | ||
504 | ||
505 | \f | |
0f2d19dd JB |
506 | void |
507 | scm_init_load () | |
0f2d19dd | 508 | { |
04e8fb0a MD |
509 | scm_listofnullstr = scm_permanent_object (SCM_LIST1 (scm_nullstr)); |
510 | scm_loc_load_path = SCM_CDRLOC (scm_sysintern ("%load-path", SCM_EOL)); | |
26544b96 | 511 | scm_loc_load_extensions |
04e8fb0a | 512 | = SCM_CDRLOC (scm_sysintern ("%load-extensions", |
0a74e31d MD |
513 | scm_listify (scm_makfrom0str (".scm"), |
514 | scm_makfrom0str (""), | |
04e8fb0a MD |
515 | SCM_UNDEFINED))); |
516 | scm_loc_load_hook = SCM_CDRLOC (scm_sysintern ("%load-hook", SCM_BOOL_F)); | |
06721500 | 517 | |
e151bee6 JB |
518 | init_build_info (); |
519 | ||
a0599745 | 520 | #include "libguile/load.x" |
0f2d19dd | 521 | } |
89e00824 ML |
522 | |
523 | /* | |
524 | Local Variables: | |
525 | c-file-style: "gnu" | |
526 | End: | |
527 | */ |