Changeset 1027 for trunk


Ignore:
Timestamp:
May 5, 2009, 5:45:31 PM (15 years ago)
Author:
garnier
Message:

en test. Ok

Location:
trunk/source
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/intercoms/include/G4UIcommandTree.hh

    r1016 r1027  
    5757      G4UIcommand * FindPath(const char* commandPath);
    5858      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
    5963      void List();
    6064      void ListCurrent();
     
    6569      G4String CreateFileName(const char* pName);
    6670      G4String ModStr(const char* strS);
     71  G4String GetFirstMatchedString(const G4String&,const G4String&) const;
    6772
    6873      std::vector<G4UIcommand*> command;
  • trunk/source/intercoms/src/G4UIcommandTree.cc

    r1016 r1027  
    199199G4UIcommandTree * G4UIcommandTree::FindCommandTree(const char* commandPath)
    200200{
     201  printf("G4UIcommandTree::FindCommandTree %s\n",commandPath);
    201202  G4String remainingPath = commandPath;
    202203  if( remainingPath.index( pathName ) == std::string::npos )
     
    219220      }
    220221    }
     222  } else {
     223    return this;
    221224  }
    222225  return NULL;
    223226}
     227
     228G4String 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////////////////////////////////////////////////////////////////////
     401G4String 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
    224424
    225425void G4UIcommandTree::ListCurrent()
  • trunk/source/interfaces/basic/src/G4VUIshell.cc

    r989 r1027  
    149149//////////////////////////////////////////////////////////////////////
    150150{
     151  printf("G4VUIshell::GetAbsCommandDirPath %s\n",apath.c_str());
    151152  if(apath.empty()) return apath;  // null string
    152153
     
    157158
    158159  // parsing...
     160  printf("G4VUIshell::GetAbsCommandDirPath bpath %s\n",bpath.c_str());
    159161  G4String absPath= "/";
     162  printf("G4VUIshell::GetAbsCommandDirPath num %d \n",G4int(bpath.length())-1);
    160163  for(G4int indx=1; indx<=G4int(bpath.length())-1; ) {
     164    printf("G4VUIshell::GetAbsCommandDirPath for %d/%d \n",indx,G4int(bpath.length())-1);
    161165    G4int jslash= bpath.index("/", indx);  // search index begin with "/"
    162166    if(jslash != G4int(G4String::npos)) {
     
    177181    indx= jslash+1;
    178182  }
     183  printf("G4VUIshell::GetAbsCommandDirPath RETURN %s\n",absPath.c_str());
    179184  return  absPath;
    180185}
  • trunk/source/interfaces/common/include/G4VBasicShell.hh

    r989 r1027  
    8585    G4String Complete(G4String);
    8686    // command completion
     87
     88    G4String CompleteCommand(G4String);
     89    // command completion
    8790    G4String FindMatchingPath(G4UIcommandTree*,G4String);
    8891
  • trunk/source/interfaces/common/src/G4VBasicShell.cc

    r921 r1027  
    180180  return value;
    181181}
     182
     183
     184
     185
    182186G4String G4VBasicShell::FindMatchingPath(
    183187 G4UIcommandTree* aTree
     
    186190// From intercoms/src/G4UIcommandTree::FindPath.
    187191{
     192  return aTree->CompleteCommandPath(aCommandPath);
     193
    188194#ifdef G4DEBUG
    189195  printf("G4VBasicShell::FindMatchingPath %s\n",aCommandPath.c_str());
     
    226232        G4UIcommand* cmd = commands[i_thCommand];
    227233        G4cout << cmd->GetCommandName() << G4endl;
     234#ifdef G4DEBUG
     235        printf("%s found\n",cmd->GetCommandName().c_str());
     236#endif
    228237      }
    229238      return empty;
     
    258267    nextPath.append(remainingPath(0,i+1));
    259268    G4int n_treeEntry = aTree->GetTreeEntry();
     269#ifdef G4DEBUG
     270    printf(" find PATH\n");
     271#endif
    260272    for( G4int i_thTree = 1; i_thTree <= n_treeEntry; i_thTree++ ) {
    261273      G4UIcommandTree* tree = aTree->GetTree(i_thTree);
     274#ifdef G4DEBUG
     275      printf("++++LOOP+++++++++++++%s == %s \n",nextPath.c_str(), tree->GetPathName().c_str());
     276#endif
    262277      if( nextPath == tree->GetPathName() ) {
    263278        return FindMatchingPath(tree,aCommandPath );
Note: See TracChangeset for help on using the changeset viewer.