Merge pull request #5680 from meepingsnesroms/master

Add option to search libretro databases and only print game name (for libretrodb-tool)
This commit is contained in:
Twinaphex 2017-11-16 08:20:38 +01:00 committed by GitHub
commit 1dc19d347c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 0 deletions

View File

@ -66,6 +66,11 @@ Usecase: Search for all games released on October 1995.
`libretrodb_tool <db file> 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 <db file> get-names "{'releasemonth':10,'releaseyear':1995}"`
# Compiling the Database
Use [libretro-super](https://github.com/libretro/libretro-super) to compile the entire database:

View File

@ -44,6 +44,7 @@ int main(int argc, char ** argv)
printf("\tlist\n");
printf("\tcreate-index <index name> <field name>\n");
printf("\tfind <query expression>\n");
printf("\tget-names <query expression>\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 <db file> find-name <query expression>\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;