1 // SPDX-License-Identifier: GPL-2.0+
3 * originally written by: Kirk Reiser.
5 ** Copyright (C) 2002 Kirk Reiser.
6 * Copyright (C) 2003 David Borowski.
13 #include <linux/version.h>
22 static unsigned char key_data[MAXKEYVAL][16], *kp;
26 static const char delims[] = "\t\n ";
28 static int map_ver = 119; /* an arbitrary number so speakup can check */
29 static int shift_table[17];
30 static int max_states = 1, flags;
31 /* flags reserved for later, maybe for individual console maps */
33 static int get_shift_value(int state)
37 for (i = 0; shift_table[i] != state; i++) {
38 if (shift_table[i] == -1) {
40 oops("too many shift states", NULL);
41 shift_table[i] = state;
50 main(int argc, char *argv[])
52 int value, shift_state, i, spk_val = 0, lock_val = 0;
53 int max_key_used = 0, num_keys_used = 0;
55 struct st_key_init *p_init;
58 bzero(key_table, sizeof(key_table));
59 bzero(key_data, sizeof(key_data));
62 for (i = 1; i <= 16; i++)
66 fputs("usage: genmap filename\n", stderr);
70 for (p_init = init_key_data; p_init->name[0] != '.'; p_init++)
71 add_key(p_init->name, p_init->value, p_init->shift);
73 open_input(NULL, argv[1]);
74 while (fgets(buffer, sizeof(buffer), infile)) {
76 value = shift_state = 0;
78 cp = strtok(buffer, delims);
87 oops("unknown key/modifier", cp);
88 if (this->shift == is_shift) {
90 oops("modifiers must come first", cp);
91 shift_state += this->value;
92 } else if (this->shift == is_input)
95 oops("bad modifier or key", cp);
96 cp = strtok(0, delims);
99 oops("no = found", NULL);
101 cp = strtok(0, delims);
103 oops("no speakup function after =", NULL);
106 if (this == NULL || this->shift != is_spk)
107 oops("invalid speakup function", cp);
109 i = get_shift_value(shift_state);
110 if (key_data[value][i]) {
111 while (--cp > buffer)
114 oops("two functions on same key combination", cp);
116 key_data[value][i] = (char)this->value;
117 if (value > max_key_used)
118 max_key_used = value;
122 this = find_key("spk_key");
124 spk_val = this->value;
126 this = find_key("spk_lock");
128 lock_val = this->value;
130 for (lc = 1; lc <= max_key_used; lc++) {
132 if (!memcmp(key_data[0], kp, 16))
135 for (i = 0; i < max_states; i++) {
136 if (kp[i] != spk_val && kp[i] != lock_val)
138 shift_state = shift_table[i];
141 shift_state = get_shift_value(shift_state+16);
142 kp[shift_state] = kp[i];
143 /* fill in so we can process the key up, as spk bit will be set */
147 printf("\t%d, %d, %d,\n\t", map_ver, num_keys_used, max_states);
148 for (i = 0; i < max_states; i++)
149 printf("%d, ", shift_table[i]);
150 printf("%d,", flags);
151 for (lc = 1; lc <= max_key_used; lc++) {
153 if (!memcmp(key_data[0], kp, 16))
155 printf("\n\t%d,", lc);
156 for (i = 0; i < max_states; i++)
157 printf(" %d,", (unsigned int)kp[i]);
159 printf("\n\t0, %d\n", map_ver);