1 #include <linux/ctype.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
, str_caps_start
, NULL
},
20 { "caps_stop", CAPS_STOP
, VAR_STRING
, 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
, &spell_delay
, NULL
},
26 { "bleeps", BLEEPS
, VAR_NUM
, &bleeps
, NULL
},
27 { "attrib_bleep", ATTRIB_BLEEP
, VAR_NUM
, &attrib_bleep
, NULL
},
28 { "bleep_time", BLEEP_TIME
, VAR_TIME
, &bleep_time
, NULL
},
29 { "cursor_time", CURSOR_TIME
, VAR_TIME
, NULL
, NULL
},
30 { "punc_level", PUNC_LEVEL
, VAR_NUM
, &punc_level
, NULL
},
31 { "reading_punc", READING_PUNC
, VAR_NUM
, &reading_punc
, NULL
},
32 { "say_control", SAY_CONTROL
, VAR_NUM
, &say_ctrl
, NULL
},
33 { "say_word_ctl", SAY_WORD_CTL
, VAR_NUM
, &say_word_ctl
, NULL
},
34 { "no_interrupt", NO_INTERRUPT
, VAR_NUM
, &no_intr
, NULL
},
35 { "key_echo", KEY_ECHO
, VAR_NUM
, &key_echo
, NULL
},
36 { "bell_pos", BELL_POS
, VAR_NUM
, &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
[] = {
61 int chartab_get_value(char *keyword
)
65 if (!strcmp(keyword
, "ALPHA"))
67 else if (!strcmp(keyword
, "B_CTL"))
69 else if (!strcmp(keyword
, "WDLM"))
71 else if (!strcmp(keyword
, "A_PUNC"))
73 else if (!strcmp(keyword
, "PUNC"))
75 else if (!strcmp(keyword
, "NUM"))
77 else if (!strcmp(keyword
, "A_CAP"))
79 else if (!strcmp(keyword
, "B_CAPSYM"))
81 else if (!strcmp(keyword
, "B_SYM"))
86 void speakup_register_var(struct var_t
*var
)
88 static char nothing
[2] = "\0";
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
)
103 p_header
->data
= var
;
104 switch (p_header
->var_type
) {
106 set_string_var(nothing
, p_header
, 0);
110 set_num_var(0, p_header
, E_DEFAULT
);
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
*get_var_header(enum var_id_t var_id
)
128 struct st_var_header
*p_header
;
129 if (var_id
< 0 || var_id
>= MAXVARS
)
131 p_header
= var_ptrs
[var_id
];
132 if (p_header
->data
== NULL
)
137 struct st_var_header
*var_header_by_name(const char *name
)
140 struct st_var_header
*where
= NULL
;
144 while ((i
< MAXVARS
) && (where
== NULL
)) {
145 if (strcmp(name
, var_ptrs
[i
]->name
) == 0)
154 struct var_t
*get_var(enum var_id_t var_id
)
156 BUG_ON(var_id
< 0 || var_id
>= MAXVARS
);
157 BUG_ON(!var_ptrs
[var_id
]);
158 return var_ptrs
[var_id
]->data
;
160 EXPORT_SYMBOL_GPL(get_var
);
162 struct punc_var_t
*get_punc_var(enum var_id_t var_id
)
164 struct punc_var_t
*rv
= NULL
;
165 struct punc_var_t
*where
;
168 while ((where
->var_id
!= -1) && (rv
== NULL
)) {
169 if (where
->var_id
== var_id
)
177 /* handlers for setting vars */
178 int set_num_var(int input
, struct st_var_header
*var
, int how
)
182 int *p_val
= var
->p_val
;
186 struct var_t
*var_data
= var
->data
;
187 if (var_data
== NULL
)
190 if (how
== E_NEW_DEFAULT
) {
191 if (input
< var_data
->u
.n
.low
|| input
> var_data
->u
.n
.high
)
194 var_data
->u
.n
.default_val
= input
;
197 if (how
== E_DEFAULT
) {
198 val
= var_data
->u
.n
.default_val
;
204 val
= var_data
->u
.n
.value
;
207 else if (how
== E_DEC
)
209 if (val
< var_data
->u
.n
.low
|| val
> var_data
->u
.n
.high
)
212 var_data
->u
.n
.value
= val
;
213 if (var
->var_type
== VAR_TIME
&& p_val
!= NULL
) {
214 *p_val
= msecs_to_jiffies(val
);
219 if (var
->var_id
== PUNC_LEVEL
) {
220 punc_mask
= punc_masks
[val
];
223 if (var_data
->u
.n
.multiplier
!= 0)
224 val
*= var_data
->u
.n
.multiplier
;
225 val
+= var_data
->u
.n
.offset
;
226 if (var
->var_id
< FIRST_SYNTH_VAR
|| synth
== NULL
)
228 if (synth
->synth_adjust
!= NULL
) {
229 int status
= synth
->synth_adjust(var
);
230 return (status
!= 0) ? status
: ret
;
232 if (!var_data
->u
.n
.synth_fmt
)
234 if (var
->var_id
== PITCH
)
238 if (!var_data
->u
.n
.out_str
)
239 l
= sprintf(cp
, var_data
->u
.n
.synth_fmt
, (int)val
);
242 var_data
->u
.n
.synth_fmt
, var_data
->u
.n
.out_str
[val
]);
243 synth_printf("%s", cp
);
247 int set_string_var(const char *page
, struct st_var_header
*var
, int len
)
250 struct var_t
*var_data
= var
->data
;
251 if (var_data
== NULL
)
256 if (!var_data
->u
.s
.default_val
)
260 var
->p_val
= var_data
->u
.s
.default_val
;
261 if (var
->p_val
!= var_data
->u
.s
.default_val
)
262 strcpy((char *)var
->p_val
, var_data
->u
.s
.default_val
);
263 } else if (var
->p_val
)
264 strcpy((char *)var
->p_val
, page
);
270 /* set_mask_bits sets or clears the punc/delim/repeat bits,
271 * if input is null uses the defaults.
272 * values for how: 0 clears bits of chars supplied,
273 * 1 clears allk, 2 sets bits for chars */
274 int set_mask_bits(const char *input
, const int which
, const int how
)
277 short mask
= punc_info
[which
].mask
;
279 for (cp
= (u_char
*)punc_info
[3].value
; *cp
; cp
++)
280 spk_chartab
[*cp
] &= ~mask
;
282 cp
= (u_char
*)input
;
284 cp
= punc_info
[which
].value
;
290 if (!(spk_chartab
[*cp
]&PUNC
))
292 } else if (spk_chartab
[*cp
]&B_NUM
)
297 cp
= (u_char
*)input
;
302 spk_chartab
[*cp
] |= mask
;
306 spk_chartab
[*cp
] &= ~mask
;
311 char *strlwr(char *s
)
322 char *speakup_s2i(char *start
, int *dest
)
326 if (ch
== '-' || ch
== '+')
328 if (*start
< '0' || *start
> '9')
330 val
= (*start
) - '0';
332 while (*start
>= '0' && *start
<= '9') {
334 val
+= (*start
) - '0';
344 char *s2uchar(char *start
, char *dest
)
347 while (*start
&& *start
<= SPACE
)
349 while (*start
>= '0' && *start
<= '9') {
351 val
+= (*start
) - '0';
362 static const char finds
[] = "nrtvafe";
363 static const char subs
[] = "\n\r\t\013\001\014\033";
364 static const char hx
[] = "0123456789abcdefABCDEF";
365 char *p
= s
, *p1
, *p2
, c
;
367 while ((p
= strchr(p
, '\\'))) {
369 p2
= strchr(finds
, *p1
);
371 *p
++ = subs
[p2
-finds
];
373 } else if (*p1
>= '0' && *p1
<= '7') {
375 while (num
< 256 && *p1
>= '0' && *p1
<= '7') {
380 } else if (*p1
== 'x' &&
381 strchr(hx
, p1
[1]) && strchr(hx
, p1
[2])) {
385 c
= (c
- '7') & 0x0f;