rpm 5.2.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

rpmdpkg.c
Go to the documentation of this file.
1
4 #include "system.h"
5
6 #include <rpmiotypes.h>
7 #include <rpmtag.h>
8
9 #define _RPMEVR_INTERNAL
10 #include <rpmdpkg.h>
11
12 #include "debug.h"
13
14 /*@access EVR_t @*/
15
16 /*@unchecked@*/
17 int _rpmdpkg_debug = 0;
18
19 /* assume ascii */
20 static inline int dpkgEVRctype(char x)
21 /*@*/
22 {
23 int c = (int)x;
24 return (
25 x == '~' ? -1
26 : xisdigit(c) ? 0
27 : x == '\0' ? 0 \
28 : xisalpha(c) ? c
29 : c + 256
30 );
31 }
32
33 int dpkgEVRcmp(const char *a, const char *b)
34 {
35 if (a == NULL) a = "";
36 if (b == NULL) b = "";
37
38 while (*a || *b) {
39 int first_diff= 0;
40
41 while ( (*a && !xisdigit((int)*a)) || (*b && !xisdigit((int)*b)) ) {
42 int vc = dpkgEVRctype(*a);
43 int rc = dpkgEVRctype(*b);
44 if (vc != rc) return vc - rc;
45 a++; b++;
46 }
47
48 while (*a == '0') a++;
49 while (*b == '0') b++;
50 while (xisdigit((int)*a) && xisdigit((int)*b)) {
51 if (!first_diff) first_diff = (int)(*a - *b);
52 a++; b++;
53 }
54 if (xisdigit((int)*a)) return 1;
55 if (xisdigit((int)*b)) return -1;
56 if (first_diff) return first_diff;
57 }
58 return 0;
59 }
60
61 int dpkgEVRparse(const char * evrstr, EVR_t evr)
62 {
63 return rpmEVRparse(evrstr, evr);
64 }
65
66 int dpkgEVRcompare(const EVR_t a, const EVR_t b)
67 {
68 int r;
69
70 if (a->Elong > b->Elong) return 1;
71 if (a->Elong < b->Elong) return -1;
72 r = dpkgEVRcmp(a->F[RPMEVR_V], b->F[RPMEVR_V]); if (r) return r;
73 return dpkgEVRcmp(a->F[RPMEVR_R], b->F[RPMEVR_R]);
74 }