summaryrefslogtreecommitdiff
path: root/lib/headerfmt.c
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2008-05-19 17:51:42 +0300
committerPanu Matilainen <pmatilai@redhat.com>2008-05-21 12:04:50 +0300
commit2bfc0fad3876bcee0143664cae9f0f0107a86a33 (patch)
tree676b421a767fbf11f52ec5c4f46392b5df339893 /lib/headerfmt.c
parentf12983793ec4683e5083917f97169d23292c7ef7 (diff)
downloadrpm-2bfc0fad3876bcee0143664cae9f0f0107a86a33.tar.gz
Add stringFormat() for barebones string representation
- use for everything not specifically overridden - pushes practically all formatting out of formatValue() into formats.c
Diffstat (limited to 'lib/headerfmt.c')
-rw-r--r--lib/headerfmt.c74
1 files changed, 3 insertions, 71 deletions
diff --git a/lib/headerfmt.c b/lib/headerfmt.c
index 75a5bfac0..4c9b3a5c3 100644
--- a/lib/headerfmt.c
+++ b/lib/headerfmt.c
@@ -399,7 +399,7 @@ static int parseFormat(headerSprintfArgs hsa, char * str,
}
token->u.tag.type = chptr;
} else {
- token->u.tag.type = NULL;
+ token->u.tag.type = "string";
}
if (!*start) {
@@ -675,76 +675,8 @@ static char * formatValue(headerSprintfArgs hsa, sprintfTag tag, int element)
(void) stpcpy( stpcpy(buf, "%"), tag->format);
- if (td->data)
- switch (td->type) {
- case RPM_STRING_ARRAY_TYPE:
- /* fallthrough */
- case RPM_STRING_TYPE:
- if (tag->fmt)
- val = tag->fmt(td, buf, tag->pad);
-
- if (val) {
- need = strlen(val);
- } else {
- str = rpmtdGetString(td);
- need = strlen(str) + tag->pad + 20;
- val = xmalloc(need+1);
- strcat(buf, "s");
- sprintf(val, buf, str);
- }
- break;
-
- case RPM_CHAR_TYPE:
- case RPM_INT8_TYPE:
- case RPM_INT16_TYPE:
- case RPM_INT32_TYPE:
- switch (td->type) {
- case RPM_CHAR_TYPE:
- case RPM_INT8_TYPE:
-#if 0
- /* XXXX unused, remove ? */
- intVal = *(((int8_t *) td->data) + element);
-#endif
- break;
- case RPM_INT16_TYPE:
- intVal = *rpmtdGetUint16(td);
- break;
- default: /* keep -Wall quiet */
- case RPM_INT32_TYPE:
- intVal = *rpmtdGetUint32(td);
- break;
- }
-
- if (tag->fmt)
- val = tag->fmt(td, buf, tag->pad);
-
- if (val) {
- need = strlen(val);
- } else {
- need = 10 + tag->pad + 20;
- val = xmalloc(need+1);
- strcat(buf, "d");
- sprintf(val, buf, intVal);
- }
- break;
-
- case RPM_BIN_TYPE:
- if (tag->fmt)
- val = tag->fmt(td, buf, tag->pad);
-
- if (val) {
- need = strlen(val);
- } else {
- val = pgpHexStr(td->data, td->count);
- need = strlen(val) + tag->pad;
- }
- break;
-
- default:
- need = sizeof("(unknown type)") - 1;
- val = xstrdup("(unknown type)");
- break;
- }
+ val = tag->fmt(td, buf, tag->pad);
+ need = strlen(val);
if (val && need > 0) {
t = hsaReserve(hsa, need);