Files
cubelinux-kernel/drivers/accessibility/speakup/utils.h
T
Greg Kroah-Hartman 598cf27219 Linux 6.19.3
Link: https://lore.kernel.org/r/20260217200002.683975158@linuxfoundation.org
Tested-by: Florian Fainelli <florian.fainelli@broadcom.com>
Tested-by: Takeshi Ogasawara <takeshi.ogasawara@futuring-girl.com>
Tested-by: Peter Schneider <pschneider1968@googlemail.com>
Tested-by: Jon Hunter <jonathanh@nvidia.com>
Tested-by: Salvatore Bonaccorso <carnil@debian.org>
Tested-by: Brett A C Sheffield <bacs@librecast.net>
Tested-by: Mark Brown <broonie@kernel.org>
Tested-by: Luna Jernberg <droidbittin@gmail.com>
Tested-by: Ronald Warsow <rwarsow@gmx.de>
Tested-by: Justin M. Forbes <jforbes@fedoraproject.org>
Tested-by: Ron Economos <re@w6rz.net>
Tested-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2026-02-19 16:33:27 +01:00

103 lines
2.0 KiB
C

/* SPDX-License-Identifier: GPL-2.0+ */
/* utils.h
* originally written by: Kirk Reiser.
*
** Copyright (C) 2002 Kirk Reiser.
* Copyright (C) 2003 David Borowski.
*/
#include <stdio.h>
#define MAXKEYS 512
#define MAXKEYVAL 160
#define HASHSIZE 101
#define is_shift -3
#define is_spk -2
#define is_input -1
struct st_key {
char *name;
struct st_key *next;
int value, shift;
};
struct st_key key_table[MAXKEYS];
struct st_key *extra_keys = key_table+HASHSIZE;
char *def_name, *def_val;
FILE *infile;
int lc;
char filename[256];
static inline void open_input(const char *dir_name, const char *name)
{
if (dir_name)
snprintf(filename, sizeof(filename), "%s/%s", dir_name, name);
else
snprintf(filename, sizeof(filename), "%s", name);
infile = fopen(filename, "r");
if (infile == 0) {
fprintf(stderr, "can't open %s\n", filename);
exit(1);
}
lc = 0;
}
static inline int oops(const char *msg, const char *info)
{
if (info == NULL)
info = "";
fprintf(stderr, "error: file %s line %d\n", filename, lc);
fprintf(stderr, "%s %s\n", msg, info);
exit(1);
}
static inline struct st_key *hash_name(char *name)
{
unsigned char *pn = (unsigned char *)name;
int hash = 0;
while (*pn) {
hash = (hash * 17) & 0xfffffff;
if (isupper(*pn))
*pn = tolower(*pn);
hash += (int)*pn;
pn++;
}
hash %= HASHSIZE;
return &key_table[hash];
}
static inline struct st_key *find_key(char *name)
{
struct st_key *this = hash_name(name);
while (this) {
if (this->name && !strcmp(name, this->name))
return this;
this = this->next;
}
return this;
}
static inline struct st_key *add_key(char *name, int value, int shift)
{
struct st_key *this = hash_name(name);
if (extra_keys-key_table >= MAXKEYS)
oops("out of key table space, enlarge MAXKEYS", NULL);
if (this->name != NULL) {
while (this->next) {
if (!strcmp(name, this->name))
oops("attempt to add duplicate key", name);
this = this->next;
}
this->next = extra_keys++;
this = this->next;
}
this->name = strdup(name);
this->value = value;
this->shift = shift;
return this;
}