From 6ea314d91439741e95772dfbab98b4135e04bebb Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Thu, 10 Sep 2009 10:58:49 +0200 Subject: [PATCH] convert vc chardev to QemuOpts. new cmd line syntax: -chardev vc,id=name -chardev vc,id=name,width=pixels,height=pixels -chardev vc,id=name,cols=chars,rows=chars Signed-off-by: Gerd Hoffmann Signed-off-by: Anthony Liguori --- console.c | 47 +++++++++++++++++++++++------------------------ console.h | 2 +- qemu-char.c | 26 +++++++++++++++++++------- qemu-config.c | 12 ++++++++++++ 4 files changed, 55 insertions(+), 32 deletions(-) diff --git a/console.c b/console.c index d55e0fdc0..9bbef593b 100644 --- a/console.c +++ b/console.c @@ -1317,16 +1317,31 @@ void console_color_init(DisplayState *ds) static int n_text_consoles; static CharDriverState *text_consoles[128]; -static char *text_console_strs[128]; +static QemuOpts *text_console_opts[128]; -static void text_console_do_init(CharDriverState *chr, DisplayState *ds, const char *p) +static void text_console_do_init(CharDriverState *chr, DisplayState *ds, QemuOpts *opts) { TextConsole *s; unsigned width; unsigned height; static int color_inited; - s = new_console(ds, (p == NULL) ? TEXT_CONSOLE : TEXT_CONSOLE_FIXED_SIZE); + width = qemu_opt_get_number(opts, "width", 0); + if (width == 0) + width = qemu_opt_get_number(opts, "cols", 0) * FONT_WIDTH; + + height = qemu_opt_get_number(opts, "height", 0); + if (height == 0) + height = qemu_opt_get_number(opts, "rows", 0) * FONT_HEIGHT; + + if (width == 0 || height == 0) { + s = new_console(ds, TEXT_CONSOLE); + width = ds_get_width(s->ds); + height = ds_get_height(s->ds); + } else { + s = new_console(ds, TEXT_CONSOLE_FIXED_SIZE); + } + if (!s) { free(chr); return; @@ -1350,23 +1365,6 @@ static void text_console_do_init(CharDriverState *chr, DisplayState *ds, const c s->total_height = DEFAULT_BACKSCROLL; s->x = 0; s->y = 0; - width = ds_get_width(s->ds); - height = ds_get_height(s->ds); - if (p != NULL) { - width = strtoul(p, (char **)&p, 10); - if (*p == 'C') { - p++; - width *= FONT_WIDTH; - } - if (*p == 'x') { - p++; - height = strtoul(p, (char **)&p, 10); - if (*p == 'C') { - p++; - height *= FONT_HEIGHT; - } - } - } s->g_width = width; s->g_height = height; @@ -1391,7 +1389,7 @@ static void text_console_do_init(CharDriverState *chr, DisplayState *ds, const c chr->init(chr); } -CharDriverState *text_console_init(const char *p) +CharDriverState *text_console_init(QemuOpts *opts) { CharDriverState *chr; @@ -1402,7 +1400,7 @@ CharDriverState *text_console_init(const char *p) exit(1); } text_consoles[n_text_consoles] = chr; - text_console_strs[n_text_consoles] = p ? qemu_strdup(p) : NULL; + text_console_opts[n_text_consoles] = opts; n_text_consoles++; return chr; @@ -1413,8 +1411,9 @@ void text_consoles_set_display(DisplayState *ds) int i; for (i = 0; i < n_text_consoles; i++) { - text_console_do_init(text_consoles[i], ds, text_console_strs[i]); - qemu_free(text_console_strs[i]); + text_console_do_init(text_consoles[i], ds, text_console_opts[i]); + qemu_opts_del(text_console_opts[i]); + text_console_opts[i] = NULL; } n_text_consoles = 0; diff --git a/console.h b/console.h index c8922e4f4..9615f5636 100644 --- a/console.h +++ b/console.h @@ -303,7 +303,7 @@ void vga_hw_text_update(console_ch_t *chardata); int is_graphic_console(void); int is_fixedsize_console(void); -CharDriverState *text_console_init(const char *p); +CharDriverState *text_console_init(QemuOpts *opts); void text_consoles_set_display(DisplayState *ds); void console_select(unsigned int index); void console_color_init(DisplayState *ds); diff --git a/qemu-char.c b/qemu-char.c index e02ac5e01..3240e138a 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -2221,7 +2221,7 @@ static CharDriverState *qemu_chr_open_socket(QemuOpts *opts) static QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename) { - char host[65], port[33]; + char host[65], port[33], width[8], height[8]; int pos; const char *p; QemuOpts *opts; @@ -2238,6 +2238,23 @@ static QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename) qemu_opt_set(opts, "backend", filename); return opts; } + if (strstart(filename, "vc", &p)) { + qemu_opt_set(opts, "backend", "vc"); + if (*p == ':') { + if (sscanf(p+1, "%8[0-9]x%8[0-9]", width, height) == 2) { + /* pixels */ + qemu_opt_set(opts, "width", width); + qemu_opt_set(opts, "height", height); + } else if (sscanf(p+1, "%8[0-9]Cx%8[0-9]C", width, height) == 2) { + /* chars */ + qemu_opt_set(opts, "cols", width); + qemu_opt_set(opts, "rows", height); + } else { + goto fail; + } + } + return opts; + } if (strcmp(filename, "con:") == 0) { qemu_opt_set(opts, "backend", "console"); return opts; @@ -2306,6 +2323,7 @@ static const struct { { .name = "null", .open = qemu_chr_open_null }, { .name = "socket", .open = qemu_chr_open_socket }, { .name = "msmouse", .open = qemu_chr_open_msmouse }, + { .name = "vc", .open = text_console_init }, #ifdef _WIN32 { .name = "file", .open = qemu_chr_open_win_file_out }, { .name = "pipe", .open = qemu_chr_open_win_pipe }, @@ -2376,12 +2394,6 @@ CharDriverState *qemu_chr_open(const char *label, const char *filename, void (*i return qemu_chr_open_opts(opts, init); } - if (!strcmp(filename, "vc")) { - chr = text_console_init(NULL); - } else - if (strstart(filename, "vc:", &p)) { - chr = text_console_init(p); - } else if (strstart(filename, "udp:", &p)) { chr = qemu_chr_open_udp(p); } else diff --git a/qemu-config.c b/qemu-config.c index 3b5083c65..09ef481a4 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -112,6 +112,18 @@ QemuOptsList qemu_chardev_opts = { },{ .name = "telnet", .type = QEMU_OPT_BOOL, + },{ + .name = "width", + .type = QEMU_OPT_NUMBER, + },{ + .name = "height", + .type = QEMU_OPT_NUMBER, + },{ + .name = "cols", + .type = QEMU_OPT_NUMBER, + },{ + .name = "rows", + .type = QEMU_OPT_NUMBER, }, { /* end if list */ } }, -- 2.39.2