source: CMT/v1r25-branch/source/cmt_system.h

Last change on this file was 664, checked in by rybkin, 10 years ago

merge -r 646:663 HEAD

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