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
);
117 void speakup_unregister_var(enum var_id_t var_id
)
119 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
;
130 if (var_id
< 0 || var_id
>= MAXVARS
)
132 p_header
= var_ptrs
[var_id
];
133 if (p_header
->data
== NULL
)
138 struct st_var_header
*spk_var_header_by_name(const char *name
)
145 for (i
= 0; i
< MAXVARS
; i
++) {
146 if (strcmp(name
, var_ptrs
[i
]->name
) == 0)
152 struct var_t
*spk_get_var(enum var_id_t var_id
)
154 BUG_ON(var_id
< 0 || var_id
>= MAXVARS
);
155 BUG_ON(!var_ptrs
[var_id
]);
156 return var_ptrs
[var_id
]->data
;
158 EXPORT_SYMBOL_GPL(spk_get_var
);
160 struct punc_var_t
*spk_get_punc_var(enum var_id_t var_id
)
162 struct punc_var_t
*rv
= NULL
;
163 struct punc_var_t
*where
;
166 while ((where
->var_id
!= -1) && (rv
== NULL
)) {
167 if (where
->var_id
== var_id
)
175 /* handlers for setting vars */
176 int spk_set_num_var(int input
, struct st_var_header
*var
, int how
)
180 int *p_val
= var
->p_val
;
184 struct var_t
*var_data
= var
->data
;
186 if (var_data
== NULL
)
189 if (how
== E_NEW_DEFAULT
) {
190 if (input
< var_data
->u
.n
.low
|| input
> var_data
->u
.n
.high
)
192 var_data
->u
.n
.default_val
= input
;
195 if (how
== E_DEFAULT
) {
196 val
= var_data
->u
.n
.default_val
;
202 val
= var_data
->u
.n
.value
;
205 else if (how
== E_DEC
)
207 if (val
< var_data
->u
.n
.low
|| val
> var_data
->u
.n
.high
)
210 var_data
->u
.n
.value
= val
;
211 if (var
->var_type
== VAR_TIME
&& p_val
!= NULL
) {
212 *p_val
= msecs_to_jiffies(val
);
217 if (var
->var_id
== PUNC_LEVEL
) {
218 spk_punc_mask
= spk_punc_masks
[val
];
221 if (var_data
->u
.n
.multiplier
!= 0)
222 val
*= var_data
->u
.n
.multiplier
;
223 val
+= var_data
->u
.n
.offset
;
224 if (var
->var_id
< FIRST_SYNTH_VAR
|| synth
== NULL
)
226 if (synth
->synth_adjust
!= NULL
) {
227 int status
= synth
->synth_adjust(var
);
229 return (status
!= 0) ? status
: ret
;
231 if (!var_data
->u
.n
.synth_fmt
)
233 if (var
->var_id
== PITCH
)
237 if (!var_data
->u
.n
.out_str
)
238 l
= sprintf(cp
, var_data
->u
.n
.synth_fmt
, (int)val
);
241 var_data
->u
.n
.synth_fmt
, var_data
->u
.n
.out_str
[val
]);
242 synth_printf("%s", cp
);
246 int spk_set_string_var(const char *page
, struct st_var_header
*var
, int len
)
248 struct var_t
*var_data
= var
->data
;
250 if (var_data
== NULL
)
255 if (!var_data
->u
.s
.default_val
)
258 var
->p_val
= var_data
->u
.s
.default_val
;
259 if (var
->p_val
!= var_data
->u
.s
.default_val
)
260 strcpy((char *)var
->p_val
, var_data
->u
.s
.default_val
);
262 } else if (var
->p_val
)
263 strcpy((char *)var
->p_val
, page
);
269 /* spk_set_mask_bits sets or clears the punc/delim/repeat bits,
270 * if input is null uses the defaults.
271 * values for how: 0 clears bits of chars supplied,
272 * 1 clears allk, 2 sets bits for chars */
273 int spk_set_mask_bits(const char *input
, const int which
, const int how
)
276 short mask
= spk_punc_info
[which
].mask
;
279 for (cp
= (u_char
*)spk_punc_info
[3].value
; *cp
; cp
++)
280 spk_chartab
[*cp
] &= ~mask
;
282 cp
= (u_char
*)input
;
284 cp
= spk_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 *spk_strlwr(char *s
)
323 char *spk_s2uchar(char *start
, char *dest
)
327 val
= simple_strtoul(skip_spaces(start
), &start
, 10);