From c524c5859e7b92b189a6ee0475f0856a71441c3a Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 9 Nov 2018 20:49:20 -0800 Subject: GLK: Add garglk_unput_string methods --- engines/gargoyle/glk.cpp | 25 +++++++++------------ engines/gargoyle/glk.h | 17 +++++++++----- engines/gargoyle/streams.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++ engines/gargoyle/streams.h | 20 +++++++++++++++++ 4 files changed, 96 insertions(+), 19 deletions(-) diff --git a/engines/gargoyle/glk.cpp b/engines/gargoyle/glk.cpp index d8152428ab..8beca88f2c 100644 --- a/engines/gargoyle/glk.cpp +++ b/engines/gargoyle/glk.cpp @@ -1115,39 +1115,36 @@ glsi32 Glk::glk_date_to_simple_time_local(const glkdate_t *date, glui32 factor) /* XXX non-official Glk functions that may or may not exist */ -char *garglk_fileref_get_name(frefid_t fref) { - // TODO - return nullptr; +const char *Glk::garglk_fileref_get_name(frefid_t fref) const { + return fref->_filename.c_str(); } void Glk::garglk_set_program_name(const char *name) { - // TODO + // Program name isn't displayed } void Glk::garglk_set_program_info(const char *info) { - // TODO + // Program info isn't displayed } void Glk::garglk_set_story_name(const char *name) { - // TODO + // Story name isn't displayed } void Glk::garglk_set_story_title(const char *title) { - // TODO + // Story title isn't displayed } void Glk::garglk_set_config(const char *name) { - // TODO + // No implementation } -/* garglk_unput_string - removes the specified string from the end of the output buffer, if -* indeed it is there. */ -void Glk::garglk_unput_string(char *str) { - // TODO +void Glk::garglk_unput_string(const char *str) { + _streams->getCurrent()->unputBuffer(str, strlen(str)); } -void Glk::garglk_unput_string_uni(glui32 *str) { - // TODO +void Glk::garglk_unput_string_uni(const glui32 *str) { + _streams->getCurrent()->unputBufferUni(str, strlen_uni(str)); } void Glk::garglk_set_zcolors(glui32 fg, glui32 bg) { diff --git a/engines/gargoyle/glk.h b/engines/gargoyle/glk.h index 7312a35d8e..eb3e68d9a6 100644 --- a/engines/gargoyle/glk.h +++ b/engines/gargoyle/glk.h @@ -260,7 +260,7 @@ public: /* XXX non-official Glk functions that may or may not exist */ #define GARGLK 1 - char* garglk_fileref_get_name(frefid_t fref); + const char *garglk_fileref_get_name(frefid_t fref) const; void garglk_set_program_name(const char *name); void garglk_set_program_info(const char *info); @@ -268,10 +268,17 @@ public: void garglk_set_story_title(const char *title); void garglk_set_config(const char *name); - /* garglk_unput_string - removes the specified string from the end of the output buffer, if - * indeed it is there. */ - void garglk_unput_string(char *str); - void garglk_unput_string_uni(glui32 *str); + /** + * Removes the specified string from the end of the output buffer, if + * indeed it is there. + */ + void garglk_unput_string(const char *str); + + /** + * Removes the specified string from the end of the output buffer, if + * indeed it is there. + */ + void garglk_unput_string_uni(const glui32 *str); void garglk_set_zcolors(glui32 fg, glui32 bg); void garglk_set_zcolors_stream(strid_t str, glui32 fg, glui32 bg); diff --git a/engines/gargoyle/streams.cpp b/engines/gargoyle/streams.cpp index 24917c56dd..0f95984046 100644 --- a/engines/gargoyle/streams.cpp +++ b/engines/gargoyle/streams.cpp @@ -147,6 +147,59 @@ void WindowStream::putBufferUni(const uint32 *buf, size_t len) { _window->_echoStream->putBufferUni(buf, len); } +void WindowStream::unputBuffer(const char *buf, size_t len) { + glui32 lx; + const char *cx; + + if (!_writable) + return; + + if (_window->_lineRequest || _window->_lineRequestUni) { + if (g_conf->_safeClicks && g_vm->_events->_forceClick) { + _window->cancelLineEvent(nullptr); + g_vm->_events->_forceClick = false; + } else { + warning("unput_buffer: window has pending line request"); + return; + } + } + + for (lx = 0, cx = buf + len - 1; lxunputCharUni(*cx)) + break; + _writeCount--; + } + if (_window->_echoStream) + _window->_echoStream->unputBuffer(buf, len); +} + +void WindowStream::unputBufferUni(const glui32 *buf, size_t len) { + glui32 lx; + const glui32 *cx; + + if (!_writable) + return; + + if (_window->_lineRequest || _window->_lineRequestUni) { + if (g_conf->_safeClicks && g_vm->_events->_forceClick) { + _window->cancelLineEvent(nullptr); + g_vm->_events->_forceClick = false; + } else { + warning("unput_buffer: window has pending line request"); + return; + } + } + + for (lx = 0, cx = buf + len - 1; lxunputCharUni(*cx)) + break; + _writeCount--; + } + + if (_window->_echoStream) + _window->_echoStream->unputBufferUni(buf, len); +} + void WindowStream::setStyle(glui32 val) { if (!_writable) return; diff --git a/engines/gargoyle/streams.h b/engines/gargoyle/streams.h index 16f63dbf0b..02e2f3b7e6 100644 --- a/engines/gargoyle/streams.h +++ b/engines/gargoyle/streams.h @@ -191,6 +191,16 @@ public: */ virtual void putBufferUni(const uint32 *buf, size_t len) = 0; + /** + * Remove a string from the end of the stream, if indeed it is at the end + */ + virtual void unputBuffer(const char *buf, size_t len) {} + + /** + * Remove a string from the end of the stream, if indeed it is at the end + */ + virtual void unputBufferUni(const glui32 *buf, size_t len) {} + /** * Send a line to the stream with a trailing newline */ @@ -288,6 +298,16 @@ public: */ virtual void putBufferUni(const uint32 *buf, size_t len) override; + /** + * Remove a string from the end of the stream, if indeed it is at the end + */ + virtual void unputBuffer(const char *buf, size_t len) override; + + /** + * Remove a string from the end of the stream, if indeed it is at the end + */ + virtual void unputBufferUni(const glui32 *buf, size_t len) override; + virtual void setStyle(glui32 val) override; /** -- cgit v1.2.3