Assorted whitespace cleanup and typo fixes.
[haiku.git] / src / bin / listarea.c
blob0879f1adaa4c7317be95d4197f9968f341e15d93
1 /*
2 * Copyright (c) 2001-2005, Haiku.
4 * This software is part of the Haiku distribution and is covered
5 * by the MIT license.
7 * Author: Daniel Reinhold (danielre@users.sf.net)
8 */
10 /** Lists area info for all currently running teams */
13 #include <OS.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
20 static void list_areas_for_id(team_id team);
21 static void list_areas_for_name(const char *teamName);
22 static void show_memory_totals(void);
25 static void
26 show_memory_totals(void)
28 int32 max = 0, used = 0;
30 system_info info;
31 if (get_system_info(&info) == B_OK) {
32 // pages are 4KB
33 max = info.max_pages * 4;
34 used = info.used_pages * 4;
37 printf("memory: total: %4" B_PRId32 "KB, used: %4" B_PRId32 "KB, left: %4"
38 B_PRId32 "KB\n", max, used, max - used);
42 static void
43 list_areas_for_id(team_id id)
45 ssize_t cookie = 0;
46 team_info teamInfo;
47 area_info areaInfo;
49 if (id != 1 && get_team_info(id, &teamInfo) == B_BAD_TEAM_ID) {
50 printf("\nteam %" B_PRId32 " unknown\n", id);
51 return;
52 } else if (id == 1)
53 strcpy(teamInfo.args, "KERNEL SPACE");
55 printf("\n%s (team %" B_PRId32 ")\n", teamInfo.args, id);
56 printf(" ID name address size alloc."
57 " #-cow #-in #-out\n");
58 printf("------------------------------------------------------------------"
59 "------------------\n");
61 while (get_next_area_info(id, &cookie, &areaInfo) == B_OK) {
62 printf("%5" B_PRId32 " %32s %p %8" B_PRIxSIZE " %8" B_PRIx32 " %5"
63 B_PRId32 " %5" B_PRId32 " %5" B_PRId32 "\n",
64 areaInfo.area,
65 areaInfo.name,
66 areaInfo.address,
67 areaInfo.size,
68 areaInfo.ram_size,
69 areaInfo.copy_count,
70 areaInfo.in_count,
71 areaInfo.out_count);
76 static void
77 list_areas_for_name(const char *name)
79 int32 cookie = 0;
80 team_info info;
81 while (get_next_team_info(&cookie, &info) >= B_OK) {
82 if (strstr(info.args, name) != NULL)
83 list_areas_for_id(info.team);
88 int
89 main(int argc, char **argv)
91 show_memory_totals();
93 if (argc == 1) {
94 // list areas of all teams
95 int32 cookie = 0;
96 team_info info;
98 while (get_next_team_info(&cookie, &info) >= B_OK)
99 list_areas_for_id(info.team);
100 } else {
101 // list areas for each team ID/name on the command line
102 while (--argc) {
103 const char *arg = *++argv;
104 team_id team = atoi(arg);
106 // if atoi returns >0 it's likely it's a number, else take it as string
107 if (team > 0)
108 list_areas_for_id(team);
109 else
110 list_areas_for_name(arg);
114 return 0;