1 | //----------------------------------------------------------- |
---|
2 | // Copyright Christian Arnault LAL-Orsay CNRS |
---|
3 | // arnault@lal.in2p3.fr |
---|
4 | // See the complete license in cmt_license.txt "http://www.cecill.info". |
---|
5 | //----------------------------------------------------------- |
---|
6 | |
---|
7 | #ifndef __cmt_system_h__ |
---|
8 | #define __cmt_system_h__ |
---|
9 | |
---|
10 | #include "cmt_std.h" |
---|
11 | #include "cmt_string.h" |
---|
12 | #include "cmt_vector.h" |
---|
13 | #include "cmt_regexp.h" |
---|
14 | |
---|
15 | class Project; |
---|
16 | |
---|
17 | class IProjectFactory |
---|
18 | { |
---|
19 | public: |
---|
20 | virtual void reset () = 0; |
---|
21 | virtual Project* create_project (const cmt_string& name, |
---|
22 | const cmt_string& path, |
---|
23 | const cmt_string& path_source, |
---|
24 | Project* parent) = 0; |
---|
25 | }; |
---|
26 | |
---|
27 | class CmtSystem |
---|
28 | { |
---|
29 | public: |
---|
30 | typedef cmt_vector<cmt_string> cmt_string_vector; |
---|
31 | |
---|
32 | static cmt_string pwd (); |
---|
33 | static bool cd (const cmt_string& dir); |
---|
34 | |
---|
35 | static void basename (const cmt_string& file_name, cmt_string& result); |
---|
36 | static void basename (const cmt_string& file_name, |
---|
37 | const cmt_string& suffix, |
---|
38 | cmt_string& result); |
---|
39 | |
---|
40 | // Resolve symbolic links in a path. |
---|
41 | static bool realpath (const cmt_string& path, cmt_string& result); |
---|
42 | // Currently the above does not resolve symbolic links in a path. |
---|
43 | static bool realpath_ (const cmt_string& path, cmt_string& result); |
---|
44 | |
---|
45 | static void dirname (const cmt_string& file_name, cmt_string& result); |
---|
46 | |
---|
47 | static void name (const cmt_string& file, cmt_string& result); |
---|
48 | |
---|
49 | static void get_suffix (const cmt_string& file, cmt_string& result); |
---|
50 | static void get_dot_suffix (const cmt_string& file, cmt_string& result); |
---|
51 | static bool has_prefix (const cmt_string& name); |
---|
52 | static bool absolute_path (const cmt_string& name); |
---|
53 | static bool has_device (const cmt_string& name); |
---|
54 | |
---|
55 | static cmt_string current_branch (); |
---|
56 | |
---|
57 | /** |
---|
58 | * Implementation of the "test -d" equivalent |
---|
59 | */ |
---|
60 | static bool test_directory (const cmt_string& name); |
---|
61 | /** |
---|
62 | * Implementation of the "test -f" equivalent |
---|
63 | */ |
---|
64 | static bool test_file (const cmt_string& name); |
---|
65 | /** |
---|
66 | * Implementation of the "touch" function equivalent |
---|
67 | */ |
---|
68 | static bool touch_file (const cmt_string& name); |
---|
69 | /** |
---|
70 | * Check if the file "name1" is identical to "name2" |
---|
71 | */ |
---|
72 | static bool compare_files (const cmt_string& name1, |
---|
73 | const cmt_string& name2); |
---|
74 | /** |
---|
75 | * Check if the file "name1" is identical to "name2" |
---|
76 | * if they are identical, "name1" will be simply deleted |
---|
77 | * otherwise "name1" will be copied to "name2" and deleted afterwards |
---|
78 | */ |
---|
79 | static bool compare_and_update_files (const cmt_string& name1, |
---|
80 | const cmt_string& name2); |
---|
81 | static int file_size (const cmt_string& name); |
---|
82 | static char file_separator (); |
---|
83 | static void reduce_file_separators (cmt_string& text); |
---|
84 | static char path_separator (); |
---|
85 | static char command_separator (); |
---|
86 | static const cmt_string& ev_open (); |
---|
87 | static const cmt_string& ev_close (); |
---|
88 | static bool create_symlink (const cmt_string& oldname, |
---|
89 | const cmt_string& newname); |
---|
90 | static bool remove_file (const cmt_string& name); |
---|
91 | static bool remove_directory (const cmt_string& name); |
---|
92 | static bool mkdir (const cmt_string& name); |
---|
93 | static void scan_dir (const cmt_string& dir_name, |
---|
94 | cmt_string_vector& list); |
---|
95 | static void scan_dir (const cmt_string& dir_name, |
---|
96 | const cmt_regexp& expression, |
---|
97 | cmt_string_vector& list); |
---|
98 | static cmt_string_vector& scan_dir (const cmt_string& dir_name); |
---|
99 | static const cmt_string& get_cmt_root (); |
---|
100 | static void get_cmt_version (cmt_string& version); |
---|
101 | static cmt_string get_cmt_config (); |
---|
102 | static cmt_string get_cmt_site (); |
---|
103 | static void get_uname (cmt_string& uname); |
---|
104 | static void get_hosttype (cmt_string& hosttype); |
---|
105 | static cmt_string get_temporary_name (); |
---|
106 | |
---|
107 | static cmt_string get_home_package (); |
---|
108 | static bool is_home_package (const cmt_string& name, |
---|
109 | const cmt_string& version); |
---|
110 | |
---|
111 | static cmt_string get_user_context_package (); |
---|
112 | static bool is_user_context_package (const cmt_string& name, |
---|
113 | const cmt_string& version); |
---|
114 | |
---|
115 | static cmt_string get_project_package (); |
---|
116 | static bool is_project_package (const cmt_string& name, |
---|
117 | const cmt_string& version); |
---|
118 | |
---|
119 | static bool testenv (const cmt_string& name); |
---|
120 | static cmt_string getenv (const cmt_string& name); |
---|
121 | static bool putenv (const cmt_string& name, const cmt_string& value); |
---|
122 | static void get_cmt_paths (IProjectFactory& factory, |
---|
123 | const cmt_string& init_text, |
---|
124 | const cmt_string& cmt_user_context, |
---|
125 | const cmt_string& cmt_home); |
---|
126 | static int execute (const cmt_string& command); |
---|
127 | static int execute (const cmt_string& command, cmt_string& output); |
---|
128 | static bool is_package_directory (const cmt_string& name); |
---|
129 | static bool is_version_directory (const cmt_string& name); |
---|
130 | static bool is_version_directory (const cmt_string& name, int& v, int& r, int& p); |
---|
131 | static void split (const cmt_string& text, |
---|
132 | const cmt_string& separators, |
---|
133 | cmt_string_vector& strings); |
---|
134 | static cmt_string quote (const cmt_string& text, |
---|
135 | const cmt_string& separators); |
---|
136 | static int mangle (const cmt_string& text, cmt_string& out); |
---|
137 | static cmt_string mangle (const cmt_string& text); |
---|
138 | |
---|
139 | static void compress_path (const cmt_string& dir, cmt_string& new_dir); |
---|
140 | static void compress_path (cmt_string& dir); |
---|
141 | |
---|
142 | static cmt_string now (); |
---|
143 | static cmt_string user (); |
---|
144 | |
---|
145 | static void get_cvsroot (cmt_string& cvsroot); |
---|
146 | |
---|
147 | static bool get_home_directory (cmt_string& dir); |
---|
148 | |
---|
149 | static cmt_string get_makefile_suffix (); |
---|
150 | |
---|
151 | static void close_ostream (FILE *stream, const cmt_string& name = "" ); |
---|
152 | static void close_stdout (void); |
---|
153 | |
---|
154 | }; |
---|
155 | |
---|
156 | class FilePath |
---|
157 | { |
---|
158 | public: |
---|
159 | |
---|
160 | FilePath (); |
---|
161 | |
---|
162 | FilePath (const FilePath& other); |
---|
163 | FilePath (const cmt_string& other); |
---|
164 | FilePath (const char* other); |
---|
165 | |
---|
166 | FilePath& operator = (const FilePath& other); |
---|
167 | FilePath& operator = (const cmt_string& other); |
---|
168 | FilePath& operator = (const char* other); |
---|
169 | |
---|
170 | bool operator == (const FilePath& other) const; |
---|
171 | bool operator == (const cmt_string& other) const; |
---|
172 | bool operator == (const char* other) const; |
---|
173 | |
---|
174 | bool operator != (const FilePath& other) const; |
---|
175 | bool operator != (const cmt_string& other) const; |
---|
176 | bool operator != (const char* other) const; |
---|
177 | |
---|
178 | const cmt_string& name () const; |
---|
179 | operator const cmt_string& () const; |
---|
180 | |
---|
181 | bool in (const FilePath& other) const; |
---|
182 | bool in (const cmt_string& other) const; |
---|
183 | bool in (const char* other) const; |
---|
184 | |
---|
185 | bool cd () const; |
---|
186 | |
---|
187 | private: |
---|
188 | |
---|
189 | void set (const FilePath& other); |
---|
190 | void set (const cmt_string& other); |
---|
191 | void set (const char* other); |
---|
192 | |
---|
193 | cmt_string p_name; // physical name |
---|
194 | cmt_string l_name; // first logical name |
---|
195 | |
---|
196 | CmtSystem::cmt_string_vector alternates; // other logical names |
---|
197 | }; |
---|
198 | |
---|
199 | |
---|
200 | #endif |
---|