mirror of
https://github.com/qemu/qemu.git
synced 2025-08-09 10:25:06 +00:00
ui/curses: manipulate cchar_t with standard curses functions
The chars/attr fields are curses internals, setcchar and getcchar have to be used instead. Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org> Tested-by: Kamil Rytarowski <n54@gmx.com> Message-Id: <20190427183307.12796-3-samuel.thibault@ens-lyon.org> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
parent
b7b664a4fe
commit
962cf8fd4f
43
ui/curses.c
43
ui/curses.c
@ -66,20 +66,22 @@ static void curses_update(DisplayChangeListener *dcl,
|
|||||||
{
|
{
|
||||||
console_ch_t *line;
|
console_ch_t *line;
|
||||||
cchar_t curses_line[width];
|
cchar_t curses_line[width];
|
||||||
|
wchar_t wch[CCHARW_MAX];
|
||||||
|
attr_t attrs;
|
||||||
|
short colors;
|
||||||
|
int ret;
|
||||||
|
|
||||||
line = screen + y * width;
|
line = screen + y * width;
|
||||||
for (h += y; y < h; y ++, line += width) {
|
for (h += y; y < h; y ++, line += width) {
|
||||||
for (x = 0; x < width; x++) {
|
for (x = 0; x < width; x++) {
|
||||||
chtype ch = line[x] & 0xff;
|
chtype ch = line[x] & 0xff;
|
||||||
chtype at = line[x] & ~0xff;
|
chtype at = line[x] & ~0xff;
|
||||||
if (vga_to_curses[ch].chars[0]) {
|
ret = getcchar(&vga_to_curses[ch], wch, &attrs, &colors, NULL);
|
||||||
curses_line[x] = vga_to_curses[ch];
|
if (ret == ERR || wch[0] == 0) {
|
||||||
} else {
|
wch[0] = ch;
|
||||||
curses_line[x] = (cchar_t) {
|
wch[1] = 0;
|
||||||
.chars[0] = ch,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
curses_line[x].attr |= at;
|
setcchar(&curses_line[x], wch, at, 0, NULL);
|
||||||
}
|
}
|
||||||
mvwadd_wchnstr(screenpad, y, 0, curses_line, width);
|
mvwadd_wchnstr(screenpad, y, 0, curses_line, width);
|
||||||
}
|
}
|
||||||
@ -412,7 +414,7 @@ static void curses_atexit(void)
|
|||||||
static void convert_ucs(unsigned char fch, uint16_t uch, iconv_t conv)
|
static void convert_ucs(unsigned char fch, uint16_t uch, iconv_t conv)
|
||||||
{
|
{
|
||||||
char mbch[MB_LEN_MAX];
|
char mbch[MB_LEN_MAX];
|
||||||
wchar_t wch;
|
wchar_t wch[2];
|
||||||
char *puch, *pmbch;
|
char *puch, *pmbch;
|
||||||
size_t such, smbch;
|
size_t such, smbch;
|
||||||
mbstate_t ps;
|
mbstate_t ps;
|
||||||
@ -430,20 +432,22 @@ static void convert_ucs(unsigned char fch, uint16_t uch, iconv_t conv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
memset(&ps, 0, sizeof(ps));
|
memset(&ps, 0, sizeof(ps));
|
||||||
if (mbrtowc(&wch, mbch, sizeof(mbch) - smbch, &ps) == -1) {
|
if (mbrtowc(&wch[0], mbch, sizeof(mbch) - smbch, &ps) == -1) {
|
||||||
fprintf(stderr, "Could not convert 0x%04x "
|
fprintf(stderr, "Could not convert 0x%04x "
|
||||||
"from a multibyte character to wchar_t: %s\n",
|
"from a multibyte character to wchar_t: %s\n",
|
||||||
uch, strerror(errno));
|
uch, strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
vga_to_curses[fch].chars[0] = wch;
|
|
||||||
|
wch[1] = 0;
|
||||||
|
setcchar(&vga_to_curses[fch], wch, 0, 0, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Setup wchar glyph for one font character */
|
/* Setup wchar glyph for one font character */
|
||||||
static void convert_font(unsigned char fch, iconv_t conv)
|
static void convert_font(unsigned char fch, iconv_t conv)
|
||||||
{
|
{
|
||||||
char mbch[MB_LEN_MAX];
|
char mbch[MB_LEN_MAX];
|
||||||
wchar_t wch;
|
wchar_t wch[2];
|
||||||
char *pfch, *pmbch;
|
char *pfch, *pmbch;
|
||||||
size_t sfch, smbch;
|
size_t sfch, smbch;
|
||||||
mbstate_t ps;
|
mbstate_t ps;
|
||||||
@ -461,13 +465,15 @@ static void convert_font(unsigned char fch, iconv_t conv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
memset(&ps, 0, sizeof(ps));
|
memset(&ps, 0, sizeof(ps));
|
||||||
if (mbrtowc(&wch, mbch, sizeof(mbch) - smbch, &ps) == -1) {
|
if (mbrtowc(&wch[0], mbch, sizeof(mbch) - smbch, &ps) == -1) {
|
||||||
fprintf(stderr, "Could not convert font glyph 0x%02x "
|
fprintf(stderr, "Could not convert font glyph 0x%02x "
|
||||||
"from a multibyte character to wchar_t: %s\n",
|
"from a multibyte character to wchar_t: %s\n",
|
||||||
fch, strerror(errno));
|
fch, strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
vga_to_curses[fch].chars[0] = wch;
|
|
||||||
|
wch[1] = 0;
|
||||||
|
setcchar(&vga_to_curses[fch], wch, 0, 0, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert one wchar to UCS-2 */
|
/* Convert one wchar to UCS-2 */
|
||||||
@ -592,7 +598,16 @@ static void font_setup(void)
|
|||||||
if (strcmp(nl_langinfo(CODESET), "UTF-8")) {
|
if (strcmp(nl_langinfo(CODESET), "UTF-8")) {
|
||||||
/* Non-Unicode capable, use termcap equivalents for those available */
|
/* Non-Unicode capable, use termcap equivalents for those available */
|
||||||
for (i = 0; i <= 0xFF; i++) {
|
for (i = 0; i <= 0xFF; i++) {
|
||||||
switch (get_ucs(vga_to_curses[i].chars[0], nativecharset_to_ucs2)) {
|
wchar_t wch[CCHARW_MAX];
|
||||||
|
attr_t attr;
|
||||||
|
short color;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = getcchar(&vga_to_curses[i], wch, &attr, &color, NULL);
|
||||||
|
if (ret == ERR)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
switch (get_ucs(wch[0], nativecharset_to_ucs2)) {
|
||||||
case 0x00a3:
|
case 0x00a3:
|
||||||
vga_to_curses[i] = *WACS_STERLING;
|
vga_to_curses[i] = *WACS_STERLING;
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user