Make extension formatter functions opaque
authorPanu Matilainen <pmatilai@redhat.com>
Fri, 16 May 2008 13:26:19 +0000 (16:26 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Fri, 16 May 2008 13:26:19 +0000 (16:26 +0300)
- tag extensions are only needed by headerGet(), formats only by headerFormat()

lib/formats.c
lib/header.c
lib/header.h
lib/headerfmt.c

index 1f26450..0b3a204 100644 (file)
@@ -1002,35 +1002,35 @@ static int groupTag(Header h, rpmtd td)
 }
 
 const struct headerSprintfExtension_s rpmHeaderTagExtensions[] = {
-    { "RPMTAG_GROUP",          { groupTag } },
-    { "RPMTAG_DESCRIPTION",    { descriptionTag } },
-    { "RPMTAG_SUMMARY",                { summaryTag } },
-    { "RPMTAG_FILECLASS",      { fileclassTag } },
-    { "RPMTAG_FILENAMES",      { filenamesTag } },
-    { "RPMTAG_FILEPROVIDE",    { fileprovideTag } },
-    { "RPMTAG_FILEREQUIRE",    { filerequireTag } },
-    { "RPMTAG_FSNAMES",                { fsnamesTag } },
-    { "RPMTAG_FSSIZES",                { fssizesTag } },
-    { "RPMTAG_INSTALLPREFIX",  { instprefixTag } },
-    { "RPMTAG_TRIGGERCONDS",   { triggercondsTag } },
-    { "RPMTAG_TRIGGERTYPE",    { triggertypeTag } },
-    { NULL,                    { NULL } }
+    { "RPMTAG_GROUP",          groupTag },
+    { "RPMTAG_DESCRIPTION",    descriptionTag },
+    { "RPMTAG_SUMMARY",                summaryTag },
+    { "RPMTAG_FILECLASS",      fileclassTag },
+    { "RPMTAG_FILENAMES",      filenamesTag },
+    { "RPMTAG_FILEPROVIDE",    fileprovideTag },
+    { "RPMTAG_FILEREQUIRE",    filerequireTag },
+    { "RPMTAG_FSNAMES",                fsnamesTag },
+    { "RPMTAG_FSSIZES",                fssizesTag },
+    { "RPMTAG_INSTALLPREFIX",  instprefixTag },
+    { "RPMTAG_TRIGGERCONDS",   triggercondsTag },
+    { "RPMTAG_TRIGGERTYPE",    triggertypeTag },
+    { NULL,                    NULL }
 };
 
 const struct headerSprintfExtension_s rpmHeaderFormats[] = {
-    { "armor",         { armorFormat } },
-    { "base64",                { base64Format } },
-    { "pgpsig",                { pgpsigFormat } },
-    { "depflags",      { depflagsFormat } },
-    { "fflags",                { fflagsFormat } },
-    { "perms",         { permsFormat } },
-    { "permissions",   { permsFormat } },
-    { "triggertype",   { triggertypeFormat } },
-    { "xml",           { xmlFormat } },
-    { "octal",                 { octalFormat } },
-    { "hex",           { hexFormat } },
-    { "date",          { dateFormat } },
-    { "day",           { dayFormat } },
-    { "shescape",      { shescapeFormat } },
-    { NULL,            { NULL } }
+    { "armor",         armorFormat },
+    { "base64",                base64Format },
+    { "pgpsig",                pgpsigFormat },
+    { "depflags",      depflagsFormat },
+    { "fflags",                fflagsFormat },
+    { "perms",         permsFormat },
+    { "permissions",   permsFormat },
+    { "triggertype",   triggertypeFormat },
+    { "xml",           xmlFormat },
+    { "octal",                 octalFormat },
+    { "hex",           hexFormat },
+    { "date",          dateFormat },
+    { "day",           dayFormat },
+    { "shescape",      shescapeFormat },
+    { NULL,            NULL }
 };
