Made the roster command a bit more useful: since the main thread and the
team IDs are now equivalent in Haiku, we don't need to print both. Also, team paths are now truncated to fit into the list to give a better visual appearance. Added two options to turn off truncating and to show the team name (instead of full path) only. Applied our style guide, replaced C++ streams with nicer stdio stuff (formatted output is not that nice in C++). git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11638 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -64,6 +64,7 @@ StdBinCommands
|
|||||||
play.cpp
|
play.cpp
|
||||||
query.cpp
|
query.cpp
|
||||||
quit.cpp
|
quit.cpp
|
||||||
|
roster.cpp
|
||||||
setversion.cpp
|
setversion.cpp
|
||||||
shutdown.cpp
|
shutdown.cpp
|
||||||
version.cpp
|
version.cpp
|
||||||
@@ -83,12 +84,6 @@ StdBinCommands
|
|||||||
: be libmedia.so
|
: be libmedia.so
|
||||||
;
|
;
|
||||||
|
|
||||||
# standard commands that need libbe.so, libstdc++.r4.so
|
|
||||||
StdBinCommands
|
|
||||||
roster.cpp
|
|
||||||
: be stdc++.r4
|
|
||||||
;
|
|
||||||
|
|
||||||
# standard commands that need libbe.so, libmail.so
|
# standard commands that need libbe.so, libmail.so
|
||||||
StdBinCommands
|
StdBinCommands
|
||||||
mail.cpp
|
mail.cpp
|
||||||
|
|||||||
+127
-69
@@ -1,87 +1,145 @@
|
|||||||
/*********************************************************************
|
/*
|
||||||
** Roster Applet
|
* Copyright 2002-2005 Haiku Inc.
|
||||||
**********************************************************************
|
* Distributed under the terms of the MIT license
|
||||||
** 2002-04-30 Mathew Hounsell Created.
|
*
|
||||||
*/
|
* Authors:
|
||||||
|
* Mathew Hounsell
|
||||||
|
* Axel Dörfler, [email protected].
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <Roster.h>
|
#include <Roster.h>
|
||||||
|
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
|
|
||||||
#include <List.h>
|
#include <List.h>
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <stdio.h>
|
||||||
#include <iomanip>
|
#include <getopt.h>
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
/*********************************************************************
|
static struct option const kLongOptions[] = {
|
||||||
*/
|
{"name", no_argument, 0, 'n'},
|
||||||
bool OutputTeam( void * item_p )
|
{"no-trunc", no_argument, 0, 't'},
|
||||||
|
{"help", no_argument, 0, 'h'},
|
||||||
|
{NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
extern const char *__progname;
|
||||||
|
static const char *kProgramName = __progname;
|
||||||
|
|
||||||
|
static const int32 kNameFieldWidth = 34;
|
||||||
|
|
||||||
|
// view modes
|
||||||
|
static const int32 kStandardMode = 0x0;
|
||||||
|
static const int32 kNameOnlyMode = 0x1;
|
||||||
|
static const int32 kNoTruncateMode = 0x2;
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
truncate_string(BString &name, int32 length)
|
||||||
{
|
{
|
||||||
static uint32 i = 0u; // counter
|
if (name.Length() <= length)
|
||||||
|
return;
|
||||||
app_info info;
|
if (length < 6)
|
||||||
|
length = 6;
|
||||||
// Roster stores team_id not team_id *
|
|
||||||
team_id id = reinterpret_cast<team_id>( item_p );
|
|
||||||
|
|
||||||
// Get info on team
|
|
||||||
if( be_roster->GetRunningAppInfo( id, &info ) == B_OK ) {
|
|
||||||
|
|
||||||
// Allocate a entry and get it's path.
|
|
||||||
// - works as they are independant (?)
|
|
||||||
BEntry entry( & info.ref );
|
|
||||||
BPath path( & entry );
|
|
||||||
|
|
||||||
// Output - leave the work to ostream
|
|
||||||
std::cout
|
|
||||||
<< setw(2) << i << ' '
|
|
||||||
// short << setw(32) << info.ref.name << ' '
|
|
||||||
<< setw(32) << path.Path() << ' '
|
|
||||||
<< setw(6) << info.thread << ' '
|
|
||||||
<< setw(4) << info.team << ' '
|
|
||||||
<< setw(4) << info.port << ' '
|
|
||||||
<< setw(4)
|
|
||||||
;
|
|
||||||
// Go hex, output, the go dec
|
|
||||||
hex( std::cout );
|
|
||||||
std::cout << info.flags;
|
|
||||||
dec( std::cout );
|
|
||||||
|
|
||||||
// Output a signature
|
int32 beginLength = length / 3 - 1;
|
||||||
std::cout
|
int32 endLength = length - 3 - beginLength;
|
||||||
<< " (" << info.signature << ')'
|
|
||||||
<< std::endl
|
BString begin, end;
|
||||||
;
|
name.CopyInto(begin, 0, beginLength);
|
||||||
|
name.CopyInto(end, name.Length() - endLength, endLength);
|
||||||
/* NOW */ ++i;
|
|
||||||
}
|
name = begin;
|
||||||
return false;
|
name.Append("...").Append(end);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************************************
|
|
||||||
*/
|
void
|
||||||
int main( int argc, char ** argv )
|
output_team(team_id id, int32 mode)
|
||||||
{
|
{
|
||||||
// Don't have an BApplication as it is a waste.
|
// Get info on team
|
||||||
|
app_info info;
|
||||||
cout
|
if (be_roster->GetRunningAppInfo(id, &info) != B_OK)
|
||||||
<< " path thread team port flags\n"
|
return;
|
||||||
"-- -------------------------------- ------ ---- ---- -----"
|
|
||||||
<< std::endl
|
// Allocate a entry and get it's path.
|
||||||
;
|
// - works as they are independant (?)
|
||||||
|
BEntry entry(&info.ref);
|
||||||
|
BPath path(&entry);
|
||||||
|
|
||||||
|
BString name;
|
||||||
|
if (mode & kNameOnlyMode)
|
||||||
|
name = info.ref.name;
|
||||||
|
else
|
||||||
|
name = path.Path();
|
||||||
|
|
||||||
|
if ((mode & kNoTruncateMode) == 0)
|
||||||
|
truncate_string(name, kNameFieldWidth);
|
||||||
|
|
||||||
|
printf("%6ld %*s %5ld %5lx (%s)\n",
|
||||||
|
id, (int)kNameFieldWidth, name.String(),
|
||||||
|
info.port, info.flags, info.signature);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
usage(int exitCode)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "usage: %s [-nt]\n"
|
||||||
|
" -n, --name\t\tInstead of the full path, only the name of the teams are written\n"
|
||||||
|
" -t, --no-trunc\tDon't truncate the path name\n",
|
||||||
|
kProgramName);
|
||||||
|
|
||||||
|
exit(exitCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
int32 mode = kStandardMode;
|
||||||
|
|
||||||
|
// Don't have an BApplication as it is not needed for what we do
|
||||||
|
|
||||||
|
int c;
|
||||||
|
while ((c = getopt_long(argc, argv, "nt", kLongOptions, NULL)) != -1) {
|
||||||
|
switch (c) {
|
||||||
|
case 'n':
|
||||||
|
mode |= kNameOnlyMode;
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
mode |= kNoTruncateMode;
|
||||||
|
break;
|
||||||
|
case 0:
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
usage(0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
usage(1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// print title line
|
||||||
|
|
||||||
|
printf(" team %*s port flags signature\n",
|
||||||
|
(int)kNameFieldWidth, mode & kNameOnlyMode ? "name" : "path");
|
||||||
|
|
||||||
|
printf("------ ");
|
||||||
|
for (int32 i = 0; i < kNameFieldWidth; i++)
|
||||||
|
putchar('-');
|
||||||
|
puts(" ----- ----- ---------");
|
||||||
|
|
||||||
// Retrieve the running list.
|
// Retrieve the running list.
|
||||||
BList applist( 0 );
|
BList applicationList;
|
||||||
be_roster->GetAppList( & applist );
|
be_roster->GetAppList(&applicationList);
|
||||||
|
|
||||||
// Iterate through the list.
|
// Iterate through the list.
|
||||||
// void DoForEach(bool (*func)(void *) )
|
for (int32 i = 0; i < applicationList.CountItems(); i++)
|
||||||
applist.DoForEach( OutputTeam );
|
output_team((team_id)applicationList.ItemAt(i), mode);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user