source: CMT/v1r19/Visual/cvsmove.cxx @ 1

Last change on this file since 1 was 1, checked in by arnault, 19 years ago

Import all tags

File size: 2.6 KB
Line 
1
2#include "cmt_std.h"
3#include "cmt_system.h"
4
5//----------------------------------------------------------
6class FileScanner
7{
8public:
9  class actor
10  {
11  public:
12    virtual void run ()
13    {
14    }
15  };
16
17  FileScanner (const cmt_string& new_root);
18  bool scan (actor& a);
19
20private:
21  void scan (int level, actor& a);
22
23  cmt_string _root;
24};
25//----------------------------------------------------------
26
27//----------------------------------------------------------
28FileScanner::FileScanner (const cmt_string& new_root) : _root(new_root)
29  //----------------------------------------------------------
30{
31}
32
33//----------------------------------------------------------
34bool FileScanner::scan (actor& a)
35//----------------------------------------------------------
36{
37  scan (0, a);
38
39  return (true);
40}
41
42//----------------------------------------------------------
43void FileScanner::scan (int level, actor& a)
44//----------------------------------------------------------
45{
46  CmtSystem::cmt_string_vector list;
47
48  CmtSystem::scan_dir ("*", list);
49
50  if (list.size () == 0) return;
51
52  // Will be set if at least one directory is a version directory
53  bool has_cvs = false;
54
55  if (CmtSystem::test_directory ("CVS")) has_cvs = true;
56
57  if (!has_cvs) return;
58
59  cmt_string cvs_root;
60  cmt_string cvs_repository;
61
62  cvs_root.read ("CVS/Root");
63  cvs_repository.read ("CVS/Repository");
64
65  int pos;
66
67  if (cvs_root[0] == ':')
68  {
69          pos = cvs_root.find_last_of (":");
70          if (pos != cmt_string::npos)
71          {
72                  cvs_root.erase (0, pos);
73          }
74  }
75
76  pos = cvs_repository.find (cvs_root);
77  if (pos == 0)
78  {
79          cvs_repository.replace (cvs_root, _root);
80  }
81 
82  if (_root.write ("CVS/Root"))
83  {
84          cout << "CVS root changed from " << cvs_root << " to " << _root << endl;
85  }
86  else
87  {
88          cout << "cannot change CVS root in " << CmtSystem::pwd () << endl;
89  }
90
91  if (cvs_repository.write ("CVS/Repository"))
92  {
93          cout << "CVS repository changed from " << cvs_root << " to " << _root << endl;
94  }
95  else
96  {
97          cout << "cannot change CVS repository in " << CmtSystem::pwd () << endl;
98  }
99
100  int i;
101  for (i = 0; i < list.size (); i++)
102    {
103      cmt_string& name = list[i];
104
105          if (name[0] == CmtSystem::file_separator ()) name.erase (0, 1);
106
107          if (CmtSystem::test_directory (name))
108          {
109                  CmtSystem::cd (name);
110                  scan (level + 1, a);
111                  CmtSystem::cd ("..");
112          }
113    }
114}
115
116int main (int argc, char* argv[])
117{
118        FileScanner scanner ("/cvs");
119        FileScanner::actor actor;
120       
121        CmtSystem::cd ("..");
122        scanner.scan (actor);
123
124        return (0);
125}
Note: See TracBrowser for help on using the repository browser.