0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/keyboard.h>
0011 #include "spk_priv.h"
0012 #include "speakup.h"
0013
0014 #define MAXFUNCS 130
0015 #define MAXKEYS 256
0016 static const int num_key_names = MSG_KEYNAMES_END - MSG_KEYNAMES_START + 1;
0017 static u_short key_offsets[MAXFUNCS], key_data[MAXKEYS];
0018 static u_short masks[] = { 32, 16, 8, 4, 2, 1 };
0019
0020 static short letter_offsets[26] = {
0021 -1, -1, -1, -1, -1, -1, -1, -1,
0022 -1, -1, -1, -1, -1, -1, -1, -1,
0023 -1, -1, -1, -1, -1, -1, -1, -1,
0024 -1, -1 };
0025
0026 static u_char funcvals[] = {
0027 ATTRIB_BLEEP_DEC, ATTRIB_BLEEP_INC, BLEEPS_DEC, BLEEPS_INC,
0028 SAY_FIRST_CHAR, SAY_LAST_CHAR, SAY_CHAR, SAY_CHAR_NUM,
0029 SAY_NEXT_CHAR, SAY_PHONETIC_CHAR, SAY_PREV_CHAR, SPEAKUP_PARKED,
0030 SPEAKUP_CUT, EDIT_DELIM, EDIT_EXNUM, EDIT_MOST,
0031 EDIT_REPEAT, EDIT_SOME, SPEAKUP_GOTO, BOTTOM_EDGE,
0032 LEFT_EDGE, RIGHT_EDGE, TOP_EDGE, SPEAKUP_HELP,
0033 SAY_LINE, SAY_NEXT_LINE, SAY_PREV_LINE, SAY_LINE_INDENT,
0034 SPEAKUP_PASTE, PITCH_DEC, PITCH_INC, PUNCT_DEC,
0035 PUNCT_INC, PUNC_LEVEL_DEC, PUNC_LEVEL_INC, SPEAKUP_QUIET,
0036 RATE_DEC, RATE_INC, READING_PUNC_DEC, READING_PUNC_INC,
0037 SAY_ATTRIBUTES, SAY_FROM_LEFT, SAY_FROM_TOP, SAY_POSITION,
0038 SAY_SCREEN, SAY_TO_BOTTOM, SAY_TO_RIGHT, SPK_KEY,
0039 SPK_LOCK, SPEAKUP_OFF, SPEECH_KILL, SPELL_DELAY_DEC,
0040 SPELL_DELAY_INC, SPELL_WORD, SPELL_PHONETIC, TONE_DEC,
0041 TONE_INC, VOICE_DEC, VOICE_INC, VOL_DEC,
0042 VOL_INC, CLEAR_WIN, SAY_WIN, SET_WIN,
0043 ENABLE_WIN, SAY_WORD, SAY_NEXT_WORD, SAY_PREV_WORD, 0
0044 };
0045
0046 static u_char *state_tbl;
0047 static int cur_item, nstates;
0048
0049 static void build_key_data(void)
0050 {
0051 u_char *kp, counters[MAXFUNCS], ch, ch1;
0052 u_short *p_key, key;
0053 int i, offset = 1;
0054
0055 nstates = (int)(state_tbl[-1]);
0056 memset(counters, 0, sizeof(counters));
0057 memset(key_offsets, 0, sizeof(key_offsets));
0058 kp = state_tbl + nstates + 1;
0059 while (*kp++) {
0060
0061 for (i = 0; i < nstates; i++, kp++) {
0062 if (!*kp)
0063 continue;
0064 if ((state_tbl[i] & 16) != 0 && *kp == SPK_KEY)
0065 continue;
0066 counters[*kp]++;
0067 }
0068 }
0069 for (i = 0; i < MAXFUNCS; i++) {
0070 if (counters[i] == 0)
0071 continue;
0072 key_offsets[i] = offset;
0073 offset += (counters[i] + 1);
0074 if (offset >= MAXKEYS)
0075 break;
0076 }
0077
0078
0079
0080
0081 kp = state_tbl + nstates + 1;
0082 while ((ch = *kp++)) {
0083 for (i = 0; i < nstates; i++) {
0084 ch1 = *kp++;
0085 if (!ch1)
0086 continue;
0087 if ((state_tbl[i] & 16) != 0 && ch1 == SPK_KEY)
0088 continue;
0089 key = (state_tbl[i] << 8) + ch;
0090 counters[ch1]--;
0091 offset = key_offsets[ch1];
0092 if (!offset)
0093 continue;
0094 p_key = key_data + offset + counters[ch1];
0095 *p_key = key;
0096 }
0097 }
0098 }
0099
0100 static void say_key(int key)
0101 {
0102 int i, state = key >> 8;
0103
0104 key &= 0xff;
0105 for (i = 0; i < 6; i++) {
0106 if (state & masks[i])
0107 synth_printf(" %s", spk_msg_get(MSG_STATES_START + i));
0108 }
0109 if ((key > 0) && (key <= num_key_names))
0110 synth_printf(" %s\n",
0111 spk_msg_get(MSG_KEYNAMES_START + (key - 1)));
0112 }
0113
0114 static int help_init(void)
0115 {
0116 char start = SPACE;
0117 int i;
0118 int num_funcs = MSG_FUNCNAMES_END - MSG_FUNCNAMES_START + 1;
0119
0120 state_tbl = spk_our_keys[0] + SHIFT_TBL_SIZE + 2;
0121 for (i = 0; i < num_funcs; i++) {
0122 char *cur_funcname = spk_msg_get(MSG_FUNCNAMES_START + i);
0123
0124 if (start == *cur_funcname)
0125 continue;
0126 start = *cur_funcname;
0127 letter_offsets[(start & 31) - 1] = i;
0128 }
0129 return 0;
0130 }
0131
0132 int spk_handle_help(struct vc_data *vc, u_char type, u_char ch, u_short key)
0133 {
0134 int i, n;
0135 char *name;
0136 u_char func, *kp;
0137 u_short *p_keys, val;
0138
0139 if (letter_offsets[0] == -1)
0140 help_init();
0141 if (type == KT_LATIN) {
0142 if (ch == SPACE) {
0143 spk_special_handler = NULL;
0144 synth_printf("%s\n", spk_msg_get(MSG_LEAVING_HELP));
0145 return 1;
0146 }
0147 ch |= 32;
0148 if (ch < 'a' || ch > 'z')
0149 return -1;
0150 if (letter_offsets[ch - 'a'] == -1) {
0151 synth_printf(spk_msg_get(MSG_NO_COMMAND), ch);
0152 synth_printf("\n");
0153 return 1;
0154 }
0155 cur_item = letter_offsets[ch - 'a'];
0156 } else if (type == KT_CUR) {
0157 if (ch == 0 &&
0158 (MSG_FUNCNAMES_START + cur_item + 1) <= MSG_FUNCNAMES_END)
0159 cur_item++;
0160 else if (ch == 3 && cur_item > 0)
0161 cur_item--;
0162 else
0163 return -1;
0164 } else if (type == KT_SPKUP && ch == SPEAKUP_HELP &&
0165 !spk_special_handler) {
0166 spk_special_handler = spk_handle_help;
0167 synth_printf("%s\n", spk_msg_get(MSG_HELP_INFO));
0168 build_key_data();
0169 return 1;
0170 } else {
0171 name = NULL;
0172 if ((type != KT_SPKUP) && (key > 0) && (key <= num_key_names)) {
0173 synth_printf("%s\n",
0174 spk_msg_get(MSG_KEYNAMES_START + key - 1));
0175 return 1;
0176 }
0177 for (i = 0; funcvals[i] != 0 && !name; i++) {
0178 if (ch == funcvals[i])
0179 name = spk_msg_get(MSG_FUNCNAMES_START + i);
0180 }
0181 if (!name)
0182 return -1;
0183 kp = spk_our_keys[key] + 1;
0184 for (i = 0; i < nstates; i++) {
0185 if (ch == kp[i])
0186 break;
0187 }
0188 key += (state_tbl[i] << 8);
0189 say_key(key);
0190 synth_printf(spk_msg_get(MSG_KEYDESC), name);
0191 synth_printf("\n");
0192 return 1;
0193 }
0194 name = spk_msg_get(MSG_FUNCNAMES_START + cur_item);
0195 func = funcvals[cur_item];
0196 synth_printf("%s", name);
0197 if (key_offsets[func] == 0) {
0198 synth_printf(" %s\n", spk_msg_get(MSG_IS_UNASSIGNED));
0199 return 1;
0200 }
0201 p_keys = key_data + key_offsets[func];
0202 for (n = 0; p_keys[n]; n++) {
0203 val = p_keys[n];
0204 if (n > 0)
0205 synth_printf("%s ", spk_msg_get(MSG_DISJUNCTION));
0206 say_key(val);
0207 }
0208 return 1;
0209 }