[Rpm-maint] [PATCH 1/3] Add identityMatch() function generator

Vladimir D. Seleznev vseleznv at altlinux.org
Wed Aug 22 21:01:45 UTC 2018


identityMatch() matches tag that should be awared in identity
calculation. The function generator inspects rpmtag.h tag list for tag
identity marker and constructs positive filter function that is adding
to tagext.c.

Signed-off-by: Vladimir D. Seleznev <vseleznv at altlinux.org>
---
 lib/Makefile.am         |  8 ++++++--
 lib/genidentitymatch.sh | 35 +++++++++++++++++++++++++++++++++++
 lib/tagexts.c           |  2 ++
 3 files changed, 43 insertions(+), 2 deletions(-)
 create mode 100644 lib/genidentitymatch.sh

diff --git a/lib/Makefile.am b/lib/Makefile.am
index baf3238ee..f88d35144 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -19,7 +19,7 @@ usrlibdir = $(libdir)
 
 check_PROGRAMS =
 CLEANFILES =
-EXTRA_DIST = gentagtbl.sh tagtbl.C rpmhash.C rpmhash.H
+EXTRA_DIST = gentagtbl.sh tagtbl.C genidentitymatch.C identitymatch.C rpmhash.C rpmhash.H
 EXTRA_PROGRAMS =
 
 usrlib_LTLIBRARIES = librpm.la
@@ -87,7 +87,11 @@ tagtbl.C: Makefile.am $(srcdir)/rpmtag.h gentagtbl.sh
 	@AWK=${AWK} ${SHELL} $(srcdir)/gentagtbl.sh \
 		    	     $(srcdir)/rpmtag.h > $@.new && \
 	 mv -f $@.new $@
-BUILT_SOURCES = tagtbl.C
+identitymatch.C: Makefile.am $(srcdir)/rpmtag.h genidentitymatch.sh
+	@AWK=${AWK} ${SHELL} $(srcdir)/genidentitymatch.sh \
+			     $(srcdir)/rpmtag.h > $@.new && \
+	mv -f $@.new $@
+BUILT_SOURCES = tagtbl.C identitymatch.C
 
 if WITH_INTERNAL_DB
 # XXX watchout, $(top_builddir)/db3/libdb.la created by this Makefile may surprise
diff --git a/lib/genidentitymatch.sh b/lib/genidentitymatch.sh
new file mode 100644
index 000000000..924c9c301
--- /dev/null
+++ b/lib/genidentitymatch.sh
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+cat <<EOF
+static int identityMatch(rpmTag tag)
+{
+    switch(tag) {
+EOF
+
+tmp="$(mktemp)"
+${AWK} '/[\t ](RPMTAG_[A-Z0-9]*)[ \t]+([0-9]*)/ && !/internal/ && !/unimplemented/ && !/^#define/ {
+	if ($6 == "identity") {
+		identity_is_present = 1
+		printf("    case %s:\n", $1)
+	}
+}' < $1 | sort -b > $tmp
+
+if [ -s "$tmp" ]; then
+    cat "$tmp"
+    cat <<EOF
+    /* this case is used to check identity marker presence in rpmtag.h */
+    case 0:
+	return 1;
+	break;
+EOF
+fi
+rm -f "$tmp"
+
+cat << EOF
+    default:
+	break;
+    }
+    return 0;
+}
+EOF
+
diff --git a/lib/tagexts.c b/lib/tagexts.c
index f72ff60f1..61e9b702b 100644
--- a/lib/tagexts.c
+++ b/lib/tagexts.c
@@ -952,6 +952,8 @@ static int filenlinksTag(Header h, rpmtd td, headerGetFlags hgflags)
     return (fc > 0);
 }
 
+#include "identitymatch.C"
+
 static const struct headerTagFunc_s rpmHeaderTagExtensions[] = {
     { RPMTAG_GROUP,		groupTag },
     { RPMTAG_DESCRIPTION,	descriptionTag },
-- 
2.17.1



More information about the Rpm-maint mailing list