46 G4String rawCommandLine = aCommandLine;
47 if (rawCommandLine.empty() || rawCommandLine[0] ==
'\0')
return rawCommandLine;
48 G4String commandLine = G4StrUtil::strip_copy(rawCommandLine);
51 size_t i = commandLine.find(
' ');
52 if (i != std::string::npos) {
53 commandString = commandLine.substr(0, i);
54 parameterString =
" ";
55 parameterString += commandLine.substr(i + 1, commandLine.length() - (i + 1));
58 commandString = commandLine;
61 G4String fullPathCommandLine = ModifyPath(commandString) + parameterString;
62 return fullPathCommandLine;
69 G4String newPrefix = G4StrUtil::strip_copy(newDir);
71 G4String newDirectory = ModifyPath(newPrefix);
72 if (newDirectory.back() !=
'/') {
78 currentDirectory = newDirectory;
84 G4String theDir = G4StrUtil::strip_copy(dirName);
86 G4String targetDir = ModifyPath(theDir);
87 if (targetDir.back() !=
'/') {
91 if (targetDir ==
"/") {
95 while (idx < targetDir.length() - 1) {
96 size_t i = targetDir.find(
'/', idx);
97 comTree = comTree->
GetTree(targetDir.substr(0, i + 1).c_str());
98 if (comTree ==
nullptr) {
108 G4String commandLine = G4StrUtil::strip_copy(commandName);
111 size_t i = commandLine.find(
' ');
112 if (i != std::string::npos) {
113 commandString = commandLine.substr(0, i);
116 commandString = commandLine;
119 G4String targetCom = ModifyPath(commandString);
125 if (tempPath.length() == 0)
return tempPath;
130 if (tempPath[0] ==
'/')
133 newPath = currentDirectory + tempPath;
137 size_t idx = newPath.find(
"/./");
138 if (idx == G4String::npos)
break;
139 newPath.erase(idx, 2);
143 size_t idx = newPath.find(
"/../");
144 if (idx == G4String::npos)
break;
149 size_t idx2 = newPath.find_last_of(
'/', idx - 1);
150 if (idx2 != G4String::npos) newPath.erase(idx2, idx - idx2 + 3);
154 if (newPath.size() >= 3) {
155 if (newPath.substr(newPath.size() - 3, 3) ==
"/..") {
156 if (newPath.size() == 3) {
160 size_t idx = newPath.find_last_of(
'/', newPath.size() - 4);
161 if (idx != G4String::npos) newPath.erase(idx + 1);
166 if (newPath.size() >= 2) {
167 if (newPath.substr(newPath.size() - 2, 2) ==
"/.") newPath.erase(newPath.size() - 1, 1);
172 size_t idx = newPath.find(
"//");
173 if (idx == G4String::npos)
break;
174 newPath.erase(idx, 1);
184 G4String rawCommandLine = commandName;
185 G4String commandLine = G4StrUtil::strip_copy(rawCommandLine);
187 size_t i = commandLine.find(
' ');
188 if (i != std::string::npos)
189 return rawCommandLine;
191 G4String commandString = commandLine;
192 G4String targetCom = ModifyPath(commandString);
195 if (value.empty())
return rawCommandLine;
213 if (aCommand.length() < 2)
return;
215 if (UI ==
nullptr)
return;
217 switch (commandStatus) {
221 G4cerr <<
"command not found: "
222 <<
"\"" << aCommand <<
"\"" <<
G4endl;
225 G4cerr <<
"illegal application state -- command refused:"
226 <<
"\"" << aCommand <<
"\"" <<
G4endl;
232 G4cerr <<
"command refused (" << commandStatus <<
"):"
233 <<
"\"" << aCommand <<
"\"" <<
G4endl;
243 if (UI ==
nullptr)
return;
245 G4String command = G4StrUtil::lstrip_copy(a_string);
247 if (command[0] ==
'#') {
250 else if (command ==
"ls" || command.substr(0, 3) ==
"ls ") {
253 else if (command ==
"pwd") {
256 else if (command ==
"cd" || command.substr(0, 3) ==
"cd ") {
259 else if (command ==
"help" || command.substr(0, 5) ==
"help ") {
262 else if (command[0] ==
'?') {
265 else if (command ==
"hist" || command ==
"history") {
267 for (
G4int i = 0; i < nh; i++) {
271 else if (command[0] ==
'!') {
272 G4String ss = command.substr(1, command.length() - 1);
275 std::istringstream is(tt);
278 if (vl >= 0 && vl < nh) {
284 G4cerr <<
"history " << vl <<
" is not found." <<
G4endl;
287 else if (command ==
"exit") {
290 G4cout <<
"Please abort it using \"/run/abort\" command first" <<
G4endl;
291 G4cout <<
" and use \"continue\" command until the application" <<
G4endl;
298 else if (command ==
"cont" || command ==
"continue") {
309 if (UI ==
nullptr)
return;
310 G4String comString = newCommand.substr(1, newCommand.length() - 1);
313 if (! curV.empty()) {
314 G4cout <<
"Current value(s) of the parameter(s) : " << curV <<
G4endl;
321 if (newCommand.length() <= 3) {
325 G4String aNewPrefix = newCommand.substr(3, newCommand.length() - 3);
326 prefix = G4StrUtil::strip_copy(aNewPrefix);
336 if (newCommand.length() <= 3) {
340 G4String newPrefix = newCommand.substr(3, newCommand.length() - 3);
341 targetDir = G4StrUtil::strip_copy(newPrefix);
344 if (commandTree ==
nullptr) {
345 G4cout <<
"Directory <" << targetDir <<
"> is not found." <<
G4endl;
354 if (UI ==
nullptr)
return;
356 size_t i = newCommand.find(
' ');
357 if (i != std::string::npos) {
358 G4String newValue = newCommand.substr(i + 1, newCommand.length() - (i + 1));
359 G4StrUtil::strip(newValue);
362 if (theCommand !=
nullptr) {
367 G4cout <<
"Command <" << newValue <<
" is not found." <<
G4endl;
374 size_t prefixIndex = 1;
376 while (prefixIndex <
prefix.length() - 1) {
377 size_t ii =
prefix.find(
'/', prefixIndex);
379 prefixIndex = ii + 1;
393 if (iFloor < (
size_t)-j)
408 if (j <= n_tree + floor[iFloor]->GetCommandEntry()) {
413 floor[iFloor + 1] = floor[iFloor]->
GetTree(j);
@ fParameterOutOfCandidates
@ fIllegalApplicationState
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
G4UIcommand * GetCommand(G4int i)
G4int GetTreeEntry() const
G4UIcommandTree * GetTree(G4int i)
void ListCurrentWithNum() const
G4String CompleteCommandPath(const G4String &commandPath)
G4UIcommand * FindPath(const char *commandPath) const
G4UIcommandTree * GetTree() const
G4int ApplyCommand(const char *aCommand)
G4int GetNumberOfHistory() const
G4String GetPreviousCommand(G4int i) const
G4String GetCurrentValues(const char *aCommand)
static G4UImanager * GetUIpointer()
G4UIcommand * FindCommand(const char *commandName) const
G4String FindMatchingPath(G4UIcommandTree *, const G4String &)
G4String ModifyToFullPathCommand(const char *aCommandLine) const
G4String Complete(const G4String &)
void ShowCurrent(const G4String &) const
void TerminalHelp(const G4String &)
virtual void ExecuteCommand(const G4String &)
void ListDirectory(const G4String &) const
void ApplyShellCommand(const G4String &, G4bool &, G4bool &)
virtual void ExitHelp() const =0
G4String GetCurrentWorkingDirectory() const
~G4VBasicShell() override
G4bool ChangeDirectory(const char *newDir)
void ChangeDirectoryCommand(const G4String &)
G4UIcommandTree * FindDirectory(const char *dirName) const
virtual G4bool GetHelpChoice(G4int &)=0