46 : promptSetting(prompt), promptString(
""), nColumn(80),
48 currentCommandDir(
"/")
127 if(absPath.length()==0)
return NULL;
128 if(absPath[absPath.length()-1] !=
'/')
return NULL;
129 if(absPath==
"/")
return cmdTree;
131 for(
G4int indx=1; indx<
G4int(absPath.length())-1; ) {
132 G4int jslash= absPath.find(
"/", indx);
133 if(jslash !=
G4int(G4String::npos)) {
135 cmdTree= cmdTree-> GetTree(
G4String(absPath.substr(0,jslash+1)));
140 if(cmdTree == NULL)
return NULL;
148 if(apath.empty())
return apath;
153 if(apath[(
size_t)0] !=
'/') bpath= currentCommandDir + apath;
157 for(
G4int indx=1; indx<=
G4int(bpath.length())-1; ) {
158 G4int jslash= bpath.find(
"/", indx);
163 if(jslash !=
G4int(G4String::npos)) {
164 if(bpath.substr(indx,jslash-indx) ==
".."){
169 if(absPath.length() >= 2) {
170 absPath.erase(absPath.length()-1);
171 auto jpre= absPath.rfind(
'/');
172 if(jpre != G4String::npos) absPath.erase(jpre+1);
174 }
else if(bpath.substr(indx,jslash-indx) ==
"."){
176 if( !(jslash==indx && bpath[indx]==
'/') )
177 absPath+= bpath.substr(indx, jslash-indx+1);
194 if(apath.empty())
return apath;
196 G4int lstr= apath.length();
200 if(apath[(
size_t)(lstr-1)]==
'/') Qsla=
TRUE;
204 for(
G4int i=lstr-1; i>=0; i--) {
205 if(Qsla && apath[(
size_t)i]!=
'/') Qsla=
FALSE;
206 if(apath[(
size_t)i]==
'/' && !Qsla) {
212 if(indx==-1)
return apath;
214 if(indx==0 && lstr==1) {
220 newPath= newPath.substr(indx+1,lstr-indx-1);
240 G4int len= input.length();
241 if(! input.empty()) {
243 for(
G4int i=len-1; i>=0; i--) {
244 if(input[(
size_t)i]==
'/') {
250 if(indx != -1) vpath= GetAbsCommandDirPath(input.substr(0,indx+1));
251 if(!(indx==0 && len==1)) vcmd= input.substr(indx+1,len-indx-1);
267 G4cout <<
"<" << input <<
">: No such directory" <<
G4endl;
275 G4int Ndir= atree-> GetTreeEntry();
276 G4int Ncmd= atree-> GetCommandEntry();
277 if(Ndir==0 && Ncmd==0)
return;
280 for(
G4int idir=1; idir<=Ndir; idir++) {
282 G4String fpdir= atree-> GetTree(idir)-> GetPathName();
284 if(candidate.empty()) {
285 if(vcmd==
"" || fpdir==inputpath) {
286 stream+= GetCommandPathTail(fpdir); stream+=
" ";
290 if( fpdir.find(candidate, 0) == 0) {
291 stream+= GetCommandPathTail(fpdir); stream+=
" ";
297 for(
G4int icmd=1; icmd<=Ncmd; icmd++){
299 G4String fpcmd= atree-> GetPathName() +
300 atree-> GetCommand(icmd) -> GetCommandName();
302 if(candidate.empty()) {
303 if(vcmd==
"" || fpcmd==inputpath) {
304 stream+= GetCommandPathTail(fpcmd); stream+=
"* ";
308 if( fpcmd.find(candidate, 0) == 0) {
309 stream+= GetCommandPathTail(fpcmd); stream+=
"* ";
315 if(!isMatch && candidate.empty())
317 <<
">: No such directory or command" << std::flush;
321 arrayString.
Show(nColumn);
static const G4String TermColorString[8]
static const G4String strESC(1,'\033')
G4GLOB_DLL std::ostream G4cout
const G4ApplicationState & GetCurrentState() const
static G4StateManager * GetStateManager()
static G4UImanager * GetUIpointer()
virtual void ResetTerminal()
virtual void MakePrompt(const char *msg=0)
virtual void ListCommand(const G4String &input, const G4String &candidate="") const
G4UIcommandTree * GetCommandTree(const G4String &dir) const
G4String currentCommandDir
G4VUIshell(const G4String &prompt="> ")
G4String GetCommandPathTail(const G4String &apath) const
G4String GetAbsCommandDirPath(const G4String &apath) const
G4String strip_copy(G4String str, char c=' ')
Return copy of string with leading and trailing characters removed.
void GetCommandTree(G4UIcommandTree *ctree)