Logo Search packages:      
Sourcecode: packagesearch version File versions

bool NApt::AptPackages::search ( Tagcoll::OpSet< int > &  result,
Tagcoll::HandleMaker< string > &  handleMaker,
const string &  pattern,
bool  searchDescr = true 
)

Searches for the given pattern in the package database.

Parameters:
result the set where the search result should be inserted. The names of the matching packages will be added to result.
handleMaker the handle maker to be used for this search - it maps the strings to the integer values.
pattern the patterns to be searched. The compare happens case insensitive.
searchDescr defines if the description should be searched too, else only the names will be serached
Returns:
if at least one package was found.

Definition at line 80 of file aptpackages.cpp.

References NApt::AptPackages::ExVerFile::NameMatch, and NApt::AptPackages::ExVerFile::Vf.

{
// the code of this function is mainly taken from apt-cache - the search section. I do not really understand
// it so it might not do what it should all the time.
// WARNING: this code does not conform with package search naming scheme as it was mostly copied 
// from apt-cache, so do not be confused by this.
      assert(_pGCache);
      pkgCache &Cache = *_pGCache;
      
      pkgDepCache::Policy Plcy;
      
      // Create the text record parser
      pkgRecords Recs(Cache);
      if (_error->PendingError() == true)
      {
            return false;
      }
      
      ExVerFile *VFList = new ExVerFile[Cache.HeaderP->PackageCount+1];
   memset(VFList,0,sizeof(*VFList)*Cache.HeaderP->PackageCount+1);      // set all pointer to be 0
      
      // Map versions that we want to write out onto the VerList array.
      for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++)
      {
            if ( QString(P.Name()).contains(pattern.c_str(),false) )
            {
                  VFList[P->ID].NameMatch = true;
            }
            // Doing names only, drop any that dont match..
            if ( !searchDescr == true && VFList[P->ID].NameMatch == false)
                  continue;
            // Find the proper version to use. 
            pkgCache::VerIterator V = Plcy.GetCandidateVer(P);
            if (V.end() == false)
                  VFList[P->ID].Vf = V.FileList();
      }
            
      // Include all the packages that _provide_ matching names too
      for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++)
      {
            if (VFList[P->ID].NameMatch == false)
                        continue;
            for (pkgCache::PrvIterator Prv = P.ProvidesList() ; Prv.end() == false; Prv++)
            {
                  pkgCache::VerIterator V = Plcy.GetCandidateVer(Prv.OwnerPkg());
                  if (V.end() == false)
                  {
                        VFList[Prv.OwnerPkg()->ID].Vf = V.FileList();
                        VFList[Prv.OwnerPkg()->ID].NameMatch = true;
                  }
            }
      }
      // I do not really understand this -> I guess it sorty the packages according to their Vf member,
      // important is that members with Vf==0 are moved to the end of the array
   LocalitySort(&VFList->Vf, Cache.HeaderP->PackageCount, sizeof(*VFList));   // BM sort using quicksort

      // Iterate over all the version records and check them
      for (ExVerFile *J = VFList; J->Vf != 0; J++)
      {
            pkgRecords::Parser &P = Recs.Lookup(pkgCache::VerFileIterator(Cache,J->Vf));
            bool match = true;      
            if (J->NameMatch == false)
            {
                  string LongDesc = P.LongDesc();
                  if ( QString(LongDesc.c_str()).contains(pattern.c_str(),false) )
                        match = true;
                  else
                        match = false;
            }
            if (match)  // if the package matched the apt search
            {
                  result.insert( handleMaker.getHandle( P.Name() ) );
            }
      }
      
      delete [] VFList;
      return result.empty();
}


Generated by  Doxygen 1.6.0   Back to index