From 69ac139b33b584eea4ce4710f20f1d4b2d686057 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Mon, 30 Jun 2014 00:24:58 -0400 Subject: [PATCH] listimage: A bunch of small fixes. * Use arch-independent format specifiers. * Print pointers at a fixed length padded with 0s, length is eitther 8 or 16 depending on pointer width. * Uppercase titles. * Add an extra space between Data and Seq# columns to more clearly show that they represent separate titles. * Move the Name column last because it is variable length. This way, all columns line up vertically and the name can overflow past the end, before a long path would push all the other columns to the right. * Make the Name column title is left-aligned, dashes go to 80 cols. * Use C89 comments and C89 variable declarations. Screenshot: http://38.media.tumblr.com/4aea59cf15f8a7c186fc97d62916f38b/tumblr_n7yrw7nwma1r0f0hfo1_1280.png --- src/bin/listimage.c | 75 +++++++++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 30 deletions(-) diff --git a/src/bin/listimage.c b/src/bin/listimage.c index 42486eef1f..98f71e4c78 100644 --- a/src/bin/listimage.c +++ b/src/bin/listimage.c @@ -1,9 +1,10 @@ /* - * Copyright (c) 2001-2005 Haiku, Inc. All rights reserved. + * Copyright (c) 2001-2014 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * Daniel Reinhold, danielre@users.sf.net + * John Scipione, jscipione@gmail.com */ /*! Lists image info for all currently running teams. */ @@ -11,6 +12,7 @@ #include #include +#include #include #include #include @@ -24,32 +26,42 @@ list_images_for_team_by_id(team_id id) team_info teamInfo; image_info imageInfo; int32 cookie = 0; - status_t result; - - result = get_team_info(id, &teamInfo); + const char* header; + char* format; + char* name; + int i; + status_t result = get_team_info(id, &teamInfo); if (id != 1 && result < B_OK) return result; + i = asprintf(&header, " ID %*s %*s Seq# Init# Name", + sizeof(uintptr_t) * 2, "Text", sizeof(uintptr_t) * 2, "Data"); + if (i == -1) + return B_NO_MEMORY; + + i = asprintf(&format, "%%5" B_PRId32 " 0x%%0%" B_PRIu32 PRIxPTR + " 0x%%0%" B_PRIu32 PRIxPTR " %%4" B_PRId32 " %%10" B_PRIu32 " %%s\n", + sizeof(uintptr_t) * 2, sizeof(uintptr_t) * 2); + if (i == -1) + return B_NO_MEMORY; + if (id == 1) printf("\nKERNEL TEAM:\n"); else - printf("\nTEAM %4ld (%s):\n", id, teamInfo.args); + printf("\nTEAM %4" B_PRId32 " (%s):\n", id, teamInfo.args); - puts(" ID name" - " text data seq# init#"); - puts("---------------------------------------------------------------------" - "---------------------------------------"); + puts(header); + for (i = 0; i < 80; i++) + putchar('-'); + printf("\n"); while ((result = get_next_image_info(id, &cookie, &imageInfo)) == B_OK) { - printf("%5ld %64s %p %p %4ld %10lu\n", - imageInfo.id, - imageInfo.name, - imageInfo.text, - imageInfo.data, - imageInfo.sequence, - imageInfo.init_order); + printf(format, imageInfo.id, imageInfo.text, imageInfo.data, + imageInfo.sequence, imageInfo.init_order, imageInfo.name); } + free(format); + if (result != B_ENTRY_NOT_FOUND && result != EINVAL) { printf("get images failed: %s\n", strerror(result)); return result; @@ -64,18 +76,19 @@ list_images_for_team(const char* arg) { int32 cookie = 0; team_info info; + status_t result; if (atoi(arg) > 0 && list_images_for_team_by_id(atoi(arg)) == B_OK) return; - // search for the team by name + /* search for the team by name */ while (get_next_team_info(&cookie, &info) >= B_OK) { if (strstr(info.args, arg)) { - status_t result = list_images_for_team_by_id(info.team); + result = list_images_for_team_by_id(info.team); if (result != B_OK) { - printf("\nCould not retrieve information about team %ld: %s\n", - info.team, strerror(result)); + printf("\nCould not retrieve information about team %" + B_PRId32 ": %s\n", info.team, strerror(result)); } } } @@ -85,22 +98,24 @@ list_images_for_team(const char* arg) int main(int argc, char** argv) { - if (argc == 1) { - int32 cookie = 0; - team_info info; + int32 cookie = 0; + team_info info; + const char* programName; + status_t result; - // list for all teams + if (argc == 1) { + /* list for all teams */ while (get_next_team_info(&cookie, &info) >= B_OK) { - status_t result = list_images_for_team_by_id(info.team); + result = list_images_for_team_by_id(info.team); if (result != B_OK) { - printf("\nCould not retrieve information about team %ld: %s\n", - info.team, strerror(result)); + printf("\nCould not retrieve information about team %" + B_PRId32 ": %s\n", info.team, strerror(result)); } } } else { - // list for each team_id on the command line - while (--argc) - list_images_for_team(*++argv); + /* list for each team_id on the command line */ + while (--argc > 0 && ++argv != NULL) + list_images_for_team(*argv); } return 0;