Gentoo Archives: gentoo-commits

From: Mike Frysinger <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage-utils:master commit in: /
Date: Sat, 28 Nov 2015 02:44:47
Message-Id: 1448658604.186af28f41cadc29027ef900c3b8622af7d3b4a0.vapier@gentoo
1 commit: 186af28f41cadc29027ef900c3b8622af7d3b4a0
2 Author: Mike Frysinger <vapier <AT> gentoo <DOT> org>
3 AuthorDate: Fri Nov 27 21:10:04 2015 +0000
4 Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org>
5 CommitDate: Fri Nov 27 21:10:04 2015 +0000
6 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=186af28f
7
8 qcache: fix cache table display w/longer arches
9
10 The table code has a hardcoded width of 12 bytes which breaks with the
11 newer arch values in the tree. Rework the code to calculate the width
12 dynamically based on the longest value in the list.
13
14 qcache.c | 32 ++++++++++++++++++++------------
15 1 file changed, 20 insertions(+), 12 deletions(-)
16
17 diff --git a/qcache.c b/qcache.c
18 index 8dbeaa3..25f8651 100644
19 --- a/qcache.c
20 +++ b/qcache.c
21 @@ -65,6 +65,7 @@ typedef struct {
22
23 static char **archlist; /* Read from PORTDIR/profiles/arch.list in qcache_init() */
24 static int archlist_count;
25 +static size_t arch_longest_len;
26 const char status[3] = {'-', '~', '+'};
27 int qcache_skip, qcache_test_arch, qcache_last = 0;
28 char *qcache_matchpkg = NULL, *qcache_matchcat = NULL;
29 @@ -703,31 +704,36 @@ void qcache_stats(qcache_data *data)
30 }
31
32 if (qcache_last) {
33 - printf("+-------------------------+\n");
34 + const char border[] = "------------------------------------------------------------------";
35 + printf("+%.*s+\n", 25, border);
36 printf("| general statistics |\n");
37 - printf("+-------------------------+\n");
38 + printf("+%.*s+\n", 25, border);
39 printf("| %s%13s%s | %s%7d%s |\n", GREEN, "architectures", NORM, BLUE, archlist_count, NORM);
40 printf("| %s%13s%s | %s%7d%s |\n", GREEN, "categories", NORM, BLUE, numcat, NORM);
41 printf("| %s%13s%s | %s%7d%s |\n", GREEN, "packages", NORM, BLUE, numpkg, NORM);
42 printf("| %s%13s%s | %s%7d%s |\n", GREEN, "ebuilds", NORM, BLUE, numebld, NORM);
43 - printf("+-------------------------+\n\n");
44 -
45 - printf("+----------------------------------------------------------+\n");
46 - printf("| keyword distribution |\n");
47 - printf("+----------------------------------------------------------+\n");
48 - printf("| %s%12s%s |%s%8s%s |%s%8s%s |%s%8s%s | %s%8s%s |\n", RED, "architecture", NORM, RED, "stable", NORM, RED, "~arch", NORM, RED, "total", NORM, RED, "total/#pkgs", NORM);
49 - printf("| | |%s%8s%s | | |\n", RED, "only", NORM);
50 - printf("+----------------------------------------------------------+\n");
51 + printf("+%.*s+\n\n", 25, border);
52 +
53 + printf("+%.*s+\n", (int)(arch_longest_len + 46), border);
54 + printf("|%*skeyword distribution |\n",
55 + (int)arch_longest_len, "");
56 + printf("+%.*s+\n", (int)(arch_longest_len + 46), border);
57 + printf("| %s%*s%s |%s%8s%s |%s%8s%s |%s%8s%s | %s%8s%s |\n",
58 + RED, (int)arch_longest_len, "architecture", NORM, RED, "stable", NORM,
59 + RED, "~arch", NORM, RED, "total", NORM, RED, "total/#pkgs", NORM);
60 + printf("| %*s | |%s%8s%s | | |\n",
61 + (int)arch_longest_len, "", RED, "only", NORM);
62 + printf("+%.*s+\n", (int)(arch_longest_len + 46), border);
63
64 for (a = 0; a < archlist_count; ++a) {
65 - printf("| %s%12s%s |", GREEN, archlist[a], NORM);
66 + printf("| %s%*s%s |", GREEN, (int)arch_longest_len, archlist[a], NORM);
67 printf("%s%8d%s |", BLUE, packages_stable[a], NORM);
68 printf("%s%8d%s |", BLUE, packages_testing[a], NORM);
69 printf("%s%8d%s |", BLUE, packages_testing[a]+packages_stable[a], NORM);
70 printf("%s%11.2f%s%% |\n", BLUE, (100.0*(packages_testing[a]+packages_stable[a]))/numpkg, NORM);
71 }
72
73 - printf("+----------------------------------------------------------+\n\n");
74 + printf("+%.*s+\n\n", (int)(arch_longest_len + 46), border);
75
76 printf("Completed in %s%d%s seconds.\n", BLUE, (int)(time(NULL)-runtime), NORM);
77
78 @@ -801,6 +807,7 @@ bool qcache_init(void)
79 goto done;
80
81 archlist_count = 0;
82 + arch_longest_len = 0;
83 buf = NULL;
84 while ((linelen = getline(&buf, &buflen, fp)) != -1) {
85 rmspace_len(buf, linelen);
86 @@ -813,6 +820,7 @@ bool qcache_init(void)
87 ++archlist_count;
88 archlist = xrealloc_array(archlist, sizeof(*archlist), archlist_count);
89 archlist[archlist_count - 1] = xstrdup(buf);
90 + arch_longest_len = MAX(arch_longest_len, strlen(buf));
91 }
92 free(buf);