Fix compiler warning
[guile-bash.git] / src / scm.c
blob07a26a7046acc27be99fccc2f00796a43fd19226
1 #include <bash/config.h>
2 #include <bash/builtins.h>
3 #include <bash/shell.h>
4 #include <stdio.h>
5 #include <libguile.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' */
11 char *filename;
12 char **argv;
13 int retval; /* Passed back from do_guile_builtin */
16 static void*
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;
25 return NULL;
28 static int
29 guile_builtin (WORD_LIST *list)
31 struct guile_builtin_state state;
32 int argc;
33 char **argv;
35 argv = make_builtin_argv(list, &argc);
36 if (argc < 2) {
37 builtin_error("not enough arguments.");
38 builtin_usage();
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);
46 return state.retval;
49 static char* const guile_doc[] = {
50 "",
51 "Load Guile code from file with access to (gnu bash) module",
52 "to control Bash internals. Feel free to crash it all. ",
53 "",
54 "Return code 0, unless exception is thrown",
55 NULL
58 struct builtin scm_struct = {
59 .name = "scm",
60 .function = guile_builtin,
61 .flags = BUILTIN_ENABLED,
62 .long_doc = guile_doc,
63 .short_doc = "scm FILENAME [ARGS ...]",
64 .handle = NULL