X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=libchimara%2Fstrio.c;h=24899c5e34c2516254897c44157f7a851949d478;hb=1f1c29341f7da406b8cbbe72793eceefcb69d058;hp=ab8443f5f8eb2823576f995bf6cafb6976b7db33;hpb=d46503e2c419d4c1235f76d98b889fc1cad2d856;p=projects%2Fchimara%2Fchimara.git
diff --git a/libchimara/strio.c b/libchimara/strio.c
index ab8443f..24899c5 100644
--- a/libchimara/strio.c
+++ b/libchimara/strio.c
@@ -61,15 +61,15 @@ flush_window_buffer(winid_t win)
gtk_text_buffer_insert(buffer, &end, win->buffer->str, -1);
gtk_text_buffer_get_iter_at_offset(buffer, &start, start_offset);
- // Default style
- gtk_text_buffer_apply_tag(buffer, default_tag, &start, &end);
-
// Player's style overrides
gtk_text_buffer_apply_tag(buffer, style_tag, &start, &end);
// GLK Program's style overrides
gtk_text_buffer_apply_tag(buffer, glk_style_tag, &start, &end);
+ // Default style
+ gtk_text_buffer_apply_tag(buffer, default_tag, &start, &end);
+
// Link style overrides
if(win->window_stream->hyperlink_mode) {
GtkTextTag *link_style_tag = gtk_text_tag_table_lookup(tags, "hyperlink");
@@ -111,6 +111,7 @@ flush_window_buffer(winid_t win)
gint available_space = win->width - gtk_text_iter_get_line_offset(&insert);
GtkTextTagTable *tags = gtk_text_buffer_get_tag_table(buffer);
+
GtkTextTag *default_tag = gtk_text_tag_table_lookup(tags, "default");
GtkTextTag *style_tag = gtk_text_tag_table_lookup(tags, win->window_stream->style);
GtkTextTag *glk_style_tag = gtk_text_tag_table_lookup(tags, win->window_stream->glk_style);
@@ -714,8 +715,8 @@ glk_get_char_stream(strid_t str)
* glk_get_char_stream_uni:
* @str: An input stream.
*
- * Reads one character from the stream @str. The result will be between 0 and
- * 0x7FFFFFFF. If the end of the stream has been reached, the result will be -1.
+ * Reads one character from the stream @str. If the end of the stream has been
+ * reached, the result will be -1.
*
* Returns: A value between 0 and 0x7FFFFFFF, or -1 on end of stream.
*/
@@ -936,7 +937,7 @@ glk_get_buffer_stream_uni(strid_t str, glui32 *buf, glui32 len)
* @len - 1
*
* characters have been read or a newline has been read. It then puts a
- * terminal null ('\0'
) aracter on
+ * terminal null ('\0'
) character on
* the end. It returns the number of characters actually read, including the
* newline (if there is one) but not including the terminal null.
*
@@ -998,26 +999,26 @@ glk_get_line_stream(strid_t str, char *buf, glui32 len)
if(str->unicode) /* Binary file with 4-byte characters */
{
/* Do it character-by-character */
- int foo;
- for(foo = 0; foo < len - 1; foo++)
+ int copycount;
+ for(copycount = 0; copycount < len - 1; copycount++)
{
glsi32 ch = read_ucs4be_char_from_file(str->file_pointer);
if(ch == -1)
{
- buf[foo] = '\0';
- return foo - 1;
+ buf[copycount] = '\0';
+ return copycount;
}
str->read_count++;
if(is_unicode_newline(ch, str->file_pointer, FALSE))
{
- buf[foo] = '\n';
- buf[foo + 1] = '\0';
- return foo;
+ buf[copycount++] = '\n';
+ buf[copycount] = '\0';
+ return copycount;
}
- buf[foo] = (ch > 0xFF)? '?' : (char)ch;
+ buf[copycount] = (ch > 0xFF)? '?' : (char)ch;
}
buf[len] = '\0';
- return foo;
+ return copycount;
}
else /* Regular binary file */
{
@@ -1140,26 +1141,26 @@ glk_get_line_stream_uni(strid_t str, glui32 *buf, glui32 len)
if(str->unicode) /* Binary file with 4-byte characters */
{
/* Do it character-by-character */
- int foo;
- for(foo = 0; foo < len - 1; foo++)
+ int copycount;
+ for(copycount = 0; copycount < len - 1; copycount++)
{
glsi32 ch = read_ucs4be_char_from_file(str->file_pointer);
if(ch == -1)
{
- buf[foo] = 0;
- return foo - 1;
+ buf[copycount] = 0;
+ return copycount;
}
str->read_count++;
if(is_unicode_newline(ch, str->file_pointer, FALSE))
{
- buf[foo] = ch; /* Preserve newline types??? */
- buf[foo + 1] = 0;
- return foo;
+ buf[copycount++] = ch; /* Preserve newline types??? */
+ buf[copycount] = 0;
+ return copycount;
}
- buf[foo] = ch;
+ buf[copycount] = ch;
}
buf[len] = 0;
- return foo;
+ return copycount;
}
else /* Regular binary file */
{
@@ -1236,6 +1237,14 @@ glk_get_line_stream_uni(strid_t str, glui32 *buf, glui32 len)
* good for much anyhow.
*
*
+ * glk_stream_get_position() on a window stream will always return zero.
+ *
+ *
+ * It might make more sense to return the number of characters written to the
+ * window, but existing libraries do not support this and it's not really
+ * worth adding the feature.
+ *
+ *
* Returns: position of the read/write mark in @str.
*/
glui32
@@ -1249,6 +1258,8 @@ glk_stream_get_position(strid_t str)
return str->mark;
case STREAM_TYPE_FILE:
return ftell(str->file_pointer);
+ case STREAM_TYPE_WINDOW:
+ return 0;
default:
ILLEGAL_PARAM("Seeking illegal on stream type: %u", str->type);
return 0;
@@ -1280,6 +1291,9 @@ glk_stream_get_position(strid_t str)
*
* Again, in Latin-1 streams, characters are bytes. In Unicode streams,
* characters are 32-bit words, or four bytes each.
+ *
+ * A window stream doesn't have a movable mark, so calling
+ * glk_stream_set_position() has no effect.
*/
void
glk_stream_set_position(strid_t str, glsi32 pos, glui32 seekmode)
@@ -1317,6 +1331,8 @@ glk_stream_set_position(strid_t str, glsi32 pos, glui32 seekmode)
WARNING("Seek failed on file stream");
break;
}
+ case STREAM_TYPE_WINDOW:
+ break; /* Quietly do nothing */
default:
ILLEGAL_PARAM("Seeking illegal on stream type: %u", str->type);
return;