William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 1 | /* speakup_keyhelp.c |
William Hubbs | 09adcb5 | 2010-10-12 11:39:29 -0500 | [diff] [blame] | 2 | * help module for speakup |
| 3 | * |
| 4 | *written by David Borowski. |
| 5 | * |
| 6 | * Copyright (C) 2003 David Borowski. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | */ |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 22 | |
| 23 | #include <linux/keyboard.h> |
| 24 | #include "spk_priv.h" |
| 25 | #include "speakup.h" |
| 26 | |
| 27 | #define MAXFUNCS 130 |
| 28 | #define MAXKEYS 256 |
| 29 | static const int num_key_names = MSG_KEYNAMES_END - MSG_KEYNAMES_START + 1; |
| 30 | static u_short key_offsets[MAXFUNCS], key_data[MAXKEYS]; |
| 31 | static u_short masks[] = { 32, 16, 8, 4, 2, 1 }; |
| 32 | |
William Hubbs | 09adcb5 | 2010-10-12 11:39:29 -0500 | [diff] [blame] | 33 | static short letter_offsets[26] = { |
Tracey Dent | 1bd15cf | 2010-10-08 06:14:45 -0400 | [diff] [blame] | 34 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 35 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 36 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 37 | -1, -1 }; |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 38 | |
| 39 | static u_char funcvals[] = { |
| 40 | ATTRIB_BLEEP_DEC, ATTRIB_BLEEP_INC, BLEEPS_DEC, BLEEPS_INC, |
| 41 | SAY_FIRST_CHAR, SAY_LAST_CHAR, SAY_CHAR, SAY_CHAR_NUM, |
| 42 | SAY_NEXT_CHAR, SAY_PHONETIC_CHAR, SAY_PREV_CHAR, SPEAKUP_PARKED, |
| 43 | SPEAKUP_CUT, EDIT_DELIM, EDIT_EXNUM, EDIT_MOST, |
| 44 | EDIT_REPEAT, EDIT_SOME, SPEAKUP_GOTO, BOTTOM_EDGE, |
| 45 | LEFT_EDGE, RIGHT_EDGE, TOP_EDGE, SPEAKUP_HELP, |
| 46 | SAY_LINE, SAY_NEXT_LINE, SAY_PREV_LINE, SAY_LINE_INDENT, |
| 47 | SPEAKUP_PASTE, PITCH_DEC, PITCH_INC, PUNCT_DEC, |
| 48 | PUNCT_INC, PUNC_LEVEL_DEC, PUNC_LEVEL_INC, SPEAKUP_QUIET, |
| 49 | RATE_DEC, RATE_INC, READING_PUNC_DEC, READING_PUNC_INC, |
| 50 | SAY_ATTRIBUTES, SAY_FROM_LEFT, SAY_FROM_TOP, SAY_POSITION, |
| 51 | SAY_SCREEN, SAY_TO_BOTTOM, SAY_TO_RIGHT, SPK_KEY, |
| 52 | SPK_LOCK, SPEAKUP_OFF, SPEECH_KILL, SPELL_DELAY_DEC, |
| 53 | SPELL_DELAY_INC, SPELL_WORD, SPELL_PHONETIC, TONE_DEC, |
| 54 | TONE_INC, VOICE_DEC, VOICE_INC, VOL_DEC, |
| 55 | VOL_INC, CLEAR_WIN, SAY_WIN, SET_WIN, |
| 56 | ENABLE_WIN, SAY_WORD, SAY_NEXT_WORD, SAY_PREV_WORD, 0 |
| 57 | }; |
| 58 | |
| 59 | static u_char *state_tbl; |
| 60 | static int cur_item, nstates; |
| 61 | |
| 62 | static void build_key_data(void) |
| 63 | { |
| 64 | u_char *kp, counters[MAXFUNCS], ch, ch1; |
| 65 | u_short *p_key = key_data, key; |
| 66 | int i, offset = 1; |
| 67 | nstates = (int)(state_tbl[-1]); |
| 68 | memset(counters, 0, sizeof(counters)); |
| 69 | memset(key_offsets, 0, sizeof(key_offsets)); |
| 70 | kp = state_tbl + nstates + 1; |
| 71 | while (*kp++) { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 72 | /* count occurrences of each function */ |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 73 | for (i = 0; i < nstates; i++, kp++) { |
| 74 | if (!*kp) |
| 75 | continue; |
| 76 | if ((state_tbl[i]&16) != 0 && *kp == SPK_KEY) |
| 77 | continue; |
| 78 | counters[*kp]++; |
| 79 | } |
| 80 | } |
| 81 | for (i = 0; i < MAXFUNCS; i++) { |
| 82 | if (counters[i] == 0) |
| 83 | continue; |
| 84 | key_offsets[i] = offset; |
| 85 | offset += (counters[i]+1); |
| 86 | if (offset >= MAXKEYS) |
| 87 | break; |
| 88 | } |
| 89 | /* leave counters set so high keycodes come first. |
William Hubbs | 09adcb5 | 2010-10-12 11:39:29 -0500 | [diff] [blame] | 90 | * this is done so num pad and other extended keys maps are spoken before |
| 91 | * the alpha with speakup type mapping. |
| 92 | */ |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 93 | kp = state_tbl + nstates + 1; |
| 94 | while ((ch = *kp++)) { |
| 95 | for (i = 0; i < nstates; i++) { |
| 96 | ch1 = *kp++; |
| 97 | if (!ch1) |
| 98 | continue; |
| 99 | if ((state_tbl[i]&16) != 0 && ch1 == SPK_KEY) |
| 100 | continue; |
| 101 | key = (state_tbl[i] << 8) + ch; |
| 102 | counters[ch1]--; |
| 103 | offset = key_offsets[ch1]; |
| 104 | if (!offset) |
| 105 | continue; |
| 106 | p_key = key_data + offset + counters[ch1]; |
| 107 | *p_key = key; |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | static void say_key(int key) |
| 113 | { |
| 114 | int i, state = key >> 8; |
| 115 | key &= 0xff; |
| 116 | for (i = 0; i < 6; i++) { |
| 117 | if (state & masks[i]) |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 118 | synth_printf(" %s", spk_msg_get(MSG_STATES_START + i)); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 119 | } |
| 120 | if ((key > 0) && (key <= num_key_names)) |
Lijo Antony | ed52565 | 2013-01-08 22:39:02 +0400 | [diff] [blame] | 121 | synth_printf(" %s\n", |
| 122 | spk_msg_get(MSG_KEYNAMES_START + (key - 1))); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | static int help_init(void) |
| 126 | { |
| 127 | char start = SPACE; |
| 128 | int i; |
| 129 | int num_funcs = MSG_FUNCNAMES_END - MSG_FUNCNAMES_START + 1; |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 130 | state_tbl = spk_our_keys[0]+SHIFT_TBL_SIZE+2; |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 131 | for (i = 0; i < num_funcs; i++) { |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 132 | char *cur_funcname = spk_msg_get(MSG_FUNCNAMES_START + i); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 133 | if (start == *cur_funcname) |
| 134 | continue; |
| 135 | start = *cur_funcname; |
| 136 | letter_offsets[(start&31)-1] = i; |
| 137 | } |
| 138 | return 0; |
| 139 | } |
| 140 | |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 141 | 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] | 142 | { |
| 143 | int i, n; |
| 144 | char *name; |
| 145 | u_char func, *kp; |
| 146 | u_short *p_keys, val; |
| 147 | if (letter_offsets[0] == -1) |
| 148 | help_init(); |
| 149 | if (type == KT_LATIN) { |
| 150 | if (ch == SPACE) { |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 151 | spk_special_handler = NULL; |
| 152 | synth_printf("%s\n", spk_msg_get(MSG_LEAVING_HELP)); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 153 | return 1; |
| 154 | } |
| 155 | ch |= 32; /* lower case */ |
| 156 | if (ch < 'a' || ch > 'z') |
| 157 | return -1; |
| 158 | if (letter_offsets[ch-'a'] == -1) { |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 159 | synth_printf(spk_msg_get(MSG_NO_COMMAND), ch); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 160 | synth_printf("\n"); |
| 161 | return 1; |
| 162 | } |
| 163 | cur_item = letter_offsets[ch-'a']; |
| 164 | } else if (type == KT_CUR) { |
Christopher Brannon | 87be424 | 2011-02-21 14:07:10 +0000 | [diff] [blame] | 165 | if (ch == 0 |
| 166 | && (MSG_FUNCNAMES_START + cur_item + 1) <= |
| 167 | MSG_FUNCNAMES_END) |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 168 | cur_item++; |
| 169 | else if (ch == 3 && cur_item > 0) |
| 170 | cur_item--; |
| 171 | else |
| 172 | return -1; |
Lijo Antony | ed52565 | 2013-01-08 22:39:02 +0400 | [diff] [blame] | 173 | } else if (type == KT_SPKUP |
| 174 | && ch == SPEAKUP_HELP |
| 175 | && !spk_special_handler) { |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 176 | spk_special_handler = spk_handle_help; |
| 177 | synth_printf("%s\n", spk_msg_get(MSG_HELP_INFO)); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 178 | build_key_data(); /* rebuild each time in case new mapping */ |
| 179 | return 1; |
| 180 | } else { |
| 181 | name = NULL; |
| 182 | if ((type != KT_SPKUP) && (key > 0) && (key <= num_key_names)) { |
William Hubbs | 09adcb5 | 2010-10-12 11:39:29 -0500 | [diff] [blame] | 183 | synth_printf("%s\n", |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 184 | spk_msg_get(MSG_KEYNAMES_START + key-1)); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 185 | return 1; |
| 186 | } |
| 187 | for (i = 0; funcvals[i] != 0 && !name; i++) { |
| 188 | if (ch == funcvals[i]) |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 189 | name = spk_msg_get(MSG_FUNCNAMES_START + i); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 190 | } |
| 191 | if (!name) |
| 192 | return -1; |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 193 | kp = spk_our_keys[key]+1; |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 194 | for (i = 0; i < nstates; i++) { |
| 195 | if (ch == kp[i]) |
| 196 | break; |
| 197 | } |
| 198 | key += (state_tbl[i] << 8); |
| 199 | say_key(key); |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 200 | synth_printf(spk_msg_get(MSG_KEYDESC), name); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 201 | synth_printf("\n"); |
| 202 | return 1; |
| 203 | } |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 204 | name = spk_msg_get(MSG_FUNCNAMES_START + cur_item); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 205 | func = funcvals[cur_item]; |
| 206 | synth_printf("%s", name); |
| 207 | if (key_offsets[func] == 0) { |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 208 | synth_printf(" %s\n", spk_msg_get(MSG_IS_UNASSIGNED)); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 209 | return 1; |
| 210 | } |
| 211 | p_keys = key_data + key_offsets[func]; |
| 212 | for (n = 0; p_keys[n]; n++) { |
| 213 | val = p_keys[n]; |
| 214 | if (n > 0) |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 215 | synth_printf("%s ", spk_msg_get(MSG_DISJUNCTION)); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 216 | say_key(val); |
| 217 | } |
| 218 | return 1; |
| 219 | } |