From b3e22f60604553005cf0ec8919d21299d3963878 Mon Sep 17 00:00:00 2001 From: meepingsnesroms Date: Wed, 15 Nov 2017 16:42:22 -0800 Subject: [PATCH] Add option to search libretro databases and only print game name --- libretro-db/README.md | 5 ++++ libretro-db/libretrodb_tool.c | 43 +++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/libretro-db/README.md b/libretro-db/README.md index 29e9a11d92..463bc9145e 100644 --- a/libretro-db/README.md +++ b/libretro-db/README.md @@ -66,6 +66,11 @@ Usecase: Search for all games released on October 1995. `libretrodb_tool find "{'releasemonth':10,'releaseyear':1995}"` +3) Names only search +Usecase: Search for all games released on October 1995, wont print checksums, filename or rom size, only the game name. + +`libretrodb_tool get-names "{'releasemonth':10,'releaseyear':1995}"` + # Compiling the Database Use [libretro-super](https://github.com/libretro/libretro-super) to compile the entire database: diff --git a/libretro-db/libretrodb_tool.c b/libretro-db/libretrodb_tool.c index b7e05524b6..b5d8842005 100644 --- a/libretro-db/libretrodb_tool.c +++ b/libretro-db/libretrodb_tool.c @@ -44,6 +44,7 @@ int main(int argc, char ** argv) printf("\tlist\n"); printf("\tcreate-index \n"); printf("\tfind \n"); + printf("\tget-names \n"); return 1; } @@ -113,6 +114,48 @@ int main(int argc, char ** argv) rmsgpack_dom_value_free(&item); } } + else if (memcmp(command, "get-names", 9) == 0) + { + if (argc != 4) + { + printf("Usage: %s find-name \n", argv[0]); + goto error; + } + + query_exp = argv[3]; + error = NULL; + q = libretrodb_query_compile(db, query_exp, strlen(query_exp), &error); + + if (error) + { + printf("%s\n", error); + goto error; + } + + if ((rv = libretrodb_cursor_open(db, cur, q)) != 0) + { + printf("Could not open cursor: %s\n", strerror(-rv)); + goto error; + } + + while (libretrodb_cursor_read_item(cur, &item) == 0) + { + if (item.type == RDT_MAP) //should always be true, but if false the program would segfault + { + unsigned i; + for (i = 0; i < item.val.map.len; i++) + { + if (item.val.map.items[i].key.type == RDT_STRING && (strncmp(item.val.map.items[i].key.val.string.buff, "name", item.val.map.items[i].key.val.string.len) == 0)) + { + rmsgpack_dom_value_print(&item.val.map.items[i].value); + printf("\n"); + } + } + } + + rmsgpack_dom_value_free(&item); + } + } else if (memcmp(command, "create-index", 12) == 0) { const char * index_name, * field_name;