projects
/
rodin
/
chimara.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Some hyperlink code.
[rodin/chimara.git]
/
libchimara
/
strio.c
diff --git
a/libchimara/strio.c
b/libchimara/strio.c
index a33f13f7f53413e41037e3d41dcf90e0c1d79a36..3309392a8da71660abdfca5c6f26d385202a59bf 100644
(file)
--- a/
libchimara/strio.c
+++ b/
libchimara/strio.c
@@
-43,7
+43,7
@@
write_utf8_to_grid(winid_t win, gchar *s)
GtkTextIter end = start;
gtk_text_iter_forward_to_line_end(&end);
gtk_text_buffer_delete(buffer, &start, &end);
GtkTextIter end = start;
gtk_text_iter_forward_to_line_end(&end);
gtk_text_buffer_delete(buffer, &start, &end);
- gtk_text_buffer_insert
(buffer, &start, s + (length - chars_left), available_space
);
+ gtk_text_buffer_insert
_with_tags_by_name(buffer, &start, s + (length - chars_left), available_space, win->window_stream->style, NULL
);
chars_left -= available_space;
gtk_text_iter_forward_line(&start);
available_space = win->width;
chars_left -= available_space;
gtk_text_iter_forward_line(&start);
available_space = win->width;
@@
-53,7
+53,7
@@
write_utf8_to_grid(winid_t win, gchar *s)
GtkTextIter end = start;
gtk_text_iter_forward_chars(&end, chars_left);
gtk_text_buffer_delete(buffer, &start, &end);
GtkTextIter end = start;
gtk_text_iter_forward_chars(&end, chars_left);
gtk_text_buffer_delete(buffer, &start, &end);
- gtk_text_buffer_insert
(buffer, &start, s + (length - chars_left), -1
);
+ gtk_text_buffer_insert
_with_tags_by_name(buffer, &start, s + (length - chars_left), -1, win->window_stream->style, NULL
);
}
gtk_text_buffer_move_mark(buffer, cursor, &start);
}
gtk_text_buffer_move_mark(buffer, cursor, &start);
@@
-61,25
+61,43
@@
write_utf8_to_grid(winid_t win, gchar *s)
gdk_threads_leave();
}
gdk_threads_leave();
}
+
/* Internal function: write a UTF-8 string to a text buffer window's text buffer. */
static void
/* Internal function: write a UTF-8 string to a text buffer window's text buffer. */
static void
-write_utf8_to_window(winid_t win, gchar *s)
+write_utf8_to_window
_buffer
(winid_t win, gchar *s)
{
if(win->input_request_type == INPUT_REQUEST_LINE || win->input_request_type == INPUT_REQUEST_LINE_UNICODE)
{
ILLEGAL("Tried to print to a text buffer window with line input pending.");
return;
}
{
if(win->input_request_type == INPUT_REQUEST_LINE || win->input_request_type == INPUT_REQUEST_LINE_UNICODE)
{
ILLEGAL("Tried to print to a text buffer window with line input pending.");
return;
}
+
+ // Write to the buffer
+ g_string_append(win->buffer, s);
+}
+/* Internal function: flush a window's text buffer to the screen. */
+void
+flush_window_buffer(winid_t win)
+{
+ if(win->buffer->len == 0)
+ return;
+
gdk_threads_enter();
GtkTextBuffer *buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(win->widget) );
GtkTextIter iter;
gtk_text_buffer_get_end_iter(buffer, &iter);
gdk_threads_enter();
GtkTextBuffer *buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(win->widget) );
GtkTextIter iter;
gtk_text_buffer_get_end_iter(buffer, &iter);
- gtk_text_buffer_insert_with_tags_by_name(buffer, &iter,
s
, -1, win->window_stream->style, NULL);
+ gtk_text_buffer_insert_with_tags_by_name(buffer, &iter,
win->buffer->str
, -1, win->window_stream->style, NULL);
gdk_threads_leave();
gdk_threads_leave();
+
+ ChimaraGlk *glk = CHIMARA_GLK(gtk_widget_get_ancestor(win->widget, CHIMARA_TYPE_GLK));
+ g_assert(glk);
+ g_signal_emit_by_name(glk, "text-buffer-output", win->rock, win->buffer->str);
+
+ g_string_truncate(win->buffer, 0);
}
/* Internal function: write a Latin-1 buffer with length to a stream. */
}
/* Internal function: write a Latin-1 buffer with length to a stream. */
@@
-119,7
+137,7
@@
write_buffer_to_stream(strid_t str, gchar *buf, glui32 len)
gchar *utf8 = convert_latin1_to_utf8(buf, len);
if(utf8 != NULL)
{
gchar *utf8 = convert_latin1_to_utf8(buf, len);
if(utf8 != NULL)
{
- write_utf8_to_window(str->window, utf8);
+ write_utf8_to_window
_buffer
(str->window, utf8);
g_free(utf8);
}
}
g_free(utf8);
}
}
@@
-220,7
+238,7
@@
write_buffer_to_stream_uni(strid_t str, glui32 *buf, glui32 len)
gchar *utf8 = convert_ucs4_to_utf8(buf, len);
if(utf8 != NULL)
{
gchar *utf8 = convert_ucs4_to_utf8(buf, len);
if(utf8 != NULL)
{
- write_utf8_to_window(str->window, utf8);
+ write_utf8_to_window
_buffer
(str->window, utf8);
g_free(utf8);
}
}
g_free(utf8);
}
}
@@
-337,6
+355,9
@@
void
glk_put_string_stream(strid_t str, char *s)
{
VALID_STREAM(str, return);
glk_put_string_stream(strid_t str, char *s)
{
VALID_STREAM(str, return);
+ if(*s == 0)
+ return;
+
g_return_if_fail(str->file_mode != filemode_Read);
write_buffer_to_stream(str, s, strlen(s));
g_return_if_fail(str->file_mode != filemode_Read);
write_buffer_to_stream(str, s, strlen(s));
@@
-355,6
+376,9
@@
void
glk_put_string_stream_uni(strid_t str, glui32 *s)
{
VALID_STREAM(str, return);
glk_put_string_stream_uni(strid_t str, glui32 *s)
{
VALID_STREAM(str, return);
+ if(*s == 0)
+ return;
+
g_return_if_fail(str->file_mode != filemode_Read);
/* An impromptu strlen() for glui32 arrays */
g_return_if_fail(str->file_mode != filemode_Read);
/* An impromptu strlen() for glui32 arrays */
@@
-379,6
+403,9
@@
void
glk_put_buffer_stream(strid_t str, char *buf, glui32 len)
{
VALID_STREAM(str, return);
glk_put_buffer_stream(strid_t str, char *buf, glui32 len)
{
VALID_STREAM(str, return);
+ if(len == 0)
+ return;
+
g_return_if_fail(str->file_mode != filemode_Read);
write_buffer_to_stream(str, buf, len);
g_return_if_fail(str->file_mode != filemode_Read);
write_buffer_to_stream(str, buf, len);
@@
-398,6
+425,9
@@
void
glk_put_buffer_stream_uni(strid_t str, glui32 *buf, glui32 len)
{
VALID_STREAM(str, return);
glk_put_buffer_stream_uni(strid_t str, glui32 *buf, glui32 len)
{
VALID_STREAM(str, return);
+ if(len == 0)
+ return;
+
g_return_if_fail(str->file_mode != filemode_Read);
write_buffer_to_stream_uni(str, buf, len);
g_return_if_fail(str->file_mode != filemode_Read);
write_buffer_to_stream_uni(str, buf, len);
@@
-880,9
+910,14
@@
glk_get_line_stream(strid_t str, char *buf, glui32 len)
}
else /* Regular binary file */
{
}
else /* Regular binary file */
{
- fgets(buf, len, str->file_pointer);
- str->read_count += strlen(buf);
- return strlen(buf);
+ if( !fgets(buf, len, str->file_pointer) ) {
+ *buf = 0;
+ return 0;
+ }
+
+ int nread = strlen(buf);
+ str->read_count += nread;
+ return nread;
}
}
else /* Text mode is the same for Unicode and regular files */
}
}
else /* Text mode is the same for Unicode and regular files */
@@
-1018,10
+1053,14
@@
glk_get_line_stream_uni(strid_t str, glui32 *buf, glui32 len)
else /* Regular binary file */
{
gchar *readbuffer = g_new0(gchar, len);
else /* Regular binary file */
{
gchar *readbuffer = g_new0(gchar, len);
- fgets(readbuffer, len, str->file_pointer);
- glui32 count = strlen(readbuffer) + 1; /* Copy terminator */
+ if( !fgets(readbuffer, len, str->file_pointer) ) {
+ *buf = 0;
+ return 0;
+ }
+
+ glui32 count = strlen(readbuffer);
int foo;
int foo;
- for(foo = 0; foo < count
; foo++)
+ for(foo = 0; foo < count
+ 1; foo++) /* Copy terminator */
buf[foo] = (unsigned char)(readbuffer[foo]);
str->read_count += count;
return count;
buf[foo] = (unsigned char)(readbuffer[foo]);
str->read_count += count;
return count;
@@
-1109,7
+1148,7
@@
glk_stream_get_position(strid_t str)
* glk_stream_set_position:
* @str: A file or memory stream.
* @pos: The position to set the mark to, relative to @seekmode.
* glk_stream_set_position:
* @str: A file or memory stream.
* @pos: The position to set the mark to, relative to @seekmode.
- * @seekmode: One of
#seekmode_Start, #seekmode_Current, or #
seekmode_End.
+ * @seekmode: One of
%seekmode_Start, %seekmode_Current, or %
seekmode_End.
*
* Sets the position of the read/write mark in @str. The position is controlled
* by @pos, and the meaning of @pos is controlled by @seekmode. See the
*
* Sets the position of the read/write mark in @str. The position is controlled
* by @pos, and the meaning of @pos is controlled by @seekmode. See the