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:
		set_string_var(nothing, p_header, 0);
		break;
	case VAR_NUM:
	case VAR_TIME:
		set_num_var(0, p_header, E_DEFAULT);
		break;
	default:
		break;
	}
	return;
}
Exemplo n.º 2
0
/*
 * This function is called when a user echos a value to one of the
 * variable parameters.
 */
ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr,
			 const char *buf, size_t count)
{
	struct st_var_header *param;
	int ret;
	int len;
	char *cp;
	struct var_t *var_data;
	int value;
	unsigned long flags;

	param = var_header_by_name(attr->attr.name);
	if (param == NULL)
		return -EINVAL;
	if (param->data == NULL)
		return 0;
	ret = 0;
	cp = xlate((char *) buf);

	spk_lock(flags);
	switch (param->var_type) {
	case VAR_NUM:
	case VAR_TIME:
		if (*cp == 'd' || *cp == 'r' || *cp == '\0')
			len = E_DEFAULT;
		else if (*cp == '+' || *cp == '-')
			len = E_INC;
		else
			len = E_SET;
		speakup_s2i(cp, &value);
		ret = set_num_var(value, param, len);
		if (ret == E_RANGE) {
			var_data = param->data;
			pr_warn("value for %s out of range, expect %d to %d\n",
				attr->attr.name,
				var_data->u.n.low, var_data->u.n.high);
		}
		break;
	case VAR_STRING:
		len = strlen(buf);
		if ((len >= 1) && (buf[len - 1] == '\n'))
			--len;
		if ((len >= 2) && (buf[0] == '"') && (buf[len - 1] == '"')) {
			++buf;
			len -= 2;
		}
		cp = (char *) buf;
		cp[len] = '\0';
		ret = set_string_var(buf, param, len);
		if (ret == E_TOOLONG)
			pr_warn("value too long for %s\n",
					attr->attr.name);
		break;
	default:
		pr_warn("%s unknown type %d\n",
			param->name, (int)param->var_type);
	break;
	}
	/*
	 * If voice was just changed, we might need to reset our default
	 * pitch and volume.
	 */
	if (strcmp(attr->attr.name, "voice") == 0) {
		if (synth && synth->default_pitch) {
			param = var_header_by_name("pitch");
			if (param)  {
				set_num_var(synth->default_pitch[value], param,
					E_NEW_DEFAULT);
				set_num_var(0, param, E_DEFAULT);
			}
		}
		if (synth && synth->default_vol) {
			param = var_header_by_name("vol");
			if (param)  {
				set_num_var(synth->default_vol[value], param,
					E_NEW_DEFAULT);
				set_num_var(0, param, E_DEFAULT);
			}
		}
	}
	spk_unlock(flags);

	if (ret == SET_DEFAULT)
		pr_info("%s reset to default value\n", attr->attr.name);
	return count;
}