skin_parser add empty parser callback remove guard conditionals

it appears callback is only set once in skin_parse() and then its never touched again
making repeatd checks pointless anyway

Change-Id: Iae4cb064b17f9c4e89a3ef772110ead17332cba2
This commit is contained in:
William Wilgus 2024-12-08 11:53:07 -05:00 committed by William Wilgus
parent bc1d7d77c5
commit ca79fd039c

View file

@ -38,8 +38,9 @@ char* skin_start = 0;
static int viewport_line = 0; static int viewport_line = 0;
#ifdef ROCKBOX #ifdef ROCKBOX
static skin_callback callback = NULL; static int empty_callback(struct skin_element* element, void* data);
static void* callback_data; static skin_callback callback = &empty_callback;
static void* callback_data = NULL;
#endif #endif
/* Auxiliary parsing functions (not visible at global scope) */ /* Auxiliary parsing functions (not visible at global scope) */
@ -71,6 +72,13 @@ static void skip_whitespace(const char** document)
} }
#ifdef ROCKBOX #ifdef ROCKBOX
static int empty_callback(struct skin_element* element, void* data)
{
(void)element;
(void)data;
return CALLBACK_OK;
}
struct skin_element* skin_parse(const char* document, struct skin_element* skin_parse(const char* document,
skin_callback cb, void* cb_data) skin_callback cb, void* cb_data)
{ {
@ -153,7 +161,7 @@ static struct skin_element* skin_parse_viewport(const char** document)
} }
} }
#ifdef ROCKBOX #ifdef ROCKBOX
else if (callback) else
{ {
if (callback(retval, callback_data) == CALLBACK_ERROR) if (callback(retval, callback_data) == CALLBACK_ERROR)
{ {
@ -331,16 +339,10 @@ static struct skin_element* skin_parse_line_optional(const char** document,
} }
#ifdef ROCKBOX #ifdef ROCKBOX
if (callback) if (callback(retval, callback_data) == CALLBACK_ERROR)
{ {
switch (callback(retval, callback_data))
{
case CALLBACK_ERROR:
skin_error(GOT_CALLBACK_ERROR, cursor); skin_error(GOT_CALLBACK_ERROR, cursor);
return NULL; return NULL;
default:
break;
}
} }
#endif #endif
@ -480,14 +482,11 @@ static struct skin_element* skin_parse_sublines_optional(const char** document,
} }
#ifdef ROCKBOX #ifdef ROCKBOX
if (callback)
{
if (callback(retval, callback_data) == CALLBACK_ERROR) if (callback(retval, callback_data) == CALLBACK_ERROR)
{ {
skin_error(GOT_CALLBACK_ERROR, *document); skin_error(GOT_CALLBACK_ERROR, *document);
return NULL; return NULL;
} }
}
#endif #endif
*document = cursor; *document = cursor;
retval->children = skin_buffer_to_offset(children); retval->children = skin_buffer_to_offset(children);
@ -542,14 +541,11 @@ static int skin_parse_tag(struct skin_element* element, const char** document)
{ {
#ifdef ROCKBOX #ifdef ROCKBOX
if (callback)
{
if (callback(element, callback_data) == CALLBACK_ERROR) if (callback(element, callback_data) == CALLBACK_ERROR)
{ {
skin_error(GOT_CALLBACK_ERROR, cursor); skin_error(GOT_CALLBACK_ERROR, cursor);
return 0; return 0;
} }
}
#endif #endif
*document = cursor; *document = cursor;
return 1; return 1;
@ -826,14 +822,11 @@ static int skin_parse_tag(struct skin_element* element, const char** document)
return 0; return 0;
} }
#ifdef ROCKBOX #ifdef ROCKBOX
if (callback)
{
if (callback(element, callback_data) == CALLBACK_ERROR) if (callback(element, callback_data) == CALLBACK_ERROR)
{ {
skin_error(GOT_CALLBACK_ERROR, *document); skin_error(GOT_CALLBACK_ERROR, *document);
return 0; return 0;
} }
}
#endif #endif
*document = cursor; *document = cursor;
@ -897,14 +890,11 @@ static int skin_parse_text(struct skin_element* element, const char** document,
text[length] = '\0'; text[length] = '\0';
#ifdef ROCKBOX #ifdef ROCKBOX
if (callback)
{
if (callback(element, callback_data) == CALLBACK_ERROR) if (callback(element, callback_data) == CALLBACK_ERROR)
{ {
skin_error(GOT_CALLBACK_ERROR, *document); skin_error(GOT_CALLBACK_ERROR, *document);
return 0; return 0;
} }
}
#endif #endif
*document = cursor; *document = cursor;
@ -940,8 +930,6 @@ static int skin_parse_conditional(struct skin_element* element, const char** doc
element->type = CONDITIONAL; element->type = CONDITIONAL;
#ifdef ROCKBOX #ifdef ROCKBOX
if (callback)
{
switch (callback(element, callback_data)) switch (callback(element, callback_data))
{ {
case FEATURE_NOT_AVAILABLE: case FEATURE_NOT_AVAILABLE:
@ -952,7 +940,6 @@ static int skin_parse_conditional(struct skin_element* element, const char** doc
default: default:
break; break;
} }
}
#endif #endif
/* Counting the children */ /* Counting the children */