rpm  5.4.10
rpmcmp.c
Go to the documentation of this file.
1 #include "system.h"
2 
3 #include <popt.h>
4 #include <rpmio_internal.h>
5 #include <rpmcb.h> /* XXX fnpyKey */
6 #include <argv.h>
7 #include <rpmtypes.h>
8 #include <rpmtag.h>
9 
10 #define _RPMDS_INTERNAL
11 #define _RPMEVR_INTERNAL
12 #include <rpmds.h>
13 
14 #include "debug.h"
15 
16 const char *__progname;
17 #define progname __progname
18 
19 static int pointRpmEVR(ARGV_t av)
20 {
21  EVR_t a = memset(alloca(sizeof(*a)), 0, sizeof(*a));
22  EVR_t b = memset(alloca(sizeof(*b)), 0, sizeof(*b));
23  int rc;
24 
25  (void) rpmEVRparse(av[0], a);
26  (void) rpmEVRparse(av[2], b);
27 
28  rc = rpmEVRcompare(a, b);
29  if (rc < 0)
30  rc = !(av[1][0] == 'l');
31  else if (rc > 0)
32  rc = !(av[1][0] == 'g');
33  else
34  rc = !(av[1][0] == 'e' || av[1][1] == 'e');
35 
36  a->str = _free(a->str);
37  b->str = _free(b->str);
38  return rc;
39 }
40 
41 static struct poptOption optionsTable[] = {
42  { "debug", 'd', POPT_ARG_VAL, &_rpmevr_debug, -1, NULL, NULL },
43  POPT_AUTOALIAS
44  POPT_AUTOHELP
45  POPT_TABLEEND
46 };
47 
48 int
49 main(int argc, char *argv[])
50 {
51  poptContext optCon;
52  ARGV_t av;
53  int ac;
54  const char * arg;
55  int ec = 0;
56  int rc;
57  int xx;
58 
59  if ((progname = strrchr(argv[0], '/')) != NULL)
60  progname++;
61  else
62  progname = argv[0];
63 
64  optCon = poptGetContext(argv[0], argc, (const char **)argv, optionsTable, 0);
65  while ((rc = poptGetNextOpt(optCon)) > 0)
66  ;
67 
68  av = poptGetArgs(optCon);
69  ac = argvCount(av);
70 
71  if (ac == 0 || !strcmp(*av, "-")) {
72  av = NULL;
73  xx = argvFgets(&av, NULL);
74  ac = argvCount(av);
75  }
76 
77  if (av != NULL)
78  while ((arg = *av++) != NULL) {
79  ARGV_t rav = NULL;
80  int rac = 0;
81  if (poptParseArgvString(arg, &rac, &rav) || rac != 3) {
82  fprintf(stderr, _("skipping malformed comparison: \"%s\"\n"), arg);
83  continue;
84  }
85  rc = pointRpmEVR(rav);
86  free(rav);
87  rav = NULL;
88  rac = 0;
89  }
90 
91  optCon = poptFreeContext(optCon);
92 
93  return ec;
94 }