RPM Package Manager, CVS Repository
http://rpm5.org/cvs/
____________________________________________________________________________
Server: rpm5.org Name: Jeff Johnson
Root: /v/rpm/cvs Email: [EMAIL PROTECTED]
Module: rpm Date: 16-May-2008 22:09:35
Branch: HEAD Handle: 2008051620093500
Added files:
rpm/lib tevr.c
Modified files:
rpm/lib Makefile.am
Log:
- jbj: add EVR statistics toy.
Summary:
Revision Changes Path
2.180 +5 -1 rpm/lib/Makefile.am
2.1 +236 -0 rpm/lib/tevr.c
____________________________________________________________________________
patch -p0 <<'@@ .'
Index: rpm/lib/Makefile.am
============================================================================
$ cvs diff -u -r2.179 -r2.180 Makefile.am
--- rpm/lib/Makefile.am 7 May 2008 16:58:25 -0000 2.179
+++ rpm/lib/Makefile.am 16 May 2008 20:09:35 -0000 2.180
@@ -31,7 +31,7 @@
EXTRA_DIST = genpgp.sh librpm.vers tpgp.c
-EXTRA_PROGRAMS = tgi tpgp tsbt
+EXTRA_PROGRAMS = tevr tgi tpgp tsbt
pkgincdir = $(pkgincludedir)$(WITH_PATH_VERSIONED_SUFFIX)
pkginc_HEADERS = \
@@ -128,6 +128,10 @@
#.PHONY: lcov-upload
#lcov-upload: lcov
# rsync -rvz -e ssh --delete lcov/* ???
+
+tevr_SOURCES = tevr.c
+tevr_LDADD = $(RPM_LDADD)
+
tgi_SOURCES = tgi.c
tgi_LDADD = $(RPM_LDADD)
@@ .
patch -p0 <<'@@ .'
Index: rpm/lib/tevr.c
============================================================================
$ cvs diff -u -r0 -r2.1 tevr.c
--- /dev/null 2008-05-16 22:00:07 +0200
+++ tevr.c 2008-05-16 22:09:35 +0200
@@ -0,0 +1,236 @@
+#include "system.h"
+#include <rpmio.h>
+#include <poptIO.h>
+#include <argv.h>
+#include <rpmhash.h>
+
+#define _RPMEVR_INTERNAL
+#include <rpmevr.h>
+
+#include "debug.h"
+
+const char *__progname;
+#define progname __progname
+
+static struct stats_e {
+ unsigned total;
+ unsigned files;
+ unsigned Kdigest;
+ unsigned Odigest;
+ unsigned Emiss;
+ unsigned Rmiss;
+ size_t strnb;
+ size_t dictnb;
+ size_t uuidnb;
+} s;
+
+static int nofiles = 0;
+static int noKdigests = 0;
+static int noOdigests = 0;
+
+typedef struct rpmdict_s * rpmdict;
+struct rpmdict_s {
+ ARGV_t av;
+ size_t ac;
+ hashTable ht;
+};
+
+/[EMAIL PROTECTED]@*/
+static rpmdict rpmdictFree(/[EMAIL PROTECTED]@*/ rpmdict dict)
+{
+ if (dict != NULL) {
+ dict->ht = (dict->ht ? htFree(dict->ht) : NULL);
+ dict->av = argvFree(dict->av);
+ dict = _free(dict);
+ }
+ return NULL;
+}
+
+static void rpmdictAdd(rpmdict dict, const char * key)
+{
+ uint64_t * val = NULL;
+ int vallen = sizeof(*val);
+ int notfound = htGetEntry(dict->ht, key, &val, &vallen, NULL);
+ if (notfound) {
+ (void) argvAdd(&dict->av, key);
+ val = xmalloc(sizeof(*val));
+ val[0] = 0;
+ htAddEntry(dict->ht, dict->av[dict->ac++], val);
+ }
+#ifdef NOTYET
+ val[0]++;
+#endif
+}
+
+/[EMAIL PROTECTED]@*/
+static rpmdict rpmdictCreate(void)
+{
+ static const char key[] = "";
+ rpmdict dict = xcalloc(1, sizeof(*dict));
+ int nbuckets = 4093;
+ size_t keySize = 0;
+ int freeData = 0;
+ dict->ht = htCreate(nbuckets, keySize, freeData, NULL, NULL);
+ rpmdictAdd(dict, key);
+ return dict;
+}
+
+static int rpmdictCmp(const void * a, const void * b)
+{
+ const char * astr = *(ARGV_t)a;
+ const char * bstr = *(ARGV_t)b;
+ return rpmEVRcmp(astr, bstr);
+}
+
+static int isKdigest(const char * s)
+{
+ static char hex[] = "0123456789abcdefABCDEF";
+ size_t len = strlen(s);
+ int rc = 0;
+ int c;
+
+ switch (len) {
+ default:
+ break;
+ case 32:
+ case 40:
+ while ((c = *s++) != 0)
+ if (strchr(hex, c) == NULL)
+ break;
+ rc = (c == 0 ? 1 : 0);
+ break;
+ }
+ return rc;
+}
+
+static int isOdigest(const char * s)
+{
+ static char hex[] = "0123456789abcdef";
+ size_t len = strlen(s);
+ int hascolon = 0;
+ int hasdash = 0;
+ int rc = 0;
+ int c;
+
+ switch (len) {
+ default:
+ break;
+ case 27:
+ while ((c = *s++) != 0) {
+ if (c == (int)':') hascolon++;
+ else if (c == (int)'-') hasdash++;
+ else if (strchr(hex, c) == NULL)
+ break;
+ }
+ rc = (c == 0 && hascolon == 1 && hasdash == 1 ? 1 : 0);
+ break;
+ }
+ return rc;
+}
+
+static struct poptOption optionsTable[] = {
+
+ { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmioAllPoptTable, 0,
+ N_("Common options for all rpmio executables:"),
+ NULL },
+
+ POPT_AUTOHELP
+ POPT_TABLEEND
+};
+
+int
+main(int argc, const char **argv)
+{
+ poptContext optCon = rpmioInit(argc, argv, optionsTable);
+ ARGV_t av;
+ int ac;
+ rpmdict dict;
+ EVR_t evr = xcalloc(1, sizeof(*evr));
+ const char * arg;
+ int rc = 0;
+ int xx;
+ int i;
+
+ if ((progname = strrchr(argv[0], '/')) != NULL)
+ progname++;
+ else
+ progname = argv[0];
+
+ av = poptGetArgs(optCon);
+ ac = argvCount(av);
+
+ if (ac == 0 || !strcmp(*av, "-")) {
+ av = NULL;
+ xx = argvFgets(&av, NULL);
+ ac = argvCount(av);
+ }
+
+ dict = rpmdictCreate();
+
+ if (av != NULL)
+ for (i = 0; (arg = av[i]) != NULL; i++) {
+ if (*arg == '\0') /* Skip cruft */
+ continue;
+ s.total++;
+
+ if (nofiles && *arg == '/') { /* Skip file paths. */
+ s.files++;
+ continue;
+ }
+ if (noKdigests && isKdigest(arg)) { /* Skip kernel MD5/SHA1. */
+ s.Kdigest++;
+ continue;
+ }
+ if (noOdigests && isOdigest(arg)) { /* Skip OCAML EVR strings. */
+ s.Odigest++;
+ continue;
+ }
+
+ /* Split E:V-R into components. */
+ xx = rpmEVRparse(arg, evr);
+ if (evr->E == NULL) {
+ evr->E = "0";
+ s.Emiss++;
+ }
+ if (evr->R == NULL) {
+ evr->R = "";
+ s.Rmiss++;
+ }
+ rpmdictAdd(dict, evr->E);
+ rpmdictAdd(dict, evr->V);
+ rpmdictAdd(dict, evr->R);
+
+if (__debug)
+fprintf(stderr, "%5d: %s => %s:%s-%s\n", s.total, arg, evr->E, evr->V,
evr->R);
+
+ evr->str = _free(evr->str);
+ }
+
+ (void) argvSort(dict->av, rpmdictCmp);
+
+ /* Compute size of string & uuid store. */
+ for (i = 0; av[i] != NULL; i++) {
+ s.strnb += sizeof(*av) + strlen(av[i]) + 1;
+ s.uuidnb += 64/8;
+ }
+ s.strnb += sizeof(*av) + 1;
+
+ /* Compute size of dictionary store. */
+ for (i = 0; dict->av[i] != NULL; i++) {
+ s.dictnb += sizeof(*dict->av) + strlen(dict->av[i]) + 1;
+ }
+ s.dictnb += sizeof(*dict->av) + 1;
+
+fprintf(stderr, "total:%u files:%u Kdigest:%u Odigest:%u Emiss:%u Rmiss:%u
dictlen:%u strnb:%u dictnb:%u uuidnb:%u\n",
+s.total, s.files, s.Kdigest, s.Odigest, s.Emiss, s.Rmiss,
argvCount(dict->av), (unsigned)s.strnb, (unsigned)s.dictnb, (unsigned)s.uuidnb);
+
+if (__debug)
+ argvPrint("E:V-R dictionary", dict->av, NULL);
+
+ evr = _free(evr);
+ dict = rpmdictFree(dict);
+
+ optCon = rpmioFini(optCon);
+
+ return rc;
+}
@@ .
______________________________________________________________________
RPM Package Manager http://rpm5.org
CVS Sources Repository [email protected]