summaryrefslogtreecommitdiffhomepage
path: root/mixguile/mixguile.c
blob: 52321ca91e1285c02ad82353f15a29f1c9d9a205 (plain)
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
/* -*-c-*- -------------- mixguile.c :
 * Implementation of the functions declared in mixguile.h
 * ------------------------------------------------------------------
 *  Last change: Time-stamp: "01/08/22 01:10:33 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 "mixguile_cmd_dispatcher.h"
#include "mixguile.h"

static mixguile_cmd_dispatcher_t *dispatcher_ = NULL;
static main_func_t main_fun_;

/* do local initialisation and enter the user provided main */
static void
real_main_ (int argc, char *argv[])
{
  (*main_fun_)(argc, argv);
}

/*
  initialise the guile command dispatcher and enter the provided
  main function. the mixlib is also initialised.
*/
void
mixguile_init (int argc, char *argv[], main_func_t main_fun)
{
  mix_init_lib ();
  main_fun_ = main_fun;
  gh_enter (argc, argv, real_main_);
}

/* enter the guile repl */
void
mixguile_enter_repl (int argc, char *argv[])
{
  mixguile_cmd_dispatcher_prepare (dispatcher_);
  gh_repl (argc, argv);
}

/* set the command dispatcher */
void
mixguile_set_cmd_dispatcher (mix_vm_cmd_dispatcher_t *dis)
{
  g_return_if_fail (dis != NULL);
  if (dispatcher_) mixguile_cmd_dispatcher_delete (dispatcher_);
  dispatcher_ = mixguile_cmd_dispatcher_new (dis);
  g_assert (dispatcher_);
}

/* access the mixguile comand dispatcher */
mix_vm_cmd_dispatcher_t *
mixguile_get_cmd_dispatcher (void)
{
  return mixguile_cmd_dispatcher_get_vm_dispatcher (dispatcher_);
}

/* execute a string or file using the guile interpreter */
void
mixguile_interpret_file (const gchar *path)
{
  mixguile_cmd_dispatcher_interpret_file (dispatcher_, path);
}

void
mixguile_interpret_command (const gchar *command)
{
  mixguile_cmd_dispatcher_interpret_command (dispatcher_, command);
}