1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/ctype.h>
7 static struct st_var_header var_headers
[] = {
8 { "version", VERSION
, VAR_PROC
, NULL
, NULL
},
9 { "synth_name", SYNTH
, VAR_PROC
, NULL
, NULL
},
10 { "keymap", KEYMAP
, VAR_PROC
, NULL
, NULL
},
11 { "silent", SILENT
, VAR_PROC
, NULL
, NULL
},
12 { "punc_some", PUNC_SOME
, VAR_PROC
, NULL
, NULL
},
13 { "punc_most", PUNC_MOST
, VAR_PROC
, NULL
, NULL
},
14 { "punc_all", PUNC_ALL
, VAR_PROC
, NULL
, NULL
},
15 { "delimiters", DELIM
, VAR_PROC
, NULL
, NULL
},
16 { "repeats", REPEATS
, VAR_PROC
, NULL
, NULL
},
17 { "ex_num", EXNUMBER
, VAR_PROC
, NULL
, NULL
},
18 { "characters", CHARS
, VAR_PROC
, NULL
, NULL
},
19 { "synth_direct", SYNTH_DIRECT
, VAR_PROC
, NULL
, NULL
},
20 { "caps_start", CAPS_START
, VAR_STRING
, spk_str_caps_start
, NULL
},
21 { "caps_stop", CAPS_STOP
, VAR_STRING
, spk_str_caps_stop
, NULL
},
22 { "delay_time", DELAY
, VAR_TIME
, NULL
, NULL
},
23 { "trigger_time", TRIGGER
, VAR_TIME
, NULL
, NULL
},
24 { "jiffy_delta", JIFFY
, VAR_TIME
, NULL
, NULL
},
25 { "full_time", FULL
, VAR_TIME
, NULL
, NULL
},
26 { "spell_delay", SPELL_DELAY
, VAR_NUM
, &spk_spell_delay
, NULL
},
27 { "bleeps", BLEEPS
, VAR_NUM
, &spk_bleeps
, NULL
},
28 { "attrib_bleep", ATTRIB_BLEEP
, VAR_NUM
, &spk_attrib_bleep
, NULL
},
29 { "bleep_time", BLEEP_TIME
, VAR_TIME
, &spk_bleep_time
, NULL
},
30 { "cursor_time", CURSOR_TIME
, VAR_TIME
, NULL
, NULL
},
31 { "punc_level", PUNC_LEVEL
, VAR_NUM
, &spk_punc_level
, NULL
},
32 { "reading_punc", READING_PUNC
, VAR_NUM
, &spk_reading_punc
, NULL
},
33 { "say_control", SAY_CONTROL
, VAR_NUM
, &spk_say_ctrl
, NULL
},
34 { "say_word_ctl", SAY_WORD_CTL
, VAR_NUM
, &spk_say_word_ctl
, NULL
},
35 { "no_interrupt", NO_INTERRUPT
, VAR_NUM
, &spk_no_intr
, NULL
},
36 { "key_echo", KEY_ECHO
, VAR_NUM
, &spk_key_echo
, NULL
},
37 { "bell_pos", BELL_POS
, VAR_NUM
, &spk_bell_pos
, NULL
},
38 { "rate", RATE
, VAR_NUM
, NULL
, NULL
},
39 { "pitch", PITCH
, VAR_NUM
, NULL
, NULL
},
40 { "vol", VOL
, VAR_NUM
, NULL
, NULL
},
41 { "tone", TONE
, VAR_NUM
, NULL
, NULL
},
42 { "punct", PUNCT
, VAR_NUM
, NULL
, NULL
},
43 { "voice", VOICE
, VAR_NUM
, NULL
, NULL
},
44 { "freq", FREQUENCY
, VAR_NUM
, NULL
, NULL
},
45 { "lang", LANG
, VAR_NUM
, NULL
, NULL
},
46 { "chartab", CHARTAB
, VAR_PROC
, NULL
, NULL
},
47 { "direct", DIRECT
, VAR_NUM
, NULL
, NULL
},
50 static struct st_var_header
*var_ptrs
[MAXVARS
] = { NULL
, NULL
, NULL
};
52 static struct punc_var_t punc_vars
[] = {
62 int spk_chartab_get_value(char *keyword
)
66 if (!strcmp(keyword
, "ALPHA"))
68 else if (!strcmp(keyword
, "B_CTL"))
70 else if (!strcmp(keyword
, "WDLM"))
72 else if (!strcmp(keyword
, "A_PUNC"))
74 else if (!strcmp(keyword
, "PUNC"))
76 else if (!strcmp(keyword
, "NUM"))
78 else if (!strcmp(keyword
, "A_CAP"))
80 else if (!strcmp(keyword
, "B_CAPSYM"))
82 else if (!strcmp(keyword
, "B_SYM"))
87 void speakup_register_var(struct var_t
*var
)
89 static char nothing
[2] = "\0";
91 struct st_var_header
*p_header
;
93 BUG_ON(!var
|| var
->var_id
< 0 || var
->var_id
>= MAXVARS
);
95 for (i
= 0; i
< MAXVARS
; i
++) {
96 p_header
= &var_headers
[i
];
97 var_ptrs
[p_header
->var_id
] = p_header
;
98 p_header
->data
= NULL
;
101 p_header
= var_ptrs
[var
->var_id
];
104 p_header
->data
= var
;
105 switch (p_header
->var_type
) {
107 spk_set_string_var(nothing
, p_header
, 0);
111 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
;
122 BUG_ON(var_id
< 0 || var_id
>= MAXVARS
);
123 p_header
= var_ptrs
[var_id
];
124 p_header
->data
= NULL
;
127 struct st_var_header
*spk_get_var_header(enum var_id_t var_id
)
129 struct st_var_header
*p_header
;
131 if (var_id
< 0 || var_id
>= MAXVARS
)
133 p_header
= var_ptrs
[var_id
];
139 struct st_var_header
*spk_var_header_by_name(const char *name
)
146 for (i
= 0; i
< MAXVARS
; i
++) {
147 if (strcmp(name
, var_ptrs
[i
]->name
) == 0)
153 struct var_t
*spk_get_var(enum var_id_t var_id
)
155 BUG_ON(var_id
< 0 || var_id
>= MAXVARS
);
156 BUG_ON(!var_ptrs
[var_id
]);
157 return var_ptrs
[var_id
]->data
;
159 EXPORT_SYMBOL_GPL(spk_get_var
);
161 struct punc_var_t
*spk_get_punc_var(enum var_id_t var_id
)
163 struct punc_var_t
*rv
= NULL
;
164 struct punc_var_t
*where
;
167 while ((where
->var_id
!= -1) && (!rv
)) {
168 if (where
->var_id
== var_id
)
176 /* handlers for setting vars */
177 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
;
189 val
= var_data
->u
.n
.value
;
192 if (input
< var_data
->u
.n
.low
|| input
> var_data
->u
.n
.high
)
194 var_data
->u
.n
.default_val
= input
;
197 val
= var_data
->u
.n
.default_val
;
210 if (val
< var_data
->u
.n
.low
|| val
> var_data
->u
.n
.high
)
213 var_data
->u
.n
.value
= val
;
214 if (var
->var_type
== VAR_TIME
&& p_val
) {
215 *p_val
= msecs_to_jiffies(val
);
220 if (var
->var_id
== PUNC_LEVEL
) {
221 spk_punc_mask
= spk_punc_masks
[val
];
224 if (var_data
->u
.n
.multiplier
!= 0)
225 val
*= var_data
->u
.n
.multiplier
;
226 val
+= var_data
->u
.n
.offset
;
227 if (var
->var_id
< FIRST_SYNTH_VAR
|| !synth
)
229 if (synth
->synth_adjust
)
230 return synth
->synth_adjust(var
);
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
);
241 l
= sprintf(cp
, 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
;
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
);
271 * spk_set_mask_bits sets or clears the punc/delim/repeat bits,
272 * if input is null uses the defaults.
273 * values for how: 0 clears bits of chars supplied,
274 * 1 clears allk, 2 sets bits for chars
276 int spk_set_mask_bits(const char *input
, const int which
, const int how
)
279 short mask
= spk_punc_info
[which
].mask
;
282 for (cp
= (u_char
*)spk_punc_info
[3].value
; *cp
; cp
++)
283 spk_chartab
[*cp
] &= ~mask
;
285 cp
= (u_char
*)input
;
287 cp
= spk_punc_info
[which
].value
;
293 if (!(spk_chartab
[*cp
] & PUNC
))
295 } else if (spk_chartab
[*cp
] & B_NUM
) {
301 cp
= (u_char
*)input
;
306 spk_chartab
[*cp
] |= mask
;
310 spk_chartab
[*cp
] &= ~mask
;
315 char *spk_strlwr(char *s
)
327 char *spk_s2uchar(char *start
, char *dest
)
331 val
= simple_strtoul(skip_spaces(start
), &start
, 10);