#include <G4VUIshell.hh>
Inheritance diagram for G4VUIshell:
Public Member Functions | |
G4VUIshell (const G4String &prompt=">") | |
virtual | ~G4VUIshell () |
void | SetNColumn (G4int ncol) |
void | SetPrompt (const G4String &prompt) |
void | SetCurrentDirectory (const G4String &ccd) |
virtual void | ShowCurrentDirectory () const |
virtual void | ListCommand (const G4String &input, const G4String &candidate="") const |
virtual G4String | GetCommandLine (const char *msg=0)=0 |
Protected Member Functions | |
virtual void | MakePrompt (const char *msg=0) |
G4UIcommandTree * | GetCommandTree (const G4String &dir) const |
G4String | GetAbsCommandDirPath (const G4String &apath) const |
G4String | GetCommandPathTail (const G4String &apath) const |
Protected Attributes | |
G4String | promptSetting |
G4String | promptString |
G4int | nColumn |
G4bool | lsColorFlag |
TermColorIndex | directoryColor |
TermColorIndex | commandColor |
G4String | currentCommandDir |
|
Definition at line 47 of file G4VUIshell.cc. References BLACK.
00048 : promptSetting(prompt), promptString(""), nColumn(80), 00049 lsColorFlag(FALSE), directoryColor(BLACK), commandColor(BLACK), 00050 currentCommandDir("/") 00052 { 00053 } |
|
Definition at line 56 of file G4VUIshell.cc.
00058 { 00059 } |
|
Definition at line 141 of file G4VUIshell.cc. Referenced by G4UItcsh::CompleteCommand(), and G4UItcsh::ListMatchedCommand().
00143 { 00144 if(apath.empty()) return apath; // null string 00145 00146 // if "apath" does not start with "/", 00147 // then it is treared as relative path 00148 G4String bpath= apath; 00149 if(apath[(size_t)0] != '/') bpath= currentCommandDir + apath; 00150 00151 // parsing... 00152 G4String absPath= "/"; 00153 for(G4int indx=1; indx<=G4int(bpath.length())-1; ) { 00154 G4int jslash= bpath.index("/", indx); // search index begin with "/" 00155 if(jslash != G4int(G4String::npos)) { 00156 if(bpath(indx,jslash-indx) == ".."){ // directory up 00157 if(absPath.length() >=1) { 00158 absPath.remove(absPath.length()-1); // remove last "/" 00159 G4int jpre= absPath.last('/'); 00160 if(jpre != G4int(G4String::npos)) absPath.remove(jpre+1); 00161 } 00162 } else if(bpath(indx,jslash-indx) == "."){ // nothing to do 00163 } else { // add 00164 if( !(jslash==indx && bpath(indx)=='/') ) // truncate "////" 00165 absPath+= bpath(indx, jslash-indx+1); 00166 // better to be check directory existence. (it costs!) 00167 } 00168 } else { // directory ONLY (ignore non-"/" terminated string) 00169 } 00170 indx= jslash+1; 00171 } 00172 return absPath; 00173 } |
|
|
|
Definition at line 177 of file G4VUIshell.cc. Referenced by G4UItcsh::CompleteCommand().
00179 { // xxx/xxx/zzz -> zzz, trancate /// -> / 00180 if(apath.empty()) return apath; 00181 00182 G4int lstr= apath.length(); 00183 00184 // for trancating "/" 00185 G4bool Qsla= FALSE; 00186 if(apath[(size_t)(lstr-1)]=='/') Qsla= TRUE; 00187 00188 // searching last '/' from tail 00189 G4int indx= -1; 00190 for(G4int i=lstr-1; i>=0; i--) { 00191 if(Qsla && apath[(size_t)i]!='/') Qsla= FALSE; // break "/" flag!! 00192 if(apath[(size_t)i]=='/' && !Qsla) { 00193 indx= i; 00194 break; 00195 } 00196 } 00197 00198 if(indx==-1) return apath; // not found 00199 00200 if(indx==0 && lstr==1) { // "/" 00201 G4String nullStr; 00202 return nullStr; 00203 } else { 00204 //G4String newPath= apath(indx+1,lstr-indx-1); 00205 G4String newPath= apath; 00206 newPath= newPath(indx+1,lstr-indx-1); 00207 return newPath; 00208 } 00209 } |
|
Definition at line 112 of file G4VUIshell.cc. Referenced by G4UItcsh::CompleteCommand().
00114 { 00115 G4UImanager* UI= G4UImanager::GetUIpointer(); 00116 00117 G4UIcommandTree* cmdTree= UI-> GetTree(); // root tree 00118 00119 G4String absPath= input; // G4String::strip() CONST !! 00120 absPath= GetAbsCommandDirPath(absPath.strip(G4String::both)); 00121 00122 // parsing absolute path ... 00123 if(absPath.length()==0) return NULL; 00124 if(absPath[absPath.length()-1] != '/') return NULL; // error?? 00125 if(absPath=="/") return cmdTree; 00126 00127 for(G4int indx=1; indx<G4int(absPath.length())-1; ) { 00128 G4int jslash= absPath.index("/", indx); // search index begin with "/" 00129 if(jslash != G4int(G4String::npos)) { 00130 if(cmdTree != NULL) 00131 cmdTree= cmdTree-> GetTree(G4String(absPath(0,jslash+1))); 00132 } 00133 indx= jslash+1; 00134 } 00135 00136 if(cmdTree == NULL) return NULL; 00137 else return cmdTree; 00138 } |
|
Definition at line 215 of file G4VUIshell.cc. References G4UIArrayString::Show(), and TermColorString. Referenced by G4UItcsh::ListMatchedCommand().
00218 { 00219 // specified directpry 00220 G4String input= dir; // ... 00221 input= input.strip(G4String::both); 00222 00223 // command tree of "user specified directory" 00224 G4String vpath= currentCommandDir; 00225 G4String vcmd; 00226 00227 G4int len= input.length(); 00228 if(! input.empty()) { 00229 G4int indx= -1; 00230 for(G4int i=len-1; i>=0; i--) { // search last '/' 00231 if(input[(size_t)i]=='/') { 00232 indx= i; 00233 break; 00234 } 00235 } 00236 // get abs. path 00237 if(indx != -1) vpath= GetAbsCommandDirPath(input(0,indx+1)); 00238 if(!(indx==0 && len==1)) vcmd= input(indx+1,len-indx-1); // care for "/" 00239 } 00240 00241 // check "vcmd" is directory? 00242 G4String inputpath= vpath+vcmd; 00243 if(! vcmd.empty()){ 00244 G4String tmpstr= inputpath + "/"; 00245 if(GetCommandTree(tmpstr) != NULL) { 00246 vpath= tmpstr; 00247 vcmd= ""; 00248 } 00249 } 00250 00251 // check "vpath" directory exists? 00252 G4UIcommandTree* atree= GetCommandTree(vpath); 00253 if(atree == NULL) { 00254 G4cout << "<" << input << ">: No such directory" << G4endl; 00255 return; 00256 } 00257 00258 // list matched directories/commands 00259 G4String stream; 00260 G4bool isMatch= FALSE; 00261 00262 G4int Ndir= atree-> GetTreeEntry(); 00263 G4int Ncmd= atree-> GetCommandEntry(); 00264 if(Ndir==0 && Ncmd==0) return; // no contents 00265 00266 // directory ... 00267 for(G4int idir=1; idir<=Ndir; idir++) { 00268 if(idir==1 && lsColorFlag) stream+= TermColorString[directoryColor]; 00269 G4String fpdir= atree-> GetTree(idir)-> GetPathName(); 00270 // matching test 00271 if(candidate.empty()) { // list all 00272 if(vcmd=="" || fpdir==inputpath) { 00273 stream+= GetCommandPathTail(fpdir); stream+= " "; 00274 isMatch= TRUE; 00275 } 00276 } else { // list only matched with candidate 00277 if( fpdir.index(candidate, 0) == 0) { 00278 stream+= GetCommandPathTail(fpdir); stream+= " "; 00279 } 00280 } 00281 } 00282 00283 // command ... 00284 for(G4int icmd=1; icmd<=Ncmd; icmd++){ 00285 if(icmd==1 && lsColorFlag) stream+= TermColorString[commandColor]; 00286 G4String fpcmd= atree-> GetPathName() + 00287 atree-> GetCommand(icmd) -> GetCommandName(); 00288 // matching test 00289 if(candidate.empty()) { // list all 00290 if(vcmd=="" || fpcmd==inputpath) { 00291 stream+= GetCommandPathTail(fpcmd); stream+= "* "; 00292 isMatch= TRUE; 00293 } 00294 } else { // list only matched with candidate 00295 if( fpcmd.index(candidate, 0) == 0) { 00296 stream+= GetCommandPathTail(fpcmd); stream+= "* "; 00297 } 00298 } 00299 } 00300 00301 // waring : not matched 00302 if(!isMatch && candidate.empty()) 00303 G4cout << "<" << input 00304 << ">: No such directory or command" << std::flush; 00305 00306 // display 00307 G4UIArrayString arrayString(stream); 00308 arrayString.Show(nColumn); 00309 } |
Here is the call graph for this function:
|
Reimplemented in G4UItcsh. Definition at line 62 of file G4VUIshell.cc. References currentCommandDir, promptSetting, and promptString. Referenced by G4UIcsh::GetCommandLine().
00064 { 00065 if(promptSetting.length()<=1) { 00066 promptString= promptSetting; 00067 return; 00068 } 00069 00070 promptString=""; 00071 G4int i; 00072 for(i=0; i<G4int(promptSetting.length())-1; i++){ 00073 if(promptSetting[(size_t)i]=='%'){ 00074 switch (promptSetting[(size_t)(i+1)]) { 00075 case 's': // current application status 00076 { 00077 G4String stateStr; 00078 if(msg) 00079 { stateStr = msg; } 00080 else 00081 { 00082 G4StateManager* statM= G4StateManager::GetStateManager(); 00083 stateStr= statM-> GetStateString(statM->GetCurrentState()); 00084 } 00085 promptString.append(stateStr); 00086 i++; 00087 } 00088 break; 00089 case '/': // current working directory 00090 promptString.append(currentCommandDir); 00091 i++; 00092 break; 00093 default: 00094 promptString.append(G4String(promptSetting[(size_t)i])); 00095 break; 00096 } 00097 } else { 00098 promptString.append(G4String(promptSetting[(size_t)i])); 00099 } 00100 } 00101 00102 // append last chaacter 00103 if(i == G4int(promptSetting.length())-1) 00104 promptString.append(G4String(promptSetting[(size_t)i])); 00105 } |
|
Definition at line 111 of file G4VUIshell.hh. References currentCommandDir.
00112 { 00113 currentCommandDir= dir; 00114 } |
|
Definition at line 101 of file G4VUIshell.hh. References nColumn.
00102 { 00103 nColumn= ncol; 00104 } |
|
Definition at line 106 of file G4VUIshell.hh. References promptSetting.
00107 { 00108 promptSetting= prompt; 00109 } |
|
Definition at line 116 of file G4VUIshell.hh. References currentCommandDir.
00117 { 00118 G4cout << currentCommandDir << G4endl; 00119 } |
|
Definition at line 70 of file G4VUIshell.hh. Referenced by G4UItcsh::SetLsColor(). |
|
Definition at line 73 of file G4VUIshell.hh. Referenced by G4UItcsh::CompleteCommand(), G4UItcsh::ListMatchedCommand(), MakePrompt(), G4UItcsh::MakePrompt(), SetCurrentDirectory(), and ShowCurrentDirectory(). |
|
Definition at line 69 of file G4VUIshell.hh. Referenced by G4UItcsh::SetLsColor(). |
|
Definition at line 68 of file G4VUIshell.hh. Referenced by G4UItcsh::SetLsColor(). |
|
Definition at line 64 of file G4VUIshell.hh. Referenced by SetNColumn(). |
|
Definition at line 61 of file G4VUIshell.hh. Referenced by MakePrompt(), G4UItcsh::MakePrompt(), and SetPrompt(). |
|
Definition at line 62 of file G4VUIshell.hh. Referenced by G4UItcsh::ClearScreen(), G4UItcsh::GetCommandLine(), G4UIcsh::GetCommandLine(), G4UItcsh::ListMatchedCommand(), MakePrompt(), and G4UItcsh::MakePrompt(). |