From 6fbc02a6b4b8a8e7614411928ab6f90772f43bcc Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 20 Jan 2015 01:00:17 +0100 Subject: [PATCH] Update libretroDB and bake in compat_fnmatch.c --- Makefile.common | 3 ++- griffin/griffin.c | 1 + libretrodb/Makefile | 3 +++ libretrodb/query.c | 47 ++++++++++++++++++++++++++++++++------- libretrodb/rarchdb_tool.c | 2 +- libretrodb/tests.lua | 1 + libretrodb/uncrustify.cfg | 4 ++-- 7 files changed, 49 insertions(+), 12 deletions(-) diff --git a/Makefile.common b/Makefile.common index 66a2fa3250..070226794e 100644 --- a/Makefile.common +++ b/Makefile.common @@ -130,6 +130,7 @@ OBJ += frontend/frontend.o \ libretro-sdk/queues/fifo_buffer.o \ core_options.o \ libretro-sdk/compat/compat.o \ + libretro-sdk/compat/compat_fnmatch.o \ cheats.o \ core_info.o \ libretro-sdk/file/config_file.o \ @@ -162,7 +163,7 @@ OBJ += frontend/frontend.o \ record/record_driver.o \ performance.o -# RarchDB +# LibretroDB OBJ += libretrodb/bintree.o \ libretrodb/rarchdb.o \ diff --git a/griffin/griffin.c b/griffin/griffin.c index d9c7e08d1a..5d2c883d59 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -62,6 +62,7 @@ PERFORMANCE COMPATIBILITY ============================================================ */ #include "../compat/compat.c" +#include "../libretro-sdk/compat/compat_fnmatch.c" /*============================================================ CONFIG FILE diff --git a/libretrodb/Makefile b/libretrodb/Makefile index 0ab0fc6559..df66a51e95 100644 --- a/libretrodb/Makefile +++ b/libretrodb/Makefile @@ -8,6 +8,7 @@ LUA_CONVERTER_OBJ = rmsgpack.o \ bintree.o \ query.o \ lua_converter.o \ + rl_fnmatch.c \ $(NULL) RARCHDB_TOOL_OBJ = rmsgpack.o \ @@ -16,11 +17,13 @@ RARCHDB_TOOL_OBJ = rmsgpack.o \ bintree.o \ query.o \ rarchdb.o \ + rl_fnmatch.c \ $(NULL) TESTLIB_C = testlib.c \ lua_common.c \ query.c \ + rl_fnmatch.c \ rarchdb.c \ bintree.c \ rmsgpack.c \ diff --git a/libretrodb/query.c b/libretrodb/query.c index 833778b2e2..a388df29df 100644 --- a/libretrodb/query.c +++ b/libretrodb/query.c @@ -7,6 +7,7 @@ #include "rarchdb.h" #include "rmsgpack_dom.h" +#include #define MAX_ERROR_LEN 256 #define MAX_ARGS 50 @@ -314,6 +315,32 @@ static struct rmsgpack_dom_value operator_and ( return res; } +static struct rmsgpack_dom_value q_glob ( + struct rmsgpack_dom_value input, + unsigned argc, + const struct argument * argv +) { + struct rmsgpack_dom_value res; + unsigned i; + res.type = RDT_BOOL; + res.bool_ = 0; + if (argc != 1) { + return res; + } + if (argv[0].type != AT_VALUE || argv[0].value.type != RDT_STRING) { + return res; + } + if (input.type != RDT_STRING) { + return res; + } + res.bool_ = rl_fnmatch( + argv[0].value.string.buff, + input.string.buff, + 0 + ) == 0; + return res; +} + static struct rmsgpack_dom_value all_map ( struct rmsgpack_dom_value input, unsigned argc, @@ -372,6 +399,7 @@ struct registered_func registered_functions[100] = { {"or", operator_or}, {"and", operator_and}, {"between", between}, + {"glob", q_glob}, {NULL, NULL} }; @@ -468,10 +496,13 @@ static struct buffer parse_string( struct rmsgpack_dom_value * value, const char ** error ) { - char terminator; + char terminator = '\0'; char c; const char * str_start; buff = get_char(buff, &terminator, error); + if (*error) { + return buff; + } if (terminator != '"' && terminator != '\'') { buff.offset--; raise_expected_string(buff.offset, error); @@ -683,7 +714,7 @@ static struct buffer parse_argument( ) { arg->type = AT_FUNCTION; buff = parse_method_call(buff, &arg->invocation, error); - } else if (peek(buff, "{")){ + } else if (peek(buff, "{")) { arg->type = AT_FUNCTION; buff = parse_table(buff, &arg->invocation, error); } else { @@ -724,16 +755,16 @@ static struct buffer parse_table( args[argi].value.type = RDT_STRING; args[argi].value.string.len = ident_len; args[argi].value.string.buff = calloc( - ident_len + 1, - sizeof(char) - ); + ident_len + 1, + sizeof(char) + ); if (!args[argi].value.string.buff) { goto clean; } strncpy( - args[argi].value.string.buff, - ident_name, - ident_len + args[argi].value.string.buff, + ident_name, + ident_len ); } } else { diff --git a/libretrodb/rarchdb_tool.c b/libretrodb/rarchdb_tool.c index 23adf56a24..a10a1bbeeb 100644 --- a/libretrodb/rarchdb_tool.c +++ b/libretrodb/rarchdb_tool.c @@ -78,7 +78,7 @@ int main( rarchdb_create_index(&db, index_name, field_name); } else { - printf("Unkonwn command %s\n", argv[1]); + printf("Unkonwn command %s\n", argv[2]); return 1; } rarchdb_close(&db); diff --git a/libretrodb/tests.lua b/libretrodb/tests.lua index 95d4e48f01..928f747c7d 100644 --- a/libretrodb/tests.lua +++ b/libretrodb/tests.lua @@ -71,6 +71,7 @@ tests = { test_string_field = query_test({{a="test"}, {a=4}}, {{a="test"}}, "{'a':'test'}"), test_or_operator = query_test({{a="test"}, {a=4}, {a=5}}, {{a="test"}, {a=4}}, "{'a':or('test', 4)}"), test_or_between = query_test({{a="test"}, {a=4}, {a=5}, {}}, {{a="test"}, {a=4}, {a=5}}, "{'a':or('test', between(2, 7))}"), + test_glob = query_test({{a="abc"}, {a="acd"}}, {{a="abc"}}, "{'a':glob('*b*')}"), test_root_function = query_test({{a=1}, {b=4}, {a=5}, {}}, {{a=1}, {b=4}}, "or({a:1},{b:4})"), } for name, cb in pairs(tests) do diff --git a/libretrodb/uncrustify.cfg b/libretrodb/uncrustify.cfg index 84e6af77ee..2e3b287585 100644 --- a/libretrodb/uncrustify.cfg +++ b/libretrodb/uncrustify.cfg @@ -121,10 +121,10 @@ indent_func_def_force_col1 = false # false/true # True: indent continued function call parameters one indent level # False: align parameters under the open paren -indent_func_call_param = false # false/true +indent_func_call_param = true # false/true # Same as indent_func_call_param, but for function defs -indent_func_def_param = false # false/true +indent_func_def_param = true # false/true # Same as indent_func_call_param, but for function protos indent_func_proto_param = false # false/true