Gentoo Archives: gentoo-commits

From: Fabian Groffen <grobian@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage-utils:master commit in: libq/
Date: Thu, 26 Sep 2019 14:06:52
Message-Id: 1569505998.debecebe010e3c33e594ec5745e591982095d62b.grobian@gentoo
1 commit: debecebe010e3c33e594ec5745e591982095d62b
2 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
3 AuthorDate: Thu Sep 26 13:53:18 2019 +0000
4 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
5 CommitDate: Thu Sep 26 13:53:18 2019 +0000
6 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=debecebe
7
8 libq/atom: add atom_compar_cb, qsort compatible comparator function
9
10 use this new function from libq/tree where it was moved from
11
12 Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
13
14 libq/atom.c | 17 +++++++++++++++++
15 libq/atom.h | 1 +
16 libq/tree.c | 9 +--------
17 3 files changed, 19 insertions(+), 8 deletions(-)
18
19 diff --git a/libq/atom.c b/libq/atom.c
20 index 8f564eb..f80bb7d 100644
21 --- a/libq/atom.c
22 +++ b/libq/atom.c
23 @@ -843,3 +843,20 @@ atom_format(const char *format, const depend_atom *atom)
24 {
25 return atom_format_r(_atom_buf, sizeof(_atom_buf), format, atom);
26 }
27 +
28 +/* qsort compatible callback function */
29 +inline int
30 +atom_compar_cb(const void *l, const void *r)
31 +{
32 + const depend_atom *al = l;
33 + const depend_atom *ar = r;
34 +
35 + switch (atom_compare(al, ar)) {
36 + case EQUAL: return 0;
37 + case NEWER: return -1;
38 + case OLDER: return 1;
39 + default: return strcmp(al->PN, ar->PN);
40 + }
41 +
42 + /* unreachable */
43 +}
44
45 diff --git a/libq/atom.h b/libq/atom.h
46 index 43397ad..a5175b0 100644
47 --- a/libq/atom.h
48 +++ b/libq/atom.h
49 @@ -104,5 +104,6 @@ char *atom_format_r(char *buf, size_t buflen,
50 const char *format, const depend_atom *atom);
51 char *atom_to_string(depend_atom *a);
52 char *atom_format(const char *format, const depend_atom *atom);
53 +int atom_compar_cb(const void *l, const void *r);
54
55 #endif
56
57 diff --git a/libq/tree.c b/libq/tree.c
58 index 8caed00..a8baabe 100644
59 --- a/libq/tree.c
60 +++ b/libq/tree.c
61 @@ -320,14 +320,7 @@ tree_pkg_compar(const void *l, const void *r)
62 depend_atom *al = tree_get_atom(pl, false);
63 depend_atom *ar = tree_get_atom(pr, false);
64
65 - switch (atom_compare(al, ar)) {
66 - case EQUAL: return 0;
67 - case NEWER: return -1;
68 - case OLDER: return 1;
69 - default: return strcmp(al->PN, ar->PN);
70 - }
71 -
72 - /* unreachable */
73 + return atom_compar_cb(al, ar);
74 }
75
76 static tree_pkg_ctx *