summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2001-05-06 21:38:13 +0000
committerJose Antonio Ortega Ruiz <jao@gnu.org>2001-05-06 21:38:13 +0000
commit070635cb6e0b42c7a485189d1a58db04482de0f8 (patch)
treeb814420bed82cf36ba64bbd44841d63eb2ded1e4
parent6c118b8f8965a5fbb602ad556b584f6f8c0c26c0 (diff)
downloadmdk-070635cb6e0b42c7a485189d1a58db04482de0f8.tar.gz
mdk-070635cb6e0b42c7a485189d1a58db04482de0f8.tar.bz2
support for gtk binary devices added
-rw-r--r--mixgtk/mixgtk_device.c146
-rw-r--r--mixlib/mix_device.c26
-rw-r--r--mixlib/xmix_device.c47
-rw-r--r--mixlib/xmix_device.h15
4 files changed, 158 insertions, 76 deletions
diff --git a/mixgtk/mixgtk_device.c b/mixgtk/mixgtk_device.c
index faf3c3b..2a31afe 100644
--- a/mixgtk/mixgtk_device.c
+++ b/mixgtk/mixgtk_device.c
@@ -1,7 +1,7 @@
/* -*-c-*- ---------------- mixgtk_device.c :
* actual types for mixgtk devices
* ------------------------------------------------------------------
- * Last change: Time-stamp: <01/04/03 00:09:46 jose>
+ * Last change: Time-stamp: <2001-05-06 23:34:51 jao>
* ------------------------------------------------------------------
* Copyright (C) 2001 Free Software Foundation, Inc.
*
@@ -24,6 +24,7 @@
#include <stdio.h>
#include <mixlib/xmix_device.h>
+#include "mixgtk.h"
#include "mixgtk_device.h"
/* device container */
@@ -35,85 +36,113 @@ static mix_vm_t *vm_ = NULL;
struct mixgtk_device_t
{
mix_device_t device;
- gchar *buffer;
GtkText *widget;
gint pos;
};
/* callbacks for output devices */
-static gboolean
-write_out_ (mix_device_t *dev, const mix_word_t *block)
+static void
+write_char_ (struct mixgtk_device_t *dev, const mix_word_t *block)
{
- struct mixgtk_device_t *gtkdev = (struct mixgtk_device_t *) dev;
+ enum {MAX_BLOCK = 16, BUFF_SIZE = MAX_BLOCK * 5 + 2};
+ static gchar BUFFER[BUFF_SIZE];
guint k, j;
-
- for (k = 0; k < SIZES_[dev->type]; k++)
+
+ for (k = 0; k < SIZES_[dev->device.type]; k++)
for (j = 1; j < 6; j++)
{
mix_char_t ch = mix_word_get_byte (block[k], j);
- gtkdev->buffer[5 * k + j - 1] = mix_char_to_ascii (ch);
+ BUFFER[5 * k + j - 1] = mix_char_to_ascii (ch);
}
- gtk_text_insert (gtkdev->widget, NULL, NULL, NULL, gtkdev->buffer, -1);
+ BUFFER[5 * k] = '\n';
+ BUFFER[5 * k + 1] = '\0';
+
+ gtk_text_insert (dev->widget, NULL, NULL, NULL, BUFFER, -1);
+
+}
+
+static void
+write_bin_ (struct mixgtk_device_t *dev, const mix_word_t *block)
+{
+ enum {BUFF_SIZE = 17, STEP = 10};
+ static gchar BUFFER[BUFF_SIZE] = { 0 };
+ guint k;
+
+ for (k = 0; k < SIZES_[dev->device.type]; k++)
+ {
+ mix_word_print_to_buffer (block[k], BUFFER);
+ gtk_text_insert (dev->widget, NULL, NULL, NULL, BUFFER, -1);
+ gtk_text_insert (dev->widget, NULL, NULL, NULL,
+ ((k+1)%STEP != 0) ? " " : "\n", -1);
+ }
+}
+
+static gboolean
+write_ (mix_device_t *dev, const mix_word_t *block)
+{
+ struct mixgtk_device_t *gtkdev = (struct mixgtk_device_t *) dev;
+
+ if (dev->type != mix_dev_CONSOLE && !(DEF_DEV_VTABLE_->write)(dev, block))
+ return FALSE;
+
+ if (MODES_[dev->type] == mix_dev_CHAR) write_char_ (gtkdev, block);
+ else write_bin_ (gtkdev, block);
+
gtk_notebook_set_page (container_, gtkdev->pos);
return TRUE;
}
+
static gboolean
-read_out_ (mix_device_t *dev, mix_word_t *block)
+read_ (mix_device_t *dev, mix_word_t *block)
{
+ struct mixgtk_device_t *gtkdev = (struct mixgtk_device_t *) dev;
+
+ if (dev->type != mix_dev_CONSOLE && !(DEF_DEV_VTABLE_->read)(dev, block))
+ return FALSE;
+
+ if (MODES_[dev->type] == mix_dev_CHAR) write_char_ (gtkdev, block);
+ else write_bin_ (gtkdev, block);
+
+ gtk_notebook_set_page (container_, gtkdev->pos);
+
return TRUE;
}
static gboolean
-ioc_out_ (mix_device_t *dev, mix_short_t cmd)
+ioc_ (mix_device_t *dev, mix_short_t cmd)
{
- return TRUE;
+ return (DEF_DEV_VTABLE_->ioc)(dev, cmd);
}
static gboolean
-busy_out_ (const mix_device_t *dev)
+busy_ (const mix_device_t *dev)
{
- return TRUE;
+ return (DEF_DEV_VTABLE_->busy)(dev);
}
-static mix_device_vtable_t MIXGTK_OUT_VTABLE_;
-
-/* create a new mixgtk device */
-static struct mixgtk_device_t *
-mixgtk_device_new_ (mix_device_type_t type)
-{
- struct mixgtk_device_t *dev = NULL;
-
- g_return_val_if_fail (type < mix_dev_INVALID, NULL);
+static mix_device_vtable_t MIXGTK_VTABLE_ = {write_, read_, ioc_, busy_};
- if (MODES_[type] == mix_dev_CHAR && FMODES_[type] == mix_io_WRITE)
- {
- dev = g_new (struct mixgtk_device_t, 1);
- dev->device.file = NULL;
- dev->device.type = type;
- dev->device.vtable = &MIXGTK_OUT_VTABLE_;
- dev->buffer = g_new (gchar, (SIZES_[type] * 5 + 2));
- dev->buffer[SIZES_[type] * 5] = '\n';
- dev->buffer[SIZES_[type] * 5 + 1] = '\0';
- dev->widget = (GtkText *)gtk_text_new (NULL, NULL);
- g_assert (dev->widget);
- gtk_text_set_editable (dev->widget, FALSE);
- }
- return dev;
-}
-/* connect a device */
+/* create the gui part of the device */
static void
-mixgtk_device_connect_ (struct mixgtk_device_t *dev)
+mixgtk_device_construct_gui_ (struct mixgtk_device_t *dev)
{
static gint last_pos = 0;
GtkWidget *label = gtk_label_new (DEF_NAMES_[dev->device.type]);
GtkWidget *box = gtk_hbox_new (0, 0);
- GtkWidget *scroll = gtk_vscrollbar_new (dev->widget->vadj);
+ GtkWidget *scroll = NULL;
+
g_assert (label);
g_assert (box);
+
+ dev->widget = (GtkText *)gtk_text_new (NULL, NULL);
+ g_assert (dev->widget);
+ gtk_text_set_editable (dev->widget, FALSE);
+
+ scroll = gtk_vscrollbar_new (dev->widget->vadj);
gtk_box_pack_start (GTK_BOX (box), GTK_WIDGET (dev->widget),
TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (box), scroll, FALSE, FALSE, 0);
@@ -124,7 +153,27 @@ mixgtk_device_connect_ (struct mixgtk_device_t *dev)
gtk_widget_show (scroll);
gtk_widget_show (GTK_WIDGET (dev->widget));
gtk_widget_draw (GTK_WIDGET (container_), NULL);
- (void) mix_vm_connect_device (vm_, (mix_device_t *)dev);
+}
+
+/* create a new mixgtk device */
+static mix_device_t *
+mixgtk_device_new_ (mix_device_type_t type)
+{
+ struct mixgtk_device_t *dev = NULL;
+ gchar *name = NULL;
+
+ g_return_val_if_fail (type < mix_dev_INVALID, NULL);
+
+ dev = g_new (struct mixgtk_device_t, 1);
+ name = g_strconcat (g_get_home_dir(), "/",
+ MIXGTK_FILES_DIR, "/", DEF_NAMES_[type], NULL);
+ construct_device_with_name_ (&dev->device, type, name);
+ g_free (name);
+ dev->device.vtable = &MIXGTK_VTABLE_;
+
+ mixgtk_device_construct_gui_ (dev);
+
+ return (mix_device_t *)dev;
}
/* init default devices */
@@ -132,7 +181,7 @@ gboolean
mixgtk_device_init (GtkNotebook *container, mix_vm_t *vm)
{
static mix_device_type_t def_types[] = {
- mix_dev_CONSOLE, mix_dev_PRINTER, mix_dev_PAPER_TAPE, mix_dev_INVALID
+ mix_dev_CONSOLE, mix_dev_INVALID
};
gint k = 0;
@@ -145,18 +194,13 @@ mixgtk_device_init (GtkNotebook *container, mix_vm_t *vm)
/* remove dummy page from container */
gtk_notebook_remove_page (container_, 0);
- /* initialise vtables */
- MIXGTK_OUT_VTABLE_.write = write_out_;
- MIXGTK_OUT_VTABLE_.read = read_out_;
- MIXGTK_OUT_VTABLE_.ioc = ioc_out_;
- MIXGTK_OUT_VTABLE_.busy = busy_out_;
+ mix_vm_set_device_factory (vm, mixgtk_device_new_);
/* connect default devices */
while (def_types[k] != mix_dev_INVALID)
{
- struct mixgtk_device_t *dev = mixgtk_device_new_ (def_types[k]);
- if (dev != NULL)
- mixgtk_device_connect_ (dev);
+ struct mix_device_t *dev = mixgtk_device_new_ (def_types[k]);
+ if (dev != NULL) mix_vm_connect_device (vm, dev);
++k;
}
diff --git a/mixlib/mix_device.c b/mixlib/mix_device.c
index 13e7150..6870427 100644
--- a/mixlib/mix_device.c
+++ b/mixlib/mix_device.c
@@ -29,14 +29,7 @@ mix_device_new (mix_device_type_t type)
mix_device_t *result = NULL;
g_return_val_if_fail (type < mix_dev_INVALID, NULL);
result = g_new (mix_device_t, 1);
- result->type = type;
- if (type != mix_dev_CONSOLE) {
- result->file = MIX_IOCHANNEL(mix_file_new_with_def_ext (DEF_NAMES_[type],
- FMODES_[type],
- DEV_EXT_));
- } else
- result->file = mix_io_new (stdout);
- result->vtable = DEF_DEV_VTABLE_;
+ construct_device_ (result, type);
return result;
}
@@ -49,18 +42,7 @@ mix_device_new_with_name (mix_device_type_t type, const gchar *name)
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (type < mix_dev_INVALID, NULL);
result = g_new (mix_device_t, 1);
- result->type = type;
- if (type != mix_dev_CONSOLE)
- {
- result->file = MIX_IOCHANNEL(mix_file_new_with_def_ext (name,
- FMODES_[type],
- DEV_EXT_));
- }
- else
- {
- result->file = mix_io_new (stdout);
- }
- result->vtable = DEF_DEV_VTABLE_;
+ construct_device_with_name_ (result, type, name);
return result;
}
@@ -74,9 +56,7 @@ mix_device_new_with_file (mix_device_type_t type, FILE *file)
g_return_val_if_fail (file != NULL, NULL);
g_return_val_if_fail (type < mix_dev_INVALID, NULL);
result = g_new (mix_device_t, 1);
- result->type = type;
- result->file = mix_io_new (file);
- result->vtable = DEF_DEV_VTABLE_;
+ construct_device_with_file_ (result, type, file);
return result;
}
diff --git a/mixlib/xmix_device.c b/mixlib/xmix_device.c
index 4754015..c93153a 100644
--- a/mixlib/xmix_device.c
+++ b/mixlib/xmix_device.c
@@ -1,7 +1,7 @@
/* -*-c-*- -------------- xmix_device.c :
* Implementation of the functions declared in xmix_device.h
* ------------------------------------------------------------------
- * Last change: Time-stamp: "01/03/02 23:14:57 jose"
+ * Last change: Time-stamp: "2001-05-04 23:40:31 jao"
* ------------------------------------------------------------------
* Copyright (C) 2001 Free Software Foundation, Inc.
*
@@ -54,6 +54,51 @@ const mix_fmode_t FMODES_[] = {
mix_io_READ, mix_io_WRITE, mix_io_WRITE, mix_io_WRITE, mix_io_WRITE
};
+/* constructors */
+void
+construct_device_ (mix_device_t *result, mix_device_type_t type)
+{
+ result->type = type;
+ if (type != mix_dev_CONSOLE) {
+ result->file = MIX_IOCHANNEL(mix_file_new_with_def_ext (DEF_NAMES_[type],
+ FMODES_[type],
+ DEV_EXT_));
+ } else
+ result->file = mix_io_new (stdout);
+ result->vtable = DEF_DEV_VTABLE_;
+}
+
+
+void
+construct_device_with_name_ (mix_device_t *result,
+ mix_device_type_t type, const gchar *name)
+{
+ result->type = type;
+ if (type != mix_dev_CONSOLE)
+ {
+ result->file = MIX_IOCHANNEL(mix_file_new_with_def_ext (name,
+ FMODES_[type],
+ DEV_EXT_));
+ }
+ else
+ {
+ result->file = mix_io_new (stdout);
+ }
+ result->vtable = DEF_DEV_VTABLE_;
+}
+
+
+void
+construct_device_with_file_ (mix_device_t *result,
+ mix_device_type_t type, FILE *file)
+{
+ result->type = type;
+ result->file = mix_io_new (file);
+ result->vtable = DEF_DEV_VTABLE_;
+}
+
+
+
/*
Write a block to the device.
*/
diff --git a/mixlib/xmix_device.h b/mixlib/xmix_device.h
index 45fd7d3..4c2866a 100644
--- a/mixlib/xmix_device.h
+++ b/mixlib/xmix_device.h
@@ -1,7 +1,7 @@
/* -*-c-*- ---------------- xmix_device.h :
* Protected declarations for mix_device_t
* ------------------------------------------------------------------
- * Last change: Time-stamp: <01/03/02 01:15:22 jose>
+ * Last change: Time-stamp: <2001-05-04 23:35:39 jao>
* ------------------------------------------------------------------
* Copyright (C) 2001 Free Software Foundation, Inc.
*
@@ -56,6 +56,19 @@ struct mix_device_t
const mix_device_vtable_t *vtable;
};
+/* constructors */
+extern void
+construct_device_ (mix_device_t *dev, mix_device_type_t type);
+
+extern void
+construct_device_with_name_ (mix_device_t *dev,
+ mix_device_type_t type, const gchar *name);
+
+extern void
+construct_device_with_file_ (mix_device_t *dev,
+ mix_device_type_t type, FILE *file);
+
+
#define GET_CHANNEL_(dev) (dev->file)
#define GET_FILE_(dev) ((mix_file_t *)(dev->file))