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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
/* -*-c-*- -------------- mixguile.c :
* Implementation of the functions declared in mixguile.h
* ------------------------------------------------------------------
* $Id: mixguile.c,v 1.5 2001/09/24 23:27:42 jao Exp $
* ------------------------------------------------------------------
* 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 <unistd.h>
#include <mixlib/mix_config.h>
#include "mixguile_cmd_dispatcher.h"
#include "mixguile.h"
static mixguile_cmd_dispatcher_t *dispatcher_ = NULL;
static mix_vm_cmd_dispatcher_t *vm_dispatcher_ = NULL;
static main_func_t main_fun_;
static gboolean init_file_;
/* do local initialisation and enter the user provided main */
static void
real_main_ (int argc, char *argv[])
{
if (vm_dispatcher_)
{
mixguile_set_cmd_dispatcher (vm_dispatcher_);
mixguile_load_bootstrap ();
}
(*main_fun_)(argc, argv);
}
/*
initialise the guile command dispatcher and enter the provided
main function.
*/
void
mixguile_init (int argc, char *argv[], gboolean initfile,
main_func_t main_fun,
mix_vm_cmd_dispatcher_t *dis)
{
main_fun_ = main_fun;
vm_dispatcher_ = dis;
init_file_ = initfile;
gh_enter (argc, argv, real_main_);
}
/* load bootstrap file */
void
mixguile_load_bootstrap (void)
{
const gchar *scmfile = SCM_FILE;
gchar *lscmfile = g_strconcat (g_get_home_dir (), G_DIR_SEPARATOR_S,
MIX_CONFIG_DIR, G_DIR_SEPARATOR_S,
LOCAL_SCM_FILE, NULL);
if (access (scmfile, R_OK) && access ((scmfile = LOCAL_SCM_FILE), R_OK))
{
g_warning ("mixguile bootstrap file %s not found\n", SCM_FILE);
scmfile = NULL;
}
else
mixguile_interpret_file (scmfile);
if (init_file_ && !access (lscmfile, R_OK))
{
mixguile_interpret_file (lscmfile);
}
g_free (lscmfile);
}
/* enter the guile repl */
void
mixguile_enter_repl (int argc, char *argv[])
{
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_);
vm_dispatcher_ = dis;
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);
}
|