r2923 - trunk/src/host/qemu-neo1973
andrew at sita.openmoko.org
andrew at sita.openmoko.org
Wed Sep 5 18:09:54 CEST 2007
Author: andrew
Date: 2007-09-05 18:09:53 +0200 (Wed, 05 Sep 2007)
New Revision: 2923
Modified:
trunk/src/host/qemu-neo1973/monitor.c
trunk/src/host/qemu-neo1973/readline.c
trunk/src/host/qemu-neo1973/vl.h
Log:
An old patch for persistent monitor commands history.
Modified: trunk/src/host/qemu-neo1973/monitor.c
===================================================================
--- trunk/src/host/qemu-neo1973/monitor.c 2007-09-05 15:40:50 UTC (rev 2922)
+++ trunk/src/host/qemu-neo1973/monitor.c 2007-09-05 16:09:53 UTC (rev 2923)
@@ -2511,6 +2511,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();
+}
+
static void term_event(void *opaque, int event)
{
if (event != CHR_EVENT_RESET)
@@ -2519,7 +2527,7 @@
if (!hide_banner)
term_printf("QEMU %s monitor - type 'help' for more information\n",
QEMU_VERSION);
- monitor_start_input();
+ monitor_init_input();
}
static int is_first_init = 1;
Modified: trunk/src/host/qemu-neo1973/readline.c
===================================================================
--- trunk/src/host/qemu-neo1973/readline.c 2007-09-05 15:40:50 UTC (rev 2922)
+++ trunk/src/host/qemu-neo1973/readline.c 2007-09-05 16:09:53 UTC (rev 2923)
@@ -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
@@ -465,4 +466,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: */
Modified: trunk/src/host/qemu-neo1973/vl.h
===================================================================
--- trunk/src/host/qemu-neo1973/vl.h 2007-09-05 15:40:50 UTC (rev 2922)
+++ trunk/src/host/qemu-neo1973/vl.h 2007-09-05 16:09:53 UTC (rev 2923)
@@ -1681,6 +1681,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);
More information about the commitlog
mailing list