[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
kbd(8)/keyboard encoding traversal question
- To: tech_(_at_)_openbsd_(_dot_)_org
- Subject: kbd(8)/keyboard encoding traversal question
- From: Jared Yanovich <phirerunner_(_at_)_comcast_(_dot_)_net>
- Date: Sun, 18 Jul 2004 14:30:17 -0500
The diff I posted to tech@ recently breaks out of scanning the encoding
table in kbd(8) as soon as an encoding is found.
Here is the table:
<dev/wscons/wsksymdef.h:711>
#define KB_ENCTAB \
{ KB_USER, "user" }, \
{ KB_US, "us" }, \
{ KB_DE, "de" }, \
{ KB_DK, "dk" }, \
{ KB_IT, "it" }, \
{ KB_FR, "fr" }, \
{ KB_UK, "uk" }, \
{ KB_JP, "jp" }, \
{ KB_SV, "sv" }, \
{ KB_NO, "no" }, \
{ KB_ES, "es" }, \
{ KB_HU, "hu" }, \
{ KB_BE, "be" }, \
{ KB_RU, "ru" }, \
{ KB_UA, "ua" }, \
{ KB_SG, "sg" }, \
{ KB_SF, "sf" }, \
{ KB_PT, "pt" }, \
{ KB_LT, "lt" }, \
{ KB_LA, "la" }, \
{ KB_BR, "br" }, \
{ KB_NL, "nl" }, \
{ KB_TR, "tr" }, \
{ KB_PL, "pl" }, \
{ KB_SI, "si" }
The program works the same before and after the patch, but in the mail
I asked whether this may break expected behavior in the future. Is
there any reason why the entire table should be scanned? (The same
goes for keyboard variants as encodings).
Here is the patch again. Note that it does not forget about multiple
variants.
Index: kbd_wscons.c
===================================================================
RCS file: /cvs/src/sbin/kbd/kbd_wscons.c,v
retrieving revision 1.16
diff -u -r1.16 kbd_wscons.c
--- kbd_wscons.c 9 May 2004 03:21:52 -0000 1.16
+++ kbd_wscons.c 18 Jul 2004 18:32:26 -0000
@@ -91,7 +91,6 @@
{ 0, 0 }
};
-extern char *__progname;
int rebuild = 0;
void kbd_show_enc(kvm_t *kd, int idx);
@@ -119,6 +118,7 @@
if (n->value == KB_ENCODING(r.name)) {
printf("%s",n->name);
found++;
+ break;
}
n++;
}
@@ -127,7 +127,6 @@
rebuild++;
}
n = &kbdvar_tab[0];
- found = 0;
variant = KB_VARIANT(r.name);
while (n->value) {
if ((n->value & KB_VARIANT(r.name)) == n->value) {
@@ -228,7 +227,7 @@
kvm_close(kd);
if (rebuild > 0) {
- printf("Unknown encoding or variant. kbd(1) needs to be rebuilt.\n");
+ printf("Unknown encoding or variant. kbd(8) needs to be rebuilt.\n");
}
#else
printf("List not available; sorry.\n");
@@ -246,14 +245,15 @@
c = name;
b = buf;
- while ((*c != '.') && (*c != '\0')) {
+ while ((*c != '.') && (*c != '\0') &&
+ (b < buf + sizeof(buf) - 1))
*b++ = *c++;
- }
*b = '\0';
n = &kbdenc_tab[0];
while (n->value) {
if (strcmp(n->name,buf) == 0) {
map = n->value;
+ break;
}
n++;
}
@@ -262,15 +262,16 @@
while (*c == '.') {
b = buf;
c++;
- while ((*c != '.') && (*c != '\0')) {
+ while ((*c != '.') && (*c != '\0') &&
+ (b < buf + sizeof(buf) - 1))
*b++ = *c++;
- }
*b = '\0';
v = 0;
n = &kbdvar_tab[0];
while (n->value) {
if (strcmp(n->name,buf) == 0) {
v = n->value;
+ break;
}
n++;
}
@@ -288,16 +289,13 @@
fd = open(device, O_RDONLY);
if (fd >= 0) {
if (ioctl(fd, WSKBDIO_SETENCODING, &map) < 0) {
- if (errno == EINVAL) {
- fprintf(stderr,
- "%s: unsupported encoding %s on %s\n",
- __progname, name, device);
- } else {
+ if (errno == EINVAL)
+ warnx("unsupported encoding %s on %s",
+ name, device);
+ else
err(1, "WSKBDIO_SETENCODING: %s", device);
- }
- v--;
- }
- v++;
+ } else
+ v++;
close(fd);
}
}
Index: main.c
===================================================================
RCS file: /cvs/src/sbin/kbd/main.c,v
retrieving revision 1.6
diff -u -r1.6 main.c
--- main.c 10 Jul 2003 00:00:57 -0000 1.6
+++ main.c 18 Jul 2004 18:32:26 -0000
@@ -44,7 +44,8 @@
static void
usage(void)
{
- fprintf(stderr, "usage: %s -l or %s [-q] name\n",
+ fprintf(stderr, "usage:\t%s -l\n"
+ "\t%s [-q] name\n",
__progname, __progname);
exit(1);
}
Visit your host, monkey.org