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
This commit is contained in:
+45
-30
@@ -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, [email protected]
|
||||
* John Scipione, [email protected]
|
||||
*/
|
||||
|
||||
/*! Lists image info for all currently running teams. */
|
||||
@@ -11,6 +12,7 @@
|
||||
|
||||
#include <ctype.h>
|
||||
#include <image.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user