index 5f0606d..05bfdb0 100644 (file)
@@ -82,6 +82,16 @@ static const int typeSizes[16] =  {
  */
 static const size_t headerMaxbytes = (32*1024*1024);
 
+/** \ingroup header
+ * HEADER_EXT_TAG format function prototype.
+ * This is allowed to fail, which indicates the tag doesn't exist.
+ *
+ * @param h            header
+ * @retval td          tag data container
+ * @return             0 on success
+ */
+typedef int (*headerTagTagFunction) (Header h, rpmtd td);
+
 Header headerLink(Header h)
 {
     if (h == NULL) return NULL;
@@ -1383,7 +1393,7 @@ static headerTagTagFunction findExtFunc(rpmTag tag)
 
     for (; ext != NULL && ext->name != NULL; ext++) {
        if (!rstrcasecmp(ext->name + sizeof("RPMTAG"), tagname)) {
-           func = ext->u.tagFunction;
+           func = ext->func;
            break;
        }
     }
index e74566c..237d36f 100644 (file)
@@ -38,42 +38,12 @@ struct headerTagTableEntry_s {
 typedef struct headerTagIndices_s * headerTagIndices;
 
 /** \ingroup header
- * HEADER_EXT_FORMAT format function prototype.
- * This will only ever be passed RPM_INT32_TYPE or RPM_STRING_TYPE to
- * help keep things simple.
- *
- * @param type         tag type
- * @param data         tag value
- * @param formatPrefix
- * @param padding
- * @param element      RPM_BIN_TYPE: no. bytes of data
- * @return             formatted string
- */
-typedef char * (*headerTagFormatFunction)(rpmTagType type,
-                               rpm_constdata_t data, char * formatPrefix,
-                               size_t padding, rpm_count_t element);
-
-/** \ingroup header
- * HEADER_EXT_TAG format function prototype.
- * This is allowed to fail, which indicates the tag doesn't exist.
- *
- * @param h            header
- * @retval td          tag data container
- * @return             0 on success
- */
-typedef int (*headerTagTagFunction) (Header h, rpmtd td);
-
-/** \ingroup header
  * Define header tag output formats.
  */
 typedef const struct headerSprintfExtension_s * headerSprintfExtension;
 struct headerSprintfExtension_s {
-    const char * name;                         /*!< Name of extension. */
-    union {
-       void * generic;                         /*!< Private extension. */
-       headerTagFormatFunction formatFunction; /*!< HEADER_EXT_TAG extension. */
-       headerTagTagFunction tagFunction;       /*!< HEADER_EXT_FORMAT extension. */
-    } u;
+    const char *name;  /*!< Name of extension. */
+    void *func;                /*!< Pointer to formatter function. */  
 };
 
 /** \ingroup rpmtag
index 8b941ad..a313b47 100644 (file)
 #define PARSER_IN_EXPR  2
 
 /** \ingroup header
+ * HEADER_EXT_FORMAT format function prototype.
+ * This will only ever be passed RPM_INT32_TYPE or RPM_STRING_TYPE to
+ * help keep things simple.
+ *
+ * @param type         tag type
+ * @param data         tag value
+ * @param formatPrefix
+ * @param padding
+ * @param element      RPM_BIN_TYPE: no. bytes of data
+ * @return             formatted string
+ */
+typedef char * (*headerTagFormatFunction)(rpmTagType type,
+                               rpm_constdata_t data, char * formatPrefix,
+                               size_t padding, rpm_count_t element);
+
+/** \ingroup header
  */
 typedef struct sprintfTag_s * sprintfTag;
 struct sprintfTag_s {
@@ -246,7 +262,7 @@ bingo:
     if (stag->type != NULL)
     for (; ext != NULL && ext->name != NULL; ext++) {
        if (!strcmp(ext->name, stag->type)) {
-           stag->fmt = ext->u.formatFunction;
+           stag->fmt = ext->func;
            break;
        }
     }