tools/rpmevrcmp.c: Use rpmVersionCompare

Replace rpmEVRcmp() with rpmVersionCompare() which is more suitable.
Idea and original patch by Alexey Tourbin.
This commit is contained in:
Дмитрий Левин 2009-04-14 16:50:00 +00:00
parent 71ba99f754
commit aad1a695b5

View File

@ -20,16 +20,39 @@
#include <stdio.h>
#include <errno.h>
#include <error.h>
#include <string.h>
#include <stdlib.h>
#include <rpmlib.h>
static Header
newHeaderEVR(const char *e, const char *v, const char *r)
{
Header h;
if (!(h = headerNew()))
return h;
if (e)
{
int i = atoi(e);
headerAddEntry(h, RPMTAG_EPOCH, RPM_INT32_TYPE, &i, 1);
}
if (v)
headerAddEntry(h, RPMTAG_VERSION, RPM_STRING_TYPE, v, 1);
if (r)
headerAddEntry(h, RPMTAG_RELEASE, RPM_STRING_TYPE, r, 1);
return h;
}
int
main(int ac, const char *av[])
{
const char *e1 = 0, *v1 = 0, *r1 = 0;
const char *e2 = 0, *v2 = 0, *r2 = 0;
char *arg1, *arg2;
Header h1, h2;
if (ac != 3)
{
@ -43,13 +66,21 @@ main(int ac, const char *av[])
}
arg1 = strdup(av[1]);
parseEVR(arg1, &e1, &v1, &r1);
arg2 = strdup(av[2]);
if (!arg1 || !arg2)
error(EXIT_FAILURE, errno, "strdup");
parseEVR(arg1, &e1, &v1, &r1);
parseEVR(arg2, &e2, &v2, &r2);
h1 = newHeaderEVR(e1, v1, r1);
h2 = newHeaderEVR(e2, v2, r2);
if (!h1 || !h2)
error(EXIT_FAILURE, errno, "headerNew");
printf("%d\n", rpmEVRcmp(e1, v1, r1, 0, e2, v2, r2, 0));
printf("%d\n", rpmVersionCompare(h1, h2));
h2 = headerFree(h2);
h1 = headerFree(h1);
free(arg2);
free(arg1);