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
, 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
] = { NULL
, NULL
, NULL
};
51 static struct punc_var_t punc_vars
[] = {
61 int spk_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 spk_set_string_var(nothing
, p_header
, 0);
110 spk_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
*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
)
131 p_header
= var_ptrs
[var_id
];
132 if (p_header
->data
== NULL
)
137 struct st_var_header
*spk_var_header_by_name(const char *name
)
144 for (i
= 0; i
< MAXVARS
; i
++) {
145 if (strcmp(name
, var_ptrs
[i
]->name
) == 0)
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
;
165 while ((where
->var_id
!= -1) && (rv
== NULL
)) {
166 if (where
->var_id
== var_id
)
174 /* handlers for setting vars */
175 int spk_set_num_var(int input
, struct st_var_header
*var
, int how
)
179 int *p_val
= var
->p_val
;
183 struct var_t
*var_data
= var
->data
;
185 if (var_data
== NULL
)
188 if (how
== E_NEW_DEFAULT
) {
189 if (input
< var_data
->u
.n
.low
|| input
> var_data
->u
.n
.high
)
191 var_data
->u
.n
.default_val
= input
;
194 if (how
== E_DEFAULT
) {
195 val
= var_data
->u
.n
.default_val
;
201 val
= var_data
->u
.n
.value
;
204 else if (how
== E_DEC
)
206 if (val
< var_data
->u
.n
.low
|| val
> var_data
->u
.n
.high
)
209 var_data
->u
.n
.value
= val
;
210 if (var
->var_type
== VAR_TIME
&& p_val
!= NULL
) {
211 *p_val
= msecs_to_jiffies(val
);
216 if (var
->var_id
== PUNC_LEVEL
) {
217 spk_punc_mask
= spk_punc_masks
[val
];
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
)
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
)
231 if (var
->var_id
== PITCH
)
235 if (!var_data
->u
.n
.out_str
)
236 l
= sprintf(cp
, var_data
->u
.n
.synth_fmt
, (int)val
);
239 var_data
->u
.n
.synth_fmt
, var_data
->u
.n
.out_str
[val
]);
240 synth_printf("%s", cp
);
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
)
253 if (!var_data
->u
.s
.default_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
);
260 } else if (var
->p_val
)
261 strcpy((char *)var
->p_val
, page
);
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
)
274 short mask
= spk_punc_info
[which
].mask
;
276 for (cp
= (u_char
*)spk_punc_info
[3].value
; *cp
; cp
++)
277 spk_chartab
[*cp
] &= ~mask
;
279 cp
= (u_char
*)input
;
281 cp
= spk_punc_info
[which
].value
;
287 if (!(spk_chartab
[*cp
]&PUNC
))
289 } else if (spk_chartab
[*cp
]&B_NUM
)
294 cp
= (u_char
*)input
;
299 spk_chartab
[*cp
] |= mask
;
303 spk_chartab
[*cp
] &= ~mask
;
308 char *spk_strlwr(char *s
)
319 char *spk_s2uchar(char *start
, char *dest
)
322 val
= simple_strtoul(skip_spaces(start
), &start
, 10);