aboutsummaryrefslogtreecommitdiff
path: root/src/guile.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-05-20 06:30:39 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-05-20 06:30:39 +0300
commitc820e08d8ab56265450204fe374ef31c5d6259cd (patch)
treede9187ba6cf747c94786331e040b02ed7d441ca6 /src/guile.c
parent87e4f1eba3914c29467ed0f75bddc893a4ab0808 (diff)
downloadcfpeek-c820e08d8ab56265450204fe374ef31c5d6259cd.tar.gz
cfpeek-c820e08d8ab56265450204fe374ef31c5d6259cd.tar.bz2
Implement --expr
Diffstat (limited to 'src/guile.c')
-rw-r--r--src/guile.c55
1 files changed, 32 insertions, 23 deletions
diff --git a/src/guile.c b/src/guile.c
index 526055d..68b75a3 100644
--- a/src/guile.c
+++ b/src/guile.c
@@ -22,6 +22,7 @@ int guile_inited = 0;
int guile_debug = 1;
SCM_GLOBAL_VARIABLE_INIT (sym_cfpeek, "cfpeek", SCM_EOL);
+SCM_GLOBAL_VARIABLE_INIT (sym_node, "node", SCM_EOL);
static SCM
eval_catch_body(void *list)
@@ -422,9 +423,7 @@ SCM_DEFINE_PUBLIC(scm_grecs_node_value, "grecs-node-value",
void
guile_init()
{
- SCM proc;
-
- if (!script_file || script_expr)
+ if (!script_file && !script_expr)
return;
scm_init_guile();
@@ -449,23 +448,28 @@ guile_init()
"grecs-node-stmt",
"grecs-node-block", NULL);
- if (script_file && guile_load(script_file)) {
- grecs_error(NULL, 0,
- "cannot load script %s", script_file);
- exit(EX_UNAVAILABLE);
- }
+ if (script_file) {
+ SCM proc;
+
+ if (guile_load(script_file)) {
+ grecs_error(NULL, 0,
+ "cannot load script %s", script_file);
+ exit(EX_UNAVAILABLE);
+ }
- proc = SCM_VARIABLE_REF(sym_cfpeek);
- if (proc == SCM_EOL) {
- grecs_error(NULL, 0, "cfpeek not defined");
- exit(EX_CONFIG);
- }
+ proc = SCM_VARIABLE_REF(sym_cfpeek);
+ if (proc == SCM_EOL) {
+ grecs_error(NULL, 0, "cfpeek not defined");
+ exit(EX_CONFIG);
+ }
- if (scm_procedure_p(proc) != SCM_BOOL_T) {
- grecs_error(NULL, 0, "cfpeek is not a procedure object");
- exit(EX_CONFIG);
+ if (scm_procedure_p(proc) != SCM_BOOL_T) {
+ grecs_error(NULL, 0,
+ "cfpeek is not a procedure object");
+ exit(EX_CONFIG);
+ }
}
-
+
guile_inited = 1;
}
@@ -481,10 +485,15 @@ guile_apply(struct grecs_node *node)
if (setjmp(jmp_env))
grecs_error(NULL, 0, "cfpeek failed");
- cell = scm_cons(SCM_VARIABLE_REF(sym_cfpeek),
- scm_list_1(node_to_scm(node)));
- scm_c_catch(SCM_BOOL_T,
- eval_catch_body, cell,
- eval_catch_handler, &jmp_env,
- NULL, NULL);
+ if (script_expr) {
+ scm_c_define("node", node_to_scm(node));
+ scm_c_eval_string(script_expr);
+ } else {
+ cell = scm_cons(SCM_VARIABLE_REF(sym_cfpeek),
+ scm_list_1(node_to_scm(node)));
+ scm_c_catch(SCM_BOOL_T,
+ eval_catch_body, cell,
+ eval_catch_handler, &jmp_env,
+ NULL, NULL);
+ }
}

Return to:

Send suggestions and report system problems to the System administrator.