2006-02-05 21:11:46 +03:00
|
|
|
/* $NetBSD: keysym.c,v 1.7 2006/02/05 18:11:46 jmmv Exp $ */
|
1998-12-28 17:01:16 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Juergen Hannken-Illjes.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 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. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``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 FOUNDATION OR CONTRIBUTORS
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <dev/wscons/wsksymdef.h>
|
2006-02-05 21:11:46 +03:00
|
|
|
|
1998-12-28 17:01:16 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2000-07-03 07:37:59 +04:00
|
|
|
#include <string.h>
|
1998-12-28 17:01:16 +03:00
|
|
|
#include <unistd.h>
|
2006-02-05 21:11:46 +03:00
|
|
|
|
1998-12-28 17:01:16 +03:00
|
|
|
#include "keysym.h"
|
|
|
|
#include "wsconsctl.h"
|
|
|
|
|
|
|
|
#define NUMKSYMS (sizeof(ksym_tab_by_name)/sizeof(ksym_tab_by_name[0]))
|
|
|
|
|
|
|
|
static int first_time = 1;
|
|
|
|
static struct ksym ksym_tab_by_ksym[NUMKSYMS];
|
|
|
|
|
|
|
|
/* copied from dev/wscons/wskbdutil.c ... */
|
|
|
|
|
|
|
|
static const u_char latin1_to_upper[256] = {
|
2006-02-05 21:11:46 +03:00
|
|
|
/* 0 8 1 9 2 a 3 b 4 c 5 d 6 e 7 f */
|
1998-12-28 17:01:16 +03:00
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0 */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0 */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1 */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1 */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 2 */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 2 */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 3 */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 3 */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 4 */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 4 */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 5 */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 5 */
|
|
|
|
0x00, 'A', 'B', 'C', 'D', 'E', 'F', 'G', /* 6 */
|
|
|
|
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', /* 6 */
|
|
|
|
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', /* 7 */
|
|
|
|
'X', 'Y', 'Z', 0x00, 0x00, 0x00, 0x00, 0x00, /* 7 */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 8 */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 8 */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 9 */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 9 */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* a */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* a */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* b */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* b */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* c */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* c */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* d */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* d */
|
|
|
|
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, /* e */
|
|
|
|
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, /* e */
|
|
|
|
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0x00, /* f */
|
|
|
|
0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0x00, /* f */
|
|
|
|
};
|
|
|
|
|
2005-01-19 23:37:52 +03:00
|
|
|
static int qcmp_name(const void *, const void *);
|
|
|
|
static int qcmp_ksym(const void *, const void *);
|
|
|
|
static int bcmp_name(const void *, const void *);
|
|
|
|
static int bcmp_ksym(const void *, const void *);
|
1998-12-28 17:01:16 +03:00
|
|
|
|
2005-01-19 23:37:52 +03:00
|
|
|
static void sort_ksym_tab(void);
|
1998-12-28 17:01:16 +03:00
|
|
|
|
|
|
|
static int
|
2005-01-19 23:37:52 +03:00
|
|
|
qcmp_name(const void *a, const void *b)
|
1998-12-28 17:01:16 +03:00
|
|
|
{
|
2006-02-05 21:11:46 +03:00
|
|
|
|
|
|
|
return strcmp(((const struct ksym *) a)->name,
|
|
|
|
((const struct ksym *) b)->name);
|
1998-12-28 17:01:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-01-19 23:37:52 +03:00
|
|
|
qcmp_ksym(const void *a, const void *b)
|
1998-12-28 17:01:16 +03:00
|
|
|
{
|
2006-02-05 21:11:46 +03:00
|
|
|
|
|
|
|
return ((const struct ksym *) b)->value -
|
|
|
|
((const struct ksym *) a)->value;
|
1998-12-28 17:01:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-01-19 23:37:52 +03:00
|
|
|
bcmp_name(const void *a, const void *b)
|
1998-12-28 17:01:16 +03:00
|
|
|
{
|
2006-02-05 21:11:46 +03:00
|
|
|
|
|
|
|
return strcmp((const char *) a, ((const struct ksym *) b)->name);
|
1998-12-28 17:01:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-01-19 23:37:52 +03:00
|
|
|
bcmp_ksym(const void *a, const void *b)
|
1998-12-28 17:01:16 +03:00
|
|
|
{
|
2006-02-05 21:11:46 +03:00
|
|
|
|
|
|
|
return ((const struct ksym *) b)->value - *((const int *) a);
|
1998-12-28 17:01:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-01-19 23:37:52 +03:00
|
|
|
sort_ksym_tab(void)
|
1998-12-28 17:01:16 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < NUMKSYMS; i++)
|
|
|
|
ksym_tab_by_ksym[i] = ksym_tab_by_name[i];
|
|
|
|
|
|
|
|
qsort(ksym_tab_by_name, NUMKSYMS, sizeof(struct ksym), qcmp_name);
|
|
|
|
qsort(ksym_tab_by_ksym, NUMKSYMS, sizeof(struct ksym), qcmp_ksym);
|
|
|
|
|
|
|
|
first_time = 0;
|
|
|
|
}
|
|
|
|
|
2005-06-27 02:45:50 +04:00
|
|
|
const char *
|
2005-01-19 23:37:52 +03:00
|
|
|
ksym2name(int k)
|
1998-12-28 17:01:16 +03:00
|
|
|
{
|
|
|
|
static char tmp[20];
|
|
|
|
struct ksym *r;
|
|
|
|
|
|
|
|
if (first_time)
|
|
|
|
sort_ksym_tab();
|
|
|
|
|
1999-01-02 22:01:12 +03:00
|
|
|
r = bsearch(&k, ksym_tab_by_ksym,
|
1998-12-28 17:01:16 +03:00
|
|
|
NUMKSYMS, sizeof(struct ksym), bcmp_ksym);
|
|
|
|
|
|
|
|
if (r != NULL)
|
2006-02-05 21:11:46 +03:00
|
|
|
return r->name;
|
1998-12-28 17:01:16 +03:00
|
|
|
else {
|
2006-02-05 21:11:46 +03:00
|
|
|
(void)snprintf(tmp, sizeof(tmp), "unknown_%d", k);
|
|
|
|
return tmp;
|
1998-12-28 17:01:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2005-01-19 23:37:52 +03:00
|
|
|
name2ksym(char *n)
|
1998-12-28 17:01:16 +03:00
|
|
|
{
|
1999-02-08 14:08:23 +03:00
|
|
|
int res;
|
1998-12-28 17:01:16 +03:00
|
|
|
struct ksym *r;
|
|
|
|
|
|
|
|
if (first_time)
|
|
|
|
sort_ksym_tab();
|
|
|
|
|
|
|
|
r = bsearch(n, ksym_tab_by_name,
|
|
|
|
NUMKSYMS, sizeof(struct ksym), bcmp_name);
|
|
|
|
|
|
|
|
if (r != NULL)
|
2006-02-05 21:11:46 +03:00
|
|
|
return r->value;
|
1999-02-08 14:08:23 +03:00
|
|
|
else if (sscanf(n, "unknown_%d", &res) == 1)
|
2006-02-05 21:11:46 +03:00
|
|
|
return res;
|
1998-12-28 17:01:16 +03:00
|
|
|
else
|
2006-02-05 21:11:46 +03:00
|
|
|
return -1;
|
1998-12-28 17:01:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
keysym_t
|
2005-01-19 23:37:52 +03:00
|
|
|
ksym_upcase(keysym_t ksym)
|
1998-12-28 17:01:16 +03:00
|
|
|
{
|
2006-02-05 21:11:46 +03:00
|
|
|
|
1998-12-28 17:01:16 +03:00
|
|
|
if (ksym >= KS_f1 && ksym <= KS_f20)
|
2006-02-05 21:11:46 +03:00
|
|
|
return KS_F1 - KS_f1 + ksym;
|
1998-12-28 17:01:16 +03:00
|
|
|
|
|
|
|
if (KS_GROUP(ksym) == KS_GROUP_Ascii && ksym <= 0xff &&
|
|
|
|
latin1_to_upper[ksym] != 0x00)
|
2006-02-05 21:11:46 +03:00
|
|
|
return latin1_to_upper[ksym];
|
1998-12-28 17:01:16 +03:00
|
|
|
|
2006-02-05 21:11:46 +03:00
|
|
|
return ksym;
|
1998-12-28 17:01:16 +03:00
|
|
|
}
|