diff options
author | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2001-08-28 16:38:06 +0000 |
---|---|---|
committer | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2001-08-28 16:38:06 +0000 |
commit | fd346daffb1a4ec94a8a7b28d30efc37e2742f24 (patch) | |
tree | 1013e9930944ffb05d198d0cd4ade1c5573f00ce /mixguile/mixguile_cmd_dispatcher.c | |
parent | 6446df78afb4f3da2aa90e25b18b471fb272a8a9 (diff) | |
download | mdk-fd346daffb1a4ec94a8a7b28d30efc37e2742f24.tar.gz mdk-fd346daffb1a4ec94a8a7b28d30efc37e2742f24.tar.bz2 |
guile integration
Diffstat (limited to 'mixguile/mixguile_cmd_dispatcher.c')
-rw-r--r-- | mixguile/mixguile_cmd_dispatcher.c | 91 |
1 files changed, 66 insertions, 25 deletions
diff --git a/mixguile/mixguile_cmd_dispatcher.c b/mixguile/mixguile_cmd_dispatcher.c index 4676c43..b55d0ed 100644 --- a/mixguile/mixguile_cmd_dispatcher.c +++ b/mixguile/mixguile_cmd_dispatcher.c @@ -30,14 +30,56 @@ #include "mixguile.h" #include "xmixguile_cmd_dispatcher.h" +#define SCM_CMD "scm" +#define SCMF_CMD "scmf" + +/*local commands */ +static gboolean +cmd_scm_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) +{ + (void) gh_eval_str_with_catch ((char *)arg, scm_handle_by_message_noexit); + return TRUE; +} + +static gboolean +cmd_scmf_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) +{ + (void) gh_eval_file_with_catch ((char *)arg, scm_handle_by_message_noexit); + return TRUE; +} + +static mix_vm_command_info_t commands_[] = { + { SCM_CMD, cmd_scm_, N_("Eval Scheme command using Guile"), "scm COMMAND"}, + { SCMF_CMD, cmd_scmf_, N_("Eval Scheme file using Guile"), "scm PATH"}, + {NULL} +}; + /* create/destroy cmd dispatcher */ +static void +make_pipe_ (mixguile_cmd_dispatcher_t *dis) +{ + int fildes[2], r; + FILE *out; + r = pipe (fildes); + g_return_if_fail (r == 0); + out = fdopen (fildes[1], "w"); + g_return_if_fail (out != NULL); + r = fcntl (fildes[0], F_GETFL, 0); + g_return_if_fail (r != -1); + r = fcntl (fildes[0], F_SETFL, r | O_NONBLOCK); + g_return_if_fail (r != -1); + + dis->guile_out = out; + dis->fildes[0] = fildes[0]; + dis->fildes[1] = fildes[1]; +} + mixguile_cmd_dispatcher_t * mixguile_cmd_dispatcher_new (mix_vm_cmd_dispatcher_t *dis) { static gboolean REGISTERED = FALSE; mixguile_cmd_dispatcher_t *result = NULL; - int fildes[2], r; - FILE *out; + int k = 0; g_return_val_if_fail (dis != NULL, NULL); @@ -46,23 +88,19 @@ mixguile_cmd_dispatcher_new (mix_vm_cmd_dispatcher_t *dis) register_scm_commands_ (DEFAULT_SCM_COMMANDS_); REGISTERED = TRUE; } - - r = pipe (fildes); - g_return_val_if_fail (r == 0, NULL); - out = fdopen (fildes[1], "w"); - g_return_val_if_fail (out != NULL, NULL); - r = fcntl (fildes[0], F_GETFL, 0); - g_return_val_if_fail (r != -1, NULL); - r = fcntl (fildes[0], F_SETFL, r | O_NONBLOCK); - g_return_val_if_fail (r != -1, NULL); result = g_new (mixguile_cmd_dispatcher_t, 1); result->dispatcher = dis; result->err = result->out = NULL; - result->guile_out = out; - result->fildes[0] = fildes[0]; - result->fildes[1] = fildes[1]; result->result = NULL; + result->fildes[0] = result->fildes[1] = -1; + result->guile_out = NULL; + + while (commands_[k].name) + { + mix_vm_cmd_dispatcher_register_new (dis, commands_ + k); + ++k; + } register_cmd_dispatcher_ (result); @@ -74,9 +112,12 @@ void mixguile_cmd_dispatcher_delete (mixguile_cmd_dispatcher_t *dis) { g_return_if_fail (dis != NULL); - fclose (dis->guile_out); - close (dis->fildes[0]); - close (dis->fildes[1]); + if (dis->guile_out) + { + fclose (dis->guile_out); + close (dis->fildes[0]); + close (dis->fildes[1]); + } mix_vm_cmd_dispatcher_delete (dis->dispatcher); } @@ -99,6 +140,7 @@ mixguile_cmd_dispatcher_last_result (mixguile_cmd_dispatcher_t *dis) gchar *tmp = NULL; g_return_val_if_fail (dis != NULL, NULL); + if (!dis->guile_out) return NULL; if (dis->result) g_free (dis->result); dis->result = NULL; fflush (dis->guile_out); @@ -124,6 +166,7 @@ mixguile_cmd_dispatcher_last_result (mixguile_cmd_dispatcher_t *dis) static void prepare_dispatcher_ (mixguile_cmd_dispatcher_t *dis) { + if (!dis->guile_out) make_pipe_ (dis); dis->out = mix_vm_cmd_dispatcher_set_out_stream (dis->dispatcher, dis->guile_out); dis->err = mix_vm_cmd_dispatcher_set_error_stream (dis->dispatcher, @@ -137,14 +180,14 @@ mixguile_cmd_dispatcher_prepare (mixguile_cmd_dispatcher_t *dis) prepare_dispatcher_ (dis); } -/* interpret commands from file or string */ +/* interpret commands from file or string static void reset_dispatcher_ (mixguile_cmd_dispatcher_t *dis) { (void) mix_vm_cmd_dispatcher_set_out_stream (dis->dispatcher, dis->out); (void) mix_vm_cmd_dispatcher_set_error_stream (dis->dispatcher, dis->err); } - +*/ void mixguile_cmd_dispatcher_interpret_file (mixguile_cmd_dispatcher_t *dis, @@ -152,9 +195,8 @@ mixguile_cmd_dispatcher_interpret_file (mixguile_cmd_dispatcher_t *dis, { g_return_if_fail (dis != NULL); g_return_if_fail (path != NULL); - prepare_dispatcher_ (dis); - (void) gh_eval_file ((char *)path); - reset_dispatcher_ (dis); + mix_vm_cmd_dispatcher_dispatch_split_text (dis->dispatcher, + SCMF_CMD, path); } void @@ -163,8 +205,7 @@ mixguile_cmd_dispatcher_interpret_command (mixguile_cmd_dispatcher_t *dis, { g_return_if_fail (dis != NULL); g_return_if_fail (command != NULL); - prepare_dispatcher_ (dis); - (void) gh_eval_str ((char *)command); - reset_dispatcher_ (dis); + mix_vm_cmd_dispatcher_dispatch_split_text (dis->dispatcher, + SCM_CMD, command); } |