From c20cb9a05f271107fff73d0d78884585bd8d78f3 Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Sun, 27 Mar 2005 05:21:20 +0000 Subject: provide enough of a -l mode in non-kvm snooping mode, and krw can shrink the install script even more --- sbin/kbd/kbd_wscons.c | 103 ++++++++++++++++++++------------------------------ 1 file changed, 42 insertions(+), 61 deletions(-) (limited to 'sbin') diff --git a/sbin/kbd/kbd_wscons.c b/sbin/kbd/kbd_wscons.c index 1640fe7281e..501ac475e08 100644 --- a/sbin/kbd/kbd_wscons.c +++ b/sbin/kbd/kbd_wscons.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kbd_wscons.c,v 1.20 2004/10/08 19:30:31 jaredy Exp $ */ +/* $OpenBSD: kbd_wscons.c,v 1.21 2005/03/27 05:21:19 deraadt Exp $ */ /* * Copyright (c) 2001 Mats O Jansson. All rights reserved. @@ -42,6 +42,16 @@ #define NUM_KBD 10 +char *kbtype_tab[] = { + "pc-xt/pc-at", + "usb", + "adb", + "lk201", + "sun", + "sun5", + "hil", + "gsc", +}; #define SA_PCKBD 0 #define SA_UKBD 1 #define SA_AKBD 2 @@ -63,22 +73,10 @@ struct nlist nl[] = { { "_gsckbd_keydesctab" }, { NULL }, }; - -char *kbtype_tab[] = { - "pc-xt/pc-at", - "usb", - "adb", - "lk201", - "sun", - "sun5", - "hil", - "gsc", -}; +#endif /* NOKVM */ int rebuild = 0; -#endif /* NOKVM */ - struct nameint { int value; char *name; @@ -102,18 +100,26 @@ void kbd_show_enc(kvm_t *kd, int idx); void kbd_list(void); void kbd_set(char *name, int verbose); -#ifndef NOKVM void kbd_show_enc(kvm_t *kd, int idx) { +#ifndef NOKVM struct wscons_keydesc r; unsigned long p; - struct nameint *n; int found; u_int32_t variant; + struct nameint *n; +#else + int i; +#endif /* NOKVM */ printf("tables available for %s keyboard:\nencoding\n\n", - kbtype_tab[idx]); + kbtype_tab[idx]); + +#ifdef NOKVM + for (i = 0; kbdenc_tab[i].value; i++) + printf("%s\n", kbdenc_tab[i].name); +#else p = nl[idx].n_value; kvm_read(kd, p, &r, sizeof(r)); while (r.name != 0) { @@ -148,27 +154,21 @@ kbd_show_enc(kvm_t *kd, int idx) p += sizeof(r); kvm_read(kd, p, &r, sizeof(r)); } +#endif printf("\n"); } -#endif void kbd_list(void) { - int fd, i, kbtype; + int pc_kbd = 0, usb_kbd = 0, adb_kbd = 0; + int zs_kbd = 0, sun_kbd = 0, sun5_kbd = 0; + int hil_kbd = 0, gsc_kbd = 0, fd, i, kbtype; + char device[MAXPATHLEN]; + kvm_t *kd = NULL; #ifndef NOKVM - kvm_t *kd; char errbuf[LINE_MAX]; #endif - char device[MAXPATHLEN]; - int pc_kbd = 0; - int usb_kbd = 0; - int adb_kbd = 0; - int zs_kbd = 0; - int sun_kbd = 0; - int sun5_kbd = 0; - int hil_kbd = 0; - int gsc_kbd = 0; /* Go through all keyboards. */ for (i = 0; i < NUM_KBD; i++) { @@ -179,8 +179,8 @@ kbd_list(void) if (fd >= 0) { if (ioctl(fd, WSKBDIO_GTYPE, &kbtype) < 0) err(1, "WSKBDIO_GTYPE"); - if ((kbtype == WSKBD_TYPE_PC_XT) || - (kbtype == WSKBD_TYPE_PC_AT)) + if (kbtype == WSKBD_TYPE_PC_XT || + kbtype == WSKBD_TYPE_PC_AT) pc_kbd++; if (kbtype == WSKBD_TYPE_USB) usb_kbd++; @@ -206,62 +206,47 @@ kbd_list(void) if (kvm_nlist(kd, nl) == -1) errx(1, "kvm_nlist: %s", kvm_geterr(kd)); +#endif if (pc_kbd > 0) kbd_show_enc(kd, SA_PCKBD); - if (usb_kbd > 0) kbd_show_enc(kd, SA_UKBD); - if (adb_kbd > 0) kbd_show_enc(kd, SA_AKBD); - if (zs_kbd > 0) kbd_show_enc(kd, SA_ZSKBD); - if (sun_kbd > 0) kbd_show_enc(kd, SA_SUNKBD); - if (sun5_kbd > 0) kbd_show_enc(kd, SA_SUN5KBD); - if (hil_kbd > 0) kbd_show_enc(kd, SA_HILKBD); - if (gsc_kbd > 0) kbd_show_enc(kd, SA_GSCKBD); - +#ifndef NOKVM kvm_close(kd); - - if (rebuild > 0) { - printf("Unknown encoding or variant. kbd(8) needs to be rebuilt.\n"); - } -#else - printf("List not available; sorry.\n"); #endif + if (rebuild > 0) + printf("Unknown encoding or variant. kbd(8) needs to be rebuilt.\n"); } void kbd_set(char *name, int verbose) { - char buf[LINE_MAX]; - char *c,*b; + char buf[LINE_MAX], *c, *b, device[sizeof "/dev/wskbd00"]; + int map = 0, v, i, fd; struct nameint *n; - int map = 0,v,i,fd; - char device[sizeof "/dev/wskbd00"]; c = name; b = buf; - while ((*c != '.') && (*c != '\0') && - (b < buf + sizeof(buf) - 1)) { + 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) { + if (strcmp(n->name, buf) == 0) map = n->value; - } n++; } if (map == 0) @@ -269,17 +254,14 @@ kbd_set(char *name, int verbose) while (*c == '.') { b = buf; c++; - while ((*c != '.') && (*c != '\0') && - (b < buf + sizeof(buf) - 1)) { + 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) { + if (strcmp(n->name, buf) == 0) v = n->value; - } n++; } if (v == 0) @@ -300,9 +282,8 @@ kbd_set(char *name, int verbose) fprintf(stderr, "%s: unsupported encoding %s on %s\n", __progname, name, device); - } else { + } else err(1, "WSKBDIO_SETENCODING: %s", device); - } v--; } v++; -- cgit v1.2.3