usr.sbin/kbdcontrol.c: Add backwards compatibility functions

This commit allows a kbdcontrol binary built with a version of kbio.h
that supports Unicode characters in dead key maps to load and display
keymaps including the dead key tables on a kernel built with a
previous version of kbio.h (that only supported 8 bit characters in
the dead key map).

This commit is meant as a temporary compatibility shim that will be
reverted when it can be assumed that all relevant systems have been
upgraded to a kernel that uses the updated kbio.h.

MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D38388
This commit is contained in:
Stefan Eßer 2023-02-06 23:56:44 +01:00
parent 4972fb9276
commit b92f8e5c0d
2 changed files with 48 additions and 9 deletions

View file

@ -209,7 +209,7 @@ struct accentmap {
};
typedef struct accentmap accentmap_t;
#ifdef _KERNEL
//#ifdef _KERNEL
struct oacc_t {
u_char accchar;
u_char map[NUM_ACCENTCHARS][2];
@ -220,7 +220,7 @@ struct oaccentmap {
struct oacc_t acc[NUM_DEADKEYS];
};
typedef struct oaccentmap oaccentmap_t;
#endif /* _KERNEL */
//#endif /* _KERNEL */
struct keyarg {
u_short keynum;
@ -257,10 +257,10 @@ typedef struct fkeyarg fkeyarg_t;
/* XXX: Should have accentmap_t as an argument, but that's too big for ioctl()! */
#define GIO_DEADKEYMAP _IO('k', 8)
#define PIO_DEADKEYMAP _IO('k', 9)
#ifdef _KERNEL
//#ifdef _KERNEL
#define OGIO_DEADKEYMAP _IOR('k', 8, oaccentmap_t)
#define OPIO_DEADKEYMAP _IOW('k', 9, oaccentmap_t)
#endif /* _KERNEL */
//#endif /* _KERNEL */
#define GIO_KEYMAPENT _IOWR('k', 10, keyarg_t)
#define PIO_KEYMAPENT _IOW('k', 11, keyarg_t)

View file

@ -818,11 +818,27 @@ add_keymap_path(const char *path)
STAILQ_INSERT_TAIL(&pathlist, pe, next);
}
static void
to_old_accentmap(accentmap_t *from, oaccentmap_t *to)
{
int i, j;
to->n_accs = from->n_accs;
for (i = 0; i < NUM_DEADKEYS; i++) {
for (j = 0; j < NUM_ACCENTCHARS; j++) {
to->acc[i].map[j][0] = from->acc[i].map[j][0];
to->acc[i].map[j][1] = from->acc[i].map[j][1];
to->acc[i].accchar = from->acc[i].accchar;
}
}
}
static void
load_keymap(char *opt, int dumponly)
{
keymap_t keymap;
accentmap_t accentmap;
oaccentmap_t oaccentmap;
struct pathent *pe;
FILE *file;
int j;
@ -882,9 +898,27 @@ load_keymap(char *opt, int dumponly)
}
if ((accentmap.n_accs > 0)
&& (ioctl(0, PIO_DEADKEYMAP, &accentmap) < 0)) {
warn("setting accentmap");
fclose(file);
return;
to_old_accentmap(&accentmap, &oaccentmap);
if (ioctl(0, OPIO_DEADKEYMAP, &oaccentmap) < 0) {
warn("setting accentmap");
fclose(file);
return;
}
}
}
static void
to_new_accentmap(oaccentmap_t *from, accentmap_t *to)
{
int i, j;
to->n_accs = from->n_accs;
for (i = 0; i < NUM_DEADKEYS; i++) {
for (j = 0; j < NUM_ACCENTCHARS; j++) {
to->acc[i].map[j][0] = from->acc[i].map[j][0];
to->acc[i].map[j][1] = from->acc[i].map[j][1];
to->acc[i].accchar = from->acc[i].accchar;
}
}
}
@ -893,12 +927,17 @@ print_keymap(void)
{
keymap_t keymap;
accentmap_t accentmap;
oaccentmap_t oaccentmap;
int i;
if (ioctl(0, GIO_KEYMAP, &keymap) < 0)
err(1, "getting keymap");
if (ioctl(0, GIO_DEADKEYMAP, &accentmap) < 0)
memset(&accentmap, 0, sizeof(accentmap));
if (ioctl(0, GIO_DEADKEYMAP, &accentmap) < 0) {
if (ioctl(0, OGIO_DEADKEYMAP, &oaccentmap) == 0)
to_new_accentmap(&oaccentmap, &accentmap);
else
memset(&accentmap, 0, sizeof(accentmap));
}
printf(
"# alt\n"
"# scan cntrl alt alt cntrl lock\n"