From ee6c147a239feb6a5587758b19192f274bd0a529 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Mon, 17 Nov 2008 12:23:19 +0200 Subject: Take advantage of rpmtdGetNumber() for numeric format specifiers - octalFormat() and hexFormat() now work for any number, not just int32, fixing rhbz#471820 - use a common helper-function for both formats, they only differ by o/x --- lib/formats.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) (limited to 'lib/formats.c') diff --git a/lib/formats.c b/lib/formats.c index 4aab74808..fcebef91c 100644 --- a/lib/formats.c +++ b/lib/formats.c @@ -67,25 +67,29 @@ static char * stringFormat(rpmtd td, char *formatPrefix) return val; } -/** - * octalFormat. - * @param td tag data container - * @param formatPrefix sprintf format string - * @return formatted string - */ -static char * octalFormat(rpmtd td, char * formatPrefix) +static char * numFormat(rpmtd td, char * formatPrefix, char *format) { char * val = NULL; - if (rpmtdType(td) != RPM_INT32_TYPE) { + if (rpmtdClass(td) != RPM_NUMERIC_CLASS) { val = xstrdup(_("(not a number)")); } else { - strcat(formatPrefix, "o"); - rasprintf(&val, formatPrefix, *rpmtdGetUint32(td)); + strcat(formatPrefix, format); + rasprintf(&val, formatPrefix, rpmtdGetNumber(td)); } return val; } +/** + * octalFormat. + * @param td tag data container + * @param formatPrefix sprintf format string + * @return formatted string + */ +static char * octalFormat(rpmtd td, char * formatPrefix) +{ + return numFormat(td, formatPrefix, "o"); +} /** * hexFormat. @@ -95,16 +99,7 @@ static char * octalFormat(rpmtd td, char * formatPrefix) */ static char * hexFormat(rpmtd td, char * formatPrefix) { - char * val = NULL; - - if (rpmtdType(td) != RPM_INT32_TYPE) { - val = xstrdup(_("(not a number)")); - } else { - strcat(formatPrefix, "x"); - rasprintf(&val, formatPrefix, *rpmtdGetUint32(td)); - } - - return val; + return numFormat(td, formatPrefix, "x"); } /** -- cgit v1.2.3