summaryrefslogtreecommitdiffhomepage
path: root/mixgtk
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2001-08-28 16:38:06 +0000
committerJose Antonio Ortega Ruiz <jao@gnu.org>2001-08-28 16:38:06 +0000
commitef4616f943c15d40cc2ff189b70e0ef6251af561 (patch)
tree784a7f78b03dee48c2c5ee387c9abe40b01a3907 /mixgtk
parent7ca7d093df5ed4f4408f4617036116a84df2bd7f (diff)
downloadmdk-ef4616f943c15d40cc2ff189b70e0ef6251af561.tar.gz
mdk-ef4616f943c15d40cc2ff189b70e0ef6251af561.tar.bz2
guile integration
Diffstat (limited to 'mixgtk')
-rw-r--r--mixgtk/Makefile.am10
-rw-r--r--mixgtk/gmixvm.c22
-rw-r--r--mixgtk/mixgtk_cmd_dispatcher.c63
-rw-r--r--mixgtk/mixgtk_mixvm.c2
4 files changed, 63 insertions, 34 deletions
diff --git a/mixgtk/Makefile.am b/mixgtk/Makefile.am
index 461a4ab..36af4b2 100644
--- a/mixgtk/Makefile.am
+++ b/mixgtk/Makefile.am
@@ -16,14 +16,20 @@ XPMS = clear.xpm colors.xpm compile.xpm edit.xpm font.xpm fontl.xpm \
EXTRA_DIST = mixgtk.glade $(XPMS)
+if MAKE_GUILE
+GUILED = -DMAKE_GUILE
+else
+GUILED =
+endif
if MAKE_GUI
pkgdata_DATA = mixgtk.glade $(XPMS)
INCLUDES = -I$(includedir) -DGLADE_FILE=\""$(pkgdatadir)/mixgtk.glade"\"\
- -DLOCAL_GLADE_FILE=\"mixgtk.glade\"
-LDADD = $(top_builddir)/mixlib/libmix.a $(top_builddir)/lib/libreplace.a $(INTLLIBS)
+ -DLOCAL_GLADE_FILE=\"mixgtk.glade\" $(GUILED)
+LDADD = $(top_builddir)/mixlib/libmix.a $(top_builddir)/lib/libreplace.a\
+ $(top_builddir)/mixguile/libmixguile.a $(INTLLIBS)
bin_PROGRAMS = gmixvm
gmixvm_SOURCES = gmixvm.c mixgtk.h mixgtk.c \
diff --git a/mixgtk/gmixvm.c b/mixgtk/gmixvm.c
index 6326957..59b4b41 100644
--- a/mixgtk/gmixvm.c
+++ b/mixgtk/gmixvm.c
@@ -24,13 +24,31 @@
#include <stdlib.h>
#include "mixgtk.h"
+
+#ifdef MAKE_GUILE
+# include <mixguile/mixguile.h>
+# include "mixgtk_cmd_dispatcher.h"
+static void
+inner_main_ (int argc, char *argv[])
+{
+ mixgtk_init (argc, argv);
+ mixguile_set_cmd_dispatcher (mixgtk_cmd_dispatcher_get_mix_dispatcher ());
+ mixguile_load_bootstrap ();
+ mixgtk_main ();
+ mixgtk_release ();
+}
+#endif
+
int
main(int argc, char *argv[])
{
+#ifdef MAKE_GUILE
+ mixguile_enter (argc, argv, inner_main_);
+#else
if (!mixgtk_init (argc, argv)) return EXIT_FAILURE;
-
mixgtk_main ();
mixgtk_release ();
-
+#endif
+
return EXIT_SUCCESS;
}
diff --git a/mixgtk/mixgtk_cmd_dispatcher.c b/mixgtk/mixgtk_cmd_dispatcher.c
index 8d2d0a7..01e549b 100644
--- a/mixgtk/mixgtk_cmd_dispatcher.c
+++ b/mixgtk/mixgtk_cmd_dispatcher.c
@@ -35,6 +35,10 @@
# include <readline/history.h>
#endif
+#ifdef MAKE_GUILE
+# include <mixguile/mixguile.h>
+#endif
+
#include <gdk/gdkkeysyms.h>
#include <mixlib/mix_vm_command.h>
#include "mixgtk_mixvm.h"
@@ -53,7 +57,6 @@ typedef struct mixgtk_dispatch_
GtkWidget *log; /* the dispatcher's messages echo area */
GtkWidget *status; /* the status bar widget */
guint context; /* context of the status bar messages */
- GCompletion *completions; /* mixvm command completions */
gchar *last_file;
} mixgtk_dispatch_data_t;
@@ -99,19 +102,7 @@ flush_log_ (mixgtk_dispatch_data_t *dis)
}
}
-/* completions */
-static void
-init_completions_ (void)
-{
- GList *cmds = NULL;
- gint k;
-
- dis_data_.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));
- g_completion_add_items (dis_data_.completions, cmds);
-}
-
+/* hooks */
static void
global_post_hook_ (mix_vm_cmd_dispatcher_t *dis,
mix_vm_command_t cmd, const gchar *arg, gpointer data)
@@ -323,10 +314,10 @@ mixgtk_cmd_dispatcher_init (mixgtk_dialog_id_t top)
int r = pipe (dis_data_.fildes);
g_return_val_if_fail (r == 0, FALSE);
- /* connect stdout/stderr to the pipe's write end
+ /* connect stdout/stderr to the pipe's write end */
if (dup2 (dis_data_.fildes[1], STDOUT_FILENO) == -1
|| dup2 (dis_data_.fildes[1], STDERR_FILENO) == -1)
- return FALSE;*/
+ return FALSE;
dis_data_.out = fdopen (dis_data_.fildes[1], "w");
g_return_val_if_fail (dis_data_.out != NULL, FALSE);
r = fcntl (dis_data_.fildes[0], F_GETFL, 0);
@@ -355,19 +346,32 @@ mixgtk_cmd_dispatcher_init (mixgtk_dialog_id_t top)
dis_data_.context = gtk_statusbar_get_context_id (GTK_STATUSBAR
(dis_data_.status),
"cmd_dis_context");
- if (!dis_data_.completions) init_completions_ ();
if (!restart) read_config_ ();
if (dis_data_.last_file)
gtk_window_set_title
(GTK_WINDOW (mixgtk_widget_factory_get_dialog (MIXGTK_MAIN)),
dis_data_.last_file);
-
restart = TRUE;
return TRUE;
}
/* dispatch an externally provided command */
+#ifdef MAKE_GUILE
+static gboolean
+try_guile_ (const gchar *command)
+{
+ if (command && command[0] == '(' && command[strlen (command) - 1] == ')')
+ {
+ mixguile_interpret_command (command);
+ return TRUE;
+ }
+ return FALSE;
+}
+#else
+# define try_guile_(ignored) FALSE
+#endif
+
void
mixgtk_cmd_dispatcher_dispatch (const gchar *command)
{
@@ -376,7 +380,8 @@ mixgtk_cmd_dispatcher_dispatch (const gchar *command)
g_assert (entry != NULL);
gtk_entry_set_text (GTK_ENTRY (entry), command);
log_command_ (&dis_data_, command);
- mix_vm_cmd_dispatcher_dispatch_text (dis_data_.dispatcher, command);
+ if (!try_guile_ (command))
+ mix_vm_cmd_dispatcher_dispatch_text (dis_data_.dispatcher, command);
gtk_entry_set_text (GTK_ENTRY (entry), "");
}
@@ -419,26 +424,26 @@ complete_command_ (void)
{
GtkEntry *entry = GTK_ENTRY (dis_data_.prompt);
gchar *prefix = NULL;
- gchar *text = g_strchomp (gtk_entry_get_text (entry));
- GList *cmds = g_completion_complete (dis_data_.completions, text, &prefix);
+ gchar *text = gtk_entry_get_text (entry);
+ const GList *cmds =
+ mix_vm_cmd_dispatcher_complete (dis_data_.dispatcher, text, &prefix);
if (prefix != NULL)
{
gtk_entry_set_text (entry, prefix);
g_free (prefix);
- if (g_list_length (cmds) > 1)
+ if (g_list_length ((GList *)cmds) > 1)
{
+ static gchar BUFFER[25];
gint k = 0;
gtk_text_insert (GTK_TEXT (dis_data_.log),
NULL, NULL, NULL, "Completions:\n", -1);
while (cmds)
{
+ snprintf (BUFFER, 25, "%-12s", (const char*)cmds->data);
++k;
gtk_text_insert (GTK_TEXT (dis_data_.log),
- NULL, NULL, NULL,
- (gchar *)(cmds->data), -1);
- gtk_text_insert (GTK_TEXT (dis_data_.log),
- NULL, NULL, NULL, " ", -1);
+ NULL, NULL, NULL, BUFFER, -1);
if (k%5 == 0)
gtk_text_insert (GTK_TEXT (dis_data_.log),
NULL, NULL, NULL, "\n", -1);
@@ -454,7 +459,6 @@ complete_command_ (void)
}
}
-
int
on_command_prompt_key_press_event (GtkEntry *w, GdkEventKey *e, gpointer d)
{
@@ -486,11 +490,12 @@ on_command_prompt_key_press_event (GtkEntry *w, GdkEventKey *e, gpointer d)
if (key == GDK_Return)
{
- gchar *text = gtk_entry_get_text (w);
+ gchar *text = g_strstrip (gtk_entry_get_text (w));
if (text && *text)
{
log_command_ (&dis_data_, text);
- mix_vm_cmd_dispatcher_dispatch_text (dis_data_.dispatcher, text);
+ if (!try_guile_ (text))
+ mix_vm_cmd_dispatcher_dispatch_text (dis_data_.dispatcher, text);
gtk_entry_set_text (w, "");
}
return TRUE;
diff --git a/mixgtk/mixgtk_mixvm.c b/mixgtk/mixgtk_mixvm.c
index f492110..0d776fc 100644
--- a/mixgtk/mixgtk_mixvm.c
+++ b/mixgtk/mixgtk_mixvm.c
@@ -235,7 +235,7 @@ void
mixgtk_mixvm_update_cells_to_address (gint address)
{
g_assert (memory_);
- g_return_if_fail (address < MIX_VM_CELL_NO);
+ if (address >= MIX_VM_CELL_NO) return;
gtk_clist_freeze (memory_);
gtk_clist_moveto (memory_, address, 0, 0, 0);