Greg Kroah-Hartman | 6496922 | 2018-01-11 11:08:40 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 2 | /* speakup_keyhelp.c |
William Hubbs | 09adcb5 | 2010-10-12 11:39:29 -0500 | [diff] [blame] | 3 | * help module for speakup |
| 4 | * |
| 5 | *written by David Borowski. |
| 6 | * |
| 7 | * Copyright (C) 2003 David Borowski. |
William Hubbs | 09adcb5 | 2010-10-12 11:39:29 -0500 | [diff] [blame] | 8 | */ |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 9 | |
| 10 | #include <linux/keyboard.h> |
| 11 | #include "spk_priv.h" |
| 12 | #include "speakup.h" |
| 13 | |
| 14 | #define MAXFUNCS 130 |
| 15 | #define MAXKEYS 256 |
| 16 | static const int num_key_names = MSG_KEYNAMES_END - MSG_KEYNAMES_START + 1; |
| 17 | static u_short key_offsets[MAXFUNCS], key_data[MAXKEYS]; |
| 18 | static u_short masks[] = { 32, 16, 8, 4, 2, 1 }; |
| 19 | |
William Hubbs | 09adcb5 | 2010-10-12 11:39:29 -0500 | [diff] [blame] | 20 | static short letter_offsets[26] = { |
Tracey Dent | 1bd15cf | 2010-10-08 06:14:45 -0400 | [diff] [blame] | 21 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 22 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 23 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 24 | -1, -1 }; |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 25 | |
| 26 | static u_char funcvals[] = { |
| 27 | ATTRIB_BLEEP_DEC, ATTRIB_BLEEP_INC, BLEEPS_DEC, BLEEPS_INC, |
| 28 | SAY_FIRST_CHAR, SAY_LAST_CHAR, SAY_CHAR, SAY_CHAR_NUM, |
| 29 | SAY_NEXT_CHAR, SAY_PHONETIC_CHAR, SAY_PREV_CHAR, SPEAKUP_PARKED, |
| 30 | SPEAKUP_CUT, EDIT_DELIM, EDIT_EXNUM, EDIT_MOST, |
| 31 | EDIT_REPEAT, EDIT_SOME, SPEAKUP_GOTO, BOTTOM_EDGE, |
| 32 | LEFT_EDGE, RIGHT_EDGE, TOP_EDGE, SPEAKUP_HELP, |
| 33 | SAY_LINE, SAY_NEXT_LINE, SAY_PREV_LINE, SAY_LINE_INDENT, |
| 34 | SPEAKUP_PASTE, PITCH_DEC, PITCH_INC, PUNCT_DEC, |
| 35 | PUNCT_INC, PUNC_LEVEL_DEC, PUNC_LEVEL_INC, SPEAKUP_QUIET, |
| 36 | RATE_DEC, RATE_INC, READING_PUNC_DEC, READING_PUNC_INC, |
| 37 | SAY_ATTRIBUTES, SAY_FROM_LEFT, SAY_FROM_TOP, SAY_POSITION, |
| 38 | SAY_SCREEN, SAY_TO_BOTTOM, SAY_TO_RIGHT, SPK_KEY, |
| 39 | SPK_LOCK, SPEAKUP_OFF, SPEECH_KILL, SPELL_DELAY_DEC, |
| 40 | SPELL_DELAY_INC, SPELL_WORD, SPELL_PHONETIC, TONE_DEC, |
| 41 | TONE_INC, VOICE_DEC, VOICE_INC, VOL_DEC, |
| 42 | VOL_INC, CLEAR_WIN, SAY_WIN, SET_WIN, |
| 43 | ENABLE_WIN, SAY_WORD, SAY_NEXT_WORD, SAY_PREV_WORD, 0 |
| 44 | }; |
| 45 | |
| 46 | static u_char *state_tbl; |
| 47 | static int cur_item, nstates; |
| 48 | |
| 49 | static void build_key_data(void) |
| 50 | { |
| 51 | u_char *kp, counters[MAXFUNCS], ch, ch1; |
Colin Ian King | 42228d9 | 2020-02-23 15:39:54 +0000 | [diff] [blame] | 52 | u_short *p_key, key; |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 53 | int i, offset = 1; |
Domagoj Trsan | 8e69a81 | 2014-09-09 20:04:34 +0200 | [diff] [blame] | 54 | |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 55 | nstates = (int)(state_tbl[-1]); |
| 56 | memset(counters, 0, sizeof(counters)); |
| 57 | memset(key_offsets, 0, sizeof(key_offsets)); |
| 58 | kp = state_tbl + nstates + 1; |
| 59 | while (*kp++) { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 60 | /* count occurrences of each function */ |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 61 | for (i = 0; i < nstates; i++, kp++) { |
| 62 | if (!*kp) |
| 63 | continue; |
Christian Colic | a4efe6f | 2015-11-19 14:40:59 +0100 | [diff] [blame] | 64 | if ((state_tbl[i] & 16) != 0 && *kp == SPK_KEY) |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 65 | continue; |
| 66 | counters[*kp]++; |
| 67 | } |
| 68 | } |
| 69 | for (i = 0; i < MAXFUNCS; i++) { |
| 70 | if (counters[i] == 0) |
| 71 | continue; |
| 72 | key_offsets[i] = offset; |
Christian Colic | a4efe6f | 2015-11-19 14:40:59 +0100 | [diff] [blame] | 73 | offset += (counters[i] + 1); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 74 | if (offset >= MAXKEYS) |
| 75 | break; |
| 76 | } |
| 77 | /* leave counters set so high keycodes come first. |
William Hubbs | 09adcb5 | 2010-10-12 11:39:29 -0500 | [diff] [blame] | 78 | * this is done so num pad and other extended keys maps are spoken before |
| 79 | * the alpha with speakup type mapping. |
| 80 | */ |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 81 | kp = state_tbl + nstates + 1; |
| 82 | while ((ch = *kp++)) { |
| 83 | for (i = 0; i < nstates; i++) { |
| 84 | ch1 = *kp++; |
| 85 | if (!ch1) |
| 86 | continue; |
Christian Colic | a4efe6f | 2015-11-19 14:40:59 +0100 | [diff] [blame] | 87 | if ((state_tbl[i] & 16) != 0 && ch1 == SPK_KEY) |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 88 | continue; |
| 89 | key = (state_tbl[i] << 8) + ch; |
| 90 | counters[ch1]--; |
| 91 | offset = key_offsets[ch1]; |
| 92 | if (!offset) |
| 93 | continue; |
| 94 | p_key = key_data + offset + counters[ch1]; |
| 95 | *p_key = key; |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | static void say_key(int key) |
| 101 | { |
| 102 | int i, state = key >> 8; |
Domagoj Trsan | 8e69a81 | 2014-09-09 20:04:34 +0200 | [diff] [blame] | 103 | |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 104 | key &= 0xff; |
| 105 | for (i = 0; i < 6; i++) { |
| 106 | if (state & masks[i]) |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 107 | synth_printf(" %s", spk_msg_get(MSG_STATES_START + i)); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 108 | } |
| 109 | if ((key > 0) && (key <= num_key_names)) |
Lijo Antony | ed52565 | 2013-01-08 22:39:02 +0400 | [diff] [blame] | 110 | synth_printf(" %s\n", |
Sreya Mittal | 4cb3150 | 2017-03-01 02:38:12 +0530 | [diff] [blame] | 111 | spk_msg_get(MSG_KEYNAMES_START + (key - 1))); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | static int help_init(void) |
| 115 | { |
| 116 | char start = SPACE; |
| 117 | int i; |
| 118 | int num_funcs = MSG_FUNCNAMES_END - MSG_FUNCNAMES_START + 1; |
Domagoj Trsan | e487352 | 2014-09-09 20:04:33 +0200 | [diff] [blame] | 119 | |
Christian Colic | a4efe6f | 2015-11-19 14:40:59 +0100 | [diff] [blame] | 120 | state_tbl = spk_our_keys[0] + SHIFT_TBL_SIZE + 2; |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 121 | for (i = 0; i < num_funcs; i++) { |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 122 | char *cur_funcname = spk_msg_get(MSG_FUNCNAMES_START + i); |
Domagoj Trsan | 8e69a81 | 2014-09-09 20:04:34 +0200 | [diff] [blame] | 123 | |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 124 | if (start == *cur_funcname) |
| 125 | continue; |
| 126 | start = *cur_funcname; |
Christian Colic | a4efe6f | 2015-11-19 14:40:59 +0100 | [diff] [blame] | 127 | letter_offsets[(start & 31) - 1] = i; |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 128 | } |
| 129 | return 0; |
| 130 | } |
| 131 | |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 132 | int spk_handle_help(struct vc_data *vc, u_char type, u_char ch, u_short key) |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 133 | { |
| 134 | int i, n; |
| 135 | char *name; |
| 136 | u_char func, *kp; |
| 137 | u_short *p_keys, val; |
Domagoj Trsan | 8e69a81 | 2014-09-09 20:04:34 +0200 | [diff] [blame] | 138 | |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 139 | if (letter_offsets[0] == -1) |
| 140 | help_init(); |
| 141 | if (type == KT_LATIN) { |
| 142 | if (ch == SPACE) { |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 143 | spk_special_handler = NULL; |
| 144 | synth_printf("%s\n", spk_msg_get(MSG_LEAVING_HELP)); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 145 | return 1; |
| 146 | } |
| 147 | ch |= 32; /* lower case */ |
| 148 | if (ch < 'a' || ch > 'z') |
| 149 | return -1; |
Christian Colic | a4efe6f | 2015-11-19 14:40:59 +0100 | [diff] [blame] | 150 | if (letter_offsets[ch - 'a'] == -1) { |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 151 | synth_printf(spk_msg_get(MSG_NO_COMMAND), ch); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 152 | synth_printf("\n"); |
| 153 | return 1; |
| 154 | } |
Christian Colic | a4efe6f | 2015-11-19 14:40:59 +0100 | [diff] [blame] | 155 | cur_item = letter_offsets[ch - 'a']; |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 156 | } else if (type == KT_CUR) { |
Sreya Mittal | 2430125 | 2017-03-01 02:38:13 +0530 | [diff] [blame] | 157 | if (ch == 0 && |
| 158 | (MSG_FUNCNAMES_START + cur_item + 1) <= MSG_FUNCNAMES_END) |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 159 | cur_item++; |
| 160 | else if (ch == 3 && cur_item > 0) |
| 161 | cur_item--; |
| 162 | else |
| 163 | return -1; |
Sreya Mittal | 2430125 | 2017-03-01 02:38:13 +0530 | [diff] [blame] | 164 | } else if (type == KT_SPKUP && ch == SPEAKUP_HELP && |
| 165 | !spk_special_handler) { |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 166 | spk_special_handler = spk_handle_help; |
| 167 | synth_printf("%s\n", spk_msg_get(MSG_HELP_INFO)); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 168 | build_key_data(); /* rebuild each time in case new mapping */ |
| 169 | return 1; |
| 170 | } else { |
| 171 | name = NULL; |
| 172 | if ((type != KT_SPKUP) && (key > 0) && (key <= num_key_names)) { |
William Hubbs | 09adcb5 | 2010-10-12 11:39:29 -0500 | [diff] [blame] | 173 | synth_printf("%s\n", |
Sreya Mittal | 4cb3150 | 2017-03-01 02:38:12 +0530 | [diff] [blame] | 174 | spk_msg_get(MSG_KEYNAMES_START + key - 1)); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 175 | return 1; |
| 176 | } |
| 177 | for (i = 0; funcvals[i] != 0 && !name; i++) { |
| 178 | if (ch == funcvals[i]) |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 179 | name = spk_msg_get(MSG_FUNCNAMES_START + i); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 180 | } |
| 181 | if (!name) |
| 182 | return -1; |
Christian Colic | a4efe6f | 2015-11-19 14:40:59 +0100 | [diff] [blame] | 183 | kp = spk_our_keys[key] + 1; |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 184 | for (i = 0; i < nstates; i++) { |
| 185 | if (ch == kp[i]) |
| 186 | break; |
| 187 | } |
| 188 | key += (state_tbl[i] << 8); |
| 189 | say_key(key); |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 190 | synth_printf(spk_msg_get(MSG_KEYDESC), name); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 191 | synth_printf("\n"); |
| 192 | return 1; |
| 193 | } |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 194 | name = spk_msg_get(MSG_FUNCNAMES_START + cur_item); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 195 | func = funcvals[cur_item]; |
| 196 | synth_printf("%s", name); |
| 197 | if (key_offsets[func] == 0) { |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 198 | synth_printf(" %s\n", spk_msg_get(MSG_IS_UNASSIGNED)); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 199 | return 1; |
| 200 | } |
| 201 | p_keys = key_data + key_offsets[func]; |
| 202 | for (n = 0; p_keys[n]; n++) { |
| 203 | val = p_keys[n]; |
| 204 | if (n > 0) |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 205 | synth_printf("%s ", spk_msg_get(MSG_DISJUNCTION)); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 206 | say_key(val); |
| 207 | } |
| 208 | return 1; |
| 209 | } |