(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,9 +104,21 @@ 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) switch (pCtx->array_depth)
{
case 0:
if (pCtx->object_depth == 1)
{
pCtx->current_string_val = NULL;
if (string_is_equal(pValue, "version"))
pCtx->current_string_val = &pCtx->core_info_cache_list->version;
}
break;
case 1:
if (pCtx->object_depth == 2)
{ {
pCtx->current_string_val = NULL; pCtx->current_string_val = NULL;
pCtx->current_string_list_val = NULL; pCtx->current_string_list_val = NULL;
@ -209,9 +221,7 @@ static bool CCJSONObjectMemberHandler(void *context,
break; break;
} }
} }
else if ( (pCtx->object_depth == 3) else if (pCtx->object_depth == 3)
&& (pCtx->array_depth == 1)
&& length)
{ {
pCtx->current_string_val = NULL; pCtx->current_string_val = NULL;
pCtx->current_entry_uint_val = NULL; pCtx->current_entry_uint_val = NULL;
@ -224,9 +234,9 @@ static bool CCJSONObjectMemberHandler(void *context,
pCtx->current_entry_uint_val = &pCtx->core_info->core_file_id.hash; pCtx->current_entry_uint_val = &pCtx->core_info->core_file_id.hash;
} }
} }
else if ( (pCtx->object_depth == 3) break;
&& (pCtx->array_depth == 2) case 2:
&& length) if (pCtx->object_depth == 3)
{ {
pCtx->current_string_val = NULL; pCtx->current_string_val = NULL;
pCtx->current_entry_bool_val = NULL; pCtx->current_entry_bool_val = NULL;
@ -243,14 +253,9 @@ static bool CCJSONObjectMemberHandler(void *context,
pCtx->current_entry_bool_val = &pCtx->core_info->firmware[firmware_idx].optional; pCtx->current_entry_bool_val = &pCtx->core_info->firmware[firmware_idx].optional;
} }
} }
else if ( (pCtx->object_depth == 1) break;
&& (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,16 +320,19 @@ static bool CCJSONStartObjectHandler(void *context)
pCtx->object_depth++; pCtx->object_depth++;
if ( (pCtx->object_depth == 1) switch (pCtx->array_depth)
&& (pCtx->array_depth == 0)) {
case 0:
if (pCtx->object_depth == 1)
{ {
if (pCtx->core_info_cache_list) if (pCtx->core_info_cache_list)
return false; return false;
if (!(pCtx->core_info_cache_list = core_info_cache_list_new())) if (!(pCtx->core_info_cache_list = core_info_cache_list_new()))
return false; return false;
} }
else if ((pCtx->object_depth == 2) break;
&& (pCtx->array_depth == 1)) case 1:
if (pCtx->object_depth == 2)
{ {
if (pCtx->core_info) if (pCtx->core_info)
{ {
@ -341,10 +349,9 @@ static bool CCJSONStartObjectHandler(void *context)
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*)
@ -363,8 +370,10 @@ static bool CCJSONStartObjectHandler(void *context)
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)) switch (pCtx->object_depth)
{
case 2:
if (pCtx->core_info)
{ {
core_info_cache_add( core_info_cache_add(
pCtx->core_info_cache_list, pCtx->core_info, true); pCtx->core_info_cache_list, pCtx->core_info, true);
free(pCtx->core_info); free(pCtx->core_info);
pCtx->core_info = NULL; pCtx->core_info = NULL;
} }
else if ((pCtx->object_depth == 3) break;
&& (pCtx->array_depth == 1)) case 3:
pCtx->to_core_file_id = false; pCtx->to_core_file_id = false;
break;
default:
break;
}
}
pCtx->object_depth--; pCtx->object_depth--;