diff mbox

[03/17] wctablet: save all chars in the query buffer

Message ID 1483692945-9866-4-git-send-email-kraxel@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Gerd Hoffmann Jan. 6, 2017, 8:55 a.m. UTC
... instead of storing the first character only, to avoid things break
in case multiple chars are passed in a single wctablet_chr_write call.

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

Patch

diff --git a/backends/wctablet.c b/backends/wctablet.c
index 758c9e8..787da49 100644
--- a/backends/wctablet.c
+++ b/backends/wctablet.c
@@ -234,21 +234,25 @@  static void wctablet_handler(void *opaque)
               qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + tablet->transmit_time);
 }
 
-static int wctablet_chr_write (struct CharDriverState *s,
-                               const uint8_t *buf, int len)
+static int wctablet_chr_write(struct CharDriverState *s,
+                              const uint8_t *buf, int len)
 {
     TabletState *tablet = (TabletState *) s->opaque;
-    uint8_t c = buf[0];
-    uint8_t input;
+    uint8_t i, input;
 
-    if (c == 0x40) {
+    for (i = 0; i < len && tablet->query_index < sizeof(tablet->query) - 1; i++) {
+        tablet->query[tablet->query_index++] = buf[i];
+    }
+    tablet->query[tablet->query_index] = 0;
+
+    while (tablet->query_index > 0 && tablet->query[0] == '@') {
+        memmove(tablet->query, tablet->query + 1, tablet->query_index);
+        tablet->query_index--;
+    }
+    if (!tablet->query_index) {
         return len;
     }
 
-    tablet->query[tablet->query_index++] = c;
-
-    // DPRINTF("Receive: %.2x\n", c);
-
     int comm = wctablet_check_command(tablet->query, tablet->query_index);
 
     if (comm == 1) {