2 * Copyright 2002-2005 Haiku Inc.
3 * Distributed under the terms of the MIT license
7 * Axel Dörfler, axeld@pinc-software.de.
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'},
29 extern const char *__progname
;
30 static const char *kProgramName
= __progname
;
32 static const int32 kNameFieldWidth
= 34;
35 static const int32 kStandardMode
= 0x0;
36 static const int32 kNameOnlyMode
= 0x1;
37 static const int32 kNoTruncateMode
= 0x2;
41 truncate_string(BString
&name
, int32 length
)
43 if (name
.Length() <= length
)
48 int32 beginLength
= length
/ 3 - 1;
49 int32 endLength
= length
- 3 - beginLength
;
52 name
.CopyInto(begin
, 0, beginLength
);
53 name
.CopyInto(end
, name
.Length() - endLength
, endLength
);
56 name
.Append("...").Append(end
);
61 output_team(team_id id
, int32 mode
)
65 if (be_roster
->GetRunningAppInfo(id
, &info
) != B_OK
)
68 // Allocate a entry and get it's path.
69 // - works as they are independant (?)
70 BEntry
entry(&info
.ref
);
74 if (mode
& kNameOnlyMode
)
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
);
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",
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
109 while ((c
= getopt_long(argc
, argv
, "nth", kLongOptions
, NULL
)) != -1) {
112 mode
|= kNameOnlyMode
;
115 mode
|= kNoTruncateMode
;
130 printf(" team %*s port flags signature\n",
131 (int)kNameFieldWidth
, mode
& kNameOnlyMode
? "name" : "path");
134 for (int32 i
= 0; i
< kNameFieldWidth
; i
++)
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
);