[1] | 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 IProjectFactory |
---|
| 16 | { |
---|
| 17 | public: |
---|
| 18 | virtual void reset () = 0; |
---|
| 19 | virtual void create_project (const cmt_string& path, |
---|
| 20 | const cmt_string& path_source) = 0; |
---|
| 21 | }; |
---|
| 22 | |
---|
| 23 | class CmtSystem |
---|
| 24 | { |
---|
| 25 | public: |
---|
| 26 | typedef cmt_vector<cmt_string> cmt_string_vector; |
---|
| 27 | |
---|
| 28 | static cmt_string pwd (); |
---|
| 29 | static bool cd (const cmt_string& dir); |
---|
| 30 | |
---|
| 31 | static void basename (const cmt_string& file_name, cmt_string& result); |
---|
| 32 | static void basename (const cmt_string& file_name, |
---|
| 33 | const cmt_string& suffix, |
---|
| 34 | cmt_string& result); |
---|
| 35 | |
---|
| 36 | static void dirname (const cmt_string& file_name, cmt_string& result); |
---|
| 37 | |
---|
| 38 | static void name (const cmt_string& file, cmt_string& result); |
---|
| 39 | |
---|
| 40 | static void get_suffix (const cmt_string& file, cmt_string& result); |
---|
| 41 | static void get_dot_suffix (const cmt_string& file, cmt_string& result); |
---|
| 42 | static bool has_prefix (const cmt_string& name); |
---|
| 43 | static bool absolute_path (const cmt_string& name); |
---|
| 44 | static bool has_device (const cmt_string& name); |
---|
| 45 | |
---|
| 46 | static cmt_string current_branch (); |
---|
| 47 | |
---|
| 48 | /** |
---|
| 49 | * Implementation of the "test -d" equivalent |
---|
| 50 | */ |
---|
| 51 | static bool test_directory (const cmt_string& name); |
---|
| 52 | /** |
---|
| 53 | * Implementation of the "test -f" equivalent |
---|
| 54 | */ |
---|
| 55 | static bool test_file (const cmt_string& name); |
---|
| 56 | /** |
---|
| 57 | * Check if the file "name1" is identical to "name2" |
---|
| 58 | */ |
---|
| 59 | static bool compare_files (const cmt_string& name1, |
---|
| 60 | const cmt_string& name2); |
---|
| 61 | /** |
---|
| 62 | * Check if the file "name1" is identical to "name2" |
---|
| 63 | * if they are identical, "name1" will be simply deleted |
---|
| 64 | * otherwise "name1" will be copied to "name2" and deleted afterwards |
---|
| 65 | */ |
---|
| 66 | static bool compare_and_update_files (const cmt_string& name1, |
---|
| 67 | const cmt_string& name2); |
---|
| 68 | static int file_size (const cmt_string& name); |
---|
| 69 | static char file_separator (); |
---|
| 70 | static void reduce_file_separators (cmt_string& text); |
---|
| 71 | static char path_separator (); |
---|
| 72 | static char command_separator (); |
---|
| 73 | static const cmt_string& ev_open (); |
---|
| 74 | static const cmt_string& ev_close (); |
---|
| 75 | static bool create_symlink (const cmt_string& oldname, |
---|
| 76 | const cmt_string& newname); |
---|
| 77 | static bool remove_file (const cmt_string& name); |
---|
| 78 | static bool remove_directory (const cmt_string& name); |
---|
| 79 | static bool mkdir (const cmt_string& name); |
---|
| 80 | static void scan_dir (const cmt_string& dir_name, |
---|
| 81 | cmt_string_vector& list); |
---|
| 82 | static void scan_dir (const cmt_string& dir_name, |
---|
| 83 | const cmt_regexp& expression, |
---|
| 84 | cmt_string_vector& list); |
---|
| 85 | static cmt_string_vector& scan_dir (const cmt_string& dir_name); |
---|
| 86 | static const cmt_string& get_cmt_root (); |
---|
| 87 | static void get_cmt_version (cmt_string& version); |
---|
| 88 | static cmt_string get_cmt_config (); |
---|
| 89 | static cmt_string get_cmt_site (); |
---|
| 90 | static void get_uname (cmt_string& uname); |
---|
| 91 | static void get_hosttype (cmt_string& hosttype); |
---|
| 92 | static cmt_string get_temporary_name (); |
---|
| 93 | |
---|
| 94 | static cmt_string get_home_package (); |
---|
| 95 | static bool is_home_package (const cmt_string& name, |
---|
| 96 | const cmt_string& version); |
---|
| 97 | |
---|
| 98 | static cmt_string get_user_context_package (); |
---|
| 99 | static bool is_user_context_package (const cmt_string& name, |
---|
| 100 | const cmt_string& version); |
---|
| 101 | |
---|
| 102 | static cmt_string get_project_package (); |
---|
| 103 | static bool is_project_package (const cmt_string& name, |
---|
| 104 | const cmt_string& version); |
---|
| 105 | |
---|
| 106 | static bool testenv (const cmt_string& name); |
---|
| 107 | static cmt_string getenv (const cmt_string& name); |
---|
| 108 | static bool putenv (const cmt_string& name_value); |
---|
| 109 | static void add_cmt_path (const cmt_string& path, |
---|
| 110 | const cmt_string& path_source, |
---|
| 111 | IProjectFactory& factory); |
---|
| 112 | static void get_cmt_paths (IProjectFactory& factory, |
---|
| 113 | const cmt_string& init_text = ""); |
---|
| 114 | static int execute (const cmt_string& command); |
---|
| 115 | static int execute (const cmt_string& command, cmt_string& output); |
---|
| 116 | static bool is_package_directory (const cmt_string& name); |
---|
| 117 | static bool is_version_directory (const cmt_string& name); |
---|
| 118 | static bool is_version_directory (const cmt_string& name, int& v, int& r, int& p); |
---|
| 119 | static void split (const cmt_string& text, |
---|
| 120 | const cmt_string& separators, |
---|
| 121 | cmt_string_vector& strings); |
---|
| 122 | |
---|
| 123 | static void compress_path (const cmt_string& dir, cmt_string& new_dir); |
---|
| 124 | static void compress_path (cmt_string& dir); |
---|
| 125 | |
---|
| 126 | static cmt_string now (); |
---|
| 127 | static cmt_string user (); |
---|
| 128 | |
---|
| 129 | static void get_cvsroot (cmt_string& cvsroot); |
---|
| 130 | |
---|
| 131 | static bool get_home_directory (cmt_string& dir); |
---|
| 132 | |
---|
| 133 | }; |
---|
| 134 | |
---|
| 135 | #endif |
---|