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). */
150 if (sysctlbyname("kern.vt.deadtimer", NULL, NULL, NULL, 0) == 0)
157 nextarg(int ac, char **av, int *indp, int oc)
160 return(av[(*indp)++]);
161 warnx("option requires two arguments -- %c", oc);
167 mkfullname(const char *s1, const char *s2, const char *s3)
169 static char *buf = NULL;
173 f = strlen(s1) + strlen(s2) + strlen(s3) + 1;
176 buf = (char *)realloc(buf, f);
178 buf = (char *)malloc(f);
196 switch ((token = yylex())) {
198 return NOP | SPECIAL;
200 return LSH | SPECIAL;
202 return RSH | SPECIAL;
204 return CLK | SPECIAL;
206 return NLK | SPECIAL;
208 return SLK | SPECIAL;
210 return BTAB | SPECIAL;
212 return LALT | SPECIAL;
214 return LCTR | SPECIAL;
216 return NEXT | SPECIAL;
218 return PREV | SPECIAL;
220 return RCTR | SPECIAL;
222 return RALT | SPECIAL;
224 return ALK | SPECIAL;
226 return ASH | SPECIAL;
228 return META | SPECIAL;
230 return RBT | SPECIAL;
232 return DBG | SPECIAL;
234 return SUSP | SPECIAL;
236 return SPSC | SPECIAL;
238 return PNC | SPECIAL;
240 return LSHA | SPECIAL;
242 return RSHA | SPECIAL;
244 return LCTRA | SPECIAL;
246 return RCTRA | SPECIAL;
248 return LALTA | SPECIAL;
250 return RALTA | SPECIAL;
252 return HALT | SPECIAL;
254 return PDWN | SPECIAL;
256 return PASTE | SPECIAL;
258 if (ACC(number) > L_ACC)
260 return ACC(number) | SPECIAL;
262 if (F(number) > L_FN)
264 return F(number) | SPECIAL;
266 if (S(number) > L_SCR)
268 return S(number) | SPECIAL;
270 return (unsigned char)letter;
272 if (number < 0x000000 || number > 0x10FFFF)
281 get_definition_line(FILE *fd, keymap_t *keymap, accentmap_t *accentmap)
291 c = get_key_definition_line(keymap);
293 errx(1, "invalid key definition");
294 if (c > keymap->n_keys)
298 c = get_accent_definition_line(accentmap);
300 errx(1, "invalid accent key definition");
301 if (c > accentmap->n_accs)
302 accentmap->n_accs = c;
308 errx(1, "illegal definition line");
314 get_key_definition_line(keymap_t *map)
316 int i, def, scancode;
318 /* check scancode number */
319 if (number < 0 || number >= NUM_KEYS)
323 /* get key definitions */
324 map->key[scancode].spcl = 0;
325 for (i=0; i<NUM_STATES; i++) {
326 if ((def = get_entry()) == -1)
329 map->key[scancode].spcl |= (0x80 >> i);
330 map->key[scancode].map[i] = def & ~SPECIAL;
332 /* get lock state key def */
333 if ((token = yylex()) != TFLAG)
335 map->key[scancode].flgs = number;
337 return (scancode + 1);
341 get_accent_definition_line(accentmap_t *map)
347 if (ACC(number) < F_ACC || ACC(number) > L_ACC)
348 /* number out of range */
351 if (map->acc[accent].accchar != 0) {
352 /* this entry has already been defined before! */
353 errx(1, "duplicated accent key definition");
356 switch ((token = yylex())) {
358 map->acc[accent].accchar = letter;
361 map->acc[accent].accchar = number;
367 for (i = 0; (token = yylex()) == '(';) {
368 switch ((token = yylex())) {
378 switch ((token = yylex())) {
388 if ((token = yylex()) != ')')
390 if (i >= NUM_ACCENTCHARS) {
391 warnx("too many accented characters, ignored");
394 map->acc[accent].map[i][0] = c1;
395 map->acc[accent].map[i][1] = c2;
402 print_entry(FILE *fp, int value)
404 int val = value & ~SPECIAL;
408 fprintf(fp, " nop ");
411 fprintf(fp, " lshift");
414 fprintf(fp, " rshift");
417 fprintf(fp, " clock ");
420 fprintf(fp, " nlock ");
423 fprintf(fp, " slock ");
426 fprintf(fp, " btab ");
429 fprintf(fp, " lalt ");
432 fprintf(fp, " lctrl ");
435 fprintf(fp, " nscr ");
438 fprintf(fp, " pscr ");
441 fprintf(fp, " rctrl ");
444 fprintf(fp, " ralt ");
447 fprintf(fp, " alock ");
450 fprintf(fp, " ashift");
453 fprintf(fp, " meta ");
456 fprintf(fp, " boot ");
459 fprintf(fp, " debug ");
462 fprintf(fp, " susp ");
465 fprintf(fp, " saver ");
468 fprintf(fp, " panic ");
471 fprintf(fp, " lshifta");
474 fprintf(fp, " rshifta");
476 case LCTRA | SPECIAL:
477 fprintf(fp, " lctrla");
479 case RCTRA | SPECIAL:
480 fprintf(fp, " rctrla");
482 case LALTA | SPECIAL:
483 fprintf(fp, " lalta ");
485 case RALTA | SPECIAL:
486 fprintf(fp, " ralta ");
489 fprintf(fp, " halt ");
492 fprintf(fp, " pdwn ");
494 case PASTE | SPECIAL:
495 fprintf(fp, " paste ");
498 if (value & SPECIAL) {
499 if (val >= F_FN && val <= L_FN)
500 fprintf(fp, " fkey%02d", val - F_FN + 1);
501 else if (val >= F_SCR && val <= L_SCR)
502 fprintf(fp, " scr%02d ", val - F_SCR + 1);
503 else if (val >= F_ACC && val <= L_ACC)
504 fprintf(fp, " %-6s", acc_names[val - F_ACC]);
506 fprintf(fp, " 0x%02x ", val);
508 fprintf(fp, " %3d ", val);
512 fprintf(fp, " %s ", ctrl_names[val]);
514 fprintf(fp, " del ");
515 else if (isascii(val) && isprint(val))
516 fprintf(fp, " '%c' ", val);
518 fprintf(fp, " 0x%02x ", val);
520 fprintf(fp, " %3d ", val);
526 print_key_definition_line(FILE *fp, int scancode, struct keyent_t *key)
530 /* print scancode number */
532 fprintf(fp, " 0x%02x ", scancode);
534 fprintf(fp, " %03d ", scancode);
536 /* print key definitions */
537 for (i=0; i<NUM_STATES; i++) {
538 if (key->spcl & (0x80 >> i))
539 print_entry(fp, key->map[i] | SPECIAL);
541 print_entry(fp, key->map[i]);
544 /* print lock state key def */
562 print_accent_definition_line(FILE *fp, int accent, struct acc_t *key)
567 if (key->accchar == 0)
570 /* print accent number */
571 fprintf(fp, " %-6s", acc_names[accent]);
572 if (isascii(key->accchar) && isprint(key->accchar))
573 fprintf(fp, "'%c' ", key->accchar);
575 fprintf(fp, "0x%02x ", key->accchar);
577 fprintf(fp, "%03d ", key->accchar);
579 for (i = 0; i < NUM_ACCENTCHARS; ++i) {
583 if ((i > 0) && ((i % 4) == 0))
585 if (isascii(c) && isprint(c))
586 fprintf(fp, "( '%c' ", c);
588 fprintf(fp, "(0x%02x ", c);
590 fprintf(fp, "( %03d ", c);
592 if (isascii(c) && isprint(c))
593 fprintf(fp, "'%c' ) ", c);
595 fprintf(fp, "0x%02x) ", c);
597 fprintf(fp, "%03d ) ", c);
603 dump_entry(int value)
605 if (value & SPECIAL) {
699 if (value >= F_FN && value <= L_FN)
700 printf(" F(%2d),", value - F_FN + 1);
701 else if (value >= F_SCR && value <= L_SCR)
702 printf(" S(%2d),", value - F_SCR + 1);
703 else if (value >= F_ACC && value <= L_ACC)
704 printf(" %-4s, ", acc_names_u[value - F_ACC]);
706 printf(" 0x%02X, ", value);
709 } else if (value == '\'') {
711 } else if (value == '\\') {
713 } else if (isascii(value) && isprint(value)) {
714 printf(" '%c', ", value);
716 printf(" 0x%02X, ", value);
721 dump_key_definition(char *name, keymap_t *keymap)
725 printf("static keymap_t keymap_%s = { 0x%02x, {\n",
726 name, (unsigned)keymap->n_keys);
729 " * scan cntrl alt alt cntrl\n"
730 " * code base shift cntrl shift alt shift cntrl shift spcl flgs\n"
731 " * ---------------------------------------------------------------------------\n"
733 for (i = 0; i < keymap->n_keys; i++) {
734 printf("/*%02x*/{{", i);
735 for (j = 0; j < NUM_STATES; j++) {
736 if (keymap->key[i].spcl & (0x80 >> j))
737 dump_entry(keymap->key[i].map[j] | SPECIAL);
739 dump_entry(keymap->key[i].map[j]);
741 printf("}, 0x%02X,0x%02X },\n",
742 (unsigned)keymap->key[i].spcl,
743 (unsigned)keymap->key[i].flgs);
749 dump_accent_definition(char *name, accentmap_t *accentmap)
754 printf("static accentmap_t accentmap_%s = { %d",
755 name, accentmap->n_accs);
756 if (accentmap->n_accs <= 0) {
761 for (i = 0; i < NUM_DEADKEYS; i++) {
762 printf(" /* %s=%d */\n {", acc_names[i], i);
763 c = accentmap->acc[i].accchar;
767 printf(" '\\\\', {");
768 else if (isascii(c) && isprint(c))
769 printf(" '%c', {", c);
771 printf(" 0x00 }, \n");
774 printf(" 0x%02x, {", c);
775 for (j = 0; j < NUM_ACCENTCHARS; j++) {
776 c = accentmap->acc[i].map[j][0];
779 if ((j > 0) && ((j % 4) == 0))
781 if (isascii(c) && isprint(c))
782 printf(" { '%c',", c);
784 printf(" { 0x%02x,", c);
785 printf("0x%02x },", accentmap->acc[i].map[j][1]);
793 load_keymap(char *opt, int dumponly)
796 accentmap_t accentmap;
800 char blank[] = "", keymap_path[] = KEYMAP_PATH;
801 char vt_keymap_path[] = VT_KEYMAP_PATH, dotkbd[] = ".kbd";
802 char *prefix[] = {blank, blank, keymap_path, NULL};
803 char *postfix[] = {blank, dotkbd, NULL};
806 prefix[2] = vt_keymap_path;
807 cp = getenv("KEYMAP_PATH");
809 asprintf(&(prefix[0]), "%s/", cp);
812 for (i=0; prefix[i] && fd == NULL; i++) {
813 for (j=0; postfix[j] && fd == NULL; j++) {
814 name = mkfullname(prefix[i], opt, postfix[j]);
815 fd = fopen(name, "r");
819 warn("keymap file \"%s\" not found", opt);
822 memset(&keymap, 0, sizeof(keymap));
823 memset(&accentmap, 0, sizeof(accentmap));
826 if (get_definition_line(fd, &keymap, &accentmap) < 0)
830 /* fix up the filename to make it a valid C identifier */
831 for (cp = opt; *cp; cp++)
832 if (!isalpha(*cp) && !isdigit(*cp)) *cp = '_';
834 " * Automatically generated from %s.\n"
837 dump_key_definition(opt, &keymap);
838 dump_accent_definition(opt, &accentmap);
841 if ((keymap.n_keys > 0) && (ioctl(0, PIO_KEYMAP, &keymap) < 0)) {
842 warn("setting keymap");
846 if ((accentmap.n_accs > 0)
847 && (ioctl(0, PIO_DEADKEYMAP, &accentmap) < 0)) {
848 warn("setting accentmap");
858 accentmap_t accentmap;
861 if (ioctl(0, GIO_KEYMAP, &keymap) < 0)
862 err(1, "getting keymap");
863 if (ioctl(0, GIO_DEADKEYMAP, &accentmap) < 0)
864 memset(&accentmap, 0, sizeof(accentmap));
867 "# scan cntrl alt alt cntrl lock\n"
868 "# code base shift cntrl shift alt shift cntrl shift state\n"
869 "# ------------------------------------------------------------------\n"
871 for (i=0; i<keymap.n_keys; i++)
872 print_key_definition_line(stdout, i, &keymap.key[i]);
875 for (i = 0; i < NUM_DEADKEYS; i++)
876 print_accent_definition_line(stdout, i, &accentmap.acc[i]);
881 load_default_functionkeys(void)
886 for (i=0; i<NUM_FKEYS; i++) {
888 strcpy(fkey.keydef, fkey_table[i]);
889 fkey.flen = strlen(fkey_table[i]);
890 if (ioctl(0, SETFKEY, &fkey) < 0)
891 warn("setting function key");
896 set_functionkey(char *keynumstr, char *string)
900 if (!strcmp(keynumstr, "load") && !strcmp(string, "default")) {
901 load_default_functionkeys();
904 fkey.keynum = atoi(keynumstr);
905 if (fkey.keynum < 1 || fkey.keynum > NUM_FKEYS) {
906 warnx("function key number must be between 1 and %d",
910 if ((fkey.flen = strlen(string)) > MAXFK) {
911 warnx("function key string too long (%d > %d)",
915 strncpy(fkey.keydef, string, MAXFK);
917 if (ioctl(0, SETFKEY, &fkey) < 0)
918 warn("setting function key");
922 set_bell_values(char *opt)
924 int bell, duration, pitch;
927 if (!strncmp(opt, "quiet.", 6)) {
928 bell = CONS_QUIET_BELL;
931 if (!strcmp(opt, "visual"))
932 bell |= CONS_VISUAL_BELL;
933 else if (!strcmp(opt, "normal"))
934 duration = 5, pitch = 800;
935 else if (!strcmp(opt, "off"))
936 duration = 0, pitch = 0;
941 duration = strtol(opt, &v1, 0);
942 if ((duration < 0) || (*v1 != '.'))
945 pitch = strtol(opt, &v1, 0);
946 if ((pitch < 0) || (*opt == '\0') || (*v1 != '\0')) {
948 warnx("argument to -b must be duration.pitch or [quiet.]visual|normal|off");
952 pitch = 1193182 / pitch; /* in Hz */
953 duration /= 10; /* in 10 m sec */
956 ioctl(0, CONS_BELLTYPE, &bell);
957 if (!(bell & CONS_VISUAL_BELL))
958 fprintf(stderr, "
\e[=%d;%dB", pitch, duration);
962 set_keyrates(char *opt)
969 if (!strcmp(opt, "slow")) {
970 delay = 1000, repeat = 500;
972 } else if (!strcmp(opt, "normal")) {
973 delay = 500, repeat = 125;
975 } else if (!strcmp(opt, "fast")) {
982 delay = strtol(opt, &v1, 0);
983 if ((delay < 0) || (*v1 != '.'))
986 repeat = strtol(opt, &v1, 0);
987 if ((repeat < 0) || (*opt == '\0') || (*v1 != '\0')) {
989 warnx("argument to -r must be delay.repeat or slow|normal|fast");
992 for (n = 0; n < ndelays - 1; n++)
993 if (delay <= delays[n])
996 for (n = 0; n < nrepeats - 1; n++)
997 if (repeat <= repeats[n])
1004 if (ioctl(0, KDSETREPEAT, arg)) {
1005 if (ioctl(0, KDSETRAD, (d << 5) | r))
1006 warn("setting keyboard rate");
1011 get_kbd_type_name(int type)
1018 { KB_101, "AT 101/102" },
1019 { KB_OTHER, "generic" },
1023 for (i = 0; i < sizeof(name_table)/sizeof(name_table[0]); ++i) {
1024 if (type == name_table[i].type)
1025 return name_table[i].name;
1033 keyboard_info_t info;
1035 if (ioctl(0, KDGKBINFO, &info) == -1) {
1036 warn("unable to obtain keyboard information");
1039 printf("kbd%d:\n", info.kb_index);
1040 printf(" %.*s%d, type:%s (%d)\n",
1041 (int)sizeof(info.kb_name), info.kb_name, info.kb_unit,
1042 get_kbd_type_name(info.kb_type), info.kb_type);
1046 set_keyboard(char *device)
1048 keyboard_info_t info;
1051 fd = open(device, O_RDONLY);
1053 warn("cannot open %s", device);
1056 if (ioctl(fd, KDGKBINFO, &info) == -1) {
1057 warn("unable to obtain keyboard information");
1062 * The keyboard device driver won't release the keyboard by
1063 * the following ioctl, but it automatically will, when the device
1064 * is closed. So, we don't check error here.
1066 ioctl(fd, CONS_RELKBD, 0);
1069 printf("kbd%d\n", info.kb_index);
1070 printf(" %.*s%d, type:%s (%d)\n",
1071 (int)sizeof(info.kb_name), info.kb_name, info.kb_unit,
1072 get_kbd_type_name(info.kb_type), info.kb_type);
1075 if (ioctl(0, CONS_SETKBD, info.kb_index) == -1)
1076 warn("unable to set keyboard");
1080 release_keyboard(void)
1082 keyboard_info_t info;
1085 * If stdin is not associated with a keyboard, the following ioctl
1088 if (ioctl(0, KDGKBINFO, &info) == -1) {
1089 warn("unable to obtain keyboard information");
1093 printf("kbd%d\n", info.kb_index);
1094 printf(" %.*s%d, type:%s (%d)\n",
1095 (int)sizeof(info.kb_name), info.kb_name, info.kb_unit,
1096 get_kbd_type_name(info.kb_type), info.kb_type);
1098 if (ioctl(0, CONS_RELKBD, 0) == -1)
1099 warn("unable to release the keyboard");
1103 mux_keyboard(u_int op, char *kbd)
1105 keyboard_info_t info;
1109 * If stdin is not associated with a keyboard, the following ioctl
1112 if (ioctl(0, KDGKBINFO, &info) == -1) {
1113 warn("unable to obtain keyboard information");
1117 printf("kbd%d\n", info.kb_index);
1118 printf(" %.*s%d, type:%s (%d)\n",
1119 (int)sizeof(info.kb_name), info.kb_name, info.kb_unit,
1120 get_kbd_type_name(info.kb_type), info.kb_type);
1123 * split kbd into name and unit. find the right most part of the
1124 * kbd string that consist of only digits.
1127 memset(&info, 0, sizeof(info));
1133 unit = strpbrk(ep + 1, "0123456789");
1135 info.kb_unit = strtol(unit, &ep, 10);
1139 } while (unit != NULL && info.kb_unit == -1);
1141 if (info.kb_unit == -1) {
1142 warnx("unable to find keyboard driver unit in '%s'", kbd);
1147 warnx("unable to find keyboard driver name in '%s'", kbd);
1150 if (unit - kbd >= (int) sizeof(info.kb_name)) {
1151 warnx("keyboard name '%s' is too long", kbd);
1155 strncpy(info.kb_name, kbd, unit - kbd);
1158 * If stdin is not associated with a kbdmux(4) keyboard, the following
1162 if (ioctl(0, op, &info) == -1)
1163 warn("unable to (un)mux the keyboard");
1169 fprintf(stderr, "%s\n%s\n%s\n",
1170 "usage: kbdcontrol [-dFKix] [-A name] [-a name] [-b duration.pitch | [quiet.]belltype]",
1171 " [-r delay.repeat | speed] [-l mapfile] [-f # string]",
1172 " [-k device] [-L mapfile]");
1178 main(int argc, char **argv)
1182 while((opt = getopt(argc, argv, "A:a:b:df:iKk:Fl:L:r:x")) != -1)
1186 mux_keyboard((opt == 'A')? KBRELKBD : KBADDKBD, optarg);
1189 set_bell_values(optarg);
1195 load_keymap(optarg, 0);
1198 load_keymap(optarg, 1);
1201 set_functionkey(optarg,
1202 nextarg(argc, argv, &optind, 'f'));
1205 load_default_functionkeys();
1214 set_keyboard(optarg);
1217 set_keyrates(optarg);
1225 if ((optind != argc) || (argc == 1))