Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

FileScanner Class Reference

This scans a path and looks for CMT packages. More...

List of all members.

Public Methods

 FileScanner ()
bool scan_path (const cmt_string& path, actor& a)
bool scan_package (const cmt_string& path, const cmt_string& package)

Private Methods

void scan_path (const cmt_string& path, int level, actor& a)

Private Attributes

bool _running
int _level


Detailed Description

This scans a path and looks for CMT packages.

Whenever it finds one, it applies the specified actor to it.

Definition at line 84 of file cmt_parser.cxx.


Constructor & Destructor Documentation

FileScanner::FileScanner ( )
 

Definition at line 158 of file cmt_parser.cxx.

00159 {
00160   _running = false;
00161   _level = 0;
00162 }


Member Function Documentation

bool FileScanner::scan_package ( const cmt_string & path,
const cmt_string & package )
 

Definition at line 284 of file cmt_parser.cxx.

Referenced by Cmt::do_show_versions().

00286 {
00287   //
00288   // Only do something if it is a directory.
00289   //
00290 
00291   if (!CmtSystem::test_directory (path)) return (false);
00292 
00293   cmt_string pattern = path;
00294   pattern += CmtSystem::file_separator ();
00295   pattern += package;
00296 
00297   if (!CmtSystem::test_directory (pattern)) return (false);
00298 
00299   CmtSystem::cmt_string_vector list;
00300 
00301   CmtSystem::scan_dir (pattern, list);
00302 
00303   if (list.size () == 0) return (false);
00304 
00305   bool result = false;
00306 
00307   int i;
00308   for (i = 0; i < list.size (); i++)
00309     {
00310       const cmt_string& name = list[i];
00311 
00312       cmt_string version;
00313       CmtSystem::basename (name, version);
00314 
00315       if (CmtSystem::is_version_directory (version))
00316         {
00317           cmt_string req;
00318 
00319           req = name;
00320           req += CmtSystem::file_separator ();
00321           req += "cmt";
00322           req += CmtSystem::file_separator ();
00323           req += "requirements";
00324 
00325           if (CmtSystem::test_file (req))
00326             {
00327               //cout << " -> cmt" << endl;
00328 
00329               cout << package << " " << version << " " << path << endl;
00330 
00331               result = true;
00332             }
00333           else
00334             {
00335               //cout << " -> no cmt" << endl;
00336 
00337               req = name;
00338               req += CmtSystem::file_separator ();
00339               req += "mgr";
00340               req += CmtSystem::file_separator ();
00341               req += "requirements";
00342 
00343               if (CmtSystem::test_file (req))
00344                 {
00345                   //cout << " -> mgr" << endl;
00346 
00347                   cout << package << " " << version << " " << path << endl;
00348 
00349                   result = true;
00350                 }
00351               else
00352                 {
00353                   //cout << " -> no mgr" << endl;
00354                 }
00355             }
00356         }
00357       else
00358         {
00359           //cout << " -> stop" << endl;
00360         }
00361     }
00362 
00363   return (result);
00364 }

void FileScanner::scan_path ( const cmt_string & path,
int level,
actor & a ) [private]
 

Definition at line 179 of file cmt_parser.cxx.

00180 {
00181   //
00182   // Only do something if it is a directory.
00183   //
00184 
00185   if (!CmtSystem::test_directory (path)) return;
00186 
00187   CmtSystem::cmt_string_vector list;
00188 
00189   CmtSystem::scan_dir (path, list);
00190 
00191   if (list.size () == 0) return;
00192 
00193   _level++;
00194 
00195   // Will be set if at least one directory is a version directory
00196   bool has_package = false;
00197 
00198   cmt_string pack;
00199   CmtSystem::basename (path, pack);
00200 
00201   int i;
00202   for (i = 0; i < list.size (); i++)
00203     {
00204       const cmt_string& name = list[i];
00205 
00206       //cout << "scan> level=" << level << " name=" << name;
00207 
00208       cmt_string version;
00209       CmtSystem::basename (name, version);
00210 
00211       //
00212       //  All entries at this level may be "legal" version directories.
00213       //
00214       //  So we go down but no more then one level deep.
00215       //  The next level we request that the entry is a version
00216       //  and that there is a mgr/requirements file below.
00217       //
00218 
00219       if (level == 0)
00220         {
00221           //cout << " -> down" << endl;
00222           scan_path (name, level + 1, a);
00223         }
00224       else if (CmtSystem::is_version_directory (version))
00225         {
00226           cmt_string req;
00227 
00228           req = name;
00229           req += CmtSystem::file_separator ();
00230           req += "cmt";
00231           req += CmtSystem::file_separator ();
00232           req += "requirements";
00233 
00234           if (CmtSystem::test_file (req))
00235             {
00236               //cout << " -> cmt" << endl;
00237 
00238               a.run (pack, version, path);
00239 
00240               has_package = true;
00241             }
00242           else
00243             {
00244               //cout << " -> no cmt" << endl;
00245               req = name;
00246               req += CmtSystem::file_separator ();
00247               req += "mgr";
00248               req += CmtSystem::file_separator ();
00249               req += "requirements";
00250 
00251               if (CmtSystem::test_file (req))
00252                 {
00253                   //cout << " -> cmt" << endl;
00254 
00255                   a.run (pack, version, path);
00256 
00257                   has_package = true;
00258                 }
00259               else
00260                 {
00261                   //cout << " -> no mgr" << endl;
00262                 }
00263             }
00264         }
00265       else
00266         {
00267           //cout << " -> stop" << endl;
00268         }
00269     }
00270 
00271   if (has_package)
00272     {
00273       //
00274       // At least one version was found here.
00275       //
00276       scan_path (path, 0, a);
00277     }
00278 
00279   _level--;
00280 }

bool FileScanner::scan_path ( const cmt_string & path,
actor & a )
 

Definition at line 165 of file cmt_parser.cxx.

Referenced by Cmt::do_broadcast(), Cmt::do_show_clients(), Cmt::do_show_packages(), and scan_path().

00166 {
00167   if (_running) return (false);
00168 
00169   _level = 0;
00170   _running = true;
00171   scan_path (path, 0, a);
00172   _running = false;
00173   _level = 0;
00174 
00175   return (true);
00176 }


Member Data Documentation

int FileScanner::_level [private]
 

Definition at line 105 of file cmt_parser.cxx.

bool FileScanner::_running [private]
 

Definition at line 104 of file cmt_parser.cxx.


The documentation for this class was generated from the following file:
Generated at Thu Apr 11 16:50:42 2002 for CMT by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000