diff mbox

[09/17] wctablet: add wctablet_shift_input

Message ID 1483692945-9866-10-git-send-email-kraxel@redhat.com
State New, archived
Headers show

Commit Message

Gerd Hoffmann Jan. 6, 2017, 8:55 a.m. UTC
Helper function to drop leading chars from the input buffer.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 backends/wctablet.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/backends/wctablet.c b/backends/wctablet.c
index d0ee0e4..2b14241 100644
--- a/backends/wctablet.c
+++ b/backends/wctablet.c
@@ -141,6 +141,13 @@  static int wctablet_check_command(uint8_t *arr, int count)
     return -1;
 }
 
+static void wctablet_shift_input(TabletState *tablet, int count)
+{
+    tablet->query_index -= count;
+    memmove(tablet->query, tablet->query + count, tablet->query_index);
+    tablet->query[tablet->query_index] = 0;
+}
+
 static void wctablet_queue_output(TabletState *tablet, uint8_t *buf, int count)
 {
     if (tablet->outlen + count > sizeof(tablet->outbuf)) {
@@ -232,8 +239,7 @@  static int wctablet_chr_write(struct CharDriverState *s,
     while (tablet->query_index > 0 && (tablet->query[0] == '@'  ||
                                        tablet->query[0] == '\r' ||
                                        tablet->query[0] == '\n')) {
-        memmove(tablet->query, tablet->query + 1, tablet->query_index);
-        tablet->query_index--;
+        wctablet_shift_input(tablet, 1);
     }
     if (!tablet->query_index) {
         return len;