重载属性时,保持最顶层的SANE_Option_Descriptor*指针不变;修复浮点数打印错误;修复字符串函数符号;初始化时获取设备固件版本及序列号,以供其它属性使用
This commit is contained in:
parent
68e062cb46
commit
d14e2327ad
|
@ -2202,6 +2202,7 @@ void hg_scanner::init_settings(const char* json_setting_text)
|
||||||
{
|
{
|
||||||
gb_json* child = nullptr;
|
gb_json* child = nullptr;
|
||||||
|
|
||||||
|
// fixed values ...
|
||||||
jsn->get_value(SANE_STD_OPT_NAME_DEVICE_VID, child);
|
jsn->get_value(SANE_STD_OPT_NAME_DEVICE_VID, child);
|
||||||
if (child)
|
if (child)
|
||||||
{
|
{
|
||||||
|
@ -2242,6 +2243,24 @@ void hg_scanner::init_settings(const char* json_setting_text)
|
||||||
child->release();
|
child->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fixed values from device ...
|
||||||
|
jsn->get_value(SANE_STD_OPT_NAME_FIRMWARE_VERSION, child);
|
||||||
|
if(child)
|
||||||
|
{
|
||||||
|
std::string val(get_firmware_version());
|
||||||
|
child->set_value("cur", val.c_str());
|
||||||
|
child->set_value("default", val.c_str());
|
||||||
|
child->release();
|
||||||
|
}
|
||||||
|
jsn->get_value(SANE_STD_OPT_NAME_DEVICE_SERIAL_NO, child);
|
||||||
|
if(child)
|
||||||
|
{
|
||||||
|
std::string val(get_serial_num());
|
||||||
|
child->set_value("cur", val.c_str());
|
||||||
|
child->set_value("default", val.c_str());
|
||||||
|
child->release();
|
||||||
|
}
|
||||||
|
|
||||||
text = std::move(jsn->to_string());
|
text = std::move(jsn->to_string());
|
||||||
}
|
}
|
||||||
jsn->release();
|
jsn->release();
|
||||||
|
|
|
@ -561,21 +561,21 @@ bool device_option::is_string_function(const char* expr, std::string& name, int&
|
||||||
{
|
{
|
||||||
name = exp.substr(0, pos++);
|
name = exp.substr(0, pos++);
|
||||||
exp.erase(0, pos);
|
exp.erase(0, pos);
|
||||||
if (exp.find("left[") == 0)
|
if (exp.find("left(") == 0)
|
||||||
{
|
{
|
||||||
exp.erase(0, 5);
|
exp.erase(0, 5);
|
||||||
start = 0;
|
start = 0;
|
||||||
cnt = atoi(exp.c_str());
|
cnt = atoi(exp.c_str());
|
||||||
pos = 0;
|
pos = 0;
|
||||||
}
|
}
|
||||||
else if (exp.find("right[") == 0)
|
else if (exp.find("right(") == 0)
|
||||||
{
|
{
|
||||||
exp.erase(0, 6);
|
exp.erase(0, 6);
|
||||||
start = -1 * atoi(exp.c_str());
|
start = -1 * atoi(exp.c_str());
|
||||||
cnt = -1;
|
cnt = -1;
|
||||||
pos = 0;
|
pos = 0;
|
||||||
}
|
}
|
||||||
else if (exp.find("mid[") == 0)
|
else if (exp.find("mid(") == 0)
|
||||||
{
|
{
|
||||||
exp.erase(0, 4);
|
exp.erase(0, 4);
|
||||||
start = atoi(exp.c_str());
|
start = atoi(exp.c_str());
|
||||||
|
@ -589,7 +589,7 @@ bool device_option::is_string_function(const char* expr, std::string& name, int&
|
||||||
}
|
}
|
||||||
if (pos == 0)
|
if (pos == 0)
|
||||||
{
|
{
|
||||||
pos = exp.find("]");
|
pos = exp.find(")");
|
||||||
ret = pos != std::string::npos && (cnt > 0 || cnt == -1);
|
ret = pos != std::string::npos && (cnt > 0 || cnt == -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -737,11 +737,11 @@ bool device_option::parse_simple_logic_expression(gb_json* root, const char* exp
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// substr function ...
|
// substr function ...
|
||||||
if (strstr(tag, "left[") || strstr(tag, "right[") || strstr(tag, "mid["))
|
if (strstr(tag, "left(") || strstr(tag, "right(") || strstr(tag, "mid("))
|
||||||
{
|
{
|
||||||
const char* end = nullptr, *start = strstr(tag, "[");
|
const char* end = nullptr, *start = strstr(tag, "(");
|
||||||
int l = string_util::find_end_of_pair(start + 1, '[', ']');
|
int l = string_util::find_end_of_pair(start + 1, '(', ')');
|
||||||
bool ret = start[++l] == ']';
|
bool ret = start[++l] == ')';
|
||||||
|
|
||||||
if (ret)
|
if (ret)
|
||||||
{
|
{
|
||||||
|
|
|
@ -175,8 +175,8 @@ bool simple_logic::parse_internal(const char* expr, int* end, void(*leaf)(const
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string sub(ptr + 1, len - 1);
|
std::string sub(ptr + 1, len - 1);
|
||||||
if (sub.find("||") == std::string::npos ||
|
if (sub.find("||") == std::string::npos &&
|
||||||
sub.find("&&") == std::string::npos ||
|
sub.find("&&") == std::string::npos &&
|
||||||
sub.find("^") == std::string::npos)
|
sub.find("^") == std::string::npos)
|
||||||
{
|
{
|
||||||
// count as function ...
|
// count as function ...
|
||||||
|
|
|
@ -36,7 +36,7 @@ std::string sane_opt::readable_text(SANE_Value_Type type, void* value)
|
||||||
else if (type == SANE_TYPE_INT)
|
else if (type == SANE_TYPE_INT)
|
||||||
return std::to_string(*(int*)value);
|
return std::to_string(*(int*)value);
|
||||||
else if (type == SANE_TYPE_FIXED)
|
else if (type == SANE_TYPE_FIXED)
|
||||||
return std::to_string(*(double*)value);
|
return std::to_string(SANE_UNFIX(*(SANE_Fixed*)value));
|
||||||
else if (type == SANE_TYPE_STRING)
|
else if (type == SANE_TYPE_STRING)
|
||||||
return (char*)value;
|
return (char*)value;
|
||||||
else
|
else
|
||||||
|
@ -376,7 +376,7 @@ bool sane_options::init_from(const char* jsn_text/*all options*/, void(*err_msg)
|
||||||
std::string str(jsn_text);
|
std::string str(jsn_text);
|
||||||
int sn = 0;
|
int sn = 0;
|
||||||
|
|
||||||
clear();
|
// clear(); // keep the SANE_Option_Descriptor*
|
||||||
if (jsn->attach_text(&str[0]))
|
if (jsn->attach_text(&str[0]))
|
||||||
{
|
{
|
||||||
gb_json* child = jsn->first_child();
|
gb_json* child = jsn->first_child();
|
||||||
|
|
Loading…
Reference in New Issue