When merging entries with the keyboard map, print only the resulting changes.

While here, replace bcopy with standad memcpy.
This commit is contained in:
mlelstv 2018-11-23 06:31:57 +00:00
parent 801bc96314
commit 71e18f4b60
4 changed files with 42 additions and 7 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: keyboard.c,v 1.9 2008/04/28 20:23:09 martin Exp $ */
/* $NetBSD: keyboard.c,v 1.10 2018/11/23 06:31:57 mlelstv Exp $ */
/*-
* Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
@ -38,6 +38,7 @@
#include <err.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "wsconsctl.h"
@ -48,6 +49,9 @@ static struct wskbd_bell_data dfbell;
static struct wscons_keymap mapdata[KS_NUMKEYCODES];
struct wskbd_map_data kbmap = /* used in map_parse.y and in util.c */
{ KS_NUMKEYCODES, mapdata };
static struct wscons_keymap oldmapdata[KS_NUMKEYCODES];
static struct wskbd_map_data oldkbmap =
{ KS_NUMKEYCODES, oldmapdata };
static struct wskbd_keyrepeat_data repeat;
static struct wskbd_keyrepeat_data dfrepeat;
static struct wskbd_scroll_data scroll;
@ -79,6 +83,29 @@ struct field keyboard_field_tab[] = {
int keyboard_field_tab_len = sizeof(keyboard_field_tab) /
sizeof(keyboard_field_tab[0]);
static void
diff_kmap(struct wskbd_map_data *omap, struct wskbd_map_data *nmap)
{
unsigned int u;
struct wscons_keymap *op, *np;
for (u = 0; u < nmap->maplen; u++) {
op = omap->map + u;
np = nmap->map + u;
if (op->command == np->command &&
op->group1[0] == np->group1[0] &&
op->group1[1] == np->group1[1] &&
op->group2[0] == np->group2[0] &&
op->group2[1] == np->group2[1]) {
np->command = KS_voidSymbol;
np->group1[0] = KS_voidSymbol;
np->group1[1] = KS_voidSymbol;
np->group2[0] = KS_voidSymbol;
np->group2[1] = KS_voidSymbol;
}
}
}
void
keyboard_get_values(int fd)
{
@ -112,6 +139,7 @@ keyboard_get_values(int fd)
kbmap.maplen = KS_NUMKEYCODES;
if (ioctl(fd, WSKBDIO_GETMAP, &kbmap) < 0)
err(EXIT_FAILURE, "WSKBDIO_GETMAP");
memcpy(oldmapdata, mapdata, sizeof(oldmapdata));
}
repeat.which = 0;
@ -200,7 +228,11 @@ keyboard_put_values(int fd)
if (field_by_value(&kbmap)->flags & FLG_SET) {
if (ioctl(fd, WSKBDIO_SETMAP, &kbmap) < 0)
err(EXIT_FAILURE, "WSKBDIO_SETMAP");
pr_field(field_by_value(&kbmap), " -> ");
if (field_by_value(&kbmap)->flags & FLG_MODIFIED) {
diff_kmap(&oldkbmap, &kbmap);
pr_field(field_by_value(&kbmap), " +> ");
} else
pr_field(field_by_value(&kbmap), " -> ");
}
repeat.which = 0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: util.c,v 1.31 2012/12/24 01:20:12 khorben Exp $ */
/* $NetBSD: util.c,v 1.32 2018/11/23 06:31:57 mlelstv Exp $ */
/*-
* Copyright (c) 1998, 2006, 2012 The NetBSD Foundation, Inc.
@ -420,7 +420,7 @@ rd_field(struct field *f, char *val, int merge)
}
}
kbmap.maplen = newkbmap.maplen;
bcopy(newkbmap.map, kbmap.map,
memcpy(kbmap.map, newkbmap.map,
kbmap.maplen * sizeof(struct wscons_keymap));
break;
case FMT_COLOR:

View File

@ -1,4 +1,4 @@
/* $NetBSD: wsconsctl.c,v 1.18 2008/08/25 00:14:46 dholland Exp $ */
/* $NetBSD: wsconsctl.c,v 1.19 2018/11/23 06:31:57 mlelstv Exp $ */
/*-
* Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
@ -207,8 +207,10 @@ main(int argc, char **argv)
}
rd_field(f, p, do_merge);
f->flags |= FLG_SET;
if (do_merge)
f->flags |= FLG_MODIFIED;
(*putval)(fd);
f->flags &= ~FLG_SET;
f->flags &= ~(FLG_SET | FLG_MODIFIED);
}
} else {
for (i = 0; i < argc; i++) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: wsconsctl.h,v 1.12 2012/12/24 01:20:44 khorben Exp $ */
/* $NetBSD: wsconsctl.h,v 1.13 2018/11/23 06:31:57 mlelstv Exp $ */
/*-
* Copyright (c) 1998, 2004, 2012 The NetBSD Foundation, Inc.
@ -71,6 +71,7 @@ struct field {
#define FLG_DISABLED 0x0010 /* variable is not available */
#define FLG_GET 0x0100 /* read this variable from driver */
#define FLG_SET 0x0200 /* write this variable to driver */
#define FLG_MODIFIED 0x0400 /* value was merged with += */
int flags;
};