From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1EpasV-0002oi-1a for qemu-devel@nongnu.org; Thu, 22 Dec 2005 19:33:47 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1EpasT-0002oI-Ib for qemu-devel@nongnu.org; Thu, 22 Dec 2005 19:33:46 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EpasT-0002oD-9u for qemu-devel@nongnu.org; Thu, 22 Dec 2005 19:33:45 -0500 Received: from [66.249.82.193] (helo=xproxy.gmail.com) by monty-python.gnu.org with esmtp (Exim 4.34) id 1Eparf-0000Rz-Sc for qemu-devel@nongnu.org; Thu, 22 Dec 2005 19:32:56 -0500 Received: by xproxy.gmail.com with SMTP id s6so395461wxc for ; Thu, 22 Dec 2005 16:32:40 -0800 (PST) Message-ID: Date: Fri, 23 Dec 2005 01:32:40 +0100 From: andrzej zaborowski MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_9754_8159363.1135297960050" Subject: [Qemu-devel] [PATCH] Slight monitor enhancements Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org ------=_Part_9754_8159363.1135297960050 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hello, I'm attaching two patches: One is for the monitor's "sendkey" command. It adds: - a very basic -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=3D03/08/21/143258 ------=_Part_9754_8159363.1135297960050 Content-Type: application/octet-stream; name=qemu-enhanced-sendkey.patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="qemu-enhanced-sendkey.patch" 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: ------=_Part_9754_8159363.1135297960050 Content-Type: application/octet-stream; name=qemu-history-save.patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="qemu-history-save.patch" 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); ------=_Part_9754_8159363.1135297960050--