Import Geant4 2.0.0 source tree
This commit is contained in:
@@ -5,215 +5,261 @@
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4UIterminal.cc,v 1.4.4.1.2.1.2.7 1999/12/14 09:16:47 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-01-01 $
|
||||
// $Id: G4UIterminal.cc,v 1.13 2000/06/23 08:46:50 stesting Exp $
|
||||
// GEANT4 tag $Name: geant4-02-00 $
|
||||
//
|
||||
|
||||
#include "G4UIterminal.hh"
|
||||
#include "g4std/strstream"
|
||||
#include "G4StateManager.hh"
|
||||
#include "G4UIcommandTree.hh"
|
||||
#include "G4UIcommand.hh"
|
||||
#include "G4UIcommandStatus.hh"
|
||||
#include "G4ios.hh"
|
||||
#include "g4std/strstream"
|
||||
#include "G4UIterminal.hh"
|
||||
#include "G4UIcsh.hh"
|
||||
|
||||
G4UIterminal::G4UIterminal()
|
||||
//////////////////////////////////////////////
|
||||
G4UIterminal::G4UIterminal(G4VUIshell* aShell)
|
||||
//////////////////////////////////////////////
|
||||
{
|
||||
UI = G4UImanager::GetUIpointer();
|
||||
UI->SetSession(this);
|
||||
UI->SetCoutDestination(this);
|
||||
G4StateManager * statM = G4StateManager::GetStateManager();
|
||||
promptCharacter = statM->GetStateString(statM->GetCurrentState())
|
||||
+ G4String("> ");
|
||||
iExit = false;
|
||||
iCont = false;
|
||||
UI= G4UImanager::GetUIpointer();
|
||||
UI-> SetSession(this);
|
||||
UI-> SetCoutDestination(this);
|
||||
G4StateManager* statM= G4StateManager::GetStateManager();
|
||||
|
||||
iExit= FALSE;
|
||||
iCont= FALSE;
|
||||
|
||||
if(aShell) shell= aShell;
|
||||
else shell= new G4UIcsh;
|
||||
}
|
||||
|
||||
/////////////////////////////
|
||||
G4UIterminal::~G4UIterminal()
|
||||
/////////////////////////////
|
||||
{
|
||||
if( G4UImanager::GetUIpointer() != 0)
|
||||
{
|
||||
UI->SetSession(NULL);
|
||||
UI->SetCoutDestination(NULL);
|
||||
// G4cout << "Terminal session deleted" << G4endl;
|
||||
if(shell) delete shell;
|
||||
|
||||
if(G4UImanager::GetUIpointer()) {
|
||||
UI-> SetSession(NULL);
|
||||
UI-> SetCoutDestination(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
G4UIsession * G4UIterminal::SessionStart()
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
void G4UIterminal::SetPrompt(const G4String& prompt)
|
||||
////////////////////////////////////////////////////
|
||||
{
|
||||
iExit = true;
|
||||
G4StateManager * statM = G4StateManager::GetStateManager();
|
||||
promptCharacter = statM->GetStateString(statM->GetCurrentState())
|
||||
+ G4String("> ");
|
||||
G4String newCommand = GetCommand();
|
||||
while( iExit )
|
||||
{
|
||||
shell-> SetPrompt(prompt);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////
|
||||
G4UIsession* G4UIterminal::SessionStart()
|
||||
/////////////////////////////////////////
|
||||
{
|
||||
iExit= TRUE;
|
||||
G4StateManager* statM= G4StateManager::GetStateManager();
|
||||
|
||||
G4String newCommand= GetCommand();
|
||||
while(iExit){
|
||||
ExecuteCommand(newCommand);
|
||||
promptCharacter = statM->GetStateString(statM->GetCurrentState())
|
||||
+ G4String("> ");
|
||||
newCommand = GetCommand();
|
||||
newCommand= GetCommand();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
void G4UIterminal::PauseSessionStart(G4String msg)
|
||||
//////////////////////////////////////////////////
|
||||
{
|
||||
promptCharacter = msg;
|
||||
iCont = true;
|
||||
G4String newCommand = GetCommand();
|
||||
while( iCont )
|
||||
{
|
||||
iCont= TRUE;
|
||||
|
||||
G4String newCommand= GetCommand();
|
||||
while(iCont){
|
||||
ExecuteCommand(newCommand);
|
||||
newCommand = GetCommand();
|
||||
newCommand= GetCommand();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
void G4UIterminal::ExecuteCommand(G4String aCommand)
|
||||
////////////////////////////////////////////////////
|
||||
{
|
||||
if(aCommand.length()<2) return;
|
||||
|
||||
G4int returnVal = UI-> ApplyCommand(aCommand);
|
||||
|
||||
G4int paramIndex = returnVal % 100;
|
||||
// 0 - 98 : paramIndex-th parameter is invalid
|
||||
// 99 : convination of parameters is invalid
|
||||
G4int commandStatus = returnVal - paramIndex;
|
||||
|
||||
G4UIcommand* cmd = 0;
|
||||
if(commandStatus!=fCommandSucceeded)
|
||||
{ cmd = FindCommand(aCommand); }
|
||||
|
||||
switch(commandStatus) {
|
||||
case fCommandSucceeded:
|
||||
break;
|
||||
case fCommandNotFound:
|
||||
G4cerr << "command <" << aCommand << "> not found" << G4endl;
|
||||
if( aCommand.index("@@") != G4String::npos) {
|
||||
G4cout << "@@G4UIterminal" << G4endl;
|
||||
}
|
||||
break;
|
||||
case fIllegalApplicationState:
|
||||
G4cerr << "illegal application state -- command refused" << G4endl;
|
||||
break;
|
||||
case fParameterOutOfRange:
|
||||
// if(paramIndex<99) {
|
||||
// G4cerr << "Parameter is out of range (index " << paramIndex << ")" << G4endl;
|
||||
// G4cerr << "Allowed range : " << cmd->GetParameter(paramIndex)->GetParameterRange() << G4endl;
|
||||
// } else {
|
||||
// G4cerr << "Parameter is out of range" << G4endl;
|
||||
// G4cerr << "Allowed range : " << cmd->GetRange() << G4endl;
|
||||
// }
|
||||
break;
|
||||
case fParameterOutOfCandidates:
|
||||
G4cerr << "Parameter is out of candidate list (index " << paramIndex << ")" << G4endl;
|
||||
G4cerr << "Candidates : " << cmd->GetParameter(paramIndex)->GetParameterCandidates() << G4endl;
|
||||
break;
|
||||
case fParameterUnreadable:
|
||||
G4cerr << "Parameter is wrong type and/or is not omittable (index " << paramIndex << ")" << G4endl;
|
||||
break;
|
||||
default:
|
||||
G4cerr << "command refused (" << commandStatus << ")" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////
|
||||
G4String G4UIterminal::GetCommand()
|
||||
///////////////////////////////////
|
||||
{
|
||||
G4String newCommand;
|
||||
G4String nullString;
|
||||
|
||||
newCommand= shell-> GetCommandLine();
|
||||
|
||||
G4String nC= newCommand.strip(G4String::leading);
|
||||
if( nC.length() == 0 ) {
|
||||
newCommand= nullString;
|
||||
|
||||
} else if( nC(0) == '#' ) {
|
||||
G4cout << nC << G4endl;
|
||||
newCommand= nullString;
|
||||
|
||||
} else if(nC=="ls" || nC(0,3)=="ls " ) { // list commands
|
||||
ListDirectory(nC);
|
||||
newCommand= nullString;
|
||||
|
||||
} else if(nC=="lc" || nC(0,3)=="lc " ) { // ... by shell
|
||||
shell-> ListCommand(nC.remove(0,2));
|
||||
newCommand= nullString;
|
||||
|
||||
} else if(nC == "pwd") { // show current directory
|
||||
G4cout << "Current Command Directory : "
|
||||
<< GetCurrentWorkingDirectory() << G4endl;
|
||||
newCommand= nullString;
|
||||
|
||||
} else if(nC == "cwd") { // ... by shell
|
||||
shell-> ShowCurrentDirectory();
|
||||
newCommand= nullString;
|
||||
|
||||
} else if(nC == "cd" || nC(0,3) == "cd ") { // "cd"
|
||||
ChangeDirectoryCommand(nC);
|
||||
shell-> SetCurrentDirectory(GetCurrentWorkingDirectory());
|
||||
newCommand= nullString;
|
||||
|
||||
} else if(nC == "help" || nC(0,5) == "help ") { // "help"
|
||||
TerminalHelp(nC);
|
||||
newCommand= nullString;
|
||||
|
||||
} else if(nC(0) == '?') { // "show current value of a parameter"
|
||||
ShowCurrent(nC);
|
||||
newCommand= nullString;
|
||||
|
||||
} else if(nC == "hist" || nC == "history") { // "hist/history"
|
||||
G4int nh= UI-> GetNumberOfHistory();
|
||||
for (G4int i=0; i<nh; i++) {
|
||||
G4cout << i << ": " << UI->GetPreviousCommand(i) << G4endl;
|
||||
}
|
||||
newCommand= nullString;
|
||||
|
||||
} else if(nC(0) == '!') { // "!"
|
||||
G4String ss= nC(1, nC.length()-1);
|
||||
G4int vl;
|
||||
const char* tt= ss;
|
||||
G4std::istrstream is((char*)tt);
|
||||
is >> vl;
|
||||
G4int nh= UI-> GetNumberOfHistory();
|
||||
if(vl>=0 && vl<nh) {
|
||||
newCommand= UI-> GetPreviousCommand(vl);
|
||||
G4cout << newCommand << G4endl;
|
||||
} else {
|
||||
G4cerr << "history " << vl << " is not found." << G4endl;
|
||||
newCommand= nullString;
|
||||
}
|
||||
|
||||
} else if(nC == "exit") { // "exit"
|
||||
if(iCont) {
|
||||
G4cout << "You are now processing RUN." << G4endl;
|
||||
G4cout << "Please abort it using \"/run/abort\" command first" << G4endl;
|
||||
G4cout << " and use \"continue\" command until the application"
|
||||
<< G4endl;
|
||||
G4cout << " becomes to Idle." << G4endl;
|
||||
} else {
|
||||
iExit= FALSE;
|
||||
newCommand= nullString;
|
||||
}
|
||||
|
||||
} else if( nC == "cont" || nC == "continue"){ // "cont/continu"
|
||||
iCont= FALSE;
|
||||
newCommand= nullString;
|
||||
|
||||
} else if( nC.empty() ){ // NULL command
|
||||
newCommand= nullString;
|
||||
|
||||
} else {
|
||||
}
|
||||
|
||||
return ModifyToFullPathCommand(newCommand);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
G4int G4UIterminal::ReceiveG4cout(G4String coutString)
|
||||
//////////////////////////////////////////////////////
|
||||
{
|
||||
G4std::cout << coutString << G4std::flush;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
G4int G4UIterminal::ReceiveG4cerr(G4String cerrString)
|
||||
//////////////////////////////////////////////////////
|
||||
{
|
||||
G4std::cerr << cerrString << G4std::flush;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void G4UIterminal::ExecuteCommand(G4String aCommand)
|
||||
///////////////////////////////////////////////
|
||||
G4bool G4UIterminal::GetHelpChoice(G4int& aInt)
|
||||
///////////////////////////////////////////////
|
||||
{
|
||||
|
||||
if(aCommand.length()<2) return;
|
||||
|
||||
int commandStatus = UI->ApplyCommand(aCommand);
|
||||
switch(commandStatus)
|
||||
{
|
||||
case fCommandSucceeded:
|
||||
break;
|
||||
case fCommandNotFound:
|
||||
G4cerr << "command <" << aCommand << "> not found" << G4endl;
|
||||
if ( aCommand.index("@@") != G4std::string::npos) {
|
||||
G4cout << "@@G4UIterminal" << G4endl;
|
||||
}
|
||||
break;
|
||||
case fIllegalApplicationState:
|
||||
G4cerr << "illegal application state -- command refused" << G4endl;
|
||||
break;
|
||||
case fParameterOutOfRange:
|
||||
case fParameterUnreadable:
|
||||
case fParameterOutOfCandidates:
|
||||
default:
|
||||
G4cerr << "command refused (" << commandStatus << ")" << G4endl;
|
||||
}
|
||||
}
|
||||
G4String G4UIterminal::GetCommand()
|
||||
{
|
||||
G4String newCommand;
|
||||
G4String nullString;
|
||||
while( 1 )
|
||||
{
|
||||
G4cout << promptCharacter;
|
||||
G4cout.flush();
|
||||
newCommand.readLine( G4cin, FALSE );
|
||||
if (!G4cin.good()) { G4cin.clear(); newCommand = nullString; iExit=false; break; }
|
||||
newCommand = newCommand.strip(G4String::leading);
|
||||
if( newCommand.length() < 1 ) { break; }
|
||||
|
||||
while( newCommand(newCommand.length()-1) == '_' )
|
||||
{
|
||||
G4String newLine;
|
||||
newCommand.remove(newCommand.length()-1);
|
||||
newLine.readLine( G4cin );
|
||||
if (!G4cin.good()) { G4cin.clear(); newCommand = nullString; iExit=false; break; }
|
||||
newCommand.append(newLine);
|
||||
}
|
||||
|
||||
G4String nC = newCommand.strip(G4String::leading);
|
||||
|
||||
|
||||
// -------------------- nC.toUpper();
|
||||
if( nC.length() < 1 ){ break; }
|
||||
if( nC(0) == '#' )
|
||||
{ G4cout << nC << G4endl; }
|
||||
else if( nC == "ls" || nC(0,3) == "ls " )
|
||||
{ ListDirectory( nC ); }
|
||||
else if( nC == "pwd" )
|
||||
{
|
||||
G4cout << "Current Working Directory : "
|
||||
<< GetCurrentWorkingDirectory() << G4endl;
|
||||
}
|
||||
else if( nC == "cd" || nC(0,3) == "cd " )
|
||||
{ ChangeDirectoryCommand( nC ); }
|
||||
else if( nC == "help" || nC(0,5) == "help " )
|
||||
{ TerminalHelp( nC ); }
|
||||
else if( nC(0) == '?' )
|
||||
{ ShowCurrent( nC ); }
|
||||
else if( nC == "hist" || nC == "history" )
|
||||
{
|
||||
G4int nh = UI->GetNumberOfHistory();
|
||||
for(int i=0;i<nh;i++)
|
||||
{ G4cout << i << ": " << UI->GetPreviousCommand(i) << G4endl; }
|
||||
}
|
||||
else if( nC(0) == '!' )
|
||||
{
|
||||
G4String ss = nC(1,nC.length()-1);
|
||||
G4int vl;
|
||||
const char* tt = ss;
|
||||
G4std::istrstream is((char*)tt);
|
||||
is >> vl;
|
||||
G4int nh = UI->GetNumberOfHistory();
|
||||
if(vl>=0 && vl<nh)
|
||||
{
|
||||
newCommand = UI->GetPreviousCommand(vl);
|
||||
G4cout << newCommand << G4endl;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{ G4cerr << "history " << vl << " is not found." << G4endl; }
|
||||
}
|
||||
else if( nC == "exit" )
|
||||
{
|
||||
if( iCont )
|
||||
{
|
||||
G4cout << "You are now processing RUN." << G4endl;
|
||||
G4cout << "Please abort it using \"/run/abort\" command first" << G4endl;
|
||||
G4cout << " and use \"continue\" command until the application" << G4endl;
|
||||
G4cout << " becomes to Idle." << G4endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
iExit = false;
|
||||
newCommand = nullString;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if( nC == "cont" || nC == "continue" )
|
||||
{
|
||||
iCont = false;
|
||||
newCommand = nullString;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{ break; }
|
||||
}
|
||||
return ModifyToFullPathCommand(newCommand);
|
||||
}
|
||||
|
||||
G4bool G4UIterminal::GetHelpChoice(G4int& aInt){
|
||||
G4cin >> aInt;
|
||||
if(!G4cin.good()){
|
||||
G4cin.clear();
|
||||
G4cin.ignore(30,'\n');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
void G4UIterminal::ExitHelp(){
|
||||
// G4cin.flush();
|
||||
|
||||
/////////////////////////////
|
||||
void G4UIterminal::ExitHelp()
|
||||
/////////////////////////////
|
||||
{
|
||||
char temp[100];
|
||||
G4cin.getline( temp, 100 );
|
||||
G4cin.getline(temp, 100);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user