-------------------------------------------------------------------- shell commands -------------------------------------------------------------------- ////////////////////////////////////////////////////////
| 223 | // -------------------------------------------------------------------- |
| 224 | ///////////////////////////////////////////////////////////// |
| 225 | void 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 += " "; |
no test coverage detected