summaryrefslogtreecommitdiffhomepage
path: root/mixguile/xmixguile_cmd_dispatcher.c
diff options
context:
space:
mode:
Diffstat (limited to 'mixguile/xmixguile_cmd_dispatcher.c')
-rw-r--r--mixguile/xmixguile_cmd_dispatcher.c91
1 files changed, 62 insertions, 29 deletions
diff --git a/mixguile/xmixguile_cmd_dispatcher.c b/mixguile/xmixguile_cmd_dispatcher.c
index 5590e5f..3e357a2 100644
--- a/mixguile/xmixguile_cmd_dispatcher.c
+++ b/mixguile/xmixguile_cmd_dispatcher.c
@@ -76,12 +76,10 @@ mixvm_cmd_ (SCM cmd, SCM arg)
argu);
g_free (com);
g_free (argu);
- com = (char *) mixguile_cmd_dispatcher_last_result (dispatcher_);
+
SCM_ALLOW_INTS;
- if (!com || strlen (com) == 0)
- return gh_symbol2scm (result? "ok" : "fail");
- return gh_str02scm (com);
+ return SCM_UNSPECIFIED;
}
static long
@@ -268,24 +266,10 @@ mix_set_cmp_ (SCM value)
}
static SCM
-mix_basename_ (const gchar *path)
-{
- SCM result;
- gchar *name;
- if (!path) return gh_str02scm ("");
- SCM_DEFER_INTS;
- name = g_basename (path);
- result = gh_str02scm (name);
- g_free (name);
- SCM_ALLOW_INTS;
- return gh_str02scm (name);
-}
-
-static SCM
mix_src_name_ (void)
{
- return
- mix_basename_ (mix_vm_cmd_dispatcher_get_src_file_path (vm_dispatcher_));
+ const gchar *path = mix_vm_cmd_dispatcher_get_src_file_path (vm_dispatcher_);
+ return gh_str02scm (path? g_basename (path) : "");
}
static SCM
@@ -298,8 +282,8 @@ mix_src_path_ (void)
static SCM
mix_prog_name_ (void)
{
- return
- mix_basename_ (mix_vm_cmd_dispatcher_get_program_path (vm_dispatcher_));
+ const gchar *path = mix_vm_cmd_dispatcher_get_program_path (vm_dispatcher_);
+ return gh_str02scm (path? g_basename (path) : "");
}
static SCM
@@ -309,6 +293,29 @@ mix_prog_path_ (void)
return gh_str02scm (path? (char *)path : "");
}
+static SCM
+mix_ddir_ (void)
+{
+ return gh_str02scm ((char *)mix_device_get_dir ());
+}
+
+static SCM
+mix_uptime_ (void)
+{
+ return gh_long2scm (mix_vm_cmd_dispatcher_get_uptime (vm_dispatcher_));
+}
+
+static SCM
+mix_progtime_ (void)
+{
+ return gh_long2scm (mix_vm_cmd_dispatcher_get_progtime (vm_dispatcher_));
+}
+
+static SCM
+mix_laptime_ (void)
+{
+ return gh_long2scm (mix_vm_cmd_dispatcher_get_laptime (vm_dispatcher_));
+}
/* ----- hook functions ---- */
@@ -317,7 +324,7 @@ static SCM
make_arg_list_ (const gchar *arg)
{
gchar **arglist = g_strsplit (arg, " ", -1);
- SCM argument = gh_list (SCM_UNDEFINED);
+ SCM argument = gh_list (SCM_UNDEFINED, SCM_EOL);
if (arglist && arglist[0])
{
int k = 0;
@@ -352,7 +359,12 @@ scm_hook_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg, gpointer data)
{
hook_data_t h;
h.function = (SCM) data;
+
+ g_assert (gh_procedure_p (h.function));
+
h.args = make_arg_list_ (arg);
+ g_assert (gh_list_p (h.args));
+
gh_catch (SCM_BOOL_T, hook_catch_body_, &h,
scm_handle_by_message_noexit, dis);
}
@@ -385,6 +397,18 @@ scm_global_hook_ (mix_vm_cmd_dispatcher_t *dis, mix_vm_command_t cmd,
}
static SCM
+define_hook_procedure_ (SCM function)
+{
+ enum {BUFF_SIZE = 128};
+ static gchar BUFFER[BUFF_SIZE];
+ static const gchar *PATTERN = "____mix__hook__%d____";
+ static int K = 0;
+ snprintf (BUFFER, BUFF_SIZE, PATTERN, K++);
+ /* gh_define (name, val) returns a pair: (symbol . symbol-value) */
+ return gh_cdr (gh_define ((char *)BUFFER, function));
+}
+
+static SCM
mix_add_hook_ (SCM cmd, SCM function, gboolean pre)
{
gchar *cmdstr = NULL;
@@ -402,11 +426,13 @@ mix_add_hook_ (SCM cmd, SCM function, gboolean pre)
SCM_ASSERT (command != MIX_CMD_INVALID, cmd, SCM_ARG1, fun);
SCM_DEFER_INTS;
if (pre)
- mix_vm_cmd_dispatcher_pre_hook (vm_dispatcher_, command,
- scm_hook_, (gpointer) function);
+ mix_vm_cmd_dispatcher_pre_hook (vm_dispatcher_, command, scm_hook_,
+ (gpointer)
+ define_hook_procedure_ (function));
else
- mix_vm_cmd_dispatcher_post_hook (vm_dispatcher_, command,
- scm_hook_, (gpointer) function);
+ mix_vm_cmd_dispatcher_post_hook (vm_dispatcher_, command, scm_hook_,
+ (gpointer)
+ define_hook_procedure_ (function));
SCM_ALLOW_INTS;
return gh_symbol2scm ("ok");
}
@@ -421,10 +447,12 @@ mix_add_global_hook_ (SCM function, gboolean pre)
SCM_DEFER_INTS;
if (pre)
mix_vm_cmd_dispatcher_global_pre_hook (vm_dispatcher_, scm_global_hook_,
- (gpointer) function);
+ (gpointer)
+ define_hook_procedure_ (function));
else
mix_vm_cmd_dispatcher_global_post_hook (vm_dispatcher_, scm_global_hook_,
- (gpointer) function);
+ (gpointer)
+ define_hook_procedure_ (function));
SCM_ALLOW_INTS;
return gh_symbol2scm ("ok");
}
@@ -464,10 +492,15 @@ const scm_command_t DEFAULT_SCM_COMMANDS_[] = {
{"mix-loc", mix_loc_, 0, 0, 0},
{"mix-set-over!", mix_set_over_, 1, 0, 0},
{"mix-cmp", mix_cmp_, 0, 0, 0},
+ {"mix-up-time", mix_uptime_, 0, 0, 0},
+ {"mix-lap-time", mix_laptime_, 0, 0, 0},
+ {"mix-prog-time", mix_progtime_, 0, 0, 0},
{"mix-prog-name", mix_prog_name_, 0, 0, 0},
{"mix-prog-path", mix_prog_path_, 0, 0, 0},
{"mix-src-name", mix_src_name_, 0, 0, 0},
{"mix-src-path", mix_src_path_, 0, 0, 0},
+ /* {"mix-src-line-no", mix_src_line_no_, 0, 1, 0}, */
+ {"mix-ddir", mix_ddir_, 0, 0, 0},
{"mix-set-cmp!", mix_set_cmp_, 1, 0, 0},
{"mix-add-pre-hook", mix_add_pre_hook_, 2, 0, 0},
{"mix-add-post-hook", mix_add_post_hook_, 2, 0, 0},