Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Protected Member Functions | Protected Attributes
G4VUIshell Class Referenceabstract

#include <G4VUIshell.hh>

Inheritance diagram for G4VUIshell:
G4UIcsh G4UImpish G4UItcsh

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 SetLsColor (TermColorIndex, TermColorIndex)
 
virtual void ShowCurrentDirectory () const
 
virtual void ListCommand (const G4String &input, const G4String &candidate="") const
 
virtual G4String GetCommandLineString (const char *msg=0)=0
 
virtual void ResetTerminal ()
 

Protected Member Functions

virtual void MakePrompt (const char *msg=0)
 
G4UIcommandTreeGetCommandTree (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
 

Detailed Description

Definition at line 59 of file G4VUIshell.hh.

Constructor & Destructor Documentation

G4VUIshell::G4VUIshell ( const G4String prompt = "> ")

Definition at line 46 of file G4VUIshell.cc.

47  : promptSetting(prompt), promptString(""), nColumn(80),
50 ///////////////////////////////////////////////////////////////////
51 {
52 }
G4String promptString
Definition: G4VUIshell.hh:62
TermColorIndex directoryColor
Definition: G4VUIshell.hh:69
TermColorIndex commandColor
Definition: G4VUIshell.hh:70
G4int nColumn
Definition: G4VUIshell.hh:64
G4bool lsColorFlag
Definition: G4VUIshell.hh:68
#define FALSE
Definition: globals.hh:52
G4String currentCommandDir
Definition: G4VUIshell.hh:73
G4String promptSetting
Definition: G4VUIshell.hh:61
G4VUIshell::~G4VUIshell ( )
virtual

Definition at line 55 of file G4VUIshell.cc.

57 {
58 }

Member Function Documentation

G4String G4VUIshell::GetAbsCommandDirPath ( const G4String apath) const
protected

Definition at line 147 of file G4VUIshell.cc.

References G4String::index(), G4String::last(), and G4String::remove().

Referenced by G4UItcsh::CompleteCommand(), and G4UItcsh::ListMatchedCommand().

149 {
150  if(apath.empty()) return apath; // null string
151 
152  // if "apath" does not start with "/",
153  // then it is treared as relative path
154  G4String bpath= apath;
155  if(apath[(size_t)0] != '/') bpath= currentCommandDir + apath;
156 
157  // parsing...
158  G4String absPath= "/";
159  for(G4int indx=1; indx<=G4int(bpath.length())-1; ) {
160  G4int jslash= bpath.index("/", indx); // search index begin with "/"
161  if(indx == jslash) { // skip first '///'
162  indx++;
163  continue;
164  }
165  if(jslash != G4int(G4String::npos)) {
166  if(bpath.substr(indx,jslash-indx) == ".."){ // directory up
167  if(absPath == "/") {
168  indx = jslash+1;
169  continue;
170  }
171  if(absPath.length() >= 2) {
172  absPath.remove(absPath.length()-1); // remove last "/"
173  G4int jpre= absPath.last('/');
174  if(jpre != G4int(G4String::npos)) absPath.remove(jpre+1);
175  }
176  } else if(bpath.substr(indx,jslash-indx) == "."){ // nothing to do
177  } else { // add
178  if( !(jslash==indx && bpath(indx)=='/') ) // truncate "////"
179  absPath+= bpath(indx, jslash-indx+1);
180  // better to be check directory existence. (it costs!)
181  }
182  indx= jslash+1;
183  } else { // directory ONLY (ignore non-"/" terminated string)
184  break;
185  }
186  }
187 
188  return absPath;
189 }
G4String & remove(str_size)
int G4int
Definition: G4Types.hh:78
str_size index(const char *, G4int pos=0) const
G4int last(char) const
G4String currentCommandDir
Definition: G4VUIshell.hh:73
virtual G4String G4VUIshell::GetCommandLineString ( const char *  msg = 0)
pure virtual

Implemented in G4UItcsh, G4UIcsh, and G4UImpish.

G4String G4VUIshell::GetCommandPathTail ( const G4String apath) const
protected

Definition at line 193 of file G4VUIshell.cc.

References FALSE, and TRUE.

Referenced by G4UItcsh::CompleteCommand().

195 { // xxx/xxx/zzz -> zzz, trancate /// -> /
196  if(apath.empty()) return apath;
197 
198  G4int lstr= apath.length();
199 
200  // for trancating "/"
201  G4bool Qsla= FALSE;
202  if(apath[(size_t)(lstr-1)]=='/') Qsla= TRUE;
203 
204  // searching last '/' from tail
205  G4int indx= -1;
206  for(G4int i=lstr-1; i>=0; i--) {
207  if(Qsla && apath[(size_t)i]!='/') Qsla= FALSE; // break "/" flag!!
208  if(apath[(size_t)i]=='/' && !Qsla) {
209  indx= i;
210  break;
211  }
212  }
213 
214  if(indx==-1) return apath; // not found
215 
216  if(indx==0 && lstr==1) { // "/"
217  G4String nullStr;
218  return nullStr;
219  } else {
220  //G4String newPath= apath(indx+1,lstr-indx-1);
221  G4String newPath= apath;
222  newPath= newPath(indx+1,lstr-indx-1);
223  return newPath;
224  }
225 }
int G4int
Definition: G4Types.hh:78
bool G4bool
Definition: G4Types.hh:79
#define FALSE
Definition: globals.hh:52
#define TRUE
Definition: globals.hh:55
G4UIcommandTree * G4VUIshell::GetCommandTree ( const G4String dir) const
protected

Definition at line 118 of file G4VUIshell.cc.

References G4String::both, G4UImanager::GetUIpointer(), G4String::index(), and G4String::strip().

Referenced by G4UItcsh::CompleteCommand().

120 {
122 
123  G4UIcommandTree* cmdTree= UI-> GetTree(); // root tree
124 
125  G4String absPath= input; // G4String::strip() CONST !!
126  absPath= GetAbsCommandDirPath(absPath.strip(G4String::both));
127 
128  // parsing absolute path ...
129  if(absPath.length()==0) return NULL;
130  if(absPath[absPath.length()-1] != '/') return NULL; // error??
131  if(absPath=="/") return cmdTree;
132 
133  for(G4int indx=1; indx<G4int(absPath.length())-1; ) {
134  G4int jslash= absPath.index("/", indx); // search index begin with "/"
135  if(jslash != G4int(G4String::npos)) {
136  if(cmdTree != NULL)
137  cmdTree= cmdTree-> GetTree(G4String(absPath(0,jslash+1)));
138  }
139  indx= jslash+1;
140  }
141 
142  if(cmdTree == NULL) return NULL;
143  else return cmdTree;
144 }
G4String strip(G4int strip_Type=trailing, char c=' ')
int G4int
Definition: G4Types.hh:78
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4String GetAbsCommandDirPath(const G4String &apath) const
Definition: G4VUIshell.cc:147
str_size index(const char *, G4int pos=0) const
void G4VUIshell::ListCommand ( const G4String input,
const G4String candidate = "" 
) const
virtual

Definition at line 231 of file G4VUIshell.cc.

References G4String::both, FALSE, G4cout, G4endl, G4String::index(), G4UIArrayString::Show(), G4String::strip(), and TRUE.

Referenced by G4UItcsh::ListMatchedCommand().

234 {
235  // specified directpry
236  G4String input= dir; // ...
237  input= input.strip(G4String::both);
238 
239  // command tree of "user specified directory"
241  G4String vcmd;
242 
243  G4int len= input.length();
244  if(! input.empty()) {
245  G4int indx= -1;
246  for(G4int i=len-1; i>=0; i--) { // search last '/'
247  if(input[(size_t)i]=='/') {
248  indx= i;
249  break;
250  }
251  }
252  // get abs. path
253  if(indx != -1) vpath= GetAbsCommandDirPath(input(0,indx+1));
254  if(!(indx==0 && len==1)) vcmd= input(indx+1,len-indx-1); // care for "/"
255  }
256 
257  // check "vcmd" is directory?
258  G4String inputpath= vpath+vcmd;
259  if(! vcmd.empty()){
260  G4String tmpstr= inputpath + "/";
261  if(GetCommandTree(tmpstr) != NULL) {
262  vpath= tmpstr;
263  vcmd= "";
264  }
265  }
266 
267  // check "vpath" directory exists?
268  G4UIcommandTree* atree= GetCommandTree(vpath);
269  if(atree == NULL) {
270  G4cout << "<" << input << ">: No such directory" << G4endl;
271  return;
272  }
273 
274  // list matched directories/commands
275  G4String stream;
276  G4bool isMatch= FALSE;
277 
278  G4int Ndir= atree-> GetTreeEntry();
279  G4int Ncmd= atree-> GetCommandEntry();
280  if(Ndir==0 && Ncmd==0) return; // no contents
281 
282  // directory ...
283  for(G4int idir=1; idir<=Ndir; idir++) {
284  if(idir==1 && lsColorFlag) stream+= TermColorString[directoryColor];
285  G4String fpdir= atree-> GetTree(idir)-> GetPathName();
286  // matching test
287  if(candidate.empty()) { // list all
288  if(vcmd=="" || fpdir==inputpath) {
289  stream+= GetCommandPathTail(fpdir); stream+= " ";
290  isMatch= TRUE;
291  }
292  } else { // list only matched with candidate
293  if( fpdir.index(candidate, 0) == 0) {
294  stream+= GetCommandPathTail(fpdir); stream+= " ";
295  }
296  }
297  }
298 
299  // command ...
300  for(G4int icmd=1; icmd<=Ncmd; icmd++){
301  if(icmd==1 && lsColorFlag) stream+= TermColorString[commandColor];
302  G4String fpcmd= atree-> GetPathName() +
303  atree-> GetCommand(icmd) -> GetCommandName();
304  // matching test
305  if(candidate.empty()) { // list all
306  if(vcmd=="" || fpcmd==inputpath) {
307  stream+= GetCommandPathTail(fpcmd); stream+= "* ";
308  isMatch= TRUE;
309  }
310  } else { // list only matched with candidate
311  if( fpcmd.index(candidate, 0) == 0) {
312  stream+= GetCommandPathTail(fpcmd); stream+= "* ";
313  }
314  }
315  }
316 
317  // waring : not matched
318  if(!isMatch && candidate.empty())
319  G4cout << "<" << input
320  << ">: No such directory or command" << std::flush;
321 
322  // display
323  G4UIArrayString arrayString(stream);
324  arrayString.Show(nColumn);
325 }
G4String GetCommandPathTail(const G4String &apath) const
Definition: G4VUIshell.cc:193
TermColorIndex directoryColor
Definition: G4VUIshell.hh:69
G4String strip(G4int strip_Type=trailing, char c=' ')
int G4int
Definition: G4Types.hh:78
G4String GetAbsCommandDirPath(const G4String &apath) const
Definition: G4VUIshell.cc:147
TermColorIndex commandColor
Definition: G4VUIshell.hh:70
G4GLOB_DLL std::ostream G4cout
str_size index(const char *, G4int pos=0) const
G4int nColumn
Definition: G4VUIshell.hh:64
bool G4bool
Definition: G4Types.hh:79
G4bool lsColorFlag
Definition: G4VUIshell.hh:68
#define FALSE
Definition: globals.hh:52
#define TRUE
Definition: globals.hh:55
G4UIcommandTree * GetCommandTree(const G4String &dir) const
Definition: G4VUIshell.cc:118
G4String currentCommandDir
Definition: G4VUIshell.hh:73
const XML_Char int len
#define G4endl
Definition: G4ios.hh:61
void G4VUIshell::MakePrompt ( const char *  msg = 0)
protectedvirtual

Reimplemented in G4UItcsh.

Definition at line 61 of file G4VUIshell.cc.

References G4String::append(), currentCommandDir, G4StateManager::GetCurrentState(), G4StateManager::GetStateManager(), promptSetting, and promptString.

Referenced by G4UIcsh::GetCommandLineString().

63 {
64  if(promptSetting.length()<=1) {
66  return;
67  }
68 
69  promptString="";
70  G4int i;
71  for(i=0; i<G4int(promptSetting.length())-1; i++){
72  if(promptSetting[(size_t)i]=='%'){
73  switch (promptSetting[(size_t)(i+1)]) {
74  case 's': // current application status
75  {
76  G4String stateStr;
77  if(msg)
78  { stateStr = msg; }
79  else
80  {
82  stateStr= statM-> GetStateString(statM->GetCurrentState());
83  }
84  promptString.append(stateStr);
85  i++;
86  }
87  break;
88  case '/': // current working directory
90  i++;
91  break;
92  default:
94  break;
95  }
96  } else {
98  }
99  }
100 
101  // append last chaacter
102  if(i == G4int(promptSetting.length())-1)
104 }
G4String promptString
Definition: G4VUIshell.hh:62
int G4int
Definition: G4Types.hh:78
static G4StateManager * GetStateManager()
G4ApplicationState GetCurrentState() const
G4String & append(const G4String &)
G4String currentCommandDir
Definition: G4VUIshell.hh:73
G4String promptSetting
Definition: G4VUIshell.hh:61
void G4VUIshell::ResetTerminal ( )
virtual

Reimplemented in G4UItcsh.

Definition at line 108 of file G4VUIshell.cc.

110 {
111 
112 }
void G4VUIshell::SetCurrentDirectory ( const G4String ccd)
inline

Definition at line 115 of file G4VUIshell.hh.

References currentCommandDir.

116 {
117  currentCommandDir= dir;
118 }
G4String currentCommandDir
Definition: G4VUIshell.hh:73
void G4VUIshell::SetLsColor ( TermColorIndex  ,
TermColorIndex   
)
inlinevirtual

Reimplemented in G4UItcsh.

Definition at line 120 of file G4VUIshell.hh.

121 {
122 }
void G4VUIshell::SetNColumn ( G4int  ncol)
inline

Definition at line 105 of file G4VUIshell.hh.

References nColumn.

106 {
107  nColumn= ncol;
108 }
G4int nColumn
Definition: G4VUIshell.hh:64
void G4VUIshell::SetPrompt ( const G4String prompt)
inline

Definition at line 110 of file G4VUIshell.hh.

References promptSetting.

111 {
112  promptSetting= prompt;
113 }
G4String promptSetting
Definition: G4VUIshell.hh:61
void G4VUIshell::ShowCurrentDirectory ( ) const
inlinevirtual

Definition at line 124 of file G4VUIshell.hh.

References currentCommandDir, G4cout, and G4endl.

125 {
127 }
G4GLOB_DLL std::ostream G4cout
G4String currentCommandDir
Definition: G4VUIshell.hh:73
#define G4endl
Definition: G4ios.hh:61

Field Documentation

TermColorIndex G4VUIshell::commandColor
protected

Definition at line 70 of file G4VUIshell.hh.

Referenced by G4UItcsh::SetLsColor().

G4String G4VUIshell::currentCommandDir
protected
TermColorIndex G4VUIshell::directoryColor
protected

Definition at line 69 of file G4VUIshell.hh.

Referenced by G4UItcsh::SetLsColor().

G4bool G4VUIshell::lsColorFlag
protected

Definition at line 68 of file G4VUIshell.hh.

Referenced by G4UItcsh::SetLsColor().

G4int G4VUIshell::nColumn
protected

Definition at line 64 of file G4VUIshell.hh.

Referenced by SetNColumn().

G4String G4VUIshell::promptSetting
protected

Definition at line 61 of file G4VUIshell.hh.

Referenced by MakePrompt(), G4UItcsh::MakePrompt(), and SetPrompt().

G4String G4VUIshell::promptString
protected

The documentation for this class was generated from the following files: