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>
45 * HALT, PDWN, and PASTE aren't defined in 4.x, but we need them to bridge
46 * to 5.0-current so define them here as a stop gap transition measure.
49 #define HALT 0xa1 /* halt machine */
52 #define PDWN 0xa2 /* halt machine and power down */
55 #define PASTE 0xa3 /* paste from cut-paste buffer */
58 #define SPECIAL 0x80000000
60 char ctrl_names[32][4] = {
61 "nul", "soh", "stx", "etx", "eot", "enq", "ack", "bel",
62 "bs ", "ht ", "nl ", "vt ", "ff ", "cr ", "so ", "si ",
63 "dle", "dc1", "dc2", "dc3", "dc4", "nak", "syn", "etb",
64 "can", "em ", "sub", "esc", "fs ", "gs ", "rs ", "us "
67 char acc_names[15][5] = {
68 "dgra", "dacu", "dcir", "dtil", "dmac", "dbre", "ddot",
69 "duml", "dsla", "drin", "dced", "dapo", "ddac", "dogo",
73 char acc_names_u[15][5] = {
74 "DGRA", "DACU", "DCIR", "DTIL", "DMAC", "DBRE", "DDOT",
75 "DUML", "DSLA", "DRIN", "DCED", "DAPO", "DDAC", "DOGO",
79 char fkey_table[96][MAXFK] = {
80 /* 01-04 */ "\033[M", "\033[N", "\033[O", "\033[P",
81 /* 05-08 */ "\033[Q", "\033[R", "\033[S", "\033[T",
82 /* 09-12 */ "\033[U", "\033[V", "\033[W", "\033[X",
83 /* 13-16 */ "\033[Y", "\033[Z", "\033[a", "\033[b",
84 /* 17-20 */ "\033[c", "\033[d", "\033[e", "\033[f",
85 /* 21-24 */ "\033[g", "\033[h", "\033[i", "\033[j",
86 /* 25-28 */ "\033[k", "\033[l", "\033[m", "\033[n",
87 /* 29-32 */ "\033[o", "\033[p", "\033[q", "\033[r",
88 /* 33-36 */ "\033[s", "\033[t", "\033[u", "\033[v",
89 /* 37-40 */ "\033[w", "\033[x", "\033[y", "\033[z",
90 /* 41-44 */ "\033[@", "\033[[", "\033[\\","\033[]",
91 /* 45-48 */ "\033[^", "\033[_", "\033[`", "\033[{",
92 /* 49-52 */ "\033[H", "\033[A", "\033[I", "-" ,
93 /* 53-56 */ "\033[D", "\033[E", "\033[C", "+" ,
94 /* 57-60 */ "\033[F", "\033[B", "\033[G", "\033[L",
95 /* 61-64 */ "\177", "\033[J", "\033[~", "\033[}",
96 /* 65-68 */ "" , "" , "" , "" ,
97 /* 69-72 */ "" , "" , "" , "" ,
98 /* 73-76 */ "" , "" , "" , "" ,
99 /* 77-80 */ "" , "" , "" , "" ,
100 /* 81-84 */ "" , "" , "" , "" ,
101 /* 85-88 */ "" , "" , "" , "" ,
102 /* 89-92 */ "" , "" , "" , "" ,
103 /* 93-96 */ "" , "" , "" , "" ,
106 const int delays[] = {250, 500, 750, 1000};
107 const int repeats[] = { 34, 38, 42, 46, 50, 55, 59, 63,
108 68, 76, 84, 92, 100, 110, 118, 126,
109 136, 152, 168, 184, 200, 220, 236, 252,
110 272, 304, 336, 368, 400, 440, 472, 504};
111 const int ndelays = (sizeof(delays) / sizeof(int));
112 const int nrepeats = (sizeof(repeats) / sizeof(int));
118 void dump_accent_definition(char *name, accentmap_t *accentmap);
119 void dump_entry(int value);
120 void dump_key_definition(char *name, keymap_t *keymap);
121 int get_accent_definition_line(accentmap_t *);
123 int get_key_definition_line(keymap_t *);
124 void load_keymap(char *opt, int dumponly);
125 void load_default_functionkeys(void);
126 char * nextarg(int ac, char **av, int *indp, int oc);
127 char * mkfullname(const char *s1, const char *s2, const char *s3);
128 void print_accent_definition_line(FILE *fp, int accent,
130 void print_entry(FILE *fp, int value);
131 void print_key_definition_line(FILE *fp, int scancode,
132 struct keyent_t *key);
133 void print_keymap(void);
134 void release_keyboard(void);
135 void mux_keyboard(u_int op, char *kbd);
136 void set_bell_values(char *opt);
137 void set_functionkey(char *keynumstr, char *string);
138 void set_keyboard(char *device);
139 void set_keyrates(char *opt);
140 void show_kbd_info(void);
141 void usage(void) __dead2;
144 nextarg(int ac, char **av, int *indp, int oc)
147 return(av[(*indp)++]);
148 warnx("option requires two arguments -- %c", oc);
154 mkfullname(const char *s1, const char *s2, const char *s3)
156 static char *buf = NULL;
160 f = strlen(s1) + strlen(s2) + strlen(s3) + 1;
163 buf = (char *)realloc(buf, f);
165 buf = (char *)malloc(f);
183 switch ((token = yylex())) {
185 return NOP | SPECIAL;
187 return LSH | SPECIAL;
189 return RSH | SPECIAL;
191 return CLK | SPECIAL;
193 return NLK | SPECIAL;
195 return SLK | SPECIAL;
197 return BTAB | SPECIAL;
199 return LALT | SPECIAL;
201 return LCTR | SPECIAL;
203 return NEXT | SPECIAL;
205 return PREV | SPECIAL;
207 return RCTR | SPECIAL;
209 return RALT | SPECIAL;
211 return ALK | SPECIAL;
213 return ASH | SPECIAL;
215 return META | SPECIAL;
217 return RBT | SPECIAL;
219 return DBG | SPECIAL;
221 return SUSP | SPECIAL;
223 return SPSC | SPECIAL;
225 return PNC | SPECIAL;
227 return LSHA | SPECIAL;
229 return RSHA | SPECIAL;
231 return LCTRA | SPECIAL;
233 return RCTRA | SPECIAL;
235 return LALTA | SPECIAL;
237 return RALTA | SPECIAL;
239 return HALT | SPECIAL;
241 return PDWN | SPECIAL;
243 return PASTE | SPECIAL;
245 if (ACC(number) > L_ACC)
247 return ACC(number) | SPECIAL;
249 if (F(number) > L_FN)
251 return F(number) | SPECIAL;
253 if (S(number) > L_SCR)
255 return S(number) | SPECIAL;
257 return (unsigned char)letter;
259 if (number < 0x000000 || number > 0x10FFFF)
268 get_definition_line(FILE *fd, keymap_t *keymap, accentmap_t *accentmap)
278 c = get_key_definition_line(keymap);
280 errx(1, "invalid key definition");
281 if (c > keymap->n_keys)
285 c = get_accent_definition_line(accentmap);
287 errx(1, "invalid accent key definition");
288 if (c > accentmap->n_accs)
289 accentmap->n_accs = c;
295 errx(1, "illegal definition line");
301 get_key_definition_line(keymap_t *map)
303 int i, def, scancode;
305 /* check scancode number */
306 if (number < 0 || number >= NUM_KEYS)
310 /* get key definitions */
311 map->key[scancode].spcl = 0;
312 for (i=0; i<NUM_STATES; i++) {
313 if ((def = get_entry()) == -1)
316 map->key[scancode].spcl |= (0x80 >> i);
317 map->key[scancode].map[i] = def & ~SPECIAL;
319 /* get lock state key def */
320 if ((token = yylex()) != TFLAG)
322 map->key[scancode].flgs = number;
324 return (scancode + 1);
328 get_accent_definition_line(accentmap_t *map)
334 if (ACC(number) < F_ACC || ACC(number) > L_ACC)
335 /* number out of range */
338 if (map->acc[accent].accchar != 0) {
339 /* this entry has already been defined before! */
340 errx(1, "duplicated accent key definition");
343 switch ((token = yylex())) {
345 map->acc[accent].accchar = letter;
348 map->acc[accent].accchar = number;
354 for (i = 0; (token = yylex()) == '(';) {
355 switch ((token = yylex())) {
365 switch ((token = yylex())) {
375 if ((token = yylex()) != ')')
377 if (i >= NUM_ACCENTCHARS) {
378 warnx("too many accented characters, ignored");
381 map->acc[accent].map[i][0] = c1;
382 map->acc[accent].map[i][1] = c2;
389 print_entry(FILE *fp, int value)
391 int val = value & ~SPECIAL;
395 fprintf(fp, " nop ");
398 fprintf(fp, " lshift");
401 fprintf(fp, " rshift");
404 fprintf(fp, " clock ");
407 fprintf(fp, " nlock ");
410 fprintf(fp, " slock ");
413 fprintf(fp, " btab ");
416 fprintf(fp, " lalt ");
419 fprintf(fp, " lctrl ");
422 fprintf(fp, " nscr ");
425 fprintf(fp, " pscr ");
428 fprintf(fp, " rctrl ");
431 fprintf(fp, " ralt ");
434 fprintf(fp, " alock ");
437 fprintf(fp, " ashift");
440 fprintf(fp, " meta ");
443 fprintf(fp, " boot ");
446 fprintf(fp, " debug ");
449 fprintf(fp, " susp ");
452 fprintf(fp, " saver ");
455 fprintf(fp, " panic ");
458 fprintf(fp, " lshifta");
461 fprintf(fp, " rshifta");
463 case LCTRA | SPECIAL:
464 fprintf(fp, " lctrla");
466 case RCTRA | SPECIAL:
467 fprintf(fp, " rctrla");
469 case LALTA | SPECIAL:
470 fprintf(fp, " lalta ");
472 case RALTA | SPECIAL:
473 fprintf(fp, " ralta ");
476 fprintf(fp, " halt ");
479 fprintf(fp, " pdwn ");
481 case PASTE | SPECIAL:
482 fprintf(fp, " paste ");
485 if (value & SPECIAL) {
486 if (val >= F_FN && val <= L_FN)
487 fprintf(fp, " fkey%02d", val - F_FN + 1);
488 else if (val >= F_SCR && val <= L_SCR)
489 fprintf(fp, " scr%02d ", val - F_SCR + 1);
490 else if (val >= F_ACC && val <= L_ACC)
491 fprintf(fp, " %-6s", acc_names[val - F_ACC]);
493 fprintf(fp, " 0x%02x ", val);
495 fprintf(fp, " %3d ", val);
499 fprintf(fp, " %s ", ctrl_names[val]);
501 fprintf(fp, " del ");
502 else if (isascii(val) && isprint(val))
503 fprintf(fp, " '%c' ", val);
505 fprintf(fp, " 0x%02x ", val);
507 fprintf(fp, " %3d ", val);
513 print_key_definition_line(FILE *fp, int scancode, struct keyent_t *key)
517 /* print scancode number */
519 fprintf(fp, " 0x%02x ", scancode);
521 fprintf(fp, " %03d ", scancode);
523 /* print key definitions */
524 for (i=0; i<NUM_STATES; i++) {
525 if (key->spcl & (0x80 >> i))
526 print_entry(fp, key->map[i] | SPECIAL);
528 print_entry(fp, key->map[i]);
531 /* print lock state key def */
549 print_accent_definition_line(FILE *fp, int accent, struct acc_t *key)
554 if (key->accchar == 0)
557 /* print accent number */
558 fprintf(fp, " %-6s", acc_names[accent]);
559 if (isascii(key->accchar) && isprint(key->accchar))
560 fprintf(fp, "'%c' ", key->accchar);
562 fprintf(fp, "0x%02x ", key->accchar);
564 fprintf(fp, "%03d ", key->accchar);
566 for (i = 0; i < NUM_ACCENTCHARS; ++i) {
570 if ((i > 0) && ((i % 4) == 0))
572 if (isascii(c) && isprint(c))
573 fprintf(fp, "( '%c' ", c);
575 fprintf(fp, "(0x%02x ", c);
577 fprintf(fp, "( %03d ", c);
579 if (isascii(c) && isprint(c))
580 fprintf(fp, "'%c' ) ", c);
582 fprintf(fp, "0x%02x) ", c);
584 fprintf(fp, "%03d ) ", c);
590 dump_entry(int value)
592 if (value & SPECIAL) {
686 if (value >= F_FN && value <= L_FN)
687 printf(" F(%2d),", value - F_FN + 1);
688 else if (value >= F_SCR && value <= L_SCR)
689 printf(" S(%2d),", value - F_SCR + 1);
690 else if (value >= F_ACC && value <= L_ACC)
691 printf(" %-4s, ", acc_names_u[value - F_ACC]);
693 printf(" 0x%02X, ", value);
696 } else if (value == '\'') {
698 } else if (value == '\\') {
700 } else if (isascii(value) && isprint(value)) {
701 printf(" '%c', ", value);
703 printf(" 0x%02X, ", value);
708 dump_key_definition(char *name, keymap_t *keymap)
712 printf("static keymap_t keymap_%s = { 0x%02x, {\n",
713 name, (unsigned)keymap->n_keys);
716 " * scan cntrl alt alt cntrl\n"
717 " * code base shift cntrl shift alt shift cntrl shift spcl flgs\n"
718 " * ---------------------------------------------------------------------------\n"
720 for (i = 0; i < keymap->n_keys; i++) {
721 printf("/*%02x*/{{", i);
722 for (j = 0; j < NUM_STATES; j++) {
723 if (keymap->key[i].spcl & (0x80 >> j))
724 dump_entry(keymap->key[i].map[j] | SPECIAL);
726 dump_entry(keymap->key[i].map[j]);
728 printf("}, 0x%02X,0x%02X },\n",
729 (unsigned)keymap->key[i].spcl,
730 (unsigned)keymap->key[i].flgs);
736 dump_accent_definition(char *name, accentmap_t *accentmap)
741 printf("static accentmap_t accentmap_%s = { %d",
742 name, accentmap->n_accs);
743 if (accentmap->n_accs <= 0) {
748 for (i = 0; i < NUM_DEADKEYS; i++) {
749 printf(" /* %s=%d */\n {", acc_names[i], i);
750 c = accentmap->acc[i].accchar;
754 printf(" '\\\\', {");
755 else if (isascii(c) && isprint(c))
756 printf(" '%c', {", c);
758 printf(" 0x00 }, \n");
761 printf(" 0x%02x, {", c);
762 for (j = 0; j < NUM_ACCENTCHARS; j++) {
763 c = accentmap->acc[i].map[j][0];
766 if ((j > 0) && ((j % 4) == 0))
768 if (isascii(c) && isprint(c))
769 printf(" { '%c',", c);
771 printf(" { 0x%02x,", c);
772 printf("0x%02x },", accentmap->acc[i].map[j][1]);
780 load_keymap(char *opt, int dumponly)
783 accentmap_t accentmap;
787 char blank[] = "", keymap_path[] = KEYMAP_PATH, dotkbd[] = ".kbd";
788 char *prefix[] = {blank, blank, keymap_path, NULL};
789 char *postfix[] = {blank, dotkbd, NULL};
791 cp = getenv("KEYMAP_PATH");
793 asprintf(&(prefix[0]), "%s/", cp);
796 for (i=0; prefix[i] && fd == NULL; i++) {
797 for (j=0; postfix[j] && fd == NULL; j++) {
798 name = mkfullname(prefix[i], opt, postfix[j]);
799 fd = fopen(name, "r");
803 warn("keymap file \"%s\" not found", opt);
806 memset(&keymap, 0, sizeof(keymap));
807 memset(&accentmap, 0, sizeof(accentmap));
810 if (get_definition_line(fd, &keymap, &accentmap) < 0)
814 /* fix up the filename to make it a valid C identifier */
815 for (cp = opt; *cp; cp++)
816 if (!isalpha(*cp) && !isdigit(*cp)) *cp = '_';
818 " * Automatically generated from %s.\n"
821 dump_key_definition(opt, &keymap);
822 dump_accent_definition(opt, &accentmap);
825 if ((keymap.n_keys > 0) && (ioctl(0, PIO_KEYMAP, &keymap) < 0)) {
826 warn("setting keymap");
830 if ((accentmap.n_accs > 0)
831 && (ioctl(0, PIO_DEADKEYMAP, &accentmap) < 0)) {
832 warn("setting accentmap");
842 accentmap_t accentmap;
845 if (ioctl(0, GIO_KEYMAP, &keymap) < 0)
846 err(1, "getting keymap");
847 if (ioctl(0, GIO_DEADKEYMAP, &accentmap) < 0)
848 memset(&accentmap, 0, sizeof(accentmap));
851 "# scan cntrl alt alt cntrl lock\n"
852 "# code base shift cntrl shift alt shift cntrl shift state\n"
853 "# ------------------------------------------------------------------\n"
855 for (i=0; i<keymap.n_keys; i++)
856 print_key_definition_line(stdout, i, &keymap.key[i]);
859 for (i = 0; i < NUM_DEADKEYS; i++)
860 print_accent_definition_line(stdout, i, &accentmap.acc[i]);
865 load_default_functionkeys(void)
870 for (i=0; i<NUM_FKEYS; i++) {
872 strcpy(fkey.keydef, fkey_table[i]);
873 fkey.flen = strlen(fkey_table[i]);
874 if (ioctl(0, SETFKEY, &fkey) < 0)
875 warn("setting function key");
880 set_functionkey(char *keynumstr, char *string)
884 if (!strcmp(keynumstr, "load") && !strcmp(string, "default")) {
885 load_default_functionkeys();
888 fkey.keynum = atoi(keynumstr);
889 if (fkey.keynum < 1 || fkey.keynum > NUM_FKEYS) {
890 warnx("function key number must be between 1 and %d",
894 if ((fkey.flen = strlen(string)) > MAXFK) {
895 warnx("function key string too long (%d > %d)",
899 strncpy(fkey.keydef, string, MAXFK);
901 if (ioctl(0, SETFKEY, &fkey) < 0)
902 warn("setting function key");
906 set_bell_values(char *opt)
908 int bell, duration, pitch;
911 if (!strncmp(opt, "quiet.", 6)) {
912 bell = CONS_QUIET_BELL;
915 if (!strcmp(opt, "visual"))
916 bell |= CONS_VISUAL_BELL;
917 else if (!strcmp(opt, "normal"))
918 duration = 5, pitch = 800;
919 else if (!strcmp(opt, "off"))
920 duration = 0, pitch = 0;
925 duration = strtol(opt, &v1, 0);
926 if ((duration < 0) || (*v1 != '.'))
929 pitch = strtol(opt, &v1, 0);
930 if ((pitch < 0) || (*opt == '\0') || (*v1 != '\0')) {
932 warnx("argument to -b must be duration.pitch or [quiet.]visual|normal|off");
936 pitch = 1193182 / pitch; /* in Hz */
937 duration /= 10; /* in 10 m sec */
940 ioctl(0, CONS_BELLTYPE, &bell);
941 if (!(bell & CONS_VISUAL_BELL))
942 fprintf(stderr, "
\e[=%d;%dB", pitch, duration);
946 set_keyrates(char *opt)
953 if (!strcmp(opt, "slow")) {
954 delay = 1000, repeat = 500;
956 } else if (!strcmp(opt, "normal")) {
957 delay = 500, repeat = 125;
959 } else if (!strcmp(opt, "fast")) {
966 delay = strtol(opt, &v1, 0);
967 if ((delay < 0) || (*v1 != '.'))
970 repeat = strtol(opt, &v1, 0);
971 if ((repeat < 0) || (*opt == '\0') || (*v1 != '\0')) {
973 warnx("argument to -r must be delay.repeat or slow|normal|fast");
976 for (n = 0; n < ndelays - 1; n++)
977 if (delay <= delays[n])
980 for (n = 0; n < nrepeats - 1; n++)
981 if (repeat <= repeats[n])
988 if (ioctl(0, KDSETREPEAT, arg)) {
989 if (ioctl(0, KDSETRAD, (d << 5) | r))
990 warn("setting keyboard rate");
995 get_kbd_type_name(int type)
1002 { KB_101, "AT 101/102" },
1003 { KB_OTHER, "generic" },
1007 for (i = 0; i < sizeof(name_table)/sizeof(name_table[0]); ++i) {
1008 if (type == name_table[i].type)
1009 return name_table[i].name;
1017 keyboard_info_t info;
1019 if (ioctl(0, KDGKBINFO, &info) == -1) {
1020 warn("unable to obtain keyboard information");
1023 printf("kbd%d:\n", info.kb_index);
1024 printf(" %.*s%d, type:%s (%d)\n",
1025 (int)sizeof(info.kb_name), info.kb_name, info.kb_unit,
1026 get_kbd_type_name(info.kb_type), info.kb_type);
1030 set_keyboard(char *device)
1032 keyboard_info_t info;
1035 fd = open(device, O_RDONLY);
1037 warn("cannot open %s", device);
1040 if (ioctl(fd, KDGKBINFO, &info) == -1) {
1041 warn("unable to obtain keyboard information");
1046 * The keyboard device driver won't release the keyboard by
1047 * the following ioctl, but it automatically will, when the device
1048 * is closed. So, we don't check error here.
1050 ioctl(fd, CONS_RELKBD, 0);
1053 printf("kbd%d\n", info.kb_index);
1054 printf(" %.*s%d, type:%s (%d)\n",
1055 (int)sizeof(info.kb_name), info.kb_name, info.kb_unit,
1056 get_kbd_type_name(info.kb_type), info.kb_type);
1059 if (ioctl(0, CONS_SETKBD, info.kb_index) == -1)
1060 warn("unable to set keyboard");
1064 release_keyboard(void)
1066 keyboard_info_t info;
1069 * If stdin is not associated with a keyboard, the following ioctl
1072 if (ioctl(0, KDGKBINFO, &info) == -1) {
1073 warn("unable to obtain keyboard information");
1077 printf("kbd%d\n", info.kb_index);
1078 printf(" %.*s%d, type:%s (%d)\n",
1079 (int)sizeof(info.kb_name), info.kb_name, info.kb_unit,
1080 get_kbd_type_name(info.kb_type), info.kb_type);
1082 if (ioctl(0, CONS_RELKBD, 0) == -1)
1083 warn("unable to release the keyboard");
1087 mux_keyboard(u_int op, char *kbd)
1089 keyboard_info_t info;
1093 * If stdin is not associated with a keyboard, the following ioctl
1096 if (ioctl(0, KDGKBINFO, &info) == -1) {
1097 warn("unable to obtain keyboard information");
1101 printf("kbd%d\n", info.kb_index);
1102 printf(" %.*s%d, type:%s (%d)\n",
1103 (int)sizeof(info.kb_name), info.kb_name, info.kb_unit,
1104 get_kbd_type_name(info.kb_type), info.kb_type);
1107 * split kbd into name and unit. find the right most part of the
1108 * kbd string that consist of only digits.
1111 memset(&info, 0, sizeof(info));
1117 unit = strpbrk(ep + 1, "0123456789");
1119 info.kb_unit = strtol(unit, &ep, 10);
1123 } while (unit != NULL && info.kb_unit == -1);
1125 if (info.kb_unit == -1) {
1126 warnx("unable to find keyboard driver unit in '%s'", kbd);
1131 warnx("unable to find keyboard driver name in '%s'", kbd);
1134 if (unit - kbd >= (int) sizeof(info.kb_name)) {
1135 warnx("keyboard name '%s' is too long", kbd);
1139 strncpy(info.kb_name, kbd, unit - kbd);
1142 * If stdin is not associated with a kbdmux(4) keyboard, the following
1146 if (ioctl(0, op, &info) == -1)
1147 warn("unable to (un)mux the keyboard");
1153 fprintf(stderr, "%s\n%s\n%s\n",
1154 "usage: kbdcontrol [-dFKix] [-A name] [-a name] [-b duration.pitch | [quiet.]belltype]",
1155 " [-r delay.repeat | speed] [-l mapfile] [-f # string]",
1156 " [-k device] [-L mapfile]");
1162 main(int argc, char **argv)
1166 while((opt = getopt(argc, argv, "A:a:b:df:iKk:Fl:L:r:x")) != -1)
1170 mux_keyboard((opt == 'A')? KBRELKBD : KBADDKBD, optarg);
1173 set_bell_values(optarg);
1179 load_keymap(optarg, 0);
1182 load_keymap(optarg, 1);
1185 set_functionkey(optarg,
1186 nextarg(argc, argv, &optind, 'f'));
1189 load_default_functionkeys();
1198 set_keyboard(optarg);
1201 set_keyrates(optarg);
1209 if ((optind != argc) || (argc == 1))