From patchwork Fri Jan 6 08:55:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 711756 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tvzNl3jbGz9t0w for ; Fri, 6 Jan 2017 20:13:10 +1100 (AEDT) Received: from localhost ([::1]:51325 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cPQaB-0004Yb-5j for incoming@patchwork.ozlabs.org; Fri, 06 Jan 2017 04:13:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46309) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cPQJg-0006RE-Vw for qemu-devel@nongnu.org; Fri, 06 Jan 2017 03:56:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cPQJe-0008N5-Gr for qemu-devel@nongnu.org; Fri, 06 Jan 2017 03:56:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42688) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cPQJe-0008MI-CO for qemu-devel@nongnu.org; Fri, 06 Jan 2017 03:56:02 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8C3F87F7C8; Fri, 6 Jan 2017 08:56:02 +0000 (UTC) Received: from nilsson.home.kraxel.org (ovpn-116-38.ams2.redhat.com [10.36.116.38]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v068u1Fe021149; Fri, 6 Jan 2017 03:56:02 -0500 Received: by nilsson.home.kraxel.org (Postfix, from userid 500) id 6C87881627; Fri, 6 Jan 2017 09:55:59 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 6 Jan 2017 09:55:37 +0100 Message-Id: <1483692945-9866-10-git-send-email-kraxel@redhat.com> In-Reply-To: <1483692945-9866-1-git-send-email-kraxel@redhat.com> References: <1483692945-9866-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 06 Jan 2017 08:56:02 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 09/17] wctablet: add wctablet_shift_input X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann , avg.tolik@gmail.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Helper function to drop leading chars from the input buffer. Signed-off-by: Gerd Hoffmann --- backends/wctablet.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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;