1994-08-17 08:59:37 +00:00
|
|
|
/*-
|
2017-11-27 15:37:16 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2011-12-30 00:59:08 +00:00
|
|
|
* Copyright (c) 1994-1995 Søren Schmidt
|
1994-08-17 08:59:37 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
1995-01-28 22:18:05 +00:00
|
|
|
* notice, this list of conditions and the following disclaimer,
|
|
|
|
* in this position and unchanged.
|
1994-08-17 08:59:37 +00:00
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
2002-06-02 20:05:59 +00:00
|
|
|
* derived from this software without specific prior written permission
|
1994-08-17 08:59:37 +00:00
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-05-03 21:06:42 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1997-09-19 06:28:57 +00:00
|
|
|
|
1994-08-17 08:59:37 +00:00
|
|
|
#include <ctype.h>
|
1997-09-19 06:28:57 +00:00
|
|
|
#include <err.h>
|
1994-08-17 08:59:37 +00:00
|
|
|
#include <stdio.h>
|
1997-09-19 06:28:57 +00:00
|
|
|
#include <stdlib.h>
|
1994-10-25 20:50:41 +00:00
|
|
|
#include <string.h>
|
1997-09-19 06:28:57 +00:00
|
|
|
#include <unistd.h>
|
1999-01-11 03:20:32 +00:00
|
|
|
#include <fcntl.h>
|
2000-10-08 21:34:00 +00:00
|
|
|
#include <sys/kbio.h>
|
|
|
|
#include <sys/consio.h>
|
2016-03-16 04:05:02 +00:00
|
|
|
#include <sys/queue.h>
|
2014-05-29 14:39:25 +00:00
|
|
|
#include <sys/sysctl.h>
|
1994-08-17 08:59:37 +00:00
|
|
|
#include "path.h"
|
|
|
|
#include "lex.h"
|
|
|
|
|
2001-05-15 22:53:05 +00:00
|
|
|
/*
|
2002-02-08 09:37:12 +00:00
|
|
|
* HALT, PDWN, and PASTE aren't defined in 4.x, but we need them to bridge
|
|
|
|
* to 5.0-current so define them here as a stop gap transition measure.
|
2001-05-15 22:53:05 +00:00
|
|
|
*/
|
2002-02-08 09:37:12 +00:00
|
|
|
#ifndef HALT
|
|
|
|
#define HALT 0xa1 /* halt machine */
|
|
|
|
#endif
|
|
|
|
#ifndef PDWN
|
|
|
|
#define PDWN 0xa2 /* halt machine and power down */
|
|
|
|
#endif
|
2001-05-15 22:53:05 +00:00
|
|
|
#ifndef PASTE
|
|
|
|
#define PASTE 0xa3 /* paste from cut-paste buffer */
|
|
|
|
#endif
|
|
|
|
|
2009-08-24 09:17:01 +00:00
|
|
|
#define SPECIAL 0x80000000
|
|
|
|
|
2011-12-12 12:33:38 +00:00
|
|
|
static const char ctrl_names[32][4] = {
|
1995-05-30 03:57:47 +00:00
|
|
|
"nul", "soh", "stx", "etx", "eot", "enq", "ack", "bel",
|
1994-08-17 08:59:37 +00:00
|
|
|
"bs ", "ht ", "nl ", "vt ", "ff ", "cr ", "so ", "si ",
|
|
|
|
"dle", "dc1", "dc2", "dc3", "dc4", "nak", "syn", "etb",
|
1998-08-06 09:44:23 +00:00
|
|
|
"can", "em ", "sub", "esc", "fs ", "gs ", "rs ", "us "
|
1994-08-17 08:59:37 +00:00
|
|
|
};
|
|
|
|
|
2011-12-12 12:33:38 +00:00
|
|
|
static const char acc_names[15][5] = {
|
1998-01-07 08:43:28 +00:00
|
|
|
"dgra", "dacu", "dcir", "dtil", "dmac", "dbre", "ddot",
|
|
|
|
"duml", "dsla", "drin", "dced", "dapo", "ddac", "dogo",
|
|
|
|
"dcar",
|
|
|
|
};
|
|
|
|
|
2011-12-12 12:33:38 +00:00
|
|
|
static const char acc_names_u[15][5] = {
|
1998-01-07 08:43:28 +00:00
|
|
|
"DGRA", "DACU", "DCIR", "DTIL", "DMAC", "DBRE", "DDOT",
|
|
|
|
"DUML", "DSLA", "DRIN", "DCED", "DAPO", "DDAC", "DOGO",
|
|
|
|
"DCAR",
|
|
|
|
};
|
|
|
|
|
2011-12-12 12:33:38 +00:00
|
|
|
static const char fkey_table[96][MAXFK] = {
|
1995-01-28 22:18:05 +00:00
|
|
|
/* 01-04 */ "\033[M", "\033[N", "\033[O", "\033[P",
|
|
|
|
/* 05-08 */ "\033[Q", "\033[R", "\033[S", "\033[T",
|
|
|
|
/* 09-12 */ "\033[U", "\033[V", "\033[W", "\033[X",
|
|
|
|
/* 13-16 */ "\033[Y", "\033[Z", "\033[a", "\033[b",
|
|
|
|
/* 17-20 */ "\033[c", "\033[d", "\033[e", "\033[f",
|
|
|
|
/* 21-24 */ "\033[g", "\033[h", "\033[i", "\033[j",
|
|
|
|
/* 25-28 */ "\033[k", "\033[l", "\033[m", "\033[n",
|
|
|
|
/* 29-32 */ "\033[o", "\033[p", "\033[q", "\033[r",
|
|
|
|
/* 33-36 */ "\033[s", "\033[t", "\033[u", "\033[v",
|
|
|
|
/* 37-40 */ "\033[w", "\033[x", "\033[y", "\033[z",
|
|
|
|
/* 41-44 */ "\033[@", "\033[[", "\033[\\","\033[]",
|
1995-06-11 19:33:05 +00:00
|
|
|
/* 45-48 */ "\033[^", "\033[_", "\033[`", "\033[{",
|
1995-01-28 22:18:05 +00:00
|
|
|
/* 49-52 */ "\033[H", "\033[A", "\033[I", "-" ,
|
|
|
|
/* 53-56 */ "\033[D", "\033[E", "\033[C", "+" ,
|
|
|
|
/* 57-60 */ "\033[F", "\033[B", "\033[G", "\033[L",
|
1995-06-11 19:33:05 +00:00
|
|
|
/* 61-64 */ "\177", "\033[J", "\033[~", "\033[}",
|
1995-01-28 22:18:05 +00:00
|
|
|
/* 65-68 */ "" , "" , "" , "" ,
|
|
|
|
/* 69-72 */ "" , "" , "" , "" ,
|
|
|
|
/* 73-76 */ "" , "" , "" , "" ,
|
|
|
|
/* 77-80 */ "" , "" , "" , "" ,
|
|
|
|
/* 81-84 */ "" , "" , "" , "" ,
|
|
|
|
/* 85-88 */ "" , "" , "" , "" ,
|
|
|
|
/* 89-92 */ "" , "" , "" , "" ,
|
|
|
|
/* 93-96 */ "" , "" , "" , "" ,
|
1994-08-17 08:59:37 +00:00
|
|
|
};
|
|
|
|
|
2011-12-12 12:33:38 +00:00
|
|
|
static const int delays[] = {250, 500, 750, 1000};
|
|
|
|
static const int repeats[] = { 34, 38, 42, 46, 50, 55, 59, 63,
|
|
|
|
68, 76, 84, 92, 100, 110, 118, 126,
|
|
|
|
136, 152, 168, 184, 200, 220, 236, 252,
|
|
|
|
272, 304, 336, 368, 400, 440, 472, 504};
|
|
|
|
static const int ndelays = (sizeof(delays) / sizeof(int));
|
|
|
|
static const int nrepeats = (sizeof(repeats) / sizeof(int));
|
|
|
|
static int hex = 0;
|
2016-03-16 04:05:02 +00:00
|
|
|
static int paths_configured = 0;
|
2011-12-12 12:33:38 +00:00
|
|
|
static int token;
|
|
|
|
|
|
|
|
int number;
|
|
|
|
char letter;
|
|
|
|
|
2016-03-16 04:05:02 +00:00
|
|
|
static void add_keymap_path(const char *path);
|
2011-12-12 12:33:38 +00:00
|
|
|
static void dump_accent_definition(char *name, accentmap_t *accentmap);
|
|
|
|
static void dump_entry(int value);
|
|
|
|
static void dump_key_definition(char *name, keymap_t *keymap);
|
|
|
|
static int get_accent_definition_line(accentmap_t *);
|
|
|
|
static int get_entry(void);
|
|
|
|
static int get_key_definition_line(keymap_t *);
|
|
|
|
static void load_keymap(char *opt, int dumponly);
|
|
|
|
static void load_default_functionkeys(void);
|
|
|
|
static char * nextarg(int ac, char **av, int *indp, int oc);
|
|
|
|
static char * mkfullname(const char *s1, const char *s2, const char *s3);
|
|
|
|
static void print_accent_definition_line(FILE *fp, int accent,
|
|
|
|
struct acc_t *key);
|
|
|
|
static void print_entry(FILE *fp, int value);
|
|
|
|
static void print_key_definition_line(FILE *fp, int scancode,
|
|
|
|
struct keyent_t *key);
|
|
|
|
static void print_keymap(void);
|
|
|
|
static void release_keyboard(void);
|
|
|
|
static void mux_keyboard(u_int op, char *kbd);
|
|
|
|
static void set_bell_values(char *opt);
|
|
|
|
static void set_functionkey(char *keynumstr, char *string);
|
|
|
|
static void set_keyboard(char *device);
|
|
|
|
static void set_keyrates(char *opt);
|
|
|
|
static void show_kbd_info(void);
|
|
|
|
static void usage(void) __dead2;
|
|
|
|
|
2016-03-16 04:05:02 +00:00
|
|
|
struct pathent {
|
|
|
|
STAILQ_ENTRY(pathent) next;
|
|
|
|
char *path;
|
|
|
|
};
|
|
|
|
static STAILQ_HEAD(, pathent) pathlist = STAILQ_HEAD_INITIALIZER(pathlist);
|
|
|
|
|
2014-05-29 14:39:25 +00:00
|
|
|
/* Detect presence of vt(4). */
|
|
|
|
static int
|
|
|
|
is_vt4(void)
|
|
|
|
{
|
2014-07-02 20:40:59 +00:00
|
|
|
char vty_name[4] = "";
|
|
|
|
size_t len = sizeof(vty_name);
|
2014-05-29 14:39:25 +00:00
|
|
|
|
2014-07-02 20:40:59 +00:00
|
|
|
if (sysctlbyname("kern.vty", vty_name, &len, NULL, 0) != 0)
|
|
|
|
return (0);
|
|
|
|
return (strcmp(vty_name, "vt") == 0);
|
2014-05-29 14:39:25 +00:00
|
|
|
}
|
|
|
|
|
2011-12-12 12:33:38 +00:00
|
|
|
static char *
|
1994-08-17 08:59:37 +00:00
|
|
|
nextarg(int ac, char **av, int *indp, int oc)
|
|
|
|
{
|
|
|
|
if (*indp < ac)
|
|
|
|
return(av[(*indp)++]);
|
1997-09-19 06:28:57 +00:00
|
|
|
warnx("option requires two arguments -- %c", oc);
|
1994-08-17 08:59:37 +00:00
|
|
|
usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-12 12:33:38 +00:00
|
|
|
static char *
|
1994-08-17 08:59:37 +00:00
|
|
|
mkfullname(const char *s1, const char *s2, const char *s3)
|
|
|
|
{
|
1995-01-12 11:47:05 +00:00
|
|
|
static char *buf = NULL;
|
|
|
|
static int bufl = 0;
|
|
|
|
int f;
|
1994-08-17 08:59:37 +00:00
|
|
|
|
|
|
|
f = strlen(s1) + strlen(s2) + strlen(s3) + 1;
|
2001-05-29 13:59:02 +00:00
|
|
|
if (f > bufl) {
|
1994-08-17 08:59:37 +00:00
|
|
|
if (buf)
|
|
|
|
buf = (char *)realloc(buf, f);
|
|
|
|
else
|
|
|
|
buf = (char *)malloc(f);
|
2001-05-29 13:59:02 +00:00
|
|
|
}
|
1994-08-17 08:59:37 +00:00
|
|
|
if (!buf) {
|
|
|
|
bufl = 0;
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
bufl = f;
|
|
|
|
strcpy(buf, s1);
|
|
|
|
strcat(buf, s2);
|
|
|
|
strcat(buf, s3);
|
|
|
|
return(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-12 12:33:38 +00:00
|
|
|
static int
|
2002-07-11 21:12:18 +00:00
|
|
|
get_entry(void)
|
1994-08-17 08:59:37 +00:00
|
|
|
{
|
1998-01-07 08:43:28 +00:00
|
|
|
switch ((token = yylex())) {
|
1994-08-17 08:59:37 +00:00
|
|
|
case TNOP:
|
2009-08-24 09:17:01 +00:00
|
|
|
return NOP | SPECIAL;
|
1994-08-17 08:59:37 +00:00
|
|
|
case TLSH:
|
2009-08-24 09:17:01 +00:00
|
|
|
return LSH | SPECIAL;
|
1994-08-17 08:59:37 +00:00
|
|
|
case TRSH:
|
2009-08-24 09:17:01 +00:00
|
|
|
return RSH | SPECIAL;
|
1994-08-17 08:59:37 +00:00
|
|
|
case TCLK:
|
2009-08-24 09:17:01 +00:00
|
|
|
return CLK | SPECIAL;
|
1994-08-17 08:59:37 +00:00
|
|
|
case TNLK:
|
2009-08-24 09:17:01 +00:00
|
|
|
return NLK | SPECIAL;
|
1994-08-17 08:59:37 +00:00
|
|
|
case TSLK:
|
2009-08-24 09:17:01 +00:00
|
|
|
return SLK | SPECIAL;
|
1994-08-17 08:59:37 +00:00
|
|
|
case TBTAB:
|
2009-08-24 09:17:01 +00:00
|
|
|
return BTAB | SPECIAL;
|
1994-08-17 08:59:37 +00:00
|
|
|
case TLALT:
|
2009-08-24 09:17:01 +00:00
|
|
|
return LALT | SPECIAL;
|
1994-08-17 08:59:37 +00:00
|
|
|
case TLCTR:
|
2009-08-24 09:17:01 +00:00
|
|
|
return LCTR | SPECIAL;
|
1994-08-17 08:59:37 +00:00
|
|
|
case TNEXT:
|
2009-08-24 09:17:01 +00:00
|
|
|
return NEXT | SPECIAL;
|
1999-06-22 14:15:46 +00:00
|
|
|
case TPREV:
|
2009-08-24 09:17:01 +00:00
|
|
|
return PREV | SPECIAL;
|
1994-08-17 08:59:37 +00:00
|
|
|
case TRCTR:
|
2009-08-24 09:17:01 +00:00
|
|
|
return RCTR | SPECIAL;
|
1994-08-17 08:59:37 +00:00
|
|
|
case TRALT:
|
2009-08-24 09:17:01 +00:00
|
|
|
return RALT | SPECIAL;
|
1994-08-17 08:59:37 +00:00
|
|
|
case TALK:
|
2009-08-24 09:17:01 +00:00
|
|
|
return ALK | SPECIAL;
|
1994-08-17 08:59:37 +00:00
|
|
|
case TASH:
|
2009-08-24 09:17:01 +00:00
|
|
|
return ASH | SPECIAL;
|
1994-08-17 08:59:37 +00:00
|
|
|
case TMETA:
|
2009-08-24 09:17:01 +00:00
|
|
|
return META | SPECIAL;
|
1994-08-17 08:59:37 +00:00
|
|
|
case TRBT:
|
2009-08-24 09:17:01 +00:00
|
|
|
return RBT | SPECIAL;
|
1994-08-17 08:59:37 +00:00
|
|
|
case TDBG:
|
2009-08-24 09:17:01 +00:00
|
|
|
return DBG | SPECIAL;
|
1995-01-28 22:18:05 +00:00
|
|
|
case TSUSP:
|
2009-08-24 09:17:01 +00:00
|
|
|
return SUSP | SPECIAL;
|
1998-08-03 11:33:22 +00:00
|
|
|
case TSPSC:
|
2009-08-24 09:17:01 +00:00
|
|
|
return SPSC | SPECIAL;
|
1999-12-10 04:24:27 +00:00
|
|
|
case TPANIC:
|
2009-08-24 09:17:01 +00:00
|
|
|
return PNC | SPECIAL;
|
1999-12-10 04:24:27 +00:00
|
|
|
case TLSHA:
|
2009-08-24 09:17:01 +00:00
|
|
|
return LSHA | SPECIAL;
|
1999-12-10 04:24:27 +00:00
|
|
|
case TRSHA:
|
2009-08-24 09:17:01 +00:00
|
|
|
return RSHA | SPECIAL;
|
1999-12-10 04:24:27 +00:00
|
|
|
case TLCTRA:
|
2009-08-24 09:17:01 +00:00
|
|
|
return LCTRA | SPECIAL;
|
1999-12-10 04:24:27 +00:00
|
|
|
case TRCTRA:
|
2009-08-24 09:17:01 +00:00
|
|
|
return RCTRA | SPECIAL;
|
1999-12-10 04:24:27 +00:00
|
|
|
case TLALTA:
|
2009-08-24 09:17:01 +00:00
|
|
|
return LALTA | SPECIAL;
|
1999-12-10 04:24:27 +00:00
|
|
|
case TRALTA:
|
2009-08-24 09:17:01 +00:00
|
|
|
return RALTA | SPECIAL;
|
2000-09-11 20:37:42 +00:00
|
|
|
case THALT:
|
2009-08-24 09:17:01 +00:00
|
|
|
return HALT | SPECIAL;
|
2000-09-11 20:37:42 +00:00
|
|
|
case TPDWN:
|
2009-08-24 09:17:01 +00:00
|
|
|
return PDWN | SPECIAL;
|
2001-03-11 22:51:05 +00:00
|
|
|
case TPASTE:
|
2009-08-24 09:17:01 +00:00
|
|
|
return PASTE | SPECIAL;
|
1998-01-07 08:43:28 +00:00
|
|
|
case TACC:
|
|
|
|
if (ACC(number) > L_ACC)
|
|
|
|
return -1;
|
2009-08-24 09:17:01 +00:00
|
|
|
return ACC(number) | SPECIAL;
|
1994-08-17 08:59:37 +00:00
|
|
|
case TFUNC:
|
|
|
|
if (F(number) > L_FN)
|
|
|
|
return -1;
|
2009-08-24 09:17:01 +00:00
|
|
|
return F(number) | SPECIAL;
|
1994-08-17 08:59:37 +00:00
|
|
|
case TSCRN:
|
|
|
|
if (S(number) > L_SCR)
|
|
|
|
return -1;
|
2009-08-24 09:17:01 +00:00
|
|
|
return S(number) | SPECIAL;
|
1994-08-17 08:59:37 +00:00
|
|
|
case TLET:
|
|
|
|
return (unsigned char)letter;
|
|
|
|
case TNUM:
|
2009-09-19 17:56:26 +00:00
|
|
|
if (number < 0x000000 || number > 0x10FFFF)
|
1994-08-17 08:59:37 +00:00
|
|
|
return -1;
|
|
|
|
return number;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
1995-05-30 03:57:47 +00:00
|
|
|
|
2001-05-29 13:59:02 +00:00
|
|
|
static int
|
2016-03-16 04:05:02 +00:00
|
|
|
get_definition_line(FILE *file, keymap_t *keymap, accentmap_t *accentmap)
|
1994-08-17 08:59:37 +00:00
|
|
|
{
|
1998-01-07 08:43:28 +00:00
|
|
|
int c;
|
1994-08-17 08:59:37 +00:00
|
|
|
|
2016-03-16 04:05:02 +00:00
|
|
|
yyin = file;
|
1994-08-17 08:59:37 +00:00
|
|
|
|
1998-01-07 08:43:28 +00:00
|
|
|
if (token < 0)
|
|
|
|
token = yylex();
|
|
|
|
switch (token) {
|
|
|
|
case TNUM:
|
|
|
|
c = get_key_definition_line(keymap);
|
|
|
|
if (c < 0)
|
|
|
|
errx(1, "invalid key definition");
|
|
|
|
if (c > keymap->n_keys)
|
|
|
|
keymap->n_keys = c;
|
|
|
|
break;
|
|
|
|
case TACC:
|
|
|
|
c = get_accent_definition_line(accentmap);
|
|
|
|
if (c < 0)
|
|
|
|
errx(1, "invalid accent key definition");
|
|
|
|
if (c > accentmap->n_accs)
|
|
|
|
accentmap->n_accs = c;
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
/* EOF */
|
1994-08-17 08:59:37 +00:00
|
|
|
return -1;
|
1998-01-07 08:43:28 +00:00
|
|
|
default:
|
|
|
|
errx(1, "illegal definition line");
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2011-12-12 12:33:38 +00:00
|
|
|
static int
|
1998-01-07 08:43:28 +00:00
|
|
|
get_key_definition_line(keymap_t *map)
|
|
|
|
{
|
|
|
|
int i, def, scancode;
|
|
|
|
|
|
|
|
/* check scancode number */
|
1994-08-17 08:59:37 +00:00
|
|
|
if (number < 0 || number >= NUM_KEYS)
|
|
|
|
return -1;
|
|
|
|
scancode = number;
|
|
|
|
|
|
|
|
/* get key definitions */
|
|
|
|
map->key[scancode].spcl = 0;
|
|
|
|
for (i=0; i<NUM_STATES; i++) {
|
|
|
|
if ((def = get_entry()) == -1)
|
|
|
|
return -1;
|
2009-08-24 09:17:01 +00:00
|
|
|
if (def & SPECIAL)
|
1994-08-17 08:59:37 +00:00
|
|
|
map->key[scancode].spcl |= (0x80 >> i);
|
2009-08-24 09:17:01 +00:00
|
|
|
map->key[scancode].map[i] = def & ~SPECIAL;
|
1994-08-17 08:59:37 +00:00
|
|
|
}
|
|
|
|
/* get lock state key def */
|
1998-01-07 08:43:28 +00:00
|
|
|
if ((token = yylex()) != TFLAG)
|
1994-08-17 08:59:37 +00:00
|
|
|
return -1;
|
|
|
|
map->key[scancode].flgs = number;
|
1998-01-07 08:43:28 +00:00
|
|
|
token = yylex();
|
|
|
|
return (scancode + 1);
|
1994-08-17 08:59:37 +00:00
|
|
|
}
|
|
|
|
|
2011-12-12 12:33:38 +00:00
|
|
|
static int
|
1998-01-07 08:43:28 +00:00
|
|
|
get_accent_definition_line(accentmap_t *map)
|
|
|
|
{
|
|
|
|
int accent;
|
|
|
|
int c1, c2;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (ACC(number) < F_ACC || ACC(number) > L_ACC)
|
|
|
|
/* number out of range */
|
|
|
|
return -1;
|
|
|
|
accent = number;
|
|
|
|
if (map->acc[accent].accchar != 0) {
|
|
|
|
/* this entry has already been defined before! */
|
|
|
|
errx(1, "duplicated accent key definition");
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ((token = yylex())) {
|
|
|
|
case TLET:
|
|
|
|
map->acc[accent].accchar = letter;
|
|
|
|
break;
|
|
|
|
case TNUM:
|
|
|
|
map->acc[accent].accchar = number;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; (token = yylex()) == '(';) {
|
|
|
|
switch ((token = yylex())) {
|
|
|
|
case TLET:
|
|
|
|
c1 = letter;
|
|
|
|
break;
|
|
|
|
case TNUM:
|
|
|
|
c1 = number;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
switch ((token = yylex())) {
|
|
|
|
case TLET:
|
|
|
|
c2 = letter;
|
|
|
|
break;
|
|
|
|
case TNUM:
|
|
|
|
c2 = number;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if ((token = yylex()) != ')')
|
|
|
|
return -1;
|
|
|
|
if (i >= NUM_ACCENTCHARS) {
|
|
|
|
warnx("too many accented characters, ignored");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
map->acc[accent].map[i][0] = c1;
|
|
|
|
map->acc[accent].map[i][1] = c2;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
return (accent + 1);
|
|
|
|
}
|
1994-08-17 08:59:37 +00:00
|
|
|
|
2011-12-12 12:33:38 +00:00
|
|
|
static void
|
1994-08-17 08:59:37 +00:00
|
|
|
print_entry(FILE *fp, int value)
|
|
|
|
{
|
2009-08-24 09:17:01 +00:00
|
|
|
int val = value & ~SPECIAL;
|
1994-08-17 08:59:37 +00:00
|
|
|
|
|
|
|
switch (value) {
|
2009-08-24 09:17:01 +00:00
|
|
|
case NOP | SPECIAL:
|
1995-05-30 03:57:47 +00:00
|
|
|
fprintf(fp, " nop ");
|
1994-08-17 08:59:37 +00:00
|
|
|
break;
|
2009-08-24 09:17:01 +00:00
|
|
|
case LSH | SPECIAL:
|
1994-08-17 08:59:37 +00:00
|
|
|
fprintf(fp, " lshift");
|
|
|
|
break;
|
2009-08-24 09:17:01 +00:00
|
|
|
case RSH | SPECIAL:
|
1994-08-17 08:59:37 +00:00
|
|
|
fprintf(fp, " rshift");
|
|
|
|
break;
|
2009-08-24 09:17:01 +00:00
|
|
|
case CLK | SPECIAL:
|
1994-08-17 08:59:37 +00:00
|
|
|
fprintf(fp, " clock ");
|
|
|
|
break;
|
2009-08-24 09:17:01 +00:00
|
|
|
case NLK | SPECIAL:
|
1994-08-17 08:59:37 +00:00
|
|
|
fprintf(fp, " nlock ");
|
|
|
|
break;
|
2009-08-24 09:17:01 +00:00
|
|
|
case SLK | SPECIAL:
|
1994-08-17 08:59:37 +00:00
|
|
|
fprintf(fp, " slock ");
|
|
|
|
break;
|
2009-08-24 09:17:01 +00:00
|
|
|
case BTAB | SPECIAL:
|
1994-08-17 08:59:37 +00:00
|
|
|
fprintf(fp, " btab ");
|
|
|
|
break;
|
2009-08-24 09:17:01 +00:00
|
|
|
case LALT | SPECIAL:
|
1994-08-17 08:59:37 +00:00
|
|
|
fprintf(fp, " lalt ");
|
|
|
|
break;
|
2009-08-24 09:17:01 +00:00
|
|
|
case LCTR | SPECIAL:
|
1994-08-17 08:59:37 +00:00
|
|
|
fprintf(fp, " lctrl ");
|
|
|
|
break;
|
2009-08-24 09:17:01 +00:00
|
|
|
case NEXT | SPECIAL:
|
1994-08-17 08:59:37 +00:00
|
|
|
fprintf(fp, " nscr ");
|
|
|
|
break;
|
2009-08-24 09:17:01 +00:00
|
|
|
case PREV | SPECIAL:
|
1999-06-22 14:15:46 +00:00
|
|
|
fprintf(fp, " pscr ");
|
|
|
|
break;
|
2009-08-24 09:17:01 +00:00
|
|
|
case RCTR | SPECIAL:
|
1994-08-17 08:59:37 +00:00
|
|
|
fprintf(fp, " rctrl ");
|
|
|
|
break;
|
2009-08-24 09:17:01 +00:00
|
|
|
case RALT | SPECIAL:
|
1994-08-17 08:59:37 +00:00
|
|
|
fprintf(fp, " ralt ");
|
|
|
|
break;
|
2009-08-24 09:17:01 +00:00
|
|
|
case ALK | SPECIAL:
|
1994-08-17 08:59:37 +00:00
|
|
|
fprintf(fp, " alock ");
|
|
|
|
break;
|
2009-08-24 09:17:01 +00:00
|
|
|
case ASH | SPECIAL:
|
1994-08-17 08:59:37 +00:00
|
|
|
fprintf(fp, " ashift");
|
|
|
|
break;
|
2009-08-24 09:17:01 +00:00
|
|
|
case META | SPECIAL:
|
1994-08-17 08:59:37 +00:00
|
|
|
fprintf(fp, " meta ");
|
|
|
|
break;
|
2009-08-24 09:17:01 +00:00
|
|
|
case RBT | SPECIAL:
|
1994-08-17 08:59:37 +00:00
|
|
|
fprintf(fp, " boot ");
|
|
|
|
break;
|
2009-08-24 09:17:01 +00:00
|
|
|
case DBG | SPECIAL:
|
1994-08-17 08:59:37 +00:00
|
|
|
fprintf(fp, " debug ");
|
|
|
|
break;
|
2009-08-24 09:17:01 +00:00
|
|
|
case SUSP | SPECIAL:
|
1998-01-07 08:43:28 +00:00
|
|
|
fprintf(fp, " susp ");
|
|
|
|
break;
|
2009-08-24 09:17:01 +00:00
|
|
|
case SPSC | SPECIAL:
|
1998-08-03 11:33:22 +00:00
|
|
|
fprintf(fp, " saver ");
|
|
|
|
break;
|
2009-08-24 09:17:01 +00:00
|
|
|
case PNC | SPECIAL:
|
1999-12-10 04:24:27 +00:00
|
|
|
fprintf(fp, " panic ");
|
|
|
|
break;
|
2009-08-24 09:17:01 +00:00
|
|
|
case LSHA | SPECIAL:
|
1999-12-10 04:24:27 +00:00
|
|
|
fprintf(fp, " lshifta");
|
|
|
|
break;
|
2009-08-24 09:17:01 +00:00
|
|
|
case RSHA | SPECIAL:
|
1999-12-10 04:24:27 +00:00
|
|
|
fprintf(fp, " rshifta");
|
|
|
|
break;
|
2009-08-24 09:17:01 +00:00
|
|
|
case LCTRA | SPECIAL:
|
1999-12-10 04:24:27 +00:00
|
|
|
fprintf(fp, " lctrla");
|
|
|
|
break;
|
2009-08-24 09:17:01 +00:00
|
|
|
case RCTRA | SPECIAL:
|
1999-12-10 04:24:27 +00:00
|
|
|
fprintf(fp, " rctrla");
|
|
|
|
break;
|
2009-08-24 09:17:01 +00:00
|
|
|
case LALTA | SPECIAL:
|
1999-12-10 04:24:27 +00:00
|
|
|
fprintf(fp, " lalta ");
|
|
|
|
break;
|
2009-08-24 09:17:01 +00:00
|
|
|
case RALTA | SPECIAL:
|
1999-12-10 04:24:27 +00:00
|
|
|
fprintf(fp, " ralta ");
|
|
|
|
break;
|
2009-08-24 09:17:01 +00:00
|
|
|
case HALT | SPECIAL:
|
2000-09-11 20:37:42 +00:00
|
|
|
fprintf(fp, " halt ");
|
|
|
|
break;
|
2009-08-24 09:17:01 +00:00
|
|
|
case PDWN | SPECIAL:
|
2000-09-11 20:37:42 +00:00
|
|
|
fprintf(fp, " pdwn ");
|
|
|
|
break;
|
2009-08-24 09:17:01 +00:00
|
|
|
case PASTE | SPECIAL:
|
2001-03-11 22:51:05 +00:00
|
|
|
fprintf(fp, " paste ");
|
|
|
|
break;
|
1994-08-17 08:59:37 +00:00
|
|
|
default:
|
2009-08-24 09:17:01 +00:00
|
|
|
if (value & SPECIAL) {
|
1995-05-30 03:57:47 +00:00
|
|
|
if (val >= F_FN && val <= L_FN)
|
1994-08-17 08:59:37 +00:00
|
|
|
fprintf(fp, " fkey%02d", val - F_FN + 1);
|
1995-05-30 03:57:47 +00:00
|
|
|
else if (val >= F_SCR && val <= L_SCR)
|
1994-08-17 08:59:37 +00:00
|
|
|
fprintf(fp, " scr%02d ", val - F_SCR + 1);
|
1998-01-07 08:43:28 +00:00
|
|
|
else if (val >= F_ACC && val <= L_ACC)
|
|
|
|
fprintf(fp, " %-6s", acc_names[val - F_ACC]);
|
1994-08-17 08:59:37 +00:00
|
|
|
else if (hex)
|
1995-05-30 03:57:47 +00:00
|
|
|
fprintf(fp, " 0x%02x ", val);
|
1994-08-17 08:59:37 +00:00
|
|
|
else
|
1998-01-07 08:43:28 +00:00
|
|
|
fprintf(fp, " %3d ", val);
|
1994-08-17 08:59:37 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (val < ' ')
|
1995-05-30 03:57:47 +00:00
|
|
|
fprintf(fp, " %s ", ctrl_names[val]);
|
1994-08-17 08:59:37 +00:00
|
|
|
else if (val == 127)
|
1995-05-30 03:57:47 +00:00
|
|
|
fprintf(fp, " del ");
|
1995-06-11 19:33:05 +00:00
|
|
|
else if (isascii(val) && isprint(val))
|
1995-05-30 03:57:47 +00:00
|
|
|
fprintf(fp, " '%c' ", val);
|
1994-08-17 08:59:37 +00:00
|
|
|
else if (hex)
|
1995-05-30 03:57:47 +00:00
|
|
|
fprintf(fp, " 0x%02x ", val);
|
1994-08-17 08:59:37 +00:00
|
|
|
else
|
1995-05-30 03:57:47 +00:00
|
|
|
fprintf(fp, " %3d ", val);
|
1994-08-17 08:59:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-12 12:33:38 +00:00
|
|
|
static void
|
1999-01-11 03:20:32 +00:00
|
|
|
print_key_definition_line(FILE *fp, int scancode, struct keyent_t *key)
|
1994-08-17 08:59:37 +00:00
|
|
|
{
|
1997-09-19 06:28:57 +00:00
|
|
|
int i;
|
1994-08-17 08:59:37 +00:00
|
|
|
|
|
|
|
/* print scancode number */
|
|
|
|
if (hex)
|
|
|
|
fprintf(fp, " 0x%02x ", scancode);
|
|
|
|
else
|
|
|
|
fprintf(fp, " %03d ", scancode);
|
|
|
|
|
|
|
|
/* print key definitions */
|
|
|
|
for (i=0; i<NUM_STATES; i++) {
|
|
|
|
if (key->spcl & (0x80 >> i))
|
2009-08-24 09:17:01 +00:00
|
|
|
print_entry(fp, key->map[i] | SPECIAL);
|
1994-08-17 08:59:37 +00:00
|
|
|
else
|
1995-05-30 03:57:47 +00:00
|
|
|
print_entry(fp, key->map[i]);
|
1994-08-17 08:59:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* print lock state key def */
|
|
|
|
switch (key->flgs) {
|
|
|
|
case 0:
|
|
|
|
fprintf(fp, " O\n");
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
fprintf(fp, " C\n");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
fprintf(fp, " N\n");
|
|
|
|
break;
|
1995-01-30 21:41:14 +00:00
|
|
|
case 3:
|
|
|
|
fprintf(fp, " B\n");
|
|
|
|
break;
|
1995-05-30 03:57:47 +00:00
|
|
|
}
|
1994-08-17 08:59:37 +00:00
|
|
|
}
|
|
|
|
|
2011-12-12 12:33:38 +00:00
|
|
|
static void
|
1998-01-07 08:43:28 +00:00
|
|
|
print_accent_definition_line(FILE *fp, int accent, struct acc_t *key)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (key->accchar == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* print accent number */
|
|
|
|
fprintf(fp, " %-6s", acc_names[accent]);
|
|
|
|
if (isascii(key->accchar) && isprint(key->accchar))
|
|
|
|
fprintf(fp, "'%c' ", key->accchar);
|
|
|
|
else if (hex)
|
|
|
|
fprintf(fp, "0x%02x ", key->accchar);
|
|
|
|
else
|
|
|
|
fprintf(fp, "%03d ", key->accchar);
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_ACCENTCHARS; ++i) {
|
|
|
|
c = key->map[i][0];
|
|
|
|
if (c == 0)
|
|
|
|
break;
|
|
|
|
if ((i > 0) && ((i % 4) == 0))
|
|
|
|
fprintf(fp, "\n ");
|
|
|
|
if (isascii(c) && isprint(c))
|
|
|
|
fprintf(fp, "( '%c' ", c);
|
|
|
|
else if (hex)
|
|
|
|
fprintf(fp, "(0x%02x ", c);
|
|
|
|
else
|
|
|
|
fprintf(fp, "( %03d ", c);
|
|
|
|
c = key->map[i][1];
|
|
|
|
if (isascii(c) && isprint(c))
|
|
|
|
fprintf(fp, "'%c' ) ", c);
|
|
|
|
else if (hex)
|
|
|
|
fprintf(fp, "0x%02x) ", c);
|
|
|
|
else
|
|
|
|
fprintf(fp, "%03d ) ", c);
|
|
|
|
}
|
|
|
|
fprintf(fp, "\n");
|
|
|
|
}
|
|
|
|
|
2011-12-12 12:33:38 +00:00
|
|
|
static void
|
1998-01-07 08:43:28 +00:00
|
|
|
dump_entry(int value)
|
|
|
|
{
|
2009-08-24 09:17:01 +00:00
|
|
|
if (value & SPECIAL) {
|
|
|
|
value &= ~SPECIAL;
|
1998-01-07 08:43:28 +00:00
|
|
|
switch (value) {
|
|
|
|
case NOP:
|
|
|
|
printf(" NOP, ");
|
|
|
|
break;
|
|
|
|
case LSH:
|
|
|
|
printf(" LSH, ");
|
|
|
|
break;
|
|
|
|
case RSH:
|
|
|
|
printf(" RSH, ");
|
|
|
|
break;
|
|
|
|
case CLK:
|
|
|
|
printf(" CLK, ");
|
|
|
|
break;
|
|
|
|
case NLK:
|
|
|
|
printf(" NLK, ");
|
|
|
|
break;
|
|
|
|
case SLK:
|
|
|
|
printf(" SLK, ");
|
|
|
|
break;
|
|
|
|
case BTAB:
|
|
|
|
printf(" BTAB, ");
|
|
|
|
break;
|
|
|
|
case LALT:
|
|
|
|
printf(" LALT, ");
|
|
|
|
break;
|
|
|
|
case LCTR:
|
|
|
|
printf(" LCTR, ");
|
|
|
|
break;
|
|
|
|
case NEXT:
|
|
|
|
printf(" NEXT, ");
|
|
|
|
break;
|
1999-06-22 14:15:46 +00:00
|
|
|
case PREV:
|
|
|
|
printf(" PREV, ");
|
|
|
|
break;
|
1998-01-07 08:43:28 +00:00
|
|
|
case RCTR:
|
|
|
|
printf(" RCTR, ");
|
|
|
|
break;
|
|
|
|
case RALT:
|
|
|
|
printf(" RALT, ");
|
|
|
|
break;
|
|
|
|
case ALK:
|
|
|
|
printf(" ALK, ");
|
|
|
|
break;
|
|
|
|
case ASH:
|
|
|
|
printf(" ASH, ");
|
|
|
|
break;
|
|
|
|
case META:
|
|
|
|
printf(" META, ");
|
|
|
|
break;
|
|
|
|
case RBT:
|
|
|
|
printf(" RBT, ");
|
|
|
|
break;
|
|
|
|
case DBG:
|
|
|
|
printf(" DBG, ");
|
|
|
|
break;
|
|
|
|
case SUSP:
|
|
|
|
printf(" SUSP, ");
|
|
|
|
break;
|
1998-08-03 11:33:22 +00:00
|
|
|
case SPSC:
|
|
|
|
printf(" SPSC, ");
|
|
|
|
break;
|
1999-12-10 04:24:27 +00:00
|
|
|
case PNC:
|
|
|
|
printf(" PNC, ");
|
|
|
|
break;
|
|
|
|
case LSHA:
|
|
|
|
printf(" LSHA, ");
|
|
|
|
break;
|
|
|
|
case RSHA:
|
|
|
|
printf(" RSHA, ");
|
|
|
|
break;
|
|
|
|
case LCTRA:
|
|
|
|
printf("LCTRA, ");
|
|
|
|
break;
|
|
|
|
case RCTRA:
|
|
|
|
printf("RCTRA, ");
|
|
|
|
break;
|
|
|
|
case LALTA:
|
|
|
|
printf("LALTA, ");
|
|
|
|
break;
|
|
|
|
case RALTA:
|
|
|
|
printf("RALTA, ");
|
|
|
|
break;
|
2000-09-11 20:37:42 +00:00
|
|
|
case HALT:
|
|
|
|
printf(" HALT, ");
|
|
|
|
break;
|
|
|
|
case PDWN:
|
|
|
|
printf(" PDWN, ");
|
|
|
|
break;
|
2001-03-11 22:51:05 +00:00
|
|
|
case PASTE:
|
|
|
|
printf("PASTE, ");
|
|
|
|
break;
|
1998-01-07 08:43:28 +00:00
|
|
|
default:
|
|
|
|
if (value >= F_FN && value <= L_FN)
|
|
|
|
printf(" F(%2d),", value - F_FN + 1);
|
|
|
|
else if (value >= F_SCR && value <= L_SCR)
|
1998-01-12 23:53:26 +00:00
|
|
|
printf(" S(%2d),", value - F_SCR + 1);
|
1998-01-07 08:43:28 +00:00
|
|
|
else if (value >= F_ACC && value <= L_ACC)
|
|
|
|
printf(" %-4s, ", acc_names_u[value - F_ACC]);
|
|
|
|
else
|
|
|
|
printf(" 0x%02X, ", value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (value == '\'') {
|
|
|
|
printf(" '\\'', ");
|
|
|
|
} else if (value == '\\') {
|
|
|
|
printf(" '\\\\', ");
|
|
|
|
} else if (isascii(value) && isprint(value)) {
|
|
|
|
printf(" '%c', ", value);
|
|
|
|
} else {
|
|
|
|
printf(" 0x%02X, ", value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-12 12:33:38 +00:00
|
|
|
static void
|
1998-01-07 08:43:28 +00:00
|
|
|
dump_key_definition(char *name, keymap_t *keymap)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
1998-01-12 23:53:26 +00:00
|
|
|
printf("static keymap_t keymap_%s = { 0x%02x, {\n",
|
1998-01-07 08:43:28 +00:00
|
|
|
name, (unsigned)keymap->n_keys);
|
|
|
|
printf(
|
1998-01-12 23:53:26 +00:00
|
|
|
"/* alt\n"
|
|
|
|
" * scan cntrl alt alt cntrl\n"
|
|
|
|
" * code base shift cntrl shift alt shift cntrl shift spcl flgs\n"
|
1998-01-07 08:43:28 +00:00
|
|
|
" * ---------------------------------------------------------------------------\n"
|
|
|
|
" */\n");
|
|
|
|
for (i = 0; i < keymap->n_keys; i++) {
|
1998-01-12 23:53:26 +00:00
|
|
|
printf("/*%02x*/{{", i);
|
1998-01-07 08:43:28 +00:00
|
|
|
for (j = 0; j < NUM_STATES; j++) {
|
|
|
|
if (keymap->key[i].spcl & (0x80 >> j))
|
2009-08-24 09:17:01 +00:00
|
|
|
dump_entry(keymap->key[i].map[j] | SPECIAL);
|
1998-01-07 08:43:28 +00:00
|
|
|
else
|
|
|
|
dump_entry(keymap->key[i].map[j]);
|
|
|
|
}
|
1998-01-12 23:53:26 +00:00
|
|
|
printf("}, 0x%02X,0x%02X },\n",
|
1998-01-07 08:43:28 +00:00
|
|
|
(unsigned)keymap->key[i].spcl,
|
|
|
|
(unsigned)keymap->key[i].flgs);
|
|
|
|
}
|
1998-01-12 23:53:26 +00:00
|
|
|
printf("} };\n\n");
|
1998-01-07 08:43:28 +00:00
|
|
|
}
|
|
|
|
|
2011-12-12 12:33:38 +00:00
|
|
|
static void
|
1998-01-07 08:43:28 +00:00
|
|
|
dump_accent_definition(char *name, accentmap_t *accentmap)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
int c;
|
|
|
|
|
1998-01-12 23:53:26 +00:00
|
|
|
printf("static accentmap_t accentmap_%s = { %d",
|
1998-01-07 08:43:28 +00:00
|
|
|
name, accentmap->n_accs);
|
1998-01-12 23:53:26 +00:00
|
|
|
if (accentmap->n_accs <= 0) {
|
|
|
|
printf(" };\n\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf(", {\n");
|
1998-01-07 08:43:28 +00:00
|
|
|
for (i = 0; i < NUM_DEADKEYS; i++) {
|
|
|
|
printf(" /* %s=%d */\n {", acc_names[i], i);
|
|
|
|
c = accentmap->acc[i].accchar;
|
|
|
|
if (c == '\'')
|
|
|
|
printf(" '\\'', {");
|
|
|
|
else if (c == '\\')
|
|
|
|
printf(" '\\\\', {");
|
|
|
|
else if (isascii(c) && isprint(c))
|
|
|
|
printf(" '%c', {", c);
|
|
|
|
else if (c == 0) {
|
|
|
|
printf(" 0x00 }, \n");
|
|
|
|
continue;
|
|
|
|
} else
|
|
|
|
printf(" 0x%02x, {", c);
|
|
|
|
for (j = 0; j < NUM_ACCENTCHARS; j++) {
|
|
|
|
c = accentmap->acc[i].map[j][0];
|
|
|
|
if (c == 0)
|
|
|
|
break;
|
|
|
|
if ((j > 0) && ((j % 4) == 0))
|
|
|
|
printf("\n\t ");
|
|
|
|
if (isascii(c) && isprint(c))
|
|
|
|
printf(" { '%c',", c);
|
|
|
|
else
|
|
|
|
printf(" { 0x%02x,", c);
|
|
|
|
printf("0x%02x },", accentmap->acc[i].map[j][1]);
|
|
|
|
}
|
|
|
|
printf(" }, },\n");
|
|
|
|
}
|
1998-01-12 23:53:26 +00:00
|
|
|
printf("} };\n\n");
|
1998-01-07 08:43:28 +00:00
|
|
|
}
|
1994-08-17 08:59:37 +00:00
|
|
|
|
2016-03-16 04:05:02 +00:00
|
|
|
static void
|
|
|
|
add_keymap_path(const char *path)
|
|
|
|
{
|
|
|
|
struct pathent* pe;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
len = strlen(path);
|
|
|
|
if ((pe = malloc(sizeof(*pe))) == NULL ||
|
|
|
|
(pe->path = malloc(len + 2)) == NULL)
|
|
|
|
err(1, "malloc");
|
|
|
|
memcpy(pe->path, path, len);
|
|
|
|
if (len > 0 && path[len - 1] != '/')
|
|
|
|
pe->path[len++] = '/';
|
|
|
|
pe->path[len] = '\0';
|
|
|
|
STAILQ_INSERT_TAIL(&pathlist, pe, next);
|
|
|
|
}
|
|
|
|
|
2011-12-12 12:33:38 +00:00
|
|
|
static void
|
1996-11-09 16:16:19 +00:00
|
|
|
load_keymap(char *opt, int dumponly)
|
1994-08-17 08:59:37 +00:00
|
|
|
{
|
1998-01-07 08:43:28 +00:00
|
|
|
keymap_t keymap;
|
|
|
|
accentmap_t accentmap;
|
2016-03-16 04:05:02 +00:00
|
|
|
struct pathent *pe;
|
|
|
|
FILE *file;
|
|
|
|
int j;
|
1996-11-09 16:16:19 +00:00
|
|
|
char *name, *cp;
|
2014-05-29 14:39:25 +00:00
|
|
|
char blank[] = "", keymap_path[] = KEYMAP_PATH;
|
|
|
|
char vt_keymap_path[] = VT_KEYMAP_PATH, dotkbd[] = ".kbd";
|
2002-07-11 21:12:18 +00:00
|
|
|
char *postfix[] = {blank, dotkbd, NULL};
|
1994-08-17 08:59:37 +00:00
|
|
|
|
2016-03-16 04:05:02 +00:00
|
|
|
if (!paths_configured) {
|
|
|
|
cp = getenv("KEYMAP_PATH");
|
|
|
|
if (cp != NULL)
|
|
|
|
add_keymap_path(cp);
|
|
|
|
add_keymap_path("");
|
|
|
|
if (is_vt4())
|
|
|
|
add_keymap_path(vt_keymap_path);
|
|
|
|
else
|
|
|
|
add_keymap_path(keymap_path);
|
|
|
|
paths_configured = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
file = NULL;
|
|
|
|
STAILQ_FOREACH(pe, &pathlist, next) {
|
|
|
|
for (j=0; postfix[j] && file == NULL; j++) {
|
|
|
|
name = mkfullname(pe->path, opt, postfix[j]);
|
|
|
|
file = fopen(name, "r");
|
|
|
|
if (file != NULL)
|
|
|
|
break;
|
2001-05-12 09:16:09 +00:00
|
|
|
}
|
2001-05-15 22:53:05 +00:00
|
|
|
}
|
2016-03-16 04:05:02 +00:00
|
|
|
if (file == NULL) {
|
2001-07-13 16:30:11 +00:00
|
|
|
warn("keymap file \"%s\" not found", opt);
|
1994-08-17 08:59:37 +00:00
|
|
|
return;
|
|
|
|
}
|
1998-01-07 08:43:28 +00:00
|
|
|
memset(&keymap, 0, sizeof(keymap));
|
|
|
|
memset(&accentmap, 0, sizeof(accentmap));
|
|
|
|
token = -1;
|
1994-08-17 08:59:37 +00:00
|
|
|
while (1) {
|
2016-03-16 04:05:02 +00:00
|
|
|
if (get_definition_line(file, &keymap, &accentmap) < 0)
|
1994-08-17 08:59:37 +00:00
|
|
|
break;
|
|
|
|
}
|
1996-11-09 16:16:19 +00:00
|
|
|
if (dumponly) {
|
|
|
|
/* fix up the filename to make it a valid C identifier */
|
|
|
|
for (cp = opt; *cp; cp++)
|
|
|
|
if (!isalpha(*cp) && !isdigit(*cp)) *cp = '_';
|
1998-01-07 08:43:28 +00:00
|
|
|
printf("/*\n"
|
|
|
|
" * Automatically generated from %s.\n"
|
|
|
|
" * DO NOT EDIT!\n"
|
|
|
|
" */\n", name);
|
|
|
|
dump_key_definition(opt, &keymap);
|
|
|
|
dump_accent_definition(opt, &accentmap);
|
1996-11-09 16:16:19 +00:00
|
|
|
return;
|
|
|
|
}
|
1998-01-07 08:43:28 +00:00
|
|
|
if ((keymap.n_keys > 0) && (ioctl(0, PIO_KEYMAP, &keymap) < 0)) {
|
1997-09-19 06:28:57 +00:00
|
|
|
warn("setting keymap");
|
2016-03-16 04:05:02 +00:00
|
|
|
fclose(file);
|
1994-08-17 08:59:37 +00:00
|
|
|
return;
|
|
|
|
}
|
1998-01-07 08:43:28 +00:00
|
|
|
if ((accentmap.n_accs > 0)
|
|
|
|
&& (ioctl(0, PIO_DEADKEYMAP, &accentmap) < 0)) {
|
|
|
|
warn("setting accentmap");
|
2016-03-16 04:05:02 +00:00
|
|
|
fclose(file);
|
1998-01-07 08:43:28 +00:00
|
|
|
return;
|
|
|
|
}
|
1994-08-17 08:59:37 +00:00
|
|
|
}
|
|
|
|
|
2011-12-12 12:33:38 +00:00
|
|
|
static void
|
2002-07-11 21:12:18 +00:00
|
|
|
print_keymap(void)
|
1994-08-17 08:59:37 +00:00
|
|
|
{
|
1998-01-07 08:43:28 +00:00
|
|
|
keymap_t keymap;
|
|
|
|
accentmap_t accentmap;
|
1994-08-17 08:59:37 +00:00
|
|
|
int i;
|
|
|
|
|
1998-01-07 08:43:28 +00:00
|
|
|
if (ioctl(0, GIO_KEYMAP, &keymap) < 0)
|
1997-09-19 06:28:57 +00:00
|
|
|
err(1, "getting keymap");
|
1998-01-07 08:43:28 +00:00
|
|
|
if (ioctl(0, GIO_DEADKEYMAP, &accentmap) < 0)
|
|
|
|
memset(&accentmap, 0, sizeof(accentmap));
|
1994-08-17 08:59:37 +00:00
|
|
|
printf(
|
|
|
|
"# alt\n"
|
|
|
|
"# scan cntrl alt alt cntrl lock\n"
|
|
|
|
"# code base shift cntrl shift alt shift cntrl shift state\n"
|
|
|
|
"# ------------------------------------------------------------------\n"
|
|
|
|
);
|
1998-01-07 08:43:28 +00:00
|
|
|
for (i=0; i<keymap.n_keys; i++)
|
|
|
|
print_key_definition_line(stdout, i, &keymap.key[i]);
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
for (i = 0; i < NUM_DEADKEYS; i++)
|
|
|
|
print_accent_definition_line(stdout, i, &accentmap.acc[i]);
|
|
|
|
|
1994-08-17 08:59:37 +00:00
|
|
|
}
|
|
|
|
|
2011-12-12 12:33:38 +00:00
|
|
|
static void
|
2002-07-11 21:12:18 +00:00
|
|
|
load_default_functionkeys(void)
|
1994-08-17 08:59:37 +00:00
|
|
|
{
|
|
|
|
fkeyarg_t fkey;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<NUM_FKEYS; i++) {
|
|
|
|
fkey.keynum = i;
|
|
|
|
strcpy(fkey.keydef, fkey_table[i]);
|
|
|
|
fkey.flen = strlen(fkey_table[i]);
|
|
|
|
if (ioctl(0, SETFKEY, &fkey) < 0)
|
1997-09-19 06:28:57 +00:00
|
|
|
warn("setting function key");
|
1994-08-17 08:59:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-12 12:33:38 +00:00
|
|
|
static void
|
1994-08-17 08:59:37 +00:00
|
|
|
set_functionkey(char *keynumstr, char *string)
|
|
|
|
{
|
|
|
|
fkeyarg_t fkey;
|
|
|
|
|
|
|
|
if (!strcmp(keynumstr, "load") && !strcmp(string, "default")) {
|
|
|
|
load_default_functionkeys();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fkey.keynum = atoi(keynumstr);
|
|
|
|
if (fkey.keynum < 1 || fkey.keynum > NUM_FKEYS) {
|
1997-09-19 06:28:57 +00:00
|
|
|
warnx("function key number must be between 1 and %d",
|
1994-08-17 08:59:37 +00:00
|
|
|
NUM_FKEYS);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((fkey.flen = strlen(string)) > MAXFK) {
|
1997-09-19 06:28:57 +00:00
|
|
|
warnx("function key string too long (%d > %d)",
|
1994-08-17 08:59:37 +00:00
|
|
|
fkey.flen, MAXFK);
|
|
|
|
return;
|
|
|
|
}
|
2004-08-09 04:27:58 +00:00
|
|
|
strncpy(fkey.keydef, string, MAXFK);
|
1994-08-17 08:59:37 +00:00
|
|
|
fkey.keynum -= 1;
|
|
|
|
if (ioctl(0, SETFKEY, &fkey) < 0)
|
1997-09-19 06:28:57 +00:00
|
|
|
warn("setting function key");
|
1994-08-17 08:59:37 +00:00
|
|
|
}
|
|
|
|
|
2011-12-12 12:33:38 +00:00
|
|
|
static void
|
1994-08-17 08:59:37 +00:00
|
|
|
set_bell_values(char *opt)
|
|
|
|
{
|
1995-01-12 11:47:05 +00:00
|
|
|
int bell, duration, pitch;
|
1994-08-17 08:59:37 +00:00
|
|
|
|
1998-08-03 09:12:39 +00:00
|
|
|
bell = 0;
|
2019-01-23 10:05:27 +00:00
|
|
|
duration = 0;
|
|
|
|
pitch = 0;
|
1998-08-03 09:12:39 +00:00
|
|
|
if (!strncmp(opt, "quiet.", 6)) {
|
2006-11-16 12:27:51 +00:00
|
|
|
bell = CONS_QUIET_BELL;
|
1998-08-03 09:12:39 +00:00
|
|
|
opt += 6;
|
|
|
|
}
|
1995-05-30 03:57:47 +00:00
|
|
|
if (!strcmp(opt, "visual"))
|
2006-11-16 12:27:51 +00:00
|
|
|
bell |= CONS_VISUAL_BELL;
|
1995-01-12 11:47:05 +00:00
|
|
|
else if (!strcmp(opt, "normal"))
|
1998-08-03 09:12:39 +00:00
|
|
|
duration = 5, pitch = 800;
|
1999-07-22 14:19:14 +00:00
|
|
|
else if (!strcmp(opt, "off"))
|
|
|
|
duration = 0, pitch = 0;
|
1994-08-17 08:59:37 +00:00
|
|
|
else {
|
|
|
|
char *v1;
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-01-12 11:47:05 +00:00
|
|
|
bell = 0;
|
1994-08-17 08:59:37 +00:00
|
|
|
duration = strtol(opt, &v1, 0);
|
|
|
|
if ((duration < 0) || (*v1 != '.'))
|
|
|
|
goto badopt;
|
|
|
|
opt = ++v1;
|
|
|
|
pitch = strtol(opt, &v1, 0);
|
|
|
|
if ((pitch < 0) || (*opt == '\0') || (*v1 != '\0')) {
|
|
|
|
badopt:
|
2001-05-29 13:59:02 +00:00
|
|
|
warnx("argument to -b must be duration.pitch or [quiet.]visual|normal|off");
|
1994-08-17 08:59:37 +00:00
|
|
|
return;
|
|
|
|
}
|
1998-08-03 09:12:39 +00:00
|
|
|
if (pitch != 0)
|
|
|
|
pitch = 1193182 / pitch; /* in Hz */
|
|
|
|
duration /= 10; /* in 10 m sec */
|
1994-08-17 08:59:37 +00:00
|
|
|
}
|
|
|
|
|
1995-01-12 11:47:05 +00:00
|
|
|
ioctl(0, CONS_BELLTYPE, &bell);
|
2019-01-23 10:05:27 +00:00
|
|
|
if (duration > 0 && pitch > 0)
|
|
|
|
fprintf(stderr, "\e[=%d;%dB", pitch, duration);
|
1994-08-17 08:59:37 +00:00
|
|
|
}
|
|
|
|
|
2011-12-12 12:33:38 +00:00
|
|
|
static void
|
1994-08-17 08:59:37 +00:00
|
|
|
set_keyrates(char *opt)
|
|
|
|
{
|
Keyboard driver update in preparation for the USB keyboard driver.
- Refined internal interface in keyboard drivers so that:
1. the side effect of device probe is kept minimal,
2. polling mode function is added,
3. and new ioctl and configuration options are added (see below).
- Added new ioctl: KDSETREPEAT
Set keyboard typematic rate. There has existed an ioctl command,
KDSETRAD, for the same purpose. However, KDSETRAD is dependent on
the AT keyboard. KDSETREPEAT provides more generic interface.
KDSETRAD will still be supported in the atkbd driver.
- Added new configuration options:
ATKBD_DFLT_KEYMAP
Specify a keymap to be used as the default, built-in keymap.
(There has been undocumented options, DKKEYMAP, UKKEYMAP, GRKEYMAP,
SWKEYMAP, RUKEYMAP, ESKEYMAP, and ISKEYMAP to set the default keymap.
These options are now gone for good. The new option is more general.)
KBD_DISABLE_KEYMAP_LOADING
Don't allow the user to change the keymap.
1999-03-10 10:36:53 +00:00
|
|
|
int arg[2];
|
1998-09-10 12:20:09 +00:00
|
|
|
int repeat;
|
|
|
|
int delay;
|
1999-05-09 04:57:51 +00:00
|
|
|
int r, d;
|
1994-08-17 08:59:37 +00:00
|
|
|
|
1999-05-09 04:57:51 +00:00
|
|
|
if (!strcmp(opt, "slow")) {
|
Keyboard driver update in preparation for the USB keyboard driver.
- Refined internal interface in keyboard drivers so that:
1. the side effect of device probe is kept minimal,
2. polling mode function is added,
3. and new ioctl and configuration options are added (see below).
- Added new ioctl: KDSETREPEAT
Set keyboard typematic rate. There has existed an ioctl command,
KDSETRAD, for the same purpose. However, KDSETRAD is dependent on
the AT keyboard. KDSETREPEAT provides more generic interface.
KDSETRAD will still be supported in the atkbd driver.
- Added new configuration options:
ATKBD_DFLT_KEYMAP
Specify a keymap to be used as the default, built-in keymap.
(There has been undocumented options, DKKEYMAP, UKKEYMAP, GRKEYMAP,
SWKEYMAP, RUKEYMAP, ESKEYMAP, and ISKEYMAP to set the default keymap.
These options are now gone for good. The new option is more general.)
KBD_DISABLE_KEYMAP_LOADING
Don't allow the user to change the keymap.
1999-03-10 10:36:53 +00:00
|
|
|
delay = 1000, repeat = 500;
|
1999-05-09 04:57:51 +00:00
|
|
|
d = 3, r = 31;
|
|
|
|
} else if (!strcmp(opt, "normal")) {
|
Keyboard driver update in preparation for the USB keyboard driver.
- Refined internal interface in keyboard drivers so that:
1. the side effect of device probe is kept minimal,
2. polling mode function is added,
3. and new ioctl and configuration options are added (see below).
- Added new ioctl: KDSETREPEAT
Set keyboard typematic rate. There has existed an ioctl command,
KDSETRAD, for the same purpose. However, KDSETRAD is dependent on
the AT keyboard. KDSETREPEAT provides more generic interface.
KDSETRAD will still be supported in the atkbd driver.
- Added new configuration options:
ATKBD_DFLT_KEYMAP
Specify a keymap to be used as the default, built-in keymap.
(There has been undocumented options, DKKEYMAP, UKKEYMAP, GRKEYMAP,
SWKEYMAP, RUKEYMAP, ESKEYMAP, and ISKEYMAP to set the default keymap.
These options are now gone for good. The new option is more general.)
KBD_DISABLE_KEYMAP_LOADING
Don't allow the user to change the keymap.
1999-03-10 10:36:53 +00:00
|
|
|
delay = 500, repeat = 125;
|
1999-05-09 04:57:51 +00:00
|
|
|
d = 1, r = 15;
|
|
|
|
} else if (!strcmp(opt, "fast")) {
|
1998-09-10 12:20:09 +00:00
|
|
|
delay = repeat = 0;
|
1999-05-09 04:57:51 +00:00
|
|
|
d = r = 0;
|
|
|
|
} else {
|
1994-08-17 08:59:37 +00:00
|
|
|
int n;
|
|
|
|
char *v1;
|
|
|
|
|
|
|
|
delay = strtol(opt, &v1, 0);
|
|
|
|
if ((delay < 0) || (*v1 != '.'))
|
|
|
|
goto badopt;
|
|
|
|
opt = ++v1;
|
|
|
|
repeat = strtol(opt, &v1, 0);
|
|
|
|
if ((repeat < 0) || (*opt == '\0') || (*v1 != '\0')) {
|
|
|
|
badopt:
|
2001-05-29 13:59:02 +00:00
|
|
|
warnx("argument to -r must be delay.repeat or slow|normal|fast");
|
1994-08-17 08:59:37 +00:00
|
|
|
return;
|
|
|
|
}
|
1999-05-09 04:57:51 +00:00
|
|
|
for (n = 0; n < ndelays - 1; n++)
|
|
|
|
if (delay <= delays[n])
|
|
|
|
break;
|
|
|
|
d = n;
|
|
|
|
for (n = 0; n < nrepeats - 1; n++)
|
|
|
|
if (repeat <= repeats[n])
|
|
|
|
break;
|
|
|
|
r = n;
|
1994-08-17 08:59:37 +00:00
|
|
|
}
|
|
|
|
|
Keyboard driver update in preparation for the USB keyboard driver.
- Refined internal interface in keyboard drivers so that:
1. the side effect of device probe is kept minimal,
2. polling mode function is added,
3. and new ioctl and configuration options are added (see below).
- Added new ioctl: KDSETREPEAT
Set keyboard typematic rate. There has existed an ioctl command,
KDSETRAD, for the same purpose. However, KDSETRAD is dependent on
the AT keyboard. KDSETREPEAT provides more generic interface.
KDSETRAD will still be supported in the atkbd driver.
- Added new configuration options:
ATKBD_DFLT_KEYMAP
Specify a keymap to be used as the default, built-in keymap.
(There has been undocumented options, DKKEYMAP, UKKEYMAP, GRKEYMAP,
SWKEYMAP, RUKEYMAP, ESKEYMAP, and ISKEYMAP to set the default keymap.
These options are now gone for good. The new option is more general.)
KBD_DISABLE_KEYMAP_LOADING
Don't allow the user to change the keymap.
1999-03-10 10:36:53 +00:00
|
|
|
arg[0] = delay;
|
|
|
|
arg[1] = repeat;
|
1999-05-09 04:57:51 +00:00
|
|
|
if (ioctl(0, KDSETREPEAT, arg)) {
|
|
|
|
if (ioctl(0, KDSETRAD, (d << 5) | r))
|
|
|
|
warn("setting keyboard rate");
|
|
|
|
}
|
1994-08-17 08:59:37 +00:00
|
|
|
}
|
|
|
|
|
2002-07-11 21:12:18 +00:00
|
|
|
static const char *
|
|
|
|
get_kbd_type_name(int type)
|
1999-01-11 03:20:32 +00:00
|
|
|
{
|
|
|
|
static struct {
|
|
|
|
int type;
|
2002-07-11 21:12:18 +00:00
|
|
|
const char *name;
|
1999-01-11 03:20:32 +00:00
|
|
|
} name_table[] = {
|
|
|
|
{ KB_84, "AT 84" },
|
|
|
|
{ KB_101, "AT 101/102" },
|
|
|
|
{ KB_OTHER, "generic" },
|
|
|
|
};
|
2002-07-11 21:12:18 +00:00
|
|
|
unsigned int i;
|
1999-01-11 03:20:32 +00:00
|
|
|
|
|
|
|
for (i = 0; i < sizeof(name_table)/sizeof(name_table[0]); ++i) {
|
|
|
|
if (type == name_table[i].type)
|
|
|
|
return name_table[i].name;
|
|
|
|
}
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
|
2011-12-12 12:33:38 +00:00
|
|
|
static void
|
1999-01-11 03:20:32 +00:00
|
|
|
show_kbd_info(void)
|
|
|
|
{
|
|
|
|
keyboard_info_t info;
|
|
|
|
|
|
|
|
if (ioctl(0, KDGKBINFO, &info) == -1) {
|
|
|
|
warn("unable to obtain keyboard information");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf("kbd%d:\n", info.kb_index);
|
|
|
|
printf(" %.*s%d, type:%s (%d)\n",
|
2001-05-29 13:59:02 +00:00
|
|
|
(int)sizeof(info.kb_name), info.kb_name, info.kb_unit,
|
1999-01-11 03:20:32 +00:00
|
|
|
get_kbd_type_name(info.kb_type), info.kb_type);
|
|
|
|
}
|
|
|
|
|
2011-12-12 12:33:38 +00:00
|
|
|
static void
|
1999-01-11 03:20:32 +00:00
|
|
|
set_keyboard(char *device)
|
|
|
|
{
|
|
|
|
keyboard_info_t info;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
fd = open(device, O_RDONLY);
|
|
|
|
if (fd < 0) {
|
|
|
|
warn("cannot open %s", device);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (ioctl(fd, KDGKBINFO, &info) == -1) {
|
|
|
|
warn("unable to obtain keyboard information");
|
|
|
|
close(fd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* The keyboard device driver won't release the keyboard by
|
|
|
|
* the following ioctl, but it automatically will, when the device
|
|
|
|
* is closed. So, we don't check error here.
|
|
|
|
*/
|
|
|
|
ioctl(fd, CONS_RELKBD, 0);
|
|
|
|
close(fd);
|
|
|
|
#if 1
|
|
|
|
printf("kbd%d\n", info.kb_index);
|
|
|
|
printf(" %.*s%d, type:%s (%d)\n",
|
2001-05-29 13:59:02 +00:00
|
|
|
(int)sizeof(info.kb_name), info.kb_name, info.kb_unit,
|
1999-01-11 03:20:32 +00:00
|
|
|
get_kbd_type_name(info.kb_type), info.kb_type);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (ioctl(0, CONS_SETKBD, info.kb_index) == -1)
|
|
|
|
warn("unable to set keyboard");
|
|
|
|
}
|
|
|
|
|
2011-12-12 12:33:38 +00:00
|
|
|
static void
|
1999-01-11 03:20:32 +00:00
|
|
|
release_keyboard(void)
|
|
|
|
{
|
|
|
|
keyboard_info_t info;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If stdin is not associated with a keyboard, the following ioctl
|
|
|
|
* will fail.
|
|
|
|
*/
|
|
|
|
if (ioctl(0, KDGKBINFO, &info) == -1) {
|
|
|
|
warn("unable to obtain keyboard information");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#if 1
|
|
|
|
printf("kbd%d\n", info.kb_index);
|
|
|
|
printf(" %.*s%d, type:%s (%d)\n",
|
2001-05-29 13:59:02 +00:00
|
|
|
(int)sizeof(info.kb_name), info.kb_name, info.kb_unit,
|
1999-01-11 03:20:32 +00:00
|
|
|
get_kbd_type_name(info.kb_type), info.kb_type);
|
|
|
|
#endif
|
|
|
|
if (ioctl(0, CONS_RELKBD, 0) == -1)
|
|
|
|
warn("unable to release the keyboard");
|
|
|
|
}
|
|
|
|
|
2011-12-12 12:33:38 +00:00
|
|
|
static void
|
2006-09-15 18:41:12 +00:00
|
|
|
mux_keyboard(u_int op, char *kbd)
|
2005-07-14 22:43:20 +00:00
|
|
|
{
|
|
|
|
keyboard_info_t info;
|
|
|
|
char *unit, *ep;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If stdin is not associated with a keyboard, the following ioctl
|
|
|
|
* will fail.
|
|
|
|
*/
|
|
|
|
if (ioctl(0, KDGKBINFO, &info) == -1) {
|
|
|
|
warn("unable to obtain keyboard information");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#if 1
|
|
|
|
printf("kbd%d\n", info.kb_index);
|
|
|
|
printf(" %.*s%d, type:%s (%d)\n",
|
|
|
|
(int)sizeof(info.kb_name), info.kb_name, info.kb_unit,
|
|
|
|
get_kbd_type_name(info.kb_type), info.kb_type);
|
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* split kbd into name and unit. find the right most part of the
|
|
|
|
* kbd string that consist of only digits.
|
|
|
|
*/
|
|
|
|
|
|
|
|
memset(&info, 0, sizeof(info));
|
|
|
|
|
|
|
|
info.kb_unit = -1;
|
|
|
|
ep = kbd - 1;
|
|
|
|
|
|
|
|
do {
|
|
|
|
unit = strpbrk(ep + 1, "0123456789");
|
|
|
|
if (unit != NULL) {
|
|
|
|
info.kb_unit = strtol(unit, &ep, 10);
|
|
|
|
if (*ep != '\0')
|
|
|
|
info.kb_unit = -1;
|
|
|
|
}
|
|
|
|
} while (unit != NULL && info.kb_unit == -1);
|
|
|
|
|
|
|
|
if (info.kb_unit == -1) {
|
|
|
|
warnx("unable to find keyboard driver unit in '%s'", kbd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unit == kbd) {
|
|
|
|
warnx("unable to find keyboard driver name in '%s'", kbd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (unit - kbd >= (int) sizeof(info.kb_name)) {
|
|
|
|
warnx("keyboard name '%s' is too long", kbd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
strncpy(info.kb_name, kbd, unit - kbd);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If stdin is not associated with a kbdmux(4) keyboard, the following
|
|
|
|
* ioctl will fail.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (ioctl(0, op, &info) == -1)
|
|
|
|
warn("unable to (un)mux the keyboard");
|
|
|
|
}
|
1995-01-30 21:41:14 +00:00
|
|
|
|
2011-12-12 12:33:38 +00:00
|
|
|
static void
|
2010-01-02 11:05:34 +00:00
|
|
|
usage(void)
|
1994-08-17 08:59:37 +00:00
|
|
|
{
|
1997-09-19 06:28:57 +00:00
|
|
|
fprintf(stderr, "%s\n%s\n%s\n",
|
2005-07-14 22:43:20 +00:00
|
|
|
"usage: kbdcontrol [-dFKix] [-A name] [-a name] [-b duration.pitch | [quiet.]belltype]",
|
1997-09-19 06:28:57 +00:00
|
|
|
" [-r delay.repeat | speed] [-l mapfile] [-f # string]",
|
2016-03-16 04:05:02 +00:00
|
|
|
" [-k device] [-L mapfile] [-P path]");
|
1997-09-19 06:28:57 +00:00
|
|
|
exit(1);
|
1994-08-17 08:59:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-15 01:58:44 +00:00
|
|
|
int
|
1994-08-17 08:59:37 +00:00
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2016-03-16 04:05:02 +00:00
|
|
|
const char *optstring = "A:a:b:df:iKk:Fl:L:P:r:x";
|
1994-08-17 08:59:37 +00:00
|
|
|
int opt;
|
|
|
|
|
2016-03-16 04:05:02 +00:00
|
|
|
/* Collect any -P arguments, regardless of where they appear. */
|
2019-06-24 21:05:14 +00:00
|
|
|
while ((opt = getopt(argc, argv, optstring)) != -1) {
|
2016-03-16 04:05:02 +00:00
|
|
|
if (opt == 'P')
|
|
|
|
add_keymap_path(optarg);
|
2019-06-24 21:05:14 +00:00
|
|
|
if (opt == '?')
|
|
|
|
usage();
|
|
|
|
}
|
2016-03-16 04:05:02 +00:00
|
|
|
|
|
|
|
optind = optreset = 1;
|
|
|
|
while ((opt = getopt(argc, argv, optstring)) != -1)
|
1994-08-17 08:59:37 +00:00
|
|
|
switch(opt) {
|
2005-07-14 22:43:20 +00:00
|
|
|
case 'A':
|
|
|
|
case 'a':
|
|
|
|
mux_keyboard((opt == 'A')? KBRELKBD : KBADDKBD, optarg);
|
|
|
|
break;
|
2001-05-28 11:05:28 +00:00
|
|
|
case 'b':
|
|
|
|
set_bell_values(optarg);
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
print_keymap();
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
load_keymap(optarg, 0);
|
|
|
|
break;
|
|
|
|
case 'L':
|
|
|
|
load_keymap(optarg, 1);
|
|
|
|
break;
|
2016-03-16 04:05:02 +00:00
|
|
|
case 'P':
|
|
|
|
break;
|
2001-05-28 11:05:28 +00:00
|
|
|
case 'f':
|
|
|
|
set_functionkey(optarg,
|
|
|
|
nextarg(argc, argv, &optind, 'f'));
|
|
|
|
break;
|
|
|
|
case 'F':
|
|
|
|
load_default_functionkeys();
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
show_kbd_info();
|
|
|
|
break;
|
|
|
|
case 'K':
|
|
|
|
release_keyboard();
|
|
|
|
break;
|
|
|
|
case 'k':
|
|
|
|
set_keyboard(optarg);
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
set_keyrates(optarg);
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
hex = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
1994-08-17 08:59:37 +00:00
|
|
|
}
|
1997-09-19 06:28:57 +00:00
|
|
|
if ((optind != argc) || (argc == 1))
|
1994-08-17 08:59:37 +00:00
|
|
|
usage();
|
|
|
|
exit(0);
|
|
|
|
}
|