Refactor tag name formatting to a helper function

No functional changes, we'll need this in the next commit(s).
This commit is contained in:
Panu Matilainen 2024-02-16 09:55:16 +02:00
parent cefb0a182a
commit 3df1dd3a35
1 changed files with 16 additions and 11 deletions

View File

@ -257,6 +257,19 @@ static void hsaError(headerSprintfArgs hsa, const char *fmt, ...)
}
}
static char *tagName(rpmTagVal tag)
{
const char * tagN = rpmTagGetName(tag);
char *tagval = NULL;
if (rstreq(tagN, "(unknown)")) {
rasprintf(&tagval, "[%u]", tag);
} else {
tagval = xstrdup(tagN);
}
return tagval;
}
static void xmlHeader(headerSprintfArgs hsa)
{
hsaAppend(hsa, "<rpmHeader>\n");
@ -269,19 +282,11 @@ static void xmlFooter(headerSprintfArgs hsa)
static void xmlTagHeader(headerSprintfArgs hsa, rpmTagVal tag, int nelem)
{
const char * tagN = rpmTagGetName(tag);
char *tagval = NULL;
if (rstreq(tagN, "(unknown)")) {
rasprintf(&tagval, "[%u]", tag);
tagN = tagval;
}
char *tagname = tagName(tag);
hsaAppend(hsa, " <rpmTag name=\"");
if (tagN != NULL)
hsaAppend(hsa, tagN);
hsaAppend(hsa, tagname);
hsaAppend(hsa, "\">\n");
free(tagval);
free(tagname);
}
static void xmlTagFooter(headerSprintfArgs hsa, rpmTagVal tag, int nelem)