RemoteDrawingEngine: Reduce RP_READ_BITMAP result timeout.
[haiku.git] / src / bin / roster.cpp
blob9eca23be26a5cc88d7d1142dfeef41040425301d
1 /*
2 * Copyright 2002-2005 Haiku Inc.
3 * Distributed under the terms of the MIT license
5 * Authors:
6 * Mathew Hounsell
7 * Axel Dörfler, axeld@pinc-software.de.
8 */
11 #include <Roster.h>
12 #include <Path.h>
13 #include <Entry.h>
14 #include <List.h>
15 #include <String.h>
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <getopt.h>
22 static struct option const kLongOptions[] = {
23 {"name", no_argument, 0, 'n'},
24 {"no-trunc", no_argument, 0, 't'},
25 {"help", no_argument, 0, 'h'},
26 {NULL}
29 extern const char *__progname;
30 static const char *kProgramName = __progname;
32 static const int32 kNameFieldWidth = 34;
34 // view modes
35 static const int32 kStandardMode = 0x0;
36 static const int32 kNameOnlyMode = 0x1;
37 static const int32 kNoTruncateMode = 0x2;
40 void
41 truncate_string(BString &name, int32 length)
43 if (name.Length() <= length)
44 return;
45 if (length < 6)
46 length = 6;
48 int32 beginLength = length / 3 - 1;
49 int32 endLength = length - 3 - beginLength;
51 BString begin, end;
52 name.CopyInto(begin, 0, beginLength);
53 name.CopyInto(end, name.Length() - endLength, endLength);
55 name = begin;
56 name.Append("...").Append(end);
60 void
61 output_team(team_id id, int32 mode)
63 // Get info on team
64 app_info info;
65 if (be_roster->GetRunningAppInfo(id, &info) != B_OK)
66 return;
68 // Allocate a entry and get it's path.
69 // - works as they are independant (?)
70 BEntry entry(&info.ref);
71 BPath path(&entry);
73 BString name;
74 if (mode & kNameOnlyMode)
75 name = info.ref.name;
76 else
77 name = path.Path();
79 if ((mode & kNoTruncateMode) == 0)
80 truncate_string(name, kNameFieldWidth);
82 printf("%6" B_PRId32 " %*s %5" B_PRId32 " %5" B_PRIx32 " (%s)\n",
83 id, (int)kNameFieldWidth, name.String(),
84 info.port, info.flags, info.signature);
88 void
89 usage(int exitCode)
91 fprintf(stderr, "usage: %s [-nt]\n"
92 " -n, --name\t\tInstead of the full path, only the name of the teams are written\n"
93 " -t, --no-trunc\tDon't truncate the path name\n"
94 " -h, --help\t\tDisplay this help and exit\n",
95 kProgramName);
97 exit(exitCode);
102 main(int argc, char **argv)
104 int32 mode = kStandardMode;
106 // Don't have an BApplication as it is not needed for what we do
108 int c;
109 while ((c = getopt_long(argc, argv, "nth", kLongOptions, NULL)) != -1) {
110 switch (c) {
111 case 'n':
112 mode |= kNameOnlyMode;
113 break;
114 case 't':
115 mode |= kNoTruncateMode;
116 break;
117 case 0:
118 break;
119 case 'h':
120 usage(0);
121 break;
122 default:
123 usage(1);
124 break;
128 // print title line
130 printf(" team %*s port flags signature\n",
131 (int)kNameFieldWidth, mode & kNameOnlyMode ? "name" : "path");
133 printf("------ ");
134 for (int32 i = 0; i < kNameFieldWidth; i++)
135 putchar('-');
136 puts(" ----- ----- ---------");
138 // Retrieve the running list.
139 BList applicationList;
140 be_roster->GetAppList(&applicationList);
142 // Iterate through the list.
143 for (int32 i = 0; i < applicationList.CountItems(); i++)
144 output_team((team_id)(addr_t)applicationList.ItemAt(i), mode);
146 return 0;