00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TAliasCommand.hh"
00017 #include "TRunManager.hh"
00018 #include "TUserInterface.hh"
00019 #include "TCommandSpecified.hh"
00020
00021 static const Tstring _name = "alias";
00022 static const Tstring _desc = "without arguments, prints all aliases.\nwith name, prints the alias for name.\nwith name and wordlist, assigns wordlist as the alias of name.";
00023
00024 TAliasCommand::TAliasCommand( TRunManager* manager )
00025 : TCommand( manager, _name, _desc )
00026 {;}
00027
00028 TAliasCommand::~TAliasCommand()
00029 {;}
00030
00031 Tvoid TAliasCommand::Execute( const TstringList& arguments )
00032 {
00033 if ( arguments.size() > 2 ) {
00034 ShowCommandDetail();
00035 return;
00036 }
00037
00038 TUserInterface* ui = theRunManager -> GetUserInterface();
00039
00040 if ( ui ) {
00041 if ( arguments.size() == 0 ) {
00042 printall();
00043 } else if ( arguments.size() == 1 ) {
00044 print( arguments[ 0 ] );
00045 } else if ( arguments.size() == 2 ) {
00046 alias( arguments[ 0 ], arguments[ 1 ] );
00047 }
00048 }
00049
00050 return;
00051 }
00052
00053 Tvoid TAliasCommand::printall()
00054 {
00055 TUserInterface* ui = theRunManager -> GetUserInterface();
00056 const TCommandTable& table = ui -> GetCommandTable();
00057
00058 for ( Tint i = 0; i < table.GetSize(); i ++ ) {
00059 if ( table[ i ].IsAliasedCommand() ) {
00060 Tcout << table[ i ].GetFullName() << " is aliased ";
00061 Tcout << table[ i ].GetCommand() -> GetCommandName() << "." << Tendl;
00062 }
00063 }
00064 return;
00065 }
00066
00067 Tvoid TAliasCommand::print( const Tstring& name )
00068 {
00069 TUserInterface* ui = theRunManager -> GetUserInterface();
00070 const TCommandTable& table = ui -> GetCommandTable();
00071 Tstring path = ui -> ModifyPath( name );
00072 for ( Tint i = 0; i < table.GetSize(); i ++ ) {
00073 if ( table[ i ].IsAliasedCommand() && table[ i ].GetFullName() == path ) {
00074 Tcout << table[ i ].GetFullName() << " is aliased ";
00075 Tcout << table[ i ].GetCommand() -> GetCommandName() << "." << Tendl;
00076 }
00077 }
00078 return;
00079 }
00080
00081 Tvoid TAliasCommand::alias( const Tstring& name, const Tstring& wordlist )
00082 {
00083 TUserInterface* ui = theRunManager -> GetUserInterface();
00084
00085 Tstring aliasname = name;
00086 Tstring realname = wordlist;
00087
00088 aliasname = ui -> ModifyPath( aliasname );
00089 Tstring abspath = ui -> ModifyPath( realname );
00090 TCommandTable& table = ui -> GetCommandTable();
00091
00092
00093 if ( table.AlreadyExist( aliasname ) || table.AlreadyExistDirectory( aliasname ) ) {
00094 Tcerr << aliasname << ": already defined." << Tendl;
00095 return;
00096 }
00097
00098 if ( ! table.AlreadyExist( abspath ) ) {
00099 Tcerr << realname << ": No such file or directory." << Tendl;
00100 return;
00101 }
00102
00103 TCommand* command = ui -> GetCommand( abspath );
00104
00105 Tint nslash = 0;
00106 for ( Tsize_t i = 0; i < aliasname.size(); i ++ ) {
00107 if ( aliasname[ i ] == '/' ) {
00108 nslash ++;
00109 }
00110 }
00111
00112 Tint depth = TCommandSpecified::tAliasDepth;
00113 Tbool flag;
00114 Tstring cname;
00115 Tstring path;
00116 if ( nslash > 0 ) {
00117 flag = Tfalse;
00118 Tsize_t slashpos = aliasname.rfind( '/' );
00119 path = aliasname.substr( 0, slashpos );
00120 cname = aliasname.substr( slashpos + 1, aliasname.size() - slashpos - 1 );
00121 } else {
00122 flag = Ttrue;
00123 cname = aliasname;
00124 path = "";
00125 }
00126
00127 TCommandSpecified spec( cname, aliasname, path, depth, flag, command );
00128 table.push_back( spec );
00129
00130 return;
00131 }
00132
00133 #ifdef __CLDAQ_ROOT_DLL
00134 ClassImp(TAliasCommand)
00135 #endif