19b0c212aSAxel Dörfler /* 269ac139bSJohn Scipione * Copyright (c) 2001-2014 Haiku, Inc. All rights reserved. 326de917cSJohn Scipione * Distributed under the terms of the MIT License. 49b0c212aSAxel Dörfler * 526de917cSJohn Scipione * Authors: 626de917cSJohn Scipione * Daniel Reinhold, danielre@users.sf.net 769ac139bSJohn Scipione * John Scipione, jscipione@gmail.com 89b0c212aSAxel Dörfler */ 99b0c212aSAxel Dörfler 1026de917cSJohn Scipione /*! Lists image info for all currently running teams. */ 1117049c45SAxel Dörfler 1217049c45SAxel Dörfler 1326de917cSJohn Scipione #include <ctype.h> 1417049c45SAxel Dörfler #include <image.h> 1569ac139bSJohn Scipione #include <inttypes.h> 1617049c45SAxel Dörfler #include <stdio.h> 1717049c45SAxel Dörfler #include <stdlib.h> 1817049c45SAxel Dörfler #include <string.h> 1926de917cSJohn Scipione 2026de917cSJohn Scipione #include <OS.h> 2117049c45SAxel Dörfler 2217049c45SAxel Dörfler 2317049c45SAxel Dörfler static status_t 2417049c45SAxel Dörfler list_images_for_team_by_id(team_id id) 2517049c45SAxel Dörfler { 2617049c45SAxel Dörfler image_info imageInfo; 2717049c45SAxel Dörfler int32 cookie = 0; 28*a846b0eeSJohn Scipione team_info teamInfo; 2969ac139bSJohn Scipione const char* header; 3069ac139bSJohn Scipione char* format; 3169ac139bSJohn Scipione int i; 3269ac139bSJohn Scipione status_t result = get_team_info(id, &teamInfo); 3326de917cSJohn Scipione if (id != 1 && result < B_OK) 3426de917cSJohn Scipione return result; 3517049c45SAxel Dörfler 3669ac139bSJohn Scipione i = asprintf(&header, " ID %*s %*s Seq# Init# Name", 3769ac139bSJohn Scipione sizeof(uintptr_t) * 2, "Text", sizeof(uintptr_t) * 2, "Data"); 3869ac139bSJohn Scipione if (i == -1) 3969ac139bSJohn Scipione return B_NO_MEMORY; 4069ac139bSJohn Scipione 4169ac139bSJohn Scipione i = asprintf(&format, "%%5" B_PRId32 " 0x%%0%" B_PRIu32 PRIxPTR 4269ac139bSJohn Scipione " 0x%%0%" B_PRIu32 PRIxPTR " %%4" B_PRId32 " %%10" B_PRIu32 " %%s\n", 4369ac139bSJohn Scipione sizeof(uintptr_t) * 2, sizeof(uintptr_t) * 2); 4469ac139bSJohn Scipione if (i == -1) 4569ac139bSJohn Scipione return B_NO_MEMORY; 4669ac139bSJohn Scipione 4717049c45SAxel Dörfler if (id == 1) 4817049c45SAxel Dörfler printf("\nKERNEL TEAM:\n"); 4917049c45SAxel Dörfler else 5069ac139bSJohn Scipione printf("\nTEAM %4" B_PRId32 " (%s):\n", id, teamInfo.args); 5117049c45SAxel Dörfler 5269ac139bSJohn Scipione puts(header); 5369ac139bSJohn Scipione for (i = 0; i < 80; i++) 5469ac139bSJohn Scipione putchar('-'); 5526de917cSJohn Scipione 5669ac139bSJohn Scipione printf("\n"); 5726de917cSJohn Scipione while ((result = get_next_image_info(id, &cookie, &imageInfo)) == B_OK) { 5869ac139bSJohn Scipione printf(format, imageInfo.id, imageInfo.text, imageInfo.data, 5969ac139bSJohn Scipione imageInfo.sequence, imageInfo.init_order, imageInfo.name); 6017049c45SAxel Dörfler } 6126de917cSJohn Scipione 6269ac139bSJohn Scipione free(format); 6369ac139bSJohn Scipione 6426de917cSJohn Scipione if (result != B_ENTRY_NOT_FOUND && result != EINVAL) { 6526de917cSJohn Scipione printf("get images failed: %s\n", strerror(result)); 6626de917cSJohn Scipione return result; 6717049c45SAxel Dörfler } 6826de917cSJohn Scipione 6917049c45SAxel Dörfler return B_OK; 7017049c45SAxel Dörfler } 7117049c45SAxel Dörfler 7217049c45SAxel Dörfler 7317049c45SAxel Dörfler static void 7417049c45SAxel Dörfler list_images_for_team(const char* arg) 7517049c45SAxel Dörfler { 7617049c45SAxel Dörfler int32 cookie = 0; 7717049c45SAxel Dörfler team_info info; 7869ac139bSJohn Scipione status_t result; 7917049c45SAxel Dörfler 8026de917cSJohn Scipione if (atoi(arg) > 0 && list_images_for_team_by_id(atoi(arg)) == B_OK) 8117049c45SAxel Dörfler return; 8217049c45SAxel Dörfler 8369ac139bSJohn Scipione /* search for the team by name */ 8417049c45SAxel Dörfler 8517049c45SAxel Dörfler while (get_next_team_info(&cookie, &info) >= B_OK) { 8617049c45SAxel Dörfler if (strstr(info.args, arg)) { 8769ac139bSJohn Scipione result = list_images_for_team_by_id(info.team); 8826de917cSJohn Scipione if (result != B_OK) { 8969ac139bSJohn Scipione printf("\nCould not retrieve information about team %" 9069ac139bSJohn Scipione B_PRId32 ": %s\n", info.team, strerror(result)); 9126de917cSJohn Scipione } 9217049c45SAxel Dörfler } 9317049c45SAxel Dörfler } 9417049c45SAxel Dörfler } 9517049c45SAxel Dörfler 9617049c45SAxel Dörfler 9717049c45SAxel Dörfler int 9817049c45SAxel Dörfler main(int argc, char** argv) 9917049c45SAxel Dörfler { 10017049c45SAxel Dörfler int32 cookie = 0; 10117049c45SAxel Dörfler team_info info; 10269ac139bSJohn Scipione status_t result; 10317049c45SAxel Dörfler 10469ac139bSJohn Scipione if (argc == 1) { 10569ac139bSJohn Scipione /* list for all teams */ 10617049c45SAxel Dörfler while (get_next_team_info(&cookie, &info) >= B_OK) { 10769ac139bSJohn Scipione result = list_images_for_team_by_id(info.team); 10826de917cSJohn Scipione if (result != B_OK) { 10969ac139bSJohn Scipione printf("\nCould not retrieve information about team %" 11069ac139bSJohn Scipione B_PRId32 ": %s\n", info.team, strerror(result)); 11126de917cSJohn Scipione } 11217049c45SAxel Dörfler } 11317049c45SAxel Dörfler } else { 11469ac139bSJohn Scipione /* list for each team_id on the command line */ 11569ac139bSJohn Scipione while (--argc > 0 && ++argv != NULL) 11669ac139bSJohn Scipione list_images_for_team(*argv); 11717049c45SAxel Dörfler } 11826de917cSJohn Scipione 11917049c45SAxel Dörfler return 0; 12017049c45SAxel Dörfler } 121