1 |
commit: 7967115a80957a456b53748820019ba7f484f4c9 |
2 |
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Dec 14 15:58:51 2019 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat Dec 14 15:58:51 2019 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=7967115a |
7 |
|
8 |
qkeyword: sort keywords |
9 |
|
10 |
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> |
11 |
|
12 |
qkeyword.c | 26 ++++++++++++++++++++++++++ |
13 |
1 file changed, 26 insertions(+) |
14 |
|
15 |
diff --git a/qkeyword.c b/qkeyword.c |
16 |
index b329068..4c6c759 100644 |
17 |
--- a/qkeyword.c |
18 |
+++ b/qkeyword.c |
19 |
@@ -650,6 +650,29 @@ qkeyword_results_cb(tree_pkg_ctx *pkg_ctx, void *priv) |
20 |
return EXIT_SUCCESS; |
21 |
} |
22 |
|
23 |
+static int |
24 |
+keyword_sort(const void *l, const void *r) |
25 |
+{ |
26 |
+ const char **ls = (const char **)l; |
27 |
+ const char **rs = (const char **)r; |
28 |
+ char *ld = strchr(*ls, '-'); |
29 |
+ char *rd = strchr(*rs, '-'); |
30 |
+ |
31 |
+ printf("%s vs %s\n", *ls, *rs); |
32 |
+ if (ld == NULL && rd != NULL) |
33 |
+ return -1; |
34 |
+ else if (ld != NULL && rd == NULL) |
35 |
+ return 1; |
36 |
+ else if (ld == NULL) |
37 |
+ return strcmp(*ls, *rs); |
38 |
+ else { |
39 |
+ int ret = strcmp(ld + 1, rd + 1); |
40 |
+ if (ret == 0) |
41 |
+ ret = strcmp(*ls, *rs); |
42 |
+ return ret; |
43 |
+ } |
44 |
+} |
45 |
+ |
46 |
static void |
47 |
qkeyword_load_arches(const char *overlay) |
48 |
{ |
49 |
@@ -690,6 +713,9 @@ qkeyword_load_arches(const char *overlay) |
50 |
free(archlist); |
51 |
list_set(archs, &archlist); |
52 |
|
53 |
+ /* sort so the output makes more 'sense' */ |
54 |
+ qsort(archlist, archlist_count, sizeof(char **), keyword_sort); |
55 |
+ |
56 |
fclose(fp); |
57 |
done: |
58 |
free(filename); |