Add macro expansion queryformat extension
authorPanu Matilainen <pmatilai@redhat.com>
Mon, 8 Feb 2010 08:01:19 +0000 (10:01 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Tue, 9 Feb 2010 07:35:52 +0000 (09:35 +0200)
- unused at the moment but doesn't hurt anything either...

doc/rpm.8
lib/formats.c
lib/rpmtd.h

index ae89d79..47c7ee7 100644 (file)
--- a/doc/rpm.8
+++ b/doc/rpm.8
@@ -469,6 +469,9 @@ Format dependency comparison operator.
 \fB:deptype\fR
 Format dependency type.
 .TP
+\fB:expand\fR
+Perform macro expansion.
+.TP
 \fB:fflags\fR
 Format file flags.
 .TP
index 8e7cb4c..8cc16a0 100644 (file)
@@ -690,6 +690,19 @@ static char * vflagsFormat(rpmtd td, char * formatPrefix)
 
     return val;
 }
+
+static char * expandFormat(rpmtd td, char * formatPrefix)
+{
+    char *val = NULL;
+    if (rpmtdClass(td) != RPM_STRING_CLASS) {
+       val = xstrdup(_("(not a string)"));
+    } else {
+       val = rpmExpand(td->data, NULL);
+    }
+    strcat(formatPrefix, "s");
+    return val;
+}
+
 void *rpmHeaderFormatFuncByName(const char *fmt)
 {
     const struct headerFormatFunc_s * ext;
@@ -738,5 +751,6 @@ static const struct headerFormatFunc_s rpmHeaderFormats[] = {
     { RPMTD_FORMAT_ARRAYSIZE,  "arraysize",    arraysizeFormat },
     { RPMTD_FORMAT_FSTATE,     "fstate",       fstateFormat },
     { RPMTD_FORMAT_VFLAGS,     "vflags",       vflagsFormat },
+    { RPMTD_FORMAT_EXPAND,     "expand",       expandFormat },
     { -1,                      NULL,           NULL }
 };
index 2291442..879af26 100644 (file)
@@ -216,6 +216,7 @@ typedef enum rpmtdFormats_e {
     RPMTD_FORMAT_DEPTYPE       = 15,   /* dependency types (int types) */
     RPMTD_FORMAT_FSTATE                = 16,   /* file states (int types) */
     RPMTD_FORMAT_VFLAGS                = 17,   /* file verify flags (int types) */
+    RPMTD_FORMAT_EXPAND                = 18,   /* macro expansion (string types) */
 } rpmtdFormats;
 
 /** \ingroup rpmtd