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.
21 static unsigned char key_data
[MAXKEYVAL
][16], *kp
;
25 static const char delims
[] = "\t\n ";
27 static int map_ver
= 119; /* an arbitrary number so speakup can check */
28 static int shift_table
[17];
29 static int max_states
= 1, flags
;
30 /* flags reserved for later, maybe for individual console maps */
32 static int get_shift_value(int state
)
36 for (i
= 0; shift_table
[i
] != state
; i
++) {
37 if (shift_table
[i
] == -1) {
39 oops("too many shift states", NULL
);
40 shift_table
[i
] = state
;
49 main(int argc
, char *argv
[])
51 int value
, shift_state
, i
, spk_val
= 0, lock_val
= 0;
52 int max_key_used
= 0, num_keys_used
= 0;
54 struct st_key_init
*p_init
;
57 bzero(key_table
, sizeof(key_table
));
58 bzero(key_data
, sizeof(key_data
));
61 for (i
= 1; i
<= 16; i
++)
65 fputs("usage: genmap filename\n", stderr
);
69 for (p_init
= init_key_data
; p_init
->name
[0] != '.'; p_init
++)
70 add_key(p_init
->name
, p_init
->value
, p_init
->shift
);
72 open_input(NULL
, argv
[1]);
73 while (fgets(buffer
, sizeof(buffer
), infile
)) {
75 value
= shift_state
= 0;
77 cp
= strtok(buffer
, delims
);
86 oops("unknown key/modifier", cp
);
87 if (this->shift
== is_shift
) {
89 oops("modifiers must come first", cp
);
90 shift_state
+= this->value
;
91 } else if (this->shift
== is_input
)
94 oops("bad modifier or key", cp
);
95 cp
= strtok(0, delims
);
98 oops("no = found", NULL
);
100 cp
= strtok(0, delims
);
102 oops("no speakup function after =", NULL
);
105 if (this == NULL
|| this->shift
!= is_spk
)
106 oops("invalid speakup function", cp
);
108 i
= get_shift_value(shift_state
);
109 if (key_data
[value
][i
]) {
110 while (--cp
> buffer
)
113 oops("two functions on same key combination", cp
);
115 key_data
[value
][i
] = (char)this->value
;
116 if (value
> max_key_used
)
117 max_key_used
= value
;
121 this = find_key("spk_key");
123 spk_val
= this->value
;
125 this = find_key("spk_lock");
127 lock_val
= this->value
;
129 for (lc
= 1; lc
<= max_key_used
; lc
++) {
131 if (!memcmp(key_data
[0], kp
, 16))
134 for (i
= 0; i
< max_states
; i
++) {
135 if (kp
[i
] != spk_val
&& kp
[i
] != lock_val
)
137 shift_state
= shift_table
[i
];
140 shift_state
= get_shift_value(shift_state
+16);
141 kp
[shift_state
] = kp
[i
];
142 /* fill in so we can process the key up, as spk bit will be set */
146 printf("\t%d, %d, %d,\n\t", map_ver
, num_keys_used
, max_states
);
147 for (i
= 0; i
< max_states
; i
++)
148 printf("%d, ", shift_table
[i
]);
149 printf("%d,", flags
);
150 for (lc
= 1; lc
<= max_key_used
; lc
++) {
152 if (!memcmp(key_data
[0], kp
, 16))
154 printf("\n\t%d,", lc
);
155 for (i
= 0; i
< max_states
; i
++)
156 printf(" %d,", (unsigned int)kp
[i
]);
158 printf("\n\t0, %d\n", map_ver
);