#include <G4VBasicShell.hh>
Inheritance diagram for G4VBasicShell:

Public Member Functions | |
| G4VBasicShell () | |
| virtual | ~G4VBasicShell () |
| virtual G4UIsession * | SessionStart ()=0 |
| virtual void | PauseSessionStart (G4String Prompt)=0 |
Protected Member Functions | |
| G4String | ModifyToFullPathCommand (const char *aCommandLine) |
| G4String | GetCurrentWorkingDirectory () |
| G4bool | ChangeDirectory (const char *newDir) |
| G4UIcommandTree * | FindDirectory (const char *dirName) |
| G4UIcommand * | FindCommand (const char *commandName) |
| G4String | Complete (G4String) |
| G4String | FindMatchingPath (G4UIcommandTree *, G4String) |
| virtual void | ExecuteCommand (G4String) |
| virtual G4bool | GetHelpChoice (G4int &)=0 |
| virtual void | ExitHelp ()=0 |
| void | ApplyShellCommand (G4String, G4bool &, G4bool &) |
| void | ShowCurrent (G4String) |
| void | ChangeDirectoryCommand (G4String) |
| void | ListDirectory (G4String) |
| void | TerminalHelp (G4String) |
Private Member Functions | |
| G4String | ModifyPath (G4String tempPath) |
Private Attributes | |
| G4String | currentDirectory |
|
|
Definition at line 40 of file G4VBasicShell.cc.
00041 :currentDirectory("/") 00042 { 00043 } |
|
|
Definition at line 45 of file G4VBasicShell.cc.
00046 {;}
|
|
||||||||||||||||
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Definition at line 286 of file G4VBasicShell.cc. References ChangeDirectoryCommand(), ExecuteCommand(), GetCurrentWorkingDirectory(), ListDirectory(), ModifyToFullPathCommand(), ShowCurrent(), and TerminalHelp(). Referenced by G4UIXm::ButtonCallback(), G4UIQt::buttonCallback(), G4UIXaw::Callback(), G4UIXm::commandEnteredCallback(), G4UIQt::commandEnteredCallback(), G4UIWin32::EditWindowProc(), and G4UIWin32::MainWindowProc().
00293 {
00294 G4UImanager* UI = G4UImanager::GetUIpointer();
00295 if(UI==NULL) return;
00296
00297 G4String command = a_string.strip(G4String::leading);
00298 if( command(0) == '#' ) {
00299
00300 G4cout << command << G4endl;
00301
00302 } else if( command == "ls" || command(0,3) == "ls " ) {
00303
00304 ListDirectory( command );
00305
00306 } else if( command == "pwd" ) {
00307
00308 G4cout << "Current Working Directory : "
00309 << GetCurrentWorkingDirectory() << G4endl;
00310
00311 } else if( command(0,2) == "cd" ) {
00312
00313 ChangeDirectoryCommand ( command );
00314
00315 } else if( command(0,4) == "help" ) {
00316
00317 TerminalHelp( command );
00318
00319 } else if( command(0) == '?' ) {
00320
00321 ShowCurrent( command );
00322
00323 } else if( command(0,4) == "hist" ) {
00324
00325 G4int nh = UI->GetNumberOfHistory();
00326 for(G4int i=0;i<nh;i++) {
00327 G4cout << i << ": " << UI->GetPreviousCommand(i) << G4endl;
00328 }
00329
00330 } else if( command(0) == '!' ) {
00331
00332 G4String ss = command(1,command.length()-1);
00333 G4int vl;
00334 const char* tt = ss;
00335 std::istringstream is(tt);
00336 is >> vl;
00337 G4int nh = UI->GetNumberOfHistory();
00338 if(vl>=0 && vl<nh) {
00339 G4String prev = UI->GetPreviousCommand(vl);
00340 G4cout << prev << G4endl;
00341 ExecuteCommand (ModifyToFullPathCommand(prev));
00342 } else {
00343 G4cerr << "history " << vl << " is not found." << G4endl;
00344 }
00345
00346 } else if( command(0,4) == "exit" ) {
00347
00348 if( exitPause == false) { //In a secondary loop.
00349 G4cout << "You are now processing RUN." << G4endl;
00350 G4cout << "Please abort it using \"/run/abort\" command first" << G4endl;
00351 G4cout << " and use \"continue\" command until the application" << G4endl;
00352 G4cout << " becomes to Idle." << G4endl;
00353 } else {
00354 exitSession = true;
00355 }
00356
00357 } else if( command(0,4) == "cont" ) {
00358
00359 exitPause = true;
00360
00361 } else {
00362
00363 ExecuteCommand (ModifyToFullPathCommand(a_string));
00364
00365 }
00366 }
|
Here is the call graph for this function:

