[2] | 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 | |
---|
[9] | 15 | class Project; |
---|
| 16 | |
---|
[2] | 17 | class IProjectFactory |
---|
| 18 | { |
---|
| 19 | public: |
---|
| 20 | virtual void reset () = 0; |
---|
[18] | 21 | virtual Project* create_project (const cmt_string& name, |
---|
| 22 | const cmt_string& path, |
---|
[9] | 23 | const cmt_string& path_source, |
---|
| 24 | Project* parent) = 0; |
---|
[2] | 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 | |
---|
[193] | 40 | // Resolve symbolic links in a path. |
---|
[197] | 41 | static bool realpath (const cmt_string& path, cmt_string& result); |
---|
[435] | 42 | // Currently the above does not resolve symbolic links in a path. |
---|
| 43 | static bool realpath_ (const cmt_string& path, cmt_string& result); |
---|
[193] | 44 | |
---|
[2] | 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 |
---|
[201] | 63 | */ |
---|
[2] | 64 | static bool test_file (const cmt_string& name); |
---|
| 65 | /** |
---|
[201] | 66 | * Implementation of the "touch" function equivalent |
---|
| 67 | */ |
---|
| 68 | static bool touch_file (const cmt_string& name); |
---|
| 69 | /** |
---|
[2] | 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); |
---|
[599] | 82 | inline static char file_separator () |
---|
| 83 | { |
---|
| 84 | #ifdef WIN32 |
---|
| 85 | return ('\\'); |
---|
| 86 | #else |
---|
| 87 | return ('/'); |
---|
| 88 | #endif |
---|
| 89 | } |
---|
[2] | 90 | static void reduce_file_separators (cmt_string& text); |
---|
[599] | 91 | inline static char path_separator () |
---|
| 92 | { |
---|
| 93 | #ifdef WIN32 |
---|
| 94 | return (';'); |
---|
| 95 | #else |
---|
| 96 | return (':'); |
---|
| 97 | #endif |
---|
| 98 | } |
---|
| 99 | inline static char command_separator () |
---|
| 100 | { |
---|
| 101 | #ifdef WIN32 |
---|
| 102 | return ('&'); |
---|
| 103 | #else |
---|
| 104 | return (';'); |
---|
| 105 | #endif |
---|
| 106 | } |
---|
| 107 | //static const char* cwd_variable (); |
---|
[2] | 108 | static const cmt_string& ev_open (); |
---|
| 109 | static const cmt_string& ev_close (); |
---|
| 110 | static bool create_symlink (const cmt_string& oldname, |
---|
| 111 | const cmt_string& newname); |
---|
| 112 | static bool remove_file (const cmt_string& name); |
---|
| 113 | static bool remove_directory (const cmt_string& name); |
---|
| 114 | static bool mkdir (const cmt_string& name); |
---|
| 115 | static void scan_dir (const cmt_string& dir_name, |
---|
| 116 | cmt_string_vector& list); |
---|
| 117 | static void scan_dir (const cmt_string& dir_name, |
---|
| 118 | const cmt_regexp& expression, |
---|
| 119 | cmt_string_vector& list); |
---|
| 120 | static cmt_string_vector& scan_dir (const cmt_string& dir_name); |
---|
| 121 | static const cmt_string& get_cmt_root (); |
---|
| 122 | static void get_cmt_version (cmt_string& version); |
---|
| 123 | static cmt_string get_cmt_config (); |
---|
| 124 | static cmt_string get_cmt_site (); |
---|
| 125 | static void get_uname (cmt_string& uname); |
---|
| 126 | static void get_hosttype (cmt_string& hosttype); |
---|
| 127 | static cmt_string get_temporary_name (); |
---|
| 128 | |
---|
| 129 | static cmt_string get_home_package (); |
---|
| 130 | static bool is_home_package (const cmt_string& name, |
---|
| 131 | const cmt_string& version); |
---|
| 132 | |
---|
| 133 | static cmt_string get_user_context_package (); |
---|
| 134 | static bool is_user_context_package (const cmt_string& name, |
---|
| 135 | const cmt_string& version); |
---|
| 136 | |
---|
| 137 | static cmt_string get_project_package (); |
---|
| 138 | static bool is_project_package (const cmt_string& name, |
---|
| 139 | const cmt_string& version); |
---|
| 140 | |
---|
| 141 | static bool testenv (const cmt_string& name); |
---|
| 142 | static cmt_string getenv (const cmt_string& name); |
---|
[144] | 143 | static bool putenv (const cmt_string& name, const cmt_string& value); |
---|
[2] | 144 | static void get_cmt_paths (IProjectFactory& factory, |
---|
[9] | 145 | const cmt_string& init_text, |
---|
| 146 | const cmt_string& cmt_user_context, |
---|
| 147 | const cmt_string& cmt_home); |
---|
[2] | 148 | static int execute (const cmt_string& command); |
---|
| 149 | static int execute (const cmt_string& command, cmt_string& output); |
---|
| 150 | static bool is_package_directory (const cmt_string& name); |
---|
| 151 | static bool is_version_directory (const cmt_string& name); |
---|
| 152 | static bool is_version_directory (const cmt_string& name, int& v, int& r, int& p); |
---|
| 153 | static void split (const cmt_string& text, |
---|
| 154 | const cmt_string& separators, |
---|
| 155 | cmt_string_vector& strings); |
---|
[561] | 156 | static cmt_string quote (const cmt_string& text, |
---|
| 157 | const cmt_string& separators); |
---|
[565] | 158 | static int mangle (const cmt_string& text, cmt_string& out); |
---|
| 159 | static cmt_string mangle (const cmt_string& text); |
---|
[2] | 160 | |
---|
| 161 | static void compress_path (const cmt_string& dir, cmt_string& new_dir); |
---|
| 162 | static void compress_path (cmt_string& dir); |
---|
| 163 | |
---|
| 164 | static cmt_string now (); |
---|
| 165 | static cmt_string user (); |
---|
| 166 | |
---|
| 167 | static void get_cvsroot (cmt_string& cvsroot); |
---|
| 168 | |
---|
| 169 | static bool get_home_directory (cmt_string& dir); |
---|
| 170 | |
---|
[179] | 171 | static cmt_string get_makefile_suffix (); |
---|
| 172 | |
---|
[527] | 173 | static void close_ostream (FILE *stream, const cmt_string& name = "" ); |
---|
| 174 | static void close_stdout (void); |
---|
| 175 | |
---|
[2] | 176 | }; |
---|
| 177 | |
---|
[400] | 178 | class FilePath |
---|
| 179 | { |
---|
| 180 | public: |
---|
| 181 | |
---|
| 182 | FilePath (); |
---|
| 183 | |
---|
| 184 | FilePath (const FilePath& other); |
---|
| 185 | FilePath (const cmt_string& other); |
---|
| 186 | FilePath (const char* other); |
---|
| 187 | |
---|
| 188 | FilePath& operator = (const FilePath& other); |
---|
| 189 | FilePath& operator = (const cmt_string& other); |
---|
| 190 | FilePath& operator = (const char* other); |
---|
| 191 | |
---|
| 192 | bool operator == (const FilePath& other) const; |
---|
| 193 | bool operator == (const cmt_string& other) const; |
---|
| 194 | bool operator == (const char* other) const; |
---|
| 195 | |
---|
| 196 | bool operator != (const FilePath& other) const; |
---|
| 197 | bool operator != (const cmt_string& other) const; |
---|
| 198 | bool operator != (const char* other) const; |
---|
| 199 | |
---|
[411] | 200 | const cmt_string& name () const; |
---|
| 201 | operator const cmt_string& () const; |
---|
| 202 | |
---|
| 203 | bool in (const FilePath& other) const; |
---|
| 204 | bool in (const cmt_string& other) const; |
---|
| 205 | bool in (const char* other) const; |
---|
| 206 | |
---|
[400] | 207 | bool cd () const; |
---|
| 208 | |
---|
| 209 | private: |
---|
| 210 | |
---|
| 211 | void set (const FilePath& other); |
---|
| 212 | void set (const cmt_string& other); |
---|
| 213 | void set (const char* other); |
---|
| 214 | |
---|
| 215 | cmt_string p_name; // physical name |
---|
| 216 | cmt_string l_name; // first logical name |
---|
| 217 | |
---|
| 218 | CmtSystem::cmt_string_vector alternates; // other logical names |
---|
| 219 | }; |
---|
| 220 | |
---|
| 221 | |
---|
[2] | 222 | #endif |
---|