diff options
Diffstat (limited to 'mixlib')
-rw-r--r-- | mixlib/mix_device.h | 13 | ||||
-rw-r--r-- | mixlib/mix_io.c | 16 | ||||
-rw-r--r-- | mixlib/mix_io.h | 54 | ||||
-rw-r--r-- | mixlib/xmix_device.c | 33 | ||||
-rw-r--r-- | mixlib/xmix_device.h | 15 |
5 files changed, 71 insertions, 60 deletions
diff --git a/mixlib/mix_device.h b/mixlib/mix_device.h index d8b604b..775b0cd 100644 --- a/mixlib/mix_device.h +++ b/mixlib/mix_device.h @@ -1,22 +1,22 @@ /* -*-c-*- ---------------- mix_device.h : * Declaration of mix_device_t and associated methods. * ------------------------------------------------------------------ - * Copyright (C) 2000, 2001 Free Software Foundation, Inc. - * + * Copyright (C) 2000, 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 * 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. - * + * */ @@ -101,8 +101,7 @@ mix_device_new_with_file (mix_device_type_t type, FILE *file); Delete a device. */ extern void -mix_device_delete(mix_device_t *dev); - +mix_device_delete (mix_device_t *dev); /* Get a device type diff --git a/mixlib/mix_io.c b/mixlib/mix_io.c index 84b9ee0..74cca66 100644 --- a/mixlib/mix_io.c +++ b/mixlib/mix_io.c @@ -184,15 +184,23 @@ mix_io_read_word_array_as_char (mix_iochannel_t *ioc, mix_word_t *w, size_t s) { guint k, j; + guchar value; + gboolean eol = FALSE; + mix_char_t spc = mix_ascii_to_char (' '); if ((ioc == NULL) || (w == NULL)) return FALSE; - for (k = 0; k < s; k++) + for (k = 0; k < s && !eol; k++) for (j = 1; j < 6; j++) { - guchar value; - if (!read_data_ (ioc, &value, 1)) return FALSE; - mix_word_set_byte (&w[k], j, mix_ascii_to_char (value)); + if (!eol && !read_data_ (ioc, &value, 1)) return FALSE; + eol = eol || (value == '\n'); + mix_word_set_byte (&w[k], j, eol? spc : mix_ascii_to_char (value)); } + for (; k < s; ++k) w[k] = MIX_WORD_ZERO; + + while (!eol && !is_eof_ (ioc) && value != '\n') + if (!read_data_ (ioc, &value, 1)) return FALSE; + return TRUE; } diff --git a/mixlib/mix_io.h b/mixlib/mix_io.h index a63bda6..61d35da 100644 --- a/mixlib/mix_io.h +++ b/mixlib/mix_io.h @@ -1,22 +1,22 @@ /* -*-c-*- ------------------ mix_io.h : * Declarations for mix_iochannel_t and mix_file_t * ------------------------------------------------------------------ - * Copyright (C) 2000 Free Software Foundation, Inc. - * + * Copyright (C) 2000, 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 * 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. - * + * */ @@ -33,7 +33,7 @@ typedef struct mix_iochannel_t mix_iochannel_t; #define MIX_IOCHANNEL(file) (mix_iochannel_t *)(file) /* I/O channels can be created in different modes: */ -typedef enum { +typedef enum { mix_io_READ, /* read existing file */ mix_io_WRITE, /* write new file */ mix_io_RDWRT, /* read/write existing from beginning */ @@ -47,7 +47,7 @@ mix_io_new (FILE *file); /* Delete */ extern void -mix_io_delete(mix_iochannel_t *ch); +mix_io_delete (mix_iochannel_t *ch); /* Convert to a FILE * */ extern FILE * @@ -55,64 +55,60 @@ mix_io_to_FILE (mix_iochannel_t *ioc); /* Read/write from/to an iochannel */ extern gboolean -mix_io_eof(mix_iochannel_t *ioc); +mix_io_eof (mix_iochannel_t *ioc); extern gboolean -mix_io_is_ready(mix_iochannel_t *ioc); +mix_io_is_ready (mix_iochannel_t *ioc); extern gboolean -mix_io_write_byte(mix_iochannel_t *ioc, mix_byte_t b); +mix_io_write_byte (mix_iochannel_t *ioc, mix_byte_t b); extern gboolean -mix_io_write_byte_array(mix_iochannel_t *ioc, const mix_byte_t *b, - size_t s); +mix_io_write_byte_array (mix_iochannel_t *ioc, const mix_byte_t *b, size_t s); extern mix_byte_t -mix_io_read_byte(mix_iochannel_t *ioc); +mix_io_read_byte (mix_iochannel_t *ioc); extern gboolean -mix_io_read_byte_array(mix_iochannel_t *ioc, mix_byte_t *b, size_t s); +mix_io_read_byte_array (mix_iochannel_t *ioc, mix_byte_t *b, size_t s); extern gboolean -mix_io_write_word(mix_iochannel_t *ioc, mix_word_t w); +mix_io_write_word (mix_iochannel_t *ioc, mix_word_t w); extern gboolean -mix_io_write_word_array(mix_iochannel_t *ioc, const mix_word_t *w, - size_t s); +mix_io_write_word_array (mix_iochannel_t *ioc, const mix_word_t *w, size_t s); extern mix_word_t -mix_io_read_word(mix_iochannel_t *ioc); +mix_io_read_word (mix_iochannel_t *ioc); extern gboolean -mix_io_read_word_array(mix_iochannel_t *ioc, mix_word_t *w, size_t s); +mix_io_read_word_array (mix_iochannel_t *ioc, mix_word_t *w, size_t s); extern gboolean -mix_io_write_short(mix_iochannel_t *ioc, mix_short_t w); +mix_io_write_short (mix_iochannel_t *ioc, mix_short_t w); extern gboolean -mix_io_write_short_array(mix_iochannel_t *ioc, const mix_short_t *w, - size_t s); +mix_io_write_short_array (mix_iochannel_t *ioc, const mix_short_t *w, size_t s); extern mix_short_t -mix_io_read_short(mix_iochannel_t *ioc); +mix_io_read_short (mix_iochannel_t *ioc); extern gboolean -mix_io_read_short_array(mix_iochannel_t *ioc, mix_short_t *w, size_t s); - +mix_io_read_short_array (mix_iochannel_t *ioc, mix_short_t *w, size_t s); extern gboolean -mix_io_write_char(mix_iochannel_t *ioc, mix_char_t c); +mix_io_write_char (mix_iochannel_t *ioc, mix_char_t c); extern mix_char_t -mix_io_read_char(mix_iochannel_t *ioc); +mix_io_read_char (mix_iochannel_t *ioc); extern gboolean -mix_io_write_word_array_as_char (mix_iochannel_t *ioc, - const mix_word_t *w, size_t s); +mix_io_write_word_array_as_char (mix_iochannel_t *ioc, + const mix_word_t *w, size_t s); extern gboolean mix_io_read_word_array_as_char (mix_iochannel_t *ioc, 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_; } @@ -121,6 +123,13 @@ write_ (mix_device_t *dev, const mix_word_t *block) } 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) { gboolean result; @@ -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_; diff --git a/mixlib/xmix_device.h b/mixlib/xmix_device.h index faa8334..a05d207 100644 --- a/mixlib/xmix_device.h +++ b/mixlib/xmix_device.h @@ -3,22 +3,22 @@ * ------------------------------------------------------------------ * Last change: Time-stamp: <2001-05-07 23:59:35 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 * 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. - * + * */ @@ -47,14 +47,15 @@ typedef struct mix_device_vtable_t mix_dev_destroy_t destroy; } mix_device_vtable_t; -/* default vtable */ +/* default vtables */ extern const mix_device_vtable_t *DEF_DEV_VTABLE_; +extern const mix_device_vtable_t *CONSOLE_DEV_VTABLE_; /* Actual definition of a mix device, which can be cast to a mix file. */ -struct mix_device_t +struct mix_device_t { mix_iochannel_t *file; mix_device_type_t type; |