00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "TExecuteCommand.hh"
00027 #include "TRunManager.hh"
00028 #include "TUserInterface.hh"
00029
00030 static const Tstring _name = "/system/execute";
00031 static const Tstring _desc =
00032 "read a macro file, execute."
00033 "\n"
00034 "1st argument is filename, 2nd argument(omiitable) is a number of loop, you wish."
00035 "\n"
00036 "CLDAQ> /system/execute sample.macro"
00037 "\n"
00038 "CLDAQ> /system/execute sample.macro 100";
00039
00040 TExecuteCommand::TExecuteCommand( TRunManager* manager )
00041 : TCommand( manager, _name, _desc ), theMacroFileParser()
00042 {;}
00043
00044 TExecuteCommand::~TExecuteCommand()
00045 {;}
00046
00047 Tvoid TExecuteCommand::Execute( const TstringList& arguments )
00048 {
00049 TUserInterface* ui = theRunManager -> GetUserInterface();
00050 static const Tstring head = "TExecuteCommand::Execute: ";
00051
00052 if ( ui ) {
00053 if ( arguments.empty() ) {
00054 ShowCommandDetail();
00055 } else if ( arguments.size() == 1 ) {
00056 Tstring filename = arguments[ 0 ];
00057 doExecute( ui, filename );
00058 } else if ( arguments.size() == 2 ) {
00059 Tstring filename = arguments[ 0 ];
00060 Tint nloop = strtol( arguments[ 1 ].c_str(), 0, 0 );
00061 doExecute( ui, filename, nloop );
00062 } else {
00063 Tcerr << head << "number of arguments should be 1 or 2." << Tendl;
00064 ShowCommandDetail();
00065 }
00066 } else {
00067 Tcerr << head << "UserInterface doesn't exist." << Tendl;
00068 }
00069 return;
00070 }
00071
00072
00073 Tvoid TExecuteCommand::doExecute( TUserInterface* ui, const Tstring& filename, Tint nloop )
00074 {
00075 TMacroFileParser macro( filename );
00076 TstringList readbuf;
00077
00078 for ( Tint i = 0; i < nloop; i ++ ) {
00079 macro.Open();
00080 while ( macro.IsSuccess() ) {
00081 readbuf = macro.ReadLine();
00082 if ( macro.IsExecutable( readbuf ) ) {
00083 Tstring command = macro.GetCommand( readbuf );
00084 TstringList args = macro.GetArguments( readbuf );
00085 ui -> ExecuteCommand( command, args );
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096 }
00097 }
00098 }
00099 macro.Close();
00100
00101 return;
00102 }
00103
00104 #ifdef __CLDAQ_ROOT_DLL
00105 ClassImp(TExecuteCommand)
00106 #endif