mirror of
https://github.com/libretro/RetroArch
synced 2025-02-05 15:40:04 +00:00
query.c - namespace functions
This commit is contained in:
parent
9300313fce
commit
4717a2df64
@ -93,20 +93,20 @@ struct registered_func
|
|||||||
static char tmp_error_buff [MAX_ERROR_LEN] = {0};
|
static char tmp_error_buff [MAX_ERROR_LEN] = {0};
|
||||||
|
|
||||||
/* Forward declarations */
|
/* Forward declarations */
|
||||||
static struct buffer parse_method_call(struct buffer buff,
|
static struct buffer query_parse_method_call(struct buffer buff,
|
||||||
struct invocation *invocation, const char **error);
|
struct invocation *invocation, const char **error);
|
||||||
static struct buffer parse_table(struct buffer buff,
|
static struct buffer query_parse_table(struct buffer buff,
|
||||||
struct invocation *invocation, const char **error);
|
struct invocation *invocation, const char **error);
|
||||||
|
|
||||||
/* Errors */
|
/* Errors */
|
||||||
static void raise_too_many_arguments(const char **error)
|
static void query_raise_too_many_arguments(const char **error)
|
||||||
{
|
{
|
||||||
strlcpy(tmp_error_buff,
|
strlcpy(tmp_error_buff,
|
||||||
"Too many arguments in function call.", sizeof(tmp_error_buff));
|
"Too many arguments in function call.", sizeof(tmp_error_buff));
|
||||||
*error = tmp_error_buff;
|
*error = tmp_error_buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct rmsgpack_dom_value func_is_true(
|
static struct rmsgpack_dom_value query_func_is_true(
|
||||||
struct rmsgpack_dom_value input,
|
struct rmsgpack_dom_value input,
|
||||||
unsigned argc, const struct argument *argv)
|
unsigned argc, const struct argument *argv)
|
||||||
{
|
{
|
||||||
@ -155,7 +155,7 @@ static struct rmsgpack_dom_value func_equals(
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct rmsgpack_dom_value func_operator_or(
|
static struct rmsgpack_dom_value query_func_operator_or(
|
||||||
struct rmsgpack_dom_value input,
|
struct rmsgpack_dom_value input,
|
||||||
unsigned argc, const struct argument * argv)
|
unsigned argc, const struct argument * argv)
|
||||||
{
|
{
|
||||||
@ -172,7 +172,7 @@ static struct rmsgpack_dom_value func_operator_or(
|
|||||||
res = func_equals(input, 1, &argv[i]);
|
res = func_equals(input, 1, &argv[i]);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
res = func_is_true(
|
res = query_func_is_true(
|
||||||
argv[i].a.invocation.func(input,
|
argv[i].a.invocation.func(input,
|
||||||
argv[i].a.invocation.argc,
|
argv[i].a.invocation.argc,
|
||||||
argv[i].a.invocation.argv
|
argv[i].a.invocation.argv
|
||||||
@ -186,7 +186,7 @@ static struct rmsgpack_dom_value func_operator_or(
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct rmsgpack_dom_value func_operator_and(
|
static struct rmsgpack_dom_value query_func_operator_and(
|
||||||
struct rmsgpack_dom_value input,
|
struct rmsgpack_dom_value input,
|
||||||
unsigned argc, const struct argument * argv)
|
unsigned argc, const struct argument * argv)
|
||||||
{
|
{
|
||||||
@ -203,7 +203,7 @@ static struct rmsgpack_dom_value func_operator_and(
|
|||||||
res = func_equals(input, 1, &argv[i]);
|
res = func_equals(input, 1, &argv[i]);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
res = func_is_true(
|
res = query_func_is_true(
|
||||||
argv[i].a.invocation.func(input,
|
argv[i].a.invocation.func(input,
|
||||||
argv[i].a.invocation.argc,
|
argv[i].a.invocation.argc,
|
||||||
argv[i].a.invocation.argv
|
argv[i].a.invocation.argv
|
||||||
@ -217,7 +217,8 @@ static struct rmsgpack_dom_value func_operator_and(
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct rmsgpack_dom_value func_between(struct rmsgpack_dom_value input,
|
static struct rmsgpack_dom_value query_func_between(
|
||||||
|
struct rmsgpack_dom_value input,
|
||||||
unsigned argc, const struct argument * argv)
|
unsigned argc, const struct argument * argv)
|
||||||
{
|
{
|
||||||
struct rmsgpack_dom_value res;
|
struct rmsgpack_dom_value res;
|
||||||
@ -256,7 +257,7 @@ static struct rmsgpack_dom_value func_between(struct rmsgpack_dom_value input,
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct rmsgpack_dom_value func_glob(
|
static struct rmsgpack_dom_value query_func_glob(
|
||||||
struct rmsgpack_dom_value input,
|
struct rmsgpack_dom_value input,
|
||||||
unsigned argc, const struct argument * argv)
|
unsigned argc, const struct argument * argv)
|
||||||
{
|
{
|
||||||
@ -284,15 +285,15 @@ static struct rmsgpack_dom_value func_glob(
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct registered_func registered_functions[100] = {
|
struct registered_func registered_functions[100] = {
|
||||||
{"is_true", func_is_true},
|
{"is_true", query_func_is_true},
|
||||||
{"or", func_operator_or},
|
{"or", query_func_operator_or},
|
||||||
{"and", func_operator_and},
|
{"and", query_func_operator_and},
|
||||||
{"between", func_between},
|
{"between", query_func_between},
|
||||||
{"glob", func_glob},
|
{"glob", query_func_glob},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
static void raise_expected_number(ssize_t where, const char **error)
|
static void query_raise_expected_number(ssize_t where, const char **error)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
snprintf(tmp_error_buff, MAX_ERROR_LEN,
|
snprintf(tmp_error_buff, MAX_ERROR_LEN,
|
||||||
@ -306,7 +307,7 @@ static void raise_expected_number(ssize_t where, const char **error)
|
|||||||
*error = tmp_error_buff;
|
*error = tmp_error_buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void raise_expected_string(ssize_t where, const char ** error)
|
static void query_raise_expected_string(ssize_t where, const char ** error)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
snprintf(tmp_error_buff, MAX_ERROR_LEN,
|
snprintf(tmp_error_buff, MAX_ERROR_LEN,
|
||||||
@ -320,7 +321,7 @@ static void raise_expected_string(ssize_t where, const char ** error)
|
|||||||
*error = tmp_error_buff;
|
*error = tmp_error_buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void raise_unexpected_eof(ssize_t where, const char ** error)
|
static void query_raise_unexpected_eof(ssize_t where, const char ** error)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
snprintf(tmp_error_buff, MAX_ERROR_LEN,
|
snprintf(tmp_error_buff, MAX_ERROR_LEN,
|
||||||
@ -336,13 +337,13 @@ static void raise_unexpected_eof(ssize_t where, const char ** error)
|
|||||||
*error = tmp_error_buff;
|
*error = tmp_error_buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void raise_enomem(const char **error)
|
static void query_raise_enomem(const char **error)
|
||||||
{
|
{
|
||||||
strlcpy(tmp_error_buff, "Out of memory", sizeof(tmp_error_buff));
|
strlcpy(tmp_error_buff, "Out of memory", sizeof(tmp_error_buff));
|
||||||
*error = tmp_error_buff;
|
*error = tmp_error_buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void raise_unknown_function(ssize_t where, const char *name,
|
static void query_raise_unknown_function(ssize_t where, const char *name,
|
||||||
ssize_t len, const char **error)
|
ssize_t len, const char **error)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -363,7 +364,9 @@ static void raise_unknown_function(ssize_t where, const char *name,
|
|||||||
strlcpy(tmp_error_buff + n + len, "'", sizeof(tmp_error_buff));
|
strlcpy(tmp_error_buff + n + len, "'", sizeof(tmp_error_buff));
|
||||||
*error = tmp_error_buff;
|
*error = tmp_error_buff;
|
||||||
}
|
}
|
||||||
static void raise_expected_eof(ssize_t where, char found, const char **error)
|
|
||||||
|
static void query_raise_expected_eof(
|
||||||
|
ssize_t where, char found, const char **error)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
snprintf(tmp_error_buff, MAX_ERROR_LEN,
|
snprintf(tmp_error_buff, MAX_ERROR_LEN,
|
||||||
@ -381,7 +384,8 @@ static void raise_expected_eof(ssize_t where, char found, const char **error)
|
|||||||
*error = tmp_error_buff;
|
*error = tmp_error_buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void raise_unexpected_char(ssize_t where, char expected, char found,
|
static void query_raise_unexpected_char(
|
||||||
|
ssize_t where, char expected, char found,
|
||||||
const char **error)
|
const char **error)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -397,7 +401,7 @@ static void raise_unexpected_char(ssize_t where, char expected, char found,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void argument_free(struct argument *arg)
|
static void query_argument_free(struct argument *arg)
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
|
||||||
@ -408,10 +412,10 @@ static void argument_free(struct argument *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < arg->a.invocation.argc; i++)
|
for (i = 0; i < arg->a.invocation.argc; i++)
|
||||||
argument_free(&arg->a.invocation.argv[i]);
|
query_argument_free(&arg->a.invocation.argv[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct buffer parse_integer(struct buffer buff,
|
static struct buffer query_parse_integer(struct buffer buff,
|
||||||
struct rmsgpack_dom_value *value, const char **error)
|
struct rmsgpack_dom_value *value, const char **error)
|
||||||
{
|
{
|
||||||
bool test = false;
|
bool test = false;
|
||||||
@ -429,7 +433,7 @@ static struct buffer parse_integer(struct buffer buff,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (test)
|
if (test)
|
||||||
raise_expected_number(buff.offset, error);
|
query_raise_expected_number(buff.offset, error);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
while (isdigit((int)buff.data[buff.offset]))
|
while (isdigit((int)buff.data[buff.offset]))
|
||||||
@ -439,7 +443,7 @@ static struct buffer parse_integer(struct buffer buff,
|
|||||||
return buff;
|
return buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct buffer chomp(struct buffer buff)
|
static struct buffer query_chomp(struct buffer buff)
|
||||||
{
|
{
|
||||||
for (; (unsigned)buff.offset < buff.len
|
for (; (unsigned)buff.offset < buff.len
|
||||||
&& isspace((int)buff.data[buff.offset]); buff.offset++);
|
&& isspace((int)buff.data[buff.offset]); buff.offset++);
|
||||||
@ -447,15 +451,15 @@ static struct buffer chomp(struct buffer buff)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static struct buffer expect_eof(struct buffer buff, const char ** error)
|
static struct buffer query_expect_eof(struct buffer buff, const char ** error)
|
||||||
{
|
{
|
||||||
buff = chomp(buff);
|
buff = query_chomp(buff);
|
||||||
if ((unsigned)buff.offset < buff.len)
|
if ((unsigned)buff.offset < buff.len)
|
||||||
raise_expected_eof(buff.offset, buff.data[buff.offset], error);
|
query_raise_expected_eof(buff.offset, buff.data[buff.offset], error);
|
||||||
return buff;
|
return buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int peek(struct buffer buff, const char * data)
|
static int query_peek(struct buffer buff, const char * data)
|
||||||
{
|
{
|
||||||
size_t remain = buff.len - buff.offset;
|
size_t remain = buff.len - buff.offset;
|
||||||
|
|
||||||
@ -466,25 +470,27 @@ static int peek(struct buffer buff, const char * data)
|
|||||||
data, strlen(data)) == 0);
|
data, strlen(data)) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int is_eot(struct buffer buff)
|
static int query_is_eot(struct buffer buff)
|
||||||
{
|
{
|
||||||
return ((unsigned)buff.offset >= buff.len);
|
return ((unsigned)buff.offset >= buff.len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct buffer get_char(struct buffer buff, char * c,
|
static struct buffer query_get_char(
|
||||||
|
struct buffer buff, char * c,
|
||||||
const char ** error)
|
const char ** error)
|
||||||
{
|
{
|
||||||
if (is_eot(buff))
|
if (query_is_eot(buff))
|
||||||
{
|
{
|
||||||
raise_unexpected_eof(buff.offset, error);
|
query_raise_unexpected_eof(buff.offset, error);
|
||||||
return buff;
|
return buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
*c = buff.data[buff.offset];
|
*c = buff.data[buff.offset];
|
||||||
buff.offset++;
|
buff.offset++;
|
||||||
return buff;
|
return buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct buffer parse_string(struct buffer buff,
|
static struct buffer query_parse_string(struct buffer buff,
|
||||||
struct rmsgpack_dom_value *value, const char **error)
|
struct rmsgpack_dom_value *value, const char **error)
|
||||||
{
|
{
|
||||||
const char * str_start = NULL;
|
const char * str_start = NULL;
|
||||||
@ -494,7 +500,7 @@ static struct buffer parse_string(struct buffer buff,
|
|||||||
|
|
||||||
(void)c;
|
(void)c;
|
||||||
|
|
||||||
buff = get_char(buff, &terminator, error);
|
buff = query_get_char(buff, &terminator, error);
|
||||||
|
|
||||||
if (*error)
|
if (*error)
|
||||||
return buff;
|
return buff;
|
||||||
@ -502,23 +508,23 @@ static struct buffer parse_string(struct buffer buff,
|
|||||||
if (terminator == 'b')
|
if (terminator == 'b')
|
||||||
{
|
{
|
||||||
is_binstr = 1;
|
is_binstr = 1;
|
||||||
buff = get_char(buff, &terminator, error);
|
buff = query_get_char(buff, &terminator, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (terminator != '"' && terminator != '\'')
|
if (terminator != '"' && terminator != '\'')
|
||||||
{
|
{
|
||||||
buff.offset--;
|
buff.offset--;
|
||||||
raise_expected_string(buff.offset, error);
|
query_raise_expected_string(buff.offset, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
str_start = buff.data + buff.offset;
|
str_start = buff.data + buff.offset;
|
||||||
buff = get_char(buff, &c, error);
|
buff = query_get_char(buff, &c, error);
|
||||||
|
|
||||||
while (!*error)
|
while (!*error)
|
||||||
{
|
{
|
||||||
if (c == terminator)
|
if (c == terminator)
|
||||||
break;
|
break;
|
||||||
buff = get_char(buff, &c, error);
|
buff = query_get_char(buff, &c, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!*error)
|
if (!*error)
|
||||||
@ -532,7 +538,7 @@ static struct buffer parse_string(struct buffer buff,
|
|||||||
value->val.string.buff = (char*)calloc(count, sizeof(char));
|
value->val.string.buff = (char*)calloc(count, sizeof(char));
|
||||||
|
|
||||||
if (!value->val.string.buff)
|
if (!value->val.string.buff)
|
||||||
raise_enomem(error);
|
query_raise_enomem(error);
|
||||||
else if (is_binstr)
|
else if (is_binstr)
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
@ -566,61 +572,62 @@ static struct buffer parse_string(struct buffer buff,
|
|||||||
return buff;
|
return buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct buffer parse_value(struct buffer buff,
|
static struct buffer query_parse_value(struct buffer buff,
|
||||||
struct rmsgpack_dom_value *value, const char **error)
|
struct rmsgpack_dom_value *value, const char **error)
|
||||||
{
|
{
|
||||||
buff = chomp(buff);
|
buff = query_chomp(buff);
|
||||||
|
|
||||||
if (peek(buff, "nil"))
|
if (query_peek(buff, "nil"))
|
||||||
{
|
{
|
||||||
buff.offset += strlen("nil");
|
buff.offset += strlen("nil");
|
||||||
value->type = RDT_NULL;
|
value->type = RDT_NULL;
|
||||||
}
|
}
|
||||||
else if (peek(buff, "true"))
|
else if (query_peek(buff, "true"))
|
||||||
{
|
{
|
||||||
buff.offset += strlen("true");
|
buff.offset += strlen("true");
|
||||||
value->type = RDT_BOOL;
|
value->type = RDT_BOOL;
|
||||||
value->val.bool_ = 1;
|
value->val.bool_ = 1;
|
||||||
}
|
}
|
||||||
else if (peek(buff, "false"))
|
else if (query_peek(buff, "false"))
|
||||||
{
|
{
|
||||||
buff.offset += strlen("false");
|
buff.offset += strlen("false");
|
||||||
value->type = RDT_BOOL;
|
value->type = RDT_BOOL;
|
||||||
value->val.bool_ = 0;
|
value->val.bool_ = 0;
|
||||||
}
|
}
|
||||||
else if (peek(buff, "b") || peek(buff, "\"") || peek(buff, "'"))
|
else if (query_peek(buff, "b") || query_peek(buff, "\"") || query_peek(buff, "'"))
|
||||||
buff = parse_string(buff, value, error);
|
buff = query_parse_string(buff, value, error);
|
||||||
else if (isdigit((int)buff.data[buff.offset]))
|
else if (isdigit((int)buff.data[buff.offset]))
|
||||||
buff = parse_integer(buff, value, error);
|
buff = query_parse_integer(buff, value, error);
|
||||||
return buff;
|
return buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void peek_char(struct buffer buff, char *c, const char **error)
|
static void query_peek_char(struct buffer buff, char *c,
|
||||||
|
const char **error)
|
||||||
{
|
{
|
||||||
if (is_eot(buff))
|
if (query_is_eot(buff))
|
||||||
{
|
{
|
||||||
raise_unexpected_eof(buff.offset, error);
|
query_raise_unexpected_eof(buff.offset, error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
*c = buff.data[buff.offset];
|
*c = buff.data[buff.offset];
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct buffer get_ident(struct buffer buff,
|
static struct buffer query_get_ident(struct buffer buff,
|
||||||
const char **ident,
|
const char **ident,
|
||||||
size_t *len, const char **error)
|
size_t *len, const char **error)
|
||||||
{
|
{
|
||||||
char c = '\0';
|
char c = '\0';
|
||||||
|
|
||||||
if (is_eot(buff))
|
if (query_is_eot(buff))
|
||||||
{
|
{
|
||||||
raise_unexpected_eof(buff.offset, error);
|
query_raise_unexpected_eof(buff.offset, error);
|
||||||
return buff;
|
return buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
*ident = buff.data + buff.offset;
|
*ident = buff.data + buff.offset;
|
||||||
*len = 0;
|
*len = 0;
|
||||||
peek_char(buff, &c, error);
|
query_peek_char(buff, &c, error);
|
||||||
|
|
||||||
if (*error)
|
if (*error)
|
||||||
goto clean;
|
goto clean;
|
||||||
@ -629,7 +636,7 @@ static struct buffer get_ident(struct buffer buff,
|
|||||||
|
|
||||||
buff.offset++;
|
buff.offset++;
|
||||||
*len = *len + 1;
|
*len = *len + 1;
|
||||||
peek_char(buff, &c, error);
|
query_peek_char(buff, &c, error);
|
||||||
|
|
||||||
while (!*error)
|
while (!*error)
|
||||||
{
|
{
|
||||||
@ -637,20 +644,20 @@ static struct buffer get_ident(struct buffer buff,
|
|||||||
break;
|
break;
|
||||||
buff.offset++;
|
buff.offset++;
|
||||||
*len = *len + 1;
|
*len = *len + 1;
|
||||||
peek_char(buff, &c, error);
|
query_peek_char(buff, &c, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
return buff;
|
return buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct buffer expect_char(struct buffer buff,
|
static struct buffer query_expect_char(struct buffer buff,
|
||||||
char c, const char ** error)
|
char c, const char ** error)
|
||||||
{
|
{
|
||||||
if ((unsigned)buff.offset >= buff.len)
|
if ((unsigned)buff.offset >= buff.len)
|
||||||
raise_unexpected_eof(buff.offset, error);
|
query_raise_unexpected_eof(buff.offset, error);
|
||||||
else if (buff.data[buff.offset] != c)
|
else if (buff.data[buff.offset] != c)
|
||||||
raise_unexpected_char(
|
query_raise_unexpected_char(
|
||||||
buff.offset, c, buff.data[buff.offset], error);
|
buff.offset, c, buff.data[buff.offset], error);
|
||||||
else
|
else
|
||||||
buff.offset++;
|
buff.offset++;
|
||||||
@ -658,39 +665,40 @@ static struct buffer expect_char(struct buffer buff,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static struct buffer parse_argument(struct buffer buff,
|
static struct buffer query_parse_argument(struct buffer buff,
|
||||||
struct argument *arg, const char **error)
|
struct argument *arg, const char **error)
|
||||||
{
|
{
|
||||||
buff = chomp(buff);
|
buff = query_chomp(buff);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
isalpha((int)buff.data[buff.offset])
|
isalpha((int)buff.data[buff.offset])
|
||||||
&& !(
|
&& !(
|
||||||
peek(buff, "nil")
|
query_peek(buff, "nil")
|
||||||
|| peek(buff, "true")
|
|| query_peek(buff, "true")
|
||||||
|| peek(buff, "false")
|
|| query_peek(buff, "false")
|
||||||
|| peek(buff, "b\"")
|
|| query_peek(buff, "b\"")
|
||||||
|| peek(buff, "b'") /* bin string prefix*/
|
|| query_peek(buff, "b'") /* bin string prefix*/
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
arg->type = AT_FUNCTION;
|
arg->type = AT_FUNCTION;
|
||||||
buff = parse_method_call(buff, &arg->a.invocation, error);
|
buff = query_parse_method_call(buff,
|
||||||
|
&arg->a.invocation, error);
|
||||||
}
|
}
|
||||||
else if (peek(buff, "{"))
|
else if (query_peek(buff, "{"))
|
||||||
{
|
{
|
||||||
arg->type = AT_FUNCTION;
|
arg->type = AT_FUNCTION;
|
||||||
buff = parse_table(buff, &arg->a.invocation, error);
|
buff = query_parse_table(buff, &arg->a.invocation, error);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
arg->type = AT_VALUE;
|
arg->type = AT_VALUE;
|
||||||
buff = parse_value(buff, &arg->a.value, error);
|
buff = query_parse_value(buff, &arg->a.value, error);
|
||||||
}
|
}
|
||||||
return buff;
|
return buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct buffer parse_method_call(struct buffer buff,
|
static struct buffer query_parse_method_call(struct buffer buff,
|
||||||
struct invocation *invocation, const char **error)
|
struct invocation *invocation, const char **error)
|
||||||
{
|
{
|
||||||
size_t func_name_len;
|
size_t func_name_len;
|
||||||
@ -702,12 +710,12 @@ static struct buffer parse_method_call(struct buffer buff,
|
|||||||
|
|
||||||
invocation->func = NULL;
|
invocation->func = NULL;
|
||||||
|
|
||||||
buff = get_ident(buff, &func_name, &func_name_len, error);
|
buff = query_get_ident(buff, &func_name, &func_name_len, error);
|
||||||
if (*error)
|
if (*error)
|
||||||
goto clean;
|
goto clean;
|
||||||
|
|
||||||
buff = chomp(buff);
|
buff = query_chomp(buff);
|
||||||
buff = expect_char(buff, '(', error);
|
buff = query_expect_char(buff, '(', error);
|
||||||
if (*error)
|
if (*error)
|
||||||
goto clean;
|
goto clean;
|
||||||
|
|
||||||
@ -723,37 +731,37 @@ static struct buffer parse_method_call(struct buffer buff,
|
|||||||
|
|
||||||
if (!invocation->func)
|
if (!invocation->func)
|
||||||
{
|
{
|
||||||
raise_unknown_function(buff.offset, func_name,
|
query_raise_unknown_function(buff.offset, func_name,
|
||||||
func_name_len, error);
|
func_name_len, error);
|
||||||
goto clean;
|
goto clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
buff = chomp(buff);
|
buff = query_chomp(buff);
|
||||||
while (!peek(buff, ")"))
|
while (!query_peek(buff, ")"))
|
||||||
{
|
{
|
||||||
if (argi >= QUERY_MAX_ARGS)
|
if (argi >= QUERY_MAX_ARGS)
|
||||||
{
|
{
|
||||||
raise_too_many_arguments(error);
|
query_raise_too_many_arguments(error);
|
||||||
goto clean;
|
goto clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
buff = parse_argument(buff, &args[argi], error);
|
buff = query_parse_argument(buff, &args[argi], error);
|
||||||
|
|
||||||
if (*error)
|
if (*error)
|
||||||
goto clean;
|
goto clean;
|
||||||
|
|
||||||
argi++;
|
argi++;
|
||||||
buff = chomp(buff);
|
buff = query_chomp(buff);
|
||||||
buff = expect_char(buff, ',', error);
|
buff = query_expect_char(buff, ',', error);
|
||||||
|
|
||||||
if (*error)
|
if (*error)
|
||||||
{
|
{
|
||||||
*error = NULL;
|
*error = NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
buff = chomp(buff);
|
buff = query_chomp(buff);
|
||||||
}
|
}
|
||||||
buff = expect_char(buff, ')', error);
|
buff = query_expect_char(buff, ')', error);
|
||||||
|
|
||||||
if (*error)
|
if (*error)
|
||||||
goto clean;
|
goto clean;
|
||||||
@ -764,7 +772,7 @@ static struct buffer parse_method_call(struct buffer buff,
|
|||||||
|
|
||||||
if (!invocation->argv)
|
if (!invocation->argv)
|
||||||
{
|
{
|
||||||
raise_enomem(error);
|
query_raise_enomem(error);
|
||||||
goto clean;
|
goto clean;
|
||||||
}
|
}
|
||||||
memcpy(invocation->argv, args,
|
memcpy(invocation->argv, args,
|
||||||
@ -773,12 +781,12 @@ static struct buffer parse_method_call(struct buffer buff,
|
|||||||
goto success;
|
goto success;
|
||||||
clean:
|
clean:
|
||||||
for (i = 0; i < argi; i++)
|
for (i = 0; i < argi; i++)
|
||||||
argument_free(&args[i]);
|
query_argument_free(&args[i]);
|
||||||
success:
|
success:
|
||||||
return buff;
|
return buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct rmsgpack_dom_value func_all_map(
|
static struct rmsgpack_dom_value query_func_all_map(
|
||||||
struct rmsgpack_dom_value input,
|
struct rmsgpack_dom_value input,
|
||||||
unsigned argc, const struct argument *argv)
|
unsigned argc, const struct argument *argv)
|
||||||
{
|
{
|
||||||
@ -818,7 +826,7 @@ static struct rmsgpack_dom_value func_all_map(
|
|||||||
res = func_equals(*value, 1, &arg);
|
res = func_equals(*value, 1, &arg);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
res = func_is_true(arg.a.invocation.func(
|
res = query_func_is_true(arg.a.invocation.func(
|
||||||
*value,
|
*value,
|
||||||
arg.a.invocation.argc,
|
arg.a.invocation.argc,
|
||||||
arg.a.invocation.argv
|
arg.a.invocation.argv
|
||||||
@ -832,7 +840,7 @@ clean:
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct buffer parse_table(struct buffer buff,
|
static struct buffer query_parse_table(struct buffer buff,
|
||||||
struct invocation *invocation, const char **error)
|
struct invocation *invocation, const char **error)
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
@ -841,25 +849,25 @@ static struct buffer parse_table(struct buffer buff,
|
|||||||
const char *ident_name = NULL;
|
const char *ident_name = NULL;
|
||||||
unsigned argi = 0;
|
unsigned argi = 0;
|
||||||
|
|
||||||
buff = chomp(buff);
|
buff = query_chomp(buff);
|
||||||
buff = expect_char(buff, '{', error);
|
buff = query_expect_char(buff, '{', error);
|
||||||
|
|
||||||
if (*error)
|
if (*error)
|
||||||
goto clean;
|
goto clean;
|
||||||
|
|
||||||
buff = chomp(buff);
|
buff = query_chomp(buff);
|
||||||
|
|
||||||
while (!peek(buff, "}"))
|
while (!query_peek(buff, "}"))
|
||||||
{
|
{
|
||||||
if (argi >= QUERY_MAX_ARGS)
|
if (argi >= QUERY_MAX_ARGS)
|
||||||
{
|
{
|
||||||
raise_too_many_arguments(error);
|
query_raise_too_many_arguments(error);
|
||||||
goto clean;
|
goto clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isalpha((int)buff.data[buff.offset]))
|
if (isalpha((int)buff.data[buff.offset]))
|
||||||
{
|
{
|
||||||
buff = get_ident(buff, &ident_name, &ident_len, error);
|
buff = query_get_ident(buff, &ident_name, &ident_len, error);
|
||||||
|
|
||||||
if (!*error)
|
if (!*error)
|
||||||
{
|
{
|
||||||
@ -881,56 +889,56 @@ static struct buffer parse_table(struct buffer buff,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
buff = parse_string(buff, &args[argi].a.value, error);
|
buff = query_parse_string(buff, &args[argi].a.value, error);
|
||||||
|
|
||||||
if (*error)
|
if (*error)
|
||||||
goto clean;
|
goto clean;
|
||||||
|
|
||||||
args[argi].type = AT_VALUE;
|
args[argi].type = AT_VALUE;
|
||||||
buff = chomp(buff);
|
buff = query_chomp(buff);
|
||||||
argi++;
|
argi++;
|
||||||
buff = expect_char(buff, ':', error);
|
buff = query_expect_char(buff, ':', error);
|
||||||
|
|
||||||
if (*error)
|
if (*error)
|
||||||
goto clean;
|
goto clean;
|
||||||
|
|
||||||
buff = chomp(buff);
|
buff = query_chomp(buff);
|
||||||
|
|
||||||
if (argi >= QUERY_MAX_ARGS)
|
if (argi >= QUERY_MAX_ARGS)
|
||||||
{
|
{
|
||||||
raise_too_many_arguments(error);
|
query_raise_too_many_arguments(error);
|
||||||
goto clean;
|
goto clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
buff = parse_argument(buff, &args[argi], error);
|
buff = query_parse_argument(buff, &args[argi], error);
|
||||||
|
|
||||||
if (*error)
|
if (*error)
|
||||||
goto clean;
|
goto clean;
|
||||||
argi++;
|
argi++;
|
||||||
buff = chomp(buff);
|
buff = query_chomp(buff);
|
||||||
buff = expect_char(buff, ',', error);
|
buff = query_expect_char(buff, ',', error);
|
||||||
|
|
||||||
if (*error)
|
if (*error)
|
||||||
{
|
{
|
||||||
*error = NULL;
|
*error = NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
buff = chomp(buff);
|
buff = query_chomp(buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
buff = expect_char(buff, '}', error);
|
buff = query_expect_char(buff, '}', error);
|
||||||
|
|
||||||
if (*error)
|
if (*error)
|
||||||
goto clean;
|
goto clean;
|
||||||
|
|
||||||
invocation->func = func_all_map;
|
invocation->func = query_func_all_map;
|
||||||
invocation->argc = argi;
|
invocation->argc = argi;
|
||||||
invocation->argv = (struct argument*)
|
invocation->argv = (struct argument*)
|
||||||
malloc(sizeof(struct argument) * argi);
|
malloc(sizeof(struct argument) * argi);
|
||||||
|
|
||||||
if (!invocation->argv)
|
if (!invocation->argv)
|
||||||
{
|
{
|
||||||
raise_enomem(error);
|
query_raise_enomem(error);
|
||||||
goto clean;
|
goto clean;
|
||||||
}
|
}
|
||||||
memcpy(invocation->argv, args,
|
memcpy(invocation->argv, args,
|
||||||
@ -939,7 +947,7 @@ static struct buffer parse_table(struct buffer buff,
|
|||||||
goto success;
|
goto success;
|
||||||
clean:
|
clean:
|
||||||
for (i = 0; i < argi; i++)
|
for (i = 0; i < argi; i++)
|
||||||
argument_free(&args[i]);
|
query_argument_free(&args[i]);
|
||||||
success:
|
success:
|
||||||
return buff;
|
return buff;
|
||||||
}
|
}
|
||||||
@ -954,7 +962,7 @@ void libretrodb_query_free(void *q)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
for (i = 0; i < real_q->root.argc; i++)
|
for (i = 0; i < real_q->root.argc; i++)
|
||||||
argument_free(&real_q->root.argv[i]);
|
query_argument_free(&real_q->root.argv[i]);
|
||||||
|
|
||||||
free(real_q->root.argv);
|
free(real_q->root.argv);
|
||||||
real_q->root.argv = NULL;
|
real_q->root.argv = NULL;
|
||||||
@ -977,24 +985,24 @@ void *libretrodb_query_compile(libretrodb_t *db,
|
|||||||
buff.offset = 0;
|
buff.offset = 0;
|
||||||
*error = NULL;
|
*error = NULL;
|
||||||
|
|
||||||
buff = chomp(buff);
|
buff = query_chomp(buff);
|
||||||
|
|
||||||
if (peek(buff, "{"))
|
if (query_peek(buff, "{"))
|
||||||
{
|
{
|
||||||
buff = parse_table(buff, &q->root, error);
|
buff = query_parse_table(buff, &q->root, error);
|
||||||
if (*error)
|
if (*error)
|
||||||
goto clean;
|
goto clean;
|
||||||
}
|
}
|
||||||
else if (isalpha((int)buff.data[buff.offset]))
|
else if (isalpha((int)buff.data[buff.offset]))
|
||||||
buff = parse_method_call(buff, &q->root, error);
|
buff = query_parse_method_call(buff, &q->root, error);
|
||||||
|
|
||||||
buff = expect_eof(buff, error);
|
buff = query_expect_eof(buff, error);
|
||||||
if (*error)
|
if (*error)
|
||||||
goto clean;
|
goto clean;
|
||||||
|
|
||||||
if (!q->root.func)
|
if (!q->root.func)
|
||||||
{
|
{
|
||||||
raise_unexpected_eof(buff.offset, error);
|
query_raise_unexpected_eof(buff.offset, error);
|
||||||
libretrodb_query_free(q);
|
libretrodb_query_free(q);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user