From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 771631384B4 for ; Sat, 28 Nov 2015 02:44:47 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 021B521C08C; Sat, 28 Nov 2015 02:44:42 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 0DF4E21C014 for ; Sat, 28 Nov 2015 02:44:40 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id C66FF3406F2 for ; Sat, 28 Nov 2015 02:44:38 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 1135EF57 for ; Sat, 28 Nov 2015 02:44:35 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1448658604.186af28f41cadc29027ef900c3b8622af7d3b4a0.vapier@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: / X-VCS-Repository: proj/portage-utils X-VCS-Files: qcache.c X-VCS-Directories: / X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: 186af28f41cadc29027ef900c3b8622af7d3b4a0 X-VCS-Branch: master Date: Sat, 28 Nov 2015 02:44:35 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: ae572ea2-63ec-41dd-8fb7-e06d2b7e0387 X-Archives-Hash: 2f5071f79b71f3a0f0dc8a27d6259c5d commit: 186af28f41cadc29027ef900c3b8622af7d3b4a0 Author: Mike Frysinger gentoo org> AuthorDate: Fri Nov 27 21:10:04 2015 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Fri Nov 27 21:10:04 2015 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=186af28f qcache: fix cache table display w/longer arches The table code has a hardcoded width of 12 bytes which breaks with the newer arch values in the tree. Rework the code to calculate the width dynamically based on the longest value in the list. qcache.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/qcache.c b/qcache.c index 8dbeaa3..25f8651 100644 --- a/qcache.c +++ b/qcache.c @@ -65,6 +65,7 @@ typedef struct { static char **archlist; /* Read from PORTDIR/profiles/arch.list in qcache_init() */ static int archlist_count; +static size_t arch_longest_len; const char status[3] = {'-', '~', '+'}; int qcache_skip, qcache_test_arch, qcache_last = 0; char *qcache_matchpkg = NULL, *qcache_matchcat = NULL; @@ -703,31 +704,36 @@ void qcache_stats(qcache_data *data) } if (qcache_last) { - printf("+-------------------------+\n"); + const char border[] = "------------------------------------------------------------------"; + printf("+%.*s+\n", 25, border); printf("| general statistics |\n"); - printf("+-------------------------+\n"); + printf("+%.*s+\n", 25, border); printf("| %s%13s%s | %s%7d%s |\n", GREEN, "architectures", NORM, BLUE, archlist_count, NORM); printf("| %s%13s%s | %s%7d%s |\n", GREEN, "categories", NORM, BLUE, numcat, NORM); printf("| %s%13s%s | %s%7d%s |\n", GREEN, "packages", NORM, BLUE, numpkg, NORM); printf("| %s%13s%s | %s%7d%s |\n", GREEN, "ebuilds", NORM, BLUE, numebld, NORM); - printf("+-------------------------+\n\n"); - - printf("+----------------------------------------------------------+\n"); - printf("| keyword distribution |\n"); - printf("+----------------------------------------------------------+\n"); - 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); - printf("| | |%s%8s%s | | |\n", RED, "only", NORM); - printf("+----------------------------------------------------------+\n"); + printf("+%.*s+\n\n", 25, border); + + printf("+%.*s+\n", (int)(arch_longest_len + 46), border); + printf("|%*skeyword distribution |\n", + (int)arch_longest_len, ""); + printf("+%.*s+\n", (int)(arch_longest_len + 46), border); + printf("| %s%*s%s |%s%8s%s |%s%8s%s |%s%8s%s | %s%8s%s |\n", + RED, (int)arch_longest_len, "architecture", NORM, RED, "stable", NORM, + RED, "~arch", NORM, RED, "total", NORM, RED, "total/#pkgs", NORM); + printf("| %*s | |%s%8s%s | | |\n", + (int)arch_longest_len, "", RED, "only", NORM); + printf("+%.*s+\n", (int)(arch_longest_len + 46), border); for (a = 0; a < archlist_count; ++a) { - printf("| %s%12s%s |", GREEN, archlist[a], NORM); + printf("| %s%*s%s |", GREEN, (int)arch_longest_len, archlist[a], NORM); printf("%s%8d%s |", BLUE, packages_stable[a], NORM); printf("%s%8d%s |", BLUE, packages_testing[a], NORM); printf("%s%8d%s |", BLUE, packages_testing[a]+packages_stable[a], NORM); printf("%s%11.2f%s%% |\n", BLUE, (100.0*(packages_testing[a]+packages_stable[a]))/numpkg, NORM); } - printf("+----------------------------------------------------------+\n\n"); + printf("+%.*s+\n\n", (int)(arch_longest_len + 46), border); printf("Completed in %s%d%s seconds.\n", BLUE, (int)(time(NULL)-runtime), NORM); @@ -801,6 +807,7 @@ bool qcache_init(void) goto done; archlist_count = 0; + arch_longest_len = 0; buf = NULL; while ((linelen = getline(&buf, &buflen, fp)) != -1) { rmspace_len(buf, linelen); @@ -813,6 +820,7 @@ bool qcache_init(void) ++archlist_count; archlist = xrealloc_array(archlist, sizeof(*archlist), archlist_count); archlist[archlist_count - 1] = xstrdup(buf); + arch_longest_len = MAX(arch_longest_len, strlen(buf)); } free(buf);