From 21830126cfa1badd81b2c6fe1b3e9d0c610c8b0a Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Tue, 8 Jun 2004 22:33:40 +0000 Subject: the console is now in/out. --- mixlib/xmix_device.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'mixlib/xmix_device.c') diff --git a/mixlib/xmix_device.c b/mixlib/xmix_device.c index 92d9c4f..73c0485 100644 --- a/mixlib/xmix_device.c +++ b/mixlib/xmix_device.c @@ -3,7 +3,7 @@ * ------------------------------------------------------------------ * Last change: Time-stamp: "2001-05-10 01:10:25 jao" * ------------------------------------------------------------------ - * Copyright (C) 2001 Free Software Foundation, Inc. + * Copyright (C) 2001, 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 @@ -23,6 +23,7 @@ #include "xmix_device.h" +#include "mix_types.h" gchar *DEV_DIR_ = NULL; @@ -53,7 +54,7 @@ const mix_fmode_t FMODES_[] = { mix_io_RDWRT, mix_io_RDWRT, mix_io_RDWRT, mix_io_RDWRT, mix_io_RDWRT, mix_io_RDWRT, mix_io_RDWRT, mix_io_RDWRT, mix_io_RDWRT, mix_io_RDWRT, mix_io_RDWRT, mix_io_RDWRT, - mix_io_READ, mix_io_WRITE, mix_io_WRITE, mix_io_WRITE, mix_io_WRITE + mix_io_READ, mix_io_WRITE, mix_io_WRITE, mix_io_RDWRT, mix_io_WRITE }; /* constructors */ @@ -78,12 +79,13 @@ construct_device_with_name_ (mix_device_t *result, result->file = MIX_IOCHANNEL(mix_file_new_with_def_ext (name, FMODES_[type], DEV_EXT_)); + result->vtable = DEF_DEV_VTABLE_; } else { result->file = mix_io_new (stdout); + result->vtable = CONSOLE_DEV_VTABLE_; } - result->vtable = DEF_DEV_VTABLE_; } @@ -120,6 +122,13 @@ write_ (mix_device_t *dev, const mix_word_t *block) return result; } +static gboolean +read_cons_ (mix_device_t *dev, mix_word_t *block) +{ + return mix_io_read_word_array_as_char (mix_io_new (stdin), block, + SIZES_[mix_dev_CONSOLE]); +} + static gboolean read_ (mix_device_t *dev, mix_word_t *block) { @@ -130,14 +139,6 @@ read_ (mix_device_t *dev, mix_word_t *block) { result = mix_io_read_word_array_as_char (GET_CHANNEL_ (dev), block, SIZES_[dev->type]); - if (result) - { - int c; - FILE *f = mix_io_to_FILE (GET_CHANNEL_ (dev)); - do { - c = getc (f); - } while (c != EOF && c != '\n'); - } } else result = mix_io_read_word_array (GET_CHANNEL_ (dev), @@ -164,12 +165,12 @@ ioc_ (mix_device_t *dev, mix_short_t arg) } if (dev->type >= mix_dev_DISK_0 && dev->type <= mix_dev_DISK_7) { - g_return_val_if_fail (m == 0, FALSE); + if (m == 0) return FALSE; // position disk } if (dev->type == mix_dev_PAPER_TAPE) { - g_return_val_if_fail (m == 0, FALSE); + if (m == 0) return FALSE; rewind (file); } return TRUE; @@ -193,3 +194,9 @@ static mix_device_vtable_t VTABLE_ = { }; const mix_device_vtable_t * DEF_DEV_VTABLE_ = &VTABLE_; + +static mix_device_vtable_t CVTABLE_ = { + write_, read_cons_, ioc_, busy_, destroy_ +}; + +const mix_device_vtable_t * CONSOLE_DEV_VTABLE_ = &CVTABLE_; -- cgit v1.2.3