1/*
2 * Copyright (c) 2001-2005, Haiku.
3 *
4 * This software is part of the Haiku distribution and is covered
5 * by the MIT license.
6 *
7 * Author: Daniel Reinhold (danielre@users.sf.net)
8 */
9
10/**	Description: lists image info for all currently running teams */
11
12
13#include <OS.h>
14#include <image.h>
15
16#include <stdio.h>
17#include <stdlib.h>
18#include <string.h>
19#include <ctype.h>
20
21
22static status_t
23list_images_for_team_by_id(team_id id)
24{
25	team_info teamInfo;
26	image_info imageInfo;
27	int32 cookie = 0;
28	status_t status;
29
30	status = get_team_info(id, &teamInfo);
31	if (id != 1 && status < B_OK)
32		return status;
33
34	if (id == 1)
35		printf("\nKERNEL TEAM:\n");
36	else
37		printf("\nTEAM %4ld (%s):\n", id, teamInfo.args);
38	printf("   ID                                                             name       text       data seq#      init#\n");
39	printf("------------------------------------------------------------------------------------------------------------\n");
40
41	while ((status = get_next_image_info(id, &cookie, &imageInfo)) == B_OK) {
42		printf("%5ld %64s %p %p %4ld %10lu\n",
43			imageInfo.id,
44			imageInfo.name,
45			imageInfo.text,
46			imageInfo.data,
47			imageInfo.sequence,
48			imageInfo.init_order);
49	}
50	if (status != B_ENTRY_NOT_FOUND && status != EINVAL) {
51		printf("get images failed: %s\n", strerror(status));
52		return status;
53	}
54	return B_OK;
55}
56
57
58static void
59list_images_for_team(const char *arg)
60{
61	int32 cookie = 0;
62	team_info info;
63
64	if (atoi(arg) > 0) {
65		if (list_images_for_team_by_id(atoi(arg)) == B_OK)
66			return;
67	}
68
69	// search for the team by name
70
71	while (get_next_team_info(&cookie, &info) >= B_OK) {
72		if (strstr(info.args, arg)) {
73			status_t status = list_images_for_team_by_id(info.team);
74			if (status != B_OK)
75				printf("\nCould not retrieve information about team %ld: %s\n",
76					info.team, strerror(status));
77		}
78	}
79}
80
81
82int
83main(int argc, char **argv)
84{
85	if (argc == 1) {
86		int32 cookie = 0;
87		team_info info;
88
89		// list for all teams
90		while (get_next_team_info(&cookie, &info) >= B_OK) {
91			status_t status = list_images_for_team_by_id(info.team);
92			if (status != B_OK)
93				printf("\nCould not retrieve information about team %ld: %s\n",
94					info.team, strerror(status));
95		}
96	} else {
97		// list for each team_id on the command line
98		while (--argc)
99			list_images_for_team(*++argv);
100	}
101	return 0;
102}
103
104