mfd: wm8350-i2c: Make sure the i2c regmap functions are compiled
[linux/fpc-iii.git] / drivers / staging / speakup / varhandlers.c
blob9aa2a78cd71cd87dfad5785a9fab9d2f26e497e2
1 #include <linux/ctype.h>
2 #include "spk_types.h"
3 #include "spk_priv.h"
4 #include "speakup.h"
6 static struct st_var_header var_headers[] = {
7 { "version", VERSION, VAR_PROC, NULL, NULL },
8 { "synth_name", SYNTH, VAR_PROC, NULL, NULL },
9 { "keymap", KEYMAP, VAR_PROC, NULL, NULL },
10 { "silent", SILENT, VAR_PROC, NULL, NULL },
11 { "punc_some", PUNC_SOME, VAR_PROC, NULL, NULL },
12 { "punc_most", PUNC_MOST, VAR_PROC, NULL, NULL },
13 { "punc_all", PUNC_ALL, VAR_PROC, NULL, NULL },
14 { "delimiters", DELIM, VAR_PROC, NULL, NULL },
15 { "repeats", REPEATS, VAR_PROC, NULL, NULL },
16 { "ex_num", EXNUMBER, VAR_PROC, NULL, NULL },
17 { "characters", CHARS, VAR_PROC, NULL, NULL },
18 { "synth_direct", SYNTH_DIRECT, VAR_PROC, NULL, NULL },
19 { "caps_start", CAPS_START, VAR_STRING, spk_str_caps_start, NULL },
20 { "caps_stop", CAPS_STOP, VAR_STRING, spk_str_caps_stop, NULL },
21 { "delay_time", DELAY, VAR_TIME, NULL, NULL },
22 { "trigger_time", TRIGGER, VAR_TIME, NULL, NULL },
23 { "jiffy_delta", JIFFY, VAR_TIME, NULL, NULL },
24 { "full_time", FULL, VAR_TIME, NULL, NULL },
25 { "spell_delay", SPELL_DELAY, VAR_NUM, &spk_spell_delay, NULL },
26 { "bleeps", BLEEPS, VAR_NUM, &spk_bleeps, NULL },
27 { "attrib_bleep", ATTRIB_BLEEP, VAR_NUM, &spk_attrib_bleep, NULL },
28 { "bleep_time", BLEEP_TIME, VAR_TIME, &spk_bleep_time, NULL },
29 { "cursor_time", CURSOR_TIME, VAR_TIME, NULL, NULL },
30 { "punc_level", PUNC_LEVEL, VAR_NUM, &spk_punc_level, NULL },
31 { "reading_punc", READING_PUNC, VAR_NUM, &spk_reading_punc, NULL },
32 { "say_control", SAY_CONTROL, VAR_NUM, &spk_say_ctrl, NULL },
33 { "say_word_ctl", SAY_WORD_CTL, VAR_NUM, &spk_say_word_ctl, NULL },
34 { "no_interrupt", NO_INTERRUPT, VAR_NUM, &spk_no_intr, NULL },
35 { "key_echo", KEY_ECHO, VAR_NUM, &spk_key_echo, NULL },
36 { "bell_pos", BELL_POS, VAR_NUM, &spk_bell_pos, NULL },
37 { "rate", RATE, VAR_NUM, NULL, NULL },
38 { "pitch", PITCH, VAR_NUM, NULL, NULL },
39 { "vol", VOL, VAR_NUM, NULL, NULL },
40 { "tone", TONE, VAR_NUM, NULL, NULL },
41 { "punct", PUNCT, VAR_NUM, NULL, NULL },
42 { "voice", VOICE, VAR_NUM, NULL, NULL },
43 { "freq", FREQUENCY, VAR_NUM, NULL, NULL },
44 { "lang", LANG, VAR_NUM, NULL, NULL },
45 { "chartab", CHARTAB, VAR_PROC, NULL, NULL },
46 { "direct", DIRECT, VAR_NUM, NULL, NULL },
49 static struct st_var_header *var_ptrs[MAXVARS] = { 0, 0, 0 };
51 static struct punc_var_t punc_vars[] = {
52 { PUNC_SOME, 1 },
53 { PUNC_MOST, 2 },
54 { PUNC_ALL, 3 },
55 { DELIM, 4 },
56 { REPEATS, 5 },
57 { EXNUMBER, 6 },
58 { -1, -1 },
61 int spk_chartab_get_value(char *keyword)
63 int value = 0;
65 if (!strcmp(keyword, "ALPHA"))
66 value = ALPHA;
67 else if (!strcmp(keyword, "B_CTL"))
68 value = B_CTL;
69 else if (!strcmp(keyword, "WDLM"))
70 value = WDLM;
71 else if (!strcmp(keyword, "A_PUNC"))
72 value = A_PUNC;
73 else if (!strcmp(keyword, "PUNC"))
74 value = PUNC;
75 else if (!strcmp(keyword, "NUM"))
76 value = NUM;
77 else if (!strcmp(keyword, "A_CAP"))
78 value = A_CAP;
79 else if (!strcmp(keyword, "B_CAPSYM"))
80 value = B_CAPSYM;
81 else if (!strcmp(keyword, "B_SYM"))
82 value = B_SYM;
83 return value;
86 void speakup_register_var(struct var_t *var)
88 static char nothing[2] = "\0";
89 int i;
90 struct st_var_header *p_header;
92 BUG_ON(!var || var->var_id < 0 || var->var_id >= MAXVARS);
93 if (var_ptrs[0] == NULL) {
94 for (i = 0; i < MAXVARS; i++) {
95 p_header = &var_headers[i];
96 var_ptrs[p_header->var_id] = p_header;
97 p_header->data = NULL;
100 p_header = var_ptrs[var->var_id];
101 if (p_header->data != NULL)
102 return;
103 p_header->data = var;
104 switch (p_header->var_type) {
105 case VAR_STRING:
106 spk_set_string_var(nothing, p_header, 0);
107 break;
108 case VAR_NUM:
109 case VAR_TIME:
110 spk_set_num_var(0, p_header, E_DEFAULT);
111 break;
112 default:
113 break;
115 return;
118 void speakup_unregister_var(enum var_id_t var_id)
120 struct st_var_header *p_header;
121 BUG_ON(var_id < 0 || var_id >= MAXVARS);
122 p_header = var_ptrs[var_id];
123 p_header->data = NULL;
126 struct st_var_header *spk_get_var_header(enum var_id_t var_id)
128 struct st_var_header *p_header;
129 if (var_id < 0 || var_id >= MAXVARS)
130 return NULL;
131 p_header = var_ptrs[var_id];
132 if (p_header->data == NULL)
133 return NULL;
134 return p_header;
137 struct st_var_header *spk_var_header_by_name(const char *name)
139 int i;
141 if (!name)
142 return NULL;
144 for (i = 0; i < MAXVARS; i++) {
145 if (strcmp(name, var_ptrs[i]->name) == 0)
146 return var_ptrs[i];
148 return NULL;
151 struct var_t *spk_get_var(enum var_id_t var_id)
153 BUG_ON(var_id < 0 || var_id >= MAXVARS);
154 BUG_ON(!var_ptrs[var_id]);
155 return var_ptrs[var_id]->data;
157 EXPORT_SYMBOL_GPL(spk_get_var);
159 struct punc_var_t *spk_get_punc_var(enum var_id_t var_id)
161 struct punc_var_t *rv = NULL;
162 struct punc_var_t *where;
164 where = punc_vars;
165 while ((where->var_id != -1) && (rv == NULL)) {
166 if (where->var_id == var_id)
167 rv = where;
168 else
169 where++;
171 return rv;
174 /* handlers for setting vars */
175 int spk_set_num_var(int input, struct st_var_header *var, int how)
177 int val;
178 short ret = 0;
179 int *p_val = var->p_val;
180 int l;
181 char buf[32];
182 char *cp;
183 struct var_t *var_data = var->data;
185 if (var_data == NULL)
186 return -ENODATA;
188 if (how == E_NEW_DEFAULT) {
189 if (input < var_data->u.n.low || input > var_data->u.n.high)
190 return -ERANGE;
191 var_data->u.n.default_val = input;
192 return 0;
194 if (how == E_DEFAULT) {
195 val = var_data->u.n.default_val;
196 ret = -ERESTART;
197 } else {
198 if (how == E_SET)
199 val = input;
200 else
201 val = var_data->u.n.value;
202 if (how == E_INC)
203 val += input;
204 else if (how == E_DEC)
205 val -= input;
206 if (val < var_data->u.n.low || val > var_data->u.n.high)
207 return -ERANGE;
209 var_data->u.n.value = val;
210 if (var->var_type == VAR_TIME && p_val != NULL) {
211 *p_val = msecs_to_jiffies(val);
212 return ret;
214 if (p_val != NULL)
215 *p_val = val;
216 if (var->var_id == PUNC_LEVEL) {
217 spk_punc_mask = spk_punc_masks[val];
218 return ret;
220 if (var_data->u.n.multiplier != 0)
221 val *= var_data->u.n.multiplier;
222 val += var_data->u.n.offset;
223 if (var->var_id < FIRST_SYNTH_VAR || synth == NULL)
224 return ret;
225 if (synth->synth_adjust != NULL) {
226 int status = synth->synth_adjust(var);
227 return (status != 0) ? status : ret;
229 if (!var_data->u.n.synth_fmt)
230 return ret;
231 if (var->var_id == PITCH)
232 cp = spk_pitch_buff;
233 else
234 cp = buf;
235 if (!var_data->u.n.out_str)
236 l = sprintf(cp, var_data->u.n.synth_fmt, (int)val);
237 else
238 l = sprintf(cp,
239 var_data->u.n.synth_fmt, var_data->u.n.out_str[val]);
240 synth_printf("%s", cp);
241 return ret;
244 int spk_set_string_var(const char *page, struct st_var_header *var, int len)
246 struct var_t *var_data = var->data;
248 if (var_data == NULL)
249 return -ENODATA;
250 if (len > MAXVARLEN)
251 return -E2BIG;
252 if (!len) {
253 if (!var_data->u.s.default_val)
254 return 0;
255 if (!var->p_val)
256 var->p_val = var_data->u.s.default_val;
257 if (var->p_val != var_data->u.s.default_val)
258 strcpy((char *)var->p_val, var_data->u.s.default_val);
259 return -ERESTART;
260 } else if (var->p_val)
261 strcpy((char *)var->p_val, page);
262 else
263 return -E2BIG;
264 return 0;
267 /* spk_set_mask_bits sets or clears the punc/delim/repeat bits,
268 * if input is null uses the defaults.
269 * values for how: 0 clears bits of chars supplied,
270 * 1 clears allk, 2 sets bits for chars */
271 int spk_set_mask_bits(const char *input, const int which, const int how)
273 u_char *cp;
274 short mask = spk_punc_info[which].mask;
275 if (how&1) {
276 for (cp = (u_char *)spk_punc_info[3].value; *cp; cp++)
277 spk_chartab[*cp] &= ~mask;
279 cp = (u_char *)input;
280 if (!cp)
281 cp = spk_punc_info[which].value;
282 else {
283 for ( ; *cp; cp++) {
284 if (*cp < SPACE)
285 break;
286 if (mask < PUNC) {
287 if (!(spk_chartab[*cp]&PUNC))
288 break;
289 } else if (spk_chartab[*cp]&B_NUM)
290 break;
292 if (*cp)
293 return -EINVAL;
294 cp = (u_char *)input;
296 if (how&2) {
297 for ( ; *cp; cp++)
298 if (*cp > SPACE)
299 spk_chartab[*cp] |= mask;
300 } else {
301 for ( ; *cp; cp++)
302 if (*cp > SPACE)
303 spk_chartab[*cp] &= ~mask;
305 return 0;
308 char *spk_strlwr(char *s)
310 char *p;
311 if (s == NULL)
312 return NULL;
314 for (p = s; *p; p++)
315 *p = tolower(*p);
316 return s;
319 char *spk_s2uchar(char *start, char *dest)
321 int val = 0;
322 val = simple_strtoul(skip_spaces(start), &start, 10);
323 if (*start == ',')
324 start++;
325 *dest = (u_char)val;
326 return start;