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

cmtshowclients.cxx

Go to the documentation of this file.
00001 
00002 #include "Package.h"
00003 #include "tree_node.h"
00004 #include "dot.h"
00005 
00010 class FileScanner
00011 {
00012 public:
00013   class actor
00014   {
00015 public:
00016     virtual ~actor ()
00017         {
00018         }
00019 
00020     virtual void run (const cmt_string& /*package*/,
00021                       const cmt_string& /*version*/,
00022                       const cmt_string& /*path*/)
00023         {
00024         }
00025   };
00026 
00027   FileScanner ();
00028   bool scan_path (const cmt_string& path, actor& a);
00029 
00030 private:
00031   void scan_path (const cmt_string& path, int level, actor& a);
00032 
00033   bool _running;
00034   int _level;
00035 };
00036 
00037 
00038 //----------------------------------------------------------
00039 FileScanner::FileScanner ()
00040 //----------------------------------------------------------
00041 {
00042   _running = false;
00043   _level = 0;
00044 }
00045 
00046 //----------------------------------------------------------
00047 bool FileScanner::scan_path (const cmt_string& path, actor& a)
00048 //----------------------------------------------------------
00049 {
00050   if (_running) return (false);
00051 
00052   _level = 0;
00053   _running = true;
00054   scan_path (path, 0, a);
00055   _running = false;
00056   _level = 0;
00057 
00058   return (true);
00059 }
00060 
00061 //----------------------------------------------------------
00062 void FileScanner::scan_path (const cmt_string& path, int level, actor& a)
00063 //----------------------------------------------------------
00064 {
00065     //
00066     // Only do something if it is a directory.
00067     //
00068 
00069   if (!CmtSystem::test_directory (path)) return;
00070 
00071   CmtSystem::cmt_string_vector list;
00072 
00073   CmtSystem::scan_dir (path, list);
00074 
00075   if (list.size () == 0) return;
00076 
00077   _level++;
00078 
00079     // Will be set if at least one directory is a version directory
00080   bool has_package = false;
00081 
00082   cmt_string pack;
00083   CmtSystem::basename (path, pack);
00084 
00085   int i;
00086   for (i = 0; i < list.size (); i++)
00087     {
00088       const cmt_string& name = list[i];
00089 
00090         //cout << "scan> level=" << level << " name=" << name;
00091 
00092       cmt_string version;
00093       CmtSystem::basename (name, version);
00094 
00095         //
00096         //  All entries at this level may be "legal" version directories.
00097         //
00098         //  So we go down but no more then one level deep.
00099         //  The next level we request that the entry is a version
00100         //  and that there is a mgr/requirements file below.
00101         //
00102 
00103       if (level == 0)
00104         {
00105             //cout << " -> down" << endl;
00106           scan_path (name, level + 1, a);
00107         }
00108       else if (CmtSystem::is_version_directory (version))
00109         {
00110           cmt_string req;
00111 
00112           req = name;
00113           req += CmtSystem::file_separator ();
00114           req += "cmt";
00115           req += CmtSystem::file_separator ();
00116           req += "requirements";
00117 
00118           if (CmtSystem::test_file (req))
00119             {
00120                 //cout << " -> cmt" << endl;
00121 
00122               a.run (pack, version, path);
00123 
00124               has_package = true;
00125             }
00126           else
00127             {
00128                 //cout << " -> no cmt" << endl;
00129               req = name;
00130               req += CmtSystem::file_separator ();
00131               req += "mgr";
00132               req += CmtSystem::file_separator ();
00133               req += "requirements";
00134 
00135               if (CmtSystem::test_file (req))
00136                 {
00137                     //cout << " -> cmt" << endl;
00138 
00139                   a.run (pack, version, path);
00140 
00141                   has_package = true;
00142                 }
00143               else
00144                 {
00145                     //cout << " -> no mgr" << endl;
00146                 }
00147             }
00148         }
00149       else
00150         {
00151             //cout << " -> stop" << endl;
00152         }
00153     }
00154 
00155   if (has_package)
00156     {
00157         //
00158         // At least one version was found here.
00159         //
00160       scan_path (path, 0, a);
00161     }
00162 
00163   _level--;
00164 }
00165 
00166 
00170 class PackageViewer : public FileScanner::actor
00171 {
00172 public:
00173   void run (const cmt_string& package,
00174             const cmt_string& version,
00175             const cmt_string& path)
00176       {
00177         cmt_string null;
00178         cmt_string offset = path;
00179 
00180         offset.replace (path_prefix, null);
00181         offset.replace (CmtSystem::file_separator (), null);
00182         offset.replace (package, null);
00183         
00184         if (CmtSystem::file_separator () == '\\')
00185           {
00186             offset.replace_all (CmtSystem::file_separator (), '/');
00187           }
00188         
00189         int pos = offset.find_last_of ('/');
00190         if (pos == (offset.size () - 1)) offset.erase (pos);
00191         
00192           //cout << package << " " << version << " " << offset << " " << path_prefix << endl;
00193         Package::create (package, version, offset, path_prefix);
00194       }
00195   
00196   void set_path (const cmt_string& path)
00197       {
00198         path_prefix = path;
00199       }
00200   
00201 private:
00202   cmt_string path_prefix;
00203 };
00204 
00205 int main (int argc, char* argv[])
00206 {
00207   if (argc < 3) return (1);
00208 
00209   cmt_string p;
00210   p = argv[1];
00211   cmt_string v;
00212   v = argv[2];
00213   cmt_string pp;
00214   if (argc >= 3) pp = argv[3];
00215 
00216   Package& top_package = Package::create (p, v, pp);
00217   tree_node top_node (0, &top_package);
00218 
00219   cmt_string cmt_version;
00220   CmtSystem::get_cmt_version (cmt_version);
00221   Package::create ("CMT", cmt_version, "");
00222 
00226   FileScanner scanner;
00227   PackageViewer viewer;
00228 
00229   CmtSystem::cmt_string_vector paths;
00230   CmtSystem::cmt_string_vector path_pwds;
00231   CmtSystem::cmt_string_vector path_sources;
00232 
00233   CmtSystem::get_cmt_paths (paths, path_pwds, path_sources);
00234 
00235   for (int path_index = 0; path_index < paths.size (); path_index++)
00236     {
00237       const cmt_string& path = paths[path_index];
00238       viewer.set_path (path);
00239       scanner.scan_path (path, viewer);
00240     }
00241 
00246   top_package.collect_clients (top_node);
00247 
00251   DotGenerator generator;
00252 
00253   generator.run (top_node, "back");
00254 
00255   return (0);
00256 }

Generated at Fri Apr 12 16:18:11 2002 for cmtgrapher by 1.2.3 written by , ??1997-2000