#include "charset.h"
+#include "magic.h"
#include "stream.h"
+#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <glib.h>
str->write_count += len;
break;
default:
- g_warning("%s: Writing to this kind of window unsupported.", __func__);
+ ILLEGAL_PARAM("Unknown window type: %u", str->window->type);
}
/* Now write the same buffer to the window's echo stream */
str->write_count += len;
break;
default:
- g_warning("%s: Writing to this kind of stream unsupported.", __func__);
+ ILLEGAL_PARAM("Unknown stream type: %u", str->type);
}
}
str->write_count += len;
break;
default:
- g_warning("%s: Writing to this kind of window unsupported.", __func__);
+ ILLEGAL_PARAM("Unknown window type: %u", str->window->type);
}
/* Now write the same buffer to the window's echo stream */
str->write_count += len;
break;
default:
- g_warning("%s: Writing to this kind of stream unsupported.", __func__);
+ ILLEGAL_PARAM("Unknown stream type: %u", str->type);
}
}
void
glk_put_char_stream(strid_t str, unsigned char ch)
{
- g_return_if_fail(str != NULL);
+ VALID_STREAM(str, return);
g_return_if_fail(str->file_mode != filemode_Read);
write_buffer_to_stream(str, (gchar *)&ch, 1);
void
glk_put_char_stream_uni(strid_t str, glui32 ch)
{
- g_return_if_fail(str != NULL);
+ VALID_STREAM(str, return);
g_return_if_fail(str->file_mode != filemode_Read);
write_buffer_to_stream_uni(str, &ch, 1);
void
glk_put_string_stream(strid_t str, char *s)
{
- g_return_if_fail(str != NULL);
+ VALID_STREAM(str, return);
g_return_if_fail(str->file_mode != filemode_Read);
write_buffer_to_stream(str, s, strlen(s));
void
glk_put_string_stream_uni(strid_t str, glui32 *s)
{
- g_return_if_fail(str != NULL);
+ VALID_STREAM(str, return);
g_return_if_fail(str->file_mode != filemode_Read);
/* An impromptu strlen() for glui32 arrays */
void
glk_put_buffer_stream(strid_t str, char *buf, glui32 len)
{
- g_return_if_fail(str != NULL);
+ VALID_STREAM(str, return);
g_return_if_fail(str->file_mode != filemode_Read);
write_buffer_to_stream(str, buf, len);
void
glk_put_buffer_stream_uni(strid_t str, glui32 *buf, glui32 len)
{
- g_return_if_fail(str != NULL);
+ VALID_STREAM(str, return);
g_return_if_fail(str->file_mode != filemode_Read);
write_buffer_to_stream_uni(str, buf, len);
glsi32 ch2 = utf8? read_utf8_char_from_file(fp) :
read_ucs4be_char_from_file(fp);
if(ch2 != 0x0A)
- fseek(fp, utf8? -1 : -4, SEEK_CUR);
+ if(fseek(fp, utf8? -1 : -4, SEEK_CUR) == -1);
+ WARNING_S("Seek failed on stream", g_strerror(errno) );
return TRUE;
}
return FALSE;
return ch;
}
default:
- g_warning("%s: Reading from this kind of stream unsupported.", __func__);
+ ILLEGAL_PARAM("Reading illegal on stream type: %u", str->type);
return -1;
}
}
glsi32
glk_get_char_stream(strid_t str)
{
- g_return_val_if_fail(str != NULL, -1);
+ VALID_STREAM(str, return -1);
g_return_val_if_fail(str->file_mode == filemode_Read || str->file_mode == filemode_ReadWrite, -1);
glsi32 ch = get_char_stream_common(str);
glsi32
glk_get_char_stream_uni(strid_t str)
{
- g_return_val_if_fail(str != NULL, -1);
+ VALID_STREAM(str, return -1);
g_return_val_if_fail(str->file_mode == filemode_Read || str->file_mode == filemode_ReadWrite, -1);
return get_char_stream_common(str);
glui32
glk_get_buffer_stream(strid_t str, char *buf, glui32 len)
{
- g_return_val_if_fail(str != NULL, 0);
+ VALID_STREAM(str, return 0);
g_return_val_if_fail(str->file_mode == filemode_Read || str->file_mode == filemode_ReadWrite, 0);
g_return_val_if_fail(buf != NULL, 0);
if(count % 4 != 0)
{
count -= count % 4;
- g_warning("%s: Incomplete character in binary Unicode file.", __func__);
+ WARNING("Incomplete character in binary Unicode file");
}
int foo;
return foo;
}
default:
- g_warning("%s: Reading from this kind of stream unsupported.", __func__);
+ ILLEGAL_PARAM("Reading illegal on stream type: %u", str->type);
return 0;
}
}
glui32
glk_get_buffer_stream_uni(strid_t str, glui32 *buf, glui32 len)
{
- g_return_val_if_fail(str != NULL, 0);
+ VALID_STREAM(str, return 0);
g_return_val_if_fail(str->file_mode == filemode_Read || str->file_mode == filemode_ReadWrite, 0);
g_return_val_if_fail(buf != NULL, 0);
if(count % 4 != 0)
{
count -= count % 4;
- g_warning("%s: Incomplete character in binary Unicode file.", __func__);
+ WARNING("Incomplete character in binary Unicode file");
}
int foo;
return foo;
}
default:
- g_warning("%s: Reading from this kind of stream unsupported.", __func__);
+ ILLEGAL_PARAM("Reading illegal on stream type: %u", str->type);
return 0;
}
}
glui32
glk_get_line_stream(strid_t str, char *buf, glui32 len)
{
- g_return_val_if_fail(str != NULL, 0);
+ VALID_STREAM(str, return 0);
g_return_val_if_fail(str->file_mode == filemode_Read || str->file_mode == filemode_ReadWrite, 0);
g_return_val_if_fail(buf != NULL, 0);
return foo;
}
default:
- g_warning("%s: Reading from this kind of stream unsupported.", __func__);
+ ILLEGAL_PARAM("Reading illegal on stream type: %u", str->type);
return 0;
}
}
glui32
glk_get_line_stream_uni(strid_t str, glui32 *buf, glui32 len)
{
- g_return_val_if_fail(str != NULL, 0);
+ VALID_STREAM(str, return 0);
g_return_val_if_fail(str->file_mode == filemode_Read || str->file_mode == filemode_ReadWrite, 0);
g_return_val_if_fail(buf != NULL, 0);
return foo;
}
default:
- g_warning("%s: Reading from this kind of stream unsupported.", __func__);
+ ILLEGAL_PARAM("Reading illegal on stream type: %u", str->type);
return 0;
}
}
glui32
glk_stream_get_position(strid_t str)
{
- g_return_val_if_fail(str != NULL, 0);
+ VALID_STREAM(str, return 0);
switch(str->type)
{
case STREAM_TYPE_FILE:
return ftell(str->file_pointer);
default:
- g_warning("%s: Seeking not supported on this type of stream.",
- __func__);
+ ILLEGAL_PARAM("Seeking illegal on stream type: %u", str->type);
return 0;
}
}
void
glk_stream_set_position(strid_t str, glsi32 pos, glui32 seekmode)
{
- g_return_if_fail(str != NULL);
+ VALID_STREAM(str, return);
g_return_if_fail(!(seekmode == seekmode_Start && pos < 0));
g_return_if_fail(!(seekmode == seekmode_End || pos > 0));
case seekmode_Current: str->mark += pos; break;
case seekmode_End: str->mark = str->buflen + pos; break;
default:
- g_assert_not_reached();
+ g_return_if_reached();
return;
}
break;
case seekmode_Current: whence = SEEK_CUR; break;
case seekmode_End: whence = SEEK_END; break;
default:
- g_assert_not_reached();
+ g_return_if_reached();
return;
}
- fseek(str->file_pointer, pos, whence);
+ if(fseek(str->file_pointer, pos, whence) == -1)
+ WARNING("Seek failed on file stream");
break;
}
default:
- g_warning("%s: Seeking not supported on this type of stream.", __func__);
+ ILLEGAL_PARAM("Seeking illegal on stream type: %u", str->type);
return;
}
}