xref: /haiku/src/bin/listimage.c (revision 26de917c7a5b153af18e017c4be4f11ab7a107f7)
19b0c212aSAxel Dörfler /*
2*26de917cSJohn Scipione  * Copyright (c) 2001-2005 Haiku, Inc. All rights reserved.
3*26de917cSJohn Scipione  * Distributed under the terms of the MIT License.
49b0c212aSAxel Dörfler  *
5*26de917cSJohn Scipione  * Authors:
6*26de917cSJohn Scipione  *		Daniel Reinhold, danielre@users.sf.net
79b0c212aSAxel Dörfler  */
89b0c212aSAxel Dörfler 
9*26de917cSJohn Scipione /*!	Lists image info for all currently running teams. */
1017049c45SAxel Dörfler 
1117049c45SAxel Dörfler 
12*26de917cSJohn Scipione #include <ctype.h>
1317049c45SAxel Dörfler #include <image.h>
1417049c45SAxel Dörfler #include <stdio.h>
1517049c45SAxel Dörfler #include <stdlib.h>
1617049c45SAxel Dörfler #include <string.h>
17*26de917cSJohn Scipione 
18*26de917cSJohn Scipione #include <OS.h>
1917049c45SAxel Dörfler 
2017049c45SAxel Dörfler 
2117049c45SAxel Dörfler static status_t
2217049c45SAxel Dörfler list_images_for_team_by_id(team_id id)
2317049c45SAxel Dörfler {
2417049c45SAxel Dörfler 	team_info teamInfo;
2517049c45SAxel Dörfler 	image_info imageInfo;
2617049c45SAxel Dörfler 	int32 cookie = 0;
27*26de917cSJohn Scipione 	status_t result;
2817049c45SAxel Dörfler 
29*26de917cSJohn Scipione 	result = get_team_info(id, &teamInfo);
30*26de917cSJohn Scipione 	if (id != 1 && result < B_OK)
31*26de917cSJohn Scipione 		return result;
3217049c45SAxel Dörfler 
3317049c45SAxel Dörfler 	if (id == 1)
3417049c45SAxel Dörfler 		printf("\nKERNEL TEAM:\n");
3517049c45SAxel Dörfler 	else
3617049c45SAxel Dörfler 		printf("\nTEAM %4ld (%s):\n", id, teamInfo.args);
3717049c45SAxel Dörfler 
38*26de917cSJohn Scipione 	puts("   ID                                                            name"
39*26de917cSJohn Scipione 		"       text       data seq#      init#");
40*26de917cSJohn Scipione 	puts("---------------------------------------------------------------------"
41*26de917cSJohn Scipione 		"---------------------------------------");
42*26de917cSJohn Scipione 
43*26de917cSJohn Scipione 	while ((result = get_next_image_info(id, &cookie, &imageInfo)) == B_OK) {
449b0c212aSAxel Dörfler 		printf("%5ld %64s %p %p %4ld %10lu\n",
4517049c45SAxel Dörfler 			imageInfo.id,
4617049c45SAxel Dörfler 			imageInfo.name,
479b0c212aSAxel Dörfler 			imageInfo.text,
489b0c212aSAxel Dörfler 			imageInfo.data,
4917049c45SAxel Dörfler 			imageInfo.sequence,
5017049c45SAxel Dörfler 			imageInfo.init_order);
5117049c45SAxel Dörfler 	}
52*26de917cSJohn Scipione 
53*26de917cSJohn Scipione 	if (result != B_ENTRY_NOT_FOUND && result != EINVAL) {
54*26de917cSJohn Scipione 		printf("get images failed: %s\n", strerror(result));
55*26de917cSJohn Scipione 		return result;
5617049c45SAxel Dörfler 	}
57*26de917cSJohn Scipione 
5817049c45SAxel Dörfler 	return B_OK;
5917049c45SAxel Dörfler }
6017049c45SAxel Dörfler 
6117049c45SAxel Dörfler 
6217049c45SAxel Dörfler static void
6317049c45SAxel Dörfler list_images_for_team(const char* arg)
6417049c45SAxel Dörfler {
6517049c45SAxel Dörfler 	int32 cookie = 0;
6617049c45SAxel Dörfler 	team_info info;
6717049c45SAxel Dörfler 
68*26de917cSJohn Scipione 	if (atoi(arg) > 0 && list_images_for_team_by_id(atoi(arg)) == B_OK)
6917049c45SAxel Dörfler 		return;
7017049c45SAxel Dörfler 
7117049c45SAxel Dörfler 	// search for the team by name
7217049c45SAxel Dörfler 
7317049c45SAxel Dörfler 	while (get_next_team_info(&cookie, &info) >= B_OK) {
7417049c45SAxel Dörfler 		if (strstr(info.args, arg)) {
75*26de917cSJohn Scipione 			status_t result = list_images_for_team_by_id(info.team);
76*26de917cSJohn Scipione 			if (result != B_OK) {
7717049c45SAxel Dörfler 				printf("\nCould not retrieve information about team %ld: %s\n",
78*26de917cSJohn Scipione 					info.team, strerror(result));
79*26de917cSJohn Scipione 			}
8017049c45SAxel Dörfler 		}
8117049c45SAxel Dörfler 	}
8217049c45SAxel Dörfler }
8317049c45SAxel Dörfler 
8417049c45SAxel Dörfler 
8517049c45SAxel Dörfler int
8617049c45SAxel Dörfler main(int argc, char** argv)
8717049c45SAxel Dörfler {
8817049c45SAxel Dörfler 	if (argc == 1) {
8917049c45SAxel Dörfler 		int32 cookie = 0;
9017049c45SAxel Dörfler 		team_info info;
9117049c45SAxel Dörfler 
9217049c45SAxel Dörfler 		// list for all teams
9317049c45SAxel Dörfler 		while (get_next_team_info(&cookie, &info) >= B_OK) {
94*26de917cSJohn Scipione 			status_t result = list_images_for_team_by_id(info.team);
95*26de917cSJohn Scipione 			if (result != B_OK) {
9617049c45SAxel Dörfler 				printf("\nCould not retrieve information about team %ld: %s\n",
97*26de917cSJohn Scipione 					info.team, strerror(result));
98*26de917cSJohn Scipione 			}
9917049c45SAxel Dörfler 		}
10017049c45SAxel Dörfler 	} else {
10117049c45SAxel Dörfler 		// list for each team_id on the command line
10217049c45SAxel Dörfler 		while (--argc)
10317049c45SAxel Dörfler 			list_images_for_team(*++argv);
10417049c45SAxel Dörfler 	}
105*26de917cSJohn Scipione 
10617049c45SAxel Dörfler 	return 0;
10717049c45SAxel Dörfler }
108