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/queue.h>
42 #include <sys/sysctl.h>
47 * HALT, PDWN, and PASTE aren't defined in 4.x, but we need them to bridge
48 * to 5.0-current so define them here as a stop gap transition measure.
51 #define HALT 0xa1 /* halt machine */
54 #define PDWN 0xa2 /* halt machine and power down */
57 #define PASTE 0xa3 /* paste from cut-paste buffer */
60 #define SPECIAL 0x80000000
62 static const char ctrl_names[32][4] = {
63 "nul", "soh", "stx", "etx", "eot", "enq", "ack", "bel",
64 "bs ", "ht ", "nl ", "vt ", "ff ", "cr ", "so ", "si ",
65 "dle", "dc1", "dc2", "dc3", "dc4", "nak", "syn", "etb",
66 "can", "em ", "sub", "esc", "fs ", "gs ", "rs ", "us "
69 static const char acc_names[15][5] = {
70 "dgra", "dacu", "dcir", "dtil", "dmac", "dbre", "ddot",
71 "duml", "dsla", "drin", "dced", "dapo", "ddac", "dogo",
75 static const char acc_names_u[15][5] = {
76 "DGRA", "DACU", "DCIR", "DTIL", "DMAC", "DBRE", "DDOT",
77 "DUML", "DSLA", "DRIN", "DCED", "DAPO", "DDAC", "DOGO",
81 static const char fkey_table[96][MAXFK] = {
82 /* 01-04 */ "\033[M", "\033[N", "\033[O", "\033[P",
83 /* 05-08 */ "\033[Q", "\033[R", "\033[S", "\033[T",
84 /* 09-12 */ "\033[U", "\033[V", "\033[W", "\033[X",
85 /* 13-16 */ "\033[Y", "\033[Z", "\033[a", "\033[b",
86 /* 17-20 */ "\033[c", "\033[d", "\033[e", "\033[f",
87 /* 21-24 */ "\033[g", "\033[h", "\033[i", "\033[j",
88 /* 25-28 */ "\033[k", "\033[l", "\033[m", "\033[n",
89 /* 29-32 */ "\033[o", "\033[p", "\033[q", "\033[r",
90 /* 33-36 */ "\033[s", "\033[t", "\033[u", "\033[v",
91 /* 37-40 */ "\033[w", "\033[x", "\033[y", "\033[z",
92 /* 41-44 */ "\033[@", "\033[[", "\033[\\","\033[]",
93 /* 45-48 */ "\033[^", "\033[_", "\033[`", "\033[{",
94 /* 49-52 */ "\033[H", "\033[A", "\033[I", "-" ,
95 /* 53-56 */ "\033[D", "\033[E", "\033[C", "+" ,
96 /* 57-60 */ "\033[F", "\033[B", "\033[G", "\033[L",
97 /* 61-64 */ "\177", "\033[J", "\033[~", "\033[}",
98 /* 65-68 */ "" , "" , "" , "" ,
99 /* 69-72 */ "" , "" , "" , "" ,
100 /* 73-76 */ "" , "" , "" , "" ,
101 /* 77-80 */ "" , "" , "" , "" ,
102 /* 81-84 */ "" , "" , "" , "" ,
103 /* 85-88 */ "" , "" , "" , "" ,
104 /* 89-92 */ "" , "" , "" , "" ,
105 /* 93-96 */ "" , "" , "" , "" ,
108 static const int delays[] = {250, 500, 750, 1000};
109 static const int repeats[] = { 34, 38, 42, 46, 50, 55, 59, 63,
110 68, 76, 84, 92, 100, 110, 118, 126,
111 136, 152, 168, 184, 200, 220, 236, 252,
112 272, 304, 336, 368, 400, 440, 472, 504};
113 static const int ndelays = (sizeof(delays) / sizeof(int));
114 static const int nrepeats = (sizeof(repeats) / sizeof(int));
116 static int paths_configured = 0;
122 static void add_keymap_path(const char *path);
123 static void dump_accent_definition(char *name, accentmap_t *accentmap);
124 static void dump_entry(int value);
125 static void dump_key_definition(char *name, keymap_t *keymap);
126 static int get_accent_definition_line(accentmap_t *);
127 static int get_entry(void);
128 static int get_key_definition_line(keymap_t *);
129 static void load_keymap(char *opt, int dumponly);
130 static void load_default_functionkeys(void);
131 static char * nextarg(int ac, char **av, int *indp, int oc);
132 static char * mkfullname(const char *s1, const char *s2, const char *s3);
133 static void print_accent_definition_line(FILE *fp, int accent,
135 static void print_entry(FILE *fp, int value);
136 static void print_key_definition_line(FILE *fp, int scancode,
137 struct keyent_t *key);
138 static void print_keymap(void);
139 static void release_keyboard(void);
140 static void mux_keyboard(u_int op, char *kbd);
141 static void set_bell_values(char *opt);
142 static void set_functionkey(char *keynumstr, char *string);
143 static void set_keyboard(char *device);
144 static void set_keyrates(char *opt);
145 static void show_kbd_info(void);
146 static void usage(void) __dead2;
149 STAILQ_ENTRY(pathent) next;
152 static STAILQ_HEAD(, pathent) pathlist = STAILQ_HEAD_INITIALIZER(pathlist);
154 /* Detect presence of vt(4). */
158 char vty_name[4] = "";
159 size_t len = sizeof(vty_name);
161 if (sysctlbyname("kern.vty", vty_name, &len, NULL, 0) != 0)
163 return (strcmp(vty_name, "vt") == 0);
167 nextarg(int ac, char **av, int *indp, int oc)
170 return(av[(*indp)++]);
171 warnx("option requires two arguments -- %c", oc);
177 mkfullname(const char *s1, const char *s2, const char *s3)
179 static char *buf = NULL;
183 f = strlen(s1) + strlen(s2) + strlen(s3) + 1;
186 buf = (char *)realloc(buf, f);
188 buf = (char *)malloc(f);
206 switch ((token = yylex())) {
208 return NOP | SPECIAL;
210 return LSH | SPECIAL;
212 return RSH | SPECIAL;
214 return CLK | SPECIAL;
216 return NLK | SPECIAL;
218 return SLK | SPECIAL;
220 return BTAB | SPECIAL;
222 return LALT | SPECIAL;
224 return LCTR | SPECIAL;
226 return NEXT | SPECIAL;
228 return PREV | SPECIAL;
230 return RCTR | SPECIAL;
232 return RALT | SPECIAL;
234 return ALK | SPECIAL;
236 return ASH | SPECIAL;
238 return META | SPECIAL;
240 return RBT | SPECIAL;
242 return DBG | SPECIAL;
244 return SUSP | SPECIAL;
246 return SPSC | SPECIAL;
248 return PNC | SPECIAL;
250 return LSHA | SPECIAL;
252 return RSHA | SPECIAL;
254 return LCTRA | SPECIAL;
256 return RCTRA | SPECIAL;
258 return LALTA | SPECIAL;
260 return RALTA | SPECIAL;
262 return HALT | SPECIAL;
264 return PDWN | SPECIAL;
266 return PASTE | SPECIAL;
268 if (ACC(number) > L_ACC)
270 return ACC(number) | SPECIAL;
272 if (F(number) > L_FN)
274 return F(number) | SPECIAL;
276 if (S(number) > L_SCR)
278 return S(number) | SPECIAL;
280 return (unsigned char)letter;
282 if (number < 0x000000 || number > 0x10FFFF)
291 get_definition_line(FILE *file, keymap_t *keymap, accentmap_t *accentmap)
301 c = get_key_definition_line(keymap);
303 errx(1, "invalid key definition");
304 if (c > keymap->n_keys)
308 c = get_accent_definition_line(accentmap);
310 errx(1, "invalid accent key definition");
311 if (c > accentmap->n_accs)
312 accentmap->n_accs = c;
318 errx(1, "illegal definition line");
324 get_key_definition_line(keymap_t *map)
326 int i, def, scancode;
328 /* check scancode number */
329 if (number < 0 || number >= NUM_KEYS)
333 /* get key definitions */
334 map->key[scancode].spcl = 0;
335 for (i=0; i<NUM_STATES; i++) {
336 if ((def = get_entry()) == -1)
339 map->key[scancode].spcl |= (0x80 >> i);
340 map->key[scancode].map[i] = def & ~SPECIAL;
342 /* get lock state key def */
343 if ((token = yylex()) != TFLAG)
345 map->key[scancode].flgs = number;
347 return (scancode + 1);
351 get_accent_definition_line(accentmap_t *map)
357 if (ACC(number) < F_ACC || ACC(number) > L_ACC)
358 /* number out of range */
361 if (map->acc[accent].accchar != 0) {
362 /* this entry has already been defined before! */
363 errx(1, "duplicated accent key definition");
366 switch ((token = yylex())) {
368 map->acc[accent].accchar = letter;
371 map->acc[accent].accchar = number;
377 for (i = 0; (token = yylex()) == '(';) {
378 switch ((token = yylex())) {
388 switch ((token = yylex())) {
398 if ((token = yylex()) != ')')
400 if (i >= NUM_ACCENTCHARS) {
401 warnx("too many accented characters, ignored");
404 map->acc[accent].map[i][0] = c1;
405 map->acc[accent].map[i][1] = c2;
412 print_entry(FILE *fp, int value)
414 int val = value & ~SPECIAL;
418 fprintf(fp, " nop ");
421 fprintf(fp, " lshift");
424 fprintf(fp, " rshift");
427 fprintf(fp, " clock ");
430 fprintf(fp, " nlock ");
433 fprintf(fp, " slock ");
436 fprintf(fp, " btab ");
439 fprintf(fp, " lalt ");
442 fprintf(fp, " lctrl ");
445 fprintf(fp, " nscr ");
448 fprintf(fp, " pscr ");
451 fprintf(fp, " rctrl ");
454 fprintf(fp, " ralt ");
457 fprintf(fp, " alock ");
460 fprintf(fp, " ashift");
463 fprintf(fp, " meta ");
466 fprintf(fp, " boot ");
469 fprintf(fp, " debug ");
472 fprintf(fp, " susp ");
475 fprintf(fp, " saver ");
478 fprintf(fp, " panic ");
481 fprintf(fp, " lshifta");
484 fprintf(fp, " rshifta");
486 case LCTRA | SPECIAL:
487 fprintf(fp, " lctrla");
489 case RCTRA | SPECIAL:
490 fprintf(fp, " rctrla");
492 case LALTA | SPECIAL:
493 fprintf(fp, " lalta ");
495 case RALTA | SPECIAL:
496 fprintf(fp, " ralta ");
499 fprintf(fp, " halt ");
502 fprintf(fp, " pdwn ");
504 case PASTE | SPECIAL:
505 fprintf(fp, " paste ");
508 if (value & SPECIAL) {
509 if (val >= F_FN && val <= L_FN)
510 fprintf(fp, " fkey%02d", val - F_FN + 1);
511 else if (val >= F_SCR && val <= L_SCR)
512 fprintf(fp, " scr%02d ", val - F_SCR + 1);
513 else if (val >= F_ACC && val <= L_ACC)
514 fprintf(fp, " %-6s", acc_names[val - F_ACC]);
516 fprintf(fp, " 0x%02x ", val);
518 fprintf(fp, " %3d ", val);
522 fprintf(fp, " %s ", ctrl_names[val]);
524 fprintf(fp, " del ");
525 else if (isascii(val) && isprint(val))
526 fprintf(fp, " '%c' ", val);
528 fprintf(fp, " 0x%02x ", val);
530 fprintf(fp, " %3d ", val);
536 print_key_definition_line(FILE *fp, int scancode, struct keyent_t *key)
540 /* print scancode number */
542 fprintf(fp, " 0x%02x ", scancode);
544 fprintf(fp, " %03d ", scancode);
546 /* print key definitions */
547 for (i=0; i<NUM_STATES; i++) {
548 if (key->spcl & (0x80 >> i))
549 print_entry(fp, key->map[i] | SPECIAL);
551 print_entry(fp, key->map[i]);
554 /* print lock state key def */
572 print_accent_definition_line(FILE *fp, int accent, struct acc_t *key)
577 if (key->accchar == 0)
580 /* print accent number */
581 fprintf(fp, " %-6s", acc_names[accent]);
582 if (isascii(key->accchar) && isprint(key->accchar))
583 fprintf(fp, "'%c' ", key->accchar);
585 fprintf(fp, "0x%02x ", key->accchar);
587 fprintf(fp, "%03d ", key->accchar);
589 for (i = 0; i < NUM_ACCENTCHARS; ++i) {
593 if ((i > 0) && ((i % 4) == 0))
595 if (isascii(c) && isprint(c))
596 fprintf(fp, "( '%c' ", c);
598 fprintf(fp, "(0x%02x ", c);
600 fprintf(fp, "( %03d ", c);
602 if (isascii(c) && isprint(c))
603 fprintf(fp, "'%c' ) ", c);
605 fprintf(fp, "0x%02x) ", c);
607 fprintf(fp, "%03d ) ", c);
613 dump_entry(int value)
615 if (value & SPECIAL) {
709 if (value >= F_FN && value <= L_FN)
710 printf(" F(%2d),", value - F_FN + 1);
711 else if (value >= F_SCR && value <= L_SCR)
712 printf(" S(%2d),", value - F_SCR + 1);
713 else if (value >= F_ACC && value <= L_ACC)
714 printf(" %-4s, ", acc_names_u[value - F_ACC]);
716 printf(" 0x%02X, ", value);
719 } else if (value == '\'') {
721 } else if (value == '\\') {
723 } else if (isascii(value) && isprint(value)) {
724 printf(" '%c', ", value);
726 printf(" 0x%02X, ", value);
731 dump_key_definition(char *name, keymap_t *keymap)
735 printf("static keymap_t keymap_%s = { 0x%02x, {\n",
736 name, (unsigned)keymap->n_keys);
739 " * scan cntrl alt alt cntrl\n"
740 " * code base shift cntrl shift alt shift cntrl shift spcl flgs\n"
741 " * ---------------------------------------------------------------------------\n"
743 for (i = 0; i < keymap->n_keys; i++) {
744 printf("/*%02x*/{{", i);
745 for (j = 0; j < NUM_STATES; j++) {
746 if (keymap->key[i].spcl & (0x80 >> j))
747 dump_entry(keymap->key[i].map[j] | SPECIAL);
749 dump_entry(keymap->key[i].map[j]);
751 printf("}, 0x%02X,0x%02X },\n",
752 (unsigned)keymap->key[i].spcl,
753 (unsigned)keymap->key[i].flgs);
759 dump_accent_definition(char *name, accentmap_t *accentmap)
764 printf("static accentmap_t accentmap_%s = { %d",
765 name, accentmap->n_accs);
766 if (accentmap->n_accs <= 0) {
771 for (i = 0; i < NUM_DEADKEYS; i++) {
772 printf(" /* %s=%d */\n {", acc_names[i], i);
773 c = accentmap->acc[i].accchar;
777 printf(" '\\\\', {");
778 else if (isascii(c) && isprint(c))
779 printf(" '%c', {", c);
781 printf(" 0x00 }, \n");
784 printf(" 0x%02x, {", c);
785 for (j = 0; j < NUM_ACCENTCHARS; j++) {
786 c = accentmap->acc[i].map[j][0];
789 if ((j > 0) && ((j % 4) == 0))
791 if (isascii(c) && isprint(c))
792 printf(" { '%c',", c);
794 printf(" { 0x%02x,", c);
795 printf("0x%02x },", accentmap->acc[i].map[j][1]);
803 add_keymap_path(const char *path)
809 if ((pe = malloc(sizeof(*pe))) == NULL ||
810 (pe->path = malloc(len + 2)) == NULL)
812 memcpy(pe->path, path, len);
813 if (len > 0 && path[len - 1] != '/')
814 pe->path[len++] = '/';
815 pe->path[len] = '\0';
816 STAILQ_INSERT_TAIL(&pathlist, pe, next);
820 load_keymap(char *opt, int dumponly)
823 accentmap_t accentmap;
828 char blank[] = "", keymap_path[] = KEYMAP_PATH;
829 char vt_keymap_path[] = VT_KEYMAP_PATH, dotkbd[] = ".kbd";
830 char *postfix[] = {blank, dotkbd, NULL};
832 if (!paths_configured) {
833 cp = getenv("KEYMAP_PATH");
838 add_keymap_path(vt_keymap_path);
840 add_keymap_path(keymap_path);
841 paths_configured = 1;
845 STAILQ_FOREACH(pe, &pathlist, next) {
846 for (j=0; postfix[j] && file == NULL; j++) {
847 name = mkfullname(pe->path, opt, postfix[j]);
848 file = fopen(name, "r");
854 warn("keymap file \"%s\" not found", opt);
857 memset(&keymap, 0, sizeof(keymap));
858 memset(&accentmap, 0, sizeof(accentmap));
861 if (get_definition_line(file, &keymap, &accentmap) < 0)
865 /* fix up the filename to make it a valid C identifier */
866 for (cp = opt; *cp; cp++)
867 if (!isalpha(*cp) && !isdigit(*cp)) *cp = '_';
869 " * Automatically generated from %s.\n"
872 dump_key_definition(opt, &keymap);
873 dump_accent_definition(opt, &accentmap);
876 if ((keymap.n_keys > 0) && (ioctl(0, PIO_KEYMAP, &keymap) < 0)) {
877 warn("setting keymap");
881 if ((accentmap.n_accs > 0)
882 && (ioctl(0, PIO_DEADKEYMAP, &accentmap) < 0)) {
883 warn("setting accentmap");
893 accentmap_t accentmap;
896 if (ioctl(0, GIO_KEYMAP, &keymap) < 0)
897 err(1, "getting keymap");
898 if (ioctl(0, GIO_DEADKEYMAP, &accentmap) < 0)
899 memset(&accentmap, 0, sizeof(accentmap));
902 "# scan cntrl alt alt cntrl lock\n"
903 "# code base shift cntrl shift alt shift cntrl shift state\n"
904 "# ------------------------------------------------------------------\n"
906 for (i=0; i<keymap.n_keys; i++)
907 print_key_definition_line(stdout, i, &keymap.key[i]);
910 for (i = 0; i < NUM_DEADKEYS; i++)
911 print_accent_definition_line(stdout, i, &accentmap.acc[i]);
916 load_default_functionkeys(void)
921 for (i=0; i<NUM_FKEYS; i++) {
923 strcpy(fkey.keydef, fkey_table[i]);
924 fkey.flen = strlen(fkey_table[i]);
925 if (ioctl(0, SETFKEY, &fkey) < 0)
926 warn("setting function key");
931 set_functionkey(char *keynumstr, char *string)
935 if (!strcmp(keynumstr, "load") && !strcmp(string, "default")) {
936 load_default_functionkeys();
939 fkey.keynum = atoi(keynumstr);
940 if (fkey.keynum < 1 || fkey.keynum > NUM_FKEYS) {
941 warnx("function key number must be between 1 and %d",
945 if ((fkey.flen = strlen(string)) > MAXFK) {
946 warnx("function key string too long (%d > %d)",
950 strncpy(fkey.keydef, string, MAXFK);
952 if (ioctl(0, SETFKEY, &fkey) < 0)
953 warn("setting function key");
957 set_bell_values(char *opt)
959 int bell, duration, pitch;
962 if (!strncmp(opt, "quiet.", 6)) {
963 bell = CONS_QUIET_BELL;
966 if (!strcmp(opt, "visual"))
967 bell |= CONS_VISUAL_BELL;
968 else if (!strcmp(opt, "normal"))
969 duration = 5, pitch = 800;
970 else if (!strcmp(opt, "off"))
971 duration = 0, pitch = 0;
976 duration = strtol(opt, &v1, 0);
977 if ((duration < 0) || (*v1 != '.'))
980 pitch = strtol(opt, &v1, 0);
981 if ((pitch < 0) || (*opt == '\0') || (*v1 != '\0')) {
983 warnx("argument to -b must be duration.pitch or [quiet.]visual|normal|off");
987 pitch = 1193182 / pitch; /* in Hz */
988 duration /= 10; /* in 10 m sec */
991 ioctl(0, CONS_BELLTYPE, &bell);
992 if (!(bell & CONS_VISUAL_BELL))
993 fprintf(stderr, "
\e[=%d;%dB", pitch, duration);
997 set_keyrates(char *opt)
1004 if (!strcmp(opt, "slow")) {
1005 delay = 1000, repeat = 500;
1007 } else if (!strcmp(opt, "normal")) {
1008 delay = 500, repeat = 125;
1010 } else if (!strcmp(opt, "fast")) {
1017 delay = strtol(opt, &v1, 0);
1018 if ((delay < 0) || (*v1 != '.'))
1021 repeat = strtol(opt, &v1, 0);
1022 if ((repeat < 0) || (*opt == '\0') || (*v1 != '\0')) {
1024 warnx("argument to -r must be delay.repeat or slow|normal|fast");
1027 for (n = 0; n < ndelays - 1; n++)
1028 if (delay <= delays[n])
1031 for (n = 0; n < nrepeats - 1; n++)
1032 if (repeat <= repeats[n])
1039 if (ioctl(0, KDSETREPEAT, arg)) {
1040 if (ioctl(0, KDSETRAD, (d << 5) | r))
1041 warn("setting keyboard rate");
1046 get_kbd_type_name(int type)
1053 { KB_101, "AT 101/102" },
1054 { KB_OTHER, "generic" },
1058 for (i = 0; i < sizeof(name_table)/sizeof(name_table[0]); ++i) {
1059 if (type == name_table[i].type)
1060 return name_table[i].name;
1068 keyboard_info_t info;
1070 if (ioctl(0, KDGKBINFO, &info) == -1) {
1071 warn("unable to obtain keyboard information");
1074 printf("kbd%d:\n", info.kb_index);
1075 printf(" %.*s%d, type:%s (%d)\n",
1076 (int)sizeof(info.kb_name), info.kb_name, info.kb_unit,
1077 get_kbd_type_name(info.kb_type), info.kb_type);
1081 set_keyboard(char *device)
1083 keyboard_info_t info;
1086 fd = open(device, O_RDONLY);
1088 warn("cannot open %s", device);
1091 if (ioctl(fd, KDGKBINFO, &info) == -1) {
1092 warn("unable to obtain keyboard information");
1097 * The keyboard device driver won't release the keyboard by
1098 * the following ioctl, but it automatically will, when the device
1099 * is closed. So, we don't check error here.
1101 ioctl(fd, CONS_RELKBD, 0);
1104 printf("kbd%d\n", info.kb_index);
1105 printf(" %.*s%d, type:%s (%d)\n",
1106 (int)sizeof(info.kb_name), info.kb_name, info.kb_unit,
1107 get_kbd_type_name(info.kb_type), info.kb_type);
1110 if (ioctl(0, CONS_SETKBD, info.kb_index) == -1)
1111 warn("unable to set keyboard");
1115 release_keyboard(void)
1117 keyboard_info_t info;
1120 * If stdin is not associated with a keyboard, the following ioctl
1123 if (ioctl(0, KDGKBINFO, &info) == -1) {
1124 warn("unable to obtain keyboard information");
1128 printf("kbd%d\n", info.kb_index);
1129 printf(" %.*s%d, type:%s (%d)\n",
1130 (int)sizeof(info.kb_name), info.kb_name, info.kb_unit,
1131 get_kbd_type_name(info.kb_type), info.kb_type);
1133 if (ioctl(0, CONS_RELKBD, 0) == -1)
1134 warn("unable to release the keyboard");
1138 mux_keyboard(u_int op, char *kbd)
1140 keyboard_info_t info;
1144 * If stdin is not associated with a keyboard, the following ioctl
1147 if (ioctl(0, KDGKBINFO, &info) == -1) {
1148 warn("unable to obtain keyboard information");
1152 printf("kbd%d\n", info.kb_index);
1153 printf(" %.*s%d, type:%s (%d)\n",
1154 (int)sizeof(info.kb_name), info.kb_name, info.kb_unit,
1155 get_kbd_type_name(info.kb_type), info.kb_type);
1158 * split kbd into name and unit. find the right most part of the
1159 * kbd string that consist of only digits.
1162 memset(&info, 0, sizeof(info));
1168 unit = strpbrk(ep + 1, "0123456789");
1170 info.kb_unit = strtol(unit, &ep, 10);
1174 } while (unit != NULL && info.kb_unit == -1);
1176 if (info.kb_unit == -1) {
1177 warnx("unable to find keyboard driver unit in '%s'", kbd);
1182 warnx("unable to find keyboard driver name in '%s'", kbd);
1185 if (unit - kbd >= (int) sizeof(info.kb_name)) {
1186 warnx("keyboard name '%s' is too long", kbd);
1190 strncpy(info.kb_name, kbd, unit - kbd);
1193 * If stdin is not associated with a kbdmux(4) keyboard, the following
1197 if (ioctl(0, op, &info) == -1)
1198 warn("unable to (un)mux the keyboard");
1204 fprintf(stderr, "%s\n%s\n%s\n",
1205 "usage: kbdcontrol [-dFKix] [-A name] [-a name] [-b duration.pitch | [quiet.]belltype]",
1206 " [-r delay.repeat | speed] [-l mapfile] [-f # string]",
1207 " [-k device] [-L mapfile] [-P path]");
1213 main(int argc, char **argv)
1215 const char *optstring = "A:a:b:df:iKk:Fl:L:P:r:x";
1218 /* Collect any -P arguments, regardless of where they appear. */
1219 while ((opt = getopt(argc, argv, optstring)) != -1)
1221 add_keymap_path(optarg);
1223 optind = optreset = 1;
1224 while ((opt = getopt(argc, argv, optstring)) != -1)
1228 mux_keyboard((opt == 'A')? KBRELKBD : KBADDKBD, optarg);
1231 set_bell_values(optarg);
1237 load_keymap(optarg, 0);
1240 load_keymap(optarg, 1);
1245 set_functionkey(optarg,
1246 nextarg(argc, argv, &optind, 'f'));
1249 load_default_functionkeys();
1258 set_keyboard(optarg);
1261 set_keyrates(optarg);
1269 if ((optind != argc) || (argc == 1))