(core_info.c) Cleanups

This commit is contained in:
libretroadmin 2024-07-24 09:55:34 +02:00
parent ac85405598
commit efbfe3610a

View file

@ -104,153 +104,158 @@ static bool CCJSONObjectMemberHandler(void *context,
{ {
CCJSONContext *pCtx = (CCJSONContext *)context; CCJSONContext *pCtx = (CCJSONContext *)context;
if ( (pCtx->object_depth == 2) if (length)
&& (pCtx->array_depth == 1)
&& length)
{ {
pCtx->current_string_val = NULL; switch (pCtx->array_depth)
pCtx->current_string_list_val = NULL;
pCtx->current_entry_uint_val = NULL;
pCtx->current_entry_bool_val = NULL;
pCtx->to_core_file_id = false;
pCtx->to_firmware = false;
switch (pValue[0])
{ {
case 'a': case 0:
if (string_is_equal(pValue, "authors")) if (pCtx->object_depth == 1)
{ {
pCtx->current_string_val = &pCtx->core_info->authors; pCtx->current_string_val = NULL;
pCtx->current_string_list_val = &pCtx->core_info->authors_list;
if (string_is_equal(pValue, "version"))
pCtx->current_string_val = &pCtx->core_info_cache_list->version;
} }
break; break;
case 'c': case 1:
if (string_is_equal(pValue, "categories")) if (pCtx->object_depth == 2)
{ {
pCtx->current_string_val = &pCtx->core_info->categories; pCtx->current_string_val = NULL;
pCtx->current_string_list_val = &pCtx->core_info->categories_list; pCtx->current_string_list_val = NULL;
pCtx->current_entry_uint_val = NULL;
pCtx->current_entry_bool_val = NULL;
pCtx->to_core_file_id = false;
pCtx->to_firmware = false;
switch (pValue[0])
{
case 'a':
if (string_is_equal(pValue, "authors"))
{
pCtx->current_string_val = &pCtx->core_info->authors;
pCtx->current_string_list_val = &pCtx->core_info->authors_list;
}
break;
case 'c':
if (string_is_equal(pValue, "categories"))
{
pCtx->current_string_val = &pCtx->core_info->categories;
pCtx->current_string_list_val = &pCtx->core_info->categories_list;
}
else if (string_is_equal(pValue, "core_name"))
pCtx->current_string_val = &pCtx->core_info->core_name;
else if (string_is_equal(pValue, "core_file_id"))
pCtx->to_core_file_id = true;
break;
case 'd':
if (string_is_equal(pValue, "display_name"))
pCtx->current_string_val = &pCtx->core_info->display_name;
else if (string_is_equal(pValue, "display_version"))
pCtx->current_string_val = &pCtx->core_info->display_version;
else if (string_is_equal(pValue, "databases"))
{
pCtx->current_string_val = &pCtx->core_info->databases;
pCtx->current_string_list_val = &pCtx->core_info->databases_list;
}
else if (string_is_equal(pValue, "description"))
pCtx->current_string_val = &pCtx->core_info->description;
else if (string_is_equal(pValue, "database_match_archive_member"))
pCtx->current_entry_bool_val = &pCtx->core_info->database_match_archive_member;
break;
case 'f':
if (string_is_equal(pValue, "firmware"))
pCtx->to_firmware = true;
break;
case 'h':
if (string_is_equal(pValue, "has_info"))
pCtx->current_entry_bool_val = &pCtx->core_info->has_info;
break;
case 'l':
if (string_is_equal(pValue, "licenses"))
{
pCtx->current_string_val = &pCtx->core_info->licenses;
pCtx->current_string_list_val = &pCtx->core_info->licenses_list;
}
else if (string_is_equal(pValue, "is_experimental"))
pCtx->current_entry_bool_val = &pCtx->core_info->is_experimental;
break;
case 'n':
if (string_is_equal(pValue, "notes"))
{
pCtx->current_string_val = &pCtx->core_info->notes;
pCtx->current_string_list_val = &pCtx->core_info->note_list;
}
break;
case 'p':
if (string_is_equal(pValue, "permissions"))
{
pCtx->current_string_val = &pCtx->core_info->permissions;
pCtx->current_string_list_val = &pCtx->core_info->permissions_list;
}
break;
case 'r':
if (string_is_equal(pValue, "required_hw_api"))
{
pCtx->current_string_val = &pCtx->core_info->required_hw_api;
pCtx->current_string_list_val = &pCtx->core_info->required_hw_api_list;
}
break;
case 's':
if (string_is_equal(pValue, "system_manufacturer"))
pCtx->current_string_val = &pCtx->core_info->system_manufacturer;
else if (string_is_equal(pValue, "systemname"))
pCtx->current_string_val = &pCtx->core_info->systemname;
else if (string_is_equal(pValue, "system_id"))
pCtx->current_string_val = &pCtx->core_info->system_id;
else if (string_is_equal(pValue, "supported_extensions"))
{
pCtx->current_string_val = &pCtx->core_info->supported_extensions;
pCtx->current_string_list_val = &pCtx->core_info->supported_extensions_list;
}
else if (string_is_equal(pValue, "supports_no_game"))
pCtx->current_entry_bool_val = &pCtx->core_info->supports_no_game;
else if (string_is_equal(pValue, "single_purpose"))
pCtx->current_entry_bool_val = &pCtx->core_info->single_purpose;
else if (string_is_equal(pValue, "savestate_support_level"))
pCtx->current_entry_uint_val = &pCtx->core_info->savestate_support_level;
break;
}
} }
else if (string_is_equal(pValue, "core_name")) else if (pCtx->object_depth == 3)
pCtx->current_string_val = &pCtx->core_info->core_name;
else if (string_is_equal(pValue, "core_file_id"))
pCtx->to_core_file_id = true;
break;
case 'd':
if (string_is_equal(pValue, "display_name"))
pCtx->current_string_val = &pCtx->core_info->display_name;
else if (string_is_equal(pValue, "display_version"))
pCtx->current_string_val = &pCtx->core_info->display_version;
else if (string_is_equal(pValue, "databases"))
{ {
pCtx->current_string_val = &pCtx->core_info->databases; pCtx->current_string_val = NULL;
pCtx->current_string_list_val = &pCtx->core_info->databases_list; pCtx->current_entry_uint_val = NULL;
}
else if (string_is_equal(pValue, "description")) if (pCtx->to_core_file_id)
pCtx->current_string_val = &pCtx->core_info->description; {
else if (string_is_equal(pValue, "database_match_archive_member")) if (string_is_equal(pValue, "str"))
pCtx->current_entry_bool_val = &pCtx->core_info->database_match_archive_member; pCtx->current_string_val = &pCtx->core_info->core_file_id.str;
break; else if (string_is_equal(pValue, "hash"))
case 'f': pCtx->current_entry_uint_val = &pCtx->core_info->core_file_id.hash;
if (string_is_equal(pValue, "firmware")) }
pCtx->to_firmware = true;
break;
case 'h':
if (string_is_equal(pValue, "has_info"))
pCtx->current_entry_bool_val = &pCtx->core_info->has_info;
break;
case 'l':
if (string_is_equal(pValue, "licenses"))
{
pCtx->current_string_val = &pCtx->core_info->licenses;
pCtx->current_string_list_val = &pCtx->core_info->licenses_list;
}
else if (string_is_equal(pValue, "is_experimental"))
pCtx->current_entry_bool_val = &pCtx->core_info->is_experimental;
break;
case 'n':
if (string_is_equal(pValue, "notes"))
{
pCtx->current_string_val = &pCtx->core_info->notes;
pCtx->current_string_list_val = &pCtx->core_info->note_list;
} }
break; break;
case 'p': case 2:
if (string_is_equal(pValue, "permissions")) if (pCtx->object_depth == 3)
{ {
pCtx->current_string_val = &pCtx->core_info->permissions; pCtx->current_string_val = NULL;
pCtx->current_string_list_val = &pCtx->core_info->permissions_list; pCtx->current_entry_bool_val = NULL;
if (pCtx->to_firmware && (pCtx->core_info->firmware_count > 0))
{
size_t firmware_idx = pCtx->core_info->firmware_count - 1;
if (string_is_equal(pValue, "path"))
pCtx->current_string_val = &pCtx->core_info->firmware[firmware_idx].path;
else if (string_is_equal(pValue, "desc"))
pCtx->current_string_val = &pCtx->core_info->firmware[firmware_idx].desc;
else if (string_is_equal(pValue, "optional"))
pCtx->current_entry_bool_val = &pCtx->core_info->firmware[firmware_idx].optional;
}
} }
break; break;
case 'r':
if (string_is_equal(pValue, "required_hw_api"))
{
pCtx->current_string_val = &pCtx->core_info->required_hw_api;
pCtx->current_string_list_val = &pCtx->core_info->required_hw_api_list;
}
break;
case 's':
if (string_is_equal(pValue, "system_manufacturer"))
pCtx->current_string_val = &pCtx->core_info->system_manufacturer;
else if (string_is_equal(pValue, "systemname"))
pCtx->current_string_val = &pCtx->core_info->systemname;
else if (string_is_equal(pValue, "system_id"))
pCtx->current_string_val = &pCtx->core_info->system_id;
else if (string_is_equal(pValue, "supported_extensions"))
{
pCtx->current_string_val = &pCtx->core_info->supported_extensions;
pCtx->current_string_list_val = &pCtx->core_info->supported_extensions_list;
}
else if (string_is_equal(pValue, "supports_no_game"))
pCtx->current_entry_bool_val = &pCtx->core_info->supports_no_game;
else if (string_is_equal(pValue, "single_purpose"))
pCtx->current_entry_bool_val = &pCtx->core_info->single_purpose;
else if (string_is_equal(pValue, "savestate_support_level"))
pCtx->current_entry_uint_val = &pCtx->core_info->savestate_support_level;
break;
} }
}
else if ( (pCtx->object_depth == 3)
&& (pCtx->array_depth == 1)
&& length)
{
pCtx->current_string_val = NULL;
pCtx->current_entry_uint_val = NULL;
if (pCtx->to_core_file_id)
{
if (string_is_equal(pValue, "str"))
pCtx->current_string_val = &pCtx->core_info->core_file_id.str;
else if (string_is_equal(pValue, "hash"))
pCtx->current_entry_uint_val = &pCtx->core_info->core_file_id.hash;
}
}
else if ( (pCtx->object_depth == 3)
&& (pCtx->array_depth == 2)
&& length)
{
pCtx->current_string_val = NULL;
pCtx->current_entry_bool_val = NULL;
if (pCtx->to_firmware && (pCtx->core_info->firmware_count > 0))
{
size_t firmware_idx = pCtx->core_info->firmware_count - 1;
if (string_is_equal(pValue, "path"))
pCtx->current_string_val = &pCtx->core_info->firmware[firmware_idx].path;
else if (string_is_equal(pValue, "desc"))
pCtx->current_string_val = &pCtx->core_info->firmware[firmware_idx].desc;
else if (string_is_equal(pValue, "optional"))
pCtx->current_entry_bool_val = &pCtx->core_info->firmware[firmware_idx].optional;
}
}
else if ( (pCtx->object_depth == 1)
&& (pCtx->array_depth == 0)
&& length)
{
pCtx->current_string_val = NULL;
if (string_is_equal(pValue, "version"))
pCtx->current_string_val = &pCtx->core_info_cache_list->version;
} }
return true; return true;
@ -315,56 +320,60 @@ static bool CCJSONStartObjectHandler(void *context)
pCtx->object_depth++; pCtx->object_depth++;
if ( (pCtx->object_depth == 1) switch (pCtx->array_depth)
&& (pCtx->array_depth == 0))
{ {
if (pCtx->core_info_cache_list) case 0:
return false; if (pCtx->object_depth == 1)
if (!(pCtx->core_info_cache_list = core_info_cache_list_new())) {
return false; if (pCtx->core_info_cache_list)
} return false;
else if ((pCtx->object_depth == 2) if (!(pCtx->core_info_cache_list = core_info_cache_list_new()))
&& (pCtx->array_depth == 1)) return false;
{ }
if (pCtx->core_info) break;
{ case 1:
core_info_free(pCtx->core_info); if (pCtx->object_depth == 2)
free(pCtx->core_info); {
pCtx->core_info = NULL; if (pCtx->core_info)
} {
core_info_free(pCtx->core_info);
free(pCtx->core_info);
pCtx->core_info = NULL;
}
if (!(pCtx->core_info = (core_info_t*)calloc(1, sizeof(core_info_t)))) if (!(pCtx->core_info = (core_info_t*)calloc(1, sizeof(core_info_t))))
return false; return false;
/* Assume all cores have 'full' savestate support /* Assume all cores have 'full' savestate support
* by default */ * by default */
pCtx->core_info->savestate_support_level = pCtx->core_info->savestate_support_level =
CORE_INFO_SAVESTATE_DETERMINISTIC; CORE_INFO_SAVESTATE_DETERMINISTIC;
} }
else if ((pCtx->object_depth == 3) break;
&& (pCtx->array_depth == 2)) case 2:
{ if (pCtx->object_depth == 3 && pCtx->to_firmware)
if (pCtx->to_firmware) {
{ size_t new_idx = pCtx->core_info->firmware_count;
size_t new_idx = pCtx->core_info->firmware_count; core_info_firmware_t *tmp = (core_info_firmware_t*)
core_info_firmware_t *tmp = (core_info_firmware_t*)
realloc(pCtx->core_info->firmware, realloc(pCtx->core_info->firmware,
(pCtx->core_info->firmware_count + 1) (pCtx->core_info->firmware_count + 1)
* sizeof(core_info_firmware_t)); * sizeof(core_info_firmware_t));
if (!tmp) if (!tmp)
return false; return false;
tmp[new_idx].path = NULL; tmp[new_idx].path = NULL;
tmp[new_idx].desc = NULL; tmp[new_idx].desc = NULL;
tmp[new_idx].missing = false; tmp[new_idx].missing = false;
tmp[new_idx].optional = false; tmp[new_idx].optional = false;
pCtx->core_info->firmware = tmp; pCtx->core_info->firmware = tmp;
pCtx->core_info->firmware_count++; pCtx->core_info->firmware_count++;
} }
break;
} }
return true; return true;
} }
@ -372,18 +381,26 @@ static bool CCJSONEndObjectHandler(void *context)
{ {
CCJSONContext *pCtx = (CCJSONContext*)context; CCJSONContext *pCtx = (CCJSONContext*)context;
if ( (pCtx->object_depth == 2) if (pCtx->array_depth == 1)
&& (pCtx->array_depth == 1)
&& (pCtx->core_info))
{ {
core_info_cache_add( switch (pCtx->object_depth)
pCtx->core_info_cache_list, pCtx->core_info, true); {
free(pCtx->core_info); case 2:
pCtx->core_info = NULL; if (pCtx->core_info)
{
core_info_cache_add(
pCtx->core_info_cache_list, pCtx->core_info, true);
free(pCtx->core_info);
pCtx->core_info = NULL;
}
break;
case 3:
pCtx->to_core_file_id = false;
break;
default:
break;
}
} }
else if ((pCtx->object_depth == 3)
&& (pCtx->array_depth == 1))
pCtx->to_core_file_id = false;
pCtx->object_depth--; pCtx->object_depth--;