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