1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
/* -*-c-*- -------------- xmixguile_cmd_dispatcher.c :
* Implementation of the functions declared in xmixguile_cmd_dispatcher.h
* ------------------------------------------------------------------
* Last change: Time-stamp: "01/08/21 23:55:06 jao"
* ------------------------------------------------------------------
* Copyright (C) 2001 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#include <mixlib/mix.h>
#include <guile/gh.h>
#include "xmixguile_cmd_dispatcher.h"
/* cmd dispatcher for use within the scm commands */
static mixguile_cmd_dispatcher_t *dispatcher_;
static mix_vm_cmd_dispatcher_t *vm_dispatcher_;
/* register a NULL-terminated list of scm commands */
void
register_scm_commands_ (const scm_command_t *commands)
{
int k = 0;
g_return_if_fail (commands != NULL);
while (commands[k].name)
{
gh_new_procedure (commands[k].name, commands[k].func,
commands[k].argno, commands[k].opt_argno,
commands[k].restp);
++k;
}
}
/* register the mixvm cmd dispatcher to use with commands */
void
register_cmd_dispatcher_ (mixguile_cmd_dispatcher_t *dis)
{
g_return_if_fail (dis != NULL);
dispatcher_ = dis;
vm_dispatcher_ = mixguile_cmd_dispatcher_get_vm_dispatcher (dis);
}
/* commands */
static SCM
mix_command_ (SCM cmd, SCM arg)
{
char *com, *argu;
int len;
gboolean result;
SCM_DEFER_INTS;
SCM_ASSERT (SCM_STRINGP (cmd), cmd, SCM_ARG1, "mix-command");
SCM_ASSERT (SCM_STRINGP (arg), arg, SCM_ARG2, "mix-command");
com = gh_scm2newstr (cmd, &len);
argu = gh_scm2newstr (arg, &len);
result = mix_vm_cmd_dispatcher_dispatch (vm_dispatcher_,
mix_vm_command_from_string (com),
argu);
g_free (com);
g_free (argu);
SCM_ALLOW_INTS;
com = (char *) mixguile_cmd_dispatcher_last_result (dispatcher_);
if (!com || strlen (com) == 0)
com = result? "ok" : "fail";
return gh_str02scm (com);
}
/* NULL-terminated list of available scm commands */
const scm_command_t DEFAULT_SCM_COMMANDS_[] = {
{"mix-command", mix_command_, 2, 0, 0},
{NULL}
};
|