56static void SignalHandler(
G4int)
63 G4cout <<
"aborting Run ...";
68 <<
"Session terminated." <<
G4endl;
69 theshell-> ResetTerminal();
73 "KeyboardInterrput with Ctrl-C");
77 signal(SIGINT, SignalHandler);
94 UI-> SetSession(
this);
95 UI-> SetCoutDestination(
this);
100 if(aShell) shell= aShell;
107 signal(SIGINT, SignalHandler);
116 if(shell)
delete shell;
119 UI-> SetSession(NULL);
120 UI-> SetCoutDestination(NULL);
140 ExecuteCommand(newCommand);
141 newCommand= GetCommand();
152 G4String newCommand= GetCommand(msg);
154 ExecuteCommand(newCommand);
155 newCommand= GetCommand(msg);
160void G4UIterminal::ExecuteCommand(
const G4String& aCommand)
163 if(aCommand.length()<2)
return;
165 G4int returnVal = UI-> ApplyCommand(aCommand);
167 G4int paramIndex = returnVal % 100;
170 G4int commandStatus = returnVal - paramIndex;
176 switch(commandStatus) {
181 if( aCommand.find(
"@@") != G4String::npos) {
186 G4cerr <<
"illegal application state -- command refused" <<
G4endl;
198 G4cerr <<
"Parameter is out of candidate list (index " << paramIndex <<
")" <<
G4endl;
202 G4cerr <<
"Parameter is wrong type and/or is not omittable (index " << paramIndex <<
")" <<
G4endl;
206 G4cerr <<
"command refused (" << commandStatus <<
")" <<
G4endl;
211G4String G4UIterminal::GetCommand(
const char* msg)
219 if( nC.length() == 0 ) {
220 newCommand= nullString;
222 }
else if( nC[0] ==
'#' ) {
224 newCommand= nullString;
226 }
else if(nC==
"ls" || nC.substr(0,3)==
"ls " ) {
228 newCommand= nullString;
230 }
else if(nC==
"lc" || nC.substr(0,3)==
"lc " ) {
231 shell-> ListCommand(nC.erase(0,2));
232 newCommand= nullString;
234 }
else if(nC ==
"pwd") {
235 G4cout <<
"Current Command Directory : "
237 newCommand= nullString;
239 }
else if(nC ==
"cwd") {
240 shell-> ShowCurrentDirectory();
241 newCommand= nullString;
243 }
else if(nC ==
"cd" || nC.substr(0,3) ==
"cd ") {
246 newCommand= nullString;
248 }
else if(nC ==
"help" || nC.substr(0,5) ==
"help ") {
250 newCommand= nullString;
252 }
else if(nC[0] ==
'?') {
254 newCommand= nullString;
256 }
else if(nC ==
"hist" || nC ==
"history") {
257 G4int nh= UI-> GetNumberOfHistory();
258 for (
G4int i=0; i<nh; i++) {
261 newCommand= nullString;
263 }
else if(nC[0] ==
'!') {
264 G4String ss= nC.substr(1, nC.length()-1);
267 std::istringstream is(tt);
269 G4int nh= UI-> GetNumberOfHistory();
271 newCommand= UI-> GetPreviousCommand(vl);
274 G4cerr <<
"history " << vl <<
" is not found." <<
G4endl;
275 newCommand= nullString;
278 }
else if(nC ==
"exit") {
281 G4cout <<
"Please abort it using \"/run/abort\" command first" <<
G4endl;
282 G4cout <<
" and use \"continue\" command until the application"
287 newCommand= nullString;
290 }
else if( nC ==
"cont" || nC ==
"continue"){
292 newCommand= nullString;
294 }
else if( nC.empty() ){
295 newCommand= nullString;
308 std::cout << coutString << std::flush;
316 std::cerr << cerrString << std::flush;
327 G4cin.ignore(30,
'\n');
334void G4UIterminal::ExitHelp() const
338 G4cin.getline(temp, 100);
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
@ fParameterOutOfCandidates
@ fIllegalApplicationState
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
static G4StateManager * GetStateManager()
G4UIparameter * GetParameter(G4int i) const
G4int ApplyCommand(const char *aCommand)
G4String GetPreviousCommand(G4int i) const
G4String SolveAlias(const char *aCmd)
static G4UImanager * GetUIpointer()
const G4String & GetParameterCandidates() const
void SetPrompt(const G4String &prompt)
virtual G4int ReceiveG4cout(const G4String &coutString)
G4UIterminal(G4VUIshell *aShell=0, G4bool qsig=true)
virtual void PauseSessionStart(const G4String &msg)
virtual G4UIsession * SessionStart()
virtual G4int ReceiveG4cerr(const G4String &cerrString)
G4UIcommand * FindCommand(const char *commandName) const
G4String ModifyToFullPathCommand(const char *aCommandLine) const
void ShowCurrent(const G4String &) const
void TerminalHelp(const G4String &)
void ListDirectory(const G4String &) const
G4String GetCurrentWorkingDirectory() const
void ChangeDirectoryCommand(const G4String &)
virtual G4String GetCommandLineString(const char *msg=0)=0
G4String lstrip_copy(G4String str, char ch=' ')
Return copy of string with leading characters removed.