qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: andrzej zaborowski <balrogg@gmail.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] Slight monitor enhancements
Date: Fri, 23 Dec 2005 01:32:40 +0100	[thread overview]
Message-ID: <fb249edb0512221632j45b45daam@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 781 bytes --]

Hello,
I'm attaching two patches:

One is for the monitor's "sendkey" command. It adds:
- a very basic <tab>-completion for the arguments of sendkey,
- the "plus" and "minus" keys so you can use ctrl-alt-plus and
ctrl-alt-minus while in X,
- posibility of giving keys as their scancode numbers, e.g. instead of
"sendkey a" you can issue "sendkey #30" or "sendkey #0x1e" or "sendkey
#036"

The second patch makes the readline save commands history to a file on
exit ("~/.qemu_history" by default) and load it from that file on init
(if the file exists).

I think the first patch is a useful and safe addition.
Regards,
Andrew
--
balrog 2oo5

Dear Outlook users: Please remove me from your address books
http://www.newsforge.com/article.pl?sid=03/08/21/143258

[-- Attachment #2: qemu-enhanced-sendkey.patch --]
[-- Type: application/octet-stream, Size: 1581 bytes --]

diff -Naur qemu/monitor.c qemu-keys/monitor.c
--- qemu/monitor.c	2005-12-05 20:31:52.000000000 +0000
+++ qemu-keys/monitor.c	2005-12-21 20:44:04.000000000 +0000
@@ -695,6 +695,8 @@
     { 0x31, "n" },
     { 0x32, "m" },
     
+    { 0x37, "asterisk" },
+
     { 0x39, "spc" },
     { 0x3a, "caps_lock" },
     { 0x3b, "f1" },
@@ -710,6 +712,9 @@
     { 0x45, "num_lock" },
     { 0x46, "scroll_lock" },
 
+    { 0x4a, "minus" },
+    { 0x4e, "plus" },
+
     { 0x56, "<" },
 
     { 0x57, "f11" },
@@ -735,11 +740,20 @@
 static int get_keycode(const char *key)
 {
     const KeyDef *p;
+    int ret;
+    char *endp;
 
     for(p = key_defs; p->name != NULL; p++) {
         if (!strcmp(key, p->name))
             return p->keycode;
     }
+
+    if (*key == '#') {
+        ret = strtoul(key + 1, &endp, 0);
+        if (ret > 0 && ret < 0x100 && *endp == 0)
+            return ret;
+    }
+
     return -1;
 }
 
@@ -2087,6 +2101,7 @@
     int nb_args, i, len;
     const char *ptype, *str;
     term_cmd_t *cmd;
+    const KeyDef *key;
 
     parse_cmdline(cmdline, &nb_args, args);
 #ifdef DEBUG_COMPLETION
@@ -2148,6 +2163,11 @@
                 for(cmd = info_cmds; cmd->name != NULL; cmd++) {
                     cmd_completion(str, cmd->name);
                 }
+            } else if (!strcmp(cmd->name, "sendkey")) {
+                completion_index = strlen(str);
+                for(key = key_defs; key->name != NULL; key++) {
+                    cmd_completion(str, key->name);
+                }
             }
             break;
         default:












[-- Attachment #3: qemu-history-save.patch --]
[-- Type: application/octet-stream, Size: 2893 bytes --]

diff -Naur qemu-keys/monitor.c qemu-history/monitor.c
--- qemu-keys/monitor.c	2005-12-21 20:44:04.000000000 +0000
+++ qemu-history/monitor.c	2005-12-22 23:03:50.000000000 +0000
@@ -2203,6 +2203,14 @@
     readline_start("(qemu) ", 0, monitor_handle_command1, NULL);
 }
 
+static void monitor_init_input(void)
+{
+    readline_history_restore();
+    atexit(readline_history_save);
+
+    monitor_start_input();
+}
+
 void monitor_init(CharDriverState *hd, int show_banner)
 {
     monitor_hd = hd;
@@ -2211,7 +2219,7 @@
                     QEMU_VERSION);
     }
     qemu_chr_add_read_handler(hd, term_can_read, term_read, NULL);
-    monitor_start_input();
+    monitor_init_input();
 }
 
 /* XXX: use threads ? */
diff -Naur qemu-keys/readline.c qemu-history/readline.c
--- qemu-keys/readline.c	2004-08-01 21:52:19.000000000 +0000
+++ qemu-history/readline.c	2005-12-22 22:52:51.000000000 +0000
@@ -26,6 +26,7 @@
 #define TERM_CMD_BUF_SIZE 4095
 #define TERM_MAX_CMDS 64
 #define NB_COMPLETIONS_MAX 256
+#define HISTORY_FILENAME ".qemu_history"
 
 #define IS_NORM 0
 #define IS_ESC  1
@@ -422,4 +423,65 @@
     return term_history[index];
 }
 
+static FILE *readline_open_historyfile(char *modes)
+{
+    char *filename, *home;
+    FILE *ret;
+
+    home = getenv("HOME");
+    if (!home)
+        return 0;
+
+    filename = qemu_malloc(strlen(home) + 1 + strlen(HISTORY_FILENAME) + 1);
+    if (!filename)
+        return 0;
+
+    sprintf(filename, "%s/" HISTORY_FILENAME, home);
+    ret = fopen(filename, modes);
+    qemu_free(filename);
 
+    return ret;
+}
+
+void readline_history_save(void)
+{
+    int idx;
+    FILE *fd;
+    const char *line;
+
+    fd = readline_open_historyfile("w");
+    if (!fd)
+        return;
+
+    idx = 0;
+    while ((line = readline_get_history(idx ++)))
+        fprintf(fd, "%s\n", line);
+
+    fclose(fd);
+}
+
+void readline_history_restore(void)
+{
+    int idx;
+    FILE *fd;
+    char line[TERM_CMD_BUF_SIZE + 1], *ret;
+
+    fd = readline_open_historyfile("r");
+    if (!fd)
+        return;
+
+    for (idx = 0; idx < TERM_MAX_CMDS; idx ++) {
+        ret = fgets(line, TERM_CMD_BUF_SIZE + 1, fd);
+        if (!ret || *line == 0 || *line == '\n')
+            break;
+
+        ret = strchr(line, '\n');
+        if (ret)
+            *ret = 0;
+
+        term_history[idx] = qemu_strdup(line);
+    }
+
+    fclose(fd);
+}
+/* vim: set ai ts=4 sw=4 et: */
diff -Naur qemu-keys/vl.h qemu-history/vl.h
--- qemu-keys/vl.h	2005-12-05 20:31:52.000000000 +0000
+++ qemu-history/vl.h	2005-12-22 22:53:41.000000000 +0000
@@ -967,6 +967,8 @@
 const char *readline_get_history(unsigned int index);
 void readline_start(const char *prompt, int is_password,
                     ReadLineFunc *readline_func, void *opaque);
+void readline_history_save(void);
+void readline_history_restore(void);
 
 void kqemu_record_dump(void);
 












                 reply	other threads:[~2005-12-23  0:33 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=fb249edb0512221632j45b45daam@mail.gmail.com \
    --to=balrogg@gmail.com \
    --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).