MCPcopy Create free account
hub / github.com/Geant4/geant4 / ListCommand

Method ListCommand

source/interfaces/core/src/G4VUIshell.cc:225–321  ·  view source on GitHub ↗

-------------------------------------------------------------------- shell commands -------------------------------------------------------------------- ////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

223// --------------------------------------------------------------------
224/////////////////////////////////////////////////////////////
225void G4VUIshell::ListCommand(const G4String& dir, const G4String& candidate) const
226/////////////////////////////////////////////////////////////
227{
228 // specified directpry
229 G4String input = G4StrUtil::strip_copy(dir);
230
231 // command tree of "user specified directory"
232 G4String vpath = currentCommandDir;
233 G4String vcmd;
234
235 auto len = (G4int)input.length();
236 if (! input.empty()) {
237 G4int indx = -1;
238 for (G4int i = len - 1; i >= 0; --i) { // search last '/'
239 if (input[i] == '/') {
240 indx = i;
241 break;
242 }
243 }
244 // get abs. path
245 if (indx != -1) vpath = GetAbsCommandDirPath(input.substr(0, indx + 1));
246 if (indx != 0 || len != 1) vcmd = input.substr(indx + 1, len - indx - 1); // care for "/"
247 }
248
249 // check "vcmd" is directory?
250 const G4String& inputpath = vpath + vcmd;
251 if (! vcmd.empty()) {
252 const G4String& tmpstr = inputpath + "/";
253 if (GetCommandTree(tmpstr) != nullptr) {
254 vpath = tmpstr;
255 vcmd = "";
256 }
257 }
258
259 // check "vpath" directory exists?
260 G4UIcommandTree* atree = GetCommandTree(vpath);
261 if (atree == nullptr) {
262 G4cout << "<" << input << ">: No such directory" << G4endl;
263 return;
264 }
265
266 // list matched directories/commands
267 G4String stream;
268 G4bool isMatch = false;
269
270 G4int Ndir = atree->GetTreeEntry();
271 G4int Ncmd = atree->GetCommandEntry();
272 if (Ndir == 0 && Ncmd == 0) return; // no contents
273
274 // directory ...
275 for (G4int idir = 1; idir <= Ndir; idir++) {
276 if (idir == 1 && lsColorFlag) stream += TermColorString[directoryColor];
277 G4String fpdir = atree->GetTree(idir)->GetPathName();
278 // matching test
279 if (candidate.empty()) { // list all
280 if (vcmd.empty() || fpdir == inputpath) {
281 stream += GetCommandPathTail(fpdir);
282 stream += " ";

Callers 2

GetCommandMethod · 0.80
GetCommandMethod · 0.80

Calls 9

substrMethod · 0.80
GetTreeEntryMethod · 0.80
GetCommandEntryMethod · 0.80
ShowMethod · 0.80
lengthMethod · 0.45
emptyMethod · 0.45
GetTreeMethod · 0.45
findMethod · 0.45
GetCommandMethod · 0.45

Tested by

no test coverage detected