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.
index(
"@@") != 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)
217 newCommand= shell-> GetCommandLineString(msg);
220 if( nC.length() == 0 ) {
221 newCommand= nullString;
223 }
else if( nC(0) ==
'#' ) {
225 newCommand= nullString;
227 }
else if(nC==
"ls" || nC.substr(0,3)==
"ls " ) {
229 newCommand= nullString;
231 }
else if(nC==
"lc" || nC.substr(0,3)==
"lc " ) {
232 shell-> ListCommand(nC.
remove(0,2));
233 newCommand= nullString;
235 }
else if(nC ==
"pwd") {
236 G4cout <<
"Current Command Directory : "
238 newCommand= nullString;
240 }
else if(nC ==
"cwd") {
241 shell-> ShowCurrentDirectory();
242 newCommand= nullString;
244 }
else if(nC ==
"cd" || nC.substr(0,3) ==
"cd ") {
247 newCommand= nullString;
249 }
else if(nC ==
"help" || nC.substr(0,5) ==
"help ") {
251 newCommand= nullString;
253 }
else if(nC(0) ==
'?') {
255 newCommand= nullString;
257 }
else if(nC ==
"hist" || nC ==
"history") {
258 G4int nh= UI-> GetNumberOfHistory();
259 for (
G4int i=0; i<nh; i++) {
262 newCommand= nullString;
264 }
else if(nC(0) ==
'!') {
268 std::istringstream is(tt);
270 G4int nh= UI-> GetNumberOfHistory();
272 newCommand= UI-> GetPreviousCommand(vl);
275 G4cerr <<
"history " << vl <<
" is not found." <<
G4endl;
276 newCommand= nullString;
279 }
else if(nC ==
"exit") {
282 G4cout <<
"Please abort it using \"/run/abort\" command first" <<
G4endl;
283 G4cout <<
" and use \"continue\" command until the application"
288 newCommand= nullString;
291 }
else if( nC ==
"cont" || nC ==
"continue"){
293 newCommand= nullString;
295 }
else if( nC.empty() ){
296 newCommand= nullString;
309 std::cout << coutString << std::flush;
317 std::cerr << cerrString << std::flush;
328 G4cin.ignore(30,
'\n');
335void G4UIterminal::ExitHelp() const
339 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()
G4String & remove(str_size)
str_size index(const char *, G4int pos=0) const
G4String strip(G4int strip_Type=trailing, char c=' ')
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 &)