summaryrefslogtreecommitdiffhomepage
path: root/mixlib/mix_vm_command.c
diff options
context:
space:
mode:
Diffstat (limited to 'mixlib/mix_vm_command.c')
-rw-r--r--mixlib/mix_vm_command.c83
1 files changed, 42 insertions, 41 deletions
diff --git a/mixlib/mix_vm_command.c b/mixlib/mix_vm_command.c
index d99bd6d..55da6a5 100644
--- a/mixlib/mix_vm_command.c
+++ b/mixlib/mix_vm_command.c
@@ -1,24 +1,24 @@
/* -*-c-*- -------------- mix_vm_command.c :
* Implementation of the functions declared in mix_vm_command.h
* ------------------------------------------------------------------
- * $Id: mix_vm_command.c,v 1.28 2002/04/10 23:39:40 jao Exp $
+ * $Id: mix_vm_command.c,v 1.29 2004/06/23 10:46:17 jao Exp $
* ------------------------------------------------------------------
- * Copyright (C) 2001, 2002 Free Software Foundation, Inc.
- *
+ * Copyright (C) 2001, 2002, 2004 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.
- *
+ *
*/
@@ -98,7 +98,7 @@ make_completions_ (void)
{
GList *cmds = NULL;
gint k;
-
+
GCompletion *completions = g_completion_new (NULL);
for (k = 0; k < MIX_CMD_INVALID; ++k)
cmds = g_list_append (cmds, (gpointer) mix_vm_command_to_string (k));
@@ -112,9 +112,9 @@ mix_vm_cmd_dispatcher_new (FILE *out_fd, /* output messages file */
{
mix_vm_cmd_dispatcher_t *result = NULL;
int k;
-
+
/* g_return_val_if_fail (out_fd && err_fd, NULL); */
-
+
result = g_new (mix_vm_cmd_dispatcher_t, 1);
result->result = TRUE;
result->out = out_fd;
@@ -127,24 +127,24 @@ mix_vm_cmd_dispatcher_new (FILE *out_fd, /* output messages file */
result->editor = NULL;
result->assembler = NULL;
result->eval = mix_eval_new ();
- result->dump = mix_dump_context_new (out_fd,
+ result->dump = mix_dump_context_new (out_fd,
MIX_SHORT_ZERO, MIX_SHORT_ZERO,
MIX_DUMP_ALL);
result->vm = mix_vm_new ();
result->global_pre = result->global_post = NULL;
-
+
for (k =0; k < MIX_CMD_INVALID; ++k)
result->pre_hooks[k] = result->post_hooks[k] = NULL;
result->config = NULL;
-
+
for (k = 0; k < PRNO_; ++k)
result->preds[k] = mix_predicate_new (k);
-
+
result->mem_preds = g_hash_table_new (NULL, NULL);
result->commands = g_hash_table_new (g_str_hash, g_str_equal);
result->completions = make_completions_ ();
-
+
return result;
}
@@ -167,7 +167,8 @@ mix_vm_cmd_dispatcher_new_with_config (FILE *out, FILE *err,
val = mix_config_get_devices_dir (result->config);
if (!val || !mix_stat_dir (val, "devices"))
{
- gchar *dirname = g_dirname (mix_config_get_filename (config));
+ gchar *dirname =
+ g_path_get_dirname (mix_config_get_filename (config));
cmd_sddir_ (result, dirname);
g_free (dirname);
}
@@ -189,7 +190,7 @@ mix_vm_cmd_dispatcher_new_with_config (FILE *out, FILE *err,
}
return result;
}
-
+
/* delete (does not close the fds in the constructor) */
static gboolean
@@ -220,7 +221,7 @@ mix_vm_cmd_dispatcher_delete (mix_vm_cmd_dispatcher_t *dis)
{
const gchar *hfile = NULL;
gint k;
-
+
g_return_if_fail (dis != NULL);
mix_eval_delete (dis->eval);
mix_dump_context_delete (dis->dump);
@@ -266,10 +267,10 @@ mix_vm_cmd_dispatcher_complete (const mix_vm_cmd_dispatcher_t *dis,
{
char *cp;
GList *result;
-
+
g_return_val_if_fail (dis != NULL, NULL);
g_return_val_if_fail (cmd != NULL, NULL);
-
+
cp = g_strdup (cmd);
result = g_completion_complete (dis->completions, cp, prefix);
g_free (cp);
@@ -355,10 +356,10 @@ const gchar *
mix_vm_cmd_dispatcher_get_src_file_path (const mix_vm_cmd_dispatcher_t *dis)
{
static gchar *PATH = NULL;
-
+
const mix_vm_t *vm = mix_vm_cmd_dispatcher_get_vm (dis);
const mix_src_file_t *f = mix_vm_get_src_file (vm);
-
+
if (PATH)
{
g_free (PATH);
@@ -367,7 +368,7 @@ mix_vm_cmd_dispatcher_get_src_file_path (const mix_vm_cmd_dispatcher_t *dis)
if (f)
PATH = mix_file_complete_name (mix_src_file_get_path (f), MIX_SRC_DEFEXT);
-
+
return PATH;
}
@@ -385,14 +386,14 @@ mix_vm_cmd_dispatcher_pre_hook (mix_vm_cmd_dispatcher_t *dis,
mix_vm_cmd_hook_t hook, gpointer data)
{
hook_ *phook;
-
+
g_return_if_fail (dis != NULL);
g_return_if_fail (cmd < MIX_CMD_INVALID);
phook = g_new (hook_, 1);
phook->func = hook;
phook->data = data;
-
+
dis->pre_hooks[cmd] = g_slist_append (dis->pre_hooks[cmd], phook);
}
@@ -402,14 +403,14 @@ mix_vm_cmd_dispatcher_post_hook (mix_vm_cmd_dispatcher_t *dis,
mix_vm_cmd_hook_t hook, gpointer data)
{
hook_ *phook;
-
+
g_return_if_fail (dis != NULL);
g_return_if_fail (cmd < MIX_CMD_INVALID);
phook = g_new (hook_, 1);
phook->func = hook;
phook->data = data;
-
+
dis->post_hooks[cmd] = g_slist_append (dis->post_hooks[cmd], phook);
}
@@ -419,13 +420,13 @@ mix_vm_cmd_dispatcher_global_pre_hook (mix_vm_cmd_dispatcher_t *dis,
gpointer data)
{
global_hook_ *phook;
-
+
g_return_if_fail (dis != NULL);
phook = g_new (global_hook_, 1);
phook->func = hook;
phook->data = data;
-
+
dis->global_pre = g_slist_append (dis->global_pre, phook);
}
@@ -435,13 +436,13 @@ mix_vm_cmd_dispatcher_global_post_hook (mix_vm_cmd_dispatcher_t *dis,
gpointer data)
{
global_hook_ *phook;
-
+
g_return_if_fail (dis != NULL);
phook = g_new (global_hook_, 1);
phook->func = hook;
phook->data = data;
-
+
dis->global_post = g_slist_append (dis->global_post, phook);
}
@@ -451,10 +452,10 @@ mix_vm_cmd_dispatcher_dispatch (mix_vm_cmd_dispatcher_t *dis,
mix_vm_command_t cmd, const gchar *arg)
{
g_return_val_if_fail (dis != NULL, FALSE);
-
+
if (dis->global_pre)
exec_global_hook_list_ (dis->global_pre, dis, cmd, arg);
-
+
if (cmd < MIX_CMD_INVALID)
{
if (dis->pre_hooks[cmd])
@@ -494,10 +495,10 @@ mix_vm_cmd_dispatcher_dispatch_text (mix_vm_cmd_dispatcher_t *dis,
{
gchar *cp, *arg = "";
int k = 0;
-
+
g_return_val_if_fail (dis != NULL, FALSE);
g_return_val_if_fail (text != NULL, FALSE);
-
+
cp = g_strdup (text);
while (cp[k] && !isspace (cp[k])) ++k;
if (cp[k])
@@ -508,7 +509,7 @@ mix_vm_cmd_dispatcher_dispatch_text (mix_vm_cmd_dispatcher_t *dis,
}
(void) mix_vm_cmd_dispatcher_dispatch_split_text (dis, cp, arg);
-
+
g_free (cp);
return dis->result;
@@ -521,12 +522,12 @@ mix_vm_cmd_dispatcher_dispatch_split_text (mix_vm_cmd_dispatcher_t *dis,
const gchar *arg)
{
mix_vm_command_info_t *info;
-
+
g_return_val_if_fail (dis, FALSE);
-
+
if (!command) return FALSE;
if (!arg) arg = "";
-
+
info = (mix_vm_command_info_t *)g_hash_table_lookup (dis->commands, command);
if (info)
@@ -619,11 +620,11 @@ mix_vm_cmd_dispatcher_get_src_file_line (const mix_vm_cmd_dispatcher_t *dis,
{
const mix_src_file_t *file;
g_return_val_if_fail (dis != NULL, NULL);
-
+
file = mix_vm_get_src_file (dis->vm);
-
+
if (line == 0 || file == NULL) return cr? "" : "\n";
-
+
if (cr)
return mix_src_file_get_line (file, line);
else