|
|
Definition at line 75 of file G4VBasicShell.cc. References currentDirectory, FindDirectory(), and ModifyPath(). Referenced by ChangeDirectoryCommand().
00076 {
00077 G4String aNewPrefix = (G4String)newDir;
00078 G4String newPrefix = (G4String)aNewPrefix.strip(G4String::both);
00079 G4String newDirectory = ModifyPath( newPrefix );
00080 if( newDirectory( newDirectory.length() - 1 ) != '/' )
00081 { newDirectory += "/"; }
00082 if( FindDirectory( (const char*)newDirectory ) == NULL )
00083 { return false; }
00084 currentDirectory = newDirectory;
00085 return true;
00086 }
|
Here is the call graph for this function:

|
|
Definition at line 378 of file G4VBasicShell.cc. References ChangeDirectory(). Referenced by ApplyShellCommand(), and G4UIterminal::GetCommand().
00379 {
00380 G4String prefix;
00381 if( newCommand.length() <= 3 ) {
00382 prefix = "/";
00383 } else {
00384 G4String aNewPrefix = newCommand(3,newCommand.length()-3);
00385 prefix = aNewPrefix.strip(G4String::both);
00386 }
00387 if(!ChangeDirectory(prefix)) {
00388 G4cout << "directory <" << prefix << "> not found." << G4endl;
00389 }
00390 }
|
Here is the call graph for this function:

|
|
Definition at line 168 of file G4VBasicShell.cc. References FindMatchingPath(), and ModifyPath(). Referenced by G4UIWin32::EditWindowProc(), and G4UIXm::keyHandler().
00169 {
00170 G4String rawCommandLine = commandName;
00171 G4String commandLine = rawCommandLine.strip(G4String::both);
00172 size_t i = commandLine.index(" ");
00173 if( i != std::string::npos ) return rawCommandLine; // Already entering parameters,
00174 // assume command path is correct.
00175 G4String commandString = commandLine;
00176 G4String targetCom = ModifyPath(commandString);
00177 G4UIcommandTree* tree = G4UImanager::GetUIpointer()->GetTree();
00178 G4String value = FindMatchingPath(tree,targetCom);
00179 if(value=="") return rawCommandLine;
00180 return value;
00181 }
|
Here is the call graph for this function:

|
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Reimplemented in G4UIterminal, and G4UIGainServer. Definition at line 258 of file G4VBasicShell.cc. Referenced by ApplyShellCommand().
00264 {
00265 if(aCommand.length()<2) return;
00266 G4UImanager* UI = G4UImanager::GetUIpointer();
00267 if(UI==NULL) return;
00268 G4int commandStatus = UI->ApplyCommand(aCommand);
00269 switch(commandStatus) {
00270 case fCommandSucceeded:
00271 break;
00272 case fCommandNotFound:
00273 G4cerr << "command not found" << G4endl;
00274 break;
00275 case fIllegalApplicationState:
00276 G4cerr << "illegal application state -- command refused" << G4endl;
00277 break;
00278 case fParameterOutOfRange:
00279 case fParameterUnreadable:
00280 case fParameterOutOfCandidates:
00281 default:
00282 G4cerr << "command refused (" << commandStatus << ")" << G4endl;
00283 }
00284 }
|
|
|
Implemented in G4UIQt, G4UIterminal, G4UIWin32, G4UIXaw, G4UIXm, and G4UIGainServer. Referenced by TerminalHelp(). |
|
|
Definition at line 110 of file G4VBasicShell.cc. References ModifyPath(). Referenced by G4UIterminal::ExecuteCommand().
00111 {
00112 G4String rawCommandLine = (G4String)commandName;
00113 G4String commandLine = (G4String)rawCommandLine.strip(G4String::both);
00114 G4String commandString;
00115 size_t i = commandLine.index(" ");
00116 if( i != std::string::npos )
00117 { commandString = (G4String)commandLine(0,i); }
00118 else
00119 { commandString = commandLine; }
00120
00121 G4String targetCom = ModifyPath(commandString);
00122 return G4UImanager::GetUIpointer()->GetTree()->FindPath(targetCom);
00123 }
|
Here is the call graph for this function:

