1 #include <bash/config.h>
2 #include <bash/builtins.h>
3 #include <bash/shell.h>
7 extern char **make_builtin_argv (WORD_LIST
*, int *);
9 struct guile_builtin_state
{
10 int argc
; /* Formed by `make_builtin_argv' in `guile_builtin' */
13 int retval
; /* Passed back from do_guile_builtin */
17 do_guile_builtin (void *data
)
19 struct guile_builtin_state
*state
= data
;
20 /* For Guile, argv[0] will be filename to be loaded. Not too useful, */
21 /* but it is all about minimizing C codebase */
22 scm_set_program_arguments(state
->argc
, state
->argv
, state
->filename
);
23 scm_c_primitive_load(state
->filename
);
24 state
->retval
= EXECUTION_SUCCESS
;
29 guile_builtin (WORD_LIST
*list
)
31 struct guile_builtin_state state
;
35 argv
= make_builtin_argv(list
, &argc
);
37 builtin_error("not enough arguments.");
39 return EXECUTION_FAILURE
;
41 state
.filename
= argv
[1];
42 state
.argc
= argc
- 2;
43 state
.argv
= argv
+ 2;
44 scm_with_guile(do_guile_builtin
, &state
);
49 static char* const guile_doc
[] = {
51 "Load Guile code from file with access to (gnu bash) module",
52 "to control Bash internals. Feel free to crash it all. ",
54 "Return code 0, unless exception is thrown",
58 struct builtin scm_struct
= {
60 .function
= guile_builtin
,
61 .flags
= BUILTIN_ENABLED
,
62 .long_doc
= guile_doc
,
63 .short_doc
= "scm FILENAME [ARGS ...]",