qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Michael Hanselmann <qemu@hansmi.ch>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] Implement ^W in readline.c
Date: Sat, 23 Jun 2007 00:24:10 +0200	[thread overview]
Message-ID: <20070622222410.GA27805@hansmi.ch> (raw)

Hello

The patch below implements ^W (Ctrl+W) in readline.c, allowing it to be
used in the monitor.

Signed-off-by: Michael Hanselmann <qemu@hansmi.ch>

Greets,
Michael

---
Index: readline.c
===================================================================
RCS file: /sources/qemu/qemu/readline.c,v
retrieving revision 1.1
diff -u -b -B -r1.1 readline.c
--- readline.c	1 Aug 2004 21:52:19 -0000	1.1
+++ readline.c	22 Jun 2007 22:17:47 -0000
@@ -156,6 +156,45 @@
     }
 }
 
+static void term_backword(void)
+{
+    int start;
+
+    if (term_cmd_buf_index == 0 || term_cmd_buf_index > term_cmd_buf_size) {
+        return;
+    }
+
+    start = term_cmd_buf_index - 1;
+
+    /* find first word (backwards) */
+    while (start > 0) {
+        if (!isspace(term_cmd_buf[start])) {
+            break;
+        }
+
+        --start;
+    }
+
+    /* find first space (backwards) */
+    while (start > 0) {
+        if (isspace(term_cmd_buf[start])) {
+            ++start;
+            break;
+        }
+
+        --start;
+    }
+
+    /* remove word */
+    if (start < term_cmd_buf_index) {
+        memmove(term_cmd_buf + start,
+                term_cmd_buf + term_cmd_buf_index,
+                term_cmd_buf_size - term_cmd_buf_index);
+        term_cmd_buf_size -= term_cmd_buf_index - start;
+        term_cmd_buf_index = start;
+    }
+}
+
 static void term_bol(void)
 {
     term_cmd_buf_index = 0;
@@ -338,6 +377,10 @@
             /* NOTE: readline_start can be called here */
             term_readline_func(term_readline_opaque, term_cmd_buf);
             break;
+        case 23:
+            /* ^W */
+            term_backword();
+            break;
         case 27:
             term_esc_state = IS_ESC;
             break;

                 reply	other threads:[~2007-06-22 22:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070622222410.GA27805@hansmi.ch \
    --to=qemu@hansmi.ch \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).