- Timestamp:
- May 5, 2009, 5:45:31 PM (15 years ago)
- Location:
- trunk/source
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/intercoms/include/G4UIcommandTree.hh
r1016 r1027 57 57 G4UIcommand * FindPath(const char* commandPath); 58 58 G4UIcommandTree * FindCommandTree(const char* commandPath); 59 G4String CompleteCommandPath(const G4String commandPath); 60 // Complete most available caracters in common into command path in the command line 61 // given 62 59 63 void List(); 60 64 void ListCurrent(); … … 65 69 G4String CreateFileName(const char* pName); 66 70 G4String ModStr(const char* strS); 71 G4String GetFirstMatchedString(const G4String&,const G4String&) const; 67 72 68 73 std::vector<G4UIcommand*> command; -
trunk/source/intercoms/src/G4UIcommandTree.cc
r1016 r1027 199 199 G4UIcommandTree * G4UIcommandTree::FindCommandTree(const char* commandPath) 200 200 { 201 printf("G4UIcommandTree::FindCommandTree %s\n",commandPath); 201 202 G4String remainingPath = commandPath; 202 203 if( remainingPath.index( pathName ) == std::string::npos ) … … 219 220 } 220 221 } 222 } else { 223 return this; 221 224 } 222 225 return NULL; 223 226 } 227 228 G4String G4UIcommandTree::CompleteCommandPath(const G4String aCommandPath) 229 { 230 #ifdef G4DEBUG 231 printf("G4UIcommandTree::FindMatchingPath %s\n",aCommandPath.c_str()); 232 #endif 233 G4String pathName = aCommandPath; 234 G4String remainingPath = aCommandPath; 235 236 // find the tree 237 G4int jpre= pathName.last('/'); 238 if(jpre != G4int(G4String::npos)) pathName.remove(jpre+1); 239 G4UIcommandTree* aTree = FindCommandTree(pathName); 240 241 G4String empty = ""; 242 if (!aTree) { 243 return empty; 244 } 245 246 if( pathName.index( pathName ) == std::string::npos ) return empty; 247 248 #ifdef G4DEBUG 249 printf("G4UIcommandTree::FindMatchingPath remainingPath:%s\n",remainingPath.c_str()); 250 #endif 251 252 std::vector<G4String> paths; 253 254 // list matched directories/commands 255 G4String stream, strtmp; 256 G4int nMatch= 0; 257 258 int Ndir= aTree-> GetTreeEntry(); 259 int Ncmd= aTree-> GetCommandEntry(); 260 261 // directory ... 262 for(G4int idir=1; idir<=Ndir; idir++) { 263 G4String fpdir= aTree-> GetTree(idir)-> GetPathName(); 264 #ifdef G4DEBUG 265 printf("G4UIcommandTree::FindMatchingPath command %d/%d %s\n",idir,Ndir,fpdir.c_str()); 266 #endif 267 // matching test 268 if( fpdir.index(remainingPath, 0) == 0) { 269 if(nMatch==0) { 270 #ifdef G4DEBUG 271 printf("G4UIcommandTree::FindMatchingPath directory match0 :%d\n",nMatch); 272 #endif 273 stream = fpdir; 274 } else { 275 #ifdef G4DEBUG 276 printf("G4UIcommandTree::FindMatchingPath directory match+ :%d\n",nMatch); 277 #endif 278 stream = GetFirstMatchedString(fpdir,stream); 279 #ifdef G4DEBUG 280 printf("G4UIcommandTree::FindMatchingPath directory match++++ :%s\n",stream.c_str()); 281 #endif 282 } 283 nMatch++; 284 paths.push_back(fpdir); 285 } 286 } 287 288 if (paths.size()>=2) { 289 G4cout << "Matching directories :" << G4endl; 290 for( unsigned int i_thCommand = 0; i_thCommand < paths.size(); i_thCommand++ ) { 291 G4cout << paths[i_thCommand] << G4endl; 292 } 293 } 294 295 // command ... 296 std::vector<G4String> commands; 297 298 for(G4int icmd=1; icmd<=Ncmd; icmd++){ 299 G4String fpcmd= aTree-> GetPathName() + 300 aTree-> GetCommand(icmd) -> GetCommandName(); 301 // matching test 302 if( fpcmd.index(remainingPath, 0) ==0) { 303 if(nMatch==0) { 304 #ifdef G4DEBUG 305 printf("G4UIcommandTree::FindMatchingPath command match0 :%d\n",nMatch); 306 #endif 307 stream= fpcmd + " "; 308 } else { 309 #ifdef G4DEBUG 310 printf("G4UIcommandTree::FindMatchingPath command match0 :%d\n",nMatch); 311 #endif 312 strtmp= fpcmd + " "; 313 stream= GetFirstMatchedString(stream, strtmp); 314 } 315 nMatch++; 316 commands.push_back(fpcmd+" "); 317 } 318 } 319 320 if (commands.size()>=2) { 321 G4cout << "Matching commands :" << G4endl; 322 for( unsigned int i_thCommand = 0; i_thCommand < commands.size(); i_thCommand++ ) { 323 G4cout << commands[i_thCommand] << G4endl; 324 } 325 } 326 327 328 329 330 // if( remainingPath == std::string::npos ) { 331 // #ifdef G4DEBUG 332 // printf("G4UIcommandTree::FindMatchingPath npos \n"); 333 // #endif 334 // // Look for number of matching commands : 335 // G4int n_commandEntry = aTree->GetCommandEntry(); 336 // for( G4int i_thCommand = 1; i_thCommand <= n_commandEntry; i_thCommand++ ) { 337 // G4UIcommand* cmd = aTree->GetCommand(i_thCommand); 338 // G4String ss = cmd->GetCommandName(); 339 // ss.resize(remainingPath.length()); 340 // if( remainingPath == ss ) commands.push_back(cmd); 341 // #ifdef G4DEBUG 342 // printf("look for command check %s %s \n",ss.c_str(),remainingPath.c_str()); 343 // #endif 344 // } 345 // n_commandEntry = commands.size(); 346 // #ifdef G4DEBUG 347 // printf("%d found\n",n_commandEntry); 348 // #endif 349 // if(n_commandEntry==1) { 350 // return (pathName + commands[0]->GetCommandName()); 351 // } else if (n_commandEntry>=2) { 352 // G4cout << "Matching commands :" << G4endl; 353 // for( G4int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ ) { 354 // G4UIcommand* cmd = commands[i_thCommand]; 355 // G4cout << cmd->GetCommandName() << G4endl; 356 // } 357 // return empty; 358 // } 359 // // Look for sub tree : 360 // std::vector<G4UIcommandTree*> trees; 361 // G4String nextPath = pathName; 362 // nextPath.append(remainingPath); 363 // G4int n_treeEntry = aTree->GetTreeEntry(); 364 // for( G4int i_thTree = 1; i_thTree <= n_treeEntry; i_thTree++ ) { 365 // G4UIcommandTree* tree = aTree->GetTree(i_thTree); 366 // G4String ss = tree->GetPathName(); 367 // ss.resize(nextPath.length()); 368 // if( nextPath == ss ) trees.push_back(tree); 369 // } 370 // n_treeEntry = trees.size(); 371 // if(n_treeEntry==1) { 372 // return trees[0]->GetPathName(); 373 // } else if (n_treeEntry>=2) { 374 // G4cout << "Matching directories :" << G4endl; 375 // for( G4int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ ) { 376 // G4UIcommandTree* tree = trees[i_thTree]; 377 // G4cout << tree->GetPathName() << G4endl; 378 // } 379 // return empty; 380 // } else { 381 // return empty; // No match. 382 // } 383 // } else { 384 // // Find path 385 // G4String nextPath = pathName; 386 // nextPath.append(remainingPath(0,i+1)); 387 // G4int n_treeEntry = aTree->GetTreeEntry(); 388 // for( G4int i_thTree = 1; i_thTree <= n_treeEntry; i_thTree++ ) { 389 // G4UIcommandTree* tree = aTree->GetTree(i_thTree); 390 // if( nextPath == tree->GetPathName() ) { 391 // return tree->CompleteCommandPath(pathName ); 392 // } 393 // } 394 // } 395 // n_commandEntry = commands.size(); 396 return stream; 397 } 398 399 400 //////////////////////////////////////////////////////////////////// 401 G4String G4UIcommandTree::GetFirstMatchedString(const G4String& str1, 402 const G4String& str2) const 403 //////////////////////////////////////////////////////////////////// 404 { 405 int nlen1= str1.length(); 406 int nlen2= str2.length(); 407 408 int nmin = nlen1<nlen2 ? nlen1 : nlen2; 409 410 G4String strMatched; 411 for(size_t i=0; G4int(i)<nmin; i++){ 412 if(str1[i]==str2[i]) { 413 strMatched+= str1[i]; 414 } else { 415 break; 416 } 417 } 418 419 return strMatched; 420 } 421 422 423 224 424 225 425 void G4UIcommandTree::ListCurrent() -
trunk/source/interfaces/basic/src/G4VUIshell.cc
r989 r1027 149 149 ////////////////////////////////////////////////////////////////////// 150 150 { 151 printf("G4VUIshell::GetAbsCommandDirPath %s\n",apath.c_str()); 151 152 if(apath.empty()) return apath; // null string 152 153 … … 157 158 158 159 // parsing... 160 printf("G4VUIshell::GetAbsCommandDirPath bpath %s\n",bpath.c_str()); 159 161 G4String absPath= "/"; 162 printf("G4VUIshell::GetAbsCommandDirPath num %d \n",G4int(bpath.length())-1); 160 163 for(G4int indx=1; indx<=G4int(bpath.length())-1; ) { 164 printf("G4VUIshell::GetAbsCommandDirPath for %d/%d \n",indx,G4int(bpath.length())-1); 161 165 G4int jslash= bpath.index("/", indx); // search index begin with "/" 162 166 if(jslash != G4int(G4String::npos)) { … … 177 181 indx= jslash+1; 178 182 } 183 printf("G4VUIshell::GetAbsCommandDirPath RETURN %s\n",absPath.c_str()); 179 184 return absPath; 180 185 } -
trunk/source/interfaces/common/include/G4VBasicShell.hh
r989 r1027 85 85 G4String Complete(G4String); 86 86 // command completion 87 88 G4String CompleteCommand(G4String); 89 // command completion 87 90 G4String FindMatchingPath(G4UIcommandTree*,G4String); 88 91 -
trunk/source/interfaces/common/src/G4VBasicShell.cc
r921 r1027 180 180 return value; 181 181 } 182 183 184 185 182 186 G4String G4VBasicShell::FindMatchingPath( 183 187 G4UIcommandTree* aTree … … 186 190 // From intercoms/src/G4UIcommandTree::FindPath. 187 191 { 192 return aTree->CompleteCommandPath(aCommandPath); 193 188 194 #ifdef G4DEBUG 189 195 printf("G4VBasicShell::FindMatchingPath %s\n",aCommandPath.c_str()); … … 226 232 G4UIcommand* cmd = commands[i_thCommand]; 227 233 G4cout << cmd->GetCommandName() << G4endl; 234 #ifdef G4DEBUG 235 printf("%s found\n",cmd->GetCommandName().c_str()); 236 #endif 228 237 } 229 238 return empty; … … 258 267 nextPath.append(remainingPath(0,i+1)); 259 268 G4int n_treeEntry = aTree->GetTreeEntry(); 269 #ifdef G4DEBUG 270 printf(" find PATH\n"); 271 #endif 260 272 for( G4int i_thTree = 1; i_thTree <= n_treeEntry; i_thTree++ ) { 261 273 G4UIcommandTree* tree = aTree->GetTree(i_thTree); 274 #ifdef G4DEBUG 275 printf("++++LOOP+++++++++++++%s == %s \n",nextPath.c_str(), tree->GetPathName().c_str()); 276 #endif 262 277 if( nextPath == tree->GetPathName() ) { 263 278 return FindMatchingPath(tree,aCommandPath );
Note: See TracChangeset
for help on using the changeset viewer.