|
|
Definition at line 88 of file G4VBasicShell.cc. References ModifyPath(). Referenced by ChangeDirectory(), and ListDirectory().
00089 {
00090 G4String aDirName = (G4String)dirName;
00091 G4String theDir = (G4String)aDirName.strip(G4String::both);
00092 G4String targetDir = ModifyPath( theDir );
00093 if( targetDir( targetDir.length()-1 ) != '/' )
00094 { targetDir += "/"; }
00095 G4UIcommandTree* comTree = G4UImanager::GetUIpointer()->GetTree();
00096 if( targetDir == "/" )
00097 { return comTree; }
00098 size_t idx = 1;
00099 while( idx < targetDir.length()-1 )
00100 {
00101 size_t i = targetDir.index("/",idx);
00102 comTree = comTree->GetTree((G4String)targetDir(0,i+1));
00103 if( comTree == NULL )
00104 { return NULL; }
00105 idx = i+1;
00106 }
00107 return comTree;
00108 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 182 of file G4VBasicShell.cc. Referenced by Complete().
00187 {
00188 G4String empty = "";
00189 if(aTree==NULL) return empty;
00190 G4String pathName = aTree->GetPathName();
00191 if( aCommandPath.index( pathName ) == std::string::npos ) return empty;
00192 G4String remainingPath = aCommandPath;
00193 remainingPath.remove(0,pathName.length());
00194 size_t i = remainingPath.first('/');
00195 if( i == std::string::npos ) {
00196 // Look for number of matching commands :
00197 std::vector<G4UIcommand*> commands;
00198 G4int n_commandEntry = aTree->GetCommandEntry();
00199 for( G4int i_thCommand = 1; i_thCommand <= n_commandEntry; i_thCommand++ ) {
00200 G4UIcommand* cmd = aTree->GetCommand(i_thCommand);
00201 G4String ss = cmd->GetCommandName();
00202 ss.resize(remainingPath.length());
00203 if( remainingPath == ss ) commands.push_back(cmd);
00204 }
00205 n_commandEntry = commands.size();
00206 if(n_commandEntry==1) {
00207 return (pathName + commands[0]->GetCommandName());
00208 } else if (n_commandEntry>=2) {
00209 G4cout << "Matching commands :" << G4endl;
00210 for( G4int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ ) {
00211 G4UIcommand* cmd = commands[i_thCommand];
00212 G4cout << cmd->GetCommandName() << G4endl;
00213 }
00214 return empty;
00215 }
00216 // Look for sub tree :
00217 std::vector<G4UIcommandTree*> trees;
00218 G4String nextPath = pathName;
00219 nextPath.append(remainingPath);
00220 G4int n_treeEntry = aTree->GetTreeEntry();
00221 for( G4int i_thTree = 1; i_thTree <= n_treeEntry; i_thTree++ ) {
00222 G4UIcommandTree* tree = aTree->GetTree(i_thTree);
00223 G4String ss = tree->GetPathName();
00224 ss.resize(nextPath.length());
00225 if( nextPath == ss ) trees.push_back(tree);
00226 }
00227 n_treeEntry = trees.size();
00228 if(n_treeEntry==1) {
00229 return trees[0]->GetPathName();
00230 } else if (n_treeEntry>=2) {
00231 G4cout << "Matching directories :" << G4endl;
00232 for( G4int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ ) {
00233 G4UIcommandTree* tree = trees[i_thTree];
00234 G4cout << tree->GetPathName() << G4endl;
00235 }
00236 return empty;
00237 } else {
00238 return empty; // No match.
00239 }
00240 } else {
00241 // Find path
00242 G4String nextPath = pathName;
00243 nextPath.append(remainingPath(0,i+1));
00244 G4int n_treeEntry = aTree->GetTreeEntry();
00245 for( G4int i_thTree = 1; i_thTree <= n_treeEntry; i_thTree++ ) {
00246 G4UIcommandTree* tree = aTree->GetTree(i_thTree);
00247 if( nextPath == tree->GetPathName() ) {
00248 return FindMatchingPath(tree,aCommandPath );
00249 }
00250 }
00251 }
00252 return empty;
00253 }
|
|
|
Definition at line 70 of file G4VBasicShell.cc. References currentDirectory. Referenced by ApplyShellCommand(), G4UIterminal::GetCommand(), ListDirectory(), and TerminalHelp().
00071 {
00072 return currentDirectory;
00073 }
|
|
|
Implemented in G4UIQt, G4UIterminal, G4UIWin32, G4UIXaw, G4UIXm, and G4UIGainServer. Referenced by TerminalHelp(). |
|
|
Reimplemented in G4UIGainServer. Definition at line 391 of file G4VBasicShell.cc. References FindDirectory(), and GetCurrentWorkingDirectory(). Referenced by ApplyShellCommand(), and G4UIterminal::GetCommand().
00392 {
00393 G4String targetDir;
00394 if( newCommand.length() <= 3 ) {
00395 targetDir = GetCurrentWorkingDirectory();
00396 } else {
00397 G4String newPrefix = newCommand(3,newCommand.length()-3);
00398 targetDir = newPrefix.strip(G4String::both);
00399 }
00400 G4UIcommandTree* commandTree = FindDirectory( targetDir );
00401 if( commandTree == NULL ) {
00402 G4cout << "Directory <" << targetDir << "> is not found." << G4endl;
00403 } else {
00404 commandTree->ListCurrent();
00405 }
00406 }
|
Here is the call graph for this function:

|
|
Definition at line 125 of file G4VBasicShell.cc. References currentDirectory. Referenced by ChangeDirectory(), Complete(), FindCommand(), FindDirectory(), and ModifyToFullPathCommand().
00126 {
00127 G4String newPath = currentDirectory;
00128
00129 if( tempPath.length()>0 )
00130 {
00131
00132 if( tempPath(0) == '/' ) // full path is given
00133 { newPath = tempPath; }
00134 else if( tempPath(0) != '.' ) // add current prefix
00135 { newPath += tempPath; }
00136 else if( tempPath(0,2) == "./" ) // add current prefix
00137 { newPath += (G4String)tempPath(2,tempPath.length()-2); }
00138 else // swim up with ".."
00139 {
00140 while( 1 )
00141 {
00142 if( tempPath(0,2) == ".." )
00143 {
00144 if( newPath != "/" )
00145 {
00146 G4String tmpString = (G4String)newPath(0,newPath.length()-1);
00147 newPath = (G4String)newPath(0,tmpString.last('/')+1);
00148 }
00149 if( tempPath == ".." || tempPath == "../" )
00150 { break; }
00151 tempPath = (G4String)tempPath(3,tempPath.length()-3);
00152 }
00153 else
00154 {
00155 newPath += tempPath;
00156 break;
00157 }
00158 }
00159 }
00160
00161 }
00162
00163 return newPath;
00164 }
|
|
|
Definition at line 48 of file G4VBasicShell.cc. References ModifyPath(). Referenced by ApplyShellCommand(), G4UIterminal::GetCommand(), ShowCurrent(), TerminalHelp(), and G4UIQt::TerminalHelp().
00049 {
00050 G4String rawCommandLine = (G4String)aCommandLine;
00051 if(rawCommandLine.isNull()||rawCommandLine(0)=='\0') return rawCommandLine;
00052 G4String commandLine = (G4String)rawCommandLine.strip(G4String::both);
00053 G4String commandString;
00054 G4String parameterString;
00055 size_t i = commandLine.index(" ");
00056 if( i != std::string::npos )
00057 {
00058 commandString = (G4String)commandLine(0,i);
00059 parameterString = " ";
00060 parameterString += (G4String)commandLine(i+1,commandLine.length()-(i+1));
00061 }
00062 else
00063 { commandString = commandLine; }
00064
00065 G4String fullPathCommandLine
00066 = ModifyPath( commandString )+parameterString;
00067 return fullPathCommandLine;
00068 }
|
Here is the call graph for this function:

|
|
Implemented in G4UIQt, G4UIterminal, G4UIWin32, G4UIXaw, G4UIXm, and G4UIGainServer. |
|
|
Implemented in G4UIQt, G4UIterminal, G4UIWin32, G4UIXaw, G4UIXm, and G4UIGainServer. |
|
|
Reimplemented in G4UIGainServer. Definition at line 367 of file G4VBasicShell.cc. References ModifyToFullPathCommand(). Referenced by ApplyShellCommand(), and G4UIterminal::GetCommand().
00368 {
00369 G4UImanager* UI = G4UImanager::GetUIpointer();
00370 if(UI==NULL) return;
00371 G4String comString = newCommand(1,newCommand.length()-1);
00372 G4String theCommand = ModifyToFullPathCommand(comString);
00373 G4String curV = UI->GetCurrentValues(theCommand);
00374 if( ! curV.isNull() ) {
00375 G4cout << "Current value(s) of the parameter(s) : " << curV << G4endl;
00376 }
00377 }
|
Here is the call graph for this function:

|
|
Reimplemented in G4UIQt, and G4UIGainServer. Definition at line 407 of file G4VBasicShell.cc. References ExitHelp(), GetCurrentWorkingDirectory(), GetHelpChoice(), and ModifyToFullPathCommand(). Referenced by ApplyShellCommand(), and G4UIterminal::GetCommand().
00408 {
00409 G4UImanager* UI = G4UImanager::GetUIpointer();
00410 if(UI==NULL) return;
00411 G4UIcommandTree * treeTop = UI->GetTree();
00412 size_t i = newCommand.index(" ");
00413 if( i != std::string::npos )
00414 {
00415 G4String newValue = newCommand(i+1,newCommand.length()-(i+1));
00416 newValue.strip(G4String::both);
00417 G4String targetCom = ModifyToFullPathCommand( newValue );
00418 G4UIcommand* theCommand = treeTop->FindPath( targetCom );
00419 if( theCommand != NULL )
00420 {
00421 theCommand->List();
00422 return;
00423 }
00424 else
00425 {
00426 G4cout << "Command <" << newValue << " is not found." << G4endl;
00427 return;
00428 }
00429 }
00430
00431 G4UIcommandTree * floor[10];
00432 floor[0] = treeTop;
00433 G4int iFloor = 0;
00434 size_t prefixIndex = 1;
00435 G4String prefix = GetCurrentWorkingDirectory();
00436 while( prefixIndex < prefix.length()-1 )
00437 {
00438 size_t ii = prefix.index("/",prefixIndex);
00439 floor[iFloor+1] =
00440 floor[iFloor]->GetTree(G4String(prefix(0,ii+1)));
00441 prefixIndex = ii+1;
00442 iFloor++;
00443 }
00444 floor[iFloor]->ListCurrentWithNum();
00445 // 1998 Oct 2 non-number input
00446 while(1){
00447 //G4cout << G4endl << "Type the number ( 0:end, -n:n level back ) : "<<std::flush;
00448 G4cout << G4endl << "Type the number ( 0:end, -n:n level back ) : "<<G4endl;
00449 G4int i;
00450 if(!GetHelpChoice(i)){
00451 G4cout << G4endl << "Not a number, once more" << G4endl;
00452 continue;
00453 } else if( i < 0 ){
00454 iFloor += i;
00455 if( iFloor < 0 ) iFloor = 0;
00456 floor[iFloor]->ListCurrentWithNum();
00457 continue;
00458 } else if(i == 0) {
00459 break;
00460 } else if( i > 0 ) {
00461 G4int n_tree = floor[iFloor]->GetTreeEntry();
00462 if( i > n_tree )
00463 {
00464 if( i <= n_tree + floor[iFloor]->GetCommandEntry() )
00465 {
00466 floor[iFloor]->GetCommand(i-n_tree)->List();
00467 }
00468 }
00469 else
00470 {
00471 floor[iFloor+1] = floor[iFloor]->GetTree(i);
00472 iFloor++;
00473 floor[iFloor]->ListCurrentWithNum();
00474 }
00475 }
00476 }
00477 G4cout << "Exit from HELP." << G4endl << G4endl;
00478 //G4cout << G4endl;
00479 ExitHelp();
00480 }
|
Here is the call graph for this function:

|
|
Definition at line 102 of file G4VBasicShell.hh. Referenced by ChangeDirectory(), GetCurrentWorkingDirectory(), and ModifyPath(). |
1.3.4