2 * Copyright (c) 1994-1995 Søren Schmidt
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * in this position and unchanged.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
40 #include <sys/consio.h>
41 #include <sys/sysctl.h>
46 * HALT, PDWN, and PASTE aren't defined in 4.x, but we need them to bridge
47 * to 5.0-current so define them here as a stop gap transition measure.
50 #define HALT 0xa1 /* halt machine */
53 #define PDWN 0xa2 /* halt machine and power down */
56 #define PASTE 0xa3 /* paste from cut-paste buffer */
59 #define SPECIAL 0x80000000
61 static const char ctrl_names[32][4] = {
62 "nul", "soh", "stx", "etx", "eot", "enq", "ack", "bel",
63 "bs ", "ht ", "nl ", "vt ", "ff ", "cr ", "so ", "si ",
64 "dle", "dc1", "dc2", "dc3", "dc4", "nak", "syn", "etb",
65 "can", "em ", "sub", "esc", "fs ", "gs ", "rs ", "us "
68 static const char acc_names[15][5] = {
69 "dgra", "dacu", "dcir", "dtil", "dmac", "dbre", "ddot",
70 "duml", "dsla", "drin", "dced", "dapo", "ddac", "dogo",
74 static const char acc_names_u[15][5] = {
75 "DGRA", "DACU", "DCIR", "DTIL", "DMAC", "DBRE", "DDOT",
76 "DUML", "DSLA", "DRIN", "DCED", "DAPO", "DDAC", "DOGO",
80 static const char fkey_table[96][MAXFK] = {
81 /* 01-04 */ "\033[M", "\033[N", "\033[O", "\033[P",
82 /* 05-08 */ "\033[Q", "\033[R", "\033[S", "\033[T",
83 /* 09-12 */ "\033[U", "\033[V", "\033[W", "\033[X",
84 /* 13-16 */ "\033[Y", "\033[Z", "\033[a", "\033[b",
85 /* 17-20 */ "\033[c", "\033[d", "\033[e", "\033[f",
86 /* 21-24 */ "\033[g", "\033[h", "\033[i", "\033[j",
87 /* 25-28 */ "\033[k", "\033[l", "\033[m", "\033[n",
88 /* 29-32 */ "\033[o", "\033[p", "\033[q", "\033[r",
89 /* 33-36 */ "\033[s", "\033[t", "\033[u", "\033[v",
90 /* 37-40 */ "\033[w", "\033[x", "\033[y", "\033[z",
91 /* 41-44 */ "\033[@", "\033[[", "\033[\\","\033[]",
92 /* 45-48 */ "\033[^", "\033[_", "\033[`", "\033[{",
93 /* 49-52 */ "\033[H", "\033[A", "\033[I", "-" ,
94 /* 53-56 */ "\033[D", "\033[E", "\033[C", "+" ,
95 /* 57-60 */ "\033[F", "\033[B", "\033[G", "\033[L",
96 /* 61-64 */ "\177", "\033[J", "\033[~", "\033[}",
97 /* 65-68 */ "" , "" , "" , "" ,
98 /* 69-72 */ "" , "" , "" , "" ,
99 /* 73-76 */ "" , "" , "" , "" ,
100 /* 77-80 */ "" , "" , "" , "" ,
101 /* 81-84 */ "" , "" , "" , "" ,
102 /* 85-88 */ "" , "" , "" , "" ,
103 /* 89-92 */ "" , "" , "" , "" ,
104 /* 93-96 */ "" , "" , "" , "" ,
107 static const int delays[] = {250, 500, 750, 1000};
108 static const int repeats[] = { 34, 38, 42, 46, 50, 55, 59, 63,
109 68, 76, 84, 92, 100, 110, 118, 126,
110 136, 152, 168, 184, 200, 220, 236, 252,
111 272, 304, 336, 368, 400, 440, 472, 504};
112 static const int ndelays = (sizeof(delays) / sizeof(int));
113 static const int nrepeats = (sizeof(repeats) / sizeof(int));
120 static void dump_accent_definition(char *name, accentmap_t *accentmap);
121 static void dump_entry(int value);
122 static void dump_key_definition(char *name, keymap_t *keymap);
123 static int get_accent_definition_line(accentmap_t *);
124 static int get_entry(void);
125 static int get_key_definition_line(keymap_t *);
126 static void load_keymap(char *opt, int dumponly);
127 static void load_default_functionkeys(void);
128 static char * nextarg(int ac, char **av, int *indp, int oc);
129 static char * mkfullname(const char *s1, const char *s2, const char *s3);
130 static void print_accent_definition_line(FILE *fp, int accent,
132 static void print_entry(FILE *fp, int value);
133 static void print_key_definition_line(FILE *fp, int scancode,
134 struct keyent_t *key);
135 static void print_keymap(void);
136 static void release_keyboard(void);
137 static void mux_keyboard(u_int op, char *kbd);
138 static void set_bell_values(char *opt);
139 static void set_functionkey(char *keynumstr, char *string);
140 static void set_keyboard(char *device);
141 static void set_keyrates(char *opt);
142 static void show_kbd_info(void);
143 static void usage(void) __dead2;
145 /* Detect presence of vt(4). */
149 char vty_name[4] = "";
150 size_t len = sizeof(vty_name);
152 if (sysctlbyname("kern.vty", vty_name, &len, NULL, 0) != 0)
154 return (strcmp(vty_name, "vt") == 0);
158 nextarg(int ac, char **av, int *indp, int oc)
161 return(av[(*indp)++]);
162 warnx("option requires two arguments -- %c", oc);
168 mkfullname(const char *s1, const char *s2, const char *s3)
170 static char *buf = NULL;
174 f = strlen(s1) + strlen(s2) + strlen(s3) + 1;
177 buf = (char *)realloc(buf, f);
179 buf = (char *)malloc(f);
197 switch ((token = yylex())) {
199 return NOP | SPECIAL;
201 return LSH | SPECIAL;
203 return RSH | SPECIAL;
205 return CLK | SPECIAL;
207 return NLK | SPECIAL;
209 return SLK | SPECIAL;
211 return BTAB | SPECIAL;
213 return LALT | SPECIAL;
215 return LCTR | SPECIAL;
217 return NEXT | SPECIAL;
219 return PREV | SPECIAL;
221 return RCTR | SPECIAL;
223 return RALT | SPECIAL;
225 return ALK | SPECIAL;
227 return ASH | SPECIAL;
229 return META | SPECIAL;
231 return RBT | SPECIAL;
233 return DBG | SPECIAL;
235 return SUSP | SPECIAL;
237 return SPSC | SPECIAL;
239 return PNC | SPECIAL;
241 return LSHA | SPECIAL;
243 return RSHA | SPECIAL;
245 return LCTRA | SPECIAL;
247 return RCTRA | SPECIAL;
249 return LALTA | SPECIAL;
251 return RALTA | SPECIAL;
253 return HALT | SPECIAL;
255 return PDWN | SPECIAL;
257 return PASTE | SPECIAL;
259 if (ACC(number) > L_ACC)
261 return ACC(number) | SPECIAL;
263 if (F(number) > L_FN)
265 return F(number) | SPECIAL;
267 if (S(number) > L_SCR)
269 return S(number) | SPECIAL;
271 return (unsigned char)letter;
273 if (number < 0x000000 || number > 0x10FFFF)
282 get_definition_line(FILE *fd, keymap_t *keymap, accentmap_t *accentmap)
292 c = get_key_definition_line(keymap);
294 errx(1, "invalid key definition");
295 if (c > keymap->n_keys)
299 c = get_accent_definition_line(accentmap);
301 errx(1, "invalid accent key definition");
302 if (c > accentmap->n_accs)
303 accentmap->n_accs = c;
309 errx(1, "illegal definition line");
315 get_key_definition_line(keymap_t *map)
317 int i, def, scancode;
319 /* check scancode number */
320 if (number < 0 || number >= NUM_KEYS)
324 /* get key definitions */
325 map->key[scancode].spcl = 0;
326 for (i=0; i<NUM_STATES; i++) {
327 if ((def = get_entry()) == -1)
330 map->key[scancode].spcl |= (0x80 >> i);
331 map->key[scancode].map[i] = def & ~SPECIAL;
333 /* get lock state key def */
334 if ((token = yylex()) != TFLAG)
336 map->key[scancode].flgs = number;
338 return (scancode + 1);
342 get_accent_definition_line(accentmap_t *map)
348 if (ACC(number) < F_ACC || ACC(number) > L_ACC)
349 /* number out of range */
352 if (map->acc[accent].accchar != 0) {
353 /* this entry has already been defined before! */
354 errx(1, "duplicated accent key definition");
357 switch ((token = yylex())) {
359 map->acc[accent].accchar = letter;
362 map->acc[accent].accchar = number;
368 for (i = 0; (token = yylex()) == '(';) {
369 switch ((token = yylex())) {
379 switch ((token = yylex())) {
389 if ((token = yylex()) != ')')
391 if (i >= NUM_ACCENTCHARS) {
392 warnx("too many accented characters, ignored");
395 map->acc[accent].map[i][0] = c1;
396 map->acc[accent].map[i][1] = c2;
403 print_entry(FILE *fp, int value)
405 int val = value & ~SPECIAL;
409 fprintf(fp, " nop ");
412 fprintf(fp, " lshift");
415 fprintf(fp, " rshift");
418 fprintf(fp, " clock ");
421 fprintf(fp, " nlock ");
424 fprintf(fp, " slock ");
427 fprintf(fp, " btab ");
430 fprintf(fp, " lalt ");
433 fprintf(fp, " lctrl ");
436 fprintf(fp, " nscr ");
439 fprintf(fp, " pscr ");
442 fprintf(fp, " rctrl ");
445 fprintf(fp, " ralt ");
448 fprintf(fp, " alock ");
451 fprintf(fp, " ashift");
454 fprintf(fp, " meta ");
457 fprintf(fp, " boot ");
460 fprintf(fp, " debug ");
463 fprintf(fp, " susp ");
466 fprintf(fp, " saver ");
469 fprintf(fp, " panic ");
472 fprintf(fp, " lshifta");
475 fprintf(fp, " rshifta");
477 case LCTRA | SPECIAL:
478 fprintf(fp, " lctrla");
480 case RCTRA | SPECIAL:
481 fprintf(fp, " rctrla");
483 case LALTA | SPECIAL:
484 fprintf(fp, " lalta ");
486 case RALTA | SPECIAL:
487 fprintf(fp, " ralta ");
490 fprintf(fp, " halt ");
493 fprintf(fp, " pdwn ");
495 case PASTE | SPECIAL:
496 fprintf(fp, " paste ");
499 if (value & SPECIAL) {
500 if (val >= F_FN && val <= L_FN)
501 fprintf(fp, " fkey%02d", val - F_FN + 1);
502 else if (val >= F_SCR && val <= L_SCR)
503 fprintf(fp, " scr%02d ", val - F_SCR + 1);
504 else if (val >= F_ACC && val <= L_ACC)
505 fprintf(fp, " %-6s", acc_names[val - F_ACC]);
507 fprintf(fp, " 0x%02x ", val);
509 fprintf(fp, " %3d ", val);
513 fprintf(fp, " %s ", ctrl_names[val]);
515 fprintf(fp, " del ");
516 else if (isascii(val) && isprint(val))
517 fprintf(fp, " '%c' ", val);
519 fprintf(fp, " 0x%02x ", val);
521 fprintf(fp, " %3d ", val);
527 print_key_definition_line(FILE *fp, int scancode, struct keyent_t *key)
531 /* print scancode number */
533 fprintf(fp, " 0x%02x ", scancode);
535 fprintf(fp, " %03d ", scancode);
537 /* print key definitions */
538 for (i=0; i<NUM_STATES; i++) {
539 if (key->spcl & (0x80 >> i))
540 print_entry(fp, key->map[i] | SPECIAL);
542 print_entry(fp, key->map[i]);
545 /* print lock state key def */
563 print_accent_definition_line(FILE *fp, int accent, struct acc_t *key)
568 if (key->accchar == 0)
571 /* print accent number */
572 fprintf(fp, " %-6s", acc_names[accent]);
573 if (isascii(key->accchar) && isprint(key->accchar))
574 fprintf(fp, "'%c' ", key->accchar);
576 fprintf(fp, "0x%02x ", key->accchar);
578 fprintf(fp, "%03d ", key->accchar);
580 for (i = 0; i < NUM_ACCENTCHARS; ++i) {
584 if ((i > 0) && ((i % 4) == 0))
586 if (isascii(c) && isprint(c))
587 fprintf(fp, "( '%c' ", c);
589 fprintf(fp, "(0x%02x ", c);
591 fprintf(fp, "( %03d ", c);
593 if (isascii(c) && isprint(c))
594 fprintf(fp, "'%c' ) ", c);
596 fprintf(fp, "0x%02x) ", c);
598 fprintf(fp, "%03d ) ", c);
604 dump_entry(int value)
606 if (value & SPECIAL) {
700 if (value >= F_FN && value <= L_FN)
701 printf(" F(%2d),", value - F_FN + 1);
702 else if (value >= F_SCR && value <= L_SCR)
703 printf(" S(%2d),", value - F_SCR + 1);
704 else if (value >= F_ACC && value <= L_ACC)
705 printf(" %-4s, ", acc_names_u[value - F_ACC]);
707 printf(" 0x%02X, ", value);
710 } else if (value == '\'') {
712 } else if (value == '\\') {
714 } else if (isascii(value) && isprint(value)) {
715 printf(" '%c', ", value);
717 printf(" 0x%02X, ", value);
722 dump_key_definition(char *name, keymap_t *keymap)
726 printf("static keymap_t keymap_%s = { 0x%02x, {\n",
727 name, (unsigned)keymap->n_keys);
730 " * scan cntrl alt alt cntrl\n"
731 " * code base shift cntrl shift alt shift cntrl shift spcl flgs\n"
732 " * ---------------------------------------------------------------------------\n"
734 for (i = 0; i < keymap->n_keys; i++) {
735 printf("/*%02x*/{{", i);
736 for (j = 0; j < NUM_STATES; j++) {
737 if (keymap->key[i].spcl & (0x80 >> j))
738 dump_entry(keymap->key[i].map[j] | SPECIAL);
740 dump_entry(keymap->key[i].map[j]);
742 printf("}, 0x%02X,0x%02X },\n",
743 (unsigned)keymap->key[i].spcl,
744 (unsigned)keymap->key[i].flgs);
750 dump_accent_definition(char *name, accentmap_t *accentmap)
755 printf("static accentmap_t accentmap_%s = { %d",
756 name, accentmap->n_accs);
757 if (accentmap->n_accs <= 0) {
762 for (i = 0; i < NUM_DEADKEYS; i++) {
763 printf(" /* %s=%d */\n {", acc_names[i], i);
764 c = accentmap->acc[i].accchar;
768 printf(" '\\\\', {");
769 else if (isascii(c) && isprint(c))
770 printf(" '%c', {", c);
772 printf(" 0x00 }, \n");
775 printf(" 0x%02x, {", c);
776 for (j = 0; j < NUM_ACCENTCHARS; j++) {
777 c = accentmap->acc[i].map[j][0];
780 if ((j > 0) && ((j % 4) == 0))
782 if (isascii(c) && isprint(c))
783 printf(" { '%c',", c);
785 printf(" { 0x%02x,", c);
786 printf("0x%02x },", accentmap->acc[i].map[j][1]);
794 load_keymap(char *opt, int dumponly)
797 accentmap_t accentmap;
801 char blank[] = "", keymap_path[] = KEYMAP_PATH;
802 char vt_keymap_path[] = VT_KEYMAP_PATH, dotkbd[] = ".kbd";
803 char *prefix[] = {blank, blank, keymap_path, NULL};
804 char *postfix[] = {blank, dotkbd, NULL};
807 prefix[2] = vt_keymap_path;
808 cp = getenv("KEYMAP_PATH");
810 asprintf(&(prefix[0]), "%s/", cp);
813 for (i=0; prefix[i] && fd == NULL; i++) {
814 for (j=0; postfix[j] && fd == NULL; j++) {
815 name = mkfullname(prefix[i], opt, postfix[j]);
816 fd = fopen(name, "r");
820 warn("keymap file \"%s\" not found", opt);
823 memset(&keymap, 0, sizeof(keymap));
824 memset(&accentmap, 0, sizeof(accentmap));
827 if (get_definition_line(fd, &keymap, &accentmap) < 0)
831 /* fix up the filename to make it a valid C identifier */
832 for (cp = opt; *cp; cp++)
833 if (!isalpha(*cp) && !isdigit(*cp)) *cp = '_';
835 " * Automatically generated from %s.\n"
838 dump_key_definition(opt, &keymap);
839 dump_accent_definition(opt, &accentmap);
842 if ((keymap.n_keys > 0) && (ioctl(0, PIO_KEYMAP, &keymap) < 0)) {
843 warn("setting keymap");
847 if ((accentmap.n_accs > 0)
848 && (ioctl(0, PIO_DEADKEYMAP, &accentmap) < 0)) {
849 warn("setting accentmap");
859 accentmap_t accentmap;
862 if (ioctl(0, GIO_KEYMAP, &keymap) < 0)
863 err(1, "getting keymap");
864 if (ioctl(0, GIO_DEADKEYMAP, &accentmap) < 0)
865 memset(&accentmap, 0, sizeof(accentmap));
868 "# scan cntrl alt alt cntrl lock\n"
869 "# code base shift cntrl shift alt shift cntrl shift state\n"
870 "# ------------------------------------------------------------------\n"
872 for (i=0; i<keymap.n_keys; i++)
873 print_key_definition_line(stdout, i, &keymap.key[i]);
876 for (i = 0; i < NUM_DEADKEYS; i++)
877 print_accent_definition_line(stdout, i, &accentmap.acc[i]);
882 load_default_functionkeys(void)
887 for (i=0; i<NUM_FKEYS; i++) {
889 strcpy(fkey.keydef, fkey_table[i]);
890 fkey.flen = strlen(fkey_table[i]);
891 if (ioctl(0, SETFKEY, &fkey) < 0)
892 warn("setting function key");
897 set_functionkey(char *keynumstr, char *string)
901 if (!strcmp(keynumstr, "load") && !strcmp(string, "default")) {
902 load_default_functionkeys();
905 fkey.keynum = atoi(keynumstr);
906 if (fkey.keynum < 1 || fkey.keynum > NUM_FKEYS) {
907 warnx("function key number must be between 1 and %d",
911 if ((fkey.flen = strlen(string)) > MAXFK) {
912 warnx("function key string too long (%d > %d)",
916 strncpy(fkey.keydef, string, MAXFK);
918 if (ioctl(0, SETFKEY, &fkey) < 0)
919 warn("setting function key");
923 set_bell_values(char *opt)
925 int bell, duration, pitch;
928 if (!strncmp(opt, "quiet.", 6)) {
929 bell = CONS_QUIET_BELL;
932 if (!strcmp(opt, "visual"))
933 bell |= CONS_VISUAL_BELL;
934 else if (!strcmp(opt, "normal"))
935 duration = 5, pitch = 800;
936 else if (!strcmp(opt, "off"))
937 duration = 0, pitch = 0;
942 duration = strtol(opt, &v1, 0);
943 if ((duration < 0) || (*v1 != '.'))
946 pitch = strtol(opt, &v1, 0);
947 if ((pitch < 0) || (*opt == '\0') || (*v1 != '\0')) {
949 warnx("argument to -b must be duration.pitch or [quiet.]visual|normal|off");
953 pitch = 1193182 / pitch; /* in Hz */
954 duration /= 10; /* in 10 m sec */
957 ioctl(0, CONS_BELLTYPE, &bell);
958 if (!(bell & CONS_VISUAL_BELL))
959 fprintf(stderr, "
\e[=%d;%dB", pitch, duration);
963 set_keyrates(char *opt)
970 if (!strcmp(opt, "slow")) {
971 delay = 1000, repeat = 500;
973 } else if (!strcmp(opt, "normal")) {
974 delay = 500, repeat = 125;
976 } else if (!strcmp(opt, "fast")) {
983 delay = strtol(opt, &v1, 0);
984 if ((delay < 0) || (*v1 != '.'))
987 repeat = strtol(opt, &v1, 0);
988 if ((repeat < 0) || (*opt == '\0') || (*v1 != '\0')) {
990 warnx("argument to -r must be delay.repeat or slow|normal|fast");
993 for (n = 0; n < ndelays - 1; n++)
994 if (delay <= delays[n])
997 for (n = 0; n < nrepeats - 1; n++)
998 if (repeat <= repeats[n])
1005 if (ioctl(0, KDSETREPEAT, arg)) {
1006 if (ioctl(0, KDSETRAD, (d << 5) | r))
1007 warn("setting keyboard rate");
1012 get_kbd_type_name(int type)
1019 { KB_101, "AT 101/102" },
1020 { KB_OTHER, "generic" },
1024 for (i = 0; i < sizeof(name_table)/sizeof(name_table[0]); ++i) {
1025 if (type == name_table[i].type)
1026 return name_table[i].name;
1034 keyboard_info_t info;
1036 if (ioctl(0, KDGKBINFO, &info) == -1) {
1037 warn("unable to obtain keyboard information");
1040 printf("kbd%d:\n", info.kb_index);
1041 printf(" %.*s%d, type:%s (%d)\n",
1042 (int)sizeof(info.kb_name), info.kb_name, info.kb_unit,
1043 get_kbd_type_name(info.kb_type), info.kb_type);
1047 set_keyboard(char *device)
1049 keyboard_info_t info;
1052 fd = open(device, O_RDONLY);
1054 warn("cannot open %s", device);
1057 if (ioctl(fd, KDGKBINFO, &info) == -1) {
1058 warn("unable to obtain keyboard information");
1063 * The keyboard device driver won't release the keyboard by
1064 * the following ioctl, but it automatically will, when the device
1065 * is closed. So, we don't check error here.
1067 ioctl(fd, CONS_RELKBD, 0);
1070 printf("kbd%d\n", info.kb_index);
1071 printf(" %.*s%d, type:%s (%d)\n",
1072 (int)sizeof(info.kb_name), info.kb_name, info.kb_unit,
1073 get_kbd_type_name(info.kb_type), info.kb_type);
1076 if (ioctl(0, CONS_SETKBD, info.kb_index) == -1)
1077 warn("unable to set keyboard");
1081 release_keyboard(void)
1083 keyboard_info_t info;
1086 * If stdin is not associated with a keyboard, the following ioctl
1089 if (ioctl(0, KDGKBINFO, &info) == -1) {
1090 warn("unable to obtain keyboard information");
1094 printf("kbd%d\n", info.kb_index);
1095 printf(" %.*s%d, type:%s (%d)\n",
1096 (int)sizeof(info.kb_name), info.kb_name, info.kb_unit,
1097 get_kbd_type_name(info.kb_type), info.kb_type);
1099 if (ioctl(0, CONS_RELKBD, 0) == -1)
1100 warn("unable to release the keyboard");
1104 mux_keyboard(u_int op, char *kbd)
1106 keyboard_info_t info;
1110 * If stdin is not associated with a keyboard, the following ioctl
1113 if (ioctl(0, KDGKBINFO, &info) == -1) {
1114 warn("unable to obtain keyboard information");
1118 printf("kbd%d\n", info.kb_index);
1119 printf(" %.*s%d, type:%s (%d)\n",
1120 (int)sizeof(info.kb_name), info.kb_name, info.kb_unit,
1121 get_kbd_type_name(info.kb_type), info.kb_type);
1124 * split kbd into name and unit. find the right most part of the
1125 * kbd string that consist of only digits.
1128 memset(&info, 0, sizeof(info));
1134 unit = strpbrk(ep + 1, "0123456789");
1136 info.kb_unit = strtol(unit, &ep, 10);
1140 } while (unit != NULL && info.kb_unit == -1);
1142 if (info.kb_unit == -1) {
1143 warnx("unable to find keyboard driver unit in '%s'", kbd);
1148 warnx("unable to find keyboard driver name in '%s'", kbd);
1151 if (unit - kbd >= (int) sizeof(info.kb_name)) {
1152 warnx("keyboard name '%s' is too long", kbd);
1156 strncpy(info.kb_name, kbd, unit - kbd);
1159 * If stdin is not associated with a kbdmux(4) keyboard, the following
1163 if (ioctl(0, op, &info) == -1)
1164 warn("unable to (un)mux the keyboard");
1170 fprintf(stderr, "%s\n%s\n%s\n",
1171 "usage: kbdcontrol [-dFKix] [-A name] [-a name] [-b duration.pitch | [quiet.]belltype]",
1172 " [-r delay.repeat | speed] [-l mapfile] [-f # string]",
1173 " [-k device] [-L mapfile]");
1179 main(int argc, char **argv)
1183 while((opt = getopt(argc, argv, "A:a:b:df:iKk:Fl:L:r:x")) != -1)
1187 mux_keyboard((opt == 'A')? KBRELKBD : KBADDKBD, optarg);
1190 set_bell_values(optarg);
1196 load_keymap(optarg, 0);
1199 load_keymap(optarg, 1);
1202 set_functionkey(optarg,
1203 nextarg(argc, argv, &optind, 'f'));
1206 load_default_functionkeys();
1215 set_keyboard(optarg);
1218 set_keyrates(optarg);
1226 if ((optind != argc) || (argc == 1))