2010-10-07 18:20:02 +00:00
|
|
|
#include <linux/ctype.h>
|
|
|
|
#include "spk_types.h"
|
|
|
|
#include "spk_priv.h"
|
|
|
|
#include "speakup.h"
|
|
|
|
|
|
|
|
static struct st_var_header var_headers[] = {
|
2010-10-16 03:13:39 +00:00
|
|
|
{ "version", VERSION, VAR_PROC, NULL, NULL },
|
|
|
|
{ "synth_name", SYNTH, VAR_PROC, NULL, NULL },
|
|
|
|
{ "keymap", KEYMAP, VAR_PROC, NULL, NULL },
|
|
|
|
{ "silent", SILENT, VAR_PROC, NULL, NULL },
|
|
|
|
{ "punc_some", PUNC_SOME, VAR_PROC, NULL, NULL },
|
|
|
|
{ "punc_most", PUNC_MOST, VAR_PROC, NULL, NULL },
|
|
|
|
{ "punc_all", PUNC_ALL, VAR_PROC, NULL, NULL },
|
|
|
|
{ "delimiters", DELIM, VAR_PROC, NULL, NULL },
|
|
|
|
{ "repeats", REPEATS, VAR_PROC, NULL, NULL },
|
|
|
|
{ "ex_num", EXNUMBER, VAR_PROC, NULL, NULL },
|
|
|
|
{ "characters", CHARS, VAR_PROC, NULL, NULL },
|
|
|
|
{ "synth_direct", SYNTH_DIRECT, VAR_PROC, NULL, NULL },
|
2013-01-02 01:37:40 +00:00
|
|
|
{ "caps_start", CAPS_START, VAR_STRING, spk_str_caps_start, NULL },
|
|
|
|
{ "caps_stop", CAPS_STOP, VAR_STRING, spk_str_caps_stop, NULL },
|
2010-10-16 03:13:39 +00:00
|
|
|
{ "delay_time", DELAY, VAR_TIME, NULL, NULL },
|
|
|
|
{ "trigger_time", TRIGGER, VAR_TIME, NULL, NULL },
|
|
|
|
{ "jiffy_delta", JIFFY, VAR_TIME, NULL, NULL },
|
|
|
|
{ "full_time", FULL, VAR_TIME, NULL, NULL },
|
2013-01-02 01:37:40 +00:00
|
|
|
{ "spell_delay", SPELL_DELAY, VAR_NUM, &spk_spell_delay, NULL },
|
|
|
|
{ "bleeps", BLEEPS, VAR_NUM, &spk_bleeps, NULL },
|
|
|
|
{ "attrib_bleep", ATTRIB_BLEEP, VAR_NUM, &spk_attrib_bleep, NULL },
|
|
|
|
{ "bleep_time", BLEEP_TIME, VAR_TIME, &spk_bleep_time, NULL },
|
2010-10-16 03:13:39 +00:00
|
|
|
{ "cursor_time", CURSOR_TIME, VAR_TIME, NULL, NULL },
|
2013-01-02 01:37:40 +00:00
|
|
|
{ "punc_level", PUNC_LEVEL, VAR_NUM, &spk_punc_level, NULL },
|
|
|
|
{ "reading_punc", READING_PUNC, VAR_NUM, &spk_reading_punc, NULL },
|
|
|
|
{ "say_control", SAY_CONTROL, VAR_NUM, &spk_say_ctrl, NULL },
|
|
|
|
{ "say_word_ctl", SAY_WORD_CTL, VAR_NUM, &spk_say_word_ctl, NULL },
|
|
|
|
{ "no_interrupt", NO_INTERRUPT, VAR_NUM, &spk_no_intr, NULL },
|
|
|
|
{ "key_echo", KEY_ECHO, VAR_NUM, &spk_key_echo, NULL },
|
|
|
|
{ "bell_pos", BELL_POS, VAR_NUM, &spk_bell_pos, NULL },
|
2010-10-16 03:13:39 +00:00
|
|
|
{ "rate", RATE, VAR_NUM, NULL, NULL },
|
|
|
|
{ "pitch", PITCH, VAR_NUM, NULL, NULL },
|
|
|
|
{ "vol", VOL, VAR_NUM, NULL, NULL },
|
|
|
|
{ "tone", TONE, VAR_NUM, NULL, NULL },
|
|
|
|
{ "punct", PUNCT, VAR_NUM, NULL, NULL },
|
|
|
|
{ "voice", VOICE, VAR_NUM, NULL, NULL },
|
|
|
|
{ "freq", FREQUENCY, VAR_NUM, NULL, NULL },
|
|
|
|
{ "lang", LANG, VAR_NUM, NULL, NULL },
|
|
|
|
{ "chartab", CHARTAB, VAR_PROC, NULL, NULL },
|
|
|
|
{ "direct", DIRECT, VAR_NUM, NULL, NULL },
|
2010-10-07 18:20:02 +00:00
|
|
|
};
|
|
|
|
|
2013-10-03 08:08:42 +00:00
|
|
|
static struct st_var_header *var_ptrs[MAXVARS] = { NULL, NULL, NULL };
|
2010-10-07 18:20:02 +00:00
|
|
|
|
|
|
|
static struct punc_var_t punc_vars[] = {
|
2010-10-16 03:13:39 +00:00
|
|
|
{ PUNC_SOME, 1 },
|
|
|
|
{ PUNC_MOST, 2 },
|
|
|
|
{ PUNC_ALL, 3 },
|
|
|
|
{ DELIM, 4 },
|
|
|
|
{ REPEATS, 5 },
|
|
|
|
{ EXNUMBER, 6 },
|
|
|
|
{ -1, -1 },
|
2010-10-07 18:20:02 +00:00
|
|
|
};
|
|
|
|
|
2013-01-02 01:37:40 +00:00
|
|
|
int spk_chartab_get_value(char *keyword)
|
2010-10-07 18:20:02 +00:00
|
|
|
{
|
|
|
|
int value = 0;
|
|
|
|
|
|
|
|
if (!strcmp(keyword, "ALPHA"))
|
|
|
|
value = ALPHA;
|
|
|
|
else if (!strcmp(keyword, "B_CTL"))
|
|
|
|
value = B_CTL;
|
|
|
|
else if (!strcmp(keyword, "WDLM"))
|
|
|
|
value = WDLM;
|
|
|
|
else if (!strcmp(keyword, "A_PUNC"))
|
|
|
|
value = A_PUNC;
|
|
|
|
else if (!strcmp(keyword, "PUNC"))
|
|
|
|
value = PUNC;
|
|
|
|
else if (!strcmp(keyword, "NUM"))
|
|
|
|
value = NUM;
|
|
|
|
else if (!strcmp(keyword, "A_CAP"))
|
|
|
|
value = A_CAP;
|
|
|
|
else if (!strcmp(keyword, "B_CAPSYM"))
|
|
|
|
value = B_CAPSYM;
|
|
|
|
else if (!strcmp(keyword, "B_SYM"))
|
|
|
|
value = B_SYM;
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void speakup_register_var(struct var_t *var)
|
|
|
|
{
|
|
|
|
static char nothing[2] = "\0";
|
|
|
|
int i;
|
|
|
|
struct st_var_header *p_header;
|
|
|
|
|
|
|
|
BUG_ON(!var || var->var_id < 0 || var->var_id >= MAXVARS);
|
|
|
|
if (var_ptrs[0] == NULL) {
|
|
|
|
for (i = 0; i < MAXVARS; i++) {
|
|
|
|
p_header = &var_headers[i];
|
|
|
|
var_ptrs[p_header->var_id] = p_header;
|
|
|
|
p_header->data = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p_header = var_ptrs[var->var_id];
|
|
|
|
if (p_header->data != NULL)
|
|
|
|
return;
|
|
|
|
p_header->data = var;
|
|
|
|
switch (p_header->var_type) {
|
|
|
|
case VAR_STRING:
|
2013-01-02 01:37:40 +00:00
|
|
|
spk_set_string_var(nothing, p_header, 0);
|
2010-10-07 18:20:02 +00:00
|
|
|
break;
|
|
|
|
case VAR_NUM:
|
|
|
|
case VAR_TIME:
|
2013-01-02 01:37:40 +00:00
|
|
|
spk_set_num_var(0, p_header, E_DEFAULT);
|
2010-10-07 18:20:02 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void speakup_unregister_var(enum var_id_t var_id)
|
|
|
|
{
|
|
|
|
struct st_var_header *p_header;
|
2014-09-09 18:04:34 +00:00
|
|
|
|
2010-10-07 18:20:02 +00:00
|
|
|
BUG_ON(var_id < 0 || var_id >= MAXVARS);
|
|
|
|
p_header = var_ptrs[var_id];
|
|
|
|
p_header->data = NULL;
|
|
|
|
}
|
|
|
|
|
2013-01-02 01:37:40 +00:00
|
|
|
struct st_var_header *spk_get_var_header(enum var_id_t var_id)
|
2010-10-07 18:20:02 +00:00
|
|
|
{
|
|
|
|
struct st_var_header *p_header;
|
2014-09-09 18:04:34 +00:00
|
|
|
|
2010-10-07 18:20:02 +00:00
|
|
|
if (var_id < 0 || var_id >= MAXVARS)
|
|
|
|
return NULL;
|
|
|
|
p_header = var_ptrs[var_id];
|
|
|
|
if (p_header->data == NULL)
|
|
|
|
return NULL;
|
|
|
|
return p_header;
|
|
|
|
}
|
|
|
|
|
2013-01-02 01:37:40 +00:00
|
|
|
struct st_var_header *spk_var_header_by_name(const char *name)
|
2010-10-07 18:20:02 +00:00
|
|
|
{
|
|
|
|
int i;
|
2013-05-09 18:31:59 +00:00
|
|
|
|
|
|
|
if (!name)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < MAXVARS; i++) {
|
|
|
|
if (strcmp(name, var_ptrs[i]->name) == 0)
|
|
|
|
return var_ptrs[i];
|
2010-10-07 18:20:02 +00:00
|
|
|
}
|
2013-05-09 18:31:59 +00:00
|
|
|
return NULL;
|
2010-10-07 18:20:02 +00:00
|
|
|
}
|
|
|
|
|
2013-01-02 01:37:40 +00:00
|
|
|
struct var_t *spk_get_var(enum var_id_t var_id)
|
2010-10-07 18:20:02 +00:00
|
|
|
{
|
|
|
|
BUG_ON(var_id < 0 || var_id >= MAXVARS);
|
2010-10-16 03:13:39 +00:00
|
|
|
BUG_ON(!var_ptrs[var_id]);
|
|
|
|
return var_ptrs[var_id]->data;
|
2010-10-07 18:20:02 +00:00
|
|
|
}
|
2013-01-02 01:37:40 +00:00
|
|
|
EXPORT_SYMBOL_GPL(spk_get_var);
|
2010-10-07 18:20:02 +00:00
|
|
|
|
2013-01-02 01:37:40 +00:00
|
|
|
struct punc_var_t *spk_get_punc_var(enum var_id_t var_id)
|
2010-10-07 18:20:02 +00:00
|
|
|
{
|
|
|
|
struct punc_var_t *rv = NULL;
|
|
|
|
struct punc_var_t *where;
|
|
|
|
|
|
|
|
where = punc_vars;
|
|
|
|
while ((where->var_id != -1) && (rv == NULL)) {
|
|
|
|
if (where->var_id == var_id)
|
|
|
|
rv = where;
|
|
|
|
else
|
|
|
|
where++;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handlers for setting vars */
|
2013-01-02 01:37:40 +00:00
|
|
|
int spk_set_num_var(int input, struct st_var_header *var, int how)
|
2010-10-07 18:20:02 +00:00
|
|
|
{
|
|
|
|
int val;
|
|
|
|
short ret = 0;
|
|
|
|
int *p_val = var->p_val;
|
|
|
|
int l;
|
|
|
|
char buf[32];
|
|
|
|
char *cp;
|
|
|
|
struct var_t *var_data = var->data;
|
2013-03-28 09:02:44 +00:00
|
|
|
|
2010-10-07 18:20:02 +00:00
|
|
|
if (var_data == NULL)
|
2013-03-28 09:02:44 +00:00
|
|
|
return -ENODATA;
|
2010-10-07 18:20:02 +00:00
|
|
|
|
|
|
|
if (how == E_NEW_DEFAULT) {
|
|
|
|
if (input < var_data->u.n.low || input > var_data->u.n.high)
|
2013-03-28 09:02:44 +00:00
|
|
|
return -ERANGE;
|
|
|
|
var_data->u.n.default_val = input;
|
|
|
|
return 0;
|
2010-10-07 18:20:02 +00:00
|
|
|
}
|
|
|
|
if (how == E_DEFAULT) {
|
|
|
|
val = var_data->u.n.default_val;
|
2013-03-28 09:02:44 +00:00
|
|
|
ret = -ERESTART;
|
2010-10-07 18:20:02 +00:00
|
|
|
} else {
|
|
|
|
if (how == E_SET)
|
|
|
|
val = input;
|
|
|
|
else
|
|
|
|
val = var_data->u.n.value;
|
|
|
|
if (how == E_INC)
|
|
|
|
val += input;
|
|
|
|
else if (how == E_DEC)
|
|
|
|
val -= input;
|
|
|
|
if (val < var_data->u.n.low || val > var_data->u.n.high)
|
2013-03-28 09:02:44 +00:00
|
|
|
return -ERANGE;
|
2010-10-07 18:20:02 +00:00
|
|
|
}
|
|
|
|
var_data->u.n.value = val;
|
|
|
|
if (var->var_type == VAR_TIME && p_val != NULL) {
|
|
|
|
*p_val = msecs_to_jiffies(val);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (p_val != NULL)
|
|
|
|
*p_val = val;
|
|
|
|
if (var->var_id == PUNC_LEVEL) {
|
2013-01-02 01:37:40 +00:00
|
|
|
spk_punc_mask = spk_punc_masks[val];
|
2010-10-07 18:20:02 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (var_data->u.n.multiplier != 0)
|
|
|
|
val *= var_data->u.n.multiplier;
|
|
|
|
val += var_data->u.n.offset;
|
|
|
|
if (var->var_id < FIRST_SYNTH_VAR || synth == NULL)
|
|
|
|
return ret;
|
|
|
|
if (synth->synth_adjust != NULL) {
|
|
|
|
int status = synth->synth_adjust(var);
|
2014-09-30 22:36:29 +00:00
|
|
|
|
2010-10-07 18:20:02 +00:00
|
|
|
return (status != 0) ? status : ret;
|
|
|
|
}
|
|
|
|
if (!var_data->u.n.synth_fmt)
|
|
|
|
return ret;
|
|
|
|
if (var->var_id == PITCH)
|
2013-01-02 01:37:40 +00:00
|
|
|
cp = spk_pitch_buff;
|
2010-10-07 18:20:02 +00:00
|
|
|
else
|
|
|
|
cp = buf;
|
|
|
|
if (!var_data->u.n.out_str)
|
|
|
|
l = sprintf(cp, var_data->u.n.synth_fmt, (int)val);
|
|
|
|
else
|
2010-10-16 03:13:39 +00:00
|
|
|
l = sprintf(cp,
|
|
|
|
var_data->u.n.synth_fmt, var_data->u.n.out_str[val]);
|
2010-10-07 18:20:02 +00:00
|
|
|
synth_printf("%s", cp);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-01-02 01:37:40 +00:00
|
|
|
int spk_set_string_var(const char *page, struct st_var_header *var, int len)
|
2010-10-07 18:20:02 +00:00
|
|
|
{
|
|
|
|
struct var_t *var_data = var->data;
|
2013-03-28 09:02:44 +00:00
|
|
|
|
2010-10-07 18:20:02 +00:00
|
|
|
if (var_data == NULL)
|
2013-03-28 09:02:44 +00:00
|
|
|
return -ENODATA;
|
2010-10-07 18:20:02 +00:00
|
|
|
if (len > MAXVARLEN)
|
2013-03-28 09:02:44 +00:00
|
|
|
return -E2BIG;
|
2010-10-07 18:20:02 +00:00
|
|
|
if (!len) {
|
2010-10-16 03:13:39 +00:00
|
|
|
if (!var_data->u.s.default_val)
|
|
|
|
return 0;
|
2010-10-07 18:20:02 +00:00
|
|
|
if (!var->p_val)
|
|
|
|
var->p_val = var_data->u.s.default_val;
|
|
|
|
if (var->p_val != var_data->u.s.default_val)
|
|
|
|
strcpy((char *)var->p_val, var_data->u.s.default_val);
|
2013-03-28 09:02:44 +00:00
|
|
|
return -ERESTART;
|
2010-10-16 03:13:39 +00:00
|
|
|
} else if (var->p_val)
|
|
|
|
strcpy((char *)var->p_val, page);
|
2010-10-07 18:20:02 +00:00
|
|
|
else
|
2013-03-28 09:02:44 +00:00
|
|
|
return -E2BIG;
|
|
|
|
return 0;
|
2010-10-07 18:20:02 +00:00
|
|
|
}
|
|
|
|
|
2013-01-02 01:37:40 +00:00
|
|
|
/* spk_set_mask_bits sets or clears the punc/delim/repeat bits,
|
2010-10-07 18:20:02 +00:00
|
|
|
* if input is null uses the defaults.
|
|
|
|
* values for how: 0 clears bits of chars supplied,
|
2015-08-14 19:34:37 +00:00
|
|
|
* 1 clears allk, 2 sets bits for chars
|
|
|
|
*/
|
2013-01-02 01:37:40 +00:00
|
|
|
int spk_set_mask_bits(const char *input, const int which, const int how)
|
2010-10-07 18:20:02 +00:00
|
|
|
{
|
|
|
|
u_char *cp;
|
2013-01-02 01:37:40 +00:00
|
|
|
short mask = spk_punc_info[which].mask;
|
2014-09-09 18:04:34 +00:00
|
|
|
|
2010-10-07 18:20:02 +00:00
|
|
|
if (how&1) {
|
2013-01-02 01:37:40 +00:00
|
|
|
for (cp = (u_char *)spk_punc_info[3].value; *cp; cp++)
|
2010-10-07 18:20:02 +00:00
|
|
|
spk_chartab[*cp] &= ~mask;
|
|
|
|
}
|
|
|
|
cp = (u_char *)input;
|
2013-05-13 10:00:42 +00:00
|
|
|
if (!cp)
|
2013-01-02 01:37:40 +00:00
|
|
|
cp = spk_punc_info[which].value;
|
2010-10-07 18:20:02 +00:00
|
|
|
else {
|
2013-10-13 10:51:07 +00:00
|
|
|
for (; *cp; cp++) {
|
2010-10-07 18:20:02 +00:00
|
|
|
if (*cp < SPACE)
|
|
|
|
break;
|
|
|
|
if (mask < PUNC) {
|
|
|
|
if (!(spk_chartab[*cp]&PUNC))
|
|
|
|
break;
|
|
|
|
} else if (spk_chartab[*cp]&B_NUM)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (*cp)
|
|
|
|
return -EINVAL;
|
|
|
|
cp = (u_char *)input;
|
|
|
|
}
|
|
|
|
if (how&2) {
|
2013-10-13 10:51:07 +00:00
|
|
|
for (; *cp; cp++)
|
2010-10-07 18:20:02 +00:00
|
|
|
if (*cp > SPACE)
|
|
|
|
spk_chartab[*cp] |= mask;
|
|
|
|
} else {
|
2013-10-13 10:51:07 +00:00
|
|
|
for (; *cp; cp++)
|
2010-10-07 18:20:02 +00:00
|
|
|
if (*cp > SPACE)
|
|
|
|
spk_chartab[*cp] &= ~mask;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-02 01:37:40 +00:00
|
|
|
char *spk_strlwr(char *s)
|
2010-10-07 18:20:02 +00:00
|
|
|
{
|
|
|
|
char *p;
|
2014-09-09 18:04:34 +00:00
|
|
|
|
2010-10-07 18:20:02 +00:00
|
|
|
if (s == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (p = s; *p; p++)
|
|
|
|
*p = tolower(*p);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2013-01-02 01:37:40 +00:00
|
|
|
char *spk_s2uchar(char *start, char *dest)
|
2010-10-07 18:20:02 +00:00
|
|
|
{
|
|
|
|
int val = 0;
|
2014-09-09 18:04:34 +00:00
|
|
|
|
2013-03-28 09:02:43 +00:00
|
|
|
val = simple_strtoul(skip_spaces(start), &start, 10);
|
2010-10-07 18:20:02 +00:00
|
|
|
if (*start == ',')
|
|
|
|
start++;
|
|
|
|
*dest = (u_char)val;
|
|
|
|
return start;
|
|
|
|
}
|