Assorted whitespace cleanup and typo fixes.
[haiku.git] / src / bin / listimage.c
blob995988c4f3b3396f3593cb56338cffd8346a92e9
1 /*
2 * Copyright (c) 2001-2014 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Daniel Reinhold, danielre@users.sf.net
7 * John Scipione, jscipione@gmail.com
8 */
10 /*! Lists image info for all currently running teams. */
13 #include <ctype.h>
14 #include <image.h>
15 #include <inttypes.h>
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
20 #include <OS.h>
23 static status_t
24 list_images_for_team_by_id(team_id id)
26 image_info imageInfo;
27 int32 cookie = 0;
28 team_info teamInfo;
29 char* header;
30 char* format;
31 int i;
32 status_t result = get_team_info(id, &teamInfo);
33 if (id != 1 && result < B_OK)
34 return result;
36 i = asprintf(&header, " ID %*s %*s Seq# Init# Name",
37 sizeof(uintptr_t) * 2, "Text", sizeof(uintptr_t) * 2, "Data");
38 if (i == -1)
39 return B_NO_MEMORY;
41 i = asprintf(&format, "%%5" B_PRId32 " 0x%%0%" B_PRIu32 PRIxPTR
42 " 0x%%0%" B_PRIu32 PRIxPTR " %%4" B_PRId32 " %%10" B_PRIu32 " %%s\n",
43 sizeof(uintptr_t) * 2, sizeof(uintptr_t) * 2);
44 if (i == -1) {
45 free(header);
46 return B_NO_MEMORY;
49 if (id == 1)
50 printf("\nKERNEL TEAM:\n");
51 else
52 printf("\nTEAM %4" B_PRId32 " (%s):\n", id, teamInfo.args);
54 puts(header);
55 for (i = 0; i < 80; i++)
56 putchar('-');
58 printf("\n");
59 while ((result = get_next_image_info(id, &cookie, &imageInfo)) == B_OK) {
60 printf(format, imageInfo.id, imageInfo.text, imageInfo.data,
61 imageInfo.sequence, imageInfo.init_order, imageInfo.name);
64 free(header);
65 free(format);
67 if (result != B_ENTRY_NOT_FOUND && result != EINVAL) {
68 printf("get images failed: %s\n", strerror(result));
69 return result;
72 return B_OK;
76 static void
77 list_images_for_team(const char* arg)
79 int32 cookie = 0;
80 team_info info;
81 status_t result;
83 if (atoi(arg) > 0 && list_images_for_team_by_id(atoi(arg)) == B_OK)
84 return;
86 /* search for the team by name */
88 while (get_next_team_info(&cookie, &info) >= B_OK) {
89 if (strstr(info.args, arg)) {
90 result = list_images_for_team_by_id(info.team);
91 if (result != B_OK) {
92 printf("\nCould not retrieve information about team %"
93 B_PRId32 ": %s\n", info.team, strerror(result));
101 main(int argc, char** argv)
103 int32 cookie = 0;
104 team_info info;
105 status_t result;
107 if (argc == 1) {
108 /* list for all teams */
109 while (get_next_team_info(&cookie, &info) >= B_OK) {
110 result = list_images_for_team_by_id(info.team);
111 if (result != B_OK) {
112 printf("\nCould not retrieve information about team %"
113 B_PRId32 ": %s\n", info.team, strerror(result));
116 } else {
117 /* list for each team_id on the command line */
118 while (--argc > 0 && ++argv != NULL)
119 list_images_for_team(*argv);
122 return 0;